diff --git a/engine/core/include/imgui_backend.hpp b/engine/core/include/imgui_backend.hpp index c253bb2..d885600 100644 --- a/engine/core/include/imgui_backend.hpp +++ b/engine/core/include/imgui_backend.hpp @@ -16,6 +16,7 @@ namespace prism { void render(); void process_move(platform::window_ptr identifier); + void process_resize(platform::window_ptr identifier); void process_mouse_down(int button); diff --git a/engine/core/src/engine.cpp b/engine/core/src/engine.cpp index e00f100..1df52ef 100755 --- a/engine/core/src/engine.cpp +++ b/engine/core/src/engine.cpp @@ -425,6 +425,8 @@ void engine::resize(const platform::window_ptr identifier, const prism::Extent e gfx->recreate_view(identifier, drawable_extent.width, drawable_extent.height); current_renderer->resize_render_target(*window->render_target, drawable_extent); + + imgui->process_resize(identifier); } void engine::move(const platform::window_ptr identifier) { diff --git a/engine/core/src/imgui_backend.cpp b/engine/core/src/imgui_backend.cpp index 46740c1..cd07928 100644 --- a/engine/core/src/imgui_backend.cpp +++ b/engine/core/src/imgui_backend.cpp @@ -159,6 +159,12 @@ void imgui_backend::process_move(platform::window_ptr identifier) { viewport->PlatformRequestMove = true; } +void imgui_backend::process_resize(platform::window_ptr identifier) { + auto viewport = ImGui::FindViewportByPlatformHandle(identifier); + if(viewport != nullptr) + viewport->PlatformRequestResize = true; +} + void imgui_backend::begin_frame(const float delta_time) { ImGuiIO& io = ImGui::GetIO(); diff --git a/engine/platform/include/platform.hpp b/engine/platform/include/platform.hpp index fd86fac..75ab71b 100755 --- a/engine/platform/include/platform.hpp +++ b/engine/platform/include/platform.hpp @@ -101,9 +101,6 @@ namespace platform { /// Forces the platform to quit the application. This is not related to Engine::quit(). void force_quit(); - /// Gets the content scale for the window. 1.0 would be 1x scale, 2.0 would be 2x scale, etc. - float get_window_dpi(window_ptr window); - /// Gets the content scale for the monitor. 1.0 would be 1x scale, 2.0 would be 2x scale, etc. float get_monitor_dpi(); diff --git a/engine/renderer/src/imguipass.cpp b/engine/renderer/src/imguipass.cpp index 73675f7..f7e28d6 100755 --- a/engine/renderer/src/imguipass.cpp +++ b/engine/renderer/src/imguipass.cpp @@ -154,8 +154,8 @@ void ImGuiPass::load_font(const std::string_view filename) { font_file->read_all(); - io.Fonts->AddFontFromMemoryTTF(font_file->cast_data(), font_file->size(), 15.0f * platform::get_window_dpi(engine->get_main_window())); - ImGui::GetIO().FontGlobalScale = 1.0f / platform::get_window_dpi(engine->get_main_window()); + io.Fonts->AddFontFromMemoryTTF(font_file->cast_data(), font_file->size(), 15.0f * platform::get_monitor_dpi()); + ImGui::GetIO().FontGlobalScale = 1.0f / platform::get_monitor_dpi(); } else { prism::log("Failed to load font file for imgui!"); return; diff --git a/platforms/sdl/main.cpp.in b/platforms/sdl/main.cpp.in index ec4d6e0..da9dca7 100644 --- a/platforms/sdl/main.cpp.in +++ b/platforms/sdl/main.cpp.in @@ -135,23 +135,26 @@ void platform::force_quit() { SDL_Quit(); } -float platform::get_window_dpi(const platform::window_ptr index) { - return 1.0; -} - float platform::get_monitor_dpi() { - return 1.0; + float dpi = 1.0f; + if (!SDL_GetDisplayDPI(0, &dpi, nullptr, nullptr)) + dpi = dpi / 96.0f; + + return dpi; } prism::Rectangle platform::get_monitor_resolution() { - SDL_DisplayMode DM; - SDL_GetCurrentDisplayMode(0, &DM); + SDL_Rect r; + SDL_GetDisplayBounds(0, &r); - return {0, 0, (uint32_t)DM.w, (uint32_t)DM.h}; + return {r.x, r.y, r.w, r.h}; } prism::Rectangle platform::get_monitor_work_area() { - return platform::get_monitor_resolution(); + SDL_Rect r = {}; + SDL_GetDisplayUsableBounds(0, &r); + + return {r.x, r.y, r.w, r.h}; } prism::Offset platform::get_window_position(const platform::window_ptr index) { diff --git a/tools/common/src/commoneditor.cpp b/tools/common/src/commoneditor.cpp index 3f67a5e..967ba05 100755 --- a/tools/common/src/commoneditor.cpp +++ b/tools/common/src/commoneditor.cpp @@ -662,7 +662,7 @@ void CommonEditor::createDockArea() { void CommonEditor::drawViewport(Scene* scene) { const auto size = ImGui::GetContentRegionAvail(); - const auto real_size = ImVec2(size.x * platform::get_window_dpi(engine->get_main_window()), size.y * platform::get_window_dpi(0)); + const auto real_size = ImVec2(size.x * platform::get_monitor_dpi(), size.y * platform::get_monitor_dpi()); if(real_size.x <= 0 || real_size.y <= 0) return;