summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/color_picker.cpp10
-rw-r--r--scene/gui/control.cpp16
-rw-r--r--scene/gui/control.h1
-rw-r--r--scene/gui/file_dialog.cpp14
-rw-r--r--scene/gui/file_dialog.h1
-rw-r--r--scene/gui/label.cpp8
-rw-r--r--scene/gui/option_button.cpp2
-rw-r--r--scene/gui/reference_rect.cpp21
-rw-r--r--scene/gui/reference_rect.h6
-rw-r--r--scene/gui/text_edit.cpp94
-rw-r--r--scene/gui/text_edit.h8
11 files changed, 129 insertions, 52 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 58a0762469..b197971b61 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -173,7 +173,7 @@ void ColorPicker::_value_changed(double) {
color.set_hsv(scroll[0]->get_value() / 360.0,
scroll[1]->get_value() / 100.0,
scroll[2]->get_value() / 100.0,
- scroll[3]->get_value() / 100.0);
+ scroll[3]->get_value() / 255.0);
} else {
for (int i = 0; i < 4; i++) {
color.components[i] = scroll[i]->get_value() / (raw_mode_enabled ? 1.0 : 255.0);
@@ -209,17 +209,17 @@ void ColorPicker::_update_color(bool p_update_sliders) {
if (hsv_mode_enabled) {
for (int i = 0; i < 4; i++) {
- scroll[i]->set_step(0.1);
+ scroll[i]->set_step(1.0);
}
- scroll[0]->set_max(360);
+ scroll[0]->set_max(359);
scroll[0]->set_value(h * 360.0);
scroll[1]->set_max(100);
scroll[1]->set_value(s * 100.0);
scroll[2]->set_max(100);
scroll[2]->set_value(v * 100.0);
- scroll[3]->set_max(100);
- scroll[3]->set_value(color.components[3] * 100.0);
+ scroll[3]->set_max(255);
+ scroll[3]->set_value(color.components[3] * 255.0);
} else {
for (int i = 0; i < 4; i++) {
if (raw_mode_enabled) {
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 6e0e26312f..eccd42cb9f 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2249,6 +2249,7 @@ Ref<Theme> Control::get_theme() const {
void Control::set_tooltip(const String &p_tooltip) {
data.tooltip = p_tooltip;
+ update_configuration_warning();
}
String Control::get_tooltip(const Point2 &p_pos) const {
@@ -2540,6 +2541,7 @@ void Control::set_mouse_filter(MouseFilter p_filter) {
ERR_FAIL_INDEX(p_filter, 3);
data.mouse_filter = p_filter;
+ update_configuration_warning();
}
Control::MouseFilter Control::get_mouse_filter() const {
@@ -2703,6 +2705,20 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List
}
}
}
+
+String Control::get_configuration_warning() const {
+ String warning = CanvasItem::get_configuration_warning();
+
+ if (data.mouse_filter == MOUSE_FILTER_IGNORE && data.tooltip != "") {
+ if (warning != String()) {
+ warning += "\n";
+ }
+ warning += TTR("The Hint Tooltip won't be displayed as the control's Mouse Filter is set to \"Ignore\". To solve this, set the Mouse Filter to \"Stop\" or \"Pass\".");
+ }
+
+ return warning;
+}
+
void Control::set_clip_contents(bool p_clip) {
data.clip_contents = p_clip;
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 2489a5eda4..1a59a6d2e4 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -487,6 +487,7 @@ public:
bool is_visibility_clip_disabled() const;
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
+ virtual String get_configuration_warning() const;
Control();
~Control();
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index ba4d390fc5..04fb991f78 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -381,6 +381,18 @@ void FileDialog::_tree_item_activated() {
}
}
+void FileDialog::update_file_name() {
+ int idx = filter->get_selected() - 1;
+ if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) {
+ if (idx == -1) idx += 1;
+ String filter_str = filters[idx];
+ String file_str = file->get_text();
+ String base_name = file_str.get_basename();
+ file_str = base_name + "." + filter_str.strip_edges().to_lower();
+ file->set_text(file_str);
+ }
+}
+
void FileDialog::update_file_list() {
tree->clear();
@@ -506,6 +518,7 @@ void FileDialog::update_file_list() {
void FileDialog::_filter_selected(int) {
+ update_file_name();
update_file_list();
}
@@ -797,6 +810,7 @@ void FileDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_select_drive"), &FileDialog::_select_drive);
ClassDB::bind_method(D_METHOD("_make_dir"), &FileDialog::_make_dir);
ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileDialog::_make_dir_confirm);
+ ClassDB::bind_method(D_METHOD("_update_file_name"), &FileDialog::update_file_name);
ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list);
ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir);
ClassDB::bind_method(D_METHOD("_go_up"), &FileDialog::_go_up);
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 9f7ea1a2f2..191af5fef3 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -102,6 +102,7 @@ private:
bool invalidated;
void update_dir();
+ void update_file_name();
void update_file_list();
void update_filters();
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index e18387a52e..510f1b18ad 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -247,11 +247,11 @@ void Label::_notification(int p_what) {
n = String::char_uppercase(n);
}
- float move = font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow, false);
+ float move = drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow);
if (use_outline) {
- font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow, false);
- font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow, false);
- font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow, false);
+ drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow);
+ drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow);
+ drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow);
}
x_ofs_shadow += move;
chars_total_shadow++;
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 872402e9e1..58671655dc 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -282,7 +282,7 @@ void OptionButton::_set_items(const Array &p_items) {
void OptionButton::get_translatable_strings(List<String> *p_strings) const {
- return popup->get_translatable_strings(p_strings);
+ popup->get_translatable_strings(p_strings);
}
void OptionButton::_bind_methods() {
diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp
index 553e133946..052c8ccd05 100644
--- a/scene/gui/reference_rect.cpp
+++ b/scene/gui/reference_rect.cpp
@@ -38,26 +38,41 @@ void ReferenceRect::_notification(int p_what) {
if (!is_inside_tree())
return;
- if (Engine::get_singleton()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint() || !editor_only)
draw_rect(Rect2(Point2(), get_size()), border_color, false);
}
}
-void ReferenceRect::set_border_color(const Color &color) {
- border_color = color;
+void ReferenceRect::set_border_color(const Color &p_color) {
+ border_color = p_color;
+ update();
}
Color ReferenceRect::get_border_color() const {
return border_color;
}
+void ReferenceRect::set_editor_only(const bool &p_enabled) {
+ editor_only = p_enabled;
+ update();
+}
+
+bool ReferenceRect::get_editor_only() const {
+ return editor_only;
+}
+
void ReferenceRect::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_border_color"), &ReferenceRect::get_border_color);
ClassDB::bind_method(D_METHOD("set_border_color", "color"), &ReferenceRect::set_border_color);
+ ClassDB::bind_method(D_METHOD("get_editor_only"), &ReferenceRect::get_editor_only);
+ ClassDB::bind_method(D_METHOD("set_editor_only", "enabled"), &ReferenceRect::set_editor_only);
+
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "border_color"), "set_border_color", "get_border_color");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "get_editor_only");
}
ReferenceRect::ReferenceRect() {
border_color = Color(1, 0, 0);
+ editor_only = true;
}
diff --git a/scene/gui/reference_rect.h b/scene/gui/reference_rect.h
index de3ccaeeca..7a88333cf2 100644
--- a/scene/gui/reference_rect.h
+++ b/scene/gui/reference_rect.h
@@ -37,6 +37,7 @@ class ReferenceRect : public Control {
GDCLASS(ReferenceRect, Control);
Color border_color;
+ bool editor_only;
protected:
void _notification(int p_what);
@@ -45,8 +46,11 @@ protected:
public:
ReferenceRect();
- void set_border_color(const Color &color);
+ void set_border_color(const Color &p_color);
Color get_border_color() const;
+
+ void set_editor_only(const bool &p_enabled);
+ bool get_editor_only() const;
};
#endif // REFERENCE_RECT_H
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index fdd21f525b..9242e7997a 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -35,6 +35,7 @@
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/project_settings.h"
+#include "core/script_language.h"
#include "scene/main/viewport.h"
#ifdef TOOLS_ENABLED
@@ -681,6 +682,13 @@ void TextEdit::_notification(int p_what) {
}
}
+ if (line_length_guideline) {
+ int x = xmargin_beg + cache.font->get_char_size('0').width * line_length_guideline_col - cursor.x_ofs;
+ if (x > xmargin_beg && x < xmargin_end) {
+ VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, size.height), cache.line_length_guideline_color);
+ }
+ }
+
int brace_open_match_line = -1;
int brace_open_match_column = -1;
bool brace_open_matching = false;
@@ -1339,13 +1347,6 @@ void TextEdit::_notification(int p_what) {
}
}
- if (line_length_guideline) {
- int x = xmargin_beg + cache.font->get_char_size('0').width * line_length_guideline_col - cursor.x_ofs;
- if (x > xmargin_beg && x < xmargin_end) {
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, size.height), cache.line_length_guideline_color);
- }
- }
-
bool completion_below = false;
if (completion_active) {
// code completion box
@@ -1362,7 +1363,7 @@ void TextEdit::_notification(int p_what) {
if (completion_options.size() < 50) {
for (int i = 0; i < completion_options.size(); i++) {
- int w2 = MIN(cache.font->get_string_size(completion_options[i]).x, cmax_width);
+ int w2 = MIN(cache.font->get_string_size(completion_options[i].display).x, cmax_width);
if (w2 > w)
w = w2;
}
@@ -1370,6 +1371,11 @@ void TextEdit::_notification(int p_what) {
w = cmax_width;
}
+ // Add space for completion icons
+ const int icon_hsep = get_constant("hseparation", "ItemList");
+ Size2 icon_area_size(get_row_height(), get_row_height());
+ w += icon_area_size.width + icon_hsep;
+
int th = h + csb->get_minimum_size().y;
if (cursor_pos.y + get_row_height() + th > get_size().height) {
@@ -1405,12 +1411,26 @@ void TextEdit::_notification(int p_what) {
ERR_CONTINUE(l < 0 || l >= completion_options.size());
Color text_color = cache.completion_font_color;
for (int j = 0; j < color_regions.size(); j++) {
- if (completion_options[l].begins_with(color_regions[j].begin_key)) {
+ if (completion_options[l].insert_text.begins_with(color_regions[j].begin_key)) {
text_color = color_regions[j].color;
}
}
int yofs = (get_row_height() - cache.font->get_height()) / 2;
- draw_string(cache.font, Point2(completion_rect.position.x, completion_rect.position.y + i * get_row_height() + cache.font->get_ascent() + yofs), completion_options[l], text_color, completion_rect.size.width);
+ Point2 title_pos(completion_rect.position.x, completion_rect.position.y + i * get_row_height() + cache.font->get_ascent() + yofs);
+
+ //draw completion icon if it is valid
+ Ref<Texture> icon = completion_options[l].icon;
+ Rect2 icon_area(completion_rect.position.x, completion_rect.position.y + i * get_row_height(), icon_area_size.width, icon_area_size.height);
+ if (icon.is_valid()) {
+ const real_t max_scale = 0.7f;
+ const real_t side = max_scale * icon_area.size.width;
+ real_t scale = MIN(side / icon->get_width(), side / icon->get_height());
+ Size2 icon_size = icon->get_size() * scale;
+ draw_texture_rect(icon, Rect2(icon_area.position + (icon_area.size - icon_size) / 2, icon_size));
+ }
+
+ title_pos.x = icon_area.position.x + icon_area.size.width + icon_hsep;
+ draw_string(cache.font, title_pos, completion_options[l].display, text_color, completion_rect.size.width);
}
if (scrollw) {
@@ -4817,14 +4837,18 @@ void TextEdit::deselect() {
void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (p_from_line >= text.size())
+ if (p_from_line < 0)
+ p_from_line = 0;
+ else if (p_from_line >= text.size())
p_from_line = text.size() - 1;
if (p_from_column >= text[p_from_line].length())
p_from_column = text[p_from_line].length();
if (p_from_column < 0)
p_from_column = 0;
- if (p_to_line >= text.size())
+ if (p_to_line < 0)
+ p_to_line = 0;
+ else if (p_to_line >= text.size())
p_to_line = text.size() - 1;
if (p_to_column >= text[p_to_line].length())
p_to_column = text[p_to_line].length();
@@ -5921,12 +5945,12 @@ void TextEdit::_confirm_completion() {
_remove_text(cursor.line, cursor.column - completion_base.length(), cursor.line, cursor.column);
cursor_set_column(cursor.column - completion_base.length(), false);
- insert_text_at_cursor(completion_current);
+ insert_text_at_cursor(completion_current.insert_text);
// When inserted into the middle of an existing string/method, don't add an unnecessary quote/bracket.
String line = text[cursor.line];
CharType next_char = line[cursor.column];
- CharType last_completion_char = completion_current[completion_current.length() - 1];
+ CharType last_completion_char = completion_current.insert_text[completion_current.insert_text.length() - 1];
if ((last_completion_char == '"' || last_completion_char == '\'') && last_completion_char == next_char) {
_base_remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
@@ -6062,39 +6086,41 @@ void TextEdit::_update_completion_candidates() {
completion_base = s;
Vector<float> sim_cache;
bool single_quote = s.begins_with("'");
- Vector<String> completion_options_casei;
+ Vector<ScriptCodeCompletionOption> completion_options_casei;
+
+ for (List<ScriptCodeCompletionOption>::Element *E = completion_sources.front(); E; E = E->next()) {
+ ScriptCodeCompletionOption &option = E->get();
- for (int i = 0; i < completion_strings.size(); i++) {
- if (single_quote && completion_strings[i].is_quoted()) {
- completion_strings.write[i] = completion_strings[i].unquote().quote("'");
+ if (single_quote && option.display.is_quoted()) {
+ option.display = option.display.unquote().quote("'");
}
- if (inquote && restore_quotes == 1 && !completion_strings[i].is_quoted()) {
+ if (inquote && restore_quotes == 1 && !option.display.is_quoted()) {
String quote = single_quote ? "'" : "\"";
- completion_strings.write[i] = completion_strings[i].quote(quote);
+ option.display = option.display.quote(quote);
}
- if (completion_strings[i].begins_with(s)) {
- completion_options.push_back(completion_strings[i]);
- } else if (completion_strings[i].to_lower().begins_with(s.to_lower())) {
- completion_options_casei.push_back(completion_strings[i]);
+ if (option.display.begins_with(s)) {
+ completion_options.push_back(option);
+ } else if (option.display.to_lower().begins_with(s.to_lower())) {
+ completion_options_casei.push_back(option);
}
}
completion_options.append_array(completion_options_casei);
if (completion_options.size() == 0) {
- for (int i = 0; i < completion_strings.size(); i++) {
- if (s.is_subsequence_of(completion_strings[i])) {
- completion_options.push_back(completion_strings[i]);
+ for (int i = 0; i < completion_sources.size(); i++) {
+ if (s.is_subsequence_of(completion_sources[i].display)) {
+ completion_options.push_back(completion_sources[i]);
}
}
}
if (completion_options.size() == 0) {
- for (int i = 0; i < completion_strings.size(); i++) {
- if (s.is_subsequence_ofi(completion_strings[i])) {
- completion_options.push_back(completion_strings[i]);
+ for (int i = 0; i < completion_sources.size(); i++) {
+ if (s.is_subsequence_ofi(completion_sources[i].display)) {
+ completion_options.push_back(completion_sources[i]);
}
}
}
@@ -6105,7 +6131,7 @@ void TextEdit::_update_completion_candidates() {
return;
}
- if (completion_options.size() == 1 && s == completion_options[0]) {
+ if (completion_options.size() == 1 && s == completion_options[0].display) {
// A perfect match, stop completion
_cancel_completion();
return;
@@ -6143,12 +6169,12 @@ void TextEdit::set_code_hint(const String &p_hint) {
update();
}
-void TextEdit::code_complete(const Vector<String> &p_strings, bool p_forced) {
+void TextEdit::code_complete(const List<ScriptCodeCompletionOption> &p_strings, bool p_forced) {
- completion_strings = p_strings;
+ completion_sources = p_strings;
completion_active = true;
completion_forced = p_forced;
- completion_current = "";
+ completion_current = ScriptCodeCompletionOption();
completion_index = 0;
_update_completion_candidates();
}
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 30956ccb23..9fb8e03288 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -255,11 +255,11 @@ private:
Set<String> completion_prefixes;
bool completion_enabled;
- Vector<String> completion_strings;
- Vector<String> completion_options;
+ List<ScriptCodeCompletionOption> completion_sources;
+ Vector<ScriptCodeCompletionOption> completion_options;
bool completion_active;
bool completion_forced;
- String completion_current;
+ ScriptCodeCompletionOption completion_current;
String completion_base;
int completion_index;
Rect2i completion_rect;
@@ -704,7 +704,7 @@ public:
void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
void set_completion(bool p_enabled, const Vector<String> &p_prefixes);
- void code_complete(const Vector<String> &p_strings, bool p_forced = false);
+ void code_complete(const List<ScriptCodeCompletionOption> &p_strings, bool p_forced = false);
void set_code_hint(const String &p_hint);
void query_code_comple();