Ran rustfmt

This commit is contained in:
Daniel Collin 2015-11-27 23:47:15 +01:00
parent 15ec55aae2
commit 860f8b4f3d

View file

@ -20,14 +20,15 @@ static mut CLOSE_APP: bool = false;
// Wrap this so we can have a proper numbef of bmiColors to write in
#[repr(C)]
struct BitmapInfo {
pub bmi_header: BITMAPINFOHEADER,
pub bmi_colors: [RGBQUAD; 3],
pub bmi_header: BITMAPINFOHEADER,
pub bmi_colors: [RGBQUAD; 3],
}
unsafe extern "system" fn wnd_proc(window: winapi::HWND, msg: winapi::UINT,
wparam: winapi::WPARAM, lparam: winapi::LPARAM)
-> winapi::LRESULT
{
unsafe extern "system" fn wnd_proc(window: winapi::HWND,
msg: winapi::UINT,
wparam: winapi::WPARAM,
lparam: winapi::LPARAM)
-> winapi::LRESULT {
match msg {
winapi::winuser::WM_KEYDOWN => {
if (wparam & 0xff) == 27 {
@ -37,7 +38,7 @@ unsafe extern "system" fn wnd_proc(window: winapi::HWND, msg: winapi::UINT,
winapi::winuser::WM_PAINT => {
let mut rect: winapi::RECT = mem::uninitialized();
let buffer = user32::GetWindowLongPtrW(window, winapi::winuser::GWLP_USERDATA);
let buffer = user32::GetWindowLongPtrW(window, winapi::winuser::GWLP_USERDATA);
user32::GetClientRect(window, &mut rect);
@ -51,17 +52,25 @@ unsafe extern "system" fn wnd_proc(window: winapi::HWND, msg: winapi::UINT,
bitmap_info.bmi_header.biCompression = winapi::wingdi::BI_BITFIELDS;
bitmap_info.bmi_header.biWidth = width;
bitmap_info.bmi_header.biHeight = -height;
bitmap_info.bmi_colors[0].rgbRed = 0xff;
bitmap_info.bmi_colors[1].rgbGreen = 0xff;
bitmap_info.bmi_colors[2].rgbBlue = 0xff;
bitmap_info.bmi_colors[0].rgbRed = 0xff;
bitmap_info.bmi_colors[1].rgbGreen = 0xff;
bitmap_info.bmi_colors[2].rgbBlue = 0xff;
let dc = user32::GetDC(window);
gdi32::StretchDIBits(dc, 0, 0, width, height, 0, 0, width, height,
mem::transmute(buffer),
mem::transmute(&bitmap_info),
winapi::wingdi::DIB_RGB_COLORS,
winapi::wingdi::SRCCOPY);
gdi32::StretchDIBits(dc,
0,
0,
width,
height,
0,
0,
width,
height,
mem::transmute(buffer),
mem::transmute(&bitmap_info),
winapi::wingdi::DIB_RGB_COLORS,
winapi::wingdi::SRCCOPY);
user32::ValidateRect(window, ptr::null_mut());
@ -78,8 +87,8 @@ pub enum MinifbError {
UnableToCreateWindow,
}
fn to_wstring(str : &str) -> *const u16 {
let v : Vec<u16> = OsStr::new(str).encode_wide(). chain(Some(0).into_iter()).collect();
fn to_wstring(str: &str) -> *const u16 {
let v: Vec<u16> = OsStr::new(str).encode_wide().chain(Some(0).into_iter()).collect();
v.as_ptr()
}
@ -90,9 +99,9 @@ pub struct Minifb {
impl Minifb {
fn open_window(name: &str, width: usize, height: usize) -> HWND {
unsafe {
let class_name = to_wstring("minifb_window");
let class_name = to_wstring("minifb_window");
let s = CString::new(name).unwrap();
let class = WNDCLASSW {
style: winapi::CS_HREDRAW | winapi::CS_VREDRAW | winapi::CS_OWNDC,
lpfnWndProc: Some(wnd_proc),
@ -109,21 +118,33 @@ impl Minifb {
user32::RegisterClassW(&class);
let mut rect = winapi::RECT {
left: 0, right: width as winapi::LONG,
top: 0, bottom: height as winapi::LONG,
left: 0,
right: width as winapi::LONG,
top: 0,
bottom: height as winapi::LONG,
};
user32::AdjustWindowRect(&mut rect, winapi::WS_POPUP | winapi::WS_SYSMENU | winapi::WS_CAPTION, 0);
user32::AdjustWindowRect(&mut rect,
winapi::WS_POPUP | winapi::WS_SYSMENU | winapi::WS_CAPTION,
0);
rect.right -= rect.left;
rect.bottom -= rect.top;
let handle = user32::CreateWindowExA(0,
"minifb_window".as_ptr() as *mut _, s.as_ptr(),
winapi::WS_OVERLAPPEDWINDOW & !winapi::WS_MAXIMIZEBOX & !winapi::WS_THICKFRAME,
winapi::CW_USEDEFAULT, winapi::CW_USEDEFAULT,
rect.right, rect.bottom,
ptr::null_mut(), ptr::null_mut(), ptr::null_mut(), ptr::null_mut());
"minifb_window".as_ptr() as *mut _,
s.as_ptr(),
winapi::WS_OVERLAPPEDWINDOW &
!winapi::WS_MAXIMIZEBOX &
!winapi::WS_THICKFRAME,
winapi::CW_USEDEFAULT,
winapi::CW_USEDEFAULT,
rect.right,
rect.bottom,
ptr::null_mut(),
ptr::null_mut(),
ptr::null_mut(),
ptr::null_mut());
if !handle.is_null() {
user32::ShowWindow(handle, winapi::SW_NORMAL);
@ -138,7 +159,7 @@ impl Minifb {
match handle.is_null() {
true => None,
false => Some(Minifb { window : handle }),
false => Some(Minifb { window: handle }),
}
}
@ -146,10 +167,13 @@ impl Minifb {
unsafe {
let mut msg = mem::uninitialized();
user32::SetWindowLongPtrW(self.window, winapi::winuser::GWLP_USERDATA, buffer.as_ptr() as i64);
user32::SetWindowLongPtrW(self.window,
winapi::winuser::GWLP_USERDATA,
buffer.as_ptr() as i64);
user32::InvalidateRect(self.window, ptr::null_mut(), winapi::TRUE);
while user32::PeekMessageW(&mut msg, self.window, 0, 0, winapi::winuser::PM_REMOVE) != 0 {
while user32::PeekMessageW(&mut msg, self.window, 0, 0, winapi::winuser::PM_REMOVE) !=
0 {
user32::TranslateMessage(&mut msg);
user32::DispatchMessageW(&mut msg);
}
@ -160,6 +184,3 @@ impl Minifb {
}
}
}