Skip to content

Commit 68b30fa

Browse files
committed
implement snapping for point-handle gizmo and implement no of point gizmo need to refactor
1 parent b6d9aa9 commit 68b30fa

File tree

6 files changed

+391
-101
lines changed

6 files changed

+391
-101
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ serde_json = { workspace = true }
4747
bezier-rs = { workspace = true }
4848
futures = { workspace = true }
4949
glam = { workspace = true, features = ["serde", "debug-glam-assert"] }
50+
kurbo = { workspace = true }
5051
derivative = { workspace = true }
5152
specta = { workspace = true }
5253
image = { workspace = true, features = ["bmp", "png"] }

editor/src/consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ pub const DEFAULT_BRUSH_SIZE: f64 = 20.;
119119

120120
// STAR GIZMOS
121121
pub const POINT_RADIUS_HANDLE_SNAP_THRESHOLD: f64 = 8.;
122+
pub const POINT_RADIUS_HANDLE_SEGMENT_THRESHOLD: f64 = 7.9;
123+
pub const NUMBER_OF_POINTS_HANDLE_SPOKE_EXTENSION: f64 = 1.2;
124+
pub const NUMBER_OF_POINTS_HANDLE_SPOKE_LENGTH: f64 = 10.;
125+
pub const GIZMO_HIDE_THRESHOLD: f64 = 20.;
122126

123127
// SCROLLBARS
124128
pub const SCROLLBAR_SPACING: f64 = 0.1;

editor/src/messages/tool/common_functionality/shapes/shape_utility.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use crate::messages::tool::common_functionality::graph_modification_utils::{self
77
use crate::messages::tool::common_functionality::transformation_cage::BoundingBoxManager;
88
use crate::messages::tool::tool_messages::tool_prelude::Key;
99
use crate::messages::tool::utility_types::*;
10+
use bezier_rs::Subpath;
1011
use glam::{DMat2, DVec2};
1112
use graph_craft::document::NodeInput;
1213
use graph_craft::document::value::TaggedValue;
14+
use graphene_std::vector::PointId;
1315
use std::collections::VecDeque;
1416
use std::f64::consts::PI;
1517

@@ -151,36 +153,31 @@ pub fn anchor_overlays(document: &DocumentMessageHandler, overlay_context: &mut
151153
}
152154
}
153155

154-
pub fn points_on_inner_circle(document: &DocumentMessageHandler, mouse_position: DVec2) -> Option<(LayerNodeIdentifier, u32, usize, f64)> {
155-
for layer in document
156-
.network_interface
157-
.selected_nodes()
158-
.selected_visible_and_unlocked_layers(&document.network_interface)
159-
.filter(|layer| graph_modification_utils::get_star_id(*layer, &document.network_interface).is_some())
160-
{
161-
let Some(node_inputs) = NodeGraphLayer::new(layer, &document.network_interface).find_node_inputs("Star") else {
162-
continue;
163-
};
156+
pub fn star_outline(layer: LayerNodeIdentifier, document: &DocumentMessageHandler, overlay_context: &mut OverlayContext) {
157+
let mut anchors = Vec::new();
164158

165-
let viewport = document.network_interface.document_metadata().transform_to_viewport(layer);
159+
let Some(node_inputs) = NodeGraphLayer::new(layer, &document.network_interface).find_node_inputs("Star") else {
160+
return;
161+
};
166162

167-
let (Some(&TaggedValue::U32(n)), Some(&TaggedValue::F64(outer)), Some(&TaggedValue::F64(inner))) = (node_inputs[1].as_value(), node_inputs[2].as_value(), node_inputs[3].as_value()) else {
168-
continue;
169-
};
163+
let (Some(&TaggedValue::U32(n)), Some(&TaggedValue::F64(radius1)), Some(&TaggedValue::F64(radius2))) = (node_inputs[1].as_value(), node_inputs[2].as_value(), node_inputs[3].as_value()) else {
164+
return;
165+
};
170166

171-
for i in 0..(2 * n) {
172-
let angle = i as f64 * PI / n as f64;
173-
let (radius, index) = if i % 2 == 0 { (outer, 2) } else { (inner, 3) };
167+
let viewport = document.metadata().transform_to_viewport(layer);
168+
for i in 0..(2 * n) {
169+
let angle = i as f64 * PI / n as f64;
170+
let radius = if i % 2 == 0 { radius1 } else { radius2 };
174171

175-
let point = viewport.transform_point2(DVec2 {
176-
x: radius * angle.sin(),
177-
y: -radius * angle.cos(),
178-
});
172+
let point = DVec2 {
173+
x: radius * angle.sin(),
174+
y: -radius * angle.cos(),
175+
};
179176

180-
if point.distance(mouse_position) < 5.0 {
181-
return Some((layer, i, index, radius));
182-
};
183-
}
177+
anchors.push(point);
184178
}
185-
None
179+
180+
let subpath: Vec<Subpath<PointId>> = vec![Subpath::from_anchors_linear(anchors, true)];
181+
182+
overlay_context.outline(subpath.iter(), viewport, None);
186183
}

0 commit comments

Comments
 (0)