From 722f4104bf04e178e4b775e089d5c054763839c1 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Wed, 6 Mar 2024 20:14:53 +0100 Subject: [PATCH] Use enums as types in SDL_*Event structures The main `SDL_Event` union is not using the enum as valid user events types are not in the enum. --- include/SDL3/SDL_events.h | 58 +++++++++++++++++++------------------- src/events/SDL_mouse.c | 2 +- src/test/SDL_test_common.c | 2 +- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h index 66673705a..3c133f5a9 100644 --- a/include/SDL3/SDL_events.h +++ b/include/SDL3/SDL_events.h @@ -245,7 +245,7 @@ typedef struct SDL_CommonEvent */ typedef struct SDL_DisplayEvent { - Uint32 type; /**< ::SDL_DISPLAYEVENT_* */ + SDL_EventType type; /**< ::SDL_DISPLAYEVENT_* */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_DisplayID displayID;/**< The associated display */ @@ -257,7 +257,7 @@ typedef struct SDL_DisplayEvent */ typedef struct SDL_WindowEvent { - Uint32 type; /**< ::SDL_WINDOWEVENT_* */ + SDL_EventType type; /**< ::SDL_WINDOWEVENT_* */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The associated window */ @@ -270,7 +270,7 @@ typedef struct SDL_WindowEvent */ typedef struct SDL_KeyboardEvent { - Uint32 type; /**< ::SDL_EVENT_KEY_DOWN or ::SDL_EVENT_KEY_UP */ + SDL_EventType type; /**< ::SDL_EVENT_KEY_DOWN or ::SDL_EVENT_KEY_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with keyboard focus, if any */ @@ -290,7 +290,7 @@ typedef struct SDL_KeyboardEvent */ typedef struct SDL_TextEditingEvent { - Uint32 type; /**< ::SDL_EVENT_TEXT_EDITING */ + SDL_EventType type; /**< ::SDL_EVENT_TEXT_EDITING */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with keyboard focus, if any */ @@ -308,7 +308,7 @@ typedef struct SDL_TextEditingEvent */ typedef struct SDL_TextInputEvent { - Uint32 type; /**< ::SDL_EVENT_TEXT_INPUT */ + SDL_EventType type; /**< ::SDL_EVENT_TEXT_INPUT */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with keyboard focus, if any */ @@ -320,7 +320,7 @@ typedef struct SDL_TextInputEvent */ typedef struct SDL_MouseMotionEvent { - Uint32 type; /**< ::SDL_EVENT_MOUSE_MOTION */ + SDL_EventType type; /**< ::SDL_EVENT_MOUSE_MOTION */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with mouse focus, if any */ @@ -337,7 +337,7 @@ typedef struct SDL_MouseMotionEvent */ typedef struct SDL_MouseButtonEvent { - Uint32 type; /**< ::SDL_EVENT_MOUSE_BUTTON_DOWN or ::SDL_EVENT_MOUSE_BUTTON_UP */ + SDL_EventType type; /**< ::SDL_EVENT_MOUSE_BUTTON_DOWN or ::SDL_EVENT_MOUSE_BUTTON_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with mouse focus, if any */ @@ -355,14 +355,14 @@ typedef struct SDL_MouseButtonEvent */ typedef struct SDL_MouseWheelEvent { - Uint32 type; /**< ::SDL_EVENT_MOUSE_WHEEL */ + SDL_EventType type; /**< ::SDL_EVENT_MOUSE_WHEEL */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with mouse focus, if any */ SDL_MouseID which; /**< The mouse instance id, SDL_TOUCH_MOUSEID, or SDL_PEN_MOUSEID */ float x; /**< The amount scrolled horizontally, positive to the right and negative to the left */ float y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */ - Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */ + SDL_MouseWheelDirection direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */ float mouse_x; /**< X coordinate, relative to window */ float mouse_y; /**< Y coordinate, relative to window */ } SDL_MouseWheelEvent; @@ -372,7 +372,7 @@ typedef struct SDL_MouseWheelEvent */ typedef struct SDL_JoyAxisEvent { - Uint32 type; /**< ::SDL_EVENT_JOYSTICK_AXIS_MOTION */ + SDL_EventType type; /**< ::SDL_EVENT_JOYSTICK_AXIS_MOTION */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -389,7 +389,7 @@ typedef struct SDL_JoyAxisEvent */ typedef struct SDL_JoyHatEvent { - Uint32 type; /**< ::SDL_EVENT_JOYSTICK_HAT_MOTION */ + SDL_EventType type; /**< ::SDL_EVENT_JOYSTICK_HAT_MOTION */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -410,7 +410,7 @@ typedef struct SDL_JoyHatEvent */ typedef struct SDL_JoyButtonEvent { - Uint32 type; /**< ::SDL_EVENT_JOYSTICK_BUTTON_DOWN or ::SDL_EVENT_JOYSTICK_BUTTON_UP */ + SDL_EventType type; /**< ::SDL_EVENT_JOYSTICK_BUTTON_DOWN or ::SDL_EVENT_JOYSTICK_BUTTON_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -425,7 +425,7 @@ typedef struct SDL_JoyButtonEvent */ typedef struct SDL_JoyDeviceEvent { - Uint32 type; /**< ::SDL_EVENT_JOYSTICK_ADDED or ::SDL_EVENT_JOYSTICK_REMOVED or ::SDL_EVENT_JOYSTICK_UPDATE_COMPLETE */ + SDL_EventType type; /**< ::SDL_EVENT_JOYSTICK_ADDED or ::SDL_EVENT_JOYSTICK_REMOVED or ::SDL_EVENT_JOYSTICK_UPDATE_COMPLETE */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -436,7 +436,7 @@ typedef struct SDL_JoyDeviceEvent */ typedef struct SDL_JoyBatteryEvent { - Uint32 type; /**< ::SDL_EVENT_JOYSTICK_BATTERY_UPDATED */ + SDL_EventType type; /**< ::SDL_EVENT_JOYSTICK_BATTERY_UPDATED */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -448,7 +448,7 @@ typedef struct SDL_JoyBatteryEvent */ typedef struct SDL_GamepadAxisEvent { - Uint32 type; /**< ::SDL_EVENT_GAMEPAD_AXIS_MOTION */ + SDL_EventType type; /**< ::SDL_EVENT_GAMEPAD_AXIS_MOTION */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -466,7 +466,7 @@ typedef struct SDL_GamepadAxisEvent */ typedef struct SDL_GamepadButtonEvent { - Uint32 type; /**< ::SDL_EVENT_GAMEPAD_BUTTON_DOWN or ::SDL_EVENT_GAMEPAD_BUTTON_UP */ + SDL_EventType type; /**< ::SDL_EVENT_GAMEPAD_BUTTON_DOWN or ::SDL_EVENT_GAMEPAD_BUTTON_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -482,7 +482,7 @@ typedef struct SDL_GamepadButtonEvent */ typedef struct SDL_GamepadDeviceEvent { - Uint32 type; /**< ::SDL_EVENT_GAMEPAD_ADDED, ::SDL_EVENT_GAMEPAD_REMOVED, or ::SDL_EVENT_GAMEPAD_REMAPPED, ::SDL_EVENT_GAMEPAD_UPDATE_COMPLETE or ::SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED */ + SDL_EventType type; /**< ::SDL_EVENT_GAMEPAD_ADDED, ::SDL_EVENT_GAMEPAD_REMOVED, or ::SDL_EVENT_GAMEPAD_REMAPPED, ::SDL_EVENT_GAMEPAD_UPDATE_COMPLETE or ::SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -493,7 +493,7 @@ typedef struct SDL_GamepadDeviceEvent */ typedef struct SDL_GamepadTouchpadEvent { - Uint32 type; /**< ::SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or ::SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or ::SDL_EVENT_GAMEPAD_TOUCHPAD_UP */ + SDL_EventType type; /**< ::SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or ::SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or ::SDL_EVENT_GAMEPAD_TOUCHPAD_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -509,7 +509,7 @@ typedef struct SDL_GamepadTouchpadEvent */ typedef struct SDL_GamepadSensorEvent { - Uint32 type; /**< ::SDL_EVENT_GAMEPAD_SENSOR_UPDATE */ + SDL_EventType type; /**< ::SDL_EVENT_GAMEPAD_SENSOR_UPDATE */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_JoystickID which; /**< The joystick instance id */ @@ -523,7 +523,7 @@ typedef struct SDL_GamepadSensorEvent */ typedef struct SDL_AudioDeviceEvent { - Uint32 type; /**< ::SDL_EVENT_AUDIO_DEVICE_ADDED, or ::SDL_EVENT_AUDIO_DEVICE_REMOVED, or ::SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED */ + SDL_EventType type; /**< ::SDL_EVENT_AUDIO_DEVICE_ADDED, or ::SDL_EVENT_AUDIO_DEVICE_REMOVED, or ::SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed or changing */ @@ -538,7 +538,7 @@ typedef struct SDL_AudioDeviceEvent */ typedef struct SDL_CameraDeviceEvent { - Uint32 type; /**< ::SDL_EVENT_CAMERA_DEVICE_ADDED, ::SDL_EVENT_CAMERA_DEVICE_REMOVED, ::SDL_EVENT_CAMERA_DEVICE_APPROVED, ::SDL_EVENT_CAMERA_DEVICE_DENIED */ + SDL_EventType type; /**< ::SDL_EVENT_CAMERA_DEVICE_ADDED, ::SDL_EVENT_CAMERA_DEVICE_REMOVED, ::SDL_EVENT_CAMERA_DEVICE_APPROVED, ::SDL_EVENT_CAMERA_DEVICE_DENIED */ Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_CameraDeviceID which; /**< SDL_CameraDeviceID for the device being added or removed or changing */ Uint8 padding1; @@ -551,7 +551,7 @@ typedef struct SDL_CameraDeviceEvent */ typedef struct SDL_TouchFingerEvent { - Uint32 type; /**< ::SDL_EVENT_FINGER_MOTION or ::SDL_EVENT_FINGER_DOWN or ::SDL_EVENT_FINGER_UP */ + SDL_EventType type; /**< ::SDL_EVENT_FINGER_MOTION or ::SDL_EVENT_FINGER_DOWN or ::SDL_EVENT_FINGER_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_TouchID touchID; /**< The touch device id */ @@ -571,7 +571,7 @@ typedef struct SDL_TouchFingerEvent */ typedef struct SDL_PenTipEvent { - Uint32 type; /**< ::SDL_EVENT_PEN_DOWN or ::SDL_EVENT_PEN_UP */ + SDL_EventType type; /**< ::SDL_EVENT_PEN_DOWN or ::SDL_EVENT_PEN_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with pen focus, if any */ @@ -589,7 +589,7 @@ typedef struct SDL_PenTipEvent */ typedef struct SDL_PenMotionEvent { - Uint32 type; /**< ::SDL_EVENT_PEN_MOTION */ + SDL_EventType type; /**< ::SDL_EVENT_PEN_MOTION */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with pen focus, if any */ @@ -607,7 +607,7 @@ typedef struct SDL_PenMotionEvent */ typedef struct SDL_PenButtonEvent { - Uint32 type; /**< ::SDL_EVENT_PEN_BUTTON_DOWN or ::SDL_EVENT_PEN_BUTTON_UP */ + SDL_EventType type; /**< ::SDL_EVENT_PEN_BUTTON_DOWN or ::SDL_EVENT_PEN_BUTTON_UP */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window with pen focus, if any */ @@ -628,7 +628,7 @@ typedef struct SDL_PenButtonEvent */ typedef struct SDL_DropEvent { - Uint32 type; /**< ::SDL_EVENT_DROP_BEGIN or ::SDL_EVENT_DROP_FILE or ::SDL_EVENT_DROP_TEXT or ::SDL_EVENT_DROP_COMPLETE or ::SDL_EVENT_DROP_POSITION */ + SDL_EventType type; /**< ::SDL_EVENT_DROP_BEGIN or ::SDL_EVENT_DROP_FILE or ::SDL_EVENT_DROP_TEXT or ::SDL_EVENT_DROP_COMPLETE or ::SDL_EVENT_DROP_POSITION */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_WindowID windowID; /**< The window that was dropped on, if any */ @@ -643,7 +643,7 @@ typedef struct SDL_DropEvent */ typedef struct SDL_ClipboardEvent { - Uint32 type; /**< ::SDL_EVENT_CLIPBOARD_UPDATE */ + SDL_EventType type; /**< ::SDL_EVENT_CLIPBOARD_UPDATE */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ } SDL_ClipboardEvent; @@ -653,7 +653,7 @@ typedef struct SDL_ClipboardEvent */ typedef struct SDL_SensorEvent { - Uint32 type; /**< ::SDL_EVENT_SENSOR_UPDATE */ + SDL_EventType type; /**< ::SDL_EVENT_SENSOR_UPDATE */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ SDL_SensorID which; /**< The instance ID of the sensor */ @@ -666,7 +666,7 @@ typedef struct SDL_SensorEvent */ typedef struct SDL_QuitEvent { - Uint32 type; /**< ::SDL_EVENT_QUIT */ + SDL_EventType type; /**< ::SDL_EVENT_QUIT */ Uint32 reserved; Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ } SDL_QuitEvent; diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index c7cf857cb..07693b131 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -879,7 +879,7 @@ int SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID event.wheel.which = mouseID; event.wheel.x = x; event.wheel.y = y; - event.wheel.direction = (Uint32)direction; + event.wheel.direction = direction; event.wheel.mouse_x = mouse->x; event.wheel.mouse_y = mouse->y; posted = (SDL_PushEvent(&event) > 0); diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index c6cf3f2fd..42d45c409 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1708,7 +1708,7 @@ static void SDLTest_PrintEvent(const SDL_Event *event) event->button.windowID); break; case SDL_EVENT_MOUSE_WHEEL: - SDL_Log("SDL EVENT: Mouse: wheel scrolled %g in x and %g in y (reversed: %" SDL_PRIu32 ") in window %" SDL_PRIu32, + SDL_Log("SDL EVENT: Mouse: wheel scrolled %g in x and %g in y (reversed: %d) in window %" SDL_PRIu32, event->wheel.x, event->wheel.y, event->wheel.direction, event->wheel.windowID); break; case SDL_EVENT_JOYSTICK_ADDED: