From c714d6b73a2425568e7d67c12b4df5274bf0e16c Mon Sep 17 00:00:00 2001 From: lisyarus Date: Wed, 17 Feb 2021 12:43:44 +0300 Subject: [PATCH] Store width & height in scene_base --- libs/app/include/psemek/app/app.hpp | 2 -- libs/app/include/psemek/app/scene.hpp | 8 ++++++++ libs/app/source/app.cpp | 19 ++++--------------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libs/app/include/psemek/app/app.hpp b/libs/app/include/psemek/app/app.hpp index 31ff77f3..9f5a07ca 100644 --- a/libs/app/include/psemek/app/app.hpp +++ b/libs/app/include/psemek/app/app.hpp @@ -35,8 +35,6 @@ namespace psemek::app void vsync(bool on); float time() const; - int width() const; - int height() const; private: psemek_declare_pimpl diff --git a/libs/app/include/psemek/app/scene.hpp b/libs/app/include/psemek/app/scene.hpp index 7f848d9b..742de2ce 100644 --- a/libs/app/include/psemek/app/scene.hpp +++ b/libs/app/include/psemek/app/scene.hpp @@ -42,6 +42,8 @@ namespace psemek::app struct scene_base : scene { + void on_resize(int width, int height) override { width_ = width; height_ = height; } + void on_mouse_move(int x, int y, int, int) override { mouse_ = geom::point{x, y}; } void on_left_button_down() override { left_button_down_ = true; } void on_left_button_up() override { left_button_down_ = false; } @@ -60,7 +62,13 @@ namespace psemek::app bool is_key_down(SDL_Keycode key) const { return keys_.count(key) > 0; } + int width() const { return width_; } + int height() const { return height_; } + private: + int width_ = 0; + int height_ = 0; + bool left_button_down_ = false; bool middle_button_down_ = false; bool right_button_down_ = false; diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index ba165847..e064e4a5 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -18,8 +18,6 @@ namespace psemek::app SDL_Window * window = nullptr; SDL_GLContext gl_context = nullptr; - int width, height; - scene * current_scene = nullptr; bool running = false; @@ -96,7 +94,9 @@ namespace psemek::app gl::GetIntegerv(gl::MINOR_VERSION, &minor); log::info() << "Initialized OpenGL " << major << '.' << minor << ", " << vendor << ", " << renderer; - SDL_GetWindowSize(impl().window, &impl().width, &impl().height); + int width, height; + SDL_GetWindowSize(impl().window, &width, &height); + scene_base::on_resize(width, height); } app::~app() @@ -114,9 +114,8 @@ namespace psemek::app void app::on_resize(int width, int height) { + scene_base::on_resize(width, height); gl::Viewport(0, 0, width, height); - impl().width = width; - impl().height = height; } void app::on_quit() @@ -263,14 +262,4 @@ namespace psemek::app } } - int app::width() const - { - return impl().width; - } - - int app::height() const - { - return impl().height; - } - }