Store width & height in scene_base
This commit is contained in:
parent
1b9e769b3f
commit
c714d6b73a
3 changed files with 12 additions and 17 deletions
|
|
@ -35,8 +35,6 @@ namespace psemek::app
|
||||||
void vsync(bool on);
|
void vsync(bool on);
|
||||||
|
|
||||||
float time() const;
|
float time() const;
|
||||||
int width() const;
|
|
||||||
int height() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
psemek_declare_pimpl
|
psemek_declare_pimpl
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ namespace psemek::app
|
||||||
struct scene_base
|
struct scene_base
|
||||||
: scene
|
: 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_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_down() override { left_button_down_ = true; }
|
||||||
void on_left_button_up() override { left_button_down_ = false; }
|
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; }
|
bool is_key_down(SDL_Keycode key) const { return keys_.count(key) > 0; }
|
||||||
|
|
||||||
|
int width() const { return width_; }
|
||||||
|
int height() const { return height_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int width_ = 0;
|
||||||
|
int height_ = 0;
|
||||||
|
|
||||||
bool left_button_down_ = false;
|
bool left_button_down_ = false;
|
||||||
bool middle_button_down_ = false;
|
bool middle_button_down_ = false;
|
||||||
bool right_button_down_ = false;
|
bool right_button_down_ = false;
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ namespace psemek::app
|
||||||
SDL_Window * window = nullptr;
|
SDL_Window * window = nullptr;
|
||||||
SDL_GLContext gl_context = nullptr;
|
SDL_GLContext gl_context = nullptr;
|
||||||
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
scene * current_scene = nullptr;
|
scene * current_scene = nullptr;
|
||||||
|
|
||||||
bool running = false;
|
bool running = false;
|
||||||
|
|
@ -96,7 +94,9 @@ namespace psemek::app
|
||||||
gl::GetIntegerv(gl::MINOR_VERSION, &minor);
|
gl::GetIntegerv(gl::MINOR_VERSION, &minor);
|
||||||
log::info() << "Initialized OpenGL " << major << '.' << minor << ", " << vendor << ", " << renderer;
|
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()
|
app::~app()
|
||||||
|
|
@ -114,9 +114,8 @@ namespace psemek::app
|
||||||
|
|
||||||
void app::on_resize(int width, int height)
|
void app::on_resize(int width, int height)
|
||||||
{
|
{
|
||||||
|
scene_base::on_resize(width, height);
|
||||||
gl::Viewport(0, 0, width, height);
|
gl::Viewport(0, 0, width, height);
|
||||||
impl().width = width;
|
|
||||||
impl().height = height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void app::on_quit()
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue