Skip to content

Commit 29e8e8b

Browse files
authored
Fix Shift-drag axis color inconsistency and pivot not being draggable with a zero-width bounding box (#2593)
* Fix axis colors not being consistent and pivot not being draggable with zero width boxes Fixes #2311 * Even for path
1 parent 41fe465 commit 29e8e8b

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ impl DocumentMetadata {
146146

147147
let bounds_size = bounds_max - bounds_min;
148148
let bounds_midpoint = bounds_min.midpoint(bounds_max);
149+
const BOX_NUDGE: f64 = 5e-9;
149150
if bounds_size.x < 1e-10 {
150-
bounds_max.x = bounds_midpoint.x + 0.5;
151-
bounds_min.x = bounds_midpoint.x - 0.5;
151+
bounds_max.x = bounds_midpoint.x + BOX_NUDGE;
152+
bounds_min.x = bounds_midpoint.x - BOX_NUDGE;
152153
}
153154
if bounds_size.y < 1e-10 {
154-
bounds_max.y = bounds_midpoint.y + 0.5;
155-
bounds_min.y = bounds_midpoint.y - 0.5;
155+
bounds_max.y = bounds_midpoint.y + BOX_NUDGE;
156+
bounds_min.y = bounds_midpoint.y - BOX_NUDGE;
156157
}
157158

158159
[bounds_min, bounds_max]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Default for Pivot {
3535
impl Pivot {
3636
/// Calculates the transform that gets from normalized pivot to viewspace.
3737
fn get_layer_pivot_transform(layer: LayerNodeIdentifier, document: &DocumentMessageHandler) -> DAffine2 {
38-
let [min, max] = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY).unwrap_or_default();
38+
let [min, max] = document.metadata().nonzero_bounding_box(layer);
3939

4040
let bounds_transform = DAffine2::from_translation(min) * DAffine2::from_scale(max - min);
4141
let layer_transform = document.metadata().transform_to_viewport(layer);

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

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use super::select_tool::extend_lasso;
22
use super::tool_prelude::*;
33
use crate::consts::{
4-
COLOR_OVERLAY_BLUE, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, DRAG_THRESHOLD, HANDLE_ROTATE_SNAP_ANGLE, INSERT_POINT_ON_SEGMENT_TOO_FAR_DISTANCE, SELECTION_THRESHOLD, SELECTION_TOLERANCE,
4+
COLOR_OVERLAY_BLUE, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, DRAG_THRESHOLD, HANDLE_ROTATE_SNAP_ANGLE, INSERT_POINT_ON_SEGMENT_TOO_FAR_DISTANCE,
5+
SELECTION_THRESHOLD, SELECTION_TOLERANCE,
56
};
67
use crate::messages::portfolio::document::overlays::utility_functions::{path_overlays, selected_segments};
78
use crate::messages::portfolio::document::overlays::utility_types::{DrawHandles, OverlayContext};
@@ -1060,21 +1061,19 @@ impl Fsm for PathToolFsmState {
10601061
let origin = tool_data.drag_start_pos;
10611062
let viewport_diagonal = input.viewport_bounds.size().length();
10621063

1063-
let mut faded_blue = graphene_std::Color::from_rgb_str(COLOR_OVERLAY_BLUE.strip_prefix('#').unwrap())
1064-
.unwrap()
1065-
.with_alpha(0.25)
1066-
.to_rgba_hex_srgb();
1067-
faded_blue.insert(0, '#');
1068-
let other = faded_blue.as_str();
1069-
1064+
let faded = |color: &str| {
1065+
let mut color = graphene_std::Color::from_rgb_str(color.strip_prefix('#').unwrap()).unwrap().with_alpha(0.25).to_rgba_hex_srgb();
1066+
color.insert(0, '#');
1067+
color
1068+
};
10701069
match axis {
10711070
Axis::Y => {
1072-
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(COLOR_OVERLAY_BLUE), None);
1073-
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(other), None);
1071+
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(COLOR_OVERLAY_GREEN), None);
1072+
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(&faded(COLOR_OVERLAY_RED)), None);
10741073
}
10751074
Axis::X | Axis::Both => {
1076-
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(COLOR_OVERLAY_BLUE), None);
1077-
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(other), None);
1075+
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(COLOR_OVERLAY_RED), None);
1076+
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(&faded(COLOR_OVERLAY_GREEN)), None);
10781077
}
10791078
}
10801079
}

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

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
use super::tool_prelude::*;
44
use crate::consts::{
5-
COLOR_OVERLAY_BLUE, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, COMPASS_ROSE_HOVER_RING_DIAMETER, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, RESIZE_HANDLE_SIZE, ROTATE_INCREMENT,
6-
SELECTION_DRAG_ANGLE, SELECTION_TOLERANCE,
5+
COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, COMPASS_ROSE_HOVER_RING_DIAMETER, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, RESIZE_HANDLE_SIZE, ROTATE_INCREMENT, SELECTION_DRAG_ANGLE,
6+
SELECTION_TOLERANCE,
77
};
88
use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
99
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
@@ -707,22 +707,23 @@ impl Fsm for SelectToolFsmState {
707707
let angle = -mouse_position.angle_to(DVec2::X);
708708
let snapped_angle = (angle / snap_resolution).round() * snap_resolution;
709709

710-
let mut other = graphene_std::Color::from_rgb_str(COLOR_OVERLAY_BLUE.strip_prefix('#').unwrap())
711-
.unwrap()
712-
.with_alpha(0.25)
713-
.to_rgba_hex_srgb();
714-
other.insert(0, '#');
715-
let other = other.as_str();
716-
717710
let extension = tool_data.drag_current - tool_data.drag_start;
718711
let origin = compass_center - extension;
719712
let viewport_diagonal = input.viewport_bounds.size().length();
720713

721-
let edge = DVec2::from_angle(snapped_angle) * viewport_diagonal;
714+
let edge = DVec2::from_angle(snapped_angle).normalize_or(DVec2::X) * viewport_diagonal;
722715
let perp = edge.perp();
723716

724-
overlay_context.line(origin - edge * viewport_diagonal, origin + edge * viewport_diagonal, Some(COLOR_OVERLAY_BLUE), None);
725-
overlay_context.line(origin - perp * viewport_diagonal, origin + perp * viewport_diagonal, Some(other), None);
717+
let (edge_color, perp_color) = if edge.x.abs() > edge.y.abs() {
718+
(COLOR_OVERLAY_RED, COLOR_OVERLAY_GREEN)
719+
} else {
720+
(COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED)
721+
};
722+
let mut perp_color = graphene_std::Color::from_rgb_str(perp_color.strip_prefix('#').unwrap()).unwrap().with_alpha(0.25).to_rgba_hex_srgb();
723+
perp_color.insert(0, '#');
724+
let perp_color = perp_color.as_str();
725+
overlay_context.line(origin - edge * viewport_diagonal, origin + edge * viewport_diagonal, Some(edge_color), None);
726+
overlay_context.line(origin - perp * viewport_diagonal, origin + perp * viewport_diagonal, Some(perp_color), None);
726727
}
727728

728729
// Check if the tool is in selection mode

0 commit comments

Comments
 (0)