From 123783c80ae2f2e5a46b0b09f01fcf691630f74d Mon Sep 17 00:00:00 2001 From: lisyarus Date: Wed, 2 Mar 2022 13:55:42 +0300 Subject: [PATCH] Support creating an app with fixed resolution & add a list of common resolutions --- libs/app/include/psemek/app/app.hpp | 15 +++++++++++++++ libs/app/source/app.cpp | 10 +++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/libs/app/include/psemek/app/app.hpp b/libs/app/include/psemek/app/app.hpp index fd520e76..082e350c 100644 --- a/libs/app/include/psemek/app/app.hpp +++ b/libs/app/include/psemek/app/app.hpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include @@ -12,12 +14,25 @@ namespace psemek::app { + static const geom::vector common_resolutions[] = + { + {1024, 768}, + {1280, 720}, + {1280, 1024}, + {1366, 768}, + {1440, 900}, + {1536, 864}, + {1600, 900}, + {1920, 1080}, + }; + struct app : scene_base, scene_manager { struct options { int multisampling = 0; + std::optional> fixed_resolution = std::nullopt; bool highdpi = false; }; diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index 2c5f6201..1326e3b6 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -80,10 +80,15 @@ namespace psemek::app SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, opts.multisampling); } - std::uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_HIDDEN; + std::uint32_t flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN; + if (!opts.fixed_resolution) + flags |= SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED; if (opts.highdpi) flags |= SDL_WINDOW_ALLOW_HIGHDPI; - impl().window = SDL_CreateWindow(name.data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 768, flags); + int width = opts.fixed_resolution ? (*opts.fixed_resolution)[0] : 1024; + int height = opts.fixed_resolution ? (*opts.fixed_resolution)[1] : 768; + + impl().window = SDL_CreateWindow(name.data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); if (!impl().window) sdl2::fail("Failed to create window: "); @@ -104,7 +109,6 @@ namespace psemek::app gl::GetIntegerv(gl::MINOR_VERSION, &minor); log::info() << "Initialized OpenGL " << major << '.' << minor << ", " << vendor << ", " << renderer; - int width, height; SDL_GL_GetDrawableSize(impl().window, &width, &height); scene_base::on_resize(width, height);