Add dragging of layers with the select tool (#293)

* Add dragging of layers with the select tool

* Transform mouse positions based on root transform

* Add TODOs regarding root inverse transforms
This commit is contained in:
Henry Sloan
2021-07-23 21:51:14 -04:00
committed by Keavon Chambers
parent c663b160e6
commit a48f44dd37
2 changed files with 80 additions and 28 deletions

View File

@@ -57,6 +57,7 @@ pub enum DocumentMessage {
SetCanvasRotation(f64),
NudgeSelectedLayers(f64, f64),
FlipLayer(Vec<LayerId>, bool, bool),
DragLayer(Vec<LayerId>, DVec2),
MoveSelectedLayersTo { path: Vec<LayerId>, insert_index: isize },
ReorderSelectedLayers(i32), // relatve_position,
}
@@ -647,6 +648,20 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
);
}
}
DragLayer(path, offset) => {
// TODO: Replace root transformations with functions of the transform api
// and do the same with all instances of `root.transform.inverse()` in other messages
let transformed_mouse_pos = self.active_document().document.root.transform.inverse().transform_vector2(ipp.mouse.position.as_dvec2());
let translation = offset + transformed_mouse_pos;
if let Ok(layer) = self.active_document_mut().document.layer_mut(&path) {
let transform = {
let mut transform = layer.transform;
transform.translation = translation;
transform.to_cols_array()
};
responses.push_back(DocumentOperation::SetLayerTransform { path, transform }.into());
}
}
message => todo!("document_action_handler does not implement: {}", message.to_discriminant().global_name()),
}
}