Skip to content

Commit 6575148

Browse files
committed
follow up for PR GraphiteEditor#2160
1 parent d692538 commit 6575148

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

editor/src/messages/tool/tool_messages/line_tool.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,21 @@ fn generate_transform(tool_data: &mut LineToolData, snap_data: SnapData, lock_an
293293

294294
let mut angle = -(document_points[1] - document_points[0]).angle_to(DVec2::X);
295295
let mut line_length = (document_points[1] - document_points[0]).length();
296+
296297
if lock_angle {
297298
angle = tool_data.angle;
298-
}
299-
if snap_angle {
299+
} else if snap_angle {
300300
let snap_resolution = LINE_ROTATE_SNAP_ANGLE.to_radians();
301301
angle = (angle / snap_resolution).round() * snap_resolution;
302302
}
303303

304+
tool_data.angle = angle;
305+
304306
if lock_angle {
305307
let angle_vec = DVec2::new(angle.cos(), angle.sin());
306308
line_length = (document_points[1] - document_points[0]).dot(angle_vec);
307309
}
310+
308311
document_points[1] = document_points[0] + line_length * DVec2::new(angle.cos(), angle.sin());
309312

310313
let constrained = snap_angle || lock_angle;

editor/src/messages/tool/tool_messages/path_tool.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ struct PathToolData {
298298
saved_points_before_anchor_select_toggle: Vec<ManipulatorPointId>,
299299
select_anchor_toggled: bool,
300300
dragging_state: DraggingState,
301+
current_selected_handle_id: Option<ManipulatorPointId>,
301302
angle: f64,
302303
}
303304

@@ -472,7 +473,7 @@ impl PathToolData {
472473
}
473474

474475
/// Attempts to get a single selected handle. Also retrieves the position of the anchor it is connected to. Used for the purpose of snapping the angle.
475-
fn try_get_selected_handle_and_anchor(&self, shape_editor: &ShapeState, document: &DocumentMessageHandler) -> Option<(DVec2, DVec2)> {
476+
fn try_get_selected_handle_and_anchor(&self, shape_editor: &ShapeState, document: &DocumentMessageHandler) -> Option<(DVec2, DVec2, ManipulatorPointId)> {
476477
// Only count selections of a single layer
477478
let (layer, selection) = shape_editor.selected_shape_state.iter().next()?;
478479

@@ -483,6 +484,7 @@ impl PathToolData {
483484

484485
// Only count selected handles
485486
let selected_handle = selection.selected().next()?.as_handle()?;
487+
let handle_id = selected_handle.to_manipulator_point();
486488

487489
let layer_to_document = document.metadata().transform_to_document(*layer);
488490
let vector_data = document.network_interface.compute_modified_vector(*layer)?;
@@ -494,24 +496,26 @@ impl PathToolData {
494496
let handle_position_document = layer_to_document.transform_point2(handle_position_local);
495497
let anchor_position_document = layer_to_document.transform_point2(anchor_position_local);
496498

497-
Some((handle_position_document, anchor_position_document))
499+
Some((handle_position_document, anchor_position_document, handle_id))
498500
}
499501

500-
fn calculate_handle_angle(&mut self, handle_vector: DVec2, lock_angle: bool, snap_angle: bool) -> f64 {
501-
let mut handle_angle = -handle_vector.angle_to(DVec2::X);
502+
fn calculate_handle_angle(&mut self, handle_vector: DVec2, handle_id: ManipulatorPointId, lock_angle: bool, snap_angle: bool) -> f64 {
503+
let current_angle = -handle_vector.angle_to(DVec2::X);
502504

503505
// When the angle is locked we use the old angle
504-
if lock_angle {
505-
handle_angle = self.angle
506+
if self.current_selected_handle_id == Some(handle_id) && lock_angle {
507+
return self.angle;
506508
}
507509

508510
// Round the angle to the closest increment
509-
if snap_angle {
511+
let mut handle_angle = current_angle;
512+
if snap_angle && !lock_angle {
510513
let snap_resolution = HANDLE_ROTATE_SNAP_ANGLE.to_radians();
511514
handle_angle = (handle_angle / snap_resolution).round() * snap_resolution;
512515
}
513516

514-
// Cache the old handle angle for the lock angle.
517+
// Cache the angle and handle id for lock angle
518+
self.current_selected_handle_id = Some(handle_id);
515519
self.angle = handle_angle;
516520

517521
handle_angle
@@ -561,10 +565,10 @@ impl PathToolData {
561565
let current_mouse = input.mouse.position;
562566
let raw_delta = document_to_viewport.inverse().transform_vector2(current_mouse - previous_mouse);
563567

564-
let snapped_delta = if let Some((handle_pos, anchor_pos)) = self.try_get_selected_handle_and_anchor(shape_editor, document) {
568+
let snapped_delta = if let Some((handle_pos, anchor_pos, handle_id)) = self.try_get_selected_handle_and_anchor(shape_editor, document) {
565569
let cursor_pos = handle_pos + raw_delta;
566570

567-
let handle_angle = self.calculate_handle_angle(cursor_pos - anchor_pos, lock_angle, snap_angle);
571+
let handle_angle = self.calculate_handle_angle(cursor_pos - anchor_pos, handle_id, lock_angle, snap_angle);
568572

569573
let constrained_direction = DVec2::new(handle_angle.cos(), handle_angle.sin());
570574
let projected_length = (cursor_pos - anchor_pos).dot(constrained_direction);

0 commit comments

Comments
 (0)