summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/SCsub2
-rw-r--r--scene/gui/base_button.cpp79
-rw-r--r--scene/gui/base_button.h3
-rw-r--r--scene/gui/box_container.cpp61
-rw-r--r--scene/gui/box_container.h3
-rw-r--r--scene/gui/button.cpp98
-rw-r--r--scene/gui/button.h1
-rw-r--r--scene/gui/center_container.cpp27
-rw-r--r--scene/gui/center_container.h1
-rw-r--r--scene/gui/check_box.cpp24
-rw-r--r--scene/gui/check_box.h1
-rw-r--r--scene/gui/check_button.cpp22
-rw-r--r--scene/gui/check_button.h1
-rw-r--r--scene/gui/color_picker.cpp163
-rw-r--r--scene/gui/color_picker.h2
-rw-r--r--scene/gui/color_rect.cpp5
-rw-r--r--scene/gui/container.cpp40
-rw-r--r--scene/gui/container.h1
-rw-r--r--scene/gui/control.cpp570
-rw-r--r--scene/gui/control.h8
-rw-r--r--scene/gui/dialogs.cpp49
-rw-r--r--scene/gui/dialogs.h2
-rw-r--r--scene/gui/file_dialog.cpp259
-rw-r--r--scene/gui/file_dialog.h23
-rw-r--r--scene/gui/gradient_edit.cpp59
-rw-r--r--scene/gui/gradient_edit.h1
-rw-r--r--scene/gui/graph_edit.cpp291
-rw-r--r--scene/gui/graph_edit.h6
-rw-r--r--scene/gui/graph_node.cpp197
-rw-r--r--scene/gui/graph_node.h1
-rw-r--r--scene/gui/grid_container.cpp47
-rw-r--r--scene/gui/grid_container.h1
-rw-r--r--scene/gui/item_list.cpp227
-rw-r--r--scene/gui/item_list.h2
-rw-r--r--scene/gui/label.cpp148
-rw-r--r--scene/gui/label.h45
-rw-r--r--scene/gui/line_edit.cpp353
-rw-r--r--scene/gui/line_edit.h2
-rw-r--r--scene/gui/link_button.cpp23
-rw-r--r--scene/gui/link_button.h1
-rw-r--r--scene/gui/margin_container.cpp27
-rw-r--r--scene/gui/menu_button.cpp23
-rw-r--r--scene/gui/menu_button.h1
-rw-r--r--scene/gui/nine_patch_rect.cpp29
-rw-r--r--scene/gui/nine_patch_rect.h1
-rw-r--r--scene/gui/option_button.cpp84
-rw-r--r--scene/gui/option_button.h1
-rw-r--r--scene/gui/panel.cpp8
-rw-r--r--scene/gui/panel.h6
-rw-r--r--scene/gui/panel_container.cpp36
-rw-r--r--scene/gui/panel_container.h1
-rw-r--r--scene/gui/popup.cpp26
-rw-r--r--scene/gui/popup.h2
-rw-r--r--scene/gui/popup_menu.cpp295
-rw-r--r--scene/gui/popup_menu.h2
-rw-r--r--scene/gui/progress_bar.cpp8
-rw-r--r--scene/gui/progress_bar.h1
-rw-r--r--scene/gui/range.cpp69
-rw-r--r--scene/gui/range.h1
-rw-r--r--scene/gui/reference_rect.cpp8
-rw-r--r--scene/gui/reference_rect.h1
-rw-r--r--scene/gui/rich_text_effect.cpp1
-rw-r--r--scene/gui/rich_text_label.cpp886
-rw-r--r--scene/gui/rich_text_label.h24
-rw-r--r--scene/gui/scroll_bar.cpp146
-rw-r--r--scene/gui/scroll_bar.h26
-rw-r--r--scene/gui/scroll_container.cpp120
-rw-r--r--scene/gui/scroll_container.h1
-rw-r--r--scene/gui/separator.cpp8
-rw-r--r--scene/gui/separator.h3
-rw-r--r--scene/gui/shortcut.cpp11
-rw-r--r--scene/gui/shortcut.h1
-rw-r--r--scene/gui/slider.cpp68
-rw-r--r--scene/gui/slider.h3
-rw-r--r--scene/gui/spin_box.cpp52
-rw-r--r--scene/gui/spin_box.h1
-rw-r--r--scene/gui/split_container.cpp100
-rw-r--r--scene/gui/split_container.h3
-rw-r--r--scene/gui/subviewport_container.cpp (renamed from scene/gui/viewport_container.cpp)105
-rw-r--r--scene/gui/subviewport_container.h (renamed from scene/gui/viewport_container.h)9
-rw-r--r--scene/gui/tab_container.cpp231
-rw-r--r--scene/gui/tab_container.h1
-rw-r--r--scene/gui/tabs.cpp185
-rw-r--r--scene/gui/tabs.h2
-rw-r--r--scene/gui/text_edit.cpp1199
-rw-r--r--scene/gui/text_edit.h18
-rw-r--r--scene/gui/texture_button.cpp71
-rw-r--r--scene/gui/texture_button.h1
-rw-r--r--scene/gui/texture_progress.cpp78
-rw-r--r--scene/gui/texture_progress.h1
-rw-r--r--scene/gui/texture_rect.cpp27
-rw-r--r--scene/gui/texture_rect.h1
-rw-r--r--scene/gui/tree.cpp991
-rw-r--r--scene/gui/tree.h12
-rw-r--r--scene/gui/video_player.cpp108
-rw-r--r--scene/gui/video_player.h2
96 files changed, 3297 insertions, 4678 deletions
diff --git a/scene/gui/SCsub b/scene/gui/SCsub
index b01e2fd54d..fc61250247 100644
--- a/scene/gui/SCsub
+++ b/scene/gui/SCsub
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-Import('env')
+Import("env")
env.add_source_files(env.scene_sources, "*.cpp")
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index a05ac08e9d..d8229b5f43 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -35,26 +35,27 @@
#include "scene/scene_string_names.h"
void BaseButton::_unpress_group() {
-
- if (!button_group.is_valid())
+ if (!button_group.is_valid()) {
return;
+ }
if (toggle_mode) {
status.pressed = true;
}
for (Set<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) {
- if (E->get() == this)
+ if (E->get() == this) {
continue;
+ }
E->get()->set_pressed(false);
}
}
void BaseButton::_gui_input(Ref<InputEvent> p_event) {
-
- if (status.disabled) // no interaction with disabled button
+ if (status.disabled) { // no interaction with disabled button
return;
+ }
Ref<InputEventMouseButton> mouse_button = p_event;
bool ui_accept = p_event->is_action("ui_accept") && !p_event->is_echo();
@@ -78,9 +79,7 @@ void BaseButton::_gui_input(Ref<InputEvent> p_event) {
}
void BaseButton::_notification(int p_what) {
-
if (p_what == NOTIFICATION_MOUSE_ENTER) {
-
status.hovering = true;
update();
}
@@ -90,7 +89,6 @@ void BaseButton::_notification(int p_what) {
update();
}
if (p_what == NOTIFICATION_DRAG_BEGIN || p_what == NOTIFICATION_SCROLL_BEGIN) {
-
if (status.press_attempt) {
status.press_attempt = false;
update();
@@ -98,13 +96,11 @@ void BaseButton::_notification(int p_what) {
}
if (p_what == NOTIFICATION_FOCUS_ENTER) {
-
status.hovering = true;
update();
}
if (p_what == NOTIFICATION_FOCUS_EXIT) {
-
if (status.press_attempt) {
status.press_attempt = false;
status.hovering = false;
@@ -116,7 +112,6 @@ void BaseButton::_notification(int p_what) {
}
if (p_what == NOTIFICATION_EXIT_TREE || (p_what == NOTIFICATION_VISIBILITY_CHANGED && !is_visible_in_tree())) {
-
if (!toggle_mode) {
status.pressed = false;
}
@@ -127,7 +122,6 @@ void BaseButton::_notification(int p_what) {
}
void BaseButton::_pressed() {
-
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed);
}
@@ -136,7 +130,6 @@ void BaseButton::_pressed() {
}
void BaseButton::_toggled(bool p_pressed) {
-
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, p_pressed);
}
@@ -145,7 +138,6 @@ void BaseButton::_toggled(bool p_pressed) {
}
void BaseButton::on_action_event(Ref<InputEvent> p_event) {
-
if (p_event->is_pressed()) {
status.press_attempt = true;
status.pressing_inside = true;
@@ -194,8 +186,9 @@ void BaseButton::toggled(bool p_pressed) {
}
void BaseButton::set_disabled(bool p_disabled) {
- if (status.disabled == p_disabled)
+ if (status.disabled == p_disabled) {
return;
+ }
status.disabled = p_disabled;
if (p_disabled) {
@@ -210,16 +203,16 @@ void BaseButton::set_disabled(bool p_disabled) {
}
bool BaseButton::is_disabled() const {
-
return status.disabled;
}
void BaseButton::set_pressed(bool p_pressed) {
-
- if (!toggle_mode)
+ if (!toggle_mode) {
return;
- if (status.pressed == p_pressed)
+ }
+ if (status.pressed == p_pressed) {
return;
+ }
_change_notify("pressed");
status.pressed = p_pressed;
@@ -232,29 +225,26 @@ void BaseButton::set_pressed(bool p_pressed) {
}
bool BaseButton::is_pressing() const {
-
return status.press_attempt;
}
bool BaseButton::is_pressed() const {
-
return toggle_mode ? status.pressed : status.press_attempt;
}
bool BaseButton::is_hovered() const {
-
return status.hovering;
}
BaseButton::DrawMode BaseButton::get_draw_mode() const {
-
if (status.disabled) {
return DRAW_DISABLED;
};
if (!status.press_attempt && status.hovering) {
- if (status.pressed)
+ if (status.pressed) {
return DRAW_HOVER_PRESSED;
+ }
return DRAW_HOVER;
} else {
@@ -262,66 +252,57 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
bool pressing;
if (status.press_attempt) {
-
pressing = (status.pressing_inside || keep_pressed_outside);
- if (status.pressed)
+ if (status.pressed) {
pressing = !pressing;
+ }
} else {
-
pressing = status.pressed;
}
- if (pressing)
+ if (pressing) {
return DRAW_PRESSED;
- else
+ } else {
return DRAW_NORMAL;
+ }
}
return DRAW_NORMAL;
}
void BaseButton::set_toggle_mode(bool p_on) {
-
toggle_mode = p_on;
}
bool BaseButton::is_toggle_mode() const {
-
return toggle_mode;
}
void BaseButton::set_shortcut_in_tooltip(bool p_on) {
-
shortcut_in_tooltip = p_on;
}
bool BaseButton::is_shortcut_in_tooltip_enabled() const {
-
return shortcut_in_tooltip;
}
void BaseButton::set_action_mode(ActionMode p_mode) {
-
action_mode = p_mode;
}
BaseButton::ActionMode BaseButton::get_action_mode() const {
-
return action_mode;
}
void BaseButton::set_button_mask(int p_mask) {
-
button_mask = p_mask;
}
int BaseButton::get_button_mask() const {
-
return button_mask;
}
void BaseButton::set_enabled_focus_mode(FocusMode p_mode) {
-
enabled_focus_mode = p_mode;
if (!status.disabled) {
set_focus_mode(p_mode);
@@ -329,22 +310,18 @@ void BaseButton::set_enabled_focus_mode(FocusMode p_mode) {
}
Control::FocusMode BaseButton::get_enabled_focus_mode() const {
-
return enabled_focus_mode;
}
void BaseButton::set_keep_pressed_outside(bool p_on) {
-
keep_pressed_outside = p_on;
}
bool BaseButton::is_keep_pressed_outside() const {
-
return keep_pressed_outside;
}
void BaseButton::set_shortcut(const Ref<ShortCut> &p_shortcut) {
-
shortcut = p_shortcut;
set_process_unhandled_input(shortcut.is_valid());
}
@@ -354,15 +331,12 @@ Ref<ShortCut> BaseButton::get_shortcut() const {
}
void BaseButton::_unhandled_input(Ref<InputEvent> p_event) {
-
if (!is_disabled() && is_visible_in_tree() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) {
-
on_action_event(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()) {
String text = shortcut->get_name() + " (" + shortcut->get_as_text() + ")";
@@ -375,7 +349,6 @@ String BaseButton::get_tooltip(const Point2 &p_pos) const {
}
void BaseButton::set_button_group(const Ref<ButtonGroup> &p_group) {
-
if (button_group.is_valid()) {
button_group->buttons.erase(this);
}
@@ -390,12 +363,10 @@ void BaseButton::set_button_group(const Ref<ButtonGroup> &p_group) {
}
Ref<ButtonGroup> BaseButton::get_button_group() const {
-
return button_group;
}
void BaseButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &BaseButton::_gui_input);
ClassDB::bind_method(D_METHOD("_unhandled_input"), &BaseButton::_unhandled_input);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed);
@@ -452,7 +423,6 @@ void BaseButton::_bind_methods() {
}
BaseButton::BaseButton() {
-
toggle_mode = false;
shortcut_in_tooltip = true;
keep_pressed_outside = false;
@@ -468,21 +438,18 @@ BaseButton::BaseButton() {
}
BaseButton::~BaseButton() {
-
if (button_group.is_valid()) {
button_group->buttons.erase(this);
}
}
void ButtonGroup::get_buttons(List<BaseButton *> *r_buttons) {
-
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
r_buttons->push_back(E->get());
}
}
Array ButtonGroup::_get_buttons() {
-
Array btns;
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
btns.push_back(E->get());
@@ -492,22 +459,20 @@ Array ButtonGroup::_get_buttons() {
}
BaseButton *ButtonGroup::get_pressed_button() {
-
for (Set<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
- if (E->get()->is_pressed())
+ if (E->get()->is_pressed()) {
return E->get();
+ }
}
- return NULL;
+ return nullptr;
}
void ButtonGroup::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_pressed_button"), &ButtonGroup::get_pressed_button);
ClassDB::bind_method(D_METHOD("get_buttons"), &ButtonGroup::_get_buttons);
}
ButtonGroup::ButtonGroup() {
-
set_local_to_scene(true);
}
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 21757488a6..05a975e266 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -36,7 +36,6 @@
class ButtonGroup;
class BaseButton : public Control {
-
GDCLASS(BaseButton, Control);
public:
@@ -55,7 +54,6 @@ private:
ActionMode action_mode;
struct Status {
-
bool pressed;
bool hovering;
bool press_attempt;
@@ -136,7 +134,6 @@ VARIANT_ENUM_CAST(BaseButton::DrawMode)
VARIANT_ENUM_CAST(BaseButton::ActionMode)
class ButtonGroup : public Resource {
-
GDCLASS(ButtonGroup, Resource);
friend class BaseButton;
Set<BaseButton *> buttons;
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 0da6e0fdfa..75d04dba61 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -33,14 +33,12 @@
#include "margin_container.h"
struct _MinSizeCache {
-
int min_size;
bool will_stretch;
int final_size;
};
void BoxContainer::_resort() {
-
/** First pass, determine minimum size AND amount of stretchable elements */
Size2i new_size = get_size();
@@ -56,10 +54,12 @@ void BoxContainer::_resort() {
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())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
_MinSizeCache msc;
@@ -84,8 +84,9 @@ void BoxContainer::_resort() {
children_count++;
}
- if (children_count == 0)
+ if (children_count == 0) {
return;
+ }
int stretch_max = (vertical ? new_size.height : new_size.width) - (children_count - 1) * sep;
int stretch_diff = stretch_max - stretch_min;
@@ -105,12 +106,13 @@ void BoxContainer::_resort() {
bool refit_successful = true; //assume refit-test will go well
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())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
ERR_FAIL_COND(!min_size_cache.has(c));
_MinSizeCache &msc = min_size_cache[c];
@@ -134,8 +136,9 @@ void BoxContainer::_resort() {
}
}
- if (refit_successful) //uf refit went well, break
+ if (refit_successful) { //uf refit went well, break
break;
+ }
}
/** Final pass, draw and stretch elements **/
@@ -158,19 +161,21 @@ void BoxContainer::_resort() {
int 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())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
_MinSizeCache &msc = min_size_cache[c];
- if (first)
+ if (first) {
first = false;
- else
+ } else {
ofs += sep;
+ }
int from = ofs;
int to = ofs + msc.final_size;
@@ -187,10 +192,8 @@ void BoxContainer::_resort() {
Rect2 rect;
if (vertical) {
-
rect = Rect2(0, from, new_size.width, size);
} else {
-
rect = Rect2(from, 0, size, new_size.height);
}
@@ -202,7 +205,6 @@ void BoxContainer::_resort() {
}
Size2 BoxContainer::get_minimum_size() const {
-
/* Calculate MINIMUM SIZE */
Size2i minimum;
@@ -212,10 +214,12 @@ Size2 BoxContainer::get_minimum_size() const {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
if (!c->is_visible()) {
continue;
@@ -247,15 +251,11 @@ Size2 BoxContainer::get_minimum_size() const {
}
void BoxContainer::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_SORT_CHILDREN: {
-
_resort();
} break;
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
} break;
}
@@ -271,28 +271,27 @@ BoxContainer::AlignMode BoxContainer::get_alignment() const {
}
void BoxContainer::add_spacer(bool p_begin) {
-
Control *c = memnew(Control);
c->set_mouse_filter(MOUSE_FILTER_PASS); //allow spacer to pass mouse events
- if (vertical)
+ if (vertical) {
c->set_v_size_flags(SIZE_EXPAND_FILL);
- else
+ } else {
c->set_h_size_flags(SIZE_EXPAND_FILL);
+ }
add_child(c);
- if (p_begin)
+ if (p_begin) {
move_child(c, 0);
+ }
}
BoxContainer::BoxContainer(bool p_vertical) {
-
vertical = p_vertical;
align = ALIGN_BEGIN;
}
void BoxContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("add_spacer", "begin"), &BoxContainer::add_spacer);
ClassDB::bind_method(D_METHOD("get_alignment"), &BoxContainer::get_alignment);
ClassDB::bind_method(D_METHOD("set_alignment", "alignment"), &BoxContainer::set_alignment);
@@ -305,7 +304,6 @@ void BoxContainer::_bind_methods() {
}
MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control *p_control, bool p_expand) {
-
Label *l = memnew(Label);
l->set_text(p_label);
add_child(l);
@@ -313,8 +311,9 @@ MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control
mc->add_theme_constant_override("margin_left", 0);
mc->add_child(p_control);
add_child(mc);
- if (p_expand)
+ if (p_expand) {
mc->set_v_size_flags(SIZE_EXPAND_FILL);
+ }
return mc;
}
diff --git a/scene/gui/box_container.h b/scene/gui/box_container.h
index 0d7deda364..cc6f6349df 100644
--- a/scene/gui/box_container.h
+++ b/scene/gui/box_container.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
class BoxContainer : public Container {
-
GDCLASS(BoxContainer, Container);
public:
@@ -67,7 +66,6 @@ public:
};
class HBoxContainer : public BoxContainer {
-
GDCLASS(HBoxContainer, BoxContainer);
public:
@@ -77,7 +75,6 @@ public:
class MarginContainer;
class VBoxContainer : public BoxContainer {
-
GDCLASS(VBoxContainer, BoxContainer);
public:
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index f71d322412..e400801b66 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -31,27 +31,28 @@
#include "button.h"
#include "core/translation.h"
-#include "servers/visual_server.h"
+#include "servers/rendering_server.h"
Size2 Button::get_minimum_size() const {
-
Size2 minsize = get_theme_font("font")->get_string_size(xl_text);
- if (clip_text)
+ if (clip_text) {
minsize.width = 0;
+ }
if (!expand_icon) {
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon"))
+ if (icon.is_null() && has_theme_icon("icon")) {
_icon = Control::get_theme_icon("icon");
- else
+ } else {
_icon = icon;
+ }
if (!_icon.is_null()) {
-
minsize.height = MAX(minsize.height, _icon->get_height());
minsize.width += _icon->get_width();
- if (xl_text != "")
+ if (xl_text != "") {
minsize.width += get_theme_constant("hseparation");
+ }
}
}
@@ -59,21 +60,17 @@ Size2 Button::get_minimum_size() const {
}
void Button::_set_internal_margin(Margin p_margin, float p_value) {
-
_internal_margin[p_margin] = p_value;
}
void Button::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
-
xl_text = tr(text);
minimum_size_changed();
update();
} break;
case NOTIFICATION_DRAW: {
-
RID ci = get_canvas_item();
Size2 size = get_size();
Color color;
@@ -83,82 +80,88 @@ void Button::_notification(int p_what) {
switch (get_draw_mode()) {
case DRAW_NORMAL: {
-
style = get_theme_stylebox("normal");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_normal"))
+ if (has_theme_color("icon_color_normal")) {
color_icon = get_theme_color("icon_color_normal");
+ }
} break;
case DRAW_HOVER_PRESSED: {
-
if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) {
style = get_theme_stylebox("hover_pressed");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
- if (has_theme_color("font_color_hover_pressed"))
+ }
+ if (has_theme_color("font_color_hover_pressed")) {
color = get_theme_color("font_color_hover_pressed");
- else
+ } else {
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_hover_pressed"))
+ }
+ if (has_theme_color("icon_color_hover_pressed")) {
color_icon = get_theme_color("icon_color_hover_pressed");
+ }
break;
}
[[fallthrough]];
}
case DRAW_PRESSED: {
-
style = get_theme_stylebox("pressed");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
- if (has_theme_color("font_color_pressed"))
+ }
+ if (has_theme_color("font_color_pressed")) {
color = get_theme_color("font_color_pressed");
- else
+ } else {
color = get_theme_color("font_color");
- if (has_theme_color("icon_color_pressed"))
+ }
+ if (has_theme_color("icon_color_pressed")) {
color_icon = get_theme_color("icon_color_pressed");
+ }
} break;
case DRAW_HOVER: {
-
style = get_theme_stylebox("hover");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color_hover");
- if (has_theme_color("icon_color_hover"))
+ if (has_theme_color("icon_color_hover")) {
color_icon = get_theme_color("icon_color_hover");
+ }
} break;
case DRAW_DISABLED: {
-
style = get_theme_stylebox("disabled");
- if (!flat)
+ if (!flat) {
style->draw(ci, Rect2(Point2(0, 0), size));
+ }
color = get_theme_color("font_color_disabled");
- if (has_theme_color("icon_color_disabled"))
+ if (has_theme_color("icon_color_disabled")) {
color_icon = get_theme_color("icon_color_disabled");
+ }
} break;
}
if (has_focus()) {
-
Ref<StyleBox> style2 = get_theme_stylebox("focus");
style2->draw(ci, Rect2(Point2(), size));
}
Ref<Font> font = get_theme_font("font");
Ref<Texture2D> _icon;
- if (icon.is_null() && has_theme_icon("icon"))
+ if (icon.is_null() && has_theme_icon("icon")) {
_icon = Control::get_theme_icon("icon");
- else
+ } else {
_icon = icon;
+ }
Rect2 icon_region = Rect2();
if (!_icon.is_null()) {
-
int valign = size.height - style->get_minimum_size().y;
if (is_disabled()) {
color_icon.a = 0.4;
@@ -172,8 +175,9 @@ void Button::_notification(int p_what) {
if (expand_icon) {
Size2 _size = get_size() - style->get_offset() * 2;
_size.width -= get_theme_constant("hseparation") + icon_ofs_region;
- if (!clip_text)
+ if (!clip_text) {
_size.width -= get_theme_font("font")->get_string_size(xl_text).width;
+ }
float icon_width = _icon->get_width() * _size.height / _icon->get_height();
float icon_height = _size.height;
@@ -209,8 +213,9 @@ void Button::_notification(int p_what) {
text_ofs.y += style->get_offset().y;
} break;
case ALIGN_CENTER: {
- if (text_ofs.x < 0)
+ if (text_ofs.x < 0) {
text_ofs.x = 0;
+ }
text_ofs += icon_ofs;
text_ofs += style->get_offset();
} break;
@@ -235,24 +240,24 @@ void Button::_notification(int p_what) {
}
void Button::set_text(const String &p_text) {
-
- if (text == p_text)
+ if (text == p_text) {
return;
+ }
text = p_text;
xl_text = tr(p_text);
update();
_change_notify("text");
minimum_size_changed();
}
-String Button::get_text() const {
+String Button::get_text() const {
return text;
}
void Button::set_icon(const Ref<Texture2D> &p_icon) {
-
- if (icon == p_icon)
+ if (icon == p_icon) {
return;
+ }
icon = p_icon;
update();
_change_notify("icon");
@@ -260,59 +265,49 @@ void Button::set_icon(const Ref<Texture2D> &p_icon) {
}
Ref<Texture2D> Button::get_icon() const {
-
return icon;
}
void Button::set_expand_icon(bool p_expand_icon) {
-
expand_icon = p_expand_icon;
update();
minimum_size_changed();
}
bool Button::is_expand_icon() const {
-
return expand_icon;
}
void Button::set_flat(bool p_flat) {
-
flat = p_flat;
update();
_change_notify("flat");
}
bool Button::is_flat() const {
-
return flat;
}
void Button::set_clip_text(bool p_clip_text) {
-
clip_text = p_clip_text;
update();
minimum_size_changed();
}
bool Button::get_clip_text() const {
-
return clip_text;
}
void Button::set_text_align(TextAlign p_align) {
-
align = p_align;
update();
}
Button::TextAlign Button::get_text_align() const {
-
return align;
}
void Button::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_text", "text"), &Button::set_text);
ClassDB::bind_method(D_METHOD("get_text"), &Button::get_text);
ClassDB::bind_method(D_METHOD("set_button_icon", "texture"), &Button::set_icon);
@@ -339,7 +334,6 @@ void Button::_bind_methods() {
}
Button::Button(const String &p_text) {
-
flat = false;
clip_text = false;
expand_icon = false;
diff --git a/scene/gui/button.h b/scene/gui/button.h
index 3135b98578..e757badd3e 100644
--- a/scene/gui/button.h
+++ b/scene/gui/button.h
@@ -34,7 +34,6 @@
#include "scene/gui/base_button.h"
class Button : public BaseButton {
-
GDCLASS(Button, BaseButton);
public:
diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp
index 64d6885bc8..f8f9bec3d7 100644
--- a/scene/gui/center_container.cpp
+++ b/scene/gui/center_container.cpp
@@ -31,19 +31,21 @@
#include "center_container.h"
Size2 CenterContainer::get_minimum_size() const {
-
- if (use_top_left)
+ if (use_top_left) {
return Size2();
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
@@ -53,7 +55,6 @@ Size2 CenterContainer::get_minimum_size() const {
}
void CenterContainer::set_use_top_left(bool p_enable) {
-
if (use_top_left == p_enable) {
return;
}
@@ -65,22 +66,20 @@ void CenterContainer::set_use_top_left(bool p_enable) {
}
bool CenterContainer::is_using_top_left() const {
-
return use_top_left;
}
void CenterContainer::_notification(int p_what) {
-
if (p_what == NOTIFICATION_SORT_CHILDREN) {
-
Size2 size = get_size();
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
@@ -90,7 +89,6 @@ void CenterContainer::_notification(int p_what) {
}
void CenterContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_use_top_left", "enable"), &CenterContainer::set_use_top_left);
ClassDB::bind_method(D_METHOD("is_using_top_left"), &CenterContainer::is_using_top_left);
@@ -98,6 +96,5 @@ void CenterContainer::_bind_methods() {
}
CenterContainer::CenterContainer() {
-
use_top_left = false;
}
diff --git a/scene/gui/center_container.h b/scene/gui/center_container.h
index 98733f384d..ae9f87db16 100644
--- a/scene/gui/center_container.h
+++ b/scene/gui/center_container.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
class CenterContainer : public Container {
-
GDCLASS(CenterContainer, Container);
bool use_top_left;
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index d68bd4fe4e..df6f38f65d 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -30,7 +30,7 @@
#include "check_box.h"
-#include "servers/visual_server.h"
+#include "servers/rendering_server.h"
Size2 CheckBox::get_icon_size() const {
Ref<Texture2D> checked = Control::get_theme_icon("checked");
@@ -39,19 +39,22 @@ Size2 CheckBox::get_icon_size() const {
Ref<Texture2D> radio_unchecked = Control::get_theme_icon("radio_unchecked");
Size2 tex_size = Size2(0, 0);
- if (!checked.is_null())
+ if (!checked.is_null()) {
tex_size = Size2(checked->get_width(), checked->get_height());
- if (!unchecked.is_null())
+ }
+ if (!unchecked.is_null()) {
tex_size = Size2(MAX(tex_size.width, unchecked->get_width()), MAX(tex_size.height, unchecked->get_height()));
- if (!radio_checked.is_null())
+ }
+ if (!radio_checked.is_null()) {
tex_size = Size2(MAX(tex_size.width, radio_checked->get_width()), MAX(tex_size.height, radio_checked->get_height()));
- if (!radio_unchecked.is_null())
+ }
+ if (!radio_unchecked.is_null()) {
tex_size = Size2(MAX(tex_size.width, radio_unchecked->get_width()), MAX(tex_size.height, radio_unchecked->get_height()));
+ }
return tex_size;
}
Size2 CheckBox::get_minimum_size() const {
-
Size2 minsize = Button::get_minimum_size();
Size2 tex_size = get_icon_size();
minsize.width += tex_size.width;
@@ -65,12 +68,9 @@ Size2 CheckBox::get_minimum_size() const {
}
void CheckBox::_notification(int p_what) {
-
if (p_what == NOTIFICATION_THEME_CHANGED) {
-
_set_internal_margin(MARGIN_LEFT, get_icon_size().width);
} else if (p_what == NOTIFICATION_DRAW) {
-
RID ci = get_canvas_item();
Ref<Texture2D> on = Control::get_theme_icon(is_radio() ? "radio_checked" : "checked");
@@ -81,15 +81,15 @@ void CheckBox::_notification(int p_what) {
ofs.x = sb->get_margin(MARGIN_LEFT);
ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust");
- if (is_pressed())
+ if (is_pressed()) {
on->draw(ci, ofs);
- else
+ } else {
off->draw(ci, ofs);
+ }
}
}
bool CheckBox::is_radio() {
-
return get_button_group().is_valid();
}
diff --git a/scene/gui/check_box.h b/scene/gui/check_box.h
index 7c8f8c11d6..58f7cce55e 100644
--- a/scene/gui/check_box.h
+++ b/scene/gui/check_box.h
@@ -36,7 +36,6 @@
@author Mariano Suligoy <marianognu.esyrpg@gmail.com>
*/
class CheckBox : public Button {
-
GDCLASS(CheckBox, Button);
protected:
diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp
index ac967a128c..1ddc730dd1 100644
--- a/scene/gui/check_button.cpp
+++ b/scene/gui/check_button.cpp
@@ -31,28 +31,29 @@
#include "check_button.h"
#include "core/print_string.h"
-#include "servers/visual_server.h"
+#include "servers/rendering_server.h"
Size2 CheckButton::get_icon_size() const {
-
Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
Ref<Texture2D> off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
Size2 tex_size = Size2(0, 0);
- if (!on.is_null())
+ if (!on.is_null()) {
tex_size = Size2(on->get_width(), on->get_height());
- if (!off.is_null())
+ }
+ if (!off.is_null()) {
tex_size = Size2(MAX(tex_size.width, off->get_width()), MAX(tex_size.height, off->get_height()));
+ }
return tex_size;
}
Size2 CheckButton::get_minimum_size() const {
-
Size2 minsize = Button::get_minimum_size();
Size2 tex_size = get_icon_size();
minsize.width += tex_size.width;
- if (get_text().length() > 0)
+ if (get_text().length() > 0) {
minsize.width += get_theme_constant("hseparation");
+ }
Ref<StyleBox> sb = get_theme_stylebox("normal");
minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM));
@@ -60,12 +61,9 @@ Size2 CheckButton::get_minimum_size() const {
}
void CheckButton::_notification(int p_what) {
-
if (p_what == NOTIFICATION_THEME_CHANGED) {
-
_set_internal_margin(MARGIN_RIGHT, get_icon_size().width);
} else if (p_what == NOTIFICATION_DRAW) {
-
RID ci = get_canvas_item();
Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
@@ -78,15 +76,15 @@ void CheckButton::_notification(int p_what) {
ofs.x = get_size().width - (tex_size.width + sb->get_margin(MARGIN_RIGHT));
ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant("check_vadjust");
- if (is_pressed())
+ if (is_pressed()) {
on->draw(ci, ofs);
- else
+ } else {
off->draw(ci, ofs);
+ }
}
}
CheckButton::CheckButton() {
-
set_toggle_mode(true);
set_text_align(ALIGN_LEFT);
diff --git a/scene/gui/check_button.h b/scene/gui/check_button.h
index 3599c26a4c..8bbad0b4b3 100644
--- a/scene/gui/check_button.h
+++ b/scene/gui/check_button.h
@@ -36,7 +36,6 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
class CheckButton : public Button {
-
GDCLASS(CheckButton, Button);
protected:
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 2ec9bb2292..84170a65d1 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -30,7 +30,7 @@
#include "color_picker.h"
-#include "core/input/input_filter.h"
+#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
@@ -41,17 +41,14 @@
#include "scene/main/window.h"
void ColorPicker::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
-
btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker"));
bt_add_preset->set_icon(get_theme_icon("add_preset"));
_update_controls();
} break;
case NOTIFICATION_ENTER_TREE: {
-
btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker"));
bt_add_preset->set_icon(get_theme_icon("add_preset"));
@@ -68,40 +65,40 @@ void ColorPicker::_notification(int p_what) {
#endif
} break;
case NOTIFICATION_PARENTED: {
-
- for (int i = 0; i < 4; i++)
- set_margin((Margin)i, get_theme_constant("margin"));
+ for (int i = 0; i < 4; i++) {
+ set_margin((Margin)i, get_margin((Margin)i) + get_theme_constant("margin"));
+ }
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
Popup *p = Object::cast_to<Popup>(get_parent());
- if (p)
+ if (p) {
p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant("margin") * 2, get_combined_minimum_size().height + get_theme_constant("margin") * 2));
+ }
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
-
- if (screen != NULL && screen->is_visible())
+ if (screen != nullptr && screen->is_visible()) {
screen->hide();
+ }
} break;
}
}
void ColorPicker::set_focus_on_line_edit() {
-
c_text->call_deferred("grab_focus");
}
void ColorPicker::_update_controls() {
-
const char *rgb[3] = { "R", "G", "B" };
const char *hsv[3] = { "H", "S", "V" };
if (hsv_mode_enabled) {
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
labels[i]->set_text(hsv[i]);
+ }
} else {
- for (int i = 0; i < 3; i++)
+ for (int i = 0; i < 3; i++) {
labels[i]->set_text(rgb[i]);
+ }
}
if (hsv_mode_enabled) {
@@ -127,7 +124,6 @@ void ColorPicker::_update_controls() {
}
void ColorPicker::_set_pick_color(const Color &p_color, bool p_update_sliders) {
-
color = p_color;
if (color != last_hsv) {
h = color.get_h();
@@ -136,38 +132,37 @@ void ColorPicker::_set_pick_color(const Color &p_color, bool p_update_sliders) {
last_hsv = color;
}
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_color(p_update_sliders);
}
void ColorPicker::set_pick_color(const Color &p_color) {
-
_set_pick_color(p_color, true); //because setters can't have more arguments
}
void ColorPicker::set_edit_alpha(bool p_show) {
-
edit_alpha = p_show;
_update_controls();
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_color();
sample->update();
}
bool ColorPicker::is_editing_alpha() const {
-
return edit_alpha;
}
void ColorPicker::_value_changed(double) {
-
- if (updating)
+ if (updating) {
return;
+ }
if (hsv_mode_enabled) {
color.set_hsv(scroll[0]->get_value() / 360.0,
@@ -185,28 +180,28 @@ void ColorPicker::_value_changed(double) {
}
void ColorPicker::_html_entered(const String &p_html) {
-
- if (updating || text_is_constructor || !c_text->is_visible())
+ if (updating || text_is_constructor || !c_text->is_visible()) {
return;
+ }
float last_alpha = color.a;
color = Color::html(p_html);
- if (!is_editing_alpha())
+ if (!is_editing_alpha()) {
color.a = last_alpha;
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
set_pick_color(color);
emit_signal("color_changed", color);
}
void ColorPicker::_update_color(bool p_update_sliders) {
-
updating = true;
if (p_update_sliders) {
-
if (hsv_mode_enabled) {
for (int i = 0; i < 4; i++) {
scroll[i]->set_step(1.0);
@@ -225,8 +220,9 @@ void ColorPicker::_update_color(bool p_update_sliders) {
if (raw_mode_enabled) {
scroll[i]->set_step(0.01);
scroll[i]->set_max(100);
- if (i == 3)
+ if (i == 3) {
scroll[i]->set_max(1);
+ }
scroll[i]->set_value(color.components[i]);
} else {
scroll[i]->set_step(1);
@@ -266,7 +262,6 @@ void ColorPicker::_update_presets() {
}
void ColorPicker::_text_type_toggled() {
-
text_is_constructor = !text_is_constructor;
if (text_is_constructor) {
text_type->set_text("");
@@ -275,7 +270,7 @@ void ColorPicker::_text_type_toggled() {
c_text->set_editable(false);
} else {
text_type->set_text("#");
- text_type->set_icon(NULL);
+ text_type->set_icon(nullptr);
c_text->set_editable(true);
}
@@ -283,12 +278,10 @@ void ColorPicker::_text_type_toggled() {
}
Color ColorPicker::get_pick_color() const {
-
return color;
}
void ColorPicker::add_preset(const Color &p_color) {
-
if (presets.find(p_color)) {
presets.move_to_back(presets.find(p_color));
} else {
@@ -305,7 +298,6 @@ void ColorPicker::add_preset(const Color &p_color) {
}
void ColorPicker::erase_preset(const Color &p_color) {
-
if (presets.find(p_color)) {
presets.erase(presets.find(p_color));
preset->update();
@@ -320,7 +312,6 @@ void ColorPicker::erase_preset(const Color &p_color) {
}
PackedColorArray ColorPicker::get_presets() const {
-
PackedColorArray arr;
arr.resize(presets.size());
for (int i = 0; i < presets.size(); i++) {
@@ -330,42 +321,44 @@ PackedColorArray ColorPicker::get_presets() const {
}
void ColorPicker::set_hsv_mode(bool p_enabled) {
-
- if (hsv_mode_enabled == p_enabled || raw_mode_enabled)
+ if (hsv_mode_enabled == p_enabled || raw_mode_enabled) {
return;
+ }
hsv_mode_enabled = p_enabled;
- if (btn_hsv->is_pressed() != p_enabled)
+ if (btn_hsv->is_pressed() != p_enabled) {
btn_hsv->set_pressed(p_enabled);
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_controls();
_update_color();
}
bool ColorPicker::is_hsv_mode() const {
-
return hsv_mode_enabled;
}
void ColorPicker::set_raw_mode(bool p_enabled) {
-
- if (raw_mode_enabled == p_enabled || hsv_mode_enabled)
+ if (raw_mode_enabled == p_enabled || hsv_mode_enabled) {
return;
+ }
raw_mode_enabled = p_enabled;
- if (btn_raw->is_pressed() != p_enabled)
+ if (btn_raw->is_pressed() != p_enabled) {
btn_raw->set_pressed(p_enabled);
+ }
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
_update_controls();
_update_color();
}
bool ColorPicker::is_raw_mode() const {
-
return raw_mode_enabled;
}
@@ -381,10 +374,11 @@ void ColorPicker::_update_text_value() {
bool visible = true;
if (text_is_constructor) {
String t = "Color(" + String::num(color.r) + ", " + String::num(color.g) + ", " + String::num(color.b);
- if (edit_alpha && color.a < 1)
+ if (edit_alpha && color.a < 1) {
t += ", " + String::num(color.a) + ")";
- else
+ } else {
t += ")";
+ }
c_text->set_text(t);
}
@@ -414,8 +408,9 @@ void ColorPicker::_sample_draw() {
}
void ColorPicker::_hsv_draw(int p_which, Control *c) {
- if (!c)
+ if (!c) {
return;
+ }
if (p_which == 0) {
Vector<Point2> points;
points.push_back(Vector2());
@@ -458,7 +453,6 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) {
}
void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid()) {
@@ -472,8 +466,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
} else if (deferred_mode_enabled && !bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
emit_signal("color_changed", color);
changing_color = false;
@@ -485,8 +480,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
- if (!changing_color)
+ if (!changing_color) {
return;
+ }
float x = CLAMP((float)mev->get_position().x, 0, uv_edit->get_size().width);
float y = CLAMP((float)mev->get_position().y, 0, uv_edit->get_size().height);
s = x / uv_edit->get_size().width;
@@ -495,17 +491,16 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
}
}
void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid()) {
-
if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
changing_color = true;
float y = CLAMP((float)bev->get_position().y, 0, w_edit->get_size().height);
@@ -517,31 +512,32 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
- else if (!bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT)
+ } else if (!bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
emit_signal("color_changed", color);
+ }
}
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
-
- if (!changing_color)
+ if (!changing_color) {
return;
+ }
float y = CLAMP((float)mev->get_position().y, 0, w_edit->get_size().height);
h = y / w_edit->get_size().height;
color.set_hsv(h, s, v, color.a);
last_hsv = color;
set_pick_color(color);
_update_color();
- if (!deferred_mode_enabled)
+ if (!deferred_mode_enabled) {
emit_signal("color_changed", color);
+ }
}
}
void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid()) {
@@ -569,19 +565,18 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
-
int index = mev->get_position().x * presets.size();
if (preset->get_size().x != 0) {
index /= preset->get_size().x;
}
- if (index < 0 || index >= presets.size())
+ if (index < 0 || index >= presets.size()) {
return;
+ }
preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Set color\nRMB: Remove preset"), presets[index].to_html(presets[index].a < 1)));
}
}
void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid() && bev->get_button_index() == BUTTON_LEFT && !bev->is_pressed()) {
emit_signal("color_changed", color);
@@ -591,12 +586,12 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
Viewport *r = get_tree()->get_root();
- if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y)))
+ if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y))) {
return;
+ }
Ref<Image> img = r->get_texture()->get_data();
if (img.is_valid() && !img->empty()) {
-
Vector2 ofs = mev->get_global_position() - r->get_visible_rect().get_position();
Color c = img->get_pixel(ofs.x, r->get_visible_rect().size.height - ofs.y);
@@ -648,15 +643,17 @@ void ColorPicker::_focus_enter() {
void ColorPicker::_focus_exit() {
for (int i = 0; i < 4; i++) {
- if (!values[i]->get_line_edit()->get_menu()->is_visible())
+ if (!values[i]->get_line_edit()->get_menu()->is_visible()) {
values[i]->get_line_edit()->select(0, 0);
+ }
}
c_text->select(0, 0);
}
void ColorPicker::_html_focus_exit() {
- if (c_text->get_menu()->is_visible())
+ if (c_text->get_menu()->is_visible()) {
return;
+ }
_html_entered(c_text->get_text());
_focus_exit();
}
@@ -688,7 +685,6 @@ bool ColorPicker::are_presets_visible() const {
}
void ColorPicker::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_pick_color", "color"), &ColorPicker::set_pick_color);
ClassDB::bind_method(D_METHOD("get_pick_color"), &ColorPicker::get_pick_color);
ClassDB::bind_method(D_METHOD("set_hsv_mode"), &ColorPicker::set_hsv_mode);
@@ -722,7 +718,6 @@ void ColorPicker::_bind_methods() {
ColorPicker::ColorPicker() :
BoxContainer(true) {
-
updating = true;
edit_alpha = true;
text_is_constructor = false;
@@ -732,7 +727,7 @@ ColorPicker::ColorPicker() :
changing_color = false;
presets_enabled = true;
presets_visible = true;
- screen = NULL;
+ screen = nullptr;
HBoxContainer *hb_edit = memnew(HBoxContainer);
add_child(hb_edit);
@@ -779,7 +774,6 @@ ColorPicker::ColorPicker() :
vbr->set_h_size_flags(SIZE_EXPAND_FILL);
for (int i = 0; i < 4; i++) {
-
HBoxContainer *hbc = memnew(HBoxContainer);
labels[i] = memnew(Label());
@@ -826,13 +820,11 @@ ColorPicker::ColorPicker() :
text_type->set_text("#");
text_type->set_tooltip(TTR("Switch between hexadecimal and code values."));
if (Engine::get_singleton()->is_editor_hint()) {
-
#ifdef TOOLS_ENABLED
text_type->set_custom_minimum_size(Size2(28 * EDSCALE, 0)); // Adjust for the width of the "Script" icon.
#endif
text_type->connect("pressed", callable_mp(this, &ColorPicker::_text_type_toggled));
} else {
-
text_type->set_flat(true);
text_type->set_mouse_filter(MOUSE_FILTER_IGNORE);
}
@@ -873,19 +865,16 @@ ColorPicker::ColorPicker() :
/////////////////
void ColorPickerButton::_color_changed(const Color &p_color) {
-
color = p_color;
update();
emit_signal("color_changed", color);
}
void ColorPickerButton::_modal_closed() {
-
emit_signal("popup_closed");
}
void ColorPickerButton::pressed() {
-
_update_picker();
popup->set_as_minsize();
@@ -904,7 +893,6 @@ void ColorPickerButton::pressed() {
if (i & 1) {
cp_rect.position.x = get_screen_position().x;
} else {
-
cp_rect.position.x = get_screen_position().x - MAX(0, (cp_rect.size.x - get_size().x));
}
@@ -918,10 +906,8 @@ void ColorPickerButton::pressed() {
}
void ColorPickerButton::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_DRAW: {
-
const Ref<StyleBox> normal = get_theme_stylebox("normal");
const Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size());
draw_texture_rect(Control::get_theme_icon("bg", "ColorPickerButton"), r, true);
@@ -933,9 +919,9 @@ void ColorPickerButton::_notification(int p_what) {
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
-
- if (popup)
+ if (popup) {
popup->hide();
+ }
} break;
}
@@ -947,7 +933,6 @@ void ColorPickerButton::_notification(int p_what) {
}
void ColorPickerButton::set_pick_color(const Color &p_color) {
-
color = p_color;
if (picker) {
picker->set_pick_color(p_color);
@@ -955,13 +940,12 @@ void ColorPickerButton::set_pick_color(const Color &p_color) {
update();
}
-Color ColorPickerButton::get_pick_color() const {
+Color ColorPickerButton::get_pick_color() const {
return color;
}
void ColorPickerButton::set_edit_alpha(bool p_show) {
-
edit_alpha = p_show;
if (picker) {
picker->set_edit_alpha(p_show);
@@ -969,18 +953,15 @@ void ColorPickerButton::set_edit_alpha(bool p_show) {
}
bool ColorPickerButton::is_editing_alpha() const {
-
return edit_alpha;
}
ColorPicker *ColorPickerButton::get_picker() {
-
_update_picker();
return picker;
}
PopupPanel *ColorPickerButton::get_popup() {
-
_update_picker();
return popup;
}
@@ -1004,7 +985,6 @@ void ColorPickerButton::_update_picker() {
}
void ColorPickerButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_pick_color", "color"), &ColorPickerButton::set_pick_color);
ClassDB::bind_method(D_METHOD("get_pick_color"), &ColorPickerButton::get_pick_color);
ClassDB::bind_method(D_METHOD("get_picker"), &ColorPickerButton::get_picker);
@@ -1020,12 +1000,11 @@ void ColorPickerButton::_bind_methods() {
}
ColorPickerButton::ColorPickerButton() {
-
// Initialization is now done deferred,
// this improves performance in the inspector as the color picker
// can be expensive to initialize.
- picker = NULL;
- popup = NULL;
+ picker = nullptr;
+ popup = nullptr;
edit_alpha = true;
set_toggle_mode(true);
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index dde2f37135..31ae92f4e4 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -44,7 +44,6 @@
#include "scene/gui/tool_button.h"
class ColorPicker : public BoxContainer {
-
GDCLASS(ColorPicker, BoxContainer);
private:
@@ -139,7 +138,6 @@ public:
};
class ColorPickerButton : public Button {
-
GDCLASS(ColorPickerButton, Button);
PopupPanel *popup;
diff --git a/scene/gui/color_rect.cpp b/scene/gui/color_rect.cpp
index 61260e153c..627e589c02 100644
--- a/scene/gui/color_rect.cpp
+++ b/scene/gui/color_rect.cpp
@@ -31,25 +31,21 @@
#include "color_rect.h"
void ColorRect::set_frame_color(const Color &p_color) {
-
color = p_color;
update();
}
Color ColorRect::get_frame_color() const {
-
return color;
}
void ColorRect::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
draw_rect(Rect2(Point2(), get_size()), color);
}
}
void ColorRect::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_frame_color", "color"), &ColorRect::set_frame_color);
ClassDB::bind_method(D_METHOD("get_frame_color"), &ColorRect::get_frame_color);
@@ -57,6 +53,5 @@ void ColorRect::_bind_methods() {
}
ColorRect::ColorRect() {
-
color = Color(1, 1, 1);
}
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index 41f33bb719..a89eef6209 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -33,7 +33,6 @@
#include "scene/scene_string_names.h"
void Container::_child_minsize_changed() {
-
//Size2 ms = get_combined_minimum_size();
//if (ms.width > get_size().width || ms.height > get_size().height) {
minimum_size_changed();
@@ -41,12 +40,12 @@ void Container::_child_minsize_changed() {
}
void Container::add_child_notify(Node *p_child) {
-
Control::add_child_notify(p_child);
Control *control = Object::cast_to<Control>(p_child);
- if (!control)
+ if (!control) {
return;
+ }
control->connect("size_flags_changed", callable_mp(this, &Container::queue_sort));
control->connect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed));
@@ -57,23 +56,23 @@ void Container::add_child_notify(Node *p_child) {
}
void Container::move_child_notify(Node *p_child) {
-
Control::move_child_notify(p_child);
- if (!Object::cast_to<Control>(p_child))
+ if (!Object::cast_to<Control>(p_child)) {
return;
+ }
minimum_size_changed();
queue_sort();
}
void Container::remove_child_notify(Node *p_child) {
-
Control::remove_child_notify(p_child);
Control *control = Object::cast_to<Control>(p_child);
- if (!control)
+ if (!control) {
return;
+ }
control->disconnect("size_flags_changed", callable_mp(this, &Container::queue_sort));
control->disconnect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed));
@@ -84,9 +83,9 @@ void Container::remove_child_notify(Node *p_child) {
}
void Container::_sort_children() {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
notification(NOTIFICATION_SORT_CHILDREN);
emit_signal(SceneStringNames::get_singleton()->sort_children);
@@ -94,7 +93,6 @@ void Container::_sort_children() {
}
void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
-
ERR_FAIL_COND(!p_child);
ERR_FAIL_COND(p_child->get_parent() != this);
@@ -123,8 +121,9 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
}
}
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++) {
p_child->set_anchor(Margin(i), ANCHOR_BEGIN);
+ }
p_child->set_position(r.position);
p_child->set_size(r.size);
@@ -133,35 +132,31 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
}
void Container::queue_sort() {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (pending_sort)
+ if (pending_sort) {
return;
+ }
- MessageQueue::get_singleton()->push_call(this, "_sort_children");
+ MessageQueue::get_singleton()->push_callable(callable_mp(this, &Container::_sort_children));
pending_sort = true;
}
void Container::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_ENTER_TREE: {
pending_sort = false;
queue_sort();
} break;
case NOTIFICATION_RESIZED: {
-
queue_sort();
} break;
case NOTIFICATION_THEME_CHANGED: {
-
queue_sort();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
if (is_visible_in_tree()) {
queue_sort();
}
@@ -170,7 +165,6 @@ void Container::_notification(int p_what) {
}
String Container::get_configuration_warning() const {
-
String warning = Control::get_configuration_warning();
if (get_class() == "Container" && get_script().is_null()) {
@@ -183,9 +177,6 @@ String Container::get_configuration_warning() const {
}
void Container::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_sort_children"), &Container::_sort_children);
-
ClassDB::bind_method(D_METHOD("queue_sort"), &Container::queue_sort);
ClassDB::bind_method(D_METHOD("fit_child_in_rect", "child", "rect"), &Container::fit_child_in_rect);
@@ -194,7 +185,6 @@ void Container::_bind_methods() {
}
Container::Container() {
-
pending_sort = false;
// All containers should let mouse events pass by default.
set_mouse_filter(MOUSE_FILTER_PASS);
diff --git a/scene/gui/container.h b/scene/gui/container.h
index 0b736d9790..c8db5ee28f 100644
--- a/scene/gui/container.h
+++ b/scene/gui/container.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class Container : public Control {
-
GDCLASS(Container, Control);
bool pending_sort;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 14bca0e2c8..97daeceda9 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -30,6 +30,7 @@
#include "control.h"
+#include "core/math/geometry_2d.h"
#include "core/message_queue.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
@@ -40,7 +41,7 @@
#include "scene/main/canvas_layer.h"
#include "scene/main/window.h"
#include "scene/scene_string_names.h"
-#include "servers/visual_server.h"
+#include "servers/rendering_server.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
@@ -49,7 +50,6 @@
#ifdef TOOLS_ENABLED
Dictionary Control::_edit_get_state() const {
-
Dictionary s;
s["rotation"] = get_rotation();
s["scale"] = get_scale();
@@ -70,7 +70,6 @@ Dictionary Control::_edit_get_state() const {
}
void Control::_edit_set_state(const Dictionary &p_state) {
-
Dictionary state = p_state;
set_rotation(state["rotation"]);
@@ -162,37 +161,36 @@ Size2 Control::_edit_get_minimum_size() const {
#endif
void Control::set_custom_minimum_size(const Size2 &p_custom) {
-
- if (p_custom == data.custom_minimum_size)
+ if (p_custom == data.custom_minimum_size) {
return;
+ }
data.custom_minimum_size = p_custom;
minimum_size_changed();
}
Size2 Control::get_custom_minimum_size() const {
-
return data.custom_minimum_size;
}
void Control::_update_minimum_size_cache() {
-
Size2 minsize = get_minimum_size();
minsize.x = MAX(minsize.x, data.custom_minimum_size.x);
minsize.y = MAX(minsize.y, data.custom_minimum_size.y);
bool size_changed = false;
- if (data.minimum_size_cache != minsize)
+ if (data.minimum_size_cache != minsize) {
size_changed = true;
+ }
data.minimum_size_cache = minsize;
data.minimum_size_valid = true;
- if (size_changed)
+ if (size_changed) {
minimum_size_changed();
+ }
}
Size2 Control::get_combined_minimum_size() const {
-
if (!data.minimum_size_valid) {
const_cast<Control *>(this)->_update_minimum_size_cache();
}
@@ -200,7 +198,6 @@ Size2 Control::get_combined_minimum_size() const {
}
Transform2D Control::_get_internal_transform() const {
-
Transform2D rot_scale;
rot_scale.set_rotation_and_scale(data.rotation, data.scale);
Transform2D offset;
@@ -210,14 +207,12 @@ Transform2D Control::_get_internal_transform() const {
}
bool Control::_set(const StringName &p_name, const Variant &p_value) {
-
String name = p_name;
if (!name.begins_with("custom")) {
return false;
}
if (p_value.get_type() == Variant::NIL) {
-
if (name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
if (data.icon_override.has(dname)) {
@@ -254,8 +249,9 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
String dname = name.get_slicec('/', 1);
data.constant_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else
+ } else {
return false;
+ }
} else {
if (name.begins_with("custom_icons/")) {
@@ -276,16 +272,17 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
} else if (name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
add_theme_constant_override(dname, p_value);
- } else
+ } else {
return false;
+ }
}
return true;
}
void Control::_update_minimum_size() {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Size2 minsize = get_combined_minimum_size();
if (minsize.x > data.size_cache.x ||
@@ -302,7 +299,6 @@ void Control::_update_minimum_size() {
}
bool Control::_get(const StringName &p_name, Variant &r_ret) const {
-
String sname = p_name;
if (!sname.begins_with("custom")) {
@@ -332,13 +328,14 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const {
String name = sname.get_slicec('/', 1);
r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant();
- } else
+ } else {
return false;
+ }
return true;
}
-void Control::_get_property_list(List<PropertyInfo> *p_list) const {
+void Control::_get_property_list(List<PropertyInfo> *p_list) const {
Ref<Theme> theme = Theme::get_default();
/* Using the default theme since the properties below are meant for editor only
if (data.theme.is_valid()) {
@@ -353,10 +350,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
List<StringName> names;
theme->get_icon_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
-
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.icon_override.has(E->get()))
+ if (data.icon_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", hint));
}
@@ -365,10 +362,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
List<StringName> names;
theme->get_shader_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
-
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.shader_override.has(E->get()))
+ if (data.shader_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Shader,VisualShader", hint));
}
@@ -377,10 +374,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
List<StringName> names;
theme->get_stylebox_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
-
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.style_override.has(E->get()))
+ if (data.style_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", hint));
}
@@ -389,10 +386,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
List<StringName> names;
theme->get_font_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
-
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.font_override.has(E->get()))
+ if (data.font_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", hint));
}
@@ -401,10 +398,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
List<StringName> names;
theme->get_color_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
-
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.color_override.has(E->get()))
+ if (data.color_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", hint));
}
@@ -413,10 +410,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
List<StringName> names;
theme->get_constant_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
-
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.constant_override.has(E->get()))
+ if (data.constant_override.has(E->get())) {
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", hint));
}
@@ -424,19 +421,16 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
}
Control *Control::get_parent_control() const {
-
return data.parent;
}
void Control::_resize(const Size2 &p_size) {
-
_size_changed();
}
//moved theme configuration here, so controls can set up even if still not inside active scene
void Control::add_child_notify(Node *p_child) {
-
Control *child_c = Object::cast_to<Control>(p_child);
if (child_c && child_c->data.theme.is_null() && (data.theme_owner || data.theme_owner_window)) {
@@ -451,59 +445,52 @@ void Control::add_child_notify(Node *p_child) {
}
void Control::remove_child_notify(Node *p_child) {
-
Control *child_c = Object::cast_to<Control>(p_child);
if (child_c && (child_c->data.theme_owner || child_c->data.theme_owner_window) && child_c->data.theme.is_null()) {
- _propagate_theme_changed(child_c, NULL, NULL);
+ _propagate_theme_changed(child_c, nullptr, nullptr);
}
Window *child_w = Object::cast_to<Window>(p_child);
if (child_w && (child_w->theme_owner || child_w->theme_owner_window) && child_w->theme.is_null()) {
- _propagate_theme_changed(child_w, NULL, NULL);
+ _propagate_theme_changed(child_w, nullptr, nullptr);
}
}
void Control::_update_canvas_item_transform() {
-
Transform2D xform = _get_internal_transform();
xform[2] += get_position();
- VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
+ RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
}
void Control::_notification(int p_notification) {
-
switch (p_notification) {
-
case NOTIFICATION_ENTER_TREE: {
-
} break;
case NOTIFICATION_POST_ENTER_TREE: {
data.minimum_size_valid = false;
_size_changed();
} break;
case NOTIFICATION_EXIT_TREE: {
-
get_viewport()->_gui_remove_control(this);
} break;
case NOTIFICATION_ENTER_CANVAS: {
-
data.parent = Object::cast_to<Control>(get_parent());
Node *parent = this; //meh
- Control *parent_control = NULL;
+ Control *parent_control = nullptr;
bool subwindow = false;
while (parent) {
-
parent = parent->get_parent();
- if (!parent)
+ if (!parent) {
break;
+ }
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
if (ci && ci->is_set_as_toplevel()) {
@@ -516,7 +503,6 @@ void Control::_notification(int p_notification) {
if (parent_control) {
break;
} else if (ci) {
-
} else {
break;
}
@@ -536,7 +522,6 @@ void Control::_notification(int p_notification) {
data.parent_canvas_item = get_parent_item();
if (data.parent_canvas_item) {
-
data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed));
} else {
//connect viewport
@@ -544,11 +529,9 @@ void Control::_notification(int p_notification) {
}
} break;
case NOTIFICATION_EXIT_CANVAS: {
-
if (data.parent_canvas_item) {
-
data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed));
- data.parent_canvas_item = NULL;
+ data.parent_canvas_item = nullptr;
} else if (!is_set_as_toplevel()) {
//disconnect viewport
get_viewport()->disconnect("size_changed", callable_mp(this, &Control::_size_changed));
@@ -556,24 +539,19 @@ void Control::_notification(int p_notification) {
if (data.RI) {
get_viewport()->_gui_remove_root_control(data.RI);
- data.RI = NULL;
+ data.RI = nullptr;
}
- data.parent = NULL;
- data.parent_canvas_item = NULL;
- /*
- if (data.theme_owner && data.theme.is_null()) {
- data.theme_owner=NULL;
- notification(NOTIFICATION_THEME_CHANGED);
- }
- */
+ data.parent = nullptr;
+ data.parent_canvas_item = nullptr;
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
// some parents need to know the order of the childrens to draw (like TabContainer)
// update if necessary
- if (data.parent)
+ if (data.parent) {
data.parent->update();
+ }
update();
if (data.RI) {
@@ -582,47 +560,39 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_RESIZED: {
-
emit_signal(SceneStringNames::get_singleton()->resized);
} break;
case NOTIFICATION_DRAW: {
-
_update_canvas_item_transform();
- VisualServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
- VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
+ RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
+ RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
//emit_signal(SceneStringNames::get_singleton()->draw);
} break;
case NOTIFICATION_MOUSE_ENTER: {
-
emit_signal(SceneStringNames::get_singleton()->mouse_entered);
} break;
case NOTIFICATION_MOUSE_EXIT: {
-
emit_signal(SceneStringNames::get_singleton()->mouse_exited);
} break;
case NOTIFICATION_FOCUS_ENTER: {
-
emit_signal(SceneStringNames::get_singleton()->focus_entered);
update();
} break;
case NOTIFICATION_FOCUS_EXIT: {
-
emit_signal(SceneStringNames::get_singleton()->focus_exited);
update();
} break;
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
update();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
if (!is_visible_in_tree()) {
-
- if (get_viewport() != NULL)
+ if (get_viewport() != nullptr) {
get_viewport()->_gui_hid_control(this);
+ }
//remove key focus
@@ -636,14 +606,13 @@ void Control::_notification(int p_notification) {
}
bool Control::clips_input() const {
-
if (get_script_instance()) {
return get_script_instance()->call(SceneStringNames::get_singleton()->_clips_input);
}
return false;
}
-bool Control::has_point(const Point2 &p_point) const {
+bool Control::has_point(const Point2 &p_point) const {
if (get_script_instance()) {
Variant v = p_point;
const Variant *p = &v;
@@ -661,15 +630,14 @@ bool Control::has_point(const Point2 &p_point) const {
}
void Control::set_drag_forwarding(Control *p_target) {
-
- if (p_target)
+ if (p_target) {
data.drag_owner = p_target->get_instance_id();
- else
+ } else {
data.drag_owner = ObjectID();
+ }
}
Variant Control::get_drag_data(const Point2 &p_point) {
-
if (data.drag_owner.is_valid()) {
Object *obj = ObjectDB::get_instance(data.drag_owner);
if (obj) {
@@ -683,15 +651,15 @@ Variant Control::get_drag_data(const Point2 &p_point) {
const Variant *p = &v;
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return ret;
+ }
}
return Variant();
}
bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
-
if (data.drag_owner.is_valid()) {
Object *obj = ObjectDB::get_instance(data.drag_owner);
if (obj) {
@@ -705,14 +673,15 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const
const Variant *p[2] = { &v, &p_data };
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return ret;
+ }
}
return Variant();
}
-void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
+void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
if (data.drag_owner.is_valid()) {
Object *obj = ObjectDB::get_instance(data.drag_owner);
if (obj) {
@@ -727,13 +696,13 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
const Variant *p[2] = { &v, &p_data };
Callable::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ if (ce.error == Callable::CallError::CALL_OK) {
return;
+ }
}
}
void Control::force_drag(const Variant &p_data, Control *p_control) {
-
ERR_FAIL_COND(!is_inside_tree());
ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
@@ -741,34 +710,30 @@ void Control::force_drag(const Variant &p_data, Control *p_control) {
}
void Control::set_drag_preview(Control *p_control) {
-
ERR_FAIL_COND(!is_inside_tree());
ERR_FAIL_COND(!get_viewport()->gui_is_dragging());
get_viewport()->_gui_set_drag_preview(this, p_control);
}
Size2 Control::get_minimum_size() const {
-
ScriptInstance *si = const_cast<Control *>(this)->get_script_instance();
if (si) {
-
Callable::CallError ce;
- Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, NULL, 0, ce);
- if (ce.error == Callable::CallError::CALL_OK)
+ Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce);
+ if (ce.error == Callable::CallError::CALL_OK) {
return s;
+ }
}
return Size2();
}
template <class T>
bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, T &r_ret, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) {
-
// try with custom themes
Control *theme_owner = p_theme_owner;
Window *theme_owner_window = p_theme_owner_window;
while (theme_owner || theme_owner_window) {
-
StringName class_name = p_type;
while (class_name != StringName()) {
@@ -798,9 +763,8 @@ bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_win
theme_owner = parent_w->theme_owner;
theme_owner_window = parent_w->theme_owner_window;
} else {
-
- theme_owner = NULL;
- theme_owner_window = NULL;
+ theme_owner = nullptr;
+ theme_owner_window = nullptr;
}
}
}
@@ -808,13 +772,11 @@ bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_win
}
bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) {
-
// try with custom themes
Control *theme_owner = p_theme_owner;
Window *theme_owner_window = p_theme_owner_window;
while (theme_owner || theme_owner_window) {
-
StringName class_name = p_type;
while (class_name != StringName()) {
@@ -842,9 +804,8 @@ bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_wind
theme_owner = parent_w->theme_owner;
theme_owner_window = parent_w->theme_owner_window;
} else {
-
- theme_owner = NULL;
- theme_owner_window = NULL;
+ theme_owner = nullptr;
+ theme_owner_window = nullptr;
}
}
}
@@ -852,12 +813,11 @@ bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_wind
}
Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
-
const Ref<Texture2D> *tex = data.icon_override.getptr(p_name);
- if (tex)
+ if (tex) {
return *tex;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -866,7 +826,6 @@ Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringNam
}
Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
Ref<Texture2D> icon;
if (_find_theme_item(p_theme_owner, p_theme_owner_window, icon, &Theme::get_icon, &Theme::has_icon, p_name, p_type)) {
@@ -883,12 +842,11 @@ Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_
}
Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
-
const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
- if (sdr)
+ if (sdr) {
return *sdr;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -897,7 +855,6 @@ Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName
}
Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
Ref<Shader> shader;
if (_find_theme_item(p_theme_owner, p_theme_owner_window, shader, &Theme::get_shader, &Theme::has_shader, p_name, p_type)) {
@@ -914,11 +871,11 @@ Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_w
}
Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
- if (style)
+ if (style) {
return *style;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -927,7 +884,6 @@ Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const String
}
Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
Ref<StyleBox> stylebox;
if (_find_theme_item(p_theme_owner, p_theme_owner_window, stylebox, &Theme::get_stylebox, &Theme::has_stylebox, p_name, p_type)) {
@@ -944,11 +900,11 @@ Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_own
}
Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
const Ref<Font> *font = data.font_override.getptr(p_name);
- if (font)
+ if (font) {
return *font;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -957,7 +913,6 @@ Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_
}
Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
Ref<Font> font;
if (_find_theme_item(p_theme_owner, p_theme_owner_window, font, &Theme::get_font, &Theme::has_font, p_name, p_type)) {
@@ -974,11 +929,11 @@ Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_windo
}
Color Control::get_theme_color(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
const Color *color = data.color_override.getptr(p_name);
- if (color)
+ if (color) {
return *color;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -987,7 +942,6 @@ Color Control::get_theme_color(const StringName &p_name, const StringName &p_typ
}
Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
Color color;
if (_find_theme_item(p_theme_owner, p_theme_owner_window, color, &Theme::get_color, &Theme::has_color, p_name, p_type)) {
@@ -1003,11 +957,11 @@ Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window,
}
int Control::get_theme_constant(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
const int *constant = data.constant_override.getptr(p_name);
- if (constant)
+ if (constant) {
return *constant;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1016,7 +970,6 @@ int Control::get_theme_constant(const StringName &p_name, const StringName &p_ty
}
int Control::get_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
int constant;
if (_find_theme_item(p_theme_owner, p_theme_owner_window, constant, &Theme::get_constant, &Theme::has_constant, p_name, p_type)) {
@@ -1032,46 +985,40 @@ int Control::get_constants(Control *p_theme_owner, Window *p_theme_owner_window,
}
bool Control::has_theme_icon_override(const StringName &p_name) const {
-
const Ref<Texture2D> *tex = data.icon_override.getptr(p_name);
- return tex != NULL;
+ return tex != nullptr;
}
bool Control::has_theme_shader_override(const StringName &p_name) const {
-
const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
- return sdr != NULL;
+ return sdr != nullptr;
}
bool Control::has_theme_stylebox_override(const StringName &p_name) const {
-
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
- return style != NULL;
+ return style != nullptr;
}
bool Control::has_theme_font_override(const StringName &p_name) const {
-
const Ref<Font> *font = data.font_override.getptr(p_name);
- return font != NULL;
+ return font != nullptr;
}
bool Control::has_theme_color_override(const StringName &p_name) const {
-
const Color *color = data.color_override.getptr(p_name);
- return color != NULL;
+ return color != nullptr;
}
bool Control::has_theme_constant_override(const StringName &p_name) const {
-
const int *constant = data.constant_override.getptr(p_name);
- return constant != NULL;
+ return constant != nullptr;
}
bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_icon_override(p_name))
+ if (has_theme_icon_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1080,7 +1027,6 @@ bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type)
}
bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_icon, p_name, p_type)) {
return true;
}
@@ -1094,18 +1040,18 @@ bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, co
}
bool Control::has_theme_shader(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_shader_override(p_name))
+ if (has_theme_shader_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
return has_shaders(data.theme_owner, data.theme_owner_window, p_name, type);
}
-bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
+bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_shader, p_name, p_type)) {
return true;
}
@@ -1119,10 +1065,10 @@ bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window,
}
bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_stylebox_override(p_name))
+ if (has_theme_stylebox_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1131,7 +1077,6 @@ bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_t
}
bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_stylebox, p_name, p_type)) {
return true;
}
@@ -1145,18 +1090,18 @@ bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window
}
bool Control::has_theme_font(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_font_override(p_name))
+ if (has_theme_font_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
return has_fonts(data.theme_owner, data.theme_owner_window, p_name, type);
}
-bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
+bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_font, p_name, p_type)) {
return true;
}
@@ -1170,18 +1115,18 @@ bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, co
}
bool Control::has_theme_color(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_color_override(p_name))
+ if (has_theme_color_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
return has_colors(data.theme_owner, data.theme_owner_window, p_name, type);
}
-bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
+bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_color, p_name, p_type)) {
return true;
}
@@ -1195,10 +1140,10 @@ bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, c
}
bool Control::has_theme_constant(const StringName &p_name, const StringName &p_type) const {
-
if (p_type == StringName() || p_type == get_class_name()) {
- if (has_theme_constant_override(p_name))
+ if (has_theme_constant_override(p_name)) {
return true;
+ }
}
StringName type = p_type ? p_type : get_class_name();
@@ -1207,7 +1152,6 @@ bool Control::has_theme_constant(const StringName &p_name, const StringName &p_t
}
bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) {
-
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_constant, p_name, p_type)) {
return true;
}
@@ -1221,8 +1165,9 @@ bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window
}
Rect2 Control::get_parent_anchorable_rect() const {
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return Rect2();
+ }
Rect2 parent_rect;
if (data.parent_canvas_item) {
@@ -1235,18 +1180,15 @@ Rect2 Control::get_parent_anchorable_rect() const {
}
Size2 Control::get_parent_area_size() const {
-
return get_parent_anchorable_rect().size;
}
void Control::_size_changed() {
-
Rect2 parent_rect = get_parent_anchorable_rect();
float margin_pos[4];
for (int i = 0; i < 4; i++) {
-
float area = parent_rect.size[i & 1];
margin_pos[i] = data.margin[i] + (data.anchor[i] * area);
}
@@ -1299,7 +1241,6 @@ void Control::_size_changed() {
}
void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bool p_push_opposite_anchor) {
-
ERR_FAIL_INDEX((int)p_margin, 4);
Rect2 parent_rect = get_parent_anchorable_rect();
@@ -1340,13 +1281,11 @@ void Control::_set_anchor(Margin p_margin, float p_anchor) {
}
void Control::set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor) {
-
set_anchor(p_margin, p_anchor, false, p_push_opposite_anchor);
set_margin(p_margin, p_pos);
}
void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margins) {
-
ERR_FAIL_INDEX((int)p_preset, 16);
//Left
@@ -1463,7 +1402,6 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margins) {
}
void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
-
ERR_FAIL_INDEX((int)p_preset, 16);
ERR_FAIL_INDEX((int)p_resize_mode, 4);
@@ -1600,14 +1538,12 @@ void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPreset
}
float Control::get_anchor(Margin p_margin) const {
-
ERR_FAIL_INDEX_V(int(p_margin), 4, 0.0);
return data.anchor[p_margin];
}
void Control::_change_notify_margins() {
-
// this avoids sending the whole object data again on a change
_change_notify("margin_left");
_change_notify("margin_top");
@@ -1618,7 +1554,6 @@ void Control::_change_notify_margins() {
}
void Control::set_margin(Margin p_margin, float p_value) {
-
ERR_FAIL_INDEX((int)p_margin, 4);
data.margin[p_margin] = p_value;
@@ -1626,37 +1561,32 @@ void Control::set_margin(Margin p_margin, float p_value) {
}
void Control::set_begin(const Size2 &p_point) {
-
data.margin[0] = p_point.x;
data.margin[1] = p_point.y;
_size_changed();
}
void Control::set_end(const Size2 &p_point) {
-
data.margin[2] = p_point.x;
data.margin[3] = p_point.y;
_size_changed();
}
float Control::get_margin(Margin p_margin) const {
-
ERR_FAIL_INDEX_V((int)p_margin, 4, 0);
return data.margin[p_margin];
}
Size2 Control::get_begin() const {
-
return Size2(data.margin[0], data.margin[1]);
}
-Size2 Control::get_end() const {
+Size2 Control::get_end() const {
return Size2(data.margin[2], data.margin[3]);
}
Point2 Control::get_global_position() const {
-
return get_global_transform().get_origin();
}
@@ -1676,11 +1606,9 @@ void Control::_set_global_position(const Point2 &p_point) {
}
void Control::set_global_position(const Point2 &p_point, bool p_keep_margins) {
-
Transform2D inv;
if (data.parent_canvas_item) {
-
inv = data.parent_canvas_item->get_global_transform().affine_inverse();
}
@@ -1688,7 +1616,6 @@ void Control::set_global_position(const Point2 &p_point, bool p_keep_margins) {
}
void Control::_compute_anchors(Rect2 p_rect, const float p_margins[4], float (&r_anchors)[4]) {
-
Size2 parent_rect_size = get_parent_anchorable_rect().size;
ERR_FAIL_COND(parent_rect_size.x == 0.0);
ERR_FAIL_COND(parent_rect_size.y == 0.0);
@@ -1700,7 +1627,6 @@ void Control::_compute_anchors(Rect2 p_rect, const float p_margins[4], float (&r
}
void Control::_compute_margins(Rect2 p_rect, const float p_anchors[4], float (&r_margins)[4]) {
-
Size2 parent_rect_size = get_parent_anchorable_rect().size;
r_margins[0] = p_rect.position.x - (p_anchors[0] * parent_rect_size.x);
r_margins[1] = p_rect.position.y - (p_anchors[1] * parent_rect_size.y);
@@ -1730,13 +1656,14 @@ void Control::_set_size(const Size2 &p_size) {
}
void Control::set_size(const Size2 &p_size, bool p_keep_margins) {
-
Size2 new_size = p_size;
Size2 min = get_combined_minimum_size();
- if (new_size.x < min.x)
+ if (new_size.x < min.x) {
new_size.x = min.x;
- if (new_size.y < min.y)
+ }
+ if (new_size.y < min.y) {
new_size.y = min.y;
+ }
if (p_keep_margins) {
_compute_anchors(Rect2(data.pos_cache, new_size), data.margin, data.anchor);
@@ -1751,22 +1678,18 @@ void Control::set_size(const Size2 &p_size, bool p_keep_margins) {
}
Size2 Control::get_position() const {
-
return data.pos_cache;
}
Size2 Control::get_size() const {
-
return data.size_cache;
}
Rect2 Control::get_global_rect() const {
-
return Rect2(get_global_position(), get_size());
}
Rect2 Control::get_screen_rect() const {
-
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
Rect2 r(get_global_position(), get_size());
@@ -1787,17 +1710,14 @@ Rect2 Control::get_window_rect() const {
}
Rect2 Control::get_rect() const {
-
return Rect2(get_position(), get_size());
}
Rect2 Control::get_anchorable_rect() const {
-
return Rect2(Point2(), get_size());
}
void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) {
-
if (data.icon_override.has(p_name)) {
data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
@@ -1815,7 +1735,6 @@ void Control::add_theme_icon_override(const StringName &p_name, const Ref<Textur
}
void Control::add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) {
-
if (data.shader_override.has(p_name)) {
data.shader_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
@@ -1831,8 +1750,8 @@ void Control::add_theme_shader_override(const StringName &p_name, const Ref<Shad
}
notification(NOTIFICATION_THEME_CHANGED);
}
-void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
+void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
if (data.style_override.has(p_name)) {
data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
@@ -1850,7 +1769,6 @@ void Control::add_theme_style_override(const StringName &p_name, const Ref<Style
}
void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) {
-
if (data.font_override.has(p_name)) {
data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
@@ -1866,46 +1784,45 @@ void Control::add_theme_font_override(const StringName &p_name, const Ref<Font>
}
notification(NOTIFICATION_THEME_CHANGED);
}
-void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) {
+void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) {
data.color_override[p_name] = p_color;
notification(NOTIFICATION_THEME_CHANGED);
}
-void Control::add_theme_constant_override(const StringName &p_name, int p_constant) {
+void Control::add_theme_constant_override(const StringName &p_name, int p_constant) {
data.constant_override[p_name] = p_constant;
notification(NOTIFICATION_THEME_CHANGED);
}
void Control::set_focus_mode(FocusMode p_focus_mode) {
-
ERR_FAIL_INDEX((int)p_focus_mode, 3);
- if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus())
+ if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) {
release_focus();
+ }
data.focus_mode = p_focus_mode;
}
static Control *_next_control(Control *p_from) {
-
- if (p_from->is_set_as_toplevel())
- return NULL; // can't go above
+ if (p_from->is_set_as_toplevel()) {
+ return nullptr; // can't go above
+ }
Control *parent = Object::cast_to<Control>(p_from->get_parent());
if (!parent) {
-
- return NULL;
+ return nullptr;
}
- int next = p_from->get_position_in_parent();
- ERR_FAIL_INDEX_V(next, parent->get_child_count(), NULL);
+ int next = p_from->get_index();
+ ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr);
for (int i = (next + 1); i < parent->get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(parent->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
+ }
return c;
}
@@ -1915,11 +1832,9 @@ static Control *_next_control(Control *p_from) {
}
Control *Control::find_next_valid_focus() const {
-
Control *from = const_cast<Control *>(this);
while (true) {
-
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_next.is_empty()) {
@@ -1927,20 +1842,20 @@ Control *Control::find_next_valid_focus() const {
Control *c;
if (n) {
c = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!c, NULL, "Next focus node is not a control: " + n->get_name() + ".");
+ ERR_FAIL_COND_V_MSG(!c, nullptr, "Next focus node is not a control: " + n->get_name() + ".");
} else {
- return NULL;
+ return nullptr;
}
- if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
+ }
}
// find next child
- Control *next_child = NULL;
+ Control *next_child = nullptr;
for (int i = 0; i < from->get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(from->get_child(i));
if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
@@ -1951,56 +1866,56 @@ Control *Control::find_next_valid_focus() const {
}
if (!next_child) {
-
next_child = _next_control(from);
if (!next_child) { //nothing else.. go up and find either window or subwindow
next_child = const_cast<Control *>(this);
while (next_child && !next_child->is_set_as_toplevel()) {
-
next_child = cast_to<Control>(next_child->get_parent());
}
if (!next_child) {
-
next_child = const_cast<Control *>(this);
while (next_child) {
-
- if (next_child->data.RI)
+ if (next_child->data.RI) {
break;
+ }
next_child = next_child->get_parent_control();
}
}
}
}
- if (next_child == this) // no next control->
- return (get_focus_mode() == FOCUS_ALL) ? next_child : NULL;
+ if (next_child == this) { // no next control->
+ return (get_focus_mode() == FOCUS_ALL) ? next_child : nullptr;
+ }
if (next_child) {
- if (next_child->get_focus_mode() == FOCUS_ALL)
+ if (next_child->get_focus_mode() == FOCUS_ALL) {
return next_child;
+ }
from = next_child;
- } else
+ } else {
break;
+ }
}
- return NULL;
+ return nullptr;
}
static Control *_prev_control(Control *p_from) {
-
- Control *child = NULL;
+ Control *child = nullptr;
for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
-
Control *c = Object::cast_to<Control>(p_from->get_child(i));
- if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
+ if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
+ }
child = c;
break;
}
- if (!child)
+ if (!child) {
return p_from;
+ }
//no prev in parent, try the same in parent
return _prev_control(child);
@@ -2010,7 +1925,6 @@ Control *Control::find_prev_valid_focus() const {
Control *from = const_cast<Control *>(this);
while (true) {
-
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_prev.is_empty()) {
@@ -2018,28 +1932,26 @@ Control *Control::find_prev_valid_focus() const {
Control *c;
if (n) {
c = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!c, NULL, "Previous focus node is not a control: " + n->get_name() + ".");
+ ERR_FAIL_COND_V_MSG(!c, nullptr, "Previous focus node is not a control: " + n->get_name() + ".");
} else {
- return NULL;
+ return nullptr;
}
- if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE)
+ if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
+ }
}
// find prev child
- Control *prev_child = NULL;
+ Control *prev_child = nullptr;
if (from->is_set_as_toplevel() || !Object::cast_to<Control>(from->get_parent())) {
-
//find last of the children
prev_child = _prev_control(from);
} else {
-
- for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) {
-
+ for (int i = (from->get_index() - 1); i >= 0; i--) {
Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i));
if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
@@ -2051,37 +1963,35 @@ Control *Control::find_prev_valid_focus() const {
}
if (!prev_child) {
-
prev_child = Object::cast_to<Control>(from->get_parent());
} else {
-
prev_child = _prev_control(prev_child);
}
}
- if (prev_child == this) // no prev control->
- return (get_focus_mode() == FOCUS_ALL) ? prev_child : NULL;
+ if (prev_child == this) { // no prev control->
+ return (get_focus_mode() == FOCUS_ALL) ? prev_child : nullptr;
+ }
- if (prev_child->get_focus_mode() == FOCUS_ALL)
+ if (prev_child->get_focus_mode() == FOCUS_ALL) {
return prev_child;
+ }
from = prev_child;
}
- return NULL;
+ return nullptr;
}
Control::FocusMode Control::get_focus_mode() const {
-
return data.focus_mode;
}
-bool Control::has_focus() const {
+bool Control::has_focus() const {
return is_inside_tree() && get_viewport()->_gui_control_has_focus(this);
}
void Control::grab_focus() {
-
ERR_FAIL_COND(!is_inside_tree());
if (data.focus_mode == FOCUS_NONE) {
@@ -2093,40 +2003,38 @@ void Control::grab_focus() {
}
void Control::release_focus() {
-
ERR_FAIL_COND(!is_inside_tree());
- if (!has_focus())
+ if (!has_focus()) {
return;
+ }
get_viewport()->_gui_remove_focus();
update();
}
bool Control::is_toplevel_control() const {
-
return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel());
}
void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) {
-
Control *c = Object::cast_to<Control>(p_at);
- if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated
+ if (c && c != p_owner && c->data.theme.is_valid()) { // has a theme, this can't be propagated
return;
+ }
Window *w = c == nullptr ? Object::cast_to<Window>(p_at) : nullptr;
- if (w && w != p_owner_window && w->theme.is_valid()) // has a theme, this can't be propagated
+ if (w && w != p_owner_window && w->theme.is_valid()) { // has a theme, this can't be propagated
return;
+ }
for (int i = 0; i < p_at->get_child_count(); i++) {
-
CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i));
if (child) {
_propagate_theme_changed(child, p_owner, p_owner_window, p_assign);
} else {
-
Window *window = Object::cast_to<Window>(p_at->get_child(i));
if (window) {
_propagate_theme_changed(window, p_owner, p_owner_window, p_assign);
@@ -2135,7 +2043,6 @@ void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_o
}
if (c) {
-
if (p_assign) {
c->data.theme_owner = p_owner;
c->data.theme_owner_window = p_owner_window;
@@ -2145,7 +2052,6 @@ void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_o
}
if (w) {
-
if (p_assign) {
w->theme_owner = p_owner;
w->theme_owner_window = p_owner_window;
@@ -2156,14 +2062,13 @@ void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_o
}
void Control::_theme_changed() {
-
_propagate_theme_changed(this, this, nullptr, false);
}
void Control::set_theme(const Ref<Theme> &p_theme) {
-
- if (data.theme == p_theme)
+ if (data.theme == p_theme) {
return;
+ }
if (data.theme.is_valid()) {
data.theme->disconnect("changed", callable_mp(this, &Control::_theme_changed));
@@ -2171,12 +2076,10 @@ void Control::set_theme(const Ref<Theme> &p_theme) {
data.theme = p_theme;
if (!p_theme.is_null()) {
-
data.theme_owner = this;
data.theme_owner_window = nullptr;
_propagate_theme_changed(this, this, nullptr);
} else {
-
Control *parent_c = Object::cast_to<Control>(get_parent());
if (parent_c && (parent_c->data.theme_owner || parent_c->data.theme_owner_window)) {
@@ -2197,125 +2100,115 @@ void Control::set_theme(const Ref<Theme> &p_theme) {
}
void Control::accept_event() {
-
- if (is_inside_tree())
+ if (is_inside_tree()) {
get_viewport()->_gui_accept_event();
+ }
}
Ref<Theme> Control::get_theme() const {
-
return data.theme;
}
void Control::set_tooltip(const String &p_tooltip) {
-
data.tooltip = p_tooltip;
update_configuration_warning();
}
String Control::get_tooltip(const Point2 &p_pos) const {
-
return data.tooltip;
}
+
Control *Control::make_custom_tooltip(const String &p_text) const {
if (get_script_instance()) {
return const_cast<Control *>(this)->call("_make_custom_tooltip", p_text);
}
- return NULL;
+ return nullptr;
}
void Control::set_default_cursor_shape(CursorShape p_shape) {
-
ERR_FAIL_INDEX(int(p_shape), CURSOR_MAX);
data.default_cursor = p_shape;
}
Control::CursorShape Control::get_default_cursor_shape() const {
-
return data.default_cursor;
}
-Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
+Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
return data.default_cursor;
}
Transform2D Control::get_transform() const {
-
Transform2D xform = _get_internal_transform();
xform[2] += get_position();
return xform;
}
String Control::_get_tooltip() const {
-
return data.tooltip;
}
void Control::set_focus_neighbour(Margin p_margin, const NodePath &p_neighbour) {
-
ERR_FAIL_INDEX((int)p_margin, 4);
data.focus_neighbour[p_margin] = p_neighbour;
}
NodePath Control::get_focus_neighbour(Margin p_margin) const {
-
ERR_FAIL_INDEX_V((int)p_margin, 4, NodePath());
return data.focus_neighbour[p_margin];
}
void Control::set_focus_next(const NodePath &p_next) {
-
data.focus_next = p_next;
}
NodePath Control::get_focus_next() const {
-
return data.focus_next;
}
void Control::set_focus_previous(const NodePath &p_prev) {
-
data.focus_prev = p_prev;
}
NodePath Control::get_focus_previous() const {
-
return data.focus_prev;
}
#define MAX_NEIGHBOUR_SEARCH_COUNT 512
Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
+ ERR_FAIL_INDEX_V((int)p_margin, 4, nullptr);
- ERR_FAIL_INDEX_V((int)p_margin, 4, NULL);
-
- if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT)
- return NULL;
+ if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT) {
+ return nullptr;
+ }
if (!data.focus_neighbour[p_margin].is_empty()) {
-
- Control *c = NULL;
+ Control *c = nullptr;
Node *n = get_node(data.focus_neighbour[p_margin]);
if (n) {
c = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!c, NULL, "Neighbor focus node is not a control: " + n->get_name() + ".");
+ ERR_FAIL_COND_V_MSG(!c, nullptr, "Neighbor focus node is not a control: " + n->get_name() + ".");
} else {
- return NULL;
+ return nullptr;
}
bool valid = true;
- if (!c->is_visible())
+ if (!c->is_visible()) {
valid = false;
- if (c->get_focus_mode() == FOCUS_NONE)
+ }
+ if (c->get_focus_mode() == FOCUS_NONE) {
valid = false;
- if (valid)
+ }
+ if (valid) {
return c;
+ }
c = c->_get_focus_neighbour(p_margin, p_count + 1);
return c;
}
float dist = 1e7;
- Control *result = NULL;
+ Control *result = nullptr;
Point2 points[4];
@@ -2338,26 +2231,27 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
float maxd = -1e7;
for (int i = 0; i < 4; i++) {
-
float d = vdir.dot(points[i]);
- if (d > maxd)
+ if (d > maxd) {
maxd = d;
+ }
}
Node *base = this;
while (base) {
-
Control *c = Object::cast_to<Control>(base);
if (c) {
- if (c->data.RI)
+ if (c->data.RI) {
break;
+ }
}
base = base->get_parent();
}
- if (!base)
- return NULL;
+ if (!base) {
+ return nullptr;
+ }
_window_find_focus_neighbour(vdir, base, points, maxd, dist, &result);
@@ -2365,14 +2259,13 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
}
void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, float p_min, float &r_closest_dist, Control **r_closest) {
-
- if (Object::cast_to<Viewport>(p_at))
+ if (Object::cast_to<Viewport>(p_at)) {
return; //bye
+ }
Control *c = Object::cast_to<Control>(p_at);
if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) {
-
Point2 points[4];
Transform2D xform = c->get_global_transform();
@@ -2385,27 +2278,24 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
float min = 1e7;
for (int i = 0; i < 4; i++) {
-
float d = p_dir.dot(points[i]);
- if (d < min)
+ if (d < min) {
min = d;
+ }
}
if (min > (p_min - CMP_EPSILON)) {
-
for (int i = 0; i < 4; i++) {
-
Vector2 la = p_points[i];
Vector2 lb = p_points[(i + 1) % 4];
for (int j = 0; j < 4; j++) {
-
Vector2 fa = points[j];
Vector2 fb = points[(j + 1) % 4];
Vector2 pa, pb;
- float d = Geometry::get_closest_points_between_segments(la, lb, fa, fb, pa, pb);
- //float d = Geometry::get_closest_distance_between_segments(Vector3(la.x,la.y,0),Vector3(lb.x,lb.y,0),Vector3(fa.x,fa.y,0),Vector3(fb.x,fb.y,0));
+ float d = Geometry2D::get_closest_points_between_segments(la, lb, fa, fb, pa, pb);
+ //float d = Geometry2D::get_closest_distance_between_segments(Vector3(la.x,la.y,0),Vector3(lb.x,lb.y,0),Vector3(fa.x,fa.y,0),Vector3(fb.x,fb.y,0));
if (d < r_closest_dist) {
r_closest_dist = d;
*r_closest = c;
@@ -2416,19 +2306,19 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
}
for (int i = 0; i < p_at->get_child_count(); i++) {
-
Node *child = p_at->get_child(i);
Control *childc = Object::cast_to<Control>(child);
- if (childc && childc->data.RI)
+ if (childc && childc->data.RI) {
continue; //subwindow, ignore
+ }
_window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
}
}
void Control::set_h_size_flags(int p_flags) {
-
- if (data.h_size_flags == p_flags)
+ if (data.h_size_flags == p_flags) {
return;
+ }
data.h_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
@@ -2436,47 +2326,47 @@ void Control::set_h_size_flags(int p_flags) {
int Control::get_h_size_flags() const {
return data.h_size_flags;
}
-void Control::set_v_size_flags(int p_flags) {
- if (data.v_size_flags == p_flags)
+void Control::set_v_size_flags(int p_flags) {
+ if (data.v_size_flags == p_flags) {
return;
+ }
data.v_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
void Control::set_stretch_ratio(float p_ratio) {
-
- if (data.expand == p_ratio)
+ if (data.expand == p_ratio) {
return;
+ }
data.expand = p_ratio;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
float Control::get_stretch_ratio() const {
-
return data.expand;
}
void Control::grab_click_focus() {
-
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->_gui_grab_click_focus(this);
}
void Control::minimum_size_changed() {
-
- if (!is_inside_tree() || data.block_minimum_size_adjust)
+ if (!is_inside_tree() || data.block_minimum_size_adjust) {
return;
+ }
Control *invalidate = this;
//invalidate cache upwards
while (invalidate && invalidate->data.minimum_size_valid) {
invalidate->data.minimum_size_valid = false;
- if (invalidate->is_set_as_toplevel())
+ if (invalidate->is_set_as_toplevel()) {
break; // do not go further up
+ }
if (!invalidate->data.parent && get_parent()) {
Window *parent_window = Object::cast_to<Window>(get_parent());
if (parent_window && parent_window->is_wrapping_controls()) {
@@ -2486,11 +2376,13 @@ void Control::minimum_size_changed() {
invalidate = invalidate->data.parent;
}
- if (!is_visible_in_tree())
+ if (!is_visible_in_tree()) {
return;
+ }
- if (data.updating_last_minimum_size)
+ if (data.updating_last_minimum_size) {
return;
+ }
data.updating_last_minimum_size = true;
@@ -2502,20 +2394,17 @@ int Control::get_v_size_flags() const {
}
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 {
-
return data.mouse_filter;
}
Control *Control::get_focus_owner() const {
-
- ERR_FAIL_COND_V(!is_inside_tree(), NULL);
+ ERR_FAIL_COND_V(!is_inside_tree(), nullptr);
return get_viewport()->_gui_get_focus_owner();
}
@@ -2539,7 +2428,6 @@ bool Control::is_text_field() const {
}
void Control::set_rotation(float p_radians) {
-
data.rotation = p_radians;
update();
_notify_transform();
@@ -2547,7 +2435,6 @@ void Control::set_rotation(float p_radians) {
}
float Control::get_rotation() const {
-
return data.rotation;
}
@@ -2560,14 +2447,12 @@ float Control::get_rotation_degrees() const {
}
void Control::_override_changed() {
-
notification(NOTIFICATION_THEME_CHANGED);
emit_signal(SceneStringNames::get_singleton()->theme_changed);
minimum_size_changed(); // overrides are likely to affect minimum size
}
void Control::set_pivot_offset(const Vector2 &p_pivot) {
-
data.pivot_offset = p_pivot;
update();
_notify_transform();
@@ -2575,39 +2460,38 @@ void Control::set_pivot_offset(const Vector2 &p_pivot) {
}
Vector2 Control::get_pivot_offset() const {
-
return data.pivot_offset;
}
void Control::set_scale(const Vector2 &p_scale) {
-
data.scale = p_scale;
// Avoid having 0 scale values, can lead to errors in physics and rendering.
- if (data.scale.x == 0)
+ if (data.scale.x == 0) {
data.scale.x = CMP_EPSILON;
- if (data.scale.y == 0)
+ }
+ if (data.scale.y == 0) {
data.scale.y = CMP_EPSILON;
+ }
update();
_notify_transform();
}
-Vector2 Control::get_scale() const {
+Vector2 Control::get_scale() const {
return data.scale;
}
Control *Control::get_root_parent_control() const {
-
const CanvasItem *ci = this;
const Control *root = this;
while (ci) {
-
const Control *c = Object::cast_to<Control>(ci);
if (c) {
root = c;
- if (c->data.RI || c->is_toplevel_control())
+ if (c->data.RI || c->is_toplevel_control()) {
break;
+ }
}
ci = ci->get_parent_item();
@@ -2621,23 +2505,19 @@ void Control::set_block_minimum_size_adjust(bool p_block) {
}
bool Control::is_minimum_size_adjust_blocked() const {
-
return data.block_minimum_size_adjust;
}
void Control::set_disable_visibility_clip(bool p_ignore) {
-
data.disable_visibility_clip = p_ignore;
update();
}
bool Control::is_visibility_clip_disabled() const {
-
return data.disable_visibility_clip;
}
void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
-
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
#else
@@ -2680,18 +2560,15 @@ String Control::get_configuration_warning() const {
}
void Control::set_clip_contents(bool p_clip) {
-
data.clip_contents = p_clip;
update();
}
bool Control::is_clipping_contents() {
-
return data.clip_contents;
}
void Control::set_h_grow_direction(GrowDirection p_direction) {
-
ERR_FAIL_INDEX((int)p_direction, 3);
data.h_grow = p_direction;
@@ -2699,24 +2576,21 @@ void Control::set_h_grow_direction(GrowDirection p_direction) {
}
Control::GrowDirection Control::get_h_grow_direction() const {
-
return data.h_grow;
}
void Control::set_v_grow_direction(GrowDirection p_direction) {
-
ERR_FAIL_INDEX((int)p_direction, 3);
data.v_grow = p_direction;
_size_changed();
}
-Control::GrowDirection Control::get_v_grow_direction() const {
+Control::GrowDirection Control::get_v_grow_direction() const {
return data.v_grow;
}
void Control::_bind_methods() {
-
//ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
ClassDB::bind_method(D_METHOD("_update_minimum_size"), &Control::_update_minimum_size);
@@ -2902,7 +2776,7 @@ void Control::_bind_methods() {
ADD_GROUP("Size Flags", "size_flags_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_GROUP("", "");
@@ -2989,21 +2863,21 @@ void Control::_bind_methods() {
BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point")));
}
-Control::Control() {
- data.parent = NULL;
+Control::Control() {
+ data.parent = nullptr;
data.mouse_filter = MOUSE_FILTER_STOP;
- data.RI = NULL;
- data.theme_owner = NULL;
- data.theme_owner_window = NULL;
+ data.RI = nullptr;
+ data.theme_owner = nullptr;
+ data.theme_owner_window = nullptr;
data.default_cursor = CURSOR_ARROW;
data.h_size_flags = SIZE_FILL;
data.v_size_flags = SIZE_FILL;
data.expand = 1;
data.rotation = 0;
- data.parent_canvas_item = NULL;
+ data.parent_canvas_item = nullptr;
data.scale = Vector2(1, 1);
data.block_minimum_size_adjust = false;
diff --git a/scene/gui/control.h b/scene/gui/control.h
index c52e80fa70..10d6ad168f 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -33,8 +33,8 @@
#include "core/math/transform_2d.h"
#include "core/rid.h"
-#include "scene/2d/canvas_item.h"
#include "scene/gui/shortcut.h"
+#include "scene/main/canvas_item.h"
#include "scene/main/node.h"
#include "scene/main/timer.h"
#include "scene/resources/theme.h"
@@ -44,7 +44,6 @@ class Label;
class Panel;
class Control : public CanvasItem {
-
GDCLASS(Control, CanvasItem);
OBJ_CATEGORY("GUI Nodes");
@@ -132,17 +131,16 @@ public:
private:
struct CComparator {
-
bool operator()(const Control *p_a, const Control *p_b) const {
- if (p_a->get_canvas_layer() == p_b->get_canvas_layer())
+ if (p_a->get_canvas_layer() == p_b->get_canvas_layer()) {
return p_b->is_greater_than(p_a);
+ }
return p_a->get_canvas_layer() < p_b->get_canvas_layer();
}
};
struct Data {
-
Point2 pos_cache;
Size2 size_cache;
Size2 minimum_size_cache;
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 2e87a92969..c6897fc684 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -55,11 +55,9 @@ void AcceptDialog::_parent_focused() {
}
void AcceptDialog::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
-
get_ok()->grab_focus();
_update_child_rects();
parent_visible = get_parent_visible_window();
@@ -98,20 +96,18 @@ void AcceptDialog::_notification(int p_what) {
}
void AcceptDialog::_text_entered(const String &p_text) {
-
_ok_pressed();
}
void AcceptDialog::_ok_pressed() {
-
- if (hide_on_ok)
+ if (hide_on_ok) {
set_visible(false);
+ }
ok_pressed();
emit_signal("confirmed");
}
void AcceptDialog::_cancel_pressed() {
-
Window *parent_window = parent_visible;
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
@@ -130,11 +126,10 @@ void AcceptDialog::_cancel_pressed() {
}
String AcceptDialog::get_text() const {
-
return label->get_text();
}
-void AcceptDialog::set_text(String p_text) {
+void AcceptDialog::set_text(String p_text) {
label->set_text(p_text);
child_controls_changed();
if (is_visible()) {
@@ -143,33 +138,30 @@ void AcceptDialog::set_text(String p_text) {
}
void AcceptDialog::set_hide_on_ok(bool p_hide) {
-
hide_on_ok = p_hide;
}
-bool AcceptDialog::get_hide_on_ok() const {
+bool AcceptDialog::get_hide_on_ok() const {
return hide_on_ok;
}
void AcceptDialog::set_autowrap(bool p_autowrap) {
-
label->set_autowrap(p_autowrap);
}
-bool AcceptDialog::has_autowrap() {
+bool AcceptDialog::has_autowrap() {
return label->has_autowrap();
}
void AcceptDialog::register_text_enter(Node *p_line_edit) {
-
ERR_FAIL_NULL(p_line_edit);
LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit);
- if (line_edit)
+ if (line_edit) {
line_edit->connect("text_entered", callable_mp(this, &AcceptDialog::_text_entered));
+ }
}
void AcceptDialog::_update_child_rects() {
-
Size2 label_size = label->get_minimum_size();
if (label->get_text().empty()) {
label_size.height = 0;
@@ -183,11 +175,13 @@ void AcceptDialog::_update_child_rects() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c == hbc || c == label || c == bg || c->is_set_as_toplevel())
+ if (c == hbc || c == label || c == bg || c->is_set_as_toplevel()) {
continue;
+ }
c->set_position(cpos);
c->set_size(csize);
@@ -204,17 +198,18 @@ void AcceptDialog::_update_child_rects() {
}
Size2 AcceptDialog::_get_contents_minimum_size() const {
-
int margin = hbc->get_theme_constant("margin", "Dialogs");
Size2 minsize = label->get_combined_minimum_size();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c == hbc || c == label || c->is_set_as_toplevel())
+ if (c == hbc || c == label || c->is_set_as_toplevel()) {
continue;
+ }
Size2 cminsize = c->get_combined_minimum_size();
minsize.x = MAX(cminsize.x, minsize.x);
@@ -233,20 +228,17 @@ Size2 AcceptDialog::_get_contents_minimum_size() const {
}
void AcceptDialog::_custom_action(const String &p_action) {
-
emit_signal("custom_action", p_action);
custom_action(p_action);
}
Button *AcceptDialog::add_button(const String &p_text, bool p_right, const String &p_action) {
-
Button *button = memnew(Button);
button->set_text(p_text);
if (p_right) {
hbc->add_child(button);
hbc->add_spacer();
} else {
-
hbc->add_child(button);
hbc->move_child(button, 0);
hbc->add_spacer(true);
@@ -260,17 +252,16 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin
}
Button *AcceptDialog::add_cancel(const String &p_cancel) {
-
String c = p_cancel;
- if (p_cancel == "")
+ if (p_cancel == "") {
c = RTR("Cancel");
+ }
Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c);
b->connect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed));
return b;
}
void AcceptDialog::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_ok"), &AcceptDialog::get_ok);
ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label);
ClassDB::bind_method(D_METHOD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok);
@@ -295,12 +286,10 @@ void AcceptDialog::_bind_methods() {
bool AcceptDialog::swap_ok_cancel = false;
void AcceptDialog::set_swap_ok_cancel(bool p_swap) {
-
swap_ok_cancel = p_swap;
}
AcceptDialog::AcceptDialog() {
-
parent_visible = nullptr;
set_wrap_controls(true);
@@ -322,7 +311,6 @@ AcceptDialog::AcceptDialog() {
label->set_end(Point2(-margin, -button_margin - 10));
add_child(label);
- hbc = memnew(HBoxContainer);
add_child(hbc);
hbc->add_spacer();
@@ -345,17 +333,14 @@ AcceptDialog::~AcceptDialog() {
// ConfirmationDialog
void ConfirmationDialog::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_cancel"), &ConfirmationDialog::get_cancel);
}
Button *ConfirmationDialog::get_cancel() {
-
return cancel;
}
ConfirmationDialog::ConfirmationDialog() {
-
set_title(RTR("Please Confirm..."));
#ifdef TOOLS_ENABLED
set_min_size(Size2(200, 70) * EDSCALE);
diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h
index b68b4297d7..5d7b6272bf 100644
--- a/scene/gui/dialogs.h
+++ b/scene/gui/dialogs.h
@@ -42,7 +42,6 @@
class LineEdit;
class AcceptDialog : public Window {
-
GDCLASS(AcceptDialog, Window);
Window *parent_visible;
@@ -98,7 +97,6 @@ public:
};
class ConfirmationDialog : public AcceptDialog {
-
GDCLASS(ConfirmationDialog, AcceptDialog);
Button *cancel;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index a4f0338f00..630f3c8ff6 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -34,21 +34,20 @@
#include "core/print_string.h"
#include "scene/gui/label.h"
-FileDialog::GetIconFunc FileDialog::get_icon_func = NULL;
-FileDialog::GetIconFunc FileDialog::get_large_icon_func = NULL;
+FileDialog::GetIconFunc FileDialog::get_icon_func = nullptr;
+FileDialog::GetIconFunc FileDialog::get_large_icon_func = nullptr;
-FileDialog::RegisterFunc FileDialog::register_func = NULL;
-FileDialog::RegisterFunc FileDialog::unregister_func = NULL;
+FileDialog::RegisterFunc FileDialog::register_func = nullptr;
+FileDialog::RegisterFunc FileDialog::unregister_func = nullptr;
VBoxContainer *FileDialog::get_vbox() {
return vbox;
}
void FileDialog::_theme_changed() {
-
- Color font_color = vbc->get_theme_color("font_color", "ToolButton");
- Color font_color_hover = vbc->get_theme_color("font_color_hover", "ToolButton");
- Color font_color_pressed = vbc->get_theme_color("font_color_pressed", "ToolButton");
+ Color font_color = vbox->get_theme_color("font_color", "ToolButton");
+ Color font_color_hover = vbox->get_theme_color("font_color_hover", "ToolButton");
+ Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "ToolButton");
dir_up->add_theme_color_override("icon_color_normal", font_color);
dir_up->add_theme_color_override("icon_color_hover", font_color_hover);
@@ -64,35 +63,27 @@ void FileDialog::_theme_changed() {
}
void FileDialog::_notification(int p_what) {
-
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (!is_visible()) {
-
set_process_unhandled_input(false);
}
}
if (p_what == NOTIFICATION_ENTER_TREE) {
-
- dir_up->set_icon(vbc->get_theme_icon("parent_folder"));
- refresh->set_icon(vbc->get_theme_icon("reload"));
- show_hidden->set_icon(vbc->get_theme_icon("toggle_hidden"));
+ dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog"));
+ refresh->set_icon(vbox->get_theme_icon("reload", "FileDialog"));
+ show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "FileDialog"));
_theme_changed();
}
}
void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventKey> k = p_event;
if (k.is_valid() && has_focus()) {
-
if (k->is_pressed()) {
-
bool handled = true;
switch (k->get_keycode()) {
-
case KEY_H: {
-
if (k->get_command()) {
set_show_hidden_files(!show_hidden_files);
} else {
@@ -101,11 +92,9 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
} break;
case KEY_F5: {
-
invalidate();
} break;
case KEY_BACKSPACE: {
-
_dir_entered("..");
} break;
default: {
@@ -113,24 +102,22 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
}
}
- if (handled)
+ if (handled) {
set_input_as_handled();
+ }
}
}
}
void FileDialog::set_enable_multiple_selection(bool p_enable) {
-
tree->set_select_mode(p_enable ? Tree::SELECT_MULTI : Tree::SELECT_SINGLE);
};
Vector<String> FileDialog::get_selected_files() const {
-
Vector<String> list;
TreeItem *item = tree->get_root();
while ((item = tree->get_next_selected(item))) {
-
list.push_back(dir_access->get_current_dir().plus_file(item->get_text(0)));
};
@@ -138,7 +125,6 @@ Vector<String> FileDialog::get_selected_files() const {
};
void FileDialog::update_dir() {
-
dir->set_text(dir_access->get_current_dir(false));
if (drives->is_visible()) {
@@ -150,7 +136,6 @@ void FileDialog::update_dir() {
}
void FileDialog::_dir_entered(String p_dir) {
-
dir_access->change_dir(p_dir);
file->set_text("");
invalidate();
@@ -158,7 +143,6 @@ void FileDialog::_dir_entered(String p_dir) {
}
void FileDialog::_file_entered(const String &p_file) {
-
_action_pressed();
}
@@ -169,16 +153,16 @@ void FileDialog::_save_confirm_pressed() {
}
void FileDialog::_post_popup() {
-
ConfirmationDialog::_post_popup();
if (invalidated) {
update_file_list();
invalidated = false;
}
- if (mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_SAVE_FILE) {
file->grab_focus();
- else
+ } else {
tree->grab_focus();
+ }
set_process_unhandled_input(true);
@@ -192,15 +176,12 @@ void FileDialog::_post_popup() {
}
void FileDialog::_action_pressed() {
-
if (mode == FILE_MODE_OPEN_FILES) {
-
- TreeItem *ti = tree->get_next_selected(NULL);
+ TreeItem *ti = tree->get_next_selected(nullptr);
String fbase = dir_access->get_current_dir();
Vector<String> files;
while (ti) {
-
files.push_back(fbase.plus_file(ti->get_text(0)));
ti = tree->get_next_selected(ti);
}
@@ -219,7 +200,6 @@ void FileDialog::_action_pressed() {
emit_signal("file_selected", f);
hide();
} else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) {
-
String path = dir_access->get_current_dir();
path = path.replace("\\", "/");
@@ -236,7 +216,6 @@ void FileDialog::_action_pressed() {
}
if (mode == FILE_MODE_SAVE_FILE) {
-
bool valid = false;
if (filter->get_selected() == filter->get_item_count() - 1) {
@@ -244,29 +223,27 @@ void FileDialog::_action_pressed() {
} else if (filters.size() > 1 && filter->get_selected() == 0) {
// match all filters
for (int i = 0; i < filters.size(); i++) {
-
String flt = filters[i].get_slice(";", 0);
for (int j = 0; j < flt.get_slice_count(","); j++) {
-
String str = flt.get_slice(",", j).strip_edges();
if (f.match(str)) {
valid = true;
break;
}
}
- if (valid)
+ if (valid) {
break;
+ }
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
-
String flt = filters[idx].get_slice(";", 0);
int filterSliceCount = flt.get_slice_count(",");
for (int j = 0; j < filterSliceCount; j++) {
-
String str = (flt.get_slice(",", j).strip_edges());
if (f.match(str)) {
valid = true;
@@ -286,7 +263,6 @@ void FileDialog::_action_pressed() {
}
if (!valid) {
-
exterr->popup_centered(Size2(250, 80));
return;
}
@@ -295,7 +271,6 @@ void FileDialog::_action_pressed() {
confirm_save->set_text(RTR("File Exists, Overwrite?"));
confirm_save->popup_centered(Size2(200, 80));
} else {
-
emit_signal("file_selected", f);
hide();
}
@@ -303,27 +278,28 @@ void FileDialog::_action_pressed() {
}
void FileDialog::_cancel_pressed() {
-
file->set_text("");
invalidate();
hide();
}
bool FileDialog::_is_open_should_be_disabled() {
-
- if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE)
+ if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_SAVE_FILE) {
return false;
+ }
TreeItem *ti = tree->get_next_selected(tree->get_root());
while (ti) {
TreeItem *prev_ti = ti;
ti = tree->get_next_selected(tree->get_root());
- if (ti == prev_ti)
+ if (ti == prev_ti) {
break;
+ }
}
// We have something that we can't select?
- if (!ti)
+ if (!ti) {
return mode != FILE_MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
+ }
Dictionary d = ti->get_metadata(0);
@@ -333,14 +309,12 @@ bool FileDialog::_is_open_should_be_disabled() {
}
void FileDialog::_go_up() {
-
dir_access->change_dir("..");
update_file_list();
update_dir();
}
void FileDialog::deselect_items() {
-
// Clear currently selected items in file manager.
tree->deselect_all();
@@ -349,7 +323,6 @@ void FileDialog::deselect_items() {
get_ok()->set_disabled(_is_open_should_be_disabled());
switch (mode) {
-
case FILE_MODE_OPEN_FILE:
case FILE_MODE_OPEN_FILES:
get_ok()->set_text(RTR("Open"));
@@ -370,14 +343,13 @@ void FileDialog::_tree_multi_selected(Object *p_object, int p_cell, bool p_selec
}
void FileDialog::_tree_selected() {
-
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
Dictionary d = ti->get_metadata(0);
if (!d["dir"]) {
-
file->set_text(d["name"]);
} else if (mode == FILE_MODE_OPEN_DIR) {
get_ok()->set_text(RTR("Select This Folder"));
@@ -387,22 +359,21 @@ void FileDialog::_tree_selected() {
}
void FileDialog::_tree_item_activated() {
-
TreeItem *ti = tree->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
Dictionary d = ti->get_metadata(0);
if (d["dir"]) {
-
dir_access->change_dir(d["name"]);
- if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY)
+ if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) {
file->set_text("");
+ }
call_deferred("_update_file_list");
call_deferred("_update_dir");
} else {
-
_action_pressed();
}
}
@@ -410,7 +381,9 @@ 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;
+ if (idx == -1) {
+ idx += 1;
+ }
String filter_str = filters[idx];
String file_str = file->get_text();
String base_name = file_str.get_basename();
@@ -420,7 +393,6 @@ void FileDialog::update_file_name() {
}
void FileDialog::update_file_list() {
-
tree->clear();
// Scroll back to the top after opening a directory
@@ -429,8 +401,10 @@ void FileDialog::update_file_list() {
dir_access->list_dir_begin();
TreeItem *root = tree->create_item();
- Ref<Texture2D> folder = vbc->get_theme_icon("folder");
- const Color folder_color = vbc->get_theme_color("folder_icon_modulate");
+ Ref<Texture2D> folder = vbox->get_theme_icon("folder", "FileDialog");
+ Ref<Texture2D> file_icon = vbox->get_theme_icon("file", "FileDialog");
+ const Color folder_color = vbox->get_theme_color("folder_icon_modulate", "FileDialog");
+ const Color file_color = vbox->get_theme_color("file_icon_modulate", "FileDialog");
List<String> files;
List<String> dirs;
@@ -438,17 +412,18 @@ void FileDialog::update_file_list() {
String item;
while ((item = dir_access->get_next()) != "") {
-
- if (item == "." || item == "..")
+ if (item == "." || item == "..") {
continue;
+ }
is_hidden = dir_access->current_is_hidden();
if (show_hidden_files || !is_hidden) {
- if (!dir_access->current_is_dir())
+ if (!dir_access->current_is_dir()) {
files.push_back(item);
- else
+ } else {
dirs.push_back(item);
+ }
}
}
@@ -474,28 +449,24 @@ void FileDialog::update_file_list() {
List<String> patterns;
// build filter
if (filter->get_selected() == filter->get_item_count() - 1) {
-
// match all
} else if (filters.size() > 1 && filter->get_selected() == 0) {
// match all filters
for (int i = 0; i < filters.size(); i++) {
-
String f = filters[i].get_slice(";", 0);
for (int j = 0; j < f.get_slice_count(","); j++) {
-
patterns.push_back(f.get_slice(",", j).strip_edges());
}
}
} else {
int idx = filter->get_selected();
- if (filters.size() > 1)
+ if (filters.size() > 1) {
idx--;
+ }
if (idx >= 0 && idx < filters.size()) {
-
String f = filters[idx].get_slice(";", 0);
for (int j = 0; j < f.get_slice_count(","); j++) {
-
patterns.push_back(f.get_slice(",", j).strip_edges());
}
}
@@ -504,12 +475,10 @@ void FileDialog::update_file_list() {
String base_dir = dir_access->get_current_dir();
while (!files.empty()) {
-
bool match = patterns.empty();
String match_str;
for (List<String>::Element *E = patterns.front(); E; E = E->next()) {
-
if (files.front()->get().matchn(E->get())) {
match_str = E->get();
match = true;
@@ -522,13 +491,15 @@ void FileDialog::update_file_list() {
ti->set_text(0, files.front()->get());
if (get_icon_func) {
-
Ref<Texture2D> icon = get_icon_func(base_dir.plus_file(files.front()->get()));
ti->set_icon(0, icon);
+ } else {
+ ti->set_icon(0, file_icon);
}
+ ti->set_icon_modulate(0, file_color);
if (mode == FILE_MODE_OPEN_DIR) {
- ti->set_custom_color(0, vbc->get_theme_color("files_disabled"));
+ ti->set_custom_color(0, vbox->get_theme_color("files_disabled", "FileDialog"));
ti->set_selectable(0, false);
}
Dictionary d;
@@ -536,25 +507,25 @@ void FileDialog::update_file_list() {
d["dir"] = false;
ti->set_metadata(0, d);
- if (file->get_text() == files.front()->get() || match_str == files.front()->get())
+ if (file->get_text() == files.front()->get() || match_str == files.front()->get()) {
ti->select(0);
+ }
}
files.pop_front();
}
- if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == NULL)
+ if (tree->get_root() && tree->get_root()->get_children() && tree->get_selected() == nullptr) {
tree->get_root()->get_children()->select(0);
+ }
}
void FileDialog::_filter_selected(int) {
-
update_file_name();
update_file_list();
}
void FileDialog::update_filters() {
-
filter->clear();
if (filters.size() > 1) {
@@ -564,37 +535,38 @@ void FileDialog::update_filters() {
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
String flt = filters[i].get_slice(";", 0).strip_edges();
- if (i > 0)
+ if (i > 0) {
all_filters += ", ";
+ }
all_filters += flt;
}
- if (max_filters < filters.size())
+ if (max_filters < filters.size()) {
all_filters += ", ...";
+ }
filter->add_item(RTR("All Recognized") + " (" + all_filters + ")");
}
for (int i = 0; i < filters.size(); i++) {
-
String flt = filters[i].get_slice(";", 0).strip_edges();
String desc = filters[i].get_slice(";", 1).strip_edges();
- if (desc.length())
+ if (desc.length()) {
filter->add_item(String(tr(desc)) + " (" + flt + ")");
- else
+ } else {
filter->add_item("(" + flt + ")");
+ }
}
filter->add_item(RTR("All Files (*)"));
}
void FileDialog::clear_filters() {
-
filters.clear();
update_filters();
invalidate();
}
-void FileDialog::add_filter(const String &p_filter) {
+void FileDialog::add_filter(const String &p_filter) {
filters.push_back(p_filter);
update_filters();
invalidate();
@@ -611,45 +583,44 @@ Vector<String> FileDialog::get_filters() const {
}
String FileDialog::get_current_dir() const {
-
return dir->get_text();
}
-String FileDialog::get_current_file() const {
+String FileDialog::get_current_file() const {
return file->get_text();
}
-String FileDialog::get_current_path() const {
+String FileDialog::get_current_path() const {
return dir->get_text().plus_file(file->get_text());
}
-void FileDialog::set_current_dir(const String &p_dir) {
+void FileDialog::set_current_dir(const String &p_dir) {
dir_access->change_dir(p_dir);
update_dir();
invalidate();
}
-void FileDialog::set_current_file(const String &p_file) {
+void FileDialog::set_current_file(const String &p_file) {
file->set_text(p_file);
update_dir();
invalidate();
int lp = p_file.find_last(".");
if (lp != -1) {
file->select(0, lp);
- if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file))
+ if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) {
file->grab_focus();
+ }
}
}
-void FileDialog::set_current_path(const String &p_path) {
- if (!p_path.size())
+void FileDialog::set_current_path(const String &p_path) {
+ if (!p_path.size()) {
return;
+ }
int pos = MAX(p_path.find_last("/"), p_path.find_last("\\"));
if (pos == -1) {
-
set_current_file(p_path);
} else {
-
String dir = p_path.substr(0, pos);
String file = p_path.substr(pos + 1, p_path.length());
set_current_dir(dir);
@@ -666,40 +637,43 @@ bool FileDialog::is_mode_overriding_title() const {
}
void FileDialog::set_file_mode(FileMode p_mode) {
-
ERR_FAIL_INDEX((int)p_mode, 5);
mode = p_mode;
switch (mode) {
-
case FILE_MODE_OPEN_FILE:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a File"));
+ }
makedir->hide();
break;
case FILE_MODE_OPEN_FILES:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open File(s)"));
+ }
makedir->hide();
break;
case FILE_MODE_OPEN_DIR:
get_ok()->set_text(RTR("Select Current Folder"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a Directory"));
+ }
makedir->show();
break;
case FILE_MODE_OPEN_ANY:
get_ok()->set_text(RTR("Open"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Open a File or Directory"));
+ }
makedir->show();
break;
case FILE_MODE_SAVE_FILE:
get_ok()->set_text(RTR("Save"));
- if (mode_overrides_title)
+ if (mode_overrides_title) {
set_title(RTR("Save a File"));
+ }
makedir->show();
break;
}
@@ -712,27 +686,23 @@ void FileDialog::set_file_mode(FileMode p_mode) {
}
FileDialog::FileMode FileDialog::get_file_mode() const {
-
return mode;
}
void FileDialog::set_access(Access p_access) {
-
ERR_FAIL_INDEX(p_access, 3);
- if (access == p_access)
+ if (access == p_access) {
return;
+ }
memdelete(dir_access);
switch (p_access) {
case ACCESS_FILESYSTEM: {
-
dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
} break;
case ACCESS_RESOURCES: {
-
dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
} break;
case ACCESS_USERDATA: {
-
dir_access = DirAccess::create(DirAccess::ACCESS_USERDATA);
} break;
}
@@ -744,7 +714,6 @@ void FileDialog::set_access(Access p_access) {
}
void FileDialog::invalidate() {
-
if (is_visible()) {
update_file_list();
invalidated = false;
@@ -754,12 +723,10 @@ void FileDialog::invalidate() {
}
FileDialog::Access FileDialog::get_access() const {
-
return access;
}
void FileDialog::_make_dir_confirm() {
-
Error err = dir_access->make_dir(makedirname->get_text());
if (err == OK) {
dir_access->change_dir(makedirname->get_text());
@@ -773,13 +740,11 @@ void FileDialog::_make_dir_confirm() {
}
void FileDialog::_make_dir() {
-
makedialog->popup_centered(Size2(250, 80));
makedirname->grab_focus();
}
void FileDialog::_select_drive(int p_idx) {
-
String d = drives->get_item_text(p_idx);
dir_access->change_dir(d);
file->set_text("");
@@ -788,7 +753,6 @@ void FileDialog::_select_drive(int p_idx) {
}
void FileDialog::_update_drives() {
-
int dc = dir_access->get_drive_count();
if (dc == 0 || access != ACCESS_FILESYSTEM) {
drives->hide();
@@ -813,7 +777,6 @@ void FileDialog::_update_drives() {
bool FileDialog::default_show_hidden_files = false;
void FileDialog::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_unhandled_input"), &FileDialog::_unhandled_input);
ClassDB::bind_method(D_METHOD("_cancel_pressed"), &FileDialog::_cancel_pressed);
@@ -883,14 +846,13 @@ void FileDialog::set_default_show_hidden_files(bool p_show) {
}
FileDialog::FileDialog() {
-
show_hidden_files = default_show_hidden_files;
mode_overrides_title = true;
- vbc = memnew(VBoxContainer);
- add_child(vbc);
- vbc->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed));
+ vbox = memnew(VBoxContainer);
+ add_child(vbox);
+ vbox->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed));
mode = FILE_MODE_SAVE_FILE;
set_title(RTR("Save a File"));
@@ -909,6 +871,7 @@ FileDialog::FileDialog() {
drives = memnew(OptionButton);
drives->connect("item_selected", callable_mp(this, &FileDialog::_select_drive));
+ hbc->add_child(drives);
dir = memnew(LineEdit);
hbc->add_child(dir);
@@ -933,11 +896,11 @@ FileDialog::FileDialog() {
makedir->set_text(RTR("Create Folder"));
makedir->connect("pressed", callable_mp(this, &FileDialog::_make_dir));
hbc->add_child(makedir);
- vbc->add_child(hbc);
+ vbox->add_child(hbc);
tree = memnew(Tree);
tree->set_hide_root(true);
- vbc->add_margin_child(RTR("Directories & Files:"), tree, true);
+ vbox->add_margin_child(RTR("Directories & Files:"), tree, true);
file_box = memnew(HBoxContainer);
file_box->add_child(memnew(Label(RTR("File:"))));
@@ -950,7 +913,7 @@ FileDialog::FileDialog() {
filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);
filter->set_clip_text(true); // too many extensions overflows it
file_box->add_child(filter);
- vbc->add_child(file_box);
+ vbox->add_child(file_box);
dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
access = ACCESS_RESOURCES;
@@ -993,50 +956,16 @@ FileDialog::FileDialog() {
update_dir();
set_hide_on_ok(false);
- vbox = vbc;
invalidated = true;
- if (register_func)
+ if (register_func) {
register_func(this);
+ }
}
FileDialog::~FileDialog() {
-
- if (unregister_func)
+ if (unregister_func) {
unregister_func(this);
+ }
memdelete(dir_access);
}
-
-void LineEditFileChooser::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("get_button"), &LineEditFileChooser::get_button);
- ClassDB::bind_method(D_METHOD("get_line_edit"), &LineEditFileChooser::get_line_edit);
- ClassDB::bind_method(D_METHOD("get_file_dialog"), &LineEditFileChooser::get_file_dialog);
-}
-
-void LineEditFileChooser::_chosen(const String &p_text) {
-
- line_edit->set_text(p_text);
- line_edit->emit_signal("text_entered", p_text);
-}
-
-void LineEditFileChooser::_browse() {
-
- dialog->popup_centered_ratio();
-}
-
-LineEditFileChooser::LineEditFileChooser() {
-
- line_edit = memnew(LineEdit);
- add_child(line_edit);
- line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- button = memnew(Button);
- button->set_text(" .. ");
- add_child(button);
- button->connect("pressed", callable_mp(this, &LineEditFileChooser::_browse));
- dialog = memnew(FileDialog);
- add_child(dialog);
- dialog->connect("file_selected", callable_mp(this, &LineEditFileChooser::_chosen));
- dialog->connect("dir_selected", callable_mp(this, &LineEditFileChooser::_chosen));
- dialog->connect("files_selected", callable_mp(this, &LineEditFileChooser::_chosen));
-}
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 295ae023d1..8bc536d576 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -40,7 +40,6 @@
#include "scene/gui/tree.h"
class FileDialog : public ConfirmationDialog {
-
GDCLASS(FileDialog, ConfirmationDialog);
public:
@@ -70,7 +69,6 @@ private:
ConfirmationDialog *makedialog;
LineEdit *makedirname;
- VBoxContainer *vbc;
Button *makedir;
Access access;
//Button *action;
@@ -178,27 +176,6 @@ public:
~FileDialog();
};
-class LineEditFileChooser : public HBoxContainer {
-
- GDCLASS(LineEditFileChooser, HBoxContainer);
- Button *button;
- LineEdit *line_edit;
- FileDialog *dialog;
-
- void _chosen(const String &p_text);
- void _browse();
-
-protected:
- static void _bind_methods();
-
-public:
- Button *get_button() { return button; }
- LineEdit *get_line_edit() { return line_edit; }
- FileDialog *get_file_dialog() { return dialog; }
-
- LineEditFileChooser();
-};
-
VARIANT_ENUM_CAST(FileDialog::FileMode);
VARIANT_ENUM_CAST(FileDialog::Access);
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index 88107f754c..ecd4ad17ea 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -73,8 +73,9 @@ int GradientEdit::_get_point_from_pos(int x) {
}
void GradientEdit::_show_color_picker() {
- if (grabbed == -1)
+ if (grabbed == -1) {
return;
+ }
picker->set_pick_color(points[grabbed].color);
Size2 minsize = popup->get_contents_minimum_size();
bool show_above = false;
@@ -93,11 +94,9 @@ GradientEdit::~GradientEdit() {
}
void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && grabbed != -1) {
-
points.remove(grabbed);
grabbed = -1;
grabbing = false;
@@ -129,7 +128,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
//Hold alt key to duplicate selected color
if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) {
-
int x = mb->get_position().x;
grabbed = _get_point_from_pos(x);
@@ -154,7 +152,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
//select
if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
-
update();
int x = mb->get_position().x;
int total_w = get_size().width - get_size().height - SPACING;
@@ -182,12 +179,12 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
int pos = -1;
for (int i = 0; i < points.size(); i++) {
- if (points[i].offset < newPoint.offset)
+ if (points[i].offset < newPoint.offset) {
pos = i;
+ }
}
if (pos == -1) {
-
prev.color = Color(0, 0, 0);
prev.offset = 0;
if (points.size()) {
@@ -197,7 +194,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
next.offset = 1.0;
}
} else {
-
if (pos == points.size() - 1) {
next.color = Color(1, 1, 1);
next.offset = 1.0;
@@ -207,7 +203,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
prev = points[pos];
}
- newPoint.color = prev.color.linear_interpolate(next.color, (newPoint.offset - prev.offset) / (next.offset - prev.offset));
+ newPoint.color = prev.color.lerp(next.color, (newPoint.offset - prev.offset) / (next.offset - prev.offset));
points.push_back(newPoint);
points.sort();
@@ -222,7 +218,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
-
if (grabbing) {
grabbing = false;
emit_signal("ramp_changed");
@@ -233,7 +228,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && grabbing) {
-
int total_w = get_size().width - get_size().height - SPACING;
int x = mm->get_position().x;
@@ -256,24 +250,25 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (temp_ofs < smallest_ofs) {
smallest_ofs = temp_ofs;
nearest_point = i;
- if (found)
+ if (found) {
break;
+ }
found = true;
}
}
}
if (found) {
- if (points[nearest_point].offset < newofs)
+ if (points[nearest_point].offset < newofs) {
newofs = points[nearest_point].offset + 0.00001;
- else
+ } else {
newofs = points[nearest_point].offset - 0.00001;
+ }
newofs = CLAMP(newofs, 0, 1);
}
}
bool valid = true;
for (int i = 0; i < points.size(); i++) {
-
if (points[i].offset == newofs && i != grabbed) {
valid = false;
break;
@@ -300,19 +295,18 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
void GradientEdit::_notification(int p_what) {
-
if (p_what == NOTIFICATION_ENTER_TREE) {
if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) {
picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed));
}
}
if (p_what == NOTIFICATION_DRAW) {
-
int w = get_size().x;
int h = get_size().y;
- if (w == 0 || h == 0)
+ if (w == 0 || h == 0) {
return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size
+ }
int total_w = get_size().width - get_size().height - SPACING;
@@ -322,20 +316,21 @@ void GradientEdit::_notification(int p_what) {
//Draw color ramp
Gradient::Point prev;
prev.offset = 0;
- if (points.size() == 0)
+ if (points.size() == 0) {
prev.color = Color(0, 0, 0); //Draw black rectangle if we have no points
- else
+ } else {
prev.color = points[0].color; //Extend color of first point to the beginning.
+ }
for (int i = -1; i < points.size(); i++) {
-
Gradient::Point next;
//If there is no next point
if (i + 1 == points.size()) {
- if (points.size() == 0)
+ if (points.size() == 0) {
next.color = Color(0, 0, 0); //Draw black rectangle if we have no points
- else
+ } else {
next.color = points[i].color; //Extend color of last point to the end.
+ }
next.offset = 1;
} else {
next = points[i + 1];
@@ -362,7 +357,6 @@ void GradientEdit::_notification(int p_what) {
//Draw point markers
for (int i = 0; i < points.size(); i++) {
-
Color col = points[i].color.contrasted();
col.a = 0.9;
@@ -397,7 +391,6 @@ void GradientEdit::_notification(int p_what) {
//Draw borders around color ramp if in focus
if (has_focus()) {
-
draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
@@ -406,7 +399,6 @@ void GradientEdit::_notification(int p_what) {
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
-
if (!is_visible()) {
grabbing = false;
}
@@ -435,21 +427,19 @@ void GradientEdit::_draw_checker(int x, int y, int w, int h) {
}
Size2 GradientEdit::get_minimum_size() const {
-
return Vector2(0, 16);
}
void GradientEdit::_color_changed(const Color &p_color) {
-
- if (grabbed == -1)
+ if (grabbed == -1) {
return;
+ }
points.write[grabbed].color = p_color;
update();
emit_signal("ramp_changed");
}
void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) {
-
ERR_FAIL_COND(p_offsets.size() != p_colors.size());
points.clear();
for (int i = 0; i < p_offsets.size(); i++) {
@@ -465,21 +455,24 @@ void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color>
Vector<float> GradientEdit::get_offsets() const {
Vector<float> ret;
- for (int i = 0; i < points.size(); i++)
+ for (int i = 0; i < points.size(); i++) {
ret.push_back(points[i].offset);
+ }
return ret;
}
Vector<Color> GradientEdit::get_colors() const {
Vector<Color> ret;
- for (int i = 0; i < points.size(); i++)
+ for (int i = 0; i < points.size(); i++) {
ret.push_back(points[i].color);
+ }
return ret;
}
void GradientEdit::set_points(Vector<Gradient::Point> &p_points) {
- if (points.size() != p_points.size())
+ if (points.size() != p_points.size()) {
grabbed = -1;
+ }
points.clear();
points = p_points;
}
diff --git a/scene/gui/gradient_edit.h b/scene/gui/gradient_edit.h
index a38a3dde47..376837b66c 100644
--- a/scene/gui/gradient_edit.h
+++ b/scene/gui/gradient_edit.h
@@ -37,7 +37,6 @@
#include "scene/resources/gradient.h"
class GradientEdit : public Control {
-
GDCLASS(GradientEdit, Control);
PopupPanel *popup;
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index fd7935b376..5080ba74e2 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -30,7 +30,7 @@
#include "graph_edit.h"
-#include "core/input/input_filter.h"
+#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "scene/gui/box_container.h"
@@ -44,19 +44,17 @@
#define MAX_ZOOM (1 * ZOOM_SCALE * ZOOM_SCALE * ZOOM_SCALE)
bool GraphEditFilter::has_point(const Point2 &p_point) const {
-
return ge->_filter_input(p_point);
}
GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
-
ge = p_edit;
}
Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
-
- if (is_node_connected(p_from, p_from_port, p_to, p_to_port))
+ if (is_node_connected(p_from, p_from_port, p_to, p_to_port)) {
return OK;
+ }
Connection c;
c.from = p_from;
c.from_port = p_from_port;
@@ -72,22 +70,18 @@ Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const S
}
bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
-
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
-
- if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port)
+ if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
return true;
+ }
}
return false;
}
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
-
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
-
if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
-
connections.erase(E);
top_layer->update();
update();
@@ -98,17 +92,14 @@ void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const
}
bool GraphEdit::clips_input() const {
-
return true;
}
void GraphEdit::get_connection_list(List<Connection> *r_connections) const {
-
*r_connections = connections;
}
void GraphEdit::set_scroll_ofs(const Vector2 &p_ofs) {
-
setting_scroll_ofs = true;
h_scroll->set_value(p_ofs.x);
v_scroll->set_value(p_ofs.y);
@@ -117,12 +108,10 @@ void GraphEdit::set_scroll_ofs(const Vector2 &p_ofs) {
}
Vector2 GraphEdit::get_scroll_ofs() const {
-
return Vector2(h_scroll->get_value(), v_scroll->get_value());
}
void GraphEdit::_scroll_moved(double) {
-
if (!awaiting_scroll_offset_update) {
call_deferred("_update_scroll_offset");
awaiting_scroll_offset_update = true;
@@ -136,14 +125,13 @@ void GraphEdit::_scroll_moved(double) {
}
void GraphEdit::_update_scroll_offset() {
-
set_block_minimum_size_adjust(true);
for (int i = 0; i < get_child_count(); i++) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Point2 pos = gn->get_offset() * zoom;
pos -= Point2(h_scroll->get_value(), v_scroll->get_value());
@@ -159,9 +147,9 @@ void GraphEdit::_update_scroll_offset() {
}
void GraphEdit::_update_scroll() {
-
- if (updating)
+ if (updating) {
return;
+ }
updating = true;
@@ -169,10 +157,10 @@ void GraphEdit::_update_scroll() {
Rect2 screen;
for (int i = 0; i < get_child_count(); i++) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Rect2 r;
r.position = gn->get_offset() * zoom;
@@ -186,19 +174,21 @@ void GraphEdit::_update_scroll() {
h_scroll->set_min(screen.position.x);
h_scroll->set_max(screen.position.x + screen.size.x);
h_scroll->set_page(get_size().x);
- if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page())
+ if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) {
h_scroll->hide();
- else
+ } else {
h_scroll->show();
+ }
v_scroll->set_min(screen.position.y);
v_scroll->set_max(screen.position.y + screen.size.y);
v_scroll->set_page(get_size().y);
- if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page())
+ if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) {
v_scroll->hide();
- else
+ } else {
v_scroll->show();
+ }
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
@@ -218,7 +208,6 @@ void GraphEdit::_update_scroll() {
}
void GraphEdit::_graph_node_raised(Node *p_gn) {
-
GraphNode *gn = Object::cast_to<GraphNode>(p_gn);
ERR_FAIL_COND(!gn);
if (gn->is_comment()) {
@@ -241,7 +230,6 @@ void GraphEdit::_graph_node_raised(Node *p_gn) {
}
void GraphEdit::_graph_node_moved(Node *p_gn) {
-
GraphNode *gn = Object::cast_to<GraphNode>(p_gn);
ERR_FAIL_COND(!gn);
top_layer->update();
@@ -250,7 +238,6 @@ void GraphEdit::_graph_node_moved(Node *p_gn) {
}
void GraphEdit::add_child_notify(Node *p_child) {
-
Control::add_child_notify(p_child);
top_layer->call_deferred("raise"); //top layer always on top!
@@ -266,7 +253,6 @@ void GraphEdit::add_child_notify(Node *p_child) {
}
void GraphEdit::remove_child_notify(Node *p_child) {
-
Control::remove_child_notify(p_child);
if (is_inside_tree()) {
top_layer->call_deferred("raise"); //top layer always on top!
@@ -279,7 +265,6 @@ void GraphEdit::remove_child_notify(Node *p_child) {
}
void GraphEdit::_notification(int p_what) {
-
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
port_grab_distance_horizontal = get_theme_constant("port_grab_distance_horizontal");
port_grab_distance_vertical = get_theme_constant("port_grab_distance_vertical");
@@ -304,7 +289,6 @@ void GraphEdit::_notification(int p_what) {
v_scroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0);
}
if (p_what == NOTIFICATION_DRAW) {
-
draw_style_box(get_theme_stylebox("bg"), Rect2(Point2(), get_size()));
if (is_using_snap()) {
@@ -322,26 +306,26 @@ void GraphEdit::_notification(int p_what) {
Color grid_major = get_theme_color("grid_major");
for (int i = from.x; i < from.x + len.x; i++) {
-
Color color;
- if (ABS(i) % 10 == 0)
+ if (ABS(i) % 10 == 0) {
color = grid_major;
- else
+ } else {
color = grid_minor;
+ }
float base_ofs = i * snap * zoom - offset.x * zoom;
draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
}
for (int i = from.y; i < from.y + len.y; i++) {
-
Color color;
- if (ABS(i) % 10 == 0)
+ if (ABS(i) % 10 == 0) {
color = grid_major;
- else
+ } else {
color = grid_minor;
+ }
float base_ofs = i * snap * zoom - offset.y * zoom;
draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
@@ -356,24 +340,22 @@ void GraphEdit::_notification(int p_what) {
}
bool GraphEdit::_filter_input(const Point2 &p_point) {
-
Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
for (int j = 0; j < gn->get_connection_output_count(); j++) {
-
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
- if (is_in_hot_zone(pos, p_point))
+ if (is_in_hot_zone(pos, p_point)) {
return true;
+ }
}
for (int j = 0; j < gn->get_connection_input_count(); j++) {
-
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
if (is_in_hot_zone(pos, p_point)) {
return true;
@@ -385,32 +367,25 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
}
void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
-
Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
-
Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
Vector2 mpos(mb->get_position().x, mb->get_position().y);
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
for (int j = 0; j < gn->get_connection_output_count(); j++) {
-
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
if (is_in_hot_zone(pos, mpos)) {
-
if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) {
//check disconnect
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
-
if (E->get().from == gn->get_name() && E->get().from_port == j) {
-
Node *to = get_node(String(E->get().to));
if (Object::cast_to<GraphNode>(to)) {
-
connecting_from = E->get().to;
connecting_index = E->get().to_port;
connecting_out = false;
@@ -445,19 +420,14 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
for (int j = 0; j < gn->get_connection_input_count(); j++) {
-
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
if (is_in_hot_zone(pos, mpos)) {
-
if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) {
//check disconnect
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
-
if (E->get().to == gn->get_name() && E->get().to_port == j) {
-
Node *fr = get_node(String(E->get().from));
if (Object::cast_to<GraphNode>(fr)) {
-
connecting_from = E->get().from;
connecting_index = E->get().from_port;
connecting_out = true;
@@ -496,7 +466,6 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseMotion> mm = p_ev;
if (mm.is_valid() && connecting) {
-
connecting_to = mm->get_position();
connecting_target = false;
top_layer->update();
@@ -504,18 +473,16 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Ref<Texture2D> port = get_theme_icon("port", "GraphNode");
Vector2 mpos = mm->get_position();
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
if (!connecting_out) {
for (int j = 0; j < gn->get_connection_output_count(); j++) {
-
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
int type = gn->get_connection_output_type(j);
if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) {
-
connecting_target = true;
connecting_to = pos;
connecting_target_to = gn->get_name();
@@ -524,9 +491,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
}
} else {
-
for (int j = 0; j < gn->get_connection_input_count(); j++) {
-
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
int type = gn->get_connection_input_type(j);
if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) {
@@ -542,9 +507,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) {
-
if (connecting && connecting_target) {
-
String from = connecting_from;
int from_slot = connecting_index;
String to = connecting_target_to;
@@ -557,7 +520,6 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
emit_signal("connection_request", from, from_slot, to, to_slot);
} else if (!just_disconnected) {
-
String from = connecting_from;
int from_slot = connecting_index;
Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y);
@@ -577,16 +539,17 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
}
bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos) {
-
- if (p_control->is_set_as_toplevel() || !p_control->is_visible())
+ if (p_control->is_set_as_toplevel() || !p_control->is_visible()) {
return false;
+ }
if (!p_control->has_point(pos) || p_control->get_mouse_filter() == MOUSE_FILTER_IGNORE) {
//test children
for (int i = 0; i < p_control->get_child_count(); i++) {
Control *subchild = Object::cast_to<Control>(p_control->get_child(i));
- if (!subchild)
+ if (!subchild) {
continue;
+ }
if (_check_clickable_control(subchild, pos - subchild->get_position())) {
return true;
}
@@ -599,23 +562,25 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos)
}
bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
- if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos))
+ if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos)) {
return false;
+ }
for (int i = 0; i < get_child_count(); i++) {
Control *child = Object::cast_to<Control>(get_child(i));
- if (!child)
+ if (!child) {
continue;
+ }
Rect2 rect = child->get_rect();
if (rect.has_point(p_mouse_pos)) {
-
//check sub-controls
Vector2 subpos = p_mouse_pos - rect.position;
for (int j = 0; j < child->get_child_count(); j++) {
Control *subchild = Object::cast_to<Control>(child->get_child(j));
- if (!subchild)
+ if (!subchild) {
continue;
+ }
if (_check_clickable_control(subchild, subpos - subchild->get_position())) {
return false;
@@ -640,7 +605,6 @@ static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, Vector2 start, Vector2 co
}
void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
-
float mp = p_begin + (p_end - p_begin) * 0.5;
Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
Vector2 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b);
@@ -651,9 +615,8 @@ void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors,
float dp = Math::rad2deg(Math::acos(na.dot(nb)));
if (p_depth >= p_min_depth && (dp < p_tol || p_depth >= p_max_depth)) {
-
points.push_back((beg + end) * 0.5);
- colors.push_back(p_color.linear_interpolate(p_to_color, mp));
+ colors.push_back(p_color.lerp(p_to_color, mp));
lines++;
} else {
_bake_segment2d(points, colors, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
@@ -662,7 +625,6 @@ void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors,
}
void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color) {
-
//cubic bezier code
float diff = p_to.x - p_from.x;
float cp_offset;
@@ -696,12 +658,10 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
}
void GraphEdit::_connections_layer_draw() {
-
Color activity_color = get_theme_color("activity");
//draw connections
List<List<Connection>::Element *> to_erase;
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
-
NodePath fromnp(E->get().from);
Node *from = get_node(fromnp);
@@ -737,8 +697,8 @@ void GraphEdit::_connections_layer_draw() {
Color tocolor = gto->get_connection_input_color(E->get().to_port);
if (E->get().activity > 0) {
- color = color.linear_interpolate(activity_color, E->get().activity);
- tocolor = tocolor.linear_interpolate(activity_color, E->get().activity);
+ color = color.lerp(activity_color, E->get().activity);
+ tocolor = tocolor.lerp(activity_color, E->get().activity);
}
_draw_cos_line(connections_layer, frompos, topos, color, tocolor);
}
@@ -750,20 +710,19 @@ void GraphEdit::_connections_layer_draw() {
}
void GraphEdit::_top_layer_draw() {
-
_update_scroll();
if (connecting) {
-
Node *fromn = get_node(connecting_from);
ERR_FAIL_COND(!fromn);
GraphNode *from = Object::cast_to<GraphNode>(fromn);
ERR_FAIL_COND(!from);
Vector2 pos;
- if (connecting_out)
+ if (connecting_out) {
pos = from->get_connection_output_position(connecting_index);
- else
+ } else {
pos = from->get_connection_input_position(connecting_index);
+ }
pos += from->get_position();
Vector2 topos;
@@ -790,40 +749,34 @@ void GraphEdit::_top_layer_draw() {
}
void GraphEdit::set_selected(Node *p_child) {
-
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
gn->set_selected(gn == p_child);
}
}
void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
-
Ref<InputEventMouseMotion> mm = p_ev;
- if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)))) {
+ if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y);
}
if (mm.is_valid() && dragging) {
-
just_selected = true;
- // TODO: Remove local mouse pos hack if/when InputEventMouseMotion is fixed to support floats
- //drag_accum+=Vector2(mm->get_relative().x,mm->get_relative().y);
- drag_accum = get_local_mouse_position() - drag_origin;
+ drag_accum += mm->get_relative();
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
if (gn && gn->is_selected()) {
-
Vector2 pos = (gn->get_drag_from() * zoom + drag_accum) / zoom;
// Snapping can be toggled temporarily by holding down Ctrl.
// This is done here as to not toggle the grid when holding down Ctrl.
- if (is_using_snap() ^ InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) {
+ if (is_using_snap() ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
const int snap = get_snap();
pos = pos.snapped(Vector2(snap, snap));
}
@@ -834,7 +787,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (mm.is_valid() && box_selecting) {
- box_selecting_to = get_local_mouse_position();
+ box_selecting_to = mm->get_position();
box_selecting_rect = Rect2(MIN(box_selecting_from.x, box_selecting_to.x),
MIN(box_selecting_from.y, box_selecting_to.y),
@@ -842,19 +795,20 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
ABS(box_selecting_from.y - box_selecting_to.y));
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
Rect2 r = gn->get_rect();
r.size *= zoom;
bool in_box = r.intersects(box_selecting_rect);
- if (in_box)
- gn->set_selected(box_selection_mode_aditive);
- else
- gn->set_selected(previus_selected.find(gn) != NULL);
+ if (in_box) {
+ gn->set_selected(box_selection_mode_additive);
+ } else {
+ gn->set_selected(previus_selected.find(gn) != nullptr);
+ }
}
top_layer->update();
@@ -862,17 +816,16 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseButton> b = p_ev;
if (b.is_valid()) {
-
if (b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
if (box_selecting) {
box_selecting = false;
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ if (!gn) {
continue;
+ }
- gn->set_selected(previus_selected.find(gn) != NULL);
+ gn->set_selected(previus_selected.find(gn) != nullptr);
}
top_layer->update();
} else {
@@ -886,7 +839,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && dragging) {
- if (!just_selected && drag_accum == Vector2() && InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) {
+ if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
//deselect current node
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -894,20 +847,21 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (gn) {
Rect2 r = gn->get_rect();
r.size *= zoom;
- if (r.has_point(get_local_mouse_position()))
+ if (r.has_point(b->get_position())) {
gn->set_selected(false);
+ }
}
}
}
if (drag_accum != Vector2()) {
-
emit_signal("_begin_node_move");
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (gn && gn->is_selected())
+ if (gn && gn->is_selected()) {
gn->set_drag(false);
+ }
}
emit_signal("_end_node_move");
@@ -921,18 +875,17 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
-
- GraphNode *gn = NULL;
+ GraphNode *gn = nullptr;
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn_selected = Object::cast_to<GraphNode>(get_child(i));
if (gn_selected) {
- if (gn_selected->is_resizing())
+ if (gn_selected->is_resizing()) {
continue;
+ }
- if (gn_selected->has_point(gn_selected->get_local_mouse_position())) {
+ if (gn_selected->has_point(b->get_position() - gn_selected->get_position())) {
gn = gn_selected;
break;
}
@@ -940,70 +893,83 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (gn) {
-
- if (_filter_input(b->get_position()))
+ if (_filter_input(b->get_position())) {
return;
+ }
dragging = true;
drag_accum = Vector2();
- drag_origin = get_local_mouse_position();
just_selected = !gn->is_selected();
- if (!gn->is_selected() && !InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) {
+ if (!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
for (int i = 0; i < get_child_count(); i++) {
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
- if (o_gn)
- o_gn->set_selected(o_gn == gn);
+ if (o_gn) {
+ if (o_gn == gn) {
+ o_gn->set_selected(true);
+ } else {
+ if (o_gn->is_selected()) {
+ emit_signal("node_unselected", o_gn);
+ }
+ o_gn->set_selected(false);
+ }
+ }
}
}
gn->set_selected(true);
for (int i = 0; i < get_child_count(); i++) {
GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i));
- if (!o_gn)
+ if (!o_gn) {
continue;
- if (o_gn->is_selected())
+ }
+ if (o_gn->is_selected()) {
o_gn->set_drag(true);
+ }
}
} else {
- if (_filter_input(b->get_position()))
+ if (_filter_input(b->get_position())) {
return;
- if (InputFilter::get_singleton()->is_key_pressed(KEY_SPACE))
+ }
+ if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
return;
+ }
box_selecting = true;
- box_selecting_from = get_local_mouse_position();
+ box_selecting_from = b->get_position();
if (b->get_control()) {
- box_selection_mode_aditive = true;
+ box_selection_mode_additive = true;
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected())
+ if (!gn2 || !gn2->is_selected()) {
continue;
+ }
previus_selected.push_back(gn2);
}
} else if (b->get_shift()) {
- box_selection_mode_aditive = false;
+ box_selection_mode_additive = false;
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2 || !gn2->is_selected())
+ if (!gn2 || !gn2->is_selected()) {
continue;
+ }
previus_selected.push_back(gn2);
}
} else {
- box_selection_mode_aditive = true;
+ box_selection_mode_additive = true;
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
-
GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
- if (!gn2)
+ if (!gn2) {
continue;
-
+ }
+ if (gn2->is_selected()) {
+ emit_signal("node_unselected", gn2);
+ }
gn2->set_selected(false);
}
}
@@ -1025,16 +991,16 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
//too difficult to get right
//set_zoom(zoom/ZOOM_SCALE);
}
- if (b->get_button_index() == BUTTON_WHEEL_UP && !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) {
+ if (b->get_button_index() == BUTTON_WHEEL_UP && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8);
}
- if (b->get_button_index() == BUTTON_WHEEL_DOWN && !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) {
+ if (b->get_button_index() == BUTTON_WHEEL_DOWN && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8);
}
- if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT))) {
+ if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) {
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b->get_factor() / 8);
}
- if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT))) {
+ if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) {
h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b->get_factor() / 8);
}
}
@@ -1042,7 +1008,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventKey> k = p_ev;
if (k.is_valid()) {
-
if (k->get_keycode() == KEY_D && k->is_pressed() && k->get_command()) {
emit_signal("duplicate_nodes_request");
accept_event();
@@ -1066,24 +1031,19 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMagnifyGesture> magnify_gesture = p_ev;
if (magnify_gesture.is_valid()) {
-
set_zoom_custom(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position());
}
Ref<InputEventPanGesture> pan_gesture = p_ev;
if (pan_gesture.is_valid()) {
-
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
}
}
void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
-
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
-
if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
-
if (Math::is_equal_approx(E->get().activity, p_activity)) {
//update only if changed
top_layer->update();
@@ -1096,22 +1056,20 @@ void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_por
}
void GraphEdit::clear_connections() {
-
connections.clear();
update();
connections_layer->update();
}
void GraphEdit::set_zoom(float p_zoom) {
-
set_zoom_custom(p_zoom, get_size() / 2);
}
void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
-
p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM);
- if (zoom == p_zoom)
+ if (zoom == p_zoom) {
return;
+ }
zoom_minus->set_disabled(zoom == MIN_ZOOM);
zoom_plus->set_disabled(zoom == MAX_ZOOM);
@@ -1125,7 +1083,6 @@ void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
connections_layer->update();
if (is_visible_in_tree()) {
-
Vector2 ofs = sbofs * zoom - p_center;
h_scroll->set_value(ofs.x);
v_scroll->set_value(ofs.y);
@@ -1139,37 +1096,30 @@ float GraphEdit::get_zoom() const {
}
void GraphEdit::set_right_disconnects(bool p_enable) {
-
right_disconnects = p_enable;
}
bool GraphEdit::is_right_disconnects_enabled() const {
-
return right_disconnects;
}
void GraphEdit::add_valid_right_disconnect_type(int p_type) {
-
valid_right_disconnect_types.insert(p_type);
}
void GraphEdit::remove_valid_right_disconnect_type(int p_type) {
-
valid_right_disconnect_types.erase(p_type);
}
void GraphEdit::add_valid_left_disconnect_type(int p_type) {
-
valid_left_disconnect_types.insert(p_type);
}
void GraphEdit::remove_valid_left_disconnect_type(int p_type) {
-
valid_left_disconnect_types.erase(p_type);
}
Array GraphEdit::_get_connection_list() const {
-
List<Connection> conns;
get_connection_list(&conns);
Array arr;
@@ -1185,21 +1135,18 @@ Array GraphEdit::_get_connection_list() const {
}
void GraphEdit::_zoom_minus() {
-
set_zoom(zoom / ZOOM_SCALE);
}
-void GraphEdit::_zoom_reset() {
+void GraphEdit::_zoom_reset() {
set_zoom(1);
}
void GraphEdit::_zoom_plus() {
-
set_zoom(zoom * ZOOM_SCALE);
}
void GraphEdit::add_valid_connection_type(int p_type, int p_with_type) {
-
ConnType ct;
ct.type_a = p_type;
ct.type_b = p_with_type;
@@ -1208,7 +1155,6 @@ void GraphEdit::add_valid_connection_type(int p_type, int p_with_type) {
}
void GraphEdit::remove_valid_connection_type(int p_type, int p_with_type) {
-
ConnType ct;
ct.type_a = p_type;
ct.type_b = p_with_type;
@@ -1217,7 +1163,6 @@ void GraphEdit::remove_valid_connection_type(int p_type, int p_with_type) {
}
bool GraphEdit::is_valid_connection_type(int p_type, int p_with_type) const {
-
ConnType ct;
ct.type_a = p_type;
ct.type_b = p_with_type;
@@ -1226,33 +1171,29 @@ bool GraphEdit::is_valid_connection_type(int p_type, int p_with_type) const {
}
void GraphEdit::set_use_snap(bool p_enable) {
-
snap_button->set_pressed(p_enable);
update();
}
bool GraphEdit::is_using_snap() const {
-
return snap_button->is_pressed();
}
int GraphEdit::get_snap() const {
-
return snap_amount->get_value();
}
void GraphEdit::set_snap(int p_snap) {
-
ERR_FAIL_COND(p_snap < 5);
snap_amount->set_value(p_snap);
update();
}
+
void GraphEdit::_snap_toggled() {
update();
}
void GraphEdit::_snap_value_changed(double) {
-
update();
}
@@ -1261,7 +1202,6 @@ HBoxContainer *GraphEdit::get_zoom_hbox() {
}
void GraphEdit::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("connect_node", "from", "from_port", "to", "to_port"), &GraphEdit::connect_node);
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);
@@ -1311,6 +1251,7 @@ void GraphEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("copy_nodes_request"));
ADD_SIGNAL(MethodInfo("paste_nodes_request"));
ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
+ ADD_SIGNAL(MethodInfo("node_unselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("delete_nodes_request"));
@@ -1323,7 +1264,7 @@ GraphEdit::GraphEdit() {
set_focus_mode(FOCUS_ALL);
awaiting_scroll_offset_update = false;
- top_layer = NULL;
+ top_layer = nullptr;
top_layer = memnew(GraphEditFilter(this));
add_child(top_layer);
top_layer->set_mouse_filter(MOUSE_FILTER_PASS);
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 7f1d2699ba..c632490855 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -42,7 +42,6 @@
class GraphEdit;
class GraphEditFilter : public Control {
-
GDCLASS(GraphEditFilter, Control);
friend class GraphEdit;
@@ -54,7 +53,6 @@ public:
};
class GraphEdit : public Control {
-
GDCLASS(GraphEdit, Control);
public:
@@ -99,12 +97,11 @@ private:
bool dragging;
bool just_selected;
Vector2 drag_accum;
- Point2 drag_origin; // Workaround for GH-5907
float zoom;
bool box_selecting;
- bool box_selection_mode_aditive;
+ bool box_selection_mode_additive;
Point2 box_selecting_from;
Point2 box_selecting_to;
Rect2 box_selecting_rect;
@@ -142,7 +139,6 @@ private:
bool lines_on_bg;
struct ConnType {
-
union {
struct {
uint32_t type_a;
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index c28a60ff87..b6a96238dc 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -33,31 +33,33 @@
#include "core/method_bind_ext.gen.inc"
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
-
- if (!p_name.operator String().begins_with("slot/"))
+ if (!p_name.operator String().begins_with("slot/")) {
return false;
+ }
int idx = p_name.operator String().get_slice("/", 1).to_int();
String what = p_name.operator String().get_slice("/", 2);
Slot si;
- if (slot_info.has(idx))
+ if (slot_info.has(idx)) {
si = slot_info[idx];
+ }
- if (what == "left_enabled")
+ if (what == "left_enabled") {
si.enable_left = p_value;
- else if (what == "left_type")
+ } else if (what == "left_type") {
si.type_left = p_value;
- else if (what == "left_color")
+ } else if (what == "left_color") {
si.color_left = p_value;
- else if (what == "right_enabled")
+ } else if (what == "right_enabled") {
si.enable_right = p_value;
- else if (what == "right_type")
+ } else if (what == "right_type") {
si.type_right = p_value;
- else if (what == "right_color")
+ } else if (what == "right_color") {
si.color_right = p_value;
- else
+ } else {
return false;
+ }
set_slot(idx, si.enable_left, si.type_left, si.color_left, si.enable_right, si.type_right, si.color_right);
update();
@@ -65,7 +67,6 @@ bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
}
bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
-
if (!p_name.operator String().begins_with("slot/")) {
return false;
}
@@ -74,33 +75,36 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
String what = p_name.operator String().get_slice("/", 2);
Slot si;
- if (slot_info.has(idx))
+ if (slot_info.has(idx)) {
si = slot_info[idx];
+ }
- if (what == "left_enabled")
+ if (what == "left_enabled") {
r_ret = si.enable_left;
- else if (what == "left_type")
+ } else if (what == "left_type") {
r_ret = si.type_left;
- else if (what == "left_color")
+ } else if (what == "left_color") {
r_ret = si.color_left;
- else if (what == "right_enabled")
+ } else if (what == "right_enabled") {
r_ret = si.enable_right;
- else if (what == "right_type")
+ } else if (what == "right_type") {
r_ret = si.type_right;
- else if (what == "right_color")
+ } else if (what == "right_color") {
r_ret = si.color_right;
- else
+ } else {
return false;
+ }
return true;
}
-void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
+void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
int idx = 0;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || c->is_set_as_toplevel())
+ if (!c || c->is_set_as_toplevel()) {
continue;
+ }
String base = "slot/" + itos(idx) + "/";
@@ -116,7 +120,6 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
}
void GraphNode::_resort() {
-
int sep = get_theme_constant("separation");
Ref<StyleBox> sb = get_theme_stylebox("frame");
bool first = true;
@@ -125,20 +128,23 @@ void GraphNode::_resort() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
minsize.y += size.y;
minsize.x = MAX(minsize.x, size.x);
- if (first)
+ if (first) {
first = false;
- else
+ } else {
minsize.y += sep;
+ }
}
int vofs = 0;
@@ -147,10 +153,12 @@ void GraphNode::_resort() {
cache_y.clear();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
@@ -167,7 +175,6 @@ void GraphNode::_resort() {
}
bool GraphNode::has_point(const Point2 &p_point) const {
-
if (comment) {
Ref<StyleBox> comment = get_theme_stylebox("comment");
Ref<Texture2D> resizer = get_theme_icon("resizer");
@@ -188,17 +195,14 @@ bool GraphNode::has_point(const Point2 &p_point) const {
}
void GraphNode::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_DRAW: {
-
Ref<StyleBox> sb;
if (comment) {
sb = get_theme_stylebox(selected ? "commentfocus" : "comment");
} else {
-
sb = get_theme_stylebox(selected ? "selectedframe" : "frame");
}
@@ -223,10 +227,8 @@ void GraphNode::_notification(int p_what) {
switch (overlay) {
case OVERLAY_DISABLED: {
-
} break;
case OVERLAY_BREAKPOINT: {
-
draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size()));
} break;
case OVERLAY_POSITION: {
@@ -237,8 +239,9 @@ void GraphNode::_notification(int p_what) {
int w = get_size().width - sb->get_minimum_size().x;
- if (show_close)
+ if (show_close) {
w -= close->get_width();
+ }
draw_string(title_font, Point2(sb->get_margin(MARGIN_LEFT) + title_h_offset, -title_font->get_height() + title_font->get_ascent() + title_offset), title, title_color, w);
if (show_close) {
@@ -251,11 +254,12 @@ void GraphNode::_notification(int p_what) {
}
for (Map<int, Slot>::Element *E = slot_info.front(); E; E = E->next()) {
-
- if (E->key() < 0 || E->key() >= cache_y.size())
+ if (E->key() < 0 || E->key() >= cache_y.size()) {
continue;
- if (!slot_info.has(E->key()))
+ }
+ if (!slot_info.has(E->key())) {
continue;
+ }
const Slot &s = slot_info[E->key()];
//left
if (s.enable_left) {
@@ -280,19 +284,16 @@ void GraphNode::_notification(int p_what) {
} break;
case NOTIFICATION_SORT_CHILDREN: {
-
_resort();
} break;
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
} break;
}
}
void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture2D> &p_custom_left, const Ref<Texture2D> &p_custom_right) {
-
ERR_FAIL_COND(p_idx < 0);
if (!p_enable_left && p_type_left == 0 && p_color_left == Color(1, 1, 1, 1) && !p_enable_right && p_type_right == 0 && p_color_right == Color(1, 1, 1, 1)) {
@@ -315,61 +316,60 @@ void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const C
}
void GraphNode::clear_slot(int p_idx) {
-
slot_info.erase(p_idx);
update();
connpos_dirty = true;
}
-void GraphNode::clear_all_slots() {
+void GraphNode::clear_all_slots() {
slot_info.clear();
update();
connpos_dirty = true;
}
-bool GraphNode::is_slot_enabled_left(int p_idx) const {
- if (!slot_info.has(p_idx))
+bool GraphNode::is_slot_enabled_left(int p_idx) const {
+ if (!slot_info.has(p_idx)) {
return false;
+ }
return slot_info[p_idx].enable_left;
}
int GraphNode::get_slot_type_left(int p_idx) const {
-
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return 0;
+ }
return slot_info[p_idx].type_left;
}
Color GraphNode::get_slot_color_left(int p_idx) const {
-
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return Color(1, 1, 1, 1);
+ }
return slot_info[p_idx].color_left;
}
bool GraphNode::is_slot_enabled_right(int p_idx) const {
-
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return false;
+ }
return slot_info[p_idx].enable_right;
}
int GraphNode::get_slot_type_right(int p_idx) const {
-
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return 0;
+ }
return slot_info[p_idx].type_right;
}
Color GraphNode::get_slot_color_right(int p_idx) const {
-
- if (!slot_info.has(p_idx))
+ if (!slot_info.has(p_idx)) {
return Color(1, 1, 1, 1);
+ }
return slot_info[p_idx].color_right;
}
Size2 GraphNode::get_minimum_size() const {
-
Ref<Font> title_font = get_theme_font("title_font");
int sep = get_theme_constant("separation");
@@ -384,31 +384,33 @@ Size2 GraphNode::get_minimum_size() const {
}
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
minsize.y += size.y;
minsize.x = MAX(minsize.x, size.x);
- if (first)
+ if (first) {
first = false;
- else
+ } else {
minsize.y += sep;
+ }
}
return minsize + sb->get_minimum_size();
}
void GraphNode::set_title(const String &p_title) {
-
- if (title == p_title)
+ if (title == p_title) {
return;
+ }
title = p_title;
update();
_change_notify("title");
@@ -416,19 +418,16 @@ void GraphNode::set_title(const String &p_title) {
}
String GraphNode::get_title() const {
-
return title;
}
void GraphNode::set_offset(const Vector2 &p_offset) {
-
offset = p_offset;
emit_signal("offset_changed");
update();
}
Vector2 GraphNode::get_offset() const {
-
return offset;
}
@@ -442,10 +441,11 @@ bool GraphNode::is_selected() {
}
void GraphNode::set_drag(bool p_drag) {
- if (p_drag)
+ if (p_drag) {
drag_from = get_offset();
- else
+ } else {
emit_signal("dragged", drag_from, get_offset()); //useful for undo/redo
+ }
}
Vector2 GraphNode::get_drag_from() {
@@ -453,17 +453,15 @@ Vector2 GraphNode::get_drag_from() {
}
void GraphNode::set_show_close_button(bool p_enable) {
-
show_close = p_enable;
update();
}
-bool GraphNode::is_close_button_visible() const {
+bool GraphNode::is_close_button_visible() const {
return show_close;
}
void GraphNode::_connpos_update() {
-
int edgeofs = get_theme_constant("port_offset");
int sep = get_theme_constant("separation");
@@ -476,10 +474,12 @@ void GraphNode::_connpos_update() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2i size = c->get_combined_minimum_size();
@@ -487,7 +487,6 @@ void GraphNode::_connpos_update() {
int h = size.y;
if (slot_info.has(idx)) {
-
if (slot_info[idx].enable_left) {
ConnCache cc;
cc.pos = Point2i(edgeofs, y + h / 2);
@@ -504,8 +503,9 @@ void GraphNode::_connpos_update() {
}
}
- if (vofs > 0)
+ if (vofs > 0) {
vofs += sep;
+ }
vofs += size.y;
idx++;
}
@@ -514,24 +514,25 @@ void GraphNode::_connpos_update() {
}
int GraphNode::get_connection_input_count() {
-
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
return conn_input_cache.size();
}
-int GraphNode::get_connection_output_count() {
- if (connpos_dirty)
+int GraphNode::get_connection_output_count() {
+ if (connpos_dirty) {
_connpos_update();
+ }
return conn_output_cache.size();
}
Vector2 GraphNode::get_connection_input_position(int p_idx) {
-
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Vector2());
Vector2 pos = conn_input_cache[p_idx].pos;
@@ -541,27 +542,27 @@ Vector2 GraphNode::get_connection_input_position(int p_idx) {
}
int GraphNode::get_connection_input_type(int p_idx) {
-
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), 0);
return conn_input_cache[p_idx].type;
}
Color GraphNode::get_connection_input_color(int p_idx) {
-
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_input_cache.size(), Color());
return conn_input_cache[p_idx].color;
}
Vector2 GraphNode::get_connection_output_position(int p_idx) {
-
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Vector2());
Vector2 pos = conn_output_cache[p_idx].pos;
@@ -571,32 +572,29 @@ Vector2 GraphNode::get_connection_output_position(int p_idx) {
}
int GraphNode::get_connection_output_type(int p_idx) {
-
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), 0);
return conn_output_cache[p_idx].type;
}
Color GraphNode::get_connection_output_color(int p_idx) {
-
- if (connpos_dirty)
+ if (connpos_dirty) {
_connpos_update();
+ }
ERR_FAIL_INDEX_V(p_idx, conn_output_cache.size(), Color());
return conn_output_cache[p_idx].color;
}
void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
-
Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid()) {
-
- ERR_FAIL_COND_MSG(get_parent_control() == NULL, "GraphNode must be the child of a GraphEdit node.");
+ ERR_FAIL_COND_MSG(get_parent_control() == nullptr, "GraphNode must be the child of a GraphEdit node.");
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
-
Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y);
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
//send focus to parent
@@ -609,7 +607,6 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
Ref<Texture2D> resizer = get_theme_icon("resizer");
if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) {
-
resizing = true;
resizing_from = mpos;
resizing_from_size = get_size();
@@ -636,40 +633,33 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
}
void GraphNode::set_overlay(Overlay p_overlay) {
-
overlay = p_overlay;
update();
}
GraphNode::Overlay GraphNode::get_overlay() const {
-
return overlay;
}
void GraphNode::set_comment(bool p_enable) {
-
comment = p_enable;
update();
}
bool GraphNode::is_comment() const {
-
return comment;
}
void GraphNode::set_resizable(bool p_enable) {
-
resizable = p_enable;
update();
}
bool GraphNode::is_resizable() const {
-
return resizable;
}
void GraphNode::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
ClassDB::bind_method(D_METHOD("_gui_input"), &GraphNode::_gui_input);
@@ -732,7 +722,6 @@ void GraphNode::_bind_methods() {
}
GraphNode::GraphNode() {
-
overlay = OVERLAY_DISABLED;
show_close = false;
connpos_dirty = true;
diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h
index a3eb8ed152..6372833e6f 100644
--- a/scene/gui/graph_node.h
+++ b/scene/gui/graph_node.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
class GraphNode : public Container {
-
GDCLASS(GraphNode, Container);
public:
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index 16f6fd0111..2f37461c4d 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -31,11 +31,8 @@
#include "grid_container.h"
void GridContainer::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_SORT_CHILDREN: {
-
Map<int, int> col_minw; // Max of min_width of all controls in each col (indexed by col).
Map<int, int> row_minh; // Max of min_height of all controls in each row (indexed by row).
Set<int> col_expanded; // Columns which have the SIZE_EXPAND flag set.
@@ -50,22 +47,25 @@ void GridContainer::_notification(int p_what) {
int valid_controls_index = 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())
+ if (!c || !c->is_visible_in_tree()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
Size2i ms = c->get_combined_minimum_size();
- if (col_minw.has(col))
+ if (col_minw.has(col)) {
col_minw[col] = MAX(col_minw[col], ms.width);
- else
+ } else {
col_minw[col] = ms.width;
- if (row_minh.has(row))
+ }
+ if (row_minh.has(row)) {
row_minh[row] = MAX(row_minh[row], ms.height);
- else
+ } else {
row_minh[row] = ms.height;
+ }
if (c->get_h_size_flags() & SIZE_EXPAND) {
col_expanded.insert(col);
@@ -83,13 +83,15 @@ void GridContainer::_notification(int p_what) {
// 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()) {
- if (!col_expanded.has(E->key()))
+ if (!col_expanded.has(E->key())) {
remaining_space.width -= E->get();
+ }
}
for (Map<int, int>::Element *E = row_minh.front(); E; E = E->next()) {
- if (!row_expanded.has(E->key()))
+ if (!row_expanded.has(E->key())) {
remaining_space.height -= E->get();
+ }
}
remaining_space.height -= vsep * MAX(max_row - 1, 0);
remaining_space.width -= hsep * MAX(max_col - 1, 0);
@@ -146,16 +148,18 @@ void GridContainer::_notification(int p_what) {
valid_controls_index = 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())
+ if (!c || !c->is_visible_in_tree()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
if (col == 0) {
col_ofs = 0;
- if (row > 0)
+ if (row > 0) {
row_ofs += (row_expanded.has(row - 1) ? row_expand : row_minh[row - 1]) + vsep;
+ }
}
Point2 p(col_ofs, row_ofs);
@@ -168,14 +172,12 @@ void GridContainer::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
} break;
}
}
void GridContainer::set_columns(int p_columns) {
-
ERR_FAIL_COND(p_columns < 1);
columns = p_columns;
queue_sort();
@@ -183,12 +185,10 @@ void GridContainer::set_columns(int p_columns) {
}
int GridContainer::get_columns() const {
-
return columns;
}
void GridContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_columns", "columns"), &GridContainer::set_columns);
ClassDB::bind_method(D_METHOD("get_columns"), &GridContainer::get_columns);
@@ -196,7 +196,6 @@ void GridContainer::_bind_methods() {
}
Size2 GridContainer::get_minimum_size() const {
-
Map<int, int> col_minw;
Map<int, int> row_minh;
@@ -208,24 +207,26 @@ Size2 GridContainer::get_minimum_size() const {
int valid_controls_index = 0;
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible())
+ if (!c || !c->is_visible()) {
continue;
+ }
int row = valid_controls_index / columns;
int col = valid_controls_index % columns;
valid_controls_index++;
Size2i ms = c->get_combined_minimum_size();
- if (col_minw.has(col))
+ if (col_minw.has(col)) {
col_minw[col] = MAX(col_minw[col], ms.width);
- else
+ } else {
col_minw[col] = ms.width;
+ }
- if (row_minh.has(row))
+ if (row_minh.has(row)) {
row_minh[row] = MAX(row_minh[row], ms.height);
- else
+ } else {
row_minh[row] = ms.height;
+ }
max_col = MAX(col, max_col);
max_row = MAX(row, max_row);
}
diff --git a/scene/gui/grid_container.h b/scene/gui/grid_container.h
index 0ed8863196..0a1bd6751a 100644
--- a/scene/gui/grid_container.h
+++ b/scene/gui/grid_container.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
class GridContainer : public Container {
-
GDCLASS(GridContainer, Container);
int columns;
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 2db44d0b66..54150d130d 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -33,7 +33,6 @@
#include "core/project_settings.h"
void ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bool p_selectable) {
-
Item item;
item.icon = p_texture;
item.icon_transposed = false;
@@ -52,7 +51,6 @@ void ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, b
}
void ItemList::add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable) {
-
Item item;
item.icon = p_item;
item.icon_transposed = false;
@@ -71,7 +69,6 @@ void ItemList::add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable) {
}
void ItemList::set_item_text(int p_idx, const String &p_text) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].text = p_text;
@@ -80,7 +77,6 @@ void ItemList::set_item_text(int p_idx, const String &p_text) {
}
String ItemList::get_item_text(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), String());
return items[p_idx].text;
}
@@ -96,7 +92,6 @@ bool ItemList::is_item_tooltip_enabled(int p_idx) const {
}
void ItemList::set_item_tooltip(int p_idx, const String &p_tooltip) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].tooltip = p_tooltip;
@@ -105,13 +100,11 @@ void ItemList::set_item_tooltip(int p_idx, const String &p_tooltip) {
}
String ItemList::get_item_tooltip(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), String());
return items[p_idx].tooltip;
}
void ItemList::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].icon = p_icon;
@@ -120,14 +113,12 @@ void ItemList::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
}
Ref<Texture2D> ItemList::get_item_icon(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture2D>());
return items[p_idx].icon;
}
void ItemList::set_item_icon_transposed(int p_idx, const bool p_transposed) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].icon_transposed = p_transposed;
@@ -136,14 +127,12 @@ void ItemList::set_item_icon_transposed(int p_idx, const bool p_transposed) {
}
bool ItemList::is_item_icon_transposed(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), false);
return items[p_idx].icon_transposed;
}
void ItemList::set_item_icon_region(int p_idx, const Rect2 &p_region) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].icon_region = p_region;
@@ -152,14 +141,12 @@ void ItemList::set_item_icon_region(int p_idx, const Rect2 &p_region) {
}
Rect2 ItemList::get_item_icon_region(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Rect2());
return items[p_idx].icon_region;
}
void ItemList::set_item_icon_modulate(int p_idx, const Color &p_modulate) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].icon_modulate = p_modulate;
@@ -167,70 +154,61 @@ void ItemList::set_item_icon_modulate(int p_idx, const Color &p_modulate) {
}
Color ItemList::get_item_icon_modulate(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Color());
return items[p_idx].icon_modulate;
}
void ItemList::set_item_custom_bg_color(int p_idx, const Color &p_custom_bg_color) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].custom_bg = p_custom_bg_color;
}
Color ItemList::get_item_custom_bg_color(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Color());
return items[p_idx].custom_bg;
}
void ItemList::set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_color) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].custom_fg = p_custom_fg_color;
}
Color ItemList::get_item_custom_fg_color(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Color());
return items[p_idx].custom_fg;
}
void ItemList::set_item_tag_icon(int p_idx, const Ref<Texture2D> &p_tag_icon) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].tag_icon = p_tag_icon;
update();
shape_changed = true;
}
-Ref<Texture2D> ItemList::get_item_tag_icon(int p_idx) const {
+Ref<Texture2D> ItemList::get_item_tag_icon(int p_idx) const {
ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture2D>());
return items[p_idx].tag_icon;
}
void ItemList::set_item_selectable(int p_idx, bool p_selectable) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].selectable = p_selectable;
}
bool ItemList::is_item_selectable(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), false);
return items[p_idx].selectable;
}
void ItemList::set_item_disabled(int p_idx, bool p_disabled) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].disabled = p_disabled;
@@ -238,13 +216,11 @@ void ItemList::set_item_disabled(int p_idx, bool p_disabled) {
}
bool ItemList::is_item_disabled(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), false);
return items[p_idx].disabled;
}
void ItemList::set_item_metadata(int p_idx, const Variant &p_metadata) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].metadata = p_metadata;
@@ -253,16 +229,14 @@ void ItemList::set_item_metadata(int p_idx, const Variant &p_metadata) {
}
Variant ItemList::get_item_metadata(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Variant());
return items[p_idx].metadata;
}
-void ItemList::select(int p_idx, bool p_single) {
+void ItemList::select(int p_idx, bool p_single) {
ERR_FAIL_INDEX(p_idx, items.size());
if (p_single || select_mode == SELECT_SINGLE) {
-
if (!items[p_idx].selectable || items[p_idx].disabled) {
return;
}
@@ -274,15 +248,14 @@ void ItemList::select(int p_idx, bool p_single) {
current = p_idx;
ensure_selected_visible = false;
} else {
-
if (items[p_idx].selectable && !items[p_idx].disabled) {
items.write[p_idx].selected = true;
}
}
update();
}
-void ItemList::unselect(int p_idx) {
+void ItemList::unselect(int p_idx) {
ERR_FAIL_INDEX(p_idx, items.size());
if (select_mode != SELECT_MULTI) {
@@ -295,12 +268,11 @@ void ItemList::unselect(int p_idx) {
}
void ItemList::unselect_all() {
-
- if (items.size() < 1)
+ if (items.size() < 1) {
return;
+ }
for (int i = 0; i < items.size(); i++) {
-
items.write[i].selected = false;
}
current = -1;
@@ -308,7 +280,6 @@ void ItemList::unselect_all() {
}
bool ItemList::is_selected(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), false);
return items[p_idx].selected;
@@ -317,21 +288,19 @@ bool ItemList::is_selected(int p_idx) const {
void ItemList::set_current(int p_current) {
ERR_FAIL_INDEX(p_current, items.size());
- if (select_mode == SELECT_SINGLE)
+ if (select_mode == SELECT_SINGLE) {
select(p_current, true);
- else {
+ } else {
current = p_current;
update();
}
}
int ItemList::get_current() const {
-
return current;
}
void ItemList::move_item(int p_from_idx, int p_to_idx) {
-
ERR_FAIL_INDEX(p_from_idx, items.size());
ERR_FAIL_INDEX(p_to_idx, items.size());
@@ -348,11 +317,10 @@ void ItemList::move_item(int p_from_idx, int p_to_idx) {
}
int ItemList::get_item_count() const {
-
return items.size();
}
-void ItemList::remove_item(int p_idx) {
+void ItemList::remove_item(int p_idx) {
ERR_FAIL_INDEX(p_idx, items.size());
items.remove(p_idx);
@@ -362,7 +330,6 @@ void ItemList::remove_item(int p_idx) {
}
void ItemList::clear() {
-
items.clear();
current = -1;
ensure_selected_visible = false;
@@ -372,65 +339,58 @@ void ItemList::clear() {
}
void ItemList::set_fixed_column_width(int p_size) {
-
ERR_FAIL_COND(p_size < 0);
fixed_column_width = p_size;
update();
shape_changed = true;
}
-int ItemList::get_fixed_column_width() const {
+int ItemList::get_fixed_column_width() const {
return fixed_column_width;
}
void ItemList::set_same_column_width(bool p_enable) {
-
same_column_width = p_enable;
update();
shape_changed = true;
}
-bool ItemList::is_same_column_width() const {
+bool ItemList::is_same_column_width() const {
return same_column_width;
}
void ItemList::set_max_text_lines(int p_lines) {
-
ERR_FAIL_COND(p_lines < 1);
max_text_lines = p_lines;
update();
shape_changed = true;
}
-int ItemList::get_max_text_lines() const {
+int ItemList::get_max_text_lines() const {
return max_text_lines;
}
void ItemList::set_max_columns(int p_amount) {
-
ERR_FAIL_COND(p_amount < 0);
max_columns = p_amount;
update();
shape_changed = true;
}
-int ItemList::get_max_columns() const {
+int ItemList::get_max_columns() const {
return max_columns;
}
void ItemList::set_select_mode(SelectMode p_mode) {
-
select_mode = p_mode;
update();
}
ItemList::SelectMode ItemList::get_select_mode() const {
-
return select_mode;
}
void ItemList::set_icon_mode(IconMode p_mode) {
-
ERR_FAIL_INDEX((int)p_mode, 2);
icon_mode = p_mode;
update();
@@ -438,28 +398,27 @@ void ItemList::set_icon_mode(IconMode p_mode) {
}
ItemList::IconMode ItemList::get_icon_mode() const {
-
return icon_mode;
}
void ItemList::set_fixed_icon_size(const Size2 &p_size) {
-
fixed_icon_size = p_size;
update();
}
Size2 ItemList::get_fixed_icon_size() const {
-
return fixed_icon_size;
}
-Size2 ItemList::Item::get_icon_size() const {
- if (icon.is_null())
+Size2 ItemList::Item::get_icon_size() const {
+ if (icon.is_null()) {
return Size2();
+ }
Size2 size_result = Size2(icon_region.size).abs();
- if (icon_region.size.x == 0 || icon_region.size.y == 0)
+ if (icon_region.size.x == 0 || icon_region.size.y == 0) {
size_result = icon->get_size();
+ }
if (icon_transposed) {
Size2 size_tmp = size_result;
@@ -471,7 +430,6 @@ Size2 ItemList::Item::get_icon_size() const {
}
void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
-
double prev_scroll = scroll_bar->get_value();
Ref<InputEventMouseMotion> mm = p_event;
@@ -483,7 +441,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (defer_select_single >= 0 && mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) {
-
select(defer_select_single, true);
emit_signal("multi_selected", defer_select_single, true);
@@ -492,7 +449,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
if (mb.is_valid() && (mb->get_button_index() == BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == BUTTON_RIGHT)) && mb->is_pressed()) {
-
search_string = ""; //any mousepress cancels
Vector2 pos = mb->get_position();
Ref<StyleBox> bg = get_theme_stylebox("bg");
@@ -502,7 +458,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
int closest = -1;
for (int i = 0; i < items.size(); i++) {
-
Rect2 rc = items[i].rect_cache;
if (i % current_columns == current_columns - 1) {
rc.size.width = get_size().width; //not right but works
@@ -515,7 +470,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
if (closest != -1) {
-
int i = closest;
if (select_mode == SELECT_MULTI && items[i].selected && mb->get_command()) {
@@ -523,7 +477,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
emit_signal("multi_selected", i, false);
} else if (select_mode == SELECT_MULTI && mb->get_shift() && current >= 0 && current < items.size() && current != i) {
-
int from = current;
int to = i;
if (i < current) {
@@ -532,23 +485,21 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
for (int j = from; j <= to; j++) {
bool selected = !items[j].selected;
select(j, false);
- if (selected)
+ if (selected) {
emit_signal("multi_selected", j, true);
+ }
}
if (mb->get_button_index() == BUTTON_RIGHT) {
-
emit_signal("item_rmb_selected", i, get_local_mouse_position());
}
} else {
-
if (!mb->is_doubleclick() && !mb->get_command() && select_mode == SELECT_MULTI && items[i].selectable && !items[i].disabled && items[i].selected && mb->get_button_index() == BUTTON_LEFT) {
defer_select_single = i;
return;
}
if (items[i].selected && mb->get_button_index() == BUTTON_RIGHT) {
-
emit_signal("item_rmb_selected", i, get_local_mouse_position());
} else {
bool selected = items[i].selected;
@@ -558,15 +509,14 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (!selected || allow_reselect) {
if (select_mode == SELECT_SINGLE) {
emit_signal("item_selected", i);
- } else
+ } else {
emit_signal("multi_selected", i, true);
+ }
}
if (mb->get_button_index() == BUTTON_RIGHT) {
-
emit_signal("item_rmb_selected", i, get_local_mouse_position());
} else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_doubleclick()) {
-
emit_signal("item_activated", i);
}
}
@@ -584,28 +534,21 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
emit_signal("nothing_selected");
}
if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
-
scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() * mb->get_factor() / 8);
}
if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
-
scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * mb->get_factor() / 8);
}
if (p_event->is_pressed() && items.size() > 0) {
if (p_event->is_action("ui_up")) {
-
if (search_string != "") {
-
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
if (diff < uint64_t(ProjectSettings::get_singleton()->get("gui/timers/incremental_search_max_interval_msec")) * 2) {
-
for (int i = current - 1; i >= 0; i--) {
-
if (items[i].text.begins_with(search_string)) {
-
set_current(i);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
@@ -629,18 +572,13 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
} else if (p_event->is_action("ui_down")) {
-
if (search_string != "") {
-
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
if (diff < uint64_t(ProjectSettings::get_singleton()->get("gui/timers/incremental_search_max_interval_msec")) * 2) {
-
for (int i = current + 1; i < items.size(); i++) {
-
if (items[i].text.begins_with(search_string)) {
-
set_current(i);
ensure_current_is_visible();
if (select_mode == SELECT_SINGLE) {
@@ -663,7 +601,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
} else if (p_event->is_action("ui_page_up")) {
-
search_string = ""; //any mousepress cancels
for (int i = 4; i > 0; i--) {
@@ -678,7 +615,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
}
} else if (p_event->is_action("ui_page_down")) {
-
search_string = ""; //any mousepress cancels
for (int i = 4; i > 0; i--) {
@@ -694,7 +630,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
}
} else if (p_event->is_action("ui_left")) {
-
search_string = ""; //any mousepress cancels
if (current % current_columns != 0) {
@@ -706,7 +641,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
} else if (p_event->is_action("ui_right")) {
-
search_string = ""; //any mousepress cancels
if (current % current_columns != (current_columns - 1) && current + 1 < items.size()) {
@@ -720,7 +654,6 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
} else if (p_event->is_action("ui_cancel")) {
search_string = "";
} else if (p_event->is_action("ui_select") && select_mode == SELECT_MULTI) {
-
if (current >= 0 && current < items.size()) {
if (items[current].selectable && !items[current].disabled && !items[current].selected) {
select(current, false);
@@ -737,11 +670,9 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
emit_signal("item_activated", current);
}
} else {
-
Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->get_unicode()) {
-
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
uint64_t max_interval = uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000));
@@ -751,19 +682,22 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
search_string = "";
}
- if (String::chr(k->get_unicode()) != search_string)
+ if (String::chr(k->get_unicode()) != search_string) {
search_string += String::chr(k->get_unicode());
+ }
for (int i = current + 1; i <= items.size(); i++) {
if (i == items.size()) {
- if (current == 0 || current == -1)
+ if (current == 0 || current == -1) {
break;
- else
+ } else {
i = 0;
+ }
}
- if (i == current)
+ if (i == current) {
break;
+ }
if (items[i].text.findn(search_string) == 0) {
set_current(i);
@@ -780,22 +714,20 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
-
scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * pan_gesture->get_delta().y / 8);
}
- if (scroll_bar->get_value() != prev_scroll)
+ if (scroll_bar->get_value() != prev_scroll) {
accept_event(); //accept event if scroll changed
+ }
}
void ItemList::ensure_current_is_visible() {
-
ensure_selected_visible = true;
update();
}
static Rect2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) {
-
Size2 size = p_max_size;
int tex_width = p_size.width * size.height / p_size.height;
int tex_height = size.height;
@@ -812,14 +744,12 @@ static Rect2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) {
}
void ItemList::_notification(int p_what) {
-
if (p_what == NOTIFICATION_RESIZED) {
shape_changed = true;
update();
}
if (p_what == NOTIFICATION_DRAW) {
-
Ref<StyleBox> bg = get_theme_stylebox("bg");
int mw = scroll_bar->get_minimum_size().x;
@@ -859,21 +789,18 @@ void ItemList::_notification(int p_what) {
}
if (has_focus()) {
- VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
draw_style_box(get_theme_stylebox("bg_focus"), Rect2(Point2(), size));
- VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false);
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false);
}
if (shape_changed) {
-
float max_column_width = 0;
//1- compute item minimum sizes
for (int i = 0; i < items.size(); i++) {
-
Size2 minsize;
if (items[i].icon.is_valid()) {
-
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
minsize = fixed_icon_size * icon_scale;
} else {
@@ -890,7 +817,6 @@ void ItemList::_notification(int p_what) {
}
if (items[i].text != "") {
-
Size2 s = font->get_string_size(items[i].text);
//s.width=MIN(s.width,fixed_column_width);
@@ -908,8 +834,9 @@ void ItemList::_notification(int p_what) {
}
}
- if (fixed_column_width > 0)
+ if (fixed_column_width > 0) {
minsize.x = fixed_column_width;
+ }
max_column_width = MAX(max_column_width, minsize.x);
// elements need to adapt to the selected size
@@ -923,8 +850,9 @@ void ItemList::_notification(int p_what) {
//2-attempt best fit
current_columns = 0x7FFFFFFF;
- if (max_columns > 0)
+ if (max_columns > 0) {
current_columns = max_columns;
+ }
while (true) {
//repeat until all fits
@@ -934,7 +862,6 @@ void ItemList::_notification(int p_what) {
int max_h = 0;
separators.clear();
for (int i = 0; i < items.size(); i++) {
-
if (current_columns > 1 && items[i].rect_cache.size.width + ofs.x > fit_size) {
//went past
current_columns = MAX(col, 1);
@@ -942,16 +869,17 @@ void ItemList::_notification(int p_what) {
break;
}
- if (same_column_width)
+ if (same_column_width) {
items.write[i].rect_cache.size.x = max_column_width;
+ }
items.write[i].rect_cache.position = ofs;
max_h = MAX(max_h, items[i].rect_cache.size.y);
ofs.x += items[i].rect_cache.size.x + hseparation;
col++;
if (col == current_columns) {
-
- if (i < items.size() - 1)
+ if (i < items.size() - 1) {
separators.push_back(ofs.y + max_h + vseparation / 2);
+ }
for (int j = i; j >= 0 && col > 0; j--, col--) {
items.write[j].rect_cache.size.y = max_h;
@@ -971,8 +899,9 @@ void ItemList::_notification(int p_what) {
if (all_fit) {
float page = MAX(0, size.height - bg->get_minimum_size().height);
float max = MAX(page, ofs.y + max_h);
- if (auto_height)
+ if (auto_height) {
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
+ }
scroll_bar->set_max(max);
scroll_bar->set_page(page);
if (max <= page) {
@@ -981,8 +910,9 @@ void ItemList::_notification(int p_what) {
} else {
scroll_bar->show();
- if (do_autoscroll_to_bottom)
+ if (do_autoscroll_to_bottom) {
scroll_bar->set_value(max);
+ }
}
break;
}
@@ -994,7 +924,6 @@ void ItemList::_notification(int p_what) {
//ensure_selected_visible needs to be checked before we draw the list.
if (ensure_selected_visible && current >= 0 && current < items.size()) {
-
Rect2 r = items[current].rect_cache;
int from = scroll_bar->get_value();
int to = from + scroll_bar->get_page();
@@ -1035,14 +964,15 @@ void ItemList::_notification(int p_what) {
}
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)
+ if (rcache.position.y > clip.position.y + clip.size.y) {
break; // done
+ }
- if (!clip.intersects(rcache))
+ if (!clip.intersects(rcache)) {
continue;
+ }
if (current_columns == 1) {
rcache.size.width = width - rcache.position.x;
@@ -1073,7 +1003,6 @@ void ItemList::_notification(int p_what) {
Vector2 text_ofs;
if (items[i].icon.is_valid()) {
-
Size2 icon_size;
//= _adjust_to_max_size(items[i].get_icon_size(),fixed_icon_size) * icon_scale;
@@ -1088,7 +1017,6 @@ void ItemList::_notification(int p_what) {
Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
if (icon_mode == ICON_MODE_TOP) {
-
pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width) / 2);
pos.y += MIN(
Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2),
@@ -1096,7 +1024,6 @@ void ItemList::_notification(int p_what) {
text_ofs.y = icon_size.height + icon_margin;
text_ofs.y += items[i].rect_cache.size.height - items[i].min_rect_cache.size.height;
} else {
-
pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2);
text_ofs.x = icon_size.width + icon_margin;
}
@@ -1110,8 +1037,9 @@ void ItemList::_notification(int p_what) {
}
Color modulate = items[i].icon_modulate;
- if (items[i].disabled)
+ if (items[i].disabled) {
modulate.a *= 0.5;
+ }
// If the icon is transposed, we have to switch the size so that it is drawn correctly
if (items[i].icon_transposed) {
@@ -1125,41 +1053,40 @@ void ItemList::_notification(int p_what) {
}
if (items[i].tag_icon.is_valid()) {
-
draw_texture(items[i].tag_icon, items[i].rect_cache.position + base_ofs);
}
if (items[i].text != "") {
-
int max_len = -1;
Vector2 size2 = font->get_string_size(items[i].text);
- if (fixed_column_width)
+ if (fixed_column_width) {
max_len = fixed_column_width;
- else if (same_column_width)
+ } else if (same_column_width) {
max_len = items[i].rect_cache.size.x;
- else
+ } else {
max_len = size2.x;
+ }
Color modulate = items[i].selected ? font_color_selected : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
- if (items[i].disabled)
+ if (items[i].disabled) {
modulate.a *= 0.5;
+ }
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
-
int ss = items[i].text.length();
float ofs = 0;
int line = 0;
for (int j = 0; j <= ss; j++) {
-
int cs = j < ss ? font->get_char_size(items[i].text[j], items[i].text[j + 1]).x : 0;
if (ofs + cs > max_len || j == ss) {
line_limit_cache.write[line] = j;
line_size_cache.write[line] = ofs;
line++;
ofs = 0;
- if (line >= max_text_lines)
+ if (line >= max_text_lines) {
break;
+ }
} else {
ofs += cs;
}
@@ -1175,21 +1102,21 @@ void ItemList::_notification(int p_what) {
FontDrawer drawer(font, Color(1, 1, 1));
for (int j = 0; j < ss; j++) {
-
if (j == line_limit_cache[line]) {
line++;
ofs = 0;
- if (line >= max_text_lines)
+ if (line >= max_text_lines) {
break;
+ }
}
ofs += drawer.draw_char(get_canvas_item(), text_ofs + Vector2(ofs + (max_len - line_size_cache[line]) / 2, line * (font_height + line_separation)).floor(), items[i].text[j], items[i].text[j + 1], modulate);
}
//special multiline mode
} else {
-
- if (fixed_column_width > 0)
+ if (fixed_column_width > 0) {
size2.x = MIN(size2.x, fixed_column_width);
+ }
if (icon_mode == ICON_MODE_TOP) {
text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
@@ -1207,7 +1134,6 @@ void ItemList::_notification(int p_what) {
}
if (select_mode == SELECT_MULTI && i == current) {
-
Rect2 r = rcache;
r.position += base_ofs;
r.position.y -= vseparation / 2;
@@ -1235,8 +1161,9 @@ void ItemList::_notification(int p_what) {
}
for (int i = first_visible_separator; i < separators.size(); i++) {
- if (separators[i] > clip.position.y + clip.size.y)
+ 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);
@@ -1249,7 +1176,6 @@ void ItemList::_scroll_changed(double) {
}
int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const {
-
Vector2 pos = p_pos;
Ref<StyleBox> bg = get_theme_stylebox("bg");
pos -= bg->get_offset();
@@ -1259,7 +1185,6 @@ int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const {
int closest_dist = 0x7FFFFFFF;
for (int i = 0; i < items.size(); i++) {
-
Rect2 rc = items[i].rect_cache;
if (i % current_columns == current_columns - 1) {
rc.size.width = get_size().width - rc.position.x; //make sure you can still select the last item when clicking past the column
@@ -1281,9 +1206,9 @@ int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const {
}
bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const {
-
- if (items.empty())
+ if (items.empty()) {
return true;
+ }
Vector2 pos = p_pos;
Ref<StyleBox> bg = get_theme_stylebox("bg");
@@ -1295,7 +1220,6 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const {
}
String ItemList::get_tooltip(const Point2 &p_pos) const {
-
int closest = get_item_at_position(p_pos, true);
if (closest != -1) {
@@ -1314,7 +1238,6 @@ String ItemList::get_tooltip(const Point2 &p_pos) const {
}
void ItemList::sort_items_by_text() {
-
items.sort();
update();
shape_changed = true;
@@ -1330,7 +1253,6 @@ void ItemList::sort_items_by_text() {
}
int ItemList::find_metadata(const Variant &p_metadata) const {
-
for (int i = 0; i < items.size(); i++) {
if (items[i].metadata == p_metadata) {
return i;
@@ -1341,22 +1263,18 @@ int ItemList::find_metadata(const Variant &p_metadata) const {
}
void ItemList::set_allow_rmb_select(bool p_allow) {
-
allow_rmb_select = p_allow;
}
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;
}
@@ -1383,20 +1301,19 @@ Vector<int> ItemList::get_selected_items() {
bool ItemList::is_anything_selected() {
for (int i = 0; i < items.size(); i++) {
- if (items[i].selected)
+ if (items[i].selected) {
return true;
+ }
}
return false;
}
void ItemList::_set_items(const Array &p_items) {
-
ERR_FAIL_COND(p_items.size() % 3);
clear();
for (int i = 0; i < p_items.size(); i += 3) {
-
String text = p_items[i + 0];
Ref<Texture2D> icon = p_items[i + 1];
bool disabled = p_items[i + 2];
@@ -1408,10 +1325,8 @@ void ItemList::_set_items(const Array &p_items) {
}
Array ItemList::_get_items() const {
-
Array items;
for (int i = 0; i < get_item_count(); i++) {
-
items.push_back(get_item_text(i));
items.push_back(get_item_icon(i));
items.push_back(is_item_disabled(i));
@@ -1421,7 +1336,6 @@ Array ItemList::_get_items() const {
}
Size2 ItemList::get_minimum_size() const {
-
if (auto_height) {
return Size2(0, auto_height_value);
}
@@ -1429,24 +1343,20 @@ Size2 ItemList::get_minimum_size() const {
}
void ItemList::set_autoscroll_to_bottom(const bool p_enable) {
-
do_autoscroll_to_bottom = p_enable;
}
void ItemList::set_auto_height(bool p_enable) {
-
auto_height = p_enable;
shape_changed = true;
update();
}
bool ItemList::has_auto_height() const {
-
return auto_height;
}
void ItemList::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("add_item", "text", "icon", "selectable"), &ItemList::add_item, DEFVAL(Variant()), DEFVAL(true));
ClassDB::bind_method(D_METHOD("add_icon_item", "icon", "selectable"), &ItemList::add_icon_item, DEFVAL(true));
@@ -1581,7 +1491,6 @@ void ItemList::_bind_methods() {
}
ItemList::ItemList() {
-
current = -1;
select_mode = SELECT_SINGLE;
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index da9851dd7d..4cdef40184 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -35,7 +35,6 @@
#include "scene/gui/scroll_bar.h"
class ItemList : public Control {
-
GDCLASS(ItemList, Control);
public:
@@ -51,7 +50,6 @@ public:
private:
struct Item {
-
Ref<Texture2D> icon;
bool icon_transposed;
Rect2i icon_region;
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index ef1bb958f6..f49acc1b96 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -29,12 +29,12 @@
/*************************************************************************/
#include "label.h"
+
#include "core/print_string.h"
#include "core/project_settings.h"
#include "core/translation.h"
void Label::set_autowrap(bool p_autowrap) {
-
if (autowrap == p_autowrap) {
return;
}
@@ -47,34 +47,31 @@ void Label::set_autowrap(bool p_autowrap) {
minimum_size_changed();
}
}
-bool Label::has_autowrap() const {
+bool Label::has_autowrap() const {
return autowrap;
}
void Label::set_uppercase(bool p_uppercase) {
-
uppercase = p_uppercase;
word_cache_dirty = true;
update();
}
-bool Label::is_uppercase() const {
+bool Label::is_uppercase() const {
return uppercase;
}
int Label::get_line_height() const {
-
return get_theme_font("font")->get_height();
}
void Label::_notification(int p_what) {
-
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
-
String new_text = tr(text);
- if (new_text == xl_text)
+ if (new_text == xl_text) {
return; //nothing new
+ }
xl_text = new_text;
regenerate_word_cache();
@@ -82,13 +79,13 @@ void Label::_notification(int p_what) {
}
if (p_what == NOTIFICATION_DRAW) {
-
if (clip) {
- VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
+ RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
}
- if (word_cache_dirty)
+ if (word_cache_dirty) {
regenerate_word_cache();
+ }
RID ci = get_canvas_item();
@@ -105,7 +102,7 @@ void Label::_notification(int p_what) {
style->draw(ci, Rect2(Point2(0, 0), get_size()));
- VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint());
+ RenderingServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(), font.is_valid() && font->is_distance_field_hint());
int font_h = font->get_height() + line_spacing;
@@ -125,9 +122,7 @@ void Label::_notification(int p_what) {
}
if (lines_visible > 0) {
-
switch (valign) {
-
case VALIGN_TOP: {
//nothing
} break;
@@ -154,22 +149,25 @@ void Label::_notification(int p_what) {
}
WordCache *wc = word_cache;
- if (!wc)
+ if (!wc) {
return;
+ }
int line = 0;
int line_to = lines_skipped + (lines_visible > 0 ? lines_visible : 1);
FontDrawer drawer(font, font_outline_modulate);
while (wc) {
/* handle lines not meant to be drawn quickly */
- if (line >= line_to)
+ if (line >= line_to) {
break;
+ }
if (line < lines_skipped) {
-
- while (wc && wc->char_pos >= 0)
+ while (wc && wc->char_pos >= 0) {
wc = wc->next;
- if (wc)
+ }
+ if (wc) {
wc = wc->next;
+ }
line++;
continue;
}
@@ -189,7 +187,6 @@ void Label::_notification(int p_what) {
int taken = 0;
int spaces = 0;
while (to && to->char_pos >= 0) {
-
taken += to->pixel_width;
if (to != from && to->space_count) {
spaces += to->space_count;
@@ -202,18 +199,14 @@ void Label::_notification(int p_what) {
float x_ofs = 0;
switch (align) {
-
case ALIGN_FILL:
case ALIGN_LEFT: {
-
x_ofs = style->get_offset().x;
} break;
case ALIGN_CENTER: {
-
x_ofs = int(size.width - (taken + spaces * space_w)) / 2;
} break;
case ALIGN_RIGHT: {
-
x_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (taken + spaces * space_w));
} break;
}
@@ -223,11 +216,9 @@ void Label::_notification(int p_what) {
y_ofs += vbegin + line * vsep;
while (from != to) {
-
// draw a word
int pos = from->char_pos;
if (from->char_pos < 0) {
-
ERR_PRINT("BUG");
return;
}
@@ -235,17 +226,14 @@ void Label::_notification(int p_what) {
/* spacing */
x_ofs += space_w * from->space_count;
if (can_fill && align == ALIGN_FILL && spaces) {
-
x_ofs += int((size.width - (taken + space_w * spaces)) / spaces);
}
}
if (font_color_shadow.a > 0) {
-
int chars_total_shadow = chars_total; //save chars drawn
float x_ofs_shadow = x_ofs;
for (int i = 0; i < from->word_len; i++) {
-
if (visible_chars < 0 || chars_total_shadow < visible_chars) {
CharType c = xl_text[i + pos];
CharType n = xl_text[i + pos + 1];
@@ -266,7 +254,6 @@ void Label::_notification(int p_what) {
}
}
for (int i = 0; i < from->word_len; i++) {
-
if (visible_chars < 0 || chars_total < visible_chars) {
CharType c = xl_text[i + pos];
CharType n = xl_text[i + pos + 1];
@@ -282,24 +269,21 @@ void Label::_notification(int p_what) {
from = from->next;
}
- wc = to ? to->next : 0;
+ wc = to ? to->next : nullptr;
line++;
}
}
if (p_what == NOTIFICATION_THEME_CHANGED) {
-
word_cache_dirty = true;
update();
}
if (p_what == NOTIFICATION_RESIZED) {
-
word_cache_dirty = true;
}
}
Size2 Label::get_minimum_size() const {
-
Size2 min_style = get_theme_stylebox("normal")->get_minimum_size();
// don't want to mutable everything
@@ -307,79 +291,78 @@ Size2 Label::get_minimum_size() const {
const_cast<Label *>(this)->regenerate_word_cache();
}
- if (autowrap)
+ if (autowrap) {
return Size2(1, clip ? 1 : minsize.height) + min_style;
- else {
+ } else {
Size2 ms = minsize;
- if (clip)
+ if (clip) {
ms.width = 1;
+ }
return ms + min_style;
}
}
int Label::get_longest_line_width() const {
-
Ref<Font> font = get_theme_font("font");
real_t max_line_width = 0;
real_t line_width = 0;
for (int i = 0; i < xl_text.size(); i++) {
-
CharType current = xl_text[i];
- if (uppercase)
+ if (uppercase) {
current = String::char_uppercase(current);
+ }
if (current < 32) {
-
if (current == '\n') {
-
- if (line_width > max_line_width)
+ if (line_width > max_line_width) {
max_line_width = line_width;
+ }
line_width = 0;
}
} else {
-
real_t char_width = font->get_char_size(current, xl_text[i + 1]).width;
line_width += char_width;
}
}
- if (line_width > max_line_width)
+ if (line_width > max_line_width) {
max_line_width = line_width;
+ }
// ceiling to ensure autowrapping does not cut text
return Math::ceil(max_line_width);
}
int Label::get_line_count() const {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return 1;
- if (word_cache_dirty)
+ }
+ if (word_cache_dirty) {
const_cast<Label *>(this)->regenerate_word_cache();
+ }
return line_count;
}
int Label::get_visible_line_count() const {
-
int line_spacing = get_theme_constant("line_spacing");
int font_h = get_theme_font("font")->get_height() + line_spacing;
int lines_visible = (get_size().height - get_theme_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h;
- if (lines_visible > line_count)
+ if (lines_visible > line_count) {
lines_visible = line_count;
+ }
- if (max_lines_visible >= 0 && lines_visible > max_lines_visible)
+ if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
lines_visible = max_lines_visible;
+ }
return lines_visible;
}
void Label::regenerate_word_cache() {
-
while (word_cache) {
-
WordCache *current = word_cache;
word_cache = current->next;
memdelete(current);
@@ -404,14 +387,14 @@ void Label::regenerate_word_cache() {
line_count = 1;
total_char_cache = 0;
- WordCache *last = NULL;
+ WordCache *last = nullptr;
for (int i = 0; i <= xl_text.length(); i++) {
-
CharType current = i < xl_text.length() ? xl_text[i] : L' '; //always a space at the end, so the algo works
- if (uppercase)
+ if (uppercase) {
current = String::char_uppercase(current);
+ }
// ranges taken from http://www.unicodemap.org/
// if your language is not well supported, consider helping improve
@@ -422,7 +405,6 @@ void Label::regenerate_word_cache() {
real_t char_width = 0;
if (current < 33) {
-
if (current_word_size > 0) {
WordCache *wc = memnew(WordCache);
if (word_cache) {
@@ -447,7 +429,7 @@ void Label::regenerate_word_cache() {
}
if (i < xl_text.length() && xl_text[i] == ' ') {
- if (line_width > 0 || last == NULL || last->char_pos != WordCache::CHAR_WRAPLINE) {
+ if (line_width > 0 || last == nullptr || last->char_pos != WordCache::CHAR_WRAPLINE) {
space_count++;
line_width += space_width;
} else {
@@ -508,8 +490,9 @@ void Label::regenerate_word_cache() {
}
}
- if (!autowrap)
+ if (!autowrap) {
minsize.width = width;
+ }
if (max_lines_visible > 0 && line_count > max_lines_visible) {
minsize.height = (font->get_height() * max_lines_visible) + (line_spacing * (max_lines_visible - 1));
@@ -525,60 +508,53 @@ void Label::regenerate_word_cache() {
}
void Label::set_align(Align p_align) {
-
ERR_FAIL_INDEX((int)p_align, 4);
align = p_align;
update();
}
Label::Align Label::get_align() const {
-
return align;
}
void Label::set_valign(VAlign p_align) {
-
ERR_FAIL_INDEX((int)p_align, 4);
valign = p_align;
update();
}
Label::VAlign Label::get_valign() const {
-
return valign;
}
void Label::set_text(const String &p_string) {
-
- if (text == p_string)
+ if (text == p_string) {
return;
+ }
text = p_string;
xl_text = tr(p_string);
word_cache_dirty = true;
- if (percent_visible < 1)
+ if (percent_visible < 1) {
visible_chars = get_total_character_count() * percent_visible;
+ }
update();
}
void Label::set_clip_text(bool p_clip) {
-
clip = p_clip;
update();
minimum_size_changed();
}
bool Label::is_clipping_text() const {
-
return clip;
}
String Label::get_text() const {
-
return text;
}
void Label::set_visible_characters(int p_amount) {
-
visible_chars = p_amount;
if (get_total_character_count() > 0) {
percent_visible = (float)p_amount / (float)total_char_cache;
@@ -588,19 +564,15 @@ void Label::set_visible_characters(int p_amount) {
}
int Label::get_visible_characters() const {
-
return visible_chars;
}
void Label::set_percent_visible(float p_percent) {
-
if (p_percent < 0 || p_percent >= 1) {
-
visible_chars = -1;
percent_visible = 1;
} else {
-
visible_chars = get_total_character_count() * p_percent;
percent_visible = p_percent;
}
@@ -609,42 +581,36 @@ void Label::set_percent_visible(float p_percent) {
}
float Label::get_percent_visible() const {
-
return percent_visible;
}
void Label::set_lines_skipped(int p_lines) {
-
lines_skipped = p_lines;
update();
}
int Label::get_lines_skipped() const {
-
return lines_skipped;
}
void Label::set_max_lines_visible(int p_lines) {
-
max_lines_visible = p_lines;
update();
}
int Label::get_max_lines_visible() const {
-
return max_lines_visible;
}
int Label::get_total_character_count() const {
-
- if (word_cache_dirty)
+ if (word_cache_dirty) {
const_cast<Label *>(this)->regenerate_word_cache();
+ }
return total_char_cache;
}
void Label::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_align", "align"), &Label::set_align);
ClassDB::bind_method(D_METHOD("get_align"), &Label::get_align);
ClassDB::bind_method(D_METHOD("set_valign", "valign"), &Label::set_valign);
@@ -693,31 +659,13 @@ void Label::_bind_methods() {
}
Label::Label(const String &p_text) {
-
- align = ALIGN_LEFT;
- valign = VALIGN_TOP;
- xl_text = "";
- word_cache = NULL;
- word_cache_dirty = true;
- autowrap = false;
- line_count = 0;
- set_v_size_flags(0);
- clip = false;
set_mouse_filter(MOUSE_FILTER_IGNORE);
- total_char_cache = 0;
- visible_chars = -1;
- percent_visible = 1;
- lines_skipped = 0;
- max_lines_visible = -1;
set_text(p_text);
- uppercase = false;
set_v_size_flags(SIZE_SHRINK_CENTER);
}
Label::~Label() {
-
while (word_cache) {
-
WordCache *current = word_cache;
word_cache = current->next;
memdelete(current);
diff --git a/scene/gui/label.h b/scene/gui/label.h
index ba6e627c58..670db69dce 100644
--- a/scene/gui/label.h
+++ b/scene/gui/label.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class Label : public Control {
-
GDCLASS(Label, Control);
public:
@@ -55,48 +54,40 @@ public:
};
private:
- Align align;
- VAlign valign;
+ Align align = ALIGN_LEFT;
+ VAlign valign = VALIGN_TOP;
String text;
String xl_text;
- bool autowrap;
- bool clip;
+ bool autowrap = false;
+ bool clip = false;
Size2 minsize;
- int line_count;
- bool uppercase;
+ int line_count = 0;
+ bool uppercase = false;
int get_longest_line_width() const;
struct WordCache {
-
enum {
CHAR_NEWLINE = -1,
CHAR_WRAPLINE = -2
};
- int char_pos; // if -1, then newline
- int word_len;
- int pixel_width;
- int space_count;
- WordCache *next;
- WordCache() {
- char_pos = 0;
- word_len = 0;
- pixel_width = 0;
- next = 0;
- space_count = 0;
- }
+ int char_pos = 0; // if -1, then newline
+ int word_len = 0;
+ int pixel_width = 0;
+ int space_count = 0;
+ WordCache *next = nullptr;
};
- bool word_cache_dirty;
+ bool word_cache_dirty = true;
void regenerate_word_cache();
- float percent_visible;
+ float percent_visible = 1;
- WordCache *word_cache;
- int total_char_cache;
- int visible_chars;
- int lines_skipped;
- int max_lines_visible;
+ WordCache *word_cache = nullptr;
+ int total_char_cache = 0;
+ int visible_chars = -1;
+ int lines_skipped = 0;
+ int max_lines_visible = -1;
protected:
void _notification(int p_what);
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 734e27b1b6..ee6783167a 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -43,16 +43,13 @@
#endif
#include "scene/main/window.h"
static bool _is_text_char(CharType c) {
-
return !is_symbol(c);
}
void LineEdit::_gui_input(Ref<InputEvent> p_event) {
-
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
-
if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) {
menu->set_position(get_global_transform().xform(get_local_mouse_position()));
menu->set_size(Vector2(1, 1));
@@ -63,12 +60,12 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
return;
}
- if (b->get_button_index() != BUTTON_LEFT)
+ if (b->get_button_index() != BUTTON_LEFT) {
return;
+ }
_reset_caret_blink_timer();
if (b->is_pressed()) {
-
accept_event(); //don't pass event further when clicked on text field
if (!text.empty() && is_editable() && _is_over_clear_button(b->get_position())) {
clear_button_status.press_attempt = true;
@@ -81,14 +78,11 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
set_cursor_at_pixel_pos(b->get_position().x);
if (b->get_shift()) {
-
selection_fill_at_cursor();
selection.creating = true;
} else {
-
if (b->is_doubleclick() && selecting_enabled) {
-
selection.enabled = true;
selection.begin = 0;
selection.end = text.length();
@@ -98,12 +92,10 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
selection.drag_attempt = false;
if ((cursor_pos < selection.begin) || (cursor_pos > selection.end) || !selection.enabled) {
-
deselect();
selection.cursor_start = cursor_pos;
selection.creating = true;
} else if (selection.enabled) {
-
selection.drag_attempt = true;
}
}
@@ -111,7 +103,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
update();
} else {
-
if (!text.empty() && is_editable() && clear_button_enabled) {
bool press_attempt = clear_button_status.press_attempt;
clear_button_status.press_attempt = false;
@@ -127,8 +118,13 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
selection.creating = false;
selection.doubleclick = false;
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
- DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length);
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
+ if (selection.enabled) {
+ DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length, selection.begin, selection.end);
+ } else {
+ DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length, cursor_pos);
+ }
+ }
}
update();
@@ -137,7 +133,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
-
if (!text.empty() && is_editable() && clear_button_enabled) {
bool last_press_inside = clear_button_status.pressing_inside;
clear_button_status.pressing_inside = clear_button_status.press_attempt && _is_over_clear_button(m->get_position());
@@ -147,7 +142,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
}
if (m->get_button_mask() & BUTTON_LEFT) {
-
if (selection.creating) {
set_cursor_at_pixel_pos(m->get_position().x);
selection_fill_at_cursor();
@@ -158,9 +152,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
-
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_control() && !k->get_shift() && !k->get_alt() && !k->get_command()) {
@@ -202,11 +196,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
unsigned int code = k->get_keycode();
if (k->get_command() && is_shortcut_keys_enabled()) {
-
bool handled = true;
switch (code) {
-
case (KEY_X): { // CUT.
if (editable) {
@@ -224,7 +216,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case (KEY_V): { // PASTE.
if (editable) {
-
paste_text();
}
@@ -243,7 +234,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case (KEY_U): { // Delete from start to cursor.
if (editable) {
-
deselect();
text = text.substr(cursor_pos, text.length() - cursor_pos);
update_cached_width();
@@ -256,7 +246,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case (KEY_Y): { // PASTE (Yank for unix users).
if (editable) {
-
paste_text();
}
@@ -264,7 +253,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case (KEY_K): { // Delete from cursor_pos to end.
if (editable) {
-
deselect();
text = text.substr(0, cursor_pos);
_text_changed();
@@ -277,10 +265,14 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
#ifdef APPLE_STYLE_KEYS
case (KEY_LEFT): { // Go to start of text - like HOME key.
+ shift_selection_check_pre(k->get_shift());
set_cursor_position(0);
+ shift_selection_check_post(k->get_shift());
} break;
case (KEY_RIGHT): { // Go to end of text - like END key.
+ shift_selection_check_pre(k->get_shift());
set_cursor_position(text.length());
+ shift_selection_check_post(k->get_shift());
} break;
#endif
default: {
@@ -296,23 +288,21 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
_reset_caret_blink_timer();
if (!k->get_metakey()) {
-
bool handled = true;
switch (code) {
-
case KEY_KP_ENTER:
case KEY_ENTER: {
-
emit_signal("text_entered", text);
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case KEY_BACKSPACE: {
-
- if (!editable)
+ if (!editable) {
break;
+ }
if (selection.enabled) {
selection_delete();
@@ -333,8 +323,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc > 0) {
bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -376,7 +367,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if (k->get_command()) {
set_cursor_position(0);
} else if (k->get_alt()) {
-
#else
if (k->get_alt()) {
handled = false;
@@ -389,8 +379,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc > 0) {
bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -444,8 +435,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
while (cc < text.length()) {
bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
@@ -461,23 +453,25 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_UP: {
-
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == 0) handled = false;
+ if (get_cursor_position() == 0) {
+ handled = false;
+ }
set_cursor_position(0);
shift_selection_check_post(k->get_shift());
} break;
case KEY_DOWN: {
-
shift_selection_check_pre(k->get_shift());
- if (get_cursor_position() == text.length()) handled = false;
+ if (get_cursor_position() == text.length()) {
+ handled = false;
+ }
set_cursor_position(text.length());
shift_selection_check_post(k->get_shift());
} break;
case KEY_DELETE: {
-
- if (!editable)
+ if (!editable) {
break;
+ }
if (k->get_shift() && !k->get_command() && !k->get_alt()) {
cut_text();
@@ -491,8 +485,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
int text_len = text.length();
- if (cursor_pos == text_len)
+ if (cursor_pos == text_len) {
break; // Nothing to do.
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_alt()) {
@@ -507,11 +502,11 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
bool prev_char = false;
while (cc < text.length()) {
-
bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
}
@@ -532,7 +527,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
[[fallthrough]];
}
case KEY_HOME: {
-
shift_selection_check_pre(k->get_shift());
set_cursor_position(0);
shift_selection_check_post(k->get_shift());
@@ -545,7 +539,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
[[fallthrough]];
}
case KEY_END: {
-
shift_selection_check_pre(k->get_shift());
set_cursor_position(text.length());
shift_selection_check_post(k->get_shift());
@@ -562,7 +555,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
default: {
-
handled = false;
} break;
}
@@ -571,7 +563,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
accept_event();
} else if (!k->get_command()) {
if (k->get_unicode() >= 32 && k->get_keycode() != KEY_DELETE) {
-
if (editable) {
selection_delete();
CharType ucodestr[2] = { (CharType)k->get_unicode(), 0 };
@@ -596,19 +587,16 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
}
void LineEdit::set_align(Align p_align) {
-
ERR_FAIL_INDEX((int)p_align, 4);
align = p_align;
update();
}
LineEdit::Align LineEdit::get_align() const {
-
return align;
}
Variant LineEdit::get_drag_data(const Point2 &p_point) {
-
if (selection.drag_attempt && selection.enabled) {
String t = text.substr(selection.begin, selection.end - selection.begin);
Label *l = memnew(Label);
@@ -619,20 +607,21 @@ Variant LineEdit::get_drag_data(const Point2 &p_point) {
return Variant();
}
-bool LineEdit::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
+bool LineEdit::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
return p_data.get_type() == Variant::STRING;
}
-void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
+void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
if (p_data.get_type() == Variant::STRING) {
set_cursor_at_pixel_pos(p_point.x);
int selected = selection.end - selection.begin;
Ref<Font> font = get_theme_font("font");
- if (font != NULL) {
- for (int i = selection.begin; i < selection.end; i++)
+ if (font != nullptr) {
+ for (int i = selection.begin; i < selection.end; i++) {
cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;
+ }
}
text.erase(selection.begin, selected);
@@ -660,7 +649,6 @@ bool LineEdit::_is_over_clear_button(const Point2 &p_pos) const {
}
void LineEdit::_notification(int p_what) {
-
switch (p_what) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_ENTER_TREE: {
@@ -675,7 +663,6 @@ void LineEdit::_notification(int p_what) {
} break;
#endif
case NOTIFICATION_RESIZED: {
-
window_pos = 0;
set_cursor_position(get_cursor_position());
@@ -696,7 +683,6 @@ void LineEdit::_notification(int p_what) {
update();
} break;
case NOTIFICATION_DRAW: {
-
if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
draw_caret = false;
}
@@ -720,7 +706,6 @@ void LineEdit::_notification(int p_what) {
style->draw(ci, Rect2(Point2(), size));
if (has_focus()) {
-
get_theme_stylebox("focus")->draw(ci, Rect2(Point2(), size));
}
@@ -729,21 +714,18 @@ void LineEdit::_notification(int p_what) {
int cached_text_width = using_placeholder ? cached_placeholder_width : cached_width;
switch (align) {
-
case ALIGN_FILL:
case ALIGN_LEFT: {
-
x_ofs = style->get_offset().x;
} break;
case ALIGN_CENTER: {
-
- if (window_pos != 0)
+ if (window_pos != 0) {
x_ofs = style->get_offset().x;
- else
+ } else {
x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - (cached_text_width)) / 2);
+ }
} break;
case ALIGN_RIGHT: {
-
x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_text_width)));
} break;
}
@@ -763,8 +745,9 @@ void LineEdit::_notification(int p_what) {
const String &t = using_placeholder ? placeholder_translated : text;
// Draw placeholder color.
- if (using_placeholder)
+ if (using_placeholder) {
font_color.a *= placeholder_alpha;
+ }
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) {
@@ -794,30 +777,32 @@ void LineEdit::_notification(int p_what) {
int caret_height = font->get_height() > y_area ? y_area : font->get_height();
FontDrawer drawer(font, Color(1, 1, 1));
while (true) {
-
// End of string, break.
- if (char_ofs >= t.length())
+ if (char_ofs >= t.length()) {
break;
+ }
if (char_ofs == cursor_pos) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs];
CharType next = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs + 1];
int im_char_width = font->get_char_size(cchar, next).width;
- if ((x_ofs + im_char_width) > ofs_max)
+ if ((x_ofs + im_char_width) > ofs_max) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color);
} else {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color);
}
drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color);
@@ -833,13 +818,15 @@ void LineEdit::_notification(int p_what) {
int char_width = font->get_char_size(cchar, next).width;
// End of widget, break.
- if ((x_ofs + char_width) > ofs_max)
+ if ((x_ofs + char_width) > ofs_max) {
break;
+ }
bool selected = selection.enabled && char_ofs >= selection.begin && char_ofs < selection.end;
- if (selected)
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);
+ if (selected) {
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);
+ }
int yofs = y_ofs + (caret_height - font->get_height()) / 2;
drawer.draw_char(ci, Point2(x_ofs, yofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);
@@ -847,9 +834,9 @@ void LineEdit::_notification(int p_what) {
if (char_ofs == cursor_pos && draw_caret && !using_placeholder) {
if (ime_text.length() == 0) {
#ifdef TOOLS_ENABLED
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color);
#else
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(1, caret_height)), cursor_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(1, caret_height)), cursor_color);
#endif
}
}
@@ -862,21 +849,23 @@ void LineEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs];
CharType next = (pass && !text.empty()) ? secret_character[0] : ime_text[ofs + 1];
int im_char_width = font->get_char_size(cchar, next).width;
- if ((x_ofs + im_char_width) > ofs_max)
+ if ((x_ofs + im_char_width) > ofs_max) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 3)), font_color);
} else {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color);
}
drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color);
@@ -905,9 +894,9 @@ void LineEdit::_notification(int p_what) {
}
}
#ifdef TOOLS_ENABLED
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(Math::round(EDSCALE), caret_height)), cursor_color);
#else
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(1, caret_height)), cursor_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(caret_x_ofs, y_ofs), Size2(1, caret_height)), cursor_color);
#endif
}
}
@@ -920,7 +909,6 @@ void LineEdit::_notification(int p_what) {
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
-
if (caret_blink_enabled) {
caret_blink_timer->start();
} else {
@@ -933,12 +921,16 @@ void LineEdit::_notification(int p_what) {
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id());
}
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
- DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length);
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
+ if (selection.enabled) {
+ DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length, selection.begin, selection.end);
+ } else {
+ DisplayServer::get_singleton()->virtual_keyboard_show(text, get_global_rect(), max_length, cursor_pos);
+ }
+ }
} break;
case NOTIFICATION_FOCUS_EXIT: {
-
if (caret_blink_enabled) {
caret_blink_timer->stop();
}
@@ -950,12 +942,12 @@ void LineEdit::_notification(int p_what) {
ime_text = "";
ime_selection = Point2();
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
-
if (has_focus()) {
ime_text = DisplayServer::get_singleton()->ime_get_text();
ime_selection = DisplayServer::get_singleton()->ime_get_selection();
@@ -966,14 +958,12 @@ void LineEdit::_notification(int p_what) {
}
void LineEdit::copy_text() {
-
if (selection.enabled && !pass) {
DisplayServer::get_singleton()->clipboard_set(text.substr(selection.begin, selection.end - selection.begin));
}
}
void LineEdit::cut_text() {
-
if (selection.enabled && !pass) {
DisplayServer::get_singleton()->clipboard_set(text.substr(selection.begin, selection.end - selection.begin));
selection_delete();
@@ -981,14 +971,14 @@ void LineEdit::cut_text() {
}
void LineEdit::paste_text() {
-
// Strip escape characters like \n and \t as they can't be displayed on LineEdit.
String paste_buffer = DisplayServer::get_singleton()->clipboard_get().strip_escapes();
if (paste_buffer != "") {
-
int prev_len = text.length();
- if (selection.enabled) selection_delete();
+ if (selection.enabled) {
+ selection_delete();
+ }
append_at_cursor(paste_buffer);
if (!text_changed_dirty) {
@@ -1001,7 +991,7 @@ void LineEdit::paste_text() {
}
void LineEdit::undo() {
- if (undo_stack_pos == NULL) {
+ if (undo_stack_pos == nullptr) {
if (undo_stack.size() <= 1) {
return;
}
@@ -1016,14 +1006,15 @@ void LineEdit::undo() {
window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
}
void LineEdit::redo() {
- if (undo_stack_pos == NULL) {
+ if (undo_stack_pos == nullptr) {
return;
}
if (undo_stack_pos == undo_stack.back()) {
@@ -1036,29 +1027,29 @@ void LineEdit::redo() {
window_pos = op.window_pos;
set_cursor_position(op.cursor_pos);
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
}
void LineEdit::shift_selection_check_pre(bool p_shift) {
-
if (!selection.enabled && p_shift) {
selection.cursor_start = cursor_pos;
}
- if (!p_shift)
+ if (!p_shift) {
deselect();
+ }
}
void LineEdit::shift_selection_check_post(bool p_shift) {
-
- if (p_shift)
+ if (p_shift) {
selection_fill_at_cursor();
+ }
}
void LineEdit::set_cursor_at_pixel_pos(int p_x) {
-
Ref<Font> font = get_theme_font("font");
int ofs = window_pos;
Ref<StyleBox> style = get_theme_stylebox("normal");
@@ -1068,35 +1059,33 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
int r_icon_width = Control::get_theme_icon("clear")->get_width();
switch (align) {
-
case ALIGN_FILL:
case ALIGN_LEFT: {
-
pixel_ofs = int(style->get_offset().x);
} break;
case ALIGN_CENTER: {
-
- if (window_pos != 0)
+ if (window_pos != 0) {
pixel_ofs = int(style->get_offset().x);
- else
+ } else {
pixel_ofs = int(size.width - (cached_width)) / 2;
+ }
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
+ }
} break;
case ALIGN_RIGHT: {
-
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
+ }
} break;
}
while (ofs < text.length()) {
-
int char_w = 0;
- if (font != NULL) {
+ if (font != nullptr) {
char_w = font->get_char_size(pass ? secret_character[0] : text[ofs]).width;
}
pixel_ofs += char_w;
@@ -1112,7 +1101,6 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
}
int LineEdit::get_cursor_pixel_pos() {
-
Ref<Font> font = get_theme_font("font");
int ofs = window_pos;
Ref<StyleBox> style = get_theme_stylebox("normal");
@@ -1122,33 +1110,32 @@ int LineEdit::get_cursor_pixel_pos() {
int r_icon_width = Control::get_theme_icon("clear")->get_width();
switch (align) {
-
case ALIGN_FILL:
case ALIGN_LEFT: {
-
pixel_ofs = int(style->get_offset().x);
} break;
case ALIGN_CENTER: {
-
- if (window_pos != 0)
+ if (window_pos != 0) {
pixel_ofs = int(style->get_offset().x);
- else
+ } else {
pixel_ofs = int(size.width - (cached_width)) / 2;
+ }
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
+ }
} break;
case ALIGN_RIGHT: {
-
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
- if (display_clear_icon)
+ if (display_clear_icon) {
pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
+ }
} break;
}
while (ofs < cursor_pos) {
- if (font != NULL) {
+ if (font != nullptr) {
pixel_ofs += font->get_char_size(pass ? secret_character[0] : text[ofs]).width;
}
ofs++;
@@ -1203,11 +1190,12 @@ void LineEdit::_toggle_draw_caret() {
}
void LineEdit::delete_char() {
-
- if ((text.length() <= 0) || (cursor_pos == 0)) return;
+ if ((text.length() <= 0) || (cursor_pos == 0)) {
+ return;
+ }
Ref<Font> font = get_theme_font("font");
- if (font != NULL) {
+ if (font != nullptr) {
cached_width -= font->get_char_size(pass ? secret_character[0] : text[cursor_pos - 1]).width;
}
@@ -1223,12 +1211,14 @@ void LineEdit::delete_char() {
}
void LineEdit::delete_text(int p_from_column, int p_to_column) {
-
+ ERR_FAIL_COND_MSG(p_from_column < 0 || p_from_column > p_to_column || p_to_column > text.length(),
+ vformat("Positional parameters (from: %d, to: %d) are inverted or outside the text length (%d).", p_from_column, p_to_column, text.length()));
if (text.size() > 0) {
Ref<Font> font = get_theme_font("font");
- if (font != NULL) {
- for (int i = p_from_column; i < p_to_column; i++)
+ if (font != nullptr) {
+ for (int i = p_from_column; i < p_to_column; i++) {
cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;
+ }
}
} else {
cached_width = 0;
@@ -1238,11 +1228,9 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
cursor_pos -= CLAMP(cursor_pos - p_from_column, 0, p_to_column - p_from_column);
if (cursor_pos >= text.length()) {
-
cursor_pos = text.length();
}
if (window_pos > cursor_pos) {
-
window_pos = cursor_pos;
}
@@ -1259,7 +1247,6 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {
}
void LineEdit::set_text(String p_text) {
-
clear_internal();
append_at_cursor(p_text);
@@ -1273,18 +1260,15 @@ void LineEdit::set_text(String p_text) {
}
void LineEdit::clear() {
-
clear_internal();
_text_changed();
}
String LineEdit::get_text() const {
-
return text;
}
void LineEdit::set_placeholder(String p_text) {
-
placeholder = p_text;
placeholder_translated = tr(placeholder);
update_placeholder_width();
@@ -1292,33 +1276,30 @@ void LineEdit::set_placeholder(String p_text) {
}
String LineEdit::get_placeholder() const {
-
return placeholder;
}
void LineEdit::set_placeholder_alpha(float p_alpha) {
-
placeholder_alpha = p_alpha;
update();
}
float LineEdit::get_placeholder_alpha() const {
-
return placeholder_alpha;
}
void LineEdit::set_cursor_position(int p_pos) {
-
- if (p_pos > (int)text.length())
+ if (p_pos > (int)text.length()) {
p_pos = text.length();
+ }
- if (p_pos < 0)
+ if (p_pos < 0) {
p_pos = 0;
+ }
cursor_pos = p_pos;
if (!is_inside_tree()) {
-
window_pos = cursor_pos;
return;
}
@@ -1338,16 +1319,15 @@ void LineEdit::set_cursor_position(int p_pos) {
window_width -= r_icon->get_width();
}
- if (window_width < 0)
+ if (window_width < 0) {
return;
+ }
int wp = window_pos;
if (font.is_valid()) {
-
int accum_width = 0;
for (int i = cursor_pos; i >= window_pos; i--) {
-
if (i >= text.length()) {
// Do not do this, because if the cursor is at the end, its just fine that it takes no space.
// accum_width = font->get_char_size(' ').width;
@@ -1358,32 +1338,33 @@ void LineEdit::set_cursor_position(int p_pos) {
accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do.
}
}
- if (accum_width > window_width)
+ if (accum_width > window_width) {
break;
+ }
wp = i;
}
}
- if (wp != window_pos)
+ if (wp != window_pos) {
set_window_pos(wp);
+ }
}
update();
}
int LineEdit::get_cursor_position() const {
-
return cursor_pos;
}
void LineEdit::set_window_pos(int p_pos) {
-
window_pos = p_pos;
- if (window_pos < 0) window_pos = 0;
+ if (window_pos < 0) {
+ window_pos = 0;
+ }
}
void LineEdit::append_at_cursor(String p_text) {
-
if ((max_length <= 0) || (text.length() + p_text.length() <= max_length)) {
String pre = text.substr(0, cursor_pos);
String post = text.substr(cursor_pos, text.length() - cursor_pos);
@@ -1396,7 +1377,6 @@ void LineEdit::append_at_cursor(String p_text) {
}
void LineEdit::clear_internal() {
-
deselect();
_clear_undo_stack();
cached_width = 0;
@@ -1408,7 +1388,6 @@ void LineEdit::clear_internal() {
}
Size2 LineEdit::get_minimum_size() const {
-
Ref<StyleBox> style = get_theme_stylebox("normal");
Ref<Font> font = get_theme_font("font");
@@ -1439,7 +1418,6 @@ Size2 LineEdit::get_minimum_size() const {
}
void LineEdit::deselect() {
-
selection.begin = 0;
selection.end = 0;
selection.cursor_start = 0;
@@ -1450,28 +1428,27 @@ void LineEdit::deselect() {
}
void LineEdit::selection_delete() {
-
- if (selection.enabled)
+ if (selection.enabled) {
delete_text(selection.begin, selection.end);
+ }
deselect();
}
void LineEdit::set_max_length(int p_max_length) {
-
ERR_FAIL_COND(p_max_length < 0);
max_length = p_max_length;
set_text(text);
}
int LineEdit::get_max_length() const {
-
return max_length;
}
void LineEdit::selection_fill_at_cursor() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
selection.begin = cursor_pos;
selection.end = selection.cursor_start;
@@ -1486,11 +1463,13 @@ void LineEdit::selection_fill_at_cursor() {
}
void LineEdit::select_all() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (!text.length())
+ if (!text.length()) {
return;
+ }
selection.begin = 0;
selection.end = text.length();
@@ -1499,9 +1478,9 @@ void LineEdit::select_all() {
}
void LineEdit::set_editable(bool p_editable) {
-
- if (editable == p_editable)
+ if (editable == p_editable) {
return;
+ }
editable = p_editable;
_generate_context_menu();
@@ -1511,24 +1490,20 @@ void LineEdit::set_editable(bool p_editable) {
}
bool LineEdit::is_editable() const {
-
return editable;
}
void LineEdit::set_secret(bool p_secret) {
-
pass = p_secret;
update_cached_width();
update();
}
bool LineEdit::is_secret() const {
-
return pass;
}
void LineEdit::set_secret_character(const String &p_string) {
-
// An empty string as the secret character would crash the engine.
// It also wouldn't make sense to use multiple characters as the secret character.
ERR_FAIL_COND_MSG(p_string.length() != 1, "Secret character must be exactly one character long (" + itos(p_string.length()) + " characters given).");
@@ -1543,8 +1518,9 @@ String LineEdit::get_secret_character() const {
}
void LineEdit::select(int p_from, int p_to) {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
if (p_from == 0 && p_to == 0) {
deselect();
@@ -1552,15 +1528,19 @@ void LineEdit::select(int p_from, int p_to) {
}
int len = text.length();
- if (p_from < 0)
+ if (p_from < 0) {
p_from = 0;
- if (p_from > len)
+ }
+ if (p_from > len) {
p_from = len;
- if (p_to < 0 || p_to > len)
+ }
+ if (p_to < 0 || p_to > len) {
p_to = len;
+ }
- if (p_from >= p_to)
+ if (p_from >= p_to) {
return;
+ }
selection.enabled = true;
selection.begin = p_from;
@@ -1571,12 +1551,10 @@ void LineEdit::select(int p_from, int p_to) {
}
bool LineEdit::is_text_field() const {
-
return true;
}
void LineEdit::menu_option(int p_option) {
-
switch (p_option) {
case MENU_CUT: {
if (editable) {
@@ -1584,7 +1562,6 @@ void LineEdit::menu_option(int p_option) {
}
} break;
case MENU_COPY: {
-
copy_text();
} break;
case MENU_PASTE: {
@@ -1633,7 +1610,6 @@ void LineEdit::_editor_settings_changed() {
}
void LineEdit::set_expand_to_text_length(bool p_enabled) {
-
expand_to_text_length = p_enabled;
minimum_size_changed();
set_window_pos(0);
@@ -1669,8 +1645,9 @@ bool LineEdit::is_shortcut_keys_enabled() const {
void LineEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = p_enabled;
- if (!selecting_enabled)
+ if (!selecting_enabled) {
deselect();
+ }
_generate_context_menu();
}
@@ -1693,8 +1670,9 @@ Ref<Texture2D> LineEdit::get_right_icon() {
}
void LineEdit::_text_changed() {
- if (expand_to_text_length)
+ if (expand_to_text_length) {
minimum_size_changed();
+ }
_emit_text_change();
_clear_redo();
@@ -1709,7 +1687,7 @@ void LineEdit::_emit_text_change() {
void LineEdit::update_cached_width() {
Ref<Font> font = get_theme_font("font");
cached_width = 0;
- if (font != NULL) {
+ if (font != nullptr) {
String text = get_text();
for (int i = 0; i < text.length(); i++) {
cached_width += font->get_char_size(pass ? secret_character[0] : text[i]).width;
@@ -1720,7 +1698,7 @@ void LineEdit::update_cached_width() {
void LineEdit::update_placeholder_width() {
Ref<Font> font = get_theme_font("font");
cached_placeholder_width = 0;
- if (font != NULL) {
+ if (font != nullptr) {
for (int i = 0; i < placeholder_translated.length(); i++) {
cached_placeholder_width += font->get_char_size(placeholder_translated[i]).width;
}
@@ -1729,7 +1707,7 @@ void LineEdit::update_placeholder_width() {
void LineEdit::_clear_redo() {
_create_undo_state();
- if (undo_stack_pos == NULL) {
+ if (undo_stack_pos == nullptr) {
return;
}
@@ -1744,7 +1722,7 @@ void LineEdit::_clear_redo() {
void LineEdit::_clear_undo_stack() {
undo_stack.clear();
- undo_stack_pos = NULL;
+ undo_stack_pos = nullptr;
_create_undo_state();
}
@@ -1760,14 +1738,17 @@ void LineEdit::_create_undo_state() {
void LineEdit::_generate_context_menu() {
// Reorganize context menu.
menu->clear();
- if (editable)
+ if (editable) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_X : 0);
+ }
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_C : 0);
- if (editable)
+ if (editable) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_V : 0);
+ }
menu->add_separator();
- if (is_selecting_enabled())
+ if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_A : 0);
+ }
if (editable) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
@@ -1777,7 +1758,6 @@ void LineEdit::_generate_context_menu() {
}
void LineEdit::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_text_changed"), &LineEdit::_text_changed);
ClassDB::bind_method(D_METHOD("set_align", "align"), &LineEdit::set_align);
@@ -1805,6 +1785,8 @@ void LineEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_max_length", "chars"), &LineEdit::set_max_length);
ClassDB::bind_method(D_METHOD("get_max_length"), &LineEdit::get_max_length);
ClassDB::bind_method(D_METHOD("append_at_cursor", "text"), &LineEdit::append_at_cursor);
+ ClassDB::bind_method(D_METHOD("delete_char_at_cursor"), &LineEdit::delete_char);
+ ClassDB::bind_method(D_METHOD("delete_text", "from_column", "to_column"), &LineEdit::delete_text);
ClassDB::bind_method(D_METHOD("set_editable", "enabled"), &LineEdit::set_editable);
ClassDB::bind_method(D_METHOD("is_editable"), &LineEdit::is_editable);
ClassDB::bind_method(D_METHOD("set_secret", "enabled"), &LineEdit::set_secret);
@@ -1864,8 +1846,7 @@ void LineEdit::_bind_methods() {
}
LineEdit::LineEdit() {
-
- undo_stack_pos = NULL;
+ undo_stack_pos = nullptr;
_create_undo_state();
align = ALIGN_LEFT;
cached_width = 0;
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index 938974453a..d31a5cb8d8 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -35,7 +35,6 @@
#include "scene/gui/popup_menu.h"
class LineEdit : public Control {
-
GDCLASS(LineEdit, Control);
public:
@@ -94,7 +93,6 @@ private:
Ref<Texture2D> right_icon;
struct Selection {
-
int begin;
int end;
int cursor_start;
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index 3dffa06b49..f8c8bd4caf 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -31,7 +31,6 @@
#include "link_button.h"
void LinkButton::set_text(const String &p_text) {
-
text = p_text;
update();
minimum_size_changed();
@@ -42,58 +41,48 @@ String LinkButton::get_text() const {
}
void LinkButton::set_underline_mode(UnderlineMode p_underline_mode) {
-
underline_mode = p_underline_mode;
update();
}
LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
-
return underline_mode;
}
Size2 LinkButton::get_minimum_size() const {
-
return get_theme_font("font")->get_string_size(text);
}
void LinkButton::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_DRAW: {
-
RID ci = get_canvas_item();
Size2 size = get_size();
Color color;
bool do_underline = false;
switch (get_draw_mode()) {
-
case DRAW_NORMAL: {
-
color = get_theme_color("font_color");
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
} break;
case DRAW_HOVER_PRESSED:
case DRAW_PRESSED: {
-
- if (has_theme_color("font_color_pressed"))
+ if (has_theme_color("font_color_pressed")) {
color = get_theme_color("font_color_pressed");
- else
+ } else {
color = get_theme_color("font_color");
+ }
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
} break;
case DRAW_HOVER: {
-
color = get_theme_color("font_color_hover");
do_underline = underline_mode != UNDERLINE_MODE_NEVER;
} break;
case DRAW_DISABLED: {
-
color = get_theme_color("font_color_disabled");
do_underline = underline_mode == UNDERLINE_MODE_ALWAYS;
@@ -101,7 +90,6 @@ void LinkButton::_notification(int p_what) {
}
if (has_focus()) {
-
Ref<StyleBox> style = get_theme_stylebox("focus");
style->draw(ci, Rect2(Point2(), size));
}
@@ -111,11 +99,11 @@ void LinkButton::_notification(int p_what) {
draw_string(font, Vector2(0, font->get_ascent()), text, color);
if (do_underline) {
- int underline_spacing = get_theme_constant("underline_spacing");
+ int underline_spacing = get_theme_constant("underline_spacing") + font->get_underline_position();
int width = font->get_string_size(text).width;
int y = font->get_ascent() + underline_spacing;
- draw_line(Vector2(0, y), Vector2(width, y), color);
+ draw_line(Vector2(0, y), Vector2(width, y), color, font->get_underline_thickness());
}
} break;
@@ -123,7 +111,6 @@ void LinkButton::_notification(int p_what) {
}
void LinkButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_text", "text"), &LinkButton::set_text);
ClassDB::bind_method(D_METHOD("get_text"), &LinkButton::get_text);
diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h
index 3bef25e249..ee37a29f9d 100644
--- a/scene/gui/link_button.h
+++ b/scene/gui/link_button.h
@@ -35,7 +35,6 @@
#include "scene/resources/bit_map.h"
class LinkButton : public BaseButton {
-
GDCLASS(LinkButton, BaseButton);
public:
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index 1cd4ff4ff8..0299065f77 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -31,7 +31,6 @@
#include "margin_container.h"
Size2 MarginContainer::get_minimum_size() const {
-
int margin_left = get_theme_constant("margin_left");
int margin_top = get_theme_constant("margin_top");
int margin_right = get_theme_constant("margin_right");
@@ -40,20 +39,24 @@ Size2 MarginContainer::get_minimum_size() const {
Size2 max;
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (!c->is_visible())
+ }
+ if (!c->is_visible()) {
continue;
+ }
Size2 s = c->get_combined_minimum_size();
- if (s.width > max.width)
+ if (s.width > max.width) {
max.width = s.width;
- if (s.height > max.height)
+ }
+ if (s.height > max.height) {
max.height = s.height;
+ }
}
max.width += (margin_left + margin_right);
@@ -63,10 +66,8 @@ Size2 MarginContainer::get_minimum_size() const {
}
void MarginContainer::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
-
int margin_left = get_theme_constant("margin_left");
int margin_top = get_theme_constant("margin_top");
int margin_right = get_theme_constant("margin_right");
@@ -75,12 +76,13 @@ void MarginContainer::_notification(int p_what) {
Size2 s = get_size();
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
int w = s.width - margin_left - margin_right;
int h = s.height - margin_top - margin_bottom;
@@ -88,7 +90,6 @@ void MarginContainer::_notification(int p_what) {
}
} break;
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
} break;
}
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index a7d1f64e93..aa69fb39e7 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -34,25 +34,25 @@
#include "scene/main/window.h"
void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
-
- if (disable_shortcuts)
+ if (disable_shortcuts) {
return;
+ }
if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) {
-
- if (!get_parent() || !is_visible_in_tree() || is_disabled())
+ if (!get_parent() || !is_visible_in_tree() || is_disabled()) {
return;
+ }
//bool global_only = (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this));
//if (popup->activate_item_by_event(p_event, global_only))
// accept_event();
- if (popup->activate_item_by_event(p_event, false))
+ if (popup->activate_item_by_event(p_event, false)) {
accept_event();
+ }
}
}
void MenuButton::pressed() {
-
{
Window *w = Object::cast_to<Window>(get_viewport());
if (w && !w->is_embedding_subwindows()) {
@@ -75,39 +75,31 @@ void MenuButton::pressed() {
}
void MenuButton::_gui_input(Ref<InputEvent> p_event) {
-
BaseButton::_gui_input(p_event);
}
PopupMenu *MenuButton::get_popup() const {
-
return popup;
}
void MenuButton::_set_items(const Array &p_items) {
-
popup->set("items", p_items);
}
Array MenuButton::_get_items() const {
-
return popup->get("items");
}
void MenuButton::set_switch_on_hover(bool p_enabled) {
-
switch_on_hover = p_enabled;
}
bool MenuButton::is_switch_on_hover() {
-
return switch_on_hover;
}
void MenuButton::_notification(int p_what) {
-
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
-
if (!is_visible_in_tree()) {
popup->hide();
}
@@ -115,7 +107,6 @@ void MenuButton::_notification(int p_what) {
}
void MenuButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_popup"), &MenuButton::get_popup);
ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &MenuButton::_unhandled_key_input);
ClassDB::bind_method(D_METHOD("_set_items"), &MenuButton::_set_items);
@@ -131,12 +122,10 @@ void MenuButton::_bind_methods() {
}
void MenuButton::set_disable_shortcuts(bool p_disabled) {
-
disable_shortcuts = p_disabled;
}
MenuButton::MenuButton() {
-
switch_on_hover = false;
set_flat(true);
set_toggle_mode(true);
diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h
index 9abd11632f..0cd161c1f0 100644
--- a/scene/gui/menu_button.h
+++ b/scene/gui/menu_button.h
@@ -35,7 +35,6 @@
#include "scene/gui/popup_menu.h"
class MenuButton : public Button {
-
GDCLASS(MenuButton, Button);
bool clicked;
diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp
index 0ef1f53006..bc71ae94f5 100644
--- a/scene/gui/nine_patch_rect.cpp
+++ b/scene/gui/nine_patch_rect.cpp
@@ -30,14 +30,13 @@
#include "nine_patch_rect.h"
-#include "servers/visual_server.h"
+#include "servers/rendering_server.h"
void NinePatchRect::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
- if (texture.is_null())
+ if (texture.is_null()) {
return;
+ }
Rect2 rect = Rect2(Point2(), get_size());
Rect2 src_rect = region_rect;
@@ -45,16 +44,15 @@ void NinePatchRect::_notification(int p_what) {
texture->get_rect_region(rect, src_rect, rect, src_rect);
RID ci = get_canvas_item();
- VS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NinePatchAxisMode(axis_h), VS::NinePatchAxisMode(axis_v), draw_center);
+ RS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center);
}
}
Size2 NinePatchRect::get_minimum_size() const {
-
return Size2(margin[MARGIN_LEFT] + margin[MARGIN_RIGHT], margin[MARGIN_TOP] + margin[MARGIN_BOTTOM]);
}
-void NinePatchRect::_bind_methods() {
+void NinePatchRect::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &NinePatchRect::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &NinePatchRect::get_texture);
ClassDB::bind_method(D_METHOD("set_patch_margin", "margin", "value"), &NinePatchRect::set_patch_margin);
@@ -89,9 +87,9 @@ void NinePatchRect::_bind_methods() {
}
void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) {
-
- if (texture == p_tex)
+ if (texture == p_tex) {
return;
+ }
texture = p_tex;
update();
/*
@@ -104,12 +102,10 @@ void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) {
}
Ref<Texture2D> NinePatchRect::get_texture() const {
-
return texture;
}
void NinePatchRect::set_patch_margin(Margin p_margin, int p_size) {
-
ERR_FAIL_INDEX((int)p_margin, 4);
margin[p_margin] = p_size;
update();
@@ -131,15 +127,14 @@ void NinePatchRect::set_patch_margin(Margin p_margin, int p_size) {
}
int NinePatchRect::get_patch_margin(Margin p_margin) const {
-
ERR_FAIL_INDEX_V((int)p_margin, 4, 0);
return margin[p_margin];
}
void NinePatchRect::set_region_rect(const Rect2 &p_region_rect) {
-
- if (region_rect == p_region_rect)
+ if (region_rect == p_region_rect) {
return;
+ }
region_rect = p_region_rect;
@@ -148,18 +143,15 @@ void NinePatchRect::set_region_rect(const Rect2 &p_region_rect) {
}
Rect2 NinePatchRect::get_region_rect() const {
-
return region_rect;
}
void NinePatchRect::set_draw_center(bool p_enabled) {
-
draw_center = p_enabled;
update();
}
bool NinePatchRect::is_draw_center_enabled() const {
-
return draw_center;
}
@@ -173,18 +165,15 @@ NinePatchRect::AxisStretchMode NinePatchRect::get_h_axis_stretch_mode() const {
}
void NinePatchRect::set_v_axis_stretch_mode(AxisStretchMode p_mode) {
-
axis_v = p_mode;
update();
}
NinePatchRect::AxisStretchMode NinePatchRect::get_v_axis_stretch_mode() const {
-
return axis_v;
}
NinePatchRect::NinePatchRect() {
-
margin[MARGIN_LEFT] = 0;
margin[MARGIN_RIGHT] = 0;
margin[MARGIN_BOTTOM] = 0;
diff --git a/scene/gui/nine_patch_rect.h b/scene/gui/nine_patch_rect.h
index 0ef7f6b299..23a40fb64b 100644
--- a/scene/gui/nine_patch_rect.h
+++ b/scene/gui/nine_patch_rect.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class NinePatchRect : public Control {
-
GDCLASS(NinePatchRect, Control);
public:
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 30ecd651b1..5780cc5e71 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -33,7 +33,6 @@
#include "core/print_string.h"
Size2 OptionButton::get_minimum_size() const {
-
Size2 minsize = Button::get_minimum_size();
if (has_theme_icon("arrow")) {
@@ -51,12 +50,11 @@ Size2 OptionButton::get_minimum_size() const {
}
void OptionButton::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_DRAW: {
-
- if (!has_theme_icon("arrow"))
+ if (!has_theme_icon("arrow")) {
return;
+ }
RID ci = get_canvas_item();
Ref<Texture2D> arrow = Control::get_theme_icon("arrow");
@@ -83,13 +81,11 @@ void OptionButton::_notification(int p_what) {
arrow->draw(ci, ofs, clr);
} break;
case NOTIFICATION_THEME_CHANGED: {
-
if (has_theme_icon("arrow")) {
_set_internal_margin(MARGIN_RIGHT, Control::get_theme_icon("arrow")->get_width());
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
if (!is_visible_in_tree()) {
popup->hide();
}
@@ -102,12 +98,10 @@ void OptionButton::_focused(int p_which) {
}
void OptionButton::_selected(int p_which) {
-
_select(p_which, true);
}
void OptionButton::pressed() {
-
Size2 size = get_size();
popup->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y));
popup->set_size(Size2(size.width, 0));
@@ -115,105 +109,96 @@ void OptionButton::pressed() {
}
void OptionButton::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id) {
-
popup->add_icon_radio_check_item(p_icon, p_label, p_id);
- if (popup->get_item_count() == 1)
+ if (popup->get_item_count() == 1) {
select(0);
+ }
}
-void OptionButton::add_item(const String &p_label, int p_id) {
+void OptionButton::add_item(const String &p_label, int p_id) {
popup->add_radio_check_item(p_label, p_id);
- if (popup->get_item_count() == 1)
+ if (popup->get_item_count() == 1) {
select(0);
+ }
}
void OptionButton::set_item_text(int p_idx, const String &p_text) {
-
popup->set_item_text(p_idx, p_text);
- if (current == p_idx)
+ if (current == p_idx) {
set_text(p_text);
+ }
}
-void OptionButton::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
+void OptionButton::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
popup->set_item_icon(p_idx, p_icon);
- if (current == p_idx)
+ if (current == p_idx) {
set_icon(p_icon);
+ }
}
-void OptionButton::set_item_id(int p_idx, int p_id) {
+void OptionButton::set_item_id(int p_idx, int p_id) {
popup->set_item_id(p_idx, p_id);
}
void OptionButton::set_item_metadata(int p_idx, const Variant &p_metadata) {
-
popup->set_item_metadata(p_idx, p_metadata);
}
void OptionButton::set_item_disabled(int p_idx, bool p_disabled) {
-
popup->set_item_disabled(p_idx, p_disabled);
}
String OptionButton::get_item_text(int p_idx) const {
-
return popup->get_item_text(p_idx);
}
Ref<Texture2D> OptionButton::get_item_icon(int p_idx) const {
-
return popup->get_item_icon(p_idx);
}
int OptionButton::get_item_id(int p_idx) const {
-
return popup->get_item_id(p_idx);
}
int OptionButton::get_item_index(int p_id) const {
-
return popup->get_item_index(p_id);
}
Variant OptionButton::get_item_metadata(int p_idx) const {
-
return popup->get_item_metadata(p_idx);
}
bool OptionButton::is_item_disabled(int p_idx) const {
-
return popup->is_item_disabled(p_idx);
}
int OptionButton::get_item_count() const {
-
return popup->get_item_count();
}
void OptionButton::add_separator() {
-
popup->add_separator();
}
void OptionButton::clear() {
-
popup->clear();
set_text("");
current = -1;
}
void OptionButton::_select(int p_which, bool p_emit) {
-
- if (p_which < 0)
+ if (p_which < 0) {
return;
- if (p_which == current)
+ }
+ if (p_which == current) {
return;
+ }
ERR_FAIL_INDEX(p_which, popup->get_item_count());
for (int i = 0; i < popup->get_item_count(); i++) {
-
popup->set_item_checked(i, i == p_which);
}
@@ -221,57 +206,53 @@ void OptionButton::_select(int p_which, bool p_emit) {
set_text(popup->get_item_text(current));
set_icon(popup->get_item_icon(current));
- if (is_inside_tree() && p_emit)
+ if (is_inside_tree() && p_emit) {
emit_signal("item_selected", current);
+ }
}
void OptionButton::_select_int(int p_which) {
-
- if (p_which < 0 || p_which >= popup->get_item_count())
+ if (p_which < 0 || p_which >= popup->get_item_count()) {
return;
+ }
_select(p_which, false);
}
void OptionButton::select(int p_idx) {
-
_select(p_idx, false);
}
int OptionButton::get_selected() const {
-
return current;
}
int OptionButton::get_selected_id() const {
-
int idx = get_selected();
- if (idx < 0)
+ if (idx < 0) {
return 0;
+ }
return get_item_id(current);
}
-Variant OptionButton::get_selected_metadata() const {
+Variant OptionButton::get_selected_metadata() const {
int idx = get_selected();
- if (idx < 0)
+ if (idx < 0) {
return Variant();
+ }
return get_item_metadata(current);
}
void OptionButton::remove_item(int p_idx) {
-
popup->remove_item(p_idx);
}
PopupMenu *OptionButton::get_popup() const {
-
return popup;
}
Array OptionButton::_get_items() const {
-
Array items;
for (int i = 0; i < get_item_count(); i++) {
-
items.push_back(get_item_text(i));
items.push_back(get_item_icon(i));
items.push_back(is_item_disabled(i));
@@ -281,13 +262,12 @@ Array OptionButton::_get_items() const {
return items;
}
-void OptionButton::_set_items(const Array &p_items) {
+void OptionButton::_set_items(const Array &p_items) {
ERR_FAIL_COND(p_items.size() % 5);
clear();
for (int i = 0; i < p_items.size(); i += 5) {
-
String text = p_items[i + 0];
Ref<Texture2D> icon = p_items[i + 1];
bool disabled = p_items[i + 2];
@@ -303,12 +283,10 @@ void OptionButton::_set_items(const Array &p_items) {
}
void OptionButton::get_translatable_strings(List<String> *p_strings) const {
-
popup->get_translatable_strings(p_strings);
}
void OptionButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("add_item", "label", "id"), &OptionButton::add_item, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id"), &OptionButton::add_icon_item, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("set_item_text", "idx", "text"), &OptionButton::set_item_text);
@@ -340,12 +318,11 @@ void OptionButton::_bind_methods() {
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")));
- ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "index")));
+ ADD_SIGNAL(MethodInfo("item_focused", PropertyInfo(Variant::INT, "index")));
}
OptionButton::OptionButton() {
-
current = -1;
set_toggle_mode(true);
set_text_align(ALIGN_LEFT);
@@ -357,9 +334,6 @@ OptionButton::OptionButton() {
popup = memnew(PopupMenu);
popup->hide();
add_child(popup);
- // popup->set_pass_on_modal_close_click(false);
- // popup->set_notify_transform(true);
- popup->set_allow_search(true);
popup->connect("index_pressed", callable_mp(this, &OptionButton::_selected));
popup->connect("id_focused", callable_mp(this, &OptionButton::_focused));
popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false));
diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h
index 9658e1fea8..69a94a34f3 100644
--- a/scene/gui/option_button.h
+++ b/scene/gui/option_button.h
@@ -35,7 +35,6 @@
#include "scene/gui/popup_menu.h"
class OptionButton : public Button {
-
GDCLASS(OptionButton, Button);
PopupMenu *popup;
diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp
index ae51463a15..d8d9beca2b 100644
--- a/scene/gui/panel.cpp
+++ b/scene/gui/panel.cpp
@@ -29,12 +29,11 @@
/*************************************************************************/
#include "panel.h"
+
#include "core/print_string.h"
void Panel::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
RID ci = get_canvas_item();
Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_theme_stylebox("panel") : get_theme_stylebox("panel_fg");
style->draw(ci, Rect2(Point2(), get_size()));
@@ -45,6 +44,7 @@ void Panel::set_mode(Mode p_mode) {
mode = p_mode;
update();
}
+
Panel::Mode Panel::get_mode() const {
return mode;
}
@@ -54,7 +54,11 @@ void Panel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_mode"), &Panel::get_mode);
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Background,Foreground"), "set_mode", "get_mode");
+
+ BIND_ENUM_CONSTANT(MODE_BACKGROUND);
+ BIND_ENUM_CONSTANT(MODE_FOREGROUND);
}
+
Panel::Panel() {
// Has visible stylebox, so stop by default.
set_mouse_filter(MOUSE_FILTER_STOP);
diff --git a/scene/gui/panel.h b/scene/gui/panel.h
index 739c64c0a6..a68c3d3f0c 100644
--- a/scene/gui/panel.h
+++ b/scene/gui/panel.h
@@ -34,13 +34,12 @@
#include "scene/gui/control.h"
class Panel : public Control {
-
GDCLASS(Panel, Control);
public:
enum Mode {
MODE_BACKGROUND,
- MODE_FOREGROUND
+ MODE_FOREGROUND,
};
private:
@@ -59,4 +58,5 @@ public:
};
VARIANT_ENUM_CAST(Panel::Mode)
-#endif
+
+#endif // PANEL_H
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 62b9296409..9abdfac009 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -31,56 +31,57 @@
#include "panel_container.h"
Size2 PanelContainer::get_minimum_size() const {
-
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible())
+ if (!c || !c->is_visible()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
ms.width = MAX(ms.width, minsize.width);
ms.height = MAX(ms.height, minsize.height);
}
- if (style.is_valid())
+ if (style.is_valid()) {
ms += style->get_minimum_size();
+ }
return ms;
}
void PanelContainer::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
RID ci = get_canvas_item();
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
style->draw(ci, Rect2(Point2(), get_size()));
}
if (p_what == NOTIFICATION_SORT_CHILDREN) {
-
Ref<StyleBox> style;
- if (has_theme_stylebox("panel"))
+ if (has_theme_stylebox("panel")) {
style = get_theme_stylebox("panel");
- else
+ } else {
style = get_theme_stylebox("panel", "PanelContainer");
+ }
Size2 size = get_size();
Point2 ofs;
@@ -90,12 +91,13 @@ void PanelContainer::_notification(int p_what) {
}
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())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
fit_child_in_rect(c, Rect2(ofs, size));
}
diff --git a/scene/gui/panel_container.h b/scene/gui/panel_container.h
index 5623c3484b..b68bc223dc 100644
--- a/scene/gui/panel_container.h
+++ b/scene/gui/panel_container.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
class PanelContainer : public Container {
-
GDCLASS(PanelContainer, Container);
protected:
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 6edafc65a0..5fc5f9b669 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -42,15 +42,13 @@ void Popup::_input_from_window(const Ref<InputEvent> &p_event) {
}
void Popup::_parent_focused() {
-
_close_pressed();
}
-void Popup::_notification(int p_what) {
+void Popup::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
-
parent_visible = get_parent_visible_window();
if (parent_visible) {
parent_visible->connect("focus_entered", callable_mp(this, &Popup::_parent_focused));
@@ -79,7 +77,6 @@ void Popup::_notification(int p_what) {
}
void Popup::_close_pressed() {
-
Window *parent_window = parent_visible;
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused));
@@ -98,8 +95,8 @@ void Popup::_close_pressed() {
void Popup::set_as_minsize() {
set_size(get_contents_minimum_size());
}
-void Popup::_bind_methods() {
+void Popup::_bind_methods() {
ADD_SIGNAL(MethodInfo("popup_hide"));
}
@@ -133,7 +130,6 @@ Rect2i Popup::_popup_adjust_rect() const {
}
Popup::Popup() {
-
parent_visible = nullptr;
set_wrap_controls(true);
@@ -149,18 +145,19 @@ Popup::~Popup() {
}
Size2 PopupPanel::_get_contents_minimum_size() const {
-
Ref<StyleBox> p = get_theme_stylebox("panel", get_class_name());
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || c == panel)
+ if (!c || c == panel) {
continue;
+ }
- if (c->is_set_as_toplevel())
+ if (c->is_set_as_toplevel()) {
continue;
+ }
Size2 cms = c->get_combined_minimum_size();
ms.x = MAX(cms.x, ms.x);
@@ -171,7 +168,6 @@ Size2 PopupPanel::_get_contents_minimum_size() const {
}
void PopupPanel::_update_child_rects() {
-
Ref<StyleBox> p = get_theme_stylebox("panel", get_class_name());
Vector2 cpos(p->get_offset());
@@ -179,11 +175,13 @@ void PopupPanel::_update_child_rects() {
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (c->is_set_as_toplevel())
+ if (c->is_set_as_toplevel()) {
continue;
+ }
if (c == panel) {
c->set_position(Vector2());
@@ -196,21 +194,17 @@ void PopupPanel::_update_child_rects() {
}
void PopupPanel::_notification(int p_what) {
-
if (p_what == NOTIFICATION_THEME_CHANGED) {
panel->add_theme_style_override("panel", get_theme_stylebox("panel", get_class_name()));
} else if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_ENTER_TREE) {
-
panel->add_theme_style_override("panel", get_theme_stylebox("panel", get_class_name()));
_update_child_rects();
} else if (p_what == NOTIFICATION_WM_SIZE_CHANGED) {
-
_update_child_rects();
}
}
PopupPanel::PopupPanel() {
-
panel = memnew(Panel);
add_child(panel);
}
diff --git a/scene/gui/popup.h b/scene/gui/popup.h
index 6cd2b4028f..0e32d55cb6 100644
--- a/scene/gui/popup.h
+++ b/scene/gui/popup.h
@@ -34,7 +34,6 @@
#include "scene/main/window.h"
class Popup : public Window {
-
GDCLASS(Popup, Window);
Window *parent_visible;
@@ -56,7 +55,6 @@ public:
};
class PopupPanel : public Popup {
-
GDCLASS(PopupPanel, Popup);
Panel *panel;
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index c096dc94cb..6e19b820e0 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -30,7 +30,7 @@
#include "popup_menu.h"
-#include "core/input/input_filter.h"
+#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "core/print_string.h"
@@ -38,18 +38,17 @@
#include "scene/gui/control.h"
String PopupMenu::_get_accel_text(int p_item) const {
-
ERR_FAIL_INDEX_V(p_item, items.size(), String());
- if (items[p_item].shortcut.is_valid())
+ if (items[p_item].shortcut.is_valid()) {
return items[p_item].shortcut->get_as_text();
- else if (items[p_item].accel)
+ } else if (items[p_item].accel) {
return keycode_get_string(items[p_item].accel);
+ }
return String();
}
Size2 PopupMenu::_get_contents_minimum_size() const {
-
int vseparation = get_theme_constant("vseparation");
int hseparation = get_theme_constant("hseparation");
@@ -64,37 +63,36 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
bool has_check = false;
for (int i = 0; i < items.size(); i++) {
-
Size2 size;
if (!items[i].icon.is_null()) {
-
Size2 icon_size = items[i].icon->get_size();
size.height = MAX(icon_size.height, font_h);
icon_w = MAX(icon_size.width + hseparation, icon_w);
} else {
-
size.height = font_h;
}
size.width += items[i].h_ofs;
- if (items[i].checkable_type)
+ if (items[i].checkable_type) {
has_check = true;
+ }
String text = items[i].xl_text;
size.width += font->get_string_size(text).width;
- if (i > 0)
+ if (i > 0) {
size.height += vseparation;
+ }
if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
-
int accel_w = hseparation * 2;
accel_w += font->get_string_size(_get_accel_text(i)).width;
accel_max_w = MAX(accel_w, accel_max_w);
}
- if (items[i].submenu != "")
+ if (items[i].submenu != "") {
size.width += get_theme_icon("submenu")->get_width();
+ }
max_w = MAX(max_w, size.width);
@@ -102,39 +100,38 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
}
minsize.width += max_w + icon_w + accel_max_w;
- if (has_check)
+ if (has_check) {
minsize.width += check_w;
+ }
return minsize;
}
int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
-
- if (p_over.x < 0 || p_over.x >= get_size().width)
+ if (p_over.x < 0 || p_over.x >= get_size().width) {
return -1;
+ }
Ref<StyleBox> style = get_theme_stylebox("panel");
Point2 ofs = style->get_offset();
- if (ofs.y > p_over.y)
+ if (ofs.y > p_over.y) {
return -1;
+ }
Ref<Font> font = get_theme_font("font");
int vseparation = get_theme_constant("vseparation");
float font_h = font->get_height();
for (int i = 0; i < items.size(); i++) {
-
ofs.y += vseparation;
float h;
if (!items[i].icon.is_null()) {
-
Size2 icon_size = items[i].icon->get_size();
h = MAX(icon_size.height, font_h);
} else {
-
h = font_h;
}
@@ -148,13 +145,13 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
}
void PopupMenu::_activate_submenu(int over) {
-
Node *n = get_node(items[over].submenu);
ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[over].submenu + ".");
Popup *pm = Object::cast_to<Popup>(n);
ERR_FAIL_COND_MSG(!pm, "Item subnode is not a Popup: " + items[over].submenu + ".");
- if (pm->is_visible())
+ if (pm->is_visible()) {
return; //already visible!
+ }
Point2 p = get_position();
Rect2 pr(p, get_size());
@@ -163,8 +160,9 @@ void PopupMenu::_activate_submenu(int over) {
Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y);
Size2 size = pm->get_size();
// fix pos
- if (pos.x + size.width > get_parent_rect().size.width)
+ if (pos.x + size.width > get_parent_rect().size.width) {
pos.x = p.x - size.width;
+ }
pm->set_position(pos);
// pm->set_scale(get_global_transform().get_scale());
@@ -172,7 +170,6 @@ void PopupMenu::_activate_submenu(int over) {
PopupMenu *pum = Object::cast_to<PopupMenu>(pm);
if (pum) {
-
pr.position -= pum->get_position();
pum->clear_autohide_areas();
pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache));
@@ -184,18 +181,17 @@ void PopupMenu::_activate_submenu(int over) {
}
void PopupMenu::_submenu_timeout() {
-
//if (!has_focus()) {
// return; //do not activate if not has focus
//}
- if (mouse_over == submenu_over)
+ if (mouse_over == submenu_over) {
_activate_submenu(mouse_over);
+ }
submenu_over = -1;
}
void PopupMenu::_scroll(float p_factor, const Point2 &p_over) {
-
int vseparation = get_theme_constant("vseparation");
Ref<Font> font = get_theme_font("font");
@@ -226,20 +222,18 @@ void PopupMenu::_scroll(float p_factor, const Point2 &p_over) {
}
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
-
if (p_event->is_action("ui_down") && p_event->is_pressed()) {
-
int search_from = mouse_over + 1;
- if (search_from >= items.size())
+ if (search_from >= items.size()) {
search_from = 0;
+ }
for (int i = search_from; i < items.size(); i++) {
-
- if (i < 0 || i >= items.size())
+ if (i < 0 || i >= items.size()) {
continue;
+ }
if (!items[i].separator && !items[i].disabled) {
-
mouse_over = i;
emit_signal("id_focused", i);
control->update();
@@ -248,18 +242,17 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
}
} else if (p_event->is_action("ui_up") && p_event->is_pressed()) {
-
int search_from = mouse_over - 1;
- if (search_from < 0)
+ if (search_from < 0) {
search_from = items.size() - 1;
+ }
for (int i = search_from; i >= 0; i--) {
-
- if (i >= items.size())
+ if (i >= items.size()) {
continue;
+ }
if (!items[i].separator && !items[i].disabled) {
-
mouse_over = i;
emit_signal("id_focused", i);
control->update();
@@ -268,22 +261,18 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
}
} else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
-
Node *n = get_parent();
if (n && Object::cast_to<PopupMenu>(n)) {
hide();
set_input_as_handled();
}
} else if (p_event->is_action("ui_right") && p_event->is_pressed()) {
-
if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over) {
_activate_submenu(mouse_over);
set_input_as_handled();
}
} else if (p_event->is_action("ui_accept") && p_event->is_pressed()) {
-
if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) {
-
if (items[mouse_over].submenu != "" && submenu_over != mouse_over) {
_activate_submenu(mouse_over);
} else {
@@ -296,25 +285,21 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
-
- if (b->is_pressed())
+ if (b->is_pressed()) {
return;
+ }
int button_idx = b->get_button_index();
switch (button_idx) {
-
case BUTTON_WHEEL_DOWN: {
-
_scroll(-b->get_factor(), b->get_position());
} break;
case BUTTON_WHEEL_UP: {
-
_scroll(b->get_factor(), b->get_position());
} break;
default: {
// Allow activating item by releasing the LMB or any that was down when the popup appeared
if (button_idx == BUTTON_LEFT || (initial_button_mask & (1 << (button_idx - 1)))) {
-
bool was_during_grabbed_click = during_grabbed_click;
during_grabbed_click = false;
initial_button_mask = 0;
@@ -332,11 +317,11 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
break; //non-activable
}
- if (items[over].separator || items[over].disabled)
+ if (items[over].separator || items[over].disabled) {
break;
+ }
if (items[over].submenu != "") {
-
_activate_submenu(over);
return;
}
@@ -351,17 +336,15 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
-
if (invalidated_click) {
moved += m->get_relative();
- if (moved.length() > 4)
+ if (moved.length() > 4) {
invalidated_click = false;
+ }
}
for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
-
if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) {
-
_close_pressed();
return;
}
@@ -394,8 +377,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
- if (allow_search && k.is_valid() && k->get_unicode()) {
-
+ if (allow_search && k.is_valid() && k->get_unicode() && k->is_pressed()) {
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
uint64_t max_interval = uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000));
@@ -405,19 +387,22 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
search_string = "";
}
- if (String::chr(k->get_unicode()) != search_string)
+ if (String::chr(k->get_unicode()) != search_string) {
search_string += String::chr(k->get_unicode());
+ }
for (int i = mouse_over + 1; i <= items.size(); i++) {
if (i == items.size()) {
- if (mouse_over <= 0)
+ if (mouse_over <= 0) {
break;
- else
+ } else {
i = 0;
+ }
}
- if (i == mouse_over)
+ if (i == mouse_over) {
break;
+ }
if (items[i].text.findn(search_string) == 0) {
mouse_over = i;
@@ -431,7 +416,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
void PopupMenu::_draw() {
-
RID ci = control->get_canvas_item();
Size2 size = get_size();
@@ -460,39 +444,39 @@ void PopupMenu::_draw() {
float icon_ofs = 0.0;
bool has_check = false;
for (int i = 0; i < items.size(); i++) {
-
- if (!items[i].icon.is_null())
+ if (!items[i].icon.is_null()) {
icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs);
+ }
- if (items[i].checkable_type)
+ if (items[i].checkable_type) {
has_check = true;
+ }
}
- if (icon_ofs > 0.0)
+ if (icon_ofs > 0.0) {
icon_ofs += hseparation;
+ }
float check_ofs = 0.0;
- if (has_check)
+ if (has_check) {
check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation;
+ }
for (int i = 0; i < items.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
ofs.y += vseparation;
+ }
Point2 item_ofs = ofs;
Size2 icon_size;
float h;
if (!items[i].icon.is_null()) {
-
icon_size = items[i].icon->get_size();
h = MAX(icon_size.height, font_h);
} else {
-
h = font_h;
}
if (i == mouse_over) {
-
hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation)));
}
@@ -500,7 +484,6 @@ void PopupMenu::_draw() {
item_ofs.x += items[i].h_ofs;
if (items[i].separator) {
-
int sep_h = separator->get_center_size().height + separator->get_minimum_size().height;
if (text != String()) {
int ss = font->get_string_size(text).width;
@@ -535,13 +518,11 @@ void PopupMenu::_draw() {
item_ofs.y += font->get_ascent();
if (items[i].separator) {
-
if (text != String()) {
int center = (get_size().width - font->get_string_size(text).width) / 2;
font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_disabled);
}
} else {
-
item_ofs.x += icon_ofs + check_ofs;
font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color));
}
@@ -560,11 +541,8 @@ void PopupMenu::_draw() {
}
void PopupMenu::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_ENTER_TREE: {
-
PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent());
if (pm) {
// Inherit submenu's popup delay time from parent menu
@@ -573,7 +551,6 @@ void PopupMenu::_notification(int p_what) {
}
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
-
for (int i = 0; i < items.size(); i++) {
items.write[i].xl_text = tr(items[i].text);
}
@@ -582,23 +559,19 @@ void PopupMenu::_notification(int p_what) {
control->update();
} break;
case NOTIFICATION_WM_MOUSE_ENTER: {
-
//grab_focus();
} break;
case NOTIFICATION_WM_MOUSE_EXIT: {
-
if (mouse_over >= 0 && (items[mouse_over].submenu == "" || submenu_over != -1)) {
mouse_over = -1;
control->update();
}
} break;
case NOTIFICATION_POST_POPUP: {
-
- initial_button_mask = InputFilter::get_singleton()->get_mouse_button_mask();
+ initial_button_mask = Input::get_singleton()->get_mouse_button_mask();
during_grabbed_click = (bool)initial_button_mask;
} break;
case NOTIFICATION_WM_SIZE_CHANGED: {
-
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
//only used when using operating system windows
@@ -607,7 +580,6 @@ void PopupMenu::_notification(int p_what) {
mouse_pos -= get_position();
for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
-
if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E->get().has_point(mouse_pos)) {
_close_pressed();
return;
@@ -616,7 +588,6 @@ void PopupMenu::_notification(int p_what) {
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
if (!is_visible()) {
if (mouse_over >= 0) {
mouse_over = -1;
@@ -624,16 +595,19 @@ void PopupMenu::_notification(int p_what) {
}
for (int i = 0; i < items.size(); i++) {
- if (items[i].submenu == "")
+ if (items[i].submenu == "") {
continue;
+ }
Node *n = get_node(items[i].submenu);
- if (!n)
+ if (!n) {
continue;
+ }
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
- if (!pm || !pm->is_visible())
+ if (!pm || !pm->is_visible()) {
continue;
+ }
pm->hide();
}
@@ -659,7 +633,6 @@ void PopupMenu::_notification(int p_what) {
item.accel = p_accel;
void PopupMenu::add_item(const String &p_label, int p_id, uint32_t p_accel) {
-
Item item;
ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel);
items.push_back(item);
@@ -668,7 +641,6 @@ void PopupMenu::add_item(const String &p_label, int p_id, uint32_t p_accel) {
}
void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) {
-
Item item;
ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel);
item.icon = p_icon;
@@ -678,7 +650,6 @@ void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_labe
}
void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel) {
-
Item item;
ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel);
item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX;
@@ -688,7 +659,6 @@ void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel
}
void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) {
-
Item item;
ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel);
item.icon = p_icon;
@@ -699,7 +669,6 @@ void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String &
}
void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p_accel) {
-
Item item;
ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel);
item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
@@ -709,7 +678,6 @@ void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p
}
void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) {
-
Item item;
ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel);
item.icon = p_icon;
@@ -720,7 +688,6 @@ void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const St
}
void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int p_default_state, int p_id, uint32_t p_accel) {
-
Item item;
ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel);
item.max_states = p_max_states;
@@ -740,7 +707,6 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int
item.shortcut_is_global = p_global;
void PopupMenu::add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) {
-
Item item;
ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global);
items.push_back(item);
@@ -749,7 +715,6 @@ void PopupMenu::add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_g
}
void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) {
-
Item item;
ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global);
item.icon = p_icon;
@@ -759,7 +724,6 @@ void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortC
}
void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) {
-
Item item;
ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global);
item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX;
@@ -769,7 +733,6 @@ void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bo
}
void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) {
-
Item item;
ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global);
item.icon = p_icon;
@@ -780,7 +743,6 @@ void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<
}
void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) {
-
Item item;
ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global);
item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
@@ -790,7 +752,6 @@ void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_
}
void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) {
-
Item item;
ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global);
item.icon = p_icon;
@@ -801,7 +762,6 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons
}
void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) {
-
Item item;
item.text = p_label;
item.xl_text = tr(p_label);
@@ -818,7 +778,6 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu,
/* Methods to modify existing items. */
void PopupMenu::set_item_text(int p_idx, const String &p_text) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].text = p_text;
items.write[p_idx].xl_text = tr(p_text);
@@ -826,16 +785,16 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) {
control->update();
child_controls_changed();
}
-void PopupMenu::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
+void PopupMenu::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].icon = p_icon;
control->update();
child_controls_changed();
}
-void PopupMenu::set_item_checked(int p_idx, bool p_checked) {
+void PopupMenu::set_item_checked(int p_idx, bool p_checked) {
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].checked = p_checked;
@@ -843,8 +802,8 @@ void PopupMenu::set_item_checked(int p_idx, bool p_checked) {
control->update();
child_controls_changed();
}
-void PopupMenu::set_item_id(int p_idx, int p_id) {
+void PopupMenu::set_item_id(int p_idx, int p_id) {
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].id = p_id;
@@ -853,7 +812,6 @@ void PopupMenu::set_item_id(int p_idx, int p_id) {
}
void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].accel = p_accel;
@@ -862,7 +820,6 @@ void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) {
}
void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].metadata = p_meta;
control->update();
@@ -870,7 +827,6 @@ void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) {
}
void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].disabled = p_disabled;
control->update();
@@ -878,7 +834,6 @@ void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) {
}
void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].submenu = p_submenu;
control->update();
@@ -886,7 +841,6 @@ void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) {
}
void PopupMenu::toggle_item_checked(int p_idx) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].checked = !items[p_idx].checked;
control->update();
@@ -894,82 +848,71 @@ void PopupMenu::toggle_item_checked(int p_idx) {
}
String PopupMenu::get_item_text(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), "");
return items[p_idx].text;
}
int PopupMenu::get_item_idx_from_text(const String &text) const {
-
for (int idx = 0; idx < items.size(); idx++) {
- if (items[idx].text == text)
+ if (items[idx].text == text) {
return idx;
+ }
}
return -1;
}
Ref<Texture2D> PopupMenu::get_item_icon(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture2D>());
return items[p_idx].icon;
}
uint32_t PopupMenu::get_item_accelerator(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), 0);
return items[p_idx].accel;
}
Variant PopupMenu::get_item_metadata(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Variant());
return items[p_idx].metadata;
}
bool PopupMenu::is_item_disabled(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), false);
return items[p_idx].disabled;
}
bool PopupMenu::is_item_checked(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), false);
return items[p_idx].checked;
}
int PopupMenu::get_item_id(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), 0);
return items[p_idx].id;
}
int PopupMenu::get_item_index(int p_id) const {
-
for (int i = 0; i < items.size(); i++) {
-
- if (items[i].id == p_id)
+ if (items[i].id == p_id) {
return i;
+ }
}
return -1;
}
String PopupMenu::get_item_submenu(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), "");
return items[p_idx].submenu;
}
String PopupMenu::get_item_tooltip(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), "");
return items[p_idx].tooltip;
}
Ref<ShortCut> PopupMenu::get_item_shortcut(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<ShortCut>());
return items[p_idx].shortcut;
}
@@ -980,7 +923,6 @@ int PopupMenu::get_item_state(int p_idx) const {
}
void PopupMenu::set_item_as_separator(int p_idx, bool p_separator) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].separator = p_separator;
control->update();
@@ -992,21 +934,18 @@ bool PopupMenu::is_item_separator(int p_idx) const {
}
void PopupMenu::set_item_as_checkable(int p_idx, bool p_checkable) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].checkable_type = p_checkable ? Item::CHECKABLE_TYPE_CHECK_BOX : Item::CHECKABLE_TYPE_NONE;
control->update();
}
void PopupMenu::set_item_as_radio_checkable(int p_idx, bool p_radio_checkable) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].checkable_type = p_radio_checkable ? Item::CHECKABLE_TYPE_RADIO_BUTTON : Item::CHECKABLE_TYPE_NONE;
control->update();
}
void PopupMenu::set_item_tooltip(int p_idx, const String &p_tooltip) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].tooltip = p_tooltip;
control->update();
@@ -1028,7 +967,6 @@ void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bo
}
void PopupMenu::set_item_h_offset(int p_idx, int p_offset) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].h_ofs = p_offset;
control->update();
@@ -1036,29 +974,27 @@ void PopupMenu::set_item_h_offset(int p_idx, int p_offset) {
}
void PopupMenu::set_item_multistate(int p_idx, int p_state) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].state = p_state;
control->update();
}
void PopupMenu::set_item_shortcut_disabled(int p_idx, bool p_disabled) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].shortcut_is_disabled = p_disabled;
control->update();
}
void PopupMenu::toggle_item_multistate(int p_idx) {
-
ERR_FAIL_INDEX(p_idx, items.size());
if (0 >= items[p_idx].max_states) {
return;
}
++items.write[p_idx].state;
- if (items.write[p_idx].max_states <= items[p_idx].state)
+ if (items.write[p_idx].max_states <= items[p_idx].state) {
items.write[p_idx].state = 0;
+ }
control->update();
}
@@ -1074,38 +1010,45 @@ bool PopupMenu::is_item_radio_checkable(int p_idx) const {
}
bool PopupMenu::is_item_shortcut_disabled(int p_idx) const {
-
ERR_FAIL_INDEX_V(p_idx, items.size(), false);
return items[p_idx].shortcut_is_disabled;
}
-int PopupMenu::get_item_count() const {
+int PopupMenu::get_current_index() const {
+ return mouse_over;
+}
+int PopupMenu::get_item_count() const {
return items.size();
}
bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only) {
-
uint32_t code = 0;
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
code = k->get_keycode();
- if (code == 0)
+ if (code == 0) {
code = k->get_unicode();
- if (k->get_control())
+ }
+ if (k->get_control()) {
code |= KEY_MASK_CTRL;
- if (k->get_alt())
+ }
+ if (k->get_alt()) {
code |= KEY_MASK_ALT;
- if (k->get_metakey())
+ }
+ if (k->get_metakey()) {
code |= KEY_MASK_META;
- if (k->get_shift())
+ }
+ if (k->get_shift()) {
code |= KEY_MASK_SHIFT;
+ }
}
for (int i = 0; i < items.size(); i++) {
- if (is_item_disabled(i) || items[i].shortcut_is_disabled)
+ if (is_item_disabled(i) || items[i].shortcut_is_disabled) {
continue;
+ }
if (items[i].shortcut.is_valid() && items[i].shortcut->is_shortcut(p_event) && (items[i].shortcut_is_global || !p_for_global_only)) {
activate_item(i);
@@ -1119,12 +1062,14 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
if (items[i].submenu != "") {
Node *n = get_node(items[i].submenu);
- if (!n)
+ if (!n) {
continue;
+ }
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
- if (!pm)
+ if (!pm) {
continue;
+ }
if (pm->activate_item_by_event(p_event, p_for_global_only)) {
return true;
@@ -1135,7 +1080,6 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo
}
void PopupMenu::activate_item(int p_item) {
-
ERR_FAIL_INDEX(p_item, items.size());
ERR_FAIL_COND(items[p_item].separator);
int id = items[p_item].id >= 0 ? items[p_item].id : p_item;
@@ -1148,13 +1092,16 @@ void PopupMenu::activate_item(int p_item) {
// with hide_on_item_selection enabled
if (items[p_item].checkable_type) {
- if (!hide_on_checkable_item_selection || !pop->is_hide_on_checkable_item_selection())
+ if (!hide_on_checkable_item_selection || !pop->is_hide_on_checkable_item_selection()) {
break;
+ }
} else if (0 < items[p_item].max_states) {
- if (!hide_on_multistate_item_selection || !pop->is_hide_on_multistate_item_selection())
+ if (!hide_on_multistate_item_selection || !pop->is_hide_on_multistate_item_selection()) {
break;
- } else if (!hide_on_item_selection || !pop->is_hide_on_item_selection())
+ }
+ } else if (!hide_on_item_selection || !pop->is_hide_on_item_selection()) {
break;
+ }
pop->hide();
next = next->get_parent();
@@ -1167,13 +1114,16 @@ void PopupMenu::activate_item(int p_item) {
bool need_hide = true;
if (items[p_item].checkable_type) {
- if (!hide_on_checkable_item_selection)
+ if (!hide_on_checkable_item_selection) {
need_hide = false;
+ }
} else if (0 < items[p_item].max_states) {
- if (!hide_on_multistate_item_selection)
+ if (!hide_on_multistate_item_selection) {
need_hide = false;
- } else if (!hide_on_item_selection)
+ }
+ } else if (!hide_on_item_selection) {
need_hide = false;
+ }
emit_signal("id_pressed", id);
emit_signal("index_pressed", p_item);
@@ -1184,7 +1134,6 @@ void PopupMenu::activate_item(int p_item) {
}
void PopupMenu::remove_item(int p_idx) {
-
ERR_FAIL_INDEX(p_idx, items.size());
if (items[p_idx].shortcut.is_valid()) {
@@ -1197,7 +1146,6 @@ void PopupMenu::remove_item(int p_idx) {
}
void PopupMenu::add_separator(const String &p_text) {
-
Item sep;
sep.separator = true;
sep.id = -1;
@@ -1210,7 +1158,6 @@ void PopupMenu::add_separator(const String &p_text) {
}
void PopupMenu::clear() {
-
for (int i = 0; i < items.size(); i++) {
if (items[i].shortcut.is_valid()) {
_unref_shortcut(items[i].shortcut);
@@ -1223,10 +1170,8 @@ void PopupMenu::clear() {
}
Array PopupMenu::_get_items() const {
-
Array items;
for (int i = 0; i < get_item_count(); i++) {
-
items.push_back(get_item_text(i));
items.push_back(get_item_icon(i));
// For compatibility, use false/true for no/checkbox and integers for other values
@@ -1246,7 +1191,6 @@ Array PopupMenu::_get_items() const {
}
void PopupMenu::_ref_shortcut(Ref<ShortCut> p_sc) {
-
if (!shortcut_refcount.has(p_sc)) {
shortcut_refcount[p_sc] = 1;
p_sc->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update));
@@ -1256,7 +1200,6 @@ void PopupMenu::_ref_shortcut(Ref<ShortCut> p_sc) {
}
void PopupMenu::_unref_shortcut(Ref<ShortCut> p_sc) {
-
ERR_FAIL_COND(!shortcut_refcount.has(p_sc));
shortcut_refcount[p_sc]--;
if (shortcut_refcount[p_sc] == 0) {
@@ -1266,12 +1209,10 @@ void PopupMenu::_unref_shortcut(Ref<ShortCut> p_sc) {
}
void PopupMenu::_set_items(const Array &p_items) {
-
ERR_FAIL_COND(p_items.size() % 10);
clear();
for (int i = 0; i < p_items.size(); i += 10) {
-
String text = p_items[i + 0];
Ref<Texture2D> icon = p_items[i + 1];
// For compatibility, use false/true for no/checkbox and integers for other values
@@ -1308,87 +1249,74 @@ void PopupMenu::_set_items(const Array &p_items) {
// Hide on item selection determines whether or not the popup will close after item selection
void PopupMenu::set_hide_on_item_selection(bool p_enabled) {
-
hide_on_item_selection = p_enabled;
}
bool PopupMenu::is_hide_on_item_selection() const {
-
return hide_on_item_selection;
}
void PopupMenu::set_hide_on_checkable_item_selection(bool p_enabled) {
-
hide_on_checkable_item_selection = p_enabled;
}
bool PopupMenu::is_hide_on_checkable_item_selection() const {
-
return hide_on_checkable_item_selection;
}
void PopupMenu::set_hide_on_multistate_item_selection(bool p_enabled) {
-
hide_on_multistate_item_selection = p_enabled;
}
bool PopupMenu::is_hide_on_multistate_item_selection() const {
-
return hide_on_multistate_item_selection;
}
void PopupMenu::set_submenu_popup_delay(float p_time) {
-
- if (p_time <= 0)
+ if (p_time <= 0) {
p_time = 0.01;
+ }
submenu_timer->set_wait_time(p_time);
}
float PopupMenu::get_submenu_popup_delay() const {
-
return submenu_timer->get_wait_time();
}
void PopupMenu::set_allow_search(bool p_allow) {
-
allow_search = p_allow;
}
bool PopupMenu::get_allow_search() const {
-
return allow_search;
}
String PopupMenu::get_tooltip(const Point2 &p_pos) const {
-
int over = _get_mouse_over(p_pos);
- if (over < 0 || over >= items.size())
+ if (over < 0 || over >= items.size()) {
return "";
+ }
return items[over].tooltip;
}
void PopupMenu::set_parent_rect(const Rect2 &p_rect) {
-
parent_rect = p_rect;
}
void PopupMenu::get_translatable_strings(List<String> *p_strings) const {
-
for (int i = 0; i < items.size(); i++) {
-
- if (items[i].xl_text != "")
+ if (items[i].xl_text != "") {
p_strings->push_back(items[i].xl_text);
+ }
}
}
void PopupMenu::add_autohide_area(const Rect2 &p_area) {
-
autohide_areas.push_back(p_area);
}
void PopupMenu::clear_autohide_areas() {
-
autohide_areas.clear();
}
@@ -1401,7 +1329,6 @@ void PopupMenu::take_mouse_focus() {
}
void PopupMenu::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &PopupMenu::_gui_input);
ClassDB::bind_method(D_METHOD("add_item", "label", "id", "accel"), &PopupMenu::add_item, DEFVAL(-1), DEFVAL(0));
@@ -1457,6 +1384,7 @@ void PopupMenu::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_tooltip", "idx"), &PopupMenu::get_item_tooltip);
ClassDB::bind_method(D_METHOD("get_item_shortcut", "idx"), &PopupMenu::get_item_shortcut);
+ ClassDB::bind_method(D_METHOD("get_current_index"), &PopupMenu::get_current_index);
ClassDB::bind_method(D_METHOD("get_item_count"), &PopupMenu::get_item_count);
ClassDB::bind_method(D_METHOD("remove_item", "idx"), &PopupMenu::remove_item);
@@ -1495,14 +1423,12 @@ void PopupMenu::_bind_methods() {
}
void PopupMenu::popup(const Rect2 &p_bounds) {
-
moved = Vector2();
invalidated_click = true;
Popup::popup(p_bounds);
}
PopupMenu::PopupMenu() {
-
control = memnew(Control);
add_child(control);
@@ -1514,8 +1440,9 @@ PopupMenu::PopupMenu() {
submenu_over = -1;
initial_button_mask = 0;
during_grabbed_click = false;
+ invalidated_click = false;
- allow_search = false;
+ allow_search = true;
search_time_msec = 0;
search_string = "";
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 2eef1f009d..d03a14d6e4 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -35,7 +35,6 @@
#include "scene/gui/shortcut.h"
class PopupMenu : public Popup {
-
GDCLASS(PopupMenu, Popup);
struct Item {
@@ -178,6 +177,7 @@ public:
Ref<ShortCut> get_item_shortcut(int p_idx) const;
int get_item_state(int p_idx) const;
+ int get_current_index() const;
int get_item_count() const;
bool activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only = false);
diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp
index 362c45453d..9246f1723d 100644
--- a/scene/gui/progress_bar.cpp
+++ b/scene/gui/progress_bar.cpp
@@ -31,7 +31,6 @@
#include "progress_bar.h"
Size2 ProgressBar::get_minimum_size() const {
-
Ref<StyleBox> bg = get_theme_stylebox("bg");
Ref<StyleBox> fg = get_theme_stylebox("fg");
Ref<Font> font = get_theme_font("font");
@@ -49,9 +48,7 @@ Size2 ProgressBar::get_minimum_size() const {
}
void ProgressBar::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
Ref<StyleBox> bg = get_theme_stylebox("bg");
Ref<StyleBox> fg = get_theme_stylebox("fg");
Ref<Font> font = get_theme_font("font");
@@ -62,7 +59,6 @@ void ProgressBar::_notification(int p_what) {
int mp = fg->get_minimum_size().width;
int p = r * (get_size().width - mp);
if (p > 0) {
-
draw_style_box(fg, Rect2(Point2(), Size2(p + fg->get_minimum_size().width, get_size().height)));
}
@@ -74,18 +70,15 @@ void ProgressBar::_notification(int p_what) {
}
void ProgressBar::set_percent_visible(bool p_visible) {
-
percent_visible = p_visible;
update();
}
bool ProgressBar::is_percent_visible() const {
-
return percent_visible;
}
void ProgressBar::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_percent_visible", "visible"), &ProgressBar::set_percent_visible);
ClassDB::bind_method(D_METHOD("is_percent_visible"), &ProgressBar::is_percent_visible);
ADD_GROUP("Percent", "percent_");
@@ -93,7 +86,6 @@ void ProgressBar::_bind_methods() {
}
ProgressBar::ProgressBar() {
-
set_v_size_flags(0);
set_step(0.01);
percent_visible = true;
diff --git a/scene/gui/progress_bar.h b/scene/gui/progress_bar.h
index 371d0370f6..d8eba921a3 100644
--- a/scene/gui/progress_bar.h
+++ b/scene/gui/progress_bar.h
@@ -34,7 +34,6 @@
#include "scene/gui/range.h"
class ProgressBar : public Range {
-
GDCLASS(ProgressBar, Range);
bool percent_visible;
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index adc5f81465..59e26d9e38 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -44,7 +44,6 @@ String Range::get_configuration_warning() const {
}
void Range::_value_changed_notify() {
-
_value_changed(shared->val);
emit_signal("value_changed", shared->val);
update();
@@ -52,53 +51,57 @@ void Range::_value_changed_notify() {
}
void Range::Shared::emit_value_changed() {
-
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
Range *r = E->get();
- if (!r->is_inside_tree())
+ if (!r->is_inside_tree()) {
continue;
+ }
r->_value_changed_notify();
}
}
void Range::_changed_notify(const char *p_what) {
-
emit_signal("changed");
update();
_change_notify(p_what);
}
void Range::Shared::emit_changed(const char *p_what) {
-
for (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
Range *r = E->get();
- if (!r->is_inside_tree())
+ if (!r->is_inside_tree()) {
continue;
+ }
r->_changed_notify(p_what);
}
}
void Range::set_value(double p_val) {
-
- if (shared->step > 0)
+ if (shared->step > 0) {
p_val = Math::round(p_val / shared->step) * shared->step;
+ }
- if (_rounded_values)
+ if (_rounded_values) {
p_val = Math::round(p_val);
+ }
- if (!shared->allow_greater && p_val > shared->max - shared->page)
+ if (!shared->allow_greater && p_val > shared->max - shared->page) {
p_val = shared->max - shared->page;
+ }
- if (!shared->allow_lesser && p_val < shared->min)
+ if (!shared->allow_lesser && p_val < shared->min) {
p_val = shared->min;
+ }
- if (shared->val == p_val)
+ if (shared->val == p_val) {
return;
+ }
shared->val = p_val;
shared->emit_value_changed();
}
+
void Range::set_min(double p_min) {
shared->min = p_min;
set_value(shared->val);
@@ -107,19 +110,20 @@ void Range::set_min(double p_min) {
update_configuration_warning();
}
+
void Range::set_max(double p_max) {
shared->max = p_max;
set_value(shared->val);
shared->emit_changed("max");
}
-void Range::set_step(double p_step) {
+void Range::set_step(double p_step) {
shared->step = p_step;
shared->emit_changed("step");
}
-void Range::set_page(double p_page) {
+void Range::set_page(double p_page) {
shared->page = p_page;
set_value(shared->val);
@@ -127,37 +131,33 @@ void Range::set_page(double p_page) {
}
double Range::get_value() const {
-
return shared->val;
}
-double Range::get_min() const {
+double Range::get_min() const {
return shared->min;
}
-double Range::get_max() const {
+double Range::get_max() const {
return shared->max;
}
-double Range::get_step() const {
+double Range::get_step() const {
return shared->step;
}
-double Range::get_page() const {
+double Range::get_page() const {
return shared->page;
}
void Range::set_as_ratio(double p_value) {
-
double v;
if (shared->exp_ratio && get_min() >= 0) {
-
double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);
double exp_max = Math::log(get_max()) / Math::log((double)2);
v = Math::pow(2, exp_min + (exp_max - exp_min) * p_value);
} else {
-
double percent = (get_max() - get_min()) * p_value;
if (get_step() > 0) {
double steps = round(percent / get_step());
@@ -169,12 +169,11 @@ void Range::set_as_ratio(double p_value) {
v = CLAMP(v, get_min(), get_max());
set_value(v);
}
-double Range::get_as_ratio() const {
+double Range::get_as_ratio() const {
ERR_FAIL_COND_V_MSG(Math::is_equal_approx(get_max(), get_min()), 0.0, "Cannot get ratio when minimum and maximum value are equal.");
if (shared->exp_ratio && get_min() >= 0) {
-
double exp_min = get_min() == 0 ? 0.0 : Math::log(get_min()) / Math::log((double)2);
double exp_max = Math::log(get_max()) / Math::log((double)2);
float value = CLAMP(get_value(), shared->min, shared->max);
@@ -183,21 +182,18 @@ double Range::get_as_ratio() const {
return CLAMP((v - exp_min) / (exp_max - exp_min), 0, 1);
} else {
-
float value = CLAMP(get_value(), shared->min, shared->max);
return CLAMP((value - get_min()) / (get_max() - get_min()), 0, 1);
}
}
void Range::_share(Node *p_range) {
-
Range *r = Object::cast_to<Range>(p_range);
ERR_FAIL_COND(!r);
share(r);
}
void Range::share(Range *p_range) {
-
ERR_FAIL_NULL(p_range);
p_range->_ref_shared(shared);
@@ -206,7 +202,6 @@ void Range::share(Range *p_range) {
}
void Range::unshare() {
-
Shared *nshared = memnew(Shared);
nshared->min = shared->min;
nshared->max = shared->max;
@@ -221,9 +216,9 @@ void Range::unshare() {
}
void Range::_ref_shared(Shared *p_shared) {
-
- if (shared && p_shared == shared)
+ if (shared && p_shared == shared) {
return;
+ }
_unref_shared();
shared = p_shared;
@@ -231,18 +226,16 @@ void Range::_ref_shared(Shared *p_shared) {
}
void Range::_unref_shared() {
-
if (shared) {
shared->owners.erase(this);
if (shared->owners.size() == 0) {
memdelete(shared);
- shared = NULL;
+ shared = nullptr;
}
}
}
void Range::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_value"), &Range::get_value);
ClassDB::bind_method(D_METHOD("get_min"), &Range::get_min);
ClassDB::bind_method(D_METHOD("get_max"), &Range::get_max);
@@ -283,49 +276,40 @@ void Range::_bind_methods() {
}
void Range::set_use_rounded_values(bool p_enable) {
-
_rounded_values = p_enable;
}
bool Range::is_using_rounded_values() const {
-
return _rounded_values;
}
void Range::set_exp_ratio(bool p_enable) {
-
shared->exp_ratio = p_enable;
update_configuration_warning();
}
bool Range::is_ratio_exp() const {
-
return shared->exp_ratio;
}
void Range::set_allow_greater(bool p_allow) {
-
shared->allow_greater = p_allow;
}
bool Range::is_greater_allowed() const {
-
return shared->allow_greater;
}
void Range::set_allow_lesser(bool p_allow) {
-
shared->allow_lesser = p_allow;
}
bool Range::is_lesser_allowed() const {
-
return shared->allow_lesser;
}
Range::Range() {
-
shared = memnew(Shared);
shared->min = 0;
shared->max = 100;
@@ -341,6 +325,5 @@ Range::Range() {
}
Range::~Range() {
-
_unref_shared();
}
diff --git a/scene/gui/range.h b/scene/gui/range.h
index 819d76941b..fe43985d0d 100644
--- a/scene/gui/range.h
+++ b/scene/gui/range.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class Range : public Control {
-
GDCLASS(Range, Control);
struct Shared {
diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp
index 0765e5d882..27c57c684a 100644
--- a/scene/gui/reference_rect.cpp
+++ b/scene/gui/reference_rect.cpp
@@ -33,13 +33,13 @@
#include "core/engine.h"
void ReferenceRect::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (Engine::get_singleton()->is_editor_hint() || !editor_only)
+ }
+ if (Engine::get_singleton()->is_editor_hint() || !editor_only) {
draw_rect(Rect2(Point2(), get_size()), border_color, false);
+ }
}
}
diff --git a/scene/gui/reference_rect.h b/scene/gui/reference_rect.h
index c25c54f271..db2f4269f3 100644
--- a/scene/gui/reference_rect.h
+++ b/scene/gui/reference_rect.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class ReferenceRect : public Control {
-
GDCLASS(ReferenceRect, Control);
Color border_color;
bool editor_only;
diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp
index 0f5926ea1c..2628e5ab0f 100644
--- a/scene/gui/rich_text_effect.cpp
+++ b/scene/gui/rich_text_effect.cpp
@@ -64,7 +64,6 @@ RichTextEffect::RichTextEffect() {
}
void CharFXTransform::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("get_relative_index"), &CharFXTransform::get_relative_index);
ClassDB::bind_method(D_METHOD("set_relative_index", "index"), &CharFXTransform::set_relative_index);
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index df28a4c12f..2f5af0eda0 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -46,16 +46,12 @@
#endif
RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
-
if (p_free) {
-
if (p_item->subitems.size()) {
-
return p_item->subitems.front()->get();
} else if (!p_item->parent) {
- return NULL;
+ return nullptr;
} else if (p_item->E->next()) {
-
return p_item->E->next()->get();
} else {
//go up until something with a next is found
@@ -63,20 +59,19 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->parent)
+ if (p_item->parent) {
return p_item->E->next()->get();
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
} else {
if (p_item->subitems.size() && p_item->type != ITEM_TABLE) {
-
return p_item->subitems.front()->get();
} else if (p_item->type == ITEM_FRAME) {
- return NULL;
+ return nullptr;
} else if (p_item->E->next()) {
-
return p_item->E->next()->get();
} else {
//go up until something with a next is found
@@ -84,26 +79,24 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->type != ITEM_FRAME)
+ if (p_item->type != ITEM_FRAME) {
return p_item->E->next()->get();
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
}
- return NULL;
+ return nullptr;
}
RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
if (p_free) {
-
if (p_item->subitems.size()) {
-
return p_item->subitems.back()->get();
} else if (!p_item->parent) {
- return NULL;
+ return nullptr;
} else if (p_item->E->prev()) {
-
return p_item->E->prev()->get();
} else {
//go back until something with a prev is found
@@ -111,20 +104,19 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->parent)
+ if (p_item->parent) {
return p_item->E->prev()->get();
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
} else {
if (p_item->subitems.size() && p_item->type != ITEM_TABLE) {
-
return p_item->subitems.back()->get();
} else if (p_item->type == ITEM_FRAME) {
- return NULL;
+ return nullptr;
} else if (p_item->E->prev()) {
-
return p_item->E->prev()->get();
} else {
//go back until something with a prev is found
@@ -132,14 +124,15 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
p_item = p_item->parent;
}
- if (p_item->type != ITEM_FRAME)
+ if (p_item->type != ITEM_FRAME) {
return p_item->E->prev()->get();
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
}
- return NULL;
+ return nullptr;
}
Rect2 RichTextLabel::_get_text_rect() {
@@ -148,17 +141,18 @@ Rect2 RichTextLabel::_get_text_rect() {
}
int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) {
-
ERR_FAIL_INDEX_V((int)p_mode, 3, 0);
RID ci;
- if (r_outside)
+ if (r_outside) {
*r_outside = false;
+ }
if (p_mode == PROCESS_DRAW) {
ci = get_canvas_item();
- if (r_click_item)
- *r_click_item = NULL;
+ if (r_click_item) {
+ *r_click_item = nullptr;
+ }
}
Line &l = p_frame->lines.write[p_line];
Item *it = l.from;
@@ -172,7 +166,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int height = get_size().y;
if (p_mode != PROCESS_CACHE) {
-
ERR_FAIL_INDEX_V(line, l.offset_caches.size(), 0);
line_ofs = l.offset_caches[line];
}
@@ -191,14 +184,16 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int spaces_size = 0;
int align_ofs = 0;
- if (p_mode != PROCESS_CACHE && align != ALIGN_FILL)
+ if (p_mode != PROCESS_CACHE && align != ALIGN_FILL) {
wofs += line_ofs;
+ }
int begin = wofs;
Ref<Font> cfont = _find_font(it);
- if (cfont.is_null())
+ if (cfont.is_null()) {
cfont = p_base_font;
+ }
//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();
@@ -230,10 +225,18 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} else { \
int used = wofs - margin; \
switch (align) { \
- case ALIGN_LEFT: l.offset_caches.push_back(0); break; \
- case ALIGN_CENTER: l.offset_caches.push_back(((p_width - margin) - used) / 2); break; \
- case ALIGN_RIGHT: l.offset_caches.push_back(((p_width - margin) - used)); break; \
- case ALIGN_FILL: l.offset_caches.push_back(line_wrapped ? ((p_width - margin) - used) : 0); break; \
+ case ALIGN_LEFT: \
+ l.offset_caches.push_back(0); \
+ break; \
+ case ALIGN_CENTER: \
+ l.offset_caches.push_back(((p_width - margin) - used) / 2); \
+ break; \
+ case ALIGN_RIGHT: \
+ l.offset_caches.push_back(((p_width - margin) - used)); \
+ break; \
+ case ALIGN_FILL: \
+ l.offset_caches.push_back(line_wrapped ? ((p_width - margin) - used) : 0); \
+ break; \
} \
l.height_caches.push_back(line_height); \
l.ascent_caches.push_back(line_ascent); \
@@ -253,9 +256,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
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_DRAW) { \
+ if (line < l.offset_caches.size()) { \
+ wofs = l.offset_caches[line]; \
+ } \
+ } \
} \
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; \
+ if (r_outside) \
+ *r_outside = true; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
@@ -275,7 +284,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} \
const bool x_in_range = (p_click_pos.x > p_ofs.x + wofs) && (!p_frame->cell || p_click_pos.x < p_ofs.x + p_width); \
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 && x_in_range) { \
- if (r_outside) *r_outside = true; \
+ if (r_outside) \
+ *r_outside = true; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
@@ -286,7 +296,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
#define ADVANCE(m_width) \
{ \
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 && p_click_pos.x < p_ofs.x + wofs + m_width) { \
- if (r_outside) *r_outside = false; \
+ if (r_outside) \
+ *r_outside = false; \
*r_click_item = it; \
*r_click_char = rchar; \
RETURN; \
@@ -317,18 +328,14 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int fh = 0;
while (it) {
-
switch (it->type) {
-
case ITEM_ALIGN: {
-
ItemAlign *align_it = static_cast<ItemAlign *>(it);
align = align_it->align;
} break;
case ITEM_INDENT: {
-
if (it != l.from) {
ItemIndent *indent_it = static_cast<ItemIndent *>(it);
@@ -340,12 +347,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_TEXT: {
-
ItemText *text = static_cast<ItemText *>(it);
Ref<Font> font = _find_font(it);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
const CharType *c = text->text.c_str();
const CharType *cf = c;
@@ -356,7 +363,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
Color font_color_shadow;
bool underline = false;
bool strikethrough = false;
- ItemFade *fade = NULL;
+ ItemFade *fade = nullptr;
int it_char_start = p_char_count;
Vector<ItemFX *> fx_stack = Vector<ItemFX *>();
@@ -388,7 +395,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
rchar = 0;
FontDrawer drawer(font, Color(1, 1, 1));
while (*c) {
-
int end = 0;
int w = 0;
int fw = 0;
@@ -401,23 +407,21 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1;
}
while (c[end] != 0 && !(end && c[end - 1] == ' ' && c[end] != ' ')) {
-
int cw = font->get_char_size(c[end], c[end + 1]).width;
if (c[end] == '\t') {
cw = tab_size * font->get_char_size(' ').width;
}
- if (end > 0 && w + cw + begin > p_width) {
+ if (end > 0 && fw + cw + begin > p_width) {
break; //don't allow lines longer than assigned width
}
- w += cw;
fw += cw;
end++;
}
CHECK_HEIGHT(fh);
- ENSURE_WIDTH(w);
+ ENSURE_WIDTH(fw);
line_ascent = MAX(line_ascent, ascent);
line_descent = MAX(line_descent, descent);
@@ -436,14 +440,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
}
{
-
int ofs = 0 - backtrack;
for (int i = 0; i < end; i++) {
int pofs = wofs + ofs;
if (p_mode == PROCESS_POINTER && r_click_char && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
-
int cw = font->get_char_size(c[i], c[i + 1]).x;
if (c[i] == '\t') {
@@ -451,7 +453,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
}
if (p_click_pos.x - cw / 2 > p_ofs.x + align_ofs + pofs) {
-
rchar = int((&c[i]) - cf);
}
@@ -463,7 +464,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
CharType fx_char = c[i];
if (selection.active) {
-
int cofs = (&c[i]) - cf;
if ((text->index > selection.from->index || (text->index == selection.from->index && cofs >= selection.from_char)) && (text->index < selection.to->index || (text->index == selection.to->index && cofs <= selection.to_char))) {
selected = true;
@@ -488,7 +488,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
const bool previously_visible = visible;
for (int j = 0; j < fx_stack.size(); j++) {
-
ItemFX *item_fx = fx_stack[j];
if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) {
@@ -552,14 +551,16 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
}
}
- if (visible)
+ if (visible) {
line_is_blank = false;
+ w += font->get_char_size(c[i], c[i + 1]).x;
+ }
- if (c[i] == '\t')
+ if (c[i] == '\t') {
visible = false;
+ }
if (visible) {
-
if (selected) {
cw = font->get_char_size(fx_char, c[i + 1]).x;
draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg);
@@ -582,13 +583,14 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} else {
cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color);
}
- } else if (previously_visible) {
+ } else if (previously_visible && c[i] != '\t') {
backtrack += font->get_char_size(fx_char, c[i + 1]).x;
}
p_char_count++;
if (c[i] == '\t') {
cw = tab_size * font->get_char_size(' ').width;
+ backtrack = MAX(0, backtrack - cw);
}
ofs += cw;
@@ -598,21 +600,21 @@ 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 - line_descent + 2;
- float underline_width = 1.0;
+ int uy = y + lh - line_descent + font->get_underline_position();
+ float underline_width = font->get_underline_thickness();
#ifdef TOOLS_ENABLED
underline_width *= EDSCALE;
#endif
- VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width);
+ RS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width);
} else if (strikethrough) {
Color uc = color;
uc.a *= 0.5;
- int uy = y + lh / 2 - line_descent + 2;
- float strikethrough_width = 1.0;
+ int uy = y + lh - (line_ascent + line_descent) / 2;
+ float strikethrough_width = font->get_underline_thickness();
#ifdef TOOLS_ENABLED
strikethrough_width *= EDSCALE;
#endif
- VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, strikethrough_width);
+ RS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, strikethrough_width);
}
}
@@ -623,30 +625,33 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_IMAGE: {
-
lh = 0;
- if (p_mode != PROCESS_CACHE)
+ if (p_mode != PROCESS_CACHE) {
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
- else
+ } else {
l.char_count += 1; //images count as chars too
+ }
ItemImage *img = static_cast<ItemImage *>(it);
Ref<Font> font = _find_font(it);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
- if (p_mode == PROCESS_POINTER && r_click_char)
+ if (p_mode == PROCESS_POINTER && r_click_char) {
*r_click_char = 0;
+ }
ENSURE_WIDTH(img->size.width);
bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->size.height, img->size.height));
- if (visible)
+ if (visible) {
line_is_blank = false;
+ }
if (p_mode == PROCESS_DRAW && visible) {
- img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size));
+ img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size), false, img->color);
}
p_char_count++;
@@ -655,7 +660,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_NEWLINE: {
-
lh = 0;
if (p_mode != PROCESS_CACHE) {
@@ -665,7 +669,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_TABLE: {
-
lh = 0;
ItemTable *table = static_cast<ItemTable *>(it);
int hseparation = get_theme_constant("table_hseparation");
@@ -677,7 +680,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
Point2 shadow_ofs2(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
if (p_mode == PROCESS_CACHE) {
-
int idx = 0;
//set minimums to zero
for (int i = 0; i < table->columns.size(); i++) {
@@ -697,7 +699,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int ly = 0;
for (int i = 0; i < frame->lines.size(); i++) {
-
_process_line(frame, Point2(), ly, available_width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2);
table->columns.write[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].minimum_width);
table->columns.write[column].max_width = MAX(table->columns[column].max_width, frame->lines[i].maximum_width);
@@ -713,17 +714,20 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
for (int i = 0; i < table->columns.size(); i++) {
remaining_width -= table->columns[i].min_width;
- if (table->columns[i].max_width > table->columns[i].min_width)
+ if (table->columns[i].max_width > table->columns[i].min_width) {
table->columns.write[i].expand = true;
- if (table->columns[i].expand)
+ }
+ if (table->columns[i].expand) {
total_ratio += table->columns[i].expand_ratio;
+ }
}
//assign actual widths
for (int i = 0; i < table->columns.size(); i++) {
table->columns.write[i].width = table->columns[i].min_width;
- if (table->columns[i].expand && total_ratio > 0)
+ if (table->columns[i].expand && total_ratio > 0) {
table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
+ }
table->total_width += table->columns[i].width + hseparation;
}
@@ -733,8 +737,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
table_need_fit = false;
//fit slim
for (int i = 0; i < table->columns.size(); i++) {
- if (!table->columns[i].expand)
+ if (!table->columns[i].expand) {
continue;
+ }
int dif = table->columns[i].width - table->columns[i].max_width;
if (dif > 0) {
table_need_fit = true;
@@ -769,7 +774,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int column = idx % table->columns.size();
for (int i = 0; i < frame->lines.size(); i++) {
-
int ly = 0;
_process_line(frame, Point2(), ly, table->columns[column].width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2);
frame->lines.write[i].height_cache = ly; //actual height
@@ -797,11 +801,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
int lines_ofs = p_ofs.y + offset.y + draw_ofs.y;
bool visible = lines_ofs < get_size().height && lines_ofs + lines_h >= 0;
- if (visible)
+ if (visible) {
line_is_blank = false;
+ }
for (int i = 0; i < frame->lines.size(); i++) {
-
if (visible) {
if (p_mode == PROCESS_DRAW) {
nonblank_line_count += _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_DRAW, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs2);
@@ -823,7 +827,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
offset.x += table->columns[column].width + hseparation;
if (column == table->columns.size() - 1) {
-
offset.y += row_height + vseparation;
offset.x = hseparation;
row_height = 0;
@@ -850,10 +853,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
it = _get_next_item(it);
if (it && (p_line + 1 < p_frame->lines.size()) && p_frame->lines[p_line + 1].from == it) {
-
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) {
//went to next line, but pointer was on the previous one
- if (r_outside) *r_outside = true;
+ if (r_outside) {
+ *r_outside = true;
+ }
*r_click_item = itp;
*r_click_char = rchar;
RETURN;
@@ -874,14 +878,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
}
void RichTextLabel::_scroll_changed(double) {
-
- if (updating_scroll || !scroll_active)
+ if (updating_scroll) {
return;
+ }
- if (scroll_follow && vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page()))
+ if (scroll_follow && vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page())) {
scroll_following = true;
- else
+ } else {
scroll_following = false;
+ }
scroll_updated = true;
@@ -889,13 +894,11 @@ void RichTextLabel::_scroll_changed(double) {
}
void RichTextLabel::_update_scroll() {
-
int total_height = get_content_height();
bool exceeds = total_height > get_size().height && scroll_active;
if (exceeds != scroll_visible) {
-
if (exceeds) {
scroll_visible = true;
scroll_w = vscroll->get_combined_minimum_size().width;
@@ -915,7 +918,7 @@ void RichTextLabel::_update_scroll() {
void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, float p_delta_time) {
Item *it = p_frame;
while (it) {
- ItemFX *ifx = NULL;
+ ItemFX *ifx = nullptr;
if (it->type == ITEM_CUSTOMFX || it->type == ITEM_SHAKE || it->type == ITEM_WAVE || it->type == ITEM_TORNADO || it->type == ITEM_RAINBOW) {
ifx = static_cast<ItemFX *>(it);
@@ -928,7 +931,7 @@ void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, float p_delta_
ifx->elapsed_time += p_delta_time;
- ItemShake *shake = NULL;
+ ItemShake *shake = nullptr;
if (it->type == ITEM_SHAKE) {
shake = static_cast<ItemShake *>(it);
@@ -947,39 +950,34 @@ void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, float p_delta_
}
void RichTextLabel::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_MOUSE_EXIT: {
if (meta_hovering) {
- meta_hovering = NULL;
+ meta_hovering = nullptr;
emit_signal("meta_hover_ended", current_meta);
current_meta = false;
update();
}
} break;
case NOTIFICATION_RESIZED: {
-
main->first_invalid_line = 0; //invalidate ALL
update();
} break;
case NOTIFICATION_ENTER_TREE: {
-
- if (bbcode != "")
+ if (bbcode != "") {
set_bbcode(bbcode);
+ }
main->first_invalid_line = 0; //invalidate ALL
update();
} break;
case NOTIFICATION_THEME_CHANGED: {
-
update();
} break;
case NOTIFICATION_DRAW: {
-
_validate_line_caches(main);
_update_scroll();
@@ -991,9 +989,9 @@ void RichTextLabel::_notification(int p_what) {
draw_style_box(get_theme_stylebox("normal"), Rect2(Point2(), size));
if (has_focus()) {
- VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
draw_style_box(get_theme_stylebox("focus"), Rect2(Point2(), size));
- VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
}
int ofs = vscroll->get_value();
@@ -1003,15 +1001,16 @@ void RichTextLabel::_notification(int p_what) {
int from_line = 0;
int total_chars = 0;
while (from_line < main->lines.size()) {
-
- if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs)
+ if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs) {
break;
+ }
total_chars += main->lines[from_line].char_count;
from_line++;
}
- if (from_line >= main->lines.size())
+ if (from_line >= main->lines.size()) {
break; //nothing to draw
+ }
int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs;
Ref<Font> base_font = get_theme_font("normal_font");
Color base_color = get_theme_color("default_color");
@@ -1021,8 +1020,7 @@ void RichTextLabel::_notification(int p_what) {
visible_line_count = 0;
while (y < size.height && from_line < main->lines.size()) {
-
- visible_line_count += _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, Point2i(), NULL, NULL, NULL, total_chars);
+ visible_line_count += _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, Point2i(), nullptr, nullptr, nullptr, total_chars);
total_chars += main->lines[from_line].char_count;
from_line++;
@@ -1038,9 +1036,9 @@ void RichTextLabel::_notification(int p_what) {
}
void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item, int *r_click_char, bool *r_outside) {
-
- if (r_click_item)
- *r_click_item = NULL;
+ if (r_click_item) {
+ *r_click_item = nullptr;
+ }
Rect2 text_rect = _get_text_rect();
int ofs = vscroll->get_value();
@@ -1052,79 +1050,81 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
int from_line = 0;
while (from_line < p_frame->lines.size()) {
-
- if (p_frame->lines[from_line].height_accum_cache >= ofs)
+ if (p_frame->lines[from_line].height_accum_cache >= ofs) {
break;
+ }
from_line++;
}
- if (from_line >= p_frame->lines.size())
+ if (from_line >= p_frame->lines.size()) {
return;
+ }
int y = (p_frame->lines[from_line].height_accum_cache - p_frame->lines[from_line].height_cache) - ofs;
Ref<Font> base_font = get_theme_font("normal_font");
Color base_color = get_theme_color("default_color");
while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) {
-
_process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_POINTER, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, p_click, r_click_item, r_click_char, r_outside);
- if (r_click_item && *r_click_item)
+ if (r_click_item && *r_click_item) {
return;
+ }
from_line++;
}
}
Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const {
-
- if (!underline_meta)
+ if (!underline_meta) {
return CURSOR_ARROW;
+ }
- if (selection.click)
+ if (selection.click) {
return CURSOR_IBEAM;
+ }
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return CURSOR_ARROW; //invalid
+ }
int line = 0;
- Item *item = NULL;
+ Item *item = nullptr;
bool outside;
((RichTextLabel *)(this))->_find_click(main, p_pos, &item, &line, &outside);
- if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, NULL))
+ if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, nullptr)) {
return CURSOR_POINTING_HAND;
+ }
return CURSOR_ARROW;
}
void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
-
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return;
+ }
if (b->get_button_index() == BUTTON_LEFT) {
if (b->is_pressed() && !b->is_doubleclick()) {
scroll_updated = false;
int line = 0;
- Item *item = NULL;
+ Item *item = nullptr;
bool outside;
_find_click(main, b->get_position(), &item, &line, &outside);
if (item) {
-
if (selection.enabled) {
-
selection.click = item;
selection.click_char = line;
// Erase previous selection.
if (selection.active) {
- selection.from = NULL;
+ selection.from = nullptr;
selection.from_char = '\0';
- selection.to = NULL;
+ selection.to = nullptr;
selection.to_char = '\0';
selection.active = false;
@@ -1133,26 +1133,22 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
}
} else if (b->is_pressed() && b->is_doubleclick() && selection.enabled) {
-
//doubleclick: select word
int line = 0;
- Item *item = NULL;
+ Item *item = nullptr;
bool outside;
_find_click(main, b->get_position(), &item, &line, &outside);
while (item && item->type != ITEM_TEXT) {
-
item = _get_next_item(item, true);
}
if (item && item->type == ITEM_TEXT) {
-
String itext = static_cast<ItemText *>(item)->text;
int beg, end;
if (select_word(itext, line, beg, end)) {
-
selection.from = item;
selection.to = item;
selection.from_char = beg;
@@ -1162,18 +1158,16 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
}
} else if (!b->is_pressed()) {
-
- selection.click = NULL;
+ selection.click = nullptr;
if (!b->is_doubleclick() && !scroll_updated) {
int line = 0;
- Item *item = NULL;
+ Item *item = nullptr;
bool outside;
_find_click(main, b->get_position(), &item, &line, &outside);
if (item) {
-
Variant meta;
if (!outside && _find_meta(item, &meta)) {
//meta clicked
@@ -1186,21 +1180,22 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
if (b->get_button_index() == BUTTON_WHEEL_UP) {
- if (scroll_active)
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() - vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
}
if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
- if (scroll_active)
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
}
}
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
-
- if (scroll_active)
-
+ if (scroll_active) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8);
+ }
return;
}
@@ -1212,42 +1207,36 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
bool handled = false;
switch (k->get_keycode()) {
case KEY_PAGEUP: {
-
if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() - vscroll->get_page());
handled = true;
}
} break;
case KEY_PAGEDOWN: {
-
if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() + vscroll->get_page());
handled = true;
}
} break;
case KEY_UP: {
-
if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height());
handled = true;
}
} break;
case KEY_DOWN: {
-
if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height());
handled = true;
}
} break;
case KEY_HOME: {
-
if (vscroll->is_visible_in_tree()) {
vscroll->set_value(0);
handled = true;
}
} break;
case KEY_END: {
-
if (vscroll->is_visible_in_tree()) {
vscroll->set_value(vscroll->get_max());
handled = true;
@@ -1255,7 +1244,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_INSERT:
case KEY_C: {
-
if (k->get_command()) {
selection_copy();
handled = true;
@@ -1264,26 +1252,28 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
} break;
}
- if (handled)
+ if (handled) {
accept_event();
+ }
}
}
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
- if (main->first_invalid_line < main->lines.size())
+ if (main->first_invalid_line < main->lines.size()) {
return;
+ }
int line = 0;
- Item *item = NULL;
+ Item *item = nullptr;
bool outside;
_find_click(main, m->get_position(), &item, &line, &outside);
if (selection.click) {
-
- if (!item)
+ if (!item) {
return; // do not update
+ }
selection.from = selection.click;
selection.from_char = selection.click_char;
@@ -1292,13 +1282,12 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
selection.to_char = line;
bool swap = false;
- if (selection.from->index > selection.to->index)
+ if (selection.from->index > selection.to->index) {
swap = true;
- else if (selection.from->index == selection.to->index) {
- if (selection.from_char > selection.to_char)
+ } else if (selection.from->index == selection.to->index) {
+ if (selection.from_char > selection.to_char) {
swap = true;
- else if (selection.from_char == selection.to_char) {
-
+ } else if (selection.from_char == selection.to_char) {
selection.active = false;
return;
}
@@ -1325,7 +1314,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
emit_signal("meta_hover_started", meta);
}
} else if (meta_hovering) {
- meta_hovering = NULL;
+ meta_hovering = nullptr;
emit_signal("meta_hover_ended", current_meta);
current_meta = false;
}
@@ -1333,13 +1322,10 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
Ref<Font> RichTextLabel::_find_font(Item *p_item) {
-
Item *fontitem = p_item;
while (fontitem) {
-
if (fontitem->type == ITEM_FONT) {
-
ItemFont *fi = static_cast<ItemFont *>(fontitem);
return fi->font;
}
@@ -1351,28 +1337,26 @@ Ref<Font> RichTextLabel::_find_font(Item *p_item) {
}
int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
-
Item *item = p_item;
int margin = 0;
while (item) {
-
if (item->type == ITEM_INDENT) {
-
Ref<Font> font = _find_font(item);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
ItemIndent *indent = static_cast<ItemIndent *>(item);
margin += indent->level * tab_size * font->get_char_size(' ').width;
} else if (item->type == ITEM_LIST) {
-
Ref<Font> font = _find_font(item);
- if (font.is_null())
+ if (font.is_null()) {
font = p_base_font;
+ }
}
item = item->parent;
@@ -1382,13 +1366,10 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
}
RichTextLabel::Align RichTextLabel::_find_align(Item *p_item) {
-
Item *item = p_item;
while (item) {
-
if (item->type == ITEM_ALIGN) {
-
ItemAlign *align = static_cast<ItemAlign *>(item);
return align->align;
}
@@ -1400,13 +1381,10 @@ RichTextLabel::Align RichTextLabel::_find_align(Item *p_item) {
}
Color RichTextLabel::_find_color(Item *p_item, const Color &p_default_color) {
-
Item *item = p_item;
while (item) {
-
if (item->type == ITEM_COLOR) {
-
ItemColor *color = static_cast<ItemColor *>(item);
return color->color;
}
@@ -1418,13 +1396,10 @@ Color RichTextLabel::_find_color(Item *p_item, const Color &p_default_color) {
}
bool RichTextLabel::_find_underline(Item *p_item) {
-
Item *item = p_item;
while (item) {
-
if (item->type == ITEM_UNDERLINE) {
-
return true;
}
@@ -1435,13 +1410,10 @@ bool RichTextLabel::_find_underline(Item *p_item) {
}
bool RichTextLabel::_find_strikethrough(Item *p_item) {
-
Item *item = p_item;
while (item) {
-
if (item->type == ITEM_STRIKETHROUGH) {
-
return true;
}
@@ -1452,7 +1424,6 @@ bool RichTextLabel::_find_strikethrough(Item *p_item) {
}
bool RichTextLabel::_find_by_type(Item *p_item, ItemType p_type) {
-
ERR_FAIL_INDEX_V((int)p_type, 19, false);
Item *item = p_item;
@@ -1477,18 +1448,58 @@ void RichTextLabel::_fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack
}
}
+Color RichTextLabel::_get_color_from_string(const String &p_color_str, const Color &p_default_color) {
+ if (p_color_str.begins_with("#")) {
+ return Color::html(p_color_str);
+ } else if (p_color_str == "aqua") {
+ return Color(0, 1, 1);
+ } else if (p_color_str == "black") {
+ return Color(0, 0, 0);
+ } else if (p_color_str == "blue") {
+ return Color(0, 0, 1);
+ } else if (p_color_str == "fuchsia") {
+ return Color(1, 0, 1);
+ } else if (p_color_str == "gray" || p_color_str == "grey") {
+ return Color(0.5, 0.5, 0.5);
+ } else if (p_color_str == "green") {
+ return Color(0, 0.5, 0);
+ } else if (p_color_str == "lime") {
+ return Color(0, 1, 0);
+ } else if (p_color_str == "maroon") {
+ return Color(0.5, 0, 0);
+ } else if (p_color_str == "navy") {
+ return Color(0, 0, 0.5);
+ } else if (p_color_str == "olive") {
+ return Color(0.5, 0.5, 0);
+ } else if (p_color_str == "purple") {
+ return Color(0.5, 0, 0.5);
+ } else if (p_color_str == "red") {
+ return Color(1, 0, 0);
+ } else if (p_color_str == "silver") {
+ return Color(0.75, 0.75, 0.75);
+ } else if (p_color_str == "teal") {
+ return Color(0, 0.5, 0.5);
+ } else if (p_color_str == "white") {
+ return Color(1, 1, 1);
+ } else if (p_color_str == "yellow") {
+ return Color(1, 1, 0);
+ } else {
+ return p_default_color;
+ }
+}
+
bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) {
Item *item = p_item;
while (item) {
-
if (item->type == ITEM_META) {
-
ItemMeta *meta = static_cast<ItemMeta *>(item);
- if (r_meta)
+ if (r_meta) {
*r_meta = meta->meta;
- if (r_item)
+ }
+ if (r_item) {
*r_item = meta;
+ }
return true;
}
@@ -1499,16 +1510,17 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item)
}
bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
-
if (from && from != to) {
- if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH)
+ if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) {
return true;
+ }
for (List<Item *>::Element *E = from->subitems.front(); E; E = E->next()) {
bool layout = _find_layout_subitem(E->get(), to);
- if (layout)
+ if (layout) {
return true;
+ }
}
}
@@ -1516,9 +1528,9 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
}
void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
-
- if (p_frame->first_invalid_line == p_frame->lines.size())
+ if (p_frame->first_invalid_line == p_frame->lines.size()) {
return;
+ }
//validate invalid lines
Size2 size = get_size();
@@ -1533,67 +1545,64 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
Ref<Font> base_font = get_theme_font("normal_font");
for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) {
-
int y = 0;
_process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, i, PROCESS_CACHE, base_font, Color(), font_color_shadow, use_outline, shadow_ofs);
p_frame->lines.write[i].height_cache = y;
p_frame->lines.write[i].height_accum_cache = y;
- if (i > 0)
+ if (i > 0) {
p_frame->lines.write[i].height_accum_cache += p_frame->lines[i - 1].height_accum_cache;
+ }
}
int total_height = 0;
- if (p_frame->lines.size())
+ if (p_frame->lines.size()) {
total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ }
main->first_invalid_line = p_frame->lines.size();
updating_scroll = true;
vscroll->set_max(total_height);
vscroll->set_page(size.height);
- if (scroll_follow && scroll_following)
+ if (scroll_follow && scroll_following) {
vscroll->set_value(total_height - size.height);
+ }
updating_scroll = false;
}
void RichTextLabel::_invalidate_current_line(ItemFrame *p_frame) {
-
if (p_frame->lines.size() - 1 <= p_frame->first_invalid_line) {
-
p_frame->first_invalid_line = p_frame->lines.size() - 1;
update();
}
}
void RichTextLabel::add_text(const String &p_text) {
-
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return; //can't add anything here
+ }
int pos = 0;
while (pos < p_text.length()) {
-
int end = p_text.find("\n", pos);
String line;
bool eol = false;
if (end == -1) {
-
end = p_text.length();
} else {
-
eol = true;
}
- if (pos == 0 && end == p_text.length())
+ if (pos == 0 && end == p_text.length()) {
line = p_text;
- else
+ } else {
line = p_text.substr(pos, end - pos);
+ }
if (line.length() > 0) {
-
if (current->subitems.size() && current->subitems.back()->get()->type == ITEM_TEXT) {
//append text condition!
ItemText *ti = static_cast<ItemText *>(current->subitems.back()->get());
@@ -1609,13 +1618,13 @@ void RichTextLabel::add_text(const String &p_text) {
}
if (eol) {
-
ItemNewline *item = memnew(ItemNewline);
item->line = current_frame->lines.size();
_add_item(item, false);
current_frame->lines.resize(current_frame->lines.size() + 1);
- if (item->type != ITEM_NEWLINE)
+ if (item->type != ITEM_NEWLINE) {
current_frame->lines.write[current_frame->lines.size() - 1].from = item;
+ }
_invalidate_current_line(current_frame);
}
@@ -1624,13 +1633,13 @@ void RichTextLabel::add_text(const String &p_text) {
}
void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) {
-
p_item->parent = current;
p_item->E = current->subitems.push_back(p_item);
p_item->index = current_idx++;
- if (p_enter)
+ if (p_enter) {
current = p_item;
+ }
if (p_ensure_newline) {
Item *from = current_frame->lines[current_frame->lines.size() - 1].from;
@@ -1641,7 +1650,7 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline)
}
}
- if (current_frame->lines[current_frame->lines.size() - 1].from == NULL) {
+ if (current_frame->lines[current_frame->lines.size() - 1].from == nullptr) {
current_frame->lines.write[current_frame->lines.size() - 1].from = p_item;
}
p_item->line = current_frame->lines.size() - 1;
@@ -1654,15 +1663,15 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline)
}
void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_subitem_line) {
-
int size = p_item->subitems.size();
if (size == 0) {
p_item->parent->subitems.erase(p_item);
if (p_item->type == ITEM_NEWLINE) {
current_frame->lines.remove(p_line);
for (int i = p_subitem_line; i < current->subitems.size(); i++) {
- if (current->subitems[i]->line > 0)
+ if (current->subitems[i]->line > 0) {
current->subitems[i]->line--;
+ }
}
}
} else {
@@ -1672,15 +1681,16 @@ 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) {
-
- if (current->type == ITEM_TABLE)
+void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color) {
+ if (current->type == ITEM_TABLE) {
return;
+ }
ERR_FAIL_COND(p_image.is_null());
ItemImage *item = memnew(ItemImage);
item->image = p_image;
+ item->color = p_color;
if (p_width > 0) {
// custom width
@@ -1709,9 +1719,9 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width,
}
void RichTextLabel::add_newline() {
-
- if (current->type == ITEM_TABLE)
+ if (current->type == ITEM_TABLE) {
return;
+ }
ItemNewline *item = memnew(ItemNewline);
item->line = current_frame->lines.size();
_add_item(item, false);
@@ -1720,9 +1730,9 @@ void RichTextLabel::add_newline() {
}
bool RichTextLabel::remove_line(const int p_line) {
-
- if (p_line >= current_frame->lines.size() || p_line < 0)
+ if (p_line >= current_frame->lines.size() || p_line < 0) {
return false;
+ }
int i = 0;
while (i < current->subitems.size() && current->subitems[i]->line < p_line) {
@@ -1733,8 +1743,9 @@ bool RichTextLabel::remove_line(const int p_line) {
while (i < current->subitems.size()) {
was_newline = current->subitems[i]->type == ITEM_NEWLINE;
_remove_item(current->subitems[i], current->subitems[i]->line, p_line);
- if (was_newline)
+ if (was_newline) {
break;
+ }
}
if (!was_newline) {
@@ -1744,8 +1755,9 @@ bool RichTextLabel::remove_line(const int p_line) {
}
}
- if (p_line == 0 && current->subitems.size() > 0)
+ if (p_line == 0 && current->subitems.size() > 0) {
main->lines.write[0].from = main;
+ }
main->first_invalid_line = 0;
@@ -1753,7 +1765,6 @@ bool RichTextLabel::remove_line(const int p_line) {
}
void RichTextLabel::push_font(const Ref<Font> &p_font) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ERR_FAIL_COND(p_font.is_null());
ItemFont *item = memnew(ItemFont);
@@ -1798,7 +1809,6 @@ void RichTextLabel::push_mono() {
}
void RichTextLabel::push_color(const Color &p_color) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemColor *item = memnew(ItemColor);
@@ -1807,7 +1817,6 @@ void RichTextLabel::push_color(const Color &p_color) {
}
void RichTextLabel::push_underline() {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemUnderline *item = memnew(ItemUnderline);
@@ -1815,7 +1824,6 @@ void RichTextLabel::push_underline() {
}
void RichTextLabel::push_strikethrough() {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemStrikethrough *item = memnew(ItemStrikethrough);
@@ -1823,7 +1831,6 @@ void RichTextLabel::push_strikethrough() {
}
void RichTextLabel::push_align(Align p_align) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemAlign *item = memnew(ItemAlign);
@@ -1832,7 +1839,6 @@ void RichTextLabel::push_align(Align p_align) {
}
void RichTextLabel::push_indent(int p_level) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ERR_FAIL_COND(p_level < 0);
@@ -1842,7 +1848,6 @@ void RichTextLabel::push_indent(int p_level) {
}
void RichTextLabel::push_list(ListType p_list) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ERR_FAIL_INDEX(p_list, 3);
@@ -1853,7 +1858,6 @@ void RichTextLabel::push_list(ListType p_list) {
}
void RichTextLabel::push_meta(const Variant &p_meta) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemMeta *item = memnew(ItemMeta);
@@ -1862,7 +1866,6 @@ void RichTextLabel::push_meta(const Variant &p_meta) {
}
void RichTextLabel::push_table(int p_columns) {
-
ERR_FAIL_COND(p_columns < 1);
ItemTable *item = memnew(ItemTable);
@@ -1919,7 +1922,6 @@ void RichTextLabel::push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionar
}
void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio) {
-
ERR_FAIL_COND(current->type != ITEM_TABLE);
ItemTable *table = static_cast<ItemTable *>(current);
ERR_FAIL_INDEX(p_column, table->columns.size());
@@ -1928,7 +1930,6 @@ void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_r
}
void RichTextLabel::push_cell() {
-
ERR_FAIL_COND(current->type != ITEM_TABLE);
ItemFrame *item = memnew(ItemFrame);
@@ -1938,12 +1939,11 @@ void RichTextLabel::push_cell() {
item->cell = true;
item->parent_line = item->parent_frame->lines.size() - 1;
item->lines.resize(1);
- item->lines.write[0].from = NULL;
+ item->lines.write[0].from = nullptr;
item->first_invalid_line = 0;
}
int RichTextLabel::get_current_table_column() const {
-
ERR_FAIL_COND_V(current->type != ITEM_TABLE, -1);
ItemTable *table = static_cast<ItemTable *>(current);
@@ -1952,7 +1952,6 @@ int RichTextLabel::get_current_table_column() const {
}
void RichTextLabel::pop() {
-
ERR_FAIL_COND(!current->parent);
if (current->type == ITEM_FRAME) {
current_frame = static_cast<ItemFrame *>(current)->parent_frame;
@@ -1961,7 +1960,6 @@ void RichTextLabel::pop() {
}
void RichTextLabel::clear() {
-
main->_clear_children();
current = main;
current_frame = main;
@@ -1969,7 +1967,7 @@ void RichTextLabel::clear() {
main->lines.resize(1);
main->first_invalid_line = 0;
update();
- selection.click = NULL;
+ selection.click = nullptr;
selection.active = false;
current_idx = 1;
@@ -1979,77 +1977,67 @@ void RichTextLabel::clear() {
}
void RichTextLabel::set_tab_size(int p_spaces) {
-
tab_size = p_spaces;
main->first_invalid_line = 0;
update();
}
int RichTextLabel::get_tab_size() const {
-
return tab_size;
}
void RichTextLabel::set_meta_underline(bool p_underline) {
-
underline_meta = p_underline;
update();
}
bool RichTextLabel::is_meta_underlined() const {
-
return underline_meta;
}
void RichTextLabel::set_override_selected_font_color(bool p_override_selected_font_color) {
-
override_selected_font_color = p_override_selected_font_color;
}
bool RichTextLabel::is_overriding_selected_font_color() const {
-
return override_selected_font_color;
}
void RichTextLabel::set_offset(int p_pixel) {
-
vscroll->set_value(p_pixel);
}
void RichTextLabel::set_scroll_active(bool p_active) {
-
- if (scroll_active == p_active)
+ if (scroll_active == p_active) {
return;
+ }
scroll_active = p_active;
+ vscroll->set_drag_node_enabled(p_active);
update();
}
bool RichTextLabel::is_scroll_active() const {
-
return scroll_active;
}
void RichTextLabel::set_scroll_follow(bool p_follow) {
-
scroll_follow = p_follow;
- if (!vscroll->is_visible_in_tree() || vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page()))
+ if (!vscroll->is_visible_in_tree() || vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page())) {
scroll_following = true;
+ }
}
bool RichTextLabel::is_scroll_following() const {
-
return scroll_follow;
}
Error RichTextLabel::parse_bbcode(const String &p_bbcode) {
-
clear();
return append_bbcode(p_bbcode);
}
Error RichTextLabel::append_bbcode(const String &p_bbcode) {
-
int pos = 0;
List<String> tag_stack;
@@ -2069,18 +2057,19 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
set_process_internal(false);
while (pos < p_bbcode.length()) {
-
int brk_pos = p_bbcode.find("[", pos);
- if (brk_pos < 0)
+ if (brk_pos < 0) {
brk_pos = p_bbcode.length();
+ }
if (brk_pos > pos) {
add_text(p_bbcode.substr(pos, brk_pos - pos));
}
- if (brk_pos == p_bbcode.length())
+ if (brk_pos == p_bbcode.length()) {
break; //nothing else to add
+ }
int brk_end = p_bbcode.find("]", brk_pos + 1);
@@ -2091,16 +2080,45 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
String tag = p_bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1);
- if (tag.begins_with("/") && tag_stack.size()) {
+ Vector<String> split_tag_block = tag.split(" ", false);
+
+ // Find optional parameters.
+ String bbcode_name;
+ typedef Map<String, String> OptionMap;
+ OptionMap bbcode_options;
+ if (!split_tag_block.empty()) {
+ bbcode_name = split_tag_block[0];
+ for (int i = 1; i < split_tag_block.size(); i++) {
+ const String &expr = split_tag_block[i];
+ int value_pos = expr.find("=");
+ if (value_pos > -1) {
+ bbcode_options[expr.substr(0, value_pos)] = expr.substr(value_pos + 1);
+ }
+ }
+ } else {
+ bbcode_name = tag;
+ }
+
+ // Find main parameter.
+ String bbcode_value;
+ int main_value_pos = bbcode_name.find("=");
+ if (main_value_pos > -1) {
+ bbcode_value = bbcode_name.substr(main_value_pos + 1);
+ bbcode_name = bbcode_name.substr(0, main_value_pos);
+ }
+ if (tag.begins_with("/") && tag_stack.size()) {
bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
- if (tag_stack.front()->get() == "b")
+ if (tag_stack.front()->get() == "b") {
in_bold = false;
- if (tag_stack.front()->get() == "i")
+ }
+ if (tag_stack.front()->get() == "i") {
in_italics = false;
- if (tag_stack.front()->get() == "indent")
+ }
+ if (tag_stack.front()->get() == "indent") {
indent_level--;
+ }
if (!tag_ok) {
add_text("[" + tag);
@@ -2110,108 +2128,99 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.pop_front();
pos = brk_end + 1;
- if (tag != "/img")
+ if (tag != "/img") {
pop();
+ }
} else if (tag == "b") {
-
//use bold font
in_bold = true;
- if (in_italics)
+ if (in_italics) {
push_font(bold_italics_font);
- else
+ } else {
push_font(bold_font);
+ }
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "i") {
-
//use italics font
in_italics = true;
- if (in_bold)
+ if (in_bold) {
push_font(bold_italics_font);
- else
+ } else {
push_font(italics_font);
+ }
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "code") {
-
//use monospace font
push_font(mono_font);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag.begins_with("table=")) {
-
int columns = tag.substr(6, tag.length()).to_int();
- if (columns < 1)
+ if (columns < 1) {
columns = 1;
+ }
push_table(columns);
pos = brk_end + 1;
tag_stack.push_front("table");
} else if (tag == "cell") {
-
push_cell();
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag.begins_with("cell=")) {
-
int ratio = tag.substr(5, tag.length()).to_int();
- if (ratio < 1)
+ if (ratio < 1) {
ratio = 1;
+ }
set_table_column_expand(get_current_table_column(), true, ratio);
push_cell();
pos = brk_end + 1;
tag_stack.push_front("cell");
} else if (tag == "u") {
-
//use underline
push_underline();
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "s") {
-
//use strikethrough
push_strikethrough();
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "center") {
-
push_align(ALIGN_CENTER);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "fill") {
-
push_align(ALIGN_FILL);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "right") {
-
push_align(ALIGN_RIGHT);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "ul") {
-
push_list(LIST_DOTS);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "ol") {
-
push_list(LIST_NUMBERS);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "indent") {
-
indent_level++;
push_indent(indent_level);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "url") {
-
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String url = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
push_meta(url);
@@ -2219,222 +2228,157 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front(tag);
} else if (tag.begins_with("url=")) {
-
String url = tag.substr(4, tag.length());
push_meta(url);
pos = brk_end + 1;
tag_stack.push_front("url");
- } else if (tag == "img") {
-
+ } else if (bbcode_name == "img") {
int end = p_bbcode.find("[", brk_end);
- if (end == -1)
+ if (end == -1) {
end = p_bbcode.length();
+ }
String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
Ref<Texture2D> texture = ResourceLoader::load(image, "Texture2D");
- if (texture.is_valid())
- add_image(texture);
+ if (texture.is_valid()) {
+ Color color = Color(1.0, 1.0, 1.0);
+ OptionMap::Element *color_option = bbcode_options.find("color");
+ if (color_option) {
+ color = _get_color_from_string(color_option->value(), color);
+ }
- pos = end;
- tag_stack.push_front(tag);
- } else if (tag.begins_with("img=")) {
+ int width = 0;
+ int height = 0;
+ if (!bbcode_value.empty()) {
+ int sep = bbcode_value.find("x");
+ if (sep == -1) {
+ width = bbcode_value.to_int();
+ } else {
+ width = bbcode_value.substr(0, sep).to_int();
+ height = bbcode_value.substr(sep + 1).to_int();
+ }
+ } else {
+ OptionMap::Element *width_option = bbcode_options.find("width");
+ if (width_option) {
+ width = width_option->value().to_int();
+ }
- int width = 0;
- int height = 0;
+ OptionMap::Element *height_option = bbcode_options.find("height");
+ if (height_option) {
+ height = height_option->value().to_int();
+ }
+ }
- String params = tag.substr(4, tag.length());
- int sep = params.find("x");
- if (sep == -1) {
- width = params.to_int();
- } else {
- width = params.substr(0, sep).to_int();
- height = params.substr(sep + 1, params.length()).to_int();
+ add_image(texture, width, height, color);
}
- int end = p_bbcode.find("[", brk_end);
- if (end == -1)
- end = p_bbcode.length();
-
- String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1);
-
- Ref<Texture2D> texture = ResourceLoader::load(image, "Texture");
- if (texture.is_valid())
- add_image(texture, width, height);
-
pos = end;
- tag_stack.push_front("img");
+ tag_stack.push_front(bbcode_name);
} else if (tag.begins_with("color=")) {
-
- String col = tag.substr(6, tag.length());
- Color color;
-
- if (col.begins_with("#"))
- color = Color::html(col);
- else if (col == "aqua")
- color = Color(0, 1, 1);
- else if (col == "black")
- color = Color(0, 0, 0);
- else if (col == "blue")
- color = Color(0, 0, 1);
- else if (col == "fuchsia")
- color = Color(1, 0, 1);
- else if (col == "gray" || col == "grey")
- color = Color(0.5, 0.5, 0.5);
- else if (col == "green")
- color = Color(0, 0.5, 0);
- else if (col == "lime")
- color = Color(0, 1, 0);
- else if (col == "maroon")
- color = Color(0.5, 0, 0);
- else if (col == "navy")
- color = Color(0, 0, 0.5);
- else if (col == "olive")
- color = Color(0.5, 0.5, 0);
- else if (col == "purple")
- color = Color(0.5, 0, 0.5);
- else if (col == "red")
- color = Color(1, 0, 0);
- else if (col == "silver")
- color = Color(0.75, 0.75, 0.75);
- else if (col == "teal")
- color = Color(0, 0.5, 0.5);
- else if (col == "white")
- color = Color(1, 1, 1);
- else if (col == "yellow")
- color = Color(1, 1, 0);
- else
- color = base_color;
-
+ String color_str = tag.substr(6, tag.length());
+ Color color = _get_color_from_string(color_str, base_color);
push_color(color);
pos = brk_end + 1;
tag_stack.push_front("color");
} else if (tag.begins_with("font=")) {
-
String fnt = tag.substr(5, tag.length());
Ref<Font> font = ResourceLoader::load(fnt, "Font");
- if (font.is_valid())
+ if (font.is_valid()) {
push_font(font);
- else
+ } else {
push_font(normal_font);
+ }
pos = brk_end + 1;
tag_stack.push_front("font");
- } else if (tag.begins_with("fade")) {
- Vector<String> tags = tag.split(" ", false);
- int startIndex = 0;
- int length = 10;
+ } else if (bbcode_name == "fade") {
+ int start_index = 0;
+ OptionMap::Element *start_option = bbcode_options.find("start");
+ if (start_option) {
+ start_index = start_option->value().to_int();
+ }
- if (tags.size() > 1) {
- tags.remove(0);
- for (int i = 0; i < tags.size(); i++) {
- String expr = tags[i];
- if (expr.begins_with("start=")) {
- String start_str = expr.substr(6, expr.length());
- startIndex = start_str.to_int();
- } else if (expr.begins_with("length=")) {
- String end_str = expr.substr(7, expr.length());
- length = end_str.to_int();
- }
- }
+ int length = 10;
+ OptionMap::Element *length_option = bbcode_options.find("length");
+ if (length_option) {
+ length = length_option->value().to_int();
}
- push_fade(startIndex, length);
+ push_fade(start_index, length);
pos = brk_end + 1;
tag_stack.push_front("fade");
- } else if (tag.begins_with("shake")) {
- Vector<String> tags = tag.split(" ", false);
+ } else if (bbcode_name == "shake") {
int strength = 5;
- float rate = 20.0f;
+ OptionMap::Element *strength_option = bbcode_options.find("level");
+ if (strength_option) {
+ strength = strength_option->value().to_int();
+ }
- if (tags.size() > 1) {
- tags.remove(0);
- for (int i = 0; i < tags.size(); i++) {
- String expr = tags[i];
- if (expr.begins_with("level=")) {
- String str_str = expr.substr(6, expr.length());
- strength = str_str.to_int();
- } else if (expr.begins_with("rate=")) {
- String rate_str = expr.substr(5, expr.length());
- rate = rate_str.to_float();
- }
- }
+ float rate = 20.0f;
+ OptionMap::Element *rate_option = bbcode_options.find("rate");
+ if (rate_option) {
+ rate = rate_option->value().to_float();
}
push_shake(strength, rate);
pos = brk_end + 1;
tag_stack.push_front("shake");
set_process_internal(true);
- } else if (tag.begins_with("wave")) {
- Vector<String> tags = tag.split(" ", false);
+ } else if (bbcode_name == "wave") {
float amplitude = 20.0f;
- float period = 5.0f;
+ OptionMap::Element *amplitude_option = bbcode_options.find("amp");
+ if (amplitude_option) {
+ amplitude = amplitude_option->value().to_float();
+ }
- if (tags.size() > 1) {
- tags.remove(0);
- for (int i = 0; i < tags.size(); i++) {
- String expr = tags[i];
- if (expr.begins_with("amp=")) {
- String amp_str = expr.substr(4, expr.length());
- amplitude = amp_str.to_float();
- } else if (expr.begins_with("freq=")) {
- String period_str = expr.substr(5, expr.length());
- period = period_str.to_float();
- }
- }
+ float period = 5.0f;
+ OptionMap::Element *period_option = bbcode_options.find("freq");
+ if (period_option) {
+ period = period_option->value().to_float();
}
push_wave(period, amplitude);
pos = brk_end + 1;
tag_stack.push_front("wave");
set_process_internal(true);
- } else if (tag.begins_with("tornado")) {
- Vector<String> tags = tag.split(" ", false);
+ } else if (bbcode_name == "tornado") {
float radius = 10.0f;
- float frequency = 1.0f;
+ OptionMap::Element *radius_option = bbcode_options.find("radius");
+ if (radius_option) {
+ radius = radius_option->value().to_float();
+ }
- if (tags.size() > 1) {
- tags.remove(0);
- for (int i = 0; i < tags.size(); i++) {
- String expr = tags[i];
- if (expr.begins_with("radius=")) {
- String amp_str = expr.substr(7, expr.length());
- radius = amp_str.to_float();
- } else if (expr.begins_with("freq=")) {
- String period_str = expr.substr(5, expr.length());
- frequency = period_str.to_float();
- }
- }
+ float frequency = 1.0f;
+ OptionMap::Element *frequency_option = bbcode_options.find("freq");
+ if (frequency_option) {
+ frequency = frequency_option->value().to_float();
}
push_tornado(frequency, radius);
pos = brk_end + 1;
tag_stack.push_front("tornado");
set_process_internal(true);
- } else if (tag.begins_with("rainbow")) {
- Vector<String> tags = tag.split(" ", false);
+ } else if (bbcode_name == "rainbow") {
float saturation = 0.8f;
+ OptionMap::Element *saturation_option = bbcode_options.find("sat");
+ if (saturation_option) {
+ saturation = saturation_option->value().to_float();
+ }
+
float value = 0.8f;
- float frequency = 1.0f;
+ OptionMap::Element *value_option = bbcode_options.find("val");
+ if (value_option) {
+ value = value_option->value().to_float();
+ }
- if (tags.size() > 1) {
- tags.remove(0);
- for (int i = 0; i < tags.size(); i++) {
- String expr = tags[i];
- if (expr.begins_with("sat=")) {
- String sat_str = expr.substr(4, expr.length());
- saturation = sat_str.to_float();
- } else if (expr.begins_with("val=")) {
- String val_str = expr.substr(4, expr.length());
- value = val_str.to_float();
- } else if (expr.begins_with("freq=")) {
- String freq_str = expr.substr(5, expr.length());
- frequency = freq_str.to_float();
- }
- }
+ float frequency = 1.0f;
+ OptionMap::Element *frequency_option = bbcode_options.find("freq");
+ if (frequency_option) {
+ frequency = frequency_option->value().to_float();
}
push_rainbow(saturation, value, frequency);
@@ -2442,7 +2386,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front("rainbow");
set_process_internal(true);
} else {
- Vector<String> expr = tag.split(" ", false);
+ Vector<String> &expr = split_tag_block;
if (expr.size() < 1) {
add_text("[");
pos = brk_pos + 1;
@@ -2469,25 +2413,23 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
void RichTextLabel::scroll_to_line(int p_line) {
-
ERR_FAIL_INDEX(p_line, main->lines.size());
_validate_line_caches(main);
vscroll->set_value(main->lines[p_line].height_accum_cache - main->lines[p_line].height_cache);
}
int RichTextLabel::get_line_count() const {
-
return current_frame->lines.size();
}
int RichTextLabel::get_visible_line_count() const {
- if (!is_visible())
+ if (!is_visible()) {
return 0;
+ }
return visible_line_count;
}
void RichTextLabel::set_selection_enabled(bool p_enabled) {
-
selection.enabled = p_enabled;
if (!p_enabled) {
if (selection.active) {
@@ -2501,7 +2443,6 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) {
}
bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous) {
-
ERR_FAIL_COND_V(!selection.enabled, false);
Item *it = main;
int charidx = 0;
@@ -2512,9 +2453,7 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
while (it) {
-
if (it->type == ITEM_TEXT) {
-
ItemText *t = static_cast<ItemText *>(it);
int sp = t->text.findn(p_string, charidx);
if (sp != -1) {
@@ -2549,10 +2488,11 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
}
- if (p_search_previous)
+ if (p_search_previous) {
it = _get_prev_item(it, true);
- else
+ } else {
it = _get_next_item(it, true);
+ }
charidx = 0;
}
@@ -2560,18 +2500,16 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
void RichTextLabel::selection_copy() {
-
- if (!selection.active || !selection.enabled)
+ if (!selection.active || !selection.enabled) {
return;
+ }
String text;
RichTextLabel::Item *item = selection.from;
while (item) {
-
if (item->type == ITEM_TEXT) {
-
String itext = static_cast<ItemText *>(item)->text;
if (item == selection.from && item == selection.to) {
text += itext.substr(selection.from_char, selection.to_char - selection.from_char + 1);
@@ -2586,8 +2524,9 @@ void RichTextLabel::selection_copy() {
} else if (item->type == ITEM_NEWLINE) {
text += "\n";
}
- if (item == selection.to)
+ if (item == selection.to) {
break;
+ }
item = _get_next_item(item, true);
}
@@ -2598,34 +2537,32 @@ void RichTextLabel::selection_copy() {
}
bool RichTextLabel::is_selection_enabled() const {
-
return selection.enabled;
}
void RichTextLabel::set_bbcode(const String &p_bbcode) {
bbcode = p_bbcode;
- if (is_inside_tree() && use_bbcode)
+ if (is_inside_tree() && use_bbcode) {
parse_bbcode(p_bbcode);
- else { // raw text
+ } else { // raw text
clear();
add_text(p_bbcode);
}
}
String RichTextLabel::get_bbcode() const {
-
return bbcode;
}
void RichTextLabel::set_use_bbcode(bool p_enable) {
- if (use_bbcode == p_enable)
+ if (use_bbcode == p_enable) {
return;
+ }
use_bbcode = p_enable;
set_bbcode(bbcode);
}
bool RichTextLabel::is_using_bbcode() const {
-
return use_bbcode;
}
@@ -2652,14 +2589,11 @@ void RichTextLabel::set_text(const String &p_string) {
}
void RichTextLabel::set_percent_visible(float p_percent) {
-
if (p_percent < 0 || p_percent >= 1) {
-
visible_characters = -1;
percent_visible = 1;
} else {
-
visible_characters = get_total_character_count() * p_percent;
percent_visible = p_percent;
}
@@ -2700,18 +2634,18 @@ void RichTextLabel::install_effect(const Variant effect) {
int RichTextLabel::get_content_height() {
int total_height = 0;
- if (main->lines.size())
+ if (main->lines.size()) {
total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ }
return total_height;
}
void RichTextLabel::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input);
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"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("add_image", "image", "width", "height", "color"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)));
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);
@@ -2845,11 +2779,12 @@ void RichTextLabel::set_visible_characters(int p_visible) {
int RichTextLabel::get_visible_characters() const {
return visible_characters;
}
-int RichTextLabel::get_total_character_count() const {
+int RichTextLabel::get_total_character_count() const {
int tc = 0;
- for (int i = 0; i < current_frame->lines.size(); i++)
+ for (int i = 0; i < current_frame->lines.size(); i++) {
tc += current_frame->lines[i].char_count;
+ }
return tc;
}
@@ -2860,7 +2795,6 @@ void RichTextLabel::set_fixed_size_to_width(int p_width) {
}
Size2 RichTextLabel::get_minimum_size() const {
-
if (fixed_width != -1) {
const_cast<RichTextLabel *>(this)->_validate_line_caches(main);
return Size2(fixed_width, const_cast<RichTextLabel *>(this)->get_content_height());
@@ -2871,8 +2805,9 @@ Size2 RichTextLabel::get_minimum_size() const {
Ref<RichTextEffect> RichTextLabel::_get_custom_effect_by_code(String p_bbcode_identifier) {
for (int i = 0; i < custom_effects.size(); i++) {
- if (!custom_effects[i].is_valid())
+ if (!custom_effects[i].is_valid()) {
continue;
+ }
if (custom_effects[i]->get_bbcode() == p_bbcode_identifier) {
return custom_effects[i];
@@ -2942,7 +2877,6 @@ Dictionary RichTextLabel::parse_expressions_for_values(Vector<String> p_expressi
}
RichTextLabel::RichTextLabel() {
-
main = memnew(ItemFrame);
main->index = 0;
current = main;
@@ -2953,7 +2887,7 @@ RichTextLabel::RichTextLabel() {
tab_size = 4;
default_align = ALIGN_LEFT;
underline_meta = true;
- meta_hovering = NULL;
+ meta_hovering = nullptr;
override_selected_font_color = false;
scroll_visible = false;
@@ -2977,7 +2911,7 @@ RichTextLabel::RichTextLabel() {
current_idx = 1;
use_bbcode = false;
- selection.click = NULL;
+ selection.click = nullptr;
selection.active = false;
selection.enabled = false;
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index dd439208af..4cec435568 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -35,7 +35,6 @@
#include "scene/gui/scroll_bar.h"
class RichTextLabel : public Control {
-
GDCLASS(RichTextLabel, Control);
public:
@@ -84,7 +83,6 @@ private:
struct Item;
struct Line {
-
Item *from;
Vector<int> offset_caches;
Vector<int> height_caches;
@@ -98,7 +96,7 @@ private:
int maximum_width;
Line() {
- from = NULL;
+ from = nullptr;
char_count = 0;
}
};
@@ -119,9 +117,11 @@ private:
}
Item() {
- parent = NULL;
- E = NULL;
+ parent = nullptr;
+ E = nullptr;
line = 0;
+ index = 0;
+ type = ITEM_FRAME;
}
virtual ~Item() { _clear_children(); }
};
@@ -135,7 +135,7 @@ private:
ItemFrame() {
type = ITEM_FRAME;
- parent_frame = NULL;
+ parent_frame = nullptr;
cell = false;
parent_line = 0;
}
@@ -149,6 +149,7 @@ private:
struct ItemImage : public Item {
Ref<Texture2D> image;
Size2 size;
+ Color color;
ItemImage() { type = ITEM_IMAGE; }
};
@@ -350,7 +351,6 @@ private:
};
struct Selection {
-
Item *click;
int click_char;
@@ -368,8 +368,8 @@ private:
int visible_characters;
float percent_visible;
- int _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0);
- void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL);
+ int _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos = Point2i(), Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr, int p_char_count = 0);
+ void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr);
Ref<Font> _find_font(Item *p_item);
int _find_margin(Item *p_item, const Ref<Font> &p_base_font);
@@ -377,11 +377,13 @@ private:
Color _find_color(Item *p_item, const Color &p_default_color);
bool _find_underline(Item *p_item);
bool _find_strikethrough(Item *p_item);
- bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = NULL);
+ bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = nullptr);
bool _find_layout_subitem(Item *from, Item *to);
bool _find_by_type(Item *p_item, ItemType p_type);
void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack);
+ static Color _get_color_from_string(const String &p_color_str, const Color &p_default_color);
+
void _update_scroll();
void _update_fx(ItemFrame *p_frame, float p_delta_time);
void _scroll_changed(double);
@@ -407,7 +409,7 @@ protected:
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);
+ 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));
void add_newline();
bool remove_line(const int p_line);
void push_font(const Ref<Font> &p_font);
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 5e9541730e..4db6ca2949 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -38,12 +38,10 @@
bool ScrollBar::focus_by_default = false;
void ScrollBar::set_can_focus_by_default(bool p_can_focus) {
-
focus_by_default = p_can_focus;
}
void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
-
Ref<InputEventMouseMotion> m = p_event;
if (!m.is_valid() || drag.active) {
emit_signal("scrolling");
@@ -55,22 +53,20 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
accept_event();
if (b->get_button_index() == BUTTON_WHEEL_DOWN && b->is_pressed()) {
-
set_value(get_value() + get_page() / 4.0);
accept_event();
}
if (b->get_button_index() == BUTTON_WHEEL_UP && b->is_pressed()) {
-
set_value(get_value() - get_page() / 4.0);
accept_event();
}
- if (b->get_button_index() != BUTTON_LEFT)
+ if (b->get_button_index() != BUTTON_LEFT) {
return;
+ }
if (b->is_pressed()) {
-
double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x;
Ref<Texture2D> decr = get_theme_icon("decrement");
Ref<Texture2D> incr = get_theme_icon("increment");
@@ -82,13 +78,11 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
double total = orientation == VERTICAL ? get_size().height : get_size().width;
if (ofs < decr_size) {
-
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
return;
}
if (ofs > total - incr_size) {
-
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
return;
}
@@ -96,7 +90,6 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
ofs -= decr_size;
if (ofs < grabber_ofs) {
-
if (scrolling) {
target_scroll = CLAMP(target_scroll - get_page(), get_min(), get_max() - get_page());
} else {
@@ -115,7 +108,6 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
ofs -= grabber_ofs;
if (ofs < grabber_size) {
-
drag.active = true;
drag.pos_at_click = grabber_ofs + ofs;
drag.value_at_click = get_as_ratio();
@@ -136,18 +128,15 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
}
} else {
-
drag.active = false;
update();
}
}
if (m.is_valid()) {
-
accept_event();
if (drag.active) {
-
double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
Ref<Texture2D> decr = get_theme_icon("decrement");
@@ -158,7 +147,6 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
set_as_ratio(drag.value_at_click + diff);
} else {
-
double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
Ref<Texture2D> decr = get_theme_icon("decrement");
Ref<Texture2D> incr = get_theme_icon("increment");
@@ -170,20 +158,16 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
HighlightStatus new_hilite;
if (ofs < decr_size) {
-
new_hilite = HIGHLIGHT_DECR;
} else if (ofs > total - incr_size) {
-
new_hilite = HIGHLIGHT_INCR;
} else {
-
new_hilite = HIGHLIGHT_RANGE;
}
if (new_hilite != highlight) {
-
highlight = new_hilite;
update();
}
@@ -191,47 +175,42 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
}
if (p_event->is_pressed()) {
-
if (p_event->is_action("ui_left")) {
-
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_right")) {
-
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_up")) {
-
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_down")) {
-
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_home")) {
-
set_value(get_min());
} else if (p_event->is_action("ui_end")) {
-
set_value(get_max());
}
}
}
void ScrollBar::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
RID ci = get_canvas_item();
Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon("decrement_highlight") : get_theme_icon("decrement");
@@ -239,47 +218,49 @@ void ScrollBar::_notification(int p_what) {
Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll");
Ref<StyleBox> grabber;
- if (drag.active)
+ if (drag.active) {
grabber = get_theme_stylebox("grabber_pressed");
- else if (highlight == HIGHLIGHT_RANGE)
+ } else if (highlight == HIGHLIGHT_RANGE) {
grabber = get_theme_stylebox("grabber_highlight");
- else
+ } else {
grabber = get_theme_stylebox("grabber");
+ }
Point2 ofs;
decr->draw(ci, Point2());
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
ofs.x += decr->get_width();
- else
+ } else {
ofs.y += decr->get_height();
+ }
Size2 area = get_size();
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
area.width -= incr->get_width() + decr->get_width();
- else
+ } else {
area.height -= incr->get_height() + decr->get_height();
+ }
bg->draw(ci, Rect2(ofs, area));
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
ofs.width += area.width;
- else
+ } else {
ofs.height += area.height;
+ }
incr->draw(ci, ofs);
Rect2 grabber_rect;
if (orientation == HORIZONTAL) {
-
grabber_rect.size.width = get_grabber_size();
grabber_rect.size.height = get_size().height;
grabber_rect.position.y = 0;
grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(MARGIN_LEFT);
} else {
-
grabber_rect.size.width = get_size().width;
grabber_rect.size.height = get_grabber_size();
grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(MARGIN_TOP);
@@ -290,7 +271,6 @@ void ScrollBar::_notification(int p_what) {
}
if (p_what == NOTIFICATION_ENTER_TREE) {
-
if (has_node(drag_node_path)) {
Node *n = get_node(drag_node_path);
drag_node = Object::cast_to<Control>(n);
@@ -302,17 +282,15 @@ void ScrollBar::_notification(int p_what) {
}
}
if (p_what == NOTIFICATION_EXIT_TREE) {
-
if (drag_node) {
drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit));
}
- drag_node = NULL;
+ drag_node = nullptr;
}
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
-
if (scrolling) {
if (get_value() != target_scroll) {
double target = target_scroll - get_value();
@@ -332,16 +310,13 @@ void ScrollBar::_notification(int p_what) {
}
} else if (drag_node_touching) {
-
if (drag_node_touching_deaccel) {
-
Vector2 pos = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
pos += drag_node_speed * get_physics_process_delta_time();
bool turnoff = false;
if (orientation == HORIZONTAL) {
-
if (pos.x < 0) {
pos.x = 0;
turnoff = true;
@@ -365,7 +340,6 @@ void ScrollBar::_notification(int p_what) {
drag_node_speed.x = sgn_x * val_x;
} else {
-
if (pos.y < 0) {
pos.y = 0;
turnoff = true;
@@ -395,9 +369,7 @@ void ScrollBar::_notification(int p_what) {
}
} else {
-
if (time_since_motion == 0 || time_since_motion > 0.1) {
-
Vector2 diff = drag_node_accum - last_drag_node_accum;
last_drag_node_accum = drag_node_accum;
drag_node_speed = diff / get_physics_process_delta_time();
@@ -409,24 +381,22 @@ void ScrollBar::_notification(int p_what) {
}
if (p_what == NOTIFICATION_MOUSE_EXIT) {
-
highlight = HIGHLIGHT_NONE;
update();
}
}
double ScrollBar::get_grabber_min_size() const {
-
Ref<StyleBox> grabber = get_theme_stylebox("grabber");
Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size();
return (orientation == VERTICAL) ? gminsize.height : gminsize.width;
}
double ScrollBar::get_grabber_size() const {
-
float range = get_max() - get_min();
- if (range <= 0)
+ if (range <= 0) {
return 0;
+ }
float page = (get_page() > 0) ? get_page() : 0;
/*
@@ -464,17 +434,14 @@ double ScrollBar::get_area_size() const {
}
double ScrollBar::get_area_offset() const {
-
double ofs = 0;
if (orientation == VERTICAL) {
-
ofs += get_theme_stylebox("hscroll")->get_margin(MARGIN_TOP);
ofs += get_theme_icon("decrement")->get_height();
}
if (orientation == HORIZONTAL) {
-
ofs += get_theme_stylebox("hscroll")->get_margin(MARGIN_LEFT);
ofs += get_theme_icon("decrement")->get_width();
}
@@ -483,31 +450,28 @@ double ScrollBar::get_area_offset() const {
}
double ScrollBar::get_click_pos(const Point2 &p_pos) const {
-
float pos = (orientation == VERTICAL) ? p_pos.y : p_pos.x;
pos -= get_area_offset();
float area = get_area_size();
- if (area == 0)
+ if (area == 0) {
return 0;
- else
+ } else {
return pos / area;
+ }
}
double ScrollBar::get_grabber_offset() const {
-
return (get_area_size()) * get_as_ratio();
}
Size2 ScrollBar::get_minimum_size() const {
-
Ref<Texture2D> incr = get_theme_icon("increment");
Ref<Texture2D> decr = get_theme_icon("decrement");
Ref<StyleBox> bg = get_theme_stylebox("scroll");
Size2 minsize;
if (orientation == VERTICAL) {
-
minsize.width = MAX(incr->get_size().width, (bg->get_minimum_size() + bg->get_center_size()).width);
minsize.height += incr->get_size().height;
minsize.height += decr->get_size().height;
@@ -516,7 +480,6 @@ Size2 ScrollBar::get_minimum_size() const {
}
if (orientation == HORIZONTAL) {
-
minsize.height = MAX(incr->get_size().height, (bg->get_center_size() + bg->get_minimum_size()).height);
minsize.width += incr->get_size().width;
minsize.width += decr->get_size().width;
@@ -528,34 +491,33 @@ Size2 ScrollBar::get_minimum_size() const {
}
void ScrollBar::set_custom_step(float p_custom_step) {
-
custom_step = p_custom_step;
}
float ScrollBar::get_custom_step() const {
-
return custom_step;
}
void ScrollBar::_drag_node_exit() {
-
if (drag_node) {
drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
}
- drag_node = NULL;
+ drag_node = nullptr;
}
void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
+ if (!drag_node_enabled) {
+ return;
+ }
Ref<InputEventMouseButton> mb = p_input;
if (mb.is_valid()) {
-
- if (mb->get_button_index() != 1)
+ if (mb->get_button_index() != 1) {
return;
+ }
if (mb->is_pressed()) {
-
drag_node_speed = Vector2();
drag_node_accum = Vector2();
last_drag_node_accum = Vector2();
@@ -570,9 +532,7 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
}
} else {
-
if (drag_node_touching) {
-
if (drag_node_speed == Vector2()) {
drag_node_touching_deaccel = false;
drag_node_touching = false;
@@ -587,19 +547,19 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
Ref<InputEventMouseMotion> mm = p_input;
if (mm.is_valid()) {
-
if (drag_node_touching && !drag_node_touching_deaccel) {
-
Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y);
drag_node_accum -= motion;
Vector2 diff = drag_node_from + drag_node_accum;
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
set_value(diff.x);
+ }
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
set_value(diff.y);
+ }
time_since_motion = 0;
}
@@ -607,20 +567,17 @@ void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
}
void ScrollBar::set_drag_node(const NodePath &p_path) {
-
if (is_inside_tree()) {
-
if (drag_node) {
drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit));
}
}
- drag_node = NULL;
+ drag_node = nullptr;
drag_node_path = p_path;
if (is_inside_tree()) {
-
if (has_node(p_path)) {
Node *n = get_node(p_path);
drag_node = Object::cast_to<Control>(n);
@@ -634,10 +591,13 @@ void ScrollBar::set_drag_node(const NodePath &p_path) {
}
NodePath ScrollBar::get_drag_node() const {
-
return drag_node_path;
}
+void ScrollBar::set_drag_node_enabled(bool p_enable) {
+ drag_node_enabled = p_enable;
+}
+
void ScrollBar::set_smooth_scroll_enabled(bool p_enable) {
smooth_scroll_enabled = p_enable;
}
@@ -647,7 +607,6 @@ bool ScrollBar::is_smooth_scroll_enabled() const {
}
void ScrollBar::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollBar::_gui_input);
ClassDB::bind_method(D_METHOD("set_custom_step", "step"), &ScrollBar::set_custom_step);
ClassDB::bind_method(D_METHOD("get_custom_step"), &ScrollBar::get_custom_step);
@@ -658,24 +617,11 @@ void ScrollBar::_bind_methods() {
}
ScrollBar::ScrollBar(Orientation p_orientation) {
-
orientation = p_orientation;
- highlight = HIGHLIGHT_NONE;
- custom_step = -1;
- drag_node = NULL;
-
- drag.active = false;
-
- drag_node_speed = Vector2();
- drag_node_touching = false;
- drag_node_touching_deaccel = false;
- scrolling = false;
- target_scroll = 0;
- smooth_scroll_enabled = false;
-
- if (focus_by_default)
+ if (focus_by_default) {
set_focus_mode(FOCUS_ALL);
+ }
set_step(0);
}
diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h
index ee5e7140cf..23ee61d9e1 100644
--- a/scene/gui/scroll_bar.h
+++ b/scene/gui/scroll_bar.h
@@ -34,7 +34,6 @@
#include "scene/gui/range.h"
class ScrollBar : public Range {
-
GDCLASS(ScrollBar, Range);
enum HighlightStatus {
@@ -48,13 +47,12 @@ class ScrollBar : public Range {
Orientation orientation;
Size2 size;
- float custom_step;
+ float custom_step = -1;
- HighlightStatus highlight;
+ HighlightStatus highlight = HIGHLIGHT_NONE;
struct Drag {
-
- bool active;
+ bool active = false;
float pos_at_click;
float value_at_click;
} drag;
@@ -68,22 +66,23 @@ class ScrollBar : public Range {
static void set_can_focus_by_default(bool p_can_focus);
- Node *drag_node;
+ Node *drag_node = nullptr;
NodePath drag_node_path;
+ bool drag_node_enabled = true;
- Vector2 drag_node_speed;
+ Vector2 drag_node_speed = Vector2();
Vector2 drag_node_accum;
Vector2 drag_node_from;
Vector2 last_drag_node_accum;
float last_drag_node_time;
float time_since_motion;
- bool drag_node_touching;
- bool drag_node_touching_deaccel;
+ bool drag_node_touching = false;
+ bool drag_node_touching_deaccel = false;
bool click_handled;
- bool scrolling;
- double target_scroll;
- bool smooth_scroll_enabled;
+ bool scrolling = false;
+ double target_scroll = 0;
+ bool smooth_scroll_enabled = false;
void _drag_node_exit();
void _drag_node_input(const Ref<InputEvent> &p_input);
@@ -101,6 +100,7 @@ public:
void set_drag_node(const NodePath &p_path);
NodePath get_drag_node() const;
+ void set_drag_node_enabled(bool p_enable);
void set_smooth_scroll_enabled(bool p_enable);
bool is_smooth_scroll_enabled() const;
@@ -111,7 +111,6 @@ public:
};
class HScrollBar : public ScrollBar {
-
GDCLASS(HScrollBar, ScrollBar);
public:
@@ -120,7 +119,6 @@ public:
};
class VScrollBar : public ScrollBar {
-
GDCLASS(VScrollBar, ScrollBar);
public:
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index fb17adf96e..b72b913af0 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -33,24 +33,24 @@
#include "scene/main/window.h"
bool ScrollContainer::clips_input() const {
-
return true;
}
Size2 ScrollContainer::get_minimum_size() const {
-
Ref<StyleBox> sb = get_theme_stylebox("bg");
Size2 min_size;
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
if (!scroll_h) {
@@ -88,14 +88,12 @@ void ScrollContainer::_cancel_drag() {
}
void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
-
double prev_v_scroll = v_scroll->get_value();
double prev_h_scroll = h_scroll->get_value();
Ref<InputEventMouseButton> mb = p_gui_input;
if (mb.is_valid()) {
-
if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
// only horizontal is enabled, scroll horizontally
if (h_scroll->is_visible() && (!v_scroll->is_visible() || mb->get_shift())) {
@@ -126,17 +124,19 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); //accept event if scroll changed
+ }
- if (!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())))
+ if (!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id()))) {
return;
+ }
- if (mb->get_button_index() != BUTTON_LEFT)
+ if (mb->get_button_index() != BUTTON_LEFT) {
return;
+ }
if (mb->is_pressed()) {
-
if (drag_touching) {
_cancel_drag();
}
@@ -156,11 +156,9 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
} else {
if (drag_touching) {
-
if (drag_speed == Vector2()) {
_cancel_drag();
} else {
-
drag_touching_deaccel = true;
}
}
@@ -170,9 +168,7 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventMouseMotion> mm = p_gui_input;
if (mm.is_valid()) {
-
if (drag_touching && !drag_touching_deaccel) {
-
Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y);
drag_accum -= motion;
@@ -186,14 +182,16 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
drag_accum = -motion;
}
Vector2 diff = drag_from + drag_accum;
- if (scroll_h)
+ if (scroll_h) {
h_scroll->set_value(diff.x);
- else
+ } else {
drag_accum.x = 0;
- if (scroll_v)
+ }
+ if (scroll_v) {
v_scroll->set_value(diff.y);
- else
+ } else {
drag_accum.y = 0;
+ }
time_since_motion = 0;
}
}
@@ -201,7 +199,6 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventPanGesture> pan_gesture = p_gui_input;
if (pan_gesture.is_valid()) {
-
if (h_scroll->is_visible_in_tree()) {
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
}
@@ -210,12 +207,12 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); //accept event if scroll changed
+ }
}
void ScrollContainer::_update_scrollbar_position() {
-
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
@@ -234,7 +231,6 @@ void ScrollContainer::_update_scrollbar_position() {
}
void ScrollContainer::_ensure_focused_visible(Control *p_control) {
-
if (!follow_focus) {
return;
}
@@ -259,19 +255,15 @@ void ScrollContainer::_ensure_focused_visible(Control *p_control) {
}
void ScrollContainer::_notification(int p_what) {
-
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
-
call_deferred("_update_scrollbar_position");
};
if (p_what == NOTIFICATION_READY) {
-
get_viewport()->connect("gui_focus_changed", callable_mp(this, &ScrollContainer::_ensure_focused_visible));
}
if (p_what == NOTIFICATION_SORT_CHILDREN) {
-
child_max_size = Size2(0, 0);
Size2 size = get_size();
Point2 ofs;
@@ -280,21 +272,25 @@ void ScrollContainer::_notification(int p_what) {
size -= sb->get_minimum_size();
ofs += sb->get_offset();
- if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) //scrolls may have been moved out for reasons
+ if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
size.y -= h_scroll->get_minimum_size().y;
+ }
- if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) //scrolls may have been moved out for reasons
+ if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
size.x -= v_scroll->get_minimum_size().x;
+ }
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
Size2 minsize = c->get_combined_minimum_size();
child_max_size.x = MAX(child_max_size.x, minsize.x);
child_max_size.y = MAX(child_max_size.y, minsize.y);
@@ -302,17 +298,19 @@ void ScrollContainer::_notification(int p_what) {
Rect2 r = Rect2(-scroll, minsize);
if (!scroll_h || (!h_scroll->is_visible_in_tree() && c->get_h_size_flags() & SIZE_EXPAND)) {
r.position.x = 0;
- if (c->get_h_size_flags() & SIZE_EXPAND)
+ if (c->get_h_size_flags() & SIZE_EXPAND) {
r.size.width = MAX(size.width, minsize.width);
- else
+ } else {
r.size.width = minsize.width;
+ }
}
if (!scroll_v || (!v_scroll->is_visible_in_tree() && c->get_v_size_flags() & SIZE_EXPAND)) {
r.position.y = 0;
- if (c->get_v_size_flags() & SIZE_EXPAND)
+ if (c->get_v_size_flags() & SIZE_EXPAND) {
r.size.height = MAX(size.height, minsize.height);
- else
+ } else {
r.size.height = minsize.height;
+ }
}
r.position += ofs;
fit_child_in_rect(c, r);
@@ -322,7 +320,6 @@ void ScrollContainer::_notification(int p_what) {
};
if (p_what == NOTIFICATION_DRAW) {
-
Ref<StyleBox> sb = get_theme_stylebox("bg");
draw_style_box(sb, Rect2(Vector2(), get_size()));
@@ -330,11 +327,8 @@ void ScrollContainer::_notification(int p_what) {
}
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
-
if (drag_touching) {
-
if (drag_touching_deaccel) {
-
Vector2 pos = Vector2(h_scroll->get_value(), v_scroll->get_value());
pos += drag_speed * get_physics_process_delta_time();
@@ -359,10 +353,12 @@ void ScrollContainer::_notification(int p_what) {
turnoff_v = true;
}
- if (scroll_h)
+ if (scroll_h) {
h_scroll->set_value(pos.x);
- if (scroll_v)
+ }
+ if (scroll_v) {
v_scroll->set_value(pos.y);
+ }
float sgn_x = drag_speed.x < 0 ? -1 : 1;
float val_x = Math::abs(drag_speed.x);
@@ -387,9 +383,7 @@ void ScrollContainer::_notification(int p_what) {
}
} else {
-
if (time_since_motion == 0 || time_since_motion > 0.1) {
-
Vector2 diff = drag_accum - last_drag_accum;
last_drag_accum = drag_accum;
drag_speed = diff / get_physics_process_delta_time();
@@ -402,7 +396,6 @@ void ScrollContainer::_notification(int p_what) {
};
void ScrollContainer::update_scrollbars() {
-
Size2 size = get_size();
Ref<StyleBox> sb = get_theme_stylebox("bg");
size -= sb->get_minimum_size();
@@ -422,11 +415,9 @@ void ScrollContainer::update_scrollbars() {
bool hide_scroll_h = !scroll_h || min.width <= size.width;
if (hide_scroll_v) {
-
v_scroll->hide();
scroll.y = 0;
} else {
-
v_scroll->show();
v_scroll->set_max(min.height);
if (hide_scroll_h) {
@@ -439,11 +430,9 @@ void ScrollContainer::update_scrollbars() {
}
if (hide_scroll_h) {
-
h_scroll->hide();
scroll.x = 0;
} else {
-
h_scroll->show();
h_scroll->set_max(min.width);
if (hide_scroll_v) {
@@ -461,7 +450,6 @@ void ScrollContainer::update_scrollbars() {
}
void ScrollContainer::_scroll_moved(float) {
-
scroll.x = h_scroll->get_value();
scroll.y = v_scroll->get_value();
queue_sort();
@@ -480,7 +468,6 @@ void ScrollContainer::set_enable_h_scroll(bool p_enable) {
}
bool ScrollContainer::is_h_scroll_enabled() const {
-
return scroll_h;
}
@@ -495,26 +482,23 @@ void ScrollContainer::set_enable_v_scroll(bool p_enable) {
}
bool ScrollContainer::is_v_scroll_enabled() const {
-
return scroll_v;
}
int ScrollContainer::get_v_scroll() const {
-
return v_scroll->get_value();
}
-void ScrollContainer::set_v_scroll(int p_pos) {
+void ScrollContainer::set_v_scroll(int p_pos) {
v_scroll->set_value(p_pos);
_cancel_drag();
}
int ScrollContainer::get_h_scroll() const {
-
return h_scroll->get_value();
}
-void ScrollContainer::set_h_scroll(int p_pos) {
+void ScrollContainer::set_h_scroll(int p_pos) {
h_scroll->set_value(p_pos);
_cancel_drag();
}
@@ -536,40 +520,39 @@ void ScrollContainer::set_follow_focus(bool p_follow) {
}
String ScrollContainer::get_configuration_warning() const {
-
int found = 0;
for (int i = 0; i < get_child_count(); i++) {
-
Control *c = Object::cast_to<Control>(get_child(i));
- if (!c)
+ if (!c) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
- if (c == h_scroll || c == v_scroll)
+ }
+ if (c == h_scroll || c == v_scroll) {
continue;
+ }
found++;
}
- if (found != 1)
+ if (found != 1) {
return TTR("ScrollContainer is intended to work with a single child control.\nUse a container as child (VBox, HBox, etc.), or a Control and set the custom minimum size manually.");
- else
+ } else {
return "";
+ }
}
HScrollBar *ScrollContainer::get_h_scrollbar() {
-
return h_scroll;
}
VScrollBar *ScrollContainer::get_v_scrollbar() {
-
return v_scroll;
}
void ScrollContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollContainer::_gui_input);
ClassDB::bind_method(D_METHOD("set_enable_h_scroll", "enable"), &ScrollContainer::set_enable_h_scroll);
ClassDB::bind_method(D_METHOD("is_h_scroll_enabled"), &ScrollContainer::is_h_scroll_enabled);
@@ -604,7 +587,6 @@ void ScrollContainer::_bind_methods() {
};
ScrollContainer::ScrollContainer() {
-
h_scroll = memnew(HScrollBar);
h_scroll->set_name("_h_scroll");
add_child(h_scroll);
diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h
index 6423b36fcc..321e0e2c5a 100644
--- a/scene/gui/scroll_container.h
+++ b/scene/gui/scroll_container.h
@@ -36,7 +36,6 @@
#include "scroll_bar.h"
class ScrollContainer : public Container {
-
GDCLASS(ScrollContainer, Container);
HScrollBar *h_scroll;
diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp
index 75c4b7cce9..4f7e5720b8 100644
--- a/scene/gui/separator.cpp
+++ b/scene/gui/separator.cpp
@@ -31,7 +31,6 @@
#include "separator.h"
Size2 Separator::get_minimum_size() const {
-
Size2 ms(3, 3);
if (orientation == VERTICAL) {
ms.x = get_theme_constant("separation");
@@ -42,20 +41,15 @@ Size2 Separator::get_minimum_size() const {
}
void Separator::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_DRAW: {
-
Size2i size = get_size();
Ref<StyleBox> style = get_theme_stylebox("separator");
Size2i ssize = style->get_minimum_size() + style->get_center_size();
if (orientation == VERTICAL) {
-
style->draw(get_canvas_item(), Rect2((size.x - ssize.x) / 2, 0, ssize.x, size.y));
} else {
-
style->draw(get_canvas_item(), Rect2(0, (size.y - ssize.y) / 2, size.x, ssize.y));
}
@@ -70,11 +64,9 @@ Separator::~Separator() {
}
HSeparator::HSeparator() {
-
orientation = HORIZONTAL;
}
VSeparator::VSeparator() {
-
orientation = VERTICAL;
}
diff --git a/scene/gui/separator.h b/scene/gui/separator.h
index 9a64d6ba99..f7e5ef2c6b 100644
--- a/scene/gui/separator.h
+++ b/scene/gui/separator.h
@@ -33,7 +33,6 @@
#include "scene/gui/control.h"
class Separator : public Control {
-
GDCLASS(Separator, Control);
protected:
@@ -48,7 +47,6 @@ public:
};
class VSeparator : public Separator {
-
GDCLASS(VSeparator, Separator);
public:
@@ -56,7 +54,6 @@ public:
};
class HSeparator : public Separator {
-
GDCLASS(HSeparator, Separator);
public:
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
index 262d8076f3..9f5b9c40c2 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -33,36 +33,31 @@
#include "core/os/keyboard.h"
void ShortCut::set_shortcut(const Ref<InputEvent> &p_shortcut) {
-
shortcut = p_shortcut;
emit_changed();
}
Ref<InputEvent> ShortCut::get_shortcut() const {
-
return shortcut;
}
bool ShortCut::is_shortcut(const Ref<InputEvent> &p_event) const {
-
return shortcut.is_valid() && shortcut->shortcut_match(p_event);
}
String ShortCut::get_as_text() const {
-
- if (shortcut.is_valid())
+ if (shortcut.is_valid()) {
return shortcut->as_text();
- else
+ } else {
return "None";
+ }
}
bool ShortCut::is_valid() const {
-
return shortcut.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);
diff --git a/scene/gui/shortcut.h b/scene/gui/shortcut.h
index b22c3441c5..063d4e43dc 100644
--- a/scene/gui/shortcut.h
+++ b/scene/gui/shortcut.h
@@ -35,7 +35,6 @@
#include "core/resource.h"
class ShortCut : public Resource {
-
GDCLASS(ShortCut, Resource);
Ref<InputEvent> shortcut;
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index e47e2b869d..3dd5e022f0 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -32,21 +32,20 @@
#include "core/os/keyboard.h"
Size2 Slider::get_minimum_size() const {
-
Ref<StyleBox> style = get_theme_stylebox("slider");
Size2i ss = style->get_minimum_size() + style->get_center_size();
Ref<Texture2D> grabber = get_theme_icon("grabber");
Size2i rs = grabber->get_size();
- if (orientation == HORIZONTAL)
+ if (orientation == HORIZONTAL) {
return Size2i(ss.width, MAX(ss.height, rs.height));
- else
+ } else {
return Size2i(MAX(ss.width, rs.width), ss.height);
+ }
}
void Slider::_gui_input(Ref<InputEvent> p_event) {
-
if (!editable) {
return;
}
@@ -55,7 +54,6 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
if (mb.is_valid()) {
if (mb->get_button_index() == BUTTON_LEFT) {
-
if (mb->is_pressed()) {
Ref<Texture2D> grabber = get_theme_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber");
grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x;
@@ -63,10 +61,11 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
double grab_width = (double)grabber->get_size().width;
double grab_height = (double)grabber->get_size().height;
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
set_as_ratio(1 - (((double)grab.pos - (grab_height / 2.0)) / max));
- else
+ } else {
set_as_ratio(((double)grab.pos - (grab_width / 2.0)) / max);
+ }
grab.active = true;
grab.uvalue = get_as_ratio();
} else {
@@ -85,53 +84,51 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
if (mm.is_valid()) {
if (grab.active) {
-
Size2i size = get_size();
Ref<Texture2D> grabber = get_theme_icon("grabber");
float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos;
- if (orientation == VERTICAL)
+ if (orientation == VERTICAL) {
motion = -motion;
+ }
float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
- if (areasize <= 0)
+ if (areasize <= 0) {
return;
+ }
float umotion = motion / float(areasize);
set_as_ratio(grab.uvalue + umotion);
}
}
if (!mm.is_valid() && !mb.is_valid()) {
-
if (p_event->is_action_pressed("ui_left", true)) {
-
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_right", true)) {
-
- if (orientation != HORIZONTAL)
+ if (orientation != HORIZONTAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_up", true)) {
-
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action_pressed("ui_down", true)) {
-
- if (orientation != VERTICAL)
+ if (orientation != VERTICAL) {
return;
+ }
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
} else if (p_event->is_action("ui_home") && p_event->is_pressed()) {
-
set_value(get_min());
accept_event();
} else if (p_event->is_action("ui_end") && p_event->is_pressed()) {
-
set_value(get_max());
accept_event();
}
@@ -139,26 +136,21 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
}
void Slider::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
update();
} break;
case NOTIFICATION_MOUSE_ENTER: {
-
mouse_inside = true;
update();
} break;
case NOTIFICATION_MOUSE_EXIT: {
-
mouse_inside = false;
update();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: // fallthrough
case NOTIFICATION_EXIT_TREE: {
-
mouse_inside = false;
grab.active = false;
} break;
@@ -166,13 +158,13 @@ void Slider::_notification(int p_what) {
RID ci = get_canvas_item();
Size2i size = get_size();
Ref<StyleBox> style = get_theme_stylebox("slider");
- Ref<StyleBox> grabber_area = get_theme_stylebox("grabber_area");
- Ref<Texture2D> grabber = get_theme_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled");
+ bool highlighted = mouse_inside || has_focus();
+ Ref<StyleBox> grabber_area = get_theme_stylebox(highlighted ? "grabber_area_highlight" : "grabber_area");
+ Ref<Texture2D> grabber = get_theme_icon(editable ? (highlighted ? "grabber_highlight" : "grabber") : "grabber_disabled");
Ref<Texture2D> tick = get_theme_icon("tick");
double ratio = Math::is_nan(get_as_ratio()) ? 0 : get_as_ratio();
if (orientation == VERTICAL) {
-
int widget_width = style->get_minimum_size().width + style->get_center_size().width;
float areasize = size.height - grabber->get_size().height;
style->draw(ci, Rect2i(Point2i(size.width / 2 - widget_width / 2, 0), Size2i(widget_width, size.height)));
@@ -181,14 +173,15 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().height / 2 - tick->get_height() / 2);
for (int i = 0; i < ticks; i++) {
- if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) continue;
+ if (!ticks_on_borders && (i == 0 || i + 1 == ticks)) {
+ continue;
+ }
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i((size.width - widget_width) / 2, ofs));
}
}
grabber->draw(ci, Point2i(size.width / 2 - grabber->get_size().width / 2, size.height - ratio * areasize - grabber->get_size().height));
} else {
-
int widget_height = style->get_minimum_size().height + style->get_center_size().height;
float areasize = size.width - grabber->get_size().width;
@@ -198,7 +191,9 @@ void Slider::_notification(int p_what) {
if (ticks > 1) {
int grabber_offset = (grabber->get_size().width / 2 - tick->get_width() / 2);
for (int i = 0; i < ticks; i++) {
- if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) continue;
+ if ((!ticks_on_borders) && ((i == 0) || ((i + 1) == ticks))) {
+ continue;
+ }
int ofs = (i * areasize / (ticks - 1)) + grabber_offset;
tick->draw(ci, Point2i(ofs, (size.height - widget_height) / 2));
}
@@ -211,23 +206,19 @@ void Slider::_notification(int p_what) {
}
void Slider::set_custom_step(float p_custom_step) {
-
custom_step = p_custom_step;
}
float Slider::get_custom_step() const {
-
return custom_step;
}
void Slider::set_ticks(int p_count) {
-
ticks = p_count;
update();
}
int Slider::get_ticks() const {
-
return ticks;
}
@@ -241,28 +232,23 @@ void Slider::set_ticks_on_borders(bool _tob) {
}
void Slider::set_editable(bool p_editable) {
-
editable = p_editable;
update();
}
bool Slider::is_editable() const {
-
return editable;
}
void Slider::set_scrollable(bool p_scrollable) {
-
scrollable = p_scrollable;
}
bool Slider::is_scrollable() const {
-
return scrollable;
}
void Slider::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &Slider::_gui_input);
ClassDB::bind_method(D_METHOD("set_ticks", "count"), &Slider::set_ticks);
ClassDB::bind_method(D_METHOD("get_ticks"), &Slider::get_ticks);
diff --git a/scene/gui/slider.h b/scene/gui/slider.h
index 1248044ec4..6f8f7cc7d8 100644
--- a/scene/gui/slider.h
+++ b/scene/gui/slider.h
@@ -34,7 +34,6 @@
#include "scene/gui/range.h"
class Slider : public Range {
-
GDCLASS(Slider, Range);
struct Grab {
@@ -78,7 +77,6 @@ public:
};
class HSlider : public Slider {
-
GDCLASS(HSlider, Slider);
public:
@@ -87,7 +85,6 @@ public:
};
class VSlider : public Slider {
-
GDCLASS(VSlider, Slider);
public:
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index ccfa8ebf63..3670f13705 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -30,28 +30,27 @@
#include "spin_box.h"
-#include "core/input/input_filter.h"
+#include "core/input/input.h"
#include "core/math/expression.h"
Size2 SpinBox::get_minimum_size() const {
-
Size2 ms = line_edit->get_combined_minimum_size();
ms.width += last_w;
return ms;
}
void SpinBox::_value_changed(double) {
-
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
- if (prefix != "")
+ if (prefix != "") {
value = prefix + " " + value;
- if (suffix != "")
+ }
+ if (suffix != "") {
value += " " + suffix;
+ }
line_edit->set_text(value);
}
void SpinBox::_text_entered(const String &p_string) {
-
Ref<Expression> expr;
expr.instance();
// Ignore the prefix and suffix in the expression
@@ -60,7 +59,7 @@ void SpinBox::_text_entered(const String &p_string) {
return;
}
- Variant value = expr->execute(Array(), NULL, false);
+ Variant value = expr->execute(Array(), nullptr, false);
if (value.get_type() != Variant::NIL) {
set_value(value);
_value_changed(0);
@@ -68,7 +67,6 @@ void SpinBox::_text_entered(const String &p_string) {
}
LineEdit *SpinBox::get_line_edit() {
-
return line_edit;
}
@@ -76,9 +74,7 @@ void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
}
void SpinBox::_range_click_timeout() {
-
- if (!drag.enabled && InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
-
+ if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
bool up = get_local_mouse_position().y < (get_size().height / 2);
set_value(get_value() + (up ? get_step() : -get_step()));
@@ -94,7 +90,6 @@ void SpinBox::_range_click_timeout() {
}
void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
-
if (!is_editable()) {
return;
}
@@ -102,13 +97,10 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed()) {
-
bool up = mb->get_position().y < (get_size().height / 2);
switch (mb->get_button_index()) {
-
case BUTTON_LEFT: {
-
line_edit->grab_focus();
set_value(get_value() + (up ? get_step() : -get_step()));
@@ -121,20 +113,17 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
drag.capture_pos = mb->get_position();
} break;
case BUTTON_RIGHT: {
-
line_edit->grab_focus();
set_value((up ? get_max() : get_min()));
} break;
case BUTTON_WHEEL_UP: {
if (line_edit->has_focus()) {
-
set_value(get_value() + get_step() * mb->get_factor());
accept_event();
}
} break;
case BUTTON_WHEEL_DOWN: {
if (line_edit->has_focus()) {
-
set_value(get_value() - get_step() * mb->get_factor());
accept_event();
}
@@ -143,13 +132,12 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
}
if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
-
//set_default_cursor_shape(CURSOR_ARROW);
range_click_timer->stop();
if (drag.enabled) {
drag.enabled = false;
- InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
warp_mouse(drag.capture_pos);
}
drag.allowed = false;
@@ -158,15 +146,12 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
-
if (drag.enabled) {
-
drag.diff_y += mm->get_relative().y;
float diff_y = -0.01 * Math::pow(ABS(drag.diff_y), 1.8f) * SGN(drag.diff_y);
set_value(CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max()));
} else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) {
-
- InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
drag.enabled = true;
drag.base_val = get_value();
drag.diff_y = 0;
@@ -175,16 +160,15 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
}
void SpinBox::_line_edit_focus_exit() {
-
// discontinue because the focus_exit was caused by right-click context menu
- if (line_edit->get_menu()->is_visible())
+ if (line_edit->get_menu()->is_visible()) {
return;
+ }
_text_entered(line_edit->get_text());
}
inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) {
-
int w = icon->get_width();
if (w != last_w) {
line_edit->set_margin(MARGIN_RIGHT, -w);
@@ -193,9 +177,7 @@ inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) {
}
void SpinBox::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
Ref<Texture2D> updown = get_theme_icon("updown");
_adjust_width_for_icon(updown);
@@ -206,48 +188,39 @@ void SpinBox::_notification(int p_what) {
updown->draw(ci, Point2i(size.width - updown->get_width(), (size.height - updown->get_height()) / 2));
} else if (p_what == NOTIFICATION_FOCUS_EXIT) {
-
//_value_changed(0);
} else if (p_what == NOTIFICATION_ENTER_TREE) {
-
_adjust_width_for_icon(get_theme_icon("updown"));
_value_changed(0);
} else if (p_what == NOTIFICATION_THEME_CHANGED) {
-
call_deferred("minimum_size_changed");
get_line_edit()->call_deferred("minimum_size_changed");
}
}
void SpinBox::set_align(LineEdit::Align p_align) {
-
line_edit->set_align(p_align);
}
LineEdit::Align SpinBox::get_align() const {
-
return line_edit->get_align();
}
void SpinBox::set_suffix(const String &p_suffix) {
-
suffix = p_suffix;
_value_changed(0);
}
String SpinBox::get_suffix() const {
-
return suffix;
}
void SpinBox::set_prefix(const String &p_prefix) {
-
prefix = p_prefix;
_value_changed(0);
}
String SpinBox::get_prefix() const {
-
return prefix;
}
@@ -256,7 +229,6 @@ void SpinBox::set_editable(bool p_editable) {
}
bool SpinBox::is_editable() const {
-
return line_edit->is_editable();
}
@@ -265,7 +237,6 @@ void SpinBox::apply() {
}
void SpinBox::_bind_methods() {
-
//ClassDB::bind_method(D_METHOD("_value_changed"),&SpinBox::_value_changed);
ClassDB::bind_method(D_METHOD("_gui_input"), &SpinBox::_gui_input);
ClassDB::bind_method(D_METHOD("set_align", "align"), &SpinBox::set_align);
@@ -286,7 +257,6 @@ void SpinBox::_bind_methods() {
}
SpinBox::SpinBox() {
-
last_w = 0;
line_edit = memnew(LineEdit);
add_child(line_edit);
diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h
index d3a3d8fe3d..3200480cf5 100644
--- a/scene/gui/spin_box.h
+++ b/scene/gui/spin_box.h
@@ -36,7 +36,6 @@
#include "scene/main/timer.h"
class SpinBox : public Range {
-
GDCLASS(SpinBox, Range);
LineEdit *line_edit;
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 4eb614a9ac..5c60153d91 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -34,23 +34,25 @@
#include "margin_container.h"
Control *SplitContainer::_getch(int p_idx) const {
-
int 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())
+ if (!c || !c->is_visible_in_tree()) {
continue;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
continue;
+ }
- if (idx == p_idx)
+ if (idx == p_idx) {
return c;
+ }
idx++;
}
- return NULL;
+ return nullptr;
}
void SplitContainer::_resort() {
@@ -119,7 +121,6 @@ void SplitContainer::_resort() {
}
Size2 SplitContainer::get_minimum_size() const {
-
/* Calculate MINIMUM SIZE */
Size2i minimum;
@@ -128,26 +129,24 @@ Size2 SplitContainer::get_minimum_size() const {
sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0;
for (int i = 0; i < 2; i++) {
-
- if (!_getch(i))
+ if (!_getch(i)) {
break;
+ }
if (i == 1) {
-
- if (vertical)
+ if (vertical) {
minimum.height += sep;
- else
+ } else {
minimum.width += sep;
+ }
}
Size2 ms = _getch(i)->get_combined_minimum_size();
if (vertical) {
-
minimum.height += ms.height;
minimum.width = MAX(minimum.width, ms.width);
} else {
-
minimum.width += ms.width;
minimum.height = MAX(minimum.height, ms.height);
}
@@ -157,80 +156,71 @@ Size2 SplitContainer::get_minimum_size() const {
}
void SplitContainer::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_SORT_CHILDREN: {
-
_resort();
} break;
case NOTIFICATION_MOUSE_EXIT: {
-
mouse_inside = false;
- if (get_theme_constant("autohide"))
+ if (get_theme_constant("autohide")) {
update();
+ }
} break;
case NOTIFICATION_DRAW: {
-
- if (!_getch(0) || !_getch(1))
+ if (!_getch(0) || !_getch(1)) {
return;
+ }
- if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide")))
+ if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide"))) {
return;
+ }
- if (dragger_visibility != DRAGGER_VISIBLE)
+ if (dragger_visibility != DRAGGER_VISIBLE) {
return;
+ }
int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant("separation") : 0;
Ref<Texture2D> tex = get_theme_icon("grabber");
Size2 size = get_size();
- if (vertical)
+ if (vertical) {
draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
- else
+ } else {
draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
+ }
} break;
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
} break;
}
}
void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
-
- if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE)
+ if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE) {
return;
+ }
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
-
if (mb->get_button_index() == BUTTON_LEFT) {
-
if (mb->is_pressed()) {
-
int sep = get_theme_constant("separation");
if (vertical) {
-
if (mb->get_position().y > middle_sep && mb->get_position().y < middle_sep + sep) {
-
dragging = true;
drag_from = mb->get_position().y;
drag_ofs = split_offset;
}
} else {
-
if (mb->get_position().x > middle_sep && mb->get_position().x < middle_sep + sep) {
-
dragging = true;
drag_from = mb->get_position().x;
drag_ofs = split_offset;
}
}
} else {
-
dragging = false;
}
}
@@ -239,22 +229,23 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
-
bool mouse_inside_state = false;
- if (vertical)
+ if (vertical) {
mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation");
- else
+ } else {
mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant("separation");
+ }
if (mouse_inside != mouse_inside_state) {
-
mouse_inside = mouse_inside_state;
- if (get_theme_constant("autohide"))
+ if (get_theme_constant("autohide")) {
update();
+ }
}
- if (!dragging)
+ if (!dragging) {
return;
+ }
split_offset = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from);
should_clamp_split_offset = true;
@@ -264,22 +255,21 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const {
-
- if (dragging)
+ if (dragging) {
return (vertical ? CURSOR_VSPLIT : CURSOR_HSPLIT);
+ }
if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) {
-
int sep = get_theme_constant("separation");
if (vertical) {
-
- if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep)
+ if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) {
return CURSOR_VSPLIT;
+ }
} else {
-
- if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep)
+ if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep) {
return CURSOR_HSPLIT;
+ }
}
}
@@ -287,9 +277,9 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const
}
void SplitContainer::set_split_offset(int p_offset) {
-
- if (split_offset == p_offset)
+ if (split_offset == p_offset) {
return;
+ }
split_offset = p_offset;
@@ -297,7 +287,6 @@ void SplitContainer::set_split_offset(int p_offset) {
}
int SplitContainer::get_split_offset() const {
-
return split_offset;
}
@@ -308,33 +297,29 @@ void SplitContainer::clamp_split_offset() {
}
void SplitContainer::set_collapsed(bool p_collapsed) {
-
- if (collapsed == p_collapsed)
+ if (collapsed == p_collapsed) {
return;
+ }
collapsed = p_collapsed;
queue_sort();
}
void SplitContainer::set_dragger_visibility(DraggerVisibility p_visibility) {
-
dragger_visibility = p_visibility;
queue_sort();
update();
}
SplitContainer::DraggerVisibility SplitContainer::get_dragger_visibility() const {
-
return dragger_visibility;
}
bool SplitContainer::is_collapsed() const {
-
return collapsed;
}
void SplitContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &SplitContainer::_gui_input);
ClassDB::bind_method(D_METHOD("set_split_offset", "offset"), &SplitContainer::set_split_offset);
@@ -359,7 +344,6 @@ void SplitContainer::_bind_methods() {
}
SplitContainer::SplitContainer(bool p_vertical) {
-
mouse_inside = false;
split_offset = 0;
should_clamp_split_offset = false;
diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h
index d759c6ad35..6dbd316a46 100644
--- a/scene/gui/split_container.h
+++ b/scene/gui/split_container.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
class SplitContainer : public Container {
-
GDCLASS(SplitContainer, Container);
public:
@@ -86,7 +85,6 @@ public:
VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility);
class HSplitContainer : public SplitContainer {
-
GDCLASS(HSplitContainer, SplitContainer);
public:
@@ -95,7 +93,6 @@ public:
};
class VSplitContainer : public SplitContainer {
-
GDCLASS(VSplitContainer, SplitContainer);
public:
diff --git a/scene/gui/viewport_container.cpp b/scene/gui/subviewport_container.cpp
index 7ce1d9e551..4e1ad2ae05 100644
--- a/scene/gui/viewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* viewport_container.cpp */
+/* subviewport_container.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,21 +28,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "viewport_container.h"
+#include "subviewport_container.h"
#include "core/engine.h"
#include "scene/main/viewport.h"
-Size2 ViewportContainer::get_minimum_size() const {
-
- if (stretch)
+Size2 SubViewportContainer::get_minimum_size() const {
+ if (stretch) {
return Size2();
+ }
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
Size2 minsize = c->get_size();
ms.width = MAX(ms.width, minsize.width);
@@ -52,34 +52,33 @@ Size2 ViewportContainer::get_minimum_size() const {
return ms;
}
-void ViewportContainer::set_stretch(bool p_enable) {
-
+void SubViewportContainer::set_stretch(bool p_enable) {
stretch = p_enable;
queue_sort();
update();
}
-bool ViewportContainer::is_stretch_enabled() const {
-
+bool SubViewportContainer::is_stretch_enabled() const {
return stretch;
}
-void ViewportContainer::set_stretch_shrink(int p_shrink) {
-
+void SubViewportContainer::set_stretch_shrink(int p_shrink) {
ERR_FAIL_COND(p_shrink < 1);
- if (shrink == p_shrink)
+ if (shrink == p_shrink) {
return;
+ }
shrink = p_shrink;
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
@@ -87,65 +86,63 @@ void ViewportContainer::set_stretch_shrink(int p_shrink) {
update();
}
-int ViewportContainer::get_stretch_shrink() const {
-
+int SubViewportContainer::get_stretch_shrink() const {
return shrink;
}
-void ViewportContainer::_notification(int p_what) {
-
+void SubViewportContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_RESIZED) {
-
- if (!stretch)
+ if (!stretch) {
return;
+ }
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
c->set_size(get_size() / shrink);
}
}
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_VISIBILITY_CHANGED) {
-
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (is_visible_in_tree())
+ if (is_visible_in_tree()) {
c->set_update_mode(SubViewport::UPDATE_ALWAYS);
- else
+ } else {
c->set_update_mode(SubViewport::UPDATE_DISABLED);
+ }
c->set_handle_input_locally(false); //do not handle input locally here
}
}
if (p_what == NOTIFICATION_DRAW) {
-
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c)
+ if (!c) {
continue;
+ }
- if (stretch)
+ if (stretch) {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size()));
- else
+ } else {
draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size()));
+ }
}
}
}
-void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
-
- if (Engine::get_singleton()->is_editor_hint())
+void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -158,19 +155,19 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) {
Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->input(ev);
}
}
-void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
-
- if (Engine::get_singleton()->is_editor_hint())
+void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
+ if (Engine::get_singleton()->is_editor_hint()) {
return;
+ }
Transform2D xform = get_global_transform();
@@ -183,31 +180,29 @@ void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse());
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c || c->is_input_disabled())
+ if (!c || c->is_input_disabled()) {
continue;
+ }
c->unhandled_input(ev);
}
}
-void ViewportContainer::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &ViewportContainer::_unhandled_input);
- ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input);
- ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch);
- ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled);
+void SubViewportContainer::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &SubViewportContainer::_unhandled_input);
+ ClassDB::bind_method(D_METHOD("_input", "event"), &SubViewportContainer::_input);
+ ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &SubViewportContainer::set_stretch);
+ ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &SubViewportContainer::is_stretch_enabled);
- ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &ViewportContainer::set_stretch_shrink);
- ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &ViewportContainer::get_stretch_shrink);
+ ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &SubViewportContainer::set_stretch_shrink);
+ ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &SubViewportContainer::get_stretch_shrink);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink");
}
-ViewportContainer::ViewportContainer() {
-
+SubViewportContainer::SubViewportContainer() {
stretch = false;
shrink = 1;
set_process_input(true);
diff --git a/scene/gui/viewport_container.h b/scene/gui/subviewport_container.h
index 8597444426..fc4c9f925a 100644
--- a/scene/gui/viewport_container.h
+++ b/scene/gui/subviewport_container.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* viewport_container.h */
+/* subviewport_container.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -33,9 +33,8 @@
#include "scene/gui/container.h"
-class ViewportContainer : public Container {
-
- GDCLASS(ViewportContainer, Container);
+class SubViewportContainer : public Container {
+ GDCLASS(SubViewportContainer, Container);
bool stretch;
int shrink;
@@ -55,7 +54,7 @@ public:
virtual Size2 get_minimum_size() const;
- ViewportContainer();
+ SubViewportContainer();
};
#endif // VIEWPORTCONTAINER_H
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 7cecbf7fa2..8c4d9a5ece 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -36,9 +36,9 @@
#include "scene/gui/texture_rect.h"
int TabContainer::_get_top_margin() const {
-
- if (!tabs_visible)
+ if (!tabs_visible) {
return 0;
+ }
// Respect the minimum tab height.
Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg");
@@ -53,14 +53,15 @@ int TabContainer::_get_top_margin() const {
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
-
Control *c = tabs[i];
- if (!c->has_meta("_tab_icon"))
+ if (!c->has_meta("_tab_icon")) {
continue;
+ }
Ref<Texture2D> tex = c->get_meta("_tab_icon");
- if (!tex.is_valid())
+ if (!tex.is_valid()) {
continue;
+ }
content_height = MAX(content_height, tex->get_size().height);
}
@@ -68,17 +69,16 @@ int TabContainer::_get_top_margin() const {
}
void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
-
Point2 pos(mb->get_position().x, mb->get_position().y);
Size2 size = get_size();
// Click must be on tabs in the tab header area.
- if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin())
+ if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin()) {
return;
+ }
// Handle menu button.
Ref<Texture2D> menu = get_theme_icon("menu");
@@ -95,8 +95,9 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
// Do not activate tabs when tabs is empty.
- if (get_tab_count() == 0)
+ if (get_tab_count() == 0) {
return;
+ }
Vector<Control *> tabs = _get_tabs();
@@ -144,13 +145,11 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
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;
@@ -161,7 +160,6 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
Ref<Texture2D> menu = get_theme_icon("menu");
if (popup) {
-
if (pos.x >= size.width - menu->get_width()) {
if (!menu_hovered) {
menu_hovered = true;
@@ -194,13 +192,11 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
Ref<Texture2D> increment = get_theme_icon("increment");
Ref<Texture2D> decrement = get_theme_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();
@@ -213,16 +209,12 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
void TabContainer::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_TRANSLATION_CHANGED: {
-
minimum_size_changed();
update();
} break;
case NOTIFICATION_RESIZED: {
-
Vector<Control *> tabs = _get_tabs();
int side_margin = get_theme_constant("side_margin");
Ref<Texture2D> menu = get_theme_icon("menu");
@@ -231,12 +223,15 @@ void TabContainer::_notification(int p_what) {
int header_width = get_size().width - side_margin * 2;
// Find the width of the header area.
- if (popup)
+ if (popup) {
header_width -= menu->get_width();
- if (buttons_visible_cache)
+ }
+ if (buttons_visible_cache) {
header_width -= increment->get_width() + decrement->get_width();
- if (popup || buttons_visible_cache)
+ }
+ if (popup || buttons_visible_cache) {
header_width += side_margin;
+ }
// Find the width of all tabs after first_tab_cache.
int all_tabs_width = 0;
@@ -249,15 +244,15 @@ void TabContainer::_notification(int p_what) {
for (int i = first_tab_cache - 1; i >= 0; i--) {
int tab_width = _get_tab_width(i);
- if (all_tabs_width + tab_width > header_width)
+ if (all_tabs_width + tab_width > header_width) {
break;
+ }
all_tabs_width += tab_width;
first_tab_cache--;
}
} break;
case NOTIFICATION_DRAW: {
-
RID canvas = get_canvas_item();
Size2 size = get_size();
@@ -283,14 +278,15 @@ void TabContainer::_notification(int p_what) {
Color font_color_bg = get_theme_color("font_color_bg");
Color font_color_disabled = get_theme_color("font_color_disabled");
int side_margin = get_theme_constant("side_margin");
- int icon_text_distance = get_theme_constant("hseparation");
+ int icon_text_distance = get_theme_constant("icon_separation");
// Find out start and width of the header area.
int header_x = side_margin;
int header_width = size.width - side_margin * 2;
int header_height = _get_top_margin();
- if (popup)
+ if (popup) {
header_width -= menu->get_width();
+ }
// Check if all tabs would fit into the header area.
int all_tabs_width = 0;
@@ -327,8 +323,9 @@ void TabContainer::_notification(int p_what) {
continue;
}
int tab_width = _get_tab_width(i);
- if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0)
+ if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0) {
break;
+ }
all_tabs_width += tab_width;
tab_widths.push_back(tab_width);
}
@@ -387,8 +384,9 @@ void TabContainer::_notification(int p_what) {
if (icon.is_valid()) {
int y = y_center - (icon->get_height() / 2);
icon->draw(canvas, Point2i(x_content, y));
- if (text != "")
+ if (text != "") {
x_content += icon->get_width() + icon_text_distance;
+ }
}
}
@@ -404,15 +402,15 @@ void TabContainer::_notification(int p_what) {
x = get_size().width;
if (popup) {
x -= menu->get_width();
- if (menu_hovered)
+ if (menu_hovered) {
menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2));
- else
+ } else {
menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2));
+ }
}
// Draw the navigation buttons.
if (buttons_visible_cache) {
-
x -= increment->get_width();
if (last_tab_cache < tabs.size() - 1) {
draw_texture(highlight_arrow == 1 ? increment_hl : increment, Point2(x, (header_height - increment->get_height()) / 2));
@@ -429,7 +427,6 @@ void TabContainer::_notification(int p_what) {
}
} break;
case NOTIFICATION_THEME_CHANGED: {
-
minimum_size_changed();
call_deferred("_on_theme_changed"); // Wait until all changed theme.
} break;
@@ -451,11 +448,11 @@ void TabContainer::_on_mouse_exited() {
}
int TabContainer::_get_tab_width(int p_index) const {
-
ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
- if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index))
+ if (!control || control->is_set_as_toplevel() || get_tab_hidden(p_index)) {
return 0;
+ }
// Get the width of the text displayed on the tab.
Ref<Font> font = get_theme_font("font");
@@ -467,8 +464,9 @@ int TabContainer::_get_tab_width(int p_index) const {
Ref<Texture2D> icon = control->get_meta("_tab_icon");
if (icon.is_valid()) {
width += icon->get_width();
- if (text != "")
- width += get_theme_constant("hseparation");
+ if (text != "") {
+ width += get_theme_constant("icon_separation");
+ }
}
}
@@ -488,13 +486,12 @@ int TabContainer::_get_tab_width(int p_index) const {
}
Vector<Control *> TabContainer::_get_tabs() const {
-
Vector<Control *> controls;
for (int i = 0; i < get_child_count(); i++) {
-
Control *control = Object::cast_to<Control>(get_child(i));
- if (!control || control->is_toplevel_control())
+ if (!control || control->is_toplevel_control()) {
continue;
+ }
controls.push_back(control);
}
@@ -502,25 +499,25 @@ Vector<Control *> TabContainer::_get_tabs() const {
}
void TabContainer::_child_renamed_callback() {
-
update();
}
void TabContainer::add_child_notify(Node *p_child) {
-
Container::add_child_notify(p_child);
Control *c = Object::cast_to<Control>(p_child);
- if (!c)
+ if (!c) {
return;
- if (c->is_set_as_toplevel())
+ }
+ if (c->is_set_as_toplevel()) {
return;
+ }
bool first = false;
- if (get_tab_count() != 1)
+ if (get_tab_count() != 1) {
c->hide();
- else {
+ } else {
c->show();
//call_deferred("set_current_tab",0);
first = true;
@@ -528,8 +525,9 @@ void TabContainer::add_child_notify(Node *p_child) {
previous = 0;
}
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- if (tabs_visible)
+ if (tabs_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
+ }
Ref<StyleBox> sb = get_theme_stylebox("panel");
c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
@@ -538,17 +536,16 @@ void TabContainer::add_child_notify(Node *p_child) {
update();
p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
- if (first && is_inside_tree())
+ if (first && is_inside_tree()) {
emit_signal("tab_changed", current);
+ }
}
int TabContainer::get_tab_count() const {
-
return _get_tabs().size();
}
void TabContainer::set_current_tab(int p_current) {
-
ERR_FAIL_INDEX(p_current, get_tab_count());
int pending_previous = current;
@@ -557,27 +554,28 @@ void TabContainer::set_current_tab(int p_current) {
Ref<StyleBox> sb = get_theme_stylebox("panel");
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
-
Control *c = tabs[i];
if (i == current) {
c->show();
c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- if (tabs_visible)
+ if (tabs_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
+ }
c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT)));
c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM)));
- } else
+ } else {
c->hide();
+ }
}
_change_notify("current_tab");
- if (pending_previous == current)
+ if (pending_previous == current) {
emit_signal("tab_selected", current);
- else {
+ } else {
previous = pending_previous;
emit_signal("tab_selected", current);
emit_signal("tab_changed", current);
@@ -587,35 +585,32 @@ void TabContainer::set_current_tab(int p_current) {
}
int TabContainer::get_current_tab() const {
-
return current;
}
int TabContainer::get_previous_tab() const {
-
return previous;
}
Control *TabContainer::get_tab_control(int p_idx) const {
-
Vector<Control *> tabs = _get_tabs();
- if (p_idx >= 0 && p_idx < tabs.size())
+ if (p_idx >= 0 && p_idx < tabs.size()) {
return tabs[p_idx];
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
Control *TabContainer::get_current_tab_control() const {
-
Vector<Control *> tabs = _get_tabs();
- if (current >= 0 && current < tabs.size())
+ if (current >= 0 && current < tabs.size()) {
return tabs[current];
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
}
void TabContainer::remove_child_notify(Node *p_child) {
-
Container::remove_child_notify(p_child);
call_deferred("_update_current_tab");
@@ -626,25 +621,27 @@ void TabContainer::remove_child_notify(Node *p_child) {
}
void TabContainer::_update_current_tab() {
-
int tc = get_tab_count();
- if (current >= tc)
+ if (current >= tc) {
current = tc - 1;
- if (current < 0)
+ }
+ if (current < 0) {
current = 0;
- else
+ } else {
set_current_tab(current);
+ }
}
Variant TabContainer::get_drag_data(const Point2 &p_point) {
-
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return Variant();
+ }
int tab_over = get_tab_idx_at_point(p_point);
- if (tab_over < 0)
+ if (tab_over < 0) {
return Variant();
+ }
HBoxContainer *drag_preview = memnew(HBoxContainer);
@@ -666,16 +663,16 @@ Variant TabContainer::get_drag_data(const Point2 &p_point) {
}
bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
-
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return false;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
if (String(d["type"]) == "tabc_element") {
-
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
@@ -693,24 +690,25 @@ bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) c
}
void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
-
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return;
+ }
int hover_now = get_tab_idx_at_point(p_point);
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "tabc_element") {
-
int tab_from_id = d["tabc_element"];
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_child(get_tab_control(tab_from_id), hover_now);
set_current_tab(hover_now);
} else if (get_tabs_rearrange_group() != -1) {
@@ -721,8 +719,9 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
Control *moving_tabc = from_tabc->get_tab_control(tab_from_id);
from_tabc->remove_child(moving_tabc);
add_child(moving_tabc);
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_child(moving_tabc, hover_now);
set_current_tab(hover_now);
emit_signal("tab_changed", hover_now);
@@ -733,13 +732,14 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
}
int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
-
- if (get_tab_count() == 0)
+ if (get_tab_count() == 0) {
return -1;
+ }
// must be on tabs in the tab header area.
- if (p_point.x < tabs_ofs_cache || p_point.y > _get_top_margin())
+ if (p_point.x < tabs_ofs_cache || p_point.y > _get_top_margin()) {
return -1;
+ }
Size2 size = get_size();
int right_ofs = 0;
@@ -772,7 +772,6 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
}
void TabContainer::set_tab_align(TabAlign p_align) {
-
ERR_FAIL_INDEX(p_align, 3);
align = p_align;
update();
@@ -781,25 +780,24 @@ void TabContainer::set_tab_align(TabAlign p_align) {
}
TabContainer::TabAlign TabContainer::get_tab_align() const {
-
return align;
}
void TabContainer::set_tabs_visible(bool p_visible) {
-
- if (p_visible == tabs_visible)
+ if (p_visible == tabs_visible) {
return;
+ }
tabs_visible = p_visible;
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
-
Control *c = tabs[i];
- if (p_visible)
+ if (p_visible) {
c->set_margin(MARGIN_TOP, _get_top_margin());
- else
+ } else {
c->set_margin(MARGIN_TOP, 0);
+ }
}
update();
@@ -807,17 +805,14 @@ void TabContainer::set_tabs_visible(bool p_visible) {
}
bool TabContainer::are_tabs_visible() const {
-
return tabs_visible;
}
Control *TabContainer::_get_tab(int p_idx) const {
-
return get_tab_control(p_idx);
}
void TabContainer::set_tab_title(int p_tab, const String &p_title) {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_name", p_title);
@@ -825,34 +820,33 @@ void TabContainer::set_tab_title(int p_tab, const String &p_title) {
}
String TabContainer::get_tab_title(int p_tab) const {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, "");
- if (child->has_meta("_tab_name"))
+ if (child->has_meta("_tab_name")) {
return child->get_meta("_tab_name");
- else
+ } else {
return child->get_name();
+ }
}
void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_icon", p_icon);
update();
}
-Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
+Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, Ref<Texture2D>());
- if (child->has_meta("_tab_icon"))
+ if (child->has_meta("_tab_icon")) {
return child->get_meta("_tab_icon");
- else
+ } else {
return Ref<Texture2D>();
+ }
}
void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_disabled", p_disabled);
@@ -860,17 +854,16 @@ void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
}
bool TabContainer::get_tab_disabled(int p_tab) const {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, false);
- if (child->has_meta("_tab_disabled"))
+ if (child->has_meta("_tab_disabled")) {
return child->get_meta("_tab_disabled");
- else
+ } else {
return false;
+ }
}
void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_hidden", p_hidden);
@@ -890,43 +883,42 @@ void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
}
bool TabContainer::get_tab_hidden(int p_tab) const {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, false);
- if (child->has_meta("_tab_hidden"))
+ if (child->has_meta("_tab_hidden")) {
return child->get_meta("_tab_hidden");
- else
+ } else {
return false;
+ }
}
void TabContainer::get_translatable_strings(List<String> *p_strings) const {
-
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
-
Control *c = tabs[i];
- if (!c->has_meta("_tab_name"))
+ if (!c->has_meta("_tab_name")) {
continue;
+ }
String name = c->get_meta("_tab_name");
- if (name != "")
+ if (name != "") {
p_strings->push_back(name);
+ }
}
}
Size2 TabContainer::get_minimum_size() const {
-
Size2 ms;
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
-
Control *c = tabs[i];
- if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size)
+ if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size) {
continue;
+ }
Size2 cms = c->get_combined_minimum_size();
ms.x = MAX(ms.x, cms.x);
@@ -966,6 +958,7 @@ void TabContainer::set_drag_to_rearrange_enabled(bool p_enabled) {
bool TabContainer::get_drag_to_rearrange_enabled() const {
return drag_to_rearrange_enabled;
}
+
void TabContainer::set_tabs_rearrange_group(int p_group_id) {
tabs_rearrange_group = p_group_id;
}
@@ -983,14 +976,13 @@ bool TabContainer::get_use_hidden_tabs_for_min_size() const {
}
void TabContainer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &TabContainer::_gui_input);
ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count);
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab);
ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab);
ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control);
- ClassDB::bind_method(D_METHOD("get_tab_control", "idx"), &TabContainer::get_tab_control);
+ ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control);
ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &TabContainer::set_tab_align);
ClassDB::bind_method(D_METHOD("get_tab_align"), &TabContainer::get_tab_align);
ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible);
@@ -1030,7 +1022,6 @@ void TabContainer::_bind_methods() {
}
TabContainer::TabContainer() {
-
first_tab_cache = 0;
last_tab_cache = 0;
buttons_visible_cache = false;
@@ -1041,7 +1032,7 @@ TabContainer::TabContainer() {
previous = 0;
align = ALIGN_CENTER;
tabs_visible = true;
- popup = NULL;
+ popup = nullptr;
drag_to_rearrange_enabled = false;
tabs_rearrange_group = -1;
use_hidden_tabs_for_min_size = false;
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 38c029475c..e8cde74c83 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
#include "scene/gui/popup.h"
class TabContainer : public Container {
-
GDCLASS(TabContainer, Container);
public:
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index ea6d44e3a7..8f71aa7cab 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -36,7 +36,6 @@
#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_disabled = get_theme_stylebox("tab_disabled");
@@ -45,22 +44,23 @@ Size2 Tabs::get_minimum_size() const {
Size2 ms(0, MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height) + font->get_height());
for (int i = 0; i < tabs.size(); i++) {
-
Ref<Texture2D> tex = tabs[i].icon;
if (tex.is_valid()) {
ms.height = MAX(ms.height, tex->get_size().height);
- if (tabs[i].text != "")
+ if (tabs[i].text != "") {
ms.width += get_theme_constant("hseparation");
+ }
}
ms.width += Math::ceil(font->get_string_size(tabs[i].xl_text).width);
- if (tabs[i].disabled)
+ if (tabs[i].disabled) {
ms.width += tab_disabled->get_minimum_size().width;
- else if (current == i)
+ } else if (current == i) {
ms.width += tab_fg->get_minimum_size().width;
- else
+ } else {
ms.width += tab_bg->get_minimum_size().width;
+ }
if (tabs[i].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[i].right_button;
@@ -84,16 +84,13 @@ Size2 Tabs::get_minimum_size() const {
}
void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
-
Point2 pos = mm->get_position();
highlight_arrow = -1;
if (buttons_visible) {
-
Ref<Texture2D> incr = get_theme_icon("increment");
Ref<Texture2D> decr = get_theme_icon("decrement");
@@ -114,9 +111,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 (scrolling_enabled && buttons_visible) {
if (offset > 0) {
offset--;
@@ -135,7 +130,6 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
-
if (rb_hover != -1) {
//pressed
emit_signal("right_button_pressed", rb_hover);
@@ -146,7 +140,6 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
-
if (cb_hover != -1) {
//pressed
emit_signal("tab_close", cb_hover);
@@ -157,12 +150,10 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
if (mb->is_pressed() && (mb->get_button_index() == BUTTON_LEFT || (select_with_rmb && mb->get_button_index() == BUTTON_RIGHT))) {
-
// clicks
Point2 pos(mb->get_position().x, mb->get_position().y);
if (buttons_visible) {
-
Ref<Texture2D> incr = get_theme_icon("increment");
Ref<Texture2D> decr = get_theme_icon("decrement");
@@ -184,11 +175,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
int found = -1;
- for (int i = 0; i < tabs.size(); i++) {
-
- if (i < offset)
- continue;
-
+ for (int i = offset; i < tabs.size(); i++) {
if (tabs[i].rb_rect.has_point(pos)) {
rb_pressing = true;
update();
@@ -210,7 +197,6 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
if (found != -1) {
-
set_current_tab(found);
emit_signal("tab_clicked", found);
}
@@ -219,9 +205,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
void Tabs::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_TRANSLATION_CHANGED: {
for (int i = 0; i < tabs.size(); ++i) {
tabs.write[i].xl_text = tr(tabs[i].text);
@@ -252,7 +236,6 @@ void Tabs::_notification(int p_what) {
int mw = 0;
for (int i = 0; i < tabs.size(); i++) {
-
tabs.write[i].ofs_cache = mw;
mw += get_tab_width(i);
}
@@ -276,11 +259,7 @@ void Tabs::_notification(int p_what) {
missing_right = false;
- for (int i = 0; i < tabs.size(); i++) {
-
- if (i < offset)
- continue;
-
+ for (int i = offset; i < tabs.size(); i++) {
tabs.write[i].ofs_cache = w;
int lsize = tabs[i].size_cache;
@@ -315,10 +294,10 @@ void Tabs::_notification(int p_what) {
Size2i sb_ms = sb->get_minimum_size();
Ref<Texture2D> icon = tabs[i].icon;
if (icon.is_valid()) {
-
icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
- if (tabs[i].text != "")
+ if (tabs[i].text != "") {
w += icon->get_width() + get_theme_constant("hseparation");
+ }
}
font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), tabs[i].xl_text, col, tabs[i].size_text);
@@ -326,7 +305,6 @@ void Tabs::_notification(int p_what) {
w += tabs[i].size_text;
if (tabs[i].right_button.is_valid()) {
-
Ref<StyleBox> style = get_theme_stylebox("button");
Ref<Texture2D> rb = tabs[i].right_button;
@@ -338,10 +316,11 @@ void Tabs::_notification(int p_what) {
rb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;
if (rb_hover == i) {
- if (rb_pressing)
+ if (rb_pressing) {
get_theme_stylebox("button_pressed")->draw(ci, rb_rect);
- else
+ } else {
style->draw(ci, rb_rect);
+ }
}
rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.position.y + style->get_margin(MARGIN_TOP)));
@@ -350,7 +329,6 @@ void Tabs::_notification(int p_what) {
}
if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
-
Ref<StyleBox> style = get_theme_stylebox("button");
Ref<Texture2D> cb = close;
@@ -362,10 +340,11 @@ void Tabs::_notification(int p_what) {
cb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;
if (!tabs[i].disabled && cb_hover == i) {
- if (cb_pressing)
+ if (cb_pressing) {
get_theme_stylebox("button_pressed")->draw(ci, cb_rect);
- else
+ } else {
style->draw(ci, cb_rect);
+ }
}
cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.position.y + style->get_margin(MARGIN_TOP)));
@@ -377,18 +356,19 @@ void Tabs::_notification(int p_what) {
}
if (offset > 0 || missing_right) {
-
int vofs = (get_size().height - incr->get_size().height) / 2;
- if (offset > 0)
+ if (offset > 0) {
draw_texture(highlight_arrow == 0 ? decr_hl : decr, Point2(limit, vofs));
- else
+ } else {
draw_texture(decr, Point2(limit, vofs), Color(1, 1, 1, 0.5));
+ }
- if (missing_right)
+ if (missing_right) {
draw_texture(highlight_arrow == 1 ? incr_hl : incr, Point2(limit + decr->get_size().width, vofs));
- else
+ } else {
draw_texture(incr, Point2(limit + decr->get_size().width, vofs), Color(1, 1, 1, 0.5));
+ }
buttons_visible = true;
} else {
@@ -399,13 +379,13 @@ void Tabs::_notification(int p_what) {
}
int Tabs::get_tab_count() const {
-
return tabs.size();
}
void Tabs::set_current_tab(int p_current) {
-
- if (current == p_current) return;
+ if (current == p_current) {
+ return;
+ }
ERR_FAIL_INDEX(p_current, get_tab_count());
current = p_current;
@@ -418,7 +398,6 @@ void Tabs::set_current_tab(int p_current) {
}
int Tabs::get_current_tab() const {
-
return current;
}
@@ -435,7 +414,6 @@ bool Tabs::get_offset_buttons_visible() const {
}
void Tabs::set_tab_title(int p_tab, const String &p_title) {
-
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs.write[p_tab].text = p_title;
tabs.write[p_tab].xl_text = tr(p_title);
@@ -444,13 +422,11 @@ void Tabs::set_tab_title(int p_tab, const String &p_title) {
}
String Tabs::get_tab_title(int p_tab) const {
-
ERR_FAIL_INDEX_V(p_tab, tabs.size(), "");
return tabs[p_tab].text;
}
void Tabs::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
-
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs.write[p_tab].icon = p_icon;
update();
@@ -458,39 +434,35 @@ void Tabs::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
}
Ref<Texture2D> Tabs::get_tab_icon(int p_tab) const {
-
ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture2D>());
return tabs[p_tab].icon;
}
void Tabs::set_tab_disabled(int p_tab, bool p_disabled) {
-
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs.write[p_tab].disabled = p_disabled;
update();
}
-bool Tabs::get_tab_disabled(int p_tab) const {
+bool Tabs::get_tab_disabled(int p_tab) const {
ERR_FAIL_INDEX_V(p_tab, tabs.size(), false);
return tabs[p_tab].disabled;
}
void Tabs::set_tab_right_button(int p_tab, const Ref<Texture2D> &p_right_button) {
-
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs.write[p_tab].right_button = p_right_button;
_update_cache();
update();
minimum_size_changed();
}
-Ref<Texture2D> Tabs::get_tab_right_button(int p_tab) const {
+Ref<Texture2D> Tabs::get_tab_right_button(int p_tab) const {
ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture2D>());
return tabs[p_tab].right_button;
}
void Tabs::_update_hover() {
-
if (!is_inside_tree()) {
return;
}
@@ -499,11 +471,7 @@ void Tabs::_update_hover() {
// test hovering to display right or close button
int hover_now = -1;
int hover_buttons = -1;
- for (int i = 0; i < tabs.size(); i++) {
-
- if (i < offset)
- continue;
-
+ for (int i = offset; i < tabs.size(); i++) {
Rect2 rect = get_tab_rect(i);
if (rect.has_point(pos)) {
hover_now = i;
@@ -559,9 +527,7 @@ void Tabs::_update_cache() {
if (count_resize > 0) {
m_width = MAX((limit - size_fixed) / count_resize, min_width);
}
- for (int i = 0; i < tabs.size(); i++) {
- if (i < offset)
- continue;
+ for (int i = offset; i < tabs.size(); i++) {
Ref<StyleBox> sb;
if (tabs[i].disabled) {
sb = tab_disabled;
@@ -596,7 +562,6 @@ void Tabs::_update_cache() {
}
void Tabs::_on_mouse_exited() {
-
rb_hover = -1;
cb_hover = -1;
hover = -1;
@@ -605,7 +570,6 @@ void Tabs::_on_mouse_exited() {
}
void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
-
Tab t;
t.text = p_str;
t.xl_text = tr(p_str);
@@ -629,33 +593,36 @@ void Tabs::clear_tabs() {
}
void Tabs::remove_tab(int p_idx) {
-
ERR_FAIL_INDEX(p_idx, tabs.size());
tabs.remove(p_idx);
- if (current >= p_idx)
+ if (current >= p_idx) {
current--;
+ }
_update_cache();
call_deferred("_update_hover");
update();
minimum_size_changed();
- if (current < 0)
+ if (current < 0) {
current = 0;
- if (current >= tabs.size())
+ }
+ if (current >= tabs.size()) {
current = tabs.size() - 1;
+ }
_ensure_no_over_offset();
}
Variant Tabs::get_drag_data(const Point2 &p_point) {
-
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return Variant();
+ }
int tab_over = get_tab_idx_at_point(p_point);
- if (tab_over < 0)
+ if (tab_over < 0) {
return Variant();
+ }
HBoxContainer *drag_preview = memnew(HBoxContainer);
@@ -681,16 +648,16 @@ Variant Tabs::get_drag_data(const Point2 &p_point) {
}
bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
-
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return false;
+ }
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return false;
+ }
if (String(d["type"]) == "tab_element") {
-
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
@@ -708,24 +675,25 @@ bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
}
void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
-
- if (!drag_to_rearrange_enabled)
+ if (!drag_to_rearrange_enabled) {
return;
+ }
int hover_now = get_tab_idx_at_point(p_point);
Dictionary d = p_data;
- if (!d.has("type"))
+ if (!d.has("type")) {
return;
+ }
if (String(d["type"]) == "tab_element") {
-
int tab_from_id = d["tab_element"];
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count() - 1;
+ }
move_tab(tab_from_id, hover_now);
emit_signal("reposition_active_tab_request", hover_now);
set_current_tab(hover_now);
@@ -734,11 +702,13 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
Node *from_node = get_node(from_path);
Tabs *from_tabs = Object::cast_to<Tabs>(from_node);
if (from_tabs && from_tabs->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {
- if (tab_from_id >= from_tabs->get_tab_count())
+ if (tab_from_id >= from_tabs->get_tab_count()) {
return;
+ }
Tab moving_tab = from_tabs->tabs[tab_from_id];
- if (hover_now < 0)
+ if (hover_now < 0) {
hover_now = get_tab_count();
+ }
tabs.insert(hover_now, moving_tab);
from_tabs->remove_tab(tab_from_id);
set_current_tab(hover_now);
@@ -751,13 +721,8 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
}
int Tabs::get_tab_idx_at_point(const Point2 &p_point) const {
-
int hover_now = -1;
- for (int i = 0; i < tabs.size(); i++) {
-
- if (i < offset)
- continue;
-
+ for (int i = offset; i < tabs.size(); i++) {
Rect2 rect = get_tab_rect(i);
if (rect.has_point(p_point)) {
hover_now = i;
@@ -768,21 +733,19 @@ int Tabs::get_tab_idx_at_point(const Point2 &p_point) const {
}
void Tabs::set_tab_align(TabAlign p_align) {
-
ERR_FAIL_INDEX(p_align, ALIGN_MAX);
tab_align = p_align;
update();
}
Tabs::TabAlign Tabs::get_tab_align() const {
-
return tab_align;
}
void Tabs::move_tab(int from, int to) {
-
- if (from == to)
+ if (from == to) {
return;
+ }
ERR_FAIL_INDEX(from, tabs.size());
ERR_FAIL_INDEX(to, tabs.size());
@@ -796,7 +759,6 @@ 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");
@@ -809,18 +771,20 @@ int Tabs::get_tab_width(int p_idx) const {
Ref<Texture2D> tex = tabs[p_idx].icon;
if (tex.is_valid()) {
x += tex->get_width();
- if (tabs[p_idx].text != "")
+ if (tabs[p_idx].text != "") {
x += get_theme_constant("hseparation");
+ }
}
x += Math::ceil(font->get_string_size(tabs[p_idx].xl_text).width);
- if (tabs[p_idx].disabled)
+ if (tabs[p_idx].disabled) {
x += tab_disabled->get_minimum_size().width;
- else if (current == p_idx)
+ } else if (current == p_idx) {
x += tab_fg->get_minimum_size().width;
- else
+ } else {
x += tab_bg->get_minimum_size().width;
+ }
if (tabs[p_idx].right_button.is_valid()) {
Ref<Texture2D> rb = tabs[p_idx].right_button;
@@ -838,9 +802,9 @@ int Tabs::get_tab_width(int p_idx) const {
}
void Tabs::_ensure_no_over_offset() {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
Ref<Texture2D> incr = get_theme_icon("increment");
Ref<Texture2D> decr = get_theme_icon("decrement");
@@ -848,13 +812,8 @@ void Tabs::_ensure_no_over_offset() {
int limit = get_size().width - incr->get_width() - decr->get_width();
while (offset > 0) {
-
int total_w = 0;
- for (int i = 0; i < tabs.size(); i++) {
-
- if (i < offset - 1)
- continue;
-
+ for (int i = offset - 1; i < tabs.size(); i++) {
total_w += tabs[i].size_cache;
}
@@ -868,11 +827,13 @@ void Tabs::_ensure_no_over_offset() {
}
void Tabs::ensure_tab_visible(int p_idx) {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
- if (tabs.size() == 0) return;
+ if (tabs.size() == 0) {
+ return;
+ }
ERR_FAIL_INDEX(p_idx, tabs.size());
if (p_idx == offset) {
@@ -900,20 +861,17 @@ void Tabs::ensure_tab_visible(int p_idx) {
}
Rect2 Tabs::get_tab_rect(int p_tab) const {
-
ERR_FAIL_INDEX_V(p_tab, tabs.size(), Rect2());
return Rect2(tabs[p_tab].ofs_cache, 0, tabs[p_tab].size_cache, get_size().height);
}
void Tabs::set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy) {
-
ERR_FAIL_INDEX(p_policy, CLOSE_BUTTON_MAX);
cb_displaypolicy = p_policy;
update();
}
Tabs::CloseButtonDisplayPolicy Tabs::get_tab_close_display_policy() const {
-
return cb_displaypolicy;
}
@@ -936,6 +894,7 @@ void Tabs::set_drag_to_rearrange_enabled(bool p_enabled) {
bool Tabs::get_drag_to_rearrange_enabled() const {
return drag_to_rearrange_enabled;
}
+
void Tabs::set_tabs_rearrange_group(int p_group_id) {
tabs_rearrange_group = p_group_id;
}
@@ -953,7 +912,6 @@ bool Tabs::get_select_with_rmb() const {
}
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("get_tab_count"), &Tabs::get_tab_count);
@@ -1011,7 +969,6 @@ void Tabs::_bind_methods() {
}
Tabs::Tabs() {
-
current = 0;
tab_align = ALIGN_CENTER;
rb_hover = -1;
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 3170acb46f..8757f70ebe 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class Tabs : public Control {
-
GDCLASS(Tabs, Control);
public:
@@ -56,7 +55,6 @@ public:
private:
struct Tab {
-
String text;
String xl_text;
Ref<Texture2D> icon;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index fb477ee3b4..e050b3f174 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -30,7 +30,7 @@
#include "text_edit.h"
-#include "core/input/input_filter.h"
+#include "core/input/input.h"
#include "core/message_queue.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
@@ -45,12 +45,10 @@
#define TAB_PIXELS
inline bool _is_symbol(CharType c) {
-
return is_symbol(c);
}
static bool _is_text_char(CharType c) {
-
return !is_symbol(c);
}
@@ -59,7 +57,6 @@ static bool _is_whitespace(CharType c) {
}
static bool _is_char(CharType c) {
-
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
}
@@ -92,38 +89,41 @@ static bool _is_pair_symbol(CharType c) {
}
static CharType _get_right_pair_symbol(CharType c) {
- if (c == '"')
+ if (c == '"') {
return '"';
- if (c == '\'')
+ }
+ if (c == '\'') {
return '\'';
- if (c == '(')
+ }
+ if (c == '(') {
return ')';
- if (c == '[')
+ }
+ if (c == '[') {
return ']';
- if (c == '{')
+ }
+ if (c == '{') {
return '}';
+ }
return 0;
}
static int _find_first_non_whitespace_column_of_line(const String &line) {
int left = 0;
- while (left < line.length() && _is_whitespace(line[left]))
+ while (left < line.length() && _is_whitespace(line[left])) {
left++;
+ }
return left;
}
void TextEdit::Text::set_font(const Ref<Font> &p_font) {
-
font = p_font;
}
void TextEdit::Text::set_indent_size(int p_indent_size) {
-
indent_size = p_indent_size;
}
void TextEdit::Text::_update_line_cache(int p_line) const {
-
int w = 0;
int len = text[p_line].data.length();
@@ -144,9 +144,9 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
text.write[p_line].region_info.clear();
for (int i = 0; i < len; i++) {
-
- if (!_is_symbol(str[i]))
+ if (!_is_symbol(str[i])) {
continue;
+ }
if (str[i] == '\\') {
i++; // Skip quoted anything.
continue;
@@ -155,7 +155,6 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
int left = len - i;
for (int j = 0; j < color_regions->size(); j++) {
-
const ColorRegion &cr = color_regions->operator[](j);
/* BEGIN */
@@ -177,7 +176,6 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
}
if (match) {
-
ColorRegionInfo cri;
cri.end = false;
cri.region = j;
@@ -204,7 +202,6 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
}
if (match) {
-
ColorRegionInfo cri;
cri.end = true;
cri.region = j;
@@ -219,7 +216,6 @@ 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 {
-
static Map<int, ColorRegionInfo> cri;
ERR_FAIL_INDEX_V(p_line, text.size(), cri);
@@ -231,7 +227,6 @@ const Map<int, TextEdit::Text::ColorRegionInfo> &TextEdit::Text::get_color_regio
}
int TextEdit::Text::get_line_width(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), -1);
if (text[p_line].width_cache == -1) {
@@ -242,28 +237,24 @@ int TextEdit::Text::get_line_width(int p_line) const {
}
void TextEdit::Text::set_line_wrap_amount(int p_line, int p_wrap_amount) const {
-
ERR_FAIL_INDEX(p_line, text.size());
text.write[p_line].wrap_amount_cache = p_wrap_amount;
}
int TextEdit::Text::get_line_wrap_amount(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), -1);
return text[p_line].wrap_amount_cache;
}
void TextEdit::Text::clear_width_cache() {
-
for (int i = 0; i < text.size(); i++) {
text.write[i].width_cache = -1;
}
}
void TextEdit::Text::clear_wrap_cache() {
-
for (int i = 0; i < text.size(); i++) {
text.write[i].wrap_amount_cache = -1;
}
@@ -276,7 +267,6 @@ void TextEdit::Text::clear_info_icons() {
}
void TextEdit::Text::clear() {
-
text.clear();
insert(0, "");
}
@@ -286,14 +276,14 @@ int TextEdit::Text::get_max_width(bool p_exclude_hidden) const {
int max = 0;
for (int i = 0; i < text.size(); i++) {
- if (!p_exclude_hidden || !is_hidden(i))
+ if (!p_exclude_hidden || !is_hidden(i)) {
max = MAX(max, get_line_width(i));
+ }
}
return max;
}
void TextEdit::Text::set(int p_line, const String &p_text) {
-
ERR_FAIL_INDEX(p_line, text.size());
text.write[p_line].width_cache = -1;
@@ -302,7 +292,6 @@ void TextEdit::Text::set(int p_line, const String &p_text) {
}
void TextEdit::Text::insert(int p_at, const String &p_text) {
-
Line line;
line.marked = false;
line.safe = false;
@@ -315,32 +304,29 @@ void TextEdit::Text::insert(int p_at, const String &p_text) {
line.data = p_text;
text.insert(p_at, line);
}
-void TextEdit::Text::remove(int p_at) {
+void TextEdit::Text::remove(int p_at) {
text.remove(p_at);
}
int TextEdit::Text::get_char_width(CharType c, CharType next_c, int px) const {
-
int tab_w = font->get_char_size(' ').width * indent_size;
int w = 0;
if (c == '\t') {
-
int left = px % tab_w;
- if (left == 0)
+ if (left == 0) {
w = tab_w;
- else
+ } else {
w = tab_w - px % tab_w; // Is right.
+ }
} else {
-
w = font->get_char_size(c, next_c).width;
}
return w;
}
void TextEdit::_update_scrollbars() {
-
Size2 size = get_size();
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
@@ -360,8 +346,9 @@ void TextEdit::_update_scrollbars() {
int visible_width = size.width - cache.style_normal->get_minimum_size().width;
int total_width = text.get_max_width(true) + vmin.x;
- if (line_numbers)
+ if (line_numbers) {
total_width += cache.line_number_w;
+ }
if (draw_breakpoint_gutter || draw_bookmark_gutter) {
total_width += cache.breakpoint_gutter_width;
@@ -384,11 +371,9 @@ void TextEdit::_update_scrollbars() {
// Thanks yessopie for this clever bit of logic.
if (total_rows <= visible_rows && total_width <= visible_width) {
-
use_hscroll = false;
use_vscroll = false;
} else {
-
if (total_rows > visible_rows && total_width <= visible_width) {
use_hscroll = false;
}
@@ -401,7 +386,6 @@ void TextEdit::_update_scrollbars() {
updating_scrolls = true;
if (use_vscroll) {
-
v_scroll->show();
v_scroll->set_max(total_rows + get_visible_rows_offset());
v_scroll->set_page(visible_rows + get_visible_rows_offset());
@@ -413,7 +397,6 @@ void TextEdit::_update_scrollbars() {
set_v_scroll(get_v_scroll());
} else {
-
cursor.line_ofs = 0;
cursor.wrap_ofs = 0;
v_scroll->set_value(0);
@@ -421,18 +404,17 @@ void TextEdit::_update_scrollbars() {
}
if (use_hscroll && !is_wrap_enabled()) {
-
h_scroll->show();
h_scroll->set_max(total_width);
h_scroll->set_page(visible_width);
- if (cursor.x_ofs > (total_width - visible_width))
+ if (cursor.x_ofs > (total_width - visible_width)) {
cursor.x_ofs = (total_width - visible_width);
+ }
if (fabs(h_scroll->get_value() - (double)cursor.x_ofs) >= 1) {
h_scroll->set_value(cursor.x_ofs);
}
} else {
-
cursor.x_ofs = 0;
h_scroll->set_value(0);
h_scroll->hide();
@@ -442,11 +424,10 @@ void TextEdit::_update_scrollbars() {
}
void TextEdit::_click_selection_held() {
-
// Warning: is_mouse_button_pressed(BUTTON_LEFT) returns false for double+ clicks, so this doesn't work for MODE_WORD
// and MODE_LINE. However, moving the mouse triggers _gui_input, which calls these functions too, so that's not a huge problem.
// I'm unsure if there's an actual fix that doesn't have a ton of side effects.
- if (InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) {
+ if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) {
switch (selection.selecting_mode) {
case Selection::MODE_POINTER: {
_update_selection_mode_pointer();
@@ -597,7 +578,6 @@ void TextEdit::_update_minimap_click() {
}
void TextEdit::_update_minimap_drag() {
-
if (!can_drag_minimap) {
return;
}
@@ -614,14 +594,15 @@ void TextEdit::_update_minimap_drag() {
}
void TextEdit::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_caches();
- if (cursor_changed_dirty)
+ if (cursor_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
- if (text_changed_dirty)
+ }
+ if (text_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
_update_wrap_at();
} break;
case NOTIFICATION_RESIZED: {
@@ -718,7 +699,6 @@ void TextEdit::_notification(int p_what) {
};
if (line_numbers) {
-
line_number_char_count = cache.line_number_w;
cache.line_number_w = (cache.line_number_w + 1) * cache.font->get_char_size('0').width;
} else {
@@ -728,7 +708,7 @@ void TextEdit::_notification(int p_what) {
_update_scrollbars();
RID ci = get_canvas_item();
- VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
+ RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width;
int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT) - cache.minimap_width;
@@ -738,8 +718,9 @@ void TextEdit::_notification(int p_what) {
cache.style_readonly->draw(ci, Rect2(Point2(), size));
draw_caret = false;
}
- if (has_focus())
+ if (has_focus()) {
cache.style_focus->draw(ci, Rect2(Point2(), size));
+ }
int ascent = cache.font->get_ascent();
@@ -749,14 +730,14 @@ void TextEdit::_notification(int p_what) {
if (syntax_coloring) {
if (cache.background_color.a > 0.01) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color);
}
}
if (line_length_guidelines) {
const int hard_x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_hard_col - cursor.x_ofs;
if (hard_x > xmargin_beg && hard_x < xmargin_end) {
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(hard_x, 0), Point2(hard_x, size.height), cache.line_length_guideline_color);
+ RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(hard_x, 0), Point2(hard_x, size.height), cache.line_length_guideline_color);
}
// Draw a "Soft" line length guideline, less visible than the hard line length guideline.
@@ -764,7 +745,7 @@ void TextEdit::_notification(int p_what) {
// Only drawn if its column differs from the hard line length guideline.
const int soft_x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_soft_col - cursor.x_ofs;
if (hard_x != soft_x && soft_x > xmargin_beg && soft_x < xmargin_end) {
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(soft_x, 0), Point2(soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5));
+ RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(soft_x, 0), Point2(soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5));
}
}
@@ -778,7 +759,6 @@ void TextEdit::_notification(int p_what) {
bool brace_close_mismatch = false;
if (brace_matching_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) {
-
if (cursor.column < text[cursor.line].length()) {
// Check for open.
CharType c = text[cursor.line][cursor.column];
@@ -793,14 +773,11 @@ void TextEdit::_notification(int p_what) {
}
if (closec != 0) {
-
int stack = 1;
for (int i = cursor.line; i < text.size(); i++) {
-
int from = i == cursor.line ? cursor.column + 1 : 0;
for (int j = from; j < text[i].length(); j++) {
-
CharType cc = text[i][j];
// Ignore any brackets inside a string.
if (cc == '"' || cc == '\'') {
@@ -824,10 +801,11 @@ void TextEdit::_notification(int p_what) {
}
}
} while (cc != quotation);
- } else if (cc == c)
+ } else if (cc == c) {
stack++;
- else if (cc == closec)
+ } else if (cc == closec) {
stack--;
+ }
if (stack == 0) {
brace_open_match_line = i;
@@ -837,12 +815,14 @@ void TextEdit::_notification(int p_what) {
break;
}
}
- if (brace_open_match_line != -1)
+ if (brace_open_match_line != -1) {
break;
+ }
}
- if (!brace_open_matching)
+ if (!brace_open_matching) {
brace_open_mismatch = true;
+ }
}
}
@@ -859,14 +839,11 @@ void TextEdit::_notification(int p_what) {
}
if (closec != 0) {
-
int stack = 1;
for (int i = cursor.line; i >= 0; i--) {
-
int from = i == cursor.line ? cursor.column - 2 : text[i].length() - 1;
for (int j = from; j >= 0; j--) {
-
CharType cc = text[i][j];
// Ignore any brackets inside a string.
if (cc == '"' || cc == '\'') {
@@ -890,10 +867,11 @@ void TextEdit::_notification(int p_what) {
}
}
} while (cc != quotation);
- } else if (cc == c)
+ } else if (cc == c) {
stack++;
- else if (cc == closec)
+ } else if (cc == closec) {
stack--;
+ }
if (stack == 0) {
brace_close_match_line = i;
@@ -903,12 +881,14 @@ void TextEdit::_notification(int p_what) {
break;
}
}
- if (brace_close_match_line != -1)
+ if (brace_close_match_line != -1) {
break;
+ }
}
- if (!brace_close_matching)
+ if (!brace_close_matching) {
brace_close_mismatch = true;
+ }
}
}
}
@@ -941,7 +921,7 @@ void TextEdit::_notification(int p_what) {
// calculate viewport size and y offset
int viewport_height = (draw_amount - 1) * minimap_line_height;
int control_height = _get_control_height() - viewport_height;
- int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
+ int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line + 1) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
// calculate the first line.
int num_lines_before = round((viewport_offset_y) / minimap_line_height);
@@ -955,9 +935,8 @@ void TextEdit::_notification(int p_what) {
// draw the minimap
Color viewport_color = (cache.background_color.get_v() < 0.5) ? Color(1, 1, 1, 0.1) : Color(0, 0, 0, 0.1);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.minimap_width, viewport_height), viewport_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.minimap_width, viewport_height), viewport_color);
for (int i = 0; i < minimap_draw_amount; i++) {
-
minimap_line++;
if (minimap_line < 0 || minimap_line >= (int)text.size()) {
@@ -992,8 +971,9 @@ void TextEdit::_notification(int p_what) {
for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
if (line_wrap_index != 0) {
i++;
- if (i >= minimap_draw_amount)
+ if (i >= minimap_draw_amount) {
break;
+ }
}
const String &str = wrap_rows[line_wrap_index];
@@ -1008,7 +988,7 @@ void TextEdit::_notification(int p_what) {
}
if (minimap_line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color);
}
Color previous_color;
@@ -1057,18 +1037,13 @@ void TextEdit::_notification(int p_what) {
// take one for zero indexing, and if we hit whitespace / the end of a word.
int chars = MAX(0, (j - (characters - 1)) - (is_whitespace ? 1 : 0)) + 1;
int char_x_ofs = indent_px + ((xmargin_end + minimap_char_size.x) + (minimap_char_size.x * chars)) + tabs;
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_x_ofs, minimap_line_height * i), Point2(minimap_char_size.x * characters, minimap_char_size.y)), previous_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_x_ofs, minimap_line_height * i), Point2(minimap_char_size.x * characters, minimap_char_size.y)), previous_color);
}
if (out_of_bounds) {
break;
}
- // re-adjust if we went backwards.
- if (color != previous_color && !is_whitespace) {
- characters++;
- }
-
if (str[j] == '\t') {
tabs += minimap_tab_size;
}
@@ -1083,11 +1058,11 @@ void TextEdit::_notification(int p_what) {
// draw main text
int line = first_visible_line;
for (int i = 0; i < draw_amount; i++) {
-
line++;
- if (line < 0 || line >= (int)text.size())
+ if (line < 0 || line >= (int)text.size()) {
continue;
+ }
while (is_line_hidden(line)) {
line++;
@@ -1096,8 +1071,9 @@ void TextEdit::_notification(int p_what) {
}
}
- if (line < 0 || line >= (int)text.size())
+ if (line < 0 || line >= (int)text.size()) {
continue;
+ }
const String &fullstr = text[line];
@@ -1117,8 +1093,9 @@ void TextEdit::_notification(int p_what) {
for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
if (line_wrap_index != 0) {
i++;
- if (i >= draw_amount)
+ if (i >= draw_amount) {
break;
+ }
}
const String &str = wrap_rows[line_wrap_index];
@@ -1127,8 +1104,9 @@ void TextEdit::_notification(int p_what) {
indent_px = 0;
}
- if (line_wrap_index > 0)
+ if (line_wrap_index > 0) {
last_wrap_column += wrap_rows[line_wrap_index - 1].length();
+ }
int char_margin = xmargin_beg - cursor.x_ofs;
char_margin += indent_px;
@@ -1143,45 +1121,46 @@ void TextEdit::_notification(int p_what) {
int ofs_y = (i * get_row_height() + cache.line_spacing / 2) + ofs_readonly;
ofs_y -= cursor.wrap_ofs * get_row_height();
- if (smooth_scroll_enabled)
- ofs_y += (-get_v_scroll_offset()) * get_row_height();
+ ofs_y -= get_v_scroll_offset() * get_row_height();
// Check if line contains highlighted word.
int highlighted_text_col = -1;
int search_text_col = -1;
int highlighted_word_col = -1;
- if (!search_text.empty())
+ if (!search_text.empty()) {
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, 0);
+ }
- if (highlighted_text.length() != 0 && highlighted_text != search_text)
+ if (highlighted_text.length() != 0 && highlighted_text != search_text) {
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
+ }
if (select_identifiers_enabled && highlighted_word.length() != 0) {
- if (_is_char(highlighted_word[0])) {
+ if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') {
highlighted_word_col = _get_column_pos_of_word(highlighted_word, fullstr, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
}
}
if (text.is_marked(line)) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color);
}
if (str.length() == 0) {
// Draw line background if empty as we won't loop at at all.
if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, get_row_height()), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, get_row_height()), cache.current_line_color);
}
// Give visual indication of empty selected line.
if (selection.active && line >= selection.from_line && line <= selection.to_line && char_margin >= xmargin_beg) {
int char_w = cache.font->get_char_size(' ').width;
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, get_row_height()), cache.selection_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, get_row_height()), cache.selection_color);
}
} 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 && cursor_wrap_index == line_wrap_index && highlight_current_line) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg + ofs_x, get_row_height()), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg + ofs_x, get_row_height()), cache.current_line_color);
}
}
@@ -1190,9 +1169,9 @@ void TextEdit::_notification(int p_what) {
if (text.is_breakpoint(line) && !draw_breakpoint_gutter) {
#ifdef TOOLS_ENABLED
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.breakpoint_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.breakpoint_color);
#else
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.breakpoint_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.breakpoint_color);
#endif
}
@@ -1202,7 +1181,7 @@ void TextEdit::_notification(int p_what) {
int vertical_gap = (get_row_height() * 40) / 100;
int horizontal_gap = (cache.breakpoint_gutter_width * 30) / 100;
int marker_radius = get_row_height() - (vertical_gap * 2);
- VisualServer::get_singleton()->canvas_item_add_circle(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2 + marker_radius / 2, ofs_y + vertical_gap + marker_radius / 2), marker_radius, Color(cache.bookmark_color.r, cache.bookmark_color.g, cache.bookmark_color.b));
+ RenderingServer::get_singleton()->canvas_item_add_circle(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2 + marker_radius / 2, ofs_y + vertical_gap + marker_radius / 2), marker_radius, Color(cache.bookmark_color.r, cache.bookmark_color.g, cache.bookmark_color.b));
}
}
@@ -1214,7 +1193,7 @@ void TextEdit::_notification(int p_what) {
int marker_height = get_row_height() - (vertical_gap * 2);
int marker_width = cache.breakpoint_gutter_width - (horizontal_gap * 2);
// No transparency on marker.
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2, ofs_y + vertical_gap, marker_width, marker_height), Color(cache.breakpoint_color.r, cache.breakpoint_color.g, cache.breakpoint_color.b));
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2, ofs_y + vertical_gap, marker_width, marker_height), Color(cache.breakpoint_color.r, cache.breakpoint_color.g, cache.breakpoint_color.b));
}
}
@@ -1254,9 +1233,9 @@ void TextEdit::_notification(int p_what) {
cache.executing_icon->draw_rect(ci, Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2 - icon_extra_size / 2, ofs_y + vertical_gap - icon_extra_size / 2, marker_width, marker_height), false, Color(cache.executing_line_color.r, cache.executing_line_color.g, cache.executing_line_color.b));
} else {
#ifdef TOOLS_ENABLED
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.executing_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.executing_line_color);
#else
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.executing_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.executing_line_color);
#endif
}
}
@@ -1291,7 +1270,6 @@ void TextEdit::_notification(int p_what) {
// Loop through characters in one line.
int j = 0;
for (; j < str.length(); j++) {
-
if (syntax_coloring) {
if (color_map.has(last_wrap_column + j)) {
current_color = color_map[last_wrap_column + j].color;
@@ -1312,13 +1290,12 @@ void TextEdit::_notification(int p_what) {
// Line highlighting handle horizontal clipping.
if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
-
if (j == str.length() - 1) {
// 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 - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color);
+ RenderingServer::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);
} 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 + ofs_x), get_row_height()), cache.current_line_color);
+ RenderingServer::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);
}
}
continue;
@@ -1332,13 +1309,14 @@ void TextEdit::_notification(int p_what) {
if (search_text_col != -1) {
// If we are at the end check for new search result on same line.
- if (j >= search_text_col + search_text.length())
+ if (j >= search_text_col + search_text.length()) {
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, j);
+ }
in_search_result = j >= search_text_col && j < search_text_col + search_text.length();
if (in_search_result) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.search_result_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.search_result_color);
}
}
@@ -1348,37 +1326,38 @@ void TextEdit::_notification(int p_what) {
if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
// Draw the wrap indent offset highlight.
if (line_wrap_index != 0 && j == 0) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + ofs_x - indent_px, ofs_y, indent_px, get_row_height()), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + ofs_x - indent_px, ofs_y, indent_px, get_row_height()), cache.current_line_color);
}
// If its the last char draw to end of the line.
if (j == str.length() - 1) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + char_w + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + char_w + ofs_x, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color);
}
// Actual text.
if (!in_selection) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.current_line_color);
}
}
if (in_selection) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.selection_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.selection_color);
}
if (in_search_result) {
Color border_color = (line == search_result_line && j >= search_result_col && j < search_result_col + search_text.length()) ? cache.font_color : cache.search_result_border_color;
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, 1)), border_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y + get_row_height() - 1), Size2i(char_w, 1)), border_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, 1)), border_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y + get_row_height() - 1), Size2i(char_w, 1)), border_color);
- if (j == search_text_col)
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(1, get_row_height())), border_color);
- if (j == search_text_col + search_text.length() - 1)
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w + ofs_x - 1, ofs_y), Size2i(1, get_row_height())), border_color);
+ if (j == search_text_col) {
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(1, get_row_height())), border_color);
+ }
+ if (j == search_text_col + search_text.length() - 1) {
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w + ofs_x - 1, ofs_y), Size2i(1, get_row_height())), border_color);
+ }
}
if (highlight_all_occurrences && !only_whitespaces_highlighted) {
if (highlighted_text_col != -1) {
-
// If we are at the end check for new word on same line.
if (j > highlighted_text_col + highlighted_text.length()) {
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, j);
@@ -1392,7 +1371,7 @@ void TextEdit::_notification(int p_what) {
}
if (in_highlighted_word) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.word_highlighted_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + ofs_x, ofs_y), Size2i(char_w, get_row_height())), cache.word_highlighted_color);
}
}
}
@@ -1408,23 +1387,22 @@ void TextEdit::_notification(int p_what) {
int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
if ((brace_open_match_line == line && brace_open_match_column == last_wrap_column + j) ||
(cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
-
- if (brace_open_mismatch)
+ if (brace_open_mismatch) {
color = cache.brace_mismatch_color;
+ }
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
if ((brace_close_match_line == line && brace_close_match_column == last_wrap_column + j) ||
(cursor.column == last_wrap_column + j + 1 && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_close_matching || brace_close_mismatch))) {
-
- if (brace_close_mismatch)
+ if (brace_close_mismatch) {
color = cache.brace_mismatch_color;
+ }
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
}
if (cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index) {
-
cursor_pos = Point2i(char_ofs + char_margin + ofs_x, ofs_y);
cursor_pos.y += (get_row_height() - cache.font->get_height()) / 2;
@@ -1437,21 +1415,23 @@ void TextEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = ime_text[ofs];
CharType next = ime_text[ofs + 1];
int im_char_width = cache.font->get_char_size(cchar, next).width;
- if ((char_ofs + char_margin + im_char_width) >= xmargin_end)
+ if ((char_ofs + char_margin + im_char_width) >= xmargin_end) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color);
} else {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color);
}
drawer.draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color);
@@ -1468,7 +1448,7 @@ void TextEdit::_notification(int p_what) {
#else
int caret_h = (block_caret) ? 4 : 2;
#endif
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, caret_h)), cache.caret_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, caret_h)), cache.caret_color);
} else {
#ifdef TOOLS_ENABLED
caret_w = (block_caret) ? caret_w : 2 * EDSCALE;
@@ -1476,7 +1456,7 @@ void TextEdit::_notification(int p_what) {
caret_w = (block_caret) ? caret_w : 2;
#endif
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color);
}
}
}
@@ -1492,12 +1472,12 @@ void TextEdit::_notification(int p_what) {
int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
int w = drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), str[j], str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
if (underlined) {
- float line_width = 1.0;
+ float line_width = cache.font->get_underline_thickness();
#ifdef TOOLS_ENABLED
line_width *= EDSCALE;
#endif
- draw_rect(Rect2(char_ofs + char_margin + ofs_x, yofs + ascent + 2, w, line_width), in_selection && override_selected_font_color ? cache.font_color_selected : color);
+ draw_rect(Rect2(char_ofs + char_margin + ofs_x, yofs + ascent + cache.font->get_underline_position(), w, line_width), in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
} else if (draw_tabs && str[j] == '\t') {
int yofs = (get_row_height() - cache.tab_icon->get_height()) / 2;
@@ -1521,7 +1501,6 @@ void TextEdit::_notification(int p_what) {
}
if (cursor.column == (last_wrap_column + j) && cursor.line == line && cursor_wrap_index == line_wrap_index && (char_ofs + char_margin) >= xmargin_beg) {
-
cursor_pos = Point2i(char_ofs + char_margin + ofs_x, ofs_y);
cursor_pos.y += (get_row_height() - cache.font->get_height()) / 2;
@@ -1532,21 +1511,23 @@ void TextEdit::_notification(int p_what) {
if (ime_text.length() > 0) {
int ofs = 0;
while (true) {
- if (ofs >= ime_text.length())
+ if (ofs >= ime_text.length()) {
break;
+ }
CharType cchar = ime_text[ofs];
CharType next = ime_text[ofs + 1];
int im_char_width = cache.font->get_char_size(cchar, next).width;
- if ((char_ofs + char_margin + im_char_width) >= xmargin_end)
+ if ((char_ofs + char_margin + im_char_width) >= xmargin_end) {
break;
+ }
bool selected = ofs >= ime_selection.x && ofs < ime_selection.x + ime_selection.y;
if (selected) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 3)), color);
} else {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color);
}
drawer.draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color);
@@ -1564,7 +1545,7 @@ void TextEdit::_notification(int p_what) {
#else
int caret_h = (block_caret) ? 4 : 2;
#endif
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(char_w, caret_h)), cache.caret_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(char_w, caret_h)), cache.caret_color);
} else {
int char_w = cache.font->get_char_size(' ').width;
#ifdef TOOLS_ENABLED
@@ -1573,7 +1554,7 @@ void TextEdit::_notification(int p_what) {
int caret_w = (block_caret) ? char_w : 2;
#endif
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, cache.font->get_height())), cache.caret_color);
}
}
}
@@ -1599,8 +1580,9 @@ 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].display).x, cmax_width);
- if (w2 > w)
+ if (w2 > w) {
w = w2;
+ }
}
} else {
w = cmax_width;
@@ -1628,20 +1610,20 @@ void TextEdit::_notification(int p_what) {
completion_rect.size.width = w + 2;
completion_rect.size.height = h;
- if (completion_options_size <= maxlines)
+ if (completion_options_size <= maxlines) {
scrollw = 0;
+ }
draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
if (cache.completion_background_color.a > 0.01) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color);
}
int line_from = CLAMP(completion_index - lines / 2, 0, completion_options_size - lines);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color);
draw_rect(Rect2(completion_rect.position + Vector2(icon_area_size.x + icon_hsep, 0), Size2(MIN(nofs, completion_rect.size.width - (icon_area_size.x + icon_hsep)), completion_rect.size.height)), cache.completion_existing_color);
for (int i = 0; i < lines; i++) {
-
int l = line_from + i;
ERR_CONTINUE(l < 0 || l >= completion_options_size);
Color text_color = cache.completion_font_color;
@@ -1693,7 +1675,6 @@ void TextEdit::_notification(int p_what) {
}
if (show_hint) {
-
Ref<StyleBox> sb = get_theme_stylebox("panel", "TooltipPanel");
Ref<Font> font = cache.font;
Color font_color = get_theme_color("font_color", "TooltipLabel");
@@ -1703,7 +1684,6 @@ void TextEdit::_notification(int p_what) {
int offset = 0;
int spacing = 0;
for (int i = 0; i < sc; i++) {
-
String l = completion_hint.get_slice("\n", i);
int len = font->get_string_size(l).x;
max_w = MAX(len, max_w);
@@ -1761,7 +1741,6 @@ void TextEdit::_notification(int p_what) {
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
-
if (caret_blink_enabled) {
caret_blink_timer->start();
} else {
@@ -1774,11 +1753,11 @@ void TextEdit::_notification(int p_what) {
DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor_pos, get_viewport()->get_window_id());
}
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect());
+ }
} break;
case NOTIFICATION_FOCUS_EXIT: {
-
if (caret_blink_enabled) {
caret_blink_timer->stop();
}
@@ -1790,11 +1769,11 @@ void TextEdit::_notification(int p_what) {
ime_text = "";
ime_selection = Point2();
- if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD))
+ if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD)) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
+ }
} break;
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
-
if (has_focus()) {
ime_text = DisplayServer::get_singleton()->ime_get_text();
ime_selection = DisplayServer::get_singleton()->ime_get_selection();
@@ -1805,7 +1784,6 @@ void TextEdit::_notification(int p_what) {
}
void TextEdit::_consume_pair_symbol(CharType ch) {
-
int cursor_position_to_move = cursor_get_column() + 1;
CharType ch_single[2] = { ch, 0 };
@@ -1813,7 +1791,6 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
CharType ch_pair[3] = { ch, _get_right_pair_symbol(ch), 0 };
if (is_selection_active()) {
-
int new_column, new_line;
begin_complex_operation();
@@ -1822,8 +1799,9 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
&new_line, &new_column);
int to_col_offset = 0;
- if (get_selection_from_line() == get_selection_to_line())
+ if (get_selection_from_line() == get_selection_to_line()) {
to_col_offset = 1;
+ }
_insert_text(get_selection_to_line(),
get_selection_to_column() + to_col_offset,
@@ -1912,11 +1890,9 @@ void TextEdit::_consume_pair_symbol(CharType ch) {
}
void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column) {
-
bool remove_right_symbol = false;
if (cursor.column < text[cursor.line].length() && cursor.column > 0) {
-
CharType left_char = text[cursor.line][cursor.column - 1];
CharType right_char = text[cursor.line][cursor.column];
@@ -1932,20 +1908,24 @@ void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column
}
void TextEdit::backspace_at_cursor() {
- if (readonly)
+ if (readonly) {
return;
+ }
- if (cursor.column == 0 && cursor.line == 0)
+ if (cursor.column == 0 && cursor.line == 0) {
return;
+ }
int prev_line = cursor.column ? cursor.line : cursor.line - 1;
int prev_column = cursor.column ? (cursor.column - 1) : (text[cursor.line - 1].length());
- if (is_line_hidden(cursor.line))
+ if (is_line_hidden(cursor.line)) {
set_line_as_hidden(prev_line, true);
+ }
if (is_line_set_as_breakpoint(cursor.line)) {
- if (!text.is_breakpoint(prev_line))
+ if (!text.is_breakpoint(prev_line)) {
emit_signal("breakpoint_toggled", prev_line);
+ }
set_line_as_breakpoint(prev_line, true);
}
@@ -1990,7 +1970,6 @@ void TextEdit::backspace_at_cursor() {
}
void TextEdit::indent_right() {
-
int start_line;
int end_line;
@@ -2021,8 +2000,9 @@ void TextEdit::indent_right() {
int spaces_to_add = _calculate_spaces_till_next_right_indent(left);
// Since we will add this much spaces we want move whole selection and cursor by this much.
selection_offset = spaces_to_add;
- for (int j = 0; j < spaces_to_add; j++)
+ for (int j = 0; j < spaces_to_add; j++) {
line_text = ' ' + line_text;
+ }
} else {
line_text = '\t' + line_text;
}
@@ -2039,7 +2019,6 @@ void TextEdit::indent_right() {
}
void TextEdit::indent_left() {
-
int start_line;
int end_line;
@@ -2100,8 +2079,9 @@ void TextEdit::indent_left() {
int TextEdit::_calculate_spaces_till_next_left_indent(int column) {
int spaces_till_indent = column % indent_size;
- if (spaces_till_indent == 0)
+ if (spaces_till_indent == 0) {
spaces_till_indent = indent_size;
+ }
return spaces_till_indent;
}
@@ -2110,7 +2090,6 @@ int TextEdit::_calculate_spaces_till_next_right_indent(int column) {
}
void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const {
-
float rows = p_mouse.y;
rows -= cache.style_normal->get_margin(MARGIN_TOP);
rows /= get_row_height();
@@ -2120,25 +2099,24 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
int wrap_index = 0;
if (is_wrap_enabled() || is_hiding_enabled()) {
-
int f_ofs = num_lines_from_rows(first_vis_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
- if (rows < 0)
+ if (rows < 0) {
row = first_vis_line - f_ofs;
- else
+ } else {
row = first_vis_line + f_ofs;
+ }
}
- if (row < 0)
+ if (row < 0) {
row = 0; // TODO.
+ }
int col = 0;
if (row >= text.size()) {
-
row = text.size() - 1;
col = text[row].size();
} else {
-
int colx = p_mouse.x - (cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width);
colx += cursor.x_ofs;
col = get_char_pos_for_line(colx, row, wrap_index);
@@ -2149,8 +2127,9 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
for (int i = 0; i < wrap_index + 1; i++) {
row_end_col += rows2[i].length();
}
- if (col >= row_end_col)
+ if (col >= row_end_col) {
col -= 1;
+ }
}
}
@@ -2186,7 +2165,7 @@ Vector2i TextEdit::_get_cursor_pixel_pos() {
int x = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width - cursor.x_ofs;
int ix = 0;
while (ix < rows2[0].size() && ix < cursor.column) {
- if (cache.font != NULL) {
+ if (cache.font != nullptr) {
x += cache.font->get_char_size(rows2[0].get(ix)).width;
}
ix++;
@@ -2197,7 +2176,6 @@ Vector2i TextEdit::_get_cursor_pixel_pos() {
}
void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const {
-
float rows = p_mouse.y;
rows -= cache.style_normal->get_margin(MARGIN_TOP);
rows /= (minimap_char_size.y + minimap_line_spacing);
@@ -2231,7 +2209,6 @@ void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const
int wrap_index = 0;
if (is_wrap_enabled() || is_hiding_enabled()) {
-
int f_ofs = num_lines_from_rows(minimap_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
if (rows < 0) {
row = minimap_line - f_ofs;
@@ -2252,7 +2229,6 @@ void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const
}
void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
-
double prev_v_scroll = v_scroll->get_value();
double prev_h_scroll = h_scroll->get_value();
@@ -2260,9 +2236,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb.is_valid()) {
if (completion_active && completion_rect.has_point(mb->get_position())) {
-
- if (!mb->is_pressed())
+ if (!mb->is_pressed()) {
return;
+ }
if (mb->get_button_index() == BUTTON_WHEEL_UP) {
if (completion_index > 0) {
@@ -2272,7 +2248,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
if (mb->get_button_index() == BUTTON_WHEEL_DOWN) {
-
if (completion_index < completion_options.size() - 1) {
completion_index++;
completion_current = completion_options[completion_index];
@@ -2281,13 +2256,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (mb->get_button_index() == BUTTON_LEFT) {
-
completion_index = CLAMP(completion_line_ofs + (mb->get_position().y - completion_rect.position.y) / get_row_height(), 0, completion_options.size() - 1);
completion_current = completion_options[completion_index];
update();
- if (mb->is_doubleclick())
+ if (mb->is_doubleclick()) {
_confirm_completion();
+ }
}
return;
} else {
@@ -2296,7 +2271,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (mb->is_pressed()) {
-
if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {
if (mb->get_shift()) {
h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
@@ -2318,7 +2292,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
h_scroll->set_value(h_scroll->get_value() + (100 * mb->get_factor()));
}
if (mb->get_button_index() == BUTTON_LEFT) {
-
_reset_caret_blink_timer();
int row, col;
@@ -2346,7 +2319,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Toggle fold on gutter click if can.
if (draw_fold_gutter) {
-
int left_margin = cache.style_normal->get_margin(MARGIN_LEFT);
int gutter_left = left_margin + cache.breakpoint_gutter_width + cache.line_number_w + cache.info_gutter_width;
if (mb->get_position().x > gutter_left - 6 && mb->get_position().x <= gutter_left + cache.fold_gutter_width - 3) {
@@ -2384,7 +2356,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(col);
if (mb->get_shift() && (cursor.column != prev_col || cursor.line != prev_line)) {
-
if (!selection.active) {
selection.active = true;
selection.selecting_mode = Selection::MODE_POINTER;
@@ -2404,9 +2375,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.selecting_column = prev_col;
update();
} else {
-
if (cursor.line < selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column < selection.selecting_column)) {
-
if (selection.shiftclick_left) {
SWAP(selection.from_column, selection.to_column);
SWAP(selection.from_line, selection.to_line);
@@ -2416,7 +2385,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.from_line = cursor.line;
} else if (cursor.line > selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column > selection.selecting_column)) {
-
if (!selection.shiftclick_left) {
SWAP(selection.from_column, selection.to_column);
SWAP(selection.from_line, selection.to_line);
@@ -2433,7 +2401,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} else {
-
selection.active = false;
selection.selecting_mode = Selection::MODE_POINTER;
selection.selecting_line = row;
@@ -2441,13 +2408,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (!mb->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) {
-
// Triple-click select line.
selection.selecting_mode = Selection::MODE_LINE;
_update_selection_mode_line();
last_dblclk = 0;
} else if (mb->is_doubleclick() && text[cursor.line].length()) {
-
// Double-click select word.
selection.selecting_mode = Selection::MODE_WORD;
_update_selection_mode_word();
@@ -2458,7 +2423,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (mb->get_button_index() == BUTTON_RIGHT && context_menu_enabled) {
-
_reset_caret_blink_timer();
int row, col;
@@ -2466,7 +2430,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (is_right_click_moving_caret()) {
if (is_selection_active()) {
-
int from_line = get_selection_from_line();
int to_line = get_selection_to_line();
int from_column = get_selection_from_column();
@@ -2490,7 +2453,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
grab_focus();
}
} else {
-
if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->get_command() && highlighted_word != String()) {
int row, col;
@@ -2513,7 +2475,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
const Ref<InputEventPanGesture> pan_gesture = p_gui_input;
if (pan_gesture.is_valid()) {
-
const real_t delta = pan_gesture->get_delta().y;
if (delta < 0) {
_scroll_up(-delta);
@@ -2521,8 +2482,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_scroll_down(delta);
}
h_scroll->set_value(h_scroll->get_value() + pan_gesture->get_delta().x * 100);
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed.
+ }
return;
}
@@ -2530,10 +2492,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventMouseMotion> mm = p_gui_input;
if (mm.is_valid()) {
-
if (select_identifiers_enabled) {
if (!dragging_minimap && !dragging_selection && mm->get_command() && mm->get_button_mask() == 0) {
-
String new_word = get_word_at_pos(mm->get_position());
if (new_word != highlighted_word) {
emit_signal("symbol_validate", new_word);
@@ -2571,13 +2531,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll)
+ if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed.
+ }
Ref<InputEventKey> k = p_gui_input;
if (k.is_valid()) {
-
k = k->duplicate(); // It will be modified later on.
#ifdef OSX_ENABLED
@@ -2587,7 +2547,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
#endif
if (select_identifiers_enabled) {
-
if (k->is_pressed() && !dragging_minimap && !dragging_selection) {
emit_signal("symbol_validate", get_word_at_pos(get_local_mouse_position()));
} else {
@@ -2596,22 +2555,23 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
+ }
if (completion_active) {
- if (readonly)
+ if (readonly) {
return;
+ }
bool valid = true;
- if (k->get_command() || k->get_metakey())
+ if (k->get_command() || k->get_metakey()) {
valid = false;
+ }
if (valid) {
-
if (!k->get_alt()) {
if (k->get_keycode() == KEY_UP) {
-
if (completion_index > 0) {
completion_index--;
} else {
@@ -2625,7 +2585,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_keycode() == KEY_DOWN) {
-
if (completion_index < completion_options.size() - 1) {
completion_index++;
} else {
@@ -2639,10 +2598,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_keycode() == KEY_PAGEUP) {
-
completion_index -= get_theme_constant("completion_lines");
- if (completion_index < 0)
+ if (completion_index < 0) {
completion_index = 0;
+ }
completion_current = completion_options[completion_index];
update();
accept_event();
@@ -2650,10 +2609,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_keycode() == KEY_PAGEDOWN) {
-
completion_index += get_theme_constant("completion_lines");
- if (completion_index >= completion_options.size())
+ if (completion_index >= completion_options.size()) {
completion_index = completion_options.size() - 1;
+ }
completion_current = completion_options[completion_index];
update();
accept_event();
@@ -2661,7 +2620,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_keycode() == KEY_HOME && completion_index > 0) {
-
completion_index = 0;
completion_current = completion_options[completion_index];
update();
@@ -2670,7 +2628,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_keycode() == KEY_END && completion_index < completion_options.size() - 1) {
-
completion_index = completion_options.size() - 1;
completion_current = completion_options[completion_index];
update();
@@ -2679,14 +2636,12 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_keycode() == KEY_KP_ENTER || k->get_keycode() == KEY_ENTER || k->get_keycode() == KEY_TAB) {
-
_confirm_completion();
accept_event();
return;
}
if (k->get_keycode() == KEY_BACKSPACE) {
-
_reset_caret_blink_timer();
backspace_at_cursor();
@@ -2702,14 +2657,12 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_unicode() > 32) {
-
_reset_caret_blink_timer();
const CharType chr[2] = { (CharType)k->get_unicode(), 0 };
if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
_consume_pair_symbol(chr[0]);
} else {
-
// Remove the old character if in insert mode.
if (insert_mode) {
begin_complex_operation();
@@ -2740,11 +2693,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Some remaps for duplicate functions.
if (k->get_command() && !k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_keycode() == KEY_INSERT) {
-
k->set_keycode(KEY_C);
}
if (!k->get_command() && k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_keycode() == KEY_INSERT) {
-
k->set_keycode(KEY_V);
k->set_command(true);
k->set_shift(false);
@@ -2787,13 +2738,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Stuff to do when selection is active.
if (!readonly && selection.active) {
-
bool clear = false;
bool unselect = false;
bool dobreak = false;
switch (k->get_keycode()) {
-
case KEY_TAB: {
if (k->get_shift()) {
indent_left();
@@ -2831,16 +2780,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
case KEY_HOME:
case KEY_END:
// Ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys).
- if (k->get_command() || k->get_shift() || k->get_alt())
+ if (k->get_command() || k->get_shift() || k->get_alt()) {
break;
+ }
unselect = true;
break;
default:
- if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey())
+ if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey()) {
clear = true;
- if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode()))
+ }
+ if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode())) {
clear = false;
+ }
}
if (unselect) {
@@ -2849,7 +2801,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
update();
}
if (clear) {
-
if (!dobreak) {
begin_complex_operation();
}
@@ -2860,8 +2811,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(selection.from_column);
update();
}
- if (dobreak)
+ if (dobreak) {
return;
+ }
}
selection.selecting_text = false;
@@ -2871,12 +2823,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Special keycode test.
switch (k->get_keycode()) {
-
case KEY_KP_ENTER:
case KEY_ENTER: {
-
- if (readonly)
+ if (readonly) {
break;
+ }
String ins = "\n";
@@ -2906,8 +2857,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (is_folded(cursor.line))
+ if (is_folded(cursor.line)) {
unfold_line(cursor.line);
+ }
bool brace_indent = false;
@@ -2936,7 +2888,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (indent_char_found && cri_map.has(i) && (color_regions[cri_map[i].region].begin_key == "#" || color_regions[cri_map[i].region].begin_key == "//")) {
-
should_indent = true;
break;
} else if (indent_char_found && !_is_whitespace(c)) {
@@ -2996,10 +2947,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} break;
case KEY_TAB: {
- if (k->get_command()) break; // Avoid tab when command.
+ if (k->get_command()) {
+ break; // Avoid tab when command.
+ }
- if (readonly)
+ if (readonly) {
break;
+ }
if (is_selection_active()) {
if (k->get_shift()) {
@@ -3009,7 +2963,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} else {
if (k->get_shift()) {
-
// Simple unindent.
int cc = cursor.column;
const String &line = text[cursor.line];
@@ -3017,23 +2970,26 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int left = _find_first_non_whitespace_column_of_line(line);
cc = MIN(cc, left);
- while (cc < indent_size && cc < left && line[cc] == ' ')
+ while (cc < indent_size && cc < left && line[cc] == ' ') {
cc++;
+ }
if (cc > 0 && cc <= text[cursor.line].length()) {
if (text[cursor.line][cc - 1] == '\t') {
// Tabs unindentation.
_remove_text(cursor.line, cc - 1, cursor.line, cc);
- if (cursor.column >= left)
+ if (cursor.column >= left) {
cursor_set_column(MAX(0, cursor.column - 1));
+ }
update();
} else {
// Spaces unindentation.
int spaces_to_remove = _calculate_spaces_till_next_left_indent(cc);
if (spaces_to_remove > 0) {
_remove_text(cursor.line, cc - spaces_to_remove, cursor.line, cc);
- if (cursor.column > left - spaces_to_remove) // Inside text?
+ if (cursor.column > left - spaces_to_remove) { // Inside text?
cursor_set_column(MAX(0, cursor.column - spaces_to_remove));
+ }
update();
}
}
@@ -3047,8 +3003,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// Insert only as much spaces as needed till next indentation level.
int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor.column);
String indent_to_insert = String();
- for (int i = 0; i < spaces_to_add; i++)
+ for (int i = 0; i < spaces_to_add; i++) {
indent_to_insert = ' ' + indent_to_insert;
+ }
_insert_text_at_cursor(indent_to_insert);
} else {
_insert_text_at_cursor("\t");
@@ -3058,8 +3015,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_BACKSPACE: {
- if (readonly)
+ if (readonly) {
break;
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_alt() && cursor.column > 1) {
@@ -3114,8 +3072,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_remove_text(cursor.line, 0, cursor.line, cursor_current_column);
#endif
} else {
- if (cursor.line > 0 && is_line_hidden(cursor.line - 1))
+ if (cursor.line > 0 && is_line_hidden(cursor.line - 1)) {
unfold_line(cursor.line - 1);
+ }
backspace_at_cursor();
}
@@ -3128,15 +3087,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_LEFT: {
-
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ } else {
#else
- else if (!k->get_alt())
+ } else if (!k->get_alt()) {
#endif
deselect();
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
@@ -3173,8 +3132,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
while (cc > 0) {
bool ischar = _is_text_char(text[cursor.line][cc - 1]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc--;
@@ -3183,7 +3143,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} else if (cursor.column == 0) {
-
if (cursor.line > 0) {
cursor_set_line(cursor.line - num_lines_from(CLAMP(cursor.line - 1, 0, text.size() - 1), -1));
cursor_set_column(text[cursor.line].length());
@@ -3192,8 +3151,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(cursor_get_column() - 1);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
} break;
case KEY_KP_6: {
@@ -3204,15 +3164,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_RIGHT: {
-
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ } else {
#else
- else if (!k->get_alt())
+ } else if (!k->get_alt()) {
#endif
deselect();
+ }
#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
@@ -3235,8 +3195,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
while (cc < text[cursor.line].length()) {
bool ischar = _is_text_char(text[cursor.line][cc]);
- if (prev_char && !ischar)
+ if (prev_char && !ischar) {
break;
+ }
prev_char = ischar;
cc++;
}
@@ -3244,7 +3205,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} else if (cursor.column == text[cursor.line].length()) {
-
if (cursor.line < text.size() - 1) {
cursor_set_line(cursor_get_line() + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1), true, false);
cursor_set_column(0);
@@ -3253,8 +3213,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(cursor_get_column() + 1);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
} break;
case KEY_KP_8: {
@@ -3265,7 +3226,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_UP: {
-
if (k->get_alt()) {
keycode_handled = false;
break;
@@ -3285,7 +3245,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
-
cursor_set_line(0);
} else
#endif
@@ -3305,8 +3264,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_code_hint();
} break;
@@ -3318,7 +3278,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_DOWN: {
-
if (k->get_alt()) {
keycode_handled = false;
break;
@@ -3353,15 +3312,16 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_code_hint();
} break;
case KEY_DELETE: {
-
- if (readonly)
+ if (readonly) {
break;
+ }
if (k->get_shift() && !k->get_command() && !k->get_alt() && is_shortcut_keys_enabled()) {
cut();
@@ -3370,8 +3330,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int curline_len = text[cursor.line].length();
- if (cursor.line == text.size() - 1 && cursor.column == curline_len)
+ if (cursor.line == text.size() - 1 && cursor.column == curline_len) {
break; // Nothing to do.
+ }
int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
int next_column;
@@ -3452,14 +3413,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
else if (k->get_command() || k->get_control())
deselect();
#else
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
if (k->get_command()) {
cursor_set_line(0);
cursor_set_column(0);
} else {
-
// Move cursor column to start of wrapped row and then to start of text.
Vector<String> rows = get_wrap_rows_text(cursor.line);
int wi = get_cursor_wrap_index();
@@ -3472,24 +3433,27 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
int current_line_whitespace_len = 0;
while (current_line_whitespace_len < text[cursor.line].length()) {
CharType c = text[cursor.line][current_line_whitespace_len];
- if (c != '\t' && c != ' ')
+ if (c != '\t' && c != ' ') {
break;
+ }
current_line_whitespace_len++;
}
- if (cursor_get_column() == current_line_whitespace_len)
+ if (cursor_get_column() == current_line_whitespace_len) {
cursor_set_column(0);
- else
+ } else {
cursor_set_column(current_line_whitespace_len);
+ }
} else {
cursor_set_column(row_start_col);
}
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
- else if (k->get_command() || k->get_control())
+ } else if (k->get_command() || k->get_control()) {
deselect();
+ }
_cancel_completion();
completion_hint = "";
#endif
@@ -3513,11 +3477,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
else if (k->get_command() || k->get_control())
deselect();
#else
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
- if (k->get_command())
+ if (k->get_command()) {
cursor_set_line(get_last_unhidden_line(), true, false, 9999);
+ }
// Move cursor column to end of wrapped row and then to end of text.
Vector<String> rows = get_wrap_rows_text(cursor.line);
@@ -3532,10 +3498,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(row_end_col);
}
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
- else if (k->get_command() || k->get_control())
+ } else if (k->get_command() || k->get_control()) {
deselect();
+ }
_cancel_completion();
completion_hint = "";
@@ -3549,16 +3516,17 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEUP: {
-
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
int wi;
int n_line = cursor.line - num_lines_from_rows(cursor.line, get_cursor_wrap_index(), -get_visible_rows(), wi) + 1;
cursor_set_line(n_line, true, false, wi);
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_completion();
completion_hint = "";
@@ -3572,23 +3540,23 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEDOWN: {
-
- if (k->get_shift())
+ if (k->get_shift()) {
_pre_shift_selection();
+ }
int wi;
int n_line = cursor.line + num_lines_from_rows(cursor.line, get_cursor_wrap_index(), get_visible_rows(), wi) - 1;
cursor_set_line(n_line, true, false, wi);
- if (k->get_shift())
+ if (k->get_shift()) {
_post_shift_selection();
+ }
_cancel_completion();
completion_hint = "";
} break;
case KEY_A: {
-
#ifndef APPLE_STYLE_KEYS
if (!k->get_control() || k->get_shift() || k->get_alt()) {
keycode_handled = false;
@@ -3628,7 +3596,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} break;
case KEY_E: {
-
if (!k->get_control() || k->get_command() || k->get_alt()) {
keycode_handled = false;
break;
@@ -3664,7 +3631,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_C: {
-
if (!k->get_command() || k->get_shift() || k->get_alt()) {
keycode_handled = false;
break;
@@ -3676,7 +3642,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_Z: {
-
if (readonly) {
break;
}
@@ -3687,14 +3652,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (is_shortcut_keys_enabled()) {
- if (k->get_shift())
+ if (k->get_shift()) {
redo();
- else
+ } else {
undo();
+ }
}
} break;
case KEY_Y: {
-
if (readonly) {
break;
}
@@ -3748,13 +3713,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
default: {
-
keycode_handled = false;
} break;
}
- if (keycode_handled)
+ if (keycode_handled) {
accept_event();
+ }
if (k->get_keycode() == KEY_INSERT) {
set_insert_mode(!insert_mode);
@@ -3765,9 +3730,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (!keycode_handled && !k->get_command()) { // For German keyboards.
if (k->get_unicode() >= 32) {
-
- if (readonly)
+ if (readonly) {
return;
+ }
// Remove the old character if in insert mode and no selection.
if (insert_mode && !had_selection) {
@@ -3806,7 +3771,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
void TextEdit::_scroll_up(real_t p_delta) {
-
if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta)) {
scrolling = false;
minimap_clicked = false;
@@ -3834,7 +3798,6 @@ void TextEdit::_scroll_up(real_t p_delta) {
}
void TextEdit::_scroll_down(real_t p_delta) {
-
if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(p_delta)) {
scrolling = false;
minimap_clicked = false;
@@ -3863,9 +3826,7 @@ void TextEdit::_scroll_down(real_t p_delta) {
}
void TextEdit::_pre_shift_selection() {
-
if (!selection.active || selection.selecting_mode == Selection::MODE_NONE) {
-
selection.selecting_line = cursor.line;
selection.selecting_column = cursor.column;
selection.active = true;
@@ -3875,9 +3836,7 @@ void TextEdit::_pre_shift_selection() {
}
void TextEdit::_post_shift_selection() {
-
if (selection.active && selection.selecting_mode == Selection::MODE_SHIFT) {
-
select(selection.selecting_line, selection.selecting_column, cursor.line, cursor.column);
update();
}
@@ -3928,7 +3887,6 @@ void TextEdit::_scroll_lines_down() {
/**** TEXT EDIT CORE API ****/
void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column) {
-
// Save for undo.
ERR_FAIL_INDEX(p_line, text.size());
ERR_FAIL_COND(p_char < 0);
@@ -3946,16 +3904,17 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
int lines = substrings.size() - 1;
for (; i < text.size(); i++) {
if (text.is_breakpoint(i)) {
- if ((i - lines < p_line || !text.is_breakpoint(i - lines)) || (i - lines == p_line && !shift_first_line))
+ if ((i - lines < p_line || !text.is_breakpoint(i - lines)) || (i - lines == p_line && !shift_first_line)) {
emit_signal("breakpoint_toggled", i);
- if (i + lines >= text.size() || !text.is_breakpoint(i + lines))
+ }
+ if (i + lines >= text.size() || !text.is_breakpoint(i + lines)) {
emit_signal("breakpoint_toggled", i + lines);
+ }
}
}
/* STEP 3: Add spaces if the char is greater than the end of the line. */
while (p_char > text[p_line].length()) {
-
text.set(p_line, text[p_line] + String::chr(' '));
}
@@ -3968,15 +3927,12 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
// Insert the substrings.
if (j == 0) {
-
text.set(p_line, preinsert_text + substrings[j]);
} else {
-
text.insert(p_line + j, substrings[j]);
}
if (j == substrings.size() - 1) {
-
text.set(p_line + j, text[p_line + j] + postinsert_text);
}
}
@@ -3990,7 +3946,7 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
text.set_breakpoint(p_line, false);
text.set_hidden(p_line, false);
- text.set_info_icon(p_line, NULL, "");
+ text.set_info_icon(p_line, nullptr, "");
}
text.set_line_wrap_amount(p_line, -1);
@@ -3999,15 +3955,15 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
r_end_column = text[r_end_line].length() - postinsert_text.length();
if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
text_changed_dirty = true;
}
_line_edited_from(p_line);
}
String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const {
-
ERR_FAIL_INDEX_V(p_from_line, text.size(), String());
ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, String());
ERR_FAIL_INDEX_V(p_to_line, text.size(), String());
@@ -4018,12 +3974,12 @@ String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_lin
String ret;
for (int i = p_from_line; i <= p_to_line; i++) {
-
int begin = (i == p_from_line) ? p_from_column : 0;
int end = (i == p_to_line) ? p_to_column : text[i].length();
- if (i > p_from_line)
+ if (i > p_from_line) {
ret += "\n";
+ }
ret += text[i].substr(begin, end - begin);
}
@@ -4031,7 +3987,6 @@ String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_lin
}
void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
-
ERR_FAIL_INDEX(p_from_line, text.size());
ERR_FAIL_INDEX(p_from_column, text[p_from_line].length() + 1);
ERR_FAIL_INDEX(p_to_line, text.size());
@@ -4046,10 +4001,12 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
for (int i = p_from_line + 1; i < text.size(); i++) {
if (text.is_breakpoint(i)) {
- if (i + lines >= text.size() || !text.is_breakpoint(i + lines))
+ if (i + lines >= text.size() || !text.is_breakpoint(i + lines)) {
emit_signal("breakpoint_toggled", i);
- if (i > p_to_line && (i - lines < 0 || !text.is_breakpoint(i - lines)))
+ }
+ if (i > p_to_line && (i - lines < 0 || !text.is_breakpoint(i - lines))) {
emit_signal("breakpoint_toggled", i - lines);
+ }
}
}
@@ -4061,17 +4018,18 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
text.set_line_wrap_amount(p_from_line, -1);
if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
text_changed_dirty = true;
}
_line_edited_from(p_from_line);
}
void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_char) {
-
- if (!setting_text && idle_detect->is_inside_tree())
+ if (!setting_text && idle_detect->is_inside_tree()) {
idle_detect->start();
+ }
if (undo_enabled) {
_clear_redo();
@@ -4079,13 +4037,16 @@ void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r
int retline, retchar;
_base_insert_text(p_line, p_char, p_text, retline, retchar);
- if (r_end_line)
+ if (r_end_line) {
*r_end_line = retline;
- if (r_end_char)
+ }
+ if (r_end_char) {
*r_end_char = retchar;
+ }
- if (!undo_enabled)
+ if (!undo_enabled) {
return;
+ }
/* UNDO!! */
TextOperation op;
@@ -4123,9 +4084,9 @@ void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r
}
void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
-
- if (!setting_text && idle_detect->is_inside_tree())
+ if (!setting_text && idle_detect->is_inside_tree()) {
idle_detect->start();
+ }
String text;
if (undo_enabled) {
@@ -4135,8 +4096,9 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, i
_base_remove_text(p_from_line, p_from_column, p_to_line, p_to_column);
- if (!undo_enabled)
+ if (!undo_enabled) {
return;
+ }
/* UNDO! */
TextOperation op;
@@ -4172,7 +4134,6 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, i
}
void TextEdit::_insert_text_at_cursor(const String &p_text) {
-
int new_column, new_line;
_insert_text(cursor.line, cursor.column, p_text, &new_line, &new_column);
_update_scrollbars();
@@ -4199,13 +4160,12 @@ void TextEdit::_line_edited_from(int p_line) {
}
int TextEdit::get_char_count() {
-
int totalsize = 0;
for (int i = 0; i < text.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
totalsize++; // Include \n.
+ }
totalsize += text[i].length();
}
@@ -4213,7 +4173,6 @@ int TextEdit::get_char_count() {
}
Size2 TextEdit::get_minimum_size() const {
-
return cache.style_normal->get_minimum_size();
}
@@ -4229,14 +4188,17 @@ int TextEdit::_get_control_height() const {
void TextEdit::_generate_context_menu() {
// Reorganize context menu.
menu->clear();
- if (!readonly)
+ if (!readonly) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_X : 0);
+ }
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_C : 0);
- if (!readonly)
+ if (!readonly) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_V : 0);
+ }
menu->add_separator();
- if (is_selecting_enabled())
+ if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_A : 0);
+ }
if (!readonly) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
@@ -4254,11 +4216,11 @@ int TextEdit::_get_minimap_visible_rows() const {
}
int TextEdit::get_total_visible_rows() const {
-
// Returns the total amount of rows we need in the editor.
// This skips hidden lines and counts each wrapping of a line.
- if (!is_hiding_enabled() && !is_wrap_enabled())
+ if (!is_hiding_enabled() && !is_wrap_enabled()) {
return text.size();
+ }
int total_rows = 0;
for (int i = 0; i < text.size(); i++) {
@@ -4271,22 +4233,21 @@ int TextEdit::get_total_visible_rows() const {
}
void TextEdit::_update_wrap_at() {
-
wrap_at = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width - wrap_right_offset;
update_cursor_wrap_offset();
text.clear_wrap_cache();
for (int i = 0; i < text.size(); i++) {
// Update all values that wrap.
- if (!line_wraps(i))
+ if (!line_wraps(i)) {
continue;
+ }
Vector<String> rows = get_wrap_rows_text(i);
text.set_line_wrap_amount(i, rows.size() - 1);
}
}
void TextEdit::adjust_viewport_to_cursor() {
-
// Make sure cursor is visible on the screen.
scrolling = false;
minimap_clicked = false;
@@ -4308,19 +4269,22 @@ void TextEdit::adjust_viewport_to_cursor() {
}
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width;
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
+ }
visible_width -= 20; // Give it a little more space.
if (!is_wrap_enabled()) {
// Adjust x offset.
int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]);
- if (cursor_x > (cursor.x_ofs + visible_width))
+ if (cursor_x > (cursor.x_ofs + visible_width)) {
cursor.x_ofs = cursor_x - visible_width + 1;
+ }
- if (cursor_x < cursor.x_ofs)
+ if (cursor_x < cursor.x_ofs) {
cursor.x_ofs = cursor_x;
+ }
} else {
cursor.x_ofs = 0;
}
@@ -4330,29 +4294,32 @@ void TextEdit::adjust_viewport_to_cursor() {
}
void TextEdit::center_viewport_to_cursor() {
-
// Move viewport so the cursor is in the center of the screen.
scrolling = false;
minimap_clicked = false;
- if (is_line_hidden(cursor.line))
+ if (is_line_hidden(cursor.line)) {
unfold_line(cursor.line);
+ }
set_line_as_center_visible(cursor.line, get_cursor_wrap_index());
int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - cache.info_gutter_width - cache.minimap_width;
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
visible_width -= v_scroll->get_combined_minimum_size().width;
+ }
visible_width -= 20; // Give it a little more space.
if (is_wrap_enabled()) {
// Center x offset.
int cursor_x = get_column_x_offset_for_line(cursor.column, cursor.line);
- if (cursor_x > (cursor.x_ofs + visible_width))
+ if (cursor_x > (cursor.x_ofs + visible_width)) {
cursor.x_ofs = cursor_x - visible_width + 1;
+ }
- if (cursor_x < cursor.x_ofs)
+ if (cursor_x < cursor.x_ofs) {
cursor.x_ofs = cursor_x;
+ }
} else {
cursor.x_ofs = 0;
}
@@ -4372,18 +4339,18 @@ void TextEdit::update_cursor_wrap_offset() {
}
bool TextEdit::line_wraps(int line) const {
-
ERR_FAIL_INDEX_V(line, text.size(), 0);
- if (!is_wrap_enabled())
+ if (!is_wrap_enabled()) {
return false;
+ }
return text.get_line_width(line) > wrap_at;
}
int TextEdit::times_line_wraps(int line) const {
-
ERR_FAIL_INDEX_V(line, text.size(), 0);
- if (!line_wraps(line))
+ if (!line_wraps(line)) {
return 0;
+ }
int wrap_amount = text.get_line_wrap_amount(line);
if (wrap_amount == -1) {
@@ -4397,7 +4364,6 @@ int TextEdit::times_line_wraps(int line) const {
}
Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), Vector<String>());
Vector<String> lines;
@@ -4470,16 +4436,15 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
}
int TextEdit::get_cursor_wrap_index() const {
-
return get_line_wrap_index_at_col(cursor.line, cursor.column);
}
int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
- if (!line_wraps(p_line))
+ if (!line_wraps(p_line)) {
return 0;
+ }
// Loop through wraps in the line text until we get to the column.
int wrap_index = 0;
@@ -4489,43 +4454,50 @@ int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
wrap_index = i;
String s = rows[wrap_index];
col += s.length();
- if (col > p_column)
+ if (col > p_column) {
break;
+ }
}
return wrap_index;
}
void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
- if (p_col < 0)
+ if (p_col < 0) {
p_col = 0;
+ }
cursor.column = p_col;
- if (cursor.column > get_line(cursor.line).length())
+ if (cursor.column > get_line(cursor.line).length()) {
cursor.column = get_line(cursor.line).length();
+ }
cursor.last_fit_x = get_column_x_offset_for_line(cursor.column, cursor.line);
- if (p_adjust_viewport)
+ if (p_adjust_viewport) {
adjust_viewport_to_cursor();
+ }
if (!cursor_changed_dirty) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ }
cursor_changed_dirty = true;
}
}
void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
-
- if (setting_row)
+ if (setting_row) {
return;
+ }
setting_row = true;
- if (p_row < 0)
+ if (p_row < 0) {
p_row = 0;
+ }
- if (p_row >= text.size())
+ if (p_row >= text.size()) {
p_row = text.size() - 1;
+ }
if (!p_can_be_hidden) {
if (is_line_hidden(CLAMP(p_row, 0, text.size() - 1))) {
@@ -4551,30 +4523,31 @@ void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_
for (int i = 0; i < p_wrap_index + 1; i++) {
row_end_col += rows[i].length();
}
- if (n_col >= row_end_col)
+ if (n_col >= row_end_col) {
n_col -= 1;
+ }
}
cursor.column = n_col;
- if (p_adjust_viewport)
+ if (p_adjust_viewport) {
adjust_viewport_to_cursor();
+ }
setting_row = false;
if (!cursor_changed_dirty) {
- if (is_inside_tree())
+ if (is_inside_tree()) {
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ }
cursor_changed_dirty = true;
}
}
int TextEdit::cursor_get_column() const {
-
return cursor.column;
}
int TextEdit::cursor_get_line() const {
-
return cursor.line;
}
@@ -4628,14 +4601,14 @@ void TextEdit::_v_scroll_input() {
}
void TextEdit::_scroll_moved(double p_to_val) {
-
- if (updating_scrolls)
+ if (updating_scrolls) {
return;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
cursor.x_ofs = h_scroll->get_value();
+ }
if (v_scroll->is_visible_in_tree()) {
-
// Set line ofs and wrap ofs.
int v_scroll_i = floor(get_v_scroll());
int sc = 0;
@@ -4644,8 +4617,9 @@ void TextEdit::_scroll_moved(double p_to_val) {
if (!is_line_hidden(n_line)) {
sc++;
sc += times_line_wraps(n_line);
- if (sc > v_scroll_i)
+ if (sc > v_scroll_i) {
break;
+ }
}
}
n_line = MIN(n_line, text.size() - 1);
@@ -4660,27 +4634,26 @@ void TextEdit::_scroll_moved(double p_to_val) {
}
int TextEdit::get_row_height() const {
-
return cache.font->get_height() + cache.line_spacing;
}
int TextEdit::get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
if (line_wraps(p_line)) {
-
int line_wrap_amount = times_line_wraps(p_line);
int wrap_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width;
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
- if (p_wrap_index > line_wrap_amount)
+ if (p_wrap_index > line_wrap_amount) {
p_wrap_index = line_wrap_amount;
- if (p_wrap_index > 0)
+ }
+ if (p_wrap_index > 0) {
p_px -= wrap_offset_px;
- else
+ } else {
p_wrap_index = 0;
+ }
Vector<String> rows = get_wrap_rows_text(p_line);
int c_pos = get_char_pos_for(p_px, rows[p_wrap_index]);
for (int i = 0; i < p_wrap_index; i++) {
@@ -4690,17 +4663,14 @@ int TextEdit::get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) cons
return c_pos;
} else {
-
return get_char_pos_for(p_px, text[p_line]);
}
}
int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
if (line_wraps(p_line)) {
-
int n_char = p_char;
int col = 0;
Vector<String> rows = get_wrap_rows_text(p_line);
@@ -4709,8 +4679,9 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
wrap_index = i;
String s = rows[wrap_index];
col += s.length();
- if (col > p_char)
+ if (col > p_char) {
break;
+ }
n_char -= s.length();
}
int px = get_column_x_offset(n_char, rows[wrap_index]);
@@ -4719,27 +4690,26 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
- if (wrap_index != 0)
+ if (wrap_index != 0) {
px += wrap_offset_px;
+ }
return px;
} else {
-
return get_column_x_offset(p_char, text[p_line]);
}
}
int TextEdit::get_char_pos_for(int p_px, String p_str) const {
-
int px = 0;
int c = 0;
while (c < p_str.length()) {
-
int w = text.get_char_width(p_str[c], p_str[c + 1], px);
- if (p_px < (px + w / 2))
+ if (p_px < (px + w / 2)) {
break;
+ }
px += w;
c++;
}
@@ -4748,13 +4718,12 @@ int TextEdit::get_char_pos_for(int p_px, String p_str) const {
}
int TextEdit::get_column_x_offset(int p_char, String p_str) const {
-
int px = 0;
for (int i = 0; i < p_char; i++) {
-
- if (i >= p_str.length())
+ if (i >= p_str.length()) {
break;
+ }
px += text.get_char_width(p_str[i], p_str[i + 1], px);
}
@@ -4763,9 +4732,7 @@ int TextEdit::get_column_x_offset(int p_char, String p_str) const {
}
void TextEdit::insert_text_at_cursor(const String &p_text) {
-
if (selection.active) {
-
cursor_set_line(selection.from_line);
cursor_set_column(selection.from_column);
@@ -4779,15 +4746,15 @@ void TextEdit::insert_text_at_cursor(const String &p_text) {
}
Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
- if (highlighted_word != String())
+ if (highlighted_word != String()) {
return CURSOR_POINTING_HAND;
+ }
int gutter = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width + cache.info_gutter_width;
if ((completion_active && completion_rect.has_point(p_pos))) {
return CURSOR_ARROW;
}
if (p_pos.x < gutter) {
-
int row, col;
_get_mouse_pos(p_pos, row, col);
int left_margin = cache.style_normal->get_margin(MARGIN_LEFT);
@@ -4808,10 +4775,11 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
// Fold icon.
if (draw_fold_gutter && p_pos.x > gutter_left + cache.line_number_w - 6 && p_pos.x <= gutter_left + cache.line_number_w + cache.fold_gutter_width - 3) {
- if (is_folded(row) || can_fold(row))
+ if (is_folded(row) || can_fold(row)) {
return CURSOR_POINTING_HAND;
- else
+ } else {
return CURSOR_ARROW;
+ }
}
return CURSOR_ARROW;
@@ -4837,7 +4805,6 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
}
void TextEdit::set_text(String p_text) {
-
setting_text = true;
if (!undo_enabled) {
_clear();
@@ -4866,72 +4833,67 @@ String TextEdit::get_text() {
String longthing;
int len = text.size();
for (int i = 0; i < len; i++) {
-
longthing += text[i];
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
};
String TextEdit::get_text_for_lookup_completion() {
-
int row, col;
_get_mouse_pos(get_local_mouse_position(), row, col);
String longthing;
int len = text.size();
for (int i = 0; i < len; i++) {
-
if (i == row) {
longthing += text[i].substr(0, col);
longthing += String::chr(0xFFFF); // Not unicode, represents the cursor.
longthing += text[i].substr(col, text[i].size());
} else {
-
longthing += text[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
}
String TextEdit::get_text_for_completion() {
-
String longthing;
int len = text.size();
for (int i = 0; i < len; i++) {
-
if (i == cursor.line) {
longthing += text[i].substr(0, cursor.column);
longthing += String::chr(0xFFFF); // Not unicode, represents the cursor.
longthing += text[i].substr(cursor.column, text[i].size());
} else {
-
longthing += text[i];
}
- if (i != len - 1)
+ if (i != len - 1) {
longthing += "\n";
+ }
}
return longthing;
};
String TextEdit::get_line(int line) const {
-
- if (line < 0 || line >= text.size())
+ if (line < 0 || line >= text.size()) {
return "";
+ }
return text[line];
};
void TextEdit::_clear() {
-
clear_undo_history();
text.clear();
cursor.column = 0;
@@ -4944,16 +4906,15 @@ void TextEdit::_clear() {
}
void TextEdit::clear() {
-
setting_text = true;
_clear();
setting_text = false;
};
void TextEdit::set_readonly(bool p_readonly) {
-
- if (readonly == p_readonly)
+ if (readonly == p_readonly) {
return;
+ }
readonly = p_readonly;
_generate_context_menu();
@@ -4988,27 +4949,22 @@ void TextEdit::set_readonly(bool p_readonly) {
}
bool TextEdit::is_readonly() const {
-
return readonly;
}
void TextEdit::set_wrap_enabled(bool p_wrap_enabled) {
-
wrap_enabled = p_wrap_enabled;
}
bool TextEdit::is_wrap_enabled() const {
-
return wrap_enabled;
}
void TextEdit::set_max_chars(int p_max_chars) {
-
max_chars = p_max_chars;
}
int TextEdit::get_max_chars() const {
-
return max_chars;
}
@@ -5031,7 +4987,6 @@ void TextEdit::_toggle_draw_caret() {
}
void TextEdit::_update_caches() {
-
cache.style_normal = get_theme_stylebox("normal");
cache.style_focus = get_theme_stylebox("focus");
cache.style_readonly = get_theme_stylebox("read_only");
@@ -5099,7 +5054,6 @@ void TextEdit::_set_syntax_highlighting(SyntaxHighlighter *p_syntax_highlighter)
}
int TextEdit::_is_line_in_region(int p_line) {
-
// Do we have in cache?
if (color_region_cache.has(p_line)) {
return color_region_cache[p_line];
@@ -5157,7 +5111,6 @@ Map<int, TextEdit::Text::ColorRegionInfo> TextEdit::_get_line_color_region_info(
}
void TextEdit::clear_colors() {
-
keywords.clear();
member_keywords.clear();
color_regions.clear();
@@ -5168,7 +5121,6 @@ void TextEdit::clear_colors() {
}
void TextEdit::add_keyword_color(const String &p_keyword, const Color &p_color) {
-
keywords[p_keyword] = p_color;
syntax_highlighting_cache.clear();
update();
@@ -5179,13 +5131,11 @@ bool TextEdit::has_keyword_color(String p_keyword) const {
}
Color TextEdit::get_keyword_color(String p_keyword) const {
-
ERR_FAIL_COND_V(!keywords.has(p_keyword), Color());
return keywords[p_keyword];
}
void TextEdit::add_color_region(const String &p_begin_key, const String &p_end_key, const Color &p_color, bool p_line_only) {
-
color_regions.push_back(ColorRegion(p_begin_key, p_end_key, p_color, p_line_only));
syntax_highlighting_cache.clear();
text.clear_width_cache();
@@ -5213,13 +5163,11 @@ void TextEdit::clear_member_keywords() {
}
void TextEdit::set_syntax_coloring(bool p_enabled) {
-
syntax_coloring = p_enabled;
update();
}
bool TextEdit::is_syntax_coloring_enabled() const {
-
return syntax_coloring;
}
@@ -5228,9 +5176,7 @@ void TextEdit::set_auto_indent(bool p_auto_indent) {
}
void TextEdit::cut() {
-
if (!selection.active) {
-
String clipboard = text[cursor.line];
DisplayServer::get_singleton()->clipboard_set(clipboard);
cursor_set_line(cursor.line);
@@ -5248,7 +5194,6 @@ void TextEdit::cut() {
cut_copy_line = clipboard;
} else {
-
String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
DisplayServer::get_singleton()->clipboard_set(clipboard);
@@ -5264,11 +5209,8 @@ void TextEdit::cut() {
}
void TextEdit::copy() {
-
if (!selection.active) {
-
if (text[cursor.line].length() != 0) {
-
String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length());
DisplayServer::get_singleton()->clipboard_set(clipboard);
cut_copy_line = clipboard;
@@ -5281,12 +5223,10 @@ void TextEdit::copy() {
}
void TextEdit::paste() {
-
String clipboard = DisplayServer::get_singleton()->clipboard_get();
begin_complex_operation();
if (selection.active) {
-
selection.active = false;
selection.selecting_mode = Selection::MODE_NONE;
_remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
@@ -5294,7 +5234,6 @@ void TextEdit::paste() {
cursor_set_column(selection.from_column);
} else if (!cut_copy_line.empty() && cut_copy_line == clipboard) {
-
cursor_set_column(0);
String ins = "\n";
clipboard += ins;
@@ -5307,11 +5246,13 @@ void TextEdit::paste() {
}
void TextEdit::select_all() {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (text.size() == 1 && text[0].length() == 0)
+ if (text.size() == 1 && text[0].length() == 0) {
return;
+ }
selection.active = true;
selection.from_line = 0;
selection.from_column = 0;
@@ -5327,32 +5268,38 @@ void TextEdit::select_all() {
}
void TextEdit::deselect() {
-
selection.active = false;
update();
}
void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (!selecting_enabled)
+ if (!selecting_enabled) {
return;
+ }
- if (p_from_line < 0)
+ if (p_from_line < 0) {
p_from_line = 0;
- else if (p_from_line >= text.size())
+ } else if (p_from_line >= text.size()) {
p_from_line = text.size() - 1;
- if (p_from_column >= text[p_from_line].length())
+ }
+ if (p_from_column >= text[p_from_line].length()) {
p_from_column = text[p_from_line].length();
- if (p_from_column < 0)
+ }
+ if (p_from_column < 0) {
p_from_column = 0;
+ }
- if (p_to_line < 0)
+ if (p_to_line < 0) {
p_to_line = 0;
- else if (p_to_line >= text.size())
+ } else if (p_to_line >= text.size()) {
p_to_line = text.size() - 1;
- if (p_to_column >= text[p_to_line].length())
+ }
+ if (p_to_column >= text[p_to_line].length()) {
p_to_column = text[p_to_line].length();
- if (p_to_column < 0)
+ }
+ if (p_to_column < 0) {
p_to_column = 0;
+ }
selection.from_line = p_from_line;
selection.from_column = p_from_column;
@@ -5362,89 +5309,86 @@ void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_t
selection.active = true;
if (selection.from_line == selection.to_line) {
-
if (selection.from_column == selection.to_column) {
-
selection.active = false;
} else if (selection.from_column > selection.to_column) {
-
selection.shiftclick_left = false;
SWAP(selection.from_column, selection.to_column);
} else {
-
selection.shiftclick_left = true;
}
} else if (selection.from_line > selection.to_line) {
-
selection.shiftclick_left = false;
SWAP(selection.from_line, selection.to_line);
SWAP(selection.from_column, selection.to_column);
} else {
-
selection.shiftclick_left = true;
}
update();
}
+
void TextEdit::swap_lines(int line1, int line2) {
String tmp = get_line(line1);
String tmp2 = get_line(line2);
set_line(line2, tmp);
set_line(line1, tmp2);
}
-bool TextEdit::is_selection_active() const {
+bool TextEdit::is_selection_active() const {
return selection.active;
}
-int TextEdit::get_selection_from_line() const {
+int TextEdit::get_selection_from_line() const {
ERR_FAIL_COND_V(!selection.active, -1);
return selection.from_line;
}
-int TextEdit::get_selection_from_column() const {
+int TextEdit::get_selection_from_column() const {
ERR_FAIL_COND_V(!selection.active, -1);
return selection.from_column;
}
-int TextEdit::get_selection_to_line() const {
+int TextEdit::get_selection_to_line() const {
ERR_FAIL_COND_V(!selection.active, -1);
return selection.to_line;
}
-int TextEdit::get_selection_to_column() const {
+int TextEdit::get_selection_to_column() const {
ERR_FAIL_COND_V(!selection.active, -1);
return selection.to_column;
}
String TextEdit::get_selection_text() const {
-
- if (!selection.active)
+ if (!selection.active) {
return "";
+ }
return _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
}
String TextEdit::get_word_under_cursor() const {
-
int prev_cc = cursor.column;
while (prev_cc > 0) {
bool is_char = _is_text_char(text[cursor.line][prev_cc - 1]);
- if (!is_char)
+ if (!is_char) {
break;
+ }
--prev_cc;
}
int next_cc = cursor.column;
while (next_cc < text[cursor.line].length()) {
bool is_char = _is_text_char(text[cursor.line][next_cc]);
- if (!is_char)
+ if (!is_char) {
break;
+ }
++next_cc;
}
- if (prev_cc == cursor.column || next_cc == cursor.column)
+ if (prev_cc == cursor.column || next_cc == cursor.column) {
return "";
+ }
return text[cursor.line].substr(prev_cc, next_cc - prev_cc);
}
@@ -5503,26 +5447,23 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
return col;
}
-Vector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {
-
+Dictionary TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {
int col, line;
if (search(p_key, p_search_flags, p_from_line, p_from_column, line, col)) {
- Vector<int> result;
- result.resize(2);
- result.set(SEARCH_RESULT_COLUMN, col);
- result.set(SEARCH_RESULT_LINE, line);
+ Dictionary result;
+ result["line"] = line;
+ result["column"] = col;
return result;
} else {
-
- return Vector<int>();
+ return Dictionary();
}
}
bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const {
-
- if (p_key.length() == 0)
+ if (p_key.length() == 0) {
return false;
+ }
ERR_FAIL_INDEX_V(p_from_line, text.size(), false);
ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, false);
@@ -5532,7 +5473,6 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
int pos = -1;
for (int i = 0; i < text.size() + 1; i++) {
-
if (line < 0) {
line = text.size() - 1;
}
@@ -5543,7 +5483,6 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
String text_line = text[line];
int from_column = 0;
if (line == p_from_line) {
-
if (i == text.size()) {
// Wrapped.
@@ -5554,15 +5493,15 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
}
} else {
-
from_column = p_from_column;
}
} else {
- if (p_search_flags & SEARCH_BACKWARDS)
+ if (p_search_flags & SEARCH_BACKWARDS) {
from_column = text_line.length() - 1;
- else
+ } else {
from_column = 0;
+ }
}
pos = -1;
@@ -5571,7 +5510,6 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
int last_pos = -1;
while (true) {
-
if (p_search_flags & SEARCH_BACKWARDS) {
while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.rfind(p_key, pos_from) : text_line.rfindn(p_key, pos_from)) != -1) {
if (last_pos <= from_column) {
@@ -5597,10 +5535,11 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
// Validate for whole words.
- if (pos > 0 && _is_text_char(text_line[pos - 1]))
+ if (pos > 0 && _is_text_char(text_line[pos - 1])) {
is_match = false;
- else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()]))
+ } else if (pos + p_key.length() < text_line.length() && _is_text_char(text_line[pos + p_key.length()])) {
is_match = false;
+ }
}
if (pos_from == -1) {
@@ -5615,13 +5554,15 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
pos = -1;
}
- if (pos != -1)
+ if (pos != -1) {
break;
+ }
- if (p_search_flags & SEARCH_BACKWARDS)
+ if (p_search_flags & SEARCH_BACKWARDS) {
line--;
- else
+ } else {
line++;
+ }
}
if (pos == -1) {
@@ -5637,19 +5578,16 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
}
void TextEdit::_cursor_changed_emit() {
-
emit_signal("cursor_changed");
cursor_changed_dirty = false;
}
void TextEdit::_text_changed_emit() {
-
emit_signal("text_changed");
text_changed_dirty = false;
}
void TextEdit::set_line_as_marked(int p_line, bool p_marked) {
-
ERR_FAIL_INDEX(p_line, text.size());
text.set_marked(p_line, p_marked);
update();
@@ -5678,72 +5616,69 @@ void TextEdit::clear_executing_line() {
}
bool TextEdit::is_line_set_as_bookmark(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), false);
return text.is_bookmark(p_line);
}
void TextEdit::set_line_as_bookmark(int p_line, bool p_bookmark) {
-
ERR_FAIL_INDEX(p_line, text.size());
text.set_bookmark(p_line, p_bookmark);
update();
}
void TextEdit::get_bookmarks(List<int> *p_bookmarks) const {
-
for (int i = 0; i < text.size(); i++) {
- if (text.is_bookmark(i))
+ if (text.is_bookmark(i)) {
p_bookmarks->push_back(i);
+ }
}
}
Array TextEdit::get_bookmarks_array() const {
-
Array arr;
for (int i = 0; i < text.size(); i++) {
- if (text.is_bookmark(i))
+ if (text.is_bookmark(i)) {
arr.append(i);
+ }
}
return arr;
}
bool TextEdit::is_line_set_as_breakpoint(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), false);
return text.is_breakpoint(p_line);
}
void TextEdit::set_line_as_breakpoint(int p_line, bool p_breakpoint) {
-
ERR_FAIL_INDEX(p_line, text.size());
text.set_breakpoint(p_line, p_breakpoint);
update();
}
void TextEdit::get_breakpoints(List<int> *p_breakpoints) const {
-
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
p_breakpoints->push_back(i);
+ }
}
}
Array TextEdit::get_breakpoints_array() const {
-
Array arr;
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
arr.append(i);
+ }
}
return arr;
}
void TextEdit::remove_breakpoints() {
for (int i = 0; i < text.size(); i++) {
- if (text.is_breakpoint(i))
+ if (text.is_breakpoint(i)) {
/* Should "breakpoint_toggled" be fired when breakpoints are removed this way? */
text.set_breakpoint(i, false);
+ }
}
}
@@ -5759,21 +5694,19 @@ void TextEdit::clear_info_icons() {
}
void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
-
ERR_FAIL_INDEX(p_line, text.size());
- if (is_hiding_enabled() || !p_hidden)
+ if (is_hiding_enabled() || !p_hidden) {
text.set_hidden(p_line, p_hidden);
+ }
update();
}
bool TextEdit::is_line_hidden(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), false);
return text.is_hidden(p_line);
}
void TextEdit::fold_all_lines() {
-
for (int i = 0; i < text.size(); i++) {
fold_line(i);
}
@@ -5782,7 +5715,6 @@ void TextEdit::fold_all_lines() {
}
void TextEdit::unhide_all_lines() {
-
for (int i = 0; i < text.size(); i++) {
text.set_hidden(i, false);
}
@@ -5791,12 +5723,12 @@ void TextEdit::unhide_all_lines() {
}
int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
-
// Returns the number of lines (hidden and unhidden) from p_line_from to (p_line_from + visible_amount of unhidden lines).
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return ABS(visible_amount);
+ }
int num_visible = 0;
int num_total = 0;
@@ -5806,8 +5738,9 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
if (!is_line_hidden(i)) {
num_visible++;
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
} else {
visible_amount = ABS(visible_amount);
@@ -5816,22 +5749,23 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
if (!is_line_hidden(i)) {
num_visible++;
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
}
return num_total;
}
int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int visible_amount, int &wrap_index) const {
-
// Returns the number of lines (hidden and unhidden) from (p_line_from + p_wrap_index_from) row to (p_line_from + visible_amount of unhidden and wrapped rows).
// Wrap index is set to the wrap index of the last line.
wrap_index = 0;
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled() && !is_wrap_enabled())
+ if (!is_hiding_enabled() && !is_wrap_enabled()) {
return ABS(visible_amount);
+ }
int num_visible = 0;
int num_total = 0;
@@ -5847,8 +5781,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible++;
num_visible += times_line_wraps(i);
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
wrap_index = times_line_wraps(MIN(i, text.size() - 1)) - (num_visible - visible_amount);
} else {
@@ -5861,8 +5796,9 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible++;
num_visible += times_line_wraps(i);
}
- if (num_visible >= visible_amount)
+ if (num_visible >= visible_amount) {
break;
+ }
}
wrap_index = (num_visible - visible_amount);
}
@@ -5871,10 +5807,10 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
}
int TextEdit::get_last_unhidden_line() const {
-
// Returns the last line in the text that is not hidden.
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return text.size() - 1;
+ }
int last_line;
for (last_line = text.size() - 1; last_line > 0; last_line--) {
@@ -5886,7 +5822,6 @@ int TextEdit::get_last_unhidden_line() const {
}
int TextEdit::get_indent_level(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), 0);
// Counts number of tabs and spaces before line starts.
@@ -5906,7 +5841,6 @@ int TextEdit::get_indent_level(int p_line) const {
}
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);
@@ -5927,26 +5861,32 @@ bool TextEdit::is_line_comment(int p_line) const {
}
bool TextEdit::can_fold(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), false);
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return false;
- if (p_line + 1 >= text.size())
+ }
+ if (p_line + 1 >= text.size()) {
return false;
- if (text[p_line].strip_edges().size() == 0)
+ }
+ if (text[p_line].strip_edges().size() == 0) {
return false;
- if (is_folded(p_line))
+ }
+ if (is_folded(p_line)) {
return false;
- if (is_line_hidden(p_line))
+ }
+ if (is_line_hidden(p_line)) {
return false;
- if (is_line_comment(p_line))
+ }
+ if (is_line_comment(p_line)) {
return false;
+ }
int start_indent = get_indent_level(p_line);
for (int i = p_line + 1; i < text.size(); i++) {
- if (text[i].strip_edges().size() == 0)
+ if (text[i].strip_edges().size() == 0) {
continue;
+ }
int next_indent = get_indent_level(i);
if (is_line_comment(i)) {
continue;
@@ -5961,10 +5901,10 @@ bool TextEdit::can_fold(int p_line) const {
}
bool TextEdit::is_folded(int p_line) const {
-
ERR_FAIL_INDEX_V(p_line, text.size(), false);
- if (p_line + 1 >= text.size())
+ if (p_line + 1 >= text.size()) {
return false;
+ }
return !is_line_hidden(p_line) && is_line_hidden(p_line + 1);
}
@@ -5980,12 +5920,13 @@ Vector<int> TextEdit::get_folded_lines() const {
}
void TextEdit::fold_line(int p_line) {
-
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_hiding_enabled())
+ if (!is_hiding_enabled()) {
return;
- if (!can_fold(p_line))
+ }
+ if (!can_fold(p_line)) {
return;
+ }
// Hide lines below this one.
int start_indent = get_indent_level(p_line);
@@ -6026,15 +5967,16 @@ void TextEdit::fold_line(int p_line) {
}
void TextEdit::unfold_line(int p_line) {
-
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_folded(p_line) && !is_line_hidden(p_line))
+ if (!is_folded(p_line) && !is_line_hidden(p_line)) {
return;
+ }
int fold_start;
for (fold_start = p_line; fold_start > 0; fold_start--) {
- if (is_folded(fold_start))
+ if (is_folded(fold_start)) {
break;
+ }
}
fold_start = is_folded(fold_start) ? fold_start : p_line;
@@ -6050,45 +5992,42 @@ void TextEdit::unfold_line(int p_line) {
}
void TextEdit::toggle_fold_line(int p_line) {
-
ERR_FAIL_INDEX(p_line, text.size());
- if (!is_folded(p_line))
+ if (!is_folded(p_line)) {
fold_line(p_line);
- else
+ } else {
unfold_line(p_line);
+ }
}
int TextEdit::get_line_count() const {
-
return text.size();
}
void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
-
ERR_FAIL_COND(p_op.type == TextOperation::TYPE_NONE);
bool insert = p_op.type == TextOperation::TYPE_INSERT;
- if (p_reverse)
+ if (p_reverse) {
insert = !insert;
+ }
if (insert) {
-
int check_line;
int check_column;
_base_insert_text(p_op.from_line, p_op.from_column, p_op.text, check_line, check_column);
ERR_FAIL_COND(check_line != p_op.to_line); // BUG.
ERR_FAIL_COND(check_column != p_op.to_column); // BUG.
} else {
-
_base_remove_text(p_op.from_line, p_op.from_column, p_op.to_line, p_op.to_column);
}
}
void TextEdit::_clear_redo() {
-
- if (undo_stack_pos == NULL)
+ if (undo_stack_pos == nullptr) {
return; // Nothing to clear.
+ }
_push_current_op();
@@ -6100,27 +6039,28 @@ void TextEdit::_clear_redo() {
}
void TextEdit::undo() {
-
_push_current_op();
- if (undo_stack_pos == NULL) {
-
- if (!undo_stack.size())
+ if (undo_stack_pos == nullptr) {
+ if (!undo_stack.size()) {
return; // Nothing to undo.
+ }
undo_stack_pos = undo_stack.back();
- } else if (undo_stack_pos == undo_stack.front())
+ } else if (undo_stack_pos == undo_stack.front()) {
return; // At the bottom of the undo stack.
- else
+ } else {
undo_stack_pos = undo_stack_pos->prev();
+ }
deselect();
TextOperation op = undo_stack_pos->get();
_do_text_op(op, true);
- if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1))
+ if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1)) {
select(op.from_line, op.from_column, op.to_line, op.to_column);
+ }
current_op.version = op.prev_version;
if (undo_stack_pos->get().chain_backward) {
@@ -6149,11 +6089,11 @@ void TextEdit::undo() {
}
void TextEdit::redo() {
-
_push_current_op();
- if (undo_stack_pos == NULL)
+ if (undo_stack_pos == nullptr) {
return; // Nothing to do.
+ }
deselect();
@@ -6161,15 +6101,15 @@ void TextEdit::redo() {
_do_text_op(op, false);
current_op.version = op.version;
if (undo_stack_pos->get().chain_forward) {
-
while (true) {
ERR_BREAK(!undo_stack_pos->next());
undo_stack_pos = undo_stack_pos->next();
op = undo_stack_pos->get();
_do_text_op(op, false);
current_op.version = op.version;
- if (undo_stack_pos->get().chain_backward)
+ if (undo_stack_pos->get().chain_backward) {
break;
+ }
}
}
@@ -6181,10 +6121,9 @@ void TextEdit::redo() {
}
void TextEdit::clear_undo_history() {
-
saved_version = 0;
current_op.type = TextOperation::TYPE_NONE;
- undo_stack_pos = NULL;
+ undo_stack_pos = nullptr;
undo_stack.clear();
}
@@ -6194,7 +6133,6 @@ void TextEdit::begin_complex_operation() {
}
void TextEdit::end_complex_operation() {
-
_push_current_op();
ERR_FAIL_COND(undo_stack.size() == 0);
@@ -6207,9 +6145,9 @@ void TextEdit::end_complex_operation() {
}
void TextEdit::_push_current_op() {
-
- if (current_op.type == TextOperation::TYPE_NONE)
+ if (current_op.type == TextOperation::TYPE_NONE) {
return; // Nothing to do.
+ }
if (next_operation_is_complex) {
current_op.chain_forward = true;
@@ -6220,6 +6158,10 @@ void TextEdit::_push_current_op() {
current_op.type = TextOperation::TYPE_NONE;
current_op.text = "";
current_op.chain_forward = false;
+
+ if (undo_stack.size() > undo_stack_max_size) {
+ undo_stack.pop_front();
+ }
}
void TextEdit::set_indent_using_spaces(const bool p_use_spaces) {
@@ -6244,28 +6186,23 @@ void TextEdit::set_indent_size(const int p_size) {
}
int TextEdit::get_indent_size() {
-
return indent_size;
}
void TextEdit::set_draw_tabs(bool p_draw) {
-
draw_tabs = p_draw;
update();
}
bool TextEdit::is_drawing_tabs() const {
-
return draw_tabs;
}
void TextEdit::set_draw_spaces(bool p_draw) {
-
draw_spaces = p_draw;
}
bool TextEdit::is_drawing_spaces() const {
-
return draw_spaces;
}
@@ -6295,19 +6232,17 @@ uint32_t TextEdit::get_version() const {
}
uint32_t TextEdit::get_saved_version() const {
-
return saved_version;
}
void TextEdit::tag_saved_version() {
-
saved_version = get_version();
}
double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
-
- if (!is_wrap_enabled() && !is_hiding_enabled())
+ if (!is_wrap_enabled() && !is_hiding_enabled()) {
return p_line;
+ }
// Count the number of visible lines up to this line.
double new_line_scroll_pos = 0;
@@ -6323,12 +6258,10 @@ double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
}
void TextEdit::set_line_as_first_visible(int p_line, int p_wrap_index) {
-
set_v_scroll(get_scroll_pos_for_line(p_line, p_wrap_index));
}
void TextEdit::set_line_as_center_visible(int p_line, int p_wrap_index) {
-
int visible_rows = get_visible_rows();
int wi;
int first_line = p_line - num_lines_from_rows(p_line, p_wrap_index, -visible_rows / 2, wi) + 1;
@@ -6337,7 +6270,6 @@ void TextEdit::set_line_as_center_visible(int p_line, int p_wrap_index) {
}
void TextEdit::set_line_as_last_visible(int p_line, int p_wrap_index) {
-
int wi;
int first_line = p_line - num_lines_from_rows(p_line, p_wrap_index, -get_visible_rows() - 1, wi) + 1;
@@ -6345,12 +6277,10 @@ void TextEdit::set_line_as_last_visible(int p_line, int p_wrap_index) {
}
int TextEdit::get_first_visible_line() const {
-
return CLAMP(cursor.line_ofs, 0, text.size() - 1);
}
int TextEdit::get_last_visible_line() const {
-
int first_vis_line = get_first_visible_line();
int last_vis_line = 0;
int wi;
@@ -6360,7 +6290,6 @@ int TextEdit::get_last_visible_line() const {
}
int TextEdit::get_last_visible_line_wrap_index() const {
-
int first_vis_line = get_first_visible_line();
int wi;
num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows() + 1, wi);
@@ -6368,7 +6297,6 @@ int TextEdit::get_last_visible_line_wrap_index() const {
}
double TextEdit::get_visible_rows_offset() const {
-
double total = _get_control_height();
total /= (double)get_row_height();
total = total - floor(total);
@@ -6377,31 +6305,27 @@ double TextEdit::get_visible_rows_offset() const {
}
double TextEdit::get_v_scroll_offset() const {
-
double val = get_v_scroll() - floor(get_v_scroll());
return CLAMP(val, 0, 1);
}
double TextEdit::get_v_scroll() const {
-
return v_scroll->get_value();
}
void TextEdit::set_v_scroll(double p_scroll) {
-
v_scroll->set_value(p_scroll);
int max_v_scroll = v_scroll->get_max() - v_scroll->get_page();
- if (p_scroll >= max_v_scroll - 1.0)
+ if (p_scroll >= max_v_scroll - 1.0) {
_scroll_moved(v_scroll->get_value());
+ }
}
int TextEdit::get_h_scroll() const {
-
return h_scroll->get_value();
}
void TextEdit::set_h_scroll(int p_scroll) {
-
if (p_scroll < 0) {
p_scroll = 0;
}
@@ -6409,36 +6333,31 @@ void TextEdit::set_h_scroll(int p_scroll) {
}
void TextEdit::set_smooth_scroll_enabled(bool p_enable) {
-
v_scroll->set_smooth_scroll_enabled(p_enable);
smooth_scroll_enabled = p_enable;
}
bool TextEdit::is_smooth_scroll_enabled() const {
-
return smooth_scroll_enabled;
}
void TextEdit::set_v_scroll_speed(float p_speed) {
-
v_scroll_speed = p_speed;
}
float TextEdit::get_v_scroll_speed() const {
-
return v_scroll_speed;
}
void TextEdit::set_completion(bool p_enabled, const Vector<String> &p_prefixes) {
-
completion_prefixes.clear();
completion_enabled = p_enabled;
- for (int i = 0; i < p_prefixes.size(); i++)
+ for (int i = 0; i < p_prefixes.size(); i++) {
completion_prefixes.insert(p_prefixes[i]);
+ }
}
void TextEdit::_confirm_completion() {
-
begin_complex_operation();
_remove_text(cursor.line, cursor.column - completion_base.length(), cursor.line, cursor.column);
@@ -6456,7 +6375,6 @@ void TextEdit::_confirm_completion() {
}
if (last_completion_char == '(') {
-
if (next_char == last_completion_char) {
_base_remove_text(cursor.line, cursor.column - 1, cursor.line, cursor.column);
} else if (auto_brace_completion_enabled) {
@@ -6464,7 +6382,6 @@ void TextEdit::_confirm_completion() {
cursor.column--;
}
} else if (last_completion_char == ')' && next_char == '(') {
-
_base_remove_text(cursor.line, cursor.column - 2, cursor.line, cursor.column);
if (line[cursor.column + 1] != ')') {
cursor.column--;
@@ -6481,15 +6398,14 @@ void TextEdit::_confirm_completion() {
}
void TextEdit::_cancel_code_hint() {
-
completion_hint = "";
update();
}
void TextEdit::_cancel_completion() {
-
- if (!completion_active)
+ if (!completion_active) {
return;
+ }
completion_active = false;
completion_forced = false;
@@ -6497,12 +6413,10 @@ void TextEdit::_cancel_completion() {
}
static bool _is_completable(CharType c) {
-
return !_is_symbol(c) || c == '"' || c == '\'';
}
void TextEdit::_update_completion_candidates() {
-
String l = text[cursor.line];
int cofs = CLAMP(cursor.column, 0, l.length());
@@ -6518,8 +6432,9 @@ void TextEdit::_update_completion_candidates() {
while (c >= 0) {
if (l[c] == '"' || l[c] == '\'') {
inquote = !inquote;
- if (first_quote == -1)
+ if (first_quote == -1) {
first_quote = c;
+ }
restore_quotes = 0;
} else if (restore_quotes == 0 && l[c] == '$') {
restore_quotes = 1;
@@ -6536,13 +6451,13 @@ void TextEdit::_update_completion_candidates() {
// No completion here.
cancel = true;
} else if (inquote && first_quote != -1) {
-
s = l.substr(first_quote, cofs - first_quote);
} else if (cofs > 0 && l[cofs - 1] == ' ') {
int kofs = cofs - 1;
String kw;
- while (kofs >= 0 && l[kofs] == ' ')
+ while (kofs >= 0 && l[kofs] == ' ') {
kofs--;
+ }
while (kofs >= 0 && l[kofs] > 32 && _is_completable(l[kofs])) {
kw = String::chr(l[kofs]) + kw;
@@ -6552,11 +6467,11 @@ void TextEdit::_update_completion_candidates() {
pre_keyword = keywords.has(kw);
} else {
-
while (cofs > 0 && l[cofs - 1] > 32 && (l[cofs - 1] == '/' || _is_completable(l[cofs - 1]))) {
s = String::chr(l[cofs - 1]) + s;
- if (l[cofs - 1] == '\'' || l[cofs - 1] == '"' || l[cofs - 1] == '$')
+ if (l[cofs - 1] == '\'' || l[cofs - 1] == '"' || l[cofs - 1] == '$') {
break;
+ }
cofs--;
}
@@ -6569,11 +6484,13 @@ void TextEdit::_update_completion_candidates() {
update();
bool prev_is_prefix = false;
- if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1])))
+ if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1]))) {
prev_is_prefix = true;
+ }
// Check with one space before prefix, to allow indent.
- if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2])))
+ if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2]))) {
prev_is_prefix = true;
+ }
if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !prev_is_prefix))) {
// None to complete, cancel.
@@ -6610,7 +6527,6 @@ void TextEdit::_update_completion_candidates() {
} else if (s.length() == 0) {
completion_options.push_back(option);
} else {
-
// This code works the same as:
/*
if (option.display.begins_with(s)) {
@@ -6633,8 +6549,8 @@ void TextEdit::_update_completion_candidates() {
const CharType *tgt = &option.display[0];
const CharType *tgt_lower = &display_lower[0];
- const CharType *ssq_last_tgt = NULL;
- const CharType *ssq_lower_last_tgt = NULL;
+ const CharType *ssq_last_tgt = nullptr;
+ const CharType *ssq_lower_last_tgt = nullptr;
for (; *tgt; tgt++, tgt_lower++) {
if (*ssq == *tgt) {
@@ -6685,7 +6601,6 @@ void TextEdit::_update_completion_candidates() {
}
void TextEdit::query_code_comple() {
-
String l = text[cursor.line];
int ofs = CLAMP(cursor.column, 0, l.length());
@@ -6693,15 +6608,16 @@ void TextEdit::query_code_comple() {
int c = ofs - 1;
while (c >= 0) {
- if (l[c] == '"' || l[c] == '\'')
+ if (l[c] == '"' || l[c] == '\'') {
inquote = !inquote;
+ }
c--;
}
bool ignored = completion_active && !completion_options.empty();
if (ignored) {
ScriptCodeCompletionOption::Kind kind = ScriptCodeCompletionOption::KIND_PLAIN_TEXT;
- const ScriptCodeCompletionOption *previous_option = NULL;
+ const ScriptCodeCompletionOption *previous_option = nullptr;
for (int i = 0; i < completion_options.size(); i++) {
const ScriptCodeCompletionOption &current_option = completion_options[i];
if (!previous_option) {
@@ -6717,22 +6633,21 @@ void TextEdit::query_code_comple() {
}
if (!ignored) {
- if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1]))))
+ if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1])))) {
emit_signal("request_completion");
- else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) // Make it work with a space too, it's good enough.
+ } else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) { // Make it work with a space too, it's good enough.
emit_signal("request_completion");
+ }
}
}
void TextEdit::set_code_hint(const String &p_hint) {
-
completion_hint = p_hint;
completion_hint_offset = -0xFFFF;
update();
}
void TextEdit::code_complete(const List<ScriptCodeCompletionOption> &p_strings, bool p_forced) {
-
completion_sources = p_strings;
completion_active = true;
completion_forced = p_forced;
@@ -6742,16 +6657,15 @@ void TextEdit::code_complete(const List<ScriptCodeCompletionOption> &p_strings,
}
String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
-
int row, col;
_get_mouse_pos(p_pos, row, col);
String s = text[row];
- if (s.length() == 0)
+ if (s.length() == 0) {
return "";
+ }
int beg, end;
if (select_word(s, col, beg, end)) {
-
bool inside_quotes = false;
CharType selected_quote = '\0';
int qbegin = 0, qend = 0;
@@ -6781,18 +6695,18 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
}
String TextEdit::get_tooltip(const Point2 &p_pos) const {
-
- if (!tooltip_obj)
+ if (!tooltip_obj) {
return Control::get_tooltip(p_pos);
+ }
int row, col;
_get_mouse_pos(p_pos, row, col);
String s = text[row];
- if (s.length() == 0)
+ if (s.length() == 0) {
return Control::get_tooltip(p_pos);
+ }
int beg, end;
if (select_word(s, col, beg, end)) {
-
String tt = tooltip_obj->call(tooltip_func, s.substr(beg, end - beg), tooltip_ud);
return tt;
@@ -6802,15 +6716,15 @@ String TextEdit::get_tooltip(const Point2 &p_pos) const {
}
void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata) {
-
tooltip_obj = p_obj;
tooltip_func = p_function;
tooltip_ud = p_udata;
}
void TextEdit::set_line(int line, String new_text) {
- if (line < 0 || line > text.size())
+ if (line < 0 || line > text.size()) {
return;
+ }
_remove_text(line, 0, line, text[line].length());
_insert_text(line, 0, new_text);
if (cursor.line == line) {
@@ -6840,13 +6754,11 @@ void TextEdit::insert_at(const String &p_text, int at) {
}
void TextEdit::set_show_line_numbers(bool p_show) {
-
line_numbers = p_show;
update();
}
void TextEdit::set_line_numbers_zero_padded(bool p_zero_padded) {
-
line_numbers_zero_padded = p_zero_padded;
update();
}
@@ -6952,8 +6864,9 @@ int TextEdit::get_minimap_width() const {
}
void TextEdit::set_hiding_enabled(bool p_enabled) {
- if (!p_enabled)
+ if (!p_enabled) {
unhide_all_lines();
+ }
hiding_enabled = p_enabled;
update();
}
@@ -6972,12 +6885,10 @@ bool TextEdit::is_highlight_current_line_enabled() const {
}
bool TextEdit::is_text_field() const {
-
return true;
}
void TextEdit::menu_option(int p_option) {
-
switch (p_option) {
case MENU_CUT: {
if (!readonly) {
@@ -7015,12 +6926,10 @@ void TextEdit::set_highlighted_word(const String &new_word) {
}
void TextEdit::set_select_identifiers_on_hover(bool p_enable) {
-
select_identifiers_enabled = p_enable;
}
bool TextEdit::is_selecting_identifiers_on_hover_enabled() const {
-
return select_identifiers_enabled;
}
@@ -7041,8 +6950,9 @@ void TextEdit::set_shortcut_keys_enabled(bool p_enabled) {
void TextEdit::set_selecting_enabled(bool p_enabled) {
selecting_enabled = p_enabled;
- if (!selecting_enabled)
+ if (!selecting_enabled) {
deselect();
+ }
_generate_context_menu();
}
@@ -7060,7 +6970,6 @@ PopupMenu *TextEdit::get_menu() const {
}
void TextEdit::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &TextEdit::_gui_input);
ClassDB::bind_method(D_METHOD("_cursor_changed_emit"), &TextEdit::_cursor_changed_emit);
ClassDB::bind_method(D_METHOD("_text_changed_emit"), &TextEdit::_text_changed_emit);
@@ -7070,9 +6979,6 @@ void TextEdit::_bind_methods() {
BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS);
BIND_ENUM_CONSTANT(SEARCH_BACKWARDS);
- BIND_ENUM_CONSTANT(SEARCH_RESULT_COLUMN);
- BIND_ENUM_CONSTANT(SEARCH_RESULT_LINE);
-
/*
ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char);
ClassDB::bind_method(D_METHOD("delete_line"),&TextEdit::delete_line);
@@ -7084,6 +6990,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_line_count"), &TextEdit::get_line_count);
ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text);
ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line);
+ ClassDB::bind_method(D_METHOD("set_line", "line", "new_text"), &TextEdit::set_line);
ClassDB::bind_method(D_METHOD("center_viewport_to_cursor"), &TextEdit::center_viewport_to_cursor);
ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(true));
@@ -7244,10 +7151,11 @@ void TextEdit::_bind_methods() {
GLOBAL_DEF("gui/timers/text_edit_idle_detect_sec", 3);
ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/text_edit_idle_detect_sec", PropertyInfo(Variant::FLOAT, "gui/timers/text_edit_idle_detect_sec", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); // No negative numbers.
+ GLOBAL_DEF("gui/common/text_edit_undo_stack_max_size", 1024);
+ ProjectSettings::get_singleton()->set_custom_property_info("gui/common/text_edit_undo_stack_max_size", PropertyInfo(Variant::INT, "gui/common/text_edit_undo_stack_max_size", PROPERTY_HINT_RANGE, "0,10000,1,or_greater")); // No negative numbers.
}
TextEdit::TextEdit() {
-
setting_row = false;
draw_tabs = false;
draw_spaces = false;
@@ -7259,7 +7167,7 @@ TextEdit::TextEdit() {
wrap_at = 0;
wrap_right_offset = 10;
set_focus_mode(FOCUS_ALL);
- syntax_highlighter = NULL;
+ syntax_highlighter = nullptr;
_update_caches();
cache.row_height = 1;
cache.line_spacing = 1;
@@ -7323,7 +7231,8 @@ TextEdit::TextEdit() {
current_op.type = TextOperation::TYPE_NONE;
undo_enabled = true;
- undo_stack_pos = NULL;
+ undo_stack_max_size = GLOBAL_GET("gui/common/text_edit_undo_stack_max_size");
+ undo_stack_pos = nullptr;
setting_text = false;
last_dblclk = 0;
current_op.version = 0;
@@ -7333,7 +7242,7 @@ TextEdit::TextEdit() {
completion_enabled = false;
completion_active = false;
completion_line_ofs = 0;
- tooltip_obj = NULL;
+ tooltip_obj = nullptr;
line_numbers = false;
line_numbers_zero_padded = false;
line_length_guidelines = false;
@@ -7394,7 +7303,7 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
return syntax_highlighting_cache[p_line];
}
- if (syntax_highlighter != NULL) {
+ if (syntax_highlighter != nullptr) {
Map<int, HighlighterInfo> color_map = syntax_highlighter->_get_line_syntax_highlighting(p_line);
syntax_highlighting_cache[p_line] = color_map;
return color_map;
@@ -7492,10 +7401,10 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
}
if (in_region == -1 && !in_keyword && is_char && !prev_is_char) {
-
int to = j;
- while (to < str.length() && _is_text_char(str[to]))
+ while (to < str.length() && _is_text_char(str[to])) {
to++;
+ }
uint32_t hash = String::hash(&str[j], to - j);
StrRange range(&str[j], to - j);
@@ -7508,7 +7417,7 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
if (col) {
for (int k = j - 1; k >= 0; k--) {
if (str[k] == '.') {
- col = NULL; // Member indexing not allowed.
+ col = nullptr; // Member indexing not allowed.
break;
} else if (str[k] > 32) {
break;
@@ -7524,7 +7433,6 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
}
if (!in_function_name && in_word && !in_keyword) {
-
int k = j;
while (k < str.length() && !_is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
k++;
@@ -7556,18 +7464,19 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int
in_member_variable = false;
}
- if (in_region >= 0)
+ if (in_region >= 0) {
color = color_regions[in_region].color;
- else if (in_keyword)
+ } else if (in_keyword) {
color = keyword_color;
- else if (in_member_variable)
+ } else if (in_member_variable) {
color = cache.member_variable_color;
- else if (in_function_name)
+ } else if (in_function_name) {
color = cache.function_color;
- else if (is_symbol)
+ } else if (is_symbol) {
color = cache.symbol_color;
- else if (is_number)
+ } else if (is_number) {
color = cache.number_color;
+ }
prev_is_char = is_char;
prev_is_number = is_number;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 7d096f7897..ab78f77d94 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -39,7 +39,6 @@
class SyntaxHighlighter;
class TextEdit : public Control {
-
GDCLASS(TextEdit, Control);
public:
@@ -48,7 +47,6 @@ public:
};
struct ColorRegion {
-
Color color;
String begin_key;
String end_key;
@@ -66,7 +64,6 @@ public:
class Text {
public:
struct ColorRegionInfo {
-
int region;
bool end;
ColorRegionInfo() {
@@ -168,7 +165,6 @@ private:
} cursor;
struct Selection {
-
enum Mode {
MODE_NONE,
@@ -207,7 +203,6 @@ private:
} selection;
struct Cache {
-
Ref<Texture2D> tab_icon;
Ref<Texture2D> space_icon;
Ref<Texture2D> can_fold_icon;
@@ -256,7 +251,6 @@ private:
int info_gutter_width;
int minimap_width;
Cache() {
-
row_height = 0;
line_spacing = 0;
line_number_w = 0;
@@ -271,7 +265,6 @@ private:
Map<int, Map<int, HighlighterInfo>> syntax_highlighting_cache;
struct TextOperation {
-
enum Type {
TYPE_NONE,
TYPE_INSERT,
@@ -306,6 +299,7 @@ private:
List<TextOperation> undo_stack;
List<TextOperation>::Element *undo_stack_pos;
+ int undo_stack_max_size;
void _clear_redo();
void _do_text_op(const TextOperation &p_op, bool p_reverse);
@@ -514,7 +508,7 @@ private:
int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column);
- Vector<int> _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
+ Dictionary _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
PopupMenu *menu;
@@ -530,7 +524,7 @@ private:
protected:
virtual String get_tooltip(const Point2 &p_pos) const;
- void _insert_text(int p_line, int p_char, const String &p_text, int *r_end_line = NULL, int *r_end_char = NULL);
+ void _insert_text(int p_line, int p_char, const String &p_text, int *r_end_line = nullptr, int *r_end_char = nullptr);
void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
void _insert_text_at_cursor(const String &p_text);
void _gui_input(const Ref<InputEvent> &p_gui_input);
@@ -567,11 +561,6 @@ public:
SEARCH_BACKWARDS = 4
};
- enum SearchResult {
- SEARCH_RESULT_COLUMN,
- SEARCH_RESULT_LINE,
- };
-
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const;
@@ -832,7 +821,6 @@ public:
VARIANT_ENUM_CAST(TextEdit::MenuItems);
VARIANT_ENUM_CAST(TextEdit::SearchFlags);
-VARIANT_ENUM_CAST(TextEdit::SearchResult);
class SyntaxHighlighter {
protected:
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 5f2e4cf58e..6e86f0f299 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -33,33 +33,34 @@
#include <stdlib.h>
Size2 TextureButton::get_minimum_size() const {
-
Size2 rscale = Control::get_minimum_size();
if (!expand) {
if (normal.is_null()) {
if (pressed.is_null()) {
- if (hover.is_null())
- if (click_mask.is_null())
+ if (hover.is_null()) {
+ if (click_mask.is_null()) {
rscale = Size2();
- else
+ } else {
rscale = click_mask->get_size();
- else
+ }
+ } else {
rscale = hover->get_size();
- } else
+ }
+ } else {
rscale = pressed->get_size();
+ }
- } else
+ } else {
rscale = normal->get_size();
+ }
}
return rscale.abs();
}
bool TextureButton::has_point(const Point2 &p_point) const {
-
if (click_mask.is_valid()) {
-
Point2 point = p_point;
Rect2 rect = Rect2();
Size2 mask_size = click_mask->get_size();
@@ -116,9 +117,7 @@ bool TextureButton::has_point(const Point2 &p_point) const {
}
void TextureButton::_notification(int p_what) {
-
switch (p_what) {
-
case NOTIFICATION_DRAW: {
DrawMode draw_mode = get_draw_mode();
@@ -126,40 +125,44 @@ void TextureButton::_notification(int p_what) {
switch (draw_mode) {
case DRAW_NORMAL: {
-
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
+ }
} break;
case DRAW_HOVER_PRESSED:
case DRAW_PRESSED: {
-
if (pressed.is_null()) {
if (hover.is_null()) {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = hover;
+ }
- } else
+ } else {
texdraw = pressed;
+ }
} break;
case DRAW_HOVER: {
-
if (hover.is_null()) {
- if (pressed.is_valid() && is_pressed())
+ if (pressed.is_valid() && is_pressed()) {
texdraw = pressed;
- else if (normal.is_valid())
+ } else if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = hover;
+ }
} break;
case DRAW_DISABLED: {
-
if (disabled.is_null()) {
- if (normal.is_valid())
+ if (normal.is_valid()) {
texdraw = normal;
- } else
+ }
+ } else {
texdraw = disabled;
+ }
} break;
}
@@ -232,7 +235,6 @@ void TextureButton::_notification(int p_what) {
}
void TextureButton::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_normal_texture", "texture"), &TextureButton::set_normal_texture);
ClassDB::bind_method(D_METHOD("set_pressed_texture", "texture"), &TextureButton::set_pressed_texture);
ClassDB::bind_method(D_METHOD("set_hover_texture", "texture"), &TextureButton::set_hover_texture);
@@ -271,61 +273,56 @@ void TextureButton::_bind_methods() {
}
void TextureButton::set_normal_texture(const Ref<Texture2D> &p_normal) {
-
normal = p_normal;
update();
minimum_size_changed();
}
void TextureButton::set_pressed_texture(const Ref<Texture2D> &p_pressed) {
-
pressed = p_pressed;
update();
}
-void TextureButton::set_hover_texture(const Ref<Texture2D> &p_hover) {
+void TextureButton::set_hover_texture(const Ref<Texture2D> &p_hover) {
hover = p_hover;
update();
}
-void TextureButton::set_disabled_texture(const Ref<Texture2D> &p_disabled) {
+void TextureButton::set_disabled_texture(const Ref<Texture2D> &p_disabled) {
disabled = p_disabled;
update();
}
-void TextureButton::set_click_mask(const Ref<BitMap> &p_click_mask) {
+void TextureButton::set_click_mask(const Ref<BitMap> &p_click_mask) {
click_mask = p_click_mask;
update();
}
Ref<Texture2D> TextureButton::get_normal_texture() const {
-
return normal;
}
-Ref<Texture2D> TextureButton::get_pressed_texture() const {
+Ref<Texture2D> TextureButton::get_pressed_texture() const {
return pressed;
}
-Ref<Texture2D> TextureButton::get_hover_texture() const {
+Ref<Texture2D> TextureButton::get_hover_texture() const {
return hover;
}
-Ref<Texture2D> TextureButton::get_disabled_texture() const {
+Ref<Texture2D> TextureButton::get_disabled_texture() const {
return disabled;
}
-Ref<BitMap> TextureButton::get_click_mask() const {
+Ref<BitMap> TextureButton::get_click_mask() const {
return click_mask;
}
Ref<Texture2D> TextureButton::get_focused_texture() const {
-
return focused;
};
void TextureButton::set_focused_texture(const Ref<Texture2D> &p_focused) {
-
focused = p_focused;
};
diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h
index 43b10a8e8b..a1e66203d3 100644
--- a/scene/gui/texture_button.h
+++ b/scene/gui/texture_button.h
@@ -34,7 +34,6 @@
#include "scene/gui/base_button.h"
#include "scene/resources/bit_map.h"
class TextureButton : public BaseButton {
-
GDCLASS(TextureButton, BaseButton);
public:
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp
index abf6b2ed49..484b14d11c 100644
--- a/scene/gui/texture_progress.cpp
+++ b/scene/gui/texture_progress.cpp
@@ -33,19 +33,16 @@
#include "core/engine.h"
void TextureProgress::set_under_texture(const Ref<Texture2D> &p_texture) {
-
under = p_texture;
update();
minimum_size_changed();
}
Ref<Texture2D> TextureProgress::get_under_texture() const {
-
return under;
}
void TextureProgress::set_over_texture(const Ref<Texture2D> &p_texture) {
-
over = p_texture;
update();
if (under.is_null()) {
@@ -54,7 +51,6 @@ void TextureProgress::set_over_texture(const Ref<Texture2D> &p_texture) {
}
Ref<Texture2D> TextureProgress::get_over_texture() const {
-
return over;
}
@@ -81,28 +77,26 @@ bool TextureProgress::get_nine_patch_stretch() const {
}
Size2 TextureProgress::get_minimum_size() const {
-
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
return Size2(stretch_margin[MARGIN_LEFT] + stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_TOP] + stretch_margin[MARGIN_BOTTOM]);
- else if (under.is_valid())
+ } else if (under.is_valid()) {
return under->get_size();
- else if (over.is_valid())
+ } else if (over.is_valid()) {
return over->get_size();
- else if (progress.is_valid())
+ } else if (progress.is_valid()) {
return progress->get_size();
+ }
return Size2(1, 1);
}
void TextureProgress::set_progress_texture(const Ref<Texture2D> &p_texture) {
-
progress = p_texture;
update();
minimum_size_changed();
}
Ref<Texture2D> TextureProgress::get_progress_texture() const {
-
return progress;
}
@@ -134,13 +128,16 @@ Color TextureProgress::get_tint_over() const {
}
Point2 TextureProgress::unit_val_to_uv(float val) {
- if (progress.is_null())
+ if (progress.is_null()) {
return Point2();
+ }
- if (val < 0)
+ if (val < 0) {
val += 1;
- if (val > 1)
+ }
+ if (val > 1) {
val -= 1;
+ }
Point2 p = get_relative_center();
@@ -158,40 +155,46 @@ Point2 TextureProgress::unit_val_to_uv(float val) {
for (int edge = 0; edge < 4; edge++) {
if (edge == 0) {
- if (dir.x > 0)
+ if (dir.x > 0) {
continue;
+ }
cq = -(edgeLeft - p.x);
dir.x *= 2.0 * cq;
cp = -dir.x;
} else if (edge == 1) {
- if (dir.x < 0)
+ if (dir.x < 0) {
continue;
+ }
cq = (edgeRight - p.x);
dir.x *= 2.0 * cq;
cp = dir.x;
} else if (edge == 2) {
- if (dir.y > 0)
+ if (dir.y > 0) {
continue;
+ }
cq = -(edgeBottom - p.y);
dir.y *= 2.0 * cq;
cp = -dir.y;
} else if (edge == 3) {
- if (dir.y < 0)
+ if (dir.y < 0) {
continue;
+ }
cq = (edgeTop - p.y);
dir.y *= 2.0 * cq;
cp = dir.y;
}
cr = cq / cp;
- if (cr >= 0 && cr < t1)
+ if (cr >= 0 && cr < t1) {
t1 = cr;
+ }
}
return (p + t1 * dir);
}
Point2 TextureProgress::get_relative_center() {
- if (progress.is_null())
+ if (progress.is_null()) {
return Point2();
+ }
Point2 p = progress->get_size() / 2;
p += rad_center_off;
p.x /= progress->get_width();
@@ -300,15 +303,13 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture2D> &p_texture,
p_texture->get_rect_region(dst_rect, src_rect, dst_rect, src_rect);
RID ci = get_canvas_item();
- VS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright, VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, true, p_modulate);
+ RS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright, RS::NINE_PATCH_STRETCH, RS::NINE_PATCH_STRETCH, true, p_modulate);
}
void TextureProgress::_notification(int p_what) {
const float corners[12] = { -0.125, -0.375, -0.625, -0.875, 0.125, 0.375, 0.625, 0.875, 1.125, 1.375, 1.625, 1.875 };
switch (p_what) {
-
case NOTIFICATION_DRAW: {
-
if (nine_patch_stretch && (mode == FILL_LEFT_TO_RIGHT || mode == FILL_RIGHT_TO_LEFT || mode == FILL_TOP_TO_BOTTOM || mode == FILL_BOTTOM_TO_TOP)) {
if (under.is_valid()) {
draw_nine_patch_stretched(under, FILL_LEFT_TO_RIGHT, 1.0, tint_under);
@@ -320,8 +321,9 @@ void TextureProgress::_notification(int p_what) {
draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0, tint_over);
}
} else {
- if (under.is_valid())
+ if (under.is_valid()) {
draw_texture(under, Point2(), tint_under);
+ }
if (progress.is_valid()) {
Size2 s = progress->get_size();
switch (mode) {
@@ -344,8 +346,9 @@ void TextureProgress::_notification(int p_what) {
case FILL_CLOCKWISE:
case FILL_COUNTER_CLOCKWISE:
case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: {
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
s = get_size();
+ }
float val = get_as_ratio() * rad_max_degrees / 360;
if (val == 1) {
@@ -367,9 +370,11 @@ void TextureProgress::_notification(int p_what) {
pts.append(end);
float from = MIN(start, end);
float to = MAX(start, end);
- for (int i = 0; i < 12; i++)
- if (corners[i] > from && corners[i] < to)
+ for (int i = 0; i < 12; i++) {
+ if (corners[i] > from && corners[i] < to) {
pts.append(corners[i]);
+ }
+ }
pts.sort();
Vector<Point2> uvs;
Vector<Point2> points;
@@ -377,8 +382,9 @@ void TextureProgress::_notification(int p_what) {
points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y));
for (int i = 0; i < pts.size(); i++) {
Point2 uv = unit_val_to_uv(pts[i]);
- if (uvs.find(uv) >= 0)
+ if (uvs.find(uv) >= 0) {
continue;
+ }
uvs.push_back(uv);
points.push_back(Point2(uv.x * s.x, uv.y * s.y));
}
@@ -389,10 +395,11 @@ void TextureProgress::_notification(int p_what) {
if (Engine::get_singleton()->is_editor_hint()) {
Point2 p;
- if (nine_patch_stretch)
+ if (nine_patch_stretch) {
p = get_size();
- else
+ } else {
p = progress->get_size();
+ }
p.x *= get_relative_center().x;
p.y *= get_relative_center().y;
@@ -413,10 +420,10 @@ void TextureProgress::_notification(int p_what) {
draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress);
}
}
- if (over.is_valid())
+ if (over.is_valid()) {
draw_texture(over, Point2(), tint_over);
+ }
}
-
} break;
}
}
@@ -432,10 +439,12 @@ int TextureProgress::get_fill_mode() {
}
void TextureProgress::set_radial_initial_angle(float p_angle) {
- while (p_angle > 360)
+ while (p_angle > 360) {
p_angle -= 360;
- while (p_angle < 0)
+ }
+ while (p_angle < 0) {
p_angle += 360;
+ }
rad_init_angle = p_angle;
update();
}
@@ -463,7 +472,6 @@ Point2 TextureProgress::get_radial_center_offset() {
}
void TextureProgress::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_under_texture", "tex"), &TextureProgress::set_under_texture);
ClassDB::bind_method(D_METHOD("get_under_texture"), &TextureProgress::get_under_texture);
diff --git a/scene/gui/texture_progress.h b/scene/gui/texture_progress.h
index e05f89aa3e..e56454f866 100644
--- a/scene/gui/texture_progress.h
+++ b/scene/gui/texture_progress.h
@@ -34,7 +34,6 @@
#include "scene/gui/range.h"
class TextureProgress : public Range {
-
GDCLASS(TextureProgress, Range);
Ref<Texture2D> under;
diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp
index 6dafd3bf4f..58e7249284 100644
--- a/scene/gui/texture_rect.cpp
+++ b/scene/gui/texture_rect.cpp
@@ -30,12 +30,10 @@
#include "texture_rect.h"
#include "core/core_string_names.h"
-#include "servers/visual_server.h"
+#include "servers/rendering_server.h"
void TextureRect::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
if (texture.is_null()) {
return;
}
@@ -95,6 +93,15 @@ void TextureRect::_notification(int p_what) {
} break;
}
+ Ref<AtlasTexture> p_atlas = texture;
+
+ if (p_atlas.is_valid() && region.has_no_area()) {
+ Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height());
+
+ offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0;
+ offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0;
+ }
+
size.width *= hflip ? -1.0f : 1.0f;
size.height *= vflip ? -1.0f : 1.0f;
@@ -107,7 +114,6 @@ void TextureRect::_notification(int p_what) {
}
Size2 TextureRect::get_minimum_size() const {
-
if (!expand && !texture.is_null()) {
return texture->get_size();
} else {
@@ -116,7 +122,6 @@ Size2 TextureRect::get_minimum_size() const {
}
void TextureRect::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TextureRect::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &TextureRect::get_texture);
ClassDB::bind_method(D_METHOD("set_expand", "enable"), &TextureRect::set_expand);
@@ -145,7 +150,6 @@ void TextureRect::_bind_methods() {
}
void TextureRect::_texture_changed() {
-
if (texture.is_valid()) {
update();
minimum_size_changed();
@@ -153,7 +157,6 @@ void TextureRect::_texture_changed() {
}
void TextureRect::set_texture(const Ref<Texture2D> &p_tex) {
-
if (p_tex == texture) {
return;
}
@@ -173,57 +176,47 @@ void TextureRect::set_texture(const Ref<Texture2D> &p_tex) {
}
Ref<Texture2D> TextureRect::get_texture() const {
-
return texture;
}
void TextureRect::set_expand(bool p_expand) {
-
expand = p_expand;
update();
minimum_size_changed();
}
bool TextureRect::has_expand() const {
-
return expand;
}
void TextureRect::set_stretch_mode(StretchMode p_mode) {
-
stretch_mode = p_mode;
update();
}
TextureRect::StretchMode TextureRect::get_stretch_mode() const {
-
return stretch_mode;
}
void TextureRect::set_flip_h(bool p_flip) {
-
hflip = p_flip;
update();
}
bool TextureRect::is_flipped_h() const {
-
return hflip;
}
void TextureRect::set_flip_v(bool p_flip) {
-
vflip = p_flip;
update();
}
bool TextureRect::is_flipped_v() const {
-
return vflip;
}
TextureRect::TextureRect() {
-
expand = false;
hflip = false;
vflip = false;
diff --git a/scene/gui/texture_rect.h b/scene/gui/texture_rect.h
index 77a2828fd4..727ab95776 100644
--- a/scene/gui/texture_rect.h
+++ b/scene/gui/texture_rect.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class TextureRect : public Control {
-
GDCLASS(TextureRect, Control);
public:
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 653ac74164..7b9db7c081 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -30,7 +30,7 @@
#include "tree.h"
-#include "core/input/input_filter.h"
+#include "core/input/input.h"
#include "core/math/math_funcs.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
@@ -47,9 +47,9 @@
#include <limits.h>
void TreeItem::move_to_top() {
-
- if (!parent || parent->children == this)
+ if (!parent || parent->children == this) {
return; //already on top
+ }
TreeItem *prev = get_prev();
prev->next = next;
next = parent->children;
@@ -57,13 +57,15 @@ void TreeItem::move_to_top() {
}
void TreeItem::move_to_bottom() {
- if (!parent || !next)
+ if (!parent || !next) {
return;
+ }
TreeItem *prev = get_prev();
TreeItem *last = next;
- while (last->next)
+ while (last->next) {
last = last->next;
+ }
if (prev) {
prev->next = next;
@@ -71,58 +73,52 @@ void TreeItem::move_to_bottom() {
parent->children = next;
}
last->next = this;
- next = NULL;
+ next = nullptr;
}
Size2 TreeItem::Cell::get_icon_size() const {
-
- if (icon.is_null())
+ if (icon.is_null()) {
return Size2();
- if (icon_region == Rect2i())
+ }
+ if (icon_region == Rect2i()) {
return icon->get_size();
- else
+ } else {
return icon_region.size;
+ }
}
void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size, const Color &p_color) const {
-
- if (icon.is_null())
+ if (icon.is_null()) {
return;
+ }
Size2i dsize = (p_size == Size2()) ? icon->get_size() : p_size;
if (icon_region == Rect2i()) {
-
icon->draw_rect_region(p_where, Rect2(p_pos, dsize), Rect2(Point2(), icon->get_size()), p_color);
} else {
-
icon->draw_rect_region(p_where, Rect2(p_pos, dsize), icon_region, p_color);
}
}
void TreeItem::_changed_notify(int p_cell) {
-
tree->item_changed(p_cell, this);
}
void TreeItem::_changed_notify() {
-
tree->item_changed(-1, this);
}
void TreeItem::_cell_selected(int p_cell) {
-
tree->item_selected(p_cell, this);
}
void TreeItem::_cell_deselected(int p_cell) {
-
tree->item_deselected(p_cell, this);
}
/* cell mode */
void TreeItem::set_cell_mode(int p_column, TreeCellMode p_mode) {
-
ERR_FAIL_INDEX(p_column, cells.size());
Cell &c = cells.write[p_column];
c.mode = p_mode;
@@ -138,32 +134,27 @@ void TreeItem::set_cell_mode(int p_column, TreeCellMode p_mode) {
}
TreeItem::TreeCellMode TreeItem::get_cell_mode(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), TreeItem::CELL_MODE_STRING);
return cells[p_column].mode;
}
/* check mode */
void TreeItem::set_checked(int p_column, bool p_checked) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].checked = p_checked;
_changed_notify(p_column);
}
bool TreeItem::is_checked(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].checked;
}
void TreeItem::set_text(int p_column, String p_text) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].text = p_text;
if (cells[p_column].mode == TreeItem::CELL_MODE_RANGE) {
-
Vector<String> strings = p_text.split(",");
cells.write[p_column].min = INT_MAX;
cells.write[p_column].max = INT_MIN;
@@ -181,13 +172,11 @@ void TreeItem::set_text(int p_column, String p_text) {
}
String TreeItem::get_text(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), "");
return cells[p_column].text;
}
void TreeItem::set_suffix(int p_column, String p_suffix) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].suffix = p_suffix;
@@ -195,91 +184,82 @@ void TreeItem::set_suffix(int p_column, String p_suffix) {
}
String TreeItem::get_suffix(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), "");
return cells[p_column].suffix;
}
void TreeItem::set_icon(int p_column, const Ref<Texture2D> &p_icon) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].icon = p_icon;
_changed_notify(p_column);
}
Ref<Texture2D> TreeItem::get_icon(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Texture2D>());
return cells[p_column].icon;
}
void TreeItem::set_icon_region(int p_column, const Rect2 &p_icon_region) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].icon_region = p_icon_region;
_changed_notify(p_column);
}
Rect2 TreeItem::get_icon_region(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), Rect2());
return cells[p_column].icon_region;
}
void TreeItem::set_icon_modulate(int p_column, const Color &p_modulate) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].icon_color = p_modulate;
_changed_notify(p_column);
}
Color TreeItem::get_icon_modulate(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
return cells[p_column].icon_color;
}
void TreeItem::set_icon_max_width(int p_column, int p_max) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].icon_max_w = p_max;
_changed_notify(p_column);
}
int TreeItem::get_icon_max_width(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), 0);
return cells[p_column].icon_max_w;
}
/* range works for mode number or mode combo */
void TreeItem::set_range(int p_column, double p_value) {
-
ERR_FAIL_INDEX(p_column, cells.size());
- if (cells[p_column].step > 0)
+ if (cells[p_column].step > 0) {
p_value = Math::stepify(p_value, cells[p_column].step);
- if (p_value < cells[p_column].min)
+ }
+ if (p_value < cells[p_column].min) {
p_value = cells[p_column].min;
- if (p_value > cells[p_column].max)
+ }
+ if (p_value > cells[p_column].max) {
p_value = cells[p_column].max;
+ }
cells.write[p_column].val = p_value;
_changed_notify(p_column);
}
double TreeItem::get_range(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), 0);
return cells[p_column].val;
}
bool TreeItem::is_range_exponential(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].expr;
}
-void TreeItem::set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp) {
+void TreeItem::set_range_config(int p_column, double p_min, double p_max, double p_step, bool p_exp) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].min = p_min;
cells.write[p_column].max = p_max;
@@ -289,7 +269,6 @@ void TreeItem::set_range_config(int p_column, double p_min, double p_max, double
}
void TreeItem::get_range_config(int p_column, double &r_min, double &r_max, double &r_step) const {
-
ERR_FAIL_INDEX(p_column, cells.size());
r_min = cells[p_column].min;
r_max = cells[p_column].max;
@@ -297,20 +276,17 @@ void TreeItem::get_range_config(int p_column, double &r_min, double &r_max, doub
}
void TreeItem::set_metadata(int p_column, const Variant &p_meta) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].meta = p_meta;
}
Variant TreeItem::get_metadata(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), Variant());
return cells[p_column].meta;
}
void TreeItem::set_custom_draw(int p_column, Object *p_object, const StringName &p_callback) {
-
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_NULL(p_object);
@@ -319,25 +295,21 @@ void TreeItem::set_custom_draw(int p_column, Object *p_object, const StringName
}
void TreeItem::set_collapsed(bool p_collapsed) {
-
- if (collapsed == p_collapsed || !tree)
+ if (collapsed == p_collapsed || !tree) {
return;
+ }
collapsed = p_collapsed;
TreeItem *ci = tree->selected_item;
if (ci) {
-
while (ci && ci != this) {
-
ci = ci->parent;
}
if (ci) { // collapsing cursor/selected, move it!
if (tree->select_mode == Tree::SELECT_MULTI) {
-
tree->selected_item = this;
emit_signal("cell_selected");
} else {
-
select(tree->selected_col);
}
@@ -350,7 +322,6 @@ void TreeItem::set_collapsed(bool p_collapsed) {
}
bool TreeItem::is_collapsed() {
-
return collapsed;
}
@@ -364,43 +335,39 @@ int TreeItem::get_custom_minimum_height() const {
}
TreeItem *TreeItem::get_next() {
-
return next;
}
TreeItem *TreeItem::get_prev() {
-
- if (!parent || parent->children == this)
- return NULL;
+ if (!parent || parent->children == this) {
+ return nullptr;
+ }
TreeItem *prev = parent->children;
- while (prev && prev->next != this)
+ while (prev && prev->next != this) {
prev = prev->next;
+ }
return prev;
}
TreeItem *TreeItem::get_parent() {
-
return parent;
}
TreeItem *TreeItem::get_children() {
-
return children;
}
TreeItem *TreeItem::get_prev_visible(bool p_wrap) {
-
TreeItem *current = this;
TreeItem *prev = current->get_prev();
if (!prev) {
-
current = current->parent;
if (current == tree->root && tree->hide_root) {
- return NULL;
+ return nullptr;
} else if (!current) {
if (p_wrap) {
current = this;
@@ -410,18 +377,18 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) {
temp = temp->get_next_visible();
}
} else {
- return NULL;
+ return nullptr;
}
}
} else {
-
current = prev;
while (!current->collapsed && current->children) {
//go to the very end
current = current->children;
- while (current->next)
+ while (current->next) {
current = current->next;
+ }
}
}
@@ -429,28 +396,24 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) {
}
TreeItem *TreeItem::get_next_visible(bool p_wrap) {
-
TreeItem *current = this;
if (!current->collapsed && current->children) {
-
current = current->children;
} else if (current->next) {
-
current = current->next;
} else {
-
while (current && !current->next) {
-
current = current->parent;
}
if (!current) {
- if (p_wrap)
+ if (p_wrap) {
return tree->root;
- else
- return NULL;
+ } else {
+ return nullptr;
+ }
} else {
current = current->next;
}
@@ -460,19 +423,16 @@ TreeItem *TreeItem::get_next_visible(bool p_wrap) {
}
void TreeItem::remove_child(TreeItem *p_item) {
-
ERR_FAIL_NULL(p_item);
TreeItem **c = &children;
while (*c) {
-
if ((*c) == p_item) {
-
TreeItem *aux = *c;
*c = (*c)->next;
- aux->parent = NULL;
+ aux->parent = nullptr;
return;
}
@@ -483,55 +443,51 @@ void TreeItem::remove_child(TreeItem *p_item) {
}
void TreeItem::set_selectable(int p_column, bool p_selectable) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].selectable = p_selectable;
}
bool TreeItem::is_selectable(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].selectable;
}
bool TreeItem::is_selected(int p_column) {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].selectable && cells[p_column].selected;
}
void TreeItem::set_as_cursor(int p_column) {
-
ERR_FAIL_INDEX(p_column, cells.size());
- if (!tree)
+ if (!tree) {
return;
- if (tree->select_mode != Tree::SELECT_MULTI)
+ }
+ if (tree->select_mode != Tree::SELECT_MULTI) {
return;
+ }
tree->selected_item = this;
tree->selected_col = p_column;
tree->update();
}
void TreeItem::select(int p_column) {
-
ERR_FAIL_INDEX(p_column, cells.size());
_cell_selected(p_column);
}
void TreeItem::deselect(int p_column) {
-
ERR_FAIL_INDEX(p_column, cells.size());
_cell_deselected(p_column);
}
void TreeItem::add_button(int p_column, const Ref<Texture2D> &p_button, int p_id, bool p_disabled, const String &p_tooltip) {
-
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_COND(!p_button.is_valid());
TreeItem::Cell::Button button;
button.texture = p_button;
- if (p_id < 0)
+ if (p_id < 0) {
p_id = cells[p_column].buttons.size();
+ }
button.id = p_id;
button.disabled = p_disabled;
button.tooltip = p_tooltip;
@@ -540,27 +496,29 @@ void TreeItem::add_button(int p_column, const Ref<Texture2D> &p_button, int p_id
}
int TreeItem::get_button_count(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
return cells[p_column].buttons.size();
}
+
Ref<Texture2D> TreeItem::get_button(int p_column, int p_idx) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Texture2D>());
ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), Ref<Texture2D>());
return cells[p_column].buttons[p_idx].texture;
}
+
String TreeItem::get_button_tooltip(int p_column, int p_idx) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), String());
ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), String());
return cells[p_column].buttons[p_idx].tooltip;
}
+
int TreeItem::get_button_id(int p_column, int p_idx) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), -1);
return cells[p_column].buttons[p_idx].id;
}
-void TreeItem::erase_button(int p_column, int p_idx) {
+void TreeItem::erase_button(int p_column, int p_idx) {
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_INDEX(p_idx, cells[p_column].buttons.size());
cells.write[p_column].buttons.remove(p_idx);
@@ -568,19 +526,17 @@ void TreeItem::erase_button(int p_column, int p_idx) {
}
int TreeItem::get_button_by_id(int p_column, int p_id) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
for (int i = 0; i < cells[p_column].buttons.size(); i++) {
-
- if (cells[p_column].buttons[i].id == p_id)
+ if (cells[p_column].buttons[i].id == p_id) {
return i;
+ }
}
return -1;
}
void TreeItem::set_button(int p_column, int p_idx, const Ref<Texture2D> &p_button) {
-
ERR_FAIL_COND(p_button.is_null());
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_INDEX(p_idx, cells[p_column].buttons.size());
@@ -589,7 +545,6 @@ void TreeItem::set_button(int p_column, int p_idx, const Ref<Texture2D> &p_butto
}
void TreeItem::set_button_color(int p_column, int p_idx, const Color &p_color) {
-
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_INDEX(p_idx, cells[p_column].buttons.size());
cells.write[p_column].buttons.write[p_idx].color = p_color;
@@ -597,7 +552,6 @@ void TreeItem::set_button_color(int p_column, int p_idx, const Color &p_color) {
}
void TreeItem::set_button_disabled(int p_column, int p_idx, bool p_disabled) {
-
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_INDEX(p_idx, cells[p_column].buttons.size());
@@ -606,7 +560,6 @@ void TreeItem::set_button_disabled(int p_column, int p_idx, bool p_disabled) {
}
bool TreeItem::is_button_disabled(int p_column, int p_idx) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), false);
@@ -614,34 +567,32 @@ bool TreeItem::is_button_disabled(int p_column, int p_idx) const {
}
void TreeItem::set_editable(int p_column, bool p_editable) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].editable = p_editable;
_changed_notify(p_column);
}
bool TreeItem::is_editable(int p_column) {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].editable;
}
void TreeItem::set_custom_color(int p_column, const Color &p_color) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].custom_color = true;
cells.write[p_column].color = p_color;
_changed_notify(p_column);
}
-Color TreeItem::get_custom_color(int p_column) const {
+Color TreeItem::get_custom_color(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
- if (!cells[p_column].custom_color)
+ if (!cells[p_column].custom_color) {
return Color();
+ }
return cells[p_column].color;
}
-void TreeItem::clear_custom_color(int p_column) {
+void TreeItem::clear_custom_color(int p_column) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].custom_color = false;
cells.write[p_column].color = Color();
@@ -649,19 +600,16 @@ void TreeItem::clear_custom_color(int p_column) {
}
void TreeItem::set_tooltip(int p_column, const String &p_tooltip) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].tooltip = p_tooltip;
}
String TreeItem::get_tooltip(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), "");
return cells[p_column].tooltip;
}
void TreeItem::set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].custom_bg_color = true;
cells.write[p_column].custom_bg_outline = p_bg_outline;
@@ -670,7 +618,6 @@ void TreeItem::set_custom_bg_color(int p_column, const Color &p_color, bool p_bg
}
void TreeItem::clear_custom_bg_color(int p_column) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].custom_bg_color = false;
cells.write[p_column].bg_color = Color();
@@ -678,21 +625,19 @@ void TreeItem::clear_custom_bg_color(int p_column) {
}
Color TreeItem::get_custom_bg_color(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
- if (!cells[p_column].custom_bg_color)
+ if (!cells[p_column].custom_bg_color) {
return Color();
+ }
return cells[p_column].bg_color;
}
void TreeItem::set_custom_as_button(int p_column, bool p_button) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].custom_button = p_button;
}
bool TreeItem::is_custom_set_as_button(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].custom_button;
}
@@ -709,20 +654,17 @@ TreeItem::TextAlign TreeItem::get_text_align(int p_column) const {
}
void TreeItem::set_expand_right(int p_column, bool p_enable) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].expand_right = p_enable;
_changed_notify(p_column);
}
bool TreeItem::get_expand_right(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), false);
return cells[p_column].expand_right;
}
void TreeItem::set_disable_folding(bool p_disable) {
-
disable_folding = p_disable;
_changed_notify(0);
}
@@ -732,7 +674,6 @@ bool TreeItem::is_folding_disabled() const {
}
Variant TreeItem::_call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
-
if (p_argcount < 1) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 0;
@@ -769,7 +710,6 @@ void TreeItem::call_recursive(const StringName &p_method, const Variant **p_args
}
void TreeItem::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode);
ClassDB::bind_method(D_METHOD("get_cell_mode", "column"), &TreeItem::get_cell_mode);
@@ -779,6 +719,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_text", "column", "text"), &TreeItem::set_text);
ClassDB::bind_method(D_METHOD("get_text", "column"), &TreeItem::get_text);
+ ClassDB::bind_method(D_METHOD("set_suffix", "column", "text"), &TreeItem::set_suffix);
+ ClassDB::bind_method(D_METHOD("get_suffix", "column"), &TreeItem::get_suffix);
+
ClassDB::bind_method(D_METHOD("set_icon", "column", "texture"), &TreeItem::set_icon);
ClassDB::bind_method(D_METHOD("get_icon", "column"), &TreeItem::get_icon);
@@ -884,63 +827,62 @@ void TreeItem::_bind_methods() {
}
void TreeItem::clear_children() {
-
TreeItem *c = children;
while (c) {
-
TreeItem *aux = c;
c = c->get_next();
- aux->parent = 0; // so it won't try to recursively autoremove from me in here
+ aux->parent = nullptr; // so it won't try to recursively autoremove from me in here
memdelete(aux);
}
- children = 0;
+ children = nullptr;
};
TreeItem::TreeItem(Tree *p_tree) {
-
tree = p_tree;
collapsed = false;
disable_folding = false;
custom_min_height = 0;
- parent = 0; // parent item
- next = 0; // next in list
- children = 0; //child items
+ parent = nullptr; // parent item
+ next = nullptr; // next in list
+ children = nullptr; //child items
}
TreeItem::~TreeItem() {
-
clear_children();
- if (parent)
+ if (parent) {
parent->remove_child(this);
+ }
if (tree && tree->root == this) {
-
- tree->root = 0;
+ tree->root = nullptr;
}
if (tree && tree->popup_edited_item == this) {
- tree->popup_edited_item = NULL;
+ tree->popup_edited_item = nullptr;
tree->pressing_for_editor = false;
}
if (tree && tree->cache.hover_item == this) {
- tree->cache.hover_item = NULL;
+ tree->cache.hover_item = nullptr;
}
- if (tree && tree->selected_item == this)
- tree->selected_item = NULL;
+ if (tree && tree->selected_item == this) {
+ tree->selected_item = nullptr;
+ }
- if (tree && tree->drop_mode_over == this)
- tree->drop_mode_over = NULL;
+ if (tree && tree->drop_mode_over == this) {
+ tree->drop_mode_over = nullptr;
+ }
- if (tree && tree->single_select_defer == this)
- tree->single_select_defer = NULL;
+ if (tree && tree->single_select_defer == this) {
+ tree->single_select_defer = nullptr;
+ }
if (tree && tree->edited_item == this) {
- tree->edited_item = NULL;
+ tree->edited_item = nullptr;
tree->pressing_for_editor = false;
}
}
@@ -953,7 +895,6 @@ TreeItem::~TreeItem() {
/**********************************************/
void Tree::update_cache() {
-
cache.font = get_theme_font("font");
cache.tb_font = get_theme_font("title_button_font");
cache.bg = get_theme_stylebox("bg");
@@ -998,45 +939,42 @@ void Tree::update_cache() {
}
int Tree::compute_item_height(TreeItem *p_item) const {
-
- if (p_item == root && hide_root)
+ if (p_item == root && hide_root) {
return 0;
+ }
ERR_FAIL_COND_V(cache.font.is_null(), 0);
int height = cache.font->get_height();
for (int i = 0; i < columns.size(); i++) {
-
for (int j = 0; j < p_item->cells[i].buttons.size(); j++) {
-
Size2i s; // = cache.button_pressed->get_minimum_size();
s += p_item->cells[i].buttons[j].texture->get_size();
- if (s.height > height)
+ if (s.height > height) {
height = s.height;
+ }
}
switch (p_item->cells[i].mode) {
-
case TreeItem::CELL_MODE_CHECK: {
-
int check_icon_h = cache.checked->get_height();
- if (height < check_icon_h)
+ if (height < check_icon_h) {
height = check_icon_h;
+ }
[[fallthrough]];
}
case TreeItem::CELL_MODE_STRING:
case TreeItem::CELL_MODE_CUSTOM:
case TreeItem::CELL_MODE_ICON: {
-
Ref<Texture2D> icon = p_item->cells[i].icon;
if (!icon.is_null()) {
-
Size2i s = p_item->cells[i].get_icon_size();
if (p_item->cells[i].icon_max_w > 0 && s.width > p_item->cells[i].icon_max_w) {
s.height = s.height * p_item->cells[i].icon_max_w / s.width;
}
- if (s.height > height)
+ if (s.height > height) {
height = s.height;
+ }
}
if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) {
height += cache.custom_button->get_minimum_size().height;
@@ -1048,8 +986,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
}
}
int item_min_height = p_item->get_custom_minimum_height();
- if (height < item_min_height)
+ if (height < item_min_height) {
height = item_min_height;
+ }
height += cache.vseparation;
@@ -1057,7 +996,6 @@ int Tree::compute_item_height(TreeItem *p_item) const {
}
int Tree::get_item_height(TreeItem *p_item) const {
-
int height = compute_item_height(p_item);
height += cache.vseparation;
@@ -1066,7 +1004,6 @@ int Tree::get_item_height(TreeItem *p_item) const {
TreeItem *c = p_item->children;
while (c) {
-
height += get_item_height(c);
c = c->next;
@@ -1077,14 +1014,14 @@ int Tree::get_item_height(TreeItem *p_item) const {
}
void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color, const Color &p_icon_color) {
-
ERR_FAIL_COND(cache.font.is_null());
Rect2i rect = p_rect;
Ref<Font> font = cache.font;
String text = p_cell.text;
- if (p_cell.suffix != String())
+ if (p_cell.suffix != String()) {
text += " " + p_cell.suffix;
+ }
int w = 0;
if (!p_cell.icon.is_null()) {
@@ -1127,9 +1064,9 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
}
int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item) {
-
- if (p_pos.y - cache.offset.y > (p_draw_size.height))
+ if (p_pos.y - cache.offset.y > (p_draw_size.height)) {
return -1; //draw no more!
+ }
RID ci = get_canvas_item();
@@ -1145,7 +1082,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
bool skip = (p_item == root && hide_root);
if (!skip && (p_pos.y + label_h - cache.offset.y) > 0) {
-
//draw separation.
//if (p_item->get_parent()!=root || !hide_root)
@@ -1157,7 +1093,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
int skip2 = 0;
for (int i = 0; i < columns.size(); i++) {
-
if (skip2) {
skip2--;
continue;
@@ -1166,22 +1101,18 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int w = get_column_width(i);
if (i == 0) {
-
w -= ofs;
if (w <= 0) {
-
ofs = get_column_width(0);
continue;
}
} else {
-
ofs += cache.hseparation;
w -= cache.hseparation;
}
if (p_item->cells[i].expand_right) {
-
int plus = 1;
while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) {
w += get_column_width(i + plus);
@@ -1194,8 +1125,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) {
Ref<Texture2D> b = p_item->cells[i].buttons[j].texture;
Size2 s = b->get_size() + cache.button_pressed->get_minimum_size();
- if (s.height < label_h)
+ if (s.height < label_h) {
s.height = label_h;
+ }
Point2i o = Point2i(ofs + w - s.width, p_pos.y) - cache.offset + p_draw_ofs;
@@ -1220,19 +1152,19 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (cache.draw_guides) {
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.position.x, cell_rect.position.y + cell_rect.size.height), cell_rect.position + cell_rect.size, cache.guide_color, 1);
+ RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.position.x, cell_rect.position.y + cell_rect.size.height), cell_rect.position + cell_rect.size, cache.guide_color, 1);
}
if (i == 0) {
-
if (p_item->cells[0].selected && select_mode == SELECT_ROW) {
Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.position.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y));
//Rect2 r = Rect2i(row_rect.pos,row_rect.size);
//r.grow(cache.selected->get_margin(MARGIN_LEFT));
- if (has_focus())
+ if (has_focus()) {
cache.selected_focus->draw(ci, row_rect);
- else
+ } else {
cache.selected->draw(ci, row_rect);
+ }
}
}
@@ -1256,7 +1188,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (p_item->cells[i].custom_bg_color) {
-
Rect2 r = cell_rect;
if (i == 0) {
r.position.x = p_draw_ofs.x;
@@ -1266,30 +1197,29 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
r.size.x += cache.hseparation;
}
if (p_item->cells[i].custom_bg_outline) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), p_item->cells[i].bg_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), p_item->cells[i].bg_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), p_item->cells[i].bg_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), p_item->cells[i].bg_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), p_item->cells[i].bg_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), p_item->cells[i].bg_color);
} else {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, r, p_item->cells[i].bg_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, r, p_item->cells[i].bg_color);
}
}
if (drop_mode_flags && drop_mode_over == p_item) {
-
Rect2 r = cell_rect;
if (drop_mode_section == -1 || drop_mode_section == 0) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color);
}
if (drop_mode_section == 0) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color);
}
if (drop_mode_section == 1 || drop_mode_section == 0) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color);
}
}
@@ -1300,13 +1230,10 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
text_pos.y += Math::floor((item_rect.size.y - font->get_height()) / 2) + font_ascent;
switch (p_item->cells[i].mode) {
-
case TreeItem::CELL_MODE_STRING: {
-
draw_item_rect(p_item->cells[i], item_rect, col, icon_col);
} break;
case TreeItem::CELL_MODE_CHECK: {
-
Ref<Texture2D> checked = cache.checked;
Ref<Texture2D> unchecked = cache.unchecked;
Point2i check_ofs = item_rect.position;
@@ -1330,9 +1257,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
} break;
case TreeItem::CELL_MODE_RANGE: {
if (p_item->cells[i].text != "") {
-
- if (!p_item->cells[i].editable)
+ if (!p_item->cells[i].editable) {
break;
+ }
int option = (int)p_item->cells[i].val;
@@ -1349,8 +1276,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
}
- if (p_item->cells[i].suffix != String())
+ if (p_item->cells[i].suffix != String()) {
s += " " + p_item->cells[i].suffix;
+ }
Ref<Texture2D> downarrow = cache.select_arrow;
@@ -1362,18 +1290,19 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
downarrow->draw(ci, arrow_pos);
} else {
-
Ref<Texture2D> updown = cache.updown;
String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step));
- if (p_item->cells[i].suffix != String())
+ if (p_item->cells[i].suffix != String()) {
valtext += " " + p_item->cells[i].suffix;
+ }
font->draw(ci, text_pos, valtext, col, item_rect.size.x - updown->get_width());
- if (!p_item->cells[i].editable)
+ if (!p_item->cells[i].editable) {
break;
+ }
Point2i updown_pos = item_rect.position;
updown_pos.x += item_rect.size.x - updown->get_width();
@@ -1384,9 +1313,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
} break;
case TreeItem::CELL_MODE_ICON: {
-
- if (p_item->cells[i].icon.is_null())
+ if (p_item->cells[i].icon.is_null()) {
break;
+ }
Size2i icon_size = p_item->cells[i].get_icon_size();
if (p_item->cells[i].icon_max_w > 0 && icon_size.width > p_item->cells[i].icon_max_w) {
icon_size.height = icon_size.height * p_item->cells[i].icon_max_w / icon_size.width;
@@ -1400,16 +1329,14 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
} break;
case TreeItem::CELL_MODE_CUSTOM: {
-
if (p_item->cells[i].custom_draw_obj.is_valid()) {
-
Object *cdo = ObjectDB::get_instance(p_item->cells[i].custom_draw_obj);
- if (cdo)
+ if (cdo) {
cdo->call(p_item->cells[i].custom_draw_callback, p_item, Rect2(item_rect));
+ }
}
if (!p_item->cells[i].editable) {
-
draw_item_rect(p_item->cells[i], item_rect, col, icon_col);
break;
}
@@ -1425,7 +1352,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (p_item->cells[i].custom_button) {
if (cache.hover_item == p_item && cache.hover_cell == i) {
- if (InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
+ if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
draw_style_box(cache.custom_button_pressed, ir);
} else {
draw_style_box(cache.custom_button_hover, ir);
@@ -1446,19 +1373,17 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (i == 0) {
-
ofs = get_column_width(0);
} else {
-
ofs += w + bw;
}
if (select_mode == SELECT_MULTI && selected_item == p_item && selected_col == i) {
-
- if (has_focus())
+ if (has_focus()) {
cache.cursor->draw(ci, cell_rect);
- else
+ } else {
cache.cursor_unfocus->draw(ci, cell_rect);
+ }
}
}
@@ -1467,7 +1392,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Ref<Texture2D> arrow;
if (p_item->collapsed) {
-
arrow = cache.arrow_collapsed;
} else {
arrow = cache.arrow;
@@ -1492,14 +1416,14 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int prev_ofs = children_pos.y - cache.offset.y + p_draw_ofs.y;
while (c) {
-
if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != root)) {
int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs;
- if (c->get_children() != NULL)
+ if (c->get_children() != nullptr) {
root_pos -= Point2i(cache.arrow->get_width(), 0);
+ }
float line_width = 1.0;
#ifdef TOOLS_ENABLED
@@ -1509,8 +1433,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Point2i parent_pos = Point2i(parent_ofs - cache.arrow->get_width() / 2, p_pos.y + label_h / 2 + cache.arrow->get_height() / 2) - cache.offset + p_draw_ofs;
if (root_pos.y + line_width >= 0) {
- VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width);
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width);
+ RenderingServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width);
+ RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width);
}
if (htotal < 0) {
@@ -1543,11 +1467,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
int Tree::_count_selected_items(TreeItem *p_from) const {
-
int count = 0;
for (int i = 0; i < columns.size(); i++) {
- if (p_from->is_selected(i))
+ if (p_from->is_selected(i)) {
count++;
+ }
}
if (p_from->get_children()) {
@@ -1560,8 +1484,8 @@ int Tree::_count_selected_items(TreeItem *p_from) const {
return count;
}
-void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev, bool *r_in_range, bool p_force_deselect) {
+void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev, bool *r_in_range, bool p_force_deselect) {
TreeItem::Cell &selected_cell = p_selected->cells.write[p_col];
bool switched = false;
@@ -1573,14 +1497,13 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
bool emitted_row = false;
for (int i = 0; i < columns.size(); i++) {
-
TreeItem::Cell &c = p_current->cells.write[i];
- if (!c.selectable)
+ if (!c.selectable) {
continue;
+ }
if (select_mode == SELECT_ROW) {
-
if (p_selected == p_current && (!c.selected || allow_reselect)) {
c.selected = true;
selected_item = p_selected;
@@ -1595,45 +1518,40 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
*/
} else if (c.selected) {
-
c.selected = false;
//p_current->deselected_signal.call(p_col);
}
} else if (select_mode == SELECT_SINGLE || select_mode == SELECT_MULTI) {
-
if (!r_in_range && &selected_cell == &c) {
-
if (!selected_cell.selected || allow_reselect) {
-
selected_cell.selected = true;
selected_item = p_selected;
selected_col = i;
emit_signal("cell_selected");
- if (select_mode == SELECT_MULTI)
+ if (select_mode == SELECT_MULTI) {
emit_signal("multi_selected", p_current, i, true);
- else if (select_mode == SELECT_SINGLE)
+ } else if (select_mode == SELECT_SINGLE) {
emit_signal("item_selected");
+ }
} else if (select_mode == SELECT_MULTI && (selected_item != p_selected || selected_col != i)) {
-
selected_item = p_selected;
selected_col = i;
emit_signal("cell_selected");
}
} else {
-
if (r_in_range && *r_in_range && !p_force_deselect) {
-
if (!c.selected && c.selectable) {
c.selected = true;
emit_signal("multi_selected", p_current, i, true);
}
} else if (!r_in_range || p_force_deselect) {
- if (select_mode == SELECT_MULTI && c.selected)
+ if (select_mode == SELECT_MULTI && c.selected) {
emit_signal("multi_selected", p_current, i, false);
+ }
c.selected = false;
}
//p_current->deselected_signal.call(p_col);
@@ -1648,21 +1566,17 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
TreeItem *c = p_current->children;
while (c) {
-
select_single_item(p_selected, c, p_col, p_prev, r_in_range, p_current->is_collapsed() || p_force_deselect);
c = c->next;
}
}
Rect2 Tree::search_item_rect(TreeItem *p_from, TreeItem *p_item) {
-
return Rect2();
}
void Tree::_range_click_timeout() {
-
- if (range_item_last && !range_drag_enabled && InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
-
+ if (range_item_last && !range_drag_enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
Point2 pos = get_local_mouse_position() - cache.bg->get_offset();
if (show_column_titles) {
pos.y -= _get_title_button_height();
@@ -1689,8 +1603,9 @@ void Tree::_range_click_timeout() {
range_click_timer->start();
}
- if (!click_handled)
+ if (!click_handled) {
range_click_timer->stop();
+ }
if (propagate_mouse_activated) {
emit_signal("item_activated");
@@ -1703,7 +1618,6 @@ void Tree::_range_click_timeout() {
}
int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod) {
-
int item_h = compute_item_height(p_item) + cache.vseparation;
bool skip = (p_item == root && hide_root);
@@ -1716,9 +1630,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
if (!p_item->disable_folding && !hide_folding && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + cache.item_margin))) {
-
- if (p_item->children)
+ if (p_item->children) {
p_item->set_collapsed(!p_item->is_collapsed());
+ }
return -1; //handled!
}
@@ -1729,11 +1643,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
int col_ofs = 0;
int col_width = 0;
for (int i = 0; i < columns.size(); i++) {
-
col_width = get_column_width(i);
if (p_item->cells[i].expand_right) {
-
int plus = 1;
while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) {
col_width += cache.hseparation;
@@ -1752,16 +1664,15 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
break;
}
- if (col == -1)
+ if (col == -1) {
return -1;
- else if (col == 0) {
+ } else if (col == 0) {
int margin = x_ofs + cache.item_margin; //-cache.hseparation;
//int lm = cache.bg->get_margin(MARGIN_LEFT);
col_width -= margin;
col_ofs += margin;
x -= margin;
} else {
-
col_width -= cache.hseparation;
x -= cache.hseparation;
}
@@ -1812,9 +1723,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
if (select_mode == SELECT_MULTI && p_mod->get_command() && c.selectable) {
-
if (!c.selected || p_button == BUTTON_RIGHT) {
-
p_item->select(col);
emit_signal("multi_selected", p_item, col, true);
if (p_button == BUTTON_RIGHT) {
@@ -1823,18 +1732,14 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
//p_item->selected_signal.call(col);
} else {
-
p_item->deselect(col);
emit_signal("multi_selected", p_item, col, false);
//p_item->deselected_signal.call(col);
}
} else {
-
if (c.selectable) {
-
if (select_mode == SELECT_MULTI && p_mod->get_shift() && selected_item && selected_item != p_item) {
-
bool inrange = false;
select_single_item(p_item, root, col, selected_item, &inrange);
@@ -1842,14 +1747,12 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
emit_signal("item_rmb_selected", get_local_mouse_position());
}
} else {
-
int icount = _count_selected_items(root);
if (select_mode == SELECT_MULTI && icount > 1 && p_button != BUTTON_RIGHT) {
single_select_defer = p_item;
single_select_defer_column = col;
} else {
-
if (p_button != BUTTON_RIGHT || !c.selected) {
select_single_item(p_item, root, col);
}
@@ -1870,8 +1773,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
}
- if (!c.editable)
+ if (!c.editable) {
return -1; // if cell is not editable, don't bother
+ }
/* editing */
@@ -1879,7 +1783,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
String editor_text = c.text;
switch (c.mode) {
-
case TreeItem::CELL_MODE_STRING: {
//nothing in particular
@@ -1889,7 +1792,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} break;
case TreeItem::CELL_MODE_CHECK: {
-
bring_up_editor = false; //checkboxes are not edited with editor
if (force_edit_checkbox_only_on_checkbox) {
if (x < cache.checked->get_width()) {
@@ -1910,7 +1812,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
popup_menu->clear();
for (int i = 0; i < c.text.get_slice_count(","); i++) {
-
String s = c.text.get_slicec(',', i);
popup_menu->add_item(s.get_slicec(':', 0), s.get_slicec(':', 1).empty() ? i : s.get_slicec(':', 1).to_int());
}
@@ -1923,16 +1824,12 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
//}
bring_up_editor = false;
} else {
-
if (x >= (col_width - item_h / 2)) {
-
/* touching the combo */
bool up = p_pos.y < (item_h / 2);
if (p_button == BUTTON_LEFT) {
-
if (range_click_timer->get_time_left() == 0) {
-
range_item_last = p_item;
range_up_last = up;
@@ -1941,7 +1838,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
range_click_timer->start();
} else if (up != range_up_last) {
-
return -1; // break. avoid changing direction on mouse held
}
@@ -1950,15 +1846,12 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
item_edited(col, p_item);
} else if (p_button == BUTTON_RIGHT) {
-
p_item->set_range(col, (up ? c.max : c.min));
item_edited(col, p_item);
} else if (p_button == BUTTON_WHEEL_UP) {
-
p_item->set_range(col, c.val + c.step);
item_edited(col, p_item);
} else if (p_button == BUTTON_WHEEL_DOWN) {
-
p_item->set_range(col, c.val - c.step);
item_edited(col, p_item);
}
@@ -1967,10 +1860,10 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
bring_up_editor = false;
} else {
-
editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step));
- if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id)
+ if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) {
bring_up_editor = false;
+ }
}
}
click_handled = true;
@@ -1998,8 +1891,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
} break;
};
- if (!bring_up_editor || p_button != BUTTON_LEFT)
+ if (!bring_up_editor || p_button != BUTTON_LEFT) {
return -1;
+ }
click_handled = true;
popup_edited_item = p_item;
@@ -2011,7 +1905,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
return -1; //select
} else {
-
Point2i new_pos = p_pos;
if (!skip) {
@@ -2026,11 +1919,11 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
TreeItem *c = p_item->children;
while (c) {
-
int child_h = propagate_mouse_event(new_pos, x_ofs, y_ofs, p_doubleclick, c, p_button, p_mod);
- if (child_h < 0)
+ if (child_h < 0) {
return -1; // break, stop propagating, no need to anymore
+ }
new_pos.y -= child_h;
y_ofs += child_h;
@@ -2047,47 +1940,46 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
void Tree::_text_editor_modal_close() {
-
- if (InputFilter::get_singleton()->is_key_pressed(KEY_ESCAPE) ||
- InputFilter::get_singleton()->is_key_pressed(KEY_KP_ENTER) ||
- InputFilter::get_singleton()->is_key_pressed(KEY_ENTER)) {
-
+ if (Input::get_singleton()->is_key_pressed(KEY_ESCAPE) ||
+ Input::get_singleton()->is_key_pressed(KEY_KP_ENTER) ||
+ Input::get_singleton()->is_key_pressed(KEY_ENTER)) {
return;
}
- if (value_editor->has_point(value_editor->get_local_mouse_position()))
+ if (value_editor->has_point(value_editor->get_local_mouse_position())) {
return;
+ }
_text_editor_enter(text_editor->get_text());
}
void Tree::_text_editor_enter(String p_text) {
-
popup_editor->hide();
- if (!popup_edited_item)
+ if (!popup_edited_item) {
return;
+ }
- if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size())
+ if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) {
return;
+ }
TreeItem::Cell &c = popup_edited_item->cells.write[popup_edited_item_col];
switch (c.mode) {
-
case TreeItem::CELL_MODE_STRING: {
-
c.text = p_text;
//popup_edited_item->edited_signal.call( popup_edited_item_col );
} break;
case TreeItem::CELL_MODE_RANGE: {
-
c.val = p_text.to_double();
- if (c.step > 0)
+ if (c.step > 0) {
c.val = Math::stepify(c.val, c.step);
- if (c.val < c.min)
+ }
+ if (c.val < c.min) {
c.val = c.min;
- else if (c.val > c.max)
+ } else if (c.val > c.max) {
c.val = c.max;
+ }
//popup_edited_item->edited_signal.call( popup_edited_item_col );
} break;
@@ -2101,7 +1993,6 @@ void Tree::_text_editor_enter(String p_text) {
}
void Tree::value_editor_changed(double p_value) {
-
if (updating_value_editor) {
return;
}
@@ -2116,12 +2007,13 @@ void Tree::value_editor_changed(double p_value) {
}
void Tree::popup_select(int p_option) {
-
- if (!popup_edited_item)
+ if (!popup_edited_item) {
return;
+ }
- if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size())
+ if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) {
return;
+ }
popup_edited_item->cells.write[popup_edited_item_col].val = p_option;
//popup_edited_item->edited_signal.call( popup_edited_item_col );
@@ -2131,7 +2023,7 @@ void Tree::popup_select(int p_option) {
void Tree::_go_left() {
if (selected_col == 0) {
- if (selected_item->get_children() != NULL && !selected_item->is_collapsed()) {
+ if (selected_item->get_children() != nullptr && !selected_item->is_collapsed()) {
selected_item->set_collapsed(true);
} else {
if (columns.size() == 1) { // goto parent with one column
@@ -2149,7 +2041,6 @@ void Tree::_go_left() {
selected_col--;
emit_signal("cell_selected");
} else {
-
selected_item->select(selected_col - 1);
}
}
@@ -2160,7 +2051,7 @@ void Tree::_go_left() {
void Tree::_go_right() {
if (selected_col == (columns.size() - 1)) {
- if (selected_item->get_children() != NULL && selected_item->is_collapsed()) {
+ if (selected_item->get_children() != nullptr && selected_item->is_collapsed()) {
selected_item->set_collapsed(false);
} else if (selected_item->get_next_visible()) {
selected_col = 0;
@@ -2171,7 +2062,6 @@ void Tree::_go_right() {
selected_col++;
emit_signal("cell_selected");
} else {
-
selected_item->select(selected_col + 1);
}
}
@@ -2181,12 +2071,11 @@ void Tree::_go_right() {
}
void Tree::_go_up() {
- TreeItem *prev = NULL;
+ TreeItem *prev = nullptr;
if (!selected_item) {
prev = get_last_item();
selected_col = 0;
} else {
-
prev = selected_item->get_prev_visible();
if (last_keypress != 0) {
//incr search next
@@ -2200,19 +2089,20 @@ void Tree::_go_up() {
}
if (select_mode == SELECT_MULTI) {
-
- if (!prev)
+ if (!prev) {
return;
+ }
selected_item = prev;
emit_signal("cell_selected");
update();
} else {
-
int col = selected_col < 0 ? 0 : selected_col;
- while (prev && !prev->cells[col].selectable)
+ while (prev && !prev->cells[col].selectable) {
prev = prev->get_prev_visible();
- if (!prev)
+ }
+ if (!prev) {
return; // do nothing..
+ }
prev->select(col);
}
@@ -2221,14 +2111,12 @@ void Tree::_go_up() {
}
void Tree::_go_down() {
- TreeItem *next = NULL;
+ TreeItem *next = nullptr;
if (!selected_item) {
-
if (root) {
next = hide_root ? root->get_next_visible() : root;
}
} else {
-
next = selected_item->get_next_visible();
if (last_keypress != 0) {
@@ -2243,7 +2131,6 @@ void Tree::_go_down() {
}
if (select_mode == SELECT_MULTI) {
-
if (!next) {
return;
}
@@ -2252,11 +2139,11 @@ void Tree::_go_down() {
emit_signal("cell_selected");
update();
} else {
-
int col = selected_col < 0 ? 0 : selected_col;
- while (next && !next->cells[col].selectable)
+ while (next && !next->cells[col].selectable) {
next = next->get_next_visible();
+ }
if (!next) {
return; // do nothing..
}
@@ -2268,13 +2155,13 @@ void Tree::_go_down() {
}
void Tree::_gui_input(Ref<InputEvent> p_event) {
-
Ref<InputEventKey> k = p_event;
bool is_command = k.is_valid() && k->get_command();
if (p_event->is_action("ui_right") && p_event->is_pressed()) {
-
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree) {
+ accept_event();
+ }
if (!selected_item || select_mode == SELECT_ROW || selected_col > (columns.size() - 1)) {
return;
@@ -2290,8 +2177,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
_go_right();
}
} else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
-
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree) {
+ accept_event();
+ }
if (!selected_item || select_mode == SELECT_ROW || selected_col < 0) {
return;
@@ -2309,48 +2197,50 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
} else if (p_event->is_action("ui_up") && p_event->is_pressed() && !is_command) {
-
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree) {
+ accept_event();
+ }
_go_up();
} else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) {
-
- if (!cursor_can_exit_tree) accept_event();
+ if (!cursor_can_exit_tree) {
+ accept_event();
+ }
_go_down();
} else if (p_event->is_action("ui_page_down") && p_event->is_pressed()) {
+ if (!cursor_can_exit_tree) {
+ accept_event();
+ }
- if (!cursor_can_exit_tree) accept_event();
-
- TreeItem *next = NULL;
- if (!selected_item)
+ TreeItem *next = nullptr;
+ if (!selected_item) {
return;
+ }
next = selected_item;
for (int i = 0; i < 10; i++) {
-
TreeItem *_n = next->get_next_visible();
if (_n) {
next = _n;
} else {
-
break;
}
}
- if (next == selected_item)
+ if (next == selected_item) {
return;
+ }
if (select_mode == SELECT_MULTI) {
-
selected_item = next;
emit_signal("cell_selected");
update();
} else {
-
- while (next && !next->cells[selected_col].selectable)
+ while (next && !next->cells[selected_col].selectable) {
next = next->get_next_visible();
+ }
if (!next) {
return; // do nothing..
}
@@ -2359,36 +2249,36 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
ensure_cursor_is_visible();
} else if (p_event->is_action("ui_page_up") && p_event->is_pressed()) {
+ if (!cursor_can_exit_tree) {
+ accept_event();
+ }
- if (!cursor_can_exit_tree) accept_event();
-
- TreeItem *prev = NULL;
- if (!selected_item)
+ TreeItem *prev = nullptr;
+ if (!selected_item) {
return;
+ }
prev = selected_item;
for (int i = 0; i < 10; i++) {
-
TreeItem *_n = prev->get_prev_visible();
if (_n) {
prev = _n;
} else {
-
break;
}
}
- if (prev == selected_item)
+ if (prev == selected_item) {
return;
+ }
if (select_mode == SELECT_MULTI) {
-
selected_item = prev;
emit_signal("cell_selected");
update();
} else {
-
- while (prev && !prev->cells[selected_col].selectable)
+ while (prev && !prev->cells[selected_col].selectable) {
prev = prev->get_prev_visible();
+ }
if (!prev) {
return; // do nothing..
}
@@ -2396,7 +2286,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
ensure_cursor_is_visible();
} else if (p_event->is_action("ui_accept") && p_event->is_pressed()) {
-
if (selected_item) {
//bring up editor if possible
if (!edit_selected()) {
@@ -2406,10 +2295,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
accept_event();
} else if (p_event->is_action("ui_select") && p_event->is_pressed()) {
-
if (select_mode == SELECT_MULTI) {
- if (!selected_item)
+ if (!selected_item) {
return;
+ }
if (selected_item->is_selected(selected_col)) {
selected_item->deselect(selected_col);
emit_signal("multi_selected", selected_item, selected_col, false);
@@ -2423,34 +2312,38 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (k.is_valid()) { // Incremental search
- if (!k->is_pressed())
+ if (!k->is_pressed()) {
return;
- if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey())
+ }
+ if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey()) {
return;
- if (!root)
+ }
+ if (!root) {
return;
+ }
- if (hide_root && !root->get_next_visible())
+ if (hide_root && !root->get_next_visible()) {
return;
+ }
if (k->get_unicode() > 0) {
-
_do_incr_search(String::chr(k->get_unicode()));
accept_event();
return;
} else {
- if (k->get_keycode() != KEY_SHIFT)
+ if (k->get_keycode() != KEY_SHIFT) {
last_keypress = 0;
+ }
}
}
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
-
- if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
+ if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
+ }
Ref<StyleBox> bg = cache.bg;
@@ -2467,13 +2360,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
pos.x += cache.offset.x;
int len = 0;
for (int i = 0; i < columns.size(); i++) {
-
len += get_column_width(i);
if (pos.x < len) {
-
cache.hover_type = Cache::CLICK_TITLE;
cache.hover_index = i;
- update();
break;
}
}
@@ -2481,16 +2371,19 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (root) {
-
Point2 mpos = mm->get_position();
mpos -= cache.bg->get_offset();
mpos.y -= _get_title_button_height();
if (mpos.y >= 0) {
-
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
mpos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
mpos.y += v_scroll->get_value();
+ }
+
+ TreeItem *old_it = cache.hover_item;
+ int old_col = cache.hover_cell;
int col, h, section;
TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
@@ -2506,18 +2399,21 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
}
- if (it != cache.hover_item) {
- cache.hover_item = it;
- update();
- }
+ cache.hover_item = it;
+ cache.hover_cell = col;
- if (it && col != cache.hover_cell) {
- cache.hover_cell = col;
- update();
+ if (it != old_it || col != old_col) {
+ // Only need to update if mouse enters/exits a button
+ bool was_over_button = old_it && old_it->cells[old_col].custom_button;
+ bool is_over_button = it && it->cells[col].custom_button;
+ if (was_over_button || is_over_button) {
+ update();
+ }
}
}
}
+ // Update if mouse enters/exits columns
if (cache.hover_type != old_hover || cache.hover_index != old_index) {
update();
}
@@ -2526,16 +2422,14 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
//range drag
if (!range_drag_enabled) {
-
Vector2 cpos = mm->get_position();
if (cpos.distance_to(pressing_pos) > 2) {
range_drag_enabled = true;
range_drag_capture_pos = cpos;
range_drag_base = popup_edited_item->get_range(popup_edited_item_col);
- InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
}
} else {
-
const TreeItem::Cell &c = popup_edited_item->cells[popup_edited_item_col];
float diff_y = -mm->get_relative().y;
diff_y = Math::pow(ABS(diff_y), 1.8f) * SGN(diff_y);
@@ -2547,7 +2441,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (drag_touching && !drag_touching_deaccel) {
-
drag_accum -= mm->get_relative().y;
v_scroll->set_value(drag_from + drag_accum);
drag_speed = -mm->get_speed().y;
@@ -2557,13 +2450,12 @@ 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 corrupt stuff
+ if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
+ }
if (!b->is_pressed()) {
-
if (b->get_button_index() == BUTTON_LEFT) {
-
Point2 pos = b->get_position() - cache.bg->get_offset();
if (show_column_titles) {
pos.y -= _get_title_button_height();
@@ -2572,7 +2464,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
pos.x += cache.offset.x;
int len = 0;
for (int i = 0; i < columns.size(); i++) {
-
len += get_column_width(i);
if (pos.x < len) {
emit_signal("column_title_pressed", i);
@@ -2584,17 +2475,15 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (single_select_defer) {
select_single_item(single_select_defer, root, single_select_defer_column);
- single_select_defer = NULL;
+ single_select_defer = nullptr;
}
range_click_timer->stop();
if (pressing_for_editor) {
-
if (range_drag_enabled) {
-
range_drag_enabled = false;
- InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
warp_mouse(range_drag_capture_pos);
} else {
Rect2 rect = get_selected()->get_meta("__focus_rect");
@@ -2609,7 +2498,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
pressing_for_editor = false;
}
- if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != NULL) {
+ if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) {
// make sure in case of wrong reference after reconstructing whole TreeItems
cache.click_item = get_item_at_position(cache.click_pos);
emit_signal("button_pressed", cache.click_item, cache.click_column, cache.click_id);
@@ -2617,17 +2506,15 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
cache.click_type = Cache::CLICK_NONE;
cache.click_index = -1;
cache.click_id = -1;
- cache.click_item = NULL;
+ cache.click_item = nullptr;
cache.click_column = 0;
if (drag_touching) {
-
if (drag_speed == 0) {
drag_touching_deaccel = false;
drag_touching = false;
set_physics_process_internal(false);
} else {
-
drag_touching_deaccel = true;
}
}
@@ -2636,8 +2523,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
}
- if (range_drag_enabled)
+ if (range_drag_enabled) {
return;
+ }
switch (b->get_button_index()) {
case BUTTON_RIGHT:
@@ -2654,10 +2542,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
pos.x += cache.offset.x;
int len = 0;
for (int i = 0; i < columns.size(); i++) {
-
len += get_column_width(i);
if (pos.x < len) {
-
cache.click_type = Cache::CLICK_TITLE;
cache.click_index = i;
//cache.click_id=;
@@ -2688,8 +2574,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
pressing_pos = b->get_position();
}
- if (b->get_button_index() == BUTTON_RIGHT)
+ if (b->get_button_index() == BUTTON_RIGHT) {
break;
+ }
if (drag_touching) {
set_physics_process_internal(false);
@@ -2711,8 +2598,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
if (b->get_button_index() == BUTTON_LEFT) {
- if (get_item_at_position(b->get_position()) == NULL && !b->get_shift() && !b->get_control() && !b->get_command())
+ if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command()) {
emit_signal("nothing_selected");
+ }
}
}
@@ -2723,7 +2611,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} break;
case BUTTON_WHEEL_UP: {
-
double prev_value = v_scroll->get_value();
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8);
if (v_scroll->get_value() != prev_value) {
@@ -2732,7 +2619,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} break;
case BUTTON_WHEEL_DOWN: {
-
double prev_value = v_scroll->get_value();
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8);
if (v_scroll->get_value() != prev_value) {
@@ -2745,7 +2631,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
-
double prev_v = v_scroll->get_value();
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
@@ -2759,15 +2644,15 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
bool Tree::edit_selected() {
-
TreeItem *s = get_selected();
ERR_FAIL_COND_V_MSG(!s, false, "No item selected.");
ensure_cursor_is_visible();
int col = get_selected_column();
ERR_FAIL_INDEX_V_MSG(col, columns.size(), false, "No item column selected.");
- if (!s->cells[col].editable)
+ if (!s->cells[col].editable) {
return false;
+ }
Rect2 rect = s->get_meta("__focus_rect");
popup_edited_item = s;
@@ -2776,12 +2661,10 @@ bool Tree::edit_selected() {
const TreeItem::Cell &c = s->cells[col];
if (c.mode == TreeItem::CELL_MODE_CHECK) {
-
s->set_checked(col, !c.checked);
item_edited(col, s);
return true;
} else if (c.mode == TreeItem::CELL_MODE_CUSTOM) {
-
edited_item = s;
edited_col = col;
custom_popup_rect = Rect2i(get_global_position() + rect.position, rect.size);
@@ -2790,10 +2673,8 @@ bool Tree::edit_selected() {
return true;
} else if (c.mode == TreeItem::CELL_MODE_RANGE && c.text != "") {
-
popup_menu->clear();
for (int i = 0; i < c.text.get_slice_count(","); i++) {
-
String s2 = c.text.get_slicec(',', i);
popup_menu->add_item(s2.get_slicec(':', 0), s2.get_slicec(':', 1).empty() ? i : s2.get_slicec(':', 1).to_int());
}
@@ -2806,7 +2687,6 @@ bool Tree::edit_selected() {
return true;
} else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE) {
-
Rect2 popup_rect;
Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2);
@@ -2820,7 +2700,6 @@ bool Tree::edit_selected() {
text_editor->select_all();
if (c.mode == TreeItem::CELL_MODE_RANGE) {
-
popup_rect.size.y += value_editor->get_minimum_size().height;
value_editor->show();
@@ -2849,12 +2728,11 @@ bool Tree::edit_selected() {
}
Size2 Tree::get_internal_min_size() const {
-
Size2i size = cache.bg->get_offset();
- if (root)
+ if (root) {
size.height += get_item_height(root);
+ }
for (int i = 0; i < columns.size(); i++) {
-
size.width += columns[i].min_width;
}
@@ -2862,13 +2740,11 @@ Size2 Tree::get_internal_min_size() const {
}
void Tree::update_scrollbars() {
-
Size2 size = get_size();
int tbh;
if (show_column_titles) {
tbh = _get_title_button_height();
} else {
-
tbh = 0;
}
@@ -2884,11 +2760,9 @@ void Tree::update_scrollbars() {
Size2 min = get_internal_min_size();
if (min.height < size.height - hmin.height) {
-
v_scroll->hide();
cache.offset.y = 0;
} else {
-
v_scroll->show();
v_scroll->set_max(min.height);
v_scroll->set_page(size.height - hmin.height - tbh);
@@ -2896,11 +2770,9 @@ void Tree::update_scrollbars() {
}
if (min.width < size.width - vmin.width) {
-
h_scroll->hide();
cache.offset.x = 0;
} else {
-
h_scroll->show();
h_scroll->set_max(min.width);
h_scroll->set_page(size.width - vmin.width);
@@ -2909,19 +2781,15 @@ void Tree::update_scrollbars() {
}
int Tree::_get_title_button_height() const {
-
ERR_FAIL_COND_V(cache.font.is_null() || cache.title_button.is_null(), 0);
return show_column_titles ? cache.font->get_height() + cache.title_button->get_minimum_size().height : 0;
}
void Tree::_notification(int p_what) {
-
if (p_what == NOTIFICATION_FOCUS_ENTER) {
-
focus_in_id = get_tree()->get_event_count();
}
if (p_what == NOTIFICATION_MOUSE_EXIT) {
-
if (cache.hover_type != Cache::CLICK_NONE) {
cache.hover_type = Cache::CLICK_NONE;
update();
@@ -2929,35 +2797,28 @@ void Tree::_notification(int p_what) {
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
-
drag_touching = false;
}
if (p_what == NOTIFICATION_ENTER_TREE) {
-
update_cache();
}
if (p_what == NOTIFICATION_DRAG_END) {
-
drop_mode_flags = 0;
scrolling = false;
set_physics_process_internal(false);
update();
}
if (p_what == NOTIFICATION_DRAG_BEGIN) {
-
- single_select_defer = NULL;
+ single_select_defer = nullptr;
if (cache.scroll_speed > 0) {
scrolling = true;
set_physics_process_internal(true);
}
}
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
-
if (drag_touching) {
-
if (drag_touching_deaccel) {
-
float pos = v_scroll->get_value();
pos += drag_speed * get_physics_process_delta_time();
@@ -3016,7 +2877,6 @@ void Tree::_notification(int p_what) {
}
if (p_what == NOTIFICATION_DRAW) {
-
update_cache();
update_scrollbars();
RID ci = get_canvas_item();
@@ -3030,9 +2890,9 @@ void Tree::_notification(int p_what) {
bg->draw(ci, Rect2(Point2(), get_size()));
if (has_focus()) {
- VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
bg_focus->draw(ci, Rect2(Point2(), get_size()));
- VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
}
int tbh = _get_title_button_height();
@@ -3041,23 +2901,13 @@ void Tree::_notification(int p_what) {
draw_size.y -= tbh;
if (root) {
-
draw_item(Point2(), draw_ofs, draw_size, root);
}
- int ofs = 0;
-
- for (int i = 0; i < (columns.size() - 1 - 1); i++) {
-
- ofs += get_column_width(i);
- }
-
if (show_column_titles) {
-
//title buttons
int ofs2 = cache.bg->get_margin(MARGIN_LEFT);
for (int i = 0; i < columns.size(); i++) {
-
Ref<StyleBox> sb = (cache.click_type == Cache::CLICK_TITLE && cache.click_index == i) ? cache.title_button_pressed : ((cache.hover_type == Cache::CLICK_TITLE && cache.hover_index == i) ? cache.title_button_hover : cache.title_button);
Ref<Font> f = cache.tb_font;
Rect2 tbrect = Rect2(ofs2 - cache.offset.x, bg->get_margin(MARGIN_TOP), get_column_width(i), tbh);
@@ -3075,8 +2925,7 @@ void Tree::_notification(int p_what) {
}
if (p_what == NOTIFICATION_RESIZED || p_what == NOTIFICATION_TRANSFORM_CHANGED) {
-
- if (popup_edited_item != NULL) {
+ if (popup_edited_item != nullptr) {
Rect2 rect = popup_edited_item->get_meta("__focus_rect");
Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2);
Point2i textedpos = get_global_position() + rect.position - ofs;
@@ -3091,24 +2940,21 @@ void Tree::_notification(int p_what) {
}
Size2 Tree::get_minimum_size() const {
-
return Size2(1, 1);
}
TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) {
+ ERR_FAIL_COND_V(blocked > 0, nullptr);
- ERR_FAIL_COND_V(blocked > 0, NULL);
-
- TreeItem *ti = NULL;
+ TreeItem *ti = nullptr;
if (p_parent) {
-
// Append or insert a new item to the given parent.
ti = memnew(TreeItem(this));
- ERR_FAIL_COND_V(!ti, NULL);
+ ERR_FAIL_COND_V(!ti, nullptr);
ti->cells.resize(columns.size());
- TreeItem *prev = NULL;
+ TreeItem *prev = nullptr;
TreeItem *c = p_parent->children;
int idx = 0;
@@ -3121,18 +2967,18 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) {
c = c->next;
}
- if (prev)
+ if (prev) {
prev->next = ti;
- else
+ } else {
p_parent->children = ti;
+ }
ti->parent = p_parent;
} else {
-
if (!root) {
// No root exists, make the given item the new root.
ti = memnew(TreeItem(this));
- ERR_FAIL_COND_V(!ti, NULL);
+ ERR_FAIL_COND_V(!ti, nullptr);
ti->cells.resize(columns.size());
root = ti;
@@ -3146,61 +2992,56 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) {
}
TreeItem *Tree::get_root() {
-
return root;
}
-TreeItem *Tree::get_last_item() {
+TreeItem *Tree::get_last_item() {
TreeItem *last = root;
while (last) {
-
- if (last->next)
+ if (last->next) {
last = last->next;
- else if (last->children)
+ } else if (last->children) {
last = last->children;
- else
+ } else {
break;
+ }
}
return last;
}
void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) {
-
edited_item = p_item;
edited_col = p_column;
- if (p_lmb)
+ if (p_lmb) {
emit_signal("item_edited");
- else
+ } else {
emit_signal("item_rmb_edited");
+ }
}
void Tree::item_changed(int p_column, TreeItem *p_item) {
-
update();
}
void Tree::item_selected(int p_column, TreeItem *p_item) {
-
if (select_mode == SELECT_MULTI) {
-
- if (!p_item->cells[p_column].selectable)
+ if (!p_item->cells[p_column].selectable) {
return;
+ }
p_item->cells.write[p_column].selected = true;
//emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select
selected_col = p_column;
} else {
-
select_single_item(p_item, root, p_column);
}
update();
}
void Tree::item_deselected(int p_column, TreeItem *p_item) {
-
if (select_mode == SELECT_MULTI || select_mode == SELECT_SINGLE) {
p_item->cells.write[p_column].selected = false;
}
@@ -3208,17 +3049,14 @@ void Tree::item_deselected(int p_column, TreeItem *p_item) {
}
void Tree::set_select_mode(SelectMode p_mode) {
-
select_mode = p_mode;
}
Tree::SelectMode Tree::get_select_mode() const {
-
return select_mode;
}
void Tree::deselect_all() {
-
TreeItem *item = get_next_selected(get_root());
while (item) {
item->deselect(selected_col);
@@ -3227,25 +3065,23 @@ void Tree::deselect_all() {
ERR_FAIL_COND(item == prev_item);
}
- selected_item = NULL;
+ selected_item = nullptr;
selected_col = -1;
update();
}
bool Tree::is_anything_selected() {
-
- return (selected_item != NULL);
+ return (selected_item != nullptr);
}
void Tree::clear() {
-
ERR_FAIL_COND(blocked > 0);
if (pressing_for_editor) {
if (range_drag_enabled) {
range_drag_enabled = false;
- InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
warp_mouse(range_drag_capture_pos);
}
pressing_for_editor = false;
@@ -3253,38 +3089,36 @@ void Tree::clear() {
if (root) {
memdelete(root);
- root = NULL;
+ root = nullptr;
};
- selected_item = NULL;
- edited_item = NULL;
- popup_edited_item = NULL;
+ selected_item = nullptr;
+ edited_item = nullptr;
+ popup_edited_item = nullptr;
update();
};
void Tree::set_hide_root(bool p_enabled) {
-
hide_root = p_enabled;
update();
}
bool Tree::is_root_hidden() const {
-
return hide_root;
}
void Tree::set_column_min_width(int p_column, int p_min_width) {
-
ERR_FAIL_INDEX(p_column, columns.size());
- if (p_min_width < 1)
+ if (p_min_width < 1) {
return;
+ }
columns.write[p_column].min_width = p_min_width;
update();
}
-void Tree::set_column_expand(int p_column, bool p_expand) {
+void Tree::set_column_expand(int p_column, bool p_expand) {
ERR_FAIL_INDEX(p_column, columns.size());
columns.write[p_column].expand = p_expand;
@@ -3292,87 +3126,80 @@ void Tree::set_column_expand(int p_column, bool p_expand) {
}
TreeItem *Tree::get_selected() const {
-
return selected_item;
}
int Tree::get_selected_column() const {
-
return selected_col;
}
TreeItem *Tree::get_edited() const {
-
return edited_item;
}
int Tree::get_edited_column() const {
-
return edited_col;
}
TreeItem *Tree::get_next_selected(TreeItem *p_item) {
-
/*
if (!p_item)
- return NULL;
+ return nullptr;
*/
- if (!root)
- return NULL;
+ if (!root) {
+ return nullptr;
+ }
while (true) {
-
if (!p_item) {
p_item = root;
} else {
-
if (p_item->children) {
-
p_item = p_item->children;
} else if (p_item->next) {
-
p_item = p_item->next;
} else {
-
while (!p_item->next) {
-
p_item = p_item->parent;
- if (p_item == NULL)
- return NULL;
+ if (p_item == nullptr) {
+ return nullptr;
+ }
}
p_item = p_item->next;
}
}
- for (int i = 0; i < columns.size(); i++)
- if (p_item->cells[i].selected)
+ for (int i = 0; i < columns.size(); i++) {
+ if (p_item->cells[i].selected) {
return p_item;
+ }
+ }
}
- return NULL;
+ return nullptr;
}
int Tree::get_column_width(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, columns.size(), -1);
- if (!columns[p_column].expand)
+ if (!columns[p_column].expand) {
return columns[p_column].min_width;
+ }
Ref<StyleBox> bg = cache.bg;
int expand_area = get_size().width - (bg->get_margin(MARGIN_LEFT) + bg->get_margin(MARGIN_RIGHT));
- if (v_scroll->is_visible_in_tree())
+ if (v_scroll->is_visible_in_tree()) {
expand_area -= v_scroll->get_combined_minimum_size().width;
+ }
int expanding_columns = 0;
int expanding_total = 0;
for (int i = 0; i < columns.size(); i++) {
-
if (!columns[i].expand) {
expand_area -= columns[i].min_width;
} else {
@@ -3381,8 +3208,9 @@ int Tree::get_column_width(int p_column) const {
}
}
- if (expand_area < expanding_total)
+ if (expand_area < expanding_total) {
return columns[p_column].min_width;
+ }
ERR_FAIL_COND_V(expanding_columns == 0, -1); // shouldn't happen
@@ -3390,56 +3218,52 @@ int Tree::get_column_width(int p_column) const {
}
void Tree::propagate_set_columns(TreeItem *p_item) {
-
p_item->cells.resize(columns.size());
TreeItem *c = p_item->get_children();
while (c) {
-
propagate_set_columns(c);
c = c->get_next();
}
}
void Tree::set_columns(int p_columns) {
-
ERR_FAIL_COND(p_columns < 1);
ERR_FAIL_COND(blocked > 0);
columns.resize(p_columns);
- if (root)
+ if (root) {
propagate_set_columns(root);
- if (selected_col >= p_columns)
+ }
+ if (selected_col >= p_columns) {
selected_col = p_columns - 1;
+ }
update();
}
int Tree::get_columns() const {
-
return columns.size();
}
void Tree::_scroll_moved(float) {
-
update();
}
Rect2 Tree::get_custom_popup_rect() const {
-
return custom_popup_rect;
}
int Tree::get_item_offset(TreeItem *p_item) const {
-
TreeItem *it = root;
int ofs = _get_title_button_height();
- if (!it)
+ if (!it) {
return 0;
+ }
while (true) {
-
- if (it == p_item)
+ if (it == p_item) {
return ofs;
+ }
ofs += compute_item_height(it);
if (it != root || !hide_root) {
@@ -3447,19 +3271,16 @@ int Tree::get_item_offset(TreeItem *p_item) const {
}
if (it->children && !it->collapsed) {
-
it = it->children;
} else if (it->next) {
-
it = it->next;
} else {
-
while (!it->next) {
-
it = it->parent;
- if (it == NULL)
+ if (it == nullptr) {
return 0;
+ }
}
it = it->next;
@@ -3516,12 +3337,10 @@ void Tree::ensure_cursor_is_visible() {
}
int Tree::get_pressed_button() const {
-
return pressed_button;
}
Rect2 Tree::get_item_rect(TreeItem *p_item, int p_column) const {
-
ERR_FAIL_NULL_V(p_item, Rect2());
ERR_FAIL_COND_V(p_item->tree != this, Rect2());
if (p_column != -1) {
@@ -3538,7 +3357,6 @@ Rect2 Tree::get_item_rect(TreeItem *p_item, int p_column) const {
r.position.x = 0;
r.size.x = get_size().width;
} else {
-
int accum = 0;
for (int i = 0; i < p_column; i++) {
accum += get_column_width(i);
@@ -3551,43 +3369,38 @@ Rect2 Tree::get_item_rect(TreeItem *p_item, int p_column) const {
}
void Tree::set_column_titles_visible(bool p_show) {
-
show_column_titles = p_show;
update();
}
bool Tree::are_column_titles_visible() const {
-
return show_column_titles;
}
void Tree::set_column_title(int p_column, const String &p_title) {
-
ERR_FAIL_INDEX(p_column, columns.size());
columns.write[p_column].title = p_title;
update();
}
String Tree::get_column_title(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, columns.size(), "");
return columns[p_column].title;
}
Point2 Tree::get_scroll() const {
-
Point2 ofs;
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
ofs.x = h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
ofs.y = v_scroll->get_value();
+ }
return ofs;
}
void Tree::scroll_to_item(TreeItem *p_item) {
-
if (!is_visible_in_tree()) {
-
// hack to work around crash in get_item_rect() if Tree is not in tree.
return;
}
@@ -3605,38 +3418,40 @@ void Tree::scroll_to_item(TreeItem *p_item) {
}
TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards) {
-
TreeItem *from = p_at;
while (p_at) {
-
for (int i = 0; i < columns.size(); i++) {
if (p_at->get_text(i).findn(p_find) == 0 && (!p_selectable || p_at->is_selectable(i))) {
- if (r_col)
+ if (r_col) {
*r_col = i;
+ }
return p_at;
}
}
- if (p_backwards)
+ if (p_backwards) {
p_at = p_at->get_prev_visible(true);
- else
+ } else {
p_at = p_at->get_next_visible(true);
+ }
- if ((p_at) == from)
+ if ((p_at) == from) {
break;
+ }
}
- return NULL;
+ return nullptr;
}
TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_selectable) {
-
TreeItem *from = get_selected();
- if (!from)
+ if (!from) {
from = root;
- if (!from)
- return NULL;
+ }
+ if (!from) {
+ return nullptr;
+ }
return _search_item_text(from->get_next_visible(true), p_find, r_col, p_selectable);
}
@@ -3649,37 +3464,35 @@ TreeItem *Tree::get_item_with_text(const String &p_find) const {
}
}
}
- return NULL;
+ return nullptr;
}
void Tree::_do_incr_search(const String &p_add) {
-
uint64_t time = OS::get_singleton()->get_ticks_usec() / 1000; // convert to msec
uint64_t diff = time - last_keypress;
- if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000)))
+ if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000))) {
incr_search = p_add;
- else if (incr_search != p_add)
+ } else if (incr_search != p_add) {
incr_search += p_add;
+ }
last_keypress = time;
int col;
TreeItem *item = search_item_text(incr_search, &col, true);
- if (!item)
+ if (!item) {
return;
+ }
item->select(col);
ensure_cursor_is_visible();
}
TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_column, int &h, int &section) const {
-
Point2 pos = p_pos;
if (root != p_item || !hide_root) {
-
h = compute_item_height(p_item) + cache.vseparation;
if (pos.y < h) {
-
if (drop_mode_flags == DROP_MODE_ON_ITEM) {
section = 0;
} else if (drop_mode_flags == DROP_MODE_INBETWEEN) {
@@ -3693,7 +3506,6 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
}
for (int i = 0; i < columns.size(); i++) {
-
int w = get_column_width(i);
if (pos.x < w) {
r_column = i;
@@ -3703,48 +3515,48 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
pos.x -= w;
}
- return NULL;
+ return nullptr;
} else {
-
pos.y -= h;
}
} else {
-
h = 0;
}
- if (p_item->is_collapsed())
- return NULL; // do not try children, it's collapsed
+ if (p_item->is_collapsed()) {
+ return nullptr; // do not try children, it's collapsed
+ }
TreeItem *n = p_item->get_children();
while (n) {
-
int ch;
TreeItem *r = _find_item_at_pos(n, pos, r_column, ch, section);
pos.y -= ch;
h += ch;
- if (r)
+ if (r) {
return r;
+ }
n = n->get_next();
}
- return NULL;
+ return nullptr;
}
int Tree::get_column_at_position(const Point2 &p_pos) const {
-
if (root) {
-
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return -1;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3758,19 +3570,20 @@ int Tree::get_column_at_position(const Point2 &p_pos) const {
}
int Tree::get_drop_section_at_position(const Point2 &p_pos) const {
-
if (root) {
-
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return -100;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
@@ -3782,58 +3595,60 @@ int Tree::get_drop_section_at_position(const Point2 &p_pos) const {
return -100;
}
-TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const {
+TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const {
if (root) {
-
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
- return NULL;
+ if (pos.y < 0) {
+ return nullptr;
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
if (it) {
-
return it;
}
}
- return NULL;
+ return nullptr;
}
String Tree::get_tooltip(const Point2 &p_pos) const {
-
if (root) {
-
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
- if (pos.y < 0)
+ if (pos.y < 0) {
return Control::get_tooltip(p_pos);
+ }
- if (h_scroll->is_visible_in_tree())
+ if (h_scroll->is_visible_in_tree()) {
pos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
+ }
+ if (v_scroll->is_visible_in_tree()) {
pos.y += v_scroll->get_value();
+ }
int col, h, section;
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
if (it) {
-
const TreeItem::Cell &c = it->cells[col];
int col_width = get_column_width(col);
- for (int i = 0; i < col; i++)
+ for (int i = 0; i < col; i++) {
pos.x -= get_column_width(i);
+ }
for (int j = c.buttons.size() - 1; j >= 0; j--) {
Ref<Texture2D> b = c.buttons[j].texture;
@@ -3847,10 +3662,11 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
col_width -= size.width;
}
String ret;
- if (it->get_tooltip(col) == "")
+ if (it->get_tooltip(col) == "") {
ret = it->get_text(col);
- else
+ } else {
ret = it->get_tooltip(col);
+ }
return ret;
}
}
@@ -3859,12 +3675,10 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
}
void Tree::set_cursor_can_exit_tree(bool p_enable) {
-
cursor_can_exit_tree = p_enable;
}
bool Tree::can_cursor_exit_tree() const {
-
return cursor_can_exit_tree;
}
@@ -3874,43 +3688,38 @@ void Tree::set_hide_folding(bool p_hide) {
}
bool Tree::is_folding_hidden() const {
-
return hide_folding;
}
void Tree::set_drop_mode_flags(int p_flags) {
- if (drop_mode_flags == p_flags)
+ if (drop_mode_flags == p_flags) {
return;
+ }
drop_mode_flags = p_flags;
if (drop_mode_flags == 0) {
- drop_mode_over = NULL;
+ drop_mode_over = nullptr;
}
update();
}
int Tree::get_drop_mode_flags() const {
-
return drop_mode_flags;
}
void Tree::set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable) {
-
force_edit_checkbox_only_on_checkbox = p_enable;
}
bool Tree::get_edit_checkbox_cell_only_when_checkbox_is_pressed() const {
-
return force_edit_checkbox_only_on_checkbox;
}
void Tree::set_allow_rmb_select(bool p_allow) {
-
allow_rmb_select = p_allow;
}
bool Tree::get_allow_rmb_select() const {
-
return allow_rmb_select;
}
@@ -3919,12 +3728,10 @@ void Tree::set_allow_reselect(bool p_allow) {
}
bool Tree::get_allow_reselect() const {
-
return allow_reselect;
}
void Tree::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_gui_input"), &Tree::_gui_input);
ClassDB::bind_method(D_METHOD("clear"), &Tree::clear);
@@ -4012,20 +3819,19 @@ void Tree::_bind_methods() {
}
Tree::Tree() {
-
selected_col = 0;
columns.resize(1);
- selected_item = NULL;
- edited_item = NULL;
+ selected_item = nullptr;
+ edited_item = nullptr;
selected_col = -1;
edited_col = -1;
hide_root = false;
select_mode = SELECT_SINGLE;
- root = 0;
- popup_menu = NULL;
- popup_edited_item = NULL;
- text_editor = NULL;
+ root = nullptr;
+ popup_menu = nullptr;
+ popup_edited_item = nullptr;
+ text_editor = nullptr;
set_focus_mode(FOCUS_ALL);
popup_menu = memnew(PopupMenu);
@@ -4078,7 +3884,7 @@ Tree::Tree() {
cache.hover_index = -1;
cache.click_index = -1;
cache.click_id = -1;
- cache.click_item = NULL;
+ cache.click_item = nullptr;
cache.click_column = 0;
cache.hover_cell = -1;
last_keypress = 0;
@@ -4098,9 +3904,9 @@ Tree::Tree() {
hide_folding = false;
drop_mode_flags = 0;
- drop_mode_over = NULL;
+ drop_mode_over = nullptr;
drop_mode_section = 0;
- single_select_defer = NULL;
+ single_select_defer = nullptr;
scrolling = false;
allow_rmb_select = false;
@@ -4108,7 +3914,7 @@ Tree::Tree() {
set_clip_contents(true);
- cache.hover_item = NULL;
+ cache.hover_item = nullptr;
cache.hover_cell = -1;
allow_reselect = false;
@@ -4116,7 +3922,6 @@ Tree::Tree() {
}
Tree::~Tree() {
-
if (root) {
memdelete(root);
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index becbe76598..46842e78a0 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -40,7 +40,6 @@
class Tree;
class TreeItem : public Object {
-
GDCLASS(TreeItem, Object);
public:
@@ -63,7 +62,6 @@ private:
friend class Tree;
struct Cell {
-
TreeCellMode mode;
Ref<Texture2D> icon;
@@ -111,7 +109,6 @@ private:
Vector<Button> buttons;
Cell() {
-
custom_draw_obj = ObjectID();
custom_button = false;
mode = TreeItem::CELL_MODE_STRING;
@@ -293,7 +290,6 @@ VARIANT_ENUM_CAST(TreeItem::TextAlign);
class VBoxContainer;
class Tree : public Control {
-
GDCLASS(Tree, Control);
public:
@@ -350,7 +346,6 @@ private:
int drop_mode_flags;
struct ColumnInfo {
-
int min_width;
bool expand;
String title;
@@ -383,7 +378,7 @@ private:
//void draw_item_text(String p_text,const Ref<Texture2D>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color);
void draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color, const Color &p_icon_color);
int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item);
- void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = NULL, bool *r_in_range = NULL, bool p_force_deselect = false);
+ void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = nullptr, bool *r_in_range = nullptr, bool p_force_deselect = false);
int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod);
void _text_editor_enter(String p_text);
void _text_editor_modal_close();
@@ -404,7 +399,6 @@ private:
void propagate_set_columns(TreeItem *p_item);
struct Cache {
-
Ref<Font> font;
Ref<Font> tb_font;
Ref<StyleBox> bg;
@@ -544,7 +538,7 @@ public:
void clear();
- TreeItem *create_item(TreeItem *p_parent = 0, int p_idx = -1);
+ TreeItem *create_item(TreeItem *p_parent = nullptr, int p_idx = -1);
TreeItem *get_root();
TreeItem *get_last_item();
@@ -584,7 +578,7 @@ public:
bool edit_selected();
// First item that starts with the text, from the current focused item down and wraps around.
- TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false);
+ TreeItem *search_item_text(const String &p_find, int *r_col = nullptr, bool p_selectable = false);
// First item that matches the whole text, from the first item down.
TreeItem *get_item_with_text(const String &p_find) const;
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index ac1e4a5629..881df06d8f 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -35,7 +35,6 @@
#include "servers/audio_server.h"
int VideoPlayer::sp_get_channel_count() const {
-
if (playback.is_null()) {
return 0;
}
@@ -44,7 +43,6 @@ int VideoPlayer::sp_get_channel_count() const {
}
bool VideoPlayer::mix(AudioFrame *p_buffer, int p_frames) {
-
// Check the amount resampler can really handle.
// If it cannot, wait "wait_resampler_phase_limit" times.
// This mechanism contributes to smoother pause/unpause operation.
@@ -59,7 +57,6 @@ bool VideoPlayer::mix(AudioFrame *p_buffer, int p_frames) {
// Called from main thread (eg VideoStreamPlaybackWebm::update)
int VideoPlayer::_audio_mix_callback(void *p_udata, const float *p_data, int p_frames) {
-
ERR_FAIL_NULL_V(p_udata, 0);
ERR_FAIL_NULL_V(p_data, 0);
@@ -79,14 +76,12 @@ int VideoPlayer::_audio_mix_callback(void *p_udata, const float *p_data, int p_f
}
void VideoPlayer::_mix_audios(void *p_self) {
-
ERR_FAIL_NULL(p_self);
reinterpret_cast<VideoPlayer *>(p_self)->_mix_audio();
}
// Called from audio thread
void VideoPlayer::_mix_audio() {
-
if (!stream.is_valid()) {
return;
}
@@ -98,8 +93,9 @@ void VideoPlayer::_mix_audio() {
int buffer_size = mix_buffer.size();
// Resample
- if (!mix(buffer, buffer_size))
+ if (!mix(buffer, buffer_size)) {
return;
+ }
AudioFrame vol = AudioFrame(volume, volume);
@@ -110,7 +106,6 @@ void VideoPlayer::_mix_audio() {
ERR_FAIL_COND(!target);
for (int j = 0; j < buffer_size; j++) {
-
target[j] += buffer[j] * vol;
}
@@ -123,7 +118,6 @@ void VideoPlayer::_mix_audio() {
}
for (int j = 0; j < buffer_size; j++) {
-
AudioFrame frame = buffer[j] * vol;
for (int k = 0; k < cc; k++) {
targets[k][j] += frame;
@@ -133,11 +127,8 @@ void VideoPlayer::_mix_audio() {
}
void VideoPlayer::_notification(int p_notification) {
-
switch (p_notification) {
-
case NOTIFICATION_ENTER_TREE: {
-
AudioServer::get_singleton()->add_callback(_mix_audios, this);
if (stream.is_valid() && autoplay && !Engine::get_singleton()->is_editor_hint()) {
@@ -147,25 +138,25 @@ void VideoPlayer::_notification(int p_notification) {
} break;
case NOTIFICATION_EXIT_TREE: {
-
AudioServer::get_singleton()->remove_callback(_mix_audios, this);
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
-
bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus);
- if (stream.is_null() || paused || playback.is_null() || !playback->is_playing())
+ if (stream.is_null() || paused || playback.is_null() || !playback->is_playing()) {
return;
+ }
double audio_time = USEC_TO_SEC(OS::get_singleton()->get_ticks_usec());
double delta = last_audio_time == 0 ? 0 : audio_time - last_audio_time;
last_audio_time = audio_time;
- if (delta == 0)
+ if (delta == 0) {
return;
+ }
playback->update(delta); // playback->is_playing() returns false in the last video frame
@@ -176,11 +167,12 @@ void VideoPlayer::_notification(int p_notification) {
} break;
case NOTIFICATION_DRAW: {
-
- if (texture.is_null())
+ if (texture.is_null()) {
return;
- if (texture->get_width() == 0)
+ }
+ if (texture->get_width() == 0) {
return;
+ }
Size2 s = expand ? get_size() : texture->get_size();
draw_texture_rect(texture, Rect2(Point2(), s), false);
@@ -190,27 +182,24 @@ void VideoPlayer::_notification(int p_notification) {
};
Size2 VideoPlayer::get_minimum_size() const {
-
- if (!expand && !texture.is_null())
+ if (!expand && !texture.is_null()) {
return texture->get_size();
- else
+ } else {
return Size2();
+ }
}
void VideoPlayer::set_expand(bool p_expand) {
-
expand = p_expand;
update();
minimum_size_changed();
}
bool VideoPlayer::has_expand() const {
-
return expand;
}
void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
-
stop();
AudioServer::get_singleton()->lock();
mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
@@ -232,14 +221,16 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
const int channels = playback->get_channels();
AudioServer::get_singleton()->lock();
- if (channels > 0)
+ if (channels > 0) {
resampler.setup(channels, playback->get_mix_rate(), AudioServer::get_singleton()->get_mix_rate(), buffering_ms, 0);
- else
+ } else {
resampler.clear();
+ }
AudioServer::get_singleton()->unlock();
- if (channels > 0)
+ if (channels > 0) {
playback->set_mix_callback(_audio_mix_callback, this);
+ }
} else {
texture.unref();
@@ -256,15 +247,14 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
};
Ref<VideoStream> VideoPlayer::get_stream() const {
-
return stream;
};
void VideoPlayer::play() {
-
ERR_FAIL_COND(!is_inside_tree());
- if (playback.is_null())
+ if (playback.is_null()) {
return;
+ }
playback->stop();
playback->play();
set_process_internal(true);
@@ -274,11 +264,12 @@ void VideoPlayer::play() {
};
void VideoPlayer::stop() {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
- if (playback.is_null())
+ }
+ if (playback.is_null()) {
return;
+ }
playback->stop();
// AudioServer::get_singleton()->stream_set_active(stream_rid,false);
@@ -288,15 +279,14 @@ void VideoPlayer::stop() {
};
bool VideoPlayer::is_playing() const {
-
- if (playback.is_null())
+ if (playback.is_null()) {
return false;
+ }
return playback->is_playing();
};
void VideoPlayer::set_paused(bool p_paused) {
-
paused = p_paused;
if (playback.is_valid()) {
playback->set_paused(p_paused);
@@ -306,17 +296,14 @@ void VideoPlayer::set_paused(bool p_paused) {
};
bool VideoPlayer::is_paused() const {
-
return paused;
}
void VideoPlayer::set_buffering_msec(int p_msec) {
-
buffering_ms = p_msec;
}
int VideoPlayer::get_buffering_msec() const {
-
return buffering_ms;
}
@@ -325,76 +312,70 @@ void VideoPlayer::set_audio_track(int p_track) {
}
int VideoPlayer::get_audio_track() const {
-
return audio_track;
}
void VideoPlayer::set_volume(float p_vol) {
-
volume = p_vol;
};
float VideoPlayer::get_volume() const {
-
return volume;
};
void VideoPlayer::set_volume_db(float p_db) {
-
- if (p_db < -79)
+ if (p_db < -79) {
set_volume(0);
- else
+ } else {
set_volume(Math::db2linear(p_db));
+ }
};
float VideoPlayer::get_volume_db() const {
-
- if (volume == 0)
+ if (volume == 0) {
return -80;
- else
+ } else {
return Math::linear2db(volume);
+ }
};
String VideoPlayer::get_stream_name() const {
-
- if (stream.is_null())
+ if (stream.is_null()) {
return "<No Stream>";
+ }
return stream->get_name();
};
float VideoPlayer::get_stream_position() const {
-
- if (playback.is_null())
+ if (playback.is_null()) {
return 0;
+ }
return playback->get_playback_position();
};
void VideoPlayer::set_stream_position(float p_position) {
-
- if (playback.is_valid())
+ if (playback.is_valid()) {
playback->seek(p_position);
+ }
}
Ref<Texture2D> VideoPlayer::get_video_texture() const {
-
- if (playback.is_valid())
+ if (playback.is_valid()) {
return playback->get_texture();
+ }
return Ref<Texture2D>();
}
void VideoPlayer::set_autoplay(bool p_enable) {
-
autoplay = p_enable;
};
bool VideoPlayer::has_autoplay() const {
-
return autoplay;
};
void VideoPlayer::set_bus(const StringName &p_bus) {
-
//if audio is active, must lock this
AudioServer::get_singleton()->lock();
bus = p_bus;
@@ -402,7 +383,6 @@ void VideoPlayer::set_bus(const StringName &p_bus) {
}
StringName VideoPlayer::get_bus() const {
-
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
if (AudioServer::get_singleton()->get_bus_name(i) == bus) {
return bus;
@@ -412,13 +392,12 @@ StringName VideoPlayer::get_bus() const {
}
void VideoPlayer::_validate_property(PropertyInfo &p_property) const {
-
if (p_property.name == "bus") {
-
String options;
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
- if (i > 0)
+ if (i > 0) {
options += ",";
+ }
String name = AudioServer::get_singleton()->get_bus_name(i);
options += name;
}
@@ -428,7 +407,6 @@ void VideoPlayer::_validate_property(PropertyInfo &p_property) const {
}
void VideoPlayer::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_stream", "stream"), &VideoPlayer::set_stream);
ClassDB::bind_method(D_METHOD("get_stream"), &VideoPlayer::get_stream);
@@ -485,7 +463,6 @@ void VideoPlayer::_bind_methods() {
}
VideoPlayer::VideoPlayer() {
-
volume = 1;
loops = false;
paused = false;
@@ -506,7 +483,6 @@ VideoPlayer::VideoPlayer() {
};
VideoPlayer::~VideoPlayer() {
-
// if (stream_rid.is_valid())
// AudioServer::get_singleton()->free(stream_rid);
resampler.clear(); //Not necessary here, but make in consistent with other "stream_player" classes
diff --git a/scene/gui/video_player.h b/scene/gui/video_player.h
index 78e7fa05f8..551c079b3c 100644
--- a/scene/gui/video_player.h
+++ b/scene/gui/video_player.h
@@ -37,11 +37,9 @@
#include "servers/audio_server.h"
class VideoPlayer : public Control {
-
GDCLASS(VideoPlayer, Control);
struct Output {
-
AudioFrame vol;
int bus_index;
Viewport *viewport; //pointer only used for reference to previous mix