App bugfix: event handler can change while handling events

This commit is contained in:
Nikita Lisitsa 2021-02-19 10:43:07 +03:00
parent db2fb3095d
commit 0c45409dfe

View file

@ -125,7 +125,7 @@ namespace psemek::app
void app::poll_events()
{
auto handler = impl().get_scene();
auto handler = [this]{ return impl().get_scene(); };
for (SDL_Event e; SDL_PollEvent(&e);) switch (e.type)
{
@ -136,33 +136,33 @@ namespace psemek::app
{
case SDL_WINDOWEVENT_RESIZED:
impl().had_initial_resize = true;
handler->on_resize(e.window.data1, e.window.data2);
handler()->on_resize(e.window.data1, e.window.data2);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
handler->on_focus_gained();
handler()->on_focus_gained();
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
handler->on_focus_lost();
handler()->on_focus_lost();
break;
}
break;
case SDL_MOUSEMOTION:
handler->on_mouse_move(e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel);
handler()->on_mouse_move(e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel);
break;
case SDL_MOUSEWHEEL:
handler->on_mouse_wheel(e.wheel.y);
handler()->on_mouse_wheel(e.wheel.y);
break;
case SDL_MOUSEBUTTONDOWN:
switch (e.button.button)
{
case SDL_BUTTON_LEFT:
handler->on_left_button_down();
handler()->on_left_button_down();
break;
case SDL_BUTTON_MIDDLE:
handler->on_middle_button_down();
handler()->on_middle_button_down();
break;
case SDL_BUTTON_RIGHT:
handler->on_right_button_down();
handler()->on_right_button_down();
break;
}
break;
@ -170,21 +170,21 @@ namespace psemek::app
switch (e.button.button)
{
case SDL_BUTTON_LEFT:
handler->on_left_button_up();
handler()->on_left_button_up();
break;
case SDL_BUTTON_MIDDLE:
handler->on_middle_button_up();
handler()->on_middle_button_up();
break;
case SDL_BUTTON_RIGHT:
handler->on_right_button_up();
handler()->on_right_button_up();
break;
}
break;
case SDL_KEYDOWN:
handler->on_key_down(e.key.keysym.sym);
handler()->on_key_down(e.key.keysym.sym);
break;
case SDL_KEYUP:
handler->on_key_up(e.key.keysym.sym);
handler()->on_key_up(e.key.keysym.sym);
break;
}
}