diff --git a/Cargo.toml b/Cargo.toml index 10068dba..103ffe2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,8 @@ keywords = ["SDL", "windowing", "graphics"] name = "sdl2" path = "src/sdl2/lib.rs" + +[dependencies.sdl2-sys] + +path = "sdl2-sys" +version = "*" diff --git a/sdl2-sys/Cargo.toml b/sdl2-sys/Cargo.toml new file mode 100644 index 00000000..918b806b --- /dev/null +++ b/sdl2-sys/Cargo.toml @@ -0,0 +1,13 @@ +[package] + +name = "sdl2-sys" +version = "0.0.0" +authors = ["Tony Aldridge "] +links = "SDL2" +build = "build.rs" + +[lib] +name = "sdl2-sys" + +[build-dependencies] +pkg-config = "*" diff --git a/sdl2-sys/build.rs b/sdl2-sys/build.rs new file mode 100644 index 00000000..14ee66ab --- /dev/null +++ b/sdl2-sys/build.rs @@ -0,0 +1,11 @@ +extern crate "pkg-config" as pkg_config; + +fn main() { + if build_pkgconfig() { return; } + panic!("Could not find SDL2 via pkgconfig"); +} + +fn build_pkgconfig() -> bool { + let opts = pkg_config::default_options("sdl2"); + pkg_config::find_library_opts("sdl2", &opts).is_ok() +} diff --git a/sdl2-sys/src/audio.rs b/sdl2-sys/src/audio.rs new file mode 100644 index 00000000..da62c601 --- /dev/null +++ b/sdl2-sys/src/audio.rs @@ -0,0 +1,106 @@ +use libc::{c_int, c_uint, c_void, uint8_t, uint32_t}; +use libc::{uint16_t, c_double, c_char}; +use super::rwops::SDL_RWops; + +// assume LSB +pub type SDL_AudioFormat = uint16_t; +pub const AUDIO_U8 : SDL_AudioFormat = 0x0008; +pub const AUDIO_S8 : SDL_AudioFormat = 0x8008; +pub const AUDIO_U16LSB : SDL_AudioFormat = 0x0010; +pub const AUDIO_S16LSB : SDL_AudioFormat = 0x8010; +pub const AUDIO_U16MSB : SDL_AudioFormat = 0x1010; +pub const AUDIO_S16MSB : SDL_AudioFormat = 0x9010; +pub const AUDIO_U16 : SDL_AudioFormat = AUDIO_U16LSB; +pub const AUDIO_S16 : SDL_AudioFormat = AUDIO_S16LSB; +pub const AUDIO_S32LSB : SDL_AudioFormat = 0x8020; +pub const AUDIO_S32MSB : SDL_AudioFormat = 0x9020; +pub const AUDIO_S32 : SDL_AudioFormat = AUDIO_S32LSB; +pub const AUDIO_F32LSB : SDL_AudioFormat = 0x8120; +pub const AUDIO_F32MSB : SDL_AudioFormat = 0x9120; +pub const AUDIO_F32 : SDL_AudioFormat = AUDIO_F32LSB; +pub const AUDIO_U16SYS : SDL_AudioFormat = AUDIO_U16LSB; +pub const AUDIO_S16SYS : SDL_AudioFormat = AUDIO_S16LSB; +pub const AUDIO_S32SYS : SDL_AudioFormat = AUDIO_S32LSB; +pub const AUDIO_F32SYS : SDL_AudioFormat = AUDIO_F32LSB; + +pub type SDL_AudioCallback = + ::std::option::Option; +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_AudioSpec { + pub freq: c_int, + pub format: SDL_AudioFormat, + pub channels: uint8_t, + pub silence: uint8_t, + pub samples: uint16_t, + pub padding: uint16_t, + pub size: uint32_t, + pub callback: SDL_AudioCallback, + pub userdata: *const c_void, +} +pub type SDL_AudioFilter = + ::std::option::Option; +#[allow(dead_code, missing_copy_implementations)] +#[repr(C)] +pub struct SDL_AudioCVT { + pub needed: c_int, + pub src_format: SDL_AudioFormat, + pub dst_format: SDL_AudioFormat, + pub rate_incr: c_double, + pub buf: *mut uint8_t, + pub len: c_int, + pub len_cvt: c_int, + pub len_mult: c_int, + pub len_ratio: c_double, + filters: [SDL_AudioFilter, ..10u], + filter_index: c_int, +} +pub type SDL_AudioDeviceID = uint32_t; +pub type SDL_AudioStatus = c_uint; +pub const SDL_AUDIO_STOPPED: c_uint = 0; +pub const SDL_AUDIO_PLAYING: c_uint = 1; +pub const SDL_AUDIO_PAUSED: c_uint = 2; +extern "C" { + pub fn SDL_GetNumAudioDrivers() -> c_int; + pub fn SDL_GetAudioDriver(index: c_int) -> *const c_char; + pub fn SDL_AudioInit(driver_name: *const c_char) -> c_int; + pub fn SDL_AudioQuit(); + pub fn SDL_GetCurrentAudioDriver() -> *const c_char; + pub fn SDL_OpenAudio(desired: *const SDL_AudioSpec, + obtained: *const SDL_AudioSpec) -> c_int; + pub fn SDL_GetNumAudioDevices(iscapture: c_int) -> c_int; + pub fn SDL_GetAudioDeviceName(index: c_int, iscapture: c_int) -> *const c_char; + pub fn SDL_OpenAudioDevice(device: *const c_char, iscapture: c_int, + desired: *const SDL_AudioSpec, + obtained: *mut SDL_AudioSpec, + allowed_changes: c_int) -> SDL_AudioDeviceID; + pub fn SDL_GetAudioStatus() -> SDL_AudioStatus; + pub fn SDL_GetAudioDeviceStatus(dev: SDL_AudioDeviceID) -> + SDL_AudioStatus; + pub fn SDL_PauseAudio(pause_on: c_int); + pub fn SDL_PauseAudioDevice(dev: SDL_AudioDeviceID, pause_on: c_int); + pub fn SDL_LoadWAV_RW(src: *const SDL_RWops, freesrc: c_int, + spec: *mut SDL_AudioSpec, + audio_buf: *mut *mut uint8_t, audio_len: *mut uint32_t) -> *mut SDL_AudioSpec; + pub fn SDL_FreeWAV(audio_buf: *mut uint8_t); + pub fn SDL_BuildAudioCVT(cvt: *mut SDL_AudioCVT, + src_format: SDL_AudioFormat, src_channels: uint8_t, + src_rate: c_int, dst_format: SDL_AudioFormat, + dst_channels: uint8_t, dst_rate: c_int) -> c_int; + pub fn SDL_ConvertAudio(cvt: *mut SDL_AudioCVT) -> c_int; + pub fn SDL_MixAudio(dst: *const uint8_t, src: *const uint8_t, len: uint32_t, + volume: c_int); + pub fn SDL_MixAudioFormat(dst: *const uint8_t, src: *const uint8_t, + format: SDL_AudioFormat, len: uint32_t, + volume: c_int); + pub fn SDL_LockAudio(); + pub fn SDL_LockAudioDevice(dev: SDL_AudioDeviceID); + pub fn SDL_UnlockAudio(); + pub fn SDL_UnlockAudioDevice(dev: SDL_AudioDeviceID); + pub fn SDL_CloseAudio(); + pub fn SDL_CloseAudioDevice(dev: SDL_AudioDeviceID); +} diff --git a/sdl2-sys/src/clipboard.rs b/sdl2-sys/src/clipboard.rs new file mode 100644 index 00000000..df35d4d4 --- /dev/null +++ b/sdl2-sys/src/clipboard.rs @@ -0,0 +1,9 @@ +use libc::{c_int, c_char}; + +pub type SDL_bool = c_int; + +extern "C" { + pub fn SDL_SetClipboardText(text: *const c_char) -> c_int; + pub fn SDL_GetClipboardText() -> *const c_char; + pub fn SDL_HasClipboardText() -> SDL_bool; +} diff --git a/sdl2-sys/src/controller.rs b/sdl2-sys/src/controller.rs new file mode 100644 index 00000000..6e310631 --- /dev/null +++ b/sdl2-sys/src/controller.rs @@ -0,0 +1,125 @@ +use libc::{c_int, c_char, c_uchar, c_uint, c_void, int16_t, uint8_t}; +use joystick::{SDL_Joystick, SDL_JoystickGUID}; + +pub type SDL_bool = c_int; + +pub type SDL_GameController = c_void; + +pub type SDL_GameControllerBindType = c_uint; +pub const SDL_CONTROLLER_BINDTYPE_NONE: SDL_GameControllerBindType = 0; +pub const SDL_CONTROLLER_BINDTYPE_BUTTON: SDL_GameControllerBindType = 1; +pub const SDL_CONTROLLER_BINDTYPE_AXIS: SDL_GameControllerBindType = 2; +pub const SDL_CONTROLLER_BINDTYPE_HAT: SDL_GameControllerBindType = 3; + +#[allow(dead_code, non_snake_case)] +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_GameControllerButtonBind { + bindType: SDL_GameControllerBindType, + value: SDL_GameControllerButtonBindData, +} + +#[allow(dead_code)] +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_GameControllerButtonBindData { + data: [c_uchar, ..8u], +} + +#[allow(dead_code)] +#[deriving(Copy, Clone)] +pub struct SDL_GameControllerButtonBindDataHat { + hat: c_int, + hat_mask: c_int, +} + +impl SDL_GameControllerButtonBindData { + pub fn button(&self) -> *const c_int { + self.data.as_ptr() as *const _ + } + pub fn axis(&self) -> *const c_int { + self.data.as_ptr() as *const _ + } + pub fn hat(&self) -> *const SDL_GameControllerButtonBindDataHat { + self.data.as_ptr() as *const _ + } +} + +pub type SDL_GameControllerAxis = c_int; +pub const SDL_CONTROLLER_AXIS_INVALID: SDL_GameControllerAxis = -1; +pub const SDL_CONTROLLER_AXIS_LEFTX: SDL_GameControllerAxis = 0; +pub const SDL_CONTROLLER_AXIS_LEFTY: SDL_GameControllerAxis = 1; +pub const SDL_CONTROLLER_AXIS_RIGHTX: SDL_GameControllerAxis = 2; +pub const SDL_CONTROLLER_AXIS_RIGHTY: SDL_GameControllerAxis = 3; +pub const SDL_CONTROLLER_AXIS_TRIGGERLEFT: SDL_GameControllerAxis = 4; +pub const SDL_CONTROLLER_AXIS_TRIGGERRIGHT: SDL_GameControllerAxis = 5; +pub const SDL_CONTROLLER_AXIS_MAX: SDL_GameControllerAxis = 6; + +pub type SDL_GameControllerButton = c_int; +pub const SDL_CONTROLLER_BUTTON_INVALID: SDL_GameControllerButton = -1; +pub const SDL_CONTROLLER_BUTTON_A: SDL_GameControllerButton = 0; +pub const SDL_CONTROLLER_BUTTON_B: SDL_GameControllerButton = 1; +pub const SDL_CONTROLLER_BUTTON_X: SDL_GameControllerButton = 2; +pub const SDL_CONTROLLER_BUTTON_Y: SDL_GameControllerButton = 3; +pub const SDL_CONTROLLER_BUTTON_BACK: SDL_GameControllerButton = 4; +pub const SDL_CONTROLLER_BUTTON_GUIDE: SDL_GameControllerButton = 5; +pub const SDL_CONTROLLER_BUTTON_START: SDL_GameControllerButton = 6; +pub const SDL_CONTROLLER_BUTTON_LEFTSTICK: SDL_GameControllerButton = 7; +pub const SDL_CONTROLLER_BUTTON_RIGHTSTICK: SDL_GameControllerButton = 8; +pub const SDL_CONTROLLER_BUTTON_LEFTSHOULDER: SDL_GameControllerButton = 9; +pub const SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: SDL_GameControllerButton = 10; +pub const SDL_CONTROLLER_BUTTON_DPAD_UP: SDL_GameControllerButton = 11; +pub const SDL_CONTROLLER_BUTTON_DPAD_DOWN: SDL_GameControllerButton = 12; +pub const SDL_CONTROLLER_BUTTON_DPAD_LEFT: SDL_GameControllerButton = 13; +pub const SDL_CONTROLLER_BUTTON_DPAD_RIGHT: SDL_GameControllerButton = 14; +pub const SDL_CONTROLLER_BUTTON_MAX: SDL_GameControllerButton = 15; + +extern "C" { + pub fn SDL_GameControllerAddMapping(mappingString: *const c_char) -> c_int; + pub fn SDL_GameControllerMappingForGUID(guid: SDL_JoystickGUID) -> + *const c_char; + pub fn SDL_GameControllerMapping(gamecontroller: *const SDL_GameController) + -> *const c_char; + pub fn SDL_IsGameController(joystick_index: c_int) -> SDL_bool; + pub fn SDL_GameControllerNameForIndex(joystick_index: c_int) -> + *const c_char; + pub fn SDL_GameControllerOpen(joystick_index: c_int) -> + *const SDL_GameController; + pub fn SDL_GameControllerName(gamecontroller: *const SDL_GameController) -> + *const c_char; + pub fn SDL_GameControllerGetAttached(gamecontroller: + *const SDL_GameController) -> + SDL_bool; + pub fn SDL_GameControllerGetJoystick(gamecontroller: + *const SDL_GameController) -> + *const SDL_Joystick; + pub fn SDL_GameControllerEventState(state: c_int) -> c_int; + pub fn SDL_GameControllerUpdate(); + pub fn SDL_GameControllerGetAxisFromString(pchString: *const c_char) -> + SDL_GameControllerAxis; + pub fn SDL_GameControllerGetStringForAxis(axis: + SDL_GameControllerAxis) + -> *const c_char; + pub fn SDL_GameControllerGetBindForAxis(gamecontroller: + *const SDL_GameController, + axis: SDL_GameControllerAxis) + -> SDL_GameControllerButtonBind; + pub fn SDL_GameControllerGetAxis(gamecontroller: *const SDL_GameController, + axis: SDL_GameControllerAxis) -> + int16_t; + pub fn SDL_GameControllerGetButtonFromString(pchString: *const c_char) -> + SDL_GameControllerButton; + pub fn SDL_GameControllerGetStringForButton(button: + SDL_GameControllerButton) + -> *const c_char; + pub fn SDL_GameControllerGetBindForButton(gamecontroller: + *const SDL_GameController, + button: + SDL_GameControllerButton) + -> SDL_GameControllerButtonBind; + pub fn SDL_GameControllerGetButton(gamecontroller: + *const SDL_GameController, + button: SDL_GameControllerButton) + -> uint8_t; + pub fn SDL_GameControllerClose(gamecontroller: *const SDL_GameController); +} diff --git a/sdl2-sys/src/cpuinfo.rs b/sdl2-sys/src/cpuinfo.rs new file mode 100644 index 00000000..12990c8f --- /dev/null +++ b/sdl2-sys/src/cpuinfo.rs @@ -0,0 +1,20 @@ +use libc::{c_int}; + +pub type SDL_bool = c_int; + +// SDL_cpuinfo.h +extern "C" { + pub fn SDL_GetCPUCount() -> c_int; + pub fn SDL_GetCPUCacheLineSize() -> c_int; + pub fn SDL_HasRDTSC() -> SDL_bool; + pub fn SDL_HasAltiVec() -> SDL_bool; + pub fn SDL_HasMMX() -> SDL_bool; + pub fn SDL_Has3DNow() -> SDL_bool; + pub fn SDL_HasSSE() -> SDL_bool; + pub fn SDL_HasSSE2() -> SDL_bool; + pub fn SDL_HasSSE3() -> SDL_bool; + pub fn SDL_HasSSE41() -> SDL_bool; + pub fn SDL_HasSSE42() -> SDL_bool; + pub fn SDL_HasAVX() -> SDL_bool; + pub fn SDL_GetSystemRAM() -> c_int; +} diff --git a/sdl2-sys/src/event.rs b/sdl2-sys/src/event.rs new file mode 100644 index 00000000..cb9ed725 --- /dev/null +++ b/sdl2-sys/src/event.rs @@ -0,0 +1,469 @@ +#![doc(hidden)] +#![allow(non_camel_case_types, non_snake_case)] +use libc::{c_float, c_int, c_char, c_uint, c_void, int16_t, + int32_t, uint8_t, uint16_t, uint32_t}; +use gesture::SDL_GestureID; +use keyboard::SDL_Keysym; +use touch::SDL_FingerID; +use touch::SDL_TouchID; + +pub type SDL_bool = c_int; + +// SDL_events.h +pub type SDL_EventState = uint8_t; +pub const SDL_DISABLE: SDL_EventState = 0; +pub const SDL_ENABLE: SDL_EventState = 1; +pub const SDL_QUERY: SDL_EventState = -1; + +pub type SDL_SysWMmsg = c_void; + +pub type SDL_EventType = c_uint; +pub const SDL_FIRSTEVENT: SDL_EventType = 0; +pub const SDL_QUIT: SDL_EventType = 256; +pub const SDL_APP_TERMINATING: SDL_EventType = 257; +pub const SDL_APP_LOWMEMORY: SDL_EventType = 258; +pub const SDL_APP_WILLENTERBACKGROUND: SDL_EventType = 259; +pub const SDL_APP_DIDENTERBACKGROUND: SDL_EventType = 260; +pub const SDL_APP_WILLENTERFOREGROUND: SDL_EventType = 261; +pub const SDL_APP_DIDENTERFOREGROUND: SDL_EventType = 262; +pub const SDL_WINDOWEVENT: SDL_EventType = 512; +pub const SDL_SYSWMEVENT: SDL_EventType = 513; +pub const SDL_KEYDOWN: SDL_EventType = 768; +pub const SDL_KEYUP: SDL_EventType = 769; +pub const SDL_TEXTEDITING: SDL_EventType = 770; +pub const SDL_TEXTINPUT: SDL_EventType = 771; +pub const SDL_MOUSEMOTION: SDL_EventType = 1024; +pub const SDL_MOUSEBUTTONDOWN: SDL_EventType = 1025; +pub const SDL_MOUSEBUTTONUP: SDL_EventType = 1026; +pub const SDL_MOUSEWHEEL: SDL_EventType = 1027; +pub const SDL_JOYAXISMOTION: SDL_EventType = 1536; +pub const SDL_JOYBALLMOTION: SDL_EventType = 1537; +pub const SDL_JOYHATMOTION: SDL_EventType = 1538; +pub const SDL_JOYBUTTONDOWN: SDL_EventType = 1539; +pub const SDL_JOYBUTTONUP: SDL_EventType = 1540; +pub const SDL_JOYDEVICEADDED: SDL_EventType = 1541; +pub const SDL_JOYDEVICEREMOVED: SDL_EventType = 1542; +pub const SDL_CONTROLLERAXISMOTION: SDL_EventType = 1616; +pub const SDL_CONTROLLERBUTTONDOWN: SDL_EventType = 1617; +pub const SDL_CONTROLLERBUTTONUP: SDL_EventType = 1618; +pub const SDL_CONTROLLERDEVICEADDED: SDL_EventType = 1619; +pub const SDL_CONTROLLERDEVICEREMOVED: SDL_EventType = 1620; +pub const SDL_CONTROLLERDEVICEREMAPPED: SDL_EventType = 1621; +pub const SDL_FINGERDOWN: SDL_EventType = 1792; +pub const SDL_FINGERUP: SDL_EventType = 1793; +pub const SDL_FINGERMOTION: SDL_EventType = 1794; +pub const SDL_DOLLARGESTURE: SDL_EventType = 2048; +pub const SDL_DOLLARRECORD: SDL_EventType = 2049; +pub const SDL_MULTIGESTURE: SDL_EventType = 2050; +pub const SDL_CLIPBOARDUPDATE: SDL_EventType = 2304; +pub const SDL_DROPFILE: SDL_EventType = 4096; +pub const SDL_USEREVENT: SDL_EventType = 32768; +pub const SDL_LASTEVENT: SDL_EventType = 65535; + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_CommonEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_WindowEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub event: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, + pub padding3: uint8_t, + pub data1: int32_t, + pub data2: int32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_KeyboardEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub state: uint8_t, + pub repeat: uint8_t, + pub padding2: uint8_t, + pub padding3: uint8_t, + pub keysym: SDL_Keysym, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_TextEditingEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub text: [c_char, ..32u], + pub start: int32_t, + pub length: int32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_TextInputEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub text: [c_char, ..32u], +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_MouseMotionEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub which: uint32_t, + pub state: uint32_t, + pub x: int32_t, + pub y: int32_t, + pub xrel: int32_t, + pub yrel: int32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_MouseButtonEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub which: uint32_t, + pub button: uint8_t, + pub state: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, + pub x: int32_t, + pub y: int32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_MouseWheelEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub which: uint32_t, + pub x: int32_t, + pub y: int32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_JoyAxisEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, + pub axis: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, + pub padding3: uint8_t, + pub value: int16_t, + pub padding4: uint16_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_JoyBallEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, + pub ball: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, + pub padding3: uint8_t, + pub xrel: int16_t, + pub yrel: int16_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_JoyHatEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, + pub hat: uint8_t, + pub value: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_JoyButtonEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, + pub button: uint8_t, + pub state: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_JoyDeviceEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_ControllerAxisEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, + pub axis: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, + pub padding3: uint8_t, + pub value: int16_t, + pub padding4: uint16_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_ControllerButtonEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, + pub button: uint8_t, + pub state: uint8_t, + pub padding1: uint8_t, + pub padding2: uint8_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_ControllerDeviceEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub which: int32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_TouchFingerEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub touchId: SDL_TouchID, + pub fingerId: SDL_FingerID, + pub x: c_float, + pub y: c_float, + pub dx: c_float, + pub dy: c_float, + pub pressure: c_float, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_MultiGestureEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub touchId: SDL_TouchID, + pub dTheta: c_float, + pub dDist: c_float, + pub x: c_float, + pub y: c_float, + pub numFingers: uint16_t, + pub padding: uint16_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_DollarGestureEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub touchId: SDL_TouchID, + pub gestureId: SDL_GestureID, + pub numFingers: uint32_t, + pub error: c_float, + pub x: c_float, + pub y: c_float, +} + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_DropEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub file: *const c_char, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_QuitEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_OSEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, +} + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_UserEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub windowID: uint32_t, + pub code: int32_t, + pub data1: *const c_void, + pub data2: *const c_void, +} + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_SysWMEvent { + pub _type: uint32_t, + pub timestamp: uint32_t, + pub msg: *const SDL_SysWMmsg, +} + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_Event { + pub data: [uint8_t, ..56u], +} + +impl SDL_Event { + pub fn _type(&self) -> *const uint32_t { + self.data.as_ptr() as *const _ + } + + pub fn common(&self) -> *const SDL_CommonEvent { + self.data.as_ptr() as *const _ + } + + pub fn window(&self) -> *const SDL_WindowEvent { + self.data.as_ptr() as *const _ + } + + pub fn key(&self) -> *const SDL_KeyboardEvent { + self.data.as_ptr() as *const _ + } + + pub fn edit(&self) -> *const SDL_TextEditingEvent { + self.data.as_ptr() as *const _ + } + + pub fn text(&self) -> *const SDL_TextInputEvent { + self.data.as_ptr() as *const _ + } + + pub fn motion(&self) -> *const SDL_MouseMotionEvent { + self.data.as_ptr() as *const _ + } + + pub fn button(&self) -> *const SDL_MouseButtonEvent { + self.data.as_ptr() as *const _ + } + + pub fn wheel(&self) -> *const SDL_MouseWheelEvent { + self.data.as_ptr() as *const _ + } + + pub fn jaxis(&self) -> *const SDL_JoyAxisEvent { + self.data.as_ptr() as *const _ + } + + pub fn jball(&self) -> *const SDL_JoyBallEvent { + self.data.as_ptr() as *const _ + } + + pub fn jhat(&self) -> *const SDL_JoyHatEvent { + self.data.as_ptr() as *const _ + } + + pub fn jbutton(&self) -> *const SDL_JoyButtonEvent { + self.data.as_ptr() as *const _ + } + + pub fn jdevice(&self) -> *const SDL_JoyDeviceEvent { + self.data.as_ptr() as *const _ + } + + pub fn caxis(&self) -> *const SDL_ControllerAxisEvent { + self.data.as_ptr() as *const _ + } + + pub fn cbutton(&self) -> *const SDL_ControllerButtonEvent { + self.data.as_ptr() as *const _ + } + + pub fn cdevice(&self) -> *const SDL_ControllerDeviceEvent { + self.data.as_ptr() as *const _ + } + + pub fn quit(&self) -> *const SDL_QuitEvent { + self.data.as_ptr() as *const _ + } + + pub fn user(&self) -> *const SDL_UserEvent { + self.data.as_ptr() as *const _ + } + + pub fn syswm(&self) -> *const SDL_SysWMEvent { + self.data.as_ptr() as *const _ + } + + pub fn tfinger(&self) -> *const SDL_TouchFingerEvent { + self.data.as_ptr() as *const _ + } + + pub fn mgesture(&self) -> *const SDL_MultiGestureEvent { + self.data.as_ptr() as *const _ + } + + pub fn dgesture(&self) -> *const SDL_DollarGestureEvent { + self.data.as_ptr() as *const _ + } + + pub fn drop(&self) -> *const SDL_DropEvent { + self.data.as_ptr() as *const _ + } +} + +pub type SDL_eventaction = c_uint; +pub const SDL_ADDEVENT: SDL_eventaction = 0; +pub const SDL_PEEKEVENT: SDL_eventaction = 1; +pub const SDL_GETEVENT: SDL_eventaction = 2; +pub type SDL_EventFilter = + extern "C" fn(userdata: *const c_void, event: *const SDL_Event) -> c_int; + +extern "C" { + pub fn SDL_free(mem: *const c_void); + pub fn SDL_PumpEvents(); + /*pub fn SDL_PeepEvents(events: &[SDL_Event], numevents: c_int, + action: SDL_eventaction, minType: uint32_t, + maxType: uint32_t) -> c_int;*/ + pub fn SDL_HasEvent(_type: uint32_t) -> SDL_bool; + pub fn SDL_HasEvents(minType: uint32_t, maxType: uint32_t) -> + SDL_bool; + pub fn SDL_FlushEvent(_type: uint32_t); + pub fn SDL_FlushEvents(minType: uint32_t, maxType: uint32_t); + pub fn SDL_PollEvent(event: *const SDL_Event) -> c_int; + pub fn SDL_WaitEvent(event: *const SDL_Event) -> c_int; + pub fn SDL_WaitEventTimeout(event: *const SDL_Event, timeout: c_int) -> + c_int; + pub fn SDL_PushEvent(event: *const SDL_Event) -> c_int; + pub fn SDL_SetEventFilter(filter: SDL_EventFilter, + userdata: *const c_void); + /*pub fn SDL_GetEventFilter(filter: *SDL_EventFilter, + userdata: **c_void) -> SDL_bool;*/ + pub fn SDL_AddEventWatch(filter: SDL_EventFilter, userdata: *const c_void); + pub fn SDL_DelEventWatch(filter: SDL_EventFilter, userdata: *const c_void); + pub fn SDL_FilterEvents(filter: SDL_EventFilter, userdata: *const c_void); + pub fn SDL_EventState(_type: uint32_t, state: SDL_EventState) -> SDL_EventState; + pub fn SDL_RegisterEvents(numevents: c_int) -> uint32_t; +} diff --git a/sdl2-sys/src/filesystem.rs b/sdl2-sys/src/filesystem.rs new file mode 100644 index 00000000..888e89a3 --- /dev/null +++ b/sdl2-sys/src/filesystem.rs @@ -0,0 +1,6 @@ +use libc::{c_char}; + +extern "C" { + pub fn SDL_GetBasePath() -> *const c_char; + pub fn SDL_GetPrefPath(arg: *const c_char, app: *const c_char) -> *const c_char; +} diff --git a/sdl2-sys/src/gesture.rs b/sdl2-sys/src/gesture.rs new file mode 100644 index 00000000..ff916bd0 --- /dev/null +++ b/sdl2-sys/src/gesture.rs @@ -0,0 +1,12 @@ +use libc::{c_int, int64_t}; +use rwops::SDL_RWops; +use touch::SDL_TouchID; + +pub type SDL_GestureID = int64_t; + +extern "C" { + pub fn SDL_RecordGesture(touchId: SDL_TouchID) -> c_int; + pub fn SDL_SaveAllDollarTemplates(src: *const SDL_RWops) -> c_int; + pub fn SDL_SaveDollarTemplate(gestureId: SDL_GestureID, src: *const SDL_RWops) -> c_int; + pub fn SDL_LoadDollarTemplates(touchId: SDL_TouchID, src: *const SDL_RWops) -> c_int; +} diff --git a/sdl2-sys/src/haptic.rs b/sdl2-sys/src/haptic.rs new file mode 100644 index 00000000..8130a68e --- /dev/null +++ b/sdl2-sys/src/haptic.rs @@ -0,0 +1,194 @@ +use joystick::SDL_Joystick; +use libc::{c_int, c_uint, c_char, c_float, c_void, int16_t, int32_t, uint8_t, uint16_t, uint32_t}; + +pub const SDL_HAPTIC_CONSTANT: uint16_t = 1 << 0; +pub const SDL_HAPTIC_SINE: uint16_t = 1 << 1; +pub const SDL_HAPTIC_LEFTRIGHT: uint16_t = 1 << 2; +pub const SDL_HAPTIC_TRIANGLE: uint16_t = 1 << 3; +pub const SDL_HAPTIC_SAWTOOTHUP: uint16_t = 1 << 4; +pub const SDL_HAPTIC_SAWTOOTHDOWN: uint16_t = 1 << 5; +pub const SDL_HAPTIC_RAMP: uint16_t = 1 << 6; +pub const SDL_HAPTIC_SPRING: uint16_t = 1 << 7; +pub const SDL_HAPTIC_DAMPER: uint16_t = 1 << 8; +pub const SDL_HAPTIC_INERTIA: uint16_t = 1 << 9; +pub const SDL_HAPTIC_FRICTION: uint16_t = 1 << 10; +pub const SDL_HAPTIC_CUSTOM: uint16_t = 1 << 11; +pub const SDL_HAPTIC_GAIN: uint16_t = 1 << 12; +pub const SDL_HAPTIC_AUTOCENTER: uint16_t = 1 << 13; +pub const SDL_HAPTIC_STATUS: uint16_t = 1 << 14; +pub const SDL_HAPTIC_PAUSE: uint16_t = 1 << 15; + +pub type SDL_Haptic = c_void; + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_HapticDirection { + pub _type: uint8_t, + pub dir: [int32_t, ..3], +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_HapticConstant { + pub _type: uint16_t, + pub direction: SDL_HapticDirection, + pub length: uint32_t, + pub delay: uint16_t, + pub button: uint16_t, + pub interval: uint16_t, + pub level: int16_t, + pub attack_length: uint16_t, + pub attack_level: uint16_t, + pub fade_length: uint16_t, + pub fade_level: uint16_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_HapticPeriodic { + pub _type: uint16_t, + pub direction: SDL_HapticDirection, + pub length: uint32_t, + pub delay: uint16_t, + pub button: uint16_t, + pub interval: uint16_t, + pub period: uint16_t, + pub magnitude: int16_t, + pub offset: int16_t, + pub phase: uint16_t, + pub attack_length: uint16_t, + pub attack_level: uint16_t, + pub fade_length: uint16_t, + pub fade_level: uint16_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_HapticCondition { + pub _type: uint16_t, + pub direction: SDL_HapticDirection, + pub length: uint32_t, + pub delay: uint16_t, + pub button: uint16_t, + pub interval: uint16_t, + pub right_sat: [uint16_t, ..3], + pub left_sat: [uint16_t, ..3], + pub right_coeff: [int16_t, ..3], + pub left_coeff: [int16_t, ..3], + pub deadband: [uint16_t, ..3], + pub center: [int16_t, ..3], +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_HapticRamp { + pub _type: uint16_t, + pub length: uint32_t, + pub delay: uint16_t, + pub button: uint16_t, + pub interval: uint16_t, + pub start: int16_t, + pub end: int16_t, + pub attack_length: uint16_t, + pub attack_level: uint16_t, + pub fade_length: uint16_t, + pub fade_level: uint16_t, +} + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_HapticLeftRight { + pub _type: uint16_t, + pub length: uint32_t, + pub large_magnitude: uint16_t, + pub small_magnitude: uint16_t, +} + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_HapticCustom { + pub _type: uint16_t, + pub direction: SDL_HapticDirection, + pub length: uint32_t, + pub delay: uint16_t, + pub button: uint16_t, + pub interval: uint16_t, + pub channels: uint8_t, + pub period: uint16_t, + pub samples: uint16_t, + pub data: *const uint16_t, + pub attack_length: uint16_t, + pub attack_level: uint16_t, + pub fade_length: uint16_t, + pub fade_level: uint16_t, +} + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_HapticEffect { + pub data: [uint8_t, ..72u], +} + +impl SDL_HapticEffect { + pub fn _type(&self) -> *const uint16_t { + self.data.as_ptr() as *const _ + } + + pub fn constant(&self) -> *const SDL_HapticConstant { + self.data.as_ptr() as *const _ + } + + pub fn periodic(&self) -> *const SDL_HapticPeriodic { + self.data.as_ptr() as *const _ + } + + pub fn condition(&self) -> *const SDL_HapticCondition { + self.data.as_ptr() as *const _ + } + + pub fn ramp(&self) -> *const SDL_HapticRamp { + self.data.as_ptr() as *const _ + } + + pub fn left_right(&self) -> *const SDL_HapticLeftRight { + self.data.as_ptr() as *const _ + } + + pub fn custom(&self) -> *const SDL_HapticCustom { + self.data.as_ptr() as *const _ + } +} + +extern "C" { + pub fn SDL_NumHaptics() -> c_int; + pub fn SDL_HapticName(device_index: c_int) -> *const c_char; + pub fn SDL_HapticOpen(device_index: c_int) -> *const SDL_Haptic; + pub fn SDL_HapticOpened(device_index: c_int) -> c_int; + pub fn SDL_HapticIndex(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_MouseIsHaptic() -> c_int; + pub fn SDL_HapticOpenFromMouse() -> *const SDL_Haptic; + pub fn SDL_JoystickIsHaptic(joystick: *const SDL_Joystick) -> c_int; + pub fn SDL_HapticOpenFromJoystick(joystick: *const SDL_Joystick) -> *const SDL_Haptic; + pub fn SDL_HapticClose(haptic: *const SDL_Haptic); + pub fn SDL_HapticNumEffects(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticNumEffectsPlaying(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticQuery(haptic: *const SDL_Haptic) -> c_uint; + pub fn SDL_HapticNumAxes(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticEffectSupported(haptic: *const SDL_Haptic, effect: *const SDL_HapticEffect) -> c_int; + pub fn SDL_HapticNewEffect(haptic: *const SDL_Haptic, effect: *const SDL_HapticEffect) -> c_int; + pub fn SDL_HapticUpdateEffect(haptic: *const SDL_Haptic, effect: *const SDL_HapticEffect) -> c_int; + pub fn SDL_HapticRunEffect(haptic: *const SDL_Haptic, effect: c_int, iterations: uint32_t) -> c_int; + pub fn SDL_HapticStopEffect(haptic: *const SDL_Haptic, effect: c_int) -> c_int; + pub fn SDL_HapticDestroyEffect(haptic: *const SDL_Haptic, effect: c_int); + pub fn SDL_HapticGetEffectStatus(haptic: *const SDL_Haptic, effect: c_int) -> c_int; + pub fn SDL_HapticSetGain(haptic: *const SDL_Haptic, gain: c_int) -> c_int; + pub fn SDL_HapticSetAutocenter(haptic: *const SDL_Haptic, autocenter: c_int) -> c_int; + pub fn SDL_HapticPause(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticUnpause(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticStopAll(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticRumbleSupported(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticRumbleInit(haptic: *const SDL_Haptic) -> c_int; + pub fn SDL_HapticRumblePlay(haptic: *const SDL_Haptic, strength: c_float, length: uint32_t) -> c_int; + pub fn SDL_HapticRumbleStop(haptic: *const SDL_Haptic) -> c_int; +} + diff --git a/sdl2-sys/src/joystick.rs b/sdl2-sys/src/joystick.rs new file mode 100644 index 00000000..7b9f185c --- /dev/null +++ b/sdl2-sys/src/joystick.rs @@ -0,0 +1,44 @@ +use libc::{c_int, c_char, c_void, int32_t, int16_t, int8_t, uint8_t}; + +pub type SDL_bool = c_int; + +pub type SDL_Joystick = c_void; + +#[allow(dead_code)] +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_JoystickGUID { + pub data: [uint8_t, ..16u], +} + +extern "C" { + pub fn SDL_NumJoysticks() -> c_int; + pub fn SDL_JoystickNameForIndex(device_index: c_int) -> *const c_char; + pub fn SDL_JoystickOpen(device_index: c_int) -> *const SDL_Joystick; + pub fn SDL_JoystickName(joystick: *const SDL_Joystick) -> *const c_char; + pub fn SDL_JoystickGetDeviceGUID(device_index: c_int) -> + SDL_JoystickGUID; + pub fn SDL_JoystickGetGUID(joystick: *const SDL_Joystick) -> + SDL_JoystickGUID; + pub fn SDL_JoystickGetGUIDString(guid: SDL_JoystickGUID, + pszGUID: *const c_char, cbGUID: c_int); + pub fn SDL_JoystickGetGUIDFromString(pchGUID: *const c_char) -> + SDL_JoystickGUID; + pub fn SDL_JoystickGetAttached(joystick: *const SDL_Joystick) -> SDL_bool; + pub fn SDL_JoystickInstanceID(joystick: *const SDL_Joystick) -> int32_t; + pub fn SDL_JoystickNumAxes(joystick: *const SDL_Joystick) -> c_int; + pub fn SDL_JoystickNumBalls(joystick: *const SDL_Joystick) -> c_int; + pub fn SDL_JoystickNumHats(joystick: *const SDL_Joystick) -> c_int; + pub fn SDL_JoystickNumButtons(joystick: *const SDL_Joystick) -> c_int; + pub fn SDL_JoystickUpdate(); + pub fn SDL_JoystickEventState(state: c_int) -> c_int; + pub fn SDL_JoystickGetAxis(joystick: *const SDL_Joystick, axis: c_int) -> + int16_t; + pub fn SDL_JoystickGetHat(joystick: *const SDL_Joystick, hat: c_int) -> + int8_t; + pub fn SDL_JoystickGetBall(joystick: *const SDL_Joystick, ball: c_int, + dx: *const c_int, dy: *const c_int) -> c_int; + pub fn SDL_JoystickGetButton(joystick: *const SDL_Joystick, button: c_int) + -> uint8_t; + pub fn SDL_JoystickClose(joystick: *const SDL_Joystick); +} diff --git a/sdl2-sys/src/keyboard.rs b/sdl2-sys/src/keyboard.rs new file mode 100644 index 00000000..2412c74d --- /dev/null +++ b/sdl2-sys/src/keyboard.rs @@ -0,0 +1,38 @@ +use libc::{c_int, c_char, c_uint, int32_t, uint8_t, uint16_t, + uint32_t}; +use rect::Rect; +use video::SDL_Window; + +pub type SDL_bool = c_int; +pub type SDL_Rect = Rect; +pub type SDL_Keycode = int32_t; +pub type SDL_Keymod = c_uint; +pub type SDL_Scancode = c_uint; + +// SDL_keyboard.h +#[deriving(Copy, Clone)] +pub struct SDL_Keysym { + pub scancode: SDL_Scancode, + pub sym: SDL_Keycode, + pub _mod: uint16_t, + pub unused: uint32_t, +} + +extern "C" { + pub fn SDL_GetKeyboardFocus() -> *const SDL_Window; + pub fn SDL_GetKeyboardState(numkeys: *const c_int) -> *const uint8_t; + pub fn SDL_GetModState() -> SDL_Keymod; + pub fn SDL_SetModState(modstate: SDL_Keymod); + pub fn SDL_GetKeyFromScancode(scancode: SDL_Scancode) -> SDL_Keycode; + pub fn SDL_GetScancodeFromKey(key: SDL_Keycode) -> SDL_Scancode; + pub fn SDL_GetScancodeName(scancode: SDL_Scancode) -> *const c_char; + pub fn SDL_GetScancodeFromName(name: *const c_char) -> SDL_Scancode; + pub fn SDL_GetKeyName(key: SDL_Keycode) -> *const c_char; + pub fn SDL_GetKeyFromName(name: *const c_char) -> SDL_Keycode; + pub fn SDL_StartTextInput(); + pub fn SDL_IsTextInputActive() -> SDL_bool; + pub fn SDL_StopTextInput(); + pub fn SDL_SetTextInputRect(rect: *const SDL_Rect); + pub fn SDL_HasScreenKeyboardSupport() -> SDL_bool; + pub fn SDL_IsScreenKeyboardShown(window: *const SDL_Window) -> SDL_bool; +} diff --git a/sdl2-sys/src/lib.rs b/sdl2-sys/src/lib.rs new file mode 100644 index 00000000..76d36a65 --- /dev/null +++ b/sdl2-sys/src/lib.rs @@ -0,0 +1,26 @@ +#![allow(non_camel_case_types)] + +extern crate libc; + +pub mod audio; +pub mod clipboard; +pub mod controller; +pub mod cpuinfo; +pub mod event; +pub mod filesystem; +pub mod haptic; +pub mod gesture; +pub mod joystick; +pub mod keyboard; +pub mod messagebox; +pub mod rect; +pub mod pixels; +pub mod render; +pub mod rwops; +pub mod surface; +pub mod touch; +pub mod video; +pub mod mouse; +pub mod sdl; +pub mod timer; +pub mod version; diff --git a/sdl2-sys/src/messagebox.rs b/sdl2-sys/src/messagebox.rs new file mode 100644 index 00000000..bedac5c1 --- /dev/null +++ b/sdl2-sys/src/messagebox.rs @@ -0,0 +1,11 @@ +use libc::{c_int, c_char, uint32_t}; +use video::SDL_Window; + +pub type SDL_MessageBoxFlags = u32; +pub const SDL_MESSAGEBOX_ERROR : SDL_MessageBoxFlags = 0x00000010; +pub const SDL_MESSAGEBOX_WARNING : SDL_MessageBoxFlags = 0x00000020; +pub const SDL_MESSAGEBOX_INFORMATION : SDL_MessageBoxFlags = 0x00000040; + +extern "C" { + pub fn SDL_ShowSimpleMessageBox(flags: uint32_t, title: *const c_char, message: *const c_char, window: *const SDL_Window) -> c_int; +} diff --git a/sdl2-sys/src/mouse.rs b/sdl2-sys/src/mouse.rs new file mode 100644 index 00000000..111e4324 --- /dev/null +++ b/sdl2-sys/src/mouse.rs @@ -0,0 +1,46 @@ +use libc::{c_int, c_uint, c_void, uint8_t, uint32_t}; +use surface::SDL_Surface; +use video::SDL_Window; + +pub type SDL_bool = c_int; +pub type SDL_Cursor = c_void; + +pub type SDL_SystemCursor = c_uint; +pub const SDL_SYSTEM_CURSOR_ARROW: SDL_SystemCursor = 0; +pub const SDL_SYSTEM_CURSOR_IBEAM: SDL_SystemCursor = 1; +pub const SDL_SYSTEM_CURSOR_WAIT: SDL_SystemCursor = 2; +pub const SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_SystemCursor = 3; +pub const SDL_SYSTEM_CURSOR_WAITARROW: SDL_SystemCursor = 4; +pub const SDL_SYSTEM_CURSOR_SIZENWSE: SDL_SystemCursor = 5; +pub const SDL_SYSTEM_CURSOR_SIZENESW: SDL_SystemCursor = 6; +pub const SDL_SYSTEM_CURSOR_SIZEWE: SDL_SystemCursor = 7; +pub const SDL_SYSTEM_CURSOR_SIZENS: SDL_SystemCursor = 8; +pub const SDL_SYSTEM_CURSOR_SIZEALL: SDL_SystemCursor = 9; +pub const SDL_SYSTEM_CURSOR_NO: SDL_SystemCursor = 10; +pub const SDL_SYSTEM_CURSOR_HAND: SDL_SystemCursor = 11; +pub const SDL_NUM_SYSTEM_CURSORS: SDL_SystemCursor = 12; + +pub type SDL_MouseState = c_int; +pub const SDL_DISABLE: SDL_MouseState = 0; +pub const SDL_ENABLE: SDL_MouseState = 1; +pub const SDL_QUERY: SDL_MouseState = -1; + +extern "C" { + pub fn SDL_GetMouseFocus() -> *const SDL_Window; + pub fn SDL_GetMouseState(x: *const c_int, y: *const c_int) -> uint32_t; + pub fn SDL_GetRelativeMouseState(x: *const c_int, y: *const c_int) -> uint32_t; + pub fn SDL_WarpMouseInWindow(window: *const SDL_Window, x: c_int, y: c_int); + pub fn SDL_SetRelativeMouseMode(enabled: SDL_bool) -> c_int; + pub fn SDL_GetRelativeMouseMode() -> SDL_bool; + pub fn SDL_CreateCursor(data: *const uint8_t, mask: *const uint8_t, w: c_int, + h: c_int, hot_x: c_int, hot_y: c_int) -> + *const SDL_Cursor; + pub fn SDL_CreateColorCursor(surface: *const SDL_Surface, hot_x: c_int, + hot_y: c_int) -> *const SDL_Cursor; + pub fn SDL_CreateSystemCursor(id: SDL_SystemCursor) -> *const SDL_Cursor; + pub fn SDL_SetCursor(cursor: *const SDL_Cursor); + pub fn SDL_GetCursor() -> *const SDL_Cursor; + pub fn SDL_GetDefaultCursor() -> *const SDL_Cursor; + pub fn SDL_FreeCursor(cursor: *const SDL_Cursor); + pub fn SDL_ShowCursor(toggle: SDL_MouseState) -> SDL_MouseState; +} diff --git a/sdl2-sys/src/pixels.rs b/sdl2-sys/src/pixels.rs new file mode 100644 index 00000000..cd320272 --- /dev/null +++ b/sdl2-sys/src/pixels.rs @@ -0,0 +1,89 @@ +use libc::{c_int, uint8_t, uint32_t}; + +//SDL_pixels.h +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_Color { + pub r: uint8_t, + pub g: uint8_t, + pub b: uint8_t, + pub a: uint8_t, +} + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_Palette { + pub ncolors: c_int, + pub colors: *const SDL_Color, + pub version: uint32_t, + pub refcount: c_int +} + +#[allow(non_snake_case, missing_copy_implementations)] +#[repr(C)] +pub struct SDL_PixelFormat { + pub format: SDL_PixelFormatFlag, + pub palette: *const SDL_Palette, + pub BitsPerPixel: uint8_t, + pub BytesPerPixel: uint8_t, + pub padding: [uint8_t, ..2], + pub Rmask: uint8_t, + pub Gmask: uint8_t, + pub Bmask: uint8_t, + pub Amask: uint8_t, + pub Rloss: uint8_t, + pub Gloss: uint8_t, + pub Bloss: uint8_t, + pub Aloss: uint8_t, + pub Rshift: uint8_t, + pub Gshift: uint8_t, + pub Bshift: uint8_t, + pub Ashift: uint8_t, + pub refcount: c_int, + pub next: *const SDL_PixelFormat +} + +pub type SDL_PixelFormatFlag = uint32_t; +pub const SDL_PIXELFORMAT_UNKNOWN: SDL_PixelFormatFlag = 0x0; +pub const SDL_PIXELFORMAT_INDEX1LSB: SDL_PixelFormatFlag = 0x11100100; +pub const SDL_PIXELFORMAT_INDEX1MSB: SDL_PixelFormatFlag = 0x11200100; +pub const SDL_PIXELFORMAT_INDEX4LSB: SDL_PixelFormatFlag = 0x12100400; +pub const SDL_PIXELFORMAT_INDEX4MSB: SDL_PixelFormatFlag = 0x12200400; +pub const SDL_PIXELFORMAT_INDEX8: SDL_PixelFormatFlag = 0x13000801; +pub const SDL_PIXELFORMAT_RGB332: SDL_PixelFormatFlag = 0x14110801; +pub const SDL_PIXELFORMAT_RGB444: SDL_PixelFormatFlag = 0x15120c02; +pub const SDL_PIXELFORMAT_RGB555: SDL_PixelFormatFlag = 0x15130f02; +pub const SDL_PIXELFORMAT_BGR555: SDL_PixelFormatFlag = 0x15530f02; +pub const SDL_PIXELFORMAT_ARGB4444: SDL_PixelFormatFlag = 0x15321002; +pub const SDL_PIXELFORMAT_RGBA4444: SDL_PixelFormatFlag = 0x15421002; +pub const SDL_PIXELFORMAT_ABGR4444: SDL_PixelFormatFlag = 0x15721002; +pub const SDL_PIXELFORMAT_BGRA4444: SDL_PixelFormatFlag = 0x15821002; +pub const SDL_PIXELFORMAT_ARGB1555: SDL_PixelFormatFlag = 0x15331002; +pub const SDL_PIXELFORMAT_RGBA5551: SDL_PixelFormatFlag = 0x15441002; +pub const SDL_PIXELFORMAT_ABGR1555: SDL_PixelFormatFlag = 0x15731002; +pub const SDL_PIXELFORMAT_BGRA5551: SDL_PixelFormatFlag = 0x15841002; +pub const SDL_PIXELFORMAT_RGB565: SDL_PixelFormatFlag = 0x15151002; +pub const SDL_PIXELFORMAT_BGR565: SDL_PixelFormatFlag = 0x15551002; +pub const SDL_PIXELFORMAT_RGB24: SDL_PixelFormatFlag = 0x17101803; +pub const SDL_PIXELFORMAT_BGR24: SDL_PixelFormatFlag = 0x17401803; +pub const SDL_PIXELFORMAT_RGB888: SDL_PixelFormatFlag = 0x16161804; +pub const SDL_PIXELFORMAT_RGBX8888: SDL_PixelFormatFlag = 0x16261804; +pub const SDL_PIXELFORMAT_BGR888: SDL_PixelFormatFlag = 0x16561804; +pub const SDL_PIXELFORMAT_BGRX8888: SDL_PixelFormatFlag = 0x16661804; +pub const SDL_PIXELFORMAT_ARGB8888: SDL_PixelFormatFlag = 0x16362004; +pub const SDL_PIXELFORMAT_RGBA8888: SDL_PixelFormatFlag = 0x16462004; +pub const SDL_PIXELFORMAT_ABGR8888: SDL_PixelFormatFlag = 0x16762004; +pub const SDL_PIXELFORMAT_BGRA8888: SDL_PixelFormatFlag = 0x16862004; +pub const SDL_PIXELFORMAT_ARGB2101010: SDL_PixelFormatFlag = 0x16372004; +pub const SDL_PIXELFORMAT_YV12: SDL_PixelFormatFlag = 0x32315659; +pub const SDL_PIXELFORMAT_IYUV: SDL_PixelFormatFlag = 0x56555949; +pub const SDL_PIXELFORMAT_YUY2: SDL_PixelFormatFlag = 0x32595559; +pub const SDL_PIXELFORMAT_UYVY: SDL_PixelFormatFlag = 0x59565955; +pub const SDL_PIXELFORMAT_YVYU: SDL_PixelFormatFlag = 0x55595659; + +extern "C" { + pub fn SDL_GetRGB(pixel: uint32_t, format: *const SDL_PixelFormat, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t); + pub fn SDL_GetRGBA(pixel: uint32_t, format: *const SDL_PixelFormat, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t, a: *const uint8_t); + pub fn SDL_MapRGB(format: *const SDL_PixelFormat, r: uint8_t, g: uint8_t, b: uint8_t) -> uint32_t; + pub fn SDL_MapRGBA(format: *const SDL_PixelFormat, r: uint8_t, g: uint8_t, b: uint8_t, a: uint8_t) -> uint32_t; +} diff --git a/sdl2-sys/src/rect.rs b/sdl2-sys/src/rect.rs new file mode 100644 index 00000000..d1ffaa48 --- /dev/null +++ b/sdl2-sys/src/rect.rs @@ -0,0 +1,140 @@ +/*! +Rectangle Functions + */ + +use std::mem; +use libc::c_int; + +/// A structure that defines a two dimensional point. +#[deriving(PartialEq, Clone, Show, Copy)] +#[repr(C)] +pub struct Point { + pub x: i32, + pub y: i32 +} + +/// A structure that defines a rectangle, with the origin at the upper left. +#[deriving(PartialEq, Clone, Show, Copy)] +#[repr(C)] +pub struct Rect { + pub x: i32, + pub y: i32, + pub w: i32, + pub h: i32 +} + +#[doc(hidden)] +#[allow(non_camel_case_types)] +pub mod ll { + + use libc::c_int; + use super::Rect; + use super::Point; + + pub type SDL_Rect = Rect; + pub type SDL_Point = Point; + pub type SDL_bool = c_int; + + extern "C" { + pub fn SDL_HasIntersection(A: *const SDL_Rect, B: *const SDL_Rect) -> SDL_bool; + pub fn SDL_IntersectRect(A: *const SDL_Rect, B: *const SDL_Rect, result: *const SDL_Rect) -> SDL_bool; + pub fn SDL_UnionRect(A: *const SDL_Rect, B: *const SDL_Rect, result: *const SDL_Rect); + pub fn SDL_EnclosePoints(points: *const SDL_Point, count: c_int, clip: *const SDL_Rect, result: *const SDL_Rect) -> SDL_bool; + pub fn SDL_IntersectRectAndLine(rect: *const SDL_Rect, X1: *const c_int, Y1: *const c_int, X2: *const c_int, Y2: *const c_int) -> SDL_bool; + } +} + +impl Point { + pub fn new(x: i32, y: i32) -> Point { + Point { + x: x, + y: y + } + } +} + +impl Rect { + pub fn new(x: i32, y: i32, w: i32, h: i32) -> Rect { + Rect { + x: x, + y: y, + w: w, + h: h + } + } + + /// Calculate a minimal rectangle enclosing a set of points. + pub fn from_enclose_points(points: &[Point], clip: Option) -> Option { + let out: Rect = Rect::new(0, 0, 0, 0); + + let result = unsafe { + ll::SDL_EnclosePoints( + points.as_ptr(), + points.len() as c_int, + mem::transmute(clip.as_ref()), + &out + ) != 0 + }; + + if result { + Some(out) + } else { + None + } + } + + /// Check whether a rectangle has no area. + pub fn is_empty(&self) -> bool { + (self.w <= 0) || (self.h <= 0) + } + + /// Determine whether two rectangles intersect. + pub fn has_intersection(&self, other: &Rect) -> bool { + unsafe { + ll::SDL_HasIntersection(self, other) != 0 + } + } + + /// Calculate the intersection of two rectangles. + pub fn intersection(&self, other: &Rect) -> Option { + let out: Rect = Rect::new(0, 0, 0, 0); + + let result = unsafe { + ll::SDL_IntersectRect(self, other, &out) != 0 + }; + + if result { + Some(out) + } else { + None + } + } + + /// Calculate the union of two rectangles. + pub fn union(&self, other: &Rect) -> Rect { + let out: Rect = Rect::new(0, 0, 0, 0); + + unsafe { + ll::SDL_UnionRect(self, other, &out) + }; + + out + } + + /// Calculate the intersection of a rectangle and line segment. return points of intersection. + pub fn intersect_line(&self, start: &Point, end: &Point) -> Option<(Point, Point)> { + let out_start: Point = start.clone(); + let out_end: Point = end.clone(); + + let result = unsafe { + ll::SDL_IntersectRectAndLine(self, &out_start.x, &out_start.y, &out_end.x, &out_end.y) != 0 + }; + + if result { + Some((out_start, out_end)) + } else { + None + } + } +} + diff --git a/sdl2-sys/src/rect_2.rs b/sdl2-sys/src/rect_2.rs new file mode 100644 index 00000000..80565d39 --- /dev/null +++ b/sdl2-sys/src/rect_2.rs @@ -0,0 +1,29 @@ +use libc::c_int; + +/// A structure that defines a two dimensional point. +#[deriving(PartialEq, Clone, Show, Copy)] +#[repr(C)] +pub struct SDL_Point { + pub x: i32, + pub y: i32 +} + +/// A structure that defines a rectangle, with the origin at the upper left. +#[deriving(PartialEq, Clone, Show, Copy)] +#[repr(C)] +pub struct SDL_Rect { + pub x: i32, + pub y: i32, + pub w: i32, + pub h: i32 +} + +pub type SDL_bool = c_int; + +extern "C" { + pub fn SDL_HasIntersection(A: *const SDL_Rect, B: *const SDL_Rect) -> SDL_bool; + pub fn SDL_IntersectRect(A: *const SDL_Rect, B: *const SDL_Rect, result: *const SDL_Rect) -> SDL_bool; + pub fn SDL_UnionRect(A: *const SDL_Rect, B: *const SDL_Rect, result: *const SDL_Rect); + pub fn SDL_EnclosePoints(points: *const SDL_Point, count: c_int, clip: *const SDL_Rect, result: *const SDL_Rect) -> SDL_bool; + pub fn SDL_IntersectRectAndLine(rect: *const SDL_Rect, X1: *const c_int, Y1: *const c_int, X2: *const c_int, Y2: *const c_int) -> SDL_bool; +} diff --git a/sdl2-sys/src/render.rs b/sdl2-sys/src/render.rs new file mode 100644 index 00000000..803b2db6 --- /dev/null +++ b/sdl2-sys/src/render.rs @@ -0,0 +1,114 @@ +use libc::{c_int, c_uint, c_char, c_void, c_float, c_double}; +use libc::{uint8_t, uint32_t}; +use rect::Point; +use rect::Rect; + +use surface::SDL_Surface; +use video::SDL_Window; + +pub type SDL_Point = Point; +pub type SDL_Rect = Rect; +pub type SDL_bool = c_int; + +//SDL_render.h +pub type SDL_RendererFlags = c_uint; +pub const SDL_RENDERER_SOFTWARE : SDL_RendererFlags = 0x00000001; +pub const SDL_RENDERER_ACCELERATED : SDL_RendererFlags = 0x00000002; +pub const SDL_RENDERER_PRESENTVSYNC : SDL_RendererFlags = 0x00000004; +pub const SDL_RENDERER_TARGETTEXTURE : SDL_RendererFlags = 0x00000008; + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_RendererInfo +{ + pub name: *const c_char, + pub flags: uint32_t, + pub num_texture_formats: uint32_t, + pub texture_formats: [uint32_t, ..16], + pub max_texture_width: c_int, + pub max_texture_height: c_int, +} + +pub type SDL_TextureAccess = c_uint; +pub const SDL_TEXTUREACCESS_STATIC : SDL_TextureAccess = 0; +pub const SDL_TEXTUREACCESS_STREAMING : SDL_TextureAccess = 1; +pub const SDL_TEXTUREACCESS_TARGET : SDL_TextureAccess = 2; + +pub type SDL_TextureModulate = c_uint; +pub const SDL_TEXTUREMODULATE_NONE : SDL_TextureModulate = 0x00000000; +pub const SDL_TEXTUREMODULATE_COLOR : SDL_TextureModulate = 0x00000001; +pub const SDL_TEXTUREMODULATE_ALPHA : SDL_TextureModulate = 0x00000002; + +pub type SDL_RendererFlip = c_uint; +pub const SDL_FLIP_NONE : SDL_RendererFlip = 0x00000000; +pub const SDL_FLIP_HORIZONTAL : SDL_RendererFlip = 0x00000001; +pub const SDL_FLIP_VERTICAL : SDL_RendererFlip = 0x00000002; + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_Renderer; +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_Texture; + +//SDL_blendmode.h +pub type SDL_BlendMode = c_uint; +pub const SDL_BLENDMODE_NONE : SDL_BlendMode = 0x00000000; +pub const SDL_BLENDMODE_BLEND : SDL_BlendMode = 0x00000001; +pub const SDL_BLENDMODE_ADD : SDL_BlendMode = 0x00000002; +pub const SDL_BLENDMODE_MOD : SDL_BlendMode = 0x00000004; + +extern "C" { + pub fn SDL_GetNumRenderDrivers() -> c_int; + pub fn SDL_GetRenderDriverInfo(index: c_int, info: *const SDL_RendererInfo) -> c_int; + pub fn SDL_CreateWindowAndRenderer(width: c_int, height: c_int, window_flags: uint32_t, window: *const *const SDL_Window, renderer: *const *const SDL_Renderer) -> c_int; + pub fn SDL_CreateRenderer(window: *const SDL_Window, index: c_int, flags: uint32_t) -> *const SDL_Renderer; + pub fn SDL_CreateSoftwareRenderer(surface: *const SDL_Surface) -> *const SDL_Renderer; + pub fn SDL_GetRenderer(window: *const SDL_Window) -> *const SDL_Renderer; + pub fn SDL_GetRendererInfo(renderer: *const SDL_Renderer, info: *const SDL_RendererInfo) -> c_int; + pub fn SDL_GetRendererOutputSize(renderer: *const SDL_Renderer, w: *const c_int, h: *const c_int) -> c_int; + pub fn SDL_CreateTexture(renderer: *const SDL_Renderer, format: uint32_t, access: c_int, w: c_int, h: c_int) -> *const SDL_Texture; + pub fn SDL_CreateTextureFromSurface(renderer: *const SDL_Renderer, surface: *const SDL_Surface) -> *const SDL_Texture; + pub fn SDL_QueryTexture(texture: *const SDL_Texture, format: *const uint32_t, access: *const c_int, w: *const c_int, h: *const c_int) -> c_int; + pub fn SDL_SetTextureColorMod(texture: *const SDL_Texture, r: uint8_t, g: uint8_t, b: uint8_t) -> c_int; + pub fn SDL_GetTextureColorMod(texture: *const SDL_Texture, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t) -> c_int; + pub fn SDL_SetTextureAlphaMod(texture: *const SDL_Texture, alpha: uint8_t) -> c_int; + pub fn SDL_GetTextureAlphaMod(texture: *const SDL_Texture, alpha: *const uint8_t) -> c_int; + pub fn SDL_SetTextureBlendMode(texture: *const SDL_Texture, blendMode: SDL_BlendMode) -> c_int; + pub fn SDL_GetTextureBlendMode(texture: *const SDL_Texture, blendMode: *const SDL_BlendMode) -> c_int; + pub fn SDL_UpdateTexture(texture: *const SDL_Texture, rect: *const SDL_Rect, pixels: *const c_void, pitch: c_int) -> c_int; + pub fn SDL_LockTexture(texture: *const SDL_Texture, rect: *const SDL_Rect, pixels: *const *const c_void, pitch: *const c_int) -> c_int; + pub fn SDL_UnlockTexture(texture: *const SDL_Texture); + pub fn SDL_RenderTargetSupported(renderer: *const SDL_Renderer) -> SDL_bool; + pub fn SDL_SetRenderTarget(renderer: *const SDL_Renderer, texture: *const SDL_Texture) -> c_int; + pub fn SDL_GetRenderTarget(renderer: *const SDL_Renderer) -> *const SDL_Texture; + pub fn SDL_RenderSetLogicalSize(renderer: *const SDL_Renderer, w: c_int, h: c_int) -> c_int; + pub fn SDL_RenderGetLogicalSize(renderer: *const SDL_Renderer, w: *const c_int, h: *const c_int); + pub fn SDL_RenderSetViewport(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; + pub fn SDL_RenderGetViewport(renderer: *const SDL_Renderer, rect: *const SDL_Rect); + pub fn SDL_RenderSetClipRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; + pub fn SDL_RenderGetClipRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect); + pub fn SDL_RenderSetScale(renderer: *const SDL_Renderer, scaleX: c_float, scaleY: c_float) -> c_int; + pub fn SDL_RenderGetScale(renderer: *const SDL_Renderer, scaleX: *const c_float, scaleY: *const c_float); + pub fn SDL_SetRenderDrawColor(renderer: *const SDL_Renderer, r: uint8_t, g: uint8_t, b: uint8_t, a: uint8_t) -> c_int; + pub fn SDL_GetRenderDrawColor(renderer: *const SDL_Renderer, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t, a: *const uint8_t) -> c_int; + pub fn SDL_SetRenderDrawBlendMode(renderer: *const SDL_Renderer, blendMode: SDL_BlendMode) -> c_int; + pub fn SDL_GetRenderDrawBlendMode(renderer: *const SDL_Renderer, blendMode: *const SDL_BlendMode) -> c_int; + pub fn SDL_RenderClear(renderer: *const SDL_Renderer) -> c_int; + pub fn SDL_RenderDrawPoint(renderer: *const SDL_Renderer, x: c_int, y: c_int) -> c_int; + pub fn SDL_RenderDrawPoints(renderer: *const SDL_Renderer, Points: *const SDL_Point, count: c_int) -> c_int; + pub fn SDL_RenderDrawLine(renderer: *const SDL_Renderer, x1: c_int, y1: c_int, x2: c_int, y2: c_int) -> c_int; + pub fn SDL_RenderDrawLines(renderer: *const SDL_Renderer, Points: *const SDL_Point, count: c_int) -> c_int; + pub fn SDL_RenderDrawRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; + pub fn SDL_RenderDrawRects(renderer: *const SDL_Renderer, rects: *const SDL_Rect, count: c_int) -> c_int; + pub fn SDL_RenderFillRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; + pub fn SDL_RenderFillRects(renderer: *const SDL_Renderer, rects: *const SDL_Rect, count: c_int) -> c_int; + pub fn SDL_RenderCopy(renderer: *const SDL_Renderer, texture: *const SDL_Texture, srcrect: *const SDL_Rect, dstrect: *const SDL_Rect) -> c_int; + pub fn SDL_RenderCopyEx(renderer: *const SDL_Renderer, texture: *const SDL_Texture, srcrect: *const SDL_Rect, dstrect: *const SDL_Rect, angle: c_double, center: *const SDL_Point, flip: SDL_RendererFlip) -> c_int; + pub fn SDL_RenderReadPixels(renderer: *const SDL_Renderer, rect: *const SDL_Rect, format: uint32_t, pixels: *mut c_void, pitch: c_int) -> c_int; + pub fn SDL_RenderPresent(renderer: *const SDL_Renderer); + pub fn SDL_DestroyTexture(texture: *const SDL_Texture); + pub fn SDL_DestroyRenderer(renderer: *const SDL_Renderer); + pub fn SDL_GL_BindTexture(texture: *const SDL_Texture, texw: *const c_float, texh: *const c_float) -> c_int; + pub fn SDL_GL_UnbindTexture(texture: *const SDL_Texture) -> c_int; +} diff --git a/sdl2-sys/src/rwops.rs b/sdl2-sys/src/rwops.rs new file mode 100644 index 00000000..8c4ccd9b --- /dev/null +++ b/sdl2-sys/src/rwops.rs @@ -0,0 +1,38 @@ +use libc::{c_uchar, uint32_t, c_char, FILE, c_void}; +use libc::{c_int, int64_t, size_t}; + +#[allow(dead_code)] +#[repr(C)] +struct SDL_RWops_Anon { + data: [c_uchar, ..24], +} + +pub type SDL_bool = c_int; + +pub static RW_SEEK_SET: c_int = 0; +pub static RW_SEEK_CUR: c_int = 1; +pub static RW_SEEK_END: c_int = 2; + +#[allow(dead_code)] +#[repr(C)] +pub struct SDL_RWops { + pub size: extern "C" fn(context: *const SDL_RWops) -> int64_t, + pub seek: extern "C" fn(context: *const SDL_RWops, offset: int64_t, whence: c_int) -> int64_t, + pub read: extern "C" fn(context: *const SDL_RWops, ptr: *const c_void, + size: size_t, maxnum: size_t) -> size_t, + pub write: extern "C" fn(context: *const SDL_RWops, ptr: *const c_void, + size: size_t, maxnum: size_t) -> size_t, + pub close: extern "C" fn(context: *const SDL_RWops) -> c_int, + pub _type: uint32_t, + hidden: SDL_RWops_Anon +} + +extern "C" { + pub fn SDL_RWFromFile(file: *const c_char, mode: *const c_char) -> *const SDL_RWops; + pub fn SDL_RWFromFP(fp: *const FILE, autoclose: SDL_bool) -> *const SDL_RWops; + pub fn SDL_RWFromMem(mem: *const c_void, size: c_int) -> *const SDL_RWops; + pub fn SDL_RWFromConstMem(mem: *const c_void, size: c_int) -> *const SDL_RWops; + + pub fn SDL_AllocRW() -> *const SDL_RWops; + pub fn SDL_FreeRW(area: *const SDL_RWops); +} diff --git a/sdl2-sys/src/sdl.rs b/sdl2-sys/src/sdl.rs new file mode 100644 index 00000000..f8eccd2d --- /dev/null +++ b/sdl2-sys/src/sdl.rs @@ -0,0 +1,56 @@ +use libc::{c_int, c_uint, c_char, uint32_t}; + +// Setup linking for all targets. +#[cfg(target_os="macos")] +mod mac { + #[cfg(mac_framework)] + #[link(kind="framework", name="SDL2")] + extern {} + + #[cfg(not(mac_framework))] + #[link(name="SDL2")] + extern {} +} + +#[cfg(any(target_os="windows", target_os="linux", target_os="freebsd"))] +mod others { + #[link(name="SDL2")] + extern {} +} + +pub type SDL_errorcode = c_uint; +pub const SDL_ENOMEM: SDL_errorcode = 0; +pub const SDL_EFREAD: SDL_errorcode = 1; +pub const SDL_EFWRITE: SDL_errorcode = 2; +pub const SDL_EFSEEK: SDL_errorcode = 3; +pub const SDL_UNSUPPORTED: SDL_errorcode = 4; +pub const SDL_LASTERROR: SDL_errorcode = 5; + +pub type SDL_InitFlag = uint32_t; +pub const SDL_INIT_TIMER: SDL_InitFlag = 0x00000001; +pub const SDL_INIT_AUDIO: SDL_InitFlag = 0x00000010; +pub const SDL_INIT_VIDEO: SDL_InitFlag = 0x00000020; +pub const SDL_INIT_JOYSTICK: SDL_InitFlag = 0x00000200; +pub const SDL_INIT_HAPTIC: SDL_InitFlag = 0x00001000; +pub const SDL_INIT_GAMECONTROLLER: SDL_InitFlag = 0x00002000; +pub const SDL_INIT_EVENTS: SDL_InitFlag = 0x00004000; +pub const SDL_INIT_NOPARACHUTE: SDL_InitFlag = 0x00100000; +pub const SDL_INIT_EVERYTHING: SDL_InitFlag = 0x0000FFFF; + +//SDL_error.h +extern "C" { + pub fn SDL_ClearError(); + pub fn SDL_Error(code: SDL_errorcode) -> c_int; + pub fn SDL_SetError(fmt: *const c_char) -> c_int; + pub fn SDL_GetError() -> *const c_char; + + //SDL.h + pub fn SDL_Init(flags: uint32_t) -> c_int; + pub fn SDL_InitSubSystem(flags: SDL_InitFlag) -> c_int; + pub fn SDL_QuitSubSystem(flags: SDL_InitFlag); + pub fn SDL_WasInit(flags: SDL_InitFlag) -> SDL_InitFlag; + pub fn SDL_Quit(); + + //SDL_timer.h + pub fn SDL_GetTicks() -> uint32_t; +} diff --git a/sdl2-sys/src/surface.rs b/sdl2-sys/src/surface.rs new file mode 100644 index 00000000..c9ef6e5a --- /dev/null +++ b/sdl2-sys/src/surface.rs @@ -0,0 +1,70 @@ +use pixels::SDL_PixelFormat; +use pixels::SDL_Palette; +use rwops::SDL_RWops; +use rect::Rect; +use libc::{c_int, c_void, uint32_t, uint8_t}; +pub use render::SDL_BlendMode; + +pub type SDL_bool = c_int; +pub type SDL_Rect = Rect; + +pub type SDL_SurfaceFlag = c_int; + +pub const SDL_SWSURFACE: SDL_SurfaceFlag = 0; +pub const SDL_PREALLOC: SDL_SurfaceFlag = 0x00000001; +pub const SDL_RLEACCEL: SDL_SurfaceFlag = 0x00000002; +pub const SDL_DONTFREE: SDL_SurfaceFlag = 0x00000004; + +//SDL_surface.h +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_BlitMap; + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_Surface { + pub flags: uint32_t, + pub format: *const SDL_PixelFormat, + pub w: c_int, + pub h: c_int, + pub pitch: c_int, + pub pixels: *const c_void, + pub userdata: *const c_void, + pub locked: c_int, + pub lock_data: *const c_void, + pub clip_rect: SDL_Rect, + pub map: *const SDL_BlitMap, + pub refcount: c_int +} + +extern "C" { + pub fn SDL_CreateRGBSurface(flags: uint32_t, width: c_int, height: c_int, depth: c_int, Rmask: uint32_t, Gmask: uint32_t, Bmask: uint32_t, Amask: uint32_t) -> *const SDL_Surface; + pub fn SDL_CreateRGBSurfaceFrom(pixels: *const c_void, width: c_int, height: c_int, depth: c_int, pitch: c_int, Rmask: uint32_t, Gmask: uint32_t, Bmask: uint32_t, Amask: uint32_t) -> *const SDL_Surface; + pub fn SDL_FreeSurface(surface: *const SDL_Surface); + pub fn SDL_SetSurfacePalette(surface: *const SDL_Surface, palette: *const SDL_Palette) -> c_int; + pub fn SDL_LockSurface(surface: *const SDL_Surface) -> c_int; + pub fn SDL_UnlockSurface(surface: *const SDL_Surface); + pub fn SDL_LoadBMP_RW(src: *const SDL_RWops, freesrc: c_int) -> *const SDL_Surface; + pub fn SDL_SaveBMP_RW(surface: *const SDL_Surface, dst: *const SDL_RWops, freedst: c_int) -> c_int; + pub fn SDL_SetSurfaceRLE(surface: *const SDL_Surface, flag: c_int) -> c_int; + pub fn SDL_SetColorKey(surface: *const SDL_Surface, flag: c_int, key: uint32_t) -> c_int; + pub fn SDL_GetColorKey(surface: *const SDL_Surface, key: *const uint32_t) -> c_int; + pub fn SDL_SetSurfaceColorMod(surface: *const SDL_Surface, r: uint8_t, g: uint8_t, b: uint8_t) -> c_int; + pub fn SDL_GetSurfaceColorMod(surface: *const SDL_Surface, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t ) -> c_int; + pub fn SDL_SetSurfaceAlphaMod(surface: *const SDL_Surface, alpha: uint8_t) -> c_int; + pub fn SDL_GetSurfaceAlphaMod(surface: *const SDL_Surface, alpha: *const uint8_t ) -> c_int; + pub fn SDL_SetSurfaceBlendMode(surface: *const SDL_Surface, blendMode: SDL_BlendMode) -> c_int; + pub fn SDL_GetSurfaceBlendMode(surface: *const SDL_Surface, blendMode: *const SDL_BlendMode) -> c_int; + pub fn SDL_SetClipRect(surface: *const SDL_Surface, rect: *const SDL_Rect) -> SDL_bool; + pub fn SDL_GetClipRect(surface: *const SDL_Surface, rect: *const SDL_Rect); + pub fn SDL_ConvertSurface(src: *const SDL_Surface, fmt: *const SDL_PixelFormat, flags: uint32_t) -> *const SDL_Surface; + pub fn SDL_ConvertSurfaceFormat(src: *const SDL_Surface, pixel_format: uint32_t, flags: uint32_t) -> *const SDL_Surface; + pub fn SDL_ConvertPixels(width: c_int, height: c_int, src_format: uint32_t, src: *const c_void, src_pitch: c_int, dst_format: uint32_t, dst: *const c_void, dst_pitch: c_int) -> c_int; + pub fn SDL_FillRect(dst: *const SDL_Surface, rect: *const SDL_Rect, color: uint32_t) -> c_int; + pub fn SDL_FillRects(dst: *const SDL_Surface, rects: *const SDL_Rect, count: c_int, color: uint32_t) -> c_int; + pub fn SDL_UpperBlit(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; + pub fn SDL_LowerBlit(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; + pub fn SDL_SoftStretch(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; + pub fn SDL_UpperBlitScaled(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; + pub fn SDL_LowerBlitScaled(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; +} diff --git a/sdl2-sys/src/timer.rs b/sdl2-sys/src/timer.rs new file mode 100644 index 00000000..1e29222f --- /dev/null +++ b/sdl2-sys/src/timer.rs @@ -0,0 +1,17 @@ +use libc::{uint32_t, uint64_t, c_void, c_int}; + +//SDL_timer.h +pub type SDL_TimerCallback = + ::std::option::Option uint32_t>; +pub type SDL_TimerID = c_int; +extern "C" { + pub fn SDL_GetTicks() -> uint32_t; + pub fn SDL_GetPerformanceCounter() -> uint64_t; + pub fn SDL_GetPerformanceFrequency() -> uint64_t; + pub fn SDL_Delay(ms: uint32_t); + + pub fn SDL_AddTimer(interval: uint32_t, callback: SDL_TimerCallback, + param: *const c_void) -> SDL_TimerID; + pub fn SDL_RemoveTimer(id: SDL_TimerID) -> c_int; +} diff --git a/sdl2-sys/src/touch.rs b/sdl2-sys/src/touch.rs new file mode 100644 index 00000000..2a5b26b7 --- /dev/null +++ b/sdl2-sys/src/touch.rs @@ -0,0 +1,23 @@ +use libc::{c_int, int64_t}; + +pub type SDL_TouchID = int64_t; +pub type SDL_FingerID = int64_t; +pub type SDL_Finger = Finger; +pub type TouchDevice = SDL_TouchID; + +#[deriving(PartialEq, Copy)] +#[repr(C)] +pub struct Finger { + id: TouchDevice, + x: f32, + y: f32, + pressure: f32, +} + +extern "C" { + pub fn SDL_GetNumTouchDevices() -> c_int; + pub fn SDL_GetTouchDevice(index: c_int) -> SDL_TouchID; + pub fn SDL_GetNumTouchFingers(touchID: SDL_TouchID) -> c_int; + pub fn SDL_GetTouchFinger(touchID: SDL_TouchID, index: c_int) -> + *const SDL_Finger; +} diff --git a/sdl2-sys/src/version.rs b/sdl2-sys/src/version.rs new file mode 100644 index 00000000..ef7672ed --- /dev/null +++ b/sdl2-sys/src/version.rs @@ -0,0 +1,16 @@ +#![doc(hidden)] + +use libc::{uint8_t, c_char, c_int}; + +#[deriving(Copy, Clone)] +#[repr(C)] +pub struct SDL_version { + pub major: uint8_t, + pub minor: uint8_t, + pub patch: uint8_t, +} +extern "C" { + pub fn SDL_GetVersion(ver: *mut SDL_version); + pub fn SDL_GetRevision() -> *const c_char; + pub fn SDL_GetRevisionNumber() -> c_int; +} diff --git a/sdl2-sys/src/video.rs b/sdl2-sys/src/video.rs new file mode 100644 index 00000000..5120028a --- /dev/null +++ b/sdl2-sys/src/video.rs @@ -0,0 +1,176 @@ +use rect::Rect; +use surface::SDL_Surface; + +use libc::{c_void, c_int, c_float, c_char, uint16_t, uint32_t}; + +pub type SDL_Rect = Rect; +pub type SDL_bool = c_int; + +//SDL_video.h +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_Window; + +#[allow(missing_copy_implementations)] +#[repr(C)] +pub struct SDL_DisplayMode { + pub format: uint32_t, + pub w: c_int, + pub h: c_int, + pub refresh_rate: c_int, + pub driverdata: *const c_void +} + +pub type SDL_WindowPos = c_int; +pub const SDL_WINDOWPOS_CENTERED: SDL_WindowPos = 0x2FFF0000; +pub const SDL_WINDOWPOS_UNDEFINED: SDL_WindowPos = 0x1FFF0000; + +#[deriving(Copy, Clone)] +pub enum SDL_WindowFlags { + SDL_WINDOW_FULLSCREEN = 0x00000001, + SDL_WINDOW_OPENGL = 0x00000002, + SDL_WINDOW_SHOWN = 0x00000004, + SDL_WINDOW_HIDDEN = 0x00000008, + SDL_WINDOW_BORDERLESS = 0x00000010, + SDL_WINDOW_RESIZABLE = 0x00000020, + SDL_WINDOW_MINIMIZED = 0x00000040, + SDL_WINDOW_MAXIMIZED = 0x00000080, + SDL_WINDOW_INPUT_GRABBED = 0x00000100, + SDL_WINDOW_INPUT_FOCUS = 0x00000200, + SDL_WINDOW_MOUSE_FOCUS = 0x00000400, + SDL_WINDOW_FULLSCREEN_DESKTOP = 0x00001001, + SDL_WINDOW_FOREIGN = 0x00000800, + SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000 +} + +#[deriving(Copy, Clone)] +pub enum SDL_WindowEventID { + SDL_WINDOWEVENT_NONE, + SDL_WINDOWEVENT_SHOWN, + SDL_WINDOWEVENT_HIDDEN, + SDL_WINDOWEVENT_EXPOSED, + SDL_WINDOWEVENT_MOVED, + SDL_WINDOWEVENT_RESIZED, + SDL_WINDOWEVENT_SIZE_CHANGED, + SDL_WINDOWEVENT_MINIMIZED, + SDL_WINDOWEVENT_MAXIMIZED, + SDL_WINDOWEVENT_RESTORED, + SDL_WINDOWEVENT_ENTER, + SDL_WINDOWEVENT_LEAVE, + SDL_WINDOWEVENT_FOCUS_GAINED, + SDL_WINDOWEVENT_FOCUS_LOST, + SDL_WINDOWEVENT_CLOSE +} + +pub type SDL_GLContext = *const c_void; + +#[deriving(Copy, Clone, FromPrimitive)] +#[repr(C)] +pub enum SDL_GLattr { + SDL_GL_RED_SIZE = 0, + SDL_GL_GREEN_SIZE = 1, + SDL_GL_BLUE_SIZE = 2, + SDL_GL_ALPHA_SIZE = 3, + SDL_GL_BUFFER_SIZE = 4, + SDL_GL_DOUBLEBUFFER = 5, + SDL_GL_DEPTH_SIZE = 6, + SDL_GL_STENCIL_SIZE = 7, + SDL_GL_ACCUM_RED_SIZE = 8, + SDL_GL_ACCUM_GREEN_SIZE = 9, + SDL_GL_ACCUM_BLUE_SIZE = 10, + SDL_GL_ACCUM_ALPHA_SIZE = 11, + SDL_GL_STEREO = 12, + SDL_GL_MULTISAMPLEBUFFERS = 13, + SDL_GL_MULTISAMPLESAMPLES = 14, + SDL_GL_ACCELERATED_VISUAL = 15, + SDL_GL_RETAINED_BACKING = 16, + SDL_GL_CONTEXT_MAJOR_VERSION = 17, + SDL_GL_CONTEXT_MINOR_VERSION = 18, + SDL_GL_CONTEXT_EGL = 19, + SDL_GL_CONTEXT_FLAGS = 20, + SDL_GL_CONTEXT_PROFILE_MASK = 21, + SDL_GL_SHARE_WITH_CURRENT_CONTEXT = 22, + SDL_GL_FRAMEBUFFER_SRGB_CAPABLE = 23 +} + +#[deriving(Copy, Clone)] +pub enum SDL_GLprofile { + SDL_GL_CONTEXT_PROFILE_CORE = 0x0001, + SDL_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002, + SDL_GL_CONTEXT_PROFILE_ES = 0x0004 +} + +//SDL_video.h +extern "C" { + pub fn SDL_GetNumVideoDrivers() -> c_int; + pub fn SDL_GetVideoDriver(index: c_int) -> *const c_char; + pub fn SDL_VideoInit(driver_name: *const c_char) -> c_int; + pub fn SDL_VideoQuit(); + pub fn SDL_GetCurrentVideoDriver() -> *const c_char; + pub fn SDL_GetNumVideoDisplays() -> c_int; + pub fn SDL_GetDisplayName(displayIndex: c_int) -> *const c_char; + pub fn SDL_GetDisplayBounds(displayIndex: c_int, rect: *const SDL_Rect) -> c_int; + pub fn SDL_GetNumDisplayModes(displayIndex: c_int) -> c_int; + pub fn SDL_GetDisplayMode(displayIndex: c_int, modeIndex: c_int, mode: *const SDL_DisplayMode) -> c_int; + pub fn SDL_GetDesktopDisplayMode(displayIndex: c_int, mode: *const SDL_DisplayMode) -> c_int; + pub fn SDL_GetCurrentDisplayMode(displayIndex: c_int, mode: *const SDL_DisplayMode) -> c_int; + pub fn SDL_GetClosestDisplayMode(displayIndex: c_int, mode: *const SDL_DisplayMode, closest: *const SDL_DisplayMode) -> *const SDL_DisplayMode; + pub fn SDL_GetWindowDisplayIndex(window: *const SDL_Window) -> c_int; + pub fn SDL_SetWindowDisplayMode(window: *const SDL_Window, mode: *const SDL_DisplayMode) -> c_int; + pub fn SDL_GetWindowDisplayMode(window: *const SDL_Window, mode: *const SDL_DisplayMode) -> c_int; + pub fn SDL_GetWindowPixelFormat(window: *const SDL_Window) -> uint32_t; + pub fn SDL_CreateWindow(title: *const c_char, x: c_int, y: c_int, w: c_int, h: c_int, flags: uint32_t) -> *const SDL_Window; + pub fn SDL_CreateWindowFrom(data: *const c_void) -> *const SDL_Window; + pub fn SDL_GetWindowID(window: *const SDL_Window) -> uint32_t; + pub fn SDL_GetWindowFromID(id: uint32_t) -> *const SDL_Window; + pub fn SDL_GetWindowFlags(window: *const SDL_Window) -> uint32_t; + pub fn SDL_SetWindowTitle(window: *const SDL_Window, title: *const c_char); + pub fn SDL_GetWindowTitle(window: *const SDL_Window) -> *const c_char; + pub fn SDL_SetWindowIcon(window: *const SDL_Window, icon: *const SDL_Surface); + pub fn SDL_SetWindowData(window: *const SDL_Window, name: *const c_char, userdata: *const c_void) -> *const c_void; + pub fn SDL_GetWindowData(window: *const SDL_Window, name: *const c_char) -> *const c_void; + pub fn SDL_SetWindowPosition(window: *const SDL_Window, x: c_int, y: c_int); + pub fn SDL_GetWindowPosition(window: *const SDL_Window, x: *const c_int, y: *const c_int); + pub fn SDL_SetWindowSize(window: *const SDL_Window, w: c_int, h: c_int); + pub fn SDL_GetWindowSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); + pub fn SDL_SetWindowMinimumSize(window: *const SDL_Window, min_w: c_int, min_h: c_int); + pub fn SDL_GetWindowMinimumSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); + pub fn SDL_SetWindowMaximumSize(window: *const SDL_Window, max_w: c_int, max_h: c_int); + pub fn SDL_GetWindowMaximumSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); + pub fn SDL_SetWindowBordered(window: *const SDL_Window, bordered: SDL_bool); + pub fn SDL_ShowWindow(window: *const SDL_Window); + pub fn SDL_HideWindow(window: *const SDL_Window); + pub fn SDL_RaiseWindow(window: *const SDL_Window); + pub fn SDL_MaximizeWindow(window: *const SDL_Window); + pub fn SDL_MinimizeWindow(window: *const SDL_Window); + pub fn SDL_RestoreWindow(window: *const SDL_Window); + pub fn SDL_SetWindowFullscreen(window: *const SDL_Window, flags: uint32_t) -> c_int; + pub fn SDL_GetWindowSurface(window: *const SDL_Window) -> *const SDL_Surface; + pub fn SDL_UpdateWindowSurface(window: *const SDL_Window) -> c_int; + pub fn SDL_UpdateWindowSurfaceRects(window: *const SDL_Window, rects: *const SDL_Rect, numrects: c_int) -> c_int; + pub fn SDL_SetWindowGrab(window: *const SDL_Window, grabbed: SDL_bool); + pub fn SDL_GetWindowGrab(window: *const SDL_Window) -> SDL_bool; + pub fn SDL_SetWindowBrightness(window: *const SDL_Window, brightness: c_float) -> c_int; + pub fn SDL_GetWindowBrightness(window: *const SDL_Window) -> c_float; + pub fn SDL_SetWindowGammaRamp(window: *const SDL_Window, red: *const uint16_t, green: *const uint16_t, blue: *const uint16_t) -> c_int; + pub fn SDL_GetWindowGammaRamp(window: *const SDL_Window, red: *const uint16_t, green: *const uint16_t, blue: *const uint16_t) -> c_int; + pub fn SDL_DestroyWindow(window: *const SDL_Window); + pub fn SDL_IsScreenSaverEnabled() -> SDL_bool; + pub fn SDL_EnableScreenSaver(); + pub fn SDL_DisableScreenSaver(); + pub fn SDL_GL_GetDrawableSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); + pub fn SDL_GL_LoadLibrary(path: *const c_char) -> c_int; + pub fn SDL_GL_GetProcAddress(procname: *const c_char) -> Option; + pub fn SDL_GL_UnloadLibrary(); + pub fn SDL_GL_ExtensionSupported(extension: *const c_char) -> SDL_bool; + pub fn SDL_GL_SetAttribute(attr: SDL_GLattr, value: c_int) -> c_int; + pub fn SDL_GL_GetAttribute(attr: SDL_GLattr, value: *const c_int) -> c_int; + pub fn SDL_GL_CreateContext(window: *const SDL_Window) -> SDL_GLContext; + pub fn SDL_GL_MakeCurrent(window: *const SDL_Window, context: SDL_GLContext) -> c_int; + pub fn SDL_GL_GetCurrentWindow() -> *const SDL_Window; + pub fn SDL_GL_GetCurrentContext() -> SDL_GLContext; + pub fn SDL_GL_SetSwapInterval(interval: c_int) -> c_int; + pub fn SDL_GL_GetSwapInterval() -> c_int; + pub fn SDL_GL_SwapWindow(window: *const SDL_Window); + pub fn SDL_GL_DeleteContext(context: SDL_GLContext); +} diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 1ba77366..06c48444 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -13,117 +13,7 @@ use get_error; use rwops::RWops; use SdlResult; - -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_uint, c_void, uint8_t, uint32_t}; - use libc::{uint16_t, c_double, c_char}; - use rwops::ll::SDL_RWops; - - // assume LSB - pub type SDL_AudioFormat = uint16_t; - pub const AUDIO_U8 : SDL_AudioFormat = 0x0008; - pub const AUDIO_S8 : SDL_AudioFormat = 0x8008; - pub const AUDIO_U16LSB : SDL_AudioFormat = 0x0010; - pub const AUDIO_S16LSB : SDL_AudioFormat = 0x8010; - pub const AUDIO_U16MSB : SDL_AudioFormat = 0x1010; - pub const AUDIO_S16MSB : SDL_AudioFormat = 0x9010; - pub const AUDIO_U16 : SDL_AudioFormat = AUDIO_U16LSB; - pub const AUDIO_S16 : SDL_AudioFormat = AUDIO_S16LSB; - pub const AUDIO_S32LSB : SDL_AudioFormat = 0x8020; - pub const AUDIO_S32MSB : SDL_AudioFormat = 0x9020; - pub const AUDIO_S32 : SDL_AudioFormat = AUDIO_S32LSB; - pub const AUDIO_F32LSB : SDL_AudioFormat = 0x8120; - pub const AUDIO_F32MSB : SDL_AudioFormat = 0x9120; - pub const AUDIO_F32 : SDL_AudioFormat = AUDIO_F32LSB; - pub const AUDIO_U16SYS : SDL_AudioFormat = AUDIO_U16LSB; - pub const AUDIO_S16SYS : SDL_AudioFormat = AUDIO_S16LSB; - pub const AUDIO_S32SYS : SDL_AudioFormat = AUDIO_S32LSB; - pub const AUDIO_F32SYS : SDL_AudioFormat = AUDIO_F32LSB; - - pub type SDL_AudioCallback = - ::std::option::Option; - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_AudioSpec { - pub freq: c_int, - pub format: SDL_AudioFormat, - pub channels: uint8_t, - pub silence: uint8_t, - pub samples: uint16_t, - pub padding: uint16_t, - pub size: uint32_t, - pub callback: SDL_AudioCallback, - pub userdata: *const c_void, - } - pub type SDL_AudioFilter = - ::std::option::Option; - #[allow(dead_code, missing_copy_implementations)] - #[repr(C)] - pub struct SDL_AudioCVT { - pub needed: c_int, - pub src_format: SDL_AudioFormat, - pub dst_format: SDL_AudioFormat, - pub rate_incr: c_double, - pub buf: *mut uint8_t, - pub len: c_int, - pub len_cvt: c_int, - pub len_mult: c_int, - pub len_ratio: c_double, - filters: [SDL_AudioFilter, ..10u], - filter_index: c_int, - } - pub type SDL_AudioDeviceID = uint32_t; - pub type SDL_AudioStatus = c_uint; - pub const SDL_AUDIO_STOPPED: c_uint = 0; - pub const SDL_AUDIO_PLAYING: c_uint = 1; - pub const SDL_AUDIO_PAUSED: c_uint = 2; - extern "C" { - pub fn SDL_GetNumAudioDrivers() -> c_int; - pub fn SDL_GetAudioDriver(index: c_int) -> *const c_char; - pub fn SDL_AudioInit(driver_name: *const c_char) -> c_int; - pub fn SDL_AudioQuit(); - pub fn SDL_GetCurrentAudioDriver() -> *const c_char; - pub fn SDL_OpenAudio(desired: *const SDL_AudioSpec, - obtained: *const SDL_AudioSpec) -> c_int; - pub fn SDL_GetNumAudioDevices(iscapture: c_int) -> c_int; - pub fn SDL_GetAudioDeviceName(index: c_int, iscapture: c_int) -> *const c_char; - pub fn SDL_OpenAudioDevice(device: *const c_char, iscapture: c_int, - desired: *const SDL_AudioSpec, - obtained: *mut SDL_AudioSpec, - allowed_changes: c_int) -> SDL_AudioDeviceID; - pub fn SDL_GetAudioStatus() -> SDL_AudioStatus; - pub fn SDL_GetAudioDeviceStatus(dev: SDL_AudioDeviceID) -> - SDL_AudioStatus; - pub fn SDL_PauseAudio(pause_on: c_int); - pub fn SDL_PauseAudioDevice(dev: SDL_AudioDeviceID, pause_on: c_int); - pub fn SDL_LoadWAV_RW(src: *const SDL_RWops, freesrc: c_int, - spec: *mut SDL_AudioSpec, - audio_buf: *mut *mut uint8_t, audio_len: *mut uint32_t) -> *mut SDL_AudioSpec; - pub fn SDL_FreeWAV(audio_buf: *mut uint8_t); - pub fn SDL_BuildAudioCVT(cvt: *mut SDL_AudioCVT, - src_format: SDL_AudioFormat, src_channels: uint8_t, - src_rate: c_int, dst_format: SDL_AudioFormat, - dst_channels: uint8_t, dst_rate: c_int) -> c_int; - pub fn SDL_ConvertAudio(cvt: *mut SDL_AudioCVT) -> c_int; - pub fn SDL_MixAudio(dst: *const uint8_t, src: *const uint8_t, len: uint32_t, - volume: c_int); - pub fn SDL_MixAudioFormat(dst: *const uint8_t, src: *const uint8_t, - format: SDL_AudioFormat, len: uint32_t, - volume: c_int); - pub fn SDL_LockAudio(); - pub fn SDL_LockAudioDevice(dev: SDL_AudioDeviceID); - pub fn SDL_UnlockAudio(); - pub fn SDL_UnlockAudioDevice(dev: SDL_AudioDeviceID); - pub fn SDL_CloseAudio(); - pub fn SDL_CloseAudioDevice(dev: SDL_AudioDeviceID); - } - -} +pub use sys::audio as ll; pub type AudioFormat = ll::SDL_AudioFormat; diff --git a/src/sdl2/clipboard.rs b/src/sdl2/clipboard.rs index 930e3d40..e9b0a9e2 100644 --- a/src/sdl2/clipboard.rs +++ b/src/sdl2/clipboard.rs @@ -1,18 +1,7 @@ use SdlResult; use get_error; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_char}; - - pub type SDL_bool = c_int; - - extern "C" { - pub fn SDL_SetClipboardText(text: *const c_char) -> c_int; - pub fn SDL_GetClipboardText() -> *const c_char; - pub fn SDL_HasClipboardText() -> SDL_bool; - } -} +pub use sys::clipboard as ll; pub fn set_clipboard_text(text: &String) -> SdlResult<()> { unsafe { diff --git a/src/sdl2/controller.rs b/src/sdl2/controller.rs index 92ece79f..b9205979 100644 --- a/src/sdl2/controller.rs +++ b/src/sdl2/controller.rs @@ -1,133 +1,6 @@ use libc::c_int; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_char, c_uchar, c_uint, c_void, int16_t, uint8_t}; - use joystick::ll::{SDL_Joystick, SDL_JoystickGUID}; - - pub type SDL_bool = c_int; - - pub type SDL_GameController = c_void; - - pub type SDL_GameControllerBindType = c_uint; - pub const SDL_CONTROLLER_BINDTYPE_NONE: SDL_GameControllerBindType = 0; - pub const SDL_CONTROLLER_BINDTYPE_BUTTON: SDL_GameControllerBindType = 1; - pub const SDL_CONTROLLER_BINDTYPE_AXIS: SDL_GameControllerBindType = 2; - pub const SDL_CONTROLLER_BINDTYPE_HAT: SDL_GameControllerBindType = 3; - - #[allow(dead_code, non_snake_case)] - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_GameControllerButtonBind { - bindType: SDL_GameControllerBindType, - value: SDL_GameControllerButtonBindData, - } - - #[allow(dead_code)] - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_GameControllerButtonBindData { - data: [c_uchar, ..8u], - } - - #[allow(dead_code)] - #[deriving(Copy, Clone)] - pub struct SDL_GameControllerButtonBindDataHat { - hat: c_int, - hat_mask: c_int, - } - - impl SDL_GameControllerButtonBindData { - pub fn button(&self) -> *const c_int { - self.data.as_ptr() as *const _ - } - pub fn axis(&self) -> *const c_int { - self.data.as_ptr() as *const _ - } - pub fn hat(&self) -> *const SDL_GameControllerButtonBindDataHat { - self.data.as_ptr() as *const _ - } - } - - pub type SDL_GameControllerAxis = c_int; - pub const SDL_CONTROLLER_AXIS_INVALID: SDL_GameControllerAxis = -1; - pub const SDL_CONTROLLER_AXIS_LEFTX: SDL_GameControllerAxis = 0; - pub const SDL_CONTROLLER_AXIS_LEFTY: SDL_GameControllerAxis = 1; - pub const SDL_CONTROLLER_AXIS_RIGHTX: SDL_GameControllerAxis = 2; - pub const SDL_CONTROLLER_AXIS_RIGHTY: SDL_GameControllerAxis = 3; - pub const SDL_CONTROLLER_AXIS_TRIGGERLEFT: SDL_GameControllerAxis = 4; - pub const SDL_CONTROLLER_AXIS_TRIGGERRIGHT: SDL_GameControllerAxis = 5; - pub const SDL_CONTROLLER_AXIS_MAX: SDL_GameControllerAxis = 6; - - pub type SDL_GameControllerButton = c_int; - pub const SDL_CONTROLLER_BUTTON_INVALID: SDL_GameControllerButton = -1; - pub const SDL_CONTROLLER_BUTTON_A: SDL_GameControllerButton = 0; - pub const SDL_CONTROLLER_BUTTON_B: SDL_GameControllerButton = 1; - pub const SDL_CONTROLLER_BUTTON_X: SDL_GameControllerButton = 2; - pub const SDL_CONTROLLER_BUTTON_Y: SDL_GameControllerButton = 3; - pub const SDL_CONTROLLER_BUTTON_BACK: SDL_GameControllerButton = 4; - pub const SDL_CONTROLLER_BUTTON_GUIDE: SDL_GameControllerButton = 5; - pub const SDL_CONTROLLER_BUTTON_START: SDL_GameControllerButton = 6; - pub const SDL_CONTROLLER_BUTTON_LEFTSTICK: SDL_GameControllerButton = 7; - pub const SDL_CONTROLLER_BUTTON_RIGHTSTICK: SDL_GameControllerButton = 8; - pub const SDL_CONTROLLER_BUTTON_LEFTSHOULDER: SDL_GameControllerButton = 9; - pub const SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: SDL_GameControllerButton = 10; - pub const SDL_CONTROLLER_BUTTON_DPAD_UP: SDL_GameControllerButton = 11; - pub const SDL_CONTROLLER_BUTTON_DPAD_DOWN: SDL_GameControllerButton = 12; - pub const SDL_CONTROLLER_BUTTON_DPAD_LEFT: SDL_GameControllerButton = 13; - pub const SDL_CONTROLLER_BUTTON_DPAD_RIGHT: SDL_GameControllerButton = 14; - pub const SDL_CONTROLLER_BUTTON_MAX: SDL_GameControllerButton = 15; - - extern "C" { - pub fn SDL_GameControllerAddMapping(mappingString: *const c_char) -> c_int; - pub fn SDL_GameControllerMappingForGUID(guid: SDL_JoystickGUID) -> - *const c_char; - pub fn SDL_GameControllerMapping(gamecontroller: *const SDL_GameController) - -> *const c_char; - pub fn SDL_IsGameController(joystick_index: c_int) -> SDL_bool; - pub fn SDL_GameControllerNameForIndex(joystick_index: c_int) -> - *const c_char; - pub fn SDL_GameControllerOpen(joystick_index: c_int) -> - *const SDL_GameController; - pub fn SDL_GameControllerName(gamecontroller: *const SDL_GameController) -> - *const c_char; - pub fn SDL_GameControllerGetAttached(gamecontroller: - *const SDL_GameController) -> - SDL_bool; - pub fn SDL_GameControllerGetJoystick(gamecontroller: - *const SDL_GameController) -> - *const SDL_Joystick; - pub fn SDL_GameControllerEventState(state: c_int) -> c_int; - pub fn SDL_GameControllerUpdate(); - pub fn SDL_GameControllerGetAxisFromString(pchString: *const c_char) -> - SDL_GameControllerAxis; - pub fn SDL_GameControllerGetStringForAxis(axis: - SDL_GameControllerAxis) - -> *const c_char; - pub fn SDL_GameControllerGetBindForAxis(gamecontroller: - *const SDL_GameController, - axis: SDL_GameControllerAxis) - -> SDL_GameControllerButtonBind; - pub fn SDL_GameControllerGetAxis(gamecontroller: *const SDL_GameController, - axis: SDL_GameControllerAxis) -> - int16_t; - pub fn SDL_GameControllerGetButtonFromString(pchString: *const c_char) -> - SDL_GameControllerButton; - pub fn SDL_GameControllerGetStringForButton(button: - SDL_GameControllerButton) - -> *const c_char; - pub fn SDL_GameControllerGetBindForButton(gamecontroller: - *const SDL_GameController, - button: - SDL_GameControllerButton) - -> SDL_GameControllerButtonBind; - pub fn SDL_GameControllerGetButton(gamecontroller: - *const SDL_GameController, - button: SDL_GameControllerButton) - -> uint8_t; - pub fn SDL_GameControllerClose(gamecontroller: *const SDL_GameController); - } -} +pub use sys::controller as ll; #[deriving(Copy, Clone, PartialEq)] #[repr(i32)] diff --git a/src/sdl2/cpuinfo.rs b/src/sdl2/cpuinfo.rs index bc58fb9e..a5937d00 100644 --- a/src/sdl2/cpuinfo.rs +++ b/src/sdl2/cpuinfo.rs @@ -1,26 +1,4 @@ -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int}; - - pub type SDL_bool = c_int; - - // SDL_cpuinfo.h - extern "C" { - pub fn SDL_GetCPUCount() -> c_int; - pub fn SDL_GetCPUCacheLineSize() -> c_int; - pub fn SDL_HasRDTSC() -> SDL_bool; - pub fn SDL_HasAltiVec() -> SDL_bool; - pub fn SDL_HasMMX() -> SDL_bool; - pub fn SDL_Has3DNow() -> SDL_bool; - pub fn SDL_HasSSE() -> SDL_bool; - pub fn SDL_HasSSE2() -> SDL_bool; - pub fn SDL_HasSSE3() -> SDL_bool; - pub fn SDL_HasSSE41() -> SDL_bool; - pub fn SDL_HasSSE42() -> SDL_bool; - pub fn SDL_HasAVX() -> SDL_bool; - pub fn SDL_GetSystemRAM() -> c_int; - } -} +pub use sys::cpuinfo as ll; pub const CACHELINESIZE: int = 128; diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index 0f5c80cc..5dabd0f6 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -23,477 +23,7 @@ use video; use get_error; use SdlResult; -#[doc(hidden)] -#[allow(non_camel_case_types, non_snake_case)] -pub mod ll { - use libc::{c_float, c_int, c_char, c_uint, c_void, int16_t, - int32_t, uint8_t, uint16_t, uint32_t}; - use gesture::ll::SDL_GestureID; - use keyboard::ll::SDL_Keysym; - use touch::ll::SDL_FingerID; - use touch::ll::SDL_TouchID; - - pub type SDL_bool = c_int; - - // SDL_events.h - pub type SDL_EventState = uint8_t; - pub const SDL_DISABLE: SDL_EventState = 0; - pub const SDL_ENABLE: SDL_EventState = 1; - pub const SDL_QUERY: SDL_EventState = -1; - - pub type SDL_SysWMmsg = c_void; - - pub type SDL_EventType = c_uint; - pub const SDL_FIRSTEVENT: SDL_EventType = 0; - pub const SDL_QUIT: SDL_EventType = 256; - pub const SDL_APP_TERMINATING: SDL_EventType = 257; - pub const SDL_APP_LOWMEMORY: SDL_EventType = 258; - pub const SDL_APP_WILLENTERBACKGROUND: SDL_EventType = 259; - pub const SDL_APP_DIDENTERBACKGROUND: SDL_EventType = 260; - pub const SDL_APP_WILLENTERFOREGROUND: SDL_EventType = 261; - pub const SDL_APP_DIDENTERFOREGROUND: SDL_EventType = 262; - pub const SDL_WINDOWEVENT: SDL_EventType = 512; - pub const SDL_SYSWMEVENT: SDL_EventType = 513; - pub const SDL_KEYDOWN: SDL_EventType = 768; - pub const SDL_KEYUP: SDL_EventType = 769; - pub const SDL_TEXTEDITING: SDL_EventType = 770; - pub const SDL_TEXTINPUT: SDL_EventType = 771; - pub const SDL_MOUSEMOTION: SDL_EventType = 1024; - pub const SDL_MOUSEBUTTONDOWN: SDL_EventType = 1025; - pub const SDL_MOUSEBUTTONUP: SDL_EventType = 1026; - pub const SDL_MOUSEWHEEL: SDL_EventType = 1027; - pub const SDL_JOYAXISMOTION: SDL_EventType = 1536; - pub const SDL_JOYBALLMOTION: SDL_EventType = 1537; - pub const SDL_JOYHATMOTION: SDL_EventType = 1538; - pub const SDL_JOYBUTTONDOWN: SDL_EventType = 1539; - pub const SDL_JOYBUTTONUP: SDL_EventType = 1540; - pub const SDL_JOYDEVICEADDED: SDL_EventType = 1541; - pub const SDL_JOYDEVICEREMOVED: SDL_EventType = 1542; - pub const SDL_CONTROLLERAXISMOTION: SDL_EventType = 1616; - pub const SDL_CONTROLLERBUTTONDOWN: SDL_EventType = 1617; - pub const SDL_CONTROLLERBUTTONUP: SDL_EventType = 1618; - pub const SDL_CONTROLLERDEVICEADDED: SDL_EventType = 1619; - pub const SDL_CONTROLLERDEVICEREMOVED: SDL_EventType = 1620; - pub const SDL_CONTROLLERDEVICEREMAPPED: SDL_EventType = 1621; - pub const SDL_FINGERDOWN: SDL_EventType = 1792; - pub const SDL_FINGERUP: SDL_EventType = 1793; - pub const SDL_FINGERMOTION: SDL_EventType = 1794; - pub const SDL_DOLLARGESTURE: SDL_EventType = 2048; - pub const SDL_DOLLARRECORD: SDL_EventType = 2049; - pub const SDL_MULTIGESTURE: SDL_EventType = 2050; - pub const SDL_CLIPBOARDUPDATE: SDL_EventType = 2304; - pub const SDL_DROPFILE: SDL_EventType = 4096; - pub const SDL_USEREVENT: SDL_EventType = 32768; - pub const SDL_LASTEVENT: SDL_EventType = 65535; - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_CommonEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_WindowEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub event: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - pub padding3: uint8_t, - pub data1: int32_t, - pub data2: int32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_KeyboardEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub state: uint8_t, - pub repeat: uint8_t, - pub padding2: uint8_t, - pub padding3: uint8_t, - pub keysym: SDL_Keysym, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_TextEditingEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub text: [c_char, ..32u], - pub start: int32_t, - pub length: int32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_TextInputEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub text: [c_char, ..32u], - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_MouseMotionEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub which: uint32_t, - pub state: uint32_t, - pub x: int32_t, - pub y: int32_t, - pub xrel: int32_t, - pub yrel: int32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_MouseButtonEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub which: uint32_t, - pub button: uint8_t, - pub state: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - pub x: int32_t, - pub y: int32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_MouseWheelEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub which: uint32_t, - pub x: int32_t, - pub y: int32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_JoyAxisEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - pub axis: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - pub padding3: uint8_t, - pub value: int16_t, - pub padding4: uint16_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_JoyBallEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - pub ball: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - pub padding3: uint8_t, - pub xrel: int16_t, - pub yrel: int16_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_JoyHatEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - pub hat: uint8_t, - pub value: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_JoyButtonEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - pub button: uint8_t, - pub state: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_JoyDeviceEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_ControllerAxisEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - pub axis: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - pub padding3: uint8_t, - pub value: int16_t, - pub padding4: uint16_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_ControllerButtonEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - pub button: uint8_t, - pub state: uint8_t, - pub padding1: uint8_t, - pub padding2: uint8_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_ControllerDeviceEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub which: int32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_TouchFingerEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub touchId: SDL_TouchID, - pub fingerId: SDL_FingerID, - pub x: c_float, - pub y: c_float, - pub dx: c_float, - pub dy: c_float, - pub pressure: c_float, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_MultiGestureEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub touchId: SDL_TouchID, - pub dTheta: c_float, - pub dDist: c_float, - pub x: c_float, - pub y: c_float, - pub numFingers: uint16_t, - pub padding: uint16_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_DollarGestureEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub touchId: SDL_TouchID, - pub gestureId: SDL_GestureID, - pub numFingers: uint32_t, - pub error: c_float, - pub x: c_float, - pub y: c_float, - } - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_DropEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub file: *const c_char, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_QuitEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_OSEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - } - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_UserEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub windowID: uint32_t, - pub code: int32_t, - pub data1: *const c_void, - pub data2: *const c_void, - } - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_SysWMEvent { - pub _type: uint32_t, - pub timestamp: uint32_t, - pub msg: *const SDL_SysWMmsg, - } - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_Event { - pub data: [uint8_t, ..56u], - } - - impl SDL_Event { - pub fn _type(&self) -> *const uint32_t { - self.data.as_ptr() as *const _ - } - - pub fn common(&self) -> *const SDL_CommonEvent { - self.data.as_ptr() as *const _ - } - - pub fn window(&self) -> *const SDL_WindowEvent { - self.data.as_ptr() as *const _ - } - - pub fn key(&self) -> *const SDL_KeyboardEvent { - self.data.as_ptr() as *const _ - } - - pub fn edit(&self) -> *const SDL_TextEditingEvent { - self.data.as_ptr() as *const _ - } - - pub fn text(&self) -> *const SDL_TextInputEvent { - self.data.as_ptr() as *const _ - } - - pub fn motion(&self) -> *const SDL_MouseMotionEvent { - self.data.as_ptr() as *const _ - } - - pub fn button(&self) -> *const SDL_MouseButtonEvent { - self.data.as_ptr() as *const _ - } - - pub fn wheel(&self) -> *const SDL_MouseWheelEvent { - self.data.as_ptr() as *const _ - } - - pub fn jaxis(&self) -> *const SDL_JoyAxisEvent { - self.data.as_ptr() as *const _ - } - - pub fn jball(&self) -> *const SDL_JoyBallEvent { - self.data.as_ptr() as *const _ - } - - pub fn jhat(&self) -> *const SDL_JoyHatEvent { - self.data.as_ptr() as *const _ - } - - pub fn jbutton(&self) -> *const SDL_JoyButtonEvent { - self.data.as_ptr() as *const _ - } - - pub fn jdevice(&self) -> *const SDL_JoyDeviceEvent { - self.data.as_ptr() as *const _ - } - - pub fn caxis(&self) -> *const SDL_ControllerAxisEvent { - self.data.as_ptr() as *const _ - } - - pub fn cbutton(&self) -> *const SDL_ControllerButtonEvent { - self.data.as_ptr() as *const _ - } - - pub fn cdevice(&self) -> *const SDL_ControllerDeviceEvent { - self.data.as_ptr() as *const _ - } - - pub fn quit(&self) -> *const SDL_QuitEvent { - self.data.as_ptr() as *const _ - } - - pub fn user(&self) -> *const SDL_UserEvent { - self.data.as_ptr() as *const _ - } - - pub fn syswm(&self) -> *const SDL_SysWMEvent { - self.data.as_ptr() as *const _ - } - - pub fn tfinger(&self) -> *const SDL_TouchFingerEvent { - self.data.as_ptr() as *const _ - } - - pub fn mgesture(&self) -> *const SDL_MultiGestureEvent { - self.data.as_ptr() as *const _ - } - - pub fn dgesture(&self) -> *const SDL_DollarGestureEvent { - self.data.as_ptr() as *const _ - } - - pub fn drop(&self) -> *const SDL_DropEvent { - self.data.as_ptr() as *const _ - } - } - - pub type SDL_eventaction = c_uint; - pub const SDL_ADDEVENT: SDL_eventaction = 0; - pub const SDL_PEEKEVENT: SDL_eventaction = 1; - pub const SDL_GETEVENT: SDL_eventaction = 2; - pub type SDL_EventFilter = - extern "C" fn(userdata: *const c_void, event: *const SDL_Event) -> c_int; - - extern "C" { - pub fn SDL_free(mem: *const c_void); - pub fn SDL_PumpEvents(); - /*pub fn SDL_PeepEvents(events: &[SDL_Event], numevents: c_int, - action: SDL_eventaction, minType: uint32_t, - maxType: uint32_t) -> c_int;*/ - pub fn SDL_HasEvent(_type: uint32_t) -> SDL_bool; - pub fn SDL_HasEvents(minType: uint32_t, maxType: uint32_t) -> - SDL_bool; - pub fn SDL_FlushEvent(_type: uint32_t); - pub fn SDL_FlushEvents(minType: uint32_t, maxType: uint32_t); - pub fn SDL_PollEvent(event: *const SDL_Event) -> c_int; - pub fn SDL_WaitEvent(event: *const SDL_Event) -> c_int; - pub fn SDL_WaitEventTimeout(event: *const SDL_Event, timeout: c_int) -> - c_int; - pub fn SDL_PushEvent(event: *const SDL_Event) -> c_int; - pub fn SDL_SetEventFilter(filter: SDL_EventFilter, - userdata: *const c_void); - /*pub fn SDL_GetEventFilter(filter: *SDL_EventFilter, - userdata: **c_void) -> SDL_bool;*/ - pub fn SDL_AddEventWatch(filter: SDL_EventFilter, userdata: *const c_void); - pub fn SDL_DelEventWatch(filter: SDL_EventFilter, userdata: *const c_void); - pub fn SDL_FilterEvents(filter: SDL_EventFilter, userdata: *const c_void); - pub fn SDL_EventState(_type: uint32_t, state: SDL_EventState) -> SDL_EventState; - pub fn SDL_RegisterEvents(numevents: c_int) -> uint32_t; - } -} +pub use sys::event as ll; /// Types of events that can be delivered. #[deriving(Copy, Clone, FromPrimitive)] diff --git a/src/sdl2/filesystem.rs b/src/sdl2/filesystem.rs index a6f89f81..61218cf1 100644 --- a/src/sdl2/filesystem.rs +++ b/src/sdl2/filesystem.rs @@ -1,15 +1,7 @@ use SdlResult; use get_error; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_char}; - - extern "C" { - pub fn SDL_GetBasePath() -> *const c_char; - pub fn SDL_GetPrefPath(arg: *const c_char, app: *const c_char) -> *const c_char; - } -} +pub use sys::filesystem as ll; pub fn get_base_path() -> SdlResult { let result = unsafe { diff --git a/src/sdl2/gesture.rs b/src/sdl2/gesture.rs index 391246c0..3b15f5ce 100644 --- a/src/sdl2/gesture.rs +++ b/src/sdl2/gesture.rs @@ -1,18 +1 @@ - -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, int64_t}; - use rwops::ll::SDL_RWops; - use touch::ll::SDL_TouchID; - - pub type SDL_GestureID = int64_t; - - - extern "C" { - pub fn SDL_RecordGesture(touchId: SDL_TouchID) -> c_int; - pub fn SDL_SaveAllDollarTemplates(src: *const SDL_RWops) -> c_int; - pub fn SDL_SaveDollarTemplate(gestureId: SDL_GestureID, src: *const SDL_RWops) -> c_int; - pub fn SDL_LoadDollarTemplates(touchId: SDL_TouchID, src: *const SDL_RWops) -> c_int; - } -} - +pub use sys::gesture as ll; diff --git a/src/sdl2/haptic.rs b/src/sdl2/haptic.rs index 863c121e..9d58fdfc 100644 --- a/src/sdl2/haptic.rs +++ b/src/sdl2/haptic.rs @@ -1,198 +1,2 @@ //! Haptic Functions - -#[allow(non_camel_case_types)] -pub mod ll { - use joystick::ll::SDL_Joystick; - use libc::{c_int, c_uint, c_char, c_float, c_void, int16_t, int32_t, uint8_t, uint16_t, uint32_t}; - - pub const SDL_HAPTIC_CONSTANT: uint16_t = 1 << 0; - pub const SDL_HAPTIC_SINE: uint16_t = 1 << 1; - pub const SDL_HAPTIC_LEFTRIGHT: uint16_t = 1 << 2; - pub const SDL_HAPTIC_TRIANGLE: uint16_t = 1 << 3; - pub const SDL_HAPTIC_SAWTOOTHUP: uint16_t = 1 << 4; - pub const SDL_HAPTIC_SAWTOOTHDOWN: uint16_t = 1 << 5; - pub const SDL_HAPTIC_RAMP: uint16_t = 1 << 6; - pub const SDL_HAPTIC_SPRING: uint16_t = 1 << 7; - pub const SDL_HAPTIC_DAMPER: uint16_t = 1 << 8; - pub const SDL_HAPTIC_INERTIA: uint16_t = 1 << 9; - pub const SDL_HAPTIC_FRICTION: uint16_t = 1 << 10; - pub const SDL_HAPTIC_CUSTOM: uint16_t = 1 << 11; - pub const SDL_HAPTIC_GAIN: uint16_t = 1 << 12; - pub const SDL_HAPTIC_AUTOCENTER: uint16_t = 1 << 13; - pub const SDL_HAPTIC_STATUS: uint16_t = 1 << 14; - pub const SDL_HAPTIC_PAUSE: uint16_t = 1 << 15; - - pub type SDL_Haptic = c_void; - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_HapticDirection { - pub _type: uint8_t, - pub dir: [int32_t, ..3], - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_HapticConstant { - pub _type: uint16_t, - pub direction: SDL_HapticDirection, - pub length: uint32_t, - pub delay: uint16_t, - pub button: uint16_t, - pub interval: uint16_t, - pub level: int16_t, - pub attack_length: uint16_t, - pub attack_level: uint16_t, - pub fade_length: uint16_t, - pub fade_level: uint16_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_HapticPeriodic { - pub _type: uint16_t, - pub direction: SDL_HapticDirection, - pub length: uint32_t, - pub delay: uint16_t, - pub button: uint16_t, - pub interval: uint16_t, - pub period: uint16_t, - pub magnitude: int16_t, - pub offset: int16_t, - pub phase: uint16_t, - pub attack_length: uint16_t, - pub attack_level: uint16_t, - pub fade_length: uint16_t, - pub fade_level: uint16_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_HapticCondition { - pub _type: uint16_t, - pub direction: SDL_HapticDirection, - pub length: uint32_t, - pub delay: uint16_t, - pub button: uint16_t, - pub interval: uint16_t, - pub right_sat: [uint16_t, ..3], - pub left_sat: [uint16_t, ..3], - pub right_coeff: [int16_t, ..3], - pub left_coeff: [int16_t, ..3], - pub deadband: [uint16_t, ..3], - pub center: [int16_t, ..3], - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_HapticRamp { - pub _type: uint16_t, - pub length: uint32_t, - pub delay: uint16_t, - pub button: uint16_t, - pub interval: uint16_t, - pub start: int16_t, - pub end: int16_t, - pub attack_length: uint16_t, - pub attack_level: uint16_t, - pub fade_length: uint16_t, - pub fade_level: uint16_t, - } - - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_HapticLeftRight { - pub _type: uint16_t, - pub length: uint32_t, - pub large_magnitude: uint16_t, - pub small_magnitude: uint16_t, - } - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_HapticCustom { - pub _type: uint16_t, - pub direction: SDL_HapticDirection, - pub length: uint32_t, - pub delay: uint16_t, - pub button: uint16_t, - pub interval: uint16_t, - pub channels: uint8_t, - pub period: uint16_t, - pub samples: uint16_t, - pub data: *const uint16_t, - pub attack_length: uint16_t, - pub attack_level: uint16_t, - pub fade_length: uint16_t, - pub fade_level: uint16_t, - } - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_HapticEffect { - pub data: [uint8_t, ..72u], - } - - impl SDL_HapticEffect { - pub fn _type(&self) -> *const uint16_t { - self.data.as_ptr() as *const _ - } - - pub fn constant(&self) -> *const SDL_HapticConstant { - self.data.as_ptr() as *const _ - } - - pub fn periodic(&self) -> *const SDL_HapticPeriodic { - self.data.as_ptr() as *const _ - } - - pub fn condition(&self) -> *const SDL_HapticCondition { - self.data.as_ptr() as *const _ - } - - pub fn ramp(&self) -> *const SDL_HapticRamp { - self.data.as_ptr() as *const _ - } - - pub fn left_right(&self) -> *const SDL_HapticLeftRight { - self.data.as_ptr() as *const _ - } - - pub fn custom(&self) -> *const SDL_HapticCustom { - self.data.as_ptr() as *const _ - } - } - - extern "C" { - pub fn SDL_NumHaptics() -> c_int; - pub fn SDL_HapticName(device_index: c_int) -> *const c_char; - pub fn SDL_HapticOpen(device_index: c_int) -> *const SDL_Haptic; - pub fn SDL_HapticOpened(device_index: c_int) -> c_int; - pub fn SDL_HapticIndex(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_MouseIsHaptic() -> c_int; - pub fn SDL_HapticOpenFromMouse() -> *const SDL_Haptic; - pub fn SDL_JoystickIsHaptic(joystick: *const SDL_Joystick) -> c_int; - pub fn SDL_HapticOpenFromJoystick(joystick: *const SDL_Joystick) -> *const SDL_Haptic; - pub fn SDL_HapticClose(haptic: *const SDL_Haptic); - pub fn SDL_HapticNumEffects(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticNumEffectsPlaying(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticQuery(haptic: *const SDL_Haptic) -> c_uint; - pub fn SDL_HapticNumAxes(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticEffectSupported(haptic: *const SDL_Haptic, effect: *const SDL_HapticEffect) -> c_int; - pub fn SDL_HapticNewEffect(haptic: *const SDL_Haptic, effect: *const SDL_HapticEffect) -> c_int; - pub fn SDL_HapticUpdateEffect(haptic: *const SDL_Haptic, effect: *const SDL_HapticEffect) -> c_int; - pub fn SDL_HapticRunEffect(haptic: *const SDL_Haptic, effect: c_int, iterations: uint32_t) -> c_int; - pub fn SDL_HapticStopEffect(haptic: *const SDL_Haptic, effect: c_int) -> c_int; - pub fn SDL_HapticDestroyEffect(haptic: *const SDL_Haptic, effect: c_int); - pub fn SDL_HapticGetEffectStatus(haptic: *const SDL_Haptic, effect: c_int) -> c_int; - pub fn SDL_HapticSetGain(haptic: *const SDL_Haptic, gain: c_int) -> c_int; - pub fn SDL_HapticSetAutocenter(haptic: *const SDL_Haptic, autocenter: c_int) -> c_int; - pub fn SDL_HapticPause(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticUnpause(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticStopAll(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticRumbleSupported(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticRumbleInit(haptic: *const SDL_Haptic) -> c_int; - pub fn SDL_HapticRumblePlay(haptic: *const SDL_Haptic, strength: c_float, length: uint32_t) -> c_int; - pub fn SDL_HapticRumbleStop(haptic: *const SDL_Haptic) -> c_int; - } -} +pub use sys::haptic as ll; diff --git a/src/sdl2/joystick.rs b/src/sdl2/joystick.rs index 4495c5e4..0d8173d6 100644 --- a/src/sdl2/joystick.rs +++ b/src/sdl2/joystick.rs @@ -1,50 +1,4 @@ -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_char, c_void, int32_t, int16_t, int8_t, uint8_t}; - - pub type SDL_bool = c_int; - - pub type SDL_Joystick = c_void; - - #[allow(dead_code)] - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_JoystickGUID { - pub data: [uint8_t, ..16u], - } - - extern "C" { - pub fn SDL_NumJoysticks() -> c_int; - pub fn SDL_JoystickNameForIndex(device_index: c_int) -> *const c_char; - pub fn SDL_JoystickOpen(device_index: c_int) -> *const SDL_Joystick; - pub fn SDL_JoystickName(joystick: *const SDL_Joystick) -> *const c_char; - pub fn SDL_JoystickGetDeviceGUID(device_index: c_int) -> - SDL_JoystickGUID; - pub fn SDL_JoystickGetGUID(joystick: *const SDL_Joystick) -> - SDL_JoystickGUID; - pub fn SDL_JoystickGetGUIDString(guid: SDL_JoystickGUID, - pszGUID: *const c_char, cbGUID: c_int); - pub fn SDL_JoystickGetGUIDFromString(pchGUID: *const c_char) -> - SDL_JoystickGUID; - pub fn SDL_JoystickGetAttached(joystick: *const SDL_Joystick) -> SDL_bool; - pub fn SDL_JoystickInstanceID(joystick: *const SDL_Joystick) -> int32_t; - pub fn SDL_JoystickNumAxes(joystick: *const SDL_Joystick) -> c_int; - pub fn SDL_JoystickNumBalls(joystick: *const SDL_Joystick) -> c_int; - pub fn SDL_JoystickNumHats(joystick: *const SDL_Joystick) -> c_int; - pub fn SDL_JoystickNumButtons(joystick: *const SDL_Joystick) -> c_int; - pub fn SDL_JoystickUpdate(); - pub fn SDL_JoystickEventState(state: c_int) -> c_int; - pub fn SDL_JoystickGetAxis(joystick: *const SDL_Joystick, axis: c_int) -> - int16_t; - pub fn SDL_JoystickGetHat(joystick: *const SDL_Joystick, hat: c_int) -> - int8_t; - pub fn SDL_JoystickGetBall(joystick: *const SDL_Joystick, ball: c_int, - dx: *const c_int, dy: *const c_int) -> c_int; - pub fn SDL_JoystickGetButton(joystick: *const SDL_Joystick, button: c_int) - -> uint8_t; - pub fn SDL_JoystickClose(joystick: *const SDL_Joystick); - } -} +pub use sys::joystick as ll; bitflags! { flags HatState: u8 { diff --git a/src/sdl2/keyboard.rs b/src/sdl2/keyboard.rs index 1e65eb94..e9b968f7 100644 --- a/src/sdl2/keyboard.rs +++ b/src/sdl2/keyboard.rs @@ -7,47 +7,7 @@ use rect::Rect; use scancode::ScanCode; use video::Window; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_char, c_uint, int32_t, uint8_t, uint16_t, - uint32_t}; - use rect::Rect; - use video::ll::SDL_Window; - - pub type SDL_bool = c_int; - pub type SDL_Rect = Rect; - pub type SDL_Keycode = int32_t; - pub type SDL_Keymod = c_uint; - pub type SDL_Scancode = c_uint; - - // SDL_keyboard.h - #[deriving(Copy, Clone)] - pub struct SDL_Keysym { - pub scancode: SDL_Scancode, - pub sym: SDL_Keycode, - pub _mod: uint16_t, - pub unused: uint32_t, - } - - extern "C" { - pub fn SDL_GetKeyboardFocus() -> *const SDL_Window; - pub fn SDL_GetKeyboardState(numkeys: *const c_int) -> *const uint8_t; - pub fn SDL_GetModState() -> SDL_Keymod; - pub fn SDL_SetModState(modstate: SDL_Keymod); - pub fn SDL_GetKeyFromScancode(scancode: SDL_Scancode) -> SDL_Keycode; - pub fn SDL_GetScancodeFromKey(key: SDL_Keycode) -> SDL_Scancode; - pub fn SDL_GetScancodeName(scancode: SDL_Scancode) -> *const c_char; - pub fn SDL_GetScancodeFromName(name: *const c_char) -> SDL_Scancode; - pub fn SDL_GetKeyName(key: SDL_Keycode) -> *const c_char; - pub fn SDL_GetKeyFromName(name: *const c_char) -> SDL_Keycode; - pub fn SDL_StartTextInput(); - pub fn SDL_IsTextInputActive() -> SDL_bool; - pub fn SDL_StopTextInput(); - pub fn SDL_SetTextInputRect(rect: *const SDL_Rect); - pub fn SDL_HasScreenKeyboardSupport() -> SDL_bool; - pub fn SDL_IsScreenKeyboardShown(window: *const SDL_Window) -> SDL_bool; - } -} +pub use sys::keyboard as ll; bitflags! { flags Mod: u32 { diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 3dc22d41..bf384e68 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -5,6 +5,7 @@ extern crate libc; extern crate collections; +extern crate "sdl2-sys" as sys; pub use sdl::*; diff --git a/src/sdl2/messagebox.rs b/src/sdl2/messagebox.rs index c643205d..0c7afb1e 100644 --- a/src/sdl2/messagebox.rs +++ b/src/sdl2/messagebox.rs @@ -4,20 +4,7 @@ use video::Window; use get_error; use SdlResult; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_char, uint32_t}; - use video::ll::SDL_Window; - - pub type SDL_MessageBoxFlags = u32; - pub const SDL_MESSAGEBOX_ERROR : SDL_MessageBoxFlags = 0x00000010; - pub const SDL_MESSAGEBOX_WARNING : SDL_MessageBoxFlags = 0x00000020; - pub const SDL_MESSAGEBOX_INFORMATION : SDL_MessageBoxFlags = 0x00000040; - - extern "C" { - pub fn SDL_ShowSimpleMessageBox(flags: uint32_t, title: *const c_char, message: *const c_char, window: *const SDL_Window) -> c_int; - } -} +pub use sys::messagebox as ll; bitflags! { flags MessageBoxFlag: u32 { diff --git a/src/sdl2/mouse.rs b/src/sdl2/mouse.rs index db9f8944..0c6129f5 100644 --- a/src/sdl2/mouse.rs +++ b/src/sdl2/mouse.rs @@ -5,55 +5,7 @@ use SdlResult; use surface; use video; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_uint, c_void, uint8_t, uint32_t}; - use surface::ll::SDL_Surface; - use video::ll::SDL_Window; - - pub type SDL_bool = c_int; - pub type SDL_Cursor = c_void; - - pub type SDL_SystemCursor = c_uint; - pub const SDL_SYSTEM_CURSOR_ARROW: SDL_SystemCursor = 0; - pub const SDL_SYSTEM_CURSOR_IBEAM: SDL_SystemCursor = 1; - pub const SDL_SYSTEM_CURSOR_WAIT: SDL_SystemCursor = 2; - pub const SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_SystemCursor = 3; - pub const SDL_SYSTEM_CURSOR_WAITARROW: SDL_SystemCursor = 4; - pub const SDL_SYSTEM_CURSOR_SIZENWSE: SDL_SystemCursor = 5; - pub const SDL_SYSTEM_CURSOR_SIZENESW: SDL_SystemCursor = 6; - pub const SDL_SYSTEM_CURSOR_SIZEWE: SDL_SystemCursor = 7; - pub const SDL_SYSTEM_CURSOR_SIZENS: SDL_SystemCursor = 8; - pub const SDL_SYSTEM_CURSOR_SIZEALL: SDL_SystemCursor = 9; - pub const SDL_SYSTEM_CURSOR_NO: SDL_SystemCursor = 10; - pub const SDL_SYSTEM_CURSOR_HAND: SDL_SystemCursor = 11; - pub const SDL_NUM_SYSTEM_CURSORS: SDL_SystemCursor = 12; - - pub type SDL_MouseState = c_int; - pub const SDL_DISABLE: SDL_MouseState = 0; - pub const SDL_ENABLE: SDL_MouseState = 1; - pub const SDL_QUERY: SDL_MouseState = -1; - - extern "C" { - pub fn SDL_GetMouseFocus() -> *const SDL_Window; - pub fn SDL_GetMouseState(x: *const c_int, y: *const c_int) -> uint32_t; - pub fn SDL_GetRelativeMouseState(x: *const c_int, y: *const c_int) -> uint32_t; - pub fn SDL_WarpMouseInWindow(window: *const SDL_Window, x: c_int, y: c_int); - pub fn SDL_SetRelativeMouseMode(enabled: SDL_bool) -> c_int; - pub fn SDL_GetRelativeMouseMode() -> SDL_bool; - pub fn SDL_CreateCursor(data: *const uint8_t, mask: *const uint8_t, w: c_int, - h: c_int, hot_x: c_int, hot_y: c_int) -> - *const SDL_Cursor; - pub fn SDL_CreateColorCursor(surface: *const SDL_Surface, hot_x: c_int, - hot_y: c_int) -> *const SDL_Cursor; - pub fn SDL_CreateSystemCursor(id: SDL_SystemCursor) -> *const SDL_Cursor; - pub fn SDL_SetCursor(cursor: *const SDL_Cursor); - pub fn SDL_GetCursor() -> *const SDL_Cursor; - pub fn SDL_GetDefaultCursor() -> *const SDL_Cursor; - pub fn SDL_FreeCursor(cursor: *const SDL_Cursor); - pub fn SDL_ShowCursor(toggle: SDL_MouseState) -> SDL_MouseState; - } -} +pub use sys::mouse as ll; #[deriving(Copy, Clone, PartialEq)] #[repr(u32)] diff --git a/src/sdl2/pixels.rs b/src/sdl2/pixels.rs index 7f29de95..4d195ae1 100644 --- a/src/sdl2/pixels.rs +++ b/src/sdl2/pixels.rs @@ -1,97 +1,7 @@ extern crate rand; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, uint8_t, uint32_t}; +pub use sys::pixels as ll; - //SDL_pixels.h - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_Color { - pub r: uint8_t, - pub g: uint8_t, - pub b: uint8_t, - pub a: uint8_t, - } - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_Palette { - pub ncolors: c_int, - pub colors: *const SDL_Color, - pub version: uint32_t, - pub refcount: c_int - } - - #[allow(non_snake_case, missing_copy_implementations)] - #[repr(C)] - pub struct SDL_PixelFormat { - pub format: SDL_PixelFormatFlag, - pub palette: *const SDL_Palette, - pub BitsPerPixel: uint8_t, - pub BytesPerPixel: uint8_t, - pub padding: [uint8_t, ..2], - pub Rmask: uint8_t, - pub Gmask: uint8_t, - pub Bmask: uint8_t, - pub Amask: uint8_t, - pub Rloss: uint8_t, - pub Gloss: uint8_t, - pub Bloss: uint8_t, - pub Aloss: uint8_t, - pub Rshift: uint8_t, - pub Gshift: uint8_t, - pub Bshift: uint8_t, - pub Ashift: uint8_t, - pub refcount: c_int, - pub next: *const SDL_PixelFormat - } - - pub type SDL_PixelFormatFlag = uint32_t; - pub const SDL_PIXELFORMAT_UNKNOWN: SDL_PixelFormatFlag = 0x0; - pub const SDL_PIXELFORMAT_INDEX1LSB: SDL_PixelFormatFlag = 0x11100100; - pub const SDL_PIXELFORMAT_INDEX1MSB: SDL_PixelFormatFlag = 0x11200100; - pub const SDL_PIXELFORMAT_INDEX4LSB: SDL_PixelFormatFlag = 0x12100400; - pub const SDL_PIXELFORMAT_INDEX4MSB: SDL_PixelFormatFlag = 0x12200400; - pub const SDL_PIXELFORMAT_INDEX8: SDL_PixelFormatFlag = 0x13000801; - pub const SDL_PIXELFORMAT_RGB332: SDL_PixelFormatFlag = 0x14110801; - pub const SDL_PIXELFORMAT_RGB444: SDL_PixelFormatFlag = 0x15120c02; - pub const SDL_PIXELFORMAT_RGB555: SDL_PixelFormatFlag = 0x15130f02; - pub const SDL_PIXELFORMAT_BGR555: SDL_PixelFormatFlag = 0x15530f02; - pub const SDL_PIXELFORMAT_ARGB4444: SDL_PixelFormatFlag = 0x15321002; - pub const SDL_PIXELFORMAT_RGBA4444: SDL_PixelFormatFlag = 0x15421002; - pub const SDL_PIXELFORMAT_ABGR4444: SDL_PixelFormatFlag = 0x15721002; - pub const SDL_PIXELFORMAT_BGRA4444: SDL_PixelFormatFlag = 0x15821002; - pub const SDL_PIXELFORMAT_ARGB1555: SDL_PixelFormatFlag = 0x15331002; - pub const SDL_PIXELFORMAT_RGBA5551: SDL_PixelFormatFlag = 0x15441002; - pub const SDL_PIXELFORMAT_ABGR1555: SDL_PixelFormatFlag = 0x15731002; - pub const SDL_PIXELFORMAT_BGRA5551: SDL_PixelFormatFlag = 0x15841002; - pub const SDL_PIXELFORMAT_RGB565: SDL_PixelFormatFlag = 0x15151002; - pub const SDL_PIXELFORMAT_BGR565: SDL_PixelFormatFlag = 0x15551002; - pub const SDL_PIXELFORMAT_RGB24: SDL_PixelFormatFlag = 0x17101803; - pub const SDL_PIXELFORMAT_BGR24: SDL_PixelFormatFlag = 0x17401803; - pub const SDL_PIXELFORMAT_RGB888: SDL_PixelFormatFlag = 0x16161804; - pub const SDL_PIXELFORMAT_RGBX8888: SDL_PixelFormatFlag = 0x16261804; - pub const SDL_PIXELFORMAT_BGR888: SDL_PixelFormatFlag = 0x16561804; - pub const SDL_PIXELFORMAT_BGRX8888: SDL_PixelFormatFlag = 0x16661804; - pub const SDL_PIXELFORMAT_ARGB8888: SDL_PixelFormatFlag = 0x16362004; - pub const SDL_PIXELFORMAT_RGBA8888: SDL_PixelFormatFlag = 0x16462004; - pub const SDL_PIXELFORMAT_ABGR8888: SDL_PixelFormatFlag = 0x16762004; - pub const SDL_PIXELFORMAT_BGRA8888: SDL_PixelFormatFlag = 0x16862004; - pub const SDL_PIXELFORMAT_ARGB2101010: SDL_PixelFormatFlag = 0x16372004; - pub const SDL_PIXELFORMAT_YV12: SDL_PixelFormatFlag = 0x32315659; - pub const SDL_PIXELFORMAT_IYUV: SDL_PixelFormatFlag = 0x56555949; - pub const SDL_PIXELFORMAT_YUY2: SDL_PixelFormatFlag = 0x32595559; - pub const SDL_PIXELFORMAT_UYVY: SDL_PixelFormatFlag = 0x59565955; - pub const SDL_PIXELFORMAT_YVYU: SDL_PixelFormatFlag = 0x55595659; - - extern "C" { - pub fn SDL_GetRGB(pixel: uint32_t, format: *const SDL_PixelFormat, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t); - pub fn SDL_GetRGBA(pixel: uint32_t, format: *const SDL_PixelFormat, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t, a: *const uint8_t); - pub fn SDL_MapRGB(format: *const SDL_PixelFormat, r: uint8_t, g: uint8_t, b: uint8_t) -> uint32_t; - pub fn SDL_MapRGBA(format: *const SDL_PixelFormat, r: uint8_t, g: uint8_t, b: uint8_t, a: uint8_t) -> uint32_t; - } -} #[deriving(PartialEq)] #[allow(raw_pointer_deriving, missing_copy_implementations)] pub struct Palette { raw: *const ll::SDL_Palette diff --git a/src/sdl2/rect.rs b/src/sdl2/rect.rs index 64c55c06..4307a29a 100644 --- a/src/sdl2/rect.rs +++ b/src/sdl2/rect.rs @@ -1,142 +1,4 @@ -/*! -Rectangle Functions - */ - -use std::mem; -use libc::c_int; - -/// A structure that defines a two dimensional point. -#[deriving(PartialEq, Clone, Show, Copy)] -#[repr(C)] -pub struct Point { - pub x: i32, - pub y: i32 -} - -/// A structure that defines a rectangle, with the origin at the upper left. -#[deriving(PartialEq, Clone, Show, Copy)] -#[repr(C)] -pub struct Rect { - pub x: i32, - pub y: i32, - pub w: i32, - pub h: i32 -} - -#[doc(hidden)] -#[allow(non_camel_case_types)] -pub mod ll { - - use libc::c_int; - use super::Rect; - use super::Point; - - pub type SDL_Rect = Rect; - pub type SDL_Point = Point; - pub type SDL_bool = c_int; - - extern "C" { - pub fn SDL_HasIntersection(A: *const SDL_Rect, B: *const SDL_Rect) -> SDL_bool; - pub fn SDL_IntersectRect(A: *const SDL_Rect, B: *const SDL_Rect, result: *const SDL_Rect) -> SDL_bool; - pub fn SDL_UnionRect(A: *const SDL_Rect, B: *const SDL_Rect, result: *const SDL_Rect); - pub fn SDL_EnclosePoints(points: *const SDL_Point, count: c_int, clip: *const SDL_Rect, result: *const SDL_Rect) -> SDL_bool; - pub fn SDL_IntersectRectAndLine(rect: *const SDL_Rect, X1: *const c_int, Y1: *const c_int, X2: *const c_int, Y2: *const c_int) -> SDL_bool; - } -} - -impl Point { - pub fn new(x: i32, y: i32) -> Point { - Point { - x: x, - y: y - } - } -} - -impl Rect { - pub fn new(x: i32, y: i32, w: i32, h: i32) -> Rect { - Rect { - x: x, - y: y, - w: w, - h: h - } - } - - /// Calculate a minimal rectangle enclosing a set of points. - pub fn from_enclose_points(points: &[Point], clip: Option) -> Option { - let out: Rect = Rect::new(0, 0, 0, 0); - - let result = unsafe { - ll::SDL_EnclosePoints( - points.as_ptr(), - points.len() as c_int, - mem::transmute(clip.as_ref()), - &out - ) != 0 - }; - - if result { - Some(out) - } else { - None - } - } - - /// Check whether a rectangle has no area. - pub fn is_empty(&self) -> bool { - (self.w <= 0) || (self.h <= 0) - } - - /// Determine whether two rectangles intersect. - pub fn has_intersection(&self, other: &Rect) -> bool { - unsafe { - ll::SDL_HasIntersection(self, other) != 0 - } - } - - /// Calculate the intersection of two rectangles. - pub fn intersection(&self, other: &Rect) -> Option { - let out: Rect = Rect::new(0, 0, 0, 0); - - let result = unsafe { - ll::SDL_IntersectRect(self, other, &out) != 0 - }; - - if result { - Some(out) - } else { - None - } - } - - /// Calculate the union of two rectangles. - pub fn union(&self, other: &Rect) -> Rect { - let out: Rect = Rect::new(0, 0, 0, 0); - - unsafe { - ll::SDL_UnionRect(self, other, &out) - }; - - out - } - - /// Calculate the intersection of a rectangle and line segment. return points of intersection. - pub fn intersect_line(&self, start: &Point, end: &Point) -> Option<(Point, Point)> { - let out_start: Point = start.clone(); - let out_end: Point = end.clone(); - - let result = unsafe { - ll::SDL_IntersectRectAndLine(self, &out_start.x, &out_start.y, &out_end.x, &out_end.y) != 0 - }; - - if result { - Some((out_start, out_end)) - } else { - None - } - } -} +pub use sys::rect::*; #[cfg(test)] mod test { diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 6378b199..dedad6a4 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -15,124 +15,7 @@ use std::vec::Vec; use std::c_vec::CVec; use std::borrow::ToOwned; -#[allow(non_camel_case_types)] -pub mod ll { - - use libc::{c_int, c_uint, c_char, c_void, c_float, c_double}; - use libc::{uint8_t, uint32_t}; - use rect::Rect; - use rect::Point; - - use surface::ll::SDL_Surface; - use video::ll::SDL_Window; - - pub type SDL_Rect = Rect; - pub type SDL_Point = Point; - pub type SDL_bool = c_int; - - //SDL_render.h - pub type SDL_RendererFlags = c_uint; - pub const SDL_RENDERER_SOFTWARE : SDL_RendererFlags = 0x00000001; - pub const SDL_RENDERER_ACCELERATED : SDL_RendererFlags = 0x00000002; - pub const SDL_RENDERER_PRESENTVSYNC : SDL_RendererFlags = 0x00000004; - pub const SDL_RENDERER_TARGETTEXTURE : SDL_RendererFlags = 0x00000008; - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_RendererInfo - { - pub name: *const c_char, - pub flags: uint32_t, - pub num_texture_formats: uint32_t, - pub texture_formats: [uint32_t, ..16], - pub max_texture_width: c_int, - pub max_texture_height: c_int, - } - - pub type SDL_TextureAccess = c_uint; - pub const SDL_TEXTUREACCESS_STATIC : SDL_TextureAccess = 0; - pub const SDL_TEXTUREACCESS_STREAMING : SDL_TextureAccess = 1; - pub const SDL_TEXTUREACCESS_TARGET : SDL_TextureAccess = 2; - - pub type SDL_TextureModulate = c_uint; - pub const SDL_TEXTUREMODULATE_NONE : SDL_TextureModulate = 0x00000000; - pub const SDL_TEXTUREMODULATE_COLOR : SDL_TextureModulate = 0x00000001; - pub const SDL_TEXTUREMODULATE_ALPHA : SDL_TextureModulate = 0x00000002; - - pub type SDL_RendererFlip = c_uint; - pub const SDL_FLIP_NONE : SDL_RendererFlip = 0x00000000; - pub const SDL_FLIP_HORIZONTAL : SDL_RendererFlip = 0x00000001; - pub const SDL_FLIP_VERTICAL : SDL_RendererFlip = 0x00000002; - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_Renderer; - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_Texture; - - //SDL_blendmode.h - pub type SDL_BlendMode = c_uint; - pub const SDL_BLENDMODE_NONE : SDL_BlendMode = 0x00000000; - pub const SDL_BLENDMODE_BLEND : SDL_BlendMode = 0x00000001; - pub const SDL_BLENDMODE_ADD : SDL_BlendMode = 0x00000002; - pub const SDL_BLENDMODE_MOD : SDL_BlendMode = 0x00000004; - - extern "C" { - pub fn SDL_GetNumRenderDrivers() -> c_int; - pub fn SDL_GetRenderDriverInfo(index: c_int, info: *const SDL_RendererInfo) -> c_int; - pub fn SDL_CreateWindowAndRenderer(width: c_int, height: c_int, window_flags: uint32_t, window: *const *const SDL_Window, renderer: *const *const SDL_Renderer) -> c_int; - pub fn SDL_CreateRenderer(window: *const SDL_Window, index: c_int, flags: uint32_t) -> *const SDL_Renderer; - pub fn SDL_CreateSoftwareRenderer(surface: *const SDL_Surface) -> *const SDL_Renderer; - pub fn SDL_GetRenderer(window: *const SDL_Window) -> *const SDL_Renderer; - pub fn SDL_GetRendererInfo(renderer: *const SDL_Renderer, info: *const SDL_RendererInfo) -> c_int; - pub fn SDL_GetRendererOutputSize(renderer: *const SDL_Renderer, w: *const c_int, h: *const c_int) -> c_int; - pub fn SDL_CreateTexture(renderer: *const SDL_Renderer, format: uint32_t, access: c_int, w: c_int, h: c_int) -> *const SDL_Texture; - pub fn SDL_CreateTextureFromSurface(renderer: *const SDL_Renderer, surface: *const SDL_Surface) -> *const SDL_Texture; - pub fn SDL_QueryTexture(texture: *const SDL_Texture, format: *const uint32_t, access: *const c_int, w: *const c_int, h: *const c_int) -> c_int; - pub fn SDL_SetTextureColorMod(texture: *const SDL_Texture, r: uint8_t, g: uint8_t, b: uint8_t) -> c_int; - pub fn SDL_GetTextureColorMod(texture: *const SDL_Texture, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t) -> c_int; - pub fn SDL_SetTextureAlphaMod(texture: *const SDL_Texture, alpha: uint8_t) -> c_int; - pub fn SDL_GetTextureAlphaMod(texture: *const SDL_Texture, alpha: *const uint8_t) -> c_int; - pub fn SDL_SetTextureBlendMode(texture: *const SDL_Texture, blendMode: SDL_BlendMode) -> c_int; - pub fn SDL_GetTextureBlendMode(texture: *const SDL_Texture, blendMode: *const SDL_BlendMode) -> c_int; - pub fn SDL_UpdateTexture(texture: *const SDL_Texture, rect: *const SDL_Rect, pixels: *const c_void, pitch: c_int) -> c_int; - pub fn SDL_LockTexture(texture: *const SDL_Texture, rect: *const SDL_Rect, pixels: *const *const c_void, pitch: *const c_int) -> c_int; - pub fn SDL_UnlockTexture(texture: *const SDL_Texture); - pub fn SDL_RenderTargetSupported(renderer: *const SDL_Renderer) -> SDL_bool; - pub fn SDL_SetRenderTarget(renderer: *const SDL_Renderer, texture: *const SDL_Texture) -> c_int; - pub fn SDL_GetRenderTarget(renderer: *const SDL_Renderer) -> *const SDL_Texture; - pub fn SDL_RenderSetLogicalSize(renderer: *const SDL_Renderer, w: c_int, h: c_int) -> c_int; - pub fn SDL_RenderGetLogicalSize(renderer: *const SDL_Renderer, w: *const c_int, h: *const c_int); - pub fn SDL_RenderSetViewport(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; - pub fn SDL_RenderGetViewport(renderer: *const SDL_Renderer, rect: *const SDL_Rect); - pub fn SDL_RenderSetClipRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; - pub fn SDL_RenderGetClipRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect); - pub fn SDL_RenderSetScale(renderer: *const SDL_Renderer, scaleX: c_float, scaleY: c_float) -> c_int; - pub fn SDL_RenderGetScale(renderer: *const SDL_Renderer, scaleX: *const c_float, scaleY: *const c_float); - pub fn SDL_SetRenderDrawColor(renderer: *const SDL_Renderer, r: uint8_t, g: uint8_t, b: uint8_t, a: uint8_t) -> c_int; - pub fn SDL_GetRenderDrawColor(renderer: *const SDL_Renderer, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t, a: *const uint8_t) -> c_int; - pub fn SDL_SetRenderDrawBlendMode(renderer: *const SDL_Renderer, blendMode: SDL_BlendMode) -> c_int; - pub fn SDL_GetRenderDrawBlendMode(renderer: *const SDL_Renderer, blendMode: *const SDL_BlendMode) -> c_int; - pub fn SDL_RenderClear(renderer: *const SDL_Renderer) -> c_int; - pub fn SDL_RenderDrawPoint(renderer: *const SDL_Renderer, x: c_int, y: c_int) -> c_int; - pub fn SDL_RenderDrawPoints(renderer: *const SDL_Renderer, Points: *const SDL_Point, count: c_int) -> c_int; - pub fn SDL_RenderDrawLine(renderer: *const SDL_Renderer, x1: c_int, y1: c_int, x2: c_int, y2: c_int) -> c_int; - pub fn SDL_RenderDrawLines(renderer: *const SDL_Renderer, Points: *const SDL_Point, count: c_int) -> c_int; - pub fn SDL_RenderDrawRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; - pub fn SDL_RenderDrawRects(renderer: *const SDL_Renderer, rects: *const SDL_Rect, count: c_int) -> c_int; - pub fn SDL_RenderFillRect(renderer: *const SDL_Renderer, rect: *const SDL_Rect) -> c_int; - pub fn SDL_RenderFillRects(renderer: *const SDL_Renderer, rects: *const SDL_Rect, count: c_int) -> c_int; - pub fn SDL_RenderCopy(renderer: *const SDL_Renderer, texture: *const SDL_Texture, srcrect: *const SDL_Rect, dstrect: *const SDL_Rect) -> c_int; - pub fn SDL_RenderCopyEx(renderer: *const SDL_Renderer, texture: *const SDL_Texture, srcrect: *const SDL_Rect, dstrect: *const SDL_Rect, angle: c_double, center: *const SDL_Point, flip: SDL_RendererFlip) -> c_int; - pub fn SDL_RenderReadPixels(renderer: *const SDL_Renderer, rect: *const SDL_Rect, format: uint32_t, pixels: *mut c_void, pitch: c_int) -> c_int; - pub fn SDL_RenderPresent(renderer: *const SDL_Renderer); - pub fn SDL_DestroyTexture(texture: *const SDL_Texture); - pub fn SDL_DestroyRenderer(renderer: *const SDL_Renderer); - pub fn SDL_GL_BindTexture(texture: *const SDL_Texture, texw: *const c_float, texh: *const c_float) -> c_int; - pub fn SDL_GL_UnbindTexture(texture: *const SDL_Texture) -> c_int; - } -} +pub use sys::render as ll; #[deriving(Copy, Clone)] pub enum RenderDriverIndex { diff --git a/src/sdl2/rwops.rs b/src/sdl2/rwops.rs index 6d9fb606..5899b124 100644 --- a/src/sdl2/rwops.rs +++ b/src/sdl2/rwops.rs @@ -4,47 +4,7 @@ use libc::{c_void, c_int, size_t}; use get_error; use SdlResult; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_uchar, uint32_t, c_char, FILE, c_void}; - use libc::{c_int, int64_t, size_t}; - - #[allow(dead_code)] - #[repr(C)] - struct SDL_RWops_Anon { - data: [c_uchar, ..24], - } - - pub type SDL_bool = c_int; - - pub static RW_SEEK_SET: c_int = 0; - pub static RW_SEEK_CUR: c_int = 1; - pub static RW_SEEK_END: c_int = 2; - - #[allow(dead_code)] - #[repr(C)] - pub struct SDL_RWops { - pub size: extern "C" fn(context: *const SDL_RWops) -> int64_t, - pub seek: extern "C" fn(context: *const SDL_RWops, offset: int64_t, whence: c_int) -> int64_t, - pub read: extern "C" fn(context: *const SDL_RWops, ptr: *const c_void, - size: size_t, maxnum: size_t) -> size_t, - pub write: extern "C" fn(context: *const SDL_RWops, ptr: *const c_void, - size: size_t, maxnum: size_t) -> size_t, - pub close: extern "C" fn(context: *const SDL_RWops) -> c_int, - pub _type: uint32_t, - hidden: SDL_RWops_Anon - } - - extern "C" { - pub fn SDL_RWFromFile(file: *const c_char, mode: *const c_char) -> *const SDL_RWops; - pub fn SDL_RWFromFP(fp: *const FILE, autoclose: SDL_bool) -> *const SDL_RWops; - pub fn SDL_RWFromMem(mem: *const c_void, size: c_int) -> *const SDL_RWops; - pub fn SDL_RWFromConstMem(mem: *const c_void, size: c_int) -> *const SDL_RWops; - - pub fn SDL_AllocRW() -> *const SDL_RWops; - pub fn SDL_FreeRW(area: *const SDL_RWops); - } -} +pub use sys::rwops as ll; #[deriving(PartialEq)] #[allow(raw_pointer_deriving)] pub struct RWops { diff --git a/src/sdl2/sdl.rs b/src/sdl2/sdl.rs index 8f5ffe52..be1a5ef2 100644 --- a/src/sdl2/sdl.rs +++ b/src/sdl2/sdl.rs @@ -1,65 +1,7 @@ use std::c_str::CString; use std::borrow::ToOwned; -// Setup linking for all targets. -#[cfg(target_os="macos")] -mod mac { - #[cfg(mac_framework)] - #[link(kind="framework", name="SDL2")] - extern {} - - #[cfg(not(mac_framework))] - #[link(name="SDL2")] - extern {} -} - -#[cfg(any(target_os="windows", target_os="linux", target_os="freebsd"))] -mod others { - #[link(name="SDL2")] - extern {} -} - -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, c_uint, c_char, uint32_t}; - - pub type SDL_errorcode = c_uint; - pub const SDL_ENOMEM: SDL_errorcode = 0; - pub const SDL_EFREAD: SDL_errorcode = 1; - pub const SDL_EFWRITE: SDL_errorcode = 2; - pub const SDL_EFSEEK: SDL_errorcode = 3; - pub const SDL_UNSUPPORTED: SDL_errorcode = 4; - pub const SDL_LASTERROR: SDL_errorcode = 5; - - pub type SDL_InitFlag = uint32_t; - pub const SDL_INIT_TIMER: SDL_InitFlag = 0x00000001; - pub const SDL_INIT_AUDIO: SDL_InitFlag = 0x00000010; - pub const SDL_INIT_VIDEO: SDL_InitFlag = 0x00000020; - pub const SDL_INIT_JOYSTICK: SDL_InitFlag = 0x00000200; - pub const SDL_INIT_HAPTIC: SDL_InitFlag = 0x00001000; - pub const SDL_INIT_GAMECONTROLLER: SDL_InitFlag = 0x00002000; - pub const SDL_INIT_EVENTS: SDL_InitFlag = 0x00004000; - pub const SDL_INIT_NOPARACHUTE: SDL_InitFlag = 0x00100000; - pub const SDL_INIT_EVERYTHING: SDL_InitFlag = 0x0000FFFF; - - //SDL_error.h - extern "C" { - pub fn SDL_ClearError(); - pub fn SDL_Error(code: SDL_errorcode) -> c_int; - pub fn SDL_SetError(fmt: *const c_char) -> c_int; - pub fn SDL_GetError() -> *const c_char; - - //SDL.h - pub fn SDL_Init(flags: uint32_t) -> c_int; - pub fn SDL_InitSubSystem(flags: SDL_InitFlag) -> c_int; - pub fn SDL_QuitSubSystem(flags: SDL_InitFlag); - pub fn SDL_WasInit(flags: SDL_InitFlag) -> SDL_InitFlag; - pub fn SDL_Quit(); - - //SDL_timer.h - pub fn SDL_GetTicks() -> uint32_t; - } -} +use sys::sdl as ll; bitflags! { flags InitFlag: u32 { diff --git a/src/sdl2/surface.rs b/src/sdl2/surface.rs index 4ef63864..7eb05ee1 100644 --- a/src/sdl2/surface.rs +++ b/src/sdl2/surface.rs @@ -8,79 +8,7 @@ use pixels; use render::BlendMode; use rwops; -#[allow(non_camel_case_types)] -pub mod ll { - use pixels::ll::SDL_PixelFormat; - use pixels::ll::SDL_Palette; - use rwops::ll::SDL_RWops; - use rect::Rect; - use libc::{c_int, c_void, uint32_t, uint8_t}; - pub use render::ll::SDL_BlendMode; - - pub type SDL_Rect = Rect; - pub type SDL_bool = c_int; - - pub type SDL_SurfaceFlag = c_int; - - pub const SDL_SWSURFACE: SDL_SurfaceFlag = 0; - pub const SDL_PREALLOC: SDL_SurfaceFlag = 0x00000001; - pub const SDL_RLEACCEL: SDL_SurfaceFlag = 0x00000002; - pub const SDL_DONTFREE: SDL_SurfaceFlag = 0x00000004; - - //SDL_surface.h - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_BlitMap; - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_Surface { - pub flags: uint32_t, - pub format: *const SDL_PixelFormat, - pub w: c_int, - pub h: c_int, - pub pitch: c_int, - pub pixels: *const c_void, - pub userdata: *const c_void, - pub locked: c_int, - pub lock_data: *const c_void, - pub clip_rect: SDL_Rect, - pub map: *const SDL_BlitMap, - pub refcount: c_int - } - - extern "C" { - pub fn SDL_CreateRGBSurface(flags: uint32_t, width: c_int, height: c_int, depth: c_int, Rmask: uint32_t, Gmask: uint32_t, Bmask: uint32_t, Amask: uint32_t) -> *const SDL_Surface; - pub fn SDL_CreateRGBSurfaceFrom(pixels: *const c_void, width: c_int, height: c_int, depth: c_int, pitch: c_int, Rmask: uint32_t, Gmask: uint32_t, Bmask: uint32_t, Amask: uint32_t) -> *const SDL_Surface; - pub fn SDL_FreeSurface(surface: *const SDL_Surface); - pub fn SDL_SetSurfacePalette(surface: *const SDL_Surface, palette: *const SDL_Palette) -> c_int; - pub fn SDL_LockSurface(surface: *const SDL_Surface) -> c_int; - pub fn SDL_UnlockSurface(surface: *const SDL_Surface); - pub fn SDL_LoadBMP_RW(src: *const SDL_RWops, freesrc: c_int) -> *const SDL_Surface; - pub fn SDL_SaveBMP_RW(surface: *const SDL_Surface, dst: *const SDL_RWops, freedst: c_int) -> c_int; - pub fn SDL_SetSurfaceRLE(surface: *const SDL_Surface, flag: c_int) -> c_int; - pub fn SDL_SetColorKey(surface: *const SDL_Surface, flag: c_int, key: uint32_t) -> c_int; - pub fn SDL_GetColorKey(surface: *const SDL_Surface, key: *const uint32_t) -> c_int; - pub fn SDL_SetSurfaceColorMod(surface: *const SDL_Surface, r: uint8_t, g: uint8_t, b: uint8_t) -> c_int; - pub fn SDL_GetSurfaceColorMod(surface: *const SDL_Surface, r: *const uint8_t, g: *const uint8_t, b: *const uint8_t ) -> c_int; - pub fn SDL_SetSurfaceAlphaMod(surface: *const SDL_Surface, alpha: uint8_t) -> c_int; - pub fn SDL_GetSurfaceAlphaMod(surface: *const SDL_Surface, alpha: *const uint8_t ) -> c_int; - pub fn SDL_SetSurfaceBlendMode(surface: *const SDL_Surface, blendMode: SDL_BlendMode) -> c_int; - pub fn SDL_GetSurfaceBlendMode(surface: *const SDL_Surface, blendMode: *const SDL_BlendMode) -> c_int; - pub fn SDL_SetClipRect(surface: *const SDL_Surface, rect: *const SDL_Rect) -> SDL_bool; - pub fn SDL_GetClipRect(surface: *const SDL_Surface, rect: *const SDL_Rect); - pub fn SDL_ConvertSurface(src: *const SDL_Surface, fmt: *const SDL_PixelFormat, flags: uint32_t) -> *const SDL_Surface; - pub fn SDL_ConvertSurfaceFormat(src: *const SDL_Surface, pixel_format: uint32_t, flags: uint32_t) -> *const SDL_Surface; - pub fn SDL_ConvertPixels(width: c_int, height: c_int, src_format: uint32_t, src: *const c_void, src_pitch: c_int, dst_format: uint32_t, dst: *const c_void, dst_pitch: c_int) -> c_int; - pub fn SDL_FillRect(dst: *const SDL_Surface, rect: *const SDL_Rect, color: uint32_t) -> c_int; - pub fn SDL_FillRects(dst: *const SDL_Surface, rects: *const SDL_Rect, count: c_int, color: uint32_t) -> c_int; - pub fn SDL_UpperBlit(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; - pub fn SDL_LowerBlit(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; - pub fn SDL_SoftStretch(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; - pub fn SDL_UpperBlitScaled(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; - pub fn SDL_LowerBlitScaled(src: *const SDL_Surface, srcrect: *const SDL_Rect, dst: *const SDL_Surface, dstrect: *const SDL_Rect) -> c_int; - } -} +pub use sys::surface as ll; bitflags! { flags SurfaceFlag: u32 { diff --git a/src/sdl2/timer.rs b/src/sdl2/timer.rs index a84b54e5..63e3da37 100644 --- a/src/sdl2/timer.rs +++ b/src/sdl2/timer.rs @@ -3,26 +3,7 @@ use libc::{uint32_t, c_void}; use std::raw; use std::kinds::marker::ContravariantLifetime; -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{uint32_t, uint64_t, c_void, c_int}; - - //SDL_timer.h - pub type SDL_TimerCallback = - ::std::option::Option uint32_t>; - pub type SDL_TimerID = c_int; - extern "C" { - pub fn SDL_GetTicks() -> uint32_t; - pub fn SDL_GetPerformanceCounter() -> uint64_t; - pub fn SDL_GetPerformanceFrequency() -> uint64_t; - pub fn SDL_Delay(ms: uint32_t); - - pub fn SDL_AddTimer(interval: uint32_t, callback: SDL_TimerCallback, - param: *const c_void) -> SDL_TimerID; - pub fn SDL_RemoveTimer(id: SDL_TimerID) -> c_int; - } -} +pub use sys::timer as ll; pub fn get_ticks() -> uint { unsafe { ll::SDL_GetTicks() as uint } diff --git a/src/sdl2/touch.rs b/src/sdl2/touch.rs index 94c9f813..18167542 100644 --- a/src/sdl2/touch.rs +++ b/src/sdl2/touch.rs @@ -1,33 +1,9 @@ use std::ptr; -pub type TouchDevice = ll::SDL_TouchID; +pub use sys::touch as ll; -#[deriving(PartialEq, Copy)] -#[repr(C)] -pub struct Finger { - id: TouchDevice, - x: f32, - y: f32, - pressure: f32, -} - -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{c_int, int64_t}; - use touch::Finger; - - pub type SDL_TouchID = int64_t; - pub type SDL_FingerID = int64_t; - pub type SDL_Finger = Finger; - - extern "C" { - pub fn SDL_GetNumTouchDevices() -> c_int; - pub fn SDL_GetTouchDevice(index: c_int) -> SDL_TouchID; - pub fn SDL_GetNumTouchFingers(touchID: SDL_TouchID) -> c_int; - pub fn SDL_GetTouchFinger(touchID: SDL_TouchID, index: c_int) -> - *const SDL_Finger; - } -} +pub type Finger = ll::Finger; +pub type TouchDevice = ll::TouchDevice; pub fn get_num_touch_devices() -> int { unsafe { ll::SDL_GetNumTouchDevices() as int } diff --git a/src/sdl2/version.rs b/src/sdl2/version.rs index 91aa484b..47053d1d 100644 --- a/src/sdl2/version.rs +++ b/src/sdl2/version.rs @@ -6,23 +6,7 @@ use std::fmt; use std::c_str::CString; use std::borrow::ToOwned; -#[doc(hidden)] -#[allow(non_camel_case_types)] -pub mod ll { - use libc::{uint8_t, c_char, c_int}; - #[deriving(Copy, Clone)] - #[repr(C)] - pub struct SDL_version { - pub major: uint8_t, - pub minor: uint8_t, - pub patch: uint8_t, - } - extern "C" { - pub fn SDL_GetVersion(ver: *mut SDL_version); - pub fn SDL_GetRevision() -> *const c_char; - pub fn SDL_GetRevisionNumber() -> c_int; - } -} +pub use sys::version as ll; /// A structure that contains information about the version of SDL in use. #[deriving(PartialEq, Copy, Clone)] diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index c097d190..7562ed21 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -10,219 +10,41 @@ use std::num::FromPrimitive; use get_error; -#[allow(non_camel_case_types)] -pub mod ll { - use rect::Rect; - use surface::ll::SDL_Surface; - - use libc::{c_void, c_int, c_float, c_char, uint16_t, uint32_t}; - - pub type SDL_Rect = Rect; - pub type SDL_bool = c_int; - - //SDL_video.h - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_Window; - - #[allow(missing_copy_implementations)] - #[repr(C)] - pub struct SDL_DisplayMode { - pub format: uint32_t, - pub w: c_int, - pub h: c_int, - pub refresh_rate: c_int, - pub driverdata: *const c_void - } - - pub type SDL_WindowPos = c_int; - pub const SDL_WINDOWPOS_CENTERED: SDL_WindowPos = 0x2FFF0000; - pub const SDL_WINDOWPOS_UNDEFINED: SDL_WindowPos = 0x1FFF0000; - - #[deriving(Copy, Clone)] - pub enum SDL_WindowFlags { - SDL_WINDOW_FULLSCREEN = 0x00000001, - SDL_WINDOW_OPENGL = 0x00000002, - SDL_WINDOW_SHOWN = 0x00000004, - SDL_WINDOW_HIDDEN = 0x00000008, - SDL_WINDOW_BORDERLESS = 0x00000010, - SDL_WINDOW_RESIZABLE = 0x00000020, - SDL_WINDOW_MINIMIZED = 0x00000040, - SDL_WINDOW_MAXIMIZED = 0x00000080, - SDL_WINDOW_INPUT_GRABBED = 0x00000100, - SDL_WINDOW_INPUT_FOCUS = 0x00000200, - SDL_WINDOW_MOUSE_FOCUS = 0x00000400, - SDL_WINDOW_FULLSCREEN_DESKTOP = 0x00001001, - SDL_WINDOW_FOREIGN = 0x00000800, - SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000 - } - - #[deriving(Copy, Clone)] - pub enum SDL_WindowEventID { - SDL_WINDOWEVENT_NONE, - SDL_WINDOWEVENT_SHOWN, - SDL_WINDOWEVENT_HIDDEN, - SDL_WINDOWEVENT_EXPOSED, - SDL_WINDOWEVENT_MOVED, - SDL_WINDOWEVENT_RESIZED, - SDL_WINDOWEVENT_SIZE_CHANGED, - SDL_WINDOWEVENT_MINIMIZED, - SDL_WINDOWEVENT_MAXIMIZED, - SDL_WINDOWEVENT_RESTORED, - SDL_WINDOWEVENT_ENTER, - SDL_WINDOWEVENT_LEAVE, - SDL_WINDOWEVENT_FOCUS_GAINED, - SDL_WINDOWEVENT_FOCUS_LOST, - SDL_WINDOWEVENT_CLOSE - } - - pub type SDL_GLContext = *const c_void; - - #[deriving(Copy, Clone, FromPrimitive)] - #[repr(C)] - pub enum SDL_GLattr { - SDL_GL_RED_SIZE = 0, - SDL_GL_GREEN_SIZE = 1, - SDL_GL_BLUE_SIZE = 2, - SDL_GL_ALPHA_SIZE = 3, - SDL_GL_BUFFER_SIZE = 4, - SDL_GL_DOUBLEBUFFER = 5, - SDL_GL_DEPTH_SIZE = 6, - SDL_GL_STENCIL_SIZE = 7, - SDL_GL_ACCUM_RED_SIZE = 8, - SDL_GL_ACCUM_GREEN_SIZE = 9, - SDL_GL_ACCUM_BLUE_SIZE = 10, - SDL_GL_ACCUM_ALPHA_SIZE = 11, - SDL_GL_STEREO = 12, - SDL_GL_MULTISAMPLEBUFFERS = 13, - SDL_GL_MULTISAMPLESAMPLES = 14, - SDL_GL_ACCELERATED_VISUAL = 15, - SDL_GL_RETAINED_BACKING = 16, - SDL_GL_CONTEXT_MAJOR_VERSION = 17, - SDL_GL_CONTEXT_MINOR_VERSION = 18, - SDL_GL_CONTEXT_EGL = 19, - SDL_GL_CONTEXT_FLAGS = 20, - SDL_GL_CONTEXT_PROFILE_MASK = 21, - SDL_GL_SHARE_WITH_CURRENT_CONTEXT = 22, - SDL_GL_FRAMEBUFFER_SRGB_CAPABLE = 23 - } - - #[deriving(Copy, Clone)] - pub enum SDL_GLprofile { - SDL_GL_CONTEXT_PROFILE_CORE = 0x0001, - SDL_GL_CONTEXT_PROFILE_COMPATIBILITY = 0x0002, - SDL_GL_CONTEXT_PROFILE_ES = 0x0004 - } - - //SDL_video.h - extern "C" { - pub fn SDL_GetNumVideoDrivers() -> c_int; - pub fn SDL_GetVideoDriver(index: c_int) -> *const c_char; - pub fn SDL_VideoInit(driver_name: *const c_char) -> c_int; - pub fn SDL_VideoQuit(); - pub fn SDL_GetCurrentVideoDriver() -> *const c_char; - pub fn SDL_GetNumVideoDisplays() -> c_int; - pub fn SDL_GetDisplayName(displayIndex: c_int) -> *const c_char; - pub fn SDL_GetDisplayBounds(displayIndex: c_int, rect: *const SDL_Rect) -> c_int; - pub fn SDL_GetNumDisplayModes(displayIndex: c_int) -> c_int; - pub fn SDL_GetDisplayMode(displayIndex: c_int, modeIndex: c_int, mode: *const SDL_DisplayMode) -> c_int; - pub fn SDL_GetDesktopDisplayMode(displayIndex: c_int, mode: *const SDL_DisplayMode) -> c_int; - pub fn SDL_GetCurrentDisplayMode(displayIndex: c_int, mode: *const SDL_DisplayMode) -> c_int; - pub fn SDL_GetClosestDisplayMode(displayIndex: c_int, mode: *const SDL_DisplayMode, closest: *const SDL_DisplayMode) -> *const SDL_DisplayMode; - pub fn SDL_GetWindowDisplayIndex(window: *const SDL_Window) -> c_int; - pub fn SDL_SetWindowDisplayMode(window: *const SDL_Window, mode: *const SDL_DisplayMode) -> c_int; - pub fn SDL_GetWindowDisplayMode(window: *const SDL_Window, mode: *const SDL_DisplayMode) -> c_int; - pub fn SDL_GetWindowPixelFormat(window: *const SDL_Window) -> uint32_t; - pub fn SDL_CreateWindow(title: *const c_char, x: c_int, y: c_int, w: c_int, h: c_int, flags: uint32_t) -> *const SDL_Window; - pub fn SDL_CreateWindowFrom(data: *const c_void) -> *const SDL_Window; - pub fn SDL_GetWindowID(window: *const SDL_Window) -> uint32_t; - pub fn SDL_GetWindowFromID(id: uint32_t) -> *const SDL_Window; - pub fn SDL_GetWindowFlags(window: *const SDL_Window) -> uint32_t; - pub fn SDL_SetWindowTitle(window: *const SDL_Window, title: *const c_char); - pub fn SDL_GetWindowTitle(window: *const SDL_Window) -> *const c_char; - pub fn SDL_SetWindowIcon(window: *const SDL_Window, icon: *const SDL_Surface); - pub fn SDL_SetWindowData(window: *const SDL_Window, name: *const c_char, userdata: *const c_void) -> *const c_void; - pub fn SDL_GetWindowData(window: *const SDL_Window, name: *const c_char) -> *const c_void; - pub fn SDL_SetWindowPosition(window: *const SDL_Window, x: c_int, y: c_int); - pub fn SDL_GetWindowPosition(window: *const SDL_Window, x: *const c_int, y: *const c_int); - pub fn SDL_SetWindowSize(window: *const SDL_Window, w: c_int, h: c_int); - pub fn SDL_GetWindowSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); - pub fn SDL_SetWindowMinimumSize(window: *const SDL_Window, min_w: c_int, min_h: c_int); - pub fn SDL_GetWindowMinimumSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); - pub fn SDL_SetWindowMaximumSize(window: *const SDL_Window, max_w: c_int, max_h: c_int); - pub fn SDL_GetWindowMaximumSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); - pub fn SDL_SetWindowBordered(window: *const SDL_Window, bordered: SDL_bool); - pub fn SDL_ShowWindow(window: *const SDL_Window); - pub fn SDL_HideWindow(window: *const SDL_Window); - pub fn SDL_RaiseWindow(window: *const SDL_Window); - pub fn SDL_MaximizeWindow(window: *const SDL_Window); - pub fn SDL_MinimizeWindow(window: *const SDL_Window); - pub fn SDL_RestoreWindow(window: *const SDL_Window); - pub fn SDL_SetWindowFullscreen(window: *const SDL_Window, flags: uint32_t) -> c_int; - pub fn SDL_GetWindowSurface(window: *const SDL_Window) -> *const SDL_Surface; - pub fn SDL_UpdateWindowSurface(window: *const SDL_Window) -> c_int; - pub fn SDL_UpdateWindowSurfaceRects(window: *const SDL_Window, rects: *const SDL_Rect, numrects: c_int) -> c_int; - pub fn SDL_SetWindowGrab(window: *const SDL_Window, grabbed: SDL_bool); - pub fn SDL_GetWindowGrab(window: *const SDL_Window) -> SDL_bool; - pub fn SDL_SetWindowBrightness(window: *const SDL_Window, brightness: c_float) -> c_int; - pub fn SDL_GetWindowBrightness(window: *const SDL_Window) -> c_float; - pub fn SDL_SetWindowGammaRamp(window: *const SDL_Window, red: *const uint16_t, green: *const uint16_t, blue: *const uint16_t) -> c_int; - pub fn SDL_GetWindowGammaRamp(window: *const SDL_Window, red: *const uint16_t, green: *const uint16_t, blue: *const uint16_t) -> c_int; - pub fn SDL_DestroyWindow(window: *const SDL_Window); - pub fn SDL_IsScreenSaverEnabled() -> SDL_bool; - pub fn SDL_EnableScreenSaver(); - pub fn SDL_DisableScreenSaver(); - pub fn SDL_GL_GetDrawableSize(window: *const SDL_Window, w: *const c_int, h: *const c_int); - pub fn SDL_GL_LoadLibrary(path: *const c_char) -> c_int; - pub fn SDL_GL_GetProcAddress(procname: *const c_char) -> Option; - pub fn SDL_GL_UnloadLibrary(); - pub fn SDL_GL_ExtensionSupported(extension: *const c_char) -> SDL_bool; - pub fn SDL_GL_SetAttribute(attr: SDL_GLattr, value: c_int) -> c_int; - pub fn SDL_GL_GetAttribute(attr: SDL_GLattr, value: *const c_int) -> c_int; - pub fn SDL_GL_CreateContext(window: *const SDL_Window) -> SDL_GLContext; - pub fn SDL_GL_MakeCurrent(window: *const SDL_Window, context: SDL_GLContext) -> c_int; - pub fn SDL_GL_GetCurrentWindow() -> *const SDL_Window; - pub fn SDL_GL_GetCurrentContext() -> SDL_GLContext; - pub fn SDL_GL_SetSwapInterval(interval: c_int) -> c_int; - pub fn SDL_GL_GetSwapInterval() -> c_int; - pub fn SDL_GL_SwapWindow(window: *const SDL_Window); - pub fn SDL_GL_DeleteContext(context: SDL_GLContext); - } -} +pub use sys::video as ll; #[deriving(Copy, Clone, PartialEq)] pub enum GLAttr { - GLRedSize = ll::SDL_GLattr::SDL_GL_RED_SIZE as int, - GLGreenSize = ll::SDL_GLattr::SDL_GL_GREEN_SIZE as int, - GLBlueSize = ll::SDL_GLattr::SDL_GL_BLUE_SIZE as int, - GLAlphaSize = ll::SDL_GLattr::SDL_GL_ALPHA_SIZE as int, - GLBufferSize = ll::SDL_GLattr::SDL_GL_BUFFER_SIZE as int, - GLDoubleBuffer = ll::SDL_GLattr::SDL_GL_DOUBLEBUFFER as int, - GLDepthSize = ll::SDL_GLattr::SDL_GL_DEPTH_SIZE as int, - GLStencilSize = ll::SDL_GLattr::SDL_GL_STENCIL_SIZE as int, - GLAccumRedSize = ll::SDL_GLattr::SDL_GL_ACCUM_RED_SIZE as int, - GLAccumGreenSize = ll::SDL_GLattr::SDL_GL_ACCUM_GREEN_SIZE as int, - GLAccumBlueSize = ll::SDL_GLattr::SDL_GL_ACCUM_BLUE_SIZE as int, - GLAccumAlphaSize = ll::SDL_GLattr::SDL_GL_ACCUM_ALPHA_SIZE as int, - GLStereo = ll::SDL_GLattr::SDL_GL_STEREO as int, - GLMultiSampleBuffers = ll::SDL_GLattr::SDL_GL_MULTISAMPLEBUFFERS as int, - GLMultiSampleSamples = ll::SDL_GLattr::SDL_GL_MULTISAMPLESAMPLES as int, - GLAcceleratedVisual = ll::SDL_GLattr::SDL_GL_ACCELERATED_VISUAL as int, - GLRetailedBacking = ll::SDL_GLattr::SDL_GL_RETAINED_BACKING as int, - GLContextMajorVersion = ll::SDL_GLattr::SDL_GL_CONTEXT_MAJOR_VERSION as int, - GLContextMinorVersion = ll::SDL_GLattr::SDL_GL_CONTEXT_MINOR_VERSION as int, - GLContextEGL = ll::SDL_GLattr::SDL_GL_CONTEXT_EGL as int, - GLContextFlags = ll::SDL_GLattr::SDL_GL_CONTEXT_FLAGS as int, - GLContextProfileMask = ll::SDL_GLattr::SDL_GL_CONTEXT_PROFILE_MASK as int, - GLShareWithCurrentContext = ll::SDL_GLattr::SDL_GL_SHARE_WITH_CURRENT_CONTEXT as int, - GLFramebufferSRGBCapable = ll::SDL_GLattr::SDL_GL_FRAMEBUFFER_SRGB_CAPABLE as int + GLRedSize = 0, + GLGreenSize = 1, + GLBlueSize = 2, + GLAlphaSize = 3, + GLBufferSize = 4, + GLDoubleBuffer = 5, + GLDepthSize = 6, + GLStencilSize = 7, + GLAccumRedSize = 8, + GLAccumGreenSize = 9, + GLAccumBlueSize = 10, + GLAccumAlphaSize = 11, + GLStereo = 12, + GLMultiSampleBuffers = 13, + GLMultiSampleSamples = 14, + GLAcceleratedVisual = 15, + GLRetailedBacking = 16, + GLContextMajorVersion = 17, + GLContextMinorVersion = 18, + GLContextEGL = 19, + GLContextFlags = 20, + GLContextProfileMask = 21, + GLShareWithCurrentContext = 22, + GLFramebufferSRGBCapable = 23, } #[deriving(Copy, Clone, PartialEq)] pub enum GLProfile { - GLCoreProfile = ll::SDL_GLprofile::SDL_GL_CONTEXT_PROFILE_CORE as int, - GLCompatibilityProfile = ll::SDL_GLprofile::SDL_GL_CONTEXT_PROFILE_COMPATIBILITY as int, - GLESProfile = ll::SDL_GLprofile::SDL_GL_CONTEXT_PROFILE_ES as int + GLCoreProfile = 0x0001, + GLCompatibilityProfile = 0x0002, + GLESProfile = 0x0004, } @@ -298,8 +120,8 @@ bitflags! { #[deriving(Copy, Clone, PartialEq)] pub enum FullscreenType { FTOff = 0, - FTTrue = ll::SDL_WindowFlags::SDL_WINDOW_FULLSCREEN as int, - FTDesktop = ll::SDL_WindowFlags::SDL_WINDOW_FULLSCREEN_DESKTOP as int + FTTrue = 0x00000001, + FTDesktop = 0x00001001, } #[deriving(PartialEq, Copy)]