mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 11:38:11 +08:00
Make Imaginate into a node (#878)
* Simplify document node input defenitions * Remove imaginate layer * Imaginate node properties * Fix serde feature gate * Add Proc Macro for Protonode implementation * Fix incorrect type * Add cargo.toml metadata * Send imaginate params to frontend * Fix image_creativity range * Finish imaginate implementation * Fix the imaginate draw tool * Remove node-graph/rpco-macro * Cargo fmt * Fix missing workspace member * Changes to the resolution * Add checkbox for Imaginate auto resolution; improve Properties panel layouts And fix bugs in panel resizing * Implement the Rescale button * Reorder imports * Update Rust deps Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
2f2daa25e9
commit
2732492307
@@ -2,6 +2,7 @@ use crate::consts::DRAG_THRESHOLD;
|
||||
use crate::messages::frontend::utility_types::MouseCursorIcon;
|
||||
use crate::messages::input_mapper::utility_types::input_keyboard::{Key, KeysGroup, MouseMotion};
|
||||
use crate::messages::layout::utility_types::layout_widget::PropertyHolder;
|
||||
use crate::messages::portfolio::document::node_graph::IMAGINATE_NODE;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::messages::tool::common_functionality::resize::Resize;
|
||||
use crate::messages::tool::utility_types::{EventToMessageMap, Fsm, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
@@ -137,11 +138,73 @@ impl Fsm for ImaginateToolFsmState {
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
use graph_craft::{document::*, generic, proto::*};
|
||||
|
||||
let imaginate_node_type = IMAGINATE_NODE;
|
||||
let num_inputs = imaginate_node_type.inputs.len();
|
||||
|
||||
let imaginate_inner_network = NodeNetwork {
|
||||
inputs: (0..num_inputs).map(|_| 0).collect(),
|
||||
output: 0,
|
||||
nodes: [(
|
||||
0,
|
||||
DocumentNode {
|
||||
name: format!("{}_impl", imaginate_node_type.name),
|
||||
// TODO: Allow inserting nodes that contain other nodes.
|
||||
implementation: DocumentNodeImplementation::Unresolved(imaginate_node_type.identifier.clone()),
|
||||
inputs: (0..num_inputs).map(|_| NodeInput::Network).collect(),
|
||||
metadata: DocumentNodeMetadata::default(),
|
||||
},
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
};
|
||||
let mut imaginate_inputs: Vec<NodeInput> = imaginate_node_type.inputs.iter().map(|input| input.default.clone()).collect();
|
||||
imaginate_inputs[0] = NodeInput::Node(0);
|
||||
|
||||
let network = NodeNetwork {
|
||||
inputs: vec![0],
|
||||
output: 1,
|
||||
nodes: [
|
||||
(
|
||||
0,
|
||||
DocumentNode {
|
||||
name: "Input".into(),
|
||||
inputs: vec![NodeInput::Network],
|
||||
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("T")])),
|
||||
metadata: DocumentNodeMetadata { position: (8, 4) },
|
||||
},
|
||||
),
|
||||
(
|
||||
1,
|
||||
DocumentNode {
|
||||
name: "Output".into(),
|
||||
inputs: vec![NodeInput::Node(2)],
|
||||
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("T")])),
|
||||
metadata: DocumentNodeMetadata { position: (32, 4) },
|
||||
},
|
||||
),
|
||||
(
|
||||
2,
|
||||
DocumentNode {
|
||||
name: imaginate_node_type.name.to_string(),
|
||||
inputs: imaginate_inputs,
|
||||
// TODO: Allow inserting nodes that contain other nodes.
|
||||
implementation: DocumentNodeImplementation::Network(imaginate_inner_network),
|
||||
metadata: graph_craft::document::DocumentNodeMetadata { position: (20, 4) },
|
||||
},
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
};
|
||||
|
||||
responses.push_back(
|
||||
Operation::AddImaginateFrame {
|
||||
Operation::AddNodeGraphFrame {
|
||||
path: shape_data.path.clone().unwrap(),
|
||||
insert_index: -1,
|
||||
transform: DAffine2::ZERO.to_cols_array(),
|
||||
network,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
||||
@@ -137,11 +137,40 @@ impl Fsm for NodeGraphToolFsmState {
|
||||
shape_data.path = Some(document.get_path_for_new_layer());
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
use graph_craft::{document::*, generic, proto::*};
|
||||
let network = NodeNetwork {
|
||||
inputs: vec![0],
|
||||
output: 1,
|
||||
nodes: [
|
||||
(
|
||||
0,
|
||||
DocumentNode {
|
||||
name: "Input".into(),
|
||||
inputs: vec![NodeInput::Network],
|
||||
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("T")])),
|
||||
metadata: DocumentNodeMetadata { position: (8, 4) },
|
||||
},
|
||||
),
|
||||
(
|
||||
1,
|
||||
DocumentNode {
|
||||
name: "Output".into(),
|
||||
inputs: vec![NodeInput::Node(0)],
|
||||
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdNode", &[generic!("T")])),
|
||||
metadata: DocumentNodeMetadata { position: (20, 4) },
|
||||
},
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
};
|
||||
|
||||
responses.push_back(
|
||||
Operation::AddNodeGraphFrame {
|
||||
path: shape_data.path.clone().unwrap(),
|
||||
insert_index: -1,
|
||||
transform: DAffine2::ZERO.to_cols_array(),
|
||||
network,
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::application::generate_uuid;
|
||||
use crate::consts::{ROTATE_SNAP_ANGLE, SELECTION_TOLERANCE};
|
||||
use crate::messages::frontend::utility_types::{FrontendImageData, MouseCursorIcon};
|
||||
use crate::messages::frontend::utility_types::MouseCursorIcon;
|
||||
use crate::messages::input_mapper::utility_types::input_keyboard::{Key, KeysGroup, MouseMotion};
|
||||
use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
|
||||
use crate::messages::layout::utility_types::layout_widget::{Layout, LayoutGroup, PropertyHolder, Widget, WidgetCallback, WidgetHolder, WidgetLayout};
|
||||
@@ -375,7 +375,7 @@ impl Fsm for SelectToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
(document, document_id, _global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
(document, _document_id, _global_tool_data, input, font_cache): ToolActionHandlerData,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
@@ -572,7 +572,7 @@ impl Fsm for SelectToolFsmState {
|
||||
tool_data.drag_current = mouse_position + closest_move;
|
||||
|
||||
if input.keyboard.get(duplicate as usize) && tool_data.not_duplicated_layers.is_none() {
|
||||
tool_data.start_duplicates(document, document_id, responses);
|
||||
tool_data.start_duplicates(document, responses);
|
||||
} else if !input.keyboard.get(duplicate as usize) && tool_data.not_duplicated_layers.is_some() {
|
||||
tool_data.stop_duplicates(responses);
|
||||
}
|
||||
@@ -929,7 +929,7 @@ impl Fsm for SelectToolFsmState {
|
||||
|
||||
impl SelectToolData {
|
||||
/// Duplicates the currently dragging layers. Called when Alt is pressed and the layers have not yet been duplicated.
|
||||
fn start_duplicates(&mut self, document: &DocumentMessageHandler, document_id: u64, responses: &mut VecDeque<Message>) {
|
||||
fn start_duplicates(&mut self, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>) {
|
||||
responses.push_back(DocumentMessage::DeselectAllLayers.into());
|
||||
|
||||
self.not_duplicated_layers = Some(self.layers_dragging.clone());
|
||||
@@ -947,7 +947,7 @@ impl SelectToolData {
|
||||
|
||||
// Copy the layers.
|
||||
// Not using the Copy message allows us to retrieve the ids of the new layers to initialize the drag.
|
||||
let mut layer = match document.graphene_document.layer(layer_path) {
|
||||
let layer = match document.graphene_document.layer(layer_path) {
|
||||
Ok(layer) => layer.clone(),
|
||||
Err(e) => {
|
||||
warn!("Could not access selected layer {:?}: {:?}", layer_path, e);
|
||||
@@ -958,20 +958,6 @@ impl SelectToolData {
|
||||
let layer_metadata = *document.layer_metadata(layer_path);
|
||||
*layer_path.last_mut().unwrap() = generate_uuid();
|
||||
|
||||
let image_data = if let LayerDataType::Imaginate(imaginate) = &mut layer.data {
|
||||
imaginate.blob_url = None;
|
||||
|
||||
imaginate.image_data.as_ref().map(|data| {
|
||||
vec![FrontendImageData {
|
||||
path: layer_path.clone(),
|
||||
image_data: data.image_data.clone(),
|
||||
mime: imaginate.mime.clone(),
|
||||
}]
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
responses.push_back(
|
||||
Operation::InsertLayer {
|
||||
layer: Box::new(layer),
|
||||
@@ -988,10 +974,6 @@ impl SelectToolData {
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
|
||||
if let Some(image_data) = image_data {
|
||||
responses.push_back(FrontendMessage::UpdateImageData { image_data, document_id }.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -315,8 +315,8 @@ fn list_tools_in_groups() -> Vec<Vec<ToolAvailability>> {
|
||||
],
|
||||
vec![
|
||||
// Raster tool group
|
||||
ToolAvailability::Available(Box::<imaginate_tool::ImaginateTool>::default()),
|
||||
ToolAvailability::Available(Box::<node_graph_frame_tool::NodeGraphFrameTool>::default()),
|
||||
ToolAvailability::Available(Box::<imaginate_tool::ImaginateTool>::default()),
|
||||
ToolAvailability::ComingSoon(ToolEntry {
|
||||
tool_type: ToolType::Brush,
|
||||
icon_name: "RasterBrushTool".into(),
|
||||
|
||||
Reference in New Issue
Block a user