diff options
Diffstat (limited to 'scene/gui/control.cpp')
-rw-r--r-- | scene/gui/control.cpp | 453 |
1 files changed, 166 insertions, 287 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index b710ba4803..96aaec6ae9 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -49,7 +49,6 @@ #ifdef TOOLS_ENABLED Dictionary Control::_edit_get_state() const { - Dictionary s; s["rotation"] = get_rotation(); s["scale"] = get_scale(); @@ -70,7 +69,6 @@ Dictionary Control::_edit_get_state() const { } void Control::_edit_set_state(const Dictionary &p_state) { - Dictionary state = p_state; set_rotation(state["rotation"]); @@ -162,37 +160,36 @@ Size2 Control::_edit_get_minimum_size() const { #endif void Control::set_custom_minimum_size(const Size2 &p_custom) { - - if (p_custom == data.custom_minimum_size) + if (p_custom == data.custom_minimum_size) { return; + } data.custom_minimum_size = p_custom; minimum_size_changed(); } Size2 Control::get_custom_minimum_size() const { - return data.custom_minimum_size; } void Control::_update_minimum_size_cache() { - Size2 minsize = get_minimum_size(); minsize.x = MAX(minsize.x, data.custom_minimum_size.x); minsize.y = MAX(minsize.y, data.custom_minimum_size.y); bool size_changed = false; - if (data.minimum_size_cache != minsize) + if (data.minimum_size_cache != minsize) { size_changed = true; + } data.minimum_size_cache = minsize; data.minimum_size_valid = true; - if (size_changed) + if (size_changed) { minimum_size_changed(); + } } Size2 Control::get_combined_minimum_size() const { - if (!data.minimum_size_valid) { const_cast<Control *>(this)->_update_minimum_size_cache(); } @@ -200,7 +197,6 @@ Size2 Control::get_combined_minimum_size() const { } Transform2D Control::_get_internal_transform() const { - Transform2D rot_scale; rot_scale.set_rotation_and_scale(data.rotation, data.scale); Transform2D offset; @@ -210,14 +206,12 @@ Transform2D Control::_get_internal_transform() const { } bool Control::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; if (!name.begins_with("custom")) { return false; } if (p_value.get_type() == Variant::NIL) { - if (name.begins_with("custom_icons/")) { String dname = name.get_slicec('/', 1); if (data.icon_override.has(dname)) { @@ -254,8 +248,9 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { String dname = name.get_slicec('/', 1); data.constant_override.erase(dname); notification(NOTIFICATION_THEME_CHANGED); - } else + } else { return false; + } } else { if (name.begins_with("custom_icons/")) { @@ -276,16 +271,17 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { } else if (name.begins_with("custom_constants/")) { String dname = name.get_slicec('/', 1); add_theme_constant_override(dname, p_value); - } else + } else { return false; + } } return true; } void Control::_update_minimum_size() { - - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } Size2 minsize = get_combined_minimum_size(); if (minsize.x > data.size_cache.x || @@ -302,7 +298,6 @@ void Control::_update_minimum_size() { } bool Control::_get(const StringName &p_name, Variant &r_ret) const { - String sname = p_name; if (!sname.begins_with("custom")) { @@ -332,13 +327,14 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const { String name = sname.get_slicec('/', 1); r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant(); - } else + } else { return false; + } return true; } -void Control::_get_property_list(List<PropertyInfo> *p_list) const { +void Control::_get_property_list(List<PropertyInfo> *p_list) const { Ref<Theme> theme = Theme::get_default(); /* Using the default theme since the properties below are meant for editor only if (data.theme.is_valid()) { @@ -353,10 +349,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; theme->get_icon_list(get_class_name(), &names); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.icon_override.has(E->get())) + if (data.icon_override.has(E->get())) { hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", hint)); } @@ -365,10 +361,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; theme->get_shader_list(get_class_name(), &names); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.shader_override.has(E->get())) + if (data.shader_override.has(E->get())) { hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Shader,VisualShader", hint)); } @@ -377,10 +373,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; theme->get_stylebox_list(get_class_name(), &names); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.style_override.has(E->get())) + if (data.style_override.has(E->get())) { hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", hint)); } @@ -389,10 +385,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; theme->get_font_list(get_class_name(), &names); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.font_override.has(E->get())) + if (data.font_override.has(E->get())) { hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", hint)); } @@ -401,10 +397,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; theme->get_color_list(get_class_name(), &names); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.color_override.has(E->get())) + if (data.color_override.has(E->get())) { hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", hint)); } @@ -413,10 +409,10 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { List<StringName> names; theme->get_constant_list(get_class_name(), &names); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.constant_override.has(E->get())) + if (data.constant_override.has(E->get())) { hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", hint)); } @@ -424,19 +420,16 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { } Control *Control::get_parent_control() const { - return data.parent; } void Control::_resize(const Size2 &p_size) { - _size_changed(); } //moved theme configuration here, so controls can set up even if still not inside active scene void Control::add_child_notify(Node *p_child) { - Control *child_c = Object::cast_to<Control>(p_child); if (child_c && child_c->data.theme.is_null() && (data.theme_owner || data.theme_owner_window)) { @@ -451,7 +444,6 @@ void Control::add_child_notify(Node *p_child) { } void Control::remove_child_notify(Node *p_child) { - Control *child_c = Object::cast_to<Control>(p_child); if (child_c && (child_c->data.theme_owner || child_c->data.theme_owner_window) && child_c->data.theme.is_null()) { @@ -466,7 +458,6 @@ void Control::remove_child_notify(Node *p_child) { } void Control::_update_canvas_item_transform() { - Transform2D xform = _get_internal_transform(); xform[2] += get_position(); @@ -474,24 +465,19 @@ void Control::_update_canvas_item_transform() { } void Control::_notification(int p_notification) { - switch (p_notification) { - case NOTIFICATION_ENTER_TREE: { - } break; case NOTIFICATION_POST_ENTER_TREE: { data.minimum_size_valid = false; _size_changed(); } break; case NOTIFICATION_EXIT_TREE: { - get_viewport()->_gui_remove_control(this); } break; case NOTIFICATION_ENTER_CANVAS: { - data.parent = Object::cast_to<Control>(get_parent()); Node *parent = this; //meh @@ -499,11 +485,11 @@ void Control::_notification(int p_notification) { bool subwindow = false; while (parent) { - parent = parent->get_parent(); - if (!parent) + if (!parent) { break; + } CanvasItem *ci = Object::cast_to<CanvasItem>(parent); if (ci && ci->is_set_as_toplevel()) { @@ -516,7 +502,6 @@ void Control::_notification(int p_notification) { if (parent_control) { break; } else if (ci) { - } else { break; } @@ -536,7 +521,6 @@ void Control::_notification(int p_notification) { data.parent_canvas_item = get_parent_item(); if (data.parent_canvas_item) { - data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); } else { //connect viewport @@ -544,9 +528,7 @@ void Control::_notification(int p_notification) { } } break; case NOTIFICATION_EXIT_CANVAS: { - if (data.parent_canvas_item) { - data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed)); data.parent_canvas_item = nullptr; } else if (!is_set_as_toplevel()) { @@ -566,8 +548,9 @@ void Control::_notification(int p_notification) { case NOTIFICATION_MOVED_IN_PARENT: { // some parents need to know the order of the childrens to draw (like TabContainer) // update if necessary - if (data.parent) + if (data.parent) { data.parent->update(); + } update(); if (data.RI) { @@ -576,11 +559,9 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_RESIZED: { - emit_signal(SceneStringNames::get_singleton()->resized); } break; case NOTIFICATION_DRAW: { - _update_canvas_item_transform(); RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size())); RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents); @@ -588,35 +569,29 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_MOUSE_ENTER: { - emit_signal(SceneStringNames::get_singleton()->mouse_entered); } break; case NOTIFICATION_MOUSE_EXIT: { - emit_signal(SceneStringNames::get_singleton()->mouse_exited); } break; case NOTIFICATION_FOCUS_ENTER: { - emit_signal(SceneStringNames::get_singleton()->focus_entered); update(); } break; case NOTIFICATION_FOCUS_EXIT: { - emit_signal(SceneStringNames::get_singleton()->focus_exited); update(); } break; case NOTIFICATION_THEME_CHANGED: { - minimum_size_changed(); update(); } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (!is_visible_in_tree()) { - - if (get_viewport() != nullptr) + if (get_viewport() != nullptr) { get_viewport()->_gui_hid_control(this); + } //remove key focus @@ -630,14 +605,13 @@ void Control::_notification(int p_notification) { } bool Control::clips_input() const { - if (get_script_instance()) { return get_script_instance()->call(SceneStringNames::get_singleton()->_clips_input); } return false; } -bool Control::has_point(const Point2 &p_point) const { +bool Control::has_point(const Point2 &p_point) const { if (get_script_instance()) { Variant v = p_point; const Variant *p = &v; @@ -655,15 +629,14 @@ bool Control::has_point(const Point2 &p_point) const { } void Control::set_drag_forwarding(Control *p_target) { - - if (p_target) + if (p_target) { data.drag_owner = p_target->get_instance_id(); - else + } else { data.drag_owner = ObjectID(); + } } Variant Control::get_drag_data(const Point2 &p_point) { - if (data.drag_owner.is_valid()) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { @@ -677,15 +650,15 @@ Variant Control::get_drag_data(const Point2 &p_point) { const Variant *p = &v; Callable::CallError ce; Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce); - if (ce.error == Callable::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) { return ret; + } } return Variant(); } bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const { - if (data.drag_owner.is_valid()) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { @@ -699,14 +672,15 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const const Variant *p[2] = { &v, &p_data }; Callable::CallError ce; Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce); - if (ce.error == Callable::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) { return ret; + } } return Variant(); } -void Control::drop_data(const Point2 &p_point, const Variant &p_data) { +void Control::drop_data(const Point2 &p_point, const Variant &p_data) { if (data.drag_owner.is_valid()) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { @@ -721,13 +695,13 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) { const Variant *p[2] = { &v, &p_data }; Callable::CallError ce; Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce); - if (ce.error == Callable::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) { return; + } } } void Control::force_drag(const Variant &p_data, Control *p_control) { - ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(p_data.get_type() == Variant::NIL); @@ -735,34 +709,30 @@ void Control::force_drag(const Variant &p_data, Control *p_control) { } void Control::set_drag_preview(Control *p_control) { - ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(!get_viewport()->gui_is_dragging()); get_viewport()->_gui_set_drag_preview(this, p_control); } Size2 Control::get_minimum_size() const { - ScriptInstance *si = const_cast<Control *>(this)->get_script_instance(); if (si) { - Callable::CallError ce; Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce); - if (ce.error == Callable::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) { return s; + } } return Size2(); } template <class T> bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, T &r_ret, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) { - // try with custom themes Control *theme_owner = p_theme_owner; Window *theme_owner_window = p_theme_owner_window; while (theme_owner || theme_owner_window) { - StringName class_name = p_type; while (class_name != StringName()) { @@ -792,7 +762,6 @@ bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_win theme_owner = parent_w->theme_owner; theme_owner_window = parent_w->theme_owner_window; } else { - theme_owner = nullptr; theme_owner_window = nullptr; } @@ -802,13 +771,11 @@ bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_win } bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) { - // try with custom themes Control *theme_owner = p_theme_owner; Window *theme_owner_window = p_theme_owner_window; while (theme_owner || theme_owner_window) { - StringName class_name = p_type; while (class_name != StringName()) { @@ -836,7 +803,6 @@ bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_wind theme_owner = parent_w->theme_owner; theme_owner_window = parent_w->theme_owner_window; } else { - theme_owner = nullptr; theme_owner_window = nullptr; } @@ -846,12 +812,11 @@ bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_wind } Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); - if (tex) + if (tex) { return *tex; + } } StringName type = p_type ? p_type : get_class_name(); @@ -860,7 +825,6 @@ Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringNam } Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Ref<Texture2D> icon; if (_find_theme_item(p_theme_owner, p_theme_owner_window, icon, &Theme::get_icon, &Theme::has_icon, p_name, p_type)) { @@ -877,12 +841,11 @@ Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_ } Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - const Ref<Shader> *sdr = data.shader_override.getptr(p_name); - if (sdr) + if (sdr) { return *sdr; + } } StringName type = p_type ? p_type : get_class_name(); @@ -891,7 +854,6 @@ Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName } Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Ref<Shader> shader; if (_find_theme_item(p_theme_owner, p_theme_owner_window, shader, &Theme::get_shader, &Theme::has_shader, p_name, p_type)) { @@ -908,11 +870,11 @@ Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_w } Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { const Ref<StyleBox> *style = data.style_override.getptr(p_name); - if (style) + if (style) { return *style; + } } StringName type = p_type ? p_type : get_class_name(); @@ -921,7 +883,6 @@ Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const String } Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Ref<StyleBox> stylebox; if (_find_theme_item(p_theme_owner, p_theme_owner_window, stylebox, &Theme::get_stylebox, &Theme::has_stylebox, p_name, p_type)) { @@ -938,11 +899,11 @@ Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_own } Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { const Ref<Font> *font = data.font_override.getptr(p_name); - if (font) + if (font) { return *font; + } } StringName type = p_type ? p_type : get_class_name(); @@ -951,7 +912,6 @@ Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_ } Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Ref<Font> font; if (_find_theme_item(p_theme_owner, p_theme_owner_window, font, &Theme::get_font, &Theme::has_font, p_name, p_type)) { @@ -968,11 +928,11 @@ Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_windo } Color Control::get_theme_color(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { const Color *color = data.color_override.getptr(p_name); - if (color) + if (color) { return *color; + } } StringName type = p_type ? p_type : get_class_name(); @@ -981,7 +941,6 @@ Color Control::get_theme_color(const StringName &p_name, const StringName &p_typ } Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - Color color; if (_find_theme_item(p_theme_owner, p_theme_owner_window, color, &Theme::get_color, &Theme::has_color, p_name, p_type)) { @@ -997,11 +956,11 @@ Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window, } int Control::get_theme_constant(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { const int *constant = data.constant_override.getptr(p_name); - if (constant) + if (constant) { return *constant; + } } StringName type = p_type ? p_type : get_class_name(); @@ -1010,7 +969,6 @@ int Control::get_theme_constant(const StringName &p_name, const StringName &p_ty } int Control::get_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - int constant; if (_find_theme_item(p_theme_owner, p_theme_owner_window, constant, &Theme::get_constant, &Theme::has_constant, p_name, p_type)) { @@ -1026,46 +984,40 @@ int Control::get_constants(Control *p_theme_owner, Window *p_theme_owner_window, } bool Control::has_theme_icon_override(const StringName &p_name) const { - const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); return tex != nullptr; } bool Control::has_theme_shader_override(const StringName &p_name) const { - const Ref<Shader> *sdr = data.shader_override.getptr(p_name); return sdr != nullptr; } bool Control::has_theme_stylebox_override(const StringName &p_name) const { - const Ref<StyleBox> *style = data.style_override.getptr(p_name); return style != nullptr; } bool Control::has_theme_font_override(const StringName &p_name) const { - const Ref<Font> *font = data.font_override.getptr(p_name); return font != nullptr; } bool Control::has_theme_color_override(const StringName &p_name) const { - const Color *color = data.color_override.getptr(p_name); return color != nullptr; } bool Control::has_theme_constant_override(const StringName &p_name) const { - const int *constant = data.constant_override.getptr(p_name); return constant != nullptr; } bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - if (has_theme_icon_override(p_name)) + if (has_theme_icon_override(p_name)) { return true; + } } StringName type = p_type ? p_type : get_class_name(); @@ -1074,7 +1026,6 @@ bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type) } bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_icon, p_name, p_type)) { return true; } @@ -1088,18 +1039,18 @@ bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, co } bool Control::has_theme_shader(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - if (has_theme_shader_override(p_name)) + if (has_theme_shader_override(p_name)) { return true; + } } StringName type = p_type ? p_type : get_class_name(); return has_shaders(data.theme_owner, data.theme_owner_window, p_name, type); } -bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { +bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_shader, p_name, p_type)) { return true; } @@ -1113,10 +1064,10 @@ bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, } bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - if (has_theme_stylebox_override(p_name)) + if (has_theme_stylebox_override(p_name)) { return true; + } } StringName type = p_type ? p_type : get_class_name(); @@ -1125,7 +1076,6 @@ bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_t } bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_stylebox, p_name, p_type)) { return true; } @@ -1139,18 +1089,18 @@ bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window } bool Control::has_theme_font(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - if (has_theme_font_override(p_name)) + if (has_theme_font_override(p_name)) { return true; + } } StringName type = p_type ? p_type : get_class_name(); return has_fonts(data.theme_owner, data.theme_owner_window, p_name, type); } -bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { +bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_font, p_name, p_type)) { return true; } @@ -1164,18 +1114,18 @@ bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, co } bool Control::has_theme_color(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - if (has_theme_color_override(p_name)) + if (has_theme_color_override(p_name)) { return true; + } } StringName type = p_type ? p_type : get_class_name(); return has_colors(data.theme_owner, data.theme_owner_window, p_name, type); } -bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { +bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_color, p_name, p_type)) { return true; } @@ -1189,10 +1139,10 @@ bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, c } bool Control::has_theme_constant(const StringName &p_name, const StringName &p_type) const { - if (p_type == StringName() || p_type == get_class_name()) { - if (has_theme_constant_override(p_name)) + if (has_theme_constant_override(p_name)) { return true; + } } StringName type = p_type ? p_type : get_class_name(); @@ -1201,7 +1151,6 @@ bool Control::has_theme_constant(const StringName &p_name, const StringName &p_t } bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { - if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_constant, p_name, p_type)) { return true; } @@ -1215,8 +1164,9 @@ bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window } Rect2 Control::get_parent_anchorable_rect() const { - if (!is_inside_tree()) + if (!is_inside_tree()) { return Rect2(); + } Rect2 parent_rect; if (data.parent_canvas_item) { @@ -1229,18 +1179,15 @@ Rect2 Control::get_parent_anchorable_rect() const { } Size2 Control::get_parent_area_size() const { - return get_parent_anchorable_rect().size; } void Control::_size_changed() { - Rect2 parent_rect = get_parent_anchorable_rect(); float margin_pos[4]; for (int i = 0; i < 4; i++) { - float area = parent_rect.size[i & 1]; margin_pos[i] = data.margin[i] + (data.anchor[i] * area); } @@ -1293,7 +1240,6 @@ void Control::_size_changed() { } void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bool p_push_opposite_anchor) { - ERR_FAIL_INDEX((int)p_margin, 4); Rect2 parent_rect = get_parent_anchorable_rect(); @@ -1334,13 +1280,11 @@ void Control::_set_anchor(Margin p_margin, float p_anchor) { } void Control::set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor) { - set_anchor(p_margin, p_anchor, false, p_push_opposite_anchor); set_margin(p_margin, p_pos); } void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margins) { - ERR_FAIL_INDEX((int)p_preset, 16); //Left @@ -1457,7 +1401,6 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margins) { } void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) { - ERR_FAIL_INDEX((int)p_preset, 16); ERR_FAIL_INDEX((int)p_resize_mode, 4); @@ -1594,14 +1537,12 @@ void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPreset } float Control::get_anchor(Margin p_margin) const { - ERR_FAIL_INDEX_V(int(p_margin), 4, 0.0); return data.anchor[p_margin]; } void Control::_change_notify_margins() { - // this avoids sending the whole object data again on a change _change_notify("margin_left"); _change_notify("margin_top"); @@ -1612,7 +1553,6 @@ void Control::_change_notify_margins() { } void Control::set_margin(Margin p_margin, float p_value) { - ERR_FAIL_INDEX((int)p_margin, 4); data.margin[p_margin] = p_value; @@ -1620,37 +1560,32 @@ void Control::set_margin(Margin p_margin, float p_value) { } void Control::set_begin(const Size2 &p_point) { - data.margin[0] = p_point.x; data.margin[1] = p_point.y; _size_changed(); } void Control::set_end(const Size2 &p_point) { - data.margin[2] = p_point.x; data.margin[3] = p_point.y; _size_changed(); } float Control::get_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0); return data.margin[p_margin]; } Size2 Control::get_begin() const { - return Size2(data.margin[0], data.margin[1]); } -Size2 Control::get_end() const { +Size2 Control::get_end() const { return Size2(data.margin[2], data.margin[3]); } Point2 Control::get_global_position() const { - return get_global_transform().get_origin(); } @@ -1670,11 +1605,9 @@ void Control::_set_global_position(const Point2 &p_point) { } void Control::set_global_position(const Point2 &p_point, bool p_keep_margins) { - Transform2D inv; if (data.parent_canvas_item) { - inv = data.parent_canvas_item->get_global_transform().affine_inverse(); } @@ -1682,7 +1615,6 @@ void Control::set_global_position(const Point2 &p_point, bool p_keep_margins) { } void Control::_compute_anchors(Rect2 p_rect, const float p_margins[4], float (&r_anchors)[4]) { - Size2 parent_rect_size = get_parent_anchorable_rect().size; ERR_FAIL_COND(parent_rect_size.x == 0.0); ERR_FAIL_COND(parent_rect_size.y == 0.0); @@ -1694,7 +1626,6 @@ void Control::_compute_anchors(Rect2 p_rect, const float p_margins[4], float (&r } void Control::_compute_margins(Rect2 p_rect, const float p_anchors[4], float (&r_margins)[4]) { - Size2 parent_rect_size = get_parent_anchorable_rect().size; r_margins[0] = p_rect.position.x - (p_anchors[0] * parent_rect_size.x); r_margins[1] = p_rect.position.y - (p_anchors[1] * parent_rect_size.y); @@ -1724,13 +1655,14 @@ void Control::_set_size(const Size2 &p_size) { } void Control::set_size(const Size2 &p_size, bool p_keep_margins) { - Size2 new_size = p_size; Size2 min = get_combined_minimum_size(); - if (new_size.x < min.x) + if (new_size.x < min.x) { new_size.x = min.x; - if (new_size.y < min.y) + } + if (new_size.y < min.y) { new_size.y = min.y; + } if (p_keep_margins) { _compute_anchors(Rect2(data.pos_cache, new_size), data.margin, data.anchor); @@ -1745,22 +1677,18 @@ void Control::set_size(const Size2 &p_size, bool p_keep_margins) { } Size2 Control::get_position() const { - return data.pos_cache; } Size2 Control::get_size() const { - return data.size_cache; } Rect2 Control::get_global_rect() const { - return Rect2(get_global_position(), get_size()); } Rect2 Control::get_screen_rect() const { - ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); Rect2 r(get_global_position(), get_size()); @@ -1781,17 +1709,14 @@ Rect2 Control::get_window_rect() const { } Rect2 Control::get_rect() const { - return Rect2(get_position(), get_size()); } Rect2 Control::get_anchorable_rect() const { - return Rect2(Point2(), get_size()); } void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { - if (data.icon_override.has(p_name)) { data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } @@ -1809,7 +1734,6 @@ void Control::add_theme_icon_override(const StringName &p_name, const Ref<Textur } void Control::add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { - if (data.shader_override.has(p_name)) { data.shader_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } @@ -1825,8 +1749,8 @@ void Control::add_theme_shader_override(const StringName &p_name, const Ref<Shad } notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { +void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { if (data.style_override.has(p_name)) { data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } @@ -1844,7 +1768,6 @@ void Control::add_theme_style_override(const StringName &p_name, const Ref<Style } void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) { - if (data.font_override.has(p_name)) { data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } @@ -1860,46 +1783,45 @@ void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> } notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) { +void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) { data.color_override[p_name] = p_color; notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_theme_constant_override(const StringName &p_name, int p_constant) { +void Control::add_theme_constant_override(const StringName &p_name, int p_constant) { data.constant_override[p_name] = p_constant; notification(NOTIFICATION_THEME_CHANGED); } void Control::set_focus_mode(FocusMode p_focus_mode) { - ERR_FAIL_INDEX((int)p_focus_mode, 3); - if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) + if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) { release_focus(); + } data.focus_mode = p_focus_mode; } static Control *_next_control(Control *p_from) { - - if (p_from->is_set_as_toplevel()) + if (p_from->is_set_as_toplevel()) { return nullptr; // can't go above + } Control *parent = Object::cast_to<Control>(p_from->get_parent()); if (!parent) { - return nullptr; } int next = p_from->get_index(); ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr); for (int i = (next + 1); i < parent->get_child_count(); i++) { - Control *c = Object::cast_to<Control>(parent->get_child(i)); - if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) + if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) { continue; + } return c; } @@ -1909,11 +1831,9 @@ static Control *_next_control(Control *p_from) { } Control *Control::find_next_valid_focus() const { - Control *from = const_cast<Control *>(this); while (true) { - // If the focus property is manually overwritten, attempt to use it. if (!data.focus_next.is_empty()) { @@ -1925,8 +1845,9 @@ Control *Control::find_next_valid_focus() const { } else { return nullptr; } - if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) + if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) { return c; + } } // find next child @@ -1934,7 +1855,6 @@ Control *Control::find_next_valid_focus() const { Control *next_child = nullptr; for (int i = 0; i < from->get_child_count(); i++) { - Control *c = Object::cast_to<Control>(from->get_child(i)); if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) { continue; @@ -1945,56 +1865,56 @@ Control *Control::find_next_valid_focus() const { } if (!next_child) { - next_child = _next_control(from); if (!next_child) { //nothing else.. go up and find either window or subwindow next_child = const_cast<Control *>(this); while (next_child && !next_child->is_set_as_toplevel()) { - next_child = cast_to<Control>(next_child->get_parent()); } if (!next_child) { - next_child = const_cast<Control *>(this); while (next_child) { - - if (next_child->data.RI) + if (next_child->data.RI) { break; + } next_child = next_child->get_parent_control(); } } } } - if (next_child == this) // no next control-> + if (next_child == this) { // no next control-> return (get_focus_mode() == FOCUS_ALL) ? next_child : nullptr; + } if (next_child) { - if (next_child->get_focus_mode() == FOCUS_ALL) + if (next_child->get_focus_mode() == FOCUS_ALL) { return next_child; + } from = next_child; - } else + } else { break; + } } return nullptr; } static Control *_prev_control(Control *p_from) { - Control *child = nullptr; for (int i = p_from->get_child_count() - 1; i >= 0; i--) { - Control *c = Object::cast_to<Control>(p_from->get_child(i)); - if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) + if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) { continue; + } child = c; break; } - if (!child) + if (!child) { return p_from; + } //no prev in parent, try the same in parent return _prev_control(child); @@ -2004,7 +1924,6 @@ Control *Control::find_prev_valid_focus() const { Control *from = const_cast<Control *>(this); while (true) { - // If the focus property is manually overwritten, attempt to use it. if (!data.focus_prev.is_empty()) { @@ -2016,8 +1935,9 @@ Control *Control::find_prev_valid_focus() const { } else { return nullptr; } - if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) + if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) { return c; + } } // find prev child @@ -2025,15 +1945,12 @@ Control *Control::find_prev_valid_focus() const { Control *prev_child = nullptr; if (from->is_set_as_toplevel() || !Object::cast_to<Control>(from->get_parent())) { - //find last of the children prev_child = _prev_control(from); } else { - for (int i = (from->get_index() - 1); i >= 0; i--) { - Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i)); if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) { @@ -2045,19 +1962,19 @@ Control *Control::find_prev_valid_focus() const { } if (!prev_child) { - prev_child = Object::cast_to<Control>(from->get_parent()); } else { - prev_child = _prev_control(prev_child); } } - if (prev_child == this) // no prev control-> + if (prev_child == this) { // no prev control-> return (get_focus_mode() == FOCUS_ALL) ? prev_child : nullptr; + } - if (prev_child->get_focus_mode() == FOCUS_ALL) + if (prev_child->get_focus_mode() == FOCUS_ALL) { return prev_child; + } from = prev_child; } @@ -2066,16 +1983,14 @@ Control *Control::find_prev_valid_focus() const { } Control::FocusMode Control::get_focus_mode() const { - return data.focus_mode; } -bool Control::has_focus() const { +bool Control::has_focus() const { return is_inside_tree() && get_viewport()->_gui_control_has_focus(this); } void Control::grab_focus() { - ERR_FAIL_COND(!is_inside_tree()); if (data.focus_mode == FOCUS_NONE) { @@ -2087,40 +2002,38 @@ void Control::grab_focus() { } void Control::release_focus() { - ERR_FAIL_COND(!is_inside_tree()); - if (!has_focus()) + if (!has_focus()) { return; + } get_viewport()->_gui_remove_focus(); update(); } bool Control::is_toplevel_control() const { - return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel()); } void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign) { - Control *c = Object::cast_to<Control>(p_at); - if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated + if (c && c != p_owner && c->data.theme.is_valid()) { // has a theme, this can't be propagated return; + } Window *w = c == nullptr ? Object::cast_to<Window>(p_at) : nullptr; - if (w && w != p_owner_window && w->theme.is_valid()) // has a theme, this can't be propagated + if (w && w != p_owner_window && w->theme.is_valid()) { // has a theme, this can't be propagated return; + } for (int i = 0; i < p_at->get_child_count(); i++) { - CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i)); if (child) { _propagate_theme_changed(child, p_owner, p_owner_window, p_assign); } else { - Window *window = Object::cast_to<Window>(p_at->get_child(i)); if (window) { _propagate_theme_changed(window, p_owner, p_owner_window, p_assign); @@ -2129,7 +2042,6 @@ void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_o } if (c) { - if (p_assign) { c->data.theme_owner = p_owner; c->data.theme_owner_window = p_owner_window; @@ -2139,7 +2051,6 @@ void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_o } if (w) { - if (p_assign) { w->theme_owner = p_owner; w->theme_owner_window = p_owner_window; @@ -2150,14 +2061,13 @@ void Control::_propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_o } void Control::_theme_changed() { - _propagate_theme_changed(this, this, nullptr, false); } void Control::set_theme(const Ref<Theme> &p_theme) { - - if (data.theme == p_theme) + if (data.theme == p_theme) { return; + } if (data.theme.is_valid()) { data.theme->disconnect("changed", callable_mp(this, &Control::_theme_changed)); @@ -2165,12 +2075,10 @@ void Control::set_theme(const Ref<Theme> &p_theme) { data.theme = p_theme; if (!p_theme.is_null()) { - data.theme_owner = this; data.theme_owner_window = nullptr; _propagate_theme_changed(this, this, nullptr); } else { - Control *parent_c = Object::cast_to<Control>(get_parent()); if (parent_c && (parent_c->data.theme_owner || parent_c->data.theme_owner_window)) { @@ -2191,26 +2099,24 @@ void Control::set_theme(const Ref<Theme> &p_theme) { } void Control::accept_event() { - - if (is_inside_tree()) + if (is_inside_tree()) { get_viewport()->_gui_accept_event(); + } } Ref<Theme> Control::get_theme() const { - return data.theme; } void Control::set_tooltip(const String &p_tooltip) { - data.tooltip = p_tooltip; update_configuration_warning(); } String Control::get_tooltip(const Point2 &p_pos) const { - return data.tooltip; } + Control *Control::make_custom_tooltip(const String &p_text) const { if (get_script_instance()) { return const_cast<Control *>(this)->call("_make_custom_tooltip", p_text); @@ -2219,75 +2125,64 @@ Control *Control::make_custom_tooltip(const String &p_text) const { } void Control::set_default_cursor_shape(CursorShape p_shape) { - ERR_FAIL_INDEX(int(p_shape), CURSOR_MAX); data.default_cursor = p_shape; } Control::CursorShape Control::get_default_cursor_shape() const { - return data.default_cursor; } -Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const { +Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const { return data.default_cursor; } Transform2D Control::get_transform() const { - Transform2D xform = _get_internal_transform(); xform[2] += get_position(); return xform; } String Control::_get_tooltip() const { - return data.tooltip; } void Control::set_focus_neighbour(Margin p_margin, const NodePath &p_neighbour) { - ERR_FAIL_INDEX((int)p_margin, 4); data.focus_neighbour[p_margin] = p_neighbour; } NodePath Control::get_focus_neighbour(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, NodePath()); return data.focus_neighbour[p_margin]; } void Control::set_focus_next(const NodePath &p_next) { - data.focus_next = p_next; } NodePath Control::get_focus_next() const { - return data.focus_next; } void Control::set_focus_previous(const NodePath &p_prev) { - data.focus_prev = p_prev; } NodePath Control::get_focus_previous() const { - return data.focus_prev; } #define MAX_NEIGHBOUR_SEARCH_COUNT 512 Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { - ERR_FAIL_INDEX_V((int)p_margin, 4, nullptr); - if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT) + if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT) { return nullptr; + } if (!data.focus_neighbour[p_margin].is_empty()) { - Control *c = nullptr; Node *n = get_node(data.focus_neighbour[p_margin]); if (n) { @@ -2297,12 +2192,15 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { return nullptr; } bool valid = true; - if (!c->is_visible()) + if (!c->is_visible()) { valid = false; - if (c->get_focus_mode() == FOCUS_NONE) + } + if (c->get_focus_mode() == FOCUS_NONE) { valid = false; - if (valid) + } + if (valid) { return c; + } c = c->_get_focus_neighbour(p_margin, p_count + 1); return c; @@ -2332,26 +2230,27 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { float maxd = -1e7; for (int i = 0; i < 4; i++) { - float d = vdir.dot(points[i]); - if (d > maxd) + if (d > maxd) { maxd = d; + } } Node *base = this; while (base) { - Control *c = Object::cast_to<Control>(base); if (c) { - if (c->data.RI) + if (c->data.RI) { break; + } } base = base->get_parent(); } - if (!base) + if (!base) { return nullptr; + } _window_find_focus_neighbour(vdir, base, points, maxd, dist, &result); @@ -2359,14 +2258,13 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) { } void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, float p_min, float &r_closest_dist, Control **r_closest) { - - if (Object::cast_to<Viewport>(p_at)) + if (Object::cast_to<Viewport>(p_at)) { return; //bye + } Control *c = Object::cast_to<Control>(p_at); if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) { - Point2 points[4]; Transform2D xform = c->get_global_transform(); @@ -2379,21 +2277,18 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con float min = 1e7; for (int i = 0; i < 4; i++) { - float d = p_dir.dot(points[i]); - if (d < min) + if (d < min) { min = d; + } } if (min > (p_min - CMP_EPSILON)) { - for (int i = 0; i < 4; i++) { - Vector2 la = p_points[i]; Vector2 lb = p_points[(i + 1) % 4]; for (int j = 0; j < 4; j++) { - Vector2 fa = points[j]; Vector2 fb = points[(j + 1) % 4]; @@ -2410,19 +2305,19 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con } for (int i = 0; i < p_at->get_child_count(); i++) { - Node *child = p_at->get_child(i); Control *childc = Object::cast_to<Control>(child); - if (childc && childc->data.RI) + if (childc && childc->data.RI) { continue; //subwindow, ignore + } _window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest); } } void Control::set_h_size_flags(int p_flags) { - - if (data.h_size_flags == p_flags) + if (data.h_size_flags == p_flags) { return; + } data.h_size_flags = p_flags; emit_signal(SceneStringNames::get_singleton()->size_flags_changed); } @@ -2430,47 +2325,47 @@ void Control::set_h_size_flags(int p_flags) { int Control::get_h_size_flags() const { return data.h_size_flags; } -void Control::set_v_size_flags(int p_flags) { - if (data.v_size_flags == p_flags) +void Control::set_v_size_flags(int p_flags) { + if (data.v_size_flags == p_flags) { return; + } data.v_size_flags = p_flags; emit_signal(SceneStringNames::get_singleton()->size_flags_changed); } void Control::set_stretch_ratio(float p_ratio) { - - if (data.expand == p_ratio) + if (data.expand == p_ratio) { return; + } data.expand = p_ratio; emit_signal(SceneStringNames::get_singleton()->size_flags_changed); } float Control::get_stretch_ratio() const { - return data.expand; } void Control::grab_click_focus() { - ERR_FAIL_COND(!is_inside_tree()); get_viewport()->_gui_grab_click_focus(this); } void Control::minimum_size_changed() { - - if (!is_inside_tree() || data.block_minimum_size_adjust) + if (!is_inside_tree() || data.block_minimum_size_adjust) { return; + } Control *invalidate = this; //invalidate cache upwards while (invalidate && invalidate->data.minimum_size_valid) { invalidate->data.minimum_size_valid = false; - if (invalidate->is_set_as_toplevel()) + if (invalidate->is_set_as_toplevel()) { break; // do not go further up + } if (!invalidate->data.parent && get_parent()) { Window *parent_window = Object::cast_to<Window>(get_parent()); if (parent_window && parent_window->is_wrapping_controls()) { @@ -2480,11 +2375,13 @@ void Control::minimum_size_changed() { invalidate = invalidate->data.parent; } - if (!is_visible_in_tree()) + if (!is_visible_in_tree()) { return; + } - if (data.updating_last_minimum_size) + if (data.updating_last_minimum_size) { return; + } data.updating_last_minimum_size = true; @@ -2496,19 +2393,16 @@ int Control::get_v_size_flags() const { } void Control::set_mouse_filter(MouseFilter p_filter) { - ERR_FAIL_INDEX(p_filter, 3); data.mouse_filter = p_filter; update_configuration_warning(); } Control::MouseFilter Control::get_mouse_filter() const { - return data.mouse_filter; } Control *Control::get_focus_owner() const { - ERR_FAIL_COND_V(!is_inside_tree(), nullptr); return get_viewport()->_gui_get_focus_owner(); } @@ -2533,7 +2427,6 @@ bool Control::is_text_field() const { } void Control::set_rotation(float p_radians) { - data.rotation = p_radians; update(); _notify_transform(); @@ -2541,7 +2434,6 @@ void Control::set_rotation(float p_radians) { } float Control::get_rotation() const { - return data.rotation; } @@ -2554,14 +2446,12 @@ float Control::get_rotation_degrees() const { } void Control::_override_changed() { - notification(NOTIFICATION_THEME_CHANGED); emit_signal(SceneStringNames::get_singleton()->theme_changed); minimum_size_changed(); // overrides are likely to affect minimum size } void Control::set_pivot_offset(const Vector2 &p_pivot) { - data.pivot_offset = p_pivot; update(); _notify_transform(); @@ -2569,39 +2459,38 @@ void Control::set_pivot_offset(const Vector2 &p_pivot) { } Vector2 Control::get_pivot_offset() const { - return data.pivot_offset; } void Control::set_scale(const Vector2 &p_scale) { - data.scale = p_scale; // Avoid having 0 scale values, can lead to errors in physics and rendering. - if (data.scale.x == 0) + if (data.scale.x == 0) { data.scale.x = CMP_EPSILON; - if (data.scale.y == 0) + } + if (data.scale.y == 0) { data.scale.y = CMP_EPSILON; + } update(); _notify_transform(); } -Vector2 Control::get_scale() const { +Vector2 Control::get_scale() const { return data.scale; } Control *Control::get_root_parent_control() const { - const CanvasItem *ci = this; const Control *root = this; while (ci) { - const Control *c = Object::cast_to<Control>(ci); if (c) { root = c; - if (c->data.RI || c->is_toplevel_control()) + if (c->data.RI || c->is_toplevel_control()) { break; + } } ci = ci->get_parent_item(); @@ -2615,23 +2504,19 @@ void Control::set_block_minimum_size_adjust(bool p_block) { } bool Control::is_minimum_size_adjust_blocked() const { - return data.block_minimum_size_adjust; } void Control::set_disable_visibility_clip(bool p_ignore) { - data.disable_visibility_clip = p_ignore; update(); } bool Control::is_visibility_clip_disabled() const { - return data.disable_visibility_clip; } void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { - #ifdef TOOLS_ENABLED const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; #else @@ -2674,18 +2559,15 @@ String Control::get_configuration_warning() const { } void Control::set_clip_contents(bool p_clip) { - data.clip_contents = p_clip; update(); } bool Control::is_clipping_contents() { - return data.clip_contents; } void Control::set_h_grow_direction(GrowDirection p_direction) { - ERR_FAIL_INDEX((int)p_direction, 3); data.h_grow = p_direction; @@ -2693,24 +2575,21 @@ void Control::set_h_grow_direction(GrowDirection p_direction) { } Control::GrowDirection Control::get_h_grow_direction() const { - return data.h_grow; } void Control::set_v_grow_direction(GrowDirection p_direction) { - ERR_FAIL_INDEX((int)p_direction, 3); data.v_grow = p_direction; _size_changed(); } -Control::GrowDirection Control::get_v_grow_direction() const { +Control::GrowDirection Control::get_v_grow_direction() const { return data.v_grow; } void Control::_bind_methods() { - //ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event); ClassDB::bind_method(D_METHOD("_update_minimum_size"), &Control::_update_minimum_size); @@ -2983,8 +2862,8 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point"))); } -Control::Control() { +Control::Control() { data.parent = nullptr; data.mouse_filter = MOUSE_FILTER_STOP; |