Store width & height in scene_base

This commit is contained in:
Nikita Lisitsa 2021-02-17 12:43:44 +03:00
parent 1b9e769b3f
commit c714d6b73a
3 changed files with 12 additions and 17 deletions

View file

@ -35,8 +35,6 @@ namespace psemek::app
void vsync(bool on);
float time() const;
int width() const;
int height() const;
private:
psemek_declare_pimpl

View file

@ -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;

View file

@ -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;
}
}