From 06e566c3f40378582c9e4e2d096dda362658b5e1 Mon Sep 17 00:00:00 2001 From: Tony Aldridge Date: Mon, 26 May 2014 14:15:45 +0100 Subject: [PATCH] Updated to match latest changes to strings --- src/codegen/branchify.rs | 6 ++-- src/codegen/keycode.rs | 4 +-- src/codegen/scancode.rs | 4 +-- src/sdl2/audio.rs | 22 ++++++------ src/sdl2/event.rs | 12 +++---- src/sdl2/keyboard.rs | 4 +-- src/sdl2/mouse.rs | 6 ++-- src/sdl2/render.rs | 78 ++++++++++++++++++++-------------------- src/sdl2/rwops.rs | 4 +-- src/sdl2/sdl.rs | 2 +- src/sdl2/surface.rs | 12 +++---- src/sdl2/version.rs | 2 +- src/sdl2/video.rs | 46 ++++++++++++------------ 13 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/codegen/branchify.rs b/src/codegen/branchify.rs index 1e6e7b1c..fb09d40a 100644 --- a/src/codegen/branchify.rs +++ b/src/codegen/branchify.rs @@ -7,7 +7,7 @@ use std::vec::Vec; struct ParseBranch { matches: Vec, - result: Option, + result: Option, children: Vec, } @@ -28,7 +28,7 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> Vec { - let first_case = if case_sensitive { c as u8 } else { c.to_ascii().to_upper().to_byte() }; + let first_case = if case_sensitive { c as u8 } else { c.to_ascii().to_uppercase().to_byte() }; for next_branch in branch.children.mut_iter() { if next_branch.matches.as_slice()[0] == first_case { go_down_moses(next_branch, chariter, result, case_sensitive); @@ -38,7 +38,7 @@ pub fn branchify(options: &[(&str, &str)], case_sensitive: bool) -> Vec Key { } impl Key { - fn ident(&self) -> StrBuf { + fn ident(&self) -> String { self.ident.to_owned() } - fn padded_ident(&self) -> StrBuf { + fn padded_ident(&self) -> String { self.ident().append(" ".repeat(unsafe { longest_ident } - self.ident().len()).as_slice()) } diff --git a/src/codegen/scancode.rs b/src/codegen/scancode.rs index cbb160af..34937ee0 100644 --- a/src/codegen/scancode.rs +++ b/src/codegen/scancode.rs @@ -44,11 +44,11 @@ fn ScanCode(code: uint, ident: &'static str) -> ScanCode { } impl ScanCode { - fn ident(&self) -> StrBuf { + fn ident(&self) -> String { self.ident.to_owned() } - fn padded_ident(&self) -> StrBuf { + fn padded_ident(&self) -> String { self.ident().append(" ".repeat(unsafe { longest_ident } - self.ident().len()).as_slice()) } diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index 36b9b06d..4177e91d 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -152,7 +152,7 @@ pub fn get_num_audio_drivers() -> int { unsafe { ll::SDL_GetNumAudioDrivers() as int } } -pub fn get_audio_driver(index: int) -> StrBuf { +pub fn get_audio_driver(index: int) -> String { unsafe { let buf = ll::SDL_GetAudioDriver(index as c_int); CString::new(buf, false).as_str().unwrap().into_owned() @@ -163,14 +163,14 @@ pub fn get_num_audio_devices(iscapture: int) -> int { unsafe { ll::SDL_GetNumAudioDevices(iscapture as c_int) as int } } -pub fn get_audio_device_name(index: int, iscapture: int) -> StrBuf { +pub fn get_audio_device_name(index: int, iscapture: int) -> String { unsafe { let buf = ll::SDL_GetAudioDeviceName(index as c_int, iscapture as c_int); CString::new(buf, false).as_str().unwrap().into_owned() } } -pub fn audio_init(name: &str) -> Result<(), StrBuf> { +pub fn audio_init(name: &str) -> Result<(), String> { let ret = name.with_c_str(|buf| { unsafe { ll::SDL_AudioInit(buf) } }); @@ -185,7 +185,7 @@ pub fn audio_quit() { unsafe { ll::SDL_AudioQuit() } } -pub fn get_current_audio_driver() -> StrBuf { +pub fn get_current_audio_driver() -> String { unsafe { let buf = ll::SDL_GetCurrentAudioDriver(); CString::new(buf, false).as_str().unwrap().into_owned() @@ -221,13 +221,13 @@ extern "C" fn c_audio_callback(userdata: *c_void, stream: *uint8_t, len: c_int) impl<'a> AudioSpec<'a> { - pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec), StrBuf> { + pub fn load_wav(path: &Path) -> Result<(AudioSpec, CVec), String> { AudioSpec::load_wav_rw(&try!(RWops::from_file(path, "rb"))) } - pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec), StrBuf> { + pub fn load_wav_rw(src: &RWops) -> Result<(AudioSpec, CVec), String> { assert_eq!(mem::size_of::(), mem::size_of::()); - let mut spec = unsafe { mem::uninit::() }; + let mut spec = unsafe { mem::uninitialized::() }; let audio_buf = ptr::null::(); let audio_len = 0u32; unsafe { @@ -261,9 +261,9 @@ impl AudioDevice { } } - pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> Result<(AudioDevice, AudioSpec), StrBuf> { + pub fn open(device: Option<&str>, iscapture: int, spec: &AudioSpec) -> Result<(AudioDevice, AudioSpec), String> { //! SDL_OpenAudioDevice - let obtained = unsafe { mem::uninit::() }; + let obtained = unsafe { mem::uninitialized::() }; unsafe { let device_c_str = match device { None => ptr::null(), @@ -334,7 +334,7 @@ impl Drop for AudioCVT { impl AudioCVT { pub fn new(src_format: AudioFormat, src_channels: u8, src_rate: int, - dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result { + dst_format: AudioFormat, dst_channels: u8, dst_rate: int) -> Result { unsafe { let c_cvt_p = libc::malloc(mem::size_of::() as size_t) as *mut ll::SDL_AudioCVT; let ret = ll::SDL_BuildAudioCVT(c_cvt_p, @@ -348,7 +348,7 @@ impl AudioCVT { } } - pub fn convert(&self, src: CVec) -> Result, StrBuf> { + pub fn convert(&self, src: CVec) -> Result, String> { //! Convert audio data to a desired audio format. unsafe { diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index b2b99146..d12b2088 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -563,9 +563,9 @@ pub enum Event { KeyDownEvent(uint, video::Window, KeyCode, ScanCode, Mod), KeyUpEvent(uint, video::Window, KeyCode, ScanCode, Mod), /// (timestamp, window, text, start, length) - TextEditingEvent(uint, video::Window, StrBuf, int, int), + TextEditingEvent(uint, video::Window, String, int, int), /// (timestamp, window, text) - TextInputEvent(uint, video::Window, StrBuf), + TextInputEvent(uint, video::Window, String), /// (timestamp, window, which, [MouseState], x, y, xrel, yrel) MouseMotionEvent(uint, video::Window, uint, MouseState, int, int, @@ -614,7 +614,7 @@ pub enum Event { ClipboardUpdateEvent(uint), /// (timestamp, filename) - DropFileEvent(uint, StrBuf), + DropFileEvent(uint, String), /// (timestamp, Window, type, code) UserEvent(uint, video::Window, uint, int), @@ -1062,7 +1062,7 @@ pub fn poll_event() -> Event { } /// Wait indefinitely for the next available event. -pub fn wait_event() -> Result { +pub fn wait_event() -> Result { let raw = null_event(); let success = unsafe { ll::SDL_WaitEvent(&raw) == 1 as c_int }; @@ -1071,7 +1071,7 @@ pub fn wait_event() -> Result { } /// Wait until the specified timeout (in milliseconds) for the next available event. -pub fn wait_event_timeout(timeout: int) -> Result { +pub fn wait_event_timeout(timeout: int) -> Result { let raw = null_event(); let success = unsafe { ll::SDL_WaitEventTimeout(&raw, timeout as c_int) == 1 as c_int }; @@ -1133,7 +1133,7 @@ pub fn register_events(num: int) -> Option { } /// add an event to the event queue -pub fn push_event(event: Event) -> Result<(), StrBuf> { +pub fn push_event(event: Event) -> Result<(), String> { match event.to_ll() { Some(raw_event) => { let ok = unsafe { ll::SDL_PushEvent(&raw_event) == 1 }; diff --git a/src/sdl2/keyboard.rs b/src/sdl2/keyboard.rs index 67bc0f4b..b247863f 100644 --- a/src/sdl2/keyboard.rs +++ b/src/sdl2/keyboard.rs @@ -114,7 +114,7 @@ pub fn get_scancode_from_key(key: KeyCode) -> ScanCode { } } -pub fn get_scancode_name(scancode: ScanCode) -> StrBuf { +pub fn get_scancode_name(scancode: ScanCode) -> String { unsafe { str::raw::from_c_str(ll::SDL_GetScancodeName(scancode.code() as u32)) } @@ -128,7 +128,7 @@ pub fn get_scancode_from_name(name: &str) -> ScanCode { } } -pub fn get_key_name(key: KeyCode) -> StrBuf { +pub fn get_key_name(key: KeyCode) -> String { unsafe { str::raw::from_c_str(ll::SDL_GetKeyName(key.code())) } diff --git a/src/sdl2/mouse.rs b/src/sdl2/mouse.rs index a1b17bf2..8adec924 100644 --- a/src/sdl2/mouse.rs +++ b/src/sdl2/mouse.rs @@ -87,7 +87,7 @@ impl Drop for Cursor { } impl Cursor { - pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result { + pub fn new(data: &[u8], mask: &[u8], width: int, height: int, hot_x: int, hot_y: int) -> Result { unsafe { let raw = ll::SDL_CreateCursor(data.as_ptr(), mask.as_ptr(), @@ -103,7 +103,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 { + pub fn from_surface(surface: &surface::Surface, hot_x: int, hot_y: int) -> Result { unsafe { let raw = ll::SDL_CreateColorCursor(surface.raw(), hot_x as i32, hot_y as i32); @@ -116,7 +116,7 @@ impl Cursor { } } - pub fn from_system(cursor: SystemCursor) -> Result { + pub fn from_system(cursor: SystemCursor) -> Result { unsafe { let raw = ll::SDL_CreateSystemCursor(cursor as u32); diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 649f7c06..b4a61713 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -158,7 +158,7 @@ bitflags!(flags RendererFlags: u32 { #[deriving(Eq)] pub struct RendererInfo { - pub name: StrBuf, + pub name: String, pub flags: RendererFlags, pub texture_formats: Vec, pub max_texture_width: int, @@ -219,7 +219,7 @@ impl Drop for Renderer { } impl Renderer { - pub fn from_window(window: Window, index: RenderDriverIndex, renderer_flags: RendererFlags) -> Result, StrBuf> { + pub fn from_window(window: Window, index: RenderDriverIndex, renderer_flags: RendererFlags) -> Result, String> { let index = match index { DriverAuto => -1, DriverIndex(x) => x @@ -236,7 +236,7 @@ impl Renderer { } } - pub fn new_with_window(width: int, height: int, window_flags: video::WindowFlags) -> Result, StrBuf> { + pub fn new_with_window(width: int, height: int, window_flags: video::WindowFlags) -> Result, String> { let raw_window: *video::ll::SDL_Window = ptr::null(); 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}; @@ -254,7 +254,7 @@ impl Renderer { } impl Renderer { - pub fn from_surface(surface: surface::Surface) -> Result, StrBuf> { + pub fn from_surface(surface: surface::Surface) -> Result, String> { let result = unsafe { ll::SDL_CreateSoftwareRenderer(surface.raw()) }; if result == ptr::null() { Ok(Renderer { @@ -284,7 +284,7 @@ impl Renderer { #[inline] pub fn owned(&self) -> bool { self.owned } - pub fn set_draw_color(&self, color: pixels::Color) -> Result<(), StrBuf> { + pub fn set_draw_color(&self, color: pixels::Color) -> Result<(), String> { let ret = match color { pixels::RGB(r, g, b) => { unsafe { ll::SDL_SetRenderDrawColor(self.raw, r, g, b, 255) } @@ -297,7 +297,7 @@ impl Renderer { else { Err(get_error()) } } - pub fn get_draw_color(&self) -> Result { + pub fn get_draw_color(&self) -> Result { let r: u8 = 0; let g: u8 = 0; let b: u8 = 0; @@ -310,7 +310,7 @@ impl Renderer { } } - pub fn clear(&self) -> Result<(), StrBuf> { + pub fn clear(&self) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderClear(self.raw) }; if ret == 0 { Ok(()) } else { Err(get_error()) } @@ -320,7 +320,7 @@ impl Renderer { unsafe { ll::SDL_RenderPresent(self.raw) } } - pub fn get_output_size(&self) -> Result<(int, int), StrBuf> { + pub fn get_output_size(&self) -> Result<(int, int), String> { let width: c_int = 0; let height: c_int = 0; @@ -333,7 +333,7 @@ impl Renderer { } } - pub fn create_texture(&self, format: pixels::PixelFormatFlag, access: TextureAccess, width: int, height: int) -> Result { + pub fn create_texture(&self, format: pixels::PixelFormatFlag, access: TextureAccess, width: int, height: int) -> Result { let result = unsafe { ll::SDL_CreateTexture(self.raw, format as uint32_t, access as c_int, width as c_int, height as c_int) }; if result == ptr::null() { Err(get_error()) @@ -342,7 +342,7 @@ impl Renderer { } } - pub fn create_texture_from_surface(&self, surface: &surface::Surface) -> Result { + pub fn create_texture_from_surface(&self, surface: &surface::Surface) -> Result { let result = unsafe { ll::SDL_CreateTextureFromSurface(self.raw, surface.raw()) }; if result == ptr::null() { Err(get_error()) @@ -355,7 +355,7 @@ impl Renderer { unsafe { ll::SDL_RenderTargetSupported(self.raw) == 1 } } - pub fn set_render_target(&self, texture: Option<&Texture>) -> Result<(), StrBuf> { + pub fn set_render_target(&self, texture: Option<&Texture>) -> Result<(), String> { unsafe { let actual_texture = match texture { Some(texture) => mem::transmute(texture.raw), @@ -369,7 +369,7 @@ impl Renderer { } } - pub fn get_render_target(&self) -> Result { + pub fn get_render_target(&self) -> Result { let raw = unsafe { ll::SDL_GetRenderTarget(self.raw) }; if raw == ptr::null() { @@ -382,7 +382,7 @@ impl Renderer { } } - pub fn set_logical_size(&self, width: int, height: int) -> Result<(), StrBuf> { + pub fn set_logical_size(&self, width: int, height: int) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderSetLogicalSize(self.raw, width as c_int, height as c_int) }; if ret == 0 { Ok(()) } @@ -399,7 +399,7 @@ impl Renderer { (width as int, height as int) } - pub fn set_viewport(&self, rect: &Rect) -> Result<(), StrBuf> { + pub fn set_viewport(&self, rect: &Rect) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderSetViewport(self.raw, rect) }; if ret == 0 { Ok(()) } @@ -417,7 +417,7 @@ impl Renderer { rect } - pub fn set_clip_rect(&self, rect: &Rect) -> Result<(), StrBuf> { + pub fn set_clip_rect(&self, rect: &Rect) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderSetClipRect(self.raw, rect) }; if ret == 0 { Ok(()) } @@ -435,7 +435,7 @@ impl Renderer { rect } - pub fn set_scale(&self, scale_x: f64, scale_y: f64) -> Result<(), StrBuf> { + pub fn set_scale(&self, scale_x: f64, scale_y: f64) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderSetScale(self.raw, scale_x as c_float, scale_y as c_float) }; if ret == 0 { Ok(()) } @@ -449,14 +449,14 @@ impl Renderer { (scale_x as f64, scale_y as f64) } - pub fn draw_point(&self, point: Point) -> Result<(), StrBuf> { + pub fn draw_point(&self, point: Point) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderDrawPoint(self.raw, point.x, point.y) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn draw_points(&self, points: &[Point]) -> Result<(), StrBuf> { + pub fn draw_points(&self, points: &[Point]) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderDrawPoints(self.raw, mem::transmute(points.as_ptr()), points.len() as c_int) }; @@ -465,14 +465,14 @@ impl Renderer { else { Err(get_error()) } } - pub fn draw_line(&self, start: Point, end: Point) -> Result<(), StrBuf> { + pub fn draw_line(&self, start: Point, end: Point) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderDrawLine(self.raw, start.x, start.y, end.x, end.y) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn draw_lines(&self, points: &[Point]) -> Result<(), StrBuf> { + pub fn draw_lines(&self, points: &[Point]) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderDrawLines(self.raw, mem::transmute(points.as_ptr()), points.len() as c_int) }; @@ -481,14 +481,14 @@ impl Renderer { else { Err(get_error()) } } - pub fn draw_rect(&self, rect: &Rect) -> Result<(), StrBuf> { + pub fn draw_rect(&self, rect: &Rect) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderDrawRect(self.raw, rect) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn draw_rects(&self, rects: &[Rect]) -> Result<(), StrBuf> { + pub fn draw_rects(&self, rects: &[Rect]) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderDrawRects(self.raw, mem::transmute(rects.as_ptr()), rects.len() as c_int) }; @@ -497,14 +497,14 @@ impl Renderer { else { Err(get_error()) } } - pub fn fill_rect(&self, rect: &Rect) -> Result<(), StrBuf> { + pub fn fill_rect(&self, rect: &Rect) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderFillRect(self.raw, rect) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn fill_rects(&self, rects: &[Rect]) -> Result<(), StrBuf> { + pub fn fill_rects(&self, rects: &[Rect]) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderFillRects(self.raw, mem::transmute(rects.as_ptr()), rects.len() as c_int) }; @@ -513,7 +513,7 @@ impl Renderer { else { Err(get_error()) } } - pub fn copy(&self, texture: &Texture, src: Option, dst: Option) -> Result<(), StrBuf> { + pub fn copy(&self, texture: &Texture, src: Option, dst: Option) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderCopy( self.raw, @@ -534,7 +534,7 @@ impl Renderer { } //TODO: Check whether RendererFlip is supposed to be combinable - pub fn copy_ex(&self, texture: &Texture, src: Option, dst: Option, angle: f64, center: Option, flip: RendererFlip) -> Result<(), StrBuf> { + pub fn copy_ex(&self, texture: &Texture, src: Option, dst: Option, angle: f64, center: Option, flip: RendererFlip) -> Result<(), String> { let ret = unsafe { ll::SDL_RenderCopyEx( self.raw, @@ -560,7 +560,7 @@ impl Renderer { else { Err(get_error()) } } - pub fn read_pixels(&self, rect: Option, format: pixels::PixelFormatFlag) -> Result, StrBuf> { + pub fn read_pixels(&self, rect: Option, format: pixels::PixelFormatFlag) -> Result, String> { unsafe { let (actual_rect, w, h) = match rect { Some(rect) => (mem::transmute(&rect), rect.w as uint, rect.h as uint), @@ -609,7 +609,7 @@ impl Drop for Texture { impl Texture { - pub fn query(&self) -> Result { + pub fn query(&self) -> Result { let format: uint32_t = 0; let access: c_int = 0; let width: c_int = 0; @@ -628,14 +628,14 @@ impl Texture { } } - pub fn set_color_mod(&self, red: u8, green: u8, blue: u8) -> Result<(), StrBuf> { + pub fn set_color_mod(&self, red: u8, green: u8, blue: u8) -> Result<(), String> { let ret = unsafe { ll::SDL_SetTextureColorMod(self.raw, red, green, blue) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn get_color_mod(&self) -> Result<(u8, u8, u8), StrBuf> { + pub fn get_color_mod(&self) -> Result<(u8, u8, u8), String> { let r = 0; let g = 0; let b = 0; @@ -648,14 +648,14 @@ impl Texture { } } - pub fn set_alpha_mod(&self, alpha: u8) -> Result<(), StrBuf> { + pub fn set_alpha_mod(&self, alpha: u8) -> Result<(), String> { let ret = unsafe { ll::SDL_SetTextureAlphaMod(self.raw, alpha) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn get_alpha_mod(&self) -> Result { + pub fn get_alpha_mod(&self) -> Result { let alpha = 0; let result = unsafe { ll::SDL_GetTextureAlphaMod(self.raw, &alpha) == 0 }; @@ -666,14 +666,14 @@ impl Texture { } } - pub fn set_blend_mode(&self, blend: BlendMode) -> Result<(), StrBuf> { + pub fn set_blend_mode(&self, blend: BlendMode) -> Result<(), String> { let ret = unsafe { ll::SDL_SetTextureBlendMode(self.raw, FromPrimitive::from_i64(blend as i64).unwrap()) }; if ret == 0 { Ok(()) } else { Err(get_error()) } } - pub fn get_blend_mode(&self) -> Result { + pub fn get_blend_mode(&self) -> Result { let blend: i64 = 0; let result = unsafe { ll::SDL_GetTextureBlendMode(self.raw, &FromPrimitive::from_i64(blend as i64).unwrap()) == 0 }; if result { @@ -683,7 +683,7 @@ impl Texture { } } - pub fn update(&self, rect: Option, pixel_data: &[u8], pitch: int) -> Result<(), StrBuf> { + pub fn update(&self, rect: Option, pixel_data: &[u8], pitch: int) -> Result<(), String> { let ret = unsafe { let actual_rect = match rect { Some(rect) => mem::transmute(&rect), @@ -697,7 +697,7 @@ impl Texture { else { Err(get_error()) } } - pub fn lock(&self, rect: Option) -> Result, StrBuf> { + pub fn lock(&self, rect: Option) -> Result, String> { let q = try!(self.query()); unsafe { let actual_rect = match rect { @@ -721,7 +721,7 @@ impl Texture { unsafe { ll::SDL_UnlockTexture(self.raw) } } - pub fn gl_bind_texture(&self) -> Result<(f64, f64), StrBuf> { + pub fn gl_bind_texture(&self) -> Result<(f64, f64), String> { let texw: c_float = 0.0; let texh: c_float = 0.0; @@ -753,7 +753,7 @@ impl Texture { } -pub fn get_num_render_drivers() -> Result { +pub fn get_num_render_drivers() -> Result { let result = unsafe { ll::SDL_GetNumRenderDrivers() }; if result > 0 { Ok(result as int) @@ -762,7 +762,7 @@ pub fn get_num_render_drivers() -> Result { } } -pub fn get_render_driver_info(index: int) -> Result { +pub fn get_render_driver_info(index: int) -> Result { let out = ll::SDL_RendererInfo { name: ptr::null(), flags: 0, diff --git a/src/sdl2/rwops.rs b/src/sdl2/rwops.rs index 290b5dbb..fadc89fa 100644 --- a/src/sdl2/rwops.rs +++ b/src/sdl2/rwops.rs @@ -52,7 +52,7 @@ 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 { + pub fn from_file(path: &Path, mode: &str) -> Result { let raw = unsafe { ll::SDL_RWFromFile(path.to_c_str().unwrap(), mode.to_c_str().unwrap()) }; @@ -60,7 +60,7 @@ impl RWops { else { Ok(RWops{raw: raw, close_on_drop: true}) } } - pub fn from_bytes(buf: &[u8]) -> Result { + pub fn from_bytes(buf: &[u8]) -> Result { let raw = unsafe { ll::SDL_RWFromConstMem(buf.as_ptr() as *c_void, buf.len() as c_int) }; diff --git a/src/sdl2/sdl.rs b/src/sdl2/sdl.rs index c03b55d7..2126eeaa 100644 --- a/src/sdl2/sdl.rs +++ b/src/sdl2/sdl.rs @@ -111,7 +111,7 @@ pub fn was_inited(flags: InitFlag) -> InitFlag { } } -pub fn get_error() -> StrBuf { +pub fn get_error() -> String { unsafe { let cstr = ll::SDL_GetError(); diff --git a/src/sdl2/surface.rs b/src/sdl2/surface.rs index 5f9ae6fc..ed545b96 100644 --- a/src/sdl2/surface.rs +++ b/src/sdl2/surface.rs @@ -105,7 +105,7 @@ 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 { + rmask: u32, gmask: u32, bmask: u32, amask: u32) -> Result { unsafe { let raw = ll::SDL_CreateRGBSurface(surface_flags.bits(), width as c_int, height as c_int, bpp as c_int, rmask, gmask, bmask, amask); @@ -166,7 +166,7 @@ impl Surface { unsafe { ll::SDL_UnlockSurface(self.raw); } } - pub fn from_bmp(path: &Path) -> Result { + pub fn from_bmp(path: &Path) -> Result { let raw = unsafe { ll::SDL_LoadBMP_RW(try!(rwops::RWops::from_file(path, "rb")).raw(), 0) }; @@ -175,7 +175,7 @@ impl Surface { else { Ok(Surface{raw: raw, owned: true}) } } - pub fn save_bmp(&self, path: &Path) -> Result<(), StrBuf> { + pub fn save_bmp(&self, path: &Path) -> Result<(), String> { let ret = unsafe { ll::SDL_SaveBMP_RW(self.raw, try!(rwops::RWops::from_file(path, "rb")).raw(), 0) }; @@ -201,7 +201,7 @@ impl Surface { } } - pub fn set_color_key(&self, enable: bool, color: pixels::Color) -> Result<(), StrBuf> { + pub fn set_color_key(&self, enable: bool, color: pixels::Color) -> Result<(), String> { let key = color.to_u32(&self.get_pixel_format()); let result = unsafe { ll::SDL_SetColorKey(self.raw, ::std::bool::to_bit(enable), key) @@ -213,7 +213,7 @@ impl Surface { } } - pub fn get_color_key(&self) -> Result { + pub fn get_color_key(&self) -> Result { let key: u32 = 0; let result = unsafe { ll::SDL_GetColorKey(self.raw, &key) @@ -237,7 +237,7 @@ impl Surface { } } - pub fn get_color_mod(&self) -> Result { + pub fn get_color_mod(&self) -> Result { let r: u8 = 0; let g: u8 = 0; let b: u8 = 0; diff --git a/src/sdl2/version.rs b/src/sdl2/version.rs index e5d82191..48924d31 100644 --- a/src/sdl2/version.rs +++ b/src/sdl2/version.rs @@ -58,7 +58,7 @@ pub fn get_version() -> Version { } /// Get the code revision of SDL that is linked against your program. -pub fn get_revision() -> StrBuf { +pub fn get_revision() -> String { unsafe { let ret = ll::SDL_GetRevision(); CString::new(ret, false).as_str().unwrap().into_owned() diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 3a19ecfb..756c4370 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -343,7 +343,7 @@ impl Drop for Window { } impl Window { - pub fn new(title: &str, x: WindowPos, y: WindowPos, width: int, height: int, window_flags: WindowFlags) -> Result { + pub fn new(title: &str, x: WindowPos, y: WindowPos, width: int, height: int, window_flags: WindowFlags) -> Result { unsafe { let raw = title.with_c_str(|buff| { ll::SDL_CreateWindow( @@ -364,7 +364,7 @@ impl Window { } } - pub fn from_id(id: u32) -> Result { + pub fn from_id(id: u32) -> Result { let raw = unsafe { ll::SDL_GetWindowFromID(id) }; if raw == ptr::null() { Err(get_error()) @@ -373,7 +373,7 @@ impl Window { } } - pub fn get_display_index(&self) -> Result { + pub fn get_display_index(&self) -> Result { let result = unsafe { ll::SDL_GetWindowDisplayIndex(self.raw) }; if result < 0 { return Err(get_error()) @@ -394,7 +394,7 @@ impl Window { } } - pub fn get_display_mode(&self, display_mode: &DisplayMode) -> Result { + pub fn get_display_mode(&self, display_mode: &DisplayMode) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { @@ -432,7 +432,7 @@ impl Window { }) } - pub fn get_title(&self) -> StrBuf { + pub fn get_title(&self) -> String { unsafe { let cstr = ll::SDL_GetWindowTitle(self.raw); str::raw::from_c_str(mem::transmute_copy(&cstr)) @@ -522,7 +522,7 @@ impl Window { unsafe { ll::SDL_SetWindowFullscreen(self.raw, fullscreen_type as uint32_t) == 0 } } - pub fn get_surface(&self) -> Result { + pub fn get_surface(&self) -> Result { let raw = unsafe { ll::SDL_GetWindowSurface(self.raw) }; if raw == ptr::null() { @@ -574,7 +574,7 @@ impl Window { } } - pub fn get_gamma_ramp(&self) -> Result<(Vec, Vec, Vec), StrBuf> { + pub fn get_gamma_ramp(&self) -> Result<(Vec, Vec, Vec), String> { let red: Vec = Vec::with_capacity(256); let green: Vec = Vec::with_capacity(256); let blue: Vec = Vec::with_capacity(256); @@ -586,7 +586,7 @@ impl Window { } } - pub fn gl_create_context(&self) -> Result { + pub fn gl_create_context(&self) -> Result { let result = unsafe { ll::SDL_GL_CreateContext(self.raw) }; if result == ptr::null() { Err(get_error()) @@ -604,7 +604,7 @@ impl Window { } } -pub fn get_num_video_drivers() -> Result { +pub fn get_num_video_drivers() -> Result { let result = unsafe { ll::SDL_GetNumVideoDrivers() }; if result < 0 { Err(get_error()) @@ -613,7 +613,7 @@ pub fn get_num_video_drivers() -> Result { } } -pub fn get_video_driver(id: int) -> StrBuf { +pub fn get_video_driver(id: int) -> String { unsafe { let cstr = ll::SDL_GetVideoDriver(id as c_int); str::raw::from_c_str(mem::transmute_copy(&cstr)) @@ -630,14 +630,14 @@ pub fn video_quit() { unsafe { ll::SDL_VideoQuit() } } -pub fn get_current_video_driver() -> StrBuf { +pub fn get_current_video_driver() -> String { unsafe { let cstr = ll::SDL_GetCurrentVideoDriver(); str::raw::from_c_str(mem::transmute_copy(&cstr)) } } -pub fn get_num_video_displays() -> Result { +pub fn get_num_video_displays() -> Result { let result = unsafe { ll::SDL_GetNumVideoDisplays() }; if result < 0 { Err(get_error()) @@ -646,14 +646,14 @@ pub fn get_num_video_displays() -> Result { } } -pub fn get_display_name(display_index: int) -> StrBuf { +pub fn get_display_name(display_index: int) -> String { unsafe { let cstr = ll::SDL_GetDisplayName(display_index as c_int); str::raw::from_c_str(mem::transmute_copy(&cstr)) } } -pub fn get_display_bounds(display_index: int) -> Result { +pub fn get_display_bounds(display_index: int) -> Result { let out: Rect = Rect::new(0, 0, 0, 0); let result = unsafe { ll::SDL_GetDisplayBounds(display_index as c_int, &out) == 0 }; @@ -664,7 +664,7 @@ pub fn get_display_bounds(display_index: int) -> Result { } } -pub fn get_num_display_modes(display_index: int) -> Result { +pub fn get_num_display_modes(display_index: int) -> Result { let result = unsafe { ll::SDL_GetNumDisplayModes(display_index as c_int) }; if result < 0 { Err(get_error()) @@ -673,7 +673,7 @@ pub fn get_num_display_modes(display_index: int) -> Result { } } -pub fn get_display_mode(display_index: int, mode_index: int) -> Result { +pub fn get_display_mode(display_index: int, mode_index: int) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { ll::SDL_GetDisplayMode(display_index as c_int, mode_index as c_int, &dm) == 0}; @@ -684,7 +684,7 @@ pub fn get_display_mode(display_index: int, mode_index: int) -> Result Result { +pub fn get_desktop_display_mode(display_index: int) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { ll::SDL_GetDesktopDisplayMode(display_index as c_int, &dm) == 0}; @@ -695,7 +695,7 @@ pub fn get_desktop_display_mode(display_index: int) -> Result Result { +pub fn get_current_display_mode(display_index: int) -> Result { let dm = empty_sdl_display_mode(); let result = unsafe { ll::SDL_GetCurrentDisplayMode(display_index as c_int, &dm) == 0}; @@ -706,7 +706,7 @@ pub fn get_current_display_mode(display_index: int) -> Result Result { +pub fn get_closest_display_mode(display_index: int, mode: &DisplayMode) -> Result { let input = mode.to_ll(); let out = empty_sdl_display_mode(); @@ -731,7 +731,7 @@ pub fn disable_screen_saver() { unsafe { ll::SDL_DisableScreenSaver() } } -pub fn gl_load_library(path: &str) -> Result<(), StrBuf> { +pub fn gl_load_library(path: &str) -> Result<(), String> { unsafe { path.with_c_str(|path| { if ll::SDL_GL_LoadLibrary(path) == 0 { @@ -765,7 +765,7 @@ pub fn gl_set_attribute(attr: GLAttr, value: int) -> bool { unsafe { ll::SDL_GL_SetAttribute(FromPrimitive::from_u64(attr as u64).unwrap(), value as c_int) == 0 } } -pub fn gl_get_attribute(attr: GLAttr) -> Result { +pub fn gl_get_attribute(attr: GLAttr) -> Result { let out: c_int = 0; let result = unsafe { ll::SDL_GL_GetAttribute(FromPrimitive::from_u64(attr as u64).unwrap(), &out) } == 0; @@ -776,7 +776,7 @@ pub fn gl_get_attribute(attr: GLAttr) -> Result { } } -pub fn gl_get_current_window() -> Result { +pub fn gl_get_current_window() -> Result { let raw = unsafe { ll::SDL_GL_GetCurrentWindow() }; if raw == ptr::null() { Err(get_error()) @@ -785,7 +785,7 @@ pub fn gl_get_current_window() -> Result { } } -pub fn gl_get_current_context() -> Result { +pub fn gl_get_current_context() -> Result { let raw = unsafe { ll::SDL_GL_GetCurrentContext() }; if raw == ptr::null() { Err(get_error())