From 0939157d127d06c5eb892996714b8a55fa71ba47 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 17:37:56 -0800 Subject: [PATCH] 3D and Materials: the Lighting tab's widget moves lights around the object The panel's Lighting tab shows a sphere above the list of lights with every light of the selected 3D effect at its Rotation and Height, filled in front of the object and hollow behind it. Dragging a light moves it on its side of the object, previewed while the pointer is down and one undo step on release; a press selects it in the list. Move Light to Back and Move Light to Front change the selected light's side. Each light takes the keyboard focus, where the arrow keys move it (Shift steps 15 degrees), and screen readers name it with its settings. The widget sends effect.setParams like the light settings below it. --- crates/ui-egui/src/dialogs.rs | 1 + crates/ui-egui/src/dialogs/revolve.rs | 6 +- crates/ui-egui/src/dialogs/revolve_gizmo.rs | 4 +- crates/ui-egui/src/dialogs/revolve_lights.rs | 266 +++++++++++++++++++ crates/ui-egui/src/i18n/bg.tsv | 3 + crates/ui-egui/src/i18n/bs.tsv | 3 + crates/ui-egui/src/i18n/ca.tsv | 3 + crates/ui-egui/src/i18n/cs.tsv | 3 + crates/ui-egui/src/i18n/da.tsv | 3 + crates/ui-egui/src/i18n/de.tsv | 3 + crates/ui-egui/src/i18n/el.tsv | 3 + crates/ui-egui/src/i18n/es.tsv | 3 + crates/ui-egui/src/i18n/fi.tsv | 3 + crates/ui-egui/src/i18n/fr.tsv | 3 + crates/ui-egui/src/i18n/gu.tsv | 3 + crates/ui-egui/src/i18n/hi.tsv | 3 + crates/ui-egui/src/i18n/hu.tsv | 3 + crates/ui-egui/src/i18n/id.tsv | 3 + crates/ui-egui/src/i18n/it.tsv | 3 + crates/ui-egui/src/i18n/ja.tsv | 3 + crates/ui-egui/src/i18n/ka.tsv | 3 + crates/ui-egui/src/i18n/ko.tsv | 3 + crates/ui-egui/src/i18n/nl.tsv | 3 + crates/ui-egui/src/i18n/pl.tsv | 3 + crates/ui-egui/src/i18n/pt-br.tsv | 3 + crates/ui-egui/src/i18n/ru.tsv | 3 + crates/ui-egui/src/i18n/sv.tsv | 3 + crates/ui-egui/src/i18n/tr.tsv | 3 + crates/ui-egui/src/i18n/uk.tsv | 3 + crates/ui-egui/src/i18n/vi.tsv | 3 + crates/ui-egui/src/i18n/zh-hans.tsv | 3 + crates/ui-egui/src/i18n/zh-hant.tsv | 3 + crates/ui-egui/src/panels/tests_three_d.rs | 171 ++++++++++++ docs/target-app-parity.md | 1 + docs/three-d.md | 30 ++- 35 files changed, 559 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/dialogs/revolve_lights.rs diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 04e58d452e..d3d3ae6bd9 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -105,6 +105,7 @@ pub mod relink; pub mod rename_artboards; pub(crate) mod revolve; pub(crate) mod revolve_gizmo; +pub(crate) mod revolve_lights; pub mod safe_mode; pub mod saturate; pub mod save_brush_library; diff --git a/crates/ui-egui/src/dialogs/revolve.rs b/crates/ui-egui/src/dialogs/revolve.rs index de21c368bc..a547c8fbb7 100644 --- a/crates/ui-egui/src/dialogs/revolve.rs +++ b/crates/ui-egui/src/dialogs/revolve.rs @@ -362,6 +362,10 @@ fn lighting_controls(ui: &mut egui::Ui, d: &mut Dialog) { // A mixed Shading leaves the light settings on, for the effects that shade. ui.add_enabled_ui(flag(d, "shade", true) != Some(false), |ui| { lighting_presets(ui, d); + // The panel's lighting widget; the dialog moves lights with its rings on the artboard. + if d.bool("__panel") { + super::revolve_lights::show(ui, d); + } light_list(ui, d); let mut selected = selected_light(d); let before = light_record(&selected); @@ -429,7 +433,7 @@ const LIGHT_KEYS: [(&str, &str); 6] = [ ("behind", "lightBehind"), ]; -fn explicit_lights(d: &Dialog) -> Option<&Vec> { +pub(super) fn explicit_lights(d: &Dialog) -> Option<&Vec> { d.fields.get("lights").and_then(Value::as_array).filter(|v| !v.is_empty() && v.len() <= vectorcraft_three_d::MAX_LIGHTS) } diff --git a/crates/ui-egui/src/dialogs/revolve_gizmo.rs b/crates/ui-egui/src/dialogs/revolve_gizmo.rs index 4595447ac2..c99e7ab83e 100644 --- a/crates/ui-egui/src/dialogs/revolve_gizmo.rs +++ b/crates/ui-egui/src/dialogs/revolve_gizmo.rs @@ -186,13 +186,13 @@ struct Drag { fields: serde_json::Map, } -fn wrap(n: f64, snap: bool) -> f64 { +pub(super) fn wrap(n: f64, snap: bool) -> f64 { let n = if snap { (n / 15.0).round() * 15.0 } else { n }; (n + 180.0).rem_euclid(360.0) - 180.0 } /// A Height, 0° to 90°, on 15° steps with Shift. -fn snap_height(height: f64, snap: bool) -> f64 { +pub(super) fn snap_height(height: f64, snap: bool) -> f64 { (if snap { (height / 15.0).round() * 15.0 } else { height }).clamp(0.0, 90.0) } diff --git a/crates/ui-egui/src/dialogs/revolve_lights.rs b/crates/ui-egui/src/dialogs/revolve_lights.rs new file mode 100644 index 0000000000..dc57cae943 --- /dev/null +++ b/crates/ui-egui/src/dialogs/revolve_lights.rs @@ -0,0 +1,266 @@ +//! The lighting widget on the 3D and Materials panel's Lighting tab for Extrude & Bevel, Revolve, +//! Inflate and Rotate: a sphere that shows each of the effect's lights +//! at its Rotation and Height, a filled sun in front of the object and a hollow one behind it. +//! Dragging a light moves it on its side of the object, a press selects it in the list of lights, +//! and the button below the sphere moves the selected light to the back or the front of the object. +//! Each light takes the keyboard focus, where the arrow keys move it, and has a name for screen +//! readers. The widget edits the panel's fields as the light settings do, so the panel previews a +//! drag and records it as one undo step when the pointer is released. + +use egui::{Id, Key, Modifiers, Rect, Sense, Stroke, Vec2, vec2}; +use serde_json::{Value, json}; +use vectorcraft_geom::Point; +use vectorcraft_three_d::{DEFAULT_LIGHT, Revolve}; + +use super::revolve::{c3, explicit_lights, light_record, set_light_value}; +use super::revolve_gizmo::{snap_height, wrap}; +use crate::state::Dialog; +use crate::theme::Tokens; + +/// The sphere's largest radius, in points. +pub(crate) const RADIUS: f32 = 56.0; +/// The radius of a light's sun. +const SUN: f32 = 7.0; +/// The arrow keys' steps in degrees, without and with Shift. +const STEP: f64 = 1.0; +const SHIFT_STEP: f64 = 15.0; +/// The keys that move the focused light. +const ARROWS: [Key; 4] = [Key::ArrowLeft, Key::ArrowRight, Key::ArrowUp, Key::ArrowDown]; + +/// One light as the widget shows it. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) struct Light { + pub rotation: f64, + pub height: f64, + pub behind: bool, + pub color: egui::Color32, +} + +impl Light { + fn options(self) -> Revolve { + Revolve { light_rotation: self.rotation, light_height: self.height, light_behind: self.behind, ..Default::default() } + } + + /// Where the light sits on a sphere of radius 1 around the origin, y down: the direction the + /// shading uses, seen from the front. + pub(crate) fn offset(self) -> Vec2 { + let [x, y, _] = self.options().light_direction(); + vec2(x as f32, y as f32) + } + + /// The Rotation and Height, rounded to 0.1°, of the light moved to `offset` (radius 1, y down) + /// on its side of the object: the farther out, the lower. Shift (`snap`) snaps both to 15°. + pub(crate) fn moved_to(self, offset: Vec2, snap: bool) -> (f64, f64) { + let [rotation, height] = self.options().light_at_on_side(Point::new(f64::from(offset.x), f64::from(offset.y))); + (round(wrap(rotation, snap)), round(snap_height(height, snap))) + } + + /// The Rotation and Height after one press of `key` (Left and Right turn the light around the + /// object counterclockwise and clockwise, Up and Down raise and lower it). Only the setting the + /// key moves changes, rounded to 0.1°. `None` for another key. + fn stepped(self, key: Key, step: f64) -> Option<(f64, f64)> { + let turn = |by: f64| round(wrap(self.rotation + by, false)); + let raise = |by: f64| round(snap_height(self.height + by, false)); + match key { + Key::ArrowLeft => Some((turn(step), self.height)), + Key::ArrowRight => Some((turn(-step), self.height)), + Key::ArrowUp => Some((self.rotation, raise(step))), + Key::ArrowDown => Some((self.rotation, raise(-step))), + _ => None, + } + } + + /// The name screen readers give the light at `index`: its number, Rotation, Height and side. + fn name(self, index: usize) -> String { + let side = if self.behind { format!(", {}", tl!("Light behind the object")) } else { String::new() }; + format!("{} {}: {} {:.1}°, {} {:.1}°{side}", c3("Light"), index + 1, tl!("Rotation"), self.rotation, tl!("Height"), self.height) + } +} + +fn round(n: f64) -> f64 { + (n * 10.0).round() / 10.0 +} + +/// The effect's lights: each light of its list, or its single light, with the effect's defaults for +/// the settings a light leaves out or the selected effects hold with different values (null). +pub(crate) fn lights(d: &Dialog) -> Vec { + let defaults = vectorcraft_effects::default_params(&d.str("__effect")).unwrap_or(json!({})); + let list = explicit_lights(d).cloned().unwrap_or_else(|| vec![light_record(d)]); + list.iter() + .map(|light| { + let value = + |key: &str, field: &str| light.get(key).filter(|v| !v.is_null()).or_else(|| defaults.get(field)).cloned().unwrap_or(Value::Null); + let [r, g, b] = value("color", "lightColor") + .as_str() + .filter(|s| s.len() == 7 && s.starts_with('#')) + .and_then(vectorcraft_color::Color::from_hex) + .unwrap_or(vectorcraft_color::Color::WHITE) + .to_rgb_uncalibrated() + .map(|c| (c * 255.0).round() as u8); + Light { + rotation: value("rotation", "lightRotation").as_f64().unwrap_or(DEFAULT_LIGHT.0), + height: value("height", "lightHeight").as_f64().unwrap_or(DEFAULT_LIGHT.1), + behind: value("behind", "lightBehind").as_bool().unwrap_or(false), + color: egui::Color32::from_rgb(r, g, b), + } + }) + .collect() +} + +/// The index of the selected light among `count` lights. +fn selected(d: &Dialog, count: usize) -> usize { + d.fields.get("__light").and_then(Value::as_u64).and_then(|v| usize::try_from(v).ok()).unwrap_or(0).min(count.saturating_sub(1)) +} + +/// Makes light `index` the selected one, as a choice in the list of lights does. +fn select(ui: &egui::Ui, d: &mut Dialog, index: usize) { + if d.fields.get("__light").and_then(Value::as_u64) != Some(index as u64) { + ui.memory_mut(|m| m.stop_text_input()); + super::revolve_gizmo::clear(ui.ctx()); + } + d.fields.insert("__light".into(), json!(index)); +} + +/// Draws the sphere with the lights and the button that moves the selected light to the back or +/// the front, editing `d.fields`. +pub(super) fn show(ui: &mut egui::Ui, d: &mut Dialog) { + let lights = lights(d); + let Some(&first) = lights.first() else { return }; + let current = selected(d, lights.len()); + let t = Tokens::get(ui.ctx()); + let radius = RADIUS.min((ui.available_width() * 0.5 - SUN - 8.0).max(24.0)); + let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), (radius + SUN + 6.0) * 2.0), Sense::hover()); + let center = rect.center(); + let painter = ui.painter_at(rect); + // The sphere: its rim is Height 0, its center Height 90°, and the ring between them 45°. + painter.circle(center, radius, t.input, Stroke::new(1.0, t.input_border)); + painter.circle_stroke(center, radius * std::f32::consts::FRAC_1_SQRT_2, Stroke::new(1.0, t.input_border.gamma_multiply(0.5))); + for axis in [vec2(radius, 0.0), vec2(0.0, radius)] { + painter.line_segment([center - axis, center + axis], Stroke::new(1.0, t.input_border.gamma_multiply(0.5))); + } + painter.circle(center, 4.0, t.panel, Stroke::new(1.0, t.text_dim)); + // The selected light last, so it is drawn above the others and a press there takes it. + let order = (0..lights.len()).filter(|&i| i != current).chain([current]); + let mut moved = None; + let mut picked = None; + let enabled = ui.is_enabled(); + for index in order { + let light = lights.get(index).copied().unwrap_or(first); + let at = center + light.offset() * radius; + let id = Id::unique(("three-d-lighting-widget", index)); + let response = ui.interact(Rect::from_center_size(at, Vec2::splat((SUN + 4.0) * 2.0)), id, Sense::click_and_drag()); + response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Slider, enabled, light.name(index))); + if response.drag_started() || response.clicked() { + // A light the pointer took takes the keyboard focus too, so the arrow keys move it next. + response.request_focus(); + picked = Some(index); + } + if response.gained_focus() { + picked = Some(index); + } + let origin = ui.input(|i| i.pointer.press_origin()); + if response.drag_started() + && let Some(origin) = origin + { + // The offset from the press to the light's center, kept for the drag, and whether the + // pointer has left the press yet. + ui.data_mut(|m| m.insert_temp(id, (at - origin, false))); + } + // The frame that releases the pointer can also move it: the light goes where it was dropped, + // the point of the press included once the pointer has left it. + if (response.dragged() || response.drag_stopped()) + && let Some(p) = response.interact_pointer_pos().or_else(|| ui.input(|i| i.pointer.latest_pos())) + { + let (grip, left): (Vec2, bool) = ui.data(|m| m.get_temp(id)).unwrap_or_default(); + let left = left || origin != Some(p); + ui.data_mut(|m| m.insert_temp(id, (grip, left))); + if left { + let snap = ui.input(|i| i.modifiers.shift); + moved = Some((index, light.moved_to((p + grip - center) / radius, snap))); + } + } + if response.has_focus() { + ui.memory_mut(|m| { + m.set_focus_lock_filter(id, egui::EventFilter { horizontal_arrows: true, vertical_arrows: true, ..Default::default() }) + }); + // Every arrow-key press in the frame moves the light in turn, in the order it came. + let presses = ui.input_mut(|i| { + let mut presses = vec![]; + i.events.retain(|e| match e { + egui::Event::Key { key, pressed: true, modifiers, .. } + if ARROWS.contains(key) && (modifiers.matches_exact(Modifiers::NONE) || modifiers.matches_exact(Modifiers::SHIFT)) => + { + presses.push((*key, if modifiers.shift { SHIFT_STEP } else { STEP })); + false + } + _ => true, + }); + presses + }); + let mut next = light; + for (key, step) in presses { + if let Some((rotation, height)) = next.stepped(key, step) { + (next.rotation, next.height) = (rotation, height); + } + } + if next != light { + moved = Some((index, (next.rotation, next.height))); + } + } + paint_light(ui, at, light, index == current, response.has_focus(), response.hovered() || response.dragged()); + if response.hovered() || response.dragged() { + ui.ctx().set_cursor_icon(if response.dragged() { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab }); + } + response.on_hover_text(tl!("Drag a light to move it. The arrow keys move the focused light; Shift steps 15°.")); + } + if let Some(index) = picked { + select(ui, d, index); + } + // Only a setting that moved is written: a press that leaves a light where it is, or a key at a + // limit, changes nothing, and a key leaves the other setting as each selected effect has it. + if let Some((index, (rotation, height))) = moved + && let Some(light) = lights.get(index) + { + for (key, value, was) in [("lightRotation", rotation, light.rotation), ("lightHeight", height, light.height)] { + if (value - was).abs() > 1e-9 { + select(ui, d, index); + set_light_value(d, key, json!(value)); + } + } + } + let index = selected(d, lights.len()); + let behind = lights.get(index).is_some_and(|l| l.behind); + ui.horizontal(|ui| { + let text = if behind { tl!("Move Light to Front") } else { tl!("Move Light to Back") }; + if ui.button(text).clicked() { + select(ui, d, index); + set_light_value(d, "lightBehind", json!(!behind)); + } + }); + ui.add_space(4.0); +} + +/// A light's sun: filled with its color in front of the object, hollow behind it, larger and +/// ringed when it is the selected light, with a second ring while it has the keyboard focus. +fn paint_light(ui: &egui::Ui, at: egui::Pos2, light: Light, selected: bool, focused: bool, hot: bool) { + let t = Tokens::get(ui.ctx()); + let painter = ui.painter(); + let r = if selected { SUN } else { SUN - 2.0 }; + let outline = Stroke::new(if hot { 2.5 } else { 1.5 }, if selected { t.warning } else { t.warning.gamma_multiply(0.7) }); + if light.behind { + painter.circle(at, r, t.panel, outline); + painter.circle_stroke(at, r * 0.5, Stroke::new(1.5, light.color)); + } else { + painter.circle(at, r, light.color, outline); + } + if selected { + for i in 0..8 { + let angle = i as f32 * std::f32::consts::TAU / 8.0; + let direction = vec2(angle.cos(), angle.sin()); + painter.line_segment([at + direction * (r + 2.0), at + direction * (r + 4.0)], Stroke::new(1.25, t.warning)); + } + } + if focused { + painter.circle_stroke(at, r + 6.0, Stroke::new(1.0, t.accent)); + } +} diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index fb3080c8c2..c9fc8a2151 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -5706,6 +5706,9 @@ theme Appearance Външен вид Softness Мекота Ambient Light Околна светлина Light behind the object Светлина зад обекта + Move Light to Back Премести светлината отзад + Move Light to Front Премести светлината отпред + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Плъзнете светлина, за да я преместите. Клавишите със стрелки местят фокусираната светлина; Shift я мести с 15°. Shadows Сенки Distance from Object Разстояние от обекта Shadow Bounds Граници на сянката diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 118609f801..52b4abb637 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -5792,6 +5792,9 @@ mark-style Japanese Japanski Softness Mekoća Ambient Light Ambijentalno svjetlo Light behind the object Svjetlo iza objekta + Move Light to Back Pomjeri svjetlo iza + Move Light to Front Pomjeri svjetlo naprijed + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Prevucite svjetlo da ga pomjerite. Tipke sa strelicama pomjeraju fokusirano svjetlo; Shift ga pomjera za 15°. Shadows Sjene Distance from Object Udaljenost od objekta Shadow Bounds Granice sjene diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index ab50e14a58..2dae0b6f17 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -2338,6 +2338,9 @@ digits Malayalam Malaiàlam Ligatures are off while the text is tracked. Les lligadures estan desactivades mentre el text té espaiat. Light Clar Light behind the object Llum darrere de l’objecte + Move Light to Back Mou la llum al darrere + Move Light to Front Mou la llum al davant + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Arrossegueu una llum per moure-la. Les tecles de fletxa mouen la llum amb el focus; Maj la mou de 15° en 15°. Shadows Ombres Distance from Object Distància de l’objecte Shadow Bounds Límits de l’ombra diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 3b9c300980..542250c918 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -6095,6 +6095,9 @@ mark-style Japanese Japonské Softness Měkkost Ambient Light Okolní světlo Light behind the object Světlo za objektem + Move Light to Back Přesunout světlo dozadu + Move Light to Front Přesunout světlo dopředu + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Přetažením světlo přesunete. Šipky posouvají světlo s fokusem; se Shiftem po 15°. Shadows Stíny Distance from Object Vzdálenost od objektu Shadow Bounds Hranice stínu diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 59ce36d15f..911c4d7b94 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -6049,6 +6049,9 @@ mark-style Japanese Japansk Softness Blødhed Ambient Light Omgivelseslys Light behind the object Lys bag objektet + Move Light to Back Flyt lys bagud + Move Light to Front Flyt lys frem + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Træk et lys for at flytte det. Piletasterne flytter lyset med fokus; Skift flytter det 15° ad gangen. Shadows Skygger Distance from Object Afstand fra objektet Shadow Bounds Skyggegrænser diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index ddc01a8016..1541cacd09 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -5677,6 +5677,9 @@ effect Soft Weich Softness Weichheit Ambient Light Umgebungslicht Light behind the object Licht hinter dem Objekt + Move Light to Back Licht nach hinten + Move Light to Front Licht nach vorne + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Ziehen Sie ein Licht, um es zu verschieben. Die Pfeiltasten verschieben das fokussierte Licht; mit Umschalt in Schritten von 15°. Shadows Schatten Distance from Object Abstand vom Objekt Shadow Bounds Schattenbegrenzung diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index a89d3c72e4..b8d42c6aa6 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -5773,6 +5773,9 @@ digits Malayalam Μαλαγιάλαμ to set spacing and orientation για ορισμό απόστασης και προσανατολισμού : : Light behind the object Φως πίσω από το αντικείμενο + Move Light to Back Μετακίνηση φωτός πίσω + Move Light to Front Μετακίνηση φωτός μπροστά + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Σύρετε ένα φως για να το μετακινήσετε. Τα πλήκτρα βέλους μετακινούν το εστιασμένο φως· με Shift ανά 15°. Shadows Σκιές Distance from Object Απόσταση από το αντικείμενο Shadow Bounds Όρια σκιάς diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 4a912f8005..1e0b23ff4b 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -6038,6 +6038,9 @@ mark-style Japanese Japonesas Softness Suavidad Ambient Light Luz ambiental Light behind the object Luz detrás del objeto + Move Light to Back Mover luz detrás + Move Light to Front Mover luz delante + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Arrastre una luz para moverla. Las teclas de flecha mueven la luz con el foco; Mayús la mueve de 15° en 15°. Shadows Sombras Distance from Object Distancia del objeto Shadow Bounds Límites de la sombra diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 06499d13ea..1ff3677b2c 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -5975,6 +5975,9 @@ mark-style Japanese Japanilainen Softness Pehmeys Ambient Light Ympäristövalo Light behind the object Valo objektin takana + Move Light to Back Siirrä valo taakse + Move Light to Front Siirrä valo eteen + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Siirrä valoa vetämällä. Nuolinäppäimet siirtävät kohdistettua valoa; Vaihto siirtää 15° kerrallaan. Shadows Varjot Distance from Object Etäisyys objektista Shadow Bounds Varjon rajat diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 90882cf105..244fa102ca 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -6091,6 +6091,9 @@ theme Appearance Apparence Softness Douceur Ambient Light Lumière ambiante Light behind the object Lumière derrière l'objet + Move Light to Back Placer la lumière derrière + Move Light to Front Placer la lumière devant + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Faites glisser une lumière pour la déplacer. Les touches fléchées déplacent la lumière active ; Maj par pas de 15°. Shadows Ombres Distance from Object Distance de l'objet Shadow Bounds Limites de l'ombre diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 0e9ed1997e..fc9575b930 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -1909,6 +1909,9 @@ Light Intensity લાઇટ તીવ્રતા Light Rough લાઇટ રફ Light behind the object ઑબ્જેક્ટની પાછળ લાઇટ + Move Light to Back લાઇટ પાછળ ખસેડો + Move Light to Front લાઇટ આગળ ખસેડો + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. લાઇટ ખસેડવા માટે તેને ખેંચો. ઍરો કી ફોકસ થયેલી લાઇટ ખસેડે છે; Shift સાથે 15° ના પગલાં. Lighten હળવું કરો Lighting લાઇટિંગ Lights લાઇટ્સ diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 671052e82b..c8829d1a5b 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -2579,6 +2579,9 @@ antiAlias Sharp शार्प Ligatures are off while the text is tracked. टेक्स्ट पर ट्रैकिंग लागू होने पर लिगेचर ऑफ़ रहते हैं। Light लाइट Light behind the object ऑब्जेक्ट के पीछे प्रकाश + Move Light to Back प्रकाश को पीछे ले जाएँ + Move Light to Front प्रकाश को आगे ले जाएँ + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. प्रकाश को हिलाने के लिए उसे खींचें। तीर कुंजियाँ फ़ोकस वाले प्रकाश को हिलाती हैं; Shift के साथ 15° के चरण। Shadows छायाएँ Distance from Object ऑब्जेक्ट से दूरी Shadow Bounds छाया सीमाएँ diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index a218a2ce15..463aadf764 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -6078,6 +6078,9 @@ imageTrace Outline Körvonal Softness Lágyság Ambient Light Környezeti fény Light behind the object Fény az objektum mögött + Move Light to Back Fény hátra + Move Light to Front Fény előre + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Húzzon egy fényt az áthelyezéséhez. A nyílbillentyűk a fókuszban lévő fényt mozgatják; Shifttel 15°-onként. Shadows Árnyékok Distance from Object Távolság az objektumtól Shadow Bounds Árnyék határai diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index fdf06cc9ee..e61d7df5ed 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -5439,6 +5439,9 @@ mark-style Japanese Jepang Softness Kelembutan Ambient Light Cahaya ambient Light behind the object Cahaya di belakang objek + Move Light to Back Pindahkan Cahaya ke Belakang + Move Light to Front Pindahkan Cahaya ke Depan + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Seret cahaya untuk memindahkannya. Tombol panah memindahkan cahaya yang difokuskan; Shift memindahkannya 15°. Shadows Bayangan Distance from Object Jarak dari objek Shadow Bounds Batas bayangan diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 2b5a6bf3da..00a7ee8d7d 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -5712,6 +5712,9 @@ lighting Light Luce Softness Morbidezza Ambient Light Luce ambientale Light behind the object Luce dietro l'oggetto + Move Light to Back Sposta luce dietro + Move Light to Front Sposta luce davanti + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Trascina una luce per spostarla. I tasti freccia spostano la luce attiva; Maiusc a passi di 15°. Shadows Ombre Distance from Object Distanza dall'oggetto Shadow Bounds Limiti dell'ombra diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 87ec6c8b05..90b8d4d7e2 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -5755,6 +5755,9 @@ lighting Light ライト Softness 柔らかさ Ambient Light 環境光 Light behind the object オブジェクトの背後のライト + Move Light to Back ライトを背面へ + Move Light to Front ライトを前面へ + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. ライトをドラッグして移動します。矢印キーでフォーカスのあるライトを移動し、Shift キーで 15° ずつ移動します。 Shadows シャドウ Distance from Object オブジェクトからの距離 Shadow Bounds シャドウの範囲 diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 8c42eafaf1..385b7ed310 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -5648,6 +5648,9 @@ imageTrace Outline კონტური In the File ფაილში Keys კლავიშები Light behind the object სინათლე ობიექტის უკან + Move Light to Back სინათლის უკან გადატანა + Move Light to Front სინათლის წინ გადატანა + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. გადაათრიეთ სინათლე მის გადასაადგილებლად. ისრიანი ღილაკები ფოკუსირებულ სინათლეს ამოძრავებს; Shift-ით 15°-იანი ბიჯით. Shadows ჩრდილები Distance from Object მანძილი ობიექტიდან Shadow Bounds ჩრდილის საზღვრები diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 4fd8001ea7..21d1ddfac2 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -5673,6 +5673,9 @@ lighting Light 광원 Softness 부드러움 Ambient Light 주변광 Light behind the object 개체 뒤의 조명 + Move Light to Back 조명을 뒤로 이동 + Move Light to Front 조명을 앞으로 이동 + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. 조명을 드래그하여 이동합니다. 화살표 키로 포커스된 조명을 이동하고, Shift 키를 누르면 15°씩 이동합니다. Shadows 그림자 Distance from Object 개체로부터의 거리 Shadow Bounds 그림자 범위 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 31872f060e..90d4354634 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -7841,6 +7841,9 @@ mark-style Japanese Japans Softness Zachtheid Ambient Light Omgevingslicht Light behind the object Licht achter het object + Move Light to Back Licht naar achteren + Move Light to Front Licht naar voren + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Sleep een licht om het te verplaatsen. De pijltoetsen verplaatsen het licht met de focus; Shift verplaatst het per 15°. Shadows Schaduwen Distance from Object Afstand tot object Shadow Bounds Schaduwgrenzen diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 77b1425e5f..22e9a328e3 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -5935,6 +5935,9 @@ mark-style Japanese Japońskie Softness Miękkość Ambient Light Światło otoczenia Light behind the object Światło za obiektem + Move Light to Back Przenieś światło do tyłu + Move Light to Front Przenieś światło do przodu + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Przeciągnij światło, aby je przesunąć. Klawisze strzałek przesuwają aktywne światło; z Shift o 15°. Shadows Cienie Distance from Object Odległość od obiektu Shadow Bounds Granice cienia diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index caed79af2a..075c6d4102 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -4798,6 +4798,9 @@ axis Both Ambos Softness Suavidade Ambient Light Luz ambiente Light behind the object Luz atrás do objeto + Move Light to Back Mover luz para trás + Move Light to Front Mover luz para a frente + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Arraste uma luz para movê-la. As teclas de seta movem a luz em foco; Shift a move de 15° em 15°. Shadows Sombras Distance from Object Distância do objeto Shadow Bounds Limites da sombra diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 206b209ee2..1889b5d920 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -5698,6 +5698,9 @@ lighting Light Свет Softness Мягкость Ambient Light Окружающий свет Light behind the object Свет позади объекта + Move Light to Back Переместить свет назад + Move Light to Front Переместить свет вперёд + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Перетащите источник света, чтобы переместить его. Клавиши со стрелками перемещают выбранный источник; с Shift — шагами по 15°. Shadows Тени Distance from Object Расстояние от объекта Shadow Bounds Границы тени diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 82e63d1667..51043d3b03 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -5988,6 +5988,9 @@ theme Appearance Utseende Softness Mjukhet Ambient Light Omgivande ljus Light behind the object Ljus bakom objektet + Move Light to Back Flytta ljus bakåt + Move Light to Front Flytta ljus framåt + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Dra ett ljus för att flytta det. Piltangenterna flyttar ljuset med fokus; Skift flyttar det 15° i taget. Shadows Skuggor Distance from Object Avstånd från objektet Shadow Bounds Skuggans gränser diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 237694bff5..f0896f2b14 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -5871,6 +5871,9 @@ theme Appearance Görünüm Softness Yumuşaklık Ambient Light Ortam Işığı Light behind the object Nesnenin arkasındaki ışık + Move Light to Back Işığı Arkaya Taşı + Move Light to Front Işığı Öne Taşı + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Işığı taşımak için sürükleyin. Ok tuşları odaktaki ışığı taşır; Shift ile 15° adımlarla. Shadows Gölgeler Distance from Object Nesneden uzaklık Shadow Bounds Gölge sınırları diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index a74a03529d..6abc5e0a75 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -5692,6 +5692,9 @@ lighting Light Світло Softness М'якість Ambient Light Навколишнє світло Light behind the object Світло позаду об'єкта + Move Light to Back Перемістити світло назад + Move Light to Front Перемістити світло вперед + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Перетягніть світло, щоб перемістити його. Клавіші зі стрілками переміщують вибране світло; із Shift — кроками по 15°. Shadows Тіні Distance from Object Відстань від об'єкта Shadow Bounds Межі тіні diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 16c613874c..d1e8ad697a 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -5696,6 +5696,9 @@ theme Appearance Giao diện Softness Độ mềm Ambient Light Ánh sáng môi trường Light behind the object Ánh sáng phía sau đối tượng + Move Light to Back Đưa ánh sáng ra sau + Move Light to Front Đưa ánh sáng ra trước + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. Kéo một nguồn sáng để di chuyển nó. Phím mũi tên di chuyển nguồn sáng đang có tiêu điểm; Shift di chuyển theo bước 15°. Shadows Bóng đổ Distance from Object Khoảng cách từ đối tượng Shadow Bounds Giới hạn bóng diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index b83bee650f..07106f0b4e 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -5965,6 +5965,9 @@ lighting Light 光源 Softness 柔和度 Ambient Light 环境光 Light behind the object 光源位于对象后方 + Move Light to Back 将光源移到后方 + Move Light to Front 将光源移到前方 + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. 拖动光源可移动它。方向键移动具有焦点的光源;按住 Shift 以 15° 为步长。 Shadows 阴影 Distance from Object 与对象的距离 Shadow Bounds 阴影边界 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 4637ecb811..eb229663d6 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -5797,6 +5797,9 @@ lighting Light 光源 Softness 柔和度 Ambient Light 環境光 Light behind the object 光源位於物件後方 + Move Light to Back 將光源移到後方 + Move Light to Front 將光源移到前方 + Drag a light to move it. The arrow keys move the focused light; Shift steps 15°. 拖曳光源即可移動。方向鍵會移動具有焦點的光源;按住 Shift 以 15° 為間距。 Shadows 陰影 Distance from Object 與物件的距離 Shadow Bounds 陰影邊界 diff --git a/crates/ui-egui/src/panels/tests_three_d.rs b/crates/ui-egui/src/panels/tests_three_d.rs index 72ce8004b5..3004195d36 100644 --- a/crates/ui-egui/src/panels/tests_three_d.rs +++ b/crates/ui-egui/src/panels/tests_three_d.rs @@ -794,6 +794,177 @@ fn quick_actions_show_on_the_object_tab_only() { assert!(super::quick_actions_shown(&d)); } +/// An app with an Extrude & Bevel square given `params`, and the panel on its Lighting tab with the +/// accessibility tree on. +fn lighting_app(params: Value) -> (VectorcraftApp, egui::Context) { + use crate::panels::tests_appearance::{click, frame_events, text_rect}; + let mut app = app(); + app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": params})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + ctx.enable_accesskit(); + let texts = frame_events(&ctx, &mut app, vec![], show); + click(&ctx, &mut app, text_rect(&texts, "Lighting").center(), show); + (app, ctx) +} + +/// The lighting widget's node for light `n` (from 1): its screen-reader name and its center. +fn light_node(app: &mut VectorcraftApp, ctx: &egui::Context, n: usize) -> (String, egui::Pos2) { + let nodes = controls(app, ctx); + let prefix = format!("Light {n}:"); + let node = nodes + .iter() + .find(|x| x.role() == egui::accesskit::Role::Slider && x.label().is_some_and(|l| l.starts_with(&prefix))) + .unwrap_or_else(|| panic!("no lighting widget node for light {n}")); + let r = node.bounds().unwrap(); + (node.label().unwrap_or_default().to_string(), egui::pos2(((r.x0 + r.x1) / 2.0) as f32, ((r.y0 + r.y1) / 2.0) as f32)) +} + +fn pointer(pos: egui::Pos2, pressed: Option) -> egui::Event { + match pressed { + Some(pressed) => egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }, + None => egui::Event::PointerMoved(pos), + } +} + +fn merged_light(app: &VectorcraftApp) -> (f64, f64) { + let (id, params) = effect(app); + let merged = vectorcraft_effects::merged_params(&id, ¶ms); + (merged["lightRotation"].as_f64().unwrap(), merged["lightHeight"].as_f64().unwrap()) +} + +/// Dragging a light in the lighting widget previews its new Rotation and Height while the pointer +/// is down and records one undo step when it is released, at the point of release; the rim of the +/// sphere is Height 0. +#[test] +fn the_lighting_widget_drags_a_light_in_one_undo_step() { + use crate::dialogs::revolve_lights::RADIUS; + use crate::panels::tests_appearance::frame_events; + let (mut app, ctx) = lighting_app(json!({})); + let (name, from) = light_node(&mut app, &ctx, 1); + assert_eq!(name, "Light 1: Rotation 125.3°, Height 30.0°"); + let light = crate::dialogs::revolve_lights::lights(&crate::state::Dialog::new( + "x", + json!({"__effect": "threeD.extrude", "lightRotation": vectorcraft_three_d::DEFAULT_LIGHT.0, "lightHeight": 30.0}), + ))[0]; + let center = from - light.offset() * RADIUS; + let history = undo_len(&app); + frame_events(&ctx, &mut app, vec![pointer(from, None)], show); + frame_events(&ctx, &mut app, vec![pointer(from, Some(true))], show); + // Halfway out along the light's own direction, then onto the rim straight right of the center. + frame_events(&ctx, &mut app, vec![pointer(center + egui::vec2(0.0, -RADIUS * 0.5), None)], show); + assert_eq!(merged_light(&app), (90.0, 60.0), "the light follows the pointer while it is down"); + let rim = center + egui::vec2(RADIUS, 0.0); + frame_events(&ctx, &mut app, vec![pointer(rim, None)], show); + assert_eq!(merged_light(&app), (0.0, 0.0)); + assert_eq!(undo_len(&app), history, "nothing is recorded while the pointer is down"); + // A frame that moves the pointer below the center and releases it there drops the light there. + let below = center + egui::vec2(0.0, RADIUS); + frame_events(&ctx, &mut app, vec![pointer(below, None), pointer(below, Some(false))], show); + frame_events(&ctx, &mut app, vec![], show); + assert_eq!(undo_len(&app), history + 1); + assert_eq!(merged_light(&app), (-90.0, 0.0)); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(merged_light(&app), (vectorcraft_three_d::DEFAULT_LIGHT.0, 30.0)); + // A drag that comes back to the press drops the light there, not where it last was. + for event in [pointer(from, None), pointer(from, Some(true)), pointer(center + egui::vec2(0.0, -RADIUS * 0.5), None), pointer(from, None)] { + frame_events(&ctx, &mut app, vec![event], show); + } + frame_events(&ctx, &mut app, vec![pointer(from, Some(false))], show); + frame_events(&ctx, &mut app, vec![], show); + assert_eq!(merged_light(&app), (125.3, 30.0)); +} + +/// With objects whose lights differ in Height, an arrow key that turns the light changes only +/// the Rotation, and each object keeps its own Height. +#[test] +fn a_key_leaves_the_other_setting_as_each_selected_effect_has_it() { + use crate::panels::tests_appearance::{click, frame_events, text_rect}; + let mut app = app(); + let a = app.session.active().unwrap().selection.objects[0].0; + app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": {"lightRotation": 0.0, "lightHeight": 20.0}})).unwrap(); + let b = app.run("shape.rectangle", json!({"x": 250, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap(); + app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": {"lightRotation": 0.0, "lightHeight": 40.0}})).unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + ctx.enable_accesskit(); + let texts = frame_events(&ctx, &mut app, vec![], show); + click(&ctx, &mut app, text_rect(&texts, "Lighting").center(), show); + let (_, at) = light_node(&mut app, &ctx, 1); + click(&ctx, &mut app, at, show); + let left = egui::Event::Key { key: egui::Key::ArrowLeft, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }; + frame_events(&ctx, &mut app, vec![left], show); + let light = |id: u64| { + let n = app.session.active().unwrap().doc.node(vectorcraft_doc::NodeId(id)).unwrap(); + let merged = vectorcraft_effects::merged_params("threeD.extrude", &n.appearance.effects[0].params); + (merged["lightRotation"].as_f64().unwrap(), merged["lightHeight"].as_f64().unwrap()) + }; + assert_eq!((light(a), light(b)), ((1.0, 20.0), (1.0, 40.0))); +} + +/// A press on a light selects it in the list without an undo step, and the button below the sphere +/// moves only the selected light to the back of the object, then back to the front. +#[test] +fn the_lighting_widget_selects_a_light_and_moves_it_behind_the_object() { + use crate::panels::tests_appearance::{click, frame_events, text_rect}; + let light = + |rotation: f64| json!({"color": "#ffffff", "intensity": 80.0, "rotation": rotation, "height": 30.0, "softness": 0.0, "behind": false}); + let (mut app, ctx) = lighting_app(json!({"lights": [light(0.0), light(180.0)]})); + let history = undo_len(&app); + let (_, second) = light_node(&mut app, &ctx, 2); + click(&ctx, &mut app, second, show); + assert_eq!(undo_len(&app), history, "a press on a light changes nothing"); + let texts = frame_events(&ctx, &mut app, vec![], show); + assert!(texts.iter().any(|(s, _)| s == "Light 2"), "the list shows the pressed light: {texts:?}"); + click(&ctx, &mut app, text_rect(&texts, "Move Light to Back").center(), show); + assert_eq!(undo_len(&app), history + 1); + let behind = |app: &VectorcraftApp| effect(app).1["lights"].as_array().unwrap().iter().map(|l| l["behind"].clone()).collect::>(); + assert_eq!(behind(&app), [json!(false), json!(true)]); + let (name, _) = light_node(&mut app, &ctx, 2); + assert_eq!(name, "Light 2: Rotation 180.0°, Height 30.0°, Light behind the object"); + let texts = frame_events(&ctx, &mut app, vec![], show); + click(&ctx, &mut app, text_rect(&texts, "Move Light to Front").center(), show); + assert_eq!(behind(&app), [json!(false), json!(false)]); + assert_eq!(undo_len(&app), history + 2); +} + +/// A light the pointer took has the keyboard focus: the arrow keys raise and lower it and turn it +/// around the object, 1° a press or 15° with Shift, changing only the setting each press moves, one +/// undo step a frame, and a press at a limit records nothing. +#[test] +fn the_arrow_keys_move_the_focused_light() { + use crate::panels::tests_appearance::{click, frame_events}; + let (mut app, ctx) = lighting_app(json!({"lightRotation": 10.04, "lightHeight": 89.5})); + let (_, at) = light_node(&mut app, &ctx, 1); + click(&ctx, &mut app, at, show); + let history = undo_len(&app); + let key = |key: egui::Key, modifiers: egui::Modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }; + frame_events(&ctx, &mut app, vec![key(egui::Key::ArrowUp, egui::Modifiers::NONE)], show); + frame_events(&ctx, &mut app, vec![], show); + assert_eq!(merged_light(&app), (10.04, 90.0), "Up leaves the Rotation as it is"); + assert_eq!(undo_len(&app), history + 1); + frame_events(&ctx, &mut app, vec![key(egui::Key::ArrowUp, egui::Modifiers::NONE)], show); + frame_events(&ctx, &mut app, vec![], show); + assert_eq!(merged_light(&app), (10.04, 90.0)); + assert_eq!(undo_len(&app), history + 1, "Height stays at 90° and nothing is recorded"); + // Down then Up in one frame, in that order: back at 90°. + frame_events(&ctx, &mut app, vec![key(egui::Key::ArrowDown, egui::Modifiers::NONE), key(egui::Key::ArrowUp, egui::Modifiers::NONE)], show); + frame_events(&ctx, &mut app, vec![], show); + assert_eq!(merged_light(&app), (10.04, 90.0)); + assert_eq!(undo_len(&app), history + 1); + // Presses that arrive in one frame all move the light, as one undo step. + let presses = vec![ + key(egui::Key::ArrowLeft, egui::Modifiers::SHIFT), + key(egui::Key::ArrowDown, egui::Modifiers::NONE), + key(egui::Key::ArrowDown, egui::Modifiers::NONE), + ]; + frame_events(&ctx, &mut app, presses, show); + frame_events(&ctx, &mut app, vec![], show); + assert_eq!(merged_light(&app), (25.0, 88.0)); + assert_eq!(undo_len(&app), history + 2); +} + #[test] fn changed_settings_lists_only_new_values() { let before = json!({"depth": 50.0, "cap": true, "bevel": "none"}); diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index c6972468cc..c99a600323 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -583,6 +583,7 @@ since 2026-10-01. - **Panel collapse controls (#5925, in part):** The small » in a floating tab-group header moves that group into the side icon rail, reusing the existing rail or creating one. An opened rail panel has the same control to fold its flyout back into the rail, including after a tab switch. Both controls preserve the tab group and its menu; other floating groups and full-width docked headers stay as they were. Pointer regressions in `crates/ui-egui/src/panel_docking/tests.rs` cover grouped tabs, reopening, separate groups, a missing rail, the menu and flyout closure after switching tabs; `native_tests.rs` covers the native-window click and removal of the empty palette. Scores and estimates unchanged. - 3D lighting presets: `crates/effects/src/lighting_presets.rs`, `crates/engine/src/cmd/effectcmd/lighting_presets_tests.rs` and the pointer tests in `crates/ui-egui/src/dialogs/revolve/tests.rs` cover recognition, atomic targeting, native round trips, preview, Cancel, reset and Undo. +- 3D lighting widget: the Lighting tab of the 3D and Materials panel shows every light on a sphere at its Rotation and Height; a drag moves a light in one undo step, a press selects it, Move Light to Back and Move Light to Front change its side, and the arrow keys move the focused light ([three-d.md](three-d.md#lighting-widget)). `crates/ui-egui/src/panels/tests_three_d.rs` covers the drag, selection, side and keyboard. - 3D shadows: Revolve, Extrude & Bevel, Inflate and Rotate take a Shadows switch with Position (Behind Object or Below Object), Distance from Object (0–100 %) and Shadow Bounds (10–400 %) on the Lighting tab ([three-d.md](three-d.md#shadows)); the first light casts one hard-edged vector shadow, drawn behind the solids, in exports and kept by Expand Appearance. Evidence: `crates/three-d/src/shadow/tests.rs`, `crates/effects/src/solids/tests_shadow.rs`, `effectcmd::tests::a_3d_shadow_is_one_undo_step_saved_exported_and_expanded`. Softness and the shadows of lights after the first are not built. Scores unchanged. - 3D shadows: with Shadows on, Revolve, Extrude & Bevel, Inflate and Rotate cast the shadow from the faces kept by the build that draws each solid, so drawing an object builds each of its solids once. The art and the shadow are unchanged. Evidence: `crates/three-d/src/shadow/tests.rs` (`a_solid_and_its_shadow_are_built_once` and the tests that compare each solid and its shadow with the two built apart), `solids::tests_shadow::a_shadowed_3d_object_builds_each_solid_once`, `solids::tests_shadow::the_shadow_cast_from_the_solids_drawn_is_the_shadow_of_solids_built_for_it`, `revolve::tests::the_shadow_cast_from_the_surfaces_drawn_is_the_shadow_of_surfaces_swept_for_it`. Scores unchanged. - Window › 3D and Materials panel: `crates/ui-egui/src/panels/three_d.rs` applies a 3D effect by object type (Plane, Extrude, Revolve, Inflate), changes an applied one in place (`effect.setParams` `threeDType`) and edits it with the options dialog's Object, Rotation and Lighting controls, one undo step per change; `crates/engine/src/cmd/effectcmd/three_d_type_tests.rs` and `crates/ui-egui/src/panels/tests_three_d.rs` cover it. No Materials tab. diff --git a/docs/three-d.md b/docs/three-d.md index f12ca4675c..871b28772c 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -66,7 +66,8 @@ pages describe it. when no selected object has a visible 3D effect. - The Lighting tab also holds the Shadows switch and its settings ([Shadows](#shadows)). The Materials tab holds the Graphics ([Graphics](#graphics)); base materials and ray-traced rendering are not built (see below). The - rotation and light rings on the artboard are part of the options dialog only. + rotation and light rings on the artboard are part of the options dialog only. The panel's Lighting tab has the + lighting widget instead ([Lighting widget](#lighting-widget)). ## Extrude & Bevel @@ -302,6 +303,33 @@ applied 3D effect. Every target must have a 3D effect at that position; validati the whole operation is one undo step. The numeric light settings are saved, not a preset name. Existing documents keep their appearance unless a preset is chosen. +### Lighting widget + +On the 3D and Materials panel's Lighting tab, above the list of lights, a sphere shows every light of the +effect where it shines from, as the public +[3D and Materials panel options](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/3d-materials-panel-options.html) +page describes for dragging light sources around the object. The sphere is seen from the front: a light's +Rotation is its angle around the center, and its Height runs from the rim (0°) to the center (90°). A light in +front of the object is a sun filled with its color, and a light behind the object is hollow. The selected light +is drawn larger, above the others. + +- Pressing a light selects it in the list of lights and records nothing. Dragging it moves it on its side of the + object, rounded to 0.1°; Shift snaps Rotation and Height to 15°. The drag is previewed while the pointer is + down and is one undo step when it is released. +- **Move Light to Back** moves the selected light behind the object, and **Move Light to Front** moves it back + in front, as the page's "Move selected light to the back/front of object" does. It sets the same + `lightBehind` (or a list light's `behind`) as the **Light behind the object** checkbox. +- Each light takes the keyboard focus. Left and Right turn the focused light around the object by 1° + (counterclockwise and clockwise), Up and Down raise and lower it by 1°, and Shift makes each step 15°. Each + press changes only the setting it moves and is one undo step. A + step past 90° or below 0° Height changes nothing. Screen readers name each light with its number, Rotation, + Height and, for a light behind the object, its side. + +The widget sends the same settings as the Rotation, Height and Light behind the object controls +(`effect.setParams`); there is no command of its own. The sphere's look, the 0.1° rounding and the arrow keys +are VectorCraft's own. The options dialogs keep the light rings on the artboard instead, and the Lighting tab +of Extrude & Bevel (Classic), Revolve (Classic) and Rotate (Classic) has no lighting widget. + ### Light settings One to ten directional lights. **Lights** selects the light whose settings and artboard gizmo are edited. **Add Light** adds and selects a white front light; **Delete Light** removes the selected light while retaining at least one. Ambient Light is shared by all lights. The public panel options' Light Settings are kept in their order: