const std = @import("std"); pub const c = @import("c.zig").c; pub const PixelFormat = enum(c_int) { pixelformatYv12, //Planar mode: Y + V + U (3 planes) pixelformatIyuv, //Planar mode: Y + U + V (3 planes) pixelformatYuy2, //Packed mode: Y0+U0+Y1+V0 (1 plane) pixelformatUyvy, //Packed mode: U0+Y0+V0+Y1 (1 plane) pixelformatYvyu, //Packed mode: Y0+V0+Y1+U0 (1 plane) pixelformatNv12, //Planar mode: Y + U/V interleaved (2 planes) pixelformatNv21, //Planar mode: Y + V/U interleaved (2 planes) pixelformatP010, //Planar mode: Y + U/V interleaved (2 planes) pixelformatExternalOes, //Android video texture format pixelformatMjpg, //Motion JPEG }; pub const Point = extern struct { x: c_int, y: c_int, }; pub const Surface = opaque {}; pub const PropertiesID = u32; pub const Rect = extern struct { x: c_int, y: c_int, w: c_int, h: c_int, }; pub const FunctionPointer = c.SDL_FunctionPointer; pub const DisplayID = u32; pub const WindowID = u32; pub const SystemTheme = enum(c_int) { systemThemeUnknown, //Unknown system theme systemThemeLight, //Light colored system theme systemThemeDark, //Dark colored system theme }; pub const DisplayModeData = opaque {}; pub const DisplayMode = extern struct { displayID: DisplayID, // the display this mode is associated with format: PixelFormat, // pixel format w: c_int, // width h: c_int, // height pixel_density: f32, // scale converting size to pixels (e.g. a 1920x1080 mode with 2.0 scale would have 3840x2160 pixels) refresh_rate: f32, // refresh rate (or 0.0f for unspecified) refresh_rate_numerator: c_int, // precise refresh rate numerator (or 0 for unspecified) refresh_rate_denominator: c_int, // precise refresh rate denominator internal: ?*DisplayModeData, // Private }; pub const DisplayOrientation = enum(c_int) { orientationUnknown, //The display orientation can't be determined orientationLandscape, //The display is in landscape mode, with the right side up, relative to portrait mode orientationLandscapeFlipped, //The display is in landscape mode, with the left side up, relative to portrait mode orientationPortrait, //The display is in portrait mode orientationPortraitFlipped, }; pub const Window = opaque { pub inline fn getDisplayForWindow(window: *Window) DisplayID { return c.SDL_GetDisplayForWindow(window); } pub inline fn getWindowPixelDensity(window: *Window) f32 { return c.SDL_GetWindowPixelDensity(window); } pub inline fn getWindowDisplayScale(window: *Window) f32 { return c.SDL_GetWindowDisplayScale(window); } pub inline fn setWindowFullscreenMode(window: *Window, mode: *const DisplayMode) bool { return c.SDL_SetWindowFullscreenMode(window, @ptrCast(mode)); } pub inline fn getWindowFullscreenMode(window: *Window) *const DisplayMode { return @ptrCast(c.SDL_GetWindowFullscreenMode(window)); } pub inline fn getWindowICCProfile(window: *Window, size: *usize) ?*anyopaque { return c.SDL_GetWindowICCProfile(window, @ptrCast(size)); } pub inline fn getWindowPixelFormat(window: *Window) PixelFormat { return @bitCast(c.SDL_GetWindowPixelFormat(window)); } pub inline fn createPopupWindow(window: *Window, offset_x: c_int, offset_y: c_int, w: c_int, h: c_int, flags: WindowFlags) ?*Window { return c.SDL_CreatePopupWindow(window, offset_x, offset_y, w, h, @bitCast(flags)); } pub inline fn getWindowID(window: *Window) WindowID { return c.SDL_GetWindowID(window); } pub inline fn getWindowParent(window: *Window) ?*Window { return c.SDL_GetWindowParent(window); } pub inline fn getWindowProperties(window: *Window) PropertiesID { return c.SDL_GetWindowProperties(window); } pub inline fn getWindowFlags(window: *Window) WindowFlags { return @bitCast(c.SDL_GetWindowFlags(window)); } pub inline fn setWindowTitle(window: *Window, title: [*c]const u8) bool { return c.SDL_SetWindowTitle(window, title); } pub inline fn getWindowTitle(window: *Window) [*c]const u8 { return c.SDL_GetWindowTitle(window); } pub inline fn setWindowIcon(window: *Window, icon: ?*Surface) bool { return c.SDL_SetWindowIcon(window, icon); } pub inline fn setWindowPosition(window: *Window, x: c_int, y: c_int) bool { return c.SDL_SetWindowPosition(window, x, y); } pub inline fn getWindowPosition(window: *Window, x: *c_int, y: *c_int) bool { return c.SDL_GetWindowPosition(window, @ptrCast(x), @ptrCast(y)); } pub inline fn setWindowSize(window: *Window, w: c_int, h: c_int) bool { return c.SDL_SetWindowSize(window, w, h); } pub inline fn getWindowSize(window: *Window, w: *c_int, h: *c_int) bool { return c.SDL_GetWindowSize(window, @ptrCast(w), @ptrCast(h)); } pub inline fn getWindowSafeArea(window: *Window, rect: ?*Rect) bool { return c.SDL_GetWindowSafeArea(window, rect); } pub inline fn setWindowAspectRatio(window: *Window, min_aspect: f32, max_aspect: f32) bool { return c.SDL_SetWindowAspectRatio(window, min_aspect, max_aspect); } pub inline fn getWindowAspectRatio(window: *Window, min_aspect: *f32, max_aspect: *f32) bool { return c.SDL_GetWindowAspectRatio(window, @ptrCast(min_aspect), @ptrCast(max_aspect)); } pub inline fn getWindowBordersSize(window: *Window, top: *c_int, left: *c_int, bottom: *c_int, right: *c_int) bool { return c.SDL_GetWindowBordersSize(window, @ptrCast(top), @ptrCast(left), @ptrCast(bottom), @ptrCast(right)); } pub inline fn getWindowSizeInPixels(window: *Window, w: *c_int, h: *c_int) bool { return c.SDL_GetWindowSizeInPixels(window, @ptrCast(w), @ptrCast(h)); } pub inline fn setWindowMinimumSize(window: *Window, min_w: c_int, min_h: c_int) bool { return c.SDL_SetWindowMinimumSize(window, min_w, min_h); } pub inline fn getWindowMinimumSize(window: *Window, w: *c_int, h: *c_int) bool { return c.SDL_GetWindowMinimumSize(window, @ptrCast(w), @ptrCast(h)); } pub inline fn setWindowMaximumSize(window: *Window, max_w: c_int, max_h: c_int) bool { return c.SDL_SetWindowMaximumSize(window, max_w, max_h); } pub inline fn getWindowMaximumSize(window: *Window, w: *c_int, h: *c_int) bool { return c.SDL_GetWindowMaximumSize(window, @ptrCast(w), @ptrCast(h)); } pub inline fn setWindowBordered(window: *Window, bordered: bool) bool { return c.SDL_SetWindowBordered(window, bordered); } pub inline fn setWindowResizable(window: *Window, resizable: bool) bool { return c.SDL_SetWindowResizable(window, resizable); } pub inline fn setWindowAlwaysOnTop(window: *Window, on_top: bool) bool { return c.SDL_SetWindowAlwaysOnTop(window, on_top); } pub inline fn showWindow(window: *Window) bool { return c.SDL_ShowWindow(window); } pub inline fn hideWindow(window: *Window) bool { return c.SDL_HideWindow(window); } pub inline fn raiseWindow(window: *Window) bool { return c.SDL_RaiseWindow(window); } pub inline fn maximizeWindow(window: *Window) bool { return c.SDL_MaximizeWindow(window); } pub inline fn minimizeWindow(window: *Window) bool { return c.SDL_MinimizeWindow(window); } pub inline fn restoreWindow(window: *Window) bool { return c.SDL_RestoreWindow(window); } pub inline fn setWindowFullscreen(window: *Window, fullscreen: bool) bool { return c.SDL_SetWindowFullscreen(window, fullscreen); } pub inline fn syncWindow(window: *Window) bool { return c.SDL_SyncWindow(window); } pub inline fn windowHasSurface(window: *Window) bool { return c.SDL_WindowHasSurface(window); } pub inline fn getWindowSurface(window: *Window) ?*Surface { return c.SDL_GetWindowSurface(window); } pub inline fn setWindowSurfaceVSync(window: *Window, vsync: c_int) bool { return c.SDL_SetWindowSurfaceVSync(window, vsync); } pub inline fn getWindowSurfaceVSync(window: *Window, vsync: *c_int) bool { return c.SDL_GetWindowSurfaceVSync(window, @ptrCast(vsync)); } pub inline fn updateWindowSurface(window: *Window) bool { return c.SDL_UpdateWindowSurface(window); } pub inline fn updateWindowSurfaceRects(window: *Window, rects: *const Rect, numrects: c_int) bool { return c.SDL_UpdateWindowSurfaceRects(window, @ptrCast(rects), numrects); } pub inline fn destroyWindowSurface(window: *Window) bool { return c.SDL_DestroyWindowSurface(window); } pub inline fn setWindowKeyboardGrab(window: *Window, grabbed: bool) bool { return c.SDL_SetWindowKeyboardGrab(window, grabbed); } pub inline fn setWindowMouseGrab(window: *Window, grabbed: bool) bool { return c.SDL_SetWindowMouseGrab(window, grabbed); } pub inline fn getWindowKeyboardGrab(window: *Window) bool { return c.SDL_GetWindowKeyboardGrab(window); } pub inline fn getWindowMouseGrab(window: *Window) bool { return c.SDL_GetWindowMouseGrab(window); } pub inline fn setWindowMouseRect(window: *Window, rect: *const Rect) bool { return c.SDL_SetWindowMouseRect(window, @ptrCast(rect)); } pub inline fn getWindowMouseRect(window: *Window) *const Rect { return @ptrCast(c.SDL_GetWindowMouseRect(window)); } pub inline fn setWindowOpacity(window: *Window, opacity: f32) bool { return c.SDL_SetWindowOpacity(window, opacity); } pub inline fn getWindowOpacity(window: *Window) f32 { return c.SDL_GetWindowOpacity(window); } pub inline fn setWindowParent(window: *Window, parent: ?*Window) bool { return c.SDL_SetWindowParent(window, parent); } pub inline fn setWindowModal(window: *Window, modal: bool) bool { return c.SDL_SetWindowModal(window, modal); } pub inline fn setWindowFocusable(window: *Window, focusable: bool) bool { return c.SDL_SetWindowFocusable(window, focusable); } pub inline fn showWindowSystemMenu(window: *Window, x: c_int, y: c_int) bool { return c.SDL_ShowWindowSystemMenu(window, x, y); } pub inline fn setWindowHitTest(window: *Window, callback: HitTest, callback_data: ?*anyopaque) bool { return c.SDL_SetWindowHitTest(window, callback, callback_data); } pub inline fn setWindowShape(window: *Window, shape: ?*Surface) bool { return c.SDL_SetWindowShape(window, shape); } pub inline fn flashWindow(window: *Window, operation: FlashOperation) bool { return c.SDL_FlashWindow(window, @intFromEnum(operation)); } pub inline fn destroyWindow(window: *Window) void { return c.SDL_DestroyWindow(window); } pub inline fn gl_CreateContext(window: *Window) GLContext { return c.SDL_GL_CreateContext(window); } pub inline fn gl_MakeCurrent(window: *Window, context: GLContext) bool { return c.SDL_GL_MakeCurrent(window, context); } pub inline fn egl_GetWindowSurface(window: *Window) EGLSurface { return c.SDL_EGL_GetWindowSurface(window); } pub inline fn gl_SwapWindow(window: *Window) bool { return c.SDL_GL_SwapWindow(window); } }; pub const WindowFlags = packed struct(u64) { windowFullscreen: bool = false, // window is in fullscreen mode windowOpengl: bool = false, // window usable with OpenGL context windowOccluded: bool = false, // window is occluded windowHidden: bool = false, // window is neither mapped onto the desktop nor shown in the taskbar/dock/window list; SDL_ShowWindow() is required for it to become visible windowBorderless: bool = false, // no window decoration windowResizable: bool = false, // window can be resized windowMinimized: bool = false, // window is minimized windowMaximized: bool = false, // window is maximized windowMouseGrabbed: bool = false, // window has grabbed mouse input windowInputFocus: bool = false, // window has input focus windowMouseFocus: bool = false, // window has mouse focus windowExternal: bool = false, // window not created by SDL windowModal: bool = false, // window is modal windowHighPixelDensity: bool = false, // window uses high pixel density back buffer if possible windowMouseCapture: bool = false, // window has mouse captured (unrelated to MOUSE_GRABBED) windowMouseRelativeMode: bool = false, // window has relative mode enabled windowAlwaysOnTop: bool = false, // window should always be above others windowUtility: bool = false, // window should be treated as a utility window, not showing in the task bar and window list windowTooltip: bool = false, // window should be treated as a tooltip and does not get mouse or keyboard focus, requires a parent window windowPopupMenu: bool = false, // window should be treated as a popup menu, requires a parent window windowKeyboardGrabbed: bool = false, // window has grabbed keyboard input 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 FlashOperation = enum(c_int) { flashCancel, //Cancel any window flash state flashBriefly, //Flash the window briefly to get attention flashUntilFocused, //Flash the window until it gets focus }; pub const GLContext = *anyopaque; pub const EGLDisplay = ?*anyopaque; pub const EGLConfig = ?*anyopaque; pub const EGLSurface = ?*anyopaque; pub const EGLAttrib = isize; pub const EGLint = c_int; pub const EGLAttribArrayCallback = c.SDL_EGLAttribArrayCallback; pub const EGLIntArrayCallback = c.SDL_EGLIntArrayCallback; pub const GLAttr = enum(c_int) { glRedSize, //the minimum number of bits for the red channel of the color buffer; defaults to 8. glGreenSize, //the minimum number of bits for the green channel of the color buffer; defaults to 8. glBlueSize, //the minimum number of bits for the blue channel of the color buffer; defaults to 8. glAlphaSize, //the minimum number of bits for the alpha channel of the color buffer; defaults to 8. glBufferSize, //the minimum number of bits for frame buffer size; defaults to 0. glDoublebuffer, //whether the output is single or double buffered; defaults to double buffering on. glDepthSize, //the minimum number of bits in the depth buffer; defaults to 16. glStencilSize, //the minimum number of bits in the stencil buffer; defaults to 0. glAccumRedSize, //the minimum number of bits for the red channel of the accumulation buffer; defaults to 0. glAccumGreenSize, //the minimum number of bits for the green channel of the accumulation buffer; defaults to 0. glAccumBlueSize, //the minimum number of bits for the blue channel of the accumulation buffer; defaults to 0. glAccumAlphaSize, //the minimum number of bits for the alpha channel of the accumulation buffer; defaults to 0. glStereo, //whether the output is stereo 3D; defaults to off. glMultisamplebuffers, //the number of buffers used for multisample anti-aliasing; defaults to 0. glMultisamplesamples, //the number of samples used around the current pixel used for multisample anti-aliasing. glAcceleratedVisual, //set to 1 to require hardware acceleration, set to 0 to force software rendering; defaults to allow either. glRetainedBacking, //not used (deprecated). glContextMajorVersion, //OpenGL context major version. glContextMinorVersion, //OpenGL context minor version. glContextFlags, //some combination of 0 or more of elements of the SDL_GLContextFlag enumeration; defaults to 0. glContextProfileMask, //type of GL context (Core, Compatibility, ES). See SDL_GLProfile; default value depends on platform. glShareWithCurrentContext, //OpenGL context sharing; defaults to 0. glFramebufferSrgbCapable, //requests sRGB capable visual; defaults to 0. glContextReleaseBehavior, //sets context the release behavior. See SDL_GLContextReleaseFlag; defaults to FLUSH. glContextResetNotification, //set context reset notification. See SDL_GLContextResetNotification; defaults to NO_NOTIFICATION. glContextNoError, glFloatbuffers, glEglPlatform, }; pub const GLProfile = u32; pub const GLContextFlag = u32; pub const GLContextReleaseFlag = u32; pub const GLContextResetNotification = u32; pub inline fn getNumVideoDrivers() c_int { return c.SDL_GetNumVideoDrivers(); } pub inline fn getVideoDriver(index: c_int) [*c]const u8 { return c.SDL_GetVideoDriver(index); } pub inline fn getCurrentVideoDriver() [*c]const u8 { return c.SDL_GetCurrentVideoDriver(); } pub inline fn getSystemTheme() SystemTheme { return c.SDL_GetSystemTheme(); } pub inline fn getDisplays(count: *c_int) ?*DisplayID { return c.SDL_GetDisplays(@ptrCast(count)); } pub inline fn getPrimaryDisplay() DisplayID { return c.SDL_GetPrimaryDisplay(); } pub inline fn getDisplayProperties(displayID: DisplayID) PropertiesID { return c.SDL_GetDisplayProperties(displayID); } pub inline fn getDisplayName(displayID: DisplayID) [*c]const u8 { return c.SDL_GetDisplayName(displayID); } pub inline fn getDisplayBounds(displayID: DisplayID, rect: ?*Rect) bool { return c.SDL_GetDisplayBounds(displayID, rect); } pub inline fn getDisplayUsableBounds(displayID: DisplayID, rect: ?*Rect) bool { return c.SDL_GetDisplayUsableBounds(displayID, rect); } pub inline fn getNaturalDisplayOrientation(displayID: DisplayID) DisplayOrientation { return c.SDL_GetNaturalDisplayOrientation(displayID); } pub inline fn getCurrentDisplayOrientation(displayID: DisplayID) DisplayOrientation { return c.SDL_GetCurrentDisplayOrientation(displayID); } pub inline fn getDisplayContentScale(displayID: DisplayID) f32 { return c.SDL_GetDisplayContentScale(displayID); } pub inline fn getFullscreenDisplayModes(displayID: DisplayID, count: *c_int) [*c][*c]DisplayMode { return @intFromEnum(c.SDL_GetFullscreenDisplayModes(displayID, @ptrCast(count))); } pub inline fn getClosestFullscreenDisplayMode(displayID: DisplayID, w: c_int, h: c_int, refresh_rate: f32, include_high_density_modes: bool, closest: ?*DisplayMode) bool { return c.SDL_GetClosestFullscreenDisplayMode(displayID, w, h, refresh_rate, include_high_density_modes, @intFromEnum(closest)); } pub inline fn getDesktopDisplayMode(displayID: DisplayID) *const DisplayMode { return @ptrCast(c.SDL_GetDesktopDisplayMode(displayID)); } pub inline fn getCurrentDisplayMode(displayID: DisplayID) *const DisplayMode { return @ptrCast(c.SDL_GetCurrentDisplayMode(displayID)); } pub inline fn getDisplayForPoint(point: *const Point) DisplayID { return c.SDL_GetDisplayForPoint(@ptrCast(point)); } pub inline fn getDisplayForRect(rect: *const Rect) DisplayID { return c.SDL_GetDisplayForRect(@ptrCast(rect)); } pub inline fn getWindows(count: *c_int) [*c][*c]Window { return c.SDL_GetWindows(@ptrCast(count)); } pub inline fn createWindow(title: [*c]const u8, w: c_int, h: c_int, flags: WindowFlags) ?*Window { return c.SDL_CreateWindow(title, w, h, @bitCast(flags)); } pub inline fn createWindowWithProperties(props: PropertiesID) ?*Window { return c.SDL_CreateWindowWithProperties(props); } pub inline fn getWindowFromID(id: WindowID) ?*Window { return c.SDL_GetWindowFromID(id); } pub inline fn getGrabbedWindow() ?*Window { return c.SDL_GetGrabbedWindow(); } pub const HitTestResult = enum(c_int) { hittestNormal, //Region is normal. No special properties. hittestDraggable, //Region can drag entire window. hittestResizeTopleft, //Region is the resizable top-left corner border. hittestResizeTop, //Region is the resizable top border. hittestResizeTopright, //Region is the resizable top-right corner border. hittestResizeRight, //Region is the resizable right border. hittestResizeBottomright, //Region is the resizable bottom-right corner border. hittestResizeBottom, //Region is the resizable bottom border. hittestResizeBottomleft, //Region is the resizable bottom-left corner border. hittestResizeLeft, //Region is the resizable left border. }; pub const HitTest = c.SDL_HitTest; pub inline fn screenSaverEnabled() bool { return c.SDL_ScreenSaverEnabled(); } pub inline fn enableScreenSaver() bool { return c.SDL_EnableScreenSaver(); } pub inline fn disableScreenSaver() bool { return c.SDL_DisableScreenSaver(); } pub inline fn gl_LoadLibrary(path: [*c]const u8) bool { return c.SDL_GL_LoadLibrary(path); } pub inline fn gl_GetProcAddress(proc: [*c]const u8) FunctionPointer { return c.SDL_GL_GetProcAddress(proc); } pub inline fn egl_GetProcAddress(proc: [*c]const u8) FunctionPointer { return c.SDL_EGL_GetProcAddress(proc); } pub inline fn gl_UnloadLibrary() void { return c.SDL_GL_UnloadLibrary(); } pub inline fn gl_ExtensionSupported(extension: [*c]const u8) bool { return c.SDL_GL_ExtensionSupported(extension); } pub inline fn gl_ResetAttributes() void { return c.SDL_GL_ResetAttributes(); } pub inline fn gl_SetAttribute(attr: GLAttr, value: c_int) bool { return c.SDL_GL_SetAttribute(attr, value); } pub inline fn gl_GetAttribute(attr: GLAttr, value: *c_int) bool { return c.SDL_GL_GetAttribute(attr, @ptrCast(value)); } pub inline fn gl_GetCurrentWindow() ?*Window { return c.SDL_GL_GetCurrentWindow(); } pub inline fn gl_GetCurrentContext() GLContext { return c.SDL_GL_GetCurrentContext(); } pub inline fn egl_GetCurrentDisplay() EGLDisplay { return c.SDL_EGL_GetCurrentDisplay(); } pub inline fn egl_GetCurrentConfig() EGLConfig { return c.SDL_EGL_GetCurrentConfig(); } pub inline fn egl_SetAttributeCallbacks(platformAttribCallback: EGLAttribArrayCallback, surfaceAttribCallback: EGLIntArrayCallback, contextAttribCallback: EGLIntArrayCallback, userdata: ?*anyopaque) void { return c.SDL_EGL_SetAttributeCallbacks(platformAttribCallback, surfaceAttribCallback, contextAttribCallback, userdata); } pub inline fn gl_SetSwapInterval(interval: c_int) bool { return c.SDL_GL_SetSwapInterval(interval); } pub inline fn gl_GetSwapInterval(interval: *c_int) bool { return c.SDL_GL_GetSwapInterval(@ptrCast(interval)); } pub inline fn gl_DestroyContext(context: GLContext) bool { return c.SDL_GL_DestroyContext(context); }