From b47a95a1582cb2bc009f3e5099c6c491de61e12f Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 2 Oct 2020 19:19:19 +0300 Subject: [PATCH] Store window size in base app --- libs/app/include/psemek/app/app.hpp | 3 +++ libs/app/source/app.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/libs/app/include/psemek/app/app.hpp b/libs/app/include/psemek/app/app.hpp index 2e3db24b..c7ea2539 100644 --- a/libs/app/include/psemek/app/app.hpp +++ b/libs/app/include/psemek/app/app.hpp @@ -32,6 +32,9 @@ namespace psemek::app void show_cursor(bool show); float time() const; + int width() const; + int height() const; + private: struct impl; std::unique_ptr pimpl_; diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index c5499841..c56a378b 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -18,6 +18,8 @@ namespace psemek::app SDL_Window * window = nullptr; SDL_GLContext gl_context = nullptr; + int width, height; + scene * current_scene = nullptr; bool running = false; @@ -91,6 +93,7 @@ namespace psemek::app log::info() << "Initialized OpenGL " << gl::sys::GetMajorVersion() << '.' << gl::sys::GetMinorVersion() << ", " << vendor << ", " << renderer; + SDL_GetWindowSize(impl().window, &impl().width, &impl().height); } app::~app() @@ -109,6 +112,8 @@ namespace psemek::app void app::on_resize(int width, int height) { gl::Viewport(0, 0, width, height); + impl().width = width; + impl().height = height; } void app::on_quit() @@ -237,4 +242,14 @@ namespace psemek::app return std::chrono::duration_cast>(clock::now() - impl().start_time).count(); } + int app::width() const + { + return impl().width; + } + + int app::height() const + { + return impl().height; + } + }