diff options
Diffstat (limited to 'scene/gui/control.cpp')
-rw-r--r-- | scene/gui/control.cpp | 144 |
1 files changed, 63 insertions, 81 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 349102fafb..fcdbdb4edb 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -370,80 +370,60 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const { void Control::_get_property_list(List<PropertyInfo> *p_list) const { ERR_MAIN_THREAD_GUARD; - Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme(); + List<ThemeDB::ThemeItemBind> theme_items; + ThemeDB::get_singleton()->get_class_items(get_class_name(), &theme_items, true); p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Theme Overrides", "theme_override_"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP)); - { - List<StringName> names; - default_theme->get_color_list(get_class_name(), &names); - for (const StringName &E : names) { - uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.theme_color_override.has(E)) { - usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; - } + for (const ThemeDB::ThemeItemBind &E : theme_items) { + uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - p_list->push_back(PropertyInfo(Variant::COLOR, PNAME("theme_override_colors") + String("/") + E, PROPERTY_HINT_NONE, "", usage)); - } - } - { - List<StringName> names; - default_theme->get_constant_list(get_class_name(), &names); - for (const StringName &E : names) { - uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.theme_constant_override.has(E)) { - usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; - } + switch (E.data_type) { + case Theme::DATA_TYPE_COLOR: { + if (data.theme_color_override.has(E.item_name)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + p_list->push_back(PropertyInfo(Variant::COLOR, PNAME("theme_override_colors") + String("/") + E.item_name, PROPERTY_HINT_NONE, "", usage)); + } break; - p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_constants") + String("/") + E, PROPERTY_HINT_RANGE, "-16384,16384", usage)); - } - } - { - List<StringName> names; - default_theme->get_font_list(get_class_name(), &names); - for (const StringName &E : names) { - uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.theme_font_override.has(E)) { - usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; - } + case Theme::DATA_TYPE_CONSTANT: { + if (data.theme_constant_override.has(E.item_name)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_constants") + String("/") + E.item_name, PROPERTY_HINT_RANGE, "-16384,16384", usage)); + } break; - p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_fonts") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage)); - } - } - { - List<StringName> names; - default_theme->get_font_size_list(get_class_name(), &names); - for (const StringName &E : names) { - uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.theme_font_size_override.has(E)) { - usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; - } + case Theme::DATA_TYPE_FONT: { + if (data.theme_font_override.has(E.item_name)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_fonts") + String("/") + E.item_name, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage)); + } break; - p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_font_sizes") + String("/") + E, PROPERTY_HINT_RANGE, "1,256,1,or_greater,suffix:px", usage)); - } - } - { - List<StringName> names; - default_theme->get_icon_list(get_class_name(), &names); - for (const StringName &E : names) { - uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.theme_icon_override.has(E)) { - usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; - } + case Theme::DATA_TYPE_FONT_SIZE: { + if (data.theme_font_size_override.has(E.item_name)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_font_sizes") + String("/") + E.item_name, PROPERTY_HINT_RANGE, "1,256,1,or_greater,suffix:px", usage)); + } break; - p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_icons") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage)); - } - } - { - List<StringName> names; - default_theme->get_stylebox_list(get_class_name(), &names); - for (const StringName &E : names) { - uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; - if (data.theme_style_override.has(E)) { - usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; - } + case Theme::DATA_TYPE_ICON: { + if (data.theme_icon_override.has(E.item_name)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_icons") + String("/") + E.item_name, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage)); + } break; - p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_styles") + String("/") + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage)); + case Theme::DATA_TYPE_STYLEBOX: { + if (data.theme_style_override.has(E.item_name)) { + usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; + } + p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_styles") + String("/") + E.item_name, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage)); + } break; + + default: { + // Silences warning. + } break; } } } @@ -1419,13 +1399,15 @@ void Control::_set_global_position(const Point2 &p_point) { void Control::set_global_position(const Point2 &p_point, bool p_keep_offsets) { ERR_MAIN_THREAD_GUARD; - Transform2D inv; - if (data.parent_canvas_item) { - inv = data.parent_canvas_item->get_global_transform().affine_inverse(); + Transform2D global_transform_cache = get_global_transform(); + if (p_point == global_transform_cache.get_origin()) { + return; // Edge case, but avoids calculation. } - set_position(inv.xform(p_point), p_keep_offsets); + Point2 internal_position = global_transform_cache.affine_inverse().xform(p_point); + + set_position(internal_position + data.pos_cache, p_keep_offsets); } Point2 Control::get_global_position() const { @@ -2548,7 +2530,7 @@ StringName Control::get_theme_type_variation() const { Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<Texture2D>()); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2572,7 +2554,7 @@ Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringNam Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<StyleBox>()); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2596,7 +2578,7 @@ Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const String Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<Font>()); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2620,7 +2602,7 @@ Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_ int Control::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(0); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2644,7 +2626,7 @@ int Control::get_theme_font_size(const StringName &p_name, const StringName &p_t Color Control::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Color()); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2668,7 +2650,7 @@ Color Control::get_theme_color(const StringName &p_name, const StringName &p_the int Control::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(0); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2719,7 +2701,7 @@ Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const { bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2736,7 +2718,7 @@ bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2753,7 +2735,7 @@ bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_t bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2770,7 +2752,7 @@ bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2787,7 +2769,7 @@ bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_ bool Control::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { @@ -2804,7 +2786,7 @@ bool Control::has_theme_color(const StringName &p_name, const StringName &p_them bool Control::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!data.initialized) { - WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |