diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2014-12-03 08:25:02 +0100 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2014-12-03 08:25:02 +0100 |
commit | c6f5b4a107109c7c900b5e56adb036a5e55e667b (patch) | |
tree | 57085dc0026f41848c59457af781550c36003448 /src/win32/init.rs | |
parent | 6652cd0bdfa8c8db90ed01afaccad40f17228c43 (diff) | |
parent | 3cf487ac70c50d8e0a0720af843145d28ce4f1c7 (diff) | |
download | glutin-c6f5b4a107109c7c900b5e56adb036a5e55e667b.tar.gz glutin-c6f5b4a107109c7c900b5e56adb036a5e55e667b.zip |
Merge pull request #150 from tomaka/winapi
Use the winapi crate instead of our own ffi
Diffstat (limited to 'src/win32/init.rs')
-rw-r--r-- | src/win32/init.rs | 253 |
1 files changed, 129 insertions, 124 deletions
diff --git a/src/win32/init.rs b/src/win32/init.rs index 7832268..f3e669c 100644 --- a/src/win32/init.rs +++ b/src/win32/init.rs @@ -1,6 +1,6 @@ use std::sync::atomic::AtomicBool; use std::ptr; -use super::{event, ffi}; +use super::event; use super::Window; use {CreationError, Event}; use CreationError::OsError; @@ -8,17 +8,21 @@ use CreationError::OsError; use std::cell::RefCell; use std::rc::Rc; +use libc; +use super::gl; +use winapi; + /// Stores the current window and its events dispatcher. /// /// We only have one window per thread. We still store the HWND in case where we /// receive an event for another window. -thread_local!(static WINDOW: Rc<RefCell<Option<(ffi::HWND, Sender<Event>)>>> = Rc::new(RefCell::new(None))) +thread_local!(static WINDOW: Rc<RefCell<Option<(winapi::HWND, Sender<Event>)>>> = Rc::new(RefCell::new(None))) pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String, builder_monitor: Option<super::MonitorID>, builder_gl_version: Option<(uint, uint)>, builder_debug: bool, builder_vsync: bool, builder_hidden: bool, - builder_sharelists: Option<ffi::HGLRC>, builder_multisampling: Option<u16>) + builder_sharelists: Option<winapi::HGLRC>, builder_multisampling: Option<u16>) -> Result<Window, CreationError> { use std::mem; @@ -39,34 +43,34 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin let class_name: Vec<u16> = "Window Class".utf16_units().chain(Some(0).into_iter()) .collect::<Vec<u16>>(); - let class = ffi::WNDCLASSEX { - cbSize: mem::size_of::<ffi::WNDCLASSEX>() as ffi::UINT, - style: ffi::CS_HREDRAW | ffi::CS_VREDRAW | ffi::CS_OWNDC, + let class = winapi::WNDCLASSEXW { + cbSize: mem::size_of::<winapi::WNDCLASSEXW>() as winapi::UINT, + style: winapi::CS_HREDRAW | winapi::CS_VREDRAW | winapi::CS_OWNDC, lpfnWndProc: callback, cbClsExtra: 0, cbWndExtra: 0, - hInstance: unsafe { ffi::GetModuleHandleW(ptr::null()) }, - hIcon: ptr::null(), - hCursor: ptr::null(), - hbrBackground: ptr::null(), + hInstance: unsafe { winapi::GetModuleHandleW(ptr::null()) }, + hIcon: ptr::null_mut(), + hCursor: ptr::null_mut(), + hbrBackground: ptr::null_mut(), lpszMenuName: ptr::null(), lpszClassName: class_name.as_ptr(), - hIconSm: ptr::null(), + hIconSm: ptr::null_mut(), }; // We ignore errors because registering the same window class twice would trigger // an error, and because errors here are detected during CreateWindowEx anyway. // Also since there is no weird element in the struct, there is no reason for this // call to fail. - unsafe { ffi::RegisterClassExW(&class) }; + unsafe { winapi::RegisterClassExW(&class) }; class_name }; // building a RECT object with coordinates - let mut rect = ffi::RECT { - left: 0, right: builder_dimensions.unwrap_or((1024, 768)).val0() as ffi::LONG, - top: 0, bottom: builder_dimensions.unwrap_or((1024, 768)).val1() as ffi::LONG, + let mut rect = winapi::RECT { + left: 0, right: builder_dimensions.unwrap_or((1024, 768)).val0() as winapi::LONG, + top: 0, bottom: builder_dimensions.unwrap_or((1024, 768)).val1() as winapi::LONG, }; // switching to fullscreen if necessary @@ -78,24 +82,24 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // adjusting the rect { let pos = monitor.get_position(); - rect.left += pos.val0() as ffi::LONG; - rect.right += pos.val0() as ffi::LONG; - rect.top += pos.val1() as ffi::LONG; - rect.bottom += pos.val1() as ffi::LONG; + rect.left += pos.val0() as winapi::LONG; + rect.right += pos.val0() as winapi::LONG; + rect.top += pos.val1() as winapi::LONG; + rect.bottom += pos.val1() as winapi::LONG; } // changing device settings - let mut screen_settings: ffi::DEVMODE = unsafe { mem::zeroed() }; - screen_settings.dmSize = mem::size_of::<ffi::DEVMODE>() as ffi::WORD; - screen_settings.dmPelsWidth = (rect.right - rect.left) as ffi::DWORD; - screen_settings.dmPelsHeight = (rect.bottom - rect.top) as ffi::DWORD; + let mut screen_settings: winapi::DEVMODEW = unsafe { mem::zeroed() }; + screen_settings.dmSize = mem::size_of::<winapi::DEVMODEW>() as winapi::WORD; + screen_settings.dmPelsWidth = (rect.right - rect.left) as winapi::DWORD; + screen_settings.dmPelsHeight = (rect.bottom - rect.top) as winapi::DWORD; screen_settings.dmBitsPerPel = 32; // TODO: ? - screen_settings.dmFields = ffi::DM_BITSPERPEL | ffi::DM_PELSWIDTH | ffi::DM_PELSHEIGHT; + screen_settings.dmFields = winapi::DM_BITSPERPEL | winapi::DM_PELSWIDTH | winapi::DM_PELSHEIGHT; - let result = unsafe { ffi::ChangeDisplaySettingsExW(monitor.get_system_name().as_ptr(), - &mut screen_settings, ptr::null(), ffi::CDS_FULLSCREEN, ptr::null_mut()) }; + let result = unsafe { winapi::ChangeDisplaySettingsExW(monitor.get_system_name().as_ptr(), + &mut screen_settings, ptr::null_mut(), winapi::CDS_FULLSCREEN, ptr::null_mut()) }; - if result != ffi::DISP_CHANGE_SUCCESSFUL { + if result != winapi::DISP_CHANGE_SUCCESSFUL { tx.send(Err(OsError(format!("ChangeDisplaySettings failed: {}", result)))); return; } @@ -103,26 +107,26 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // computing the style and extended style of the window let (ex_style, style) = if builder_monitor.is_some() { - (ffi::WS_EX_APPWINDOW, ffi::WS_POPUP | ffi::WS_CLIPSIBLINGS | ffi::WS_CLIPCHILDREN) + (winapi::WS_EX_APPWINDOW, winapi::WS_POPUP | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN) } else { - (ffi::WS_EX_APPWINDOW | ffi::WS_EX_WINDOWEDGE, - ffi::WS_OVERLAPPEDWINDOW | ffi::WS_CLIPSIBLINGS | ffi::WS_CLIPCHILDREN) + (winapi::WS_EX_APPWINDOW | winapi::WS_EX_WINDOWEDGE, + winapi::WS_OVERLAPPEDWINDOW | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN) }; // adjusting the window coordinates using the style - unsafe { ffi::AdjustWindowRectEx(&mut rect, style, 0, ex_style) }; + unsafe { winapi::AdjustWindowRectEx(&mut rect, style, 0, ex_style) }; // getting the address of wglCreateContextAttribsARB and the pixel format // that we will use let (extra_functions, pixel_format) = { // creating a dummy invisible window for GL initialization let dummy_window = unsafe { - let handle = ffi::CreateWindowExW(ex_style, class_name.as_ptr(), - title.as_ptr() as ffi::LPCWSTR, - style | ffi::WS_CLIPSIBLINGS | ffi::WS_CLIPCHILDREN, - ffi::CW_USEDEFAULT, ffi::CW_USEDEFAULT, + let handle = winapi::CreateWindowExW(ex_style, class_name.as_ptr(), + title.as_ptr() as winapi::LPCWSTR, + style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN, + winapi::CW_USEDEFAULT, winapi::CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, - ptr::null(), ptr::null(), ffi::GetModuleHandleW(ptr::null()), + ptr::null_mut(), ptr::null_mut(), winapi::GetModuleHandleW(ptr::null()), ptr::null_mut()); if handle.is_null() { @@ -137,11 +141,11 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // getting the HDC of the dummy window let dummy_hdc = { - let hdc = unsafe { ffi::GetDC(dummy_window) }; + let hdc = unsafe { winapi::GetDC(dummy_window) }; if hdc.is_null() { tx.send(Err(OsError(format!("GetDC function failed: {}", os::error_string(os::errno() as uint))))); - unsafe { ffi::DestroyWindow(dummy_window); } + unsafe { winapi::DestroyWindow(dummy_window); } return; } hdc @@ -150,35 +154,35 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // getting the pixel format that we will use let pixel_format = { // initializing a PIXELFORMATDESCRIPTOR that indicates what we want - let mut output: ffi::PIXELFORMATDESCRIPTOR = unsafe { mem::zeroed() }; - output.nSize = mem::size_of::<ffi::PIXELFORMATDESCRIPTOR>() as ffi::WORD; + let mut output: winapi::PIXELFORMATDESCRIPTOR = unsafe { mem::zeroed() }; + output.nSize = mem::size_of::<winapi::PIXELFORMATDESCRIPTOR>() as winapi::WORD; output.nVersion = 1; - output.dwFlags = ffi::PFD_DRAW_TO_WINDOW | ffi::PFD_DOUBLEBUFFER | - ffi::PFD_SUPPORT_OPENGL | ffi::PFD_GENERIC_ACCELERATED; - output.iPixelType = ffi::PFD_TYPE_RGBA; + output.dwFlags = winapi::PFD_DRAW_TO_WINDOW | winapi::PFD_DOUBLEBUFFER | + winapi::PFD_SUPPORT_OPENGL | winapi::PFD_GENERIC_ACCELERATED; + output.iPixelType = winapi::PFD_TYPE_RGBA; output.cColorBits = 24; output.cAlphaBits = 8; output.cAccumBits = 0; output.cDepthBits = 24; output.cStencilBits = 8; output.cAuxBuffers = 0; - output.iLayerType = ffi::PFD_MAIN_PLANE; + output.iLayerType = winapi::PFD_MAIN_PLANE; - let pf_index = unsafe { ffi::ChoosePixelFormat(dummy_hdc, &output) }; + let pf_index = unsafe { winapi::ChoosePixelFormat(dummy_hdc, &output) }; if pf_index == 0 { tx.send(Err(OsError(format!("ChoosePixelFormat function failed: {}", os::error_string(os::errno() as uint))))); - unsafe { ffi::DestroyWindow(dummy_window); } + unsafe { winapi::DestroyWindow(dummy_window); } return; } - if unsafe { ffi::DescribePixelFormat(dummy_hdc, pf_index, - mem::size_of::<ffi::PIXELFORMATDESCRIPTOR>() as ffi::UINT, &mut output) } == 0 + if unsafe { winapi::DescribePixelFormat(dummy_hdc, pf_index, + mem::size_of::<winapi::PIXELFORMATDESCRIPTOR>() as winapi::UINT, &mut output) } == 0 { tx.send(Err(OsError(format!("DescribePixelFormat function failed: {}", os::error_string(os::errno() as uint))))); - unsafe { ffi::DestroyWindow(dummy_window); } + unsafe { winapi::DestroyWindow(dummy_window); } return; } @@ -187,45 +191,45 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // calling SetPixelFormat unsafe { - if ffi::SetPixelFormat(dummy_hdc, 1, &pixel_format) == 0 { + if winapi::SetPixelFormat(dummy_hdc, 1, &pixel_format) == 0 { tx.send(Err(OsError(format!("SetPixelFormat function failed: {}", os::error_string(os::errno() as uint))))); - ffi::DestroyWindow(dummy_window); + winapi::DestroyWindow(dummy_window); return; } } // creating the dummy OpenGL context let dummy_context = { - let ctxt = unsafe { ffi::wgl::CreateContext(dummy_hdc) }; + let ctxt = unsafe { gl::wgl::CreateContext(dummy_hdc as *const libc::c_void) }; if ctxt.is_null() { tx.send(Err(OsError(format!("wglCreateContext function failed: {}", os::error_string(os::errno() as uint))))); - unsafe { ffi::DestroyWindow(dummy_window); } + unsafe { winapi::DestroyWindow(dummy_window); } return; } ctxt }; // making context current - unsafe { ffi::wgl::MakeCurrent(dummy_hdc, dummy_context); } + unsafe { gl::wgl::MakeCurrent(dummy_hdc as *const libc::c_void, dummy_context); } // loading the extra WGL functions - let extra_functions = ffi::wgl_extra::Wgl::load_with(|addr| { + let extra_functions = gl::wgl_extra::Wgl::load_with(|addr| { unsafe { addr.with_c_str(|s| { use libc; - ffi::wgl::GetProcAddress(s) as *const libc::c_void + gl::wgl::GetProcAddress(s) as *const libc::c_void }) } }); // removing current context - unsafe { ffi::wgl::MakeCurrent(ptr::null(), ptr::null()); } + unsafe { gl::wgl::MakeCurrent(ptr::null(), ptr::null()); } // destroying the context and the window - unsafe { ffi::wgl::DeleteContext(dummy_context); } - unsafe { ffi::DestroyWindow(dummy_window); } + unsafe { gl::wgl::DeleteContext(dummy_context); } + unsafe { winapi::DestroyWindow(dummy_window); } // returning the address (extra_functions, pixel_format) @@ -242,16 +246,16 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin let style = if builder_hidden { style } else { - style | ffi::WS_VISIBLE + style | winapi::WS_VISIBLE }; - let handle = ffi::CreateWindowExW(ex_style, class_name.as_ptr(), - title.as_ptr() as ffi::LPCWSTR, - style | ffi::WS_CLIPSIBLINGS | ffi::WS_CLIPCHILDREN, - if builder_monitor.is_some() { 0 } else { ffi::CW_USEDEFAULT }, - if builder_monitor.is_some() { 0 } else { ffi::CW_USEDEFAULT }, - width.unwrap_or(ffi::CW_USEDEFAULT), height.unwrap_or(ffi::CW_USEDEFAULT), - ptr::null(), ptr::null(), ffi::GetModuleHandleW(ptr::null()), + let handle = winapi::CreateWindowExW(ex_style, class_name.as_ptr(), + title.as_ptr() as winapi::LPCWSTR, + style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN, + if builder_monitor.is_some() { 0 } else { winapi::CW_USEDEFAULT }, + if builder_monitor.is_some() { 0 } else { winapi::CW_USEDEFAULT }, + width.unwrap_or(winapi::CW_USEDEFAULT), height.unwrap_or(winapi::CW_USEDEFAULT), + ptr::null_mut(), ptr::null_mut(), winapi::GetModuleHandleW(ptr::null()), ptr::null_mut()); if handle.is_null() { @@ -266,11 +270,11 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // getting the HDC of the window let hdc = { - let hdc = unsafe { ffi::GetDC(real_window) }; + let hdc = unsafe { winapi::GetDC(real_window) }; if hdc.is_null() { tx.send(Err(OsError(format!("GetDC function failed: {}", os::error_string(os::errno() as uint))))); - unsafe { ffi::DestroyWindow(real_window); } + unsafe { winapi::DestroyWindow(real_window); } return; } hdc @@ -278,10 +282,10 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // calling SetPixelFormat unsafe { - if ffi::SetPixelFormat(hdc, 1, &pixel_format) == 0 { + if winapi::SetPixelFormat(hdc, 1, &pixel_format) == 0 { tx.send(Err(OsError(format!("SetPixelFormat function failed: {}", os::error_string(os::errno() as uint))))); - ffi::DestroyWindow(real_window); + winapi::DestroyWindow(real_window); return; } } @@ -294,29 +298,30 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin if builder_gl_version.is_some() { let version = builder_gl_version.as_ref().unwrap(); - attributes.push(ffi::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int); + attributes.push(gl::wgl_extra::CONTEXT_MAJOR_VERSION_ARB as libc::c_int); attributes.push(version.val0() as libc::c_int); - attributes.push(ffi::wgl_extra::CONTEXT_MINOR_VERSION_ARB as libc::c_int); + attributes.push(gl::wgl_extra::CONTEXT_MINOR_VERSION_ARB as libc::c_int); attributes.push(version.val1() as libc::c_int); } if builder_debug { - attributes.push(ffi::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int); - attributes.push(ffi::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int); + attributes.push(gl::wgl_extra::CONTEXT_FLAGS_ARB as libc::c_int); + attributes.push(gl::wgl_extra::CONTEXT_DEBUG_BIT_ARB as libc::c_int); } attributes.push(0); let ctxt = unsafe { if extra_functions.CreateContextAttribsARB.is_loaded() { - let share = if let Some(c) = builder_sharelists { c } else { ptr::null() }; - extra_functions.CreateContextAttribsARB(hdc, share, + let share = if let Some(c) = builder_sharelists { c } else { ptr::null_mut() }; + extra_functions.CreateContextAttribsARB(hdc as *const libc::c_void, + share as *const libc::c_void, attributes.as_slice().as_ptr()) } else { - let ctxt = ffi::wgl::CreateContext(hdc); + let ctxt = gl::wgl::CreateContext(hdc as *const libc::c_void); if let Some(c) = builder_sharelists { - ffi::wgl::ShareLists(c, ctxt); + gl::wgl::ShareLists(c as *const libc::c_void, ctxt); }; ctxt } @@ -325,7 +330,7 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin if ctxt.is_null() { tx.send(Err(OsError(format!("OpenGL context creation failed: {}", os::error_string(os::errno() as uint))))); - unsafe { ffi::DestroyWindow(real_window); } + unsafe { winapi::DestroyWindow(real_window); } return; } @@ -334,7 +339,7 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // calling SetForegroundWindow if fullscreen if builder_monitor.is_some() { - unsafe { ffi::SetForegroundWindow(real_window) }; + unsafe { winapi::SetForegroundWindow(real_window) }; } // filling the WINDOW task-local storage @@ -351,12 +356,12 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin let gl_library = { let name = "opengl32.dll".utf16_units().chain(Some(0).into_iter()) .collect::<Vec<u16>>().as_ptr(); - let lib = unsafe { ffi::LoadLibraryW(name) }; + let lib = unsafe { winapi::LoadLibraryW(name) }; if lib.is_null() { tx.send(Err(OsError(format!("LoadLibrary function failed: {}", os::error_string(os::errno() as uint))))); - unsafe { ffi::wgl::DeleteContext(context); } - unsafe { ffi::DestroyWindow(real_window); } + unsafe { gl::wgl::DeleteContext(context); } + unsafe { winapi::DestroyWindow(real_window); } return; } lib @@ -365,25 +370,25 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin // handling vsync if builder_vsync { if extra_functions.SwapIntervalEXT.is_loaded() { - unsafe { ffi::wgl::MakeCurrent(hdc, context) }; + unsafe { gl::wgl::MakeCurrent(hdc as *const libc::c_void, context) }; if unsafe { extra_functions.SwapIntervalEXT(1) } == 0 { tx.send(Err(OsError(format!("wglSwapIntervalEXT failed")))); - unsafe { ffi::wgl::DeleteContext(context); } - unsafe { ffi::DestroyWindow(real_window); } + unsafe { gl::wgl::DeleteContext(context); } + unsafe { winapi::DestroyWindow(real_window); } return; } // it is important to remove the current context, otherwise you get very weird // errors - unsafe { ffi::wgl::MakeCurrent(ptr::null(), ptr::null()); } + unsafe { gl::wgl::MakeCurrent(ptr::null(), ptr::null()); } } } // building the struct let window = Window{ window: real_window, - hdc: hdc, - context: context, + hdc: hdc as winapi::HDC, + context: context as winapi::HGLRC, gl_library: gl_library, events_receiver: events_receiver, is_closed: AtomicBool::new(false), @@ -397,12 +402,12 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin loop { let mut msg = unsafe { mem::uninitialized() }; - if unsafe { ffi::GetMessageW(&mut msg, ptr::null(), 0, 0) } == 0 { + if unsafe { winapi::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) } == 0 { break; } - unsafe { ffi::TranslateMessage(&msg) }; - unsafe { ffi::DispatchMessageW(&msg) }; // calls `callback` (see below) + unsafe { winapi::TranslateMessage(&msg) }; + unsafe { winapi::DispatchMessageW(&msg) }; // calls `callback` (see below) } }); @@ -410,7 +415,7 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin } /// Checks that the window is the good one, and if so send the event to it. -fn send_event(input_window: ffi::HWND, event: Event) { +fn send_event(input_window: winapi::HWND, event: Event) { WINDOW.with(|window| { let window = window.borrow(); let stored = match *window { @@ -431,11 +436,11 @@ fn send_event(input_window: ffi::HWND, event: Event) { /// This is the callback that is called by `DispatchMessage` in the events loop. /// /// Returning 0 tells the Win32 API that the message has been processed. -extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, - wparam: ffi::WPARAM, lparam: ffi::LPARAM) -> ffi::LRESULT +extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, + wparam: winapi::WPARAM, lparam: winapi::LPARAM) -> winapi::LRESULT { match msg { - ffi::WM_DESTROY => { + winapi::WM_DESTROY => { use events::Event::Closed; WINDOW.with(|w| { @@ -446,7 +451,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, }; if win == &window { - unsafe { ffi::PostQuitMessage(0); } + unsafe { winapi::PostQuitMessage(0); } } }); @@ -454,27 +459,27 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_ERASEBKGND => { + winapi::WM_ERASEBKGND => { 1 }, - ffi::WM_SIZE => { + winapi::WM_SIZE => { use events::Event::Resized; - let w = ffi::LOWORD(lparam as ffi::DWORD) as uint; - let h = ffi::HIWORD(lparam as ffi::DWORD) as uint; + let w = winapi::LOWORD(lparam as winapi::DWORD) as uint; + let h = winapi::HIWORD(lparam as winapi::DWORD) as uint; send_event(window, Resized(w, h)); 0 }, - ffi::WM_MOVE => { + winapi::WM_MOVE => { use events::Event::Moved; - let x = ffi::LOWORD(lparam as ffi::DWORD) as i16 as int; - let y = ffi::HIWORD(lparam as ffi::DWORD) as i16 as int; + let x = winapi::LOWORD(lparam as winapi::DWORD) as i16 as int; + let y = winapi::HIWORD(lparam as winapi::DWORD) as i16 as int; send_event(window, Moved(x, y)); 0 }, - ffi::WM_CHAR => { + winapi::WM_CHAR => { use std::mem; use events::Event::ReceivedCharacter; let chr: char = unsafe { mem::transmute(wparam as u32) }; @@ -482,18 +487,18 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_MOUSEMOVE => { + winapi::WM_MOUSEMOVE => { use events::Event::MouseMoved; - let x = ffi::GET_X_LPARAM(lparam) as int; - let y = ffi::GET_Y_LPARAM(lparam) as int; + let x = winapi::GET_X_LPARAM(lparam) as int; + let y = winapi::GET_Y_LPARAM(lparam) as int; send_event(window, MouseMoved((x, y))); 0 }, - ffi::WM_MOUSEWHEEL => { + winapi::WM_MOUSEWHEEL => { use events::Event::MouseWheel; let value = (wparam >> 16) as i16; @@ -504,7 +509,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_KEYDOWN => { + winapi::WM_KEYDOWN => { use events::Event::KeyboardInput; use events::ElementState::Pressed; let scancode = ((lparam >> 16) & 0xff) as u8; @@ -513,7 +518,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_KEYUP => { + winapi::WM_KEYUP => { use events::Event::KeyboardInput; use events::ElementState::Released; let scancode = ((lparam >> 16) & 0xff) as u8; @@ -522,7 +527,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_LBUTTONDOWN => { + winapi::WM_LBUTTONDOWN => { use events::Event::MouseInput; use events::MouseButton::LeftMouseButton; use events::ElementState::Pressed; @@ -530,7 +535,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_LBUTTONUP => { + winapi::WM_LBUTTONUP => { use events::Event::MouseInput; use events::MouseButton::LeftMouseButton; use events::ElementState::Released; @@ -538,7 +543,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_RBUTTONDOWN => { + winapi::WM_RBUTTONDOWN => { use events::Event::MouseInput; use events::MouseButton::RightMouseButton; use events::ElementState::Pressed; @@ -546,7 +551,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_RBUTTONUP => { + winapi::WM_RBUTTONUP => { use events::Event::MouseInput; use events::MouseButton::RightMouseButton; use events::ElementState::Released; @@ -554,7 +559,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_MBUTTONDOWN => { + winapi::WM_MBUTTONDOWN => { use events::Event::MouseInput; use events::MouseButton::MiddleMouseButton; use events::ElementState::Pressed; @@ -562,7 +567,7 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_MBUTTONUP => { + winapi::WM_MBUTTONUP => { use events::Event::MouseInput; use events::MouseButton::MiddleMouseButton; use events::ElementState::Released; @@ -570,29 +575,29 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT, 0 }, - ffi::WM_SETFOCUS => { + winapi::WM_SETFOCUS => { use events::Event::Focused; send_event(window, Focused(true)); 0 }, - ffi::WM_KILLFOCUS => { + winapi::WM_KILLFOCUS => { use events::Event::Focused; send_event(window, Focused(false)); 0 }, _ => unsafe { - ffi::DefWindowProcW(window, msg, wparam, lparam) + winapi::DefWindowProcW(window, msg, wparam, lparam) } } } -/*fn hints_to_pixelformat(hints: &Hints) -> ffi::PIXELFORMATDESCRIPTOR { +/*fn hints_to_pixelformat(hints: &Hints) -> winapi::PIXELFORMATDESCRIPTOR { use std::mem; - ffi::PIXELFORMATDESCRIPTOR { - nSize: size_of::<ffi::PIXELFORMATDESCRIPTOR>(), + winapi::PIXELFORMATDESCRIPTOR { + nSize: size_of::<winapi::PIXELFORMATDESCRIPTOR>(), nVersion: 1, dwFlags: if hints.stereo { PFD_STEREO } else { 0 }, |