diff --git a/crates/draw/src/ui/mod.rs b/crates/draw/src/ui/mod.rs index 94a269ea2..e2a96a69f 100644 --- a/crates/draw/src/ui/mod.rs +++ b/crates/draw/src/ui/mod.rs @@ -34,10 +34,13 @@ pub mod corner; pub mod crop; pub mod gradient; pub mod measure; +pub mod paint_bar; +pub mod paths; pub mod pattern; pub mod pen; pub mod picture_fill; pub mod shape; +pub mod shape_presets; pub mod shape_drag; pub mod slice; pub mod stroke; diff --git a/crates/draw/src/ui/paint_bar.rs b/crates/draw/src/ui/paint_bar.rs new file mode 100644 index 000000000..da53cec07 --- /dev/null +++ b/crates/draw/src/ui/paint_bar.rs @@ -0,0 +1,189 @@ +//! [`PaintBar`]: the options bar members of the Brush, Pencil, Eraser and Mixer Brush tools after the preset picker. + +use craft_behavior::{EditEvents, Value}; +use craft_theme::Srgba; +use craft_ui::contract::Entry; +use craft_ui::text::RangeAlert; +use egui::{Response, Ui}; + +mod words; + +pub use words::PaintBarWords; + +/// The painting tools the bar serves. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum PaintTool { + /// The Brush tool. + Brush, + /// The Pencil tool. + Pencil, + /// The Eraser tool. + Eraser, + /// The Mixer Brush tool. + MixerBrush, +} + +/// The bar's values. +#[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] +pub struct PaintValues { + /// The brush size. + pub size: f64, + /// The brush hardness. + pub hardness: f64, + /// The opacity. + pub opacity: f64, + /// The flow. + pub flow: f64, + /// The stroke smoothing. + pub smoothing: Smoothing, + /// Pressure controls the opacity. + pub pressure_opacity: bool, + /// Pressure controls the size. + pub pressure_size: bool, + /// Build-up (airbrush) is on. + pub build_up: bool, + /// The blend mode, as the app's blend key. + pub mode: M, + /// The eraser erases to history. + pub erase_to_history: bool, + /// The pencil erases where it starts on the foreground colour. + pub auto_erase: bool, + /// The Mixer Brush's values. + pub mixer: MixerValues, +} + +/// The stroke smoothing options. +#[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] +pub struct Smoothing { + /// The amount, 0 to 1. + pub amount: f64, + /// Pulled string mode. + pub pulled_string: bool, + /// The stroke catches up when the pointer pauses. + pub catch_up: bool, + /// The stroke catches up at the end. + pub catch_up_on_end: bool, + /// The amount adjusts for zoom. + pub adjust_for_zoom: bool, +} + +/// The Mixer Brush's values. +#[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] +pub struct MixerValues { + /// Load the brush after each stroke. + pub load_after_stroke: bool, + /// Clean the brush after each stroke. + pub clean_after_stroke: bool, + /// The wetness. + pub wet: f64, + /// The load. + pub load: f64, + /// The mix. + pub mix: f64, + /// The flow. + pub flow: f64, + /// Sample all layers. + pub sample_all_layers: bool, + /// The index into [`MIXER_COMBINATIONS`]. + pub combination: usize, + /// The colour the brush is loaded with, if any. + pub load_color: Option, + /// Only solid colours load. + pub solid_colors_only: bool, +} + +/// What the Eraser tool erases with. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum EraserMode { + /// A brush. + #[default] + Brush, + /// A pencil. + Pencil, + /// A block. + Block, +} + +/// The mixer combinations as (wet, load, mix); `None` is Custom. +pub const MIXER_COMBINATIONS: [Option<(f64, f64, f64)>; 13] = [ + None, + Some((0.0, 25.0, 25.0)), + Some((0.0, 50.0, 50.0)), + Some((0.0, 75.0, 75.0)), + Some((25.0, 25.0, 25.0)), + Some((25.0, 50.0, 50.0)), + Some((25.0, 75.0, 75.0)), + Some((50.0, 25.0, 25.0)), + Some((50.0, 50.0, 50.0)), + Some((50.0, 75.0, 75.0)), + Some((75.0, 25.0, 25.0)), + Some((75.0, 50.0, 50.0)), + Some((75.0, 75.0, 75.0)), +]; + +/// The index of the first combination of each group, as fractions 0..1 of the list. +pub const MIXER_GROUP_STARTS: [usize; 4] = [0, 1, 4, 7]; + +/// The bar's members for one painting tool. +#[must_use = "show the bar with `show`"] +#[derive(craft_ui::contract::Pattern)] +#[pattern(probe(PaintBar<'static, u32>))] +pub struct PaintBar<'a, M: Value> { + tool: PaintTool, + values: &'a mut PaintValues, + eraser_mode: Option<&'a mut EraserMode>, + max_size: f64, + modes: &'a [Entry], +} + +/// What [`PaintBar::show`] reports. +#[non_exhaustive] +pub struct PaintBarOutput { + /// The bar's response. + pub response: Response, + /// The edits of the values, one gesture each. + pub edits: EditEvents>, + /// The Load button was pressed. + pub mixer_load: bool, + /// The Clean button was pressed. + pub mixer_clean: bool, + /// A value was typed out of range. + pub out_of_range: Option, +} + +impl<'a, M: Value> PaintBar<'a, M> { + /// The bar of `tool` over `values`. + pub fn new(tool: PaintTool, values: &'a mut PaintValues) -> Self { + PaintBar { tool, values, eraser_mode: None, max_size: 5000.0, modes: &[] } + } + + /// The Eraser's mode, shown for the Eraser tool. + pub fn eraser_mode(mut self, mode: &'a mut EraserMode) -> Self { + self.eraser_mode = Some(mode); + self + } + + /// The largest brush size. + pub fn max_size(mut self, max: f64) -> Self { + self.max_size = max; + self + } + + /// The blend modes the Mode list offers. + pub fn modes(mut self, modes: &'a [Entry]) -> Self { + self.modes = modes; + self + } + + /// Shows the members. + pub fn show(self, ui: &mut Ui) -> PaintBarOutput { + let PaintBar { tool, values, eraser_mode, max_size, modes } = self; + let _ = (ui, tool, values, eraser_mode, max_size, modes); + todo!("pn.C18") + } +} diff --git a/crates/draw/src/ui/paint_bar/words.rs b/crates/draw/src/ui/paint_bar/words.rs new file mode 100644 index 000000000..22ea3ede7 --- /dev/null +++ b/crates/draw/src/ui/paint_bar/words.rs @@ -0,0 +1,35 @@ +//! The words of the paint bar ([`PaintBarWords`]). + +craft_ui::words! { + /// The words of [`PaintBar`](super::PaintBar), English by default (Photoshop's). + pub struct PaintBarWords { + /// The Size field's caption. + size: "paintBar.size" = "Size"; + /// The Hardness field's caption. + hardness: "paintBar.hardness" = "Hardness"; + /// The Opacity field's caption. + opacity: "paintBar.opacity" = "Opacity"; + /// The Flow field's caption. + flow: "paintBar.flow" = "Flow"; + /// The Mode field's caption. + mode: "paintBar.mode" = "Mode"; + /// The Smoothing field's caption. + smoothing: "paintBar.smoothing" = "Smoothing"; + /// The names of the mixer combinations, in [`MIXER_COMBINATIONS`](super::MIXER_COMBINATIONS) order. + combinations: array [ + "paintBar.combination0" = "Custom", + "paintBar.combination1" = "Dry, Light Load", + "paintBar.combination2" = "Dry, Medium Load", + "paintBar.combination3" = "Dry, Heavy Load", + "paintBar.combination4" = "Moist, Light Load", + "paintBar.combination5" = "Moist, Medium Load", + "paintBar.combination6" = "Moist, Heavy Load", + "paintBar.combination7" = "Wet, Light Load", + "paintBar.combination8" = "Wet, Medium Load", + "paintBar.combination9" = "Wet, Heavy Load", + "paintBar.combination10" = "Very Wet, Light Load", + "paintBar.combination11" = "Very Wet, Medium Load", + "paintBar.combination12" = "Very Wet, Heavy Load" + ]; + } +} diff --git a/crates/draw/src/ui/paths/footer.rs b/crates/draw/src/ui/paths/footer.rs new file mode 100644 index 000000000..4e6733d16 --- /dev/null +++ b/crates/draw/src/ui/paths/footer.rs @@ -0,0 +1,19 @@ +//! The footer of the Paths panel. + +/// A button of the Paths footer. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum PathsFooterButton { + /// Fill the path with the foreground colour; disabled while the document cannot be filled. + FillPath, + /// Stroke the path. + StrokePath, + /// Load the path as a selection; a row dropped on it is loaded. + LoadSelection, + /// Make a work path from the selection. + MakeWorkPath, + /// Create a new path; a row dropped on it is duplicated. + New, + /// Delete the path; a row dropped on it is deleted. + Delete, +} diff --git a/crates/draw/src/ui/paths/menu.rs b/crates/draw/src/ui/paths/menu.rs new file mode 100644 index 000000000..8fabf0f5f --- /dev/null +++ b/crates/draw/src/ui/paths/menu.rs @@ -0,0 +1,41 @@ +//! The commands of the Paths panel. + +use super::PathKind; +use craft_ui::contract::CommandSet; + +/// The commands of the Paths panel: its panel-menu rows, its row menu and the footer's buttons. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, CommandSet)] +#[command(prefix = "pathsPanel", scope = "pathsPanel")] +#[non_exhaustive] +pub enum PathsCommands { + /// Load the path as a selection. + #[command(label = "Make Selection…")] + MakeSelection, + /// Fill the path with the foreground colour. + #[command(label = "Fill Path…")] + FillPath, + /// Stroke the path with the current tool. + #[command(label = "Stroke Path…")] + StrokePath, + /// Save the work path. + #[command(label = "Save Path…")] + SavePath, + /// Duplicate the path. + #[command(label = "Duplicate Path…")] + DuplicatePath, + /// Rename the path in place. + #[command(label = "Rename Path…")] + RenamePath, + /// Delete the path. + #[command(label = "Delete Path")] + DeletePath, +} + +impl PathsCommands { + /// Whether the command applies to a targeted row of `kind` (`None`: no row targeted); Fill Path and Stroke Path + /// need `can_fill`. + pub fn applies_to(self, kind: Option, can_fill: bool) -> bool { + let fills = matches!(self, PathsCommands::FillPath | PathsCommands::StrokePath); + kind.is_some() && (can_fill || !fills) + } +} diff --git a/crates/draw/src/ui/paths/mod.rs b/crates/draw/src/ui/paths/mod.rs new file mode 100644 index 000000000..292096202 --- /dev/null +++ b/crates/draw/src/ui/paths/mod.rs @@ -0,0 +1,15 @@ +//! The Paths panel ([`PathsPanel`]): saved paths, the work path, shape paths and vector masks as a list with a +//! footer. + +mod footer; +mod menu; +mod model; +mod panel; +mod rows; +mod words; + +pub use footer::PathsFooterButton; +pub use menu::PathsCommands; +pub use model::{PathKind, PathRow, PathsEvent, PathsOutput}; +pub use panel::PathsPanel; +pub use words::PathsWords; diff --git a/crates/draw/src/ui/paths/model.rs b/crates/draw/src/ui/paths/model.rs new file mode 100644 index 000000000..86982cf97 --- /dev/null +++ b/crates/draw/src/ui/paths/model.rs @@ -0,0 +1,106 @@ +//! The data of the Paths panel: its rows, events and output. + +use craft_behavior::geometry::selection_op::SelectionOperation; +use craft_ui::contract::{NoValue, Outcome}; +use egui::Response; + +/// What a path row is. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] +pub enum PathKind { + /// A saved path. + Saved, + /// The work path: italic, one per document. + Work, + /// The path of the selected shape layer. + ShapePath, + /// The path of the selected layer's vector mask. + VectorMask, +} + +impl PathKind { + /// Whether a row of this kind is renamed in place. + pub fn renames(self) -> bool { + let _ = self; + todo!("tl.T34") + } + + /// Whether a row of this kind can be dragged. + pub fn drags(self) -> bool { + let _ = self; + todo!("tl.T34") + } + + /// Whether a row of this kind is shown in italics: the work path. + pub fn italic(self) -> bool { + matches!(self, PathKind::Work) + } +} + +/// One row of the panel. +#[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] +pub struct PathRow { + /// The row's key. + pub key: K, + /// What the row is. + pub kind: PathKind, + /// The path's name. + pub name: String, + /// The outline the thumbnail draws, in document pixels. + pub outline: kurbo::BezPath, + /// The row is the selected path. + pub selected: bool, +} + +impl PathRow { + /// An unselected row of `kind` named `name` with `outline`. + pub fn new(key: K, kind: PathKind, name: impl Into, outline: kurbo::BezPath) -> Self { + PathRow { key, kind, name: name.into(), outline, selected: false } + } +} + +/// What the Paths panel reports, in the order it happened. +#[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] +pub enum PathsEvent { + /// A row was selected. + Select(K), + /// A rename committed: never empty after trimming, never unchanged. + #[non_exhaustive] + Rename { + /// The path. + key: K, + /// The new name, trimmed. + text: String, + }, + /// A Cmd/Ctrl-click on the thumbnail: load the path as a selection with the operation of Shift and Alt. + #[non_exhaustive] + LoadSelection { + /// The path. + key: K, + /// New, add, subtract or intersect. + operation: SelectionOperation, + }, + /// A command of the panel menu, the row menu or the footer. + Command(super::PathsCommands), +} + +/// What [`PathsPanel::show`](super::PathsPanel::show) returns. +#[derive(Debug)] +#[must_use = "the app applies the panel's events"] +#[non_exhaustive] +pub struct PathsOutput { + /// What the user did this pass, in order. + pub events: Vec>, + /// The panel. + pub response: Response, +} + +impl Outcome for PathsOutput { + type Value = NoValue; + + fn response(&self) -> &Response { + &self.response + } +} diff --git a/crates/draw/src/ui/paths/panel.rs b/crates/draw/src/ui/paths/panel.rs new file mode 100644 index 000000000..79e502b28 --- /dev/null +++ b/crates/draw/src/ui/paths/panel.rs @@ -0,0 +1,54 @@ +//! [`PathsPanel`]: the Paths panel on a `List` with a footer. + +use super::{PathRow, PathsOutput}; +use craft_ui::runtime::env::Label; +use egui::Ui; +use std::fmt::Debug; +use std::hash::Hash; + +/// The Paths panel: one row per path with a thumbnail of its outline, rename in place, and the footer's buttons. +/// +/// A Cmd/Ctrl-click on the thumbnail loads the path as a selection. Fill Path and Stroke Path are greyed while +/// [`can_fill`](Self::can_fill) is false. +#[must_use = "show the panel with `show`"] +#[derive(craft_ui::contract::Pattern)] +#[pattern(probe(PathsPanel<'static, u32>))] +pub struct PathsPanel<'a, K: Clone + Eq + Hash + Debug + Send + Sync + 'static> { + rows: &'a [PathRow], + document: kurbo::Size, + can_fill: bool, + work_name: Option