diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 6de12a31a2..52c44dee3a 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -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 diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index cfac9c383c..9a6e08fece 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -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 diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index d9d11113f7..f6dcb30743 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -743,6 +743,7 @@ Amount 量 Anchor: 基準位置: Angle 角度 + Use Global Light グローバルライトを使用 Angle Gradient 円錐形グラデーション Angle Jitter 角度のジッター Answer the unsaved-changes prompt first 先に未保存の変更の確認に答えてください diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index ca3701fedd..16cb2540a1 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -1081,6 +1081,7 @@ W Ш H В Angle Угол + Use Global Light Использовать общий свет Scale Масштаб X X Y Y diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 7c02912422..5697eaeacb 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -741,6 +741,7 @@ Amount 数量 Anchor: 定位点: Angle 角度 + Use Global Light 使用全局光源 Angle Gradient 角度渐变 Angle Jitter 角度抖动 Answer the unsaved-changes prompt first 请先处理未保存更改的提示 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index e0b6a53ebe..da4a171ae3 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -744,6 +744,7 @@ Amount 總量 Anchor: 錨點: Angle 角度 + Use Global Light 使用全域光源 Angle Gradient 角度漸層 Angle Jitter 角度快速變換 Answer the unsaved-changes prompt first 請先回應未儲存變更的提示 diff --git a/crates/ui-egui/src/layer_style.rs b/crates/ui-egui/src/layer_style.rs index 23ee7eb307..1ff2607dad 100644 --- a/crates/ui-egui/src/layer_style.rs +++ b/crates/ui-egui/src/layer_style.rs @@ -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 { 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, mut run: impl FnMut(&str, Value) -> Result = 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); + } }