mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +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 SNAP_TOLERANCE: f64 = 3.;
|
||||
pub const SNAP_TOLERANCE: f64 = 6.;
|
||||
|
||||
// TRANSFORMING LAYER
|
||||
pub const ROTATE_SNAP_ANGLE: f64 = 15.;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
mod snapping;
|
||||
pub mod snapping;
|
||||
pub mod tool_message_handler;
|
||||
pub mod tool_options;
|
||||
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.)
|
||||
/// This should be called at the start of a drag.
|
||||
pub fn start_snap(
|
||||
&mut self,
|
||||
responses: &mut VecDeque<Message>,
|
||||
viewport_bounds: DVec2,
|
||||
document_message_handler: &DocumentMessageHandler,
|
||||
target_layers: Vec<Vec<LayerId>>,
|
||||
ignore_layers: &[Vec<LayerId>],
|
||||
) {
|
||||
pub fn start_snap(&mut self, responses: &mut VecDeque<Message>, viewport_bounds: DVec2, document_message_handler: &DocumentMessageHandler, target_layers: Vec<Vec<LayerId>>) {
|
||||
if document_message_handler.snapping_enabled {
|
||||
// Could be made into sorted Vec or a HashSet for more performant lookups.
|
||||
self.snap_targets = Some(
|
||||
target_layers
|
||||
.iter()
|
||||
.filter(|path| !ignore_layers.contains(path))
|
||||
.filter_map(|path| document_message_handler.graphene_document.viewport_bounding_box(path).ok()?)
|
||||
.flat_map(|[bound1, bound2]| [bound1, bound2, ((bound1 + bound2) / 2.)])
|
||||
.map(|vec| vec.into())
|
||||
|
||||
@@ -86,7 +86,7 @@ impl Fsm for LineToolFsmState {
|
||||
if let ToolMessage::Line(event) = event {
|
||||
match (self, event) {
|
||||
(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);
|
||||
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
@@ -94,7 +94,7 @@ impl Fsm for PenToolFsmState {
|
||||
data.path = Some(vec![generate_uuid()]);
|
||||
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 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.
|
||||
pub fn start(&mut self, responses: &mut VecDeque<Message>, viewport_bounds: DVec2, document: &DocumentMessageHandler, mouse_position: DVec2) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -174,6 +174,8 @@ impl Fsm for SelectToolFsmState {
|
||||
let state = if selected.iter().any(|path| intersection.contains(path)) {
|
||||
buffer.push(DocumentMessage::StartTransaction.into());
|
||||
data.layers_dragging = selected;
|
||||
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.non_selected_layers_sorted());
|
||||
|
||||
Dragging
|
||||
} else {
|
||||
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::StartTransaction.into());
|
||||
data.layers_dragging.append(&mut selected);
|
||||
data.snap_handler.start_snap(responses, input.viewport_bounds.size(), document, document.non_selected_layers_sorted());
|
||||
Dragging
|
||||
} else {
|
||||
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));
|
||||
|
||||
// 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
|
||||
}
|
||||
(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()));
|
||||
delete(&mut data.drag_box_overlay_layer);
|
||||
delete(&mut data.bounding_box_overlay_layer);
|
||||
data.snap_handler.cleanup(responses);
|
||||
Ready
|
||||
}
|
||||
(_, Align(axis, aggregate)) => {
|
||||
|
||||
Reference in New Issue
Block a user