mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Keep process swatch color when dropping onto Fill or Stroke
This commit is contained in:
1 parent
96e90267ab
commit
3a447162cc
3 files changed
+48
-11
No files matched your search
@@ -353,7 +353,7 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
|
||||
run(app, "graphicStyle.apply", json!({"name": style.name, "ids": [top], "add": drop.op == DropOperation::Copy}))
|
||||
}
|
||||
Payload::Style(_) => Ok(()),
|
||||
Payload::Panel(PanelDrag::Paint { params, paint, rows, .. }) if !params.is_null() => {
|
||||
Payload::Panel(drag @ PanelDrag::Paint { params, paint, .. }) if !params.is_null() => {
|
||||
if let Some(color) = paint.color()
|
||||
&& crate::panels::proxy_cmd(app, false) == "paint.setFill"
|
||||
&& let Some((id, points)) = selected_mesh_drop(app, at, zoom)
|
||||
@@ -362,14 +362,7 @@ pub(crate) fn apply_drop(app: &mut VectorcraftApp, drop: &Dropped) -> Result<(),
|
||||
return run(app, "object.mesh.setPointColor", params);
|
||||
}
|
||||
let Some(hit) = hit() else { return Ok(()) };
|
||||
let mut params = if let Some(rows) = rows.as_ref().filter(|rows| rows.unlinked_process_color)
|
||||
&& app.session.active().is_some_and(|st| st.uid != rows.document)
|
||||
&& let Some(color) = paint.color()
|
||||
{
|
||||
json!({"color": crate::panels::color_json(&color), "keepModel": true})
|
||||
} else {
|
||||
params.clone()
|
||||
};
|
||||
let Some(mut params) = drag.paint_drop_params(app.session.active().map(|st| st.uid)) else { return Ok(()) };
|
||||
params["ids"] = json!([owner(app, &hit)?]);
|
||||
params["focus"] = json!(false);
|
||||
let cmd = crate::panels::proxy_cmd(app, false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! What panels drag onto art and onto each other.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use vectorcraft_color::Paint;
|
||||
|
||||
/// What panels drag onto art and onto each other. One payload type, so the canvas has one drop
|
||||
@@ -70,4 +71,20 @@ impl PanelDrag {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A named process swatch follows the source drawing's swatch. In another drawing its
|
||||
/// captured process color applies without using a same-name swatch there.
|
||||
pub(crate) fn paint_drop_params(&self, destination: Option<u64>) -> Option<Value> {
|
||||
let Self::Paint { paint, params, rows, .. } = self else { return None };
|
||||
if params.is_null() {
|
||||
return None;
|
||||
}
|
||||
if let Some(rows) = rows.as_ref().filter(|rows| rows.unlinked_process_color)
|
||||
&& destination.is_some_and(|uid| uid != rows.document)
|
||||
&& let Some(color) = paint.color()
|
||||
{
|
||||
return Some(json!({"color": crate::panels::color_json(&color), "keepModel": true}));
|
||||
}
|
||||
Some(params.clone())
|
||||
}
|
||||
}
|
||||
@@ -790,9 +790,9 @@ fn takes_drop(mixed: (bool, bool), well: Well, drag: &PanelDrag) -> bool {
|
||||
|
||||
/// Paints the fill (the primary well) or the stroke with the paint `drag` carries.
|
||||
fn drop_paint(app: &mut VectorcraftApp, well: Well, drag: &PanelDrag) {
|
||||
if let PanelDrag::Paint { params, .. } = drag {
|
||||
if let Some(params) = drag.paint_drop_params(app.session.active().map(|st| st.uid)) {
|
||||
let cmd = if well == Well::Primary { "paint.setFill" } else { "paint.setStroke" };
|
||||
app.run(cmd, params.clone()).ok();
|
||||
app.run(cmd, params).ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1085,6 +1085,33 @@ mod tests {
|
||||
assert_eq!(current_paints(&app).0.color().map(|c| c.to_hex()), Some("#00ff00".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proxy_drops_keep_the_dragged_process_color_after_switching_documents() {
|
||||
use crate::panel_drag::SwatchRows;
|
||||
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let name = "Shared Swatch";
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap();
|
||||
app.run("swatch.new", json!({"name": name, "color": "#ff0000"})).unwrap();
|
||||
let source = app.session.active().unwrap();
|
||||
let paint = source.doc.swatch(name).unwrap().paint.clone();
|
||||
let rows = SwatchRows { document: source.uid, grabbed: name.into(), names: vec![name.into()], groups: false, unlinked_process_color: true };
|
||||
let drag = PanelDrag::Paint { paint: paint.clone(), params: json!({"swatch": name}), rows: Some(rows), library: None };
|
||||
app.run("swatch.edit", json!({"name": name, "color": "#ff8800"})).unwrap();
|
||||
drop_paint(&mut app, Well::Primary, &drag);
|
||||
assert_eq!(current_paints(&app).0, app.session.active().unwrap().doc.swatch(name).unwrap().paint);
|
||||
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap();
|
||||
app.run("swatch.new", json!({"name": name, "color": "#0000ff"})).unwrap();
|
||||
let destination = app.session.active().unwrap().doc.swatch(name).unwrap().paint.clone();
|
||||
drop_paint(&mut app, Well::Primary, &drag);
|
||||
drop_paint(&mut app, Well::Secondary, &drag);
|
||||
assert_eq!(current_paints(&app), (paint.clone(), paint));
|
||||
assert_eq!(app.session.active().unwrap().doc.swatch(name).unwrap().paint, destination);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paint_params_roundtrip_shapes() {
|
||||
assert_eq!(paint_params(&Paint::None), json!({"none": true}));
|
||||
|
||||
Reference in new issue
Block a user