mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-12-23 10:11:54 +00:00
Automatically place layers into the artboard they're drawn inside of (#2110)
* place new layer from basic tools within an artboard bounds Signed-off-by: James Ryans <james.ryans2012@gmail.com> * add for Text Tool Signed-off-by: James Ryans <james.ryans2012@gmail.com> * use click_xray function Signed-off-by: James Ryans <james.ryans2012@gmail.com> * support for freehand tool Signed-off-by: James Ryans <james.ryans2012@gmail.com> * support spline tool Signed-off-by: James Ryans <james.ryans2012@gmail.com> --------- Signed-off-by: James Ryans <james.ryans2012@gmail.com>
This commit is contained in:
parent
337b8bad13
commit
3be7505faf
9 changed files with 16 additions and 8 deletions
|
|
@ -1652,6 +1652,14 @@ impl DocumentMessageHandler {
|
|||
}
|
||||
}
|
||||
|
||||
/// Finds the artboard that bounds the point in viewport space and be the container of any newly added layers.
|
||||
pub fn new_layer_bounding_artboard(&self, ipp: &InputPreprocessorMessageHandler) -> LayerNodeIdentifier {
|
||||
self.click_xray(ipp)
|
||||
.filter(|layer| self.network_interface.is_artboard(&layer.to_node(), &[]))
|
||||
.next()
|
||||
.unwrap_or(LayerNodeIdentifier::ROOT_PARENT)
|
||||
}
|
||||
|
||||
/// Finds the parent folder which, based on the current selections, should be the container of any newly added layers.
|
||||
pub fn new_layer_parent(&self, include_self: bool) -> LayerNodeIdentifier {
|
||||
self.network_interface
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ impl Fsm for EllipseToolFsmState {
|
|||
let node = node_type.node_template_input_override([None, Some(NodeInput::value(TaggedValue::F64(0.5), false)), Some(NodeInput::value(TaggedValue::F64(0.5), false))]);
|
||||
let nodes = vec![(NodeId(0), node)];
|
||||
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(true), responses);
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
|
||||
responses.add(Message::StartBuffer);
|
||||
responses.add(GraphOperationMessage::TransformSet {
|
||||
layer,
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ impl Fsm for FreehandToolFsmState {
|
|||
|
||||
responses.add(DocumentMessage::DeselectAllLayers);
|
||||
|
||||
let parent = document.new_layer_parent(true);
|
||||
let parent = document.new_layer_bounding_artboard(input);
|
||||
|
||||
let node_type = resolve_document_node_type("Path").expect("Path node does not exist");
|
||||
let node = node_type.default_node_template();
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ impl Fsm for LineToolFsmState {
|
|||
]);
|
||||
let nodes = vec![(NodeId(0), node)];
|
||||
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(false), responses);
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
|
||||
responses.add(Message::StartBuffer);
|
||||
responses.add(GraphOperationMessage::TransformSet {
|
||||
layer,
|
||||
|
|
|
|||
|
|
@ -492,7 +492,7 @@ impl PenToolData {
|
|||
let node_type = resolve_document_node_type("Path").expect("Path node does not exist");
|
||||
let nodes = vec![(NodeId(0), node_type.default_node_template())];
|
||||
|
||||
let parent = document.new_layer_parent(true);
|
||||
let parent = document.new_layer_bounding_artboard(input);
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, parent, responses);
|
||||
tool_options.fill.apply_fill(layer, responses);
|
||||
tool_options.stroke.apply_stroke(tool_options.line_weight, layer, responses);
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ impl Fsm for PolygonToolFsmState {
|
|||
|
||||
let nodes = vec![(NodeId(0), node)];
|
||||
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(false), responses);
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
|
||||
responses.add(Message::StartBuffer);
|
||||
responses.add(GraphOperationMessage::TransformSet {
|
||||
layer,
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ impl Fsm for RectangleToolFsmState {
|
|||
let node = node_type.node_template_input_override([None, Some(NodeInput::value(TaggedValue::F64(1.), false)), Some(NodeInput::value(TaggedValue::F64(1.), false))]);
|
||||
let nodes = vec![(NodeId(0), node)];
|
||||
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_parent(true), responses);
|
||||
let layer = graph_modification_utils::new_custom(NodeId::new(), nodes, document.new_layer_bounding_artboard(input), responses);
|
||||
responses.add(Message::StartBuffer);
|
||||
responses.add(GraphOperationMessage::TransformSet {
|
||||
layer,
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ impl Fsm for SplineToolFsmState {
|
|||
responses.add(DocumentMessage::StartTransaction);
|
||||
responses.add(DocumentMessage::DeselectAllLayers);
|
||||
|
||||
let parent = document.new_layer_parent(true);
|
||||
let parent = document.new_layer_bounding_artboard(input);
|
||||
|
||||
tool_data.weight = tool_options.line_weight;
|
||||
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ impl TextToolData {
|
|||
size: editing_text.font_size,
|
||||
line_height_ratio: editing_text.line_height_ratio,
|
||||
character_spacing: editing_text.character_spacing,
|
||||
parent: document.new_layer_parent(true),
|
||||
parent: document.new_layer_bounding_artboard(input),
|
||||
insert_index: 0,
|
||||
});
|
||||
responses.add(Message::StartBuffer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue