Browse Source

Fix DPI scaling on Windows

master
C. J. Howard 5 years ago
parent
commit
b18e983499
Signed by: cjhoward GPG Key ID: 03E1FABA9C3EC195
3 changed files with 10 additions and 4 deletions
  1. +5
    -0
      CMakeLists.txt
  2. +4
    -1
      src/game.cpp
  3. +1
    -3
      src/game.hpp

+ 5
- 0
CMakeLists.txt View File

@ -37,6 +37,11 @@ configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in
file(GLOB_RECURSE SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/*.cpp)
# Make DPI-aware on Windows
if(MSVC)
list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/dpi-aware.manifest")
endif()
# Add executable target
set(EXECUTABLE_TARGET ${PROJECT_NAME}-executable)
add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})

+ 4
- 1
src/game.cpp View File

@ -1094,7 +1094,10 @@ void Game::setupUI()
// Get DPI and convert font size to pixels
const Display* display = deviceManager->getDisplays()->front();
dpi = display->getDPI();
fontSizePX = fontSizePT * (1.0f / 72.0f) * dpi;
fontSizePX = fontSizePT * (1.0f / 96.0f) * dpi;
logger->log("Detected display DPI as " + std::to_string(dpi) + ".");
logger->log("Fonts size = " + std::to_string(fontSizePT) + " PT = " + std::to_string(fontSizePX) + " PX.");
// Load fonts
loadFonts();

+ 1
- 3
src/game.hpp View File

@ -162,9 +162,7 @@ private:
virtual void handleEvent(const GamepadDisconnectedEvent& event);
virtual void handleEvent(const ScheduledFunctionEvent& event);
#if defined(DEBUG)
void setupDebugging();
#endif
void setupDebugging();
void setupLocalization();
void setupWindow();
void setupGraphics();

Loading…
Cancel
Save