You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

184 lines
3.7 KiB

use crate::{
opaque_struct,
types::ffi::{Bool, Nts},
};
use std::os::raw;
pub(super) const WINDOW_POS_UNDEF: raw::c_int = 0x1FFF0000;
bitflags::bitflags! {
#[repr(transparent)]
pub(super) struct InitFlags: u32 {
const TIMER = 0x01;
const AUDIO = 0x10;
const VIDEO = 0x20;
const JOYSTICK = 0x200;
const HAPTIC = 0x1000;
const GAME_CONTROLLER = 0x2000;
const EVENTS = 0x4000;
const SENSOR = 0x8000;
}
#[repr(transparent)]
pub(super) struct WindowFlags: u32 {
const FULLSCREEN = 0x00000001;
const OPENGL = 0x00000002;
const SHOWN = 0x00000004;
const HIDDEN = 0x00000008;
const BORDERLESS = 0x00000010;
const RESIZABLE = 0x00000020;
const MINIMIZED = 0x00000040;
const MAXIMIZED = 0x00000080;
const INPUT_GRABBED = 0x00000100;
const INPUT_FOCUS = 0x00000200;
const MOUSE_FOCUS = 0x00000400;
const FOREIGN = 0x00000800;
const FULLSCREEN_DESKTOP = Self::FULLSCREEN.bits | 0x00001000;
const ALLOW_HIGH_DPI = 0x00002000;
const MOUSE_CAPTURE = 0x00004000;
const ALWAYS_ON_TOP = 0x00008000;
const SKIP_TASKBAR = 0x00010000;
const UTILITY = 0x00020000;
const TOOLTIP = 0x00040000;
const POPUP_MENU = 0x00080000;
const VULKAN = 0x10000000;
const METAL = 0x20000000;
}
}
#[repr(u32)]
#[derive(Clone, Copy)]
#[non_exhaustive]
#[allow(dead_code)]
pub(super) enum EventType {
Quit = 0x100,
AppTerminating,
AppLowMemory,
AppWillEnterBackground,
AppDidEnterBackground,
AppWillEnterForeground,
AppDidEnterForeground,
LocaleChanged,
DisplayEvent = 0x150,
WindowEvent = 0x200,
SysWmEvent,
KeyDown = 0x300,
KeyUp,
TextEditing,
TextInput,
KeyMapChanged,
MouseMotion = 0x400,
MouseButtonDown,
MouseButtonUp,
MouseWheel,
JoyAxisMotion = 0x600,
JoyBallMotion,
JoyHatMotion,
JoyButtonDown,
JoyButtonUp,
JoyDeviceAdded,
JoyDeviceRemoved,
ControllerAxisMotion = 0x650,
ControllerButtonDown,
ControllerButtonUp,
ControllerDeviceAdded,
ControllerDeviceRemoved,
ControllerDeviceRemapped,
ControllerTouchPadDown,
ControllerTouchPadMotion,
ControllerTouchPadUp,
ControllerSensorUpdate,
FingerDown = 0x700,
FingerUp,
FingerMotion,
DollarGesture = 0x800,
DollarRecord,
MultiGesture,
ClipboardUpdate = 0x900,
DropFile = 0x1000,
DropText,
DropBegin,
DropComplete,
AudioDeviceAdded = 0x1100,
AudioDeviceRemoved,
SensorUpdate = 0x1200,
RenderTargetsReset = 0x2000,
RenderDeviceReset,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub(super) struct CommonEvent {
pub(super) ty: EventType,
pub(super) time_stamp: u32,
}
#[repr(C)]
pub(super) union Event {
pub(super) ty: EventType,
pub(super) common: CommonEvent,
_forced_size: [u8; 56],
}
opaque_struct!(pub(super) Window);
#[link(name = "SDL2")]
extern "C" {
// initialization
#[link_name = "SDL_SetMainReady"]
pub(super) fn set_main_ready();
#[link_name = "SDL_Init"]
pub(super) fn init(flags: InitFlags) -> raw::c_int;
#[link_name = "SDL_Quit"]
pub(super) fn quit();
// errors
#[link_name = "SDL_GetError"]
pub(super) fn get_error() -> Nts;
// events
#[link_name = "SDL_PollEvent"]
pub(super) fn poll_event(event: *mut Event) -> raw::c_int;
// windows
#[link_name = "SDL_CreateWindow"]
pub(super) fn create_window(
title: Nts, x: raw::c_int, y: raw::c_int, w: raw::c_int, h: raw::c_int,
flags: WindowFlags,
) -> *mut Window;
#[link_name = "SDL_DestroyWindow"]
pub(super) fn destroy_window(window: *mut Window);
// vulkan
#[link_name = "SDL_Vulkan_GetInstanceExtensions"]
pub(super) fn vulkan_get_instance_extensions(
window: *mut Window, p_count: *mut raw::c_uint, p_names: *mut Nts,
) -> Bool;
#[link_name = "SDL_Vulkan_CreateSurface"]
pub(super) fn vulkan_create_surface(
window: *mut Window, instance: ash::vk::Instance,
surface: *mut ash::vk::SurfaceKHR,
) -> Bool;
}
// EOF