diff options
Diffstat (limited to 'scene/gui')
100 files changed, 990 insertions, 963 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 9c20decef0..8fd19e8655 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "base_button.h" + #include "os/keyboard.h" #include "print_string.h" #include "scene/main/viewport.h" @@ -514,13 +515,13 @@ void BaseButton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), "set_shortcut", "get_shortcut"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "group", PROPERTY_HINT_RESOURCE_TYPE, "ButtonGroup"), "set_button_group", "get_button_group"); - BIND_CONSTANT(DRAW_NORMAL); - BIND_CONSTANT(DRAW_PRESSED); - BIND_CONSTANT(DRAW_HOVER); - BIND_CONSTANT(DRAW_DISABLED); + BIND_ENUM_CONSTANT(DRAW_NORMAL); + BIND_ENUM_CONSTANT(DRAW_PRESSED); + BIND_ENUM_CONSTANT(DRAW_HOVER); + BIND_ENUM_CONSTANT(DRAW_DISABLED); - BIND_CONSTANT(ACTION_MODE_BUTTON_PRESS); - BIND_CONSTANT(ACTION_MODE_BUTTON_RELEASE); + BIND_ENUM_CONSTANT(ACTION_MODE_BUTTON_PRESS); + BIND_ENUM_CONSTANT(ACTION_MODE_BUTTON_RELEASE); } BaseButton::BaseButton() { diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index dfcf3b0f8a..0c08dc53a3 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 16b2cfa083..739fd84b38 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -54,7 +54,7 @@ void BoxContainer::_resort() { Map<Control *, _MinSizeCache> min_size_cache; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; if (c->is_set_as_toplevel()) @@ -106,7 +106,7 @@ void BoxContainer::_resort() { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; if (c->is_set_as_toplevel()) @@ -159,7 +159,7 @@ void BoxContainer::_resort() { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; if (c->is_set_as_toplevel()) @@ -211,7 +211,7 @@ Size2 BoxContainer::get_minimum_size() const { bool first = true; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -295,9 +295,9 @@ void BoxContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_alignment"), &BoxContainer::get_alignment); ClassDB::bind_method(D_METHOD("set_alignment", "alignment"), &BoxContainer::set_alignment); - BIND_CONSTANT(ALIGN_BEGIN); - BIND_CONSTANT(ALIGN_CENTER); - BIND_CONSTANT(ALIGN_END); + BIND_ENUM_CONSTANT(ALIGN_BEGIN); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_END); ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Begin,Center,End"), "set_alignment", "get_alignment"); } diff --git a/scene/gui/box_container.h b/scene/gui/box_container.h index d544ff79d1..4d00a2011f 100644 --- a/scene/gui/box_container.h +++ b/scene/gui/box_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 9a0b3b3c89..1fa03f81f4 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -59,7 +59,7 @@ void Button::_notification(int p_what) { if (p_what == NOTIFICATION_TRANSLATION_CHANGED) { - xl_text = XL_MESSAGE(text); + xl_text = tr(text); minimum_size_changed(); update(); } @@ -172,7 +172,7 @@ void Button::set_text(const String &p_text) { if (text == p_text) return; text = p_text; - xl_text = XL_MESSAGE(p_text); + xl_text = tr(p_text); update(); _change_notify("text"); minimum_size_changed(); @@ -245,9 +245,9 @@ void Button::_bind_methods() { ClassDB::bind_method(D_METHOD("get_text_align"), &Button::get_text_align); ClassDB::bind_method(D_METHOD("is_flat"), &Button::is_flat); - BIND_CONSTANT(ALIGN_LEFT); - BIND_CONSTANT(ALIGN_CENTER); - BIND_CONSTANT(ALIGN_RIGHT); + BIND_ENUM_CONSTANT(ALIGN_LEFT); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_RIGHT); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text"); ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_button_icon", "get_button_icon"); diff --git a/scene/gui/button.h b/scene/gui/button.h index 499e44c0e1..dd6e730b86 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/button_group.cpp b/scene/gui/button_group.cpp index e54e810d7d..336c88fe9d 100644 --- a/scene/gui/button_group.cpp +++ b/scene/gui/button_group.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -56,7 +56,7 @@ void ButtonGroup::set_pressed_button(BaseButton *p_button) { void ButtonGroup::_pressed(Object *p_button) { ERR_FAIL_NULL(p_button); - BaseButton *b=p_button->cast_to<BaseButton>(); + BaseButton *b=Object::cast_to<BaseButton>(p_button); ERR_FAIL_COND(!b); for(Set<BaseButton*>::Element *E=buttons.front();E;E=E->next()) { diff --git a/scene/gui/button_group.h b/scene/gui/button_group.h index 93c3aaaeb3..6ebc0575d2 100644 --- a/scene/gui/button_group.h +++ b/scene/gui/button_group.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp index bdc811870d..8c9c9d8720 100644 --- a/scene/gui/center_container.cpp +++ b/scene/gui/center_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -36,7 +36,7 @@ Size2 CenterContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -69,7 +69,7 @@ void CenterContainer::_notification(int p_what) { Size2 size = get_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) diff --git a/scene/gui/center_container.h b/scene/gui/center_container.h index 30b526e893..4397539046 100644 --- a/scene/gui/center_container.h +++ b/scene/gui/center_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index b61d516599..21e2269141 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/check_box.h b/scene/gui/check_box.h index ec8e097bae..4a1adb5f2f 100644 --- a/scene/gui/check_box.h +++ b/scene/gui/check_box.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index 1c3d4df308..e68159e27f 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/check_button.h b/scene/gui/check_button.h index 8634858cfe..af3b80fe04 100644 --- a/scene/gui/check_button.h +++ b/scene/gui/check_button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 5e110362c8..704c00b1d6 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -56,11 +56,10 @@ void ColorPicker::_notification(int p_what) { } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (get_parent()) { - Popup *p = get_parent()->cast_to<Popup>(); - if (p) - p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2)); - } + + Popup *p = Object::cast_to<Popup>(get_parent()); + if (p) + p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2)); } break; case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: { @@ -204,7 +203,7 @@ void ColorPicker::_update_presets() { } void ColorPicker::_text_type_toggled() { - if (!get_tree()->is_editor_hint()) + if (!Engine::get_singleton()->is_editor_hint()) return; text_is_constructor = !text_is_constructor; if (text_is_constructor) { diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index d35182e062..7de67a707c 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/color_rect.cpp b/scene/gui/color_rect.cpp index 0641302b1c..6b5247648e 100644 --- a/scene/gui/color_rect.cpp +++ b/scene/gui/color_rect.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/color_rect.h b/scene/gui/color_rect.h index 65da3d9a7c..382648fddf 100644 --- a/scene/gui/color_rect.h +++ b/scene/gui/color_rect.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index 4bbe15ed7e..ba5d92620b 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -43,7 +43,7 @@ void Container::add_child_notify(Node *p_child) { Control::add_child_notify(p_child); - Control *control = p_child->cast_to<Control>(); + Control *control = Object::cast_to<Control>(p_child); if (!control) return; @@ -57,7 +57,7 @@ void Container::move_child_notify(Node *p_child) { Control::move_child_notify(p_child); - if (!p_child->cast_to<Control>()) + if (!Object::cast_to<Control>(p_child)) return; queue_sort(); @@ -67,7 +67,7 @@ void Container::remove_child_notify(Node *p_child) { Control::remove_child_notify(p_child); - Control *control = p_child->cast_to<Control>(); + Control *control = Object::cast_to<Control>(p_child); if (!control) return; diff --git a/scene/gui/container.h b/scene/gui/container.h index bff24c6d55..60a7a9efcb 100644 --- a/scene/gui/container.h +++ b/scene/gui/container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c97426ad42..961fccc804 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -353,7 +353,7 @@ void Control::_resize(const Size2 &p_size) { void Control::add_child_notify(Node *p_child) { - Control *child_c = p_child->cast_to<Control>(); + Control *child_c = Object::cast_to<Control>(p_child); if (!child_c) return; @@ -364,7 +364,7 @@ void Control::add_child_notify(Node *p_child) { void Control::remove_child_notify(Node *p_child) { - Control *child_c = p_child->cast_to<Control>(); + Control *child_c = Object::cast_to<Control>(p_child); if (!child_c) return; @@ -398,7 +398,7 @@ void Control::_notification(int p_notification) { case NOTIFICATION_ENTER_CANVAS: { - data.parent = get_parent()->cast_to<Control>(); + data.parent = Object::cast_to<Control>(get_parent()); if (is_set_as_toplevel()) { data.SI = get_viewport()->_gui_add_subwindow_control(this); @@ -421,13 +421,13 @@ void Control::_notification(int p_notification) { if (!parent) break; - CanvasItem *ci = parent->cast_to<CanvasItem>(); + CanvasItem *ci = Object::cast_to<CanvasItem>(parent); if (ci && ci->is_set_as_toplevel()) { subwindow = true; break; } - parent_control = parent->cast_to<Control>(); + parent_control = Object::cast_to<Control>(parent); if (parent_control) { break; @@ -624,7 +624,7 @@ Variant Control::get_drag_data(const Point2 &p_point) { if (data.drag_owner) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { - Control *c = obj->cast_to<Control>(); + Control *c = Object::cast_to<Control>(obj); return c->call("get_drag_data_fw", p_point, this); } } @@ -646,7 +646,7 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const if (data.drag_owner) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { - Control *c = obj->cast_to<Control>(); + Control *c = Object::cast_to<Control>(obj); return c->call("can_drop_data_fw", p_point, p_data, this); } } @@ -667,7 +667,7 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) { if (data.drag_owner) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { - Control *c = obj->cast_to<Control>(); + Control *c = Object::cast_to<Control>(obj); c->call("drop_data_fw", p_point, p_data, this); return; } @@ -749,7 +749,7 @@ Ref<Texture> Control::get_icon(const StringName &p_name, const StringName &p_typ class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -785,7 +785,7 @@ Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_ty class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -821,7 +821,7 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -858,7 +858,7 @@ Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) if (theme_owner->data.theme->get_default_theme_font().is_valid()) return theme_owner->data.theme->get_default_theme_font(); - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -892,7 +892,7 @@ Color Control::get_color(const StringName &p_name, const StringName &p_type) con class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -927,7 +927,7 @@ int Control::get_constant(const StringName &p_name, const StringName &p_type) co class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -1015,7 +1015,7 @@ bool Control::has_icon(const StringName &p_name, const StringName &p_type) const class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -1049,7 +1049,7 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -1082,7 +1082,7 @@ bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) c class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -1115,7 +1115,7 @@ bool Control::has_font(const StringName &p_name, const StringName &p_type) const class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -1149,7 +1149,7 @@ bool Control::has_color(const StringName &p_name, const StringName &p_type) cons class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -1183,7 +1183,7 @@ bool Control::has_constant(const StringName &p_name, const StringName &p_type) c class_name = ClassDB::get_parent_class_nocheck(class_name); } - Control *parent = theme_owner->get_parent() ? theme_owner->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(theme_owner->get_parent()); if (parent) theme_owner = parent->data.theme_owner; @@ -1329,7 +1329,7 @@ void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bo void Control::_set_anchor(Margin p_margin, float p_anchor) { #ifdef TOOLS_ENABLED - if (is_inside_tree() && get_tree()->is_editor_hint()) { + if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) { set_anchor(p_margin, p_anchor, EDITOR_DEF("editors/2d/keep_margins_when_changing_anchors", false)); } else { set_anchor(p_margin, p_anchor, false); @@ -1687,7 +1687,7 @@ static Control *_next_control(Control *p_from) { if (p_from->is_set_as_toplevel()) return NULL; // can't go above - Control *parent = p_from->get_parent() ? p_from->get_parent()->cast_to<Control>() : NULL; + Control *parent = Object::cast_to<Control>(p_from->get_parent()); if (!parent) { @@ -1698,7 +1698,7 @@ static Control *_next_control(Control *p_from) { ERR_FAIL_INDEX_V(next, parent->get_child_count(), NULL); for (int i = (next + 1); i < parent->get_child_count(); i++) { - Control *c = parent->get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(parent->get_child(i)); if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) continue; @@ -1721,7 +1721,7 @@ Control *Control::find_next_valid_focus() const { for (int i = 0; i < from->get_child_count(); i++) { - Control *c = from->get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(from->get_child(i)); if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) { continue; } @@ -1739,10 +1739,8 @@ Control *Control::find_next_valid_focus() const { 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()) { - if (next_child->get_parent()) { - next_child = next_child->get_parent()->cast_to<Control>(); - } else - next_child = NULL; + + next_child = cast_to<Control>(next_child->get_parent()); } if (!next_child) { @@ -1776,7 +1774,7 @@ static Control *_prev_control(Control *p_from) { Control *child = NULL; for (int i = p_from->get_child_count() - 1; i >= 0; i--) { - Control *c = p_from->get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(p_from->get_child(i)); if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) continue; @@ -1800,7 +1798,7 @@ Control *Control::find_prev_valid_focus() const { Control *prev_child = NULL; - if (from->is_set_as_toplevel() || !from->get_parent() || !from->get_parent()->cast_to<Control>()) { + if (from->is_set_as_toplevel() || !Object::cast_to<Control>(from->get_parent())) { //find last of the childs @@ -1810,7 +1808,7 @@ Control *Control::find_prev_valid_focus() const { for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) { - Control *c = from->get_parent()->get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i)); if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) { continue; @@ -1822,7 +1820,7 @@ Control *Control::find_prev_valid_focus() const { if (!prev_child) { - prev_child = from->get_parent()->cast_to<Control>(); + prev_child = Object::cast_to<Control>(from->get_parent()); } else { prev_child = _prev_control(prev_child); @@ -1839,8 +1837,6 @@ Control *Control::find_prev_valid_focus() const { } return NULL; - - return NULL; } Control::FocusMode Control::get_focus_mode() const { @@ -1914,14 +1910,14 @@ void Control::_modal_stack_remove() { void Control::_propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign) { - Control *c = p_at->cast_to<Control>(); + 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 return; for (int i = 0; i < p_at->get_child_count(); i++) { - CanvasItem *child = p_at->get_child(i)->cast_to<CanvasItem>(); + CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i)); if (child) { _propagate_theme_changed(child, p_owner, p_assign); } @@ -1957,7 +1953,7 @@ void Control::set_theme(const Ref<Theme> &p_theme) { _propagate_theme_changed(this, this); } else { - Control *parent = get_parent() ? get_parent()->cast_to<Control>() : NULL; + Control *parent = cast_to<Control>(get_parent()); if (parent && parent->data.theme_owner) { _propagate_theme_changed(this, parent->data.theme_owner); } else { @@ -2040,7 +2036,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { Control *c = NULL; Node *n = get_node(data.focus_neighbour[p_margin]); if (n) { - c = n->cast_to<Control>(); + c = Object::cast_to<Control>(n); if (!c) { @@ -2097,7 +2093,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { while (base) { - Control *c = base->cast_to<Control>(); + Control *c = Object::cast_to<Control>(base); if (c) { if (c->data.SI) break; @@ -2117,10 +2113,10 @@ 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 (p_at->cast_to<Viewport>()) + if (Object::cast_to<Viewport>(p_at)) return; //bye - Control *c = p_at->cast_to<Control>(); + Control *c = Object::cast_to<Control>(p_at); if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) { @@ -2170,7 +2166,7 @@ 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 = child->cast_to<Control>(); + Control *childc = Object::cast_to<Control>(child); if (childc && childc->data.SI) continue; //subwindow, ignore _window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest); @@ -2365,7 +2361,7 @@ Control *Control::get_root_parent_control() const { while (ci) { - const Control *c = ci->cast_to<Control>(); + const Control *c = Object::cast_to<Control>(ci); if (c) { root = c; @@ -2634,9 +2630,9 @@ void Control::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); ADD_GROUP("", ""); - BIND_CONSTANT(FOCUS_NONE); - BIND_CONSTANT(FOCUS_CLICK); - BIND_CONSTANT(FOCUS_ALL); + BIND_ENUM_CONSTANT(FOCUS_NONE); + BIND_ENUM_CONSTANT(FOCUS_CLICK); + BIND_ENUM_CONSTANT(FOCUS_ALL); BIND_CONSTANT(NOTIFICATION_RESIZED); BIND_CONSTANT(NOTIFICATION_MOUSE_ENTER); @@ -2646,56 +2642,56 @@ void Control::_bind_methods() { BIND_CONSTANT(NOTIFICATION_THEME_CHANGED); BIND_CONSTANT(NOTIFICATION_MODAL_CLOSE); - BIND_CONSTANT(CURSOR_ARROW); - BIND_CONSTANT(CURSOR_IBEAM); - BIND_CONSTANT(CURSOR_POINTING_HAND); - BIND_CONSTANT(CURSOR_CROSS); - BIND_CONSTANT(CURSOR_WAIT); - BIND_CONSTANT(CURSOR_BUSY); - BIND_CONSTANT(CURSOR_DRAG); - BIND_CONSTANT(CURSOR_CAN_DROP); - BIND_CONSTANT(CURSOR_FORBIDDEN); - BIND_CONSTANT(CURSOR_VSIZE); - BIND_CONSTANT(CURSOR_HSIZE); - BIND_CONSTANT(CURSOR_BDIAGSIZE); - BIND_CONSTANT(CURSOR_FDIAGSIZE); - BIND_CONSTANT(CURSOR_MOVE); - BIND_CONSTANT(CURSOR_VSPLIT); - BIND_CONSTANT(CURSOR_HSPLIT); - BIND_CONSTANT(CURSOR_HELP); - - BIND_CONSTANT(PRESET_TOP_LEFT); - BIND_CONSTANT(PRESET_TOP_RIGHT); - BIND_CONSTANT(PRESET_BOTTOM_LEFT); - BIND_CONSTANT(PRESET_BOTTOM_RIGHT); - BIND_CONSTANT(PRESET_CENTER_LEFT); - BIND_CONSTANT(PRESET_CENTER_TOP); - BIND_CONSTANT(PRESET_CENTER_RIGHT); - BIND_CONSTANT(PRESET_CENTER_BOTTOM); - BIND_CONSTANT(PRESET_CENTER); - BIND_CONSTANT(PRESET_LEFT_WIDE); - BIND_CONSTANT(PRESET_TOP_WIDE); - BIND_CONSTANT(PRESET_RIGHT_WIDE); - BIND_CONSTANT(PRESET_BOTTOM_WIDE); - BIND_CONSTANT(PRESET_VCENTER_WIDE); - BIND_CONSTANT(PRESET_HCENTER_WIDE); - BIND_CONSTANT(PRESET_WIDE); - - BIND_CONSTANT(SIZE_EXPAND); - BIND_CONSTANT(SIZE_FILL); - BIND_CONSTANT(SIZE_EXPAND_FILL); - BIND_CONSTANT(SIZE_SHRINK_CENTER); - BIND_CONSTANT(SIZE_SHRINK_END); - - BIND_CONSTANT(MOUSE_FILTER_STOP); - BIND_CONSTANT(MOUSE_FILTER_PASS); - BIND_CONSTANT(MOUSE_FILTER_IGNORE); - - BIND_CONSTANT(GROW_DIRECTION_BEGIN); - BIND_CONSTANT(GROW_DIRECTION_END); - - BIND_CONSTANT(ANCHOR_BEGIN); - BIND_CONSTANT(ANCHOR_END); + BIND_ENUM_CONSTANT(CURSOR_ARROW); + BIND_ENUM_CONSTANT(CURSOR_IBEAM); + BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND); + BIND_ENUM_CONSTANT(CURSOR_CROSS); + BIND_ENUM_CONSTANT(CURSOR_WAIT); + BIND_ENUM_CONSTANT(CURSOR_BUSY); + BIND_ENUM_CONSTANT(CURSOR_DRAG); + BIND_ENUM_CONSTANT(CURSOR_CAN_DROP); + BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN); + BIND_ENUM_CONSTANT(CURSOR_VSIZE); + BIND_ENUM_CONSTANT(CURSOR_HSIZE); + BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_MOVE); + BIND_ENUM_CONSTANT(CURSOR_VSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HELP); + + BIND_ENUM_CONSTANT(PRESET_TOP_LEFT); + BIND_ENUM_CONSTANT(PRESET_TOP_RIGHT); + BIND_ENUM_CONSTANT(PRESET_BOTTOM_LEFT); + BIND_ENUM_CONSTANT(PRESET_BOTTOM_RIGHT); + BIND_ENUM_CONSTANT(PRESET_CENTER_LEFT); + BIND_ENUM_CONSTANT(PRESET_CENTER_TOP); + BIND_ENUM_CONSTANT(PRESET_CENTER_RIGHT); + BIND_ENUM_CONSTANT(PRESET_CENTER_BOTTOM); + BIND_ENUM_CONSTANT(PRESET_CENTER); + BIND_ENUM_CONSTANT(PRESET_LEFT_WIDE); + BIND_ENUM_CONSTANT(PRESET_TOP_WIDE); + BIND_ENUM_CONSTANT(PRESET_RIGHT_WIDE); + BIND_ENUM_CONSTANT(PRESET_BOTTOM_WIDE); + BIND_ENUM_CONSTANT(PRESET_VCENTER_WIDE); + BIND_ENUM_CONSTANT(PRESET_HCENTER_WIDE); + BIND_ENUM_CONSTANT(PRESET_WIDE); + + BIND_ENUM_CONSTANT(SIZE_EXPAND); + BIND_ENUM_CONSTANT(SIZE_FILL); + BIND_ENUM_CONSTANT(SIZE_EXPAND_FILL); + BIND_ENUM_CONSTANT(SIZE_SHRINK_CENTER); + BIND_ENUM_CONSTANT(SIZE_SHRINK_END); + + BIND_ENUM_CONSTANT(MOUSE_FILTER_STOP); + BIND_ENUM_CONSTANT(MOUSE_FILTER_PASS); + BIND_ENUM_CONSTANT(MOUSE_FILTER_IGNORE); + + BIND_ENUM_CONSTANT(GROW_DIRECTION_BEGIN); + BIND_ENUM_CONSTANT(GROW_DIRECTION_END); + + BIND_ENUM_CONSTANT(ANCHOR_BEGIN); + BIND_ENUM_CONSTANT(ANCHOR_END); ADD_SIGNAL(MethodInfo("resized")); ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); @@ -2707,7 +2703,7 @@ void Control::_bind_methods() { ADD_SIGNAL(MethodInfo("minimum_size_changed")); ADD_SIGNAL(MethodInfo("modal_closed")); - BIND_VMETHOD(MethodInfo("has_point:bool", PropertyInfo(Variant::VECTOR2, "point"))); + BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point"))); } Control::Control() { diff --git a/scene/gui/control.h b/scene/gui/control.h index d73ca3f7c9..da5c4d0908 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -33,7 +33,7 @@ #include "math_2d.h" #include "rid.h" #include "scene/2d/canvas_item.h" -#include "scene/gui/input_action.h" +#include "scene/gui/shortcut.h" #include "scene/main/node.h" #include "scene/main/timer.h" #include "scene/resources/theme.h" diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 8232a7a466..140d002387 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -60,13 +60,13 @@ void WindowDialog::_fix_size() { float right = 0; // Check validity, because the theme could contain a different type of StyleBox if (panel->get_class() == "StyleBoxTexture") { - Ref<StyleBoxTexture> panel_texture = panel->cast_to<StyleBoxTexture>(); + Ref<StyleBoxTexture> panel_texture = Object::cast_to<StyleBoxTexture>(*panel); top = panel_texture->get_expand_margin_size(MARGIN_TOP); left = panel_texture->get_expand_margin_size(MARGIN_LEFT); bottom = panel_texture->get_expand_margin_size(MARGIN_BOTTOM); right = panel_texture->get_expand_margin_size(MARGIN_RIGHT); } else if (panel->get_class() == "StyleBoxFlat") { - Ref<StyleBoxFlat> panel_flat = panel->cast_to<StyleBoxFlat>(); + Ref<StyleBoxFlat> panel_flat = Object::cast_to<StyleBoxFlat>(*panel); top = panel_flat->get_expand_margin_size(MARGIN_TOP); left = panel_flat->get_expand_margin_size(MARGIN_LEFT); bottom = panel_flat->get_expand_margin_size(MARGIN_BOTTOM); @@ -227,11 +227,11 @@ void WindowDialog::_notification(int p_what) { } break; #ifdef TOOLS_ENABLED case NOTIFICATION_POST_POPUP: { - if (get_tree() && get_tree()->is_editor_hint() && EditorNode::get_singleton()) + if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) EditorNode::get_singleton()->dim_editor(true); } break; case NOTIFICATION_POPUP_HIDE: { - if (get_tree() && get_tree()->is_editor_hint() && EditorNode::get_singleton()) + if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()) EditorNode::get_singleton()->dim_editor(false); } break; #endif @@ -271,7 +271,7 @@ int WindowDialog::_drag_hit_test(const Point2 &pos) const { void WindowDialog::set_title(const String &p_title) { - title = XL_MESSAGE(p_title); + title = tr(p_title); update(); } String WindowDialog::get_title() const { @@ -424,7 +424,7 @@ void AcceptDialog::_update_child_rects() { Vector2 csize(size.x - margin * 2, size.y - margin * 3 - hminsize.y - label_size.height); for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; @@ -448,7 +448,7 @@ Size2 AcceptDialog::get_minimum_size() const { Size2 minsize = label->get_combined_minimum_size(); for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index 9d8f113caa..54cc290b05 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 74255b38bf..990c0f3d96 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -464,7 +464,7 @@ void FileDialog::update_filters() { String flt = filters[i].get_slice(";", 0).strip_edges(); String desc = filters[i].get_slice(";", 1).strip_edges(); if (desc.length()) - filter->add_item(String(XL_MESSAGE(desc)) + " ( " + flt + " )"); + filter->add_item(String(tr(desc)) + " ( " + flt + " )"); else filter->add_item("( " + flt + " )"); } @@ -718,16 +718,15 @@ void FileDialog::_bind_methods() { ADD_SIGNAL(MethodInfo("files_selected", PropertyInfo(Variant::POOL_STRING_ARRAY, "paths"))); ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir"))); - BIND_CONSTANT(MODE_OPEN_FILE); - BIND_CONSTANT(MODE_OPEN_FILES); - BIND_CONSTANT(MODE_OPEN_DIR); - BIND_CONSTANT(MODE_OPEN_ANY); + BIND_ENUM_CONSTANT(MODE_OPEN_FILE); + BIND_ENUM_CONSTANT(MODE_OPEN_FILES); + BIND_ENUM_CONSTANT(MODE_OPEN_DIR); + BIND_ENUM_CONSTANT(MODE_OPEN_ANY); + BIND_ENUM_CONSTANT(MODE_SAVE_FILE); - BIND_CONSTANT(MODE_SAVE_FILE); - - BIND_CONSTANT(ACCESS_RESOURCES); - BIND_CONSTANT(ACCESS_USERDATA); - BIND_CONSTANT(ACCESS_FILESYSTEM); + BIND_ENUM_CONSTANT(ACCESS_RESOURCES); + BIND_ENUM_CONSTANT(ACCESS_USERDATA); + BIND_ENUM_CONSTANT(ACCESS_FILESYSTEM); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Open one,Open many,Open folder,Open any,Save"), "set_mode", "get_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "access", PROPERTY_HINT_ENUM, "Resources,User data,File system"), "set_access", "get_access"); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 9873a677b2..34cecfe4d0 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index 22de28ea7f..c9ce5e2143 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/gradient_edit.h b/scene/gui/gradient_edit.h index 6c4ae6fd15..026e4f783b 100644 --- a/scene/gui/gradient_edit.h +++ b/scene/gui/gradient_edit.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index ec1932ed5a..5b00aab2ef 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "graph_edit.h" + #include "os/input.h" #include "os/keyboard.h" #include "scene/gui/box_container.h" @@ -134,7 +135,7 @@ void GraphEdit::_update_scroll_offset() { for (int i = 0; i < get_child_count(); i++) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -163,7 +164,7 @@ void GraphEdit::_update_scroll() { Rect2 screen; for (int i = 0; i < get_child_count(); i++) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -205,7 +206,7 @@ void GraphEdit::_update_scroll() { void GraphEdit::_graph_node_raised(Node *p_gn) { - GraphNode *gn = p_gn->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(p_gn); ERR_FAIL_COND(!gn); if (gn->is_comment()) { move_child(gn, 0); @@ -214,7 +215,7 @@ void GraphEdit::_graph_node_raised(Node *p_gn) { } int first_not_comment = 0; for (int i = 0; i < get_child_count(); i++) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (gn && !gn->is_comment()) { first_not_comment = i; break; @@ -228,7 +229,7 @@ void GraphEdit::_graph_node_raised(Node *p_gn) { void GraphEdit::_graph_node_moved(Node *p_gn) { - GraphNode *gn = p_gn->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(p_gn); ERR_FAIL_COND(!gn); top_layer->update(); update(); @@ -240,7 +241,7 @@ void GraphEdit::add_child_notify(Node *p_child) { Control::add_child_notify(p_child); top_layer->call_deferred("raise"); //top layer always on top! - GraphNode *gn = p_child->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(p_child); if (gn) { gn->set_scale(Vector2(zoom, zoom)); gn->connect("offset_changed", this, "_graph_node_moved", varray(gn)); @@ -256,7 +257,7 @@ void GraphEdit::remove_child_notify(Node *p_child) { Control::remove_child_notify(p_child); top_layer->call_deferred("raise"); //top layer always on top! - GraphNode *gn = p_child->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(p_child); if (gn) { gn->disconnect("offset_changed", this, "_graph_node_moved"); gn->disconnect("raise_request", this, "_graph_node_raised"); @@ -345,7 +346,7 @@ bool GraphEdit::_filter_input(const Point2 &p_point) { float grab_r = port->get_width() * 0.5 * grab_r_extend; for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -379,7 +380,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { float grab_r = port->get_width() * 0.5 * grab_r_extend; for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -395,20 +396,20 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { if (E->get().from == gn->get_name() && E->get().from_port == j) { Node *to = get_node(String(E->get().to)); - if (to && to->cast_to<GraphNode>()) { + if (Object::cast_to<GraphNode>(to)) { connecting_from = E->get().to; connecting_index = E->get().to_port; connecting_out = false; - connecting_type = to->cast_to<GraphNode>()->get_connection_input_type(E->get().to_port); - connecting_color = to->cast_to<GraphNode>()->get_connection_input_color(E->get().to_port); + connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E->get().to_port); + connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E->get().to_port); connecting_target = false; connecting_to = pos; just_disconected = true; emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port); to = get_node(String(connecting_from)); //maybe it was erased - if (to && to->cast_to<GraphNode>()) { + if (Object::cast_to<GraphNode>(to)) { connecting = true; } return; @@ -443,20 +444,20 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { if (E->get().to == gn->get_name() && E->get().to_port == j) { Node *fr = get_node(String(E->get().from)); - if (fr && fr->cast_to<GraphNode>()) { + if (Object::cast_to<GraphNode>(fr)) { connecting_from = E->get().from; connecting_index = E->get().from_port; connecting_out = true; - connecting_type = fr->cast_to<GraphNode>()->get_connection_output_type(E->get().from_port); - connecting_color = fr->cast_to<GraphNode>()->get_connection_output_color(E->get().from_port); + connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E->get().from_port); + connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E->get().from_port); connecting_target = false; connecting_to = pos; just_disconected = true; emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port); fr = get_node(String(connecting_from)); //maybe it was erased - if (fr && fr->cast_to<GraphNode>()) { + if (Object::cast_to<GraphNode>(fr)) { connecting = true; } return; @@ -493,7 +494,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { float grab_r = port->get_width() * 0.5 * grab_r_extend; for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -593,8 +594,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) { -#if 1 - //cubic bezier code float diff = p_to.x - p_from.x; float cp_offset; @@ -621,84 +620,53 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const colors.push_back(p_to_color); p_where->draw_polyline_colors(points, colors, 2, true); - -#else - - static const int steps = 20; - - //old cosine code - Rect2 r; - r.pos = p_from; - r.expand_to(p_to); - Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1); - bool flip = sign.x * sign.y < 0; - - Vector2 prev; - for (int i = 0; i <= steps; i++) { - - float d = i / float(steps); - float c = -Math::cos(d * Math_PI) * 0.5 + 0.5; - if (flip) - c = 1.0 - c; - Vector2 p = r.pos + Vector2(d * r.size.width, c * r.size.height); - - if (i > 0) { - - p_where->draw_line(prev, p, p_color.linear_interpolate(p_to_color, d), 2); - } - - prev = p; - } -#endif } void GraphEdit::_connections_layer_draw() { - { - //draw connections - List<List<Connection>::Element *> to_erase; - for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { - - NodePath fromnp(E->get().from); + //draw connections + List<List<Connection>::Element *> to_erase; + for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { - Node *from = get_node(fromnp); - if (!from) { - to_erase.push_back(E); - continue; - } + NodePath fromnp(E->get().from); - GraphNode *gfrom = from->cast_to<GraphNode>(); + Node *from = get_node(fromnp); + if (!from) { + to_erase.push_back(E); + continue; + } - if (!gfrom) { - to_erase.push_back(E); - continue; - } + GraphNode *gfrom = Object::cast_to<GraphNode>(from); - NodePath tonp(E->get().to); - Node *to = get_node(tonp); - if (!to) { - to_erase.push_back(E); - continue; - } + if (!gfrom) { + to_erase.push_back(E); + continue; + } - GraphNode *gto = to->cast_to<GraphNode>(); + NodePath tonp(E->get().to); + Node *to = get_node(tonp); + if (!to) { + to_erase.push_back(E); + continue; + } - if (!gto) { - to_erase.push_back(E); - continue; - } + GraphNode *gto = Object::cast_to<GraphNode>(to); - Vector2 frompos = gfrom->get_connection_output_pos(E->get().from_port) + gfrom->get_offset() * zoom; - Color color = gfrom->get_connection_output_color(E->get().from_port); - Vector2 topos = gto->get_connection_input_pos(E->get().to_port) + gto->get_offset() * zoom; - Color tocolor = gto->get_connection_input_color(E->get().to_port); - _draw_cos_line(connections_layer, frompos, topos, color, tocolor); + if (!gto) { + to_erase.push_back(E); + continue; } - while (to_erase.size()) { - connections.erase(to_erase.front()->get()); - to_erase.pop_front(); - } + Vector2 frompos = gfrom->get_connection_output_pos(E->get().from_port) + gfrom->get_offset() * zoom; + Color color = gfrom->get_connection_output_color(E->get().from_port); + Vector2 topos = gto->get_connection_input_pos(E->get().to_port) + gto->get_offset() * zoom; + Color tocolor = gto->get_connection_input_color(E->get().to_port); + _draw_cos_line(connections_layer, frompos, topos, color, tocolor); + } + + while (to_erase.size()) { + connections.erase(to_erase.front()->get()); + to_erase.pop_front(); } } @@ -710,7 +678,7 @@ void GraphEdit::_top_layer_draw() { Node *fromn = get_node(connecting_from); ERR_FAIL_COND(!fromn); - GraphNode *from = fromn->cast_to<GraphNode>(); + GraphNode *from = Object::cast_to<GraphNode>(fromn); ERR_FAIL_COND(!from); Vector2 pos; if (connecting_out) @@ -744,7 +712,7 @@ void GraphEdit::set_selected(Node *p_child) { for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -767,7 +735,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { //drag_accum+=Vector2(mm->get_relative().x,mm->get_relative().y); drag_accum = get_local_mouse_pos() - drag_origin; for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (gn && gn->is_selected()) { Vector2 pos = (gn->get_drag_from() * zoom + drag_accum) / zoom; @@ -791,7 +759,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -816,7 +784,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { box_selecting = false; for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; @@ -837,7 +805,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { //deselect current node for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (gn) { Rect2 r = gn->get_rect(); @@ -853,7 +821,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { emit_signal("_begin_node_move"); for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (gn && gn->is_selected()) gn->set_drag(false); } @@ -874,7 +842,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn_selected = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn_selected = Object::cast_to<GraphNode>(get_child(i)); if (gn_selected) { if (gn_selected->is_resizing()) @@ -898,7 +866,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { just_selected = !gn->is_selected(); if (!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { for (int i = 0; i < get_child_count(); i++) { - GraphNode *o_gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i)); if (o_gn) o_gn->set_selected(o_gn == gn); } @@ -906,7 +874,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { gn->set_selected(true); for (int i = 0; i < get_child_count(); i++) { - GraphNode *o_gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *o_gn = Object::cast_to<GraphNode>(get_child(i)); if (!o_gn) continue; if (o_gn->is_selected()) @@ -926,7 +894,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn || !gn->is_selected()) continue; @@ -937,7 +905,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn || !gn->is_selected()) continue; @@ -948,7 +916,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { previus_selected.clear(); for (int i = get_child_count() - 1; i >= 0; i--) { - GraphNode *gn = get_child(i)->cast_to<GraphNode>(); + GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index e908829d5f..4656b50133 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index b9062295b5..8730be0c06 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -96,7 +96,7 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const { int idx = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || c->is_set_as_toplevel()) continue; @@ -122,7 +122,7 @@ void GraphNode::_resort() { Size2 minsize; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -144,7 +144,7 @@ void GraphNode::_resort() { cache_y.clear(); for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -375,7 +375,7 @@ Size2 GraphNode::get_minimum_size() const { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -462,7 +462,7 @@ void GraphNode::_connpos_update() { int idx = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -710,9 +710,9 @@ void GraphNode::_bind_methods() { ADD_SIGNAL(MethodInfo("close_request")); ADD_SIGNAL(MethodInfo("resize_request", PropertyInfo(Variant::VECTOR2, "new_minsize"))); - BIND_CONSTANT(OVERLAY_DISABLED); - BIND_CONSTANT(OVERLAY_BREAKPOINT); - BIND_CONSTANT(OVERLAY_POSITION); + BIND_ENUM_CONSTANT(OVERLAY_DISABLED); + BIND_ENUM_CONSTANT(OVERLAY_BREAKPOINT); + BIND_ENUM_CONSTANT(OVERLAY_POSITION); } GraphNode::GraphNode() { diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index a7d9e8ddb0..416d711aab 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 06a58d69b2..5dd5667f46 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -51,7 +51,7 @@ void GridContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; @@ -109,7 +109,7 @@ void GridContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; int row = idx / columns; @@ -184,7 +184,7 @@ Size2 GridContainer::get_minimum_size() const { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; int row = idx / columns; diff --git a/scene/gui/grid_container.h b/scene/gui/grid_container.h index aaa6a295ff..45e26ed48e 100644 --- a/scene/gui/grid_container.h +++ b/scene/gui/grid_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index b30a6000ff..9bad871ef9 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -1374,10 +1374,11 @@ void ItemList::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_mode", PROPERTY_HINT_ENUM, "Top,Left"), "set_icon_mode", "get_icon_mode"); ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "icon_scale"), "set_icon_scale", "get_icon_scale"); - BIND_CONSTANT(ICON_MODE_TOP); - BIND_CONSTANT(ICON_MODE_LEFT); - BIND_CONSTANT(SELECT_SINGLE); - BIND_CONSTANT(SELECT_MULTI); + BIND_ENUM_CONSTANT(ICON_MODE_TOP); + BIND_ENUM_CONSTANT(ICON_MODE_LEFT); + + BIND_ENUM_CONSTANT(SELECT_SINGLE); + BIND_ENUM_CONSTANT(SELECT_MULTI); ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "index"))); ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::VECTOR2, "atpos"))); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index a80727f568..8166975408 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 874156821e..5fe3dd0129 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -63,7 +63,7 @@ void Label::_notification(int p_what) { if (p_what == NOTIFICATION_TRANSLATION_CHANGED) { - String new_text = XL_MESSAGE(text); + String new_text = tr(text); if (new_text == xl_text) return; //nothing new xl_text = new_text; @@ -493,7 +493,10 @@ void Label::regenerate_word_cache() { minsize.height = (font->get_height() * line_count) + (line_spacing * (line_count - 1)); } - minimum_size_changed(); + if (!autowrap || !clip) { + //helps speed up some labels that may change a lot, as no resizing is requested. Do not change. + minimum_size_changed(); + } word_cache_dirty = false; } @@ -526,7 +529,7 @@ void Label::set_text(const String &p_string) { if (text == p_string) return; text = p_string; - xl_text = XL_MESSAGE(p_string); + xl_text = tr(p_string); word_cache_dirty = true; if (percent_visible < 1) visible_chars = get_total_character_count() * percent_visible; @@ -641,15 +644,15 @@ void Label::_bind_methods() { ClassDB::bind_method(D_METHOD("set_max_lines_visible", "lines_visible"), &Label::set_max_lines_visible); ClassDB::bind_method(D_METHOD("get_max_lines_visible"), &Label::get_max_lines_visible); - BIND_CONSTANT(ALIGN_LEFT); - BIND_CONSTANT(ALIGN_CENTER); - BIND_CONSTANT(ALIGN_RIGHT); - BIND_CONSTANT(ALIGN_FILL); + BIND_ENUM_CONSTANT(ALIGN_LEFT); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_RIGHT); + BIND_ENUM_CONSTANT(ALIGN_FILL); - BIND_CONSTANT(VALIGN_TOP); - BIND_CONSTANT(VALIGN_CENTER); - BIND_CONSTANT(VALIGN_BOTTOM); - BIND_CONSTANT(VALIGN_FILL); + BIND_ENUM_CONSTANT(VALIGN_TOP); + BIND_ENUM_CONSTANT(VALIGN_CENTER); + BIND_ENUM_CONSTANT(VALIGN_BOTTOM); + BIND_ENUM_CONSTANT(VALIGN_FILL); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align"); diff --git a/scene/gui/label.h b/scene/gui/label.h index dce68f4422..7c1905af7d 100644 --- a/scene/gui/label.h +++ b/scene/gui/label.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index c1784fb7ba..66b4e6cec1 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -534,7 +534,7 @@ void LineEdit::_notification(int p_what) { switch (p_what) { #ifdef TOOLS_ENABLED case NOTIFICATION_ENTER_TREE: { - if (get_tree()->is_editor_hint()) { + if (Engine::get_singleton()->is_editor_hint()) { cursor_set_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false)); cursor_set_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65)); @@ -991,7 +991,7 @@ String LineEdit::get_text() const { void LineEdit::set_placeholder(String p_text) { - placeholder = XL_MESSAGE(p_text); + placeholder = tr(p_text); update(); } @@ -1352,18 +1352,18 @@ void LineEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("text_changed", PropertyInfo(Variant::STRING, "text"))); ADD_SIGNAL(MethodInfo("text_entered", PropertyInfo(Variant::STRING, "text"))); - BIND_CONSTANT(ALIGN_LEFT); - BIND_CONSTANT(ALIGN_CENTER); - BIND_CONSTANT(ALIGN_RIGHT); - BIND_CONSTANT(ALIGN_FILL); - - BIND_CONSTANT(MENU_CUT); - BIND_CONSTANT(MENU_COPY); - BIND_CONSTANT(MENU_PASTE); - BIND_CONSTANT(MENU_CLEAR); - BIND_CONSTANT(MENU_SELECT_ALL); - BIND_CONSTANT(MENU_UNDO); - BIND_CONSTANT(MENU_MAX); + BIND_ENUM_CONSTANT(ALIGN_LEFT); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_RIGHT); + BIND_ENUM_CONSTANT(ALIGN_FILL); + + BIND_ENUM_CONSTANT(MENU_CUT); + BIND_ENUM_CONSTANT(MENU_COPY); + BIND_ENUM_CONSTANT(MENU_PASTE); + BIND_ENUM_CONSTANT(MENU_CLEAR); + BIND_ENUM_CONSTANT(MENU_SELECT_ALL); + BIND_ENUM_CONSTANT(MENU_UNDO); + BIND_ENUM_CONSTANT(MENU_MAX); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align"); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index fb0eaa9446..52a4a29a33 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -186,5 +186,6 @@ public: }; VARIANT_ENUM_CAST(LineEdit::Align); +VARIANT_ENUM_CAST(LineEdit::MenuItems); #endif diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 9cb67b75e2..9fe94fc464 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -130,9 +130,9 @@ void LinkButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_underline_mode", "underline_mode"), &LinkButton::set_underline_mode); ClassDB::bind_method(D_METHOD("get_underline_mode"), &LinkButton::get_underline_mode); - BIND_CONSTANT(UNDERLINE_MODE_ALWAYS); - BIND_CONSTANT(UNDERLINE_MODE_ON_HOVER); - BIND_CONSTANT(UNDERLINE_MODE_NEVER); + BIND_ENUM_CONSTANT(UNDERLINE_MODE_ALWAYS); + BIND_ENUM_CONSTANT(UNDERLINE_MODE_ON_HOVER); + BIND_ENUM_CONSTANT(UNDERLINE_MODE_NEVER); ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "underline", PROPERTY_HINT_ENUM, "Always,On Hover,Never"), "set_underline_mode", "get_underline_mode"); diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h index 98a3dc66f6..386eb452ae 100644 --- a/scene/gui/link_button.h +++ b/scene/gui/link_button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp index 2bc9db529b..14991f5d44 100644 --- a/scene/gui/margin_container.cpp +++ b/scene/gui/margin_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -40,7 +40,7 @@ Size2 MarginContainer::get_minimum_size() const { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -74,7 +74,7 @@ void MarginContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) diff --git a/scene/gui/margin_container.h b/scene/gui/margin_container.h index 1cdb3a36cc..9703d9ebe0 100644 --- a/scene/gui/margin_container.h +++ b/scene/gui/margin_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 93284f2b6c..ac450616d6 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -33,7 +33,7 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { - if (p_event->is_pressed() && !p_event->is_echo() && (p_event->cast_to<InputEventKey>() || p_event->cast_to<InputEventJoypadButton>() || p_event->cast_to<InputEventAction>())) { + 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; diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index 6bb23452dd..c7f1d976ff 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 00df266a09..b4d0799945 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index db921b8b97..a06c540678 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index f3c6142f9e..536b655f75 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/panel.h b/scene/gui/panel.h index eac8f2d4e8..cc7ca47319 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index 86874f7cfd..a0c75d1330 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -41,7 +41,7 @@ Size2 PanelContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; if (c->is_set_as_toplevel()) @@ -90,7 +90,7 @@ void PanelContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; if (c->is_set_as_toplevel()) diff --git a/scene/gui/panel_container.h b/scene/gui/panel_container.h index f8f1fb6494..5d8f1ee64b 100644 --- a/scene/gui/panel_container.h +++ b/scene/gui/panel_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/patch_9_rect.cpp b/scene/gui/patch_9_rect.cpp index 249090830d..6b2deeb209 100644 --- a/scene/gui/patch_9_rect.cpp +++ b/scene/gui/patch_9_rect.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -82,9 +82,9 @@ void NinePatchRect::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "axis_stretch_horizontal", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_h_axis_stretch_mode", "get_h_axis_stretch_mode"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "axis_stretch_vertical", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_v_axis_stretch_mode", "get_v_axis_stretch_mode"); - BIND_CONSTANT(AXIS_STRETCH_MODE_STRETCH); - BIND_CONSTANT(AXIS_STRETCH_MODE_TILE); - BIND_CONSTANT(AXIS_STRETCH_MODE_TILE_FIT); + BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_STRETCH); + BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_TILE); + BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_TILE_FIT); } void NinePatchRect::set_texture(const Ref<Texture> &p_tex) { diff --git a/scene/gui/patch_9_rect.h b/scene/gui/patch_9_rect.h index 636b9127e7..4cf93e4c05 100644 --- a/scene/gui/patch_9_rect.h +++ b/scene/gui/patch_9_rect.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index f2ba6bfbc4..5a2a552943 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,6 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "popup.h" + +#include "engine.h" #include "os/keyboard.h" void Popup::_gui_input(Ref<InputEvent> p_event) { @@ -48,7 +50,7 @@ void Popup::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { //small helper to make editing of these easier in editor #ifdef TOOLS_ENABLED - if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { set_as_toplevel(false); } #endif @@ -57,17 +59,10 @@ void Popup::_notification(int p_what) { void Popup::_fix_size() { -#if 0 - Point2 pos = get_position(); - Size2 size = get_size(); - Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); -#else - Point2 pos = get_global_position(); Size2 size = get_size(); Point2 window_size = get_viewport_rect().size; -#endif if (pos.x + size.width > window_size.width) pos.x = window_size.width - size.width; if (pos.x < 0) @@ -77,14 +72,8 @@ void Popup::_fix_size() { pos.y = window_size.height - size.height; if (pos.y < 0) pos.y = 0; -#if 0 - if (pos!=get_pos()) - set_position(pos); -#else if (pos != get_position()) set_global_position(pos); - -#endif } void Popup::set_as_minsize() { @@ -93,7 +82,7 @@ void Popup::set_as_minsize() { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (!c->is_visible()) @@ -127,7 +116,7 @@ void Popup::popup_centered_minsize(const Size2 &p_minsize) { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (!c->is_visible()) @@ -247,6 +236,7 @@ void Popup::_bind_methods() { ADD_SIGNAL(MethodInfo("popup_hide")); ADD_GROUP("Popup", "popup_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "popup_exclusive"), "set_exclusive", "is_exclusive"); + BIND_CONSTANT(NOTIFICATION_POST_POPUP); BIND_CONSTANT(NOTIFICATION_POPUP_HIDE); } @@ -276,9 +266,10 @@ void PopupPanel::set_child_rect(Control *p_child) { Ref<StyleBox> p = get_stylebox("panel"); p_child->set_area_as_parent_rect(); - for (int i = 0; i < 4; i++) { - p_child->set_margin(Margin(i), p->get_margin(Margin(i))); - } + p_child->set_margin(MARGIN_LEFT, p->get_margin(MARGIN_LEFT)); + p_child->set_margin(MARGIN_RIGHT, -p->get_margin(MARGIN_RIGHT)); + p_child->set_margin(MARGIN_TOP, p->get_margin(MARGIN_TOP)); + p_child->set_margin(MARGIN_BOTTOM, -p->get_margin(MARGIN_BOTTOM)); } void PopupPanel::_notification(int p_what) { diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 0543ae1937..6739c580f2 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 46aa0e5054..f3711b86b6 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -168,7 +168,7 @@ void PopupMenu::_activate_submenu(int over) { Node *n = get_node(items[over].submenu); ERR_EXPLAIN("item subnode does not exist: " + items[over].submenu); ERR_FAIL_COND(!n); - Popup *pm = n->cast_to<Popup>(); + Popup *pm = Object::cast_to<Popup>(n); ERR_EXPLAIN("item subnode is not a Popup: " + items[over].submenu); ERR_FAIL_COND(!pm); if (pm->is_visible_in_tree()) @@ -187,7 +187,7 @@ void PopupMenu::_activate_submenu(int over) { pm->set_position(pos); pm->popup(); - PopupMenu *pum = pm->cast_to<PopupMenu>(); + PopupMenu *pum = Object::cast_to<PopupMenu>(pm); if (pum) { pr.position -= pum->get_global_position(); @@ -395,7 +395,7 @@ void PopupMenu::_notification(int p_what) { case NOTIFICATION_TRANSLATION_CHANGED: { for (int i = 0; i < items.size(); i++) { - items[i].xl_text = XL_MESSAGE(items[i].text); + items[i].xl_text = tr(items[i].text); } minimum_size_changed(); @@ -513,7 +513,7 @@ void PopupMenu::add_icon_item(const Ref<Texture> &p_icon, const String &p_label, Item item; item.icon = p_icon; item.text = p_label; - item.xl_text = XL_MESSAGE(p_label); + item.xl_text = tr(p_label); item.accel = p_accel; item.ID = p_ID; items.push_back(item); @@ -523,7 +523,7 @@ void PopupMenu::add_item(const String &p_label, int p_ID, uint32_t p_accel) { Item item; item.text = p_label; - item.xl_text = XL_MESSAGE(p_label); + item.xl_text = tr(p_label); item.accel = p_accel; item.ID = p_ID; items.push_back(item); @@ -534,7 +534,7 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, Item item; item.text = p_label; - item.xl_text = XL_MESSAGE(p_label); + item.xl_text = tr(p_label); item.ID = p_ID; item.submenu = p_submenu; items.push_back(item); @@ -546,7 +546,7 @@ void PopupMenu::add_icon_check_item(const Ref<Texture> &p_icon, const String &p_ Item item; item.icon = p_icon; item.text = p_label; - item.xl_text = XL_MESSAGE(p_label); + item.xl_text = tr(p_label); item.accel = p_accel; item.ID = p_ID; item.checkable = true; @@ -557,7 +557,7 @@ void PopupMenu::add_check_item(const String &p_label, int p_ID, uint32_t p_accel Item item; item.text = p_label; - item.xl_text = XL_MESSAGE(p_label); + item.xl_text = tr(p_label); item.accel = p_accel; item.ID = p_ID; item.checkable = true; @@ -628,7 +628,7 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) { ERR_FAIL_INDEX(p_idx, items.size()); items[p_idx].text = p_text; - items[p_idx].xl_text = XL_MESSAGE(p_text); + items[p_idx].xl_text = tr(p_text); update(); } @@ -869,7 +869,7 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo if (!n) continue; - PopupMenu *pm = n->cast_to<PopupMenu>(); + PopupMenu *pm = Object::cast_to<PopupMenu>(n); if (!pm) continue; @@ -891,14 +891,14 @@ void PopupMenu::activate_item(int p_item) { //hide all parent PopupMenue's Node *next = get_parent(); - PopupMenu *pop = next->cast_to<PopupMenu>(); + PopupMenu *pop = Object::cast_to<PopupMenu>(next); while (pop) { // We close all parents that are chained together, // with hide_on_item_selection enabled if ((items[p_item].checkable && hide_on_checkable_item_selection && pop->is_hide_on_checkable_item_selection()) || (!items[p_item].checkable && hide_on_item_selection && pop->is_hide_on_item_selection())) { pop->hide(); next = next->get_parent(); - pop = next->cast_to<PopupMenu>(); + pop = Object::cast_to<PopupMenu>(next); } else { // Break out of loop when the next parent has // hide_on_item_selection disabled diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 37714ee989..c9e9c8e311 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index 13d368d253..6953d03384 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/progress_bar.h b/scene/gui/progress_bar.h index 1121a78aab..c5a9252123 100644 --- a/scene/gui/progress_bar.h +++ b/scene/gui/progress_bar.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index 68afe8150a..1dbec6e5a1 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -170,7 +170,7 @@ double Range::get_as_ratio() const { void Range::_share(Node *p_range) { - Range *r = p_range->cast_to<Range>(); + Range *r = Object::cast_to<Range>(p_range); ERR_FAIL_COND(!r); share(r); } diff --git a/scene/gui/range.h b/scene/gui/range.h index fdcbbb09ee..daa8af824a 100644 --- a/scene/gui/range.h +++ b/scene/gui/range.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp index 400ff299a9..e2f4abe04a 100644 --- a/scene/gui/reference_rect.cpp +++ b/scene/gui/reference_rect.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -29,13 +29,15 @@ /*************************************************************************/ #include "reference_rect.h" +#include "engine.h" + void ReferenceRect::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { if (!is_inside_tree()) return; - if (get_tree()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) draw_style_box(get_stylebox("border"), Rect2(Point2(), get_size())); } } diff --git a/scene/gui/reference_rect.h b/scene/gui/reference_rect.h index b118425eb6..9b826a1145 100644 --- a/scene/gui/reference_rect.h +++ b/scene/gui/reference_rect.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 42084ade25..a3f116c883 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -1915,26 +1915,26 @@ void RichTextLabel::_bind_methods() { ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta"))); - BIND_CONSTANT(ALIGN_LEFT); - BIND_CONSTANT(ALIGN_CENTER); - BIND_CONSTANT(ALIGN_RIGHT); - BIND_CONSTANT(ALIGN_FILL); - - BIND_CONSTANT(LIST_NUMBERS); - BIND_CONSTANT(LIST_LETTERS); - BIND_CONSTANT(LIST_DOTS); - - BIND_CONSTANT(ITEM_FRAME); - BIND_CONSTANT(ITEM_TEXT); - BIND_CONSTANT(ITEM_IMAGE); - BIND_CONSTANT(ITEM_NEWLINE); - BIND_CONSTANT(ITEM_FONT); - BIND_CONSTANT(ITEM_COLOR); - BIND_CONSTANT(ITEM_UNDERLINE); - BIND_CONSTANT(ITEM_ALIGN); - BIND_CONSTANT(ITEM_INDENT); - BIND_CONSTANT(ITEM_LIST); - BIND_CONSTANT(ITEM_META); + BIND_ENUM_CONSTANT(ALIGN_LEFT); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_RIGHT); + BIND_ENUM_CONSTANT(ALIGN_FILL); + + BIND_ENUM_CONSTANT(LIST_NUMBERS); + BIND_ENUM_CONSTANT(LIST_LETTERS); + BIND_ENUM_CONSTANT(LIST_DOTS); + + BIND_ENUM_CONSTANT(ITEM_FRAME); + BIND_ENUM_CONSTANT(ITEM_TEXT); + BIND_ENUM_CONSTANT(ITEM_IMAGE); + BIND_ENUM_CONSTANT(ITEM_NEWLINE); + BIND_ENUM_CONSTANT(ITEM_FONT); + BIND_ENUM_CONSTANT(ITEM_COLOR); + BIND_ENUM_CONSTANT(ITEM_UNDERLINE); + BIND_ENUM_CONSTANT(ITEM_ALIGN); + BIND_ENUM_CONSTANT(ITEM_INDENT); + BIND_ENUM_CONSTANT(ITEM_LIST); + BIND_ENUM_CONSTANT(ITEM_META); } void RichTextLabel::set_visible_characters(int p_visible) { diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 71fa766958..74bf180b5d 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 2ccdbb05a9..16d1b320b7 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,9 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "scroll_bar.h" + #include "os/keyboard.h" #include "os/os.h" #include "print_string.h" + bool ScrollBar::focus_by_default = false; void ScrollBar::set_can_focus_by_default(bool p_can_focus) { @@ -40,6 +42,11 @@ void ScrollBar::set_can_focus_by_default(bool 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"); + } + Ref<InputEventMouseButton> b = p_event; if (b.is_valid()) { @@ -98,7 +105,18 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (ofs < grabber_ofs) { - set_value(get_value() - get_page()); + if (scrolling) { + target_scroll = target_scroll - get_page(); + } else { + target_scroll = get_value() - get_page(); + } + + if (smooth_scroll_enabled) { + scrolling = true; + set_fixed_process(true); + } else { + set_value(target_scroll); + } return; } @@ -111,8 +129,18 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { drag.value_at_click = get_as_ratio(); update(); } else { + if (scrolling) { + target_scroll = target_scroll + get_page(); + } else { + target_scroll = get_value() + get_page(); + } - set_value(get_value() + get_page()); + if (smooth_scroll_enabled) { + scrolling = true; + set_fixed_process(true); + } else { + set_value(target_scroll); + } } } else { @@ -122,8 +150,6 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { } } - Ref<InputEventMouseMotion> m = p_event; - if (m.is_valid()) { accept_event(); @@ -291,7 +317,7 @@ void ScrollBar::_notification(int p_what) { if (has_node(drag_slave_path)) { Node *n = get_node(drag_slave_path); - drag_slave = n->cast_to<Control>(); + drag_slave = Object::cast_to<Control>(n); } if (drag_slave) { @@ -311,7 +337,22 @@ void ScrollBar::_notification(int p_what) { if (p_what == NOTIFICATION_FIXED_PROCESS) { - if (drag_slave_touching) { + if (scrolling) { + if (get_value() != target_scroll) { + double target = target_scroll - get_value(); + double dist = sqrt(target * target); + double vel = ((target / dist) * 500) * get_fixed_process_delta_time(); + + if (vel >= dist) { + set_value(target_scroll); + } else { + set_value(get_value() + vel); + } + } else { + scrolling = false; + set_fixed_process(false); + } + } else if (drag_slave_touching) { if (drag_slave_touching_deaccel) { @@ -624,7 +665,7 @@ void ScrollBar::set_drag_slave(const NodePath &p_path) { if (has_node(p_path)) { Node *n = get_node(p_path); - drag_slave = n->cast_to<Control>(); + drag_slave = Object::cast_to<Control>(n); } if (drag_slave) { @@ -639,138 +680,14 @@ NodePath ScrollBar::get_drag_slave() const { return drag_slave_path; } -#if 0 - -void ScrollBar::mouse_button(const Point2& p_pos, int b->get_button_index(),bool b->is_pressed(),int p_modifier_mask) { - - // wheel! - - if (b->get_button_index()==BUTTON_WHEEL_UP && b->is_pressed()) { - - if (orientation==VERTICAL) - set_val( get_val() - get_page() / 4.0 ); - else - set_val( get_val() + get_page() / 4.0 ); - - } - if (b->get_button_index()==BUTTON_WHEEL_DOWN && b->is_pressed()) { - - if (orientation==HORIZONTAL) - set_val( get_val() - get_page() / 4.0 ); - else - set_val( get_val() + get_page() / 4.0 ); - } - - if (b->get_button_index()!=BUTTON_LEFT) - return; - - if (b->is_pressed()) { - - int ofs = orientation==VERTICAL ? p_pos.y : p_pos.x ; - int grabber_ofs = get_grabber_offset(); - int grabber_size = get_grabber_size(); - - if ( ofs < grabber_ofs ) { - - set_val( get_val() - get_page() ); - - } else if (ofs > grabber_ofs + grabber_size ) { - - set_val( get_val() + get_page() ); - - } else { - - - drag.active=true; - drag.pos_at_click=get_click_pos(p_pos); - drag.value_at_click=get_unit_value(); - } - - - } else { - - drag.active=false; - } - +void ScrollBar::set_smooth_scroll_enabled(bool p_enable) { + smooth_scroll_enabled = p_enable; } -void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b->get_button_index()_mask) { - - if (!drag.active) - return; - - double value_ofs=drag.value_at_click+(get_click_pos(p_pos)-drag.pos_at_click); - - - value_ofs=value_ofs*( get_max() - get_min() ); - if (value_ofs<get_min()) - value_ofs=get_min(); - if (value_ofs>(get_max()-get_page())) - value_ofs=get_max()-get_page(); - if (get_val()==value_ofs) - return; //don't bother if the value is the same - - set_val( value_ofs ); +bool ScrollBar::is_smooth_scroll_enabled() const { + return smooth_scroll_enabled; } -bool ScrollBar::key(unsigned long p_unicode, unsigned long p_scan_code,bool b->is_pressed(),bool p_repeat,int p_modifier_mask) { - - if (!b->is_pressed()) - return false; - - switch (p_scan_code) { - - case KEY_LEFT: { - - if (orientation!=HORIZONTAL) - return false; - set_val( get_val() - get_step() ); - - } break; - case KEY_RIGHT: { - - if (orientation!=HORIZONTAL) - return false; - set_val( get_val() + get_step() ); - - } break; - case KEY_UP: { - - if (orientation!=VERTICAL) - return false; - - set_val( get_val() - get_step() ); - - - } break; - case KEY_DOWN: { - - if (orientation!=VERTICAL) - return false; - set_val( get_val() + get_step() ); - - } break; - case KEY_HOME: { - - set_val( get_min() ); - - } break; - case KEY_END: { - - set_val( get_max() ); - - } break; - - default: - return false; - - } - - return true; -} - -#endif - void ScrollBar::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollBar::_gui_input); @@ -779,6 +696,8 @@ void ScrollBar::_bind_methods() { ClassDB::bind_method(D_METHOD("_drag_slave_input"), &ScrollBar::_drag_slave_input); ClassDB::bind_method(D_METHOD("_drag_slave_exit"), &ScrollBar::_drag_slave_exit); + ADD_SIGNAL(MethodInfo("scrolling")); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "custom_step", PROPERTY_HINT_RANGE, "-1,4096"), "set_custom_step", "get_custom_step"); } @@ -795,6 +714,10 @@ ScrollBar::ScrollBar(Orientation p_orientation) { drag_slave_touching = false; drag_slave_touching_deaccel = false; + scrolling = false; + target_scroll = 0; + smooth_scroll_enabled = false; + if (focus_by_default) set_focus_mode(FOCUS_ALL); set_step(0); diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h index 8310e12590..373483a8a0 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -83,6 +83,10 @@ class ScrollBar : public Range { bool drag_slave_touching_deaccel; bool click_handled; + bool scrolling; + double target_scroll; + bool smooth_scroll_enabled; + void _drag_slave_exit(); void _drag_slave_input(const Ref<InputEvent> &p_input); @@ -100,6 +104,9 @@ public: void set_drag_slave(const NodePath &p_path); NodePath get_drag_slave() const; + void set_smooth_scroll_enabled(bool p_enable); + bool is_smooth_scroll_enabled() const; + virtual Size2 get_minimum_size() const; ScrollBar(Orientation p_orientation = VERTICAL); ~ScrollBar(); diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 939bdd8d0c..e182e491d3 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -40,7 +40,7 @@ Size2 ScrollContainer::get_minimum_size() const { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -220,7 +220,7 @@ void ScrollContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) @@ -423,7 +423,7 @@ String ScrollContainer::get_configuration_warning() const { for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c) continue; if (c->is_set_as_toplevel()) diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h index e5df3e5e1c..9076be0d72 100644 --- a/scene/gui/scroll_container.h +++ b/scene/gui/scroll_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp index 3b00ab4605..3db234f7cc 100644 --- a/scene/gui/separator.cpp +++ b/scene/gui/separator.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/separator.h b/scene/gui/separator.h index 9a5fe2ac66..be2f1e8e77 100644 --- a/scene/gui/separator.h +++ b/scene/gui/separator.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/input_action.cpp b/scene/gui/shortcut.cpp index c08059a049..f37410e77b 100644 --- a/scene/gui/input_action.cpp +++ b/scene/gui/shortcut.cpp @@ -1,9 +1,9 @@ /*************************************************************************/ -/* input_action.cpp */ +/* shortcut.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -27,7 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "input_action.h" +#include "shortcut.h" + #include "os/keyboard.h" void ShortCut::set_shortcut(const Ref<InputEvent> &p_shortcut) { @@ -52,61 +53,6 @@ String ShortCut::get_as_text() const { return shortcut->as_text(); else return "None"; -#if 0 - switch (shortcut.type) { - - case Ref<InputEvent>::NONE: { - - return "None"; - } break; - case Ref<InputEvent>::KEY: { - - String str; - if (shortcut->get_shift()) - str += RTR("Shift+"); - if (shortcut->get_alt()) - str += RTR("Alt+"); - if (shortcut->get_control()) - str += RTR("Ctrl+"); - if (shortcut->get_metakey()) - str += RTR("Meta+"); - - str += keycode_get_string(shortcut->get_scancode()).capitalize(); - - return str; - } break; - case Ref<InputEvent>::JOYPAD_BUTTON: { - - String str = RTR("Device") + " " + itos(shortcut.device) + ", " + RTR("Button") + " " + itos(shortcut.joy_button->get_button_index()); - str += "."; - - return str; - } break; - case Ref<InputEvent>::MOUSE_BUTTON: { - - String str = RTR("Device") + " " + itos(shortcut.device) + ", "; - switch (shortcut->get_button_index()) { - case BUTTON_LEFT: str += RTR("Left Button."); break; - case BUTTON_RIGHT: str += RTR("Right Button."); break; - case BUTTON_MIDDLE: str += RTR("Middle Button."); break; - case BUTTON_WHEEL_UP: str += RTR("Wheel Up."); break; - case BUTTON_WHEEL_DOWN: str += RTR("Wheel Down."); break; - default: str += RTR("Button") + " " + itos(shortcut->get_button_index()) + "."; - } - - return str; - } break; - case Ref<InputEvent>::JOYPAD_MOTION: { - - int ax = shortcut.joy_motion.axis; - String str = RTR("Device") + " " + itos(shortcut.device) + ", " + RTR("Axis") + " " + itos(ax) + "."; - - return str; - } break; - } - - return ""; -#endif } bool ShortCut::is_valid() const { diff --git a/scene/gui/input_action.h b/scene/gui/shortcut.h index 5c91d2be28..8d85bb920f 100644 --- a/scene/gui/input_action.h +++ b/scene/gui/shortcut.h @@ -1,9 +1,9 @@ /*************************************************************************/ -/* input_action.h */ +/* shortcut.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -27,8 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef INPUTACTION_H -#define INPUTACTION_H +#ifndef SHORTCUT_H +#define SHORTCUT_H #include "os/input_event.h" #include "resource.h" @@ -53,4 +53,4 @@ public: ShortCut(); }; -#endif // INPUTACTION_H +#endif // SHORTCUT_H diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 9ba17ce34f..4661f54526 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/slider.h b/scene/gui/slider.h index f3cf3c6f48..a2334a69fc 100644 --- a/scene/gui/slider.h +++ b/scene/gui/slider.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index c5b9df15b9..f462989f53 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -192,7 +192,7 @@ void SpinBox::_notification(int p_what) { int w = updown->get_width(); if (w != last_w) { - line_edit->set_margin(MARGIN_RIGHT, w); + line_edit->set_margin(MARGIN_RIGHT, -w); last_w = w; } diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index 683ed0c344..0c562bd744 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index e3dad08809..4420a936d2 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -44,7 +44,7 @@ Control *SplitContainer::_getch(int p_idx) const { int idx = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = get_child(i)->cast_to<Control>(); + Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; if (c->is_set_as_toplevel()) @@ -410,9 +410,9 @@ void SplitContainer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collapsed"), "set_collapsed", "is_collapsed"); ADD_PROPERTY(PropertyInfo(Variant::INT, "dragger_visibility", PROPERTY_HINT_ENUM, "Visible,Hidden,Hidden & Collapsed"), "set_dragger_visibility", "get_dragger_visibility"); - BIND_CONSTANT(DRAGGER_VISIBLE); - BIND_CONSTANT(DRAGGER_HIDDEN); - BIND_CONSTANT(DRAGGER_HIDDEN_COLLAPSED); + BIND_ENUM_CONSTANT(DRAGGER_VISIBLE); + BIND_ENUM_CONSTANT(DRAGGER_HIDDEN); + BIND_ENUM_CONSTANT(DRAGGER_HIDDEN_COLLAPSED); } SplitContainer::SplitContainer(bool p_vertical) { diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index 87a210f24c..8ec21b5eaa 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 1352569f33..461ae3444b 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -230,8 +230,8 @@ void TabContainer::_notification(int p_what) { tab_style->draw(canvas, tab_rect); // Draw the tab contents. - Control *control = tabs[i + first_tab_cache]->cast_to<Control>(); - String text = control->has_meta("_tab_name") ? String(XL_MESSAGE(String(control->get_meta("_tab_name")))) : String(control->get_name()); + Control *control = Object::cast_to<Control>(tabs[i + first_tab_cache]); + String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name()); int x_content = tab_rect.position.x + tab_style->get_margin(MARGIN_LEFT); int top_margin = tab_style->get_margin(MARGIN_TOP); @@ -293,13 +293,13 @@ void TabContainer::_notification(int p_what) { } int TabContainer::_get_tab_width(int p_index) const { - Control *control = _get_tabs()[p_index]->cast_to<Control>(); + Control *control = Object::cast_to<Control>(_get_tabs()[p_index]); if (!control || control->is_set_as_toplevel()) return 0; // Get the width of the text displayed on the tab. Ref<Font> font = get_font("font"); - String text = control->has_meta("_tab_name") ? String(XL_MESSAGE(String(control->get_meta("_tab_name")))) : String(control->get_name()); + String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name()); int width = font->get_string_size(text).width; // Add space for a tab icon. @@ -332,7 +332,7 @@ Vector<Control *> TabContainer::_get_tabs() const { Vector<Control *> controls; for (int i = 0; i < get_child_count(); i++) { - Control *control = get_child(i)->cast_to<Control>(); + Control *control = Object::cast_to<Control>(get_child(i)); if (!control || control->is_toplevel_control()) continue; @@ -350,7 +350,7 @@ void TabContainer::add_child_notify(Node *p_child) { Control::add_child_notify(p_child); - Control *c = p_child->cast_to<Control>(); + Control *c = Object::cast_to<Control>(p_child); if (!c) return; if (c->is_set_as_toplevel()) @@ -616,7 +616,7 @@ Size2 TabContainer::get_minimum_size() const { void TabContainer::set_popup(Node *p_popup) { ERR_FAIL_NULL(p_popup); - popup = p_popup->cast_to<Popup>(); + popup = Object::cast_to<Popup>(p_popup); update(); } diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 3e1a2c1598..be59a16b3f 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index acffbbc499..085f6de6b8 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -815,15 +815,15 @@ void Tabs::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "tab_close_display_policy", PROPERTY_HINT_ENUM, "Show Never,Show Active Only,Show Always"), "set_tab_close_display_policy", "get_tab_close_display_policy"); - BIND_CONSTANT(ALIGN_LEFT); - BIND_CONSTANT(ALIGN_CENTER); - BIND_CONSTANT(ALIGN_RIGHT); - BIND_CONSTANT(ALIGN_MAX); + BIND_ENUM_CONSTANT(ALIGN_LEFT); + BIND_ENUM_CONSTANT(ALIGN_CENTER); + BIND_ENUM_CONSTANT(ALIGN_RIGHT); + BIND_ENUM_CONSTANT(ALIGN_MAX); - BIND_CONSTANT(CLOSE_BUTTON_SHOW_ACTIVE_ONLY); - BIND_CONSTANT(CLOSE_BUTTON_SHOW_ALWAYS); - BIND_CONSTANT(CLOSE_BUTTON_SHOW_NEVER); - BIND_CONSTANT(CLOSE_BUTTON_MAX); + BIND_ENUM_CONSTANT(CLOSE_BUTTON_SHOW_ACTIVE_ONLY); + BIND_ENUM_CONSTANT(CLOSE_BUTTON_SHOW_ALWAYS); + BIND_ENUM_CONSTANT(CLOSE_BUTTON_SHOW_NEVER); + BIND_ENUM_CONSTANT(CLOSE_BUTTON_MAX); } Tabs::Tabs() { diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index 86ad128dcd..73fa40bbb8 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 2b47539c42..7a9daea73e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -27,13 +27,12 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ - #include "text_edit.h" + +#include "message_queue.h" #include "os/input.h" #include "os/keyboard.h" #include "os/os.h" - -#include "message_queue.h" #include "project_settings.h" #include "scene/main/viewport.h" @@ -215,8 +214,8 @@ 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) { - Map<int, ColorRegionInfo> *cri = NULL; - ERR_FAIL_INDEX_V(p_line, text.size(), *cri); //enjoy your crash + static Map<int, ColorRegionInfo> cri; + ERR_FAIL_INDEX_V(p_line, text.size(), cri); if (text[p_line].width_cache == -1) { _update_line_cache(p_line); @@ -338,6 +337,11 @@ void TextEdit::_update_scrollbars() { v_scroll->show(); v_scroll->set_max(total_rows); v_scroll->set_page(visible_rows); + if (smooth_scroll_enabled) { + v_scroll->set_step(0.25); + } else { + v_scroll->set_step(1); + } if (fabs(v_scroll->get_value() - (double)cursor.line_ofs) >= 1) { v_scroll->set_value(cursor.line_ofs); @@ -420,6 +424,24 @@ void TextEdit::_notification(int p_what) { draw_caret = false; update(); } break; + case NOTIFICATION_FIXED_PROCESS: { + if (scrolling && v_scroll->get_value() != target_v_scroll) { + double target_y = target_v_scroll - v_scroll->get_value(); + double dist = sqrt(target_y * target_y); + double vel = ((target_y / dist) * v_scroll_speed) * get_fixed_process_delta_time(); + + if (vel >= dist) { + v_scroll->set_value(target_v_scroll); + scrolling = false; + set_fixed_process(false); + } else { + v_scroll->set_value(v_scroll->get_value() + vel); + } + } else { + scrolling = false; + set_fixed_process(false); + } + } break; case NOTIFICATION_DRAW: { if ((!has_focus() && !menu->has_focus()) || !window_has_focus) { @@ -436,7 +458,7 @@ void TextEdit::_notification(int p_what) { int line_number_char_count = 0; { - int lc = text.size() + 1; + int lc = text.size(); cache.line_number_w = 0; while (lc) { cache.line_number_w += 1; @@ -454,6 +476,7 @@ void TextEdit::_notification(int p_what) { _update_scrollbars(); RID ci = get_canvas_item(); + VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width; int xmargin_end = cache.size.width - cache.style_normal->get_margin(MARGIN_RIGHT); //let's do it easy for now: @@ -463,7 +486,7 @@ void TextEdit::_notification(int p_what) { int ascent = cache.font->get_ascent(); - int visible_rows = get_visible_rows(); + int visible_rows = get_visible_rows() + 1; int tab_w = cache.font->get_char_size(' ').width * indent_size; @@ -674,7 +697,11 @@ void TextEdit::_notification(int p_what) { int char_margin = xmargin_beg - cursor.x_ofs; int char_ofs = 0; - int ofs_y = i * get_row_height() + cache.line_spacing / 2; + int ofs_y = (i * get_row_height() + cache.line_spacing / 2); + if (smooth_scroll_enabled) { + ofs_y -= (v_scroll->get_value() - cursor.line_ofs) * get_row_height(); + } + bool prev_is_char = false; bool prev_is_number = false; bool in_keyword = false; @@ -1028,6 +1055,8 @@ void TextEdit::_notification(int p_what) { if (cursor.column == j && cursor.line == line && block_caret && draw_caret && !insert_mode) { color = cache.caret_background_color; + } else if (!syntax_coloring && block_caret) { + color = cache.font_color; } if (str[j] >= 32) { @@ -1498,7 +1527,7 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co float rows = p_mouse.y; rows -= cache.style_normal->get_margin(MARGIN_TOP); rows /= get_row_height(); - int row = cursor.line_ofs + rows; + int row = cursor.line_ofs + (rows + (v_scroll->get_value() - cursor.line_ofs)); if (row < 0) row = 0; @@ -1564,10 +1593,43 @@ 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()) { - v_scroll->set_value(v_scroll->get_value() - (3 * mb->get_factor())); + if (scrolling) { + target_v_scroll = (target_v_scroll - (3 * mb->get_factor())); + } else { + target_v_scroll = (v_scroll->get_value() - (3 * mb->get_factor())); + } + + if (smooth_scroll_enabled) { + if (target_v_scroll <= 0) { + target_v_scroll = 0; + } + scrolling = true; + set_fixed_process(true); + } else { + v_scroll->set_value(target_v_scroll); + } } if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) { - v_scroll->set_value(v_scroll->get_value() + (3 * mb->get_factor())); + if (scrolling) { + target_v_scroll = (target_v_scroll + (3 * mb->get_factor())); + } else { + target_v_scroll = (v_scroll->get_value() + (3 * mb->get_factor())); + } + + if (smooth_scroll_enabled) { + int max_v_scroll = get_line_count() - 1; + if (!scroll_past_end_of_file_enabled) { + max_v_scroll -= get_visible_rows() - 1; + } + + if (target_v_scroll > max_v_scroll) { + target_v_scroll = max_v_scroll; + } + scrolling = true; + set_fixed_process(true); + } else { + v_scroll->set_value(target_v_scroll); + } } if (mb->get_button_index() == BUTTON_WHEEL_LEFT) { h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor())); @@ -2052,14 +2114,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { //keep indentation int space_count = 0; for (int i = 0; i < text[cursor.line].length(); i++) { - if (text[cursor.line][i] == '\t') { + if (text[cursor.line][i] == '\t' && cursor.column > 0) { if (indent_using_spaces) { ins += space_indent; } else { ins += "\t"; } space_count = 0; - } else if (text[cursor.line][i] == ' ') { + } else if (text[cursor.line][i] == ' ' && cursor.column > 0) { space_count++; if (space_count == indent_size) { @@ -2248,6 +2310,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { #endif bool prev_char = false; int cc = cursor.column; + + if (cc == 0 && cursor.line > 0) { + cursor_set_line(cursor.line - 1); + cursor_set_column(text[cursor.line].length()); + break; + } + while (cc > 0) { bool ischar = _is_text_char(text[cursor.line][cc - 1]); @@ -2305,6 +2374,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { #endif bool prev_char = false; int cc = cursor.column; + + if (cc == text[cursor.line].length() && cursor.line < text.size() - 1) { + cursor_set_line(cursor.line + 1); + cursor_set_column(0); + break; + } + while (cc < text[cursor.line].length()) { bool ischar = _is_text_char(text[cursor.line][cc]); @@ -2659,6 +2735,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { else undo(); } break; + case KEY_Y: { + + if (!k->get_command()) { + scancode_handled = false; + break; + } + + redo(); + } break; case KEY_V: { if (readonly) { break; @@ -2803,6 +2888,8 @@ void TextEdit::_post_shift_selection() { } void TextEdit::_scroll_lines_up() { + scrolling = false; + // adjust the vertical scroll if (get_v_scroll() > 0) { set_v_scroll(get_v_scroll() - 1); @@ -2815,6 +2902,8 @@ void TextEdit::_scroll_lines_up() { } void TextEdit::_scroll_lines_down() { + scrolling = false; + // calculate the maximum vertical scroll position int max_v_scroll = get_line_count() - 1; if (!scroll_past_end_of_file_enabled) { @@ -3079,6 +3168,7 @@ int TextEdit::get_visible_rows() const { return total; } void TextEdit::adjust_viewport_to_cursor() { + scrolling = false; if (cursor.line_ofs > cursor.line) cursor.line_ofs = cursor.line; @@ -3095,10 +3185,15 @@ void TextEdit::adjust_viewport_to_cursor() { visible_rows -= ((h_scroll->get_combined_minimum_size().height - 1) / get_row_height()); if (cursor.line >= (cursor.line_ofs + visible_rows)) - cursor.line_ofs = cursor.line - visible_rows + 1; + cursor.line_ofs = cursor.line - visible_rows; if (cursor.line < cursor.line_ofs) cursor.line_ofs = cursor.line; + if (cursor.line_ofs + visible_rows > text.size() && !scroll_past_end_of_file_enabled) { + cursor.line_ofs = text.size() - visible_rows; + v_scroll->set_value(text.size() - visible_rows); + } + int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]); if (cursor_x > (cursor.x_ofs + visible_width)) @@ -3118,6 +3213,7 @@ void TextEdit::adjust_viewport_to_cursor() { } void TextEdit::center_viewport_to_cursor() { + scrolling = false; if (cursor.line_ofs > cursor.line) cursor.line_ofs = cursor.line; @@ -3236,6 +3332,10 @@ bool TextEdit::cursor_is_block_mode() const { return block_caret; } +void TextEdit::_v_scroll_input() { + scrolling = false; +} + void TextEdit::_scroll_moved(double p_to_val) { if (updating_scrolls) @@ -3566,10 +3666,10 @@ void TextEdit::cut() { String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); OS::get_singleton()->set_clipboard(clipboard); - cursor_set_line(selection.from_line); + _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); + cursor_set_line(selection.from_line); // set afterwards else it causes the view to be offset cursor_set_column(selection.from_column); - _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); selection.active = false; selection.selecting_mode = Selection::MODE_NONE; update(); @@ -3579,9 +3679,6 @@ void TextEdit::cut() { void TextEdit::copy() { - if (!selection.active) - return; - if (!selection.active) { String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length()); OS::get_singleton()->set_clipboard(clipboard); @@ -3821,11 +3918,9 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l //search through the whole documment, but start by current line - int line = -1; + int line = p_from_line; int pos = -1; - line = p_from_line; - for (int i = 0; i < text.size() + 1; i++) { //backwards is broken... //int idx=(p_search_flags&SEARCH_BACKWARDS)?(text.size()-i):i; //do backwards seearch @@ -4178,6 +4273,23 @@ void TextEdit::set_h_scroll(int p_scroll) { h_scroll->set_value(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(); @@ -4220,6 +4332,7 @@ void TextEdit::_cancel_completion() { return; completion_active = false; + completion_forced = false; update(); } @@ -4287,13 +4400,19 @@ void TextEdit::_update_completion_candidates() { } } - if (cursor.column > 0 && l[cursor.column - 1] == '(' && !pre_keyword && !completion_strings[0].begins_with("\"")) { + if (cursor.column > 0 && l[cursor.column - 1] == '(' && !pre_keyword && !completion_forced) { cancel = true; } update(); - if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !completion_prefixes.has(String::chr(l[cofs - 1]))))) { + bool prev_is_prefix = false; + if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1]))) + prev_is_prefix = true; + if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2]))) //check with one space before prefix, to allow indent + prev_is_prefix = true; + + if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !prev_is_prefix))) { //none to complete, cancel _cancel_completion(); return; @@ -4351,18 +4470,6 @@ void TextEdit::_update_completion_candidates() { // The top of the list is the best match completion_current = completion_options[0]; - -#if 0 // even there's only one option, user still get the chance to choose using it or not - if (completion_options.size()==1) { - //one option to complete, just complete it automagically - _confirm_completion(); - //insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length())); - _cancel_completion(); - return; - - } -#endif - completion_enabled = true; } @@ -4382,6 +4489,8 @@ void TextEdit::query_code_comple() { if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1])))) emit_signal("request_completion"); + else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) //make it work with a space too, it's good enough + emit_signal("request_completion"); } void TextEdit::set_code_hint(const String &p_hint) { @@ -4393,12 +4502,13 @@ void TextEdit::set_code_hint(const String &p_hint) { update(); } -void TextEdit::code_complete(const Vector<String> &p_strings) { +void TextEdit::code_complete(const Vector<String> &p_strings, bool p_forced) { VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1); raised_from_completion = true; completion_strings = p_strings; completion_active = true; + completion_forced = p_forced; completion_current = ""; completion_index = 0; _update_completion_candidates(); @@ -4617,10 +4727,11 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("_push_current_op"), &TextEdit::_push_current_op); ClassDB::bind_method(D_METHOD("_click_selection_held"), &TextEdit::_click_selection_held); ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &TextEdit::_toggle_draw_caret); + ClassDB::bind_method(D_METHOD("_v_scroll_input"), &TextEdit::_v_scroll_input); - BIND_CONSTANT(SEARCH_MATCH_CASE); - BIND_CONSTANT(SEARCH_WHOLE_WORDS); - BIND_CONSTANT(SEARCH_BACKWARDS); + BIND_ENUM_CONSTANT(SEARCH_MATCH_CASE); + BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS); + BIND_ENUM_CONSTANT(SEARCH_BACKWARDS); /* ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char); @@ -4678,6 +4789,11 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_syntax_coloring", "enable"), &TextEdit::set_syntax_coloring); ClassDB::bind_method(D_METHOD("is_syntax_coloring_enabled"), &TextEdit::is_syntax_coloring_enabled); + ClassDB::bind_method(D_METHOD("set_smooth_scroll_enable", "enable"), &TextEdit::set_smooth_scroll_enabled); + ClassDB::bind_method(D_METHOD("is_smooth_scroll_enabled"), &TextEdit::is_smooth_scroll_enabled); + ClassDB::bind_method(D_METHOD("set_v_scroll_speed", "speed"), &TextEdit::set_v_scroll_speed); + ClassDB::bind_method(D_METHOD("get_v_scroll_speed"), &TextEdit::get_v_scroll_speed); + ClassDB::bind_method(D_METHOD("add_keyword_color", "keyword", "color"), &TextEdit::add_keyword_color); ClassDB::bind_method(D_METHOD("add_color_region", "begin_key", "end_key", "color", "line_only"), &TextEdit::add_color_region, DEFVAL(false)); ClassDB::bind_method(D_METHOD("clear_colors"), &TextEdit::clear_colors); @@ -4687,6 +4803,8 @@ void TextEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "syntax_highlighting"), "set_syntax_coloring", "is_syntax_coloring_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), "set_show_line_numbers", "is_show_line_numbers_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scrolling"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed"); ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode"); @@ -4699,13 +4817,13 @@ void TextEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("breakpoint_toggled", PropertyInfo(Variant::INT, "row"))); ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::INT, "column"))); - BIND_CONSTANT(MENU_CUT); - BIND_CONSTANT(MENU_COPY); - BIND_CONSTANT(MENU_PASTE); - BIND_CONSTANT(MENU_CLEAR); - BIND_CONSTANT(MENU_SELECT_ALL); - BIND_CONSTANT(MENU_UNDO); - BIND_CONSTANT(MENU_MAX); + BIND_ENUM_CONSTANT(MENU_CUT); + BIND_ENUM_CONSTANT(MENU_COPY); + BIND_ENUM_CONSTANT(MENU_PASTE); + BIND_ENUM_CONSTANT(MENU_CLEAR); + BIND_ENUM_CONSTANT(MENU_SELECT_ALL); + BIND_ENUM_CONSTANT(MENU_UNDO); + BIND_ENUM_CONSTANT(MENU_MAX); GLOBAL_DEF("gui/timers/text_edit_idle_detect_sec", 3); } @@ -4747,6 +4865,8 @@ TextEdit::TextEdit() { h_scroll->connect("value_changed", this, "_scroll_moved"); v_scroll->connect("value_changed", this, "_scroll_moved"); + v_scroll->connect("scrolling", this, "_v_scroll_input"); + cursor_changed_dirty = false; text_changed_dirty = false; @@ -4776,24 +4896,6 @@ TextEdit::TextEdit() { click_select_held->set_wait_time(0.05); click_select_held->connect("timeout", this, "_click_selection_held"); -#if 0 - syntax_coloring=true; - keywords["void"]=Color(0.3,0.0,0.1); - keywords["int"]=Color(0.3,0.0,0.1); - keywords["function"]=Color(0.3,0.0,0.1); - keywords["class"]=Color(0.3,0.0,0.1); - keywords["extends"]=Color(0.3,0.0,0.1); - keywords["constructor"]=Color(0.3,0.0,0.1); - symbol_color=Color(0.1,0.0,0.3,1.0); - - color_regions.push_back(ColorRegion("/*","*/",Color(0.4,0.6,0,4))); - color_regions.push_back(ColorRegion("//","",Color(0.6,0.6,0.4))); - color_regions.push_back(ColorRegion("\"","\"",Color(0.4,0.7,0.7))); - color_regions.push_back(ColorRegion("'","'",Color(0.4,0.8,0.8))); - color_regions.push_back(ColorRegion("#","",Color(0.2,1.0,0.2))); - -#endif - current_op.type = TextOperation::TYPE_NONE; undo_enabled = true; undo_stack_pos = NULL; @@ -4823,6 +4925,10 @@ TextEdit::TextEdit() { insert_mode = false; window_has_focus = true; select_identifiers_enabled = false; + smooth_scroll_enabled = false; + scrolling = false; + target_v_scroll = 0; + v_scroll_speed = 80; raised_from_completion = false; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 4c17347a5d..68ef559f46 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -205,6 +205,7 @@ class TextEdit : public Control { Vector<String> completion_strings; Vector<String> completion_options; bool completion_active; + bool completion_forced; String completion_current; String completion_base; int completion_index; @@ -256,6 +257,11 @@ class TextEdit : public Control { bool insert_mode; bool select_identifiers_enabled; + bool smooth_scroll_enabled; + bool scrolling; + float target_v_scroll; + float v_scroll_speed; + bool raised_from_completion; String highlighted_word; @@ -294,6 +300,7 @@ class TextEdit : public Control { void adjust_viewport_to_cursor(); void _scroll_moved(double); void _update_scrollbars(); + void _v_scroll_input(); void _click_selection_held(); void _pre_shift_selection(); @@ -487,6 +494,12 @@ public: int get_h_scroll() const; void set_h_scroll(int p_scroll); + void set_smooth_scroll_enabled(bool p_enable); + bool is_smooth_scroll_enabled() const; + + void set_v_scroll_speed(float p_speed); + float get_v_scroll_speed() const; + uint32_t get_version() const; uint32_t get_saved_version() const; void tag_saved_version(); @@ -510,7 +523,7 @@ public: void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata); void set_completion(bool p_enabled, const Vector<String> &p_prefixes); - void code_complete(const Vector<String> &p_strings); + void code_complete(const Vector<String> &p_strings, bool p_forced = false); void set_code_hint(const String &p_hint); void query_code_comple(); @@ -528,4 +541,7 @@ public: ~TextEdit(); }; +VARIANT_ENUM_CAST(TextEdit::MenuItems); +VARIANT_ENUM_CAST(TextEdit::SearchFlags); + #endif // TEXT_EDIT_H diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 7abf8380ce..77bc876201 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -208,13 +208,13 @@ void TextureButton::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "expand", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_expand", "get_expand"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode"); - BIND_CONSTANT(STRETCH_SCALE); - BIND_CONSTANT(STRETCH_TILE); - BIND_CONSTANT(STRETCH_KEEP); - BIND_CONSTANT(STRETCH_KEEP_CENTERED); - BIND_CONSTANT(STRETCH_KEEP_ASPECT); - BIND_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED); - BIND_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); + BIND_ENUM_CONSTANT(STRETCH_SCALE); + BIND_ENUM_CONSTANT(STRETCH_TILE); + BIND_ENUM_CONSTANT(STRETCH_KEEP); + BIND_ENUM_CONSTANT(STRETCH_KEEP_CENTERED); + BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT); + BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED); + BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); } void TextureButton::set_normal_texture(const Ref<Texture> &p_normal) { diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h index 8df30cd35a..94f372decf 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index 081c7ddb73..aad7c6b96b 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -29,6 +29,8 @@ /*************************************************************************/ #include "texture_progress.h" +#include "engine.h" + void TextureProgress::set_under_texture(const Ref<Texture> &p_texture) { under = p_texture; @@ -55,9 +57,33 @@ Ref<Texture> TextureProgress::get_over_texture() const { return over; } +void TextureProgress::set_stretch_margin(Margin p_margin, int p_size) { + ERR_FAIL_INDEX(p_margin, 4); + stretch_margin[p_margin] = p_size; + update(); + minimum_size_changed(); +} + +int TextureProgress::get_stretch_margin(Margin p_margin) const { + ERR_FAIL_INDEX_V(p_margin, 4, 0); + return stretch_margin[p_margin]; +} + +void TextureProgress::set_nine_patch_stretch(bool p_stretch) { + nine_patch_stretch = p_stretch; + update(); + minimum_size_changed(); +} + +bool TextureProgress::get_nine_patch_stretch() const { + return nine_patch_stretch; +} + Size2 TextureProgress::get_minimum_size() const { - if (under.is_valid()) + 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()) return under->get_size(); else if (over.is_valid()) return over->get_size(); @@ -120,80 +146,165 @@ Point2 TextureProgress::get_relative_center() { return p; } +void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, FillMode p_mode, double p_ratio) { + Vector2 texture_size = p_texture->get_size(); + Vector2 topleft = Vector2(stretch_margin[MARGIN_LEFT], stretch_margin[MARGIN_TOP]); + Vector2 bottomright = Vector2(stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_BOTTOM]); + + Rect2 src_rect = Rect2(Point2(), texture_size); + Rect2 dst_rect = Rect2(Point2(), get_size()); + + if (p_ratio < 1.0) { + // Drawing a partially-filled 9-patch is a little tricky - + // texture is divided by 3 sections toward fill direction, + // then middle section is streching while the other two aren't. + + double width_total = 0.0; + double width_texture = 0.0; + double first_section_size = 0.0; + double last_section_size = 0.0; + switch (mode) { + case FILL_LEFT_TO_RIGHT: + case FILL_RIGHT_TO_LEFT: { + width_total = dst_rect.size.x; + width_texture = texture_size.x; + first_section_size = topleft.x; + last_section_size = bottomright.x; + } break; + case FILL_TOP_TO_BOTTOM: + case FILL_BOTTOM_TO_TOP: { + width_total = dst_rect.size.y; + width_texture = texture_size.y; + first_section_size = topleft.y; + last_section_size = bottomright.y; + } break; + } + + double width_filled = width_total * p_ratio; + double middle_section_size = MAX(0.0, width_texture - first_section_size - last_section_size); + + middle_section_size *= MIN(1.0, (MAX(0.0, width_filled - first_section_size) / MAX(1.0, width_total - first_section_size - last_section_size))); + last_section_size = MAX(0.0, last_section_size - (width_total - width_filled)); + width_texture = MIN(width_texture, first_section_size + middle_section_size + last_section_size); + + switch (mode) { + case FILL_LEFT_TO_RIGHT: { + src_rect.size.x = width_texture; + dst_rect.size.x = width_filled; + bottomright.x = last_section_size; + } break; + case FILL_RIGHT_TO_LEFT: { + src_rect.position.x += src_rect.size.x - width_texture; + src_rect.size.x = width_texture; + dst_rect.position.x += width_total - width_filled; + dst_rect.size.x = width_filled; + topleft.x = last_section_size; + } break; + case FILL_TOP_TO_BOTTOM: { + src_rect.size.y = width_texture; + dst_rect.size.y = width_filled; + bottomright.y = last_section_size; + } break; + case FILL_BOTTOM_TO_TOP: { + src_rect.position.y += src_rect.size.y - width_texture; + src_rect.size.y = width_texture; + dst_rect.position.y += width_total - width_filled; + dst_rect.size.y = width_filled; + topleft.y = last_section_size; + } break; + } + } + + RID ci = get_canvas_item(); + VS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright); +} + 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 (under.is_valid()) - draw_texture(under, Point2()); - if (progress.is_valid()) { - Size2 s = progress->get_size(); - switch (mode) { - case FILL_LEFT_TO_RIGHT: { - Rect2 region = Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_RIGHT_TO_LEFT: { - Rect2 region = Rect2(Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y)); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_TOP_TO_BOTTOM: { - Rect2 region = Rect2(Point2(), Size2(s.x, s.y * get_as_ratio())); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_BOTTOM_TO_TOP: { - Rect2 region = Rect2(Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio())); - draw_texture_rect_region(progress, region, region); - } break; - case FILL_CLOCKWISE: - case FILL_COUNTER_CLOCKWISE: { - float val = get_as_ratio() * rad_max_degrees / 360; - if (val == 1) { - Rect2 region = Rect2(Point2(), s); + 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); + } + if (progress.is_valid()) { + draw_nine_patch_stretched(progress, mode, get_as_ratio()); + } + if (over.is_valid()) { + draw_nine_patch_stretched(over, FILL_LEFT_TO_RIGHT, 1.0); + } + } else { + if (under.is_valid()) + draw_texture(under, Point2()); + if (progress.is_valid()) { + Size2 s = progress->get_size(); + switch (mode) { + case FILL_LEFT_TO_RIGHT: { + Rect2 region = Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)); + draw_texture_rect_region(progress, region, region); + } break; + case FILL_RIGHT_TO_LEFT: { + Rect2 region = Rect2(Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y)); draw_texture_rect_region(progress, region, region); - } else if (val != 0) { - Array pts; - float direction = mode == FILL_CLOCKWISE ? 1 : -1; - float start = rad_init_angle / 360; - float end = start + direction * val; - pts.append(start); - pts.append(end); - float from = MIN(start, end); - float to = MAX(start, end); - for (int i = 0; i < 12; i++) - if (corners[i] > from && corners[i] < to) - pts.append(corners[i]); - pts.sort(); - Vector<Point2> uvs; - Vector<Point2> points; - uvs.push_back(get_relative_center()); - points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y)); - for (int i = 0; i < pts.size(); i++) { - Point2 uv = unit_val_to_uv(pts[i]); - if (uvs.find(uv) >= 0) - continue; - uvs.push_back(uv); - points.push_back(Point2(uv.x * s.x, uv.y * s.y)); + } break; + case FILL_TOP_TO_BOTTOM: { + Rect2 region = Rect2(Point2(), Size2(s.x, s.y * get_as_ratio())); + draw_texture_rect_region(progress, region, region); + } break; + case FILL_BOTTOM_TO_TOP: { + Rect2 region = Rect2(Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio())); + draw_texture_rect_region(progress, region, region); + } break; + case FILL_CLOCKWISE: + case FILL_COUNTER_CLOCKWISE: { + float val = get_as_ratio() * rad_max_degrees / 360; + if (val == 1) { + Rect2 region = Rect2(Point2(), s); + draw_texture_rect_region(progress, region, region); + } else if (val != 0) { + Array pts; + float direction = mode == FILL_CLOCKWISE ? 1 : -1; + float start = rad_init_angle / 360; + float end = start + direction * val; + pts.append(start); + pts.append(end); + float from = MIN(start, end); + float to = MAX(start, end); + for (int i = 0; i < 12; i++) + if (corners[i] > from && corners[i] < to) + pts.append(corners[i]); + pts.sort(); + Vector<Point2> uvs; + Vector<Point2> points; + uvs.push_back(get_relative_center()); + points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y)); + for (int i = 0; i < pts.size(); i++) { + Point2 uv = unit_val_to_uv(pts[i]); + if (uvs.find(uv) >= 0) + continue; + uvs.push_back(uv); + points.push_back(Point2(uv.x * s.x, uv.y * s.y)); + } + draw_polygon(points, Vector<Color>(), uvs, progress); } - draw_polygon(points, Vector<Color>(), uvs, progress); - } - if (get_tree()->is_editor_hint()) { - Point2 p = progress->get_size(); - p.x *= get_relative_center().x; - p.y *= get_relative_center().y; - p = p.floor(); - draw_line(p - Point2(8, 0), p + Point2(8, 0), Color(0.9, 0.5, 0.5), 2); - draw_line(p - Point2(0, 8), p + Point2(0, 8), Color(0.9, 0.5, 0.5), 2); - } - } break; - default: - draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y))); + if (Engine::get_singleton()->is_editor_hint()) { + Point2 p = progress->get_size(); + p.x *= get_relative_center().x; + p.y *= get_relative_center().y; + p = p.floor(); + draw_line(p - Point2(8, 0), p + Point2(8, 0), Color(0.9, 0.5, 0.5), 2); + draw_line(p - Point2(0, 8), p + Point2(0, 8), Color(0.9, 0.5, 0.5), 2); + } + } break; + default: + draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y))); + } } + if (over.is_valid()) + draw_texture(over, Point2()); } - if (over.is_valid()) - draw_texture(over, Point2()); } break; } @@ -263,6 +374,12 @@ void TextureProgress::_bind_methods() { ClassDB::bind_method(D_METHOD("set_fill_degrees", "mode"), &TextureProgress::set_fill_degrees); ClassDB::bind_method(D_METHOD("get_fill_degrees"), &TextureProgress::get_fill_degrees); + ClassDB::bind_method(D_METHOD("set_stretch_margin", "margin", "value"), &TextureProgress::set_stretch_margin); + ClassDB::bind_method(D_METHOD("get_stretch_margin", "margin"), &TextureProgress::get_stretch_margin); + + ClassDB::bind_method(D_METHOD("set_nine_patch_stretch", "stretch"), &TextureProgress::set_nine_patch_stretch); + ClassDB::bind_method(D_METHOD("get_nine_patch_stretch"), &TextureProgress::get_nine_patch_stretch); + ADD_GROUP("Textures", "texture_"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_under", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_under_texture", "get_under_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_over", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_over_texture", "get_over_texture"); @@ -272,13 +389,19 @@ void TextureProgress::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "radial_initial_angle", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_radial_initial_angle", "get_radial_initial_angle"); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "radial_fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_fill_degrees", "get_fill_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "radial_center_offset"), "set_radial_center_offset", "get_radial_center_offset"); - - BIND_CONSTANT(FILL_LEFT_TO_RIGHT); - BIND_CONSTANT(FILL_RIGHT_TO_LEFT); - BIND_CONSTANT(FILL_TOP_TO_BOTTOM); - BIND_CONSTANT(FILL_BOTTOM_TO_TOP); - BIND_CONSTANT(FILL_CLOCKWISE); - BIND_CONSTANT(FILL_COUNTER_CLOCKWISE); + ADD_GROUP("Stretch", "stretch_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "nine_patch_stretch"), "set_nine_patch_stretch", "get_nine_patch_stretch"); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_left", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_LEFT); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_top", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_TOP); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_right", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_RIGHT); + ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "stretch_margin_bottom", PROPERTY_HINT_RANGE, "0,16384,1"), "set_stretch_margin", "get_stretch_margin", MARGIN_BOTTOM); + + BIND_ENUM_CONSTANT(FILL_LEFT_TO_RIGHT); + BIND_ENUM_CONSTANT(FILL_RIGHT_TO_LEFT); + BIND_ENUM_CONSTANT(FILL_TOP_TO_BOTTOM); + BIND_ENUM_CONSTANT(FILL_BOTTOM_TO_TOP); + BIND_ENUM_CONSTANT(FILL_CLOCKWISE); + BIND_ENUM_CONSTANT(FILL_COUNTER_CLOCKWISE); } TextureProgress::TextureProgress() { @@ -287,4 +410,10 @@ TextureProgress::TextureProgress() { rad_center_off = Point2(); rad_max_degrees = 360; set_mouse_filter(MOUSE_FILTER_PASS); + + nine_patch_stretch = false; + stretch_margin[MARGIN_LEFT] = 0; + stretch_margin[MARGIN_RIGHT] = 0; + stretch_margin[MARGIN_BOTTOM] = 0; + stretch_margin[MARGIN_TOP] = 0; } diff --git a/scene/gui/texture_progress.h b/scene/gui/texture_progress.h index c0c2779cf9..04096d35e3 100644 --- a/scene/gui/texture_progress.h +++ b/scene/gui/texture_progress.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -75,6 +75,12 @@ public: void set_over_texture(const Ref<Texture> &p_texture); Ref<Texture> get_over_texture() const; + void set_stretch_margin(Margin p_margin, int p_size); + int get_stretch_margin(Margin p_margin) const; + + void set_nine_patch_stretch(bool p_stretch); + bool get_nine_patch_stretch() const; + Size2 get_minimum_size() const; TextureProgress(); @@ -84,9 +90,14 @@ private: float rad_init_angle; float rad_max_degrees; Point2 rad_center_off; + bool nine_patch_stretch; + int stretch_margin[4]; Point2 unit_val_to_uv(float val); Point2 get_relative_center(); + void draw_nine_patch_stretched(const Ref<Texture> &p_texture, FillMode p_mode, double p_ratio); }; +VARIANT_ENUM_CAST(TextureProgress::FillMode); + #endif // TEXTURE_PROGRESS_H diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp index 92a3db6a74..38f90fe7b5 100644 --- a/scene/gui/texture_rect.cpp +++ b/scene/gui/texture_rect.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -112,14 +112,14 @@ void TextureRect::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "expand"), "set_expand", "has_expand"); ADD_PROPERTYNO(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode"); - BIND_CONSTANT(STRETCH_SCALE_ON_EXPAND); - BIND_CONSTANT(STRETCH_SCALE); - BIND_CONSTANT(STRETCH_TILE); - BIND_CONSTANT(STRETCH_KEEP); - BIND_CONSTANT(STRETCH_KEEP_CENTERED); - BIND_CONSTANT(STRETCH_KEEP_ASPECT); - BIND_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED); - BIND_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); + BIND_ENUM_CONSTANT(STRETCH_SCALE_ON_EXPAND); + BIND_ENUM_CONSTANT(STRETCH_SCALE); + BIND_ENUM_CONSTANT(STRETCH_TILE); + BIND_ENUM_CONSTANT(STRETCH_KEEP); + BIND_ENUM_CONSTANT(STRETCH_KEEP_CENTERED); + BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT); + BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_CENTERED); + BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); } void TextureRect::set_texture(const Ref<Texture> &p_tex) { diff --git a/scene/gui/texture_rect.h b/scene/gui/texture_rect.h index dcc6c3f9bd..8a2b715488 100644 --- a/scene/gui/texture_rect.h +++ b/scene/gui/texture_rect.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/tool_button.cpp b/scene/gui/tool_button.cpp index 5fc4b6ecf8..4dfa3d8f37 100644 --- a/scene/gui/tool_button.cpp +++ b/scene/gui/tool_button.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/tool_button.h b/scene/gui/tool_button.h index d243b5559f..4c5ea685de 100644 --- a/scene/gui/tool_button.h +++ b/scene/gui/tool_button.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index fa499ff277..5e15bceb7d 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,6 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "tree.h" + #include "os/input.h" #include "os/keyboard.h" #include "os/os.h" @@ -752,12 +753,12 @@ void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_disable_folding", "disable"), &TreeItem::set_disable_folding); ClassDB::bind_method(D_METHOD("is_folding_disabled"), &TreeItem::is_folding_disabled); - BIND_CONSTANT(CELL_MODE_STRING); - BIND_CONSTANT(CELL_MODE_CHECK); - BIND_CONSTANT(CELL_MODE_RANGE); - BIND_CONSTANT(CELL_MODE_RANGE_EXPRESSION); - BIND_CONSTANT(CELL_MODE_ICON); - BIND_CONSTANT(CELL_MODE_CUSTOM); + BIND_ENUM_CONSTANT(CELL_MODE_STRING); + BIND_ENUM_CONSTANT(CELL_MODE_CHECK); + BIND_ENUM_CONSTANT(CELL_MODE_RANGE); + BIND_ENUM_CONSTANT(CELL_MODE_RANGE_EXPRESSION); + BIND_ENUM_CONSTANT(CELL_MODE_ICON); + BIND_ENUM_CONSTANT(CELL_MODE_CUSTOM); } void TreeItem::clear_children() { @@ -990,41 +991,10 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co rect.size.x -= bmsize.x + cache.hseparation; } - /* - if (p_tool) - rect.size.x-=Math::floor(rect.size.y/2); - */ - rect.position.y += Math::floor((rect.size.y - font->get_height()) / 2.0) + font->get_ascent(); font->draw(ci, rect.position, text, p_color, rect.size.x); } -#if 0 -void Tree::draw_item_text(String p_text,const Ref<Texture>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color) { - - RID ci = get_canvas_item(); - if (!p_icon.is_null()) { - Size2i bmsize = p_icon->get_size(); - if (p_icon_max_w>0 && bmsize.width > p_icon_max_w) { - bmsize.height = bmsize.height * p_icon_max_w / bmsize.width; - bmsize.width=p_icon_max_w; - } - - draw_texture_rect(p_icon,Rect2(p_rect.pos + Size2i(0,Math::floor((p_rect.size.y-bmsize.y)/2)),bmsize)); - p_rect.pos.x+=bmsize.x+cache.hseparation; - p_rect.size.x-=bmsize.x+cache.hseparation; - - } - - if (p_tool) - p_rect.size.x-=Math::floor(p_rect.size.y/2); - - Ref<Font> font = cache.font; - - p_rect.pos.y+=Math::floor((p_rect.size.y-font->get_height())/2.0) +font->get_ascent(); - font->draw(ci,p_rect.pos,p_text,p_color,p_rect.size.x); -} -#endif 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)) @@ -1455,11 +1425,10 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c if (select_mode == SELECT_ROW) { - if (p_selected == p_current && !c.selected) { + if (p_selected == p_current && (!c.selected || allow_reselect)) { c.selected = true; selected_item = p_selected; selected_col = 0; - selected_item = p_selected; if (!emitted_row) { emit_signal("item_selected"); emitted_row = true; @@ -1478,7 +1447,7 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c if (!r_in_range && &selected_cell == &c) { - if (!selected_cell.selected || force_select_on_already_selected) { + if (!selected_cell.selected || allow_reselect) { selected_cell.selected = true; @@ -1743,7 +1712,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool /* editing */ - bool bring_up_editor = force_select_on_already_selected ? (c.selected && already_selected) : c.selected; + bool bring_up_editor = allow_reselect ? (c.selected && already_selected) : c.selected; String editor_text = c.text; switch (c.mode) { @@ -2474,22 +2443,24 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { Point2 pos = b->get_position() - bg->get_offset(); cache.click_type = Cache::CLICK_NONE; - if (show_column_titles && b->get_button_index() == BUTTON_LEFT) { + if (show_column_titles) { pos.y -= _get_title_button_height(); if (pos.y < 0) { - 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=; - update(); - break; + if (b->get_button_index() == BUTTON_LEFT) { + 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=; + update(); + break; + } } } break; @@ -2869,8 +2840,8 @@ TreeItem *Tree::create_item(TreeItem *p_parent) { TreeItem *ti = memnew(TreeItem(this)); - ti->cells.resize(columns.size()); ERR_FAIL_COND_V(!ti, NULL); + ti->cells.resize(columns.size()); if (p_parent) { @@ -3557,16 +3528,6 @@ int Tree::get_drop_mode_flags() const { return drop_mode_flags; } -void Tree::set_single_select_cell_editing_only_when_already_selected(bool p_enable) { - - force_select_on_already_selected = p_enable; -} - -bool Tree::get_single_select_cell_editing_only_when_already_selected() const { - - return force_select_on_already_selected; -} - void Tree::set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable) { force_edit_checkbox_only_on_checkbox = p_enable; @@ -3587,6 +3548,15 @@ bool Tree::get_allow_rmb_select() const { return allow_rmb_select; } +void Tree::set_allow_reselect(bool p_allow) { + allow_reselect = p_allow; +} + +bool Tree::get_allow_reselect() const { + + return allow_reselect; +} + void Tree::_bind_methods() { ClassDB::bind_method(D_METHOD("_range_click_timeout"), &Tree::_range_click_timeout); @@ -3640,8 +3610,8 @@ void Tree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_allow_rmb_select", "allow"), &Tree::set_allow_rmb_select); ClassDB::bind_method(D_METHOD("get_allow_rmb_select"), &Tree::get_allow_rmb_select); - ClassDB::bind_method(D_METHOD("set_single_select_cell_editing_only_when_already_selected", "enable"), &Tree::set_single_select_cell_editing_only_when_already_selected); - ClassDB::bind_method(D_METHOD("get_single_select_cell_editing_only_when_already_selected"), &Tree::get_single_select_cell_editing_only_when_already_selected); + ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &Tree::set_allow_reselect); + ClassDB::bind_method(D_METHOD("get_allow_reselect"), &Tree::get_allow_reselect); ADD_SIGNAL(MethodInfo("item_selected")); ADD_SIGNAL(MethodInfo("cell_selected")); @@ -3659,13 +3629,13 @@ void Tree::_bind_methods() { ADD_SIGNAL(MethodInfo("item_activated")); ADD_SIGNAL(MethodInfo("column_title_pressed", PropertyInfo(Variant::INT, "column"))); - BIND_CONSTANT(SELECT_SINGLE); - BIND_CONSTANT(SELECT_ROW); - BIND_CONSTANT(SELECT_MULTI); + BIND_ENUM_CONSTANT(SELECT_SINGLE); + BIND_ENUM_CONSTANT(SELECT_ROW); + BIND_ENUM_CONSTANT(SELECT_MULTI); - BIND_CONSTANT(DROP_MODE_DISABLED); - BIND_CONSTANT(DROP_MODE_ON_ITEM); - BIND_CONSTANT(DROP_MODE_INBETWEEN); + BIND_ENUM_CONSTANT(DROP_MODE_DISABLED); + BIND_ENUM_CONSTANT(DROP_MODE_ON_ITEM); + BIND_ENUM_CONSTANT(DROP_MODE_INBETWEEN); } Tree::Tree() { @@ -3751,7 +3721,6 @@ Tree::Tree() { drop_mode_over = NULL; drop_mode_section = 0; single_select_defer = NULL; - force_select_on_already_selected = false; allow_rmb_select = false; force_edit_checkbox_only_on_checkbox = false; @@ -3760,6 +3729,8 @@ Tree::Tree() { cache.hover_item = NULL; cache.hover_cell = -1; + + allow_reselect = false; } Tree::~Tree() { diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 81880122a9..1fb1eb2792 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -172,7 +172,9 @@ protected: return d; } - void _remove_child(Object *p_child) { remove_child(p_child->cast_to<TreeItem>()); } + void _remove_child(Object *p_child) { + remove_child(Object::cast_to<TreeItem>(p_child)); + } public: /* cell mode */ @@ -490,7 +492,8 @@ private: bool allow_rmb_select; bool scrolling; - bool force_select_on_already_selected; + bool allow_reselect; + bool force_edit_checkbox_only_on_checkbox; bool hide_folding; @@ -503,9 +506,17 @@ protected: static void _bind_methods(); //bind helpers - Object *_create_item(Object *p_parent) { return create_item(p_parent->cast_to<TreeItem>()); } - TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>()); } - Rect2 _get_item_rect(Object *p_item, int p_column) const { return get_item_rect(p_item->cast_to<TreeItem>(), p_column); } + Object *_create_item(Object *p_parent) { + return create_item(Object::cast_to<TreeItem>(p_parent)); + } + + TreeItem *_get_next_selected(Object *p_item) { + return get_next_selected(Object::cast_to<TreeItem>(p_item)); + } + + Rect2 _get_item_rect(Object *p_item, int p_column) const { + return get_item_rect(Object::cast_to<TreeItem>(p_item), p_column); + } public: virtual String get_tooltip(const Point2 &p_pos) const; @@ -566,15 +577,15 @@ public: void set_drop_mode_flags(int p_flags); int get_drop_mode_flags() const; - void set_single_select_cell_editing_only_when_already_selected(bool p_enable); - bool get_single_select_cell_editing_only_when_already_selected() const; - void set_edit_checkbox_cell_only_when_checkbox_is_pressed(bool p_enable); bool get_edit_checkbox_cell_only_when_checkbox_is_pressed() const; void set_allow_rmb_select(bool p_allow); bool get_allow_rmb_select() const; + void set_allow_reselect(bool p_allow); + bool get_allow_reselect() const; + void set_value_evaluator(ValueEvaluator *p_evaluator); Tree(); @@ -582,4 +593,5 @@ public: }; VARIANT_ENUM_CAST(Tree::SelectMode); +VARIANT_ENUM_CAST(Tree::DropModeFlags); #endif diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index 9c018a4e7c..a92155cc4f 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,27 +28,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "video_player.h" + #include "os/os.h" #include "servers/audio_server.h" -/* - -int VideoPlayer::InternalStream::get_channel_count() const { - - return player->sp_get_channel_count(); -} -void VideoPlayer::InternalStream::set_mix_rate(int p_rate){ - - return player->sp_set_mix_rate(p_rate); -} -bool VideoPlayer::InternalStream::mix(int32_t *p_buffer,int p_frames){ - - return player->sp_mix(p_buffer,p_frames); -} -void VideoPlayer::InternalStream::update(){ - - player->sp_update(); -} -*/ int VideoPlayer::sp_get_channel_count() const { @@ -69,31 +51,6 @@ bool VideoPlayer::sp_mix(int32_t *p_buffer, int p_frames) { return false; } -void VideoPlayer::sp_update() { -#if 0 - _THREAD_SAFE_METHOD_ - //update is unused - if (!paused && playback.is_valid()) { - - if (!playback->is_playing()) { - //stream depleted data, but there's still audio in the ringbuffer - //check that all this audio has been flushed before stopping the stream - int to_mix = resampler.get_total() - resampler.get_todo(); - if (to_mix==0) { - stop(); - return; - } - - return; - } - - int todo =resampler.get_todo(); - int wrote = playback->mix(resampler.get_write_buffer(),todo); - resampler.write(wrote); - } -#endif -} - int VideoPlayer::_audio_mix_callback(void *p_udata, const int16_t *p_data, int p_frames) { VideoPlayer *vp = (VideoPlayer *)p_udata; @@ -116,7 +73,7 @@ void VideoPlayer::_notification(int p_notification) { case NOTIFICATION_ENTER_TREE: { - if (stream.is_valid() && autoplay && !get_tree()->is_editor_hint()) { + if (stream.is_valid() && autoplay && !Engine::get_singleton()->is_editor_hint()) { play(); } } break; @@ -399,7 +356,6 @@ VideoPlayer::VideoPlayer() { paused = false; autoplay = false; expand = true; - loops = false; audio_track = 0; diff --git a/scene/gui/video_player.h b/scene/gui/video_player.h index 87c452509b..b78f3aabe7 100644 --- a/scene/gui/video_player.h +++ b/scene/gui/video_player.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -38,23 +38,12 @@ class VideoPlayer : public Control { GDCLASS(VideoPlayer, Control); - /* struct InternalStream : public AudioServer::AudioStream { - VideoPlayer *player; - virtual int get_channel_count() const; - virtual void set_mix_rate(int p_rate); //notify the stream of the mix rate - virtual bool mix(int32_t *p_buffer,int p_frames); - virtual void update(); - }; -*/ - - // InternalStream internal_stream; Ref<VideoStreamPlayback> playback; Ref<VideoStream> stream; int sp_get_channel_count() const; void sp_set_mix_rate(int p_rate); //notify the stream of the mix rate bool sp_mix(int32_t *p_buffer, int p_frames); - void sp_update(); RID stream_rid; @@ -118,4 +107,4 @@ public: ~VideoPlayer(); }; -#endif +#endif // VIDEO_PLAYER_H diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp index dbc2699867..c321b873fd 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/viewport_container.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -38,7 +38,7 @@ Size2 ViewportContainer::get_minimum_size() const { Size2 ms; for (int i = 0; i < get_child_count(); i++) { - Viewport *c = get_child(i)->cast_to<Viewport>(); + Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; @@ -71,7 +71,7 @@ void ViewportContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = get_child(i)->cast_to<Viewport>(); + Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; @@ -83,7 +83,7 @@ void ViewportContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = get_child(i)->cast_to<Viewport>(); + Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; @@ -98,7 +98,7 @@ void ViewportContainer::_notification(int p_what) { for (int i = 0; i < get_child_count(); i++) { - Viewport *c = get_child(i)->cast_to<Viewport>(); + Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h index 27eb6ec81b..630523b5fb 100644 --- a/scene/gui/viewport_container.h +++ b/scene/gui/viewport_container.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ |