diff --git a/code/addons/dynui/imguicontext.cc b/code/addons/dynui/imguicontext.cc index e02965b1e..8144b89ac 100644 --- a/code/addons/dynui/imguicontext.cc +++ b/code/addons/dynui/imguicontext.cc @@ -403,6 +403,7 @@ ImguiContext::Create() Ptr display = DisplayDevice::Instance(); DisplayMode mode = CoreGraphics::WindowGetDisplayMode(display->GetCurrentWindow()); + float scaleFactor = mode.GetContentScale(); // setup Imgui ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); @@ -437,6 +438,8 @@ ImguiContext::Create() style.WindowBorderSize = 1.0f; style.PopupBorderSize = 0.0f; style.ChildBorderSize = 0.0f; + + style.ScaleAllSizes(scaleFactor); ImVec4 nebulaOrange(1.0f, 0.30f, 0.0f, 1.0f); ImVec4 nebulaOrangeActive(0.9f, 0.20f, 0.05f, 1.0f); @@ -524,11 +527,11 @@ ImguiContext::Create() config.OversampleH = 3; config.OversampleV = 1; #if __WIN32__ - state.normalFont = io.Fonts->AddFontFromFileTTF("c:/windows/fonts/calibri.ttf", 14, &config); - state.smallFont = io.Fonts->AddFontFromFileTTF("c:/windows/fonts/calibri.ttf", 12, &config); + state.normalFont = io.Fonts->AddFontFromFileTTF("c:/windows/fonts/calibri.ttf", scaleFactor * 14, &config); + state.smallFont = io.Fonts->AddFontFromFileTTF("c:/windows/fonts/calibri.ttf", scaleFactor * 12, &config); #else - state.normalFont = io.Fonts->AddFontFromFileTTF("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 14, &config); - state.smallFont = io.Fonts->AddFontFromFileTTF("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 12, &config); + state.normalFont = io.Fonts->AddFontFromFileTTF("/usr/share/fonts/truetype/freefont/FreeSans.ttf", scaleFactor * 14, &config); + state.smallFont = io.Fonts->AddFontFromFileTTF("/usr/share/fonts/truetype/freefont/FreeSans.ttf", scaleFactor * 12, &config); #endif unsigned char* buffer; diff --git a/code/application/appgame/gameapplication.cc b/code/application/appgame/gameapplication.cc index 9eea81b41..45f18eca2 100644 --- a/code/application/appgame/gameapplication.cc +++ b/code/application/appgame/gameapplication.cc @@ -286,7 +286,7 @@ GameApplication::StepFrame() void GameApplication::SetupGameFeatures() { - + // create any features in derived class } //------------------------------------------------------------------------------ diff --git a/code/render/coregraphics/displaymode.h b/code/render/coregraphics/displaymode.h index e16c7275e..a1c2e3010 100644 --- a/code/render/coregraphics/displaymode.h +++ b/code/render/coregraphics/displaymode.h @@ -59,6 +59,10 @@ class DisplayMode void SetRefreshRate( uint refreshRate ); /// gives you the refresh rate uint GetRefreshRate() const; + /// set content scale factor + void SetContentScale(float s); + /// get content scale factor + float GetContentScale() const; private: @@ -69,6 +73,7 @@ class DisplayMode SizeT height; uint refreshRate; float aspectRatio; + float contentScale; PixelFormat::Code pixelFormat; }; @@ -84,6 +89,7 @@ DisplayMode::DisplayMode() : height(768), refreshRate(60), aspectRatio(4.0f / 3.0f), + contentScale(1.0f), pixelFormat(PixelFormat::SRGBA8) { // empty @@ -101,6 +107,7 @@ DisplayMode::DisplayMode(uint x, uint y, SizeT w, SizeT h) : height(h), refreshRate(60), aspectRatio(float(w) / float(h)), + contentScale(1.0f), pixelFormat(PixelFormat::SRGBA8) { // empty @@ -118,6 +125,7 @@ DisplayMode::DisplayMode(SizeT w, SizeT h, PixelFormat::Code p) : height(h), refreshRate(60), aspectRatio(float(w) / float(h)), + contentScale(1.0f), pixelFormat(p) { // empty @@ -134,6 +142,7 @@ DisplayMode::DisplayMode(uint x, uint y, SizeT w, SizeT h, PixelFormat::Code p) height(h), refreshRate(60), aspectRatio(float(w) / float(h)), + contentScale(1.0f), pixelFormat(p) { // empty @@ -150,7 +159,8 @@ DisplayMode::operator==(const DisplayMode& rhs) const (this->width == rhs.width) && (this->height == rhs.height) && (this->refreshRate == rhs.refreshRate) && - (this->aspectRatio == rhs.aspectRatio) && + (this->aspectRatio == rhs.aspectRatio) && + (this->contentScale == rhs.contentScale) && (this->pixelFormat == rhs.pixelFormat)); } @@ -271,6 +281,24 @@ DisplayMode::GetAspectRatio() const return this->aspectRatio; } +//------------------------------------------------------------------------------ +/** +*/ +inline void +DisplayMode::SetContentScale(float a) +{ + this->contentScale = a; +} + +//------------------------------------------------------------------------------ +/** +*/ +inline float +DisplayMode::GetContentScale() const +{ + return this->contentScale; +} + //------------------------------------------------------------------------------ /** */ diff --git a/code/render/coregraphics/glfw/glfwwindow.cc b/code/render/coregraphics/glfw/glfwwindow.cc index 5caa69784..c20229d6f 100644 --- a/code/render/coregraphics/glfw/glfwwindow.cc +++ b/code/render/coregraphics/glfw/glfwwindow.cc @@ -353,6 +353,14 @@ InternalSetupFunction(const WindowCreateInfo& info, const Util::Blob& windowData // if Vulkan, context is created and managed by render device glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); #endif + // scale window according to platform dpi + glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); + float xScale, yScale; + glfwGetMonitorContentScale(monitor, &xScale, &yScale); + float contentScale = Math::max(xScale, yScale); + mode.SetWidth(info.mode.GetWidth() * contentScale); + mode.SetHeight(info.mode.GetHeight() * contentScale); + mode.SetContentScale(contentScale); // set user pointer to this window WindowId* ptr = new WindowId; @@ -409,7 +417,6 @@ InternalSetupFunction(const WindowCreateInfo& info, const Util::Blob& windowData #endif glfwWindowAllocator.Get(windowId) = wnd; - glfwWindowAllocator.Get(windowId) = info.mode; // notify window is opened GLFW::GLFWDisplayDevice::Instance()->NotifyEventHandlers(DisplayEvent(DisplayEvent::WindowOpen, id)); diff --git a/code/render/coregraphics/window.h b/code/render/coregraphics/window.h index 0cbe9bf6d..4c0746662 100644 --- a/code/render/coregraphics/window.h +++ b/code/render/coregraphics/window.h @@ -77,5 +77,7 @@ const Util::StringAtom& WindowGetTitle(const WindowId id); const Util::StringAtom& WindowGetIcon(const WindowId id); /// get render texture associated with window const CoreGraphics::TextureId& WindowGetTexture(const WindowId id); +/// retrieve window content scaling (ratio between current DPI and platform default DPI) +Math::vec2 WindowGetContentScale(const WindowId id); } // CoreGraphics