From e592860145ff511d4249c46d98fc4845d943bad8 Mon Sep 17 00:00:00 2001 From: volzhs Date: Fri, 28 Apr 2017 01:51:23 +0900 Subject: [PATCH] Show transparency and accurate color for property --- editor/icons/2x/icon_transparent.png | Bin 0 -> 177 bytes editor/icons/icon_transparent.png | Bin 0 -> 158 bytes editor/property_editor.cpp | 23 +++++++++++++++++++++-- editor/property_editor.h | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 editor/icons/2x/icon_transparent.png create mode 100644 editor/icons/icon_transparent.png diff --git a/editor/icons/2x/icon_transparent.png b/editor/icons/2x/icon_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..627607039b6553e575330fcf7c55599f627d2f4f GIT binary patch literal 177 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oArNM~bhqvgP*AKY zB%;Kzv?L?Hh=HNvmiFoMD^F>#F>r=4Ezh4>vmB_x(bL5-B;xSfiw8Lw3^`mKC%e7b zuf0~~rkssVW94^!=5?#A3^k0^Ki~KWG#m_G*ZA_4Y!`=c_VDhwZNYUbIlH$TB;e`l K=d#Wzp$PyxjWiVi literal 0 HcmV?d00001 diff --git a/editor/icons/icon_transparent.png b/editor/icons/icon_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..07e9b52b5c3a058c3fa449bbe3943a4a0329ced9 GIT binary patch literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GGLLkg|>2BR0prBY) zNJNQaX-P(Y5d%ZTE$!3iSDw;fW8e&9TAn|%W;sxWo~Mgrh{fsTnhy^S*0b3-#Kp=4alOKUset_custom_bg_color(1, obj->get(p_name)); + tree->update(); //p_item->set_text(1,obj->get(p_name)); } break; @@ -3168,7 +3168,7 @@ void PropertyEditor::update_tree() { item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM); item->set_editable(1, !read_only); // item->set_text(1,obj->get(p.name)); - item->set_custom_bg_color(1, obj->get(p.name)); + item->set_custom_draw(1, this, "_draw_transparency"); if (show_type_icons) item->set_icon(0, get_icon("Color", "EditorIcons")); @@ -3309,6 +3309,24 @@ void PropertyEditor::update_tree() { } } +void PropertyEditor::_draw_transparency(Object *t, const Rect2 &p_rect) { + + TreeItem *ti = t->cast_to(); + if (!ti) + return; + + Color color = obj->get(ti->get_metadata(1)); + Ref arrow = tree->get_icon("select_arrow"); + + // make a little space between consecutive color fields + Rect2 area = p_rect; + area.pos.y += 1; + area.size.height -= 2; + area.size.width -= arrow->get_size().width + 5; + tree->draw_texture_rect(get_icon("Transparent", "EditorIcons"), area, true); + tree->draw_rect(area, color); +} + void PropertyEditor::_item_selected() { TreeItem *item = tree->get_selected(); @@ -3790,6 +3808,7 @@ void PropertyEditor::_bind_methods() { ObjectTypeDB::bind_method("update_tree", &PropertyEditor::update_tree); ObjectTypeDB::bind_method("_resource_preview_done", &PropertyEditor::_resource_preview_done); ObjectTypeDB::bind_method("refresh", &PropertyEditor::refresh); + ObjectTypeDB::bind_method("_draw_transparency", &PropertyEditor::_draw_transparency); ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &PropertyEditor::get_drag_data_fw); ObjectTypeDB::bind_method(_MD("can_drop_data_fw"), &PropertyEditor::can_drop_data_fw); diff --git a/editor/property_editor.h b/editor/property_editor.h index 18c6e4b8987..bbfac418755 100644 --- a/editor/property_editor.h +++ b/editor/property_editor.h @@ -234,6 +234,7 @@ class PropertyEditor : public Control { void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); void _resource_preview_done(const String &p_path, const Ref &p_preview, Variant p_ud); + void _draw_transparency(Object *t, const Rect2 &p_rect); UndoRedo *undo_redo;