6.2 KiB
6.2 KiB
Plan: Brush Editor — Dynamics, Real Preview, Scrollable Panels
Goal
Extend the existing Krita-style brush editor in hcie-egui-app/crates/hcie-gui-egui/src/app/brush_editor.rs so it exposes real brush dynamics, shows an accurate engine-rendered preview, and keeps all dock panels scrollable by mouse wheel / pan without visible scrollbars.
Current State
- A basic brush editor modal exists with four categories: Brush Tip, Dynamics, Color, Texture.
BrushConfig(inhcie-protocol/src/tools.rs) exposes onlysize,opacity,hardness,flow,spacing,style,blend_mode,cyclic_color,cyclic_speed,color_variant,variant_amount,density.- Engine
BrushTipalready hasjitter_amount,scatter_amount,angle,roundness, but the GUI never sets them (canvas code hard-codes0.0/1.0). - Preview is procedural (
brushes_panel::draw_brush_preview) and does not reflect actual engine output. - Dock panels vary: some use
ScrollArea, some do not; scrollbars are visible.
Decisions
1. New brush dynamics fields
Add to hcie-protocol/src/tools.rs BrushConfig:
pub jitter_amount: f32,
pub scatter_amount: f32,
pub angle: f32,
pub roundness: f32,
pub drawing_angle: bool,
pub rotation_random: f32,
pub time_enabled: bool,
pub time_size_start: f32,
pub time_size_end: f32,
pub time_opacity_start: f32,
pub time_opacity_end: f32,
pub time_angle_start: f32,
pub time_angle_end: f32,
Defaults: 0.0, 0.0, 0.0, 1.0, false, 0.0, false, 1.0/1.0/1.0/1.0/0.0/0.0.
2. GUI controls
- Brush Tip panel: keep
Diameter,Hardness,Spacing,Style,Blend Mode; add Angle, Roundness, Drawing Angle checkbox, Rotation Random. - Dynamics panel: keep
Opacity,Flow,Pressure Curveplaceholder; add Jitter, Scatter. - Color panel: keep
Color Variant,Cyclic Color; add a Time subsection with checkbox and start/end sliders forsize,opacity,angle. - Every slider pairs with a right-aligned
DragValueso mouse users can click/type exact values. - Angles displayed and edited in degrees, stored in radians.
3. Engine wiring
hcie-egui-app/crates/hcie-gui-egui/src/canvas/mod.rs: when buildingBrushTip, copyjitter_amount,scatter_amount,angle(converted to radians),roundnessfromstate.tool_configs.brush.hcie-brush-engine/src/lib.rs: updategenerate_brush_stampand dab dispatchers so that:drawing_angle == trueoverridesanglewith the stroke segment direction.rotation_randomadds a per-dab random offset to the effective angle.roundnessscales the stamp along the effective angle (elliptical dab).
hcie-engine-api/src/stroke_brush.rs: applytime_*interpolation using accumulated stroke distance (brush_accumulated_dist) before passing size/opacity/angle to the dab functions. Reset at stroke start (begin_stroke).
4. Real preview
- Add
Engine::render_brush_preview(&self, width, height, tip, color, stroke_points) -> Vec<u8>inhcie-engine-api/src/lib.rs. - It creates a temporary 1-layer document, draws the supplied stroke points, composites, and returns RGBA pixels.
brush_editor.rscalls this on every significant parameter change (whenbrush_editor_instant_previewis true), caches the texture, and draws it in the preview area instead of the procedural function.- Guard with a small debounce to avoid 4K-preview cost.
5. Scrollable panels
- Create a helper
scrollable_panel(ui, id, contents)in a new filehcie-egui-app/crates/hcie-gui-egui/src/app/scrollable_panel.rs. - It wraps
egui::ScrollArea::vertical().always_show_scroll(false)and implements drag-to-pan by tracking pointer delta over the content rect when the left button is held and no widget is being dragged. - Apply the helper to every dock panel body:
brushes_panel::show_brushes_uipanels.rstool-property bodies (Tools, Layers, History, Properties, etc.)brush_editor.rsright-hand settings area
- Keep existing
ScrollAreacalls but switch them to the helper so behavior is consistent.
Affected Boundaries (Locked Crates)
The following crates are normally locked by hcie-guard; the implementation agent must run unlock.sh <crate>, edit, then lock.sh <crate>:
hcie-protocol/src/tools.rs—BrushConfigfieldshcie-engine-api/src/lib.rs— new public preview APIhcie-engine-api/src/stroke_brush.rs— time interpolationhcie-brush-engine/src/lib.rs— drawing angle / rotation / roundness behavior
GUI-only files (open to agent edits):
hcie-egui-app/crates/hcie-gui-egui/src/app/brush_editor.rshcie-egui-app/crates/hcie-gui-egui/src/app/brushes_panel.rshcie-egui-app/crates/hcie-gui-egui/src/app/panels.rshcie-egui-app/crates/hcie-gui-egui/src/app/mod.rshcie-egui-app/crates/hcie-gui-egui/src/canvas/mod.rs
Task Order
- Extend
BrushConfiginhcie-protocoland rebuild engine. - Implement engine preview API.
- Implement
drawing_angle,rotation_random,roundnessinhcie-brush-engine. - Implement time interpolation in
hcie-engine-api/src/stroke_brush.rs. - Wire new fields from GUI config to
BrushTipincanvas/mod.rs. - Extend
brush_editor.rsUI (new sliders, real preview, scrollable right panel). - Implement
scrollable_panelhelper and apply to all dock panels. - Run
cargo test -p hcie-engine-api --test visual_regressionandcargo test -p hcie-engine-api --test performance_stroke_4k. - Lock affected engine crates.
- Capture screenshots of brush editor and each scrollable panel.
Validation
- Visual regression tests (
visual_regression) must still pass. - Performance regression benchmark (
performance_stroke_4k) must not regress beyond 5%. - Brush editor preview updates within 200 ms of parameter change.
- All dock panels scroll by mouse wheel and pan-drag without visible scrollbars.
Risks
hcie-brush-engineangle/roundness changes can alter default brush appearance if defaults are wrong; test withvisual_regression.- Real preview allocates a temporary engine/document per frame; debounce/caching is mandatory.
- Locked crate modifications require
unlock.sh/lock.shand possible terminal password prompt.
Open Questions
- None remaining; user confirmed all decisions.