mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 20:16:29 -05:00
Merge pull request #19327
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
7b35c6c798
3 files changed
+69
No files matched your search
@@ -166,6 +166,8 @@ pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings
|
||||
brush.mixer.load_after_stroke = true;
|
||||
brush.mixer.clean_after_stroke = true;
|
||||
brush.mixer.sample_all_layers = false;
|
||||
brush.transfer.enabled = true;
|
||||
brush.transfer.flow.control = photocraft_engine::paint::brush::Control::PenPressure;
|
||||
}
|
||||
Tool::Eraser => {
|
||||
(brush.size, brush.hardness, brush.spacing) = ERASER_TOOL_TIP;
|
||||
|
||||
@@ -1159,6 +1159,8 @@ mod home_screen_escape_no_document_tests;
|
||||
#[cfg(test)]
|
||||
mod lasso_click_tests;
|
||||
#[cfg(test)]
|
||||
mod mixer_reset_transfer_flow_tests;
|
||||
#[cfg(test)]
|
||||
mod reset_tip_tests;
|
||||
#[cfg(test)]
|
||||
mod rotate_steps_tests;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
use photocraft_engine::paint::brush::Control;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
|
||||
fn painting_app(tool: Tool) -> Result<Box<PhotocraftApp>, String> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.background_jobs = false;
|
||||
app.run("file.new", json!({"width": 64, "height": 64, "background": "white"}))?;
|
||||
app.run("layer.new.layer", json!({"name": "Paint"}))?;
|
||||
app.ui.tool = tool;
|
||||
crate::paint_mouse::sync_tool_brush(&mut app);
|
||||
app.sync_views();
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
fn reset(app: &mut PhotocraftApp, command: &str, params: Value) -> Result<(), String> {
|
||||
let ctx = app.ctx().clone();
|
||||
crate::menus::invoke(app, &ctx, command, params).map(|_| ())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixer_resets_enable_pressure_flow_only() -> Result<(), String> {
|
||||
let mut app = painting_app(Tool::MixerBrush)?;
|
||||
for (command, params) in [("tool.reset", json!({})), ("tool.resetAll", json!({"confirmed": true}))] {
|
||||
app.session.tools.brush.transfer = Default::default();
|
||||
reset(&mut app, command, params)?;
|
||||
|
||||
let brush = &app.session.tools.brush;
|
||||
let transfer = &brush.transfer;
|
||||
assert!(transfer.enabled, "{command}");
|
||||
assert_eq!(transfer.flow.control, Control::PenPressure);
|
||||
assert_eq!((transfer.flow.jitter, transfer.flow.minimum), (0.0, 0.0));
|
||||
assert_eq!((transfer.opacity.control, transfer.wetness.control, transfer.mix.control), (Control::Off, Control::Off, Control::Off));
|
||||
assert!(brush.smoothing.enabled);
|
||||
assert_eq!((brush.mixer.wet, brush.mixer.load, brush.mixer.mix, brush.mixer.flow), (0.8, 0.75, 0.9, 1.0));
|
||||
}
|
||||
|
||||
let mut brush = painting_app(Tool::Brush)?;
|
||||
reset(&mut brush, "tool.reset", json!({}))?;
|
||||
assert!(!brush.session.tools.brush.transfer.enabled);
|
||||
assert_eq!(brush.session.tools.brush.transfer.flow.control, Control::Off);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn dry_mixer_deposit(points: Value, flow: u8) -> Result<f32, String> {
|
||||
let mut app = painting_app(Tool::MixerBrush)?;
|
||||
reset(&mut app, "tool.reset", json!({}))?;
|
||||
app.run("paint.mixerBrush", json!({"points": points, "wet": 0, "load": 100, "mix": 0, "flow": flow, "color": "#ff0000", "seed": 17754}))?;
|
||||
let doc = app.session.active().ok_or("missing test document")?;
|
||||
let layer = doc.active_layer.and_then(|id| doc.doc.layer(id)).ok_or("missing test paint target")?;
|
||||
let surface = layer.surface().ok_or("missing test paint surface")?;
|
||||
Ok(surface.rgba(24, 24)[3])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dry_half_pressure_mixer_matches_a_mouse_at_half_flow() -> Result<(), String> {
|
||||
let pen = dry_mixer_deposit(json!([[24.5, 24.5, 0.5]]), 100)?;
|
||||
let mouse_half = dry_mixer_deposit(json!([[24.5, 24.5]]), 50)?;
|
||||
let mouse_full = dry_mixer_deposit(json!([[24.5, 24.5]]), 100)?;
|
||||
assert!(pen > 0.0 && mouse_full > pen, "pen {pen}, mouse at full flow {mouse_full}");
|
||||
assert!((pen - mouse_half).abs() <= 1.0 / 255.0, "half-pressure pen {pen}, mouse at half flow {mouse_half}");
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user