Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix bugs with remote `CanvasItem`s interactions due to embedding and scale

Michael Alexsander6cf1cd506f03
diff --git a/editor/run/game_view_plugin.cpp b/editor/run/game_view_plugin.cpp
index 308f199f0e4..f9042321093 100644
--- a/editor/run/game_view_plugin.cpp
+++ b/editor/run/game_view_plugin.cpp
@@ -83,6 +83,7 @@ void GameViewDebugger::_session_started(Ref<EditorDebuggerSession> p_session) {
settings["canvas_item_editor/cancel_transform"] = DebuggerMarshalls::serialize_key_shortcut(ED_GET_SHORTCUT("canvas_item_editor/cancel_transform"));
settings["box_selection_fill_color"] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("box_selection_fill_color"), EditorStringName(Editor));
settings["box_selection_stroke_color"] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("box_selection_stroke_color"), EditorStringName(Editor));
+ settings["editor_scale"] = EDSCALE;
if (!is_native) {
settings["accent_color"] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("accent_color"), EditorStringName(Editor));
settings["axis_x_color"] = EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("axis_x_color"), EditorStringName(Editor));
diff --git a/editor/scene/canvas_item_editor_plugin.cpp b/editor/scene/canvas_item_editor_plugin.cpp
index 637b63b8e38..72eafaeb11d 100644
--- a/editor/scene/canvas_item_editor_plugin.cpp
+++ b/editor/scene/canvas_item_editor_plugin.cpp
@@ -2639,7 +2639,6 @@ void CanvasItemEditor::_notification(int p_what) {
callable_mp(EditorNode::get_singleton(), &EditorNode::get_edited_scene),
callable_mp(this, &CanvasItemEditor::_select_click_on_item),
callable_mp(this, &CanvasItemEditor::_get_selection_callback),
- callable_mp(viewport_scrollable, &Control::get_transform),
callable_mp((Viewport *)EditorNode::get_singleton()->get_scene_root(), &Viewport::get_global_canvas_transform),
callable_mp((CanvasItem *)viewport, &CanvasItem::get_local_mouse_position),
callable_mp(EditorNode::get_singleton()->get_editor_plugins_over(), &EditorPluginList::forward_gui_input));
diff --git a/scene/debugger/canvas_item_manipulator.cpp b/scene/debugger/canvas_item_manipulator.cpp
index 0194b120f6e..a379a0445f2 100644
--- a/scene/debugger/canvas_item_manipulator.cpp
+++ b/scene/debugger/canvas_item_manipulator.cpp
@@ -48,7 +48,7 @@ bool CanvasItemManipulator::_gui_input_rulers_and_guides(const Ref<InputEvent> &
if (show_guides && show_rulers && drag_type == DRAG_NONE) {
Node *start = Object::cast_to<Node>(find_items_start_callback.call());
if (start) {
- Transform2D xform = (Transform2D)local_transform_callback.call() * (Transform2D)global_transform_callback.call();
+ Transform2D xform = global_transform_callback.call();
// Retrieve the guide lists.
Array vguides = start->get_meta("_edit_vertical_guides_", Array());
Array hguides = start->get_meta("_edit_horizontal_guides_", Array());
@@ -130,7 +130,7 @@ bool CanvasItemManipulator::_gui_input_rulers_and_guides(const Ref<InputEvent> &
if (drag_type == DRAG_DOUBLE_GUIDE || drag_type == DRAG_V_GUIDE || drag_type == DRAG_H_GUIDE) {
// Move the guide.
if (m.is_valid()) {
- Transform2D xform = (Transform2D)local_transform_callback.call() * (Transform2D)global_transform_callback.call();
+ Transform2D xform = global_transform_callback.call();
drag_to = xform.affine_inverse().xform(m->get_position());
dragged_guide_pos = xform.xform(snap_point(drag_to, SNAP_GRID | SNAP_PIXEL | SNAP_OTHER_NODES));
@@ -142,13 +142,11 @@ bool CanvasItemManipulator::_gui_input_rulers_and_guides(const Ref<InputEvent> &
if (show_guides && b.is_valid() && b->get_button_index() == MouseButton::LEFT && !b->is_pressed()) {
Node *start = Object::cast_to<Node>(find_items_start_callback.call());
if (start) {
- Transform2D xform = (Transform2D)local_transform_callback.call() * (Transform2D)global_transform_callback.call();
-
// Retrieve the guide lists.
Array vguides = start->get_meta("_edit_vertical_guides_", Array());
Array hguides = start->get_meta("_edit_horizontal_guides_", Array());
- Point2 edited = snap_point(xform.affine_inverse().xform(b->get_position()), SNAP_GRID | SNAP_PIXEL | SNAP_OTHER_NODES);
+ Point2 edited = snap_point(Transform2D(global_transform_callback.call()).affine_inverse().xform(b->get_position()), SNAP_GRID | SNAP_PIXEL | SNAP_OTHER_NODES);
if (drag_type == DRAG_V_GUIDE) {
String msg;
if (b->get_position().x > ruler_width) { // Add/move a vertical guide.
@@ -242,24 +240,18 @@ bool CanvasItemManipulator::_gui_input_scale(const Ref<InputEvent> &p_event) {
}
Transform2D xform = (Transform2D)global_transform_callback.call() * ci->get_screen_transform();
- Transform2D unscaled_transform = (xform * ci->get_transform().affine_inverse() * edit_transform).orthonormalized();
- Transform2D simple_xform;
- if (local_space) {
- simple_xform = (Transform2D)local_transform_callback.call() * unscaled_transform;
- } else {
- Transform2D translation = Transform2D(0.0f, unscaled_transform.get_origin());
- simple_xform = (Transform2D)local_transform_callback.call() * translation;
- }
+ Transform2D unscaled_xform = (xform * ci->get_transform().affine_inverse() * edit_transform).orthonormalized();
+ Transform2D simple_xform = local_space ? unscaled_xform : Transform2D(0.0f, unscaled_xform.get_origin());
drag_type = DRAG_SCALE_BOTH;
if (show_transformation_gizmos) {
- Size2 scale_factor = Size2(GIZMO_HANDLE_DISTANCE, GIZMO_HANDLE_DISTANCE);
- Rect2 x_handle_rect = Rect2(scale_factor.x * scale, -5 * scale, 10 * scale, 10 * scale);
+ Size2 scale_factor = Size2(GIZMO_HANDLE_DISTANCE, GIZMO_HANDLE_DISTANCE) * scale;
+ Rect2 x_handle_rect = Rect2(Point2(scale_factor.x, GIZMO_HANDLE_X_RECT.position.y * scale), GIZMO_HANDLE_X_RECT.size * scale);
if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) {
drag_type = DRAG_SCALE_X;
}
- Rect2 y_handle_rect = Rect2(-5 * scale, scale_factor.y * scale, 10 * scale, 10 * scale);
+ Rect2 y_handle_rect = Rect2(Point2(GIZMO_HANDLE_Y_RECT.position.x * scale, scale_factor.y), GIZMO_HANDLE_Y_RECT.size * scale);
if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) {
drag_type = DRAG_SCALE_Y;
}
@@ -317,14 +309,14 @@ bool CanvasItemManipulator::_gui_input_scale(const Ref<InputEvent> &p_event) {
for (const Variant &var : drag_selection) {
CanvasItem *ci = Object::cast_to<CanvasItem>(var);
Transform2D parent_xform = ci->get_screen_transform() * ci->get_transform().affine_inverse();
- Transform2D unscaled_transform = ((Transform2D)global_transform_callback.call() * parent_xform * edit_transform).orthonormalized();
- Transform2D simple_xform;
+ Transform2D unscaled_xform = ((Transform2D)global_transform_callback.call() * parent_xform * edit_transform).orthonormalized();
+ Transform2D simple_xform;
if (local_space || drag_type == DRAG_SCALE_BOTH) {
- simple_xform = ((Transform2D)local_transform_callback.call() * unscaled_transform).affine_inverse() * (Transform2D)global_transform_callback.call();
+ simple_xform = (unscaled_xform).affine_inverse() * (Transform2D)global_transform_callback.call();
} else {
- Transform2D translation = Transform2D(0.0f, unscaled_transform.get_origin());
- simple_xform = ((Transform2D)local_transform_callback.call() * translation).affine_inverse() * (Transform2D)global_transform_callback.call();
+ Transform2D translation = Transform2D(0.0f, unscaled_xform.get_origin());
+ simple_xform = (translation).affine_inverse() * (Transform2D)global_transform_callback.call();
}
bool uniform = m->is_shift_pressed();
@@ -447,18 +439,18 @@ bool CanvasItemManipulator::_gui_input_pivot(const Ref<InputEvent> &p_event) {
// Start dragging if we still have nodes.
if (!drag_selection.is_empty()) {
- Vector2 event_pos = b.is_valid() ? b->get_position() : (Point2)local_mouse_pos_callback.call();
+ Vector2 pos = b.is_valid() ? b->get_position() : (Point2)local_mouse_pos_callback.call();
if (move_temp_pivot) {
drag_type = DRAG_TEMP_PIVOT;
- temp_pivot = Transform2D(global_transform_callback.call()).affine_inverse().xform(event_pos);
+ temp_pivot = Transform2D(global_transform_callback.call()).affine_inverse().xform(pos);
emit_signal(update_canvas_signal);
return true;
}
emit_signal("save_canvas_state_requested", drag_selection, false);
- drag_from = Transform2D(global_transform_callback.call()).affine_inverse().xform(event_pos);
- Vector2 new_pos;
+ drag_from = Transform2D(global_transform_callback.call()).affine_inverse().xform(pos);
+ Point2 new_pos;
if (drag_selection.size() == 1) {
const Node2D *n2d = Object::cast_to<Node2D>(drag_selection.front());
new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, n2d);
@@ -489,7 +481,7 @@ bool CanvasItemManipulator::_gui_input_pivot(const Ref<InputEvent> &p_event) {
drag_to = Transform2D(global_transform_callback.call()).affine_inverse().xform(m->get_position());
emit_signal("restore_canvas_state_requested", drag_selection, false);
- Vector2 new_pos;
+ Point2 new_pos;
if (drag_selection.size() == 1) {
const Node2D *n2d = Object::cast_to<Node2D>(drag_selection.front());
new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, n2d);
@@ -849,14 +841,8 @@ bool CanvasItemManipulator::_gui_input_move(const Ref<InputEvent> &p_event) {
CanvasItem *ci = Object::cast_to<CanvasItem>(drag_selection.front());
Transform2D parent_xform = ci->get_screen_transform() * ci->get_transform().affine_inverse();
- Transform2D unscaled_transform = ((Transform2D)global_transform_callback.call() * parent_xform * ci->_edit_get_transform()).orthonormalized();
- Transform2D simple_xform;
- if (local_space) {
- simple_xform = (Transform2D)local_transform_callback.call() * unscaled_transform;
- } else {
- Transform2D translation = Transform2D(0.0f, unscaled_transform.get_origin());
- simple_xform = (Transform2D)local_transform_callback.call() * translation;
- }
+ Transform2D unscaled_xform = ((Transform2D)global_transform_callback.call() * parent_xform * ci->_edit_get_transform()).orthonormalized();
+ Transform2D simple_xform = local_space ? unscaled_xform : Transform2D(0.0f, unscaled_xform.get_origin());
if (show_transformation_gizmos) {
const Rect2 x_handle_rect = Rect2(GIZMO_HANDLE_X_RECT.position * scale, GIZMO_HANDLE_X_RECT.size * scale);
@@ -907,12 +893,7 @@ bool CanvasItemManipulator::_gui_input_move(const Ref<InputEvent> &p_event) {
if (drag_type == DRAG_MOVE_X || drag_type == DRAG_MOVE_Y) {
const CanvasItem *selected = Object::cast_to<CanvasItem>(drag_selection.front());
Transform2D parent_xform = selected->get_screen_transform() * selected->get_transform().affine_inverse();
- Transform2D unscaled_transform = ((Transform2D)global_transform_callback.call() * parent_xform * selected->_edit_get_transform()).orthonormalized();
-
- Transform2D simple_xform = local_transform_callback.call();
- if (local_space) {
- simple_xform *= unscaled_transform;
- }
+ Transform2D simple_xform = local_space ? ((Transform2D)global_transform_callback.call() * parent_xform * selected->_edit_get_transform()).orthonormalized() : Transform2D();
drag_delta = simple_xform.affine_inverse().basis_xform(drag_delta);
if (drag_type == DRAG_MOVE_X) {
@@ -1065,13 +1046,15 @@ bool CanvasItemManipulator::_gui_input_anchors(const Ref<InputEvent> &p_event) {
anchor_pos[3] = Vector2(control->get_anchor(SIDE_LEFT), control->get_anchor(SIDE_BOTTOM));
Rect2 anchor_rects[4];
+ Size2 handle_size = ANCHOR_HANDLE_SIZE * scale;
+
for (int i = 0; i < 4; i++) {
anchor_pos[i] = ((Transform2D)global_transform_callback.call() * control->get_screen_transform()).xform(anchor_to_position(control, anchor_pos[i]));
- anchor_rects[i] = Rect2(anchor_pos[i], ANCHOR_HANDLE_SIZE);
+ anchor_rects[i] = Rect2(anchor_pos[i], handle_size);
if (control->is_layout_rtl()) {
- anchor_rects[i].position -= ANCHOR_HANDLE_SIZE * Vector2(real_t(i == 1 || i == 2), real_t(i <= 1));
+ anchor_rects[i].position -= handle_size * Vector2(real_t(i == 1 || i == 2), real_t(i <= 1));
} else {
- anchor_rects[i].position -= ANCHOR_HANDLE_SIZE * Vector2(real_t(i == 0 || i == 3), real_t(i <= 1));
+ anchor_rects[i].position -= handle_size * Vector2(real_t(i == 0 || i == 3), real_t(i <= 1));
}
}
@@ -1084,7 +1067,7 @@ bool CanvasItemManipulator::_gui_input_anchors(const Ref<InputEvent> &p_event) {
for (int i = 0; i < 4; i++) {
if (anchor_rects[i].has_point(b->get_position())) {
- if ((anchor_pos[0] == anchor_pos[2]) && (anchor_pos[0].distance_to(b->get_position()) < ANCHOR_HANDLE_SIZE.length() / 3.0)) {
+ if ((anchor_pos[0] == anchor_pos[2]) && (anchor_pos[0].distance_to(b->get_position()) < handle_size.length() / 3.0)) {
drag_type = DRAG_ANCHOR_ALL;
} else {
drag_type = dragger[i];
@@ -2101,25 +2084,32 @@ void CanvasItemManipulator::get_canvas_items_at_pos(const Point2 &p_pos, Vector<
void CanvasItemManipulator::find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<DebuggerHelpers::SelectResult> &r_items, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform) {
Transform2D xform = p_canvas_xform;
- Viewport *vp = Object::cast_to<Viewport>(p_node);
- if (CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node)) {
+ CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
+ if (cl) {
if (editor_mode) {
- xform = cl->get_transform();
- }
- } else if (vp) {
- if (!editor_mode && vp != SceneTree::get_singleton()->get_root()) {
- return; // FIXME: Make subviewport selection work at runtime.
+ xform *= cl->get_transform();
}
+ } else {
+ Viewport *vp = Object::cast_to<Viewport>(p_node);
+ if (vp) {
+ if (editor_mode) {
+ if (!vp->is_visible_subviewport()) {
+ return;
+ }
- if (editor_mode && !vp->is_visible_subviewport()) {
- return;
- }
+ xform = vp->get_popup_base_transform();
- xform = vp->get_popup_base_transform();
+ if (!vp->get_visible_rect().has_point(xform.affine_inverse().xform(p_pos))) {
+ return;
+ }
+ } else {
+ if (vp != SceneTree::get_singleton()->get_root()) {
+ return; // FIXME: Make subviewport selection work at runtime.
+ }
- if (editor_mode && !vp->get_visible_rect().has_point(xform.affine_inverse().xform(p_pos))) {
- return;
+ xform = vp->get_popup_base_transform();
+ }
}
}
@@ -2141,22 +2131,19 @@ void CanvasItemManipulator::find_canvas_items_at_pos(const Point2 &p_pos, Node *
return;
}
- if (!ci->is_set_as_top_level()) {
- xform *= p_parent_xform;
- }
-
- Point2 pos = p_pos;
-
// Cameras don't affect `CanvasLayer`s.
// Only check at runtime, as cameras aren't active in the editor.
if (!editor_mode && (!ci->get_canvas_layer_node() || ci->get_canvas_layer_node()->is_following_viewport())) {
- Window *root = SceneTree::get_singleton()->get_root();
- pos = root->get_canvas_transform().affine_inverse().xform(p_pos);
+ xform *= SceneTree::get_singleton()->get_root()->get_canvas_transform();
+ }
+
+ if (!ci->is_set_as_top_level()) {
+ xform *= p_parent_xform;
}
xform = (xform * ci->get_transform()).affine_inverse();
const real_t local_grab_distance = xform.basis_xform(Vector2(grab_distance, 0)).length() / zoom;
- if (ci->_edit_is_selected_on_click(xform.xform(pos), local_grab_distance)) {
+ if (ci->_edit_is_selected_on_click(xform.xform(p_pos), local_grab_distance)) {
DebuggerHelpers::SelectResult res;
res.item = ci;
res.order = ci->get_effective_z_index() + ci->get_canvas_layer();
@@ -2170,25 +2157,32 @@ void CanvasItemManipulator::find_canvas_items_in_rect(const Rect2 &p_rect, Node
}
Transform2D xform = p_canvas_xform;
- Viewport *vp = Object::cast_to<Viewport>(p_node);
+ CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
- if (CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node)) {
+ if (cl) {
if (editor_mode) {
xform = cl->get_transform();
}
- } else if (vp) {
- if (!editor_mode && vp != SceneTree::get_singleton()->get_root()) {
- return; // FIXME: Make subviewport selection work at runtime.
- }
+ } else {
+ Viewport *vp = Object::cast_to<Viewport>(p_node);
+ if (vp) {
+ if (editor_mode) {
+ if (!vp->is_visible_subviewport()) {
+ return;
+ }
- if (editor_mode && !vp->is_visible_subviewport()) {
- return;
- }
+ xform = vp->get_popup_base_transform();
- xform = vp->get_popup_base_transform();
+ if (!vp->get_visible_rect().intersects(xform.affine_inverse().xform(p_rect))) {
+ return;
+ }
+ } else {
+ if (vp != SceneTree::get_singleton()->get_root()) {
+ return; // FIXME: Make subviewport selection work at runtime.
+ }
- if (editor_mode && !vp->get_visible_rect().intersects(xform.affine_inverse().xform(p_rect))) {
- return;
+ xform = vp->get_popup_base_transform();
+ }
}
}
@@ -2210,13 +2204,12 @@ void CanvasItemManipulator::find_canvas_items_in_rect(const Rect2 &p_rect, Node
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
if (ci) {
if (!ci->is_set_as_top_level()) {
- find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, p_parent_xform * ci->get_transform(), p_canvas_xform);
+ find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, p_parent_xform * ci->get_transform(), xform);
} else {
- find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, ci->get_transform(), p_canvas_xform);
+ find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, ci->get_transform(), xform);
}
} else {
- CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
- find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, Transform2D(), cl ? cl->get_transform() : p_canvas_xform);
+ find_canvas_items_in_rect(p_rect, p_node->get_child(i), r_items, Transform2D(), xform);
}
}
}
@@ -2225,29 +2218,27 @@ void CanvasItemManipulator::find_canvas_items_in_rect(const Rect2 &p_rect, Node
return;
}
- if (!ci->is_set_as_top_level()) {
- xform *= p_parent_xform;
- }
- xform *= ci->get_transform();
-
- Rect2 rect = p_rect;
// Cameras don't affect `CanvasLayer`s.
// Only check at runtime, as cameras aren't active in the editor.
if (!editor_mode && (!ci->get_canvas_layer_node() || ci->get_canvas_layer_node()->is_following_viewport())) {
- Window *root = SceneTree::get_singleton()->get_root();
- rect = root->get_canvas_transform().affine_inverse().xform(p_rect);
+ xform *= SceneTree::get_singleton()->get_root()->get_canvas_transform();
}
+ if (!ci->is_set_as_top_level()) {
+ xform *= p_parent_xform;
+ }
+ xform *= ci->get_transform();
+
bool selected = false;
if (ci->_edit_use_rect()) {
Rect2 ci_rect = xform.xform(ci->_edit_get_rect());
- if (rect.has_point(ci_rect.position) &&
- rect.has_point(ci_rect.position + Vector2(ci_rect.size.x, 0)) &&
- rect.has_point(ci_rect.position + Vector2(ci_rect.size.x, ci_rect.size.y)) &&
- rect.has_point(ci_rect.position + Vector2(0, ci_rect.size.y))) {
+ if (p_rect.has_point(ci_rect.position) &&
+ p_rect.has_point(ci_rect.position + Vector2(ci_rect.size.x, 0)) &&
+ p_rect.has_point(ci_rect.position + Vector2(ci_rect.size.x, ci_rect.size.y)) &&
+ p_rect.has_point(ci_rect.position + Vector2(0, ci_rect.size.y))) {
selected = true;
}
- } else if (rect.has_point(xform.xform(Point2()))) {
+ } else if (p_rect.has_point(xform.xform(Point2()))) {
selected = true;
}
@@ -2296,13 +2287,12 @@ void CanvasItemManipulator::set_tool(Tool p_tool) {
tool = p_tool;
}
-void CanvasItemManipulator::set_callbacks(const Callable &p_find_items_start, const Callable &p_point_selected, const Callable &p_get_selection, const Callable &p_local_xform, const Callable &p_global_xform, const Callable &p_local_mouse_pos, const Callable &p_plugin_input) {
+void CanvasItemManipulator::set_callbacks(const Callable &p_find_items_start, const Callable &p_point_selected, const Callable &p_get_selection, const Callable &p_global_xform, const Callable &p_local_mouse_pos, const Callable &p_plugin_input) {
find_items_start_callback = p_find_items_start;
point_selected_callback = p_point_selected;
get_selection_callback = p_get_selection;
global_transform_callback = p_global_xform;
#ifdef TOOLS_ENABLED
- local_transform_callback = p_local_xform;
local_mouse_pos_callback = p_local_mouse_pos;
plugin_input_callback = p_plugin_input;
#endif
diff --git a/scene/debugger/canvas_item_manipulator.h b/scene/debugger/canvas_item_manipulator.h
index a96d32ec116..bea2cf4bc9d 100644
--- a/scene/debugger/canvas_item_manipulator.h
+++ b/scene/debugger/canvas_item_manipulator.h
@@ -200,7 +200,6 @@ private:
HashMap<int, Ref<Shortcut>> inputs;
- Callable local_transform_callback;
Callable local_mouse_pos_callback;
Callable plugin_input_callback;
@@ -261,7 +260,7 @@ public:
void set_view_offset(const Point2 p_offset) { view_offset = p_offset; }
void set_viewport(Viewport *p_viewport) { viewport = p_viewport; }
- void set_callbacks(const Callable &p_find_items_start, const Callable &p_point_selected, const Callable &p_get_selection, const Callable &p_local_xform, const Callable &p_global_xform, const Callable &p_local_mouse_pos, const Callable &p_plugin_input);
+ void set_callbacks(const Callable &p_find_items_start, const Callable &p_point_selected, const Callable &p_get_selection, const Callable &p_global_xform, const Callable &p_local_mouse_pos, const Callable &p_plugin_input);
static bool is_node_locked(const Node *p_node);
diff --git a/scene/debugger/runtime_node_select.cpp b/scene/debugger/runtime_node_select.cpp
index c27be1b8ba9..40ae7c540f8 100644
--- a/scene/debugger/runtime_node_select.cpp
+++ b/scene/debugger/runtime_node_select.cpp
@@ -33,7 +33,6 @@
#include "runtime_node_select.h"
#include "core/config/engine.h"
-#include "core/config/project_settings.h"
#include "core/debugger/debugger_marshalls.h"
#include "core/debugger/engine_debugger.h"
#include "core/input/input.h"
@@ -95,7 +94,13 @@ void RuntimeNodeSelect::_setup(const Dictionary &p_settings) {
root->connect("size_changed", callable_mp(this, &RuntimeNodeSelect::_queue_selection_update), CONNECT_DEFERRED);
max_selection = p_settings.get("debugger/max_node_selection", 1);
- scale = GLOBAL_GET("display/window/stretch/scale");
+
+ float editor_scale = p_settings.get("editor_scale", 1);
+ scale = root->get_content_scale_factor();
+ if (root->get_content_scale_stretch() == Window::CONTENT_SCALE_STRETCH_INTEGER) {
+ scale = Math::floor(scale);
+ }
+ scale = editor_scale / scale;
#ifdef TOOLS_ENABLED
accent_color = p_settings.get("accent_color", Color());
@@ -125,14 +130,13 @@ void RuntimeNodeSelect::_setup(const Dictionary &p_settings) {
ci_manipulator.instantiate();
ci_manipulator->set_grab_distance(p_settings.get("editors/polygon_editor/point_grab_radius", 1));
- ci_manipulator->set_scale(scale);
+ ci_manipulator->set_scale(editor_scale); // No need to take the view scale into account.
ci_manipulator->set_viewport(root);
ci_manipulator->set_callbacks(
callable_mp(this, &RuntimeNodeSelect::_find_ci_start_callback),
callable_mp(this, &RuntimeNodeSelect::_point_selected_ci_callback),
callable_mp(this, &RuntimeNodeSelect::_get_selection_ci_callback),
- callable_mp(this, &RuntimeNodeSelect::_local_transform_callback),
- callable_mp((Viewport *)root, &Viewport::get_screen_transform),
+ callable_mp(this, &RuntimeNodeSelect::_global_transform_callback),
callable_mp(this, &RuntimeNodeSelect::_local_mouse_pos_callback),
callable_mp(this, &RuntimeNodeSelect::_plugin_input_callback));
@@ -156,8 +160,6 @@ void RuntimeNodeSelect::_setup(const Dictionary &p_settings) {
/// 2D Selection Rectangle Generation
- sel_2d_scale = MAX(1, Math::ceil(2.0 / scale));
-
selection_area_fill = p_settings.get("box_selection_fill_color", Color());
selection_area_outline = p_settings.get("box_selection_stroke_color", Color());
@@ -407,9 +409,14 @@ bool RuntimeNodeSelect::_get_selection_ci_callback(Array r_selection) {
return has_locked_items;
}
+Transform2D RuntimeNodeSelect::_global_transform_callback() const {
+ Window *root = SceneTree::get_singleton()->get_root();
+ return root->get_screen_transform() * root->get_popup_base_transform().affine_inverse();
+}
+
Point2 RuntimeNodeSelect::_local_mouse_pos_callback() const {
Window *root = SceneTree::get_singleton()->get_root();
- return root->get_screen_transform().affine_inverse().xform(root->get_mouse_position());
+ return root->get_screen_transform().xform(root->get_mouse_position());
}
void RuntimeNodeSelect::_root_window_input(const Ref<InputEvent> &p_event) {
@@ -529,12 +536,6 @@ void RuntimeNodeSelect::_root_window_input(const Ref<InputEvent> &p_event) {
bool was_input_disabled = Input::get_singleton()->is_input_disabled();
Input::get_singleton()->set_disable_input(false);
- Ref<InputEventMouse> me = p_event;
- if (me.is_valid()) {
- // Offset the mouse position by the embedding's transform.
- me->set_position(root->get_popup_base_transform().xform(me->get_position()));
- }
-
if (!ci_manipulator->gui_input(p_event)) {
// Remind the user to enable the camera override when panning.
if (!camera_override && ci_manipulator->get_tool() == CanvasItemManipulator::TOOL_PAN && b.is_valid() && b->is_pressed()) {
@@ -1112,7 +1113,7 @@ void RuntimeNodeSelect::_update_selection() {
Color color = item_locked ? srect_locked_color : srect_color;
for (int i = 0; i < 4; i++) {
- RS::get_singleton()->canvas_item_add_line(srect_ci, endpoints[i], endpoints[(i + 1) % 4], color, sel_2d_scale);
+ RS::get_singleton()->canvas_item_add_line(srect_ci, endpoints[i], endpoints[(i + 1) % 4], color, MAX(1, Math::round(2.0 * scale)));
}
}
@@ -1150,9 +1151,9 @@ void RuntimeNodeSelect::_update_selection() {
Transform2D xform_unscaled = (ci->get_global_transform_with_canvas() * ci->get_transform().affine_inverse() * edit_xform).orthonormalized();
Transform2D simple_xform;
if (ci_manipulator->is_local_space_enabled()) {
- simple_xform *= xform_unscaled;
+ simple_xform = xform_unscaled;
} else {
- simple_xform *= Transform2D(0.0f, xform_unscaled.get_origin());
+ simple_xform = Transform2D(0.0f, xform_unscaled.get_origin());
}
RS::get_singleton()->canvas_item_add_set_transform(srect_ci, simple_xform);
@@ -1160,31 +1161,33 @@ void RuntimeNodeSelect::_update_selection() {
// Move Handles
if (is_moving) {
+ Rect2 handle_x_rect(CanvasItemManipulator::GIZMO_HANDLE_X_RECT.position * scale, CanvasItemManipulator::GIZMO_HANDLE_X_RECT.size * scale);
Vector<Point2> points = {
- Point2(CanvasItemManipulator::GIZMO_HANDLE_X_RECT.position.x, CanvasItemManipulator::GIZMO_HANDLE_X_RECT.size.height / 2.0),
- Point2(CanvasItemManipulator::GIZMO_HANDLE_X_RECT.position.x, -CanvasItemManipulator::GIZMO_HANDLE_X_RECT.size.height / 2.0),
- Point2(CanvasItemManipulator::GIZMO_HANDLE_X_RECT.position.x + CanvasItemManipulator::GIZMO_HANDLE_X_RECT.size.width, 0)
+ Point2(handle_x_rect.position.x, handle_x_rect.size.height / 2.0),
+ Point2(handle_x_rect.position.x, -handle_x_rect.size.height / 2.0),
+ Point2(handle_x_rect.position.x + handle_x_rect.size.width, 0)
};
Vector<Color> colors = { axis_x_color };
RS::get_singleton()->canvas_item_add_polygon(srect_ci, points, colors);
- RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(CanvasItemManipulator::GIZMO_HANDLE_DISTANCE, 0), axis_x_color, scale);
+ RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(CanvasItemManipulator::GIZMO_HANDLE_DISTANCE * scale, 0), axis_x_color, MAX(1, scale));
+ Rect2 handle_y_rect(CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.position * scale, CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.size * scale);
points = {
- Point2(CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.size.width / 2.0, CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.position.y),
- Point2(-CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.size.width / 2.0, CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.position.y),
- Point2(0, CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.position.y + CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.size.height)
+ Point2(handle_y_rect.size.width / 2.0, handle_y_rect.position.y),
+ Point2(-handle_y_rect.size.width / 2.0, handle_y_rect.position.y),
+ Point2(0, handle_y_rect.position.y + handle_y_rect.size.height)
};
colors = { axis_y_color };
RS::get_singleton()->canvas_item_add_polygon(srect_ci, points, colors);
- RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(0, CanvasItemManipulator::GIZMO_HANDLE_DISTANCE), axis_y_color, scale);
+ RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(0, CanvasItemManipulator::GIZMO_HANDLE_DISTANCE), axis_y_color, MAX(1, scale));
}
// Scale Handles
if (tool == CanvasItemManipulator::TOOL_SCALE || drag == CanvasItemManipulator::DRAG_SCALE_X || drag == CanvasItemManipulator::DRAG_SCALE_Y || (tool == CanvasItemManipulator::TOOL_SELECT && is_alt && is_ctrl)) {
- Size2 scale_factor(CanvasItemManipulator::GIZMO_HANDLE_DISTANCE, CanvasItemManipulator::GIZMO_HANDLE_DISTANCE);
+ Size2 scale_factor(CanvasItemManipulator::GIZMO_HANDLE_DISTANCE * scale, CanvasItemManipulator::GIZMO_HANDLE_DISTANCE * scale);
bool uniform = Input::get_singleton()->is_key_pressed(Key::SHIFT);
Point2 offset = simple_xform.affine_inverse().xform(ci_manipulator->get_drag_to()) - simple_xform.affine_inverse().xform(ci_manipulator->get_drag_from());
@@ -1200,33 +1203,35 @@ void RuntimeNodeSelect::_update_selection() {
}
}
- Rect2 handle_x_rect(Point2(scale_factor.x, CanvasItemManipulator::GIZMO_HANDLE_X_RECT.position.y), CanvasItemManipulator::GIZMO_HANDLE_X_RECT.size);
+ Rect2 handle_x_rect(Point2(scale_factor.x, CanvasItemManipulator::GIZMO_HANDLE_X_RECT.position.y * scale), CanvasItemManipulator::GIZMO_HANDLE_X_RECT.size * scale);
RS::get_singleton()->canvas_item_add_rect(srect_ci, handle_x_rect, axis_x_color);
- RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(scale_factor.x, 0), axis_x_color, scale);
+ RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(scale_factor.x, 0), axis_x_color, MAX(1, scale));
- Rect2 handle_y_rect(Point2(CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.position.x, scale_factor.y), CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.size);
+ Rect2 handle_y_rect(Point2(CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.position.x * scale, scale_factor.y), CanvasItemManipulator::GIZMO_HANDLE_Y_RECT.size * scale);
RS::get_singleton()->canvas_item_add_rect(srect_ci, handle_y_rect, axis_y_color);
- RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(0, scale_factor.y), axis_y_color, scale);
+ RS::get_singleton()->canvas_item_add_line(srect_ci, Point2(), Point2(0, scale_factor.y), axis_y_color, MAX(1, scale));
}
Input::get_singleton()->set_disable_input(was_input_disabled);
}
}
- // Compensate the mouse position offset from the embedding.
+ // Compensate the offset from the embedding.
RS::get_singleton()->canvas_item_add_set_transform(srect_ci, SceneTree::get_singleton()->get_root()->get_popup_base_transform().affine_inverse());
// Rotation Line
if (drag == CanvasItemManipulator::DRAG_ROTATE) {
- RS::get_singleton()->canvas_item_add_line(srect_ci, ci_manipulator->get_drag_rotation_center(), ci_manipulator->get_drag_to(), accent_color * Color(1, 1, 1, 0.6), 2 * scale);
+ RS::get_singleton()->canvas_item_add_line(srect_ci, ci_manipulator->get_drag_rotation_center(), ci_manipulator->get_drag_to(), accent_color * Color(1, 1, 1, 0.6), MAX(1, 2 * scale));
}
+ RS::get_singleton()->canvas_item_add_set_transform(srect_ci, SceneTree::get_singleton()->get_root()->get_canvas_transform());
+
// Temporary Pivot
if (!Math::is_inf(temp_pivot.x) && !Math::is_inf(temp_pivot.y)) {
Size2 pivot_size = pivot_icon->get_size() * scale;
- Rect2 rect(((temp_pivot - view_2d_offset) * view_2d_zoom - (pivot_size / 2.0)).floor(), pivot_size);
+ Rect2 rect((temp_pivot - (pivot_size / 2.0)).floor(), pivot_size);
RS::get_singleton()->canvas_item_add_texture_rect(srect_ci, rect, pivot_icon->get_rid(), false, accent_color);
}
@@ -1375,15 +1380,18 @@ void RuntimeNodeSelect::_set_selection_area(const Rect2 &p_area) {
return;
}
+ // Compensate the offset from the embedding.
+ Rect2 area = SceneTree::get_singleton()->get_root()->get_popup_base_transform().affine_inverse().xform(p_area);
+
const Vector2 endpoints[4] = {
- p_area.position,
- p_area.position + Point2(p_area.size.x, 0),
- p_area.position + p_area.size,
- p_area.position + Point2(0, p_area.size.y)
+ area.position,
+ area.position + Point2(area.size.x, 0),
+ area.position + area.size,
+ area.position + Point2(0, area.size.y)
};
// Draw fill.
- RS::get_singleton()->canvas_item_add_rect(sel_drag_ci, p_area, selection_area_fill);
+ RS::get_singleton()->canvas_item_add_rect(sel_drag_ci, area, selection_area_fill);
// Draw outline.
for (int i = 0; i < 4; i++) {
RS::get_singleton()->canvas_item_add_line(sel_drag_ci, endpoints[i], endpoints[(i + 1) % 4], selection_area_outline, 1);
diff --git a/scene/debugger/runtime_node_select.h b/scene/debugger/runtime_node_select.h
index 35e3d613502..f1b4a4827d8 100644
--- a/scene/debugger/runtime_node_select.h
+++ b/scene/debugger/runtime_node_select.h
@@ -125,7 +125,6 @@ private:
#endif
HashMap<ObjectID, Dictionary> selected_ci_nodes; // The node's ID and its canvas state.
- int sel_2d_scale = 1;
Color srect_color;
Color srect_locked_color;
@@ -210,7 +209,7 @@ private:
Variant _find_ci_start_callback() const;
bool _point_selected_ci_callback(const Variant &p_node, bool p_append);
bool _get_selection_ci_callback(Array r_selection);
- Transform2D _local_transform_callback() const { return Transform2D(); }
+ Transform2D _global_transform_callback() const;
Point2 _local_mouse_pos_callback() const;
bool _plugin_input_callback(const Ref<InputEvent> &p_event) { return false; }