Skip to content

Commit b4679b0

Browse files
authored
Improve Gradient tool dragging behavior and make hints reactive to current interaction state (#3828)
* Improve Gradient tool dragging behavior and make hints reactive to current interaction state * Reduce code duplication for drawing stops * Fix coordinate system issue when PTZ'ing document during drag or autopan
1 parent 4a6cdff commit b4679b0

File tree

6 files changed

+515
-142
lines changed

6 files changed

+515
-142
lines changed

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub fn input_mappings(zoom_with_scroll: bool) -> Mapping {
177177
// GradientToolMessage
178178
entry!(DoubleClick(MouseButton::Left); action_dispatch=GradientToolMessage::DoubleClick),
179179
entry!(KeyDown(MouseLeft); action_dispatch=GradientToolMessage::PointerDown),
180-
entry!(PointerMove; refresh_keys=[Shift], action_dispatch=GradientToolMessage::PointerMove { constrain_axis: Shift }),
180+
entry!(PointerMove; refresh_keys=[Shift, Control], action_dispatch=GradientToolMessage::PointerMove { constrain_axis: Shift, lock_angle: Control }),
181181
entry!(KeyUp(MouseLeft); action_dispatch=GradientToolMessage::PointerUp),
182182
entry!(KeyDown(Delete); action_dispatch=GradientToolMessage::DeleteStop),
183183
entry!(KeyDown(Backspace); action_dispatch=GradientToolMessage::DeleteStop),

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2787,7 +2787,10 @@ impl NodeGraphMessageHandler {
27872787
if self.has_selection {
27882788
hint_data.0.extend([
27892789
HintGroup(vec![HintInfo::mouse(MouseMotion::LmbDrag, "Drag Selected")]),
2790-
HintGroup(vec![HintInfo::keys([Key::Delete], "Delete Selected"), HintInfo::keys([Key::Control], "Keep Children").prepend_plus()]),
2790+
HintGroup(vec![
2791+
HintInfo::keys([Key::Backspace], "Delete Selected"),
2792+
HintInfo::keys([Key::Control], "Keep Children").prepend_plus(),
2793+
]),
27912794
HintGroup(vec![
27922795
HintInfo::keys_and_mouse([Key::Alt], MouseMotion::LmbDrag, "Move Duplicate"),
27932796
HintInfo::keys([Key::Control, Key::KeyD], "Duplicate").add_mac_keys([Key::Command, Key::KeyD]),

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ pub fn empty_provider() -> OverlayProvider {
3333
|_| Message::NoOp
3434
}
3535

36+
// TODO Remove duplicated definition of this in `utility_types_web.rs`
37+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
38+
pub enum GizmoEmphasis {
39+
Regular,
40+
Hovered,
41+
Active,
42+
}
43+
3644
// TODO Remove duplicated definition of this in `utility_types_web.rs`
3745
/// Types of overlays used by DocumentMessage to enable/disable the selected set of viewport overlays.
3846
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
@@ -273,12 +281,12 @@ impl OverlayContext {
273281
self.internal().manipulator_anchor(position, selected, color);
274282
}
275283

276-
pub fn gradient_color_stop(&mut self, position: DVec2, selected: bool, color: &str, small: bool) {
277-
self.internal().gradient_color_stop(position, selected, color, small);
284+
pub fn gradient_color_stop(&mut self, position: DVec2, emphasis: GizmoEmphasis, color: &str, small: bool) {
285+
self.internal().gradient_color_stop(position, emphasis, color, small);
278286
}
279287

280-
pub fn gradient_midpoint(&mut self, position: DVec2, selected: bool, angle: f64) {
281-
self.internal().gradient_midpoint(position, selected, angle);
288+
pub fn gradient_midpoint(&mut self, position: DVec2, emphasis: GizmoEmphasis, angle: f64) {
289+
self.internal().gradient_midpoint(position, emphasis, angle);
282290
}
283291

284292
pub fn resize_handle(&mut self, position: DVec2, rotation: f64) {
@@ -591,11 +599,16 @@ impl OverlayContextInternal {
591599
self.square(position, None, Some(color_fill), Some(COLOR_OVERLAY_BLUE));
592600
}
593601

594-
fn gradient_color_stop(&mut self, position: DVec2, selected: bool, color: &str, small: bool) {
602+
fn gradient_color_stop(&mut self, position: DVec2, emphasis: GizmoEmphasis, color: &str, small: bool) {
595603
let transform = self.get_transform();
596604
let position = position.round() - DVec2::splat(0.5);
597605

598-
let (radius_offset, stroke_width) = if selected { (1., 3.) } else { (0., 1.) };
606+
let radius_offset = match emphasis {
607+
GizmoEmphasis::Regular => 0.,
608+
GizmoEmphasis::Hovered => 0.5,
609+
GizmoEmphasis::Active => 1.,
610+
};
611+
let stroke_width = radius_offset * 2. + 1.;
599612
let radius = (MANIPULATOR_GROUP_MARKER_SIZE / 1.5 + 1. + radius_offset) * if small { 0.5 } else { 1. };
600613

601614
let mut draw_circle = |radius: f64, width: Option<f64>, color: &str| {
@@ -614,7 +627,7 @@ impl OverlayContextInternal {
614627
draw_circle(radius, Some(stroke_width), COLOR_OVERLAY_WHITE);
615628
}
616629

617-
fn gradient_midpoint(&mut self, position: DVec2, selected: bool, angle: f64) {
630+
fn gradient_midpoint(&mut self, position: DVec2, emphasis: GizmoEmphasis, angle: f64) {
618631
let transform = self.get_transform();
619632
let position = position.round() - DVec2::splat(0.5);
620633

@@ -634,9 +647,13 @@ impl OverlayContextInternal {
634647
path.line_to(kurbo::Point::new(position.x + left.x, position.y + left.y));
635648
path.close_path();
636649

637-
let fill = if selected { COLOR_OVERLAY_BLUE } else { COLOR_OVERLAY_WHITE };
650+
let (fill, stroke_width) = match emphasis {
651+
GizmoEmphasis::Regular => (COLOR_OVERLAY_WHITE, 1.),
652+
GizmoEmphasis::Hovered => (COLOR_OVERLAY_WHITE, 2.),
653+
GizmoEmphasis::Active => (COLOR_OVERLAY_BLUE, 1.),
654+
};
638655
self.scene.fill(peniko::Fill::NonZero, transform, Self::parse_color(fill), None, &path);
639-
self.scene.stroke(&kurbo::Stroke::new(1.), transform, Self::parse_color(COLOR_OVERLAY_BLUE), None, &path);
656+
self.scene.stroke(&kurbo::Stroke::new(stroke_width), transform, Self::parse_color(COLOR_OVERLAY_BLUE), None, &path);
640657
}
641658

642659
fn resize_handle(&mut self, position: DVec2, rotation: f64) {

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ pub fn empty_provider() -> OverlayProvider {
2828
|_| Message::NoOp
2929
}
3030

31+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
32+
pub enum GizmoEmphasis {
33+
Regular,
34+
Hovered,
35+
Active,
36+
}
37+
3138
/// Types of overlays used by DocumentMessage to enable/disable the selected set of viewport overlays.
3239
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
3340
pub enum OverlaysType {
@@ -469,12 +476,17 @@ impl OverlayContext {
469476
self.square(position, None, Some(color_fill), Some(color_stroke));
470477
}
471478

472-
pub fn gradient_color_stop(&mut self, position: DVec2, selected: bool, color: &str, small: bool) {
479+
pub fn gradient_color_stop(&mut self, position: DVec2, emphasis: GizmoEmphasis, color: &str, small: bool) {
473480
self.start_dpi_aware_transform();
474481

475482
let position = position.round() - DVec2::splat(0.5);
476483

477-
let (radius_offset, stroke_width) = if selected { (1., 3.) } else { (0., 1.) };
484+
let radius_offset = match emphasis {
485+
GizmoEmphasis::Regular => 0.,
486+
GizmoEmphasis::Hovered => 0.5,
487+
GizmoEmphasis::Active => 1.,
488+
};
489+
let stroke_width = radius_offset * 2. + 1.;
478490
let radius = (MANIPULATOR_GROUP_MARKER_SIZE / 1.5 + 1. + radius_offset) * if small { 0.5 } else { 1. };
479491

480492
let draw_circle = |radius: f64, width: Option<f64>, color: &str| {
@@ -501,7 +513,7 @@ impl OverlayContext {
501513
self.end_dpi_aware_transform();
502514
}
503515

504-
pub fn gradient_midpoint(&mut self, position: DVec2, selected: bool, angle: f64) {
516+
pub fn gradient_midpoint(&mut self, position: DVec2, emphasis: GizmoEmphasis, angle: f64) {
505517
self.start_dpi_aware_transform();
506518

507519
let position = position.round() - DVec2::splat(0.5);
@@ -522,11 +534,17 @@ impl OverlayContext {
522534
self.render_context.line_to(position.x + left.x, position.y + left.y);
523535
self.render_context.close_path();
524536

525-
let fill = if selected { COLOR_OVERLAY_BLUE } else { COLOR_OVERLAY_WHITE };
537+
let (fill, stroke_width) = match emphasis {
538+
GizmoEmphasis::Regular => (COLOR_OVERLAY_WHITE, 1.),
539+
GizmoEmphasis::Hovered => (COLOR_OVERLAY_WHITE, 2.),
540+
GizmoEmphasis::Active => (COLOR_OVERLAY_BLUE, 1.),
541+
};
526542
self.render_context.set_fill_style_str(fill);
527543
self.render_context.set_stroke_style_str(COLOR_OVERLAY_BLUE);
528544
self.render_context.fill();
545+
self.render_context.set_line_width(stroke_width);
529546
self.render_context.stroke();
547+
self.render_context.set_line_width(1.);
530548

531549
self.end_dpi_aware_transform();
532550
}

0 commit comments

Comments
 (0)