mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-27 00:58:11 +08:00
Initial work migrating vector layers to document graph
* Fix pen tool (except overlays) * Thumbnail of only the layer and not the composite * Fix occasional transform breakages * Constrain size of thumbnail * Insert new layers at the top * Broken layer tree * Fix crash when drawing * Reduce calls to send graph * Reduce calls to updating properties * Store cached transforms upon the document * Fix missing node UI updates * Fix fill tool and clean up imports and indentation * Error on overide existing layer * Fix pen tool (partially) * Fix some lints
This commit is contained in:
committed by
Keavon Chambers
parent
fc6cee372a
commit
4cd72edb64
@@ -195,6 +195,9 @@ pub enum DocumentMessage {
|
||||
folder_path: Vec<LayerId>,
|
||||
},
|
||||
UngroupSelectedLayers,
|
||||
UpdateDocumentTransform {
|
||||
transform: glam::DAffine2,
|
||||
},
|
||||
UpdateLayerMetadata {
|
||||
layer_path: Vec<LayerId>,
|
||||
layer_metadata: LayerMetadata,
|
||||
|
||||
@@ -18,8 +18,9 @@ use crate::messages::tool::utility_types::ToolType;
|
||||
use crate::node_graph_executor::NodeGraphExecutor;
|
||||
|
||||
use document_legacy::document::Document as DocumentLegacy;
|
||||
use document_legacy::document_metadata::LayerNodeIdentifier;
|
||||
use document_legacy::layers::blend_mode::BlendMode;
|
||||
use document_legacy::layers::folder_layer::FolderLayer;
|
||||
|
||||
use document_legacy::layers::layer_info::{LayerDataType, LayerDataTypeDiscriminant};
|
||||
use document_legacy::layers::layer_layer::CachedOutputData;
|
||||
use document_legacy::layers::style::{RenderData, ViewMode};
|
||||
@@ -211,7 +212,6 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
responses,
|
||||
NodeGraphHandlerData {
|
||||
document: &mut self.document_legacy,
|
||||
executor,
|
||||
document_id,
|
||||
document_name: self.name.as_str(),
|
||||
input: ipp,
|
||||
@@ -315,6 +315,7 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
}
|
||||
DeleteLayer { layer_path } => {
|
||||
responses.add_front(DocumentOperation::DeleteLayer { path: layer_path.clone() });
|
||||
responses.add(GraphOperationMessage::DeleteLayer { id: layer_path[0] });
|
||||
responses.add_front(BroadcastEvent::ToolAbort);
|
||||
responses.add(PropertiesPanelMessage::CheckSelectedWasDeleted { path: layer_path });
|
||||
}
|
||||
@@ -938,6 +939,11 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
}
|
||||
responses.add(DocumentMessage::CommitTransaction);
|
||||
}
|
||||
UpdateDocumentTransform { transform } => {
|
||||
self.document_legacy.metadata.document_to_viewport = transform;
|
||||
let transform = graphene_core::renderer::format_transform_matrix(transform);
|
||||
responses.add(FrontendMessage::UpdateDocumentTransform { transform });
|
||||
}
|
||||
UpdateLayerMetadata { layer_path, layer_metadata } => {
|
||||
self.layer_metadata.insert(layer_path, layer_metadata);
|
||||
}
|
||||
@@ -997,6 +1003,9 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
}
|
||||
|
||||
impl DocumentMessageHandler {
|
||||
pub fn network(&self) -> &NodeNetwork {
|
||||
&self.document_legacy.document_network
|
||||
}
|
||||
pub fn rasterize_region_below_layer(&mut self, document_id: u64, layer_path: Vec<LayerId>, _preferences: &PreferencesMessageHandler, persistent_data: &PersistentData) -> Option<Message> {
|
||||
// Prepare the node graph input image
|
||||
|
||||
@@ -1117,7 +1126,7 @@ impl DocumentMessageHandler {
|
||||
pub fn with_name(name: String, ipp: &InputPreprocessorMessageHandler) -> Self {
|
||||
let mut document = Self { name, ..Self::default() };
|
||||
let starting_root_transform = document.navigation_handler.calculate_offset_transform(ipp.viewport_bounds.size() / 2.);
|
||||
document.document_legacy.root.transform = starting_root_transform;
|
||||
document.document_legacy.metadata.document_to_viewport = starting_root_transform;
|
||||
document.artboard_message_handler.artboards_document.root.transform = starting_root_transform;
|
||||
|
||||
document
|
||||
@@ -1221,13 +1230,14 @@ impl DocumentMessageHandler {
|
||||
)
|
||||
}
|
||||
|
||||
fn serialize_structure(&self, folder: &FolderLayer, structure: &mut Vec<u64>, data: &mut Vec<LayerId>, path: &mut Vec<LayerId>) {
|
||||
fn serialize_structure(&self, folder: LayerNodeIdentifier, structure: &mut Vec<u64>, data: &mut Vec<LayerId>, path: &mut Vec<LayerId>) {
|
||||
let mut space = 0;
|
||||
for (id, layer) in folder.layer_ids.iter().zip(folder.layers()).rev() {
|
||||
data.push(*id);
|
||||
for layer_node in folder.children(&self.document_legacy.metadata) {
|
||||
data.push(layer_node.to_node());
|
||||
info!("Pushed child");
|
||||
space += 1;
|
||||
if let LayerDataType::Folder(ref folder) = layer.data {
|
||||
path.push(*id);
|
||||
if layer_node.has_children(&self.document_legacy.metadata) {
|
||||
path.push(layer_node.to_node());
|
||||
if self.layer_metadata(path).expanded {
|
||||
structure.push(space);
|
||||
self.serialize_structure(folder, structure, data, path);
|
||||
@@ -1273,7 +1283,7 @@ impl DocumentMessageHandler {
|
||||
/// ```
|
||||
pub fn serialize_root(&self) -> Vec<u64> {
|
||||
let (mut structure, mut data) = (vec![0], Vec::new());
|
||||
self.serialize_structure(self.document_legacy.root.as_folder().unwrap(), &mut structure, &mut data, &mut vec![]);
|
||||
self.serialize_structure(self.document_legacy.metadata.root(), &mut structure, &mut data, &mut vec![]);
|
||||
structure[0] = structure.len() as u64 - 1;
|
||||
structure.extend(data);
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ use crate::messages::prelude::*;
|
||||
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
|
||||
|
||||
use document_legacy::document::Document;
|
||||
use document_legacy::Operation as DocumentOperation;
|
||||
use graphene_core::renderer::format_transform_matrix;
|
||||
|
||||
use glam::{DAffine2, DVec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -407,21 +405,9 @@ impl NavigationMessageHandler {
|
||||
fn create_document_transform(&self, viewport_bounds: &ViewportBounds, responses: &mut VecDeque<Message>) {
|
||||
let half_viewport = viewport_bounds.size() / 2.;
|
||||
let scaled_half_viewport = half_viewport / self.snapped_scale();
|
||||
responses.add(DocumentOperation::SetLayerTransform {
|
||||
path: vec![],
|
||||
transform: self.calculate_offset_transform(scaled_half_viewport).to_cols_array(),
|
||||
});
|
||||
|
||||
responses.add(ArtboardMessage::DispatchOperation(
|
||||
DocumentOperation::SetLayerTransform {
|
||||
path: vec![],
|
||||
transform: self.calculate_offset_transform(scaled_half_viewport).to_cols_array(),
|
||||
}
|
||||
.into(),
|
||||
));
|
||||
let transform = format_transform_matrix(self.calculate_offset_transform(scaled_half_viewport));
|
||||
responses.add(FrontendMessage::UpdateDocumentTransform { transform });
|
||||
// TODO: Artboard pos
|
||||
let transform = self.calculate_offset_transform(scaled_half_viewport);
|
||||
responses.add(DocumentMessage::UpdateDocumentTransform { transform });
|
||||
}
|
||||
|
||||
pub fn center_zoom(&self, viewport_bounds: DVec2, zoom_factor: f64, mouse: DVec2) -> Message {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use bezier_rs::Subpath;
|
||||
use graph_craft::document::NodeId;
|
||||
use graphene_core::uuid::ManipulatorGroupId;
|
||||
use graphene_core::vector::brush_stroke::BrushStroke;
|
||||
@@ -58,12 +59,16 @@ pub enum GraphOperationMessage {
|
||||
id: NodeId,
|
||||
artboard: Artboard,
|
||||
},
|
||||
NewVectorLayer {
|
||||
id: NodeId,
|
||||
subpaths: Vec<Subpath<ManipulatorGroupId>>,
|
||||
},
|
||||
ResizeArtboard {
|
||||
id: NodeId,
|
||||
location: IVec2,
|
||||
dimensions: IVec2,
|
||||
},
|
||||
DeleteArtboard {
|
||||
DeleteLayer {
|
||||
id: NodeId,
|
||||
},
|
||||
ClearArtboards,
|
||||
|
||||
+99
-61
@@ -1,10 +1,13 @@
|
||||
use super::{resolve_document_node_type, VectorDataModification};
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use bezier_rs::Subpath;
|
||||
use document_legacy::document::Document;
|
||||
use document_legacy::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
|
||||
use document_legacy::{LayerId, Operation};
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{generate_uuid, DocumentNode, DocumentNodeMetadata, NodeId, NodeInput, NodeNetwork, NodeOutput};
|
||||
use graph_craft::document::{generate_uuid, DocumentNode, NodeId, NodeInput, NodeNetwork, NodeOutput};
|
||||
use graphene_core::uuid::ManipulatorGroupId;
|
||||
use graphene_core::vector::brush_stroke::BrushStroke;
|
||||
use graphene_core::vector::style::{Fill, FillType, Stroke};
|
||||
use graphene_core::Artboard;
|
||||
@@ -24,22 +27,11 @@ struct ModifyInputsContext<'a> {
|
||||
layer: &'a [LayerId],
|
||||
outwards_links: HashMap<NodeId, Vec<NodeId>>,
|
||||
layer_node: Option<NodeId>,
|
||||
document_metadata: &'a mut DocumentMetadata,
|
||||
}
|
||||
impl<'a> ModifyInputsContext<'a> {
|
||||
/// Get the node network from the document
|
||||
fn new(layer: &'a [LayerId], document: &'a mut Document, node_graph: &'a mut NodeGraphMessageHandler, responses: &'a mut VecDeque<Message>) -> Option<Self> {
|
||||
document.layer_mut(layer).ok().and_then(|layer| layer.as_layer_network_mut().ok()).map(|network| Self {
|
||||
outwards_links: network.collect_outwards_links(),
|
||||
network,
|
||||
node_graph,
|
||||
responses,
|
||||
layer,
|
||||
layer_node: None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the node network from the document
|
||||
fn new_doc(document: &'a mut Document, node_graph: &'a mut NodeGraphMessageHandler, responses: &'a mut VecDeque<Message>) -> Self {
|
||||
fn new(document: &'a mut Document, node_graph: &'a mut NodeGraphMessageHandler, responses: &'a mut VecDeque<Message>) -> Self {
|
||||
Self {
|
||||
outwards_links: document.document_network.collect_outwards_links(),
|
||||
network: &mut document.document_network,
|
||||
@@ -47,15 +39,22 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
responses,
|
||||
layer: &[],
|
||||
layer_node: None,
|
||||
document_metadata: &mut document.metadata,
|
||||
}
|
||||
}
|
||||
|
||||
fn locate_layer(&mut self, mut id: NodeId) -> Option<NodeId> {
|
||||
while self.network.nodes.get(&id)?.name != "Layer" {
|
||||
id = self.outwards_links.get(&id)?.first().copied()?;
|
||||
/// Get the node network from the document
|
||||
fn new_layer(layer: &'a [LayerId], document: &'a mut Document, node_graph: &'a mut NodeGraphMessageHandler, responses: &'a mut VecDeque<Message>) -> Option<Self> {
|
||||
let mut document = Self::new(document, node_graph, responses);
|
||||
let Some(mut id) = layer.last().copied() else {
|
||||
error!("Tried to modify root layer");
|
||||
return None;
|
||||
};
|
||||
while document.network.nodes.get(&id)?.name != "Layer" {
|
||||
id = document.outwards_links.get(&id)?.first().copied()?;
|
||||
}
|
||||
self.layer_node = Some(id);
|
||||
Some(id)
|
||||
document.layer_node = Some(id);
|
||||
Some(document)
|
||||
}
|
||||
|
||||
/// Updates the input of an existing node
|
||||
@@ -64,8 +63,8 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
update_input(&mut document_node.inputs);
|
||||
}
|
||||
|
||||
pub fn insert_between(&mut self, pre: NodeOutput, post: NodeOutput, mut node: DocumentNode, input: usize, output: usize) -> Option<NodeId> {
|
||||
let id = generate_uuid();
|
||||
pub fn insert_between(&mut self, id: NodeId, pre: NodeOutput, post: NodeOutput, mut node: DocumentNode, input: usize, output: usize, shift_upstream: IVec2) -> Option<NodeId> {
|
||||
assert!(!self.network.nodes.contains_key(&id), "Creating already existing node");
|
||||
let pre_node = self.network.nodes.get_mut(&pre.node_id)?;
|
||||
node.metadata.position = pre_node.metadata.position;
|
||||
|
||||
@@ -75,12 +74,13 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
|
||||
self.network.nodes.insert(id, node);
|
||||
|
||||
self.shift_upstream(id, IVec2::new(-8, 0));
|
||||
self.shift_upstream(id, shift_upstream);
|
||||
|
||||
Some(id)
|
||||
}
|
||||
|
||||
pub fn insert_node_before(&mut self, new_id: NodeId, node_id: NodeId, input_index: usize, mut document_node: DocumentNode, offset: IVec2) -> Option<NodeId> {
|
||||
assert!(!self.network.nodes.contains_key(&new_id), "Creating already existing node");
|
||||
let post_node = self.network.nodes.get_mut(&node_id)?;
|
||||
|
||||
post_node.inputs[input_index] = NodeInput::node(new_id, 0);
|
||||
@@ -90,32 +90,39 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
Some(new_id)
|
||||
}
|
||||
|
||||
pub fn create_layer(&mut self, new_id: NodeId, output_node_id: NodeId) -> Option<NodeId> {
|
||||
let mut current_node = output_node_id;
|
||||
let mut input_index = 0;
|
||||
let mut current_input = &self.network.nodes.get(¤t_node)?.inputs[input_index];
|
||||
pub fn create_layer(&mut self, new_id: NodeId, output_node_id: NodeId, input_index: usize) -> Option<NodeId> {
|
||||
assert!(!self.network.nodes.contains_key(&new_id), "Creating already existing layer");
|
||||
|
||||
while let NodeInput::Node { node_id, output_index, .. } = current_input {
|
||||
let output = NodeOutput::new(output_node_id, input_index);
|
||||
// Locate the node output of the first sibling layer to the new layer
|
||||
let new_id = if let NodeInput::Node { node_id, output_index, .. } = &self.network.nodes.get(&output_node_id)?.inputs[input_index] {
|
||||
let sibling_node = &self.network.nodes.get(node_id)?;
|
||||
if sibling_node.name == "Layer" {
|
||||
current_node = *node_id;
|
||||
input_index = 7;
|
||||
current_input = &self.network.nodes.get(¤t_node)?.inputs[input_index];
|
||||
let sibling_layer = if sibling_node.name == "Layer" {
|
||||
// There is already a layer node
|
||||
NodeOutput::new(*node_id, 0)
|
||||
} else {
|
||||
// Insert a layer node between the output and the new
|
||||
let layer_node = resolve_document_node_type("Layer").expect("Layer node");
|
||||
let node = layer_node.to_document_node_default_inputs([], DocumentNodeMetadata::default());
|
||||
let node_id = self.insert_between(NodeOutput::new(*node_id, *output_index), NodeOutput::new(current_node, input_index), node, 0, 0)?;
|
||||
current_node = node_id;
|
||||
input_index = 7;
|
||||
current_input = &self.network.nodes.get(¤t_node)?.inputs[input_index];
|
||||
}
|
||||
// The user has connected another node to the output. Insert a layer node between the output and the node.
|
||||
let node = resolve_document_node_type("Layer").expect("Layer node").default_document_node();
|
||||
let node_id = self.insert_between(generate_uuid(), NodeOutput::new(*node_id, *output_index), output, node, 0, 0, IVec2::new(-8, 0))?;
|
||||
NodeOutput::new(node_id, 0)
|
||||
};
|
||||
|
||||
let node = resolve_document_node_type("Layer").expect("Layer node").default_document_node();
|
||||
self.insert_between(new_id, sibling_layer, output, node, 7, 0, IVec2::new(-4, 3))
|
||||
} else {
|
||||
let layer_node = resolve_document_node_type("Layer").expect("Node").default_document_node();
|
||||
self.insert_node_before(new_id, output_node_id, input_index, layer_node, IVec2::new(-4, 3))
|
||||
};
|
||||
|
||||
// Update the document metadata structure
|
||||
if let Some(new_id) = new_id {
|
||||
let parent = LayerNodeIdentifier::new(output_node_id, self.network);
|
||||
let new_child = LayerNodeIdentifier::new(new_id, self.network);
|
||||
parent.push_front_child(self.document_metadata, new_child);
|
||||
self.responses.add(DocumentMessage::DocumentStructureChanged);
|
||||
}
|
||||
|
||||
let layer_node = resolve_document_node_type("Layer").expect("Node").to_document_node_default_inputs([], Default::default());
|
||||
let layer_node = self.insert_node_before(new_id, current_node, input_index, layer_node, IVec2::new(-4, 3))?;
|
||||
|
||||
Some(layer_node)
|
||||
new_id
|
||||
}
|
||||
|
||||
fn insert_artboard(&mut self, artboard: Artboard, layer: NodeId) -> Option<NodeId> {
|
||||
@@ -129,9 +136,30 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
],
|
||||
Default::default(),
|
||||
);
|
||||
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
|
||||
self.insert_node_before(generate_uuid(), layer, 0, artboard_node, IVec2::new(-8, 0))
|
||||
}
|
||||
|
||||
fn insert_vector_data(&mut self, subpaths: Vec<Subpath<ManipulatorGroupId>>, layer: NodeId) {
|
||||
let shape = {
|
||||
let node_type = resolve_document_node_type("Shape").expect("Shape node does not exist");
|
||||
node_type.to_document_node_default_inputs([Some(NodeInput::value(TaggedValue::Subpaths(subpaths), false))], Default::default())
|
||||
};
|
||||
let transform = resolve_document_node_type("Transform").expect("Transform node does not exist").default_document_node();
|
||||
let fill = resolve_document_node_type("Fill").expect("Fill node does not exist").default_document_node();
|
||||
let stroke = resolve_document_node_type("Stroke").expect("Stroke node does not exist").default_document_node();
|
||||
|
||||
let stroke_id = generate_uuid();
|
||||
self.insert_node_before(stroke_id, layer, 0, stroke, IVec2::new(-8, 0));
|
||||
let fill_id = generate_uuid();
|
||||
self.insert_node_before(fill_id, stroke_id, 0, fill, IVec2::new(-8, 0));
|
||||
let transform_id = generate_uuid();
|
||||
self.insert_node_before(transform_id, fill_id, 0, transform, IVec2::new(-8, 0));
|
||||
let shape_id = generate_uuid();
|
||||
self.insert_node_before(shape_id, transform_id, 0, shape, IVec2::new(-8, 0));
|
||||
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: true });
|
||||
}
|
||||
|
||||
fn shift_upstream(&mut self, node_id: NodeId, shift: IVec2) {
|
||||
let mut shift_nodes = HashSet::new();
|
||||
let mut stack = vec![node_id];
|
||||
@@ -184,7 +212,6 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
} else {
|
||||
self.modify_new_node(name, update_input);
|
||||
}
|
||||
self.node_graph.update_layer_path(Some(self.layer.to_vec()), self.responses);
|
||||
self.node_graph.nested_path.clear();
|
||||
self.responses.add(PropertiesPanelMessage::ResendActiveProperties);
|
||||
let layer_path = self.layer.to_vec();
|
||||
@@ -354,13 +381,19 @@ impl<'a> ModifyInputsContext<'a> {
|
||||
let mut new_input = None;
|
||||
let post_node = self.outwards_links.get(&id).and_then(|links| links.first().copied());
|
||||
let mut delete_nodes = vec![id];
|
||||
let mut is_artboard = false;
|
||||
for (node, id) in self.network.primary_flow_from_opt(Some(id)) {
|
||||
delete_nodes.push(id);
|
||||
if node.name == "Artboard" {
|
||||
new_input = Some(node.inputs[0].clone());
|
||||
is_artboard = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !is_artboard {
|
||||
LayerNodeIdentifier::new(id, self.network).delete(self.document_metadata);
|
||||
}
|
||||
self.responses.add(DocumentMessage::DocumentStructureChanged);
|
||||
|
||||
for node_id in delete_nodes {
|
||||
self.network.nodes.remove(&node_id);
|
||||
@@ -378,19 +411,19 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
|
||||
fn process_message(&mut self, message: GraphOperationMessage, responses: &mut VecDeque<Message>, (document, node_graph): (&mut Document, &mut NodeGraphMessageHandler)) {
|
||||
match message {
|
||||
GraphOperationMessage::FillSet { layer, fill } => {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.fill_set(fill);
|
||||
} else {
|
||||
responses.add(Operation::SetLayerFill { path: layer, fill });
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::UpdateBounds { layer, old_bounds, new_bounds } => {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.update_bounds(old_bounds, new_bounds);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::StrokeSet { layer, stroke } => {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.stroke_set(stroke);
|
||||
} else {
|
||||
responses.add(Operation::SetLayerStroke { path: layer, stroke });
|
||||
@@ -402,9 +435,9 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
|
||||
transform_in,
|
||||
skip_rerender,
|
||||
} => {
|
||||
let parent_transform = document.multiply_transforms(&layer[..layer.len() - 1]).unwrap_or_default();
|
||||
let parent_transform = document.metadata.document_to_viewport * document.multiply_transforms(&layer[..layer.len() - 1]).unwrap_or_default();
|
||||
let bounds = LayerBounds::new(document, &layer);
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.transform_change(transform, transform_in, parent_transform, bounds, skip_rerender);
|
||||
}
|
||||
|
||||
@@ -424,10 +457,10 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
|
||||
transform_in,
|
||||
skip_rerender,
|
||||
} => {
|
||||
let parent_transform = document.multiply_transforms(&layer[..layer.len() - 1]).unwrap_or_default();
|
||||
let parent_transform = document.metadata.document_to_viewport * document.multiply_transforms(&layer[..layer.len() - 1]).unwrap_or_default();
|
||||
let current_transform = document.layer(&layer).ok().map(|layer| layer.transform);
|
||||
let bounds = LayerBounds::new(document, &layer);
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.transform_set(transform, transform_in, parent_transform, current_transform, bounds, skip_rerender);
|
||||
}
|
||||
let transform = transform.to_cols_array();
|
||||
@@ -442,7 +475,7 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
|
||||
}
|
||||
GraphOperationMessage::TransformSetPivot { layer, pivot } => {
|
||||
let bounds = LayerBounds::new(document, &layer);
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.pivot_set(pivot, bounds);
|
||||
}
|
||||
|
||||
@@ -450,33 +483,38 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
|
||||
responses.add(Operation::SetPivot { layer_path: layer, pivot });
|
||||
}
|
||||
GraphOperationMessage::Vector { layer, modification } => {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.vector_modify(modification);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::Brush { layer, strokes } => {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&layer, document, node_graph, responses) {
|
||||
modify_inputs.brush_modify(strokes);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::NewArtboard { id, artboard } => {
|
||||
let mut modify_inputs = ModifyInputsContext::new_doc(document, node_graph, responses);
|
||||
if let Some(layer) = modify_inputs.create_layer(id, modify_inputs.network.outputs[0].node_id) {
|
||||
let mut modify_inputs = ModifyInputsContext::new(document, node_graph, responses);
|
||||
if let Some(layer) = modify_inputs.create_layer(id, modify_inputs.network.outputs[0].node_id, 0) {
|
||||
modify_inputs.insert_artboard(artboard, layer);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::NewVectorLayer { id, subpaths } => {
|
||||
let mut modify_inputs = ModifyInputsContext::new(document, node_graph, responses);
|
||||
if let Some(layer) = modify_inputs.create_layer(id, modify_inputs.network.outputs[0].node_id, 0) {
|
||||
modify_inputs.insert_vector_data(subpaths, layer);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::ResizeArtboard { id, location, dimensions } => {
|
||||
let mut modify_inputs = ModifyInputsContext::new_doc(document, node_graph, responses);
|
||||
if modify_inputs.locate_layer(id).is_some() {
|
||||
if let Some(mut modify_inputs) = ModifyInputsContext::new_layer(&[id], document, node_graph, responses) {
|
||||
modify_inputs.resize_artboard(location, dimensions);
|
||||
}
|
||||
}
|
||||
GraphOperationMessage::DeleteArtboard { id } => {
|
||||
let mut modify_inputs = ModifyInputsContext::new_doc(document, node_graph, responses);
|
||||
GraphOperationMessage::DeleteLayer { id } => {
|
||||
let mut modify_inputs = ModifyInputsContext::new(document, node_graph, responses);
|
||||
modify_inputs.delete_layer(id);
|
||||
}
|
||||
GraphOperationMessage::ClearArtboards => {
|
||||
let mut modify_inputs = ModifyInputsContext::new_doc(document, node_graph, responses);
|
||||
let mut modify_inputs = ModifyInputsContext::new(document, node_graph, responses);
|
||||
let artboard_nodes = modify_inputs.network.nodes.iter().filter(|(_, node)| node.name == "Artboard").map(|(id, _)| *id).collect::<Vec<_>>();
|
||||
for id in artboard_nodes {
|
||||
modify_inputs.delete_layer(id);
|
||||
|
||||
@@ -2,7 +2,7 @@ pub use self::document_node_types::*;
|
||||
use crate::messages::input_mapper::utility_types::macros::action_keys;
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::node_graph_executor::{GraphIdentifier, NodeGraphExecutor};
|
||||
use crate::node_graph_executor::GraphIdentifier;
|
||||
|
||||
use document_legacy::document::Document;
|
||||
use document_legacy::LayerId;
|
||||
@@ -87,8 +87,6 @@ pub struct FrontendNode {
|
||||
pub position: (i32, i32),
|
||||
pub disabled: bool,
|
||||
pub previewed: bool,
|
||||
#[serde(rename = "thumbnailSvg")]
|
||||
pub thumbnail_svg: Option<String>,
|
||||
}
|
||||
|
||||
// (link_start, link_end, link_end_input_index)
|
||||
@@ -128,11 +126,6 @@ pub struct NodeGraphMessageHandler {
|
||||
}
|
||||
|
||||
impl NodeGraphMessageHandler {
|
||||
pub fn update_layer_path(&mut self, layer_path: Option<Vec<LayerId>>, responses: &mut VecDeque<Message>) {
|
||||
self.layer_path = layer_path;
|
||||
responses.add(NodeGraphMessage::UpdateNewNodeGraph);
|
||||
}
|
||||
|
||||
fn get_root_network<'a>(&self, document: &'a Document) -> &'a graph_craft::document::NodeNetwork {
|
||||
self.layer_path
|
||||
.as_ref()
|
||||
@@ -284,7 +277,7 @@ impl NodeGraphMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fn send_graph(network: &NodeNetwork, executor: &NodeGraphExecutor, layer_path: &Option<Vec<LayerId>>, responses: &mut VecDeque<Message>) {
|
||||
fn send_graph(network: &NodeNetwork, layer_path: &Option<Vec<LayerId>>, responses: &mut VecDeque<Message>) {
|
||||
responses.add(PropertiesPanelMessage::ResendActiveProperties);
|
||||
|
||||
let layer_id = layer_path.as_ref().and_then(|path| path.last().copied());
|
||||
@@ -345,8 +338,7 @@ impl NodeGraphMessageHandler {
|
||||
});
|
||||
let primary_output = outputs.next();
|
||||
|
||||
let graph_identifier = GraphIdentifier::new(layer_id);
|
||||
let thumbnail_svg = executor.thumbnails.get(&graph_identifier).and_then(|thumbnails| thumbnails.get(id)).map(|svg| svg.to_string());
|
||||
let _graph_identifier = GraphIdentifier::new(layer_id);
|
||||
|
||||
nodes.push(FrontendNode {
|
||||
id: *id,
|
||||
@@ -358,7 +350,6 @@ impl NodeGraphMessageHandler {
|
||||
position: node.metadata.position.into(),
|
||||
previewed: network.outputs_contain(*id),
|
||||
disabled: network.disabled.contains(id),
|
||||
thumbnail_svg,
|
||||
})
|
||||
}
|
||||
responses.add(FrontendMessage::UpdateNodeGraph { nodes, links });
|
||||
@@ -467,7 +458,6 @@ impl NodeGraphMessageHandler {
|
||||
#[derive(Debug)]
|
||||
pub struct NodeGraphHandlerData<'a> {
|
||||
pub document: &'a mut Document,
|
||||
pub executor: &'a NodeGraphExecutor,
|
||||
pub document_id: u64,
|
||||
pub document_name: &'a str,
|
||||
pub input: &'a InputPreprocessorMessageHandler,
|
||||
@@ -478,9 +468,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
fn process_message(&mut self, message: NodeGraphMessage, responses: &mut VecDeque<Message>, data: NodeGraphHandlerData<'a>) {
|
||||
#[remain::sorted]
|
||||
match message {
|
||||
NodeGraphMessage::CloseNodeGraph => {
|
||||
self.update_layer_path(None, responses);
|
||||
}
|
||||
NodeGraphMessage::CloseNodeGraph => {}
|
||||
NodeGraphMessage::ConnectNodesByLink {
|
||||
output_node,
|
||||
output_node_connector_index,
|
||||
@@ -571,6 +559,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
if self.selected_nodes.iter().any(|&node_id| network.connected_to_output(node_id)) {
|
||||
if let Some(layer_path) = self.layer_path.clone() {
|
||||
responses.add(DocumentMessage::InputFrameRasterizeRegionBelowLayer { layer_path });
|
||||
} else {
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,7 +600,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
}
|
||||
}
|
||||
if let Some(network) = self.get_active_network(data.document) {
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
}
|
||||
self.collect_nested_addresses(data.document, data.document_name, responses);
|
||||
self.update_selected(data.document, responses);
|
||||
@@ -635,7 +625,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
responses.add(NodeGraphMessage::InsertNode { node_id, document_node });
|
||||
}
|
||||
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
self.update_selected(data.document, responses);
|
||||
responses.add(NodeGraphMessage::SendGraph { should_rerender: false });
|
||||
}
|
||||
@@ -646,7 +636,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
self.nested_path.pop();
|
||||
}
|
||||
if let Some(network) = self.get_active_network(data.document) {
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
}
|
||||
self.collect_nested_addresses(data.document, data.document_name, responses);
|
||||
self.update_selected(data.document, responses);
|
||||
@@ -697,7 +687,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
node.metadata.position += IVec2::new(displacement_x, displacement_y)
|
||||
}
|
||||
}
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
}
|
||||
NodeGraphMessage::OpenNodeGraph { layer_path } => {
|
||||
self.layer_path = Some(layer_path);
|
||||
@@ -705,7 +695,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
if let Some(network) = self.get_active_network(data.document) {
|
||||
self.selected_nodes.clear();
|
||||
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
|
||||
let node_types = document_node_types::collect_node_types();
|
||||
responses.add(FrontendMessage::UpdateNodeTypes { node_types });
|
||||
@@ -774,7 +764,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
}
|
||||
NodeGraphMessage::SendGraph { should_rerender } => {
|
||||
if let Some(network) = self.get_active_network(data.document) {
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
if should_rerender {
|
||||
if let Some(layer_path) = self.layer_path.clone() {
|
||||
responses.add(DocumentMessage::InputFrameRasterizeRegionBelowLayer { layer_path });
|
||||
@@ -901,12 +891,14 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
.disabled
|
||||
.extend(self.selected_nodes.iter().filter(|&id| !network.inputs.contains(id) && !original_outputs.contains(id)));
|
||||
}
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
|
||||
// Only generate node graph if one of the selected nodes is connected to the output
|
||||
if self.selected_nodes.iter().any(|&node_id| network.connected_to_output(node_id)) {
|
||||
if let Some(layer_path) = self.layer_path.clone() {
|
||||
responses.add(DocumentMessage::InputFrameRasterizeRegionBelowLayer { layer_path });
|
||||
} else {
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -927,18 +919,20 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
}
|
||||
self.update_selection_action_buttons(data.document, responses);
|
||||
if let Some(layer_path) = self.layer_path.clone() {
|
||||
responses.add(DocumentMessage::InputFrameRasterizeRegionBelowLayer { layer_path });
|
||||
} else {
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::UpdateNewNodeGraph => {
|
||||
if let Some(network) = self.get_active_network(data.document) {
|
||||
self.selected_nodes.clear();
|
||||
|
||||
Self::send_graph(network, data.executor, &self.layer_path, responses);
|
||||
Self::send_graph(network, &self.layer_path, responses);
|
||||
|
||||
let node_types = document_node_types::collect_node_types();
|
||||
responses.add(FrontendMessage::UpdateNodeTypes { node_types });
|
||||
|
||||
+26
-13
@@ -181,23 +181,14 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
||||
name: "Layer",
|
||||
category: "General",
|
||||
identifier: NodeImplementation::DocumentNode(NodeNetwork {
|
||||
inputs: vec![0; 8],
|
||||
outputs: vec![NodeOutput::new(1, 0)],
|
||||
inputs: vec![0, 2, 2, 2, 2, 2, 2, 2],
|
||||
outputs: vec![NodeOutput::new(2, 0)],
|
||||
nodes: [
|
||||
(
|
||||
0,
|
||||
DocumentNode {
|
||||
inputs: vec![
|
||||
NodeInput::Network(concrete!(graphene_core::vector::VectorData)),
|
||||
NodeInput::Network(concrete!(String)),
|
||||
NodeInput::Network(concrete!(BlendMode)),
|
||||
NodeInput::Network(concrete!(f32)),
|
||||
NodeInput::Network(concrete!(bool)),
|
||||
NodeInput::Network(concrete!(bool)),
|
||||
NodeInput::Network(concrete!(bool)),
|
||||
NodeInput::Network(concrete!(graphene_core::GraphicGroup)),
|
||||
],
|
||||
implementation: DocumentNodeImplementation::proto("graphene_core::ConstructLayerNode<_, _, _, _, _, _, _>"),
|
||||
inputs: vec![NodeInput::Network(concrete!(graphene_core::vector::VectorData))],
|
||||
implementation: DocumentNodeImplementation::proto("graphene_core::ToGraphicElementData"),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
@@ -211,6 +202,23 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
2,
|
||||
DocumentNode {
|
||||
inputs: vec![
|
||||
NodeInput::node(1, 0),
|
||||
NodeInput::Network(concrete!(String)),
|
||||
NodeInput::Network(concrete!(BlendMode)),
|
||||
NodeInput::Network(concrete!(f32)),
|
||||
NodeInput::Network(concrete!(bool)),
|
||||
NodeInput::Network(concrete!(bool)),
|
||||
NodeInput::Network(concrete!(bool)),
|
||||
NodeInput::Network(concrete!(graphene_core::GraphicGroup)),
|
||||
],
|
||||
implementation: DocumentNodeImplementation::proto("graphene_core::ConstructLayerNode<_, _, _, _, _, _, _>"),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
..Default::default()
|
||||
@@ -2390,6 +2398,11 @@ impl DocumentNodeType {
|
||||
let inputs = self.inputs.iter().map(|default| input_override.next().unwrap_or_default().unwrap_or_else(|| default.default.clone()));
|
||||
self.to_document_node(inputs, metadata)
|
||||
}
|
||||
|
||||
/// Converts the [DocumentNodeType] type to a [DocumentNode], completly default
|
||||
pub fn default_document_node(&self) -> DocumentNode {
|
||||
self.to_document_node(self.inputs.iter().map(|input| input.default.clone()), DocumentNodeMetadata::default())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wrap_network_in_scope(mut network: NodeNetwork) -> NodeNetwork {
|
||||
|
||||
Reference in New Issue
Block a user