summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp2
-rw-r--r--scene/gui/button_array.cpp546
-rw-r--r--scene/gui/button_array.h131
-rw-r--r--scene/gui/color_picker.cpp106
-rw-r--r--scene/gui/color_picker.h1
-rw-r--r--scene/gui/container.cpp20
-rw-r--r--scene/gui/control.cpp133
-rw-r--r--scene/gui/control.h24
-rw-r--r--scene/gui/dialogs.cpp30
-rw-r--r--scene/gui/gradient_edit.cpp (renamed from scene/gui/color_ramp_edit.cpp)46
-rw-r--r--scene/gui/gradient_edit.h (renamed from scene/gui/color_ramp_edit.h)8
-rw-r--r--scene/gui/graph_edit.cpp46
-rw-r--r--scene/gui/graph_edit.h2
-rw-r--r--scene/gui/graph_node.cpp10
-rw-r--r--scene/gui/input_action.cpp2
-rw-r--r--scene/gui/item_list.cpp109
-rw-r--r--scene/gui/item_list.h3
-rw-r--r--scene/gui/label.cpp7
-rw-r--r--scene/gui/line_edit.cpp4
-rw-r--r--scene/gui/patch_9_rect.cpp36
-rw-r--r--scene/gui/patch_9_rect.h17
-rw-r--r--scene/gui/popup.cpp10
-rw-r--r--scene/gui/popup_menu.cpp37
-rw-r--r--scene/gui/popup_menu.h4
-rw-r--r--scene/gui/rich_text_label.cpp43
-rw-r--r--scene/gui/rich_text_label.h6
-rw-r--r--scene/gui/scroll_bar.cpp14
-rw-r--r--scene/gui/scroll_container.cpp4
-rw-r--r--scene/gui/slider.cpp26
-rw-r--r--scene/gui/slider.h4
-rw-r--r--scene/gui/spin_box.cpp6
-rw-r--r--scene/gui/split_container.cpp32
-rw-r--r--scene/gui/split_container.h2
-rw-r--r--scene/gui/tab_container.cpp4
-rw-r--r--scene/gui/tabs.cpp214
-rw-r--r--scene/gui/tabs.h12
-rw-r--r--scene/gui/text_edit.cpp32
-rw-r--r--scene/gui/tree.cpp307
-rw-r--r--scene/gui/tree.h35
39 files changed, 1023 insertions, 1052 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 318db8458b..c1dbc82f3c 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -162,7 +162,7 @@ void BaseButton::_gui_input(Ref<InputEvent> p_event) {
if (mm.is_valid()) {
if (status.press_attempt && status.pressing_button == 0) {
bool last_press_inside = status.pressing_inside;
- status.pressing_inside = has_point(mm->get_pos());
+ status.pressing_inside = has_point(mm->get_position());
if (last_press_inside != status.pressing_inside)
update();
}
diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp
deleted file mode 100644
index 0d518059c8..0000000000
--- a/scene/gui/button_array.cpp
+++ /dev/null
@@ -1,546 +0,0 @@
-/*************************************************************************/
-/* button_array.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "button_array.h"
-
-bool ButtonArray::_set(const StringName &p_name, const Variant &p_value) {
-
- String n = String(p_name);
- if (n.begins_with("button/")) {
-
- String what = n.get_slicec('/', 1);
- if (what == "count") {
- int new_size = p_value;
- if (new_size > 0 && buttons.size() == 0) {
- selected = 0;
- }
-
- if (new_size < buttons.size()) {
- if (selected >= new_size)
- selected = new_size - 1;
- }
- buttons.resize(new_size);
- _change_notify();
- minimum_size_changed();
- } else if (what == "align") {
- set_align(Align(p_value.operator int()));
- } else if (what == "selected") {
- set_selected(p_value);
- } else if (what == "min_button_size") {
- min_button_size = p_value;
- } else {
- int idx = what.to_int();
- ERR_FAIL_INDEX_V(idx, buttons.size(), false);
- String f = n.get_slicec('/', 2);
- if (f == "text") {
- buttons[idx].text = p_value;
- buttons[idx].xl_text = XL_MESSAGE(p_value);
- } else if (f == "tooltip")
- buttons[idx].tooltip = p_value;
- else if (f == "icon")
- buttons[idx].icon = p_value;
- else
- return false;
- }
-
- update();
- return true;
- }
-
- return false;
-}
-
-bool ButtonArray::_get(const StringName &p_name, Variant &r_ret) const {
-
- String n = String(p_name);
- if (n.begins_with("button/")) {
-
- String what = n.get_slicec('/', 1);
- if (what == "count") {
- r_ret = buttons.size();
- } else if (what == "align") {
- r_ret = get_align();
- } else if (what == "selected") {
- r_ret = get_selected();
- } else if (what == "min_button_size") {
- r_ret = min_button_size;
- } else {
- int idx = what.to_int();
- ERR_FAIL_INDEX_V(idx, buttons.size(), false);
- String f = n.get_slicec('/', 2);
- if (f == "text")
- r_ret = buttons[idx].text;
- else if (f == "tooltip")
- r_ret = buttons[idx].tooltip;
- else if (f == "icon")
- r_ret = buttons[idx].icon;
- else
- return false;
- }
-
- return true;
- }
-
- return false;
-}
-void ButtonArray::_get_property_list(List<PropertyInfo> *p_list) const {
-
- p_list->push_back(PropertyInfo(Variant::INT, "button/count", PROPERTY_HINT_RANGE, "0,512,1"));
- p_list->push_back(PropertyInfo(Variant::INT, "button/min_button_size", PROPERTY_HINT_RANGE, "0,1024,1"));
- p_list->push_back(PropertyInfo(Variant::INT, "button/align", PROPERTY_HINT_ENUM, "Begin,Center,End,Fill,Expand"));
- for (int i = 0; i < buttons.size(); i++) {
- String base = "button/" + itos(i) + "/";
- p_list->push_back(PropertyInfo(Variant::STRING, base + "text"));
- p_list->push_back(PropertyInfo(Variant::STRING, base + "tooltip"));
- p_list->push_back(PropertyInfo(Variant::OBJECT, base + "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"));
- }
- if (buttons.size() > 0) {
- p_list->push_back(PropertyInfo(Variant::INT, "button/selected", PROPERTY_HINT_RANGE, "0," + itos(buttons.size() - 1) + ",1"));
- }
-}
-
-Size2 ButtonArray::get_minimum_size() const {
-
- Ref<StyleBox> style_normal = get_stylebox("normal");
- Ref<StyleBox> style_selected = get_stylebox("selected");
- Ref<Font> font_normal = get_font("font");
- Ref<Font> font_selected = get_font("font_selected");
- int icon_sep = get_constant("icon_separator");
- int button_sep = get_constant("button_separator");
-
- Size2 minsize;
-
- for (int i = 0; i < buttons.size(); i++) {
-
- Ref<StyleBox> sb = i == selected ? style_selected : style_normal;
- Ref<Font> f = i == selected ? font_selected : font_normal;
-
- Size2 ms;
- ms = f->get_string_size(buttons[i].xl_text);
- if (buttons[i].icon.is_valid()) {
-
- Size2 bs = buttons[i].icon->get_size();
- ms.height = MAX(ms.height, bs.height);
- ms.width += bs.width + icon_sep;
- }
-
- ms += sb->get_minimum_size();
-
- buttons[i]._ms_cache = ms[orientation];
-
- minsize[orientation] += ms[orientation];
- if (i > 0)
- minsize[orientation] += button_sep;
- minsize[!orientation] = MAX(minsize[!orientation], ms[!orientation]);
- }
-
- return minsize;
-}
-
-void ButtonArray::_notification(int p_what) {
-
- switch (p_what) {
- case NOTIFICATION_MOUSE_EXIT: {
- hover = -1;
- update();
- } break;
- case NOTIFICATION_READY: {
- MethodInfo mi;
- mi.name = "mouse_sub_enter";
-
- add_user_signal(mi);
-
- } break;
- case NOTIFICATION_DRAW: {
-
- Size2 size = get_size();
- Size2 minsize = get_combined_minimum_size();
- Ref<StyleBox> style_normal = get_stylebox("normal");
- Ref<StyleBox> style_selected = get_stylebox("selected");
- Ref<StyleBox> style_focus = get_stylebox("focus");
- Ref<StyleBox> style_hover = get_stylebox("hover");
- Ref<Font> font_normal = get_font("font");
- Ref<Font> font_selected = get_font("font_selected");
- int icon_sep = get_constant("icon_separator");
- int button_sep = get_constant("button_separator");
- Color color_normal = get_color("font_color");
- Color color_selected = get_color("font_color_selected");
-
- int sep = button_sep;
- int ofs = 0;
- int expand = 0;
-
- switch (align) {
- case ALIGN_BEGIN: {
-
- ofs = 0;
- } break;
- case ALIGN_CENTER: {
-
- ofs = Math::floor((size[orientation] - minsize[orientation]) / 2);
- } break;
- case ALIGN_END: {
-
- ofs = Math::floor((size[orientation] - minsize[orientation]));
- } break;
- case ALIGN_FILL: {
-
- if (buttons.size() > 1)
- sep += Math::floor((size[orientation] - minsize[orientation]) / (buttons.size() - 1.0));
- ofs = 0;
- } break;
- case ALIGN_EXPAND_FILL: {
-
- ofs = 0;
- expand = size[orientation] - minsize[orientation];
- } break;
- }
-
- int op_size = orientation == VERTICAL ? size.width : size.height;
-
- for (int i = 0; i < buttons.size(); i++) {
-
- int ms = buttons[i]._ms_cache;
- int s = ms;
- if (expand > 0) {
- s += expand / buttons.size();
- }
- if (min_button_size != -1 && s < min_button_size) {
- s = min_button_size;
- }
-
- Rect2 r;
- r.pos[orientation] = ofs;
- r.pos[!orientation] = 0;
- r.size[orientation] = s;
- r.size[!orientation] = op_size;
-
- Ref<Font> f;
- Color c;
- Point2 sbsize;
- Point2 sbofs;
- if (i == selected) {
- draw_style_box(style_selected, r);
- sbsize = style_selected->get_minimum_size();
- sbofs = style_selected->get_offset();
- f = font_selected;
- c = color_selected;
- if (has_focus())
- draw_style_box(style_focus, r);
- } else {
- if (hover == i)
- draw_style_box(style_hover, r);
- else if (!flat)
- draw_style_box(style_normal, r);
- sbsize = style_normal->get_minimum_size();
- sbofs = style_normal->get_offset();
- f = font_normal;
- c = color_normal;
- }
-
- Size2 ssize = f->get_string_size(buttons[i].xl_text);
- if (buttons[i].icon.is_valid()) {
-
- ssize.x += buttons[i].icon->get_width();
- }
- Point2 text_ofs = ((r.size - ssize - sbsize) / 2.0 + Point2(0, f->get_ascent())).floor() + sbofs;
- if (buttons[i].icon.is_valid()) {
-
- draw_texture(buttons[i].icon, r.pos + Point2(text_ofs.x, Math::floor((r.size.height - buttons[i].icon->get_height()) / 2.0)));
- text_ofs.x += buttons[i].icon->get_width() + icon_sep;
- }
- draw_string(f, text_ofs + r.pos, buttons[i].xl_text, c);
- buttons[i]._pos_cache = ofs;
- buttons[i]._size_cache = s;
-
- ofs += s;
- ofs += sep;
- }
-
- } break;
- }
-}
-
-void ButtonArray::_gui_input(const Ref<InputEvent> &p_event) {
-
- if (
- ((orientation == HORIZONTAL && p_event->is_action("ui_left")) ||
- (orientation == VERTICAL && p_event->is_action("ui_up"))) &&
- p_event->is_pressed() && selected > 0) {
- set_selected(selected - 1);
- accept_event();
- emit_signal("button_selected", selected);
- return;
- }
-
- if (
- ((orientation == HORIZONTAL && p_event->is_action("ui_right")) ||
- (orientation == VERTICAL && p_event->is_action("ui_down"))) &&
- p_event->is_pressed() && selected < (buttons.size() - 1)) {
- set_selected(selected + 1);
- accept_event();
- emit_signal("button_selected", selected);
- return;
- }
-
- Ref<InputEventMouseButton> mb = p_event;
-
- if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
-
- int ofs = orientation == HORIZONTAL ? mb->get_pos().x : mb->get_pos().y;
-
- for (int i = 0; i < buttons.size(); i++) {
-
- if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache) {
-
- set_selected(i);
- emit_signal("button_selected", i);
- return;
- }
- }
- }
-
- Ref<InputEventMouseMotion> mm = p_event;
-
- if (mm.is_valid()) {
-
- int ofs = orientation == HORIZONTAL ? mm->get_pos().x : mm->get_pos().y;
- int new_hover = -1;
- for (int i = 0; i < buttons.size(); i++) {
-
- if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache) {
-
- new_hover = i;
- break;
- }
- }
-
- if (new_hover != hover) {
- hover = new_hover;
- emit_signal("mouse_sub_enter");
- update();
- }
- }
-}
-
-String ButtonArray::get_tooltip(const Point2 &p_pos) const {
-
- int ofs = orientation == HORIZONTAL ? p_pos.x : p_pos.y;
- for (int i = 0; i < buttons.size(); i++) {
-
- if (ofs >= buttons[i]._pos_cache && ofs < buttons[i]._pos_cache + buttons[i]._size_cache)
- return buttons[i].tooltip;
- }
- return Control::get_tooltip(p_pos);
-}
-
-void ButtonArray::set_align(Align p_align) {
-
- align = p_align;
- update();
-}
-
-ButtonArray::Align ButtonArray::get_align() const {
-
- return align;
-}
-
-void ButtonArray::set_flat(bool p_flat) {
-
- flat = p_flat;
- update();
-}
-
-bool ButtonArray::is_flat() const {
-
- return flat;
-}
-
-void ButtonArray::add_button(const String &p_text, const String &p_tooltip) {
-
- Button button;
- button.text = p_text;
- button.xl_text = XL_MESSAGE(p_text);
- button.tooltip = p_tooltip;
- buttons.push_back(button);
- update();
-
- if (selected == -1)
- selected = 0;
-
- minimum_size_changed();
-}
-
-void ButtonArray::add_icon_button(const Ref<Texture> &p_icon, const String &p_text, const String &p_tooltip) {
-
- Button button;
- button.text = p_text;
- button.xl_text = XL_MESSAGE(p_text);
- button.icon = p_icon;
- button.tooltip = p_tooltip;
- buttons.push_back(button);
- if (selected == -1)
- selected = 0;
-
- update();
-}
-
-void ButtonArray::set_button_text(int p_button, const String &p_text) {
-
- ERR_FAIL_INDEX(p_button, buttons.size());
- buttons[p_button].text = p_text;
- buttons[p_button].xl_text = XL_MESSAGE(p_text);
- update();
- minimum_size_changed();
-}
-
-void ButtonArray::set_button_tooltip(int p_button, const String &p_text) {
-
- ERR_FAIL_INDEX(p_button, buttons.size());
- buttons[p_button].tooltip = p_text;
-}
-
-void ButtonArray::set_button_icon(int p_button, const Ref<Texture> &p_icon) {
-
- ERR_FAIL_INDEX(p_button, buttons.size());
- buttons[p_button].icon = p_icon;
- update();
- minimum_size_changed();
-}
-
-String ButtonArray::get_button_text(int p_button) const {
-
- ERR_FAIL_INDEX_V(p_button, buttons.size(), "");
- return buttons[p_button].text;
-}
-
-String ButtonArray::get_button_tooltip(int p_button) const {
-
- ERR_FAIL_INDEX_V(p_button, buttons.size(), "");
- return buttons[p_button].tooltip;
-}
-
-Ref<Texture> ButtonArray::get_button_icon(int p_button) const {
-
- ERR_FAIL_INDEX_V(p_button, buttons.size(), Ref<Texture>());
- return buttons[p_button].icon;
-}
-
-int ButtonArray::get_selected() const {
-
- return selected;
-}
-
-int ButtonArray::get_hovered() const {
-
- return hover;
-}
-
-void ButtonArray::set_selected(int p_selected) {
-
- ERR_FAIL_INDEX(p_selected, buttons.size());
- selected = p_selected;
- update();
-}
-
-void ButtonArray::erase_button(int p_button) {
-
- ERR_FAIL_INDEX(p_button, buttons.size());
- buttons.remove(p_button);
- if (p_button >= selected)
- selected--;
- if (selected < 0)
- selected = 0;
- if (selected >= buttons.size())
- selected = buttons.size() - 1;
-
- update();
-}
-
-void ButtonArray::clear() {
-
- buttons.clear();
- selected = -1;
- update();
-}
-
-int ButtonArray::get_button_count() const {
-
- return buttons.size();
-}
-
-void ButtonArray::get_translatable_strings(List<String> *p_strings) const {
-
- for (int i = 0; i < buttons.size(); i++) {
- p_strings->push_back(buttons[i].text);
- p_strings->push_back(buttons[i].tooltip);
- }
-}
-
-void ButtonArray::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("add_button", "text", "tooltip"), &ButtonArray::add_button, DEFVAL(""));
- ClassDB::bind_method(D_METHOD("add_icon_button", "icon:Texture", "text", "tooltip"), &ButtonArray::add_icon_button, DEFVAL(""), DEFVAL(""));
- ClassDB::bind_method(D_METHOD("set_button_text", "button_idx", "text"), &ButtonArray::set_button_text);
- ClassDB::bind_method(D_METHOD("set_button_tooltip", "button_idx", "text"), &ButtonArray::set_button_tooltip);
- ClassDB::bind_method(D_METHOD("set_button_icon", "button_idx", "icon:Texture"), &ButtonArray::set_button_icon);
- ClassDB::bind_method(D_METHOD("get_button_text", "button_idx"), &ButtonArray::get_button_text);
- ClassDB::bind_method(D_METHOD("get_button_tooltip", "button_idx"), &ButtonArray::get_button_tooltip);
- ClassDB::bind_method(D_METHOD("get_button_icon:Texture", "button_idx"), &ButtonArray::get_button_icon);
- ClassDB::bind_method(D_METHOD("get_button_count"), &ButtonArray::get_button_count);
- ClassDB::bind_method(D_METHOD("set_flat", "enabled"), &ButtonArray::set_flat);
- ClassDB::bind_method(D_METHOD("is_flat"), &ButtonArray::is_flat);
- ClassDB::bind_method(D_METHOD("get_selected"), &ButtonArray::get_selected);
- ClassDB::bind_method(D_METHOD("get_hovered"), &ButtonArray::get_hovered);
- ClassDB::bind_method(D_METHOD("set_selected", "button_idx"), &ButtonArray::set_selected);
- ClassDB::bind_method(D_METHOD("erase_button", "button_idx"), &ButtonArray::erase_button);
- ClassDB::bind_method(D_METHOD("clear"), &ButtonArray::clear);
-
- ClassDB::bind_method(D_METHOD("_gui_input"), &ButtonArray::_gui_input);
-
- BIND_CONSTANT(ALIGN_BEGIN);
- BIND_CONSTANT(ALIGN_CENTER);
- BIND_CONSTANT(ALIGN_END);
- BIND_CONSTANT(ALIGN_FILL);
- BIND_CONSTANT(ALIGN_EXPAND_FILL);
-
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
-
- ADD_SIGNAL(MethodInfo("button_selected", PropertyInfo(Variant::INT, "button_idx")));
-}
-
-ButtonArray::ButtonArray(Orientation p_orientation) {
-
- orientation = p_orientation;
- selected = -1;
- set_focus_mode(FOCUS_ALL);
- hover = -1;
- flat = false;
- min_button_size = -1;
-}
diff --git a/scene/gui/button_array.h b/scene/gui/button_array.h
deleted file mode 100644
index 0ebf681cb6..0000000000
--- a/scene/gui/button_array.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/*************************************************************************/
-/* button_array.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef BUTTON_ARRAY_H
-#define BUTTON_ARRAY_H
-
-#include "scene/gui/control.h"
-
-class ButtonArray : public Control {
-
- GDCLASS(ButtonArray, Control);
-
-public:
- enum Align {
- ALIGN_BEGIN,
- ALIGN_CENTER,
- ALIGN_END,
- ALIGN_FILL,
- ALIGN_EXPAND_FILL
- };
-
-private:
- Orientation orientation;
- Align align;
-
- struct Button {
-
- String text;
- String xl_text;
- String tooltip;
- Ref<Texture> icon;
- mutable int _ms_cache;
- mutable int _pos_cache;
- mutable int _size_cache;
- };
-
- int selected;
- int hover;
- bool flat;
- double min_button_size;
-
- Vector<Button> buttons;
-
-protected:
- bool _set(const StringName &p_name, const Variant &p_value);
- bool _get(const StringName &p_name, Variant &r_ret) const;
- void _get_property_list(List<PropertyInfo> *p_list) const;
-
- void _notification(int p_what);
- static void _bind_methods();
-
-public:
- void _gui_input(const Ref<InputEvent> &p_event);
-
- void set_align(Align p_align);
- Align get_align() const;
-
- void set_flat(bool p_flat);
- bool is_flat() const;
-
- void add_button(const String &p_button, const String &p_tooltip = "");
- void add_icon_button(const Ref<Texture> &p_icon, const String &p_button = "", const String &p_tooltip = "");
-
- void set_button_text(int p_button, const String &p_text);
- void set_button_tooltip(int p_button, const String &p_text);
- void set_button_icon(int p_button, const Ref<Texture> &p_icon);
-
- String get_button_text(int p_button) const;
- String get_button_tooltip(int p_button) const;
- Ref<Texture> get_button_icon(int p_button) const;
-
- int get_selected() const;
- int get_hovered() const;
- void set_selected(int p_selected);
-
- int get_button_count() const;
-
- void erase_button(int p_button);
- void clear();
-
- virtual Size2 get_minimum_size() const;
-
- virtual void get_translatable_strings(List<String> *p_strings) const;
- virtual String get_tooltip(const Point2 &p_pos) const;
-
- ButtonArray(Orientation p_orientation = HORIZONTAL);
-};
-
-class HButtonArray : public ButtonArray {
- GDCLASS(HButtonArray, ButtonArray);
-
-public:
- HButtonArray()
- : ButtonArray(HORIZONTAL){};
-};
-
-class VButtonArray : public ButtonArray {
- GDCLASS(VButtonArray, ButtonArray);
-
-public:
- VButtonArray()
- : ButtonArray(VERTICAL){};
-};
-
-#endif // BUTTON_ARRAY_H
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 662ce63946..9ef340edbc 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -48,7 +48,15 @@ void ColorPicker::_notification(int p_what) {
btn_pick->set_icon(get_icon("screen_picker", "ColorPicker"));
_update_color();
- }
+ } break;
+
+ case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: {
+ if (screen != NULL) {
+ if (screen->is_visible()) {
+ screen->hide();
+ }
+ }
+ } break;
}
}
@@ -84,9 +92,6 @@ void ColorPicker::set_pick_color(const Color &p_color) {
if (!is_inside_tree())
return;
- return; //it crashes, so returning
- uv_edit->get_child(0)->cast_to<Control>()->update();
- w_edit->get_child(0)->cast_to<Control>()->update();
_update_color();
}
@@ -117,9 +122,6 @@ void ColorPicker::_value_changed(double) {
}
set_pick_color(color);
-
- _update_text_value();
-
emit_signal("color_changed", color);
}
@@ -156,6 +158,8 @@ void ColorPicker::_update_color() {
_update_text_value();
sample->update();
+ uv_edit->update();
+ w_edit->update();
updating = false;
}
@@ -250,7 +254,7 @@ void ColorPicker::_update_text_value() {
}
void ColorPicker::_sample_draw() {
- sample->draw_rect(Rect2(Point2(), Size2(256, 20)), color);
+ sample->draw_rect(Rect2(Point2(), Size2(uv_edit->get_size().width, 20)), color);
}
void ColorPicker::_hsv_draw(int p_wich, Control *c) {
@@ -263,23 +267,23 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) {
points.push_back(c->get_size());
points.push_back(Vector2(0, c->get_size().y));
Vector<Color> colors;
- colors.push_back(Color(1, 1, 1));
- colors.push_back(Color(1, 1, 1));
- colors.push_back(Color());
- colors.push_back(Color());
+ colors.push_back(Color(1, 1, 1, 1));
+ colors.push_back(Color(1, 1, 1, 1));
+ colors.push_back(Color(0, 0, 0, 1));
+ colors.push_back(Color(0, 0, 0, 1));
c->draw_polygon(points, colors);
Vector<Color> colors2;
Color col = color;
- col.set_hsv(color.get_h(), 1, 1);
+ col.set_hsv(h, 1, 1);
col.a = 0;
colors2.push_back(col);
col.a = 1;
colors2.push_back(col);
- col.set_hsv(color.get_h(), 1, 0);
+ col.set_hsv(h, 1, 0);
colors2.push_back(col);
col.a = 0;
colors2.push_back(col);
- c->draw_polygon(points, colors);
+ c->draw_polygon(points, colors2);
int x = CLAMP(c->get_size().x * s, 0, c->get_size().x);
int y = CLAMP(c->get_size().y - c->get_size().y * v, 0, c->get_size().y);
col = color;
@@ -290,7 +294,7 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) {
} else if (p_wich == 1) {
Ref<Texture> hue = get_icon("color_hue", "ColorPicker");
c->draw_texture_rect(hue, Rect2(Point2(), c->get_size()));
- int y = c->get_size().y - c->get_size().y * h;
+ int y = c->get_size().y - c->get_size().y * (1.0 - h);
Color col = Color();
col.set_hsv(h, 1, 1);
c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted());
@@ -304,10 +308,10 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &ev) {
if (bev.is_valid()) {
if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
changing_color = true;
- float x = CLAMP((float)bev->get_pos().x, 0, 256);
- float y = CLAMP((float)bev->get_pos().y, 0, 256);
- s = x / 256;
- v = 1.0 - y / 256.0;
+ float x = CLAMP((float)bev->get_position().x, 0, uv_edit->get_size().width);
+ float y = CLAMP((float)bev->get_position().y, 0, uv_edit->get_size().height);
+ s = x / uv_edit->get_size().width;
+ v = 1.0 - y / uv_edit->get_size().height;
color.set_hsv(h, s, v, color.a);
last_hsv = color;
set_pick_color(color);
@@ -323,10 +327,10 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &ev) {
if (mev.is_valid()) {
if (!changing_color)
return;
- float x = CLAMP((float)mev->get_pos().x, 0, 256);
- float y = CLAMP((float)mev->get_pos().y, 0, 256);
- s = x / 256;
- v = 1.0 - y / 256.0;
+ float x = CLAMP((float)mev->get_position().x, 0, uv_edit->get_size().width);
+ float y = CLAMP((float)mev->get_position().y, 0, uv_edit->get_size().height);
+ s = x / uv_edit->get_size().width;
+ v = 1.0 - y / uv_edit->get_size().height;
color.set_hsv(h, s, v, color.a);
last_hsv = color;
set_pick_color(color);
@@ -343,8 +347,8 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) {
if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
changing_color = true;
- h = 1 - ((float)bev->get_pos().y) / 256.0;
-
+ float y = CLAMP((float)bev->get_position().y, 0, w_edit->get_size().height);
+ h = y / w_edit->get_size().height;
} else {
changing_color = false;
}
@@ -361,8 +365,8 @@ void ColorPicker::_w_input(const Ref<InputEvent> &ev) {
if (!changing_color)
return;
- float y = CLAMP((float)mev->get_pos().y, 0, 256);
- h = 1.0 - y / 256.0;
+ float y = CLAMP((float)mev->get_position().y, 0, w_edit->get_size().height);
+ h = y / w_edit->get_size().height;
color.set_hsv(h, s, v, color.a);
last_hsv = color;
set_pick_color(color);
@@ -378,10 +382,10 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &ev) {
if (bev.is_valid()) {
if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
- int index = bev->get_pos().x / (preset->get_size().x / presets.size());
+ int index = bev->get_position().x / (preset->get_size().x / presets.size());
set_pick_color(presets[index]);
} else if (bev->is_pressed() && bev->get_button_index() == BUTTON_RIGHT) {
- int index = bev->get_pos().x / (preset->get_size().x / presets.size());
+ int index = bev->get_position().x / (preset->get_size().x / presets.size());
presets.erase(presets[index]);
_update_presets();
bt_add_preset->show();
@@ -394,7 +398,7 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &ev) {
if (mev.is_valid()) {
- int index = mev->get_pos().x * presets.size();
+ int index = mev->get_position().x * presets.size();
if (preset->get_size().x != 0) {
index /= preset->get_size().x;
}
@@ -422,21 +426,14 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &ev) {
if (mev.is_valid()) {
Viewport *r = get_tree()->get_root();
- if (!r->get_visible_rect().has_point(Point2(mev->get_global_pos().x, mev->get_global_pos().y)))
+ if (!r->get_visible_rect().has_point(Point2(mev->get_global_position().x, mev->get_global_position().y)))
return;
- Ref<Image> img = r->get_screen_capture();
- if (!img.is_null()) {
- last_capture = img;
- r->queue_screen_capture();
- }
- if (last_capture.is_valid() && !last_capture->empty()) {
- int pw = last_capture->get_format() == Image::FORMAT_RGBA8 ? 4 : 3;
- int ofs = (mev->get_global_pos().y * last_capture->get_width() + mev->get_global_pos().x) * pw;
-
- PoolVector<uint8_t>::Read r = last_capture->get_data().read();
-
- Color c(r[ofs + 0] / 255.0, r[ofs + 1] / 255.0, r[ofs + 2] / 255.0);
-
+ Ref<Image> img = r->get_texture()->get_data();
+ if (img.is_valid() && !img->empty()) {
+ img->lock();
+ Vector2 ofs = mev->get_global_position() - r->get_visible_rect().get_position();
+ Color c = img->get_pixel(ofs.x, r->get_visible_rect().size.height - ofs.y);
+ img->unlock();
set_pick_color(c);
}
}
@@ -453,11 +450,11 @@ void ColorPicker::_screen_pick_pressed() {
r->add_child(screen);
screen->set_as_toplevel(true);
screen->set_area_as_parent_rect();
+ screen->set_default_cursor_shape(CURSOR_POINTING_HAND);
screen->connect("gui_input", this, "_screen_input");
}
screen->raise();
screen->show_modal();
- r->queue_screen_capture();
}
void ColorPicker::_bind_methods() {
@@ -507,12 +504,14 @@ ColorPicker::ColorPicker()
add_child(hb_smpl);
HBoxContainer *hb_edit = memnew(HBoxContainer);
+ hb_edit->set_v_size_flags(SIZE_EXPAND_FILL);
uv_edit = memnew(Control);
uv_edit->connect("gui_input", this, "_uv_input");
uv_edit->set_mouse_filter(MOUSE_FILTER_PASS);
- uv_edit->set_custom_minimum_size(Size2(256, 256));
+ uv_edit->set_h_size_flags(SIZE_EXPAND_FILL);
+ uv_edit->set_v_size_flags(SIZE_EXPAND_FILL);
Vector<Variant> args = Vector<Variant>();
args.push_back(0);
args.push_back(uv_edit);
@@ -522,7 +521,9 @@ ColorPicker::ColorPicker()
w_edit = memnew(Control);
//w_edit->set_ignore_mouse(false);
- w_edit->set_custom_minimum_size(Size2(30, 256));
+ w_edit->set_custom_minimum_size(Size2(30, 0));
+ w_edit->set_h_size_flags(SIZE_FILL);
+ w_edit->set_v_size_flags(SIZE_EXPAND_FILL);
w_edit->connect("gui_input", this, "_w_input");
args.clear();
args.push_back(1);
@@ -548,6 +549,7 @@ ColorPicker::ColorPicker()
HBoxContainer *hbc = memnew(HBoxContainer);
labels[i] = memnew(Label(lt[i]));
+ labels[i]->set_custom_minimum_size(Size2(10, 0));
hbc->add_child(labels[i]);
scroll[i] = memnew(HSlider);
@@ -569,7 +571,7 @@ ColorPicker::ColorPicker()
HBoxContainer *hhb = memnew(HBoxContainer);
btn_mode = memnew(CheckButton);
- btn_mode->set_text("RAW Mode");
+ btn_mode->set_text(TTR("RAW Mode"));
btn_mode->connect("toggled", this, "set_raw_mode");
hhb->add_child(btn_mode);
vbr->add_child(hhb);
@@ -600,7 +602,7 @@ ColorPicker::ColorPicker()
bt_add_preset = memnew(Button);
bt_add_preset->set_icon(get_icon("add_preset"));
- bt_add_preset->set_tooltip("Add current color as a preset");
+ bt_add_preset->set_tooltip(TTR("Add current color as a preset"));
bt_add_preset->connect("pressed", this, "_add_preset_pressed");
bbc->add_child(bt_add_preset);
}
@@ -629,6 +631,10 @@ void ColorPickerButton::_notification(int p_what) {
Ref<StyleBox> normal = get_stylebox("normal");
draw_rect(Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()), picker->get_pick_color());
}
+
+ if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST) {
+ popup->hide();
+ }
}
void ColorPickerButton::set_pick_color(const Color &p_color) {
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index ca47c3a5f4..de624fd029 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -47,7 +47,6 @@ class ColorPicker : public BoxContainer {
private:
Control *screen;
- Ref<Image> last_capture;
Control *uv_edit;
Control *w_edit;
TextureRect *sample;
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index c428d524a4..2a96f8260c 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -95,19 +95,31 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
Rect2 r = p_rect;
if (!(p_child->get_h_size_flags() & SIZE_FILL)) {
- r.size.x = minsize.x;
- r.pos.x += Math::floor((p_rect.size.x - minsize.x) / 2);
+ r.size.x = minsize.width;
+ if (p_child->get_h_size_flags() & SIZE_SHRINK_END) {
+ r.position.x += p_rect.size.width - minsize.width;
+ } else if (p_child->get_h_size_flags() & SIZE_SHRINK_CENTER) {
+ r.position.x += Math::floor((p_rect.size.x - minsize.width) / 2);
+ } else {
+ r.position.x += 0;
+ }
}
if (!(p_child->get_v_size_flags() & SIZE_FILL)) {
r.size.y = minsize.y;
- r.pos.y += Math::floor((p_rect.size.y - minsize.y) / 2);
+ if (p_child->get_v_size_flags() & SIZE_SHRINK_END) {
+ r.position.y += p_rect.size.height - minsize.height;
+ } else if (p_child->get_v_size_flags() & SIZE_SHRINK_CENTER) {
+ r.position.y += Math::floor((p_rect.size.y - minsize.height) / 2);
+ } else {
+ r.position.y += 0;
+ }
}
for (int i = 0; i < 4; i++)
p_child->set_anchor(Margin(i), ANCHOR_BEGIN);
- p_child->set_position(r.pos);
+ p_child->set_position(r.position);
p_child->set_size(r.size);
p_child->set_rotation(0);
p_child->set_scale(Vector2(1, 1));
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 83fa20bee5..e9e299ffc5 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -58,7 +58,7 @@ void Control::edit_set_state(const Variant &p_state) {
Dictionary s = p_state;
Rect2 state = s["rect"];
- set_position(state.pos);
+ set_position(state.position);
set_size(state.size);
set_rotation(s["rot"]);
set_scale(s["scale"]);
@@ -90,19 +90,30 @@ Size2 Control::edit_get_minimum_size() const {
return get_combined_minimum_size();
}
+Transform2D Control::_get_internal_transform() const {
+
+ Transform2D rot_scale;
+ rot_scale.set_rotation_and_scale(data.rotation, data.scale);
+ Transform2D offset;
+ offset.set_origin(-data.pivot_offset);
+
+ return offset.affine_inverse() * (rot_scale * offset);
+}
void Control::edit_set_rect(const Rect2 &p_edit_rect) {
- Transform2D postxf;
- postxf.set_rotation_and_scale(data.rotation, data.scale);
- Vector2 new_pos = postxf.xform(p_edit_rect.pos);
+ Transform2D xform = _get_internal_transform();
+
+ // xform[2] += get_position();
+
+ Vector2 new_pos = xform.basis_xform(p_edit_rect.position);
Vector2 pos = get_position() + new_pos;
Rect2 new_rect = get_rect();
- new_rect.pos = pos.snapped(Vector2(1, 1));
+ new_rect.position = pos.snapped(Vector2(1, 1));
new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1));
- set_position(new_rect.pos);
+ set_position(new_rect.position);
set_size(new_rect.size);
}
@@ -353,8 +364,9 @@ void Control::remove_child_notify(Node *p_child) {
void Control::_update_canvas_item_transform() {
- Transform2D xform = Transform2D(data.rotation, get_position());
- xform.scale_basis(data.scale);
+ Transform2D xform = _get_internal_transform();
+ xform[2] += get_position();
+
VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
}
@@ -1184,6 +1196,7 @@ Size2 Control::get_parent_area_size() const {
parent_size = get_viewport()->get_visible_rect().size;
}
+
return parent_size;
}
@@ -1216,12 +1229,28 @@ void Control::_size_changed() {
}
}
- Point2 new_pos_cache = Point2(margin_pos[0], margin_pos[1]).floor();
- Size2 new_size_cache = Point2(margin_pos[2], margin_pos[3]).floor() - new_pos_cache;
+ Point2 new_pos_cache = Point2(margin_pos[0], margin_pos[1]);
+ Size2 new_size_cache = Point2(margin_pos[2], margin_pos[3]) - new_pos_cache;
+
Size2 minimum_size = get_combined_minimum_size();
- new_size_cache.x = MAX(minimum_size.x, new_size_cache.x);
- new_size_cache.y = MAX(minimum_size.y, new_size_cache.y);
+ if (data.h_grow == GROW_DIRECTION_BEGIN) {
+ if (minimum_size.width > new_size_cache.width) {
+ new_pos_cache.x = new_pos_cache.x + new_size_cache.width - minimum_size.width;
+ new_size_cache.width = minimum_size.width;
+ }
+ } else {
+ new_size_cache.width = MAX(minimum_size.width, new_size_cache.width);
+ }
+
+ if (data.v_grow == GROW_DIRECTION_BEGIN) {
+ if (minimum_size.height > new_size_cache.height) {
+ new_pos_cache.y = new_pos_cache.y + new_size_cache.height - minimum_size.height;
+ new_size_cache.height = minimum_size.height;
+ }
+ } else {
+ new_size_cache.height = MAX(minimum_size.height, new_size_cache.height);
+ }
bool pos_changed = new_pos_cache != data.pos_cache;
bool size_changed = new_size_cache != data.size_cache;
@@ -1477,7 +1506,7 @@ Rect2 Control::get_global_rect() const {
Rect2 Control::get_window_rect() const {
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
Rect2 gr = get_global_rect();
- gr.pos += get_viewport()->get_visible_rect().pos;
+ gr.position += get_viewport()->get_visible_rect().position;
return gr;
}
@@ -1886,8 +1915,8 @@ Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
Transform2D Control::get_transform() const {
- Transform2D xform = Transform2D(data.rotation, get_position());
- xform.scale_basis(data.scale);
+ Transform2D xform = _get_internal_transform();
+ xform[2] += get_position();
return xform;
}
@@ -1949,10 +1978,10 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
Transform2D xform = get_global_transform();
Rect2 rect = get_item_rect();
- points[0] = xform.xform(rect.pos);
- points[1] = xform.xform(rect.pos + Point2(rect.size.x, 0));
- points[2] = xform.xform(rect.pos + rect.size);
- points[3] = xform.xform(rect.pos + Point2(0, rect.size.y));
+ points[0] = xform.xform(rect.position);
+ points[1] = xform.xform(rect.position + Point2(rect.size.x, 0));
+ points[2] = xform.xform(rect.position + rect.size);
+ points[3] = xform.xform(rect.position + Point2(0, rect.size.y));
const Vector2 dir[4] = {
Vector2(-1, 0),
@@ -2008,10 +2037,10 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
Transform2D xform = c->get_global_transform();
Rect2 rect = c->get_item_rect();
- points[0] = xform.xform(rect.pos);
- points[1] = xform.xform(rect.pos + Point2(rect.size.x, 0));
- points[2] = xform.xform(rect.pos + rect.size);
- points[3] = xform.xform(rect.pos + Point2(0, rect.size.y));
+ points[0] = xform.xform(rect.position);
+ points[1] = xform.xform(rect.position + Point2(rect.size.x, 0));
+ points[2] = xform.xform(rect.position + rect.size);
+ points[3] = xform.xform(rect.position + Point2(0, rect.size.y));
float min = 1e7;
@@ -2213,6 +2242,19 @@ void Control::_font_changed() {
minimum_size_changed(); //fonts affect minimum size pretty much almost always
}
+void Control::set_pivot_offset(const Vector2 &p_pivot) {
+
+ data.pivot_offset = p_pivot;
+ update();
+ _notify_transform();
+ _change_notify("rect_pivot_offset");
+}
+
+Vector2 Control::get_pivot_offset() const {
+
+ return data.pivot_offset;
+}
+
void Control::set_scale(const Vector2 &p_scale) {
data.scale = p_scale;
@@ -2299,6 +2341,27 @@ bool Control::is_clipping_contents() {
return data.clip_contents;
}
+void Control::set_h_grow_direction(GrowDirection p_direction) {
+
+ data.h_grow = p_direction;
+ _size_changed();
+}
+
+Control::GrowDirection Control::get_h_grow_direction() const {
+
+ return data.h_grow;
+}
+
+void Control::set_v_grow_direction(GrowDirection p_direction) {
+
+ data.v_grow = p_direction;
+ _size_changed();
+}
+Control::GrowDirection Control::get_v_grow_direction() const {
+
+ return data.v_grow;
+}
+
void Control::_bind_methods() {
//ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
@@ -2324,6 +2387,7 @@ void Control::_bind_methods() {
// TODO: Obsolete this method (old name) properly (GH-4397)
ClassDB::bind_method(D_METHOD("_set_rotation_deg", "degrees"), &Control::_set_rotation_deg);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
+ ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset);
ClassDB::bind_method(D_METHOD("get_margin", "margin"), &Control::get_margin);
ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin);
ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end);
@@ -2334,6 +2398,7 @@ void Control::_bind_methods() {
// TODO: Obsolete this method (old name) properly (GH-4397)
ClassDB::bind_method(D_METHOD("_get_rotation_deg"), &Control::_get_rotation_deg);
ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
+ ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset);
ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size);
ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_size);
ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position);
@@ -2387,6 +2452,12 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_parent_control:Control"), &Control::get_parent_control);
+ ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction);
+ ClassDB::bind_method(D_METHOD("get_h_grow_direction"), &Control::get_h_grow_direction);
+
+ ClassDB::bind_method(D_METHOD("set_v_grow_direction", "direction"), &Control::set_v_grow_direction);
+ ClassDB::bind_method(D_METHOD("get_v_grow_direction"), &Control::get_v_grow_direction);
+
ClassDB::bind_method(D_METHOD("set_tooltip", "tooltip"), &Control::set_tooltip);
ClassDB::bind_method(D_METHOD("get_tooltip", "atpos"), &Control::get_tooltip, DEFVAL(Point2()));
ClassDB::bind_method(D_METHOD("_get_tooltip"), &Control::_get_tooltip);
@@ -2437,12 +2508,17 @@ void Control::_bind_methods() {
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_RIGHT);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_BOTTOM);
+ ADD_GROUP("Grow Direction", "grow_");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Begin,End"), "set_h_grow_direction", "get_h_grow_direction");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Begin,End"), "set_v_grow_direction", "get_v_grow_direction");
+
ADD_GROUP("Rect", "rect_");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_deg", "get_rotation_deg");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
+ ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
ADD_GROUP("Hint", "hint_");
@@ -2458,8 +2534,8 @@ void Control::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
ADD_GROUP("Size Flags", "size_flags_");
- ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_h_size_flags", "get_h_size_flags");
- ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_v_size_flags", "get_v_size_flags");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "1,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
@@ -2501,11 +2577,16 @@ void Control::_bind_methods() {
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);
+
ADD_SIGNAL(MethodInfo("resized"));
ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
@@ -2542,6 +2623,8 @@ Control::Control() {
data.modal_frame = 0;
data.block_minimum_size_adjust = false;
data.disable_visibility_clip = false;
+ data.h_grow = GROW_DIRECTION_END;
+ data.v_grow = GROW_DIRECTION_END;
data.clip_contents = false;
for (int i = 0; i < 4; i++) {
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 5834d1550a..86cf8f6dbd 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -57,6 +57,11 @@ public:
ANCHOR_CENTER,
};
+ enum GrowDirection {
+ GROW_DIRECTION_BEGIN,
+ GROW_DIRECTION_END
+ };
+
enum FocusMode {
FOCUS_NONE,
FOCUS_CLICK,
@@ -67,7 +72,9 @@ public:
SIZE_FILL = 1,
SIZE_EXPAND = 2,
- SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL
+ SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,
+ SIZE_SHRINK_CENTER = 4, //ignored by expand or fill
+ SIZE_SHRINK_END = 8, //ignored by expand or fil
};
@@ -117,9 +124,12 @@ private:
float margin[4];
AnchorType anchor[4];
FocusMode focus_mode;
+ GrowDirection h_grow;
+ GrowDirection v_grow;
float rotation;
Vector2 scale;
+ Vector2 pivot_offset;
bool pending_resize;
@@ -200,6 +210,8 @@ private:
void _update_canvas_item_transform();
+ Transform2D _get_internal_transform() const;
+
friend class Viewport;
void _modal_stack_remove();
void _modal_set_prev_focus_owner(ObjectID p_prev);
@@ -273,6 +285,12 @@ public:
void set_begin(const Point2 &p_point); // helper
void set_end(const Point2 &p_point); // helper
+ void set_h_grow_direction(GrowDirection p_direction);
+ GrowDirection get_h_grow_direction() const;
+
+ void set_v_grow_direction(GrowDirection p_direction);
+ GrowDirection get_v_grow_direction() const;
+
float get_margin(Margin p_margin) const;
Point2 get_begin() const;
Point2 get_end() const;
@@ -293,6 +311,9 @@ public:
float get_rotation() const;
float get_rotation_deg() const;
+ void set_pivot_offset(const Vector2 &p_pivot);
+ Vector2 get_pivot_offset() const;
+
void set_scale(const Vector2 &p_scale);
Vector2 get_scale() const;
@@ -409,5 +430,6 @@ VARIANT_ENUM_CAST(Control::FocusMode);
VARIANT_ENUM_CAST(Control::SizeFlags);
VARIANT_ENUM_CAST(Control::CursorShape);
VARIANT_ENUM_CAST(Control::MouseFilter);
+VARIANT_ENUM_CAST(Control::GrowDirection);
#endif
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 627bc96fb1..60d1350405 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -90,15 +90,15 @@ bool WindowDialog::has_point(const Point2 &p_point) const {
// Enlarge upwards for title bar.
int title_height = get_constant("title_height", "WindowDialog");
- r.pos.y -= title_height;
+ r.position.y -= title_height;
r.size.y += title_height;
// Inflate by the resizable border thickness.
if (resizable) {
int scaleborder_size = get_constant("scaleborder_size", "WindowDialog");
- r.pos.x -= scaleborder_size;
+ r.position.x -= scaleborder_size;
r.size.width += scaleborder_size * 2;
- r.pos.y -= scaleborder_size;
+ r.position.y -= scaleborder_size;
r.size.height += scaleborder_size * 2;
}
@@ -113,7 +113,7 @@ void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) {
if (mb->is_pressed()) {
// Begin a possible dragging operation.
- drag_type = _drag_hit_test(Point2(mb->get_pos().x, mb->get_pos().y));
+ drag_type = _drag_hit_test(Point2(mb->get_position().x, mb->get_position().y));
if (drag_type != DRAG_NONE)
drag_offset = get_global_mouse_position() - get_position();
drag_offset_far = get_position() + get_size() - get_global_mouse_position();
@@ -131,7 +131,7 @@ void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) {
// Update the cursor while moving along the borders.
CursorShape cursor = CURSOR_ARROW;
if (resizable) {
- int preview_drag_type = _drag_hit_test(Point2(mm->get_pos().x, mm->get_pos().y));
+ int preview_drag_type = _drag_hit_test(Point2(mm->get_position().x, mm->get_position().y));
switch (preview_drag_type) {
case DRAG_RESIZE_TOP:
case DRAG_RESIZE_BOTTOM:
@@ -162,28 +162,28 @@ void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) {
Size2 min_size = get_minimum_size();
if (drag_type == DRAG_MOVE) {
- rect.pos = global_pos - drag_offset;
+ rect.position = global_pos - drag_offset;
} else {
if (drag_type & DRAG_RESIZE_TOP) {
- int bottom = rect.pos.y + rect.size.height;
+ int bottom = rect.position.y + rect.size.height;
int max_y = bottom - min_size.height;
- rect.pos.y = MIN(global_pos.y - drag_offset.y, max_y);
- rect.size.height = bottom - rect.pos.y;
+ rect.position.y = MIN(global_pos.y - drag_offset.y, max_y);
+ rect.size.height = bottom - rect.position.y;
} else if (drag_type & DRAG_RESIZE_BOTTOM) {
- rect.size.height = global_pos.y - rect.pos.y + drag_offset_far.y;
+ rect.size.height = global_pos.y - rect.position.y + drag_offset_far.y;
}
if (drag_type & DRAG_RESIZE_LEFT) {
- int right = rect.pos.x + rect.size.width;
+ int right = rect.position.x + rect.size.width;
int max_x = right - min_size.width;
- rect.pos.x = MIN(global_pos.x - drag_offset.x, max_x);
- rect.size.width = right - rect.pos.x;
+ rect.position.x = MIN(global_pos.x - drag_offset.x, max_x);
+ rect.size.width = right - rect.position.x;
} else if (drag_type & DRAG_RESIZE_RIGHT) {
- rect.size.width = global_pos.x - rect.pos.x + drag_offset_far.x;
+ rect.size.width = global_pos.x - rect.position.x + drag_offset_far.x;
}
}
set_size(rect.size);
- set_position(rect.pos);
+ set_position(rect.position);
}
}
}
diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/gradient_edit.cpp
index 8c47f8559a..58bce57580 100644
--- a/scene/gui/color_ramp_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -27,10 +27,10 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "color_ramp_edit.h"
+#include "gradient_edit.h"
#include "os/keyboard.h"
-ColorRampEdit::ColorRampEdit() {
+GradientEdit::GradientEdit() {
grabbed = -1;
grabbing = false;
set_focus_mode(FOCUS_ALL);
@@ -46,7 +46,7 @@ ColorRampEdit::ColorRampEdit() {
checker->create_from_image(img, ImageTexture::FLAG_REPEAT);
}
-int ColorRampEdit::_get_point_from_pos(int x) {
+int GradientEdit::_get_point_from_pos(int x) {
int result = -1;
int total_w = get_size().width - get_size().height - 3;
for (int i = 0; i < points.size(); i++) {
@@ -58,7 +58,7 @@ int ColorRampEdit::_get_point_from_pos(int x) {
return result;
}
-void ColorRampEdit::_show_color_picker() {
+void GradientEdit::_show_color_picker() {
if (grabbed == -1)
return;
Size2 ms = Size2(350, picker->get_combined_minimum_size().height + 10);
@@ -68,10 +68,10 @@ void ColorRampEdit::_show_color_picker() {
popup->popup();
}
-ColorRampEdit::~ColorRampEdit() {
+GradientEdit::~GradientEdit() {
}
-void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
+void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
@@ -88,14 +88,14 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
//Show color picker on double click.
if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_doubleclick() && mb->is_pressed()) {
- grabbed = _get_point_from_pos(mb->get_pos().x);
+ grabbed = _get_point_from_pos(mb->get_position().x);
_show_color_picker();
accept_event();
}
//Delete point on right click
if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
- grabbed = _get_point_from_pos(mb->get_pos().x);
+ grabbed = _get_point_from_pos(mb->get_position().x);
if (grabbed != -1) {
points.remove(grabbed);
grabbed = -1;
@@ -109,7 +109,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
//Hold alt key to duplicate selected color
if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) {
- int x = mb->get_pos().x;
+ int x = mb->get_position().x;
grabbed = _get_point_from_pos(x);
if (grabbed != -1) {
@@ -134,7 +134,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
update();
- int x = mb->get_pos().x;
+ int x = mb->get_position().x;
int total_w = get_size().width - get_size().height - 3;
//Check if color selector was clicked.
@@ -214,7 +214,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
int total_w = get_size().width - get_size().height - 3;
- int x = mm->get_pos().x;
+ int x = mm->get_position().x;
float newofs = CLAMP(x / float(total_w), 0, 1);
@@ -272,7 +272,7 @@ void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
}
}
-void ColorRampEdit::_notification(int p_what) {
+void GradientEdit::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
if (!picker->is_connected("color_changed", this, "_color_changed")) {
@@ -370,7 +370,7 @@ void ColorRampEdit::_notification(int p_what) {
}
}
-void ColorRampEdit::_draw_checker(int x, int y, int w, int h) {
+void GradientEdit::_draw_checker(int x, int y, int w, int h) {
//Draw it with polygon to insert UVs for scale
Vector<Vector2> backPoints;
backPoints.push_back(Vector2(x, y));
@@ -391,12 +391,12 @@ void ColorRampEdit::_draw_checker(int x, int y, int w, int h) {
draw_polygon(backPoints, colorPoints, uvPoints, checker);
}
-Size2 ColorRampEdit::get_minimum_size() const {
+Size2 GradientEdit::get_minimum_size() const {
return Vector2(0, 16);
}
-void ColorRampEdit::_color_changed(const Color &p_color) {
+void GradientEdit::_color_changed(const Color &p_color) {
if (grabbed == -1)
return;
@@ -405,7 +405,7 @@ void ColorRampEdit::_color_changed(const Color &p_color) {
emit_signal("ramp_changed");
}
-void ColorRampEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) {
+void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) {
ERR_FAIL_COND(p_offsets.size() != p_colors.size());
points.clear();
@@ -420,33 +420,33 @@ void ColorRampEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color>
update();
}
-Vector<float> ColorRampEdit::get_offsets() const {
+Vector<float> GradientEdit::get_offsets() const {
Vector<float> ret;
for (int i = 0; i < points.size(); i++)
ret.push_back(points[i].offset);
return ret;
}
-Vector<Color> ColorRampEdit::get_colors() const {
+Vector<Color> GradientEdit::get_colors() const {
Vector<Color> ret;
for (int i = 0; i < points.size(); i++)
ret.push_back(points[i].color);
return ret;
}
-void ColorRampEdit::set_points(Vector<Gradient::Point> &p_points) {
+void GradientEdit::set_points(Vector<Gradient::Point> &p_points) {
if (points.size() != p_points.size())
grabbed = -1;
points.clear();
points = p_points;
}
-Vector<Gradient::Point> &ColorRampEdit::get_points() {
+Vector<Gradient::Point> &GradientEdit::get_points() {
return points;
}
-void ColorRampEdit::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &ColorRampEdit::_gui_input);
- ClassDB::bind_method(D_METHOD("_color_changed"), &ColorRampEdit::_color_changed);
+void GradientEdit::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("_gui_input"), &GradientEdit::_gui_input);
+ ClassDB::bind_method(D_METHOD("_color_changed"), &GradientEdit::_color_changed);
ADD_SIGNAL(MethodInfo("ramp_changed"));
}
diff --git a/scene/gui/color_ramp_edit.h b/scene/gui/gradient_edit.h
index 0fe447c43a..6c4ae6fd15 100644
--- a/scene/gui/color_ramp_edit.h
+++ b/scene/gui/gradient_edit.h
@@ -37,9 +37,9 @@
#define POINT_WIDTH 8
-class ColorRampEdit : public Control {
+class GradientEdit : public Control {
- GDCLASS(ColorRampEdit, Control);
+ GDCLASS(GradientEdit, Control);
PopupPanel *popup;
ColorPicker *picker;
@@ -68,8 +68,8 @@ public:
Vector<Gradient::Point> &get_points();
virtual Size2 get_minimum_size() const;
- ColorRampEdit();
- virtual ~ColorRampEdit();
+ GradientEdit();
+ virtual ~GradientEdit();
};
/*class ColorRampEditPanel : public Panel
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index c52cdd9325..9d45b6e70a 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -168,24 +168,24 @@ void GraphEdit::_update_scroll() {
continue;
Rect2 r;
- r.pos = gn->get_offset() * zoom;
+ r.position = gn->get_offset() * zoom;
r.size = gn->get_size() * zoom;
screen = screen.merge(r);
}
- screen.pos -= get_size();
+ screen.position -= get_size();
screen.size += get_size() * 2.0;
- h_scroll->set_min(screen.pos.x);
- h_scroll->set_max(screen.pos.x + screen.size.x);
+ h_scroll->set_min(screen.position.x);
+ h_scroll->set_max(screen.position.x + screen.size.x);
h_scroll->set_page(get_size().x);
if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page())
h_scroll->hide();
else
h_scroll->show();
- v_scroll->set_min(screen.pos.y);
- v_scroll->set_max(screen.pos.y + screen.size.y);
+ v_scroll->set_min(screen.position.y);
+ v_scroll->set_max(screen.position.y + screen.size.y);
v_scroll->set_page(get_size().y);
if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page())
@@ -374,7 +374,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
Ref<Texture> port = get_icon("port", "GraphNode");
- Vector2 mpos(mb->get_pos().x, mb->get_pos().y);
+ Vector2 mpos(mb->get_position().x, mb->get_position().y);
float grab_r = port->get_width() * 0.5 * grab_r_extend;
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -483,12 +483,12 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseMotion> mm = p_ev;
if (mm.is_valid() && connecting) {
- connecting_to = mm->get_pos();
+ connecting_to = mm->get_position();
connecting_target = false;
top_layer->update();
Ref<Texture> port = get_icon("port", "GraphNode");
- Vector2 mpos = mm->get_pos();
+ Vector2 mpos = mm->get_position();
float grab_r = port->get_width() * 0.5 * grab_r_extend;
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -546,7 +546,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
} else if (!just_disconected) {
String from = connecting_from;
int from_slot = connecting_index;
- Vector2 ofs = Vector2(mb->get_pos().x, mb->get_pos().y);
+ Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y);
emit_signal("connection_to_empty", from, from_slot, ofs);
}
connecting = false;
@@ -568,7 +568,7 @@ static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, Vector2 start, Vector2 co
return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
}
-void GraphEdit::_bake_segment2d(CanvasItem *p_where, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
+void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
float mp = p_begin + (p_end - p_begin) * 0.5;
Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
@@ -581,11 +581,12 @@ void GraphEdit::_bake_segment2d(CanvasItem *p_where, float p_begin, float p_end,
if (p_depth >= p_min_depth && (dp < p_tol || p_depth >= p_max_depth)) {
- p_where->draw_line(beg, end, p_color.linear_interpolate(p_to_color, mp), 2, true);
+ points.push_back((beg + end) * 0.5);
+ colors.push_back(p_color.linear_interpolate(p_to_color, mp));
lines++;
} else {
- _bake_segment2d(p_where, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
- _bake_segment2d(p_where, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
+ _bake_segment2d(points, colors, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
+ _bake_segment2d(points, colors, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
}
}
@@ -609,7 +610,16 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const
Vector2 c2 = Vector2(-cp_offset * zoom, 0);
int lines = 0;
- _bake_segment2d(p_where, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 8, p_color, p_to_color, lines);
+
+ Vector<Point2> points;
+ Vector<Color> colors;
+ points.push_back(p_from);
+ colors.push_back(p_color);
+ _bake_segment2d(points, colors, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 8, p_color, p_to_color, lines);
+ points.push_back(p_to);
+ colors.push_back(p_to_color);
+
+ p_where->draw_polyline_colors(points, colors, 2, true);
#else
@@ -817,7 +827,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
connecting = false;
top_layer->update();
} else {
- emit_signal("popup_request", b->get_global_pos());
+ emit_signal("popup_request", b->get_global_position());
}
}
}
@@ -880,7 +890,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
if (gn) {
- if (_filter_input(b->get_pos()))
+ if (_filter_input(b->get_position()))
return;
dragging = true;
@@ -905,7 +915,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
} else {
- if (_filter_input(b->get_pos()))
+ if (_filter_input(b->get_position()))
return;
if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
return;
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 22d053d312..e908829d5f 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -110,7 +110,7 @@ private:
bool awaiting_scroll_offset_update;
List<Connection> connections;
- void _bake_segment2d(CanvasItem *p_where, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;
+ void _bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;
void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color);
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index fb0ff4f320..538dd846e4 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "graph_node.h"
-#include "method_bind_ext.inc"
+#include "method_bind_ext.gen.inc"
bool GraphNode::_set(const StringName &p_name, const Variant &p_value) {
@@ -239,7 +239,7 @@ void GraphNode::_notification(int p_what) {
if (show_close) {
Vector2 cpos = Point2(w + sb->get_margin(MARGIN_LEFT), -close->get_height() + close_offset);
draw_texture(close, cpos);
- close_rect.pos = cpos;
+ close_rect.position = cpos;
close_rect.size = close->get_size();
} else {
close_rect = Rect2();
@@ -582,11 +582,9 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
ERR_EXPLAIN("GraphNode must be the child of a GraphEdit node.");
ERR_FAIL_COND(get_parent_control() == NULL);
- print_line("INPUT EVENT BUTTON");
-
if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
- Vector2 mpos = Vector2(mb->get_pos().x, mb->get_pos().y);
+ Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y);
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
emit_signal("close_request");
accept_event();
@@ -616,7 +614,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseMotion> mm = p_ev;
if (resizing && mm.is_valid()) {
- Vector2 mpos = mm->get_pos();
+ Vector2 mpos = mm->get_position();
Vector2 diff = mpos - resizing_from;
diff --git a/scene/gui/input_action.cpp b/scene/gui/input_action.cpp
index 311cb4ab13..3f80c31c8b 100644
--- a/scene/gui/input_action.cpp
+++ b/scene/gui/input_action.cpp
@@ -43,7 +43,7 @@ Ref<InputEvent> ShortCut::get_shortcut() const {
bool ShortCut::is_shortcut(const Ref<InputEvent> &p_event) const {
- return shortcut.is_valid() && shortcut->action_match(p_event);
+ return shortcut.is_valid() && shortcut->shortcut_match(p_event);
}
String ShortCut::get_as_text() const {
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index a9f063280b..160b7b151a 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -431,7 +431,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && (mb->get_button_index() == BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == BUTTON_RIGHT)) && mb->is_pressed()) {
search_string = ""; //any mousepress cancels
- Vector2 pos(mb->get_pos().x, mb->get_pos().y);
+ Vector2 pos(mb->get_position().x, mb->get_position().y);
Ref<StyleBox> bg = get_stylebox("bg");
pos -= bg->get_offset();
pos.y += scroll_bar->get_value();
@@ -475,7 +475,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y));
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
}
} else {
@@ -486,7 +486,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (items[i].selected && mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y));
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
} else {
bool selected = !items[i].selected;
@@ -501,7 +501,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y));
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_position().x, mb->get_position().y));
} else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_doubleclick()) {
emit_signal("item_activated", i);
@@ -857,7 +857,7 @@ void ItemList::_notification(int p_what) {
items[i].rect_cache = items[i].min_rect_cache;
if (same_column_width)
items[i].rect_cache.size.x = max_column_width;
- items[i].rect_cache.pos = ofs;
+ items[i].rect_cache.position = ofs;
max_h = MAX(max_h, items[i].rect_cache.size.y);
ofs.x += items[i].rect_cache.size.x + hseparation;
//print_line("item "+itos(i)+" ofs "+rtos(items[i].rect_cache.size.x));
@@ -906,10 +906,10 @@ void ItemList::_notification(int p_what) {
int from = scroll_bar->get_value();
int to = from + scroll_bar->get_page();
- if (r.pos.y < from) {
- scroll_bar->set_value(r.pos.y);
- } else if (r.pos.y + r.size.y > to) {
- scroll_bar->set_value(r.pos.y + r.size.y - (to - from));
+ if (r.position.y < from) {
+ scroll_bar->set_value(r.position.y);
+ } else if (r.position.y + r.size.y > to) {
+ scroll_bar->set_value(r.position.y + r.size.y - (to - from));
}
}
@@ -928,26 +928,29 @@ void ItemList::_notification(int p_what) {
continue;
if (current_columns == 1) {
- rcache.size.width = width - rcache.pos.x;
+ rcache.size.width = width - rcache.position.x;
}
- Rect2 r = rcache;
- r.pos += base_ofs;
-
- // Use stylebox to dimension potential bg color, even if not selected
- r.pos.x -= sbsel->get_margin(MARGIN_LEFT);
- r.size.x += sbsel->get_margin(MARGIN_LEFT) + sbsel->get_margin(MARGIN_RIGHT);
- r.pos.y -= sbsel->get_margin(MARGIN_TOP);
- r.size.y += sbsel->get_margin(MARGIN_TOP) + sbsel->get_margin(MARGIN_BOTTOM);
-
if (items[i].selected) {
+ Rect2 r = rcache;
+ r.position += base_ofs;
+
+ // Use stylebox to dimension potential bg color
+ r.position.x -= sbsel->get_margin(MARGIN_LEFT);
+ r.size.x += sbsel->get_margin(MARGIN_LEFT) + sbsel->get_margin(MARGIN_RIGHT);
+ r.position.y -= sbsel->get_margin(MARGIN_TOP);
+ r.size.y += sbsel->get_margin(MARGIN_TOP) + sbsel->get_margin(MARGIN_BOTTOM);
draw_style_box(sbsel, r);
}
+
if (items[i].custom_bg.a > 0.001) {
- r.pos.x += 2;
- r.size.x -= 4;
- r.pos.y += 2;
- r.size.y -= 4;
+
+ Rect2 r = rcache;
+ r.position += base_ofs;
+
+ // Size rect to make the align the temperature colors
+ r.position.y -= vseparation / 2;
+ r.size.y += vseparation;
draw_rect(r, items[i].custom_bg);
}
@@ -965,7 +968,7 @@ void ItemList::_notification(int p_what) {
Vector2 icon_ofs;
- Point2 pos = items[i].rect_cache.pos + icon_ofs + base_ofs;
+ Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
if (icon_mode == ICON_MODE_TOP) {
@@ -985,7 +988,7 @@ void ItemList::_notification(int p_what) {
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size);
- draw_rect.pos += adj.pos;
+ draw_rect.position += adj.position;
draw_rect.size = adj.size;
}
@@ -1001,7 +1004,7 @@ void ItemList::_notification(int p_what) {
if (items[i].tag_icon.is_valid()) {
- draw_texture(items[i].tag_icon, items[i].rect_cache.pos + base_ofs);
+ draw_texture(items[i].tag_icon, items[i].rect_cache.position + base_ofs);
}
if (items[i].text != "") {
@@ -1046,7 +1049,7 @@ void ItemList::_notification(int p_what) {
text_ofs.y += font->get_ascent();
text_ofs = text_ofs.floor();
text_ofs += base_ofs;
- text_ofs += items[i].rect_cache.pos;
+ text_ofs += items[i].rect_cache.position;
for (int j = 0; j < ss; j++) {
@@ -1074,7 +1077,7 @@ void ItemList::_notification(int p_what) {
text_ofs.y += font->get_ascent();
text_ofs = text_ofs.floor();
text_ofs += base_ofs;
- text_ofs += items[i].rect_cache.pos;
+ text_ofs += items[i].rect_cache.position;
draw_string(font, text_ofs, items[i].text, modulate, max_len + 1);
}
@@ -1083,7 +1086,7 @@ void ItemList::_notification(int p_what) {
if (select_mode == SELECT_MULTI && i == current) {
Rect2 r = rcache;
- r.pos += base_ofs;
+ r.position += base_ofs;
draw_style_box(cursor, r);
}
}
@@ -1141,7 +1144,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const {
pos.y += scroll_bar->get_value();
Rect2 endrect = items[items.size() - 1].rect_cache;
- return (pos.y > endrect.pos.y + endrect.size.y);
+ return (pos.y > endrect.position.y + endrect.size.y);
}
String ItemList::get_tooltip(const Point2 &p_pos) const {
@@ -1220,6 +1223,36 @@ Vector<int> ItemList::get_selected_items() {
return selected;
}
+void ItemList::_set_items(const Array &p_items) {
+
+ ERR_FAIL_COND(p_items.size() % 3);
+ clear();
+
+ for (int i = 0; i < p_items.size(); i += 3) {
+
+ String text = p_items[i + 0];
+ Ref<Texture> icon = p_items[i + 1];
+ bool disabled = p_items[i + 2];
+
+ int idx = get_item_count();
+ add_item(text, icon);
+ set_item_disabled(idx, disabled);
+ }
+}
+
+Array ItemList::_get_items() const {
+
+ Array items;
+ for (int i = 0; i < get_item_count(); i++) {
+
+ items.push_back(get_item_text(i));
+ items.push_back(get_item_icon(i));
+ items.push_back(is_item_disabled(i));
+ }
+
+ return items;
+}
+
void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_item", "text", "icon:Texture", "selectable"), &ItemList::add_item, DEFVAL(Variant()), DEFVAL(true));
@@ -1299,6 +1332,22 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("_scroll_changed"), &ItemList::_scroll_changed);
ClassDB::bind_method(D_METHOD("_gui_input"), &ItemList::_gui_input);
+ ClassDB::bind_method(D_METHOD("_set_items"), &ItemList::_set_items);
+ ClassDB::bind_method(D_METHOD("_get_items"), &ItemList::_get_items);
+
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items");
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines");
+ ADD_GROUP("Columns", "");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_columns"), "set_max_columns", "get_max_columns");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "same_column_width"), "set_same_column_width", "is_same_column_width");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "fixed_column_width"), "set_fixed_column_width", "get_fixed_column_width");
+ ADD_GROUP("Icon", "");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_mode", PROPERTY_HINT_ENUM, "Top,Left"), "set_icon_mode", "get_icon_mode");
+ ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "icon_scale"), "set_icon_scale", "get_icon_scale");
+
BIND_CONSTANT(ICON_MODE_TOP);
BIND_CONSTANT(ICON_MODE_LEFT);
BIND_CONSTANT(SELECT_SINGLE);
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index c7abc2990f..9cb7016b60 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -103,6 +103,9 @@ private:
real_t icon_scale;
+ Array _get_items() const;
+ void _set_items(const Array &p_items);
+
void _scroll_changed(double);
void _gui_input(const Ref<InputEvent> &p_event);
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index f3a279bada..fb85930ceb 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -65,7 +65,12 @@ void Label::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- xl_text = XL_MESSAGE(text);
+ String new_text = XL_MESSAGE(text);
+ if (new_text == xl_text)
+ return; //nothing new
+ xl_text = new_text;
+
+ regenerate_word_cache();
minimum_size_changed();
update();
}
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 38debe8a77..bc579020bd 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -64,7 +64,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
shift_selection_check_pre(b->get_shift());
- set_cursor_at_pixel_pos(b->get_pos().x);
+ set_cursor_at_pixel_pos(b->get_position().x);
if (b->get_shift()) {
@@ -118,7 +118,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if (m->get_button_mask() & BUTTON_LEFT) {
if (selection.creating) {
- set_cursor_at_pixel_pos(m->get_pos().x);
+ set_cursor_at_pixel_pos(m->get_position().x);
selection_fill_at_cursor();
}
}
diff --git a/scene/gui/patch_9_rect.cpp b/scene/gui/patch_9_rect.cpp
index 0c2b94d700..735f36b55d 100644
--- a/scene/gui/patch_9_rect.cpp
+++ b/scene/gui/patch_9_rect.cpp
@@ -44,7 +44,7 @@ void NinePatchRect::_notification(int p_what) {
texture->get_rect_region(rect, src_rect, rect, src_rect);
RID ci = get_canvas_item();
- VS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center);
+ VS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NinePatchAxisMode(axis_h), VS::NinePatchAxisMode(axis_v), draw_center);
}
}
@@ -62,6 +62,10 @@ void NinePatchRect::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_region_rect"), &NinePatchRect::get_region_rect);
ClassDB::bind_method(D_METHOD("set_draw_center", "draw_center"), &NinePatchRect::set_draw_center);
ClassDB::bind_method(D_METHOD("get_draw_center"), &NinePatchRect::get_draw_center);
+ ClassDB::bind_method(D_METHOD("set_h_axis_stretch_mode", "mode"), &NinePatchRect::set_h_axis_stretch_mode);
+ ClassDB::bind_method(D_METHOD("get_h_axis_stretch_mode"), &NinePatchRect::get_h_axis_stretch_mode);
+ ClassDB::bind_method(D_METHOD("set_v_axis_stretch_mode", "mode"), &NinePatchRect::set_v_axis_stretch_mode);
+ ClassDB::bind_method(D_METHOD("get_v_axis_stretch_mode"), &NinePatchRect::get_v_axis_stretch_mode);
ADD_SIGNAL(MethodInfo("texture_changed"));
@@ -74,6 +78,13 @@ void NinePatchRect::_bind_methods() {
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin_top", PROPERTY_HINT_RANGE, "0,16384,1"), "set_patch_margin", "get_patch_margin", MARGIN_TOP);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin_right", PROPERTY_HINT_RANGE, "0,16384,1"), "set_patch_margin", "get_patch_margin", MARGIN_RIGHT);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "patch_margin_bottom", PROPERTY_HINT_RANGE, "0,16384,1"), "set_patch_margin", "get_patch_margin", MARGIN_BOTTOM);
+ ADD_GROUP("Axis Stretch", "axis_stretch_");
+ 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);
}
void NinePatchRect::set_texture(const Ref<Texture> &p_tex) {
@@ -150,6 +161,26 @@ bool NinePatchRect::get_draw_center() const {
return draw_center;
}
+void NinePatchRect::set_h_axis_stretch_mode(AxisStretchMode p_mode) {
+ axis_h = p_mode;
+ update();
+}
+
+NinePatchRect::AxisStretchMode NinePatchRect::get_h_axis_stretch_mode() const {
+ return axis_h;
+}
+
+void NinePatchRect::set_v_axis_stretch_mode(AxisStretchMode p_mode) {
+
+ axis_v = p_mode;
+ update();
+}
+
+NinePatchRect::AxisStretchMode NinePatchRect::get_v_axis_stretch_mode() const {
+
+ return axis_v;
+}
+
NinePatchRect::NinePatchRect() {
margin[MARGIN_LEFT] = 0;
@@ -159,6 +190,9 @@ NinePatchRect::NinePatchRect() {
set_mouse_filter(MOUSE_FILTER_IGNORE);
draw_center = true;
+
+ axis_h = AXIS_STRETCH_MODE_STRETCH;
+ axis_v = AXIS_STRETCH_MODE_STRETCH;
}
NinePatchRect::~NinePatchRect() {
diff --git a/scene/gui/patch_9_rect.h b/scene/gui/patch_9_rect.h
index ba978f2f81..602a6d22bf 100644
--- a/scene/gui/patch_9_rect.h
+++ b/scene/gui/patch_9_rect.h
@@ -38,11 +38,20 @@ class NinePatchRect : public Control {
GDCLASS(NinePatchRect, Control);
+public:
+ enum AxisStretchMode {
+ AXIS_STRETCH_MODE_STRETCH,
+ AXIS_STRETCH_MODE_TILE,
+ AXIS_STRETCH_MODE_TILE_FIT,
+ };
+
bool draw_center;
int margin[4];
Rect2 region_rect;
Ref<Texture> texture;
+ AxisStretchMode axis_h, axis_v;
+
protected:
void _notification(int p_what);
virtual Size2 get_minimum_size() const;
@@ -61,7 +70,15 @@ public:
void set_draw_center(bool p_enable);
bool get_draw_center() const;
+ void set_h_axis_stretch_mode(AxisStretchMode p_mode);
+ AxisStretchMode get_h_axis_stretch_mode() const;
+
+ void set_v_axis_stretch_mode(AxisStretchMode p_mode);
+ AxisStretchMode get_v_axis_stretch_mode() const;
+
NinePatchRect();
~NinePatchRect();
};
+
+VARIANT_ENUM_CAST(NinePatchRect::AxisStretchMode)
#endif // PATCH_9_FRAME_H
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 655d8ed6f6..8979e0f111 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -170,8 +170,8 @@ void Popup::popup_centered(const Size2 &p_size) {
Rect2 rect;
rect.size = p_size == Size2() ? get_size() : p_size;
- rect.pos = ((window_size - rect.size) / 2.0).floor();
- set_position(rect.pos);
+ rect.position = ((window_size - rect.size) / 2.0).floor();
+ set_position(rect.position);
set_size(rect.size);
show_modal(exclusive);
@@ -193,8 +193,8 @@ void Popup::popup_centered_ratio(float p_screen_ratio) {
Rect2 rect;
Point2 window_size = get_viewport_rect().size;
rect.size = (window_size * p_screen_ratio).floor();
- rect.pos = ((window_size - rect.size) / 2.0).floor();
- set_position(rect.pos);
+ rect.position = ((window_size - rect.size) / 2.0).floor();
+ set_position(rect.position);
set_size(rect.size);
show_modal(exclusive);
@@ -216,7 +216,7 @@ void Popup::popup(const Rect2 &bounds) {
// Fit the popup into the optionally provided bounds.
if (!bounds.has_no_area()) {
- set_position(bounds.pos);
+ set_position(bounds.position);
set_size(bounds.size);
}
_fix_size();
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 985d9addc9..74b26da580 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -190,12 +190,12 @@ void PopupMenu::_activate_submenu(int over) {
PopupMenu *pum = pm->cast_to<PopupMenu>();
if (pum) {
- pr.pos -= pum->get_global_position();
+ pr.position -= pum->get_global_position();
pum->clear_autohide_areas();
- pum->add_autohide_area(Rect2(pr.pos.x, pr.pos.y, pr.size.x, items[over]._ofs_cache));
+ pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache));
if (over < items.size() - 1) {
int from = items[over + 1]._ofs_cache;
- pum->add_autohide_area(Rect2(pr.pos.x, pr.pos.y + from, pr.size.x, pr.size.y - from));
+ pum->add_autohide_area(Rect2(pr.position.x, pr.position.y + from, pr.size.x, pr.size.y - from));
}
}
}
@@ -284,7 +284,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
//update hover
Ref<InputEventMouseMotion> ie;
ie.instance();
- ie->set_pos(b->get_pos() + Vector2(0, s));
+ ie->set_position(b->get_position() + Vector2(0, s));
_gui_input(ie);
}
} break;
@@ -303,13 +303,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
//update hover
Ref<InputEventMouseMotion> ie;
ie.instance();
- ie->set_pos(b->get_pos() - Vector2(0, s));
+ ie->set_position(b->get_position() - Vector2(0, s));
_gui_input(ie);
}
} break;
case BUTTON_LEFT: {
- int over = _get_mouse_over(b->get_pos());
+ int over = _get_mouse_over(b->get_position());
if (invalidated_click) {
invalidated_click = false;
@@ -348,13 +348,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
- if (!Rect2(Point2(), get_size()).has_point(m->get_pos()) && E->get().has_point(m->get_pos())) {
+ if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) {
call_deferred("hide");
return;
}
}
- int over = _get_mouse_over(m->get_pos());
+ int over = _get_mouse_over(m->get_position());
int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].ID >= 0 ? items[over].ID : over);
if (id < 0) {
@@ -884,7 +884,7 @@ void PopupMenu::activate_item(int p_item) {
while (pop) {
// We close all parents that are chained together,
// with hide_on_item_selection enabled
- if (hide_on_item_selection && pop->is_hide_on_item_selection()) {
+ 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>();
@@ -895,8 +895,8 @@ void PopupMenu::activate_item(int p_item) {
}
}
// Hides popup by default; unless otherwise specified
- // by using set_hide_on_item_selection
- if (hide_on_item_selection) {
+ // by using set_hide_on_item_selection and set_hide_on_checkable_item_selection
+ if ((items[p_item].checkable && hide_on_checkable_item_selection) || (!items[p_item].checkable && hide_on_item_selection)) {
hide();
}
}
@@ -1019,6 +1019,16 @@ bool PopupMenu::is_hide_on_item_selection() {
return hide_on_item_selection;
}
+void PopupMenu::set_hide_on_checkable_item_selection(bool p_enabled) {
+
+ hide_on_checkable_item_selection = p_enabled;
+}
+
+bool PopupMenu::is_hide_on_checkable_item_selection() {
+
+ return hide_on_checkable_item_selection;
+}
+
String PopupMenu::get_tooltip(const Point2 &p_pos) const {
int over = _get_mouse_over(p_pos);
@@ -1107,10 +1117,14 @@ void PopupMenu::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_hide_on_item_selection", "enable"), &PopupMenu::set_hide_on_item_selection);
ClassDB::bind_method(D_METHOD("is_hide_on_item_selection"), &PopupMenu::is_hide_on_item_selection);
+ ClassDB::bind_method(D_METHOD("set_hide_on_checkable_item_selection", "enable"), &PopupMenu::set_hide_on_checkable_item_selection);
+ ClassDB::bind_method(D_METHOD("is_hide_on_checkable_item_selection"), &PopupMenu::is_hide_on_checkable_item_selection);
+
ClassDB::bind_method(D_METHOD("_submenu_timeout"), &PopupMenu::_submenu_timeout);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_item_selection"), "set_hide_on_item_selection", "is_hide_on_item_selection");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_checkable_item_selection"), "set_hide_on_checkable_item_selection", "is_hide_on_checkable_item_selection");
ADD_SIGNAL(MethodInfo("id_pressed", PropertyInfo(Variant::INT, "ID")));
ADD_SIGNAL(MethodInfo("index_pressed", PropertyInfo(Variant::INT, "index")));
@@ -1128,6 +1142,7 @@ PopupMenu::PopupMenu() {
set_focus_mode(FOCUS_ALL);
set_as_toplevel(true);
set_hide_on_item_selection(true);
+ set_hide_on_checkable_item_selection(true);
submenu_timer = memnew(Timer);
submenu_timer->set_wait_time(0.3);
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 7ef532453d..a9bd8f7e50 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -85,6 +85,7 @@ class PopupMenu : public Popup {
bool invalidated_click;
bool hide_on_item_selection;
+ bool hide_on_checkable_item_selection;
Vector2 moved;
Array _get_items() const;
@@ -168,6 +169,9 @@ public:
void set_hide_on_item_selection(bool p_enabled);
bool is_hide_on_item_selection();
+ void set_hide_on_checkable_item_selection(bool p_enabled);
+ bool is_hide_on_checkable_item_selection();
+
PopupMenu();
~PopupMenu();
};
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index a618810c11..c6b8398736 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -264,7 +264,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int
cw = tab_size * font->get_char_size(' ').width;
}
- if (end > 0 && w + cw + wofs > p_width) {
+ if (end > 0 && w + cw + begin > p_width) {
break; //don't allow lines longer than assigned width
}
@@ -751,7 +751,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
Item *item = NULL;
bool outside;
- _find_click(main, b->get_pos(), &item, &line, &outside);
+ _find_click(main, b->get_position(), &item, &line, &outside);
if (item) {
@@ -852,7 +852,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
int line = 0;
Item *item = NULL;
- _find_click(main, m->get_pos(), &item, &line);
+ _find_click(main, m->get_position(), &item, &line);
if (!item)
return; // do not update
@@ -1822,16 +1822,41 @@ String RichTextLabel::get_text() {
return text;
}
+void RichTextLabel::set_text(const String &p_string) {
+ clear();
+ add_text(p_string);
+}
+
+void RichTextLabel::set_percent_visible(float p_percent) {
+
+ if (p_percent < 0 || p_percent >= 1) {
+
+ visible_characters = -1;
+ percent_visible = 1;
+
+ } else {
+
+ visible_characters = get_total_character_count() * p_percent;
+ percent_visible = p_percent;
+ }
+ update();
+}
+
+float RichTextLabel::get_percent_visible() const {
+ return percent_visible;
+}
+
void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input);
ClassDB::bind_method(D_METHOD("_scroll_changed"), &RichTextLabel::_scroll_changed);
ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text);
ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text);
+ ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text);
ClassDB::bind_method(D_METHOD("add_image", "image:Texture"), &RichTextLabel::add_image);
ClassDB::bind_method(D_METHOD("newline"), &RichTextLabel::add_newline);
ClassDB::bind_method(D_METHOD("remove_line"), &RichTextLabel::remove_line);
- ClassDB::bind_method(D_METHOD("push_font", "font"), &RichTextLabel::push_font);
+ ClassDB::bind_method(D_METHOD("push_font", "font:Font"), &RichTextLabel::push_font);
ClassDB::bind_method(D_METHOD("push_color", "color"), &RichTextLabel::push_color);
ClassDB::bind_method(D_METHOD("push_align", "align"), &RichTextLabel::push_align);
ClassDB::bind_method(D_METHOD("push_indent", "level"), &RichTextLabel::push_indent);
@@ -1854,7 +1879,7 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_scroll_follow", "follow"), &RichTextLabel::set_scroll_follow);
ClassDB::bind_method(D_METHOD("is_scroll_following"), &RichTextLabel::is_scroll_following);
- ClassDB::bind_method(D_METHOD("get_v_scroll"), &RichTextLabel::get_v_scroll);
+ ClassDB::bind_method(D_METHOD("get_v_scroll:VScrollBar"), &RichTextLabel::get_v_scroll);
ClassDB::bind_method(D_METHOD("scroll_to_line", "line"), &RichTextLabel::scroll_to_line);
@@ -1873,6 +1898,9 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_visible_characters", "amount"), &RichTextLabel::set_visible_characters);
ClassDB::bind_method(D_METHOD("get_visible_characters"), &RichTextLabel::get_visible_characters);
+ ClassDB::bind_method(D_METHOD("set_percent_visible", "percent_visible"), &RichTextLabel::set_percent_visible);
+ ClassDB::bind_method(D_METHOD("get_percent_visible"), &RichTextLabel::get_percent_visible);
+
ClassDB::bind_method(D_METHOD("get_total_character_count"), &RichTextLabel::get_total_character_count);
ClassDB::bind_method(D_METHOD("set_use_bbcode", "enable"), &RichTextLabel::set_use_bbcode);
@@ -1881,7 +1909,9 @@ void RichTextLabel::_bind_methods() {
ADD_GROUP("BBCode", "bbcode_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode_text", PROPERTY_HINT_MULTILINE_TEXT), "set_bbcode", "get_bbcode");
+
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta")));
@@ -1914,7 +1944,6 @@ void RichTextLabel::set_visible_characters(int p_visible) {
}
int RichTextLabel::get_visible_characters() const {
-
return visible_characters;
}
int RichTextLabel::get_total_character_count() const {
@@ -1964,11 +1993,11 @@ RichTextLabel::RichTextLabel() {
selection.enabled = false;
visible_characters = -1;
+ percent_visible = 1;
set_clip_contents(true);
}
RichTextLabel::~RichTextLabel() {
-
memdelete(main);
}
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index eedb7e54db..409a8f6b3f 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -258,6 +258,7 @@ private:
Selection selection;
int visible_characters;
+ float percent_visible;
void _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0);
void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL);
@@ -340,10 +341,15 @@ public:
void set_bbcode(const String &p_bbcode);
String get_bbcode() const;
+ void set_text(const String &p_string);
+
void set_visible_characters(int p_visible);
int get_visible_characters() const;
int get_total_character_count() const;
+ void set_percent_visible(float p_percent);
+ float get_percent_visible() const;
+
RichTextLabel();
~RichTextLabel();
};
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 27a16ccc33..bd66cd2745 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -72,7 +72,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
if (b->is_pressed()) {
- double ofs = orientation == VERTICAL ? b->get_pos().y : b->get_pos().x;
+ double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x;
Ref<Texture> decr = get_icon("decrement");
Ref<Texture> incr = get_icon("increment");
@@ -130,7 +130,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
if (drag.active) {
- double ofs = orientation == VERTICAL ? m->get_pos().y : m->get_pos().x;
+ double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
Ref<Texture> decr = get_icon("decrement");
double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
@@ -141,7 +141,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
set_as_ratio(drag.value_at_click + diff);
} else {
- double ofs = orientation == VERTICAL ? m->get_pos().y : m->get_pos().x;
+ double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x;
Ref<Texture> decr = get_icon("decrement");
Ref<Texture> incr = get_icon("increment");
@@ -267,14 +267,14 @@ void ScrollBar::_notification(int p_what) {
grabber_rect.size.width = get_grabber_size();
grabber_rect.size.height = get_size().height;
- grabber_rect.pos.y = 0;
- grabber_rect.pos.x = get_grabber_offset() + decr->get_width() + bg->get_margin(MARGIN_LEFT);
+ grabber_rect.position.y = 0;
+ grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(MARGIN_LEFT);
} else {
grabber_rect.size.width = get_size().width;
grabber_rect.size.height = get_grabber_size();
- grabber_rect.pos.y = get_grabber_offset() + decr->get_height() + bg->get_margin(MARGIN_TOP);
- grabber_rect.pos.x = 0;
+ grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(MARGIN_TOP);
+ grabber_rect.position.x = 0;
}
grabber->draw(ci, grabber_rect);
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 70b4ac47f8..cc1a637d2b 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -233,14 +233,14 @@ void ScrollContainer::_notification(int p_what) {
Rect2 r = Rect2(-scroll, minsize);
if (!scroll_h || (!h_scroll->is_visible_in_tree() && c->get_h_size_flags() & SIZE_EXPAND)) {
- r.pos.x = 0;
+ r.position.x = 0;
if (c->get_h_size_flags() & SIZE_EXPAND)
r.size.width = MAX(size.width, minsize.width);
else
r.size.width = minsize.width;
}
if (!scroll_v || (!v_scroll->is_visible_in_tree() && c->get_v_size_flags() & SIZE_EXPAND)) {
- r.pos.y = 0;
+ r.position.y = 0;
r.size.height = size.height;
if (c->get_v_size_flags() & SIZE_EXPAND)
r.size.height = MAX(size.height, minsize.height);
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index ae2bf0999e..c84608ef2e 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -39,6 +39,10 @@ Size2 Slider::get_minimum_size() const {
void Slider::_gui_input(Ref<InputEvent> p_event) {
+ if (!editable) {
+ return;
+ }
+
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid()) {
@@ -46,7 +50,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
if (mb->is_pressed()) {
Ref<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber");
- grab.pos = orientation == VERTICAL ? mb->get_pos().y : mb->get_pos().x;
+ grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x;
double grab_width = (double)grabber->get_size().width;
double grab_height = (double)grabber->get_size().height;
@@ -75,7 +79,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
Size2i size = get_size();
Ref<Texture> grabber = get_icon("grabber");
- float motion = (orientation == VERTICAL ? mm->get_pos().y : mm->get_pos().x) - grab.pos;
+ float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos;
if (orientation == VERTICAL)
motion = -motion;
float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
@@ -158,7 +162,7 @@ void Slider::_notification(int p_what) {
Size2i size = get_size();
Ref<StyleBox> style = get_stylebox("slider");
Ref<StyleBox> focus = get_stylebox("focus");
- Ref<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber");
+ Ref<Texture> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled");
Ref<Texture> tick = get_icon("tick");
if (orientation == VERTICAL) {
@@ -231,6 +235,17 @@ void Slider::set_ticks_on_borders(bool _tob) {
update();
}
+void Slider::set_editable(bool p_editable) {
+
+ editable = p_editable;
+ update();
+}
+
+bool Slider::is_editable() const {
+
+ return editable;
+}
+
void Slider::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &Slider::_gui_input);
@@ -240,6 +255,10 @@ void Slider::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_ticks_on_borders"), &Slider::get_ticks_on_borders);
ClassDB::bind_method(D_METHOD("set_ticks_on_borders", "ticks_on_border"), &Slider::set_ticks_on_borders);
+ ClassDB::bind_method(D_METHOD("set_editable", "editable"), &Slider::set_editable);
+ ClassDB::bind_method(D_METHOD("is_editable"), &Slider::is_editable);
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
ADD_PROPERTY(PropertyInfo(Variant::INT, "tick_count", PROPERTY_HINT_RANGE, "0,4096,1"), "set_ticks", "get_ticks");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ticks_on_borders"), "set_ticks_on_borders", "get_ticks_on_borders");
ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode");
@@ -251,5 +270,6 @@ Slider::Slider(Orientation p_orientation) {
grab.active = false;
ticks = 0;
custom_step = -1;
+ editable = true;
set_focus_mode(FOCUS_ALL);
}
diff --git a/scene/gui/slider.h b/scene/gui/slider.h
index 7194484058..f3cf3c6f48 100644
--- a/scene/gui/slider.h
+++ b/scene/gui/slider.h
@@ -46,6 +46,7 @@ class Slider : public Range {
bool mouse_inside;
Orientation orientation;
float custom_step;
+ bool editable;
protected:
void _gui_input(Ref<InputEvent> p_event);
@@ -65,6 +66,9 @@ public:
void set_ticks_on_borders(bool);
bool get_ticks_on_borders() const;
+ void set_editable(bool p_editable);
+ bool is_editable() const;
+
Slider(Orientation p_orientation = VERTICAL);
};
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 2eb2028391..c5b9df15b9 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -96,7 +96,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && mb->is_pressed()) {
- bool up = mb->get_pos().y < (get_size().height / 2);
+ bool up = mb->get_position().y < (get_size().height / 2);
switch (mb->get_button_index()) {
@@ -135,7 +135,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1) {
//set_default_cursor_shape(CURSOR_VSIZE);
- Vector2 cpos = Vector2(mb->get_pos().x, mb->get_pos().y);
+ Vector2 cpos = Vector2(mb->get_position().x, mb->get_position().y);
drag.mouse_pos = cpos;
}
@@ -155,7 +155,7 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid() && mm->get_button_mask() & 1) {
- Vector2 cpos = mm->get_pos();
+ Vector2 cpos = mm->get_position();
if (drag.enabled) {
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 91fd18e2ed..e3dad08809 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -131,7 +131,12 @@ void SplitContainer::_resort() {
if (ratiomode) {
- middle_sep = ms_first[axis] + available / 2;
+ int first_ratio = first->get_stretch_ratio();
+ int second_ratio = second->get_stretch_ratio();
+
+ float ratio = float(first_ratio) / (first_ratio + second_ratio);
+
+ middle_sep = ms_first[axis] + available * ratio;
} else if (expand_first_mode) {
@@ -144,12 +149,17 @@ void SplitContainer::_resort() {
} else if (ratiomode) {
- if (expand_ofs < -(available / 2))
- expand_ofs = -(available / 2);
- else if (expand_ofs > (available / 2))
- expand_ofs = (available / 2);
+ int first_ratio = first->get_stretch_ratio();
+ int second_ratio = second->get_stretch_ratio();
+
+ float ratio = float(first_ratio) / (first_ratio + second_ratio);
+
+ if (expand_ofs < -(available * ratio))
+ expand_ofs = -(available * ratio);
+ else if (expand_ofs > (available * (1.0 - ratio)))
+ expand_ofs = (available * (1.0 - ratio));
- middle_sep = ms_first[axis] + available / 2 + expand_ofs;
+ middle_sep = ms_first[axis] + available * ratio + expand_ofs;
} else if (expand_first_mode) {
@@ -286,16 +296,16 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (vertical) {
- if (mb->get_pos().y > middle_sep && mb->get_pos().y < middle_sep + sep) {
+ if (mb->get_position().y > middle_sep && mb->get_position().y < middle_sep + sep) {
dragging = true;
- drag_from = mb->get_pos().y;
+ drag_from = mb->get_position().y;
drag_ofs = expand_ofs;
}
} else {
- if (mb->get_pos().x > middle_sep && mb->get_pos().x < middle_sep + sep) {
+ if (mb->get_position().x > middle_sep && mb->get_position().x < middle_sep + sep) {
dragging = true;
- drag_from = mb->get_pos().x;
+ drag_from = mb->get_position().x;
drag_ofs = expand_ofs;
}
}
@@ -312,7 +322,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (dragging) {
- expand_ofs = drag_ofs + ((vertical ? mm->get_pos().y : mm->get_pos().x) - drag_from);
+ expand_ofs = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from);
queue_sort();
emit_signal("dragged", get_split_offset());
}
diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h
index 94b80cf279..87a210f24c 100644
--- a/scene/gui/split_container.h
+++ b/scene/gui/split_container.h
@@ -34,7 +34,7 @@
class SplitContainer : public Container {
- GDCLASS(SplitContainer, Container);
+ GDCLASS(SplitContainer, Container)
public:
enum DraggerVisibility {
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 6bbfa1aeb0..5ebcef3e8d 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -69,7 +69,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
- Point2 pos(mb->get_pos().x, mb->get_pos().y);
+ Point2 pos(mb->get_position().x, mb->get_position().y);
Size2 size = get_size();
// Click must be on tabs in the tab header area.
@@ -233,7 +233,7 @@ void TabContainer::_notification(int p_what) {
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());
- int x_content = tab_rect.pos.x + tab_style->get_margin(MARGIN_LEFT);
+ int x_content = tab_rect.position.x + tab_style->get_margin(MARGIN_LEFT);
int top_margin = tab_style->get_margin(MARGIN_TOP);
int y_center = top_margin + (tab_rect.size.y - tab_style->get_minimum_size().y) / 2;
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index d94c33e408..4316f06a53 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -85,7 +85,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid()) {
- Point2 pos = mm->get_pos();
+ Point2 pos = mm->get_position();
highlight_arrow = -1;
if (buttons_visible) {
@@ -103,13 +103,17 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
}
// test hovering to display right or close button
+ int hover_now = -1;
int hover_buttons = -1;
- hover = -1;
for (int i = 0; i < tabs.size(); i++) {
if (i < offset)
continue;
+ Rect2 rect = get_tab_rect(i);
+ if (rect.has_point(pos)) {
+ hover_now = i;
+ }
if (tabs[i].rb_rect.has_point(pos)) {
rb_hover = i;
cb_hover = -1;
@@ -122,6 +126,10 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
break;
}
}
+ if (hover != hover_now) {
+ hover = hover_now;
+ emit_signal("tab_hover", hover);
+ }
if (hover_buttons == -1) { // no hover
rb_hover = hover_buttons;
@@ -165,7 +173,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
mb->get_button_index() == BUTTON_LEFT) {
// clicks
- Point2 pos(mb->get_pos().x, mb->get_pos().y);
+ Point2 pos(mb->get_position().x, mb->get_position().y);
if (buttons_visible) {
@@ -234,11 +242,13 @@ void Tabs::_notification(int p_what) {
update();
} break;
case NOTIFICATION_RESIZED: {
-
+ _update_cache();
_ensure_no_over_offset();
+ ensure_tab_visible(current);
+
} break;
case NOTIFICATION_DRAW: {
-
+ _update_cache();
RID ci = get_canvas_item();
Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
@@ -286,18 +296,7 @@ void Tabs::_notification(int p_what) {
tabs[i].ofs_cache = w;
- int lsize = get_tab_width(i);
-
- String text = tabs[i].text;
- int slen = font->get_string_size(text).width;
-
- if (w + lsize > limit) {
- max_drawn_tab = i - 1;
- missing_right = true;
- break;
- } else {
- max_drawn_tab = i;
- }
+ int lsize = tabs[i].size_cache;
Ref<StyleBox> sb;
Color col;
@@ -313,7 +312,15 @@ void Tabs::_notification(int p_what) {
col = color_bg;
}
- Rect2 sb_rect = Rect2(w, 0, lsize, h);
+ if (w + lsize > limit) {
+ max_drawn_tab = i - 1;
+ missing_right = true;
+ break;
+ } else {
+ max_drawn_tab = i;
+ }
+
+ Rect2 sb_rect = Rect2(w, 0, tabs[i].size_cache, h);
sb->draw(ci, sb_rect);
w += sb->get_margin(MARGIN_LEFT);
@@ -323,13 +330,13 @@ void Tabs::_notification(int p_what) {
if (icon.is_valid()) {
icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2));
- if (text != "")
+ if (tabs[i].text != "")
w += icon->get_width() + get_constant("hseparation");
}
- font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), text, col);
+ font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), tabs[i].text, col, tabs[i].size_text);
- w += slen;
+ w += tabs[i].size_text;
if (tabs[i].right_button.is_valid()) {
@@ -340,8 +347,8 @@ void Tabs::_notification(int p_what) {
Rect2 rb_rect;
rb_rect.size = style->get_minimum_size() + rb->get_size();
- rb_rect.pos.x = w;
- rb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;
+ rb_rect.position.x = w;
+ rb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (rb_rect.size.y)) / 2;
if (rb_hover == i) {
if (rb_pressing)
@@ -350,7 +357,7 @@ void Tabs::_notification(int p_what) {
style->draw(ci, rb_rect);
}
- rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.pos.y + style->get_margin(MARGIN_TOP)));
+ rb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), rb_rect.position.y + style->get_margin(MARGIN_TOP)));
w += rb->get_width();
tabs[i].rb_rect = rb_rect;
}
@@ -364,8 +371,8 @@ void Tabs::_notification(int p_what) {
Rect2 cb_rect;
cb_rect.size = style->get_minimum_size() + cb->get_size();
- cb_rect.pos.x = w;
- cb_rect.pos.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;
+ cb_rect.position.x = w;
+ cb_rect.position.y = sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - (cb_rect.size.y)) / 2;
if (!tabs[i].disabled && cb_hover == i) {
if (cb_pressing)
@@ -374,14 +381,12 @@ void Tabs::_notification(int p_what) {
style->draw(ci, cb_rect);
}
- cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.pos.y + style->get_margin(MARGIN_TOP)));
+ cb->draw(ci, Point2i(w + style->get_margin(MARGIN_LEFT), cb_rect.position.y + style->get_margin(MARGIN_TOP)));
w += cb->get_width();
tabs[i].cb_rect = cb_rect;
}
w += sb->get_margin(MARGIN_RIGHT);
-
- tabs[i].size_cache = w - tabs[i].ofs_cache;
}
if (offset > 0 || missing_right) {
@@ -419,6 +424,7 @@ void Tabs::set_current_tab(int p_current) {
current = p_current;
_change_notify("current_tab");
+ _update_cache();
update();
}
@@ -427,6 +433,10 @@ int Tabs::get_current_tab() const {
return current;
}
+int Tabs::get_hovered_tab() const {
+ return hover;
+}
+
void Tabs::set_tab_title(int p_tab, const String &p_title) {
ERR_FAIL_INDEX(p_tab, tabs.size());
@@ -480,15 +490,81 @@ Ref<Texture> Tabs::get_tab_right_button(int p_tab) const {
return tabs[p_tab].right_button;
}
+void Tabs::_update_cache() {
+ Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
+ Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
+ Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
+ Ref<Font> font = get_font("font");
+ Ref<Texture> incr = get_icon("increment");
+ Ref<Texture> decr = get_icon("decrement");
+ int limit = get_size().width - incr->get_width() - decr->get_width();
+
+ int w = 0;
+ int mw = 0;
+ int size_fixed = 0;
+ int count_resize = 0;
+ for (int i = 0; i < tabs.size(); i++) {
+ tabs[i].ofs_cache = mw;
+ tabs[i].size_cache = get_tab_width(i);
+ tabs[i].size_text = font->get_string_size(tabs[i].text).width;
+ mw += tabs[i].size_cache;
+ if (tabs[i].size_cache <= min_width || i == current) {
+ size_fixed += tabs[i].size_cache;
+ } else {
+ count_resize++;
+ }
+ }
+ int m_width = min_width;
+ if (count_resize > 0) {
+ m_width = MAX((limit - size_fixed) / count_resize, min_width);
+ }
+ for (int i = 0; i < tabs.size(); i++) {
+ if (i < offset)
+ continue;
+ Ref<StyleBox> sb;
+ if (tabs[i].disabled) {
+ sb = tab_disabled;
+ } else if (i == current) {
+ sb = tab_fg;
+ } else {
+ sb = tab_bg;
+ }
+ int lsize = tabs[i].size_cache;
+ int slen = tabs[i].size_text;
+ if (min_width > 0 && mw > limit && i != current) {
+ if (lsize > m_width) {
+ slen = m_width - (sb->get_margin(MARGIN_LEFT) + sb->get_margin(MARGIN_RIGHT));
+ if (tabs[i].icon.is_valid()) {
+ slen -= tabs[i].icon->get_width();
+ slen -= get_constant("hseparation");
+ }
+ if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) {
+ Ref<Texture> cb = get_icon("close");
+ slen -= cb->get_width();
+ slen -= get_constant("hseparation");
+ }
+ slen = MAX(slen, 1);
+ lsize = m_width;
+ }
+ }
+ tabs[i].ofs_cache = w;
+ tabs[i].size_cache = lsize;
+ tabs[i].size_text = slen;
+ w += lsize;
+ }
+}
+
void Tabs::add_tab(const String &p_str, const Ref<Texture> &p_icon) {
Tab t;
t.text = p_str;
t.icon = p_icon;
t.disabled = false;
+ t.ofs_cache = 0;
+ t.size_cache = 0;
tabs.push_back(t);
-
+ _update_cache();
update();
minimum_size_changed();
}
@@ -505,6 +581,7 @@ void Tabs::remove_tab(int p_idx) {
tabs.remove(p_idx);
if (current >= p_idx)
current--;
+ _update_cache();
update();
minimum_size_changed();
@@ -516,6 +593,41 @@ void Tabs::remove_tab(int p_idx) {
_ensure_no_over_offset();
}
+Variant Tabs::get_drag_data(const Point2 &p_point) {
+
+ return get_tab_idx_at_point(p_point);
+}
+
+bool Tabs::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
+
+ return get_tab_idx_at_point(p_point) > -1;
+}
+
+void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) {
+
+ int hover_now = get_tab_idx_at_point(p_point);
+
+ ERR_FAIL_INDEX(hover_now, tabs.size());
+ emit_signal("reposition_active_tab_request", hover_now);
+}
+
+int Tabs::get_tab_idx_at_point(const Point2 &p_point) const {
+
+ int hover_now = -1;
+ for (int i = 0; i < tabs.size(); i++) {
+
+ if (i < offset)
+ continue;
+
+ Rect2 rect = get_tab_rect(i);
+ if (rect.has_point(p_point)) {
+ hover_now = i;
+ }
+ }
+
+ return hover_now;
+}
+
void Tabs::set_tab_align(TabAlign p_align) {
tab_align = p_align;
@@ -587,7 +699,7 @@ void Tabs::_ensure_no_over_offset() {
if (i < offset - 1)
continue;
- total_w += get_tab_width(i);
+ total_w += tabs[i].size_cache;
}
if (total_w < limit) {
@@ -604,37 +716,35 @@ void Tabs::ensure_tab_visible(int p_idx) {
if (!is_inside_tree())
return;
+ if (tabs.size() == 0) return;
ERR_FAIL_INDEX(p_idx, tabs.size());
- _ensure_no_over_offset();
-
- if (p_idx <= offset) {
+ if (p_idx == offset) {
+ return;
+ }
+ if (p_idx < offset) {
offset = p_idx;
update();
return;
}
+ int prev_offset = offset;
Ref<Texture> incr = get_icon("increment");
Ref<Texture> decr = get_icon("decrement");
int limit = get_size().width - incr->get_width() - decr->get_width();
-
- int x = 0;
- for (int i = 0; i < tabs.size(); i++) {
-
- if (i < offset)
- continue;
-
- int sz = get_tab_width(i);
- tabs[i].x_cache = x;
- tabs[i].x_size_cache = sz;
- x += sz;
+ for (int i = offset; i <= p_idx; i++) {
+ if (tabs[i].ofs_cache + tabs[i].size_cache > limit) {
+ offset++;
+ }
}
- while (offset < tabs.size() && ((tabs[p_idx].x_cache + tabs[p_idx].x_size_cache) - tabs[offset].x_cache) > limit) {
- offset++;
+ if (prev_offset != offset) {
+ update();
}
+}
- update();
+Rect2 Tabs::get_tab_rect(int p_tab) const {
+ return Rect2(tabs[p_tab].ofs_cache, 0, tabs[p_tab].size_cache, get_size().height);
}
void Tabs::set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy) {
@@ -642,6 +752,10 @@ void Tabs::set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy) {
update();
}
+void Tabs::set_min_width(int p_width) {
+ min_width = p_width;
+}
+
void Tabs::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &Tabs::_gui_input);
@@ -663,6 +777,8 @@ void Tabs::_bind_methods() {
ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("right_button_pressed", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("tab_close", PropertyInfo(Variant::INT, "tab")));
+ ADD_SIGNAL(MethodInfo("tab_hover", PropertyInfo(Variant::INT, "tab")));
+ ADD_SIGNAL(MethodInfo("reposition_active_tab_request", PropertyInfo(Variant::INT, "idx_to")));
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab");
@@ -688,4 +804,6 @@ Tabs::Tabs() {
cb_displaypolicy = CLOSE_BUTTON_SHOW_NEVER;
offset = 0;
max_drawn_tab = 0;
+
+ min_width = 0;
}
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 61b97d2dff..613c604b12 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -59,6 +59,7 @@ private:
int ofs_cache;
bool disabled;
int size_cache;
+ int size_text;
int x_cache;
int x_size_cache;
@@ -74,7 +75,6 @@ private:
bool missing_right;
Vector<Tab> tabs;
int current;
- Control *_get_tab(int idx) const;
int _get_top_margin() const;
TabAlign tab_align;
int rb_hover;
@@ -85,15 +85,22 @@ private:
CloseButtonDisplayPolicy cb_displaypolicy;
int hover; // hovered tab
+ int min_width;
int get_tab_width(int p_idx) const;
void _ensure_no_over_offset();
+ void _update_cache();
protected:
void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
static void _bind_methods();
+ Variant get_drag_data(const Point2 &p_point);
+ bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
+ void drop_data(const Point2 &p_point, const Variant &p_data);
+ int get_tab_idx_at_point(const Point2 &p_point) const;
+
public:
void add_tab(const String &p_str = "", const Ref<Texture> &p_icon = Ref<Texture>());
@@ -117,13 +124,16 @@ public:
int get_tab_count() const;
void set_current_tab(int p_current);
int get_current_tab() const;
+ int get_hovered_tab() const;
void remove_tab(int p_idx);
void clear_tabs();
void ensure_tab_visible(int p_idx);
+ void set_min_width(int p_width);
+ Rect2 get_tab_rect(int p_tab) const;
Size2 get_minimum_size() const;
Tabs();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 4989a3d863..936a9b77f8 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1069,16 +1069,16 @@ void TextEdit::_notification(int p_what) {
int th = h + csb->get_minimum_size().y;
if (cursor_pos.y + get_row_height() + th > get_size().height) {
- completion_rect.pos.y = cursor_pos.y - th;
+ completion_rect.position.y = cursor_pos.y - th;
} else {
- completion_rect.pos.y = cursor_pos.y + get_row_height() + csb->get_offset().y;
+ completion_rect.position.y = cursor_pos.y + get_row_height() + csb->get_offset().y;
completion_below = true;
}
if (cursor_pos.x - nofs + w + scrollw > get_size().width) {
- completion_rect.pos.x = get_size().width - w - scrollw;
+ completion_rect.position.x = get_size().width - w - scrollw;
} else {
- completion_rect.pos.x = cursor_pos.x - nofs;
+ completion_rect.position.x = cursor_pos.x - nofs;
}
completion_rect.size.width = w + 2;
@@ -1086,14 +1086,14 @@ void TextEdit::_notification(int p_what) {
if (completion_options.size() <= maxlines)
scrollw = 0;
- draw_style_box(csb, Rect2(completion_rect.pos - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
+ draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
if (cache.completion_background_color.a > 0.01) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.pos, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color);
}
int line_from = CLAMP(completion_index - lines / 2, 0, completion_options.size() - lines);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.pos.x, completion_rect.pos.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color);
- draw_rect(Rect2(completion_rect.pos, Size2(nofs, completion_rect.size.height)), cache.completion_existing_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color);
+ draw_rect(Rect2(completion_rect.position, Size2(nofs, completion_rect.size.height)), cache.completion_existing_color);
for (int i = 0; i < lines; i++) {
@@ -1105,14 +1105,14 @@ void TextEdit::_notification(int p_what) {
text_color = color_regions[j].color;
}
}
- draw_string(cache.font, Point2(completion_rect.pos.x, completion_rect.pos.y + i * get_row_height() + cache.font->get_ascent()), completion_options[l], text_color, completion_rect.size.width);
+ draw_string(cache.font, Point2(completion_rect.position.x, completion_rect.position.y + i * get_row_height() + cache.font->get_ascent()), completion_options[l], text_color, completion_rect.size.width);
}
if (scrollw) {
//draw a small scroll rectangle to show a position in the options
float r = maxlines / (float)completion_options.size();
float o = line_from / (float)completion_options.size();
- draw_rect(Rect2(completion_rect.pos.x + completion_rect.size.width, completion_rect.pos.y + o * completion_rect.size.y, scrollw, completion_rect.size.y * r), scrollc);
+ draw_rect(Rect2(completion_rect.position.x + completion_rect.size.width, completion_rect.position.y + o * completion_rect.size.y, scrollw, completion_rect.size.y * r), scrollc);
}
completion_line_ofs = line_from;
@@ -1445,7 +1445,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventMouseButton> mb = p_gui_input;
if (mb.is_valid()) {
- if (completion_active && completion_rect.has_point(mb->get_pos())) {
+ if (completion_active && completion_rect.has_point(mb->get_position())) {
if (!mb->is_pressed())
return;
@@ -1468,7 +1468,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb->get_button_index() == BUTTON_LEFT) {
- completion_index = CLAMP(completion_line_ofs + (mb->get_pos().y - completion_rect.pos.y) / get_row_height(), 0, completion_options.size() - 1);
+ completion_index = CLAMP(completion_line_ofs + (mb->get_position().y - completion_rect.position.y) / get_row_height(), 0, completion_options.size() - 1);
completion_current = completion_options[completion_index];
update();
@@ -1500,7 +1500,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_reset_caret_blink_timer();
int row, col;
- _get_mouse_pos(Point2i(mb->get_pos().x, mb->get_pos().y), row, col);
+ _get_mouse_pos(Point2i(mb->get_position().x, mb->get_position().y), row, col);
if (mb->get_command() && highlighted_word != String()) {
@@ -1511,7 +1511,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// toggle breakpoint on gutter click
if (draw_breakpoint_gutter) {
int gutter = cache.style_normal->get_margin(MARGIN_LEFT);
- if (mb->get_pos().x > gutter && mb->get_pos().x <= gutter + cache.breakpoint_gutter_width + 3) {
+ if (mb->get_position().x > gutter && mb->get_position().x <= gutter + cache.breakpoint_gutter_width + 3) {
set_line_as_breakpoint(row, !is_line_set_as_breakpoint(row));
emit_signal("breakpoint_toggled", row);
return;
@@ -1646,7 +1646,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (select_identifiers_enabled) {
if (mm->get_command() && mm->get_button_mask() == 0) {
- String new_word = get_word_at_pos(mm->get_pos());
+ String new_word = get_word_at_pos(mm->get_position());
if (new_word != highlighted_word) {
highlighted_word = new_word;
update();
@@ -1666,7 +1666,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_reset_caret_blink_timer();
int row, col;
- _get_mouse_pos(mm->get_pos(), row, col);
+ _get_mouse_pos(mm->get_position(), row, col);
select(selection.selecting_line, selection.selecting_column, row, col);
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index b17192fe4f..d8788b4eca 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -610,6 +610,52 @@ Color TreeItem::get_custom_bg_color(int p_column) const {
return cells[p_column].bg_color;
}
+void TreeItem::set_custom_as_button(int p_column, bool p_button) {
+
+ ERR_FAIL_INDEX(p_column, cells.size());
+ cells[p_column].custom_button = p_button;
+}
+
+bool TreeItem::is_custom_set_as_button(int p_column) const {
+
+ ERR_FAIL_INDEX_V(p_column, cells.size(), false);
+ return cells[p_column].custom_button;
+}
+
+void TreeItem::set_text_align(int p_column, TextAlign p_align) {
+ ERR_FAIL_INDEX(p_column, cells.size());
+ cells[p_column].text_align = p_align;
+ _changed_notify(p_column);
+}
+
+TreeItem::TextAlign TreeItem::get_text_align(int p_column) const {
+ ERR_FAIL_INDEX_V(p_column, cells.size(), ALIGN_LEFT);
+ return cells[p_column].text_align;
+}
+
+void TreeItem::set_expand_right(int p_column, bool p_enable) {
+
+ ERR_FAIL_INDEX(p_column, cells.size());
+ cells[p_column].expand_right = p_enable;
+ _changed_notify(p_column);
+}
+
+bool TreeItem::get_expand_right(int p_column) const {
+
+ ERR_FAIL_INDEX_V(p_column, cells.size(), false);
+ return cells[p_column].expand_right;
+}
+
+void TreeItem::set_disable_folding(bool p_disable) {
+
+ disable_folding = p_disable;
+ _changed_notify(0);
+}
+
+bool TreeItem::is_folding_disabled() const {
+ return disable_folding;
+}
+
void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_cell_mode", "column", "mode"), &TreeItem::set_cell_mode);
@@ -670,6 +716,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color);
ClassDB::bind_method(D_METHOD("get_custom_bg_color", "column"), &TreeItem::get_custom_bg_color);
+ ClassDB::bind_method(D_METHOD("set_custom_as_button", "column", "enable"), &TreeItem::set_custom_as_button);
+ ClassDB::bind_method(D_METHOD("is_custom_set_as_button", "column"), &TreeItem::is_custom_set_as_button);
+
ClassDB::bind_method(D_METHOD("add_button", "column", "button:Texture", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count);
ClassDB::bind_method(D_METHOD("get_button:Texture", "column", "button_idx"), &TreeItem::get_button);
@@ -677,12 +726,19 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("erase_button", "column", "button_idx"), &TreeItem::erase_button);
ClassDB::bind_method(D_METHOD("is_button_disabled", "column", "button_idx"), &TreeItem::is_button_disabled);
+ ClassDB::bind_method(D_METHOD("set_expand_right", "column", "enable"), &TreeItem::set_expand_right);
+ ClassDB::bind_method(D_METHOD("get_expand_right", "column"), &TreeItem::get_expand_right);
+
ClassDB::bind_method(D_METHOD("set_tooltip", "column", "tooltip"), &TreeItem::set_tooltip);
ClassDB::bind_method(D_METHOD("get_tooltip", "column"), &TreeItem::get_tooltip);
-
+ ClassDB::bind_method(D_METHOD("set_text_align", "column", "text_align"), &TreeItem::set_text_align);
+ ClassDB::bind_method(D_METHOD("get_text_align", "column"), &TreeItem::get_text_align);
ClassDB::bind_method(D_METHOD("move_to_top"), &TreeItem::move_to_top);
ClassDB::bind_method(D_METHOD("move_to_bottom"), &TreeItem::move_to_bottom);
+ 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);
@@ -709,6 +765,7 @@ TreeItem::TreeItem(Tree *p_tree) {
tree = p_tree;
collapsed = false;
+ disable_folding = false;
parent = 0; // parent item
next = 0; // next in list
@@ -732,6 +789,10 @@ TreeItem::~TreeItem() {
tree->pressing_for_editor = false;
}
+ if (tree && tree->cache.hover_item == this) {
+ tree->cache.hover_item = NULL;
+ }
+
if (tree && tree->selected_item == this)
tree->selected_item = NULL;
@@ -772,6 +833,11 @@ void Tree::update_cache() {
cache.select_arrow = get_icon("select_arrow");
cache.updown = get_icon("updown");
+ cache.custom_button = get_stylebox("custom_button");
+ cache.custom_button_hover = get_stylebox("custom_button_hover");
+ cache.custom_button_pressed = get_stylebox("custom_button_pressed");
+ cache.custom_button_font_highlight = get_color("custom_button_font_highlight");
+
cache.font_color = get_color("font_color");
cache.font_color_selected = get_color("font_color_selected");
cache.guide_color = get_color("guide_color");
@@ -833,6 +899,9 @@ int Tree::compute_item_height(TreeItem *p_item) const {
if (s.height > height)
height = s.height;
}
+ if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) {
+ height += cache.custom_button->get_minimum_size().height;
+ }
} break;
default: {}
@@ -867,6 +936,32 @@ int Tree::get_item_height(TreeItem *p_item) const {
void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color) {
Rect2i rect = p_rect;
+ Ref<Font> font = cache.font;
+ String text = p_cell.text;
+ if (p_cell.suffix != String())
+ text += " " + p_cell.suffix;
+
+ int w = 0;
+ if (!p_cell.icon.is_null()) {
+ Size2i bmsize = p_cell.get_icon_size();
+
+ if (p_cell.icon_max_w > 0 && bmsize.width > p_cell.icon_max_w) {
+ bmsize.width = p_cell.icon_max_w;
+ }
+ w += bmsize.width + cache.hseparation;
+ }
+ w += font->get_string_size(text).width;
+
+ switch (p_cell.text_align) {
+ case TreeItem::ALIGN_LEFT:
+ break; //do none
+ case TreeItem::ALIGN_CENTER:
+ rect.position.x = MAX(0, (rect.size.width - w) / 2);
+ break; //do none
+ case TreeItem::ALIGN_RIGHT:
+ rect.position.x = MAX(0, (rect.size.width - w));
+ break; //do none
+ }
RID ci = get_canvas_item();
if (!p_cell.icon.is_null()) {
@@ -877,8 +972,8 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
bmsize.width = p_cell.icon_max_w;
}
- p_cell.draw_icon(ci, rect.pos + Size2i(0, Math::floor((real_t)(rect.size.y - bmsize.y) / 2)), bmsize);
- rect.pos.x += bmsize.x + cache.hseparation;
+ p_cell.draw_icon(ci, rect.position + Size2i(0, Math::floor((real_t)(rect.size.y - bmsize.y) / 2)), bmsize);
+ rect.position.x += bmsize.x + cache.hseparation;
rect.size.x -= bmsize.x + cache.hseparation;
}
@@ -887,14 +982,8 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
rect.size.x-=Math::floor(rect.size.y/2);
*/
- Ref<Font> font = cache.font;
-
- String text = p_cell.text;
- if (p_cell.suffix != String())
- text += " " + p_cell.suffix;
-
- rect.pos.y += Math::floor((rect.size.y - font->get_height()) / 2.0) + font->get_ascent();
- font->draw(ci, rect.pos, text, p_color, rect.size.x);
+ 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
@@ -943,20 +1032,6 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (!skip && (p_pos.y + label_h - cache.offset.y) > 0) {
- if (!hide_folding && p_item->childs) { //has childs, draw the guide box
-
- Ref<Texture> arrow;
-
- if (p_item->collapsed) {
-
- arrow = cache.arrow_collapsed;
- } else {
- arrow = cache.arrow;
- }
-
- arrow->draw(ci, p_pos + p_draw_ofs + Point2i(0, (label_h - arrow->get_height()) / 2) - cache.offset);
- }
-
//draw separation.
//if (p_item->get_parent()!=root || !hide_root)
@@ -964,9 +1039,15 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int font_ascent = font->get_ascent();
- int ofs = p_pos.x + (hide_folding ? cache.hseparation : cache.item_margin);
+ int ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
+ int skip = 0;
for (int i = 0; i < columns.size(); i++) {
+ if (skip) {
+ skip--;
+ continue;
+ }
+
int w = get_column_width(i);
if (i == 0) {
@@ -984,6 +1065,16 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
w -= cache.hseparation;
}
+ if (p_item->cells[i].expand_right) {
+
+ int plus = 1;
+ while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) {
+ w += get_column_width(i + plus);
+ plus++;
+ skip++;
+ }
+ }
+
int bw = 0;
for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) {
Ref<Texture> b = p_item->cells[i].buttons[j].texture;
@@ -1007,16 +1098,16 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Rect2i item_rect = Rect2i(Point2i(ofs, p_pos.y) - cache.offset + p_draw_ofs, Size2i(w, label_h));
Rect2i cell_rect = item_rect;
if (i != 0) {
- cell_rect.pos.x -= cache.hseparation;
+ cell_rect.position.x -= cache.hseparation;
cell_rect.size.x += cache.hseparation;
}
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.pos.x, cell_rect.pos.y + cell_rect.size.height), cell_rect.pos + cell_rect.size, cache.guide_color, 1);
+ VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(cell_rect.position.x, cell_rect.position.y + cell_rect.size.height), cell_rect.position + cell_rect.size, cache.guide_color, 1);
if (i == 0) {
if (p_item->cells[0].selected && select_mode == SELECT_ROW) {
- Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.pos.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y));
+ Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.position.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y));
//Rect2 r = Rect2i(row_rect.pos,row_rect.size);
//r.grow(cache.selected->get_margin(MARGIN_LEFT));
if (has_focus())
@@ -1028,34 +1119,39 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (p_item->cells[i].selected && select_mode != SELECT_ROW) {
- Rect2i r(item_rect.pos, item_rect.size);
+ Rect2i r(item_rect.position, item_rect.size);
if (p_item->cells[i].text.size() > 0) {
float icon_width = p_item->cells[i].get_icon_size().width;
- r.pos.x += icon_width;
+ r.position.x += icon_width;
r.size.x -= icon_width;
}
//r.grow(cache.selected->get_margin(MARGIN_LEFT));
if (has_focus()) {
cache.selected_focus->draw(ci, r);
- p_item->set_meta("__focus_rect", Rect2(r.pos, r.size));
+ p_item->set_meta("__focus_rect", Rect2(r.position, r.size));
} else {
cache.selected->draw(ci, r);
}
if (text_editor->is_visible_in_tree()) {
- text_editor->set_position(get_global_position() + r.pos);
+ text_editor->set_position(get_global_position() + r.position);
}
}
if (p_item->cells[i].custom_bg_color) {
Rect2 r = cell_rect;
- r.pos.x -= cache.hseparation;
- r.size.x += cache.hseparation;
+ if (i == 0) {
+ r.position.x = p_draw_ofs.x;
+ r.size.x = w + ofs;
+ } else {
+ r.position.x -= cache.hseparation;
+ r.size.x += cache.hseparation;
+ }
if (p_item->cells[i].custom_bg_outline) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, r.size.x, 1), p_item->cells[i].bg_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, 1, r.size.y), p_item->cells[i].bg_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x + r.size.x - 1, r.pos.y, 1, r.size.y), p_item->cells[i].bg_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), p_item->cells[i].bg_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y - 1, r.size.x, 1), p_item->cells[i].bg_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), p_item->cells[i].bg_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), p_item->cells[i].bg_color);
} else {
VisualServer::get_singleton()->canvas_item_add_rect(ci, r, p_item->cells[i].bg_color);
}
@@ -1066,22 +1162,22 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Rect2 r = cell_rect;
if (drop_mode_section == -1 || drop_mode_section == 0) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, r.size.x, 1), cache.drop_position_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color);
}
if (drop_mode_section == 0) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y, 1, r.size.y), cache.drop_position_color);
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x + r.size.x - 1, r.pos.y, 1, r.size.y), cache.drop_position_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color);
}
if (drop_mode_section == 1 || drop_mode_section == 0) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.pos.x, r.pos.y + r.size.y, r.size.x, 1), cache.drop_position_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color);
}
}
Color col = p_item->cells[i].custom_color ? p_item->cells[i].color : get_color(p_item->cells[i].selected ? "font_color_selected" : "font_color");
- Point2i text_pos = item_rect.pos;
+ Point2i text_pos = item_rect.position;
text_pos.y += Math::floor((item_rect.size.y - font->get_height()) / 2) + font_ascent;
switch (p_item->cells[i].mode) {
@@ -1094,7 +1190,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Ref<Texture> checked = cache.checked;
Ref<Texture> unchecked = cache.unchecked;
- Point2i check_ofs = item_rect.pos;
+ Point2i check_ofs = item_rect.position;
check_ofs.y += Math::floor((real_t)(item_rect.size.y - checked->get_height()) / 2);
if (p_item->cells[i].checked) {
@@ -1109,7 +1205,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
text_pos.x += check_w;
item_rect.size.x -= check_w;
- item_rect.pos.x += check_w;
+ item_rect.position.x += check_w;
draw_item_rect(p_item->cells[i], item_rect, col);
@@ -1137,7 +1233,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
font->draw(ci, text_pos, s, col, item_rect.size.x - downarrow->get_width());
//?
- Point2i arrow_pos = item_rect.pos;
+ Point2i arrow_pos = item_rect.position;
arrow_pos.x += item_rect.size.x - downarrow->get_width();
arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0);
@@ -1157,7 +1253,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (!p_item->cells[i].editable)
break;
- Point2i updown_pos = item_rect.pos;
+ Point2i updown_pos = item_rect.position;
updown_pos.x += item_rect.size.x - updown->get_width();
updown_pos.y += Math::floor(((item_rect.size.y - updown->get_height())) / 2.0);
@@ -1176,7 +1272,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
Point2i icon_ofs = (item_rect.size - icon_size) / 2;
- icon_ofs += item_rect.pos;
+ icon_ofs += item_rect.position;
draw_texture_rect(p_item->cells[i].icon, Rect2(icon_ofs, icon_size));
//p_item->cells[i].icon->draw(ci, icon_ofs);
@@ -1202,12 +1298,28 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
Ref<Texture> downarrow = cache.select_arrow;
Rect2i ir = item_rect;
- ir.size.width -= downarrow->get_width();
- draw_item_rect(p_item->cells[i], ir, col);
- Point2i arrow_pos = item_rect.pos;
+ Point2i arrow_pos = item_rect.position;
arrow_pos.x += item_rect.size.x - downarrow->get_width();
arrow_pos.y += Math::floor(((item_rect.size.y - downarrow->get_height())) / 2.0);
+ ir.size.width -= downarrow->get_width();
+
+ if (p_item->cells[i].custom_button) {
+ if (cache.hover_item == p_item && cache.hover_cell == i) {
+ if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
+ draw_style_box(cache.custom_button_pressed, ir);
+ } else {
+ draw_style_box(cache.custom_button_hover, ir);
+ col = cache.custom_button_font_highlight;
+ }
+ } else {
+ draw_style_box(cache.custom_button, ir);
+ }
+ ir.size -= cache.custom_button->get_minimum_size();
+ ir.position += cache.custom_button->get_offset();
+ }
+
+ draw_item_rect(p_item->cells[i], ir, col);
downarrow->draw(ci, arrow_pos);
@@ -1231,6 +1343,19 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
}
+ if (!p_item->disable_folding && !hide_folding && p_item->childs) { //has childs, draw the guide box
+
+ Ref<Texture> arrow;
+
+ if (p_item->collapsed) {
+
+ arrow = cache.arrow_collapsed;
+ } else {
+ arrow = cache.arrow;
+ }
+
+ arrow->draw(ci, p_pos + p_draw_ofs + Point2i(0, (label_h - arrow->get_height()) / 2) - cache.offset);
+ }
//separator
//get_painter()->draw_fill_rect( Point2i(0,pos.y),Size2i(get_size().width,1),color( COLOR_TREE_GRID) );
@@ -1252,8 +1377,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
while (c) {
if (cache.draw_relationship_lines == 1) {
- int root_ofs = children_pos.x + (hide_folding ? cache.hseparation : cache.item_margin);
- int parent_ofs = p_pos.x + (hide_folding ? cache.hseparation : cache.item_margin);
+ int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
+ int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs;
if (c->get_children() != NULL)
root_pos -= Point2i(cache.arrow->get_width(), 0);
@@ -1445,7 +1570,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
return -1;
}
- if (!hide_folding && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + cache.item_margin))) {
+ if (!p_item->disable_folding && !hide_folding && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + cache.item_margin))) {
if (p_item->childs)
p_item->set_collapsed(!p_item->is_collapsed());
@@ -1461,6 +1586,18 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
for (int i = 0; i < columns.size(); i++) {
col_width = get_column_width(i);
+
+ if (p_item->cells[i].expand_right) {
+
+ int plus = 1;
+ while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) {
+ plus++;
+ col_width += cache.hseparation;
+ col_width += get_column_width(i + plus);
+ plus++;
+ }
+ }
+
if (x > col_width) {
col_ofs += col_width;
x -= col_width;
@@ -1485,6 +1622,11 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
x -= cache.hseparation;
}
+ if (!p_item->disable_folding && !hide_folding && !p_item->cells[col].editable && !p_item->cells[col].selectable && p_item->get_children()) {
+ p_item->set_collapsed(!p_item->is_collapsed());
+ return -1; //collapse/uncollapse because nothing can be done with item
+ }
+
TreeItem::Cell &c = p_item->cells[col];
bool already_selected = c.selected;
@@ -1697,11 +1839,18 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
case TreeItem::CELL_MODE_CUSTOM: {
edited_item = p_item;
edited_col = col;
- custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h));
- emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2))));
+ bool on_arrow = x > col_width - cache.select_arrow->get_width();
bring_up_editor = false;
- item_edited(col, p_item);
+
+ if (on_arrow || !p_item->cells[col].custom_button) {
+ custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h));
+ emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2))));
+ }
+
+ if (!p_item->cells[col].custom_button || !on_arrow) {
+ item_edited(col, p_item);
+ }
click_handled = true;
return -1;
} break;
@@ -2122,7 +2271,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
Ref<StyleBox> bg = cache.bg;
- Point2 pos = mm->get_pos() - bg->get_offset();
+ Point2 pos = mm->get_position() - bg->get_offset();
Cache::ClickType old_hover = cache.hover_type;
int old_index = cache.hover_index;
@@ -2148,9 +2297,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
}
- if (drop_mode_flags && root) {
+ if (root) {
- Point2 mpos = mm->get_pos();
+ Point2 mpos = mm->get_position();
mpos -= cache.bg->get_offset();
mpos.y -= _get_title_button_height();
if (mpos.y >= 0) {
@@ -2163,11 +2312,17 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
int col, h, section;
TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
- if (it != drop_mode_over || section != drop_mode_section) {
+ if (drop_mode_flags && it != drop_mode_over || section != drop_mode_section) {
drop_mode_over = it;
drop_mode_section = section;
update();
}
+
+ if (it != cache.hover_item || col != cache.hover_cell) {
+ cache.hover_item = it;
+ cache.hover_cell = col;
+ update();
+ }
}
}
@@ -2180,7 +2335,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (!range_drag_enabled) {
- Vector2 cpos = mm->get_pos();
+ Vector2 cpos = mm->get_position();
if (cpos.distance_to(pressing_pos) > 2) {
range_drag_enabled = true;
range_drag_capture_pos = cpos;
@@ -2217,7 +2372,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (b->get_button_index() == BUTTON_LEFT) {
- Point2 pos = b->get_pos() - cache.bg->get_offset();
+ Point2 pos = b->get_position() - cache.bg->get_offset();
if (show_column_titles) {
pos.y -= _get_title_button_height();
@@ -2251,7 +2406,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
warp_mouse(range_drag_capture_pos);
} else {
Rect2 rect = get_selected()->get_meta("__focus_rect");
- if (rect.has_point(Point2(b->get_pos().x, b->get_pos().y))) {
+ if (rect.has_point(Point2(b->get_position().x, b->get_position().y))) {
edit_selected();
} else {
emit_signal("item_double_clicked");
@@ -2295,7 +2450,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
case BUTTON_LEFT: {
Ref<StyleBox> bg = cache.bg;
- Point2 pos = b->get_pos() - bg->get_offset();
+ Point2 pos = b->get_position() - bg->get_offset();
cache.click_type = Cache::CLICK_NONE;
if (show_column_titles && b->get_button_index() == BUTTON_LEFT) {
pos.y -= _get_title_button_height();
@@ -2333,7 +2488,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
blocked--;
if (pressing_for_editor) {
- pressing_pos = b->get_pos();
+ pressing_pos = b->get_position();
}
if (b->get_button_index() == BUTTON_RIGHT)
@@ -2401,7 +2556,7 @@ bool Tree::edit_selected() {
edited_item = s;
edited_col = col;
- custom_popup_rect = Rect2i(get_global_position() + rect.pos, rect.size);
+ custom_popup_rect = Rect2i(get_global_position() + rect.position, rect.size);
emit_signal("custom_popup_edited", false);
item_edited(col, s);
@@ -2416,7 +2571,7 @@ bool Tree::edit_selected() {
}
popup_menu->set_size(Size2(rect.size.width, 0));
- popup_menu->set_position(get_global_position() + rect.pos + Point2i(0, rect.size.height));
+ popup_menu->set_position(get_global_position() + rect.position + Point2i(0, rect.size.height));
popup_menu->popup();
popup_edited_item = s;
popup_edited_item_col = col;
@@ -2424,7 +2579,7 @@ bool Tree::edit_selected() {
} else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) {
- Point2i textedpos = get_global_position() + rect.pos;
+ Point2i textedpos = get_global_position() + rect.position;
text_editor->set_position(textedpos);
text_editor->set_size(rect.size);
text_editor->clear();
@@ -2671,7 +2826,7 @@ void Tree::_notification(int p_what) {
ofs += tbrect.size.width;
//text
int clip_w = tbrect.size.width - sb->get_minimum_size().width;
- f->draw_halign(ci, tbrect.pos + Point2i(sb->get_offset().x, (tbrect.size.height - f->get_height()) / 2 + f->get_ascent()), HALIGN_CENTER, clip_w, columns[i].title, cache.title_button_color);
+ f->draw_halign(ci, tbrect.position + Point2i(sb->get_offset().x, (tbrect.size.height - f->get_height()) / 2 + f->get_ascent()), HALIGN_CENTER, clip_w, columns[i].title, cache.title_button_color);
}
}
}
@@ -3053,11 +3208,11 @@ Rect2 Tree::get_item_rect(TreeItem *p_item, int p_column) const {
int ofs = get_item_offset(p_item);
int height = compute_item_height(p_item);
Rect2 r;
- r.pos.y = ofs;
+ r.position.y = ofs;
r.size.height = height;
if (p_column == -1) {
- r.pos.x = 0;
+ r.position.x = 0;
r.size.x = get_size().width;
} else {
@@ -3065,7 +3220,7 @@ Rect2 Tree::get_item_rect(TreeItem *p_item, int p_column) const {
for (int i = 0; i < p_column; i++) {
accum += get_column_width(i);
}
- r.pos.x = accum;
+ r.position.x = accum;
r.size.x = get_column_width(p_column);
}
@@ -3469,6 +3624,7 @@ void Tree::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos")));
ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "pos")));
ADD_SIGNAL(MethodInfo("item_edited"));
+ ADD_SIGNAL(MethodInfo("item_custom_button_pressed"));
ADD_SIGNAL(MethodInfo("item_double_clicked"));
ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item")));
//ADD_SIGNAL( MethodInfo("item_doubleclicked" ) );
@@ -3575,6 +3731,9 @@ Tree::Tree() {
force_edit_checkbox_only_on_checkbox = false;
set_clip_contents(true);
+
+ cache.hover_item = NULL;
+ cache.hover_cell = -1;
}
Tree::~Tree() {
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 0c07109e7d..59e35bb230 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -58,6 +58,12 @@ public:
CELL_MODE_CUSTOM, ///< Contains a custom value, show a string, and an edit button
};
+ enum TextAlign {
+ ALIGN_LEFT,
+ ALIGN_CENTER,
+ ALIGN_RIGHT
+ };
+
private:
friend class Tree;
@@ -81,6 +87,10 @@ private:
bool custom_bg_color;
bool custom_bg_outline;
Color bg_color;
+ bool custom_button;
+ bool expand_right;
+
+ TextAlign text_align;
Variant meta;
String tooltip;
@@ -107,6 +117,7 @@ private:
Cell() {
custom_draw_obj = 0;
+ custom_button = false;
mode = TreeItem::CELL_MODE_STRING;
min = 0;
max = 100;
@@ -120,6 +131,8 @@ private:
custom_bg_color = false;
expr = false;
icon_max_w = 0;
+ text_align = ALIGN_LEFT;
+ expand_right = false;
}
Size2 get_icon_size() const;
@@ -129,6 +142,7 @@ private:
Vector<Cell> cells;
bool collapsed; // wont show childs
+ bool disable_folding;
TreeItem *parent; // parent item
TreeItem *next; // next in list
@@ -238,18 +252,31 @@ public:
void clear_custom_bg_color(int p_column);
Color get_custom_bg_color(int p_column) const;
+ void set_custom_as_button(int p_column, bool p_button);
+ bool is_custom_set_as_button(int p_column) const;
+
void set_tooltip(int p_column, const String &p_tooltip);
String get_tooltip(int p_column) const;
void clear_children();
+ void set_text_align(int p_column, TextAlign p_align);
+ TextAlign get_text_align(int p_column) const;
+
+ void set_expand_right(int p_column, bool p_enable);
+ bool get_expand_right(int p_column) const;
+
void move_to_top();
void move_to_bottom();
+ void set_disable_folding(bool p_disable);
+ bool is_folding_disabled() const;
+
~TreeItem();
};
VARIANT_ENUM_CAST(TreeItem::TreeCellMode);
+VARIANT_ENUM_CAST(TreeItem::TextAlign);
class Tree : public Control {
@@ -369,6 +396,10 @@ private:
Ref<StyleBox> title_button;
Ref<StyleBox> title_button_hover;
Ref<StyleBox> title_button_pressed;
+ Ref<StyleBox> custom_button;
+ Ref<StyleBox> custom_button_hover;
+ Ref<StyleBox> custom_button_pressed;
+
Color title_button_color;
Ref<Texture> checked;
@@ -383,6 +414,7 @@ private:
Color guide_color;
Color drop_position_color;
Color relationship_line_color;
+ Color custom_button_font_highlight;
int hseparation;
int vseparation;
@@ -410,6 +442,9 @@ private:
int hover_index;
Point2 click_pos;
+ TreeItem *hover_item;
+ int hover_cell;
+
} cache;
int _get_title_button_height() const;