Merge pull request #28435 from YeldhamDev/editorpath_menubutton_change
Make 'EditorPath' into a proper 'MenuButton'
This commit is contained in:
commit
3b509a9c53
@ -56,58 +56,28 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) {
|
|||||||
|
|
||||||
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj);
|
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj);
|
||||||
|
|
||||||
int index = popup->get_item_count();
|
int index = get_popup()->get_item_count();
|
||||||
popup->add_icon_item(icon, E->get().name.capitalize(), objects.size());
|
get_popup()->add_icon_item(icon, E->get().name.capitalize(), objects.size());
|
||||||
popup->set_item_h_offset(index, p_depth * 10 * EDSCALE);
|
get_popup()->set_item_h_offset(index, p_depth * 10 * EDSCALE);
|
||||||
objects.push_back(obj->get_instance_id());
|
objects.push_back(obj->get_instance_id());
|
||||||
|
|
||||||
_add_children_to_popup(obj, p_depth + 1);
|
_add_children_to_popup(obj, p_depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorPath::_gui_input(const Ref<InputEvent> &p_event) {
|
void EditorPath::_about_to_show() {
|
||||||
|
|
||||||
Ref<InputEventMouseButton> mb = p_event;
|
|
||||||
if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
|
|
||||||
|
|
||||||
Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1));
|
Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1));
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
objects.clear();
|
objects.clear();
|
||||||
popup->clear();
|
get_popup()->clear();
|
||||||
|
get_popup()->set_size(Size2(get_size().width, 1));
|
||||||
_add_children_to_popup(obj);
|
_add_children_to_popup(obj);
|
||||||
popup->set_position(get_global_position() + Vector2(0, get_size().height));
|
|
||||||
popup->set_size(Size2(get_size().width, 1));
|
|
||||||
popup->popup();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorPath::_notification(int p_what) {
|
void EditorPath::update_path() {
|
||||||
|
|
||||||
switch (p_what) {
|
|
||||||
|
|
||||||
case NOTIFICATION_MOUSE_ENTER: {
|
|
||||||
mouse_over = true;
|
|
||||||
update();
|
|
||||||
} break;
|
|
||||||
case NOTIFICATION_MOUSE_EXIT: {
|
|
||||||
mouse_over = false;
|
|
||||||
update();
|
|
||||||
} break;
|
|
||||||
case NOTIFICATION_DRAW: {
|
|
||||||
|
|
||||||
RID ci = get_canvas_item();
|
|
||||||
Ref<Font> label_font = get_font("font", "Label");
|
|
||||||
Size2i size = get_size();
|
|
||||||
Ref<Texture> sn = get_icon("SmallNext", "EditorIcons");
|
|
||||||
Ref<StyleBox> sb = get_stylebox("pressed", "Button");
|
|
||||||
|
|
||||||
int ofs = sb->get_margin(MARGIN_LEFT);
|
|
||||||
|
|
||||||
if (mouse_over) {
|
|
||||||
draw_style_box(sb, Rect2(Point2(), get_size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < history->get_path_size(); i++) {
|
for (int i = 0; i < history->get_path_size(); i++) {
|
||||||
|
|
||||||
@ -115,21 +85,11 @@ void EditorPath::_notification(int p_what) {
|
|||||||
if (!obj)
|
if (!obj)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String type = obj->get_class();
|
|
||||||
|
|
||||||
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj);
|
Ref<Texture> icon = EditorNode::get_singleton()->get_object_icon(obj);
|
||||||
|
if (icon.is_valid())
|
||||||
if (icon.is_valid()) {
|
set_icon(icon);
|
||||||
icon->draw(ci, Point2i(ofs, (size.height - icon->get_height()) / 2));
|
|
||||||
ofs += icon->get_width();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == history->get_path_size() - 1) {
|
if (i == history->get_path_size() - 1) {
|
||||||
//add name
|
|
||||||
ofs += 4;
|
|
||||||
int left = size.width - ofs;
|
|
||||||
if (left < 0)
|
|
||||||
continue;
|
|
||||||
String name;
|
String name;
|
||||||
if (Object::cast_to<Resource>(obj)) {
|
if (Object::cast_to<Resource>(obj)) {
|
||||||
|
|
||||||
@ -150,28 +110,13 @@ void EditorPath::_notification(int p_what) {
|
|||||||
else
|
else
|
||||||
name = obj->get_class();
|
name = obj->get_class();
|
||||||
|
|
||||||
|
set_text(" " + name); // An extra space so the text is not too close of the icon.
|
||||||
set_tooltip(obj->get_class());
|
set_tooltip(obj->get_class());
|
||||||
|
}
|
||||||
label_font->draw(ci, Point2i(ofs, (size.height - label_font->get_height()) / 2 + label_font->get_ascent()), name, get_color("font_color", "Label"), left);
|
|
||||||
} else {
|
|
||||||
//add arrow
|
|
||||||
|
|
||||||
//sn->draw(ci,Point2i(ofs,(size.height-sn->get_height())/2));
|
|
||||||
//ofs+=sn->get_width();
|
|
||||||
ofs += 5; //just looks better! somehow
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
void EditorPath::_id_pressed(int p_idx) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorPath::update_path() {
|
|
||||||
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorPath::_popup_select(int p_idx) {
|
|
||||||
|
|
||||||
ERR_FAIL_INDEX(p_idx, objects.size());
|
ERR_FAIL_INDEX(p_idx, objects.size());
|
||||||
|
|
||||||
@ -184,15 +129,14 @@ void EditorPath::_popup_select(int p_idx) {
|
|||||||
|
|
||||||
void EditorPath::_bind_methods() {
|
void EditorPath::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method("_gui_input", &EditorPath::_gui_input);
|
ClassDB::bind_method("_about_to_show", &EditorPath::_about_to_show);
|
||||||
ClassDB::bind_method("_popup_select", &EditorPath::_popup_select);
|
ClassDB::bind_method("_id_pressed", &EditorPath::_id_pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorPath::EditorPath(EditorHistory *p_history) {
|
EditorPath::EditorPath(EditorHistory *p_history) {
|
||||||
|
|
||||||
history = p_history;
|
history = p_history;
|
||||||
mouse_over = false;
|
set_text_align(ALIGN_LEFT);
|
||||||
popup = memnew(PopupMenu);
|
get_popup()->connect("about_to_show", this, "_about_to_show");
|
||||||
popup->connect("id_pressed", this, "_popup_select");
|
get_popup()->connect("id_pressed", this, "_id_pressed");
|
||||||
add_child(popup);
|
|
||||||
}
|
}
|
||||||
|
@ -32,27 +32,23 @@
|
|||||||
#define EDITOR_PATH_H
|
#define EDITOR_PATH_H
|
||||||
|
|
||||||
#include "editor_data.h"
|
#include "editor_data.h"
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/menu_button.h"
|
||||||
#include "scene/gui/popup_menu.h"
|
|
||||||
|
|
||||||
class EditorPath : public Control {
|
class EditorPath : public MenuButton {
|
||||||
|
|
||||||
GDCLASS(EditorPath, Control);
|
GDCLASS(EditorPath, MenuButton);
|
||||||
|
|
||||||
EditorHistory *history;
|
EditorHistory *history;
|
||||||
|
|
||||||
Vector<ObjectID> objects;
|
Vector<ObjectID> objects;
|
||||||
PopupMenu *popup;
|
|
||||||
bool mouse_over;
|
|
||||||
EditorPath();
|
EditorPath();
|
||||||
|
|
||||||
void _popup_select(int p_idx);
|
void _id_pressed(int p_idx);
|
||||||
void _gui_input(const Ref<InputEvent> &p_event);
|
void _about_to_show();
|
||||||
void _add_children_to_popup(Object *p_obj, int p_depth = 0);
|
void _add_children_to_popup(Object *p_obj, int p_depth = 0);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
void _notification(int p_what);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update_path();
|
void update_path();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user