diff options
author | ancarola <raffaele.ancarola@epfl.ch> | 2019-02-03 21:52:52 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-02-06 23:33:11 +0100 |
commit | 0d30bb843d3aeeacae211e1d0ba3cbf5faa01cd7 (patch) | |
tree | bbe7c5b43fb2f6b451336f69bef27153a84bbc24 /event.cpp | |
parent | Add basic texture wrapper (diff) | |
download | libwsdl2-master.tar.gz libwsdl2-master.zip |
List of basic events interfaces in namespace wsdl2::event
- event_t
- e_key
- mouse::e_mouse
- mouse::e_motion
- mouse::e_button
- e_quit (pure SDL quit callback)
- window::e_window
- window::e_resize
- window::e_move
Diffstat (limited to '')
-rw-r--r-- | event.cpp | 100 |
1 files changed, 92 insertions, 8 deletions
@@ -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 +// |