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
This commit is contained in:
mTvare 2025-04-18 02:15:08 +05:30 committed by GitHub
parent 41fe46591a
commit 29e8e8bdac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 29 deletions

View file

@ -146,13 +146,14 @@ impl DocumentMetadata {
let bounds_size = bounds_max - bounds_min;
let bounds_midpoint = bounds_min.midpoint(bounds_max);
const BOX_NUDGE: f64 = 5e-9;
if bounds_size.x < 1e-10 {
bounds_max.x = bounds_midpoint.x + 0.5;
bounds_min.x = bounds_midpoint.x - 0.5;
bounds_max.x = bounds_midpoint.x + BOX_NUDGE;
bounds_min.x = bounds_midpoint.x - BOX_NUDGE;
}
if bounds_size.y < 1e-10 {
bounds_max.y = bounds_midpoint.y + 0.5;
bounds_min.y = bounds_midpoint.y - 0.5;
bounds_max.y = bounds_midpoint.y + BOX_NUDGE;
bounds_min.y = bounds_midpoint.y - BOX_NUDGE;
}
[bounds_min, bounds_max]

View file

@ -35,7 +35,7 @@ impl Default for Pivot {
impl Pivot {
/// Calculates the transform that gets from normalized pivot to viewspace.
fn get_layer_pivot_transform(layer: LayerNodeIdentifier, document: &DocumentMessageHandler) -> DAffine2 {
let [min, max] = document.metadata().bounding_box_with_transform(layer, DAffine2::IDENTITY).unwrap_or_default();
let [min, max] = document.metadata().nonzero_bounding_box(layer);
let bounds_transform = DAffine2::from_translation(min) * DAffine2::from_scale(max - min);
let layer_transform = document.metadata().transform_to_viewport(layer);

View file

@ -1,7 +1,8 @@
use super::select_tool::extend_lasso;
use super::tool_prelude::*;
use crate::consts::{
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,
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,
SELECTION_THRESHOLD, SELECTION_TOLERANCE,
};
use crate::messages::portfolio::document::overlays::utility_functions::{path_overlays, selected_segments};
use crate::messages::portfolio::document::overlays::utility_types::{DrawHandles, OverlayContext};
@ -1060,21 +1061,19 @@ impl Fsm for PathToolFsmState {
let origin = tool_data.drag_start_pos;
let viewport_diagonal = input.viewport_bounds.size().length();
let mut faded_blue = graphene_std::Color::from_rgb_str(COLOR_OVERLAY_BLUE.strip_prefix('#').unwrap())
.unwrap()
.with_alpha(0.25)
.to_rgba_hex_srgb();
faded_blue.insert(0, '#');
let other = faded_blue.as_str();
let faded = |color: &str| {
let mut color = graphene_std::Color::from_rgb_str(color.strip_prefix('#').unwrap()).unwrap().with_alpha(0.25).to_rgba_hex_srgb();
color.insert(0, '#');
color
};
match axis {
Axis::Y => {
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(COLOR_OVERLAY_BLUE), None);
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(other), None);
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(COLOR_OVERLAY_GREEN), None);
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(&faded(COLOR_OVERLAY_RED)), None);
}
Axis::X | Axis::Both => {
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(COLOR_OVERLAY_BLUE), None);
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(other), None);
overlay_context.line(origin - DVec2::X * viewport_diagonal, origin + DVec2::X * viewport_diagonal, Some(COLOR_OVERLAY_RED), None);
overlay_context.line(origin - DVec2::Y * viewport_diagonal, origin + DVec2::Y * viewport_diagonal, Some(&faded(COLOR_OVERLAY_GREEN)), None);
}
}
}

View file

@ -2,8 +2,8 @@
use super::tool_prelude::*;
use crate::consts::{
COLOR_OVERLAY_BLUE, COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, COMPASS_ROSE_HOVER_RING_DIAMETER, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, RESIZE_HANDLE_SIZE, ROTATE_INCREMENT,
SELECTION_DRAG_ANGLE, SELECTION_TOLERANCE,
COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED, COMPASS_ROSE_HOVER_RING_DIAMETER, DRAG_DIRECTION_MODE_DETERMINATION_THRESHOLD, RESIZE_HANDLE_SIZE, ROTATE_INCREMENT, SELECTION_DRAG_ANGLE,
SELECTION_TOLERANCE,
};
use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
@ -707,22 +707,23 @@ impl Fsm for SelectToolFsmState {
let angle = -mouse_position.angle_to(DVec2::X);
let snapped_angle = (angle / snap_resolution).round() * snap_resolution;
let mut other = graphene_std::Color::from_rgb_str(COLOR_OVERLAY_BLUE.strip_prefix('#').unwrap())
.unwrap()
.with_alpha(0.25)
.to_rgba_hex_srgb();
other.insert(0, '#');
let other = other.as_str();
let extension = tool_data.drag_current - tool_data.drag_start;
let origin = compass_center - extension;
let viewport_diagonal = input.viewport_bounds.size().length();
let edge = DVec2::from_angle(snapped_angle) * viewport_diagonal;
let edge = DVec2::from_angle(snapped_angle).normalize_or(DVec2::X) * viewport_diagonal;
let perp = edge.perp();
overlay_context.line(origin - edge * viewport_diagonal, origin + edge * viewport_diagonal, Some(COLOR_OVERLAY_BLUE), None);
overlay_context.line(origin - perp * viewport_diagonal, origin + perp * viewport_diagonal, Some(other), None);
let (edge_color, perp_color) = if edge.x.abs() > edge.y.abs() {
(COLOR_OVERLAY_RED, COLOR_OVERLAY_GREEN)
} else {
(COLOR_OVERLAY_GREEN, COLOR_OVERLAY_RED)
};
let mut perp_color = graphene_std::Color::from_rgb_str(perp_color.strip_prefix('#').unwrap()).unwrap().with_alpha(0.25).to_rgba_hex_srgb();
perp_color.insert(0, '#');
let perp_color = perp_color.as_str();
overlay_context.line(origin - edge * viewport_diagonal, origin + edge * viewport_diagonal, Some(edge_color), None);
overlay_context.line(origin - perp * viewport_diagonal, origin + perp * viewport_diagonal, Some(perp_color), None);
}
// Check if the tool is in selection mode