From 6f589d4b6edf401416d6425d6a93b41f15ee31a4 Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:03:29 +0100 Subject: [PATCH 1/2] feat: duplicate offset taking into account snap If snap is activated, the offset is one exactly the size of one grid element, and if not, uses the previous value. --- crates/rnote-engine/src/engine/mod.rs | 5 ++++- crates/rnote-engine/src/pens/selector/penevents.rs | 5 ++++- crates/rnote-engine/src/store/selection_comp.rs | 12 +++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/rnote-engine/src/engine/mod.rs b/crates/rnote-engine/src/engine/mod.rs index 2e7ad19093..42763fdd25 100644 --- a/crates/rnote-engine/src/engine/mod.rs +++ b/crates/rnote-engine/src/engine/mod.rs @@ -850,7 +850,10 @@ impl Engine { } pub fn duplicate_selection(&mut self) -> WidgetFlags { - let new_selected = self.store.duplicate_selection(); + let new_selected = self.store.duplicate_selection( + self.document.background.pattern_size, + self.document.snap_positions, + ); self.store.update_geometry_for_strokes(&new_selected); self.current_pen_update_state() | self.doc_resize_autoexpand() diff --git a/crates/rnote-engine/src/pens/selector/penevents.rs b/crates/rnote-engine/src/pens/selector/penevents.rs index fe0597a84e..a993e561d0 100644 --- a/crates/rnote-engine/src/pens/selector/penevents.rs +++ b/crates/rnote-engine/src/pens/selector/penevents.rs @@ -628,7 +628,10 @@ impl Selector { KeyboardKey::Unicode('d') => { //Duplicate selection if modifier_keys.contains(&ModifierKey::KeyboardCtrl) { - let duplicated = engine_view.store.duplicate_selection(); + let duplicated = engine_view.store.duplicate_selection( + engine_view.document.background.pattern_size, + engine_view.document.snap_positions, + ); engine_view.store.update_geometry_for_strokes(&duplicated); engine_view.store.regenerate_rendering_for_strokes_threaded( engine_view.tasks_tx.clone(), diff --git a/crates/rnote-engine/src/store/selection_comp.rs b/crates/rnote-engine/src/store/selection_comp.rs index f390dbe57f..f674d8ef68 100644 --- a/crates/rnote-engine/src/store/selection_comp.rs +++ b/crates/rnote-engine/src/store/selection_comp.rs @@ -95,7 +95,7 @@ impl StrokeStore { /// Duplicate the selected keys. /// /// The returned, duplicated strokes then need to update their geometry and rendering. - pub(crate) fn duplicate_selection(&mut self) -> Vec { + pub(crate) fn duplicate_selection(&mut self, pattern_size:na::Vector2, snap_mode:bool) -> Vec { let old_selected = self.selection_keys_as_rendered(); self.set_selected_keys(&old_selected, false); @@ -126,8 +126,14 @@ impl StrokeStore { .collect::>(); // Offsetting the new selected stroke to make the duplication apparent - self.translate_strokes(&new_selected, Stroke::IMPORT_OFFSET_DEFAULT); - self.translate_strokes_images(&new_selected, Stroke::IMPORT_OFFSET_DEFAULT); + // check if snap position is activated or not here + let offset = if snap_mode { + pattern_size + } else { + Stroke::IMPORT_OFFSET_DEFAULT + }; + self.translate_strokes(&new_selected, offset); + self.translate_strokes_images(&new_selected, offset); new_selected } From 4935cee43e2a01aaf8563b52e07823932fd71488 Mon Sep 17 00:00:00 2001 From: Doublonmousse <115779707+Doublonmousse@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:19:06 +0100 Subject: [PATCH 2/2] fmt --- crates/rnote-engine/src/store/selection_comp.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/rnote-engine/src/store/selection_comp.rs b/crates/rnote-engine/src/store/selection_comp.rs index f674d8ef68..f177101325 100644 --- a/crates/rnote-engine/src/store/selection_comp.rs +++ b/crates/rnote-engine/src/store/selection_comp.rs @@ -95,7 +95,11 @@ impl StrokeStore { /// Duplicate the selected keys. /// /// The returned, duplicated strokes then need to update their geometry and rendering. - pub(crate) fn duplicate_selection(&mut self, pattern_size:na::Vector2, snap_mode:bool) -> Vec { + pub(crate) fn duplicate_selection( + &mut self, + pattern_size: na::Vector2, + snap_mode: bool, + ) -> Vec { let old_selected = self.selection_keys_as_rendered(); self.set_selected_keys(&old_selected, false);