Implemented scaling

BestFit isn't implemented yet though
This commit is contained in:
Daniel Collin 2015-12-11 10:33:20 +01:00
parent 2f5503d115
commit 6f47463a2e
2 changed files with 27 additions and 5 deletions

View file

@ -12,6 +12,7 @@ extern crate core_foundation;
/// Scale will scale the frame buffer and the window that is being sent in when calling the update /// Scale will scale the frame buffer and the window that is being sent in when calling the update
/// function. This is useful if you for example want to display a 320 x 256 window on a screen with /// function. This is useful if you for example want to display a 320 x 256 window on a screen with
/// much higher resolution which would result in that the window is very small. /// much higher resolution which would result in that the window is very small.
#[derive(Clone, Copy)]
pub enum Scale { pub enum Scale {
/// This mode checks your current screen resolution and will caluclate the largest window size /// This mode checks your current screen resolution and will caluclate the largest window size
/// that can be used within that limit and resize it. Useful if you have a small buffer to /// that can be used within that limit and resize it. Useful if you have a small buffer to

View file

@ -162,8 +162,8 @@ unsafe extern "system" fn wnd_proc(window: winapi::HWND,
gdi32::StretchDIBits(wnd.dc.unwrap(), gdi32::StretchDIBits(wnd.dc.unwrap(),
0, 0,
0, 0,
width, width * wnd.scale_factor,
height, height * wnd.scale_factor,
0, 0,
0, 0,
width, width,
@ -198,10 +198,11 @@ pub struct Window {
keys: [bool; 512], keys: [bool; 512],
buffer: Vec<u32>, buffer: Vec<u32>,
is_open : bool, is_open : bool,
scale_factor: i32,
} }
impl Window { impl Window {
fn open_window(name: &str, width: usize, height: usize, _: Scale, _: Vsync) -> Option<HWND> { fn open_window(name: &str, width: usize, height: usize, scale: Scale, _: Vsync) -> Option<HWND> {
unsafe { unsafe {
let class_name = to_wstring("minifb_window"); let class_name = to_wstring("minifb_window");
let class = WNDCLASSW { let class = WNDCLASSW {
@ -222,11 +223,15 @@ impl Window {
return None; return None;
} }
let scale_factor = Self::get_scale_factor(scale);
let new_width = width * scale_factor as usize;
let new_height = height * scale_factor as usize;
let mut rect = winapi::RECT { let mut rect = winapi::RECT {
left: 0, left: 0,
right: width as winapi::LONG, right: new_width as winapi::LONG,
top: 0, top: 0,
bottom: height as winapi::LONG, bottom: new_height as winapi::LONG,
}; };
user32::AdjustWindowRect(&mut rect, user32::AdjustWindowRect(&mut rect,
@ -282,6 +287,7 @@ impl Window {
keys: [false; 512], keys: [false; 512],
buffer: Vec::new(), buffer: Vec::new(),
is_open: true, is_open: true,
scale_factor: Self::get_scale_factor(scale),
}; };
Ok(window) Ok(window)
@ -316,6 +322,21 @@ impl Window {
} }
} }
} }
fn get_scale_factor(scale: Scale) -> i32 {
// TODO: Implement best fit
let factor: i32 = match scale {
Scale::X1 => 1,
Scale::X2 => 2,
Scale::X4 => 4,
Scale::X8 => 8,
Scale::X16 => 16,
Scale::X32 => 32,
_ => 1,
};
return factor;
}
} }
impl Drop for Window { impl Drop for Window {