diff --git a/crates/ui-egui/src/panels/tests_three_d.rs b/crates/ui-egui/src/panels/tests_three_d.rs index f0a8626eb2..145c210b72 100644 --- a/crates/ui-egui/src/panels/tests_three_d.rs +++ b/crates/ui-egui/src/panels/tests_three_d.rs @@ -1704,6 +1704,64 @@ fn a_live_edit_without_a_warning_clears_the_earlier_one() { assert_eq!(app.ui.status, vectorcraft_effects::rendered::OPAQUE_ONLY); } +/// A drag whose preview falls back to shaded faces and is then canceled, or dragged back to where it +/// began, clears the fallback warning, since the restored settings render; a newer status line stays. +#[test] +fn a_canceled_drag_clears_the_fallback_warning_its_preview_showed() { + let fresh = || { + let mut app = app(); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 500, "height": 500})).unwrap(); + let render = json!({"mode": "rendered", "quality": "low", "resolution": 300}); + app.run("effect.apply", json!({"effect": "threeD.extrude", "item": null, "params": {"depth": 50, "render": render}})).unwrap(); + app.ui.status.clear(); + app + }; + let too_large = vectorcraft_effects::rendered::TOO_LARGE; + for back in [false, true] { + let mut app = fresh(); + let before = begin(&mut app, GESTURE); + update(&mut app, GESTURE, &[("depth", json!(2000.0))]); + assert_eq!(app.ui.status, too_large); + if back { + update(&mut app, GESTURE, &[("depth", json!(50.0))]); + } else { + pass(&mut app, &before, EditEvent::cancel(GESTURE, CancelReason::Escape, None)); + } + assert_eq!(effect(&app).1["depth"], 50.0); + assert_eq!(app.ui.status, "", "dragged back: {back}"); + } + let mut app = fresh(); + let before = begin(&mut app, GESTURE); + update(&mut app, GESTURE, &[("depth", json!(2000.0))]); + app.status("Something else"); + pass(&mut app, &before, EditEvent::cancel(GESTURE, CancelReason::Escape, None)); + assert_eq!(app.ui.status, "Something else"); + + // A warning an earlier edit of other objects showed stays when a drag that showed none is canceled. + let mut app = fresh(); + let square = app.session.active().unwrap().selection.objects[0].0; + let a = app.run("shape.rectangle", json!({"x": 600, "y": 0, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap(); + let b = app.run("shape.rectangle", json!({"x": 750, "y": 0, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + app.run( + "paint.setFill", + json!({"gradient": {"kind": "linear", "stops": [ + {"offset": 0, "color": "#000000"}, {"offset": 1, "color": "#ffffff"} + ]}}), + ) + .unwrap(); + set_type(&mut app, "extrude").unwrap(); + super::set_render(&mut app, "rendered", Some("low")); + app.ui.status.clear(); + send(&mut app, Map::from_iter([("depth".into(), json!(40))]), Live::Released); + assert_eq!(app.ui.status, vectorcraft_effects::rendered::OPAQUE_ONLY); + app.run("select.set", json!({"ids": [square]})).unwrap(); + let before = begin(&mut app, GESTURE); + update(&mut app, GESTURE, &[("depth", json!(60.0))]); + pass(&mut app, &before, EditEvent::cancel(GESTURE, CancelReason::Escape, None)); + assert_eq!(app.ui.status, vectorcraft_effects::rendered::OPAQUE_ONLY); +} + /// Raster Settings OK shows why a rendered image falls back to shaded faces at a higher resolution. #[test] fn raster_settings_rendered_warning_reaches_the_status_bar() { diff --git a/crates/ui-egui/src/panels/three_d.rs b/crates/ui-egui/src/panels/three_d.rs index 56847a4639..fe8e629be2 100644 --- a/crates/ui-egui/src/panels/three_d.rs +++ b/crates/ui-egui/src/panels/three_d.rs @@ -67,6 +67,8 @@ pub(crate) struct Model { graphic: usize, /// The settings as they were when the gesture began. before: Value, + /// [`crate::state::UiState::status_sets`] when the gesture began: a live warning shown after it is the gesture's own. + began_sets: u64, } /// The selection's 3D effect: the appearance item whose effects hold it (`None`: the object's @@ -159,10 +161,25 @@ fn rollback(app: &mut VectorcraftApp) { m.before = Value::Null; if previewed { app.session.cancel_interaction().ok(); - app.sync_views(); + restored(app); } } +/// After a preview was rolled back: clears the warning the gesture's preview put in the status bar +/// while the status line still holds it, shows the restored selection's own rendered warning, and +/// redraws. A warning shown before the gesture began is kept. +fn restored(app: &mut VectorcraftApp) { + if let Some((cmd, sets, text)) = app.ui.live_warning.take() { + if sets <= app.three_d.began_sets { + app.ui.live_warning = Some((cmd, sets, text)); + } else if app.ui.status_sets == sets && app.ui.status == text { + app.ui.status.clear(); + show_rendered_warning(app); + } + } + app.sync_views(); +} + /// What a change goes to, taken when it starts (before any preview): the selected objects' ids, /// and each selected object with a 3D effect, the effect, and whether its list of lights matches /// the first one's (a light list edited in the panel replaces only those). @@ -282,6 +299,7 @@ pub(crate) fn apply(app: &mut VectorcraftApp, params: &[Param], input: &DialogFi // A gesture still running (its selection changed under it) ends with what it previewed. finish(app); app.three_d.gesture = Some(*id); + app.three_d.began_sets = app.ui.status_sets; app.three_d.before = settings(input); app.three_d.plan = Some(plan(app)); } @@ -292,7 +310,7 @@ pub(crate) fn apply(app: &mut VectorcraftApp, params: &[Param], input: &DialogFi // gesture goes on. app.three_d.pending.clear(); app.session.cancel_interaction().ok(); - app.sync_views(); + restored(app); } else { let changed = returned(app, changed); send(app, changed, Live::Dragging); diff --git a/docs/three-d.md b/docs/three-d.md index 9a97fc6258..d45a826edc 100644 --- a/docs/three-d.md +++ b/docs/three-d.md @@ -798,8 +798,9 @@ out, perspective). No Adobe software, assets, presets or bevel shapes were used. Inflate's puffed front and back only ([Graphics](#graphics)). - The bevel shapes and their names are our own. Custom bevels come from VectorCraft's own bevels file ([Custom bevels](#custom-bevels)) and are cut into straight lines. -- Visibility is a painter's algorithm: faces of a closed solid turned away are left out, and the rest are drawn - back to front, with a flat cap or flat back turned toward the viewer drawn after all of them. Concave solids +- Shaded vector faces are drawn with a painter's algorithm. This covers Rendered too when it falls back to shaded + faces; a Rendered image is drawn with a depth buffer. Faces of a closed solid turned away are left out, and the + rest are drawn back to front, with a flat cap or flat back turned toward the viewer drawn after all of them. Concave solids seen at steep angles can overlap wrongly; open (hollow) solids show both sides. Twisted walls and bevels are drawn in pieces about as long as a wall slice is wide (fewer near the limit of 32,768 facets). The piece drawn on top can still lie a few points behind another nearby piece.