Add preview for rectangles / shapes / lines (#85)

👀 Add preview for rectangles / shapes / lines
This commit is contained in:
0HyperCube 2021-04-24 22:18:48 +01:00 committed by Keavon Chambers
parent 8a981efd1d
commit 164e9f9729
3 changed files with 65 additions and 9 deletions

View File

@ -46,6 +46,7 @@ impl Fsm for LineToolFsmState {
match (self, event) {
(LineToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
data.drag_start = mouse_state.position;
operations.push(Operation::MountWorkingFolder { path: vec![] });
LineToolFsmState::LmbDown
}
(LineToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
@ -54,10 +55,27 @@ impl Fsm for LineToolFsmState {
}
LineToolFsmState::Ready
}
(LineToolFsmState::LmbDown, Event::MouseMove(mouse_state)) => {
operations.push(Operation::ClearWorkingFolder);
let start = data.drag_start;
let end = mouse_state;
operations.push(Operation::AddLine {
path: vec![],
insert_index: -1,
x0: start.x as f64,
y0: start.y as f64,
x1: end.x as f64,
y1: end.y as f64,
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, 5.)), None),
});
LineToolFsmState::LmbDown
}
// TODO - Check for left mouse button
(LineToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
let distance = data.drag_start.distance(&mouse_state.position);
log::info!("draw Line with distance: {:.2}", distance);
operations.push(Operation::ClearWorkingFolder);
let start = data.drag_start;
let end = mouse_state.position;
operations.push(Operation::AddLine {
@ -69,6 +87,7 @@ impl Fsm for LineToolFsmState {
y1: end.y as f64,
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, 5.)), None),
});
operations.push(Operation::CommitTransaction);
LineToolFsmState::Ready
}

View File

@ -46,6 +46,7 @@ impl Fsm for RectangleToolFsmState {
match (self, event) {
(RectangleToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
data.drag_start = mouse_state.position;
operations.push(Operation::MountWorkingFolder { path: vec![] });
RectangleToolFsmState::LmbDown
}
(RectangleToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
@ -54,11 +55,27 @@ impl Fsm for RectangleToolFsmState {
}
RectangleToolFsmState::Ready
}
(RectangleToolFsmState::LmbDown, Event::MouseMove(mouse_state)) => {
operations.push(Operation::ClearWorkingFolder);
let start = data.drag_start;
let end = mouse_state;
operations.push(Operation::AddRect {
path: vec![],
insert_index: -1,
x0: start.x as f64,
y0: start.y as f64,
x1: end.x as f64,
y1: end.y as f64,
style: style::PathStyle::new(None, Some(style::Fill::new(tool_data.primary_color))),
});
RectangleToolFsmState::LmbDown
}
// TODO - Check for left mouse button
(RectangleToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
let r = data.drag_start.distance(&mouse_state.position);
log::info!("draw rectangle with radius: {:.2}", r);
operations.push(Operation::ClearWorkingFolder);
let start = data.drag_start;
let end = mouse_state.position;
operations.push(Operation::AddRect {
@ -70,6 +87,7 @@ impl Fsm for RectangleToolFsmState {
y1: end.y as f64,
style: style::PathStyle::new(None, Some(style::Fill::new(tool_data.primary_color))),
});
operations.push(Operation::CommitTransaction);
RectangleToolFsmState::Ready
}

View File

@ -47,6 +47,7 @@ impl Fsm for ShapeToolFsmState {
match (self, event) {
(ShapeToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
data.drag_start = mouse_state.position;
operations.push(Operation::MountWorkingFolder { path: vec![] });
ShapeToolFsmState::LmbDown
}
(ShapeToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
@ -55,16 +56,10 @@ impl Fsm for ShapeToolFsmState {
}
ShapeToolFsmState::Ready
}
// TODO - Check for left mouse button
(ShapeToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
let r = data.drag_start.distance(&mouse_state.position);
log::info!("Draw Shape with radius: {:.2}", r);
(ShapeToolFsmState::LmbDown, Event::MouseMove(mouse_state)) => {
operations.push(Operation::ClearWorkingFolder);
let start = data.drag_start;
let end = mouse_state.position;
// TODO: Set the sides value and use it for the operation.
let sides = data.sides;
let end = mouse_state;
operations.push(Operation::AddShape {
path: vec![],
insert_index: -1,
@ -76,6 +71,30 @@ impl Fsm for ShapeToolFsmState {
style: style::PathStyle::new(None, Some(style::Fill::new(tool_data.primary_color))),
});
ShapeToolFsmState::LmbDown
}
// TODO - Check for left mouse button
(ShapeToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
let r = data.drag_start.distance(&mouse_state.position);
log::info!("Draw Shape with radius: {:.2}", r);
let start = data.drag_start;
let end = mouse_state.position;
// TODO: Set the sides value and use it for the operation.
let sides = data.sides;
operations.push(Operation::ClearWorkingFolder);
operations.push(Operation::AddShape {
path: vec![],
insert_index: -1,
x0: start.x as f64,
y0: start.y as f64,
x1: end.x as f64,
y1: end.y as f64,
sides: 6,
style: style::PathStyle::new(None, Some(style::Fill::new(tool_data.primary_color))),
});
operations.push(Operation::CommitTransaction);
ShapeToolFsmState::Ready
}