Skip to content

Commit ba31408

Browse files
committed
fix: pivot pinning and origin angle
1 parent a0115ff commit ba31408

5 files changed

Lines changed: 70 additions & 32 deletions

File tree

editor/src/messages/portfolio/document/overlays/utility_types.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::utility_functions::overlay_canvas_context;
22
use crate::consts::{
3-
COLOR_OVERLAY_BLUE, COLOR_OVERLAY_BLUE_50, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_ORANGE, COLOR_OVERLAY_RED, COLOR_OVERLAY_WHITE, COLOR_OVERLAY_YELLOW, COMPASS_ROSE_ARROW_SIZE,
4-
COMPASS_ROSE_HOVER_RING_DIAMETER, COMPASS_ROSE_MAIN_RING_DIAMETER, COMPASS_ROSE_RING_INNER_DIAMETER, DOWEL_PIN_RADIUS, MANIPULATOR_GROUP_MARKER_SIZE, PIVOT_CROSSHAIR_LENGTH,
5-
PIVOT_CROSSHAIR_THICKNESS, PIVOT_DIAMETER,
3+
COLOR_OVERLAY_BLUE, COLOR_OVERLAY_BLUE_50, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, COLOR_OVERLAY_WHITE, COLOR_OVERLAY_YELLOW, COMPASS_ROSE_ARROW_SIZE, COMPASS_ROSE_HOVER_RING_DIAMETER,
4+
COMPASS_ROSE_MAIN_RING_DIAMETER, COMPASS_ROSE_RING_INNER_DIAMETER, DOWEL_PIN_RADIUS, MANIPULATOR_GROUP_MARKER_SIZE, PIVOT_CROSSHAIR_LENGTH, PIVOT_CROSSHAIR_THICKNESS, PIVOT_DIAMETER,
65
};
76
use crate::messages::prelude::Message;
87
use bezier_rs::{Bezier, Subpath};
@@ -559,9 +558,9 @@ impl OverlayContext {
559558
self.end_dpi_aware_transform();
560559
}
561560

562-
pub fn dowel_pin(&mut self, position: DVec2, color: Option<&str>) {
561+
pub fn dowel_pin(&mut self, position: DVec2, angle: f64, color: Option<&str>) {
563562
let (x, y) = (position.round() - DVec2::splat(0.5)).into();
564-
let color = color.unwrap_or(COLOR_OVERLAY_ORANGE);
563+
let color = color.unwrap_or(COLOR_OVERLAY_YELLOW);
565564

566565
self.start_dpi_aware_transform();
567566

@@ -577,11 +576,11 @@ impl OverlayContext {
577576
self.render_context.begin_path();
578577
// Top-left sector
579578
self.render_context.move_to(x, y);
580-
self.render_context.arc(x, y, DOWEL_PIN_RADIUS, FRAC_PI_2, PI).expect("Failed to draw arc");
579+
self.render_context.arc(x, y, DOWEL_PIN_RADIUS, FRAC_PI_2 + angle, PI + angle).expect("Failed to draw arc");
581580
self.render_context.close_path();
582581
// Bottom-right sector
583582
self.render_context.move_to(x, y);
584-
self.render_context.arc(x, y, DOWEL_PIN_RADIUS, PI + FRAC_PI_2, TAU).expect("Failed to draw arc");
583+
self.render_context.arc(x, y, DOWEL_PIN_RADIUS, PI + FRAC_PI_2 + angle, TAU + angle).expect("Failed to draw arc");
585584
self.render_context.close_path();
586585
self.render_context.set_fill_style_str(color);
587586
self.render_context.fill();

editor/src/messages/tool/common_functionality/pivot.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ pub struct Pivot {
171171
active: bool,
172172
/// Used to enable and disable the pivot
173173
pub pinned: bool,
174+
/// Had selected_visible_and_unlocked_layers
175+
pub empty: bool,
174176
}
175177

176178
impl Default for Pivot {
@@ -183,6 +185,7 @@ impl Default for Pivot {
183185
last_non_none_reference: ReferencePoint::Center,
184186
active: true,
185187
pinned: false,
188+
empty: true,
186189
}
187190
}
188191
}
@@ -195,9 +198,9 @@ impl Pivot {
195198
}
196199

197200
let selected = document.network_interface.selected_nodes();
201+
202+
self.empty = !selected.has_selected_nodes();
198203
if !selected.has_selected_nodes() {
199-
self.normalized_pivot = DVec2::splat(0.5);
200-
self.pivot = None;
201204
return;
202205
};
203206

@@ -221,7 +224,9 @@ impl Pivot {
221224

222225
let [min, max] = bounds.unwrap_or([DVec2::ZERO, DVec2::ONE]);
223226
self.transform_from_normalized = transform * DAffine2::from_translation(min) * DAffine2::from_scale(max - min);
224-
self.pivot = Some(self.transform_from_normalized.transform_point2(self.normalized_pivot));
227+
if self.old_pivot_position != ReferencePoint::None {
228+
self.pivot = Some(self.transform_from_normalized.transform_point2(self.normalized_pivot));
229+
}
225230
}
226231

227232
pub fn recalculate_pivot_for_layer(&mut self, document: &DocumentMessageHandler, bounds: Option<[DVec2; 2]>) {

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,15 @@ impl LayoutHolder for PathTool {
263263
.selected_index(Some(self.options.path_overlay_mode as u32))
264264
.widget_holder();
265265

266-
let [checkbox, dropdown] = {
266+
let [_checkbox, _dropdown] = {
267267
let dot_widget = dot_type_widget(self.tool_data.dot.state, Source::Path);
268-
[dot_widget.get(0).unwrap().clone(), dot_widget.get(2).unwrap().clone()]
268+
[dot_widget[0].clone(), dot_widget[2].clone()]
269269
};
270270

271271
let has_somrthing = !self.tool_data.saved_points_before_anchor_convert_smooth_sharp.is_empty();
272-
let pivot_reference = pivot_reference_point_widget(has_somrthing || !self.tool_data.dot.state.is_pivot(), self.tool_data.dot.pivot.to_pivot_position(), Source::Path);
272+
let _pivot_reference = pivot_reference_point_widget(has_somrthing || !self.tool_data.dot.state.is_pivot(), self.tool_data.dot.pivot.to_pivot_position(), Source::Path);
273273

274-
let pin_pivot = pin_pivot_widget(self.tool_data.dot.pin_inactive(), Source::Path);
274+
let _pin_pivot = pin_pivot_widget(self.tool_data.dot.pin_inactive(), Source::Path);
275275

276276
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row {
277277
widgets: vec![
@@ -289,13 +289,13 @@ impl LayoutHolder for PathTool {
289289
unrelated_seperator.clone(),
290290
path_overlay_mode_widget,
291291
unrelated_seperator.clone(),
292-
checkbox.clone(),
293-
related_seperator.clone(),
294-
dropdown.clone(),
295-
unrelated_seperator,
296-
pivot_reference,
297-
related_seperator.clone(),
298-
pin_pivot,
292+
// checkbox.clone(),
293+
// related_seperator.clone(),
294+
// dropdown.clone(),
295+
// unrelated_seperator,
296+
// pivot_reference,
297+
// related_seperator.clone(),
298+
// pin_pivot,
299299
],
300300
}]))
301301
}
@@ -566,7 +566,6 @@ impl PathToolData {
566566

567567
fn update_selection_status(&mut self, shape_editor: &mut ShapeState, document: &DocumentMessageHandler) {
568568
let selection_status = get_selection_status(&document.network_interface, shape_editor);
569-
// debug!("{:?}", selection_status);
570569

571570
self.can_toggle_colinearity = match &selection_status {
572571
SelectionStatus::None => false,
@@ -610,8 +609,6 @@ impl PathToolData {
610609

611610
let old_selection = shape_editor.selected_points().cloned().collect::<Vec<_>>();
612611

613-
debug!("{old_selection:?}");
614-
615612
// Check if the point is already selected; if not, select the first point within the threshold (in pixels)
616613
// Don't select the points which are not shown currently in PathOverlayMode
617614
if let Some((already_selected, mut selection_info)) = shape_editor.get_point_selection_state(
@@ -1396,6 +1393,10 @@ impl Fsm for PathToolFsmState {
13961393
update_dynamic_hints(self, responses, shape_editor, document, tool_data, tool_options);
13971394

13981395
let ToolMessage::Path(event) = event else { return self };
1396+
1397+
// TODO(mTvare6): Remove it once dots are implemented for path_tool
1398+
tool_data.dot.state.enabled = false;
1399+
13991400
match (self, event) {
14001401
(_, PathToolMessage::SelectionChanged) => {
14011402
// Set the newly targeted layers to visible

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl SelectToolData {
538538

539539
fn state_from_dot(&self, mouse: DVec2) -> Option<SelectToolFsmState> {
540540
match self.dot.state.dot {
541-
DotType::Pivot if !self.dot.pivot.pinned => self.dot.pivot.is_over(mouse).then_some(SelectToolFsmState::DraggingPivot),
541+
DotType::Pivot => self.dot.pivot.is_over(mouse).then_some(SelectToolFsmState::DraggingPivot),
542542
_ => None,
543543
}
544544
}
@@ -766,21 +766,52 @@ impl Fsm for SelectToolFsmState {
766766
});
767767

768768
let mut active_origin = None;
769+
let mut origin_angle = 0.;
769770
if overlay_context.visibility_settings.origin() && !tool_data.dot.state.is_pivot_type() {
771+
let get_angle = |layer: LayerNodeIdentifier| -> f64 {
772+
let quad = Quad::from_box([DVec2::ZERO, DVec2::ONE]);
773+
let bounds = document.metadata().transform_to_viewport_with_first_transform_node_if_group(layer, &document.network_interface) * quad;
774+
(bounds.top_left() - bounds.top_right()).to_angle()
775+
};
776+
if tool_data.dot.state.dot == DotType::Average {
777+
let mut count = 0;
778+
779+
let sum: f64 = document
780+
.network_interface
781+
.selected_nodes()
782+
.selected_visible_and_unlocked_layers(&document.network_interface)
783+
.map(get_angle)
784+
.inspect(|_| count += 1)
785+
.sum();
786+
if count > 0 {
787+
origin_angle = sum / count as f64;
788+
}
789+
} else if tool_data.dot.state.dot == DotType::Active {
790+
origin_angle = document
791+
.network_interface
792+
.selected_nodes()
793+
.selected_visible_and_unlocked_layers(&document.network_interface)
794+
.find(|&layer| Some(layer) == tool_data.dot.layer)
795+
.iter()
796+
.map(|&layer| get_angle(layer))
797+
.sum();
798+
}
799+
770800
for layer in document.network_interface.selected_nodes().selected_visible_and_unlocked_layers(&document.network_interface) {
771801
let origin = graph_modification_utils::get_viewport_origin(layer, &document.network_interface);
772802
if Some(layer) == tool_data.dot.layer {
773803
active_origin = Some(origin);
774804
continue;
775805
}
776-
overlay_context.dowel_pin(origin, None);
806+
overlay_context.dowel_pin(origin, origin_angle, None);
777807
}
778808
}
779809
if let Some(origin) = active_origin {
780-
overlay_context.dowel_pin(origin, Some(COLOR_OVERLAY_YELLOW));
810+
overlay_context.dowel_pin(origin, origin_angle, Some(COLOR_OVERLAY_ORANGE));
781811
}
782812

783-
let draw_pivot = tool_data.dot.state.is_pivot() && overlay_context.visibility_settings.pivot();
813+
let has_layers = document.network_interface.selected_nodes().has_selected_nodes();
814+
let draw_pivot = tool_data.dot.state.is_pivot() && overlay_context.visibility_settings.pivot() && has_layers;
784815
tool_data.dot.pivot.update(document, &mut overlay_context, Some((angle,)), draw_pivot);
785816

786817
// Update compass rose
@@ -1009,8 +1040,10 @@ impl Fsm for SelectToolFsmState {
10091040
let extend = input.keyboard.key(extend_selection);
10101041
if !extend && !input.keyboard.key(remove_from_selection) {
10111042
responses.add(DocumentMessage::DeselectAllLayers);
1012-
let position = tool_data.dot.pivot.last_non_none_reference;
1013-
responses.add(SelectToolMessage::SetPivot { position });
1043+
if !tool_data.dot.pivot.pinned {
1044+
let position = tool_data.dot.pivot.last_non_none_reference;
1045+
responses.add(SelectToolMessage::SetPivot { position });
1046+
}
10141047
tool_data.layers_dragging.clear();
10151048
}
10161049

editor/src/messages/tool/transform_layer/transform_layer_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ impl MessageHandler<TransformLayerMessage, TransformData<'_>> for TransformLayer
388388
}
389389
}
390390

391-
if let Some(bounds) = self.path_bounds {
392-
overlay_context.quad(Quad::from_box(bounds), None, None);
391+
if let Some(_) = self.path_bounds {
392+
// overlay_context.quad(Quad::from_box(bounds), None, None);
393393
}
394394
}
395395

0 commit comments

Comments
 (0)