mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-24 03:41:29 +11:00
Implemented FitScreen
This commit is contained in:
parent
ef9ac3e88c
commit
03e8075157
|
@ -202,7 +202,7 @@ pub struct Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
fn open_window(name: &str, width: usize, height: usize, scale: Scale, _: Vsync) -> Option<HWND> {
|
fn open_window(name: &str, width: usize, height: usize, scale_factor: i32, _: 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 {
|
||||||
|
@ -223,7 +223,6 @@ impl Window {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let scale_factor = Self::get_scale_factor(scale);
|
|
||||||
let new_width = width * scale_factor as usize;
|
let new_width = width * scale_factor as usize;
|
||||||
let new_height = height * scale_factor as usize;
|
let new_height = height * scale_factor as usize;
|
||||||
|
|
||||||
|
@ -275,7 +274,9 @@ impl Window {
|
||||||
vsync: Vsync)
|
vsync: Vsync)
|
||||||
-> Result<Window, &str> {
|
-> Result<Window, &str> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let handle = Self::open_window(name, width, height, scale, vsync);
|
let scale_factor = Self::get_scale_factor(width, height, scale);
|
||||||
|
|
||||||
|
let handle = Self::open_window(name, width, height, scale_factor, vsync);
|
||||||
|
|
||||||
if handle.is_none() {
|
if handle.is_none() {
|
||||||
return Err("Unable to create Window");
|
return Err("Unable to create Window");
|
||||||
|
@ -287,7 +288,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),
|
scale_factor: scale_factor,
|
||||||
width: width as i32,
|
width: width as i32,
|
||||||
height: height as i32,
|
height: height as i32,
|
||||||
};
|
};
|
||||||
|
@ -325,7 +326,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_scale_factor(scale: Scale) -> i32 {
|
unsafe fn get_scale_factor(width: usize, height: usize, scale: Scale) -> i32 {
|
||||||
// TODO: Implement best fit
|
// TODO: Implement best fit
|
||||||
let factor: i32 = match scale {
|
let factor: i32 = match scale {
|
||||||
Scale::X1 => 1,
|
Scale::X1 => 1,
|
||||||
|
@ -334,7 +335,25 @@ impl Window {
|
||||||
Scale::X8 => 8,
|
Scale::X8 => 8,
|
||||||
Scale::X16 => 16,
|
Scale::X16 => 16,
|
||||||
Scale::X32 => 32,
|
Scale::X32 => 32,
|
||||||
_ => 1,
|
Scale::FitScreen => {
|
||||||
|
let screen_x = user32::GetSystemMetrics(winapi::winuser::SM_CXSCREEN) as i32;
|
||||||
|
let screen_y = user32::GetSystemMetrics(winapi::winuser::SM_CYSCREEN) as i32;
|
||||||
|
|
||||||
|
let mut scale = 1i32;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let w = width as i32 * (scale + 1);
|
||||||
|
let h = height as i32 * (scale + 1);
|
||||||
|
|
||||||
|
if w > screen_x || h > screen_y {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
scale *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
scale
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return factor;
|
return factor;
|
||||||
|
|
Loading…
Reference in a new issue