summaryrefslogtreecommitdiffhomepage
path: root/main
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-23 20:04:00 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-23 20:04:00 +0200
commitee869706042fefcb942b7283f68a5de3ecb011f8 (patch)
treeba1a279f1dd707308f0e04628b012928a82aca17 /main
parent4edf238a0d92e258cc6e11aa2aa4372613929213 (diff)
a
Diffstat (limited to 'main')
-rw-r--r--main/floormat-app.hpp2
-rw-r--r--main/floormat-events.cpp26
-rw-r--r--main/floormat-events.hpp5
3 files changed, 18 insertions, 15 deletions
diff --git a/main/floormat-app.hpp b/main/floormat-app.hpp
index dac9f077..805718a0 100644
--- a/main/floormat-app.hpp
+++ b/main/floormat-app.hpp
@@ -34,7 +34,7 @@ struct floormat_app
virtual bool on_text_input_event(const text_input_event& event) noexcept = 0;
virtual bool on_text_editing_event(const text_editing_event& event) noexcept = 0;
virtual void on_viewport_event(const Magnum::Math::Vector2<int>& size) noexcept = 0;
- virtual bool on_any_event(const any_event& event) noexcept = 0;
+ virtual void on_any_event(const any_event& event) noexcept = 0;
virtual void on_focus_in() noexcept = 0;
virtual void on_focus_out() noexcept = 0;
virtual void on_mouse_leave() noexcept = 0;
diff --git a/main/floormat-events.cpp b/main/floormat-events.cpp
index 527a979a..5e8aa278 100644
--- a/main/floormat-events.cpp
+++ b/main/floormat-events.cpp
@@ -26,10 +26,10 @@ void main_impl::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)
void main_impl::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)
{
- if (app.on_mouse_down({event.position(),
- (SDL_Keymod)(std::uint16_t)event.modifiers(),
- mouse_button(event.button()),
- std::uint8_t(std::min(255, event.clickCount()))}))
+ if (app.on_mouse_up({event.position(),
+ (SDL_Keymod)(std::uint16_t)event.modifiers(),
+ mouse_button(event.button()),
+ std::uint8_t(std::min(255, event.clickCount()))}))
return event.setAccepted();
}
@@ -70,12 +70,10 @@ void main_impl::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
void main_impl::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
{
- if (_imgui.handleKeyReleaseEvent(event))
- {
- keys = {};
+ if (app.on_key_up({(SDL_Keycode)(std::uint32_t)event.key(),
+ (SDL_Keymod)(std::uint16_t)event.modifiers(),
+ event.isRepeated()}))
return event.setAccepted();
- }
- do_key(event.key(), event.modifiers(), false, false);
}
void main_impl::anyEvent(SDL_Event& event)
@@ -84,15 +82,15 @@ void main_impl::anyEvent(SDL_Event& event)
switch (event.window.event)
{
case SDL_WINDOWEVENT_FOCUS_LOST:
- return app.event_focus_out();
+ return app.on_focus_out();
case SDL_WINDOWEVENT_FOCUS_GAINED:
- return app.event_focus_in();
+ return app.on_focus_in();
case SDL_WINDOWEVENT_LEAVE:
- return app.event_mouse_leave();
+ return app.on_mouse_leave();
case SDL_WINDOWEVENT_ENTER:
- return app.event_mouse_enter();
+ return app.on_mouse_enter();
default:
- std::fputs("", stdout); break; // put breakpoint here
+ return app.on_any_event({event});
}
}
} // namespace floormat
diff --git a/main/floormat-events.hpp b/main/floormat-events.hpp
index ba10ee9a..4d9376df 100644
--- a/main/floormat-events.hpp
+++ b/main/floormat-events.hpp
@@ -2,6 +2,7 @@
#include <Magnum/Math/Vector2.h>
#include <SDL_keycode.h>
#include <SDL_mouse.h>
+#include <SDL_events.h>
namespace floormat {
@@ -48,4 +49,8 @@ struct key_event final {
bool is_repeated = false;
};
+struct any_event final {
+ SDL_Event event = {};
+};
+
} // namespace floormat