Skip to content

Commit e89cded

Browse files
otdaviesKeavon
andauthored
Add selection cycle and gray pre-selection outlines to the Path tool, and Tab to swap Select/Path tools (#2818)
* Added initial version of this feature for the path tool * Removed debug statements * Thickened the overlay width * Added hover highlighting for path tool * Experimental switch to path tool at leaf layer * Ghost outline initial implementation * Added tab swap for select tool -> path tool * Minor fix for Select Tool dbl click -> Path Tool * Added support for ghosts when using GRS in the path tool * Fixed GRS undo bug, vastly improved hover behavior and now clearly visualize next double click target * Fixed unused import warnings * Updated behavior to handle mouse movement cases, reverted line width to 1px * Fixed merge behavioral issues * Disabled Select Tool to Path Tool double click toggle, fixed single click drill through for special case * Clean up of unused consts and comment * Properly cancel the drill through state when the mouse moves * Fix some stuff --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent d6d1bbb commit e89cded

File tree

9 files changed

+198
-28
lines changed

9 files changed

+198
-28
lines changed

editor/src/consts.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub const MIN_LENGTH_FOR_SKEW_TRIANGLE_VISIBILITY: f64 = 48.;
101101
// PATH TOOL
102102
pub const MANIPULATOR_GROUP_MARKER_SIZE: f64 = 6.;
103103
pub const SELECTION_THRESHOLD: f64 = 10.;
104+
pub const DRILL_THROUGH_THRESHOLD: f64 = 10.;
104105
pub const HIDE_HANDLE_DISTANCE: f64 = 3.;
105106
pub const HANDLE_ROTATE_SNAP_ANGLE: f64 = 15.;
106107
pub const SEGMENT_INSERTION_DISTANCE: f64 = 5.;
@@ -134,13 +135,15 @@ pub const SCALE_EFFECT: f64 = 0.5;
134135

135136
// COLORS
136137
pub const COLOR_OVERLAY_BLUE: &str = "#00a8ff";
138+
pub const COLOR_OVERLAY_BLUE_50: &str = "#00a8ff80";
137139
pub const COLOR_OVERLAY_YELLOW: &str = "#ffc848";
138140
pub const COLOR_OVERLAY_YELLOW_DULL: &str = "#d7ba8b";
139141
pub const COLOR_OVERLAY_GREEN: &str = "#63ce63";
140142
pub const COLOR_OVERLAY_RED: &str = "#ef5454";
141143
pub const COLOR_OVERLAY_GRAY: &str = "#cccccc";
144+
pub const COLOR_OVERLAY_GRAY_25: &str = "#cccccc40";
142145
pub const COLOR_OVERLAY_WHITE: &str = "#ffffff";
143-
pub const COLOR_OVERLAY_LABEL_BACKGROUND: &str = "#000000cc";
146+
pub const COLOR_OVERLAY_BLACK_75: &str = "#000000bf";
144147

145148
// DOCUMENT
146149
pub const DEFAULT_DOCUMENT_NAME: &str = "Untitled Document";

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ pub fn input_mappings() -> Mapping {
317317
entry!(KeyDown(KeyX); modifiers=[Shift], action_dispatch=ToolMessage::SwapColors),
318318
entry!(KeyDown(KeyC); modifiers=[Alt], action_dispatch=ToolMessage::SelectRandomWorkingColor { primary: true }),
319319
entry!(KeyDown(KeyC); modifiers=[Alt, Shift], action_dispatch=ToolMessage::SelectRandomWorkingColor { primary: false }),
320+
entry!(KeyDownNoRepeat(Tab); action_dispatch=ToolMessage::ToggleSelectVsPath),
320321
//
321322
// DocumentMessage
322323
entry!(KeyDown(Space); modifiers=[Control], action_dispatch=DocumentMessage::GraphViewOverlayToggle),

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,11 @@ impl DocumentMessageHandler {
16831683
})
16841684
}
16851685

1686+
pub fn click_list_no_parents<'a>(&'a self, ipp: &InputPreprocessorMessageHandler) -> impl Iterator<Item = LayerNodeIdentifier> + use<'a> {
1687+
self.click_xray(ipp)
1688+
.filter(move |&layer| !self.network_interface.is_artboard(&layer.to_node(), &[]) && !layer.has_children(self.network_interface.document_metadata()))
1689+
}
1690+
16861691
/// Find the deepest layer that has been clicked on from a location in viewport space.
16871692
pub fn click(&self, ipp: &InputPreprocessorMessageHandler) -> Option<LayerNodeIdentifier> {
16881693
self.click_list(ipp).last()

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::utility_functions::overlay_canvas_context;
22
use crate::consts::{
3-
COLOR_OVERLAY_BLUE, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, COLOR_OVERLAY_WHITE, COLOR_OVERLAY_YELLOW, COLOR_OVERLAY_YELLOW_DULL, 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,
3+
COLOR_OVERLAY_BLUE, COLOR_OVERLAY_BLUE_50, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, COLOR_OVERLAY_WHITE, COLOR_OVERLAY_YELLOW, COLOR_OVERLAY_YELLOW_DULL, 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,
56
};
67
use crate::messages::prelude::Message;
78
use bezier_rs::{Bezier, Subpath};
@@ -349,6 +350,7 @@ impl OverlayContext {
349350
self.render_context.rect(corner.x, corner.y, size, size);
350351
self.render_context.set_fill_style_str(color_fill);
351352
self.render_context.set_stroke_style_str(color_stroke);
353+
self.render_context.set_line_width(1.);
352354
self.render_context.fill();
353355
self.render_context.stroke();
354356

@@ -631,11 +633,9 @@ impl OverlayContext {
631633
pub fn outline_overlay_bezier(&mut self, bezier: Bezier, transform: DAffine2) {
632634
self.start_dpi_aware_transform();
633635

634-
let color = Color::from_rgb_str(COLOR_OVERLAY_BLUE.strip_prefix('#').unwrap()).unwrap().with_alpha(0.05).to_rgba_hex_srgb();
635-
636636
self.render_context.begin_path();
637637
self.bezier_command(bezier, transform, true);
638-
self.render_context.set_stroke_style_str(&color);
638+
self.render_context.set_stroke_style_str(COLOR_OVERLAY_BLUE_50);
639639
self.render_context.set_line_width(4.);
640640
self.render_context.stroke();
641641

@@ -727,6 +727,7 @@ impl OverlayContext {
727727

728728
let color = color.unwrap_or(COLOR_OVERLAY_BLUE);
729729
self.render_context.set_stroke_style_str(color);
730+
self.render_context.set_line_width(1.);
730731
self.render_context.stroke();
731732
}
732733
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod grid_snapper;
44
mod layer_snapper;
55
mod snap_results;
66

7-
use crate::consts::{COLOR_OVERLAY_BLUE, COLOR_OVERLAY_LABEL_BACKGROUND, COLOR_OVERLAY_WHITE};
7+
use crate::consts::{COLOR_OVERLAY_BLACK_75, COLOR_OVERLAY_BLUE, COLOR_OVERLAY_WHITE};
88
use crate::messages::portfolio::document::overlays::utility_types::{OverlayContext, Pivot};
99
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
1010
use crate::messages::portfolio::document::utility_types::misc::{GridSnapTarget, PathSnapTarget, SnapTarget};
@@ -482,7 +482,7 @@ impl SnapManager {
482482
if !any_align && ind.distribution_equal_distance_horizontal.is_none() && ind.distribution_equal_distance_vertical.is_none() {
483483
let text = format!("[{}] from [{}]", ind.target, ind.source);
484484
let transform = DAffine2::from_translation(viewport - DVec2::new(0., 4.));
485-
overlay_context.text(&text, COLOR_OVERLAY_WHITE, Some(COLOR_OVERLAY_LABEL_BACKGROUND), transform, 4., [Pivot::Start, Pivot::End]);
485+
overlay_context.text(&text, COLOR_OVERLAY_WHITE, Some(COLOR_OVERLAY_BLACK_75), transform, 4., [Pivot::Start, Pivot::End]);
486486
overlay_context.square(viewport, Some(4.), Some(COLOR_OVERLAY_BLUE), Some(COLOR_OVERLAY_BLUE));
487487
}
488488
}

editor/src/messages/tool/tool_message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub enum ToolMessage {
8787
SelectRandomWorkingColor {
8888
primary: bool,
8989
},
90+
ToggleSelectVsPath,
9091
SwapColors,
9192
Undo,
9293
UpdateCursor,

editor/src/messages/tool/tool_message_handler.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ impl MessageHandler<ToolMessage, ToolMessageContext<'_>> for ToolMessageHandler
284284

285285
document_data.update_working_colors(responses); // TODO: Make this an event
286286
}
287+
ToolMessage::ToggleSelectVsPath => {
288+
// If we have the select tool active, toggle to the path tool and vice versa
289+
let tool_data = &mut self.tool_state.tool_data;
290+
let active_tool_type = tool_data.active_tool_type;
291+
if active_tool_type == ToolType::Select {
292+
responses.add(ToolMessage::ActivateTool { tool_type: ToolType::Path });
293+
} else {
294+
responses.add(ToolMessage::ActivateTool { tool_type: ToolType::Select });
295+
}
296+
}
287297
ToolMessage::SwapColors => {
288298
let document_data = &mut self.tool_state.document_tool_data;
289299

@@ -359,9 +369,12 @@ impl MessageHandler<ToolMessage, ToolMessageContext<'_>> for ToolMessageHandler
359369

360370
ActivateToolBrush,
361371

372+
ToggleSelectVsPath,
373+
362374
SelectRandomWorkingColor,
363375
ResetColors,
364376
SwapColors,
377+
365378
Undo,
366379
);
367380
list.extend(self.tool_state.tool_data.active_tool().actions());

0 commit comments

Comments
 (0)