summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/button.cpp29
-rw-r--r--scene/gui/dialogs.cpp30
-rw-r--r--scene/gui/graph_edit.cpp4
-rw-r--r--scene/gui/item_list.cpp18
-rw-r--r--scene/gui/item_list.h4
-rw-r--r--scene/gui/line_edit.cpp4
-rw-r--r--scene/gui/option_button.cpp19
-rw-r--r--scene/gui/spin_box.cpp7
-rw-r--r--scene/gui/tab_container.cpp9
-rw-r--r--scene/gui/tool_button.cpp4
-rw-r--r--scene/gui/tool_button.h3
-rw-r--r--scene/gui/tree.cpp18
-rw-r--r--scene/gui/tree.h4
13 files changed, 111 insertions, 42 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 6fcc878e11..f57b3d0fd1 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -69,49 +69,48 @@ void Button::_notification(int p_what) {
RID ci = get_canvas_item();
Size2 size = get_size();
Color color;
+ Color icon_color = Color(1, 1, 1);
//print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode()));
- Ref<StyleBox> style = get_stylebox("normal");
-
+ String style_name = "";
switch (get_draw_mode()) {
case DRAW_NORMAL: {
- style = get_stylebox("normal");
- if (!flat)
- style->draw(ci, Rect2(Point2(0, 0), size));
+ style_name = "normal";
color = get_color("font_color");
+
} break;
case DRAW_PRESSED: {
- style = get_stylebox("pressed");
- style->draw(ci, Rect2(Point2(0, 0), size));
- if (has_color("font_color_pressed"))
+ style_name = "pressed";
+ if (has_color("font_color_pressed")) {
color = get_color("font_color_pressed");
- else
+ icon_color = color;
+ } else
color = get_color("font_color");
} break;
case DRAW_HOVER: {
- style = get_stylebox("hover");
- style->draw(ci, Rect2(Point2(0, 0), size));
+ style_name = "hover";
color = get_color("font_color_hover");
} break;
case DRAW_DISABLED: {
- style = get_stylebox("disabled");
- style->draw(ci, Rect2(Point2(0, 0), size));
+ style_name = "disabled";
color = get_color("font_color_disabled");
} break;
}
+ if (style_name != "" && !flat) get_stylebox(style_name)->draw(ci, Rect2(Point2(0, 0), size));
+
+ Ref<StyleBox> style = get_stylebox(style_name);
if (has_focus()) {
- Ref<StyleBox> style = get_stylebox("focus");
style->draw(ci, Rect2(Point2(), size));
}
@@ -149,7 +148,7 @@ void Button::_notification(int p_what) {
int valign = size.height - style->get_minimum_size().y;
- _icon->draw(ci, style->get_offset() + Point2(0, Math::floor((valign - _icon->get_height()) / 2.0)), is_disabled() ? Color(1, 1, 1, 0.4) : Color(1, 1, 1));
+ _icon->draw(ci, style->get_offset() + Point2(0, Math::floor((valign - _icon->get_height()) / 2.0)), is_disabled() ? Color(1, 1, 1, 0.4) : icon_color);
}
}
}
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 835775e13b..cf5321e907 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -54,20 +54,24 @@ void WindowDialog::_fix_size() {
// Windows require additional padding to keep the window chrome visible.
Ref<StyleBoxTexture> panel = get_stylebox("panel", "WindowDialog");
- float top = panel->get_expand_margin_size(MARGIN_TOP);
- float left = panel->get_expand_margin_size(MARGIN_LEFT);
- float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM);
- float right = panel->get_expand_margin_size(MARGIN_RIGHT);
- pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right));
- pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom));
- set_global_position(pos);
-
- // Also resize the window to fit if a resize should be possible at all.
- if (resizable) {
- size.x = MIN(size.x, viewport_size.x - left - right);
- size.y = MIN(size.y, viewport_size.y - top - bottom);
- set_size(size);
+ // Check validity, because the theme could contain a different type of StyleBox
+ if (panel.is_valid()) {
+ float top = panel->get_expand_margin_size(MARGIN_TOP);
+ float left = panel->get_expand_margin_size(MARGIN_LEFT);
+ float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM);
+ float right = panel->get_expand_margin_size(MARGIN_RIGHT);
+
+ pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right));
+ pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom));
+ set_global_position(pos);
+
+ // Also resize the window to fit if a resize should be possible at all.
+ if (resizable) {
+ size.x = MIN(size.x, viewport_size.x - left - right);
+ size.y = MIN(size.y, viewport_size.y - top - bottom);
+ set_size(size);
+ }
}
}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 0c092a4e17..0bc48677dd 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -579,7 +579,7 @@ void GraphEdit::_bake_segment2d(CanvasItem *p_where, float p_begin, float p_end,
if (p_depth >= p_min_depth && (dp < p_tol || p_depth >= p_max_depth)) {
- p_where->draw_line(beg, end, p_color.linear_interpolate(p_to_color, mp), 2, true);
+ p_where->draw_line(beg, end, p_color.linear_interpolate(p_to_color, mp), 4, true);
lines++;
} else {
_bake_segment2d(p_where, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
@@ -598,7 +598,7 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
int cp_neg_len = get_constant("bezier_len_neg");
if (diff > 0) {
- cp_offset = MAX(cp_len, diff * 0.5);
+ cp_offset = MIN(cp_len, diff * 0.5);
} else {
cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
}
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index c2d5775b64..1dc4230d2a 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -42,6 +42,7 @@ 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();
@@ -151,6 +152,20 @@ 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());
@@ -1013,7 +1028,8 @@ void ItemList::_notification(int p_what) {
else
max_len = size.x;
- Color modulate = items[i].selected ? font_color_selected : font_color;
+ Color font_color_2 = items[i].custom_font_color;
+ Color modulate = items[i].selected ? font_color_selected : font_color_2;
if (items[i].disabled)
modulate.a *= 0.5;
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index 4b896de77c..96a894d3fd 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -62,6 +62,7 @@ private:
Variant metadata;
String tooltip;
Color custom_bg;
+ Color custom_font_color;
Rect2 rect_cache;
Rect2 min_rect_cache;
@@ -144,6 +145,9 @@ public:
void set_item_custom_bg_color(int p_idx, const Color &p_custom_bg_color);
Color get_item_custom_bg_color(int p_idx) const;
+ void set_item_custom_font_color(int p_idx, const Color &p_custom_font_color);
+ Color get_item_custom_font_color(int p_idx) const;
+
void select(int p_idx, bool p_single = true);
void unselect(int p_idx);
bool is_selected(int p_idx) const;
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 9abf9649c0..0acb7265e3 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -576,7 +576,7 @@ void LineEdit::_notification(int p_what) {
RID ci = get_canvas_item();
- Ref<StyleBox> style = get_stylebox("normal");
+ Ref<StyleBox> style = has_focus() ? get_stylebox("active") : get_stylebox("normal");
if (!is_editable())
style = get_stylebox("read_only");
@@ -617,7 +617,7 @@ void LineEdit::_notification(int p_what) {
int font_ascent = font->get_ascent();
Color selection_color = get_color("selection_color");
- Color font_color = get_color("font_color");
+ Color font_color = is_editable() ? has_focus() ? get_color("font_color_active") : get_color("font_color") : get_color("font_color_read_only");
Color font_color_selected = get_color("font_color_selected");
Color cursor_color = get_color("cursor_color");
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 0806d35d48..b967a1a7ce 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -56,7 +56,24 @@ void OptionButton::_notification(int p_what) {
Size2 size = get_size();
Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2)));
- arrow->draw(ci, ofs);
+
+ Color arrow_color = get_color("font_color");
+ switch (get_draw_mode()) {
+ case DRAW_NORMAL: {
+ arrow_color = get_color("font_color");
+ } break;
+ case DRAW_PRESSED: {
+ arrow_color = get_color("font_color_pressed");
+ } break;
+ case DRAW_HOVER: {
+ arrow_color = get_color("font_color_hover");
+ } break;
+ case DRAW_DISABLED: {
+ arrow_color = get_color("font_color_disabled");
+ } break;
+ }
+
+ arrow->draw(ci, ofs, arrow_color);
} break;
}
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 049adc6fb4..ba8ca63721 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -192,7 +192,12 @@ void SpinBox::_notification(int p_what) {
RID ci = get_canvas_item();
Size2i size = get_size();
- updown->draw(ci, Point2i(size.width - updown->get_width(), (size.height - updown->get_height()) / 2));
+ Color color = has_focus() ? line_edit->get_color("font_color_active") : line_edit->get_color("font_color");
+ if (!is_editable())
+ color = line_edit->get_color("font_color_read_only");
+ updown->draw(ci, Point2i(size.width - updown->get_width(), (size.height - updown->get_height()) / 2), color);
+
+ } else if (p_what == NOTIFICATION_FOCUS_EXIT) {
} else if (p_what == NOTIFICATION_FOCUS_EXIT) {
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 0c7a58dc16..952f2a9710 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -206,6 +206,9 @@ void TabContainer::_notification(int p_what) {
break;
}
+ // Draw the tab area.
+ panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
+
// Draw all visible tabs.
int x = 0;
for (int i = 0; i < tab_widths.size(); i++) {
@@ -224,7 +227,7 @@ void TabContainer::_notification(int p_what) {
// Draw the tab background.
int tab_width = tab_widths[i];
- Rect2 tab_rect(tabs_ofs_cache + x, 0, tab_width, header_height);
+ Rect2 tab_rect(tabs_ofs_cache + x, 2, tab_width, header_height);
tab_style->draw(canvas, tab_rect);
// Draw the tab contents.
@@ -279,8 +282,6 @@ void TabContainer::_notification(int p_what) {
Color(1, 1, 1, first_tab_cache > 0 ? 1.0 : 0.5));
}
- // Draw the tab area.
- panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
} break;
case NOTIFICATION_THEME_CHANGED: {
if (get_tab_count() > 0) {
@@ -659,7 +660,7 @@ TabContainer::TabContainer() {
current = 0;
previous = 0;
mouse_x_cache = 0;
- align = ALIGN_CENTER;
+ align = ALIGN_LEFT;
tabs_visible = true;
popup = NULL;
} \ No newline at end of file
diff --git a/scene/gui/tool_button.cpp b/scene/gui/tool_button.cpp
index 5fc4b6ecf8..7e8a426d15 100644
--- a/scene/gui/tool_button.cpp
+++ b/scene/gui/tool_button.cpp
@@ -29,6 +29,10 @@
/*************************************************************************/
#include "tool_button.h"
+void ToolButton::_notification(int p_what) {
+ // set_self_modulate(get_color("pressed"));
+}
+
ToolButton::ToolButton() {
set_flat(true);
}
diff --git a/scene/gui/tool_button.h b/scene/gui/tool_button.h
index d243b5559f..58948f798f 100644
--- a/scene/gui/tool_button.h
+++ b/scene/gui/tool_button.h
@@ -37,6 +37,9 @@ class ToolButton : public Button {
public:
ToolButton();
+
+protected:
+ void _notification(int p_what);
};
#endif // TOOL_BUTTON_H
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index bc7b7485d8..6f2d725353 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -464,7 +464,7 @@ void TreeItem::deselect(int p_column) {
_cell_deselected(p_column);
}
-void TreeItem::add_button(int p_column, const Ref<Texture> &p_button, int p_id, bool p_disabled) {
+void TreeItem::add_button(int p_column, const Ref<Texture> &p_button, int p_id, bool p_disabled, const String &p_tooltip) {
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_COND(!p_button.is_valid());
@@ -474,6 +474,7 @@ void TreeItem::add_button(int p_column, const Ref<Texture> &p_button, int p_id,
p_id = cells[p_column].buttons.size();
button.id = p_id;
button.disabled = p_disabled;
+ button.tooltip = p_tooltip;
cells[p_column].buttons.push_back(button);
_changed_notify(p_column);
}
@@ -669,7 +670,7 @@ 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("add_button", "column", "button:Texture", "button_idx", "disabled"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false));
+ 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);
ClassDB::bind_method(D_METHOD("set_button", "column", "button_idx", "button:Texture"), &TreeItem::set_button);
@@ -3290,6 +3291,19 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
if (it) {
+ TreeItem::Cell &c = it->cells[col];
+ int col_width = get_column_width(col);
+ for (int j = c.buttons.size() - 1; j >= 0; j--) {
+ Ref<Texture> b = c.buttons[j].texture;
+ Size2 size = b->get_size() + cache.button_pressed->get_minimum_size();
+ if (pos.x > col_width - size.width) {
+ String tooltip = c.buttons[j].tooltip;
+ if (tooltip != "") {
+ return tooltip;
+ }
+ }
+ col_width -= size.width;
+ }
String ret;
if (it->get_tooltip(col) == "")
ret = it->get_text(col);
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 3830c3e8ca..4bee1adc4b 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -93,10 +93,12 @@ private:
bool disabled;
Ref<Texture> texture;
Color color;
+ String tooltip;
Button() {
id = 0;
disabled = false;
color = Color(1, 1, 1, 1);
+ tooltip = "";
}
};
@@ -180,7 +182,7 @@ public:
void set_icon_max_width(int p_column, int p_max);
int get_icon_max_width(int p_column) const;
- void add_button(int p_column, const Ref<Texture> &p_button, int p_id = -1, bool p_disabled = false);
+ void add_button(int p_column, const Ref<Texture> &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = "");
int get_button_count(int p_column) const;
Ref<Texture> get_button(int p_column, int p_idx) const;
int get_button_id(int p_column, int p_idx) const;