summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-09-28 20:50:05 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-09-28 20:50:05 +0200
commite3464c8fc86e346c5c3a9d7d554cc2c5866ccb48 (patch)
treec2db4d7b5931f4acc4914f4f7416ef2963f208f3 /scene/main
parentba25a6e93bcfff0c30b440301edaeb3e2ca73f05 (diff)
parent52da6f1a44ff407fcb852a7e7124b7e652885d87 (diff)
Merge pull request #58995 from Sauermann/fix-mouse-cursor-change-2
Update mouse cursor shape after changes
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/scene_tree.cpp1
-rw-r--r--scene/main/viewport.cpp4
-rw-r--r--scene/main/window.cpp12
-rw-r--r--scene/main/window.h2
4 files changed, 17 insertions, 2 deletions
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 0d2186ba08..3f71de1b18 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -1085,6 +1085,7 @@ void SceneTree::_change_scene(Node *p_to) {
if (p_to) {
current_scene = p_to;
root->add_child(p_to);
+ root->update_mouse_cursor_shape();
}
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index a1c7139b25..549cc19cb1 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1576,7 +1576,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.drag_preview_id = ObjectID();
}
_propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
- // Change mouse accordingly.
+ get_base_window()->update_mouse_cursor_shape();
}
_gui_cancel_tooltip();
@@ -1597,7 +1597,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.dragging = false;
gui.drag_mouse_over = nullptr;
_propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
- // Change mouse accordingly.
+ get_base_window()->update_mouse_cursor_shape();
}
gui.mouse_focus_mask &= ~mouse_button_to_mask(mb->get_button_index()); // Remove from mask.
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 73f278bb50..64869b2936 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -395,6 +395,18 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
}
}
+void Window::update_mouse_cursor_shape() {
+ // The default shape is set in Viewport::_gui_input_event. To instantly
+ // see the shape in the viewport we need to trigger a mouse motion event.
+ Ref<InputEventMouseMotion> mm;
+ Vector2 pos = get_mouse_position();
+ Transform2D xform = get_global_canvas_transform().affine_inverse();
+ mm.instantiate();
+ mm->set_position(pos);
+ mm->set_global_position(xform.xform(pos));
+ push_input(mm);
+}
+
void Window::show() {
set_visible(true);
}
diff --git a/scene/main/window.h b/scene/main/window.h
index 8c6ca65436..786f0ada38 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -220,6 +220,8 @@ public:
void set_visible(bool p_visible);
bool is_visible() const;
+ void update_mouse_cursor_shape();
+
void show();
void hide();