Slightly altered virtual mouse position

This commit is contained in:
JanNeuendorf 2025-05-04 14:44:06 +02:00
parent b6086eed8c
commit 7be70269e9
3 changed files with 7 additions and 3 deletions

2
Cargo.lock generated
View File

@ -548,7 +548,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "svc16"
version = "1.0.0"
version = "1.0.1"
dependencies = [
"anyhow",
"clap",

View File

@ -1,6 +1,6 @@
[package]
name = "svc16"
version = "1.0.0"
version = "1.0.1"
edition = "2021"
authors = ["Jan Neuendorf"]
description = "An emulator for a simple virtual computer"

View File

@ -35,7 +35,11 @@ impl Layout {
let (raw_x, raw_y) = mouse_position();
let clamped_x = (raw_x.clamp(self.x, self.x + self.size) - self.x) / self.size * 255.;
let clamped_y = (raw_y.clamp(self.y, self.y + self.size) - self.y) / self.size * 255.;
(clamped_x, clamped_y)
// The mouse position is slightly modified so that the maximal position can be reached when the image takes up the entire window.
(
(clamped_x * 255. / 254.).min(255.),
(clamped_y * 255. / 254.).min(255.),
)
}
pub fn cursor_in_window(&self) -> bool {
let mp = mouse_position();