Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Show Technique and Range in the glow Layer Style pages (#6698)

Hector Villarreal5a5de0e73d9d
diff --git a/crates/engine/src/layer_style.rs b/crates/engine/src/layer_style.rs
index 8933f838b..bfaa756eb 100644
--- a/crates/engine/src/layer_style.rs
+++ b/crates/engine/src/layer_style.rs
@@ -86,10 +86,10 @@ pub fn effect_defaults(kind: &str) -> Value {
json!({"blend": "Multiply", "color": "#000000", "opacity": 75, "angle": 120, "useGlobalLight": true, "distance": 5, "choke": 0, "size": 5, "contour": "Linear", "antiAlias": false, "noise": 0})
}
"outerGlow" => {
- json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "spread": 0, "size": 5, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0})
+ json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "technique": "softer", "spread": 0, "size": 5, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0})
}
"innerGlow" => {
- json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "source": "edge", "choke": 0, "size": 5, "contour": "Linear", "antiAlias": false, "noise": 0})
+ json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "technique": "softer", "source": "edge", "choke": 0, "size": 5, "range": 50, "contour": "Linear", "antiAlias": false, "noise": 0})
}
"stroke" => json!({"size": 3, "position": "outside", "blend": "Normal", "opacity": 100, "color": "#000000"}),
"colorOverlay" => json!({"blend": "Normal", "color": "#ff0000", "opacity": 100}),
@@ -1007,7 +1007,7 @@ pub fn specs() -> Vec<CommandSpec> {
style_cmd!(
"innerGlow",
"Inner Glow…",
- r##"{"color":"#rrggbb","opacity":0..100=75,"blend":str="screen","technique":"softer|precise","source":"edge|center","choke":0..100,"size":px,"contour":name|curve,"antiAlias":bool,"noise":0..100,"add":bool}"##
+ r##"{"color":"#rrggbb","opacity":0..100=75,"blend":str="screen","technique":"softer|precise","source":"edge|center","choke":0..100,"size":px,"range":0..100,"contour":name|curve,"antiAlias":bool,"noise":0..100,"add":bool}"##
),
style_cmd!(
"stroke",
diff --git a/crates/ui-egui/src/layer_style.rs b/crates/ui-egui/src/layer_style.rs
index d876c1827..f7be218b6 100644
--- a/crates/ui-egui/src/layer_style.rs
+++ b/crates/ui-egui/src/layer_style.rs
@@ -14,7 +14,7 @@
//! the page-only `blendIfChannel`; `channelNames`: the document's colour channels.
use egui::{Color32, RichText, Sense, Stroke, StrokeKind, vec2};
-use photocraft_doc::effects::{FxPaint, GlowSource, StrokePosition};
+use photocraft_doc::effects::{FxPaint, GlowSource, GlowTechnique, StrokePosition};
use photocraft_doc::{Effect, Layer};
use serde_json::{Map, Value, json};
@@ -89,6 +89,7 @@ fn spec(kind: &str) -> &'static [(&'static str, &'static str, P)] {
const TECHNIQUE: &[(&str, &str)] = &[("smooth", "Smooth"), ("chiselHard", "Chisel Hard"), ("chiselSoft", "Chisel Soft")];
const DIR: &[(&str, &str)] = &[("up", "Up"), ("down", "Down")];
const SRC: &[(&str, &str)] = &[("edge", "Edge"), ("center", "Center")];
+ const GLOW_TECHNIQUE: &[(&str, &str)] = &[("softer", "Softer"), ("precise", "Precise")];
const CONTOUR: P = P::Contour(Some("antiAlias"));
match kind {
"dropShadow" => &[
@@ -116,24 +117,28 @@ fn spec(kind: &str) -> &'static [(&'static str, &'static str, P)] {
("contour", "Contour", CONTOUR),
("noise", "Noise", P::Slider(0.0, 100.0, "%")),
],
+ // Photoshop's order (#6698): Technique before the spread or choke, Range after the contour.
"outerGlow" => &[
("blend", "Blend Mode", P::Blend),
("opacity", "Opacity", P::Slider(0.0, 100.0, "%")),
("color", "Color", P::Color),
+ ("technique", "Technique", P::Choice(GLOW_TECHNIQUE)),
("spread", "Spread", P::Slider(0.0, 100.0, "%")),
("size", "Size", P::Slider(0.0, 250.0, "px")),
- ("range", "Range", P::Slider(1.0, 100.0, "%")),
("contour", "Contour", CONTOUR),
+ ("range", "Range", P::Slider(1.0, 100.0, "%")),
("noise", "Noise", P::Slider(0.0, 100.0, "%")),
],
"innerGlow" => &[
("blend", "Blend Mode", P::Blend),
("opacity", "Opacity", P::Slider(0.0, 100.0, "%")),
("color", "Color", P::Color),
+ ("technique", "Technique", P::Choice(GLOW_TECHNIQUE)),
("source", "Source", P::Choice(SRC)),
("choke", "Choke", P::Slider(0.0, 100.0, "%")),
("size", "Size", P::Slider(0.0, 250.0, "px")),
("contour", "Contour", CONTOUR),
+ ("range", "Range", P::Slider(1.0, 100.0, "%")),
("noise", "Noise", P::Slider(0.0, 100.0, "%")),
],
"stroke" => &[
@@ -243,6 +248,7 @@ fn values_of(e: &Effect, light: f32) -> Value {
} else {
drop_keys(&mut v, &["color"]);
}
+ set(&mut v, "technique", json!(if g.technique == GlowTechnique::Precise { "precise" } else { "softer" }));
set(&mut v, if matches!(e, Effect::OuterGlow(_)) { "spread" } else { "choke" }, json!((g.spread * 100.0).round()));
set(&mut v, "size", json!(g.size));
set(&mut v, "range", json!((g.range * 100.0).round()));
@@ -1886,6 +1892,48 @@ mod tests {
assert_eq!(source(&s), Some(GlowSource::Center), "OK keeps the source");
}
+ /// #6698: Inner Glow lacked Photoshop's Technique and Range, Outer Glow its Technique. They
+ /// show in Photoshop's order, the dialog loads them, and OK keeps them.
+ #[test]
+ fn glows_show_and_keep_technique_and_range() {
+ let keys = |kind: &str| spec(kind).iter().map(|(k, _, _)| *k).collect::<Vec<_>>();
+ assert_eq!(keys("innerGlow"), ["blend", "opacity", "color", "technique", "source", "choke", "size", "contour", "range", "noise"]);
+ assert_eq!(keys("outerGlow"), ["blend", "opacity", "color", "technique", "spread", "size", "contour", "range", "noise"]);
+ let mut s = session();
+ s.execute("layer.layerStyle.innerGlow", json!({"technique": "precise", "range": 30})).unwrap();
+ s.execute("layer.layerStyle.outerGlow", json!({"technique": "precise"})).unwrap();
+ let glows = |s: &photocraft_engine::Session| {
+ let d = s.active().unwrap();
+ let id = d.active_layer.unwrap();
+ d.doc
+ .layer(id)
+ .unwrap()
+ .effects
+ .items
+ .iter()
+ .filter_map(|e| match e {
+ Effect::InnerGlow(g) | Effect::OuterGlow(g) => Some((kind_of(e), g.technique, (g.range * 100.0).round())),
+ _ => None,
+ })
+ .collect::<Vec<_>>()
+ };
+ let expected = [("outerGlow", GlowTechnique::Precise, 50.0), ("innerGlow", GlowTechnique::Precise, 30.0)];
+ let mut have = glows(&s);
+ have.sort_by_key(|g| g.0);
+ let mut want = expected.to_vec();
+ want.sort_by_key(|g| g.0);
+ assert_eq!(have, want);
+ let st = s.active().unwrap();
+ let id = st.active_layer.unwrap();
+ let f = initial_fields(st.doc.layer(id).unwrap(), None, st.doc.global_light.angle);
+ let inner = effects_of(&f).iter().find(|e| e["kind"] == json!("innerGlow")).unwrap().clone();
+ assert_eq!((&inner["params"]["technique"], &inner["params"]["range"]), (&json!("precise"), &json!(30.0)), "the dialog shows them");
+ apply(&f, |cmd, p| s.execute(cmd, p).map_err(|e| e.to_string())).unwrap();
+ let mut have = glows(&s);
+ have.sort_by_key(|g| g.0);
+ assert_eq!(have, want, "OK keeps them");
+ }
+
#[test]
fn drop_shadow_angle_reaches_the_effect() {
// #350: the Angle slider was dead — the dialog never sent `useGlobalLight`, so the engine