Displays node icon on hover

This commit is contained in:
Gilles Roudiere 2018-03-12 23:32:25 +01:00
parent 0251b08afa
commit a724f34ef3
4 changed files with 217 additions and 8 deletions

View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
version="1.1"
viewBox="0 0 16 16"
id="svg919"
sodipodi:docname="icon_editor_position.svg"
inkscape:version="0.92.2 5c3e80d, 2017-08-06">
<metadata
id="metadata925">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs923" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2550"
inkscape:window-height="1414"
id="namedview921"
showgrid="false"
inkscape:zoom="64"
inkscape:cx="13.492036"
inkscape:cy="5.8518769"
inkscape:window-x="1370"
inkscape:window-y="20"
inkscape:window-maximized="0"
inkscape:current-layer="svg919"
inkscape:snap-page="true" />
<g
id="g6479">
<path
id="path913"
d="M 6 0 L 6 4.4199219 A 4.2661548 4.0576186 0 0 0 4.2910156 6 L 0 6 L 0 10 L 4.2949219 10 A 4.2661548 4.0576186 0 0 0 6 11.582031 L 6 16 L 10 16 L 10 11.580078 A 4.2661548 4.0576186 0 0 0 11.708984 10 L 16 10 L 16 6 L 11.705078 6 A 4.2661548 4.0576186 0 0 0 10 4.4179688 L 10 0 L 6 0 z "
style="fill:#ffffff;fill-opacity:0.70588237" />
<path
id="path915"
d="M 7 1 L 7 4.0605469 A 4.2661548 4.0576186 0 0 1 8 3.9414062 A 4.2661548 4.0576186 0 0 1 9 4.0605469 L 9 1 L 7 1 z M 1 7 L 1 9 L 3.8691406 9 A 4.2661548 4.0576186 0 0 1 3.734375 8 A 4.2661548 4.0576186 0 0 1 3.8710938 7 L 1 7 z M 12.130859 7 A 4.2661548 4.0576186 0 0 1 12.265625 8 A 4.2661548 4.0576186 0 0 1 12.128906 9 L 15 9 L 15 7 L 12.130859 7 z M 7 11.939453 L 7 15 L 9 15 L 9 11.939453 A 4.2661548 4.0576186 0 0 1 8 12.058594 A 4.2661548 4.0576186 0 0 1 7 11.939453 z "
style="fill:#ff8484;stroke:none;fill-opacity:1" />
<circle
id="circle1517"
r="2.9201488"
cy="8"
cx="8"
style="fill:#ff8484;fill-opacity:1;stroke-width:0.97338283" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
version="1.1"
viewBox="0 0 16 16"
id="svg919"
sodipodi:docname="icon_editor_position_unselected.svg"
inkscape:version="0.92.2 5c3e80d, 2017-08-06">
<metadata
id="metadata925">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs923" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2550"
inkscape:window-height="1414"
id="namedview921"
showgrid="false"
inkscape:zoom="64"
inkscape:cx="13.492036"
inkscape:cy="8.3518769"
inkscape:window-x="1370"
inkscape:window-y="20"
inkscape:window-maximized="0"
inkscape:current-layer="svg919"
inkscape:snap-page="true" />
<path
style="fill:#000000;fill-opacity:0.41077441"
d="M 6 0 L 6 4.4199219 A 4.2661548 4.0576186 0 0 0 4.2910156 6 L 0 6 L 0 10 L 4.2949219 10 A 4.2661548 4.0576186 0 0 0 6 11.582031 L 6 16 L 10 16 L 10 11.580078 A 4.2661548 4.0576186 0 0 0 11.708984 10 L 16 10 L 16 6 L 11.705078 6 A 4.2661548 4.0576186 0 0 0 10 4.4179688 L 10 0 L 6 0 z "
id="path913" />
<path
style="fill:#d9d9d9;stroke:none;fill-opacity:1"
d="M 7 1 L 7 4.0605469 A 4.2661548 4.0576186 0 0 1 8 3.9414062 A 4.2661548 4.0576186 0 0 1 9 4.0605469 L 9 1 L 7 1 z M 1 7 L 1 9 L 3.8691406 9 A 4.2661548 4.0576186 0 0 1 3.734375 8 A 4.2661548 4.0576186 0 0 1 3.8710938 7 L 1 7 z M 12.130859 7 A 4.2661548 4.0576186 0 0 1 12.265625 8 A 4.2661548 4.0576186 0 0 1 12.128906 9 L 15 9 L 15 7 L 12.130859 7 z M 7 11.939453 L 7 15 L 9 15 L 9 11.939453 A 4.2661548 4.0576186 0 0 1 8 12.058594 A 4.2661548 4.0576186 0 0 1 7 11.939453 z "
id="path915" />
<circle
style="fill:#d9d9d9;fill-opacity:1;stroke-width:0.97338283"
cx="8"
cy="8"
r="2.9201488"
id="circle1517" />
</svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -466,13 +466,14 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no
const real_t grab_distance = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
if (p_node->get_owner() != editor->get_edited_scene() || !p_node->has_meta("_edit_lock_")) {
Node *scene = editor->get_edited_scene();
if (!(p_node != scene && p_node->get_owner() != scene && (!scene->is_editable_instance(p_node) || p_node->has_meta("_edit_lock_")))) {
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
if (canvas_item && !canvas_item->is_set_as_toplevel()) {
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, 0, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, limit, p_parent_xform * canvas_item->get_transform(), p_canvas_xform);
} else {
CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, 0, Transform2D(), cl ? cl->get_transform() : p_canvas_xform);
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), r_items, limit, Transform2D(), cl ? cl->get_transform() : p_canvas_xform);
}
if (limit != 0 && r_items.size() >= limit)
return;
@ -1850,6 +1851,42 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
return false;
}
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());
Node *scene = editor->get_edited_scene();
//Checks if the hovered items changed, update the viewport if so
Vector<_SelectResult> hovering_results_tmp;
_find_canvas_items_at_pos(click, scene, 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;
}
if (changed) {
hovering_results = hovering_results_tmp;
viewport->update();
}
return true;
}
}
return false;
}
void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
bool accepted = false;
if ((accepted = _gui_input_rulers_and_guides(p_event))) {
@ -1877,6 +1914,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
if (accepted)
accept_event();
// Handles the mouse hovering
_gui_input_hover(p_event);
// Change the cursor
CursorShape c = CURSOR_ARROW;
switch (drag_type) {
@ -2578,7 +2618,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
ERR_FAIL_COND(!p_node);
Node *scene = editor->get_edited_scene();
if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node->get_owner()))
if (p_node != scene && p_node->get_owner() != scene && !scene->is_editable_instance(p_node))
return;
CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node);
if (canvas_item && !canvas_item->is_visible())
@ -2602,21 +2642,51 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
if (canvas_item && !canvas_item->_edit_use_rect() && !editor_selection->is_selected(canvas_item)) {
Transform2D xform = transform * canvas_xform * parent_xform;
Ref<Texture> position_icon = get_icon("EditorPivot", "EditorIcons");
// Draw the node's position
Ref<Texture> position_icon = get_icon("EditorPositionUnselected", "EditorIcons");
Transform2D transform = Transform2D(xform.get_rotation(), xform.get_origin());
viewport->draw_set_transform_matrix(transform);
viewport->draw_texture(position_icon, -position_icon->get_size() / 2, Color(1.0, 1.0, 1.0, 0.5));
viewport->draw_set_transform_matrix(Transform2D());
}
}
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();
// 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");
viewport->draw_texture(node_icon, xform.get_origin() + position_icon->get_size() / 3, Color(1.0, 1.0, 1.0, 0.5));
Ref<Font> font = get_font("font", "Label");
viewport->draw_string(font, xform.get_origin() + position_icon->get_size() / 3 + node_icon->get_size() + Point2(4, -3), canvas_item->get_name(), Color(1.0, 1.0, 1.0, 0.5));
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);
// 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))) {
pos.y = E->get().get_position().y - item_size.y;
}
}
previous_rects.push_back(Rect2(pos, item_size));
// Draw the node icon and name
viewport->draw_texture(node_icon, pos, Color(1.0, 1.0, 1.0, 0.5));
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));
}
}
@ -2747,6 +2817,7 @@ void CanvasItemEditor::_draw_viewport() {
if (show_guides)
_draw_guides();
_draw_focus();
_draw_hover();
}
void CanvasItemEditor::_notification(int p_what) {

View file

@ -258,6 +258,7 @@ class CanvasItemEditor : public VBoxContainer {
};
Vector<_SelectResult> selection_results;
Vector<_SelectResult> hovering_results;
struct BoneList {
@ -389,6 +390,7 @@ class CanvasItemEditor : public VBoxContainer {
void _draw_bones();
void _draw_invisible_nodes_positions(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
void _draw_locks_and_groups(Node *p_node, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D());
void _draw_hover();
void _draw_viewport();
@ -401,6 +403,7 @@ class CanvasItemEditor : public VBoxContainer {
bool _gui_input_select(const Ref<InputEvent> &p_event);
bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event);
bool _gui_input_rulers_and_guides(const Ref<InputEvent> &p_event);
bool _gui_input_hover(const Ref<InputEvent> &p_event);
void _gui_input_viewport(const Ref<InputEvent> &p_event);