Merge branch 'master' of https://github.com/dpx-infinity/rust-sdl2 into dpx-infinity-master

Conflicts:
	src/sdl2/render.rs
This commit is contained in:
Tony Aldridge
2014-05-26 14:06:03 +01:00
10 changed files with 103 additions and 35 deletions
+6 -3
View File
@@ -231,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, mem::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 {
@@ -317,10 +317,13 @@ impl AudioDevice {
#[deriving(Eq)] #[allow(raw_pointer_deriving)]
pub struct AudioCVT {
pub raw: *mut ll::SDL_AudioCVT,
pub owned: bool,
raw: *mut ll::SDL_AudioCVT,
owned: bool,
}
impl_raw_accessors!(AudioCVT, *mut ll::SDL_AudioCVT)
impl_owned_accessors!(AudioCVT, owned)
impl Drop for AudioCVT {
fn drop(&mut self) {
if self.owned {
+2 -2
View File
@@ -71,7 +71,7 @@ pub fn get_keyboard_focus() -> Option<Window> {
if raw == ptr::null() {
None
} else {
Some(Window{ raw: raw, owned: false })
unsafe { Some(Window::from_ll(raw, false)) }
}
}
@@ -163,5 +163,5 @@ pub fn has_screen_keyboard_support() -> bool {
}
pub fn is_screen_keyboard_shown(window: &Window) -> bool {
unsafe { ll::SDL_IsScreenKeyboardShown(window.raw) == 1 }
unsafe { ll::SDL_IsScreenKeyboardShown(window.raw()) == 1 }
}
+1
View File
@@ -16,6 +16,7 @@ pub mod keycode;
#[path = "generated/scancode.rs"]
pub mod scancode;
pub mod macros;
pub mod event;
pub mod gesture;
pub mod touch;
+36
View File
@@ -0,0 +1,36 @@
#![macro_escape]
macro_rules! impl_raw_accessors(
($($t:ty, $raw:ty);+) => (
$(
impl $t {
#[inline]
pub fn raw(&self) -> $raw { self.raw }
}
)+
)
)
macro_rules! impl_owned_accessors(
($($t:ty, $owned:ident);+) => (
$(
impl $t {
#[inline]
pub fn $owned(&self) -> bool { self.$owned }
}
)+
)
)
macro_rules! impl_raw_constructor(
($($t:ty -> $te:ident ($($r:ident:$rt:ty),+));+) => (
$(
impl $t {
#[inline]
pub unsafe fn from_ll($($r:$rt),+) -> $t {
$te { $($r: $r),+ }
}
}
)+
)
)
+3 -3
View File
@@ -105,7 +105,7 @@ impl Cursor {
// TODO: figure out how to pass Surface in here correctly
pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> Result<Cursor, StrBuf> {
unsafe {
let raw = ll::SDL_CreateColorCursor(surface.raw, hot_x as i32,
let raw = ll::SDL_CreateColorCursor(surface.raw(), hot_x as i32,
hot_y as i32);
if raw == ptr::null() {
@@ -167,7 +167,7 @@ pub fn get_mouse_focus() -> Option<video::Window> {
if raw == ptr::null() {
None
} else {
Some(video::Window{ raw: raw, owned: false })
unsafe { Some(video::Window::from_ll(raw, false)) }
}
}
@@ -190,7 +190,7 @@ pub fn get_relative_mouse_state() -> (MouseState, int, int) {
}
pub fn warp_mouse_in_window(window: &video::Window, x: i32, y: i32) {
unsafe { ll::SDL_WarpMouseInWindow(window.raw, x, y); }
unsafe { ll::SDL_WarpMouseInWindow(window.raw(), x, y); }
}
pub fn set_relative_mouse_mode(on: bool) {
+7 -2
View File
@@ -89,9 +89,11 @@ pub mod ll {
}
#[deriving(Eq)] #[allow(raw_pointer_deriving)]
pub struct Palette {
pub raw: *ll::SDL_Palette
raw: *ll::SDL_Palette
}
impl_raw_accessors!(Palette, *ll::SDL_Palette)
#[deriving(Eq)]
pub enum Color {
RGB(u8, u8, u8),
@@ -132,9 +134,12 @@ impl rand::Rand for Color {
#[deriving(Eq)] #[allow(raw_pointer_deriving)]
pub struct PixelFormat {
pub raw: *ll::SDL_PixelFormat
raw: *ll::SDL_PixelFormat
}
impl_raw_accessors!(PixelFormat, *ll::SDL_PixelFormat)
impl_raw_constructor!(PixelFormat -> PixelFormat (raw: *ll::SDL_PixelFormat))
#[deriving(Eq, Show, FromPrimitive)]
pub enum PixelFormatFlag {
Unknown = ll::SDL_PIXELFORMAT_UNKNOWN as int,
+12 -9
View File
@@ -202,9 +202,9 @@ impl RendererInfo {
#[deriving(Eq)] #[allow(raw_pointer_deriving)]
pub struct Renderer<S> {
pub raw: *ll::SDL_Renderer,
raw: *ll::SDL_Renderer,
parent: Option<S>,
pub owned: bool
owned: bool
}
#[unsafe_destructor]
@@ -226,7 +226,7 @@ impl Renderer<Window> {
};
let raw = unsafe {
ll::SDL_CreateRenderer(window.raw, index as c_int, renderer_flags.bits())
ll::SDL_CreateRenderer(window.raw(), index as c_int, renderer_flags.bits())
};
if raw == ptr::null() {
@@ -241,10 +241,7 @@ impl Renderer<Window> {
let raw_renderer: *ll::SDL_Renderer = ptr::null();
let result = unsafe { ll::SDL_CreateWindowAndRenderer(width as c_int, height as c_int, window_flags.bits(), &raw_window, &raw_renderer) == 0};
if result {
let window = Window {
raw: raw_window,
owned: true
};
let window = unsafe { Window::from_ll(raw_window, true) };
Ok(Renderer {
raw: raw_renderer,
parent: Some(window),
@@ -258,7 +255,7 @@ impl Renderer<Window> {
impl Renderer<Surface> {
pub fn from_surface(surface: surface::Surface) -> Result<Renderer<Surface>, StrBuf> {
let result = unsafe { ll::SDL_CreateSoftwareRenderer(surface.raw) };
let result = unsafe { ll::SDL_CreateSoftwareRenderer(surface.raw()) };
if result == ptr::null() {
Ok(Renderer {
raw: result,
@@ -281,6 +278,12 @@ impl<S> Renderer<S> {
mem::replace(&mut self.parent, None).unwrap()
}
#[inline]
pub fn raw(&self) -> *ll::SDL_Renderer { self.raw }
#[inline]
pub fn owned(&self) -> bool { self.owned }
pub fn set_draw_color(&self, color: pixels::Color) -> Result<(), StrBuf> {
let ret = match color {
pixels::RGB(r, g, b) => {
@@ -340,7 +343,7 @@ impl<S> Renderer<S> {
}
pub fn create_texture_from_surface(&self, surface: &surface::Surface) -> Result<Texture, StrBuf> {
let result = unsafe { ll::SDL_CreateTextureFromSurface(self.raw, surface.raw) };
let result = unsafe { ll::SDL_CreateTextureFromSurface(self.raw, surface.raw()) };
if result == ptr::null() {
Err(get_error())
} else {
+5 -2
View File
@@ -43,10 +43,13 @@ pub mod ll {
#[deriving(Eq)] #[allow(raw_pointer_deriving)]
pub struct RWops {
pub raw: *ll::SDL_RWops,
pub close_on_drop: bool
raw: *ll::SDL_RWops,
close_on_drop: bool
}
impl_raw_accessors!(RWops, *ll::SDL_RWops)
impl_owned_accessors!(RWops, close_on_drop)
/// A structure that provides an abstract interface to stream I/O.
impl RWops {
pub fn from_file(path: &Path, mode: &str) -> Result<RWops, StrBuf> {
+11 -7
View File
@@ -85,8 +85,8 @@ bitflags!(flags SurfaceFlag: u32 {
#[deriving(Eq)]
#[allow(raw_pointer_deriving)]
pub struct Surface {
pub raw: *ll::SDL_Surface,
pub owned: bool
raw: *ll::SDL_Surface,
owned: bool
}
impl Drop for Surface {
@@ -99,6 +99,10 @@ impl Drop for Surface {
}
}
impl_raw_accessors!(Surface, *ll::SDL_Surface)
impl_owned_accessors!(Surface, owned)
impl_raw_constructor!(Surface -> Surface (raw: *ll::SDL_Surface, owned: bool))
impl Surface {
pub fn new(surface_flags: SurfaceFlag, width: int, height: int, bpp: int,
rmask: u32, gmask: u32, bmask: u32, amask: u32) -> Result<Surface, StrBuf> {
@@ -137,8 +141,8 @@ impl Surface {
}
pub fn get_pixel_format(&self) -> pixels::PixelFormat {
pixels::PixelFormat {
raw: unsafe { (*self.raw).format }
unsafe {
pixels::PixelFormat::from_ll((*self.raw).format)
}
}
@@ -164,7 +168,7 @@ impl Surface {
pub fn from_bmp(path: &Path) -> Result<Surface, StrBuf> {
let raw = unsafe {
ll::SDL_LoadBMP_RW(try!(rwops::RWops::from_file(path, "rb")).raw, 0)
ll::SDL_LoadBMP_RW(try!(rwops::RWops::from_file(path, "rb")).raw(), 0)
};
if raw.is_null() { Err(get_error()) }
@@ -173,7 +177,7 @@ impl Surface {
pub fn save_bmp(&self, path: &Path) -> Result<(), StrBuf> {
let ret = unsafe {
ll::SDL_SaveBMP_RW(self.raw, try!(rwops::RWops::from_file(path, "rb")).raw, 0)
ll::SDL_SaveBMP_RW(self.raw, try!(rwops::RWops::from_file(path, "rb")).raw(), 0)
};
if ret == 0 { Ok(()) }
else { Err(get_error()) }
@@ -181,7 +185,7 @@ impl Surface {
pub fn set_palette(&self, palette: &pixels::Palette) -> bool {
unsafe {
ll::SDL_SetSurfacePalette(self.raw, palette.raw) == 0
ll::SDL_SetSurfacePalette(self.raw, palette.raw()) == 0
}
}
+20 -7
View File
@@ -297,8 +297,8 @@ fn unwrap_windowpos (pos: WindowPos) -> ll::SDL_WindowPos {
#[deriving(Eq)]
pub struct GLContext {
pub raw: ll::SDL_GLContext,
pub owned: bool
raw: ll::SDL_GLContext,
owned: bool
}
impl Drop for GLContext {
@@ -311,14 +311,27 @@ impl Drop for GLContext {
}
}
#[deriving(Eq)]
#[allow(raw_pointer_deriving)]
pub struct Window {
pub raw: *ll::SDL_Window,
pub owned: bool
raw: *ll::SDL_Window,
owned: bool
}
impl_raw_accessors!(
GLContext, ll::SDL_GLContext;
Window, *ll::SDL_Window
)
impl_owned_accessors!(
GLContext, owned;
Window, owned
)
impl_raw_constructor!(
Window -> Window (raw: *ll::SDL_Window, owned: bool)
)
impl Drop for Window {
fn drop(&mut self) {
if self.owned {
@@ -427,7 +440,7 @@ impl Window {
}
pub fn set_icon(&self, icon: &Surface) {
unsafe { ll::SDL_SetWindowIcon(self.raw, icon.raw) }
unsafe { ll::SDL_SetWindowIcon(self.raw, icon.raw()) }
}
//pub fn SDL_SetWindowData(window: *SDL_Window, name: *c_char, userdata: *c_void) -> *c_void; //TODO: Figure out what this does
@@ -515,7 +528,7 @@ impl Window {
if raw == ptr::null() {
Err(get_error())
} else {
Ok(Surface {raw: raw, owned: false}) //Docs say that it releases with the window
unsafe { Ok(Surface::from_ll(raw, false)) } //Docs say that it releases with the window
}
}