summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-06-04 20:35:08 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-06-04 20:35:45 -0300
commit01198cb896297da2b6d853caf583cf9e5bbba730 (patch)
tree5575b51107111a0d14b3be3a3e385451736f40bf
parent5aa66d03d8b4d66ccdcfbc6c5c20e7bb510ac87a (diff)
Removed stupid right arrow to edit resource. Now simply click it..
-rw-r--r--editor/editor_themes.cpp4
-rw-r--r--editor/property_editor.cpp24
-rw-r--r--scene/gui/tree.cpp74
-rw-r--r--scene/gui/tree.h13
-rw-r--r--scene/resources/default_theme/default_theme.cpp4
5 files changed, 108 insertions, 11 deletions
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp
index bf15f43d32..4e44251f35 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -247,6 +247,10 @@ Ref<Theme> create_editor_theme() {
theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("TreeArrowRight", "EditorIcons"));
theme->set_icon("select_arrow", "Tree", theme->get_icon("Dropdown", "EditorIcons"));
theme->set_stylebox("bg_focus", "Tree", focus_sbt);
+ theme->set_stylebox("custom_button", "Tree", style_button);
+ theme->set_stylebox("custom_button_pressed", "Tree", style_button);
+ theme->set_stylebox("custom_button_hover", "Tree", style_button);
+ theme->set_color("custom_button_font_highlight", "Tree", HIGHLIGHT_COLOR_LIGHT);
Ref<StyleBox> style_tree_btn = make_flat_stylebox(light_color_1, 2, 4, 2, 4);
theme->set_stylebox("button_pressed", "Tree", style_tree_btn);
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index 1c8a1c0ee0..b113d1b7ad 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -2310,6 +2310,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p
if (obj->get(p_name).get_type() == Variant::NIL || obj->get(p_name).operator RefPtr().is_null()) {
p_item->set_text(1, "<null>");
p_item->set_icon(1, Ref<Texture>());
+ p_item->set_custom_as_button(1, false);
Dictionary d = p_item->get_metadata(0);
int hint = d.has("hint") ? d["hint"].operator int() : -1;
@@ -2319,6 +2320,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p
}
} else {
+ p_item->set_custom_as_button(1, true);
RES res = obj->get(p_name).operator RefPtr();
if (res->is_class("Texture")) {
int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width");
@@ -3540,17 +3542,21 @@ void PropertyEditor::update_tree() {
item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM);
item->set_editable(1, !read_only);
- item->add_button(1, get_icon("EditResource", "EditorIcons"));
+ //item->add_button(1, get_icon("EditResource", "EditorIcons"));
String type;
if (p.hint == PROPERTY_HINT_RESOURCE_TYPE)
type = p.hint_string;
- if (obj->get(p.name).get_type() == Variant::NIL || obj->get(p.name).operator RefPtr().is_null()) {
+ RES res = obj->get(p.name).operator RefPtr();
+
+ if (obj->get(p.name).get_type() == Variant::NIL || res.is_null()) {
item->set_text(1, "<null>");
item->set_icon(1, Ref<Texture>());
+ item->set_custom_as_button(1, false);
- } else {
- RES res = obj->get(p.name).operator RefPtr();
+ } else if (res.is_valid()) {
+
+ item->set_custom_as_button(1, true);
if (res->is_class("Texture")) {
int tw = EditorSettings::get_singleton()->get("docks/property_editor/texture_preview_width");
@@ -3854,6 +3860,16 @@ void PropertyEditor::_item_edited() {
_edit_set(name, NodePath(item->get_text(1)), refresh_all);
} break;
+ case Variant::OBJECT: {
+ if (!item->is_custom_set_as_button(1))
+ break;
+
+ RES res = obj->get(name);
+ if (res.is_valid()) {
+ emit_signal("resource_selected", res.get_ref_ptr(), name);
+ }
+
+ } break;
case Variant::DICTIONARY: {
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 397386700e..9da37746ae 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -610,6 +610,18 @@ Color TreeItem::get_custom_bg_color(int p_column) const {
return cells[p_column].bg_color;
}
+void TreeItem::set_custom_as_button(int p_column, bool p_button) {
+
+ ERR_FAIL_INDEX(p_column, cells.size());
+ cells[p_column].custom_button = p_button;
+}
+
+bool TreeItem::is_custom_set_as_button(int p_column) const {
+
+ ERR_FAIL_INDEX_V(p_column, cells.size(), false);
+ return cells[p_column].custom_button;
+}
+
void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode);
@@ -670,6 +682,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color);
ClassDB::bind_method(D_METHOD("get_custom_bg_color", "column"), &TreeItem::get_custom_bg_color);
+ ClassDB::bind_method(D_METHOD("set_custom_as_button", "column", "enable"), &TreeItem::set_custom_as_button);
+ ClassDB::bind_method(D_METHOD("is_custom_set_as_button", "column"), &TreeItem::is_custom_set_as_button);
+
ClassDB::bind_method(D_METHOD("add_button", "column", "button:Texture", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count);
ClassDB::bind_method(D_METHOD("get_button:Texture", "column", "button_idx"), &TreeItem::get_button);
@@ -732,6 +747,10 @@ TreeItem::~TreeItem() {
tree->pressing_for_editor = false;
}
+ if (tree && tree->cache.hover_item == this) {
+ tree->cache.hover_item = NULL;
+ }
+
if (tree && tree->selected_item == this)
tree->selected_item = NULL;
@@ -772,6 +791,11 @@ void Tree::update_cache() {
cache.select_arrow = get_icon("select_arrow");
cache.updown = get_icon("updown");
+ cache.custom_button = get_stylebox("custom_button");
+ cache.custom_button_hover = get_stylebox("custom_button_hover");
+ cache.custom_button_pressed = get_stylebox("custom_button_pressed");
+ cache.custom_button_font_highlight = get_color("custom_button_font_highlight");
+
cache.font_color = get_color("font_color");
cache.font_color_selected = get_color("font_color_selected");
cache.guide_color = get_color("guide_color");
@@ -833,6 +857,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
if (s.height > height)
height = s.height;
}
+ if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) {
+ height += cache.custom_button->get_minimum_size().height;
+ }
} break;
default: {}
@@ -1202,12 +1229,28 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Ref<Texture> downarrow = cache.select_arrow;
Rect2i ir = item_rect;
- ir.size.width -= downarrow->get_width();
- draw_item_rect(p_item->cells[i], ir, col);
Point2i arrow_pos = item_rect.pos;
arrow_pos.x += item_rect.size.x - downarrow->get_width();
arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0);
+ ir.size.width -= downarrow->get_width();
+
+ if (p_item->cells[i].custom_button) {
+ if (cache.hover_item == p_item && cache.hover_cell == i) {
+ if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
+ draw_style_box(cache.custom_button_pressed, ir);
+ } else {
+ draw_style_box(cache.custom_button_hover, ir);
+ col = cache.custom_button_font_highlight;
+ }
+ } else {
+ draw_style_box(cache.custom_button, ir);
+ }
+ ir.size -= cache.custom_button->get_minimum_size();
+ ir.pos += cache.custom_button->get_offset();
+ }
+
+ draw_item_rect(p_item->cells[i], ir, col);
downarrow->draw(ci, arrow_pos);
@@ -1697,11 +1740,18 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
case TreeItem::CELL_MODE_CUSTOM: {
edited_item = p_item;
edited_col = col;
- custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h));
- emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2))));
+ bool on_arrow = x > col_width - cache.select_arrow->get_width();
bring_up_editor = false;
- item_edited(col, p_item);
+
+ if (on_arrow || !p_item->cells[col].custom_button) {
+ custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h));
+ emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2))));
+ }
+
+ if (!p_item->cells[col].custom_button || !on_arrow) {
+ item_edited(col, p_item);
+ }
click_handled = true;
return -1;
} break;
@@ -2148,7 +2198,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
}
- if (drop_mode_flags && root) {
+ if (root) {
Point2 mpos = mm->get_position();
mpos -= cache.bg->get_offset();
@@ -2163,11 +2213,17 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
int col, h, section;
TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
- if (it != drop_mode_over || section != drop_mode_section) {
+ if (drop_mode_flags && it != drop_mode_over || section != drop_mode_section) {
drop_mode_over = it;
drop_mode_section = section;
update();
}
+
+ if (it != cache.hover_item || col != cache.hover_cell) {
+ cache.hover_item = it;
+ cache.hover_cell = col;
+ update();
+ }
}
}
@@ -3469,6 +3525,7 @@ void Tree::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos")));
ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos")));
ADD_SIGNAL(MethodInfo("item_edited"));
+ ADD_SIGNAL(MethodInfo("item_custom_button_pressed"));
ADD_SIGNAL(MethodInfo("item_double_clicked"));
ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item")));
//ADD_SIGNAL( MethodInfo("item_doubleclicked" ) );
@@ -3575,6 +3632,9 @@ Tree::Tree() {
force_edit_checkbox_only_on_checkbox = false;
set_clip_contents(true);
+
+ cache.hover_item = NULL;
+ cache.hover_cell = -1;
}
Tree::~Tree() {
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 0c07109e7d..097e0110e8 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -81,6 +81,7 @@ private:
bool custom_bg_color;
bool custom_bg_outline;
Color bg_color;
+ bool custom_button;
Variant meta;
String tooltip;
@@ -107,6 +108,7 @@ private:
Cell() {
custom_draw_obj = 0;
+ custom_button = false;
mode = TreeItem::CELL_MODE_STRING;
min = 0;
max = 100;
@@ -238,6 +240,9 @@ public:
void clear_custom_bg_color(int p_column);
Color get_custom_bg_color(int p_column) const;
+ void set_custom_as_button(int p_column, bool p_button);
+ bool is_custom_set_as_button(int p_column) const;
+
void set_tooltip(int p_column, const String &p_tooltip);
String get_tooltip(int p_column) const;
@@ -369,6 +374,10 @@ private:
Ref<StyleBox> title_button;
Ref<StyleBox> title_button_hover;
Ref<StyleBox> title_button_pressed;
+ Ref<StyleBox> custom_button;
+ Ref<StyleBox> custom_button_hover;
+ Ref<StyleBox> custom_button_pressed;
+
Color title_button_color;
Ref<Texture> checked;
@@ -383,6 +392,7 @@ private:
Color guide_color;
Color drop_position_color;
Color relationship_line_color;
+ Color custom_button_font_highlight;
int hseparation;
int vseparation;
@@ -410,6 +420,9 @@ private:
int hover_index;
Point2 click_pos;
+ TreeItem *hover_item;
+ int hover_cell;
+
} cache;
int _get_title_button_height() const;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 7e5065a03b..1af2e82a4f 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -626,6 +626,9 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
t->set_stylebox("title_button_normal", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4));
t->set_stylebox("title_button_pressed", "Tree", make_stylebox(tree_title_pressed_png, 4, 4, 4, 4));
t->set_stylebox("title_button_hover", "Tree", make_stylebox(tree_title_png, 4, 4, 4, 4));
+ t->set_stylebox("custom_button", "Tree", sb_button_normal);
+ t->set_stylebox("custom_button_pressed", "Tree", sb_button_pressed);
+ t->set_stylebox("custom_button_hover", "Tree", sb_button_hover);
t->set_icon("checked", "Tree", make_icon(checked_png));
t->set_icon("unchecked", "Tree", make_icon(unchecked_png));
@@ -645,6 +648,7 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
t->set_color("guide_color", "Tree", Color(0, 0, 0, 0.1));
t->set_color("drop_position_color", "Tree", Color(1, 0.3, 0.2));
t->set_color("relationship_line_color", "Tree", Color::html("464646"));
+ t->set_color("custom_button_font_highlight", "Tree", control_font_color_hover);
t->set_constant("hseparation", "Tree", 4 * scale);
t->set_constant("vseparation", "Tree", 4 * scale);