Skip to content
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

Update mouse cursor shape after changes #58995

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,19 @@ void Control::_window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, cons
void Control::set_default_cursor_shape(CursorShape p_shape) {
ERR_FAIL_INDEX(int(p_shape), CURSOR_MAX);

if (data.default_cursor == p_shape) {
return;
}
data.default_cursor = p_shape;

if (!is_inside_tree()) {
return;
}
if (!get_global_rect().has_point(get_global_mouse_position())) {
return;
}

get_viewport()->get_base_window()->update_mouse_cursor_shape();
}

Control::CursorShape Control::get_default_cursor_shape() const {
Expand Down
1 change: 1 addition & 0 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
4 changes: 2 additions & 2 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,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);
}
Expand Down
2 changes: 2 additions & 0 deletions scene/main/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ class Window : public Viewport {
void set_visible(bool p_visible);
bool is_visible() const;

void update_mouse_cursor_shape();

void show();
void hide();

Expand Down