Snap to visible masked-area centers during layer editing
This commit is contained in:
parent
fa2ee8e957
commit
88e00c94d3
|
|
@ -548,7 +548,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "canvas-pilot"
|
||||
version = "0.9.30"
|
||||
version = "0.9.31"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"craft-dwg",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.9.30"
|
||||
version = "0.9.31"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "Language packs",
|
||||
"language.remove-pack": "Remove pack…",
|
||||
"language.overwrite-pack": "Overwrite pack",
|
||||
"ui.mask-edges": "Mask edges",
|
||||
"ui.mask-edges": "Mask edges & centers",
|
||||
"ui.rename-layer": "Rename layer…",
|
||||
"ui.move-to-folder": "Move to folder",
|
||||
"ui.no-folder": "No folder",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "Lingvopakaĵoj",
|
||||
"language.remove-pack": "Forigi pakaĵon…",
|
||||
"language.overwrite-pack": "Anstataŭigi pakaĵon",
|
||||
"ui.mask-edges": "Randoj de maskoj",
|
||||
"ui.mask-edges": "Maskaj randoj kaj centroj",
|
||||
"ui.rename-layer": "Renomi tavolon…",
|
||||
"ui.move-to-folder": "Movi al dosierujo",
|
||||
"ui.no-folder": "Sen dosierujo",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "Paquetes de idiomas",
|
||||
"language.remove-pack": "Eliminar paquete…",
|
||||
"language.overwrite-pack": "Sobrescribir paquete",
|
||||
"ui.mask-edges": "Bordes de máscara",
|
||||
"ui.mask-edges": "Bordes y centros de máscara",
|
||||
"ui.rename-layer": "Renombrar capa…",
|
||||
"ui.move-to-folder": "Mover a carpeta",
|
||||
"ui.no-folder": "Sin carpeta",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "Packs de langues",
|
||||
"language.remove-pack": "Supprimer le pack…",
|
||||
"language.overwrite-pack": "Remplacer le pack",
|
||||
"ui.mask-edges": "Bords des masques",
|
||||
"ui.mask-edges": "Bords et centres des masques",
|
||||
"ui.rename-layer": "Renommer le calque…",
|
||||
"ui.move-to-folder": "Déplacer vers un dossier",
|
||||
"ui.no-folder": "Sans dossier",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "Δέματα γλωσσῶν",
|
||||
"language.remove-pack": "Ἀφαιρεῖν τὸ δέμα…",
|
||||
"language.overwrite-pack": "Ἀντικαθιστάναι τὸ δέμα",
|
||||
"ui.mask-edges": "Ἄκρα τῶν καλυμμάτων",
|
||||
"ui.mask-edges": "Ἄκρα καὶ κέντρα καλυμμάτων",
|
||||
"ui.rename-layer": "Μετονόμασον τὸ στρῶμα…",
|
||||
"ui.move-to-folder": "Εἰς φάκελον μετάθεσον",
|
||||
"ui.no-folder": "Ἄνευ φακέλου",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "भाषा पैक",
|
||||
"language.remove-pack": "पैक हटाएँ…",
|
||||
"language.overwrite-pack": "पैक बदलें",
|
||||
"ui.mask-edges": "मास्क के किनारे",
|
||||
"ui.mask-edges": "मास्क के किनारे और केंद्र",
|
||||
"ui.rename-layer": "परत का नाम बदलें…",
|
||||
"ui.move-to-folder": "फ़ोल्डर में ले जाएँ",
|
||||
"ui.no-folder": "कोई फ़ोल्डर नहीं",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "言語パック",
|
||||
"language.remove-pack": "パックを削除…",
|
||||
"language.overwrite-pack": "パックを上書き",
|
||||
"ui.mask-edges": "マスクの端",
|
||||
"ui.mask-edges": "マスクの端と中心",
|
||||
"ui.rename-layer": "レイヤー名を変更…",
|
||||
"ui.move-to-folder": "フォルダーに移動",
|
||||
"ui.no-folder": "フォルダーなし",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "भाषा प्याकहरू",
|
||||
"language.remove-pack": "प्याक हटाउनुहोस्…",
|
||||
"language.overwrite-pack": "प्याक बदल्नुहोस्",
|
||||
"ui.mask-edges": "मास्कका किनाराहरू",
|
||||
"ui.mask-edges": "मास्कका किनारा र केन्द्रहरू",
|
||||
"ui.rename-layer": "तहको नाम फेर्नुहोस्…",
|
||||
"ui.move-to-folder": "फोल्डरमा सार्नुहोस्",
|
||||
"ui.no-folder": "फोल्डर छैन",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "Pacotes de idiomas",
|
||||
"language.remove-pack": "Remover pacote…",
|
||||
"language.overwrite-pack": "Substituir pacote",
|
||||
"ui.mask-edges": "Limites da máscara",
|
||||
"ui.mask-edges": "Bordas e centros da máscara",
|
||||
"ui.rename-layer": "Mudar nome da camada…",
|
||||
"ui.move-to-folder": "Mover para pasta",
|
||||
"ui.no-folder": "Sem pasta",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "ชุดภาษา",
|
||||
"language.remove-pack": "ลบชุดภาษา…",
|
||||
"language.overwrite-pack": "เขียนทับชุดภาษา",
|
||||
"ui.mask-edges": "ขอบมาสก์",
|
||||
"ui.mask-edges": "ขอบและจุดกึ่งกลางของมาสก์",
|
||||
"ui.rename-layer": "เปลี่ยนชื่อเลเยอร์…",
|
||||
"ui.move-to-folder": "ย้ายไปโฟลเดอร์",
|
||||
"ui.no-folder": "ไม่มีโฟลเดอร์",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "kulupu toki",
|
||||
"language.remove-pack": "o weka e kulupu…",
|
||||
"language.overwrite-pack": "o ante e kulupu",
|
||||
"ui.mask-edges": "poka pi len sitelen",
|
||||
"ui.mask-edges": "poka pi len sitelen en insa ona",
|
||||
"ui.rename-layer": "o ante e nimi lipu…",
|
||||
"ui.move-to-folder": "o tawa kulupu",
|
||||
"ui.no-folder": "kulupu ala",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"language.packs": "语言包",
|
||||
"language.remove-pack": "移除语言包…",
|
||||
"language.overwrite-pack": "覆盖语言包",
|
||||
"ui.mask-edges": "蒙版边缘",
|
||||
"ui.mask-edges": "遮罩边缘和中心",
|
||||
"ui.rename-layer": "重命名图层…",
|
||||
"ui.move-to-folder": "移至文件夹",
|
||||
"ui.no-folder": "无文件夹",
|
||||
|
|
|
|||
|
|
@ -482,7 +482,7 @@ mod tests {
|
|||
click_label(&mut app, &ctx, "Options");
|
||||
click_label(&mut app, &ctx, "Snapping");
|
||||
click_label(&mut app, &ctx, "Snap movement & resizing");
|
||||
click_label(&mut app, &ctx, "Mask edges");
|
||||
click_label(&mut app, &ctx, "Mask edges & centers");
|
||||
assert!(app.snapping.mask_edges);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
let (store, saved) = settings::Store::at(path);
|
||||
|
|
|
|||
|
|
@ -94,10 +94,14 @@ impl Snapping {
|
|||
.mask_edges
|
||||
.then(|| mask_geometry(formats, index, g))
|
||||
.flatten();
|
||||
[self.layer_edges.then_some(g), mask]
|
||||
self.layer_edges
|
||||
.then_some(g)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flat_map(move |g| edges(g, axis))
|
||||
.chain(mask.into_iter().flat_map(move |g| {
|
||||
let [low, high] = edges(g, axis);
|
||||
[low, high, g.center()[axis]]
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,10 +215,16 @@ impl Layout {
|
|||
Vec::new()
|
||||
};
|
||||
targets.extend(grid_targets.iter().copied());
|
||||
let mut mask_centers = Vec::new();
|
||||
if options.layer_edges || options.mask_edges {
|
||||
for (i, g) in before.layers.iter().enumerate() {
|
||||
if !selected[i] && self.visible[i] {
|
||||
targets.extend(options.targets(&before.formats, i, *g, axis));
|
||||
if options.mask_edges
|
||||
&& let Some(mask) = mask_geometry(&before.formats, i, *g)
|
||||
{
|
||||
mask_centers.push(mask.center()[axis]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -232,14 +242,16 @@ impl Layout {
|
|||
.chain(mask.into_iter().flat_map(|g| edge(g, axis)))
|
||||
.map(|v| (false, v))
|
||||
.chain(std::iter::once((true, g.center()[axis])))
|
||||
.chain(mask.map(|g| (true, g.center()[axis])))
|
||||
{
|
||||
for target in &targets {
|
||||
// Centers align to screen interior guides and overlay grid lines;
|
||||
// other targets retain edge-to-edge behavior.
|
||||
// Centers align to screen interior/grid lines and visible mask
|
||||
// centers; existing layer-edge behavior stays unchanged.
|
||||
if is_center
|
||||
&& (!options.screen_edges
|
||||
|| !screen_guides(self.formats.output[axis])[1..4].contains(target))
|
||||
&& !grid_targets.contains(target)
|
||||
&& !mask_centers.contains(target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -934,6 +934,154 @@ fn mask_targets_follow_all_fit_modes_and_skip_letterbox_space() {
|
|||
);
|
||||
assert_eq!(actual, expected, "{fit:?} {origin:?}");
|
||||
assert_eq!(guides, expected.map(Some));
|
||||
let high = [
|
||||
(g.x + g.width)
|
||||
.min(mask.x + mask.width)
|
||||
.min(picture.x + picture.width),
|
||||
(g.y + g.height)
|
||||
.min(mask.y + mask.height)
|
||||
.min(picture.y + picture.height),
|
||||
];
|
||||
let center = std::array::from_fn(|axis| (expected[axis] + high[axis]) / 2.0);
|
||||
assert_eq!(
|
||||
layout.snap_pivot(1, center.map(|v| v + 2.0), mask_options(), 6.0, None, false),
|
||||
(center, center.map(Some)),
|
||||
"{fit:?} {origin:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mask_centers_snap_pivots_resizes_and_moves_and_respect_visibility() {
|
||||
use canvas_pilot::{
|
||||
ResizeHandle,
|
||||
formats::{Mask, MaskOrigin},
|
||||
};
|
||||
for origin in [MaskOrigin::Layer, MaskOrigin::Source] {
|
||||
let mut layout = Layout::default();
|
||||
layout
|
||||
.set_mask(
|
||||
0,
|
||||
Mask {
|
||||
origin,
|
||||
right: 0.25,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
layout.set_locked(0, true);
|
||||
// Visible mask spans x=120..600; its center is 360, not the layer's 440.
|
||||
let options = mask_options();
|
||||
assert_eq!(
|
||||
layout.snap_pivot(1, [362.0, 362.0], options, 6.0, None, false),
|
||||
([360.0, 360.0], [Some(360.0), Some(360.0)])
|
||||
);
|
||||
layout.start_handle_resize(1, ResizeHandle::Left, [1160.0, 360.0], false);
|
||||
assert_eq!(
|
||||
layout.drag_to_snapped([362.0, 360.0], options, 6.0)[0],
|
||||
Some(360.0)
|
||||
);
|
||||
assert_eq!(layout.layers()[1].x, 360.0);
|
||||
layout.cancel_drag();
|
||||
// A whole layer's center can also align to the visible mask center.
|
||||
layout.start_drag([1200.0, 200.0]);
|
||||
assert_eq!(
|
||||
layout.drag_to_snapped([82.0, 200.0], options, 6.0)[0],
|
||||
Some(360.0)
|
||||
);
|
||||
assert_eq!(layout.layers()[1].center()[0], 360.0);
|
||||
layout.cancel_drag();
|
||||
for hidden in [false, true] {
|
||||
layout.set_visible(0, !hidden);
|
||||
for enabled in [false, true] {
|
||||
let options = Snapping {
|
||||
mask_edges: enabled,
|
||||
..options
|
||||
};
|
||||
assert_eq!(
|
||||
layout
|
||||
.snap_pivot(1, [362.0, 362.0], options, 6.0, None, false)
|
||||
.1,
|
||||
if enabled && !hidden {
|
||||
[Some(360.0); 2]
|
||||
} else {
|
||||
[None; 2]
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_mask_center_aligns_to_masks_screen_and_grid_with_rigid_groups_and_undo() {
|
||||
use canvas_pilot::formats::Mask;
|
||||
let mut layout = Layout::default();
|
||||
layout
|
||||
.set_mask(
|
||||
0,
|
||||
Mask {
|
||||
right: 0.375,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
layout
|
||||
.set_mask(
|
||||
1,
|
||||
Mask {
|
||||
left: 0.25,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let before = layout.layers().clone();
|
||||
let formats = layout.formats().clone();
|
||||
layout.start_drag([1200.0, 200.0]);
|
||||
assert_eq!(
|
||||
layout.drag_to_snapped([-37.0, 200.0], mask_options(), 6.0)[0],
|
||||
Some(320.0)
|
||||
);
|
||||
assert_eq!(
|
||||
layout
|
||||
.formats()
|
||||
.mask_bounds(1, layout.layers()[1])
|
||||
.unwrap()
|
||||
.center()[0],
|
||||
320.0
|
||||
);
|
||||
layout.finish_drag();
|
||||
assert_eq!(*layout.formats(), formats);
|
||||
layout.undo();
|
||||
assert_eq!(*layout.layers(), before);
|
||||
layout.set_selection([true, true]);
|
||||
for grid in [false, true] {
|
||||
layout.start_drag([1200.0, 200.0]);
|
||||
let options = Snapping {
|
||||
screen_edges: !grid,
|
||||
grid,
|
||||
grid_divisions: [2, 2],
|
||||
..mask_options()
|
||||
};
|
||||
assert_eq!(
|
||||
layout.drag_to_snapped([603.0, 200.0], options, 6.0)[0],
|
||||
Some(960.0)
|
||||
);
|
||||
assert_eq!(
|
||||
layout
|
||||
.formats()
|
||||
.mask_bounds(1, layout.layers()[1])
|
||||
.unwrap()
|
||||
.center()[0],
|
||||
960.0
|
||||
);
|
||||
assert_eq!(
|
||||
layout.layers()[1].x - layout.layers()[0].x,
|
||||
before[1].x - before[0].x
|
||||
);
|
||||
layout.cancel_drag();
|
||||
assert_eq!(*layout.layers(), before);
|
||||
assert_eq!(*layout.formats(), formats);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,13 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### v0.9.31
|
||||
|
||||
- Extended Mask edges snapping to include visible masked-area centers as movement
|
||||
anchors and move/resize/pivot targets. Centers use the clipped visible picture,
|
||||
including source-relative masks and explicit fit modes; hidden or fully blanked
|
||||
targets stay excluded. Existing preferences, group movement and Undo are preserved.
|
||||
|
||||
### v0.9.30
|
||||
|
||||
- Replaced the toolbar Import tray with an inward-arrow box and added a matching
|
||||
|
|
|
|||
|
|
@ -156,10 +156,15 @@ or document history. Existing project saves still preserve zoom/pan values.
|
|||
|
||||
### Snap to masks
|
||||
|
||||
Enable **Mask edges** in the snapping options to add the visible mask boundaries
|
||||
as targets, independently of **Visible layer edges**. Movement can align either
|
||||
Enable **Mask edges & centers** in the snapping options to add the visible mask boundaries
|
||||
and their centers as targets, independently of **Visible layer edges**. Movement can align either
|
||||
outer layer edges or mask edges to those targets, screen guides and grid lines.
|
||||
Resize handles and pivots can snap to stationary layers’ mask boundaries;
|
||||
The center of a moving visible masked area can align to screen interior guides,
|
||||
overlay grid lines and other masked-area centers. Whole-layer centers can also
|
||||
align to masked-area centers. The center comes from the visible remainder after
|
||||
masking, rather than the hidden/blanked part. Groups move rigidly and Undo restores
|
||||
the complete move without changing mask values.
|
||||
Resize handles and pivots can snap to stationary layers’ mask boundaries or centers;
|
||||
resize handles still belong to the outer layer rectangle. Mirrored/opposite
|
||||
resize contact remains based on outer layer edges.
|
||||
|
||||
|
|
|
|||
|
|
@ -144,9 +144,12 @@ layer movement, resize handles and pivot placement; numeric entry, nudges and cr
|
|||
bypass it. Resize snapping preserves anchors and proportions and shows guides only
|
||||
when the resulting edge actually reaches its target.
|
||||
`mask_edges` adds the nonempty intersection of mask reveal, layer aperture and
|
||||
fitted picture as edge targets. Hidden layers are skipped, locked layers included.
|
||||
Movement also adds selected mask edges as anchors; resize handles remain on the
|
||||
outer rectangle, with masked edges available on stationary targets. Mirrored
|
||||
fitted picture as edge and center targets. Hidden layers are skipped, locked layers included.
|
||||
Movement also adds selected mask edges and centers as anchors; resize handles remain on the
|
||||
outer rectangle, with masked edges and centers available on stationary targets.
|
||||
Moving centers align to screen interior guides, overlay grid lines and stationary
|
||||
mask centers. This extends the existing `mask_edges` flag without changing its
|
||||
serialized name, default or schema version. Mirrored
|
||||
contact uses outer edges. The option defaults to false.
|
||||
|
||||
The session-only toolbar grid tools select 10 or 100 screen pixels (mutually exclusive). Shift temporarily selects the 10 px grid; Ctrl+Shift selects 100 px. If that same grid tool is selected, the matching shortcut temporarily disables it instead. Alt overrides both grids and temporarily inverts the saved snapping-enabled value (off becomes on; on becomes off), including on release. The chosen pixel/screen/layer-edge targets still apply. These modifiers do not change the saved options or settings version.
|
||||
|
|
|
|||
Loading…
Reference in New Issue