mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 02:03:02 +00:00
Merge pull request #8500 from dotCooCoo/feat/bristle-pen-cursor
Paintbrush: preview Bristle tip for rotation-capable pens
This commit is contained in:
@@ -37,7 +37,7 @@ use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_brush::{Calligraphic, Variation};
|
||||
use vectorcraft_brush::{BristleShape, BrushKind, Calligraphic, Variation};
|
||||
use vectorcraft_doc::{NodeId, NodeKind};
|
||||
use vectorcraft_geom::{Affine, BezPath, FillRule, ParamCurve, PathData, PathSeg, Point, Rect, Vec2, shapes};
|
||||
use vectorcraft_pathops as po;
|
||||
@@ -200,6 +200,12 @@ pub struct GestureTool {
|
||||
/// Where the Blob Brush's or the Eraser's tip outline shows: the pointer over the canvas,
|
||||
/// unless Cmd/Ctrl lends a selection tool or Alt the Smooth tool.
|
||||
tip_at: Option<Point>,
|
||||
/// Alt as it was at the last pointer event; the release can select a new path after the tool
|
||||
/// returns, so the Bristle tip checks the current selection when overlays are drawn.
|
||||
tip_alt: bool,
|
||||
/// The last rotation-capable pen over the Paintbrush's Bristle tip; a mouse or a pen without
|
||||
/// barrel rotation has no tip annotator.
|
||||
bristle_pen: Option<(PenPose, f64)>,
|
||||
/// A pen pressed less than fully at a point of the stroke whose pressure is kept.
|
||||
light: bool,
|
||||
/// Which way the pen leaned at the last point of the stroke where it leaned 1° or more from
|
||||
@@ -899,6 +905,8 @@ impl GestureTool {
|
||||
snap: DrawSnap::default(),
|
||||
pressed: Point::ZERO,
|
||||
tip_at: None,
|
||||
tip_alt: false,
|
||||
bristle_pen: None,
|
||||
light: false,
|
||||
bearing: None,
|
||||
bearings: vec![],
|
||||
@@ -1088,12 +1096,50 @@ impl GestureTool {
|
||||
p
|
||||
}
|
||||
|
||||
fn pointer_tip(&mut self, cx: &ToolContext, ev: &PointerEvent) {
|
||||
if self.varies_size() {
|
||||
self.tip_at = (!ev.mods.cmd && !self.blob_alt_smooths(ev.mods)).then_some(ev.pos);
|
||||
} else if self.id == "paintbrush" {
|
||||
self.tip_alt = ev.mods.alt;
|
||||
self.bristle_pen =
|
||||
ev.pen.filter(|pen| pen.rotation.is_some()).map(|pen| (pen, if ev.kind == PointerKind::Move { 0.5 } else { f64::from(ev.pressure) }));
|
||||
let borrows_smooth = !self.active && ev.mods.alt && has_selected_smooth_path(cx);
|
||||
self.tip_at = self.bristle_pen.filter(|_| !ev.mods.cmd && !borrows_smooth).map(|_| ev.pos);
|
||||
}
|
||||
}
|
||||
|
||||
/// The Blob Brush's or the Eraser's tip at the pointer, before and while painting: its outline
|
||||
/// `size` across at its angle and roundness (the Eraser's as the pen varies them while it
|
||||
/// erases, [`Self::tip_now`]), at the zoom, black on a white halo so it reads on
|
||||
/// any art. Precise cursors show only the crosshair, and smoothing shows no tip.
|
||||
fn tip_outline(&self, cx: &ToolContext) -> Vec<Overlay> {
|
||||
let Some(at) = self.tip_at.filter(|_| !self.smoothing && !cx.precise_cursors) else { return vec![] };
|
||||
if self.id == "paintbrush" {
|
||||
if !self.active && self.tip_alt && has_selected_smooth_path(cx) {
|
||||
return vec![];
|
||||
}
|
||||
let Some((pose, pressure)) = self.bristle_pen else { return vec![] };
|
||||
let Some(name) = vectorcraft_brush::current(cx.doc) else { return vec![] };
|
||||
let Some(brush) = vectorcraft_brush::find(cx.doc, &name) else { return vec![] };
|
||||
let BrushKind::Bristle(bristle) = brush.kind else { return vec![] };
|
||||
let [pressure, tilt, bearing, rotation] = super::pen_controls(pressure, Some(pose), super::pen_bearing(pose));
|
||||
let size = bristle.size.max(0.1) * cx.paint.stroke_width.max(0.0) * (0.5 + pressure) * (1.25 - 0.5 * tilt);
|
||||
if size <= 0.0 {
|
||||
return vec![];
|
||||
}
|
||||
let roundness = match bristle.shape {
|
||||
BristleShape::RoundFan | BristleShape::FlatFan => 0.25,
|
||||
BristleShape::FlatPoint | BristleShape::FlatBlunt | BristleShape::FlatCurve | BristleShape::FlatAngle => 0.45,
|
||||
_ => 0.8,
|
||||
};
|
||||
let angle = std::f64::consts::TAU * (bearing + rotation - 1.0);
|
||||
let circle = kurbo::Shape::to_path(&kurbo::Circle::new(Point::ORIGIN, size / 2.0), size.max(0.1) * 0.05);
|
||||
let path = Affine::translate(at.to_vec2()) * Affine::rotate(-angle) * Affine::scale_non_uniform(1.0, roundness) * circle;
|
||||
return vec![
|
||||
Overlay::Path { path: path.clone(), color: [0xff, 0xff, 0xff], width: 3.0, dashed: false },
|
||||
Overlay::Path { path, color: [0, 0, 0], width: 1.0, dashed: false },
|
||||
];
|
||||
}
|
||||
let [angle, roundness, size] = self.tip_now();
|
||||
let tip = if self.id == "blobBrush" { blob_tip(angle, roundness) } else { eraser_tip(angle, roundness) };
|
||||
let r = size / 2.0;
|
||||
@@ -1587,9 +1633,7 @@ impl Tool for GestureTool {
|
||||
}
|
||||
fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {
|
||||
let p = ev.pos;
|
||||
if self.varies_size() {
|
||||
self.tip_at = (!ev.mods.cmd && !self.blob_alt_smooths(ev.mods)).then_some(p);
|
||||
}
|
||||
self.pointer_tip(cx, ev);
|
||||
if let Some(out) = self.marquee_pointer(cx, ev) {
|
||||
return out;
|
||||
}
|
||||
@@ -1762,6 +1806,10 @@ impl Tool for GestureTool {
|
||||
self.close_to = None;
|
||||
self.connect_to.clear();
|
||||
self.redraw = None;
|
||||
if self.id == "paintbrush" {
|
||||
// The release can change a drawing stroke into an Alt-borrowed Smooth hover.
|
||||
self.pointer_tip(cx, ev);
|
||||
}
|
||||
out
|
||||
}
|
||||
_ => vec![],
|
||||
|
||||
@@ -3043,6 +3043,103 @@ fn the_blob_brush_and_the_eraser_show_their_tip_at_the_pointer() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A rotation-capable pen shows the current Bristle brush's tip before and during a Paintbrush
|
||||
/// stroke. A mouse, a pen without rotation, precise cursors and a borrowed selection tool do not.
|
||||
#[test]
|
||||
fn bristle_tip_annotator_follows_a_rotation_capable_pen() {
|
||||
let (mut d, id) = doc_with_rect();
|
||||
d.unknown.insert(vectorcraft_brush::CURRENT_KEY.into(), json!("Bristle Flat Fan"));
|
||||
let s = Selection::default();
|
||||
let p = paint();
|
||||
let view = cx(&d, &s, &p);
|
||||
let bounds = |t: &GestureTool, cx: &ToolContext| {
|
||||
let overlays = t.overlays(cx);
|
||||
let Some(Overlay::Path { path, color: [0, 0, 0], width: 1.0, .. }) = overlays.last() else { return None };
|
||||
assert!(matches!(overlays.get(overlays.len() - 2), Some(Overlay::Path { color: [0xff, 0xff, 0xff], width: 3.0, .. })));
|
||||
Some(vectorcraft_geom::Shape::bounding_box(path))
|
||||
};
|
||||
let mut tool = GestureTool::new("paintbrush");
|
||||
let at =
|
||||
|rotation| PointerEvent { pen: Some(PenPose { tilt: Some([30.0, 0.0]), rotation }), ..PointerEvent::new(PointerKind::Move, 100.0, 50.0) };
|
||||
assert!(bounds(&tool, &view).is_none());
|
||||
tool.pointer(&view, &PointerEvent::new(PointerKind::Move, 100.0, 50.0));
|
||||
assert!(bounds(&tool, &view).is_none(), "mouse");
|
||||
tool.pointer(&view, &at(None));
|
||||
assert!(bounds(&tool, &view).is_none(), "pen without rotation");
|
||||
tool.pointer(&view, &at(Some(0.0)));
|
||||
let horizontal = bounds(&tool, &view).expect("rotating pen shows a tip");
|
||||
let mut selected = Selection::default();
|
||||
selected.set([id]);
|
||||
let selected_view = cx(&d, &selected, &p);
|
||||
tool.pointer(&selected_view, &at(Some(0.0)).with_mods(Mods { alt: true, ..Default::default() }));
|
||||
assert!(bounds(&tool, &selected_view).is_none(), "Alt borrows Smooth for a selected path");
|
||||
tool.pointer(&view, &at(Some(0.0)));
|
||||
let mut wider_paint = p.clone();
|
||||
wider_paint.stroke_width = 10.0;
|
||||
let wider_view = cx(&d, &s, &wider_paint);
|
||||
let wider = bounds(&tool, &wider_view).expect("stroke width scales the tip");
|
||||
assert!((wider.width() - horizontal.width() * 10.0).abs() < 1e-6, "{horizontal:?}, {wider:?}");
|
||||
wider_paint.stroke_width = 0.0;
|
||||
assert!(bounds(&tool, &cx(&d, &s, &wider_paint)).is_none(), "a zero-width stroke has no tip");
|
||||
tool.pointer(&view, &at(Some(90.0)));
|
||||
let vertical = bounds(&tool, &view).expect("tip turns with the barrel");
|
||||
assert!(horizontal.width() > horizontal.height() * 2.0, "{horizontal:?}");
|
||||
assert!(vertical.height() > vertical.width() * 2.0, "{vertical:?}");
|
||||
let mut light = at(Some(0.0));
|
||||
light.kind = PointerKind::Down;
|
||||
light.pressure = 0.1;
|
||||
tool.pointer(&view, &light);
|
||||
let light_tip = bounds(&tool, &view).expect("light pressure shows a smaller tip");
|
||||
let mut heavy = light;
|
||||
heavy.kind = PointerKind::Drag;
|
||||
heavy.pressure = 0.9;
|
||||
tool.pointer(&view, &heavy);
|
||||
let heavy_tip = bounds(&tool, &view).expect("heavy pressure shows a larger tip");
|
||||
assert!(heavy_tip.width() > light_tip.width() * 1.5, "{light_tip:?}, {heavy_tip:?}");
|
||||
let mut release = heavy;
|
||||
release.kind = PointerKind::Up;
|
||||
tool.pointer(&view, &release);
|
||||
let mut alt_stroke = light;
|
||||
alt_stroke.pressure = 0.5;
|
||||
tool.pointer(&selected_view, &alt_stroke);
|
||||
alt_stroke.kind = PointerKind::Drag;
|
||||
alt_stroke.mods.alt = true;
|
||||
tool.pointer(&selected_view, &alt_stroke);
|
||||
assert!(bounds(&tool, &selected_view).is_some(), "Alt during a drawing stroke keeps the tip");
|
||||
alt_stroke.kind = PointerKind::Up;
|
||||
tool.pointer(&selected_view, &alt_stroke);
|
||||
assert_eq!(tool.cursor(&selected_view, alt_stroke.pos, alt_stroke.mods), Cursor::Smooth);
|
||||
assert!(bounds(&tool, &selected_view).is_none(), "Alt release borrows Smooth without a stale tip");
|
||||
// A completed stroke can select its new path after `pointer` returns its actions. The overlay
|
||||
// must use that current selection even without a further pointer move.
|
||||
let mut newly_selected = GestureTool::new("paintbrush");
|
||||
let mut new_stroke = light;
|
||||
newly_selected.pointer(&view, &new_stroke);
|
||||
new_stroke.kind = PointerKind::Drag;
|
||||
new_stroke.mods.alt = true;
|
||||
newly_selected.pointer(&view, &new_stroke);
|
||||
new_stroke.kind = PointerKind::Up;
|
||||
newly_selected.pointer(&view, &new_stroke);
|
||||
assert!(bounds(&newly_selected, &view).is_some(), "no selected path borrows Smooth yet");
|
||||
assert_eq!(newly_selected.cursor(&selected_view, new_stroke.pos, new_stroke.mods), Cursor::Smooth);
|
||||
assert!(bounds(&newly_selected, &selected_view).is_none(), "post-commit selection also hides the tip");
|
||||
tool.pointer(&view, &at(Some(0.0)));
|
||||
assert!(bounds(&tool, &view).is_some(), "a normal pen hover shows the tip before Precise Cursors hides it");
|
||||
let precise = ToolContext { precise_cursors: true, ..cx(&d, &s, &p) };
|
||||
assert!(bounds(&tool, &precise).is_none());
|
||||
tool.pointer(&view, &at(Some(0.0)).with_mods(Mods { cmd: true, ..Default::default() }));
|
||||
assert!(bounds(&tool, &view).is_none(), "selection tool borrowed by Cmd");
|
||||
tool.pointer(&view, &at(Some(0.0)));
|
||||
tool.hover_ended(&view);
|
||||
assert!(bounds(&tool, &view).is_none(), "leaving the canvas");
|
||||
|
||||
let (mut d, _) = doc_with_rect();
|
||||
d.unknown.insert(vectorcraft_brush::CURRENT_KEY.into(), json!("3 pt. Round"));
|
||||
let calligraphic = cx(&d, &s, &p);
|
||||
tool.pointer(&calligraphic, &at(Some(0.0)));
|
||||
assert!(bounds(&tool, &calligraphic).is_none(), "other brush types keep their cursor");
|
||||
}
|
||||
|
||||
/// Eraser Tool Options' Angle, Roundness and Size variation menus: the Eraser keeps each mode and
|
||||
/// Variation, the release sends them with the pen's readings along the drag, and while it erases
|
||||
/// its tip outline at the pointer takes the angle, roundness and size the pen gives there. The Blob
|
||||
|
||||
@@ -16,6 +16,8 @@ pub(super) struct HoverContext {
|
||||
pub(super) center: Point,
|
||||
pub(super) zoom: f64,
|
||||
pub(super) rotation: f64,
|
||||
/// A pen turning in place changes a Bristle tip even when its pointer stays still.
|
||||
pub(super) pen: Option<PenPose>,
|
||||
/// The active document's id and revision (which moves with every edit, undo and selection
|
||||
/// change).
|
||||
pub(super) doc: Option<(u64, u64)>,
|
||||
|
||||
@@ -12,6 +12,9 @@ use super::{Color32, Drag, Mods, Point, PointerEvent, PointerKind, Pos2, Shape,
|
||||
|
||||
/// Dispatch canvas pointer, keyboard and drop events through the active document view.
|
||||
pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Response, rect: egui::Rect) {
|
||||
if let Some(feed) = app.services.stylus.as_ref() {
|
||||
feed.bind_repaint(ui.ctx());
|
||||
}
|
||||
// A modal dialog takes the canvas's presses, finger taps, long touches and view navigation, from the frame it opens.
|
||||
let modal = crate::panel_docking::modal_open(app, ui.ctx());
|
||||
let (pointer, m, space, hover) = wheel_view(app, ui, resp, rect, modal);
|
||||
@@ -53,7 +56,7 @@ pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respo
|
||||
});
|
||||
// What a hover means besides where the pointer is on screen: the tool, the canvas, the view
|
||||
// (scrolled, zoomed or turned by the wheel, a gesture, keys or a command) and the document and
|
||||
// selection as they are (another tab, an edit, an undo). Under a still pointer, a tool switched
|
||||
// selection as they are (another tab, an edit, an undo), and the pen's orientation. Under a still pointer, a tool switched
|
||||
// to is hovered at once, and when the rest changes, a tool that asks for it
|
||||
// ([`Session::tool_wants_rehover`]) is hovered again where the pointer is.
|
||||
let context = HoverContext {
|
||||
@@ -62,13 +65,14 @@ pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respo
|
||||
center: v.center,
|
||||
zoom: v.zoom,
|
||||
rotation: v.rotation,
|
||||
pen: pen_pose(app, &xf),
|
||||
doc: app.session.active().map(|st| (st.uid, st.revision)),
|
||||
};
|
||||
let (tool_switched, context_changed) = ui.data_mut(|d| {
|
||||
let (tool_switched, context_changed, pen_changed) = ui.data_mut(|d| {
|
||||
let id = egui::Id::unique("canvas-hover-context");
|
||||
let prev = d.get_temp::<HoverContext>(id);
|
||||
d.insert_temp(id, context);
|
||||
prev.map_or((false, false), |prev| (prev.tool != context.tool, prev != context))
|
||||
prev.map_or((false, false, false), |prev| (prev.tool != context.tool, prev != context, prev.pen != context.pen))
|
||||
});
|
||||
|
||||
if app.ui.screen_mode == 3 && matches!(drag, None | Some(Drag::Present | Drag::Gesture)) {
|
||||
@@ -137,7 +141,12 @@ pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respo
|
||||
} else if let Some(p) = hover_tool
|
||||
// A press on an artboard's name starts no drag: the moves while it is held are not hover.
|
||||
&& !(pointer.primary_down() && ui.data(|d| d.get_temp::<(usize, bool)>(name_press_id()).is_some()))
|
||||
&& (pointer.is_moving() || mods_changed || !was_over || tool_switched || (context_changed && app.session.tool_wants_rehover()))
|
||||
&& (pointer.is_moving()
|
||||
|| mods_changed
|
||||
|| !was_over
|
||||
|| tool_switched
|
||||
|| (context_changed && app.session.tool_wants_rehover())
|
||||
|| (pen_changed && context.tool == "paintbrush"))
|
||||
{
|
||||
let ev = PointerEvent {
|
||||
kind: PointerKind::Move,
|
||||
@@ -145,7 +154,7 @@ pub(super) fn handle_input(app: &mut VectorcraftApp, ui: &Ui, resp: &egui::Respo
|
||||
mods: mods(m, space),
|
||||
backquote: ui.input(|i| i.key_down(egui::Key::Backtick)),
|
||||
pressure: 1.0,
|
||||
pen: None,
|
||||
pen: pen_pose(app, &xf),
|
||||
};
|
||||
dispatch(app, &ev, view);
|
||||
}
|
||||
|
||||
@@ -11482,6 +11482,46 @@ fn the_tip_brings_back_the_perspective_grid_tool_without_showing_the_grid() {
|
||||
assert!(!visible(&app), "the grid stays hidden");
|
||||
}
|
||||
|
||||
/// The native pen feed's barrel rotation reaches the Paintbrush during canvas hover, before any
|
||||
/// stroke begins. Turning the pen or replacing it with a mouse updates a still pointer too.
|
||||
#[test]
|
||||
fn bristle_pen_tip_reaches_the_canvas_before_a_press() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let feed = StylusFeed::default();
|
||||
app.services.stylus = Some(feed.clone());
|
||||
app.session.execute("file.new", &json!({"width": 800, "height": 600})).unwrap();
|
||||
app.session.execute("brush.setCurrent", &json!({"name": "Bristle Flat Fan"})).unwrap();
|
||||
app.select_tool("paintbrush");
|
||||
let ctx = egui::Context::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let at = app.canvas_rect.unwrap().center();
|
||||
let tip = |app: &mut VectorcraftApp| {
|
||||
app.session.overlays(app.view_info()).into_iter().find_map(|o| match o {
|
||||
vectorcraft_tools::Overlay::Path { path, color: [0, 0, 0], width: 1.0, .. } => Some(path.bounding_box()),
|
||||
_ => None,
|
||||
})
|
||||
};
|
||||
feed.set_sample(Some(crate::stylus::PenSample {
|
||||
pressure: 0.0,
|
||||
pose: PenPose { rotation: Some(0.0), ..Default::default() },
|
||||
..Default::default()
|
||||
}));
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]);
|
||||
let horizontal = tip(&mut app).expect("hovering pen shows its brush tip");
|
||||
assert!(horizontal.width() > horizontal.height() * 2.0, "{horizontal:?}");
|
||||
feed.set_sample(Some(crate::stylus::PenSample {
|
||||
pressure: 0.0,
|
||||
pose: PenPose { rotation: Some(90.0), ..Default::default() },
|
||||
..Default::default()
|
||||
}));
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let vertical = tip(&mut app).expect("turning a still pen turns its tip");
|
||||
assert!(vertical.height() > vertical.width() * 2.0, "{vertical:?}");
|
||||
feed.set(None);
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert!(tip(&mut app).is_none(), "a mouse clears a still pen's tip");
|
||||
}
|
||||
|
||||
/// #764: the pen's tilt and barrel rotation in the host's feed reach the Paintbrush's points,
|
||||
/// the tilt turned onto the page when the view is rotated; a mouse's points carry neither.
|
||||
#[test]
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
//! the tip selects the tool used before.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::{Arc, Condvar, Mutex, MutexGuard};
|
||||
use std::sync::{Arc, Condvar, Mutex, MutexGuard, OnceLock};
|
||||
use std::time::Duration;
|
||||
|
||||
pub use vectorcraft_tools::PenPose;
|
||||
@@ -82,6 +82,8 @@ impl Pen {
|
||||
#[derive(Default)]
|
||||
struct Shared {
|
||||
pen: Mutex<Pen>,
|
||||
/// Wake the canvas for a pen that turns without a new window pointer event.
|
||||
repaint: OnceLock<egui::Context>,
|
||||
/// Signaled on every [`StylusFeed::set_sample`] ([`StylusFeed::set`] included).
|
||||
set: Condvar,
|
||||
/// Written on the UI thread itself ([`StylusFeed::on_ui_thread`]): a press never waits.
|
||||
@@ -104,6 +106,10 @@ impl StylusFeed {
|
||||
self.0.pen.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
}
|
||||
|
||||
pub(crate) fn bind_repaint(&self, ctx: &egui::Context) {
|
||||
self.0.repaint.get_or_init(|| ctx.clone());
|
||||
}
|
||||
|
||||
/// A pen turned to its tip moved with `pressure`, or `None`: another pointer moved
|
||||
/// ([`Self::set_sample`]).
|
||||
pub fn set(&self, pressure: Option<f32>) {
|
||||
@@ -119,6 +125,7 @@ impl StylusFeed {
|
||||
let pressure = sample.map(|s| if s.pressure.is_finite() { s.pressure.clamp(0.0, 1.0) } else { 1.0 });
|
||||
let eraser = sample.is_some_and(|s| s.eraser);
|
||||
let mut pen = self.lock();
|
||||
let before_pose = pen.pose;
|
||||
if eraser != pen.eraser {
|
||||
*pen = Pen::default();
|
||||
}
|
||||
@@ -138,8 +145,12 @@ impl StylusFeed {
|
||||
}
|
||||
}
|
||||
pen.latest = pressure;
|
||||
let pose_changed = pen.pose != before_pose;
|
||||
drop(pen);
|
||||
self.0.set.notify_all();
|
||||
if pose_changed && let Some(ctx) = self.0.repaint.get() {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/// Like [`Self::set_sample`], for a pen sample that comes with one pointer move of the window,
|
||||
@@ -282,6 +293,30 @@ pub(crate) fn sync_eraser_tool(app: &mut VectorcraftApp) -> bool {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
#[test]
|
||||
fn changing_a_still_pens_pose_wakes_the_canvas() {
|
||||
let feed = StylusFeed::default();
|
||||
let ctx = egui::Context::default();
|
||||
let repaints = Arc::new(AtomicUsize::new(0));
|
||||
let count = repaints.clone();
|
||||
ctx.set_repaint_observer(move |_| {
|
||||
count.fetch_add(1, Ordering::Relaxed);
|
||||
});
|
||||
feed.bind_repaint(&ctx);
|
||||
let pose = PenPose { rotation: Some(0.0), ..Default::default() };
|
||||
let sample = PenSample { pressure: 0.0, pose, ..Default::default() };
|
||||
let writer = feed.clone();
|
||||
std::thread::spawn(move || writer.set_sample(Some(sample))).join().unwrap();
|
||||
assert_eq!(repaints.load(Ordering::Relaxed), 1);
|
||||
feed.set_sample(Some(sample));
|
||||
assert_eq!(repaints.load(Ordering::Relaxed), 1, "an unchanged pose needs no new frame");
|
||||
feed.set_sample(Some(PenSample { pose: PenPose { rotation: Some(90.0), ..pose }, ..sample }));
|
||||
assert_eq!(repaints.load(Ordering::Relaxed), 2);
|
||||
feed.set_sample(None);
|
||||
assert_eq!(repaints.load(Ordering::Relaxed), 3, "mouse input clears the tip");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_feed_keeps_the_last_pressure_within_0_to_1() {
|
||||
|
||||
@@ -1929,6 +1929,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
Scatter, Art and Pattern Brush Options have the Tips button for Colorization that the [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) page (archived copy) describes, beside Method. It opens Colorization Tips, which shows each method's name and what it does beside a sample of the brush, as OK would make it, painted with that method on a blue stroke; Hue Shift's sample uses the dialog's Key Color. `ui.dialog.set {field: "tips", value: true}` opens it. Screen readers name the button, the popover and each sample.
|
||||
Hue Shift set by `brush.new` or `brush.options` without a key color takes the color the art's fills and strokes use most, as Brush Options already offers it, following the Brushes page, where the key color defaults to the color that stands out most in the art (<https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html>). The page does not state how prominence is measured. Counting the fills and strokes that use each solid color, with the first one found winning a tie and black for art with no solid color, is VectorCraft's own rule. A `brush.options` edit that gives only the method keeps the brush's key color, and one that gives only an art brush's start guide keeps its end guide. Evidence: `tests_brushsym::hue_shift_without_a_key_takes_the_most_used_art_color`, `tests_brushsym::art_brush_options_keep_the_scale_fields_an_edit_leaves_out`.
|
||||
Bristle Brush Options and `brush.new` take a bristle brush name of at most 31 characters, as the Brushes page states for the Bristle Brush Options. The Name field stops taking characters at 31, and `brush.new` and `brush.options` refuse a longer new name with an error that names the limit. The page does not say how the limit counts characters or what happens to longer names already saved; counting characters and the number added to a taken name, keeping longer saved names, and leaving `brush.duplicate` unlimited are VectorCraft's own rules. A bristle brush that a document or a saved file already holds under a longer name keeps it, and the other brush types take a name of any length. Test: `bristle_brush_names_have_at_most_31_characters` in `tests/brushsym.rs`. Public reference: [Brushes](https://web.archive.org/web/20241230205225/https://helpx.adobe.com/illustrator/using/brushes.html) (archived copy).
|
||||
With a Bristle brush selected, the Paintbrush shows a tip outline at a rotation-capable pen's pointer: its width responds to pressure and the stroke weight, its long axis follows the pen's barrel rotation and bearing, and its aspect follows the selected tip shape. Mouse input and a pen without barrel rotation keep the regular Paintbrush cursor; Precise Cursors, the borrowed selection tool, smoothing and leaving the canvas hide the outline. This is VectorCraft's own approximate tip preview; the [Brushes guide](https://web.archive.org/web/20220911143322/https://helpx.adobe.com/pdf/cs6/illustrator_reference.pdf#page=189) documents when a Bristle brush tip cursor appears, but does not define its geometry or pressure mapping. Tests: `draw2::gesture::tests::bristle_tip_annotator_follows_a_rotation_capable_pen` (vectorcraft-tools) and `canvas::tests::bristle_pen_tip_reaches_the_canvas_before_a_press` (vectorcraft-ui-egui).
|
||||
In the Brushes panel, Shift-click selects a range of brushes and Ctrl/Cmd-click adds or removes one. Delete Brush and Duplicate Brush then act on all of them (`brush.delete {names}`, `brush.duplicate {names}`).
|
||||
The Brushes panel's Delete Brush button and panel menu item ask "Delete the selected brushes?" with Yes and No when none of the brushes is in use. Alt-click (Option-click on macOS) on the button deletes them without asking, as the [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists for panel deletion outside the Layers panel (archived copy). When a stroke uses one of the brushes, the button, Alt-click and the menu item all ask with Remove Strokes and Cancel; Remove Strokes deletes the brushes and the strokes that used them become plain strokes. Tests: `panels::brushes::tests`, `dialogs::brush_delete::tests`.
|
||||
Document Info has a Brushes category after Graphic Styles. It lists the names and types of the brushes applied to the artwork, as the [Document Info panel](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/document-info-panel.html) page describes, or with Selection Only the brushes that the selected objects' strokes use. The Document Info report and Package's report list them too (`document.info {category: "brushes"}`, `brushNames`, `brushes`). Listing each brush once, leaving out the Brushes panel's brushes no art uses (`panelBrushNames` lists the panel's brushes), hidden strokes, strokes at an opacity of 0, strokes with no paint or width, guides, paths with no segment, type that draws no characters, a group's or layer's own strokes, a compound path member's own strokes and an image's strokes without a shape, and listing a brush the panel does not hold as missing, are VectorCraft's own rules. Tests: `cmd::docinfo::tests::info_lists_the_brushes` and `info_brushes_skip_undrawn_strokes_and_name_missing_brushes` (vectorcraft-engine).
|
||||
|
||||
Reference in New Issue
Block a user