114 lines
4.9 KiB
Zig
114 lines
4.9 KiB
Zig
const std = @import("std");
|
|
pub const c = @import("c.zig").c;
|
|
|
|
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 InitFlags = packed struct(u32) {
|
|
initAudio: bool = false, // `SDL_INIT_AUDIO` implies `SDL_INIT_EVENTS`
|
|
initVideo: bool = false, // `SDL_INIT_VIDEO` implies `SDL_INIT_EVENTS`, should be initialized on the main thread
|
|
initJoystick: bool = false, // `SDL_INIT_JOYSTICK` implies `SDL_INIT_EVENTS`, should be initialized on the same thread as SDL_INIT_VIDEO on Windows if you don't set SDL_HINT_JOYSTICK_THREAD
|
|
initHaptic: bool = false,
|
|
initGamepad: bool = false, // `SDL_INIT_GAMEPAD` implies `SDL_INIT_JOYSTICK`
|
|
initEvents: bool = false,
|
|
initSensor: bool = false, // `SDL_INIT_SENSOR` implies `SDL_INIT_EVENTS`
|
|
initCamera: bool = false, // `SDL_INIT_CAMERA` implies `SDL_INIT_EVENTS`
|
|
pad0: u23 = 0,
|
|
rsvd: bool = false,
|
|
};
|
|
|
|
pub const AppResult = enum(c_int) {
|
|
appContinue, //Value that requests that the app continue from the main callbacks.
|
|
appSuccess, //Value that requests termination with success from the main callbacks.
|
|
appFailure, //Value that requests termination with error from the main callbacks.
|
|
};
|
|
|
|
pub const AppInit_func = *const fn (appstate: [*c]?*anyopaque, argc: c_int, argv: [*c][*c]u8) callconv(.C) AppResult;
|
|
|
|
pub const AppIterate_func = *const fn (appstate: ?*anyopaque) callconv(.C) AppResult;
|
|
|
|
pub const AppEvent_func = *const fn (appstate: ?*anyopaque, event: ?*Event) callconv(.C) AppResult;
|
|
|
|
pub const AppQuit_func = *const fn (appstate: ?*anyopaque, result: AppResult) callconv(.C) void;
|
|
|
|
pub inline fn init(flags: InitFlags) bool {
|
|
return c.SDL_Init(@bitCast(flags));
|
|
}
|
|
|
|
pub inline fn initSubSystem(flags: InitFlags) bool {
|
|
return c.SDL_InitSubSystem(@bitCast(flags));
|
|
}
|
|
|
|
pub inline fn quitSubSystem(flags: InitFlags) void {
|
|
return c.SDL_QuitSubSystem(@bitCast(flags));
|
|
}
|
|
|
|
pub inline fn wasInit(flags: InitFlags) InitFlags {
|
|
return @bitCast(c.SDL_WasInit(@bitCast(flags)));
|
|
}
|
|
|
|
pub inline fn quit() void {
|
|
return c.SDL_Quit();
|
|
}
|
|
|
|
pub inline fn isMainThread() bool {
|
|
return c.SDL_IsMainThread();
|
|
}
|
|
|
|
pub const MainThreadCallback = *const fn (userdata: ?*anyopaque) callconv(.C) void;
|
|
|
|
pub inline fn runOnMainThread(callback: MainThreadCallback, userdata: ?*anyopaque, wait_complete: bool) bool {
|
|
return c.SDL_RunOnMainThread(callback, userdata, wait_complete);
|
|
}
|
|
|
|
pub inline fn setAppMetadata(appname: [*c]const u8, appversion: [*c]const u8, appidentifier: [*c]const u8) bool {
|
|
return c.SDL_SetAppMetadata(appname, appversion, appidentifier);
|
|
}
|
|
|
|
pub inline fn setAppMetadataProperty(name: [*c]const u8, value: [*c]const u8) bool {
|
|
return c.SDL_SetAppMetadataProperty(name, value);
|
|
}
|
|
|
|
pub inline fn getAppMetadataProperty(name: [*c]const u8) [*c]const u8 {
|
|
return c.SDL_GetAppMetadataProperty(name);
|
|
}
|