feat: add watercolor brush category with presets and splat renderer
- Implemented a new crate `hcie-watercolor-brushes` containing watercolor brush presets and a procedural splat preview renderer. - Integrated watercolor brushes into the iced GUI's Brushes panel, adding a new category for watercolor brushes. - Updated the `BrushCategory` enum to include `Watercolor` and modified the rendering logic to display watercolor presets. - Added functionality to generate watercolor splat thumbnails using a noise-based algorithm. - Ensured that existing brush styles and engine crates remain unmodified, adhering to project constraints.
This commit is contained in:
@@ -1,129 +1,180 @@
|
||||
# Plan: Build Increment Script + Vector Editing Improvements
|
||||
# Watercolor Brush Category — Implementation Plan
|
||||
|
||||
## Task 1: File Increment Script
|
||||
## Goal
|
||||
Add a new **Watercolor** brush category to the iced GUI's Brushes panel. Each brush has a watercolor-splat preview (not the standard sine-wave stroke). The brushes simulate realistic watercolor effects. Implemented as a new crate with zero modification to existing brush/engine crates.
|
||||
|
||||
**File:** `/mnt/extra/00_PROJECTS/hcie-rust-v3.05/build.id` (currently contains `990`)
|
||||
## Architecture Overview
|
||||
|
||||
A single robust bash command:
|
||||
### Existing brush flow
|
||||
1. `hcie-brush-engine` defines `BrushStyle` enum (33 variants including `Watercolor`) and `BrushPreset` struct
|
||||
2. `hcie-engine-api` re-exports `BrushPreset` and provides `draw_specialized_stroke` → dispatches to `draw_watercolor_brush` for `BrushStyle::Watercolor`
|
||||
3. `hcie-iced-gui/src/panels/brushes.rs` defines `BrushCategory` enum, `BRUSH_STYLES` static array, and `generate_brush_preview()` for thumbnails
|
||||
4. When a preset is selected → `Message::BrushPresetSelected(preset)` → sets `tool_state.brush_style`, `brush_size`, `brush_opacity`, `brush_hardness`, `brush_spacing`, `active_brush_preset`
|
||||
|
||||
```bash
|
||||
echo $(( $(cat /mnt/extra/00_PROJECTS/hcie-rust-v3.05/build.id) + 1 )) > /mnt/extra/00_PROJECTS/hcie-rust-v3.05/build.id
|
||||
```
|
||||
### Key constraint
|
||||
Engine crates (`hcie-brush-engine`, `hcie-protocol`, `hcie-engine-api`, `hcie-draw`) are **locked** — agents must not modify them. The new crate lives in the GUI layer and reuses the engine's existing `BrushStyle::Watercolor` rendering path.
|
||||
|
||||
Or as a reusable script at the project root:
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
# increment_build.sh — atomically increments the integer in build.id
|
||||
set -euo pipefail
|
||||
FILE="/mnt/extra/00_PROJECTS/hcie-rust-v3.05/build.id"
|
||||
CURRENT=$(cat "$FILE")
|
||||
NEXT=$(( CURRENT + 1 ))
|
||||
echo "$NEXT" > "$FILE"
|
||||
echo "build.id: $CURRENT -> $NEXT"
|
||||
```
|
||||
|
||||
**Edge cases handled:**
|
||||
- `set -euo pipefail` catches missing file, non-integer content, write failures
|
||||
- The `$(( ))` arithmetic is safe for unsigned integers
|
||||
- No temp file race: single echo redirect is atomic on Linux ext4 for small writes
|
||||
### New crate strategy
|
||||
- Define watercolor presets using existing `BrushPreset` (from `hcie-engine-api`) with `style: BrushStyle::Watercolor`
|
||||
- Provide a **watercolor splat preview renderer** that generates RGBA pixels for thumbnails
|
||||
- The brushes panel integrates the new crate's presets under a "Watercolor" category tab
|
||||
- Actual drawing uses the engine's existing watercolor brush rendering — no engine changes needed
|
||||
|
||||
---
|
||||
|
||||
## Task 2: Vector Editing Improvements
|
||||
## Step 1: Create the new crate `hcie-watercolor-brushes`
|
||||
|
||||
### Sub-task 2.1: Angular Snapping Visual Feedback
|
||||
**Path:** `hcie-iced-app/crates/hcie-watercolor-brushes/`
|
||||
|
||||
**Problem:** When Shift is held during rotation, the angle snaps to 15° increments but there is no visual confirmation — it looks like freehand drawing.
|
||||
### `Cargo.toml`
|
||||
```toml
|
||||
[package]
|
||||
name = "hcie-watercolor-brushes"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
**Solution:** Add an angle indicator arc + snapped-angle label in the canvas overlay during active rotation drags.
|
||||
|
||||
**Files:**
|
||||
- `hcie-iced-app/crates/hcie-iced-gui/src/canvas/mod.rs` — overlay rendering (around line 1331 where edit handles are drawn)
|
||||
- `hcie-iced-app/crates/hcie-iced-gui/src/app.rs` — store the current snapped angle and shift state during drag
|
||||
|
||||
**Implementation:**
|
||||
|
||||
1. **New state fields on `HcieIcedApp`** (in `app.rs`):
|
||||
```rust
|
||||
/// True while Shift is held during a rotation drag.
|
||||
pub rotation_snap_active: bool,
|
||||
/// The snapped angle (radians) shown in the overlay label.
|
||||
pub rotation_snap_angle: f32,
|
||||
```
|
||||
|
||||
2. **Update in `VectorSelectDragMove` handler** (in `app.rs`):
|
||||
After `transform_shape` returns, set:
|
||||
```rust
|
||||
self.rotation_snap_active = self.modifiers.shift();
|
||||
self.rotation_snap_angle = shape.angle();
|
||||
```
|
||||
|
||||
3. **Clear on drag end** (in `VectorSelectDragEnd`):
|
||||
```rust
|
||||
self.rotation_snap_active = false;
|
||||
```
|
||||
|
||||
4. **Render in overlay** (in `canvas/mod.rs` after the edit-handles block ~line 1355):
|
||||
When `rotation_snap_active` is true, draw:
|
||||
- A thin dashed arc from the shape center at the snapped angle (radius ~40px in screen space)
|
||||
- A small text label showing the snapped angle in degrees (e.g., "45°")
|
||||
- Use a distinctive color (e.g., cyan `iced::Color::from_rgba(0.0, 0.8, 1.0, 0.9)`)
|
||||
|
||||
5. **Same for egui GUI:** Apply equivalent changes to `hcie-egui-app/crates/hcie-gui-egui/src/canvas/mod.rs` (around the edit-handles overlay).
|
||||
|
||||
### Sub-task 2.2: Enhanced Transformation Constraints
|
||||
|
||||
**Problem:** Angle snapping during vector path editing and aspect-ratio lock during resize are not fully wired.
|
||||
|
||||
**Current state:**
|
||||
- Rotation snapping: ✅ Already implemented via `snap_to_15deg` in `vector_edit.rs` and applied in `transform_shape` when `snap_angle=true`.
|
||||
- Resize aspect lock: ✅ Already implemented via `lock_aspect` in `resize_bounds`.
|
||||
- Path editing snap: ❌ Not implemented — when editing vector paths (node editing), there is no angle snap.
|
||||
|
||||
**Solution for path editing snap:** In the `hcie-iced-gui` canvas `VectorSelect` handler (canvas/mod.rs ~line 994), when a non-rotate, non-move handle drag is active and Shift is held, snap the resulting angle of any created edge to 15° increments. This applies to the `VectorSelectDragMove` handler's `transform_shape` call — already wired via the `snap_angle` parameter.
|
||||
|
||||
**Verification:** The `transform_shape` function already accepts `snap_angle: bool` and the caller passes `self.modifiers.shift()`. For the Rotate handle, this snaps the angle. For resize handles, the aspect lock is via `lock_aspect` (also shift). The constraint is that `lock_aspect` and `snap_angle` share the same Shift key — this is standard UX (Shift = constrain).
|
||||
|
||||
**No code changes needed for sub-task 2.2** — it's already wired. Just verify both work:
|
||||
- Rotation: Shift + rotate handle → snaps to 15° ✅
|
||||
- Resize: Shift + corner handle → locks aspect ✅
|
||||
- Path editing: Shift is passed to `transform_shape` as both `lock_aspect` and `snap_angle` — resize constraints work, rotation snaps work ✅
|
||||
|
||||
### Sub-task 2.3: Color Logic Refinement
|
||||
|
||||
**Problem:** In the iced GUI, `fill_color` defaults to `color` (primary/fg) instead of secondary/bg.
|
||||
|
||||
**Evidence:**
|
||||
- `hcie-iced-app/crates/hcie-iced-gui/src/app.rs:5772`: `let fill_color = color;` where `color = self.fg_color`
|
||||
- `hcie-egui-app/crates/hcie-gui-egui/src/canvas/mod.rs:2184`: `let fill_color = state.secondary_color;` ← correct
|
||||
|
||||
**Fix:** In `app.rs` line 5772, change:
|
||||
```rust
|
||||
let fill_color = color;
|
||||
```
|
||||
to:
|
||||
```rust
|
||||
let fill_color = self.bg_color;
|
||||
[dependencies]
|
||||
hcie-engine-api = { path = "../../../hcie-engine-api" }
|
||||
```
|
||||
|
||||
**Files:**
|
||||
- `hcie-iced-app/crates/hcie-iced-gui/src/app.rs` — line 5772
|
||||
### `src/lib.rs` — Presets + Preview Renderer
|
||||
|
||||
Exports:
|
||||
- `pub fn watercolor_presets() -> Vec<BrushPreset>` — returns 8 watercolor brush presets
|
||||
- `pub fn render_watercolor_splat(style: BrushStyle, base_color: [u8; 3]) -> Vec<u8>` — generates 64×64 RGBA watercolor splat preview
|
||||
|
||||
#### Presets (8 brushes)
|
||||
| ID | Name | Size | Opacity | Hardness | Spacing | Description |
|
||||
|----|------|------|---------|----------|---------|-------------|
|
||||
| `wc_wash` | Watercolor Wash | 80 | 0.25 | 0.0 | 0.08 | Large, transparent wash |
|
||||
| `wc_wet` | Wet Watercolor | 60 | 0.35 | 0.0 | 0.06 | Medium, wet-on-wet |
|
||||
| `wc_dry` | Dry Brush | 30 | 0.70 | 0.6 | 0.12 | Small, textured, high opacity |
|
||||
| `wc_glaze` | Glazing | 50 | 0.15 | 0.0 | 0.10 | Very transparent, layered |
|
||||
| `wc_splat` | Splatter | 40 | 0.50 | 0.2 | 0.30 | Scattered droplets |
|
||||
| `wc_bleed` | Color Bleed | 70 | 0.30 | 0.0 | 0.07 | Heavy diffusion edges |
|
||||
| `wc_grain` | Granulation | 45 | 0.40 | 0.3 | 0.09 | Visible paper grain texture |
|
||||
| `wc_bloom` | Bloom | 90 | 0.20 | 0.0 | 0.05 | Soft, blooming edges |
|
||||
|
||||
All use `BrushStyle::Watercolor` as the engine style — the engine's existing `draw_watercolor_brush` handles the actual stroke rendering.
|
||||
|
||||
#### Watercolor Splat Preview Algorithm (64×64 RGBA)
|
||||
|
||||
The splat is generated procedurally using multi-octave value noise:
|
||||
|
||||
1. **Base shape:** Radial gradient from center, `alpha = (1 - dist/radius)^1.5`
|
||||
2. **Edge displacement:** Displace the radius at each angle using 3-octave value noise → irregular organic boundary
|
||||
3. **Multiple layers:** 3-5 overlapping semi-transparent blobs at slightly offset positions
|
||||
4. **Color variation:** Shift hue slightly per layer (±10°) for color separation
|
||||
5. **Granulation:** High-frequency noise modulates alpha in the outer 40% of the radius
|
||||
6. **Wet edge:** Slightly darker/more saturated ring near the boundary (wet-edge accumulation effect)
|
||||
|
||||
The noise function is a simple hash-based value noise (no external deps):
|
||||
```rust
|
||||
fn value_noise(x: f32, y: f32) -> f32 {
|
||||
// hash-based pseudo-random, returns 0.0..1.0
|
||||
}
|
||||
fn fbm(x: f32, y: f32, octaves: u32) -> f32 {
|
||||
// fractal Brownian motion using value_noise
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Changes Summary
|
||||
## Step 2: Register the crate in the workspace
|
||||
|
||||
| # | File | Change |
|
||||
|---|------|--------|
|
||||
| 1 | Project root | Add `increment_build.sh` script |
|
||||
| 2 | `hcie-iced-app/.../app.rs` | Add `rotation_snap_active` and `rotation_snap_angle` fields, set/clear them in drag handlers |
|
||||
| 3 | `hcie-iced-app/.../canvas/mod.rs` | Render angle indicator arc + label when `rotation_snap_active` |
|
||||
| 4 | `hcie-egui-app/.../canvas/mod.rs` | Same overlay for egui (if desired, otherwise skip) |
|
||||
| 5 | `hcie-iced-app/.../app.rs` | Change `fill_color = color` to `fill_color = self.bg_color` |
|
||||
**File:** `Cargo.toml` (workspace root)
|
||||
|
||||
Add to `[workspace] members`:
|
||||
```toml
|
||||
"hcie-iced-app/crates/hcie-watercolor-brushes",
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 3: Add `hcie-watercolor-brushes` dependency to `hcie-iced-gui`
|
||||
|
||||
**File:** `hcie-iced-app/crates/hcie-iced-gui/Cargo.toml`
|
||||
|
||||
Add:
|
||||
```toml
|
||||
hcie-watercolor-brushes = { path = "../hcie-watercolor-brushes" }
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Step 4: Update the Brushes panel
|
||||
|
||||
**File:** `hcie-iced-app/crates/hcie-iced-gui/src/panels/brushes.rs`
|
||||
|
||||
### 4a. Add `Watercolor` variant to `BrushCategory`
|
||||
```rust
|
||||
pub enum BrushCategory {
|
||||
All,
|
||||
Drawing,
|
||||
Painting,
|
||||
Watercolor, // ← NEW
|
||||
Effects,
|
||||
Custom,
|
||||
Imported,
|
||||
}
|
||||
```
|
||||
|
||||
### 4b. Update `category_matches_style` for the new variant
|
||||
```rust
|
||||
BrushCategory::Watercolor => style_category == BrushCategory::Watercolor,
|
||||
```
|
||||
|
||||
### 4c. Add Watercolor tab to the category tabs array
|
||||
```rust
|
||||
(BrushCategory::Watercolor, "Watercolor", "icons/brush.svg"),
|
||||
```
|
||||
|
||||
### 4d. Render watercolor presets when Watercolor category is active
|
||||
When `active_category == BrushCategory::Watercolor`:
|
||||
- Call `hcie_watercolor_brushes::watercolor_presets()` to get the preset list
|
||||
- For each preset, call `hcie_watercolor_brushes::render_watercolor_splat(...)` for the thumbnail
|
||||
- Render as a grid (same 2-column layout as existing brushes)
|
||||
- Each cell sends `Message::BrushPresetSelected(preset)` on click
|
||||
|
||||
### 4e. Update `view` function signature
|
||||
The function already accepts `imported_presets: &[BrushPreset]`. No signature change needed — the watercolor presets are fetched internally from the new crate.
|
||||
|
||||
### 4f. Update test `catalog_contains_every_engine_brush_style`
|
||||
The test asserts `BRUSH_STYLES.len() == 34`. This doesn't change (watercolor presets are separate from `BRUSH_STYLES`). The test remains valid.
|
||||
|
||||
---
|
||||
|
||||
## Step 5: Add "Watercolor" to the egui GUI category filter (optional, for parity)
|
||||
|
||||
**File:** `hcie-egui-app/crates/hcie-gui-egui/src/app/tools/brushes_panel.rs`
|
||||
|
||||
Add "Watercolor" to the categories array and update `matches_style_category` to map it to `BrushStyle::Watercolor`. This is a minimal change for parity — the watercolor presets themselves would need separate integration in the egui panel if desired.
|
||||
|
||||
**Note:** This step is optional for the initial implementation. The user's request focuses on the iced GUI.
|
||||
|
||||
---
|
||||
|
||||
## Files Changed
|
||||
|
||||
| File | Change |
|
||||
|------|--------|
|
||||
| `hcie-iced-app/crates/hcie-watercolor-brushes/Cargo.toml` | **New** — crate manifest |
|
||||
| `hcie-iced-app/crates/hcie-watercolor-brushes/src/lib.rs` | **New** — presets + splat renderer |
|
||||
| `Cargo.toml` (workspace root) | Add member `hcie-iced-app/crates/hcie-watercolor-brushes` |
|
||||
| `hcie-iced-app/crates/hcie-iced-gui/Cargo.toml` | Add dependency `hcie-watercolor-brushes` |
|
||||
| `hcie-iced-app/crates/hcie-iced-gui/src/panels/brushes.rs` | Add `Watercolor` category, tab, and grid rendering |
|
||||
|
||||
**Files NOT modified:** All engine crates (`hcie-brush-engine`, `hcie-protocol`, `hcie-engine-api`, `hcie-draw`), existing brush definitions, existing `BRUSH_STYLES` array.
|
||||
|
||||
---
|
||||
|
||||
## Validation
|
||||
|
||||
1. `cargo check -p hcie-iced-gui && cargo check -p hcie-gui-egui`
|
||||
2. `cargo test -p hcie-iced-gui`
|
||||
3. Manual: run `bash increment_build.sh` and verify `build.id` increments from 990 → 991
|
||||
1. `cargo check -p hcie-watercolor-brushes` — new crate compiles
|
||||
2. `cargo check -p hcie-iced-gui` — GUI compiles with new dependency
|
||||
3. `cargo test -p hcie-iced-gui` — all existing tests pass
|
||||
4. `cargo test -p hcie-watercolor-brushes` — new crate tests pass
|
||||
5. `cargo test --test feature_scorecard` — scorecard passes
|
||||
6. Visual: launch the app, open Brushes panel, click "Watercolor" tab → 8 watercolor presets with splat previews appear
|
||||
7. Visual: select a watercolor brush → draw on canvas → realistic watercolor stroke rendered
|
||||
8. Regression: existing Drawing/Painting/Effects brushes unchanged
|
||||
|
||||
Reference in New Issue
Block a user