diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-25 16:19:21 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-25 16:19:21 +0200 |
commit | a00ac8b5fed9d03cb2b3eafb4cd7d04546e341b1 (patch) | |
tree | 18bfeda1abd43a2a0b81f2ad4b909c30b9bfb419 /main/events.cpp | |
parent | 45f2533113a0dfe4cf8a7723a1c76099d0a6d091 (diff) |
move some headers around
Diffstat (limited to 'main/events.cpp')
-rw-r--r-- | main/events.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/main/events.cpp b/main/events.cpp new file mode 100644 index 00000000..ac8f0766 --- /dev/null +++ b/main/events.cpp @@ -0,0 +1,97 @@ +#include "main-impl.hpp" +#include "floormat/app.hpp" +#include "floormat/events.hpp" +#include "compat/assert.hpp" +#include <SDL_events.h> +#include <SDL_video.h> + +namespace floormat { + +void main_impl::viewportEvent(Platform::Sdl2Application::ViewportEvent& event) +{ + fm_assert(event.framebufferSize() == event.windowSize()); + recalc_viewport(event.windowSize()); + app.on_viewport_event(event.windowSize()); +} + +void main_impl::mousePressEvent(Platform::Sdl2Application::MouseEvent& event) +{ + app.on_mouse_up_down({event.position(), + (SDL_Keymod)(std::uint16_t)event.modifiers(), + mouse_button(SDL_BUTTON((std::uint8_t)event.button())), + std::uint8_t(std::min(255, event.clickCount()))}, + true); +} + +void main_impl::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event) +{ + app.on_mouse_up_down({event.position(), + (SDL_Keymod)(std::uint16_t)event.modifiers(), + mouse_button(SDL_BUTTON((std::uint8_t)event.button())), + std::uint8_t(std::min(255, event.clickCount()))}, + false); +} + +void main_impl::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event) +{ + app.on_mouse_move({event.position(), event.relativePosition(), + (mouse_button)(std::uint8_t)(std::uint32_t)event.buttons(), + (SDL_Keymod)(std::uint16_t)event.modifiers()}); +} + +void main_impl::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event) +{ + app.on_mouse_scroll({event.offset(), event.position(), + (SDL_Keymod)(std::uint16_t)event.modifiers()}); +} + +void main_impl::textInputEvent(Platform::Sdl2Application::TextInputEvent& event) +{ + app.on_text_input_event({event.text()}); +} + +#if 0 +void main_impl::textEditingEvent(Platform::Sdl2Application::TextEditingEvent& event) +{ + app.on_text_editing_event({event.text(), event.start(), event.length()}) +} +#endif + +void main_impl::keyPressEvent(Platform::Sdl2Application::KeyEvent& event) +{ + app.on_key_up_down({(SDL_Keycode)(std::uint32_t)event.key(), + (SDL_Keymod)(std::uint16_t)event.modifiers(), + event.isRepeated()}, + true); +} + +void main_impl::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event) +{ + app.on_key_up_down({(SDL_Keycode)(std::uint32_t)event.key(), + (SDL_Keymod)(std::uint16_t)event.modifiers(), + event.isRepeated()}, + false); +} + +void main_impl::anyEvent(SDL_Event& event) +{ + if (event.type == SDL_WINDOWEVENT) + switch (event.window.event) + { + case SDL_WINDOWEVENT_FOCUS_LOST: + return app.on_focus_out(); + case SDL_WINDOWEVENT_FOCUS_GAINED: + return app.on_focus_in(); + case SDL_WINDOWEVENT_LEAVE: + return app.on_mouse_leave(); + case SDL_WINDOWEVENT_ENTER: + return app.on_mouse_enter(); + default: + return app.on_any_event({event}); + } + else + return app.on_any_event({event}); +} + +} // namespace floormat + |