Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ pub enum FrontendMessage {
UpdateNodeGraphSelection {
selected: Vec<NodeId>,
},
UpdateNodeGraphVisibility {
visible: bool,
},
UpdateNodeTypes {
#[serde(rename = "nodeTypes")]
node_types: Vec<FrontendNodeType>,
Expand Down
30 changes: 26 additions & 4 deletions editor/src/messages/portfolio/document/document_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,18 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
warn!("Image node should be in registry");
return;
};
let Some(transform_node_type) = crate::messages::portfolio::document::node_graph::resolve_document_node_type("Transform") else {
warn!("Transform node should be in registry");
return;
};
let Some(downscale_node_type) = crate::messages::portfolio::document::node_graph::resolve_document_node_type("Downscale") else {
warn!("Downscale node should be in registry");
return;
};

let path = vec![generate_uuid()];
let image_node_id = 100;
let mut network = crate::messages::portfolio::document::node_graph::new_image_network(32, image_node_id);
let [image_node_id, transform_node_id, downscale_node_id] = [100, 101, 102];
let mut network = crate::messages::portfolio::document::node_graph::new_image_network(32, downscale_node_id);

// Transform of parent folder
let to_parent_folder = self.document_legacy.generate_transform_across_scope(&path[..path.len() - 1], None).unwrap_or_default();
Expand All @@ -612,16 +620,30 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe

responses.push_back(DocumentMessage::StartTransaction.into());

let mut pos = 8;
let mut next_pos = || {
pos += 8;
graph_craft::document::DocumentNodeMetadata::position((pos, 4))
};

network.nodes.insert(
image_node_id,
image_node_type.to_document_node(
[graph_craft::document::NodeInput::value(
graph_craft::document::value::TaggedValue::ImageFrame(ImageFrame { image, transform }),
graph_craft::document::value::TaggedValue::ImageFrame(ImageFrame { image, transform: DAffine2::IDENTITY }),
false,
)],
graph_craft::document::DocumentNodeMetadata::position((20, 4)),
next_pos(),
),
);
network.nodes.insert(
transform_node_id,
transform_node_type.to_document_node_default_inputs([Some(graph_craft::document::NodeInput::node(image_node_id, 0))], next_pos()),
);
network.nodes.insert(
downscale_node_id,
downscale_node_type.to_document_node_default_inputs([Some(graph_craft::document::NodeInput::node(transform_node_id, 0))], next_pos()),
);

responses.push_back(
DocumentOperation::AddNodeGraphFrame {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum GraphOperationMessage {
Vector { layer: LayerIdentifier, modification: VectorDataModification },
}

#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
#[derive(PartialEq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
pub enum TransformIn {
Local,
Scope { scope: DAffine2 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ impl<'a> ModifyInputsContext<'a> {
let metadata = output_node.metadata.clone();
let new_input = output_node.inputs[0].clone();
let node_id = generate_uuid();

output_node.metadata.position.x += 8;
output_node.inputs[0] = NodeInput::node(node_id, 0);

let Some(node_type) = resolve_document_node_type(name) else {
Expand All @@ -62,8 +64,8 @@ impl<'a> ModifyInputsContext<'a> {

/// Changes the inputs of a specific node
fn modify_inputs(&mut self, name: &'static str, update_input: impl FnOnce(&mut Vec<NodeInput>)) {
let node_id = self.network.primary_flow().find(|(node, _)| node.name == name).map(|(_, id)| id);
if let Some(node_id) = node_id {
let existing_node_id = self.network.primary_flow().find(|(node, _)| node.name == name).map(|(_, id)| id);
if let Some(node_id) = existing_node_id {
self.modify_existing_node_inputs(node_id, update_input);
} else {
self.modify_new_node(name, update_input);
Expand All @@ -73,6 +75,10 @@ impl<'a> ModifyInputsContext<'a> {
self.responses.add(PropertiesPanelMessage::ResendActiveProperties);
let layer_path = self.layer.to_vec();
self.responses.add(DocumentMessage::NodeGraphFrameGenerate { layer_path });

if existing_node_id.is_none() {
self.responses.add(NodeGraphMessage::SendGraph { should_rerender: false });
}
}

fn fill_set(&mut self, fill: Fill) {
Expand Down Expand Up @@ -117,8 +123,8 @@ impl<'a> ModifyInputsContext<'a> {
TransformIn::Scope { scope } => scope * parent_transform,
TransformIn::Viewport => parent_transform,
};
let pivot = DAffine2::from_translation(bounds.local_pivot(transform_utils::get_current_normalized_pivot(inputs)));
let transform = to.inverse() * pivot.inverse() * transform * pivot * to * layer_transform;
let pivot = DAffine2::from_translation(bounds.layerspace_pivot(transform_utils::get_current_normalized_pivot(inputs)));
let transform = to.inverse() * transform * to * layer_transform;
transform_utils::update_transform(inputs, transform);
});
}
Expand All @@ -130,8 +136,8 @@ impl<'a> ModifyInputsContext<'a> {
TransformIn::Scope { scope } => scope * parent_transform,
TransformIn::Viewport => parent_transform,
};
let pivot = DAffine2::from_translation(bounds.local_pivot(transform_utils::get_current_normalized_pivot(inputs)));
let transform = to.inverse() * pivot.inverse() * transform * pivot;
let pivot = DAffine2::from_translation(bounds.layerspace_pivot(transform_utils::get_current_normalized_pivot(inputs)));
let transform = to.inverse() * transform * pivot;
transform_utils::update_transform(inputs, transform);
});
}
Expand All @@ -141,7 +147,7 @@ impl<'a> ModifyInputsContext<'a> {
let layer_transform = transform_utils::get_current_transform(inputs);
let old_pivot_transform = DAffine2::from_translation(bounds.local_pivot(transform_utils::get_current_normalized_pivot(inputs)));
let new_pivot_transform = DAffine2::from_translation(bounds.local_pivot(new_pivot));
let transform = new_pivot_transform.inverse() * old_pivot_transform * layer_transform * old_pivot_transform.inverse() * new_pivot_transform;
let transform = layer_transform * old_pivot_transform.inverse() * new_pivot_transform;
transform_utils::update_transform(inputs, transform);
inputs[5] = NodeInput::value(TaggedValue::DVec2(new_pivot), false);
});
Expand Down Expand Up @@ -184,7 +190,7 @@ impl<'a> ModifyInputsContext<'a> {
let new_pivot_transform = DAffine2::from_translation(new_layerspace_pivot);
let old_pivot_transform = DAffine2::from_translation(old_layerspace_pivot);

let transform = new_pivot_transform.inverse() * old_pivot_transform * layer_transform * old_pivot_transform.inverse() * new_pivot_transform;
let transform = layer_transform * old_pivot_transform.inverse() * new_pivot_transform;
transform_utils::update_transform(inputs, transform);
});
}
Expand Down Expand Up @@ -231,17 +237,16 @@ impl MessageHandler<GraphOperationMessage, (&mut Document, &mut NodeGraphMessage
let bounds = LayerBounds::new(document, &layer);
if let Some(mut modify_inputs) = ModifyInputsContext::new(&layer, document, node_graph, responses) {
modify_inputs.transform_set(transform, transform_in, parent_transform, bounds);
} else {
let transform = transform.to_cols_array();
responses.add(match transform_in {
TransformIn::Local => Operation::SetLayerTransform { path: layer, transform },
TransformIn::Scope { scope } => {
let scope = scope.to_cols_array();
Operation::SetLayerTransformInScope { path: layer, transform, scope }
}
TransformIn::Viewport => Operation::SetLayerTransformInViewport { path: layer, transform },
});
}
let transform = transform.to_cols_array();
responses.add(match transform_in {
TransformIn::Local => Operation::SetLayerTransform { path: layer, transform },
TransformIn::Scope { scope } => {
let scope = scope.to_cols_array();
Operation::SetLayerTransformInScope { path: layer, transform, scope }
}
TransformIn::Viewport => Operation::SetLayerTransformInViewport { path: layer, transform },
});
}
GraphOperationMessage::TransformSetPivot { layer, pivot } => {
let bounds = LayerBounds::new(document, &layer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ pub enum NodeGraphMessage {
SendGraph {
should_rerender: bool,
},
SetDrawing {
new_drawing: bool,
},
SetInputValue {
node_id: NodeId,
input_index: usize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ pub struct NodeGraphMessageHandler {
pub selected_nodes: Vec<graph_craft::document::NodeId>,
#[serde(skip)]
pub widgets: [LayoutGroup; 2],
/// Do not allow the node graph window to open or close whilst the user is drawing a node graph frame
#[serde(skip)]
pub is_drawing_node_graph_frame: bool,
}

impl NodeGraphMessageHandler {
Expand Down Expand Up @@ -395,6 +392,15 @@ impl NodeGraphMessageHandler {
.filter_map(|(&id, &new)| network.nodes.get(&id).map(|node| (new, node.clone())))
.map(move |(new, node)| (new, node.map_ids(Self::default_node_input, new_ids)))
}
fn clear_graph(responses: &mut VecDeque<Message>) {
let nodes = Vec::new();
let links = Vec::new();
responses.add(FrontendMessage::UpdateNodeGraph { nodes, links });
responses.add(LayoutMessage::SendLayout {
layout: Layout::WidgetLayout(WidgetLayout::new(Vec::new())),
layout_target: crate::messages::layout::utility_types::misc::LayoutTarget::NodeGraphBar,
});
}
}

impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &[LayerId]>)> for NodeGraphMessageHandler {
Expand All @@ -403,13 +409,8 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
#[remain::sorted]
match message {
NodeGraphMessage::CloseNodeGraph => {
// Don't close when drawing a node graph frame
if self.is_drawing_node_graph_frame {
return;
}

if let Some(_old_layer_path) = self.layer_path.take() {
responses.push_back(FrontendMessage::UpdateNodeGraphVisibility { visible: false }.into());
Self::clear_graph(responses);
responses.push_back(PropertiesPanelMessage::ResendActiveProperties.into());
}
}
Expand Down Expand Up @@ -622,16 +623,10 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
Self::send_graph(network, responses);
}
NodeGraphMessage::OpenNodeGraph { layer_path } => {
// Don't open when drawing a node graph frame
if self.is_drawing_node_graph_frame {
return;
}

self.layer_path = Some(layer_path);

if let Some(network) = self.get_active_network(document) {
self.selected_nodes.clear();
responses.push_back(FrontendMessage::UpdateNodeGraphVisibility { visible: true }.into());

Self::send_graph(network, responses);

Expand Down Expand Up @@ -700,25 +695,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
}
}
}
NodeGraphMessage::SetDrawing { new_drawing } => {
let selected: Vec<_> = selected.collect();
// Check if we stopped drawing a node graph frame
if self.is_drawing_node_graph_frame && !new_drawing {
// Check if we should open or close the node graph
if selected.len() == 1
&& document
.layer(selected[0])
.ok()
.filter(|layer| LayerDataTypeDiscriminant::from(&layer.data) == LayerDataTypeDiscriminant::NodeGraphFrame)
.is_some()
{
responses.push_back(NodeGraphMessage::OpenNodeGraph { layer_path: selected[0].to_vec() }.into());
} else {
responses.push_back(NodeGraphMessage::CloseNodeGraph.into());
}
}
self.is_drawing_node_graph_frame = new_drawing
}

NodeGraphMessage::SetInputValue { node_id, input_index, value } => {
if let Some(network) = self.get_active_network(document) {
if let Some(node) = network.nodes.get(&node_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn static_nodes() -> Vec<DocumentNodeType> {
properties: |_document_node, _node_id, _context| node_properties::string_properties("The identity node simply returns the input"),
},
DocumentNodeType {
name: "Image",
name: "Downscale",
category: "Ignore",
identifier: NodeImplementation::DocumentNode(NodeNetwork {
inputs: vec![0],
Expand Down Expand Up @@ -138,7 +138,7 @@ fn static_nodes() -> Vec<DocumentNodeType> {
}),
inputs: vec![DocumentInputType::value("Image", TaggedValue::ImageFrame(ImageFrame::empty()), false)],
outputs: vec![DocumentOutputType::new("Image", FrontendGraphDataType::Raster)],
properties: |_document_node, _node_id, _context| node_properties::string_properties("A bitmap image embedded in this node"),
properties: |_document_node, _node_id, _context| node_properties::string_properties("Downscale the image to a lower resolution"),
},
// DocumentNodeType {
// name: "Input",
Expand Down Expand Up @@ -473,6 +473,14 @@ fn static_nodes() -> Vec<DocumentNodeType> {
outputs: vec![DocumentOutputType::new("Image", FrontendGraphDataType::Raster)],
properties: node_properties::no_properties,
},
DocumentNodeType {
name: "Image",
category: "Ignore",
identifier: NodeImplementation::proto("graphene_core::ops::IdNode"),
inputs: vec![DocumentInputType::value("Image", TaggedValue::ImageFrame(ImageFrame::empty()), false)],
outputs: vec![DocumentOutputType::new("Image", FrontendGraphDataType::Raster)],
properties: |_document_node, _node_id, _context| node_properties::string_properties("A bitmap image embedded in this node"),
},
#[cfg(feature = "gpu")]
DocumentNodeType {
name: "GpuImage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
// Create the input to the graph using an empty image
let image_frame = std::borrow::Cow::Owned(graphene_core::raster::ImageFrame {
image: graphene_core::raster::Image::empty(),
transform,
transform: glam::DAffine2::IDENTITY,
});
// Compute the transform input to the node graph frame
let image_frame: graphene_core::raster::ImageFrame = context.executor.compute_input(context.network, &imaginate_node, 0, image_frame).unwrap_or_default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ pub fn register_artwork_layer_properties(
]
}
LayerDataType::NodeGraphFrame(node_graph_frame) => {
let mut properties_sections = vec![node_section_transform(layer, persistent_data)];
let mut properties_sections = Vec::new();

let mut context = crate::messages::portfolio::document::node_graph::NodePropertiesContext {
persistent_data,
Expand Down
3 changes: 0 additions & 3 deletions editor/src/messages/tool/tool_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, u64, &InputPreprocess

// Notify the frontend about the new active tool to be displayed
tool_data.register_properties(responses, LayoutTarget::ToolShelf);

// Ensure the node graph drawing state is reset
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());
}
ToolMessage::DeactivateTools => {
let tool_data = &mut self.tool_state.tool_data;
Expand Down
10 changes: 8 additions & 2 deletions editor/src/messages/tool/tool_messages/freehand_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use document_legacy::LayerId;
use document_legacy::Operation;
use graphene_core::vector::style::Stroke;

use glam::DVec2;
use glam::{DAffine2, DVec2};
use serde::{Deserialize, Serialize};

#[derive(Default)]
Expand Down Expand Up @@ -219,10 +219,16 @@ fn remove_preview(data: &FreehandToolData) -> Message {
fn add_polyline(data: &FreehandToolData, tool_data: &DocumentToolData, responses: &mut VecDeque<Message>) {
let layer_path = data.path.clone().unwrap();
let subpath = bezier_rs::Subpath::from_anchors(data.points.iter().copied(), false);
let position = subpath.bounding_box().unwrap_or_default().into_iter().sum::<DVec2>() / 2.;
graph_modification_utils::new_vector_layer(vec![subpath], layer_path.clone(), responses);

responses.add(GraphOperationMessage::StrokeSet {
layer: layer_path,
layer: layer_path.clone(),
stroke: Stroke::new(tool_data.primary_color, data.weight),
});
responses.add(GraphOperationMessage::TransformSet {
layer: layer_path,
transform: DAffine2::from_translation(position),
transform_in: TransformIn::Local,
});
}
4 changes: 0 additions & 4 deletions editor/src/messages/tool/tool_messages/imaginate_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ impl Fsm for ImaginateToolFsmState {
(Ready, DragStart) => {
shape_data.start(responses, document, input, render_data);
responses.push_back(DocumentMessage::StartTransaction.into());
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: true }.into());
shape_data.path = Some(document.get_path_for_new_layer());
responses.push_back(DocumentMessage::DeselectAllLayers.into());

Expand Down Expand Up @@ -153,16 +152,13 @@ impl Fsm for ImaginateToolFsmState {
}
(Drawing, DragStop) => {
input.mouse.finish_transaction(shape_data.viewport_drag_start(document), responses);
responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());
shape_data.cleanup(responses);

Ready
}
(Drawing, Abort) => {
responses.push_back(DocumentMessage::AbortTransaction.into());

responses.push_back(NodeGraphMessage::SetDrawing { new_drawing: false }.into());

shape_data.cleanup(responses);

Ready
Expand Down
Loading