Implement snapping for rotation (#257)
This commit is contained in:
parent
246ca2c95b
commit
57b8ee0e86
|
|
@ -42,6 +42,8 @@ pub enum DocumentMessage {
|
||||||
TranslateCanvasBegin,
|
TranslateCanvasBegin,
|
||||||
WheelCanvasTranslate { use_y_as_x: bool },
|
WheelCanvasTranslate { use_y_as_x: bool },
|
||||||
RotateCanvasBegin { snap: bool },
|
RotateCanvasBegin { snap: bool },
|
||||||
|
EnableSnapping,
|
||||||
|
DisableSnapping,
|
||||||
ZoomCanvasBegin,
|
ZoomCanvasBegin,
|
||||||
TranslateCanvasEnd,
|
TranslateCanvasEnd,
|
||||||
SetCanvasZoom(f64),
|
SetCanvasZoom(f64),
|
||||||
|
|
@ -69,6 +71,7 @@ pub struct DocumentMessageHandler {
|
||||||
translating: bool,
|
translating: bool,
|
||||||
rotating: bool,
|
rotating: bool,
|
||||||
zooming: bool,
|
zooming: bool,
|
||||||
|
snapping: bool,
|
||||||
mouse_pos: ViewportPosition,
|
mouse_pos: ViewportPosition,
|
||||||
copy_buffer: Vec<Layer>,
|
copy_buffer: Vec<Layer>,
|
||||||
}
|
}
|
||||||
|
|
@ -165,6 +168,7 @@ impl Default for DocumentMessageHandler {
|
||||||
translating: false,
|
translating: false,
|
||||||
rotating: false,
|
rotating: false,
|
||||||
zooming: false,
|
zooming: false,
|
||||||
|
snapping: false,
|
||||||
mouse_pos: ViewportPosition::default(),
|
mouse_pos: ViewportPosition::default(),
|
||||||
copy_buffer: vec![],
|
copy_buffer: vec![],
|
||||||
}
|
}
|
||||||
|
|
@ -383,13 +387,16 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||||
self.translating = true;
|
self.translating = true;
|
||||||
self.mouse_pos = ipp.mouse.position;
|
self.mouse_pos = ipp.mouse.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
RotateCanvasBegin { snap } => {
|
RotateCanvasBegin { snap } => {
|
||||||
self.rotating = true;
|
self.rotating = true;
|
||||||
|
self.snapping = snap;
|
||||||
let layerdata = self.layerdata_mut(&vec![]);
|
let layerdata = self.layerdata_mut(&vec![]);
|
||||||
// TODO: Set up the input system to allow the addition of the Shift key to begin snapping while rotating without snapping
|
|
||||||
layerdata.snap_rotate = snap;
|
layerdata.snap_rotate = snap;
|
||||||
self.mouse_pos = ipp.mouse.position;
|
self.mouse_pos = ipp.mouse.position;
|
||||||
}
|
}
|
||||||
|
EnableSnapping => self.snapping = true,
|
||||||
|
DisableSnapping => self.snapping = false,
|
||||||
ZoomCanvasBegin => {
|
ZoomCanvasBegin => {
|
||||||
self.zooming = true;
|
self.zooming = true;
|
||||||
self.mouse_pos = ipp.mouse.position;
|
self.mouse_pos = ipp.mouse.position;
|
||||||
|
|
@ -419,8 +426,10 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||||
start_vec.angle_between(end_vec)
|
start_vec.angle_between(end_vec)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let snapping = self.snapping;
|
||||||
let layerdata = self.layerdata_mut(&vec![]);
|
let layerdata = self.layerdata_mut(&vec![]);
|
||||||
layerdata.rotation += rotation;
|
layerdata.rotation += rotation;
|
||||||
|
layerdata.snap_rotate = snapping;
|
||||||
responses.push_back(
|
responses.push_back(
|
||||||
FrontendMessage::SetRotation {
|
FrontendMessage::SetRotation {
|
||||||
new_radians: layerdata.snapped_angle(),
|
new_radians: layerdata.snapped_angle(),
|
||||||
|
|
@ -504,10 +513,16 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn actions(&self) -> ActionList {
|
fn actions(&self) -> ActionList {
|
||||||
|
let mut common = actions!(DocumentMessageDiscriminant; Undo, SelectAllLayers, DeselectAllLayers, RenderDocument, ExportDocument, NewDocument, CloseActiveDocument, NextDocument, PrevDocument, MouseMove, TranslateCanvasEnd, TranslateCanvasBegin, PasteLayers, RotateCanvasBegin, ZoomCanvasBegin, SetCanvasZoom, MultiplyCanvasZoom, SetRotation, WheelCanvasZoom, WheelCanvasTranslate);
|
||||||
|
|
||||||
if self.active_document().layer_data.values().any(|data| data.selected) {
|
if self.active_document().layer_data.values().any(|data| data.selected) {
|
||||||
actions!(DocumentMessageDiscriminant; Undo, SelectAllLayers, DeselectAllLayers, DeleteSelectedLayers, DuplicateSelectedLayers, RenderDocument, ExportDocument, NewDocument, CloseActiveDocument, NextDocument, PrevDocument, MouseMove, TranslateCanvasEnd, TranslateCanvasBegin, CopySelectedLayers, PasteLayers, NudgeSelectedLayers, RotateCanvasBegin, ZoomCanvasBegin, SetCanvasZoom, MultiplyCanvasZoom, SetRotation, WheelCanvasZoom, WheelCanvasTranslate)
|
let select = actions!(DocumentMessageDiscriminant; DeleteSelectedLayers, DuplicateSelectedLayers, CopySelectedLayers, NudgeSelectedLayers );
|
||||||
} else {
|
common.extend(select);
|
||||||
actions!(DocumentMessageDiscriminant; Undo, SelectAllLayers, DeselectAllLayers, RenderDocument, ExportDocument, NewDocument, CloseActiveDocument, NextDocument, PrevDocument, MouseMove, TranslateCanvasEnd, TranslateCanvasBegin, PasteLayers, RotateCanvasBegin, ZoomCanvasBegin, SetCanvasZoom, MultiplyCanvasZoom, SetRotation, WheelCanvasZoom, WheelCanvasTranslate)
|
|
||||||
}
|
}
|
||||||
|
if self.rotating {
|
||||||
|
let snapping = actions!(DocumentMessageDiscriminant; EnableSnapping, DisableSnapping);
|
||||||
|
common.extend(snapping);
|
||||||
|
}
|
||||||
|
common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,8 @@ impl Default for Mapping {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let (up, down, pointer_move, mouse_scroll) = mapping![
|
let (up, down, pointer_move, mouse_scroll) = mapping![
|
||||||
entry! {action=DocumentMessage::PasteLayers, key_down=KeyV, modifiers=[KeyControl]},
|
entry! {action=DocumentMessage::PasteLayers, key_down=KeyV, modifiers=[KeyControl]},
|
||||||
|
entry! {action=DocumentMessage::EnableSnapping, key_down=KeyShift},
|
||||||
|
entry! {action=DocumentMessage::DisableSnapping, key_up=KeyShift},
|
||||||
// Select
|
// Select
|
||||||
entry! {action=SelectMessage::MouseMove, message=InputMapperMessage::PointerMove},
|
entry! {action=SelectMessage::MouseMove, message=InputMapperMessage::PointerMove},
|
||||||
entry! {action=SelectMessage::DragStart, key_down=Lmb},
|
entry! {action=SelectMessage::DragStart, key_down=Lmb},
|
||||||
|
|
@ -186,8 +188,8 @@ impl Default for Mapping {
|
||||||
entry! {action=DocumentMessage::ExportDocument, key_down=KeyS, modifiers=[KeyControl, KeyShift]},
|
entry! {action=DocumentMessage::ExportDocument, key_down=KeyS, modifiers=[KeyControl, KeyShift]},
|
||||||
entry! {action=DocumentMessage::ExportDocument, key_down=KeyE, modifiers=[KeyControl]},
|
entry! {action=DocumentMessage::ExportDocument, key_down=KeyE, modifiers=[KeyControl]},
|
||||||
entry! {action=DocumentMessage::MouseMove, message=InputMapperMessage::PointerMove},
|
entry! {action=DocumentMessage::MouseMove, message=InputMapperMessage::PointerMove},
|
||||||
entry! {action=DocumentMessage::RotateCanvasBegin{snap:true}, key_down=Mmb, modifiers=[KeyControl, KeyShift]},
|
|
||||||
entry! {action=DocumentMessage::RotateCanvasBegin{snap:false}, key_down=Mmb, modifiers=[KeyControl]},
|
entry! {action=DocumentMessage::RotateCanvasBegin{snap:false}, key_down=Mmb, modifiers=[KeyControl]},
|
||||||
|
entry! {action=DocumentMessage::RotateCanvasBegin{snap:true}, key_down=Mmb, modifiers=[KeyControl, KeyShift]},
|
||||||
entry! {action=DocumentMessage::ZoomCanvasBegin, key_down=Mmb, modifiers=[KeyShift]},
|
entry! {action=DocumentMessage::ZoomCanvasBegin, key_down=Mmb, modifiers=[KeyShift]},
|
||||||
entry! {action=DocumentMessage::TranslateCanvasBegin, key_down=Mmb},
|
entry! {action=DocumentMessage::TranslateCanvasBegin, key_down=Mmb},
|
||||||
entry! {action=DocumentMessage::TranslateCanvasEnd, key_up=Mmb},
|
entry! {action=DocumentMessage::TranslateCanvasEnd, key_up=Mmb},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue