diff options
| author | Max Pernklau | 2020-12-29 10:50:31 +0100 |
|---|---|---|
| committer | GitHub | 2020-12-29 10:50:31 +0100 |
| commit | 9b5762cf3716503819e2cf06f3c335bbfd3b0a3c (patch) | |
| tree | b5d5bd02e5de6bcdb34d0052d7675b2644ac377f | |
| parent | 2d2f45df9d47db25ac5a91c8f926a025c3a5dc7a (diff) | |
| parent | f2430645e7b78dcc0b06a59d20b7c0ff36a5f3c2 (diff) | |
| download | graf_karto-9b5762cf3716503819e2cf06f3c335bbfd3b0a3c.tar.gz graf_karto-9b5762cf3716503819e2cf06f3c335bbfd3b0a3c.zip | |
Merge pull request #26 from LordSentox/position-indicator
Add indicator to show where the mouse is pointing
| -rw-r--r-- | src/colours.rs | 16 | ||||
| -rw-r--r-- | src/gui/mod.rs | 2 | ||||
| -rw-r--r-- | src/gui/position_indicator.rs | 31 | ||||
| -rw-r--r-- | src/main.rs | 4 |
4 files changed, 51 insertions, 2 deletions
diff --git a/src/colours.rs b/src/colours.rs index 4a3b799..d381266 100644 --- a/src/colours.rs +++ b/src/colours.rs @@ -32,6 +32,10 @@ pub struct Colours { pub dimension_indicators: Color, /// Colour of the text used to display the size of the dimension indicators dimensions. pub dimension_text: Color, + /// Colour the point to show where something is will be drawn in. + pub position_indicator: Color, + /// Colour that is used for the text stating the position of the position indicator in meters. + pub position_text: Color, /// The colour used for drawing the lines of the grid which divides the map into chunks of evenly /// spaced cells. pub grid_lines: Color, @@ -115,6 +119,18 @@ impl Colours { b: 200, a: 255, }, + position_indicator: Color { + r: 200, + g: 200, + b: 200, + a: 255, + }, + position_text: Color { + r: 200, + g: 200, + b: 200, + a: 255, + }, grid_lines: Color { r: 255, g: 255, diff --git a/src/gui/mod.rs b/src/gui/mod.rs index a94122e..f8630d7 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -8,7 +8,9 @@ //! called from any point in the program except the main loop, where the user input is polled. pub mod dimension_indicator; +pub mod position_indicator; pub mod tool_sidebar; pub use self::dimension_indicator::*; +pub use self::position_indicator::*; pub use self::tool_sidebar::*; diff --git a/src/gui/position_indicator.rs b/src/gui/position_indicator.rs new file mode 100644 index 0000000..b6d0dac --- /dev/null +++ b/src/gui/position_indicator.rs @@ -0,0 +1,31 @@ +//! The position indicator shows the mouse position on the map +//! +//! The exact position the mouse is currently on is shown unless hidden by the user (TODO). This +//! helps to place things exactly where they should be on the map and let the user know where they +//! are looking and where relative to them other things should be easily at all times. Currently, this +//! is a simple HUD so it doesn't interact with anything in the world, but that may change in the +//! future. + +use crate::colours::DEFAULT_COLOURS; +use crate::math::Vec2; +use crate::transform::Transform; +use raylib::drawing::{RaylibDraw, RaylibDrawHandle}; + +/// Function to draw a dot at the mouse position and the coordinates associated with it. +// TODO: Snap this, when the user wants to snap, don't if they don't want to. +pub fn position_indicator_draw( + rld: &mut RaylibDrawHandle, + mouse_pos_px: Vec2<f64>, + transform: &Transform, +) { + let mouse_pos_m = transform.point_px_to_m(&mouse_pos_px); + + rld.draw_circle_v(mouse_pos_px, 2., DEFAULT_COLOURS.position_indicator); + rld.draw_text( + &format!("({:.3}m, {:.3}m)", mouse_pos_m.x, mouse_pos_m.y), + mouse_pos_px.x as i32 - 30, + mouse_pos_px.y as i32 - 30, + 20, + DEFAULT_COLOURS.position_text, + ); +} diff --git a/src/main.rs b/src/main.rs index 8c1d63e..1cfc31b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,9 +126,9 @@ fn main() { editor.map().draw(&mut d, &transform); editor.draw_tools(&mut d, &transform); - tool_sidebar.draw(screen_height as u16, &mut d, &mut editor); - + gui::position_indicator_draw(&mut d, last_mouse_pos.into(), &transform); dimension_indicator.draw(&mut d, &transform); + tool_sidebar.draw(screen_height as u16, &mut d, &mut editor); } } } |
