Preview cropped content at half opacity while reframing
This commit is contained in:
parent
46ff587d83
commit
cbb1681b04
|
|
@ -268,7 +268,13 @@ fn fit_rect(rect: Rect, size: [f64; 2]) -> Rect {
|
||||||
let k = (rect.width() / size[0] as f32).min(rect.height() / size[1] as f32);
|
let k = (rect.width() / size[0] as f32).min(rect.height() / size[1] as f32);
|
||||||
Rect::from_center_size(rect.center(), Vec2::new(size[0] as f32, size[1] as f32) * k)
|
Rect::from_center_size(rect.center(), Vec2::new(size[0] as f32, size[1] as f32) * k)
|
||||||
}
|
}
|
||||||
pub(super) fn paint_pattern(painter: &egui::Painter, rect: Rect, source: Source, crop: Crop) {
|
/// Reveal only the usable input discarded by the layer crop, behind other layers.
|
||||||
|
pub(super) fn paint_content_overflow(
|
||||||
|
painter: &egui::Painter,
|
||||||
|
rect: Rect,
|
||||||
|
source: Source,
|
||||||
|
crop: Crop,
|
||||||
|
) {
|
||||||
let Ok(input) = source.input() else {
|
let Ok(input) = source.input() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -276,8 +282,45 @@ pub(super) fn paint_pattern(painter: &egui::Painter, rect: Rect, source: Source,
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let k = rect.width() as f64 / retained[0];
|
let k = rect.width() as f64 / retained[0];
|
||||||
let p = painter.with_clip_rect(painter.clip_rect().intersect(rect));
|
let full = Rect::from_min_size(
|
||||||
p.rect_filled(rect, 0.0, Color32::from_rgb(24, 43, 58));
|
rect.min - Vec2::new((crop.left * k) as f32, (crop.top * k) as f32),
|
||||||
|
Vec2::new((input[0] * k) as f32, (input[1] * k) as f32),
|
||||||
|
);
|
||||||
|
// 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())),
|
||||||
|
] {
|
||||||
|
let clip = clip.intersect(painter.clip_rect());
|
||||||
|
if clip.is_positive() {
|
||||||
|
let mut ghost = painter.with_clip_rect(clip);
|
||||||
|
ghost.multiply_opacity(0.5);
|
||||||
|
paint_pattern_clipped(&ghost, rect, source, crop, clip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn paint_pattern(painter: &egui::Painter, rect: Rect, source: Source, crop: Crop) {
|
||||||
|
paint_pattern_clipped(painter, rect, source, crop, rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn paint_pattern_clipped(
|
||||||
|
painter: &egui::Painter,
|
||||||
|
rect: Rect,
|
||||||
|
source: Source,
|
||||||
|
crop: Crop,
|
||||||
|
clip: Rect,
|
||||||
|
) {
|
||||||
|
let Ok(input) = source.input() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let Ok(retained) = crop.remaining(input) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let k = rect.width() as f64 / retained[0];
|
||||||
|
let p = painter.with_clip_rect(painter.clip_rect().intersect(clip));
|
||||||
let point = |x: f64, y: f64| {
|
let point = |x: f64, y: f64| {
|
||||||
rect.min
|
rect.min
|
||||||
+ Vec2::new(
|
+ Vec2::new(
|
||||||
|
|
@ -296,7 +339,7 @@ pub(super) fn paint_pattern(painter: &egui::Painter, rect: Rect, source: Source,
|
||||||
y + source.native[1] as f64 / 6.0,
|
y + source.native[1] as f64 / 6.0,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if !cell.intersects(rect) {
|
if !cell.intersects(clip) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
p.rect_filled(
|
p.rect_filled(
|
||||||
|
|
|
||||||
|
|
@ -1179,6 +1179,21 @@ impl Editor {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if self.edit_content
|
||||||
|
&& let Some(i) = self.layout.selected()
|
||||||
|
{
|
||||||
|
let g = self.layout.layers()[i];
|
||||||
|
let rect = Rect::from_min_size(
|
||||||
|
origin + Vec2::new(g.x as f32, g.y as f32) * scale,
|
||||||
|
Vec2::new(g.width as f32, g.height as f32) * scale,
|
||||||
|
);
|
||||||
|
format_ui::paint_content_overflow(
|
||||||
|
&screen.painter,
|
||||||
|
rect,
|
||||||
|
self.layout.formats().sources[self.layout.formats().source_for[i]],
|
||||||
|
self.layout.formats().advanced[i],
|
||||||
|
);
|
||||||
|
}
|
||||||
for (i, g) in self.layout.layers().iter().enumerate() {
|
for (i, g) in self.layout.layers().iter().enumerate() {
|
||||||
if !self.layout.visible(i) {
|
if !self.layout.visible(i) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,9 @@ framing**:
|
||||||
Drags clamp at valid crop boundaries; Escape cancels a drag and leaves this
|
Drags clamp at valid crop boundaries; Escape cancels a drag and leaves this
|
||||||
mode. Wheel zoom still controls the camera. A source-coordinate test pattern
|
mode. Wheel zoom still controls the camera. A source-coordinate test pattern
|
||||||
illustrates framing; it is deliberately separate from the screen reference.
|
illustrates framing; it is deliberately separate from the screen reference.
|
||||||
|
While editing, cropped-out content appears at 50% opacity outside the box,
|
||||||
|
behind other layers. This preview stops at the usable input boundary; input
|
||||||
|
cropping remains excluded. The content inside the box stays fully opaque.
|
||||||
|
|
||||||
Sources shared by both layers share the input crop. The dialog names affected
|
Sources shared by both layers share the input crop. The dialog names affected
|
||||||
layers; each keeps its independent layer crop. Shared changes undo atomically,
|
layers; each keeps its independent layer crop. Shared changes undo atomically,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue