commit d2f6fb404db6607949d1ddc0dfd78f5a2fc93a27 Author: peterino2 Date: Mon Jan 26 21:49:47 2026 -0800 sample with zig 3.4.0 castholm's repo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..707072c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +.zig-cache/ +zig-out diff --git a/README.md b/README.md new file mode 100644 index 0000000..ee6dafb --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# SDL3 Sample Project with Zig Bindings + +A sample SDL3 application using Zig-native bindings instead of C imports. + +## Features + +- SDL3 window initialization and management +- Zig-native API bindings vendored from sdl3bind +- Event loop with keyboard input handling +- Exits on pressing Escape key +- Basic rendering with color clear + +## Structure + +- `src/main.zig` - Main application using Zig SDL3 bindings +- `sdl3-zig/` - Vendored Zig bindings for SDL3 + - `sdl3.zig` - Main module that re-exports all SDL3 APIs + - `sdl3/` - Individual API modules (init, video, events, render, etc.) + - `sdl3/c.zig` - C import wrapper for SDL3 headers +- `build.zig` - Build configuration +- `build.zig.zon` - Package manifest + +## Dependencies + +- SDL3 (castholm's Zig port) - v0.4.0+3.4.0 +- SDL3 Zig bindings - official/release-3.4.0 + +## Building + +```bash +zig build +``` + +## Running + +```bash +zig build run +``` + +Press Escape to exit the application. + +## Notes + +- Uses Zig 0.15.2 API +- The Zig bindings provide type-safe, Zig-friendly wrappers around SDL3's C API +- Opaque pointer types require `@ptrCast` when crossing between binding and C types +- All SDL3 functions are accessed through the `sdl` import (e.g., `sdl.init_fn()`, `sdl.video.createWindow()`) diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..c5e8ca4 --- /dev/null +++ b/build.zig @@ -0,0 +1,48 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const sdl_dep = b.dependency("sdl", .{ + .target = target, + .optimize = optimize, + }); + const sdl_lib = sdl_dep.artifact("SDL3"); + + // Create the sdl3-zig module + const sdl3_module = b.createModule(.{ + .root_source_file = b.path("sdl3-zig/sdl3.zig"), + .target = target, + .optimize = optimize, + }); + + // Link SDL library to the module so C imports work + sdl3_module.linkLibrary(sdl_lib); + + const exe = b.addExecutable(.{ + .name = "sdl3-sample", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }), + }); + + // Add the sdl3 module to the executable + exe.root_module.addImport("sdl3", sdl3_module); + + exe.linkLibrary(sdl_lib); + + b.installArtifact(exe); + + const run_cmd = b.addRunArtifact(exe); + run_cmd.step.dependOn(b.getInstallStep()); + + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..761c76e --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,16 @@ +.{ + .name = .sdl3_sample, + .version = "0.1.0", + .fingerprint = 0xf00a4904d65478d1, + .minimum_zig_version = "0.15.2", + .dependencies = .{ + .sdl = .{ + .path = "../castholm-sdl", + }, + }, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + }, +} diff --git a/sdl3-zig/sdl3.zig b/sdl3-zig/sdl3.zig new file mode 100644 index 0000000..9d493b0 --- /dev/null +++ b/sdl3-zig/sdl3.zig @@ -0,0 +1,63 @@ +// SDL3 Zig bindings module +// Auto-generated Zig-friendly wrappers for SDL3 + +pub const audio = @import("sdl3/audio.zig"); +pub const blendmode = @import("sdl3/blendmode.zig"); +pub const camera = @import("sdl3/camera.zig"); +pub const clipboard = @import("sdl3/clipboard.zig"); +pub const dialog = @import("sdl3/dialog.zig"); +pub const endian = @import("sdl3/endian.zig"); +pub const error_ = @import("sdl3/error.zig"); +pub const events = @import("sdl3/events.zig"); +pub const filesystem = @import("sdl3/filesystem.zig"); +pub const gamepad = @import("sdl3/gamepad.zig"); +pub const gpu = @import("sdl3/gpu.zig"); +pub const haptic = @import("sdl3/haptic.zig"); +pub const hints = @import("sdl3/hints.zig"); +pub const init = @import("sdl3/init.zig"); +pub const joystick = @import("sdl3/joystick.zig"); +pub const keycode = @import("sdl3/keycode.zig"); +pub const loadso = @import("sdl3/loadso.zig"); +pub const messagebox = @import("sdl3/messagebox.zig"); +pub const misc = @import("sdl3/misc.zig"); +pub const mouse = @import("sdl3/mouse.zig"); +pub const pixels = @import("sdl3/pixels.zig"); +pub const properties = @import("sdl3/properties.zig"); +pub const rect = @import("sdl3/rect.zig"); +pub const render = @import("sdl3/render.zig"); +pub const sensor = @import("sdl3/sensor.zig"); +pub const storage = @import("sdl3/storage.zig"); +pub const surface = @import("sdl3/surface.zig"); +pub const system = @import("sdl3/system.zig"); +pub const time = @import("sdl3/time.zig"); +pub const timer = @import("sdl3/timer.zig"); +pub const touch = @import("sdl3/touch.zig"); +pub const version = @import("sdl3/version.zig"); +pub const video = @import("sdl3/video.zig"); + +// Re-export commonly used types and functions at top level for convenience +pub const InitFlags = init.InitFlags; +pub const init_fn = init.init; +pub const quit = init.quit; + +pub const Window = video.Window; +pub const WindowFlags = video.WindowFlags; +pub const createWindow = video.createWindow; +pub const destroyWindow = video.destroyWindow; + +pub const Renderer = render.Renderer; +pub const createRenderer = render.createRenderer; +pub const destroyRenderer = render.destroyRenderer; +pub const renderClear = render.renderClear; +pub const renderPresent = render.renderPresent; +pub const setRenderDrawColor = render.setRenderDrawColor; + +pub const Event = events.Event; +pub const pollEvent = events.pollEvent; +pub const EventType = events.EventType; + +pub const Keycode = keycode.Keycode; + +pub const delay = timer.delay; + +pub const getError = error_.getError; diff --git a/sdl3-zig/sdl3/audio.zig b/sdl3-zig/sdl3/audio.zig new file mode 100644 index 0000000..16f8acb --- /dev/null +++ b/sdl3-zig/sdl3/audio.zig @@ -0,0 +1,262 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const IOStream = opaque { + pub inline fn loadWAV_IO(iostream: *IOStream, closeio: bool, spec: ?*AudioSpec, audio_buf: [*c][*c]u8, audio_len: *u32) bool { + return @bitCast(c.SDL_LoadWAV_IO(@ptrCast(iostream), @bitCast(closeio), @ptrCast(spec), audio_buf, @ptrCast(audio_len))); + } +}; + +pub const PropertiesID = u32; + +pub const AudioFormat = enum(c_int) { + audioUnknown = 0x0000, //Unspecified audio format + audioU8 = 0x0008, //Unsigned 8-bit samples + audioS8 = 0x8008, //Signed 8-bit samples + audioS16le = 0x8010, //Signed 16-bit samples + audioS16be = 0x9010, //As above, but big-endian byte order + audioS32le = 0x8020, //32-bit integer samples + audioS32be = 0x9020, //As above, but big-endian byte order + audioF32le = 0x8120, //32-bit floating point samples + audioF32be = 0x9120, //As above, but big-endian byte order +}; + +pub const AudioDeviceID = u32; + +pub const AudioSpec = extern struct { + format: AudioFormat, // Audio data format + channels: c_int, // Number of channels: 1 mono, 2 stereo, etc + freq: c_int, // sample rate: sample frames per second +}; + +pub const AudioStream = opaque { + pub inline fn unbindAudioStream(audiostream: *AudioStream) void { + return c.SDL_UnbindAudioStream(@ptrCast(audiostream)); + } + + pub inline fn getAudioStreamDevice(audiostream: *AudioStream) AudioDeviceID { + return c.SDL_GetAudioStreamDevice(@ptrCast(audiostream)); + } + + pub inline fn getAudioStreamProperties(audiostream: *AudioStream) PropertiesID { + return c.SDL_GetAudioStreamProperties(@ptrCast(audiostream)); + } + + pub inline fn getAudioStreamFormat(audiostream: *AudioStream, src_spec: ?*AudioSpec, dst_spec: ?*AudioSpec) bool { + return @bitCast(c.SDL_GetAudioStreamFormat(@ptrCast(audiostream), @ptrCast(src_spec), @ptrCast(dst_spec))); + } + + pub inline fn setAudioStreamFormat(audiostream: *AudioStream, src_spec: *const AudioSpec, dst_spec: *const AudioSpec) bool { + return @bitCast(c.SDL_SetAudioStreamFormat(@ptrCast(audiostream), @ptrCast(src_spec), @ptrCast(dst_spec))); + } + + pub inline fn getAudioStreamFrequencyRatio(audiostream: *AudioStream) f32 { + return c.SDL_GetAudioStreamFrequencyRatio(@ptrCast(audiostream)); + } + + pub inline fn setAudioStreamFrequencyRatio(audiostream: *AudioStream, ratio: f32) bool { + return @bitCast(c.SDL_SetAudioStreamFrequencyRatio(@ptrCast(audiostream), ratio)); + } + + pub inline fn getAudioStreamGain(audiostream: *AudioStream) f32 { + return c.SDL_GetAudioStreamGain(@ptrCast(audiostream)); + } + + pub inline fn setAudioStreamGain(audiostream: *AudioStream, gain: f32) bool { + return @bitCast(c.SDL_SetAudioStreamGain(@ptrCast(audiostream), gain)); + } + + pub inline fn getAudioStreamInputChannelMap(audiostream: *AudioStream, count: *c_int) *c_int { + return @ptrCast(c.SDL_GetAudioStreamInputChannelMap(@ptrCast(audiostream), @ptrCast(count))); + } + + pub inline fn getAudioStreamOutputChannelMap(audiostream: *AudioStream, count: *c_int) *c_int { + return @ptrCast(c.SDL_GetAudioStreamOutputChannelMap(@ptrCast(audiostream), @ptrCast(count))); + } + + pub inline fn setAudioStreamInputChannelMap(audiostream: *AudioStream, chmap: [*c]const c_int, count: c_int) bool { + return @bitCast(c.SDL_SetAudioStreamInputChannelMap(@ptrCast(audiostream), chmap, count)); + } + + pub inline fn setAudioStreamOutputChannelMap(audiostream: *AudioStream, chmap: [*c]const c_int, count: c_int) bool { + return @bitCast(c.SDL_SetAudioStreamOutputChannelMap(@ptrCast(audiostream), chmap, count)); + } + + pub inline fn putAudioStreamData(audiostream: *AudioStream, buf: ?*const anyopaque, len: c_int) bool { + return @bitCast(c.SDL_PutAudioStreamData(@ptrCast(audiostream), buf, len)); + } + + pub inline fn putAudioStreamDataNoCopy(audiostream: *AudioStream, buf: ?*const anyopaque, len: c_int, callback: AudioStreamDataCompleteCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_PutAudioStreamDataNoCopy(@ptrCast(audiostream), buf, len, callback, userdata)); + } + + pub inline fn getAudioStreamData(audiostream: *AudioStream, buf: ?*anyopaque, len: c_int) c_int { + return c.SDL_GetAudioStreamData(@ptrCast(audiostream), buf, len); + } + + pub inline fn getAudioStreamAvailable(audiostream: *AudioStream) c_int { + return c.SDL_GetAudioStreamAvailable(@ptrCast(audiostream)); + } + + pub inline fn getAudioStreamQueued(audiostream: *AudioStream) c_int { + return c.SDL_GetAudioStreamQueued(@ptrCast(audiostream)); + } + + pub inline fn flushAudioStream(audiostream: *AudioStream) bool { + return @bitCast(c.SDL_FlushAudioStream(@ptrCast(audiostream))); + } + + pub inline fn clearAudioStream(audiostream: *AudioStream) bool { + return @bitCast(c.SDL_ClearAudioStream(@ptrCast(audiostream))); + } + + pub inline fn pauseAudioStreamDevice(audiostream: *AudioStream) bool { + return @bitCast(c.SDL_PauseAudioStreamDevice(@ptrCast(audiostream))); + } + + pub inline fn resumeAudioStreamDevice(audiostream: *AudioStream) bool { + return @bitCast(c.SDL_ResumeAudioStreamDevice(@ptrCast(audiostream))); + } + + pub inline fn audioStreamDevicePaused(audiostream: *AudioStream) bool { + return @bitCast(c.SDL_AudioStreamDevicePaused(@ptrCast(audiostream))); + } + + pub inline fn lockAudioStream(audiostream: *AudioStream) bool { + return @bitCast(c.SDL_LockAudioStream(@ptrCast(audiostream))); + } + + pub inline fn unlockAudioStream(audiostream: *AudioStream) bool { + return @bitCast(c.SDL_UnlockAudioStream(@ptrCast(audiostream))); + } + + pub inline fn setAudioStreamGetCallback(audiostream: *AudioStream, callback: AudioStreamCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_SetAudioStreamGetCallback(@ptrCast(audiostream), callback, userdata)); + } + + pub inline fn setAudioStreamPutCallback(audiostream: *AudioStream, callback: AudioStreamCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_SetAudioStreamPutCallback(@ptrCast(audiostream), callback, userdata)); + } + + pub inline fn destroyAudioStream(audiostream: *AudioStream) void { + return c.SDL_DestroyAudioStream(@ptrCast(audiostream)); + } +}; + +pub inline fn getNumAudioDrivers() c_int { + return c.SDL_GetNumAudioDrivers(); +} + +pub inline fn getAudioDriver(index: c_int) [*c]const u8 { + return c.SDL_GetAudioDriver(index); +} + +pub inline fn getCurrentAudioDriver() [*c]const u8 { + return c.SDL_GetCurrentAudioDriver(); +} + +pub inline fn getAudioPlaybackDevices(count: *c_int) ?*AudioDeviceID { + return @ptrCast(c.SDL_GetAudioPlaybackDevices(@ptrCast(count))); +} + +pub inline fn getAudioRecordingDevices(count: *c_int) ?*AudioDeviceID { + return @ptrCast(c.SDL_GetAudioRecordingDevices(@ptrCast(count))); +} + +pub inline fn getAudioDeviceName(devid: AudioDeviceID) [*c]const u8 { + return c.SDL_GetAudioDeviceName(devid); +} + +pub inline fn getAudioDeviceFormat(devid: AudioDeviceID, spec: ?*AudioSpec, sample_frames: *c_int) bool { + return @bitCast(c.SDL_GetAudioDeviceFormat(devid, @ptrCast(spec), @ptrCast(sample_frames))); +} + +pub inline fn getAudioDeviceChannelMap(devid: AudioDeviceID, count: *c_int) *c_int { + return @ptrCast(c.SDL_GetAudioDeviceChannelMap(devid, @ptrCast(count))); +} + +pub inline fn openAudioDevice(devid: AudioDeviceID, spec: *const AudioSpec) AudioDeviceID { + return c.SDL_OpenAudioDevice(devid, @ptrCast(spec)); +} + +pub inline fn isAudioDevicePhysical(devid: AudioDeviceID) bool { + return @bitCast(c.SDL_IsAudioDevicePhysical(devid)); +} + +pub inline fn isAudioDevicePlayback(devid: AudioDeviceID) bool { + return @bitCast(c.SDL_IsAudioDevicePlayback(devid)); +} + +pub inline fn pauseAudioDevice(devid: AudioDeviceID) bool { + return @bitCast(c.SDL_PauseAudioDevice(devid)); +} + +pub inline fn resumeAudioDevice(devid: AudioDeviceID) bool { + return @bitCast(c.SDL_ResumeAudioDevice(devid)); +} + +pub inline fn audioDevicePaused(devid: AudioDeviceID) bool { + return @bitCast(c.SDL_AudioDevicePaused(devid)); +} + +pub inline fn getAudioDeviceGain(devid: AudioDeviceID) f32 { + return c.SDL_GetAudioDeviceGain(devid); +} + +pub inline fn setAudioDeviceGain(devid: AudioDeviceID, gain: f32) bool { + return @bitCast(c.SDL_SetAudioDeviceGain(devid, gain)); +} + +pub inline fn closeAudioDevice(devid: AudioDeviceID) void { + return c.SDL_CloseAudioDevice(devid); +} + +pub inline fn bindAudioStreams(devid: AudioDeviceID, streams: [*c]*const AudioStream, num_streams: c_int) bool { + return @bitCast(c.SDL_BindAudioStreams(devid, streams, num_streams)); +} + +pub inline fn bindAudioStream(devid: AudioDeviceID, stream: ?*AudioStream) bool { + return @bitCast(c.SDL_BindAudioStream(devid, @ptrCast(stream))); +} + +pub inline fn unbindAudioStreams(streams: [*c]*const AudioStream, num_streams: c_int) void { + return c.SDL_UnbindAudioStreams(streams, num_streams); +} + +pub inline fn createAudioStream(src_spec: *const AudioSpec, dst_spec: *const AudioSpec) ?*AudioStream { + return @ptrCast(c.SDL_CreateAudioStream(@ptrCast(src_spec), @ptrCast(dst_spec))); +} + +pub const AudioStreamDataCompleteCallback = c.SDL_AudioStreamDataCompleteCallback; + +pub const AudioStreamCallback = c.SDL_AudioStreamCallback; + +pub inline fn openAudioDeviceStream(devid: AudioDeviceID, spec: *const AudioSpec, callback: AudioStreamCallback, userdata: ?*anyopaque) ?*AudioStream { + return @ptrCast(c.SDL_OpenAudioDeviceStream(devid, @ptrCast(spec), callback, userdata)); +} + +pub const AudioPostmixCallback = c.SDL_AudioPostmixCallback; + +pub inline fn setAudioPostmixCallback(devid: AudioDeviceID, callback: AudioPostmixCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_SetAudioPostmixCallback(devid, callback, userdata)); +} + +pub inline fn loadWAV(path: [*c]const u8, spec: ?*AudioSpec, audio_buf: [*c][*c]u8, audio_len: *u32) bool { + return @bitCast(c.SDL_LoadWAV(path, @ptrCast(spec), audio_buf, @ptrCast(audio_len))); +} + +pub inline fn mixAudio(dst: [*c]u8, src: [*c]const u8, format: AudioFormat, len: u32, volume: f32) bool { + return @bitCast(c.SDL_MixAudio(dst, src, @bitCast(format), len, volume)); +} + +pub inline fn convertAudioSamples(src_spec: *const AudioSpec, src_data: [*c]const u8, src_len: c_int, dst_spec: *const AudioSpec, dst_data: [*c][*c]u8, dst_len: *c_int) bool { + return @bitCast(c.SDL_ConvertAudioSamples(@ptrCast(src_spec), src_data, src_len, @ptrCast(dst_spec), dst_data, @ptrCast(dst_len))); +} + +pub inline fn getAudioFormatName(format: AudioFormat) [*c]const u8 { + return c.SDL_GetAudioFormatName(@bitCast(format)); +} + +pub inline fn getSilenceValueForFormat(format: AudioFormat) c_int { + return c.SDL_GetSilenceValueForFormat(@bitCast(format)); +} diff --git a/sdl3-zig/sdl3/blendmode.zig b/sdl3-zig/sdl3/blendmode.zig new file mode 100644 index 0000000..5428b63 --- /dev/null +++ b/sdl3-zig/sdl3/blendmode.zig @@ -0,0 +1,29 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const BlendMode = u32; + +pub const BlendOperation = enum(c_int) { + blendoperationAdd = 0x1, //dst + src: supported by all renderers + blendoperationSubtract = 0x2, //src - dst : supported by D3D, OpenGL, OpenGLES, and Vulkan + blendoperationRevSubtract = 0x3, //dst - src : supported by D3D, OpenGL, OpenGLES, and Vulkan + blendoperationMinimum = 0x4, //min(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan + blendoperationMaximum = 0x5, +}; + +pub const BlendFactor = enum(c_int) { + blendfactorZero = 0x1, //0, 0, 0, 0 + blendfactorOne = 0x2, //1, 1, 1, 1 + blendfactorSrcColor = 0x3, //srcR, srcG, srcB, srcA + blendfactorOneMinusSrcColor = 0x4, //1-srcR, 1-srcG, 1-srcB, 1-srcA + blendfactorSrcAlpha = 0x5, //srcA, srcA, srcA, srcA + blendfactorOneMinusSrcAlpha = 0x6, //1-srcA, 1-srcA, 1-srcA, 1-srcA + blendfactorDstColor = 0x7, //dstR, dstG, dstB, dstA + blendfactorOneMinusDstColor = 0x8, //1-dstR, 1-dstG, 1-dstB, 1-dstA + blendfactorDstAlpha = 0x9, //dstA, dstA, dstA, dstA + blendfactorOneMinusDstAlpha = 0xA, +}; + +pub inline fn composeCustomBlendMode(srcColorFactor: BlendFactor, dstColorFactor: BlendFactor, colorOperation: BlendOperation, srcAlphaFactor: BlendFactor, dstAlphaFactor: BlendFactor, alphaOperation: BlendOperation) BlendMode { + return @intFromEnum(c.SDL_ComposeCustomBlendMode(srcColorFactor, dstColorFactor, @intFromEnum(colorOperation), srcAlphaFactor, dstAlphaFactor, @intFromEnum(alphaOperation))); +} diff --git a/sdl3-zig/sdl3/c.zig b/sdl3-zig/sdl3/c.zig new file mode 100644 index 0000000..f8c5506 --- /dev/null +++ b/sdl3-zig/sdl3/c.zig @@ -0,0 +1,37 @@ +// SDL3 C bindings wrapper +pub const c = @cImport({ + @cInclude("SDL3/SDL.h"); + @cInclude("SDL3/SDL_audio.h"); + @cInclude("SDL3/SDL_blendmode.h"); + @cInclude("SDL3/SDL_camera.h"); + @cInclude("SDL3/SDL_clipboard.h"); + @cInclude("SDL3/SDL_dialog.h"); + @cInclude("SDL3/SDL_endian.h"); + @cInclude("SDL3/SDL_error.h"); + @cInclude("SDL3/SDL_events.h"); + @cInclude("SDL3/SDL_filesystem.h"); + @cInclude("SDL3/SDL_gamepad.h"); + @cInclude("SDL3/SDL_gpu.h"); + @cInclude("SDL3/SDL_haptic.h"); + @cInclude("SDL3/SDL_hints.h"); + @cInclude("SDL3/SDL_init.h"); + @cInclude("SDL3/SDL_joystick.h"); + @cInclude("SDL3/SDL_keycode.h"); + @cInclude("SDL3/SDL_loadso.h"); + @cInclude("SDL3/SDL_messagebox.h"); + @cInclude("SDL3/SDL_misc.h"); + @cInclude("SDL3/SDL_mouse.h"); + @cInclude("SDL3/SDL_pixels.h"); + @cInclude("SDL3/SDL_properties.h"); + @cInclude("SDL3/SDL_rect.h"); + @cInclude("SDL3/SDL_render.h"); + @cInclude("SDL3/SDL_sensor.h"); + @cInclude("SDL3/SDL_storage.h"); + @cInclude("SDL3/SDL_surface.h"); + @cInclude("SDL3/SDL_system.h"); + @cInclude("SDL3/SDL_time.h"); + @cInclude("SDL3/SDL_timer.h"); + @cInclude("SDL3/SDL_touch.h"); + @cInclude("SDL3/SDL_version.h"); + @cInclude("SDL3/SDL_video.h"); +}); diff --git a/sdl3-zig/sdl3/camera.zig b/sdl3-zig/sdl3/camera.zig new file mode 100644 index 0000000..e4ecf87 --- /dev/null +++ b/sdl3-zig/sdl3/camera.zig @@ -0,0 +1,133 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12 = 0x32315659, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv = 0x56555949, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2 = 0x32595559, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy = 0x59565955, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu = 0x55595659, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12 = 0x3231564e, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21 = 0x3132564e, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010 = 0x30313050, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes = 0x2053454f, //Android video texture format + pixelformatMjpg = 0x47504a4d, //Motion JPEG +}; + +pub const Surface = opaque {}; + +pub const Colorspace = enum(c_int) { + colorspaceSrgb = 0x120005a0, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 + colorRangeFull, + colorPrimariesBt709, + transferCharacteristicsSrgb, + matrixCoefficientsIdentity, + colorspaceSrgbLinear = 0x12000500, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 + transferCharacteristicsLinear, + colorspaceHdr10 = 0x12002600, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 + colorPrimariesBt2020, + transferCharacteristicsPq, + colorspaceJpeg = 0x220004c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 + transferCharacteristicsBt601, + matrixCoefficientsBt601, + colorspaceBt601Limited = 0x211018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorRangeLimited, + colorPrimariesBt601, + colorspaceBt601Full = 0x221018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorspaceBt709Limited = 0x21100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + transferCharacteristicsBt709, + matrixCoefficientsBt709, + colorspaceBt709Full = 0x22100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + colorspaceBt2020Limited = 0x21102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 + matrixCoefficientsBt2020Ncl, + colorspaceBt2020Full = 0x22102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 + + pub const colorspaceRgbDefault = .colorspaceSrgb; //The default colorspace for RGB surfaces if no colorspace is specified + pub const colorspaceYuvDefault = .colorspaceBt601Limited; //The default colorspace for YUV surfaces if no colorspace is specified +}; + +pub const PropertiesID = u32; + +pub const CameraID = u32; + +pub const Camera = opaque { + pub inline fn getCameraPermissionState(camera: *Camera) CameraPermissionState { + return c.SDL_GetCameraPermissionState(@ptrCast(camera)); + } + + pub inline fn getCameraID(camera: *Camera) CameraID { + return c.SDL_GetCameraID(@ptrCast(camera)); + } + + pub inline fn getCameraProperties(camera: *Camera) PropertiesID { + return c.SDL_GetCameraProperties(@ptrCast(camera)); + } + + pub inline fn getCameraFormat(camera: *Camera, spec: ?*CameraSpec) bool { + return @bitCast(c.SDL_GetCameraFormat(@ptrCast(camera), @ptrCast(spec))); + } + + pub inline fn acquireCameraFrame(camera: *Camera, timestampNS: *u64) ?*Surface { + return @ptrCast(c.SDL_AcquireCameraFrame(@ptrCast(camera), @ptrCast(timestampNS))); + } + + pub inline fn releaseCameraFrame(camera: *Camera, frame: ?*Surface) void { + return c.SDL_ReleaseCameraFrame(@ptrCast(camera), @ptrCast(frame)); + } + + pub inline fn closeCamera(camera: *Camera) void { + return c.SDL_CloseCamera(@ptrCast(camera)); + } +}; + +pub const CameraSpec = extern struct { + format: PixelFormat, // Frame format + colorspace: Colorspace, // Frame colorspace + width: c_int, // Frame width + height: c_int, // Frame height + framerate_numerator: c_int, // Frame rate numerator ((num / denom) == FPS, (denom / num) == duration in seconds) + framerate_denominator: c_int, // Frame rate denominator ((num / denom) == FPS, (denom / num) == duration in seconds) +}; + +pub const CameraPosition = enum(c_int) { + cameraPositionUnknown, + cameraPositionFrontFacing, + cameraPositionBackFacing, +}; + +pub const CameraPermissionState = enum(c_int) { + cameraPermissionStatePending, + cameraPermissionStateApproved, +}; + +pub inline fn getNumCameraDrivers() c_int { + return c.SDL_GetNumCameraDrivers(); +} + +pub inline fn getCameraDriver(index: c_int) [*c]const u8 { + return c.SDL_GetCameraDriver(index); +} + +pub inline fn getCurrentCameraDriver() [*c]const u8 { + return c.SDL_GetCurrentCameraDriver(); +} + +pub inline fn getCameras(count: *c_int) ?*CameraID { + return @ptrCast(c.SDL_GetCameras(@ptrCast(count))); +} + +pub inline fn getCameraSupportedFormats(instance_id: CameraID, count: *c_int) [*c][*c]CameraSpec { + return c.SDL_GetCameraSupportedFormats(instance_id, @ptrCast(count)); +} + +pub inline fn getCameraName(instance_id: CameraID) [*c]const u8 { + return c.SDL_GetCameraName(instance_id); +} + +pub inline fn getCameraPosition(instance_id: CameraID) CameraPosition { + return c.SDL_GetCameraPosition(instance_id); +} + +pub inline fn openCamera(instance_id: CameraID, spec: *const CameraSpec) ?*Camera { + return @ptrCast(c.SDL_OpenCamera(instance_id, @ptrCast(spec))); +} diff --git a/sdl3-zig/sdl3/clipboard.zig b/sdl3-zig/sdl3/clipboard.zig new file mode 100644 index 0000000..e8cb2cd --- /dev/null +++ b/sdl3-zig/sdl3/clipboard.zig @@ -0,0 +1,50 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn setClipboardText(text: [*c]const u8) bool { + return @bitCast(c.SDL_SetClipboardText(text)); +} + +pub inline fn getClipboardText() [*c]u8 { + return c.SDL_GetClipboardText(); +} + +pub inline fn hasClipboardText() bool { + return @bitCast(c.SDL_HasClipboardText()); +} + +pub inline fn setPrimarySelectionText(text: [*c]const u8) bool { + return @bitCast(c.SDL_SetPrimarySelectionText(text)); +} + +pub inline fn getPrimarySelectionText() [*c]u8 { + return c.SDL_GetPrimarySelectionText(); +} + +pub inline fn hasPrimarySelectionText() bool { + return @bitCast(c.SDL_HasPrimarySelectionText()); +} + +pub const ClipboardDataCallback = c.SDL_ClipboardDataCallback; + +pub const ClipboardCleanupCallback = c.SDL_ClipboardCleanupCallback; + +pub inline fn setClipboardData(callback: ClipboardDataCallback, cleanup: ClipboardCleanupCallback, userdata: ?*anyopaque, mime_types: [*c][*c]const u8, num_mime_types: usize) bool { + return @bitCast(c.SDL_SetClipboardData(callback, cleanup, userdata, mime_types, num_mime_types)); +} + +pub inline fn clearClipboardData() bool { + return @bitCast(c.SDL_ClearClipboardData()); +} + +pub inline fn getClipboardData(mime_type: [*c]const u8, size: *usize) ?*anyopaque { + return c.SDL_GetClipboardData(mime_type, @ptrCast(size)); +} + +pub inline fn hasClipboardData(mime_type: [*c]const u8) bool { + return @bitCast(c.SDL_HasClipboardData(mime_type)); +} + +pub inline fn getClipboardMimeTypes(num_mime_types: *usize) [*c][*c]u8 { + return c.SDL_GetClipboardMimeTypes(@ptrCast(num_mime_types)); +} diff --git a/sdl3-zig/sdl3/dialog.zig b/sdl3-zig/sdl3/dialog.zig new file mode 100644 index 0000000..3af9a6a --- /dev/null +++ b/sdl3-zig/sdl3/dialog.zig @@ -0,0 +1,35 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque {}; + +pub const PropertiesID = u32; + +pub const DialogFileFilter = extern struct { + name: [*c]const u8, + pattern: [*c]const u8, +}; + +pub const DialogFileCallback = c.SDL_DialogFileCallback; + +pub inline fn showOpenFileDialog(callback: DialogFileCallback, userdata: ?*anyopaque, window: ?*Window, filters: *const DialogFileFilter, nfilters: c_int, default_location: [*c]const u8, allow_many: bool) void { + return c.SDL_ShowOpenFileDialog(callback, userdata, @ptrCast(window), @ptrCast(filters), nfilters, default_location, @bitCast(allow_many)); +} + +pub inline fn showSaveFileDialog(callback: DialogFileCallback, userdata: ?*anyopaque, window: ?*Window, filters: *const DialogFileFilter, nfilters: c_int, default_location: [*c]const u8) void { + return c.SDL_ShowSaveFileDialog(callback, userdata, @ptrCast(window), @ptrCast(filters), nfilters, default_location); +} + +pub inline fn showOpenFolderDialog(callback: DialogFileCallback, userdata: ?*anyopaque, window: ?*Window, default_location: [*c]const u8, allow_many: bool) void { + return c.SDL_ShowOpenFolderDialog(callback, userdata, @ptrCast(window), default_location, @bitCast(allow_many)); +} + +pub const FileDialogType = enum(c_int) { + filedialogOpenfile, + filedialogSavefile, + filedialogOpenfolder, +}; + +pub inline fn showFileDialogWithProperties(_type: FileDialogType, callback: DialogFileCallback, userdata: ?*anyopaque, props: PropertiesID) void { + return c.SDL_ShowFileDialogWithProperties(@intFromEnum(_type), callback, userdata, props); +} diff --git a/sdl3-zig/sdl3/endian.zig b/sdl3-zig/sdl3/endian.zig new file mode 100644 index 0000000..c1f53b9 --- /dev/null +++ b/sdl3-zig/sdl3/endian.zig @@ -0,0 +1,2 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; diff --git a/sdl3-zig/sdl3/error.zig b/sdl3-zig/sdl3/error.zig new file mode 100644 index 0000000..5fce715 --- /dev/null +++ b/sdl3-zig/sdl3/error.zig @@ -0,0 +1,14 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn outOfMemory() bool { + return @bitCast(c.SDL_OutOfMemory()); +} + +pub inline fn getError() [*c]const u8 { + return c.SDL_GetError(); +} + +pub inline fn clearError() bool { + return @bitCast(c.SDL_ClearError()); +} diff --git a/sdl3-zig/sdl3/events.zig b/sdl3-zig/sdl3/events.zig new file mode 100644 index 0000000..a0a1574 --- /dev/null +++ b/sdl3-zig/sdl3/events.zig @@ -0,0 +1,794 @@ +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 + penInputInProximity: bool = false, // pen is in proximity (since SDL 3.4.0) + pad0: u23 = 0, + rsvd: bool = false, + + pub const None = PenInputFlags{}; +}; + +pub const MouseButtonFlags = packed struct(u32) { + buttonLeft: bool = false, + buttonMiddle: bool = false, + buttonX1: bool = false, + pad0: u28 = 0, + rsvd: bool = false, + + pub const None = MouseButtonFlags{}; +}; + +pub const Scancode = enum(c_int) { + scancodeBackslash = 49, + scancodeNonushash = 50, + scancodeGrave = 53, + scancodeInsert = 73, + scancodeNumlockclear = 83, + scancodeNonusbackslash = 100, + scancodeApplication = 101, //windows contextual menu, compose + scancodePower = 102, + scancodeHelp = 117, //AL Integrated Help Center + scancodeMenu = 118, //Menu (show menu) + scancodeStop = 120, //AC Stop + scancodeAgain = 121, //AC Redo/Repeat + scancodeUndo = 122, //AC Undo + scancodeCut = 123, //AC Cut + scancodeCopy = 124, //AC Copy + scancodePaste = 125, //AC Paste + scancodeFind = 126, //AC Find + scancodeInternational1 = 135, + scancodeInternational3 = 137, //Yen + scancodeLang1 = 144, //Hangul/English toggle + scancodeLang2 = 145, //Hanja conversion + scancodeLang3 = 146, //Katakana + scancodeLang4 = 147, //Hiragana + scancodeLang5 = 148, //Zenkaku/Hankaku + scancodeLang6 = 149, //reserved + scancodeLang7 = 150, //reserved + scancodeLang8 = 151, //reserved + scancodeLang9 = 152, //reserved + scancodeAlterase = 153, //Erase-Eaze + scancodeCancel = 155, //AC Cancel + scancodeLalt = 226, //alt, option + scancodeLgui = 227, //windows, command (apple), meta + scancodeRalt = 230, //alt gr, option + scancodeRgui = 231, //windows, command (apple), meta + scancodeMode = 257, + scancodeSleep = 258, //Sleep + scancodeWake = 259, //Wake + scancodeChannelIncrement = 260, //Channel Increment + scancodeChannelDecrement = 261, //Channel Decrement + scancodeMediaPlay = 262, //Play + scancodeMediaPause = 263, //Pause + scancodeMediaRecord = 264, //Record + scancodeMediaFastForward = 265, //Fast Forward + scancodeMediaRewind = 266, //Rewind + scancodeMediaNextTrack = 267, //Next Track + scancodeMediaPreviousTrack = 268, //Previous Track + scancodeMediaStop = 269, //Stop + scancodeMediaEject = 270, //Eject + scancodeMediaPlayPause = 271, //Play / Pause + scancodeMediaSelect = 272, + scancodeAcNew = 273, //AC New + scancodeAcOpen = 274, //AC Open + scancodeAcClose = 275, //AC Close + scancodeAcExit = 276, //AC Exit + scancodeAcSave = 277, //AC Save + scancodeAcPrint = 278, //AC Print + scancodeAcProperties = 279, //AC Properties + scancodeAcSearch = 280, //AC Search + scancodeAcHome = 281, //AC Home + scancodeAcBack = 282, //AC Back + scancodeAcForward = 283, //AC Forward + scancodeAcStop = 284, //AC Stop + scancodeAcRefresh = 285, //AC Refresh + scancodeAcBookmarks = 286, //AC Bookmarks + scancodeSoftleft = 287, + scancodeSoftright = 288, + scancodeCall = 289, //Used for accepting phone calls. + scancodeEndcall = 290, //Used for rejecting phone calls. + scancodeReserved = 400, //400-500 reserved for dynamic keycodes + scancodeCount = 512, +}; + +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 = -1, //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 = 0, //Unused (do not remove) + eventQuit = 0x100, //User-requested quit + eventTerminating, + eventLowMemory, + eventWillEnterBackground, + eventDidEnterBackground, + eventWillEnterForeground, + eventDidEnterForeground, + eventLocaleChanged, //The user's locale preferences have changed. + eventSystemThemeChanged, //The system theme changed + eventDisplayOrientation = 0x151, //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 + eventDisplayUsableBoundsChanged, //Display has changed usable bounds + eventWindowShown = 0x202, //Window has been shown + eventWindowHidden, //Window has been hidden + eventWindowExposed, + 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 = 0x300, //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 + eventScreenKeyboardShown, //The on-screen keyboard has been shown + eventScreenKeyboardHidden, //The on-screen keyboard has been hidden + eventMouseMotion = 0x400, //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 = 0x600, //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 = 0x650, //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, + eventPinchBegin = 0x710, //Pinch gesture started + eventPinchUpdate, //Pinch gesture updated + eventPinchEnd, //Pinch gesture ended + eventClipboardUpdate = 0x900, //The clipboard changed + eventDropFile = 0x1000, //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 = 0x1100, //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 = 0x1200, //A sensor was updated + eventPenProximityIn = 0x1300, //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 = 0x1400, //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 = 0x2000, //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 = 0x7F00, //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_EVENT_DISPLAY_* + 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 PinchFingerEvent = extern struct { + _type: EventType, // ::SDL_EVENT_PINCH_BEGIN or ::SDL_EVENT_PINCH_UPDATE or ::SDL_EVENT_PINCH_END + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + scale: f32, // The scale change since the last SDL_EVENT_PINCH_UPDATE. Scale < 1 is "zoom out". Scale > 1 is "zoom in". + 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, 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 + pinch: PinchFingerEvent, // Pinch 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(@ptrCast(events), numevents, action, minType, maxType); +} + +pub inline fn hasEvent(_type: u32) bool { + return @bitCast(c.SDL_HasEvent(_type)); +} + +pub inline fn hasEvents(minType: u32, maxType: u32) bool { + return @bitCast(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 @bitCast(c.SDL_PollEvent(@ptrCast(event))); +} + +pub inline fn waitEvent(event: ?*Event) bool { + return @bitCast(c.SDL_WaitEvent(@ptrCast(event))); +} + +pub inline fn waitEventTimeout(event: ?*Event, timeoutMS: i32) bool { + return @bitCast(c.SDL_WaitEventTimeout(@ptrCast(event), timeoutMS)); +} + +pub inline fn pushEvent(event: ?*Event) bool { + return @bitCast(c.SDL_PushEvent(@ptrCast(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 @bitCast(c.SDL_GetEventFilter(@ptrCast(filter), userdata)); +} + +pub inline fn addEventWatch(filter: EventFilter, userdata: ?*anyopaque) bool { + return @bitCast(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, @bitCast(enabled)); +} + +pub inline fn eventEnabled(_type: u32) bool { + return @bitCast(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 @ptrCast(c.SDL_GetWindowFromEvent(@ptrCast(event))); +} + +pub inline fn getEventDescription(event: *const Event, buf: [*c]u8, buflen: c_int) c_int { + return c.SDL_GetEventDescription(@ptrCast(event), buf, buflen); +} diff --git a/sdl3-zig/sdl3/filesystem.zig b/sdl3-zig/sdl3/filesystem.zig new file mode 100644 index 0000000..4b1a383 --- /dev/null +++ b/sdl3-zig/sdl3/filesystem.zig @@ -0,0 +1,94 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Time = i64; + +pub inline fn getBasePath() [*c]const u8 { + return c.SDL_GetBasePath(); +} + +pub inline fn getPrefPath(org: [*c]const u8, app: [*c]const u8) [*c]u8 { + return c.SDL_GetPrefPath(org, app); +} + +pub const Folder = enum(c_int) { + folderHome, //The folder which contains all of the current user's data, preferences, and documents. It usually contains most of the other folders. If a requested folder does not exist, the home folder can be considered a safe fallback to store a user's documents. + folderDesktop, //The folder of files that are displayed on the desktop. Note that the existence of a desktop folder does not guarantee that the system does show icons on its desktop; certain GNU/Linux distros with a graphical environment may not have desktop icons. + folderDocuments, //User document files, possibly application-specific. This is a good place to save a user's projects. + folderDownloads, //Standard folder for user files downloaded from the internet. + folderMusic, //Music files that can be played using a standard music player (mp3, ogg...). + folderPictures, //Image files that can be displayed using a standard viewer (png, jpg...). + folderPublicshare, //Files that are meant to be shared with other users on the same computer. + folderSavedgames, //Save files for games. + folderScreenshots, //Application screenshots. + folderTemplates, //Template files to be used when the user requests the desktop environment to create a new file in a certain folder, such as "New Text File.txt". Any file in the Templates folder can be used as a starting point for a new file. + folderVideos, //Video files that can be played using a standard video player (mp4, webm...). + folderCount, +}; + +pub inline fn getUserFolder(folder: Folder) [*c]const u8 { + return c.SDL_GetUserFolder(folder); +} + +pub const PathType = enum(c_int) { + pathtypeNone, //path does not exist + pathtypeFile, //a normal file + pathtypeDirectory, //a directory + pathtypeOther, +}; + +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 GlobFlags = packed struct(u32) { + globCaseinsensitive: bool = false, + pad0: u30 = 0, + rsvd: bool = false, + + pub const None = GlobFlags{}; +}; + +pub inline fn createDirectory(path: [*c]const u8) bool { + return @bitCast(c.SDL_CreateDirectory(path)); +} + +pub const EnumerationResult = enum(c_int) { + enumContinue, //Value that requests that enumeration continue. + enumSuccess, //Value that requests that enumeration stop, successfully. + enumFailure, +}; + +pub const EnumerateDirectoryCallback = c.SDL_EnumerateDirectoryCallback; + +pub inline fn enumerateDirectory(path: [*c]const u8, callback: EnumerateDirectoryCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_EnumerateDirectory(path, callback, userdata)); +} + +pub inline fn removePath(path: [*c]const u8) bool { + return @bitCast(c.SDL_RemovePath(path)); +} + +pub inline fn renamePath(oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return @bitCast(c.SDL_RenamePath(oldpath, newpath)); +} + +pub inline fn copyFile(oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return @bitCast(c.SDL_CopyFile(oldpath, newpath)); +} + +pub inline fn getPathInfo(path: [*c]const u8, info: ?*PathInfo) bool { + return @bitCast(c.SDL_GetPathInfo(path, @ptrCast(info))); +} + +pub inline fn globDirectory(path: [*c]const u8, pattern: [*c]const u8, flags: GlobFlags, count: *c_int) [*c][*c]u8 { + return c.SDL_GlobDirectory(path, pattern, @bitCast(flags), @ptrCast(count)); +} + +pub inline fn getCurrentDirectory() [*c]u8 { + return c.SDL_GetCurrentDirectory(); +} diff --git a/sdl3-zig/sdl3/gamepad.zig b/sdl3-zig/sdl3/gamepad.zig new file mode 100644 index 0000000..17aebe1 --- /dev/null +++ b/sdl3-zig/sdl3/gamepad.zig @@ -0,0 +1,410 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const JoystickConnectionState = enum(c_int) { + joystickConnectionUnknown, + joystickConnectionWired, + joystickConnectionWireless, +}; + +pub const GUID = extern struct { + data: [16]u8, +}; + +pub const PropertiesID = u32; + +pub const IOStream = opaque { + pub inline fn addGamepadMappingsFromIO(iostream: *IOStream, closeio: bool) c_int { + return c.SDL_AddGamepadMappingsFromIO(@ptrCast(iostream), @bitCast(closeio)); + } +}; + +pub const JoystickID = u32; + +pub const SensorType = enum(c_int) { + sensorInvalid = -1, //Returned for an invalid sensor + sensorUnknown, //Unknown sensor type + sensorAccel, //Accelerometer + sensorGyro, //Gyroscope + sensorAccelL, //Accelerometer for left Joy-Con controller and Wii nunchuk + sensorGyroL, //Gyroscope for left Joy-Con controller + sensorAccelR, //Accelerometer for right Joy-Con controller + sensorGyroR, //Gyroscope for right Joy-Con controller + sensorCount, +}; + +pub const PowerState = enum(c_int) { + powerstateError = -1, //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 Joystick = opaque {}; + +pub const Gamepad = opaque { + pub inline fn getGamepadMapping(gamepad: *Gamepad) [*c]u8 { + return c.SDL_GetGamepadMapping(@ptrCast(gamepad)); + } + + pub inline fn getGamepadProperties(gamepad: *Gamepad) PropertiesID { + return c.SDL_GetGamepadProperties(@ptrCast(gamepad)); + } + + pub inline fn getGamepadID(gamepad: *Gamepad) JoystickID { + return c.SDL_GetGamepadID(@ptrCast(gamepad)); + } + + pub inline fn getGamepadName(gamepad: *Gamepad) [*c]const u8 { + return c.SDL_GetGamepadName(@ptrCast(gamepad)); + } + + pub inline fn getGamepadPath(gamepad: *Gamepad) [*c]const u8 { + return c.SDL_GetGamepadPath(@ptrCast(gamepad)); + } + + pub inline fn getGamepadType(gamepad: *Gamepad) GamepadType { + return @intFromEnum(c.SDL_GetGamepadType(@ptrCast(gamepad))); + } + + pub inline fn getRealGamepadType(gamepad: *Gamepad) GamepadType { + return @intFromEnum(c.SDL_GetRealGamepadType(@ptrCast(gamepad))); + } + + pub inline fn getGamepadPlayerIndex(gamepad: *Gamepad) c_int { + return c.SDL_GetGamepadPlayerIndex(@ptrCast(gamepad)); + } + + pub inline fn setGamepadPlayerIndex(gamepad: *Gamepad, player_index: c_int) bool { + return @bitCast(c.SDL_SetGamepadPlayerIndex(@ptrCast(gamepad), player_index)); + } + + pub inline fn getGamepadVendor(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadVendor(@ptrCast(gamepad)); + } + + pub inline fn getGamepadProduct(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadProduct(@ptrCast(gamepad)); + } + + pub inline fn getGamepadProductVersion(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadProductVersion(@ptrCast(gamepad)); + } + + pub inline fn getGamepadFirmwareVersion(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadFirmwareVersion(@ptrCast(gamepad)); + } + + pub inline fn getGamepadSerial(gamepad: *Gamepad) [*c]const u8 { + return c.SDL_GetGamepadSerial(@ptrCast(gamepad)); + } + + pub inline fn getGamepadSteamHandle(gamepad: *Gamepad) u64 { + return c.SDL_GetGamepadSteamHandle(@ptrCast(gamepad)); + } + + pub inline fn getGamepadConnectionState(gamepad: *Gamepad) JoystickConnectionState { + return c.SDL_GetGamepadConnectionState(@ptrCast(gamepad)); + } + + pub inline fn getGamepadPowerInfo(gamepad: *Gamepad, percent: *c_int) PowerState { + return c.SDL_GetGamepadPowerInfo(@ptrCast(gamepad), @ptrCast(percent)); + } + + pub inline fn gamepadConnected(gamepad: *Gamepad) bool { + return @bitCast(c.SDL_GamepadConnected(@ptrCast(gamepad))); + } + + pub inline fn getGamepadJoystick(gamepad: *Gamepad) ?*Joystick { + return @ptrCast(c.SDL_GetGamepadJoystick(@ptrCast(gamepad))); + } + + pub inline fn getGamepadBindings(gamepad: *Gamepad, count: *c_int) [*c][*c]GamepadBinding { + return c.SDL_GetGamepadBindings(@ptrCast(gamepad), @ptrCast(count)); + } + + pub inline fn gamepadHasAxis(gamepad: *Gamepad, axis: GamepadAxis) bool { + return @bitCast(c.SDL_GamepadHasAxis(@ptrCast(gamepad), axis)); + } + + pub inline fn getGamepadAxis(gamepad: *Gamepad, axis: GamepadAxis) i16 { + return c.SDL_GetGamepadAxis(@ptrCast(gamepad), axis); + } + + pub inline fn gamepadHasButton(gamepad: *Gamepad, button: GamepadButton) bool { + return @bitCast(c.SDL_GamepadHasButton(@ptrCast(gamepad), button)); + } + + pub inline fn getGamepadButton(gamepad: *Gamepad, button: GamepadButton) bool { + return @bitCast(c.SDL_GetGamepadButton(@ptrCast(gamepad), button)); + } + + pub inline fn getGamepadButtonLabel(gamepad: *Gamepad, button: GamepadButton) GamepadButtonLabel { + return c.SDL_GetGamepadButtonLabel(@ptrCast(gamepad), button); + } + + pub inline fn getNumGamepadTouchpads(gamepad: *Gamepad) c_int { + return c.SDL_GetNumGamepadTouchpads(@ptrCast(gamepad)); + } + + pub inline fn getNumGamepadTouchpadFingers(gamepad: *Gamepad, touchpad: c_int) c_int { + return c.SDL_GetNumGamepadTouchpadFingers(@ptrCast(gamepad), touchpad); + } + + pub inline fn getGamepadTouchpadFinger(gamepad: *Gamepad, touchpad: c_int, finger: c_int, down: *bool, x: *f32, y: *f32, pressure: *f32) bool { + return @bitCast(c.SDL_GetGamepadTouchpadFinger(@ptrCast(gamepad), touchpad, finger, @ptrCast(down), @ptrCast(x), @ptrCast(y), @ptrCast(pressure))); + } + + pub inline fn gamepadHasSensor(gamepad: *Gamepad, _type: SensorType) bool { + return @bitCast(c.SDL_GamepadHasSensor(@ptrCast(gamepad), @intFromEnum(_type))); + } + + pub inline fn setGamepadSensorEnabled(gamepad: *Gamepad, _type: SensorType, enabled: bool) bool { + return @bitCast(c.SDL_SetGamepadSensorEnabled(@ptrCast(gamepad), @intFromEnum(_type), @bitCast(enabled))); + } + + pub inline fn gamepadSensorEnabled(gamepad: *Gamepad, _type: SensorType) bool { + return @bitCast(c.SDL_GamepadSensorEnabled(@ptrCast(gamepad), @intFromEnum(_type))); + } + + pub inline fn getGamepadSensorDataRate(gamepad: *Gamepad, _type: SensorType) f32 { + return c.SDL_GetGamepadSensorDataRate(@ptrCast(gamepad), @intFromEnum(_type)); + } + + pub inline fn getGamepadSensorData(gamepad: *Gamepad, _type: SensorType, data: *f32, num_values: c_int) bool { + return @bitCast(c.SDL_GetGamepadSensorData(@ptrCast(gamepad), @intFromEnum(_type), @ptrCast(data), num_values)); + } + + pub inline fn rumbleGamepad(gamepad: *Gamepad, low_frequency_rumble: u16, high_frequency_rumble: u16, duration_ms: u32) bool { + return @bitCast(c.SDL_RumbleGamepad(@ptrCast(gamepad), low_frequency_rumble, high_frequency_rumble, duration_ms)); + } + + pub inline fn rumbleGamepadTriggers(gamepad: *Gamepad, left_rumble: u16, right_rumble: u16, duration_ms: u32) bool { + return @bitCast(c.SDL_RumbleGamepadTriggers(@ptrCast(gamepad), left_rumble, right_rumble, duration_ms)); + } + + pub inline fn setGamepadLED(gamepad: *Gamepad, red: u8, green: u8, blue: u8) bool { + return @bitCast(c.SDL_SetGamepadLED(@ptrCast(gamepad), red, green, blue)); + } + + pub inline fn sendGamepadEffect(gamepad: *Gamepad, data: ?*const anyopaque, size: c_int) bool { + return @bitCast(c.SDL_SendGamepadEffect(@ptrCast(gamepad), data, size)); + } + + pub inline fn closeGamepad(gamepad: *Gamepad) void { + return c.SDL_CloseGamepad(@ptrCast(gamepad)); + } + + pub inline fn getGamepadAppleSFSymbolsNameForButton(gamepad: *Gamepad, button: GamepadButton) [*c]const u8 { + return c.SDL_GetGamepadAppleSFSymbolsNameForButton(@ptrCast(gamepad), button); + } + + pub inline fn getGamepadAppleSFSymbolsNameForAxis(gamepad: *Gamepad, axis: GamepadAxis) [*c]const u8 { + return c.SDL_GetGamepadAppleSFSymbolsNameForAxis(@ptrCast(gamepad), axis); + } +}; + +pub const GamepadType = enum(c_int) { + gamepadTypeStandard, + gamepadTypeXbox360, + gamepadTypeXboxone, + gamepadTypePs3, + gamepadTypePs4, + gamepadTypePs5, + gamepadTypeNintendoSwitchPro, + gamepadTypeNintendoSwitchJoyconLeft, + gamepadTypeNintendoSwitchJoyconRight, + gamepadTypeNintendoSwitchJoyconPair, + gamepadTypeGamecube, + gamepadTypeCount, +}; + +pub const GamepadButton = enum(c_int) { + gamepadButtonSouth, //Bottom face button (e.g. Xbox A button) + gamepadButtonEast, //Right face button (e.g. Xbox B button) + gamepadButtonWest, //Left face button (e.g. Xbox X button) + gamepadButtonNorth, //Top face button (e.g. Xbox Y button) + gamepadButtonBack, + gamepadButtonGuide, + gamepadButtonStart, + gamepadButtonLeftStick, + gamepadButtonRightStick, + gamepadButtonLeftShoulder, + gamepadButtonRightShoulder, + gamepadButtonDpadUp, + gamepadButtonDpadDown, + gamepadButtonDpadLeft, + gamepadButtonDpadRight, + gamepadButtonMisc1, //Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) + gamepadButtonRightPaddle1, //Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1, DualSense Edge RB button, Right Joy-Con SR button) + gamepadButtonLeftPaddle1, //Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3, DualSense Edge LB button, Left Joy-Con SL button) + gamepadButtonRightPaddle2, //Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2, DualSense Edge right Fn button, Right Joy-Con SL button) + gamepadButtonLeftPaddle2, //Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4, DualSense Edge left Fn button, Left Joy-Con SR button) + gamepadButtonTouchpad, //PS4/PS5 touchpad button + gamepadButtonMisc2, //Additional button + gamepadButtonMisc3, //Additional button (e.g. Nintendo GameCube left trigger click) + gamepadButtonMisc4, //Additional button (e.g. Nintendo GameCube right trigger click) + gamepadButtonMisc5, //Additional button + gamepadButtonMisc6, //Additional button + gamepadButtonCount, +}; + +pub const GamepadButtonLabel = enum(c_int) { + gamepadButtonLabelUnknown, + gamepadButtonLabelA, + gamepadButtonLabelB, + gamepadButtonLabelX, + gamepadButtonLabelY, + gamepadButtonLabelCross, + gamepadButtonLabelCircle, + gamepadButtonLabelSquare, + gamepadButtonLabelTriangle, +}; + +pub const GamepadAxis = enum(c_int) { + gamepadAxisLeftx, + gamepadAxisLefty, + gamepadAxisRightx, + gamepadAxisRighty, + gamepadAxisLeftTrigger, + gamepadAxisRightTrigger, + gamepadAxisCount, +}; + +pub const GamepadBindingType = enum(c_int) { + gamepadBindtypeButton, + gamepadBindtypeAxis, + gamepadBindtypeHat, +}; + +pub const GamepadBinding = opaque {}; + +pub inline fn addGamepadMapping(mapping: [*c]const u8) c_int { + return c.SDL_AddGamepadMapping(mapping); +} + +pub inline fn addGamepadMappingsFromFile(file: [*c]const u8) c_int { + return c.SDL_AddGamepadMappingsFromFile(file); +} + +pub inline fn reloadGamepadMappings() bool { + return @bitCast(c.SDL_ReloadGamepadMappings()); +} + +pub inline fn getGamepadMappings(count: *c_int) [*c][*c]u8 { + return c.SDL_GetGamepadMappings(@ptrCast(count)); +} + +pub inline fn getGamepadMappingForGUID(guid: GUID) [*c]u8 { + return c.SDL_GetGamepadMappingForGUID(guid); +} + +pub inline fn setGamepadMapping(instance_id: JoystickID, mapping: [*c]const u8) bool { + return @bitCast(c.SDL_SetGamepadMapping(instance_id, mapping)); +} + +pub inline fn hasGamepad() bool { + return @bitCast(c.SDL_HasGamepad()); +} + +pub inline fn getGamepads(count: *c_int) ?*JoystickID { + return @ptrCast(c.SDL_GetGamepads(@ptrCast(count))); +} + +pub inline fn isGamepad(instance_id: JoystickID) bool { + return @bitCast(c.SDL_IsGamepad(instance_id)); +} + +pub inline fn getGamepadNameForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetGamepadNameForID(instance_id); +} + +pub inline fn getGamepadPathForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetGamepadPathForID(instance_id); +} + +pub inline fn getGamepadPlayerIndexForID(instance_id: JoystickID) c_int { + return c.SDL_GetGamepadPlayerIndexForID(instance_id); +} + +pub inline fn getGamepadGUIDForID(instance_id: JoystickID) GUID { + return c.SDL_GetGamepadGUIDForID(instance_id); +} + +pub inline fn getGamepadVendorForID(instance_id: JoystickID) u16 { + return c.SDL_GetGamepadVendorForID(instance_id); +} + +pub inline fn getGamepadProductForID(instance_id: JoystickID) u16 { + return c.SDL_GetGamepadProductForID(instance_id); +} + +pub inline fn getGamepadProductVersionForID(instance_id: JoystickID) u16 { + return c.SDL_GetGamepadProductVersionForID(instance_id); +} + +pub inline fn getGamepadTypeForID(instance_id: JoystickID) GamepadType { + return @intFromEnum(c.SDL_GetGamepadTypeForID(instance_id)); +} + +pub inline fn getRealGamepadTypeForID(instance_id: JoystickID) GamepadType { + return @intFromEnum(c.SDL_GetRealGamepadTypeForID(instance_id)); +} + +pub inline fn getGamepadMappingForID(instance_id: JoystickID) [*c]u8 { + return c.SDL_GetGamepadMappingForID(instance_id); +} + +pub inline fn openGamepad(instance_id: JoystickID) ?*Gamepad { + return @ptrCast(c.SDL_OpenGamepad(instance_id)); +} + +pub inline fn getGamepadFromID(instance_id: JoystickID) ?*Gamepad { + return @ptrCast(c.SDL_GetGamepadFromID(instance_id)); +} + +pub inline fn getGamepadFromPlayerIndex(player_index: c_int) ?*Gamepad { + return @ptrCast(c.SDL_GetGamepadFromPlayerIndex(player_index)); +} + +pub inline fn setGamepadEventsEnabled(enabled: bool) void { + return c.SDL_SetGamepadEventsEnabled(@bitCast(enabled)); +} + +pub inline fn gamepadEventsEnabled() bool { + return @bitCast(c.SDL_GamepadEventsEnabled()); +} + +pub inline fn updateGamepads() void { + return c.SDL_UpdateGamepads(); +} + +pub inline fn getGamepadTypeFromString(str: [*c]const u8) GamepadType { + return @intFromEnum(c.SDL_GetGamepadTypeFromString(str)); +} + +pub inline fn getGamepadStringForType(_type: GamepadType) [*c]const u8 { + return c.SDL_GetGamepadStringForType(@intFromEnum(_type)); +} + +pub inline fn getGamepadAxisFromString(str: [*c]const u8) GamepadAxis { + return c.SDL_GetGamepadAxisFromString(str); +} + +pub inline fn getGamepadStringForAxis(axis: GamepadAxis) [*c]const u8 { + return c.SDL_GetGamepadStringForAxis(axis); +} + +pub inline fn getGamepadButtonFromString(str: [*c]const u8) GamepadButton { + return c.SDL_GetGamepadButtonFromString(str); +} + +pub inline fn getGamepadStringForButton(button: GamepadButton) [*c]const u8 { + return c.SDL_GetGamepadStringForButton(button); +} + +pub inline fn getGamepadButtonLabelForType(_type: GamepadType, button: GamepadButton) GamepadButtonLabel { + return c.SDL_GetGamepadButtonLabelForType(@intFromEnum(_type), button); +} diff --git a/sdl3-zig/sdl3/gpu.zig b/sdl3-zig/sdl3/gpu.zig new file mode 100644 index 0000000..bfc2583 --- /dev/null +++ b/sdl3-zig/sdl3/gpu.zig @@ -0,0 +1,1140 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const FColor = extern struct { + r: f32, + g: f32, + b: f32, + a: f32, +}; + +pub const PropertiesID = u32; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12 = 0x32315659, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv = 0x56555949, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2 = 0x32595559, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy = 0x59565955, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu = 0x55595659, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12 = 0x3231564e, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21 = 0x3132564e, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010 = 0x30313050, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes = 0x2053454f, //Android video texture format + pixelformatMjpg = 0x47504a4d, //Motion JPEG +}; + +pub const Rect = extern struct { + x: c_int, + y: c_int, + w: c_int, + h: c_int, +}; + +pub const Window = opaque {}; + +pub const FlipMode = packed struct(u32) { + flipHorizontal: bool = false, // flip horizontally + flipVertical: bool = false, // flip vertically + pad0: u29 = 0, + rsvd: bool = false, + + pub const None = FlipMode{}; +}; + +pub const GPUDevice = opaque { + pub inline fn destroyGPUDevice(gpudevice: *GPUDevice) void { + return c.SDL_DestroyGPUDevice(@ptrCast(gpudevice)); + } + + pub inline fn getGPUDeviceDriver(gpudevice: *GPUDevice) [*c]const u8 { + return c.SDL_GetGPUDeviceDriver(@ptrCast(gpudevice)); + } + + pub inline fn getGPUShaderFormats(gpudevice: *GPUDevice) GPUShaderFormat { + return @bitCast(c.SDL_GetGPUShaderFormats(@ptrCast(gpudevice))); + } + + pub inline fn getGPUDeviceProperties(gpudevice: *GPUDevice) PropertiesID { + return c.SDL_GetGPUDeviceProperties(@ptrCast(gpudevice)); + } + + pub inline fn createGPUComputePipeline(gpudevice: *GPUDevice, createinfo: *const GPUComputePipelineCreateInfo) ?*GPUComputePipeline { + return @ptrCast(c.SDL_CreateGPUComputePipeline(@ptrCast(gpudevice), @ptrCast(createinfo))); + } + + pub inline fn createGPUGraphicsPipeline(gpudevice: *GPUDevice, createinfo: *const GPUGraphicsPipelineCreateInfo) ?*GPUGraphicsPipeline { + return @ptrCast(c.SDL_CreateGPUGraphicsPipeline(@ptrCast(gpudevice), @ptrCast(createinfo))); + } + + pub inline fn createGPUSampler(gpudevice: *GPUDevice, createinfo: *const GPUSamplerCreateInfo) ?*GPUSampler { + return @ptrCast(c.SDL_CreateGPUSampler(@ptrCast(gpudevice), @ptrCast(createinfo))); + } + + pub inline fn createGPUShader(gpudevice: *GPUDevice, createinfo: *const GPUShaderCreateInfo) ?*GPUShader { + return @ptrCast(c.SDL_CreateGPUShader(@ptrCast(gpudevice), @ptrCast(createinfo))); + } + + pub inline fn createGPUTexture(gpudevice: *GPUDevice, createinfo: *const GPUTextureCreateInfo) ?*GPUTexture { + return @ptrCast(c.SDL_CreateGPUTexture(@ptrCast(gpudevice), @ptrCast(createinfo))); + } + + pub inline fn createGPUBuffer(gpudevice: *GPUDevice, createinfo: *const GPUBufferCreateInfo) ?*GPUBuffer { + return @ptrCast(c.SDL_CreateGPUBuffer(@ptrCast(gpudevice), @ptrCast(createinfo))); + } + + pub inline fn createGPUTransferBuffer(gpudevice: *GPUDevice, createinfo: *const GPUTransferBufferCreateInfo) ?*GPUTransferBuffer { + return @ptrCast(c.SDL_CreateGPUTransferBuffer(@ptrCast(gpudevice), @ptrCast(createinfo))); + } + + pub inline fn setGPUBufferName(gpudevice: *GPUDevice, buffer: ?*GPUBuffer, text: [*c]const u8) void { + return c.SDL_SetGPUBufferName(@ptrCast(gpudevice), @ptrCast(buffer), text); + } + + pub inline fn setGPUTextureName(gpudevice: *GPUDevice, texture: ?*GPUTexture, text: [*c]const u8) void { + return c.SDL_SetGPUTextureName(@ptrCast(gpudevice), @ptrCast(texture), text); + } + + pub inline fn releaseGPUTexture(gpudevice: *GPUDevice, texture: ?*GPUTexture) void { + return c.SDL_ReleaseGPUTexture(@ptrCast(gpudevice), @ptrCast(texture)); + } + + pub inline fn releaseGPUSampler(gpudevice: *GPUDevice, sampler: ?*GPUSampler) void { + return c.SDL_ReleaseGPUSampler(@ptrCast(gpudevice), @ptrCast(sampler)); + } + + pub inline fn releaseGPUBuffer(gpudevice: *GPUDevice, buffer: ?*GPUBuffer) void { + return c.SDL_ReleaseGPUBuffer(@ptrCast(gpudevice), @ptrCast(buffer)); + } + + pub inline fn releaseGPUTransferBuffer(gpudevice: *GPUDevice, transfer_buffer: ?*GPUTransferBuffer) void { + return c.SDL_ReleaseGPUTransferBuffer(@ptrCast(gpudevice), @ptrCast(transfer_buffer)); + } + + pub inline fn releaseGPUComputePipeline(gpudevice: *GPUDevice, compute_pipeline: ?*GPUComputePipeline) void { + return c.SDL_ReleaseGPUComputePipeline(@ptrCast(gpudevice), @ptrCast(compute_pipeline)); + } + + pub inline fn releaseGPUShader(gpudevice: *GPUDevice, shader: ?*GPUShader) void { + return c.SDL_ReleaseGPUShader(@ptrCast(gpudevice), @ptrCast(shader)); + } + + pub inline fn releaseGPUGraphicsPipeline(gpudevice: *GPUDevice, graphics_pipeline: ?*GPUGraphicsPipeline) void { + return c.SDL_ReleaseGPUGraphicsPipeline(@ptrCast(gpudevice), @ptrCast(graphics_pipeline)); + } + + pub inline fn acquireGPUCommandBuffer(gpudevice: *GPUDevice) ?*GPUCommandBuffer { + return @ptrCast(c.SDL_AcquireGPUCommandBuffer(@ptrCast(gpudevice))); + } + + pub inline fn mapGPUTransferBuffer(gpudevice: *GPUDevice, transfer_buffer: ?*GPUTransferBuffer, cycle: bool) ?*anyopaque { + return c.SDL_MapGPUTransferBuffer(@ptrCast(gpudevice), @ptrCast(transfer_buffer), @bitCast(cycle)); + } + + pub inline fn unmapGPUTransferBuffer(gpudevice: *GPUDevice, transfer_buffer: ?*GPUTransferBuffer) void { + return c.SDL_UnmapGPUTransferBuffer(@ptrCast(gpudevice), @ptrCast(transfer_buffer)); + } + + pub inline fn windowSupportsGPUSwapchainComposition(gpudevice: *GPUDevice, window: ?*Window, swapchain_composition: GPUSwapchainComposition) bool { + return @bitCast(c.SDL_WindowSupportsGPUSwapchainComposition(@ptrCast(gpudevice), @ptrCast(window), swapchain_composition)); + } + + pub inline fn windowSupportsGPUPresentMode(gpudevice: *GPUDevice, window: ?*Window, present_mode: GPUPresentMode) bool { + return @bitCast(c.SDL_WindowSupportsGPUPresentMode(@ptrCast(gpudevice), @ptrCast(window), @intFromEnum(present_mode))); + } + + pub inline fn claimWindowForGPUDevice(gpudevice: *GPUDevice, window: ?*Window) bool { + return @bitCast(c.SDL_ClaimWindowForGPUDevice(@ptrCast(gpudevice), @ptrCast(window))); + } + + pub inline fn releaseWindowFromGPUDevice(gpudevice: *GPUDevice, window: ?*Window) void { + return c.SDL_ReleaseWindowFromGPUDevice(@ptrCast(gpudevice), @ptrCast(window)); + } + + pub inline fn setGPUSwapchainParameters(gpudevice: *GPUDevice, window: ?*Window, swapchain_composition: GPUSwapchainComposition, present_mode: GPUPresentMode) bool { + return @bitCast(c.SDL_SetGPUSwapchainParameters(@ptrCast(gpudevice), @ptrCast(window), swapchain_composition, @intFromEnum(present_mode))); + } + + pub inline fn setGPUAllowedFramesInFlight(gpudevice: *GPUDevice, allowed_frames_in_flight: u32) bool { + return @bitCast(c.SDL_SetGPUAllowedFramesInFlight(@ptrCast(gpudevice), allowed_frames_in_flight)); + } + + pub inline fn getGPUSwapchainTextureFormat(gpudevice: *GPUDevice, window: ?*Window) GPUTextureFormat { + return @bitCast(c.SDL_GetGPUSwapchainTextureFormat(@ptrCast(gpudevice), @ptrCast(window))); + } + + pub inline fn waitForGPUSwapchain(gpudevice: *GPUDevice, window: ?*Window) bool { + return @bitCast(c.SDL_WaitForGPUSwapchain(@ptrCast(gpudevice), @ptrCast(window))); + } + + pub inline fn waitForGPUIdle(gpudevice: *GPUDevice) bool { + return @bitCast(c.SDL_WaitForGPUIdle(@ptrCast(gpudevice))); + } + + pub inline fn waitForGPUFences(gpudevice: *GPUDevice, wait_all: bool, fences: [*c]*const GPUFence, num_fences: u32) bool { + return @bitCast(c.SDL_WaitForGPUFences(@ptrCast(gpudevice), @bitCast(wait_all), fences, num_fences)); + } + + pub inline fn queryGPUFence(gpudevice: *GPUDevice, fence: ?*GPUFence) bool { + return @bitCast(c.SDL_QueryGPUFence(@ptrCast(gpudevice), @ptrCast(fence))); + } + + pub inline fn releaseGPUFence(gpudevice: *GPUDevice, fence: ?*GPUFence) void { + return c.SDL_ReleaseGPUFence(@ptrCast(gpudevice), @ptrCast(fence)); + } + + pub inline fn gpuTextureSupportsFormat(gpudevice: *GPUDevice, format: GPUTextureFormat, _type: GPUTextureType, usage: GPUTextureUsageFlags) bool { + return @bitCast(c.SDL_GPUTextureSupportsFormat(@ptrCast(gpudevice), @bitCast(format), @intFromEnum(_type), @bitCast(usage))); + } + + pub inline fn gpuTextureSupportsSampleCount(gpudevice: *GPUDevice, format: GPUTextureFormat, sample_count: GPUSampleCount) bool { + return @bitCast(c.SDL_GPUTextureSupportsSampleCount(@ptrCast(gpudevice), @bitCast(format), sample_count)); + } + + pub inline fn gdkSuspendGPU(gpudevice: *GPUDevice) void { + return c.SDL_GDKSuspendGPU(@ptrCast(gpudevice)); + } + + pub inline fn gdkResumeGPU(gpudevice: *GPUDevice) void { + return c.SDL_GDKResumeGPU(@ptrCast(gpudevice)); + } +}; + +pub const GPUBuffer = opaque {}; + +pub const GPUTransferBuffer = opaque {}; + +pub const GPUTexture = opaque {}; + +pub const GPUSampler = opaque {}; + +pub const GPUShader = opaque {}; + +pub const GPUComputePipeline = opaque {}; + +pub const GPUGraphicsPipeline = opaque {}; + +pub const GPUCommandBuffer = opaque { + pub inline fn insertGPUDebugLabel(gpucommandbuffer: *GPUCommandBuffer, text: [*c]const u8) void { + return c.SDL_InsertGPUDebugLabel(@ptrCast(gpucommandbuffer), text); + } + + pub inline fn pushGPUDebugGroup(gpucommandbuffer: *GPUCommandBuffer, name: [*c]const u8) void { + return c.SDL_PushGPUDebugGroup(@ptrCast(gpucommandbuffer), name); + } + + pub inline fn popGPUDebugGroup(gpucommandbuffer: *GPUCommandBuffer) void { + return c.SDL_PopGPUDebugGroup(@ptrCast(gpucommandbuffer)); + } + + pub inline fn pushGPUVertexUniformData(gpucommandbuffer: *GPUCommandBuffer, slot_index: u32, data: ?*const anyopaque, length: u32) void { + return c.SDL_PushGPUVertexUniformData(@ptrCast(gpucommandbuffer), slot_index, data, length); + } + + pub inline fn pushGPUFragmentUniformData(gpucommandbuffer: *GPUCommandBuffer, slot_index: u32, data: ?*const anyopaque, length: u32) void { + return c.SDL_PushGPUFragmentUniformData(@ptrCast(gpucommandbuffer), slot_index, data, length); + } + + pub inline fn pushGPUComputeUniformData(gpucommandbuffer: *GPUCommandBuffer, slot_index: u32, data: ?*const anyopaque, length: u32) void { + return c.SDL_PushGPUComputeUniformData(@ptrCast(gpucommandbuffer), slot_index, data, length); + } + + pub inline fn beginGPURenderPass(gpucommandbuffer: *GPUCommandBuffer, color_target_infos: *const GPUColorTargetInfo, num_color_targets: u32, depth_stencil_target_info: *const GPUDepthStencilTargetInfo) ?*GPURenderPass { + return @ptrCast(c.SDL_BeginGPURenderPass(@ptrCast(gpucommandbuffer), @ptrCast(color_target_infos), num_color_targets, @ptrCast(depth_stencil_target_info))); + } + + pub inline fn beginGPUComputePass(gpucommandbuffer: *GPUCommandBuffer, storage_texture_bindings: *const GPUStorageTextureReadWriteBinding, num_storage_texture_bindings: u32, storage_buffer_bindings: *const GPUStorageBufferReadWriteBinding, num_storage_buffer_bindings: u32) ?*GPUComputePass { + return @ptrCast(c.SDL_BeginGPUComputePass(@ptrCast(gpucommandbuffer), @ptrCast(storage_texture_bindings), num_storage_texture_bindings, @ptrCast(storage_buffer_bindings), num_storage_buffer_bindings)); + } + + pub inline fn beginGPUCopyPass(gpucommandbuffer: *GPUCommandBuffer) ?*GPUCopyPass { + return @ptrCast(c.SDL_BeginGPUCopyPass(@ptrCast(gpucommandbuffer))); + } + + pub inline fn generateMipmapsForGPUTexture(gpucommandbuffer: *GPUCommandBuffer, texture: ?*GPUTexture) void { + return c.SDL_GenerateMipmapsForGPUTexture(@ptrCast(gpucommandbuffer), @ptrCast(texture)); + } + + pub inline fn blitGPUTexture(gpucommandbuffer: *GPUCommandBuffer, info: *const GPUBlitInfo) void { + return c.SDL_BlitGPUTexture(@ptrCast(gpucommandbuffer), @ptrCast(info)); + } + + pub inline fn acquireGPUSwapchainTexture(gpucommandbuffer: *GPUCommandBuffer, window: ?*Window, swapchain_texture: [*c][*c]GPUTexture, swapchain_texture_width: *u32, swapchain_texture_height: *u32) bool { + return @bitCast(c.SDL_AcquireGPUSwapchainTexture(@ptrCast(gpucommandbuffer), @ptrCast(window), swapchain_texture, @ptrCast(swapchain_texture_width), @ptrCast(swapchain_texture_height))); + } + + pub inline fn waitAndAcquireGPUSwapchainTexture(gpucommandbuffer: *GPUCommandBuffer, window: ?*Window, swapchain_texture: [*c][*c]GPUTexture, swapchain_texture_width: *u32, swapchain_texture_height: *u32) bool { + return @bitCast(c.SDL_WaitAndAcquireGPUSwapchainTexture(@ptrCast(gpucommandbuffer), @ptrCast(window), swapchain_texture, @ptrCast(swapchain_texture_width), @ptrCast(swapchain_texture_height))); + } + + pub inline fn submitGPUCommandBuffer(gpucommandbuffer: *GPUCommandBuffer) bool { + return @bitCast(c.SDL_SubmitGPUCommandBuffer(@ptrCast(gpucommandbuffer))); + } + + pub inline fn submitGPUCommandBufferAndAcquireFence(gpucommandbuffer: *GPUCommandBuffer) ?*GPUFence { + return @ptrCast(c.SDL_SubmitGPUCommandBufferAndAcquireFence(@ptrCast(gpucommandbuffer))); + } + + pub inline fn cancelGPUCommandBuffer(gpucommandbuffer: *GPUCommandBuffer) bool { + return @bitCast(c.SDL_CancelGPUCommandBuffer(@ptrCast(gpucommandbuffer))); + } +}; + +pub const GPURenderPass = opaque { + pub inline fn bindGPUGraphicsPipeline(gpurenderpass: *GPURenderPass, graphics_pipeline: ?*GPUGraphicsPipeline) void { + return c.SDL_BindGPUGraphicsPipeline(@ptrCast(gpurenderpass), @ptrCast(graphics_pipeline)); + } + + pub inline fn setGPUViewport(gpurenderpass: *GPURenderPass, viewport: *const GPUViewport) void { + return c.SDL_SetGPUViewport(@ptrCast(gpurenderpass), @ptrCast(viewport)); + } + + pub inline fn setGPUScissor(gpurenderpass: *GPURenderPass, scissor: *const Rect) void { + return c.SDL_SetGPUScissor(@ptrCast(gpurenderpass), @ptrCast(scissor)); + } + + pub inline fn setGPUBlendConstants(gpurenderpass: *GPURenderPass, blend_constants: FColor) void { + return c.SDL_SetGPUBlendConstants(@ptrCast(gpurenderpass), blend_constants); + } + + pub inline fn setGPUStencilReference(gpurenderpass: *GPURenderPass, reference: u8) void { + return c.SDL_SetGPUStencilReference(@ptrCast(gpurenderpass), reference); + } + + pub inline fn bindGPUVertexBuffers(gpurenderpass: *GPURenderPass, first_slot: u32, bindings: *const GPUBufferBinding, num_bindings: u32) void { + return c.SDL_BindGPUVertexBuffers(@ptrCast(gpurenderpass), first_slot, @ptrCast(bindings), num_bindings); + } + + pub inline fn bindGPUIndexBuffer(gpurenderpass: *GPURenderPass, binding: *const GPUBufferBinding, index_element_size: GPUIndexElementSize) void { + return c.SDL_BindGPUIndexBuffer(@ptrCast(gpurenderpass), @ptrCast(binding), index_element_size); + } + + pub inline fn bindGPUVertexSamplers(gpurenderpass: *GPURenderPass, first_slot: u32, texture_sampler_bindings: *const GPUTextureSamplerBinding, num_bindings: u32) void { + return c.SDL_BindGPUVertexSamplers(@ptrCast(gpurenderpass), first_slot, @ptrCast(texture_sampler_bindings), num_bindings); + } + + pub inline fn bindGPUVertexStorageTextures(gpurenderpass: *GPURenderPass, first_slot: u32, storage_textures: [*c]*const GPUTexture, num_bindings: u32) void { + return c.SDL_BindGPUVertexStorageTextures(@ptrCast(gpurenderpass), first_slot, storage_textures, num_bindings); + } + + pub inline fn bindGPUVertexStorageBuffers(gpurenderpass: *GPURenderPass, first_slot: u32, storage_buffers: [*c]*const GPUBuffer, num_bindings: u32) void { + return c.SDL_BindGPUVertexStorageBuffers(@ptrCast(gpurenderpass), first_slot, storage_buffers, num_bindings); + } + + pub inline fn bindGPUFragmentSamplers(gpurenderpass: *GPURenderPass, first_slot: u32, texture_sampler_bindings: *const GPUTextureSamplerBinding, num_bindings: u32) void { + return c.SDL_BindGPUFragmentSamplers(@ptrCast(gpurenderpass), first_slot, @ptrCast(texture_sampler_bindings), num_bindings); + } + + pub inline fn bindGPUFragmentStorageTextures(gpurenderpass: *GPURenderPass, first_slot: u32, storage_textures: [*c]*const GPUTexture, num_bindings: u32) void { + return c.SDL_BindGPUFragmentStorageTextures(@ptrCast(gpurenderpass), first_slot, storage_textures, num_bindings); + } + + pub inline fn bindGPUFragmentStorageBuffers(gpurenderpass: *GPURenderPass, first_slot: u32, storage_buffers: [*c]*const GPUBuffer, num_bindings: u32) void { + return c.SDL_BindGPUFragmentStorageBuffers(@ptrCast(gpurenderpass), first_slot, storage_buffers, num_bindings); + } + + pub inline fn drawGPUIndexedPrimitives(gpurenderpass: *GPURenderPass, num_indices: u32, num_instances: u32, first_index: u32, vertex_offset: i32, first_instance: u32) void { + return c.SDL_DrawGPUIndexedPrimitives(@ptrCast(gpurenderpass), num_indices, num_instances, first_index, vertex_offset, first_instance); + } + + pub inline fn drawGPUPrimitives(gpurenderpass: *GPURenderPass, num_vertices: u32, num_instances: u32, first_vertex: u32, first_instance: u32) void { + return c.SDL_DrawGPUPrimitives(@ptrCast(gpurenderpass), num_vertices, num_instances, first_vertex, first_instance); + } + + pub inline fn drawGPUPrimitivesIndirect(gpurenderpass: *GPURenderPass, buffer: ?*GPUBuffer, offset: u32, draw_count: u32) void { + return c.SDL_DrawGPUPrimitivesIndirect(@ptrCast(gpurenderpass), @ptrCast(buffer), offset, draw_count); + } + + pub inline fn drawGPUIndexedPrimitivesIndirect(gpurenderpass: *GPURenderPass, buffer: ?*GPUBuffer, offset: u32, draw_count: u32) void { + return c.SDL_DrawGPUIndexedPrimitivesIndirect(@ptrCast(gpurenderpass), @ptrCast(buffer), offset, draw_count); + } + + pub inline fn endGPURenderPass(gpurenderpass: *GPURenderPass) void { + return c.SDL_EndGPURenderPass(@ptrCast(gpurenderpass)); + } +}; + +pub const GPUComputePass = opaque { + pub inline fn bindGPUComputePipeline(gpucomputepass: *GPUComputePass, compute_pipeline: ?*GPUComputePipeline) void { + return c.SDL_BindGPUComputePipeline(@ptrCast(gpucomputepass), @ptrCast(compute_pipeline)); + } + + pub inline fn bindGPUComputeSamplers(gpucomputepass: *GPUComputePass, first_slot: u32, texture_sampler_bindings: *const GPUTextureSamplerBinding, num_bindings: u32) void { + return c.SDL_BindGPUComputeSamplers(@ptrCast(gpucomputepass), first_slot, @ptrCast(texture_sampler_bindings), num_bindings); + } + + pub inline fn bindGPUComputeStorageTextures(gpucomputepass: *GPUComputePass, first_slot: u32, storage_textures: [*c]*const GPUTexture, num_bindings: u32) void { + return c.SDL_BindGPUComputeStorageTextures(@ptrCast(gpucomputepass), first_slot, storage_textures, num_bindings); + } + + pub inline fn bindGPUComputeStorageBuffers(gpucomputepass: *GPUComputePass, first_slot: u32, storage_buffers: [*c]*const GPUBuffer, num_bindings: u32) void { + return c.SDL_BindGPUComputeStorageBuffers(@ptrCast(gpucomputepass), first_slot, storage_buffers, num_bindings); + } + + pub inline fn dispatchGPUCompute(gpucomputepass: *GPUComputePass, groupcount_x: u32, groupcount_y: u32, groupcount_z: u32) void { + return c.SDL_DispatchGPUCompute(@ptrCast(gpucomputepass), groupcount_x, groupcount_y, groupcount_z); + } + + pub inline fn dispatchGPUComputeIndirect(gpucomputepass: *GPUComputePass, buffer: ?*GPUBuffer, offset: u32) void { + return c.SDL_DispatchGPUComputeIndirect(@ptrCast(gpucomputepass), @ptrCast(buffer), offset); + } + + pub inline fn endGPUComputePass(gpucomputepass: *GPUComputePass) void { + return c.SDL_EndGPUComputePass(@ptrCast(gpucomputepass)); + } +}; + +pub const GPUCopyPass = opaque { + pub inline fn uploadToGPUTexture(gpucopypass: *GPUCopyPass, source: *const GPUTextureTransferInfo, destination: *const GPUTextureRegion, cycle: bool) void { + return c.SDL_UploadToGPUTexture(@ptrCast(gpucopypass), @ptrCast(source), @ptrCast(destination), @bitCast(cycle)); + } + + pub inline fn uploadToGPUBuffer(gpucopypass: *GPUCopyPass, source: *const GPUTransferBufferLocation, destination: *const GPUBufferRegion, cycle: bool) void { + return c.SDL_UploadToGPUBuffer(@ptrCast(gpucopypass), @ptrCast(source), @ptrCast(destination), @bitCast(cycle)); + } + + pub inline fn copyGPUTextureToTexture(gpucopypass: *GPUCopyPass, source: *const GPUTextureLocation, destination: *const GPUTextureLocation, w: u32, h: u32, d: u32, cycle: bool) void { + return c.SDL_CopyGPUTextureToTexture(@ptrCast(gpucopypass), @ptrCast(source), @ptrCast(destination), w, h, d, @bitCast(cycle)); + } + + pub inline fn copyGPUBufferToBuffer(gpucopypass: *GPUCopyPass, source: *const GPUBufferLocation, destination: *const GPUBufferLocation, size: u32, cycle: bool) void { + return c.SDL_CopyGPUBufferToBuffer(@ptrCast(gpucopypass), @ptrCast(source), @ptrCast(destination), size, @bitCast(cycle)); + } + + pub inline fn downloadFromGPUTexture(gpucopypass: *GPUCopyPass, source: *const GPUTextureRegion, destination: *const GPUTextureTransferInfo) void { + return c.SDL_DownloadFromGPUTexture(@ptrCast(gpucopypass), @ptrCast(source), @ptrCast(destination)); + } + + pub inline fn downloadFromGPUBuffer(gpucopypass: *GPUCopyPass, source: *const GPUBufferRegion, destination: *const GPUTransferBufferLocation) void { + return c.SDL_DownloadFromGPUBuffer(@ptrCast(gpucopypass), @ptrCast(source), @ptrCast(destination)); + } + + pub inline fn endGPUCopyPass(gpucopypass: *GPUCopyPass) void { + return c.SDL_EndGPUCopyPass(@ptrCast(gpucopypass)); + } +}; + +pub const GPUFence = opaque {}; + +pub const GPUPrimitiveType = enum(c_int) { + primitivetypeTrianglelist, //A series of separate triangles. + primitivetypeTrianglestrip, //A series of connected triangles. + primitivetypeLinelist, //A series of separate lines. + primitivetypeLinestrip, //A series of connected lines. + primitivetypePointlist, //A series of separate points. +}; + +pub const GPULoadOp = enum(c_int) { + loadopLoad, //The previous contents of the texture will be preserved. + loadopClear, //The contents of the texture will be cleared to a color. + loadopDontCare, //The previous contents of the texture need not be preserved. The contents will be undefined. +}; + +pub const GPUStoreOp = enum(c_int) { + storeopStore, //The contents generated during the render pass will be written to memory. + storeopDontCare, //The contents generated during the render pass are not needed and may be discarded. The contents will be undefined. + storeopResolve, //The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture may then be discarded and will be undefined. + storeopResolveAndStore, //The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture will be written to memory. +}; + +pub const GPUIndexElementSize = enum(c_int) { + indexelementsize16bit, //The index elements are 16-bit. + indexelementsize32bit, //The index elements are 32-bit. +}; + +pub const GPUTextureFormat = enum(c_int) { + textureformatInvalid, + textureformatA8Unorm, + textureformatR8Unorm, + textureformatR8g8Unorm, + textureformatR8g8b8a8Unorm, + textureformatR16Unorm, + textureformatR16g16Unorm, + textureformatR16g16b16a16Unorm, + textureformatR10g10b10a2Unorm, + textureformatB5g6r5Unorm, + textureformatB5g5r5a1Unorm, + textureformatB4g4r4a4Unorm, + textureformatB8g8r8a8Unorm, + textureformatBc1RgbaUnorm, + textureformatBc2RgbaUnorm, + textureformatBc3RgbaUnorm, + textureformatBc4RUnorm, + textureformatBc5RgUnorm, + textureformatBc7RgbaUnorm, + textureformatBc6hRgbFloat, + textureformatBc6hRgbUfloat, + textureformatR8Snorm, + textureformatR8g8Snorm, + textureformatR8g8b8a8Snorm, + textureformatR16Snorm, + textureformatR16g16Snorm, + textureformatR16g16b16a16Snorm, + textureformatR16Float, + textureformatR16g16Float, + textureformatR16g16b16a16Float, + textureformatR32Float, + textureformatR32g32Float, + textureformatR32g32b32a32Float, + textureformatR11g11b10Ufloat, + textureformatR8Uint, + textureformatR8g8Uint, + textureformatR8g8b8a8Uint, + textureformatR16Uint, + textureformatR16g16Uint, + textureformatR16g16b16a16Uint, + textureformatR32Uint, + textureformatR32g32Uint, + textureformatR32g32b32a32Uint, + textureformatR8Int, + textureformatR8g8Int, + textureformatR8g8b8a8Int, + textureformatR16Int, + textureformatR16g16Int, + textureformatR16g16b16a16Int, + textureformatR32Int, + textureformatR32g32Int, + textureformatR32g32b32a32Int, + textureformatR8g8b8a8UnormSrgb, + textureformatB8g8r8a8UnormSrgb, + textureformatBc1RgbaUnormSrgb, + textureformatBc2RgbaUnormSrgb, + textureformatBc3RgbaUnormSrgb, + textureformatBc7RgbaUnormSrgb, + textureformatD16Unorm, + textureformatD24Unorm, + textureformatD32Float, + textureformatD24UnormS8Uint, + textureformatD32FloatS8Uint, + textureformatAstc4x4Unorm, + textureformatAstc5x4Unorm, + textureformatAstc5x5Unorm, + textureformatAstc6x5Unorm, + textureformatAstc6x6Unorm, + textureformatAstc8x5Unorm, + textureformatAstc8x6Unorm, + textureformatAstc8x8Unorm, + textureformatAstc10x5Unorm, + textureformatAstc10x6Unorm, + textureformatAstc10x8Unorm, + textureformatAstc10x10Unorm, + textureformatAstc12x10Unorm, + textureformatAstc12x12Unorm, + textureformatAstc4x4UnormSrgb, + textureformatAstc5x4UnormSrgb, + textureformatAstc5x5UnormSrgb, + textureformatAstc6x5UnormSrgb, + textureformatAstc6x6UnormSrgb, + textureformatAstc8x5UnormSrgb, + textureformatAstc8x6UnormSrgb, + textureformatAstc8x8UnormSrgb, + textureformatAstc10x5UnormSrgb, + textureformatAstc10x6UnormSrgb, + textureformatAstc10x8UnormSrgb, + textureformatAstc10x10UnormSrgb, + textureformatAstc12x10UnormSrgb, + textureformatAstc12x12UnormSrgb, + textureformatAstc4x4Float, + textureformatAstc5x4Float, + textureformatAstc5x5Float, + textureformatAstc6x5Float, + textureformatAstc6x6Float, + textureformatAstc8x5Float, + textureformatAstc8x6Float, + textureformatAstc8x8Float, + textureformatAstc10x5Float, + textureformatAstc10x6Float, + textureformatAstc10x8Float, + textureformatAstc10x10Float, + textureformatAstc12x10Float, + textureformatAstc12x12Float, +}; + +pub const GPUTextureUsageFlags = packed struct(u32) { + textureusageSampler: bool = false, // Texture supports sampling. + textureusageColorTarget: bool = false, // Texture is a color render target. + textureusageDepthStencilTarget: bool = false, // Texture is a depth stencil target. + textureusageGraphicsStorageRead: bool = false, // Texture supports storage reads in graphics stages. + textureusageComputeStorageRead: bool = false, // Texture supports storage reads in the compute stage. + textureusageComputeStorageWrite: bool = false, // Texture supports storage writes in the compute stage. + textureusageComputeStorageSimultaneousReadWrite: bool = false, // Texture supports reads and writes in the same compute shader. This is NOT equivalent to READ | WRITE. + pad0: u24 = 0, + rsvd: bool = false, + + pub const None = GPUTextureUsageFlags{}; +}; + +pub const GPUTextureType = enum(c_int) { + texturetype2d, //The texture is a 2-dimensional image. + texturetype2dArray, //The texture is a 2-dimensional array image. + texturetype3d, //The texture is a 3-dimensional image. + texturetypeCube, //The texture is a cube image. + texturetypeCubeArray, //The texture is a cube array image. +}; + +pub const GPUSampleCount = enum(c_int) { + samplecount1, //No multisampling. + samplecount2, //MSAA 2x + samplecount4, //MSAA 4x + samplecount8, //MSAA 8x +}; + +pub const GPUCubeMapFace = enum(c_int) { + cubemapfacePositivex, + cubemapfaceNegativex, + cubemapfacePositivey, + cubemapfaceNegativey, + cubemapfacePositivez, + cubemapfaceNegativez, +}; + +pub const GPUBufferUsageFlags = packed struct(u32) { + bufferusageVertex: bool = false, // Buffer is a vertex buffer. + bufferusageIndex: bool = false, // Buffer is an index buffer. + bufferusageIndirect: bool = false, // Buffer is an indirect buffer. + bufferusageGraphicsStorageRead: bool = false, // Buffer supports storage reads in graphics stages. + bufferusageComputeStorageRead: bool = false, // Buffer supports storage reads in the compute stage. + bufferusageComputeStorageWrite: bool = false, // Buffer supports storage writes in the compute stage. + pad0: u25 = 0, + rsvd: bool = false, + + pub const None = GPUBufferUsageFlags{}; +}; + +pub const GPUTransferBufferUsage = enum(c_int) { + transferbufferusageUpload, + transferbufferusageDownload, +}; + +pub const GPUShaderStage = enum(c_int) { + shaderstageVertex, + shaderstageFragment, +}; + +pub const GPUShaderFormat = u32; + +pub const GPUVertexElementFormat = enum(c_int) { + vertexelementformatInvalid, + vertexelementformatInt, + vertexelementformatInt2, + vertexelementformatInt3, + vertexelementformatInt4, + vertexelementformatUint, + vertexelementformatUint2, + vertexelementformatUint3, + vertexelementformatUint4, + vertexelementformatFloat, + vertexelementformatFloat2, + vertexelementformatFloat3, + vertexelementformatFloat4, + vertexelementformatByte2, + vertexelementformatByte4, + vertexelementformatUbyte2, + vertexelementformatUbyte4, + vertexelementformatByte2Norm, + vertexelementformatByte4Norm, + vertexelementformatUbyte2Norm, + vertexelementformatUbyte4Norm, + vertexelementformatShort2, + vertexelementformatShort4, + vertexelementformatUshort2, + vertexelementformatUshort4, + vertexelementformatShort2Norm, + vertexelementformatShort4Norm, + vertexelementformatUshort2Norm, + vertexelementformatUshort4Norm, + vertexelementformatHalf2, + vertexelementformatHalf4, +}; + +pub const GPUVertexInputRate = enum(c_int) { + vertexinputrateVertex, //Attribute addressing is a function of the vertex index. + vertexinputrateInstance, //Attribute addressing is a function of the instance index. +}; + +pub const GPUFillMode = enum(c_int) { + fillmodeFill, //Polygons will be rendered via rasterization. + fillmodeLine, //Polygon edges will be drawn as line segments. +}; + +pub const GPUCullMode = enum(c_int) { + cullmodeNone, //No triangles are culled. + cullmodeFront, //Front-facing triangles are culled. + cullmodeBack, //Back-facing triangles are culled. +}; + +pub const GPUFrontFace = enum(c_int) { + frontfaceCounterClockwise, //A triangle with counter-clockwise vertex winding will be considered front-facing. + frontfaceClockwise, //A triangle with clockwise vertex winding will be considered front-facing. +}; + +pub const GPUCompareOp = enum(c_int) { + compareopInvalid, + compareopNever, //The comparison always evaluates false. + compareopLess, //The comparison evaluates reference < test. + compareopEqual, //The comparison evaluates reference == test. + compareopLessOrEqual, //The comparison evaluates reference <= test. + compareopGreater, //The comparison evaluates reference > test. + compareopNotEqual, //The comparison evaluates reference != test. + compareopGreaterOrEqual, //The comparison evaluates reference >= test. + compareopAlways, //The comparison always evaluates true. +}; + +pub const GPUStencilOp = enum(c_int) { + stencilopInvalid, + stencilopKeep, //Keeps the current value. + stencilopZero, //Sets the value to 0. + stencilopReplace, //Sets the value to reference. + stencilopIncrementAndClamp, //Increments the current value and clamps to the maximum value. + stencilopDecrementAndClamp, //Decrements the current value and clamps to 0. + stencilopInvert, //Bitwise-inverts the current value. + stencilopIncrementAndWrap, //Increments the current value and wraps back to 0. + stencilopDecrementAndWrap, //Decrements the current value and wraps to the maximum value. +}; + +pub const GPUBlendOp = enum(c_int) { + blendopInvalid, + blendopAdd, //(source * source_factor) + (destination * destination_factor) + blendopSubtract, //(source * source_factor) - (destination * destination_factor) + blendopReverseSubtract, //(destination * destination_factor) - (source * source_factor) + blendopMin, //min(source, destination) + blendopMax, +}; + +pub const GPUBlendFactor = enum(c_int) { + blendfactorInvalid, + blendfactorZero, //0 + blendfactorOne, //1 + blendfactorSrcColor, //source color + blendfactorOneMinusSrcColor, //1 - source color + blendfactorDstColor, //destination color + blendfactorOneMinusDstColor, //1 - destination color + blendfactorSrcAlpha, //source alpha + blendfactorOneMinusSrcAlpha, //1 - source alpha + blendfactorDstAlpha, //destination alpha + blendfactorOneMinusDstAlpha, //1 - destination alpha + blendfactorConstantColor, //blend constant + blendfactorOneMinusConstantColor, //1 - blend constant + blendfactorSrcAlphaSaturate, +}; + +pub const GPUColorComponentFlags = packed struct(u8) { + colorcomponentR: bool = false, // the red component + colorcomponentG: bool = false, // the green component + colorcomponentB: bool = false, // the blue component + colorcomponentA: bool = false, // the alpha component + pad0: u3 = 0, + rsvd: bool = false, + + pub const None = GPUColorComponentFlags{}; +}; + +pub const GPUFilter = enum(c_int) { + filterNearest, //Point filtering. + filterLinear, //Linear filtering. +}; + +pub const GPUSamplerMipmapMode = enum(c_int) { + samplermipmapmodeNearest, //Point filtering. + samplermipmapmodeLinear, //Linear filtering. +}; + +pub const GPUSamplerAddressMode = enum(c_int) { + sampleraddressmodeRepeat, //Specifies that the coordinates will wrap around. + sampleraddressmodeMirroredRepeat, //Specifies that the coordinates will wrap around mirrored. + sampleraddressmodeClampToEdge, //Specifies that the coordinates will clamp to the 0-1 range. +}; + +pub const GPUPresentMode = enum(c_int) { + presentmodeVsync, + presentmodeImmediate, + presentmodeMailbox, +}; + +pub const GPUSwapchainComposition = enum(c_int) { + swapchaincompositionSdr, + swapchaincompositionSdrLinear, + swapchaincompositionHdrExtendedLinear, + swapchaincompositionHdr10St2084, +}; + +pub const GPUViewport = extern struct { + x: f32, // The left offset of the viewport. + y: f32, // The top offset of the viewport. + w: f32, // The width of the viewport. + h: f32, // The height of the viewport. + min_depth: f32, // The minimum depth of the viewport. + max_depth: f32, // The maximum depth of the viewport. +}; + +pub const GPUTextureTransferInfo = extern struct { + transfer_buffer: ?*GPUTransferBuffer, // The transfer buffer used in the transfer operation. + offset: u32, // The starting byte of the image data in the transfer buffer. + pixels_per_row: u32, // The number of pixels from one row to the next. + rows_per_layer: u32, // The number of rows from one layer/depth-slice to the next. +}; + +pub const GPUTransferBufferLocation = extern struct { + transfer_buffer: ?*GPUTransferBuffer, // The transfer buffer used in the transfer operation. + offset: u32, // The starting byte of the buffer data in the transfer buffer. +}; + +pub const GPUTextureLocation = extern struct { + texture: ?*GPUTexture, // The texture used in the copy operation. + mip_level: u32, // The mip level index of the location. + layer: u32, // The layer index of the location. + x: u32, // The left offset of the location. + y: u32, // The top offset of the location. + z: u32, // The front offset of the location. +}; + +pub const GPUTextureRegion = extern struct { + texture: ?*GPUTexture, // The texture used in the copy operation. + mip_level: u32, // The mip level index to transfer. + layer: u32, // The layer index to transfer. + x: u32, // The left offset of the region. + y: u32, // The top offset of the region. + z: u32, // The front offset of the region. + w: u32, // The width of the region. + h: u32, // The height of the region. + d: u32, // The depth of the region. +}; + +pub const GPUBlitRegion = extern struct { + texture: ?*GPUTexture, // The texture. + mip_level: u32, // The mip level index of the region. + layer_or_depth_plane: u32, // The layer index or depth plane of the region. This value is treated as a layer index on 2D array and cube textures, and as a depth plane on 3D textures. + x: u32, // The left offset of the region. + y: u32, // The top offset of the region. + w: u32, // The width of the region. + h: u32, // The height of the region. +}; + +pub const GPUBufferLocation = extern struct { + buffer: ?*GPUBuffer, // The buffer. + offset: u32, // The starting byte within the buffer. +}; + +pub const GPUBufferRegion = extern struct { + buffer: ?*GPUBuffer, // The buffer. + offset: u32, // The starting byte within the buffer. + size: u32, // The size in bytes of the region. +}; + +pub const GPUIndirectDrawCommand = extern struct { + num_vertices: u32, // The number of vertices to draw. + num_instances: u32, // The number of instances to draw. + first_vertex: u32, // The index of the first vertex to draw. + first_instance: u32, // The ID of the first instance to draw. +}; + +pub const GPUIndexedIndirectDrawCommand = extern struct { + num_indices: u32, // The number of indices to draw per instance. + num_instances: u32, // The number of instances to draw. + first_index: u32, // The base index within the index buffer. + vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer. + first_instance: u32, // The ID of the first instance to draw. +}; + +pub const GPUIndirectDispatchCommand = extern struct { + groupcount_x: u32, // The number of local workgroups to dispatch in the X dimension. + groupcount_y: u32, // The number of local workgroups to dispatch in the Y dimension. + groupcount_z: u32, // The number of local workgroups to dispatch in the Z dimension. +}; + +pub const GPUSamplerCreateInfo = extern struct { + min_filter: GPUFilter, // The minification filter to apply to lookups. + mag_filter: GPUFilter, // The magnification filter to apply to lookups. + mipmap_mode: GPUSamplerMipmapMode, // The mipmap filter to apply to lookups. + address_mode_u: GPUSamplerAddressMode, // The addressing mode for U coordinates outside [0, 1). + address_mode_v: GPUSamplerAddressMode, // The addressing mode for V coordinates outside [0, 1). + address_mode_w: GPUSamplerAddressMode, // The addressing mode for W coordinates outside [0, 1). + mip_lod_bias: f32, // The bias to be added to mipmap LOD calculation. + max_anisotropy: f32, // The anisotropy value clamp used by the sampler. If enable_anisotropy is false, this is ignored. + compare_op: GPUCompareOp, // The comparison operator to apply to fetched data before filtering. + min_lod: f32, // Clamps the minimum of the computed LOD value. + max_lod: f32, // Clamps the maximum of the computed LOD value. + enable_anisotropy: bool, // true to enable anisotropic filtering. + enable_compare: bool, // true to enable comparison against a reference value during lookups. + padding1: u8, + padding2: u8, + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPUVertexBufferDescription = extern struct { + slot: u32, // The binding slot of the vertex buffer. + pitch: u32, // The size of a single element + the offset between elements. + input_rate: GPUVertexInputRate, // Whether attribute addressing is a function of the vertex index or instance index. + instance_step_rate: u32, // Reserved for future use. Must be set to 0. +}; + +pub const GPUVertexAttribute = extern struct { + location: u32, // The shader input location index. + buffer_slot: u32, // The binding slot of the associated vertex buffer. + format: GPUVertexElementFormat, // The size and type of the attribute data. + offset: u32, // The byte offset of this attribute relative to the start of the vertex element. +}; + +pub const GPUVertexInputState = extern struct { + vertex_buffer_descriptions: *const GPUVertexBufferDescription, // A pointer to an array of vertex buffer descriptions. + num_vertex_buffers: u32, // The number of vertex buffer descriptions in the above array. + vertex_attributes: *const GPUVertexAttribute, // A pointer to an array of vertex attribute descriptions. + num_vertex_attributes: u32, // The number of vertex attribute descriptions in the above array. +}; + +pub const GPUStencilOpState = extern struct { + fail_op: GPUStencilOp, // The action performed on samples that fail the stencil test. + pass_op: GPUStencilOp, // The action performed on samples that pass the depth and stencil tests. + depth_fail_op: GPUStencilOp, // The action performed on samples that pass the stencil test and fail the depth test. + compare_op: GPUCompareOp, // The comparison operator used in the stencil test. +}; + +pub const GPUColorTargetBlendState = extern struct { + src_color_blendfactor: GPUBlendFactor, // The value to be multiplied by the source RGB value. + dst_color_blendfactor: GPUBlendFactor, // The value to be multiplied by the destination RGB value. + color_blend_op: GPUBlendOp, // The blend operation for the RGB components. + src_alpha_blendfactor: GPUBlendFactor, // The value to be multiplied by the source alpha. + dst_alpha_blendfactor: GPUBlendFactor, // The value to be multiplied by the destination alpha. + alpha_blend_op: GPUBlendOp, // The blend operation for the alpha component. + color_write_mask: GPUColorComponentFlags, // A bitmask specifying which of the RGBA components are enabled for writing. Writes to all channels if enable_color_write_mask is false. + enable_blend: bool, // Whether blending is enabled for the color target. + enable_color_write_mask: bool, // Whether the color write mask is enabled. + padding1: u8, + padding2: u8, +}; + +pub const GPUShaderCreateInfo = extern struct { + code_size: usize, // The size in bytes of the code pointed to. + code: [*c]const u8, // A pointer to shader code. + entrypoint: [*c]const u8, // A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader. + format: GPUShaderFormat, // The format of the shader code. + stage: GPUShaderStage, // The stage the shader program corresponds to. + num_samplers: u32, // The number of samplers defined in the shader. + num_storage_textures: u32, // The number of storage textures defined in the shader. + num_storage_buffers: u32, // The number of storage buffers defined in the shader. + num_uniform_buffers: u32, // The number of uniform buffers defined in the shader. + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPUTextureCreateInfo = extern struct { + _type: GPUTextureType, // The base dimensionality of the texture. + format: GPUTextureFormat, // The pixel format of the texture. + usage: GPUTextureUsageFlags, // How the texture is intended to be used by the client. + width: u32, // The width of the texture. + height: u32, // The height of the texture. + layer_count_or_depth: u32, // The layer count or depth of the texture. This value is treated as a layer count on 2D array textures, and as a depth value on 3D textures. + num_levels: u32, // The number of mip levels in the texture. + sample_count: GPUSampleCount, // The number of samples per texel. Only applies if the texture is used as a render target. + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPUBufferCreateInfo = extern struct { + usage: GPUBufferUsageFlags, // How the buffer is intended to be used by the client. + size: u32, // The size in bytes of the buffer. + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPUTransferBufferCreateInfo = extern struct { + usage: GPUTransferBufferUsage, // How the transfer buffer is intended to be used by the client. + size: u32, // The size in bytes of the transfer buffer. + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPURasterizerState = extern struct { + fill_mode: GPUFillMode, // Whether polygons will be filled in or drawn as lines. + cull_mode: GPUCullMode, // The facing direction in which triangles will be culled. + front_face: GPUFrontFace, // The vertex winding that will cause a triangle to be determined as front-facing. + depth_bias_constant_factor: f32, // A scalar factor controlling the depth value added to each fragment. + depth_bias_clamp: f32, // The maximum depth bias of a fragment. + depth_bias_slope_factor: f32, // A scalar factor applied to a fragment's slope in depth calculations. + enable_depth_bias: bool, // true to bias fragment depth values. + enable_depth_clip: bool, // true to enable depth clip, false to enable depth clamp. + padding1: u8, + padding2: u8, +}; + +pub const GPUMultisampleState = extern struct { + sample_count: GPUSampleCount, // The number of samples to be used in rasterization. + sample_mask: u32, // Reserved for future use. Must be set to 0. + enable_mask: bool, // Reserved for future use. Must be set to false. + enable_alpha_to_coverage: bool, // true enables the alpha-to-coverage feature. + padding2: u8, + padding3: u8, +}; + +pub const GPUDepthStencilState = extern struct { + compare_op: GPUCompareOp, // The comparison operator used for depth testing. + back_stencil_state: GPUStencilOpState, // The stencil op state for back-facing triangles. + front_stencil_state: GPUStencilOpState, // The stencil op state for front-facing triangles. + compare_mask: u8, // Selects the bits of the stencil values participating in the stencil test. + write_mask: u8, // Selects the bits of the stencil values updated by the stencil test. + enable_depth_test: bool, // true enables the depth test. + enable_depth_write: bool, // true enables depth writes. Depth writes are always disabled when enable_depth_test is false. + enable_stencil_test: bool, // true enables the stencil test. + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const GPUColorTargetDescription = extern struct { + format: GPUTextureFormat, // The pixel format of the texture to be used as a color target. + blend_state: GPUColorTargetBlendState, // The blend state to be used for the color target. +}; + +pub const GPUGraphicsPipelineTargetInfo = extern struct { + color_target_descriptions: *const GPUColorTargetDescription, // A pointer to an array of color target descriptions. + num_color_targets: u32, // The number of color target descriptions in the above array. + depth_stencil_format: GPUTextureFormat, // The pixel format of the depth-stencil target. Ignored if has_depth_stencil_target is false. + has_depth_stencil_target: bool, // true specifies that the pipeline uses a depth-stencil target. + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const GPUGraphicsPipelineCreateInfo = extern struct { + vertex_shader: ?*GPUShader, // The vertex shader used by the graphics pipeline. + fragment_shader: ?*GPUShader, // The fragment shader used by the graphics pipeline. + vertex_input_state: GPUVertexInputState, // The vertex layout of the graphics pipeline. + primitive_type: GPUPrimitiveType, // The primitive topology of the graphics pipeline. + rasterizer_state: GPURasterizerState, // The rasterizer state of the graphics pipeline. + multisample_state: GPUMultisampleState, // The multisample state of the graphics pipeline. + depth_stencil_state: GPUDepthStencilState, // The depth-stencil state of the graphics pipeline. + target_info: GPUGraphicsPipelineTargetInfo, // Formats and blend modes for the render targets of the graphics pipeline. + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPUComputePipelineCreateInfo = extern struct { + code_size: usize, // The size in bytes of the compute shader code pointed to. + code: [*c]const u8, // A pointer to compute shader code. + entrypoint: [*c]const u8, // A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader. + format: GPUShaderFormat, // The format of the compute shader code. + num_samplers: u32, // The number of samplers defined in the shader. + num_readonly_storage_textures: u32, // The number of readonly storage textures defined in the shader. + num_readonly_storage_buffers: u32, // The number of readonly storage buffers defined in the shader. + num_readwrite_storage_textures: u32, // The number of read-write storage textures defined in the shader. + num_readwrite_storage_buffers: u32, // The number of read-write storage buffers defined in the shader. + num_uniform_buffers: u32, // The number of uniform buffers defined in the shader. + threadcount_x: u32, // The number of threads in the X dimension. This should match the value in the shader. + threadcount_y: u32, // The number of threads in the Y dimension. This should match the value in the shader. + threadcount_z: u32, // The number of threads in the Z dimension. This should match the value in the shader. + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPUColorTargetInfo = extern struct { + texture: ?*GPUTexture, // The texture that will be used as a color target by a render pass. + mip_level: u32, // The mip level to use as a color target. + layer_or_depth_plane: u32, // The layer index or depth plane to use as a color target. This value is treated as a layer index on 2D array and cube textures, and as a depth plane on 3D textures. + clear_color: FColor, // The color to clear the color target to at the start of the render pass. Ignored if SDL_GPU_LOADOP_CLEAR is not used. + load_op: GPULoadOp, // What is done with the contents of the color target at the beginning of the render pass. + store_op: GPUStoreOp, // What is done with the results of the render pass. + resolve_texture: ?*GPUTexture, // The texture that will receive the results of a multisample resolve operation. Ignored if a RESOLVE* store_op is not used. + resolve_mip_level: u32, // The mip level of the resolve texture to use for the resolve operation. Ignored if a RESOLVE* store_op is not used. + resolve_layer: u32, // The layer index of the resolve texture to use for the resolve operation. Ignored if a RESOLVE* store_op is not used. + cycle: bool, // true cycles the texture if the texture is bound and load_op is not LOAD + cycle_resolve_texture: bool, // true cycles the resolve texture if the resolve texture is bound. Ignored if a RESOLVE* store_op is not used. + padding1: u8, + padding2: u8, +}; + +pub const GPUDepthStencilTargetInfo = extern struct { + texture: ?*GPUTexture, // The texture that will be used as the depth stencil target by the render pass. + clear_depth: f32, // The value to clear the depth component to at the beginning of the render pass. Ignored if SDL_GPU_LOADOP_CLEAR is not used. + load_op: GPULoadOp, // What is done with the depth contents at the beginning of the render pass. + store_op: GPUStoreOp, // What is done with the depth results of the render pass. + stencil_load_op: GPULoadOp, // What is done with the stencil contents at the beginning of the render pass. + stencil_store_op: GPUStoreOp, // What is done with the stencil results of the render pass. + cycle: bool, // true cycles the texture if the texture is bound and any load ops are not LOAD + clear_stencil: u8, // The value to clear the stencil component to at the beginning of the render pass. Ignored if SDL_GPU_LOADOP_CLEAR is not used. + mip_level: u8, // The mip level to use as the depth stencil target. + layer: u8, // The layer index to use as the depth stencil target. +}; + +pub const GPUBlitInfo = extern struct { + source: GPUBlitRegion, // The source region for the blit. + destination: GPUBlitRegion, // The destination region for the blit. + load_op: GPULoadOp, // What is done with the contents of the destination before the blit. + clear_color: FColor, // The color to clear the destination region to before the blit. Ignored if load_op is not SDL_GPU_LOADOP_CLEAR. + flip_mode: FlipMode, // The flip mode for the source region. + filter: GPUFilter, // The filter mode used when blitting. + cycle: bool, // true cycles the destination texture if it is already bound. + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const GPUBufferBinding = extern struct { + buffer: ?*GPUBuffer, // The buffer to bind. Must have been created with SDL_GPU_BUFFERUSAGE_VERTEX for SDL_BindGPUVertexBuffers, or SDL_GPU_BUFFERUSAGE_INDEX for SDL_BindGPUIndexBuffer. + offset: u32, // The starting byte of the data to bind in the buffer. +}; + +pub const GPUTextureSamplerBinding = extern struct { + texture: ?*GPUTexture, // The texture to bind. Must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER. + sampler: ?*GPUSampler, // The sampler to bind. +}; + +pub const GPUStorageBufferReadWriteBinding = extern struct { + buffer: ?*GPUBuffer, // The buffer to bind. Must have been created with SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE. + cycle: bool, // true cycles the buffer if it is already bound. + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub const GPUStorageTextureReadWriteBinding = extern struct { + texture: ?*GPUTexture, // The texture to bind. Must have been created with SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE or SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE. + mip_level: u32, // The mip level index to bind. + layer: u32, // The layer index to bind. + cycle: bool, // true cycles the texture if it is already bound. + padding1: u8, + padding2: u8, + padding3: u8, +}; + +pub inline fn gpuSupportsShaderFormats(format_flags: GPUShaderFormat, name: [*c]const u8) bool { + return @bitCast(c.SDL_GPUSupportsShaderFormats(@bitCast(format_flags), name)); +} + +pub inline fn gpuSupportsProperties(props: PropertiesID) bool { + return @bitCast(c.SDL_GPUSupportsProperties(props)); +} + +pub inline fn createGPUDevice(format_flags: GPUShaderFormat, debug_mode: bool, name: [*c]const u8) ?*GPUDevice { + return @ptrCast(c.SDL_CreateGPUDevice(@bitCast(format_flags), @bitCast(debug_mode), name)); +} + +pub inline fn createGPUDeviceWithProperties(props: PropertiesID) ?*GPUDevice { + return @ptrCast(c.SDL_CreateGPUDeviceWithProperties(props)); +} + +pub const GPUVulkanOptions = extern struct { + vulkan_api_version: u32, // The Vulkan API version to request for the instance. Use Vulkan's VK_MAKE_VERSION or VK_MAKE_API_VERSION. + feature_list: ?*anyopaque, // Pointer to the first element of a chain of Vulkan feature structs. (Requires API version 1.1 or higher.) + vulkan_10_physical_device_features: ?*anyopaque, // Pointer to a VkPhysicalDeviceFeatures struct to enable additional Vulkan 1.0 features. + device_extension_count: u32, // Number of additional device extensions to require. + device_extension_names: [*c][*c]const u8, // Pointer to a list of additional device extensions to require. + instance_extension_count: u32, // Number of additional instance extensions to require. + instance_extension_names: [*c][*c]const u8, // Pointer to a list of additional instance extensions to require. +}; + +pub inline fn getNumGPUDrivers() c_int { + return c.SDL_GetNumGPUDrivers(); +} + +pub inline fn getGPUDriver(index: c_int) [*c]const u8 { + return c.SDL_GetGPUDriver(index); +} + +pub inline fn gpuTextureFormatTexelBlockSize(format: GPUTextureFormat) u32 { + return c.SDL_GPUTextureFormatTexelBlockSize(@bitCast(format)); +} + +pub inline fn calculateGPUTextureFormatSize(format: GPUTextureFormat, width: u32, height: u32, depth_or_layer_count: u32) u32 { + return c.SDL_CalculateGPUTextureFormatSize(@bitCast(format), width, height, depth_or_layer_count); +} + +pub inline fn getPixelFormatFromGPUTextureFormat(format: GPUTextureFormat) PixelFormat { + return @bitCast(c.SDL_GetPixelFormatFromGPUTextureFormat(@bitCast(format))); +} + +pub inline fn getGPUTextureFormatFromPixelFormat(format: PixelFormat) GPUTextureFormat { + return @bitCast(c.SDL_GetGPUTextureFormatFromPixelFormat(@bitCast(format))); +} diff --git a/sdl3-zig/sdl3/haptic.zig b/sdl3-zig/sdl3/haptic.zig new file mode 100644 index 0000000..3861b0d --- /dev/null +++ b/sdl3-zig/sdl3/haptic.zig @@ -0,0 +1,236 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Joystick = opaque { + pub inline fn isJoystickHaptic(joystick: *Joystick) bool { + return @bitCast(c.SDL_IsJoystickHaptic(@ptrCast(joystick))); + } + + pub inline fn openHapticFromJoystick(joystick: *Joystick) ?*Haptic { + return @ptrCast(c.SDL_OpenHapticFromJoystick(@ptrCast(joystick))); + } +}; + +pub const Haptic = opaque { + pub inline fn getHapticID(haptic: *Haptic) HapticID { + return c.SDL_GetHapticID(@ptrCast(haptic)); + } + + pub inline fn getHapticName(haptic: *Haptic) [*c]const u8 { + return c.SDL_GetHapticName(@ptrCast(haptic)); + } + + pub inline fn closeHaptic(haptic: *Haptic) void { + return c.SDL_CloseHaptic(@ptrCast(haptic)); + } + + pub inline fn getMaxHapticEffects(haptic: *Haptic) c_int { + return c.SDL_GetMaxHapticEffects(@ptrCast(haptic)); + } + + pub inline fn getMaxHapticEffectsPlaying(haptic: *Haptic) c_int { + return c.SDL_GetMaxHapticEffectsPlaying(@ptrCast(haptic)); + } + + pub inline fn getHapticFeatures(haptic: *Haptic) u32 { + return c.SDL_GetHapticFeatures(@ptrCast(haptic)); + } + + pub inline fn getNumHapticAxes(haptic: *Haptic) c_int { + return c.SDL_GetNumHapticAxes(@ptrCast(haptic)); + } + + pub inline fn hapticEffectSupported(haptic: *Haptic, effect: *const HapticEffect) bool { + return @bitCast(c.SDL_HapticEffectSupported(@ptrCast(haptic), @ptrCast(effect))); + } + + pub inline fn createHapticEffect(haptic: *Haptic, effect: *const HapticEffect) HapticEffectID { + return c.SDL_CreateHapticEffect(@ptrCast(haptic), @ptrCast(effect)); + } + + pub inline fn updateHapticEffect(haptic: *Haptic, effect: HapticEffectID, data: *const HapticEffect) bool { + return @bitCast(c.SDL_UpdateHapticEffect(@ptrCast(haptic), effect, @ptrCast(data))); + } + + pub inline fn runHapticEffect(haptic: *Haptic, effect: HapticEffectID, iterations: u32) bool { + return @bitCast(c.SDL_RunHapticEffect(@ptrCast(haptic), effect, iterations)); + } + + pub inline fn stopHapticEffect(haptic: *Haptic, effect: HapticEffectID) bool { + return @bitCast(c.SDL_StopHapticEffect(@ptrCast(haptic), effect)); + } + + pub inline fn destroyHapticEffect(haptic: *Haptic, effect: HapticEffectID) void { + return c.SDL_DestroyHapticEffect(@ptrCast(haptic), effect); + } + + pub inline fn getHapticEffectStatus(haptic: *Haptic, effect: HapticEffectID) bool { + return @bitCast(c.SDL_GetHapticEffectStatus(@ptrCast(haptic), effect)); + } + + pub inline fn setHapticGain(haptic: *Haptic, gain: c_int) bool { + return @bitCast(c.SDL_SetHapticGain(@ptrCast(haptic), gain)); + } + + pub inline fn setHapticAutocenter(haptic: *Haptic, autocenter: c_int) bool { + return @bitCast(c.SDL_SetHapticAutocenter(@ptrCast(haptic), autocenter)); + } + + pub inline fn pauseHaptic(haptic: *Haptic) bool { + return @bitCast(c.SDL_PauseHaptic(@ptrCast(haptic))); + } + + pub inline fn resumeHaptic(haptic: *Haptic) bool { + return @bitCast(c.SDL_ResumeHaptic(@ptrCast(haptic))); + } + + pub inline fn stopHapticEffects(haptic: *Haptic) bool { + return @bitCast(c.SDL_StopHapticEffects(@ptrCast(haptic))); + } + + pub inline fn hapticRumbleSupported(haptic: *Haptic) bool { + return @bitCast(c.SDL_HapticRumbleSupported(@ptrCast(haptic))); + } + + pub inline fn initHapticRumble(haptic: *Haptic) bool { + return @bitCast(c.SDL_InitHapticRumble(@ptrCast(haptic))); + } + + pub inline fn playHapticRumble(haptic: *Haptic, strength: f32, length: u32) bool { + return @bitCast(c.SDL_PlayHapticRumble(@ptrCast(haptic), strength, length)); + } + + pub inline fn stopHapticRumble(haptic: *Haptic) bool { + return @bitCast(c.SDL_StopHapticRumble(@ptrCast(haptic))); + } +}; + +pub const HapticEffectType = u16; + +pub const HapticDirectionType = u8; + +pub const HapticEffectID = c_int; + +pub const HapticDirection = extern struct { + _type: HapticDirectionType, // The type of encoding. + dir: [3]i32, // The encoded direction. +}; + +pub const HapticConstant = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_CONSTANT + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + level: i16, // Strength of the constant effect. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticPeriodic = extern struct { + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + period: u16, // Period of the wave. + magnitude: i16, // Peak value; if negative, equivalent to 180 degrees extra phase shift. + offset: i16, // Mean value of the wave. + phase: u16, // Positive phase shift given by hundredth of a degree. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticCondition = extern struct { + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + right_sat: [3]u16, // Level when joystick is to the positive side; max 0xFFFF. + left_sat: [3]u16, // Level when joystick is to the negative side; max 0xFFFF. + right_coeff: [3]i16, // How fast to increase the force towards the positive side. + left_coeff: [3]i16, // How fast to increase the force towards the negative side. + deadband: [3]u16, // Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. + center: [3]i16, // Position of the dead zone. +}; + +pub const HapticRamp = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_RAMP + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + start: i16, // Beginning strength level. + end: i16, // Ending strength level. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticLeftRight = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_LEFTRIGHT + length: u32, // Duration of the effect in milliseconds. + large_magnitude: u16, // Control of the large controller motor. + small_magnitude: u16, // Control of the small controller motor. +}; + +pub const HapticCustom = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_CUSTOM + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + channels: u8, // Axes to use, minimum of one. + period: u16, // Sample periods. + samples: u16, // Amount of samples. + data: *u16, // Should contain channels*samples items. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticEffect = extern union { + _type: HapticEffectType, // Effect type. + constant: HapticConstant, // Constant effect. + periodic: HapticPeriodic, // Periodic effect. + condition: HapticCondition, // Condition effect. + ramp: HapticRamp, // Ramp effect. + leftright: HapticLeftRight, // Left/Right effect. + custom: HapticCustom, // Custom effect. +}; + +pub const HapticID = u32; + +pub inline fn getHaptics(count: *c_int) ?*HapticID { + return @ptrCast(c.SDL_GetHaptics(@ptrCast(count))); +} + +pub inline fn getHapticNameForID(instance_id: HapticID) [*c]const u8 { + return c.SDL_GetHapticNameForID(instance_id); +} + +pub inline fn openHaptic(instance_id: HapticID) ?*Haptic { + return @ptrCast(c.SDL_OpenHaptic(instance_id)); +} + +pub inline fn getHapticFromID(instance_id: HapticID) ?*Haptic { + return @ptrCast(c.SDL_GetHapticFromID(instance_id)); +} + +pub inline fn isMouseHaptic() bool { + return @bitCast(c.SDL_IsMouseHaptic()); +} + +pub inline fn openHapticFromMouse() ?*Haptic { + return @ptrCast(c.SDL_OpenHapticFromMouse()); +} diff --git a/sdl3-zig/sdl3/hints.zig b/sdl3-zig/sdl3/hints.zig new file mode 100644 index 0000000..299b839 --- /dev/null +++ b/sdl3-zig/sdl3/hints.zig @@ -0,0 +1,42 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const HintPriority = enum(c_int) { + hintDefault, + hintNormal, + hintOverride, +}; + +pub inline fn setHintWithPriority(name: [*c]const u8, value: [*c]const u8, priority: HintPriority) bool { + return @bitCast(c.SDL_SetHintWithPriority(name, value, priority)); +} + +pub inline fn setHint(name: [*c]const u8, value: [*c]const u8) bool { + return @bitCast(c.SDL_SetHint(name, value)); +} + +pub inline fn resetHint(name: [*c]const u8) bool { + return @bitCast(c.SDL_ResetHint(name)); +} + +pub inline fn resetHints() void { + return c.SDL_ResetHints(); +} + +pub inline fn getHint(name: [*c]const u8) [*c]const u8 { + return c.SDL_GetHint(name); +} + +pub inline fn getHintBoolean(name: [*c]const u8, default_value: bool) bool { + return @bitCast(c.SDL_GetHintBoolean(name, @bitCast(default_value))); +} + +pub const HintCallback = c.SDL_HintCallback; + +pub inline fn addHintCallback(name: [*c]const u8, callback: HintCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_AddHintCallback(name, callback, userdata)); +} + +pub inline fn removeHintCallback(name: [*c]const u8, callback: HintCallback, userdata: ?*anyopaque) void { + return c.SDL_RemoveHintCallback(name, callback, userdata); +} diff --git a/sdl3-zig/sdl3/init.zig b/sdl3-zig/sdl3/init.zig new file mode 100644 index 0000000..1c0d191 --- /dev/null +++ b/sdl3-zig/sdl3/init.zig @@ -0,0 +1,73 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const InitFlags = packed struct(u32) { + initAudio: bool = false, // `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS` + initVideo: bool = false, // `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS`, should be initialized on the main thread + initJoystick: bool = false, // `SDL_INIT_JOYSTICK` implies `SDL_INIT_EVENTS` + initHaptic: bool = false, + initGamepad: bool = false, // `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` + initEvents: bool = false, + initSensor: bool = false, // `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS` + initCamera: bool = false, // `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS` + pad0: u23 = 0, + rsvd: bool = false, + + pub const None = InitFlags{}; +}; + +pub const AppResult = enum(c_int) { + appContinue, //Value that requests that the app continue from the main callbacks. + appSuccess, //Value that requests termination with success from the main callbacks. + appFailure, //Value that requests termination with error from the main callbacks. +}; + +pub const AppInit_func = c.SDL_AppInit_func; + +pub const AppIterate_func = c.SDL_AppIterate_func; + +pub const AppEvent_func = c.SDL_AppEvent_func; + +pub const AppQuit_func = c.SDL_AppQuit_func; + +pub inline fn init(flags: InitFlags) bool { + return @bitCast(c.SDL_Init(@bitCast(flags))); +} + +pub inline fn initSubSystem(flags: InitFlags) bool { + return @bitCast(c.SDL_InitSubSystem(@bitCast(flags))); +} + +pub inline fn quitSubSystem(flags: InitFlags) void { + return c.SDL_QuitSubSystem(@bitCast(flags)); +} + +pub inline fn wasInit(flags: InitFlags) InitFlags { + return @bitCast(c.SDL_WasInit(@bitCast(flags))); +} + +pub inline fn quit() void { + return c.SDL_Quit(); +} + +pub inline fn isMainThread() bool { + return @bitCast(c.SDL_IsMainThread()); +} + +pub const MainThreadCallback = c.SDL_MainThreadCallback; + +pub inline fn runOnMainThread(callback: MainThreadCallback, userdata: ?*anyopaque, wait_complete: bool) bool { + return @bitCast(c.SDL_RunOnMainThread(callback, userdata, @bitCast(wait_complete))); +} + +pub inline fn setAppMetadata(appname: [*c]const u8, appversion: [*c]const u8, appidentifier: [*c]const u8) bool { + return @bitCast(c.SDL_SetAppMetadata(appname, appversion, appidentifier)); +} + +pub inline fn setAppMetadataProperty(name: [*c]const u8, value: [*c]const u8) bool { + return @bitCast(c.SDL_SetAppMetadataProperty(name, value)); +} + +pub inline fn getAppMetadataProperty(name: [*c]const u8) [*c]const u8 { + return c.SDL_GetAppMetadataProperty(name); +} diff --git a/sdl3-zig/sdl3/joystick.zig b/sdl3-zig/sdl3/joystick.zig new file mode 100644 index 0000000..76a104e --- /dev/null +++ b/sdl3-zig/sdl3/joystick.zig @@ -0,0 +1,322 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const SensorType = enum(c_int) { + sensorInvalid = -1, //Returned for an invalid sensor + sensorUnknown, //Unknown sensor type + sensorAccel, //Accelerometer + sensorGyro, //Gyroscope + sensorAccelL, //Accelerometer for left Joy-Con controller and Wii nunchuk + sensorGyroL, //Gyroscope for left Joy-Con controller + sensorAccelR, //Accelerometer for right Joy-Con controller + sensorGyroR, //Gyroscope for right Joy-Con controller + sensorCount, +}; + +pub const GUID = extern struct { + data: [16]u8, +}; + +pub const PowerState = enum(c_int) { + powerstateError = -1, //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 Joystick = opaque { + pub inline fn setJoystickVirtualAxis(joystick: *Joystick, axis: c_int, value: i16) bool { + return @bitCast(c.SDL_SetJoystickVirtualAxis(@ptrCast(joystick), axis, value)); + } + + pub inline fn setJoystickVirtualBall(joystick: *Joystick, ball: c_int, xrel: i16, yrel: i16) bool { + return @bitCast(c.SDL_SetJoystickVirtualBall(@ptrCast(joystick), ball, xrel, yrel)); + } + + pub inline fn setJoystickVirtualButton(joystick: *Joystick, button: c_int, down: bool) bool { + return @bitCast(c.SDL_SetJoystickVirtualButton(@ptrCast(joystick), button, @bitCast(down))); + } + + pub inline fn setJoystickVirtualHat(joystick: *Joystick, hat: c_int, value: u8) bool { + return @bitCast(c.SDL_SetJoystickVirtualHat(@ptrCast(joystick), hat, value)); + } + + pub inline fn setJoystickVirtualTouchpad(joystick: *Joystick, touchpad: c_int, finger: c_int, down: bool, x: f32, y: f32, pressure: f32) bool { + return @bitCast(c.SDL_SetJoystickVirtualTouchpad(@ptrCast(joystick), touchpad, finger, @bitCast(down), x, y, pressure)); + } + + pub inline fn sendJoystickVirtualSensorData(joystick: *Joystick, _type: SensorType, sensor_timestamp: u64, data: *const f32, num_values: c_int) bool { + return @bitCast(c.SDL_SendJoystickVirtualSensorData(@ptrCast(joystick), @intFromEnum(_type), sensor_timestamp, @ptrCast(data), num_values)); + } + + pub inline fn getJoystickProperties(joystick: *Joystick) PropertiesID { + return c.SDL_GetJoystickProperties(@ptrCast(joystick)); + } + + pub inline fn getJoystickName(joystick: *Joystick) [*c]const u8 { + return c.SDL_GetJoystickName(@ptrCast(joystick)); + } + + pub inline fn getJoystickPath(joystick: *Joystick) [*c]const u8 { + return c.SDL_GetJoystickPath(@ptrCast(joystick)); + } + + pub inline fn getJoystickPlayerIndex(joystick: *Joystick) c_int { + return c.SDL_GetJoystickPlayerIndex(@ptrCast(joystick)); + } + + pub inline fn setJoystickPlayerIndex(joystick: *Joystick, player_index: c_int) bool { + return @bitCast(c.SDL_SetJoystickPlayerIndex(@ptrCast(joystick), player_index)); + } + + pub inline fn getJoystickGUID(joystick: *Joystick) GUID { + return c.SDL_GetJoystickGUID(@ptrCast(joystick)); + } + + pub inline fn getJoystickVendor(joystick: *Joystick) u16 { + return c.SDL_GetJoystickVendor(@ptrCast(joystick)); + } + + pub inline fn getJoystickProduct(joystick: *Joystick) u16 { + return c.SDL_GetJoystickProduct(@ptrCast(joystick)); + } + + pub inline fn getJoystickProductVersion(joystick: *Joystick) u16 { + return c.SDL_GetJoystickProductVersion(@ptrCast(joystick)); + } + + pub inline fn getJoystickFirmwareVersion(joystick: *Joystick) u16 { + return c.SDL_GetJoystickFirmwareVersion(@ptrCast(joystick)); + } + + pub inline fn getJoystickSerial(joystick: *Joystick) [*c]const u8 { + return c.SDL_GetJoystickSerial(@ptrCast(joystick)); + } + + pub inline fn getJoystickType(joystick: *Joystick) JoystickType { + return @intFromEnum(c.SDL_GetJoystickType(@ptrCast(joystick))); + } + + pub inline fn joystickConnected(joystick: *Joystick) bool { + return @bitCast(c.SDL_JoystickConnected(@ptrCast(joystick))); + } + + pub inline fn getJoystickID(joystick: *Joystick) JoystickID { + return c.SDL_GetJoystickID(@ptrCast(joystick)); + } + + pub inline fn getNumJoystickAxes(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickAxes(@ptrCast(joystick)); + } + + pub inline fn getNumJoystickBalls(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickBalls(@ptrCast(joystick)); + } + + pub inline fn getNumJoystickHats(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickHats(@ptrCast(joystick)); + } + + pub inline fn getNumJoystickButtons(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickButtons(@ptrCast(joystick)); + } + + pub inline fn getJoystickAxis(joystick: *Joystick, axis: c_int) i16 { + return c.SDL_GetJoystickAxis(@ptrCast(joystick), axis); + } + + pub inline fn getJoystickAxisInitialState(joystick: *Joystick, axis: c_int, state: *i16) bool { + return @bitCast(c.SDL_GetJoystickAxisInitialState(@ptrCast(joystick), axis, @ptrCast(state))); + } + + pub inline fn getJoystickBall(joystick: *Joystick, ball: c_int, dx: *c_int, dy: *c_int) bool { + return @bitCast(c.SDL_GetJoystickBall(@ptrCast(joystick), ball, @ptrCast(dx), @ptrCast(dy))); + } + + pub inline fn getJoystickHat(joystick: *Joystick, hat: c_int) u8 { + return c.SDL_GetJoystickHat(@ptrCast(joystick), hat); + } + + pub inline fn getJoystickButton(joystick: *Joystick, button: c_int) bool { + return @bitCast(c.SDL_GetJoystickButton(@ptrCast(joystick), button)); + } + + pub inline fn rumbleJoystick(joystick: *Joystick, low_frequency_rumble: u16, high_frequency_rumble: u16, duration_ms: u32) bool { + return @bitCast(c.SDL_RumbleJoystick(@ptrCast(joystick), low_frequency_rumble, high_frequency_rumble, duration_ms)); + } + + pub inline fn rumbleJoystickTriggers(joystick: *Joystick, left_rumble: u16, right_rumble: u16, duration_ms: u32) bool { + return @bitCast(c.SDL_RumbleJoystickTriggers(@ptrCast(joystick), left_rumble, right_rumble, duration_ms)); + } + + pub inline fn setJoystickLED(joystick: *Joystick, red: u8, green: u8, blue: u8) bool { + return @bitCast(c.SDL_SetJoystickLED(@ptrCast(joystick), red, green, blue)); + } + + pub inline fn sendJoystickEffect(joystick: *Joystick, data: ?*const anyopaque, size: c_int) bool { + return @bitCast(c.SDL_SendJoystickEffect(@ptrCast(joystick), data, size)); + } + + pub inline fn closeJoystick(joystick: *Joystick) void { + return c.SDL_CloseJoystick(@ptrCast(joystick)); + } + + pub inline fn getJoystickConnectionState(joystick: *Joystick) JoystickConnectionState { + return c.SDL_GetJoystickConnectionState(@ptrCast(joystick)); + } + + pub inline fn getJoystickPowerInfo(joystick: *Joystick, percent: *c_int) PowerState { + return c.SDL_GetJoystickPowerInfo(@ptrCast(joystick), @ptrCast(percent)); + } +}; + +pub const JoystickID = u32; + +pub const JoystickType = enum(c_int) { + joystickTypeUnknown, + joystickTypeGamepad, + joystickTypeWheel, + joystickTypeArcadeStick, + joystickTypeFlightStick, + joystickTypeDancePad, + joystickTypeGuitar, + joystickTypeDrumKit, + joystickTypeArcadePad, + joystickTypeThrottle, + joystickTypeCount, +}; + +pub const JoystickConnectionState = enum(c_int) { + joystickConnectionUnknown, + joystickConnectionWired, + joystickConnectionWireless, +}; + +pub inline fn lockJoysticks() void { + return c.SDL_LockJoysticks(); +} + +pub inline fn unlockJoysticks() void { + return c.SDL_UnlockJoysticks(); +} + +pub inline fn hasJoystick() bool { + return @bitCast(c.SDL_HasJoystick()); +} + +pub inline fn getJoysticks(count: *c_int) ?*JoystickID { + return @ptrCast(c.SDL_GetJoysticks(@ptrCast(count))); +} + +pub inline fn getJoystickNameForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetJoystickNameForID(instance_id); +} + +pub inline fn getJoystickPathForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetJoystickPathForID(instance_id); +} + +pub inline fn getJoystickPlayerIndexForID(instance_id: JoystickID) c_int { + return c.SDL_GetJoystickPlayerIndexForID(instance_id); +} + +pub inline fn getJoystickGUIDForID(instance_id: JoystickID) GUID { + return c.SDL_GetJoystickGUIDForID(instance_id); +} + +pub inline fn getJoystickVendorForID(instance_id: JoystickID) u16 { + return c.SDL_GetJoystickVendorForID(instance_id); +} + +pub inline fn getJoystickProductForID(instance_id: JoystickID) u16 { + return c.SDL_GetJoystickProductForID(instance_id); +} + +pub inline fn getJoystickProductVersionForID(instance_id: JoystickID) u16 { + return c.SDL_GetJoystickProductVersionForID(instance_id); +} + +pub inline fn getJoystickTypeForID(instance_id: JoystickID) JoystickType { + return @intFromEnum(c.SDL_GetJoystickTypeForID(instance_id)); +} + +pub inline fn openJoystick(instance_id: JoystickID) ?*Joystick { + return @ptrCast(c.SDL_OpenJoystick(instance_id)); +} + +pub inline fn getJoystickFromID(instance_id: JoystickID) ?*Joystick { + return @ptrCast(c.SDL_GetJoystickFromID(instance_id)); +} + +pub inline fn getJoystickFromPlayerIndex(player_index: c_int) ?*Joystick { + return @ptrCast(c.SDL_GetJoystickFromPlayerIndex(player_index)); +} + +pub const VirtualJoystickTouchpadDesc = extern struct { + nfingers: u16, // the number of simultaneous fingers on this touchpad + padding: [3]u16, +}; + +pub const VirtualJoystickSensorDesc = extern struct { + _type: SensorType, // the type of this sensor + rate: f32, // the update frequency of this sensor, may be 0.0f +}; + +pub const VirtualJoystickDesc = extern struct { + version: u32, // the version of this interface + _type: u16, // `SDL_JoystickType` + padding: u16, // unused + vendor_id: u16, // the USB vendor ID of this joystick + product_id: u16, // the USB product ID of this joystick + naxes: u16, // the number of axes on this joystick + nbuttons: u16, // the number of buttons on this joystick + nballs: u16, // the number of balls on this joystick + nhats: u16, // the number of hats on this joystick + ntouchpads: u16, // the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions + nsensors: u16, // the number of sensors on this joystick, requires `sensors` to point at valid descriptions + padding2: [2]u16, // unused + name: [*c]const u8, // the name of the joystick + touchpads: *const VirtualJoystickTouchpadDesc, // A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 + sensors: *const VirtualJoystickSensorDesc, // A pointer to an array of sensor descriptions, required if `nsensors` is > 0 + userdata: ?*anyopaque, // User data pointer passed to callbacks + Update: ?*const anyopaque, // Called when the joystick state should be updated + SetPlayerIndex: ?*const anyopaque, // Called when the player index is set + Rumble: ?*const anyopaque, // Implements SDL_RumbleJoystick() + RumbleTriggers: ?*const anyopaque, // Implements SDL_RumbleJoystickTriggers() + SetLED: ?*const anyopaque, // Implements SDL_SetJoystickLED() + SendEffect: ?*const anyopaque, // Implements SDL_SendJoystickEffect() + SetSensorsEnabled: ?*const anyopaque, // Implements SDL_SetGamepadSensorEnabled() + Cleanup: ?*const anyopaque, // Cleans up the userdata when the joystick is detached +}; + +pub inline fn attachVirtualJoystick(desc: *const VirtualJoystickDesc) JoystickID { + return c.SDL_AttachVirtualJoystick(@ptrCast(desc)); +} + +pub inline fn detachVirtualJoystick(instance_id: JoystickID) bool { + return @bitCast(c.SDL_DetachVirtualJoystick(instance_id)); +} + +pub inline fn isJoystickVirtual(instance_id: JoystickID) bool { + return @bitCast(c.SDL_IsJoystickVirtual(instance_id)); +} + +pub inline fn getJoystickGUIDInfo(guid: GUID, vendor: *u16, product: *u16, version: *u16, crc16: *u16) void { + return c.SDL_GetJoystickGUIDInfo(guid, @ptrCast(vendor), @ptrCast(product), @ptrCast(version), @ptrCast(crc16)); +} + +pub inline fn setJoystickEventsEnabled(enabled: bool) void { + return c.SDL_SetJoystickEventsEnabled(@bitCast(enabled)); +} + +pub inline fn joystickEventsEnabled() bool { + return @bitCast(c.SDL_JoystickEventsEnabled()); +} + +pub inline fn updateJoysticks() void { + return c.SDL_UpdateJoysticks(); +} diff --git a/sdl3-zig/sdl3/keycode.zig b/sdl3-zig/sdl3/keycode.zig new file mode 100644 index 0000000..d0aaa55 --- /dev/null +++ b/sdl3-zig/sdl3/keycode.zig @@ -0,0 +1,6 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Keycode = u32; + +pub const Keymod = u16; diff --git a/sdl3-zig/sdl3/loadso.zig b/sdl3-zig/sdl3/loadso.zig new file mode 100644 index 0000000..3a056bd --- /dev/null +++ b/sdl3-zig/sdl3/loadso.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const FunctionPointer = c.SDL_FunctionPointer; + +pub const SharedObject = opaque { + pub inline fn loadFunction(sharedobject: *SharedObject, name: [*c]const u8) FunctionPointer { + return c.SDL_LoadFunction(@ptrCast(sharedobject), name); + } + + pub inline fn unloadObject(sharedobject: *SharedObject) void { + return c.SDL_UnloadObject(@ptrCast(sharedobject)); + } +}; + +pub inline fn loadObject(sofile: [*c]const u8) ?*SharedObject { + return @ptrCast(c.SDL_LoadObject(sofile)); +} diff --git a/sdl3-zig/sdl3/messagebox.zig b/sdl3-zig/sdl3/messagebox.zig new file mode 100644 index 0000000..52326bc --- /dev/null +++ b/sdl3-zig/sdl3/messagebox.zig @@ -0,0 +1,68 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque {}; + +pub const MessageBoxFlags = packed struct(u32) { + messageboxError: bool = false, // error dialog + messageboxWarning: bool = false, // warning dialog + messageboxInformation: bool = false, // informational dialog + messageboxButtonsLeftToRight: bool = false, // buttons placed left to right + messageboxButtonsRightToLeft: bool = false, // buttons placed right to left + pad0: u26 = 0, + rsvd: bool = false, + + pub const None = MessageBoxFlags{}; +}; + +pub const MessageBoxButtonFlags = packed struct(u32) { + messageboxButtonReturnkeyDefault: bool = false, // Marks the default button when return is hit + messageboxButtonEscapekeyDefault: bool = false, // Marks the default button when escape is hit + pad0: u29 = 0, + rsvd: bool = false, + + pub const None = MessageBoxButtonFlags{}; +}; + +pub const MessageBoxButtonData = extern struct { + flags: MessageBoxButtonFlags, + buttonID: c_int, // User defined button id (value returned via SDL_ShowMessageBox) + text: [*c]const u8, // The UTF-8 button text +}; + +pub const MessageBoxColor = extern struct { + r: u8, + g: u8, + b: u8, +}; + +pub const MessageBoxColorType = enum(c_int) { + messageboxColorBackground, + messageboxColorText, + messageboxColorButtonBorder, + messageboxColorButtonBackground, + messageboxColorButtonSelected, + messageboxColorCount, //Size of the colors array of SDL_MessageBoxColorScheme. +}; + +pub const MessageBoxColorScheme = extern struct { + colors: [c.SDL_MESSAGEBOX_COLOR_COUNT]MessageBoxColor, +}; + +pub const MessageBoxData = extern struct { + flags: MessageBoxFlags, + window: ?*Window, // Parent window, can be NULL + title: [*c]const u8, // UTF-8 title + message: [*c]const u8, // UTF-8 message text + numbuttons: c_int, + buttons: *const MessageBoxButtonData, + colorScheme: *const MessageBoxColorScheme, // SDL_MessageBoxColorScheme, can be NULL to use system settings +}; + +pub inline fn showMessageBox(messageboxdata: *const MessageBoxData, buttonid: *c_int) bool { + return @bitCast(c.SDL_ShowMessageBox(@ptrCast(messageboxdata), @ptrCast(buttonid))); +} + +pub inline fn showSimpleMessageBox(flags: MessageBoxFlags, title: [*c]const u8, message: [*c]const u8, window: ?*Window) bool { + return @bitCast(c.SDL_ShowSimpleMessageBox(@bitCast(flags), title, message, @ptrCast(window))); +} diff --git a/sdl3-zig/sdl3/misc.zig b/sdl3-zig/sdl3/misc.zig new file mode 100644 index 0000000..189a0fa --- /dev/null +++ b/sdl3-zig/sdl3/misc.zig @@ -0,0 +1,6 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn openURL(url: [*c]const u8) bool { + return @bitCast(c.SDL_OpenURL(url)); +} diff --git a/sdl3-zig/sdl3/mouse.zig b/sdl3-zig/sdl3/mouse.zig new file mode 100644 index 0000000..02b4373 --- /dev/null +++ b/sdl3-zig/sdl3/mouse.zig @@ -0,0 +1,152 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque { + pub inline fn warpMouseInWindow(window: *Window, x: f32, y: f32) void { + return c.SDL_WarpMouseInWindow(@ptrCast(window), x, y); + } + + pub inline fn setWindowRelativeMouseMode(window: *Window, enabled: bool) bool { + return @bitCast(c.SDL_SetWindowRelativeMouseMode(@ptrCast(window), @bitCast(enabled))); + } + + pub inline fn getWindowRelativeMouseMode(window: *Window) bool { + return @bitCast(c.SDL_GetWindowRelativeMouseMode(@ptrCast(window))); + } +}; + +pub const Surface = opaque { + pub inline fn createColorCursor(surface: *Surface, hot_x: c_int, hot_y: c_int) ?*Cursor { + return @ptrCast(c.SDL_CreateColorCursor(@ptrCast(surface), hot_x, hot_y)); + } +}; + +pub const MouseID = u32; + +pub const Cursor = opaque { + pub inline fn setCursor(cursor: *Cursor) bool { + return @bitCast(c.SDL_SetCursor(@ptrCast(cursor))); + } + + pub inline fn destroyCursor(cursor: *Cursor) void { + return c.SDL_DestroyCursor(@ptrCast(cursor)); + } +}; + +pub const SystemCursor = enum(c_int) { + systemCursorDefault, //Default cursor. Usually an arrow. + systemCursorText, //Text selection. Usually an I-beam. + systemCursorWait, //Wait. Usually an hourglass or watch or spinning ball. + systemCursorCrosshair, //Crosshair. + systemCursorProgress, //Program is busy but still interactive. Usually it's WAIT with an arrow. + systemCursorNwseResize, //Double arrow pointing northwest and southeast. + systemCursorNeswResize, //Double arrow pointing northeast and southwest. + systemCursorEwResize, //Double arrow pointing west and east. + systemCursorNsResize, //Double arrow pointing north and south. + systemCursorMove, //Four pointed arrow pointing north, south, east, and west. + systemCursorNotAllowed, //Not permitted. Usually a slashed circle or crossbones. + systemCursorPointer, //Pointer that indicates a link. Usually a pointing hand. + systemCursorNwResize, //Window resize top-left. This may be a single arrow or a double arrow like NWSE_RESIZE. + systemCursorNResize, //Window resize top. May be NS_RESIZE. + systemCursorNeResize, //Window resize top-right. May be NESW_RESIZE. + systemCursorEResize, //Window resize right. May be EW_RESIZE. + systemCursorSeResize, //Window resize bottom-right. May be NWSE_RESIZE. + systemCursorSResize, //Window resize bottom. May be NS_RESIZE. + systemCursorSwResize, //Window resize bottom-left. May be NESW_RESIZE. + systemCursorWResize, //Window resize left. May be EW_RESIZE. + systemCursorCount, +}; + +pub const MouseWheelDirection = enum(c_int) { + mousewheelNormal, //The scroll direction is normal + mousewheelFlipped, //The scroll direction is flipped / natural +}; + +pub const CursorFrameInfo = extern struct { + surface: ?*Surface, // The surface data for this frame + duration: u32, // The frame duration in milliseconds (a duration of 0 is infinite) +}; + +pub const MouseButtonFlags = packed struct(u32) { + buttonLeft: bool = false, + buttonMiddle: bool = false, + buttonX1: bool = false, + pad0: u28 = 0, + rsvd: bool = false, + + pub const None = MouseButtonFlags{}; +}; + +pub const MouseMotionTransformCallback = c.SDL_MouseMotionTransformCallback; + +pub inline fn hasMouse() bool { + return @bitCast(c.SDL_HasMouse()); +} + +pub inline fn getMice(count: *c_int) ?*MouseID { + return @ptrCast(c.SDL_GetMice(@ptrCast(count))); +} + +pub inline fn getMouseNameForID(instance_id: MouseID) [*c]const u8 { + return c.SDL_GetMouseNameForID(instance_id); +} + +pub inline fn getMouseFocus() ?*Window { + return @ptrCast(c.SDL_GetMouseFocus()); +} + +pub inline fn getMouseState(x: *f32, y: *f32) MouseButtonFlags { + return @bitCast(c.SDL_GetMouseState(@ptrCast(x), @ptrCast(y))); +} + +pub inline fn getGlobalMouseState(x: *f32, y: *f32) MouseButtonFlags { + return @bitCast(c.SDL_GetGlobalMouseState(@ptrCast(x), @ptrCast(y))); +} + +pub inline fn getRelativeMouseState(x: *f32, y: *f32) MouseButtonFlags { + return @bitCast(c.SDL_GetRelativeMouseState(@ptrCast(x), @ptrCast(y))); +} + +pub inline fn warpMouseGlobal(x: f32, y: f32) bool { + return @bitCast(c.SDL_WarpMouseGlobal(x, y)); +} + +pub inline fn setRelativeMouseTransform(callback: MouseMotionTransformCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_SetRelativeMouseTransform(callback, userdata)); +} + +pub inline fn captureMouse(enabled: bool) bool { + return @bitCast(c.SDL_CaptureMouse(@bitCast(enabled))); +} + +pub inline fn createCursor(data: [*c]const u8, mask: [*c]const u8, w: c_int, h: c_int, hot_x: c_int, hot_y: c_int) ?*Cursor { + return @ptrCast(c.SDL_CreateCursor(data, mask, w, h, hot_x, hot_y)); +} + +pub inline fn createAnimatedCursor(frames: ?*CursorFrameInfo, frame_count: c_int, hot_x: c_int, hot_y: c_int) ?*Cursor { + return @ptrCast(c.SDL_CreateAnimatedCursor(@ptrCast(frames), frame_count, hot_x, hot_y)); +} + +pub inline fn createSystemCursor(id: SystemCursor) ?*Cursor { + return @ptrCast(c.SDL_CreateSystemCursor(id)); +} + +pub inline fn getCursor() ?*Cursor { + return @ptrCast(c.SDL_GetCursor()); +} + +pub inline fn getDefaultCursor() ?*Cursor { + return @ptrCast(c.SDL_GetDefaultCursor()); +} + +pub inline fn showCursor() bool { + return @bitCast(c.SDL_ShowCursor()); +} + +pub inline fn hideCursor() bool { + return @bitCast(c.SDL_HideCursor()); +} + +pub inline fn cursorVisible() bool { + return @bitCast(c.SDL_CursorVisible()); +} diff --git a/sdl3-zig/sdl3/pixels.zig b/sdl3-zig/sdl3/pixels.zig new file mode 100644 index 0000000..e47c912 --- /dev/null +++ b/sdl3-zig/sdl3/pixels.zig @@ -0,0 +1,239 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PixelType = enum(c_int) { + pixeltypeUnknown, + pixeltypeIndex1, + pixeltypeIndex4, + pixeltypeIndex8, + pixeltypePacked8, + pixeltypePacked16, + pixeltypePacked32, + pixeltypeArrayu8, + pixeltypeArrayu16, + pixeltypeArrayu32, + pixeltypeArrayf16, + pixeltypeArrayf32, + pixeltypeIndex2, +}; + +pub const BitmapOrder = enum(c_int) { + bitmaporderNone, + bitmaporder4321, + bitmaporder1234, +}; + +pub const PackedOrder = enum(c_int) { + packedorderNone, + packedorderXrgb, + packedorderRgbx, + packedorderArgb, + packedorderRgba, + packedorderXbgr, + packedorderBgrx, + packedorderAbgr, + packedorderBgra, +}; + +pub const ArrayOrder = enum(c_int) { + arrayorderNone, + arrayorderRgb, + arrayorderRgba, + arrayorderArgb, + arrayorderBgr, + arrayorderBgra, + arrayorderAbgr, +}; + +pub const PackedLayout = enum(c_int) { + packedlayoutNone, + packedlayout332, + packedlayout4444, + packedlayout1555, + packedlayout5551, + packedlayout565, + packedlayout8888, + packedlayout2101010, + packedlayout1010102, +}; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12 = 0x32315659, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv = 0x56555949, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2 = 0x32595559, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy = 0x59565955, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu = 0x55595659, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12 = 0x3231564e, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21 = 0x3132564e, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010 = 0x30313050, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes = 0x2053454f, //Android video texture format + pixelformatMjpg = 0x47504a4d, //Motion JPEG +}; + +pub const ColorRange = enum(c_int) { + colorRangeLimited = 1, //Narrow range, e.g. 16-235 for 8-bit RGB and luma, and 16-240 for 8-bit chroma + colorRangeFull = 2, +}; + +pub const ColorPrimaries = enum(c_int) { + colorPrimariesBt709 = 1, //ITU-R BT.709-6 + colorPrimariesBt470m = 4, //ITU-R BT.470-6 System M + colorPrimariesBt470bg = 5, //ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625 + colorPrimariesBt601 = 6, //ITU-R BT.601-7 525, SMPTE 170M + colorPrimariesSmpte240 = 7, //SMPTE 240M, functionally the same as SDL_COLOR_PRIMARIES_BT601 + colorPrimariesGenericFilm = 8, //Generic film (color filters using Illuminant C) + colorPrimariesBt2020 = 9, //ITU-R BT.2020-2 / ITU-R BT.2100-0 + colorPrimariesXyz = 10, //SMPTE ST 428-1 + colorPrimariesSmpte431 = 11, //SMPTE RP 431-2 + colorPrimariesSmpte432 = 12, //SMPTE EG 432-1 / DCI P3 + colorPrimariesEbu3213 = 22, //EBU Tech. 3213-E +}; + +pub const TransferCharacteristics = enum(c_int) { + transferCharacteristicsBt709 = 1, //Rec. ITU-R BT.709-6 / ITU-R BT1361 + transferCharacteristicsGamma22 = 4, //ITU-R BT.470-6 System M / ITU-R BT1700 625 PAL & SECAM + transferCharacteristicsGamma28 = 5, //ITU-R BT.470-6 System B, G + transferCharacteristicsBt601 = 6, //SMPTE ST 170M / ITU-R BT.601-7 525 or 625 + transferCharacteristicsSmpte240 = 7, //SMPTE ST 240M + transferCharacteristicsIec61966 = 11, //IEC 61966-2-4 + transferCharacteristicsBt1361 = 12, //ITU-R BT1361 Extended Colour Gamut + transferCharacteristicsSrgb = 13, //IEC 61966-2-1 (sRGB or sYCC) + transferCharacteristicsBt202010bit = 14, //ITU-R BT2020 for 10-bit system + transferCharacteristicsBt202012bit = 15, //ITU-R BT2020 for 12-bit system + transferCharacteristicsPq = 16, //SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems + transferCharacteristicsSmpte428 = 17, //SMPTE ST 428-1 + transferCharacteristicsHlg = 18, //ARIB STD-B67, known as "hybrid log-gamma" (HLG) +}; + +pub const MatrixCoefficients = enum(c_int) { + matrixCoefficientsBt709 = 1, //ITU-R BT.709-6 + matrixCoefficientsFcc = 4, //US FCC Title 47 + matrixCoefficientsBt470bg = 5, //ITU-R BT.470-6 System B, G / ITU-R BT.601-7 625, functionally the same as SDL_MATRIX_COEFFICIENTS_BT601 + matrixCoefficientsBt601 = 6, //ITU-R BT.601-7 525 + matrixCoefficientsSmpte240 = 7, //SMPTE 240M + matrixCoefficientsBt2020Ncl = 9, //ITU-R BT.2020-2 non-constant luminance + matrixCoefficientsBt2020Cl = 10, //ITU-R BT.2020-2 constant luminance + matrixCoefficientsSmpte2085 = 11, //SMPTE ST 2085 + matrixCoefficientsIctcp = 14, //ITU-R BT.2100-0 ICTCP +}; + +pub const ChromaLocation = enum(c_int) { + chromaLocationNone = 0, //RGB, no chroma sampling + chromaLocationLeft = 1, //In MPEG-2, MPEG-4, and AVC, Cb and Cr are taken on midpoint of the left-edge of the 2x2 square. In other words, they have the same horizontal location as the top-left pixel, but is shifted one-half pixel down vertically. + chromaLocationCenter = 2, //In JPEG/JFIF, H.261, and MPEG-1, Cb and Cr are taken at the center of the 2x2 square. In other words, they are offset one-half pixel to the right and one-half pixel down compared to the top-left pixel. + chromaLocationTopleft = 3, +}; + +pub const Colorspace = enum(c_int) { + colorspaceSrgb = 0x120005a0, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 + colorRangeFull, + colorPrimariesBt709, + transferCharacteristicsSrgb, + matrixCoefficientsIdentity, + colorspaceSrgbLinear = 0x12000500, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 + transferCharacteristicsLinear, + colorspaceHdr10 = 0x12002600, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 + colorPrimariesBt2020, + transferCharacteristicsPq, + colorspaceJpeg = 0x220004c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 + transferCharacteristicsBt601, + matrixCoefficientsBt601, + colorspaceBt601Limited = 0x211018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorRangeLimited, + colorPrimariesBt601, + colorspaceBt601Full = 0x221018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorspaceBt709Limited = 0x21100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + transferCharacteristicsBt709, + matrixCoefficientsBt709, + colorspaceBt709Full = 0x22100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + colorspaceBt2020Limited = 0x21102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 + matrixCoefficientsBt2020Ncl, + colorspaceBt2020Full = 0x22102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 + + pub const colorspaceRgbDefault = .colorspaceSrgb; //The default colorspace for RGB surfaces if no colorspace is specified + pub const colorspaceYuvDefault = .colorspaceBt601Limited; //The default colorspace for YUV surfaces if no colorspace is specified +}; + +pub const Color = extern struct { + r: u8, + g: u8, + b: u8, + a: u8, +}; + +pub const FColor = extern struct { + r: f32, + g: f32, + b: f32, + a: f32, +}; + +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 PixelFormatDetails = extern struct { + format: PixelFormat, + bits_per_pixel: u8, + bytes_per_pixel: u8, + padding: [2]u8, + Rmask: u32, + Gmask: u32, + Bmask: u32, + Amask: u32, + Rbits: u8, + Gbits: u8, + Bbits: u8, + Abits: u8, + Rshift: u8, + Gshift: u8, + Bshift: u8, + Ashift: u8, +}; + +pub inline fn getPixelFormatName(format: PixelFormat) [*c]const u8 { + return c.SDL_GetPixelFormatName(@bitCast(format)); +} + +pub inline fn getMasksForPixelFormat(format: PixelFormat, bpp: *c_int, Rmask: *u32, Gmask: *u32, Bmask: *u32, Amask: *u32) bool { + return @bitCast(c.SDL_GetMasksForPixelFormat(@bitCast(format), @ptrCast(bpp), @ptrCast(Rmask), @ptrCast(Gmask), @ptrCast(Bmask), @ptrCast(Amask))); +} + +pub inline fn getPixelFormatForMasks(bpp: c_int, Rmask: u32, Gmask: u32, Bmask: u32, Amask: u32) PixelFormat { + return @bitCast(c.SDL_GetPixelFormatForMasks(bpp, Rmask, Gmask, Bmask, Amask)); +} + +pub inline fn getPixelFormatDetails(format: PixelFormat) *const PixelFormatDetails { + return @ptrCast(c.SDL_GetPixelFormatDetails(@bitCast(format))); +} + +pub inline fn createPalette(ncolors: c_int) ?*Palette { + return @ptrCast(c.SDL_CreatePalette(ncolors)); +} + +pub inline fn setPaletteColors(palette: ?*Palette, colors: *const Color, firstcolor: c_int, ncolors: c_int) bool { + return @bitCast(c.SDL_SetPaletteColors(@ptrCast(palette), @ptrCast(colors), firstcolor, ncolors)); +} + +pub inline fn destroyPalette(palette: ?*Palette) void { + return c.SDL_DestroyPalette(@ptrCast(palette)); +} + +pub inline fn mapRGB(format: *const PixelFormatDetails, palette: *const Palette, r: u8, g: u8, b: u8) u32 { + return c.SDL_MapRGB(@ptrCast(format), @ptrCast(palette), r, g, b); +} + +pub inline fn mapRGBA(format: *const PixelFormatDetails, palette: *const Palette, r: u8, g: u8, b: u8, a: u8) u32 { + return c.SDL_MapRGBA(@ptrCast(format), @ptrCast(palette), r, g, b, a); +} + +pub inline fn getRGB(pixelvalue: u32, format: *const PixelFormatDetails, palette: *const Palette, r: [*c]u8, g: [*c]u8, b: [*c]u8) void { + return c.SDL_GetRGB(pixelvalue, @ptrCast(format), @ptrCast(palette), r, g, b); +} + +pub inline fn getRGBA(pixelvalue: u32, format: *const PixelFormatDetails, palette: *const Palette, r: [*c]u8, g: [*c]u8, b: [*c]u8, a: [*c]u8) void { + return c.SDL_GetRGBA(pixelvalue, @ptrCast(format), @ptrCast(palette), r, g, b, a); +} diff --git a/sdl3-zig/sdl3/properties.zig b/sdl3-zig/sdl3/properties.zig new file mode 100644 index 0000000..84fae79 --- /dev/null +++ b/sdl3-zig/sdl3/properties.zig @@ -0,0 +1,101 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const PropertyType = enum(c_int) { + propertyTypeInvalid, + propertyTypePointer, + propertyTypeString, + propertyTypeNumber, + propertyTypeFloat, + propertyTypeBoolean, +}; + +pub inline fn getGlobalProperties() PropertiesID { + return c.SDL_GetGlobalProperties(); +} + +pub inline fn createProperties() PropertiesID { + return c.SDL_CreateProperties(); +} + +pub inline fn copyProperties(src: PropertiesID, dst: PropertiesID) bool { + return @bitCast(c.SDL_CopyProperties(src, dst)); +} + +pub inline fn lockProperties(props: PropertiesID) bool { + return @bitCast(c.SDL_LockProperties(props)); +} + +pub inline fn unlockProperties(props: PropertiesID) void { + return c.SDL_UnlockProperties(props); +} + +pub const CleanupPropertyCallback = c.SDL_CleanupPropertyCallback; + +pub inline fn setPointerPropertyWithCleanup(props: PropertiesID, name: [*c]const u8, value: ?*anyopaque, cleanup: CleanupPropertyCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata)); +} + +pub inline fn setPointerProperty(props: PropertiesID, name: [*c]const u8, value: ?*anyopaque) bool { + return @bitCast(c.SDL_SetPointerProperty(props, name, value)); +} + +pub inline fn setStringProperty(props: PropertiesID, name: [*c]const u8, value: [*c]const u8) bool { + return @bitCast(c.SDL_SetStringProperty(props, name, value)); +} + +pub inline fn setNumberProperty(props: PropertiesID, name: [*c]const u8, value: i64) bool { + return @bitCast(c.SDL_SetNumberProperty(props, name, value)); +} + +pub inline fn setFloatProperty(props: PropertiesID, name: [*c]const u8, value: f32) bool { + return @bitCast(c.SDL_SetFloatProperty(props, name, value)); +} + +pub inline fn setBooleanProperty(props: PropertiesID, name: [*c]const u8, value: bool) bool { + return @bitCast(c.SDL_SetBooleanProperty(props, name, @bitCast(value))); +} + +pub inline fn hasProperty(props: PropertiesID, name: [*c]const u8) bool { + return @bitCast(c.SDL_HasProperty(props, name)); +} + +pub inline fn getPropertyType(props: PropertiesID, name: [*c]const u8) PropertyType { + return @intFromEnum(c.SDL_GetPropertyType(props, name)); +} + +pub inline fn getPointerProperty(props: PropertiesID, name: [*c]const u8, default_value: ?*anyopaque) ?*anyopaque { + return c.SDL_GetPointerProperty(props, name, default_value); +} + +pub inline fn getStringProperty(props: PropertiesID, name: [*c]const u8, default_value: [*c]const u8) [*c]const u8 { + return c.SDL_GetStringProperty(props, name, default_value); +} + +pub inline fn getNumberProperty(props: PropertiesID, name: [*c]const u8, default_value: i64) i64 { + return c.SDL_GetNumberProperty(props, name, default_value); +} + +pub inline fn getFloatProperty(props: PropertiesID, name: [*c]const u8, default_value: f32) f32 { + return c.SDL_GetFloatProperty(props, name, default_value); +} + +pub inline fn getBooleanProperty(props: PropertiesID, name: [*c]const u8, default_value: bool) bool { + return @bitCast(c.SDL_GetBooleanProperty(props, name, @bitCast(default_value))); +} + +pub inline fn clearProperty(props: PropertiesID, name: [*c]const u8) bool { + return @bitCast(c.SDL_ClearProperty(props, name)); +} + +pub const EnumeratePropertiesCallback = c.SDL_EnumeratePropertiesCallback; + +pub inline fn enumerateProperties(props: PropertiesID, callback: EnumeratePropertiesCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_EnumerateProperties(props, callback, userdata)); +} + +pub inline fn destroyProperties(props: PropertiesID) void { + return c.SDL_DestroyProperties(props); +} diff --git a/sdl3-zig/sdl3/rect.zig b/sdl3-zig/sdl3/rect.zig new file mode 100644 index 0000000..04637ec --- /dev/null +++ b/sdl3-zig/sdl3/rect.zig @@ -0,0 +1,66 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Point = extern struct { + x: c_int, + y: c_int, +}; + +pub const FPoint = extern struct { + x: f32, + y: f32, +}; + +pub const Rect = extern struct { + x: c_int, + y: c_int, + w: c_int, + h: c_int, +}; + +pub const FRect = extern struct { + x: f32, + y: f32, + w: f32, + h: f32, +}; + +pub inline fn hasRectIntersection(A: *const Rect, B: *const Rect) bool { + return @bitCast(c.SDL_HasRectIntersection(@ptrCast(A), @ptrCast(B))); +} + +pub inline fn getRectIntersection(A: *const Rect, B: *const Rect, result: ?*Rect) bool { + return @bitCast(c.SDL_GetRectIntersection(@ptrCast(A), @ptrCast(B), @ptrCast(result))); +} + +pub inline fn getRectUnion(A: *const Rect, B: *const Rect, result: ?*Rect) bool { + return @bitCast(c.SDL_GetRectUnion(@ptrCast(A), @ptrCast(B), @ptrCast(result))); +} + +pub inline fn getRectEnclosingPoints(points: *const Point, count: c_int, clip: *const Rect, result: ?*Rect) bool { + return @bitCast(c.SDL_GetRectEnclosingPoints(@ptrCast(points), count, @ptrCast(clip), @ptrCast(result))); +} + +pub inline fn getRectAndLineIntersection(rect: *const Rect, X1: *c_int, Y1: *c_int, X2: *c_int, Y2: *c_int) bool { + return @bitCast(c.SDL_GetRectAndLineIntersection(@ptrCast(rect), @ptrCast(X1), @ptrCast(Y1), @ptrCast(X2), @ptrCast(Y2))); +} + +pub inline fn hasRectIntersectionFloat(A: *const FRect, B: *const FRect) bool { + return @bitCast(c.SDL_HasRectIntersectionFloat(@ptrCast(A), @ptrCast(B))); +} + +pub inline fn getRectIntersectionFloat(A: *const FRect, B: *const FRect, result: ?*FRect) bool { + return @bitCast(c.SDL_GetRectIntersectionFloat(@ptrCast(A), @ptrCast(B), @ptrCast(result))); +} + +pub inline fn getRectUnionFloat(A: *const FRect, B: *const FRect, result: ?*FRect) bool { + return @bitCast(c.SDL_GetRectUnionFloat(@ptrCast(A), @ptrCast(B), @ptrCast(result))); +} + +pub inline fn getRectEnclosingPointsFloat(points: *const FPoint, count: c_int, clip: *const FRect, result: ?*FRect) bool { + return @bitCast(c.SDL_GetRectEnclosingPointsFloat(@ptrCast(points), count, @ptrCast(clip), @ptrCast(result))); +} + +pub inline fn getRectAndLineIntersectionFloat(rect: *const FRect, X1: *f32, Y1: *f32, X2: *f32, Y2: *f32) bool { + return @bitCast(c.SDL_GetRectAndLineIntersectionFloat(@ptrCast(rect), @ptrCast(X1), @ptrCast(Y1), @ptrCast(X2), @ptrCast(Y2))); +} diff --git a/sdl3-zig/sdl3/render.zig b/sdl3-zig/sdl3/render.zig new file mode 100644 index 0000000..7dde717 --- /dev/null +++ b/sdl3-zig/sdl3/render.zig @@ -0,0 +1,1275 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const FPoint = extern struct { + x: f32, + y: f32, +}; + +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 @ptrCast(c.SDL_CreateSoftwareRenderer(@ptrCast(surface))); + } +}; + +pub const PropertiesID = u32; + +pub const Window = opaque { + pub inline fn createRenderer(window: *Window, name: [*c]const u8) ?*Renderer { + return @ptrCast(c.SDL_CreateRenderer(@ptrCast(window), name)); + } + + pub inline fn getRenderer(window: *Window) ?*Renderer { + return @ptrCast(c.SDL_GetRenderer(@ptrCast(window))); + } +}; + +pub const FRect = extern struct { + x: f32, + y: f32, + w: f32, + h: f32, +}; + +pub const GPUTextureSamplerBinding = extern struct { + texture: ?*GPUTexture, // The texture to bind. Must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER. + sampler: ?*GPUSampler, // The sampler to bind. +}; + +pub const GPUSampler = opaque {}; + +pub const GPUTexture = opaque {}; + +pub const GPUShader = opaque {}; + +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 + windowFillDocument: bool = false, // window is in fill-document mode (Emscripten only), since SDL 3.4.0 + 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: u37 = 0, + rsvd: bool = false, + + pub const None = WindowFlags{}; +}; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12 = 0x32315659, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv = 0x56555949, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2 = 0x32595559, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy = 0x59565955, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu = 0x55595659, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12 = 0x3231564e, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21 = 0x3132564e, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010 = 0x30313050, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes = 0x2053454f, //Android video texture format + pixelformatMjpg = 0x47504a4d, //Motion JPEG +}; + +pub const ScaleMode = enum(c_int) { + scalemodeNearest, //nearest pixel sampling + scalemodeLinear, //linear filtering + scalemodePixelart, +}; + +pub const GPUDevice = opaque { + pub inline fn createGPURenderer(gpudevice: *GPUDevice, window: ?*Window) ?*Renderer { + return @ptrCast(c.SDL_CreateGPURenderer(@ptrCast(gpudevice), @ptrCast(window))); + } +}; + +pub const BlendMode = u32; + +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 + pinch: PinchFingerEvent, // Pinch 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, 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 PinchFingerEvent = extern struct { + _type: EventType, // ::SDL_EVENT_PINCH_BEGIN or ::SDL_EVENT_PINCH_UPDATE or ::SDL_EVENT_PINCH_END + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + scale: f32, // The scale change since the last SDL_EVENT_PINCH_UPDATE. Scale < 1 is "zoom out". Scale > 1 is "zoom in". + windowID: WindowID, // The window underneath the finger, if any +}; + +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_EVENT_DISPLAY_* + 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 = 0, //Unused (do not remove) + eventQuit = 0x100, //User-requested quit + eventTerminating, + eventLowMemory, + eventWillEnterBackground, + eventDidEnterBackground, + eventWillEnterForeground, + eventDidEnterForeground, + eventLocaleChanged, //The user's locale preferences have changed. + eventSystemThemeChanged, //The system theme changed + eventDisplayOrientation = 0x151, //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 + eventDisplayUsableBoundsChanged, //Display has changed usable bounds + eventWindowShown = 0x202, //Window has been shown + eventWindowHidden, //Window has been hidden + eventWindowExposed, + 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 = 0x300, //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 + eventScreenKeyboardShown, //The on-screen keyboard has been shown + eventScreenKeyboardHidden, //The on-screen keyboard has been hidden + eventMouseMotion = 0x400, //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 = 0x600, //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 = 0x650, //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, + eventPinchBegin = 0x710, //Pinch gesture started + eventPinchUpdate, //Pinch gesture updated + eventPinchEnd, //Pinch gesture ended + eventClipboardUpdate = 0x900, //The clipboard changed + eventDropFile = 0x1000, //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 = 0x1100, //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 = 0x1200, //A sensor was updated + eventPenProximityIn = 0x1300, //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 = 0x1400, //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 = 0x2000, //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 = 0x7F00, //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 None = MouseButtonFlags{}; +}; + +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 + penInputInProximity: bool = false, // pen is in proximity (since SDL 3.4.0) + pad0: u23 = 0, + rsvd: bool = false, + + pub const None = PenInputFlags{}; +}; + +pub const PenID = u32; + +pub const DisplayID = u32; + +pub const CameraID = u32; + +pub const KeyboardID = u32; + +pub const PowerState = enum(c_int) { + powerstateError = -1, //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 = 49, + scancodeNonushash = 50, + scancodeGrave = 53, + scancodeInsert = 73, + scancodeNumlockclear = 83, + scancodeNonusbackslash = 100, + scancodeApplication = 101, //windows contextual menu, compose + scancodePower = 102, + scancodeHelp = 117, //AL Integrated Help Center + scancodeMenu = 118, //Menu (show menu) + scancodeStop = 120, //AC Stop + scancodeAgain = 121, //AC Redo/Repeat + scancodeUndo = 122, //AC Undo + scancodeCut = 123, //AC Cut + scancodeCopy = 124, //AC Copy + scancodePaste = 125, //AC Paste + scancodeFind = 126, //AC Find + scancodeInternational1 = 135, + scancodeInternational3 = 137, //Yen + scancodeLang1 = 144, //Hangul/English toggle + scancodeLang2 = 145, //Hanja conversion + scancodeLang3 = 146, //Katakana + scancodeLang4 = 147, //Hiragana + scancodeLang5 = 148, //Zenkaku/Hankaku + scancodeLang6 = 149, //reserved + scancodeLang7 = 150, //reserved + scancodeLang8 = 151, //reserved + scancodeLang9 = 152, //reserved + scancodeAlterase = 153, //Erase-Eaze + scancodeCancel = 155, //AC Cancel + scancodeLalt = 226, //alt, option + scancodeLgui = 227, //windows, command (apple), meta + scancodeRalt = 230, //alt gr, option + scancodeRgui = 231, //windows, command (apple), meta + scancodeMode = 257, + scancodeSleep = 258, //Sleep + scancodeWake = 259, //Wake + scancodeChannelIncrement = 260, //Channel Increment + scancodeChannelDecrement = 261, //Channel Decrement + scancodeMediaPlay = 262, //Play + scancodeMediaPause = 263, //Pause + scancodeMediaRecord = 264, //Record + scancodeMediaFastForward = 265, //Fast Forward + scancodeMediaRewind = 266, //Rewind + scancodeMediaNextTrack = 267, //Next Track + scancodeMediaPreviousTrack = 268, //Previous Track + scancodeMediaStop = 269, //Stop + scancodeMediaEject = 270, //Eject + scancodeMediaPlayPause = 271, //Play / Pause + scancodeMediaSelect = 272, + scancodeAcNew = 273, //AC New + scancodeAcOpen = 274, //AC Open + scancodeAcClose = 275, //AC Close + scancodeAcExit = 276, //AC Exit + scancodeAcSave = 277, //AC Save + scancodeAcPrint = 278, //AC Print + scancodeAcProperties = 279, //AC Properties + scancodeAcSearch = 280, //AC Search + scancodeAcHome = 281, //AC Home + scancodeAcBack = 282, //AC Back + scancodeAcForward = 283, //AC Forward + scancodeAcStop = 284, //AC Stop + scancodeAcRefresh = 285, //AC Refresh + scancodeAcBookmarks = 286, //AC Bookmarks + scancodeSoftleft = 287, + scancodeSoftright = 288, + scancodeCall = 289, //Used for accepting phone calls. + scancodeEndcall = 290, //Used for rejecting phone calls. + scancodeReserved = 400, //400-500 reserved for dynamic keycodes + scancodeCount = 512, +}; + +pub const Keymod = u16; + +pub const Keycode = u32; + +pub const FlipMode = packed struct(u32) { + flipHorizontal: bool = false, // flip horizontally + flipVertical: bool = false, // flip vertically + pad0: u29 = 0, + rsvd: bool = false, + + pub const None = FlipMode{}; +}; + +pub const GPUBuffer = opaque {}; + +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 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 TextureAddressMode = enum(c_int) { + textureAddressAuto, //Wrapping is enabled if texture coordinates are outside [0, 1], this is the default + textureAddressClamp, //Texture coordinates are clamped to the [0, 1] range + textureAddressWrap, //The texture is repeated (tiled) +}; + +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 the clear color + 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 getGPURendererDevice(renderer: *Renderer) ?*GPUDevice { + return @ptrCast(c.SDL_GetGPURendererDevice(@ptrCast(renderer))); + } + + pub inline fn getRenderWindow(renderer: *Renderer) ?*Window { + return @ptrCast(c.SDL_GetRenderWindow(@ptrCast(renderer))); + } + + pub inline fn getRendererName(renderer: *Renderer) [*c]const u8 { + return c.SDL_GetRendererName(@ptrCast(renderer)); + } + + pub inline fn getRendererProperties(renderer: *Renderer) PropertiesID { + return c.SDL_GetRendererProperties(@ptrCast(renderer)); + } + + pub inline fn getRenderOutputSize(renderer: *Renderer, w: *c_int, h: *c_int) bool { + return @bitCast(c.SDL_GetRenderOutputSize(@ptrCast(renderer), @ptrCast(w), @ptrCast(h))); + } + + pub inline fn getCurrentRenderOutputSize(renderer: *Renderer, w: *c_int, h: *c_int) bool { + return @bitCast(c.SDL_GetCurrentRenderOutputSize(@ptrCast(renderer), @ptrCast(w), @ptrCast(h))); + } + + pub inline fn createTexture(renderer: *Renderer, format: PixelFormat, access: TextureAccess, w: c_int, h: c_int) ?*Texture { + return @ptrCast(c.SDL_CreateTexture(@ptrCast(renderer), @bitCast(format), access, w, h)); + } + + pub inline fn createTextureFromSurface(renderer: *Renderer, surface: ?*Surface) ?*Texture { + return @ptrCast(c.SDL_CreateTextureFromSurface(@ptrCast(renderer), @ptrCast(surface))); + } + + pub inline fn createTextureWithProperties(renderer: *Renderer, props: PropertiesID) ?*Texture { + return @ptrCast(c.SDL_CreateTextureWithProperties(@ptrCast(renderer), props)); + } + + pub inline fn setRenderTarget(renderer: *Renderer, texture: ?*Texture) bool { + return @bitCast(c.SDL_SetRenderTarget(@ptrCast(renderer), @ptrCast(texture))); + } + + pub inline fn getRenderTarget(renderer: *Renderer) ?*Texture { + return @ptrCast(c.SDL_GetRenderTarget(@ptrCast(renderer))); + } + + pub inline fn setRenderLogicalPresentation(renderer: *Renderer, w: c_int, h: c_int, mode: RendererLogicalPresentation) bool { + return @bitCast(c.SDL_SetRenderLogicalPresentation(@ptrCast(renderer), w, h, mode)); + } + + pub inline fn getRenderLogicalPresentation(renderer: *Renderer, w: *c_int, h: *c_int, mode: ?*RendererLogicalPresentation) bool { + return @bitCast(c.SDL_GetRenderLogicalPresentation(@ptrCast(renderer), @ptrCast(w), @ptrCast(h), @ptrCast(mode))); + } + + pub inline fn getRenderLogicalPresentationRect(renderer: *Renderer, rect: ?*FRect) bool { + return @bitCast(c.SDL_GetRenderLogicalPresentationRect(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn renderCoordinatesFromWindow(renderer: *Renderer, window_x: f32, window_y: f32, x: *f32, y: *f32) bool { + return @bitCast(c.SDL_RenderCoordinatesFromWindow(@ptrCast(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 @bitCast(c.SDL_RenderCoordinatesToWindow(@ptrCast(renderer), x, y, @ptrCast(window_x), @ptrCast(window_y))); + } + + pub inline fn convertEventToRenderCoordinates(renderer: *Renderer, event: ?*Event) bool { + return @bitCast(c.SDL_ConvertEventToRenderCoordinates(@ptrCast(renderer), @ptrCast(event))); + } + + pub inline fn setRenderViewport(renderer: *Renderer, rect: *const Rect) bool { + return @bitCast(c.SDL_SetRenderViewport(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn getRenderViewport(renderer: *Renderer, rect: ?*Rect) bool { + return @bitCast(c.SDL_GetRenderViewport(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn renderViewportSet(renderer: *Renderer) bool { + return @bitCast(c.SDL_RenderViewportSet(@ptrCast(renderer))); + } + + pub inline fn getRenderSafeArea(renderer: *Renderer, rect: ?*Rect) bool { + return @bitCast(c.SDL_GetRenderSafeArea(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn setRenderClipRect(renderer: *Renderer, rect: *const Rect) bool { + return @bitCast(c.SDL_SetRenderClipRect(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn getRenderClipRect(renderer: *Renderer, rect: ?*Rect) bool { + return @bitCast(c.SDL_GetRenderClipRect(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn renderClipEnabled(renderer: *Renderer) bool { + return @bitCast(c.SDL_RenderClipEnabled(@ptrCast(renderer))); + } + + pub inline fn setRenderScale(renderer: *Renderer, scaleX: f32, scaleY: f32) bool { + return @bitCast(c.SDL_SetRenderScale(@ptrCast(renderer), scaleX, scaleY)); + } + + pub inline fn getRenderScale(renderer: *Renderer, scaleX: *f32, scaleY: *f32) bool { + return @bitCast(c.SDL_GetRenderScale(@ptrCast(renderer), @ptrCast(scaleX), @ptrCast(scaleY))); + } + + pub inline fn setRenderDrawColor(renderer: *Renderer, r: u8, g: u8, b: u8, a: u8) bool { + return @bitCast(c.SDL_SetRenderDrawColor(@ptrCast(renderer), r, g, b, a)); + } + + pub inline fn setRenderDrawColorFloat(renderer: *Renderer, r: f32, g: f32, b: f32, a: f32) bool { + return @bitCast(c.SDL_SetRenderDrawColorFloat(@ptrCast(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 @bitCast(c.SDL_GetRenderDrawColor(@ptrCast(renderer), r, g, b, a)); + } + + pub inline fn getRenderDrawColorFloat(renderer: *Renderer, r: *f32, g: *f32, b: *f32, a: *f32) bool { + return @bitCast(c.SDL_GetRenderDrawColorFloat(@ptrCast(renderer), @ptrCast(r), @ptrCast(g), @ptrCast(b), @ptrCast(a))); + } + + pub inline fn setRenderColorScale(renderer: *Renderer, scale: f32) bool { + return @bitCast(c.SDL_SetRenderColorScale(@ptrCast(renderer), scale)); + } + + pub inline fn getRenderColorScale(renderer: *Renderer, scale: *f32) bool { + return @bitCast(c.SDL_GetRenderColorScale(@ptrCast(renderer), @ptrCast(scale))); + } + + pub inline fn setRenderDrawBlendMode(renderer: *Renderer, blendMode: BlendMode) bool { + return @bitCast(c.SDL_SetRenderDrawBlendMode(@ptrCast(renderer), @intFromEnum(blendMode))); + } + + pub inline fn getRenderDrawBlendMode(renderer: *Renderer, blendMode: ?*BlendMode) bool { + return @bitCast(c.SDL_GetRenderDrawBlendMode(@ptrCast(renderer), @ptrCast(blendMode))); + } + + pub inline fn renderClear(renderer: *Renderer) bool { + return @bitCast(c.SDL_RenderClear(@ptrCast(renderer))); + } + + pub inline fn renderPoint(renderer: *Renderer, x: f32, y: f32) bool { + return @bitCast(c.SDL_RenderPoint(@ptrCast(renderer), x, y)); + } + + pub inline fn renderPoints(renderer: *Renderer, points: *const FPoint, count: c_int) bool { + return @bitCast(c.SDL_RenderPoints(@ptrCast(renderer), @ptrCast(points), count)); + } + + pub inline fn renderLine(renderer: *Renderer, x1: f32, y1: f32, x2: f32, y2: f32) bool { + return @bitCast(c.SDL_RenderLine(@ptrCast(renderer), x1, y1, x2, y2)); + } + + pub inline fn renderLines(renderer: *Renderer, points: *const FPoint, count: c_int) bool { + return @bitCast(c.SDL_RenderLines(@ptrCast(renderer), @ptrCast(points), count)); + } + + pub inline fn renderRect(renderer: *Renderer, rect: *const FRect) bool { + return @bitCast(c.SDL_RenderRect(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn renderRects(renderer: *Renderer, rects: *const FRect, count: c_int) bool { + return @bitCast(c.SDL_RenderRects(@ptrCast(renderer), @ptrCast(rects), count)); + } + + pub inline fn renderFillRect(renderer: *Renderer, rect: *const FRect) bool { + return @bitCast(c.SDL_RenderFillRect(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn renderFillRects(renderer: *Renderer, rects: *const FRect, count: c_int) bool { + return @bitCast(c.SDL_RenderFillRects(@ptrCast(renderer), @ptrCast(rects), count)); + } + + pub inline fn renderTexture(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, dstrect: *const FRect) bool { + return @bitCast(c.SDL_RenderTexture(@ptrCast(renderer), @ptrCast(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 @bitCast(c.SDL_RenderTextureRotated(@ptrCast(renderer), @ptrCast(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 @bitCast(c.SDL_RenderTextureAffine(@ptrCast(renderer), @ptrCast(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 @bitCast(c.SDL_RenderTextureTiled(@ptrCast(renderer), @ptrCast(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 @bitCast(c.SDL_RenderTexture9Grid(@ptrCast(renderer), @ptrCast(texture), @ptrCast(srcrect), left_width, right_width, top_height, bottom_height, scale, @ptrCast(dstrect))); + } + + pub inline fn renderTexture9GridTiled(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, left_width: f32, right_width: f32, top_height: f32, bottom_height: f32, scale: f32, dstrect: *const FRect, tileScale: f32) bool { + return @bitCast(c.SDL_RenderTexture9GridTiled(@ptrCast(renderer), @ptrCast(texture), @ptrCast(srcrect), left_width, right_width, top_height, bottom_height, scale, @ptrCast(dstrect), tileScale)); + } + + 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 @bitCast(c.SDL_RenderGeometry(@ptrCast(renderer), @ptrCast(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 @bitCast(c.SDL_RenderGeometryRaw(@ptrCast(renderer), @ptrCast(texture), @ptrCast(xy), xy_stride, @ptrCast(color), color_stride, @ptrCast(uv), uv_stride, num_vertices, indices, num_indices, size_indices)); + } + + pub inline fn setRenderTextureAddressMode(renderer: *Renderer, u_mode: TextureAddressMode, v_mode: TextureAddressMode) bool { + return @bitCast(c.SDL_SetRenderTextureAddressMode(@ptrCast(renderer), @intFromEnum(u_mode), @intFromEnum(v_mode))); + } + + pub inline fn getRenderTextureAddressMode(renderer: *Renderer, u_mode: ?*TextureAddressMode, v_mode: ?*TextureAddressMode) bool { + return @bitCast(c.SDL_GetRenderTextureAddressMode(@ptrCast(renderer), @ptrCast(u_mode), @ptrCast(v_mode))); + } + + pub inline fn renderReadPixels(renderer: *Renderer, rect: *const Rect) ?*Surface { + return @ptrCast(c.SDL_RenderReadPixels(@ptrCast(renderer), @ptrCast(rect))); + } + + pub inline fn renderPresent(renderer: *Renderer) bool { + return @bitCast(c.SDL_RenderPresent(@ptrCast(renderer))); + } + + pub inline fn destroyRenderer(renderer: *Renderer) void { + return c.SDL_DestroyRenderer(@ptrCast(renderer)); + } + + pub inline fn flushRenderer(renderer: *Renderer) bool { + return @bitCast(c.SDL_FlushRenderer(@ptrCast(renderer))); + } + + pub inline fn getRenderMetalLayer(renderer: *Renderer) ?*anyopaque { + return c.SDL_GetRenderMetalLayer(@ptrCast(renderer)); + } + + pub inline fn getRenderMetalCommandEncoder(renderer: *Renderer) ?*anyopaque { + return c.SDL_GetRenderMetalCommandEncoder(@ptrCast(renderer)); + } + + pub inline fn addVulkanRenderSemaphores(renderer: *Renderer, wait_stage_mask: u32, wait_semaphore: i64, signal_semaphore: i64) bool { + return @bitCast(c.SDL_AddVulkanRenderSemaphores(@ptrCast(renderer), wait_stage_mask, wait_semaphore, signal_semaphore)); + } + + pub inline fn setRenderVSync(renderer: *Renderer, vsync: c_int) bool { + return @bitCast(c.SDL_SetRenderVSync(@ptrCast(renderer), vsync)); + } + + pub inline fn getRenderVSync(renderer: *Renderer, vsync: *c_int) bool { + return @bitCast(c.SDL_GetRenderVSync(@ptrCast(renderer), @ptrCast(vsync))); + } + + pub inline fn renderDebugText(renderer: *Renderer, x: f32, y: f32, str: [*c]const u8) bool { + return @bitCast(c.SDL_RenderDebugText(@ptrCast(renderer), x, y, str)); + } + + pub inline fn setDefaultTextureScaleMode(renderer: *Renderer, scale_mode: ScaleMode) bool { + return @bitCast(c.SDL_SetDefaultTextureScaleMode(@ptrCast(renderer), @intFromEnum(scale_mode))); + } + + pub inline fn getDefaultTextureScaleMode(renderer: *Renderer, scale_mode: ?*ScaleMode) bool { + return @bitCast(c.SDL_GetDefaultTextureScaleMode(@ptrCast(renderer), @ptrCast(scale_mode))); + } + + pub inline fn createGPURenderState(renderer: *Renderer, createinfo: ?*GPURenderStateCreateInfo) ?*GPURenderState { + return @ptrCast(c.SDL_CreateGPURenderState(@ptrCast(renderer), @ptrCast(createinfo))); + } + + pub inline fn setGPURenderState(renderer: *Renderer, state: ?*GPURenderState) bool { + return @bitCast(c.SDL_SetGPURenderState(@ptrCast(renderer), @ptrCast(state))); + } +}; + +pub const Texture = opaque { + pub inline fn getTextureProperties(texture: *Texture) PropertiesID { + return c.SDL_GetTextureProperties(@ptrCast(texture)); + } + + pub inline fn getRendererFromTexture(texture: *Texture) ?*Renderer { + return @ptrCast(c.SDL_GetRendererFromTexture(@ptrCast(texture))); + } + + pub inline fn getTextureSize(texture: *Texture, w: *f32, h: *f32) bool { + return @bitCast(c.SDL_GetTextureSize(@ptrCast(texture), @ptrCast(w), @ptrCast(h))); + } + + pub inline fn setTexturePalette(texture: *Texture, palette: ?*Palette) bool { + return @bitCast(c.SDL_SetTexturePalette(@ptrCast(texture), @ptrCast(palette))); + } + + pub inline fn getTexturePalette(texture: *Texture) ?*Palette { + return @ptrCast(c.SDL_GetTexturePalette(@ptrCast(texture))); + } + + pub inline fn setTextureColorMod(texture: *Texture, r: u8, g: u8, b: u8) bool { + return @bitCast(c.SDL_SetTextureColorMod(@ptrCast(texture), r, g, b)); + } + + pub inline fn setTextureColorModFloat(texture: *Texture, r: f32, g: f32, b: f32) bool { + return @bitCast(c.SDL_SetTextureColorModFloat(@ptrCast(texture), r, g, b)); + } + + pub inline fn getTextureColorMod(texture: *Texture, r: [*c]u8, g: [*c]u8, b: [*c]u8) bool { + return @bitCast(c.SDL_GetTextureColorMod(@ptrCast(texture), r, g, b)); + } + + pub inline fn getTextureColorModFloat(texture: *Texture, r: *f32, g: *f32, b: *f32) bool { + return @bitCast(c.SDL_GetTextureColorModFloat(@ptrCast(texture), @ptrCast(r), @ptrCast(g), @ptrCast(b))); + } + + pub inline fn setTextureAlphaMod(texture: *Texture, alpha: u8) bool { + return @bitCast(c.SDL_SetTextureAlphaMod(@ptrCast(texture), alpha)); + } + + pub inline fn setTextureAlphaModFloat(texture: *Texture, alpha: f32) bool { + return @bitCast(c.SDL_SetTextureAlphaModFloat(@ptrCast(texture), alpha)); + } + + pub inline fn getTextureAlphaMod(texture: *Texture, alpha: [*c]u8) bool { + return @bitCast(c.SDL_GetTextureAlphaMod(@ptrCast(texture), alpha)); + } + + pub inline fn getTextureAlphaModFloat(texture: *Texture, alpha: *f32) bool { + return @bitCast(c.SDL_GetTextureAlphaModFloat(@ptrCast(texture), @ptrCast(alpha))); + } + + pub inline fn setTextureBlendMode(texture: *Texture, blendMode: BlendMode) bool { + return @bitCast(c.SDL_SetTextureBlendMode(@ptrCast(texture), @intFromEnum(blendMode))); + } + + pub inline fn getTextureBlendMode(texture: *Texture, blendMode: ?*BlendMode) bool { + return @bitCast(c.SDL_GetTextureBlendMode(@ptrCast(texture), @ptrCast(blendMode))); + } + + pub inline fn setTextureScaleMode(texture: *Texture, scaleMode: ScaleMode) bool { + return @bitCast(c.SDL_SetTextureScaleMode(@ptrCast(texture), @intFromEnum(scaleMode))); + } + + pub inline fn getTextureScaleMode(texture: *Texture, scaleMode: ?*ScaleMode) bool { + return @bitCast(c.SDL_GetTextureScaleMode(@ptrCast(texture), @ptrCast(scaleMode))); + } + + pub inline fn updateTexture(texture: *Texture, rect: *const Rect, pixels: ?*const anyopaque, pitch: c_int) bool { + return @bitCast(c.SDL_UpdateTexture(@ptrCast(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 @bitCast(c.SDL_UpdateYUVTexture(@ptrCast(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 @bitCast(c.SDL_UpdateNVTexture(@ptrCast(texture), @ptrCast(rect), Yplane, Ypitch, UVplane, UVpitch)); + } + + pub inline fn lockTexture(texture: *Texture, rect: *const Rect, pixels: [*c]?*anyopaque, pitch: *c_int) bool { + return @bitCast(c.SDL_LockTexture(@ptrCast(texture), @ptrCast(rect), pixels, @ptrCast(pitch))); + } + + pub inline fn lockTextureToSurface(texture: *Texture, rect: *const Rect, surface: [*c][*c]Surface) bool { + return @bitCast(c.SDL_LockTextureToSurface(@ptrCast(texture), @ptrCast(rect), surface)); + } + + pub inline fn unlockTexture(texture: *Texture) void { + return c.SDL_UnlockTexture(@ptrCast(texture)); + } + + pub inline fn destroyTexture(texture: *Texture) void { + return c.SDL_DestroyTexture(@ptrCast(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 @bitCast(c.SDL_CreateWindowAndRenderer(title, width, height, @bitCast(window_flags), window, renderer)); +} + +pub inline fn createRendererWithProperties(props: PropertiesID) ?*Renderer { + return @ptrCast(c.SDL_CreateRendererWithProperties(props)); +} + +pub const GPURenderStateCreateInfo = extern struct { + fragment_shader: ?*GPUShader, // The fragment shader to use when this render state is active + num_sampler_bindings: i32, // The number of additional fragment samplers to bind when this render state is active + sampler_bindings: *const GPUTextureSamplerBinding, // Additional fragment samplers to bind when this render state is active + num_storage_textures: i32, // The number of storage textures to bind when this render state is active + storage_textures: [*c]*const GPUTexture, // Storage textures to bind when this render state is active + num_storage_buffers: i32, // The number of storage buffers to bind when this render state is active + storage_buffers: [*c]*const GPUBuffer, // Storage buffers to bind when this render state is active + props: PropertiesID, // A properties ID for extensions. Should be 0 if no extensions are needed. +}; + +pub const GPURenderState = opaque { + pub inline fn setGPURenderStateFragmentUniforms(gpurenderstate: *GPURenderState, slot_index: u32, data: ?*const anyopaque, length: u32) bool { + return @bitCast(c.SDL_SetGPURenderStateFragmentUniforms(@ptrCast(gpurenderstate), slot_index, data, length)); + } + + pub inline fn destroyGPURenderState(gpurenderstate: *GPURenderState) void { + return c.SDL_DestroyGPURenderState(@ptrCast(gpurenderstate)); + } +}; diff --git a/sdl3-zig/sdl3/sensor.zig b/sdl3-zig/sdl3/sensor.zig new file mode 100644 index 0000000..cc7fe67 --- /dev/null +++ b/sdl3-zig/sdl3/sensor.zig @@ -0,0 +1,76 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const Sensor = opaque { + pub inline fn getSensorProperties(sensor: *Sensor) PropertiesID { + return c.SDL_GetSensorProperties(@ptrCast(sensor)); + } + + pub inline fn getSensorName(sensor: *Sensor) [*c]const u8 { + return c.SDL_GetSensorName(@ptrCast(sensor)); + } + + pub inline fn getSensorType(sensor: *Sensor) SensorType { + return @intFromEnum(c.SDL_GetSensorType(@ptrCast(sensor))); + } + + pub inline fn getSensorNonPortableType(sensor: *Sensor) c_int { + return c.SDL_GetSensorNonPortableType(@ptrCast(sensor)); + } + + pub inline fn getSensorID(sensor: *Sensor) SensorID { + return c.SDL_GetSensorID(@ptrCast(sensor)); + } + + pub inline fn getSensorData(sensor: *Sensor, data: *f32, num_values: c_int) bool { + return @bitCast(c.SDL_GetSensorData(@ptrCast(sensor), @ptrCast(data), num_values)); + } + + pub inline fn closeSensor(sensor: *Sensor) void { + return c.SDL_CloseSensor(@ptrCast(sensor)); + } +}; + +pub const SensorID = u32; + +pub const SensorType = enum(c_int) { + sensorInvalid = -1, //Returned for an invalid sensor + sensorUnknown, //Unknown sensor type + sensorAccel, //Accelerometer + sensorGyro, //Gyroscope + sensorAccelL, //Accelerometer for left Joy-Con controller and Wii nunchuk + sensorGyroL, //Gyroscope for left Joy-Con controller + sensorAccelR, //Accelerometer for right Joy-Con controller + sensorGyroR, //Gyroscope for right Joy-Con controller + sensorCount, +}; + +pub inline fn getSensors(count: *c_int) ?*SensorID { + return @ptrCast(c.SDL_GetSensors(@ptrCast(count))); +} + +pub inline fn getSensorNameForID(instance_id: SensorID) [*c]const u8 { + return c.SDL_GetSensorNameForID(instance_id); +} + +pub inline fn getSensorTypeForID(instance_id: SensorID) SensorType { + return @intFromEnum(c.SDL_GetSensorTypeForID(instance_id)); +} + +pub inline fn getSensorNonPortableTypeForID(instance_id: SensorID) c_int { + return c.SDL_GetSensorNonPortableTypeForID(instance_id); +} + +pub inline fn openSensor(instance_id: SensorID) ?*Sensor { + return @ptrCast(c.SDL_OpenSensor(instance_id)); +} + +pub inline fn getSensorFromID(instance_id: SensorID) ?*Sensor { + return @ptrCast(c.SDL_GetSensorFromID(instance_id)); +} + +pub inline fn updateSensors() void { + return c.SDL_UpdateSensors(); +} diff --git a/sdl3-zig/sdl3/storage.zig b/sdl3-zig/sdl3/storage.zig new file mode 100644 index 0000000..dd07876 --- /dev/null +++ b/sdl3-zig/sdl3/storage.zig @@ -0,0 +1,116 @@ +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 None = GlobFlags{}; +}; + +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 @bitCast(c.SDL_CloseStorage(@ptrCast(storage))); + } + + pub inline fn storageReady(storage: *Storage) bool { + return @bitCast(c.SDL_StorageReady(@ptrCast(storage))); + } + + pub inline fn getStorageFileSize(storage: *Storage, path: [*c]const u8, length: *u64) bool { + return @bitCast(c.SDL_GetStorageFileSize(@ptrCast(storage), path, @ptrCast(length))); + } + + pub inline fn readStorageFile(storage: *Storage, path: [*c]const u8, destination: ?*anyopaque, length: u64) bool { + return @bitCast(c.SDL_ReadStorageFile(@ptrCast(storage), path, destination, length)); + } + + pub inline fn writeStorageFile(storage: *Storage, path: [*c]const u8, source: ?*const anyopaque, length: u64) bool { + return @bitCast(c.SDL_WriteStorageFile(@ptrCast(storage), path, source, length)); + } + + pub inline fn createStorageDirectory(storage: *Storage, path: [*c]const u8) bool { + return @bitCast(c.SDL_CreateStorageDirectory(@ptrCast(storage), path)); + } + + pub inline fn enumerateStorageDirectory(storage: *Storage, path: [*c]const u8, callback: EnumerateDirectoryCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_EnumerateStorageDirectory(@ptrCast(storage), path, callback, userdata)); + } + + pub inline fn removeStoragePath(storage: *Storage, path: [*c]const u8) bool { + return @bitCast(c.SDL_RemoveStoragePath(@ptrCast(storage), path)); + } + + pub inline fn renameStoragePath(storage: *Storage, oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return @bitCast(c.SDL_RenameStoragePath(@ptrCast(storage), oldpath, newpath)); + } + + pub inline fn copyStorageFile(storage: *Storage, oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return @bitCast(c.SDL_CopyStorageFile(@ptrCast(storage), oldpath, newpath)); + } + + pub inline fn getStoragePathInfo(storage: *Storage, path: [*c]const u8, info: ?*PathInfo) bool { + return @bitCast(c.SDL_GetStoragePathInfo(@ptrCast(storage), path, @ptrCast(info))); + } + + pub inline fn getStorageSpaceRemaining(storage: *Storage) u64 { + return c.SDL_GetStorageSpaceRemaining(@ptrCast(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(@ptrCast(storage), path, pattern, @bitCast(flags), @ptrCast(count)); + } +}; + +pub inline fn openTitleStorage(override: [*c]const u8, props: PropertiesID) ?*Storage { + return @ptrCast(c.SDL_OpenTitleStorage(override, props)); +} + +pub inline fn openUserStorage(org: [*c]const u8, app: [*c]const u8, props: PropertiesID) ?*Storage { + return @ptrCast(c.SDL_OpenUserStorage(org, app, props)); +} + +pub inline fn openFileStorage(path: [*c]const u8) ?*Storage { + return @ptrCast(c.SDL_OpenFileStorage(path)); +} + +pub inline fn openStorage(iface: *const StorageInterface, userdata: ?*anyopaque) ?*Storage { + return @ptrCast(c.SDL_OpenStorage(@ptrCast(iface), userdata)); +} diff --git a/sdl3-zig/sdl3/surface.zig b/sdl3-zig/sdl3/surface.zig new file mode 100644 index 0000000..dc1167a --- /dev/null +++ b/sdl3-zig/sdl3/surface.zig @@ -0,0 +1,360 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12 = 0x32315659, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv = 0x56555949, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2 = 0x32595559, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy = 0x59565955, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu = 0x55595659, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12 = 0x3231564e, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21 = 0x3132564e, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010 = 0x30313050, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes = 0x2053454f, //Android video texture format + pixelformatMjpg = 0x47504a4d, //Motion JPEG +}; + +pub const BlendMode = u32; + +pub const IOStream = opaque { + pub inline fn loadSurface_IO(iostream: *IOStream, closeio: bool) ?*Surface { + return @ptrCast(c.SDL_LoadSurface_IO(@ptrCast(iostream), @bitCast(closeio))); + } + + pub inline fn loadBMP_IO(iostream: *IOStream, closeio: bool) ?*Surface { + return @ptrCast(c.SDL_LoadBMP_IO(@ptrCast(iostream), @bitCast(closeio))); + } + + pub inline fn loadPNG_IO(iostream: *IOStream, closeio: bool) ?*Surface { + return @ptrCast(c.SDL_LoadPNG_IO(@ptrCast(iostream), @bitCast(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 = 0x120005a0, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 + colorRangeFull, + colorPrimariesBt709, + transferCharacteristicsSrgb, + matrixCoefficientsIdentity, + colorspaceSrgbLinear = 0x12000500, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 + transferCharacteristicsLinear, + colorspaceHdr10 = 0x12002600, //Equivalent to DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 + colorPrimariesBt2020, + transferCharacteristicsPq, + colorspaceJpeg = 0x220004c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 + transferCharacteristicsBt601, + matrixCoefficientsBt601, + colorspaceBt601Limited = 0x211018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorRangeLimited, + colorPrimariesBt601, + colorspaceBt601Full = 0x221018c6, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 + colorspaceBt709Limited = 0x21100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + transferCharacteristicsBt709, + matrixCoefficientsBt709, + colorspaceBt709Full = 0x22100421, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 + colorspaceBt2020Limited = 0x21102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 + matrixCoefficientsBt2020Ncl, + colorspaceBt2020Full = 0x22102609, //Equivalent to DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 + + pub const colorspaceRgbDefault = .colorspaceSrgb; //The default colorspace for RGB surfaces if no colorspace is specified + pub const colorspaceYuvDefault = .colorspaceBt601Limited; //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 None = SurfaceFlags{}; +}; + +pub const ScaleMode = enum(c_int) { + scalemodeNearest, //nearest pixel sampling + scalemodeLinear, //linear filtering + scalemodePixelart, +}; + +pub const FlipMode = packed struct(u32) { + flipHorizontal: bool = false, // flip horizontally + flipVertical: bool = false, // flip vertically + pad0: u29 = 0, + rsvd: bool = false, + + pub const None = FlipMode{}; +}; + +pub const Surface = opaque { + pub inline fn destroySurface(surface: *Surface) void { + return c.SDL_DestroySurface(@ptrCast(surface)); + } + + pub inline fn getSurfaceProperties(surface: *Surface) PropertiesID { + return c.SDL_GetSurfaceProperties(@ptrCast(surface)); + } + + pub inline fn setSurfaceColorspace(surface: *Surface, colorspace: Colorspace) bool { + return @bitCast(c.SDL_SetSurfaceColorspace(@ptrCast(surface), colorspace)); + } + + pub inline fn getSurfaceColorspace(surface: *Surface) Colorspace { + return c.SDL_GetSurfaceColorspace(@ptrCast(surface)); + } + + pub inline fn createSurfacePalette(surface: *Surface) ?*Palette { + return @ptrCast(c.SDL_CreateSurfacePalette(@ptrCast(surface))); + } + + pub inline fn setSurfacePalette(surface: *Surface, palette: ?*Palette) bool { + return @bitCast(c.SDL_SetSurfacePalette(@ptrCast(surface), @ptrCast(palette))); + } + + pub inline fn getSurfacePalette(surface: *Surface) ?*Palette { + return @ptrCast(c.SDL_GetSurfacePalette(@ptrCast(surface))); + } + + pub inline fn addSurfaceAlternateImage(surface: *Surface, image: ?*Surface) bool { + return @bitCast(c.SDL_AddSurfaceAlternateImage(@ptrCast(surface), @ptrCast(image))); + } + + pub inline fn surfaceHasAlternateImages(surface: *Surface) bool { + return @bitCast(c.SDL_SurfaceHasAlternateImages(@ptrCast(surface))); + } + + pub inline fn getSurfaceImages(surface: *Surface, count: *c_int) [*c][*c]Surface { + return c.SDL_GetSurfaceImages(@ptrCast(surface), @ptrCast(count)); + } + + pub inline fn removeSurfaceAlternateImages(surface: *Surface) void { + return c.SDL_RemoveSurfaceAlternateImages(@ptrCast(surface)); + } + + pub inline fn lockSurface(surface: *Surface) bool { + return @bitCast(c.SDL_LockSurface(@ptrCast(surface))); + } + + pub inline fn unlockSurface(surface: *Surface) void { + return c.SDL_UnlockSurface(@ptrCast(surface)); + } + + pub inline fn saveBMP_IO(surface: *Surface, dst: ?*IOStream, closeio: bool) bool { + return @bitCast(c.SDL_SaveBMP_IO(@ptrCast(surface), @ptrCast(dst), @bitCast(closeio))); + } + + pub inline fn saveBMP(surface: *Surface, file: [*c]const u8) bool { + return @bitCast(c.SDL_SaveBMP(@ptrCast(surface), file)); + } + + pub inline fn savePNG_IO(surface: *Surface, dst: ?*IOStream, closeio: bool) bool { + return @bitCast(c.SDL_SavePNG_IO(@ptrCast(surface), @ptrCast(dst), @bitCast(closeio))); + } + + pub inline fn savePNG(surface: *Surface, file: [*c]const u8) bool { + return @bitCast(c.SDL_SavePNG(@ptrCast(surface), file)); + } + + pub inline fn setSurfaceRLE(surface: *Surface, enabled: bool) bool { + return @bitCast(c.SDL_SetSurfaceRLE(@ptrCast(surface), @bitCast(enabled))); + } + + pub inline fn surfaceHasRLE(surface: *Surface) bool { + return @bitCast(c.SDL_SurfaceHasRLE(@ptrCast(surface))); + } + + pub inline fn setSurfaceColorKey(surface: *Surface, enabled: bool, key: u32) bool { + return @bitCast(c.SDL_SetSurfaceColorKey(@ptrCast(surface), @bitCast(enabled), key)); + } + + pub inline fn surfaceHasColorKey(surface: *Surface) bool { + return @bitCast(c.SDL_SurfaceHasColorKey(@ptrCast(surface))); + } + + pub inline fn getSurfaceColorKey(surface: *Surface, key: *u32) bool { + return @bitCast(c.SDL_GetSurfaceColorKey(@ptrCast(surface), @ptrCast(key))); + } + + pub inline fn setSurfaceColorMod(surface: *Surface, r: u8, g: u8, b: u8) bool { + return @bitCast(c.SDL_SetSurfaceColorMod(@ptrCast(surface), r, g, b)); + } + + pub inline fn getSurfaceColorMod(surface: *Surface, r: [*c]u8, g: [*c]u8, b: [*c]u8) bool { + return @bitCast(c.SDL_GetSurfaceColorMod(@ptrCast(surface), r, g, b)); + } + + pub inline fn setSurfaceAlphaMod(surface: *Surface, alpha: u8) bool { + return @bitCast(c.SDL_SetSurfaceAlphaMod(@ptrCast(surface), alpha)); + } + + pub inline fn getSurfaceAlphaMod(surface: *Surface, alpha: [*c]u8) bool { + return @bitCast(c.SDL_GetSurfaceAlphaMod(@ptrCast(surface), alpha)); + } + + pub inline fn setSurfaceBlendMode(surface: *Surface, blendMode: BlendMode) bool { + return @bitCast(c.SDL_SetSurfaceBlendMode(@ptrCast(surface), @intFromEnum(blendMode))); + } + + pub inline fn getSurfaceBlendMode(surface: *Surface, blendMode: ?*BlendMode) bool { + return @bitCast(c.SDL_GetSurfaceBlendMode(@ptrCast(surface), @ptrCast(blendMode))); + } + + pub inline fn setSurfaceClipRect(surface: *Surface, rect: *const Rect) bool { + return @bitCast(c.SDL_SetSurfaceClipRect(@ptrCast(surface), @ptrCast(rect))); + } + + pub inline fn getSurfaceClipRect(surface: *Surface, rect: ?*Rect) bool { + return @bitCast(c.SDL_GetSurfaceClipRect(@ptrCast(surface), @ptrCast(rect))); + } + + pub inline fn flipSurface(surface: *Surface, flip: FlipMode) bool { + return @bitCast(c.SDL_FlipSurface(@ptrCast(surface), @intFromEnum(flip))); + } + + pub inline fn rotateSurface(surface: *Surface, angle: f32) ?*Surface { + return @ptrCast(c.SDL_RotateSurface(@ptrCast(surface), angle)); + } + + pub inline fn duplicateSurface(surface: *Surface) ?*Surface { + return @ptrCast(c.SDL_DuplicateSurface(@ptrCast(surface))); + } + + pub inline fn scaleSurface(surface: *Surface, width: c_int, height: c_int, scaleMode: ScaleMode) ?*Surface { + return @ptrCast(c.SDL_ScaleSurface(@ptrCast(surface), width, height, @intFromEnum(scaleMode))); + } + + pub inline fn convertSurface(surface: *Surface, format: PixelFormat) ?*Surface { + return @ptrCast(c.SDL_ConvertSurface(@ptrCast(surface), @bitCast(format))); + } + + pub inline fn convertSurfaceAndColorspace(surface: *Surface, format: PixelFormat, palette: ?*Palette, colorspace: Colorspace, props: PropertiesID) ?*Surface { + return @ptrCast(c.SDL_ConvertSurfaceAndColorspace(@ptrCast(surface), @bitCast(format), @ptrCast(palette), colorspace, props)); + } + + pub inline fn premultiplySurfaceAlpha(surface: *Surface, linear: bool) bool { + return @bitCast(c.SDL_PremultiplySurfaceAlpha(@ptrCast(surface), @bitCast(linear))); + } + + pub inline fn clearSurface(surface: *Surface, r: f32, g: f32, b: f32, a: f32) bool { + return @bitCast(c.SDL_ClearSurface(@ptrCast(surface), r, g, b, a)); + } + + pub inline fn fillSurfaceRect(surface: *Surface, rect: *const Rect, color: u32) bool { + return @bitCast(c.SDL_FillSurfaceRect(@ptrCast(surface), @ptrCast(rect), color)); + } + + pub inline fn fillSurfaceRects(surface: *Surface, rects: *const Rect, count: c_int, color: u32) bool { + return @bitCast(c.SDL_FillSurfaceRects(@ptrCast(surface), @ptrCast(rects), count, color)); + } + + pub inline fn blitSurface(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect) bool { + return @bitCast(c.SDL_BlitSurface(@ptrCast(surface), @ptrCast(srcrect), @ptrCast(dst), @ptrCast(dstrect))); + } + + pub inline fn blitSurfaceUnchecked(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect) bool { + return @bitCast(c.SDL_BlitSurfaceUnchecked(@ptrCast(surface), @ptrCast(srcrect), @ptrCast(dst), @ptrCast(dstrect))); + } + + pub inline fn blitSurfaceScaled(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect, scaleMode: ScaleMode) bool { + return @bitCast(c.SDL_BlitSurfaceScaled(@ptrCast(surface), @ptrCast(srcrect), @ptrCast(dst), @ptrCast(dstrect), @intFromEnum(scaleMode))); + } + + pub inline fn blitSurfaceUncheckedScaled(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect, scaleMode: ScaleMode) bool { + return @bitCast(c.SDL_BlitSurfaceUncheckedScaled(@ptrCast(surface), @ptrCast(srcrect), @ptrCast(dst), @ptrCast(dstrect), @intFromEnum(scaleMode))); + } + + pub inline fn stretchSurface(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect, scaleMode: ScaleMode) bool { + return @bitCast(c.SDL_StretchSurface(@ptrCast(surface), @ptrCast(srcrect), @ptrCast(dst), @ptrCast(dstrect), @intFromEnum(scaleMode))); + } + + pub inline fn blitSurfaceTiled(surface: *Surface, srcrect: *const Rect, dst: ?*Surface, dstrect: *const Rect) bool { + return @bitCast(c.SDL_BlitSurfaceTiled(@ptrCast(surface), @ptrCast(srcrect), @ptrCast(dst), @ptrCast(dstrect))); + } + + pub inline fn blitSurfaceTiledWithScale(surface: *Surface, srcrect: *const Rect, scale: f32, scaleMode: ScaleMode, dst: ?*Surface, dstrect: *const Rect) bool { + return @bitCast(c.SDL_BlitSurfaceTiledWithScale(@ptrCast(surface), @ptrCast(srcrect), scale, @intFromEnum(scaleMode), @ptrCast(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 @bitCast(c.SDL_BlitSurface9Grid(@ptrCast(surface), @ptrCast(srcrect), left_width, right_width, top_height, bottom_height, scale, @intFromEnum(scaleMode), @ptrCast(dst), @ptrCast(dstrect))); + } + + pub inline fn mapSurfaceRGB(surface: *Surface, r: u8, g: u8, b: u8) u32 { + return c.SDL_MapSurfaceRGB(@ptrCast(surface), r, g, b); + } + + pub inline fn mapSurfaceRGBA(surface: *Surface, r: u8, g: u8, b: u8, a: u8) u32 { + return c.SDL_MapSurfaceRGBA(@ptrCast(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 @bitCast(c.SDL_ReadSurfacePixel(@ptrCast(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 @bitCast(c.SDL_ReadSurfacePixelFloat(@ptrCast(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 @bitCast(c.SDL_WriteSurfacePixel(@ptrCast(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 @bitCast(c.SDL_WriteSurfacePixelFloat(@ptrCast(surface), x, y, r, g, b, a)); + } +}; + +pub inline fn createSurface(width: c_int, height: c_int, format: PixelFormat) ?*Surface { + return @ptrCast(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 @ptrCast(c.SDL_CreateSurfaceFrom(width, height, @bitCast(format), pixels, pitch)); +} + +pub inline fn loadSurface(file: [*c]const u8) ?*Surface { + return @ptrCast(c.SDL_LoadSurface(file)); +} + +pub inline fn loadBMP(file: [*c]const u8) ?*Surface { + return @ptrCast(c.SDL_LoadBMP(file)); +} + +pub inline fn loadPNG(file: [*c]const u8) ?*Surface { + return @ptrCast(c.SDL_LoadPNG(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 @bitCast(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 @bitCast(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 @bitCast(c.SDL_PremultiplyAlpha(width, height, @bitCast(src_format), src, src_pitch, @bitCast(dst_format), dst, dst_pitch, @bitCast(linear))); +} diff --git a/sdl3-zig/sdl3/system.zig b/sdl3-zig/sdl3/system.zig new file mode 100644 index 0000000..adb1c4c --- /dev/null +++ b/sdl3-zig/sdl3/system.zig @@ -0,0 +1,159 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const DisplayID = u32; + +pub const Window = opaque { + pub inline fn setiOSAnimationCallback(window: *Window, interval: c_int, callback: iOSAnimationCallback, callbackParam: ?*anyopaque) bool { + return @bitCast(c.SDL_SetiOSAnimationCallback(@ptrCast(window), interval, callback, callbackParam)); + } +}; + +pub const MSG = opaque {}; + +pub const WindowsMessageHook = c.SDL_WindowsMessageHook; + +pub inline fn setWindowsMessageHook(callback: WindowsMessageHook, userdata: ?*anyopaque) void { + return c.SDL_SetWindowsMessageHook(callback, userdata); +} + +pub inline fn getDirect3D9AdapterIndex(displayID: DisplayID) c_int { + return c.SDL_GetDirect3D9AdapterIndex(displayID); +} + +pub inline fn getDXGIOutputInfo(displayID: DisplayID, adapterIndex: *c_int, outputIndex: *c_int) bool { + return @bitCast(c.SDL_GetDXGIOutputInfo(displayID, @ptrCast(adapterIndex), @ptrCast(outputIndex))); +} + +pub const X11EventHook = c.SDL_X11EventHook; + +pub inline fn setX11EventHook(callback: X11EventHook, userdata: ?*anyopaque) void { + return c.SDL_SetX11EventHook(callback, userdata); +} + +pub inline fn setLinuxThreadPriority(threadID: i64, priority: c_int) bool { + return @bitCast(c.SDL_SetLinuxThreadPriority(threadID, priority)); +} + +pub inline fn setLinuxThreadPriorityAndPolicy(threadID: i64, sdlPriority: c_int, schedPolicy: c_int) bool { + return @bitCast(c.SDL_SetLinuxThreadPriorityAndPolicy(threadID, sdlPriority, schedPolicy)); +} + +pub const iOSAnimationCallback = c.SDL_iOSAnimationCallback; + +pub inline fn setiOSEventPump(enabled: bool) void { + return c.SDL_SetiOSEventPump(@bitCast(enabled)); +} + +pub inline fn getAndroidJNIEnv() ?*anyopaque { + return c.SDL_GetAndroidJNIEnv(); +} + +pub inline fn getAndroidActivity() ?*anyopaque { + return c.SDL_GetAndroidActivity(); +} + +pub inline fn getAndroidSDKVersion() c_int { + return c.SDL_GetAndroidSDKVersion(); +} + +pub inline fn isChromebook() bool { + return @bitCast(c.SDL_IsChromebook()); +} + +pub inline fn isDeXMode() bool { + return @bitCast(c.SDL_IsDeXMode()); +} + +pub inline fn sendAndroidBackButton() void { + return c.SDL_SendAndroidBackButton(); +} + +pub inline fn getAndroidInternalStoragePath() [*c]const u8 { + return c.SDL_GetAndroidInternalStoragePath(); +} + +pub inline fn getAndroidExternalStorageState() u32 { + return c.SDL_GetAndroidExternalStorageState(); +} + +pub inline fn getAndroidExternalStoragePath() [*c]const u8 { + return c.SDL_GetAndroidExternalStoragePath(); +} + +pub inline fn getAndroidCachePath() [*c]const u8 { + return c.SDL_GetAndroidCachePath(); +} + +pub const RequestAndroidPermissionCallback = c.SDL_RequestAndroidPermissionCallback; + +pub inline fn requestAndroidPermission(permission: [*c]const u8, cb: RequestAndroidPermissionCallback, userdata: ?*anyopaque) bool { + return @bitCast(c.SDL_RequestAndroidPermission(permission, cb, userdata)); +} + +pub inline fn showAndroidToast(message: [*c]const u8, duration: c_int, gravity: c_int, xoffset: c_int, yoffset: c_int) bool { + return @bitCast(c.SDL_ShowAndroidToast(message, duration, gravity, xoffset, yoffset)); +} + +pub inline fn sendAndroidMessage(command: u32, param: c_int) bool { + return @bitCast(c.SDL_SendAndroidMessage(command, param)); +} + +pub inline fn isTablet() bool { + return @bitCast(c.SDL_IsTablet()); +} + +pub inline fn isTV() bool { + return @bitCast(c.SDL_IsTV()); +} + +pub const Sandbox = enum(c_int) { + sandboxUnknownContainer, + sandboxFlatpak, + sandboxSnap, + sandboxMacos, +}; + +pub inline fn getSandbox() Sandbox { + return c.SDL_GetSandbox(); +} + +pub inline fn onApplicationWillTerminate() void { + return c.SDL_OnApplicationWillTerminate(); +} + +pub inline fn onApplicationDidReceiveMemoryWarning() void { + return c.SDL_OnApplicationDidReceiveMemoryWarning(); +} + +pub inline fn onApplicationWillEnterBackground() void { + return c.SDL_OnApplicationWillEnterBackground(); +} + +pub inline fn onApplicationDidEnterBackground() void { + return c.SDL_OnApplicationDidEnterBackground(); +} + +pub inline fn onApplicationWillEnterForeground() void { + return c.SDL_OnApplicationWillEnterForeground(); +} + +pub inline fn onApplicationDidEnterForeground() void { + return c.SDL_OnApplicationDidEnterForeground(); +} + +pub inline fn onApplicationDidChangeStatusBarOrientation() void { + return c.SDL_OnApplicationDidChangeStatusBarOrientation(); +} + +pub const XTaskQueueHandle = *anyopaque; + +pub const XUserHandle = *anyopaque; + +pub inline fn getGDKTaskQueue(outTaskQueue: [*c]XTaskQueueHandle) bool { + return @bitCast(c.SDL_GetGDKTaskQueue(outTaskQueue)); +} + +pub inline fn getGDKDefaultUser(outUserHandle: [*c]XUserHandle) bool { + return @bitCast(c.SDL_GetGDKDefaultUser(outUserHandle)); +} diff --git a/sdl3-zig/sdl3/time.zig b/sdl3-zig/sdl3/time.zig new file mode 100644 index 0000000..7d1ed86 --- /dev/null +++ b/sdl3-zig/sdl3/time.zig @@ -0,0 +1,63 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Time = i64; + +pub const DateTime = extern struct { + year: c_int, // Year + month: c_int, // Month [01-12] + day: c_int, // Day of the month [01-31] + hour: c_int, // Hour [0-23] + minute: c_int, // Minute [0-59] + second: c_int, // Seconds [0-60] + nanosecond: c_int, // Nanoseconds [0-999999999] + day_of_week: c_int, // Day of the week [0-6] (0 being Sunday) + utc_offset: c_int, // Seconds east of UTC +}; + +pub const DateFormat = enum(c_int) { + dateFormatYyyymmdd = 0, //Year/Month/Day + dateFormatDdmmyyyy = 1, //Day/Month/Year + dateFormatMmddyyyy = 2, //Month/Day/Year +}; + +pub const TimeFormat = enum(c_int) { + timeFormat24hr = 0, //24 hour time + timeFormat12hr = 1, //12 hour time +}; + +pub inline fn getDateTimeLocalePreferences(dateFormat: ?*DateFormat, timeFormat: ?*TimeFormat) bool { + return @bitCast(c.SDL_GetDateTimeLocalePreferences(@ptrCast(dateFormat), @ptrCast(timeFormat))); +} + +pub inline fn getCurrentTime(ticks: ?*Time) bool { + return @bitCast(c.SDL_GetCurrentTime(@ptrCast(ticks))); +} + +pub inline fn timeToDateTime(ticks: Time, dt: ?*DateTime, localTime: bool) bool { + return @bitCast(c.SDL_TimeToDateTime(ticks, @ptrCast(dt), @bitCast(localTime))); +} + +pub inline fn dateTimeToTime(dt: *const DateTime, ticks: ?*Time) bool { + return @bitCast(c.SDL_DateTimeToTime(@ptrCast(dt), @ptrCast(ticks))); +} + +pub inline fn timeToWindows(ticks: Time, dwLowDateTime: *u32, dwHighDateTime: *u32) void { + return c.SDL_TimeToWindows(ticks, @ptrCast(dwLowDateTime), @ptrCast(dwHighDateTime)); +} + +pub inline fn timeFromWindows(dwLowDateTime: u32, dwHighDateTime: u32) Time { + return c.SDL_TimeFromWindows(dwLowDateTime, dwHighDateTime); +} + +pub inline fn getDaysInMonth(year: c_int, month: c_int) c_int { + return c.SDL_GetDaysInMonth(year, month); +} + +pub inline fn getDayOfYear(year: c_int, month: c_int, day: c_int) c_int { + return c.SDL_GetDayOfYear(year, month, day); +} + +pub inline fn getDayOfWeek(year: c_int, month: c_int, day: c_int) c_int { + return c.SDL_GetDayOfWeek(year, month, day); +} diff --git a/sdl3-zig/sdl3/timer.zig b/sdl3-zig/sdl3/timer.zig new file mode 100644 index 0000000..965e68d --- /dev/null +++ b/sdl3-zig/sdl3/timer.zig @@ -0,0 +1,48 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn getTicks() u64 { + return c.SDL_GetTicks(); +} + +pub inline fn getTicksNS() u64 { + return c.SDL_GetTicksNS(); +} + +pub inline fn getPerformanceCounter() u64 { + return c.SDL_GetPerformanceCounter(); +} + +pub inline fn getPerformanceFrequency() u64 { + return c.SDL_GetPerformanceFrequency(); +} + +pub inline fn delay(ms: u32) void { + return c.SDL_Delay(ms); +} + +pub inline fn delayNS(ns: u64) void { + return c.SDL_DelayNS(ns); +} + +pub inline fn delayPrecise(ns: u64) void { + return c.SDL_DelayPrecise(ns); +} + +pub const TimerID = u32; + +pub const TimerCallback = c.SDL_TimerCallback; + +pub inline fn addTimer(interval: u32, callback: TimerCallback, userdata: ?*anyopaque) TimerID { + return c.SDL_AddTimer(interval, callback, userdata); +} + +pub const NSTimerCallback = c.SDL_NSTimerCallback; + +pub inline fn addTimerNS(interval: u64, callback: NSTimerCallback, userdata: ?*anyopaque) TimerID { + return c.SDL_AddTimerNS(interval, callback, userdata); +} + +pub inline fn removeTimer(id: TimerID) bool { + return @bitCast(c.SDL_RemoveTimer(id)); +} diff --git a/sdl3-zig/sdl3/touch.zig b/sdl3-zig/sdl3/touch.zig new file mode 100644 index 0000000..2bf4bf6 --- /dev/null +++ b/sdl3-zig/sdl3/touch.zig @@ -0,0 +1,35 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const TouchID = u64; + +pub const FingerID = u64; + +pub const TouchDeviceType = enum(c_int) { + touchDeviceDirect, //touch screen with window-relative coordinates + touchDeviceIndirectAbsolute, //trackpad with absolute device coordinates + touchDeviceIndirectRelative, //trackpad with screen cursor-relative coordinates +}; + +pub const Finger = extern struct { + id: FingerID, // the finger ID + x: f32, // the x-axis location of the touch event, normalized (0...1) + y: f32, // the y-axis location of the touch event, normalized (0...1) + pressure: f32, // the quantity of pressure applied, normalized (0...1) +}; + +pub inline fn getTouchDevices(count: *c_int) ?*TouchID { + return @ptrCast(c.SDL_GetTouchDevices(@ptrCast(count))); +} + +pub inline fn getTouchDeviceName(touchID: TouchID) [*c]const u8 { + return c.SDL_GetTouchDeviceName(touchID); +} + +pub inline fn getTouchDeviceType(touchID: TouchID) TouchDeviceType { + return @intFromEnum(c.SDL_GetTouchDeviceType(touchID)); +} + +pub inline fn getTouchFingers(touchID: TouchID, count: *c_int) [*c][*c]Finger { + return c.SDL_GetTouchFingers(touchID, @ptrCast(count)); +} diff --git a/sdl3-zig/sdl3/version.zig b/sdl3-zig/sdl3/version.zig new file mode 100644 index 0000000..8cef3e8 --- /dev/null +++ b/sdl3-zig/sdl3/version.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn getVersion() c_int { + return c.SDL_GetVersion(); +} + +pub inline fn getRevision() [*c]const u8 { + return c.SDL_GetRevision(); +} diff --git a/sdl3-zig/sdl3/video.zig b/sdl3-zig/sdl3/video.zig new file mode 100644 index 0000000..6d33104 --- /dev/null +++ b/sdl3-zig/sdl3/video.zig @@ -0,0 +1,641 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PixelFormat = enum(c_int) { + pixelformatYv12 = 0x32315659, //Planar mode: Y + V + U (3 planes) + pixelformatIyuv = 0x56555949, //Planar mode: Y + U + V (3 planes) + pixelformatYuy2 = 0x32595559, //Packed mode: Y0+U0+Y1+V0 (1 plane) + pixelformatUyvy = 0x59565955, //Packed mode: U0+Y0+V0+Y1 (1 plane) + pixelformatYvyu = 0x55595659, //Packed mode: Y0+V0+Y1+U0 (1 plane) + pixelformatNv12 = 0x3231564e, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatNv21 = 0x3132564e, //Planar mode: Y + V/U interleaved (2 planes) + pixelformatP010 = 0x30313050, //Planar mode: Y + U/V interleaved (2 planes) + pixelformatExternalOes = 0x2053454f, //Android video texture format + pixelformatMjpg = 0x47504a4d, //Motion JPEG +}; + +pub const Point = extern struct { + x: c_int, + y: c_int, +}; + +pub const Surface = opaque {}; + +pub const PropertiesID = u32; + +pub const Rect = extern struct { + x: c_int, + y: c_int, + w: c_int, + h: c_int, +}; + +pub const FunctionPointer = c.SDL_FunctionPointer; + +pub const DisplayID = u32; + +pub const WindowID = u32; + +pub const SystemTheme = enum(c_int) { + systemThemeUnknown, //Unknown system theme + systemThemeLight, //Light colored system theme + systemThemeDark, //Dark colored system theme +}; + +pub const DisplayModeData = opaque {}; + +pub const DisplayMode = extern struct { + displayID: DisplayID, // the display this mode is associated with + format: PixelFormat, // pixel format + w: c_int, // width + h: c_int, // height + pixel_density: f32, // scale converting size to pixels (e.g. a 1920x1080 mode with 2.0 scale would have 3840x2160 pixels) + refresh_rate: f32, // refresh rate (or 0.0f for unspecified) + refresh_rate_numerator: c_int, // precise refresh rate numerator (or 0 for unspecified) + refresh_rate_denominator: c_int, // precise refresh rate denominator + internal: ?*DisplayModeData, // Private +}; + +pub const DisplayOrientation = enum(c_int) { + orientationUnknown, //The display orientation can't be determined + orientationLandscape, //The display is in landscape mode, with the right side up, relative to portrait mode + orientationLandscapeFlipped, //The display is in landscape mode, with the left side up, relative to portrait mode + orientationPortrait, //The display is in portrait mode + orientationPortraitFlipped, +}; + +pub const Window = opaque { + pub inline fn getDisplayForWindow(window: *Window) DisplayID { + return c.SDL_GetDisplayForWindow(@ptrCast(window)); + } + + pub inline fn getWindowPixelDensity(window: *Window) f32 { + return c.SDL_GetWindowPixelDensity(@ptrCast(window)); + } + + pub inline fn getWindowDisplayScale(window: *Window) f32 { + return c.SDL_GetWindowDisplayScale(@ptrCast(window)); + } + + pub inline fn setWindowFullscreenMode(window: *Window, mode: *const DisplayMode) bool { + return @bitCast(c.SDL_SetWindowFullscreenMode(@ptrCast(window), @ptrCast(mode))); + } + + pub inline fn getWindowFullscreenMode(window: *Window) *const DisplayMode { + return @ptrCast(c.SDL_GetWindowFullscreenMode(@ptrCast(window))); + } + + pub inline fn getWindowICCProfile(window: *Window, size: *usize) ?*anyopaque { + return c.SDL_GetWindowICCProfile(@ptrCast(window), @ptrCast(size)); + } + + pub inline fn getWindowPixelFormat(window: *Window) PixelFormat { + return @bitCast(c.SDL_GetWindowPixelFormat(@ptrCast(window))); + } + + pub inline fn createPopupWindow(window: *Window, offset_x: c_int, offset_y: c_int, w: c_int, h: c_int, flags: WindowFlags) ?*Window { + return @ptrCast(c.SDL_CreatePopupWindow(@ptrCast(window), offset_x, offset_y, w, h, @bitCast(flags))); + } + + pub inline fn getWindowID(window: *Window) WindowID { + return c.SDL_GetWindowID(@ptrCast(window)); + } + + pub inline fn getWindowParent(window: *Window) ?*Window { + return @ptrCast(c.SDL_GetWindowParent(@ptrCast(window))); + } + + pub inline fn getWindowProperties(window: *Window) PropertiesID { + return c.SDL_GetWindowProperties(@ptrCast(window)); + } + + pub inline fn getWindowFlags(window: *Window) WindowFlags { + return @bitCast(c.SDL_GetWindowFlags(@ptrCast(window))); + } + + pub inline fn setWindowTitle(window: *Window, title: [*c]const u8) bool { + return @bitCast(c.SDL_SetWindowTitle(@ptrCast(window), title)); + } + + pub inline fn getWindowTitle(window: *Window) [*c]const u8 { + return c.SDL_GetWindowTitle(@ptrCast(window)); + } + + pub inline fn setWindowIcon(window: *Window, icon: ?*Surface) bool { + return @bitCast(c.SDL_SetWindowIcon(@ptrCast(window), @ptrCast(icon))); + } + + pub inline fn setWindowPosition(window: *Window, x: c_int, y: c_int) bool { + return @bitCast(c.SDL_SetWindowPosition(@ptrCast(window), x, y)); + } + + pub inline fn getWindowPosition(window: *Window, x: *c_int, y: *c_int) bool { + return @bitCast(c.SDL_GetWindowPosition(@ptrCast(window), @ptrCast(x), @ptrCast(y))); + } + + pub inline fn setWindowSize(window: *Window, w: c_int, h: c_int) bool { + return @bitCast(c.SDL_SetWindowSize(@ptrCast(window), w, h)); + } + + pub inline fn getWindowSize(window: *Window, w: *c_int, h: *c_int) bool { + return @bitCast(c.SDL_GetWindowSize(@ptrCast(window), @ptrCast(w), @ptrCast(h))); + } + + pub inline fn getWindowSafeArea(window: *Window, rect: ?*Rect) bool { + return @bitCast(c.SDL_GetWindowSafeArea(@ptrCast(window), @ptrCast(rect))); + } + + pub inline fn setWindowAspectRatio(window: *Window, min_aspect: f32, max_aspect: f32) bool { + return @bitCast(c.SDL_SetWindowAspectRatio(@ptrCast(window), min_aspect, max_aspect)); + } + + pub inline fn getWindowAspectRatio(window: *Window, min_aspect: *f32, max_aspect: *f32) bool { + return @bitCast(c.SDL_GetWindowAspectRatio(@ptrCast(window), @ptrCast(min_aspect), @ptrCast(max_aspect))); + } + + pub inline fn getWindowBordersSize(window: *Window, top: *c_int, left: *c_int, bottom: *c_int, right: *c_int) bool { + return @bitCast(c.SDL_GetWindowBordersSize(@ptrCast(window), @ptrCast(top), @ptrCast(left), @ptrCast(bottom), @ptrCast(right))); + } + + pub inline fn getWindowSizeInPixels(window: *Window, w: *c_int, h: *c_int) bool { + return @bitCast(c.SDL_GetWindowSizeInPixels(@ptrCast(window), @ptrCast(w), @ptrCast(h))); + } + + pub inline fn setWindowMinimumSize(window: *Window, min_w: c_int, min_h: c_int) bool { + return @bitCast(c.SDL_SetWindowMinimumSize(@ptrCast(window), min_w, min_h)); + } + + pub inline fn getWindowMinimumSize(window: *Window, w: *c_int, h: *c_int) bool { + return @bitCast(c.SDL_GetWindowMinimumSize(@ptrCast(window), @ptrCast(w), @ptrCast(h))); + } + + pub inline fn setWindowMaximumSize(window: *Window, max_w: c_int, max_h: c_int) bool { + return @bitCast(c.SDL_SetWindowMaximumSize(@ptrCast(window), max_w, max_h)); + } + + pub inline fn getWindowMaximumSize(window: *Window, w: *c_int, h: *c_int) bool { + return @bitCast(c.SDL_GetWindowMaximumSize(@ptrCast(window), @ptrCast(w), @ptrCast(h))); + } + + pub inline fn setWindowBordered(window: *Window, bordered: bool) bool { + return @bitCast(c.SDL_SetWindowBordered(@ptrCast(window), @bitCast(bordered))); + } + + pub inline fn setWindowResizable(window: *Window, resizable: bool) bool { + return @bitCast(c.SDL_SetWindowResizable(@ptrCast(window), @bitCast(resizable))); + } + + pub inline fn setWindowAlwaysOnTop(window: *Window, on_top: bool) bool { + return @bitCast(c.SDL_SetWindowAlwaysOnTop(@ptrCast(window), @bitCast(on_top))); + } + + pub inline fn setWindowFillDocument(window: *Window, fill: bool) bool { + return @bitCast(c.SDL_SetWindowFillDocument(@ptrCast(window), @bitCast(fill))); + } + + pub inline fn showWindow(window: *Window) bool { + return @bitCast(c.SDL_ShowWindow(@ptrCast(window))); + } + + pub inline fn hideWindow(window: *Window) bool { + return @bitCast(c.SDL_HideWindow(@ptrCast(window))); + } + + pub inline fn raiseWindow(window: *Window) bool { + return @bitCast(c.SDL_RaiseWindow(@ptrCast(window))); + } + + pub inline fn maximizeWindow(window: *Window) bool { + return @bitCast(c.SDL_MaximizeWindow(@ptrCast(window))); + } + + pub inline fn minimizeWindow(window: *Window) bool { + return @bitCast(c.SDL_MinimizeWindow(@ptrCast(window))); + } + + pub inline fn restoreWindow(window: *Window) bool { + return @bitCast(c.SDL_RestoreWindow(@ptrCast(window))); + } + + pub inline fn setWindowFullscreen(window: *Window, fullscreen: bool) bool { + return @bitCast(c.SDL_SetWindowFullscreen(@ptrCast(window), @bitCast(fullscreen))); + } + + pub inline fn syncWindow(window: *Window) bool { + return @bitCast(c.SDL_SyncWindow(@ptrCast(window))); + } + + pub inline fn windowHasSurface(window: *Window) bool { + return @bitCast(c.SDL_WindowHasSurface(@ptrCast(window))); + } + + pub inline fn getWindowSurface(window: *Window) ?*Surface { + return @ptrCast(c.SDL_GetWindowSurface(@ptrCast(window))); + } + + pub inline fn setWindowSurfaceVSync(window: *Window, vsync: c_int) bool { + return @bitCast(c.SDL_SetWindowSurfaceVSync(@ptrCast(window), vsync)); + } + + pub inline fn getWindowSurfaceVSync(window: *Window, vsync: *c_int) bool { + return @bitCast(c.SDL_GetWindowSurfaceVSync(@ptrCast(window), @ptrCast(vsync))); + } + + pub inline fn updateWindowSurface(window: *Window) bool { + return @bitCast(c.SDL_UpdateWindowSurface(@ptrCast(window))); + } + + pub inline fn updateWindowSurfaceRects(window: *Window, rects: *const Rect, numrects: c_int) bool { + return @bitCast(c.SDL_UpdateWindowSurfaceRects(@ptrCast(window), @ptrCast(rects), numrects)); + } + + pub inline fn destroyWindowSurface(window: *Window) bool { + return @bitCast(c.SDL_DestroyWindowSurface(@ptrCast(window))); + } + + pub inline fn setWindowKeyboardGrab(window: *Window, grabbed: bool) bool { + return @bitCast(c.SDL_SetWindowKeyboardGrab(@ptrCast(window), @bitCast(grabbed))); + } + + pub inline fn setWindowMouseGrab(window: *Window, grabbed: bool) bool { + return @bitCast(c.SDL_SetWindowMouseGrab(@ptrCast(window), @bitCast(grabbed))); + } + + pub inline fn getWindowKeyboardGrab(window: *Window) bool { + return @bitCast(c.SDL_GetWindowKeyboardGrab(@ptrCast(window))); + } + + pub inline fn getWindowMouseGrab(window: *Window) bool { + return @bitCast(c.SDL_GetWindowMouseGrab(@ptrCast(window))); + } + + pub inline fn setWindowMouseRect(window: *Window, rect: *const Rect) bool { + return @bitCast(c.SDL_SetWindowMouseRect(@ptrCast(window), @ptrCast(rect))); + } + + pub inline fn getWindowMouseRect(window: *Window) *const Rect { + return @ptrCast(c.SDL_GetWindowMouseRect(@ptrCast(window))); + } + + pub inline fn setWindowOpacity(window: *Window, opacity: f32) bool { + return @bitCast(c.SDL_SetWindowOpacity(@ptrCast(window), opacity)); + } + + pub inline fn getWindowOpacity(window: *Window) f32 { + return c.SDL_GetWindowOpacity(@ptrCast(window)); + } + + pub inline fn setWindowParent(window: *Window, parent: ?*Window) bool { + return @bitCast(c.SDL_SetWindowParent(@ptrCast(window), @ptrCast(parent))); + } + + pub inline fn setWindowModal(window: *Window, modal: bool) bool { + return @bitCast(c.SDL_SetWindowModal(@ptrCast(window), @bitCast(modal))); + } + + pub inline fn setWindowFocusable(window: *Window, focusable: bool) bool { + return @bitCast(c.SDL_SetWindowFocusable(@ptrCast(window), @bitCast(focusable))); + } + + pub inline fn showWindowSystemMenu(window: *Window, x: c_int, y: c_int) bool { + return @bitCast(c.SDL_ShowWindowSystemMenu(@ptrCast(window), x, y)); + } + + pub inline fn setWindowHitTest(window: *Window, callback: HitTest, callback_data: ?*anyopaque) bool { + return @bitCast(c.SDL_SetWindowHitTest(@ptrCast(window), callback, callback_data)); + } + + pub inline fn setWindowShape(window: *Window, shape: ?*Surface) bool { + return @bitCast(c.SDL_SetWindowShape(@ptrCast(window), @ptrCast(shape))); + } + + pub inline fn flashWindow(window: *Window, operation: FlashOperation) bool { + return @bitCast(c.SDL_FlashWindow(@ptrCast(window), @intFromEnum(operation))); + } + + pub inline fn setWindowProgressState(window: *Window, state: ProgressState) bool { + return @bitCast(c.SDL_SetWindowProgressState(@ptrCast(window), state)); + } + + pub inline fn getWindowProgressState(window: *Window) ProgressState { + return c.SDL_GetWindowProgressState(@ptrCast(window)); + } + + pub inline fn setWindowProgressValue(window: *Window, value: f32) bool { + return @bitCast(c.SDL_SetWindowProgressValue(@ptrCast(window), value)); + } + + pub inline fn getWindowProgressValue(window: *Window) f32 { + return c.SDL_GetWindowProgressValue(@ptrCast(window)); + } + + pub inline fn destroyWindow(window: *Window) void { + return c.SDL_DestroyWindow(@ptrCast(window)); + } + + pub inline fn gl_CreateContext(window: *Window) GLContext { + return c.SDL_GL_CreateContext(@ptrCast(window)); + } + + pub inline fn gl_MakeCurrent(window: *Window, context: GLContext) bool { + return @bitCast(c.SDL_GL_MakeCurrent(@ptrCast(window), context)); + } + + pub inline fn egl_GetWindowSurface(window: *Window) EGLSurface { + return c.SDL_EGL_GetWindowSurface(@ptrCast(window)); + } + + pub inline fn gl_SwapWindow(window: *Window) bool { + return @bitCast(c.SDL_GL_SwapWindow(@ptrCast(window))); + } +}; + +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 + windowFillDocument: bool = false, // window is in fill-document mode (Emscripten only), since SDL 3.4.0 + 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: u37 = 0, + rsvd: bool = false, + + pub const None = WindowFlags{}; +}; + +pub const FlashOperation = enum(c_int) { + flashCancel, //Cancel any window flash state + flashBriefly, //Flash the window briefly to get attention + flashUntilFocused, //Flash the window until it gets focus +}; + +pub const ProgressState = enum(c_int) { + progressStateInvalid = -1, //An invalid progress state indicating an error; check SDL_GetError() + progressStateNone, //No progress bar is shown + progressStateIndeterminate, //The progress bar is shown in a indeterminate state + progressStateNormal, //The progress bar is shown in a normal state + progressStatePaused, //The progress bar is shown in a paused state + progressStateError, //The progress bar is shown in a state indicating the application had an error +}; + +pub const GLContext = *anyopaque; + +pub const EGLDisplay = ?*anyopaque; + +pub const EGLConfig = ?*anyopaque; + +pub const EGLSurface = ?*anyopaque; + +pub const EGLAttrib = isize; + +pub const EGLint = c_int; + +pub const EGLAttribArrayCallback = c.SDL_EGLAttribArrayCallback; + +pub const EGLIntArrayCallback = c.SDL_EGLIntArrayCallback; + +pub const GLAttr = enum(c_int) { + glRedSize, //the minimum number of bits for the red channel of the color buffer; defaults to 8. + glGreenSize, //the minimum number of bits for the green channel of the color buffer; defaults to 8. + glBlueSize, //the minimum number of bits for the blue channel of the color buffer; defaults to 8. + glAlphaSize, //the minimum number of bits for the alpha channel of the color buffer; defaults to 8. + glBufferSize, //the minimum number of bits for frame buffer size; defaults to 0. + glDoublebuffer, //whether the output is single or double buffered; defaults to double buffering on. + glDepthSize, //the minimum number of bits in the depth buffer; defaults to 16. + glStencilSize, //the minimum number of bits in the stencil buffer; defaults to 0. + glAccumRedSize, //the minimum number of bits for the red channel of the accumulation buffer; defaults to 0. + glAccumGreenSize, //the minimum number of bits for the green channel of the accumulation buffer; defaults to 0. + glAccumBlueSize, //the minimum number of bits for the blue channel of the accumulation buffer; defaults to 0. + glAccumAlphaSize, //the minimum number of bits for the alpha channel of the accumulation buffer; defaults to 0. + glStereo, //whether the output is stereo 3D; defaults to off. + glMultisamplebuffers, //the number of buffers used for multisample anti-aliasing; defaults to 0. + glMultisamplesamples, //the number of samples used around the current pixel used for multisample anti-aliasing. + glAcceleratedVisual, //set to 1 to require hardware acceleration, set to 0 to force software rendering; defaults to allow either. + glRetainedBacking, //not used (deprecated). + glContextMajorVersion, //OpenGL context major version. + glContextMinorVersion, //OpenGL context minor version. + glContextFlags, //some combination of 0 or more of elements of the SDL_GLContextFlag enumeration; defaults to 0. + glContextProfileMask, //type of GL context (Core, Compatibility, ES). See SDL_GLProfile; default value depends on platform. + glShareWithCurrentContext, //OpenGL context sharing; defaults to 0. + glFramebufferSrgbCapable, //requests sRGB-capable visual if 1. Defaults to -1 ("don't care"). This is a request; GL drivers might not comply! + glContextReleaseBehavior, //sets context the release behavior. See SDL_GLContextReleaseFlag; defaults to FLUSH. + glContextResetNotification, //set context reset notification. See SDL_GLContextResetNotification; defaults to NO_NOTIFICATION. + glContextNoError, + glFloatbuffers, + glEglPlatform, +}; + +pub const GLProfile = u32; + +pub const GLContextFlag = u32; + +pub const GLContextReleaseFlag = u32; + +pub const GLContextResetNotification = u32; + +pub inline fn getNumVideoDrivers() c_int { + return c.SDL_GetNumVideoDrivers(); +} + +pub inline fn getVideoDriver(index: c_int) [*c]const u8 { + return c.SDL_GetVideoDriver(index); +} + +pub inline fn getCurrentVideoDriver() [*c]const u8 { + return c.SDL_GetCurrentVideoDriver(); +} + +pub inline fn getSystemTheme() SystemTheme { + return c.SDL_GetSystemTheme(); +} + +pub inline fn getDisplays(count: *c_int) ?*DisplayID { + return @ptrCast(c.SDL_GetDisplays(@ptrCast(count))); +} + +pub inline fn getPrimaryDisplay() DisplayID { + return c.SDL_GetPrimaryDisplay(); +} + +pub inline fn getDisplayProperties(displayID: DisplayID) PropertiesID { + return c.SDL_GetDisplayProperties(displayID); +} + +pub inline fn getDisplayName(displayID: DisplayID) [*c]const u8 { + return c.SDL_GetDisplayName(displayID); +} + +pub inline fn getDisplayBounds(displayID: DisplayID, rect: ?*Rect) bool { + return @bitCast(c.SDL_GetDisplayBounds(displayID, @ptrCast(rect))); +} + +pub inline fn getDisplayUsableBounds(displayID: DisplayID, rect: ?*Rect) bool { + return @bitCast(c.SDL_GetDisplayUsableBounds(displayID, @ptrCast(rect))); +} + +pub inline fn getNaturalDisplayOrientation(displayID: DisplayID) DisplayOrientation { + return c.SDL_GetNaturalDisplayOrientation(displayID); +} + +pub inline fn getCurrentDisplayOrientation(displayID: DisplayID) DisplayOrientation { + return c.SDL_GetCurrentDisplayOrientation(displayID); +} + +pub inline fn getDisplayContentScale(displayID: DisplayID) f32 { + return c.SDL_GetDisplayContentScale(displayID); +} + +pub inline fn getFullscreenDisplayModes(displayID: DisplayID, count: *c_int) [*c][*c]DisplayMode { + return @intFromEnum(c.SDL_GetFullscreenDisplayModes(displayID, @ptrCast(count))); +} + +pub inline fn getClosestFullscreenDisplayMode(displayID: DisplayID, w: c_int, h: c_int, refresh_rate: f32, include_high_density_modes: bool, closest: ?*DisplayMode) bool { + return @bitCast(c.SDL_GetClosestFullscreenDisplayMode(displayID, w, h, refresh_rate, @bitCast(include_high_density_modes), @ptrCast(closest))); +} + +pub inline fn getDesktopDisplayMode(displayID: DisplayID) *const DisplayMode { + return @ptrCast(c.SDL_GetDesktopDisplayMode(displayID)); +} + +pub inline fn getCurrentDisplayMode(displayID: DisplayID) *const DisplayMode { + return @ptrCast(c.SDL_GetCurrentDisplayMode(displayID)); +} + +pub inline fn getDisplayForPoint(point: *const Point) DisplayID { + return c.SDL_GetDisplayForPoint(@ptrCast(point)); +} + +pub inline fn getDisplayForRect(rect: *const Rect) DisplayID { + return c.SDL_GetDisplayForRect(@ptrCast(rect)); +} + +pub inline fn getWindows(count: *c_int) [*c][*c]Window { + return c.SDL_GetWindows(@ptrCast(count)); +} + +pub inline fn createWindow(title: [*c]const u8, w: c_int, h: c_int, flags: WindowFlags) ?*Window { + return @ptrCast(c.SDL_CreateWindow(title, w, h, @bitCast(flags))); +} + +pub inline fn createWindowWithProperties(props: PropertiesID) ?*Window { + return @ptrCast(c.SDL_CreateWindowWithProperties(props)); +} + +pub inline fn getWindowFromID(id: WindowID) ?*Window { + return @ptrCast(c.SDL_GetWindowFromID(id)); +} + +pub inline fn getGrabbedWindow() ?*Window { + return @ptrCast(c.SDL_GetGrabbedWindow()); +} + +pub const HitTestResult = enum(c_int) { + hittestNormal, //Region is normal. No special properties. + hittestDraggable, //Region can drag entire window. + hittestResizeTopleft, //Region is the resizable top-left corner border. + hittestResizeTop, //Region is the resizable top border. + hittestResizeTopright, //Region is the resizable top-right corner border. + hittestResizeRight, //Region is the resizable right border. + hittestResizeBottomright, //Region is the resizable bottom-right corner border. + hittestResizeBottom, //Region is the resizable bottom border. + hittestResizeBottomleft, //Region is the resizable bottom-left corner border. + hittestResizeLeft, //Region is the resizable left border. +}; + +pub const HitTest = c.SDL_HitTest; + +pub inline fn screenSaverEnabled() bool { + return @bitCast(c.SDL_ScreenSaverEnabled()); +} + +pub inline fn enableScreenSaver() bool { + return @bitCast(c.SDL_EnableScreenSaver()); +} + +pub inline fn disableScreenSaver() bool { + return @bitCast(c.SDL_DisableScreenSaver()); +} + +pub inline fn gl_LoadLibrary(path: [*c]const u8) bool { + return @bitCast(c.SDL_GL_LoadLibrary(path)); +} + +pub inline fn gl_GetProcAddress(proc: [*c]const u8) FunctionPointer { + return c.SDL_GL_GetProcAddress(proc); +} + +pub inline fn egl_GetProcAddress(proc: [*c]const u8) FunctionPointer { + return c.SDL_EGL_GetProcAddress(proc); +} + +pub inline fn gl_UnloadLibrary() void { + return c.SDL_GL_UnloadLibrary(); +} + +pub inline fn gl_ExtensionSupported(extension: [*c]const u8) bool { + return @bitCast(c.SDL_GL_ExtensionSupported(extension)); +} + +pub inline fn gl_ResetAttributes() void { + return c.SDL_GL_ResetAttributes(); +} + +pub inline fn gl_SetAttribute(attr: GLAttr, value: c_int) bool { + return @bitCast(c.SDL_GL_SetAttribute(attr, value)); +} + +pub inline fn gl_GetAttribute(attr: GLAttr, value: *c_int) bool { + return @bitCast(c.SDL_GL_GetAttribute(attr, @ptrCast(value))); +} + +pub inline fn gl_GetCurrentWindow() ?*Window { + return @ptrCast(c.SDL_GL_GetCurrentWindow()); +} + +pub inline fn gl_GetCurrentContext() GLContext { + return c.SDL_GL_GetCurrentContext(); +} + +pub inline fn egl_GetCurrentDisplay() EGLDisplay { + return c.SDL_EGL_GetCurrentDisplay(); +} + +pub inline fn egl_GetCurrentConfig() EGLConfig { + return c.SDL_EGL_GetCurrentConfig(); +} + +pub inline fn egl_SetAttributeCallbacks(platformAttribCallback: EGLAttribArrayCallback, surfaceAttribCallback: EGLIntArrayCallback, contextAttribCallback: EGLIntArrayCallback, userdata: ?*anyopaque) void { + return c.SDL_EGL_SetAttributeCallbacks(platformAttribCallback, surfaceAttribCallback, contextAttribCallback, userdata); +} + +pub inline fn gl_SetSwapInterval(interval: c_int) bool { + return @bitCast(c.SDL_GL_SetSwapInterval(interval)); +} + +pub inline fn gl_GetSwapInterval(interval: *c_int) bool { + return @bitCast(c.SDL_GL_GetSwapInterval(@ptrCast(interval))); +} + +pub inline fn gl_DestroyContext(context: GLContext) bool { + return @bitCast(c.SDL_GL_DestroyContext(context)); +} diff --git a/sdl3-zig/src/audio.zig b/sdl3-zig/src/audio.zig new file mode 100644 index 0000000..76ea45d --- /dev/null +++ b/sdl3-zig/src/audio.zig @@ -0,0 +1,269 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const IOStream = opaque { + pub inline fn loadWAV_IO(iostream: *IOStream, closeio: bool, spec: ?*AudioSpec, audio_buf: [*c][*c]u8, audio_len: *u32) bool { + return c.SDL_LoadWAV_IO(iostream, closeio, spec, audio_buf, @ptrCast(audio_len)); + } + +}; + +pub const PropertiesID = u32; + +pub const AudioFormat = enum(c_int) { + audioUnknown = 0x0000u, //Unspecified audio format + audioU8 = 0x0008u, //Unsigned 8-bit samples + audioS8 = 0x8008u, //Signed 8-bit samples + audioS16le = 0x8010u, //Signed 16-bit samples + audioS16be = 0x9010u, //As above, but big-endian byte order + audioS32le = 0x8020u, //32-bit integer samples + audioS32be = 0x9020u, //As above, but big-endian byte order + audioF32le = 0x8120u, //32-bit floating point samples + audioF32be = 0x9120u, //As above, but big-endian byte order +}; + +pub const AudioDeviceID = u32; + +pub const AudioSpec = extern struct { + format: AudioFormat, // Audio data format + channels: c_int, // Number of channels: 1 mono, 2 stereo, etc + freq: c_int, // sample rate: sample frames per second +}; + +pub const AudioStream = opaque { + pub inline fn unbindAudioStream(audiostream: *AudioStream) void { + return c.SDL_UnbindAudioStream(audiostream); + } + + pub inline fn getAudioStreamDevice(audiostream: *AudioStream) AudioDeviceID { + return c.SDL_GetAudioStreamDevice(audiostream); + } + + pub inline fn getAudioStreamProperties(audiostream: *AudioStream) PropertiesID { + return c.SDL_GetAudioStreamProperties(audiostream); + } + + pub inline fn getAudioStreamFormat(audiostream: *AudioStream, src_spec: ?*AudioSpec, dst_spec: ?*AudioSpec) bool { + return c.SDL_GetAudioStreamFormat(audiostream, src_spec, dst_spec); + } + + pub inline fn setAudioStreamFormat(audiostream: *AudioStream, src_spec: *const AudioSpec, dst_spec: *const AudioSpec) bool { + return c.SDL_SetAudioStreamFormat(audiostream, @ptrCast(src_spec), @ptrCast(dst_spec)); + } + + pub inline fn getAudioStreamFrequencyRatio(audiostream: *AudioStream) f32 { + return c.SDL_GetAudioStreamFrequencyRatio(audiostream); + } + + pub inline fn setAudioStreamFrequencyRatio(audiostream: *AudioStream, ratio: f32) bool { + return c.SDL_SetAudioStreamFrequencyRatio(audiostream, ratio); + } + + pub inline fn getAudioStreamGain(audiostream: *AudioStream) f32 { + return c.SDL_GetAudioStreamGain(audiostream); + } + + pub inline fn setAudioStreamGain(audiostream: *AudioStream, gain: f32) bool { + return c.SDL_SetAudioStreamGain(audiostream, gain); + } + + pub inline fn getAudioStreamInputChannelMap(audiostream: *AudioStream, count: *c_int) *c_int { + return @ptrCast(c.SDL_GetAudioStreamInputChannelMap(audiostream, @ptrCast(count))); + } + + pub inline fn getAudioStreamOutputChannelMap(audiostream: *AudioStream, count: *c_int) *c_int { + return @ptrCast(c.SDL_GetAudioStreamOutputChannelMap(audiostream, @ptrCast(count))); + } + + pub inline fn setAudioStreamInputChannelMap(audiostream: *AudioStream, chmap: [*c]const c_int, count: c_int) bool { + return c.SDL_SetAudioStreamInputChannelMap(audiostream, chmap, count); + } + + pub inline fn setAudioStreamOutputChannelMap(audiostream: *AudioStream, chmap: [*c]const c_int, count: c_int) bool { + return c.SDL_SetAudioStreamOutputChannelMap(audiostream, chmap, count); + } + + pub inline fn putAudioStreamData(audiostream: *AudioStream, buf: ?*const anyopaque, len: c_int) bool { + return c.SDL_PutAudioStreamData(audiostream, buf, len); + } + + pub inline fn putAudioStreamDataNoCopy(audiostream: *AudioStream, buf: ?*const anyopaque, len: c_int, callback: AudioStreamDataCompleteCallback, userdata: ?*anyopaque) bool { + return c.SDL_PutAudioStreamDataNoCopy(audiostream, buf, len, callback, userdata); + } + + pub inline fn putAudioStreamPlanarData(audiostream: *AudioStream, channel_buffers: [*c]const void * const, num_channels: c_int, num_samples: c_int) bool { + return c.SDL_PutAudioStreamPlanarData(audiostream, channel_buffers, num_channels, num_samples); + } + + pub inline fn getAudioStreamData(audiostream: *AudioStream, buf: ?*anyopaque, len: c_int) c_int { + return c.SDL_GetAudioStreamData(audiostream, buf, len); + } + + pub inline fn getAudioStreamAvailable(audiostream: *AudioStream) c_int { + return c.SDL_GetAudioStreamAvailable(audiostream); + } + + pub inline fn getAudioStreamQueued(audiostream: *AudioStream) c_int { + return c.SDL_GetAudioStreamQueued(audiostream); + } + + pub inline fn flushAudioStream(audiostream: *AudioStream) bool { + return c.SDL_FlushAudioStream(audiostream); + } + + pub inline fn clearAudioStream(audiostream: *AudioStream) bool { + return c.SDL_ClearAudioStream(audiostream); + } + + pub inline fn pauseAudioStreamDevice(audiostream: *AudioStream) bool { + return c.SDL_PauseAudioStreamDevice(audiostream); + } + + pub inline fn resumeAudioStreamDevice(audiostream: *AudioStream) bool { + return c.SDL_ResumeAudioStreamDevice(audiostream); + } + + pub inline fn audioStreamDevicePaused(audiostream: *AudioStream) bool { + return c.SDL_AudioStreamDevicePaused(audiostream); + } + + pub inline fn lockAudioStream(audiostream: *AudioStream) bool { + return c.SDL_LockAudioStream(audiostream); + } + + pub inline fn unlockAudioStream(audiostream: *AudioStream) bool { + return c.SDL_UnlockAudioStream(audiostream); + } + + pub inline fn setAudioStreamGetCallback(audiostream: *AudioStream, callback: AudioStreamCallback, userdata: ?*anyopaque) bool { + return c.SDL_SetAudioStreamGetCallback(audiostream, callback, userdata); + } + + pub inline fn setAudioStreamPutCallback(audiostream: *AudioStream, callback: AudioStreamCallback, userdata: ?*anyopaque) bool { + return c.SDL_SetAudioStreamPutCallback(audiostream, callback, userdata); + } + + pub inline fn destroyAudioStream(audiostream: *AudioStream) void { + return c.SDL_DestroyAudioStream(audiostream); + } + +}; + +pub inline fn getNumAudioDrivers() c_int { + return c.SDL_GetNumAudioDrivers(); +} + +pub inline fn getAudioDriver(index: c_int) [*c]const u8 { + return c.SDL_GetAudioDriver(index); +} + +pub inline fn getCurrentAudioDriver() [*c]const u8 { + return c.SDL_GetCurrentAudioDriver(); +} + +pub inline fn getAudioPlaybackDevices(count: *c_int) ?*AudioDeviceID { + return c.SDL_GetAudioPlaybackDevices(@ptrCast(count)); +} + +pub inline fn getAudioRecordingDevices(count: *c_int) ?*AudioDeviceID { + return c.SDL_GetAudioRecordingDevices(@ptrCast(count)); +} + +pub inline fn getAudioDeviceName(devid: AudioDeviceID) [*c]const u8 { + return c.SDL_GetAudioDeviceName(devid); +} + +pub inline fn getAudioDeviceFormat(devid: AudioDeviceID, spec: ?*AudioSpec, sample_frames: *c_int) bool { + return c.SDL_GetAudioDeviceFormat(devid, spec, @ptrCast(sample_frames)); +} + +pub inline fn getAudioDeviceChannelMap(devid: AudioDeviceID, count: *c_int) *c_int { + return @ptrCast(c.SDL_GetAudioDeviceChannelMap(devid, @ptrCast(count))); +} + +pub inline fn openAudioDevice(devid: AudioDeviceID, spec: *const AudioSpec) AudioDeviceID { + return c.SDL_OpenAudioDevice(devid, @ptrCast(spec)); +} + +pub inline fn isAudioDevicePhysical(devid: AudioDeviceID) bool { + return c.SDL_IsAudioDevicePhysical(devid); +} + +pub inline fn isAudioDevicePlayback(devid: AudioDeviceID) bool { + return c.SDL_IsAudioDevicePlayback(devid); +} + +pub inline fn pauseAudioDevice(devid: AudioDeviceID) bool { + return c.SDL_PauseAudioDevice(devid); +} + +pub inline fn resumeAudioDevice(devid: AudioDeviceID) bool { + return c.SDL_ResumeAudioDevice(devid); +} + +pub inline fn audioDevicePaused(devid: AudioDeviceID) bool { + return c.SDL_AudioDevicePaused(devid); +} + +pub inline fn getAudioDeviceGain(devid: AudioDeviceID) f32 { + return c.SDL_GetAudioDeviceGain(devid); +} + +pub inline fn setAudioDeviceGain(devid: AudioDeviceID, gain: f32) bool { + return c.SDL_SetAudioDeviceGain(devid, gain); +} + +pub inline fn closeAudioDevice(devid: AudioDeviceID) void { + return c.SDL_CloseAudioDevice(devid); +} + +pub inline fn bindAudioStreams(devid: AudioDeviceID, streams: [*c]*const AudioStream, num_streams: c_int) bool { + return c.SDL_BindAudioStreams(devid, streams, num_streams); +} + +pub inline fn bindAudioStream(devid: AudioDeviceID, stream: ?*AudioStream) bool { + return c.SDL_BindAudioStream(devid, stream); +} + +pub inline fn unbindAudioStreams(streams: [*c]*const AudioStream, num_streams: c_int) void { + return c.SDL_UnbindAudioStreams(streams, num_streams); +} + +pub inline fn createAudioStream(src_spec: *const AudioSpec, dst_spec: *const AudioSpec) ?*AudioStream { + return c.SDL_CreateAudioStream(@ptrCast(src_spec), @ptrCast(dst_spec)); +} + +pub const AudioStreamDataCompleteCallback = c.SDL_AudioStreamDataCompleteCallback; + +pub const AudioStreamCallback = c.SDL_AudioStreamCallback; + +pub inline fn openAudioDeviceStream(devid: AudioDeviceID, spec: *const AudioSpec, callback: AudioStreamCallback, userdata: ?*anyopaque) ?*AudioStream { + return c.SDL_OpenAudioDeviceStream(devid, @ptrCast(spec), callback, userdata); +} + +pub const AudioPostmixCallback = c.SDL_AudioPostmixCallback; + +pub inline fn setAudioPostmixCallback(devid: AudioDeviceID, callback: AudioPostmixCallback, userdata: ?*anyopaque) bool { + return c.SDL_SetAudioPostmixCallback(devid, callback, userdata); +} + +pub inline fn loadWAV(path: [*c]const u8, spec: ?*AudioSpec, audio_buf: [*c][*c]u8, audio_len: *u32) bool { + return c.SDL_LoadWAV(path, spec, audio_buf, @ptrCast(audio_len)); +} + +pub inline fn mixAudio(dst: [*c]u8, src: [*c]const u8, format: AudioFormat, len: u32, volume: f32) bool { + return c.SDL_MixAudio(dst, src, @bitCast(format), len, volume); +} + +pub inline fn convertAudioSamples(src_spec: *const AudioSpec, src_data: [*c]const u8, src_len: c_int, dst_spec: *const AudioSpec, dst_data: [*c][*c]u8, dst_len: *c_int) bool { + return c.SDL_ConvertAudioSamples(@ptrCast(src_spec), src_data, src_len, @ptrCast(dst_spec), dst_data, @ptrCast(dst_len)); +} + +pub inline fn getAudioFormatName(format: AudioFormat) [*c]const u8 { + return c.SDL_GetAudioFormatName(@bitCast(format)); +} + +pub inline fn getSilenceValueForFormat(format: AudioFormat) c_int { + return c.SDL_GetSilenceValueForFormat(@bitCast(format)); +} + diff --git a/sdl3-zig/src/blendmode.zig b/sdl3-zig/src/blendmode.zig new file mode 100644 index 0000000..5428b63 --- /dev/null +++ b/sdl3-zig/src/blendmode.zig @@ -0,0 +1,29 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const BlendMode = u32; + +pub const BlendOperation = enum(c_int) { + blendoperationAdd = 0x1, //dst + src: supported by all renderers + blendoperationSubtract = 0x2, //src - dst : supported by D3D, OpenGL, OpenGLES, and Vulkan + blendoperationRevSubtract = 0x3, //dst - src : supported by D3D, OpenGL, OpenGLES, and Vulkan + blendoperationMinimum = 0x4, //min(dst, src) : supported by D3D, OpenGL, OpenGLES, and Vulkan + blendoperationMaximum = 0x5, +}; + +pub const BlendFactor = enum(c_int) { + blendfactorZero = 0x1, //0, 0, 0, 0 + blendfactorOne = 0x2, //1, 1, 1, 1 + blendfactorSrcColor = 0x3, //srcR, srcG, srcB, srcA + blendfactorOneMinusSrcColor = 0x4, //1-srcR, 1-srcG, 1-srcB, 1-srcA + blendfactorSrcAlpha = 0x5, //srcA, srcA, srcA, srcA + blendfactorOneMinusSrcAlpha = 0x6, //1-srcA, 1-srcA, 1-srcA, 1-srcA + blendfactorDstColor = 0x7, //dstR, dstG, dstB, dstA + blendfactorOneMinusDstColor = 0x8, //1-dstR, 1-dstG, 1-dstB, 1-dstA + blendfactorDstAlpha = 0x9, //dstA, dstA, dstA, dstA + blendfactorOneMinusDstAlpha = 0xA, +}; + +pub inline fn composeCustomBlendMode(srcColorFactor: BlendFactor, dstColorFactor: BlendFactor, colorOperation: BlendOperation, srcAlphaFactor: BlendFactor, dstAlphaFactor: BlendFactor, alphaOperation: BlendOperation) BlendMode { + return @intFromEnum(c.SDL_ComposeCustomBlendMode(srcColorFactor, dstColorFactor, @intFromEnum(colorOperation), srcAlphaFactor, dstAlphaFactor, @intFromEnum(alphaOperation))); +} diff --git a/sdl3-zig/src/clipboard.zig b/sdl3-zig/src/clipboard.zig new file mode 100644 index 0000000..2847baa --- /dev/null +++ b/sdl3-zig/src/clipboard.zig @@ -0,0 +1,50 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn setClipboardText(text: [*c]const u8) bool { + return c.SDL_SetClipboardText(text); +} + +pub inline fn getClipboardText() [*c]u8 { + return c.SDL_GetClipboardText(); +} + +pub inline fn hasClipboardText() bool { + return c.SDL_HasClipboardText(); +} + +pub inline fn setPrimarySelectionText(text: [*c]const u8) bool { + return c.SDL_SetPrimarySelectionText(text); +} + +pub inline fn getPrimarySelectionText() [*c]u8 { + return c.SDL_GetPrimarySelectionText(); +} + +pub inline fn hasPrimarySelectionText() bool { + return c.SDL_HasPrimarySelectionText(); +} + +pub const ClipboardDataCallback = c.SDL_ClipboardDataCallback; + +pub const ClipboardCleanupCallback = c.SDL_ClipboardCleanupCallback; + +pub inline fn setClipboardData(callback: ClipboardDataCallback, cleanup: ClipboardCleanupCallback, userdata: ?*anyopaque, mime_types: [*c][*c]const u8, num_mime_types: usize) bool { + return c.SDL_SetClipboardData(callback, cleanup, userdata, mime_types, num_mime_types); +} + +pub inline fn clearClipboardData() bool { + return c.SDL_ClearClipboardData(); +} + +pub inline fn getClipboardData(mime_type: [*c]const u8, size: *usize) ?*anyopaque { + return c.SDL_GetClipboardData(mime_type, @ptrCast(size)); +} + +pub inline fn hasClipboardData(mime_type: [*c]const u8) bool { + return c.SDL_HasClipboardData(mime_type); +} + +pub inline fn getClipboardMimeTypes(num_mime_types: *usize) [*c][*c]u8 { + return c.SDL_GetClipboardMimeTypes(@ptrCast(num_mime_types)); +} diff --git a/sdl3-zig/src/dialog.zig b/sdl3-zig/src/dialog.zig new file mode 100644 index 0000000..17ee2ac --- /dev/null +++ b/sdl3-zig/src/dialog.zig @@ -0,0 +1,35 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque {}; + +pub const PropertiesID = u32; + +pub const DialogFileFilter = extern struct { + name: [*c]const u8, + pattern: [*c]const u8, +}; + +pub const DialogFileCallback = c.SDL_DialogFileCallback; + +pub inline fn showOpenFileDialog(callback: DialogFileCallback, userdata: ?*anyopaque, window: ?*Window, filters: *const DialogFileFilter, nfilters: c_int, default_location: [*c]const u8, allow_many: bool) void { + return c.SDL_ShowOpenFileDialog(callback, userdata, window, @ptrCast(filters), nfilters, default_location, allow_many); +} + +pub inline fn showSaveFileDialog(callback: DialogFileCallback, userdata: ?*anyopaque, window: ?*Window, filters: *const DialogFileFilter, nfilters: c_int, default_location: [*c]const u8) void { + return c.SDL_ShowSaveFileDialog(callback, userdata, window, @ptrCast(filters), nfilters, default_location); +} + +pub inline fn showOpenFolderDialog(callback: DialogFileCallback, userdata: ?*anyopaque, window: ?*Window, default_location: [*c]const u8, allow_many: bool) void { + return c.SDL_ShowOpenFolderDialog(callback, userdata, window, default_location, allow_many); +} + +pub const FileDialogType = enum(c_int) { + filedialogOpenfile, + filedialogSavefile, + filedialogOpenfolder, +}; + +pub inline fn showFileDialogWithProperties(_type: FileDialogType, callback: DialogFileCallback, userdata: ?*anyopaque, props: PropertiesID) void { + return c.SDL_ShowFileDialogWithProperties(@intFromEnum(_type), callback, userdata, props); +} diff --git a/sdl3-zig/src/endian.zig b/sdl3-zig/src/endian.zig new file mode 100644 index 0000000..c1f53b9 --- /dev/null +++ b/sdl3-zig/src/endian.zig @@ -0,0 +1,2 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; diff --git a/sdl3-zig/src/error.zig b/sdl3-zig/src/error.zig new file mode 100644 index 0000000..1954227 --- /dev/null +++ b/sdl3-zig/src/error.zig @@ -0,0 +1,14 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn outOfMemory() bool { + return c.SDL_OutOfMemory(); +} + +pub inline fn getError() [*c]const u8 { + return c.SDL_GetError(); +} + +pub inline fn clearError() bool { + return c.SDL_ClearError(); +} diff --git a/sdl3-zig/src/events.zig b/sdl3-zig/src/events.zig new file mode 100644 index 0000000..5443d1a --- /dev/null +++ b/sdl3-zig/src/events.zig @@ -0,0 +1,790 @@ +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 + penInputInProximity: bool = false, // pen is in proximity (since SDL 3.4.0) + pad0: u23 = 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 = 49, + scancodeNonushash = 50, + scancodeGrave = 53, + scancodeInsert = 73, + scancodeNumlockclear = 83, + scancodeNonusbackslash = 100, + scancodeApplication = 101, //windows contextual menu, compose + scancodePower = 102, + scancodeHelp = 117, //AL Integrated Help Center + scancodeMenu = 118, //Menu (show menu) + scancodeStop = 120, //AC Stop + scancodeAgain = 121, //AC Redo/Repeat + scancodeUndo = 122, //AC Undo + scancodeCut = 123, //AC Cut + scancodeCopy = 124, //AC Copy + scancodePaste = 125, //AC Paste + scancodeFind = 126, //AC Find + scancodeInternational1 = 135, + scancodeInternational3 = 137, //Yen + scancodeLang1 = 144, //Hangul/English toggle + scancodeLang2 = 145, //Hanja conversion + scancodeLang3 = 146, //Katakana + scancodeLang4 = 147, //Hiragana + scancodeLang5 = 148, //Zenkaku/Hankaku + scancodeLang6 = 149, //reserved + scancodeLang7 = 150, //reserved + scancodeLang8 = 151, //reserved + scancodeLang9 = 152, //reserved + scancodeAlterase = 153, //Erase-Eaze + scancodeCancel = 155, //AC Cancel + scancodeLalt = 226, //alt, option + scancodeLgui = 227, //windows, command (apple), meta + scancodeRalt = 230, //alt gr, option + scancodeRgui = 231, //windows, command (apple), meta + scancodeMode = 257, + scancodeSleep = 258, //Sleep + scancodeWake = 259, //Wake + scancodeChannelIncrement = 260, //Channel Increment + scancodeChannelDecrement = 261, //Channel Decrement + scancodeMediaPlay = 262, //Play + scancodeMediaPause = 263, //Pause + scancodeMediaRecord = 264, //Record + scancodeMediaFastForward = 265, //Fast Forward + scancodeMediaRewind = 266, //Rewind + scancodeMediaNextTrack = 267, //Next Track + scancodeMediaPreviousTrack = 268, //Previous Track + scancodeMediaStop = 269, //Stop + scancodeMediaEject = 270, //Eject + scancodeMediaPlayPause = 271, //Play / Pause + scancodeMediaSelect = 272, + scancodeAcNew = 273, //AC New + scancodeAcOpen = 274, //AC Open + scancodeAcClose = 275, //AC Close + scancodeAcExit = 276, //AC Exit + scancodeAcSave = 277, //AC Save + scancodeAcPrint = 278, //AC Print + scancodeAcProperties = 279, //AC Properties + scancodeAcSearch = 280, //AC Search + scancodeAcHome = 281, //AC Home + scancodeAcBack = 282, //AC Back + scancodeAcForward = 283, //AC Forward + scancodeAcStop = 284, //AC Stop + scancodeAcRefresh = 285, //AC Refresh + scancodeAcBookmarks = 286, //AC Bookmarks + scancodeSoftleft = 287, + scancodeSoftright = 288, + scancodeCall = 289, //Used for accepting phone calls. + scancodeEndcall = 290, //Used for rejecting phone calls. + scancodeReserved = 400, //400-500 reserved for dynamic keycodes + scancodeCount = 512, +}; + +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 = -1, //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 = 0, //Unused (do not remove) + eventQuit = 0x100, //User-requested quit + eventTerminating, + eventLowMemory, + eventWillEnterBackground, + eventDidEnterBackground, + eventWillEnterForeground, + eventDidEnterForeground, + eventLocaleChanged, //The user's locale preferences have changed. + eventSystemThemeChanged, //The system theme changed + eventDisplayOrientation = 0x151, //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 + eventDisplayUsableBoundsChanged, //Display has changed usable bounds + eventWindowShown = 0x202, //Window has been shown + eventWindowHidden, //Window has been hidden + eventWindowExposed, + 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 = 0x300, //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 + eventScreenKeyboardShown, //The on-screen keyboard has been shown + eventScreenKeyboardHidden, //The on-screen keyboard has been hidden + eventMouseMotion = 0x400, //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 = 0x600, //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 = 0x650, //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, + eventPinchBegin = 0x710, //Pinch gesture started + eventPinchUpdate, //Pinch gesture updated + eventPinchEnd, //Pinch gesture ended + eventClipboardUpdate = 0x900, //The clipboard changed + eventDropFile = 0x1000, //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 = 0x1100, //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 = 0x1200, //A sensor was updated + eventPenProximityIn = 0x1300, //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 = 0x1400, //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 = 0x2000, //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 = 0x7F00, //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_EVENT_DISPLAY_* + 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 PinchFingerEvent = extern struct { + _type: EventType, // ::SDL_EVENT_PINCH_BEGIN or ::SDL_EVENT_PINCH_UPDATE or ::SDL_EVENT_PINCH_END + reserved: u32, + timestamp: u64, // In nanoseconds, populated using SDL_GetTicksNS() + scale: f32, // The scale change since the last SDL_EVENT_PINCH_UPDATE. Scale < 1 is "zoom out". Scale > 1 is "zoom in". + 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, 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 + pinch: PinchFingerEvent, // Pinch 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)); +} + +pub inline fn getEventDescription(event: *const Event, buf: [*c]u8, buflen: c_int) c_int { + return c.SDL_GetEventDescription(@ptrCast(event), buf, buflen); +} diff --git a/sdl3-zig/src/filesystem.zig b/sdl3-zig/src/filesystem.zig new file mode 100644 index 0000000..f8ee2d4 --- /dev/null +++ b/sdl3-zig/src/filesystem.zig @@ -0,0 +1,92 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Time = i64; + +pub inline fn getBasePath() [*c]const u8 { + return c.SDL_GetBasePath(); +} + +pub inline fn getPrefPath(org: [*c]const u8, app: [*c]const u8) [*c]u8 { + return c.SDL_GetPrefPath(org, app); +} + +pub const Folder = enum(c_int) { + folderHome, //The folder which contains all of the current user's data, preferences, and documents. It usually contains most of the other folders. If a requested folder does not exist, the home folder can be considered a safe fallback to store a user's documents. + folderDesktop, //The folder of files that are displayed on the desktop. Note that the existence of a desktop folder does not guarantee that the system does show icons on its desktop; certain GNU/Linux distros with a graphical environment may not have desktop icons. + folderDocuments, //User document files, possibly application-specific. This is a good place to save a user's projects. + folderDownloads, //Standard folder for user files downloaded from the internet. + folderMusic, //Music files that can be played using a standard music player (mp3, ogg...). + folderPictures, //Image files that can be displayed using a standard viewer (png, jpg...). + folderPublicshare, //Files that are meant to be shared with other users on the same computer. + folderSavedgames, //Save files for games. + folderScreenshots, //Application screenshots. + folderTemplates, //Template files to be used when the user requests the desktop environment to create a new file in a certain folder, such as "New Text File.txt". Any file in the Templates folder can be used as a starting point for a new file. + folderVideos, //Video files that can be played using a standard video player (mp4, webm...). + folderCount, +}; + +pub inline fn getUserFolder(folder: Folder) [*c]const u8 { + return c.SDL_GetUserFolder(folder); +} + +pub const PathType = enum(c_int) { + pathtypeNone, //path does not exist + pathtypeFile, //a normal file + pathtypeDirectory, //a directory + pathtypeOther, +}; + +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 GlobFlags = packed struct(u32) { + globCaseinsensitive: bool = false, + pad0: u30 = 0, + rsvd: bool = false, +}; + +pub inline fn createDirectory(path: [*c]const u8) bool { + return c.SDL_CreateDirectory(path); +} + +pub const EnumerationResult = enum(c_int) { + enumContinue, //Value that requests that enumeration continue. + enumSuccess, //Value that requests that enumeration stop, successfully. + enumFailure, +}; + +pub const EnumerateDirectoryCallback = c.SDL_EnumerateDirectoryCallback; + +pub inline fn enumerateDirectory(path: [*c]const u8, callback: EnumerateDirectoryCallback, userdata: ?*anyopaque) bool { + return c.SDL_EnumerateDirectory(path, callback, userdata); +} + +pub inline fn removePath(path: [*c]const u8) bool { + return c.SDL_RemovePath(path); +} + +pub inline fn renamePath(oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return c.SDL_RenamePath(oldpath, newpath); +} + +pub inline fn copyFile(oldpath: [*c]const u8, newpath: [*c]const u8) bool { + return c.SDL_CopyFile(oldpath, newpath); +} + +pub inline fn getPathInfo(path: [*c]const u8, info: ?*PathInfo) bool { + return c.SDL_GetPathInfo(path, info); +} + +pub inline fn globDirectory(path: [*c]const u8, pattern: [*c]const u8, flags: GlobFlags, count: *c_int) [*c][*c]u8 { + return c.SDL_GlobDirectory(path, pattern, @bitCast(flags), @ptrCast(count)); +} + +pub inline fn getCurrentDirectory() [*c]u8 { + return c.SDL_GetCurrentDirectory(); +} diff --git a/sdl3-zig/src/gamepad.zig b/sdl3-zig/src/gamepad.zig new file mode 100644 index 0000000..d3b0070 --- /dev/null +++ b/sdl3-zig/src/gamepad.zig @@ -0,0 +1,410 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const JoystickConnectionState = enum(c_int) { + joystickConnectionUnknown, + joystickConnectionWired, + joystickConnectionWireless, +}; + +pub const GUID = extern struct { + data: [16]u8, +}; + +pub const PropertiesID = u32; + +pub const IOStream = opaque { + pub inline fn addGamepadMappingsFromIO(iostream: *IOStream, closeio: bool) c_int { + return c.SDL_AddGamepadMappingsFromIO(iostream, closeio); + } +}; + +pub const JoystickID = u32; + +pub const SensorType = enum(c_int) { + sensorInvalid = -1, //Returned for an invalid sensor + sensorUnknown, //Unknown sensor type + sensorAccel, //Accelerometer + sensorGyro, //Gyroscope + sensorAccelL, //Accelerometer for left Joy-Con controller and Wii nunchuk + sensorGyroL, //Gyroscope for left Joy-Con controller + sensorAccelR, //Accelerometer for right Joy-Con controller + sensorGyroR, //Gyroscope for right Joy-Con controller + sensorCount, +}; + +pub const PowerState = enum(c_int) { + powerstateError = -1, //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 Joystick = opaque {}; + +pub const Gamepad = opaque { + pub inline fn getGamepadMapping(gamepad: *Gamepad) [*c]u8 { + return c.SDL_GetGamepadMapping(gamepad); + } + + pub inline fn getGamepadProperties(gamepad: *Gamepad) PropertiesID { + return c.SDL_GetGamepadProperties(gamepad); + } + + pub inline fn getGamepadID(gamepad: *Gamepad) JoystickID { + return c.SDL_GetGamepadID(gamepad); + } + + pub inline fn getGamepadName(gamepad: *Gamepad) [*c]const u8 { + return c.SDL_GetGamepadName(gamepad); + } + + pub inline fn getGamepadPath(gamepad: *Gamepad) [*c]const u8 { + return c.SDL_GetGamepadPath(gamepad); + } + + pub inline fn getGamepadType(gamepad: *Gamepad) GamepadType { + return @intFromEnum(c.SDL_GetGamepadType(gamepad)); + } + + pub inline fn getRealGamepadType(gamepad: *Gamepad) GamepadType { + return @intFromEnum(c.SDL_GetRealGamepadType(gamepad)); + } + + pub inline fn getGamepadPlayerIndex(gamepad: *Gamepad) c_int { + return c.SDL_GetGamepadPlayerIndex(gamepad); + } + + pub inline fn setGamepadPlayerIndex(gamepad: *Gamepad, player_index: c_int) bool { + return c.SDL_SetGamepadPlayerIndex(gamepad, player_index); + } + + pub inline fn getGamepadVendor(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadVendor(gamepad); + } + + pub inline fn getGamepadProduct(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadProduct(gamepad); + } + + pub inline fn getGamepadProductVersion(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadProductVersion(gamepad); + } + + pub inline fn getGamepadFirmwareVersion(gamepad: *Gamepad) u16 { + return c.SDL_GetGamepadFirmwareVersion(gamepad); + } + + pub inline fn getGamepadSerial(gamepad: *Gamepad) [*c]const u8 { + return c.SDL_GetGamepadSerial(gamepad); + } + + pub inline fn getGamepadSteamHandle(gamepad: *Gamepad) u64 { + return c.SDL_GetGamepadSteamHandle(gamepad); + } + + pub inline fn getGamepadConnectionState(gamepad: *Gamepad) JoystickConnectionState { + return c.SDL_GetGamepadConnectionState(gamepad); + } + + pub inline fn getGamepadPowerInfo(gamepad: *Gamepad, percent: *c_int) PowerState { + return c.SDL_GetGamepadPowerInfo(gamepad, @ptrCast(percent)); + } + + pub inline fn gamepadConnected(gamepad: *Gamepad) bool { + return c.SDL_GamepadConnected(gamepad); + } + + pub inline fn getGamepadJoystick(gamepad: *Gamepad) ?*Joystick { + return c.SDL_GetGamepadJoystick(gamepad); + } + + pub inline fn getGamepadBindings(gamepad: *Gamepad, count: *c_int) [*c][*c]GamepadBinding { + return c.SDL_GetGamepadBindings(gamepad, @ptrCast(count)); + } + + pub inline fn gamepadHasAxis(gamepad: *Gamepad, axis: GamepadAxis) bool { + return c.SDL_GamepadHasAxis(gamepad, axis); + } + + pub inline fn getGamepadAxis(gamepad: *Gamepad, axis: GamepadAxis) i16 { + return c.SDL_GetGamepadAxis(gamepad, axis); + } + + pub inline fn gamepadHasButton(gamepad: *Gamepad, button: GamepadButton) bool { + return c.SDL_GamepadHasButton(gamepad, button); + } + + pub inline fn getGamepadButton(gamepad: *Gamepad, button: GamepadButton) bool { + return c.SDL_GetGamepadButton(gamepad, button); + } + + pub inline fn getGamepadButtonLabel(gamepad: *Gamepad, button: GamepadButton) GamepadButtonLabel { + return c.SDL_GetGamepadButtonLabel(gamepad, button); + } + + pub inline fn getNumGamepadTouchpads(gamepad: *Gamepad) c_int { + return c.SDL_GetNumGamepadTouchpads(gamepad); + } + + pub inline fn getNumGamepadTouchpadFingers(gamepad: *Gamepad, touchpad: c_int) c_int { + return c.SDL_GetNumGamepadTouchpadFingers(gamepad, touchpad); + } + + pub inline fn getGamepadTouchpadFinger(gamepad: *Gamepad, touchpad: c_int, finger: c_int, down: *bool, x: *f32, y: *f32, pressure: *f32) bool { + return c.SDL_GetGamepadTouchpadFinger(gamepad, touchpad, finger, @ptrCast(down), @ptrCast(x), @ptrCast(y), @ptrCast(pressure)); + } + + pub inline fn gamepadHasSensor(gamepad: *Gamepad, _type: SensorType) bool { + return c.SDL_GamepadHasSensor(gamepad, @intFromEnum(_type)); + } + + pub inline fn setGamepadSensorEnabled(gamepad: *Gamepad, _type: SensorType, enabled: bool) bool { + return c.SDL_SetGamepadSensorEnabled(gamepad, @intFromEnum(_type), enabled); + } + + pub inline fn gamepadSensorEnabled(gamepad: *Gamepad, _type: SensorType) bool { + return c.SDL_GamepadSensorEnabled(gamepad, @intFromEnum(_type)); + } + + pub inline fn getGamepadSensorDataRate(gamepad: *Gamepad, _type: SensorType) f32 { + return c.SDL_GetGamepadSensorDataRate(gamepad, @intFromEnum(_type)); + } + + pub inline fn getGamepadSensorData(gamepad: *Gamepad, _type: SensorType, data: *f32, num_values: c_int) bool { + return c.SDL_GetGamepadSensorData(gamepad, @intFromEnum(_type), @ptrCast(data), num_values); + } + + pub inline fn rumbleGamepad(gamepad: *Gamepad, low_frequency_rumble: u16, high_frequency_rumble: u16, duration_ms: u32) bool { + return c.SDL_RumbleGamepad(gamepad, low_frequency_rumble, high_frequency_rumble, duration_ms); + } + + pub inline fn rumbleGamepadTriggers(gamepad: *Gamepad, left_rumble: u16, right_rumble: u16, duration_ms: u32) bool { + return c.SDL_RumbleGamepadTriggers(gamepad, left_rumble, right_rumble, duration_ms); + } + + pub inline fn setGamepadLED(gamepad: *Gamepad, red: u8, green: u8, blue: u8) bool { + return c.SDL_SetGamepadLED(gamepad, red, green, blue); + } + + pub inline fn sendGamepadEffect(gamepad: *Gamepad, data: ?*const anyopaque, size: c_int) bool { + return c.SDL_SendGamepadEffect(gamepad, data, size); + } + + pub inline fn closeGamepad(gamepad: *Gamepad) void { + return c.SDL_CloseGamepad(gamepad); + } + + pub inline fn getGamepadAppleSFSymbolsNameForButton(gamepad: *Gamepad, button: GamepadButton) [*c]const u8 { + return c.SDL_GetGamepadAppleSFSymbolsNameForButton(gamepad, button); + } + + pub inline fn getGamepadAppleSFSymbolsNameForAxis(gamepad: *Gamepad, axis: GamepadAxis) [*c]const u8 { + return c.SDL_GetGamepadAppleSFSymbolsNameForAxis(gamepad, axis); + } +}; + +pub const GamepadType = enum(c_int) { + gamepadTypeStandard, + gamepadTypeXbox360, + gamepadTypeXboxone, + gamepadTypePs3, + gamepadTypePs4, + gamepadTypePs5, + gamepadTypeNintendoSwitchPro, + gamepadTypeNintendoSwitchJoyconLeft, + gamepadTypeNintendoSwitchJoyconRight, + gamepadTypeNintendoSwitchJoyconPair, + gamepadTypeGamecube, + gamepadTypeCount, +}; + +pub const GamepadButton = enum(c_int) { + gamepadButtonSouth, //Bottom face button (e.g. Xbox A button) + gamepadButtonEast, //Right face button (e.g. Xbox B button) + gamepadButtonWest, //Left face button (e.g. Xbox X button) + gamepadButtonNorth, //Top face button (e.g. Xbox Y button) + gamepadButtonBack, + gamepadButtonGuide, + gamepadButtonStart, + gamepadButtonLeftStick, + gamepadButtonRightStick, + gamepadButtonLeftShoulder, + gamepadButtonRightShoulder, + gamepadButtonDpadUp, + gamepadButtonDpadDown, + gamepadButtonDpadLeft, + gamepadButtonDpadRight, + gamepadButtonMisc1, //Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) + gamepadButtonRightPaddle1, //Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1, DualSense Edge RB button, Right Joy-Con SR button) + gamepadButtonLeftPaddle1, //Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3, DualSense Edge LB button, Left Joy-Con SL button) + gamepadButtonRightPaddle2, //Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2, DualSense Edge right Fn button, Right Joy-Con SL button) + gamepadButtonLeftPaddle2, //Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4, DualSense Edge left Fn button, Left Joy-Con SR button) + gamepadButtonTouchpad, //PS4/PS5 touchpad button + gamepadButtonMisc2, //Additional button + gamepadButtonMisc3, //Additional button (e.g. Nintendo GameCube left trigger click) + gamepadButtonMisc4, //Additional button (e.g. Nintendo GameCube right trigger click) + gamepadButtonMisc5, //Additional button + gamepadButtonMisc6, //Additional button + gamepadButtonCount, +}; + +pub const GamepadButtonLabel = enum(c_int) { + gamepadButtonLabelUnknown, + gamepadButtonLabelA, + gamepadButtonLabelB, + gamepadButtonLabelX, + gamepadButtonLabelY, + gamepadButtonLabelCross, + gamepadButtonLabelCircle, + gamepadButtonLabelSquare, + gamepadButtonLabelTriangle, +}; + +pub const GamepadAxis = enum(c_int) { + gamepadAxisLeftx, + gamepadAxisLefty, + gamepadAxisRightx, + gamepadAxisRighty, + gamepadAxisLeftTrigger, + gamepadAxisRightTrigger, + gamepadAxisCount, +}; + +pub const GamepadBindingType = enum(c_int) { + gamepadBindtypeButton, + gamepadBindtypeAxis, + gamepadBindtypeHat, +}; + +pub const GamepadBinding = opaque {}; + +pub inline fn addGamepadMapping(mapping: [*c]const u8) c_int { + return c.SDL_AddGamepadMapping(mapping); +} + +pub inline fn addGamepadMappingsFromFile(file: [*c]const u8) c_int { + return c.SDL_AddGamepadMappingsFromFile(file); +} + +pub inline fn reloadGamepadMappings() bool { + return c.SDL_ReloadGamepadMappings(); +} + +pub inline fn getGamepadMappings(count: *c_int) [*c][*c]u8 { + return c.SDL_GetGamepadMappings(@ptrCast(count)); +} + +pub inline fn getGamepadMappingForGUID(guid: GUID) [*c]u8 { + return c.SDL_GetGamepadMappingForGUID(guid); +} + +pub inline fn setGamepadMapping(instance_id: JoystickID, mapping: [*c]const u8) bool { + return c.SDL_SetGamepadMapping(instance_id, mapping); +} + +pub inline fn hasGamepad() bool { + return c.SDL_HasGamepad(); +} + +pub inline fn getGamepads(count: *c_int) ?*JoystickID { + return c.SDL_GetGamepads(@ptrCast(count)); +} + +pub inline fn isGamepad(instance_id: JoystickID) bool { + return c.SDL_IsGamepad(instance_id); +} + +pub inline fn getGamepadNameForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetGamepadNameForID(instance_id); +} + +pub inline fn getGamepadPathForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetGamepadPathForID(instance_id); +} + +pub inline fn getGamepadPlayerIndexForID(instance_id: JoystickID) c_int { + return c.SDL_GetGamepadPlayerIndexForID(instance_id); +} + +pub inline fn getGamepadGUIDForID(instance_id: JoystickID) GUID { + return c.SDL_GetGamepadGUIDForID(instance_id); +} + +pub inline fn getGamepadVendorForID(instance_id: JoystickID) u16 { + return c.SDL_GetGamepadVendorForID(instance_id); +} + +pub inline fn getGamepadProductForID(instance_id: JoystickID) u16 { + return c.SDL_GetGamepadProductForID(instance_id); +} + +pub inline fn getGamepadProductVersionForID(instance_id: JoystickID) u16 { + return c.SDL_GetGamepadProductVersionForID(instance_id); +} + +pub inline fn getGamepadTypeForID(instance_id: JoystickID) GamepadType { + return @intFromEnum(c.SDL_GetGamepadTypeForID(instance_id)); +} + +pub inline fn getRealGamepadTypeForID(instance_id: JoystickID) GamepadType { + return @intFromEnum(c.SDL_GetRealGamepadTypeForID(instance_id)); +} + +pub inline fn getGamepadMappingForID(instance_id: JoystickID) [*c]u8 { + return c.SDL_GetGamepadMappingForID(instance_id); +} + +pub inline fn openGamepad(instance_id: JoystickID) ?*Gamepad { + return c.SDL_OpenGamepad(instance_id); +} + +pub inline fn getGamepadFromID(instance_id: JoystickID) ?*Gamepad { + return c.SDL_GetGamepadFromID(instance_id); +} + +pub inline fn getGamepadFromPlayerIndex(player_index: c_int) ?*Gamepad { + return c.SDL_GetGamepadFromPlayerIndex(player_index); +} + +pub inline fn setGamepadEventsEnabled(enabled: bool) void { + return c.SDL_SetGamepadEventsEnabled(enabled); +} + +pub inline fn gamepadEventsEnabled() bool { + return c.SDL_GamepadEventsEnabled(); +} + +pub inline fn updateGamepads() void { + return c.SDL_UpdateGamepads(); +} + +pub inline fn getGamepadTypeFromString(str: [*c]const u8) GamepadType { + return @intFromEnum(c.SDL_GetGamepadTypeFromString(str)); +} + +pub inline fn getGamepadStringForType(_type: GamepadType) [*c]const u8 { + return c.SDL_GetGamepadStringForType(@intFromEnum(_type)); +} + +pub inline fn getGamepadAxisFromString(str: [*c]const u8) GamepadAxis { + return c.SDL_GetGamepadAxisFromString(str); +} + +pub inline fn getGamepadStringForAxis(axis: GamepadAxis) [*c]const u8 { + return c.SDL_GetGamepadStringForAxis(axis); +} + +pub inline fn getGamepadButtonFromString(str: [*c]const u8) GamepadButton { + return c.SDL_GetGamepadButtonFromString(str); +} + +pub inline fn getGamepadStringForButton(button: GamepadButton) [*c]const u8 { + return c.SDL_GetGamepadStringForButton(button); +} + +pub inline fn getGamepadButtonLabelForType(_type: GamepadType, button: GamepadButton) GamepadButtonLabel { + return c.SDL_GetGamepadButtonLabelForType(@intFromEnum(_type), button); +} diff --git a/sdl3-zig/src/haptic.zig b/sdl3-zig/src/haptic.zig new file mode 100644 index 0000000..eeeeda1 --- /dev/null +++ b/sdl3-zig/src/haptic.zig @@ -0,0 +1,236 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Joystick = opaque { + pub inline fn isJoystickHaptic(joystick: *Joystick) bool { + return c.SDL_IsJoystickHaptic(joystick); + } + + pub inline fn openHapticFromJoystick(joystick: *Joystick) ?*Haptic { + return c.SDL_OpenHapticFromJoystick(joystick); + } +}; + +pub const Haptic = opaque { + pub inline fn getHapticID(haptic: *Haptic) HapticID { + return c.SDL_GetHapticID(haptic); + } + + pub inline fn getHapticName(haptic: *Haptic) [*c]const u8 { + return c.SDL_GetHapticName(haptic); + } + + pub inline fn closeHaptic(haptic: *Haptic) void { + return c.SDL_CloseHaptic(haptic); + } + + pub inline fn getMaxHapticEffects(haptic: *Haptic) c_int { + return c.SDL_GetMaxHapticEffects(haptic); + } + + pub inline fn getMaxHapticEffectsPlaying(haptic: *Haptic) c_int { + return c.SDL_GetMaxHapticEffectsPlaying(haptic); + } + + pub inline fn getHapticFeatures(haptic: *Haptic) u32 { + return c.SDL_GetHapticFeatures(haptic); + } + + pub inline fn getNumHapticAxes(haptic: *Haptic) c_int { + return c.SDL_GetNumHapticAxes(haptic); + } + + pub inline fn hapticEffectSupported(haptic: *Haptic, effect: *const HapticEffect) bool { + return c.SDL_HapticEffectSupported(haptic, @ptrCast(effect)); + } + + pub inline fn createHapticEffect(haptic: *Haptic, effect: *const HapticEffect) HapticEffectID { + return c.SDL_CreateHapticEffect(haptic, @ptrCast(effect)); + } + + pub inline fn updateHapticEffect(haptic: *Haptic, effect: HapticEffectID, data: *const HapticEffect) bool { + return c.SDL_UpdateHapticEffect(haptic, effect, @ptrCast(data)); + } + + pub inline fn runHapticEffect(haptic: *Haptic, effect: HapticEffectID, iterations: u32) bool { + return c.SDL_RunHapticEffect(haptic, effect, iterations); + } + + pub inline fn stopHapticEffect(haptic: *Haptic, effect: HapticEffectID) bool { + return c.SDL_StopHapticEffect(haptic, effect); + } + + pub inline fn destroyHapticEffect(haptic: *Haptic, effect: HapticEffectID) void { + return c.SDL_DestroyHapticEffect(haptic, effect); + } + + pub inline fn getHapticEffectStatus(haptic: *Haptic, effect: HapticEffectID) bool { + return c.SDL_GetHapticEffectStatus(haptic, effect); + } + + pub inline fn setHapticGain(haptic: *Haptic, gain: c_int) bool { + return c.SDL_SetHapticGain(haptic, gain); + } + + pub inline fn setHapticAutocenter(haptic: *Haptic, autocenter: c_int) bool { + return c.SDL_SetHapticAutocenter(haptic, autocenter); + } + + pub inline fn pauseHaptic(haptic: *Haptic) bool { + return c.SDL_PauseHaptic(haptic); + } + + pub inline fn resumeHaptic(haptic: *Haptic) bool { + return c.SDL_ResumeHaptic(haptic); + } + + pub inline fn stopHapticEffects(haptic: *Haptic) bool { + return c.SDL_StopHapticEffects(haptic); + } + + pub inline fn hapticRumbleSupported(haptic: *Haptic) bool { + return c.SDL_HapticRumbleSupported(haptic); + } + + pub inline fn initHapticRumble(haptic: *Haptic) bool { + return c.SDL_InitHapticRumble(haptic); + } + + pub inline fn playHapticRumble(haptic: *Haptic, strength: f32, length: u32) bool { + return c.SDL_PlayHapticRumble(haptic, strength, length); + } + + pub inline fn stopHapticRumble(haptic: *Haptic) bool { + return c.SDL_StopHapticRumble(haptic); + } +}; + +pub const HapticEffectType = u16; + +pub const HapticDirectionType = u8; + +pub const HapticEffectID = c_int; + +pub const HapticDirection = extern struct { + _type: HapticDirectionType, // The type of encoding. + dir: [3]i32, // The encoded direction. +}; + +pub const HapticConstant = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_CONSTANT + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + level: i16, // Strength of the constant effect. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticPeriodic = extern struct { + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + period: u16, // Period of the wave. + magnitude: i16, // Peak value; if negative, equivalent to 180 degrees extra phase shift. + offset: i16, // Mean value of the wave. + phase: u16, // Positive phase shift given by hundredth of a degree. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticCondition = extern struct { + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + right_sat: [3]u16, // Level when joystick is to the positive side; max 0xFFFF. + left_sat: [3]u16, // Level when joystick is to the negative side; max 0xFFFF. + right_coeff: [3]i16, // How fast to increase the force towards the positive side. + left_coeff: [3]i16, // How fast to increase the force towards the negative side. + deadband: [3]u16, // Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. + center: [3]i16, // Position of the dead zone. +}; + +pub const HapticRamp = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_RAMP + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + start: i16, // Beginning strength level. + end: i16, // Ending strength level. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticLeftRight = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_LEFTRIGHT + length: u32, // Duration of the effect in milliseconds. + large_magnitude: u16, // Control of the large controller motor. + small_magnitude: u16, // Control of the small controller motor. +}; + +pub const HapticCustom = extern struct { + _type: HapticEffectType, // SDL_HAPTIC_CUSTOM + direction: HapticDirection, // Direction of the effect. + length: u32, // Duration of the effect. + delay: u16, // Delay before starting the effect. + button: u16, // Button that triggers the effect. + interval: u16, // How soon it can be triggered again after button. + channels: u8, // Axes to use, minimum of one. + period: u16, // Sample periods. + samples: u16, // Amount of samples. + data: *u16, // Should contain channels*samples items. + attack_length: u16, // Duration of the attack. + attack_level: u16, // Level at the start of the attack. + fade_length: u16, // Duration of the fade. + fade_level: u16, // Level at the end of the fade. +}; + +pub const HapticEffect = extern union { + _type: HapticEffectType, // Effect type. + constant: HapticConstant, // Constant effect. + periodic: HapticPeriodic, // Periodic effect. + condition: HapticCondition, // Condition effect. + ramp: HapticRamp, // Ramp effect. + leftright: HapticLeftRight, // Left/Right effect. + custom: HapticCustom, // Custom effect. +}; + +pub const HapticID = u32; + +pub inline fn getHaptics(count: *c_int) ?*HapticID { + return c.SDL_GetHaptics(@ptrCast(count)); +} + +pub inline fn getHapticNameForID(instance_id: HapticID) [*c]const u8 { + return c.SDL_GetHapticNameForID(instance_id); +} + +pub inline fn openHaptic(instance_id: HapticID) ?*Haptic { + return c.SDL_OpenHaptic(instance_id); +} + +pub inline fn getHapticFromID(instance_id: HapticID) ?*Haptic { + return c.SDL_GetHapticFromID(instance_id); +} + +pub inline fn isMouseHaptic() bool { + return c.SDL_IsMouseHaptic(); +} + +pub inline fn openHapticFromMouse() ?*Haptic { + return c.SDL_OpenHapticFromMouse(); +} diff --git a/sdl3-zig/src/hints.zig b/sdl3-zig/src/hints.zig new file mode 100644 index 0000000..991da86 --- /dev/null +++ b/sdl3-zig/src/hints.zig @@ -0,0 +1,42 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const HintPriority = enum(c_int) { + hintDefault, + hintNormal, + hintOverride, +}; + +pub inline fn setHintWithPriority(name: [*c]const u8, value: [*c]const u8, priority: HintPriority) bool { + return c.SDL_SetHintWithPriority(name, value, priority); +} + +pub inline fn setHint(name: [*c]const u8, value: [*c]const u8) bool { + return c.SDL_SetHint(name, value); +} + +pub inline fn resetHint(name: [*c]const u8) bool { + return c.SDL_ResetHint(name); +} + +pub inline fn resetHints() void { + return c.SDL_ResetHints(); +} + +pub inline fn getHint(name: [*c]const u8) [*c]const u8 { + return c.SDL_GetHint(name); +} + +pub inline fn getHintBoolean(name: [*c]const u8, default_value: bool) bool { + return c.SDL_GetHintBoolean(name, default_value); +} + +pub const HintCallback = c.SDL_HintCallback; + +pub inline fn addHintCallback(name: [*c]const u8, callback: HintCallback, userdata: ?*anyopaque) bool { + return c.SDL_AddHintCallback(name, callback, userdata); +} + +pub inline fn removeHintCallback(name: [*c]const u8, callback: HintCallback, userdata: ?*anyopaque) void { + return c.SDL_RemoveHintCallback(name, callback, userdata); +} diff --git a/sdl3-zig/src/init.zig b/sdl3-zig/src/init.zig new file mode 100644 index 0000000..c34d6df --- /dev/null +++ b/sdl3-zig/src/init.zig @@ -0,0 +1,71 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const InitFlags = packed struct(u32) { + initAudio: bool = false, // `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS` + initVideo: bool = false, // `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS`, should be initialized on the main thread + initJoystick: bool = false, // `SDL_INIT_JOYSTICK` implies `SDL_INIT_EVENTS` + initHaptic: bool = false, + initGamepad: bool = false, // `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK` + initEvents: bool = false, + initSensor: bool = false, // `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS` + initCamera: bool = false, // `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS` + pad0: u23 = 0, + rsvd: bool = false, +}; + +pub const AppResult = enum(c_int) { + appContinue, //Value that requests that the app continue from the main callbacks. + appSuccess, //Value that requests termination with success from the main callbacks. + appFailure, //Value that requests termination with error from the main callbacks. +}; + +pub const AppInit_func = c.SDL_AppInit_func; + +pub const AppIterate_func = c.SDL_AppIterate_func; + +pub const AppEvent_func = c.SDL_AppEvent_func; + +pub const AppQuit_func = c.SDL_AppQuit_func; + +pub inline fn init(flags: InitFlags) bool { + return c.SDL_Init(@bitCast(flags)); +} + +pub inline fn initSubSystem(flags: InitFlags) bool { + return c.SDL_InitSubSystem(@bitCast(flags)); +} + +pub inline fn quitSubSystem(flags: InitFlags) void { + return c.SDL_QuitSubSystem(@bitCast(flags)); +} + +pub inline fn wasInit(flags: InitFlags) InitFlags { + return @bitCast(c.SDL_WasInit(@bitCast(flags))); +} + +pub inline fn quit() void { + return c.SDL_Quit(); +} + +pub inline fn isMainThread() bool { + return c.SDL_IsMainThread(); +} + +pub const MainThreadCallback = c.SDL_MainThreadCallback; + +pub inline fn runOnMainThread(callback: MainThreadCallback, userdata: ?*anyopaque, wait_complete: bool) bool { + return c.SDL_RunOnMainThread(callback, userdata, wait_complete); +} + +pub inline fn setAppMetadata(appname: [*c]const u8, appversion: [*c]const u8, appidentifier: [*c]const u8) bool { + return c.SDL_SetAppMetadata(appname, appversion, appidentifier); +} + +pub inline fn setAppMetadataProperty(name: [*c]const u8, value: [*c]const u8) bool { + return c.SDL_SetAppMetadataProperty(name, value); +} + +pub inline fn getAppMetadataProperty(name: [*c]const u8) [*c]const u8 { + return c.SDL_GetAppMetadataProperty(name); +} diff --git a/sdl3-zig/src/joystick.zig b/sdl3-zig/src/joystick.zig new file mode 100644 index 0000000..f5395e9 --- /dev/null +++ b/sdl3-zig/src/joystick.zig @@ -0,0 +1,322 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const SensorType = enum(c_int) { + sensorInvalid = -1, //Returned for an invalid sensor + sensorUnknown, //Unknown sensor type + sensorAccel, //Accelerometer + sensorGyro, //Gyroscope + sensorAccelL, //Accelerometer for left Joy-Con controller and Wii nunchuk + sensorGyroL, //Gyroscope for left Joy-Con controller + sensorAccelR, //Accelerometer for right Joy-Con controller + sensorGyroR, //Gyroscope for right Joy-Con controller + sensorCount, +}; + +pub const GUID = extern struct { + data: [16]u8, +}; + +pub const PowerState = enum(c_int) { + powerstateError = -1, //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 Joystick = opaque { + pub inline fn setJoystickVirtualAxis(joystick: *Joystick, axis: c_int, value: i16) bool { + return c.SDL_SetJoystickVirtualAxis(joystick, axis, value); + } + + pub inline fn setJoystickVirtualBall(joystick: *Joystick, ball: c_int, xrel: i16, yrel: i16) bool { + return c.SDL_SetJoystickVirtualBall(joystick, ball, xrel, yrel); + } + + pub inline fn setJoystickVirtualButton(joystick: *Joystick, button: c_int, down: bool) bool { + return c.SDL_SetJoystickVirtualButton(joystick, button, down); + } + + pub inline fn setJoystickVirtualHat(joystick: *Joystick, hat: c_int, value: u8) bool { + return c.SDL_SetJoystickVirtualHat(joystick, hat, value); + } + + pub inline fn setJoystickVirtualTouchpad(joystick: *Joystick, touchpad: c_int, finger: c_int, down: bool, x: f32, y: f32, pressure: f32) bool { + return c.SDL_SetJoystickVirtualTouchpad(joystick, touchpad, finger, down, x, y, pressure); + } + + pub inline fn sendJoystickVirtualSensorData(joystick: *Joystick, _type: SensorType, sensor_timestamp: u64, data: *const f32, num_values: c_int) bool { + return c.SDL_SendJoystickVirtualSensorData(joystick, @intFromEnum(_type), sensor_timestamp, @ptrCast(data), num_values); + } + + pub inline fn getJoystickProperties(joystick: *Joystick) PropertiesID { + return c.SDL_GetJoystickProperties(joystick); + } + + pub inline fn getJoystickName(joystick: *Joystick) [*c]const u8 { + return c.SDL_GetJoystickName(joystick); + } + + pub inline fn getJoystickPath(joystick: *Joystick) [*c]const u8 { + return c.SDL_GetJoystickPath(joystick); + } + + pub inline fn getJoystickPlayerIndex(joystick: *Joystick) c_int { + return c.SDL_GetJoystickPlayerIndex(joystick); + } + + pub inline fn setJoystickPlayerIndex(joystick: *Joystick, player_index: c_int) bool { + return c.SDL_SetJoystickPlayerIndex(joystick, player_index); + } + + pub inline fn getJoystickGUID(joystick: *Joystick) GUID { + return c.SDL_GetJoystickGUID(joystick); + } + + pub inline fn getJoystickVendor(joystick: *Joystick) u16 { + return c.SDL_GetJoystickVendor(joystick); + } + + pub inline fn getJoystickProduct(joystick: *Joystick) u16 { + return c.SDL_GetJoystickProduct(joystick); + } + + pub inline fn getJoystickProductVersion(joystick: *Joystick) u16 { + return c.SDL_GetJoystickProductVersion(joystick); + } + + pub inline fn getJoystickFirmwareVersion(joystick: *Joystick) u16 { + return c.SDL_GetJoystickFirmwareVersion(joystick); + } + + pub inline fn getJoystickSerial(joystick: *Joystick) [*c]const u8 { + return c.SDL_GetJoystickSerial(joystick); + } + + pub inline fn getJoystickType(joystick: *Joystick) JoystickType { + return @intFromEnum(c.SDL_GetJoystickType(joystick)); + } + + pub inline fn joystickConnected(joystick: *Joystick) bool { + return c.SDL_JoystickConnected(joystick); + } + + pub inline fn getJoystickID(joystick: *Joystick) JoystickID { + return c.SDL_GetJoystickID(joystick); + } + + pub inline fn getNumJoystickAxes(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickAxes(joystick); + } + + pub inline fn getNumJoystickBalls(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickBalls(joystick); + } + + pub inline fn getNumJoystickHats(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickHats(joystick); + } + + pub inline fn getNumJoystickButtons(joystick: *Joystick) c_int { + return c.SDL_GetNumJoystickButtons(joystick); + } + + pub inline fn getJoystickAxis(joystick: *Joystick, axis: c_int) i16 { + return c.SDL_GetJoystickAxis(joystick, axis); + } + + pub inline fn getJoystickAxisInitialState(joystick: *Joystick, axis: c_int, state: *i16) bool { + return c.SDL_GetJoystickAxisInitialState(joystick, axis, @ptrCast(state)); + } + + pub inline fn getJoystickBall(joystick: *Joystick, ball: c_int, dx: *c_int, dy: *c_int) bool { + return c.SDL_GetJoystickBall(joystick, ball, @ptrCast(dx), @ptrCast(dy)); + } + + pub inline fn getJoystickHat(joystick: *Joystick, hat: c_int) u8 { + return c.SDL_GetJoystickHat(joystick, hat); + } + + pub inline fn getJoystickButton(joystick: *Joystick, button: c_int) bool { + return c.SDL_GetJoystickButton(joystick, button); + } + + pub inline fn rumbleJoystick(joystick: *Joystick, low_frequency_rumble: u16, high_frequency_rumble: u16, duration_ms: u32) bool { + return c.SDL_RumbleJoystick(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms); + } + + pub inline fn rumbleJoystickTriggers(joystick: *Joystick, left_rumble: u16, right_rumble: u16, duration_ms: u32) bool { + return c.SDL_RumbleJoystickTriggers(joystick, left_rumble, right_rumble, duration_ms); + } + + pub inline fn setJoystickLED(joystick: *Joystick, red: u8, green: u8, blue: u8) bool { + return c.SDL_SetJoystickLED(joystick, red, green, blue); + } + + pub inline fn sendJoystickEffect(joystick: *Joystick, data: ?*const anyopaque, size: c_int) bool { + return c.SDL_SendJoystickEffect(joystick, data, size); + } + + pub inline fn closeJoystick(joystick: *Joystick) void { + return c.SDL_CloseJoystick(joystick); + } + + pub inline fn getJoystickConnectionState(joystick: *Joystick) JoystickConnectionState { + return c.SDL_GetJoystickConnectionState(joystick); + } + + pub inline fn getJoystickPowerInfo(joystick: *Joystick, percent: *c_int) PowerState { + return c.SDL_GetJoystickPowerInfo(joystick, @ptrCast(percent)); + } +}; + +pub const JoystickID = u32; + +pub const JoystickType = enum(c_int) { + joystickTypeUnknown, + joystickTypeGamepad, + joystickTypeWheel, + joystickTypeArcadeStick, + joystickTypeFlightStick, + joystickTypeDancePad, + joystickTypeGuitar, + joystickTypeDrumKit, + joystickTypeArcadePad, + joystickTypeThrottle, + joystickTypeCount, +}; + +pub const JoystickConnectionState = enum(c_int) { + joystickConnectionUnknown, + joystickConnectionWired, + joystickConnectionWireless, +}; + +pub inline fn lockJoysticks() void { + return c.SDL_LockJoysticks(); +} + +pub inline fn unlockJoysticks() void { + return c.SDL_UnlockJoysticks(); +} + +pub inline fn hasJoystick() bool { + return c.SDL_HasJoystick(); +} + +pub inline fn getJoysticks(count: *c_int) ?*JoystickID { + return c.SDL_GetJoysticks(@ptrCast(count)); +} + +pub inline fn getJoystickNameForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetJoystickNameForID(instance_id); +} + +pub inline fn getJoystickPathForID(instance_id: JoystickID) [*c]const u8 { + return c.SDL_GetJoystickPathForID(instance_id); +} + +pub inline fn getJoystickPlayerIndexForID(instance_id: JoystickID) c_int { + return c.SDL_GetJoystickPlayerIndexForID(instance_id); +} + +pub inline fn getJoystickGUIDForID(instance_id: JoystickID) GUID { + return c.SDL_GetJoystickGUIDForID(instance_id); +} + +pub inline fn getJoystickVendorForID(instance_id: JoystickID) u16 { + return c.SDL_GetJoystickVendorForID(instance_id); +} + +pub inline fn getJoystickProductForID(instance_id: JoystickID) u16 { + return c.SDL_GetJoystickProductForID(instance_id); +} + +pub inline fn getJoystickProductVersionForID(instance_id: JoystickID) u16 { + return c.SDL_GetJoystickProductVersionForID(instance_id); +} + +pub inline fn getJoystickTypeForID(instance_id: JoystickID) JoystickType { + return @intFromEnum(c.SDL_GetJoystickTypeForID(instance_id)); +} + +pub inline fn openJoystick(instance_id: JoystickID) ?*Joystick { + return c.SDL_OpenJoystick(instance_id); +} + +pub inline fn getJoystickFromID(instance_id: JoystickID) ?*Joystick { + return c.SDL_GetJoystickFromID(instance_id); +} + +pub inline fn getJoystickFromPlayerIndex(player_index: c_int) ?*Joystick { + return c.SDL_GetJoystickFromPlayerIndex(player_index); +} + +pub const VirtualJoystickTouchpadDesc = extern struct { + nfingers: u16, // the number of simultaneous fingers on this touchpad + padding: [3]u16, +}; + +pub const VirtualJoystickSensorDesc = extern struct { + _type: SensorType, // the type of this sensor + rate: f32, // the update frequency of this sensor, may be 0.0f +}; + +pub const VirtualJoystickDesc = extern struct { + version: u32, // the version of this interface + _type: u16, // `SDL_JoystickType` + padding: u16, // unused + vendor_id: u16, // the USB vendor ID of this joystick + product_id: u16, // the USB product ID of this joystick + naxes: u16, // the number of axes on this joystick + nbuttons: u16, // the number of buttons on this joystick + nballs: u16, // the number of balls on this joystick + nhats: u16, // the number of hats on this joystick + ntouchpads: u16, // the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions + nsensors: u16, // the number of sensors on this joystick, requires `sensors` to point at valid descriptions + padding2: [2]u16, // unused + name: [*c]const u8, // the name of the joystick + touchpads: *const VirtualJoystickTouchpadDesc, // A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 + sensors: *const VirtualJoystickSensorDesc, // A pointer to an array of sensor descriptions, required if `nsensors` is > 0 + userdata: ?*anyopaque, // User data pointer passed to callbacks + Update: ?*const anyopaque, // Called when the joystick state should be updated + SetPlayerIndex: ?*const anyopaque, // Called when the player index is set + Rumble: ?*const anyopaque, // Implements SDL_RumbleJoystick() + RumbleTriggers: ?*const anyopaque, // Implements SDL_RumbleJoystickTriggers() + SetLED: ?*const anyopaque, // Implements SDL_SetJoystickLED() + SendEffect: ?*const anyopaque, // Implements SDL_SendJoystickEffect() + SetSensorsEnabled: ?*const anyopaque, // Implements SDL_SetGamepadSensorEnabled() + Cleanup: ?*const anyopaque, // Cleans up the userdata when the joystick is detached +}; + +pub inline fn attachVirtualJoystick(desc: *const VirtualJoystickDesc) JoystickID { + return c.SDL_AttachVirtualJoystick(@ptrCast(desc)); +} + +pub inline fn detachVirtualJoystick(instance_id: JoystickID) bool { + return c.SDL_DetachVirtualJoystick(instance_id); +} + +pub inline fn isJoystickVirtual(instance_id: JoystickID) bool { + return c.SDL_IsJoystickVirtual(instance_id); +} + +pub inline fn getJoystickGUIDInfo(guid: GUID, vendor: *u16, product: *u16, version: *u16, crc16: *u16) void { + return c.SDL_GetJoystickGUIDInfo(guid, @ptrCast(vendor), @ptrCast(product), @ptrCast(version), @ptrCast(crc16)); +} + +pub inline fn setJoystickEventsEnabled(enabled: bool) void { + return c.SDL_SetJoystickEventsEnabled(enabled); +} + +pub inline fn joystickEventsEnabled() bool { + return c.SDL_JoystickEventsEnabled(); +} + +pub inline fn updateJoysticks() void { + return c.SDL_UpdateJoysticks(); +} diff --git a/sdl3-zig/src/keycode.zig b/sdl3-zig/src/keycode.zig new file mode 100644 index 0000000..d0aaa55 --- /dev/null +++ b/sdl3-zig/src/keycode.zig @@ -0,0 +1,6 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Keycode = u32; + +pub const Keymod = u16; diff --git a/sdl3-zig/src/loadso.zig b/sdl3-zig/src/loadso.zig new file mode 100644 index 0000000..6bf3894 --- /dev/null +++ b/sdl3-zig/src/loadso.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const FunctionPointer = c.SDL_FunctionPointer; + +pub const SharedObject = opaque { + pub inline fn loadFunction(sharedobject: *SharedObject, name: [*c]const u8) FunctionPointer { + return c.SDL_LoadFunction(sharedobject, name); + } + + pub inline fn unloadObject(sharedobject: *SharedObject) void { + return c.SDL_UnloadObject(sharedobject); + } +}; + +pub inline fn loadObject(sofile: [*c]const u8) ?*SharedObject { + return c.SDL_LoadObject(sofile); +} diff --git a/sdl3-zig/src/messagebox.zig b/sdl3-zig/src/messagebox.zig new file mode 100644 index 0000000..b7820eb --- /dev/null +++ b/sdl3-zig/src/messagebox.zig @@ -0,0 +1,64 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque {}; + +pub const MessageBoxFlags = packed struct(u32) { + messageboxError: bool = false, // error dialog + messageboxWarning: bool = false, // warning dialog + messageboxInformation: bool = false, // informational dialog + messageboxButtonsLeftToRight: bool = false, // buttons placed left to right + messageboxButtonsRightToLeft: bool = false, // buttons placed right to left + pad0: u26 = 0, + rsvd: bool = false, +}; + +pub const MessageBoxButtonFlags = packed struct(u32) { + messageboxButtonReturnkeyDefault: bool = false, // Marks the default button when return is hit + messageboxButtonEscapekeyDefault: bool = false, // Marks the default button when escape is hit + pad0: u29 = 0, + rsvd: bool = false, +}; + +pub const MessageBoxButtonData = extern struct { + flags: MessageBoxButtonFlags, + buttonID: c_int, // User defined button id (value returned via SDL_ShowMessageBox) + text: [*c]const u8, // The UTF-8 button text +}; + +pub const MessageBoxColor = extern struct { + r: u8, + g: u8, + b: u8, +}; + +pub const MessageBoxColorType = enum(c_int) { + messageboxColorBackground, + messageboxColorText, + messageboxColorButtonBorder, + messageboxColorButtonBackground, + messageboxColorButtonSelected, + messageboxColorCount, //Size of the colors array of SDL_MessageBoxColorScheme. +}; + +pub const MessageBoxColorScheme = extern struct { + colors: [c.SDL_MESSAGEBOX_COLOR_COUNT]MessageBoxColor, +}; + +pub const MessageBoxData = extern struct { + flags: MessageBoxFlags, + window: ?*Window, // Parent window, can be NULL + title: [*c]const u8, // UTF-8 title + message: [*c]const u8, // UTF-8 message text + numbuttons: c_int, + buttons: *const MessageBoxButtonData, + colorScheme: *const MessageBoxColorScheme, // SDL_MessageBoxColorScheme, can be NULL to use system settings +}; + +pub inline fn showMessageBox(messageboxdata: *const MessageBoxData, buttonid: *c_int) bool { + return c.SDL_ShowMessageBox(@ptrCast(messageboxdata), @ptrCast(buttonid)); +} + +pub inline fn showSimpleMessageBox(flags: MessageBoxFlags, title: [*c]const u8, message: [*c]const u8, window: ?*Window) bool { + return c.SDL_ShowSimpleMessageBox(@bitCast(flags), title, message, window); +} diff --git a/sdl3-zig/src/misc.zig b/sdl3-zig/src/misc.zig new file mode 100644 index 0000000..2bcc6d5 --- /dev/null +++ b/sdl3-zig/src/misc.zig @@ -0,0 +1,6 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn openURL(url: [*c]const u8) bool { + return c.SDL_OpenURL(url); +} diff --git a/sdl3-zig/src/mouse.zig b/sdl3-zig/src/mouse.zig new file mode 100644 index 0000000..5d6a5d0 --- /dev/null +++ b/sdl3-zig/src/mouse.zig @@ -0,0 +1,150 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque { + pub inline fn warpMouseInWindow(window: *Window, x: f32, y: f32) void { + return c.SDL_WarpMouseInWindow(window, x, y); + } + + pub inline fn setWindowRelativeMouseMode(window: *Window, enabled: bool) bool { + return c.SDL_SetWindowRelativeMouseMode(window, enabled); + } + + pub inline fn getWindowRelativeMouseMode(window: *Window) bool { + return c.SDL_GetWindowRelativeMouseMode(window); + } +}; + +pub const Surface = opaque { + pub inline fn createColorCursor(surface: *Surface, hot_x: c_int, hot_y: c_int) ?*Cursor { + return c.SDL_CreateColorCursor(surface, hot_x, hot_y); + } +}; + +pub const MouseID = u32; + +pub const Cursor = opaque { + pub inline fn setCursor(cursor: *Cursor) bool { + return c.SDL_SetCursor(cursor); + } + + pub inline fn destroyCursor(cursor: *Cursor) void { + return c.SDL_DestroyCursor(cursor); + } +}; + +pub const SystemCursor = enum(c_int) { + systemCursorDefault, //Default cursor. Usually an arrow. + systemCursorText, //Text selection. Usually an I-beam. + systemCursorWait, //Wait. Usually an hourglass or watch or spinning ball. + systemCursorCrosshair, //Crosshair. + systemCursorProgress, //Program is busy but still interactive. Usually it's WAIT with an arrow. + systemCursorNwseResize, //Double arrow pointing northwest and southeast. + systemCursorNeswResize, //Double arrow pointing northeast and southwest. + systemCursorEwResize, //Double arrow pointing west and east. + systemCursorNsResize, //Double arrow pointing north and south. + systemCursorMove, //Four pointed arrow pointing north, south, east, and west. + systemCursorNotAllowed, //Not permitted. Usually a slashed circle or crossbones. + systemCursorPointer, //Pointer that indicates a link. Usually a pointing hand. + systemCursorNwResize, //Window resize top-left. This may be a single arrow or a double arrow like NWSE_RESIZE. + systemCursorNResize, //Window resize top. May be NS_RESIZE. + systemCursorNeResize, //Window resize top-right. May be NESW_RESIZE. + systemCursorEResize, //Window resize right. May be EW_RESIZE. + systemCursorSeResize, //Window resize bottom-right. May be NWSE_RESIZE. + systemCursorSResize, //Window resize bottom. May be NS_RESIZE. + systemCursorSwResize, //Window resize bottom-left. May be NESW_RESIZE. + systemCursorWResize, //Window resize left. May be EW_RESIZE. + systemCursorCount, +}; + +pub const MouseWheelDirection = enum(c_int) { + mousewheelNormal, //The scroll direction is normal + mousewheelFlipped, //The scroll direction is flipped / natural +}; + +pub const CursorFrameInfo = extern struct { + surface: ?*Surface, // The surface data for this frame + duration: u32, // The frame duration in milliseconds (a duration of 0 is infinite) +}; + +pub const MouseButtonFlags = packed struct(u32) { + buttonLeft: bool = false, + buttonMiddle: bool = false, + buttonX1: bool = false, + pad0: u28 = 0, + rsvd: bool = false, +}; + +pub const MouseMotionTransformCallback = c.SDL_MouseMotionTransformCallback; + +pub inline fn hasMouse() bool { + return c.SDL_HasMouse(); +} + +pub inline fn getMice(count: *c_int) ?*MouseID { + return c.SDL_GetMice(@ptrCast(count)); +} + +pub inline fn getMouseNameForID(instance_id: MouseID) [*c]const u8 { + return c.SDL_GetMouseNameForID(instance_id); +} + +pub inline fn getMouseFocus() ?*Window { + return c.SDL_GetMouseFocus(); +} + +pub inline fn getMouseState(x: *f32, y: *f32) MouseButtonFlags { + return @bitCast(c.SDL_GetMouseState(@ptrCast(x), @ptrCast(y))); +} + +pub inline fn getGlobalMouseState(x: *f32, y: *f32) MouseButtonFlags { + return @bitCast(c.SDL_GetGlobalMouseState(@ptrCast(x), @ptrCast(y))); +} + +pub inline fn getRelativeMouseState(x: *f32, y: *f32) MouseButtonFlags { + return @bitCast(c.SDL_GetRelativeMouseState(@ptrCast(x), @ptrCast(y))); +} + +pub inline fn warpMouseGlobal(x: f32, y: f32) bool { + return c.SDL_WarpMouseGlobal(x, y); +} + +pub inline fn setRelativeMouseTransform(callback: MouseMotionTransformCallback, userdata: ?*anyopaque) bool { + return c.SDL_SetRelativeMouseTransform(callback, userdata); +} + +pub inline fn captureMouse(enabled: bool) bool { + return c.SDL_CaptureMouse(enabled); +} + +pub inline fn createCursor(data: [*c]const u8, mask: [*c]const u8, w: c_int, h: c_int, hot_x: c_int, hot_y: c_int) ?*Cursor { + return c.SDL_CreateCursor(data, mask, w, h, hot_x, hot_y); +} + +pub inline fn createAnimatedCursor(frames: ?*CursorFrameInfo, frame_count: c_int, hot_x: c_int, hot_y: c_int) ?*Cursor { + return c.SDL_CreateAnimatedCursor(frames, frame_count, hot_x, hot_y); +} + +pub inline fn createSystemCursor(id: SystemCursor) ?*Cursor { + return c.SDL_CreateSystemCursor(id); +} + +pub inline fn getCursor() ?*Cursor { + return c.SDL_GetCursor(); +} + +pub inline fn getDefaultCursor() ?*Cursor { + return c.SDL_GetDefaultCursor(); +} + +pub inline fn showCursor() bool { + return c.SDL_ShowCursor(); +} + +pub inline fn hideCursor() bool { + return c.SDL_HideCursor(); +} + +pub inline fn cursorVisible() bool { + return c.SDL_CursorVisible(); +} diff --git a/sdl3-zig/src/properties.zig b/sdl3-zig/src/properties.zig new file mode 100644 index 0000000..56e3ac8 --- /dev/null +++ b/sdl3-zig/src/properties.zig @@ -0,0 +1,101 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const PropertyType = enum(c_int) { + propertyTypeInvalid, + propertyTypePointer, + propertyTypeString, + propertyTypeNumber, + propertyTypeFloat, + propertyTypeBoolean, +}; + +pub inline fn getGlobalProperties() PropertiesID { + return c.SDL_GetGlobalProperties(); +} + +pub inline fn createProperties() PropertiesID { + return c.SDL_CreateProperties(); +} + +pub inline fn copyProperties(src: PropertiesID, dst: PropertiesID) bool { + return c.SDL_CopyProperties(src, dst); +} + +pub inline fn lockProperties(props: PropertiesID) bool { + return c.SDL_LockProperties(props); +} + +pub inline fn unlockProperties(props: PropertiesID) void { + return c.SDL_UnlockProperties(props); +} + +pub const CleanupPropertyCallback = c.SDL_CleanupPropertyCallback; + +pub inline fn setPointerPropertyWithCleanup(props: PropertiesID, name: [*c]const u8, value: ?*anyopaque, cleanup: CleanupPropertyCallback, userdata: ?*anyopaque) bool { + return c.SDL_SetPointerPropertyWithCleanup(props, name, value, cleanup, userdata); +} + +pub inline fn setPointerProperty(props: PropertiesID, name: [*c]const u8, value: ?*anyopaque) bool { + return c.SDL_SetPointerProperty(props, name, value); +} + +pub inline fn setStringProperty(props: PropertiesID, name: [*c]const u8, value: [*c]const u8) bool { + return c.SDL_SetStringProperty(props, name, value); +} + +pub inline fn setNumberProperty(props: PropertiesID, name: [*c]const u8, value: i64) bool { + return c.SDL_SetNumberProperty(props, name, value); +} + +pub inline fn setFloatProperty(props: PropertiesID, name: [*c]const u8, value: f32) bool { + return c.SDL_SetFloatProperty(props, name, value); +} + +pub inline fn setBooleanProperty(props: PropertiesID, name: [*c]const u8, value: bool) bool { + return c.SDL_SetBooleanProperty(props, name, value); +} + +pub inline fn hasProperty(props: PropertiesID, name: [*c]const u8) bool { + return c.SDL_HasProperty(props, name); +} + +pub inline fn getPropertyType(props: PropertiesID, name: [*c]const u8) PropertyType { + return @intFromEnum(c.SDL_GetPropertyType(props, name)); +} + +pub inline fn getPointerProperty(props: PropertiesID, name: [*c]const u8, default_value: ?*anyopaque) ?*anyopaque { + return c.SDL_GetPointerProperty(props, name, default_value); +} + +pub inline fn getStringProperty(props: PropertiesID, name: [*c]const u8, default_value: [*c]const u8) [*c]const u8 { + return c.SDL_GetStringProperty(props, name, default_value); +} + +pub inline fn getNumberProperty(props: PropertiesID, name: [*c]const u8, default_value: i64) i64 { + return c.SDL_GetNumberProperty(props, name, default_value); +} + +pub inline fn getFloatProperty(props: PropertiesID, name: [*c]const u8, default_value: f32) f32 { + return c.SDL_GetFloatProperty(props, name, default_value); +} + +pub inline fn getBooleanProperty(props: PropertiesID, name: [*c]const u8, default_value: bool) bool { + return c.SDL_GetBooleanProperty(props, name, default_value); +} + +pub inline fn clearProperty(props: PropertiesID, name: [*c]const u8) bool { + return c.SDL_ClearProperty(props, name); +} + +pub const EnumeratePropertiesCallback = c.SDL_EnumeratePropertiesCallback; + +pub inline fn enumerateProperties(props: PropertiesID, callback: EnumeratePropertiesCallback, userdata: ?*anyopaque) bool { + return c.SDL_EnumerateProperties(props, callback, userdata); +} + +pub inline fn destroyProperties(props: PropertiesID) void { + return c.SDL_DestroyProperties(props); +} diff --git a/sdl3-zig/src/rect.zig b/sdl3-zig/src/rect.zig new file mode 100644 index 0000000..ab3d595 --- /dev/null +++ b/sdl3-zig/src/rect.zig @@ -0,0 +1,66 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Point = extern struct { + x: c_int, + y: c_int, +}; + +pub const FPoint = extern struct { + x: f32, + y: f32, +}; + +pub const Rect = extern struct { + x: c_int, + y: c_int, + w: c_int, + h: c_int, +}; + +pub const FRect = extern struct { + x: f32, + y: f32, + w: f32, + h: f32, +}; + +pub inline fn hasRectIntersection(A: *const Rect, B: *const Rect) bool { + return c.SDL_HasRectIntersection(@ptrCast(A), @ptrCast(B)); +} + +pub inline fn getRectIntersection(A: *const Rect, B: *const Rect, result: ?*Rect) bool { + return c.SDL_GetRectIntersection(@ptrCast(A), @ptrCast(B), result); +} + +pub inline fn getRectUnion(A: *const Rect, B: *const Rect, result: ?*Rect) bool { + return c.SDL_GetRectUnion(@ptrCast(A), @ptrCast(B), result); +} + +pub inline fn getRectEnclosingPoints(points: *const Point, count: c_int, clip: *const Rect, result: ?*Rect) bool { + return c.SDL_GetRectEnclosingPoints(@ptrCast(points), count, @ptrCast(clip), result); +} + +pub inline fn getRectAndLineIntersection(rect: *const Rect, X1: *c_int, Y1: *c_int, X2: *c_int, Y2: *c_int) bool { + return c.SDL_GetRectAndLineIntersection(@ptrCast(rect), @ptrCast(X1), @ptrCast(Y1), @ptrCast(X2), @ptrCast(Y2)); +} + +pub inline fn hasRectIntersectionFloat(A: *const FRect, B: *const FRect) bool { + return c.SDL_HasRectIntersectionFloat(@ptrCast(A), @ptrCast(B)); +} + +pub inline fn getRectIntersectionFloat(A: *const FRect, B: *const FRect, result: ?*FRect) bool { + return c.SDL_GetRectIntersectionFloat(@ptrCast(A), @ptrCast(B), result); +} + +pub inline fn getRectUnionFloat(A: *const FRect, B: *const FRect, result: ?*FRect) bool { + return c.SDL_GetRectUnionFloat(@ptrCast(A), @ptrCast(B), result); +} + +pub inline fn getRectEnclosingPointsFloat(points: *const FPoint, count: c_int, clip: *const FRect, result: ?*FRect) bool { + return c.SDL_GetRectEnclosingPointsFloat(@ptrCast(points), count, @ptrCast(clip), result); +} + +pub inline fn getRectAndLineIntersectionFloat(rect: *const FRect, X1: *f32, Y1: *f32, X2: *f32, Y2: *f32) bool { + return c.SDL_GetRectAndLineIntersectionFloat(@ptrCast(rect), @ptrCast(X1), @ptrCast(Y1), @ptrCast(X2), @ptrCast(Y2)); +} diff --git a/sdl3-zig/src/sensor.zig b/sdl3-zig/src/sensor.zig new file mode 100644 index 0000000..9068d9d --- /dev/null +++ b/sdl3-zig/src/sensor.zig @@ -0,0 +1,76 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const Sensor = opaque { + pub inline fn getSensorProperties(sensor: *Sensor) PropertiesID { + return c.SDL_GetSensorProperties(sensor); + } + + pub inline fn getSensorName(sensor: *Sensor) [*c]const u8 { + return c.SDL_GetSensorName(sensor); + } + + pub inline fn getSensorType(sensor: *Sensor) SensorType { + return @intFromEnum(c.SDL_GetSensorType(sensor)); + } + + pub inline fn getSensorNonPortableType(sensor: *Sensor) c_int { + return c.SDL_GetSensorNonPortableType(sensor); + } + + pub inline fn getSensorID(sensor: *Sensor) SensorID { + return c.SDL_GetSensorID(sensor); + } + + pub inline fn getSensorData(sensor: *Sensor, data: *f32, num_values: c_int) bool { + return c.SDL_GetSensorData(sensor, @ptrCast(data), num_values); + } + + pub inline fn closeSensor(sensor: *Sensor) void { + return c.SDL_CloseSensor(sensor); + } +}; + +pub const SensorID = u32; + +pub const SensorType = enum(c_int) { + sensorInvalid = -1, //Returned for an invalid sensor + sensorUnknown, //Unknown sensor type + sensorAccel, //Accelerometer + sensorGyro, //Gyroscope + sensorAccelL, //Accelerometer for left Joy-Con controller and Wii nunchuk + sensorGyroL, //Gyroscope for left Joy-Con controller + sensorAccelR, //Accelerometer for right Joy-Con controller + sensorGyroR, //Gyroscope for right Joy-Con controller + sensorCount, +}; + +pub inline fn getSensors(count: *c_int) ?*SensorID { + return c.SDL_GetSensors(@ptrCast(count)); +} + +pub inline fn getSensorNameForID(instance_id: SensorID) [*c]const u8 { + return c.SDL_GetSensorNameForID(instance_id); +} + +pub inline fn getSensorTypeForID(instance_id: SensorID) SensorType { + return @intFromEnum(c.SDL_GetSensorTypeForID(instance_id)); +} + +pub inline fn getSensorNonPortableTypeForID(instance_id: SensorID) c_int { + return c.SDL_GetSensorNonPortableTypeForID(instance_id); +} + +pub inline fn openSensor(instance_id: SensorID) ?*Sensor { + return c.SDL_OpenSensor(instance_id); +} + +pub inline fn getSensorFromID(instance_id: SensorID) ?*Sensor { + return c.SDL_GetSensorFromID(instance_id); +} + +pub inline fn updateSensors() void { + return c.SDL_UpdateSensors(); +} diff --git a/sdl3-zig/src/storage.zig b/sdl3-zig/src/storage.zig new file mode 100644 index 0000000..37100c3 --- /dev/null +++ b/sdl3-zig/src/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/sdl3-zig/src/system.zig b/sdl3-zig/src/system.zig new file mode 100644 index 0000000..8863cba --- /dev/null +++ b/sdl3-zig/src/system.zig @@ -0,0 +1,159 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const DisplayID = u32; + +pub const Window = opaque { + pub inline fn setiOSAnimationCallback(window: *Window, interval: c_int, callback: iOSAnimationCallback, callbackParam: ?*anyopaque) bool { + return c.SDL_SetiOSAnimationCallback(window, interval, callback, callbackParam); + } +}; + +pub const MSG = opaque {}; + +pub const WindowsMessageHook = c.SDL_WindowsMessageHook; + +pub inline fn setWindowsMessageHook(callback: WindowsMessageHook, userdata: ?*anyopaque) void { + return c.SDL_SetWindowsMessageHook(callback, userdata); +} + +pub inline fn getDirect3D9AdapterIndex(displayID: DisplayID) c_int { + return c.SDL_GetDirect3D9AdapterIndex(displayID); +} + +pub inline fn getDXGIOutputInfo(displayID: DisplayID, adapterIndex: *c_int, outputIndex: *c_int) bool { + return c.SDL_GetDXGIOutputInfo(displayID, @ptrCast(adapterIndex), @ptrCast(outputIndex)); +} + +pub const X11EventHook = c.SDL_X11EventHook; + +pub inline fn setX11EventHook(callback: X11EventHook, userdata: ?*anyopaque) void { + return c.SDL_SetX11EventHook(callback, userdata); +} + +pub inline fn setLinuxThreadPriority(threadID: i64, priority: c_int) bool { + return c.SDL_SetLinuxThreadPriority(threadID, priority); +} + +pub inline fn setLinuxThreadPriorityAndPolicy(threadID: i64, sdlPriority: c_int, schedPolicy: c_int) bool { + return c.SDL_SetLinuxThreadPriorityAndPolicy(threadID, sdlPriority, schedPolicy); +} + +pub const iOSAnimationCallback = c.SDL_iOSAnimationCallback; + +pub inline fn setiOSEventPump(enabled: bool) void { + return c.SDL_SetiOSEventPump(enabled); +} + +pub inline fn getAndroidJNIEnv() ?*anyopaque { + return c.SDL_GetAndroidJNIEnv(); +} + +pub inline fn getAndroidActivity() ?*anyopaque { + return c.SDL_GetAndroidActivity(); +} + +pub inline fn getAndroidSDKVersion() c_int { + return c.SDL_GetAndroidSDKVersion(); +} + +pub inline fn isChromebook() bool { + return c.SDL_IsChromebook(); +} + +pub inline fn isDeXMode() bool { + return c.SDL_IsDeXMode(); +} + +pub inline fn sendAndroidBackButton() void { + return c.SDL_SendAndroidBackButton(); +} + +pub inline fn getAndroidInternalStoragePath() [*c]const u8 { + return c.SDL_GetAndroidInternalStoragePath(); +} + +pub inline fn getAndroidExternalStorageState() u32 { + return c.SDL_GetAndroidExternalStorageState(); +} + +pub inline fn getAndroidExternalStoragePath() [*c]const u8 { + return c.SDL_GetAndroidExternalStoragePath(); +} + +pub inline fn getAndroidCachePath() [*c]const u8 { + return c.SDL_GetAndroidCachePath(); +} + +pub const RequestAndroidPermissionCallback = c.SDL_RequestAndroidPermissionCallback; + +pub inline fn requestAndroidPermission(permission: [*c]const u8, cb: RequestAndroidPermissionCallback, userdata: ?*anyopaque) bool { + return c.SDL_RequestAndroidPermission(permission, cb, userdata); +} + +pub inline fn showAndroidToast(message: [*c]const u8, duration: c_int, gravity: c_int, xoffset: c_int, yoffset: c_int) bool { + return c.SDL_ShowAndroidToast(message, duration, gravity, xoffset, yoffset); +} + +pub inline fn sendAndroidMessage(command: u32, param: c_int) bool { + return c.SDL_SendAndroidMessage(command, param); +} + +pub inline fn isTablet() bool { + return c.SDL_IsTablet(); +} + +pub inline fn isTV() bool { + return c.SDL_IsTV(); +} + +pub const Sandbox = enum(c_int) { + sandboxUnknownContainer, + sandboxFlatpak, + sandboxSnap, + sandboxMacos, +}; + +pub inline fn getSandbox() Sandbox { + return c.SDL_GetSandbox(); +} + +pub inline fn onApplicationWillTerminate() void { + return c.SDL_OnApplicationWillTerminate(); +} + +pub inline fn onApplicationDidReceiveMemoryWarning() void { + return c.SDL_OnApplicationDidReceiveMemoryWarning(); +} + +pub inline fn onApplicationWillEnterBackground() void { + return c.SDL_OnApplicationWillEnterBackground(); +} + +pub inline fn onApplicationDidEnterBackground() void { + return c.SDL_OnApplicationDidEnterBackground(); +} + +pub inline fn onApplicationWillEnterForeground() void { + return c.SDL_OnApplicationWillEnterForeground(); +} + +pub inline fn onApplicationDidEnterForeground() void { + return c.SDL_OnApplicationDidEnterForeground(); +} + +pub inline fn onApplicationDidChangeStatusBarOrientation() void { + return c.SDL_OnApplicationDidChangeStatusBarOrientation(); +} + +pub const XTaskQueueHandle = *anyopaque; + +pub const XUserHandle = *anyopaque; + +pub inline fn getGDKTaskQueue(outTaskQueue: [*c]XTaskQueueHandle) bool { + return c.SDL_GetGDKTaskQueue(outTaskQueue); +} + +pub inline fn getGDKDefaultUser(outUserHandle: [*c]XUserHandle) bool { + return c.SDL_GetGDKDefaultUser(outUserHandle); +} diff --git a/sdl3-zig/src/time.zig b/sdl3-zig/src/time.zig new file mode 100644 index 0000000..3270ed1 --- /dev/null +++ b/sdl3-zig/src/time.zig @@ -0,0 +1,63 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Time = i64; + +pub const DateTime = extern struct { + year: c_int, // Year + month: c_int, // Month [01-12] + day: c_int, // Day of the month [01-31] + hour: c_int, // Hour [0-23] + minute: c_int, // Minute [0-59] + second: c_int, // Seconds [0-60] + nanosecond: c_int, // Nanoseconds [0-999999999] + day_of_week: c_int, // Day of the week [0-6] (0 being Sunday) + utc_offset: c_int, // Seconds east of UTC +}; + +pub const DateFormat = enum(c_int) { + dateFormatYyyymmdd = 0, //Year/Month/Day + dateFormatDdmmyyyy = 1, //Day/Month/Year + dateFormatMmddyyyy = 2, //Month/Day/Year +}; + +pub const TimeFormat = enum(c_int) { + timeFormat24hr = 0, //24 hour time + timeFormat12hr = 1, //12 hour time +}; + +pub inline fn getDateTimeLocalePreferences(dateFormat: ?*DateFormat, timeFormat: ?*TimeFormat) bool { + return c.SDL_GetDateTimeLocalePreferences(@bitCast(dateFormat), @bitCast(timeFormat)); +} + +pub inline fn getCurrentTime(ticks: ?*Time) bool { + return c.SDL_GetCurrentTime(ticks); +} + +pub inline fn timeToDateTime(ticks: Time, dt: ?*DateTime, localTime: bool) bool { + return c.SDL_TimeToDateTime(ticks, dt, localTime); +} + +pub inline fn dateTimeToTime(dt: *const DateTime, ticks: ?*Time) bool { + return c.SDL_DateTimeToTime(@ptrCast(dt), ticks); +} + +pub inline fn timeToWindows(ticks: Time, dwLowDateTime: *u32, dwHighDateTime: *u32) void { + return c.SDL_TimeToWindows(ticks, @ptrCast(dwLowDateTime), @ptrCast(dwHighDateTime)); +} + +pub inline fn timeFromWindows(dwLowDateTime: u32, dwHighDateTime: u32) Time { + return c.SDL_TimeFromWindows(dwLowDateTime, dwHighDateTime); +} + +pub inline fn getDaysInMonth(year: c_int, month: c_int) c_int { + return c.SDL_GetDaysInMonth(year, month); +} + +pub inline fn getDayOfYear(year: c_int, month: c_int, day: c_int) c_int { + return c.SDL_GetDayOfYear(year, month, day); +} + +pub inline fn getDayOfWeek(year: c_int, month: c_int, day: c_int) c_int { + return c.SDL_GetDayOfWeek(year, month, day); +} diff --git a/sdl3-zig/src/timer.zig b/sdl3-zig/src/timer.zig new file mode 100644 index 0000000..3300d85 --- /dev/null +++ b/sdl3-zig/src/timer.zig @@ -0,0 +1,48 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn getTicks() u64 { + return c.SDL_GetTicks(); +} + +pub inline fn getTicksNS() u64 { + return c.SDL_GetTicksNS(); +} + +pub inline fn getPerformanceCounter() u64 { + return c.SDL_GetPerformanceCounter(); +} + +pub inline fn getPerformanceFrequency() u64 { + return c.SDL_GetPerformanceFrequency(); +} + +pub inline fn delay(ms: u32) void { + return c.SDL_Delay(ms); +} + +pub inline fn delayNS(ns: u64) void { + return c.SDL_DelayNS(ns); +} + +pub inline fn delayPrecise(ns: u64) void { + return c.SDL_DelayPrecise(ns); +} + +pub const TimerID = u32; + +pub const TimerCallback = c.SDL_TimerCallback; + +pub inline fn addTimer(interval: u32, callback: TimerCallback, userdata: ?*anyopaque) TimerID { + return c.SDL_AddTimer(interval, callback, userdata); +} + +pub const NSTimerCallback = c.SDL_NSTimerCallback; + +pub inline fn addTimerNS(interval: u64, callback: NSTimerCallback, userdata: ?*anyopaque) TimerID { + return c.SDL_AddTimerNS(interval, callback, userdata); +} + +pub inline fn removeTimer(id: TimerID) bool { + return c.SDL_RemoveTimer(id); +} diff --git a/sdl3-zig/src/touch.zig b/sdl3-zig/src/touch.zig new file mode 100644 index 0000000..2394cdc --- /dev/null +++ b/sdl3-zig/src/touch.zig @@ -0,0 +1,35 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const TouchID = u64; + +pub const FingerID = u64; + +pub const TouchDeviceType = enum(c_int) { + touchDeviceDirect, //touch screen with window-relative coordinates + touchDeviceIndirectAbsolute, //trackpad with absolute device coordinates + touchDeviceIndirectRelative, //trackpad with screen cursor-relative coordinates +}; + +pub const Finger = extern struct { + id: FingerID, // the finger ID + x: f32, // the x-axis location of the touch event, normalized (0...1) + y: f32, // the y-axis location of the touch event, normalized (0...1) + pressure: f32, // the quantity of pressure applied, normalized (0...1) +}; + +pub inline fn getTouchDevices(count: *c_int) ?*TouchID { + return c.SDL_GetTouchDevices(@ptrCast(count)); +} + +pub inline fn getTouchDeviceName(touchID: TouchID) [*c]const u8 { + return c.SDL_GetTouchDeviceName(touchID); +} + +pub inline fn getTouchDeviceType(touchID: TouchID) TouchDeviceType { + return @intFromEnum(c.SDL_GetTouchDeviceType(touchID)); +} + +pub inline fn getTouchFingers(touchID: TouchID, count: *c_int) [*c][*c]Finger { + return c.SDL_GetTouchFingers(touchID, @ptrCast(count)); +} diff --git a/sdl3-zig/src/version.zig b/sdl3-zig/src/version.zig new file mode 100644 index 0000000..8cef3e8 --- /dev/null +++ b/sdl3-zig/src/version.zig @@ -0,0 +1,10 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn getVersion() c_int { + return c.SDL_GetVersion(); +} + +pub inline fn getRevision() [*c]const u8 { + return c.SDL_GetRevision(); +} diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..0aebf85 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,68 @@ +const std = @import("std"); +const sdl = @import("sdl3"); + +pub fn main() !void { + // Initialize SDL with video subsystem + const init_flags = sdl.InitFlags{ + .initVideo = true, + }; + + if (!sdl.init_fn(init_flags)) { + std.debug.print("SDL_Init failed: {s}\n", .{sdl.getError()}); + return error.SDLInitFailed; + } + defer sdl.quit(); + + // Create window + const window = sdl.createWindow( + "SDL3 Sample Window", + 800, + 600, + sdl.WindowFlags{ + .windowResizable = true, + }, + ) orelse { + std.debug.print("SDL_CreateWindow failed: {s}\n", .{sdl.getError()}); + return error.WindowCreationFailed; + }; + defer sdl.video.Window.destroyWindow(window); + + // Create renderer + const renderer = sdl.render.Window.createRenderer(@ptrCast(window), null) orelse { + std.debug.print("SDL_CreateRenderer failed: {s}\n", .{sdl.getError()}); + return error.RendererCreationFailed; + }; + defer sdl.render.Renderer.destroyRenderer(renderer); + + // Main loop + var running = true; + while (running) { + var event: sdl.Event = undefined; + while (sdl.pollEvent(&event)) { + std.debug.print("Event type: {}\n", .{event._type}); + + switch (event._type) { + @intFromEnum(sdl.EventType.eventQuit) => { + std.debug.print("Quit event received\n", .{}); + running = false; + }, + @intFromEnum(sdl.EventType.eventKeyDown) => { + std.debug.print("Key down event - keycode: {}\n", .{event.key.key}); + // Access the key field from keyboard event + if (event.key.key == sdl.keycode.c.SDLK_ESCAPE) { + std.debug.print("Escape key pressed!\n", .{}); + running = false; + } + }, + else => {}, + } + } + + // Clear screen with dark background + _ = sdl.render.Renderer.setRenderDrawColor(renderer, 30, 30, 46, 255); + _ = sdl.render.Renderer.renderClear(renderer); + _ = sdl.render.Renderer.renderPresent(renderer); + + sdl.delay(16); + } +}