From b42ddaa4bf86b782bdbc619f7d66ded41c909465 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Tue, 29 Dec 2020 11:12:11 +0100 Subject: Add snapping module to replace the rigid grid snapping --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 8c1d63e..38f3912 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ pub mod grid; pub mod gui; pub mod map; pub mod math; +pub mod snapping; pub mod svg; pub mod tool; pub mod transform; @@ -38,6 +39,7 @@ use config::Config; use editor::Editor; use gui::{DimensionIndicator, ToolSidebar}; use raylib::prelude::*; +use snapping::Snapper; use std::ffi::CString; use std::io; use transform::Transform; @@ -86,6 +88,7 @@ fn main() { let mut editor = Editor::new(&mut rl, &thread, config); let mut dimension_indicator = DimensionIndicator::new(); let tool_sidebar = ToolSidebar::new(&mut rl, &thread); + let mut snapper = Snapper::default(); let mut transform = Transform::new(); let mut last_mouse_pos = rl.get_mouse_position(); @@ -111,10 +114,12 @@ fn main() { } dimension_indicator.update(editor.map_mut(), &mut rl); + snapper.update(&mut rl); editor.update( &mut rl, &transform, + &snapper, ToolSidebar::mouse_captured(screen_height as u16, last_mouse_pos.into()), ); @@ -127,6 +132,7 @@ fn main() { editor.draw_tools(&mut d, &transform); tool_sidebar.draw(screen_height as u16, &mut d, &mut editor); + snapper.draw(&mut d); dimension_indicator.draw(&mut d, &transform); } -- cgit v1.2.3-70-g09d2 From 1c81d7c70fe891e6ded49d49d6a09f04ce74dd6e Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Tue, 5 Jan 2021 12:44:02 +0100 Subject: Position indicator is now dependent on current snapping --- src/gui/position_indicator.rs | 16 +++++++++++----- src/main.rs | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main.rs') diff --git a/src/gui/position_indicator.rs b/src/gui/position_indicator.rs index b6d0dac..737a427 100644 --- a/src/gui/position_indicator.rs +++ b/src/gui/position_indicator.rs @@ -8,6 +8,7 @@ use crate::colours::DEFAULT_COLOURS; use crate::math::Vec2; +use crate::snapping::Snapper; use crate::transform::Transform; use raylib::drawing::{RaylibDraw, RaylibDrawHandle}; @@ -17,14 +18,19 @@ pub fn position_indicator_draw( rld: &mut RaylibDrawHandle, mouse_pos_px: Vec2, transform: &Transform, + snapper: &Snapper, ) { - let mouse_pos_m = transform.point_px_to_m(&mouse_pos_px); + 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_px, 2., DEFAULT_COLOURS.position_indicator); + rld.draw_circle_v(mouse_pos_snapped_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, + &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, ); diff --git a/src/main.rs b/src/main.rs index c9ebe48..345477b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -134,9 +134,8 @@ fn main() { tool_sidebar.draw(screen_height as u16, &mut d, &mut editor); snapper.draw(&mut d); - gui::position_indicator_draw(&mut d, last_mouse_pos.into(), &transform); + gui::position_indicator_draw(&mut d, last_mouse_pos.into(), &transform, &snapper); dimension_indicator.draw(&mut d, &transform); - tool_sidebar.draw(screen_height as u16, &mut d, &mut editor); } } } -- cgit v1.2.3-70-g09d2