mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 04:18:11 +08:00
Fix regressions introduced in the vector nodes migration (#1100)
* Fix double click to enter path tool * Fix error * Fix transform bug * Fix squaring scale on images * Shift node position and refresh graph * Downscale node seperate * Fix mirror * Remove duplicate transform * Always show node graph * Correctly set freehand and spline tool positions * Run cargo format * Maybe fix the scale * Downscaled image is always smaller than origional * Fix one crash * Don't show node graph on welcome screen * Reduce default graph panel height --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
92fe0bea50
commit
d710285029
@@ -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();
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 },
|
||||
|
||||
+23
-18
@@ -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 {
|
||||
@@ -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);
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -65,9 +65,6 @@ pub enum NodeGraphMessage {
|
||||
SendGraph {
|
||||
should_rerender: bool,
|
||||
},
|
||||
SetDrawing {
|
||||
new_drawing: bool,
|
||||
},
|
||||
SetInputValue {
|
||||
node_id: NodeId,
|
||||
input_index: usize,
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+10
-2
@@ -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],
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user