summaryrefslogtreecommitdiffstats
path: root/event.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--event.cpp100
1 files changed, 92 insertions, 8 deletions
diff --git a/event.cpp b/event.cpp
index 60d432e..a6830e6 100644
--- a/event.cpp
+++ b/event.cpp
@@ -1,21 +1,105 @@
#include "event.hpp"
-
-#include <optional>
+#include "video.hpp"
extern "C" {
#include <SDL2/SDL.h>
}
-wsdl2::event::event(const SDL_Event& e) {
- m_event = e;
+using namespace wsdl2::event;
+
+event_t::event_t(const SDL_Event& e) : m_event(e) {}
+
+event_t::event_t(const event_t& e) : m_event(e.m_event) {}
+
+uint32_t event_t::type() const
+{
+ return m_event.type;
}
-std::optional<wsdl2::event> wsdl2::poll_event() {
+std::shared_ptr<event_t> poll_event() {
+
SDL_Event ev;
+#define EV_PTR(__type__) std::make_shared<event_t>(ev)
+
+ using namespace wsdl2::event;
+
if (SDL_PollEvent(&ev) != 0) {
- return event(ev);
+
+ switch (ev.type)
+ {
+
+ // keyboard events
+ case SDL_KEYUP:
+ return EV_PTR(e_key);
+ case SDL_KEYDOWN:
+ return EV_PTR(e_key);
+
+ // mouse events
+ case SDL_MOUSEMOTION:
+ return EV_PTR(mouse::e_motion);
+ case SDL_MOUSEBUTTONDOWN:
+ return EV_PTR(mouse::e_button);
+ case SDL_MOUSEBUTTONUP:
+ return EV_PTR(mouse::e_button);
+ case SDL_MOUSEWHEEL:
+ return EV_PTR(mouse::e_wheel);
+
+ // sdl quit event
+ case SDL_QUIT:
+ return EV_PTR(e_quit);
+
+ // window events
+ case SDL_WINDOWEVENT:
+
+ switch (ev.window.event)
+ {
+ case (SDL_WINDOWEVENT_MOVED):
+ return EV_PTR(window::e_move);
+ case (SDL_WINDOWEVENT_RESIZED):
+ return EV_PTR(window::e_resize);
+ case (SDL_WINDOWEVENT_SIZE_CHANGED):
+ return EV_PTR(window::e_resize);
+ default:
+ return EV_PTR(window::e_window);
+ }
+ }
+
+ return nullptr;
}
- return std::nullopt;
-} \ No newline at end of file
+ return nullptr;
+}
+
+
+/*
+ * Keyboard
+ */
+
+e_key::action_t e_key::action() const
+{
+ return static_cast<e_key::action_t>(sdl().type);
+}
+
+SDL_Keycode e_key::get() const
+{
+ return sdl().key.keysym.sym;
+}
+
+/*
+ * Mouse
+ */
+
+mouse::action_t mouse::e_mouse::action() const
+{
+ return static_cast<mouse::action_t>(sdl().type);
+}
+
+mm::vec2<int> mouse::e_mouse::location() const
+{
+ // TODO
+ return mm::vec2<int>({});
+}
+
+// TODO other structures
+//