diff --git a/lib/sdl3/build.zig b/lib/sdl3/build.zig index 225a6a0..b443fdb 100644 --- a/lib/sdl3/build.zig +++ b/lib/sdl3/build.zig @@ -143,22 +143,61 @@ pub fn build(b: *std.Build) void { }); const parser_exe = parser_dep.artifact("sdl-parser"); + // All public SDL3 API headers (53 total) const headers_to_generate = [_]struct { header: []const u8, output: []const u8 }{ - .{ .header = "SDL/include/SDL3/SDL_gpu.h", .output = "v2/gpu.zig" }, - .{ .header = "SDL/include/SDL3/SDL_video.h", .output = "v2/video.zig" }, - .{ .header = "SDL/include/SDL3/SDL_events.h", .output = "v2/events.zig" }, - .{ .header = "SDL/include/SDL3/SDL_keyboard.h", .output = "v2/keyboard.zig" }, - .{ .header = "SDL/include/SDL3/SDL_mouse.h", .output = "v2/mouse.zig" }, - .{ .header = "SDL/include/SDL3/SDL_scancode.h", .output = "v2/scancode.zig" }, - .{ .header = "SDL/include/SDL3/SDL_keycode.h", .output = "v2/keycode.zig" }, - .{ .header = "SDL/include/SDL3/SDL_pixels.h", .output = "v2/pixels.zig" }, - .{ .header = "SDL/include/SDL3/SDL_rect.h", .output = "v2/rect.zig" }, - .{ .header = "SDL/include/SDL3/SDL_surface.h", .output = "v2/surface.zig" }, + .{ .header = "SDL/include/SDL3/SDL_assert.h", .output = "v2/assert.zig" }, + .{ .header = "SDL/include/SDL3/SDL_asyncio.h", .output = "v2/asyncio.zig" }, + .{ .header = "SDL/include/SDL3/SDL_atomic.h", .output = "v2/atomic.zig" }, + .{ .header = "SDL/include/SDL3/SDL_audio.h", .output = "v2/audio.zig" }, .{ .header = "SDL/include/SDL3/SDL_blendmode.h", .output = "v2/blendmode.zig" }, - .{ .header = "SDL/include/SDL3/SDL_init.h", .output = "v2/init.zig" }, - .{ .header = "SDL/include/SDL3/SDL_timer.h", .output = "v2/timer.zig" }, + .{ .header = "SDL/include/SDL3/SDL_camera.h", .output = "v2/camera.zig" }, + .{ .header = "SDL/include/SDL3/SDL_clipboard.h", .output = "v2/clipboard.zig" }, + .{ .header = "SDL/include/SDL3/SDL_cpuinfo.h", .output = "v2/cpuinfo.zig" }, + .{ .header = "SDL/include/SDL3/SDL_dialog.h", .output = "v2/dialog.zig" }, + .{ .header = "SDL/include/SDL3/SDL_endian.h", .output = "v2/endian.zig" }, .{ .header = "SDL/include/SDL3/SDL_error.h", .output = "v2/error.zig" }, + .{ .header = "SDL/include/SDL3/SDL_events.h", .output = "v2/events.zig" }, + .{ .header = "SDL/include/SDL3/SDL_filesystem.h", .output = "v2/filesystem.zig" }, + .{ .header = "SDL/include/SDL3/SDL_gamepad.h", .output = "v2/gamepad.zig" }, + .{ .header = "SDL/include/SDL3/SDL_gpu.h", .output = "v2/gpu.zig" }, + .{ .header = "SDL/include/SDL3/SDL_guid.h", .output = "v2/guid.zig" }, + .{ .header = "SDL/include/SDL3/SDL_haptic.h", .output = "v2/haptic.zig" }, + .{ .header = "SDL/include/SDL3/SDL_hidapi.h", .output = "v2/hidapi.zig" }, + .{ .header = "SDL/include/SDL3/SDL_hints.h", .output = "v2/hints.zig" }, + .{ .header = "SDL/include/SDL3/SDL_init.h", .output = "v2/init.zig" }, .{ .header = "SDL/include/SDL3/SDL_iostream.h", .output = "v2/iostream.zig" }, + .{ .header = "SDL/include/SDL3/SDL_joystick.h", .output = "v2/joystick.zig" }, + .{ .header = "SDL/include/SDL3/SDL_keyboard.h", .output = "v2/keyboard.zig" }, + .{ .header = "SDL/include/SDL3/SDL_keycode.h", .output = "v2/keycode.zig" }, + .{ .header = "SDL/include/SDL3/SDL_loadso.h", .output = "v2/loadso.zig" }, + .{ .header = "SDL/include/SDL3/SDL_locale.h", .output = "v2/locale.zig" }, + .{ .header = "SDL/include/SDL3/SDL_log.h", .output = "v2/log.zig" }, + .{ .header = "SDL/include/SDL3/SDL_messagebox.h", .output = "v2/messagebox.zig" }, + .{ .header = "SDL/include/SDL3/SDL_metal.h", .output = "v2/metal.zig" }, + .{ .header = "SDL/include/SDL3/SDL_misc.h", .output = "v2/misc.zig" }, + .{ .header = "SDL/include/SDL3/SDL_mouse.h", .output = "v2/mouse.zig" }, + .{ .header = "SDL/include/SDL3/SDL_mutex.h", .output = "v2/mutex.zig" }, + .{ .header = "SDL/include/SDL3/SDL_opengl.h", .output = "v2/opengl.zig" }, + .{ .header = "SDL/include/SDL3/SDL_pen.h", .output = "v2/pen.zig" }, + .{ .header = "SDL/include/SDL3/SDL_pixels.h", .output = "v2/pixels.zig" }, + .{ .header = "SDL/include/SDL3/SDL_power.h", .output = "v2/power.zig" }, + .{ .header = "SDL/include/SDL3/SDL_process.h", .output = "v2/process.zig" }, + .{ .header = "SDL/include/SDL3/SDL_properties.h", .output = "v2/properties.zig" }, + .{ .header = "SDL/include/SDL3/SDL_rect.h", .output = "v2/rect.zig" }, + .{ .header = "SDL/include/SDL3/SDL_render.h", .output = "v2/render.zig" }, + .{ .header = "SDL/include/SDL3/SDL_scancode.h", .output = "v2/scancode.zig" }, + .{ .header = "SDL/include/SDL3/SDL_sensor.h", .output = "v2/sensor.zig" }, + .{ .header = "SDL/include/SDL3/SDL_storage.h", .output = "v2/storage.zig" }, + .{ .header = "SDL/include/SDL3/SDL_surface.h", .output = "v2/surface.zig" }, + .{ .header = "SDL/include/SDL3/SDL_system.h", .output = "v2/system.zig" }, + .{ .header = "SDL/include/SDL3/SDL_thread.h", .output = "v2/thread.zig" }, + .{ .header = "SDL/include/SDL3/SDL_time.h", .output = "v2/time.zig" }, + .{ .header = "SDL/include/SDL3/SDL_timer.h", .output = "v2/timer.zig" }, + .{ .header = "SDL/include/SDL3/SDL_touch.h", .output = "v2/touch.zig" }, + .{ .header = "SDL/include/SDL3/SDL_tray.h", .output = "v2/tray.zig" }, + .{ .header = "SDL/include/SDL3/SDL_version.h", .output = "v2/version.zig" }, + .{ .header = "SDL/include/SDL3/SDL_video.h", .output = "v2/video.zig" }, + .{ .header = "SDL/include/SDL3/SDL_vulkan.h", .output = "v2/vulkan.zig" }, }; const regenerate_step = b.step("regenerate-zig", "Regenerate bindings from SDL headers"); diff --git a/lib/sdl3/v2/assert.zig b/lib/sdl3/v2/assert.zig new file mode 100644 index 0000000..f27ede6 --- /dev/null +++ b/lib/sdl3/v2/assert.zig @@ -0,0 +1,37 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const AssertData = extern struct { + always_ignore: bool, // true if app should always continue when assertion is triggered. + trigger_count: unsigned int, // Number of times this assertion has been triggered. + condition: [*c]const u8, // A string of this assert's test code. + filename: [*c]const u8, // The source file where this assert lives. + linenum: c_int, // The line in `filename` where this assert lives. + function: [*c]const u8, // The name of the function where this assert lives. + next: const struct SDL_AssertData *, // next item in the linked list. +}; + +pub inline fn reportAssertion(data: ?*AssertData, func: [*c]const u8, file: [*c]const u8, line: c_int,) AssertState { + return c.SDL_ReportAssertion(data, func, file, line); +} + +pub inline fn setAssertionHandler(handler: AssertionHandler, userdata: ?*anyopaque) void { + return c.SDL_SetAssertionHandler(handler, userdata); +} + +pub inline fn getDefaultAssertionHandler() AssertionHandler { + return c.SDL_GetDefaultAssertionHandler(); +} + +pub inline fn getAssertionHandler(puserdata: [*c]?*anyopaque) AssertionHandler { + return c.SDL_GetAssertionHandler(puserdata); +} + +pub inline fn getAssertionReport() *const AssertData { + return @ptrCast(c.SDL_GetAssertionReport()); +} + +pub inline fn resetAssertionReport() void { + return c.SDL_ResetAssertionReport(); +} + diff --git a/lib/sdl3/v2/asyncio.zig b/lib/sdl3/v2/asyncio.zig new file mode 100644 index 0000000..167f8f4 --- /dev/null +++ b/lib/sdl3/v2/asyncio.zig @@ -0,0 +1,80 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const AsyncIO = opaque { + pub inline fn getAsyncIOSize(asyncio: *AsyncIO) i64 { + return c.SDL_GetAsyncIOSize(asyncio); + } + + pub inline fn readAsyncIO( + asyncio: *AsyncIO, + ptr: ?*anyopaque, + offset: u64, + size: u64, + queue: ?*AsyncIOQueue, + userdata: ?*anyopaque, + ) bool { + return c.SDL_ReadAsyncIO(asyncio, ptr, offset, size, queue, userdata); + } + + pub inline fn writeAsyncIO( + asyncio: *AsyncIO, + ptr: ?*anyopaque, + offset: u64, + size: u64, + queue: ?*AsyncIOQueue, + userdata: ?*anyopaque, + ) bool { + return c.SDL_WriteAsyncIO(asyncio, ptr, offset, size, queue, userdata); + } + + pub inline fn closeAsyncIO( + asyncio: *AsyncIO, + flush: bool, + queue: ?*AsyncIOQueue, + userdata: ?*anyopaque, + ) bool { + return c.SDL_CloseAsyncIO(asyncio, flush, queue, userdata); + } +}; + +pub const AsyncIOOutcome = extern struct { + asyncio: ?*AsyncIO, // what generated this task. This pointer will be invalid if it was closed! + type: AsyncIOTaskType, // What sort of task was this? Read, write, etc? + result: AsyncIOResult, // the result of the work (success, failure, cancellation). + buffer: ?*anyopaque, // buffer where data was read/written. + offset: u64, // offset in the SDL_AsyncIO where data was read/written. + bytes_requested: u64, // number of bytes the task was to read/write. + bytes_transferred: u64, // actual number of bytes that were read/written. + userdata: ?*anyopaque, // pointer provided by the app when starting the task +}; + +pub const AsyncIOQueue = opaque { + pub inline fn destroyAsyncIOQueue(asyncioqueue: *AsyncIOQueue) void { + return c.SDL_DestroyAsyncIOQueue(asyncioqueue); + } + + pub inline fn getAsyncIOResult(asyncioqueue: *AsyncIOQueue, outcome: ?*AsyncIOOutcome) bool { + return c.SDL_GetAsyncIOResult(asyncioqueue, outcome); + } + + pub inline fn waitAsyncIOResult(asyncioqueue: *AsyncIOQueue, outcome: ?*AsyncIOOutcome, timeoutMS: i32) bool { + return c.SDL_WaitAsyncIOResult(asyncioqueue, outcome, timeoutMS); + } + + pub inline fn signalAsyncIOQueue(asyncioqueue: *AsyncIOQueue) void { + return c.SDL_SignalAsyncIOQueue(asyncioqueue); + } +}; + +pub inline fn asyncIOFromFile(file: [*c]const u8, mode: [*c]const u8) ?*AsyncIO { + return c.SDL_AsyncIOFromFile(file, mode); +} + +pub inline fn createAsyncIOQueue() ?*AsyncIOQueue { + return c.SDL_CreateAsyncIOQueue(); +} + +pub inline fn loadFileAsync(file: [*c]const u8, queue: ?*AsyncIOQueue, userdata: ?*anyopaque) bool { + return c.SDL_LoadFileAsync(file, queue, userdata); +} diff --git a/lib/sdl3/v2/atomic.zig b/lib/sdl3/v2/atomic.zig new file mode 100644 index 0000000..fb91f6c --- /dev/null +++ b/lib/sdl3/v2/atomic.zig @@ -0,0 +1,70 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const SpinLock = c_int; + +pub inline fn tryLockSpinlock(lock: ?*SpinLock) bool { + return c.SDL_TryLockSpinlock(lock); +} + +pub inline fn lockSpinlock(lock: ?*SpinLock) void { + return c.SDL_LockSpinlock(lock); +} + +pub inline fn unlockSpinlock(lock: ?*SpinLock) void { + return c.SDL_UnlockSpinlock(lock); +} + +pub inline fn memoryBarrierReleaseFunction() void { + return c.SDL_MemoryBarrierReleaseFunction(); +} + +pub inline fn memoryBarrierAcquireFunction() void { + return c.SDL_MemoryBarrierAcquireFunction(); +} + +pub const KernelMemoryBarrierFunc = *const fn () callconv(.C) void; + +pub const AtomicInt = extern struct {}; + +pub inline fn compareAndSwapAtomicInt(a: ?*AtomicInt, oldval: c_int, newval: c_int) bool { + return c.SDL_CompareAndSwapAtomicInt(a, oldval, newval); +} + +pub inline fn setAtomicInt(a: ?*AtomicInt, v: c_int) c_int { + return c.SDL_SetAtomicInt(a, v); +} + +pub inline fn getAtomicInt(a: ?*AtomicInt) c_int { + return c.SDL_GetAtomicInt(a); +} + +pub inline fn addAtomicInt(a: ?*AtomicInt, v: c_int) c_int { + return c.SDL_AddAtomicInt(a, v); +} + +pub const AtomicU32 = extern struct {}; + +pub inline fn compareAndSwapAtomicU32(a: ?*AtomicU32, oldval: u32, newval: u32) bool { + return c.SDL_CompareAndSwapAtomicU32(a, oldval, newval); +} + +pub inline fn setAtomicU32(a: ?*AtomicU32, v: u32) u32 { + return c.SDL_SetAtomicU32(a, v); +} + +pub inline fn getAtomicU32(a: ?*AtomicU32) u32 { + return c.SDL_GetAtomicU32(a); +} + +pub inline fn compareAndSwapAtomicPointer(a: [*c]?*anyopaque, oldval: ?*anyopaque, newval: ?*anyopaque) bool { + return c.SDL_CompareAndSwapAtomicPointer(a, oldval, newval); +} + +pub inline fn setAtomicPointer(a: [*c]?*anyopaque, v: ?*anyopaque) ?*anyopaque { + return c.SDL_SetAtomicPointer(a, v); +} + +pub inline fn getAtomicPointer(a: [*c]?*anyopaque) ?*anyopaque { + return c.SDL_GetAtomicPointer(a); +} diff --git a/lib/sdl3/v2/audio.zig b/lib/sdl3/v2/audio.zig new file mode 100644 index 0000000..60f325f --- /dev/null +++ b/lib/sdl3/v2/audio.zig @@ -0,0 +1,253 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const IOStream = opaque { + pub inline fn loadWAV_IO(iostream: *IOStream, closeio: bool, spec: ?*AudioSpec, audio_buf: Uint8 **, audio_len: *u32,) bool { + return c.SDL_LoadWAV_IO(iostream, closeio, spec, audio_buf, @ptrCast(audio_len)); + } + +}; + +pub const AudioFormat = enum(c_int) { + audioS16, + audioS32, + audioF32, +}; + +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: const int *, count: c_int) bool { + return c.SDL_SetAudioStreamInputChannelMap(audiostream, chmap, count); + } + + pub inline fn setAudioStreamOutputChannelMap(audiostream: *AudioStream, chmap: const 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 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: ?*AudioStream * const, 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: ?*AudioStream * const, 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 AudioStreamCallback = *const fn(userdata: ?*anyopaque, stream: ?*AudioStream, additional_amount: c_int, total_amount: c_int) callconv(.C) void; + +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 = *const fn(userdata: ?*anyopaque, spec: *const AudioSpec, buffer: *f32, buflen: c_int) callconv(.C) void; + +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: Uint8 **, 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: Uint8 **, 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/lib/sdl3/v2/camera.zig b/lib/sdl3/v2/camera.zig new file mode 100644 index 0000000..014c157 --- /dev/null +++ b/lib/sdl3/v2/camera.zig @@ -0,0 +1,155 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PixelFormat = enum(c_int) { + pixelformatUnknown, + pixelformatIndex1lsb, + pixelformatIndex1msb, + pixelformatIndex2lsb, + pixelformatIndex2msb, + pixelformatIndex4lsb, + pixelformatIndex4msb, + pixelformatIndex8, + pixelformatRgb332, + pixelformatXrgb4444, + pixelformatXbgr4444, + pixelformatXrgb1555, + pixelformatXbgr1555, + pixelformatArgb4444, + pixelformatRgba4444, + pixelformatAbgr4444, + pixelformatBgra4444, + pixelformatArgb1555, + pixelformatRgba5551, + pixelformatAbgr1555, + pixelformatBgra5551, + pixelformatRgb565, + pixelformatBgr565, + pixelformatRgb24, + pixelformatBgr24, + pixelformatXrgb8888, + pixelformatRgbx8888, + pixelformatXbgr8888, + pixelformatBgrx8888, + pixelformatArgb8888, + pixelformatRgba8888, + pixelformatAbgr8888, + pixelformatBgra8888, + pixelformatXrgb2101010, + pixelformatXbgr2101010, + pixelformatArgb2101010, + pixelformatAbgr2101010, + pixelformatRgb48, + pixelformatBgr48, + pixelformatRgba64, + pixelformatArgb64, + pixelformatBgra64, + pixelformatAbgr64, + pixelformatRgb48Float, + pixelformatBgr48Float, + pixelformatRgba64Float, + pixelformatArgb64Float, + pixelformatBgra64Float, + pixelformatAbgr64Float, + pixelformatRgb96Float, + pixelformatBgr96Float, + pixelformatRgba128Float, + pixelformatArgb128Float, + pixelformatBgra128Float, + pixelformatAbgr128Float, + pixelformatRgba32, + pixelformatArgb32, + pixelformatBgra32, + pixelformatAbgr32, + pixelformatRgbx32, + pixelformatXrgb32, + pixelformatBgrx32, + pixelformatXbgr32, +}; + +pub const Surface = opaque {}; + +pub const Colorspace = enum(c_int) { + colorspaceUnknown, +}; + +pub const PropertiesID = u32; + +pub const CameraID = u32; + +pub const Camera = opaque { + pub inline fn getCameraPermissionState(camera: *Camera) c_int { + return c.SDL_GetCameraPermissionState(camera); + } + + pub inline fn getCameraID(camera: *Camera) CameraID { + return c.SDL_GetCameraID(camera); + } + + pub inline fn getCameraProperties(camera: *Camera) PropertiesID { + return c.SDL_GetCameraProperties(camera); + } + + pub inline fn getCameraFormat(camera: *Camera, spec: ?*CameraSpec) bool { + return c.SDL_GetCameraFormat(camera, spec); + } + + pub inline fn acquireCameraFrame(camera: *Camera, timestampNS: *u64) ?*Surface { + return c.SDL_AcquireCameraFrame(camera, @ptrCast(timestampNS)); + } + + pub inline fn releaseCameraFrame(camera: *Camera, frame: ?*Surface) void { + return c.SDL_ReleaseCameraFrame(camera, frame); + } + + pub inline fn closeCamera(camera: *Camera) void { + return c.SDL_CloseCamera(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 demoninator ((num / denom) == FPS, (denom / num) == duration in seconds) +}; + +pub const CameraPosition = enum(c_int) { + cameraPositionUnknown, + cameraPositionFrontFacing, + cameraPositionBackFacing, +}; + +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 c.SDL_GetCameras(@ptrCast(count)); +} + +pub inline fn getCameraSupportedFormats(instance_id: CameraID, count: *c_int) ?*?*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 c.SDL_OpenCamera(instance_id, @ptrCast(spec)); +} diff --git a/lib/sdl3/v2/clipboard.zig b/lib/sdl3/v2/clipboard.zig new file mode 100644 index 0000000..9898845 --- /dev/null +++ b/lib/sdl3/v2/clipboard.zig @@ -0,0 +1,56 @@ +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 = *const fn (userdata: ?*anyopaque, mime_type: [*c]const u8, size: *usize) callconv(.C) ?*const anyopaque; + +pub const ClipboardCleanupCallback = *const fn (userdata: ?*anyopaque) callconv(.C) void; + +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/lib/sdl3/v2/cpuinfo.zig b/lib/sdl3/v2/cpuinfo.zig new file mode 100644 index 0000000..bdca40f --- /dev/null +++ b/lib/sdl3/v2/cpuinfo.zig @@ -0,0 +1,74 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn getNumLogicalCPUCores() c_int { + return c.SDL_GetNumLogicalCPUCores(); +} + +pub inline fn getCPUCacheLineSize() c_int { + return c.SDL_GetCPUCacheLineSize(); +} + +pub inline fn hasAltiVec() bool { + return c.SDL_HasAltiVec(); +} + +pub inline fn hasMMX() bool { + return c.SDL_HasMMX(); +} + +pub inline fn hasSSE() bool { + return c.SDL_HasSSE(); +} + +pub inline fn hasSSE2() bool { + return c.SDL_HasSSE2(); +} + +pub inline fn hasSSE3() bool { + return c.SDL_HasSSE3(); +} + +pub inline fn hasSSE41() bool { + return c.SDL_HasSSE41(); +} + +pub inline fn hasSSE42() bool { + return c.SDL_HasSSE42(); +} + +pub inline fn hasAVX() bool { + return c.SDL_HasAVX(); +} + +pub inline fn hasAVX2() bool { + return c.SDL_HasAVX2(); +} + +pub inline fn hasAVX512F() bool { + return c.SDL_HasAVX512F(); +} + +pub inline fn hasARMSIMD() bool { + return c.SDL_HasARMSIMD(); +} + +pub inline fn hasNEON() bool { + return c.SDL_HasNEON(); +} + +pub inline fn hasLSX() bool { + return c.SDL_HasLSX(); +} + +pub inline fn hasLASX() bool { + return c.SDL_HasLASX(); +} + +pub inline fn getSystemRAM() c_int { + return c.SDL_GetSystemRAM(); +} + +pub inline fn getSIMDAlignment() usize { + return c.SDL_GetSIMDAlignment(); +} diff --git a/lib/sdl3/v2/dialog.zig b/lib/sdl3/v2/dialog.zig new file mode 100644 index 0000000..e3bc5fb --- /dev/null +++ b/lib/sdl3/v2/dialog.zig @@ -0,0 +1,61 @@ +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 = *const fn (userdata: ?*anyopaque, filelist: [*c]const [*c]const u8, filter: c_int) callconv(.C) void; + +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/lib/sdl3/v2/endian.zig b/lib/sdl3/v2/endian.zig new file mode 100644 index 0000000..c1f53b9 --- /dev/null +++ b/lib/sdl3/v2/endian.zig @@ -0,0 +1,2 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; diff --git a/lib/sdl3/v2/filesystem.zig b/lib/sdl3/v2/filesystem.zig new file mode 100644 index 0000000..a916ff0 --- /dev/null +++ b/lib/sdl3/v2/filesystem.zig @@ -0,0 +1,69 @@ +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 inline fn getUserFolder(folder: Folder) [*c]const u8 { + return c.SDL_GetUserFolder(folder); +} + +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 EnumerateDirectoryCallback = *const fn (userdata: ?*anyopaque, dirname: [*c]const u8, fname: [*c]const u8) callconv(.C) EnumerationResult; + +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/lib/sdl3/v2/gamepad.zig b/lib/sdl3/v2/gamepad.zig new file mode 100644 index 0000000..a23c213 --- /dev/null +++ b/lib/sdl3/v2/gamepad.zig @@ -0,0 +1,419 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const JoystickConnectionState = enum(c_int) { + joystickConnectionInvalid, + 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 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) ?*?*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) { + gamepadTypeUnknown, + gamepadTypeStandard, + gamepadTypeXbox360, + gamepadTypeXboxone, + gamepadTypePs3, + gamepadTypePs4, + gamepadTypePs5, + gamepadTypeNintendoSwitchPro, + gamepadTypeNintendoSwitchJoyconLeft, + gamepadTypeNintendoSwitchJoyconRight, + gamepadTypeNintendoSwitchJoyconPair, + gamepadTypeCount, +}; + +pub const GamepadButton = enum(c_int) { + gamepadButtonInvalid, + gamepadButtonBack, + gamepadButtonGuide, + gamepadButtonStart, + gamepadButtonLeftStick, + gamepadButtonRightStick, + gamepadButtonLeftShoulder, + gamepadButtonRightShoulder, + gamepadButtonDpadUp, + gamepadButtonDpadDown, + gamepadButtonDpadLeft, + gamepadButtonDpadRight, + gamepadButtonCount, +}; + +pub const GamepadButtonLabel = enum(c_int) { + gamepadButtonLabelUnknown, + gamepadButtonLabelA, + gamepadButtonLabelB, + gamepadButtonLabelX, + gamepadButtonLabelY, + gamepadButtonLabelCross, + gamepadButtonLabelCircle, + gamepadButtonLabelSquare, + gamepadButtonLabelTriangle, +}; + +pub const GamepadAxis = enum(c_int) { + gamepadAxisInvalid, + gamepadAxisLeftx, + gamepadAxisLefty, + gamepadAxisRightx, + gamepadAxisRighty, + gamepadAxisLeftTrigger, + gamepadAxisRightTrigger, + gamepadAxisCount, +}; + +pub const GamepadBindingType = enum(c_int) { + gamepadBindtypeNone, + gamepadBindtypeButton, + gamepadBindtypeAxis, + gamepadBindtypeHat, +}; + +pub const GamepadBinding = extern struct { + input_type: GamepadBindingType, + button: c_int, + axis: c_int, + axis_min: c_int, + axis_max: c_int, + hat: c_int, + hat_mask: c_int, + output_type: GamepadBindingType, + button: GamepadButton, + axis: GamepadAxis, + axis_min: c_int, + axis_max: c_int, +}; + +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/lib/sdl3/v2/guid.zig b/lib/sdl3/v2/guid.zig new file mode 100644 index 0000000..bb1a7a7 --- /dev/null +++ b/lib/sdl3/v2/guid.zig @@ -0,0 +1,14 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const GUID = extern struct { + data: [16]u8, +}; + +pub inline fn guidToString(guid: GUID, pszGUID: [*c]u8, cbGUID: c_int) void { + return c.SDL_GUIDToString(guid, pszGUID, cbGUID); +} + +pub inline fn stringToGUID(pchGUID: [*c]const u8) GUID { + return c.SDL_StringToGUID(pchGUID); +} diff --git a/lib/sdl3/v2/haptic.zig b/lib/sdl3/v2/haptic.zig new file mode 100644 index 0000000..18e4862 --- /dev/null +++ b/lib/sdl3/v2/haptic.zig @@ -0,0 +1,233 @@ +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) c_int { + return c.SDL_CreateHapticEffect(haptic, @ptrCast(effect)); + } + + pub inline fn updateHapticEffect(haptic: *Haptic, effect: c_int, data: *const HapticEffect) bool { + return c.SDL_UpdateHapticEffect(haptic, effect, @ptrCast(data)); + } + + pub inline fn runHapticEffect(haptic: *Haptic, effect: c_int, iterations: u32) bool { + return c.SDL_RunHapticEffect(haptic, effect, iterations); + } + + pub inline fn stopHapticEffect(haptic: *Haptic, effect: c_int) bool { + return c.SDL_StopHapticEffect(haptic, effect); + } + + pub inline fn destroyHapticEffect(haptic: *Haptic, effect: c_int) void { + return c.SDL_DestroyHapticEffect(haptic, effect); + } + + pub inline fn getHapticEffectStatus(haptic: *Haptic, effect: c_int) 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 HapticDirection = extern struct { + type: u8, // The type of encoding. + dir: [3]i32, // The encoded direction. +}; + +pub const HapticConstant = extern struct { + type: u16, // 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: u16, // 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: u16, // 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: u16, // 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: Uint16 *, // 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: u16, // 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/lib/sdl3/v2/hidapi.zig b/lib/sdl3/v2/hidapi.zig new file mode 100644 index 0000000..6b35a61 --- /dev/null +++ b/lib/sdl3/v2/hidapi.zig @@ -0,0 +1,120 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const hid_device = opaque { + pub inline fn hid_write(hid_device: *hid_device, data: const unsigned char *, length: usize) c_int { + return c.SDL_hid_write(hid_device, data, length); + } + + pub inline fn hid_read_timeout(hid_device: *hid_device, data: unsigned char *, length: usize, milliseconds: c_int,) c_int { + return c.SDL_hid_read_timeout(hid_device, data, length, milliseconds); + } + + pub inline fn hid_read(hid_device: *hid_device, data: unsigned char *, length: usize) c_int { + return c.SDL_hid_read(hid_device, data, length); + } + + pub inline fn hid_set_nonblocking(hid_device: *hid_device, nonblock: c_int) c_int { + return c.SDL_hid_set_nonblocking(hid_device, nonblock); + } + + pub inline fn hid_send_feature_report(hid_device: *hid_device, data: const unsigned char *, length: usize) c_int { + return c.SDL_hid_send_feature_report(hid_device, data, length); + } + + pub inline fn hid_get_feature_report(hid_device: *hid_device, data: unsigned char *, length: usize) c_int { + return c.SDL_hid_get_feature_report(hid_device, data, length); + } + + pub inline fn hid_get_input_report(hid_device: *hid_device, data: unsigned char *, length: usize) c_int { + return c.SDL_hid_get_input_report(hid_device, data, length); + } + + pub inline fn hid_close(hid_device: *hid_device) c_int { + return c.SDL_hid_close(hid_device); + } + + pub inline fn hid_get_manufacturer_string(hid_device: *hid_device, string: wchar_t *, maxlen: usize) c_int { + return c.SDL_hid_get_manufacturer_string(hid_device, string, maxlen); + } + + pub inline fn hid_get_product_string(hid_device: *hid_device, string: wchar_t *, maxlen: usize) c_int { + return c.SDL_hid_get_product_string(hid_device, string, maxlen); + } + + pub inline fn hid_get_serial_number_string(hid_device: *hid_device, string: wchar_t *, maxlen: usize) c_int { + return c.SDL_hid_get_serial_number_string(hid_device, string, maxlen); + } + + pub inline fn hid_get_indexed_string(hid_device: *hid_device, string_index: c_int, string: wchar_t *, maxlen: usize,) c_int { + return c.SDL_hid_get_indexed_string(hid_device, string_index, string, maxlen); + } + + pub inline fn hid_get_device_info(hid_device: *hid_device) ?*hid_device_info { + return c.SDL_hid_get_device_info(hid_device); + } + + pub inline fn hid_get_report_descriptor(hid_device: *hid_device, buf: unsigned char *, buf_size: usize) c_int { + return c.SDL_hid_get_report_descriptor(hid_device, buf, buf_size); + } + +}; + +pub const hid_bus_type = enum(c_int) { + hidApiBusUnknown, + hidApiBusUsb, + hidApiBusBluetooth, + hidApiBusI2c, + hidApiBusSpi, +}; + +pub const hid_device_info = extern struct { + path: [*c]u8, + vendor_id: unsigned short, + product_id: unsigned short, + serial_number: wchar_t *, + release_number: unsigned short, + manufacturer_string: wchar_t *, + product_string: wchar_t *, + usage_page: unsigned short, + usage: unsigned short, + interface_number: c_int, + interface_class: c_int, + interface_subclass: c_int, + interface_protocol: c_int, + bus_type: hid_bus_type, + next: struct SDL_hid_device_info *, +}; + +pub inline fn hid_init() c_int { + return c.SDL_hid_init(); +} + +pub inline fn hid_exit() c_int { + return c.SDL_hid_exit(); +} + +pub inline fn hid_device_change_count() u32 { + return c.SDL_hid_device_change_count(); +} + +pub inline fn hid_enumerate(vendor_id: unsigned short, product_id: unsigned short) ?*hid_device_info { + return c.SDL_hid_enumerate(vendor_id, product_id); +} + +pub inline fn hid_free_enumeration(devs: ?*hid_device_info) void { + return c.SDL_hid_free_enumeration(devs); +} + +pub inline fn hid_open(vendor_id: unsigned short, product_id: unsigned short, serial_number: const wchar_t *) ?*hid_device { + return c.SDL_hid_open(vendor_id, product_id, serial_number); +} + +pub inline fn hid_open_path(path: [*c]const u8) ?*hid_device { + return c.SDL_hid_open_path(path); +} + +pub inline fn hid_ble_scan(active: bool) void { + return c.SDL_hid_ble_scan(active); +} + diff --git a/lib/sdl3/v2/hints.zig b/lib/sdl3/v2/hints.zig new file mode 100644 index 0000000..0c207a5 --- /dev/null +++ b/lib/sdl3/v2/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 = *const fn (userdata: ?*anyopaque, name: [*c]const u8, oldValue: [*c]const u8, newValue: [*c]const u8) callconv(.C) void; + +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/lib/sdl3/v2/iostream.zig b/lib/sdl3/v2/iostream.zig index 60fd72c..714ef6e 100644 --- a/lib/sdl3/v2/iostream.zig +++ b/lib/sdl3/v2/iostream.zig @@ -5,12 +5,12 @@ pub const PropertiesID = u32; pub const IOStreamInterface = extern struct { version: u32, - userdata: Sint64 (SDLCALL *size)(void *, - whence: Sint64 (SDLCALL *seek)(void *userdata, Sint64 offset, SDL_IOWhence, - status: size_t (SDLCALL *read)(void *userdata, void *ptr, size_t size, SDL_IOStatus *, - status: size_t (SDLCALL *write)(void *userdata, const void *ptr, size_t size, SDL_IOStatus *, - status: bool (SDLCALL *flush)(void *userdata, SDL_IOStatus *, - userdata: bool (SDLCALL *close)(void *, + size: ?*const anyopaque, + seek: ?*const anyopaque, + read: ?*const anyopaque, + write: ?*const anyopaque, + flush: ?*const anyopaque, + close: ?*const anyopaque, }; pub const IOStream = opaque { diff --git a/lib/sdl3/v2/joystick.zig b/lib/sdl3/v2/joystick.zig new file mode 100644 index 0000000..e813170 --- /dev/null +++ b/lib/sdl3/v2/joystick.zig @@ -0,0 +1,304 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const GUID = extern struct { + data: [16]u8, +}; + +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 float *, num_values: c_int,) bool { + return c.SDL_SendJoystickVirtualSensorData(joystick, @intFromEnum(type), sensor_timestamp, 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: Sint16 *) bool { + return c.SDL_GetJoystickAxisInitialState(joystick, axis, 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) { + joystickConnectionInvalid, + joystickConnectionUnknown, + joystickConnectionWired, + joystickConnectionWireless, +}; + +pub inline fn lockJoysticks(SDL_ACQUIRE(SDL_joystick_lock: void)) void { + return c.SDL_LockJoysticks(SDL_ACQUIRE(SDL_joystick_lock); +} + +pub inline fn unlockJoysticks(SDL_RELEASE(SDL_joystick_lock: void)) void { + return c.SDL_UnlockJoysticks(SDL_RELEASE(SDL_joystick_lock); +} + +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: Uint16 *, product: Uint16 *, version: Uint16 *, crc16: Uint16 *,) void { + return c.SDL_GetJoystickGUIDInfo(guid, vendor, product, version, 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/lib/sdl3/v2/loadso.zig b/lib/sdl3/v2/loadso.zig new file mode 100644 index 0000000..e326ea4 --- /dev/null +++ b/lib/sdl3/v2/loadso.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +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/lib/sdl3/v2/locale.zig b/lib/sdl3/v2/locale.zig new file mode 100644 index 0000000..2f8fa01 --- /dev/null +++ b/lib/sdl3/v2/locale.zig @@ -0,0 +1,11 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Locale = extern struct { + language: [*c]const u8, // A language name, like "en" for English. + country: [*c]const u8, // A country, like "US" for America. Can be NULL. +}; + +pub inline fn getPreferredLocales(count: *c_int) ?*?*Locale { + return c.SDL_GetPreferredLocales(@ptrCast(count)); +} diff --git a/lib/sdl3/v2/log.zig b/lib/sdl3/v2/log.zig new file mode 100644 index 0000000..be186b3 --- /dev/null +++ b/lib/sdl3/v2/log.zig @@ -0,0 +1,148 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const LogCategory = enum(c_int) { + logCategoryApplication, + logCategoryError, + logCategoryAssert, + logCategorySystem, + logCategoryAudio, + logCategoryVideo, + logCategoryRender, + logCategoryInput, + logCategoryTest, + logCategoryGpu, + logCategoryReserved2, + logCategoryReserved3, + logCategoryReserved4, + logCategoryReserved5, + logCategoryReserved6, + logCategoryReserved7, + logCategoryReserved8, + logCategoryReserved9, + logCategoryReserved10, + logCategoryCustom, +}; + +pub const LogPriority = enum(c_int) { + logPriorityInvalid, + logPriorityTrace, + logPriorityVerbose, + logPriorityDebug, + logPriorityInfo, + logPriorityWarn, + logPriorityError, + logPriorityCritical, + logPriorityCount, +}; + +pub inline fn setLogPriorities(priority: LogPriority) void { + return c.SDL_SetLogPriorities(priority); +} + +pub inline fn setLogPriority(category: c_int, priority: LogPriority) void { + return c.SDL_SetLogPriority(category, priority); +} + +pub inline fn getLogPriority(category: c_int) LogPriority { + return c.SDL_GetLogPriority(category); +} + +pub inline fn resetLogPriorities() void { + return c.SDL_ResetLogPriorities(); +} + +pub inline fn setLogPriorityPrefix(priority: LogPriority, prefix: [*c]const u8) bool { + return c.SDL_SetLogPriorityPrefix(priority, prefix); +} + +pub inline fn log(fmt: [*c]const u8, ...) void { + return c.SDL_Log( + fmt, + ); +} + +pub inline fn logTrace(category: c_int, fmt: [*c]const u8, ...) void { + return c.SDL_LogTrace( + category, + fmt, + ); +} + +pub inline fn logVerbose(category: c_int, fmt: [*c]const u8, ...) void { + return c.SDL_LogVerbose( + category, + fmt, + ); +} + +pub inline fn logDebug(category: c_int, fmt: [*c]const u8, ...) void { + return c.SDL_LogDebug( + category, + fmt, + ); +} + +pub inline fn logInfo(category: c_int, fmt: [*c]const u8, ...) void { + return c.SDL_LogInfo( + category, + fmt, + ); +} + +pub inline fn logWarn(category: c_int, fmt: [*c]const u8, ...) void { + return c.SDL_LogWarn( + category, + fmt, + ); +} + +pub inline fn logError(category: c_int, fmt: [*c]const u8, ...) void { + return c.SDL_LogError( + category, + fmt, + ); +} + +pub inline fn logCritical(category: c_int, fmt: [*c]const u8, ...) void { + return c.SDL_LogCritical( + category, + fmt, + ); +} + +pub inline fn logMessage( + category: c_int, + priority: LogPriority, + fmt: [*c]const u8, + ..., +) void { + return c.SDL_LogMessage( + category, + priority, + fmt, + ); +} + +pub inline fn logMessageV( + category: c_int, + priority: LogPriority, + fmt: [*c]const u8, + ap: std.builtin.VaList, +) void { + return c.SDL_LogMessageV(category, priority, fmt, ap); +} + +pub const LogOutputFunction = *const fn (userdata: ?*anyopaque, category: c_int, priority: LogPriority, message: [*c]const u8) callconv(.C) void; + +pub inline fn getDefaultLogOutputFunction() LogOutputFunction { + return c.SDL_GetDefaultLogOutputFunction(); +} + +pub inline fn getLogOutputFunction(callback: ?*LogOutputFunction, userdata: [*c]?*anyopaque) void { + return c.SDL_GetLogOutputFunction(callback, userdata); +} + +pub inline fn setLogOutputFunction(callback: LogOutputFunction, userdata: ?*anyopaque) void { + return c.SDL_SetLogOutputFunction(callback, userdata); +} diff --git a/lib/sdl3/v2/messagebox.zig b/lib/sdl3/v2/messagebox.zig new file mode 100644 index 0000000..360a6ec --- /dev/null +++ b/lib/sdl3/v2/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 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, +}; + +pub const MessageBoxColorScheme = extern struct { + colors: [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/lib/sdl3/v2/metal.zig b/lib/sdl3/v2/metal.zig new file mode 100644 index 0000000..5326e5a --- /dev/null +++ b/lib/sdl3/v2/metal.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque { + pub inline fn metal_CreateView(window: *Window) MetalView { + return c.SDL_Metal_CreateView(window); + } +}; + +pub inline fn metal_DestroyView(view: MetalView) void { + return c.SDL_Metal_DestroyView(view); +} + +pub inline fn metal_GetLayer(view: MetalView) ?*anyopaque { + return c.SDL_Metal_GetLayer(view); +} diff --git a/lib/sdl3/v2/misc.zig b/lib/sdl3/v2/misc.zig new file mode 100644 index 0000000..2bcc6d5 --- /dev/null +++ b/lib/sdl3/v2/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/lib/sdl3/v2/mutex.zig b/lib/sdl3/v2/mutex.zig new file mode 100644 index 0000000..be38fb1 --- /dev/null +++ b/lib/sdl3/v2/mutex.zig @@ -0,0 +1,145 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const ThreadID = u64; + +pub const AtomicInt = extern struct { +}; + +pub const Mutex = opaque { + pub inline fn destroyMutex(mutex: *Mutex) void { + return c.SDL_DestroyMutex(mutex); + } + +}; + +pub inline fn createMutex() ?*Mutex { + return c.SDL_CreateMutex(); +} + +pub inline fn lockMutex(SDL_ACQUIRE(mutex: Mutex *mutex)) void { + return c.SDL_LockMutex(SDL_ACQUIRE(mutex); +} + +pub inline fn tryLockMutex(SDL_TRY_ACQUIRE(0: Mutex *mutex), mutex) bool { + return c.SDL_TryLockMutex(SDL_TRY_ACQUIRE(0, ); +} + +pub inline fn unlockMutex(SDL_RELEASE(mutex: Mutex *mutex)) void { + return c.SDL_UnlockMutex(SDL_RELEASE(mutex); +} + +pub const RWLock = opaque { + pub inline fn destroyRWLock(rwlock: *RWLock) void { + return c.SDL_DestroyRWLock(rwlock); + } + +}; + +pub inline fn createRWLock() ?*RWLock { + return c.SDL_CreateRWLock(); +} + +pub inline fn lockRWLockForReading(SDL_ACQUIRE_SHARED(rwlock: RWLock *rwlock)) void { + return c.SDL_LockRWLockForReading(SDL_ACQUIRE_SHARED(rwlock); +} + +pub inline fn lockRWLockForWriting(SDL_ACQUIRE(rwlock: RWLock *rwlock)) void { + return c.SDL_LockRWLockForWriting(SDL_ACQUIRE(rwlock); +} + +pub inline fn tryLockRWLockForReading(SDL_TRY_ACQUIRE_SHARED(0: RWLock *rwlock), rwlock) bool { + return c.SDL_TryLockRWLockForReading(SDL_TRY_ACQUIRE_SHARED(0, ); +} + +pub inline fn tryLockRWLockForWriting(SDL_TRY_ACQUIRE(0: RWLock *rwlock), rwlock) bool { + return c.SDL_TryLockRWLockForWriting(SDL_TRY_ACQUIRE(0, ); +} + +pub inline fn unlockRWLock(SDL_RELEASE_GENERIC(rwlock: RWLock *rwlock)) void { + return c.SDL_UnlockRWLock(SDL_RELEASE_GENERIC(rwlock); +} + +pub const Semaphore = opaque { + pub inline fn destroySemaphore(semaphore: *Semaphore) void { + return c.SDL_DestroySemaphore(semaphore); + } + + pub inline fn waitSemaphore(semaphore: *Semaphore) void { + return c.SDL_WaitSemaphore(semaphore); + } + + pub inline fn tryWaitSemaphore(semaphore: *Semaphore) bool { + return c.SDL_TryWaitSemaphore(semaphore); + } + + pub inline fn waitSemaphoreTimeout(semaphore: *Semaphore, timeoutMS: i32) bool { + return c.SDL_WaitSemaphoreTimeout(semaphore, timeoutMS); + } + + pub inline fn signalSemaphore(semaphore: *Semaphore) void { + return c.SDL_SignalSemaphore(semaphore); + } + + pub inline fn getSemaphoreValue(semaphore: *Semaphore) u32 { + return c.SDL_GetSemaphoreValue(semaphore); + } + +}; + +pub inline fn createSemaphore(initial_value: u32) ?*Semaphore { + return c.SDL_CreateSemaphore(initial_value); +} + +pub const Condition = opaque { + pub inline fn destroyCondition(condition: *Condition) void { + return c.SDL_DestroyCondition(condition); + } + + pub inline fn signalCondition(condition: *Condition) void { + return c.SDL_SignalCondition(condition); + } + + pub inline fn broadcastCondition(condition: *Condition) void { + return c.SDL_BroadcastCondition(condition); + } + + pub inline fn waitCondition(condition: *Condition, mutex: ?*Mutex) void { + return c.SDL_WaitCondition(condition, mutex); + } + + pub inline fn waitConditionTimeout(condition: *Condition, mutex: ?*Mutex, timeoutMS: i32) bool { + return c.SDL_WaitConditionTimeout(condition, mutex, timeoutMS); + } + +}; + +pub inline fn createCondition() ?*Condition { + return c.SDL_CreateCondition(); +} + +pub const InitStatus = enum(c_int) { + initStatusUninitialized, + initStatusInitializing, + initStatusInitialized, + initStatusUninitializing, +}; + +pub const InitState = extern struct { + status: AtomicInt, + thread: ThreadID, + reserved: ?*anyopaque, +}; + +pub inline fn shouldInit(state: ?*InitState) bool { + return c.SDL_ShouldInit(state); +} + +pub inline fn shouldQuit(state: ?*InitState) bool { + return c.SDL_ShouldQuit(state); +} + +pub inline fn setInitialized(state: ?*InitState, initialized: bool) void { + return c.SDL_SetInitialized(state, initialized); +} + diff --git a/lib/sdl3/v2/opengl.zig b/lib/sdl3/v2/opengl.zig new file mode 100644 index 0000000..c1f53b9 --- /dev/null +++ b/lib/sdl3/v2/opengl.zig @@ -0,0 +1,2 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; diff --git a/lib/sdl3/v2/pen.zig b/lib/sdl3/v2/pen.zig new file mode 100644 index 0000000..21e549f --- /dev/null +++ b/lib/sdl3/v2/pen.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PenID = u32; + +pub const PenInputFlags = packed struct(u32) { + penInputDown: bool = false, // pen is pressed down + penInputButton1: bool = false, // button 1 is pressed + penInputButton2: bool = false, // button 2 is pressed + penInputButton3: bool = false, // button 3 is pressed + penInputButton4: bool = false, // button 4 is pressed + penInputButton5: bool = false, // button 5 is pressed + penInputEraserTip: bool = false, // eraser tip is used + pad0: u24 = 0, + rsvd: bool = false, +}; diff --git a/lib/sdl3/v2/power.zig b/lib/sdl3/v2/power.zig new file mode 100644 index 0000000..85b8aa7 --- /dev/null +++ b/lib/sdl3/v2/power.zig @@ -0,0 +1,6 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub inline fn getPowerInfo(seconds: *c_int, percent: *c_int) PowerState { + return c.SDL_GetPowerInfo(@ptrCast(seconds), @ptrCast(percent)); +} diff --git a/lib/sdl3/v2/process.zig b/lib/sdl3/v2/process.zig new file mode 100644 index 0000000..aeb3f4e --- /dev/null +++ b/lib/sdl3/v2/process.zig @@ -0,0 +1,44 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const IOStream = opaque {}; + +pub const Process = opaque { + pub inline fn getProcessProperties(process: *Process) PropertiesID { + return c.SDL_GetProcessProperties(process); + } + + pub inline fn readProcess(process: *Process, datasize: *usize, exitcode: *c_int) ?*anyopaque { + return c.SDL_ReadProcess(process, @ptrCast(datasize), @ptrCast(exitcode)); + } + + pub inline fn getProcessInput(process: *Process) ?*IOStream { + return c.SDL_GetProcessInput(process); + } + + pub inline fn getProcessOutput(process: *Process) ?*IOStream { + return c.SDL_GetProcessOutput(process); + } + + pub inline fn killProcess(process: *Process, force: bool) bool { + return c.SDL_KillProcess(process, force); + } + + pub inline fn waitProcess(process: *Process, block: bool, exitcode: *c_int) bool { + return c.SDL_WaitProcess(process, block, @ptrCast(exitcode)); + } + + pub inline fn destroyProcess(process: *Process) void { + return c.SDL_DestroyProcess(process); + } +}; + +pub inline fn createProcess(args: [*c]const [*c]const u8, pipe_stdio: bool) ?*Process { + return c.SDL_CreateProcess(args, pipe_stdio); +} + +pub inline fn createProcessWithProperties(props: PropertiesID) ?*Process { + return c.SDL_CreateProcessWithProperties(props); +} diff --git a/lib/sdl3/v2/properties.zig b/lib/sdl3/v2/properties.zig new file mode 100644 index 0000000..908bae6 --- /dev/null +++ b/lib/sdl3/v2/properties.zig @@ -0,0 +1,107 @@ +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 = *const fn (userdata: ?*anyopaque, value: ?*anyopaque) callconv(.C) void; + +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 = *const fn (userdata: ?*anyopaque, props: PropertiesID, name: [*c]const u8) callconv(.C) void; + +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/lib/sdl3/v2/render.zig b/lib/sdl3/v2/render.zig new file mode 100644 index 0000000..9bbe669 --- /dev/null +++ b/lib/sdl3/v2/render.zig @@ -0,0 +1,549 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const FPoint = extern struct { + x: f32, + y: f32, +}; + +pub const PixelFormat = enum(c_int) { + pixelformatUnknown, + pixelformatIndex1lsb, + pixelformatIndex1msb, + pixelformatIndex2lsb, + pixelformatIndex2msb, + pixelformatIndex4lsb, + pixelformatIndex4msb, + pixelformatIndex8, + pixelformatRgb332, + pixelformatXrgb4444, + pixelformatXbgr4444, + pixelformatXrgb1555, + pixelformatXbgr1555, + pixelformatArgb4444, + pixelformatRgba4444, + pixelformatAbgr4444, + pixelformatBgra4444, + pixelformatArgb1555, + pixelformatRgba5551, + pixelformatAbgr1555, + pixelformatBgra5551, + pixelformatRgb565, + pixelformatBgr565, + pixelformatRgb24, + pixelformatBgr24, + pixelformatXrgb8888, + pixelformatRgbx8888, + pixelformatXbgr8888, + pixelformatBgrx8888, + pixelformatArgb8888, + pixelformatRgba8888, + pixelformatAbgr8888, + pixelformatBgra8888, + pixelformatXrgb2101010, + pixelformatXbgr2101010, + pixelformatArgb2101010, + pixelformatAbgr2101010, + pixelformatRgb48, + pixelformatBgr48, + pixelformatRgba64, + pixelformatArgb64, + pixelformatBgra64, + pixelformatAbgr64, + pixelformatRgb48Float, + pixelformatBgr48Float, + pixelformatRgba64Float, + pixelformatArgb64Float, + pixelformatBgra64Float, + pixelformatAbgr64Float, + pixelformatRgb96Float, + pixelformatBgr96Float, + pixelformatRgba128Float, + pixelformatArgb128Float, + pixelformatBgra128Float, + pixelformatAbgr128Float, + pixelformatRgba32, + pixelformatArgb32, + pixelformatBgra32, + pixelformatAbgr32, + pixelformatRgbx32, + pixelformatXrgb32, + pixelformatBgrx32, + pixelformatXbgr32, +}; + +pub const FColor = extern struct { + r: f32, + g: f32, + b: f32, + a: f32, +}; + +pub const Surface = opaque { + pub inline fn createSoftwareRenderer(surface: *Surface) ?*Renderer { + return c.SDL_CreateSoftwareRenderer(surface); + } + +}; + +pub const ScaleMode = enum(c_int) { + scalemodeInvalid, +}; + +pub const PropertiesID = u32; + +pub const BlendMode = u32; + +pub const Window = opaque { + pub inline fn createRenderer(window: *Window, name: [*c]const u8) ?*Renderer { + return c.SDL_CreateRenderer(window, name); + } + + pub inline fn getRenderer(window: *Window) ?*Renderer { + return c.SDL_GetRenderer(window); + } + +}; + +pub const FRect = extern struct { + x: f32, + y: f32, + w: f32, + h: f32, +}; + +pub const Event = extern union { + type: u32, // Event type, shared with all events, Uint32 to cover user events which are not in the SDL_EventType enumeration + common: CommonEvent, // Common event data + display: DisplayEvent, // Display event data + window: WindowEvent, // Window event data + kdevice: KeyboardDeviceEvent, // Keyboard device change event data + key: KeyboardEvent, // Keyboard event data + edit: TextEditingEvent, // Text editing event data + edit_candidates: TextEditingCandidatesEvent, // Text editing candidates event data + text: TextInputEvent, // Text input event data + mdevice: MouseDeviceEvent, // Mouse device change event data + motion: MouseMotionEvent, // Mouse motion event data + button: MouseButtonEvent, // Mouse button event data + wheel: MouseWheelEvent, // Mouse wheel event data + jdevice: JoyDeviceEvent, // Joystick device change event data + jaxis: JoyAxisEvent, // Joystick axis event data + jball: JoyBallEvent, // Joystick ball event data + jhat: JoyHatEvent, // Joystick hat event data + jbutton: JoyButtonEvent, // Joystick button event data + jbattery: JoyBatteryEvent, // Joystick battery event data + gdevice: GamepadDeviceEvent, // Gamepad device event data + gaxis: GamepadAxisEvent, // Gamepad axis event data + gbutton: GamepadButtonEvent, // Gamepad button event data + gtouchpad: GamepadTouchpadEvent, // Gamepad touchpad event data + gsensor: GamepadSensorEvent, // Gamepad sensor event data + adevice: AudioDeviceEvent, // Audio device event data + cdevice: CameraDeviceEvent, // Camera device event data + sensor: SensorEvent, // Sensor event data + quit: QuitEvent, // Quit request event data + user: UserEvent, // Custom event data + tfinger: TouchFingerEvent, // Touch finger event data + pproximity: PenProximityEvent, // Pen proximity event data + ptouch: PenTouchEvent, // Pen tip touching event data + pmotion: PenMotionEvent, // Pen motion event data + pbutton: PenButtonEvent, // Pen button event data + paxis: PenAxisEvent, // Pen axis event data + render: RenderEvent, // Render event data + drop: DropEvent, // Drag and drop event data + clipboard: ClipboardEvent, // Clipboard event data + padding: [128]u8, +}; + +pub const Rect = extern struct { + x: c_int, + y: c_int, + w: c_int, + h: c_int, +}; + +pub const WindowFlags = packed struct(u64) { + windowFullscreen: bool = false, // window is in fullscreen mode + windowOpengl: bool = false, // window usable with OpenGL context + windowOccluded: bool = false, // window is occluded + windowHidden: bool = false, // window is neither mapped onto the desktop nor shown in the taskbar/dock/window list; SDL_ShowWindow() is required for it to become visible + windowBorderless: bool = false, // no window decoration + windowResizable: bool = false, // window can be resized + windowMinimized: bool = false, // window is minimized + windowMaximized: bool = false, // window is maximized + windowMouseGrabbed: bool = false, // window has grabbed mouse input + windowInputFocus: bool = false, // window has input focus + windowMouseFocus: bool = false, // window has mouse focus + windowExternal: bool = false, // window not created by SDL + windowModal: bool = false, // window is modal + windowHighPixelDensity: bool = false, // window uses high pixel density back buffer if possible + windowMouseCapture: bool = false, // window has mouse captured (unrelated to MOUSE_GRABBED) + windowMouseRelativeMode: bool = false, // window has relative mode enabled + windowAlwaysOnTop: bool = false, // window should always be above others + windowUtility: bool = false, // window should be treated as a utility window, not showing in the task bar and window list + windowTooltip: bool = false, // window should be treated as a tooltip and does not get mouse or keyboard focus, requires a parent window + windowPopupMenu: bool = false, // window should be treated as a popup menu, requires a parent window + windowKeyboardGrabbed: bool = false, // window has grabbed keyboard input + windowVulkan: bool = false, // window usable for Vulkan surface + windowMetal: bool = false, // window usable for Metal view + windowTransparent: bool = false, // window with transparent buffer + windowNotFocusable: bool = false, // window should not be focusable + pad0: u38 = 0, + rsvd: bool = false, +}; + +pub const Vertex = extern struct { + position: FPoint, // Vertex position, in SDL_Renderer coordinates + color: FColor, // Vertex color + tex_coord: FPoint, // Normalized texture coordinates, if needed +}; + +pub const Renderer = opaque { + pub inline fn getRenderWindow(renderer: *Renderer) ?*Window { + return c.SDL_GetRenderWindow(renderer); + } + + pub inline fn getRendererName(renderer: *Renderer) [*c]const u8 { + return c.SDL_GetRendererName(renderer); + } + + pub inline fn getRendererProperties(renderer: *Renderer) PropertiesID { + return c.SDL_GetRendererProperties(renderer); + } + + pub inline fn getRenderOutputSize(renderer: *Renderer, w: *c_int, h: *c_int) bool { + return c.SDL_GetRenderOutputSize(renderer, @ptrCast(w), @ptrCast(h)); + } + + pub inline fn getCurrentRenderOutputSize(renderer: *Renderer, w: *c_int, h: *c_int) bool { + return c.SDL_GetCurrentRenderOutputSize(renderer, @ptrCast(w), @ptrCast(h)); + } + + pub inline fn createTexture(renderer: *Renderer, format: PixelFormat, access: TextureAccess, w: c_int, h: c_int,) ?*Texture { + return c.SDL_CreateTexture(renderer, @bitCast(format), access, w, h); + } + + pub inline fn createTextureFromSurface(renderer: *Renderer, surface: ?*Surface) ?*Texture { + return c.SDL_CreateTextureFromSurface(renderer, surface); + } + + pub inline fn createTextureWithProperties(renderer: *Renderer, props: PropertiesID) ?*Texture { + return c.SDL_CreateTextureWithProperties(renderer, props); + } + + pub inline fn setRenderTarget(renderer: *Renderer, texture: ?*Texture) bool { + return c.SDL_SetRenderTarget(renderer, texture); + } + + pub inline fn getRenderTarget(renderer: *Renderer) ?*Texture { + return c.SDL_GetRenderTarget(renderer); + } + + pub inline fn setRenderLogicalPresentation(renderer: *Renderer, w: c_int, h: c_int, mode: RendererLogicalPresentation,) bool { + return c.SDL_SetRenderLogicalPresentation(renderer, w, h, mode); + } + + pub inline fn getRenderLogicalPresentation(renderer: *Renderer, w: *c_int, h: *c_int, mode: ?*RendererLogicalPresentation,) bool { + return c.SDL_GetRenderLogicalPresentation(renderer, @ptrCast(w), @ptrCast(h), mode); + } + + pub inline fn getRenderLogicalPresentationRect(renderer: *Renderer, rect: ?*FRect) bool { + return c.SDL_GetRenderLogicalPresentationRect(renderer, rect); + } + + pub inline fn renderCoordinatesFromWindow(renderer: *Renderer, window_x: f32, window_y: f32, x: *f32, y: *f32,) bool { + return c.SDL_RenderCoordinatesFromWindow(renderer, window_x, window_y, @ptrCast(x), @ptrCast(y)); + } + + pub inline fn renderCoordinatesToWindow(renderer: *Renderer, x: f32, y: f32, window_x: *f32, window_y: *f32,) bool { + return c.SDL_RenderCoordinatesToWindow(renderer, x, y, @ptrCast(window_x), @ptrCast(window_y)); + } + + pub inline fn convertEventToRenderCoordinates(renderer: *Renderer, event: ?*Event) bool { + return c.SDL_ConvertEventToRenderCoordinates(renderer, event); + } + + pub inline fn setRenderViewport(renderer: *Renderer, rect: *const Rect) bool { + return c.SDL_SetRenderViewport(renderer, @ptrCast(rect)); + } + + pub inline fn getRenderViewport(renderer: *Renderer, rect: ?*Rect) bool { + return c.SDL_GetRenderViewport(renderer, rect); + } + + pub inline fn renderViewportSet(renderer: *Renderer) bool { + return c.SDL_RenderViewportSet(renderer); + } + + pub inline fn getRenderSafeArea(renderer: *Renderer, rect: ?*Rect) bool { + return c.SDL_GetRenderSafeArea(renderer, rect); + } + + pub inline fn setRenderClipRect(renderer: *Renderer, rect: *const Rect) bool { + return c.SDL_SetRenderClipRect(renderer, @ptrCast(rect)); + } + + pub inline fn getRenderClipRect(renderer: *Renderer, rect: ?*Rect) bool { + return c.SDL_GetRenderClipRect(renderer, rect); + } + + pub inline fn renderClipEnabled(renderer: *Renderer) bool { + return c.SDL_RenderClipEnabled(renderer); + } + + pub inline fn setRenderScale(renderer: *Renderer, scaleX: f32, scaleY: f32) bool { + return c.SDL_SetRenderScale(renderer, scaleX, scaleY); + } + + pub inline fn getRenderScale(renderer: *Renderer, scaleX: *f32, scaleY: *f32) bool { + return c.SDL_GetRenderScale(renderer, @ptrCast(scaleX), @ptrCast(scaleY)); + } + + pub inline fn setRenderDrawColor(renderer: *Renderer, r: u8, g: u8, b: u8, a: u8,) bool { + return c.SDL_SetRenderDrawColor(renderer, r, g, b, a); + } + + pub inline fn setRenderDrawColorFloat(renderer: *Renderer, r: f32, g: f32, b: f32, a: f32,) bool { + return c.SDL_SetRenderDrawColorFloat(renderer, r, g, b, a); + } + + pub inline fn getRenderDrawColor(renderer: *Renderer, r: [*c]u8, g: [*c]u8, b: [*c]u8, a: [*c]u8,) bool { + return c.SDL_GetRenderDrawColor(renderer, r, g, b, a); + } + + pub inline fn getRenderDrawColorFloat(renderer: *Renderer, r: *f32, g: *f32, b: *f32, a: *f32,) bool { + return c.SDL_GetRenderDrawColorFloat(renderer, @ptrCast(r), @ptrCast(g), @ptrCast(b), @ptrCast(a)); + } + + pub inline fn setRenderColorScale(renderer: *Renderer, scale: f32) bool { + return c.SDL_SetRenderColorScale(renderer, scale); + } + + pub inline fn getRenderColorScale(renderer: *Renderer, scale: *f32) bool { + return c.SDL_GetRenderColorScale(renderer, @ptrCast(scale)); + } + + pub inline fn setRenderDrawBlendMode(renderer: *Renderer, blendMode: BlendMode) bool { + return c.SDL_SetRenderDrawBlendMode(renderer, @intFromEnum(blendMode)); + } + + pub inline fn getRenderDrawBlendMode(renderer: *Renderer, blendMode: ?*BlendMode) bool { + return c.SDL_GetRenderDrawBlendMode(renderer, @intFromEnum(blendMode)); + } + + pub inline fn renderClear(renderer: *Renderer) bool { + return c.SDL_RenderClear(renderer); + } + + pub inline fn renderPoint(renderer: *Renderer, x: f32, y: f32) bool { + return c.SDL_RenderPoint(renderer, x, y); + } + + pub inline fn renderPoints(renderer: *Renderer, points: *const FPoint, count: c_int) bool { + return c.SDL_RenderPoints(renderer, @ptrCast(points), count); + } + + pub inline fn renderLine(renderer: *Renderer, x1: f32, y1: f32, x2: f32, y2: f32,) bool { + return c.SDL_RenderLine(renderer, x1, y1, x2, y2); + } + + pub inline fn renderLines(renderer: *Renderer, points: *const FPoint, count: c_int) bool { + return c.SDL_RenderLines(renderer, @ptrCast(points), count); + } + + pub inline fn renderRect(renderer: *Renderer, rect: *const FRect) bool { + return c.SDL_RenderRect(renderer, @ptrCast(rect)); + } + + pub inline fn renderRects(renderer: *Renderer, rects: *const FRect, count: c_int) bool { + return c.SDL_RenderRects(renderer, @ptrCast(rects), count); + } + + pub inline fn renderFillRect(renderer: *Renderer, rect: *const FRect) bool { + return c.SDL_RenderFillRect(renderer, @ptrCast(rect)); + } + + pub inline fn renderFillRects(renderer: *Renderer, rects: *const FRect, count: c_int) bool { + return c.SDL_RenderFillRects(renderer, @ptrCast(rects), count); + } + + pub inline fn renderTexture(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, dstrect: *const FRect,) bool { + return c.SDL_RenderTexture(renderer, texture, @ptrCast(srcrect), @ptrCast(dstrect)); + } + + pub inline fn renderTextureRotated(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, dstrect: *const FRect, angle: f64, center: *const FPoint, flip: FlipMode,) bool { + return c.SDL_RenderTextureRotated(renderer, texture, @ptrCast(srcrect), @ptrCast(dstrect), angle, @ptrCast(center), @intFromEnum(flip)); + } + + pub inline fn renderTextureAffine(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, origin: *const FPoint, right: *const FPoint, down: *const FPoint,) bool { + return c.SDL_RenderTextureAffine(renderer, texture, @ptrCast(srcrect), @ptrCast(origin), @ptrCast(right), @ptrCast(down)); + } + + pub inline fn renderTextureTiled(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, scale: f32, dstrect: *const FRect,) bool { + return c.SDL_RenderTextureTiled(renderer, texture, @ptrCast(srcrect), scale, @ptrCast(dstrect)); + } + + pub inline fn renderTexture9Grid(renderer: *Renderer, texture: ?*Texture, srcrect: *const FRect, left_width: f32, right_width: f32, top_height: f32, bottom_height: f32, scale: f32, dstrect: *const FRect,) bool { + return c.SDL_RenderTexture9Grid(renderer, texture, @ptrCast(srcrect), left_width, right_width, top_height, bottom_height, scale, @ptrCast(dstrect)); + } + + pub inline fn renderGeometry(renderer: *Renderer, texture: ?*Texture, vertices: *const Vertex, num_vertices: c_int, indices: const int *, num_indices: c_int,) bool { + return c.SDL_RenderGeometry(renderer, texture, @ptrCast(vertices), num_vertices, indices, num_indices); + } + + pub inline fn renderGeometryRaw(renderer: *Renderer, texture: ?*Texture, xy: const float *, xy_stride: c_int, color: *const FColor, color_stride: c_int, uv: const float *, uv_stride: c_int, num_vertices: c_int, indices: ?*const anyopaque, num_indices: c_int, size_indices: c_int,) bool { + return c.SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, @ptrCast(color), color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices); + } + + pub inline fn renderReadPixels(renderer: *Renderer, rect: *const Rect) ?*Surface { + return c.SDL_RenderReadPixels(renderer, @ptrCast(rect)); + } + + pub inline fn renderPresent(renderer: *Renderer) bool { + return c.SDL_RenderPresent(renderer); + } + + pub inline fn destroyRenderer(renderer: *Renderer) void { + return c.SDL_DestroyRenderer(renderer); + } + + pub inline fn flushRenderer(renderer: *Renderer) bool { + return c.SDL_FlushRenderer(renderer); + } + + pub inline fn getRenderMetalLayer(renderer: *Renderer) ?*anyopaque { + return c.SDL_GetRenderMetalLayer(renderer); + } + + pub inline fn getRenderMetalCommandEncoder(renderer: *Renderer) ?*anyopaque { + return c.SDL_GetRenderMetalCommandEncoder(renderer); + } + + pub inline fn addVulkanRenderSemaphores(renderer: *Renderer, wait_stage_mask: u32, wait_semaphore: i64, signal_semaphore: i64,) bool { + return c.SDL_AddVulkanRenderSemaphores(renderer, wait_stage_mask, wait_semaphore, signal_semaphore); + } + + pub inline fn setRenderVSync(renderer: *Renderer, vsync: c_int) bool { + return c.SDL_SetRenderVSync(renderer, vsync); + } + + pub inline fn getRenderVSync(renderer: *Renderer, vsync: *c_int) bool { + return c.SDL_GetRenderVSync(renderer, @ptrCast(vsync)); + } + + pub inline fn renderDebugText(renderer: *Renderer, x: f32, y: f32, str: [*c]const u8,) bool { + return c.SDL_RenderDebugText(renderer, x, y, str); + } + + pub inline fn renderDebugTextFormat(renderer: *Renderer, x: f32, y: f32, fmt: [*c]const u8, ...,) bool { + return c.SDL_RenderDebugTextFormat(renderer, x, y, fmt, ); + } + +}; + +pub const Texture = opaque { + pub inline fn getTextureProperties(texture: *Texture) PropertiesID { + return c.SDL_GetTextureProperties(texture); + } + + pub inline fn getRendererFromTexture(texture: *Texture) ?*Renderer { + return c.SDL_GetRendererFromTexture(texture); + } + + pub inline fn getTextureSize(texture: *Texture, w: *f32, h: *f32) bool { + return c.SDL_GetTextureSize(texture, @ptrCast(w), @ptrCast(h)); + } + + pub inline fn setTextureColorMod(texture: *Texture, r: u8, g: u8, b: u8,) bool { + return c.SDL_SetTextureColorMod(texture, r, g, b); + } + + pub inline fn setTextureColorModFloat(texture: *Texture, r: f32, g: f32, b: f32,) bool { + return c.SDL_SetTextureColorModFloat(texture, r, g, b); + } + + pub inline fn getTextureColorMod(texture: *Texture, r: [*c]u8, g: [*c]u8, b: [*c]u8,) bool { + return c.SDL_GetTextureColorMod(texture, r, g, b); + } + + pub inline fn getTextureColorModFloat(texture: *Texture, r: *f32, g: *f32, b: *f32,) bool { + return c.SDL_GetTextureColorModFloat(texture, @ptrCast(r), @ptrCast(g), @ptrCast(b)); + } + + pub inline fn setTextureAlphaMod(texture: *Texture, alpha: u8) bool { + return c.SDL_SetTextureAlphaMod(texture, alpha); + } + + pub inline fn setTextureAlphaModFloat(texture: *Texture, alpha: f32) bool { + return c.SDL_SetTextureAlphaModFloat(texture, alpha); + } + + pub inline fn getTextureAlphaMod(texture: *Texture, alpha: [*c]u8) bool { + return c.SDL_GetTextureAlphaMod(texture, alpha); + } + + pub inline fn getTextureAlphaModFloat(texture: *Texture, alpha: *f32) bool { + return c.SDL_GetTextureAlphaModFloat(texture, @ptrCast(alpha)); + } + + pub inline fn setTextureBlendMode(texture: *Texture, blendMode: BlendMode) bool { + return c.SDL_SetTextureBlendMode(texture, @intFromEnum(blendMode)); + } + + pub inline fn getTextureBlendMode(texture: *Texture, blendMode: ?*BlendMode) bool { + return c.SDL_GetTextureBlendMode(texture, @intFromEnum(blendMode)); + } + + pub inline fn setTextureScaleMode(texture: *Texture, scaleMode: ScaleMode) bool { + return c.SDL_SetTextureScaleMode(texture, @intFromEnum(scaleMode)); + } + + pub inline fn getTextureScaleMode(texture: *Texture, scaleMode: ?*ScaleMode) bool { + return c.SDL_GetTextureScaleMode(texture, @intFromEnum(scaleMode)); + } + + pub inline fn updateTexture(texture: *Texture, rect: *const Rect, pixels: ?*const anyopaque, pitch: c_int,) bool { + return c.SDL_UpdateTexture(texture, @ptrCast(rect), pixels, pitch); + } + + pub inline fn updateYUVTexture(texture: *Texture, rect: *const Rect, Yplane: [*c]const u8, Ypitch: c_int, Uplane: [*c]const u8, Upitch: c_int, Vplane: [*c]const u8, Vpitch: c_int,) bool { + return c.SDL_UpdateYUVTexture(texture, @ptrCast(rect), Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); + } + + pub inline fn updateNVTexture(texture: *Texture, rect: *const Rect, Yplane: [*c]const u8, Ypitch: c_int, UVplane: [*c]const u8, UVpitch: c_int,) bool { + return c.SDL_UpdateNVTexture(texture, @ptrCast(rect), Yplane, Ypitch, UVplane, UVpitch); + } + + pub inline fn lockTexture(texture: *Texture, rect: *const Rect, pixels: [*c]?*anyopaque, pitch: *c_int,) bool { + return c.SDL_LockTexture(texture, @ptrCast(rect), pixels, @ptrCast(pitch)); + } + + pub inline fn lockTextureToSurface(texture: *Texture, rect: *const Rect, surface: ?*?*Surface) bool { + return c.SDL_LockTextureToSurface(texture, @ptrCast(rect), surface); + } + + pub inline fn unlockTexture(texture: *Texture) void { + return c.SDL_UnlockTexture(texture); + } + + pub inline fn destroyTexture(texture: *Texture) void { + return c.SDL_DestroyTexture(texture); + } + +}; + +pub inline fn getNumRenderDrivers() c_int { + return c.SDL_GetNumRenderDrivers(); +} + +pub inline fn getRenderDriver(index: c_int) [*c]const u8 { + return c.SDL_GetRenderDriver(index); +} + +pub inline fn createWindowAndRenderer(title: [*c]const u8, width: c_int, height: c_int, window_flags: WindowFlags, window: ?*?*Window, renderer: ?*?*Renderer,) bool { + return c.SDL_CreateWindowAndRenderer(title, width, height, @bitCast(window_flags), window, renderer); +} + +pub inline fn createRendererWithProperties(props: PropertiesID) ?*Renderer { + return c.SDL_CreateRendererWithProperties(props); +} + diff --git a/lib/sdl3/v2/sensor.zig b/lib/sdl3/v2/sensor.zig new file mode 100644 index 0000000..0bc5018 --- /dev/null +++ b/lib/sdl3/v2/sensor.zig @@ -0,0 +1,64 @@ +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 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/lib/sdl3/v2/storage.zig b/lib/sdl3/v2/storage.zig new file mode 100644 index 0000000..f6a27c7 --- /dev/null +++ b/lib/sdl3/v2/storage.zig @@ -0,0 +1,124 @@ +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 GlobFlags = packed struct(u32) { + globCaseinsensitive: bool = false, + pad0: u30 = 0, + rsvd: bool = false, +}; + +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/lib/sdl3/v2/system.zig b/lib/sdl3/v2/system.zig new file mode 100644 index 0000000..571694c --- /dev/null +++ b/lib/sdl3/v2/system.zig @@ -0,0 +1,47 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const tagMSG = extern struct { + 0: SANDBOX_NONE =, +}; + +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 inline fn getGDKTaskQueue(outTaskQueue: XTaskQueueHandle *) bool { + return c.SDL_GetGDKTaskQueue(outTaskQueue); +} + +pub inline fn getGDKDefaultUser(outUserHandle: XUserHandle *) bool { + return c.SDL_GetGDKDefaultUser(outUserHandle); +} + diff --git a/lib/sdl3/v2/thread.zig b/lib/sdl3/v2/thread.zig new file mode 100644 index 0000000..2f0a9ca --- /dev/null +++ b/lib/sdl3/v2/thread.zig @@ -0,0 +1,79 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const PropertiesID = u32; + +pub const Thread = opaque { + pub inline fn getThreadName(thread: *Thread) [*c]const u8 { + return c.SDL_GetThreadName(thread); + } + + pub inline fn getThreadID(thread: *Thread) ThreadID { + return c.SDL_GetThreadID(thread); + } + + pub inline fn waitThread(thread: *Thread, status: *c_int) void { + return c.SDL_WaitThread(thread, @ptrCast(status)); + } + + pub inline fn getThreadState(thread: *Thread) ThreadState { + return c.SDL_GetThreadState(thread); + } + + pub inline fn detachThread(thread: *Thread) void { + return c.SDL_DetachThread(thread); + } + +}; + +pub const ThreadID = u64; + +pub const TLSID = AtomicInt; + +pub const ThreadPriority = enum(c_int) { + threadPriorityLow, + threadPriorityNormal, + threadPriorityHigh, + threadPriorityTimeCritical, +}; + +pub const ThreadFunction = *const fn(data: ?*anyopaque) callconv(.C) c_int; + +pub inline fn createThread(fn: ThreadFunction, name: [*c]const u8, data: ?*anyopaque) ?*Thread { + return c.SDL_CreateThread(fn, name, data); +} + +pub inline fn createThreadWithProperties(props: PropertiesID) ?*Thread { + return c.SDL_CreateThreadWithProperties(props); +} + +pub inline fn createThreadRuntime(fn: ThreadFunction, name: [*c]const u8, data: ?*anyopaque, pfnBeginThread: FunctionPointer, pfnEndThread: FunctionPointer,) ?*Thread { + return c.SDL_CreateThreadRuntime(fn, name, data, pfnBeginThread, pfnEndThread); +} + +pub inline fn createThreadWithPropertiesRuntime(props: PropertiesID, pfnBeginThread: FunctionPointer, pfnEndThread: FunctionPointer) ?*Thread { + return c.SDL_CreateThreadWithPropertiesRuntime(props, pfnBeginThread, pfnEndThread); +} + +pub inline fn getCurrentThreadID() ThreadID { + return c.SDL_GetCurrentThreadID(); +} + +pub inline fn setCurrentThreadPriority(priority: ThreadPriority) bool { + return c.SDL_SetCurrentThreadPriority(priority); +} + +pub inline fn getTLS(id: ?*TLSID) ?*anyopaque { + return c.SDL_GetTLS(id); +} + +pub const TLSDestructorCallback = *const fn(value: ?*anyopaque) callconv(.C) void; + +pub inline fn setTLS(id: ?*TLSID, value: ?*const anyopaque, destructor: TLSDestructorCallback) bool { + return c.SDL_SetTLS(id, value, destructor); +} + +pub inline fn cleanupTLS() void { + return c.SDL_CleanupTLS(); +} + diff --git a/lib/sdl3/v2/time.zig b/lib/sdl3/v2/time.zig new file mode 100644 index 0000000..51051d0 --- /dev/null +++ b/lib/sdl3/v2/time.zig @@ -0,0 +1,52 @@ +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 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/lib/sdl3/v2/touch.zig b/lib/sdl3/v2/touch.zig new file mode 100644 index 0000000..2343cd1 --- /dev/null +++ b/lib/sdl3/v2/touch.zig @@ -0,0 +1,33 @@ +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) { + touchDeviceInvalid, +}; + +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) ?*?*Finger { + return c.SDL_GetTouchFingers(touchID, @ptrCast(count)); +} diff --git a/lib/sdl3/v2/tray.zig b/lib/sdl3/v2/tray.zig new file mode 100644 index 0000000..2917a0d --- /dev/null +++ b/lib/sdl3/v2/tray.zig @@ -0,0 +1,119 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Surface = opaque { + pub inline fn createTray(surface: *Surface, tooltip: [*c]const u8) ?*Tray { + return c.SDL_CreateTray(surface, tooltip); + } + +}; + +pub const Tray = opaque { + pub inline fn setTrayIcon(tray: *Tray, icon: ?*Surface) void { + return c.SDL_SetTrayIcon(tray, icon); + } + + pub inline fn setTrayTooltip(tray: *Tray, tooltip: [*c]const u8) void { + return c.SDL_SetTrayTooltip(tray, tooltip); + } + + pub inline fn createTrayMenu(tray: *Tray) ?*TrayMenu { + return c.SDL_CreateTrayMenu(tray); + } + + pub inline fn getTrayMenu(tray: *Tray) ?*TrayMenu { + return c.SDL_GetTrayMenu(tray); + } + + pub inline fn destroyTray(tray: *Tray) void { + return c.SDL_DestroyTray(tray); + } + +}; + +pub const TrayMenu = opaque { + pub inline fn getTrayEntries(traymenu: *TrayMenu, count: *c_int) *const TrayEntry * { + return @ptrCast(c.SDL_GetTrayEntries(traymenu, @ptrCast(count))); + } + + pub inline fn insertTrayEntryAt(traymenu: *TrayMenu, pos: c_int, label: [*c]const u8, flags: TrayEntryFlags,) ?*TrayEntry { + return c.SDL_InsertTrayEntryAt(traymenu, pos, label, @bitCast(flags)); + } + + pub inline fn getTrayMenuParentEntry(traymenu: *TrayMenu) ?*TrayEntry { + return c.SDL_GetTrayMenuParentEntry(traymenu); + } + + pub inline fn getTrayMenuParentTray(traymenu: *TrayMenu) ?*Tray { + return c.SDL_GetTrayMenuParentTray(traymenu); + } + +}; + +pub const TrayEntry = opaque { + pub inline fn createTraySubmenu(trayentry: *TrayEntry) ?*TrayMenu { + return c.SDL_CreateTraySubmenu(trayentry); + } + + pub inline fn getTraySubmenu(trayentry: *TrayEntry) ?*TrayMenu { + return c.SDL_GetTraySubmenu(trayentry); + } + + pub inline fn removeTrayEntry(trayentry: *TrayEntry) void { + return c.SDL_RemoveTrayEntry(trayentry); + } + + pub inline fn setTrayEntryLabel(trayentry: *TrayEntry, label: [*c]const u8) void { + return c.SDL_SetTrayEntryLabel(trayentry, label); + } + + pub inline fn getTrayEntryLabel(trayentry: *TrayEntry) [*c]const u8 { + return c.SDL_GetTrayEntryLabel(trayentry); + } + + pub inline fn setTrayEntryChecked(trayentry: *TrayEntry, checked: bool) void { + return c.SDL_SetTrayEntryChecked(trayentry, checked); + } + + pub inline fn getTrayEntryChecked(trayentry: *TrayEntry) bool { + return c.SDL_GetTrayEntryChecked(trayentry); + } + + pub inline fn setTrayEntryEnabled(trayentry: *TrayEntry, enabled: bool) void { + return c.SDL_SetTrayEntryEnabled(trayentry, enabled); + } + + pub inline fn getTrayEntryEnabled(trayentry: *TrayEntry) bool { + return c.SDL_GetTrayEntryEnabled(trayentry); + } + + pub inline fn setTrayEntryCallback(trayentry: *TrayEntry, callback: TrayCallback, userdata: ?*anyopaque) void { + return c.SDL_SetTrayEntryCallback(trayentry, callback, userdata); + } + + pub inline fn clickTrayEntry(trayentry: *TrayEntry) void { + return c.SDL_ClickTrayEntry(trayentry); + } + + pub inline fn getTrayEntryParent(trayentry: *TrayEntry) ?*TrayMenu { + return c.SDL_GetTrayEntryParent(trayentry); + } + +}; + +pub const TrayEntryFlags = packed struct(u32) { + trayentryButton: bool = false, // Make the entry a simple button. Required. + trayentryCheckbox: bool = false, // Make the entry a checkbox. Required. + trayentrySubmenu: bool = false, // Prepare the entry to have a submenu. Required + trayentryDisabled: bool = false, // Make the entry disabled. Optional. + trayentryChecked: bool = false, // Make the entry checked. This is valid only for checkboxes. Optional. + pad0: u26 = 0, + rsvd: bool = false, +}; + +pub const TrayCallback = *const fn(userdata: ?*anyopaque, entry: ?*TrayEntry) callconv(.C) void; + +pub inline fn updateTrays() void { + return c.SDL_UpdateTrays(); +} + diff --git a/lib/sdl3/v2/version.zig b/lib/sdl3/v2/version.zig new file mode 100644 index 0000000..8cef3e8 --- /dev/null +++ b/lib/sdl3/v2/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/lib/sdl3/v2/vulkan.zig b/lib/sdl3/v2/vulkan.zig new file mode 100644 index 0000000..8c27ac7 --- /dev/null +++ b/lib/sdl3/v2/vulkan.zig @@ -0,0 +1,34 @@ +const std = @import("std"); +pub const c = @import("c.zig").c; + +pub const Window = opaque { + pub inline fn vulkan_CreateSurface(window: *Window, instance: VkInstance, allocator: const struct VkAllocationCallbacks *, surface: VkSurfaceKHR *,) bool { + return c.SDL_Vulkan_CreateSurface(window, instance, allocator, surface); + } + +}; + +pub inline fn vulkan_LoadLibrary(path: [*c]const u8) bool { + return c.SDL_Vulkan_LoadLibrary(path); +} + +pub inline fn vulkan_GetVkGetInstanceProcAddr() FunctionPointer { + return c.SDL_Vulkan_GetVkGetInstanceProcAddr(); +} + +pub inline fn vulkan_UnloadLibrary() void { + return c.SDL_Vulkan_UnloadLibrary(); +} + +pub inline fn vulkan_GetInstanceExtensions(count: *u32) char const * const * { + return c.SDL_Vulkan_GetInstanceExtensions(@ptrCast(count)); +} + +pub inline fn vulkan_DestroySurface(instance: VkInstance, surface: VkSurfaceKHR, allocator: const struct VkAllocationCallbacks *) void { + return c.SDL_Vulkan_DestroySurface(instance, surface, allocator); +} + +pub inline fn vulkan_GetPresentationSupport(instance: VkInstance, physicalDevice: VkPhysicalDevice, queueFamilyIndex: u32) bool { + return c.SDL_Vulkan_GetPresentationSupport(instance, physicalDevice, queueFamilyIndex); +} +