summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/osx/os_osx.mm13
-rw-r--r--platform/windows/os_windows.cpp7
-rw-r--r--platform/x11/os_x11.cpp6
-rw-r--r--scene/gui/control.cpp9
-rw-r--r--scene/gui/control.h2
-rw-r--r--scene/main/viewport.cpp9
-rw-r--r--scene/main/viewport.h2
7 files changed, 44 insertions, 4 deletions
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 5bc47a74c1..af2552496b 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -1093,8 +1093,19 @@ void OS_OSX::warp_mouse_pos(const Point2& p_to) {
mouse_y = p_to.y;
}
else{ //set OS position
- CGPoint lMouseWarpPos = {p_to.x, p_to.y};
+ /* this code has not been tested, please be a kind soul and fix it if it fails! */
+
+ //local point in window coords
+ NSPoint localPoint = { p_to.x, p_to.y };
+
+ NSPoint pointInWindow = [window_view convertPoint:localPoint toView:nil];
+ NSPoint pointOnScreen = [[window_view window] convertRectToScreen:(CGRect){.origin=pointInWindow}];
+
+ //point in scren coords
+ CGPoint lMouseWarpPos = { pointOnScreen.x, pointOnScreen.y};
+
+ //do the warping
CGEventSourceRef lEventRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventSourceSetLocalEventsSuppressionInterval(lEventRef, 0.0);
CGAssociateMouseAndMouseCursorPosition(false);
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 086b4d7d12..ad54a327cf 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1432,7 +1432,12 @@ void OS_Windows::warp_mouse_pos(const Point2& p_to) {
old_y=p_to.y;
} else {
- SetCursorPos(p_to.x, p_to.y);
+ POINT p;
+ p.x=p_to.x;
+ p.y=p_to.y;
+ ClientToScreen(hWnd,&p);
+
+ SetCursorPos(p.x,p.y);
}
}
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index a40af8d2a9..ac1818d200 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -479,8 +479,12 @@ void OS_X11::warp_mouse_pos(const Point2& p_to) {
last_mouse_pos=p_to;
} else {
+ /*XWindowAttributes xwa;
+ XGetWindowAttributes(x11_display, x11_window, &xwa);
+ printf("%d %d\n", xwa.x, xwa.y); needed? */
+
XWarpPointer(x11_display, None, x11_window,
- 0,0,0,0, (int)p_to.x, (int)p_to.y);
+ 0,0,0,0, (int)p_to.x , (int)p_to.y);
}
}
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index ce268843b1..4d32c7ea9a 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2688,6 +2688,12 @@ Control *Control::get_focus_owner() const {
return data.window->window->key_focus;
}
+
+void Control::warp_mouse(const Point2& p_to_pos) {
+ ERR_FAIL_COND(!is_inside_tree());
+ get_viewport()->warp_mouse(get_global_transform().xform(p_to_pos));
+}
+
void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_window_input_event"),&Control::_window_input_event);
@@ -2784,6 +2790,9 @@ void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_drag_preview","control:Control"),&Control::set_drag_preview);
+ ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"),&Control::warp_mouse);
+
+
BIND_VMETHOD(MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
BIND_VMETHOD(MethodInfo(Variant::VECTOR2,"get_minimum_size"));
BIND_VMETHOD(MethodInfo(Variant::OBJECT,"get_drag_data",PropertyInfo(Variant::VECTOR2,"pos")));
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 64b5a9b661..7e14bff098 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -380,7 +380,7 @@ public:
void grab_click_focus();
-
+ void warp_mouse(const Point2& p_to_pos);
Control();
~Control();
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index e6c787cf9e..fa163bf96d 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -29,6 +29,8 @@
#include "viewport.h"
#include "os/os.h"
#include "scene/3d/spatial.h"
+#include "os/input.h"
+
//#include "scene/3d/camera.h"
#include "servers/spatial_sound_server.h"
@@ -1100,6 +1102,12 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) {
}
+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_pos(gpos);
+}
+
void Viewport::input(const InputEvent& p_event) {
ERR_FAIL_COND(!is_inside_tree());
@@ -1289,6 +1297,7 @@ void Viewport::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d);
ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect"), &Viewport::set_render_target_to_screen_rect);
+ ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse);
ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world") );
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 4bb5735731..832a6b6107 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -246,6 +246,8 @@ public:
void set_render_target_to_screen_rect(const Rect2& p_rect);
Rect2 get_render_target_to_screen_rect() const;
+ void warp_mouse(const Vector2& p_pos);
+
void set_physics_object_picking(bool p_enable);
bool get_physics_object_picking();