From 942e577775b82ccf16816db6744c0bdc493c718d Mon Sep 17 00:00:00 2001 From: peterino2 Date: Sun, 25 Jan 2026 02:02:31 -0800 Subject: [PATCH] saving --- build.zig | 2 +- json/events.json | 2404 ++++++++++++++++++++++++++++++++++++++++++ src/header_cache.zig | 442 ++++++++ src/parser.zig | 278 +++-- v2/events.zig | 770 ++++++++++++++ v2/loadso.zig | 2 +- v2/render.zig | 1157 ++++++++++++++++++++ v2/storage.zig | 114 ++ v2/surface.zig | 325 ++++++ v2/video.zig | 2 +- 10 files changed, 5334 insertions(+), 162 deletions(-) create mode 100644 json/events.json create mode 100644 src/header_cache.zig create mode 100644 v2/events.zig create mode 100644 v2/render.zig create mode 100644 v2/storage.zig create mode 100644 v2/surface.zig diff --git a/build.zig b/build.zig index 37cbdd6..1616907 100644 --- a/build.zig +++ b/build.zig @@ -112,7 +112,7 @@ pub fn generateApi(b: *std.Build, parser_exe: *std.Build.Step.Compile, fetch_sdl .{ .header = "SDL_dialog.h", .output = "dialog" }, .{ .header = "SDL_endian.h", .output = "endian" }, .{ .header = "SDL_error.h", .output = "error" }, - // .{ .header = "SDL_events.h", .output = "events" }, + .{ .header = "SDL_events.h", .output = "events" }, .{ .header = "SDL_filesystem.h", .output = "filesystem" }, .{ .header = "SDL_gamepad.h", .output = "gamepad" }, .{ .header = "SDL_gpu.h", .output = "gpu" }, diff --git a/json/events.json b/json/events.json new file mode 100644 index 0000000..2698065 --- /dev/null +++ b/json/events.json @@ -0,0 +1,2404 @@ +{ + "header": "SDL_events.h", + "opaque_types": [], + "typedefs": [], + "function_pointers": [], + "c_type_aliases": [ + { + "name": "SDL_EventFilter" + } + ], + "enums": [ + { + "name": "SDL_EventType", + "values": [ + { + "name": "SDL_EVENT_FIRST", + "value": "0", + "comment": "Unused (do not remove)" + }, + { + "name": "SDL_EVENT_QUIT", + "value": "0x100", + "comment": "User-requested quit" + }, + { + "name": "SDL_EVENT_TERMINATING" + }, + { + "name": "SDL_EVENT_LOW_MEMORY" + }, + { + "name": "SDL_EVENT_WILL_ENTER_BACKGROUND" + }, + { + "name": "SDL_EVENT_DID_ENTER_BACKGROUND" + }, + { + "name": "SDL_EVENT_WILL_ENTER_FOREGROUND" + }, + { + "name": "SDL_EVENT_DID_ENTER_FOREGROUND" + }, + { + "name": "SDL_EVENT_LOCALE_CHANGED", + "comment": "The user's locale preferences have changed." + }, + { + "name": "SDL_EVENT_SYSTEM_THEME_CHANGED", + "comment": "The system theme changed" + }, + { + "name": "SDL_EVENT_DISPLAY_ORIENTATION", + "value": "0x151", + "comment": "Display orientation has changed to data1" + }, + { + "name": "SDL_EVENT_DISPLAY_ADDED", + "comment": "Display has been added to the system" + }, + { + "name": "SDL_EVENT_DISPLAY_REMOVED", + "comment": "Display has been removed from the system" + }, + { + "name": "SDL_EVENT_DISPLAY_MOVED", + "comment": "Display has changed position" + }, + { + "name": "SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED", + "comment": "Display has changed desktop mode" + }, + { + "name": "SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED", + "comment": "Display has changed current mode" + }, + { + "name": "SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED", + "comment": "Display has changed content scale" + }, + { + "name": "SDL_EVENT_WINDOW_SHOWN", + "value": "0x202", + "comment": "Window has been shown" + }, + { + "name": "SDL_EVENT_WINDOW_HIDDEN", + "comment": "Window has been hidden" + }, + { + "name": "SDL_EVENT_WINDOW_EXPOSED", + "comment": "Window has been exposed and should be redrawn, and can be redrawn directly from event watchers for this event" + }, + { + "name": "SDL_EVENT_WINDOW_MOVED", + "comment": "Window has been moved to data1, data2" + }, + { + "name": "SDL_EVENT_WINDOW_RESIZED", + "comment": "Window has been resized to data1xdata2" + }, + { + "name": "SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED", + "comment": "The pixel size of the window has changed to data1xdata2" + }, + { + "name": "SDL_EVENT_WINDOW_METAL_VIEW_RESIZED", + "comment": "The pixel size of a Metal view associated with the window has changed" + }, + { + "name": "SDL_EVENT_WINDOW_MINIMIZED", + "comment": "Window has been minimized" + }, + { + "name": "SDL_EVENT_WINDOW_MAXIMIZED", + "comment": "Window has been maximized" + }, + { + "name": "SDL_EVENT_WINDOW_RESTORED", + "comment": "Window has been restored to normal size and position" + }, + { + "name": "SDL_EVENT_WINDOW_MOUSE_ENTER", + "comment": "Window has gained mouse focus" + }, + { + "name": "SDL_EVENT_WINDOW_MOUSE_LEAVE", + "comment": "Window has lost mouse focus" + }, + { + "name": "SDL_EVENT_WINDOW_FOCUS_GAINED", + "comment": "Window has gained keyboard focus" + }, + { + "name": "SDL_EVENT_WINDOW_FOCUS_LOST", + "comment": "Window has lost keyboard focus" + }, + { + "name": "SDL_EVENT_WINDOW_CLOSE_REQUESTED", + "comment": "The window manager requests that the window be closed" + }, + { + "name": "SDL_EVENT_WINDOW_HIT_TEST", + "comment": "Window had a hit test that wasn't SDL_HITTEST_NORMAL" + }, + { + "name": "SDL_EVENT_WINDOW_ICCPROF_CHANGED", + "comment": "The ICC profile of the window's display has changed" + }, + { + "name": "SDL_EVENT_WINDOW_DISPLAY_CHANGED", + "comment": "Window has been moved to display data1" + }, + { + "name": "SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED", + "comment": "Window display scale has been changed" + }, + { + "name": "SDL_EVENT_WINDOW_SAFE_AREA_CHANGED", + "comment": "The window safe area has been changed" + }, + { + "name": "SDL_EVENT_WINDOW_OCCLUDED", + "comment": "The window has been occluded" + }, + { + "name": "SDL_EVENT_WINDOW_ENTER_FULLSCREEN", + "comment": "The window has entered fullscreen mode" + }, + { + "name": "SDL_EVENT_WINDOW_LEAVE_FULLSCREEN", + "comment": "The window has left fullscreen mode" + }, + { + "name": "SDL_EVENT_WINDOW_DESTROYED" + }, + { + "name": "SDL_EVENT_WINDOW_HDR_STATE_CHANGED", + "comment": "Window HDR properties have changed" + }, + { + "name": "SDL_EVENT_KEY_DOWN", + "value": "0x300", + "comment": "Key pressed" + }, + { + "name": "SDL_EVENT_KEY_UP", + "comment": "Key released" + }, + { + "name": "SDL_EVENT_TEXT_EDITING", + "comment": "Keyboard text editing (composition)" + }, + { + "name": "SDL_EVENT_TEXT_INPUT", + "comment": "Keyboard text input" + }, + { + "name": "SDL_EVENT_KEYMAP_CHANGED" + }, + { + "name": "SDL_EVENT_KEYBOARD_ADDED", + "comment": "A new keyboard has been inserted into the system" + }, + { + "name": "SDL_EVENT_KEYBOARD_REMOVED", + "comment": "A keyboard has been removed" + }, + { + "name": "SDL_EVENT_TEXT_EDITING_CANDIDATES", + "comment": "Keyboard text editing candidates" + }, + { + "name": "SDL_EVENT_MOUSE_MOTION", + "value": "0x400", + "comment": "Mouse moved" + }, + { + "name": "SDL_EVENT_MOUSE_BUTTON_DOWN", + "comment": "Mouse button pressed" + }, + { + "name": "SDL_EVENT_MOUSE_BUTTON_UP", + "comment": "Mouse button released" + }, + { + "name": "SDL_EVENT_MOUSE_WHEEL", + "comment": "Mouse wheel motion" + }, + { + "name": "SDL_EVENT_MOUSE_ADDED", + "comment": "A new mouse has been inserted into the system" + }, + { + "name": "SDL_EVENT_MOUSE_REMOVED", + "comment": "A mouse has been removed" + }, + { + "name": "SDL_EVENT_JOYSTICK_AXIS_MOTION", + "value": "0x600", + "comment": "Joystick axis motion" + }, + { + "name": "SDL_EVENT_JOYSTICK_BALL_MOTION", + "comment": "Joystick trackball motion" + }, + { + "name": "SDL_EVENT_JOYSTICK_HAT_MOTION", + "comment": "Joystick hat position change" + }, + { + "name": "SDL_EVENT_JOYSTICK_BUTTON_DOWN", + "comment": "Joystick button pressed" + }, + { + "name": "SDL_EVENT_JOYSTICK_BUTTON_UP", + "comment": "Joystick button released" + }, + { + "name": "SDL_EVENT_JOYSTICK_ADDED", + "comment": "A new joystick has been inserted into the system" + }, + { + "name": "SDL_EVENT_JOYSTICK_REMOVED", + "comment": "An opened joystick has been removed" + }, + { + "name": "SDL_EVENT_JOYSTICK_BATTERY_UPDATED", + "comment": "Joystick battery level change" + }, + { + "name": "SDL_EVENT_JOYSTICK_UPDATE_COMPLETE", + "comment": "Joystick update is complete" + }, + { + "name": "SDL_EVENT_GAMEPAD_AXIS_MOTION", + "value": "0x650", + "comment": "Gamepad axis motion" + }, + { + "name": "SDL_EVENT_GAMEPAD_BUTTON_DOWN", + "comment": "Gamepad button pressed" + }, + { + "name": "SDL_EVENT_GAMEPAD_BUTTON_UP", + "comment": "Gamepad button released" + }, + { + "name": "SDL_EVENT_GAMEPAD_ADDED", + "comment": "A new gamepad has been inserted into the system" + }, + { + "name": "SDL_EVENT_GAMEPAD_REMOVED", + "comment": "A gamepad has been removed" + }, + { + "name": "SDL_EVENT_GAMEPAD_REMAPPED", + "comment": "The gamepad mapping was updated" + }, + { + "name": "SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN", + "comment": "Gamepad touchpad was touched" + }, + { + "name": "SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION", + "comment": "Gamepad touchpad finger was moved" + }, + { + "name": "SDL_EVENT_GAMEPAD_TOUCHPAD_UP", + "comment": "Gamepad touchpad finger was lifted" + }, + { + "name": "SDL_EVENT_GAMEPAD_SENSOR_UPDATE", + "comment": "Gamepad sensor was updated" + }, + { + "name": "SDL_EVENT_GAMEPAD_UPDATE_COMPLETE", + "comment": "Gamepad update is complete" + }, + { + "name": "SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED", + "comment": "Gamepad Steam handle has changed" + }, + { + "name": "SDL_EVENT_FINGER_UP" + }, + { + "name": "SDL_EVENT_FINGER_MOTION" + }, + { + "name": "SDL_EVENT_FINGER_CANCELED" + }, + { + "name": "SDL_EVENT_CLIPBOARD_UPDATE", + "value": "0x900", + "comment": "The clipboard or primary selection changed" + }, + { + "name": "SDL_EVENT_DROP_FILE", + "value": "0x1000", + "comment": "The system requests a file open" + }, + { + "name": "SDL_EVENT_DROP_TEXT", + "comment": "text/plain drag-and-drop event" + }, + { + "name": "SDL_EVENT_DROP_BEGIN", + "comment": "A new set of drops is beginning (NULL filename)" + }, + { + "name": "SDL_EVENT_DROP_COMPLETE", + "comment": "Current set of drops is now complete (NULL filename)" + }, + { + "name": "SDL_EVENT_DROP_POSITION", + "comment": "Position while moving over the window" + }, + { + "name": "SDL_EVENT_AUDIO_DEVICE_ADDED", + "value": "0x1100", + "comment": "A new audio device is available" + }, + { + "name": "SDL_EVENT_AUDIO_DEVICE_REMOVED", + "comment": "An audio device has been removed." + }, + { + "name": "SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED", + "comment": "An audio device's format has been changed by the system." + }, + { + "name": "SDL_EVENT_SENSOR_UPDATE", + "value": "0x1200", + "comment": "A sensor was updated" + }, + { + "name": "SDL_EVENT_PEN_PROXIMITY_IN", + "value": "0x1300", + "comment": "Pressure-sensitive pen has become available" + }, + { + "name": "SDL_EVENT_PEN_PROXIMITY_OUT", + "comment": "Pressure-sensitive pen has become unavailable" + }, + { + "name": "SDL_EVENT_PEN_DOWN", + "comment": "Pressure-sensitive pen touched drawing surface" + }, + { + "name": "SDL_EVENT_PEN_UP", + "comment": "Pressure-sensitive pen stopped touching drawing surface" + }, + { + "name": "SDL_EVENT_PEN_BUTTON_DOWN", + "comment": "Pressure-sensitive pen button pressed" + }, + { + "name": "SDL_EVENT_PEN_BUTTON_UP", + "comment": "Pressure-sensitive pen button released" + }, + { + "name": "SDL_EVENT_PEN_MOTION", + "comment": "Pressure-sensitive pen is moving on the tablet" + }, + { + "name": "SDL_EVENT_PEN_AXIS", + "comment": "Pressure-sensitive pen angle/pressure/etc changed" + }, + { + "name": "SDL_EVENT_CAMERA_DEVICE_ADDED", + "value": "0x1400", + "comment": "A new camera device is available" + }, + { + "name": "SDL_EVENT_CAMERA_DEVICE_REMOVED", + "comment": "A camera device has been removed." + }, + { + "name": "SDL_EVENT_CAMERA_DEVICE_APPROVED", + "comment": "A camera device has been approved for use by the user." + }, + { + "name": "SDL_EVENT_CAMERA_DEVICE_DENIED", + "comment": "A camera device has been denied for use by the user." + }, + { + "name": "SDL_EVENT_RENDER_TARGETS_RESET", + "value": "0x2000", + "comment": "The render targets have been reset and their contents need to be updated" + }, + { + "name": "SDL_EVENT_RENDER_DEVICE_RESET", + "comment": "The device has been reset and all textures need to be recreated" + }, + { + "name": "SDL_EVENT_RENDER_DEVICE_LOST", + "comment": "The device has been lost and can't be recovered." + }, + { + "name": "SDL_EVENT_PRIVATE1" + }, + { + "name": "SDL_EVENT_PRIVATE2" + }, + { + "name": "SDL_EVENT_PRIVATE3" + }, + { + "name": "SDL_EVENT_POLL_SENTINEL", + "value": "0x7F00", + "comment": "Signals the end of an event poll cycle" + } + ] + }, + { + "name": "SDL_EventAction", + "values": [ + { + "name": "SDL_ADDEVENT", + "comment": "Add events to the back of the queue." + }, + { + "name": "SDL_PEEKEVENT", + "comment": "Check but don't remove events from the queue front." + }, + { + "name": "SDL_GETEVENT", + "comment": "Retrieve/remove events from the front of the queue." + } + ] + } + ], + "structs": [ + { + "name": "SDL_CommonEvent", + "fields": [ + { + "name": "_type", + "type": "Uint32", + "comment": "Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + } + ] + }, + { + "name": "SDL_DisplayEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_DISPLAYEVENT_*" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "displayID", + "type": "SDL_DisplayID", + "comment": "The associated display" + }, + { + "name": "data1", + "type": "Sint32", + "comment": "event dependent data" + }, + { + "name": "data2", + "type": "Sint32", + "comment": "event dependent data" + } + ] + }, + { + "name": "SDL_WindowEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_WINDOW_*" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The associated window" + }, + { + "name": "data1", + "type": "Sint32", + "comment": "event dependent data" + }, + { + "name": "data2", + "type": "Sint32", + "comment": "event dependent data" + } + ] + }, + { + "name": "SDL_KeyboardDeviceEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_KEYBOARD_ADDED or SDL_EVENT_KEYBOARD_REMOVED" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_KeyboardID", + "comment": "The keyboard instance id" + } + ] + }, + { + "name": "SDL_KeyboardEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_KEY_DOWN or SDL_EVENT_KEY_UP" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with keyboard focus, if any" + }, + { + "name": "which", + "type": "SDL_KeyboardID", + "comment": "The keyboard instance id, or 0 if unknown or virtual" + }, + { + "name": "scancode", + "type": "SDL_Scancode", + "comment": "SDL physical key code" + }, + { + "name": "key", + "type": "SDL_Keycode", + "comment": "SDL virtual key code" + }, + { + "name": "mod", + "type": "SDL_Keymod", + "comment": "current key modifiers" + }, + { + "name": "raw", + "type": "Uint16", + "comment": "The platform dependent scancode for this event" + }, + { + "name": "down", + "type": "bool", + "comment": "true if the key is pressed" + }, + { + "name": "repeat", + "type": "bool", + "comment": "true if this is a key repeat" + } + ] + }, + { + "name": "SDL_TextEditingEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_TEXT_EDITING" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with keyboard focus, if any" + }, + { + "name": "text", + "type": "const char *", + "comment": "The editing text" + }, + { + "name": "start", + "type": "Sint32", + "comment": "The start cursor of selected editing text, or -1 if not set" + }, + { + "name": "length", + "type": "Sint32", + "comment": "The length of selected editing text, or -1 if not set" + } + ] + }, + { + "name": "SDL_TextEditingCandidatesEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_TEXT_EDITING_CANDIDATES" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with keyboard focus, if any" + }, + { + "name": "candidates", + "type": "const char * const *", + "comment": "The list of candidates, or NULL if there are no candidates available" + }, + { + "name": "num_candidates", + "type": "Sint32", + "comment": "The number of strings in `candidates`" + }, + { + "name": "selected_candidate", + "type": "Sint32", + "comment": "The index of the selected candidate, or -1 if no candidate is selected" + }, + { + "name": "horizontal", + "type": "bool", + "comment": "true if the list is horizontal, false if it's vertical" + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + }, + { + "name": "padding3", + "type": "Uint8" + } + ] + }, + { + "name": "SDL_TextInputEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_TEXT_INPUT" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with keyboard focus, if any" + }, + { + "name": "text", + "type": "const char *", + "comment": "The input text, UTF-8 encoded" + } + ] + }, + { + "name": "SDL_MouseDeviceEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_MOUSE_ADDED or SDL_EVENT_MOUSE_REMOVED" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_MouseID", + "comment": "The mouse instance id" + } + ] + }, + { + "name": "SDL_MouseMotionEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_MOUSE_MOTION" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with mouse focus, if any" + }, + { + "name": "which", + "type": "SDL_MouseID", + "comment": "The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0" + }, + { + "name": "state", + "type": "SDL_MouseButtonFlags", + "comment": "The current button state" + }, + { + "name": "x", + "type": "float", + "comment": "X coordinate, relative to window" + }, + { + "name": "y", + "type": "float", + "comment": "Y coordinate, relative to window" + }, + { + "name": "xrel", + "type": "float", + "comment": "The relative motion in the X direction" + }, + { + "name": "yrel", + "type": "float", + "comment": "The relative motion in the Y direction" + } + ] + }, + { + "name": "SDL_MouseButtonEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_MOUSE_BUTTON_DOWN or SDL_EVENT_MOUSE_BUTTON_UP" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with mouse focus, if any" + }, + { + "name": "which", + "type": "SDL_MouseID", + "comment": "The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0" + }, + { + "name": "button", + "type": "Uint8", + "comment": "The mouse button index" + }, + { + "name": "down", + "type": "bool", + "comment": "true if the button is pressed" + }, + { + "name": "clicks", + "type": "Uint8", + "comment": "1 for single-click, 2 for double-click, etc." + }, + { + "name": "padding", + "type": "Uint8" + }, + { + "name": "x", + "type": "float", + "comment": "X coordinate, relative to window" + }, + { + "name": "y", + "type": "float", + "comment": "Y coordinate, relative to window" + } + ] + }, + { + "name": "SDL_MouseWheelEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_MOUSE_WHEEL" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with mouse focus, if any" + }, + { + "name": "which", + "type": "SDL_MouseID", + "comment": "The mouse instance id in relative mode or 0" + }, + { + "name": "x", + "type": "float", + "comment": "The amount scrolled horizontally, positive to the right and negative to the left" + }, + { + "name": "y", + "type": "float", + "comment": "The amount scrolled vertically, positive away from the user and negative toward the user" + }, + { + "name": "direction", + "type": "SDL_MouseWheelDirection", + "comment": "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" + }, + { + "name": "mouse_x", + "type": "float", + "comment": "X coordinate, relative to window" + }, + { + "name": "mouse_y", + "type": "float", + "comment": "Y coordinate, relative to window" + }, + { + "name": "integer_x", + "type": "Sint32", + "comment": "The amount scrolled horizontally, accumulated to whole scroll \"ticks\" (added in 3.2.12)" + }, + { + "name": "integer_y", + "type": "Sint32", + "comment": "The amount scrolled vertically, accumulated to whole scroll \"ticks\" (added in 3.2.12)" + } + ] + }, + { + "name": "SDL_JoyAxisEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_JOYSTICK_AXIS_MOTION" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "axis", + "type": "Uint8", + "comment": "The joystick axis index" + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + }, + { + "name": "padding3", + "type": "Uint8" + }, + { + "name": "value", + "type": "Sint16", + "comment": "The axis value (range: -32768 to 32767)" + }, + { + "name": "padding4", + "type": "Uint16" + } + ] + }, + { + "name": "SDL_JoyBallEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_JOYSTICK_BALL_MOTION" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "ball", + "type": "Uint8", + "comment": "The joystick trackball index" + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + }, + { + "name": "padding3", + "type": "Uint8" + }, + { + "name": "xrel", + "type": "Sint16", + "comment": "The relative motion in the X direction" + }, + { + "name": "yrel", + "type": "Sint16", + "comment": "The relative motion in the Y direction" + } + ] + }, + { + "name": "SDL_JoyHatEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_JOYSTICK_HAT_MOTION" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "hat", + "type": "Uint8", + "comment": "The joystick hat index" + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + } + ] + }, + { + "name": "SDL_JoyButtonEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_JOYSTICK_BUTTON_DOWN or SDL_EVENT_JOYSTICK_BUTTON_UP" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "button", + "type": "Uint8", + "comment": "The joystick button index" + }, + { + "name": "down", + "type": "bool", + "comment": "true if the button is pressed" + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + } + ] + }, + { + "name": "SDL_JoyDeviceEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_JOYSTICK_ADDED or SDL_EVENT_JOYSTICK_REMOVED or SDL_EVENT_JOYSTICK_UPDATE_COMPLETE" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + } + ] + }, + { + "name": "SDL_JoyBatteryEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_JOYSTICK_BATTERY_UPDATED" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "state", + "type": "SDL_PowerState", + "comment": "The joystick battery state" + }, + { + "name": "percent", + "type": "int", + "comment": "The joystick battery percent charge remaining" + } + ] + }, + { + "name": "SDL_GamepadAxisEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_GAMEPAD_AXIS_MOTION" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "axis", + "type": "Uint8", + "comment": "The gamepad axis (SDL_GamepadAxis)" + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + }, + { + "name": "padding3", + "type": "Uint8" + }, + { + "name": "value", + "type": "Sint16", + "comment": "The axis value (range: -32768 to 32767)" + }, + { + "name": "padding4", + "type": "Uint16" + } + ] + }, + { + "name": "SDL_GamepadButtonEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_GAMEPAD_BUTTON_DOWN or SDL_EVENT_GAMEPAD_BUTTON_UP" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "button", + "type": "Uint8", + "comment": "The gamepad button (SDL_GamepadButton)" + }, + { + "name": "down", + "type": "bool", + "comment": "true if the button is pressed" + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + } + ] + }, + { + "name": "SDL_GamepadDeviceEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "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" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + } + ] + }, + { + "name": "SDL_GamepadTouchpadEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or SDL_EVENT_GAMEPAD_TOUCHPAD_UP" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "touchpad", + "type": "Sint32", + "comment": "The index of the touchpad" + }, + { + "name": "finger", + "type": "Sint32", + "comment": "The index of the finger on the touchpad" + }, + { + "name": "x", + "type": "float", + "comment": "Normalized in the range 0...1 with 0 being on the left" + }, + { + "name": "y", + "type": "float", + "comment": "Normalized in the range 0...1 with 0 being at the top" + }, + { + "name": "pressure", + "type": "float", + "comment": "Normalized in the range 0...1" + } + ] + }, + { + "name": "SDL_GamepadSensorEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_GAMEPAD_SENSOR_UPDATE" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_JoystickID", + "comment": "The joystick instance id" + }, + { + "name": "sensor", + "type": "Sint32", + "comment": "The type of the sensor, one of the values of SDL_SensorType" + }, + { + "name": "data", + "type": "float[3]", + "comment": "Up to 3 values from the sensor, as defined in SDL_sensor.h" + }, + { + "name": "sensor_timestamp", + "type": "Uint64", + "comment": "The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock" + } + ] + }, + { + "name": "SDL_AudioDeviceEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_AUDIO_DEVICE_ADDED, or SDL_EVENT_AUDIO_DEVICE_REMOVED, or SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_AudioDeviceID", + "comment": "SDL_AudioDeviceID for the device being added or removed or changing" + }, + { + "name": "recording", + "type": "bool", + "comment": "false if a playback device, true if a recording device." + }, + { + "name": "padding1", + "type": "Uint8" + }, + { + "name": "padding2", + "type": "Uint8" + }, + { + "name": "padding3", + "type": "Uint8" + } + ] + }, + { + "name": "SDL_CameraDeviceEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_CAMERA_DEVICE_ADDED, SDL_EVENT_CAMERA_DEVICE_REMOVED, SDL_EVENT_CAMERA_DEVICE_APPROVED, SDL_EVENT_CAMERA_DEVICE_DENIED" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_CameraID", + "comment": "SDL_CameraID for the device being added or removed or changing" + } + ] + }, + { + "name": "SDL_RenderEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_RENDER_TARGETS_RESET, SDL_EVENT_RENDER_DEVICE_RESET, SDL_EVENT_RENDER_DEVICE_LOST" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window containing the renderer in question." + } + ] + }, + { + "name": "SDL_TouchFingerEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_UP, SDL_EVENT_FINGER_MOTION, or SDL_EVENT_FINGER_CANCELED" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "touchID", + "type": "SDL_TouchID", + "comment": "The touch device id" + }, + { + "name": "fingerID", + "type": "SDL_FingerID" + }, + { + "name": "x", + "type": "float", + "comment": "Normalized in the range 0...1" + }, + { + "name": "y", + "type": "float", + "comment": "Normalized in the range 0...1" + }, + { + "name": "dx", + "type": "float", + "comment": "Normalized in the range -1...1" + }, + { + "name": "dy", + "type": "float", + "comment": "Normalized in the range -1...1" + }, + { + "name": "pressure", + "type": "float", + "comment": "Normalized in the range 0...1" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window underneath the finger, if any" + } + ] + }, + { + "name": "SDL_PenProximityEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_PEN_PROXIMITY_IN or SDL_EVENT_PEN_PROXIMITY_OUT" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with pen focus, if any" + }, + { + "name": "which", + "type": "SDL_PenID", + "comment": "The pen instance id" + } + ] + }, + { + "name": "SDL_PenMotionEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_PEN_MOTION" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with pen focus, if any" + }, + { + "name": "which", + "type": "SDL_PenID", + "comment": "The pen instance id" + }, + { + "name": "pen_state", + "type": "SDL_PenInputFlags", + "comment": "Complete pen input state at time of event" + }, + { + "name": "x", + "type": "float", + "comment": "X coordinate, relative to window" + }, + { + "name": "y", + "type": "float", + "comment": "Y coordinate, relative to window" + } + ] + }, + { + "name": "SDL_PenTouchEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_PEN_DOWN or SDL_EVENT_PEN_UP" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with pen focus, if any" + }, + { + "name": "which", + "type": "SDL_PenID", + "comment": "The pen instance id" + }, + { + "name": "pen_state", + "type": "SDL_PenInputFlags", + "comment": "Complete pen input state at time of event" + }, + { + "name": "x", + "type": "float", + "comment": "X coordinate, relative to window" + }, + { + "name": "y", + "type": "float", + "comment": "Y coordinate, relative to window" + }, + { + "name": "eraser", + "type": "bool", + "comment": "true if eraser end is used (not all pens support this)." + }, + { + "name": "down", + "type": "bool", + "comment": "true if the pen is touching or false if the pen is lifted off" + } + ] + }, + { + "name": "SDL_PenButtonEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_PEN_BUTTON_DOWN or SDL_EVENT_PEN_BUTTON_UP" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with mouse focus, if any" + }, + { + "name": "which", + "type": "SDL_PenID", + "comment": "The pen instance id" + }, + { + "name": "pen_state", + "type": "SDL_PenInputFlags", + "comment": "Complete pen input state at time of event" + }, + { + "name": "x", + "type": "float", + "comment": "X coordinate, relative to window" + }, + { + "name": "y", + "type": "float", + "comment": "Y coordinate, relative to window" + }, + { + "name": "button", + "type": "Uint8", + "comment": "The pen button index (first button is 1)." + }, + { + "name": "down", + "type": "bool", + "comment": "true if the button is pressed" + } + ] + }, + { + "name": "SDL_PenAxisEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_PEN_AXIS" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window with pen focus, if any" + }, + { + "name": "which", + "type": "SDL_PenID", + "comment": "The pen instance id" + }, + { + "name": "pen_state", + "type": "SDL_PenInputFlags", + "comment": "Complete pen input state at time of event" + }, + { + "name": "x", + "type": "float", + "comment": "X coordinate, relative to window" + }, + { + "name": "y", + "type": "float", + "comment": "Y coordinate, relative to window" + }, + { + "name": "axis", + "type": "SDL_PenAxis", + "comment": "Axis that has changed" + }, + { + "name": "value", + "type": "float", + "comment": "New value of axis" + } + ] + }, + { + "name": "SDL_DropEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_DROP_BEGIN or SDL_EVENT_DROP_FILE or SDL_EVENT_DROP_TEXT or SDL_EVENT_DROP_COMPLETE or SDL_EVENT_DROP_POSITION" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The window that was dropped on, if any" + }, + { + "name": "x", + "type": "float", + "comment": "X coordinate, relative to window (not on begin)" + }, + { + "name": "y", + "type": "float", + "comment": "Y coordinate, relative to window (not on begin)" + }, + { + "name": "source", + "type": "const char *", + "comment": "The source app that sent this drop event, or NULL if that isn't available" + }, + { + "name": "data", + "type": "const char *", + "comment": "The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events" + } + ] + }, + { + "name": "SDL_ClipboardEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_CLIPBOARD_UPDATE" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "owner", + "type": "bool", + "comment": "are we owning the clipboard (internal update)" + }, + { + "name": "num_mime_types", + "type": "Sint32", + "comment": "number of mime types" + }, + { + "name": "mime_types", + "type": "const char **", + "comment": "current mime types" + } + ] + }, + { + "name": "SDL_SensorEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_SENSOR_UPDATE" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "which", + "type": "SDL_SensorID", + "comment": "The instance ID of the sensor" + }, + { + "name": "data", + "type": "float[6]", + "comment": "Up to 6 values from the sensor - additional values can be queried using SDL_GetSensorData()" + }, + { + "name": "sensor_timestamp", + "type": "Uint64", + "comment": "The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock" + } + ] + }, + { + "name": "SDL_QuitEvent", + "fields": [ + { + "name": "_type", + "type": "SDL_EventType", + "comment": "SDL_EVENT_QUIT" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + } + ] + }, + { + "name": "SDL_UserEvent", + "fields": [ + { + "name": "_type", + "type": "Uint32", + "comment": "SDL_EVENT_USER through SDL_EVENT_LAST-1, Uint32 because these are not in the SDL_EventType enumeration" + }, + { + "name": "reserved", + "type": "Uint32" + }, + { + "name": "timestamp", + "type": "Uint64", + "comment": "In nanoseconds, populated using SDL_GetTicksNS()" + }, + { + "name": "windowID", + "type": "SDL_WindowID", + "comment": "The associated window if any" + }, + { + "name": "code", + "type": "Sint32", + "comment": "User defined event code" + }, + { + "name": "data1", + "type": "void *", + "comment": "User defined data pointer" + }, + { + "name": "data2", + "type": "void *", + "comment": "User defined data pointer" + } + ] + } + ], + "unions": [ + { + "name": "SDL_Event", + "fields": [ + { + "name": "_type", + "type": "Uint32", + "comment": "Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration" + }, + { + "name": "common", + "type": "SDL_CommonEvent", + "comment": "Common event data" + }, + { + "name": "display", + "type": "SDL_DisplayEvent", + "comment": "Display event data" + }, + { + "name": "window", + "type": "SDL_WindowEvent", + "comment": "Window event data" + }, + { + "name": "kdevice", + "type": "SDL_KeyboardDeviceEvent", + "comment": "Keyboard device change event data" + }, + { + "name": "key", + "type": "SDL_KeyboardEvent", + "comment": "Keyboard event data" + }, + { + "name": "edit", + "type": "SDL_TextEditingEvent", + "comment": "Text editing event data" + }, + { + "name": "edit_candidates", + "type": "SDL_TextEditingCandidatesEvent", + "comment": "Text editing candidates event data" + }, + { + "name": "text", + "type": "SDL_TextInputEvent", + "comment": "Text input event data" + }, + { + "name": "mdevice", + "type": "SDL_MouseDeviceEvent", + "comment": "Mouse device change event data" + }, + { + "name": "motion", + "type": "SDL_MouseMotionEvent", + "comment": "Mouse motion event data" + }, + { + "name": "button", + "type": "SDL_MouseButtonEvent", + "comment": "Mouse button event data" + }, + { + "name": "wheel", + "type": "SDL_MouseWheelEvent", + "comment": "Mouse wheel event data" + }, + { + "name": "jdevice", + "type": "SDL_JoyDeviceEvent", + "comment": "Joystick device change event data" + }, + { + "name": "jaxis", + "type": "SDL_JoyAxisEvent", + "comment": "Joystick axis event data" + }, + { + "name": "jball", + "type": "SDL_JoyBallEvent", + "comment": "Joystick ball event data" + }, + { + "name": "jhat", + "type": "SDL_JoyHatEvent", + "comment": "Joystick hat event data" + }, + { + "name": "jbutton", + "type": "SDL_JoyButtonEvent", + "comment": "Joystick button event data" + }, + { + "name": "jbattery", + "type": "SDL_JoyBatteryEvent", + "comment": "Joystick battery event data" + }, + { + "name": "gdevice", + "type": "SDL_GamepadDeviceEvent", + "comment": "Gamepad device event data" + }, + { + "name": "gaxis", + "type": "SDL_GamepadAxisEvent", + "comment": "Gamepad axis event data" + }, + { + "name": "gbutton", + "type": "SDL_GamepadButtonEvent", + "comment": "Gamepad button event data" + }, + { + "name": "gtouchpad", + "type": "SDL_GamepadTouchpadEvent", + "comment": "Gamepad touchpad event data" + }, + { + "name": "gsensor", + "type": "SDL_GamepadSensorEvent", + "comment": "Gamepad sensor event data" + }, + { + "name": "adevice", + "type": "SDL_AudioDeviceEvent", + "comment": "Audio device event data" + }, + { + "name": "cdevice", + "type": "SDL_CameraDeviceEvent", + "comment": "Camera device event data" + }, + { + "name": "sensor", + "type": "SDL_SensorEvent", + "comment": "Sensor event data" + }, + { + "name": "quit", + "type": "SDL_QuitEvent", + "comment": "Quit request event data" + }, + { + "name": "user", + "type": "SDL_UserEvent", + "comment": "Custom event data" + }, + { + "name": "tfinger", + "type": "SDL_TouchFingerEvent", + "comment": "Touch finger event data" + }, + { + "name": "pproximity", + "type": "SDL_PenProximityEvent", + "comment": "Pen proximity event data" + }, + { + "name": "ptouch", + "type": "SDL_PenTouchEvent", + "comment": "Pen tip touching event data" + }, + { + "name": "pmotion", + "type": "SDL_PenMotionEvent", + "comment": "Pen motion event data" + }, + { + "name": "pbutton", + "type": "SDL_PenButtonEvent", + "comment": "Pen button event data" + }, + { + "name": "paxis", + "type": "SDL_PenAxisEvent", + "comment": "Pen axis event data" + }, + { + "name": "render", + "type": "SDL_RenderEvent", + "comment": "Render event data" + }, + { + "name": "drop", + "type": "SDL_DropEvent", + "comment": "Drag and drop event data" + }, + { + "name": "clipboard", + "type": "SDL_ClipboardEvent", + "comment": "Clipboard event data" + }, + { + "name": "padding", + "type": "Uint8[128]" + } + ] + } + ], + "flags": [], + "functions": [ + { + "name": "SDL_PumpEvents", + "return_type": "void", + "parameters": [] + }, + { + "name": "SDL_PeepEvents", + "return_type": "int", + "parameters": [ + { + "name": "events", + "type": "SDL_Event *" + }, + { + "name": "numevents", + "type": "int" + }, + { + "name": "action", + "type": "SDL_EventAction" + }, + { + "name": "minType", + "type": "Uint32" + }, + { + "name": "maxType", + "type": "Uint32" + } + ] + }, + { + "name": "SDL_HasEvent", + "return_type": "bool", + "parameters": [ + { + "name": "_type", + "type": "Uint32" + } + ] + }, + { + "name": "SDL_HasEvents", + "return_type": "bool", + "parameters": [ + { + "name": "minType", + "type": "Uint32" + }, + { + "name": "maxType", + "type": "Uint32" + } + ] + }, + { + "name": "SDL_FlushEvent", + "return_type": "void", + "parameters": [ + { + "name": "_type", + "type": "Uint32" + } + ] + }, + { + "name": "SDL_FlushEvents", + "return_type": "void", + "parameters": [ + { + "name": "minType", + "type": "Uint32" + }, + { + "name": "maxType", + "type": "Uint32" + } + ] + }, + { + "name": "SDL_PollEvent", + "return_type": "bool", + "parameters": [ + { + "name": "event", + "type": "SDL_Event *" + } + ] + }, + { + "name": "SDL_WaitEvent", + "return_type": "bool", + "parameters": [ + { + "name": "event", + "type": "SDL_Event *" + } + ] + }, + { + "name": "SDL_WaitEventTimeout", + "return_type": "bool", + "parameters": [ + { + "name": "event", + "type": "SDL_Event *" + }, + { + "name": "timeoutMS", + "type": "Sint32" + } + ] + }, + { + "name": "SDL_PushEvent", + "return_type": "bool", + "parameters": [ + { + "name": "event", + "type": "SDL_Event *" + } + ] + }, + { + "name": "SDL_SetEventFilter", + "return_type": "void", + "parameters": [ + { + "name": "filter", + "type": "SDL_EventFilter" + }, + { + "name": "userdata", + "type": "void *" + } + ] + }, + { + "name": "SDL_GetEventFilter", + "return_type": "bool", + "parameters": [ + { + "name": "filter", + "type": "SDL_EventFilter *" + }, + { + "name": "userdata", + "type": "void **" + } + ] + }, + { + "name": "SDL_AddEventWatch", + "return_type": "bool", + "parameters": [ + { + "name": "filter", + "type": "SDL_EventFilter" + }, + { + "name": "userdata", + "type": "void *" + } + ] + }, + { + "name": "SDL_RemoveEventWatch", + "return_type": "void", + "parameters": [ + { + "name": "filter", + "type": "SDL_EventFilter" + }, + { + "name": "userdata", + "type": "void *" + } + ] + }, + { + "name": "SDL_FilterEvents", + "return_type": "void", + "parameters": [ + { + "name": "filter", + "type": "SDL_EventFilter" + }, + { + "name": "userdata", + "type": "void *" + } + ] + }, + { + "name": "SDL_SetEventEnabled", + "return_type": "void", + "parameters": [ + { + "name": "_type", + "type": "Uint32" + }, + { + "name": "enabled", + "type": "bool" + } + ] + }, + { + "name": "SDL_EventEnabled", + "return_type": "bool", + "parameters": [ + { + "name": "_type", + "type": "Uint32" + } + ] + }, + { + "name": "SDL_RegisterEvents", + "return_type": "Uint32", + "parameters": [ + { + "name": "numevents", + "type": "int" + } + ] + }, + { + "name": "SDL_GetWindowFromEvent", + "return_type": "SDL_Window *", + "parameters": [ + { + "name": "event", + "type": "const SDL_Event *" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/header_cache.zig b/src/header_cache.zig new file mode 100644 index 0000000..aec9098 --- /dev/null +++ b/src/header_cache.zig @@ -0,0 +1,442 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; +const patterns = @import("patterns.zig"); +const Declaration = patterns.Declaration; + +pub const HeaderCache = struct { + // Map from type name to its declaration + type_cache: std.StringHashMap(Declaration), + // Track which headers we've already parsed (avoid re-parsing) + parsed_headers: std.StringHashMap(void), + allocator: Allocator, + + pub fn init(allocator: Allocator) HeaderCache { + return .{ + .type_cache = std.StringHashMap(Declaration).init(allocator), + .parsed_headers = std.StringHashMap(void).init(allocator), + .allocator = allocator, + }; + } + + pub fn deinit(self: *HeaderCache) void { + // Free type cache keys + var type_it = self.type_cache.keyIterator(); + while (type_it.next()) |key| { + self.allocator.free(key.*); + } + // Free cached declarations + var val_it = self.type_cache.valueIterator(); + while (val_it.next()) |decl| { + freeDeclaration(self.allocator, decl.*); + } + self.type_cache.deinit(); + + // Free parsed headers keys + var header_it = self.parsed_headers.keyIterator(); + while (header_it.next()) |key| { + self.allocator.free(key.*); + } + self.parsed_headers.deinit(); + } + + pub fn buildCache(allocator: Allocator, header_path: []const u8) !HeaderCache { + var cache = HeaderCache.init(allocator); + errdefer cache.deinit(); + + const header_dir = std.fs.path.dirname(header_path) orelse "."; + try cache.parseHeaderRecursive(header_dir, std.fs.path.basename(header_path)); + + return cache; + } + + fn parseHeaderRecursive(self: *HeaderCache, header_dir: []const u8, filename: []const u8) !void { + // Skip non-SDL headers (stdlib, system headers, etc) + if (!std.mem.startsWith(u8, filename, "SDL_")) { + return; + } + + // Skip if already parsed + if (self.parsed_headers.contains(filename)) { + return; + } + + // Mark as parsed + try self.parsed_headers.put(try self.allocator.dupe(u8, filename), {}); + + // Build full path + const full_path = try std.fs.path.join(self.allocator, &[_][]const u8{ header_dir, filename }); + defer self.allocator.free(full_path); + + std.debug.print(" Caching types from: {s}\n", .{filename}); + + // Read and parse this header + const content = std.fs.cwd().readFileAlloc(self.allocator, full_path, 10_000_000) catch |err| { + std.debug.print(" Warning: Could not read {s}: {}\n", .{ filename, err }); + return; + }; + defer self.allocator.free(content); + + var scanner = patterns.Scanner.init(self.allocator, content); + const decls = scanner.scan() catch |err| { + std.debug.print(" Warning: Could not parse {s}: {}\n", .{ filename, err }); + return; + }; + defer self.allocator.free(decls); + + // Add all type definitions to cache + for (decls) |decl| { + const type_name = getTypeName(decl); + if (type_name) |name| { + // Don't cache if already present (first occurrence wins) + if (!self.type_cache.contains(name)) { + const name_copy = try self.allocator.dupe(u8, name); + const decl_copy = try cloneDeclaration(self.allocator, decl); + try self.type_cache.put(name_copy, decl_copy); + } + } + } + + // Free the original declarations (we made copies) + for (decls) |decl| { + freeDeclaration(self.allocator, decl); + } + + // Find and recursively parse all #include "SDL_*.h" directives + const includes = try findSDLIncludes(self.allocator, content); + defer { + for (includes) |inc| self.allocator.free(inc); + self.allocator.free(includes); + } + + for (includes) |inc_filename| { + try self.parseHeaderRecursive(header_dir, inc_filename); + } + } + + pub fn lookupType(self: *HeaderCache, type_name: []const u8) ?Declaration { + const decl = self.type_cache.get(type_name) orelse return null; + // Return a copy so caller owns it + return cloneDeclaration(self.allocator, decl) catch null; + } + + /// Lookup a type and recursively resolve all its dependencies + /// Returns an array of declarations: [0] is the requested type, [1..] are dependencies + pub fn lookupTypeWithDependencies(self: *HeaderCache, type_name: []const u8) ![]Declaration { + const dependency_resolver = @import("dependency_resolver.zig"); + + var result = try std.ArrayList(Declaration).initCapacity(self.allocator, 10); + errdefer { + for (result.items) |decl| { + freeDeclaration(self.allocator, decl); + } + result.deinit(self.allocator); + } + + // Track which types we've already processed + var processed = std.StringHashMap(void).init(self.allocator); + defer { + var it = processed.keyIterator(); + while (it.next()) |key| { + self.allocator.free(key.*); + } + processed.deinit(); + } + + // Work queue for types to resolve + var queue = try std.ArrayList([]const u8).initCapacity(self.allocator, 10); + defer { + for (queue.items) |item| { + self.allocator.free(item); + } + queue.deinit(self.allocator); + } + + // Start with the requested type + try queue.append(self.allocator, try self.allocator.dupe(u8, type_name)); + + // Process queue until empty + while (queue.items.len > 0) { + const current_type = queue.orderedRemove(0); + defer self.allocator.free(current_type); + + // Skip if already processed + if (processed.contains(current_type)) continue; + try processed.put(try self.allocator.dupe(u8, current_type), {}); + + // Look up the type + const decl = self.type_cache.get(current_type) orelse continue; + + // Add cloned declaration to result + const decl_copy = try cloneDeclaration(self.allocator, decl); + try result.append(self.allocator, decl_copy); + + // Analyze this declaration to find its dependencies + var resolver = dependency_resolver.DependencyResolver.init(self.allocator); + defer resolver.deinit(); + + const single_decl = [_]Declaration{decl}; + try resolver.analyze(&single_decl); + + const missing = try resolver.getMissingTypes(self.allocator); + defer { + for (missing) |m| self.allocator.free(m); + self.allocator.free(missing); + } + + // Add missing types to queue if not already processed + for (missing) |missing_type| { + if (!processed.contains(missing_type) and self.type_cache.contains(missing_type)) { + try queue.append(self.allocator, try self.allocator.dupe(u8, missing_type)); + } + } + } + + return try result.toOwnedSlice(self.allocator); + } + + fn getTypeName(decl: Declaration) ?[]const u8 { + return switch (decl) { + .opaque_type => |o| o.name, + .typedef_decl => |t| t.name, + .function_pointer_decl => |fp| fp.name, + .c_type_alias => |a| a.name, + .enum_decl => |e| e.name, + .struct_decl => |s| s.name, + .union_decl => |u| u.name, + .flag_decl => |f| f.name, + .function_decl => null, // Functions don't define types + }; + } + + fn findSDLIncludes(allocator: Allocator, source: []const u8) ![][]const u8 { + var includes = std.ArrayList([]const u8){}; + errdefer { + for (includes.items) |inc| allocator.free(inc); + includes.deinit(allocator); + } + + var lines = std.mem.splitScalar(u8, source, '\n'); + while (lines.next()) |line| { + const trimmed = std.mem.trim(u8, line, " \t\r"); + + // Match: #include + if (std.mem.startsWith(u8, trimmed, "#include ")) |end| { + const header_name = trimmed[after_open..][0..end]; + if (std.mem.startsWith(u8, header_name, "SDL_")) { + try includes.append(allocator, try allocator.dupe(u8, header_name)); + } + } + } + // Also match: #include "SDL_something.h" + else if (std.mem.startsWith(u8, trimmed, "#include \"SDL_")) { + const after_open = "#include \"".len; + if (std.mem.indexOf(u8, trimmed[after_open..], "\"")) |end| { + const header_name = trimmed[after_open..][0..end]; + if (std.mem.startsWith(u8, header_name, "SDL_")) { + try includes.append(allocator, try allocator.dupe(u8, header_name)); + } + } + } + } + + return try includes.toOwnedSlice(allocator); + } +}; + +fn cloneDeclaration(allocator: Allocator, decl: Declaration) !Declaration { + return switch (decl) { + .opaque_type => |o| Declaration{ + .opaque_type = .{ + .name = try allocator.dupe(u8, o.name), + .doc_comment = if (o.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + .typedef_decl => |t| Declaration{ + .typedef_decl = .{ + .name = try allocator.dupe(u8, t.name), + .underlying_type = try allocator.dupe(u8, t.underlying_type), + .doc_comment = if (t.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + .enum_decl => |e| Declaration{ + .enum_decl = .{ + .name = try allocator.dupe(u8, e.name), + .values = try cloneEnumValues(allocator, e.values), + .doc_comment = if (e.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + .struct_decl => |s| Declaration{ + .struct_decl = .{ + .name = try allocator.dupe(u8, s.name), + .fields = try cloneFields(allocator, s.fields), + .doc_comment = if (s.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + .has_unions = s.has_unions, + }, + }, + .union_decl => |u| Declaration{ + .union_decl = .{ + .name = try allocator.dupe(u8, u.name), + .fields = try cloneFields(allocator, u.fields), + .doc_comment = if (u.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + .flag_decl => |f| Declaration{ + .flag_decl = .{ + .name = try allocator.dupe(u8, f.name), + .underlying_type = try allocator.dupe(u8, f.underlying_type), + .flags = try cloneFlagValues(allocator, f.flags), + .doc_comment = if (f.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + .function_decl => |func| Declaration{ + .function_decl = .{ + .name = try allocator.dupe(u8, func.name), + .return_type = try allocator.dupe(u8, func.return_type), + .params = try cloneParams(allocator, func.params), + .doc_comment = if (func.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + .function_pointer_decl => |fp| Declaration{ + .function_pointer_decl = .{ + .name = try allocator.dupe(u8, fp.name), + .return_type = try allocator.dupe(u8, fp.return_type), + .params = try cloneParams(allocator, fp.params), + .doc_comment = if (fp.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + .c_type_alias => |a| Declaration{ + .c_type_alias = .{ + .name = try allocator.dupe(u8, a.name), + .doc_comment = if (a.doc_comment) |doc| try allocator.dupe(u8, doc) else null, + }, + }, + }; +} + +fn cloneEnumValues(allocator: Allocator, values: []const patterns.EnumValue) ![]patterns.EnumValue { + const new_values = try allocator.alloc(patterns.EnumValue, values.len); + for (values, 0..) |val, i| { + new_values[i] = .{ + .name = try allocator.dupe(u8, val.name), + .value = if (val.value) |v| try allocator.dupe(u8, v) else null, + .comment = if (val.comment) |c| try allocator.dupe(u8, c) else null, + }; + } + return new_values; +} + +fn cloneFlagValues(allocator: Allocator, flags: []const patterns.FlagValue) ![]patterns.FlagValue { + const new_flags = try allocator.alloc(patterns.FlagValue, flags.len); + for (flags, 0..) |flag, i| { + new_flags[i] = .{ + .name = try allocator.dupe(u8, flag.name), + .value = try allocator.dupe(u8, flag.value), + .comment = if (flag.comment) |c| try allocator.dupe(u8, c) else null, + }; + } + return new_flags; +} + +fn cloneFields(allocator: Allocator, fields: []const patterns.FieldDecl) ![]patterns.FieldDecl { + const new_fields = try allocator.alloc(patterns.FieldDecl, fields.len); + for (fields, 0..) |field, i| { + new_fields[i] = .{ + .name = try allocator.dupe(u8, field.name), + .type_name = try allocator.dupe(u8, field.type_name), + .comment = if (field.comment) |c| try allocator.dupe(u8, c) else null, + }; + } + return new_fields; +} + +fn cloneParams(allocator: Allocator, params: []const patterns.ParamDecl) ![]patterns.ParamDecl { + const new_params = try allocator.alloc(patterns.ParamDecl, params.len); + for (params, 0..) |param, i| { + new_params[i] = .{ + .name = try allocator.dupe(u8, param.name), + .type_name = try allocator.dupe(u8, param.type_name), + }; + } + return new_params; +} + +fn freeDeclaration(allocator: Allocator, decl: Declaration) void { + switch (decl) { + .opaque_type => |o| { + allocator.free(o.name); + if (o.doc_comment) |doc| allocator.free(doc); + }, + .typedef_decl => |t| { + allocator.free(t.name); + allocator.free(t.underlying_type); + if (t.doc_comment) |doc| allocator.free(doc); + }, + .enum_decl => |e| { + allocator.free(e.name); + for (e.values) |val| { + allocator.free(val.name); + if (val.value) |v| allocator.free(v); + if (val.comment) |c| allocator.free(c); + } + allocator.free(e.values); + if (e.doc_comment) |doc| allocator.free(doc); + }, + .struct_decl => |s| { + allocator.free(s.name); + for (s.fields) |field| { + allocator.free(field.name); + allocator.free(field.type_name); + if (field.comment) |c| allocator.free(c); + } + allocator.free(s.fields); + if (s.doc_comment) |doc| allocator.free(doc); + }, + .union_decl => |u| { + allocator.free(u.name); + for (u.fields) |field| { + allocator.free(field.name); + allocator.free(field.type_name); + if (field.comment) |c| allocator.free(c); + } + allocator.free(u.fields); + if (u.doc_comment) |doc| allocator.free(doc); + }, + .flag_decl => |f| { + allocator.free(f.name); + allocator.free(f.underlying_type); + for (f.flags) |flag| { + allocator.free(flag.name); + allocator.free(flag.value); + if (flag.comment) |c| allocator.free(c); + } + allocator.free(f.flags); + if (f.doc_comment) |doc| allocator.free(doc); + }, + .function_decl => |func| { + allocator.free(func.name); + allocator.free(func.return_type); + for (func.params) |param| { + allocator.free(param.name); + allocator.free(param.type_name); + } + allocator.free(func.params); + if (func.doc_comment) |doc| allocator.free(doc); + }, + .function_pointer_decl => |fp| { + allocator.free(fp.name); + allocator.free(fp.return_type); + for (fp.params) |param| { + allocator.free(param.name); + allocator.free(param.type_name); + } + allocator.free(fp.params); + if (fp.doc_comment) |doc| allocator.free(doc); + }, + .c_type_alias => |a| { + allocator.free(a.name); + if (a.doc_comment) |doc| allocator.free(doc); + }, + } +} diff --git a/src/parser.zig b/src/parser.zig index 2534b1a..d906815 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -4,6 +4,7 @@ const codegen = @import("codegen.zig"); const dependency_resolver = @import("dependency_resolver.zig"); const json_serializer = @import("json_serializer.zig"); const io = @import("io.zig"); +const header_cache = @import("header_cache.zig"); pub fn main() !void { const allocator = std.heap.smp_allocator; @@ -251,6 +252,14 @@ pub fn main() !void { std.debug.print("Adding {d} hardcoded type declarations\n", .{hardcoded_decls.len}); } + var dependency_decls = std.ArrayList(patterns.Declaration){}; + defer { + for (dependency_decls.items) |dep_decl| { + freeDeclDeep(allocator, dep_decl); + } + dependency_decls.deinit(allocator); + } + if (missing_types.len > 0) { std.debug.print("Found {d} missing types:\n", .{missing_types.len}); for (missing_types) |missing| { @@ -258,191 +267,142 @@ pub fn main() !void { } std.debug.print("\n", .{}); - // Extract missing types from included headers - std.debug.print("Resolving dependencies from included headers...\n", .{}); - const includes = try dependency_resolver.parseIncludes(allocator, source); - defer { - for (includes) |inc| allocator.free(inc); - allocator.free(includes); - } + // PHASE 1: Build complete type cache from all SDL headers + std.debug.print("Building type cache from all SDL headers...\n", .{}); + var cache = try header_cache.HeaderCache.buildCache(allocator, header_path); + defer cache.deinit(); + std.debug.print("Type cache built successfully\n\n", .{}); - const header_dir = std.fs.path.dirname(header_path) orelse "."; - - var dependency_decls = std.ArrayList(patterns.Declaration){}; + // PHASE 2: Resolve dependencies via cache lookup with recursive dependency resolution + std.debug.print("Resolving dependencies from cache...\n", .{}); + + // Track which types we've already added to avoid duplicates + var added_types = std.StringHashMap(void).init(allocator); defer { - for (dependency_decls.items) |dep_decl| { - freeDeclDeep(allocator, dep_decl); + var it = added_types.keyIterator(); + while (it.next()) |key| { + allocator.free(key.*); } - dependency_decls.deinit(allocator); + added_types.deinit(); } - + for (missing_types) |missing_type| { - var found = false; - for (includes) |include| { - const dep_path = try std.fs.path.join(allocator, &[_][]const u8{ header_dir, include }); - defer allocator.free(dep_path); - - const dep_source = std.fs.cwd().readFileAlloc(allocator, dep_path, 10 * 1024 * 1024) catch continue; - defer allocator.free(dep_source); - - if (try dependency_resolver.extractTypeFromHeader(allocator, dep_source, missing_type)) |dep_decl| { - try dependency_decls.append(allocator, dep_decl); - std.debug.print(" Found {s} in {s}\n", .{ missing_type, include }); - found = true; - break; + // Skip if already added + if (added_types.contains(missing_type)) continue; + + // Look up type with all its dependencies + const resolved_decls = cache.lookupTypeWithDependencies(missing_type) catch |err| { + std.debug.print(" Warning: Could not resolve {s}: {}\n", .{ missing_type, err }); + continue; + }; + + // Add all resolved declarations + for (resolved_decls) |resolved_decl| { + const decl_type_name = switch (resolved_decl) { + .opaque_type => |o| o.name, + .typedef_decl => |t| t.name, + .function_pointer_decl => |fp| fp.name, + .c_type_alias => |a| a.name, + .enum_decl => |e| e.name, + .struct_decl => |s| s.name, + .union_decl => |u| u.name, + .flag_decl => |f| f.name, + .function_decl => continue, // Skip functions + }; + + if (!added_types.contains(decl_type_name)) { + try dependency_decls.append(allocator, resolved_decl); + try added_types.put(try allocator.dupe(u8, decl_type_name), {}); + + if (std.mem.eql(u8, decl_type_name, missing_type)) { + std.debug.print(" Found {s} in cache\n", .{missing_type}); + } else { + std.debug.print(" + dependency: {s}\n", .{decl_type_name}); + } + } else { + // Already added, free this duplicate + freeDeclDeep(allocator, resolved_decl); } } - - if (!found) { - std.debug.print(" Warning: Could not find definition for type: {s}\n", .{missing_type}); - } + + allocator.free(resolved_decls); } - // Combine declarations (hardcoded first, then dependencies, then primary!) - std.debug.print("\nCombining {d} hardcoded + {d} dependency declarations with primary declarations...\n", .{ hardcoded_decls.len, dependency_decls.items.len }); + std.debug.print("\n", .{}); + } - var all_decls = std.ArrayList(patterns.Declaration){}; - defer all_decls.deinit(allocator); + // Combine declarations (hardcoded first, then dependencies, then primary!) + std.debug.print("Combining {d} hardcoded + {d} dependency declarations with primary declarations...\n", .{ hardcoded_decls.len, dependency_decls.items.len }); - try all_decls.appendSlice(allocator, hardcoded_decls); - try all_decls.appendSlice(allocator, dependency_decls.items); - try all_decls.appendSlice(allocator, decls); + var all_decls = std.ArrayList(patterns.Declaration){}; + defer all_decls.deinit(allocator); - // Generate code with all declarations - const output = try codegen.CodeGen.generate(allocator, all_decls.items); - defer allocator.free(output); + try all_decls.appendSlice(allocator, hardcoded_decls); + try all_decls.appendSlice(allocator, dependency_decls.items); + try all_decls.appendSlice(allocator, decls); - // Parse and format the AST for validation - const output_z = try allocator.dupeZ(u8, output); - defer allocator.free(output_z); + // Generate code with all declarations + const output = try codegen.CodeGen.generate(allocator, all_decls.items); + defer allocator.free(output); - var ast = try std.zig.Ast.parse(allocator, output_z, .zig); - defer ast.deinit(allocator); + // Parse and format the AST for validation + const output_z = try allocator.dupeZ(u8, output); + defer allocator.free(output_z); - // Check for parse errors - if (ast.errors.len > 0) { - std.debug.print("{s}", .{output_z}); - std.debug.print("\nError: {d} syntax errors detected in generated code\n", .{ast.errors.len}); - for (ast.errors) |err| { - const loc = ast.tokenLocation(0, err.token); - std.debug.print(" Line {d}: {s}\n", .{ loc.line + 1, @tagName(err.tag) }); - } + var ast = try std.zig.Ast.parse(allocator, output_z, .zig); + defer ast.deinit(allocator); - // Write to debug file - try writeDebugFile(allocator, header_path, output); - - // Write unformatted output for debugging - if (output_file) |file_path| { - try std.fs.cwd().writeFile(.{ - .sub_path = file_path, - .data = output, - }); - std.debug.print("\nGenerated (with errors): {s}\n", .{file_path}); - } - - return error.InvalidSyntax; + // Check for parse errors + if (ast.errors.len > 0) { + std.debug.print("{s}", .{output_z}); + std.debug.print("\nError: {d} syntax errors detected in generated code\n", .{ast.errors.len}); + for (ast.errors) |err| { + const loc = ast.tokenLocation(0, err.token); + std.debug.print(" Line {d}: {s}\n", .{ loc.line + 1, @tagName(err.tag) }); } - // Render formatted output from AST - const formatted_output = ast.renderAlloc(allocator) catch |err| { - std.debug.print("\nError: AST render failed: {}\n", .{err}); - try writeDebugFile(allocator, header_path, output); - return err; - }; - defer allocator.free(formatted_output); + // Write to debug file + try writeDebugFile(allocator, header_path, output); - // Write formatted output to file or stdout + // Write unformatted output for debugging if (output_file) |file_path| { - try writeZigFileWithFmt(allocator, header_path, file_path, formatted_output); - } else { - _ = try io.stdout().write(formatted_output); - } - - // Generate C mocks if requested (with all declarations) - if (mock_output_file) |mock_path| { - const mock_codegen = @import("mock_codegen.zig"); - const mock_output = try mock_codegen.MockCodeGen.generate(allocator, all_decls.items); - defer allocator.free(mock_output); - - try ensureParentDirExists(mock_path); try std.fs.cwd().writeFile(.{ - .sub_path = mock_path, - .data = mock_output, + .sub_path = file_path, + .data = output, }); - std.debug.print("Generated C mocks: {s}\n", .{mock_path}); + std.debug.print("\nGenerated (with errors): {s}\n", .{file_path}); } + + return error.InvalidSyntax; + } + + // Render formatted output from AST + const formatted_output = ast.renderAlloc(allocator) catch |err| { + std.debug.print("\nError: AST render failed: {}\n", .{err}); + try writeDebugFile(allocator, header_path, output); + return err; + }; + defer allocator.free(formatted_output); + + // Write formatted output to file or stdout + if (output_file) |file_path| { + try writeZigFileWithFmt(allocator, header_path, file_path, formatted_output); } else { - std.debug.print("No missing dependencies found!\n\n", .{}); + _ = try io.stdout().write(formatted_output); + } - // Generate code (include hardcoded declarations if any) - var gen_decls = std.ArrayList(patterns.Declaration){}; - defer gen_decls.deinit(allocator); - if (hardcoded_decls.len > 0) { - try gen_decls.appendSlice(allocator, hardcoded_decls); - } - try gen_decls.appendSlice(allocator, decls); + // Generate C mocks if requested (with all declarations) + if (mock_output_file) |mock_path| { + const mock_codegen = @import("mock_codegen.zig"); + const mock_output = try mock_codegen.MockCodeGen.generate(allocator, all_decls.items); + defer allocator.free(mock_output); - const output = try codegen.CodeGen.generate(allocator, gen_decls.items); - defer allocator.free(output); - - // Parse and format the AST for validation - const output_z = try allocator.dupeZ(u8, output); - defer allocator.free(output_z); - - var ast = try std.zig.Ast.parse(allocator, output_z, .zig); - defer ast.deinit(allocator); - - // Check for parse errors - if (ast.errors.len > 0) { - std.debug.print("\nError: {d} syntax errors detected in generated code\n", .{ast.errors.len}); - for (ast.errors) |err| { - const loc = ast.tokenLocation(0, err.token); - std.debug.print(" Line {d}: {s}\n", .{ loc.line + 1, @tagName(err.tag) }); - } - - // Write to debug file - try writeDebugFile(allocator, header_path, output); - - // Write unformatted output for debugging - if (output_file) |file_path| { - try std.fs.cwd().writeFile(.{ - .sub_path = file_path, - .data = output, - }); - std.debug.print("\nGenerated (with errors): {s}\n", .{file_path}); - } - - return error.InvalidSyntax; - } - - // Render formatted output from AST - const formatted_output = ast.renderAlloc(allocator) catch |err| { - std.debug.print("\nError: AST render failed: {}\n", .{err}); - try writeDebugFile(allocator, header_path, output); - return err; - }; - defer allocator.free(formatted_output); - - // Write formatted output to file or stdout - if (output_file) |file_path| { - try writeZigFileWithFmt(allocator, header_path, file_path, formatted_output); - } else { - _ = try io.stdout().write(formatted_output); - } - - // Generate C mocks if requested - if (mock_output_file) |mock_path| { - const mock_codegen = @import("mock_codegen.zig"); - const mock_output = try mock_codegen.MockCodeGen.generate(allocator, gen_decls.items); - defer allocator.free(mock_output); - - try ensureParentDirExists(mock_path); - try std.fs.cwd().writeFile(.{ - .sub_path = mock_path, - .data = mock_output, - }); - std.debug.print("Generated C mocks: {s}\n", .{mock_path}); - } + try ensureParentDirExists(mock_path); + try std.fs.cwd().writeFile(.{ + .sub_path = mock_path, + .data = mock_output, + }); + std.debug.print("Generated C mocks: {s}\n", .{mock_path}); } } diff --git a/v2/events.zig b/v2/events.zig new file mode 100644 index 0000000..04a45b7 --- /dev/null +++ b/v2/events.zig @@ -0,0 +1,770 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PenID = u32; + +pub const WindowID = u32; + +pub const AudioDeviceID = u32; + +pub const DisplayID = u32; + +pub const CameraID = u32; + +pub const PenInputFlags = packed struct(u32) { + penInputDown: bool = false, // pen is pressed down + penInputButton1: bool = false, // button 1 is pressed + penInputButton2: bool = false, // button 2 is pressed + penInputButton3: bool = false, // button 3 is pressed + penInputButton4: bool = false, // button 4 is pressed + penInputButton5: bool = false, // button 5 is pressed + penInputEraserTip: bool = false, // eraser tip is used + pad0: u24 = 0, + rsvd: bool = false, +}; + +pub const MouseButtonFlags = packed struct(u32) { + buttonLeft: bool = false, + buttonMiddle: bool = false, + buttonX1: bool = false, + pad0: u28 = 0, + rsvd: bool = false, +}; + +pub const Scancode = enum(c_int) { + scancodeBackslash, + scancodeNonushash, + scancodeGrave, + scancodeInsert, + scancodeNumlockclear, + scancodeNonusbackslash, + scancodeApplication, //windows contextual menu, compose + scancodePower, + scancodeHelp, //AL Integrated Help Center + scancodeMenu, //Menu (show menu) + scancodeStop, //AC Stop + scancodeAgain, //AC Redo/Repeat + scancodeUndo, //AC Undo + scancodeCut, //AC Cut + scancodeCopy, //AC Copy + scancodePaste, //AC Paste + scancodeFind, //AC Find + scancodeInternational1, + scancodeInternational3, //Yen + scancodeLang1, //Hangul/English toggle + scancodeLang2, //Hanja conversion + scancodeLang3, //Katakana + scancodeLang4, //Hiragana + scancodeLang5, //Zenkaku/Hankaku + scancodeLang6, //reserved + scancodeLang7, //reserved + scancodeLang8, //reserved + scancodeLang9, //reserved + scancodeAlterase, //Erase-Eaze + scancodeCancel, //AC Cancel + scancodeLalt, //alt, option + scancodeLgui, //windows, command (apple), meta + scancodeRalt, //alt gr, option + scancodeRgui, //windows, command (apple), meta + scancodeMode, + scancodeSleep, //Sleep + scancodeWake, //Wake + scancodeChannelIncrement, //Channel Increment + scancodeChannelDecrement, //Channel Decrement + scancodeMediaPlay, //Play + scancodeMediaPause, //Pause + scancodeMediaRecord, //Record + scancodeMediaFastForward, //Fast Forward + scancodeMediaRewind, //Rewind + scancodeMediaNextTrack, //Next Track + scancodeMediaPreviousTrack, //Previous Track + scancodeMediaStop, //Stop + scancodeMediaEject, //Eject + scancodeMediaPlayPause, //Play / Pause + scancodeMediaSelect, + scancodeAcNew, //AC New + scancodeAcOpen, //AC Open + scancodeAcClose, //AC Close + scancodeAcExit, //AC Exit + scancodeAcSave, //AC Save + scancodeAcPrint, //AC Print + scancodeAcProperties, //AC Properties + scancodeAcSearch, //AC Search + scancodeAcHome, //AC Home + scancodeAcBack, //AC Back + scancodeAcForward, //AC Forward + scancodeAcStop, //AC Stop + scancodeAcRefresh, //AC Refresh + scancodeAcBookmarks, //AC Bookmarks + scancodeSoftleft, + scancodeSoftright, + scancodeCall, //Used for accepting phone calls. + scancodeEndcall, //Used for rejecting phone calls. + scancodeReserved, //400-500 reserved for dynamic keycodes + scancodeCount, +}; + +pub const TouchID = u64; + +pub const KeyboardID = u32; + +pub const PenAxis = enum(c_int) { + penAxisPressure, //Pen pressure. Unidirectional: 0 to 1.0 + penAxisXtilt, //Pen horizontal tilt angle. Bidirectional: -90.0 to 90.0 (left-to-right). + penAxisYtilt, //Pen vertical tilt angle. Bidirectional: -90.0 to 90.0 (top-to-down). + penAxisDistance, //Pen distance to drawing surface. Unidirectional: 0.0 to 1.0 + penAxisRotation, //Pen barrel rotation. Bidirectional: -180 to 179.9 (clockwise, 0 is facing up, -180.0 is facing down). + penAxisSlider, //Pen finger wheel or slider (e.g., Airbrush Pen). Unidirectional: 0 to 1.0 + penAxisTangentialPressure, //Pressure from squeezing the pen ("barrel pressure"). + penAxisCount, //Total known pen axis types in this version of SDL. This number may grow in future releases! +}; + +pub const MouseID = u32; + +pub const MouseWheelDirection = enum(c_int) { + mousewheelNormal, //The scroll direction is normal + mousewheelFlipped, //The scroll direction is flipped / natural +}; + +pub const PowerState = enum(c_int) { + powerstateError, //error determining power status + powerstateUnknown, //cannot determine power status + powerstateOnBattery, //Not plugged in, running on the battery + powerstateNoBattery, //Plugged in, no battery available + powerstateCharging, //Plugged in, charging battery + powerstateCharged, +}; + +pub const Window = opaque {}; + +pub const FingerID = u64; + +pub const Keycode = u32; + +pub const SensorID = u32; + +pub const JoystickID = u32; + +pub const Keymod = u16; + +pub const EventType = enum(c_int) { + eventFirst, //Unused (do not remove) + eventQuit, //User-requested quit + eventTerminating, + eventLowMemory, + eventWillEnterBackground, + eventDidEnterBackground, + eventWillEnterForeground, + eventDidEnterForeground, + eventLocaleChanged, //The user's locale preferences have changed. + eventSystemThemeChanged, //The system theme changed + eventDisplayOrientation, //Display orientation has changed to data1 + eventDisplayAdded, //Display has been added to the system + eventDisplayRemoved, //Display has been removed from the system + eventDisplayMoved, //Display has changed position + eventDisplayDesktopModeChanged, //Display has changed desktop mode + eventDisplayCurrentModeChanged, //Display has changed current mode + eventDisplayContentScaleChanged, //Display has changed content scale + eventWindowShown, //Window has been shown + eventWindowHidden, //Window has been hidden + eventWindowExposed, //Window has been exposed and should be redrawn, and can be redrawn directly from event watchers for this event + eventWindowMoved, //Window has been moved to data1, data2 + eventWindowResized, //Window has been resized to data1xdata2 + eventWindowPixelSizeChanged, //The pixel size of the window has changed to data1xdata2 + eventWindowMetalViewResized, //The pixel size of a Metal view associated with the window has changed + eventWindowMinimized, //Window has been minimized + eventWindowMaximized, //Window has been maximized + eventWindowRestored, //Window has been restored to normal size and position + eventWindowMouseEnter, //Window has gained mouse focus + eventWindowMouseLeave, //Window has lost mouse focus + eventWindowFocusGained, //Window has gained keyboard focus + eventWindowFocusLost, //Window has lost keyboard focus + eventWindowCloseRequested, //The window manager requests that the window be closed + eventWindowHitTest, //Window had a hit test that wasn't SDL_HITTEST_NORMAL + eventWindowIccprofChanged, //The ICC profile of the window's display has changed + eventWindowDisplayChanged, //Window has been moved to display data1 + eventWindowDisplayScaleChanged, //Window display scale has been changed + eventWindowSafeAreaChanged, //The window safe area has been changed + eventWindowOccluded, //The window has been occluded + eventWindowEnterFullscreen, //The window has entered fullscreen mode + eventWindowLeaveFullscreen, //The window has left fullscreen mode + eventWindowDestroyed, + eventWindowHdrStateChanged, //Window HDR properties have changed + eventKeyDown, //Key pressed + eventKeyUp, //Key released + eventTextEditing, //Keyboard text editing (composition) + eventTextInput, //Keyboard text input + eventKeymapChanged, + eventKeyboardAdded, //A new keyboard has been inserted into the system + eventKeyboardRemoved, //A keyboard has been removed + eventTextEditingCandidates, //Keyboard text editing candidates + eventMouseMotion, //Mouse moved + eventMouseButtonDown, //Mouse button pressed + eventMouseButtonUp, //Mouse button released + eventMouseWheel, //Mouse wheel motion + eventMouseAdded, //A new mouse has been inserted into the system + eventMouseRemoved, //A mouse has been removed + eventJoystickAxisMotion, //Joystick axis motion + eventJoystickBallMotion, //Joystick trackball motion + eventJoystickHatMotion, //Joystick hat position change + eventJoystickButtonDown, //Joystick button pressed + eventJoystickButtonUp, //Joystick button released + eventJoystickAdded, //A new joystick has been inserted into the system + eventJoystickRemoved, //An opened joystick has been removed + eventJoystickBatteryUpdated, //Joystick battery level change + eventJoystickUpdateComplete, //Joystick update is complete + eventGamepadAxisMotion, //Gamepad axis motion + eventGamepadButtonDown, //Gamepad button pressed + eventGamepadButtonUp, //Gamepad button released + eventGamepadAdded, //A new gamepad has been inserted into the system + eventGamepadRemoved, //A gamepad has been removed + eventGamepadRemapped, //The gamepad mapping was updated + eventGamepadTouchpadDown, //Gamepad touchpad was touched + eventGamepadTouchpadMotion, //Gamepad touchpad finger was moved + eventGamepadTouchpadUp, //Gamepad touchpad finger was lifted + eventGamepadSensorUpdate, //Gamepad sensor was updated + eventGamepadUpdateComplete, //Gamepad update is complete + eventGamepadSteamHandleUpdated, //Gamepad Steam handle has changed + eventFingerUp, + eventFingerMotion, + eventFingerCanceled, + eventClipboardUpdate, //The clipboard or primary selection changed + eventDropFile, //The system requests a file open + eventDropText, //text/plain drag-and-drop event + eventDropBegin, //A new set of drops is beginning (NULL filename) + eventDropComplete, //Current set of drops is now complete (NULL filename) + eventDropPosition, //Position while moving over the window + eventAudioDeviceAdded, //A new audio device is available + eventAudioDeviceRemoved, //An audio device has been removed. + eventAudioDeviceFormatChanged, //An audio device's format has been changed by the system. + eventSensorUpdate, //A sensor was updated + eventPenProximityIn, //Pressure-sensitive pen has become available + eventPenProximityOut, //Pressure-sensitive pen has become unavailable + eventPenDown, //Pressure-sensitive pen touched drawing surface + eventPenUp, //Pressure-sensitive pen stopped touching drawing surface + eventPenButtonDown, //Pressure-sensitive pen button pressed + eventPenButtonUp, //Pressure-sensitive pen button released + eventPenMotion, //Pressure-sensitive pen is moving on the tablet + eventPenAxis, //Pressure-sensitive pen angle/pressure/etc changed + eventCameraDeviceAdded, //A new camera device is available + eventCameraDeviceRemoved, //A camera device has been removed. + eventCameraDeviceApproved, //A camera device has been approved for use by the user. + eventCameraDeviceDenied, //A camera device has been denied for use by the user. + eventRenderTargetsReset, //The render targets have been reset and their contents need to be updated + eventRenderDeviceReset, //The device has been reset and all textures need to be recreated + eventRenderDeviceLost, //The device has been lost and can't be recovered. + eventPrivate1, + eventPrivate2, + eventPrivate3, + eventPollSentinel, //Signals the end of an event poll cycle +}; + +pub const CommonEvent = extern struct { + _type: u32, // Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() +}; + +pub const DisplayEvent = extern struct { + _type: EventType, // SDL_DISPLAYEVENT_* + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + displayID: DisplayID, // The associated display + data1: i32, // event dependent data + data2: i32, // event dependent data +}; + +pub const WindowEvent = extern struct { + _type: EventType, // SDL_EVENT_WINDOW_* + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The associated window + data1: i32, // event dependent data + data2: i32, // event dependent data +}; + +pub const KeyboardDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_KEYBOARD_ADDED or SDL_EVENT_KEYBOARD_REMOVED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: KeyboardID, // The keyboard instance id +}; + +pub const KeyboardEvent = extern struct { + _type: EventType, // SDL_EVENT_KEY_DOWN or SDL_EVENT_KEY_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + which: KeyboardID, // The keyboard instance id, or 0 if unknown or virtual + scancode: Scancode, // SDL physical key code + key: Keycode, // SDL virtual key code + mod: Keymod, // current key modifiers + raw: u16, // The platform dependent scancode for this event + down: bool, // true if the key is pressed + repeat: bool, // true if this is a key repeat +}; + +pub const TextEditingEvent = extern struct { + _type: EventType, // SDL_EVENT_TEXT_EDITING + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + text: [*c]const u8, // The editing text + start: i32, // The start cursor of selected editing text, or -1 if not set + length: i32, // The length of selected editing text, or -1 if not set +}; + +pub const TextEditingCandidatesEvent = extern struct { + _type: EventType, // SDL_EVENT_TEXT_EDITING_CANDIDATES + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + candidates: [*c]const [*c]const u8, // The list of candidates, or NULL if there are no candidates available + num_candidates: i32, // The number of strings in `candidates` + selected_candidate: i32, // The index of the selected candidate, or -1 if no candidate is selected + horizontal: bool, // true if the list is horizontal, false if it's vertical + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const TextInputEvent = extern struct { + _type: EventType, // SDL_EVENT_TEXT_INPUT + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + text: [*c]const u8, // The input text, UTF-8 encoded +}; + +pub const MouseDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_ADDED or SDL_EVENT_MOUSE_REMOVED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: MouseID, // The mouse instance id +}; + +pub const MouseMotionEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: MouseID, // The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0 + state: MouseButtonFlags, // The current button state + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + xrel: f32, // The relative motion in the X direction + yrel: f32, // The relative motion in the Y direction +}; + +pub const MouseButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_BUTTON_DOWN or SDL_EVENT_MOUSE_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: MouseID, // The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0 + button: u8, // The mouse button index + down: bool, // true if the button is pressed + clicks: u8, // 1 for single-click, 2 for double-click, etc. + padding: u8, + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window +}; + +pub const MouseWheelEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_WHEEL + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: MouseID, // The mouse instance id in relative mode or 0 + x: f32, // The amount scrolled horizontally, positive to the right and negative to the left + y: f32, // The amount scrolled vertically, positive away from the user and negative toward the user + direction: MouseWheelDirection, // 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 + mouse_x: f32, // X coordinate, relative to window + mouse_y: f32, // Y coordinate, relative to window + integer_x: i32, // The amount scrolled horizontally, accumulated to whole scroll "ticks" (added in 3.2.12) + integer_y: i32, // The amount scrolled vertically, accumulated to whole scroll "ticks" (added in 3.2.12) +}; + +pub const JoyAxisEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_AXIS_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + axis: u8, // The joystick axis index + padding1: u8, + padding2: u8, + padding3: u8, + value: i16, // The axis value (range: -32768 to 32767) + padding4: u16, +}; + +pub const JoyBallEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_BALL_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + ball: u8, // The joystick trackball index + padding1: u8, + padding2: u8, + padding3: u8, + xrel: i16, // The relative motion in the X direction + yrel: i16, // The relative motion in the Y direction +}; + +pub const JoyHatEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_HAT_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + hat: u8, // The joystick hat index + padding1: u8, + padding2: u8, +}; + +pub const JoyButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_BUTTON_DOWN or SDL_EVENT_JOYSTICK_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + button: u8, // The joystick button index + down: bool, // true if the button is pressed + padding1: u8, + padding2: u8, +}; + +pub const JoyDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_ADDED or SDL_EVENT_JOYSTICK_REMOVED or SDL_EVENT_JOYSTICK_UPDATE_COMPLETE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id +}; + +pub const JoyBatteryEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_BATTERY_UPDATED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + state: PowerState, // The joystick battery state + percent: c_int, // The joystick battery percent charge remaining +}; + +pub const GamepadAxisEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_AXIS_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + axis: u8, // The gamepad axis (SDL_GamepadAxis) + padding1: u8, + padding2: u8, + padding3: u8, + value: i16, // The axis value (range: -32768 to 32767) + padding4: u16, +}; + +pub const GamepadButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_BUTTON_DOWN or SDL_EVENT_GAMEPAD_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + button: u8, // The gamepad button (SDL_GamepadButton) + down: bool, // true if the button is pressed + padding1: u8, + padding2: u8, +}; + +pub const GamepadDeviceEvent = extern struct { + _type: EventType, // 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 + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id +}; + +pub const GamepadTouchpadEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or SDL_EVENT_GAMEPAD_TOUCHPAD_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + touchpad: i32, // The index of the touchpad + finger: i32, // The index of the finger on the touchpad + x: f32, // Normalized in the range 0...1 with 0 being on the left + y: f32, // Normalized in the range 0...1 with 0 being at the top + pressure: f32, // Normalized in the range 0...1 +}; + +pub const GamepadSensorEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_SENSOR_UPDATE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + sensor: i32, // The type of the sensor, one of the values of SDL_SensorType + data: [3]f32, // Up to 3 values from the sensor, as defined in SDL_sensor.h + sensor_timestamp: u64, // The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock +}; + +pub const AudioDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_AUDIO_DEVICE_ADDED, or SDL_EVENT_AUDIO_DEVICE_REMOVED, or SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: AudioDeviceID, // SDL_AudioDeviceID for the device being added or removed or changing + recording: bool, // false if a playback device, true if a recording device. + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const CameraDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_CAMERA_DEVICE_ADDED, SDL_EVENT_CAMERA_DEVICE_REMOVED, SDL_EVENT_CAMERA_DEVICE_APPROVED, SDL_EVENT_CAMERA_DEVICE_DENIED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: CameraID, // SDL_CameraID for the device being added or removed or changing +}; + +pub const RenderEvent = extern struct { + _type: EventType, // SDL_EVENT_RENDER_TARGETS_RESET, SDL_EVENT_RENDER_DEVICE_RESET, SDL_EVENT_RENDER_DEVICE_LOST + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window containing the renderer in question. +}; + +pub const TouchFingerEvent = extern struct { + _type: EventType, // SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_UP, SDL_EVENT_FINGER_MOTION, or SDL_EVENT_FINGER_CANCELED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + touchID: TouchID, // The touch device id + fingerID: FingerID, + x: f32, // Normalized in the range 0...1 + y: f32, // Normalized in the range 0...1 + dx: f32, // Normalized in the range -1...1 + dy: f32, // Normalized in the range -1...1 + pressure: f32, // Normalized in the range 0...1 + windowID: WindowID, // The window underneath the finger, if any +}; + +pub const PenProximityEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_PROXIMITY_IN or SDL_EVENT_PEN_PROXIMITY_OUT + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id +}; + +pub const PenMotionEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window +}; + +pub const PenTouchEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_DOWN or SDL_EVENT_PEN_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + eraser: bool, // true if eraser end is used (not all pens support this). + down: bool, // true if the pen is touching or false if the pen is lifted off +}; + +pub const PenButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_BUTTON_DOWN or SDL_EVENT_PEN_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + button: u8, // The pen button index (first button is 1). + down: bool, // true if the button is pressed +}; + +pub const PenAxisEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_AXIS + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + axis: PenAxis, // Axis that has changed + value: f32, // New value of axis +}; + +pub const DropEvent = extern struct { + _type: EventType, // SDL_EVENT_DROP_BEGIN or SDL_EVENT_DROP_FILE or SDL_EVENT_DROP_TEXT or SDL_EVENT_DROP_COMPLETE or SDL_EVENT_DROP_POSITION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window that was dropped on, if any + x: f32, // X coordinate, relative to window (not on begin) + y: f32, // Y coordinate, relative to window (not on begin) + source: [*c]const u8, // The source app that sent this drop event, or NULL if that isn't available + data: [*c]const u8, // The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events +}; + +pub const ClipboardEvent = extern struct { + _type: EventType, // SDL_EVENT_CLIPBOARD_UPDATE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + owner: bool, // are we owning the clipboard (internal update) + num_mime_types: i32, // number of mime types + mime_types: [*c][*c]const u8, // current mime types +}; + +pub const SensorEvent = extern struct { + _type: EventType, // SDL_EVENT_SENSOR_UPDATE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: SensorID, // The instance ID of the sensor + data: [6]f32, // Up to 6 values from the sensor - additional values can be queried using SDL_GetSensorData() + sensor_timestamp: u64, // The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock +}; + +pub const QuitEvent = extern struct { + _type: EventType, // SDL_EVENT_QUIT + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() +}; + +pub const UserEvent = extern struct { + _type: u32, // SDL_EVENT_USER through SDL_EVENT_LAST-1, Uint32 because these are not in the SDL_EventType enumeration + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The associated window if any + code: i32, // User defined event code + data1: ?*anyopaque, // User defined data pointer + data2: ?*anyopaque, // User defined data pointer +}; + +pub const Event = extern union { + _type: u32, // Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration + common: CommonEvent, // Common event data + display: DisplayEvent, // Display event data + window: WindowEvent, // Window event data + kdevice: KeyboardDeviceEvent, // Keyboard device change event data + key: KeyboardEvent, // Keyboard event data + edit: TextEditingEvent, // Text editing event data + edit_candidates: TextEditingCandidatesEvent, // Text editing candidates event data + text: TextInputEvent, // Text input event data + mdevice: MouseDeviceEvent, // Mouse device change event data + motion: MouseMotionEvent, // Mouse motion event data + button: MouseButtonEvent, // Mouse button event data + wheel: MouseWheelEvent, // Mouse wheel event data + jdevice: JoyDeviceEvent, // Joystick device change event data + jaxis: JoyAxisEvent, // Joystick axis event data + jball: JoyBallEvent, // Joystick ball event data + jhat: JoyHatEvent, // Joystick hat event data + jbutton: JoyButtonEvent, // Joystick button event data + jbattery: JoyBatteryEvent, // Joystick battery event data + gdevice: GamepadDeviceEvent, // Gamepad device event data + gaxis: GamepadAxisEvent, // Gamepad axis event data + gbutton: GamepadButtonEvent, // Gamepad button event data + gtouchpad: GamepadTouchpadEvent, // Gamepad touchpad event data + gsensor: GamepadSensorEvent, // Gamepad sensor event data + adevice: AudioDeviceEvent, // Audio device event data + cdevice: CameraDeviceEvent, // Camera device event data + sensor: SensorEvent, // Sensor event data + quit: QuitEvent, // Quit request event data + user: UserEvent, // Custom event data + tfinger: TouchFingerEvent, // Touch finger event data + pproximity: PenProximityEvent, // Pen proximity event data + ptouch: PenTouchEvent, // Pen tip touching event data + pmotion: PenMotionEvent, // Pen motion event data + pbutton: PenButtonEvent, // Pen button event data + paxis: PenAxisEvent, // Pen axis event data + render: RenderEvent, // Render event data + drop: DropEvent, // Drag and drop event data + clipboard: ClipboardEvent, // Clipboard event data + padding: [128]u8, +}; + +pub inline fn pumpEvents() void { + return c.SDL_PumpEvents(); +} + +pub const EventAction = enum(c_int) { + addevent, //Add events to the back of the queue. + peekevent, //Check but don't remove events from the queue front. + getevent, //Retrieve/remove events from the front of the queue. +}; + +pub inline fn peepEvents(events: ?*Event, numevents: c_int, action: EventAction, minType: u32, maxType: u32) c_int { + return c.SDL_PeepEvents(events, numevents, action, minType, maxType); +} + +pub inline fn hasEvent(_type: u32) bool { + return c.SDL_HasEvent(_type); +} + +pub inline fn hasEvents(minType: u32, maxType: u32) bool { + return c.SDL_HasEvents(minType, maxType); +} + +pub inline fn flushEvent(_type: u32) void { + return c.SDL_FlushEvent(_type); +} + +pub inline fn flushEvents(minType: u32, maxType: u32) void { + return c.SDL_FlushEvents(minType, maxType); +} + +pub inline fn pollEvent(event: ?*Event) bool { + return c.SDL_PollEvent(event); +} + +pub inline fn waitEvent(event: ?*Event) bool { + return c.SDL_WaitEvent(event); +} + +pub inline fn waitEventTimeout(event: ?*Event, timeoutMS: i32) bool { + return c.SDL_WaitEventTimeout(event, timeoutMS); +} + +pub inline fn pushEvent(event: ?*Event) bool { + return c.SDL_PushEvent(event); +} + +pub const EventFilter = c.SDL_EventFilter; + +pub inline fn setEventFilter(filter: EventFilter, userdata: ?*anyopaque) void { + return c.SDL_SetEventFilter(filter, userdata); +} + +pub inline fn getEventFilter(filter: ?*EventFilter, userdata: [*c]?*anyopaque) bool { + return c.SDL_GetEventFilter(filter, userdata); +} + +pub inline fn addEventWatch(filter: EventFilter, userdata: ?*anyopaque) bool { + return c.SDL_AddEventWatch(filter, userdata); +} + +pub inline fn removeEventWatch(filter: EventFilter, userdata: ?*anyopaque) void { + return c.SDL_RemoveEventWatch(filter, userdata); +} + +pub inline fn filterEvents(filter: EventFilter, userdata: ?*anyopaque) void { + return c.SDL_FilterEvents(filter, userdata); +} + +pub inline fn setEventEnabled(_type: u32, enabled: bool) void { + return c.SDL_SetEventEnabled(_type, enabled); +} + +pub inline fn eventEnabled(_type: u32) bool { + return c.SDL_EventEnabled(_type); +} + +pub inline fn registerEvents(numevents: c_int) u32 { + return c.SDL_RegisterEvents(numevents); +} + +pub inline fn getWindowFromEvent(event: *const Event) ?*Window { + return c.SDL_GetWindowFromEvent(@ptrCast(event)); +} diff --git a/v2/loadso.zig b/v2/loadso.zig index b59c408..6bf3894 100644 --- a/v2/loadso.zig +++ b/v2/loadso.zig @@ -1,7 +1,7 @@ const std = @import("std"); pub const c = @import("c.zig").c; -pub const FunctionPointer = ?*anyopaque; +pub const FunctionPointer = c.SDL_FunctionPointer; pub const SharedObject = opaque { pub inline fn loadFunction(sharedobject: *SharedObject, name: [*c]const u8) FunctionPointer { diff --git a/v2/render.zig b/v2/render.zig new file mode 100644 index 0000000..f50ce41 --- /dev/null +++ b/v2/render.zig @@ -0,0 +1,1157 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const FPoint = extern struct { + x: f32, + y: f32, +}; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes, //Android video texture format + pixelformatMjpg, //Motion JPEG +}; + +pub const FColor = extern struct { + r: f32, + g: f32, + b: f32, + a: f32, +}; + +pub const Surface = opaque { + pub inline fn createSoftwareRenderer(surface: *Surface) ?*Renderer { + return c.SDL_CreateSoftwareRenderer(surface); + } +}; + +pub const ScaleMode = enum(c_int) { + scalemodeNearest, //nearest pixel sampling + scalemodeLinear, //linear filtering +}; + +pub const PropertiesID = u32; + +pub const BlendMode = u32; + +pub const Window = opaque { + pub inline fn createRenderer(window: *Window, name: [*c]const u8) ?*Renderer { + return c.SDL_CreateRenderer(window, name); + } + + pub inline fn getRenderer(window: *Window) ?*Renderer { + return c.SDL_GetRenderer(window); + } +}; + +pub const FRect = extern struct { + x: f32, + y: f32, + w: f32, + h: f32, +}; + +pub const Event = extern union { + _type: u32, // Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration + common: CommonEvent, // Common event data + display: DisplayEvent, // Display event data + window: WindowEvent, // Window event data + kdevice: KeyboardDeviceEvent, // Keyboard device change event data + key: KeyboardEvent, // Keyboard event data + edit: TextEditingEvent, // Text editing event data + edit_candidates: TextEditingCandidatesEvent, // Text editing candidates event data + text: TextInputEvent, // Text input event data + mdevice: MouseDeviceEvent, // Mouse device change event data + motion: MouseMotionEvent, // Mouse motion event data + button: MouseButtonEvent, // Mouse button event data + wheel: MouseWheelEvent, // Mouse wheel event data + jdevice: JoyDeviceEvent, // Joystick device change event data + jaxis: JoyAxisEvent, // Joystick axis event data + jball: JoyBallEvent, // Joystick ball event data + jhat: JoyHatEvent, // Joystick hat event data + jbutton: JoyButtonEvent, // Joystick button event data + jbattery: JoyBatteryEvent, // Joystick battery event data + gdevice: GamepadDeviceEvent, // Gamepad device event data + gaxis: GamepadAxisEvent, // Gamepad axis event data + gbutton: GamepadButtonEvent, // Gamepad button event data + gtouchpad: GamepadTouchpadEvent, // Gamepad touchpad event data + gsensor: GamepadSensorEvent, // Gamepad sensor event data + adevice: AudioDeviceEvent, // Audio device event data + cdevice: CameraDeviceEvent, // Camera device event data + sensor: SensorEvent, // Sensor event data + quit: QuitEvent, // Quit request event data + user: UserEvent, // Custom event data + tfinger: TouchFingerEvent, // Touch finger event data + pproximity: PenProximityEvent, // Pen proximity event data + ptouch: PenTouchEvent, // Pen tip touching event data + pmotion: PenMotionEvent, // Pen motion event data + pbutton: PenButtonEvent, // Pen button event data + paxis: PenAxisEvent, // Pen axis event data + render: RenderEvent, // Render event data + drop: DropEvent, // Drag and drop event data + clipboard: ClipboardEvent, // Clipboard event data + padding: [128]u8, +}; + +pub const JoyAxisEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_AXIS_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + axis: u8, // The joystick axis index + padding1: u8, + padding2: u8, + padding3: u8, + value: i16, // The axis value (range: -32768 to 32767) + padding4: u16, +}; + +pub const UserEvent = extern struct { + _type: u32, // SDL_EVENT_USER through SDL_EVENT_LAST-1, Uint32 because these are not in the SDL_EventType enumeration + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The associated window if any + code: i32, // User defined event code + data1: ?*anyopaque, // User defined data pointer + data2: ?*anyopaque, // User defined data pointer +}; + +pub const MouseMotionEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: MouseID, // The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0 + state: MouseButtonFlags, // The current button state + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + xrel: f32, // The relative motion in the X direction + yrel: f32, // The relative motion in the Y direction +}; + +pub const CommonEvent = extern struct { + _type: u32, // Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() +}; + +pub const GamepadButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_BUTTON_DOWN or SDL_EVENT_GAMEPAD_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + button: u8, // The gamepad button (SDL_GamepadButton) + down: bool, // true if the button is pressed + padding1: u8, + padding2: u8, +}; + +pub const JoyDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_ADDED or SDL_EVENT_JOYSTICK_REMOVED or SDL_EVENT_JOYSTICK_UPDATE_COMPLETE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id +}; + +pub const GamepadTouchpadEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN or SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION or SDL_EVENT_GAMEPAD_TOUCHPAD_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + touchpad: i32, // The index of the touchpad + finger: i32, // The index of the finger on the touchpad + x: f32, // Normalized in the range 0...1 with 0 being on the left + y: f32, // Normalized in the range 0...1 with 0 being at the top + pressure: f32, // Normalized in the range 0...1 +}; + +pub const GamepadSensorEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_SENSOR_UPDATE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + sensor: i32, // The type of the sensor, one of the values of SDL_SensorType + data: [3]f32, // Up to 3 values from the sensor, as defined in SDL_sensor.h + sensor_timestamp: u64, // The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock +}; + +pub const RenderEvent = extern struct { + _type: EventType, // SDL_EVENT_RENDER_TARGETS_RESET, SDL_EVENT_RENDER_DEVICE_RESET, SDL_EVENT_RENDER_DEVICE_LOST + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window containing the renderer in question. +}; + +pub const ClipboardEvent = extern struct { + _type: EventType, // SDL_EVENT_CLIPBOARD_UPDATE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + owner: bool, // are we owning the clipboard (internal update) + num_mime_types: i32, // number of mime types + mime_types: [*c][*c]const u8, // current mime types +}; + +pub const PenMotionEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window +}; + +pub const GamepadAxisEvent = extern struct { + _type: EventType, // SDL_EVENT_GAMEPAD_AXIS_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + axis: u8, // The gamepad axis (SDL_GamepadAxis) + padding1: u8, + padding2: u8, + padding3: u8, + value: i16, // The axis value (range: -32768 to 32767) + padding4: u16, +}; + +pub const DisplayEvent = extern struct { + _type: EventType, // SDL_DISPLAYEVENT_* + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + displayID: DisplayID, // The associated display + data1: i32, // event dependent data + data2: i32, // event dependent data +}; + +pub const DropEvent = extern struct { + _type: EventType, // SDL_EVENT_DROP_BEGIN or SDL_EVENT_DROP_FILE or SDL_EVENT_DROP_TEXT or SDL_EVENT_DROP_COMPLETE or SDL_EVENT_DROP_POSITION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window that was dropped on, if any + x: f32, // X coordinate, relative to window (not on begin) + y: f32, // Y coordinate, relative to window (not on begin) + source: [*c]const u8, // The source app that sent this drop event, or NULL if that isn't available + data: [*c]const u8, // The text for SDL_EVENT_DROP_TEXT and the file name for SDL_EVENT_DROP_FILE, NULL for other events +}; + +pub const CameraDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_CAMERA_DEVICE_ADDED, SDL_EVENT_CAMERA_DEVICE_REMOVED, SDL_EVENT_CAMERA_DEVICE_APPROVED, SDL_EVENT_CAMERA_DEVICE_DENIED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: CameraID, // SDL_CameraID for the device being added or removed or changing +}; + +pub const KeyboardDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_KEYBOARD_ADDED or SDL_EVENT_KEYBOARD_REMOVED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: KeyboardID, // The keyboard instance id +}; + +pub const JoyBatteryEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_BATTERY_UPDATED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + state: PowerState, // The joystick battery state + percent: c_int, // The joystick battery percent charge remaining +}; + +pub const TouchFingerEvent = extern struct { + _type: EventType, // SDL_EVENT_FINGER_DOWN, SDL_EVENT_FINGER_UP, SDL_EVENT_FINGER_MOTION, or SDL_EVENT_FINGER_CANCELED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + touchID: TouchID, // The touch device id + fingerID: FingerID, + x: f32, // Normalized in the range 0...1 + y: f32, // Normalized in the range 0...1 + dx: f32, // Normalized in the range -1...1 + dy: f32, // Normalized in the range -1...1 + pressure: f32, // Normalized in the range 0...1 + windowID: WindowID, // The window underneath the finger, if any +}; + +pub const SensorEvent = extern struct { + _type: EventType, // SDL_EVENT_SENSOR_UPDATE + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: SensorID, // The instance ID of the sensor + data: [6]f32, // Up to 6 values from the sensor - additional values can be queried using SDL_GetSensorData() + sensor_timestamp: u64, // The timestamp of the sensor reading in nanoseconds, not necessarily synchronized with the system clock +}; + +pub const TextEditingEvent = extern struct { + _type: EventType, // SDL_EVENT_TEXT_EDITING + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + text: [*c]const u8, // The editing text + start: i32, // The start cursor of selected editing text, or -1 if not set + length: i32, // The length of selected editing text, or -1 if not set +}; + +pub const JoyHatEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_HAT_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + hat: u8, // The joystick hat index + padding1: u8, + padding2: u8, +}; + +pub const QuitEvent = extern struct { + _type: EventType, // SDL_EVENT_QUIT + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() +}; + +pub const PenProximityEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_PROXIMITY_IN or SDL_EVENT_PEN_PROXIMITY_OUT + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id +}; + +pub const WindowEvent = extern struct { + _type: EventType, // SDL_EVENT_WINDOW_* + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The associated window + data1: i32, // event dependent data + data2: i32, // event dependent data +}; + +pub const PenTouchEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_DOWN or SDL_EVENT_PEN_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + eraser: bool, // true if eraser end is used (not all pens support this). + down: bool, // true if the pen is touching or false if the pen is lifted off +}; + +pub const PenButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_BUTTON_DOWN or SDL_EVENT_PEN_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + button: u8, // The pen button index (first button is 1). + down: bool, // true if the button is pressed +}; + +pub const GamepadDeviceEvent = extern struct { + _type: EventType, // 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 + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id +}; + +pub const JoyBallEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_BALL_MOTION + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + ball: u8, // The joystick trackball index + padding1: u8, + padding2: u8, + padding3: u8, + xrel: i16, // The relative motion in the X direction + yrel: i16, // The relative motion in the Y direction +}; + +pub const AudioDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_AUDIO_DEVICE_ADDED, or SDL_EVENT_AUDIO_DEVICE_REMOVED, or SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: AudioDeviceID, // SDL_AudioDeviceID for the device being added or removed or changing + recording: bool, // false if a playback device, true if a recording device. + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const MouseWheelEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_WHEEL + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: MouseID, // The mouse instance id in relative mode or 0 + x: f32, // The amount scrolled horizontally, positive to the right and negative to the left + y: f32, // The amount scrolled vertically, positive away from the user and negative toward the user + direction: MouseWheelDirection, // 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 + mouse_x: f32, // X coordinate, relative to window + mouse_y: f32, // Y coordinate, relative to window + integer_x: i32, // The amount scrolled horizontally, accumulated to whole scroll "ticks" (added in 3.2.12) + integer_y: i32, // The amount scrolled vertically, accumulated to whole scroll "ticks" (added in 3.2.12) +}; + +pub const PenAxisEvent = extern struct { + _type: EventType, // SDL_EVENT_PEN_AXIS + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with pen focus, if any + which: PenID, // The pen instance id + pen_state: PenInputFlags, // Complete pen input state at time of event + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window + axis: PenAxis, // Axis that has changed + value: f32, // New value of axis +}; + +pub const MouseDeviceEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_ADDED or SDL_EVENT_MOUSE_REMOVED + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: MouseID, // The mouse instance id +}; + +pub const JoyButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_JOYSTICK_BUTTON_DOWN or SDL_EVENT_JOYSTICK_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + which: JoystickID, // The joystick instance id + button: u8, // The joystick button index + down: bool, // true if the button is pressed + padding1: u8, + padding2: u8, +}; + +pub const MouseButtonEvent = extern struct { + _type: EventType, // SDL_EVENT_MOUSE_BUTTON_DOWN or SDL_EVENT_MOUSE_BUTTON_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with mouse focus, if any + which: MouseID, // The mouse instance id in relative mode, SDL_TOUCH_MOUSEID for touch events, or 0 + button: u8, // The mouse button index + down: bool, // true if the button is pressed + clicks: u8, // 1 for single-click, 2 for double-click, etc. + padding: u8, + x: f32, // X coordinate, relative to window + y: f32, // Y coordinate, relative to window +}; + +pub const KeyboardEvent = extern struct { + _type: EventType, // SDL_EVENT_KEY_DOWN or SDL_EVENT_KEY_UP + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + which: KeyboardID, // The keyboard instance id, or 0 if unknown or virtual + scancode: Scancode, // SDL physical key code + key: Keycode, // SDL virtual key code + mod: Keymod, // current key modifiers + raw: u16, // The platform dependent scancode for this event + down: bool, // true if the key is pressed + repeat: bool, // true if this is a key repeat +}; + +pub const TextEditingCandidatesEvent = extern struct { + _type: EventType, // SDL_EVENT_TEXT_EDITING_CANDIDATES + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + candidates: [*c]const [*c]const u8, // The list of candidates, or NULL if there are no candidates available + num_candidates: i32, // The number of strings in `candidates` + selected_candidate: i32, // The index of the selected candidate, or -1 if no candidate is selected + horizontal: bool, // true if the list is horizontal, false if it's vertical + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const TextInputEvent = extern struct { + _type: EventType, // SDL_EVENT_TEXT_INPUT + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + windowID: WindowID, // The window with keyboard focus, if any + text: [*c]const u8, // The input text, UTF-8 encoded +}; + +pub const EventType = enum(c_int) { + eventFirst, //Unused (do not remove) + eventQuit, //User-requested quit + eventTerminating, + eventLowMemory, + eventWillEnterBackground, + eventDidEnterBackground, + eventWillEnterForeground, + eventDidEnterForeground, + eventLocaleChanged, //The user's locale preferences have changed. + eventSystemThemeChanged, //The system theme changed + eventDisplayOrientation, //Display orientation has changed to data1 + eventDisplayAdded, //Display has been added to the system + eventDisplayRemoved, //Display has been removed from the system + eventDisplayMoved, //Display has changed position + eventDisplayDesktopModeChanged, //Display has changed desktop mode + eventDisplayCurrentModeChanged, //Display has changed current mode + eventDisplayContentScaleChanged, //Display has changed content scale + eventWindowShown, //Window has been shown + eventWindowHidden, //Window has been hidden + eventWindowExposed, //Window has been exposed and should be redrawn, and can be redrawn directly from event watchers for this event + eventWindowMoved, //Window has been moved to data1, data2 + eventWindowResized, //Window has been resized to data1xdata2 + eventWindowPixelSizeChanged, //The pixel size of the window has changed to data1xdata2 + eventWindowMetalViewResized, //The pixel size of a Metal view associated with the window has changed + eventWindowMinimized, //Window has been minimized + eventWindowMaximized, //Window has been maximized + eventWindowRestored, //Window has been restored to normal size and position + eventWindowMouseEnter, //Window has gained mouse focus + eventWindowMouseLeave, //Window has lost mouse focus + eventWindowFocusGained, //Window has gained keyboard focus + eventWindowFocusLost, //Window has lost keyboard focus + eventWindowCloseRequested, //The window manager requests that the window be closed + eventWindowHitTest, //Window had a hit test that wasn't SDL_HITTEST_NORMAL + eventWindowIccprofChanged, //The ICC profile of the window's display has changed + eventWindowDisplayChanged, //Window has been moved to display data1 + eventWindowDisplayScaleChanged, //Window display scale has been changed + eventWindowSafeAreaChanged, //The window safe area has been changed + eventWindowOccluded, //The window has been occluded + eventWindowEnterFullscreen, //The window has entered fullscreen mode + eventWindowLeaveFullscreen, //The window has left fullscreen mode + eventWindowDestroyed, + eventWindowHdrStateChanged, //Window HDR properties have changed + eventKeyDown, //Key pressed + eventKeyUp, //Key released + eventTextEditing, //Keyboard text editing (composition) + eventTextInput, //Keyboard text input + eventKeymapChanged, + eventKeyboardAdded, //A new keyboard has been inserted into the system + eventKeyboardRemoved, //A keyboard has been removed + eventTextEditingCandidates, //Keyboard text editing candidates + eventMouseMotion, //Mouse moved + eventMouseButtonDown, //Mouse button pressed + eventMouseButtonUp, //Mouse button released + eventMouseWheel, //Mouse wheel motion + eventMouseAdded, //A new mouse has been inserted into the system + eventMouseRemoved, //A mouse has been removed + eventJoystickAxisMotion, //Joystick axis motion + eventJoystickBallMotion, //Joystick trackball motion + eventJoystickHatMotion, //Joystick hat position change + eventJoystickButtonDown, //Joystick button pressed + eventJoystickButtonUp, //Joystick button released + eventJoystickAdded, //A new joystick has been inserted into the system + eventJoystickRemoved, //An opened joystick has been removed + eventJoystickBatteryUpdated, //Joystick battery level change + eventJoystickUpdateComplete, //Joystick update is complete + eventGamepadAxisMotion, //Gamepad axis motion + eventGamepadButtonDown, //Gamepad button pressed + eventGamepadButtonUp, //Gamepad button released + eventGamepadAdded, //A new gamepad has been inserted into the system + eventGamepadRemoved, //A gamepad has been removed + eventGamepadRemapped, //The gamepad mapping was updated + eventGamepadTouchpadDown, //Gamepad touchpad was touched + eventGamepadTouchpadMotion, //Gamepad touchpad finger was moved + eventGamepadTouchpadUp, //Gamepad touchpad finger was lifted + eventGamepadSensorUpdate, //Gamepad sensor was updated + eventGamepadUpdateComplete, //Gamepad update is complete + eventGamepadSteamHandleUpdated, //Gamepad Steam handle has changed + eventFingerUp, + eventFingerMotion, + eventFingerCanceled, + eventClipboardUpdate, //The clipboard or primary selection changed + eventDropFile, //The system requests a file open + eventDropText, //text/plain drag-and-drop event + eventDropBegin, //A new set of drops is beginning (NULL filename) + eventDropComplete, //Current set of drops is now complete (NULL filename) + eventDropPosition, //Position while moving over the window + eventAudioDeviceAdded, //A new audio device is available + eventAudioDeviceRemoved, //An audio device has been removed. + eventAudioDeviceFormatChanged, //An audio device's format has been changed by the system. + eventSensorUpdate, //A sensor was updated + eventPenProximityIn, //Pressure-sensitive pen has become available + eventPenProximityOut, //Pressure-sensitive pen has become unavailable + eventPenDown, //Pressure-sensitive pen touched drawing surface + eventPenUp, //Pressure-sensitive pen stopped touching drawing surface + eventPenButtonDown, //Pressure-sensitive pen button pressed + eventPenButtonUp, //Pressure-sensitive pen button released + eventPenMotion, //Pressure-sensitive pen is moving on the tablet + eventPenAxis, //Pressure-sensitive pen angle/pressure/etc changed + eventCameraDeviceAdded, //A new camera device is available + eventCameraDeviceRemoved, //A camera device has been removed. + eventCameraDeviceApproved, //A camera device has been approved for use by the user. + eventCameraDeviceDenied, //A camera device has been denied for use by the user. + eventRenderTargetsReset, //The render targets have been reset and their contents need to be updated + eventRenderDeviceReset, //The device has been reset and all textures need to be recreated + eventRenderDeviceLost, //The device has been lost and can't be recovered. + eventPrivate1, + eventPrivate2, + eventPrivate3, + eventPollSentinel, //Signals the end of an event poll cycle +}; + +pub const JoystickID = u32; + +pub const WindowID = u32; + +pub const MouseID = u32; + +pub const MouseButtonFlags = packed struct(u32) { + buttonLeft: bool = false, + buttonMiddle: bool = false, + buttonX1: bool = false, + pad0: u28 = 0, + rsvd: bool = false, +}; + +pub const PenInputFlags = packed struct(u32) { + penInputDown: bool = false, // pen is pressed down + penInputButton1: bool = false, // button 1 is pressed + penInputButton2: bool = false, // button 2 is pressed + penInputButton3: bool = false, // button 3 is pressed + penInputButton4: bool = false, // button 4 is pressed + penInputButton5: bool = false, // button 5 is pressed + penInputEraserTip: bool = false, // eraser tip is used + pad0: u24 = 0, + rsvd: bool = false, +}; + +pub const PenID = u32; + +pub const DisplayID = u32; + +pub const CameraID = u32; + +pub const KeyboardID = u32; + +pub const PowerState = enum(c_int) { + powerstateError, //error determining power status + powerstateUnknown, //cannot determine power status + powerstateOnBattery, //Not plugged in, running on the battery + powerstateNoBattery, //Plugged in, no battery available + powerstateCharging, //Plugged in, charging battery + powerstateCharged, +}; + +pub const TouchID = u64; + +pub const FingerID = u64; + +pub const SensorID = u32; + +pub const AudioDeviceID = u32; + +pub const MouseWheelDirection = enum(c_int) { + mousewheelNormal, //The scroll direction is normal + mousewheelFlipped, //The scroll direction is flipped / natural +}; + +pub const PenAxis = enum(c_int) { + penAxisPressure, //Pen pressure. Unidirectional: 0 to 1.0 + penAxisXtilt, //Pen horizontal tilt angle. Bidirectional: -90.0 to 90.0 (left-to-right). + penAxisYtilt, //Pen vertical tilt angle. Bidirectional: -90.0 to 90.0 (top-to-down). + penAxisDistance, //Pen distance to drawing surface. Unidirectional: 0.0 to 1.0 + penAxisRotation, //Pen barrel rotation. Bidirectional: -180 to 179.9 (clockwise, 0 is facing up, -180.0 is facing down). + penAxisSlider, //Pen finger wheel or slider (e.g., Airbrush Pen). Unidirectional: 0 to 1.0 + penAxisTangentialPressure, //Pressure from squeezing the pen ("barrel pressure"). + penAxisCount, //Total known pen axis types in this version of SDL. This number may grow in future releases! +}; + +pub const Scancode = enum(c_int) { + scancodeBackslash, + scancodeNonushash, + scancodeGrave, + scancodeInsert, + scancodeNumlockclear, + scancodeNonusbackslash, + scancodeApplication, //windows contextual menu, compose + scancodePower, + scancodeHelp, //AL Integrated Help Center + scancodeMenu, //Menu (show menu) + scancodeStop, //AC Stop + scancodeAgain, //AC Redo/Repeat + scancodeUndo, //AC Undo + scancodeCut, //AC Cut + scancodeCopy, //AC Copy + scancodePaste, //AC Paste + scancodeFind, //AC Find + scancodeInternational1, + scancodeInternational3, //Yen + scancodeLang1, //Hangul/English toggle + scancodeLang2, //Hanja conversion + scancodeLang3, //Katakana + scancodeLang4, //Hiragana + scancodeLang5, //Zenkaku/Hankaku + scancodeLang6, //reserved + scancodeLang7, //reserved + scancodeLang8, //reserved + scancodeLang9, //reserved + scancodeAlterase, //Erase-Eaze + scancodeCancel, //AC Cancel + scancodeLalt, //alt, option + scancodeLgui, //windows, command (apple), meta + scancodeRalt, //alt gr, option + scancodeRgui, //windows, command (apple), meta + scancodeMode, + scancodeSleep, //Sleep + scancodeWake, //Wake + scancodeChannelIncrement, //Channel Increment + scancodeChannelDecrement, //Channel Decrement + scancodeMediaPlay, //Play + scancodeMediaPause, //Pause + scancodeMediaRecord, //Record + scancodeMediaFastForward, //Fast Forward + scancodeMediaRewind, //Rewind + scancodeMediaNextTrack, //Next Track + scancodeMediaPreviousTrack, //Previous Track + scancodeMediaStop, //Stop + scancodeMediaEject, //Eject + scancodeMediaPlayPause, //Play / Pause + scancodeMediaSelect, + scancodeAcNew, //AC New + scancodeAcOpen, //AC Open + scancodeAcClose, //AC Close + scancodeAcExit, //AC Exit + scancodeAcSave, //AC Save + scancodeAcPrint, //AC Print + scancodeAcProperties, //AC Properties + scancodeAcSearch, //AC Search + scancodeAcHome, //AC Home + scancodeAcBack, //AC Back + scancodeAcForward, //AC Forward + scancodeAcStop, //AC Stop + scancodeAcRefresh, //AC Refresh + scancodeAcBookmarks, //AC Bookmarks + scancodeSoftleft, + scancodeSoftright, + scancodeCall, //Used for accepting phone calls. + scancodeEndcall, //Used for rejecting phone calls. + scancodeReserved, //400-500 reserved for dynamic keycodes + scancodeCount, +}; + +pub const Keymod = u16; + +pub const Keycode = u32; + +pub const FlipMode = enum(c_int) { + flipNone, //Do not flip + flipHorizontal, //flip horizontally + flipVertical, //flip vertically +}; + +pub const Rect = extern struct { + x: c_int, + y: c_int, + w: c_int, + h: c_int, +}; + +pub const WindowFlags = packed struct(u64) { + windowFullscreen: bool = false, // window is in fullscreen mode + windowOpengl: bool = false, // window usable with OpenGL context + windowOccluded: bool = false, // window is occluded + windowHidden: bool = false, // window is neither mapped onto the desktop nor shown in the taskbar/dock/window list; SDL_ShowWindow() is required for it to become visible + windowBorderless: bool = false, // no window decoration + windowResizable: bool = false, // window can be resized + windowMinimized: bool = false, // window is minimized + windowMaximized: bool = false, // window is maximized + windowMouseGrabbed: bool = false, // window has grabbed mouse input + windowInputFocus: bool = false, // window has input focus + windowMouseFocus: bool = false, // window has mouse focus + windowExternal: bool = false, // window not created by SDL + windowModal: bool = false, // window is modal + windowHighPixelDensity: bool = false, // window uses high pixel density back buffer if possible + windowMouseCapture: bool = false, // window has mouse captured (unrelated to MOUSE_GRABBED) + windowMouseRelativeMode: bool = false, // window has relative mode enabled + windowAlwaysOnTop: bool = false, // window should always be above others + windowUtility: bool = false, // window should be treated as a utility window, not showing in the task bar and window list + windowTooltip: bool = false, // window should be treated as a tooltip and does not get mouse or keyboard focus, requires a parent window + windowPopupMenu: bool = false, // window should be treated as a popup menu, requires a parent window + windowKeyboardGrabbed: bool = false, // window has grabbed keyboard input + windowVulkan: bool = false, // window usable for Vulkan surface + windowMetal: bool = false, // window usable for Metal view + windowTransparent: bool = false, // window with transparent buffer + windowNotFocusable: bool = false, // window should not be focusable + pad0: u38 = 0, + rsvd: bool = false, +}; + +pub const Vertex = extern struct { + position: FPoint, // Vertex position, in SDL_Renderer coordinates + color: FColor, // Vertex color + tex_coord: FPoint, // Normalized texture coordinates, if needed +}; + +pub const TextureAccess = enum(c_int) { + textureaccessStatic, //Changes rarely, not lockable + textureaccessStreaming, //Changes frequently, lockable + textureaccessTarget, //Texture can be used as a render target +}; + +pub const RendererLogicalPresentation = enum(c_int) { + logicalPresentationDisabled, //There is no logical size in effect + logicalPresentationStretch, //The rendered content is stretched to the output resolution + logicalPresentationLetterbox, //The rendered content is fit to the largest dimension and the other dimension is letterboxed with black bars + logicalPresentationOverscan, //The rendered content is fit to the smallest dimension and the other dimension extends beyond the output bounds + logicalPresentationIntegerScale, //The rendered content is scaled up by integer multiples to fit the output resolution +}; + +pub const Renderer = opaque { + pub inline fn getRenderWindow(renderer: *Renderer) ?*Window { + return c.SDL_GetRenderWindow(renderer); + } + + pub inline fn getRendererName(renderer: *Renderer) [*c]const u8 { + return c.SDL_GetRendererName(renderer); + } + + pub inline fn getRendererProperties(renderer: *Renderer) PropertiesID { + return c.SDL_GetRendererProperties(renderer); + } + + pub inline fn getRenderOutputSize(renderer: *Renderer, w: *c_int, h: *c_int) bool { + return c.SDL_GetRenderOutputSize(renderer, @ptrCast(w), @ptrCast(h)); + } + + pub inline fn getCurrentRenderOutputSize(renderer: *Renderer, w: *c_int, h: *c_int) bool { + return c.SDL_GetCurrentRenderOutputSize(renderer, @ptrCast(w), @ptrCast(h)); + } + + pub inline fn createTexture(renderer: *Renderer, format: PixelFormat, access: TextureAccess, w: c_int, h: c_int) ?*Texture { + return c.SDL_CreateTexture(renderer, @bitCast(format), access, w, h); + } + + pub inline fn createTextureFromSurface(renderer: *Renderer, surface: ?*Surface) ?*Texture { + return c.SDL_CreateTextureFromSurface(renderer, surface); + } + + pub inline fn createTextureWithProperties(renderer: *Renderer, props: PropertiesID) ?*Texture { + return c.SDL_CreateTextureWithProperties(renderer, props); + } + + pub inline fn setRenderTarget(renderer: *Renderer, texture: ?*Texture) bool { + return c.SDL_SetRenderTarget(renderer, texture); + } + + pub inline fn getRenderTarget(renderer: *Renderer) ?*Texture { + return c.SDL_GetRenderTarget(renderer); + } + + pub inline fn setRenderLogicalPresentation(renderer: *Renderer, w: c_int, h: c_int, mode: RendererLogicalPresentation) bool { + return c.SDL_SetRenderLogicalPresentation(renderer, w, h, mode); + } + + pub inline fn getRenderLogicalPresentation(renderer: *Renderer, w: *c_int, h: *c_int, mode: ?*RendererLogicalPresentation) bool { + return c.SDL_GetRenderLogicalPresentation(renderer, @ptrCast(w), @ptrCast(h), mode); + } + + pub inline fn getRenderLogicalPresentationRect(renderer: *Renderer, rect: ?*FRect) bool { + return c.SDL_GetRenderLogicalPresentationRect(renderer, rect); + } + + pub inline fn renderCoordinatesFromWindow(renderer: *Renderer, window_x: f32, window_y: f32, x: *f32, y: *f32) bool { + return c.SDL_RenderCoordinatesFromWindow(renderer, window_x, window_y, @ptrCast(x), @ptrCast(y)); + } + + pub inline fn renderCoordinatesToWindow(renderer: *Renderer, x: f32, y: f32, window_x: *f32, window_y: *f32) bool { + return c.SDL_RenderCoordinatesToWindow(renderer, x, y, @ptrCast(window_x), @ptrCast(window_y)); + } + + pub inline fn convertEventToRenderCoordinates(renderer: *Renderer, event: ?*Event) bool { + return c.SDL_ConvertEventToRenderCoordinates(renderer, event); + } + + pub inline fn setRenderViewport(renderer: *Renderer, rect: *const Rect) bool { + return c.SDL_SetRenderViewport(renderer, @ptrCast(rect)); + } + + pub inline fn getRenderViewport(renderer: *Renderer, rect: ?*Rect) bool { + return c.SDL_GetRenderViewport(renderer, rect); + } + + pub inline fn renderViewportSet(renderer: *Renderer) bool { + return c.SDL_RenderViewportSet(renderer); + } + + pub inline fn getRenderSafeArea(renderer: *Renderer, rect: ?*Rect) bool { + return c.SDL_GetRenderSafeArea(renderer, rect); + } + + pub inline fn setRenderClipRect(renderer: *Renderer, rect: *const Rect) bool { + return c.SDL_SetRenderClipRect(renderer, @ptrCast(rect)); + } + + pub inline fn getRenderClipRect(renderer: *Renderer, rect: ?*Rect) bool { + return c.SDL_GetRenderClipRect(renderer, rect); + } + + pub inline fn renderClipEnabled(renderer: *Renderer) bool { + return c.SDL_RenderClipEnabled(renderer); + } + + pub inline fn setRenderScale(renderer: *Renderer, scaleX: f32, scaleY: f32) bool { + return c.SDL_SetRenderScale(renderer, scaleX, scaleY); + } + + pub inline fn getRenderScale(renderer: *Renderer, scaleX: *f32, scaleY: *f32) bool { + return c.SDL_GetRenderScale(renderer, @ptrCast(scaleX), @ptrCast(scaleY)); + } + + pub inline fn setRenderDrawColor(renderer: *Renderer, r: u8, g: u8, b: u8, a: u8) bool { + return c.SDL_SetRenderDrawColor(renderer, r, g, b, a); + } + + pub inline fn setRenderDrawColorFloat(renderer: *Renderer, r: f32, g: f32, b: f32, a: f32) bool { + return c.SDL_SetRenderDrawColorFloat(renderer, r, g, b, a); + } + + pub inline fn getRenderDrawColor(renderer: *Renderer, r: [*c]u8, g: [*c]u8, b: [*c]u8, a: [*c]u8) bool { + return c.SDL_GetRenderDrawColor(renderer, r, g, b, a); + } + + pub inline fn getRenderDrawColorFloat(renderer: *Renderer, r: *f32, g: *f32, b: *f32, a: *f32) bool { + return c.SDL_GetRenderDrawColorFloat(renderer, @ptrCast(r), @ptrCast(g), @ptrCast(b), @ptrCast(a)); + } + + pub inline fn setRenderColorScale(renderer: *Renderer, scale: f32) bool { + return c.SDL_SetRenderColorScale(renderer, scale); + } + + pub inline fn getRenderColorScale(renderer: *Renderer, scale: *f32) bool { + return c.SDL_GetRenderColorScale(renderer, @ptrCast(scale)); + } + + pub inline fn setRenderDrawBlendMode(renderer: *Renderer, blendMode: BlendMode) bool { + return c.SDL_SetRenderDrawBlendMode(renderer, @intFromEnum(blendMode)); + } + + pub inline fn getRenderDrawBlendMode(renderer: *Renderer, blendMode: ?*BlendMode) bool { + return c.SDL_GetRenderDrawBlendMode(renderer, @intFromEnum(blendMode)); + } + + pub inline fn renderClear(renderer: *Renderer) bool { + return c.SDL_RenderClear(renderer); + } + + pub inline fn renderPoint(renderer: *Renderer, x: f32, y: f32) bool { + return c.SDL_RenderPoint(renderer, x, y); + } + + pub inline fn renderPoints(renderer: *Renderer, points: *const FPoint, count: c_int) bool { + return c.SDL_RenderPoints(renderer, @ptrCast(points), count); + } + + pub inline fn renderLine(renderer: *Renderer, x1: f32, y1: f32, x2: f32, y2: f32) bool { + return c.SDL_RenderLine(renderer, x1, y1, x2, y2); + } + + pub inline fn renderLines(renderer: *Renderer, points: *const FPoint, count: c_int) bool { + return c.SDL_RenderLines(renderer, @ptrCast(points), count); + } + + pub inline fn renderRect(renderer: *Renderer, rect: *const FRect) bool { + return c.SDL_RenderRect(renderer, @ptrCast(rect)); + } + + pub inline fn renderRects(renderer: *Renderer, rects: *const FRect, count: c_int) bool { + return c.SDL_RenderRects(renderer, @ptrCast(rects), count); + } + + pub inline fn renderFillRect(renderer: *Renderer, rect: *const FRect) bool { + return c.SDL_RenderFillRect(renderer, @ptrCast(rect)); + } + + pub inline fn renderFillRects(renderer: *Renderer, rects: *const FRect, count: c_int) bool { + return c.SDL_RenderFillRects(renderer, @ptrCast(rects), count); + } + + pub inline fn renderTexture(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, dstrect: *const FRect) bool { + return c.SDL_RenderTexture(renderer, texture, @ptrCast(srcrect), @ptrCast(dstrect)); + } + + pub inline fn renderTextureRotated(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, dstrect: *const FRect, angle: f64, center: *const FPoint, flip: FlipMode) bool { + return c.SDL_RenderTextureRotated(renderer, texture, @ptrCast(srcrect), @ptrCast(dstrect), angle, @ptrCast(center), @intFromEnum(flip)); + } + + pub inline fn renderTextureAffine(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, origin: *const FPoint, right: *const FPoint, down: *const FPoint) bool { + return c.SDL_RenderTextureAffine(renderer, texture, @ptrCast(srcrect), @ptrCast(origin), @ptrCast(right), @ptrCast(down)); + } + + pub inline fn renderTextureTiled(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, scale: f32, dstrect: *const FRect) bool { + return c.SDL_RenderTextureTiled(renderer, texture, @ptrCast(srcrect), scale, @ptrCast(dstrect)); + } + + pub inline fn renderTexture9Grid(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, left_width: f32, right_width: f32, top_height: f32, bottom_height: f32, scale: f32, dstrect: *const FRect) bool { + return c.SDL_RenderTexture9Grid(renderer, texture, @ptrCast(srcrect), left_width, right_width, top_height, bottom_height, scale, @ptrCast(dstrect)); + } + + pub inline fn renderGeometry(renderer: *Renderer, texture: ?*Texture, vertices: *const Vertex, num_vertices: c_int, indices: [*c]const c_int, num_indices: c_int) bool { + return c.SDL_RenderGeometry(renderer, texture, @ptrCast(vertices), num_vertices, indices, num_indices); + } + + pub inline fn renderGeometryRaw(renderer: *Renderer, texture: ?*Texture, xy: *const f32, xy_stride: c_int, color: *const FColor, color_stride: c_int, uv: *const f32, uv_stride: c_int, num_vertices: c_int, indices: ?*const anyopaque, num_indices: c_int, size_indices: c_int) bool { + return c.SDL_RenderGeometryRaw(renderer, texture, @ptrCast(xy), xy_stride, @ptrCast(color), color_stride, @ptrCast(uv), uv_stride, num_vertices, indices, num_indices, size_indices); + } + + pub inline fn renderReadPixels(renderer: *Renderer, rect: *const Rect) ?*Surface { + return c.SDL_RenderReadPixels(renderer, @ptrCast(rect)); + } + + pub inline fn renderPresent(renderer: *Renderer) bool { + return c.SDL_RenderPresent(renderer); + } + + pub inline fn destroyRenderer(renderer: *Renderer) void { + return c.SDL_DestroyRenderer(renderer); + } + + pub inline fn flushRenderer(renderer: *Renderer) bool { + return c.SDL_FlushRenderer(renderer); + } + + pub inline fn getRenderMetalLayer(renderer: *Renderer) ?*anyopaque { + return c.SDL_GetRenderMetalLayer(renderer); + } + + pub inline fn getRenderMetalCommandEncoder(renderer: *Renderer) ?*anyopaque { + return c.SDL_GetRenderMetalCommandEncoder(renderer); + } + + pub inline fn addVulkanRenderSemaphores(renderer: *Renderer, wait_stage_mask: u32, wait_semaphore: i64, signal_semaphore: i64) bool { + return c.SDL_AddVulkanRenderSemaphores(renderer, wait_stage_mask, wait_semaphore, signal_semaphore); + } + + pub inline fn setRenderVSync(renderer: *Renderer, vsync: c_int) bool { + return c.SDL_SetRenderVSync(renderer, vsync); + } + + pub inline fn getRenderVSync(renderer: *Renderer, vsync: *c_int) bool { + return c.SDL_GetRenderVSync(renderer, @ptrCast(vsync)); + } + + pub inline fn renderDebugText(renderer: *Renderer, x: f32, y: f32, str: [*c]const u8) bool { + return c.SDL_RenderDebugText(renderer, x, y, str); + } + + pub inline fn renderDebugTextFormat(renderer: *Renderer, x: f32, y: f32, fmt: [*c]const u8, ...) bool { + return c.SDL_RenderDebugTextFormat( + renderer, + x, + y, + fmt, + ); + } +}; + +pub const Texture = opaque { + pub inline fn getTextureProperties(texture: *Texture) PropertiesID { + return c.SDL_GetTextureProperties(texture); + } + + pub inline fn getRendererFromTexture(texture: *Texture) ?*Renderer { + return c.SDL_GetRendererFromTexture(texture); + } + + pub inline fn getTextureSize(texture: *Texture, w: *f32, h: *f32) bool { + return c.SDL_GetTextureSize(texture, @ptrCast(w), @ptrCast(h)); + } + + pub inline fn setTextureColorMod(texture: *Texture, r: u8, g: u8, b: u8) bool { + return c.SDL_SetTextureColorMod(texture, r, g, b); + } + + pub inline fn setTextureColorModFloat(texture: *Texture, r: f32, g: f32, b: f32) bool { + return c.SDL_SetTextureColorModFloat(texture, r, g, b); + } + + pub inline fn getTextureColorMod(texture: *Texture, r: [*c]u8, g: [*c]u8, b: [*c]u8) bool { + return c.SDL_GetTextureColorMod(texture, r, g, b); + } + + pub inline fn getTextureColorModFloat(texture: *Texture, r: *f32, g: *f32, b: *f32) bool { + return c.SDL_GetTextureColorModFloat(texture, @ptrCast(r), @ptrCast(g), @ptrCast(b)); + } + + pub inline fn setTextureAlphaMod(texture: *Texture, alpha: u8) bool { + return c.SDL_SetTextureAlphaMod(texture, alpha); + } + + pub inline fn setTextureAlphaModFloat(texture: *Texture, alpha: f32) bool { + return c.SDL_SetTextureAlphaModFloat(texture, alpha); + } + + pub inline fn getTextureAlphaMod(texture: *Texture, alpha: [*c]u8) bool { + return c.SDL_GetTextureAlphaMod(texture, alpha); + } + + pub inline fn getTextureAlphaModFloat(texture: *Texture, alpha: *f32) bool { + return c.SDL_GetTextureAlphaModFloat(texture, @ptrCast(alpha)); + } + + pub inline fn setTextureBlendMode(texture: *Texture, blendMode: BlendMode) bool { + return c.SDL_SetTextureBlendMode(texture, @intFromEnum(blendMode)); + } + + pub inline fn getTextureBlendMode(texture: *Texture, blendMode: ?*BlendMode) bool { + return c.SDL_GetTextureBlendMode(texture, @intFromEnum(blendMode)); + } + + pub inline fn setTextureScaleMode(texture: *Texture, scaleMode: ScaleMode) bool { + return c.SDL_SetTextureScaleMode(texture, @intFromEnum(scaleMode)); + } + + pub inline fn getTextureScaleMode(texture: *Texture, scaleMode: ?*ScaleMode) bool { + return c.SDL_GetTextureScaleMode(texture, @intFromEnum(scaleMode)); + } + + pub inline fn updateTexture(texture: *Texture, rect: *const Rect, pixels: ?*const anyopaque, pitch: c_int) bool { + return c.SDL_UpdateTexture(texture, @ptrCast(rect), pixels, pitch); + } + + pub inline fn updateYUVTexture(texture: *Texture, rect: *const Rect, Yplane: [*c]const u8, Ypitch: c_int, Uplane: [*c]const u8, Upitch: c_int, Vplane: [*c]const u8, Vpitch: c_int) bool { + return c.SDL_UpdateYUVTexture(texture, @ptrCast(rect), Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); + } + + pub inline fn updateNVTexture(texture: *Texture, rect: *const Rect, Yplane: [*c]const u8, Ypitch: c_int, UVplane: [*c]const u8, UVpitch: c_int) bool { + return c.SDL_UpdateNVTexture(texture, @ptrCast(rect), Yplane, Ypitch, UVplane, UVpitch); + } + + pub inline fn lockTexture(texture: *Texture, rect: *const Rect, pixels: [*c]?*anyopaque, pitch: *c_int) bool { + return c.SDL_LockTexture(texture, @ptrCast(rect), pixels, @ptrCast(pitch)); + } + + pub inline fn lockTextureToSurface(texture: *Texture, rect: *const Rect, surface: [*c][*c]Surface) bool { + return c.SDL_LockTextureToSurface(texture, @ptrCast(rect), surface); + } + + pub inline fn unlockTexture(texture: *Texture) void { + return c.SDL_UnlockTexture(texture); + } + + pub inline fn destroyTexture(texture: *Texture) void { + return c.SDL_DestroyTexture(texture); + } +}; + +pub inline fn getNumRenderDrivers() c_int { + return c.SDL_GetNumRenderDrivers(); +} + +pub inline fn getRenderDriver(index: c_int) [*c]const u8 { + return c.SDL_GetRenderDriver(index); +} + +pub inline fn createWindowAndRenderer(title: [*c]const u8, width: c_int, height: c_int, window_flags: WindowFlags, window: [*c][*c]Window, renderer: [*c][*c]Renderer) bool { + return c.SDL_CreateWindowAndRenderer(title, width, height, @bitCast(window_flags), window, renderer); +} + +pub inline fn createRendererWithProperties(props: PropertiesID) ?*Renderer { + return c.SDL_CreateRendererWithProperties(props); +} diff --git a/v2/storage.zig b/v2/storage.zig new file mode 100644 index 0000000..37100c3 --- /dev/null +++ b/v2/storage.zig @@ -0,0 +1,114 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PathInfo = extern struct { + _type: PathType, // the path type + size: u64, // the file size in bytes + create_time: Time, // the time when the path was created + modify_time: Time, // the last time the path was modified + access_time: Time, // the last time the path was read +}; + +pub const PathType = enum(c_int) { + pathtypeNone, //path does not exist + pathtypeFile, //a normal file + pathtypeDirectory, //a directory + pathtypeOther, +}; + +pub const Time = i64; + +pub const GlobFlags = packed struct(u32) { + globCaseinsensitive: bool = false, + pad0: u30 = 0, + rsvd: bool = false, +}; + +pub const EnumerateDirectoryCallback = c.SDL_EnumerateDirectoryCallback; + +pub const PropertiesID = u32; + +pub const StorageInterface = extern struct { + version: u32, + close: ?*const anyopaque, + ready: ?*const anyopaque, + enumerate: ?*const anyopaque, + info: ?*const anyopaque, + read_file: ?*const anyopaque, + write_file: ?*const anyopaque, + mkdir: ?*const anyopaque, + remove: ?*const anyopaque, + rename: ?*const anyopaque, + copy: ?*const anyopaque, + space_remaining: ?*const anyopaque, +}; + +pub const Storage = opaque { + pub inline fn closeStorage(storage: *Storage) bool { + return c.SDL_CloseStorage(storage); + } + + pub inline fn storageReady(storage: *Storage) bool { + return c.SDL_StorageReady(storage); + } + + pub inline fn getStorageFileSize(storage: *Storage, path: [*c]const u8, length: *u64) bool { + return c.SDL_GetStorageFileSize(storage, path, @ptrCast(length)); + } + + pub inline fn readStorageFile(storage: *Storage, path: [*c]const u8, destination: ?*anyopaque, length: u64) bool { + return c.SDL_ReadStorageFile(storage, path, destination, length); + } + + pub inline fn writeStorageFile(storage: *Storage, path: [*c]const u8, source: ?*const anyopaque, length: u64) bool { + return c.SDL_WriteStorageFile(storage, path, source, length); + } + + pub inline fn createStorageDirectory(storage: *Storage, path: [*c]const u8) bool { + return c.SDL_CreateStorageDirectory(storage, path); + } + + pub inline fn enumerateStorageDirectory(storage: *Storage, path: [*c]const u8, callback: EnumerateDirectoryCallback, userdata: ?*anyopaque) bool { + return c.SDL_EnumerateStorageDirectory(storage, path, callback, userdata); + } + + pub inline fn removeStoragePath(storage: *Storage, path: [*c]const u8) bool { + return c.SDL_RemoveStoragePath(storage, path); + } + + pub inline fn renameStoragePath(storage: *Storage, oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return c.SDL_RenameStoragePath(storage, oldpath, newpath); + } + + pub inline fn copyStorageFile(storage: *Storage, oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return c.SDL_CopyStorageFile(storage, oldpath, newpath); + } + + pub inline fn getStoragePathInfo(storage: *Storage, path: [*c]const u8, info: ?*PathInfo) bool { + return c.SDL_GetStoragePathInfo(storage, path, info); + } + + pub inline fn getStorageSpaceRemaining(storage: *Storage) u64 { + return c.SDL_GetStorageSpaceRemaining(storage); + } + + pub inline fn globStorageDirectory(storage: *Storage, path: [*c]const u8, pattern: [*c]const u8, flags: GlobFlags, count: *c_int) [*c][*c]u8 { + return c.SDL_GlobStorageDirectory(storage, path, pattern, @bitCast(flags), @ptrCast(count)); + } +}; + +pub inline fn openTitleStorage(override: [*c]const u8, props: PropertiesID) ?*Storage { + return c.SDL_OpenTitleStorage(override, props); +} + +pub inline fn openUserStorage(org: [*c]const u8, app: [*c]const u8, props: PropertiesID) ?*Storage { + return c.SDL_OpenUserStorage(org, app, props); +} + +pub inline fn openFileStorage(path: [*c]const u8) ?*Storage { + return c.SDL_OpenFileStorage(path); +} + +pub inline fn openStorage(iface: *const StorageInterface, userdata: ?*anyopaque) ?*Storage { + return c.SDL_OpenStorage(@ptrCast(iface), userdata); +} diff --git a/v2/surface.zig b/v2/surface.zig new file mode 100644 index 0000000..5b170d5 --- /dev/null +++ b/v2/surface.zig @@ -0,0 +1,325 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes, //Android video texture format + pixelformatMjpg, //Motion JPEG +}; + +pub const BlendMode = u32; + +pub const IOStream = opaque { + pub inline fn loadBMP_IO(iostream: *IOStream, closeio: bool) ?*Surface { + return c.SDL_LoadBMP_IO(iostream, closeio); + } +}; + +pub const Rect = extern struct { + x: c_int, + y: c_int, + w: c_int, + h: c_int, +}; + +pub const Palette = extern struct { + ncolors: c_int, // number of elements in `colors`. + colors: ?*Color, // an array of colors, `ncolors` long. + version: u32, // internal use only, do not touch. + refcount: c_int, // internal use only, do not touch. +}; + +pub const Color = extern struct { + r: u8, + g: u8, + b: u8, + a: u8, +}; + +pub const Colorspace = enum(c_int) { + colorspaceSrgb, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 + colorRangeFull, + colorPrimariesBt709, + transferCharacteristicsSrgb, + matrixCoefficientsIdentity, + colorspaceSrgbLinear, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 + transferCharacteristicsLinear, + colorspaceHdr10, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 + colorPrimariesBt2020, + transferCharacteristicsPq, + colorspaceJpeg, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 + transferCharacteristicsBt601, + matrixCoefficientsBt601, + colorspaceBt601Limited, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorRangeLimited, + colorPrimariesBt601, + colorspaceBt601Full, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorspaceBt709Limited, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + transferCharacteristicsBt709, + matrixCoefficientsBt709, + colorspaceBt709Full, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + colorspaceBt2020Limited, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 + matrixCoefficientsBt2020Ncl, + colorspaceBt2020Full, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 + colorspaceRgbDefault, //The default colorspace for RGB surfaces if no colorspace is specified + colorspaceYuvDefault, //The default colorspace for YUV surfaces if no colorspace is specified +}; + +pub const PropertiesID = u32; + +pub const SurfaceFlags = packed struct(u32) { + surfacePreallocated: bool = false, // Surface uses preallocated pixel memory + surfaceLockNeeded: bool = false, // Surface needs to be locked to access pixels + surfaceLocked: bool = false, // Surface is currently locked + surfaceSimdAligned: bool = false, // Surface uses pixel memory allocated with SDL_aligned_alloc() + pad0: u27 = 0, + rsvd: bool = false, +}; + +pub const ScaleMode = enum(c_int) { + scalemodeNearest, //nearest pixel sampling + scalemodeLinear, //linear filtering +}; + +pub const FlipMode = enum(c_int) { + flipNone, //Do not flip + flipHorizontal, //flip horizontally + flipVertical, //flip vertically +}; + +pub const Surface = opaque { + pub inline fn destroySurface(surface: *Surface) void { + return c.SDL_DestroySurface(surface); + } + + pub inline fn getSurfaceProperties(surface: *Surface) PropertiesID { + return c.SDL_GetSurfaceProperties(surface); + } + + pub inline fn setSurfaceColorspace(surface: *Surface, colorspace: Colorspace) bool { + return c.SDL_SetSurfaceColorspace(surface, colorspace); + } + + pub inline fn getSurfaceColorspace(surface: *Surface) Colorspace { + return c.SDL_GetSurfaceColorspace(surface); + } + + pub inline fn createSurfacePalette(surface: *Surface) ?*Palette { + return c.SDL_CreateSurfacePalette(surface); + } + + pub inline fn setSurfacePalette(surface: *Surface, palette: ?*Palette) bool { + return c.SDL_SetSurfacePalette(surface, palette); + } + + pub inline fn getSurfacePalette(surface: *Surface) ?*Palette { + return c.SDL_GetSurfacePalette(surface); + } + + pub inline fn addSurfaceAlternateImage(surface: *Surface, image: ?*Surface) bool { + return c.SDL_AddSurfaceAlternateImage(surface, image); + } + + pub inline fn surfaceHasAlternateImages(surface: *Surface) bool { + return c.SDL_SurfaceHasAlternateImages(surface); + } + + pub inline fn getSurfaceImages(surface: *Surface, count: *c_int) [*c][*c]Surface { + return c.SDL_GetSurfaceImages(surface, @ptrCast(count)); + } + + pub inline fn removeSurfaceAlternateImages(surface: *Surface) void { + return c.SDL_RemoveSurfaceAlternateImages(surface); + } + + pub inline fn lockSurface(surface: *Surface) bool { + return c.SDL_LockSurface(surface); + } + + pub inline fn unlockSurface(surface: *Surface) void { + return c.SDL_UnlockSurface(surface); + } + + pub inline fn saveBMP_IO(surface: *Surface, dst: ?*IOStream, closeio: bool) bool { + return c.SDL_SaveBMP_IO(surface, dst, closeio); + } + + pub inline fn saveBMP(surface: *Surface, file: [*c]const u8) bool { + return c.SDL_SaveBMP(surface, file); + } + + pub inline fn setSurfaceRLE(surface: *Surface, enabled: bool) bool { + return c.SDL_SetSurfaceRLE(surface, enabled); + } + + pub inline fn surfaceHasRLE(surface: *Surface) bool { + return c.SDL_SurfaceHasRLE(surface); + } + + pub inline fn setSurfaceColorKey(surface: *Surface, enabled: bool, key: u32) bool { + return c.SDL_SetSurfaceColorKey(surface, enabled, key); + } + + pub inline fn surfaceHasColorKey(surface: *Surface) bool { + return c.SDL_SurfaceHasColorKey(surface); + } + + pub inline fn getSurfaceColorKey(surface: *Surface, key: *u32) bool { + return c.SDL_GetSurfaceColorKey(surface, @ptrCast(key)); + } + + pub inline fn setSurfaceColorMod(surface: *Surface, r: u8, g: u8, b: u8) bool { + return c.SDL_SetSurfaceColorMod(surface, r, g, b); + } + + pub inline fn getSurfaceColorMod(surface: *Surface, r: [*c]u8, g: [*c]u8, b: [*c]u8) bool { + return c.SDL_GetSurfaceColorMod(surface, r, g, b); + } + + pub inline fn setSurfaceAlphaMod(surface: *Surface, alpha: u8) bool { + return c.SDL_SetSurfaceAlphaMod(surface, alpha); + } + + pub inline fn getSurfaceAlphaMod(surface: *Surface, alpha: [*c]u8) bool { + return c.SDL_GetSurfaceAlphaMod(surface, alpha); + } + + pub inline fn setSurfaceBlendMode(surface: *Surface, blendMode: BlendMode) bool { + return c.SDL_SetSurfaceBlendMode(surface, @intFromEnum(blendMode)); + } + + pub inline fn getSurfaceBlendMode(surface: *Surface, blendMode: ?*BlendMode) bool { + return c.SDL_GetSurfaceBlendMode(surface, @intFromEnum(blendMode)); + } + + pub inline fn setSurfaceClipRect(surface: *Surface, rect: *const Rect) bool { + return c.SDL_SetSurfaceClipRect(surface, @ptrCast(rect)); + } + + pub inline fn getSurfaceClipRect(surface: *Surface, rect: ?*Rect) bool { + return c.SDL_GetSurfaceClipRect(surface, rect); + } + + pub inline fn flipSurface(surface: *Surface, flip: FlipMode) bool { + return c.SDL_FlipSurface(surface, @intFromEnum(flip)); + } + + pub inline fn duplicateSurface(surface: *Surface) ?*Surface { + return c.SDL_DuplicateSurface(surface); + } + + pub inline fn scaleSurface(surface: *Surface, width: c_int, height: c_int, scaleMode: ScaleMode) ?*Surface { + return c.SDL_ScaleSurface(surface, width, height, @intFromEnum(scaleMode)); + } + + pub inline fn convertSurface(surface: *Surface, format: PixelFormat) ?*Surface { + return c.SDL_ConvertSurface(surface, @bitCast(format)); + } + + pub inline fn convertSurfaceAndColorspace(surface: *Surface, format: PixelFormat, palette: ?*Palette, colorspace: Colorspace, props: PropertiesID) ?*Surface { + return c.SDL_ConvertSurfaceAndColorspace(surface, @bitCast(format), palette, colorspace, props); + } + + pub inline fn premultiplySurfaceAlpha(surface: *Surface, linear: bool) bool { + return c.SDL_PremultiplySurfaceAlpha(surface, linear); + } + + pub inline fn clearSurface(surface: *Surface, r: f32, g: f32, b: f32, a: f32) bool { + return c.SDL_ClearSurface(surface, r, g, b, a); + } + + pub inline fn fillSurfaceRect(surface: *Surface, rect: *const Rect, color: u32) bool { + return c.SDL_FillSurfaceRect(surface, @ptrCast(rect), color); + } + + pub inline fn fillSurfaceRects(surface: *Surface, rects: *const Rect, count: c_int, color: u32) bool { + return c.SDL_FillSurfaceRects(surface, @ptrCast(rects), count, color); + } + + pub inline fn blitSurface(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect) bool { + return c.SDL_BlitSurface(surface, @ptrCast(srcrect), dst, @ptrCast(dstrect)); + } + + pub inline fn blitSurfaceUnchecked(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect) bool { + return c.SDL_BlitSurfaceUnchecked(surface, @ptrCast(srcrect), dst, @ptrCast(dstrect)); + } + + pub inline fn blitSurfaceScaled(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect, scaleMode: ScaleMode) bool { + return c.SDL_BlitSurfaceScaled(surface, @ptrCast(srcrect), dst, @ptrCast(dstrect), @intFromEnum(scaleMode)); + } + + pub inline fn blitSurfaceUncheckedScaled(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect, scaleMode: ScaleMode) bool { + return c.SDL_BlitSurfaceUncheckedScaled(surface, @ptrCast(srcrect), dst, @ptrCast(dstrect), @intFromEnum(scaleMode)); + } + + pub inline fn stretchSurface(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect, scaleMode: ScaleMode) bool { + return c.SDL_StretchSurface(surface, @ptrCast(srcrect), dst, @ptrCast(dstrect), @intFromEnum(scaleMode)); + } + + pub inline fn blitSurfaceTiled(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect) bool { + return c.SDL_BlitSurfaceTiled(surface, @ptrCast(srcrect), dst, @ptrCast(dstrect)); + } + + pub inline fn blitSurfaceTiledWithScale(surface: *Surface, srcrect: *const Rect, scale: f32, scaleMode: ScaleMode, dst: ?*Surface, dstrect: *const Rect) bool { + return c.SDL_BlitSurfaceTiledWithScale(surface, @ptrCast(srcrect), scale, @intFromEnum(scaleMode), dst, @ptrCast(dstrect)); + } + + pub inline fn blitSurface9Grid(surface: *Surface, srcrect: *const Rect, left_width: c_int, right_width: c_int, top_height: c_int, bottom_height: c_int, scale: f32, scaleMode: ScaleMode, dst: ?*Surface, dstrect: *const Rect) bool { + return c.SDL_BlitSurface9Grid(surface, @ptrCast(srcrect), left_width, right_width, top_height, bottom_height, scale, @intFromEnum(scaleMode), dst, @ptrCast(dstrect)); + } + + pub inline fn mapSurfaceRGB(surface: *Surface, r: u8, g: u8, b: u8) u32 { + return c.SDL_MapSurfaceRGB(surface, r, g, b); + } + + pub inline fn mapSurfaceRGBA(surface: *Surface, r: u8, g: u8, b: u8, a: u8) u32 { + return c.SDL_MapSurfaceRGBA(surface, r, g, b, a); + } + + pub inline fn readSurfacePixel(surface: *Surface, x: c_int, y: c_int, r: [*c]u8, g: [*c]u8, b: [*c]u8, a: [*c]u8) bool { + return c.SDL_ReadSurfacePixel(surface, x, y, r, g, b, a); + } + + pub inline fn readSurfacePixelFloat(surface: *Surface, x: c_int, y: c_int, r: *f32, g: *f32, b: *f32, a: *f32) bool { + return c.SDL_ReadSurfacePixelFloat(surface, x, y, @ptrCast(r), @ptrCast(g), @ptrCast(b), @ptrCast(a)); + } + + pub inline fn writeSurfacePixel(surface: *Surface, x: c_int, y: c_int, r: u8, g: u8, b: u8, a: u8) bool { + return c.SDL_WriteSurfacePixel(surface, x, y, r, g, b, a); + } + + pub inline fn writeSurfacePixelFloat(surface: *Surface, x: c_int, y: c_int, r: f32, g: f32, b: f32, a: f32) bool { + return c.SDL_WriteSurfacePixelFloat(surface, x, y, r, g, b, a); + } +}; + +pub inline fn createSurface(width: c_int, height: c_int, format: PixelFormat) ?*Surface { + return c.SDL_CreateSurface(width, height, @bitCast(format)); +} + +pub inline fn createSurfaceFrom(width: c_int, height: c_int, format: PixelFormat, pixels: ?*anyopaque, pitch: c_int) ?*Surface { + return c.SDL_CreateSurfaceFrom(width, height, @bitCast(format), pixels, pitch); +} + +pub inline fn loadBMP(file: [*c]const u8) ?*Surface { + return c.SDL_LoadBMP(file); +} + +pub inline fn convertPixels(width: c_int, height: c_int, src_format: PixelFormat, src: ?*const anyopaque, src_pitch: c_int, dst_format: PixelFormat, dst: ?*anyopaque, dst_pitch: c_int) bool { + return c.SDL_ConvertPixels(width, height, @bitCast(src_format), src, src_pitch, @bitCast(dst_format), dst, dst_pitch); +} + +pub inline fn convertPixelsAndColorspace(width: c_int, height: c_int, src_format: PixelFormat, src_colorspace: Colorspace, src_properties: PropertiesID, src: ?*const anyopaque, src_pitch: c_int, dst_format: PixelFormat, dst_colorspace: Colorspace, dst_properties: PropertiesID, dst: ?*anyopaque, dst_pitch: c_int) bool { + return c.SDL_ConvertPixelsAndColorspace(width, height, @bitCast(src_format), src_colorspace, src_properties, src, src_pitch, @bitCast(dst_format), dst_colorspace, dst_properties, dst, dst_pitch); +} + +pub inline fn premultiplyAlpha(width: c_int, height: c_int, src_format: PixelFormat, src: ?*const anyopaque, src_pitch: c_int, dst_format: PixelFormat, dst: ?*anyopaque, dst_pitch: c_int, linear: bool) bool { + return c.SDL_PremultiplyAlpha(width, height, @bitCast(src_format), src, src_pitch, @bitCast(dst_format), dst, dst_pitch, linear); +} diff --git a/v2/video.zig b/v2/video.zig index 4445cb9..1a95885 100644 --- a/v2/video.zig +++ b/v2/video.zig @@ -30,7 +30,7 @@ pub const Rect = extern struct { h: c_int, }; -pub const FunctionPointer = ?*anyopaque; +pub const FunctionPointer = c.SDL_FunctionPointer; pub const DisplayID = u32;