21 #include "hx3d/window/sdl2/sdl2_events.hpp" 23 #include "hx3d/core/core.hpp" 24 #include "hx3d/window/application.hpp" 25 #include "hx3d/window/input_handler.hpp" 27 #include <SDL2/SDL_events.h> 35 while (SDL_PollEvent(&event)) {
36 if (event.type == SDL_WINDOWEVENT) {
39 switch (event.window.event) {
40 case SDL_WINDOWEVENT_CLOSE:
43 case SDL_WINDOWEVENT_SHOWN:
46 case SDL_WINDOWEVENT_MOVED:
57 else if (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) {
61 switch (event.button.button) {
65 case SDL_BUTTON_RIGHT:
68 case SDL_BUTTON_MIDDLE:
81 unsigned int position =
static_cast<unsigned int>(key);
82 if (type == MouseButtonEvent::Type::Released) {
105 if (type == MouseButtonEvent::Type::Released) {
124 else if (event.type == SDL_MOUSEMOTION) {
142 else if (event.type == SDL_MOUSEWHEEL) {
145 if (event.wheel.x > 0)
147 else if (event.wheel.x < 0)
149 else if (event.wheel.y > 0)
151 else if (event.wheel.y < 0)
154 unsigned int position =
static_cast<unsigned int>(direction);
164 else if (event.type == SDL_FINGERUP || event.type == SDL_FINGERDOWN) {
170 if (type == TouchEvent::Type::Released) {
200 else if (event.type == SDL_FINGERMOTION) {
202 _touchMovement = glm::vec2(event.tfinger.dx, event.tfinger.dy) * 300.f;
211 else if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) {
215 if (event.key.repeat) {
219 switch (event.key.keysym.sym) {
221 key = KeyEvent::Key::A;
224 key = KeyEvent::Key::B;
227 key = KeyEvent::Key::C;
230 key = KeyEvent::Key::D;
233 key = KeyEvent::Key::E;
236 key = KeyEvent::Key::Q;
239 key = KeyEvent::Key::S;
242 key = KeyEvent::Key::Z;
245 key = KeyEvent::Key::Space;
248 key = KeyEvent::Key::Escape;
251 key = KeyEvent::Key::Return;
254 key = KeyEvent::Key::AndroidBack;
257 key = KeyEvent::Key::AndroidMenu;
263 unsigned int position =
static_cast<unsigned int>(key);
265 if (type == KeyEvent::Type::Released) {
float _touchPressure
Touch pressure.
bool * _keysReleased
Keys released.
glm::vec2 _mouseMovement
Mouse movement.
bool * _mouseButtonReleased
Mouse buttons released.
bool _touchSimulation
Is touch simulated with mouse ?
static window::Application * App()
Get the application instance.
glm::vec2 _mousePosition
Mouse position.
InputHandler * _currentHandler
Current input handler.
bool * _mouseButtonClicked
Mouse buttons clicked.
bool * _keysPressed
Keys pressed.
bool _screenTouched
Screen touched ?
Direction
Mouse wheel direction.
glm::vec2 _mouseWheelMovement
Mouse wheel movement.
bool * _mouseWheelTurned
Mouse wheels turned.
virtual void poll() override
Poll the event queue.
bool _screenReleased
Screen released ?
bool * _windowEvents
Window events.
glm::vec2 _touchPosition
Touch position.
int getHeight()
Get the window height.
glm::vec2 _touchMovement
Touch movement.
int getWidth()
Get the window width.