mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Surface: added from_data and fill_rect.
This commit is contained in:
+28
-1
@@ -119,7 +119,22 @@ impl Surface {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: From Data
|
||||
pub fn from_data(data: &[u8], width: int, height: int, bpp: int, pitch: int,
|
||||
rmask: u32, gmask: u32, bmask: u32, amask: u32) -> SdlResult<Surface> {
|
||||
|
||||
unsafe {
|
||||
let raw = ll::SDL_CreateRGBSurfaceFrom(
|
||||
mem::transmute(data.as_ptr()), width as c_int, height as c_int,
|
||||
bpp as c_int, pitch as c_int, rmask, gmask, bmask, amask);
|
||||
|
||||
if raw == ptr::null() {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok(Surface { raw: raw, owned: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_width(&self) -> int {
|
||||
unsafe { (*self.raw).w as int }
|
||||
}
|
||||
@@ -268,6 +283,18 @@ impl Surface {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fill_rect(&mut self, rect: Option<Rect>, color: pixels::Color) -> SdlResult<()> {
|
||||
unsafe {
|
||||
let rect_ptr = mem::transmute( rect.as_ref() );
|
||||
let format = self.get_pixel_format();
|
||||
let result = ll::SDL_FillRect( self.raw, rect_ptr, color.to_u32(&format) );
|
||||
match result {
|
||||
0 => Ok(()),
|
||||
_ => Err(get_error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn SDL_SetSurfaceAlphaMod(surface: *SDL_Surface, alpha: uint8_t) -> c_int;
|
||||
pub fn SDL_GetSurfaceAlphaMod(surface: *SDL_Surface, alpha: *uint8_t ) -> c_int;
|
||||
|
||||
Reference in New Issue
Block a user