mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 19:41:36 -05:00
3D: a canceled drag clears the fallback warning its preview showed
Canceling a 3D and Materials drag, or dragging back to where it began, rolled the preview back but left its rendered fallback warning in the status bar, describing settings the document no longer had. The rollback now clears that warning while the status line still holds it and shows the restored selection's own warning instead. A warning shown before the drag began, or a newer status message, is kept. docs/three-d.md now scopes the painter's algorithm note to shaded vector faces; a Rendered image is drawn with a depth buffer.
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-2
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user