summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp1
-rw-r--r--scene/gui/line_edit.cpp38
-rw-r--r--scene/gui/rich_text_label.h93
-rw-r--r--scene/gui/slider.cpp1
-rw-r--r--scene/gui/tab_container.cpp112
-rw-r--r--scene/gui/tab_container.h4
-rw-r--r--scene/gui/tabs.cpp18
-rw-r--r--scene/gui/tabs.h4
-rw-r--r--scene/gui/text_edit.cpp2
9 files changed, 211 insertions, 62 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index d39f017cad..f8f29632b3 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -645,6 +645,7 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_THEME_CHANGED: {
+ minimum_size_changed();
update();
} break;
case NOTIFICATION_MODAL_CLOSE: {
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 04e03f569e..ab6f80bfa9 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -757,20 +757,17 @@ void LineEdit::_notification(int p_what) {
}
}
- float icon_width = MIN(r_icon->get_width(), r_icon->get_width() * (height - (style->get_margin(MARGIN_TOP) + style->get_margin(MARGIN_BOTTOM))) / r_icon->get_height());
- float icon_height = MIN(r_icon->get_height(), height - (style->get_margin(MARGIN_TOP) + style->get_margin(MARGIN_BOTTOM)));
- Rect2 icon_region = Rect2(Point2(width - icon_width - style->get_margin(MARGIN_RIGHT), height / 2 - icon_height / 2), Size2(icon_width, icon_height));
- draw_texture_rect_region(r_icon, icon_region, Rect2(Point2(), r_icon->get_size()), color_icon);
+ r_icon->draw(ci, Point2(width - r_icon->get_width() - style->get_margin(MARGIN_RIGHT), height / 2 - r_icon->get_height() / 2), color_icon);
if (align == ALIGN_CENTER) {
if (window_pos == 0) {
- x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - cached_text_width - icon_width - style->get_margin(MARGIN_RIGHT) * 2) / 2);
+ x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - cached_text_width - r_icon->get_width() - style->get_margin(MARGIN_RIGHT) * 2) / 2);
}
} else {
- x_ofs = MAX(style->get_margin(MARGIN_LEFT), x_ofs - icon_width - style->get_margin(MARGIN_RIGHT));
+ x_ofs = MAX(style->get_margin(MARGIN_LEFT), x_ofs - r_icon->get_width() - style->get_margin(MARGIN_RIGHT));
}
- ofs_max -= icon_width;
+ ofs_max -= r_icon->get_width();
}
int caret_height = font->get_height() > y_area ? y_area : font->get_height();
@@ -1279,10 +1276,7 @@ void LineEdit::set_cursor_position(int p_pos) {
bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
Ref<Texture> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon;
-
- float icon_width = MIN(r_icon->get_width(), r_icon->get_width() * (get_size().height - (style->get_margin(MARGIN_TOP) + style->get_margin(MARGIN_BOTTOM))) / r_icon->get_height());
-
- window_width -= icon_width;
+ window_width -= r_icon->get_width();
}
if (window_width < 0)
@@ -1361,21 +1355,30 @@ Size2 LineEdit::get_minimum_size() const {
Ref<StyleBox> style = get_stylebox("normal");
Ref<Font> font = get_font("font");
- Size2 min = style->get_minimum_size();
- min.height += font->get_height();
+ Size2 min_size;
// Minimum size of text.
int space_size = font->get_char_size(' ').x;
- int mstext = get_constant("minimum_spaces") * space_size;
+ min_size.width = get_constant("minimum_spaces") * space_size;
if (expand_to_text_length) {
// Add a space because some fonts are too exact, and because cursor needs a bit more when at the end.
- mstext = MAX(mstext, font->get_string_size(text).x + space_size);
+ min_size.width = MAX(min_size.width, font->get_string_size(text).x + space_size);
}
- min.width += mstext;
+ min_size.height = font->get_height();
+
+ // Take icons into account.
+ if (!text.empty() && is_editable() && clear_button_enabled) {
+ min_size.width = MAX(min_size.width, Control::get_icon("clear")->get_width());
+ min_size.height = MAX(min_size.height, Control::get_icon("clear")->get_height());
+ }
+ if (right_icon.is_valid()) {
+ min_size.width = MAX(min_size.width, right_icon->get_width());
+ min_size.height = MAX(min_size.height, right_icon->get_height());
+ }
- return min;
+ return style->get_minimum_size() + min_size;
}
void LineEdit::deselect() {
@@ -1772,7 +1775,6 @@ void LineEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "secret"), "set_secret", "is_secret");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "secret_character"), "set_secret_character", "get_secret_character");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_to_text_length"), "set_expand_to_text_length", "get_expand_to_text_length");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clear_button_enabled"), "set_clear_button_enabled", "is_clear_button_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled");
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 1c212700ef..481f8d9746 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -81,7 +81,7 @@ protected:
static void _bind_methods();
private:
- struct Item;
+ class Item;
struct Line {
@@ -103,8 +103,10 @@ private:
}
};
- struct Item : public Object {
+ class Item : public Object {
+ GDCLASS(Item, Object);
+ public:
int index;
Item *parent;
ItemType type;
@@ -127,8 +129,10 @@ private:
virtual ~Item() { _clear_children(); }
};
- struct ItemFrame : public Item {
+ class ItemFrame : public Item {
+ GDCLASS(ItemFrame, Item);
+ public:
int parent_line;
bool cell;
Vector<Line> lines;
@@ -143,71 +147,95 @@ private:
}
};
- struct ItemText : public Item {
+ class ItemText : public Item {
+ GDCLASS(ItemText, Item);
+ public:
String text;
ItemText() { type = ITEM_TEXT; }
};
- struct ItemImage : public Item {
+ class ItemImage : public Item {
+ GDCLASS(ItemImage, Item);
+ public:
Ref<Texture> image;
ItemImage() { type = ITEM_IMAGE; }
};
- struct ItemFont : public Item {
+ class ItemFont : public Item {
+ GDCLASS(ItemFont, Item);
+ public:
Ref<Font> font;
ItemFont() { type = ITEM_FONT; }
};
- struct ItemColor : public Item {
+ class ItemColor : public Item {
+ GDCLASS(ItemColor, Item);
+ public:
Color color;
ItemColor() { type = ITEM_COLOR; }
};
- struct ItemUnderline : public Item {
+ class ItemUnderline : public Item {
+ GDCLASS(ItemUnderline, Item);
+ public:
ItemUnderline() { type = ITEM_UNDERLINE; }
};
- struct ItemStrikethrough : public Item {
+ class ItemStrikethrough : public Item {
+ GDCLASS(ItemStrikethrough, Item);
+ public:
ItemStrikethrough() { type = ITEM_STRIKETHROUGH; }
};
- struct ItemMeta : public Item {
+ class ItemMeta : public Item {
+ GDCLASS(ItemMeta, Item);
+ public:
Variant meta;
ItemMeta() { type = ITEM_META; }
};
- struct ItemAlign : public Item {
+ class ItemAlign : public Item {
+ GDCLASS(ItemAlign, Item);
+ public:
Align align;
ItemAlign() { type = ITEM_ALIGN; }
};
- struct ItemIndent : public Item {
+ class ItemIndent : public Item {
+ GDCLASS(ItemIndent, Item);
+ public:
int level;
ItemIndent() { type = ITEM_INDENT; }
};
- struct ItemList : public Item {
+ class ItemList : public Item {
+ GDCLASS(ItemList, Item);
+ public:
ListType list_type;
ItemList() { type = ITEM_LIST; }
};
- struct ItemNewline : public Item {
+ class ItemNewline : public Item {
+ GDCLASS(ItemNewline, Item);
+ public:
ItemNewline() { type = ITEM_NEWLINE; }
};
- struct ItemTable : public Item {
+ class ItemTable : public Item {
+ GDCLASS(ItemTable, Item);
+ public:
struct Column {
bool expand;
int expand_ratio;
@@ -221,14 +249,20 @@ private:
ItemTable() { type = ITEM_TABLE; }
};
- struct ItemFade : public Item {
+ class ItemFade : public Item {
+ GDCLASS(ItemFade, Item);
+
+ public:
int starting_index;
int length;
ItemFade() { type = ITEM_FADE; }
};
- struct ItemFX : public Item {
+ class ItemFX : public Item {
+ GDCLASS(ItemFX, Item);
+
+ public:
float elapsed_time;
ItemFX() {
@@ -236,7 +270,10 @@ private:
}
};
- struct ItemShake : public ItemFX {
+ class ItemShake : public ItemFX {
+ GDCLASS(ItemShake, ItemFX);
+
+ public:
int strength;
float rate;
uint64_t _current_rng;
@@ -265,7 +302,10 @@ private:
}
};
- struct ItemWave : public ItemFX {
+ class ItemWave : public ItemFX {
+ GDCLASS(ItemWave, ItemFX);
+
+ public:
float frequency;
float amplitude;
@@ -276,7 +316,10 @@ private:
}
};
- struct ItemTornado : public ItemFX {
+ class ItemTornado : public ItemFX {
+ GDCLASS(ItemTornado, ItemFX);
+
+ public:
float radius;
float frequency;
@@ -287,7 +330,10 @@ private:
}
};
- struct ItemRainbow : public ItemFX {
+ class ItemRainbow : public ItemFX {
+ GDCLASS(ItemRainbow, ItemFX);
+
+ public:
float saturation;
float value;
float frequency;
@@ -300,7 +346,10 @@ private:
}
};
- struct ItemCustomFX : public ItemFX {
+ class ItemCustomFX : public ItemFX {
+ GDCLASS(ItemCustomFX, ItemFX);
+
+ public:
String identifier;
Dictionary environment;
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index b777e77bc3..9f853cf0c8 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -287,7 +287,6 @@ void Slider::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scrollable"), "set_scrollable", "is_scrollable");
ADD_PROPERTY(PropertyInfo(Variant::INT, "tick_count", PROPERTY_HINT_RANGE, "0,4096,1"), "set_ticks", "get_ticks");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ticks_on_borders"), "set_ticks_on_borders", "get_ticks_on_borders");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode");
}
Slider::Slider(Orientation p_orientation) {
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 292d80be9d..a29ba36bad 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -94,7 +94,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
return;
}
- // Do not activate tabs when tabs is empty
+ // Do not activate tabs when tabs is empty.
if (get_tab_count() == 0)
return;
@@ -140,6 +140,76 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
pos.x -= tab_width;
}
}
+
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
+
+ Point2 pos(mm->get_position().x, mm->get_position().y);
+ Size2 size = get_size();
+
+ // Mouse must be on tabs in the tab header area.
+ if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin()) {
+
+ if (menu_hovered || highlight_arrow > -1) {
+ menu_hovered = false;
+ highlight_arrow = -1;
+ update();
+ }
+ return;
+ }
+
+ Ref<Texture> menu = get_icon("menu");
+ if (popup) {
+
+ if (pos.x >= size.width - menu->get_width()) {
+ if (!menu_hovered) {
+ menu_hovered = true;
+ highlight_arrow = -1;
+ update();
+ return;
+ }
+ } else if (menu_hovered) {
+ menu_hovered = false;
+ update();
+ }
+
+ if (menu_hovered) {
+ return;
+ }
+ }
+
+ // Do not activate tabs when tabs is empty.
+ if ((get_tab_count() == 0 || !buttons_visible_cache) && menu_hovered) {
+ highlight_arrow = -1;
+ update();
+ return;
+ }
+
+ int popup_ofs = 0;
+ if (popup) {
+ popup_ofs = menu->get_width();
+ }
+
+ Ref<Texture> increment = get_icon("increment");
+ Ref<Texture> decrement = get_icon("decrement");
+ if (pos.x >= size.width - increment->get_width() - popup_ofs) {
+
+ if (highlight_arrow != 1) {
+ highlight_arrow = 1;
+ update();
+ }
+ } else if (pos.x >= size.width - increment->get_width() - decrement->get_width() - popup_ofs) {
+
+ if (highlight_arrow != 0) {
+ highlight_arrow = 0;
+ update();
+ }
+ } else if (highlight_arrow > -1) {
+ highlight_arrow = -1;
+ update();
+ }
+ }
}
void TabContainer::_notification(int p_what) {
@@ -203,9 +273,11 @@ void TabContainer::_notification(int p_what) {
Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
Ref<Texture> increment = get_icon("increment");
+ Ref<Texture> increment_hl = get_icon("increment_highlight");
Ref<Texture> decrement = get_icon("decrement");
+ Ref<Texture> decrement_hl = get_icon("decrement_highlight");
Ref<Texture> menu = get_icon("menu");
- Ref<Texture> menu_hl = get_icon("menu_hl");
+ Ref<Texture> menu_hl = get_icon("menu_highlight");
Ref<Font> font = get_font("font");
Color font_color_fg = get_color("font_color_fg");
Color font_color_bg = get_color("font_color_bg");
@@ -332,7 +404,7 @@ void TabContainer::_notification(int p_what) {
x = get_size().width;
if (popup) {
x -= menu->get_width();
- if (mouse_x_cache > x)
+ if (menu_hovered)
menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2));
else
menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2));
@@ -340,23 +412,26 @@ void TabContainer::_notification(int p_what) {
// Draw the navigation buttons.
if (buttons_visible_cache) {
- int y_center = header_height / 2;
x -= increment->get_width();
- increment->draw(canvas,
- Point2(x, y_center - (increment->get_height() / 2)),
- Color(1, 1, 1, last_tab_cache < tabs.size() - 1 ? 1.0 : 0.5));
+ if (last_tab_cache < tabs.size() - 1) {
+ draw_texture(highlight_arrow == 1 ? increment_hl : increment, Point2(x, (header_height - increment->get_height()) / 2));
+ } else {
+ draw_texture(increment, Point2(x, (header_height - increment->get_height()) / 2), Color(1, 1, 1, 0.5));
+ }
x -= decrement->get_width();
- decrement->draw(canvas,
- Point2(x, y_center - (decrement->get_height() / 2)),
- Color(1, 1, 1, first_tab_cache > 0 ? 1.0 : 0.5));
+ if (first_tab_cache > 0) {
+ draw_texture(highlight_arrow == 0 ? decrement_hl : decrement, Point2(x, (header_height - decrement->get_height()) / 2));
+ } else {
+ draw_texture(decrement, Point2(x, (header_height - decrement->get_height()) / 2), Color(1, 1, 1, 0.5));
+ }
}
} break;
case NOTIFICATION_THEME_CHANGED: {
minimum_size_changed();
- call_deferred("_on_theme_changed"); //wait until all changed theme
+ call_deferred("_on_theme_changed"); // Wait until all changed theme.
} break;
}
}
@@ -367,6 +442,14 @@ void TabContainer::_on_theme_changed() {
}
}
+void TabContainer::_on_mouse_exited() {
+ if (menu_hovered || highlight_arrow > -1) {
+ menu_hovered = false;
+ highlight_arrow = -1;
+ update();
+ }
+}
+
int TabContainer::_get_tab_width(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
@@ -894,6 +977,7 @@ void TabContainer::set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs) {
bool TabContainer::get_use_hidden_tabs_for_min_size() const {
return use_hidden_tabs_for_min_size;
}
+
void TabContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &TabContainer::_gui_input);
@@ -925,6 +1009,7 @@ void TabContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("_child_renamed_callback"), &TabContainer::_child_renamed_callback);
ClassDB::bind_method(D_METHOD("_on_theme_changed"), &TabContainer::_on_theme_changed);
+ ClassDB::bind_method(D_METHOD("_on_mouse_exited"), &TabContainer::_on_mouse_exited);
ClassDB::bind_method(D_METHOD("_update_current_tab"), &TabContainer::_update_current_tab);
ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
@@ -947,14 +1032,17 @@ TabContainer::TabContainer() {
first_tab_cache = 0;
last_tab_cache = 0;
buttons_visible_cache = false;
+ menu_hovered = false;
+ highlight_arrow = -1;
tabs_ofs_cache = 0;
current = 0;
previous = 0;
- mouse_x_cache = 0;
align = ALIGN_CENTER;
tabs_visible = true;
popup = NULL;
drag_to_rearrange_enabled = false;
tabs_rearrange_group = -1;
use_hidden_tabs_for_min_size = false;
+
+ connect("mouse_exited", this, "_on_mouse_exited");
}
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 0314f86837..0c17ebc3ae 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -46,7 +46,6 @@ public:
};
private:
- int mouse_x_cache;
int first_tab_cache;
int tabs_ofs_cache;
int last_tab_cache;
@@ -54,6 +53,8 @@ private:
int previous;
bool tabs_visible;
bool buttons_visible_cache;
+ bool menu_hovered;
+ int highlight_arrow;
TabAlign align;
Control *_get_tab(int p_idx) const;
int _get_top_margin() const;
@@ -65,6 +66,7 @@ private:
Vector<Control *> _get_tabs() const;
int _get_tab_width(int p_index) const;
void _on_theme_changed();
+ void _on_mouse_exited();
void _update_current_tab();
protected:
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 7b0836cd28..93b091e8d0 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -226,12 +226,6 @@ void Tabs::_notification(int p_what) {
minimum_size_changed();
update();
} break;
- case NOTIFICATION_MOUSE_EXIT: {
- rb_hover = -1;
- cb_hover = -1;
- hover = -1;
- update();
- } break;
case NOTIFICATION_RESIZED: {
_update_cache();
_ensure_no_over_offset();
@@ -597,6 +591,15 @@ void Tabs::_update_cache() {
}
}
+void Tabs::_on_mouse_exited() {
+
+ rb_hover = -1;
+ cb_hover = -1;
+ hover = -1;
+ highlight_arrow = -1;
+ update();
+}
+
void Tabs::add_tab(const String &p_str, const Ref<Texture> &p_icon) {
Tab t;
@@ -948,6 +951,7 @@ void Tabs::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &Tabs::_gui_input);
ClassDB::bind_method(D_METHOD("_update_hover"), &Tabs::_update_hover);
+ ClassDB::bind_method(D_METHOD("_on_mouse_exited"), &Tabs::_on_mouse_exited);
ClassDB::bind_method(D_METHOD("get_tab_count"), &Tabs::get_tab_count);
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &Tabs::set_current_tab);
ClassDB::bind_method(D_METHOD("get_current_tab"), &Tabs::get_current_tab);
@@ -1024,4 +1028,6 @@ Tabs::Tabs() {
hover = -1;
drag_to_rearrange_enabled = false;
tabs_rearrange_group = -1;
+
+ connect("mouse_exited", this, "_on_mouse_exited");
}
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 7c54f1acf2..a762b5b9cb 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -89,7 +89,7 @@ private:
bool cb_pressing;
CloseButtonDisplayPolicy cb_displaypolicy;
- int hover; // hovered tab
+ int hover; // Hovered tab.
int min_width;
bool scrolling_enabled;
bool drag_to_rearrange_enabled;
@@ -101,6 +101,8 @@ private:
void _update_hover();
void _update_cache();
+ void _on_mouse_exited();
+
protected:
void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index d5f1d317c7..75c845b8db 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -6110,7 +6110,7 @@ bool TextEdit::is_indent_using_spaces() const {
}
void TextEdit::set_indent_size(const int p_size) {
- ERR_FAIL_COND(p_size <= 0);
+ ERR_FAIL_COND_MSG(p_size <= 0, "Indend size must be greater than 0.");
indent_size = p_size;
text.set_indent_size(p_size);