Make sure app::on_resize gets called at least once

This commit is contained in:
Nikita Lisitsa 2020-08-30 08:51:55 +03:00
parent a6316d27f4
commit de3f9cc8cc

View file

@ -41,6 +41,8 @@ namespace psemek::app
bool running = false;
bool had_initial_resize = false;
clock::time_point start_time;
~impl()
@ -131,6 +133,7 @@ namespace psemek::app
case SDL_WINDOWEVENT: switch (e.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
impl().had_initial_resize = true;
on_resize(e.window.data1, e.window.data2);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
@ -199,6 +202,13 @@ namespace psemek::app
while (running())
{
poll_events();
if (!impl().had_initial_resize)
{
int w, h;
SDL_GetWindowSize(impl().window, &w, &h);
impl().had_initial_resize = true;
on_resize(w, h);
}
if (!running()) break;
update();
draw();