Store window size in base app

This commit is contained in:
Nikita Lisitsa 2020-10-02 19:19:19 +03:00
parent eb1f5d49ff
commit b47a95a158
2 changed files with 18 additions and 0 deletions

View file

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

View file

@ -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<std::chrono::duration<float>>(clock::now() - impl().start_time).count();
}
int app::width() const
{
return impl().width;
}
int app::height() const
{
return impl().height;
}
}