diff --git a/core/input/input.cpp b/core/input/input.cpp index 656bb92203b..e64b5a3ab70 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -72,7 +72,7 @@ Input *Input::singleton = nullptr; void (*Input::set_mouse_mode_func)(Input::MouseMode) = nullptr; Input::MouseMode (*Input::get_mouse_mode_func)() = nullptr; -void (*Input::warp_mouse_func)(const Vector2 &p_to_pos) = nullptr; +void (*Input::warp_mouse_func)(const Vector2 &p_position) = nullptr; Input::CursorShape (*Input::get_current_cursor_shape_func)() = nullptr; void (*Input::set_custom_mouse_cursor_func)(const RES &, Input::CursorShape, const Vector2 &) = nullptr; @@ -126,7 +126,7 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask); ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode); ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode); - ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &Input::warp_mouse_position); + ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &Input::warp_mouse); ClassDB::bind_method(D_METHOD("action_press", "action", "strength"), &Input::action_press, DEFVAL(1.f)); ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release); ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW)); @@ -733,8 +733,8 @@ MouseButton Input::get_mouse_button_mask() const { return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); } -void Input::warp_mouse_position(const Vector2 &p_to) { - warp_mouse_func(p_to); +void Input::warp_mouse(const Vector2 &p_position) { + warp_mouse_func(p_position); } Point2i Input::warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect) { @@ -756,7 +756,7 @@ Point2i Input::warp_mouse_motion(const Ref &p_motion, con const Point2i pos_local = p_motion->get_global_position() - p_rect.position; const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y)); if (pos_warped != pos_local) { - warp_mouse_position(pos_warped + p_rect.position); + warp_mouse(pos_warped + p_rect.position); } return rel_warped; diff --git a/core/input/input.h b/core/input/input.h index ab2cd377f40..ac688b53b80 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -216,7 +216,7 @@ private: static void (*set_mouse_mode_func)(MouseMode); static MouseMode (*get_mouse_mode_func)(); - static void (*warp_mouse_func)(const Vector2 &p_to_pos); + static void (*warp_mouse_func)(const Vector2 &p_position); static CursorShape (*get_current_cursor_shape_func)(); static void (*set_custom_mouse_cursor_func)(const RES &, CursorShape, const Vector2 &); @@ -273,7 +273,7 @@ public: Vector2 get_last_mouse_velocity(); MouseButton get_mouse_button_mask() const; - void warp_mouse_position(const Vector2 &p_to); + void warp_mouse(const Vector2 &p_position); Point2i warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect); void parse_input_event(const Ref &p_event); diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 3163ac56101..78150af9dde 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -943,9 +943,9 @@ - + - Moves the mouse cursor to [code]to_position[/code], relative to [member position] of this [Control]. + Moves the mouse cursor to [code]position[/code], relative to [member position] of this [Control]. diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml index 47bc4961000..16a20191490 100644 --- a/doc/classes/DisplayServer.xml +++ b/doc/classes/DisplayServer.xml @@ -670,13 +670,6 @@ - - - - - Sets the mouse cursor position to the given [code]position[/code]. - - @@ -852,6 +845,13 @@ [b]Note:[/b] This method is implemented on Android, iOS and UWP. + + + + + Sets the mouse cursor position to the given [code]position[/code] relative to an origin at the upper left corner of the currently focused game Window Manager window. + + diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index 64a914bb312..c3552c9f62e 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -379,11 +379,11 @@ [b]Note:[/b] It needs [code]VIBRATE[/code] permission for Android at export settings. iOS does not support duration. - + - + - Sets the mouse position to the specified vector, provided in pixels and relative to an origin at the upper left corner of the game window. + Sets the mouse position to the specified vector, provided in pixels and relative to an origin at the upper left corner of the currently focused Window Manager game window. Mouse position is clipped to the limits of the screen resolution, or to the limits of the game window if [enum MouseMode] is set to [code]MOUSE_MODE_CONFINED[/code] or [code]MOUSE_MODE_CONFINED_HIDDEN[/code]. diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index a72e7f1eb09..b5916f8c175 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -172,7 +172,7 @@ - + Moves the mouse pointer to the specified position in this [Viewport] using the coordinate system of this [Viewport]. diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 9bf3c4c5905..32d28cd3a7d 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -81,7 +81,7 @@ void EditorSpinSlider::gui_input(const Ref &p_event) { if (grabbing_spinner_attempt) { if (grabbing_spinner) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); - Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); + Input::get_singleton()->warp_mouse(grabbing_spinner_mouse_pos); update(); } else { _focus_entered(); @@ -414,7 +414,7 @@ void EditorSpinSlider::_draw_spin_slider() { grabber->set_position(get_global_position() + (grabber_rect.get_center() - grabber->get_size() * 0.5) * scale); if (mousewheel_over_grabber) { - Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); + Input::get_singleton()->warp_mouse(grabber->get_position() + grabber_rect.size); } grabber_range = width; diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 52e60b606cf..ea119a33fa0 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -205,7 +205,7 @@ void ViewportRotationControl::gui_input(const Ref &p_event) { orbiting = false; if (Input::get_singleton()->get_mouse_mode() == Input::MOUSE_MODE_CAPTURED) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); - Input::get_singleton()->warp_mouse_position(orbiting_mouse_start); + Input::get_singleton()->warp_mouse(orbiting_mouse_start); } } } diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index 07cb6a23e81..2ddccdb8bf3 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -363,15 +363,15 @@ DisplayServerX11::MouseMode DisplayServerX11::mouse_get_mode() const { return mouse_mode; } -void DisplayServerX11::mouse_warp_to_position(const Point2i &p_to) { +void DisplayServerX11::warp_mouse(const Point2i &p_position) { _THREAD_SAFE_METHOD_ if (mouse_mode == MOUSE_MODE_CAPTURED) { - last_mouse_pos = p_to; + last_mouse_pos = p_position; } else { WindowID window_id = windows.has(last_focused_window) ? last_focused_window : MAIN_WINDOW_ID; XWarpPointer(x11_display, None, windows[window_id].x11_window, - 0, 0, 0, 0, (int)p_to.x, (int)p_to.y); + 0, 0, 0, 0, (int)p_position.x, (int)p_position.y); } } diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h index 63d32d939d3..0f44aa4b11e 100644 --- a/platform/linuxbsd/display_server_x11.h +++ b/platform/linuxbsd/display_server_x11.h @@ -301,7 +301,7 @@ public: virtual void mouse_set_mode(MouseMode p_mode) override; virtual MouseMode mouse_get_mode() const override; - virtual void mouse_warp_to_position(const Point2i &p_to) override; + virtual void warp_mouse(const Point2i &p_position) override; virtual Point2i mouse_get_position() const override; virtual MouseButton mouse_get_button_state() const override; diff --git a/platform/osx/display_server_osx.h b/platform/osx/display_server_osx.h index d9a0d2ce17b..fa3091ff81c 100644 --- a/platform/osx/display_server_osx.h +++ b/platform/osx/display_server_osx.h @@ -271,7 +271,7 @@ public: virtual MouseMode mouse_get_mode() const override; bool update_mouse_wrap(WindowData &p_wd, NSPoint &r_delta, NSPoint &r_mpos, NSTimeInterval p_timestamp); - virtual void mouse_warp_to_position(const Point2i &p_to) override; + virtual void warp_mouse(const Point2i &p_position) override; virtual Point2i mouse_get_position() const override; void mouse_set_button_state(MouseButton p_state); virtual MouseButton mouse_get_button_state() const override; diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 8820201c103..6cdadcae395 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -1646,7 +1646,7 @@ bool DisplayServerOSX::update_mouse_wrap(WindowData &p_wd, NSPoint &r_delta, NSP return false; } -void DisplayServerOSX::mouse_warp_to_position(const Point2i &p_to) { +void DisplayServerOSX::warp_mouse(const Point2i &p_position) { _THREAD_SAFE_METHOD_ if (mouse_mode != MOUSE_MODE_CAPTURED) { @@ -1656,7 +1656,7 @@ void DisplayServerOSX::mouse_warp_to_position(const Point2i &p_to) { // Local point in window coords. const NSRect contentRect = [wd.window_view frame]; const float scale = screen_get_max_scale(); - NSRect pointInWindowRect = NSMakeRect(p_to.x / scale, contentRect.size.height - (p_to.y / scale - 1), 0, 0); + NSRect pointInWindowRect = NSMakeRect(p_position.x / scale, contentRect.size.height - (p_position.y / scale - 1), 0, 0); NSPoint pointOnScreen = [[wd.window_view window] convertRectToScreen:pointInWindowRect].origin; // Point in scren coords. diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index d243d4c05d4..16323dcc131 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -150,7 +150,7 @@ DisplayServer::MouseMode DisplayServerWindows::mouse_get_mode() const { return mouse_mode; } -void DisplayServerWindows::mouse_warp_to_position(const Point2i &p_to) { +void DisplayServerWindows::warp_mouse(const Point2i &p_position) { _THREAD_SAFE_METHOD_ if (!windows.has(last_focused_window)) { @@ -158,12 +158,12 @@ void DisplayServerWindows::mouse_warp_to_position(const Point2i &p_to) { } if (mouse_mode == MOUSE_MODE_CAPTURED) { - old_x = p_to.x; - old_y = p_to.y; + old_x = p_position.x; + old_y = p_position.y; } else { POINT p; - p.x = p_to.x; - p.y = p_to.y; + p.x = p_position.x; + p.y = p_position.y; ClientToScreen(windows[last_focused_window].hWnd, &p); SetCursorPos(p.x, p.y); diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index a56a2b83ac1..71fedf2bca0 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -457,7 +457,7 @@ public: virtual void mouse_set_mode(MouseMode p_mode) override; virtual MouseMode mouse_get_mode() const override; - virtual void mouse_warp_to_position(const Point2i &p_to) override; + virtual void warp_mouse(const Point2i &p_position) override; virtual Point2i mouse_get_position() const override; virtual MouseButton mouse_get_button_state() const override; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index d2d1b5e9b7b..ee35eee35d1 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2937,9 +2937,9 @@ Control::MouseFilter Control::get_mouse_filter() const { return data.mouse_filter; } -void Control::warp_mouse(const Point2 &p_to_pos) { +void Control::warp_mouse(const Point2 &p_position) { ERR_FAIL_COND(!is_inside_tree()); - get_viewport()->warp_mouse(get_global_transform().xform(p_to_pos)); + get_viewport()->warp_mouse(get_global_transform().xform(p_position)); } bool Control::is_text_field() const { @@ -3331,7 +3331,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_drag_preview", "control"), &Control::set_drag_preview); ClassDB::bind_method(D_METHOD("is_drag_successful"), &Control::is_drag_successful); - ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Control::warp_mouse); + ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &Control::warp_mouse); ClassDB::bind_method(D_METHOD("update_minimum_size"), &Control::update_minimum_size); diff --git a/scene/gui/control.h b/scene/gui/control.h index becb50a118d..9f78d003ae9 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -548,7 +548,7 @@ public: void grab_click_focus(); - void warp_mouse(const Point2 &p_to_pos); + void warp_mouse(const Point2 &p_position); virtual bool is_text_field() const; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 4525696071d..10ff464bfaa 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1124,9 +1124,9 @@ Vector2 Viewport::get_mouse_position() const { return gui.last_mouse_pos; } -void Viewport::warp_mouse(const Vector2 &p_pos) { - Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos); - Input::get_singleton()->warp_mouse_position(gpos); +void Viewport::warp_mouse(const Vector2 &p_position) { + Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_position); + Input::get_singleton()->warp_mouse(gpos); } void Viewport::_gui_sort_roots() { @@ -3642,7 +3642,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d); ClassDB::bind_method(D_METHOD("get_mouse_position"), &Viewport::get_mouse_position); - ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Viewport::warp_mouse); + ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &Viewport::warp_mouse); ClassDB::bind_method(D_METHOD("gui_get_drag_data"), &Viewport::gui_get_drag_data); ClassDB::bind_method(D_METHOD("gui_is_dragging"), &Viewport::gui_is_dragging); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index e4912f31c59..d5fca1b8814 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -547,7 +547,7 @@ public: bool is_input_disabled() const; Vector2 get_mouse_position() const; - void warp_mouse(const Vector2 &p_pos); + void warp_mouse(const Vector2 &p_position); void set_physics_object_picking(bool p_enable); bool get_physics_object_picking(); diff --git a/servers/display_server.cpp b/servers/display_server.cpp index db65465c644..67bfc75426b 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -228,7 +228,7 @@ DisplayServer::MouseMode DisplayServer::mouse_get_mode() const { return MOUSE_MODE_VISIBLE; } -void DisplayServer::mouse_warp_to_position(const Point2i &p_to) { +void DisplayServer::warp_mouse(const Point2i &p_position) { WARN_PRINT("Mouse warping is not supported by this display server."); } @@ -481,7 +481,7 @@ void DisplayServer::_bind_methods() { ClassDB::bind_method(D_METHOD("mouse_set_mode", "mouse_mode"), &DisplayServer::mouse_set_mode); ClassDB::bind_method(D_METHOD("mouse_get_mode"), &DisplayServer::mouse_get_mode); - ClassDB::bind_method(D_METHOD("mouse_warp_to_position", "position"), &DisplayServer::mouse_warp_to_position); + ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &DisplayServer::warp_mouse); ClassDB::bind_method(D_METHOD("mouse_get_position"), &DisplayServer::mouse_get_position); ClassDB::bind_method(D_METHOD("mouse_get_button_state"), &DisplayServer::mouse_get_button_state); @@ -729,7 +729,7 @@ Input::MouseMode DisplayServer::_input_get_mouse_mode() { } void DisplayServer::_input_warp(const Vector2 &p_to_pos) { - singleton->mouse_warp_to_position(p_to_pos); + singleton->warp_mouse(p_to_pos); } Input::CursorShape DisplayServer::_input_get_current_cursor_shape() { diff --git a/servers/display_server.h b/servers/display_server.h index f3a910471fb..4961b07ba34 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -183,7 +183,7 @@ public: virtual void mouse_set_mode(MouseMode p_mode); virtual MouseMode mouse_get_mode() const; - virtual void mouse_warp_to_position(const Point2i &p_to); + virtual void warp_mouse(const Point2i &p_position); virtual Point2i mouse_get_position() const; virtual MouseButton mouse_get_button_state() const;