Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for when the mouse has changed #317

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bracket-terminal/src/bterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct BTerm {
pub key: Option<VirtualKeyCode>,
pub mouse_pos: (i32, i32),
pub left_click: bool,
pub mouse_changed: bool,
pub shift: bool,
pub control: bool,
pub alt: bool,
Expand Down Expand Up @@ -357,6 +358,7 @@ impl BTerm {
if button_num == 0 {
self.left_click = true;
}
self.mouse_changed = true;
let mut input = INPUT.lock();
if pressed {
input.on_mouse_button_down(button_num);
Expand All @@ -372,6 +374,7 @@ impl BTerm {
/// Internal: mark mouse position changes
pub(crate) fn on_mouse_position(&mut self, x: f64, y: f64) {
let bi = BACKEND_INTERNAL.lock();
self.mouse_changed = true;
self.mouse_pos = (x as i32, y as i32);
let mut input = INPUT.lock();
input.on_mouse_pixel_position(x, y);
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/crossterm_be/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn init_raw<S: ToString>(
frame_time_ms: 0.0,
active_console: 0,
key: None,
mouse_changed: false,
mouse_pos: (0, 0),
left_click: false,
shift: false,
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/crossterm_be/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub fn main_loop<GS: GameState>(mut bterm: BTerm, mut gamestate: GS) -> BResult<
}

gamestate.tick(&mut bterm);
bterm.mouse_changed = true;

if output_buffer.is_none() {
output_buffer = Some(full_redraw()?);
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/curses/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn init_raw<S: ToString>(
frame_time_ms: 0.0,
active_console: 0,
key: None,
mouse_changed: false,
mouse_pos: (0, 0),
left_click: false,
shift: false,
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/curses/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub fn main_loop<GS: GameState>(mut bterm: BTerm, mut gamestate: GS) -> BResult<
}

gamestate.tick(&mut bterm);
bterm.mouse_changed = true;

if output_buffer.is_none() {
output_buffer = Some(full_redraw()?);
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/native/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub fn init_raw<S: ToString>(
frame_time_ms: 0.0,
active_console: 0,
key: None,
mouse_changed: false,
mouse_pos: (0, 0),
left_click: false,
shift: false,
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/native/mainloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ fn tock<GS: GameState>(

// Run the main loop
gamestate.tick(bterm);
bterm.mouse_changed = false;

// Tell each console to draw itself
render_consoles().unwrap();
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/wasm/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn init_raw<S: ToString>(
frame_time_ms: 0.0,
active_console: 0,
key: None,
mouse_changed: false,
mouse_pos: (0, 0),
left_click: false,
shift: false,
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/wasm/mainloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ fn tock<GS: GameState>(
}

gamestate.tick(bterm);
bterm.mouse_changed = false;

// Console structure - doesn't really have to be every frame...
rebuild_consoles();
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/webgpu/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub fn init_raw<S: ToString>(
frame_time_ms: 0.0,
active_console: 0,
key: None,
mouse_changed: false,
mouse_pos: (0, 0),
left_click: false,
shift: false,
Expand Down
1 change: 1 addition & 0 deletions bracket-terminal/src/hal/webgpu/mainloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ fn tock<GS: GameState>(

// Run the main loop
gamestate.tick(bterm);
bterm.mouse_changed = false;

// Tell each console to draw itself
render_consoles().unwrap();
Expand Down