From 51fbfa9b2913e04f923c11f6d2bb9319a638faa3 Mon Sep 17 00:00:00 2001 From: milerius Date: Mon, 28 Oct 2019 20:37:10 +0100 Subject: [PATCH] feat(sdl): scaling work on windows --- cmake/dependencies.cmake | 6 +++++- modules/sdl/antara/gaming/sdl/graphic.system.cpp | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index f0f24cc2..2717c4a7 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -99,7 +99,11 @@ if (USE_SDL_ANTARA_WRAPPER) add_library(antara::sdl_import ALIAS antara_sdl_import) #add_dependencies(antara_sdl_import external_sdl) #include(GNUInstallDirs) - set(SDL2_DIR ${CMAKE_BINARY_DIR}/sdl/external/installed/lib/cmake/SDL2) + if (WIN32) + set(SDL2_DIR ${CMAKE_BINARY_DIR}/sdl/external/installed/cmake/) + else () + set(SDL2_DIR ${CMAKE_BINARY_DIR}/sdl/external/installed/lib/cmake/SDL2) + endif () find_package(SDL2 REQUIRED) target_link_libraries(antara_sdl_import INTERFACE SDL2::SDL2-static) target_include_directories(antara_sdl_import diff --git a/modules/sdl/antara/gaming/sdl/graphic.system.cpp b/modules/sdl/antara/gaming/sdl/graphic.system.cpp index 747ee5e2..6b37bf9b 100644 --- a/modules/sdl/antara/gaming/sdl/graphic.system.cpp +++ b/modules/sdl/antara/gaming/sdl/graphic.system.cpp @@ -13,10 +13,16 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ +#ifdef _WIN32 + #pragma comment(lib, "Shcore.lib") + #define NOMINMAX + #include + #include +#endif -#include #include #include + #include "antara/gaming/graphics/component.canvas.hpp" #include "antara/gaming/event/fatal.error.hpp" #include "antara/gaming/sdl/graphic.system.hpp" @@ -32,7 +38,7 @@ namespace SDL_Window *window = nullptr; auto[screen_width, screen_height] = canvas_2d.window.size.to(); auto[screen_pos_x, screen_pos_y] = canvas_2d.window.position.to(); - SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1"); + Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; if (canvas_2d.is_fullscreen) { flags |= SDL_WINDOW_FULLSCREEN; @@ -57,6 +63,9 @@ namespace antara::gaming::sdl graphic_system::graphic_system(entt::registry ®istry) noexcept : system(registry) { +#ifdef _WIN32 + SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); +#endif if (auto res = SDL_Init(SDL_INIT_EVERYTHING); res < 0) { this->dispatcher_.trigger(std::error_code(res, sdl::sdl_error_category())); }