summaryrefslogtreecommitdiff
path: root/scene/gui/tabs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/tabs.cpp')
-rw-r--r--scene/gui/tabs.cpp102
1 files changed, 45 insertions, 57 deletions
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index d332a5cbc6..4a7285a154 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -38,11 +38,11 @@
#include "scene/gui/texture_rect.h"
Size2 Tabs::get_minimum_size() const {
- Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg");
- Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
+ Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
- int y_margin = MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height);
+ int y_margin = MAX(MAX(tab_unselected->get_minimum_size().height, tab_selected->get_minimum_size().height), tab_disabled->get_minimum_size().height);
Size2 ms(0, 0);
@@ -61,9 +61,9 @@ Size2 Tabs::get_minimum_size() const {
if (tabs[i].disabled) {
ms.width += tab_disabled->get_minimum_size().width;
} else if (current == i) {
- ms.width += tab_fg->get_minimum_size().width;
+ ms.width += tab_selected->get_minimum_size().width;
} else {
- ms.width += tab_bg->get_minimum_size().width;
+ ms.width += tab_unselected->get_minimum_size().width;
}
if (tabs[i].right_button.is_valid()) {
@@ -71,7 +71,7 @@ Size2 Tabs::get_minimum_size() const {
Size2 bms = rb->get_size();
bms.width += get_theme_constant("hseparation");
ms.width += bms.width;
- ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height);
+ ms.height = MAX(bms.height + tab_unselected->get_minimum_size().height, ms.height);
}
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
@@ -79,7 +79,7 @@ Size2 Tabs::get_minimum_size() const {
Size2 bms = cb->get_size();
bms.width += get_theme_constant("hseparation");
ms.width += bms.width;
- ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height);
+ ms.height = MAX(bms.height + tab_unselected->get_minimum_size().height, ms.height);
}
}
@@ -122,7 +122,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
- if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {
+ if (mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP && !mb->get_command()) {
if (scrolling_enabled && buttons_visible) {
if (offset > 0) {
offset--;
@@ -131,7 +131,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
}
- if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) {
+ if (mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN && !mb->get_command()) {
if (scrolling_enabled && buttons_visible) {
if (missing_right) {
offset++;
@@ -140,7 +140,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
}
- if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+ if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (rb_hover != -1) {
//pressed
emit_signal("right_button_pressed", rb_hover);
@@ -150,7 +150,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
update();
}
- if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+ if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (cb_hover != -1) {
//pressed
emit_signal("tab_closed", cb_hover);
@@ -160,7 +160,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
update();
}
- if (mb->is_pressed() && (mb->get_button_index() == BUTTON_LEFT || (select_with_rmb && mb->get_button_index() == BUTTON_RIGHT))) {
+ if (mb->is_pressed() && (mb->get_button_index() == MOUSE_BUTTON_LEFT || (select_with_rmb && mb->get_button_index() == MOUSE_BUTTON_RIGHT))) {
// clicks
Point2 pos(mb->get_position().x, mb->get_position().y);
@@ -268,13 +268,16 @@ void Tabs::_notification(int p_what) {
_update_cache();
RID ci = get_canvas_item();
- Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg");
- Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
+ Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
- Color color_fg = get_theme_color("font_color_fg");
- Color color_bg = get_theme_color("font_color_bg");
- Color color_disabled = get_theme_color("font_color_disabled");
+ Color font_selected_color = get_theme_color("font_selected_color");
+ Color font_unselected_color = get_theme_color("font_unselected_color");
+ Color font_disabled_color = get_theme_color("font_disabled_color");
Ref<Texture2D> close = get_theme_icon("close");
+ Color font_outline_color = get_theme_color("font_outline_color");
+ int outline_size = get_theme_constant("outline_size");
+
Vector2 size = get_size();
bool rtl = is_layout_rtl();
@@ -316,13 +319,13 @@ void Tabs::_notification(int p_what) {
if (tabs[i].disabled) {
sb = tab_disabled;
- col = color_disabled;
+ col = font_disabled_color;
} else if (i == current) {
- sb = tab_fg;
- col = color_fg;
+ sb = tab_selected;
+ col = font_selected_color;
} else {
- sb = tab_bg;
- col = color_bg;
+ sb = tab_unselected;
+ col = font_unselected_color;
}
if (w + lsize > limit) {
@@ -357,9 +360,17 @@ void Tabs::_notification(int p_what) {
}
if (rtl) {
- tabs[i].text_buf->draw(ci, Point2i(size.width - w - tabs[i].text_buf->get_size().x, sb->get_margin(SIDE_TOP) + ((sb_rect.size.y - sb_ms.y) - tabs[i].text_buf->get_size().y) / 2), col);
+ Vector2 text_pos = Point2i(size.width - w - tabs[i].text_buf->get_size().x, sb->get_margin(SIDE_TOP) + ((sb_rect.size.y - sb_ms.y) - tabs[i].text_buf->get_size().y) / 2);
+ if (outline_size > 0 && font_outline_color.a > 0) {
+ tabs[i].text_buf->draw_outline(ci, text_pos, outline_size, font_outline_color);
+ }
+ tabs[i].text_buf->draw(ci, text_pos, col);
} else {
- tabs[i].text_buf->draw(ci, Point2i(w, sb->get_margin(SIDE_TOP) + ((sb_rect.size.y - sb_ms.y) - tabs[i].text_buf->get_size().y) / 2), col);
+ Vector2 text_pos = Point2i(w, sb->get_margin(SIDE_TOP) + ((sb_rect.size.y - sb_ms.y) - tabs[i].text_buf->get_size().y) / 2);
+ if (outline_size > 0 && font_outline_color.a > 0) {
+ tabs[i].text_buf->draw_outline(ci, text_pos, outline_size, font_outline_color);
+ }
+ tabs[i].text_buf->draw(ci, text_pos, col);
}
w += tabs[i].size_text;
@@ -481,7 +492,6 @@ void Tabs::set_current_tab(int p_current) {
previous = current;
current = p_current;
- _change_notify("current_tab");
_update_cache();
update();
@@ -652,8 +662,8 @@ void Tabs::_update_hover() {
void Tabs::_update_cache() {
Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
- Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg");
- Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
+ Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
Ref<Texture2D> incr = get_theme_icon("increment");
Ref<Texture2D> decr = get_theme_icon("decrement");
int limit = get_size().width - incr->get_width() - decr->get_width();
@@ -683,9 +693,9 @@ void Tabs::_update_cache() {
if (tabs[i].disabled) {
sb = tab_disabled;
} else if (i == current) {
- sb = tab_fg;
+ sb = tab_selected;
} else {
- sb = tab_bg;
+ sb = tab_unselected;
}
int lsize = tabs[i].size_cache;
int slen = tabs[i].size_text;
@@ -918,8 +928,8 @@ void Tabs::move_tab(int from, int to) {
int Tabs::get_tab_width(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, tabs.size(), 0);
- Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg");
- Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg");
+ Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected");
+ Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected");
Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled");
int x = 0;
@@ -937,9 +947,9 @@ int Tabs::get_tab_width(int p_idx) const {
if (tabs[p_idx].disabled) {
x += tab_disabled->get_minimum_size().width;
} else if (current == p_idx) {
- x += tab_fg->get_minimum_size().width;
+ x += tab_selected->get_minimum_size().width;
} else {
- x += tab_bg->get_minimum_size().width;
+ x += tab_unselected->get_minimum_size().width;
}
if (tabs[p_idx].right_button.is_valid()) {
@@ -1137,27 +1147,5 @@ void Tabs::_bind_methods() {
}
Tabs::Tabs() {
- current = 0;
- previous = 0;
- tab_align = ALIGN_CENTER;
- rb_hover = -1;
- rb_pressing = false;
- highlight_arrow = -1;
-
- cb_hover = -1;
- cb_pressing = false;
- cb_displaypolicy = CLOSE_BUTTON_SHOW_NEVER;
- offset = 0;
- max_drawn_tab = 0;
-
- select_with_rmb = false;
-
- min_width = 0;
- scrolling_enabled = true;
- buttons_visible = false;
- hover = -1;
- drag_to_rearrange_enabled = false;
- tabs_rearrange_group = -1;
-
connect("mouse_exited", callable_mp(this, &Tabs::_on_mouse_exited));
}