Add quick measure overlays with Alt pressed (#1894)

* Measure with alt

* Code review

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
James Lindsay
2024-08-10 04:56:02 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent 501b562d0f
commit 1f278799d6
5 changed files with 93 additions and 7 deletions
@@ -486,6 +486,7 @@ impl Fsm for PathToolFsmState {
// `Self::InsertPoint` case:
(Self::InsertPoint, PathToolMessage::MouseDown { .. } | PathToolMessage::Enter { .. }) => {
tool_data.double_click_handled = true;
// TODO: Don't use `Key::Shift` directly, instead take it as a variable from the input mappings list like in all other places
let shift = input.keyboard.get(Key::Shift as usize);
tool_data.end_insertion(shape_editor, responses, InsertEndKind::Add { shift })
}
@@ -499,8 +500,11 @@ impl Fsm for PathToolFsmState {
(Self::InsertPoint, PathToolMessage::GRS { key: propagate }) => {
// MAYBE: use `InputMapperMessage::KeyDown(..)` instead
match propagate {
// TODO: Don't use `Key::G` directly, instead take it as a variable from the input mappings list like in all other places
Key::KeyG => responses.add(TransformLayerMessage::BeginGrab),
// TODO: Don't use `Key::R` directly, instead take it as a variable from the input mappings list like in all other places
Key::KeyR => responses.add(TransformLayerMessage::BeginRotate),
// TODO: Don't use `Key::S` directly, instead take it as a variable from the input mappings list like in all other places
Key::KeyS => responses.add(TransformLayerMessage::BeginScale),
_ => warn!("Unexpected GRS key"),
}
@@ -10,14 +10,15 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, FlipAxis};
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, NodeNetworkInterface, NodeTemplate};
use crate::messages::portfolio::document::utility_types::transformation::Selected;
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
use crate::messages::tool::common_functionality::graph_modification_utils::is_layer_fed_by_node_of_name;
use crate::messages::tool::common_functionality::pivot::Pivot;
use crate::messages::tool::common_functionality::snapping::{self, SnapCandidatePoint, SnapData, SnapManager};
use crate::messages::tool::common_functionality::transformation_cage::*;
use crate::messages::tool::common_functionality::{auto_panning::AutoPanning, measure};
use graph_craft::document::NodeId;
use graphene_core::renderer::Quad;
use graphene_std::renderer::Rect;
use graphene_std::vector::misc::BooleanOperation;
use std::fmt;
@@ -471,13 +472,27 @@ impl Fsm for SelectToolFsmState {
// Update the selection box
overlay_context.quad(quad);
}
// Only highlight layers if the viewport is not being panned (middle mouse button is pressed)
} else if !input.keyboard.get(Key::Mmb as usize) {
// TODO: Don't use `Key::Mmb` directly, instead take it as a variable from the input mappings list like in all other places
else if !input.keyboard.get(Key::Mmb as usize) {
// Get the layer the user is hovering over
let click = document.click(input);
let not_selected_click = click.filter(|&hovered_layer| !document.network_interface.selected_nodes(&[]).unwrap().selected_layers_contains(hovered_layer, document.metadata()));
if let Some(layer) = not_selected_click {
overlay_context.outline(document.metadata().layer_outline(layer), document.metadata().transform_to_viewport(layer));
// Measure with Alt held down
// TODO: Don't use `Key::Alt` directly, instead take it as a variable from the input mappings list like in all other places
if input.keyboard.get(Key::Alt as usize) {
let hovered_bounds = document
.metadata()
.bounding_box_with_transform(layer, transform.inverse() * document.metadata().transform_to_viewport(layer));
if let [Some(selected_bounds), Some(hovered_bounds)] = [bounds, hovered_bounds].map(|rect| rect.map(Rect::from_box)) {
measure::overlay(selected_bounds, hovered_bounds, transform, document.metadata().document_to_viewport, &mut overlay_context);
}
}
}
}