From 3637346c1ab5826e069664772be95e46715ae529 Mon Sep 17 00:00:00 2001 From: Funnisimo Date: Tue, 23 Aug 2022 10:01:13 -0500 Subject: [PATCH 1/3] export colors mods separately to aid precise imports --- bracket-color/Cargo.toml | 6 +++--- bracket-color/examples/util/mod.rs | 2 +- bracket-color/src/lib.rs | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bracket-color/Cargo.toml b/bracket-color/Cargo.toml index 3c5122c0..564d5439 100755 --- a/bracket-color/Cargo.toml +++ b/bracket-color/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bracket-color" -version = "0.8.2" +version = "0.8.3" authors = ["Herbert Wolverson "] edition = "2018" publish = true @@ -17,13 +17,13 @@ palette = [ "lazy_static", "parking_lot" ] [dependencies] serde = { version = "~1.0.110", features = ["derive"], optional = true } -crossterm = { version = "~0.24", optional = true } +crossterm = { version = "~0.25", optional = true } lazy_static = { version = "1.4.0", optional = true } parking_lot = { version = "~0.12", optional = true } bevy = { version = "0.8", optional = true } [dev-dependencies] -crossterm = "~0.24" +crossterm = "~0.25" [[example]] name = "colors" diff --git a/bracket-color/examples/util/mod.rs b/bracket-color/examples/util/mod.rs index cafaf439..b620f9ed 100755 --- a/bracket-color/examples/util/mod.rs +++ b/bracket-color/examples/util/mod.rs @@ -2,7 +2,7 @@ use bracket_color::prelude::*; use crossterm::queue; use crossterm::style::{Print, SetForegroundColor}; use std::convert::TryInto; -use std::io::{stdout, Write}; +use std::io::stdout; pub fn print_color(color: RGB, text: &str) { queue!(stdout(), SetForegroundColor(color.try_into().unwrap())).expect("Command Fail"); diff --git a/bracket-color/src/lib.rs b/bracket-color/src/lib.rs index ab9a0908..84721e17 100755 --- a/bracket-color/src/lib.rs +++ b/bracket-color/src/lib.rs @@ -31,20 +31,20 @@ extern crate lazy_static; /// Import color pair support -mod color_pair; +pub mod color_pair; /// Import HSV color support -mod hsv; +pub mod hsv; /// Import Lerp as an iterator -mod lerpit; +pub mod lerpit; /// Import library of named colors -mod named; +pub mod named; /// Import Palette support #[cfg(feature = "palette")] -mod palette; +pub mod palette; /// Import RGB color support -mod rgb; +pub mod rgb; /// Import RGBA color support -mod rgba; +pub mod rgba; /// Exports the color functions/types in the `prelude` namespace. pub mod prelude { From f74a2a81be46803889adebfe7c6a3edad9c8ced9 Mon Sep 17 00:00:00 2001 From: Funnisimo Date: Tue, 23 Aug 2022 10:02:40 -0500 Subject: [PATCH 2/3] use updated bracket-color --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 992aa165..c1bc8267 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ webgpu = [ "bracket-terminal/webgpu" ] [dependencies] bracket-algorithm-traits = { path = "./bracket-algorithm-traits", version = "~0.8.2" } -bracket-color = { path = "./bracket-color", version = "~0.8.2", features = [ "palette" ] } +bracket-color = { path = "./bracket-color", version = "~0.8.3", features = [ "palette" ] } bracket-geometry = { path = "./bracket-geometry", version = "~0.8.2" } bracket-noise = { path = "./bracket-noise", version = "~0.8.2" } bracket-pathfinding = { path = "./bracket-pathfinding", version = "~0.8.2" } From a43a3f2b905c1e3279d1a9edc0254b30426dd72d Mon Sep 17 00:00:00 2001 From: Funnisimo Date: Wed, 12 Oct 2022 10:47:58 -0500 Subject: [PATCH 3/3] updated offset for mouse --- bracket-terminal/src/bterm.rs | 27 +++++++++++++------ bracket-terminal/src/consoles/console.rs | 4 +++ .../src/consoles/flexible_console.rs | 9 +++++-- .../src/consoles/simple_console.rs | 6 +++++ .../src/consoles/sparse_console.rs | 6 +++++ .../src/consoles/sprite_console.rs | 4 +++ .../src/consoles/virtual_console.rs | 4 +++ 7 files changed, 50 insertions(+), 10 deletions(-) diff --git a/bracket-terminal/src/bterm.rs b/bracket-terminal/src/bterm.rs index e7af4efb..046ba01f 100755 --- a/bracket-terminal/src/bterm.rs +++ b/bracket-terminal/src/bterm.rs @@ -245,9 +245,10 @@ impl BTerm { self.width_pixels as f32 / max_sizes.0 as f32, self.height_pixels as f32 / max_sizes.1 as f32, ); + let global_offset = console.get_offset(); let mut offsets = ( - center_x as f32 * font_size.0 * (scale - 1.0), - center_y as f32 * font_size.1 * (scale - 1.0), + (center_x as f32 + global_offset.0) * font_size.0 * (scale - 1.0), + (center_y as f32 + global_offset.1) * font_size.1 * (scale - 1.0), ); let w: f32; @@ -261,12 +262,19 @@ impl BTerm { offsets.1 -= be.screen_scaler.gutter_top as f32; } - let extent_x = (pos.0 as f32 + offsets.0) / w; - let extent_y = (pos.1 as f32 + offsets.1) / h; + let mut global_offset = console.get_offset(); + global_offset.0 *= font_size.0 * scale; + global_offset.1 *= font_size.1 * scale; + + let extent_x = (pos.0 as f32 + offsets.0 - global_offset.0) / w; + let extent_y = (pos.1 as f32 + offsets.1 + global_offset.1) / h; let mouse_x = f32::min(extent_x * max_sizes.0 as f32, max_sizes.0 as f32 - 1.0); let mouse_y = f32::min(extent_y * max_sizes.1 as f32, max_sizes.1 as f32 - 1.0); - (i32::max(0, mouse_x as i32), i32::max(0, mouse_y as i32)) + ( + i32::max(-1, mouse_x.floor() as i32), + i32::max(-1, mouse_y.floor() as i32), + ) } /// Applies the current physical mouse position to the active console, and translates the coordinates into that console's coordinate space. @@ -354,13 +362,16 @@ impl BTerm { /// Internal: mark a mouse press pub(crate) fn on_mouse_button(&mut self, button_num: usize, pressed: bool) { - if button_num == 0 { - self.left_click = true; - } let mut input = INPUT.lock(); if pressed { + if button_num == 0 { + self.left_click = true; + } input.on_mouse_button_down(button_num); } else { + if button_num == 0 { + self.left_click = false; + } input.on_mouse_button_up(button_num); } input.push_event(BEvent::MouseClick { diff --git a/bracket-terminal/src/consoles/console.rs b/bracket-terminal/src/consoles/console.rs index dea81be3..9dcb4cd0 100755 --- a/bracket-terminal/src/consoles/console.rs +++ b/bracket-terminal/src/consoles/console.rs @@ -135,6 +135,10 @@ pub trait Console { /// drawing walls between tiles. fn set_offset(&mut self, x: f32, y: f32); + /// Return the current global offset (by character count, so 0.5 is half a character). Useful for + /// calculating mouse position. + fn get_offset(&self) -> (f32, f32); + /// Specify a scale and center of the console. /// A scale above 1.0 will make the text larger. /// The center of the scale is at character position (center_x, center_y). diff --git a/bracket-terminal/src/consoles/flexible_console.rs b/bracket-terminal/src/consoles/flexible_console.rs index 76ed3433..b1766570 100755 --- a/bracket-terminal/src/consoles/flexible_console.rs +++ b/bracket-terminal/src/consoles/flexible_console.rs @@ -5,9 +5,8 @@ use crate::prelude::{ use bracket_color::prelude::RGBA; use bracket_geometry::prelude::{PointF, Rect}; use bracket_rex::prelude::XpColor; -use ultraviolet::Vec2; - use std::any::Any; +use ultraviolet::Vec2; /// Internal storage structure for sparse tiles. pub struct FlexiTile { @@ -396,6 +395,12 @@ impl Console for FlexiConsole { self.offset_y = y * (2.0 / self.height as f32); } + fn get_offset(&self) -> (f32, f32) { + let x = self.offset_x / (2.0 / self.width as f32); + let y = self.offset_y / (2.0 / self.height as f32); + (x, y) + } + fn set_scale(&mut self, scale: f32, center_x: i32, center_y: i32) { self.is_dirty = true; self.scale = scale; diff --git a/bracket-terminal/src/consoles/simple_console.rs b/bracket-terminal/src/consoles/simple_console.rs index 66f7b053..f15a5cb7 100755 --- a/bracket-terminal/src/consoles/simple_console.rs +++ b/bracket-terminal/src/consoles/simple_console.rs @@ -327,6 +327,12 @@ impl Console for SimpleConsole { self.offset_y = y * (2.0 / self.height as f32); } + fn get_offset(&self) -> (f32, f32) { + let x = self.offset_x / (2.0 / self.width as f32); + let y = self.offset_y / (2.0 / self.height as f32); + (x, y) + } + fn set_scale(&mut self, scale: f32, center_x: i32, center_y: i32) { self.is_dirty = true; self.scale = scale; diff --git a/bracket-terminal/src/consoles/sparse_console.rs b/bracket-terminal/src/consoles/sparse_console.rs index e6afe949..3387f62a 100755 --- a/bracket-terminal/src/consoles/sparse_console.rs +++ b/bracket-terminal/src/consoles/sparse_console.rs @@ -359,6 +359,12 @@ impl Console for SparseConsole { self.offset_y = y * (2.0 / self.height as f32); } + fn get_offset(&self) -> (f32, f32) { + let x = self.offset_x / (2.0 / self.width as f32); + let y = self.offset_y / (2.0 / self.height as f32); + (x, y) + } + fn set_scale(&mut self, scale: f32, center_x: i32, center_y: i32) { self.is_dirty = true; self.scale = scale; diff --git a/bracket-terminal/src/consoles/sprite_console.rs b/bracket-terminal/src/consoles/sprite_console.rs index c36264ab..935449f0 100755 --- a/bracket-terminal/src/consoles/sprite_console.rs +++ b/bracket-terminal/src/consoles/sprite_console.rs @@ -224,6 +224,10 @@ impl Console for SpriteConsole { /// character size; so -0.5 will offset half a character to the left/top. fn set_offset(&mut self, _x: f32, _y: f32) {} + fn get_offset(&self) -> (f32, f32) { + (0.0, 0.0) + } + fn set_scale(&mut self, _scale: f32, _center_x: i32, _center_y: i32) {} fn get_scale(&self) -> (f32, i32, i32) { diff --git a/bracket-terminal/src/consoles/virtual_console.rs b/bracket-terminal/src/consoles/virtual_console.rs index 048dcac1..80ecdc24 100755 --- a/bracket-terminal/src/consoles/virtual_console.rs +++ b/bracket-terminal/src/consoles/virtual_console.rs @@ -378,6 +378,10 @@ impl Console for VirtualConsole { panic!("Unsupported on virtual consoles."); } + fn get_offset(&self) -> (f32, f32) { + (0.0, 0.0) + } + fn set_scale(&mut self, _scale: f32, _center_x: i32, _center_y: i32) { panic!("Unsupported on virtual consoles."); }