static void HandleEventActions(void);
+// event filter to set mouse x/y position (for pointer class global animations)
+// (this is especially required to ensure smooth global animation mouse pointer
+// movement when the screen is updated without handling events; this can happen
+// when drawing door/envelope request animations, for example)
+
+int FilterMouseMotionEvents(void *userdata, Event *event)
+{
+ if (event->type != EVENT_MOTIONNOTIFY)
+ return 1;
+
+ int mouse_x = ((MotionEvent *)event)->x;
+ int mouse_y = ((MotionEvent *)event)->y;
+
+ // mouse events do not contain logical screen size corrections at this stage
+ SDLCorrectMouseEventXY(&mouse_x, &mouse_y);
+
+ mouse_x -= video.screen_xoffset;
+ mouse_y -= video.screen_yoffset;
+
+ gfx.mouse_x = mouse_x;
+ gfx.mouse_y = mouse_y;
+
+ return 1;
+}
+
// event filter especially needed for SDL event filtering due to
// delay problems with lots of mouse motion events when mouse button
// not pressed (X11 can handle this with 'PointerMotionHintMask')
{
((MotionEvent *)event)->x -= video.screen_xoffset;
((MotionEvent *)event)->y -= video.screen_yoffset;
-
- gfx.mouse_x = ((MotionEvent *)event)->x;
- gfx.mouse_y = ((MotionEvent *)event)->y;
}
// non-motion events are directly passed to event handler functions
#define USEREVENT_ANIM_EVENT_ACTION 2
+int FilterMouseMotionEvents(void *, Event *);
boolean NextValidEvent(Event *);
void EventLoop(void);
InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
InitVideoOverlay();
+ InitEventFilter(FilterMouseMotionEvents);
+
print_timestamp_time("[init video stuff]");
InitElementPropertiesStatic();
SDL_WaitEvent(event);
}
+void SDLCorrectMouseEventXY(int *x, int *y)
+{
+ if (sdl_renderer == NULL)
+ return;
+
+ // this corrects the raw mouse position for logical screen size within event
+ // filters (correction done later by SDL library when handling mouse events)
+
+ SDL_Rect viewport;
+ float scale_x, scale_y;
+
+ SDL_RenderGetViewport(sdl_renderer, &viewport);
+ SDL_RenderGetScale(sdl_renderer, &scale_x, &scale_y);
+
+ *x = (int)(*x / scale_x);
+ *y = (int)(*y / scale_y);
+
+ *x -= viewport.x;
+ *y -= viewport.y;
+}
+
// ============================================================================
// joystick functions
typedef SDL_WindowEvent WindowEvent;
typedef SDL_KeyboardEvent KeyEvent;
+typedef SDL_EventFilter EventFilter;
+
// structure definitions
void SDLCloseAudio(void);
void SDLWaitEvent(Event *);
+void SDLCorrectMouseEventXY(int *, int *);
void HandleJoystickEvent(Event *);
void SDLInitJoysticks(void);
// event functions
// ============================================================================
+void InitEventFilter(EventFilter filter_function)
+{
+ SDL_SetEventFilter(filter_function, NULL);
+}
+
boolean PendingEvent(void)
{
return (SDL_PollEvent(NULL) ? TRUE : FALSE);
void CloseAudio(void);
void SetAudioMode(boolean);
+void InitEventFilter(EventFilter);
boolean PendingEvent(void);
void WaitEvent(Event *event);
void PeekEvent(Event *event);