mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 02:28:11 +08:00
Made snapping / overlays not render extra times, made snapping distance larger
This commit is contained in:
@@ -15,7 +15,7 @@ pub const VIEWPORT_SCROLL_RATE: f64 = 0.6;
|
|||||||
|
|
||||||
pub const VIEWPORT_ROTATE_SNAP_INTERVAL: f64 = 15.;
|
pub const VIEWPORT_ROTATE_SNAP_INTERVAL: f64 = 15.;
|
||||||
|
|
||||||
pub const SNAP_TOLERANCE: f64 = 3.;
|
pub const SNAP_TOLERANCE: f64 = 6.;
|
||||||
|
|
||||||
// TRANSFORMING LAYER
|
// TRANSFORMING LAYER
|
||||||
pub const ROTATE_SNAP_ANGLE: f64 = 15.;
|
pub const ROTATE_SNAP_ANGLE: f64 = 15.;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
mod snapping;
|
pub mod snapping;
|
||||||
pub mod tool_message_handler;
|
pub mod tool_message_handler;
|
||||||
pub mod tool_options;
|
pub mod tool_options;
|
||||||
pub mod tools;
|
pub mod tools;
|
||||||
|
|||||||
@@ -58,20 +58,12 @@ impl SnapHandler {
|
|||||||
|
|
||||||
/// Gets a list of snap targets for the X and Y axes in Viewport coords for the target layers (usually all layers or all non-selected layers.)
|
/// Gets a list of snap targets for the X and Y axes in Viewport coords for the target layers (usually all layers or all non-selected layers.)
|
||||||
/// This should be called at the start of a drag.
|
/// This should be called at the start of a drag.
|
||||||
pub fn start_snap(
|
pub fn start_snap(&mut self, responses: &mut VecDeque<Message>, viewport_bounds: DVec2, document_message_handler: &DocumentMessageHandler, target_layers: Vec<Vec<LayerId>>) {
|
||||||
&mut self,
|
|
||||||
responses: &mut VecDeque<Message>,
|
|
||||||
viewport_bounds: DVec2,
|
|
||||||
document_message_handler: &DocumentMessageHandler,
|
|
||||||
target_layers: Vec<Vec<LayerId>>,
|
|
||||||
ignore_layers: &[Vec<LayerId>],
|
|
||||||
) {
|
|
||||||
if document_message_handler.snapping_enabled {
|
if document_message_handler.snapping_enabled {
|
||||||
// Could be made into sorted Vec or a HashSet for more performant lookups.
|
// Could be made into sorted Vec or a HashSet for more performant lookups.
|
||||||
self.snap_targets = Some(
|
self.snap_targets = Some(
|
||||||
target_layers
|
target_layers
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|path| !ignore_layers.contains(path))
|
|
||||||
.filter_map(|path| document_message_handler.graphene_document.viewport_bounding_box(path).ok()?)
|
.filter_map(|path| document_message_handler.graphene_document.viewport_bounding_box(path).ok()?)
|
||||||
.flat_map(|[bound1, bound2]| [bound1, bound2, ((bound1 + bound2) / 2.)])
|
.flat_map(|[bound1, bound2]| [bound1, bound2, ((bound1 + bound2) / 2.)])
|
||||||
.map(|vec| vec.into())
|
.map(|vec| vec.into())
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ impl Fsm for LineToolFsmState {
|
|||||||
if let ToolMessage::Line(event) = event {
|
if let ToolMessage::Line(event) = event {
|
||||||
match (self, event) {
|
match (self, event) {
|
||||||
(Ready, DragStart) => {
|
(Ready, DragStart) => {
|
||||||
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.all_layers_sorted(), &[]);
|
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.all_layers_sorted());
|
||||||
data.drag_start = data.snap_handler.snap_position(document, input.mouse.position);
|
data.drag_start = data.snap_handler.snap_position(document, input.mouse.position);
|
||||||
|
|
||||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ impl Fsm for PenToolFsmState {
|
|||||||
data.path = Some(vec![generate_uuid()]);
|
data.path = Some(vec![generate_uuid()]);
|
||||||
data.layer_exists = false;
|
data.layer_exists = false;
|
||||||
|
|
||||||
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.all_layers_sorted(), &[]);
|
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.all_layers_sorted());
|
||||||
let snapped_position = data.snap_handler.snap_position(document, input.mouse.position);
|
let snapped_position = data.snap_handler.snap_position(document, input.mouse.position);
|
||||||
|
|
||||||
let pos = transform.inverse() * DAffine2::from_translation(snapped_position);
|
let pos = transform.inverse() * DAffine2::from_translation(snapped_position);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ impl Resize {
|
|||||||
/// Starts a resize, assigning the snap targets and snapping the starting position.
|
/// Starts a resize, assigning the snap targets and snapping the starting position.
|
||||||
pub fn start(&mut self, responses: &mut VecDeque<Message>, viewport_bounds: DVec2, document: &DocumentMessageHandler, mouse_position: DVec2) {
|
pub fn start(&mut self, responses: &mut VecDeque<Message>, viewport_bounds: DVec2, document: &DocumentMessageHandler, mouse_position: DVec2) {
|
||||||
let layers = document.all_layers_sorted();
|
let layers = document.all_layers_sorted();
|
||||||
self.snap_handler.start_snap(responses, viewport_bounds, document, layers, &[]);
|
self.snap_handler.start_snap(responses, viewport_bounds, document, layers);
|
||||||
self.drag_start = self.snap_handler.snap_position(document, mouse_position);
|
self.drag_start = self.snap_handler.snap_position(document, mouse_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -174,6 +174,8 @@ impl Fsm for SelectToolFsmState {
|
|||||||
let state = if selected.iter().any(|path| intersection.contains(path)) {
|
let state = if selected.iter().any(|path| intersection.contains(path)) {
|
||||||
buffer.push(DocumentMessage::StartTransaction.into());
|
buffer.push(DocumentMessage::StartTransaction.into());
|
||||||
data.layers_dragging = selected;
|
data.layers_dragging = selected;
|
||||||
|
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.non_selected_layers_sorted());
|
||||||
|
|
||||||
Dragging
|
Dragging
|
||||||
} else {
|
} else {
|
||||||
if !input.keyboard.get(add_to_selection as usize) {
|
if !input.keyboard.get(add_to_selection as usize) {
|
||||||
@@ -186,6 +188,7 @@ impl Fsm for SelectToolFsmState {
|
|||||||
buffer.push(DocumentMessage::AddSelectedLayers(selected.clone()).into());
|
buffer.push(DocumentMessage::AddSelectedLayers(selected.clone()).into());
|
||||||
buffer.push(DocumentMessage::StartTransaction.into());
|
buffer.push(DocumentMessage::StartTransaction.into());
|
||||||
data.layers_dragging.append(&mut selected);
|
data.layers_dragging.append(&mut selected);
|
||||||
|
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.non_selected_layers_sorted());
|
||||||
Dragging
|
Dragging
|
||||||
} else {
|
} else {
|
||||||
data.drag_box_overlay_layer = Some(add_bounding_box(&mut buffer));
|
data.drag_box_overlay_layer = Some(add_bounding_box(&mut buffer));
|
||||||
@@ -193,15 +196,6 @@ impl Fsm for SelectToolFsmState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
buffer.into_iter().rev().for_each(|message| responses.push_front(message));
|
buffer.into_iter().rev().for_each(|message| responses.push_front(message));
|
||||||
|
|
||||||
// TODO: Probably delete this now that the overlay system has moved to a separate Graphene document? (@0hypercube)
|
|
||||||
let ignore_layers = if let Some(bounding_box) = &data.bounding_box_overlay_layer {
|
|
||||||
vec![bounding_box.clone()]
|
|
||||||
} else {
|
|
||||||
Vec::new()
|
|
||||||
};
|
|
||||||
data.snap_handler
|
|
||||||
.start_snap(responses, input.viewport_bounds.size(), document, document.non_selected_layers_sorted(), &ignore_layers);
|
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
(Dragging, MouseMove { snap_angle }) => {
|
(Dragging, MouseMove { snap_angle }) => {
|
||||||
@@ -278,6 +272,7 @@ impl Fsm for SelectToolFsmState {
|
|||||||
let mut delete = |path: &mut Option<Vec<LayerId>>| path.take().map(|path| responses.push_front(DocumentMessage::Overlay(Operation::DeleteLayer { path }.into()).into()));
|
let mut delete = |path: &mut Option<Vec<LayerId>>| path.take().map(|path| responses.push_front(DocumentMessage::Overlay(Operation::DeleteLayer { path }.into()).into()));
|
||||||
delete(&mut data.drag_box_overlay_layer);
|
delete(&mut data.drag_box_overlay_layer);
|
||||||
delete(&mut data.bounding_box_overlay_layer);
|
delete(&mut data.bounding_box_overlay_layer);
|
||||||
|
data.snap_handler.cleanup(responses);
|
||||||
Ready
|
Ready
|
||||||
}
|
}
|
||||||
(_, Align(axis, aggregate)) => {
|
(_, Align(axis, aggregate)) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user