summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp6
-rw-r--r--scene/gui/control.cpp50
-rw-r--r--scene/gui/graph_edit.cpp9
-rw-r--r--scene/gui/grid_container.cpp123
-rw-r--r--scene/gui/item_list.cpp74
-rw-r--r--scene/gui/item_list.h5
-rw-r--r--scene/gui/line_edit.cpp18
-rw-r--r--scene/gui/line_edit.h1
-rw-r--r--scene/gui/option_button.cpp3
-rw-r--r--scene/gui/rich_text_label.cpp26
-rw-r--r--scene/gui/rich_text_label.h2
-rw-r--r--scene/gui/spin_box.cpp16
-rw-r--r--scene/gui/spin_box.h2
-rw-r--r--scene/gui/split_container.cpp134
-rw-r--r--scene/gui/split_container.h2
-rw-r--r--scene/gui/tab_container.cpp22
-rw-r--r--scene/gui/tab_container.h1
-rw-r--r--scene/gui/text_edit.cpp57
-rw-r--r--scene/gui/text_edit.h3
-rw-r--r--scene/gui/texture_button.cpp65
-rw-r--r--scene/gui/texture_button.h4
-rw-r--r--scene/gui/tree.cpp4
22 files changed, 392 insertions, 235 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 8b9469021c..5f541ea16a 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -307,14 +307,12 @@ void BaseButton::toggled(bool p_pressed) {
}
void BaseButton::set_disabled(bool p_disabled) {
+ if (status.disabled == p_disabled)
+ return;
status.disabled = p_disabled;
update();
_change_notify("disabled");
- if (p_disabled)
- set_focus_mode(FOCUS_NONE);
- else
- set_focus_mode(enabled_focus_mode);
}
bool BaseButton::is_disabled() const {
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 01415594d3..a5883863cd 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -49,31 +49,41 @@
Dictionary Control::_edit_get_state() const {
Dictionary s;
- s["rect"] = get_rect();
s["rotation"] = get_rotation();
s["scale"] = get_scale();
+ s["pivot"] = get_pivot_offset();
Array anchors;
anchors.push_back(get_anchor(MARGIN_LEFT));
anchors.push_back(get_anchor(MARGIN_TOP));
anchors.push_back(get_anchor(MARGIN_RIGHT));
anchors.push_back(get_anchor(MARGIN_BOTTOM));
s["anchors"] = anchors;
+ Array margins;
+ margins.push_back(get_margin(MARGIN_LEFT));
+ margins.push_back(get_margin(MARGIN_TOP));
+ margins.push_back(get_margin(MARGIN_RIGHT));
+ margins.push_back(get_margin(MARGIN_BOTTOM));
+ s["margins"] = margins;
return s;
}
void Control::_edit_set_state(const Dictionary &p_state) {
Dictionary state = p_state;
- Rect2 rect = state["rect"];
- set_position(rect.position);
- set_size(rect.size);
set_rotation(state["rotation"]);
set_scale(state["scale"]);
+ set_pivot_offset(state["pivot"]);
Array anchors = state["anchors"];
- set_anchor(MARGIN_LEFT, anchors[0]);
- set_anchor(MARGIN_TOP, anchors[1]);
- set_anchor(MARGIN_RIGHT, anchors[2]);
- set_anchor(MARGIN_BOTTOM, anchors[3]);
+ data.anchor[MARGIN_LEFT] = anchors[0];
+ data.anchor[MARGIN_TOP] = anchors[1];
+ data.anchor[MARGIN_RIGHT] = anchors[2];
+ data.anchor[MARGIN_BOTTOM] = anchors[3];
+ Array margins = state["margins"];
+ data.margin[MARGIN_LEFT] = margins[0];
+ data.margin[MARGIN_TOP] = margins[1];
+ data.margin[MARGIN_RIGHT] = margins[2];
+ data.margin[MARGIN_BOTTOM] = margins[3];
+ _size_changed();
}
void Control::_edit_set_position(const Point2 &p_position) {
@@ -85,19 +95,8 @@ Point2 Control::_edit_get_position() const {
};
void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
-
- Transform2D xform = _get_internal_transform();
-
- Vector2 new_pos = xform.basis_xform(p_edit_rect.position);
-
- Vector2 pos = get_position() + new_pos;
-
- Rect2 new_rect = get_rect();
- new_rect.position = pos.snapped(Vector2(1, 1));
- new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1));
-
- set_position(new_rect.position);
- set_size(new_rect.size);
+ set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)));
+ set_size(p_edit_rect.size.snapped(Vector2(1, 1)));
}
Rect2 Control::_edit_get_rect() const {
@@ -121,6 +120,9 @@ bool Control::_edit_use_rotation() const {
}
void Control::_edit_set_pivot(const Point2 &p_pivot) {
+ Vector2 delta_pivot = p_pivot - get_pivot_offset();
+ Vector2 move = Vector2((cos(data.rotation) - 1.0) * delta_pivot.x - sin(data.rotation) * delta_pivot.y, sin(data.rotation) * delta_pivot.x + (cos(data.rotation) - 1.0) * delta_pivot.y);
+ set_position(get_position() + move);
set_pivot_offset(p_pivot);
}
@@ -1297,7 +1299,8 @@ void Control::_size_changed() {
new_size_cache.height = MAX(minimum_size.height, new_size_cache.height);
}
- if (get_viewport()->is_snap_controls_to_pixels_enabled()) {
+ // We use a little workaround to avoid flickering when moving the pivot with _edit_set_pivot()
+ if (Math::abs(Math::sin(data.rotation * 4.0f)) < 0.00001f && get_viewport()->is_snap_controls_to_pixels_enabled()) {
new_size_cache = new_size_cache.floor();
new_pos_cache = new_pos_cache.floor();
}
@@ -1378,7 +1381,6 @@ void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bo
data.margin[(p_margin + 2) % 4] = _s2a(previous_opposite_margin_pos, data.anchor[(p_margin + 2) % 4], parent_range);
}
}
-
if (is_inside_tree()) {
_size_changed();
}
@@ -2847,7 +2849,7 @@ void Control::_bind_methods() {
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_degrees", "get_rotation_degrees");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset");
- ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
ADD_GROUP("Hint", "hint_");
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "hint_tooltip", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip", "_get_tooltip");
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 1b5014367b..38ce91a4df 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -1147,9 +1147,18 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_node_connected", "from", "from_port", "to", "to_port"), &GraphEdit::is_node_connected);
ClassDB::bind_method(D_METHOD("disconnect_node", "from", "from_port", "to", "to_port"), &GraphEdit::disconnect_node);
ClassDB::bind_method(D_METHOD("get_connection_list"), &GraphEdit::_get_connection_list);
+ ClassDB::bind_method(D_METHOD("clear_connections"), &GraphEdit::clear_connections);
ClassDB::bind_method(D_METHOD("get_scroll_ofs"), &GraphEdit::get_scroll_ofs);
ClassDB::bind_method(D_METHOD("set_scroll_ofs", "ofs"), &GraphEdit::set_scroll_ofs);
+ ClassDB::bind_method(D_METHOD("add_valid_right_disconnect_type", "type"), &GraphEdit::add_valid_right_disconnect_type);
+ ClassDB::bind_method(D_METHOD("remove_valid_right_disconnect_type", "type"), &GraphEdit::remove_valid_right_disconnect_type);
+ ClassDB::bind_method(D_METHOD("add_valid_left_disconnect_type", "type"), &GraphEdit::add_valid_left_disconnect_type);
+ ClassDB::bind_method(D_METHOD("remove_valid_left_disconnect_type", "type"), &GraphEdit::remove_valid_left_disconnect_type);
+ ClassDB::bind_method(D_METHOD("add_valid_connection_type", "from_type", "to_type"), &GraphEdit::add_valid_connection_type);
+ ClassDB::bind_method(D_METHOD("remove_valid_connection_type", "from_type", "to_type"), &GraphEdit::remove_valid_connection_type);
+ ClassDB::bind_method(D_METHOD("is_valid_connection_type", "from_type", "to_type"), &GraphEdit::is_valid_connection_type);
+
ClassDB::bind_method(D_METHOD("set_zoom", "p_zoom"), &GraphEdit::set_zoom);
ClassDB::bind_method(D_METHOD("get_zoom"), &GraphEdit::get_zoom);
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index 8c3f835be3..c2b8a7dfab 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -43,107 +43,118 @@ void GridContainer::_notification(int p_what) {
int hsep = get_constant("hseparation");
int vsep = get_constant("vseparation");
+ int max_col = MIN(get_child_count(), columns);
+ int max_row = get_child_count() / columns;
- int idx = 0;
- int max_row = 0;
- int max_col = 0;
-
- Size2 size = get_size();
-
+ // Compute the per-column/per-row data
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
if (!c || !c->is_visible_in_tree())
continue;
- int row = idx / columns;
- int col = idx % columns;
+ int row = i / columns;
+ int col = i % columns;
Size2i ms = c->get_combined_minimum_size();
if (col_minw.has(col))
col_minw[col] = MAX(col_minw[col], ms.width);
else
col_minw[col] = ms.width;
-
if (row_minh.has(row))
row_minh[row] = MAX(row_minh[row], ms.height);
else
row_minh[row] = ms.height;
- //print_line("store row "+itos(row)+" mw "+itos(ms.height));
-
- if (c->get_h_size_flags() & SIZE_EXPAND)
+ if (c->get_h_size_flags() & SIZE_EXPAND) {
col_expanded.insert(col);
- if (c->get_v_size_flags() & SIZE_EXPAND)
+ }
+ if (c->get_v_size_flags() & SIZE_EXPAND) {
row_expanded.insert(row);
-
- max_col = MAX(col, max_col);
- max_row = MAX(row, max_row);
- idx++;
+ }
}
- Size2 ms;
- int expand_rows = 0;
- int expand_cols = 0;
-
+ // Evaluate the remaining space for expanded columns/rows
+ Size2 remaining_space = get_size();
for (Map<int, int>::Element *E = col_minw.front(); E; E = E->next()) {
- ms.width += E->get();
- if (col_expanded.has(E->key()))
- expand_cols++;
+ if (!col_expanded.has(E->key()))
+ remaining_space.width -= E->get();
}
for (Map<int, int>::Element *E = row_minh.front(); E; E = E->next()) {
- ms.height += E->get();
- if (row_expanded.has(E->key()))
- expand_rows++;
+ if (!row_expanded.has(E->key()))
+ remaining_space.height -= E->get();
+ }
+ remaining_space.height -= vsep * (max_row - 1);
+ remaining_space.width -= hsep * (max_col - 1);
+
+ bool can_fit = false;
+ while (!can_fit) {
+ // Check if all minwidth constraints are ok if we use the remaining space
+ can_fit = true;
+ int max_index = 0;
+ for (Set<int>::Element *E = col_expanded.front(); E; E = E->next()) {
+ if (col_minw[E->get()] > col_minw[max_index]) {
+ max_index = col_minw[E->get()];
+ }
+ if (can_fit && (remaining_space.width / col_expanded.size()) < col_minw[E->get()]) {
+ can_fit = false;
+ }
+ }
+
+ // If not, the column with maximum minwidth is not expanded
+ if (!can_fit) {
+ col_expanded.erase(max_index);
+ remaining_space.width -= col_minw[max_index];
+ }
}
- ms.height += vsep * max_row;
- ms.width += hsep * max_col;
+ can_fit = false;
+ while (!can_fit) {
+ // Check if all minwidth constraints are ok if we use the remaining space
+ can_fit = true;
+ int max_index = 0;
+ for (Set<int>::Element *E = row_expanded.front(); E; E = E->next()) {
+ if (row_minh[E->get()] > row_minh[max_index]) {
+ max_index = row_minh[E->get()];
+ }
+ if (can_fit && (remaining_space.height / row_expanded.size()) < row_minh[E->get()]) {
+ can_fit = false;
+ }
+ }
+
+ // If not, the row with maximum minwidth is not expanded
+ if (!can_fit) {
+ row_expanded.erase(max_index);
+ remaining_space.height -= row_minh[max_index];
+ }
+ }
- int row_expand = expand_rows ? (size.y - ms.y) / expand_rows : 0;
- int col_expand = expand_cols ? (size.x - ms.x) / expand_cols : 0;
+ // Finally, fit the nodes
+ int col_expand = remaining_space.width / col_expanded.size();
+ int row_expand = remaining_space.height / row_expanded.size();
int col_ofs = 0;
int row_ofs = 0;
- idx = 0;
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
if (!c || !c->is_visible_in_tree())
continue;
- int row = idx / columns;
- int col = idx % columns;
+ int row = i / columns;
+ int col = i % columns;
if (col == 0) {
col_ofs = 0;
- if (row > 0 && row_minh.has(row - 1))
- row_ofs += row_minh[row - 1] + vsep + (row_expanded.has(row - 1) ? row_expand : 0);
+ if (row > 0)
+ row_ofs += ((row_expanded.has(row - 1)) ? row_expand : row_minh[row - 1]) + vsep;
}
- Size2 s;
- if (col_minw.has(col))
- s.width = col_minw[col];
- if (row_minh.has(row))
- s.height = row_minh[row];
-
- if (row_expanded.has(row))
- s.height += row_expand;
- if (col_expanded.has(col))
- s.width += col_expand;
-
Point2 p(col_ofs, row_ofs);
+ Size2 s((col_expanded.has(col)) ? col_expand : col_minw[col], (row_expanded.has(row)) ? row_expand : row_minh[row]);
- //print_line("col: "+itos(col)+" row: "+itos(row)+" col_ofs: "+itos(col_ofs)+" row_ofs: "+itos(row_ofs));
fit_child_in_rect(c, Rect2(p, s));
- //print_line("col: "+itos(col)+" row: "+itos(row)+" rect: "+Rect2(p,s));
-
- if (col_minw.has(col)) {
- col_ofs += col_minw[col] + hsep + (col_expanded.has(col) ? col_expand : 0);
- }
- idx++;
+ col_ofs += s.width + hsep;
}
} break;
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 77d3a34c66..f7574ca2cd 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -517,11 +517,11 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
emit_signal("item_rmb_selected", i, get_local_mouse_position());
} else {
- bool selected = !items[i].selected;
+ bool selected = items[i].selected;
select(i, select_mode == SELECT_SINGLE || !mb->get_command());
- if (selected) {
+ if (!selected || allow_reselect) {
if (select_mode == SELECT_SINGLE) {
emit_signal("item_selected", i);
} else
@@ -961,12 +961,36 @@ void ItemList::_notification(int p_what) {
Vector2 base_ofs = bg->get_offset();
base_ofs.y -= int(scroll_bar->get_value());
- Rect2 clip(Point2(), size - bg->get_minimum_size() + Vector2(0, scroll_bar->get_value()));
+ const Rect2 clip(-base_ofs, size); // visible frame, don't need to draw outside of there
+
+ int first_item_visible;
+ {
+ // do a binary search to find the first item whose rect reaches below clip.position.y
+ int lo = 0;
+ int hi = items.size();
+ while (lo < hi) {
+ const int mid = (lo + hi) / 2;
+ const Rect2 &rcache = items[mid].rect_cache;
+ if (rcache.position.y + rcache.size.y < clip.position.y) {
+ lo = mid + 1;
+ } else {
+ hi = mid;
+ }
+ }
+ // we might have ended up with column 2, or 3, ..., so let's find the first column
+ while (lo > 0 && items[lo - 1].rect_cache.position.y == items[lo].rect_cache.position.y) {
+ lo -= 1;
+ }
+ first_item_visible = lo;
+ }
- for (int i = 0; i < items.size(); i++) {
+ for (int i = first_item_visible; i < items.size(); i++) {
Rect2 rcache = items[i].rect_cache;
+ if (rcache.position.y > clip.position.y + clip.size.y)
+ break; // done
+
if (!clip.intersects(rcache))
continue;
@@ -1138,8 +1162,28 @@ void ItemList::_notification(int p_what) {
}
}
- for (int i = 0; i < separators.size(); i++) {
- draw_line(Vector2(bg->get_margin(MARGIN_LEFT), base_ofs.y + separators[i]), Vector2(width, base_ofs.y + separators[i]), guide_color);
+ int first_visible_separator = 0;
+ {
+ // do a binary search to find the first separator that is below clip_position.y
+ int lo = 0;
+ int hi = separators.size();
+ while (lo < hi) {
+ const int mid = (lo + hi) / 2;
+ if (separators[mid] < clip.position.y) {
+ lo = mid + 1;
+ } else {
+ hi = mid;
+ }
+ }
+ first_visible_separator = lo;
+ }
+
+ for (int i = first_visible_separator; i < separators.size(); i++) {
+ if (separators[i] > clip.position.y + clip.size.y)
+ break; // done
+
+ const int y = base_ofs.y + separators[i];
+ draw_line(Vector2(bg->get_margin(MARGIN_LEFT), y), Vector2(width, y), guide_color);
}
}
}
@@ -1241,6 +1285,7 @@ int ItemList::find_metadata(const Variant &p_metadata) const {
}
void ItemList::set_allow_rmb_select(bool p_allow) {
+
allow_rmb_select = p_allow;
}
@@ -1249,6 +1294,16 @@ bool ItemList::get_allow_rmb_select() const {
return allow_rmb_select;
}
+void ItemList::set_allow_reselect(bool p_allow) {
+
+ allow_reselect = p_allow;
+}
+
+bool ItemList::get_allow_reselect() const {
+
+ return allow_reselect;
+}
+
void ItemList::set_icon_scale(real_t p_scale) {
icon_scale = p_scale;
}
@@ -1404,6 +1459,9 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_rmb_select", "allow"), &ItemList::set_allow_rmb_select);
ClassDB::bind_method(D_METHOD("get_allow_rmb_select"), &ItemList::get_allow_rmb_select);
+ ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &ItemList::set_allow_reselect);
+ ClassDB::bind_method(D_METHOD("get_allow_reselect"), &ItemList::get_allow_reselect);
+
ClassDB::bind_method(D_METHOD("set_auto_height", "enable"), &ItemList::set_auto_height);
ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height);
@@ -1422,6 +1480,7 @@ void ItemList::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines");
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height");
@@ -1432,7 +1491,7 @@ void ItemList::_bind_methods() {
ADD_GROUP("Icon", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_mode", PROPERTY_HINT_ENUM, "Top,Left"), "set_icon_mode", "get_icon_mode");
ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "icon_scale"), "set_icon_scale", "get_icon_scale");
- ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "fixed_icon_size"), "set_fixed_icon_size", "get_fixed_icon_size");
+ ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "fixed_icon_size"), "set_fixed_icon_size", "get_fixed_icon_size");
BIND_ENUM_CONSTANT(ICON_MODE_TOP);
BIND_ENUM_CONSTANT(ICON_MODE_LEFT);
@@ -1476,6 +1535,7 @@ ItemList::ItemList() {
ensure_selected_visible = false;
defer_select_single = -1;
allow_rmb_select = false;
+ allow_reselect = false;
do_autoscroll_to_bottom = false;
icon_scale = 1.0f;
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index 24e9498044..7f34a250bd 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -106,6 +106,8 @@ private:
bool allow_rmb_select;
+ bool allow_reselect;
+
real_t icon_scale;
bool do_autoscroll_to_bottom;
@@ -198,6 +200,9 @@ public:
void set_allow_rmb_select(bool p_allow);
bool get_allow_rmb_select() const;
+ void set_allow_reselect(bool p_allow);
+ bool get_allow_reselect() const;
+
void ensure_current_is_visible();
void sort_items_by_text();
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 524a68a116..03dc6686b8 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -30,6 +30,7 @@
#include "line_edit.h"
#include "label.h"
+#include "message_queue.h"
#include "os/keyboard.h"
#include "os/os.h"
#include "print_string.h"
@@ -800,7 +801,12 @@ void LineEdit::paste_text() {
if (selection.enabled) selection_delete();
append_at_cursor(paste_buffer);
- _text_changed();
+ if (!text_changed_dirty) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_text_changed");
+ }
+ text_changed_dirty = true;
+ }
}
}
@@ -974,7 +980,12 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
window_pos = cursor_pos;
}
- _text_changed();
+ if (!text_changed_dirty) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_text_changed");
+ }
+ text_changed_dirty = true;
+ }
}
void LineEdit::set_text(String p_text) {
@@ -1341,6 +1352,7 @@ void LineEdit::_text_changed() {
void LineEdit::_emit_text_change() {
emit_signal("text_changed", text);
_change_notify("text");
+ text_changed_dirty = false;
}
void LineEdit::_clear_redo() {
@@ -1373,6 +1385,7 @@ void LineEdit::_create_undo_state() {
void LineEdit::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("_text_changed"), &LineEdit::_text_changed);
ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &LineEdit::_toggle_draw_caret);
#ifdef TOOLS_ENABLED
@@ -1458,6 +1471,7 @@ LineEdit::LineEdit() {
window_has_focus = true;
max_length = 0;
pass = false;
+ text_changed_dirty = false;
placeholder_alpha = 0.6;
deselect();
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index e15980d3c4..e3ad3b17f1 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -67,6 +67,7 @@ private:
bool editable;
bool pass;
+ bool text_changed_dirty;
String undo_text;
String text;
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 1a46921561..71c14810f6 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -318,8 +318,9 @@ void OptionButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_items"), &OptionButton::_set_items);
ClassDB::bind_method(D_METHOD("_get_items"), &OptionButton::_get_items);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
+ // "selected" property must come after "items", otherwise GH-10213 occurs
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "selected"), "_select_int", "get_selected");
ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "ID")));
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index a7419519ae..381c6c75a5 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -121,6 +121,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
if (p_mode == PROCESS_CACHE) {
l.offset_caches.clear();
l.height_caches.clear();
+ l.ascent_caches.clear();
+ l.descent_caches.clear();
l.char_count = 0;
l.minimum_width = 0;
}
@@ -140,6 +142,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
//line height should be the font height for the first time, this ensures that an empty line will never have zero height and successive newlines are displayed
int line_height = cfont->get_height();
+ int line_ascent = cfont->get_ascent();
+ int line_descent = cfont->get_descent();
int nonblank_line_count = 0; //number of nonblank lines as counted during PROCESS_DRAW
@@ -169,16 +173,22 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
case ALIGN_FILL: l.offset_caches.push_back((p_width - margin) - used /*+spaces_size*/); break; \
} \
l.height_caches.push_back(line_height); \
+ l.ascent_caches.push_back(line_ascent); \
+ l.descent_caches.push_back(line_descent); \
l.space_caches.push_back(spaces); \
} \
y += line_height + get_constant(SceneStringNames::get_singleton()->line_separation); \
line_height = 0; \
+ line_ascent = 0; \
+ line_descent = 0; \
spaces = 0; \
spaces_size = 0; \
wofs = begin; \
align_ofs = 0; \
if (p_mode != PROCESS_CACHE) { \
lh = line < l.height_caches.size() ? l.height_caches[line] : 1; \
+ line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1; \
+ line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1; \
} \
if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x < p_ofs.x + wofs) { \
if (r_outside) *r_outside = true; \
@@ -254,6 +264,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
const CharType *cf = c;
int fh = font->get_height();
int ascent = font->get_ascent();
+ int descent = font->get_descent();
+
+ line_ascent = MAX(line_ascent, ascent);
+ line_descent = MAX(line_descent, descent);
+ fh = MAX(fh, line_ascent + line_descent); // various fonts!
+
Color color;
bool underline = false;
@@ -280,6 +296,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
lh = 0;
if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
+ line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1;
+ line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1;
}
while (c[end] != 0 && !(end && c[end - 1] == ' ' && c[end] != ' ')) {
@@ -348,7 +366,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int cw = 0;
- bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - (fh - 0 * ascent), fh); //getting rid of ascent seems to work??
+ bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent);
if (visible)
line_is_blank = false;
@@ -360,11 +378,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
cw = font->get_char_size(c[i], c[i + 1]).x;
draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg);
if (visible)
- font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - (fh - ascent)), c[i], c[i + 1], override_selected_font_color ? selection_fg : color);
+ font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], override_selected_font_color ? selection_fg : color);
} else {
if (visible)
- cw = font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - (fh - ascent)), c[i], c[i + 1], color);
+ cw = font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], color);
}
p_char_count++;
@@ -379,7 +397,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
if (underline) {
Color uc = color;
uc.a *= 0.5;
- int uy = y + lh - fh + ascent + 2;
+ int uy = y + lh - line_descent + 2;
float underline_width = 1.0;
#ifdef TOOLS_ENABLED
underline_width *= EDSCALE;
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 48f746e28d..e7d5e6bb1b 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -80,6 +80,8 @@ private:
Item *from;
Vector<int> offset_caches;
Vector<int> height_caches;
+ Vector<int> ascent_caches;
+ Vector<int> descent_caches;
Vector<int> space_caches;
int height_cache;
int height_accum_cache;
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 3c5d524d80..145981d498 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -185,17 +185,22 @@ void SpinBox::_line_edit_focus_exit() {
_text_entered(line_edit->get_text());
}
+inline void SpinBox::_adjust_width_for_icon(const Ref<Texture> icon) {
+
+ int w = icon->get_width();
+ if (w != last_w) {
+ line_edit->set_margin(MARGIN_RIGHT, -w);
+ last_w = w;
+ }
+}
+
void SpinBox::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
Ref<Texture> updown = get_icon("updown");
- int w = updown->get_width();
- if (w != last_w) {
- line_edit->set_margin(MARGIN_RIGHT, -w);
- last_w = w;
- }
+ _adjust_width_for_icon(updown);
RID ci = get_canvas_item();
Size2i size = get_size();
@@ -207,6 +212,7 @@ void SpinBox::_notification(int p_what) {
//_value_changed(0);
} else if (p_what == NOTIFICATION_ENTER_TREE) {
+ _adjust_width_for_icon(get_icon("updown"));
_value_changed(0);
}
}
diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h
index b8565ec082..8863f44bef 100644
--- a/scene/gui/spin_box.h
+++ b/scene/gui/spin_box.h
@@ -62,6 +62,8 @@ class SpinBox : public Range {
void _line_edit_focus_exit();
+ inline void _adjust_width_for_icon(const Ref<Texture> icon);
+
protected:
void _gui_input(const Ref<InputEvent> &p_event);
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index e1d49019b3..bf7033e8ba 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -61,127 +61,69 @@ Control *SplitContainer::_getch(int p_idx) const {
}
void SplitContainer::_resort() {
-
- /* First pass, determine minimum size AND amount of stretchable elements */
-
int axis = vertical ? 1 : 0;
- bool has_first = _getch(0);
- bool has_second = _getch(1);
+ Control *first = _getch(0);
+ Control *second = _getch(1);
- if (!has_first && !has_second) {
- return;
- } else if (!(has_first && has_second)) {
- if (has_first)
+ // If we have only one element
+ if (!first || !second) {
+ if (first) {
fit_child_in_rect(_getch(0), Rect2(Point2(), get_size()));
- else
+ } else if (second) {
fit_child_in_rect(_getch(1), Rect2(Point2(), get_size()));
-
+ }
return;
}
- Control *first = _getch(0);
- Control *second = _getch(1);
-
- bool ratiomode = false;
- bool expand_first_mode = false;
-
+ // Determine expanded children
+ bool first_expanded = false;
+ bool second_expanded = false;
if (vertical) {
-
- ratiomode = first->get_v_size_flags() & SIZE_EXPAND && second->get_v_size_flags() & SIZE_EXPAND;
- expand_first_mode = first->get_v_size_flags() & SIZE_EXPAND && !(second->get_v_size_flags() & SIZE_EXPAND);
+ first_expanded = first->get_v_size_flags() & SIZE_EXPAND;
+ second_expanded = second->get_v_size_flags() & SIZE_EXPAND;
} else {
-
- ratiomode = first->get_h_size_flags() & SIZE_EXPAND && second->get_h_size_flags() & SIZE_EXPAND;
- expand_first_mode = first->get_h_size_flags() & SIZE_EXPAND && !(second->get_h_size_flags() & SIZE_EXPAND);
+ first_expanded = first->get_h_size_flags() & SIZE_EXPAND;
+ second_expanded = second->get_h_size_flags() & SIZE_EXPAND;
}
- int sep = get_constant("separation");
+ // Determine the separation between items
Ref<Texture> g = get_icon("grabber");
-
+ int sep = get_constant("separation");
if (dragger_visibility == DRAGGER_HIDDEN_COLLAPSED) {
sep = 0;
} else {
sep = MAX(sep, vertical ? g->get_height() : g->get_width());
}
- int total = vertical ? get_size().height : get_size().width;
-
- total -= sep;
-
- int minimum = 0;
-
+ // Compute the minimum size
Size2 ms_first = first->get_combined_minimum_size();
Size2 ms_second = second->get_combined_minimum_size();
- if (vertical) {
- minimum = ms_first.height + ms_second.height;
- } else {
- minimum = ms_first.width + ms_second.width;
- }
-
- int available = total - minimum;
- if (available < 0)
- available = 0;
-
- middle_sep = 0;
-
- if (collapsed) {
-
- if (ratiomode) {
-
- int first_ratio = first->get_stretch_ratio();
- int second_ratio = second->get_stretch_ratio();
-
- float ratio = float(first_ratio) / (first_ratio + second_ratio);
-
- middle_sep = ms_first[axis] + available * ratio;
-
- } else if (expand_first_mode) {
-
- middle_sep = get_size()[axis] - ms_second[axis] - sep;
- } else {
-
- middle_sep = ms_first[axis];
- }
- } else if (ratiomode) {
-
- int first_ratio = first->get_stretch_ratio();
- int second_ratio = second->get_stretch_ratio();
-
- float ratio = float(first_ratio) / (first_ratio + second_ratio);
-
- if (expand_ofs < -(available * ratio))
- expand_ofs = -(available * ratio);
- else if (expand_ofs > (available * (1.0 - ratio)))
- expand_ofs = (available * (1.0 - ratio));
-
- middle_sep = ms_first[axis] + available * ratio + expand_ofs;
- } else if (expand_first_mode) {
+ float ratio = first->get_stretch_ratio() / (first->get_stretch_ratio() + second->get_stretch_ratio());
- if (expand_ofs > 0)
- expand_ofs = 0;
- else if (expand_ofs < -available)
- expand_ofs = -available;
-
- middle_sep = get_size()[axis] - ms_second[axis] - sep + expand_ofs;
+ int no_offset_middle_sep = 0;
+ if (first_expanded && second_expanded) {
+ no_offset_middle_sep = get_size()[axis] * ratio - sep / 2;
+ } else if (first_expanded) {
+ no_offset_middle_sep = get_size()[axis] - ms_second[axis] - sep;
} else {
+ no_offset_middle_sep = ms_first[axis];
+ }
- if (expand_ofs < 0)
- expand_ofs = 0;
- else if (expand_ofs > available)
- expand_ofs = available;
-
- middle_sep = ms_first[axis] + expand_ofs;
+ middle_sep = no_offset_middle_sep;
+ middle_sep += (collapsed) ? 0 : split_offset;
+ middle_sep = MIN(middle_sep, get_size()[axis] - ms_second[axis] - sep);
+ middle_sep = MAX(middle_sep, ms_first[axis]);
+ if (!collapsed) {
+ split_offset = middle_sep - no_offset_middle_sep;
}
if (vertical) {
-
fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(get_size().width, middle_sep)));
int sofs = middle_sep + sep;
fit_child_in_rect(second, Rect2(Point2(0, sofs), Size2(get_size().width, get_size().height - sofs)));
} else {
-
fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(middle_sep, get_size().height)));
int sofs = middle_sep + sep;
fit_child_in_rect(second, Rect2(Point2(sofs, 0), Size2(get_size().width - sofs, get_size().height)));
@@ -290,7 +232,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
dragging = true;
drag_from = mb->get_position().y;
- drag_ofs = expand_ofs;
+ drag_ofs = split_offset;
}
} else {
@@ -298,7 +240,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
dragging = true;
drag_from = mb->get_position().x;
- drag_ofs = expand_ofs;
+ drag_ofs = split_offset;
}
}
} else {
@@ -312,7 +254,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid() && dragging) {
- expand_ofs = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from);
+ split_offset = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from);
queue_sort();
emit_signal("dragged", get_split_offset());
}
@@ -343,16 +285,16 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const
void SplitContainer::set_split_offset(int p_offset) {
- if (expand_ofs == p_offset)
+ if (split_offset == p_offset)
return;
- expand_ofs = p_offset;
+ split_offset = p_offset;
queue_sort();
}
int SplitContainer::get_split_offset() const {
- return expand_ofs;
+ return split_offset;
}
void SplitContainer::set_collapsed(bool p_collapsed) {
@@ -407,7 +349,7 @@ void SplitContainer::_bind_methods() {
SplitContainer::SplitContainer(bool p_vertical) {
mouse_inside = false;
- expand_ofs = 0;
+ split_offset = 0;
middle_sep = 0;
vertical = p_vertical;
dragging = false;
diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h
index a31dc766d2..321f7fd3b7 100644
--- a/scene/gui/split_container.h
+++ b/scene/gui/split_container.h
@@ -46,7 +46,7 @@ public:
private:
bool vertical;
- int expand_ofs;
+ int split_offset;
int middle_sep;
bool dragging;
int drag_from;
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 0312e58094..6e85ce5eb4 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -474,21 +474,24 @@ void TabContainer::remove_child_notify(Node *p_child) {
Control::remove_child_notify(p_child);
- int tc = get_tab_count();
- if (current == tc - 1) {
- current--;
- if (current < 0)
- current = 0;
- else {
- call_deferred("set_current_tab", current);
- }
- }
+ call_deferred("_update_current_tab");
p_child->disconnect("renamed", this, "_child_renamed_callback");
update();
}
+void TabContainer::_update_current_tab() {
+
+ int tc = get_tab_count();
+ if (current >= tc)
+ current = tc - 1;
+ if (current < 0)
+ current = 0;
+ else
+ set_current_tab(current);
+}
+
void TabContainer::set_tab_align(TabAlign p_align) {
ERR_FAIL_INDEX(p_align, 3);
@@ -664,6 +667,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("_update_current_tab"), &TabContainer::_update_current_tab);
ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab")));
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 0ba8c205ea..4bc6e00145 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -62,6 +62,7 @@ private:
Vector<Control *> _get_tabs() const;
int _get_tab_width(int p_index) const;
void _on_theme_changed();
+ void _update_current_tab();
protected:
void _child_renamed_callback();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 95bd676a08..f13950461b 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -217,7 +217,7 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
}
}
-const Map<int, TextEdit::Text::ColorRegionInfo> &TextEdit::Text::get_color_region_info(int p_line) {
+const Map<int, TextEdit::Text::ColorRegionInfo> &TextEdit::Text::get_color_region_info(int p_line) const {
static Map<int, ColorRegionInfo> cri;
ERR_FAIL_INDEX_V(p_line, text.size(), cri);
@@ -776,7 +776,6 @@ void TextEdit::_notification(int p_what) {
j--;
}
if (escaped) {
- j--;
cc = '\\';
continue;
}
@@ -890,7 +889,7 @@ void TextEdit::_notification(int p_what) {
} else {
// if it has text, then draw current line marker in the margin, as line number etc will draw over it, draw the rest of line marker later.
if (line == cursor.line && highlight_current_line) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg, get_row_height()), cache.current_line_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg + ofs_x, get_row_height()), cache.current_line_color);
}
}
@@ -1122,14 +1121,14 @@ void TextEdit::_notification(int p_what) {
// line highlighting handle horizontal clipping
if (line == cursor.line && highlight_current_line) {
- // char next to margin is skipped
- if ((char_ofs + char_margin) > xmargin_beg) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, (char_ofs + char_margin) - (xmargin_beg + ofs_x), get_row_height()), cache.current_line_color);
- }
- // end of line when last char is skipped
if (j == str.length() - 1) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color);
+ // end of line when last char is skipped
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - (xmargin_beg + ofs_x), get_row_height()), cache.current_line_color);
+
+ } else if ((char_ofs + char_margin) > xmargin_beg) {
+ // char next to margin is skipped
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, (char_ofs + char_margin) - xmargin_beg, get_row_height()), cache.current_line_color);
}
}
continue;
@@ -4710,8 +4709,6 @@ int TextEdit::get_indent_level(int p_line) const {
tab_count++;
} else if (text[p_line][i] == ' ') {
whitespace_count++;
- } else if (text[p_line][i] == '#') {
- break;
} else {
break;
}
@@ -4719,6 +4716,31 @@ int TextEdit::get_indent_level(int p_line) const {
return tab_count + whitespace_count / indent_size;
}
+bool TextEdit::is_line_comment(int p_line) const {
+
+ // checks to see if this line is the start of a comment
+ ERR_FAIL_INDEX_V(p_line, text.size(), false);
+
+ const Map<int, Text::ColorRegionInfo> &cri_map = text.get_color_region_info(p_line);
+
+ int line_length = text[p_line].size();
+ for (int i = 0; i < line_length - 1; i++) {
+ if (_is_symbol(text[p_line][i]) && cri_map.has(i)) {
+ const Text::ColorRegionInfo &cri = cri_map[i];
+ if (color_regions[cri.region].begin_key == "#" || color_regions[cri.region].begin_key == "//") {
+ return true;
+ } else {
+ return false;
+ }
+ } else if (_is_whitespace(text[p_line][i])) {
+ continue;
+ } else {
+ break;
+ }
+ }
+ return false;
+}
+
bool TextEdit::can_fold(int p_line) const {
ERR_FAIL_INDEX_V(p_line, text.size(), false);
@@ -4732,6 +4754,8 @@ bool TextEdit::can_fold(int p_line) const {
return false;
if (is_line_hidden(p_line))
return false;
+ if (is_line_comment(p_line))
+ return false;
int start_indent = get_indent_level(p_line);
@@ -4739,10 +4763,13 @@ bool TextEdit::can_fold(int p_line) const {
if (text[i].size() == 0)
continue;
int next_indent = get_indent_level(i);
- if (next_indent > start_indent)
+ if (is_line_comment(i)) {
+ continue;
+ } else if (next_indent > start_indent) {
return true;
- else
+ } else {
return false;
+ }
}
return false;
@@ -4771,7 +4798,9 @@ void TextEdit::fold_line(int p_line) {
int last_line = start_indent;
for (int i = p_line + 1; i < text.size(); i++) {
if (text[i].strip_edges().size() != 0) {
- if (get_indent_level(i) > start_indent) {
+ if (is_line_comment(i)) {
+ continue;
+ } else if (get_indent_level(i) > start_indent) {
last_line = i;
} else {
break;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index acbf41aa81..8ac3b9fce6 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -162,7 +162,7 @@ class TextEdit : public Control {
void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; }
int get_line_width(int p_line) const;
int get_max_width(bool p_exclude_hidden = false) const;
- const Map<int, ColorRegionInfo> &get_color_region_info(int p_line);
+ const Map<int, ColorRegionInfo> &get_color_region_info(int p_line) const;
void set(int p_line, const String &p_text);
void set_marked(int p_line, bool p_marked) { text[p_line].marked = p_marked; }
bool is_marked(int p_line) const { return text[p_line].marked; }
@@ -450,6 +450,7 @@ public:
void indent_left();
void indent_right();
int get_indent_level(int p_line) const;
+ bool is_line_comment(int p_line) const;
inline void set_scroll_pass_end_of_file(bool p_enabled) {
scroll_past_end_of_file_enabled = p_enabled;
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 07c9894611..6bd3b26280 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -29,6 +29,8 @@
/*************************************************************************/
#include "texture_button.h"
+#include "core/typedefs.h"
+#include <stdlib.h>
Size2 TextureButton::get_minimum_size() const {
@@ -58,10 +60,50 @@ bool TextureButton::has_point(const Point2 &p_point) const {
if (click_mask.is_valid()) {
- Point2i p = p_point;
- if (p.x < 0 || p.x >= click_mask->get_size().width || p.y < 0 || p.y >= click_mask->get_size().height)
+ Point2 point = p_point;
+ Rect2 rect = Rect2();
+ Size2 mask_size = click_mask->get_size();
+
+ if (_tile) {
+ // if the stretch mode is tile we offset the point to keep it inside the mask size
+ rect.size = mask_size;
+ if (_position_rect.has_point(point)) {
+ int cols = (int)Math::ceil(_position_rect.size.x / mask_size.x);
+ int rows = (int)Math::ceil(_position_rect.size.y / mask_size.y);
+ int col = (int)(point.x / mask_size.x) % cols;
+ int row = (int)(point.y / mask_size.y) % rows;
+ point.x -= mask_size.x * col;
+ point.y -= mask_size.y * row;
+ }
+ } else {
+ // we need to transform the point from our scaled / translated image back to our mask image
+ Point2 ofs = _position_rect.position;
+ Size2 scale = mask_size / _position_rect.size;
+
+ switch (stretch_mode) {
+ case STRETCH_KEEP_ASPECT_COVERED: {
+ // if the stretch mode is aspect covered the image uses a texture region so we need to take that into account
+ float min = MIN(scale.x, scale.y);
+ scale.x = min;
+ scale.y = min;
+ ofs -= _texture_region.position / min;
+ } break;
+ }
+
+ // offset and scale the new point position to adjust it to the bitmask size
+ point -= ofs;
+ point *= scale;
+
+ // finally, we need to check if the point is inside a rectangle with a position >= 0,0 and a size <= mask_size
+ rect.position = Point2(MAX(0, _texture_region.position.x), MAX(0, _texture_region.position.y));
+ rect.size = Size2(MIN(mask_size.x, _texture_region.size.x), MIN(mask_size.y, _texture_region.size.y));
+ }
+
+ if (!rect.has_point(point)) {
return false;
+ }
+ Point2i p = point;
return click_mask->get_bit(p);
}
@@ -118,8 +160,8 @@ void TextureButton::_notification(int p_what) {
if (texdraw.is_valid()) {
Point2 ofs;
Size2 size = texdraw->get_size();
- Rect2 tex_regin = Rect2(Point2(), texdraw->get_size());
- bool tile = false;
+ _texture_region = Rect2(Point2(), texdraw->get_size());
+ _tile = false;
if (expand) {
switch (stretch_mode) {
case STRETCH_KEEP:
@@ -130,7 +172,7 @@ void TextureButton::_notification(int p_what) {
break;
case STRETCH_TILE:
size = get_size();
- tile = true;
+ _tile = true;
break;
case STRETCH_KEEP_CENTERED:
ofs = (get_size() - texdraw->get_size()) / 2;
@@ -161,14 +203,15 @@ void TextureButton::_notification(int p_what) {
float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height;
Size2 scaledTexSize = tex_size * scale;
Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f;
- tex_regin = Rect2(ofs, size / scale);
+ _texture_region = Rect2(ofs, size / scale);
} break;
}
}
- if (tile)
- draw_texture_rect(texdraw, Rect2(ofs, size), tile);
+ _position_rect = Rect2(ofs, size);
+ if (_tile)
+ draw_texture_rect(texdraw, _position_rect, _tile);
else
- draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin);
+ draw_texture_rect_region(texdraw, _position_rect, _texture_region);
}
if (has_focus() && focused.is_valid()) {
@@ -299,4 +342,8 @@ TextureButton::StretchMode TextureButton::get_stretch_mode() const {
TextureButton::TextureButton() {
expand = false;
stretch_mode = STRETCH_SCALE;
+
+ _texture_region = Rect2();
+ _position_rect = Rect2();
+ _tile = false;
}
diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h
index 1cf4b66413..d42df390e8 100644
--- a/scene/gui/texture_button.h
+++ b/scene/gui/texture_button.h
@@ -58,6 +58,10 @@ private:
bool expand;
StretchMode stretch_mode;
+ Rect2 _texture_region;
+ Rect2 _position_rect;
+ bool _tile;
+
protected:
virtual Size2 get_minimum_size() const;
virtual bool has_point(const Point2 &p_point) const;
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index e12044fca2..cdbdc9b0d7 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -2384,7 +2384,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (mm.is_valid()) {
- if (cache.font.is_null()) // avoid a strange case that may fuckup stuff
+ if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
update_cache();
Ref<StyleBox> bg = cache.bg;
@@ -2483,7 +2483,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (cache.font.is_null()) // avoid a strange case that may fuckup stuff
+ if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
update_cache();
if (!b->is_pressed()) {