-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Wrap cursor around viewport during G/R/S (#3255) #4486
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
base: master
Are you sure you want to change the base?
Changes from all commits
784a670
7f8c35f
dacb9ba
aa846b8
d2bf22f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,14 @@ impl MessageHandler<AppWindowMessage, ()> for AppWindowMessageHandler { | |
| #[cfg(not(target_family = "wasm"))] | ||
| responses.add(FrontendMessage::WindowPointerLock); | ||
| } | ||
| AppWindowMessage::PointerUnlock => { | ||
| #[cfg(not(target_family = "wasm"))] | ||
| responses.add(FrontendMessage::WindowPointerUnlock); | ||
| } | ||
| AppWindowMessage::PointerLockMove { x, y } => { | ||
| responses.add(FrontendMessage::WindowPointerLockMove { position: (x, y) }); | ||
| // Keep G/R/S dragging moving while the pointer is locked | ||
| responses.add(InputPreprocessorMessage::RelativePointerMove { delta: glam::DVec2::new(x, y) }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: On web, each locked Prompt for AI agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| } | ||
| AppWindowMessage::Close => { | ||
| #[cfg(not(target_family = "wasm"))] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use crate::consts::{ANGLE_MEASURE_RADIUS_FACTOR, ARC_MEASURE_RADIUS_FACTOR_RANGE, COLOR_OVERLAY_BLUE, COLOR_OVERLAY_GRAY, SLOWING_DIVISOR}; | ||
| use crate::messages::frontend::utility_types::MouseCursorIcon; | ||
| use crate::messages::input_mapper::utility_types::pointer::{DocumentPosition, ViewportPosition}; | ||
| use crate::messages::portfolio::document::overlays::utility_functions::text_width; | ||
| use crate::messages::portfolio::document::overlays::utility_types::{OverlayProvider, Pivot}; | ||
|
|
@@ -12,6 +13,7 @@ use crate::messages::tool::common_functionality::shapes::shape_utility::format_r | |
| use crate::messages::tool::tool_messages::select_tool; | ||
| use crate::messages::tool::tool_messages::tool_prelude::Key; | ||
| use crate::messages::tool::utility_types::{ToolData, ToolType}; | ||
| use crate::messages::viewport::Position; | ||
| use glam::{DAffine2, DVec2}; | ||
| use graphene_std::renderer::Quad; | ||
| use graphene_std::vector::click_target::ClickTargetType; | ||
|
|
@@ -95,6 +97,10 @@ pub struct TransformLayerMessageHandler { | |
|
|
||
| // Path tool (ghost outlines showing pre-transform geometry) | ||
| ghost_outline: Vec<(Vec<ClickTargetType>, DAffine2)>, | ||
|
|
||
| // Software cursor for wrap-around (visible fake cursor on Wayland/Web, OS warp on X11) | ||
| software_cursor_active: bool, | ||
| software_cursor_pos: ViewportPosition, | ||
| } | ||
|
|
||
| #[message_handler_data] | ||
|
|
@@ -339,6 +345,7 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| responses.add(OverlaysMessage::RemoveProvider { | ||
| provider: TRANSFORM_GRS_OVERLAY_PROVIDER, | ||
| }); | ||
| self.disable_software_cursor(responses); | ||
| } | ||
| } | ||
| TransformLayerMessage::BeginTransformOperation { operation } => { | ||
|
|
@@ -384,6 +391,7 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| responses.add(OverlaysMessage::AddProvider { | ||
| provider: TRANSFORM_GRS_OVERLAY_PROVIDER, | ||
| }); | ||
| self.enable_software_cursor(responses, input.mouse.position); | ||
| // Find a way better than this hack | ||
| responses.add(TransformLayerMessage::PointerMove { | ||
| slow_key: SLOW_KEY, | ||
|
|
@@ -471,6 +479,7 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| responses.add(OverlaysMessage::AddProvider { | ||
| provider: TRANSFORM_GRS_OVERLAY_PROVIDER, | ||
| }); | ||
| self.enable_software_cursor(responses, input.mouse.position); | ||
| } | ||
| responses.add(TransformLayerMessage::BeginTransformOperation { operation: transform_type }); | ||
| responses.add(TransformLayerMessage::PointerMove { | ||
|
|
@@ -510,6 +519,7 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| responses.add(OverlaysMessage::RemoveProvider { | ||
| provider: TRANSFORM_GRS_OVERLAY_PROVIDER, | ||
| }); | ||
| self.disable_software_cursor(responses); | ||
| } | ||
| TransformLayerMessage::ConstrainX => { | ||
| self.state.is_transforming_in_local_space = self.transform_operation.constrain_axis(Axis::X, &mut selected, &self.state, document); | ||
|
|
@@ -581,6 +591,26 @@ impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for | |
| }; | ||
| } | ||
|
|
||
| if self.software_cursor_active { | ||
| let delta = input.mouse.position - self.mouse_position; | ||
| self.software_cursor_pos += delta; | ||
|
|
||
| // Wrap around the viewport edges | ||
| let size = viewport.size(); | ||
| if size.x() > 0. && size.y() > 0. { | ||
| self.software_cursor_pos = DVec2::new( | ||
| ((self.software_cursor_pos.x % size.x()) + size.x()) % size.x(), | ||
| ((self.software_cursor_pos.y % size.y()) + size.y()) % size.y(), | ||
| ); | ||
| } | ||
|
|
||
| responses.add(FrontendMessage::UpdateSoftwareCursor { | ||
| visible: true, | ||
| x: self.software_cursor_pos.x, | ||
| y: self.software_cursor_pos.y, | ||
| }); | ||
| } | ||
|
|
||
| self.mouse_position = input.mouse.position; | ||
| } | ||
| TransformLayerMessage::SelectionChanged => { | ||
|
|
@@ -651,6 +681,27 @@ impl TransformLayerMessageHandler { | |
| self.transform_operation.hints(responses, self.state.is_transforming_in_local_space); | ||
| } | ||
|
|
||
| fn enable_software_cursor(&mut self, responses: &mut VecDeque<Message>, pos: ViewportPosition) { | ||
| if self.software_cursor_active { | ||
| return; | ||
| } | ||
| self.software_cursor_active = true; | ||
| self.software_cursor_pos = pos; | ||
| responses.add(FrontendMessage::UpdateSoftwareCursor { visible: true, x: pos.x, y: pos.y }); | ||
| responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::None }); | ||
| responses.add(AppWindowMessage::PointerLock); | ||
| } | ||
|
|
||
| fn disable_software_cursor(&mut self, responses: &mut VecDeque<Message>) { | ||
| if !self.software_cursor_active { | ||
| return; | ||
| } | ||
| self.software_cursor_active = false; | ||
| responses.add(FrontendMessage::UpdateSoftwareCursor { visible: false, x: 0., y: 0. }); | ||
| responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Default }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: When a G/R/S transform ends in a tool with a non-default cursor, this line overwrites that tool cursor with Prompt for AI agents |
||
| responses.add(AppWindowMessage::PointerUnlock); | ||
| } | ||
|
|
||
| fn set_ghost_outline(ghost_outline: &mut Vec<(Vec<ClickTargetType>, DAffine2)>, shape_editor: &ShapeState, document: &DocumentMessageHandler) { | ||
| ghost_outline.clear(); | ||
| for &layer in shape_editor.selected_shape_state.keys() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.