summaryrefslogtreecommitdiff
path: root/scene/gui/item_list.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/item_list.cpp')
-rw-r--r--scene/gui/item_list.cpp146
1 files changed, 68 insertions, 78 deletions
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 1dc4230d2a..2f0c7b9aaf 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -42,7 +42,6 @@ void ItemList::add_item(const String &p_item, const Ref<Texture> &p_texture, boo
item.disabled = false;
item.tooltip_enabled = true;
item.custom_bg = Color(0, 0, 0, 0);
- item.custom_font_color = get_color("font_color");
items.push_back(item);
update();
@@ -152,20 +151,6 @@ Color ItemList::get_item_custom_bg_color(int p_idx) const {
return items[p_idx].custom_bg;
}
-void ItemList::set_item_custom_font_color(int p_idx, const Color &p_custom_font_color) {
-
- ERR_FAIL_INDEX(p_idx, items.size());
-
- items[p_idx].custom_font_color = p_custom_font_color;
-}
-
-Color ItemList::get_item_custom_font_color(int p_idx) const {
-
- ERR_FAIL_INDEX_V(p_idx, items.size(), Color());
-
- return items[p_idx].custom_font_color;
-}
-
void ItemList::set_item_tag_icon(int p_idx, const Ref<Texture> &p_tag_icon) {
ERR_FAIL_INDEX(p_idx, items.size());
@@ -424,14 +409,17 @@ Size2 ItemList::Item::get_icon_size() const {
return icon_region.size;
}
-void ItemList::_gui_input(const InputEvent &p_event) {
+void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
- if (defer_select_single >= 0 && p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (defer_select_single >= 0 && mm.is_valid()) {
defer_select_single = -1;
return;
}
- if (defer_select_single >= 0 && p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_LEFT && !p_event.mouse_button.pressed) {
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (defer_select_single >= 0 && mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) {
select(defer_select_single, true);
@@ -440,12 +428,10 @@ void ItemList::_gui_input(const InputEvent &p_event) {
return;
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && (p_event.mouse_button.button_index == BUTTON_LEFT || (allow_rmb_select && p_event.mouse_button.button_index == BUTTON_RIGHT)) && p_event.mouse_button.pressed) {
-
- const InputEventMouseButton &mb = p_event.mouse_button;
+ if (mb.is_valid() && (mb->get_button_index() == BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == BUTTON_RIGHT)) && mb->is_pressed()) {
search_string = ""; //any mousepress cancels
- Vector2 pos(mb.x, mb.y);
+ Vector2 pos(mb->get_position().x, mb->get_position().y);
Ref<StyleBox> bg = get_stylebox("bg");
pos -= bg->get_offset();
pos.y += scroll_bar->get_value();
@@ -469,11 +455,11 @@ void ItemList::_gui_input(const InputEvent &p_event) {
int i = closest;
- if (select_mode == SELECT_MULTI && items[i].selected && mb.mod.command) {
+ if (select_mode == SELECT_MULTI && items[i].selected && mb->get_command()) {
unselect(i);
emit_signal("multi_selected", i, false);
- } else if (select_mode == SELECT_MULTI && mb.mod.shift && current >= 0 && current < items.size() && current != i) {
+ } else if (select_mode == SELECT_MULTI && mb->get_shift() && current >= 0 && current < items.size() && current != i) {
int from = current;
int to = i;
@@ -487,24 +473,24 @@ void ItemList::_gui_input(const InputEvent &p_event) {
emit_signal("multi_selected", i, true);
}
- if (p_event.mouse_button.button_index == BUTTON_RIGHT) {
+ if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb.x, mb.y));
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
}
} else {
- if (!mb.doubleclick && !mb.mod.command && select_mode == SELECT_MULTI && items[i].selectable && !items[i].disabled && items[i].selected && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ if (!mb->is_doubleclick() && !mb->get_command() && select_mode == SELECT_MULTI && items[i].selectable && !items[i].disabled && items[i].selected && mb->get_button_index() == BUTTON_LEFT) {
defer_select_single = i;
return;
}
- if (items[i].selected && p_event.mouse_button.button_index == BUTTON_RIGHT) {
+ if (items[i].selected && mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb.x, mb.y));
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
} else {
bool selected = !items[i].selected;
- select(i, select_mode == SELECT_SINGLE || !mb.mod.command);
+ select(i, select_mode == SELECT_SINGLE || !mb->get_command());
if (selected) {
if (select_mode == SELECT_SINGLE) {
@@ -513,10 +499,10 @@ void ItemList::_gui_input(const InputEvent &p_event) {
emit_signal("multi_selected", i, true);
}
- if (p_event.mouse_button.button_index == BUTTON_RIGHT) {
+ if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb.x, mb.y));
- } else if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) {
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
+ } else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_doubleclick()) {
emit_signal("item_activated", i);
}
@@ -531,17 +517,17 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
}
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_WHEEL_UP && p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
- scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() / 8);
+ scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() * mb->get_factor() / 8);
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_WHEEL_DOWN && p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
- scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() / 8);
+ scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * mb->get_factor() / 8);
}
- if (p_event.is_pressed() && items.size() > 0) {
- if (p_event.is_action("ui_up")) {
+ if (p_event->is_pressed() && items.size() > 0) {
+ if (p_event->is_action("ui_up")) {
if (search_string != "") {
@@ -576,7 +562,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_down")) {
+ } else if (p_event->is_action("ui_down")) {
if (search_string != "") {
@@ -610,7 +596,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_page_up")) {
+ } else if (p_event->is_action("ui_page_up")) {
search_string = ""; //any mousepress cancels
@@ -625,7 +611,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
break;
}
}
- } else if (p_event.is_action("ui_page_down")) {
+ } else if (p_event->is_action("ui_page_down")) {
search_string = ""; //any mousepress cancels
@@ -641,7 +627,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
break;
}
}
- } else if (p_event.is_action("ui_left")) {
+ } else if (p_event->is_action("ui_left")) {
search_string = ""; //any mousepress cancels
@@ -653,7 +639,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_right")) {
+ } else if (p_event->is_action("ui_right")) {
search_string = ""; //any mousepress cancels
@@ -665,9 +651,9 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_cancel")) {
+ } else if (p_event->is_action("ui_cancel")) {
search_string = "";
- } else if (p_event.is_action("ui_select")) {
+ } else if (p_event->is_action("ui_select")) {
if (select_mode == SELECT_MULTI && current >= 0 && current < items.size()) {
if (items[current].selectable && !items[current].disabled && !items[current].selected) {
@@ -678,15 +664,17 @@ void ItemList::_gui_input(const InputEvent &p_event) {
emit_signal("multi_selected", current, false);
}
}
- } else if (p_event.is_action("ui_accept")) {
+ } else if (p_event->is_action("ui_accept")) {
search_string = ""; //any mousepress cance
if (current >= 0 && current < items.size()) {
emit_signal("item_activated", current);
}
- } else if (p_event.type == InputEvent::KEY) {
+ } else {
+
+ Ref<InputEventKey> k = p_event;
- if (p_event.key.unicode) {
+ if (k.is_valid() && k->get_unicode()) {
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
@@ -697,7 +685,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
search_string = "";
}
- search_string += String::chr(p_event.key.unicode);
+ search_string += String::chr(k->get_unicode());
for (int i = 0; i < items.size(); i++) {
if (items[i].text.begins_with(search_string)) {
set_current(i);
@@ -869,7 +857,7 @@ void ItemList::_notification(int p_what) {
items[i].rect_cache = items[i].min_rect_cache;
if (same_column_width)
items[i].rect_cache.size.x = max_column_width;
- items[i].rect_cache.pos = ofs;
+ items[i].rect_cache.position = ofs;
max_h = MAX(max_h, items[i].rect_cache.size.y);
ofs.x += items[i].rect_cache.size.x + hseparation;
//print_line("item "+itos(i)+" ofs "+rtos(items[i].rect_cache.size.x));
@@ -918,10 +906,10 @@ void ItemList::_notification(int p_what) {
int from = scroll_bar->get_value();
int to = from + scroll_bar->get_page();
- if (r.pos.y < from) {
- scroll_bar->set_value(r.pos.y);
- } else if (r.pos.y + r.size.y > to) {
- scroll_bar->set_value(r.pos.y + r.size.y - (to - from));
+ if (r.position.y < from) {
+ scroll_bar->set_value(r.position.y);
+ } else if (r.position.y + r.size.y > to) {
+ scroll_bar->set_value(r.position.y + r.size.y - (to - from));
}
}
@@ -940,26 +928,29 @@ void ItemList::_notification(int p_what) {
continue;
if (current_columns == 1) {
- rcache.size.width = width - rcache.pos.x;
+ rcache.size.width = width - rcache.position.x;
}
- Rect2 r = rcache;
- r.pos += base_ofs;
-
- // Use stylebox to dimension potential bg color, even if not selected
- r.pos.x -= sbsel->get_margin(MARGIN_LEFT);
- r.size.x += sbsel->get_margin(MARGIN_LEFT) + sbsel->get_margin(MARGIN_RIGHT);
- r.pos.y -= sbsel->get_margin(MARGIN_TOP);
- r.size.y += sbsel->get_margin(MARGIN_TOP) + sbsel->get_margin(MARGIN_BOTTOM);
-
if (items[i].selected) {
+ Rect2 r = rcache;
+ r.position += base_ofs;
+
+ // Use stylebox to dimension potential bg color
+ r.position.x -= sbsel->get_margin(MARGIN_LEFT);
+ r.size.x += sbsel->get_margin(MARGIN_LEFT) + sbsel->get_margin(MARGIN_RIGHT);
+ r.position.y -= sbsel->get_margin(MARGIN_TOP);
+ r.size.y += sbsel->get_margin(MARGIN_TOP) + sbsel->get_margin(MARGIN_BOTTOM);
draw_style_box(sbsel, r);
}
+
if (items[i].custom_bg.a > 0.001) {
- r.pos.x += 2;
- r.size.x -= 4;
- r.pos.y += 2;
- r.size.y -= 4;
+
+ Rect2 r = rcache;
+ r.position += base_ofs;
+
+ // Size rect to make the align the temperature colors
+ r.position.y -= vseparation / 2;
+ r.size.y += vseparation;
draw_rect(r, items[i].custom_bg);
}
@@ -977,7 +968,7 @@ void ItemList::_notification(int p_what) {
Vector2 icon_ofs;
- Point2 pos = items[i].rect_cache.pos + icon_ofs + base_ofs;
+ Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
if (icon_mode == ICON_MODE_TOP) {
@@ -997,7 +988,7 @@ void ItemList::_notification(int p_what) {
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size);
- draw_rect.pos += adj.pos;
+ draw_rect.position += adj.position;
draw_rect.size = adj.size;
}
@@ -1013,7 +1004,7 @@ void ItemList::_notification(int p_what) {
if (items[i].tag_icon.is_valid()) {
- draw_texture(items[i].tag_icon, items[i].rect_cache.pos + base_ofs);
+ draw_texture(items[i].tag_icon, items[i].rect_cache.position + base_ofs);
}
if (items[i].text != "") {
@@ -1028,8 +1019,7 @@ void ItemList::_notification(int p_what) {
else
max_len = size.x;
- Color font_color_2 = items[i].custom_font_color;
- Color modulate = items[i].selected ? font_color_selected : font_color_2;
+ Color modulate = items[i].selected ? font_color_selected : font_color;
if (items[i].disabled)
modulate.a *= 0.5;
@@ -1059,7 +1049,7 @@ void ItemList::_notification(int p_what) {
text_ofs.y += font->get_ascent();
text_ofs = text_ofs.floor();
text_ofs += base_ofs;
- text_ofs += items[i].rect_cache.pos;
+ text_ofs += items[i].rect_cache.position;
for (int j = 0; j < ss; j++) {
@@ -1087,7 +1077,7 @@ void ItemList::_notification(int p_what) {
text_ofs.y += font->get_ascent();
text_ofs = text_ofs.floor();
text_ofs += base_ofs;
- text_ofs += items[i].rect_cache.pos;
+ text_ofs += items[i].rect_cache.position;
draw_string(font, text_ofs, items[i].text, modulate, max_len + 1);
}
@@ -1096,7 +1086,7 @@ void ItemList::_notification(int p_what) {
if (select_mode == SELECT_MULTI && i == current) {
Rect2 r = rcache;
- r.pos += base_ofs;
+ r.position += base_ofs;
draw_style_box(cursor, r);
}
}
@@ -1154,7 +1144,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const {
pos.y += scroll_bar->get_value();
Rect2 endrect = items[items.size() - 1].rect_cache;
- return (pos.y > endrect.pos.y + endrect.size.y);
+ return (pos.y > endrect.position.y + endrect.size.y);
}
String ItemList::get_tooltip(const Point2 &p_pos) const {