Fix smudge tool

This commit is contained in:
Skyler Lehmkuhl
2026-03-01 14:00:39 -05:00
parent 1c7256a12e
commit e85efe7405
7 changed files with 260 additions and 105 deletions
@@ -119,25 +119,18 @@
"name": "Drawing/Painting",
"description": "Minimal UI - just canvas and drawing tools",
"layout": {
"type": "vertical-grid",
"percent": 8,
"type": "horizontal-grid",
"percent": 15,
"children": [
{ "type": "pane", "name": "toolbar" },
{
"type": "horizontal-grid",
"percent": 85,
"type": "vertical-grid",
"percent": 30,
"children": [
{ "type": "pane", "name": "stage" },
{
"type": "vertical-grid",
"percent": 70,
"children": [
{ "type": "pane", "name": "infopanel" },
{ "type": "pane", "name": "timelineV2" }
]
}
{ "type": "pane", "name": "toolbar" },
{ "type": "pane", "name": "infopanel" }
]
}
},
{ "type": "pane", "name": "stage" }
]
}
}
@@ -755,6 +755,11 @@ struct EditorApp {
draw_simplify_mode: lightningbeam_core::tool::SimplifyMode, // Current simplification mode for draw tool
rdp_tolerance: f64, // RDP simplification tolerance (default: 10.0)
schneider_max_error: f64, // Schneider curve fitting max error (default: 30.0)
// Raster brush settings
brush_radius: f32, // brush radius in pixels
brush_opacity: f32, // brush opacity 0.0–1.0
brush_hardness: f32, // brush hardness 0.0–1.0
brush_spacing: f32, // dabs_per_radius (fraction of radius per dab)
// Audio engine integration
#[allow(dead_code)] // Must be kept alive to maintain audio output
audio_stream: Option<cpal::Stream>,
@@ -1026,6 +1031,10 @@ impl EditorApp {
draw_simplify_mode: lightningbeam_core::tool::SimplifyMode::Smooth, // Default to smooth curves
rdp_tolerance: 10.0, // Default RDP tolerance
schneider_max_error: 30.0, // Default Schneider max error
brush_radius: 10.0,
brush_opacity: 1.0,
brush_hardness: 0.5,
brush_spacing: 0.1,
audio_stream,
audio_controller,
audio_event_rx,
@@ -5069,6 +5078,10 @@ impl eframe::App for EditorApp {
draw_simplify_mode: &mut self.draw_simplify_mode,
rdp_tolerance: &mut self.rdp_tolerance,
schneider_max_error: &mut self.schneider_max_error,
brush_radius: &mut self.brush_radius,
brush_opacity: &mut self.brush_opacity,
brush_hardness: &mut self.brush_hardness,
brush_spacing: &mut self.brush_spacing,
audio_controller: self.audio_controller.as_ref(),
video_manager: &self.video_manager,
playback_time: &mut self.playback_time,
@@ -147,13 +147,19 @@ impl InfopanelPane {
fn render_tool_section(&mut self, ui: &mut Ui, path: &NodePath, shared: &mut SharedPaneState) {
let tool = *shared.selected_tool;
let active_is_raster = shared.active_layer_id
.and_then(|id| shared.action_executor.document().get_layer(&id))
.map_or(false, |l| matches!(l, AnyLayer::Raster(_)));
let is_raster_paint_tool = active_is_raster && matches!(tool, Tool::Draw | Tool::Erase | Tool::Smudge);
// Only show tool options for tools that have options
let is_vector_tool = matches!(
let is_vector_tool = !active_is_raster && matches!(
tool,
Tool::Select | Tool::BezierEdit | Tool::Draw | Tool::Rectangle
| Tool::Ellipse | Tool::Line | Tool::Polygon
);
let has_options = is_vector_tool || matches!(
let has_options = is_vector_tool || is_raster_paint_tool || matches!(
tool,
Tool::PaintBucket | Tool::RegionSelect
);
@@ -162,7 +168,17 @@ impl InfopanelPane {
return;
}
egui::CollapsingHeader::new("Tool Options")
let header_label = if is_raster_paint_tool {
match tool {
Tool::Erase => "Eraser",
Tool::Smudge => "Smudge",
_ => "Brush",
}
} else {
"Tool Options"
};
egui::CollapsingHeader::new(header_label)
.id_salt(("tool_options", path))
.default_open(self.tool_section_open)
.show(ui, |ui| {
@@ -175,7 +191,7 @@ impl InfopanelPane {
}
match tool {
Tool::Draw => {
Tool::Draw if !is_raster_paint_tool => {
// Stroke width
ui.horizontal(|ui| {
ui.label("Stroke Width:");
@@ -284,6 +300,42 @@ impl InfopanelPane {
});
}
// Raster paint tools
Tool::Draw | Tool::Erase | Tool::Smudge if is_raster_paint_tool => {
ui.horizontal(|ui| {
ui.label("Size:");
ui.add(
egui::Slider::new(shared.brush_radius, 1.0_f32..=200.0)
.logarithmic(true)
.suffix(" px"),
);
});
if !matches!(tool, Tool::Smudge) {
ui.horizontal(|ui| {
ui.label("Opacity:");
ui.add(
egui::Slider::new(shared.brush_opacity, 0.0_f32..=1.0)
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)),
);
});
}
ui.horizontal(|ui| {
ui.label("Hardness:");
ui.add(
egui::Slider::new(shared.brush_hardness, 0.0_f32..=1.0)
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)),
);
});
ui.horizontal(|ui| {
ui.label("Spacing:");
ui.add(
egui::Slider::new(shared.brush_spacing, 0.01_f32..=1.0)
.logarithmic(true)
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)),
);
});
}
_ => {}
}
@@ -185,6 +185,11 @@ pub struct SharedPaneState<'a> {
pub draw_simplify_mode: &'a mut lightningbeam_core::tool::SimplifyMode,
pub rdp_tolerance: &'a mut f64,
pub schneider_max_error: &'a mut f64,
/// Raster brush settings
pub brush_radius: &'a mut f32,
pub brush_opacity: &'a mut f32,
pub brush_hardness: &'a mut f32,
pub brush_spacing: &'a mut f32,
/// Audio engine controller for playback control (wrapped in Arc<Mutex<>> for thread safety)
pub audio_controller: Option<&'a std::sync::Arc<std::sync::Mutex<daw_backend::EngineController>>>,
/// Video manager for video decoding and frame caching
@@ -4213,7 +4213,20 @@ impl StagePane {
return;
}
let brush = lightningbeam_core::brush_settings::BrushSettings::default_round_soft();
let brush = {
use lightningbeam_core::brush_settings::BrushSettings;
BrushSettings {
radius_log: shared.brush_radius.ln(),
hardness: *shared.brush_hardness,
opaque: *shared.brush_opacity,
dabs_per_radius: *shared.brush_spacing,
color_h: 0.0,
color_s: 0.0,
color_v: 0.0,
pressure_radius_gain: 0.3,
pressure_opacity_gain: 0.8,
}
};
let color = if matches!(blend_mode, lightningbeam_core::raster_layer::RasterBlendMode::Erase) {
[1.0f32, 1.0, 1.0, 1.0]
@@ -193,53 +193,55 @@ impl PaneRenderer for ToolbarPane {
y += button_size + button_spacing;
}
// Add color pickers below the tool buttons (vector layers only)
if matches!(active_layer_type, None | Some(LayerType::Vector)) {
let is_raster = matches!(active_layer_type, Some(LayerType::Raster));
let show_colors = matches!(active_layer_type, None | Some(LayerType::Vector) | Some(LayerType::Raster));
// Add color pickers below the tool buttons
if show_colors {
y += button_spacing * 2.0; // Extra spacing
// Fill Color
let fill_label_width = 40.0;
let color_button_size = 50.0;
let color_row_width = fill_label_width + color_button_size + button_spacing;
let color_x = rect.left() + (rect.width() - color_row_width) / 2.0;
// Fill color label
// For raster layers show a single "Color" swatch (brush paint color = stroke_color).
// For vector layers show Fill + Stroke.
if !is_raster {
// Fill color label
ui.painter().text(
egui::pos2(color_x + fill_label_width / 2.0, y + color_button_size / 2.0),
egui::Align2::CENTER_CENTER,
"Fill",
egui::FontId::proportional(14.0),
egui::Color32::from_gray(200),
);
// Fill color button
let fill_button_rect = egui::Rect::from_min_size(
egui::pos2(color_x + fill_label_width + button_spacing, y),
egui::vec2(color_button_size, color_button_size),
);
let fill_button_id = ui.id().with(("fill_color_button", path));
let fill_response = ui.interact(fill_button_rect, fill_button_id, egui::Sense::click());
draw_color_button(ui, fill_button_rect, *shared.fill_color);
egui::containers::Popup::from_toggle_button_response(&fill_response)
.show(|ui| {
let changed = egui::color_picker::color_picker_color32(ui, shared.fill_color, egui::color_picker::Alpha::OnlyBlend);
if changed {
*shared.active_color_mode = super::ColorMode::Fill;
}
});
y += color_button_size + button_spacing;
}
// Stroke/brush color label
let stroke_label = if is_raster { "Color" } else { "Stroke" };
ui.painter().text(
egui::pos2(color_x + fill_label_width / 2.0, y + color_button_size / 2.0),
egui::Align2::CENTER_CENTER,
"Fill",
egui::FontId::proportional(14.0),
egui::Color32::from_gray(200),
);
// Fill color button
let fill_button_rect = egui::Rect::from_min_size(
egui::pos2(color_x + fill_label_width + button_spacing, y),
egui::vec2(color_button_size, color_button_size),
);
let fill_button_id = ui.id().with(("fill_color_button", path));
let fill_response = ui.interact(fill_button_rect, fill_button_id, egui::Sense::click());
// Draw fill color button with checkerboard for alpha
draw_color_button(ui, fill_button_rect, *shared.fill_color);
// Show fill color picker popup using new Popup API
egui::containers::Popup::from_toggle_button_response(&fill_response)
.show(|ui| {
let changed = egui::color_picker::color_picker_color32(ui, shared.fill_color, egui::color_picker::Alpha::OnlyBlend);
// Track that the user interacted with the fill color
if changed {
*shared.active_color_mode = super::ColorMode::Fill;
}
});
y += color_button_size + button_spacing;
// Stroke color label
ui.painter().text(
egui::pos2(color_x + fill_label_width / 2.0, y + color_button_size / 2.0),
egui::Align2::CENTER_CENTER,
"Stroke",
stroke_label,
egui::FontId::proportional(14.0),
egui::Color32::from_gray(200),
);
@@ -251,20 +253,15 @@ impl PaneRenderer for ToolbarPane {
);
let stroke_button_id = ui.id().with(("stroke_color_button", path));
let stroke_response = ui.interact(stroke_button_rect, stroke_button_id, egui::Sense::click());
// Draw stroke color button with checkerboard for alpha
draw_color_button(ui, stroke_button_rect, *shared.stroke_color);
// Show stroke color picker popup using new Popup API
egui::containers::Popup::from_toggle_button_response(&stroke_response)
.show(|ui| {
let changed = egui::color_picker::color_picker_color32(ui, shared.stroke_color, egui::color_picker::Alpha::OnlyBlend);
// Track that the user interacted with the stroke color
if changed {
*shared.active_color_mode = super::ColorMode::Stroke;
}
});
} // end color pickers (vector only)
} // end color pickers
}
fn name(&self) -> &str {