Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the open hand cursor when space bar is held #2173

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
17 changes: 13 additions & 4 deletions editor/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct DispatcherMessageHandlers {
pub portfolio_message_handler: PortfolioMessageHandler,
preferences_message_handler: PreferencesMessageHandler,
tool_message_handler: ToolMessageHandler,
pub transform_layer_handler: TransformLayerMessageHandler,
workspace_message_handler: WorkspaceMessageHandler,
}

Expand Down Expand Up @@ -208,10 +209,18 @@ impl Dispatcher {
let ipp = &self.message_handlers.input_preprocessor_message_handler;
let preferences = &self.message_handlers.preferences_message_handler;
let current_tool = &self.message_handlers.tool_message_handler.tool_state.tool_data.active_tool_type;

self.message_handlers
.portfolio_message_handler
.process_message(message, &mut queue, PortfolioMessageData { ipp, preferences, current_tool });
let transform_layer_handler = &self.message_handlers.transform_layer_handler;

self.message_handlers.portfolio_message_handler.process_message(
message,
&mut queue,
PortfolioMessageData {
ipp,
preferences,
current_tool,
transform_layer_handler: transform_layer_handler,
},
);
}
Message::Preferences(message) => {
self.message_handlers.preferences_message_handler.process_message(message, &mut queue, ());
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/frontend/utility_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum MouseCursorIcon {
ZoomIn,
ZoomOut,
Grabbing,
Grab,
Crosshair,
Text,
Move,
Expand Down
4 changes: 4 additions & 0 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ pub fn input_mappings() -> Mapping {
entry!(KeyDown(MouseRight); action_dispatch=TextToolMessage::CommitText),
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::CommitText),
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::CommitText),
// entry!(KeyDownNoRepeat(Space); action_dispatch=NavigationMessage::SetCursorState { is_active: true }),
// entry!(KeyUp(Space); action_dispatch=NavigationMessage::SetCursorState { is_active: false }),
//
// GradientToolMessage
entry!(KeyDown(MouseLeft); action_dispatch=GradientToolMessage::PointerDown),
Expand Down Expand Up @@ -384,6 +386,8 @@ pub fn input_mappings() -> Mapping {
//
// NavigationMessage
entry!(KeyDown(MouseMiddle); modifiers=[Alt], action_dispatch=NavigationMessage::BeginCanvasTilt { was_dispatched_from_menu: false }),
entry!(KeyDownNoRepeat(Space); action_dispatch=NavigationMessage::SetCursorState { is_active: true }),
entry!(KeyUp(Space); action_dispatch=NavigationMessage::SetCursorState { is_active: false }),
entry!(KeyDown(MouseMiddle); modifiers=[Shift], action_dispatch=NavigationMessage::BeginCanvasZoom),
entry!(KeyDown(MouseLeft); modifiers=[Shift, Space], action_dispatch=NavigationMessage::BeginCanvasZoom),
entry!(KeyDown(MouseMiddle); action_dispatch=NavigationMessage::BeginCanvasPan),
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/portfolio/document/document_message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::utility_types::misc::SnappingState;
use crate::messages::frontend::utility_types::MouseCursorIcon;
use crate::messages::input_mapper::utility_types::input_keyboard::Key;
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct DocumentMessageData<'a> {
pub persistent_data: &'a PersistentData,
pub executor: &'a mut NodeGraphExecutor,
pub current_tool: &'a ToolType,
pub transform_layer_handler: &'a TransformLayerMessageHandler,
}

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
Expand Down Expand Up @@ -166,6 +167,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
persistent_data,
executor,
current_tool,
transform_layer_handler,
} = data;

let selected_nodes_bounding_box_viewport = self.network_interface.selected_nodes_bounding_box_viewport(&self.breadcrumb_network_path);
Expand All @@ -174,6 +176,8 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
// Sub-messages
DocumentMessage::Navigation(message) => {
let data = NavigationMessageData {
transform_layer_handler: transform_layer_handler,
tool_type: *current_tool,
network_interface: &mut self.network_interface,
breadcrumb_network_path: &self.breadcrumb_network_path,
ipp,
Expand Down Expand Up @@ -1371,6 +1375,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
// More additional actions
common.extend(self.navigation_handler.actions());
common.extend(self.node_graph_handler.actions());
// common.extend(actions!(NavigationMessageDiscriminant::SetCursorState));
common
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum NavigationMessage {
BeginCanvasPan,
BeginCanvasTilt { was_dispatched_from_menu: bool },
BeginCanvasZoom,
SetCursorState { is_active: bool },
CanvasPan { delta: DVec2 },
CanvasPanByViewportFraction { delta: DVec2 },
CanvasPanMouseWheel { use_y_as_x: bool },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use crate::consts::{
};
use crate::messages::frontend::utility_types::MouseCursorIcon;
use crate::messages::input_mapper::utility_types::input_keyboard::{Key, KeysGroup, MouseMotion};
use crate::messages::input_mapper::utility_types::input_mouse::ViewportPosition;
use crate::messages::input_mapper::utility_types::input_mouse::{MouseKeys, ViewportPosition};
use crate::messages::portfolio::document::navigation::utility_types::NavigationOperation;
use crate::messages::portfolio::document::utility_types::misc::PTZ;
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};

use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo, ToolType};

use graph_craft::document::NodeId;

Expand All @@ -22,6 +23,8 @@ pub struct NavigationMessageData<'a> {
pub selection_bounds: Option<[DVec2; 2]>,
pub document_ptz: &'a mut PTZ,
pub graph_view_overlay_open: bool,
pub tool_type: ToolType,
pub transform_layer_handler: &'a TransformLayerMessageHandler,
}

#[derive(Debug, Clone, PartialEq, Default)]
Expand All @@ -40,6 +43,8 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation
selection_bounds,
document_ptz,
graph_view_overlay_open,
tool_type,
transform_layer_handler,
} = data;

fn get_ptz<'a>(document_ptz: &'a PTZ, network_interface: &'a NodeNetworkInterface, graph_view_overlay_open: bool, breadcrumb_network_path: &[NodeId]) -> Option<&'a PTZ> {
Expand Down Expand Up @@ -83,6 +88,19 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation
};
self.navigation_operation = NavigationOperation::Pan { pan_original_for_abort: ptz.pan };
}
NavigationMessage::SetCursorState { is_active } => {
let should_update_cursor = is_active && !ipp.mouse.mouse_keys.contains(MouseKeys::LEFT) && transform_layer_handler.is_transforming();
if should_update_cursor {
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Grab });
} else {
if tool_type != ToolType::Select {
log::info!("ToolType is not Select, so we are not updating the cursor");
responses.add(ToolMessage::UpdateCursor);
} else {
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Default });
}
}
}
NavigationMessage::BeginCanvasTilt { was_dispatched_from_menu } => {
let Some(ptz) = get_ptz(document_ptz, network_interface, graph_view_overlay_open, breadcrumb_network_path) else {
return;
Expand Down Expand Up @@ -303,7 +321,12 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation

// Send the final messages to close out the operation
responses.add(BroadcastEvent::CanvasTransformed);
responses.add(ToolMessage::UpdateCursor);
if ipp.keyboard.key(Key::Space) {
debug!("space is pressed");
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Grab });
} else {
responses.add(ToolMessage::UpdateCursor);
}
responses.add(ToolMessage::UpdateHints);
responses.add(NavigateToolMessage::End);
}
Expand Down Expand Up @@ -466,6 +489,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation
CanvasZoomIncrease,
CanvasZoomMouseWheel,
FitViewportToSelection,
SetCursorState
);

if self.navigation_operation != NavigationOperation::None {
Expand Down
12 changes: 10 additions & 2 deletions editor/src/messages/portfolio/portfolio_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::messages::portfolio::document::node_graph::document_node_definitions:
use crate::messages::portfolio::document::utility_types::clipboards::{Clipboard, CopyBufferEntry, INTERNAL_CLIPBOARD_COUNT};
use crate::messages::portfolio::document::DocumentMessageData;
use crate::messages::prelude::*;
use crate::messages::tool::utility_types::{HintData, HintGroup, ToolType};
use crate::messages::tool::utility_types::{HintData, HintGroup, ToolData, ToolType};
use crate::node_graph_executor::{ExportConfig, NodeGraphExecutor};

use graph_craft::document::value::TaggedValue;
Expand All @@ -26,6 +26,7 @@ pub struct PortfolioMessageData<'a> {
pub ipp: &'a InputPreprocessorMessageHandler,
pub preferences: &'a PreferencesMessageHandler,
pub current_tool: &'a ToolType,
pub transform_layer_handler: &'a TransformLayerMessageHandler,
}

#[derive(Debug, Default)]
Expand All @@ -42,7 +43,12 @@ pub struct PortfolioMessageHandler {

impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMessageHandler {
fn process_message(&mut self, message: PortfolioMessage, responses: &mut VecDeque<Message>, data: PortfolioMessageData) {
let PortfolioMessageData { ipp, preferences, current_tool } = data;
let PortfolioMessageData {
ipp,
preferences,
current_tool,
transform_layer_handler,
} = data;

match message {
// Sub-messages
Expand Down Expand Up @@ -79,6 +85,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
let document_inputs = DocumentMessageData {
document_id,
ipp,
transform_layer_handler: &transform_layer_handler,
persistent_data: &self.persistent_data,
executor: &mut self.executor,
current_tool,
Expand All @@ -97,6 +104,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
persistent_data: &self.persistent_data,
executor: &mut self.executor,
current_tool,
transform_layer_handler: &transform_layer_handler,
};
document.process_message(message, responses, document_inputs)
}
Expand Down
15 changes: 14 additions & 1 deletion editor/src/messages/tool/tool_messages/text_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,20 @@ impl Fsm for TextToolFsmState {

responses.add(FrontendMessage::UpdateInputHints { hint_data });
}

fn standard_tool_messages(&self, message: &ToolMessage, responses: &mut VecDeque<Message>, _tool_data: &mut Self::ToolData) -> bool {
// Check for standard hits or cursor events
match message {
ToolMessage::UpdateHints => {
self.update_hints(responses);
true
}
ToolMessage::UpdateCursor => {
self.update_cursor(responses);
true
}
_ => false,
}
}
fn update_cursor(&self, responses: &mut VecDeque<Message>) {
let cursor = match self {
TextToolFsmState::Dragging => MouseCursorIcon::Crosshair,
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/panels/Document.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@

cursorString = `url('data:image/svg+xml;utf8,${svg}') 8 8, alias`;
}

canvasCursor = cursorString;
}

Expand Down Expand Up @@ -396,9 +395,9 @@

// Update mouse cursor icon
editor.subscriptions.subscribeJsMessage(UpdateMouseCursor, async (data) => {
await tick();

const { cursor } = data;
console.log("Received UpdateMouseCursor message:", data);
await tick();
updateMouseCursor(cursor);
});

Expand Down
13 changes: 11 additions & 2 deletions frontend/src/io-managers/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli

async function onKeyDown(e: KeyboardEvent) {
const key = await getLocalizedScanCode(e);

console.log("Key pressed:", key);
if(key=="Space"){
e.preventDefault();
// e.stopPropagation();
console.log("Space key detected and preventDefault applied.");
}
const NO_KEY_REPEAT_MODIFIER_KEYS = ["ControlLeft", "ControlRight", "ShiftLeft", "ShiftRight", "MetaLeft", "MetaRight", "AltLeft", "AltRight", "AltGraph", "CapsLock", "Fn", "FnLock"];
if (e.repeat && NO_KEY_REPEAT_MODIFIER_KEYS.includes(key)) return;

Expand All @@ -120,7 +125,11 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli

async function onKeyUp(e: KeyboardEvent) {
const key = await getLocalizedScanCode(e);

// if(key=="Space"){
// e.preventDefault();
// e.stopPropagation();
// console.log("Space key detected and preventDefault applied.");
// }
if (await shouldRedirectKeyboardEventToBackend(e)) {
e.preventDefault();
const modifiers = makeKeyboardModifiersBitfield(e);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/wasm-communication/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ const mouseCursorIconCSSNames = {
ZoomIn: "zoom-in",
ZoomOut: "zoom-out",
Grabbing: "grabbing",
Grab: "grab",
Crosshair: "crosshair",
Text: "text",
Move: "move",
Expand Down