summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp45
-rw-r--r--scene/gui/base_button.h3
-rw-r--r--scene/gui/box_container.cpp15
-rw-r--r--scene/gui/box_container.h3
-rw-r--r--scene/gui/button.cpp27
-rw-r--r--scene/gui/button.h1
-rw-r--r--scene/gui/center_container.cpp9
-rw-r--r--scene/gui/center_container.h1
-rw-r--r--scene/gui/check_box.cpp5
-rw-r--r--scene/gui/check_box.h1
-rw-r--r--scene/gui/check_button.cpp6
-rw-r--r--scene/gui/check_button.h1
-rw-r--r--scene/gui/color_picker.cpp53
-rw-r--r--scene/gui/color_picker.h2
-rw-r--r--scene/gui/color_rect.cpp5
-rw-r--r--scene/gui/container.cpp15
-rw-r--r--scene/gui/container.h1
-rw-r--r--scene/gui/control.cpp212
-rw-r--r--scene/gui/control.h3
-rw-r--r--scene/gui/dialogs.cpp24
-rw-r--r--scene/gui/dialogs.h2
-rw-r--r--scene/gui/file_dialog.cpp78
-rw-r--r--scene/gui/file_dialog.h1
-rw-r--r--scene/gui/gradient_edit.cpp18
-rw-r--r--scene/gui/gradient_edit.h1
-rw-r--r--scene/gui/graph_edit.cpp104
-rw-r--r--scene/gui/graph_edit.h3
-rw-r--r--scene/gui/graph_node.cpp52
-rw-r--r--scene/gui/graph_node.h1
-rw-r--r--scene/gui/grid_container.cpp9
-rw-r--r--scene/gui/grid_container.h1
-rw-r--r--scene/gui/item_list.cpp126
-rw-r--r--scene/gui/item_list.h2
-rw-r--r--scene/gui/label.cpp58
-rw-r--r--scene/gui/label.h2
-rw-r--r--scene/gui/line_edit.cpp101
-rw-r--r--scene/gui/line_edit.h2
-rw-r--r--scene/gui/link_button.cpp14
-rw-r--r--scene/gui/link_button.h1
-rw-r--r--scene/gui/margin_container.cpp6
-rw-r--r--scene/gui/menu_button.cpp14
-rw-r--r--scene/gui/menu_button.h1
-rw-r--r--scene/gui/nine_patch_rect.cpp15
-rw-r--r--scene/gui/nine_patch_rect.h1
-rw-r--r--scene/gui/option_button.cpp39
-rw-r--r--scene/gui/option_button.h1
-rw-r--r--scene/gui/panel.cpp2
-rw-r--r--scene/gui/panel.h1
-rw-r--r--scene/gui/panel_container.cpp6
-rw-r--r--scene/gui/panel_container.h1
-rw-r--r--scene/gui/popup.cpp12
-rw-r--r--scene/gui/popup.h2
-rw-r--r--scene/gui/popup_menu.cpp131
-rw-r--r--scene/gui/popup_menu.h1
-rw-r--r--scene/gui/progress_bar.cpp8
-rw-r--r--scene/gui/progress_bar.h1
-rw-r--r--scene/gui/range.cpp34
-rw-r--r--scene/gui/range.h1
-rw-r--r--scene/gui/reference_rect.cpp2
-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.cpp175
-rw-r--r--scene/gui/rich_text_label.h3
-rw-r--r--scene/gui/scroll_bar.cpp64
-rw-r--r--scene/gui/scroll_bar.h4
-rw-r--r--scene/gui/scroll_container.cpp42
-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.cpp6
-rw-r--r--scene/gui/shortcut.h1
-rw-r--r--scene/gui/slider.cpp27
-rw-r--r--scene/gui/slider.h3
-rw-r--r--scene/gui/spin_box.cpp33
-rw-r--r--scene/gui/spin_box.h1
-rw-r--r--scene/gui/split_container.cpp35
-rw-r--r--scene/gui/split_container.h3
-rw-r--r--scene/gui/subviewport_container.cpp20
-rw-r--r--scene/gui/subviewport_container.h1
-rw-r--r--scene/gui/tab_container.cpp56
-rw-r--r--scene/gui/tab_container.h1
-rw-r--r--scene/gui/tabs.cpp58
-rw-r--r--scene/gui/tabs.h2
-rw-r--r--scene/gui/text_edit.cpp321
-rw-r--r--scene/gui/text_edit.h7
-rw-r--r--scene/gui/texture_button.cpp22
-rw-r--r--scene/gui/texture_button.h1
-rw-r--r--scene/gui/texture_progress.cpp10
-rw-r--r--scene/gui/texture_progress.h1
-rw-r--r--scene/gui/texture_rect.cpp16
-rw-r--r--scene/gui/texture_rect.h1
-rw-r--r--scene/gui/tree.cpp345
-rw-r--r--scene/gui/tree.h6
-rw-r--r--scene/gui/video_player.cpp43
-rw-r--r--scene/gui/video_player.h2
95 files changed, 0 insertions, 2611 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 1cdc6f8057..79e1102f6b 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -35,7 +35,6 @@
#include "scene/scene_string_names.h"
void BaseButton::_unpress_group() {
-
if (!button_group.is_valid())
return;
@@ -52,7 +51,6 @@ void BaseButton::_unpress_group() {
}
void BaseButton::_gui_input(Ref<InputEvent> p_event) {
-
if (status.disabled) // no interaction with disabled button
return;
@@ -78,9 +76,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 +86,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 +93,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 +109,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 +119,6 @@ void BaseButton::_notification(int p_what) {
}
void BaseButton::_pressed() {
-
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_pressed);
}
@@ -136,7 +127,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 +135,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;
@@ -210,12 +199,10 @@ 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)
return;
if (status.pressed == p_pressed)
@@ -232,22 +219,18 @@ 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;
};
@@ -262,12 +245,10 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
bool pressing;
if (status.press_attempt) {
-
pressing = (status.pressing_inside || keep_pressed_outside);
if (status.pressed)
pressing = !pressing;
} else {
-
pressing = status.pressed;
}
@@ -281,47 +262,38 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const {
}
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 +301,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 +322,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 +340,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 +354,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 +414,6 @@ void BaseButton::_bind_methods() {
}
BaseButton::BaseButton() {
-
toggle_mode = false;
shortcut_in_tooltip = true;
keep_pressed_outside = false;
@@ -468,21 +429,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,7 +450,6 @@ 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())
return E->get();
@@ -502,12 +459,10 @@ BaseButton *ButtonGroup::get_pressed_button() {
}
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..5252f3f2f2 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();
@@ -105,7 +103,6 @@ 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())
continue;
@@ -158,7 +155,6 @@ 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())
continue;
@@ -187,10 +183,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 +196,6 @@ void BoxContainer::_resort() {
}
Size2 BoxContainer::get_minimum_size() const {
-
/* Calculate MINIMUM SIZE */
Size2i minimum;
@@ -247,15 +240,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,7 +260,6 @@ 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
@@ -286,13 +274,11 @@ void BoxContainer::add_spacer(bool p_begin) {
}
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 +291,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);
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 1f8487c173..cf1ff059bf 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -34,7 +34,6 @@
#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)
minsize.width = 0;
@@ -47,7 +46,6 @@ Size2 Button::get_minimum_size() const {
_icon = icon;
if (!_icon.is_null()) {
-
minsize.height = MAX(minsize.height, _icon->get_height());
minsize.width += _icon->get_width();
if (xl_text != "")
@@ -59,21 +57,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,7 +77,6 @@ void Button::_notification(int p_what) {
switch (get_draw_mode()) {
case DRAW_NORMAL: {
-
style = get_theme_stylebox("normal");
if (!flat)
style->draw(ci, Rect2(Point2(0, 0), size));
@@ -92,7 +85,6 @@ void Button::_notification(int p_what) {
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)
@@ -109,7 +101,6 @@ void Button::_notification(int p_what) {
[[fallthrough]];
}
case DRAW_PRESSED: {
-
style = get_theme_stylebox("pressed");
if (!flat)
style->draw(ci, Rect2(Point2(0, 0), size));
@@ -122,7 +113,6 @@ void Button::_notification(int p_what) {
} break;
case DRAW_HOVER: {
-
style = get_theme_stylebox("hover");
if (!flat)
style->draw(ci, Rect2(Point2(0, 0), size));
@@ -132,7 +122,6 @@ void Button::_notification(int p_what) {
} break;
case DRAW_DISABLED: {
-
style = get_theme_stylebox("disabled");
if (!flat)
style->draw(ci, Rect2(Point2(0, 0), size));
@@ -144,7 +133,6 @@ void Button::_notification(int p_what) {
}
if (has_focus()) {
-
Ref<StyleBox> style2 = get_theme_stylebox("focus");
style2->draw(ci, Rect2(Point2(), size));
}
@@ -158,7 +146,6 @@ void Button::_notification(int p_what) {
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;
@@ -235,7 +222,6 @@ void Button::_notification(int p_what) {
}
void Button::set_text(const String &p_text) {
-
if (text == p_text)
return;
text = p_text;
@@ -245,12 +231,10 @@ void Button::set_text(const String &p_text) {
minimum_size_changed();
}
String Button::get_text() const {
-
return text;
}
void Button::set_icon(const Ref<Texture2D> &p_icon) {
-
if (icon == p_icon)
return;
icon = p_icon;
@@ -260,59 +244,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 +313,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..ff2b5ea17e 100644
--- a/scene/gui/center_container.cpp
+++ b/scene/gui/center_container.cpp
@@ -31,12 +31,10 @@
#include "center_container.h"
Size2 CenterContainer::get_minimum_size() const {
-
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)
continue;
@@ -53,7 +51,6 @@ Size2 CenterContainer::get_minimum_size() const {
}
void CenterContainer::set_use_top_left(bool p_enable) {
-
if (use_top_left == p_enable) {
return;
}
@@ -65,17 +62,13 @@ 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)
continue;
@@ -90,7 +83,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 +90,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 470450e3ed..8681b9bda7 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -51,7 +51,6 @@ Size2 CheckBox::get_icon_size() const {
}
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 +64,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");
@@ -89,7 +85,6 @@ void CheckBox::_notification(int p_what) {
}
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 96484424f8..041a28a0be 100644
--- a/scene/gui/check_button.cpp
+++ b/scene/gui/check_button.cpp
@@ -34,7 +34,6 @@
#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);
@@ -47,7 +46,6 @@ Size2 CheckButton::get_icon_size() const {
}
Size2 CheckButton::get_minimum_size() const {
-
Size2 minsize = Button::get_minimum_size();
Size2 tex_size = get_icon_size();
minsize.width += tex_size.width;
@@ -60,12 +58,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");
@@ -86,7 +81,6 @@ void CheckButton::_notification(int p_what) {
}
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 63878a0b26..1730df6bb3 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -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,18 +65,15 @@ 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"));
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
Popup *p = Object::cast_to<Popup>(get_parent());
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 != nullptr && screen->is_visible())
screen->hide();
} break;
@@ -87,12 +81,10 @@ void ColorPicker::_notification(int p_what) {
}
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" };
@@ -127,7 +119,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();
@@ -143,12 +134,10 @@ void ColorPicker::_set_pick_color(const Color &p_color, bool 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();
@@ -160,12 +149,10 @@ void ColorPicker::set_edit_alpha(bool p_show) {
}
bool ColorPicker::is_editing_alpha() const {
-
return edit_alpha;
}
void ColorPicker::_value_changed(double) {
-
if (updating)
return;
@@ -185,7 +172,6 @@ void ColorPicker::_value_changed(double) {
}
void ColorPicker::_html_entered(const String &p_html) {
-
if (updating || text_is_constructor || !c_text->is_visible())
return;
@@ -202,11 +188,9 @@ void ColorPicker::_html_entered(const String &p_html) {
}
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);
@@ -266,7 +250,6 @@ void ColorPicker::_update_presets() {
}
void ColorPicker::_text_type_toggled() {
-
text_is_constructor = !text_is_constructor;
if (text_is_constructor) {
text_type->set_text("");
@@ -283,12 +266,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 +286,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 +300,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,7 +309,6 @@ PackedColorArray ColorPicker::get_presets() const {
}
void ColorPicker::set_hsv_mode(bool p_enabled) {
-
if (hsv_mode_enabled == p_enabled || raw_mode_enabled)
return;
hsv_mode_enabled = p_enabled;
@@ -345,12 +323,10 @@ void ColorPicker::set_hsv_mode(bool p_enabled) {
}
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)
return;
raw_mode_enabled = p_enabled;
@@ -365,7 +341,6 @@ void ColorPicker::set_raw_mode(bool p_enabled) {
}
bool ColorPicker::is_raw_mode() const {
-
return raw_mode_enabled;
}
@@ -458,7 +433,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()) {
@@ -501,11 +475,9 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event) {
}
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);
@@ -526,7 +498,6 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mev = p_event;
if (mev.is_valid()) {
-
if (!changing_color)
return;
float y = CLAMP((float)mev->get_position().y, 0, w_edit->get_size().height);
@@ -541,7 +512,6 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
}
void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
-
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid()) {
@@ -569,7 +539,6 @@ 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;
@@ -581,7 +550,6 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
}
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);
@@ -596,7 +564,6 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
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);
@@ -688,7 +655,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 +688,6 @@ void ColorPicker::_bind_methods() {
ColorPicker::ColorPicker() :
BoxContainer(true) {
-
updating = true;
edit_alpha = true;
text_is_constructor = false;
@@ -779,7 +744,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 +790,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 +835,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 +863,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 +876,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,7 +889,6 @@ void ColorPickerButton::_notification(int p_what) {
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
-
if (popup)
popup->hide();
} break;
@@ -947,7 +902,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);
@@ -956,12 +910,10 @@ void ColorPickerButton::set_pick_color(const Color &p_color) {
update();
}
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 +921,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 +953,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,7 +968,6 @@ 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.
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..5bde293648 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,7 +40,6 @@ 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);
@@ -57,7 +55,6 @@ 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))
@@ -68,7 +65,6 @@ void Container::move_child_notify(Node *p_child) {
}
void Container::remove_child_notify(Node *p_child) {
-
Control::remove_child_notify(p_child);
Control *control = Object::cast_to<Control>(p_child);
@@ -84,7 +80,6 @@ void Container::remove_child_notify(Node *p_child) {
}
void Container::_sort_children() {
-
if (!is_inside_tree())
return;
@@ -94,7 +89,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);
@@ -133,7 +127,6 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
}
void Container::queue_sort() {
-
if (!is_inside_tree())
return;
@@ -145,23 +138,18 @@ void Container::queue_sort() {
}
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 +158,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,7 +170,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);
@@ -194,7 +180,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 b710ba4803..3dbdd4dfab 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -49,7 +49,6 @@
#ifdef TOOLS_ENABLED
Dictionary Control::_edit_get_state() const {
-
Dictionary s;
s["rotation"] = get_rotation();
s["scale"] = get_scale();
@@ -70,7 +69,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,7 +160,6 @@ 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)
return;
data.custom_minimum_size = p_custom;
@@ -170,12 +167,10 @@ void Control::set_custom_minimum_size(const Size2 &p_custom) {
}
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);
@@ -192,7 +187,6 @@ void Control::_update_minimum_size_cache() {
}
Size2 Control::get_combined_minimum_size() const {
-
if (!data.minimum_size_valid) {
const_cast<Control *>(this)->_update_minimum_size_cache();
}
@@ -200,7 +194,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 +203,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)) {
@@ -283,7 +274,6 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
}
void Control::_update_minimum_size() {
-
if (!is_inside_tree())
return;
@@ -302,7 +292,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")) {
@@ -338,7 +327,6 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const {
return true;
}
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,7 +341,6 @@ 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()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
@@ -365,7 +352,6 @@ 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()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
@@ -377,7 +363,6 @@ 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()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
@@ -389,7 +374,6 @@ 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()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
@@ -401,7 +385,6 @@ 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()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
@@ -413,7 +396,6 @@ 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()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
@@ -424,19 +406,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,7 +430,6 @@ 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()) {
@@ -466,7 +444,6 @@ void Control::remove_child_notify(Node *p_child) {
}
void Control::_update_canvas_item_transform() {
-
Transform2D xform = _get_internal_transform();
xform[2] += get_position();
@@ -474,24 +451,19 @@ void Control::_update_canvas_item_transform() {
}
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
@@ -499,7 +471,6 @@ void Control::_notification(int p_notification) {
bool subwindow = false;
while (parent) {
-
parent = parent->get_parent();
if (!parent)
@@ -516,7 +487,6 @@ void Control::_notification(int p_notification) {
if (parent_control) {
break;
} else if (ci) {
-
} else {
break;
}
@@ -536,7 +506,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,9 +513,7 @@ 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 = nullptr;
} else if (!is_set_as_toplevel()) {
@@ -576,11 +543,9 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_RESIZED: {
-
emit_signal(SceneStringNames::get_singleton()->resized);
} break;
case NOTIFICATION_DRAW: {
-
_update_canvas_item_transform();
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);
@@ -588,33 +553,26 @@ void Control::_notification(int p_notification) {
} 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() != nullptr)
get_viewport()->_gui_hid_control(this);
@@ -630,14 +588,12 @@ 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 {
-
if (get_script_instance()) {
Variant v = p_point;
const Variant *p = &v;
@@ -655,7 +611,6 @@ bool Control::has_point(const Point2 &p_point) const {
}
void Control::set_drag_forwarding(Control *p_target) {
-
if (p_target)
data.drag_owner = p_target->get_instance_id();
else
@@ -663,7 +618,6 @@ void Control::set_drag_forwarding(Control *p_target) {
}
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) {
@@ -685,7 +639,6 @@ Variant Control::get_drag_data(const Point2 &p_point) {
}
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) {
@@ -706,7 +659,6 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const
return Variant();
}
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,7 +679,6 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
}
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);
@@ -735,17 +686,14 @@ 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, nullptr, 0, ce);
if (ce.error == Callable::CallError::CALL_OK)
@@ -756,13 +704,11 @@ Size2 Control::get_minimum_size() const {
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()) {
@@ -792,7 +738,6 @@ 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 = nullptr;
theme_owner_window = nullptr;
}
@@ -802,13 +747,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()) {
@@ -836,7 +779,6 @@ 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 = nullptr;
theme_owner_window = nullptr;
}
@@ -846,9 +788,7 @@ 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)
return *tex;
@@ -860,7 +800,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)) {
@@ -877,9 +816,7 @@ 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)
return *sdr;
@@ -891,7 +828,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)) {
@@ -908,7 +844,6 @@ 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)
@@ -921,7 +856,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)) {
@@ -938,7 +872,6 @@ 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)
@@ -951,7 +884,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)) {
@@ -968,7 +900,6 @@ 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)
@@ -981,7 +912,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)) {
@@ -997,7 +927,6 @@ 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)
@@ -1010,7 +939,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)) {
@@ -1026,43 +954,36 @@ 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 != nullptr;
}
bool Control::has_theme_shader_override(const StringName &p_name) const {
-
const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
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 != nullptr;
}
bool Control::has_theme_font_override(const StringName &p_name) const {
-
const Ref<Font> *font = data.font_override.getptr(p_name);
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 != nullptr;
}
bool Control::has_theme_constant_override(const StringName &p_name) const {
-
const int *constant = data.constant_override.getptr(p_name);
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))
return true;
@@ -1074,7 +995,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;
}
@@ -1088,7 +1008,6 @@ 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))
return true;
@@ -1099,7 +1018,6 @@ bool Control::has_theme_shader(const StringName &p_name, const StringName &p_typ
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) {
-
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_shader, p_name, p_type)) {
return true;
}
@@ -1113,7 +1031,6 @@ 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))
return true;
@@ -1125,7 +1042,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;
}
@@ -1139,7 +1055,6 @@ 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))
return true;
@@ -1150,7 +1065,6 @@ bool Control::has_theme_font(const StringName &p_name, const StringName &p_type)
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) {
-
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_font, p_name, p_type)) {
return true;
}
@@ -1164,7 +1078,6 @@ 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))
return true;
@@ -1175,7 +1088,6 @@ bool Control::has_theme_color(const StringName &p_name, const StringName &p_type
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) {
-
if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_color, p_name, p_type)) {
return true;
}
@@ -1189,7 +1101,6 @@ 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))
return true;
@@ -1201,7 +1112,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;
}
@@ -1229,18 +1139,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);
}
@@ -1293,7 +1200,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();
@@ -1334,13 +1240,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
@@ -1457,7 +1361,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);
@@ -1594,14 +1497,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");
@@ -1612,7 +1513,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;
@@ -1620,37 +1520,31 @@ 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 {
-
return Size2(data.margin[2], data.margin[3]);
}
Point2 Control::get_global_position() const {
-
return get_global_transform().get_origin();
}
@@ -1670,11 +1564,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();
}
@@ -1682,7 +1574,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);
@@ -1694,7 +1585,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);
@@ -1724,7 +1614,6 @@ 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)
@@ -1745,22 +1634,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());
@@ -1781,17 +1666,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));
}
@@ -1809,7 +1691,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));
}
@@ -1826,7 +1707,6 @@ 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) {
-
if (data.style_override.has(p_name)) {
data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
@@ -1844,7 +1724,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));
}
@@ -1861,18 +1740,15 @@ 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) {
-
data.color_override[p_name] = p_color;
notification(NOTIFICATION_THEME_CHANGED);
}
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())
@@ -1882,21 +1758,18 @@ void Control::set_focus_mode(FocusMode p_focus_mode) {
}
static Control *_next_control(Control *p_from) {
-
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 nullptr;
}
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())
continue;
@@ -1909,11 +1782,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()) {
@@ -1934,7 +1805,6 @@ Control *Control::find_next_valid_focus() const {
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;
@@ -1945,20 +1815,16 @@ 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)
break;
next_child = next_child->get_parent_control();
@@ -1981,10 +1847,8 @@ Control *Control::find_next_valid_focus() const {
}
static Control *_prev_control(Control *p_from) {
-
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())
continue;
@@ -2004,7 +1868,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()) {
@@ -2025,15 +1888,12 @@ Control *Control::find_prev_valid_focus() const {
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_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()) {
@@ -2045,10 +1905,8 @@ 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);
}
}
@@ -2066,16 +1924,13 @@ Control *Control::find_prev_valid_focus() const {
}
Control::FocusMode Control::get_focus_mode() const {
-
return data.focus_mode;
}
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) {
@@ -2087,7 +1942,6 @@ void Control::grab_focus() {
}
void Control::release_focus() {
-
ERR_FAIL_COND(!is_inside_tree());
if (!has_focus())
@@ -2098,12 +1952,10 @@ void Control::release_focus() {
}
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
@@ -2115,12 +1967,10 @@ void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_o
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);
@@ -2129,7 +1979,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;
@@ -2139,7 +1988,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;
@@ -2150,12 +1998,10 @@ 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)
return;
@@ -2165,12 +2011,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)) {
@@ -2191,24 +2035,20 @@ void Control::set_theme(const Ref<Theme> &p_theme) {
}
void Control::accept_event() {
-
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 {
@@ -2219,75 +2059,62 @@ Control *Control::make_custom_tooltip(const String &p_text) const {
}
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 {
-
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);
if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT)
return nullptr;
if (!data.focus_neighbour[p_margin].is_empty()) {
-
Control *c = nullptr;
Node *n = get_node(data.focus_neighbour[p_margin]);
if (n) {
@@ -2332,7 +2159,6 @@ 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)
maxd = d;
@@ -2341,7 +2167,6 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
Node *base = this;
while (base) {
-
Control *c = Object::cast_to<Control>(base);
if (c) {
if (c->data.RI)
@@ -2359,14 +2184,12 @@ 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))
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();
@@ -2379,21 +2202,17 @@ 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)
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];
@@ -2410,7 +2229,6 @@ 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)
@@ -2420,7 +2238,6 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
}
void Control::set_h_size_flags(int p_flags) {
-
if (data.h_size_flags == p_flags)
return;
data.h_size_flags = p_flags;
@@ -2431,7 +2248,6 @@ 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)
return;
data.v_size_flags = p_flags;
@@ -2439,7 +2255,6 @@ void Control::set_v_size_flags(int p_flags) {
}
void Control::set_stretch_ratio(float p_ratio) {
-
if (data.expand == p_ratio)
return;
@@ -2448,19 +2263,16 @@ void Control::set_stretch_ratio(float p_ratio) {
}
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)
return;
@@ -2496,19 +2308,16 @@ 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(), nullptr);
return get_viewport()->_gui_get_focus_owner();
}
@@ -2533,7 +2342,6 @@ bool Control::is_text_field() const {
}
void Control::set_rotation(float p_radians) {
-
data.rotation = p_radians;
update();
_notify_transform();
@@ -2541,7 +2349,6 @@ void Control::set_rotation(float p_radians) {
}
float Control::get_rotation() const {
-
return data.rotation;
}
@@ -2554,14 +2361,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();
@@ -2569,12 +2374,10 @@ 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)
@@ -2585,17 +2388,14 @@ void Control::set_scale(const Vector2 &p_scale) {
_notify_transform();
}
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;
@@ -2615,23 +2415,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
@@ -2674,18 +2470,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;
@@ -2693,24 +2486,20 @@ 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 {
-
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);
@@ -2984,7 +2773,6 @@ void Control::_bind_methods() {
BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point")));
}
Control::Control() {
-
data.parent = nullptr;
data.mouse_filter = MOUSE_FILTER_STOP;
diff --git a/scene/gui/control.h b/scene/gui/control.h
index d02fea20a6..5a4c64492b 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -44,7 +44,6 @@ class Label;
class Panel;
class Control : public CanvasItem {
-
GDCLASS(Control, CanvasItem);
OBJ_CATEGORY("GUI Nodes");
@@ -132,7 +131,6 @@ 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())
return p_b->is_greater_than(p_a);
@@ -142,7 +140,6 @@ private:
};
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 5654219a3e..3e1a72beb7 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,12 +96,10 @@ void AcceptDialog::_notification(int p_what) {
}
void AcceptDialog::_text_entered(const String &p_text) {
-
_ok_pressed();
}
void AcceptDialog::_ok_pressed() {
-
if (hide_on_ok)
set_visible(false);
ok_pressed();
@@ -111,7 +107,6 @@ void AcceptDialog::_ok_pressed() {
}
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 +125,9 @@ void AcceptDialog::_cancel_pressed() {
}
String AcceptDialog::get_text() const {
-
return label->get_text();
}
void AcceptDialog::set_text(String p_text) {
-
label->set_text(p_text);
child_controls_changed();
if (is_visible()) {
@@ -143,25 +136,20 @@ 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 {
-
return hide_on_ok;
}
void AcceptDialog::set_autowrap(bool p_autowrap) {
-
label->set_autowrap(p_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)
@@ -169,7 +157,6 @@ void AcceptDialog::register_text_enter(Node *p_line_edit) {
}
void AcceptDialog::_update_child_rects() {
-
Size2 label_size = label->get_minimum_size();
if (label->get_text().empty()) {
label_size.height = 0;
@@ -204,7 +191,6 @@ 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();
@@ -233,20 +219,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,7 +243,6 @@ 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 == "")
c = RTR("Cancel");
@@ -270,7 +252,6 @@ Button *AcceptDialog::add_cancel(const String &p_cancel) {
}
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 +276,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);
@@ -344,17 +323,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 a449d680a8..adf67bc7df 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -45,7 +45,6 @@ VBoxContainer *FileDialog::get_vbox() {
}
void FileDialog::_theme_changed() {
-
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");
@@ -64,15 +63,12 @@ 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(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"));
@@ -81,18 +77,13 @@ void FileDialog::_notification(int p_what) {
}
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: {
@@ -120,17 +109,14 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
}
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 +124,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 +135,6 @@ void FileDialog::update_dir() {
}
void FileDialog::_dir_entered(String p_dir) {
-
dir_access->change_dir(p_dir);
file->set_text("");
invalidate();
@@ -158,7 +142,6 @@ void FileDialog::_dir_entered(String p_dir) {
}
void FileDialog::_file_entered(const String &p_file) {
-
_action_pressed();
}
@@ -169,7 +152,6 @@ void FileDialog::_save_confirm_pressed() {
}
void FileDialog::_post_popup() {
-
ConfirmationDialog::_post_popup();
if (invalidated) {
update_file_list();
@@ -192,15 +174,12 @@ void FileDialog::_post_popup() {
}
void FileDialog::_action_pressed() {
-
if (mode == FILE_MODE_OPEN_FILES) {
-
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 +198,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 +214,6 @@ void FileDialog::_action_pressed() {
}
if (mode == FILE_MODE_SAVE_FILE) {
-
bool valid = false;
if (filter->get_selected() == filter->get_item_count() - 1) {
@@ -244,10 +221,8 @@ 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;
@@ -262,11 +237,9 @@ void FileDialog::_action_pressed() {
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 +259,6 @@ void FileDialog::_action_pressed() {
}
if (!valid) {
-
exterr->popup_centered(Size2(250, 80));
return;
}
@@ -295,7 +267,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,14 +274,12 @@ 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)
return false;
@@ -333,14 +302,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 +316,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 +336,12 @@ 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)
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,7 +351,6 @@ void FileDialog::_tree_selected() {
}
void FileDialog::_tree_item_activated() {
-
TreeItem *ti = tree->get_selected();
if (!ti)
return;
@@ -395,14 +358,12 @@ void FileDialog::_tree_item_activated() {
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)
file->set_text("");
call_deferred("_update_file_list");
call_deferred("_update_dir");
} else {
-
_action_pressed();
}
}
@@ -421,7 +382,6 @@ void FileDialog::update_file_name() {
}
void FileDialog::update_file_list() {
-
tree->clear();
// Scroll back to the top after opening a directory
@@ -439,7 +399,6 @@ void FileDialog::update_file_list() {
String item;
while ((item = dir_access->get_next()) != "") {
-
if (item == "." || item == "..")
continue;
@@ -475,15 +434,12 @@ 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());
}
}
@@ -493,10 +449,8 @@ void FileDialog::update_file_list() {
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());
}
}
@@ -505,12 +459,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;
@@ -523,7 +475,6 @@ 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);
}
@@ -549,13 +500,11 @@ void FileDialog::update_file_list() {
}
void FileDialog::_filter_selected(int) {
-
update_file_name();
update_file_list();
}
void FileDialog::update_filters() {
-
filter->clear();
if (filters.size() > 1) {
@@ -576,7 +525,6 @@ void FileDialog::update_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())
@@ -589,13 +537,11 @@ void FileDialog::update_filters() {
}
void FileDialog::clear_filters() {
-
filters.clear();
update_filters();
invalidate();
}
void FileDialog::add_filter(const String &p_filter) {
-
filters.push_back(p_filter);
update_filters();
invalidate();
@@ -612,25 +558,20 @@ Vector<String> FileDialog::get_filters() const {
}
String FileDialog::get_current_dir() const {
-
return dir->get_text();
}
String FileDialog::get_current_file() const {
-
return file->get_text();
}
String FileDialog::get_current_path() const {
-
return dir->get_text().plus_file(file->get_text());
}
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) {
-
file->set_text(p_file);
update_dir();
invalidate();
@@ -642,15 +583,12 @@ void FileDialog::set_current_file(const String &p_file) {
}
}
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);
@@ -667,12 +605,10 @@ 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)
@@ -713,27 +649,22 @@ 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)
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;
}
@@ -745,7 +676,6 @@ void FileDialog::set_access(Access p_access) {
}
void FileDialog::invalidate() {
-
if (is_visible()) {
update_file_list();
invalidated = false;
@@ -755,12 +685,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());
@@ -774,13 +702,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("");
@@ -789,7 +715,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();
@@ -814,7 +739,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);
@@ -884,7 +808,6 @@ void FileDialog::set_default_show_hidden_files(bool p_show) {
}
FileDialog::FileDialog() {
-
show_hidden_files = default_show_hidden_files;
mode_overrides_title = true;
@@ -1002,7 +925,6 @@ FileDialog::FileDialog() {
}
FileDialog::~FileDialog() {
-
if (unregister_func)
unregister_func(this);
memdelete(dir_access);
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index ac0e733abc..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:
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index a6ed3d8de9..1617405dd3 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -93,11 +93,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 +127,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 +151,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;
@@ -187,7 +183,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
if (pos == -1) {
-
prev.color = Color(0, 0, 0);
prev.offset = 0;
if (points.size()) {
@@ -197,7 +192,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;
@@ -222,7 +216,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 +226,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;
@@ -273,7 +265,6 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
bool valid = true;
for (int i = 0; i < points.size(); i++) {
-
if (points[i].offset == newofs && i != grabbed) {
valid = false;
break;
@@ -300,14 +291,12 @@ 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;
@@ -328,7 +317,6 @@ void GradientEdit::_notification(int p_what) {
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()) {
@@ -362,7 +350,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 +384,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 +392,6 @@ void GradientEdit::_notification(int p_what) {
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
-
if (!is_visible()) {
grabbing = false;
}
@@ -435,12 +420,10 @@ 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)
return;
points.write[grabbed].color = p_color;
@@ -449,7 +432,6 @@ void GradientEdit::_color_changed(const Color &p_color) {
}
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++) {
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 0bf67df9b4..2129ae6126 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -44,17 +44,14 @@
#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))
return OK;
Connection c;
@@ -72,9 +69,7 @@ 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)
return true;
}
@@ -83,11 +78,8 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
}
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 +90,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 +106,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,11 +123,9 @@ 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)
continue;
@@ -159,7 +144,6 @@ void GraphEdit::_update_scroll_offset() {
}
void GraphEdit::_update_scroll() {
-
if (updating)
return;
@@ -169,7 +153,6 @@ 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)
continue;
@@ -218,7 +201,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 +223,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 +231,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 +246,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 +258,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 +282,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,7 +299,6 @@ 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)
@@ -335,7 +311,6 @@ void GraphEdit::_notification(int p_what) {
}
for (int i = from.y; i < from.y + len.y; i++) {
-
Color color;
if (ABS(i) % 10 == 0)
@@ -356,24 +331,20 @@ 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)
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))
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 +356,24 @@ 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)
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 +408,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 +454,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 +461,15 @@ 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)
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 +478,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 +494,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 +507,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,7 +526,6 @@ 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())
return false;
@@ -608,7 +556,6 @@ bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
continue;
Rect2 rect = child->get_rect();
if (rect.has_point(p_mouse_pos)) {
-
//check sub-controls
Vector2 subpos = p_mouse_pos - rect.position;
@@ -640,7 +587,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,7 +597,6 @@ 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.lerp(p_to_color, mp));
lines++;
@@ -662,7 +607,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 +640,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);
@@ -750,11 +692,9 @@ 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);
@@ -790,9 +730,7 @@ 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)
continue;
@@ -802,7 +740,6 @@ void GraphEdit::set_selected(Node *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 && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
@@ -810,7 +747,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
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);
@@ -818,7 +754,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
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.
@@ -842,7 +777,6 @@ 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)
continue;
@@ -862,12 +796,10 @@ 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)
continue;
@@ -901,7 +833,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (drag_accum != Vector2()) {
-
emit_signal("_begin_node_move");
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -921,11 +852,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
-
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) {
@@ -940,7 +869,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (gn) {
-
if (_filter_input(b->get_position()))
return;
@@ -985,7 +913,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
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())
continue;
@@ -996,7 +923,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
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())
continue;
@@ -1007,7 +933,6 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
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)
continue;
@@ -1052,7 +977,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();
@@ -1076,24 +1000,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();
@@ -1106,19 +1025,16 @@ 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)
return;
@@ -1135,7 +1051,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);
@@ -1149,37 +1064,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;
@@ -1195,21 +1103,17 @@ Array GraphEdit::_get_connection_list() const {
}
void GraphEdit::_zoom_minus() {
-
set_zoom(zoom / ZOOM_SCALE);
}
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;
@@ -1218,7 +1122,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;
@@ -1227,7 +1130,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;
@@ -1236,23 +1138,19 @@ 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();
@@ -1262,7 +1160,6 @@ void GraphEdit::_snap_toggled() {
}
void GraphEdit::_snap_value_changed(double) {
-
update();
}
@@ -1271,7 +1168,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);
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index f675f8c7f3..8cfc5d32b9 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:
@@ -142,7 +140,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 5dbc5bc50d..efac874462 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -33,7 +33,6 @@
#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/"))
return false;
@@ -65,7 +64,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;
}
@@ -95,7 +93,6 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
return true;
}
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));
@@ -116,7 +113,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;
@@ -167,7 +163,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 +183,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 +215,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: {
@@ -251,7 +241,6 @@ 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())
continue;
if (!slot_info.has(E->key()))
@@ -280,19 +269,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 +301,52 @@ 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() {
-
slot_info.clear();
update();
connpos_dirty = true;
}
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))
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))
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))
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))
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))
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,7 +361,6 @@ 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)
continue;
@@ -406,7 +382,6 @@ Size2 GraphNode::get_minimum_size() const {
}
void GraphNode::set_title(const String &p_title) {
-
if (title == p_title)
return;
title = p_title;
@@ -416,19 +391,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;
}
@@ -453,17 +425,14 @@ 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 {
-
return show_close;
}
void GraphNode::_connpos_update() {
-
int edgeofs = get_theme_constant("port_offset");
int sep = get_theme_constant("separation");
@@ -487,7 +456,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);
@@ -514,14 +482,12 @@ void GraphNode::_connpos_update() {
}
int GraphNode::get_connection_input_count() {
-
if (connpos_dirty)
_connpos_update();
return conn_input_cache.size();
}
int GraphNode::get_connection_output_count() {
-
if (connpos_dirty)
_connpos_update();
@@ -529,7 +495,6 @@ int GraphNode::get_connection_output_count() {
}
Vector2 GraphNode::get_connection_input_position(int p_idx) {
-
if (connpos_dirty)
_connpos_update();
@@ -541,7 +506,6 @@ Vector2 GraphNode::get_connection_input_position(int p_idx) {
}
int GraphNode::get_connection_input_type(int p_idx) {
-
if (connpos_dirty)
_connpos_update();
@@ -550,7 +514,6 @@ int GraphNode::get_connection_input_type(int p_idx) {
}
Color GraphNode::get_connection_input_color(int p_idx) {
-
if (connpos_dirty)
_connpos_update();
@@ -559,7 +522,6 @@ Color GraphNode::get_connection_input_color(int p_idx) {
}
Vector2 GraphNode::get_connection_output_position(int p_idx) {
-
if (connpos_dirty)
_connpos_update();
@@ -571,7 +533,6 @@ Vector2 GraphNode::get_connection_output_position(int p_idx) {
}
int GraphNode::get_connection_output_type(int p_idx) {
-
if (connpos_dirty)
_connpos_update();
@@ -580,7 +541,6 @@ int GraphNode::get_connection_output_type(int p_idx) {
}
Color GraphNode::get_connection_output_color(int p_idx) {
-
if (connpos_dirty)
_connpos_update();
@@ -589,14 +549,11 @@ Color GraphNode::get_connection_output_color(int p_idx) {
}
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() == 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 +566,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 +592,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 +681,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..1ba761e7a1 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.
@@ -168,14 +165,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 +178,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 +189,6 @@ void GridContainer::_bind_methods() {
}
Size2 GridContainer::get_minimum_size() const {
-
Map<int, int> col_minw;
Map<int, int> row_minh;
@@ -208,7 +200,6 @@ 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())
continue;
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 47a5ac68d2..86daa47c36 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,42 +154,36 @@ 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;
@@ -210,27 +191,23 @@ void ItemList::set_item_tag_icon(int p_idx, const Ref<Texture2D> &p_tag_icon) {
shape_changed = true;
}
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 +215,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 +228,13 @@ 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) {
-
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,7 +246,6 @@ 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;
}
@@ -282,7 +253,6 @@ void ItemList::select(int p_idx, bool p_single) {
update();
}
void ItemList::unselect(int p_idx) {
-
ERR_FAIL_INDEX(p_idx, items.size());
if (select_mode != SELECT_MULTI) {
@@ -295,12 +265,10 @@ void ItemList::unselect(int p_idx) {
}
void ItemList::unselect_all() {
-
if (items.size() < 1)
return;
for (int i = 0; i < items.size(); i++) {
-
items.write[i].selected = false;
}
current = -1;
@@ -308,7 +276,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;
@@ -326,12 +293,10 @@ void ItemList::set_current(int p_current) {
}
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 +313,9 @@ 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) {
-
ERR_FAIL_INDEX(p_idx, items.size());
items.remove(p_idx);
@@ -362,7 +325,6 @@ void ItemList::remove_item(int p_idx) {
}
void ItemList::clear() {
-
items.clear();
current = -1;
ensure_selected_visible = false;
@@ -372,65 +334,54 @@ 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 {
-
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 {
-
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 {
-
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 {
-
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,22 +389,18 @@ 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())
return Size2();
@@ -471,7 +418,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 +429,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 +437,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 +446,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 +458,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 +465,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) {
@@ -537,18 +478,15 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
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;
@@ -563,10 +501,8 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
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 +520,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 +558,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 +587,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 +601,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 +616,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 +627,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 +640,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 +656,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));
@@ -780,7 +697,6 @@ 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);
}
@@ -789,13 +705,11 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
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 +726,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;
@@ -865,15 +777,12 @@ void ItemList::_notification(int p_what) {
}
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 +799,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);
@@ -934,7 +842,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);
@@ -949,7 +856,6 @@ void ItemList::_notification(int p_what) {
ofs.x += items[i].rect_cache.size.x + hseparation;
col++;
if (col == current_columns) {
-
if (i < items.size() - 1)
separators.push_back(ofs.y + max_h + vseparation / 2);
@@ -994,7 +900,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,7 +940,6 @@ 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)
@@ -1073,7 +977,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 +991,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 +998,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;
}
@@ -1125,12 +1026,10 @@ 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);
@@ -1146,12 +1045,10 @@ void ItemList::_notification(int p_what) {
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;
@@ -1175,7 +1072,6 @@ 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;
@@ -1187,7 +1083,6 @@ void ItemList::_notification(int p_what) {
//special multiline mode
} else {
-
if (fixed_column_width > 0)
size2.x = MIN(size2.x, fixed_column_width);
@@ -1207,7 +1102,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;
@@ -1249,7 +1143,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 +1152,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,7 +1173,6 @@ 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())
return true;
@@ -1295,7 +1186,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 +1204,6 @@ String ItemList::get_tooltip(const Point2 &p_pos) const {
}
void ItemList::sort_items_by_text() {
-
items.sort();
update();
shape_changed = true;
@@ -1330,7 +1219,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 +1229,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;
}
@@ -1391,12 +1275,10 @@ bool ItemList::is_anything_selected() {
}
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 +1290,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 +1301,6 @@ Array ItemList::_get_items() const {
}
Size2 ItemList::get_minimum_size() const {
-
if (auto_height) {
return Size2(0, auto_height_value);
}
@@ -1429,24 +1308,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 +1456,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 7490101ee3..5f84dbe34b 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -35,7 +35,6 @@
#include "core/translation.h"
void Label::set_autowrap(bool p_autowrap) {
-
if (autowrap == p_autowrap) {
return;
}
@@ -49,30 +48,24 @@ void Label::set_autowrap(bool p_autowrap) {
}
}
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 {
-
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)
return; //nothing new
@@ -83,7 +76,6 @@ void Label::_notification(int p_what) {
}
if (p_what == NOTIFICATION_DRAW) {
-
if (clip) {
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
}
@@ -126,9 +118,7 @@ void Label::_notification(int p_what) {
}
if (lines_visible > 0) {
-
switch (valign) {
-
case VALIGN_TOP: {
//nothing
} break;
@@ -166,7 +156,6 @@ void Label::_notification(int p_what) {
if (line >= line_to)
break;
if (line < lines_skipped) {
-
while (wc && wc->char_pos >= 0)
wc = wc->next;
if (wc)
@@ -190,7 +179,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;
@@ -203,18 +191,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;
}
@@ -224,11 +208,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;
}
@@ -236,17 +218,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];
@@ -267,7 +246,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];
@@ -289,18 +267,15 @@ void Label::_notification(int p_what) {
}
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
@@ -319,27 +294,22 @@ Size2 Label::get_minimum_size() const {
}
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)
current = String::char_uppercase(current);
if (current < 32) {
-
if (current == '\n') {
-
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;
}
@@ -353,7 +323,6 @@ int Label::get_longest_line_width() const {
}
int Label::get_line_count() const {
-
if (!is_inside_tree())
return 1;
if (word_cache_dirty)
@@ -363,7 +332,6 @@ int Label::get_line_count() const {
}
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;
@@ -378,9 +346,7 @@ int Label::get_visible_line_count() const {
}
void Label::regenerate_word_cache() {
-
while (word_cache) {
-
WordCache *current = word_cache;
word_cache = current->next;
memdelete(current);
@@ -408,7 +374,6 @@ void Label::regenerate_word_cache() {
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)
@@ -423,7 +388,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) {
@@ -526,31 +490,26 @@ 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)
return;
text = p_string;
@@ -562,24 +521,20 @@ void Label::set_text(const String &p_string) {
}
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;
@@ -589,19 +544,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;
}
@@ -610,34 +561,28 @@ 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)
const_cast<Label *>(this)->regenerate_word_cache();
@@ -645,7 +590,6 @@ int Label::get_total_character_count() const {
}
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);
@@ -700,9 +644,7 @@ Label::Label(const String &p_text) {
}
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 0f84b01604..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:
@@ -68,7 +67,6 @@ private:
int get_longest_line_width() const;
struct WordCache {
-
enum {
CHAR_NEWLINE = -1,
CHAR_WRAPLINE = -2
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index bb177ae0e7..c1cfef0381 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));
@@ -68,7 +65,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
_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 +77,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 +91,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 +102,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;
@@ -137,7 +127,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 +136,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,7 +146,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
-
if (!k->is_pressed())
return;
@@ -202,11 +189,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 +209,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case (KEY_V): { // PASTE.
if (editable) {
-
paste_text();
}
@@ -243,7 +227,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 +239,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
case (KEY_Y): { // PASTE (Yank for unix users).
if (editable) {
-
paste_text();
}
@@ -264,7 +246,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();
@@ -300,13 +281,10 @@ 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))
DisplayServer::get_singleton()->virtual_keyboard_hide();
@@ -314,7 +292,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_BACKSPACE: {
-
if (!editable)
break;
@@ -380,7 +357,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;
@@ -465,7 +441,6 @@ 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;
@@ -473,7 +448,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
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;
@@ -481,7 +455,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
shift_selection_check_post(k->get_shift());
} break;
case KEY_DELETE: {
-
if (!editable)
break;
@@ -513,7 +486,6 @@ 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)
@@ -538,7 +510,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());
@@ -551,7 +522,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());
@@ -568,7 +538,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
default: {
-
handled = false;
} break;
}
@@ -577,7 +546,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 };
@@ -602,19 +570,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);
@@ -626,11 +591,9 @@ 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 {
-
return p_data.get_type() == Variant::STRING;
}
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;
@@ -666,7 +629,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: {
@@ -681,7 +643,6 @@ void LineEdit::_notification(int p_what) {
} break;
#endif
case NOTIFICATION_RESIZED: {
-
window_pos = 0;
set_cursor_position(get_cursor_position());
@@ -702,7 +663,6 @@ void LineEdit::_notification(int p_what) {
update();
} break;
case NOTIFICATION_DRAW: {
-
if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
draw_caret = false;
}
@@ -726,7 +686,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));
}
@@ -735,21 +694,17 @@ 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)
x_ofs = style->get_offset().x;
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;
}
@@ -800,7 +755,6 @@ 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())
break;
@@ -926,7 +880,6 @@ void LineEdit::_notification(int p_what) {
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
-
if (caret_blink_enabled) {
caret_blink_timer->start();
} else {
@@ -944,7 +897,6 @@ void LineEdit::_notification(int p_what) {
} break;
case NOTIFICATION_FOCUS_EXIT: {
-
if (caret_blink_enabled) {
caret_blink_timer->stop();
}
@@ -961,7 +913,6 @@ void LineEdit::_notification(int p_what) {
} 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();
@@ -972,14 +923,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();
@@ -987,12 +936,10 @@ 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();
@@ -1050,7 +997,6 @@ void LineEdit::redo() {
}
void LineEdit::shift_selection_check_pre(bool p_shift) {
-
if (!selection.enabled && p_shift) {
selection.cursor_start = cursor_pos;
}
@@ -1059,13 +1005,11 @@ void LineEdit::shift_selection_check_pre(bool p_shift) {
}
void LineEdit::shift_selection_check_post(bool 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");
@@ -1075,14 +1019,11 @@ 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)
pixel_ofs = int(style->get_offset().x);
else
@@ -1092,7 +1033,6 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
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)
@@ -1101,7 +1041,6 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
}
while (ofs < text.length()) {
-
int char_w = 0;
if (font != nullptr) {
char_w = font->get_char_size(pass ? secret_character[0] : text[ofs]).width;
@@ -1119,7 +1058,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");
@@ -1129,14 +1067,11 @@ 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)
pixel_ofs = int(style->get_offset().x);
else
@@ -1146,7 +1081,6 @@ int LineEdit::get_cursor_pixel_pos() {
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)
@@ -1210,7 +1144,6 @@ void LineEdit::_toggle_draw_caret() {
}
void LineEdit::delete_char() {
-
if ((text.length() <= 0) || (cursor_pos == 0))
return;
@@ -1231,7 +1164,6 @@ void LineEdit::delete_char() {
}
void LineEdit::delete_text(int p_from_column, int p_to_column) {
-
if (text.size() > 0) {
Ref<Font> font = get_theme_font("font");
if (font != nullptr) {
@@ -1246,11 +1178,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;
}
@@ -1267,7 +1197,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);
@@ -1281,18 +1210,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();
@@ -1300,23 +1226,19 @@ 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())
p_pos = text.length();
@@ -1326,7 +1248,6 @@ void LineEdit::set_cursor_position(int p_pos) {
cursor_pos = p_pos;
if (!is_inside_tree()) {
-
window_pos = cursor_pos;
return;
}
@@ -1351,11 +1272,9 @@ void LineEdit::set_cursor_position(int p_pos) {
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;
@@ -1380,19 +1299,16 @@ void LineEdit::set_cursor_position(int p_pos) {
}
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;
}
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);
@@ -1405,7 +1321,6 @@ void LineEdit::append_at_cursor(String p_text) {
}
void LineEdit::clear_internal() {
-
deselect();
_clear_undo_stack();
cached_width = 0;
@@ -1417,7 +1332,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");
@@ -1448,7 +1362,6 @@ Size2 LineEdit::get_minimum_size() const {
}
void LineEdit::deselect() {
-
selection.begin = 0;
selection.end = 0;
selection.cursor_start = 0;
@@ -1459,7 +1372,6 @@ void LineEdit::deselect() {
}
void LineEdit::selection_delete() {
-
if (selection.enabled)
delete_text(selection.begin, selection.end);
@@ -1467,14 +1379,12 @@ void LineEdit::selection_delete() {
}
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;
}
@@ -1508,7 +1418,6 @@ void LineEdit::select_all() {
}
void LineEdit::set_editable(bool p_editable) {
-
if (editable == p_editable)
return;
@@ -1520,24 +1429,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).");
@@ -1580,12 +1485,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) {
@@ -1593,7 +1496,6 @@ void LineEdit::menu_option(int p_option) {
}
} break;
case MENU_COPY: {
-
copy_text();
} break;
case MENU_PASTE: {
@@ -1642,7 +1544,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);
@@ -1786,7 +1687,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);
@@ -1873,7 +1773,6 @@ void LineEdit::_bind_methods() {
}
LineEdit::LineEdit() {
-
undo_stack_pos = nullptr;
_create_undo_state();
align = ALIGN_LEFT;
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 098e8297ad..d772b257fc 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,42 +41,33 @@ 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"))
color = get_theme_color("font_color_pressed");
else
@@ -87,13 +77,11 @@ void LinkButton::_notification(int p_what) {
} 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 +89,6 @@ void LinkButton::_notification(int p_what) {
}
if (has_focus()) {
-
Ref<StyleBox> style = get_theme_stylebox("focus");
style->draw(ci, Rect2(Point2(), size));
}
@@ -123,7 +110,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..3f5bc43d93 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,7 +39,6 @@ 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)
continue;
@@ -63,10 +61,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,7 +71,6 @@ 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)
continue;
@@ -88,7 +83,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..2593784cbd 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -34,12 +34,10 @@
#include "scene/main/window.h"
void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
-
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())
return;
@@ -52,7 +50,6 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
}
void MenuButton::pressed() {
-
{
Window *w = Object::cast_to<Window>(get_viewport());
if (w && !w->is_embedding_subwindows()) {
@@ -75,39 +72,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 +104,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 +119,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 cf10c4cfbd..a65edefa5f 100644
--- a/scene/gui/nine_patch_rect.cpp
+++ b/scene/gui/nine_patch_rect.cpp
@@ -33,9 +33,7 @@
#include "servers/rendering_server.h"
void NinePatchRect::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
if (texture.is_null())
return;
@@ -50,11 +48,9 @@ void NinePatchRect::_notification(int p_what) {
}
Size2 NinePatchRect::get_minimum_size() const {
-
return Size2(margin[MARGIN_LEFT] + margin[MARGIN_RIGHT], margin[MARGIN_TOP] + margin[MARGIN_BOTTOM]);
}
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,7 +85,6 @@ void NinePatchRect::_bind_methods() {
}
void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) {
-
if (texture == p_tex)
return;
texture = p_tex;
@@ -104,12 +99,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,13 +124,11 @@ 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)
return;
@@ -148,18 +139,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 +161,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 a03d6d0cdc..b3c024bd1d 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,10 +50,8 @@ Size2 OptionButton::get_minimum_size() const {
}
void OptionButton::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_DRAW: {
-
if (!has_theme_icon("arrow"))
return;
@@ -83,13 +80,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 +97,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,96 +108,79 @@ 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)
select(0);
}
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)
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)
set_text(p_text);
}
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)
set_icon(p_icon);
}
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)
return;
if (p_which == current)
@@ -213,7 +189,6 @@ void OptionButton::_select(int p_which, bool p_emit) {
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);
}
@@ -226,31 +201,26 @@ void OptionButton::_select(int p_which, bool p_emit) {
}
void OptionButton::_select_int(int p_which) {
-
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)
return 0;
return get_item_id(current);
}
Variant OptionButton::get_selected_metadata() const {
-
int idx = get_selected();
if (idx < 0)
return Variant();
@@ -258,20 +228,16 @@ Variant OptionButton::get_selected_metadata() const {
}
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));
@@ -282,12 +248,10 @@ Array OptionButton::_get_items() const {
return 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 +267,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);
@@ -345,7 +307,6 @@ void OptionButton::_bind_methods() {
}
OptionButton::OptionButton() {
-
current = -1;
set_toggle_mode(true);
set_text_align(ALIGN_LEFT);
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 a17d0eb9c6..a13d8a0cdd 100644
--- a/scene/gui/panel.cpp
+++ b/scene/gui/panel.cpp
@@ -33,9 +33,7 @@
#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()));
diff --git a/scene/gui/panel.h b/scene/gui/panel.h
index 75e266b6a6..a68c3d3f0c 100644
--- a/scene/gui/panel.h
+++ b/scene/gui/panel.h
@@ -34,7 +34,6 @@
#include "scene/gui/control.h"
class Panel : public Control {
-
GDCLASS(Panel, Control);
public:
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 62b9296409..6cac15d9f0 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -31,7 +31,6 @@
#include "panel_container.h"
Size2 PanelContainer::get_minimum_size() const {
-
Ref<StyleBox> style;
if (has_theme_stylebox("panel"))
@@ -41,7 +40,6 @@ Size2 PanelContainer::get_minimum_size() const {
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())
continue;
@@ -59,9 +57,7 @@ Size2 PanelContainer::get_minimum_size() const {
}
void PanelContainer::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
RID ci = get_canvas_item();
Ref<StyleBox> style;
@@ -74,7 +70,6 @@ void PanelContainer::_notification(int p_what) {
}
if (p_what == NOTIFICATION_SORT_CHILDREN) {
-
Ref<StyleBox> style;
if (has_theme_stylebox("panel"))
@@ -90,7 +85,6 @@ 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())
continue;
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..7068e2e1e2 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -42,15 +42,12 @@ void Popup::_input_from_window(const Ref<InputEvent> &p_event) {
}
void Popup::_parent_focused() {
-
_close_pressed();
}
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 +76,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));
@@ -99,7 +95,6 @@ void Popup::set_as_minsize() {
set_size(get_contents_minimum_size());
}
void Popup::_bind_methods() {
-
ADD_SIGNAL(MethodInfo("popup_hide"));
}
@@ -133,7 +128,6 @@ Rect2i Popup::_popup_adjust_rect() const {
}
Popup::Popup() {
-
parent_visible = nullptr;
set_wrap_controls(true);
@@ -149,7 +143,6 @@ Popup::~Popup() {
}
Size2 PopupPanel::_get_contents_minimum_size() const {
-
Ref<StyleBox> p = get_theme_stylebox("panel", get_class_name());
Size2 ms;
@@ -171,7 +164,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());
@@ -196,21 +188,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 9c48801ec1..52fe991f83 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -38,7 +38,6 @@
#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())
@@ -49,7 +48,6 @@ String PopupMenu::_get_accel_text(int p_item) const {
}
Size2 PopupMenu::_get_contents_minimum_size() const {
-
int vseparation = get_theme_constant("vseparation");
int hseparation = get_theme_constant("hseparation");
@@ -64,15 +62,12 @@ 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;
}
@@ -87,7 +82,6 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
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);
@@ -109,7 +103,6 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
}
int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
-
if (p_over.x < 0 || p_over.x >= get_size().width)
return -1;
@@ -125,16 +118,13 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
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,7 +138,6 @@ 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);
@@ -172,7 +161,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,7 +172,6 @@ void PopupMenu::_activate_submenu(int over) {
}
void PopupMenu::_submenu_timeout() {
-
//if (!has_focus()) {
// return; //do not activate if not has focus
//}
@@ -195,7 +182,6 @@ void PopupMenu::_submenu_timeout() {
}
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 +212,16 @@ 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())
search_from = 0;
for (int i = search_from; i < items.size(); i++) {
-
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 +230,15 @@ 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)
search_from = items.size() - 1;
for (int i = search_from; i >= 0; i--) {
-
if (i >= items.size())
continue;
if (!items[i].separator && !items[i].disabled) {
-
mouse_over = i;
emit_signal("id_focused", i);
control->update();
@@ -268,22 +247,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 +271,20 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
-
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;
@@ -336,7 +306,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
break;
if (items[over].submenu != "") {
-
_activate_submenu(over);
return;
}
@@ -351,7 +320,6 @@ 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)
@@ -359,9 +327,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
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;
}
@@ -395,7 +361,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
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));
@@ -431,7 +396,6 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
void PopupMenu::_draw() {
-
RID ci = control->get_canvas_item();
Size2 size = get_size();
@@ -460,7 +424,6 @@ 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())
icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs);
@@ -475,7 +438,6 @@ void PopupMenu::_draw() {
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)
ofs.y += vseparation;
Point2 item_ofs = ofs;
@@ -483,16 +445,13 @@ void PopupMenu::_draw() {
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 +459,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 +493,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 +516,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 +526,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 +534,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 = 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 +555,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 +563,6 @@ void PopupMenu::_notification(int p_what) {
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
-
if (!is_visible()) {
if (mouse_over >= 0) {
mouse_over = -1;
@@ -659,7 +605,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 +613,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 +622,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 +631,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 +641,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 +650,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 +660,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 +679,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 +687,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 +696,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 +705,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 +715,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 +724,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 +734,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 +750,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);
@@ -827,7 +758,6 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) {
child_controls_changed();
}
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;
@@ -835,7 +765,6 @@ void PopupMenu::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) {
child_controls_changed();
}
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;
@@ -844,7 +773,6 @@ void PopupMenu::set_item_checked(int p_idx, bool p_checked) {
child_controls_changed();
}
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 +781,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 +789,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 +796,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 +803,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 +810,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,13 +817,11 @@ 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)
return idx;
@@ -910,45 +831,37 @@ int PopupMenu::get_item_idx_from_text(const String &text) const {
}
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)
return i;
}
@@ -957,19 +870,16 @@ int PopupMenu::get_item_index(int p_id) const {
}
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 +890,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 +901,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 +934,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,21 +941,18 @@ 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;
@@ -1074,23 +976,19 @@ 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_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;
@@ -1140,7 +1038,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;
@@ -1189,7 +1086,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()) {
@@ -1202,7 +1098,6 @@ void PopupMenu::remove_item(int p_idx) {
}
void PopupMenu::add_separator(const String &p_text) {
-
Item sep;
sep.separator = true;
sep.id = -1;
@@ -1215,7 +1110,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);
@@ -1228,10 +1122,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
@@ -1251,7 +1143,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));
@@ -1261,7 +1152,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) {
@@ -1271,12 +1161,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
@@ -1313,37 +1201,30 @@ 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)
p_time = 0.01;
@@ -1351,22 +1232,18 @@ void PopupMenu::set_submenu_popup_delay(float 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())
return "";
@@ -1374,26 +1251,21 @@ String PopupMenu::get_tooltip(const Point2 &p_pos) const {
}
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 != "")
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();
}
@@ -1406,7 +1278,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));
@@ -1501,14 +1372,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);
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index d5c1015863..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 {
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 ab2f64e1b4..2260a5a97c 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,7 +51,6 @@ 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())
@@ -62,14 +60,12 @@ void Range::Shared::emit_value_changed() {
}
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())
@@ -79,7 +75,6 @@ void Range::Shared::emit_changed(const char *p_what) {
}
void Range::set_value(double p_val) {
-
if (shared->step > 0)
p_val = Math::round(p_val / shared->step) * shared->step;
@@ -114,12 +109,10 @@ void Range::set_max(double p_max) {
shared->emit_changed("max");
}
void Range::set_step(double p_step) {
-
shared->step = p_step;
shared->emit_changed("step");
}
void Range::set_page(double p_page) {
-
shared->page = p_page;
set_value(shared->val);
@@ -127,37 +120,29 @@ void Range::set_page(double p_page) {
}
double Range::get_value() const {
-
return shared->val;
}
double Range::get_min() const {
-
return shared->min;
}
double Range::get_max() const {
-
return shared->max;
}
double Range::get_step() const {
-
return shared->step;
}
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());
@@ -170,11 +155,9 @@ void Range::set_as_ratio(double p_value) {
set_value(v);
}
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 +166,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 +186,6 @@ void Range::share(Range *p_range) {
}
void Range::unshare() {
-
Shared *nshared = memnew(Shared);
nshared->min = shared->min;
nshared->max = shared->max;
@@ -221,7 +200,6 @@ void Range::unshare() {
}
void Range::_ref_shared(Shared *p_shared) {
-
if (shared && p_shared == shared)
return;
@@ -231,7 +209,6 @@ void Range::_ref_shared(Shared *p_shared) {
}
void Range::_unref_shared() {
-
if (shared) {
shared->owners.erase(this);
if (shared->owners.size() == 0) {
@@ -242,7 +219,6 @@ void Range::_unref_shared() {
}
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 +259,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 +308,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..0f6ff4da26 100644
--- a/scene/gui/reference_rect.cpp
+++ b/scene/gui/reference_rect.cpp
@@ -33,9 +33,7 @@
#include "core/engine.h"
void ReferenceRect::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
if (!is_inside_tree())
return;
if (Engine::get_singleton()->is_editor_hint() || !editor_only)
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 a6c0c99bdb..baf8c53fef 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 nullptr;
} else if (p_item->E->next()) {
-
return p_item->E->next()->get();
} else {
//go up until something with a next is found
@@ -71,12 +67,10 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
} 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 nullptr;
} else if (p_item->E->next()) {
-
return p_item->E->next()->get();
} else {
//go up until something with a next is found
@@ -96,14 +90,11 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) {
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 nullptr;
} else if (p_item->E->prev()) {
-
return p_item->E->prev()->get();
} else {
//go back until something with a prev is found
@@ -119,12 +110,10 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) {
} 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 nullptr;
} else if (p_item->E->prev()) {
-
return p_item->E->prev()->get();
} else {
//go back until something with a prev is found
@@ -148,7 +137,6 @@ 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;
@@ -172,7 +160,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];
}
@@ -328,18 +315,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);
@@ -351,7 +334,6 @@ 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);
@@ -399,7 +381,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;
@@ -412,7 +393,6 @@ 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;
@@ -446,14 +426,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') {
@@ -461,7 +439,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);
}
@@ -473,7 +450,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;
@@ -498,7 +474,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) {
@@ -571,7 +546,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
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);
@@ -636,7 +610,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_IMAGE: {
-
lh = 0;
if (p_mode != PROCESS_CACHE)
lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
@@ -668,7 +641,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
} break;
case ITEM_NEWLINE: {
-
lh = 0;
if (p_mode != PROCESS_CACHE) {
@@ -678,7 +650,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");
@@ -690,7 +661,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++) {
@@ -710,7 +680,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);
@@ -782,7 +751,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
@@ -814,7 +782,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
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);
@@ -836,7 +803,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;
@@ -863,7 +829,6 @@ 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)
@@ -888,7 +853,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
}
void RichTextLabel::_scroll_changed(double) {
-
if (updating_scroll || !scroll_active)
return;
@@ -903,13 +867,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;
@@ -961,9 +923,7 @@ 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 = nullptr;
@@ -973,13 +933,11 @@ void RichTextLabel::_notification(int p_what) {
}
} break;
case NOTIFICATION_RESIZED: {
-
main->first_invalid_line = 0; //invalidate ALL
update();
} break;
case NOTIFICATION_ENTER_TREE: {
-
if (bbcode != "")
set_bbcode(bbcode);
@@ -988,12 +946,10 @@ void RichTextLabel::_notification(int p_what) {
} break;
case NOTIFICATION_THEME_CHANGED: {
-
update();
} break;
case NOTIFICATION_DRAW: {
-
_validate_line_caches(main);
_update_scroll();
@@ -1017,7 +973,6 @@ 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)
break;
total_chars += main->lines[from_line].char_count;
@@ -1035,7 +990,6 @@ 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(), nullptr, nullptr, nullptr, total_chars);
total_chars += main->lines[from_line].char_count;
@@ -1052,7 +1006,6 @@ 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 = nullptr;
@@ -1066,7 +1019,6 @@ 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)
break;
from_line++;
@@ -1080,7 +1032,6 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
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)
return;
@@ -1089,7 +1040,6 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
}
Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const {
-
if (!underline_meta)
return CURSOR_ARROW;
@@ -1111,7 +1061,6 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const
}
void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
-
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
@@ -1128,9 +1077,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
_find_click(main, b->get_position(), &item, &line, &outside);
if (item) {
-
if (selection.enabled) {
-
selection.click = item;
selection.click_char = line;
@@ -1147,7 +1094,6 @@ 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 = nullptr;
@@ -1156,17 +1102,14 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
_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;
@@ -1176,7 +1119,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
}
} else if (!b->is_pressed()) {
-
selection.click = nullptr;
if (!b->is_doubleclick() && !scroll_updated) {
@@ -1187,7 +1129,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
_find_click(main, b->get_position(), &item, &line, &outside);
if (item) {
-
Variant meta;
if (!outside && _find_meta(item, &meta)) {
//meta clicked
@@ -1211,7 +1152,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
-
if (scroll_active)
vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8);
@@ -1226,42 +1166,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;
@@ -1269,7 +1203,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_INSERT:
case KEY_C: {
-
if (k->get_command()) {
selection_copy();
handled = true;
@@ -1295,7 +1228,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
_find_click(main, m->get_position(), &item, &line, &outside);
if (selection.click) {
-
if (!item)
return; // do not update
@@ -1312,7 +1244,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
if (selection.from_char > selection.to_char)
swap = true;
else if (selection.from_char == selection.to_char) {
-
selection.active = false;
return;
}
@@ -1347,13 +1278,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;
}
@@ -1365,15 +1293,12 @@ 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())
font = p_base_font;
@@ -1383,7 +1308,6 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
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())
font = p_base_font;
@@ -1396,13 +1320,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;
}
@@ -1414,13 +1335,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;
}
@@ -1432,13 +1350,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;
}
@@ -1449,13 +1364,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;
}
@@ -1466,7 +1378,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;
@@ -1495,9 +1406,7 @@ 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)
*r_meta = meta->meta;
@@ -1513,7 +1422,6 @@ 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)
return true;
@@ -1530,7 +1438,6 @@ 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())
return;
@@ -1547,7 +1454,6 @@ 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;
@@ -1573,31 +1479,25 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
}
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)
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;
}
@@ -1607,7 +1507,6 @@ void RichTextLabel::add_text(const String &p_text) {
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());
@@ -1623,7 +1522,6 @@ void RichTextLabel::add_text(const String &p_text) {
}
if (eol) {
-
ItemNewline *item = memnew(ItemNewline);
item->line = current_frame->lines.size();
_add_item(item, false);
@@ -1638,7 +1536,6 @@ 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++;
@@ -1668,7 +1565,6 @@ 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);
@@ -1687,7 +1583,6 @@ 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)
return;
@@ -1723,7 +1618,6 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width,
}
void RichTextLabel::add_newline() {
-
if (current->type == ITEM_TABLE)
return;
ItemNewline *item = memnew(ItemNewline);
@@ -1734,7 +1628,6 @@ void RichTextLabel::add_newline() {
}
bool RichTextLabel::remove_line(const int p_line) {
-
if (p_line >= current_frame->lines.size() || p_line < 0)
return false;
@@ -1767,7 +1660,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);
@@ -1812,7 +1704,6 @@ void RichTextLabel::push_mono() {
}
void RichTextLabel::push_color(const Color &p_color) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemColor *item = memnew(ItemColor);
@@ -1821,7 +1712,6 @@ void RichTextLabel::push_color(const Color &p_color) {
}
void RichTextLabel::push_underline() {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemUnderline *item = memnew(ItemUnderline);
@@ -1829,7 +1719,6 @@ void RichTextLabel::push_underline() {
}
void RichTextLabel::push_strikethrough() {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemStrikethrough *item = memnew(ItemStrikethrough);
@@ -1837,7 +1726,6 @@ void RichTextLabel::push_strikethrough() {
}
void RichTextLabel::push_align(Align p_align) {
-
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemAlign *item = memnew(ItemAlign);
@@ -1846,7 +1734,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);
@@ -1856,7 +1743,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);
@@ -1867,7 +1753,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);
@@ -1876,7 +1761,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);
@@ -1933,7 +1817,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());
@@ -1942,7 +1825,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);
@@ -1957,7 +1839,6 @@ void RichTextLabel::push_cell() {
}
int RichTextLabel::get_current_table_column() const {
-
ERR_FAIL_COND_V(current->type != ITEM_TABLE, -1);
ItemTable *table = static_cast<ItemTable *>(current);
@@ -1966,7 +1847,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;
@@ -1975,7 +1855,6 @@ void RichTextLabel::pop() {
}
void RichTextLabel::clear() {
-
main->_clear_children();
current = main;
current_frame = main;
@@ -1993,45 +1872,37 @@ 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)
return;
@@ -2040,30 +1911,25 @@ void RichTextLabel::set_scroll_active(bool p_active) {
}
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()))
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;
@@ -2083,7 +1949,6 @@ 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)
@@ -2108,7 +1973,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
Vector<String> split_tag_block = tag.split(" ", false);
String bbcode = !split_tag_block.empty() ? split_tag_block[0] : "";
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")
@@ -2130,7 +1994,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pop();
} else if (tag == "b") {
-
//use bold font
in_bold = true;
if (in_italics)
@@ -2140,7 +2003,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "i") {
-
//use italics font
in_italics = true;
if (in_bold)
@@ -2150,13 +2012,11 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
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)
columns = 1;
@@ -2165,12 +2025,10 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
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)
ratio = 1;
@@ -2180,51 +2038,42 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
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)
end = p_bbcode.length();
@@ -2235,13 +2084,11 @@ 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") {
-
int end = p_bbcode.find("[", brk_end);
if (end == -1)
end = p_bbcode.length();
@@ -2255,7 +2102,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pos = end;
tag_stack.push_front(tag);
} else if (tag.begins_with("img=")) {
-
int width = 0;
int height = 0;
@@ -2281,7 +2127,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pos = end;
tag_stack.push_front("img");
} else if (tag.begins_with("color=")) {
-
String col = tag.substr(6, tag.length());
Color color;
@@ -2327,7 +2172,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
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");
@@ -2480,14 +2324,12 @@ 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();
}
@@ -2498,7 +2340,6 @@ int RichTextLabel::get_visible_line_count() const {
}
void RichTextLabel::set_selection_enabled(bool p_enabled) {
-
selection.enabled = p_enabled;
if (!p_enabled) {
if (selection.active) {
@@ -2512,7 +2353,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;
@@ -2523,9 +2363,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) {
@@ -2571,7 +2409,6 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
}
void RichTextLabel::selection_copy() {
-
if (!selection.active || !selection.enabled)
return;
@@ -2580,9 +2417,7 @@ void RichTextLabel::selection_copy() {
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);
@@ -2609,7 +2444,6 @@ void RichTextLabel::selection_copy() {
}
bool RichTextLabel::is_selection_enabled() const {
-
return selection.enabled;
}
@@ -2624,7 +2458,6 @@ void RichTextLabel::set_bbcode(const String &p_bbcode) {
}
String RichTextLabel::get_bbcode() const {
-
return bbcode;
}
@@ -2636,7 +2469,6 @@ void RichTextLabel::set_use_bbcode(bool p_enable) {
}
bool RichTextLabel::is_using_bbcode() const {
-
return use_bbcode;
}
@@ -2663,14 +2495,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;
}
@@ -2717,7 +2546,6 @@ int RichTextLabel::get_content_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);
@@ -2857,7 +2685,6 @@ int RichTextLabel::get_visible_characters() const {
return visible_characters;
}
int RichTextLabel::get_total_character_count() const {
-
int tc = 0;
for (int i = 0; i < current_frame->lines.size(); i++)
tc += current_frame->lines[i].char_count;
@@ -2871,7 +2698,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());
@@ -2953,7 +2779,6 @@ Dictionary RichTextLabel::parse_expressions_for_values(Vector<String> p_expressi
}
RichTextLabel::RichTextLabel() {
-
main = memnew(ItemFrame);
main->index = 0;
current = main;
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 7f2b5facb9..019edf5d45 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;
@@ -352,7 +350,6 @@ private:
};
struct Selection {
-
Item *click;
int click_char;
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 1c63c25e28..98b6de0696 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,13 +53,11 @@ 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();
}
@@ -70,7 +66,6 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
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 +77,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 +89,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 +107,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 +127,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 +146,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 +157,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 +174,38 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
}
if (p_event->is_pressed()) {
-
if (p_event->is_action("ui_left")) {
-
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)
return;
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
} else if (p_event->is_action("ui_up")) {
-
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)
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");
@@ -273,13 +247,11 @@ void ScrollBar::_notification(int p_what) {
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 +262,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,7 +273,6 @@ 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));
@@ -312,7 +282,6 @@ void ScrollBar::_notification(int p_what) {
}
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
-
if (scrolling) {
if (get_value() != target_scroll) {
double target = target_scroll - get_value();
@@ -332,16 +301,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 +331,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 +360,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,21 +372,18 @@ 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)
return 0;
@@ -464,17 +424,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,7 +440,6 @@ 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();
@@ -495,19 +451,16 @@ double ScrollBar::get_click_pos(const Point2 &p_pos) const {
}
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 +469,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,17 +480,14 @@ 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));
}
@@ -546,16 +495,13 @@ void ScrollBar::_drag_node_exit() {
}
void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) {
-
Ref<InputEventMouseButton> mb = p_input;
if (mb.is_valid()) {
-
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 +516,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,9 +531,7 @@ 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;
@@ -607,9 +549,7 @@ 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));
@@ -620,7 +560,6 @@ void ScrollBar::set_drag_node(const NodePath &p_path) {
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,7 +573,6 @@ void ScrollBar::set_drag_node(const NodePath &p_path) {
}
NodePath ScrollBar::get_drag_node() const {
-
return drag_node_path;
}
@@ -647,7 +585,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,7 +595,6 @@ void ScrollBar::_bind_methods() {
}
ScrollBar::ScrollBar(Orientation p_orientation) {
-
orientation = p_orientation;
highlight = HIGHLIGHT_NONE;
custom_step = -1;
diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h
index ee5e7140cf..d2641b14f3 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 {
@@ -53,7 +52,6 @@ class ScrollBar : public Range {
HighlightStatus highlight;
struct Drag {
-
bool active;
float pos_at_click;
float value_at_click;
@@ -111,7 +109,6 @@ public:
};
class HScrollBar : public ScrollBar {
-
GDCLASS(HScrollBar, ScrollBar);
public:
@@ -120,7 +117,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..2f54ece449 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -33,17 +33,14 @@
#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)
continue;
@@ -88,14 +85,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())) {
@@ -136,7 +131,6 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
if (mb->is_pressed()) {
-
if (drag_touching) {
_cancel_drag();
}
@@ -156,11 +150,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 +162,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;
@@ -201,7 +191,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);
}
@@ -215,7 +204,6 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
void ScrollContainer::_update_scrollbar_position() {
-
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
@@ -234,7 +222,6 @@ void ScrollContainer::_update_scrollbar_position() {
}
void ScrollContainer::_ensure_focused_visible(Control *p_control) {
-
if (!follow_focus) {
return;
}
@@ -259,19 +246,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;
@@ -287,7 +270,6 @@ void ScrollContainer::_notification(int p_what) {
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)
continue;
@@ -322,7 +304,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 +311,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();
@@ -387,9 +365,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 +378,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 +397,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 +412,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 +432,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 +450,6 @@ void ScrollContainer::set_enable_h_scroll(bool p_enable) {
}
bool ScrollContainer::is_h_scroll_enabled() const {
-
return scroll_h;
}
@@ -495,26 +464,21 @@ 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) {
-
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) {
-
h_scroll->set_value(p_pos);
_cancel_drag();
}
@@ -536,11 +500,9 @@ 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)
continue;
@@ -559,17 +521,14 @@ String ScrollContainer::get_configuration_warning() const {
}
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 +563,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..a529c52065 100644
--- a/scene/gui/shortcut.cpp
+++ b/scene/gui/shortcut.cpp
@@ -33,23 +33,19 @@
#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())
return shortcut->as_text();
else
@@ -57,12 +53,10 @@ String ShortCut::get_as_text() const {
}
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 910d5f8230..b48922bf32 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -32,7 +32,6 @@
#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();
@@ -46,7 +45,6 @@ Size2 Slider::get_minimum_size() const {
}
void Slider::_gui_input(Ref<InputEvent> p_event) {
-
if (!editable) {
return;
}
@@ -55,7 +53,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;
@@ -85,7 +82,6 @@ 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;
@@ -100,38 +96,31 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
}
if (!mm.is_valid() && !mb.is_valid()) {
-
if (p_event->is_action_pressed("ui_left", true)) {
-
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)
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)
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)
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 +128,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;
@@ -173,7 +157,6 @@ void Slider::_notification(int p_what) {
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)));
@@ -190,7 +173,6 @@ void Slider::_notification(int p_what) {
}
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;
@@ -214,23 +196,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;
}
@@ -244,28 +222,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 94628f7cea..a82e9f7009 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -34,14 +34,12 @@
#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 != "")
value = prefix + " " + value;
@@ -51,7 +49,6 @@ void SpinBox::_value_changed(double) {
}
void SpinBox::_text_entered(const String &p_string) {
-
Ref<Expression> expr;
expr.instance();
// Ignore the prefix and suffix in the expression
@@ -68,7 +65,6 @@ void SpinBox::_text_entered(const String &p_string) {
}
LineEdit *SpinBox::get_line_edit() {
-
return line_edit;
}
@@ -76,9 +72,7 @@ void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
}
void SpinBox::_range_click_timeout() {
-
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 +88,6 @@ void SpinBox::_range_click_timeout() {
}
void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
-
if (!is_editable()) {
return;
}
@@ -102,13 +95,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 +111,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,7 +130,6 @@ 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();
@@ -158,14 +144,11 @@ 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) {
-
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
drag.enabled = true;
drag.base_val = get_value();
@@ -175,7 +158,6 @@ 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())
return;
@@ -184,7 +166,6 @@ void SpinBox::_line_edit_focus_exit() {
}
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 +174,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 +185,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 +226,6 @@ void SpinBox::set_editable(bool p_editable) {
}
bool SpinBox::is_editable() const {
-
return line_edit->is_editable();
}
@@ -265,7 +234,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 +254,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 de892a4fb9..14a4edc609 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -34,7 +34,6 @@
#include "margin_container.h"
Control *SplitContainer::_getch(int p_idx) const {
-
int idx = 0;
for (int i = 0; i < get_child_count(); i++) {
@@ -119,7 +118,6 @@ void SplitContainer::_resort() {
}
Size2 SplitContainer::get_minimum_size() const {
-
/* Calculate MINIMUM SIZE */
Size2i minimum;
@@ -128,12 +126,10 @@ 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))
break;
if (i == 1) {
-
if (vertical)
minimum.height += sep;
else
@@ -143,11 +139,9 @@ Size2 SplitContainer::get_minimum_size() const {
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,21 +151,16 @@ 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"))
update();
} break;
case NOTIFICATION_DRAW: {
-
if (!_getch(0) || !_getch(1))
return;
@@ -191,46 +180,36 @@ void SplitContainer::_notification(int p_what) {
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)
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,7 +218,6 @@ 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)
mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation");
@@ -247,7 +225,6 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
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"))
update();
@@ -264,20 +241,16 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
}
Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const {
-
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)
return CURSOR_VSPLIT;
} else {
-
if (p_pos.x > middle_sep && p_pos.x < middle_sep + sep)
return CURSOR_HSPLIT;
}
@@ -287,7 +260,6 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const
}
void SplitContainer::set_split_offset(int p_offset) {
-
if (split_offset == p_offset)
return;
@@ -297,7 +269,6 @@ void SplitContainer::set_split_offset(int p_offset) {
}
int SplitContainer::get_split_offset() const {
-
return split_offset;
}
@@ -308,7 +279,6 @@ void SplitContainer::clamp_split_offset() {
}
void SplitContainer::set_collapsed(bool p_collapsed) {
-
if (collapsed == p_collapsed)
return;
@@ -317,24 +287,20 @@ void SplitContainer::set_collapsed(bool p_collapsed) {
}
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 +325,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/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index 7252a43651..7d0dabeaca 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -34,12 +34,10 @@
#include "scene/main/viewport.h"
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)
continue;
@@ -53,19 +51,16 @@ Size2 SubViewportContainer::get_minimum_size() const {
}
void SubViewportContainer::set_stretch(bool p_enable) {
-
stretch = p_enable;
queue_sort();
update();
}
bool SubViewportContainer::is_stretch_enabled() const {
-
return stretch;
}
void SubViewportContainer::set_stretch_shrink(int p_shrink) {
-
ERR_FAIL_COND(p_shrink < 1);
if (shrink == p_shrink)
return;
@@ -76,7 +71,6 @@ void SubViewportContainer::set_stretch_shrink(int p_shrink) {
return;
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
if (!c)
continue;
@@ -88,19 +82,15 @@ void SubViewportContainer::set_stretch_shrink(int p_shrink) {
}
int SubViewportContainer::get_stretch_shrink() const {
-
return shrink;
}
void SubViewportContainer::_notification(int p_what) {
-
if (p_what == NOTIFICATION_RESIZED) {
-
if (!stretch)
return;
for (int i = 0; i < get_child_count(); i++) {
-
SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
if (!c)
continue;
@@ -110,9 +100,7 @@ void SubViewportContainer::_notification(int p_what) {
}
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)
continue;
@@ -127,9 +115,7 @@ void SubViewportContainer::_notification(int p_what) {
}
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)
continue;
@@ -143,7 +129,6 @@ void SubViewportContainer::_notification(int p_what) {
}
void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
-
if (Engine::get_singleton()->is_editor_hint())
return;
@@ -158,7 +143,6 @@ void SubViewportContainer::_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())
continue;
@@ -168,7 +152,6 @@ void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
}
void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
-
if (Engine::get_singleton()->is_editor_hint())
return;
@@ -183,7 +166,6 @@ void SubViewportContainer::_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())
continue;
@@ -193,7 +175,6 @@ void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
}
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);
@@ -207,7 +188,6 @@ void SubViewportContainer::_bind_methods() {
}
SubViewportContainer::SubViewportContainer() {
-
stretch = false;
shrink = 1;
set_process_input(true);
diff --git a/scene/gui/subviewport_container.h b/scene/gui/subviewport_container.h
index 13b711f838..fc4c9f925a 100644
--- a/scene/gui/subviewport_container.h
+++ b/scene/gui/subviewport_container.h
@@ -34,7 +34,6 @@
#include "scene/gui/container.h"
class SubViewportContainer : public Container {
-
GDCLASS(SubViewportContainer, Container);
bool stretch;
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 3a128cf8e6..501e50e7f7 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -36,7 +36,6 @@
#include "scene/gui/texture_rect.h"
int TabContainer::_get_top_margin() const {
-
if (!tabs_visible)
return 0;
@@ -53,7 +52,6 @@ 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"))
continue;
@@ -68,11 +66,9 @@ 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();
@@ -144,13 +140,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 +155,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 +187,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 +204,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");
@@ -257,7 +244,6 @@ void TabContainer::_notification(int p_what) {
}
} break;
case NOTIFICATION_DRAW: {
-
RID canvas = get_canvas_item();
Size2 size = get_size();
@@ -412,7 +398,6 @@ void TabContainer::_notification(int p_what) {
// 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 +414,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,7 +435,6 @@ 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))
@@ -488,10 +471,8 @@ 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())
continue;
@@ -502,12 +483,10 @@ 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);
@@ -543,12 +522,10 @@ void TabContainer::add_child_notify(Node *p_child) {
}
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,7 +534,6 @@ 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();
@@ -587,17 +563,14 @@ 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())
return tabs[p_idx];
@@ -606,7 +579,6 @@ Control *TabContainer::get_tab_control(int p_idx) const {
}
Control *TabContainer::get_current_tab_control() const {
-
Vector<Control *> tabs = _get_tabs();
if (current >= 0 && current < tabs.size())
return tabs[current];
@@ -615,7 +587,6 @@ Control *TabContainer::get_current_tab_control() const {
}
void TabContainer::remove_child_notify(Node *p_child) {
-
Container::remove_child_notify(p_child);
call_deferred("_update_current_tab");
@@ -626,7 +597,6 @@ void TabContainer::remove_child_notify(Node *p_child) {
}
void TabContainer::_update_current_tab() {
-
int tc = get_tab_count();
if (current >= tc)
current = tc - 1;
@@ -637,7 +607,6 @@ void TabContainer::_update_current_tab() {
}
Variant TabContainer::get_drag_data(const Point2 &p_point) {
-
if (!drag_to_rearrange_enabled)
return Variant();
@@ -666,7 +635,6 @@ 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)
return false;
@@ -675,7 +643,6 @@ bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) c
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,7 +660,6 @@ 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)
return;
@@ -704,7 +670,6 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
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();
@@ -733,7 +698,6 @@ 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)
return -1;
@@ -772,7 +736,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,12 +744,10 @@ 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)
return;
@@ -794,7 +755,6 @@ void TabContainer::set_tabs_visible(bool p_visible) {
Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) {
-
Control *c = tabs[i];
if (p_visible)
c->set_margin(MARGIN_TOP, _get_top_margin());
@@ -807,17 +767,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,7 +782,6 @@ 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"))
@@ -835,14 +791,12 @@ String TabContainer::get_tab_title(int p_tab) const {
}
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 {
-
Control *child = _get_tab(p_tab);
ERR_FAIL_COND_V(!child, Ref<Texture2D>());
if (child->has_meta("_tab_icon"))
@@ -852,7 +806,6 @@ Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
}
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,7 +813,6 @@ 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"))
@@ -870,7 +822,6 @@ bool TabContainer::get_tab_disabled(int p_tab) const {
}
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,7 +841,6 @@ 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"))
@@ -900,10 +850,8 @@ bool TabContainer::get_tab_hidden(int p_tab) const {
}
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"))
@@ -917,12 +865,10 @@ void TabContainer::get_translatable_strings(List<String> *p_strings) const {
}
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)
@@ -983,7 +929,6 @@ 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);
@@ -1030,7 +975,6 @@ void TabContainer::_bind_methods() {
}
TabContainer::TabContainer() {
-
first_tab_cache = 0;
last_tab_cache = 0;
buttons_visible_cache = 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 b856d3ab3a..2dce34daf0 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,7 +44,6 @@ 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);
@@ -84,16 +82,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 +109,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 +128,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 +138,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 +148,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");
@@ -185,7 +174,6 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
int found = -1;
for (int i = offset; i < tabs.size(); i++) {
-
if (tabs[i].rb_rect.has_point(pos)) {
rb_pressing = true;
update();
@@ -207,7 +195,6 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
if (found != -1) {
-
set_current_tab(found);
emit_signal("tab_clicked", found);
}
@@ -216,9 +203,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);
@@ -249,7 +234,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);
}
@@ -274,7 +258,6 @@ void Tabs::_notification(int p_what) {
missing_right = false;
for (int i = offset; i < tabs.size(); i++) {
-
tabs.write[i].ofs_cache = w;
int lsize = tabs[i].size_cache;
@@ -309,7 +292,6 @@ 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 != "")
w += icon->get_width() + get_theme_constant("hseparation");
@@ -320,7 +302,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;
@@ -344,7 +325,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;
@@ -371,7 +351,6 @@ void Tabs::_notification(int p_what) {
}
if (offset > 0 || missing_right) {
-
int vofs = (get_size().height - incr->get_size().height) / 2;
if (offset > 0)
@@ -393,12 +372,10 @@ 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;
ERR_FAIL_INDEX(p_current, get_tab_count());
@@ -413,7 +390,6 @@ void Tabs::set_current_tab(int p_current) {
}
int Tabs::get_current_tab() const {
-
return current;
}
@@ -430,7 +406,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);
@@ -439,13 +414,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();
@@ -453,25 +426,21 @@ 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 {
-
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();
@@ -479,13 +448,11 @@ void Tabs::set_tab_right_button(int p_tab, const Ref<Texture2D> &p_right_button)
minimum_size_changed();
}
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;
}
@@ -495,7 +462,6 @@ void Tabs::_update_hover() {
int hover_now = -1;
int hover_buttons = -1;
for (int i = offset; i < tabs.size(); i++) {
-
Rect2 rect = get_tab_rect(i);
if (rect.has_point(pos)) {
hover_now = i;
@@ -552,7 +518,6 @@ void Tabs::_update_cache() {
m_width = MAX((limit - size_fixed) / count_resize, min_width);
}
for (int i = offset; i < tabs.size(); i++) {
-
Ref<StyleBox> sb;
if (tabs[i].disabled) {
sb = tab_disabled;
@@ -587,7 +552,6 @@ void Tabs::_update_cache() {
}
void Tabs::_on_mouse_exited() {
-
rb_hover = -1;
cb_hover = -1;
hover = -1;
@@ -596,7 +560,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);
@@ -620,7 +583,6 @@ 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)
@@ -639,7 +601,6 @@ void Tabs::remove_tab(int p_idx) {
}
Variant Tabs::get_drag_data(const Point2 &p_point) {
-
if (!drag_to_rearrange_enabled)
return Variant();
@@ -672,7 +633,6 @@ 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)
return false;
@@ -681,7 +641,6 @@ bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
return false;
if (String(d["type"]) == "tab_element") {
-
NodePath from_path = d["from_path"];
NodePath to_path = get_path();
if (from_path == to_path) {
@@ -699,7 +658,6 @@ 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)
return;
@@ -710,7 +668,6 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
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();
@@ -742,10 +699,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 = offset; i < tabs.size(); i++) {
-
Rect2 rect = get_tab_rect(i);
if (rect.has_point(p_point)) {
hover_now = i;
@@ -756,19 +711,16 @@ 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)
return;
@@ -784,7 +736,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");
@@ -826,7 +777,6 @@ int Tabs::get_tab_width(int p_idx) const {
}
void Tabs::_ensure_no_over_offset() {
-
if (!is_inside_tree())
return;
@@ -836,10 +786,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 = offset - 1; i < tabs.size(); i++) {
-
total_w += tabs[i].size_cache;
}
@@ -853,7 +801,6 @@ void Tabs::_ensure_no_over_offset() {
}
void Tabs::ensure_tab_visible(int p_idx) {
-
if (!is_inside_tree())
return;
@@ -886,20 +833,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;
}
@@ -939,7 +883,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);
@@ -997,7 +940,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 e986e350f3..ee1391806e 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -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 == '_';
}
@@ -113,17 +110,14 @@ static int _find_first_non_whitespace_column_of_line(const String &line) {
}
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,7 +138,6 @@ 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]))
continue;
if (str[i] == '\\') {
@@ -155,7 +148,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 +169,6 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
}
if (match) {
-
ColorRegionInfo cri;
cri.end = false;
cri.region = j;
@@ -204,7 +195,6 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
}
if (match) {
-
ColorRegionInfo cri;
cri.end = true;
cri.region = j;
@@ -219,7 +209,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 +220,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 +230,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 +260,6 @@ void TextEdit::Text::clear_info_icons() {
}
void TextEdit::Text::clear() {
-
text.clear();
insert(0, "");
}
@@ -293,7 +276,6 @@ int TextEdit::Text::get_max_width(bool p_exclude_hidden) const {
}
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 +284,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;
@@ -316,31 +297,26 @@ void TextEdit::Text::insert(int p_at, const String &p_text) {
text.insert(p_at, line);
}
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)
w = tab_w;
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();
@@ -384,11 +360,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 +375,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 +386,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,7 +393,6 @@ 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);
@@ -432,7 +403,6 @@ void TextEdit::_update_scrollbars() {
}
} else {
-
cursor.x_ofs = 0;
h_scroll->set_value(0);
h_scroll->hide();
@@ -442,7 +412,6 @@ 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.
@@ -597,7 +566,6 @@ void TextEdit::_update_minimap_click() {
}
void TextEdit::_update_minimap_drag() {
-
if (!can_drag_minimap) {
return;
}
@@ -614,7 +582,6 @@ void TextEdit::_update_minimap_drag() {
}
void TextEdit::_notification(int p_what) {
-
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_caches();
@@ -718,7 +685,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 {
@@ -778,7 +744,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 +758,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 == '\'') {
@@ -859,14 +821,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 == '\'') {
@@ -957,7 +916,6 @@ void TextEdit::_notification(int p_what) {
Color viewport_color = (cache.background_color.get_v() < 0.5) ? Color(1, 1, 1, 0.1) : Color(0, 0, 0, 0.1);
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()) {
@@ -1078,7 +1036,6 @@ 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())
@@ -1286,7 +1243,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;
@@ -1307,7 +1263,6 @@ 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.
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);
@@ -1373,7 +1328,6 @@ void TextEdit::_notification(int p_what) {
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);
@@ -1403,7 +1357,6 @@ 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)
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);
@@ -1411,7 +1364,6 @@ void TextEdit::_notification(int p_what) {
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)
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);
@@ -1419,7 +1371,6 @@ void TextEdit::_notification(int p_what) {
}
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;
@@ -1516,7 +1467,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;
@@ -1636,7 +1586,6 @@ void TextEdit::_notification(int p_what) {
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;
@@ -1688,7 +1637,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");
@@ -1698,7 +1646,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);
@@ -1756,7 +1703,6 @@ void TextEdit::_notification(int p_what) {
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
-
if (caret_blink_enabled) {
caret_blink_timer->start();
} else {
@@ -1773,7 +1719,6 @@ void TextEdit::_notification(int p_what) {
DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect());
} break;
case NOTIFICATION_FOCUS_EXIT: {
-
if (caret_blink_enabled) {
caret_blink_timer->stop();
}
@@ -1789,7 +1734,6 @@ void TextEdit::_notification(int p_what) {
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();
@@ -1800,7 +1744,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 };
@@ -1808,7 +1751,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();
@@ -1907,11 +1849,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];
@@ -1985,7 +1925,6 @@ void TextEdit::backspace_at_cursor() {
}
void TextEdit::indent_right() {
-
int start_line;
int end_line;
@@ -2034,7 +1973,6 @@ void TextEdit::indent_right() {
}
void TextEdit::indent_left() {
-
int start_line;
int end_line;
@@ -2105,7 +2043,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();
@@ -2115,7 +2052,6 @@ 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)
row = first_vis_line - f_ofs;
@@ -2129,11 +2065,9 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
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);
@@ -2192,7 +2126,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);
@@ -2226,7 +2159,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;
@@ -2247,7 +2179,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();
@@ -2255,7 +2186,6 @@ 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())
return;
@@ -2267,7 +2197,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];
@@ -2276,7 +2205,6 @@ 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];
@@ -2291,7 +2219,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()));
@@ -2313,7 +2240,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;
@@ -2341,7 +2267,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) {
@@ -2379,7 +2304,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;
@@ -2399,9 +2323,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);
@@ -2411,7 +2333,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);
@@ -2428,7 +2349,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;
@@ -2436,13 +2356,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();
@@ -2453,7 +2371,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;
@@ -2461,7 +2378,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();
@@ -2485,7 +2401,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;
@@ -2508,7 +2423,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);
@@ -2525,10 +2439,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);
@@ -2572,7 +2484,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventKey> k = p_gui_input;
if (k.is_valid()) {
-
k = k->duplicate(); // It will be modified later on.
#ifdef OSX_ENABLED
@@ -2582,7 +2493,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 {
@@ -2603,10 +2513,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
valid = false;
if (valid) {
-
if (!k->get_alt()) {
if (k->get_keycode() == KEY_UP) {
-
if (completion_index > 0) {
completion_index--;
} else {
@@ -2620,7 +2528,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 {
@@ -2634,7 +2541,6 @@ 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)
completion_index = 0;
@@ -2645,7 +2551,6 @@ 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())
completion_index = completion_options.size() - 1;
@@ -2656,7 +2561,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();
@@ -2665,7 +2569,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();
@@ -2674,14 +2577,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();
@@ -2697,14 +2598,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();
@@ -2735,11 +2634,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);
@@ -2782,13 +2679,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();
@@ -2844,7 +2739,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
update();
}
if (clear) {
-
if (!dobreak) {
begin_complex_operation();
}
@@ -2866,10 +2760,8 @@ 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)
break;
@@ -2931,7 +2823,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)) {
@@ -3005,7 +2896,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];
@@ -3124,7 +3014,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_LEFT: {
-
if (k->get_shift())
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
@@ -3179,7 +3068,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());
@@ -3200,7 +3088,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_RIGHT: {
-
if (k->get_shift())
_pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
@@ -3240,7 +3127,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);
@@ -3261,7 +3147,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_UP: {
-
if (k->get_alt()) {
keycode_handled = false;
break;
@@ -3281,7 +3166,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
@@ -3314,7 +3198,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_DOWN: {
-
if (k->get_alt()) {
keycode_handled = false;
break;
@@ -3355,7 +3238,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_DELETE: {
-
if (readonly)
break;
@@ -3455,7 +3337,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
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();
@@ -3545,7 +3426,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEUP: {
-
if (k->get_shift())
_pre_shift_selection();
@@ -3568,7 +3448,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
[[fallthrough]];
}
case KEY_PAGEDOWN: {
-
if (k->get_shift())
_pre_shift_selection();
@@ -3584,7 +3463,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_A: {
-
#ifndef APPLE_STYLE_KEYS
if (!k->get_control() || k->get_shift() || k->get_alt()) {
keycode_handled = false;
@@ -3624,7 +3502,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;
@@ -3660,7 +3537,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;
@@ -3672,7 +3548,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
case KEY_Z: {
-
if (readonly) {
break;
}
@@ -3690,7 +3565,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} break;
case KEY_Y: {
-
if (readonly) {
break;
}
@@ -3744,7 +3618,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} break;
default: {
-
keycode_handled = false;
} break;
}
@@ -3761,7 +3634,6 @@ 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)
return;
@@ -3802,7 +3674,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;
@@ -3830,7 +3701,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;
@@ -3859,9 +3729,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;
@@ -3871,9 +3739,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();
}
@@ -3924,7 +3790,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);
@@ -3951,7 +3816,6 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
/* 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(' '));
}
@@ -3964,15 +3828,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);
}
}
@@ -4003,7 +3864,6 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
}
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());
@@ -4014,7 +3874,6 @@ 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();
@@ -4027,7 +3886,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());
@@ -4065,7 +3923,6 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li
}
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())
idle_detect->start();
@@ -4119,7 +3976,6 @@ 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())
idle_detect->start();
@@ -4168,7 +4024,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();
@@ -4195,11 +4050,9 @@ 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)
totalsize++; // Include \n.
totalsize += text[i].length();
@@ -4209,7 +4062,6 @@ int TextEdit::get_char_count() {
}
Size2 TextEdit::get_minimum_size() const {
-
return cache.style_normal->get_minimum_size();
}
@@ -4250,7 +4102,6 @@ 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())
@@ -4267,7 +4118,6 @@ 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();
@@ -4282,7 +4132,6 @@ void TextEdit::_update_wrap_at() {
}
void TextEdit::adjust_viewport_to_cursor() {
-
// Make sure cursor is visible on the screen.
scrolling = false;
minimap_clicked = false;
@@ -4326,7 +4175,6 @@ 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;
@@ -4368,7 +4216,6 @@ 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())
return false;
@@ -4376,7 +4223,6 @@ bool TextEdit::line_wraps(int line) const {
}
int TextEdit::times_line_wraps(int line) const {
-
ERR_FAIL_INDEX_V(line, text.size(), 0);
if (!line_wraps(line))
return 0;
@@ -4393,7 +4239,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;
@@ -4466,12 +4311,10 @@ 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))
@@ -4512,7 +4355,6 @@ void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
}
void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
-
if (setting_row)
return;
@@ -4565,12 +4407,10 @@ void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_
}
int TextEdit::cursor_get_column() const {
-
return cursor.column;
}
int TextEdit::cursor_get_line() const {
-
return cursor.line;
}
@@ -4624,14 +4464,12 @@ void TextEdit::_v_scroll_input() {
}
void TextEdit::_scroll_moved(double p_to_val) {
-
if (updating_scrolls)
return;
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;
@@ -4656,16 +4494,13 @@ 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) {
@@ -4686,17 +4521,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);
@@ -4720,18 +4552,15 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
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))
@@ -4744,11 +4573,9 @@ 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())
break;
@@ -4759,9 +4586,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);
@@ -4783,7 +4608,6 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
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);
@@ -4833,7 +4657,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();
@@ -4862,7 +4685,6 @@ String TextEdit::get_text() {
String longthing;
int len = text.size();
for (int i = 0; i < len; i++) {
-
longthing += text[i];
if (i != len - 1)
longthing += "\n";
@@ -4872,20 +4694,17 @@ String TextEdit::get_text() {
};
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];
}
@@ -4897,17 +4716,14 @@ String TextEdit::get_text_for_lookup_completion() {
}
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];
}
@@ -4919,7 +4735,6 @@ String TextEdit::get_text_for_completion() {
};
String TextEdit::get_line(int line) const {
-
if (line < 0 || line >= text.size())
return "";
@@ -4927,7 +4742,6 @@ String TextEdit::get_line(int line) const {
};
void TextEdit::_clear() {
-
clear_undo_history();
text.clear();
cursor.column = 0;
@@ -4940,14 +4754,12 @@ void TextEdit::_clear() {
}
void TextEdit::clear() {
-
setting_text = true;
_clear();
setting_text = false;
};
void TextEdit::set_readonly(bool p_readonly) {
-
if (readonly == p_readonly)
return;
@@ -4984,27 +4796,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;
}
@@ -5027,7 +4834,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");
@@ -5095,7 +4901,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];
@@ -5153,7 +4958,6 @@ Map<int, TextEdit::Text::ColorRegionInfo> TextEdit::_get_line_color_region_info(
}
void TextEdit::clear_colors() {
-
keywords.clear();
member_keywords.clear();
color_regions.clear();
@@ -5164,7 +4968,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();
@@ -5175,13 +4978,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();
@@ -5209,13 +5010,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;
}
@@ -5224,9 +5023,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);
@@ -5244,7 +5041,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);
@@ -5260,11 +5056,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;
@@ -5277,12 +5070,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);
@@ -5290,7 +5081,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;
@@ -5323,7 +5113,6 @@ void TextEdit::select_all() {
}
void TextEdit::deselect() {
-
selection.active = false;
update();
}
@@ -5358,26 +5147,20 @@ 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;
}
@@ -5390,32 +5173,26 @@ void TextEdit::swap_lines(int line1, int line2) {
set_line(line1, tmp2);
}
bool TextEdit::is_selection_active() const {
-
return selection.active;
}
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 {
-
ERR_FAIL_COND_V(!selection.active, -1);
return selection.from_column;
}
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 {
-
ERR_FAIL_COND_V(!selection.active, -1);
return selection.to_column;
}
String TextEdit::get_selection_text() const {
-
if (!selection.active)
return "";
@@ -5423,7 +5200,6 @@ String TextEdit::get_selection_text() const {
}
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]);
@@ -5500,7 +5276,6 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
}
Vector<int> 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;
@@ -5510,13 +5285,11 @@ Vector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags,
return result;
} else {
-
return Vector<int>();
}
}
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)
return false;
ERR_FAIL_INDEX_V(p_from_line, text.size(), false);
@@ -5528,7 +5301,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;
}
@@ -5539,7 +5311,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.
@@ -5550,7 +5321,6 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
}
} else {
-
from_column = p_from_column;
}
@@ -5567,7 +5337,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) {
@@ -5633,19 +5402,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();
@@ -5674,20 +5440,17 @@ 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))
p_bookmarks->push_back(i);
@@ -5695,7 +5458,6 @@ void TextEdit::get_bookmarks(List<int> *p_bookmarks) const {
}
Array TextEdit::get_bookmarks_array() const {
-
Array arr;
for (int i = 0; i < text.size(); i++) {
if (text.is_bookmark(i))
@@ -5705,20 +5467,17 @@ Array TextEdit::get_bookmarks_array() const {
}
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))
p_breakpoints->push_back(i);
@@ -5726,7 +5485,6 @@ void TextEdit::get_breakpoints(List<int> *p_breakpoints) const {
}
Array TextEdit::get_breakpoints_array() const {
-
Array arr;
for (int i = 0; i < text.size(); i++) {
if (text.is_breakpoint(i))
@@ -5755,7 +5513,6 @@ 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)
text.set_hidden(p_line, p_hidden);
@@ -5763,13 +5520,11 @@ void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
}
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);
}
@@ -5778,7 +5533,6 @@ void TextEdit::fold_all_lines() {
}
void TextEdit::unhide_all_lines() {
-
for (int i = 0; i < text.size(); i++) {
text.set_hidden(i, false);
}
@@ -5787,7 +5541,6 @@ 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));
@@ -5820,7 +5573,6 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
}
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;
@@ -5867,7 +5619,6 @@ 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())
return text.size() - 1;
@@ -5882,7 +5633,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.
@@ -5902,7 +5652,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);
@@ -5923,7 +5672,6 @@ 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())
return false;
@@ -5957,7 +5705,6 @@ 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())
return false;
@@ -5976,7 +5723,6 @@ 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())
return;
@@ -6022,7 +5768,6 @@ 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))
@@ -6046,7 +5791,6 @@ 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))
@@ -6056,12 +5800,10 @@ void TextEdit::toggle_fold_line(int 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;
@@ -6069,20 +5811,17 @@ void TextEdit::_do_text_op(const TextOperation &p_op, bool 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 == nullptr)
return; // Nothing to clear.
@@ -6096,11 +5835,9 @@ void TextEdit::_clear_redo() {
}
void TextEdit::undo() {
-
_push_current_op();
if (undo_stack_pos == nullptr) {
-
if (!undo_stack.size())
return; // Nothing to undo.
@@ -6145,7 +5882,6 @@ void TextEdit::undo() {
}
void TextEdit::redo() {
-
_push_current_op();
if (undo_stack_pos == nullptr)
@@ -6157,7 +5893,6 @@ 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();
@@ -6177,7 +5912,6 @@ void TextEdit::redo() {
}
void TextEdit::clear_undo_history() {
-
saved_version = 0;
current_op.type = TextOperation::TYPE_NONE;
undo_stack_pos = nullptr;
@@ -6190,7 +5924,6 @@ void TextEdit::begin_complex_operation() {
}
void TextEdit::end_complex_operation() {
-
_push_current_op();
ERR_FAIL_COND(undo_stack.size() == 0);
@@ -6203,7 +5936,6 @@ void TextEdit::end_complex_operation() {
}
void TextEdit::_push_current_op() {
-
if (current_op.type == TextOperation::TYPE_NONE)
return; // Nothing to do.
@@ -6244,28 +5976,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,17 +6022,14 @@ 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())
return p_line;
@@ -6323,12 +6047,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 +6059,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 +6066,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 +6079,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 +6086,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,18 +6094,15 @@ 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)
@@ -6396,12 +6110,10 @@ void TextEdit::set_v_scroll(double p_scroll) {
}
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,28 +6121,23 @@ 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++)
@@ -6438,7 +6145,6 @@ void TextEdit::set_completion(bool p_enabled, const Vector<String> &p_prefixes)
}
void TextEdit::_confirm_completion() {
-
begin_complex_operation();
_remove_text(cursor.line, cursor.column - completion_base.length(), cursor.line, cursor.column);
@@ -6456,7 +6162,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 +6169,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,13 +6185,11 @@ void TextEdit::_confirm_completion() {
}
void TextEdit::_cancel_code_hint() {
-
completion_hint = "";
update();
}
void TextEdit::_cancel_completion() {
-
if (!completion_active)
return;
@@ -6497,12 +6199,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());
@@ -6536,7 +6236,6 @@ 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;
@@ -6552,7 +6251,6 @@ 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] == '$')
@@ -6610,7 +6308,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)) {
@@ -6685,7 +6382,6 @@ void TextEdit::_update_completion_candidates() {
}
void TextEdit::query_code_comple() {
-
String l = text[cursor.line];
int ofs = CLAMP(cursor.column, 0, l.length());
@@ -6725,14 +6421,12 @@ void TextEdit::query_code_comple() {
}
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,7 +6436,6 @@ 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);
@@ -6751,7 +6444,6 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
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,7 +6473,6 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
}
String TextEdit::get_tooltip(const Point2 &p_pos) const {
-
if (!tooltip_obj)
return Control::get_tooltip(p_pos);
int row, col;
@@ -6792,7 +6483,6 @@ String TextEdit::get_tooltip(const Point2 &p_pos) const {
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,7 +6492,6 @@ 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;
@@ -6840,13 +6529,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();
}
@@ -6972,12 +6659,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 +6700,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;
}
@@ -7060,7 +6743,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);
@@ -7250,7 +6932,6 @@ void TextEdit::_bind_methods() {
}
TextEdit::TextEdit() {
-
setting_row = false;
draw_tabs = false;
draw_spaces = false;
@@ -7496,7 +7177,6 @@ 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]))
to++;
@@ -7528,7 +7208,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++;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index ac8eb5da1d..689199b6c2 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,
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 5f2e4cf58e..325b9d00ed 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -33,7 +33,6 @@
#include <stdlib.h>
Size2 TextureButton::get_minimum_size() const {
-
Size2 rscale = Control::get_minimum_size();
if (!expand) {
@@ -57,9 +56,7 @@ Size2 TextureButton::get_minimum_size() const {
}
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 +113,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,13 +121,11 @@ void TextureButton::_notification(int p_what) {
switch (draw_mode) {
case DRAW_NORMAL: {
-
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())
@@ -144,7 +137,6 @@ void TextureButton::_notification(int p_what) {
texdraw = pressed;
} break;
case DRAW_HOVER: {
-
if (hover.is_null()) {
if (pressed.is_valid() && is_pressed())
texdraw = pressed;
@@ -154,7 +146,6 @@ void TextureButton::_notification(int p_what) {
texdraw = hover;
} break;
case DRAW_DISABLED: {
-
if (disabled.is_null()) {
if (normal.is_valid())
texdraw = normal;
@@ -232,7 +223,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 +261,49 @@ 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) {
-
hover = p_hover;
update();
}
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) {
-
click_mask = p_click_mask;
update();
}
Ref<Texture2D> TextureButton::get_normal_texture() const {
-
return normal;
}
Ref<Texture2D> TextureButton::get_pressed_texture() const {
-
return pressed;
}
Ref<Texture2D> TextureButton::get_hover_texture() const {
-
return hover;
}
Ref<Texture2D> TextureButton::get_disabled_texture() const {
-
return disabled;
}
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 0dd43e4a35..5edb10958c 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,7 +77,6 @@ bool TextureProgress::get_nine_patch_stretch() const {
}
Size2 TextureProgress::get_minimum_size() const {
-
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())
@@ -95,14 +90,12 @@ Size2 TextureProgress::get_minimum_size() const {
}
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;
}
@@ -306,9 +299,7 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture2D> &p_texture,
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);
@@ -463,7 +454,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 92f3c5b5d9..58e7249284 100644
--- a/scene/gui/texture_rect.cpp
+++ b/scene/gui/texture_rect.cpp
@@ -33,9 +33,7 @@
#include "servers/rendering_server.h"
void TextureRect::_notification(int p_what) {
-
if (p_what == NOTIFICATION_DRAW) {
-
if (texture.is_null()) {
return;
}
@@ -116,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 {
@@ -125,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);
@@ -154,7 +150,6 @@ void TextureRect::_bind_methods() {
}
void TextureRect::_texture_changed() {
-
if (texture.is_valid()) {
update();
minimum_size_changed();
@@ -162,7 +157,6 @@ void TextureRect::_texture_changed() {
}
void TextureRect::set_texture(const Ref<Texture2D> &p_tex) {
-
if (p_tex == texture) {
return;
}
@@ -182,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 4a550727fc..c0bdc3923b 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -47,7 +47,6 @@
#include <limits.h>
void TreeItem::move_to_top() {
-
if (!parent || parent->children == this)
return; //already on top
TreeItem *prev = get_prev();
@@ -75,7 +74,6 @@ void TreeItem::move_to_bottom() {
}
Size2 TreeItem::Cell::get_icon_size() const {
-
if (icon.is_null())
return Size2();
if (icon_region == Rect2i())
@@ -85,44 +83,36 @@ Size2 TreeItem::Cell::get_icon_size() const {
}
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())
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 +128,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 +166,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,66 +178,56 @@ 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)
p_value = Math::stepify(p_value, cells[p_column].step);
@@ -268,18 +241,15 @@ void TreeItem::set_range(int p_column, double p_value) {
}
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) {
-
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].min = p_min;
cells.write[p_column].max = p_max;
@@ -289,7 +259,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 +266,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 +285,20 @@ 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)
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 +311,6 @@ void TreeItem::set_collapsed(bool p_collapsed) {
}
bool TreeItem::is_collapsed() {
-
return collapsed;
}
@@ -364,12 +324,10 @@ int TreeItem::get_custom_minimum_height() const {
}
TreeItem *TreeItem::get_next() {
-
return next;
}
TreeItem *TreeItem::get_prev() {
-
if (!parent || parent->children == this)
return nullptr;
@@ -381,23 +339,19 @@ TreeItem *TreeItem::get_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 nullptr;
@@ -414,7 +368,6 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) {
}
}
} else {
-
current = prev;
while (!current->collapsed && current->children) {
//go to the very end
@@ -429,20 +382,15 @@ 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;
}
@@ -460,14 +408,11 @@ 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;
@@ -483,25 +428,21 @@ 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)
return;
@@ -513,19 +454,16 @@ void TreeItem::set_as_cursor(int p_column) {
}
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;
@@ -540,7 +478,6 @@ 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();
}
@@ -560,7 +497,6 @@ int TreeItem::get_button_id(int p_column, int p_idx) const {
return cells[p_column].buttons[p_idx].id;
}
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,10 +504,8 @@ 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)
return i;
}
@@ -580,7 +514,6 @@ int TreeItem::get_button_by_id(int p_column, int p_id) const {
}
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 +522,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 +529,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 +537,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 +544,29 @@ 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 {
-
ERR_FAIL_INDEX_V(p_column, cells.size(), Color());
if (!cells[p_column].custom_color)
return Color();
return cells[p_column].color;
}
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 +574,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 +592,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,7 +599,6 @@ 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)
return Color();
@@ -686,13 +606,11 @@ Color TreeItem::get_custom_bg_color(int p_column) const {
}
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 +627,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 +647,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 +683,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);
@@ -887,10 +800,8 @@ void TreeItem::_bind_methods() {
}
void TreeItem::clear_children() {
-
TreeItem *c = children;
while (c) {
-
TreeItem *aux = c;
c = c->get_next();
aux->parent = nullptr; // so it won't try to recursively autoremove from me in here
@@ -901,7 +812,6 @@ void TreeItem::clear_children() {
};
TreeItem::TreeItem(Tree *p_tree) {
-
tree = p_tree;
collapsed = false;
disable_folding = false;
@@ -913,14 +823,12 @@ TreeItem::TreeItem(Tree *p_tree) {
}
TreeItem::~TreeItem() {
-
clear_children();
if (parent)
parent->remove_child(this);
if (tree && tree->root == this) {
-
tree->root = nullptr;
}
@@ -956,7 +864,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");
@@ -1001,7 +908,6 @@ void Tree::update_cache() {
}
int Tree::compute_item_height(TreeItem *p_item) const {
-
if (p_item == root && hide_root)
return 0;
@@ -1009,9 +915,7 @@ int Tree::compute_item_height(TreeItem *p_item) const {
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)
@@ -1019,9 +923,7 @@ int Tree::compute_item_height(TreeItem *p_item) const {
}
switch (p_item->cells[i].mode) {
-
case TreeItem::CELL_MODE_CHECK: {
-
int check_icon_h = cache.checked->get_height();
if (height < check_icon_h)
height = check_icon_h;
@@ -1030,10 +932,8 @@ int Tree::compute_item_height(TreeItem *p_item) const {
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;
@@ -1060,7 +960,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;
@@ -1069,7 +968,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;
@@ -1080,7 +978,6 @@ 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;
@@ -1130,7 +1027,6 @@ 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))
return -1; //draw no more!
@@ -1148,7 +1044,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)
@@ -1160,7 +1055,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;
@@ -1169,22 +1063,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);
@@ -1227,7 +1117,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
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);
@@ -1259,7 +1148,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;
@@ -1279,7 +1167,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
if (drop_mode_flags && drop_mode_over == p_item) {
-
Rect2 r = cell_rect;
if (drop_mode_section == -1 || drop_mode_section == 0) {
@@ -1303,13 +1190,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;
@@ -1333,7 +1217,6 @@ 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)
break;
@@ -1365,7 +1248,6 @@ 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));
@@ -1387,7 +1269,6 @@ 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())
break;
Size2i icon_size = p_item->cells[i].get_icon_size();
@@ -1403,16 +1284,13 @@ 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)
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;
}
@@ -1449,15 +1327,12 @@ 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())
cache.cursor->draw(ci, cell_rect);
else
@@ -1470,7 +1345,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;
@@ -1495,7 +1369,6 @@ 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);
@@ -1546,7 +1419,6 @@ 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))
@@ -1564,7 +1436,6 @@ 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) {
-
TreeItem::Cell &selected_cell = p_selected->cells.write[p_col];
bool switched = false;
@@ -1576,14 +1447,12 @@ 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)
continue;
if (select_mode == SELECT_ROW) {
-
if (p_selected == p_current && (!c.selected || allow_reselect)) {
c.selected = true;
selected_item = p_selected;
@@ -1598,16 +1467,12 @@ 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;
@@ -1620,15 +1485,12 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
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);
@@ -1651,21 +1513,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 && 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();
@@ -1706,7 +1564,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);
@@ -1719,7 +1576,6 @@ 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)
p_item->set_collapsed(!p_item->is_collapsed());
@@ -1732,11 +1588,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;
@@ -1764,7 +1618,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
col_ofs += margin;
x -= margin;
} else {
-
col_width -= cache.hseparation;
x -= cache.hseparation;
}
@@ -1815,9 +1668,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) {
@@ -1826,18 +1677,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);
@@ -1845,14 +1692,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);
}
@@ -1882,7 +1727,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
@@ -1892,7 +1736,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()) {
@@ -1913,7 +1756,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());
}
@@ -1926,16 +1768,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;
@@ -1944,7 +1782,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
}
@@ -1953,15 +1790,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);
}
@@ -1970,7 +1804,6 @@ 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)
bring_up_editor = false;
@@ -2014,7 +1847,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) {
@@ -2029,7 +1861,6 @@ 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)
@@ -2050,11 +1881,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
}
void Tree::_text_editor_modal_close() {
-
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;
}
@@ -2065,7 +1894,6 @@ void Tree::_text_editor_modal_close() {
}
void Tree::_text_editor_enter(String p_text) {
-
popup_editor->hide();
if (!popup_edited_item)
@@ -2076,14 +1904,11 @@ void Tree::_text_editor_enter(String p_text) {
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)
c.val = Math::stepify(c.val, c.step);
@@ -2104,7 +1929,6 @@ void Tree::_text_editor_enter(String p_text) {
}
void Tree::value_editor_changed(double p_value) {
-
if (updating_value_editor) {
return;
}
@@ -2119,7 +1943,6 @@ void Tree::value_editor_changed(double p_value) {
}
void Tree::popup_select(int p_option) {
-
if (!popup_edited_item)
return;
@@ -2152,7 +1975,6 @@ void Tree::_go_left() {
selected_col--;
emit_signal("cell_selected");
} else {
-
selected_item->select(selected_col - 1);
}
}
@@ -2174,7 +1996,6 @@ void Tree::_go_right() {
selected_col++;
emit_signal("cell_selected");
} else {
-
selected_item->select(selected_col + 1);
}
}
@@ -2189,7 +2010,6 @@ void Tree::_go_up() {
prev = get_last_item();
selected_col = 0;
} else {
-
prev = selected_item->get_prev_visible();
if (last_keypress != 0) {
//incr search next
@@ -2203,14 +2023,12 @@ void Tree::_go_up() {
}
if (select_mode == SELECT_MULTI) {
-
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)
prev = prev->get_prev_visible();
@@ -2226,12 +2044,10 @@ void Tree::_go_up() {
void Tree::_go_down() {
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) {
@@ -2246,7 +2062,6 @@ void Tree::_go_down() {
}
if (select_mode == SELECT_MULTI) {
-
if (!next) {
return;
}
@@ -2255,7 +2070,6 @@ void Tree::_go_down() {
emit_signal("cell_selected");
update();
} else {
-
int col = selected_col < 0 ? 0 : selected_col;
while (next && !next->cells[col].selectable)
@@ -2271,12 +2085,10 @@ 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();
@@ -2294,7 +2106,6 @@ 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();
@@ -2314,21 +2125,18 @@ 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();
_go_up();
} else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) {
-
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();
@@ -2338,12 +2146,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
next = selected_item;
for (int i = 0; i < 10; i++) {
-
TreeItem *_n = next->get_next_visible();
if (_n) {
next = _n;
} else {
-
break;
}
}
@@ -2351,12 +2157,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
if (select_mode == SELECT_MULTI) {
-
selected_item = next;
emit_signal("cell_selected");
update();
} else {
-
while (next && !next->cells[selected_col].selectable)
next = next->get_next_visible();
if (!next) {
@@ -2367,7 +2171,6 @@ 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();
@@ -2377,12 +2180,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
prev = selected_item;
for (int i = 0; i < 10; i++) {
-
TreeItem *_n = prev->get_prev_visible();
if (_n) {
prev = _n;
} else {
-
break;
}
}
@@ -2390,12 +2191,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
if (select_mode == SELECT_MULTI) {
-
selected_item = prev;
emit_signal("cell_selected");
update();
} else {
-
while (prev && !prev->cells[selected_col].selectable)
prev = prev->get_prev_visible();
if (!prev) {
@@ -2405,7 +2204,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()) {
@@ -2415,7 +2213,6 @@ 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)
return;
@@ -2443,7 +2240,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
return;
if (k->get_unicode() > 0) {
-
_do_incr_search(String::chr(k->get_unicode()));
accept_event();
@@ -2457,7 +2253,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
-
if (cache.font.is_null()) // avoid a strange case that may corrupt stuff
update_cache();
@@ -2476,10 +2271,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.hover_type = Cache::CLICK_TITLE;
cache.hover_index = i;
update();
@@ -2490,12 +2283,10 @@ 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())
mpos.x += h_scroll->get_value();
if (v_scroll->is_visible_in_tree())
@@ -2535,7 +2326,6 @@ 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;
@@ -2544,7 +2334,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
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);
@@ -2556,7 +2345,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;
@@ -2570,9 +2358,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
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();
@@ -2581,7 +2367,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);
@@ -2599,9 +2384,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
range_click_timer->stop();
if (pressing_for_editor) {
-
if (range_drag_enabled) {
-
range_drag_enabled = false;
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
warp_mouse(range_drag_capture_pos);
@@ -2630,13 +2413,11 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
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;
}
}
@@ -2663,10 +2444,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=;
@@ -2732,7 +2511,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) {
@@ -2741,7 +2519,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) {
@@ -2754,7 +2531,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);
@@ -2768,7 +2544,6 @@ 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();
@@ -2785,12 +2560,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);
@@ -2799,10 +2572,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());
}
@@ -2815,7 +2586,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);
@@ -2829,7 +2599,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();
@@ -2858,12 +2627,10 @@ bool Tree::edit_selected() {
}
Size2 Tree::get_internal_min_size() const {
-
Size2i size = cache.bg->get_offset();
if (root)
size.height += get_item_height(root);
for (int i = 0; i < columns.size(); i++) {
-
size.width += columns[i].min_width;
}
@@ -2871,13 +2638,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;
}
@@ -2893,11 +2658,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);
@@ -2905,11 +2668,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);
@@ -2918,19 +2679,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();
@@ -2938,23 +2695,19 @@ 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 = nullptr;
if (cache.scroll_speed > 0) {
scrolling = true;
@@ -2962,11 +2715,8 @@ void Tree::_notification(int p_what) {
}
}
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();
@@ -3025,7 +2775,6 @@ void Tree::_notification(int p_what) {
}
if (p_what == NOTIFICATION_DRAW) {
-
update_cache();
update_scrollbars();
RID ci = get_canvas_item();
@@ -3050,16 +2799,13 @@ void Tree::_notification(int p_what) {
draw_size.y -= tbh;
if (root) {
-
draw_item(Point2(), draw_ofs, draw_size, root);
}
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);
@@ -3077,7 +2823,6 @@ void Tree::_notification(int p_what) {
}
if (p_what == NOTIFICATION_RESIZED || p_what == NOTIFICATION_TRANSFORM_CHANGED) {
-
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);
@@ -3093,18 +2838,15 @@ 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);
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, nullptr);
@@ -3130,7 +2872,6 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) {
ti->parent = p_parent;
} else {
-
if (!root) {
// No root exists, make the given item the new root.
ti = memnew(TreeItem(this));
@@ -3148,15 +2889,12 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) {
}
TreeItem *Tree::get_root() {
-
return root;
}
TreeItem *Tree::get_last_item() {
-
TreeItem *last = root;
while (last) {
-
if (last->next)
last = last->next;
else if (last->children)
@@ -3169,7 +2907,6 @@ TreeItem *Tree::get_last_item() {
}
void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) {
-
edited_item = p_item;
edited_col = p_column;
if (p_lmb)
@@ -3179,14 +2916,11 @@ void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) {
}
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)
return;
@@ -3195,14 +2929,12 @@ void Tree::item_selected(int p_column, TreeItem *p_item) {
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;
}
@@ -3210,17 +2942,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);
@@ -3236,12 +2965,10 @@ void Tree::deselect_all() {
}
bool Tree::is_anything_selected() {
-
return (selected_item != nullptr);
}
void Tree::clear() {
-
ERR_FAIL_COND(blocked > 0);
if (pressing_for_editor) {
@@ -3266,18 +2993,15 @@ void Tree::clear() {
};
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)
@@ -3286,7 +3010,6 @@ void Tree::set_column_min_width(int p_column, int p_min_width) {
update();
}
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;
@@ -3294,27 +3017,22 @@ 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 nullptr;
@@ -3323,22 +3041,16 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
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 == nullptr)
return nullptr;
@@ -3357,7 +3069,6 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) {
}
int Tree::get_column_width(int p_column) const {
-
ERR_FAIL_INDEX_V(p_column, columns.size(), -1);
if (!columns[p_column].expand)
@@ -3374,7 +3085,6 @@ int Tree::get_column_width(int p_column) const {
int expanding_total = 0;
for (int i = 0; i < columns.size(); i++) {
-
if (!columns[i].expand) {
expand_area -= columns[i].min_width;
} else {
@@ -3392,19 +3102,16 @@ 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);
@@ -3417,29 +3124,24 @@ void Tree::set_columns(int p_columns) {
}
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)
return 0;
while (true) {
-
if (it == p_item)
return ofs;
@@ -3449,16 +3151,12 @@ 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 == nullptr)
return 0;
@@ -3518,12 +3216,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) {
@@ -3540,7 +3236,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);
@@ -3553,31 +3248,26 @@ 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())
ofs.x = h_scroll->get_value();
@@ -3587,9 +3277,7 @@ Point2 Tree::get_scroll() const {
}
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;
}
@@ -3607,10 +3295,8 @@ 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)
@@ -3632,7 +3318,6 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c
}
TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_selectable) {
-
TreeItem *from = get_selected();
if (!from)
@@ -3655,7 +3340,6 @@ TreeItem *Tree::get_item_with_text(const String &p_find) const {
}
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)))
@@ -3674,14 +3358,11 @@ void Tree::_do_incr_search(const String &p_add) {
}
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) {
@@ -3695,7 +3376,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;
@@ -3707,11 +3387,9 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
return nullptr;
} else {
-
pos.y -= h;
}
} else {
-
h = 0;
}
@@ -3720,7 +3398,6 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
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;
@@ -3734,9 +3411,7 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_
}
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();
@@ -3760,9 +3435,7 @@ 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();
@@ -3785,9 +3458,7 @@ 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 {
-
if (root) {
-
Point2 pos = p_pos;
pos -= cache.bg->get_offset();
pos.y -= _get_title_button_height();
@@ -3803,7 +3474,6 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const {
TreeItem *it = _find_item_at_pos(root, pos, col, h, section);
if (it) {
-
return it;
}
}
@@ -3812,9 +3482,7 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const {
}
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();
@@ -3830,7 +3498,6 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
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);
@@ -3861,12 +3528,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;
}
@@ -3876,7 +3541,6 @@ void Tree::set_hide_folding(bool p_hide) {
}
bool Tree::is_folding_hidden() const {
-
return hide_folding;
}
@@ -3892,27 +3556,22 @@ void Tree::set_drop_mode_flags(int p_flags) {
}
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;
}
@@ -3921,12 +3580,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);
@@ -4014,7 +3671,6 @@ void Tree::_bind_methods() {
}
Tree::Tree() {
-
selected_col = 0;
columns.resize(1);
selected_item = nullptr;
@@ -4118,7 +3774,6 @@ Tree::Tree() {
}
Tree::~Tree() {
-
if (root) {
memdelete(root);
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 3c67a79558..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;
@@ -404,7 +399,6 @@ private:
void propagate_set_columns(TreeItem *p_item);
struct Cache {
-
Ref<Font> font;
Ref<Font> tb_font;
Ref<StyleBox> bg;
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index ac1e4a5629..52538203dd 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;
}
@@ -110,7 +105,6 @@ void VideoPlayer::_mix_audio() {
ERR_FAIL_COND(!target);
for (int j = 0; j < buffer_size; j++) {
-
target[j] += buffer[j] * vol;
}
@@ -123,7 +117,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 +126,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,13 +137,11 @@ 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())
@@ -176,7 +164,6 @@ void VideoPlayer::_notification(int p_notification) {
} break;
case NOTIFICATION_DRAW: {
-
if (texture.is_null())
return;
if (texture->get_width() == 0)
@@ -190,7 +177,6 @@ void VideoPlayer::_notification(int p_notification) {
};
Size2 VideoPlayer::get_minimum_size() const {
-
if (!expand && !texture.is_null())
return texture->get_size();
else
@@ -198,19 +184,16 @@ Size2 VideoPlayer::get_minimum_size() const {
}
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());
@@ -256,12 +239,10 @@ 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())
return;
@@ -274,7 +255,6 @@ void VideoPlayer::play() {
};
void VideoPlayer::stop() {
-
if (!is_inside_tree())
return;
if (playback.is_null())
@@ -288,7 +268,6 @@ void VideoPlayer::stop() {
};
bool VideoPlayer::is_playing() const {
-
if (playback.is_null())
return false;
@@ -296,7 +275,6 @@ bool VideoPlayer::is_playing() const {
};
void VideoPlayer::set_paused(bool p_paused) {
-
paused = p_paused;
if (playback.is_valid()) {
playback->set_paused(p_paused);
@@ -306,17 +284,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,22 +300,18 @@ 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)
set_volume(0);
else
@@ -348,7 +319,6 @@ void VideoPlayer::set_volume_db(float p_db) {
};
float VideoPlayer::get_volume_db() const {
-
if (volume == 0)
return -80;
else
@@ -356,27 +326,23 @@ float VideoPlayer::get_volume_db() const {
};
String VideoPlayer::get_stream_name() const {
-
if (stream.is_null())
return "<No Stream>";
return stream->get_name();
};
float VideoPlayer::get_stream_position() const {
-
if (playback.is_null())
return 0;
return playback->get_playback_position();
};
void VideoPlayer::set_stream_position(float p_position) {
-
if (playback.is_valid())
playback->seek(p_position);
}
Ref<Texture2D> VideoPlayer::get_video_texture() const {
-
if (playback.is_valid())
return playback->get_texture();
@@ -384,17 +350,14 @@ Ref<Texture2D> VideoPlayer::get_video_texture() const {
}
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 +365,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,9 +374,7 @@ 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)
@@ -428,7 +388,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 +444,6 @@ void VideoPlayer::_bind_methods() {
}
VideoPlayer::VideoPlayer() {
-
volume = 1;
loops = false;
paused = false;
@@ -506,7 +464,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