Some scaling fixes and new cursor rules

This commit is contained in:
JanNeuendorf 2025-01-04 21:41:34 +01:00
parent 9ed60f1ff9
commit 454cf22322
2 changed files with 28 additions and 8 deletions

View File

@ -21,8 +21,8 @@ fn window_conf() -> Conf {
Conf {
window_title: "SVC16".to_owned(),
window_width: 512 * cli.scaling,
window_height: 512 * cli.scaling,
window_width: 256 * cli.scaling,
window_height: 256 * cli.scaling,
fullscreen: cli.fullscreen,
..Default::default()
@ -31,7 +31,7 @@ fn window_conf() -> Conf {
#[macroquad::main(window_conf)]
async fn main() -> Result<()> {
let cli = Cli::parse();
show_mouse(cli.cursor);
// show_mouse(cli.cursor);
let mut buffer = [Color::from_rgba(255, 255, 255, 255); 256 * 256];
let texture = Texture2D::from_image(&Image::gen_image_color(256, 256, BLACK));
@ -71,6 +71,12 @@ async fn main() -> Result<()> {
texture.update(&image);
clear_background(BLACK);
let layout = Layout::generate();
if layout.cursor_in_window() {
show_mouse(cli.cursor);
} else {
show_mouse(true);
}
draw_texture_ex(
&texture,
layout.x,

View File

@ -15,13 +15,27 @@ impl Layout {
let clamped_y = (raw_y.clamp(self.y, self.y + self.size) - self.y) / self.size * 255.;
(clamped_x, clamped_y)
}
pub fn cursor_in_window(&self) -> bool {
let mp = mouse_position();
mp.0 >= self.x
&& mp.0 < (self.x + self.size)
&& mp.1 >= self.y
&& mp.1 < (self.y + self.size)
}
}
fn place(width: f32, height: f32) -> (f32, f32, f32) {
let minsize = width.min(height);
let power_two = minsize.log2().floor() as u32;
let image_size = (2 as usize).pow(power_two) as f32;
let startx = (width - image_size) / 2.;
let starty = (height - image_size) / 2.;
(startx, starty, image_size)
if minsize >= 256. {
let image_size = (minsize / 256.).floor() * 256.;
let startx = (width - image_size) / 2.;
let starty = (height - image_size) / 2.;
return (startx, starty, image_size);
} else {
let power_two = minsize.log2().floor() as u32;
let image_size = (2 as usize).pow(power_two) as f32;
let startx = (width - image_size) / 2.;
let starty = (height - image_size) / 2.;
(startx, starty, image_size)
}
}