Skip to content

Commit

Permalink
gui/perf overlay: Refactor calcul window size.
Browse files Browse the repository at this point in the history
- Fix Window size when using scaling.
  • Loading branch information
Zangetsu38 committed Sep 20, 2024
1 parent 77abeaa commit fe58c8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
49 changes: 22 additions & 27 deletions vita3k/gui/src/perf_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,53 +43,48 @@ static ImVec2 get_perf_pos(ImVec2 window_size, EmuEnvState &emuenv) {
return ImVec2(LEFT, TOP);
}

static float get_perf_height(EmuEnvState &emuenv) {
switch (emuenv.cfg.performance_overlay_detail) {
case MAXIMUM: return 138.f;
case MEDIUM: return 80.f;
case LOW:
case MINIMUM:
default: break;
}

return 57.f;
}

void draw_perf_overlay(GuiState &gui, EmuEnvState &emuenv) {
auto lang = gui.lang.performance_overlay;

const ImVec2 display_size(emuenv.viewport_size.x, emuenv.viewport_size.y);
const auto RES_SCALE = ImVec2(display_size.x / emuenv.res_width_dpi_scale, display_size.y / emuenv.res_height_dpi_scale);
const auto SCALE = ImVec2(RES_SCALE.x * emuenv.dpi_scale, RES_SCALE.y * emuenv.dpi_scale);
const ImVec2 VIEWPORT_SIZE(emuenv.viewport_size.x, emuenv.viewport_size.y);
const ImVec2 RES_SCALE(VIEWPORT_SIZE.x / emuenv.res_width_dpi_scale, VIEWPORT_SIZE.y / emuenv.res_height_dpi_scale);
const ImVec2 SCALE(RES_SCALE.x * emuenv.dpi_scale, RES_SCALE.y * emuenv.dpi_scale);

const auto MAIN_WINDOW_SIZE = ImVec2((emuenv.cfg.performance_overlay_detail == MINIMUM ? 95.5f : 152.f) * SCALE.x, get_perf_height(emuenv) * SCALE.y);
const auto SCALED_FONT_SIZE = ImGui::GetFontSize() * (0.7f * RES_SCALE.y);
const auto FONT_SCALE = SCALED_FONT_SIZE / ImGui::GetFontSize();

const auto WINDOW_POS = get_perf_pos(MAIN_WINDOW_SIZE, emuenv);
const auto WINDOW_SIZE = ImVec2((emuenv.cfg.performance_overlay_detail == MINIMUM ? 72.5f : 130.f) * SCALE.x, (emuenv.cfg.performance_overlay_detail <= LOW ? 35.f : 58.f) * SCALE.y);
const auto FPS_TEXT = emuenv.cfg.performance_overlay_detail == MINIMUM ? fmt::format("FPS: {}", emuenv.fps) : fmt::format("FPS: {} {}: {}", emuenv.fps, lang["avg"], emuenv.avg_fps);
const auto MIN_MAX_FPS_TEXT = fmt::format("{}: {} {}: {}", lang["min"], emuenv.min_fps, lang["max"], emuenv.max_fps);

const ImVec2 TOTAL_WINDOW_PADDING(ImGui::GetStyle().WindowPadding.x * 2, ImGui::GetStyle().WindowPadding.y * 2);

const auto MAX_TEXT_WIDTH_SCALED = std::max(ImGui::CalcTextSize(FPS_TEXT.c_str()).x, ImGui::CalcTextSize(MIN_MAX_FPS_TEXT.c_str()).x) * FONT_SCALE;
const auto MAX_TEXT_HEIGHT_SCALED = SCALED_FONT_SIZE + (emuenv.cfg.performance_overlay_detail >= MEDIUM ? SCALED_FONT_SIZE + ImGui::GetStyle().ItemSpacing.y : 0);

const ImVec2 WINDOW_SIZE(MAX_TEXT_WIDTH_SCALED + TOTAL_WINDOW_PADDING.x, MAX_TEXT_HEIGHT_SCALED + TOTAL_WINDOW_PADDING.y);
const ImVec2 MAIN_WINDOW_SIZE(WINDOW_SIZE.x + TOTAL_WINDOW_PADDING.x, WINDOW_SIZE.y + TOTAL_WINDOW_PADDING.y + (emuenv.cfg.performance_overlay_detail == MAXIMUM ? WINDOW_SIZE.y : 0));

const auto WINDOW_POS = get_perf_pos(MAIN_WINDOW_SIZE, emuenv);
ImGui::SetNextWindowSize(MAIN_WINDOW_SIZE);
ImGui::SetNextWindowPos(WINDOW_POS);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
ImGui::Begin("##performance", nullptr, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus);
ImGui::PushStyleColor(ImGuiCol_ChildBg, PERF_OVERLAY_BG_COLOR);
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.f * SCALE.x);
ImGui::BeginChild("#perf_stats", WINDOW_SIZE, ImGuiChildFlags_Borders, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings);
ImGui::PushFont(gui.vita_font);
ImGui::SetWindowFontScale(0.7f * RES_SCALE.x);
if (emuenv.cfg.performance_overlay_detail == PerformanceOverlayDetail::MINIMUM)
ImGui::Text("FPS: %d", emuenv.fps);
else
ImGui::Text("FPS: %d %s: %d", emuenv.fps, lang["avg"].c_str(), emuenv.avg_fps);

ImGui::SetWindowFontScale(0.7f * RES_SCALE.y);

ImGui::Text("%s", FPS_TEXT.c_str());
if (emuenv.cfg.performance_overlay_detail >= PerformanceOverlayDetail::MEDIUM) {
ImGui::Separator();
ImGui::Text("%s: %d %s: %d", lang["min"].c_str(), emuenv.min_fps, lang["max"].c_str(), emuenv.max_fps);
ImGui::Text("%s", MIN_MAX_FPS_TEXT.c_str());
}
ImGui::PopFont();
ImGui::EndChild();
ImGui::PopStyleVar();
ImGui::PopStyleColor();
if (emuenv.cfg.performance_overlay_detail == PerformanceOverlayDetail::MAXIMUM) {
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - (3.f * SCALE.y));
ImGui::SetCursorPosY(ImGui::GetCursorPosY() - ImGui::GetStyle().ItemSpacing.y);
ImGui::PlotLines("##fps_graphic", emuenv.fps_values, IM_ARRAYSIZE(emuenv.fps_values), emuenv.current_fps_offset, nullptr, 0.f, float(emuenv.max_fps), WINDOW_SIZE);
}
ImGui::End();
Expand Down
5 changes: 4 additions & 1 deletion vita3k/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,11 @@ int main(int argc, char *argv[]) {
gui::draw_common_dialog(gui, emuenv);
gui::draw_vita_area(gui, emuenv);

if (emuenv.cfg.performance_overlay && !emuenv.kernel.is_threads_paused() && (emuenv.common_dialog.status != SCE_COMMON_DIALOG_STATUS_RUNNING))
if (emuenv.cfg.performance_overlay && !emuenv.kernel.is_threads_paused() && (emuenv.common_dialog.status != SCE_COMMON_DIALOG_STATUS_RUNNING)) {
ImGui::PushFont(gui.vita_font);
gui::draw_perf_overlay(gui, emuenv);
ImGui::PopFont();
}

if (emuenv.cfg.current_config.show_touchpad_cursor && !emuenv.kernel.is_threads_paused())
gui::draw_touchpad_cursor(emuenv);
Expand Down

0 comments on commit fe58c8d

Please sign in to comment.