From 8118d0d2f5d6e780d0a8d62d39f7ce7b26139c78 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Sun, 7 May 2023 11:14:57 -0300 Subject: [PATCH] Add more uses of appropriate cursors when resizing/moving some UI nodes --- scene/gui/graph_edit.cpp | 17 +++++++++++++++++ scene/gui/graph_edit.h | 4 ++++ scene/gui/graph_node.cpp | 13 ++++++++++++- scene/gui/graph_node.h | 2 ++ scene/main/viewport.cpp | 4 ++++ 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 946e8a2ad58..f2f98b18897 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -62,6 +62,15 @@ GraphEditMinimap::GraphEditMinimap(GraphEdit *p_edit) { is_resizing = false; } +Control::CursorShape GraphEditMinimap::get_cursor_shape(const Point2 &p_pos) const { + Ref resizer = get_theme_icon(SNAME("resizer")); + if (is_resizing || (p_pos.x < resizer->get_width() && p_pos.y < resizer->get_height())) { + return CURSOR_FDIAGSIZE; + } + + return Control::get_cursor_shape(p_pos); +} + void GraphEditMinimap::update_minimap() { Vector2 graph_offset = _get_graph_offset(); Vector2 graph_size = _get_graph_size(); @@ -190,6 +199,14 @@ void GraphEditMinimap::_adjust_graph_scroll(const Vector2 &p_offset) { ge->set_scroll_ofs(p_offset + graph_offset - camera_size / 2); } +Control::CursorShape GraphEdit::get_cursor_shape(const Point2 &p_pos) const { + if (moving_selection) { + return CURSOR_MOVE; + } + + return Control::get_cursor_shape(p_pos); +} + PackedStringArray GraphEdit::get_configuration_warnings() const { PackedStringArray warnings = Control::get_configuration_warnings(); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index dfe6b949060..8b02fbfddc3 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -64,6 +64,8 @@ protected: public: GraphEditMinimap(GraphEdit *p_edit); + virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override; + void update_minimap(); Rect2 get_camera_rect(); @@ -286,6 +288,8 @@ protected: GDVIRTUAL4R(bool, _is_node_hover_valid, StringName, int, StringName, int); public: + virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override; + PackedStringArray get_configuration_warnings() const override; Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 8b2d462d851..6031730b81e 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -990,7 +990,6 @@ void GraphNode::gui_input(const Ref &p_ev) { Ref mm = p_ev; if (resizing && mm.is_valid()) { Vector2 mpos = mm->get_position(); - Vector2 diff = mpos - resizing_from; emit_signal(SNAME("resize_request"), resizing_from_size + diff); @@ -1055,6 +1054,18 @@ bool GraphNode::is_selectable() { return selectable; } +Control::CursorShape GraphNode::get_cursor_shape(const Point2 &p_pos) const { + if (resizable) { + Ref resizer = get_theme_icon(SNAME("resizer")); + + if (resizing || (p_pos.x > get_size().x - resizer->get_width() && p_pos.y > get_size().y - resizer->get_height())) { + return CURSOR_FDIAGSIZE; + } + } + + return Control::get_cursor_shape(p_pos); +} + Vector GraphNode::get_allowed_size_flags_horizontal() const { Vector flags; flags.append(SIZE_FILL); diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index a118efb37a4..e6ecc3d89b0 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -197,6 +197,8 @@ public: virtual Size2 get_minimum_size() const override; + virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override; + virtual Vector get_allowed_size_flags_horizontal() const override; virtual Vector get_allowed_size_flags_vertical() const override; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index f3c2f4b0ccf..07560b4a827 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2601,6 +2601,10 @@ bool Viewport::_sub_windows_forward_input(const Ref &p_event) { } gui.subwindow_focused->_rect_changed_callback(new_rect); + + if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE)) { + DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CURSOR_MOVE); + } } if (gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE) { gui.subwindow_drag_close_inside = gui.subwindow_drag_close_rect.has_point(mm->get_position());