summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-06-13 15:10:24 +0200
committerGitHub <noreply@github.com>2018-06-13 15:10:24 +0200
commit9c2de8ae2d80cfcc082ef88bd3894c900531a409 (patch)
tree786f9510b28fca9cd2ea40072f942d251eefc3be /editor
parentcca0b8cb03f96a18e28354f22f450e0aaeb46e91 (diff)
parent71cea6b5159ce4e11cc350ff3b0cdcfdcd00d2fd (diff)
Merge pull request #19516 from groud/fix_crash_on_hover
Fixes a crash on draw_hover
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp86
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h10
2 files changed, 57 insertions, 39 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 13a9a84de1..0f46f7f004 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -1983,32 +1983,53 @@ bool CanvasItemEditor::_gui_input_hover(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
- if (drag_type == DRAG_NONE && tool == TOOL_SELECT) {
- Point2 click = transform.affine_inverse().xform(m->get_position());
-
- //Checks if the hovered items changed, update the viewport if so
- Vector<_SelectResult> hovering_results_tmp;
- _get_canvas_items_at_pos(click, hovering_results_tmp);
- hovering_results_tmp.sort();
- bool changed = false;
- if (hovering_results.size() == hovering_results_tmp.size()) {
- for (int i = 0; i < hovering_results.size(); i++) {
- if (hovering_results[i].item != hovering_results_tmp[i].item) {
- changed = true;
- break;
- }
- }
- } else {
- changed = true;
- }
+ Point2 click = transform.affine_inverse().xform(m->get_position());
- if (changed) {
- hovering_results = hovering_results_tmp;
- viewport->update();
+ // Checks if the hovered items changed, update the viewport if so
+ Vector<_SelectResult> hovering_results_items;
+ _get_canvas_items_at_pos(click, hovering_results_items);
+ hovering_results_items.sort();
+
+ // Compute the nodes names and icon position
+ Vector<_HoverResult> hovering_results_tmp;
+ for (int i = 0; i < hovering_results_items.size(); i++) {
+ CanvasItem *canvas_item = hovering_results_items[i].item;
+
+ if (canvas_item->_edit_use_rect())
+ continue;
+
+ _HoverResult hover_result;
+ hover_result.position = canvas_item->get_global_transform_with_canvas().get_origin();
+ if (has_icon(canvas_item->get_class(), "EditorIcons"))
+ hover_result.icon = get_icon(canvas_item->get_class(), "EditorIcons");
+ else
+ hover_result.icon = get_icon("Object", "EditorIcons");
+ hover_result.name = canvas_item->get_name();
+
+ hovering_results_tmp.push_back(hover_result);
+ }
+
+ // Check if changed, if so, update.
+ bool changed = false;
+ if (hovering_results_tmp.size() == hovering_results.size()) {
+ for (int i = 0; i < hovering_results_tmp.size(); i++) {
+ _HoverResult a = hovering_results_tmp[i];
+ _HoverResult b = hovering_results[i];
+ if (a.icon != b.icon || a.name != b.name || a.position != b.position) {
+ changed = true;
+ break;
+ }
}
+ } else {
+ changed = true;
+ }
- return true;
+ if (changed) {
+ hovering_results = hovering_results_tmp;
+ viewport->update();
}
+
+ return true;
}
return false;
@@ -2769,26 +2790,15 @@ void CanvasItemEditor::_draw_hover() {
List<Rect2> previous_rects;
for (int i = 0; i < hovering_results.size(); i++) {
- // Draw the node's name and icon
- CanvasItem *canvas_item = hovering_results[i].item;
-
- if (canvas_item->_edit_use_rect())
- continue;
- Transform2D xform = transform * canvas_item->get_global_transform_with_canvas();
+ Ref<Texture> node_icon = hovering_results[i].icon;
+ String node_name = hovering_results[i].name;
- // Get the resources
- Ref<Texture> node_icon;
- if (has_icon(canvas_item->get_class(), "EditorIcons"))
- node_icon = get_icon(canvas_item->get_class(), "EditorIcons");
- else
- node_icon = get_icon("Object", "EditorIcons");
Ref<Font> font = get_font("font", "Label");
- String node_name = canvas_item->get_name();
Size2 node_name_size = font->get_string_size(node_name);
Size2 item_size = Size2(node_icon->get_size().x + 4 + node_name_size.x, MAX(node_icon->get_size().y, node_name_size.y - 3));
- Point2 pos = xform.get_origin() - Point2(0, item_size.y) + (Point2(node_icon->get_size().x, -node_icon->get_size().y) / 4);
+ Point2 pos = transform.xform(hovering_results[i].position) - Point2(0, item_size.y) + (Point2(node_icon->get_size().x, -node_icon->get_size().y) / 4);
// Rectify the position to avoid overlaping items
for (List<Rect2>::Element *E = previous_rects.front(); E; E = E->next()) {
if (E->get().intersects(Rect2(pos, item_size))) {
@@ -2798,8 +2808,10 @@ void CanvasItemEditor::_draw_hover() {
previous_rects.push_back(Rect2(pos, item_size));
- // Draw the node icon and name
+ // Draw icon
viewport->draw_texture(node_icon, pos, Color(1.0, 1.0, 1.0, 0.5));
+
+ // Draw name
viewport->draw_string(font, pos + Point2(node_icon->get_size().x + 4, item_size.y - 3), node_name, Color(1.0, 1.0, 1.0, 0.5));
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 4d2af11303..adc4010f39 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -257,9 +257,15 @@ class CanvasItemEditor : public VBoxContainer {
return has_z && p_rr.has_z ? p_rr.z_index < z_index : p_rr.has_z;
}
};
-
Vector<_SelectResult> selection_results;
- Vector<_SelectResult> hovering_results;
+
+ struct _HoverResult {
+
+ Point2 position;
+ Ref<Texture> icon;
+ String name;
+ };
+ Vector<_HoverResult> hovering_results;
struct BoneList {