Skip to content

Commit

Permalink
revert HighDPI (#502)
Browse files Browse the repository at this point in the history
* Revert "fix: ifdef macro that doesn't exist on switch (#501)"

This reverts commit 8a079ed.

* Revert "HighDPI UI behavouir (#467)"

This reverts commit b73cdb5.
  • Loading branch information
briaguya-ai authored Apr 22, 2024
1 parent 8a079ed commit c29a484
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
57 changes: 0 additions & 57 deletions src/window/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARA

#endif

#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
#endif

namespace LUS {
#define TOGGLE_BTN ImGuiKey_F1
#define TOGGLE_PAD_BTN ImGuiKey_GamepadBack
Expand Down Expand Up @@ -283,8 +279,6 @@ void Gui::Update(WindowEvent event) {
mNeedsConsoleVariableSave = false;
}

float dpiScale = 0;

switch (Context::GetInstance()->GetWindow()->GetWindowBackend()) {
#ifdef __WIIU__
case WindowBackend::GX2:
Expand All @@ -295,26 +289,6 @@ void Gui::Update(WindowEvent event) {
case WindowBackend::SDL_METAL:
ImGui_ImplSDL2_ProcessEvent(static_cast<const SDL_Event*>(event.Sdl.Event));

#ifdef __SWITCH__
// Switch doesn't support SDL_WINDOWEVENT_DISPLAY_CHANGED
if (mDpiInit) {
#else
if (static_cast<const SDL_Event*>(event.Sdl.Event)->window.event == SDL_WINDOWEVENT_DISPLAY_CHANGED ||
mDpiInit) {
#endif
int display = 0;
if (Context::GetInstance()->GetWindow()->GetWindowBackend() == WindowBackend::SDL_OPENGL) {
display = SDL_GetWindowDisplayIndex(static_cast<SDL_Window*>(mImpl.Opengl.Window));
} else {
display = SDL_GetWindowDisplayIndex(static_cast<SDL_Window*>(mImpl.Metal.Window));
}

float dpi;
if (SDL_GetDisplayDPI(display, &dpi, nullptr, nullptr) == 0) {
dpiScale = dpi / USER_DEFAULT_SCREEN_DPI;
}
}

#ifdef __SWITCH__
LUS::Switch::ImGuiProcessEvent(mImGuiIo->WantTextInput);
#endif
Expand All @@ -327,30 +301,11 @@ void Gui::Update(WindowEvent event) {
case WindowBackend::DX11:
ImGui_ImplWin32_WndProcHandler(static_cast<HWND>(event.Win32.Handle), event.Win32.Msg, event.Win32.Param1,
event.Win32.Param2);

if (event.Win32.Msg == WM_DPICHANGED || mDpiInit) {
HMONITOR monitor = MonitorFromWindow(static_cast<HWND>(event.Win32.Handle), MONITOR_DEFAULTTONEAREST);
dpiScale = (float)ImGui_ImplWin32_GetDpiScaleForMonitor(monitor);
}
break;
#endif
default:
break;
}

if (dpiScale > 0) {
if (mDpiInit) {
mLastDpiScale = 1.f;
mDpiInit = false;
}

float diff = dpiScale / mLastDpiScale;
mLastDpiScale = dpiScale;

ImGui::GetStyle().ScaleAllSizes(diff);
ImFont* font = ImGui::GetFont();
font->Scale *= diff;
}
}

bool Gui::ImGuiGamepadNavigationEnabled() {
Expand All @@ -367,24 +322,12 @@ void Gui::UnblockImGuiGamepadNavigation() {
}
}

float Gui::GetCurrentDpiScale() {
if (mLastDpiScale <= 0) {
return 1.f;
}

return mLastDpiScale;
}

void Gui::DrawMenu() {
LUS::Context::GetInstance()->GetWindow()->GetGui()->GetGuiWindow("Console")->Update();
ImGuiBackendNewFrame();
ImGuiWMNewFrame();
ImGui::NewFrame();

if (mLastDpiScale == 0) {
mDpiInit = true;
}

const std::shared_ptr<Window> wnd = Context::GetInstance()->GetWindow();
const std::shared_ptr<Config> conf = Context::GetInstance()->GetConfig();

Expand Down
4 changes: 0 additions & 4 deletions src/window/gui/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class Gui {
bool ImGuiGamepadNavigationEnabled();
void BlockImGuiGamepadNavigation();
void UnblockImGuiGamepadNavigation();
float GetCurrentDpiScale();

protected:
void ImGuiWMInit();
Expand All @@ -112,9 +111,6 @@ class Gui {
std::shared_ptr<GuiMenuBar> mMenuBar;
std::map<std::string, GuiTextureMetadata> mGuiTextures;
std::map<std::string, std::shared_ptr<GuiWindow>> mGuiWindows;

bool mDpiInit = false;
float mLastDpiScale = 0;
};
} // namespace LUS

Expand Down

0 comments on commit c29a484

Please sign in to comment.