Merge pull request #31628 from merumelu/treeitem-icon-modulate

Tree: fix and expose icon modulation
This commit is contained in:
Rémi Verschelde 2019-08-25 10:49:26 +02:00 committed by GitHub
commit 0d37f198f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 24 deletions

View file

@ -136,6 +136,15 @@
Returns the column's icon's maximum width. Returns the column's icon's maximum width.
</description> </description>
</method> </method>
<method name="get_icon_modulate" qualifiers="const">
<return type="Color">
</return>
<argument index="0" name="column" type="int">
</argument>
<description>
Returns the [Color] modulating the column's icon.
</description>
</method>
<method name="get_icon_region" qualifiers="const"> <method name="get_icon_region" qualifiers="const">
<return type="Rect2"> <return type="Rect2">
</return> </return>
@ -464,6 +473,17 @@
Sets the given column's icon's maximum width. Sets the given column's icon's maximum width.
</description> </description>
</method> </method>
<method name="set_icon_modulate">
<return type="void">
</return>
<argument index="0" name="column" type="int">
</argument>
<argument index="1" name="modulate" type="Color">
</argument>
<description>
Modulates the given column's icon with [code]modulate[/code].
</description>
</method>
<method name="set_icon_region"> <method name="set_icon_region">
<return type="void"> <return type="void">
</return> </return>

View file

@ -63,7 +63,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory
subdirectory_item->set_text(0, dname); subdirectory_item->set_text(0, dname);
subdirectory_item->set_icon(0, get_icon("Folder", "EditorIcons")); subdirectory_item->set_icon(0, get_icon("Folder", "EditorIcons"));
subdirectory_item->set_icon_color(0, get_color("folder_icon_modulate", "FileDialog")); subdirectory_item->set_icon_modulate(0, get_color("folder_icon_modulate", "FileDialog"));
subdirectory_item->set_selectable(0, true); subdirectory_item->set_selectable(0, true);
String lpath = p_dir->get_path(); String lpath = p_dir->get_path();
subdirectory_item->set_metadata(0, lpath); subdirectory_item->set_metadata(0, lpath);
@ -214,7 +214,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo
TreeItem *ti = tree->create_item(favorites); TreeItem *ti = tree->create_item(favorites);
ti->set_text(0, text); ti->set_text(0, text);
ti->set_icon(0, icon); ti->set_icon(0, icon);
ti->set_icon_color(0, color); ti->set_icon_modulate(0, color);
ti->set_tooltip(0, fave); ti->set_tooltip(0, fave);
ti->set_selectable(0, true); ti->set_selectable(0, true);
ti->set_metadata(0, fave); ti->set_metadata(0, fave);

View file

@ -430,7 +430,7 @@ void FileDialog::update_file_list() {
TreeItem *ti = tree->create_item(root); TreeItem *ti = tree->create_item(root);
ti->set_text(0, dir_name); ti->set_text(0, dir_name);
ti->set_icon(0, folder); ti->set_icon(0, folder);
ti->set_icon_color(0, folder_color); ti->set_icon_modulate(0, folder_color);
Dictionary d; Dictionary d;
d["name"] = dir_name; d["name"] = dir_name;

View file

@ -224,14 +224,14 @@ Rect2 TreeItem::get_icon_region(int p_column) const {
return cells[p_column].icon_region; return cells[p_column].icon_region;
} }
void TreeItem::set_icon_color(int p_column, const Color &p_icon_color) { void TreeItem::set_icon_modulate(int p_column, const Color &p_modulate) {
ERR_FAIL_INDEX(p_column, cells.size()); ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].icon_color = p_icon_color; cells.write[p_column].icon_color = p_modulate;
_changed_notify(p_column); _changed_notify(p_column);
} }
Color TreeItem::get_icon_color(int p_column) const { Color TreeItem::get_icon_modulate(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Color()); ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
return cells[p_column].icon_color; return cells[p_column].icon_color;
@ -744,6 +744,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_icon_max_width", "column", "width"), &TreeItem::set_icon_max_width); ClassDB::bind_method(D_METHOD("set_icon_max_width", "column", "width"), &TreeItem::set_icon_max_width);
ClassDB::bind_method(D_METHOD("get_icon_max_width", "column"), &TreeItem::get_icon_max_width); ClassDB::bind_method(D_METHOD("get_icon_max_width", "column"), &TreeItem::get_icon_max_width);
ClassDB::bind_method(D_METHOD("set_icon_modulate", "column", "modulate"), &TreeItem::set_icon_modulate);
ClassDB::bind_method(D_METHOD("get_icon_modulate", "column"), &TreeItem::get_icon_modulate);
ClassDB::bind_method(D_METHOD("set_range", "column", "value"), &TreeItem::set_range); ClassDB::bind_method(D_METHOD("set_range", "column", "value"), &TreeItem::set_range);
ClassDB::bind_method(D_METHOD("get_range", "column"), &TreeItem::get_range); ClassDB::bind_method(D_METHOD("get_range", "column"), &TreeItem::get_range);
ClassDB::bind_method(D_METHOD("set_range_config", "column", "min", "max", "step", "expr"), &TreeItem::set_range_config, DEFVAL(false)); ClassDB::bind_method(D_METHOD("set_range_config", "column", "min", "max", "step", "expr"), &TreeItem::set_range_config, DEFVAL(false));
@ -1259,10 +1262,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
check_ofs.y += Math::floor((real_t)(item_rect.size.y - checked->get_height()) / 2); check_ofs.y += Math::floor((real_t)(item_rect.size.y - checked->get_height()) / 2);
if (p_item->cells[i].checked) { if (p_item->cells[i].checked) {
checked->draw(ci, check_ofs);
checked->draw(ci, check_ofs, icon_col);
} else { } else {
unchecked->draw(ci, check_ofs, icon_col); unchecked->draw(ci, check_ofs);
} }
int check_w = checked->get_width() + cache.hseparation; int check_w = checked->get_width() + cache.hseparation;
@ -1274,8 +1276,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
draw_item_rect(p_item->cells[i], item_rect, col, icon_col); draw_item_rect(p_item->cells[i], item_rect, col, icon_col);
//font->draw( ci, text_pos, p_item->cells[i].text, col,item_rect.size.x-check_w );
} break; } break;
case TreeItem::CELL_MODE_RANGE: { case TreeItem::CELL_MODE_RANGE: {
if (p_item->cells[i].text != "") { if (p_item->cells[i].text != "") {
@ -1305,18 +1305,16 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
font->draw(ci, text_pos, s, col, item_rect.size.x - downarrow->get_width()); font->draw(ci, text_pos, s, col, item_rect.size.x - downarrow->get_width());
//?
Point2i arrow_pos = item_rect.position; Point2i arrow_pos = item_rect.position;
arrow_pos.x += item_rect.size.x - downarrow->get_width(); arrow_pos.x += item_rect.size.x - downarrow->get_width();
arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0); arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0);
downarrow->draw(ci, arrow_pos, icon_col); downarrow->draw(ci, arrow_pos);
} else { } else {
Ref<Texture> updown = cache.updown; Ref<Texture> updown = cache.updown;
String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step)); String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step));
//String valtext = rtos( p_item->cells[i].val );
if (p_item->cells[i].suffix != String()) if (p_item->cells[i].suffix != String())
valtext += " " + p_item->cells[i].suffix; valtext += " " + p_item->cells[i].suffix;
@ -1330,7 +1328,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
updown_pos.x += item_rect.size.x - updown->get_width(); updown_pos.x += item_rect.size.x - updown->get_width();
updown_pos.y += Math::floor(((item_rect.size.y - updown->get_height())) / 2.0); updown_pos.y += Math::floor(((item_rect.size.y - updown->get_height())) / 2.0);
updown->draw(ci, updown_pos, icon_col); updown->draw(ci, updown_pos);
} }
} break; } break;
@ -1348,13 +1346,10 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
icon_ofs += item_rect.position; icon_ofs += item_rect.position;
draw_texture_rect(p_item->cells[i].icon, Rect2(icon_ofs, icon_size), false, icon_col); draw_texture_rect(p_item->cells[i].icon, Rect2(icon_ofs, icon_size), false, icon_col);
//p_item->cells[i].icon->draw(ci, icon_ofs);
} break; } break;
case TreeItem::CELL_MODE_CUSTOM: { case TreeItem::CELL_MODE_CUSTOM: {
//int option = (int)p_item->cells[i].val;
if (p_item->cells[i].custom_draw_obj) { if (p_item->cells[i].custom_draw_obj) {
Object *cdo = ObjectDB::get_instance(p_item->cells[i].custom_draw_obj); Object *cdo = ObjectDB::get_instance(p_item->cells[i].custom_draw_obj);
@ -1429,10 +1424,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
arrow->draw(ci, p_pos + p_draw_ofs + Point2i(0, (label_h - arrow->get_height()) / 2) - cache.offset); arrow->draw(ci, p_pos + p_draw_ofs + Point2i(0, (label_h - arrow->get_height()) / 2) - cache.offset);
} }
//separator
//get_painter()->draw_fill_rect( Point2i(0,pos.y),Size2i(get_size().width,1),color( COLOR_TREE_GRID) );
//pos=p_pos; //reset pos
} }
Point2 children_pos = p_pos; Point2 children_pos = p_pos;

View file

@ -193,8 +193,8 @@ public:
void set_icon_region(int p_column, const Rect2 &p_icon_region); void set_icon_region(int p_column, const Rect2 &p_icon_region);
Rect2 get_icon_region(int p_column) const; Rect2 get_icon_region(int p_column) const;
void set_icon_color(int p_column, const Color &p_icon_color); void set_icon_modulate(int p_column, const Color &p_modulate);
Color get_icon_color(int p_column) const; Color get_icon_modulate(int p_column) const;
void set_icon_max_width(int p_column, int p_max); void set_icon_max_width(int p_column, int p_max);
int get_icon_max_width(int p_column) const; int get_icon_max_width(int p_column) const;