@@ -8,6 +8,7 @@ use crate::messages::frontend::utility_types::MouseCursorIcon;
8
8
use crate :: messages:: portfolio:: document:: overlays:: utility_types:: OverlayContext ;
9
9
use crate :: messages:: portfolio:: document:: utility_types:: transformation:: OriginalTransforms ;
10
10
use crate :: messages:: prelude:: * ;
11
+ use crate :: messages:: tool:: common_functionality:: compass_rose:: Axis ;
11
12
use crate :: messages:: tool:: common_functionality:: snapping:: SnapTypeConfiguration ;
12
13
use glam:: { DAffine2 , DMat2 , DVec2 } ;
13
14
use graphene_core:: renderer:: Quad ;
@@ -286,25 +287,30 @@ impl SelectedEdges {
286
287
}
287
288
288
289
/// Aligns the mouse position to the closest axis
289
- pub fn axis_align_drag ( axis_align : bool , position : DVec2 , start : DVec2 ) -> DVec2 {
290
+ pub fn axis_align_drag ( axis_align : bool , axis : Axis , position : DVec2 , start : DVec2 ) -> DVec2 {
290
291
if axis_align {
291
292
let mouse_position = position - start;
292
293
let snap_resolution = SELECTION_DRAG_ANGLE . to_radians ( ) ;
293
294
let angle = -mouse_position. angle_to ( DVec2 :: X ) ;
294
295
let snapped_angle = ( angle / snap_resolution) . round ( ) * snap_resolution;
296
+ let axis_vector = DVec2 :: from_angle ( snapped_angle) ;
295
297
if snapped_angle. is_finite ( ) {
296
- start + DVec2 :: new ( snapped_angle . cos ( ) , snapped_angle . sin ( ) ) * mouse_position. length ( )
298
+ start + axis_vector * mouse_position. dot ( axis_vector ) . abs ( )
297
299
} else {
298
300
start
299
301
}
302
+ } else if axis. is_constraint ( ) {
303
+ let mouse_position = position - start;
304
+ let axis_vector: DVec2 = axis. into ( ) ;
305
+ start + axis_vector * mouse_position. dot ( axis_vector)
300
306
} else {
301
307
position
302
308
}
303
309
}
304
310
305
311
/// Snaps a dragging event from the artboard or select tool
306
- pub fn snap_drag ( start : DVec2 , current : DVec2 , axis_align : bool , snap_data : SnapData , snap_manager : & mut SnapManager , candidates : & [ SnapCandidatePoint ] ) -> DVec2 {
307
- let mouse_position = axis_align_drag ( axis_align , snap_data. input . mouse . position , start) ;
312
+ pub fn snap_drag ( start : DVec2 , current : DVec2 , snap_to_axis : bool , axis : Axis , snap_data : SnapData , snap_manager : & mut SnapManager , candidates : & [ SnapCandidatePoint ] ) -> DVec2 {
313
+ let mouse_position = axis_align_drag ( snap_to_axis , axis , snap_data. input . mouse . position , start) ;
308
314
let document = snap_data. document ;
309
315
let total_mouse_delta_document = document. metadata ( ) . document_to_viewport . inverse ( ) . transform_vector2 ( mouse_position - start) ;
310
316
let mouse_delta_document = document. metadata ( ) . document_to_viewport . inverse ( ) . transform_vector2 ( mouse_position - current) ;
@@ -324,7 +330,8 @@ pub fn snap_drag(start: DVec2, current: DVec2, axis_align: bool, snap_data: Snap
324
330
let mut point = point. clone ( ) ;
325
331
point. document_point += total_mouse_delta_document;
326
332
327
- let snapped = if axis_align {
333
+ let constrained_along_axis = snap_to_axis || axis. is_constraint ( ) ;
334
+ let snapped = if constrained_along_axis {
328
335
let constraint = SnapConstraint :: Line {
329
336
origin : point. document_point ,
330
337
direction : total_mouse_delta_document. try_normalize ( ) . unwrap_or ( DVec2 :: X ) ,
0 commit comments