mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Filter preview: the addressed document, layer and mask are part of the preview session
This commit is contained in:
1 parent
e03e93e2df
commit
b15b1f29c4
2 files changed
+25
-4
No files matched your search
@@ -224,12 +224,13 @@ pub(crate) fn ensure_filter_preview(app: &mut PhotocraftApp, idx: usize, ctx: &e
|
||||
const FADE: &str = "edit.fade";
|
||||
|
||||
/// The preview session of `key`: everything that makes two requests the same target at any scale (document,
|
||||
/// revision, active layer, dialog and its open, and the target, sources, command, tool colours and Match Color's source layer),
|
||||
/// not the other parameters and not `k`. A frame of another session is foreign to the dialog's preview.
|
||||
/// revision, active layer, dialog and its open, the channel target, the addressed document, layer and mask or
|
||||
/// filter mask of the parameters, sources, command, tool colours and Match Color's source layer), not the other
|
||||
/// parameters and not `k`. A frame of another session is foreign to the dialog's preview.
|
||||
pub(crate) fn session_of(key: &crate::filter_dialog::FilterPreviewKey) -> PreviewSession {
|
||||
let layer = key.active.map_or(0, |l| l.0 + 1);
|
||||
let source_layer = key.params.get("sourceLayer");
|
||||
let target = format!("{:?}|{:?}|{}|{:?}|{:?}", key.target, key.sources, key.command, key.tool_colors, source_layer);
|
||||
let addressed = ["document", "layer", "target", "sourceLayer"].map(|name| key.params.get(name));
|
||||
let target = format!("{:?}|{:?}|{}|{:?}|{:?}", key.target, key.sources, key.command, key.tool_colors, addressed);
|
||||
PreviewSession::new(key.doc.0, key.revision, layer).and(key.dialog.value()).and(key.open).and(settings_hash(&[target.as_bytes()]))
|
||||
}
|
||||
|
||||
|
||||
@@ -663,3 +663,23 @@ fn a_reopened_dialog_never_paints_the_previous_dialogs_preview() {
|
||||
!a.filter_preview_worker.busy()
|
||||
});
|
||||
}
|
||||
|
||||
/// A preview belongs to what the command addresses: another document, layer or mask in the parameters is another
|
||||
/// session, while a slider on the same target keeps the session's last frame.
|
||||
#[test]
|
||||
fn an_addressed_layer_or_mask_is_its_own_preview_session() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 16, "height": 16, "background": "white"})).unwrap();
|
||||
open_filter(&mut app, "filter.blur.gaussianBlur");
|
||||
let ctx = app.ctx().clone();
|
||||
assert!(ensure_filter_preview(&mut app, 0, &ctx).is_some(), "the preview reaches the canvas");
|
||||
let key = app.filter_preview.as_ref().unwrap().key.clone();
|
||||
let mut slider = key.clone();
|
||||
slider.params["radius"] = json!(9.0);
|
||||
assert!(same_target(&app, &slider), "a slider keeps the session");
|
||||
for (name, value) in [("target", json!("mask")), ("layer", json!(7)), ("document", json!(1))] {
|
||||
let mut other = key.clone();
|
||||
other.params[name] = value;
|
||||
assert!(!same_target(&app, &other), "another {name} is another session");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user