Skip to content

Commit

Permalink
Switch Eyedropper/Fill tools from Rmb to Shift+Lmb
Browse files Browse the repository at this point in the history
  • Loading branch information
Keavon committed Mar 9, 2024
1 parent d780602 commit 9f84661
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
13 changes: 7 additions & 6 deletions editor/src/messages/input_mapper/default_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ pub fn default_mapping() -> Mapping {
entry!(KeyUp(Mmb); action_dispatch=NavigateToolMessage::TransformCanvasEnd),
//
// EyedropperToolMessage
entry!(KeyDown(Lmb); action_dispatch=EyedropperToolMessage::SamplePrimaryColorBegin),
entry!(KeyDown(Lmb); modifiers=[Shift], action_dispatch=EyedropperToolMessage::SampleSecondaryColorBegin),
entry!(KeyUp(Lmb); action_dispatch=EyedropperToolMessage::SamplePrimaryColorEnd),
entry!(KeyUp(Lmb); modifiers=[Shift], action_dispatch=EyedropperToolMessage::SampleSecondaryColorEnd),
entry!(PointerMove; action_dispatch=EyedropperToolMessage::PointerMove),
entry!(KeyDown(Lmb); action_dispatch=EyedropperToolMessage::LeftPointerDown),
entry!(KeyDown(Rmb); action_dispatch=EyedropperToolMessage::RightPointerDown),
entry!(KeyUp(Lmb); action_dispatch=EyedropperToolMessage::LeftPointerUp),
entry!(KeyUp(Rmb); action_dispatch=EyedropperToolMessage::RightPointerUp),
entry!(KeyDown(Rmb); action_dispatch=EyedropperToolMessage::Abort),
entry!(KeyDown(Escape); action_dispatch=EyedropperToolMessage::Abort),
//
// TextToolMessage
Expand Down Expand Up @@ -244,8 +245,8 @@ pub fn default_mapping() -> Mapping {
entry!(KeyDown(Enter); action_dispatch=SplineToolMessage::Confirm),
//
// FillToolMessage
entry!(KeyDown(Lmb); action_dispatch=FillToolMessage::LeftPointerDown),
entry!(KeyDown(Rmb); action_dispatch=FillToolMessage::RightPointerDown),
entry!(KeyDown(Lmb); action_dispatch=FillToolMessage::FillPrimaryColor),
entry!(KeyDown(Lmb); modifiers=[Shift], action_dispatch=FillToolMessage::FillSecondaryColor),
//
// BrushToolMessage
entry!(PointerMove; action_dispatch=BrushToolMessage::PointerMove),
Expand Down
28 changes: 15 additions & 13 deletions editor/src/messages/tool/tool_messages/eyedropper_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub enum EyedropperToolMessage {
Abort,

// Tool-specific messages
LeftPointerDown,
LeftPointerUp,
SamplePrimaryColorBegin,
SamplePrimaryColorEnd,
PointerMove,
RightPointerDown,
RightPointerUp,
SampleSecondaryColorBegin,
SampleSecondaryColorEnd,
}

impl ToolMetadata for EyedropperTool {
Expand All @@ -45,11 +45,11 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Eyedrop
}

advertise_actions!(EyedropperToolMessageDiscriminant;
LeftPointerDown,
LeftPointerUp,
SamplePrimaryColorBegin,
SamplePrimaryColorEnd,
SampleSecondaryColorBegin,
SampleSecondaryColorEnd,
PointerMove,
RightPointerDown,
RightPointerUp,
Abort,
);
}
Expand Down Expand Up @@ -87,10 +87,10 @@ impl Fsm for EyedropperToolFsmState {
};
match (self, event) {
// Ready -> Sampling
(EyedropperToolFsmState::Ready, mouse_down) if matches!(mouse_down, EyedropperToolMessage::LeftPointerDown | EyedropperToolMessage::RightPointerDown) => {
(EyedropperToolFsmState::Ready, mouse_down) if matches!(mouse_down, EyedropperToolMessage::SamplePrimaryColorBegin | EyedropperToolMessage::SampleSecondaryColorBegin) => {
update_cursor_preview(responses, input, global_tool_data, None);

if mouse_down == EyedropperToolMessage::LeftPointerDown {
if mouse_down == EyedropperToolMessage::SamplePrimaryColorBegin {
EyedropperToolFsmState::SamplingPrimary
} else {
EyedropperToolFsmState::SamplingSecondary
Expand All @@ -107,7 +107,7 @@ impl Fsm for EyedropperToolFsmState {
self
}
// Sampling -> Ready
(EyedropperToolFsmState::SamplingPrimary, EyedropperToolMessage::LeftPointerUp) | (EyedropperToolFsmState::SamplingSecondary, EyedropperToolMessage::RightPointerUp) => {
(EyedropperToolFsmState::SamplingPrimary, EyedropperToolMessage::SamplePrimaryColorEnd) | (EyedropperToolFsmState::SamplingSecondary, EyedropperToolMessage::SampleSecondaryColorEnd) => {
let set_color_choice = if self == EyedropperToolFsmState::SamplingPrimary { "Primary" } else { "Secondary" }.to_string();
update_cursor_preview(responses, input, global_tool_data, Some(set_color_choice));
disable_cursor_preview(responses);
Expand All @@ -129,9 +129,11 @@ impl Fsm for EyedropperToolFsmState {
let hint_data = match self {
EyedropperToolFsmState::Ready => HintData(vec![HintGroup(vec![
HintInfo::mouse(MouseMotion::Lmb, "Sample to Primary"),
HintInfo::mouse(MouseMotion::Rmb, "Sample to Secondary"),
HintInfo::keys_and_mouse([Key::Shift], MouseMotion::Lmb, "Sample to Secondary"),
])]),
EyedropperToolFsmState::SamplingPrimary | EyedropperToolFsmState::SamplingSecondary => HintData(vec![HintGroup(vec![HintInfo::keys([Key::Escape], "Cancel")])]),
EyedropperToolFsmState::SamplingPrimary | EyedropperToolFsmState::SamplingSecondary => {
HintData(vec![HintGroup(vec![HintInfo::mouse(MouseMotion::Rmb, ""), HintInfo::keys([Key::Escape], "Cancel").prepend_slash()])])
}
};

responses.add(FrontendMessage::UpdateInputHints { hint_data });
Expand Down
14 changes: 7 additions & 7 deletions editor/src/messages/tool/tool_messages/fill_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub struct FillTool {
#[derive(PartialEq, Eq, Clone, Debug, Hash, Serialize, Deserialize, specta::Type)]
pub enum FillToolMessage {
// Tool-specific messages
LeftPointerDown,
RightPointerDown,
FillPrimaryColor,
FillSecondaryColor,
}

impl ToolMetadata for FillTool {
Expand All @@ -39,8 +39,8 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for FillToo
}

advertise_actions!(FillToolMessageDiscriminant;
LeftPointerDown,
RightPointerDown,
FillPrimaryColor,
FillSecondaryColor,
);
}

Expand Down Expand Up @@ -72,8 +72,8 @@ impl Fsm for FillToolFsmState {
return self;
};
let color = match event {
FillToolMessage::LeftPointerDown => global_tool_data.primary_color,
FillToolMessage::RightPointerDown => global_tool_data.secondary_color,
FillToolMessage::FillPrimaryColor => global_tool_data.primary_color,
FillToolMessage::FillSecondaryColor => global_tool_data.secondary_color,
};
let fill = Fill::Solid(color);

Expand All @@ -88,7 +88,7 @@ impl Fsm for FillToolFsmState {
let hint_data = match self {
FillToolFsmState::Ready => HintData(vec![HintGroup(vec![
HintInfo::mouse(MouseMotion::Lmb, "Fill with Primary"),
HintInfo::mouse(MouseMotion::Rmb, "Fill with Secondary"),
HintInfo::keys_and_mouse([Key::Shift], MouseMotion::Lmb, "Fill with Secondary"),
])]),
};

Expand Down

0 comments on commit 9f84661

Please sign in to comment.