diff options
Diffstat (limited to 'src/tool/icon_tool.rs')
| -rw-r--r-- | src/tool/icon_tool.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/tool/icon_tool.rs b/src/tool/icon_tool.rs index 4b3a1eb..e972c1c 100644 --- a/src/tool/icon_tool.rs +++ b/src/tool/icon_tool.rs @@ -19,9 +19,9 @@ pub const ICON_DIR: &str = "assets/icons"; struct IconFileInfo { /// The position the icon should be anchored in pixels. This is the Vector it will be moved by /// relative to the mouse pointer (to the left and up). - anchor: Vec2<f32>, + anchor: Vec2<f64>, /// The scale of the icon as expressed in image pixels per real meter. - pixels_per_m: f32, + pixels_per_m: f64, } #[derive(Clone, Serialize, Deserialize)] @@ -29,9 +29,9 @@ pub struct IconInfo { /// The id of the icon is the icons position in the currently loaded icon_data vector. pub icon_id: usize, /// The position of the icon on the map, given by the vector in meters. - pub position: Vec2<f32>, + pub position: Vec2<f64>, /// Rotation of the icon texture in degrees. - pub rotation: f32, + pub rotation: f64, } pub struct IconTool { @@ -132,7 +132,7 @@ impl Tool for IconTool { ) { // Update the position of the icon that should be drawn to the current mouse position. let snapped_mouse_pos_m = snap_to_grid( - transform.point_px_to_m(rl.get_mouse_position().into()), + transform.point_px_to_m(&rl.get_mouse_position().into()), SNAP_SIZE, ); self.current_icon.position = snapped_mouse_pos_m; @@ -161,14 +161,14 @@ impl Tool for IconTool { let (texture, info) = &self.icon_data[icon.icon_id]; // Round the position to whole pixels to fix rotation problems. let mut position_px = - transform.point_m_to_px(icon.position - (info.anchor / info.pixels_per_m)); - position_px.x = position_px.x as i32 as f32; - position_px.y = position_px.y as i32 as f32; + transform.point_m_to_px(&(icon.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, - icon.rotation, - transform.pixels_per_m() / info.pixels_per_m, + icon.rotation as f32, + (transform.pixels_per_m() / info.pixels_per_m) as f32, Color { r: 255, g: 255, @@ -183,14 +183,14 @@ impl Tool for IconTool { let (texture, info) = &self.icon_data[self.current_icon.icon_id]; // Round the position to whole pixels to fix rotation problems. let mut position_px = transform - .point_m_to_px(self.current_icon.position - (info.anchor / info.pixels_per_m)); - position_px.x = position_px.x as i32 as f32; - position_px.y = position_px.y as i32 as f32; + .point_m_to_px(&(self.current_icon.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.current_icon.rotation, - transform.pixels_per_m() / info.pixels_per_m, + self.current_icon.rotation as f32, + (transform.pixels_per_m() / info.pixels_per_m) as f32, Color { r: 120, g: 200, |
