Remove "owned" from Window, alter functions to return id instead of Window

This commit is contained in:
Dan Spencer
2015-07-22 00:30:54 -06:00
parent 5cba31f29a
commit 70e5700a79
3 changed files with 15 additions and 34 deletions
+3 -2
View File
@@ -30,12 +30,13 @@ bitflags! {
}
}
pub fn get_keyboard_focus() -> Option<Window> {
pub fn get_focused_window_id() -> Option<u32> {
let raw = unsafe { ll::SDL_GetKeyboardFocus() };
if raw == ptr::null_mut() {
None
} else {
unsafe { Some(Window::from_ll(raw, false)) }
let id = unsafe { ::sys::video::SDL_GetWindowID(raw) };
Some(id)
}
}
+3 -2
View File
@@ -148,12 +148,13 @@ pub fn wrap_mouse(bitflags: u8) -> Mouse {
}
}
pub fn get_mouse_focus() -> Option<video::Window> {
pub fn get_focused_window_id() -> Option<u32> {
let raw = unsafe { ll::SDL_GetMouseFocus() };
if raw == ptr::null_mut() {
None
} else {
unsafe { Some(video::Window::from_ll(raw, false)) }
let id = unsafe { ::sys::video::SDL_GetWindowID(raw) };
Some(id)
}
}
+9 -30
View File
@@ -401,8 +401,7 @@ impl GLContext {
}
pub struct Window {
raw: *mut ll::SDL_Window,
owned: bool
raw: *mut ll::SDL_Window
}
impl_raw_accessors!(
@@ -410,21 +409,14 @@ impl_raw_accessors!(
(Window, *mut ll::SDL_Window)
);
impl_owned_accessors!(
(Window, owned)
);
impl_raw_constructor!(
(Window, Window (raw: *mut ll::SDL_Window, owned: bool))
(Window, Window (raw: *mut ll::SDL_Window))
);
impl Drop for Window {
#[inline]
fn drop(&mut self) {
if self.owned {
unsafe {
ll::SDL_DestroyWindow(self.raw);
}
}
unsafe { ll::SDL_DestroyWindow(self.raw) };
}
}
@@ -477,7 +469,7 @@ impl WindowBuilder {
if raw == ptr::null_mut() {
Err(get_error())
} else {
Ok(Window { raw: raw, owned: true })
Ok(Window { raw: raw })
}
}
}
@@ -612,20 +604,6 @@ impl Window {
}
}
/// Get a Window from a stored ID.
///
/// Warning: This function is unsafe!
/// It may introduce aliased Window values if a Window of the same ID is
/// already being used as a variable in the application.
pub unsafe fn from_id(id: u32) -> SdlResult<Window> {
let raw = ll::SDL_GetWindowFromID(id);
if raw == ptr::null_mut() {
Err(get_error())
} else {
Ok(Window{ raw: raw, owned: false})
}
}
pub fn get_id(&self) -> u32 {
unsafe { ll::SDL_GetWindowID(self.raw) }
}
@@ -1100,12 +1078,13 @@ pub fn gl_extension_supported(extension: &str) -> bool {
}
}
pub unsafe fn gl_get_current_window() -> SdlResult<Window> {
let raw = ll::SDL_GL_GetCurrentWindow();
pub fn gl_get_current_window_id() -> SdlResult<u32> {
let raw = unsafe { ll::SDL_GL_GetCurrentWindow() };
if raw == ptr::null_mut() {
Err(get_error())
} else {
Ok(Window{ raw: raw, owned: false })
let id = unsafe { ll::SDL_GetWindowID(raw) };
Ok(id)
}
}