Merge pull request #250 from mvdnes/pkgconfig

Split package into lib and sys
This commit is contained in:
Tony Aldridge
2015-01-02 14:22:44 +00:00
50 changed files with 1957 additions and 1913 deletions
+5
View File
@@ -12,3 +12,8 @@ keywords = ["SDL", "windowing", "graphics"]
name = "sdl2"
path = "src/sdl2/lib.rs"
[dependencies.sdl2-sys]
path = "sdl2-sys"
version = "*"
+13
View File
@@ -0,0 +1,13 @@
[package]
name = "sdl2-sys"
version = "0.0.0"
authors = ["Tony Aldridge <tony@angry-lawyer.com>"]
links = "SDL2"
build = "build.rs"
[lib]
name = "sdl2-sys"
[build-dependencies]
pkg-config = "*"
+11
View File
@@ -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()
}
+106
View File
@@ -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<extern "C" fn
(arg1: *const c_void, arg2: *const uint8_t,
arg3: c_int)>;
#[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<extern "C" fn
(arg1: *const SDL_AudioCVT,
arg2: SDL_AudioFormat)>;
#[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);
}
+9
View File
@@ -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;
}
+125
View File
@@ -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);
}
+20
View File
@@ -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;
}
+469
View File
@@ -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;
}
+6
View File
@@ -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;
}
+12
View File
@@ -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;
}
+194
View File
@@ -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;
}
+44
View File
@@ -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);
}
+38
View File
@@ -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;
}
+26
View File
@@ -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;
+11
View File
@@ -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;
}
+46
View File
@@ -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;
}
+89
View File
@@ -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;
}
+140
View File
@@ -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<Rect>) -> Option<Rect> {
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<Rect> {
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
}
}
}
+29
View File
@@ -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;
}
+114
View File
@@ -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;
}

Some files were not shown because too many files have changed in this diff Show More