mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Merge pull request #10282 from storytold/fix/vectorcraft-0251-zoom-freehand
Restore selected Zoom gestures and keep freehand strokes stationary at canvas edges
This commit is contained in:
4 files changed
+77
-6
No files matched your search
@@ -140,6 +140,7 @@ impl VectorcraftApp {
|
||||
text_nodes: Default::default(),
|
||||
momentary: None,
|
||||
hand: None,
|
||||
zoom_tool: None,
|
||||
selection_box: None,
|
||||
selection_bounds: None,
|
||||
selection_marks: None,
|
||||
|
||||
@@ -82,6 +82,8 @@ pub struct CanvasCache {
|
||||
/// passes; the tool adapter takes it out for its call and puts it back.
|
||||
pub momentary: Option<craft::ui::canvas::Momentary>,
|
||||
pub hand: Option<craft::ui::canvas::HandTool>,
|
||||
/// The selected Zoom tool keeps its press and drag rectangle between canvas passes.
|
||||
pub zoom_tool: Option<craft::ui::canvas::ZoomTool>,
|
||||
/// [`VectorcraftApp::selection_box`] for (document uid, revision, Use Preview Bounds and
|
||||
/// Measure Type by Glyph Bounds).
|
||||
pub selection_box: Option<((u64, u64, vectorcraft_effects::preview::Measure), Option<vectorcraft_doc::OrientedBox>)>,
|
||||
|
||||
@@ -139,3 +139,57 @@ fn a_hand_drag_held_near_the_edge_does_not_scroll_on() {
|
||||
assert_eq!(center(&app), c0);
|
||||
frame(&mut app, &ctx, vec![button(edge, false)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_freehand_stroke_at_the_edge_keeps_the_artwork_stationary() {
|
||||
let (mut app, ctx, original) = zoomed_in("pencil");
|
||||
let rect = app.canvas_view().unwrap().rect;
|
||||
let start = rect.center() - vec2(120.0, 60.0);
|
||||
let edge = pos2(rect.right() - 2.0, start.y + 40.0);
|
||||
let initial = center(&app);
|
||||
let nodes = |app: &VectorcraftApp| {
|
||||
let mut count = 0;
|
||||
app.session.active().unwrap().doc.walk(|_| count += 1);
|
||||
count
|
||||
};
|
||||
let before = nodes(&app);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(start), button(start, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(start + vec2(15.0, 25.0))]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(edge)]);
|
||||
for _ in 0..5 {
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert_eq!(center(&app), initial);
|
||||
}
|
||||
frame(&mut app, &ctx, vec![button(edge, false)]);
|
||||
assert!(nodes(&app) > before, "the pencil drew a new path");
|
||||
assert!(app.session.active().unwrap().doc.node(original).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_zoom_tool_clicks_option_clicks_and_drags_a_marquee() {
|
||||
let (mut app, ctx, _) = zoomed_in("zoom");
|
||||
app.session.prefs.animated_zoom = false;
|
||||
let rect = app.canvas_view().unwrap().rect;
|
||||
let position = rect.center();
|
||||
let zoom = |app: &VectorcraftApp| app.view().unwrap().zoom;
|
||||
let initial = zoom(&app);
|
||||
for pressed in [true, false] {
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(position), button(position, pressed)]);
|
||||
}
|
||||
let enlarged = zoom(&app);
|
||||
assert!(enlarged > initial, "click should zoom in: {initial} -> {enlarged}");
|
||||
let modifiers = egui::Modifiers::ALT;
|
||||
for pressed in [true, false] {
|
||||
let event = egui::Event::PointerButton { pos: position, button: egui::PointerButton::Primary, pressed, modifiers };
|
||||
frame(&mut app, &ctx, vec![egui::Event::ModifiersChanged(modifiers), event]);
|
||||
}
|
||||
frame(&mut app, &ctx, vec![egui::Event::ModifiersChanged(egui::Modifiers::NONE)]);
|
||||
let reduced = zoom(&app);
|
||||
assert!(reduced < enlarged, "Option-click should zoom out: {enlarged} -> {reduced}");
|
||||
let start = position - vec2(90.0, 65.0);
|
||||
let end = position + vec2(80.0, 55.0);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(start), button(start, true)]);
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(end)]);
|
||||
frame(&mut app, &ctx, vec![button(end, false)]);
|
||||
assert!(zoom(&app) > reduced, "the marquee should fit its region to the view");
|
||||
}
|
||||
@@ -590,7 +590,9 @@ impl CanvasTool for SessionTool<'_> {
|
||||
}
|
||||
|
||||
fn autoscrolls(&self) -> bool {
|
||||
!self.carrying.get() && !self.view_only()
|
||||
// Sampled freehand tools trace the pointer on the artwork. Scrolling
|
||||
// under a held pen would extend the stroke without another sample.
|
||||
!self.carrying.get() && !self.view_only() && !self.app().session.tool_wants_samples()
|
||||
}
|
||||
|
||||
fn view_only(&self) -> bool {
|
||||
@@ -651,18 +653,30 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too
|
||||
let mut picked = ToolHostResponse::default();
|
||||
let mut response = if crate::dialogs::recolor::edit_tab::with_theme_pick(app, |app, tool| picked = host_run(app, ui, pass, tool)) {
|
||||
picked
|
||||
} else if app.session.tool_id() == "hand" && app.ui.screen_mode != 3 && app.ui.rearrange_placement.is_none() {
|
||||
} else if matches!(app.session.tool_id(), "hand" | "zoom") && app.ui.screen_mode != 3 && app.ui.rearrange_placement.is_none() {
|
||||
let options = crate::app::view::navigation(&app.session.prefs);
|
||||
let mut hand = app.canvas.hand.take().unwrap_or_else(|| craft::ui::canvas::HandTool::new(options));
|
||||
hand.options = options;
|
||||
let response = host_run(app, ui, pass, &mut hand);
|
||||
let response = if app.session.tool_id() == "zoom" {
|
||||
app.canvas.hand = None;
|
||||
let mut zoom = app.canvas.zoom_tool.take().unwrap_or_else(|| craft::ui::canvas::ZoomTool::new(options));
|
||||
zoom.options = options;
|
||||
let response = host_run(app, ui, pass, &mut zoom);
|
||||
app.canvas.zoom_tool = Some(zoom);
|
||||
response
|
||||
} else {
|
||||
app.canvas.zoom_tool = None;
|
||||
let mut hand = app.canvas.hand.take().unwrap_or_else(|| craft::ui::canvas::HandTool::new(options));
|
||||
hand.options = options;
|
||||
let response = host_run(app, ui, pass, &mut hand);
|
||||
app.canvas.hand = Some(hand);
|
||||
response
|
||||
};
|
||||
if response.gesture.is_some() && !view_tool_held(app) && ui.input(|i| i.pointer.primary_down() || i.pointer.primary_pressed()) {
|
||||
crate::shortcuts::note_tool_use(app);
|
||||
}
|
||||
app.canvas.hand = Some(hand);
|
||||
response
|
||||
} else {
|
||||
app.canvas.hand = None;
|
||||
app.canvas.zoom_tool = None;
|
||||
let mut tool = SessionTool::new(app, view_info, ui);
|
||||
let response = host_run_session(&mut tool, ui, pass);
|
||||
drop(tool);
|
||||
|
||||
Reference in new issue
Block a user