42 #include "render/graphics.h"
78 SDL_EventState(SDL_VIDEOEXPOSE, SDL_IGNORE);
81 SDL_EventState(SDL_SYSWMEVENT,
mLogInput ? SDL_ENABLE : SDL_IGNORE);
82 SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
101 BLOCK_END(
"EventsManager::handleCommonEvents")
104 case SDL_WINDOWEVENT:
105 handleSDL2WindowEvent(event);
106 BLOCK_END(
"EventsManager::handleCommonEvents")
109 case SDL_VIDEORESIZE:
113 BLOCK_END(
"EventsManager::handleCommonEvents")
115 case SDL_ACTIVEEVENT:
117 BLOCK_END(
"EventsManager::handleCommonEvents")
120 case SDL_KEYBOARDSHOW:
122 BLOCK_END(
"EventsManager::handleCommonEvents")
124 case SDL_ACCELEROMETER:
134 BLOCK_END(
"EventsManager::handleCommonEvents")
138 BLOCK_END(
"EventsManager::handleCommonEvents")
164 case SDL_ACTIVEEVENT:
165 if ((event.active.state & SDL_APPACTIVE)
166 && !event.active.gain)
208 if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
209 game->updateHistory(event);
217 BLOCK_END(
"EventsManager::handleGameEvents")
222 if (name ==
"logInput")
231 #define winEventLog(name, name2) \
236 case SDL_MOUSEMOTION:
237 logger->
log(
"event: SDL_MOUSEMOTION: %u, %d,%d, %d,%d",
246 const SDL_TouchFingerEvent &touch =
event.tfinger;
249 logger->
log(
"event: SDL_FINGERDOWN: %u,%u (%f,%f) (%f,%f) %f",
252 touch.x * w, touch.y * w,
253 touch.dx * w, touch.dy * h,
259 const SDL_TouchFingerEvent &touch =
event.tfinger;
262 logger->
log(
"event: SDL_FINGERUP: %u,%u (%f,%f) (%f,%f) %f",
265 touch.x * w, touch.y * w,
266 touch.dx * w, touch.dy * h,
270 case SDL_FINGERMOTION:
272 const SDL_TouchFingerEvent &touch =
event.tfinger;
275 logger->
log(
"event: SDL_FINGERMOTION: %u,%u (%f,%f) (%f,%f) %f",
278 touch.x * w, touch.y * h,
279 touch.dx * w, touch.dy * h,
283 case SDL_MULTIGESTURE:
285 const SDL_MultiGestureEvent &gesture =
event.mgesture;
288 logger->
log(
"event: SDL_MULTIGESTURE: %u %f,%f (%f,%f) %d",
290 gesture.dTheta, gesture.dDist,
291 gesture.x * w, gesture.y * h,
296 logger->
log(
"event: SDL_KEYDOWN: %s(%d) %s(%d) %d,%d,%u",
297 SDL_GetScancodeName(event.key.keysym.scancode),
298 event.key.keysym.scancode,
299 SDL_GetKeyName(event.key.keysym.sym),
300 event.key.keysym.sym,
306 logger->
log(
"event: SDL_KEYUP: %s(%d) %s(%d) %d,%d,%u",
307 SDL_GetScancodeName(event.key.keysym.scancode),
308 event.key.keysym.scancode,
309 SDL_GetKeyName(event.key.keysym.sym),
310 event.key.keysym.sym,
315 case SDL_WINDOWEVENT:
317 const int data1 =
event.window.data1;
318 const int data2 =
event.window.data2;
320 switch (event.window.event)
322 winEventLog(SDL_WINDOWEVENT_NONE,
"SDL_WINDOWEVENT_NONE");
323 winEventLog(SDL_WINDOWEVENT_SHOWN,
"SDL_WINDOWEVENT_SHOWN");
324 winEventLog(SDL_WINDOWEVENT_HIDDEN,
"SDL_WINDOWEVENT_HIDDEN");
325 winEventLog(SDL_WINDOWEVENT_EXPOSED,
326 "SDL_WINDOWEVENT_EXPOSED");
327 winEventLog(SDL_WINDOWEVENT_MOVED,
"SDL_WINDOWEVENT_MOVED");
328 winEventLog(SDL_WINDOWEVENT_RESIZED,
329 "SDL_WINDOWEVENT_RESIZED");
330 winEventLog(SDL_WINDOWEVENT_SIZE_CHANGED,
331 "SDL_WINDOWEVENT_SIZE_CHANGED");
332 winEventLog(SDL_WINDOWEVENT_MINIMIZED,
333 "SDL_WINDOWEVENT_MINIMIZED");
334 winEventLog(SDL_WINDOWEVENT_MAXIMIZED,
335 "SDL_WINDOWEVENT_MAXIMIZED");
336 winEventLog(SDL_WINDOWEVENT_RESTORED,
337 "SDL_WINDOWEVENT_RESTORED");
338 winEventLog(SDL_WINDOWEVENT_ENTER,
"SDL_WINDOWEVENT_ENTER");
339 winEventLog(SDL_WINDOWEVENT_LEAVE,
"SDL_WINDOWEVENT_LEAVE");
340 winEventLog(SDL_WINDOWEVENT_FOCUS_GAINED,
341 "SDL_WINDOWEVENT_FOCUS_GAINED");
342 winEventLog(SDL_WINDOWEVENT_FOCUS_LOST,
343 "SDL_WINDOWEVENT_FOCUS_LOST");
344 winEventLog(SDL_WINDOWEVENT_CLOSE,
"SDL_WINDOWEVENT_CLOSE");
345 #if SDL_VERSION_ATLEAST(2, 0, 5)
346 winEventLog(SDL_WINDOWEVENT_TAKE_FOCUS,
347 "SDL_WINDOWEVENT_TAKE_FOCUS");
348 winEventLog(SDL_WINDOWEVENT_HIT_TEST,
349 "SDL_WINDOWEVENT_HIT_TEST");
356 logger->
log(
"event: SDL_WINDOWEVENT: %s: %d,%d",
357 str.c_str(), data1, data2);
362 const char *
const text =
event.text.text;
363 logger->
log(
"event: SDL_TEXTINPUT: %s", text);
364 const size_t sz = strlen(event.text.text);
365 for (
size_t f = 0; f < sz; f ++)
369 case SDL_APP_TERMINATING:
372 case SDL_APP_LOWMEMORY:
375 case SDL_APP_WILLENTERBACKGROUND:
376 logger->
log(
"SDL_APP_WILLENTERBACKGROUND");
378 case SDL_APP_WILLENTERFOREGROUND:
379 logger->
log(
"SDL_APP_WILLENTERFOREGROUND");
381 case SDL_APP_DIDENTERFOREGROUND:
382 logger->
log(
"SDL_APP_DIDENTERFOREGROUND");
384 case SDL_APP_DIDENTERBACKGROUND:
385 logger->
log(
"SDL_APP_DIDENTERBACKGROUND");
388 #if SDL_VERSION_ATLEAST(2, 0, 4)
389 logger->
log(
"event: SDL_MOUSEWHEEL: %u,%u, %d,%d, %u",
390 event.wheel.windowID,
394 event.wheel.direction);
397 logger->
log(
"event: SDL_MOUSEWHEEL: %u,%u, %d,%d",
398 event.wheel.windowID,
404 #if SDL_VERSION_ATLEAST(2, 0, 4)
405 case SDL_AUDIODEVICEADDED:
406 logger->
log(
"event: SDL_AUDIODEVICEADDED: %u,%u",
408 event.adevice.iscapture);
410 case SDL_KEYMAPCHANGED:
414 case SDL_MOUSEBUTTONDOWN:
415 logger->
log(
"event: SDL_MOUSEBUTTONDOWN: %u,%u,%u, %d,%d",
422 case SDL_MOUSEBUTTONUP:
423 logger->
log(
"event: SDL_MOUSEBUTTONUP: %u,%u,%u, %d,%d",
430 case SDL_JOYDEVICEADDED:
431 logger->
log(
"event: SDL_JOYDEVICEADDED: %d",
432 event.jdevice.which);
434 case SDL_JOYDEVICEREMOVED:
435 logger->
log(
"event: SDL_JOYDEVICEREMOVED: %d",
436 event.jdevice.which);
440 case SDL_MOUSEMOTION:
441 logger->
log(
"event: SDL_MOUSEMOTION: %u,%d,%d",
442 event.motion.state, event.motion.x, event.motion.y);
445 logger->
log(
"event: SDL_KEYDOWN: %s(%d),%d,%d,%d",
446 SDL_GetKeyName(event.key.keysym.sym),
447 event.key.keysym.sym,
448 event.key.keysym.scancode,
450 event.key.keysym.unicode);
453 logger->
log(
"event: SDL_KEYUP: %s(%d),%d,%d,%d",
454 SDL_GetKeyName(event.key.keysym.sym),
455 event.key.keysym.sym,
456 event.key.keysym.scancode,
458 event.key.keysym.unicode);
460 case SDL_VIDEORESIZE:
463 case SDL_VIDEOEXPOSE:
466 case SDL_ACTIVEEVENT:
467 logger->
log(
"event: SDL_ACTIVEEVENT: %d %d",
468 event.active.state, event.active.gain);
470 case SDL_MOUSEBUTTONDOWN:
471 logger->
log(
"event: SDL_MOUSEBUTTONDOWN: %d,%d, %d,%d",
477 case SDL_MOUSEBUTTONUP:
478 logger->
log(
"event: SDL_MOUSEBUTTONUP: %d,%d,%d,%d",
486 case SDL_JOYAXISMOTION:
487 logger->
log(
"event: SDL_JOYAXISMOTION: %d,%d,%d",
488 event.jaxis.which, event.jaxis.axis, event.jaxis.value);
490 case SDL_JOYBALLMOTION:
491 logger->
log(
"event: SDL_JOYBALLMOTION: %d,%d,%d,%d",
492 event.jball.which, event.jball.ball,
493 event.jball.xrel, event.jball.yrel);
495 case SDL_JOYHATMOTION:
496 logger->
log(
"event: SDL_JOYHATMOTION: %d,%d,%d", event.jhat.which,
497 event.jhat.hat, event.jhat.value);
499 case SDL_JOYBUTTONDOWN:
500 logger->
log(
"event: SDL_JOYBUTTONDOWN: %d,%d,%d",
501 event.jbutton.which, event.jbutton.button,
502 event.jbutton.state);
504 case SDL_JOYBUTTONUP:
505 logger->
log(
"event: SDL_JOYBUTTONUP: %d,%d,%d",
506 event.jbutton.which, event.jbutton.button,
507 event.jbutton.state);
515 const bool res = X11Logger::logEvent(event);
531 case SDL_ACCELEROMETER:
545 void EventsManager::handleSDL2WindowEvent(
const SDL_Event &event)
551 const int eventType =
event.window.event;
555 case SDL_WINDOWEVENT_RESIZED:
560 case SDL_WINDOWEVENT_ENTER:
563 case SDL_WINDOWEVENT_LEAVE:
566 case SDL_WINDOWEVENT_FOCUS_GAINED:
569 #if SDL_VERSION_ATLEAST(2, 0, 5)
570 case SDL_WINDOWEVENT_TAKE_FOCUS:
575 case SDL_WINDOWEVENT_FOCUS_LOST:
578 case SDL_WINDOWEVENT_MINIMIZED:
588 case SDL_WINDOWEVENT_RESTORED:
589 case SDL_WINDOWEVENT_MAXIMIZED:
607 if (eventType == SDL_WINDOWEVENT_MINIMIZED
608 || eventType == SDL_WINDOWEVENT_RESTORED
609 || eventType == SDL_WINDOWEVENT_MAXIMIZED)
629 if ((event.active.state & SDL_APPACTIVE) != 0)
631 if (event.active.gain != 0U)
672 if ((event.active.state & SDL_APPINPUTFOCUS) != 0)
677 if ((event.active.state & SDL_APPMOUSEFOCUS) != 0)
uint8_t getDirection() const
void setState(const StateT state)
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void removeListeners(ConfigListener *const listener)
int getIntValue(const std::string &key) const
void optionChanged(const std::string &name)
bool handleEvents() const
void handleGameEvents() const
bool handleCommonEvents(const SDL_Event &event) const
static void logEvent(const SDL_Event &event)
static void handleActive(const SDL_Event &event)
void updateFrameRate(int fpsLimit)
void setHalfAway(const bool n)
void updateStatus() const
void log(const char *const log_text,...)
void assertLog(const char *const log_text,...)
void log1(const char *const log_text)
KeyboardFocusT inputFocused
EventsManager eventsManager
LocalPlayer * localPlayer
bool PollEvent(SDL_Event *event)
void updateScreenKeyboard(const int height)
void setIsMinimized(const bool n)
void resizeVideo(int actualWidth, int actualHeight, const bool always)
#define BLOCK_START(name)
void setPriority(const bool big)
std::string strprintf(const char *const format,...)