From f92e9f6f07b1e3834c2ca58ce3510734819d08e4 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Wed, 27 Jan 2021 14:01:50 +0100 Subject: Rework graf karto to fit the client/server structure --- src/client/gui/position_indicator.rs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/client/gui/position_indicator.rs (limited to 'src/client/gui/position_indicator.rs') diff --git a/src/client/gui/position_indicator.rs b/src/client/gui/position_indicator.rs new file mode 100644 index 0000000..4d68b86 --- /dev/null +++ b/src/client/gui/position_indicator.rs @@ -0,0 +1,37 @@ +//! 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::client::colours::DEFAULT_COLOURS; +use crate::client::snapping::Snapper; +use crate::client::transform::Transform; +use crate::math::Vec2; +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, + transform: &Transform, + snapper: &Snapper, +) { + let mouse_pos_snapped_m = snapper.snap(transform.point_px_to_m(&mouse_pos_px)); + let mouse_pos_snapped_px = transform.point_m_to_px(&mouse_pos_snapped_m); + + rld.draw_circle_v(mouse_pos_snapped_px, 2., DEFAULT_COLOURS.position_indicator); + rld.draw_text( + &format!( + "({:.3}m, {:.3}m)", + mouse_pos_snapped_m.x, mouse_pos_snapped_m.y + ), + mouse_pos_snapped_px.x as i32 - 30, + mouse_pos_snapped_px.y as i32 - 30, + 20, + DEFAULT_COLOURS.position_text, + ); +} -- cgit v1.2.3-70-g09d2