mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-01 14:20:05 -04:00
Implement get_position for win32 and fix interface
This commit is contained in:
@@ -8,7 +8,7 @@ pub enum Event {
|
|||||||
SizeChanged(uint, uint),
|
SizeChanged(uint, uint),
|
||||||
|
|
||||||
/// The position of the window has changed.
|
/// The position of the window has changed.
|
||||||
Moved(uint, uint),
|
Moved(int, int),
|
||||||
|
|
||||||
/// The window has been closed.
|
/// The window has been closed.
|
||||||
Closed,
|
Closed,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_position(&self) -> (uint, uint) {
|
pub fn get_position(&self) -> (int, int) {
|
||||||
self.window.get_position()
|
self.window.get_position()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -552,6 +552,17 @@ pub struct DEVMODE {
|
|||||||
pub dmPanningHeight: DWORD,
|
pub dmPanningHeight: DWORD,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms632611(v=vs.85).aspx
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct WINDOWPLACEMENT {
|
||||||
|
pub length: UINT,
|
||||||
|
pub flags: UINT,
|
||||||
|
pub showCmd: UINT,
|
||||||
|
pub ptMinPosition: POINT,
|
||||||
|
pub ptMaxPosition: POINT,
|
||||||
|
pub rcNormalPosition: RECT,
|
||||||
|
}
|
||||||
|
|
||||||
pub type LPMSG = *mut MSG;
|
pub type LPMSG = *mut MSG;
|
||||||
|
|
||||||
#[link(name = "advapi32")]
|
#[link(name = "advapi32")]
|
||||||
@@ -621,6 +632,9 @@ extern "system" {
|
|||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx
|
||||||
pub fn GetProcAddress(hModule: HMODULE, lpProcName: LPCSTR) -> *const libc::c_void;
|
pub fn GetProcAddress(hModule: HMODULE, lpProcName: LPCSTR) -> *const libc::c_void;
|
||||||
|
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633518(v=vs.85).aspx
|
||||||
|
pub fn GetWindowPlacement(hWnd: HWND, lpwndpl: *mut WINDOWPLACEMENT) -> BOOL;
|
||||||
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519(v=vs.85).aspx
|
||||||
pub fn GetWindowRect(hWnd: HWND, lpRect: *mut RECT) -> BOOL;
|
pub fn GetWindowRect(hWnd: HWND, lpRect: *mut RECT) -> BOOL;
|
||||||
|
|
||||||
|
|||||||
@@ -207,8 +207,18 @@ impl Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_position(&self) -> (uint, uint) {
|
pub fn get_position(&self) -> (int, int) {
|
||||||
unimplemented!()
|
use std::{mem, os};
|
||||||
|
|
||||||
|
let mut placement: ffi::WINDOWPLACEMENT = unsafe { mem::zeroed() };
|
||||||
|
placement.length = mem::size_of::<ffi::WINDOWPLACEMENT>() as ffi::UINT;
|
||||||
|
|
||||||
|
if unsafe { ffi::GetWindowPlacement(self.window, &mut placement) } == 0 {
|
||||||
|
fail!("GetWindowPlacement failed: {}", os::error_string(os::errno() as uint));
|
||||||
|
}
|
||||||
|
|
||||||
|
let ref rect = placement.rcNormalPosition;
|
||||||
|
(rect.left as int, rect.top as int)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_position(&self, x: uint, y: uint) {
|
pub fn set_position(&self, x: uint, y: uint) {
|
||||||
@@ -363,8 +373,8 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT,
|
|||||||
|
|
||||||
ffi::WM_MOVE => {
|
ffi::WM_MOVE => {
|
||||||
use events::Moved;
|
use events::Moved;
|
||||||
let x = ffi::LOWORD(lparam as ffi::DWORD) as uint;
|
let x = ffi::LOWORD(lparam as ffi::DWORD) as i16 as int;
|
||||||
let y = ffi::HIWORD(lparam as ffi::DWORD) as uint;
|
let y = ffi::HIWORD(lparam as ffi::DWORD) as i16 as int;
|
||||||
send_event(window, Moved(x, y));
|
send_event(window, Moved(x, y));
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ impl Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_position(&self) -> (uint, uint) {
|
pub fn get_position(&self) -> (int, int) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user