mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-02 07:38:12 +08:00
Add preview for rectangles / shapes / lines (#85)
👀 Add preview for rectangles / shapes / lines
This commit is contained in:
committed by
Keavon Chambers
parent
6ddbc29614
commit
2500fc5053
@@ -46,6 +46,7 @@ impl Fsm for LineToolFsmState {
|
|||||||
match (self, event) {
|
match (self, event) {
|
||||||
(LineToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
|
(LineToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
|
||||||
data.drag_start = mouse_state.position;
|
data.drag_start = mouse_state.position;
|
||||||
|
operations.push(Operation::MountWorkingFolder { path: vec![] });
|
||||||
LineToolFsmState::LmbDown
|
LineToolFsmState::LmbDown
|
||||||
}
|
}
|
||||||
(LineToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
|
(LineToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
|
||||||
@@ -54,10 +55,27 @@ impl Fsm for LineToolFsmState {
|
|||||||
}
|
}
|
||||||
LineToolFsmState::Ready
|
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
|
// TODO - Check for left mouse button
|
||||||
(LineToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
|
(LineToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
|
||||||
let distance = data.drag_start.distance(&mouse_state.position);
|
let distance = data.drag_start.distance(&mouse_state.position);
|
||||||
log::info!("draw Line with distance: {:.2}", distance);
|
log::info!("draw Line with distance: {:.2}", distance);
|
||||||
|
operations.push(Operation::ClearWorkingFolder);
|
||||||
let start = data.drag_start;
|
let start = data.drag_start;
|
||||||
let end = mouse_state.position;
|
let end = mouse_state.position;
|
||||||
operations.push(Operation::AddLine {
|
operations.push(Operation::AddLine {
|
||||||
@@ -69,6 +87,7 @@ impl Fsm for LineToolFsmState {
|
|||||||
y1: end.y as f64,
|
y1: end.y as f64,
|
||||||
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, 5.)), None),
|
style: style::PathStyle::new(Some(style::Stroke::new(tool_data.primary_color, 5.)), None),
|
||||||
});
|
});
|
||||||
|
operations.push(Operation::CommitTransaction);
|
||||||
|
|
||||||
LineToolFsmState::Ready
|
LineToolFsmState::Ready
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ impl Fsm for RectangleToolFsmState {
|
|||||||
match (self, event) {
|
match (self, event) {
|
||||||
(RectangleToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
|
(RectangleToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
|
||||||
data.drag_start = mouse_state.position;
|
data.drag_start = mouse_state.position;
|
||||||
|
operations.push(Operation::MountWorkingFolder { path: vec![] });
|
||||||
RectangleToolFsmState::LmbDown
|
RectangleToolFsmState::LmbDown
|
||||||
}
|
}
|
||||||
(RectangleToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
|
(RectangleToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
|
||||||
@@ -54,11 +55,27 @@ impl Fsm for RectangleToolFsmState {
|
|||||||
}
|
}
|
||||||
RectangleToolFsmState::Ready
|
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
|
// TODO - Check for left mouse button
|
||||||
(RectangleToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
|
(RectangleToolFsmState::LmbDown, Event::MouseUp(mouse_state)) => {
|
||||||
let r = data.drag_start.distance(&mouse_state.position);
|
let r = data.drag_start.distance(&mouse_state.position);
|
||||||
log::info!("draw rectangle with radius: {:.2}", r);
|
log::info!("draw rectangle with radius: {:.2}", r);
|
||||||
|
operations.push(Operation::ClearWorkingFolder);
|
||||||
let start = data.drag_start;
|
let start = data.drag_start;
|
||||||
let end = mouse_state.position;
|
let end = mouse_state.position;
|
||||||
operations.push(Operation::AddRect {
|
operations.push(Operation::AddRect {
|
||||||
@@ -70,6 +87,7 @@ impl Fsm for RectangleToolFsmState {
|
|||||||
y1: end.y as f64,
|
y1: end.y as f64,
|
||||||
style: style::PathStyle::new(None, Some(style::Fill::new(tool_data.primary_color))),
|
style: style::PathStyle::new(None, Some(style::Fill::new(tool_data.primary_color))),
|
||||||
});
|
});
|
||||||
|
operations.push(Operation::CommitTransaction);
|
||||||
|
|
||||||
RectangleToolFsmState::Ready
|
RectangleToolFsmState::Ready
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ impl Fsm for ShapeToolFsmState {
|
|||||||
match (self, event) {
|
match (self, event) {
|
||||||
(ShapeToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
|
(ShapeToolFsmState::Ready, Event::MouseDown(mouse_state)) if mouse_state.mouse_keys.contains(MouseKeys::LEFT) => {
|
||||||
data.drag_start = mouse_state.position;
|
data.drag_start = mouse_state.position;
|
||||||
|
operations.push(Operation::MountWorkingFolder { path: vec![] });
|
||||||
ShapeToolFsmState::LmbDown
|
ShapeToolFsmState::LmbDown
|
||||||
}
|
}
|
||||||
(ShapeToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
|
(ShapeToolFsmState::Ready, Event::KeyDown(Key::KeyZ)) => {
|
||||||
@@ -55,16 +56,10 @@ impl Fsm for ShapeToolFsmState {
|
|||||||
}
|
}
|
||||||
ShapeToolFsmState::Ready
|
ShapeToolFsmState::Ready
|
||||||
}
|
}
|
||||||
|
(ShapeToolFsmState::LmbDown, Event::MouseMove(mouse_state)) => {
|
||||||
// TODO - Check for left mouse button
|
operations.push(Operation::ClearWorkingFolder);
|
||||||
(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 start = data.drag_start;
|
||||||
let end = mouse_state.position;
|
let end = mouse_state;
|
||||||
// TODO: Set the sides value and use it for the operation.
|
|
||||||
let sides = data.sides;
|
|
||||||
operations.push(Operation::AddShape {
|
operations.push(Operation::AddShape {
|
||||||
path: vec![],
|
path: vec![],
|
||||||
insert_index: -1,
|
insert_index: -1,
|
||||||
@@ -76,6 +71,30 @@ impl Fsm for ShapeToolFsmState {
|
|||||||
style: style::PathStyle::new(None, Some(style::Fill::new(tool_data.primary_color))),
|
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
|
ShapeToolFsmState::Ready
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user