aboutsummaryrefslogtreecommitdiff
path: root/src/map/icon.rs
diff options
context:
space:
mode:
authorArne Dußin2021-01-27 14:01:50 +0100
committerArne Dußin2021-02-02 22:16:15 +0100
commitf92e9f6f07b1e3834c2ca58ce3510734819d08e4 (patch)
tree20e3d3afce342a56ae98f6c20491482ccd2b5c6b /src/map/icon.rs
parentc60a6d07efb120724b308e29e8e70f27c87c952d (diff)
downloadgraf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.tar.gz
graf_karto-f92e9f6f07b1e3834c2ca58ce3510734819d08e4.zip
Rework graf karto to fit the client/server structure
Diffstat (limited to 'src/map/icon.rs')
-rw-r--r--src/map/icon.rs102
1 files changed, 0 insertions, 102 deletions
diff --git a/src/map/icon.rs b/src/map/icon.rs
deleted file mode 100644
index 2e45486..0000000
--- a/src/map/icon.rs
+++ /dev/null
@@ -1,102 +0,0 @@
-//! Icons are map elements that have a specific size and cannot be stretched. They are usually used
-//! as markers for specific places in the world.
-
-use super::icon_renderer::IconRenderer;
-use crate::colours::DEFAULT_COLOURS;
-use crate::map::Mappable;
-use crate::math::{Rect, Vec2};
-use crate::transform::Transform;
-use raylib::core::drawing::{RaylibDraw, RaylibDrawHandle};
-use serde::{Deserialize, Serialize};
-use std::ops::{Deref, DerefMut};
-use std::rc::Rc;
-
-/// The icon data necessary to create an Icon again.
-#[derive(Clone, Serialize, Deserialize)]
-pub struct IconData {
- /// The id of the icon is the icons position in the currently loaded icon_data vector.
- pub id: usize,
- /// The position of the icon on the map, given by the vector in meters.
- pub position: Vec2<f64>,
- /// Rotation of the icon texture in degrees.
- pub rotation: f64,
-}
-
-/// Describes an icon in the world and can be drawn.
-#[derive(Clone)]
-pub struct Icon {
- data: IconData,
- selected: bool,
- renderer: Rc<IconRenderer>,
-}
-
-impl Icon {
- /// Create a new icon. Requires the icon renderer that is used to render this icon, as well as all
- /// the information necessary to describe the icon itself.
- pub fn new(id: usize, position: Vec2<f64>, rotation: f64, renderer: Rc<IconRenderer>) -> Self {
- Self::from_data(
- IconData {
- id,
- position,
- rotation,
- },
- renderer,
- )
- }
-
- /// Like `new()`, but with the icon data bundled into the icon data type.
- pub fn from_data(data: IconData, renderer: Rc<IconRenderer>) -> Self {
- Self {
- data,
- selected: false,
- renderer,
- }
- }
-}
-
-impl Mappable for Icon {
- fn draw(&self, rld: &mut RaylibDrawHandle, transform: &Transform) {
- let (texture, info) = self.renderer.get(self.id);
- // Round the position to whole pixels to fix rotation problems.
- let mut position_px =
- transform.point_m_to_px(&(self.position - (info.anchor / info.pixels_per_m)));
- position_px.x = position_px.x.floor();
- position_px.y = position_px.y.floor();
- rld.draw_texture_ex(
- texture,
- position_px,
- self.rotation as f32,
- (transform.pixels_per_m() / info.pixels_per_m) as f32,
- if self.selected() {
- DEFAULT_COLOURS.icon_selected
- } else {
- DEFAULT_COLOURS.icon_normal
- },
- );
- }
-
- fn set_selected(&mut self, selected: bool) {
- self.selected = selected;
- }
-
- fn selected(&self) -> bool {
- self.selected
- }
-
- fn bounding_rect(&self) -> Rect<f64> {
- Rect::new(self.data.position.x, self.data.position.y, 0., 0.)
- }
-}
-
-impl Deref for Icon {
- type Target = IconData;
-
- fn deref(&self) -> &Self::Target {
- &self.data
- }
-}
-impl DerefMut for Icon {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.data
- }
-}