From fb3d681f555dc2045c4892732eb0b9095ef8163b Mon Sep 17 00:00:00 2001 From: Ry Date: Sat, 16 Apr 2022 15:15:03 -0700 Subject: [PATCH] fox32+fox32rom: Add EVENT_TYPE_MOUSE_RELEASE --- src/bus.rs | 19 +++++++++++-------- src/main.rs | 6 +++++- src/mouse.rs | 5 +++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/bus.rs b/src/bus.rs index 81c4aab..a5fb63c 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -51,15 +51,17 @@ impl Bus { 0x00 => { // we're reading the button states let mut byte: u8 = 0x00; - let mut mouse_lock = self.mouse.lock().expect("failed to lock the mouse mutex"); - if mouse_lock.click { - byte |= 0b01; - mouse_lock.click = false; + let mouse_lock = self.mouse.lock().expect("failed to lock the mouse mutex"); + if mouse_lock.clicked { + byte |= 0b001; + } + if mouse_lock.released { + byte |= 0b010; } if mouse_lock.held { - byte |= 0b10; + byte |= 0b100; } else { - byte &= !0b10; + byte &= !0b100; } byte as u32 } @@ -145,8 +147,9 @@ impl Bus { 0x00 => { // we're setting the button states let mut mouse_lock = self.mouse.lock().expect("failed to lock the mouse mutex"); - mouse_lock.click = word & (1 << 0) != 0; - mouse_lock.held = word & (1 << 1) != 0; + mouse_lock.clicked = word & (1 << 0) != 0; + mouse_lock.released = word & (1 << 1) != 0; + mouse_lock.held = word & (1 << 2) != 0; } 0x01 => { // we're setting the position diff --git a/src/main.rs b/src/main.rs index bb5a5eb..1b7e895 100644 --- a/src/main.rs +++ b/src/main.rs @@ -217,9 +217,13 @@ fn main() { let mut mouse_lock = mouse.lock().expect("failed to lock the mouse mutex"); mouse_lock.x = mouse_pixel.0; mouse_lock.y = mouse_pixel.1; + if mouse_lock.held && !input.mouse_held(0) { + // mouse button was released this frame + mouse_lock.released = true; + } mouse_lock.held = input.mouse_held(0); if input.mouse_pressed(0) { - mouse_lock.click = true; + mouse_lock.clicked = true; } } }); diff --git a/src/mouse.rs b/src/mouse.rs index 6ae653d..f6846f7 100644 --- a/src/mouse.rs +++ b/src/mouse.rs @@ -3,12 +3,13 @@ pub struct Mouse { pub x: u16, pub y: u16, - pub click: bool, + pub clicked: bool, + pub released: bool, pub held: bool, } impl Mouse { pub fn new() -> Self { - Mouse { x: 0, y: 0, click: false, held: false } + Mouse { x: 0, y: 0, clicked: false, released: false, held: false } } } \ No newline at end of file