mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 17:37:14 +00:00
commit
2d14c7ceb7
2 files changed
+36
-8
No files matched your search
@@ -233,6 +233,21 @@ mod tests {
|
||||
assert_eq!(frame_angle([0.0, 0.0], [f64::INFINITY, 1.0], 1.0), None);
|
||||
}
|
||||
|
||||
/// A straighten is one box Undo step (#3145): Undo turns the frame back instead of undoing the
|
||||
/// document under the pending crop, and Redo turns it again.
|
||||
#[test]
|
||||
fn straighten_is_a_box_undo_step() {
|
||||
let mut app = app(SampleType::U8);
|
||||
let before = (app.ui.crop_rect, app.ui.crop_angle);
|
||||
drag(&mut app, &[[0.0, 0.0], [100.0, 17.6]], CMD);
|
||||
let turned = (app.ui.crop_rect, app.ui.crop_angle);
|
||||
assert!(turned.1.abs() > 5.0, "{turned:?}");
|
||||
assert!(crate::crop_ui::intercept(&mut app, "edit.undo").is_some(), "Undo steps the box");
|
||||
assert_eq!((app.ui.crop_rect, app.ui.crop_angle), before);
|
||||
assert!(crate::crop_ui::intercept(&mut app, "edit.redo").is_some());
|
||||
assert_eq!((app.ui.crop_rect, app.ui.crop_angle), turned);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_angle_readout_never_shows_minus_zero_or_minus_180() {
|
||||
use crate::canvas::angle_readout;
|
||||
|
||||
@@ -708,9 +708,17 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
|
||||
if crate::crop_straighten::pointer(app, ev, mods) {
|
||||
claim(app);
|
||||
// Default mode: the image turns so the line ends up level (the press keeps its point).
|
||||
// The turn is one box Undo step, like any other frame gesture.
|
||||
match ev {
|
||||
ToolEvent::Down { .. } => crate::crop_mode::sync(app, Some(p)),
|
||||
_ => crate::crop_mode::sync_frame(app),
|
||||
ToolEvent::Down { .. } => {
|
||||
app.crop.press_step = Some(step_of(app));
|
||||
crate::crop_mode::sync(app, Some(p));
|
||||
}
|
||||
ToolEvent::Move { .. } => crate::crop_mode::sync_frame(app),
|
||||
ToolEvent::Up { .. } => {
|
||||
crate::crop_mode::sync_frame(app);
|
||||
push_press_step(app);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -776,18 +784,23 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let Some(before) = app.crop.press_step.take()
|
||||
&& step_of(app) != before
|
||||
{
|
||||
app.crop.undo.push(before);
|
||||
app.crop.redo.clear();
|
||||
}
|
||||
push_press_step(app);
|
||||
}
|
||||
}
|
||||
crate::crop_mode::sync_frame(app);
|
||||
true
|
||||
}
|
||||
|
||||
/// On release: the frame state at the press becomes a box Undo step when the gesture changed it.
|
||||
fn push_press_step(app: &mut PhotocraftApp) {
|
||||
if let Some(before) = app.crop.press_step.take()
|
||||
&& step_of(app) != before
|
||||
{
|
||||
app.crop.undo.push(before);
|
||||
app.crop.redo.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// The frame follows the pointer at `p`.
|
||||
fn update(app: &mut PhotocraftApp, p: [f64; 2], mods: Modifiers) {
|
||||
let ratio = preset_ratio(app);
|
||||
|
||||
Reference in new issue
Block a user