mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
fix compile error under newest rust
This commit is contained in:
+5
-6
@@ -1,4 +1,3 @@
|
||||
use std::cast;
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
use std::c_str::CString;
|
||||
@@ -209,11 +208,11 @@ pub struct AudioSpec<'a > {
|
||||
|
||||
extern "C" fn c_audio_callback(userdata: *c_void, stream: *uint8_t, len: c_int) {
|
||||
unsafe {
|
||||
let f : &mut |&mut [u8]| = cast::transmute(userdata);
|
||||
let f : &mut |&mut [u8]| = mem::transmute(userdata);
|
||||
|
||||
// FIXME: lifetime error in calling
|
||||
//slice::raw::mut_buf_as_slice(stream as *mut u8, len as uint, *f)
|
||||
(*f)(cast::transmute(Slice {
|
||||
(*f)(mem::transmute(Slice {
|
||||
data: stream,
|
||||
len: len as uint
|
||||
}))
|
||||
@@ -232,7 +231,7 @@ impl<'a> AudioSpec<'a> {
|
||||
let audio_buf = ptr::null::<u8>();
|
||||
let audio_len = 0u32;
|
||||
unsafe {
|
||||
let ret = ll::SDL_LoadWAV_RW(src.raw, 0, cast::transmute(&spec), &audio_buf, &audio_len);
|
||||
let ret = ll::SDL_LoadWAV_RW(src.raw, 0, mem::transmute(&spec), &audio_buf, &audio_len);
|
||||
if ret.is_null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
@@ -272,8 +271,8 @@ impl AudioDevice {
|
||||
};
|
||||
let ret = ll::SDL_OpenAudioDevice(device_c_str,
|
||||
iscapture as c_int,
|
||||
cast::transmute(spec),
|
||||
cast::transmute(&obtained),
|
||||
mem::transmute(spec),
|
||||
mem::transmute(&obtained),
|
||||
0);
|
||||
if ret == 0 {
|
||||
Err(get_error())
|
||||
|
||||
@@ -2,7 +2,7 @@ use libc::c_int;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub mod ll {
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use libc::{c_int, c_char, c_uchar, c_uint, c_void, int16_t, uint8_t};
|
||||
use joystick::ll::{SDL_Joystick, SDL_JoystickGUID};
|
||||
|
||||
@@ -32,13 +32,13 @@ pub mod ll {
|
||||
|
||||
impl SDL_GameControllerButtonBindData {
|
||||
pub fn button(&self) -> *c_int {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
pub fn axis(&self) -> *c_int {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
pub fn hat(&self) -> *SDL_GameControllerButtonBindDataHat {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
-36
@@ -2,7 +2,7 @@
|
||||
Event Handling
|
||||
*/
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use libc::{c_int, c_void, uint32_t};
|
||||
use std::num::FromPrimitive;
|
||||
use std::str;
|
||||
@@ -25,7 +25,7 @@ use get_error;
|
||||
#[doc(hidden)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub mod ll {
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use libc::{c_float, c_int, c_char, c_uint, c_void, int16_t,
|
||||
int32_t, uint8_t, uint16_t, uint32_t};
|
||||
use gesture::ll::SDL_GestureID;
|
||||
@@ -314,99 +314,99 @@ pub mod ll {
|
||||
|
||||
impl SDL_Event {
|
||||
pub fn _type(&self) -> *uint32_t {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn common(&self) -> *SDL_CommonEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn window(&self) -> *SDL_WindowEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn key(&self) -> *SDL_KeyboardEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn edit(&self) -> *SDL_TextEditingEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn text(&self) -> *SDL_TextInputEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn motion(&self) -> *SDL_MouseMotionEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn button(&self) -> *SDL_MouseButtonEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn wheel(&self) -> *SDL_MouseWheelEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn jaxis(&self) -> *SDL_JoyAxisEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn jball(&self) -> *SDL_JoyBallEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn jhat(&self) -> *SDL_JoyHatEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn jbutton(&self) -> *SDL_JoyButtonEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn jdevice(&self) -> *SDL_JoyDeviceEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn caxis(&self) -> *SDL_ControllerAxisEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn cbutton(&self) -> *SDL_ControllerButtonEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn cdevice(&self) -> *SDL_ControllerDeviceEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn quit(&self) -> *SDL_QuitEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn user(&self) -> *SDL_UserEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn syswm(&self) -> *SDL_SysWMEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn tfinger(&self) -> *SDL_TouchFingerEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn mgesture(&self) -> *SDL_MultiGestureEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn dgesture(&self) -> *SDL_DollarGestureEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
|
||||
pub fn drop(&self) -> *SDL_DropEvent {
|
||||
unsafe { cast::transmute_copy(&self) }
|
||||
unsafe { mem::transmute_copy(&self) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ impl Event {
|
||||
data2: ptr::null(),
|
||||
};
|
||||
unsafe {
|
||||
ptr::copy_memory(cast::transmute::<_,*mut ll::SDL_UserEvent>(&ret), &event, 1);
|
||||
ptr::copy_memory(mem::transmute::<_,*mut ll::SDL_UserEvent>(&ret), &event, 1);
|
||||
}
|
||||
Some(ret)
|
||||
},
|
||||
@@ -785,7 +785,7 @@ impl Event {
|
||||
Ok(window) => window,
|
||||
};
|
||||
|
||||
let text = str::from_utf8_owned(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<~[u8]>()).unwrap_or("".to_owned());
|
||||
let text = str::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<Vec<u8>>().as_slice()).into_owned();
|
||||
TextEditingEvent(event.timestamp as uint, window, text,
|
||||
event.start as int, event.length as int)
|
||||
}
|
||||
@@ -798,8 +798,8 @@ impl Event {
|
||||
Ok(window) => window,
|
||||
};
|
||||
|
||||
let text = str::from_utf8_owned(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<~[u8]>()).unwrap_or("".to_owned());
|
||||
TextInputEvent(event.timestamp as uint, window, text)
|
||||
let text = str::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::<Vec<u8>>().as_slice()).into_owned();
|
||||
TextInputEvent(event.timestamp as uint, window, text.to_owned())
|
||||
}
|
||||
|
||||
MouseMotionEventType => {
|
||||
@@ -1081,33 +1081,33 @@ pub fn wait_event_timeout(timeout: int) -> Result<Event, ~str> {
|
||||
}
|
||||
|
||||
extern "C" fn event_filter_wrapper(userdata: *c_void, event: *ll::SDL_Event) -> c_int {
|
||||
let filter: extern fn(event: Event) -> bool = unsafe { cast::transmute(userdata) };
|
||||
let filter: extern fn(event: Event) -> bool = unsafe { mem::transmute(userdata) };
|
||||
if event.is_null() { 1 }
|
||||
else { filter(Event::from_ll(unsafe { cast::transmute(event) })) as c_int }
|
||||
else { filter(Event::from_ll(unsafe { mem::transmute(event) })) as c_int }
|
||||
}
|
||||
|
||||
/// Set up a filter to process all events before they change internal state and are posted to the internal event queue.
|
||||
pub fn set_event_filter(filter_func: extern fn(event: Event) -> bool) {
|
||||
unsafe { ll::SDL_SetEventFilter(event_filter_wrapper,
|
||||
cast::transmute(filter_func)) }
|
||||
mem::transmute(filter_func)) }
|
||||
}
|
||||
|
||||
/// Add a callback to be triggered when an event is added to the event queue.
|
||||
pub fn add_event_watch(filter_func: extern fn(event: Event) -> bool) {
|
||||
unsafe { ll::SDL_AddEventWatch(event_filter_wrapper,
|
||||
cast::transmute(filter_func)) }
|
||||
mem::transmute(filter_func)) }
|
||||
}
|
||||
|
||||
/// Remove an event watch callback added.
|
||||
pub fn delete_event_watch(filter_func: extern fn(event: Event) -> bool) {
|
||||
unsafe { ll::SDL_DelEventWatch(event_filter_wrapper,
|
||||
cast::transmute(filter_func)) }
|
||||
mem::transmute(filter_func)) }
|
||||
}
|
||||
|
||||
/// Run a specific filter function on the current event queue, removing any events for which the filter returns 0.
|
||||
pub fn filter_events(filter_func: extern fn(event: Event) -> bool) {
|
||||
unsafe { ll::SDL_FilterEvents(event_filter_wrapper,
|
||||
cast::transmute(filter_func)) }
|
||||
mem::transmute(filter_func)) }
|
||||
}
|
||||
|
||||
/// Set the state of processing events.
|
||||
|
||||
@@ -2,7 +2,7 @@ use collections::hashmap::HashMap;
|
||||
use std::num::FromPrimitive;
|
||||
use std::ptr;
|
||||
use std::str;
|
||||
use std::slice;
|
||||
use std::vec;
|
||||
|
||||
use keycode::KeyCode;
|
||||
use rect::Rect;
|
||||
@@ -79,13 +79,13 @@ pub fn get_keyboard_state() -> HashMap<ScanCode, bool> {
|
||||
let mut state: HashMap<ScanCode, bool> = HashMap::new();
|
||||
let count = 0;
|
||||
|
||||
let raw = unsafe { slice::raw::from_buf_raw(ll::SDL_GetKeyboardState(&count),
|
||||
count as uint) };
|
||||
let raw = unsafe { vec::raw::from_buf(ll::SDL_GetKeyboardState(&count),
|
||||
count as uint) };
|
||||
|
||||
let mut current = 0;
|
||||
while current < raw.len() {
|
||||
state.insert(FromPrimitive::from_int(current as int).unwrap(),
|
||||
raw[current] == 1);
|
||||
*raw.get(current) == 1);
|
||||
current += 1;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
Rectangle Functions
|
||||
*/
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use libc::c_int;
|
||||
|
||||
/// A structure that defines a two dimensional point.
|
||||
@@ -67,9 +67,9 @@ impl Rect {
|
||||
|
||||
let result = unsafe {
|
||||
ll::SDL_EnclosePoints(
|
||||
cast::transmute(points.as_ptr()),
|
||||
mem::transmute(points.as_ptr()),
|
||||
points.len() as c_int,
|
||||
cast::transmute(clip.as_ref()),
|
||||
mem::transmute(clip.as_ref()),
|
||||
&out
|
||||
) != 0
|
||||
};
|
||||
|
||||
+16
-16
@@ -6,7 +6,7 @@ use std::ptr;
|
||||
use libc;
|
||||
use libc::{c_int, uint32_t, c_float, c_double, c_void, size_t};
|
||||
use std::str;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use rect::Point;
|
||||
use rect::Rect;
|
||||
use std::num::FromPrimitive;
|
||||
@@ -188,7 +188,7 @@ impl RendererInfo {
|
||||
}).collect();
|
||||
|
||||
RendererInfo {
|
||||
name: str::raw::from_c_str(cast::transmute_copy(&info.name)),
|
||||
name: str::raw::from_c_str(mem::transmute_copy(&info.name)),
|
||||
flags: actual_flags,
|
||||
texture_formats: texture_formats,
|
||||
max_texture_width: info.max_texture_width as int,
|
||||
@@ -345,7 +345,7 @@ impl Renderer {
|
||||
pub fn set_render_target(&self, texture: Option<&Texture>) -> Result<(), ~str> {
|
||||
unsafe {
|
||||
let actual_texture = match texture {
|
||||
Some(texture) => cast::transmute(texture.raw),
|
||||
Some(texture) => mem::transmute(texture.raw),
|
||||
None => ptr::null()
|
||||
};
|
||||
if ll::SDL_SetRenderTarget(self.raw, actual_texture) == 0 {
|
||||
@@ -445,7 +445,7 @@ impl Renderer {
|
||||
|
||||
pub fn draw_points(&self, points: &[Point]) -> Result<(), ~str> {
|
||||
let ret = unsafe {
|
||||
ll::SDL_RenderDrawPoints(self.raw, cast::transmute(points.as_ptr()), points.len() as c_int)
|
||||
ll::SDL_RenderDrawPoints(self.raw, mem::transmute(points.as_ptr()), points.len() as c_int)
|
||||
};
|
||||
|
||||
if ret == 0 { Ok(()) }
|
||||
@@ -461,7 +461,7 @@ impl Renderer {
|
||||
|
||||
pub fn draw_lines(&self, points: &[Point]) -> Result<(), ~str> {
|
||||
let ret = unsafe {
|
||||
ll::SDL_RenderDrawLines(self.raw, cast::transmute(points.as_ptr()), points.len() as c_int)
|
||||
ll::SDL_RenderDrawLines(self.raw, mem::transmute(points.as_ptr()), points.len() as c_int)
|
||||
};
|
||||
|
||||
if ret == 0 { Ok(()) }
|
||||
@@ -477,7 +477,7 @@ impl Renderer {
|
||||
|
||||
pub fn draw_rects(&self, rects: &[Rect]) -> Result<(), ~str> {
|
||||
let ret = unsafe {
|
||||
ll::SDL_RenderDrawRects(self.raw, cast::transmute(rects.as_ptr()), rects.len() as c_int)
|
||||
ll::SDL_RenderDrawRects(self.raw, mem::transmute(rects.as_ptr()), rects.len() as c_int)
|
||||
};
|
||||
|
||||
if ret == 0 { Ok(()) }
|
||||
@@ -493,7 +493,7 @@ impl Renderer {
|
||||
|
||||
pub fn fill_rects(&self, rects: &[Rect]) -> Result<(), ~str> {
|
||||
let ret = unsafe {
|
||||
ll::SDL_RenderFillRects(self.raw, cast::transmute(rects.as_ptr()), rects.len() as c_int)
|
||||
ll::SDL_RenderFillRects(self.raw, mem::transmute(rects.as_ptr()), rects.len() as c_int)
|
||||
};
|
||||
|
||||
if ret == 0 { Ok(()) }
|
||||
@@ -506,11 +506,11 @@ impl Renderer {
|
||||
self.raw,
|
||||
texture.raw,
|
||||
match src {
|
||||
Some(rect) => cast::transmute(&rect),
|
||||
Some(rect) => mem::transmute(&rect),
|
||||
None => ptr::null()
|
||||
},
|
||||
match dst {
|
||||
Some(rect) => cast::transmute(&rect),
|
||||
Some(rect) => mem::transmute(&rect),
|
||||
None => ptr::null()
|
||||
}
|
||||
)
|
||||
@@ -527,16 +527,16 @@ impl Renderer {
|
||||
self.raw,
|
||||
texture.raw,
|
||||
match src {
|
||||
Some(rect) => cast::transmute(&rect),
|
||||
Some(rect) => mem::transmute(&rect),
|
||||
None => ptr::null()
|
||||
},
|
||||
match dst {
|
||||
Some(rect) => cast::transmute(&rect),
|
||||
Some(rect) => mem::transmute(&rect),
|
||||
None => ptr::null()
|
||||
},
|
||||
angle as c_double,
|
||||
match center {
|
||||
Some(point) => cast::transmute(&point),
|
||||
Some(point) => mem::transmute(&point),
|
||||
None => ptr::null()
|
||||
},
|
||||
FromPrimitive::from_i64(flip as i64).unwrap()
|
||||
@@ -550,7 +550,7 @@ impl Renderer {
|
||||
pub fn read_pixels(&self, rect: Option<Rect>, format: pixels::PixelFormatFlag) -> Result<CVec<u8>, ~str> {
|
||||
unsafe {
|
||||
let (actual_rect, w, h) = match rect {
|
||||
Some(rect) => (cast::transmute(&rect), rect.w as uint, rect.h as uint),
|
||||
Some(rect) => (mem::transmute(&rect), rect.w as uint, rect.h as uint),
|
||||
None => {
|
||||
let (w, h) = try!(self.get_output_size());
|
||||
(ptr::null(), w as uint, h as uint)
|
||||
@@ -673,11 +673,11 @@ impl Texture {
|
||||
pub fn update(&self, rect: Option<Rect>, pixel_data: &[u8], pitch: int) -> Result<(), ~str> {
|
||||
let ret = unsafe {
|
||||
let actual_rect = match rect {
|
||||
Some(rect) => cast::transmute(&rect),
|
||||
Some(rect) => mem::transmute(&rect),
|
||||
None => ptr::null()
|
||||
};
|
||||
|
||||
ll::SDL_UpdateTexture(self.raw, actual_rect, cast::transmute(pixel_data.as_ptr()), pitch as c_int)
|
||||
ll::SDL_UpdateTexture(self.raw, actual_rect, mem::transmute(pixel_data.as_ptr()), pitch as c_int)
|
||||
};
|
||||
|
||||
if ret == 0 { Ok(()) }
|
||||
@@ -688,7 +688,7 @@ impl Texture {
|
||||
let q = try!(self.query());
|
||||
unsafe {
|
||||
let actual_rect = match rect {
|
||||
Some(rect) => cast::transmute(&rect),
|
||||
Some(rect) => mem::transmute(&rect),
|
||||
None => ptr::null()
|
||||
};
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::str;
|
||||
|
||||
// Setup linking for all targets.
|
||||
@@ -113,7 +113,7 @@ pub fn get_error() -> ~str {
|
||||
unsafe {
|
||||
let cstr = ll::SDL_GetError();
|
||||
|
||||
str::raw::from_c_str(cast::transmute_copy(&cstr))
|
||||
str::raw::from_c_str(mem::transmute_copy(&cstr))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use rect::Rect;
|
||||
use get_error;
|
||||
use std::ptr;
|
||||
@@ -150,7 +150,7 @@ impl Surface {
|
||||
unsafe {
|
||||
if ll::SDL_LockSurface(self.raw) != 0 { fail!("could not lock surface"); }
|
||||
let len = (*self.raw).pitch as uint * ((*self.raw).h as uint);
|
||||
let pixels: &mut [u8] = cast::transmute(((*self.raw).pixels, len));
|
||||
let pixels: &mut [u8] = mem::transmute(((*self.raw).pixels, len));
|
||||
let rv = f(pixels);
|
||||
ll::SDL_UnlockSurface(self.raw);
|
||||
rv
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use libc::{uint32_t, c_void};
|
||||
use std::raw;
|
||||
|
||||
@@ -49,14 +49,14 @@ pub struct Timer<'a> {
|
||||
impl<'a> Timer<'a> {
|
||||
pub fn new<'a>(delay: uint, callback: ||: 'a -> uint, remove_on_drop: bool) -> Timer<'a> {
|
||||
unsafe {
|
||||
let c_param = cast::transmute::<_, raw::Closure>(callback);
|
||||
let c_param = mem::transmute::<_, raw::Closure>(callback);
|
||||
Timer { delay: delay, raw: 0, closure: c_param, remove_on_drop: remove_on_drop }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(&mut self) {
|
||||
unsafe {
|
||||
let timer_id = ll::SDL_AddTimer(self.delay as u32, Some(c_timer_callback), cast::transmute(&self.closure));
|
||||
let timer_id = ll::SDL_AddTimer(self.delay as u32, Some(c_timer_callback), mem::transmute(&self.closure));
|
||||
self.raw = timer_id;
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,6 @@ impl<'a> Drop for Timer<'a> {
|
||||
}
|
||||
|
||||
extern "C" fn c_timer_callback(_interval: uint32_t, param: *c_void) -> uint32_t {
|
||||
let f : &mut || -> uint = unsafe { cast::transmute(param) };
|
||||
let f : &mut || -> uint = unsafe { mem::transmute(param) };
|
||||
(*f)() as uint32_t
|
||||
}
|
||||
|
||||
+19
-19
@@ -1,7 +1,7 @@
|
||||
use libc::{c_int, c_float, uint32_t};
|
||||
use std::ptr;
|
||||
use std::str;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::vec::Vec;
|
||||
|
||||
use rect::Rect;
|
||||
@@ -69,7 +69,7 @@ pub mod ll {
|
||||
SDL_WINDOWEVENT_FOCUS_LOST,
|
||||
SDL_WINDOWEVENT_CLOSE
|
||||
}
|
||||
|
||||
|
||||
pub type SDL_GLContext = *c_void;
|
||||
|
||||
#[deriving(FromPrimitive)]
|
||||
@@ -290,7 +290,7 @@ pub enum WindowPos {
|
||||
fn unwrap_windowpos (pos: WindowPos) -> ll::SDL_WindowPos {
|
||||
match pos {
|
||||
PosUndefined => ll::SDL_WINDOWPOS_UNDEFINED,
|
||||
PosCentered => ll::SDL_WINDOWPOS_CENTERED,
|
||||
PosCentered => ll::SDL_WINDOWPOS_CENTERED,
|
||||
Positioned(x) => x as ll::SDL_WindowPos
|
||||
}
|
||||
}
|
||||
@@ -369,25 +369,25 @@ impl Window {
|
||||
}
|
||||
|
||||
pub fn set_display_mode(&self, display_mode: Option<DisplayMode>) -> bool {
|
||||
return unsafe {
|
||||
return unsafe {
|
||||
ll::SDL_SetWindowDisplayMode(
|
||||
self.raw,
|
||||
match display_mode {
|
||||
Some(ref mode) => cast::transmute(&mode.to_ll()),
|
||||
None => ptr::null()
|
||||
Some(ref mode) => mem::transmute(&mode.to_ll()),
|
||||
None => ptr::null()
|
||||
}
|
||||
) == 0
|
||||
) == 0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_display_mode(&self, display_mode: &DisplayMode) -> Result<DisplayMode, ~str> {
|
||||
let dm = empty_sdl_display_mode();
|
||||
|
||||
let result = unsafe {
|
||||
let result = unsafe {
|
||||
ll::SDL_GetWindowDisplayMode(
|
||||
self.raw,
|
||||
&display_mode.to_ll()
|
||||
) == 0
|
||||
) == 0
|
||||
};
|
||||
|
||||
if result {
|
||||
@@ -415,11 +415,11 @@ impl Window {
|
||||
unsafe { ll::SDL_SetWindowTitle(self.raw, buff) }
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pub fn get_title(&self) -> ~str {
|
||||
unsafe {
|
||||
let cstr = ll::SDL_GetWindowTitle(self.raw);
|
||||
str::raw::from_c_str(cast::transmute_copy(&cstr))
|
||||
str::raw::from_c_str(mem::transmute_copy(&cstr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ impl Window {
|
||||
}
|
||||
|
||||
pub fn update_surface_rects(&self, rects: &[Rect]) -> bool {
|
||||
unsafe { ll::SDL_UpdateWindowSurfaceRects(self.raw, cast::transmute(rects.as_ptr()), rects.len() as c_int) == 0}
|
||||
unsafe { ll::SDL_UpdateWindowSurfaceRects(self.raw, mem::transmute(rects.as_ptr()), rects.len() as c_int) == 0}
|
||||
}
|
||||
|
||||
pub fn set_grab(&self, grabbed: bool) {
|
||||
@@ -543,15 +543,15 @@ impl Window {
|
||||
pub fn set_gamma_ramp(&self, red: Option<&[u16, ..256]>, green: Option<&[u16, ..256]>, blue: Option<&[u16, ..256]>) -> bool {
|
||||
unsafe {
|
||||
let unwrapped_red = match red {
|
||||
Some(values) => cast::transmute((*values).as_ptr()),
|
||||
Some(values) => mem::transmute((*values).as_ptr()),
|
||||
None => ptr::null()
|
||||
};
|
||||
let unwrapped_green = match green {
|
||||
Some(values) => cast::transmute((*values).as_ptr()),
|
||||
Some(values) => mem::transmute((*values).as_ptr()),
|
||||
None => ptr::null()
|
||||
};
|
||||
let unwrapped_blue = match blue {
|
||||
Some(values) => cast::transmute((*values).as_ptr()),
|
||||
Some(values) => mem::transmute((*values).as_ptr()),
|
||||
None => ptr::null()
|
||||
};
|
||||
ll::SDL_SetWindowGammaRamp(self.raw, unwrapped_red, unwrapped_green, unwrapped_blue) == 0
|
||||
@@ -562,7 +562,7 @@ impl Window {
|
||||
let red: Vec<u16> = Vec::with_capacity(256);
|
||||
let green: Vec<u16> = Vec::with_capacity(256);
|
||||
let blue: Vec<u16> = Vec::with_capacity(256);
|
||||
let result = unsafe {ll::SDL_GetWindowGammaRamp(self.raw, cast::transmute(red.as_ptr()), cast::transmute(green.as_ptr()), cast::transmute(blue.as_ptr())) == 0};
|
||||
let result = unsafe {ll::SDL_GetWindowGammaRamp(self.raw, mem::transmute(red.as_ptr()), mem::transmute(green.as_ptr()), mem::transmute(blue.as_ptr())) == 0};
|
||||
if result {
|
||||
Ok((red, green, blue))
|
||||
} else {
|
||||
@@ -600,7 +600,7 @@ pub fn get_num_video_drivers() -> Result<int, ~str> {
|
||||
pub fn get_video_driver(id: int) -> ~str {
|
||||
unsafe {
|
||||
let cstr = ll::SDL_GetVideoDriver(id as c_int);
|
||||
str::raw::from_c_str(cast::transmute_copy(&cstr))
|
||||
str::raw::from_c_str(mem::transmute_copy(&cstr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -617,7 +617,7 @@ pub fn video_quit() {
|
||||
pub fn get_current_video_driver() -> ~str {
|
||||
unsafe {
|
||||
let cstr = ll::SDL_GetCurrentVideoDriver();
|
||||
str::raw::from_c_str(cast::transmute_copy(&cstr))
|
||||
str::raw::from_c_str(mem::transmute_copy(&cstr))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,7 +633,7 @@ pub fn get_num_video_displays() -> Result<int, ~str> {
|
||||
pub fn get_display_name(display_index: int) -> ~str {
|
||||
unsafe {
|
||||
let cstr = ll::SDL_GetDisplayName(display_index as c_int);
|
||||
str::raw::from_c_str(cast::transmute_copy(&cstr))
|
||||
str::raw::from_c_str(mem::transmute_copy(&cstr))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user