mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Merge branch 'master' into ignore-extra-sdl-keymod-bits
This commit is contained in:
+8
-1
@@ -17,7 +17,14 @@ env:
|
||||
- secure: MJhmVnQ2IM7+sVmc3vU4ndKOcQgLLeHUPW3qaQBQHKQmvoswCwQK60N17uSgWn1Ln8teqvSRHq4KclIjdMHI+VuQXJHQKHDgjcYbHxwmc3AM1Whnp0XB44ksKUmD109BGWSfZQxzF+6dA+YNOQ+mti+bpydMu8n2FMVjA/SXwQ8=
|
||||
|
||||
install:
|
||||
- if [[ $CI_BUILD_FEATURES != *"bundled"* ]]; then bash scripts/travis-install-sdl2.sh; fi
|
||||
- |
|
||||
if [[ $CI_BUILD_FEATURES != *"bundled"* ]]; then
|
||||
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install --assume-yes libgl1-mesa-dev
|
||||
fi
|
||||
bash scripts/travis-install-sdl2.sh
|
||||
fi
|
||||
|
||||
before_script:
|
||||
- shopt -s expand_aliases
|
||||
|
||||
@@ -6,6 +6,11 @@ when upgrading from a version of rust-sdl2 to another.
|
||||
[PR #882](https://github.com/Rust-SDL2/rust-sdl2/pull/882)
|
||||
Ignore unknown bits in `SDL_Keysym`'s `mod` field (key modifiers) when constructing `Event::KeyDown` and `Event::KeyUp`. Deprecate `sdl2::event::Event::unwrap_keymod`, which had been made public accidentally.
|
||||
|
||||
### v0.32.2
|
||||
|
||||
[PR #898](https://github.com/Rust-SDL2/rust-sdl2/pull/898):
|
||||
Implements `TryFrom<PixelFormatEnum>` for `PixelFormat`
|
||||
|
||||
### v0.32.1
|
||||
|
||||
[PR #868](https://github.com/Rust-SDL2/rust-sdl2/pull/868):
|
||||
|
||||
+5
-5
@@ -57,11 +57,11 @@ fn download_to(url: &str, dest: &str) {
|
||||
if cfg!(windows) {
|
||||
run_command("powershell", &[
|
||||
"-NoProfile", "-NonInteractive",
|
||||
"-Command", "& {
|
||||
"-Command", &format!("& {{
|
||||
$client = New-Object System.Net.WebClient
|
||||
$client.DownloadFile($args[0], $args[1])
|
||||
if (!$?) { Exit 1 }
|
||||
}", url, dest
|
||||
$client.DownloadFile(\"{0}\", \"{1}\")
|
||||
if (!$?) {{ Exit 1 }}
|
||||
}}", url, dest).as_str()
|
||||
]);
|
||||
} else {
|
||||
run_command("curl", &[url, "-o", dest]);
|
||||
@@ -301,7 +301,7 @@ fn link_sdl2(target_os: &str) {
|
||||
if cfg!(feature = "bundled") || cfg!(not(feature = "use-pkgconfig")) {
|
||||
if cfg!(feature = "use_mac_framework") && target_os == "darwin" {
|
||||
println!("cargo:rustc-flags=-l framework=SDL2");
|
||||
} else {
|
||||
} else if target_os != "emscripten" {
|
||||
println!("cargo:rustc-flags=-l SDL2");
|
||||
}
|
||||
}
|
||||
|
||||
+15
-14
@@ -66,6 +66,7 @@ use crate::get_error;
|
||||
use crate::rwops::RWops;
|
||||
|
||||
use crate::sys;
|
||||
use crate::sys::SDL_AudioStatus;
|
||||
|
||||
impl AudioSubsystem {
|
||||
/// Opens a new audio device given the desired parameters and callback.
|
||||
@@ -199,18 +200,18 @@ impl AudioFormat {
|
||||
#[repr(i32)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
pub enum AudioStatus {
|
||||
Stopped = sys::SDL_AudioStatus::SDL_AUDIO_STOPPED as i32,
|
||||
Playing = sys::SDL_AudioStatus::SDL_AUDIO_PLAYING as i32,
|
||||
Paused = sys::SDL_AudioStatus::SDL_AUDIO_PAUSED as i32,
|
||||
Stopped = SDL_AudioStatus::SDL_AUDIO_STOPPED as i32,
|
||||
Playing = SDL_AudioStatus::SDL_AUDIO_PLAYING as i32,
|
||||
Paused = SDL_AudioStatus::SDL_AUDIO_PAUSED as i32,
|
||||
}
|
||||
|
||||
impl FromPrimitive for AudioStatus {
|
||||
fn from_i64(n: i64) -> Option<AudioStatus> {
|
||||
use self::AudioStatus::*;
|
||||
|
||||
const STOPPED: i64 = sys::SDL_AudioStatus::SDL_AUDIO_STOPPED as i64;
|
||||
const PLAYING: i64 = sys::SDL_AudioStatus::SDL_AUDIO_PLAYING as i64;
|
||||
const PAUSED: i64 = sys::SDL_AudioStatus::SDL_AUDIO_PAUSED as i64;
|
||||
const STOPPED: i64 = SDL_AudioStatus::SDL_AUDIO_STOPPED as i64;
|
||||
const PLAYING: i64 = SDL_AudioStatus::SDL_AUDIO_PLAYING as i64;
|
||||
const PAUSED: i64 = SDL_AudioStatus::SDL_AUDIO_PAUSED as i64;
|
||||
|
||||
Some(match n {
|
||||
STOPPED => Stopped,
|
||||
@@ -301,8 +302,8 @@ impl AudioSpecWAV {
|
||||
freq: desired.freq,
|
||||
format: AudioFormat::from_ll(desired.format).unwrap(),
|
||||
channels: desired.channels,
|
||||
audio_buf: audio_buf,
|
||||
audio_len: audio_len
|
||||
audio_buf,
|
||||
audio_len
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -543,9 +544,9 @@ impl<'a, Channel: AudioFormatNum> AudioQueue<Channel> {
|
||||
|
||||
Ok(AudioQueue {
|
||||
subsystem: a.clone(),
|
||||
device_id: device_id,
|
||||
device_id,
|
||||
phantom: PhantomData::default(),
|
||||
spec: spec,
|
||||
spec,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -636,9 +637,9 @@ impl<CB: AudioCallback> AudioDevice<CB> {
|
||||
|
||||
Ok(AudioDevice {
|
||||
subsystem: a.clone(),
|
||||
device_id: device_id,
|
||||
userdata: userdata,
|
||||
spec: spec,
|
||||
device_id,
|
||||
userdata,
|
||||
spec,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -747,7 +748,7 @@ impl AudioCVT {
|
||||
src_format.to_ll(), src_channels, src_rate as c_int,
|
||||
dst_format.to_ll(), dst_channels, dst_rate as c_int);
|
||||
if ret == 1 || ret == 0 {
|
||||
Ok(AudioCVT { raw: raw })
|
||||
Ok(AudioCVT { raw })
|
||||
} else {
|
||||
Err(get_error())
|
||||
}
|
||||
|
||||
+11
-10
@@ -1,4 +1,5 @@
|
||||
use crate::sys;
|
||||
use crate::sys::SDL_bool;
|
||||
|
||||
pub const CACHELINESIZE: u8 = 128;
|
||||
|
||||
@@ -11,43 +12,43 @@ pub fn cpu_cache_line_size() -> i32 {
|
||||
}
|
||||
|
||||
pub fn has_rdtsc() -> bool {
|
||||
unsafe { sys::SDL_HasRDTSC() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasRDTSC() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_alti_vec() -> bool {
|
||||
unsafe { sys::SDL_HasAltiVec() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasAltiVec() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_mmx() -> bool {
|
||||
unsafe { sys::SDL_HasMMX() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasMMX() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_3d_now() -> bool {
|
||||
unsafe { sys::SDL_Has3DNow() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_Has3DNow() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_sse() -> bool {
|
||||
unsafe { sys::SDL_HasSSE() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasSSE() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_sse2() -> bool {
|
||||
unsafe { sys::SDL_HasSSE2() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasSSE2() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_sse3() -> bool {
|
||||
unsafe { sys::SDL_HasSSE3() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasSSE3() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_sse41() -> bool {
|
||||
unsafe { sys::SDL_HasSSE41() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasSSE41() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_sse42() -> bool {
|
||||
unsafe { sys::SDL_HasSSE42() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasSSE42() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn has_avx() -> bool {
|
||||
unsafe { sys::SDL_HasAVX() == sys::SDL_bool::SDL_TRUE }
|
||||
unsafe { sys::SDL_HasAVX() == SDL_bool::SDL_TRUE }
|
||||
}
|
||||
|
||||
pub fn system_ram() -> i32 {
|
||||
|
||||
+131
-130
@@ -28,6 +28,7 @@ use crate::keyboard::Scancode;
|
||||
use crate::get_error;
|
||||
|
||||
use crate::sys;
|
||||
use crate::sys::SDL_EventType;
|
||||
|
||||
struct CustomEventTypeMaps {
|
||||
sdl_id_to_type_id: HashMap<u32, ::std::any::TypeId>,
|
||||
@@ -91,8 +92,8 @@ impl crate::EventSubsystem {
|
||||
events_ptr,
|
||||
max_amount as c_int,
|
||||
sys::SDL_eventaction::SDL_PEEKEVENT,
|
||||
sys::SDL_EventType::SDL_FIRSTEVENT as u32,
|
||||
sys::SDL_EventType::SDL_LASTEVENT as u32
|
||||
SDL_EventType::SDL_FIRSTEVENT as u32,
|
||||
SDL_EventType::SDL_LASTEVENT as u32
|
||||
)
|
||||
};
|
||||
|
||||
@@ -264,56 +265,56 @@ impl crate::EventSubsystem {
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
pub enum EventType {
|
||||
First = sys::SDL_EventType::SDL_FIRSTEVENT as u32,
|
||||
First = SDL_EventType::SDL_FIRSTEVENT as u32,
|
||||
|
||||
Quit = sys::SDL_EventType::SDL_QUIT as u32,
|
||||
AppTerminating = sys::SDL_EventType::SDL_APP_TERMINATING as u32,
|
||||
AppLowMemory = sys::SDL_EventType::SDL_APP_LOWMEMORY as u32,
|
||||
AppWillEnterBackground = sys::SDL_EventType::SDL_APP_WILLENTERBACKGROUND as u32,
|
||||
AppDidEnterBackground = sys::SDL_EventType::SDL_APP_DIDENTERBACKGROUND as u32,
|
||||
AppWillEnterForeground = sys::SDL_EventType::SDL_APP_WILLENTERFOREGROUND as u32,
|
||||
AppDidEnterForeground = sys::SDL_EventType::SDL_APP_DIDENTERFOREGROUND as u32,
|
||||
Quit = SDL_EventType::SDL_QUIT as u32,
|
||||
AppTerminating = SDL_EventType::SDL_APP_TERMINATING as u32,
|
||||
AppLowMemory = SDL_EventType::SDL_APP_LOWMEMORY as u32,
|
||||
AppWillEnterBackground = SDL_EventType::SDL_APP_WILLENTERBACKGROUND as u32,
|
||||
AppDidEnterBackground = SDL_EventType::SDL_APP_DIDENTERBACKGROUND as u32,
|
||||
AppWillEnterForeground = SDL_EventType::SDL_APP_WILLENTERFOREGROUND as u32,
|
||||
AppDidEnterForeground = SDL_EventType::SDL_APP_DIDENTERFOREGROUND as u32,
|
||||
|
||||
Window = sys::SDL_EventType::SDL_WINDOWEVENT as u32,
|
||||
Window = SDL_EventType::SDL_WINDOWEVENT as u32,
|
||||
// TODO: SysWM = sys::SDL_SYSWMEVENT as u32,
|
||||
|
||||
KeyDown = sys::SDL_EventType::SDL_KEYDOWN as u32,
|
||||
KeyUp = sys::SDL_EventType::SDL_KEYUP as u32,
|
||||
TextEditing = sys::SDL_EventType::SDL_TEXTEDITING as u32,
|
||||
TextInput = sys::SDL_EventType::SDL_TEXTINPUT as u32,
|
||||
KeyDown = SDL_EventType::SDL_KEYDOWN as u32,
|
||||
KeyUp = SDL_EventType::SDL_KEYUP as u32,
|
||||
TextEditing = SDL_EventType::SDL_TEXTEDITING as u32,
|
||||
TextInput = SDL_EventType::SDL_TEXTINPUT as u32,
|
||||
|
||||
MouseMotion = sys::SDL_EventType::SDL_MOUSEMOTION as u32,
|
||||
MouseButtonDown = sys::SDL_EventType::SDL_MOUSEBUTTONDOWN as u32,
|
||||
MouseButtonUp = sys::SDL_EventType::SDL_MOUSEBUTTONUP as u32,
|
||||
MouseWheel = sys::SDL_EventType::SDL_MOUSEWHEEL as u32,
|
||||
MouseMotion = SDL_EventType::SDL_MOUSEMOTION as u32,
|
||||
MouseButtonDown = SDL_EventType::SDL_MOUSEBUTTONDOWN as u32,
|
||||
MouseButtonUp = SDL_EventType::SDL_MOUSEBUTTONUP as u32,
|
||||
MouseWheel = SDL_EventType::SDL_MOUSEWHEEL as u32,
|
||||
|
||||
JoyAxisMotion = sys::SDL_EventType::SDL_JOYAXISMOTION as u32,
|
||||
JoyBallMotion = sys::SDL_EventType::SDL_JOYBALLMOTION as u32,
|
||||
JoyHatMotion = sys::SDL_EventType::SDL_JOYHATMOTION as u32,
|
||||
JoyButtonDown = sys::SDL_EventType::SDL_JOYBUTTONDOWN as u32,
|
||||
JoyButtonUp = sys::SDL_EventType::SDL_JOYBUTTONUP as u32,
|
||||
JoyDeviceAdded = sys::SDL_EventType::SDL_JOYDEVICEADDED as u32,
|
||||
JoyDeviceRemoved = sys::SDL_EventType::SDL_JOYDEVICEREMOVED as u32,
|
||||
JoyAxisMotion = SDL_EventType::SDL_JOYAXISMOTION as u32,
|
||||
JoyBallMotion = SDL_EventType::SDL_JOYBALLMOTION as u32,
|
||||
JoyHatMotion = SDL_EventType::SDL_JOYHATMOTION as u32,
|
||||
JoyButtonDown = SDL_EventType::SDL_JOYBUTTONDOWN as u32,
|
||||
JoyButtonUp = SDL_EventType::SDL_JOYBUTTONUP as u32,
|
||||
JoyDeviceAdded = SDL_EventType::SDL_JOYDEVICEADDED as u32,
|
||||
JoyDeviceRemoved = SDL_EventType::SDL_JOYDEVICEREMOVED as u32,
|
||||
|
||||
ControllerAxisMotion = sys::SDL_EventType::SDL_CONTROLLERAXISMOTION as u32,
|
||||
ControllerButtonDown = sys::SDL_EventType::SDL_CONTROLLERBUTTONDOWN as u32,
|
||||
ControllerButtonUp = sys::SDL_EventType::SDL_CONTROLLERBUTTONUP as u32,
|
||||
ControllerDeviceAdded = sys::SDL_EventType::SDL_CONTROLLERDEVICEADDED as u32,
|
||||
ControllerDeviceRemoved = sys::SDL_EventType::SDL_CONTROLLERDEVICEREMOVED as u32,
|
||||
ControllerDeviceRemapped = sys::SDL_EventType::SDL_CONTROLLERDEVICEREMAPPED as u32,
|
||||
ControllerAxisMotion = SDL_EventType::SDL_CONTROLLERAXISMOTION as u32,
|
||||
ControllerButtonDown = SDL_EventType::SDL_CONTROLLERBUTTONDOWN as u32,
|
||||
ControllerButtonUp = SDL_EventType::SDL_CONTROLLERBUTTONUP as u32,
|
||||
ControllerDeviceAdded = SDL_EventType::SDL_CONTROLLERDEVICEADDED as u32,
|
||||
ControllerDeviceRemoved = SDL_EventType::SDL_CONTROLLERDEVICEREMOVED as u32,
|
||||
ControllerDeviceRemapped = SDL_EventType::SDL_CONTROLLERDEVICEREMAPPED as u32,
|
||||
|
||||
FingerDown = sys::SDL_EventType::SDL_FINGERDOWN as u32,
|
||||
FingerUp = sys::SDL_EventType::SDL_FINGERUP as u32,
|
||||
FingerMotion = sys::SDL_EventType::SDL_FINGERMOTION as u32,
|
||||
DollarGesture = sys::SDL_EventType::SDL_DOLLARGESTURE as u32,
|
||||
DollarRecord = sys::SDL_EventType::SDL_DOLLARRECORD as u32,
|
||||
MultiGesture = sys::SDL_EventType::SDL_MULTIGESTURE as u32,
|
||||
FingerDown = SDL_EventType::SDL_FINGERDOWN as u32,
|
||||
FingerUp = SDL_EventType::SDL_FINGERUP as u32,
|
||||
FingerMotion = SDL_EventType::SDL_FINGERMOTION as u32,
|
||||
DollarGesture = SDL_EventType::SDL_DOLLARGESTURE as u32,
|
||||
DollarRecord = SDL_EventType::SDL_DOLLARRECORD as u32,
|
||||
MultiGesture = SDL_EventType::SDL_MULTIGESTURE as u32,
|
||||
|
||||
ClipboardUpdate = sys::SDL_EventType::SDL_CLIPBOARDUPDATE as u32,
|
||||
DropFile = sys::SDL_EventType::SDL_DROPFILE as u32,
|
||||
ClipboardUpdate = SDL_EventType::SDL_CLIPBOARDUPDATE as u32,
|
||||
DropFile = SDL_EventType::SDL_DROPFILE as u32,
|
||||
|
||||
User = sys::SDL_EventType::SDL_USEREVENT as u32,
|
||||
Last = sys::SDL_EventType::SDL_LASTEVENT as u32,
|
||||
User = SDL_EventType::SDL_USEREVENT as u32,
|
||||
Last = SDL_EventType::SDL_LASTEVENT as u32,
|
||||
}
|
||||
|
||||
impl FromPrimitive for EventType {
|
||||
@@ -735,7 +736,7 @@ where S: Into<Option<Scancode>>,
|
||||
.unwrap_or(sys::SDLK_UNKNOWN as i32);
|
||||
let keymod = keymod.bits() as u16;
|
||||
sys::SDL_Keysym {
|
||||
scancode: scancode,
|
||||
scancode,
|
||||
sym: keycode,
|
||||
mod_: keymod,
|
||||
unused: 0,
|
||||
@@ -752,11 +753,11 @@ impl Event {
|
||||
Event::User { window_id, type_, code, data1, data2, timestamp} => {
|
||||
let event = sys::SDL_UserEvent {
|
||||
type_: type_ as uint32_t,
|
||||
timestamp: timestamp,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
code: code as i32,
|
||||
data1: data1,
|
||||
data2: data2
|
||||
data1,
|
||||
data2
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_UserEvent, 1);
|
||||
@@ -766,8 +767,8 @@ impl Event {
|
||||
|
||||
Event::Quit{timestamp} => {
|
||||
let event = sys::SDL_QuitEvent {
|
||||
type_: sys::SDL_EventType::SDL_QUIT as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_QUIT as u32,
|
||||
timestamp,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_QuitEvent, 1);
|
||||
@@ -782,15 +783,15 @@ impl Event {
|
||||
} => {
|
||||
let (win_event_id, data1, data2) = win_event.to_ll();
|
||||
let event = sys::SDL_WindowEvent {
|
||||
type_: sys::SDL_EventType::SDL_WINDOWEVENT as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_WINDOWEVENT as u32,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
event: win_event_id,
|
||||
padding1: 0,
|
||||
padding2: 0,
|
||||
padding3: 0,
|
||||
data1: data1,
|
||||
data2: data2,
|
||||
data1,
|
||||
data2,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_WindowEvent, 1);
|
||||
@@ -808,14 +809,14 @@ impl Event {
|
||||
} => {
|
||||
let keysym = mk_keysym(scancode, keycode, keymod);
|
||||
let event = sys::SDL_KeyboardEvent{
|
||||
type_: sys::SDL_EventType::SDL_KEYDOWN as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_KEYDOWN as u32,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
state: sys::SDL_PRESSED as u8,
|
||||
repeat: repeat as u8,
|
||||
padding2: 0,
|
||||
padding3: 0,
|
||||
keysym: keysym,
|
||||
keysym,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_KeyboardEvent, 1);
|
||||
@@ -832,14 +833,14 @@ impl Event {
|
||||
} => {
|
||||
let keysym = mk_keysym(scancode, keycode, keymod);
|
||||
let event = sys::SDL_KeyboardEvent{
|
||||
type_: sys::SDL_EventType::SDL_KEYUP as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_KEYUP as u32,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
state: sys::SDL_RELEASED as u8,
|
||||
repeat: repeat as u8,
|
||||
padding2: 0,
|
||||
padding3: 0,
|
||||
keysym: keysym,
|
||||
keysym,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_KeyboardEvent, 1);
|
||||
@@ -858,15 +859,15 @@ impl Event {
|
||||
} => {
|
||||
let state = mousestate.to_sdl_state();
|
||||
let event = sys::SDL_MouseMotionEvent {
|
||||
type_: sys::SDL_EventType::SDL_MOUSEMOTION as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_MOUSEMOTION as u32,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
which: which,
|
||||
state: state,
|
||||
x: x,
|
||||
y: y,
|
||||
xrel: xrel,
|
||||
yrel: yrel,
|
||||
which,
|
||||
state,
|
||||
x,
|
||||
y,
|
||||
xrel,
|
||||
yrel,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_MouseMotionEvent, 1);
|
||||
@@ -884,16 +885,16 @@ impl Event {
|
||||
y
|
||||
} => {
|
||||
let event = sys::SDL_MouseButtonEvent {
|
||||
type_: sys::SDL_EventType::SDL_MOUSEBUTTONDOWN as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_MOUSEBUTTONDOWN as u32,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
which: which,
|
||||
which,
|
||||
button: mouse_btn as u8,
|
||||
state: sys::SDL_PRESSED as u8,
|
||||
clicks: clicks,
|
||||
clicks,
|
||||
padding1: 0,
|
||||
x: x,
|
||||
y: y
|
||||
x,
|
||||
y
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_MouseButtonEvent, 1);
|
||||
@@ -910,16 +911,16 @@ impl Event {
|
||||
y
|
||||
} => {
|
||||
let event = sys::SDL_MouseButtonEvent {
|
||||
type_: sys::SDL_EventType::SDL_MOUSEBUTTONUP as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_MOUSEBUTTONUP as u32,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
which: which,
|
||||
which,
|
||||
button: mouse_btn as u8,
|
||||
state: sys::SDL_RELEASED as u8,
|
||||
clicks: clicks,
|
||||
clicks,
|
||||
padding1: 0,
|
||||
x: x,
|
||||
y: y
|
||||
x,
|
||||
y
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_MouseButtonEvent, 1);
|
||||
@@ -936,12 +937,12 @@ impl Event {
|
||||
direction,
|
||||
} => {
|
||||
let event = sys::SDL_MouseWheelEvent {
|
||||
type_: sys::SDL_EventType::SDL_MOUSEWHEEL as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_MOUSEWHEEL as u32,
|
||||
timestamp,
|
||||
windowID: window_id,
|
||||
which: which,
|
||||
x: x,
|
||||
y: y,
|
||||
which,
|
||||
x,
|
||||
y,
|
||||
direction : direction.to_ll(),
|
||||
};
|
||||
unsafe {
|
||||
@@ -956,11 +957,11 @@ impl Event {
|
||||
value
|
||||
} => {
|
||||
let event = sys::SDL_JoyAxisEvent {
|
||||
type_: sys::SDL_EventType::SDL_JOYAXISMOTION as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_JOYAXISMOTION as u32,
|
||||
timestamp,
|
||||
which,
|
||||
axis: axis_idx,
|
||||
value: value,
|
||||
value,
|
||||
padding1: 0,
|
||||
padding2: 0,
|
||||
padding3: 0,
|
||||
@@ -980,12 +981,12 @@ impl Event {
|
||||
yrel
|
||||
} => {
|
||||
let event = sys::SDL_JoyBallEvent {
|
||||
type_: sys::SDL_EventType::SDL_JOYBALLMOTION as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_JOYBALLMOTION as u32,
|
||||
timestamp,
|
||||
which,
|
||||
ball: ball_idx,
|
||||
xrel: xrel,
|
||||
yrel: yrel,
|
||||
xrel,
|
||||
yrel,
|
||||
padding1: 0,
|
||||
padding2: 0,
|
||||
padding3: 0
|
||||
@@ -1004,9 +1005,9 @@ impl Event {
|
||||
} => {
|
||||
let hatvalue = state.to_raw();
|
||||
let event = sys::SDL_JoyHatEvent {
|
||||
type_: sys::SDL_EventType::SDL_JOYHATMOTION as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_JOYHATMOTION as u32,
|
||||
timestamp,
|
||||
which,
|
||||
hat: hat_idx,
|
||||
value: hatvalue,
|
||||
padding1: 0,
|
||||
@@ -1024,9 +1025,9 @@ impl Event {
|
||||
button_idx
|
||||
} => {
|
||||
let event = sys::SDL_JoyButtonEvent {
|
||||
type_: sys::SDL_EventType::SDL_JOYBUTTONDOWN as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_JOYBUTTONDOWN as u32,
|
||||
timestamp,
|
||||
which,
|
||||
button: button_idx,
|
||||
state: sys::SDL_PRESSED as u8,
|
||||
padding1: 0,
|
||||
@@ -1045,9 +1046,9 @@ impl Event {
|
||||
button_idx,
|
||||
} => {
|
||||
let event = sys::SDL_JoyButtonEvent {
|
||||
type_: sys::SDL_EventType::SDL_JOYBUTTONUP as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_JOYBUTTONUP as u32,
|
||||
timestamp,
|
||||
which,
|
||||
button: button_idx,
|
||||
state: sys::SDL_RELEASED as u8,
|
||||
padding1: 0,
|
||||
@@ -1065,8 +1066,8 @@ impl Event {
|
||||
which,
|
||||
} => {
|
||||
let event = sys::SDL_JoyDeviceEvent {
|
||||
type_: sys::SDL_EventType::SDL_JOYDEVICEADDED as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_JOYDEVICEADDED as u32,
|
||||
timestamp,
|
||||
which: which as i32,
|
||||
};
|
||||
unsafe {
|
||||
@@ -1080,9 +1081,9 @@ impl Event {
|
||||
which,
|
||||
} => {
|
||||
let event = sys::SDL_JoyDeviceEvent {
|
||||
type_: sys::SDL_EventType::SDL_JOYDEVICEREMOVED as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_JOYDEVICEREMOVED as u32,
|
||||
timestamp,
|
||||
which,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_JoyDeviceEvent, 1);
|
||||
@@ -1098,11 +1099,11 @@ impl Event {
|
||||
} => {
|
||||
let axisval = axis.to_ll();
|
||||
let event = sys::SDL_ControllerAxisEvent {
|
||||
type_: sys::SDL_EventType::SDL_CONTROLLERAXISMOTION as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_CONTROLLERAXISMOTION as u32,
|
||||
timestamp,
|
||||
which,
|
||||
axis: axisval as u8,
|
||||
value: value,
|
||||
value,
|
||||
padding1: 0,
|
||||
padding2: 0,
|
||||
padding3: 0,
|
||||
@@ -1120,9 +1121,9 @@ impl Event {
|
||||
} => {
|
||||
let buttonval = button.to_ll();
|
||||
let event = sys::SDL_ControllerButtonEvent {
|
||||
type_: sys::SDL_EventType::SDL_CONTROLLERBUTTONDOWN as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_CONTROLLERBUTTONDOWN as u32,
|
||||
timestamp,
|
||||
which,
|
||||
// This conversion turns an i32 into a u8; signed-to-unsigned conversions
|
||||
// are a bit of a code smell, but that appears to be how SDL defines it.
|
||||
button: buttonval as u8,
|
||||
@@ -1143,9 +1144,9 @@ impl Event {
|
||||
} => {
|
||||
let buttonval = button.to_ll();
|
||||
let event = sys::SDL_ControllerButtonEvent {
|
||||
type_: sys::SDL_EventType::SDL_CONTROLLERBUTTONUP as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_CONTROLLERBUTTONUP as u32,
|
||||
timestamp,
|
||||
which,
|
||||
button: buttonval as u8,
|
||||
state: sys::SDL_RELEASED as u8,
|
||||
padding1: 0,
|
||||
@@ -1162,8 +1163,8 @@ impl Event {
|
||||
which,
|
||||
} => {
|
||||
let event = sys::SDL_ControllerDeviceEvent {
|
||||
type_: sys::SDL_EventType::SDL_CONTROLLERDEVICEADDED as u32,
|
||||
timestamp: timestamp,
|
||||
type_: SDL_EventType::SDL_CONTROLLERDEVICEADDED as u32,
|
||||
timestamp,
|
||||
which: which as i32,
|
||||
};
|
||||
unsafe {
|
||||
@@ -1178,9 +1179,9 @@ impl Event {
|
||||
which,
|
||||
} => {
|
||||
let event = sys::SDL_ControllerDeviceEvent {
|
||||
type_: sys::SDL_EventType::SDL_CONTROLLERDEVICEREMOVED as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_CONTROLLERDEVICEREMOVED as u32,
|
||||
timestamp,
|
||||
which,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
@@ -1194,9 +1195,9 @@ impl Event {
|
||||
which,
|
||||
} => {
|
||||
let event = sys::SDL_ControllerDeviceEvent {
|
||||
type_: sys::SDL_EventType::SDL_CONTROLLERDEVICEREMAPPED as u32,
|
||||
timestamp: timestamp,
|
||||
which: which,
|
||||
type_: SDL_EventType::SDL_CONTROLLERDEVICEREMAPPED as u32,
|
||||
timestamp,
|
||||
which,
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy(&event, &mut ret as *mut sys::SDL_Event as *mut sys::SDL_ControllerDeviceEvent, 1);
|
||||
@@ -1306,7 +1307,7 @@ impl Event {
|
||||
Event::TextEditing {
|
||||
timestamp: event.timestamp,
|
||||
window_id: event.windowID,
|
||||
text: text,
|
||||
text,
|
||||
start: event.start,
|
||||
length: event.length
|
||||
}
|
||||
@@ -1323,7 +1324,7 @@ impl Event {
|
||||
Event::TextInput {
|
||||
timestamp: event.timestamp,
|
||||
window_id: event.windowID,
|
||||
text: text
|
||||
text
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1446,7 +1447,7 @@ impl Event {
|
||||
Event::ControllerAxisMotion {
|
||||
timestamp: event.timestamp,
|
||||
which: event.which,
|
||||
axis: axis,
|
||||
axis,
|
||||
value: event.value
|
||||
}
|
||||
}
|
||||
@@ -1457,7 +1458,7 @@ impl Event {
|
||||
Event::ControllerButtonDown {
|
||||
timestamp: event.timestamp,
|
||||
which: event.which,
|
||||
button: button
|
||||
button
|
||||
}
|
||||
}
|
||||
EventType::ControllerButtonUp => {
|
||||
@@ -1467,7 +1468,7 @@ impl Event {
|
||||
Event::ControllerButtonUp {
|
||||
timestamp: event.timestamp,
|
||||
which: event.which,
|
||||
button: button
|
||||
button
|
||||
}
|
||||
}
|
||||
EventType::ControllerDeviceAdded => {
|
||||
@@ -1766,7 +1767,7 @@ impl crate::EventPump {
|
||||
pub fn wait_timeout_iter(&mut self, timeout: u32) -> EventWaitTimeoutIterator {
|
||||
EventWaitTimeoutIterator {
|
||||
_marker: PhantomData,
|
||||
timeout: timeout
|
||||
timeout
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,27 +4,27 @@ use libc;
|
||||
use libc::{c_void, uint32_t, size_t};
|
||||
use std::mem;
|
||||
use ::get_error;
|
||||
use sys;
|
||||
use sys::gfx;
|
||||
|
||||
/// Structure holding the state and timing information of the framerate controller.
|
||||
pub struct FPSManager {
|
||||
raw: *mut sys::gfx::framerate::FPSmanager,
|
||||
raw: *mut gfx::framerate::FPSmanager,
|
||||
}
|
||||
|
||||
impl FPSManager {
|
||||
/// Create the framerate manager.
|
||||
pub fn new() -> FPSManager {
|
||||
unsafe {
|
||||
let size = mem::size_of::<sys::gfx::framerate::FPSmanager>() as size_t;
|
||||
let raw = libc::malloc(size) as *mut sys::gfx::framerate::FPSmanager;
|
||||
sys::gfx::framerate::SDL_initFramerate(raw);
|
||||
let size = mem::size_of::<gfx::framerate::FPSmanager>() as size_t;
|
||||
let raw = libc::malloc(size) as *mut gfx::framerate::FPSmanager;
|
||||
gfx::framerate::SDL_initFramerate(raw);
|
||||
FPSManager { raw: raw }
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the framerate in Hz.
|
||||
pub fn set_framerate(&mut self, rate: u32) -> Result<(), String> {
|
||||
let ret = unsafe { sys::gfx::framerate::SDL_setFramerate(self.raw, rate as uint32_t) };
|
||||
let ret = unsafe { gfx::framerate::SDL_setFramerate(self.raw, rate as uint32_t) };
|
||||
match ret {
|
||||
0 => Ok(()),
|
||||
_ => Err(get_error())
|
||||
@@ -34,18 +34,18 @@ impl FPSManager {
|
||||
/// Return the current target framerate in Hz.
|
||||
pub fn get_framerate(&self) -> i32 {
|
||||
// will not get an error
|
||||
unsafe { sys::gfx::framerate::SDL_getFramerate(self.raw) as i32 }
|
||||
unsafe { gfx::framerate::SDL_getFramerate(self.raw) as i32 }
|
||||
}
|
||||
|
||||
/// Return the current framecount.
|
||||
pub fn get_frame_count(&self) -> i32 {
|
||||
// will not get an error
|
||||
unsafe { sys::gfx::framerate::SDL_getFramecount(self.raw) as i32 }
|
||||
unsafe { gfx::framerate::SDL_getFramecount(self.raw) as i32 }
|
||||
}
|
||||
|
||||
/// Delay execution to maintain a constant framerate and calculate fps.
|
||||
pub fn delay(&mut self) -> u32 {
|
||||
unsafe { sys::gfx::framerate::SDL_framerateDelay(self.raw) as u32 }
|
||||
unsafe { gfx::framerate::SDL_framerateDelay(self.raw) as u32 }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
-43
@@ -29,15 +29,16 @@ use rwops::RWops;
|
||||
use version::Version;
|
||||
use get_error;
|
||||
use sys;
|
||||
use sys::image;
|
||||
|
||||
/// InitFlags are passed to init() to control which subsystem
|
||||
/// functionality to load.
|
||||
bitflags! {
|
||||
pub struct InitFlag : u32 {
|
||||
const JPG = sys::image::IMG_InitFlags_IMG_INIT_JPG as u32;
|
||||
const PNG = sys::image::IMG_InitFlags_IMG_INIT_PNG as u32;
|
||||
const TIF = sys::image::IMG_InitFlags_IMG_INIT_TIF as u32;
|
||||
const WEBP = sys::image::IMG_InitFlags_IMG_INIT_WEBP as u32;
|
||||
const JPG = image::IMG_InitFlags_IMG_INIT_JPG as u32;
|
||||
const PNG = image::IMG_InitFlags_IMG_INIT_PNG as u32;
|
||||
const TIF = image::IMG_InitFlags_IMG_INIT_TIF as u32;
|
||||
const WEBP = image::IMG_InitFlags_IMG_INIT_WEBP as u32;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +82,7 @@ impl<'a> LoadSurface for Surface<'a> {
|
||||
//! Loads an SDL Surface from a file
|
||||
unsafe {
|
||||
let c_filename = CString::new(filename.as_ref().to_str().unwrap()).unwrap();
|
||||
let raw = sys::image::IMG_Load(c_filename.as_ptr() as *const _);
|
||||
let raw = image::IMG_Load(c_filename.as_ptr() as *const _);
|
||||
if (raw as *mut ()).is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
@@ -93,7 +94,7 @@ impl<'a> LoadSurface for Surface<'a> {
|
||||
fn from_xpm_array(xpm: *const *const i8) -> Result<Surface<'a>, String> {
|
||||
//! Loads an SDL Surface from XPM data
|
||||
unsafe {
|
||||
let raw = sys::image::IMG_ReadXPMFromArray(xpm as *mut *mut c_char);
|
||||
let raw = image::IMG_ReadXPMFromArray(xpm as *mut *mut c_char);
|
||||
if (raw as *mut ()).is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
@@ -108,7 +109,7 @@ impl<'a> SaveSurface for Surface<'a> {
|
||||
//! Saves an SDL Surface to a file
|
||||
unsafe {
|
||||
let c_filename = CString::new(filename.as_ref().to_str().unwrap()).unwrap();
|
||||
let status = sys::image::IMG_SavePNG(self.raw(), c_filename.as_ptr() as *const _);
|
||||
let status = image::IMG_SavePNG(self.raw(), c_filename.as_ptr() as *const _);
|
||||
if status != 0 {
|
||||
Err(get_error())
|
||||
} else {
|
||||
@@ -120,7 +121,7 @@ impl<'a> SaveSurface for Surface<'a> {
|
||||
fn save_rw(&self, dst: &mut RWops) -> Result<(), String> {
|
||||
//! Saves an SDL Surface to an RWops
|
||||
unsafe {
|
||||
let status = sys::image::IMG_SavePNG_RW(self.raw(), dst.raw(), 0);
|
||||
let status = image::IMG_SavePNG_RW(self.raw(), dst.raw(), 0);
|
||||
|
||||
if status != 0 {
|
||||
Err(get_error())
|
||||
@@ -141,7 +142,7 @@ impl<T> LoadTexture for TextureCreator<T> {
|
||||
//! Loads an SDL Texture from a file
|
||||
unsafe {
|
||||
let c_filename = CString::new(filename.as_ref().to_str().unwrap()).unwrap();
|
||||
let raw = sys::image::IMG_LoadTexture(self.raw(), c_filename.as_ptr() as *const _);
|
||||
let raw = image::IMG_LoadTexture(self.raw(), c_filename.as_ptr() as *const _);
|
||||
if (raw as *mut ()).is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
@@ -158,7 +159,7 @@ pub struct Sdl2ImageContext;
|
||||
impl Drop for Sdl2ImageContext {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
sys::image::IMG_Quit();
|
||||
image::IMG_Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +168,7 @@ impl Drop for Sdl2ImageContext {
|
||||
/// If not every flag is set it returns an error
|
||||
pub fn init(flags: InitFlag) -> Result<Sdl2ImageContext, String> {
|
||||
let return_flags = unsafe {
|
||||
let used = sys::image::IMG_Init(flags.bits() as c_int);
|
||||
let used = image::IMG_Init(flags.bits() as c_int);
|
||||
InitFlag::from_bits_truncate(used as u32)
|
||||
};
|
||||
if !flags.intersects(return_flags) {
|
||||
@@ -186,7 +187,7 @@ pub fn init(flags: InitFlag) -> Result<Sdl2ImageContext, String> {
|
||||
|
||||
/// Returns the version of the dynamically linked `SDL_image` library
|
||||
pub fn get_linked_version() -> Version {
|
||||
unsafe { Version::from_ll(*sys::image::IMG_Linked_Version()) }
|
||||
unsafe { Version::from_ll(*image::IMG_Linked_Version()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -238,118 +239,118 @@ pub trait ImageRWops {
|
||||
|
||||
impl<'a> ImageRWops for RWops<'a> {
|
||||
fn load(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_Load_RW(self.raw(), 0) };
|
||||
let raw = unsafe { image::IMG_Load_RW(self.raw(), 0) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_typed(&self, _type: &str) -> Result<Surface, String> {
|
||||
let raw = unsafe {
|
||||
let c_type = CString::new(_type.as_bytes()).unwrap();
|
||||
sys::image::IMG_LoadTyped_RW(self.raw(), 0, c_type.as_ptr() as *const _)
|
||||
image::IMG_LoadTyped_RW(self.raw(), 0, c_type.as_ptr() as *const _)
|
||||
};
|
||||
to_surface_result(raw)
|
||||
}
|
||||
|
||||
fn load_cur(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadCUR_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadCUR_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_ico(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadICO_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadICO_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_bmp(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadBMP_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadBMP_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_pnm(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadPNM_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadPNM_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_xpm(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadXPM_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadXPM_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_xcf(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadXCF_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadXCF_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_pcx(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadPCX_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadPCX_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_gif(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadGIF_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadGIF_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_jpg(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadJPG_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadJPG_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_tif(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadTIF_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadTIF_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_png(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadPNG_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadPNG_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_tga(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadTGA_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadTGA_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_lbm(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadLBM_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadLBM_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_xv(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadXV_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadXV_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
fn load_webp(&self) -> Result<Surface, String> {
|
||||
let raw = unsafe { sys::image::IMG_LoadWEBP_RW(self.raw()) };
|
||||
let raw = unsafe { image::IMG_LoadWEBP_RW(self.raw()) };
|
||||
to_surface_result(raw)
|
||||
}
|
||||
|
||||
fn is_cur(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isCUR(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isCUR(self.raw()) == 1 }
|
||||
}
|
||||
fn is_ico(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isICO(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isICO(self.raw()) == 1 }
|
||||
}
|
||||
fn is_bmp(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isBMP(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isBMP(self.raw()) == 1 }
|
||||
}
|
||||
fn is_pnm(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isPNM(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isPNM(self.raw()) == 1 }
|
||||
}
|
||||
fn is_xpm(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isXPM(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isXPM(self.raw()) == 1 }
|
||||
}
|
||||
fn is_xcf(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isXCF(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isXCF(self.raw()) == 1 }
|
||||
}
|
||||
fn is_pcx(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isPCX(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isPCX(self.raw()) == 1 }
|
||||
}
|
||||
fn is_gif(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isGIF(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isGIF(self.raw()) == 1 }
|
||||
}
|
||||
fn is_jpg(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isJPG(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isJPG(self.raw()) == 1 }
|
||||
}
|
||||
fn is_tif(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isTIF(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isTIF(self.raw()) == 1 }
|
||||
}
|
||||
fn is_png(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isPNG(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isPNG(self.raw()) == 1 }
|
||||
}
|
||||
fn is_lbm(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isLBM(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isLBM(self.raw()) == 1 }
|
||||
}
|
||||
fn is_xv(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isXV(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isXV(self.raw()) == 1 }
|
||||
}
|
||||
fn is_webp(&self) -> bool {
|
||||
unsafe { sys::image::IMG_isWEBP(self.raw()) == 1 }
|
||||
unsafe { image::IMG_isWEBP(self.raw()) == 1 }
|
||||
}
|
||||
}
|
||||
|
||||
+30
-25
@@ -1,4 +1,5 @@
|
||||
use crate::sys;
|
||||
use crate::sys::SDL_JoystickPowerLevel;
|
||||
|
||||
use crate::JoystickSubsystem;
|
||||
use crate::get_error;
|
||||
@@ -61,7 +62,7 @@ impl JoystickSubsystem {
|
||||
|
||||
let raw = unsafe { sys::SDL_JoystickGetDeviceGUID(joystick_index) };
|
||||
|
||||
let guid = Guid { raw: raw };
|
||||
let guid = Guid { raw };
|
||||
|
||||
if guid.is_zero() {
|
||||
Err(SdlError(get_error()))
|
||||
@@ -93,35 +94,35 @@ impl JoystickSubsystem {
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
#[repr(i32)]
|
||||
pub enum PowerLevel {
|
||||
Unknown = sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN as i32,
|
||||
Empty = sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_EMPTY as i32,
|
||||
Low = sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_LOW as i32,
|
||||
Medium = sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_MEDIUM as i32,
|
||||
Full = sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_FULL as i32,
|
||||
Wired = sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_WIRED as i32,
|
||||
Unknown = SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN as i32,
|
||||
Empty = SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_EMPTY as i32,
|
||||
Low = SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_LOW as i32,
|
||||
Medium = SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_MEDIUM as i32,
|
||||
Full = SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_FULL as i32,
|
||||
Wired = SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_WIRED as i32,
|
||||
}
|
||||
|
||||
impl PowerLevel {
|
||||
pub fn from_ll(raw: sys::SDL_JoystickPowerLevel) -> PowerLevel {
|
||||
pub fn from_ll(raw: SDL_JoystickPowerLevel) -> PowerLevel {
|
||||
match raw {
|
||||
sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN => PowerLevel::Unknown,
|
||||
sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_EMPTY => PowerLevel::Empty,
|
||||
sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_LOW => PowerLevel::Low,
|
||||
sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_MEDIUM => PowerLevel::Medium,
|
||||
sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_FULL => PowerLevel::Full,
|
||||
sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_WIRED => PowerLevel::Wired,
|
||||
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN => PowerLevel::Unknown,
|
||||
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_EMPTY => PowerLevel::Empty,
|
||||
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_LOW => PowerLevel::Low,
|
||||
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_MEDIUM => PowerLevel::Medium,
|
||||
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_FULL => PowerLevel::Full,
|
||||
SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_WIRED => PowerLevel::Wired,
|
||||
_ => panic!("Unexpected power level: {:?}", raw),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_ll(&self) -> sys::SDL_JoystickPowerLevel {
|
||||
pub fn to_ll(&self) -> SDL_JoystickPowerLevel {
|
||||
match *self {
|
||||
PowerLevel::Unknown => sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN,
|
||||
PowerLevel::Empty => sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_EMPTY,
|
||||
PowerLevel::Low => sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_LOW,
|
||||
PowerLevel::Medium => sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_MEDIUM,
|
||||
PowerLevel::Full => sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_FULL,
|
||||
PowerLevel::Wired => sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_WIRED,
|
||||
PowerLevel::Unknown => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN,
|
||||
PowerLevel::Empty => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_EMPTY,
|
||||
PowerLevel::Low => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_LOW,
|
||||
PowerLevel::Medium => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_MEDIUM,
|
||||
PowerLevel::Full => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_FULL,
|
||||
PowerLevel::Wired => SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_WIRED,
|
||||
}
|
||||
|
||||
}
|
||||
@@ -166,7 +167,7 @@ impl Joystick {
|
||||
pub fn guid(&self) -> Guid {
|
||||
let raw = unsafe { sys::SDL_JoystickGetGUID(self.raw) };
|
||||
|
||||
let guid = Guid { raw: raw };
|
||||
let guid = Guid { raw };
|
||||
|
||||
if guid.is_zero() {
|
||||
// Should only fail if the joystick is NULL.
|
||||
@@ -185,7 +186,7 @@ impl Joystick {
|
||||
|
||||
let state = PowerLevel::from_ll(result);
|
||||
|
||||
if result != sys::SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN {
|
||||
if result != SDL_JoystickPowerLevel::SDL_JOYSTICK_POWER_UNKNOWN {
|
||||
Ok(state)
|
||||
} else {
|
||||
let err = get_error();
|
||||
@@ -407,7 +408,7 @@ impl Guid {
|
||||
|
||||
let raw = unsafe { sys::SDL_JoystickGetGUIDFromString(guid.as_ptr() as *const c_char) };
|
||||
|
||||
Ok(Guid { raw: raw })
|
||||
Ok(Guid { raw })
|
||||
}
|
||||
|
||||
/// Return `true` if GUID is full 0s
|
||||
@@ -488,7 +489,11 @@ impl HatState {
|
||||
6 => HatState::RightDown,
|
||||
9 => HatState::LeftUp,
|
||||
12 => HatState::LeftDown,
|
||||
_ => panic!("Unexpected hat position: {}", raw),
|
||||
|
||||
// The Xinput driver on Windows can report hat states on certain hardware that don't
|
||||
// make any sense from a gameplay perspective, and so aren't worth putting in the
|
||||
// HatState enumeration.
|
||||
_ => HatState::Centered,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::EventPump;
|
||||
use crate::rect::Rect;
|
||||
use crate::video::Window;
|
||||
|
||||
use std::fmt;
|
||||
use std::mem::transmute;
|
||||
|
||||
use crate::sys;
|
||||
@@ -28,6 +30,12 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Mod {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:04x}", *self)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct KeyboardState<'a> {
|
||||
keyboard_state: &'a [u8]
|
||||
}
|
||||
@@ -42,7 +50,7 @@ impl<'a> KeyboardState<'a> {
|
||||
};
|
||||
|
||||
KeyboardState {
|
||||
keyboard_state: keyboard_state
|
||||
keyboard_state
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+487
-486
File diff suppressed because it is too large
Load Diff
+110
-109
File diff suppressed because it is too large
Load Diff
+17
-16
@@ -5,6 +5,7 @@ use crate::EventPump;
|
||||
use std::mem::transmute;
|
||||
|
||||
use crate::sys;
|
||||
use crate::sys::SDL_SystemCursor;
|
||||
|
||||
mod relative;
|
||||
pub use self::relative::RelativeMouseState;
|
||||
@@ -12,18 +13,18 @@ pub use self::relative::RelativeMouseState;
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
#[repr(u32)]
|
||||
pub enum SystemCursor {
|
||||
Arrow = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_ARROW as u32,
|
||||
IBeam = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_IBEAM as u32,
|
||||
Wait = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_WAIT as u32,
|
||||
Crosshair = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_CROSSHAIR as u32,
|
||||
WaitArrow = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_WAITARROW as u32,
|
||||
SizeNWSE = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZENWSE as u32,
|
||||
SizeNESW = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZENESW as u32,
|
||||
SizeWE = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZEWE as u32,
|
||||
SizeNS = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZENS as u32,
|
||||
SizeAll = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZEALL as u32,
|
||||
No = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_NO as u32,
|
||||
Hand = sys::SDL_SystemCursor::SDL_SYSTEM_CURSOR_HAND as u32,
|
||||
Arrow = SDL_SystemCursor::SDL_SYSTEM_CURSOR_ARROW as u32,
|
||||
IBeam = SDL_SystemCursor::SDL_SYSTEM_CURSOR_IBEAM as u32,
|
||||
Wait = SDL_SystemCursor::SDL_SYSTEM_CURSOR_WAIT as u32,
|
||||
Crosshair = SDL_SystemCursor::SDL_SYSTEM_CURSOR_CROSSHAIR as u32,
|
||||
WaitArrow = SDL_SystemCursor::SDL_SYSTEM_CURSOR_WAITARROW as u32,
|
||||
SizeNWSE = SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZENWSE as u32,
|
||||
SizeNESW = SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZENESW as u32,
|
||||
SizeWE = SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZEWE as u32,
|
||||
SizeNS = SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZENS as u32,
|
||||
SizeAll = SDL_SystemCursor::SDL_SYSTEM_CURSOR_SIZEALL as u32,
|
||||
No = SDL_SystemCursor::SDL_SYSTEM_CURSOR_NO as u32,
|
||||
Hand = SDL_SystemCursor::SDL_SYSTEM_CURSOR_HAND as u32,
|
||||
}
|
||||
|
||||
pub struct Cursor {
|
||||
@@ -48,7 +49,7 @@ impl Cursor {
|
||||
if raw.is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(Cursor{ raw: raw })
|
||||
Ok(Cursor{ raw })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +62,7 @@ impl Cursor {
|
||||
if raw.is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(Cursor{ raw: raw })
|
||||
Ok(Cursor{ raw })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +74,7 @@ impl Cursor {
|
||||
if raw.is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(Cursor{ raw: raw })
|
||||
Ok(Cursor{ raw })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +168,7 @@ impl MouseState {
|
||||
};
|
||||
|
||||
MouseState {
|
||||
mouse_state: mouse_state,
|
||||
mouse_state,
|
||||
x: x as i32,
|
||||
y: y as i32
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ impl RelativeMouseState {
|
||||
};
|
||||
|
||||
RelativeMouseState {
|
||||
mouse_state: mouse_state,
|
||||
mouse_state,
|
||||
x: x as i32,
|
||||
y: y as i32
|
||||
}
|
||||
|
||||
+23
-7
@@ -5,6 +5,7 @@ use self::rand::distributions::{Distribution, Standard};
|
||||
use libc::uint32_t;
|
||||
use num::FromPrimitive;
|
||||
use std::mem::transmute;
|
||||
use std::convert::TryFrom;
|
||||
use crate::sys;
|
||||
|
||||
use crate::get_error;
|
||||
@@ -38,7 +39,7 @@ impl Palette {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(Palette {
|
||||
raw: raw,
|
||||
raw,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -107,13 +108,13 @@ impl Color {
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn RGB(r: u8, g: u8, b: u8) -> Color {
|
||||
Color { r: r, g: g, b: b, a: 0xff }
|
||||
Color { r, g, b, a: 0xff }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn RGBA(r: u8, g: u8, b: u8, a: u8) -> Color {
|
||||
Color { r: r, g: g, b: b, a: a }
|
||||
Color { r, g, b, a }
|
||||
}
|
||||
|
||||
pub fn to_u32(&self, format: &PixelFormat) -> u32 {
|
||||
@@ -283,10 +284,10 @@ impl PixelFormatEnum {
|
||||
} else {
|
||||
Ok(PixelMasks {
|
||||
bpp: bpp as u8,
|
||||
rmask: rmask,
|
||||
gmask: gmask,
|
||||
bmask: bmask,
|
||||
amask: amask
|
||||
rmask,
|
||||
gmask,
|
||||
bmask,
|
||||
amask
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -460,6 +461,21 @@ impl FromPrimitive for PixelFormatEnum {
|
||||
fn from_u64(n: u64) -> Option<PixelFormatEnum> { FromPrimitive::from_i64(n as i64) }
|
||||
}
|
||||
|
||||
impl TryFrom<PixelFormatEnum> for PixelFormat {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(pfe: PixelFormatEnum) -> Result<Self, Self::Error> {
|
||||
unsafe {
|
||||
let pf_ptr = sys::SDL_AllocFormat(pfe as u32);
|
||||
if pf_ptr.is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(PixelFormat::from_ll(pf_ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Just test a round-trip conversion from PixelFormat to
|
||||
// PixelFormatEnum and back.
|
||||
|
||||
+2
-2
@@ -115,7 +115,7 @@ impl Rect {
|
||||
w: clamp_size(width) as i32,
|
||||
h: clamp_size(height) as i32,
|
||||
};
|
||||
Rect { raw: raw }
|
||||
Rect { raw }
|
||||
}
|
||||
|
||||
/// Creates a new rectangle centered on the given position.
|
||||
@@ -136,7 +136,7 @@ impl Rect {
|
||||
w: clamp_size(width) as i32,
|
||||
h: clamp_size(height) as i32,
|
||||
};
|
||||
let mut rect = Rect { raw: raw };
|
||||
let mut rect = Rect { raw };
|
||||
rect.center_on(center.into());
|
||||
rect
|
||||
}
|
||||
|
||||
+41
-39
@@ -53,6 +53,8 @@ use std::mem::{transmute, uninitialized};
|
||||
use libc::c_void;
|
||||
|
||||
use crate::sys;
|
||||
use crate::sys::SDL_TextureAccess;
|
||||
use crate::sys::SDL_BlendMode;
|
||||
|
||||
/// Contains the description of an error returned by SDL
|
||||
#[derive(Debug)]
|
||||
@@ -102,9 +104,9 @@ impl Error for TargetRenderError {
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
#[repr(i32)]
|
||||
pub enum TextureAccess {
|
||||
Static = sys::SDL_TextureAccess::SDL_TEXTUREACCESS_STATIC as i32,
|
||||
Streaming = sys::SDL_TextureAccess::SDL_TEXTUREACCESS_STREAMING as i32,
|
||||
Target = sys::SDL_TextureAccess::SDL_TEXTUREACCESS_TARGET as i32,
|
||||
Static = SDL_TextureAccess::SDL_TEXTUREACCESS_STATIC as i32,
|
||||
Streaming = SDL_TextureAccess::SDL_TEXTUREACCESS_STREAMING as i32,
|
||||
Target = SDL_TextureAccess::SDL_TEXTUREACCESS_TARGET as i32,
|
||||
}
|
||||
|
||||
impl FromPrimitive for TextureAccess {
|
||||
@@ -112,10 +114,10 @@ impl FromPrimitive for TextureAccess {
|
||||
use self::TextureAccess::*;
|
||||
let n = n as u32;
|
||||
|
||||
Some(match unsafe { transmute::<u32, sys::SDL_TextureAccess>(n) } {
|
||||
sys::SDL_TextureAccess::SDL_TEXTUREACCESS_STATIC => Static,
|
||||
sys::SDL_TextureAccess::SDL_TEXTUREACCESS_STREAMING => Streaming,
|
||||
sys::SDL_TextureAccess::SDL_TEXTUREACCESS_TARGET => Target,
|
||||
Some(match unsafe { transmute::<u32, SDL_TextureAccess>(n) } {
|
||||
SDL_TextureAccess::SDL_TEXTUREACCESS_STATIC => Static,
|
||||
SDL_TextureAccess::SDL_TEXTUREACCESS_STREAMING => Streaming,
|
||||
SDL_TextureAccess::SDL_TEXTUREACCESS_TARGET => Target,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -138,11 +140,11 @@ pub struct RendererInfo {
|
||||
#[repr(i32)]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
pub enum BlendMode {
|
||||
None = sys::SDL_BlendMode::SDL_BLENDMODE_NONE as i32,
|
||||
Blend = sys::SDL_BlendMode::SDL_BLENDMODE_BLEND as i32,
|
||||
Add = sys::SDL_BlendMode::SDL_BLENDMODE_ADD as i32,
|
||||
Mod = sys::SDL_BlendMode::SDL_BLENDMODE_MOD as i32,
|
||||
Invalid = sys::SDL_BlendMode::SDL_BLENDMODE_INVALID as i32,
|
||||
None = SDL_BlendMode::SDL_BLENDMODE_NONE as i32,
|
||||
Blend = SDL_BlendMode::SDL_BLENDMODE_BLEND as i32,
|
||||
Add = SDL_BlendMode::SDL_BLENDMODE_ADD as i32,
|
||||
Mod = SDL_BlendMode::SDL_BLENDMODE_MOD as i32,
|
||||
Invalid = SDL_BlendMode::SDL_BLENDMODE_INVALID as i32,
|
||||
}
|
||||
|
||||
impl FromPrimitive for BlendMode {
|
||||
@@ -150,12 +152,12 @@ impl FromPrimitive for BlendMode {
|
||||
use self::BlendMode::*;
|
||||
let n = n as u32;
|
||||
|
||||
Some(match unsafe { transmute::<u32, sys::SDL_BlendMode>(n) } {
|
||||
sys::SDL_BlendMode::SDL_BLENDMODE_NONE => None,
|
||||
sys::SDL_BlendMode::SDL_BLENDMODE_BLEND => Blend,
|
||||
sys::SDL_BlendMode::SDL_BLENDMODE_ADD => Add,
|
||||
sys::SDL_BlendMode::SDL_BLENDMODE_MOD => Mod,
|
||||
sys::SDL_BlendMode::SDL_BLENDMODE_INVALID => Invalid,
|
||||
Some(match unsafe { transmute::<u32, SDL_BlendMode>(n) } {
|
||||
SDL_BlendMode::SDL_BLENDMODE_NONE => None,
|
||||
SDL_BlendMode::SDL_BLENDMODE_BLEND => Blend,
|
||||
SDL_BlendMode::SDL_BLENDMODE_ADD => Add,
|
||||
SDL_BlendMode::SDL_BLENDMODE_MOD => Mod,
|
||||
SDL_BlendMode::SDL_BLENDMODE_INVALID => Invalid,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -179,9 +181,9 @@ impl RendererInfo {
|
||||
let name = CStr::from_ptr(info.name as *const _).to_str().unwrap();
|
||||
|
||||
RendererInfo {
|
||||
name: name,
|
||||
name,
|
||||
flags: info.flags,
|
||||
texture_formats: texture_formats,
|
||||
texture_formats,
|
||||
max_texture_width: info.max_texture_width as u32,
|
||||
max_texture_height: info.max_texture_height as u32,
|
||||
}
|
||||
@@ -225,7 +227,7 @@ impl<T> RendererContext<T> {
|
||||
|
||||
pub unsafe fn from_ll(raw: *mut sys::SDL_Renderer, target: Rc<T>) -> Self {
|
||||
RendererContext {
|
||||
raw: raw,
|
||||
raw,
|
||||
_target: target,
|
||||
}
|
||||
}
|
||||
@@ -342,8 +344,8 @@ impl<'s> Canvas<Surface<'s>> {
|
||||
let default_pixel_format = surface.pixel_format_enum();
|
||||
Ok(Canvas {
|
||||
target: surface,
|
||||
context: context,
|
||||
default_pixel_format: default_pixel_format,
|
||||
context,
|
||||
default_pixel_format,
|
||||
})
|
||||
} else {
|
||||
Err(get_error())
|
||||
@@ -407,7 +409,7 @@ impl Canvas<Window> {
|
||||
pub fn into_window(self) -> Window {
|
||||
self.target
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn default_pixel_format(&self) -> PixelFormatEnum {
|
||||
self.window().window_pixel_format()
|
||||
@@ -588,7 +590,7 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
Err(TargetRenderError::NotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "unsafe_textures")]
|
||||
pub fn with_multiple_texture_canvas<'a : 's, 's, I, F, U: 's>(&mut self, textures: I, mut f: F)
|
||||
-> Result<(), TargetRenderError>
|
||||
@@ -640,7 +642,7 @@ impl CanvasBuilder {
|
||||
/// Initializes a new `CanvasBuilder`.
|
||||
pub fn new(window: Window) -> CanvasBuilder {
|
||||
CanvasBuilder {
|
||||
window: window,
|
||||
window,
|
||||
// -1 means to initialize the first rendering driver supporting the
|
||||
// renderer flags
|
||||
index: None,
|
||||
@@ -665,9 +667,9 @@ impl CanvasBuilder {
|
||||
let context = Rc::new(unsafe { RendererContext::from_ll(raw, self.window.context()) });
|
||||
let default_pixel_format = self.window.window_pixel_format();
|
||||
Ok(Canvas {
|
||||
context: context,
|
||||
context,
|
||||
target: self.window,
|
||||
default_pixel_format: default_pixel_format,
|
||||
default_pixel_format,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -881,16 +883,16 @@ impl<T> TextureCreator<T> {
|
||||
#[inline]
|
||||
pub unsafe fn raw_create_texture(&self, raw: *mut sys::SDL_Texture) -> Texture {
|
||||
Texture {
|
||||
raw: raw,
|
||||
raw,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Create a texture from its raw `SDL_Texture`. Should be used with care.
|
||||
#[cfg(feature = "unsafe_textures")]
|
||||
pub unsafe fn raw_create_texture(&self, raw: *mut sys::SDL_Texture) -> Texture {
|
||||
Texture {
|
||||
raw: raw,
|
||||
raw,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -937,7 +939,7 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
|
||||
/// Gets the blend mode used for drawing operations.
|
||||
pub fn blend_mode(&self) -> BlendMode {
|
||||
let mut blend: sys::SDL_BlendMode;
|
||||
let mut blend: SDL_BlendMode;
|
||||
unsafe { blend = uninitialized(); }
|
||||
let ret = unsafe { sys::SDL_GetRenderDrawBlendMode(self.context.raw, &mut blend) };
|
||||
// Should only fail on an invalid renderer
|
||||
@@ -1426,7 +1428,7 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
unsafe { Ok(self.raw_create_texture(result)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "unsafe_textures")]
|
||||
/// Create a texture from its raw `SDL_Texture`. Should be used with care.
|
||||
///
|
||||
@@ -1435,7 +1437,7 @@ impl<T: RenderTarget> Canvas<T> {
|
||||
/// Note that this method is only accessible in Canvas with the `unsafe_textures` feature.
|
||||
pub unsafe fn raw_create_texture(&self, raw: *mut sys::SDL_Texture) -> Texture {
|
||||
Texture {
|
||||
raw: raw,
|
||||
raw,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1737,7 +1739,7 @@ impl InternalTexture {
|
||||
}
|
||||
|
||||
pub fn blend_mode(&self) -> BlendMode {
|
||||
let mut blend: sys::SDL_BlendMode;
|
||||
let mut blend: SDL_BlendMode;
|
||||
unsafe { blend = uninitialized(); }
|
||||
let ret = unsafe { sys::SDL_GetTextureBlendMode(self.raw, &mut blend) };
|
||||
|
||||
@@ -1873,7 +1875,7 @@ impl InternalTexture {
|
||||
plane: "y",
|
||||
length: y_plane.len(),
|
||||
pitch: y_pitch,
|
||||
height: height,
|
||||
height,
|
||||
});
|
||||
}
|
||||
if u_plane.len() != (u_pitch * height / 2) {
|
||||
@@ -2027,7 +2029,7 @@ impl<'r> Texture<'r> {
|
||||
pub fn set_color_mod(&mut self, red: u8, green: u8, blue: u8) {
|
||||
InternalTexture{ raw: self.raw }.set_color_mod(red, green, blue)
|
||||
}
|
||||
|
||||
|
||||
/// Gets the additional color value multiplied into render copy operations.
|
||||
#[inline]
|
||||
pub fn color_mod(&self) -> (u8, u8, u8) {
|
||||
@@ -2106,7 +2108,7 @@ impl<'r> Texture<'r> {
|
||||
{
|
||||
InternalTexture { raw: self.raw }.with_lock(rect, func)
|
||||
}
|
||||
|
||||
|
||||
/// Binds an OpenGL/ES/ES2 texture to the current
|
||||
/// context for use with when rendering OpenGL primitives directly.
|
||||
#[inline]
|
||||
@@ -2224,7 +2226,7 @@ impl<> Texture<> {
|
||||
{
|
||||
InternalTexture { raw: self.raw }.with_lock(rect, func)
|
||||
}
|
||||
|
||||
|
||||
/// Binds an OpenGL/ES/ES2 texture to the current
|
||||
/// context for use with when rendering OpenGL primitives directly.
|
||||
#[inline]
|
||||
|
||||
+4
-4
@@ -20,7 +20,7 @@ impl<'a> RWops<'a> {
|
||||
|
||||
pub unsafe fn from_ll<'b>(raw: *mut sys::SDL_RWops) -> RWops<'b> {
|
||||
RWops {
|
||||
raw: raw,
|
||||
raw,
|
||||
_marker: PhantomData
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ impl<'a> RWops<'a> {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(RWops {
|
||||
raw: raw,
|
||||
raw,
|
||||
_marker: PhantomData
|
||||
})
|
||||
}
|
||||
@@ -55,7 +55,7 @@ impl<'a> RWops<'a> {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(RWops {
|
||||
raw: raw,
|
||||
raw,
|
||||
_marker: PhantomData
|
||||
})
|
||||
}
|
||||
@@ -88,7 +88,7 @@ impl<'a> RWops<'a> {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(RWops {
|
||||
raw: raw,
|
||||
raw,
|
||||
_marker: PhantomData
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ impl<'a> AsMut<SurfaceRef> for Surface<'a> {
|
||||
impl<'a> Surface<'a> {
|
||||
pub unsafe fn from_ll<'b>(raw: *mut sys::SDL_Surface) -> Surface<'b> {
|
||||
let context = SurfaceContext {
|
||||
raw: raw,
|
||||
raw,
|
||||
_marker: PhantomData,
|
||||
};
|
||||
Surface { context: Rc::new(context) }
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ impl TimerSubsystem {
|
||||
}
|
||||
}
|
||||
|
||||
pub type TimerCallback<'a> = Box<FnMut() -> u32+'a+Sync>;
|
||||
pub type TimerCallback<'a> = Box<dyn FnMut() -> u32+'a+Sync>;
|
||||
|
||||
pub struct Timer<'b, 'a> {
|
||||
callback: Option<Box<TimerCallback<'a>>>,
|
||||
@@ -82,7 +82,7 @@ impl<'b, 'a> Drop for Timer<'b, 'a> {
|
||||
|
||||
extern "C" fn c_timer_callback(_interval: u32, param: *mut c_void) -> uint32_t {
|
||||
unsafe {
|
||||
let f: *mut Box<Fn() -> u32> = mem::transmute(param);
|
||||
let f: *mut Box<dyn Fn() -> u32> = mem::transmute(param);
|
||||
(*f)() as uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user