mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
15 files changed
+414
-40
No files matched your search
@@ -1569,6 +1569,11 @@ fn package(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
for (_, _, l) in doc.walk() {
|
||||
let LayerContent::Smart(so) = &l.content else { continue };
|
||||
let SmartSource::Linked { path } = &so.source else { continue };
|
||||
// PSD stores embedded placed files as Linked sources keyed by their UUID. Their payload
|
||||
// remains in the document's global blocks, so they are not filesystem links to collect.
|
||||
if photocraft_io::linked::embedded_payload(&doc.metadata, path).is_some() {
|
||||
continue;
|
||||
}
|
||||
if missing.contains(path) {
|
||||
continue;
|
||||
}
|
||||
@@ -1849,3 +1854,7 @@ mod package_clash_name_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "print_cmds/package_layer_rename_tests.rs"]
|
||||
mod package_layer_rename_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "print_cmds/package_psd_embedded_tests.rs"]
|
||||
mod package_psd_embedded_tests;
|
||||
@@ -0,0 +1,60 @@
|
||||
//! PSD-embedded smart objects are represented as Linked UUID sources, but their bytes live in the
|
||||
//! document's preserved `lnk2` blocks. Package must leave those sources in the document rather
|
||||
//! than treating UUIDs as missing files.
|
||||
|
||||
use super::*;
|
||||
use photocraft_doc::{Affine, Layer, SmartObject, SmartSource};
|
||||
use std::sync::Arc;
|
||||
|
||||
fn temp_dir() -> (tempfile::TempDir, String) {
|
||||
let root = tempfile::Builder::new().prefix("photocraft-package-psd-").tempdir().unwrap();
|
||||
let path = root.path().to_string_lossy().replace('\\', "/");
|
||||
(root, path)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn package_skips_psd_embedded_sources_but_collects_external_links() {
|
||||
let (_root, dir) = temp_dir();
|
||||
let external = format!("{dir}/external.png");
|
||||
let mut source = crate::session();
|
||||
source.execute("file.new", json!({"width": 4, "height": 4, "background": "#336699"})).unwrap();
|
||||
crate::file_cmds::save_doc(&source.active().unwrap().doc, &external, None).unwrap();
|
||||
|
||||
let mut s = crate::session();
|
||||
s.execute("file.new", json!({"width": 40, "height": 30, "background": "#ffffff"})).unwrap();
|
||||
s.edit("PSD embedded and external links", |doc, active| {
|
||||
let embedded = photocraft_io::linked::LinkedFile { uuid: "embedded-uuid".into(), file_name: "embedded.pcraft".into(), bytes: vec![1, 2, 3] };
|
||||
let block = photocraft_io::linked::encode_linked_file(&embedded);
|
||||
doc.metadata.psd_global_blocks.push((*b"8BIM", *b"lnk2", Arc::new(block)));
|
||||
let embedded_layer = Layer::new("Embedded", LayerContent::Smart(SmartObject::new(SmartSource::Linked { path: embedded.uuid }, Affine::IDENTITY, None)));
|
||||
let external_layer =
|
||||
Layer::new("External", LayerContent::Smart(SmartObject::new(SmartSource::Linked { path: external.clone() }, Affine::IDENTITY, None)));
|
||||
let parent = active.unwrap();
|
||||
let embedded_id = doc.insert_above(Some(parent), embedded_layer);
|
||||
doc.insert_above(Some(embedded_id), external_layer);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let result = s.execute("file.package", json!({"dir": format!("{dir}/out")})).unwrap();
|
||||
assert_eq!(result["missing"], json!([]));
|
||||
assert_eq!(result["links"].as_array().unwrap().len(), 1);
|
||||
assert!(result["links"][0].as_str().unwrap().ends_with("Links/external.png"));
|
||||
|
||||
let packaged_path = result["document"].as_str().unwrap();
|
||||
let packaged = photocraft_io::import("packaged.pcraft", &std::fs::read(packaged_path).unwrap()).unwrap().document;
|
||||
let embedded_sources: Vec<String> = packaged
|
||||
.walk()
|
||||
.iter()
|
||||
.filter_map(|(_, _, layer)| match &layer.content {
|
||||
LayerContent::Smart(smart) => match &smart.source {
|
||||
SmartSource::Linked { path } if path == "embedded-uuid" => Some(path.clone()),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(embedded_sources, vec!["embedded-uuid"]);
|
||||
let (_, payload) = photocraft_io::linked::embedded_payload(&packaged.metadata, "embedded-uuid").expect("the embedded payload survives packaging");
|
||||
assert_eq!(payload, [1, 2, 3]);
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
//! #12672: when the Burn tool can't work on the layer (a hidden target layer, Lock All, Lock Image
|
||||
//! Pixels, a group's pixels), a press opens the reference application's alert with OK and changes
|
||||
//! nothing; Lock position still burns. The Brush keeps its alerts, the other tools keep today's
|
||||
//! behaviour.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::brush_refusal_alert_tests::{active, alerts, app, refused, steps, stroke};
|
||||
use super::*;
|
||||
use crate::control::{ControlRequest, Reply, handle};
|
||||
|
||||
#[test]
|
||||
fn a_hidden_target_layer() {
|
||||
let mut app = app(Tool::Burn);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
refused(&mut app, "Could not use the burn tool because the target layer is hidden.");
|
||||
assert!(app.ui.status.is_empty() || !app.ui.status_error, "no status-bar error as well: {:?}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_all_and_lock_image_pixels() {
|
||||
// Both are the one "the layer is locked." alert in the reference application.
|
||||
for lock in ["all", "pixels"] {
|
||||
let mut app = app(Tool::Burn);
|
||||
app.run("layer.lockLayers", json!({ lock: true })).unwrap();
|
||||
refused(&mut app, "Could not use the burn tool because the layer is locked.");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_is_active() {
|
||||
let mut app = app(Tool::Burn);
|
||||
app.run("layer.new.group", json!({})).unwrap();
|
||||
refused(&mut app, "Could not use the burn tool because the pixels in a group cannot be edited without merging the group.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lock_position_still_burns() {
|
||||
let mut app = app(Tool::Burn);
|
||||
app.run("layer.lockLayers", json!({"position": true})).unwrap();
|
||||
let before = steps(&app);
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty(), "Lock position is no refusal: {:?}", alerts(&app));
|
||||
assert_eq!(steps(&app), before + 1, "the stroke was applied");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_alert_is_listed_and_confirmed_over_the_control_channel() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = app(Tool::Burn);
|
||||
app.run("layer.lockLayers", json!({"pixels": true})).unwrap();
|
||||
stroke(&mut app);
|
||||
let mut call = |method: &str, params: serde_json::Value| {
|
||||
let (req, _rx) = ControlRequest::new(method, params);
|
||||
match handle(&mut app, &ctx, &req) {
|
||||
Reply::Done(v) => v,
|
||||
_ => panic!("{method}: expected an immediate reply"),
|
||||
}
|
||||
};
|
||||
let inspect = call("ui.inspect", json!({}));
|
||||
let dialog = &inspect["result"]["dialogs"][0];
|
||||
assert_eq!(dialog["fields"]["message"], "Could not use the burn tool because the layer is locked.", "{inspect}");
|
||||
assert_eq!(call("ui.dialog.confirm", json!({"dialog": dialog["id"]}))["ok"], true);
|
||||
assert!(alerts(&app).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_brush_and_the_other_tools_keep_todays_behaviour() {
|
||||
// The Brush: no alert for Lock Image Pixels.
|
||||
let mut app = self::app(Tool::Brush);
|
||||
app.run("layer.lockLayers", json!({"pixels": true})).unwrap();
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
// The Dodge tool, the Burn tool's neighbour in the toolbar, has no layer alerts yet: the status
|
||||
// bar says a hidden target.
|
||||
let mut app = self::app(Tool::Dodge);
|
||||
let id = active(&app);
|
||||
app.run("layer.setProps", json!({"layer": id, "visible": false})).unwrap();
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
assert_eq!(app.ui.status, photocraft_engine::hidden_target::HIDDEN);
|
||||
assert_eq!(tool_name(&app, Tool::Dodge), None);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
//! Edit › Assign Profile on a document with layers first asks whether to go on (#14235): giving the document another
|
||||
//! profile can change how its layers look. OK (the default) and Cancel, and a "Don't show again" box kept with the
|
||||
//! other dialog preferences. OK opens the Assign Profile dialog; Cancel or Escape ends the command with nothing changed.
|
||||
//! A document with only a Background layer never asks, nor does `edit.assignProfile` run with params (scripts,
|
||||
//! actions, agents, the control channel), which the menu arm leaves to the command.
|
||||
//! profile can change how its layers look. A warning icon beside the text (#16683), OK (the default) and Cancel, and a
|
||||
//! "Don't show again" box kept with the other dialog preferences. OK opens the Assign Profile dialog; Cancel or Escape
|
||||
//! ends the command with nothing changed. A document with only a Background layer never asks, nor does
|
||||
//! `edit.assignProfile` run with params (scripts, actions, agents, the control channel), which the menu arm leaves to
|
||||
//! the command.
|
||||
|
||||
use craft::behavior::IconId;
|
||||
use craft::ui::dialog::{DialogId, PromptAnswer, PromptChoice, StandardPrompt};
|
||||
|
||||
use super::alerts;
|
||||
@@ -30,6 +32,7 @@ pub fn asks(app: &PhotocraftApp) -> bool {
|
||||
pub fn open(app: &mut PhotocraftApp) -> DialogId {
|
||||
let prompt = StandardPrompt::custom(tl!(QUESTION).to_owned())
|
||||
.title(tl!("Assign Profile").to_owned())
|
||||
.icon(IconId::new("warning"))
|
||||
.button(PromptChoice::Proceed, tl!("OK").to_owned())
|
||||
.button(PromptChoice::Cancel, tl!("Cancel").to_owned())
|
||||
.dont_show_again()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
//! #14235: Edit › Assign Profile on a document with layers asks first, with OK, Cancel and an unticked "Don't show
|
||||
//! again". OK opens the Assign Profile dialog, Cancel changes nothing; a flat document and a run with params never ask;
|
||||
//! a ticked box with OK keeps the question away.
|
||||
//! a ticked box with OK keeps the question away. #16683: the question shows a warning icon beside its text.
|
||||
|
||||
use craft::ui::dialog::{DialogId, StackDialog as _, StandardPrompt};
|
||||
use craft::ui::patterns::form_dialogs::HostedParamDialog;
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::alerts;
|
||||
@@ -56,6 +59,24 @@ fn a_document_with_layers_asks_before_the_dialog() {
|
||||
assert_eq!(steps(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_question_shows_a_warning_icon_beside_its_text() {
|
||||
let app = app(true);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1200.0, 800.0))
|
||||
.with_max_steps(64)
|
||||
.with_context(app.ctx().clone())
|
||||
.build_ui_state(|ui, app: &mut Box<PhotocraftApp>| crate::dialogs::run(app, ui), app);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
menu(h.state_mut());
|
||||
h.run_steps(4);
|
||||
let title = h.get_by_role_and_label(Role::Heading, "Assign Profile").rect();
|
||||
let message = h.get_by_label_contains("Assign a profile anyway?").rect();
|
||||
// The prompt draws the icon unnamed, so it shows in the layout: the title starts at the content's start, the
|
||||
// message after the icon on its row.
|
||||
assert!(message.left() > title.left() + 8.0, "the message starts after the icon: {message:?} vs title {title:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ok_opens_the_assign_profile_dialog() {
|
||||
let mut app = app(true);
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
//! Layers panel's, so a mode has one key and one shortcut everywhere. Fill, Stroke and Fade grey the modes the active
|
||||
//! document's colour mode and depth can't use (#13806, #14647).
|
||||
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, Param, ParamKind};
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamKind, ParamResult};
|
||||
use craft::ui::runtime::env::Label;
|
||||
use craft::ui::runtime::memory::{SaveKey, saved_value, set_saved_value};
|
||||
use photocraft_color::BlendMode;
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
|
||||
const PRESERVE: &str = "preserveTransparency";
|
||||
|
||||
/// A blend-mode row `key` over the Layers panel's mode list (`group` adds Pass Through), opening on `current`.
|
||||
pub(crate) fn blend_param(key: &str, label: impl Into<Label>, group: bool, current: BlendMode) -> Param {
|
||||
let modes = crate::panels::blend_options(group, current)
|
||||
@@ -31,14 +34,46 @@ pub(crate) fn blend_mode(fields: &DialogFields, key: &str) -> BlendMode {
|
||||
fields.text(key).and_then(photocraft_engine::commands::parse_blend).unwrap_or(BlendMode::Normal)
|
||||
}
|
||||
|
||||
/// The Blending section, Mode, Opacity (percent) and Preserve Transparency: the rows Fill and Stroke share.
|
||||
pub(crate) fn blending_rows(app: &PhotocraftApp) -> Vec<Param> {
|
||||
vec![
|
||||
Param::section(tl!("Blending")),
|
||||
document_mode_param(app, tl!("Mode:")),
|
||||
super::new_layer_ui::opacity_param(),
|
||||
Param::new("preserveTransparency", tl!("Preserve Transparency"), ParamKind::bool(false)),
|
||||
]
|
||||
/// The Blending section, Mode, Opacity (percent) and Preserve Transparency: the rows Fill and Stroke share. A
|
||||
/// `forced` Preserve Transparency ([`forced_preserve_transparency`]) shows greyed at that state and is not remembered.
|
||||
pub(crate) fn blending_rows(app: &PhotocraftApp, forced: Option<bool>) -> Vec<Param> {
|
||||
let mut preserve = Param::new(PRESERVE, tl!("Preserve Transparency"), ParamKind::bool(forced.unwrap_or(false)));
|
||||
if forced.is_some() {
|
||||
// No value enables it, so neither the user nor automation can change the target's state.
|
||||
preserve = preserve.enabled_when_in(PRESERVE, Vec::<FieldValue>::new()).not_remembered();
|
||||
}
|
||||
vec![Param::section(tl!("Blending")), document_mode_param(app, tl!("Mode:")), super::new_layer_ui::opacity_param(), preserve]
|
||||
}
|
||||
|
||||
/// The Preserve Transparency that Fill's or Stroke's `target` (as `edit.fill` takes it) forces: off on the Background
|
||||
/// layer or other pixels without transparency, on with Lock Transparent Pixels. `None` for other layers, masks and
|
||||
/// channels, where the box offers the remembered choice.
|
||||
pub(crate) fn forced_preserve_transparency(app: &PhotocraftApp, target: &Value) -> Option<bool> {
|
||||
let st = app.session.active()?;
|
||||
let id = st.active_layer?;
|
||||
if photocraft_engine::channel_cmds::gray_target(&json!({ "target": target })).is_some() {
|
||||
return None;
|
||||
}
|
||||
// The Background also carries the transparency lock, so it is tested first.
|
||||
if st.doc.is_background(id) || st.doc.layer(id)?.surface().is_some_and(|s| !s.format().alpha) {
|
||||
return Some(false);
|
||||
}
|
||||
st.doc.effective_locks(id).transparency.then_some(true)
|
||||
}
|
||||
|
||||
/// Remembers the choices of `result`. A forced Preserve Transparency is not among them, so the choice remembered
|
||||
/// before is kept for the next open.
|
||||
pub(crate) fn remember_blending(ctx: &egui::Context, result: &ParamResult) {
|
||||
let key = SaveKey::named(super::params::memory_scope(&result.key));
|
||||
let before = saved_value::<Option<DialogFields>>(ctx, &key).and_then(|saved| saved.get(PRESERVE).cloned());
|
||||
result.remember(ctx);
|
||||
if let Some(before) = before
|
||||
&& let Some(mut saved) = saved_value::<Option<DialogFields>>(ctx, &key)
|
||||
&& !saved.contains(PRESERVE)
|
||||
{
|
||||
saved.set(PRESERVE, before);
|
||||
set_saved_value(ctx, &key, Some(saved));
|
||||
}
|
||||
}
|
||||
|
||||
/// The engine params of [`blending_rows`].
|
||||
|
||||
@@ -16,7 +16,7 @@ fn app(mode: &str, depth: u32) -> Box<PhotocraftApp> {
|
||||
|
||||
/// The labels of the Mode row's disabled entries in the Fill and Stroke rows of `app`.
|
||||
fn greyed(app: &PhotocraftApp) -> Vec<&'static str> {
|
||||
let rows = blending_rows(app);
|
||||
let rows = blending_rows(app, None);
|
||||
let row = rows.iter().find(|p| p.key == "mode").unwrap();
|
||||
let ParamKind::Blend { modes, .. } = &row.kind else { panic!("Mode is a blend row") };
|
||||
assert_eq!(modes.len(), BlendMode::LAYER_MODES.len(), "every mode stays listed");
|
||||
@@ -67,8 +67,8 @@ fn without_a_document_nothing_is_greyed() {
|
||||
fn a_remembered_greyed_mode_opens_as_normal() {
|
||||
let mut saved = DialogFields::new();
|
||||
saved.set("mode", BlendMode::Darken.key().to_string());
|
||||
let lab = ParamDialog::remembered(&blending_rows(&app("lab", 8)), &saved);
|
||||
let lab = ParamDialog::remembered(&blending_rows(&app("lab", 8), None), &saved);
|
||||
assert_eq!(lab.text("mode"), None, "Darken is greyed in Lab 8-bit");
|
||||
let rgb = ParamDialog::remembered(&blending_rows(&app("rgb", 16)), &saved);
|
||||
let rgb = ParamDialog::remembered(&blending_rows(&app("rgb", 16), None), &saved);
|
||||
assert_eq!(rgb.text("mode"), Some(BlendMode::Darken.key()), "Darken stays in RGB 16-bit");
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use photocraft_color::BlendMode;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::dialogs::blend_options::{blending_params, blending_rows};
|
||||
use crate::dialogs::blend_options::{blending_params, blending_rows, forced_preserve_transparency, remember_blending};
|
||||
use crate::dialogs::params::{captured, open_param};
|
||||
|
||||
/// The command of the dialog, which is also its dialog key.
|
||||
@@ -40,8 +40,8 @@ pub(crate) fn hex(c: [f32; 3]) -> String {
|
||||
format!("#{:02x}{:02x}{:02x}", b(c[0]), b(c[1]), b(c[2]))
|
||||
}
|
||||
|
||||
/// The dialog's rows.
|
||||
fn rows(app: &PhotocraftApp, foreground: [f32; 3], first_pattern: Option<String>) -> Vec<Param> {
|
||||
/// The dialog's rows, with the Preserve Transparency the target forces.
|
||||
fn rows(app: &PhotocraftApp, foreground: [f32; 3], first_pattern: Option<String>, preserve: Option<bool>) -> Vec<Param> {
|
||||
let contents = CONTENTS.iter().map(|(k, l)| (k.to_string(), Label::from(tl!(l)))).collect();
|
||||
let mut rows = vec![
|
||||
Param::new("contents", tl!("Contents:"), ParamKind::choice(contents, Some("foreground".into()))),
|
||||
@@ -49,12 +49,13 @@ fn rows(app: &PhotocraftApp, foreground: [f32; 3], first_pattern: Option<String>
|
||||
Param::new("pattern", tl!("Custom Pattern:"), ParamKind::pattern(first_pattern)).visible_when("contents", "pattern"),
|
||||
Param::new("colorAdaptation", tl!("Color Adaptation"), ParamKind::bool(true)).visible_when("contents", "contentAware"),
|
||||
];
|
||||
rows.extend(blending_rows(app));
|
||||
rows.extend(blending_rows(app, preserve));
|
||||
rows
|
||||
}
|
||||
|
||||
/// Photoshop's Fill defaults, which Alt+Reset restores instead of the last-used values.
|
||||
fn defaults(foreground: [f32; 3], first_pattern: Option<String>, inks: Option<[f32; 4]>) -> DialogFields {
|
||||
/// Photoshop's Fill defaults, which Alt+Reset restores instead of the last-used values; a forced Preserve Transparency
|
||||
/// keeps its state.
|
||||
fn defaults(foreground: [f32; 3], first_pattern: Option<String>, inks: Option<[f32; 4]>, preserve: Option<bool>) -> DialogFields {
|
||||
let mut f = DialogFields::new();
|
||||
f.set("contents", "foreground");
|
||||
f.set("color", FieldValue::Color(foreground));
|
||||
@@ -65,7 +66,7 @@ fn defaults(foreground: [f32; 3], first_pattern: Option<String>, inks: Option<[f
|
||||
f.set("colorAdaptation", true);
|
||||
f.set("mode", BlendMode::Normal.key().to_string());
|
||||
f.set("opacity", 100.0);
|
||||
f.set("preserveTransparency", false);
|
||||
f.set("preserveTransparency", preserve.unwrap_or(false));
|
||||
f
|
||||
}
|
||||
|
||||
@@ -75,6 +76,7 @@ pub fn open(app: &mut PhotocraftApp) -> DialogId {
|
||||
let target = target.get("target").cloned().unwrap_or_else(|| crate::canvas::paint_target(app));
|
||||
// Alpha and Quick Mask belong to the document, independently of its active layer.
|
||||
let layer_bound = target.as_str() != Some("quickMask") && target.get("channel").is_none();
|
||||
let preserve = forced_preserve_transparency(app, &target);
|
||||
let mut held = json!({ "target": target });
|
||||
if let Some(st) = app.session.active() {
|
||||
held["document"] = json!(st.doc.id.0);
|
||||
@@ -85,9 +87,9 @@ pub fn open(app: &mut PhotocraftApp) -> DialogId {
|
||||
let [r, g, b, _] = app.session.tools.foreground;
|
||||
let first = app.session.patterns.items.first().map(|p| p.id.clone());
|
||||
let patterns = crate::panels::preset_browser::pattern_swatches(app);
|
||||
let rows = rows(app, [r, g, b], first.clone());
|
||||
let rows = rows(app, [r, g, b], first.clone(), preserve);
|
||||
let inks = crate::color_picker_ui::ink_value(craft::theme::Srgba::rgb(r, g, b), app.session.tools.picked_role_cmyk(0));
|
||||
let reset = defaults([r, g, b], first, app.session.tools.picked_role_cmyk(0));
|
||||
let reset = defaults([r, g, b], first, app.session.tools.picked_role_cmyk(0), preserve);
|
||||
let mut fields = DialogFields::new();
|
||||
let remembered: Option<DialogFields> = MemoryStage::peek_saved(app.ctx(), &SaveKey::named(REMEMBER_INKS));
|
||||
let remembered_inks = remembered.as_ref().and_then(|saved| saved.get(&crate::color_picker_ui::ink_field("color"))).cloned();
|
||||
@@ -154,7 +156,7 @@ pub(crate) fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamRes
|
||||
let captured = captured(app, &result.key);
|
||||
match app.run(COMMAND, params(&result.fields, &captured)) {
|
||||
Ok(_) => {
|
||||
result.remember(ctx);
|
||||
remember_blending(ctx, &result);
|
||||
// The framework remembers visible parameter rows only; keep their ink companion in the same saved tier.
|
||||
let mut inks = DialogFields::new();
|
||||
if let Some(value) = result.fields.get(&crate::color_picker_ui::ink_field("color")) {
|
||||
@@ -166,5 +168,7 @@ pub(crate) fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamRes
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod preserve_transparency_state_tests;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -0,0 +1,60 @@
|
||||
//! Preserve Transparency in Fill and Stroke follows the target layer (#14651): greyed off on the Background, greyed on
|
||||
//! with Lock Transparent Pixels, and neither forced state replaces the remembered choice.
|
||||
|
||||
use craft::ui::patterns::form_dialogs::HostedParamDialog;
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
use crate::smart_filter_dialog::tests::{cancel, confirm, set};
|
||||
|
||||
/// A document with a white Background and a pixel layer "Paint" above it, active, with a selection to fill or stroke.
|
||||
fn app() -> (Box<PhotocraftApp>, photocraft_doc::LayerId, photocraft_doc::LayerId) {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap();
|
||||
let background = app.session.active().unwrap().active_layer.unwrap();
|
||||
app.run("layer.new.layer", json!({"name": "Paint"})).unwrap();
|
||||
let paint = app.session.active().unwrap().active_layer.unwrap();
|
||||
app.run("select.rect", json!({"x": 5, "y": 5, "width": 20, "height": 15})).unwrap();
|
||||
(app, background, paint)
|
||||
}
|
||||
|
||||
/// The box's value in the open dialog `id`, and whether it takes a change.
|
||||
fn preserve(app: &mut PhotocraftApp, id: DialogId) -> (bool, bool) {
|
||||
let dialog = app.framework.dialogs.get_by_id::<HostedParamDialog>(id).expect("a hosted dialog");
|
||||
let on = dialog.fields().bool("preserveTransparency").expect("the box has a value");
|
||||
let ctx = app.ctx().clone();
|
||||
let editable = app.framework.dialogs.set_json_field(&ctx, id, "preserveTransparency", json!(on)).is_ok();
|
||||
(on, editable)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_box_is_greyed_at_the_targets_state_and_the_remembered_choice_survives() {
|
||||
for (name, open) in [("Fill", open as fn(&mut PhotocraftApp) -> DialogId), ("Stroke", crate::stroke_ui::open)] {
|
||||
let (mut app, background, paint) = app();
|
||||
let id = open(&mut app);
|
||||
assert_eq!(preserve(&mut app, id), (false, true), "{name}: a pixel layer offers the default");
|
||||
set(&mut app, id, "preserveTransparency", json!(true));
|
||||
confirm(&mut app, id);
|
||||
|
||||
app.session.select_layer(background).unwrap();
|
||||
let id = open(&mut app);
|
||||
assert_eq!(preserve(&mut app, id), (false, false), "{name}: greyed off on the Background");
|
||||
confirm(&mut app, id);
|
||||
|
||||
app.session.select_layer(paint).unwrap();
|
||||
let id = open(&mut app);
|
||||
assert_eq!(preserve(&mut app, id), (true, true), "{name}: the Background's forced state is not remembered");
|
||||
set(&mut app, id, "preserveTransparency", json!(false));
|
||||
confirm(&mut app, id);
|
||||
|
||||
app.run("layer.toggleLockTransparency", json!({})).unwrap();
|
||||
let id = open(&mut app);
|
||||
assert_eq!(preserve(&mut app, id), (true, false), "{name}: greyed on with Lock Transparent Pixels");
|
||||
confirm(&mut app, id);
|
||||
|
||||
app.run("layer.toggleLockTransparency", json!({})).unwrap();
|
||||
let id = open(&mut app);
|
||||
assert_eq!(preserve(&mut app, id), (false, true), "{name}: the lock's forced state is not remembered");
|
||||
cancel(&mut app, id);
|
||||
}
|
||||
}
|
||||
@@ -313,8 +313,8 @@ fn reset_fill_restores_the_original_native_inks_for_the_same_rgb() {
|
||||
use craft::ui::testing::Fixture;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
let original = [0., 0., 0., 1.];
|
||||
let reset = defaults([0.; 3], None, Some(original));
|
||||
let rows = rows(&app(), [0.; 3], None);
|
||||
let reset = defaults([0.; 3], None, Some(original), None);
|
||||
let rows = rows(&app(), [0.; 3], None, None);
|
||||
let fields = Rc::new(RefCell::new(reset.clone()));
|
||||
let shown = fields.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
|
||||
@@ -11,7 +11,7 @@ use craft::ui::runtime::memory::SaveKey;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::dialogs::blend_options::{blending_params, blending_rows};
|
||||
use crate::dialogs::blend_options::{blending_params, blending_rows, forced_preserve_transparency, remember_blending};
|
||||
use crate::dialogs::fill_ui::hex;
|
||||
use crate::dialogs::params::{captured, open_param};
|
||||
|
||||
@@ -20,15 +20,15 @@ pub const COMMAND: &str = "edit.stroke";
|
||||
const REMEMBER: &str = "photocraft.dialog.edit.stroke";
|
||||
const LOCATIONS: [(&str, &str); 3] = [("inside", "Inside"), ("center", "Center"), ("outside", "Outside")];
|
||||
|
||||
/// The dialog's rows.
|
||||
fn rows(app: &PhotocraftApp, foreground: [f32; 3]) -> Vec<Param> {
|
||||
/// The dialog's rows, with the Preserve Transparency the target forces.
|
||||
fn rows(app: &PhotocraftApp, foreground: [f32; 3], preserve: Option<bool>) -> Vec<Param> {
|
||||
let locations = LOCATIONS.iter().map(|(k, l)| (k.to_string(), Label::from(tl!(l)))).collect();
|
||||
let mut rows = vec![
|
||||
Param::new("width", tl!("Width:"), ParamKind::number(Some(1.0), Some(250.0), 1.0, 1.0, 0)).unit(UnitKind::Pixels),
|
||||
Param::new("color", tl!("Color:"), ParamKind::color(Some(foreground))),
|
||||
Param::new("location", tl!("Location:"), ParamKind::radio(locations, Some("center".into()))),
|
||||
];
|
||||
rows.extend(blending_rows(app));
|
||||
rows.extend(blending_rows(app, preserve));
|
||||
rows
|
||||
}
|
||||
|
||||
@@ -36,13 +36,14 @@ fn rows(app: &PhotocraftApp, foreground: [f32; 3]) -> Vec<Param> {
|
||||
pub fn open(app: &mut PhotocraftApp) -> DialogId {
|
||||
let target = app.with_mask_target(COMMAND, json!({}));
|
||||
let target = target.get("target").cloned().unwrap_or_else(|| crate::canvas::paint_target(app));
|
||||
let preserve = forced_preserve_transparency(app, &target);
|
||||
let mut held = json!({ "target": target });
|
||||
if let Some(st) = app.session.active() {
|
||||
held["document"] = json!(st.doc.id.0);
|
||||
held["layer"] = json!(st.active_layer);
|
||||
}
|
||||
let [r, g, b, _] = app.session.tools.foreground;
|
||||
let rows = rows(app, [r, g, b]);
|
||||
let rows = rows(app, [r, g, b], preserve);
|
||||
let title = Label::from(tl!("Stroke"));
|
||||
open_param(app, COMMAND, DialogFields::new(), held, move |fields| {
|
||||
ParamDialog::new(COMMAND, title.clone(), Cow::Owned(rows.clone())).values(Bind::bound(fields)).remember(SaveKey::named(REMEMBER))
|
||||
@@ -86,7 +87,7 @@ pub(crate) fn check(app: &mut PhotocraftApp, result: &ParamResult) -> Result<(),
|
||||
pub(crate) fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamResult) {
|
||||
let captured = captured(app, &result.key);
|
||||
match app.run(COMMAND, params(&result.fields, &captured)) {
|
||||
Ok(_) => result.remember(ctx),
|
||||
Ok(_) => remember_blending(ctx, &result),
|
||||
Err(e) => crate::notices::error(app, e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ fn stroke_choices_apply_on_confirm_and_cancel_does_not_modify_document() {
|
||||
/// #15539: Width shows px and Opacity % after their numbers.
|
||||
#[test]
|
||||
fn width_and_opacity_declare_their_units() {
|
||||
let rows = rows(&app(), [0.0, 0.0, 0.0]);
|
||||
let rows = rows(&app(), [0.0, 0.0, 0.0], None);
|
||||
let unit = |key: &str| rows.iter().find(|p| p.key == key).and_then(|p| p.unit);
|
||||
assert_eq!(unit("width"), Some(UnitKind::Pixels));
|
||||
assert_eq!(unit("opacity"), Some(UnitKind::Percent));
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
//! Layer › New lists Layer from Background… or Background from Layer in one slot, never both (#16761).
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
use crate::control::{ControlRequest, Reply};
|
||||
|
||||
const LAYER_FROM: &str = "layer.new.layerFromBackground";
|
||||
const BACKGROUND_FROM: &str = "layer.new.backgroundFromLayer";
|
||||
|
||||
fn app(doc: bool) -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
if doc {
|
||||
app.run("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
app.sync_views();
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
/// The Layer › New rows the menu bar shows, as (id, label, enabled).
|
||||
fn layer_new(app: &PhotocraftApp) -> Vec<(String, String, bool)> {
|
||||
menu_rows(app).into_iter().filter(|r| r.path == ["Layer", "New"]).map(|r| (r.command.id, r.label, r.enabled)).collect()
|
||||
}
|
||||
|
||||
/// Which of the two entries `ui.menu.list` and Help search report.
|
||||
fn listed_and_searched(app: &mut PhotocraftApp) -> (Vec<String>, Vec<String>) {
|
||||
let ctx = app.ctx().clone();
|
||||
let (req, _rx) = ControlRequest::new("ui.menu.list", json!({}));
|
||||
let Reply::Done(listed) = crate::control::handle(app, &ctx, &req) else { panic!("ui.menu.list: expected an immediate reply") };
|
||||
let pair = |id: &str| id == LAYER_FROM || id == BACKGROUND_FROM;
|
||||
let listed = listed["result"].as_array().unwrap().iter().filter_map(|it| it["id"].as_str()).filter(|id| pair(id)).map(String::from).collect();
|
||||
let searched = crate::menus::help_entries(app, &ctx).iter().map(|e| e.command().id.clone()).filter(|id| pair(id)).collect();
|
||||
(listed, searched)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_a_background_only_layer_from_background_is_listed() {
|
||||
let mut a = app(true);
|
||||
assert!(a.session.active().unwrap().doc.background().is_some(), "a new white document has a Background");
|
||||
let rows = layer_new(&a);
|
||||
assert_eq!(rows[1].0, LAYER_FROM, "second entry of Layer › New: {rows:?}");
|
||||
assert!(rows[1].2, "Layer from Background… runs with the Background active");
|
||||
assert!(rows.iter().all(|r| r.0 != BACKGROUND_FROM), "{rows:?}");
|
||||
let (listed, searched) = listed_and_searched(&mut a);
|
||||
assert_eq!(listed, [LAYER_FROM]);
|
||||
assert_eq!(searched, [LAYER_FROM]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_background_only_background_from_layer_is_listed_in_that_slot() {
|
||||
let mut a = app(true);
|
||||
a.run(LAYER_FROM, json!({})).unwrap();
|
||||
assert!(a.session.active().unwrap().doc.background().is_none());
|
||||
let rows = layer_new(&a);
|
||||
assert_eq!(rows[1].0, BACKGROUND_FROM, "Background from Layer takes the same slot: {rows:?}");
|
||||
assert_eq!(rows[1].1, "Background from Layer");
|
||||
assert!(rows[1].2, "it runs on the former Background");
|
||||
assert!(rows.iter().all(|r| r.0 != LAYER_FROM), "{rows:?}");
|
||||
let (listed, searched) = listed_and_searched(&mut a);
|
||||
assert_eq!(listed, [BACKGROUND_FROM]);
|
||||
assert_eq!(searched, [BACKGROUND_FROM]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_no_document_the_slot_reads_layer_from_background_greyed() {
|
||||
let a = app(false);
|
||||
let rows = layer_new(&a);
|
||||
assert_eq!(rows[1].0, LAYER_FROM, "{rows:?}");
|
||||
assert!(!rows[1].2, "greyed with no document");
|
||||
assert!(rows.iter().all(|r| r.0 != BACKGROUND_FROM), "{rows:?}");
|
||||
}
|
||||
|
||||
/// The Keyboard Shortcuts dialog reads the rows before the swap, so either command can take a shortcut at any time.
|
||||
#[test]
|
||||
fn the_keyboard_shortcuts_rows_keep_both_entries() {
|
||||
for doc in [false, true] {
|
||||
let rows = base_rows(&app(doc));
|
||||
for id in [LAYER_FROM, BACKGROUND_FROM] {
|
||||
assert!(rows.iter().any(|r| r.command.id == id), "doc {doc}: {id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,9 +341,15 @@ pub fn base_rows(app: &PhotocraftApp) -> Vec<Row> {
|
||||
rows
|
||||
}
|
||||
|
||||
/// [`base_rows`] with Edit › Menus applied: hidden rows dropped and the chosen colours set.
|
||||
/// [`base_rows`] as the menus show them: Layer › New's two Background entries narrowed to the one that applies, then
|
||||
/// Edit › Menus applied (hidden rows dropped and the chosen colours set).
|
||||
pub fn menu_rows(app: &PhotocraftApp) -> Vec<Row> {
|
||||
let mut rows = base_rows(app);
|
||||
// Layer › New lists Layer from Background… while the document has a Background (or none is open) and Background
|
||||
// from Layer while it has none, in the same slot (#16761). The Keyboard Shortcuts dialog keeps both.
|
||||
let background = app.session.active().is_none_or(|st| st.doc.background().is_some());
|
||||
let other = if background { "layer.new.backgroundFromLayer" } else { "layer.new.layerFromBackground" };
|
||||
rows.retain(|r| r.command.id != other);
|
||||
let prefs = app.session.prefs();
|
||||
let hidden = prefs.menus.hidden.iter().filter(|id| photocraft_engine::prefs::MenuCustomization::hideable(id)).cloned();
|
||||
let colors = if prefs.interface.show_menu_colors {
|
||||
@@ -453,3 +459,7 @@ fn build(app: &PhotocraftApp) -> Built {
|
||||
let laid = layout(&bar, target(app.ctx()), &options).bar;
|
||||
Built { rows, source: bar, bar: laid }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "background_entry_swap_tests.rs"]
|
||||
mod background_entry_swap_tests;
|
||||
@@ -38,7 +38,7 @@ fn mode_tool_name(tool: Tool) -> Option<&'static str> {
|
||||
}
|
||||
|
||||
/// The tool's name in the alerts, for the tools whose wording was measured: the Brush, the
|
||||
/// Sharpen tool (#12952), the Sponge (#13030), the Smudge tool (#12965), the Art History Brush
|
||||
/// Sharpen tool (#12952), the Sponge (#13030), the Smudge tool (#12965), the Burn tool (#12672), the Art History Brush
|
||||
/// (#12638) and the Classic gradient (the live Gradient makes a fill layer and isn't measured, #12017).
|
||||
pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
|
||||
match tool {
|
||||
@@ -50,6 +50,7 @@ pub fn tool_name(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
|
||||
Tool::Smudge => Some(tl!("smudge tool")),
|
||||
// The Spot Healing Brush (#12581).
|
||||
Tool::SpotHealing => Some(tl!("spot healing brush")),
|
||||
Tool::Burn => Some(tl!("burn tool")),
|
||||
Tool::ArtHistoryBrush => Some(tl!("art history brush")),
|
||||
Tool::Gradient if app.ui.tool_options.gradient_classic => Some(tl!("gradient tool")),
|
||||
_ => None,
|
||||
@@ -125,11 +126,11 @@ fn layer_refusal(app: &PhotocraftApp, tool: Tool) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `locks` refuse `tool`: Lock All, and for the Sharpen, Sponge and Smudge tools and the
|
||||
/// Whether `locks` refuse `tool`: Lock All, and for the Sharpen, Sponge, Smudge and Burn tools and the
|
||||
/// Art History Brush Lock Image Pixels as well (measured for them; the Brush keeps today's
|
||||
/// behaviour there).
|
||||
fn locked(locks: photocraft_doc::Locks, tool: Tool) -> bool {
|
||||
locks.all || (matches!(tool, Tool::Sharpen | Tool::Sponge | Tool::Smudge | Tool::ArtHistoryBrush | Tool::MagicEraser) && locks.pixels)
|
||||
locks.all || (matches!(tool, Tool::Sharpen | Tool::Sponge | Tool::Smudge | Tool::Burn | Tool::ArtHistoryBrush | Tool::MagicEraser) && locks.pixels)
|
||||
}
|
||||
|
||||
/// A Spot Healing press on an empty pixel layer with Sample All Layers off (#12581): when that layer is hidden, the
|
||||
@@ -171,3 +172,7 @@ mod remove_hidden_layer_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "art_history_refusal_alert_tests.rs"]
|
||||
mod art_history_refusal_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../burn_refusal_alert_tests.rs"]
|
||||
mod burn_refusal_alert_tests;
|
||||
Reference in new issue
Block a user