Skip to content

Commit 759a32e

Browse files
committed
Handle warped mouse motion as floating point
Fixes certain issues where sub-pixel motions would get discarded while the mouse is captured, such as when free look is enabled in the editor (at least when turned on while holding right click). Very slightly compat breaking, as actual public APIs are changed, although with "compatible" types (Point2i->Point2).
1 parent 907db8e commit 759a32e

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

core/input/input.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ void Input::warp_mouse(const Vector2 &p_position) {
855855
warp_mouse_func(p_position);
856856
}
857857

858-
Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
858+
Point2 Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
859859
// The relative distance reported for the next event after a warp is in the boundaries of the
860860
// size of the rect on that axis, but it may be greater, in which case there's no problem as fmod()
861861
// will warp it, but if the pointer has moved in the opposite direction between the pointer relocation
@@ -865,14 +865,14 @@ Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, con
865865
// detect the warp: if the relative distance is greater than the half of the size of the relevant rect
866866
// (checked per each axis), it will be considered as the consequence of a former pointer warp.
867867

868-
const Point2i rel_sign(p_motion->get_relative().x >= 0.0f ? 1 : -1, p_motion->get_relative().y >= 0.0 ? 1 : -1);
869-
const Size2i warp_margin = p_rect.size * 0.5f;
870-
const Point2i rel_warped(
868+
const Point2 rel_sign(p_motion->get_relative().x >= 0.0f ? 1 : -1, p_motion->get_relative().y >= 0.0 ? 1 : -1);
869+
const Size2 warp_margin = p_rect.size * 0.5f;
870+
const Point2 rel_warped(
871871
Math::fmod(p_motion->get_relative().x + rel_sign.x * warp_margin.x, p_rect.size.x) - rel_sign.x * warp_margin.x,
872872
Math::fmod(p_motion->get_relative().y + rel_sign.y * warp_margin.y, p_rect.size.y) - rel_sign.y * warp_margin.y);
873873

874-
const Point2i pos_local = p_motion->get_global_position() - p_rect.position;
875-
const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y));
874+
const Point2 pos_local = p_motion->get_global_position() - p_rect.position;
875+
const Point2 pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y));
876876
if (pos_warped != pos_local) {
877877
warp_mouse(pos_warped + p_rect.position);
878878
}

core/input/input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class Input : public Object {
308308
BitField<MouseButtonMask> get_mouse_button_mask() const;
309309

310310
void warp_mouse(const Vector2 &p_position);
311-
Point2i warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect);
311+
Point2 warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect);
312312

313313
void parse_input_event(const Ref<InputEvent> &p_event);
314314

editor/plugins/node_3d_editor_plugin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,8 +2572,8 @@ void Node3DEditorViewport::scale_freelook_speed(real_t scale) {
25722572
surface->queue_redraw();
25732573
}
25742574

2575-
Point2i Node3DEditorViewport::_get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const {
2576-
Point2i relative;
2575+
Point2 Node3DEditorViewport::_get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const {
2576+
Point2 relative;
25772577
if (bool(EDITOR_GET("editors/3d/navigation/warped_mouse_panning"))) {
25782578
relative = Input::get_singleton()->warp_mouse_motion(p_ev_mouse_motion, surface->get_global_rect());
25792579
} else {

editor/plugins/node_3d_editor_plugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ class Node3DEditorViewport : public Control {
431431
void _selection_result_pressed(int);
432432
void _selection_menu_hide();
433433
void _list_select(Ref<InputEventMouseButton> b);
434-
Point2i _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const;
434+
Point2 _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const;
435435

436436
Vector3 _get_instance_position(const Point2 &p_pos) const;
437437
static AABB _calculate_spatial_bounds(const Node3D *p_parent, const Node3D *p_top_level_parent = nullptr);

0 commit comments

Comments
 (0)