summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp4
-rw-r--r--scene/gui/gradient_edit.cpp28
-rw-r--r--scene/gui/gradient_edit.h2
-rw-r--r--scene/gui/item_list.cpp2
-rw-r--r--scene/gui/popup_menu.cpp6
-rw-r--r--scene/gui/rich_text_label.cpp74
-rw-r--r--scene/gui/rich_text_label.h8
-rw-r--r--scene/gui/shortcut.cpp33
-rw-r--r--scene/gui/shortcut.h12
9 files changed, 88 insertions, 81 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 75a4464a40..82f4a216b8 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -345,7 +345,7 @@ void BaseButton::_unhandled_key_input(Ref<InputEvent> p_event) {
return;
}
- if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) {
+ if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->matches_event(p_event)) {
on_action_event(p_event);
accept_event();
}
@@ -353,7 +353,7 @@ void BaseButton::_unhandled_key_input(Ref<InputEvent> p_event) {
String BaseButton::get_tooltip(const Point2 &p_pos) const {
String tooltip = Control::get_tooltip(p_pos);
- if (shortcut_in_tooltip && shortcut.is_valid() && shortcut->is_valid()) {
+ if (shortcut_in_tooltip && shortcut.is_valid() && shortcut->has_valid_event()) {
String text = shortcut->get_name() + " (" + shortcut->get_as_text() + ")";
if (tooltip != String() && shortcut->get_name().nocasecmp_to(tooltip) != 0) {
text += "\n" + tooltip;
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index 83ecf1d534..706d3b48c2 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -49,9 +49,6 @@ GradientEdit::GradientEdit() {
popup->add_child(picker);
add_child(popup);
-
- checker = Ref<ImageTexture>(memnew(ImageTexture));
- Ref<Image> img = memnew(Image(checker_bg_png));
}
int GradientEdit::_get_point_from_pos(int x) {
@@ -311,7 +308,7 @@ void GradientEdit::_notification(int p_what) {
int total_w = get_size().width - get_size().height - SPACING;
//Draw checker pattern for ramp
- _draw_checker(0, 0, total_w, h);
+ draw_texture_rect(get_theme_icon("GuiMiniCheckerboard", "EditorIcons"), Rect2(0, 0, total_w, h), true);
//Draw color ramp
Gradient::Point prev;
@@ -378,7 +375,7 @@ void GradientEdit::_notification(int p_what) {
}
//Draw "button" for color selector
- _draw_checker(total_w + SPACING, 0, h, h);
+ draw_texture_rect(get_theme_icon("GuiMiniCheckerboard", "EditorIcons"), Rect2(total_w + SPACING, 0, h, h), true);
if (grabbed != -1) {
//Draw with selection color
draw_rect(Rect2(total_w + SPACING, 0, h, h), points[grabbed].color);
@@ -405,27 +402,6 @@ void GradientEdit::_notification(int p_what) {
}
}
-void GradientEdit::_draw_checker(int x, int y, int w, int h) {
- //Draw it with polygon to insert UVs for scale
- Vector<Vector2> backPoints;
- backPoints.push_back(Vector2(x, y));
- backPoints.push_back(Vector2(x, y + h));
- backPoints.push_back(Vector2(x + w, y + h));
- backPoints.push_back(Vector2(x + w, y));
- Vector<Color> colorPoints;
- colorPoints.push_back(Color(1, 1, 1, 1));
- colorPoints.push_back(Color(1, 1, 1, 1));
- colorPoints.push_back(Color(1, 1, 1, 1));
- colorPoints.push_back(Color(1, 1, 1, 1));
- Vector<Vector2> uvPoints;
- //Draw checker pattern pixel-perfect and scale it by 2.
- uvPoints.push_back(Vector2(x, y));
- uvPoints.push_back(Vector2(x, y + h * .5f / checker->get_height()));
- uvPoints.push_back(Vector2(x + w * .5f / checker->get_width(), y + h * .5f / checker->get_height()));
- uvPoints.push_back(Vector2(x + w * .5f / checker->get_width(), y));
- draw_polygon(backPoints, colorPoints, uvPoints, checker);
-}
-
Size2 GradientEdit::get_minimum_size() const {
return Vector2(0, 16);
}
diff --git a/scene/gui/gradient_edit.h b/scene/gui/gradient_edit.h
index eb7367d598..3d83a02429 100644
--- a/scene/gui/gradient_edit.h
+++ b/scene/gui/gradient_edit.h
@@ -42,8 +42,6 @@ class GradientEdit : public Control {
PopupPanel *popup;
ColorPicker *picker;
- Ref<ImageTexture> checker;
-
bool grabbing = false;
int grabbed = -1;
Vector<Gradient::Point> points;
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index fdf6181f1d..258d65112a 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -245,6 +245,7 @@ void ItemList::set_item_custom_bg_color(int p_idx, const Color &p_custom_bg_colo
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].custom_bg = p_custom_bg_color;
+ update();
}
Color ItemList::get_item_custom_bg_color(int p_idx) const {
@@ -257,6 +258,7 @@ void ItemList::set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_colo
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].custom_fg = p_custom_fg_color;
+ update();
}
Color ItemList::get_item_custom_fg_color(int p_idx) const {
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 490548fce0..44f7200cd7 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -74,7 +74,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
size.width += items[i].text_buf->get_size().x;
size.height += vseparation;
- if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
+ if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->has_valid_event())) {
int accel_w = hseparation * 2;
accel_w += items[i].accel_text_buf->get_size().x;
accel_max_w = MAX(accel_w, accel_max_w);
@@ -635,7 +635,7 @@ void PopupMenu::_draw_items() {
}
// Accelerator / Shortcut
- if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
+ if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->has_valid_event())) {
if (rtl) {
item_ofs.x = scroll_width + style->get_margin(SIDE_LEFT) + item_end_padding;
} else {
@@ -1301,7 +1301,7 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
continue;
}
- if (items[i].shortcut.is_valid() && items[i].shortcut->is_shortcut(p_event) && (items[i].shortcut_is_global || !p_for_global_only)) {
+ if (items[i].shortcut.is_valid() && items[i].shortcut->matches_event(p_event) && (items[i].shortcut_is_global || !p_for_global_only)) {
activate_item(i);
return true;
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 3925e0c38e..3cb1f7d2bc 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -2289,7 +2289,7 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
}
}
-void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color, VAlign p_align) {
+void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color, InlineAlign p_align) {
if (current->type == ITEM_TABLE) {
return;
}
@@ -2534,7 +2534,7 @@ void RichTextLabel::push_meta(const Variant &p_meta) {
_add_item(item, true);
}
-void RichTextLabel::push_table(int p_columns, VAlign p_align) {
+void RichTextLabel::push_table(int p_columns, InlineAlign p_align) {
ERR_FAIL_COND(p_columns < 1);
ItemTable *item = memnew(ItemTable);
@@ -2897,18 +2897,35 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
columns = 1;
}
- VAlign align = VALIGN_TOP;
- if (subtag.size() > 1) {
+ int align = INLINE_ALIGN_TOP;
+ if (subtag.size() > 2) {
if (subtag[1] == "top" || subtag[1] == "t") {
- align = VALIGN_TOP;
+ align = INLINE_ALIGN_TOP_TO;
} else if (subtag[1] == "center" || subtag[1] == "c") {
- align = VALIGN_CENTER;
+ align = INLINE_ALIGN_CENTER_TO;
} else if (subtag[1] == "bottom" || subtag[1] == "b") {
- align = VALIGN_BOTTOM;
+ align = INLINE_ALIGN_BOTTOM_TO;
+ }
+ if (subtag[2] == "top" || subtag[2] == "t") {
+ align |= INLINE_ALIGN_TO_TOP;
+ } else if (subtag[2] == "center" || subtag[2] == "c") {
+ align |= INLINE_ALIGN_TO_CENTER;
+ } else if (subtag[2] == "baseline" || subtag[2] == "l") {
+ align |= INLINE_ALIGN_TO_BASELINE;
+ } else if (subtag[2] == "bottom" || subtag[2] == "b") {
+ align |= INLINE_ALIGN_TO_BOTTOM;
+ }
+ } else if (subtag.size() > 1) {
+ if (subtag[1] == "top" || subtag[1] == "t") {
+ align = INLINE_ALIGN_TOP;
+ } else if (subtag[1] == "center" || subtag[1] == "c") {
+ align = INLINE_ALIGN_CENTER;
+ } else if (subtag[1] == "bottom" || subtag[1] == "b") {
+ align = INLINE_ALIGN_BOTTOM;
}
}
- push_table(columns, align);
+ push_table(columns, (InlineAlign)align);
pos = brk_end + 1;
tag_stack.push_front("table");
} else if (tag == "cell") {
@@ -3187,15 +3204,34 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pos = end;
tag_stack.push_front(bbcode_name);
} else if (tag.begins_with("img")) {
- VAlign align = VALIGN_TOP;
+ int align = INLINE_ALIGN_CENTER;
if (tag.begins_with("img=")) {
- String al = tag.substr(4, tag.length());
- if (al == "top" || al == "t") {
- align = VALIGN_TOP;
- } else if (al == "center" || al == "c") {
- align = VALIGN_CENTER;
- } else if (al == "bottom" || al == "b") {
- align = VALIGN_BOTTOM;
+ Vector<String> subtag = tag.substr(4, tag.length()).split(",");
+ if (subtag.size() > 1) {
+ if (subtag[0] == "top" || subtag[0] == "t") {
+ align = INLINE_ALIGN_TOP_TO;
+ } else if (subtag[0] == "center" || subtag[0] == "c") {
+ align = INLINE_ALIGN_CENTER_TO;
+ } else if (subtag[0] == "bottom" || subtag[0] == "b") {
+ align = INLINE_ALIGN_BOTTOM_TO;
+ }
+ if (subtag[1] == "top" || subtag[1] == "t") {
+ align |= INLINE_ALIGN_TO_TOP;
+ } else if (subtag[1] == "center" || subtag[1] == "c") {
+ align |= INLINE_ALIGN_TO_CENTER;
+ } else if (subtag[1] == "baseline" || subtag[1] == "l") {
+ align |= INLINE_ALIGN_TO_BASELINE;
+ } else if (subtag[1] == "bottom" || subtag[1] == "b") {
+ align |= INLINE_ALIGN_TO_BOTTOM;
+ }
+ } else if (subtag.size() > 0) {
+ if (subtag[0] == "top" || subtag[0] == "t") {
+ align = INLINE_ALIGN_TOP;
+ } else if (subtag[0] == "center" || subtag[0] == "c") {
+ align = INLINE_ALIGN_CENTER;
+ } else if (subtag[0] == "bottom" || subtag[0] == "b") {
+ align = INLINE_ALIGN_BOTTOM;
+ }
}
}
@@ -3236,7 +3272,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
}
- add_image(texture, width, height, color, align);
+ add_image(texture, width, height, color, (InlineAlign)align);
}
pos = end;
@@ -3961,7 +3997,7 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text);
ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text);
ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text);
- ClassDB::bind_method(D_METHOD("add_image", "image", "width", "height", "color", "inline_align"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(VALIGN_TOP));
+ ClassDB::bind_method(D_METHOD("add_image", "image", "width", "height", "color", "inline_align"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(INLINE_ALIGN_CENTER));
ClassDB::bind_method(D_METHOD("newline"), &RichTextLabel::add_newline);
ClassDB::bind_method(D_METHOD("remove_line", "line"), &RichTextLabel::remove_line);
ClassDB::bind_method(D_METHOD("push_font", "font"), &RichTextLabel::push_font);
@@ -3981,7 +4017,7 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("push_meta", "data"), &RichTextLabel::push_meta);
ClassDB::bind_method(D_METHOD("push_underline"), &RichTextLabel::push_underline);
ClassDB::bind_method(D_METHOD("push_strikethrough"), &RichTextLabel::push_strikethrough);
- ClassDB::bind_method(D_METHOD("push_table", "columns", "inline_align"), &RichTextLabel::push_table, DEFVAL(VALIGN_TOP));
+ ClassDB::bind_method(D_METHOD("push_table", "columns", "inline_align"), &RichTextLabel::push_table, DEFVAL(INLINE_ALIGN_TOP));
ClassDB::bind_method(D_METHOD("push_dropcap", "string", "font", "size", "dropcap_margins", "color", "outline_size", "outline_color"), &RichTextLabel::push_dropcap, DEFVAL(Rect2()), DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(Color(0, 0, 0, 0)));
ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand);
ClassDB::bind_method(D_METHOD("set_cell_row_background_color", "odd_row_bg", "even_row_bg"), &RichTextLabel::set_cell_row_background_color);
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 999d8b05fd..a73176ba7e 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -161,7 +161,7 @@ private:
struct ItemImage : public Item {
Ref<Texture2D> image;
- VAlign inline_align = VALIGN_TOP;
+ InlineAlign inline_align = INLINE_ALIGN_CENTER;
Size2 size;
Color color;
ItemImage() { type = ITEM_IMAGE; }
@@ -248,7 +248,7 @@ private:
int total_width = 0;
int total_height = 0;
- VAlign inline_align = VALIGN_TOP;
+ InlineAlign inline_align = INLINE_ALIGN_TOP;
ItemTable() { type = ITEM_TABLE; }
};
@@ -463,7 +463,7 @@ private:
public:
String get_text();
void add_text(const String &p_text);
- void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), VAlign p_align = VALIGN_TOP);
+ void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), InlineAlign p_align = INLINE_ALIGN_CENTER);
void add_newline();
bool remove_line(const int p_line);
void push_dropcap(const String &p_string, const Ref<Font> &p_font, int p_size, const Rect2 &p_dropcap_margins = Rect2(), const Color &p_color = Color(1, 1, 1), int p_ol_size = 0, const Color &p_ol_color = Color(0, 0, 0, 0));
@@ -484,7 +484,7 @@ public:
void push_indent(int p_level);
void push_list(int p_level, ListType p_list, bool p_capitalize);
void push_meta(const Variant &p_meta);
- void push_table(int p_columns, VAlign p_align = VALIGN_TOP);
+ void push_table(int p_columns, InlineAlign p_align = INLINE_ALIGN_TOP);
void push_fade(int p_start_index, int p_length);
void push_shake(int p_strength, float p_rate);
void push_wave(float p_frequency, float p_amplitude);
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
index 962c6dcc60..885a51e058 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -32,42 +32,39 @@
#include "core/os/keyboard.h"
-void Shortcut::set_shortcut(const Ref<InputEvent> &p_shortcut) {
- shortcut = p_shortcut;
+void Shortcut::set_event(const Ref<InputEvent> &p_event) {
+ event = p_event;
emit_changed();
}
-Ref<InputEvent> Shortcut::get_shortcut() const {
- return shortcut;
+Ref<InputEvent> Shortcut::get_event() const {
+ return event;
}
-bool Shortcut::is_shortcut(const Ref<InputEvent> &p_event) const {
- return shortcut.is_valid() && shortcut->is_match(p_event, true);
+bool Shortcut::matches_event(const Ref<InputEvent> &p_event) const {
+ return event.is_valid() && event->is_match(p_event, true);
}
String Shortcut::get_as_text() const {
- if (shortcut.is_valid()) {
- return shortcut->as_text();
+ if (event.is_valid()) {
+ return event->as_text();
} else {
return "None";
}
}
-bool Shortcut::is_valid() const {
- return shortcut.is_valid();
+bool Shortcut::has_valid_event() const {
+ return event.is_valid();
}
void Shortcut::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_shortcut", "event"), &Shortcut::set_shortcut);
- ClassDB::bind_method(D_METHOD("get_shortcut"), &Shortcut::get_shortcut);
+ ClassDB::bind_method(D_METHOD("set_event", "event"), &Shortcut::set_event);
+ ClassDB::bind_method(D_METHOD("get_event"), &Shortcut::get_event);
- ClassDB::bind_method(D_METHOD("is_valid"), &Shortcut::is_valid);
+ ClassDB::bind_method(D_METHOD("has_valid_event"), &Shortcut::has_valid_event);
- ClassDB::bind_method(D_METHOD("is_shortcut", "event"), &Shortcut::is_shortcut);
+ ClassDB::bind_method(D_METHOD("matches_event", "event"), &Shortcut::matches_event);
ClassDB::bind_method(D_METHOD("get_as_text"), &Shortcut::get_as_text);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), "set_shortcut", "get_shortcut");
-}
-
-Shortcut::Shortcut() {
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), "set_event", "get_event");
}
diff --git a/scene/gui/shortcut.h b/scene/gui/shortcut.h
index ea91f29b5d..249dd1971f 100644
--- a/scene/gui/shortcut.h
+++ b/scene/gui/shortcut.h
@@ -37,20 +37,18 @@
class Shortcut : public Resource {
GDCLASS(Shortcut, Resource);
- Ref<InputEvent> shortcut;
+ Ref<InputEvent> event;
protected:
static void _bind_methods();
public:
- void set_shortcut(const Ref<InputEvent> &p_shortcut);
- Ref<InputEvent> get_shortcut() const;
- bool is_shortcut(const Ref<InputEvent> &p_event) const;
- bool is_valid() const;
+ void set_event(const Ref<InputEvent> &p_shortcut);
+ Ref<InputEvent> get_event() const;
+ bool matches_event(const Ref<InputEvent> &p_event) const;
+ bool has_valid_event() const;
String get_as_text() const;
-
- Shortcut();
};
#endif // SHORTCUT_H