aboutsummaryrefslogtreecommitdiff
path: root/src/gui/position_indicator.rs
blob: b6d0dac4821c9d83596e0366281e1781b50eca35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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,
    );
}