From: Holger Schemel Date: Tue, 29 Nov 2016 19:40:02 +0000 (+0100) Subject: changed event filter to not set as SDL event filter, but call it manually X-Git-Tag: 4.0.0.0~12 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=a1fabab3e5db1baab46a95a318b27fdf33d470cc;p=rocksndiamonds.git changed event filter to not set as SDL event filter, but call it manually --- diff --git a/src/events.c b/src/events.c index 79821e98..d19ff880 100644 --- a/src/events.c +++ b/src/events.c @@ -46,7 +46,7 @@ static unsigned int special_cursor_delay_value = 1000; /* event filter addition for SDL2: as SDL2 does not have a function to enable or disable keyboard auto-repeat, filter repeated keyboard events instead */ -static int FilterEventsExt(const Event *event) +static int FilterEvents(const Event *event) { MotionEvent *motion; @@ -88,23 +88,11 @@ static int FilterEventsExt(const Event *event) return 1; } -#if defined(TARGET_SDL2) -int FilterEvents(void *userdata, Event *event) -{ - return FilterEventsExt(event); -} -#else -int FilterEvents(const Event *event) -{ - return FilterEventsExt(event); -} -#endif - /* to prevent delay problems, skip mouse motion events if the very next event is also a mouse motion event (and therefore effectively only handling the last of a row of mouse motion events in the event queue) */ -boolean SkipPressedMouseMotionEvent(const Event *event) +static boolean SkipPressedMouseMotionEvent(const Event *event) { /* nothing to do if the current event is not a mouse motion event */ if (event->type != EVENT_MOTIONNOTIFY) @@ -128,9 +116,13 @@ boolean SkipPressedMouseMotionEvent(const Event *event) return FALSE; } -/* this is only really needed for non-SDL targets to filter unwanted events; - when using SDL with properly installed event filter, this function can be - replaced with a simple "NextEvent()" call, but it doesn't hurt either */ +/* this is especially needed for event modifications for the Android target: + if mouse coordinates should be modified in the event filter function, + using a properly installed SDL event filter does not work, because in + the event filter, mouse coordinates in the event structure are still + physical pixel positions, not logical (scaled) screen positions, so this + has to be handled at a later stage in the event processing functions + (when device pixel positions are already converted to screen positions) */ boolean NextValidEvent(Event *event) { @@ -140,7 +132,7 @@ boolean NextValidEvent(Event *event) NextEvent(event); - if (FilterEventsExt(event)) + if (FilterEvents(event)) handle_this_event = TRUE; if (SkipPressedMouseMotionEvent(event)) diff --git a/src/events.h b/src/events.h index a809665c..e5d2dcc3 100644 --- a/src/events.h +++ b/src/events.h @@ -14,12 +14,6 @@ #include "main.h" -#if defined(TARGET_SDL2) -int FilterEvents(void *, Event *); -#else -int FilterEvents(const Event *); -#endif - boolean NextValidEvent(Event *); void EventLoop(void); diff --git a/src/init.c b/src/init.c index 28dcd41c..8595288c 100644 --- a/src/init.c +++ b/src/init.c @@ -5926,8 +5926,6 @@ void OpenAll() InitVideoDisplay(); InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen); - InitEventFilter(FilterEvents); - print_timestamp_time("[init video stuff]"); InitElementPropertiesStatic(); diff --git a/src/libgame/system.c b/src/libgame/system.c index 7d85f617..222b6f60 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1401,16 +1401,6 @@ void SetAudioMode(boolean enabled) /* event functions */ /* ========================================================================= */ -void InitEventFilter(EventFilter filter_function) -{ - /* set event filter to filter out certain events */ -#if defined(TARGET_SDL2) - SDL_SetEventFilter(filter_function, NULL); -#else - SDL_SetEventFilter(filter_function); -#endif -} - boolean PendingEvent(void) { return (SDL_PollEvent(NULL) ? TRUE : FALSE); diff --git a/src/libgame/system.h b/src/libgame/system.h index 64101094..a11c6b8e 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -723,14 +723,6 @@ } -/* type definitions */ -#if defined(TARGET_SDL2) -typedef int (*EventFilter)(void *, Event *); -#else -typedef int (*EventFilter)(const Event *); -#endif - - /* structure definitions */ struct ProgramInfo @@ -1494,7 +1486,6 @@ void OpenAudio(void); void CloseAudio(void); void SetAudioMode(boolean); -void InitEventFilter(EventFilter); boolean PendingEvent(void); void NextEvent(Event *event); void PeekEvent(Event *event);