Layer Style: the changed global-light angle wins; translate "Use Global Light"

Follow-up to #411. With two effects on the global light (Bevel & Emboss
and Drop Shadow, common on type), Apply took the angle of whichever was
applied last, so changing the Bevel's angle was undone by the Drop
Shadow's unchanged one. The dialog now records the light angle it opened
with (`globalLight` field), and Apply moves the shared light only to an
angle that differs from it; an untouched angle adds no Global Light
history step. "Use Global Light" is in every catalog, and the comment no
longer names another product.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
bflatasticandClaude Opus 5.5 committed 2026-10-07 10:54:22 +07:00
1 parent f071c3a33f
commit f48c2ea86b
7 files changed
+61 -7

No files matched your search

+1
View File
@@ -753,6 +753,7 @@
Amount Míra
Anchor: Ukotvení:
Angle Úhel
Use Global Light Použít globální světlo
Angle Gradient Úhlový přechod
Angle Jitter Kolísání úhlu
Answer the unsaved-changes prompt first Nejprve odpovězte na dotaz k neuloženým změnám
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -738,6 +738,7 @@
Amount Cantidad
Anchor: Anclaje:
Angle Ángulo
Use Global Light Usar luz global
Angle Gradient Degradado angular
Angle Jitter Variación de ángulo
Answer the unsaved-changes prompt first Responda primero al aviso de cambios sin guardar
Can't render this file because it contains an unexpected character in line 4 and column 47.
+1
View File
@@ -743,6 +743,7 @@
Amount 量
Anchor: 基準位置:
Angle 角度
Use Global Light グローバルライトを使用
Angle Gradient 円錐形グラデーション
Angle Jitter 角度のジッター
Answer the unsaved-changes prompt first 先に未保存の変更の確認に答えてください
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -1081,6 +1081,7 @@
W Ш
H В
Angle Угол
Use Global Light Использовать общий свет
Scale Масштаб
X X
Y Y
Can't render this file because it contains an unexpected character in line 6 and column 47.
+1
View File
@@ -741,6 +741,7 @@
Amount 数量
Anchor: 定位点:
Angle 角度
Use Global Light 使用全局光源
Angle Gradient 角度渐变
Angle Jitter 角度抖动
Answer the unsaved-changes prompt first 请先处理未保存更改的提示
1 # Simplified Chinese (zh-hans) catalog. UTF-8, TAB-separated columns:
741
742
743
744
745
746
747
+1
View File
@@ -744,6 +744,7 @@
Amount 總量
Anchor: 錨點:
Angle 角度
Use Global Light 使用全域光源
Angle Gradient 角度漸層
Angle Jitter 角度快速變換
Answer the unsaved-changes prompt first 請先回應未儲存變更的提示
Can't render this file because it contains an unexpected character in line 6 and column 47.
+55 -7
View File
@@ -137,8 +137,12 @@ fn spec(kind: &str) -> &'static [(&'static str, &'static str, P)] {
fn defaults(kind: &str) -> Value {
match kind {
"dropShadow" => json!({"blend": "Multiply", "color": "#000000", "opacity": 75, "angle": 120, "useGlobalLight": true, "distance": 5, "spread": 0, "size": 5, "knocksOut": true}),
"innerShadow" => json!({"blend": "Multiply", "color": "#000000", "opacity": 75, "angle": 120, "useGlobalLight": true, "distance": 5, "choke": 0, "size": 5}),
"dropShadow" => {
json!({"blend": "Multiply", "color": "#000000", "opacity": 75, "angle": 120, "useGlobalLight": true, "distance": 5, "spread": 0, "size": 5, "knocksOut": true})
}
"innerShadow" => {
json!({"blend": "Multiply", "color": "#000000", "opacity": 75, "angle": 120, "useGlobalLight": true, "distance": 5, "choke": 0, "size": 5})
}
"outerGlow" => json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "spread": 0, "size": 5, "range": 50}),
"innerGlow" => json!({"blend": "Screen", "opacity": 75, "color": "#ffffbe", "source": "edge", "choke": 0, "size": 5}),
"stroke" => json!({"size": 3, "position": "outside", "blend": "Normal", "opacity": 100, "color": "#000000"}),
@@ -147,7 +151,9 @@ fn defaults(kind: &str) -> Value {
json!({"blend": "Normal", "opacity": 100, "from": "#000000", "to": "#ffffff", "reverse": false, "style": "linear", "angle": 90, "scale": 100})
}
"patternOverlay" => json!({"blend": "Normal", "opacity": 100, "pattern": "", "angle": 0, "scale": 100, "link": true}),
"bevelEmboss" => json!({"style": "inner", "depth": 100, "direction": "up", "size": 5, "soften": 0, "angle": 120, "useGlobalLight": true, "altitude": 30}),
"bevelEmboss" => {
json!({"style": "inner", "depth": 100, "direction": "up", "size": 5, "soften": 0, "angle": 120, "useGlobalLight": true, "altitude": 30})
}
"satin" => json!({"blend": "Multiply", "color": "#000000", "opacity": 50, "angle": 19, "distance": 11, "size": 14, "invert": true}),
_ => json!({}),
}
@@ -264,6 +270,9 @@ fn values_of(e: &Effect, light: f32) -> Value {
pub fn initial_fields(layer: &Layer, select: Option<&str>, light: f32) -> Map<String, Value> {
let mut f = Map::new();
f.insert("layer".into(), json!(layer.id.0));
// The light angle the dialog opened with: Apply moves the shared light only to an angle the
// user changed (see `apply`).
f.insert("globalLight".into(), json!(light));
f.insert(
format!("p:{BLENDING}"),
json!({"blend": layer.blend.label(), "opacity": (layer.opacity * 100.0).round(), "fillOpacity": (layer.fill_opacity * 100.0).round()}),
@@ -321,15 +330,22 @@ fn apply(f: &Map<String, Value>, mut run: impl FnMut(&str, Value) -> Result<Valu
run("layer.layerStyle.blendingOptions", p)?;
}
let _ = run("layer.layerStyle.clear", json!({"layer": layer}));
// An effect lit by the global light follows the document's light angle, so the Angle slider
// drives that shared angle (as in Photoshop) rather than the per-effect angle the compositor ignores.
// An effect lit by the global light follows the document's light angle, so its Angle slider
// drives that shared angle rather than the per-effect angle the compositor ignores. Several
// effects show the same shared angle: the one the user changed wins (the others still show the
// angle the dialog opened with), and an unchanged angle adds no history step.
let opened = f.get("globalLight").and_then(Value::as_f64);
let mut light_angle: Option<f64> = None;
for &(kind, _) in KINDS {
if f.get(&format!("on:{kind}")).and_then(Value::as_bool) == Some(true) {
let mut p = f.get(&format!("p:{kind}")).cloned().unwrap_or_else(|| json!({}));
p["layer"] = layer.clone();
if p.get("useGlobalLight").and_then(Value::as_bool) == Some(true) {
light_angle = p.get("angle").and_then(Value::as_f64);
if p.get("useGlobalLight").and_then(Value::as_bool) == Some(true)
&& let Some(angle) = p.get("angle").and_then(Value::as_f64)
&& light_angle.is_none()
&& opened.is_none_or(|o| (o - angle).abs() > 1e-6)
{
light_angle = Some(angle);
}
run(&format!("layer.layerStyle.{kind}"), p)?;
}
@@ -612,4 +628,36 @@ mod tests {
assert_eq!(f["p:dropShadow"]["useGlobalLight"], json!(true));
assert_eq!(f["p:dropShadow"]["angle"], json!(30.0));
}
#[test]
fn the_changed_global_light_angle_wins_and_an_unchanged_one_adds_no_step() {
let mut s = photocraft_engine::Session::new();
s.execute("file.new", json!({"width": 64, "height": 64})).unwrap();
s.execute("layer.new.layer", json!({})).unwrap();
s.execute("edit.fill", json!({"color": "#808080"})).unwrap();
let fields = |s: &photocraft_engine::Session| {
let st = s.active().unwrap();
let mut f = initial_fields(st.doc.layer(st.active_layer.unwrap()).unwrap(), Some("bevelEmboss"), st.doc.global_light.angle);
f.insert("on:bevelEmboss".into(), json!(true));
f.insert("on:dropShadow".into(), json!(true));
f
};
let light = |s: &photocraft_engine::Session| s.active().unwrap().doc.global_light.angle;
let (start, before) = (light(&s), s.active().unwrap().history.past_len());
// Bevel & Emboss is applied first, Drop Shadow last: a change to the Bevel's angle used to
// be overwritten by the Drop Shadow's unchanged one.
let mut f = fields(&s);
f.get_mut("p:bevelEmboss").unwrap()["angle"] = json!(45.0);
apply(&f, |cmd, p| s.execute(cmd, p).map_err(|e| e.to_string())).unwrap();
assert_eq!(light(&s), 45.0);
// Re-applying without touching any angle leaves the light (and its history step) alone.
let light_steps = |s: &photocraft_engine::Session| s.active().unwrap().history.entries().iter().filter(|e| *e == "Global Light").count();
let (lights, steps) = (light_steps(&s), s.active().unwrap().history.past_len());
assert_eq!(lights, 1);
let f = fields(&s);
apply(&f, |cmd, p| s.execute(cmd, p).map_err(|e| e.to_string())).unwrap();
assert_eq!(light(&s), 45.0);
assert_eq!(light_steps(&s), 1, "no second Global Light step");
assert!(before < steps && start != 45.0);
}
}