mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-02 22:20:50 -06:00
Fix #321: the perspective grid hides while a perspective tool is chosen
The grid was drawn whenever its `visible` flag was set or a perspective tool was active, and choosing the Perspective Grid tool (Shift+P) didn't set the flag. So with the tool chosen, View > Perspective Grid > Hide Grid (perspective.grid.show) turned the hidden flag on instead of off and the grid stayed on screen however it was toggled. Choosing a perspective tool now shows the grid (sets `visible`, view state, no undo step), and the grid, its widget and the Perspective Grid tool's handles are drawn only while it is visible. Hide Grid hides it with the tool still chosen; choosing the tool again shows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
bflatastic
co-authored by
Claude Opus 5.5
parent
f17c34a067
commit
4a676c4d5e
@@ -480,11 +480,6 @@ impl PerspectiveGrid {
|
||||
self.extent_right.unwrap_or(self.extent)
|
||||
}
|
||||
|
||||
/// Is the grid drawn (shown, or a perspective tool active)?
|
||||
pub fn shown(&self, tool_id: &str) -> bool {
|
||||
self.visible || matches!(tool_id, "perspectiveGrid" | "perspectiveSelection")
|
||||
}
|
||||
|
||||
/// Page → plane coordinates.
|
||||
pub fn to_plane(&self, plane: Plane, p: Point) -> Option<Point> {
|
||||
self.homography(plane)?.inverse()?.apply(p)
|
||||
@@ -761,16 +756,16 @@ fn in_quad(q: &[Point; 4], p: Point) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Grid overlays (lines, horizon, vanishing points, widget) drawn whenever the grid is visible or
|
||||
/// a perspective tool is active. `tol` = document units per screen pixel.
|
||||
pub fn grid_overlays(doc: &Document, tol: f64, tool_id: &str) -> Vec<Overlay> {
|
||||
grid_overlays_in(doc, tol, tool_id, Some(widget::WidgetPlace::default()))
|
||||
/// Grid overlays (lines, horizon, vanishing points, widget) drawn whenever the grid is visible
|
||||
/// (selecting a perspective tool shows it). `tol` = document units per screen pixel.
|
||||
pub fn grid_overlays(doc: &Document, tol: f64) -> Vec<Overlay> {
|
||||
grid_overlays_in(doc, tol, Some(widget::WidgetPlace::default()))
|
||||
}
|
||||
|
||||
/// [`grid_overlays`] with the Plane Switching Widget at `place` (None: hidden).
|
||||
pub fn grid_overlays_in(doc: &Document, tol: f64, tool_id: &str, place: Option<widget::WidgetPlace>) -> Vec<Overlay> {
|
||||
pub fn grid_overlays_in(doc: &Document, tol: f64, place: Option<widget::WidgetPlace>) -> Vec<Overlay> {
|
||||
let g = PerspectiveGrid::current(doc);
|
||||
if !g.shown(tool_id) {
|
||||
if !g.visible {
|
||||
return vec![];
|
||||
}
|
||||
let mut out = vec![];
|
||||
@@ -1012,6 +1007,10 @@ impl Tool for PerspectiveGridTool {
|
||||
}
|
||||
fn overlays(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
let g = PerspectiveGrid::current(cx.doc);
|
||||
// The grid's handles hide with it.
|
||||
if !g.visible {
|
||||
return vec![];
|
||||
}
|
||||
let ink = [0x20, 0x20, 0x20];
|
||||
handles(&g, cx.tol(1.0))
|
||||
.into_iter()
|
||||
@@ -1412,7 +1411,7 @@ mod tests {
|
||||
assert_eq!(cmd, "perspective.grid.set");
|
||||
assert_eq!(v["vpLeft"], json!(g.vp_left - 40.0));
|
||||
assert_eq!(v["horizon"], json!(g.horizon + 10.0));
|
||||
assert!(!grid_overlays(&d, 1.0, "selection").is_empty());
|
||||
assert!(!grid_overlays(&d, 1.0).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user