Rename Crop tool to Artboard tool

This commit is contained in:
Keavon Chambers
2022-04-21 10:52:33 -07:00
parent 2ace16df0f
commit d65ce17d7e
14 changed files with 68 additions and 68 deletions

View File

@@ -49,12 +49,12 @@ impl Default for Mapping {
entry! {action=SelectToolMessage::EditLayer, message=InputMapperMessage::DoubleClick},
entry! {action=SelectToolMessage::Abort, key_down=Rmb},
entry! {action=SelectToolMessage::Abort, key_down=KeyEscape},
// Crop
entry! {action=CropToolMessage::PointerDown, key_down=Lmb},
entry! {action=CropToolMessage::PointerMove { constrain_axis_or_aspect: KeyShift, center: KeyAlt }, message=InputMapperMessage::PointerMove},
entry! {action=CropToolMessage::PointerUp, key_up=Lmb},
entry! {action=CropToolMessage::DeleteSelected, key_down=KeyDelete},
entry! {action=CropToolMessage::DeleteSelected, key_down=KeyBackspace},
// Artboard
entry! {action=ArtboardToolMessage::PointerDown, key_down=Lmb},
entry! {action=ArtboardToolMessage::PointerMove { constrain_axis_or_aspect: KeyShift, center: KeyAlt }, message=InputMapperMessage::PointerMove},
entry! {action=ArtboardToolMessage::PointerUp, key_up=Lmb},
entry! {action=ArtboardToolMessage::DeleteSelected, key_down=KeyDelete},
entry! {action=ArtboardToolMessage::DeleteSelected, key_down=KeyBackspace},
// Navigate
entry! {action=NavigateToolMessage::ClickZoom { zoom_in: false }, key_up=Lmb, modifiers=[KeyShift]},
entry! {action=NavigateToolMessage::ClickZoom { zoom_in: true }, key_up=Lmb},

View File

@@ -72,7 +72,7 @@ pub mod message_prelude {
pub use crate::layout::{LayoutMessage, LayoutMessageDiscriminant};
pub use crate::misc::derivable_custom_traits::{ToDiscriminant, TransitiveChild};
pub use crate::viewport_tools::tool_message::{ToolMessage, ToolMessageDiscriminant};
pub use crate::viewport_tools::tools::crop_tool::{CropToolMessage, CropToolMessageDiscriminant};
pub use crate::viewport_tools::tools::artboard_tool::{ArtboardToolMessage, ArtboardToolMessageDiscriminant};
pub use crate::viewport_tools::tools::ellipse_tool::{EllipseToolMessage, EllipseToolMessageDiscriminant};
pub use crate::viewport_tools::tools::eyedropper_tool::{EyedropperToolMessage, EyedropperToolMessageDiscriminant};
pub use crate::viewport_tools::tools::fill_tool::{FillToolMessage, FillToolMessageDiscriminant};

View File

@@ -25,7 +25,7 @@ macro_rules! count_args {
/// ```ignore
/// let tools = gen_tools_hash_map! {
/// Select => select::Select,
/// Crop => crop::Crop,
/// Artboard => artboard::Artboard,
/// };
/// ```
/// expands to
@@ -34,7 +34,7 @@ macro_rules! count_args {
/// let mut hash_map: std::collections::HashMap<crate::tool::ToolType, Box<dyn crate::tool::Tool>> = std::collections::HashMap::with_capacity(count_args!(/* Macro args */));
///
/// hash_map.insert(crate::tool::ToolType::Select, Box::new(select::Select::default()));
/// hash_map.insert(crate::tool::ToolType::Crop, Box::new(crop::Crop::default()));
/// hash_map.insert(crate::tool::ToolType::Artboard, Box::new(artboard::Artboard::default()));
///
/// hash_map
/// };

View File

@@ -79,7 +79,7 @@ impl Default for ToolFsmState {
tools: gen_tools_hash_map! {
// General
Select => select_tool::SelectTool,
Crop => crop_tool::CropTool,
Artboard => artboard_tool::ArtboardTool,
Navigate => navigate_tool::NavigateTool,
Eyedropper => eyedropper_tool::EyedropperTool,
Fill => fill_tool::FillTool,
@@ -127,7 +127,7 @@ impl ToolFsmState {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ToolType {
Select,
Crop,
Artboard,
Navigate,
Eyedropper,
Text,
@@ -155,7 +155,7 @@ impl fmt::Display for ToolType {
let name = match_variant_name!(match (self) {
Select,
Crop,
Artboard,
Navigate,
Eyedropper,
Text,
@@ -192,7 +192,7 @@ pub fn standard_tool_message(tool: ToolType, message_type: StandardToolMessageTy
match message_type {
StandardToolMessageType::DocumentIsDirty => match tool {
ToolType::Select => Some(SelectToolMessage::DocumentIsDirty.into()),
ToolType::Crop => Some(CropToolMessage::DocumentIsDirty.into()),
ToolType::Artboard => Some(ArtboardToolMessage::DocumentIsDirty.into()),
ToolType::Navigate => None, // Some(NavigateToolMessage::DocumentIsDirty.into()),
ToolType::Eyedropper => None, // Some(EyedropperToolMessage::DocumentIsDirty.into()),
ToolType::Text => Some(TextMessage::DocumentIsDirty.into()),
@@ -215,7 +215,7 @@ pub fn standard_tool_message(tool: ToolType, message_type: StandardToolMessageTy
},
StandardToolMessageType::Abort => match tool {
ToolType::Select => Some(SelectToolMessage::Abort.into()),
ToolType::Crop => Some(CropToolMessage::Abort.into()),
ToolType::Artboard => Some(ArtboardToolMessage::Abort.into()),
ToolType::Navigate => Some(NavigateToolMessage::Abort.into()),
ToolType::Eyedropper => Some(EyedropperToolMessage::Abort.into()),
ToolType::Text => Some(TextMessage::Abort.into()),
@@ -249,7 +249,7 @@ pub fn message_to_tool_type(message: &ToolMessage) -> ToolType {
match message {
Select(_) => ToolType::Select,
Crop(_) => ToolType::Crop,
Artboard(_) => ToolType::Artboard,
Navigate(_) => ToolType::Navigate,
Eyedropper(_) => ToolType::Eyedropper,
Text(_) => ToolType::Text,

View File

@@ -15,7 +15,7 @@ pub enum ToolMessage {
Select(SelectToolMessage),
#[remain::unsorted]
#[child]
Crop(CropToolMessage),
Artboard(ArtboardToolMessage),
#[remain::unsorted]
#[child]
Navigate(NavigateToolMessage),

View File

@@ -18,15 +18,15 @@ use glam::{DVec2, Vec2Swizzles};
use serde::{Deserialize, Serialize};
#[derive(Default)]
pub struct CropTool {
fsm_state: CropToolFsmState,
data: CropToolData,
pub struct ArtboardTool {
fsm_state: ArtboardToolFsmState,
data: ArtboardToolData,
}
#[remain::sorted]
#[impl_message(Message, ToolMessage, Crop)]
#[impl_message(Message, ToolMessage, Artboard)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum CropToolMessage {
pub enum ArtboardToolMessage {
// Standard messages
#[remain::unsorted]
Abort,
@@ -43,7 +43,7 @@ pub enum CropToolMessage {
PointerUp,
}
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for CropTool {
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for ArtboardTool {
fn process_action(&mut self, action: ToolMessage, data: ToolActionHandlerData<'a>, responses: &mut VecDeque<Message>) {
if action == ToolMessage::UpdateHints {
self.fsm_state.update_hints(responses);
@@ -63,27 +63,27 @@ impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for CropTool {
}
}
advertise_actions!(CropToolMessageDiscriminant; PointerDown, PointerUp, PointerMove, DeleteSelected, Abort);
advertise_actions!(ArtboardToolMessageDiscriminant; PointerDown, PointerUp, PointerMove, DeleteSelected, Abort);
}
impl PropertyHolder for CropTool {}
impl PropertyHolder for ArtboardTool {}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum CropToolFsmState {
enum ArtboardToolFsmState {
Ready,
Drawing,
ResizingBounds,
Dragging,
}
impl Default for CropToolFsmState {
impl Default for ArtboardToolFsmState {
fn default() -> Self {
CropToolFsmState::Ready
ArtboardToolFsmState::Ready
}
}
#[derive(Clone, Debug, Default)]
struct CropToolData {
struct ArtboardToolData {
bounding_box_overlays: Option<BoundingBoxOverlays>,
selected_board: Option<LayerId>,
snap_handler: SnapHandler,
@@ -92,8 +92,8 @@ struct CropToolData {
drag_current: DVec2,
}
impl Fsm for CropToolFsmState {
type ToolData = CropToolData;
impl Fsm for ArtboardToolFsmState {
type ToolData = ArtboardToolData;
type ToolOptions = ();
fn transition(
@@ -106,9 +106,9 @@ impl Fsm for CropToolFsmState {
input: &InputPreprocessorMessageHandler,
responses: &mut VecDeque<Message>,
) -> Self {
if let ToolMessage::Crop(event) = event {
if let ToolMessage::Artboard(event) = event {
match (self, event) {
(CropToolFsmState::Ready | CropToolFsmState::ResizingBounds | CropToolFsmState::Dragging, CropToolMessage::DocumentIsDirty) => {
(ArtboardToolFsmState::Ready | ArtboardToolFsmState::ResizingBounds | ArtboardToolFsmState::Dragging, ArtboardToolMessage::DocumentIsDirty) => {
let mut buffer = Vec::new();
match (
data.selected_board.map(|path| document.artboard_bounding_box_and_transform(&[path])).unwrap_or(None),
@@ -139,7 +139,7 @@ impl Fsm for CropToolFsmState {
buffer.into_iter().rev().for_each(|message| responses.push_front(message));
self
}
(CropToolFsmState::Ready, CropToolMessage::PointerDown) => {
(ArtboardToolFsmState::Ready, ArtboardToolMessage::PointerDown) => {
data.drag_start = input.mouse.position;
data.drag_current = input.mouse.position;
@@ -164,7 +164,7 @@ impl Fsm for CropToolFsmState {
data.snap_handler
.start_snap(document, document.bounding_boxes(None, Some(data.selected_board.unwrap())), snap_x, snap_y);
CropToolFsmState::ResizingBounds
ArtboardToolFsmState::ResizingBounds
} else {
let tolerance = DVec2::splat(SELECTION_TOLERANCE);
let quad = Quad::from_box([input.mouse.position - tolerance, input.mouse.position + tolerance]);
@@ -184,7 +184,7 @@ impl Fsm for CropToolFsmState {
.into(),
);
CropToolFsmState::Dragging
ArtboardToolFsmState::Dragging
} else {
let id = generate_uuid();
data.selected_board = Some(id);
@@ -202,11 +202,11 @@ impl Fsm for CropToolFsmState {
responses.push_back(PropertiesPanelMessage::ClearSelection.into());
CropToolFsmState::Drawing
ArtboardToolFsmState::Drawing
}
}
}
(CropToolFsmState::ResizingBounds, CropToolMessage::PointerMove { constrain_axis_or_aspect, center }) => {
(ArtboardToolFsmState::ResizingBounds, ArtboardToolMessage::PointerMove { constrain_axis_or_aspect, center }) => {
if let Some(bounds) = &data.bounding_box_overlays {
if let Some(movement) = &bounds.selected_edges {
let from_center = input.keyboard.get(center as usize);
@@ -230,9 +230,9 @@ impl Fsm for CropToolFsmState {
responses.push_back(ToolMessage::DocumentIsDirty.into());
}
}
CropToolFsmState::ResizingBounds
ArtboardToolFsmState::ResizingBounds
}
(CropToolFsmState::Dragging, CropToolMessage::PointerMove { constrain_axis_or_aspect, .. }) => {
(ArtboardToolFsmState::Dragging, ArtboardToolMessage::PointerMove { constrain_axis_or_aspect, .. }) => {
if let Some(bounds) = &data.bounding_box_overlays {
let axis_align = input.keyboard.get(constrain_axis_or_aspect as usize);
@@ -259,9 +259,9 @@ impl Fsm for CropToolFsmState {
data.drag_current = mouse_position + closest_move;
}
CropToolFsmState::Dragging
ArtboardToolFsmState::Dragging
}
(CropToolFsmState::Drawing, CropToolMessage::PointerMove { constrain_axis_or_aspect, center }) => {
(ArtboardToolFsmState::Drawing, ArtboardToolMessage::PointerMove { constrain_axis_or_aspect, center }) => {
let mouse_position = input.mouse.position;
let snapped_mouse_position = data.snap_handler.snap_position(responses, input.viewport_bounds.size(), document, mouse_position);
@@ -303,9 +303,9 @@ impl Fsm for CropToolFsmState {
responses.push_back(ToolMessage::DocumentIsDirty.into());
CropToolFsmState::Drawing
ArtboardToolFsmState::Drawing
}
(CropToolFsmState::Ready, CropToolMessage::PointerMove { .. }) => {
(ArtboardToolFsmState::Ready, ArtboardToolMessage::PointerMove { .. }) => {
let cursor = data.bounding_box_overlays.as_ref().map_or(MouseCursorIcon::Default, |bounds| bounds.get_cursor(input, false));
if data.cursor != cursor {
@@ -313,18 +313,18 @@ impl Fsm for CropToolFsmState {
responses.push_back(FrontendMessage::UpdateMouseCursor { cursor }.into());
}
CropToolFsmState::Ready
ArtboardToolFsmState::Ready
}
(CropToolFsmState::ResizingBounds, CropToolMessage::PointerUp) => {
(ArtboardToolFsmState::ResizingBounds, ArtboardToolMessage::PointerUp) => {
data.snap_handler.cleanup(responses);
if let Some(bounds) = &mut data.bounding_box_overlays {
bounds.original_transforms.clear();
}
CropToolFsmState::Ready
ArtboardToolFsmState::Ready
}
(CropToolFsmState::Drawing, CropToolMessage::PointerUp) => {
(ArtboardToolFsmState::Drawing, ArtboardToolMessage::PointerUp) => {
data.snap_handler.cleanup(responses);
if let Some(bounds) = &mut data.bounding_box_overlays {
@@ -333,25 +333,25 @@ impl Fsm for CropToolFsmState {
responses.push_back(ToolMessage::DocumentIsDirty.into());
CropToolFsmState::Ready
ArtboardToolFsmState::Ready
}
(CropToolFsmState::Dragging, CropToolMessage::PointerUp) => {
(ArtboardToolFsmState::Dragging, ArtboardToolMessage::PointerUp) => {
data.snap_handler.cleanup(responses);
if let Some(bounds) = &mut data.bounding_box_overlays {
bounds.original_transforms.clear();
}
CropToolFsmState::Ready
ArtboardToolFsmState::Ready
}
(_, CropToolMessage::DeleteSelected) => {
(_, ArtboardToolMessage::DeleteSelected) => {
if let Some(artboard) = data.selected_board.take() {
responses.push_back(ArtboardMessage::DeleteArtboard { artboard }.into());
responses.push_back(ToolMessage::DocumentIsDirty.into());
}
CropToolFsmState::Ready
ArtboardToolFsmState::Ready
}
(_, CropToolMessage::Abort) => {
(_, ArtboardToolMessage::Abort) => {
if let Some(bounding_box_overlays) = data.bounding_box_overlays.take() {
bounding_box_overlays.delete(responses);
}
@@ -366,7 +366,7 @@ impl Fsm for CropToolFsmState {
);
data.snap_handler.cleanup(responses);
CropToolFsmState::Ready
ArtboardToolFsmState::Ready
}
_ => self,
}
@@ -377,7 +377,7 @@ impl Fsm for CropToolFsmState {
fn update_hints(&self, responses: &mut VecDeque<Message>) {
let hint_data = match self {
CropToolFsmState::Ready => HintData(vec![
ArtboardToolFsmState::Ready => HintData(vec![
HintGroup(vec![HintInfo {
key_groups: vec![],
mouse: Some(MouseMotion::LmbDrag),
@@ -397,13 +397,13 @@ impl Fsm for CropToolFsmState {
plus: false,
}]),
]),
CropToolFsmState::Dragging => HintData(vec![HintGroup(vec![HintInfo {
ArtboardToolFsmState::Dragging => HintData(vec![HintGroup(vec![HintInfo {
key_groups: vec![KeysGroup(vec![Key::KeyShift])],
mouse: None,
label: String::from("Constrain to Axis"),
plus: false,
}])]),
CropToolFsmState::Drawing | CropToolFsmState::ResizingBounds => HintData(vec![HintGroup(vec![
ArtboardToolFsmState::Drawing | ArtboardToolFsmState::ResizingBounds => HintData(vec![HintGroup(vec![
HintInfo {
key_groups: vec![KeysGroup(vec![Key::KeyShift])],
mouse: None,

View File

@@ -1,4 +1,4 @@
pub mod crop_tool;
pub mod artboard_tool;
pub mod ellipse_tool;
pub mod eyedropper_tool;
pub mod fill_tool;