summaryrefslogtreecommitdiffstats
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_item.compat.inc41
-rw-r--r--scene/main/canvas_item.cpp36
-rw-r--r--scene/main/canvas_item.h8
-rw-r--r--scene/main/status_indicator.cpp63
-rw-r--r--scene/main/status_indicator.h12
-rw-r--r--scene/main/viewport.cpp37
-rw-r--r--scene/main/viewport.h2
-rw-r--r--scene/main/window.cpp4
8 files changed, 180 insertions, 23 deletions
diff --git a/scene/main/canvas_item.compat.inc b/scene/main/canvas_item.compat.inc
new file mode 100644
index 0000000000..7136fded15
--- /dev/null
+++ b/scene/main/canvas_item.compat.inc
@@ -0,0 +1,41 @@
+/**************************************************************************/
+/* canvas_item.compat.inc */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#ifndef DISABLE_DEPRECATED
+
+void CanvasItem::_draw_circle_compat_84472(const Point2 &p_pos, real_t p_radius, const Color &p_color) {
+ draw_circle(p_pos, p_radius, p_color, true, -1.0, false);
+}
+
+void CanvasItem::_bind_compatibility_methods() {
+ ClassDB::bind_compatibility_method(D_METHOD("draw_circle", "position", "radius", "color"), &CanvasItem::_draw_circle_compat_84472);
+}
+
+#endif
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 56aa453407..cabba0f2ed 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -29,6 +29,7 @@
/**************************************************************************/
#include "canvas_item.h"
+#include "canvas_item.compat.inc"
#include "scene/2d/canvas_group.h"
#include "scene/main/canvas_layer.h"
@@ -726,11 +727,40 @@ void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_fil
}
}
-void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color) {
+void CanvasItem::draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled, real_t p_width, bool p_antialiased) {
ERR_THREAD_GUARD;
ERR_DRAW_GUARD;
- RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color);
+ if (p_filled) {
+ if (p_width != -1.0) {
+ WARN_PRINT("The draw_circle() \"width\" argument has no effect when \"filled\" is \"true\".");
+ }
+
+ RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color);
+ } else if (p_width >= 2.0 * p_radius) {
+ RenderingServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius + 0.5 * p_width, p_color);
+ } else {
+ // Tessellation count is hardcoded. Keep in sync with the same variable in `RendererCanvasCull::canvas_item_add_circle()`.
+ const int circle_segments = 64;
+
+ Vector<Vector2> points;
+ points.resize(circle_segments + 1);
+
+ Vector2 *points_ptr = points.ptrw();
+ const real_t circle_point_step = Math_TAU / circle_segments;
+
+ for (int i = 0; i < circle_segments; i++) {
+ float angle = i * circle_point_step;
+ points_ptr[i].x = Math::cos(angle) * p_radius;
+ points_ptr[i].y = Math::sin(angle) * p_radius;
+ points_ptr[i] += p_pos;
+ }
+ points_ptr[circle_segments] = points_ptr[0];
+
+ Vector<Color> colors = { p_color };
+
+ RenderingServer::get_singleton()->canvas_item_add_polyline(canvas_item, points, colors, p_width, p_antialiased);
+ }
}
void CanvasItem::draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate) {
@@ -1163,7 +1193,7 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("draw_multiline", "points", "color", "width"), &CanvasItem::draw_multiline, DEFVAL(-1.0));
ClassDB::bind_method(D_METHOD("draw_multiline_colors", "points", "colors", "width"), &CanvasItem::draw_multiline_colors, DEFVAL(-1.0));
ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color", "filled", "width"), &CanvasItem::draw_rect, DEFVAL(true), DEFVAL(-1.0));
- ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color"), &CanvasItem::draw_circle);
+ ClassDB::bind_method(D_METHOD("draw_circle", "position", "radius", "color", "filled", "width", "antialiased"), &CanvasItem::draw_circle, DEFVAL(true), DEFVAL(-1.0), DEFVAL(false));
ClassDB::bind_method(D_METHOD("draw_texture", "texture", "position", "modulate"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)));
ClassDB::bind_method(D_METHOD("draw_texture_rect", "texture", "rect", "tile", "modulate", "transpose"), &CanvasItem::draw_texture_rect, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false));
ClassDB::bind_method(D_METHOD("draw_texture_rect_region", "texture", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &CanvasItem::draw_texture_rect_region, DEFVAL(Color(1, 1, 1, 1)), DEFVAL(false), DEFVAL(true));
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index 8cec086ca6..ae7b195ead 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -166,6 +166,12 @@ protected:
void _notification(int p_what);
static void _bind_methods();
+
+#ifndef DISABLE_DEPRECATED
+ void _draw_circle_compat_84472(const Point2 &p_pos, real_t p_radius, const Color &p_color);
+ static void _bind_compatibility_methods();
+#endif
+
void _validate_property(PropertyInfo &p_property) const;
_FORCE_INLINE_ void set_hide_clip_children(bool p_value) { hide_clip_children = p_value; }
@@ -273,7 +279,7 @@ public:
void draw_multiline(const Vector<Point2> &p_points, const Color &p_color, real_t p_width = -1.0);
void draw_multiline_colors(const Vector<Point2> &p_points, const Vector<Color> &p_colors, real_t p_width = -1.0);
void draw_rect(const Rect2 &p_rect, const Color &p_color, bool p_filled = true, real_t p_width = -1.0);
- void draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color);
+ void draw_circle(const Point2 &p_pos, real_t p_radius, const Color &p_color, bool p_filled = true, real_t p_width = -1.0, bool p_antialiased = false);
void draw_texture(const Ref<Texture2D> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1));
void draw_texture_rect(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
void draw_texture_rect_region(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, bool p_clip_uv = false);
diff --git a/scene/main/status_indicator.cpp b/scene/main/status_indicator.cpp
index 54b2ff75ca..891974f68f 100644
--- a/scene/main/status_indicator.cpp
+++ b/scene/main/status_indicator.cpp
@@ -30,6 +30,8 @@
#include "status_indicator.h"
+#include "scene/gui/popup_menu.h"
+
void StatusIndicator::_notification(int p_what) {
ERR_MAIN_THREAD_GUARD;
#ifdef TOOLS_ENABLED
@@ -43,12 +45,22 @@ void StatusIndicator::_notification(int p_what) {
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_STATUS_INDICATOR)) {
if (visible && iid == DisplayServer::INVALID_INDICATOR_ID) {
iid = DisplayServer::get_singleton()->create_status_indicator(icon, tooltip, callable_mp(this, &StatusIndicator::_callback));
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
+ if (pm) {
+ RID menu_rid = pm->bind_global_menu();
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, menu_rid);
+ }
}
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_STATUS_INDICATOR)) {
if (iid != DisplayServer::INVALID_INDICATOR_ID) {
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
+ if (pm) {
+ pm->unbind_global_menu();
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, RID());
+ }
DisplayServer::get_singleton()->delete_status_indicator(iid);
iid = DisplayServer::INVALID_INDICATOR_ID;
}
@@ -66,11 +78,15 @@ void StatusIndicator::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_icon"), &StatusIndicator::get_icon);
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &StatusIndicator::set_visible);
ClassDB::bind_method(D_METHOD("is_visible"), &StatusIndicator::is_visible);
+ ClassDB::bind_method(D_METHOD("set_menu", "menu"), &StatusIndicator::set_menu);
+ ClassDB::bind_method(D_METHOD("get_menu"), &StatusIndicator::get_menu);
+ ClassDB::bind_method(D_METHOD("get_rect"), &StatusIndicator::get_rect);
ADD_SIGNAL(MethodInfo("pressed", PropertyInfo(Variant::INT, "mouse_button"), PropertyInfo(Variant::VECTOR2I, "mouse_position")));
ADD_PROPERTY(PropertyInfo(Variant::STRING, "tooltip", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip", "get_tooltip");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "set_icon", "get_icon");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_icon", "get_icon");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "menu", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "PopupMenu"), "set_menu", "get_menu");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
}
@@ -78,7 +94,7 @@ void StatusIndicator::_callback(MouseButton p_index, const Point2i &p_pos) {
emit_signal(SNAME("pressed"), p_index, p_pos);
}
-void StatusIndicator::set_icon(const Ref<Image> &p_icon) {
+void StatusIndicator::set_icon(const Ref<Texture2D> &p_icon) {
ERR_MAIN_THREAD_GUARD;
icon = p_icon;
if (iid != DisplayServer::INVALID_INDICATOR_ID) {
@@ -86,7 +102,7 @@ void StatusIndicator::set_icon(const Ref<Image> &p_icon) {
}
}
-Ref<Image> StatusIndicator::get_icon() const {
+Ref<Texture2D> StatusIndicator::get_icon() const {
return icon;
}
@@ -102,6 +118,30 @@ String StatusIndicator::get_tooltip() const {
return tooltip;
}
+void StatusIndicator::set_menu(const NodePath &p_menu) {
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
+ if (pm) {
+ pm->unbind_global_menu();
+ if (iid != DisplayServer::INVALID_INDICATOR_ID) {
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, RID());
+ }
+ }
+
+ menu = p_menu;
+
+ pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
+ if (pm) {
+ if (iid != DisplayServer::INVALID_INDICATOR_ID) {
+ RID menu_rid = pm->bind_global_menu();
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, menu_rid);
+ }
+ }
+}
+
+NodePath StatusIndicator::get_menu() const {
+ return menu;
+}
+
void StatusIndicator::set_visible(bool p_visible) {
ERR_MAIN_THREAD_GUARD;
if (visible == p_visible) {
@@ -122,8 +162,18 @@ void StatusIndicator::set_visible(bool p_visible) {
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_STATUS_INDICATOR)) {
if (visible && iid == DisplayServer::INVALID_INDICATOR_ID) {
iid = DisplayServer::get_singleton()->create_status_indicator(icon, tooltip, callable_mp(this, &StatusIndicator::_callback));
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
+ if (pm) {
+ RID menu_rid = pm->bind_global_menu();
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, menu_rid);
+ }
}
if (!visible && iid != DisplayServer::INVALID_INDICATOR_ID) {
+ PopupMenu *pm = Object::cast_to<PopupMenu>(get_node_or_null(menu));
+ if (pm) {
+ pm->unbind_global_menu();
+ DisplayServer::get_singleton()->status_indicator_set_menu(iid, RID());
+ }
DisplayServer::get_singleton()->delete_status_indicator(iid);
iid = DisplayServer::INVALID_INDICATOR_ID;
}
@@ -133,3 +183,10 @@ void StatusIndicator::set_visible(bool p_visible) {
bool StatusIndicator::is_visible() const {
return visible;
}
+
+Rect2 StatusIndicator::get_rect() const {
+ if (iid == DisplayServer::INVALID_INDICATOR_ID) {
+ return Rect2();
+ }
+ return DisplayServer::get_singleton()->status_indicator_get_rect(iid);
+}
diff --git a/scene/main/status_indicator.h b/scene/main/status_indicator.h
index aa3aa68d78..cd38da6e6c 100644
--- a/scene/main/status_indicator.h
+++ b/scene/main/status_indicator.h
@@ -37,10 +37,11 @@
class StatusIndicator : public Node {
GDCLASS(StatusIndicator, Node);
- Ref<Image> icon;
+ Ref<Texture2D> icon;
String tooltip;
bool visible = true;
DisplayServer::IndicatorID iid = DisplayServer::INVALID_INDICATOR_ID;
+ NodePath menu;
protected:
void _notification(int p_what);
@@ -49,14 +50,19 @@ protected:
void _callback(MouseButton p_index, const Point2i &p_pos);
public:
- void set_icon(const Ref<Image> &p_icon);
- Ref<Image> get_icon() const;
+ void set_icon(const Ref<Texture2D> &p_icon);
+ Ref<Texture2D> get_icon() const;
void set_tooltip(const String &p_tooltip);
String get_tooltip() const;
+ void set_menu(const NodePath &p_menu);
+ NodePath get_menu() const;
+
void set_visible(bool p_visible);
bool is_visible() const;
+
+ Rect2 get_rect() const;
};
#endif // STATUS_INDICATOR_H
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 73ce166123..9dbe10f30b 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -688,6 +688,18 @@ void Viewport::_process_picking() {
physics_picking_events.clear();
return;
}
+#ifndef _3D_DISABLED
+ if (use_xr) {
+ if (XRServer::get_singleton() != nullptr) {
+ Ref<XRInterface> xr_interface = XRServer::get_singleton()->get_primary_interface();
+ if (xr_interface.is_valid() && xr_interface->is_initialized() && xr_interface->get_view_count() > 1) {
+ WARN_PRINT_ONCE("Object picking can't be used when stereo rendering, this will be turned off!");
+ physics_object_picking = false; // don't try again.
+ return;
+ }
+ }
+ }
+#endif
_drop_physics_mouseover(true);
@@ -856,9 +868,10 @@ void Viewport::_process_picking() {
if (send_event) {
co->_input_event_call(this, ev, res[i].shape);
- if (physics_object_picking_first_only) {
- break;
- }
+ }
+
+ if (physics_object_picking_first_only) {
+ break;
}
}
}
@@ -970,7 +983,7 @@ void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override,
stretch_transform_new.scale(scale);
}
- Size2i new_size = p_size.max(Size2i(2, 2));
+ Size2i new_size = p_size.maxi(2);
if (size == new_size && size_allocated == p_allocated && stretch_transform == stretch_transform_new && p_size_2d_override == size_2d_override) {
return;
}
@@ -1721,7 +1734,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.mouse_focus_mask.set_flag(button_mask);
} else {
gui.mouse_focus = gui_find_control(mpos);
- gui.last_mouse_focus = gui.mouse_focus;
if (!gui.mouse_focus) {
return;
@@ -2306,6 +2318,7 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *
gui.dragging = true;
gui.drag_data = p_data;
gui.mouse_focus = nullptr;
+ gui.mouse_focus_mask.clear();
if (p_control) {
_gui_set_drag_preview(p_base, p_control);
@@ -2378,9 +2391,6 @@ void Viewport::_gui_remove_control(Control *p_control) {
gui.forced_mouse_focus = false;
gui.mouse_focus_mask.clear();
}
- if (gui.last_mouse_focus == p_control) {
- gui.last_mouse_focus = nullptr;
- }
if (gui.key_focus == p_control) {
gui.key_focus = nullptr;
}
@@ -2758,7 +2768,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
Size2i min_size = gui.currently_dragged_subwindow->get_min_size();
Size2i min_size_clamped = gui.currently_dragged_subwindow->get_clamped_minimum_size();
- min_size_clamped = min_size_clamped.max(Size2i(1, 1));
+ min_size_clamped = min_size_clamped.maxi(1);
Rect2i r = gui.subwindow_resize_from_rect;
@@ -2819,7 +2829,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
Size2i max_size = gui.currently_dragged_subwindow->get_max_size();
if ((max_size.x > 0 || max_size.y > 0) && (max_size.x >= min_size.x && max_size.y >= min_size.y)) {
- max_size = max_size.max(Size2i(1, 1));
+ max_size = max_size.maxi(1);
if (r.size.x > max_size.x) {
r.size.x = max_size.x;
@@ -3578,6 +3588,13 @@ bool Viewport::gui_is_drag_successful() const {
return gui.drag_successful;
}
+void Viewport::gui_cancel_drag() {
+ ERR_MAIN_THREAD_GUARD;
+ if (gui_is_dragging()) {
+ _perform_drop();
+ }
+}
+
void Viewport::set_input_as_handled() {
ERR_MAIN_THREAD_GUARD;
if (!handle_input_locally) {
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 21832a454c..394d48143c 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -345,7 +345,6 @@ private:
bool key_event_accepted = false;
HashMap<int, ObjectID> touch_focus;
Control *mouse_focus = nullptr;
- Control *last_mouse_focus = nullptr;
Control *mouse_click_grabber = nullptr;
BitField<MouseButtonMask> mouse_focus_mask;
Control *key_focus = nullptr;
@@ -616,6 +615,7 @@ public:
bool gui_is_dragging() const;
bool gui_is_drag_successful() const;
+ void gui_cancel_drag();
Control *gui_find_control(const Point2 &p_global);
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 0ccc056a8d..929720fcf4 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -415,7 +415,7 @@ Size2i Window::_clamp_limit_size(const Size2i &p_limit_size) {
if (max_window_size != Size2i()) {
return p_limit_size.clamp(Vector2i(), max_window_size);
} else {
- return p_limit_size.max(Vector2i());
+ return p_limit_size.maxi(0);
}
}
@@ -1036,7 +1036,7 @@ void Window::_update_window_size() {
}
if (embedder) {
- size = size.max(Size2i(1, 1));
+ size = size.maxi(1);
embedder->_sub_window_update(this);
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {