mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 04:04:25 +00:00
Crop overlay: a crop that fills what a turn uncovers keeps the press frame; Content-Aware Fill sets it
This commit is contained in:
@@ -265,6 +265,9 @@ impl CropTool {
|
||||
if settings.delete_pixels {
|
||||
overlay = overlay.bounds(document.canvas());
|
||||
}
|
||||
if settings.fill == CropFill::ContentAware {
|
||||
overlay = overlay.fills_uncovered();
|
||||
}
|
||||
if settings.image_mode() {
|
||||
overlay = overlay.image_mode();
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ pub(super) struct Rules {
|
||||
pub turn_step: f64,
|
||||
pub image: bool,
|
||||
pub auto_center: bool,
|
||||
pub fills_uncovered: bool,
|
||||
/// The canvas's snapping, with this pass's tolerance.
|
||||
pub snap: Option<Snap>,
|
||||
pub os: Platform,
|
||||
@@ -122,9 +123,9 @@ impl Rules {
|
||||
match self.bounds.filter(|_| self.image) {
|
||||
// An image-mode turn keeps the frame inside the turned image (#10869), each step from the press
|
||||
// frame so turning back gives it back. ⌘ keeps the press frame, and so does a press frame that
|
||||
// was already past the bounds.
|
||||
// was already past the bounds, and a crop that fills what the turn uncovers.
|
||||
Some(bounds) => {
|
||||
let keeps_press = mods.cmd || at.kept_inside(bounds) != Some(at);
|
||||
let keeps_press = mods.cmd || self.fills_uncovered || at.kept_inside(bounds) != Some(at);
|
||||
let kept = if keeps_press { Some(turned) } else { turned.kept_inside(bounds) };
|
||||
return kept.filter(CropBox::is_finite).or(Some(drag.last));
|
||||
}
|
||||
|
||||
@@ -163,6 +163,10 @@ pub struct CropOverlay<'a> {
|
||||
/// middle of the canvas.
|
||||
#[prop(flag)]
|
||||
auto_center: bool,
|
||||
/// The crop fills what the turned image leaves uncovered (Content-Aware Fill), so an image-mode turn leaves the
|
||||
/// frame as it was at the press instead of moving or shrinking it inside the bounds.
|
||||
#[prop(flag)]
|
||||
fills_uncovered: bool,
|
||||
/// Nothing is painted and a press anywhere on the canvas draws a new frame.
|
||||
#[prop(flag)]
|
||||
hidden: bool,
|
||||
@@ -185,6 +189,7 @@ impl<'a> CropOverlay<'a> {
|
||||
bounds: None,
|
||||
image_mode: false,
|
||||
auto_center: false,
|
||||
fills_uncovered: false,
|
||||
hidden: false,
|
||||
report: Report::default(),
|
||||
}
|
||||
@@ -199,6 +204,7 @@ impl<'a> CropOverlay<'a> {
|
||||
turn_step: self.turn_step,
|
||||
image: self.image_mode,
|
||||
auto_center: self.auto_center,
|
||||
fills_uncovered: self.fills_uncovered,
|
||||
snap: canvas_snap(env),
|
||||
os: env.shell().os,
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ struct Setup {
|
||||
default_frame: bool,
|
||||
image_mode: bool,
|
||||
auto_center: bool,
|
||||
fills_uncovered: bool,
|
||||
hidden: bool,
|
||||
bounds: Option<Rect>,
|
||||
snap_x: Option<f64>,
|
||||
@@ -49,6 +50,7 @@ impl Setup {
|
||||
default_frame: false,
|
||||
image_mode: false,
|
||||
auto_center: false,
|
||||
fills_uncovered: false,
|
||||
hidden: false,
|
||||
bounds: None,
|
||||
snap_x: None,
|
||||
@@ -148,6 +150,9 @@ impl Rig {
|
||||
if s.straighten {
|
||||
overlay = overlay.straighten();
|
||||
}
|
||||
if s.fills_uncovered {
|
||||
overlay = overlay.fills_uncovered();
|
||||
}
|
||||
if s.hidden {
|
||||
overlay = overlay.hidden();
|
||||
}
|
||||
@@ -688,6 +693,18 @@ fn a_default_turn_keeps_the_frame_inside_the_turned_image() {
|
||||
assert_eq!(rig.rect(), past.rect, "the frame was past the image at the press");
|
||||
rig.release(end);
|
||||
|
||||
// A crop that fills what the turn uncovers keeps the press frame.
|
||||
let mut s = Setup::new();
|
||||
s.image_mode = true;
|
||||
s.bounds = Some(image);
|
||||
s.fills_uncovered = true;
|
||||
s.view = crop_view(&edge, &s.view);
|
||||
let mut rig = Rig::new(edge, s);
|
||||
let (_, end) = turn_by(&mut rig, &[10.0, 20.0], 120.0, Modifiers::NONE);
|
||||
assert!(rig.crop().angle.abs() > 1.0, "it turned: {:?}", rig.crop());
|
||||
assert_eq!(rig.rect(), edge.rect, "the fill covers what the turn uncovers");
|
||||
rig.release(end);
|
||||
|
||||
// A Classic Mode turn that would leave the image is refused: both steps leave it.
|
||||
let mut rig = rig_for(fits, false);
|
||||
let (_, end) = turn_by(&mut rig, &[30.0, 40.0], 140.0, Modifiers::NONE);
|
||||
|
||||
Reference in New Issue
Block a user