Files
texturecraft/crates/engine/src/tool_settings.rs
T
chasse20 0ff72b0d46 Auto: Revert export additions and evaluate brush pickup by tile
Remove DDS encoding, its dependency, export options, tests and documentation. Revert the MaterialX export-dialog option and preview additions while retaining engine export support.

Evaluate material-brush and mask Clone/Smudge pickup on demand. Give mask preview and commit an explicit value image. Sample the document in solo mode and avoid redundant export cache invalidation.

Validate saved decal axes, stencil settings and smudge strength. Bound smart-mask reads, write masks atomically and reject external anchor references. Clear stale clone sources on cross-set selection. Reject moves into another set’s folder and use layer positions to detect no-op moves without cloning the project again.

Load saved materials on shelf click and route pinch gestures to viewport zoom. Add regression tests for the affected behaviors.
2026-11-18 05:20:25 +00:00

66 lines
2.5 KiB
Rust

//! The tool settings that outlive a project: they are kept when another project opens and are
//! saved with the UI state, so the next session starts with the same brush.
use serde::{Deserialize, Serialize};
use crate::session::{CloneFrom, StencilLook, ToolState};
use texturecraft_paint::BrushSettings;
/// Brush, symmetry, stencil placement, smudge strength, clone mode and alignment and path switches. Left out
/// because they belong to one project: the clone source point, the stencil image, the points of
/// the path being drawn and the brush's image alpha (an image resource of that project).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ToolSettings {
pub brush: BrushSettings,
pub stencil: StencilLook,
pub smudge_strength: f32,
pub clone_from: CloneFrom,
/// Settings saved before the Aligned switch existed keep its default (on)
#[serde(default = "aligned_by_default")]
pub clone_aligned: bool,
pub path_closed: bool,
pub path_fill: bool,
}
fn aligned_by_default() -> bool {
true
}
impl Default for ToolSettings {
fn default() -> Self {
ToolSettings::of(&ToolState::default())
}
}
impl ToolSettings {
/// The settings `tool` has now.
pub fn of(tool: &ToolState) -> ToolSettings {
let mut brush = tool.brush.clone();
brush.alpha_image = None;
ToolSettings {
brush,
stencil: tool.stencil.as_ref().map_or(tool.stencil_look, |stencil| stencil.look()),
smudge_strength: tool.smudge_strength,
clone_from: tool.clone_from,
clone_aligned: tool.clone_aligned,
path_closed: tool.path.closed,
path_fill: tool.path.fill,
}
}
/// Make `tool` use these settings, leaving what belongs to its project alone.
pub fn apply(&self, tool: &mut ToolState) {
let alpha_image = tool.brush.alpha_image.take();
tool.brush = self.brush.clone().sanitized();
// An image alpha names a resource of the project that was open; the library alpha is global
tool.brush.alpha_image = alpha_image;
tool.stencil_look = self.stencil.sanitized();
tool.smudge_strength = if self.smudge_strength.is_finite() { self.smudge_strength.clamp(0.0, 1.0) } else { crate::session::default_smudge_strength() };
tool.clone_from = self.clone_from;
tool.clone_aligned = self.clone_aligned;
tool.path.closed = self.path_closed;
tool.path.fill = self.path_fill;
}
}