Show faded hatched content in masked editing regions
This commit is contained in:
parent
37707a108e
commit
85d07c3278
|
|
@ -548,7 +548,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "canvas-pilot"
|
||||
version = "0.9.10"
|
||||
version = "0.9.11"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"craft-dwg",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.9.10"
|
||||
version = "0.9.11"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"
|
||||
|
|
|
|||
|
|
@ -670,12 +670,7 @@ pub(super) fn paint_content_overflow(
|
|||
return;
|
||||
};
|
||||
// Disjoint strips avoid painting the visible box twice or doubling opacity.
|
||||
for clip in [
|
||||
Rect::from_min_max(full.min, Pos2::new(full.right(), rect.top())),
|
||||
Rect::from_min_max(Pos2::new(full.left(), rect.bottom()), full.max),
|
||||
Rect::from_min_max(Pos2::new(full.left(), rect.top()), rect.left_bottom()),
|
||||
Rect::from_min_max(rect.right_top(), Pos2::new(full.right(), rect.bottom())),
|
||||
] {
|
||||
for clip in outside_strips(full, rect) {
|
||||
let clip = clip.intersect(painter.clip_rect());
|
||||
if clip.is_positive() {
|
||||
let mut ghost = painter.with_clip_rect(clip);
|
||||
|
|
@ -700,18 +695,10 @@ pub(super) fn paint_one_to_one_helper(
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn paint_layer_source(
|
||||
painter: &egui::Painter,
|
||||
rect: Rect,
|
||||
layout: &Layout,
|
||||
i: usize,
|
||||
preview: Option<(egui::TextureId, f32)>,
|
||||
) {
|
||||
pub(super) fn layer_mask_rect(rect: Rect, layout: &Layout, i: usize) -> Option<Rect> {
|
||||
let formats = layout.formats();
|
||||
let mask = formats.masks[i];
|
||||
let Ok(reference) = formats.mask_reference(i, layout.layers()[i]) else {
|
||||
return;
|
||||
};
|
||||
let reference = formats.mask_reference(i, layout.layers()[i]).ok()?;
|
||||
let layer = layout.layers()[i];
|
||||
let k = rect.width() as f64 / layer.width;
|
||||
let mask_rect = Rect::from_min_size(
|
||||
|
|
@ -734,11 +721,89 @@ pub(super) fn paint_layer_source(
|
|||
mask_rect.height() * mask.bottom as f32,
|
||||
),
|
||||
);
|
||||
Some(clip)
|
||||
}
|
||||
|
||||
/// Four disjoint strips; a collapsed or disjoint reveal leaves the whole area hidden.
|
||||
pub(super) fn outside_strips(outer: Rect, reveal: Rect) -> [Rect; 4] {
|
||||
let reveal = outer.intersect(reveal);
|
||||
if !reveal.is_positive() {
|
||||
return [outer, Rect::NOTHING, Rect::NOTHING, Rect::NOTHING];
|
||||
}
|
||||
[
|
||||
Rect::from_min_max(outer.min, Pos2::new(outer.right(), reveal.top())),
|
||||
Rect::from_min_max(Pos2::new(outer.left(), reveal.bottom()), outer.max),
|
||||
Rect::from_min_max(Pos2::new(outer.left(), reveal.top()), reveal.left_bottom()),
|
||||
Rect::from_min_max(
|
||||
reveal.right_top(),
|
||||
Pos2::new(outer.right(), reveal.bottom()),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
/// Editor-only context: hidden source remains readable, with hatching marking blanking.
|
||||
pub(super) fn paint_mask_helper(
|
||||
painter: &egui::Painter,
|
||||
rect: Rect,
|
||||
layout: &Layout,
|
||||
i: usize,
|
||||
preview: Option<(egui::TextureId, f32)>,
|
||||
) {
|
||||
let Some(reveal) = layer_mask_rect(rect, layout, i) else {
|
||||
return;
|
||||
};
|
||||
for strip in outside_strips(rect, reveal) {
|
||||
let clip = strip.intersect(painter.clip_rect());
|
||||
if !clip.is_positive() {
|
||||
continue;
|
||||
}
|
||||
let clipped = painter.with_clip_rect(clip);
|
||||
let mut ghost = clipped.clone();
|
||||
ghost.multiply_opacity(0.25);
|
||||
paint_layer_content(&ghost, rect, layout, i, preview);
|
||||
// Spacing is in screen points, so zoom cannot generate an unbounded grid.
|
||||
let spacing = 12.0;
|
||||
let mut sum = ((clip.left() + clip.top()) / spacing).floor() * spacing;
|
||||
let end = clip.right() + clip.bottom();
|
||||
let stroke = Stroke::new(1.0, Color32::from_rgba_unmultiplied(222, 108, 220, 85));
|
||||
while sum <= end {
|
||||
clipped.line_segment(
|
||||
[
|
||||
Pos2::new(sum - clip.top(), clip.top()),
|
||||
Pos2::new(sum - clip.bottom(), clip.bottom()),
|
||||
],
|
||||
stroke,
|
||||
);
|
||||
sum += spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn paint_layer_source(
|
||||
painter: &egui::Painter,
|
||||
rect: Rect,
|
||||
layout: &Layout,
|
||||
i: usize,
|
||||
preview: Option<(egui::TextureId, f32)>,
|
||||
) {
|
||||
let Some(clip) = layer_mask_rect(rect, layout, i) else {
|
||||
return;
|
||||
};
|
||||
if !clip.is_positive() {
|
||||
return;
|
||||
}
|
||||
let clipped = painter.with_clip_rect(painter.clip_rect().intersect(clip).intersect(rect));
|
||||
let painter = &clipped;
|
||||
let clipped = painter.with_clip_rect(clip.intersect(rect));
|
||||
paint_layer_content(&clipped, rect, layout, i, preview);
|
||||
}
|
||||
|
||||
fn paint_layer_content(
|
||||
painter: &egui::Painter,
|
||||
rect: Rect,
|
||||
layout: &Layout,
|
||||
i: usize,
|
||||
preview: Option<(egui::TextureId, f32)>,
|
||||
) {
|
||||
let formats = layout.formats();
|
||||
let source = formats.sources[formats.source_for[i]];
|
||||
let crop = formats.advanced[i];
|
||||
let Some(fit) = formats.layer_fit[i] else {
|
||||
|
|
@ -1573,6 +1638,108 @@ mod tests {
|
|||
#[cfg(test)]
|
||||
mod preview_paint_tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn masked_helper_is_translucent_hatched_and_confined_to_hidden_regions() {
|
||||
use canvas_pilot::formats::{LayerFit, Mask, MaskOrigin};
|
||||
let rect = Rect::from_min_size(Pos2::new(200.0, 200.0), Vec2::new(320.0, 180.0));
|
||||
for fit in std::iter::once(None).chain(LayerFit::ALL.into_iter().map(Some)) {
|
||||
for origin in [MaskOrigin::Layer, MaskOrigin::Source] {
|
||||
let mut app = Editor::default();
|
||||
app.layout.set_layer_fit(1, fit, Crop::default()).unwrap();
|
||||
for edge in [0.45, 0.5] {
|
||||
app.layout
|
||||
.set_mask(
|
||||
1,
|
||||
Mask {
|
||||
origin,
|
||||
left: edge,
|
||||
right: edge,
|
||||
top: edge,
|
||||
bottom: edge,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let before = app.project();
|
||||
let reveal = layer_mask_rect(rect, &app.layout, 1).unwrap();
|
||||
for preview in [None, Some((egui::TextureId::User(91), 0.0))] {
|
||||
let ctx = egui::Context::default();
|
||||
let output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
paint_mask_helper(ui.painter(), rect, &app.layout, 1, preview)
|
||||
});
|
||||
assert!(!output.shapes.is_empty(), "{fit:?} {origin:?}");
|
||||
assert!(output.shapes.iter().all(|s| rect.contains_rect(s.clip_rect)
|
||||
&& !s.clip_rect.intersect(reveal).is_positive()));
|
||||
assert!(output.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::LineSegment { stroke, .. } if stroke.color == Color32::from_rgba_unmultiplied(222,108,220,85))));
|
||||
if preview.is_some() {
|
||||
let meshes: Vec<_> = output
|
||||
.shapes
|
||||
.iter()
|
||||
.filter_map(|s| {
|
||||
if let egui::Shape::Mesh(m) = &s.shape {
|
||||
Some(m)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
assert!(!meshes.is_empty());
|
||||
assert!(meshes.iter().all(|m| {
|
||||
m.vertices
|
||||
.iter()
|
||||
.all(|v| v.color.a() == Color32::WHITE.gamma_multiply(0.25).a())
|
||||
}));
|
||||
}
|
||||
}
|
||||
assert_eq!(app.project(), before);
|
||||
}
|
||||
}
|
||||
}
|
||||
let app = Editor::default();
|
||||
let ctx = egui::Context::default();
|
||||
let output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
paint_mask_helper(ui.painter(), rect, &app.layout, 1, None)
|
||||
});
|
||||
assert!(
|
||||
output.shapes.is_empty(),
|
||||
"an unmasked layer needs no overlay"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn masked_overlay_is_visible_only_while_editing_the_selected_layer() {
|
||||
use crate::gui::tests::frame;
|
||||
use canvas_pilot::formats::Mask;
|
||||
let mut app = Editor::default();
|
||||
app.layout.select(Some(1));
|
||||
app.layout
|
||||
.set_mask(
|
||||
1,
|
||||
Mask {
|
||||
left: 0.25,
|
||||
..Mask::default()
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let before = app.project();
|
||||
let ctx = egui::Context::default();
|
||||
let hatched = |out: &egui::FullOutput| {
|
||||
out.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::LineSegment { stroke, .. } if stroke.color == Color32::from_rgba_unmultiplied(222,108,220,85)))
|
||||
};
|
||||
assert!(!hatched(&frame(&mut app, &ctx, vec![])));
|
||||
app.edit_content = true;
|
||||
assert!(hatched(&frame(&mut app, &ctx, vec![])));
|
||||
app.edit_mask = true;
|
||||
assert!(hatched(&frame(&mut app, &ctx, vec![])));
|
||||
app.edit_content = false;
|
||||
app.edit_mask = false;
|
||||
assert!(!hatched(&frame(&mut app, &ctx, vec![])));
|
||||
app.layout.select(Some(0));
|
||||
app.edit_content = true;
|
||||
assert!(!hatched(&frame(&mut app, &ctx, vec![])));
|
||||
app.layout.select(Some(1));
|
||||
assert_eq!(app.project(), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn crop_helpers_render_translucent_content_outside_the_retained_rectangle() {
|
||||
let rect = Rect::from_min_size(Pos2::new(200.0, 200.0), Vec2::new(300.0, 300.0));
|
||||
|
|
|
|||
|
|
@ -3621,15 +3621,27 @@ impl Editor {
|
|||
origin + Vec2::new(reference.x as f32, reference.y as f32) * scale,
|
||||
Vec2::new(reference.width as f32, reference.height as f32) * scale,
|
||||
);
|
||||
let mut ghost = screen.painter.clone();
|
||||
ghost.multiply_opacity(0.3);
|
||||
format_ui::paint_source(
|
||||
&ghost,
|
||||
rect,
|
||||
self.layout.formats().sources[self.layout.formats().source_for[i]],
|
||||
Default::default(),
|
||||
self.layer_preview(i),
|
||||
let layer = self.layout.layers()[i];
|
||||
let layer_rect = Rect::from_min_size(
|
||||
origin + Vec2::new(layer.x as f32, layer.y as f32) * scale,
|
||||
Vec2::new(layer.width as f32, layer.height as f32) * scale,
|
||||
);
|
||||
// Inside the layer, the masked-area helper owns the ghost opacity.
|
||||
for strip in format_ui::outside_strips(rect, layer_rect) {
|
||||
let clip = strip.intersect(screen.painter.clip_rect());
|
||||
if !clip.is_positive() {
|
||||
continue;
|
||||
}
|
||||
let mut ghost = screen.painter.with_clip_rect(clip);
|
||||
ghost.multiply_opacity(0.3);
|
||||
format_ui::paint_source(
|
||||
&ghost,
|
||||
rect,
|
||||
self.layout.formats().sources[self.layout.formats().source_for[i]],
|
||||
Default::default(),
|
||||
self.layer_preview(i),
|
||||
);
|
||||
}
|
||||
}
|
||||
if self.edit_content
|
||||
&& !self.mask_editing()
|
||||
|
|
@ -3645,13 +3657,27 @@ impl Editor {
|
|||
if self.layout.formats().layer_fit[i] == Some(canvas_pilot::formats::LayerFit::OneToOne)
|
||||
{
|
||||
if let Some(image) = self.crop_bounds(origin, scale) {
|
||||
format_ui::paint_one_to_one_helper(
|
||||
&screen.painter,
|
||||
image,
|
||||
self.layout.formats().sources[self.layout.formats().source_for[i]],
|
||||
self.layout.formats().advanced[i],
|
||||
self.layer_preview(i),
|
||||
);
|
||||
// Do not stack the crop ghost over the masked-area ghost inside
|
||||
// the layer. Keep the usable-source guide outside it and in the reveal.
|
||||
let reveal = format_ui::layer_mask_rect(rect, &self.layout, i)
|
||||
.unwrap_or(Rect::NOTHING)
|
||||
.intersect(rect);
|
||||
for clip in format_ui::outside_strips(screen.painter.clip_rect(), rect)
|
||||
.into_iter()
|
||||
.chain(std::iter::once(reveal))
|
||||
{
|
||||
let clip = clip.intersect(screen.painter.clip_rect());
|
||||
if !clip.is_positive() {
|
||||
continue;
|
||||
}
|
||||
format_ui::paint_one_to_one_helper(
|
||||
&screen.painter.with_clip_rect(clip),
|
||||
image,
|
||||
self.layout.formats().sources[self.layout.formats().source_for[i]],
|
||||
self.layout.formats().advanced[i],
|
||||
self.layer_preview(i),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
format_ui::paint_content_overflow(
|
||||
|
|
@ -3710,6 +3736,9 @@ impl Editor {
|
|||
|| preview.is_some()
|
||||
|| self.layout.formats().masks[i] != Default::default()
|
||||
{
|
||||
if self.edit_content && self.layout.selected() == Some(i) {
|
||||
format_ui::paint_mask_helper(p, rect, &self.layout, i, preview);
|
||||
}
|
||||
format_ui::paint_layer_source(
|
||||
p,
|
||||
rect,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,16 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### v0.9.11
|
||||
|
||||
- Added a 25%-opacity source guide with sparse diagonal hatching over masked areas
|
||||
while editing the selected layer's crop or mask. Hidden content stays readable;
|
||||
leaving editing restores normal transparent blanking. Exports/device data are unchanged.
|
||||
- Kept source-mask and 1:1 context guides from stacking opacity inside masked areas.
|
||||
Hatching uses fixed screen spacing and clips to the viewport, including at high zoom.
|
||||
- Verified native crop/Tab-mask rendering, both mask origins and all fit modes.
|
||||
Required checks passed with 91.46% whole-application line coverage.
|
||||
|
||||
### v0.9.10
|
||||
|
||||
- Restored faded content outside the layer during crop editing and outside the
|
||||
|
|
|
|||
|
|
@ -239,7 +239,12 @@ ends. Alt alone does nothing outside crop mode and still zooms out with the Zoom
|
|||
tool. Some Linux window managers reserve Alt + mouse gestures; use the context
|
||||
menu if the desktop intercepts it.
|
||||
The magenta rectangle reveals the image; outside pixels
|
||||
are blanked transparently. It works with normal crop and every advanced fit.
|
||||
are blanked transparently in normal viewing and output. While editing the selected
|
||||
layer's crop or mask, the masked portions inside the layer instead show a 25%-opacity
|
||||
source guide with sparse magenta diagonal hatching. This keeps hidden content
|
||||
readable and distinguishes masking from the ordinary faded crop overflow outside
|
||||
the layer. The hatching and masked-content guide disappear when editing ends;
|
||||
they are never exported or sent to the device. It works with normal crop and every advanced fit.
|
||||
|
||||
- Drag a side or corner independently to blank more or fewer pixels.
|
||||
- Drag anywhere inside the layer to move the reveal window without resizing it.
|
||||
|
|
|
|||
Loading…
Reference in New Issue