mod api;
mod context;
mod device;
mod event;
mod geometry;
pub mod ime;
mod monitor;
mod procedure;
#[cfg(feature = "raw_input")]
pub mod raw_input;
mod resource;
mod window;
#[macro_use]
mod error;
pub use context::RunType;
pub use device::*;
pub use event::*;
pub use geometry::*;
pub use monitor::*;
pub use resource::*;
pub use window::*;
use context::*;
use std::ptr::null_mut;
use winapi::um::winuser::*;
pub const DEFAULT_DPI: i32 = 96;
pub fn initialize<T: EventHandler + 'static>() {
api::enable_dpi_awareness();
window::register_class::<T>();
api::enable_gui_thread();
context::create_context();
}
pub fn run<T: EventHandler + 'static>(run_type: RunType, handler: T) {
set_event_handler(handler);
let mut msg = MSG::default();
match run_type {
RunType::Idle => unsafe {
while msg.message != WM_QUIT {
call_handler(|eh: &mut T, _| eh.begin_frame());
if PeekMessageW(&mut msg, null_mut(), 0, 0, PM_REMOVE) != 0 {
TranslateMessage(&msg);
DispatchMessageW(&msg);
} else {
call_handler(|eh: &mut T, _| eh.idle());
}
maybe_resume_unwind();
call_handler(|eh: &mut T, _| eh.end_frame());
}
},
RunType::Wait => unsafe {
loop {
let ret = GetMessageW(&mut msg, null_mut(), 0, 0);
if ret == 0 || ret == -1 {
break;
}
TranslateMessage(&msg);
DispatchMessageW(&msg);
maybe_resume_unwind();
}
},
}
destroy_context();
}