| 1 | /**************************************************************************/ |
| 2 | /* control.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "control.h" |
| 32 | #include "control.compat.inc" |
| 33 | |
| 34 | #include "container.h" |
| 35 | #include "core/config/project_settings.h" |
| 36 | #include "core/input/input_map.h" |
| 37 | #include "core/os/os.h" |
| 38 | #include "core/string/string_builder.h" |
| 39 | #include "scene/gui/scroll_container.h" |
| 40 | #include "scene/main/canvas_layer.h" |
| 41 | #include "scene/main/window.h" |
| 42 | #include "scene/theme/theme_db.h" |
| 43 | #include "scene/theme/theme_owner.h" |
| 44 | #include "servers/rendering/rendering_server.h" |
| 45 | #include "servers/text/text_server.h" |
| 46 | |
| 47 | #ifdef TOOLS_ENABLED |
| 48 | #include "editor/scene/gui/control_editor_plugin.h" |
| 49 | #endif // TOOLS_ENABLED |
| 50 | |
| 51 | // Editor plugin interoperability. |
| 52 | |
| 53 | // TODO: Decouple controls from their editor plugin and get rid of this. |
| 54 | #ifdef TOOLS_ENABLED |
| 55 | Dictionary Control::_edit_get_state() const { |
| 56 | Dictionary s; |
| 57 | s["rotation"] = get_rotation(); |
| 58 | s["scale"] = get_scale(); |
| 59 | s["pivot"] = get_pivot_offset(); |
| 60 | s["pivot_ratio"] = get_pivot_offset_ratio(); |
| 61 | |
| 62 | Array anchors = { get_anchor(SIDE_LEFT), get_anchor(SIDE_TOP), get_anchor(SIDE_RIGHT), get_anchor(SIDE_BOTTOM) }; |
| 63 | s["anchors"] = anchors; |
| 64 | |
| 65 | Array offsets = { get_offset(SIDE_LEFT), get_offset(SIDE_TOP), get_offset(SIDE_RIGHT), get_offset(SIDE_BOTTOM) }; |
| 66 | s["offsets"] = offsets; |
| 67 | |
| 68 | s["layout_mode"] = _get_layout_mode(); |
| 69 | s["anchors_layout_preset"] = _get_anchors_layout_preset(); |
| 70 | |
| 71 | return s; |
| 72 | } |
| 73 | |
| 74 | void Control::_edit_set_state(const Dictionary &p_state) { |
| 75 | ERR_FAIL_COND(p_state.is_empty() || |
| 76 | !p_state.has("rotation") || !p_state.has("scale") || |
| 77 | !p_state.has("pivot") || !p_state.has("pivot_ratio") || !p_state.has("anchors") || !p_state.has("offsets") || |
| 78 | !p_state.has("layout_mode") || !p_state.has("anchors_layout_preset")); |
| 79 | Dictionary state = p_state; |
| 80 | |
| 81 | set_rotation(state["rotation"]); |
| 82 | set_scale(state["scale"]); |
| 83 | set_pivot_offset(state["pivot"]); |
| 84 | set_pivot_offset_ratio(state["pivot_ratio"]); |
| 85 | |
| 86 | Array anchors = state["anchors"]; |
| 87 | |
| 88 | // If anchors are not in their default position, force the anchor layout mode in place of position. |
| 89 | LayoutMode _layout = (LayoutMode)(int)state["layout_mode"]; |
| 90 | if (_layout == LayoutMode::LAYOUT_MODE_POSITION) { |
| 91 | bool anchors_mode = ((real_t)anchors[0] != 0.0 || (real_t)anchors[1] != 0.0 || (real_t)anchors[2] != 0.0 || (real_t)anchors[3] != 0.0); |
| 92 | if (anchors_mode) { |
| 93 | _layout = LayoutMode::LAYOUT_MODE_ANCHORS; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | _set_layout_mode(_layout); |
| 98 | if (_layout == LayoutMode::LAYOUT_MODE_ANCHORS || _layout == LayoutMode::LAYOUT_MODE_UNCONTROLLED) { |
| 99 | _set_anchors_layout_preset((int)state["anchors_layout_preset"]); |
| 100 | } |
| 101 | |
| 102 | data.anchor[SIDE_LEFT] = anchors[0]; |
| 103 | data.anchor[SIDE_TOP] = anchors[1]; |
| 104 | data.anchor[SIDE_RIGHT] = anchors[2]; |
| 105 | data.anchor[SIDE_BOTTOM] = anchors[3]; |
| 106 | |
| 107 | Array offsets = state["offsets"]; |
| 108 | data.offset[SIDE_LEFT] = offsets[0]; |
| 109 | data.offset[SIDE_TOP] = offsets[1]; |
| 110 | data.offset[SIDE_RIGHT] = offsets[2]; |
| 111 | data.offset[SIDE_BOTTOM] = offsets[3]; |
| 112 | |
| 113 | _size_changed(); |
| 114 | } |
| 115 | |
| 116 | void Control::_edit_set_position(const Point2 &p_position) { |
| 117 | ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins."); |
| 118 | set_position(p_position, ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled() && get_parent_control()); |
| 119 | } |
| 120 | |
| 121 | Point2 Control::_edit_get_position() const { |
| 122 | return get_position(); |
| 123 | } |
| 124 | |
| 125 | void Control::_edit_set_scale(const Size2 &p_scale) { |
| 126 | set_scale(p_scale); |
| 127 | } |
| 128 | |
| 129 | Size2 Control::_edit_get_scale() const { |
| 130 | return data.scale; |
| 131 | } |
| 132 | |
| 133 | void Control::_edit_set_rect(const Rect2 &p_edit_rect) { |
| 134 | ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins."); |
| 135 | // Changing the size might change the internal transform (in case of non-zero `pivot_offset_ratio`), |
| 136 | // hence `position` (which is in the parent space, and is not always equivalent to the Control's rect top-left corner) |
| 137 | // needs to be changed after `size` (which is local) and needs to account for the possibly changed internal transform. |
| 138 | Vector2 rect_new_pos_in_parent_space = get_transform().xform(p_edit_rect.position); |
| 139 | set_size(p_edit_rect.size, ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled()); |
| 140 | set_position(rect_new_pos_in_parent_space - _get_internal_transform().get_origin(), ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled()); |
| 141 | } |
| 142 | |
| 143 | void Control::_edit_set_rotation(real_t p_rotation) { |
| 144 | set_rotation(p_rotation); |
| 145 | } |
| 146 | |
| 147 | real_t Control::_edit_get_rotation() const { |
| 148 | return get_rotation(); |
| 149 | } |
| 150 | |
| 151 | bool Control::_edit_use_rotation() const { |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | void Control::_edit_set_pivot(const Point2 &p_pivot) { |
| 156 | Vector2 delta_pivot = p_pivot - get_pivot_offset(); |
| 157 | Vector2 move = Vector2((std::cos(data.rotation) - 1.0) * delta_pivot.x - std::sin(data.rotation) * delta_pivot.y, std::sin(data.rotation) * delta_pivot.x + (std::cos(data.rotation) - 1.0) * delta_pivot.y); |
| 158 | set_position(get_position() + move); |
| 159 | set_pivot_offset(p_pivot); |
| 160 | set_pivot_offset_ratio(Vector2()); |
| 161 | } |
| 162 | |
| 163 | Point2 Control::_edit_get_pivot() const { |
| 164 | return get_combined_pivot_offset(); |
| 165 | } |
| 166 | |
| 167 | bool Control::_edit_use_pivot() const { |
| 168 | return true; |
| 169 | } |
| 170 | |
| 171 | Size2 Control::_edit_get_minimum_size() const { |
| 172 | return get_combined_minimum_size(); |
| 173 | } |
| 174 | #endif // TOOLS_ENABLED |
| 175 | |
| 176 | #ifdef DEBUG_ENABLED |
| 177 | Rect2 Control::_edit_get_rect() const { |
| 178 | return Rect2(Point2(), get_size()); |
| 179 | } |
| 180 | |
| 181 | bool Control::_edit_use_rect() const { |
| 182 | return true; |
| 183 | } |
| 184 | #endif // DEBUG_ENABLED |
| 185 | |
| 186 | void Control::reparent(RequiredParam<Node> p_parent, bool p_keep_global_transform) { |
| 187 | ERR_MAIN_THREAD_GUARD; |
| 188 | if (p_keep_global_transform) { |
| 189 | Transform2D temp = get_global_transform(); |
| 190 | Node::reparent(p_parent); |
| 191 | set_global_position(temp.get_origin()); |
| 192 | } else { |
| 193 | Node::reparent(p_parent); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Editor integration. |
| 198 | |
| 199 | int Control::root_layout_direction = 0; |
| 200 | |
| 201 | void Control::set_root_layout_direction(int p_root_dir) { |
| 202 | root_layout_direction = p_root_dir; |
| 203 | } |
| 204 | |
| 205 | #ifdef TOOLS_ENABLED |
| 206 | void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { |
| 207 | ERR_READ_THREAD_GUARD; |
| 208 | if (p_idx == 0) { |
| 209 | const String pf = p_function; |
| 210 | Theme::DataType type = Theme::DATA_TYPE_MAX; |
| 211 | |
| 212 | if (pf == "add_theme_color_override" || pf == "has_theme_color" || pf == "has_theme_color_override" || pf == "get_theme_color" || pf == "remove_theme_color_override") { |
| 213 | type = Theme::DATA_TYPE_COLOR; |
| 214 | } else if (pf == "add_theme_constant_override" || pf == "has_theme_constant" || pf == "has_theme_constant_override" || pf == "get_theme_constant" || pf == "remove_theme_constant_override") { |
| 215 | type = Theme::DATA_TYPE_CONSTANT; |
| 216 | } else if (pf == "add_theme_font_override" || pf == "has_theme_font" || pf == "has_theme_font_override" || pf == "get_theme_font" || pf == "remove_theme_font_override") { |
| 217 | type = Theme::DATA_TYPE_FONT; |
| 218 | } else if (pf == "add_theme_font_size_override" || pf == "has_theme_font_size" || pf == "has_theme_font_size_override" || pf == "get_theme_font_size" || pf == "remove_theme_font_size_override") { |
| 219 | type = Theme::DATA_TYPE_FONT_SIZE; |
| 220 | } else if (pf == "add_theme_icon_override" || pf == "has_theme_icon" || pf == "has_theme_icon_override" || pf == "get_theme_icon" || pf == "remove_theme_icon_override") { |
| 221 | type = Theme::DATA_TYPE_ICON; |
| 222 | } else if (pf == "add_theme_stylebox_override" || pf == "has_theme_stylebox" || pf == "has_theme_stylebox_override" || pf == "get_theme_stylebox" || pf == "remove_theme_stylebox_override") { |
| 223 | type = Theme::DATA_TYPE_STYLEBOX; |
| 224 | } |
| 225 | |
| 226 | if (type != Theme::DATA_TYPE_MAX) { |
| 227 | List<ThemeDB::ThemeItemBind> theme_items; |
| 228 | ThemeDB::get_singleton()->get_class_items(get_class_name(), &theme_items, true, type); |
| 229 | |
| 230 | List<StringName> sn; |
| 231 | for (const ThemeDB::ThemeItemBind &E : theme_items) { |
| 232 | if (E.data_type == type) { |
| 233 | sn.push_back(E.item_name); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | sn.sort_custom<StringName::AlphCompare>(); |
| 238 | for (const StringName &name : sn) { |
| 239 | r_options->push_back(String(name).quote()); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | CanvasItem::get_argument_options(p_function, p_idx, r_options); |
| 244 | } |
| 245 | #endif // TOOLS_ENABLED |
| 246 | |
| 247 | PackedStringArray Control::get_configuration_warnings() const { |
| 248 | ERR_READ_THREAD_GUARD_V(PackedStringArray()); |
| 249 | PackedStringArray warnings = CanvasItem::get_configuration_warnings(); |
| 250 | |
| 251 | if (data.mouse_filter == MOUSE_FILTER_IGNORE && !data.tooltip.is_empty()) { |
| 252 | warnings.push_back(RTR("The Hint Tooltip won't be displayed as the control's Mouse Filter is set to \"Ignore\". To solve this, set the Mouse Filter to \"Stop\" or \"Pass\".")); |
| 253 | } |
| 254 | |
| 255 | return warnings; |
| 256 | } |
| 257 | |
| 258 | PackedStringArray Control::get_accessibility_configuration_warnings() const { |
| 259 | ERR_READ_THREAD_GUARD_V(PackedStringArray()); |
| 260 | PackedStringArray warnings = Node::get_accessibility_configuration_warnings(); |
| 261 | |
| 262 | String ac_name = get_accessibility_name().strip_edges(); |
| 263 | if (ac_name.is_empty()) { |
| 264 | warnings.push_back(RTR("Accessibility Name must not be empty, or contain only spaces.")); |
| 265 | } |
| 266 | if (ac_name.contains(get_class_name())) { |
| 267 | warnings.push_back(RTR("Accessibility Name must not include Node class name.")); |
| 268 | } |
| 269 | for (int i = 0; i < ac_name.length(); i++) { |
| 270 | if (is_control(ac_name[i])) { |
| 271 | warnings.push_back(RTR("Accessibility Name must not include control character.")); |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | return warnings; |
| 277 | } |
| 278 | |
| 279 | bool Control::is_text_field() const { |
| 280 | ERR_READ_THREAD_GUARD_V(false); |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | // Dynamic properties. |
| 285 | |
| 286 | String Control::properties_managed_by_container[] = { |
| 287 | "offset_left", |
| 288 | "offset_top", |
| 289 | "offset_right", |
| 290 | "offset_bottom", |
| 291 | "anchor_left", |
| 292 | "anchor_top", |
| 293 | "anchor_right", |
| 294 | "anchor_bottom", |
| 295 | "position", |
| 296 | "rotation", |
| 297 | "scale", |
| 298 | "size" |
| 299 | }; |
| 300 | |
| 301 | bool Control::_set(const StringName &p_name, const Variant &p_value) { |
| 302 | ERR_MAIN_THREAD_GUARD_V(false); |
| 303 | String name = p_name; |
| 304 | |
| 305 | if (!name.begins_with("theme_override")) { |
| 306 | return false; |
| 307 | } |
| 308 | |
| 309 | if (p_value.get_type() == Variant::NIL || (p_value.get_type() == Variant::OBJECT && (Object *)p_value == nullptr)) { |
| 310 | if (name.begins_with("theme_override_icons/")) { |
| 311 | String dname = name.get_slicec('/', 1); |
| 312 | if (data.theme_icon_override.has(dname)) { |
| 313 | data.theme_icon_override[dname]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 314 | } |
| 315 | data.theme_icon_override.erase(dname); |
| 316 | _notify_theme_override_changed(); |
| 317 | } else if (name.begins_with("theme_override_styles/")) { |
| 318 | String dname = name.get_slicec('/', 1); |
| 319 | if (data.theme_style_override.has(dname)) { |
| 320 | data.theme_style_override[dname]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 321 | } |
| 322 | data.theme_style_override.erase(dname); |
| 323 | _notify_theme_override_changed(); |
| 324 | } else if (name.begins_with("theme_override_fonts/")) { |
| 325 | String dname = name.get_slicec('/', 1); |
| 326 | if (data.theme_font_override.has(dname)) { |
| 327 | data.theme_font_override[dname]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 328 | } |
| 329 | data.theme_font_override.erase(dname); |
| 330 | _notify_theme_override_changed(); |
| 331 | } else if (name.begins_with("theme_override_font_sizes/")) { |
| 332 | String dname = name.get_slicec('/', 1); |
| 333 | data.theme_font_size_override.erase(dname); |
| 334 | _notify_theme_override_changed(); |
| 335 | } else if (name.begins_with("theme_override_colors/")) { |
| 336 | String dname = name.get_slicec('/', 1); |
| 337 | data.theme_color_override.erase(dname); |
| 338 | _notify_theme_override_changed(); |
| 339 | } else if (name.begins_with("theme_override_constants/")) { |
| 340 | String dname = name.get_slicec('/', 1); |
| 341 | data.theme_constant_override.erase(dname); |
| 342 | _notify_theme_override_changed(); |
| 343 | } else { |
| 344 | return false; |
| 345 | } |
| 346 | } else { |
| 347 | if (name.begins_with("theme_override_icons/")) { |
| 348 | String dname = name.get_slicec('/', 1); |
| 349 | add_theme_icon_override(dname, p_value); |
| 350 | } else if (name.begins_with("theme_override_styles/")) { |
| 351 | String dname = name.get_slicec('/', 1); |
| 352 | add_theme_style_override(dname, p_value); |
| 353 | } else if (name.begins_with("theme_override_fonts/")) { |
| 354 | String dname = name.get_slicec('/', 1); |
| 355 | add_theme_font_override(dname, p_value); |
| 356 | } else if (name.begins_with("theme_override_font_sizes/")) { |
| 357 | String dname = name.get_slicec('/', 1); |
| 358 | add_theme_font_size_override(dname, p_value); |
| 359 | } else if (name.begins_with("theme_override_colors/")) { |
| 360 | String dname = name.get_slicec('/', 1); |
| 361 | add_theme_color_override(dname, p_value); |
| 362 | } else if (name.begins_with("theme_override_constants/")) { |
| 363 | String dname = name.get_slicec('/', 1); |
| 364 | add_theme_constant_override(dname, p_value); |
| 365 | } else { |
| 366 | return false; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | return true; |
| 371 | } |
| 372 | |
| 373 | bool Control::_get(const StringName &p_name, Variant &r_ret) const { |
| 374 | ERR_MAIN_THREAD_GUARD_V(false); |
| 375 | String sname = p_name; |
| 376 | |
| 377 | if (!sname.begins_with("theme_override")) { |
| 378 | return false; |
| 379 | } |
| 380 | |
| 381 | if (sname.begins_with("theme_override_icons/")) { |
| 382 | String name = sname.get_slicec('/', 1); |
| 383 | r_ret = data.theme_icon_override.has(name) ? Variant(data.theme_icon_override[name]) : Variant(); |
| 384 | } else if (sname.begins_with("theme_override_styles/")) { |
| 385 | String name = sname.get_slicec('/', 1); |
| 386 | r_ret = data.theme_style_override.has(name) ? Variant(data.theme_style_override[name]) : Variant(); |
| 387 | } else if (sname.begins_with("theme_override_fonts/")) { |
| 388 | String name = sname.get_slicec('/', 1); |
| 389 | r_ret = data.theme_font_override.has(name) ? Variant(data.theme_font_override[name]) : Variant(); |
| 390 | } else if (sname.begins_with("theme_override_font_sizes/")) { |
| 391 | String name = sname.get_slicec('/', 1); |
| 392 | r_ret = data.theme_font_size_override.has(name) ? Variant(data.theme_font_size_override[name]) : Variant(); |
| 393 | } else if (sname.begins_with("theme_override_colors/")) { |
| 394 | String name = sname.get_slicec('/', 1); |
| 395 | r_ret = data.theme_color_override.has(name) ? Variant(data.theme_color_override[name]) : Variant(); |
| 396 | } else if (sname.begins_with("theme_override_constants/")) { |
| 397 | String name = sname.get_slicec('/', 1); |
| 398 | r_ret = data.theme_constant_override.has(name) ? Variant(data.theme_constant_override[name]) : Variant(); |
| 399 | } else { |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | return true; |
| 404 | } |
| 405 | |
| 406 | void Control::_get_property_list(List<PropertyInfo> *p_list) const { |
| 407 | ERR_MAIN_THREAD_GUARD; |
| 408 | List<ThemeDB::ThemeItemBind> theme_items; |
| 409 | ThemeDB::get_singleton()->get_class_items(get_class_name(), &theme_items, true); |
| 410 | |
| 411 | p_list->push_back(PropertyInfo(Variant::NIL, GNAME("Theme Overrides", "theme_override_"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP)); |
| 412 | |
| 413 | for (const ThemeDB::ThemeItemBind &E : theme_items) { |
| 414 | if (E.external) { |
| 415 | continue; // External items are not meant to be exposed. |
| 416 | } |
| 417 | |
| 418 | uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE; |
| 419 | |
| 420 | switch (E.data_type) { |
| 421 | case Theme::DATA_TYPE_COLOR: { |
| 422 | if (data.theme_color_override.has(E.item_name)) { |
| 423 | usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; |
| 424 | } |
| 425 | p_list->push_back(PropertyInfo(Variant::COLOR, PNAME("theme_override_colors") + String("/") + E.item_name, PROPERTY_HINT_NONE, "", usage)); |
| 426 | } break; |
| 427 | |
| 428 | case Theme::DATA_TYPE_CONSTANT: { |
| 429 | if (data.theme_constant_override.has(E.item_name)) { |
| 430 | usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; |
| 431 | } |
| 432 | p_list->push_back(PropertyInfo(Variant::INT, PNAME("theme_override_constants") + String("/") + E.item_name, PROPERTY_HINT_RANGE, "-16384,16384", usage)); |
| 433 | } break; |
| 434 | |
| 435 | case Theme::DATA_TYPE_FONT: { |
| 436 | if (data.theme_font_override.has(E.item_name)) { |
| 437 | usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; |
| 438 | } |
| 439 | p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_fonts") + String("/") + E.item_name, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage)); |
| 440 | } break; |
| 441 | |
| 442 | case Theme::DATA_TYPE_FONT_SIZE: { |
| 443 | if (data.theme_font_size_override.has(E.item_name)) { |
| 444 | usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; |
| 445 | } |
| 446 | 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)); |
| 447 | } break; |
| 448 | |
| 449 | case Theme::DATA_TYPE_ICON: { |
| 450 | if (data.theme_icon_override.has(E.item_name)) { |
| 451 | usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; |
| 452 | } |
| 453 | p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_icons") + String("/") + E.item_name, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage)); |
| 454 | } break; |
| 455 | |
| 456 | case Theme::DATA_TYPE_STYLEBOX: { |
| 457 | if (data.theme_style_override.has(E.item_name)) { |
| 458 | usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; |
| 459 | } |
| 460 | p_list->push_back(PropertyInfo(Variant::OBJECT, PNAME("theme_override_styles") + String("/") + E.item_name, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage)); |
| 461 | } break; |
| 462 | |
| 463 | default: { |
| 464 | // Silences warning. |
| 465 | } break; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | void Control::_validate_property(PropertyInfo &p_property) const { |
| 471 | // Update theme type variation options. |
| 472 | if (Engine::get_singleton()->is_editor_hint() && p_property.name == "theme_type_variation") { |
| 473 | List<StringName> names; |
| 474 | |
| 475 | ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names); |
| 476 | |
| 477 | // Iterate to find all themes. |
| 478 | Control *tmp_control = Object::cast_to<Control>(get_parent()); |
| 479 | Window *tmp_window = Object::cast_to<Window>(get_parent()); |
| 480 | while (tmp_control || tmp_window) { |
| 481 | // We go up and any non Control/Window will break the chain. |
| 482 | if (tmp_control) { |
| 483 | if (tmp_control->get_theme().is_valid()) { |
| 484 | tmp_control->get_theme()->get_type_variation_list(get_class_name(), &names); |
| 485 | } |
| 486 | tmp_window = Object::cast_to<Window>(tmp_control->get_parent()); |
| 487 | tmp_control = Object::cast_to<Control>(tmp_control->get_parent()); |
| 488 | } else { // Window. |
| 489 | if (tmp_window->get_theme().is_valid()) { |
| 490 | tmp_window->get_theme()->get_type_variation_list(get_class_name(), &names); |
| 491 | } |
| 492 | tmp_control = Object::cast_to<Control>(tmp_window->get_parent()); |
| 493 | tmp_window = Object::cast_to<Window>(tmp_window->get_parent()); |
| 494 | } |
| 495 | } |
| 496 | if (get_theme().is_valid()) { |
| 497 | get_theme()->get_type_variation_list(get_class_name(), &names); |
| 498 | } |
| 499 | if (ThemeDB::get_singleton()->get_project_theme().is_valid()) { |
| 500 | ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names); |
| 501 | } |
| 502 | names.sort_custom<StringName::AlphCompare>(); |
| 503 | |
| 504 | Vector<StringName> unique_names; |
| 505 | String hint_string; |
| 506 | for (const StringName &E : names) { |
| 507 | // Skip duplicate values. |
| 508 | if (unique_names.has(E)) { |
| 509 | continue; |
| 510 | } |
| 511 | |
| 512 | hint_string += String(E) + ","; |
| 513 | unique_names.append(E); |
| 514 | } |
| 515 | |
| 516 | p_property.hint_string = hint_string; |
| 517 | } |
| 518 | |
| 519 | if (Engine::get_singleton()->is_editor_hint() && p_property.name == "mouse_force_pass_scroll_events") { |
| 520 | // Disable force pass if the control is not stopping the event. |
| 521 | if (data.mouse_filter != MOUSE_FILTER_STOP) { |
| 522 | p_property.usage |= PROPERTY_USAGE_READ_ONLY; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | if (Engine::get_singleton()->is_editor_hint() && p_property.name == "scale") { |
| 527 | p_property.hint = PROPERTY_HINT_LINK; |
| 528 | } |
| 529 | // Validate which positioning properties should be displayed depending on the parent and the layout mode. |
| 530 | Control *parent_control = get_parent_control(); |
| 531 | if (Engine::get_singleton()->is_editor_hint() && !parent_control) { |
| 532 | // If there is no parent control, display both anchor and container options. |
| 533 | |
| 534 | // Set the layout mode to be disabled with the proper value. |
| 535 | if (p_property.name == "layout_mode") { |
| 536 | p_property.hint_string = "Position,Anchors,Container,Uncontrolled"; |
| 537 | p_property.usage |= PROPERTY_USAGE_READ_ONLY; |
| 538 | } |
| 539 | |
| 540 | // Use the layout mode to display or hide advanced anchoring properties. |
| 541 | bool use_custom_anchors = _get_anchors_layout_preset() == -1; // Custom "preset". |
| 542 | if (!use_custom_anchors && (p_property.name.begins_with("anchor_") || p_property.name.begins_with("offset_") || p_property.name.begins_with("grow_"))) { |
| 543 | p_property.usage ^= PROPERTY_USAGE_EDITOR; |
| 544 | } |
| 545 | } else if (Object::cast_to<Container>(parent_control)) { |
| 546 | // If the parent is a container, display only container-related properties. |
| 547 | if (p_property.name.begins_with("anchor_") || p_property.name.begins_with("offset_") || p_property.name.begins_with("grow_") || p_property.name == "anchors_preset") { |
| 548 | p_property.usage ^= PROPERTY_USAGE_DEFAULT; |
| 549 | } else if (p_property.name == "position" || p_property.name == "rotation" || p_property.name == "scale" || p_property.name == "size" || p_property.name == "pivot_offset" || p_property.name == "pivot_offset_ratio") { |
| 550 | p_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_READ_ONLY; |
| 551 | } else if (Engine::get_singleton()->is_editor_hint() && p_property.name == "layout_mode") { |
| 552 | // Set the layout mode to be disabled with the proper value. |
| 553 | p_property.hint_string = "Position,Anchors,Container,Uncontrolled"; |
| 554 | p_property.usage |= PROPERTY_USAGE_READ_ONLY; |
| 555 | } else if (Engine::get_singleton()->is_editor_hint() && (p_property.name == "size_flags_horizontal" || p_property.name == "size_flags_vertical")) { |
| 556 | // Filter allowed size flags based on the parent container configuration. |
| 557 | Container *parent_container = Object::cast_to<Container>(parent_control); |
| 558 | Vector<int> size_flags; |
| 559 | if (p_property.name == "size_flags_horizontal") { |
| 560 | size_flags = parent_container->get_allowed_size_flags_horizontal(); |
| 561 | } else if (p_property.name == "size_flags_vertical") { |
| 562 | size_flags = parent_container->get_allowed_size_flags_vertical(); |
| 563 | } |
| 564 | |
| 565 | // Enforce the order of the options, regardless of what the container provided. |
| 566 | String hint_string; |
| 567 | if (size_flags.has(SIZE_FILL)) { |
| 568 | hint_string += "Fill:1"; |
| 569 | } |
| 570 | if (size_flags.has(SIZE_EXPAND)) { |
| 571 | if (!hint_string.is_empty()) { |
| 572 | hint_string += ","; |
| 573 | } |
| 574 | hint_string += "Expand:2"; |
| 575 | } |
| 576 | if (size_flags.has(SIZE_SHRINK_CENTER)) { |
| 577 | if (!hint_string.is_empty()) { |
| 578 | hint_string += ","; |
| 579 | } |
| 580 | hint_string += "Shrink Center:4"; |
| 581 | } |
| 582 | if (size_flags.has(SIZE_SHRINK_END)) { |
| 583 | if (!hint_string.is_empty()) { |
| 584 | hint_string += ","; |
| 585 | } |
| 586 | hint_string += "Shrink End:8"; |
| 587 | } |
| 588 | |
| 589 | if (hint_string.is_empty()) { |
| 590 | p_property.hint_string = ""; |
| 591 | p_property.usage |= PROPERTY_USAGE_READ_ONLY; |
| 592 | } else { |
| 593 | p_property.hint_string = hint_string; |
| 594 | } |
| 595 | } |
| 596 | } else if (Engine::get_singleton()->is_editor_hint()) { |
| 597 | // If the parent is a non-container control, display only anchoring-related properties. |
| 598 | if (p_property.name.begins_with("size_flags_")) { |
| 599 | p_property.usage ^= PROPERTY_USAGE_EDITOR; |
| 600 | |
| 601 | } else if (p_property.name == "layout_mode") { |
| 602 | // Set the layout mode to be enabled with proper options. |
| 603 | p_property.hint_string = "Position,Anchors"; |
| 604 | } |
| 605 | |
| 606 | // Use the layout mode to display or hide advanced anchoring properties. |
| 607 | LayoutMode _layout = _get_layout_mode(); |
| 608 | bool use_anchors = (_layout == LayoutMode::LAYOUT_MODE_ANCHORS || _layout == LayoutMode::LAYOUT_MODE_UNCONTROLLED); |
| 609 | if (!use_anchors && p_property.name == "anchors_preset") { |
| 610 | p_property.usage ^= PROPERTY_USAGE_EDITOR; |
| 611 | } |
| 612 | bool use_custom_anchors = use_anchors && _get_anchors_layout_preset() == -1; // Custom "preset". |
| 613 | if (!use_custom_anchors && (p_property.name.begins_with("anchor_") || p_property.name.begins_with("offset_") || p_property.name.begins_with("grow_"))) { |
| 614 | p_property.usage ^= PROPERTY_USAGE_EDITOR; |
| 615 | } |
| 616 | } |
| 617 | if (!Engine::get_singleton()->is_editor_hint()) { |
| 618 | return; |
| 619 | } |
| 620 | // Disable the property if it's managed by the parent container. |
| 621 | if (!Object::cast_to<Container>(parent_control)) { |
| 622 | return; |
| 623 | } |
| 624 | bool property_is_managed_by_container = false; |
| 625 | for (unsigned i = 0; i < properties_managed_by_container_count; i++) { |
| 626 | property_is_managed_by_container = properties_managed_by_container[i] == p_property.name; |
| 627 | if (property_is_managed_by_container) { |
| 628 | break; |
| 629 | } |
| 630 | } |
| 631 | if (property_is_managed_by_container) { |
| 632 | p_property.usage |= PROPERTY_USAGE_READ_ONLY; |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | bool Control::_property_can_revert(const StringName &p_name) const { |
| 637 | if (p_name == "layout_mode" || p_name == "anchors_preset") { |
| 638 | return true; |
| 639 | } |
| 640 | |
| 641 | return false; |
| 642 | } |
| 643 | |
| 644 | bool Control::_property_get_revert(const StringName &p_name, Variant &r_property) const { |
| 645 | if (p_name == "layout_mode") { |
| 646 | r_property = _get_default_layout_mode(); |
| 647 | return true; |
| 648 | } else if (p_name == "anchors_preset") { |
| 649 | r_property = LayoutPreset::PRESET_TOP_LEFT; |
| 650 | return true; |
| 651 | } |
| 652 | |
| 653 | return false; |
| 654 | } |
| 655 | |
| 656 | // Global relations. |
| 657 | |
| 658 | Control *Control::get_parent_control() const { |
| 659 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 660 | return data.parent_control; |
| 661 | } |
| 662 | |
| 663 | Window *Control::get_parent_window() const { |
| 664 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 665 | return data.parent_window; |
| 666 | } |
| 667 | |
| 668 | Control *Control::get_root_parent_control() const { |
| 669 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 670 | const CanvasItem *ci = this; |
| 671 | const Control *root = this; |
| 672 | |
| 673 | while (ci) { |
| 674 | const Control *c = Object::cast_to<Control>(ci); |
| 675 | if (c) { |
| 676 | root = c; |
| 677 | } |
| 678 | |
| 679 | ci = ci->get_parent_item(); |
| 680 | } |
| 681 | |
| 682 | return const_cast<Control *>(root); |
| 683 | } |
| 684 | |
| 685 | Rect2 Control::get_parent_anchorable_rect() const { |
| 686 | ERR_READ_THREAD_GUARD_V(Rect2()); |
| 687 | if (!is_inside_tree()) { |
| 688 | return Rect2(); |
| 689 | } |
| 690 | |
| 691 | Rect2 parent_rect; |
| 692 | if (data.parent_canvas_item) { |
| 693 | parent_rect = data.parent_canvas_item->get_anchorable_rect(); |
| 694 | } else { |
| 695 | #ifdef TOOLS_ENABLED |
| 696 | Node *edited_scene_root = get_tree()->get_edited_scene_root(); |
| 697 | Node *scene_root_parent = edited_scene_root ? edited_scene_root->get_parent() : nullptr; |
| 698 | |
| 699 | if (scene_root_parent && get_viewport() == scene_root_parent->get_viewport()) { |
| 700 | parent_rect.size = Size2(GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_width"), GLOBAL_GET_CACHED(real_t, "display/window/size/viewport_height")); |
| 701 | } else { |
| 702 | parent_rect = get_viewport()->get_visible_rect(); |
| 703 | } |
| 704 | |
| 705 | #else |
| 706 | parent_rect = get_viewport()->get_visible_rect(); |
| 707 | #endif // TOOLS_ENABLED |
| 708 | } |
| 709 | |
| 710 | return parent_rect; |
| 711 | } |
| 712 | |
| 713 | Size2 Control::get_parent_area_size() const { |
| 714 | ERR_READ_THREAD_GUARD_V(Size2()); |
| 715 | return get_parent_anchorable_rect().size; |
| 716 | } |
| 717 | |
| 718 | // Positioning and sizing. |
| 719 | |
| 720 | Transform2D Control::_get_internal_transform() const { |
| 721 | // T(pivot_offset) * R(rotation) * S(scale) * T(-pivot_offset) |
| 722 | Transform2D xform(data.rotation, data.scale, 0.0f, get_combined_pivot_offset()); |
| 723 | xform.translate_local(-get_combined_pivot_offset()); |
| 724 | return xform; |
| 725 | } |
| 726 | |
| 727 | void Control::_update_canvas_item_transform() { |
| 728 | Transform2D xform = _get_internal_transform(); |
| 729 | xform[2] += get_position(); |
| 730 | |
| 731 | // We use a little workaround to avoid flickering when moving the pivot with _edit_set_pivot() |
| 732 | if (is_inside_tree() && Math::abs(Math::sin(data.rotation * 4.0f)) < 0.00001f && get_viewport()->is_snap_controls_to_pixels_enabled()) { |
| 733 | xform[2] = (xform[2] + Vector2(0.5, 0.5)).floor(); |
| 734 | } |
| 735 | |
| 736 | RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform); |
| 737 | } |
| 738 | |
| 739 | Transform2D Control::get_transform() const { |
| 740 | ERR_READ_THREAD_GUARD_V(Transform2D()); |
| 741 | Transform2D xform = _get_internal_transform(); |
| 742 | xform[2] += get_position(); |
| 743 | return xform; |
| 744 | } |
| 745 | |
| 746 | void Control::_top_level_changed_on_parent() { |
| 747 | // Update root control status. |
| 748 | _notification(NOTIFICATION_EXIT_CANVAS); |
| 749 | _notification(NOTIFICATION_ENTER_CANVAS); |
| 750 | } |
| 751 | |
| 752 | /// Anchors and offsets. |
| 753 | |
| 754 | void Control::_set_anchor(Side p_side, real_t p_anchor) { |
| 755 | set_anchor(p_side, p_anchor); |
| 756 | } |
| 757 | |
| 758 | void Control::set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset, bool p_push_opposite_anchor) { |
| 759 | ERR_MAIN_THREAD_GUARD; |
| 760 | ERR_FAIL_INDEX((int)p_side, 4); |
| 761 | |
| 762 | Rect2 parent_rect = get_parent_anchorable_rect(); |
| 763 | real_t parent_range = (p_side == SIDE_LEFT || p_side == SIDE_RIGHT) ? parent_rect.size.x : parent_rect.size.y; |
| 764 | real_t previous_pos = data.offset[p_side] + data.anchor[p_side] * parent_range; |
| 765 | real_t previous_opposite_pos = data.offset[(p_side + 2) % 4] + data.anchor[(p_side + 2) % 4] * parent_range; |
| 766 | |
| 767 | data.anchor[p_side] = p_anchor; |
| 768 | |
| 769 | if (((p_side == SIDE_LEFT || p_side == SIDE_TOP) && data.anchor[p_side] > data.anchor[(p_side + 2) % 4]) || |
| 770 | ((p_side == SIDE_RIGHT || p_side == SIDE_BOTTOM) && data.anchor[p_side] < data.anchor[(p_side + 2) % 4])) { |
| 771 | if (p_push_opposite_anchor) { |
| 772 | data.anchor[(p_side + 2) % 4] = data.anchor[p_side]; |
| 773 | } else { |
| 774 | data.anchor[p_side] = data.anchor[(p_side + 2) % 4]; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | if (!p_keep_offset) { |
| 779 | data.offset[p_side] = previous_pos - data.anchor[p_side] * parent_range; |
| 780 | if (p_push_opposite_anchor) { |
| 781 | data.offset[(p_side + 2) % 4] = previous_opposite_pos - data.anchor[(p_side + 2) % 4] * parent_range; |
| 782 | } |
| 783 | } |
| 784 | if (is_inside_tree()) { |
| 785 | _size_changed(); |
| 786 | } |
| 787 | |
| 788 | queue_redraw(); |
| 789 | } |
| 790 | |
| 791 | real_t Control::get_anchor(Side p_side) const { |
| 792 | ERR_READ_THREAD_GUARD_V(0); |
| 793 | ERR_FAIL_INDEX_V(int(p_side), 4, 0.0); |
| 794 | |
| 795 | return data.anchor[p_side]; |
| 796 | } |
| 797 | |
| 798 | void Control::set_offset(Side p_side, real_t p_value) { |
| 799 | ERR_MAIN_THREAD_GUARD; |
| 800 | ERR_FAIL_INDEX((int)p_side, 4); |
| 801 | if (data.offset[p_side] == p_value) { |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | data.offset[p_side] = p_value; |
| 806 | _size_changed(); |
| 807 | } |
| 808 | |
| 809 | real_t Control::get_offset(Side p_side) const { |
| 810 | ERR_READ_THREAD_GUARD_V(0); |
| 811 | ERR_FAIL_INDEX_V((int)p_side, 4, 0); |
| 812 | |
| 813 | return data.offset[p_side]; |
| 814 | } |
| 815 | |
| 816 | void Control::set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos, bool p_push_opposite_anchor) { |
| 817 | ERR_MAIN_THREAD_GUARD; |
| 818 | set_anchor(p_side, p_anchor, false, p_push_opposite_anchor); |
| 819 | set_offset(p_side, p_pos); |
| 820 | } |
| 821 | |
| 822 | void Control::set_begin(const Point2 &p_point) { |
| 823 | ERR_MAIN_THREAD_GUARD; |
| 824 | ERR_FAIL_COND(!std::isfinite(p_point.x) || !std::isfinite(p_point.y)); |
| 825 | if (data.offset[0] == p_point.x && data.offset[1] == p_point.y) { |
| 826 | return; |
| 827 | } |
| 828 | |
| 829 | data.offset[0] = p_point.x; |
| 830 | data.offset[1] = p_point.y; |
| 831 | _size_changed(); |
| 832 | } |
| 833 | |
| 834 | Point2 Control::get_begin() const { |
| 835 | ERR_READ_THREAD_GUARD_V(Vector2()); |
| 836 | return Point2(data.offset[0], data.offset[1]); |
| 837 | } |
| 838 | |
| 839 | void Control::set_end(const Point2 &p_point) { |
| 840 | ERR_MAIN_THREAD_GUARD; |
| 841 | if (data.offset[2] == p_point.x && data.offset[3] == p_point.y) { |
| 842 | return; |
| 843 | } |
| 844 | |
| 845 | data.offset[2] = p_point.x; |
| 846 | data.offset[3] = p_point.y; |
| 847 | _size_changed(); |
| 848 | } |
| 849 | |
| 850 | Point2 Control::get_end() const { |
| 851 | ERR_READ_THREAD_GUARD_V(Point2()); |
| 852 | return Point2(data.offset[2], data.offset[3]); |
| 853 | } |
| 854 | |
| 855 | void Control::set_h_grow_direction(GrowDirection p_direction) { |
| 856 | ERR_MAIN_THREAD_GUARD; |
| 857 | if (data.h_grow == p_direction) { |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | ERR_FAIL_INDEX((int)p_direction, 3); |
| 862 | |
| 863 | data.h_grow = p_direction; |
| 864 | _size_changed(); |
| 865 | } |
| 866 | |
| 867 | Control::GrowDirection Control::get_h_grow_direction() const { |
| 868 | ERR_READ_THREAD_GUARD_V(GROW_DIRECTION_BEGIN); |
| 869 | return data.h_grow; |
| 870 | } |
| 871 | |
| 872 | void Control::set_v_grow_direction(GrowDirection p_direction) { |
| 873 | ERR_MAIN_THREAD_GUARD; |
| 874 | if (data.v_grow == p_direction) { |
| 875 | return; |
| 876 | } |
| 877 | |
| 878 | ERR_FAIL_INDEX((int)p_direction, 3); |
| 879 | |
| 880 | data.v_grow = p_direction; |
| 881 | _size_changed(); |
| 882 | } |
| 883 | |
| 884 | Control::GrowDirection Control::get_v_grow_direction() const { |
| 885 | ERR_READ_THREAD_GUARD_V(GROW_DIRECTION_BEGIN); |
| 886 | return data.v_grow; |
| 887 | } |
| 888 | |
| 889 | void Control::_compute_anchors(Rect2 p_rect, const real_t p_offsets[4], real_t (&r_anchors)[4]) { |
| 890 | Size2 parent_rect_size = get_parent_anchorable_rect().size; |
| 891 | ERR_FAIL_COND(parent_rect_size.x == 0.0); |
| 892 | ERR_FAIL_COND(parent_rect_size.y == 0.0); |
| 893 | |
| 894 | real_t x = p_rect.position.x; |
| 895 | if (is_layout_rtl()) { |
| 896 | x = parent_rect_size.x - x - p_rect.size.x; |
| 897 | } |
| 898 | r_anchors[0] = (x - p_offsets[0]) / parent_rect_size.x; |
| 899 | r_anchors[1] = (p_rect.position.y - p_offsets[1]) / parent_rect_size.y; |
| 900 | r_anchors[2] = (x + p_rect.size.x - p_offsets[2]) / parent_rect_size.x; |
| 901 | r_anchors[3] = (p_rect.position.y + p_rect.size.y - p_offsets[3]) / parent_rect_size.y; |
| 902 | } |
| 903 | |
| 904 | void Control::_compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (&r_offsets)[4]) { |
| 905 | Size2 parent_rect_size = get_parent_anchorable_rect().size; |
| 906 | |
| 907 | real_t x = p_rect.position.x; |
| 908 | if (is_layout_rtl()) { |
| 909 | x = parent_rect_size.x - x - p_rect.size.x; |
| 910 | } |
| 911 | r_offsets[0] = x - (p_anchors[0] * parent_rect_size.x); |
| 912 | r_offsets[1] = p_rect.position.y - (p_anchors[1] * parent_rect_size.y); |
| 913 | r_offsets[2] = x + p_rect.size.x - (p_anchors[2] * parent_rect_size.x); |
| 914 | r_offsets[3] = p_rect.position.y + p_rect.size.y - (p_anchors[3] * parent_rect_size.y); |
| 915 | } |
| 916 | |
| 917 | /// Presets and layout modes. |
| 918 | |
| 919 | void Control::_set_layout_mode(LayoutMode p_mode) { |
| 920 | bool list_changed = false; |
| 921 | |
| 922 | if (data.stored_layout_mode != p_mode) { |
| 923 | list_changed = true; |
| 924 | data.stored_layout_mode = p_mode; |
| 925 | } |
| 926 | |
| 927 | if (data.stored_layout_mode == LayoutMode::LAYOUT_MODE_POSITION) { |
| 928 | data.stored_use_custom_anchors = false; |
| 929 | set_anchors_and_offsets_preset(LayoutPreset::PRESET_TOP_LEFT, LayoutPresetMode::PRESET_MODE_KEEP_SIZE); |
| 930 | set_grow_direction_preset(LayoutPreset::PRESET_TOP_LEFT); |
| 931 | } |
| 932 | |
| 933 | if (list_changed) { |
| 934 | notify_property_list_changed(); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | void Control::_update_layout_mode() { |
| 939 | LayoutMode computed_layout = _get_layout_mode(); |
| 940 | if (data.stored_layout_mode != computed_layout) { |
| 941 | data.stored_layout_mode = computed_layout; |
| 942 | notify_property_list_changed(); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | Control::LayoutMode Control::_get_layout_mode() const { |
| 947 | Control *parent_control = get_parent_control(); |
| 948 | // In these modes the property is read-only. |
| 949 | if (!parent_control) { |
| 950 | return LayoutMode::LAYOUT_MODE_UNCONTROLLED; |
| 951 | } else if (Object::cast_to<Container>(parent_control)) { |
| 952 | return LayoutMode::LAYOUT_MODE_CONTAINER; |
| 953 | } |
| 954 | |
| 955 | // If anchors are not in the top-left position, this is definitely in anchors mode. |
| 956 | if (_get_anchors_layout_preset() != (int)LayoutPreset::PRESET_TOP_LEFT) { |
| 957 | return LayoutMode::LAYOUT_MODE_ANCHORS; |
| 958 | } |
| 959 | |
| 960 | // Only position/anchors modes are valid for non-container control parent. |
| 961 | if (data.stored_layout_mode == LayoutMode::LAYOUT_MODE_POSITION || data.stored_layout_mode == LayoutMode::LAYOUT_MODE_ANCHORS) { |
| 962 | return data.stored_layout_mode; |
| 963 | } |
| 964 | |
| 965 | // Otherwise fallback to position mode. |
| 966 | return LayoutMode::LAYOUT_MODE_POSITION; |
| 967 | } |
| 968 | |
| 969 | Control::LayoutMode Control::_get_default_layout_mode() const { |
| 970 | Control *parent_control = get_parent_control(); |
| 971 | // In these modes the property is read-only. |
| 972 | if (!parent_control) { |
| 973 | return LayoutMode::LAYOUT_MODE_UNCONTROLLED; |
| 974 | } else if (Object::cast_to<Container>(parent_control)) { |
| 975 | return LayoutMode::LAYOUT_MODE_CONTAINER; |
| 976 | } |
| 977 | |
| 978 | // Otherwise fallback to the position mode. |
| 979 | return LayoutMode::LAYOUT_MODE_POSITION; |
| 980 | } |
| 981 | |
| 982 | void Control::_set_anchors_layout_preset(int p_preset) { |
| 983 | if (p_preset == -1) { |
| 984 | if (!data.stored_use_custom_anchors) { |
| 985 | data.stored_use_custom_anchors = true; |
| 986 | notify_property_list_changed(); |
| 987 | } |
| 988 | return; // Keep settings as is. |
| 989 | } |
| 990 | |
| 991 | if (data.stored_layout_mode != LayoutMode::LAYOUT_MODE_UNCONTROLLED && data.stored_layout_mode != LayoutMode::LAYOUT_MODE_ANCHORS) { |
| 992 | // In other modes the anchor preset is non-operational and shouldn't be set to anything. |
| 993 | return; |
| 994 | } |
| 995 | |
| 996 | bool list_changed = false; |
| 997 | |
| 998 | if (data.stored_use_custom_anchors) { |
| 999 | list_changed = true; |
| 1000 | data.stored_use_custom_anchors = false; |
| 1001 | } |
| 1002 | |
| 1003 | LayoutPreset preset = (LayoutPreset)p_preset; |
| 1004 | // Set correct anchors. |
| 1005 | set_anchors_preset(preset); |
| 1006 | |
| 1007 | // Select correct preset mode. |
| 1008 | switch (preset) { |
| 1009 | case PRESET_TOP_LEFT: |
| 1010 | case PRESET_TOP_RIGHT: |
| 1011 | case PRESET_BOTTOM_LEFT: |
| 1012 | case PRESET_BOTTOM_RIGHT: |
| 1013 | case PRESET_CENTER_LEFT: |
| 1014 | case PRESET_CENTER_TOP: |
| 1015 | case PRESET_CENTER_RIGHT: |
| 1016 | case PRESET_CENTER_BOTTOM: |
| 1017 | case PRESET_CENTER: |
| 1018 | set_offsets_preset(preset, LayoutPresetMode::PRESET_MODE_KEEP_SIZE); |
| 1019 | break; |
| 1020 | case PRESET_LEFT_WIDE: |
| 1021 | case PRESET_TOP_WIDE: |
| 1022 | case PRESET_RIGHT_WIDE: |
| 1023 | case PRESET_BOTTOM_WIDE: |
| 1024 | case PRESET_VCENTER_WIDE: |
| 1025 | case PRESET_HCENTER_WIDE: |
| 1026 | case PRESET_FULL_RECT: |
| 1027 | set_offsets_preset(preset, LayoutPresetMode::PRESET_MODE_MINSIZE); |
| 1028 | break; |
| 1029 | } |
| 1030 | |
| 1031 | // Select correct grow directions. |
| 1032 | set_grow_direction_preset(preset); |
| 1033 | |
| 1034 | if (list_changed) { |
| 1035 | notify_property_list_changed(); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | int Control::_get_anchors_layout_preset() const { |
| 1040 | // If this is a layout mode that doesn't rely on anchors, avoid excessive checks. |
| 1041 | if (data.stored_layout_mode != LayoutMode::LAYOUT_MODE_UNCONTROLLED && data.stored_layout_mode != LayoutMode::LAYOUT_MODE_ANCHORS) { |
| 1042 | return LayoutPreset::PRESET_TOP_LEFT; |
| 1043 | } |
| 1044 | |
| 1045 | // If the custom preset was selected by user, use it. |
| 1046 | if (data.stored_use_custom_anchors) { |
| 1047 | return -1; |
| 1048 | } |
| 1049 | |
| 1050 | // Check anchors to determine if the current state matches a preset, or not. |
| 1051 | |
| 1052 | float left = get_anchor(SIDE_LEFT); |
| 1053 | float right = get_anchor(SIDE_RIGHT); |
| 1054 | float top = get_anchor(SIDE_TOP); |
| 1055 | float bottom = get_anchor(SIDE_BOTTOM); |
| 1056 | |
| 1057 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_BEGIN && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_BEGIN) { |
| 1058 | return (int)LayoutPreset::PRESET_TOP_LEFT; |
| 1059 | } |
| 1060 | if (left == (float)ANCHOR_END && right == (float)ANCHOR_END && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_BEGIN) { |
| 1061 | return (int)LayoutPreset::PRESET_TOP_RIGHT; |
| 1062 | } |
| 1063 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_BEGIN && top == (float)ANCHOR_END && bottom == (float)ANCHOR_END) { |
| 1064 | return (int)LayoutPreset::PRESET_BOTTOM_LEFT; |
| 1065 | } |
| 1066 | if (left == (float)ANCHOR_END && right == (float)ANCHOR_END && top == (float)ANCHOR_END && bottom == (float)ANCHOR_END) { |
| 1067 | return (int)LayoutPreset::PRESET_BOTTOM_RIGHT; |
| 1068 | } |
| 1069 | |
| 1070 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_BEGIN && top == 0.5 && bottom == 0.5) { |
| 1071 | return (int)LayoutPreset::PRESET_CENTER_LEFT; |
| 1072 | } |
| 1073 | if (left == (float)ANCHOR_END && right == (float)ANCHOR_END && top == 0.5 && bottom == 0.5) { |
| 1074 | return (int)LayoutPreset::PRESET_CENTER_RIGHT; |
| 1075 | } |
| 1076 | if (left == 0.5 && right == 0.5 && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_BEGIN) { |
| 1077 | return (int)LayoutPreset::PRESET_CENTER_TOP; |
| 1078 | } |
| 1079 | if (left == 0.5 && right == 0.5 && top == (float)ANCHOR_END && bottom == (float)ANCHOR_END) { |
| 1080 | return (int)LayoutPreset::PRESET_CENTER_BOTTOM; |
| 1081 | } |
| 1082 | if (left == 0.5 && right == 0.5 && top == 0.5 && bottom == 0.5) { |
| 1083 | return (int)LayoutPreset::PRESET_CENTER; |
| 1084 | } |
| 1085 | |
| 1086 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_BEGIN && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_END) { |
| 1087 | return (int)LayoutPreset::PRESET_LEFT_WIDE; |
| 1088 | } |
| 1089 | if (left == (float)ANCHOR_END && right == (float)ANCHOR_END && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_END) { |
| 1090 | return (int)LayoutPreset::PRESET_RIGHT_WIDE; |
| 1091 | } |
| 1092 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_END && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_BEGIN) { |
| 1093 | return (int)LayoutPreset::PRESET_TOP_WIDE; |
| 1094 | } |
| 1095 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_END && top == (float)ANCHOR_END && bottom == (float)ANCHOR_END) { |
| 1096 | return (int)LayoutPreset::PRESET_BOTTOM_WIDE; |
| 1097 | } |
| 1098 | |
| 1099 | if (left == 0.5 && right == 0.5 && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_END) { |
| 1100 | return (int)LayoutPreset::PRESET_VCENTER_WIDE; |
| 1101 | } |
| 1102 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_END && top == 0.5 && bottom == 0.5) { |
| 1103 | return (int)LayoutPreset::PRESET_HCENTER_WIDE; |
| 1104 | } |
| 1105 | |
| 1106 | if (left == (float)ANCHOR_BEGIN && right == (float)ANCHOR_END && top == (float)ANCHOR_BEGIN && bottom == (float)ANCHOR_END) { |
| 1107 | return (int)LayoutPreset::PRESET_FULL_RECT; |
| 1108 | } |
| 1109 | |
| 1110 | // Does not match any preset, return "Custom". |
| 1111 | return -1; |
| 1112 | } |
| 1113 | |
| 1114 | void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets) { |
| 1115 | ERR_MAIN_THREAD_GUARD; |
| 1116 | ERR_FAIL_INDEX((int)p_preset, 16); |
| 1117 | |
| 1118 | //Left |
| 1119 | switch (p_preset) { |
| 1120 | case PRESET_TOP_LEFT: |
| 1121 | case PRESET_BOTTOM_LEFT: |
| 1122 | case PRESET_CENTER_LEFT: |
| 1123 | case PRESET_TOP_WIDE: |
| 1124 | case PRESET_BOTTOM_WIDE: |
| 1125 | case PRESET_LEFT_WIDE: |
| 1126 | case PRESET_HCENTER_WIDE: |
| 1127 | case PRESET_FULL_RECT: |
| 1128 | set_anchor(SIDE_LEFT, ANCHOR_BEGIN, p_keep_offsets); |
| 1129 | break; |
| 1130 | |
| 1131 | case PRESET_CENTER_TOP: |
| 1132 | case PRESET_CENTER_BOTTOM: |
| 1133 | case PRESET_CENTER: |
| 1134 | case PRESET_VCENTER_WIDE: |
| 1135 | set_anchor(SIDE_LEFT, 0.5, p_keep_offsets); |
| 1136 | break; |
| 1137 | |
| 1138 | case PRESET_TOP_RIGHT: |
| 1139 | case PRESET_BOTTOM_RIGHT: |
| 1140 | case PRESET_CENTER_RIGHT: |
| 1141 | case PRESET_RIGHT_WIDE: |
| 1142 | set_anchor(SIDE_LEFT, ANCHOR_END, p_keep_offsets); |
| 1143 | break; |
| 1144 | } |
| 1145 | |
| 1146 | // Top |
| 1147 | switch (p_preset) { |
| 1148 | case PRESET_TOP_LEFT: |
| 1149 | case PRESET_TOP_RIGHT: |
| 1150 | case PRESET_CENTER_TOP: |
| 1151 | case PRESET_LEFT_WIDE: |
| 1152 | case PRESET_RIGHT_WIDE: |
| 1153 | case PRESET_TOP_WIDE: |
| 1154 | case PRESET_VCENTER_WIDE: |
| 1155 | case PRESET_FULL_RECT: |
| 1156 | set_anchor(SIDE_TOP, ANCHOR_BEGIN, p_keep_offsets); |
| 1157 | break; |
| 1158 | |
| 1159 | case PRESET_CENTER_LEFT: |
| 1160 | case PRESET_CENTER_RIGHT: |
| 1161 | case PRESET_CENTER: |
| 1162 | case PRESET_HCENTER_WIDE: |
| 1163 | set_anchor(SIDE_TOP, 0.5, p_keep_offsets); |
| 1164 | break; |
| 1165 | |
| 1166 | case PRESET_BOTTOM_LEFT: |
| 1167 | case PRESET_BOTTOM_RIGHT: |
| 1168 | case PRESET_CENTER_BOTTOM: |
| 1169 | case PRESET_BOTTOM_WIDE: |
| 1170 | set_anchor(SIDE_TOP, ANCHOR_END, p_keep_offsets); |
| 1171 | break; |
| 1172 | } |
| 1173 | |
| 1174 | // Right |
| 1175 | switch (p_preset) { |
| 1176 | case PRESET_TOP_LEFT: |
| 1177 | case PRESET_BOTTOM_LEFT: |
| 1178 | case PRESET_CENTER_LEFT: |
| 1179 | case PRESET_LEFT_WIDE: |
| 1180 | set_anchor(SIDE_RIGHT, ANCHOR_BEGIN, p_keep_offsets); |
| 1181 | break; |
| 1182 | |
| 1183 | case PRESET_CENTER_TOP: |
| 1184 | case PRESET_CENTER_BOTTOM: |
| 1185 | case PRESET_CENTER: |
| 1186 | case PRESET_VCENTER_WIDE: |
| 1187 | set_anchor(SIDE_RIGHT, 0.5, p_keep_offsets); |
| 1188 | break; |
| 1189 | |
| 1190 | case PRESET_TOP_RIGHT: |
| 1191 | case PRESET_BOTTOM_RIGHT: |
| 1192 | case PRESET_CENTER_RIGHT: |
| 1193 | case PRESET_TOP_WIDE: |
| 1194 | case PRESET_RIGHT_WIDE: |
| 1195 | case PRESET_BOTTOM_WIDE: |
| 1196 | case PRESET_HCENTER_WIDE: |
| 1197 | case PRESET_FULL_RECT: |
| 1198 | set_anchor(SIDE_RIGHT, ANCHOR_END, p_keep_offsets); |
| 1199 | break; |
| 1200 | } |
| 1201 | |
| 1202 | // Bottom |
| 1203 | switch (p_preset) { |
| 1204 | case PRESET_TOP_LEFT: |
| 1205 | case PRESET_TOP_RIGHT: |
| 1206 | case PRESET_CENTER_TOP: |
| 1207 | case PRESET_TOP_WIDE: |
| 1208 | set_anchor(SIDE_BOTTOM, ANCHOR_BEGIN, p_keep_offsets); |
| 1209 | break; |
| 1210 | |
| 1211 | case PRESET_CENTER_LEFT: |
| 1212 | case PRESET_CENTER_RIGHT: |
| 1213 | case PRESET_CENTER: |
| 1214 | case PRESET_HCENTER_WIDE: |
| 1215 | set_anchor(SIDE_BOTTOM, 0.5, p_keep_offsets); |
| 1216 | break; |
| 1217 | |
| 1218 | case PRESET_BOTTOM_LEFT: |
| 1219 | case PRESET_BOTTOM_RIGHT: |
| 1220 | case PRESET_CENTER_BOTTOM: |
| 1221 | case PRESET_LEFT_WIDE: |
| 1222 | case PRESET_RIGHT_WIDE: |
| 1223 | case PRESET_BOTTOM_WIDE: |
| 1224 | case PRESET_VCENTER_WIDE: |
| 1225 | case PRESET_FULL_RECT: |
| 1226 | set_anchor(SIDE_BOTTOM, ANCHOR_END, p_keep_offsets); |
| 1227 | break; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | void Control::set_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) { |
| 1232 | ERR_MAIN_THREAD_GUARD; |
| 1233 | ERR_FAIL_INDEX((int)p_preset, 16); |
| 1234 | ERR_FAIL_INDEX((int)p_resize_mode, 4); |
| 1235 | |
| 1236 | // Calculate the size if the node is not resized |
| 1237 | Size2 min_size = get_minimum_size(); |
| 1238 | Size2 new_size = get_size(); |
| 1239 | if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) { |
| 1240 | new_size.x = min_size.x; |
| 1241 | } |
| 1242 | if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) { |
| 1243 | new_size.y = min_size.y; |
| 1244 | } |
| 1245 | |
| 1246 | Rect2 parent_rect = get_parent_anchorable_rect(); |
| 1247 | |
| 1248 | real_t x = parent_rect.size.x; |
| 1249 | if (is_layout_rtl()) { |
| 1250 | x = parent_rect.size.x - x - new_size.x; |
| 1251 | } |
| 1252 | //Left |
| 1253 | switch (p_preset) { |
| 1254 | case PRESET_TOP_LEFT: |
| 1255 | case PRESET_BOTTOM_LEFT: |
| 1256 | case PRESET_CENTER_LEFT: |
| 1257 | case PRESET_TOP_WIDE: |
| 1258 | case PRESET_BOTTOM_WIDE: |
| 1259 | case PRESET_LEFT_WIDE: |
| 1260 | case PRESET_HCENTER_WIDE: |
| 1261 | case PRESET_FULL_RECT: |
| 1262 | data.offset[0] = x * (0.0 - data.anchor[0]) + p_margin + parent_rect.position.x; |
| 1263 | break; |
| 1264 | |
| 1265 | case PRESET_CENTER_TOP: |
| 1266 | case PRESET_CENTER_BOTTOM: |
| 1267 | case PRESET_CENTER: |
| 1268 | case PRESET_VCENTER_WIDE: |
| 1269 | data.offset[0] = x * (0.5 - data.anchor[0]) - new_size.x / 2 + parent_rect.position.x; |
| 1270 | break; |
| 1271 | |
| 1272 | case PRESET_TOP_RIGHT: |
| 1273 | case PRESET_BOTTOM_RIGHT: |
| 1274 | case PRESET_CENTER_RIGHT: |
| 1275 | case PRESET_RIGHT_WIDE: |
| 1276 | data.offset[0] = x * (1.0 - data.anchor[0]) - new_size.x - p_margin + parent_rect.position.x; |
| 1277 | break; |
| 1278 | } |
| 1279 | |
| 1280 | // Top |
| 1281 | switch (p_preset) { |
| 1282 | case PRESET_TOP_LEFT: |
| 1283 | case PRESET_TOP_RIGHT: |
| 1284 | case PRESET_CENTER_TOP: |
| 1285 | case PRESET_LEFT_WIDE: |
| 1286 | case PRESET_RIGHT_WIDE: |
| 1287 | case PRESET_TOP_WIDE: |
| 1288 | case PRESET_VCENTER_WIDE: |
| 1289 | case PRESET_FULL_RECT: |
| 1290 | data.offset[1] = parent_rect.size.y * (0.0 - data.anchor[1]) + p_margin + parent_rect.position.y; |
| 1291 | break; |
| 1292 | |
| 1293 | case PRESET_CENTER_LEFT: |
| 1294 | case PRESET_CENTER_RIGHT: |
| 1295 | case PRESET_CENTER: |
| 1296 | case PRESET_HCENTER_WIDE: |
| 1297 | data.offset[1] = parent_rect.size.y * (0.5 - data.anchor[1]) - new_size.y / 2 + parent_rect.position.y; |
| 1298 | break; |
| 1299 | |
| 1300 | case PRESET_BOTTOM_LEFT: |
| 1301 | case PRESET_BOTTOM_RIGHT: |
| 1302 | case PRESET_CENTER_BOTTOM: |
| 1303 | case PRESET_BOTTOM_WIDE: |
| 1304 | data.offset[1] = parent_rect.size.y * (1.0 - data.anchor[1]) - new_size.y - p_margin + parent_rect.position.y; |
| 1305 | break; |
| 1306 | } |
| 1307 | |
| 1308 | // Right |
| 1309 | switch (p_preset) { |
| 1310 | case PRESET_TOP_LEFT: |
| 1311 | case PRESET_BOTTOM_LEFT: |
| 1312 | case PRESET_CENTER_LEFT: |
| 1313 | case PRESET_LEFT_WIDE: |
| 1314 | data.offset[2] = x * (0.0 - data.anchor[2]) + new_size.x + p_margin + parent_rect.position.x; |
| 1315 | break; |
| 1316 | |
| 1317 | case PRESET_CENTER_TOP: |
| 1318 | case PRESET_CENTER_BOTTOM: |
| 1319 | case PRESET_CENTER: |
| 1320 | case PRESET_VCENTER_WIDE: |
| 1321 | data.offset[2] = x * (0.5 - data.anchor[2]) + new_size.x / 2 + parent_rect.position.x; |
| 1322 | break; |
| 1323 | |
| 1324 | case PRESET_TOP_RIGHT: |
| 1325 | case PRESET_BOTTOM_RIGHT: |
| 1326 | case PRESET_CENTER_RIGHT: |
| 1327 | case PRESET_TOP_WIDE: |
| 1328 | case PRESET_RIGHT_WIDE: |
| 1329 | case PRESET_BOTTOM_WIDE: |
| 1330 | case PRESET_HCENTER_WIDE: |
| 1331 | case PRESET_FULL_RECT: |
| 1332 | data.offset[2] = x * (1.0 - data.anchor[2]) - p_margin + parent_rect.position.x; |
| 1333 | break; |
| 1334 | } |
| 1335 | |
| 1336 | // Bottom |
| 1337 | switch (p_preset) { |
| 1338 | case PRESET_TOP_LEFT: |
| 1339 | case PRESET_TOP_RIGHT: |
| 1340 | case PRESET_CENTER_TOP: |
| 1341 | case PRESET_TOP_WIDE: |
| 1342 | data.offset[3] = parent_rect.size.y * (0.0 - data.anchor[3]) + new_size.y + p_margin + parent_rect.position.y; |
| 1343 | break; |
| 1344 | |
| 1345 | case PRESET_CENTER_LEFT: |
| 1346 | case PRESET_CENTER_RIGHT: |
| 1347 | case PRESET_CENTER: |
| 1348 | case PRESET_HCENTER_WIDE: |
| 1349 | data.offset[3] = parent_rect.size.y * (0.5 - data.anchor[3]) + new_size.y / 2 + parent_rect.position.y; |
| 1350 | break; |
| 1351 | |
| 1352 | case PRESET_BOTTOM_LEFT: |
| 1353 | case PRESET_BOTTOM_RIGHT: |
| 1354 | case PRESET_CENTER_BOTTOM: |
| 1355 | case PRESET_LEFT_WIDE: |
| 1356 | case PRESET_RIGHT_WIDE: |
| 1357 | case PRESET_BOTTOM_WIDE: |
| 1358 | case PRESET_VCENTER_WIDE: |
| 1359 | case PRESET_FULL_RECT: |
| 1360 | data.offset[3] = parent_rect.size.y * (1.0 - data.anchor[3]) - p_margin + parent_rect.position.y; |
| 1361 | break; |
| 1362 | } |
| 1363 | |
| 1364 | _size_changed(); |
| 1365 | } |
| 1366 | |
| 1367 | void Control::set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) { |
| 1368 | ERR_MAIN_THREAD_GUARD; |
| 1369 | set_anchors_preset(p_preset); |
| 1370 | set_offsets_preset(p_preset, p_resize_mode, p_margin); |
| 1371 | } |
| 1372 | |
| 1373 | void Control::set_grow_direction_preset(LayoutPreset p_preset) { |
| 1374 | ERR_MAIN_THREAD_GUARD; |
| 1375 | // Select correct horizontal grow direction. |
| 1376 | switch (p_preset) { |
| 1377 | case PRESET_TOP_LEFT: |
| 1378 | case PRESET_BOTTOM_LEFT: |
| 1379 | case PRESET_CENTER_LEFT: |
| 1380 | case PRESET_LEFT_WIDE: |
| 1381 | set_h_grow_direction(GrowDirection::GROW_DIRECTION_END); |
| 1382 | break; |
| 1383 | case PRESET_TOP_RIGHT: |
| 1384 | case PRESET_BOTTOM_RIGHT: |
| 1385 | case PRESET_CENTER_RIGHT: |
| 1386 | case PRESET_RIGHT_WIDE: |
| 1387 | set_h_grow_direction(GrowDirection::GROW_DIRECTION_BEGIN); |
| 1388 | break; |
| 1389 | case PRESET_CENTER_TOP: |
| 1390 | case PRESET_CENTER_BOTTOM: |
| 1391 | case PRESET_CENTER: |
| 1392 | case PRESET_TOP_WIDE: |
| 1393 | case PRESET_BOTTOM_WIDE: |
| 1394 | case PRESET_VCENTER_WIDE: |
| 1395 | case PRESET_HCENTER_WIDE: |
| 1396 | case PRESET_FULL_RECT: |
| 1397 | set_h_grow_direction(GrowDirection::GROW_DIRECTION_BOTH); |
| 1398 | break; |
| 1399 | } |
| 1400 | |
| 1401 | // Select correct vertical grow direction. |
| 1402 | switch (p_preset) { |
| 1403 | case PRESET_TOP_LEFT: |
| 1404 | case PRESET_TOP_RIGHT: |
| 1405 | case PRESET_CENTER_TOP: |
| 1406 | case PRESET_TOP_WIDE: |
| 1407 | set_v_grow_direction(GrowDirection::GROW_DIRECTION_END); |
| 1408 | break; |
| 1409 | |
| 1410 | case PRESET_BOTTOM_LEFT: |
| 1411 | case PRESET_BOTTOM_RIGHT: |
| 1412 | case PRESET_CENTER_BOTTOM: |
| 1413 | case PRESET_BOTTOM_WIDE: |
| 1414 | set_v_grow_direction(GrowDirection::GROW_DIRECTION_BEGIN); |
| 1415 | break; |
| 1416 | |
| 1417 | case PRESET_CENTER_LEFT: |
| 1418 | case PRESET_CENTER_RIGHT: |
| 1419 | case PRESET_CENTER: |
| 1420 | case PRESET_LEFT_WIDE: |
| 1421 | case PRESET_RIGHT_WIDE: |
| 1422 | case PRESET_VCENTER_WIDE: |
| 1423 | case PRESET_HCENTER_WIDE: |
| 1424 | case PRESET_FULL_RECT: |
| 1425 | set_v_grow_direction(GrowDirection::GROW_DIRECTION_BOTH); |
| 1426 | break; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | /// Manual positioning. |
| 1431 | |
| 1432 | void Control::_set_position(const Point2 &p_point) { |
| 1433 | set_position(p_point); |
| 1434 | } |
| 1435 | |
| 1436 | void Control::set_position(const Point2 &p_point, bool p_keep_offsets) { |
| 1437 | ERR_MAIN_THREAD_GUARD; |
| 1438 | |
| 1439 | #ifdef TOOLS_ENABLED |
| 1440 | // Can't compute anchors, set position directly and return immediately. |
| 1441 | if (saving && !is_inside_tree()) { |
| 1442 | data.pos_cache = p_point; |
| 1443 | return; |
| 1444 | } |
| 1445 | #endif // TOOLS_ENABLED |
| 1446 | |
| 1447 | if (p_keep_offsets) { |
| 1448 | _compute_anchors(Rect2(p_point, data.size_cache), data.offset, data.anchor); |
| 1449 | } else { |
| 1450 | _compute_offsets(Rect2(p_point, data.size_cache), data.anchor, data.offset); |
| 1451 | } |
| 1452 | _size_changed(); |
| 1453 | } |
| 1454 | |
| 1455 | Size2 Control::get_position() const { |
| 1456 | ERR_READ_THREAD_GUARD_V(Size2()); |
| 1457 | return data.pos_cache; |
| 1458 | } |
| 1459 | |
| 1460 | void Control::_set_global_position(const Point2 &p_point) { |
| 1461 | set_global_position(p_point); |
| 1462 | } |
| 1463 | |
| 1464 | void Control::set_global_position(const Point2 &p_point, bool p_keep_offsets) { |
| 1465 | ERR_MAIN_THREAD_GUARD; |
| 1466 | // (parent_global_transform * T(new_position) * internal_transform).origin == new_global_position |
| 1467 | // (T(new_position) * internal_transform).origin == new_position_in_parent_space |
| 1468 | // new_position == new_position_in_parent_space - internal_transform.origin |
| 1469 | Point2 position_in_parent_space = data.parent_canvas_item ? data.parent_canvas_item->get_global_transform().affine_inverse().xform(p_point) : p_point; |
| 1470 | set_position(position_in_parent_space - _get_internal_transform().get_origin(), p_keep_offsets); |
| 1471 | } |
| 1472 | |
| 1473 | Point2 Control::get_global_position() const { |
| 1474 | ERR_READ_THREAD_GUARD_V(Point2()); |
| 1475 | return get_global_transform().get_origin(); |
| 1476 | } |
| 1477 | |
| 1478 | Point2 Control::get_screen_position() const { |
| 1479 | ERR_READ_THREAD_GUARD_V(Point2()); |
| 1480 | ERR_FAIL_COND_V(!is_inside_tree(), Point2()); |
| 1481 | return get_screen_transform().get_origin(); |
| 1482 | } |
| 1483 | |
| 1484 | void Control::_set_size(const Size2 &p_size) { |
| 1485 | #ifdef DEBUG_ENABLED |
| 1486 | if (data.size_warning && (data.anchor[SIDE_LEFT] != data.anchor[SIDE_RIGHT] || data.anchor[SIDE_TOP] != data.anchor[SIDE_BOTTOM])) { |
| 1487 | WARN_PRINT("Nodes with non-equal opposite anchors will have their size overridden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred()."); |
| 1488 | } |
| 1489 | #endif // DEBUG_ENABLED |
| 1490 | set_size(p_size); |
| 1491 | } |
| 1492 | |
| 1493 | void Control::set_size(const Size2 &p_size, bool p_keep_offsets) { |
| 1494 | ERR_MAIN_THREAD_GUARD; |
| 1495 | ERR_FAIL_COND(!std::isfinite(p_size.x) || !std::isfinite(p_size.y)); |
| 1496 | Size2 new_size = p_size; |
| 1497 | Size2 min = get_combined_minimum_size(); |
| 1498 | if (new_size.x < min.x) { |
| 1499 | new_size.x = min.x; |
| 1500 | } |
| 1501 | if (new_size.y < min.y) { |
| 1502 | new_size.y = min.y; |
| 1503 | } |
| 1504 | |
| 1505 | #ifdef TOOLS_ENABLED |
| 1506 | // Can't compute anchors, set size directly and return immediately. |
| 1507 | if (saving && !is_inside_tree()) { |
| 1508 | data.size_cache = new_size; |
| 1509 | return; |
| 1510 | } |
| 1511 | #endif // TOOLS_ENABLED |
| 1512 | |
| 1513 | if (p_keep_offsets) { |
| 1514 | _compute_anchors(Rect2(data.pos_cache, new_size), data.offset, data.anchor); |
| 1515 | } else { |
| 1516 | _compute_offsets(Rect2(data.pos_cache, new_size), data.anchor, data.offset); |
| 1517 | } |
| 1518 | _size_changed(); |
| 1519 | } |
| 1520 | |
| 1521 | Size2 Control::get_size() const { |
| 1522 | ERR_READ_THREAD_GUARD_V(Size2()); |
| 1523 | return data.size_cache; |
| 1524 | } |
| 1525 | |
| 1526 | void Control::reset_size() { |
| 1527 | ERR_MAIN_THREAD_GUARD; |
| 1528 | set_size(Size2()); |
| 1529 | } |
| 1530 | |
| 1531 | void Control::set_rect(const Rect2 &p_rect) { |
| 1532 | ERR_MAIN_THREAD_GUARD; |
| 1533 | for (int i = 0; i < 4; i++) { |
| 1534 | data.anchor[i] = ANCHOR_BEGIN; |
| 1535 | } |
| 1536 | |
| 1537 | _compute_offsets(p_rect, data.anchor, data.offset); |
| 1538 | if (is_inside_tree()) { |
| 1539 | _size_changed(); |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | Rect2 Control::get_rect() const { |
| 1544 | ERR_READ_THREAD_GUARD_V(Rect2()); |
| 1545 | Transform2D xform = get_transform(); |
| 1546 | return Rect2(xform.get_origin(), xform.get_scale() * get_size()); |
| 1547 | } |
| 1548 | |
| 1549 | Rect2 Control::get_global_rect() const { |
| 1550 | ERR_READ_THREAD_GUARD_V(Rect2()); |
| 1551 | Transform2D xform = get_global_transform(); |
| 1552 | return Rect2(xform.get_origin(), xform.get_scale() * get_size()); |
| 1553 | } |
| 1554 | |
| 1555 | Rect2 Control::get_screen_rect() const { |
| 1556 | ERR_READ_THREAD_GUARD_V(Rect2()); |
| 1557 | ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); |
| 1558 | |
| 1559 | Transform2D xform = get_screen_transform(); |
| 1560 | return Rect2(xform.get_origin(), xform.get_scale() * get_size()); |
| 1561 | } |
| 1562 | |
| 1563 | Rect2 Control::get_anchorable_rect() const { |
| 1564 | ERR_READ_THREAD_GUARD_V(Rect2()); |
| 1565 | return Rect2(Point2(), get_size()); |
| 1566 | } |
| 1567 | |
| 1568 | void Control::set_scale(const Vector2 &p_scale) { |
| 1569 | ERR_MAIN_THREAD_GUARD; |
| 1570 | if (data.scale == p_scale) { |
| 1571 | return; |
| 1572 | } |
| 1573 | |
| 1574 | data.scale = p_scale; |
| 1575 | // Avoid having 0 scale values, can lead to errors in physics and rendering. |
| 1576 | if (data.scale.x == 0) { |
| 1577 | data.scale.x = CMP_EPSILON; |
| 1578 | } |
| 1579 | if (data.scale.y == 0) { |
| 1580 | data.scale.y = CMP_EPSILON; |
| 1581 | } |
| 1582 | queue_redraw(); |
| 1583 | _notify_transform(); |
| 1584 | queue_accessibility_update(); |
| 1585 | } |
| 1586 | |
| 1587 | Vector2 Control::get_scale() const { |
| 1588 | ERR_READ_THREAD_GUARD_V(Vector2()); |
| 1589 | return data.scale; |
| 1590 | } |
| 1591 | |
| 1592 | void Control::set_rotation(real_t p_radians) { |
| 1593 | ERR_MAIN_THREAD_GUARD; |
| 1594 | if (data.rotation == p_radians) { |
| 1595 | return; |
| 1596 | } |
| 1597 | |
| 1598 | data.rotation = p_radians; |
| 1599 | queue_redraw(); |
| 1600 | _notify_transform(); |
| 1601 | queue_accessibility_update(); |
| 1602 | } |
| 1603 | |
| 1604 | void Control::set_rotation_degrees(real_t p_degrees) { |
| 1605 | ERR_MAIN_THREAD_GUARD; |
| 1606 | set_rotation(Math::deg_to_rad(p_degrees)); |
| 1607 | } |
| 1608 | |
| 1609 | real_t Control::get_rotation() const { |
| 1610 | ERR_READ_THREAD_GUARD_V(0); |
| 1611 | return data.rotation; |
| 1612 | } |
| 1613 | |
| 1614 | real_t Control::get_rotation_degrees() const { |
| 1615 | ERR_READ_THREAD_GUARD_V(0); |
| 1616 | return Math::rad_to_deg(get_rotation()); |
| 1617 | } |
| 1618 | |
| 1619 | void Control::set_pivot_offset_ratio(const Vector2 &p_ratio) { |
| 1620 | ERR_MAIN_THREAD_GUARD; |
| 1621 | if (data.pivot_offset_ratio == p_ratio) { |
| 1622 | return; |
| 1623 | } |
| 1624 | |
| 1625 | data.pivot_offset_ratio = p_ratio; |
| 1626 | queue_redraw(); |
| 1627 | _notify_transform(); |
| 1628 | queue_accessibility_update(); |
| 1629 | } |
| 1630 | |
| 1631 | Vector2 Control::get_pivot_offset_ratio() const { |
| 1632 | ERR_READ_THREAD_GUARD_V(Vector2()); |
| 1633 | return data.pivot_offset_ratio; |
| 1634 | } |
| 1635 | |
| 1636 | void Control::set_pivot_offset(const Vector2 &p_pivot) { |
| 1637 | ERR_MAIN_THREAD_GUARD; |
| 1638 | if (data.pivot_offset == p_pivot) { |
| 1639 | return; |
| 1640 | } |
| 1641 | |
| 1642 | data.pivot_offset = p_pivot; |
| 1643 | queue_redraw(); |
| 1644 | _notify_transform(); |
| 1645 | queue_accessibility_update(); |
| 1646 | } |
| 1647 | |
| 1648 | Vector2 Control::get_pivot_offset() const { |
| 1649 | ERR_READ_THREAD_GUARD_V(Vector2()); |
| 1650 | return data.pivot_offset; |
| 1651 | } |
| 1652 | |
| 1653 | Vector2 Control::get_combined_pivot_offset() const { |
| 1654 | ERR_READ_THREAD_GUARD_V(Vector2()); |
| 1655 | return data.pivot_offset + data.pivot_offset_ratio * get_size(); |
| 1656 | } |
| 1657 | |
| 1658 | /// Sizes. |
| 1659 | |
| 1660 | void Control::_update_minimum_size() { |
| 1661 | if (!is_inside_tree()) { |
| 1662 | data.updating_last_minimum_size = false; |
| 1663 | return; |
| 1664 | } |
| 1665 | |
| 1666 | Size2 minsize = get_combined_minimum_size(); |
| 1667 | data.updating_last_minimum_size = false; |
| 1668 | |
| 1669 | if (minsize != data.last_minimum_size) { |
| 1670 | data.last_minimum_size = minsize; |
| 1671 | _size_changed(); |
| 1672 | emit_signal(SceneStringName(minimum_size_changed)); |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | void Control::update_minimum_size() { |
| 1677 | ERR_MAIN_THREAD_GUARD; |
| 1678 | if (!is_inside_tree() || data.block_minimum_size_adjust) { |
| 1679 | return; |
| 1680 | } |
| 1681 | |
| 1682 | // Invalidate cache upwards. |
| 1683 | Control *invalidate = this; |
| 1684 | while (invalidate && invalidate->data.minimum_size_valid) { |
| 1685 | invalidate->data.minimum_size_valid = false; |
| 1686 | if (invalidate->is_set_as_top_level()) { |
| 1687 | break; // Do not go further up. |
| 1688 | } |
| 1689 | |
| 1690 | Window *parent_window = invalidate->get_parent_window(); |
| 1691 | if (parent_window && parent_window->is_wrapping_controls()) { |
| 1692 | parent_window->child_controls_changed(); |
| 1693 | break; // Stop on a window as well. |
| 1694 | } |
| 1695 | |
| 1696 | invalidate = invalidate->get_parent_control(); |
| 1697 | } |
| 1698 | |
| 1699 | if (!is_visible_in_tree()) { |
| 1700 | return; |
| 1701 | } |
| 1702 | |
| 1703 | if (data.updating_last_minimum_size) { |
| 1704 | return; |
| 1705 | } |
| 1706 | data.updating_last_minimum_size = true; |
| 1707 | |
| 1708 | callable_mp(this, &Control::_update_minimum_size).call_deferred(); |
| 1709 | } |
| 1710 | |
| 1711 | void Control::set_block_minimum_size_adjust(bool p_block) { |
| 1712 | ERR_MAIN_THREAD_GUARD; |
| 1713 | data.block_minimum_size_adjust = p_block; |
| 1714 | } |
| 1715 | |
| 1716 | Size2 Control::get_minimum_size() const { |
| 1717 | ERR_READ_THREAD_GUARD_V(Size2()); |
| 1718 | Vector2 ms; |
| 1719 | GDVIRTUAL_CALL(_get_minimum_size, ms); |
| 1720 | return ms; |
| 1721 | } |
| 1722 | |
| 1723 | void Control::set_custom_minimum_size(const Size2 &p_custom) { |
| 1724 | ERR_MAIN_THREAD_GUARD; |
| 1725 | if (p_custom == data.custom_minimum_size) { |
| 1726 | return; |
| 1727 | } |
| 1728 | |
| 1729 | if (!std::isfinite(p_custom.x) || !std::isfinite(p_custom.y)) { |
| 1730 | // Prevent infinite loop. |
| 1731 | return; |
| 1732 | } |
| 1733 | |
| 1734 | data.custom_minimum_size = p_custom; |
| 1735 | update_minimum_size(); |
| 1736 | update_configuration_warnings(); |
| 1737 | } |
| 1738 | |
| 1739 | Size2 Control::get_custom_minimum_size() const { |
| 1740 | ERR_READ_THREAD_GUARD_V(Size2()); |
| 1741 | return data.custom_minimum_size; |
| 1742 | } |
| 1743 | |
| 1744 | void Control::_update_minimum_size_cache() const { |
| 1745 | Size2 minsize = get_minimum_size(); |
| 1746 | minsize = minsize.max(data.custom_minimum_size); |
| 1747 | |
| 1748 | data.minimum_size_cache = minsize; |
| 1749 | data.minimum_size_valid = true; |
| 1750 | } |
| 1751 | |
| 1752 | Size2 Control::get_combined_minimum_size() const { |
| 1753 | ERR_READ_THREAD_GUARD_V(Size2()); |
| 1754 | if (!data.minimum_size_valid) { |
| 1755 | _update_minimum_size_cache(); |
| 1756 | } |
| 1757 | return data.minimum_size_cache; |
| 1758 | } |
| 1759 | |
| 1760 | void Control::_size_changed() { |
| 1761 | Rect2 parent_rect = get_parent_anchorable_rect(); |
| 1762 | |
| 1763 | real_t edge_pos[4]; |
| 1764 | |
| 1765 | for (int i = 0; i < 4; i++) { |
| 1766 | real_t area = parent_rect.size[i & 1]; |
| 1767 | edge_pos[i] = data.offset[i] + (data.anchor[i] * area); |
| 1768 | } |
| 1769 | |
| 1770 | Point2 new_pos_cache = Point2(edge_pos[0], edge_pos[1]); |
| 1771 | Size2 new_size_cache = Point2(edge_pos[2], edge_pos[3]) - new_pos_cache; |
| 1772 | |
| 1773 | Size2 minimum_size = get_combined_minimum_size(); |
| 1774 | |
| 1775 | if (minimum_size.width > new_size_cache.width) { |
| 1776 | if (data.h_grow == GROW_DIRECTION_BEGIN) { |
| 1777 | new_pos_cache.x += new_size_cache.width - minimum_size.width; |
| 1778 | } else if (data.h_grow == GROW_DIRECTION_BOTH) { |
| 1779 | new_pos_cache.x += 0.5 * (new_size_cache.width - minimum_size.width); |
| 1780 | } |
| 1781 | |
| 1782 | new_size_cache.width = minimum_size.width; |
| 1783 | } |
| 1784 | |
| 1785 | if (is_layout_rtl()) { |
| 1786 | new_pos_cache.x = parent_rect.size.x + 2 * parent_rect.position.x - new_pos_cache.x - new_size_cache.x; |
| 1787 | } |
| 1788 | |
| 1789 | if (minimum_size.height > new_size_cache.height) { |
| 1790 | if (data.v_grow == GROW_DIRECTION_BEGIN) { |
| 1791 | new_pos_cache.y += new_size_cache.height - minimum_size.height; |
| 1792 | } else if (data.v_grow == GROW_DIRECTION_BOTH) { |
| 1793 | new_pos_cache.y += 0.5 * (new_size_cache.height - minimum_size.height); |
| 1794 | } |
| 1795 | |
| 1796 | new_size_cache.height = minimum_size.height; |
| 1797 | } |
| 1798 | |
| 1799 | bool pos_changed = new_pos_cache != data.pos_cache; |
| 1800 | bool size_changed = new_size_cache != data.size_cache; |
| 1801 | // Below helps in getting rid of floating point errors for signaling resized. |
| 1802 | bool approx_pos_changed = !new_pos_cache.is_equal_approx(data.pos_cache); |
| 1803 | bool approx_size_changed = !new_size_cache.is_equal_approx(data.size_cache); |
| 1804 | |
| 1805 | if (pos_changed) { |
| 1806 | data.pos_cache = new_pos_cache; |
| 1807 | } |
| 1808 | if (size_changed) { |
| 1809 | data.size_cache = new_size_cache; |
| 1810 | } |
| 1811 | |
| 1812 | if (is_inside_tree()) { |
| 1813 | if (approx_pos_changed || approx_size_changed) { |
| 1814 | // Ensure global transform is marked as dirty before `NOTIFICATION_RESIZED` / `item_rect_changed` signal |
| 1815 | // so an up to date global transform could be obtained when handling these. |
| 1816 | _notify_transform(); |
| 1817 | |
| 1818 | item_rect_changed(approx_size_changed); |
| 1819 | if (approx_size_changed) { |
| 1820 | notification(NOTIFICATION_RESIZED); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | if (pos_changed && !approx_size_changed) { |
| 1825 | _update_canvas_item_transform(); |
| 1826 | } |
| 1827 | |
| 1828 | queue_accessibility_update(); |
| 1829 | } else if (pos_changed) { |
| 1830 | _notify_transform(); |
| 1831 | } |
| 1832 | } |
| 1833 | |
| 1834 | void Control::_clear_size_warning() { |
| 1835 | data.size_warning = false; |
| 1836 | } |
| 1837 | |
| 1838 | // Container sizing. |
| 1839 | |
| 1840 | void Control::set_h_size_flags(BitField<SizeFlags> p_flags) { |
| 1841 | ERR_MAIN_THREAD_GUARD; |
| 1842 | if ((int)data.h_size_flags == (int)p_flags) { |
| 1843 | return; |
| 1844 | } |
| 1845 | data.h_size_flags = p_flags; |
| 1846 | emit_signal(SceneStringName(size_flags_changed)); |
| 1847 | } |
| 1848 | |
| 1849 | BitField<Control::SizeFlags> Control::get_h_size_flags() const { |
| 1850 | ERR_READ_THREAD_GUARD_V(SIZE_EXPAND_FILL); |
| 1851 | return data.h_size_flags; |
| 1852 | } |
| 1853 | |
| 1854 | void Control::set_v_size_flags(BitField<SizeFlags> p_flags) { |
| 1855 | ERR_MAIN_THREAD_GUARD; |
| 1856 | if ((int)data.v_size_flags == (int)p_flags) { |
| 1857 | return; |
| 1858 | } |
| 1859 | data.v_size_flags = p_flags; |
| 1860 | emit_signal(SceneStringName(size_flags_changed)); |
| 1861 | } |
| 1862 | |
| 1863 | BitField<Control::SizeFlags> Control::get_v_size_flags() const { |
| 1864 | ERR_READ_THREAD_GUARD_V(SIZE_EXPAND_FILL); |
| 1865 | return data.v_size_flags; |
| 1866 | } |
| 1867 | |
| 1868 | void Control::set_stretch_ratio(real_t p_ratio) { |
| 1869 | ERR_MAIN_THREAD_GUARD; |
| 1870 | if (data.expand == p_ratio) { |
| 1871 | return; |
| 1872 | } |
| 1873 | |
| 1874 | data.expand = p_ratio; |
| 1875 | emit_signal(SceneStringName(size_flags_changed)); |
| 1876 | } |
| 1877 | |
| 1878 | real_t Control::get_stretch_ratio() const { |
| 1879 | ERR_READ_THREAD_GUARD_V(0); |
| 1880 | return data.expand; |
| 1881 | } |
| 1882 | |
| 1883 | // Input events. |
| 1884 | |
| 1885 | void Control::_call_gui_input(const Ref<InputEvent> &p_event) { |
| 1886 | if (p_event->get_device() != InputEvent::DEVICE_ID_INTERNAL) { |
| 1887 | emit_signal(SceneStringName(gui_input), p_event); // Signal should be first, so it's possible to override an event (and then accept it). |
| 1888 | } |
| 1889 | if (!is_inside_tree() || get_viewport()->is_input_handled()) { |
| 1890 | return; // Input was handled, abort. |
| 1891 | } |
| 1892 | |
| 1893 | if (p_event->get_device() != InputEvent::DEVICE_ID_INTERNAL) { |
| 1894 | GDVIRTUAL_CALL(_gui_input, p_event); |
| 1895 | } |
| 1896 | if (!is_inside_tree() || get_viewport()->is_input_handled()) { |
| 1897 | return; // Input was handled, abort. |
| 1898 | } |
| 1899 | gui_input(p_event); |
| 1900 | } |
| 1901 | |
| 1902 | void Control::gui_input(const Ref<InputEvent> &p_event) { |
| 1903 | } |
| 1904 | |
| 1905 | void Control::accept_event() { |
| 1906 | ERR_MAIN_THREAD_GUARD; |
| 1907 | if (is_inside_tree()) { |
| 1908 | get_viewport()->_gui_accept_event(); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | bool Control::has_point(const Point2 &p_point) const { |
| 1913 | ERR_READ_THREAD_GUARD_V(false); |
| 1914 | bool ret; |
| 1915 | if (GDVIRTUAL_CALL(_has_point, p_point, ret)) { |
| 1916 | return ret; |
| 1917 | } |
| 1918 | return Rect2(Point2(), get_size()).has_point(p_point); |
| 1919 | } |
| 1920 | |
| 1921 | void Control::set_mouse_filter(MouseFilter p_filter) { |
| 1922 | ERR_MAIN_THREAD_GUARD; |
| 1923 | ERR_FAIL_INDEX(p_filter, 3); |
| 1924 | |
| 1925 | if (data.mouse_filter == p_filter) { |
| 1926 | return; |
| 1927 | } |
| 1928 | |
| 1929 | data.mouse_filter = p_filter; |
| 1930 | notify_property_list_changed(); |
| 1931 | update_configuration_warnings(); |
| 1932 | |
| 1933 | if (get_viewport()) { |
| 1934 | get_viewport()->_gui_update_mouse_over(); |
| 1935 | } |
| 1936 | } |
| 1937 | |
| 1938 | Control::MouseFilter Control::get_mouse_filter() const { |
| 1939 | ERR_READ_THREAD_GUARD_V(MOUSE_FILTER_IGNORE); |
| 1940 | return data.mouse_filter; |
| 1941 | } |
| 1942 | |
| 1943 | Control::MouseFilter Control::get_mouse_filter_with_override() const { |
| 1944 | ERR_READ_THREAD_GUARD_V(MOUSE_FILTER_IGNORE); |
| 1945 | if (!_is_mouse_filter_enabled()) { |
| 1946 | return MOUSE_FILTER_IGNORE; |
| 1947 | } |
| 1948 | return data.mouse_filter; |
| 1949 | } |
| 1950 | |
| 1951 | void Control::set_mouse_behavior_recursive(MouseBehaviorRecursive p_mouse_behavior_recursive) { |
| 1952 | ERR_MAIN_THREAD_GUARD; |
| 1953 | ERR_FAIL_INDEX(p_mouse_behavior_recursive, 3); |
| 1954 | if (data.mouse_behavior_recursive == p_mouse_behavior_recursive) { |
| 1955 | return; |
| 1956 | } |
| 1957 | data.mouse_behavior_recursive = p_mouse_behavior_recursive; |
| 1958 | _update_mouse_behavior_recursive(); |
| 1959 | } |
| 1960 | |
| 1961 | Control::MouseBehaviorRecursive Control::get_mouse_behavior_recursive() const { |
| 1962 | ERR_READ_THREAD_GUARD_V(MOUSE_BEHAVIOR_INHERITED); |
| 1963 | return data.mouse_behavior_recursive; |
| 1964 | } |
| 1965 | |
| 1966 | bool Control::_is_mouse_filter_enabled() const { |
| 1967 | ERR_READ_THREAD_GUARD_V(false); |
| 1968 | if (data.mouse_behavior_recursive == MOUSE_BEHAVIOR_INHERITED) { |
| 1969 | if (data.parent_control) { |
| 1970 | return data.parent_mouse_behavior_recursive_enabled; |
| 1971 | } |
| 1972 | return true; |
| 1973 | } |
| 1974 | return data.mouse_behavior_recursive == MOUSE_BEHAVIOR_ENABLED; |
| 1975 | } |
| 1976 | |
| 1977 | void Control::_update_mouse_behavior_recursive() { |
| 1978 | if (data.mouse_behavior_recursive == MOUSE_BEHAVIOR_INHERITED) { |
| 1979 | if (data.parent_control) { |
| 1980 | _propagate_mouse_behavior_recursive_recursively(data.parent_control->_is_mouse_filter_enabled(), false); |
| 1981 | } else { |
| 1982 | _propagate_mouse_behavior_recursive_recursively(true, false); |
| 1983 | } |
| 1984 | } else { |
| 1985 | _propagate_mouse_behavior_recursive_recursively(data.mouse_behavior_recursive == MOUSE_BEHAVIOR_ENABLED, false); |
| 1986 | } |
| 1987 | if (get_viewport()) { |
| 1988 | get_viewport()->_gui_update_mouse_over(); |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | void Control::_propagate_mouse_behavior_recursive_recursively(bool p_enabled, bool p_skip_non_inherited) { |
| 1993 | if (p_skip_non_inherited && data.mouse_behavior_recursive != MOUSE_BEHAVIOR_INHERITED) { |
| 1994 | return; |
| 1995 | } |
| 1996 | |
| 1997 | data.parent_mouse_behavior_recursive_enabled = p_enabled; |
| 1998 | for (int i = 0; i < get_child_count(); i++) { |
| 1999 | Control *control = Object::cast_to<Control>(get_child(i)); |
| 2000 | if (control) { |
| 2001 | control->_propagate_mouse_behavior_recursive_recursively(p_enabled, true); |
| 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | void Control::set_force_pass_scroll_events(bool p_force_pass_scroll_events) { |
| 2007 | ERR_MAIN_THREAD_GUARD; |
| 2008 | data.force_pass_scroll_events = p_force_pass_scroll_events; |
| 2009 | } |
| 2010 | |
| 2011 | bool Control::is_force_pass_scroll_events() const { |
| 2012 | ERR_READ_THREAD_GUARD_V(false); |
| 2013 | return data.force_pass_scroll_events; |
| 2014 | } |
| 2015 | |
| 2016 | void Control::warp_mouse(const Point2 &p_position) { |
| 2017 | ERR_MAIN_THREAD_GUARD; |
| 2018 | ERR_FAIL_COND(!is_inside_tree()); |
| 2019 | get_viewport()->warp_mouse(get_global_transform_with_canvas().xform(p_position)); |
| 2020 | } |
| 2021 | |
| 2022 | void Control::set_shortcut_context(const Node *p_node) { |
| 2023 | ERR_MAIN_THREAD_GUARD; |
| 2024 | if (p_node != nullptr) { |
| 2025 | data.shortcut_context = p_node->get_instance_id(); |
| 2026 | } else { |
| 2027 | data.shortcut_context = ObjectID(); |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | Node *Control::get_shortcut_context() const { |
| 2032 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 2033 | Object *ctx_obj = ObjectDB::get_instance(data.shortcut_context); |
| 2034 | Node *ctx_node = Object::cast_to<Node>(ctx_obj); |
| 2035 | |
| 2036 | return ctx_node; |
| 2037 | } |
| 2038 | |
| 2039 | bool Control::is_focus_owner_in_shortcut_context() const { |
| 2040 | ERR_READ_THREAD_GUARD_V(false); |
| 2041 | if (data.shortcut_context == ObjectID()) { |
| 2042 | // No context, therefore global - always "in" context. |
| 2043 | return true; |
| 2044 | } |
| 2045 | |
| 2046 | const Node *ctx_node = get_shortcut_context(); |
| 2047 | const Control *vp_focus = get_viewport() ? get_viewport()->gui_get_focus_owner() : nullptr; |
| 2048 | |
| 2049 | // If the context is valid and the viewport focus is valid, check if the context is the focus or is a parent of it. |
| 2050 | return ctx_node && vp_focus && (ctx_node == vp_focus || ctx_node->is_ancestor_of(vp_focus)); |
| 2051 | } |
| 2052 | |
| 2053 | // Drag and drop handling. |
| 2054 | |
| 2055 | void Control::set_drag_forwarding(const Callable &p_drag, const Callable &p_can_drop, const Callable &p_drop) { |
| 2056 | ERR_MAIN_THREAD_GUARD; |
| 2057 | data.forward_drag = p_drag; |
| 2058 | data.forward_can_drop = p_can_drop; |
| 2059 | data.forward_drop = p_drop; |
| 2060 | } |
| 2061 | |
| 2062 | Variant Control::get_drag_data(const Point2 &p_point) { |
| 2063 | ERR_READ_THREAD_GUARD_V(Variant()); |
| 2064 | Variant ret; |
| 2065 | if (data.forward_drag.is_valid()) { |
| 2066 | Variant p = p_point; |
| 2067 | const Variant *vp[1] = { &p }; |
| 2068 | Callable::CallError ce; |
| 2069 | data.forward_drag.callp((const Variant **)vp, 1, ret, ce); |
| 2070 | if (ce.error != Callable::CallError::CALL_OK) { |
| 2071 | ERR_FAIL_V_MSG(Variant(), "Error calling forwarded method from 'get_drag_data': " + Variant::get_callable_error_text(data.forward_drag, (const Variant **)vp, 1, ce) + "."); |
| 2072 | } |
| 2073 | return ret; |
| 2074 | } |
| 2075 | |
| 2076 | GDVIRTUAL_CALL(_get_drag_data, p_point, ret); |
| 2077 | return ret; |
| 2078 | } |
| 2079 | |
| 2080 | bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const { |
| 2081 | ERR_READ_THREAD_GUARD_V(false); |
| 2082 | if (data.forward_can_drop.is_valid()) { |
| 2083 | Variant ret; |
| 2084 | Variant p = p_point; |
| 2085 | const Variant *vp[2] = { &p, &p_data }; |
| 2086 | Callable::CallError ce; |
| 2087 | data.forward_can_drop.callp((const Variant **)vp, 2, ret, ce); |
| 2088 | if (ce.error != Callable::CallError::CALL_OK) { |
| 2089 | ERR_FAIL_V_MSG(Variant(), "Error calling forwarded method from 'can_drop_data': " + Variant::get_callable_error_text(data.forward_can_drop, (const Variant **)vp, 2, ce) + "."); |
| 2090 | } |
| 2091 | return ret; |
| 2092 | } |
| 2093 | |
| 2094 | bool ret = false; |
| 2095 | GDVIRTUAL_CALL(_can_drop_data, p_point, p_data, ret); |
| 2096 | return ret; |
| 2097 | } |
| 2098 | |
| 2099 | void Control::drop_data(const Point2 &p_point, const Variant &p_data) { |
| 2100 | ERR_READ_THREAD_GUARD; |
| 2101 | if (data.forward_drop.is_valid()) { |
| 2102 | Variant ret; |
| 2103 | Variant p = p_point; |
| 2104 | const Variant *vp[2] = { &p, &p_data }; |
| 2105 | Callable::CallError ce; |
| 2106 | data.forward_drop.callp((const Variant **)vp, 2, ret, ce); |
| 2107 | if (ce.error != Callable::CallError::CALL_OK) { |
| 2108 | ERR_FAIL_MSG("Error calling forwarded method from 'drop_data': " + Variant::get_callable_error_text(data.forward_drop, (const Variant **)vp, 2, ce) + "."); |
| 2109 | } |
| 2110 | return; |
| 2111 | } |
| 2112 | |
| 2113 | GDVIRTUAL_CALL(_drop_data, p_point, p_data); |
| 2114 | } |
| 2115 | |
| 2116 | void Control::force_drag(const Variant &p_data, Control *p_control) { |
| 2117 | ERR_MAIN_THREAD_GUARD; |
| 2118 | ERR_FAIL_COND(!is_inside_tree()); |
| 2119 | ERR_FAIL_COND(p_data.get_type() == Variant::NIL); |
| 2120 | |
| 2121 | Viewport *vp = get_viewport(); |
| 2122 | |
| 2123 | vp->_gui_force_drag_start(); |
| 2124 | vp->_gui_force_drag(this, p_data, p_control); |
| 2125 | } |
| 2126 | |
| 2127 | void Control::accessibility_drag() { |
| 2128 | ERR_MAIN_THREAD_GUARD; |
| 2129 | ERR_FAIL_COND(!is_inside_tree()); |
| 2130 | |
| 2131 | Viewport *vp = get_viewport(); |
| 2132 | |
| 2133 | vp->_gui_force_drag_start(); |
| 2134 | Variant dnd_data = get_drag_data(Vector2(Math::INF, Math::INF)); |
| 2135 | if (dnd_data.get_type() != Variant::NIL) { |
| 2136 | Window *w = Window::get_from_id(get_window()->get_window_id()); |
| 2137 | if (w) { |
| 2138 | w->accessibility_announcement(vformat(RTR("%s grabbed. Select target and use %s to drop, use %s to cancel."), vp->gui_get_drag_description(), InputMap::get_singleton()->get_action_description("ui_accessibility_drag_and_drop"), InputMap::get_singleton()->get_action_description("ui_cancel"))); |
| 2139 | } |
| 2140 | vp->_gui_force_drag(this, dnd_data, nullptr); |
| 2141 | queue_accessibility_update(); |
| 2142 | } else { |
| 2143 | vp->_gui_force_drag_cancel(); |
| 2144 | } |
| 2145 | } |
| 2146 | |
| 2147 | void Control::accessibility_drop() { |
| 2148 | ERR_MAIN_THREAD_GUARD; |
| 2149 | ERR_FAIL_COND(!is_inside_tree()); |
| 2150 | ERR_FAIL_COND(!get_viewport()->gui_is_dragging()); |
| 2151 | |
| 2152 | get_viewport()->gui_perform_drop_at(Vector2(Math::INF, Math::INF), this); |
| 2153 | |
| 2154 | queue_accessibility_update(); |
| 2155 | } |
| 2156 | |
| 2157 | String Control::get_accessibility_container_name(const Node *p_node) const { |
| 2158 | String ret; |
| 2159 | if (GDVIRTUAL_CALL(_get_accessibility_container_name, p_node, ret)) { |
| 2160 | } else if (data.parent_control) { |
| 2161 | ret = data.parent_control->get_accessibility_container_name(this); |
| 2162 | } |
| 2163 | return ret; |
| 2164 | } |
| 2165 | |
| 2166 | void Control::set_accessibility_name(const String &p_name) { |
| 2167 | ERR_THREAD_GUARD |
| 2168 | if (data.accessibility_name != p_name) { |
| 2169 | data.accessibility_name = p_name; |
| 2170 | queue_accessibility_update(); |
| 2171 | update_configuration_warnings(); |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | String Control::get_accessibility_name() const { |
| 2176 | return tr(data.accessibility_name); |
| 2177 | } |
| 2178 | |
| 2179 | void Control::set_accessibility_description(const String &p_description) { |
| 2180 | ERR_THREAD_GUARD |
| 2181 | if (data.accessibility_description != p_description) { |
| 2182 | data.accessibility_description = p_description; |
| 2183 | queue_accessibility_update(); |
| 2184 | } |
| 2185 | } |
| 2186 | |
| 2187 | String Control::get_accessibility_description() const { |
| 2188 | return tr(data.accessibility_description); |
| 2189 | } |
| 2190 | |
| 2191 | void Control::set_accessibility_live(DisplayServer::AccessibilityLiveMode p_mode) { |
| 2192 | ERR_THREAD_GUARD |
| 2193 | if (data.accessibility_live != p_mode) { |
| 2194 | data.accessibility_live = p_mode; |
| 2195 | queue_accessibility_update(); |
| 2196 | } |
| 2197 | } |
| 2198 | |
| 2199 | DisplayServer::AccessibilityLiveMode Control::get_accessibility_live() const { |
| 2200 | return data.accessibility_live; |
| 2201 | } |
| 2202 | |
| 2203 | void Control::set_accessibility_controls_nodes(const TypedArray<NodePath> &p_node_path) { |
| 2204 | ERR_MAIN_THREAD_GUARD; |
| 2205 | if (data.accessibility_controls_nodes != p_node_path) { |
| 2206 | data.accessibility_controls_nodes = p_node_path; |
| 2207 | queue_accessibility_update(); |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | TypedArray<NodePath> Control::get_accessibility_controls_nodes() const { |
| 2212 | return data.accessibility_controls_nodes; |
| 2213 | } |
| 2214 | |
| 2215 | void Control::set_accessibility_described_by_nodes(const TypedArray<NodePath> &p_node_path) { |
| 2216 | ERR_MAIN_THREAD_GUARD; |
| 2217 | if (data.accessibility_described_by_nodes != p_node_path) { |
| 2218 | data.accessibility_described_by_nodes = p_node_path; |
| 2219 | queue_accessibility_update(); |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | TypedArray<NodePath> Control::get_accessibility_described_by_nodes() const { |
| 2224 | return data.accessibility_described_by_nodes; |
| 2225 | } |
| 2226 | |
| 2227 | void Control::set_accessibility_labeled_by_nodes(const TypedArray<NodePath> &p_node_path) { |
| 2228 | ERR_MAIN_THREAD_GUARD; |
| 2229 | if (data.accessibility_labeled_by_nodes != p_node_path) { |
| 2230 | data.accessibility_labeled_by_nodes = p_node_path; |
| 2231 | queue_accessibility_update(); |
| 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | TypedArray<NodePath> Control::get_accessibility_labeled_by_nodes() const { |
| 2236 | return data.accessibility_labeled_by_nodes; |
| 2237 | } |
| 2238 | |
| 2239 | void Control::set_accessibility_flow_to_nodes(const TypedArray<NodePath> &p_node_path) { |
| 2240 | ERR_MAIN_THREAD_GUARD; |
| 2241 | if (data.accessibility_flow_to_nodes != p_node_path) { |
| 2242 | data.accessibility_flow_to_nodes = p_node_path; |
| 2243 | queue_accessibility_update(); |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | TypedArray<NodePath> Control::get_accessibility_flow_to_nodes() const { |
| 2248 | return data.accessibility_flow_to_nodes; |
| 2249 | } |
| 2250 | |
| 2251 | void Control::set_drag_preview(Control *p_control) { |
| 2252 | ERR_MAIN_THREAD_GUARD; |
| 2253 | ERR_FAIL_COND(!is_inside_tree()); |
| 2254 | ERR_FAIL_COND(!get_viewport()->gui_is_dragging()); |
| 2255 | get_viewport()->_gui_set_drag_preview(this, p_control); |
| 2256 | } |
| 2257 | |
| 2258 | bool Control::is_drag_successful() const { |
| 2259 | ERR_READ_THREAD_GUARD_V(false); |
| 2260 | return is_inside_tree() && get_viewport()->gui_is_drag_successful(); |
| 2261 | } |
| 2262 | |
| 2263 | // Focus. |
| 2264 | |
| 2265 | void Control::set_focus_mode(FocusMode p_focus_mode) { |
| 2266 | ERR_MAIN_THREAD_GUARD; |
| 2267 | ERR_FAIL_INDEX((int)p_focus_mode, 4); |
| 2268 | |
| 2269 | if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus()) { |
| 2270 | release_focus(); |
| 2271 | } |
| 2272 | |
| 2273 | if (data.focus_mode == p_focus_mode) { |
| 2274 | return; |
| 2275 | } |
| 2276 | data.focus_mode = p_focus_mode; |
| 2277 | queue_accessibility_update(); |
| 2278 | } |
| 2279 | |
| 2280 | Control::FocusMode Control::get_focus_mode() const { |
| 2281 | ERR_READ_THREAD_GUARD_V(FOCUS_NONE); |
| 2282 | return data.focus_mode; |
| 2283 | } |
| 2284 | |
| 2285 | Control::FocusMode Control::get_focus_mode_with_override() const { |
| 2286 | ERR_READ_THREAD_GUARD_V(FOCUS_NONE); |
| 2287 | if (!_is_focus_mode_enabled()) { |
| 2288 | return FOCUS_NONE; |
| 2289 | } |
| 2290 | return data.focus_mode; |
| 2291 | } |
| 2292 | |
| 2293 | void Control::set_focus_behavior_recursive(FocusBehaviorRecursive p_focus_behavior_recursive) { |
| 2294 | ERR_MAIN_THREAD_GUARD; |
| 2295 | ERR_FAIL_INDEX((int)p_focus_behavior_recursive, 3); |
| 2296 | if (data.focus_behavior_recursive == p_focus_behavior_recursive) { |
| 2297 | return; |
| 2298 | } |
| 2299 | data.focus_behavior_recursive = p_focus_behavior_recursive; |
| 2300 | _update_focus_behavior_recursive(); |
| 2301 | queue_accessibility_update(); |
| 2302 | } |
| 2303 | |
| 2304 | Control::FocusBehaviorRecursive Control::get_focus_behavior_recursive() const { |
| 2305 | ERR_READ_THREAD_GUARD_V(FOCUS_BEHAVIOR_INHERITED); |
| 2306 | return data.focus_behavior_recursive; |
| 2307 | } |
| 2308 | |
| 2309 | bool Control::_is_focusable() const { |
| 2310 | bool ac_enabled = is_inside_tree() && get_tree()->is_accessibility_enabled(); |
| 2311 | return (is_visible_in_tree() && ((get_focus_mode_with_override() == FOCUS_ALL) || (get_focus_mode_with_override() == FOCUS_CLICK) || (ac_enabled && get_focus_mode_with_override() == FOCUS_ACCESSIBILITY))); |
| 2312 | } |
| 2313 | |
| 2314 | bool Control::_is_focus_mode_enabled() const { |
| 2315 | if (data.focus_behavior_recursive == FOCUS_BEHAVIOR_INHERITED) { |
| 2316 | if (data.parent_control) { |
| 2317 | return data.parent_focus_behavior_recursive_enabled; |
| 2318 | } |
| 2319 | return true; |
| 2320 | } |
| 2321 | return data.focus_behavior_recursive == FOCUS_BEHAVIOR_ENABLED; |
| 2322 | } |
| 2323 | |
| 2324 | void Control::_update_focus_behavior_recursive() { |
| 2325 | if (data.focus_behavior_recursive == FOCUS_BEHAVIOR_INHERITED) { |
| 2326 | Control *parent = get_parent_control(); |
| 2327 | if (parent) { |
| 2328 | _propagate_focus_behavior_recursive_recursively(parent->_is_focus_mode_enabled(), false); |
| 2329 | } else { |
| 2330 | _propagate_focus_behavior_recursive_recursively(true, false); |
| 2331 | } |
| 2332 | } else { |
| 2333 | _propagate_focus_behavior_recursive_recursively(data.focus_behavior_recursive == FOCUS_BEHAVIOR_ENABLED, false); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | void Control::_propagate_focus_behavior_recursive_recursively(bool p_enabled, bool p_skip_non_inherited) { |
| 2338 | if (is_inside_tree() && (data.focus_behavior_recursive == FOCUS_BEHAVIOR_DISABLED || (data.focus_behavior_recursive == FOCUS_BEHAVIOR_INHERITED && !p_enabled)) && has_focus()) { |
| 2339 | release_focus(); |
| 2340 | } |
| 2341 | |
| 2342 | if (p_skip_non_inherited && data.focus_behavior_recursive != FOCUS_BEHAVIOR_INHERITED) { |
| 2343 | return; |
| 2344 | } |
| 2345 | |
| 2346 | data.parent_focus_behavior_recursive_enabled = p_enabled; |
| 2347 | |
| 2348 | for (int i = 0; i < get_child_count(); i++) { |
| 2349 | Control *control = Object::cast_to<Control>(get_child(i)); |
| 2350 | if (control) { |
| 2351 | control->_propagate_focus_behavior_recursive_recursively(p_enabled, true); |
| 2352 | } |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | bool Control::has_focus(bool p_ignore_hidden_focus) const { |
| 2357 | ERR_READ_THREAD_GUARD_V(false); |
| 2358 | return is_inside_tree() && get_viewport()->_gui_control_has_focus(this, p_ignore_hidden_focus); |
| 2359 | } |
| 2360 | |
| 2361 | void Control::grab_focus(bool p_hide_focus) { |
| 2362 | ERR_MAIN_THREAD_GUARD; |
| 2363 | ERR_FAIL_COND(!is_inside_tree()); |
| 2364 | |
| 2365 | if (get_focus_mode_with_override() == FOCUS_ACCESSIBILITY) { |
| 2366 | if (!get_tree()->is_accessibility_enabled()) { |
| 2367 | WARN_PRINT("This control can grab focus only when screen reader is active. Use set_focus_mode() and set_focus_behavior_recursive() to allow a control to get focus. Use get_tree().is_accessibility_enabled() to check screen-reader state."); |
| 2368 | return; |
| 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | if (get_focus_mode_with_override() == FOCUS_NONE) { |
| 2373 | WARN_PRINT("This control can't grab focus. Use set_focus_mode() and set_focus_behavior_recursive() to allow a control to get focus."); |
| 2374 | return; |
| 2375 | } |
| 2376 | |
| 2377 | get_viewport()->_gui_control_grab_focus(this, p_hide_focus); |
| 2378 | } |
| 2379 | |
| 2380 | void Control::grab_click_focus() { |
| 2381 | ERR_MAIN_THREAD_GUARD; |
| 2382 | ERR_FAIL_COND(!is_inside_tree()); |
| 2383 | |
| 2384 | get_viewport()->_gui_grab_click_focus(this); |
| 2385 | } |
| 2386 | |
| 2387 | void Control::release_focus() { |
| 2388 | ERR_MAIN_THREAD_GUARD; |
| 2389 | ERR_FAIL_COND(!is_inside_tree()); |
| 2390 | |
| 2391 | if (!has_focus()) { |
| 2392 | return; |
| 2393 | } |
| 2394 | |
| 2395 | get_viewport()->gui_release_focus(); |
| 2396 | } |
| 2397 | |
| 2398 | static Control *_next_control(Control *p_from) { |
| 2399 | if (p_from->is_set_as_top_level()) { |
| 2400 | return nullptr; // Can't go above. |
| 2401 | } |
| 2402 | |
| 2403 | Control *parent = p_from->get_parent_control(); |
| 2404 | |
| 2405 | if (!parent) { |
| 2406 | return nullptr; |
| 2407 | } |
| 2408 | |
| 2409 | int next = p_from->get_index(); |
| 2410 | ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr); |
| 2411 | for (int i = (next + 1); i < parent->get_child_count(); i++) { |
| 2412 | Control *c = Object::cast_to<Control>(parent->get_child(i)); |
| 2413 | if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { |
| 2414 | continue; |
| 2415 | } |
| 2416 | |
| 2417 | return c; |
| 2418 | } |
| 2419 | |
| 2420 | // No next in parent, try the same in parent. |
| 2421 | return _next_control(parent); |
| 2422 | } |
| 2423 | |
| 2424 | Control *Control::find_next_valid_focus() const { |
| 2425 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 2426 | |
| 2427 | // If the focus property is manually overwritten, attempt to use it. |
| 2428 | if (!data.focus_next.is_empty()) { |
| 2429 | Node *n = get_node_or_null(data.focus_next); |
| 2430 | ERR_FAIL_NULL_V_MSG(n, nullptr, "Next focus node path is invalid: '" + String(data.focus_next) + "'."); |
| 2431 | Control *c = Object::cast_to<Control>(n); |
| 2432 | ERR_FAIL_NULL_V_MSG(c, nullptr, "Next focus node is not a control: '" + n->get_name() + "'."); |
| 2433 | if (c->_is_focusable()) { |
| 2434 | return c; |
| 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | Control *from = const_cast<Control *>(this); |
| 2439 | HashSet<Control *> checked; |
| 2440 | bool ac_enabled = get_tree() && get_tree()->is_accessibility_enabled(); |
| 2441 | |
| 2442 | // Index of the current `Control` subtree within the containing `Window`. |
| 2443 | int window_next = -1; |
| 2444 | checked.insert(from); |
| 2445 | |
| 2446 | while (true) { |
| 2447 | // Find next child. |
| 2448 | |
| 2449 | Control *next_child = nullptr; |
| 2450 | |
| 2451 | for (int i = 0; i < from->get_child_count(); i++) { |
| 2452 | Control *c = Object::cast_to<Control>(from->get_child(i)); |
| 2453 | if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { |
| 2454 | continue; |
| 2455 | } |
| 2456 | |
| 2457 | next_child = c; |
| 2458 | break; |
| 2459 | } |
| 2460 | |
| 2461 | if (!next_child) { |
| 2462 | next_child = _next_control(from); |
| 2463 | if (!next_child) { // Nothing else. Go up and find either window or subwindow. |
| 2464 | next_child = const_cast<Control *>(this); |
| 2465 | |
| 2466 | while (next_child) { |
| 2467 | if (next_child->is_set_as_top_level()) { |
| 2468 | break; |
| 2469 | } |
| 2470 | |
| 2471 | if (next_child->data.RI) { |
| 2472 | break; |
| 2473 | } |
| 2474 | next_child = next_child->data.parent_control; |
| 2475 | } |
| 2476 | |
| 2477 | Window *win = next_child == nullptr ? nullptr : next_child->data.parent_window; |
| 2478 | if (win) { // Cycle through `Control` subtrees of the parent window |
| 2479 | if (window_next == -1) { |
| 2480 | window_next = next_child->get_index(); |
| 2481 | ERR_FAIL_INDEX_V(window_next, win->get_child_count(), nullptr); |
| 2482 | } |
| 2483 | |
| 2484 | for (int i = 1; i < win->get_child_count() + 1; i++) { |
| 2485 | int next = Math::wrapi(window_next + i, 0, win->get_child_count()); |
| 2486 | Control *c = Object::cast_to<Control>(win->get_child(next)); |
| 2487 | if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { |
| 2488 | continue; |
| 2489 | } |
| 2490 | window_next = next; |
| 2491 | next_child = c; |
| 2492 | break; |
| 2493 | } |
| 2494 | } |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | if (!next_child) { |
| 2499 | break; |
| 2500 | } |
| 2501 | |
| 2502 | if ((next_child->get_focus_mode_with_override() == FOCUS_ALL) || (ac_enabled && next_child->get_focus_mode_with_override() == FOCUS_ACCESSIBILITY)) { |
| 2503 | return next_child; |
| 2504 | } |
| 2505 | |
| 2506 | if (checked.has(next_child)) { |
| 2507 | return nullptr; // Stuck in a loop with no next control. |
| 2508 | } |
| 2509 | checked.insert(next_child); |
| 2510 | |
| 2511 | from = next_child; // Try to find the next control with focus mode FOCUS_ALL. |
| 2512 | } |
| 2513 | |
| 2514 | return nullptr; |
| 2515 | } |
| 2516 | |
| 2517 | static Control *_prev_control(Control *p_from) { |
| 2518 | for (int i = p_from->get_child_count() - 1; i >= 0; i--) { |
| 2519 | Control *c = Object::cast_to<Control>(p_from->get_child(i)); |
| 2520 | if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { |
| 2521 | continue; |
| 2522 | } |
| 2523 | |
| 2524 | // Find the last child as prev, try the same in the last child. |
| 2525 | return _prev_control(c); |
| 2526 | } |
| 2527 | |
| 2528 | return p_from; // Not found in the children, return itself. |
| 2529 | } |
| 2530 | |
| 2531 | Control *Control::find_prev_valid_focus() const { |
| 2532 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 2533 | |
| 2534 | // If the focus property is manually overwritten, attempt to use it. |
| 2535 | if (!data.focus_prev.is_empty()) { |
| 2536 | Node *n = get_node_or_null(data.focus_prev); |
| 2537 | ERR_FAIL_NULL_V_MSG(n, nullptr, "Previous focus node path is invalid: '" + String(data.focus_prev) + "'."); |
| 2538 | Control *c = Object::cast_to<Control>(n); |
| 2539 | ERR_FAIL_NULL_V_MSG(c, nullptr, "Previous focus node is not a control: '" + n->get_name() + "'."); |
| 2540 | if (c->_is_focusable()) { |
| 2541 | return c; |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | Control *from = const_cast<Control *>(this); |
| 2546 | HashSet<Control *> checked; |
| 2547 | bool ac_enabled = get_tree() && get_tree()->is_accessibility_enabled(); |
| 2548 | |
| 2549 | // Index of the current `Control` subtree within the containing `Window`. |
| 2550 | int window_prev = -1; |
| 2551 | checked.insert(from); |
| 2552 | |
| 2553 | while (true) { |
| 2554 | // Find prev child. |
| 2555 | |
| 2556 | Control *prev_child = nullptr; |
| 2557 | |
| 2558 | if (from->is_set_as_top_level() || !from->data.parent_control) { |
| 2559 | // Find last of the children. |
| 2560 | |
| 2561 | Window *win = from->data.parent_window; |
| 2562 | if (win) { // Cycle through `Control` subtrees of the parent window |
| 2563 | if (window_prev == -1) { |
| 2564 | window_prev = from->get_index(); |
| 2565 | ERR_FAIL_INDEX_V(window_prev, win->get_child_count(), nullptr); |
| 2566 | } |
| 2567 | |
| 2568 | for (int i = 1; i < win->get_child_count() + 1; i++) { |
| 2569 | int prev = Math::wrapi(window_prev - i, 0, win->get_child_count()); |
| 2570 | Control *c = Object::cast_to<Control>(win->get_child(prev)); |
| 2571 | if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { |
| 2572 | continue; |
| 2573 | } |
| 2574 | window_prev = prev; |
| 2575 | prev_child = _prev_control(c); |
| 2576 | break; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | if (!prev_child) { |
| 2581 | prev_child = _prev_control(from); // Wrap start here. |
| 2582 | } |
| 2583 | |
| 2584 | } else { |
| 2585 | for (int i = (from->get_index() - 1); i >= 0; i--) { |
| 2586 | Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i)); |
| 2587 | |
| 2588 | if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) { |
| 2589 | continue; |
| 2590 | } |
| 2591 | |
| 2592 | prev_child = c; |
| 2593 | break; |
| 2594 | } |
| 2595 | |
| 2596 | if (!prev_child) { |
| 2597 | prev_child = from->data.parent_control; |
| 2598 | } else { |
| 2599 | prev_child = _prev_control(prev_child); |
| 2600 | } |
| 2601 | } |
| 2602 | |
| 2603 | if ((prev_child->get_focus_mode_with_override() == FOCUS_ALL) || (ac_enabled && prev_child->get_focus_mode_with_override() == FOCUS_ACCESSIBILITY)) { |
| 2604 | return prev_child; |
| 2605 | } |
| 2606 | |
| 2607 | if (checked.has(prev_child)) { |
| 2608 | return nullptr; // Stuck in a loop with no prev control. |
| 2609 | } |
| 2610 | checked.insert(prev_child); |
| 2611 | |
| 2612 | from = prev_child; // Try to find the prev control with focus mode FOCUS_ALL. |
| 2613 | } |
| 2614 | |
| 2615 | return nullptr; |
| 2616 | } |
| 2617 | |
| 2618 | void Control::set_focus_neighbor(Side p_side, const NodePath &p_neighbor) { |
| 2619 | ERR_MAIN_THREAD_GUARD; |
| 2620 | ERR_FAIL_INDEX((int)p_side, 4); |
| 2621 | data.focus_neighbor[p_side] = p_neighbor; |
| 2622 | } |
| 2623 | |
| 2624 | NodePath Control::get_focus_neighbor(Side p_side) const { |
| 2625 | ERR_READ_THREAD_GUARD_V(NodePath()); |
| 2626 | ERR_FAIL_INDEX_V((int)p_side, 4, NodePath()); |
| 2627 | return data.focus_neighbor[p_side]; |
| 2628 | } |
| 2629 | |
| 2630 | void Control::set_focus_next(const NodePath &p_next) { |
| 2631 | ERR_MAIN_THREAD_GUARD; |
| 2632 | data.focus_next = p_next; |
| 2633 | } |
| 2634 | |
| 2635 | NodePath Control::get_focus_next() const { |
| 2636 | ERR_READ_THREAD_GUARD_V(NodePath()); |
| 2637 | return data.focus_next; |
| 2638 | } |
| 2639 | |
| 2640 | void Control::set_focus_previous(const NodePath &p_prev) { |
| 2641 | ERR_MAIN_THREAD_GUARD; |
| 2642 | data.focus_prev = p_prev; |
| 2643 | } |
| 2644 | |
| 2645 | NodePath Control::get_focus_previous() const { |
| 2646 | ERR_READ_THREAD_GUARD_V(NodePath()); |
| 2647 | return data.focus_prev; |
| 2648 | } |
| 2649 | |
| 2650 | #define MAX_NEIGHBOR_SEARCH_COUNT 512 |
| 2651 | |
| 2652 | Control *Control::_get_focus_neighbor(Side p_side, int p_count) { |
| 2653 | ERR_FAIL_INDEX_V((int)p_side, 4, nullptr); |
| 2654 | |
| 2655 | if (p_count >= MAX_NEIGHBOR_SEARCH_COUNT) { |
| 2656 | return nullptr; |
| 2657 | } |
| 2658 | if (!data.focus_neighbor[p_side].is_empty()) { |
| 2659 | Node *n = get_node_or_null(data.focus_neighbor[p_side]); |
| 2660 | ERR_FAIL_NULL_V_MSG(n, nullptr, "Neighbor focus node path is invalid: '" + String(data.focus_neighbor[p_side]) + "'."); |
| 2661 | Control *c = Object::cast_to<Control>(n); |
| 2662 | ERR_FAIL_NULL_V_MSG(c, nullptr, "Neighbor focus node is not a control: '" + n->get_name() + "'."); |
| 2663 | if (c->_is_focusable()) { |
| 2664 | return c; |
| 2665 | } |
| 2666 | |
| 2667 | c = c->_get_focus_neighbor(p_side, p_count + 1); |
| 2668 | return c; |
| 2669 | } |
| 2670 | |
| 2671 | real_t square_of_dist = 1e14; |
| 2672 | Control *result = nullptr; |
| 2673 | |
| 2674 | const Vector2 dir[4] = { |
| 2675 | Vector2(-1, 0), |
| 2676 | Vector2(0, -1), |
| 2677 | Vector2(1, 0), |
| 2678 | Vector2(0, 1) |
| 2679 | }; |
| 2680 | |
| 2681 | Vector2 vdir = dir[p_side]; |
| 2682 | |
| 2683 | Rect2 r = get_global_rect(); |
| 2684 | real_t begin_d = vdir.dot(r.get_position()); |
| 2685 | real_t end_d = vdir.dot(r.get_end()); |
| 2686 | real_t maxd = MAX(begin_d, end_d); |
| 2687 | |
| 2688 | Rect2 clamp = Rect2(-1e7, -1e7, 2e7, 2e7); |
| 2689 | Rect2 result_rect; |
| 2690 | |
| 2691 | Node *base = this; |
| 2692 | |
| 2693 | while (base) { |
| 2694 | ScrollContainer *sc = Object::cast_to<ScrollContainer>(base); |
| 2695 | |
| 2696 | if (sc) { |
| 2697 | Rect2 sc_r = sc->get_global_rect(); |
| 2698 | bool follow_focus = sc->is_following_focus(); |
| 2699 | |
| 2700 | if (result && !follow_focus && !sc_r.intersects(result_rect)) { |
| 2701 | result = nullptr; // Skip invisible control. |
| 2702 | } |
| 2703 | |
| 2704 | if (result == nullptr) { |
| 2705 | real_t sc_begin_d = vdir.dot(sc_r.get_position()); |
| 2706 | real_t sc_end_d = vdir.dot(sc_r.get_end()); |
| 2707 | real_t sc_maxd = sc_begin_d; |
| 2708 | real_t sc_mind = sc_end_d; |
| 2709 | if (sc_begin_d < sc_end_d) { |
| 2710 | sc_maxd = sc_end_d; |
| 2711 | sc_mind = sc_begin_d; |
| 2712 | } |
| 2713 | |
| 2714 | if (!follow_focus && maxd < sc_mind) { |
| 2715 | // Reposition to find visible control. |
| 2716 | maxd = sc_mind; |
| 2717 | r.set_position(r.get_position() + (sc_mind - maxd) * vdir); |
| 2718 | } |
| 2719 | |
| 2720 | if (follow_focus || sc_maxd > maxd) { |
| 2721 | _window_find_focus_neighbor(vdir, base, r, clamp, maxd, square_of_dist, &result); |
| 2722 | } |
| 2723 | |
| 2724 | if (result == nullptr) { |
| 2725 | // Reposition to search upwards. |
| 2726 | maxd = sc_maxd; |
| 2727 | r.set_position(r.get_position() + (sc_maxd - maxd) * vdir); |
| 2728 | } else { |
| 2729 | result_rect = result->get_global_rect(); |
| 2730 | if (follow_focus) { |
| 2731 | real_t r_begin_d = vdir.dot(result_rect.get_position()); |
| 2732 | real_t r_end_d = vdir.dot(result_rect.get_end()); |
| 2733 | real_t r_maxd = r_begin_d; |
| 2734 | real_t r_mind = r_end_d; |
| 2735 | if (r_begin_d < r_end_d) { |
| 2736 | r_maxd = r_end_d; |
| 2737 | r_mind = r_begin_d; |
| 2738 | } |
| 2739 | |
| 2740 | if (r_maxd > sc_maxd) { |
| 2741 | result_rect.set_position(result_rect.get_position() + (sc_maxd - r_maxd) * vdir); |
| 2742 | } else if (r_mind < sc_mind) { |
| 2743 | result_rect.set_position(result_rect.get_position() + (sc_mind - r_mind) * vdir); |
| 2744 | } |
| 2745 | } |
| 2746 | } |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | Control *c = Object::cast_to<Control>(base); |
| 2751 | if (c) { |
| 2752 | if (c->data.RI) { |
| 2753 | break; |
| 2754 | } |
| 2755 | } |
| 2756 | base = base->get_parent(); |
| 2757 | } |
| 2758 | |
| 2759 | if (result) { |
| 2760 | return result; |
| 2761 | } |
| 2762 | |
| 2763 | if (!base) { |
| 2764 | return nullptr; |
| 2765 | } |
| 2766 | |
| 2767 | _window_find_focus_neighbor(vdir, base, r, clamp, maxd, square_of_dist, &result); |
| 2768 | |
| 2769 | return result; |
| 2770 | } |
| 2771 | |
| 2772 | Control *Control::find_valid_focus_neighbor(Side p_side) const { |
| 2773 | return const_cast<Control *>(this)->_get_focus_neighbor(p_side); |
| 2774 | } |
| 2775 | |
| 2776 | void Control::_window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Rect2 &p_rect, const Rect2 &p_clamp, real_t p_min, real_t &r_closest_dist_squared, Control **r_closest) { |
| 2777 | if (Object::cast_to<Viewport>(p_at)) { |
| 2778 | return; // Bye. |
| 2779 | } |
| 2780 | |
| 2781 | bool ac_enabled = get_tree() && get_tree()->is_accessibility_enabled(); |
| 2782 | |
| 2783 | Control *c = Object::cast_to<Control>(p_at); |
| 2784 | Container *container = Object::cast_to<Container>(p_at); |
| 2785 | bool in_container = container ? container->is_ancestor_of(this) : false; |
| 2786 | |
| 2787 | if (c && c != this && ((c->get_focus_mode_with_override() == FOCUS_ALL) || (ac_enabled && c->get_focus_mode_with_override() == FOCUS_ACCESSIBILITY)) && !in_container && p_clamp.intersects(c->get_global_rect())) { |
| 2788 | Rect2 r_c = c->get_global_rect(); |
| 2789 | r_c = r_c.intersection(p_clamp); |
| 2790 | real_t begin_d = p_dir.dot(r_c.get_position()); |
| 2791 | real_t end_d = p_dir.dot(r_c.get_end()); |
| 2792 | real_t max = MAX(begin_d, end_d); |
| 2793 | |
| 2794 | // Use max to allow navigation to overlapping controls (for ScrollContainer case). |
| 2795 | if (max > (p_min + CMP_EPSILON)) { |
| 2796 | // Calculate the shortest distance. (No shear transform) |
| 2797 | // Flip along axis(es) so that C falls in the first quadrant of c (as origin) for easy calculation. |
| 2798 | // The same transformation would put the direction vector in the positive direction (+x or +y). |
| 2799 | // | ------------- |
| 2800 | // | | | | |
| 2801 | // | |-----C-----| |
| 2802 | // ----|---a | | | |
| 2803 | // | | | b------------ |
| 2804 | // -|---c---|-----------------------> |
| 2805 | // | | | |
| 2806 | // ----|---- |
| 2807 | // cC = ca + ab + bC |
| 2808 | // The shortest distance is the vector ab's length or its positive projection length. |
| 2809 | |
| 2810 | Vector2 cC_origin = r_c.get_center() - p_rect.get_center(); |
| 2811 | Vector2 cC = cC_origin.abs(); // Converted to fall in the first quadrant of c. |
| 2812 | |
| 2813 | Vector2 ab = cC - 0.5 * r_c.get_size() - 0.5 * p_rect.get_size(); |
| 2814 | |
| 2815 | real_t min_d_squared = 0.0; |
| 2816 | if (ab.x > 0.0) { |
| 2817 | min_d_squared += ab.x * ab.x; |
| 2818 | } |
| 2819 | if (ab.y > 0.0) { |
| 2820 | min_d_squared += ab.y * ab.y; |
| 2821 | } |
| 2822 | |
| 2823 | if (min_d_squared < r_closest_dist_squared || *r_closest == nullptr) { |
| 2824 | r_closest_dist_squared = min_d_squared; |
| 2825 | *r_closest = c; |
| 2826 | } else if (min_d_squared == r_closest_dist_squared) { |
| 2827 | // Tie-breaking aims to address situations where a potential focus neighbor's bounding rect |
| 2828 | // is right next to the currently focused control (e.g. in BoxContainer with |
| 2829 | // separation overridden to 0). This needs specific handling so that the correct |
| 2830 | // focus neighbor is selected. |
| 2831 | |
| 2832 | Point2 p_center = p_rect.get_center(); |
| 2833 | Control *closest = *r_closest; |
| 2834 | Point2 closest_center = closest->get_global_rect().get_center(); |
| 2835 | |
| 2836 | // Tie-break in favor of the control most aligned with p_dir. |
| 2837 | if (Math::abs(p_dir.cross(cC_origin)) < Math::abs(p_dir.cross(closest_center - p_center))) { |
| 2838 | *r_closest = c; |
| 2839 | } |
| 2840 | } |
| 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | ScrollContainer *sc = Object::cast_to<ScrollContainer>(c); |
| 2845 | Rect2 intersection = p_clamp; |
| 2846 | if (sc) { |
| 2847 | if (!sc->is_following_focus() || !in_container) { |
| 2848 | intersection = p_clamp.intersection(sc->get_global_rect()); |
| 2849 | if (!intersection.has_area()) { |
| 2850 | return; |
| 2851 | } |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | for (int i = 0; i < p_at->get_child_count(); i++) { |
| 2856 | Node *child = p_at->get_child(i); |
| 2857 | Control *childc = Object::cast_to<Control>(child); |
| 2858 | if (childc) { |
| 2859 | if (childc->data.RI) { |
| 2860 | continue; // Subwindow, ignore. |
| 2861 | } |
| 2862 | if (!childc->is_visible_in_tree()) { |
| 2863 | continue; // Skip invisible node trees. |
| 2864 | } |
| 2865 | if (Object::cast_to<ScrollContainer>(childc) && childc->is_ancestor_of(this)) { |
| 2866 | continue; // Already searched in it, skip it. |
| 2867 | } |
| 2868 | } |
| 2869 | _window_find_focus_neighbor(p_dir, child, p_rect, intersection, p_min, r_closest_dist_squared, r_closest); |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | // Rendering. |
| 2874 | |
| 2875 | void Control::set_default_cursor_shape(CursorShape p_shape) { |
| 2876 | ERR_MAIN_THREAD_GUARD; |
| 2877 | ERR_FAIL_INDEX(int(p_shape), CURSOR_MAX); |
| 2878 | |
| 2879 | if (data.default_cursor == p_shape) { |
| 2880 | return; |
| 2881 | } |
| 2882 | data.default_cursor = p_shape; |
| 2883 | |
| 2884 | if (!is_inside_tree()) { |
| 2885 | return; |
| 2886 | } |
| 2887 | if (!get_global_rect().has_point(get_global_mouse_position())) { |
| 2888 | return; |
| 2889 | } |
| 2890 | |
| 2891 | // Display the new cursor shape instantly. |
| 2892 | get_viewport()->update_mouse_cursor_state(); |
| 2893 | } |
| 2894 | |
| 2895 | Control::CursorShape Control::get_default_cursor_shape() const { |
| 2896 | ERR_READ_THREAD_GUARD_V(CURSOR_ARROW); |
| 2897 | return data.default_cursor; |
| 2898 | } |
| 2899 | |
| 2900 | Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const { |
| 2901 | ERR_READ_THREAD_GUARD_V(CURSOR_ARROW); |
| 2902 | return data.default_cursor; |
| 2903 | } |
| 2904 | |
| 2905 | void Control::set_disable_visibility_clip(bool p_ignore) { |
| 2906 | ERR_MAIN_THREAD_GUARD; |
| 2907 | if (data.disable_visibility_clip == p_ignore) { |
| 2908 | return; |
| 2909 | } |
| 2910 | data.disable_visibility_clip = p_ignore; |
| 2911 | queue_redraw(); |
| 2912 | } |
| 2913 | |
| 2914 | bool Control::is_visibility_clip_disabled() const { |
| 2915 | ERR_READ_THREAD_GUARD_V(false); |
| 2916 | return data.disable_visibility_clip; |
| 2917 | } |
| 2918 | |
| 2919 | void Control::set_clip_contents(bool p_clip) { |
| 2920 | ERR_MAIN_THREAD_GUARD; |
| 2921 | if (data.clip_contents == p_clip) { |
| 2922 | return; |
| 2923 | } |
| 2924 | data.clip_contents = p_clip; |
| 2925 | queue_redraw(); |
| 2926 | } |
| 2927 | |
| 2928 | bool Control::is_clipping_contents() { |
| 2929 | ERR_READ_THREAD_GUARD_V(false); |
| 2930 | return data.clip_contents; |
| 2931 | } |
| 2932 | |
| 2933 | // Theming. |
| 2934 | |
| 2935 | void Control::_theme_changed() { |
| 2936 | if (is_inside_tree()) { |
| 2937 | data.theme_owner->propagate_theme_changed(this, this, true, false); |
| 2938 | } |
| 2939 | } |
| 2940 | |
| 2941 | void Control::_notify_theme_override_changed() { |
| 2942 | if (!data.bulk_theme_override && is_inside_tree()) { |
| 2943 | notification(NOTIFICATION_THEME_CHANGED); |
| 2944 | } |
| 2945 | } |
| 2946 | |
| 2947 | void Control::_invalidate_theme_cache() { |
| 2948 | data.theme_icon_cache.clear(); |
| 2949 | data.theme_style_cache.clear(); |
| 2950 | data.theme_font_cache.clear(); |
| 2951 | data.theme_font_size_cache.clear(); |
| 2952 | data.theme_color_cache.clear(); |
| 2953 | data.theme_constant_cache.clear(); |
| 2954 | } |
| 2955 | |
| 2956 | void Control::_update_theme_item_cache() { |
| 2957 | ThemeDB::get_singleton()->update_class_instance_items(this); |
| 2958 | } |
| 2959 | |
| 2960 | void Control::set_theme_owner_node(Node *p_node) { |
| 2961 | ERR_MAIN_THREAD_GUARD; |
| 2962 | data.theme_owner->set_owner_node(p_node); |
| 2963 | } |
| 2964 | |
| 2965 | Node *Control::get_theme_owner_node() const { |
| 2966 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 2967 | return data.theme_owner->get_owner_node(); |
| 2968 | } |
| 2969 | |
| 2970 | bool Control::has_theme_owner_node() const { |
| 2971 | ERR_READ_THREAD_GUARD_V(false); |
| 2972 | return data.theme_owner->has_owner_node(); |
| 2973 | } |
| 2974 | |
| 2975 | void Control::set_theme_context(ThemeContext *p_context, bool p_propagate) { |
| 2976 | ERR_MAIN_THREAD_GUARD; |
| 2977 | data.theme_owner->set_owner_context(p_context, p_propagate); |
| 2978 | } |
| 2979 | |
| 2980 | void Control::set_theme(const Ref<Theme> &p_theme) { |
| 2981 | ERR_MAIN_THREAD_GUARD; |
| 2982 | if (data.theme == p_theme) { |
| 2983 | return; |
| 2984 | } |
| 2985 | |
| 2986 | if (data.theme.is_valid()) { |
| 2987 | data.theme->disconnect_changed(callable_mp(this, &Control::_theme_changed)); |
| 2988 | } |
| 2989 | |
| 2990 | data.theme = p_theme; |
| 2991 | if (data.theme.is_valid()) { |
| 2992 | data.theme_owner->propagate_theme_changed(this, this, is_inside_tree(), true); |
| 2993 | data.theme->connect_changed(callable_mp(this, &Control::_theme_changed), CONNECT_DEFERRED); |
| 2994 | return; |
| 2995 | } |
| 2996 | |
| 2997 | Control *parent_c = Object::cast_to<Control>(get_parent()); |
| 2998 | if (parent_c && parent_c->has_theme_owner_node()) { |
| 2999 | data.theme_owner->propagate_theme_changed(this, parent_c->get_theme_owner_node(), is_inside_tree(), true); |
| 3000 | return; |
| 3001 | } |
| 3002 | |
| 3003 | Window *parent_w = cast_to<Window>(get_parent()); |
| 3004 | if (parent_w && parent_w->has_theme_owner_node()) { |
| 3005 | data.theme_owner->propagate_theme_changed(this, parent_w->get_theme_owner_node(), is_inside_tree(), true); |
| 3006 | return; |
| 3007 | } |
| 3008 | |
| 3009 | data.theme_owner->propagate_theme_changed(this, nullptr, is_inside_tree(), true); |
| 3010 | } |
| 3011 | |
| 3012 | Ref<Theme> Control::get_theme() const { |
| 3013 | ERR_READ_THREAD_GUARD_V(Ref<Theme>()); |
| 3014 | return data.theme; |
| 3015 | } |
| 3016 | |
| 3017 | void Control::set_theme_type_variation(const StringName &p_theme_type) { |
| 3018 | ERR_MAIN_THREAD_GUARD; |
| 3019 | if (data.theme_type_variation == p_theme_type) { |
| 3020 | return; |
| 3021 | } |
| 3022 | data.theme_type_variation = p_theme_type; |
| 3023 | if (is_inside_tree()) { |
| 3024 | notification(NOTIFICATION_THEME_CHANGED); |
| 3025 | } |
| 3026 | } |
| 3027 | |
| 3028 | StringName Control::get_theme_type_variation() const { |
| 3029 | ERR_READ_THREAD_GUARD_V(StringName()); |
| 3030 | return data.theme_type_variation; |
| 3031 | } |
| 3032 | |
| 3033 | /// Theme property lookup. |
| 3034 | |
| 3035 | Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { |
| 3036 | ERR_READ_THREAD_GUARD_V(Ref<Texture2D>()); |
| 3037 | if (!data.initialized) { |
| 3038 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3039 | } |
| 3040 | |
| 3041 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3042 | const Ref<Texture2D> *tex = data.theme_icon_override.getptr(p_name); |
| 3043 | if (tex) { |
| 3044 | return *tex; |
| 3045 | } |
| 3046 | } |
| 3047 | |
| 3048 | if (data.theme_icon_cache.has(p_theme_type) && data.theme_icon_cache[p_theme_type].has(p_name)) { |
| 3049 | return data.theme_icon_cache[p_theme_type][p_name]; |
| 3050 | } |
| 3051 | |
| 3052 | Vector<StringName> theme_types; |
| 3053 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3054 | Ref<Texture2D> icon = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types); |
| 3055 | data.theme_icon_cache[p_theme_type][p_name] = icon; |
| 3056 | return icon; |
| 3057 | } |
| 3058 | |
| 3059 | Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { |
| 3060 | ERR_READ_THREAD_GUARD_V(Ref<StyleBox>()); |
| 3061 | if (!data.initialized) { |
| 3062 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3063 | } |
| 3064 | |
| 3065 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3066 | const Ref<StyleBox> *style = data.theme_style_override.getptr(p_name); |
| 3067 | if (style) { |
| 3068 | return *style; |
| 3069 | } |
| 3070 | } |
| 3071 | |
| 3072 | if (data.theme_style_cache.has(p_theme_type) && data.theme_style_cache[p_theme_type].has(p_name)) { |
| 3073 | return data.theme_style_cache[p_theme_type][p_name]; |
| 3074 | } |
| 3075 | |
| 3076 | Vector<StringName> theme_types; |
| 3077 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3078 | Ref<StyleBox> style = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types); |
| 3079 | data.theme_style_cache[p_theme_type][p_name] = style; |
| 3080 | return style; |
| 3081 | } |
| 3082 | |
| 3083 | Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { |
| 3084 | ERR_READ_THREAD_GUARD_V(Ref<Font>()); |
| 3085 | if (!data.initialized) { |
| 3086 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3087 | } |
| 3088 | |
| 3089 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3090 | const Ref<Font> *font = data.theme_font_override.getptr(p_name); |
| 3091 | if (font) { |
| 3092 | return *font; |
| 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | if (data.theme_font_cache.has(p_theme_type) && data.theme_font_cache[p_theme_type].has(p_name)) { |
| 3097 | return data.theme_font_cache[p_theme_type][p_name]; |
| 3098 | } |
| 3099 | |
| 3100 | Vector<StringName> theme_types; |
| 3101 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3102 | Ref<Font> font = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types); |
| 3103 | data.theme_font_cache[p_theme_type][p_name] = font; |
| 3104 | return font; |
| 3105 | } |
| 3106 | |
| 3107 | int Control::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { |
| 3108 | ERR_READ_THREAD_GUARD_V(0); |
| 3109 | if (!data.initialized) { |
| 3110 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3111 | } |
| 3112 | |
| 3113 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3114 | const int *font_size = data.theme_font_size_override.getptr(p_name); |
| 3115 | if (font_size && (*font_size) > 0) { |
| 3116 | return *font_size; |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | if (data.theme_font_size_cache.has(p_theme_type) && data.theme_font_size_cache[p_theme_type].has(p_name)) { |
| 3121 | return data.theme_font_size_cache[p_theme_type][p_name]; |
| 3122 | } |
| 3123 | |
| 3124 | Vector<StringName> theme_types; |
| 3125 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3126 | int font_size = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types); |
| 3127 | data.theme_font_size_cache[p_theme_type][p_name] = font_size; |
| 3128 | return font_size; |
| 3129 | } |
| 3130 | |
| 3131 | Color Control::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { |
| 3132 | ERR_READ_THREAD_GUARD_V(Color()); |
| 3133 | if (!data.initialized) { |
| 3134 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3135 | } |
| 3136 | |
| 3137 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3138 | const Color *color = data.theme_color_override.getptr(p_name); |
| 3139 | if (color) { |
| 3140 | return *color; |
| 3141 | } |
| 3142 | } |
| 3143 | |
| 3144 | if (data.theme_color_cache.has(p_theme_type) && data.theme_color_cache[p_theme_type].has(p_name)) { |
| 3145 | return data.theme_color_cache[p_theme_type][p_name]; |
| 3146 | } |
| 3147 | |
| 3148 | Vector<StringName> theme_types; |
| 3149 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3150 | Color color = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types); |
| 3151 | data.theme_color_cache[p_theme_type][p_name] = color; |
| 3152 | return color; |
| 3153 | } |
| 3154 | |
| 3155 | int Control::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { |
| 3156 | ERR_READ_THREAD_GUARD_V(0); |
| 3157 | if (!data.initialized) { |
| 3158 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3159 | } |
| 3160 | |
| 3161 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3162 | const int *constant = data.theme_constant_override.getptr(p_name); |
| 3163 | if (constant) { |
| 3164 | return *constant; |
| 3165 | } |
| 3166 | } |
| 3167 | |
| 3168 | if (data.theme_constant_cache.has(p_theme_type) && data.theme_constant_cache[p_theme_type].has(p_name)) { |
| 3169 | return data.theme_constant_cache[p_theme_type][p_name]; |
| 3170 | } |
| 3171 | |
| 3172 | Vector<StringName> theme_types; |
| 3173 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3174 | int constant = data.theme_owner->get_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types); |
| 3175 | data.theme_constant_cache[p_theme_type][p_name] = constant; |
| 3176 | return constant; |
| 3177 | } |
| 3178 | |
| 3179 | Variant Control::get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type) const { |
| 3180 | switch (p_data_type) { |
| 3181 | case Theme::DATA_TYPE_COLOR: |
| 3182 | return get_theme_color(p_name, p_theme_type); |
| 3183 | case Theme::DATA_TYPE_CONSTANT: |
| 3184 | return get_theme_constant(p_name, p_theme_type); |
| 3185 | case Theme::DATA_TYPE_FONT: |
| 3186 | return get_theme_font(p_name, p_theme_type); |
| 3187 | case Theme::DATA_TYPE_FONT_SIZE: |
| 3188 | return get_theme_font_size(p_name, p_theme_type); |
| 3189 | case Theme::DATA_TYPE_ICON: |
| 3190 | return get_theme_icon(p_name, p_theme_type); |
| 3191 | case Theme::DATA_TYPE_STYLEBOX: |
| 3192 | return get_theme_stylebox(p_name, p_theme_type); |
| 3193 | case Theme::DATA_TYPE_MAX: |
| 3194 | break; // Can't happen, but silences warning. |
| 3195 | } |
| 3196 | |
| 3197 | return Variant(); |
| 3198 | } |
| 3199 | |
| 3200 | Variant Control::get_used_theme_item(const String &p_full_name, const StringName &p_theme_type) const { |
| 3201 | if (p_full_name.begins_with("theme_override_icons/")) { |
| 3202 | String name = p_full_name.substr(strlen("theme_override_icons/")); |
| 3203 | if (has_theme_icon(name)) { // Exclude cached and default ones. |
| 3204 | return get_theme_icon(name); |
| 3205 | } |
| 3206 | } else if (p_full_name.begins_with("theme_override_styles/")) { |
| 3207 | String name = p_full_name.substr(strlen("theme_override_styles/")); |
| 3208 | if (has_theme_stylebox(name)) { |
| 3209 | return get_theme_stylebox(name); |
| 3210 | } |
| 3211 | } else if (p_full_name.begins_with("theme_override_fonts/")) { |
| 3212 | String name = p_full_name.substr(strlen("theme_override_fonts/")); |
| 3213 | if (has_theme_font(name)) { |
| 3214 | return get_theme_font(name); |
| 3215 | } |
| 3216 | } else if (p_full_name.begins_with("theme_override_font_sizes/")) { |
| 3217 | String name = p_full_name.substr(strlen("theme_override_font_sizes/")); |
| 3218 | if (has_theme_font_size(name)) { |
| 3219 | return get_theme_font_size(name); |
| 3220 | } |
| 3221 | } else if (p_full_name.begins_with("theme_override_colors/")) { |
| 3222 | String name = p_full_name.substr(strlen("theme_override_colors/")); |
| 3223 | if (has_theme_color(name)) { |
| 3224 | return get_theme_color(name); |
| 3225 | } |
| 3226 | } else if (p_full_name.begins_with("theme_override_constants/")) { |
| 3227 | String name = p_full_name.substr(strlen("theme_override_constants/")); |
| 3228 | if (has_theme_constant(name)) { |
| 3229 | return get_theme_constant(name); |
| 3230 | } |
| 3231 | } else { |
| 3232 | ERR_FAIL_V_MSG(Variant(), vformat("The property %s is not a theme item.", p_full_name)); |
| 3233 | } |
| 3234 | |
| 3235 | return Variant(); |
| 3236 | } |
| 3237 | |
| 3238 | #ifdef TOOLS_ENABLED |
| 3239 | Ref<Texture2D> Control::get_editor_theme_icon(const StringName &p_name) const { |
| 3240 | return get_theme_icon(p_name, SNAME("EditorIcons")); |
| 3241 | } |
| 3242 | #endif // TOOLS_ENABLED |
| 3243 | |
| 3244 | bool Control::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { |
| 3245 | ERR_READ_THREAD_GUARD_V(false); |
| 3246 | if (!data.initialized) { |
| 3247 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3248 | } |
| 3249 | |
| 3250 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3251 | if (has_theme_icon_override(p_name)) { |
| 3252 | return true; |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | Vector<StringName> theme_types; |
| 3257 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3258 | return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types); |
| 3259 | } |
| 3260 | |
| 3261 | bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { |
| 3262 | ERR_READ_THREAD_GUARD_V(false); |
| 3263 | if (!data.initialized) { |
| 3264 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3265 | } |
| 3266 | |
| 3267 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3268 | if (has_theme_stylebox_override(p_name)) { |
| 3269 | return true; |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | Vector<StringName> theme_types; |
| 3274 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3275 | return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types); |
| 3276 | } |
| 3277 | |
| 3278 | bool Control::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const { |
| 3279 | ERR_READ_THREAD_GUARD_V(false); |
| 3280 | if (!data.initialized) { |
| 3281 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3282 | } |
| 3283 | |
| 3284 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3285 | if (has_theme_font_override(p_name)) { |
| 3286 | return true; |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | Vector<StringName> theme_types; |
| 3291 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3292 | return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types); |
| 3293 | } |
| 3294 | |
| 3295 | bool Control::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { |
| 3296 | ERR_READ_THREAD_GUARD_V(false); |
| 3297 | if (!data.initialized) { |
| 3298 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3299 | } |
| 3300 | |
| 3301 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3302 | if (has_theme_font_size_override(p_name)) { |
| 3303 | return true; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | Vector<StringName> theme_types; |
| 3308 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3309 | return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types); |
| 3310 | } |
| 3311 | |
| 3312 | bool Control::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const { |
| 3313 | ERR_READ_THREAD_GUARD_V(false); |
| 3314 | if (!data.initialized) { |
| 3315 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3316 | } |
| 3317 | |
| 3318 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3319 | if (has_theme_color_override(p_name)) { |
| 3320 | return true; |
| 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | Vector<StringName> theme_types; |
| 3325 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3326 | return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types); |
| 3327 | } |
| 3328 | |
| 3329 | bool Control::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { |
| 3330 | ERR_READ_THREAD_GUARD_V(false); |
| 3331 | if (!data.initialized) { |
| 3332 | WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", get_description())); |
| 3333 | } |
| 3334 | |
| 3335 | if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == data.theme_type_variation) { |
| 3336 | if (has_theme_constant_override(p_name)) { |
| 3337 | return true; |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | Vector<StringName> theme_types; |
| 3342 | data.theme_owner->get_theme_type_dependencies(this, p_theme_type, theme_types); |
| 3343 | return data.theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types); |
| 3344 | } |
| 3345 | |
| 3346 | /// Local property overrides. |
| 3347 | |
| 3348 | void Control::add_theme_icon_override(const StringName &p_name, RequiredParam<Texture2D> rp_icon) { |
| 3349 | ERR_MAIN_THREAD_GUARD; |
| 3350 | EXTRACT_PARAM_OR_FAIL(p_icon, rp_icon); |
| 3351 | |
| 3352 | if (data.theme_icon_override.has(p_name)) { |
| 3353 | data.theme_icon_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 3354 | } |
| 3355 | |
| 3356 | data.theme_icon_override[p_name] = p_icon; |
| 3357 | data.theme_icon_override[p_name]->connect_changed(callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); |
| 3358 | _notify_theme_override_changed(); |
| 3359 | } |
| 3360 | |
| 3361 | void Control::add_theme_style_override(const StringName &p_name, RequiredParam<StyleBox> rp_style) { |
| 3362 | ERR_MAIN_THREAD_GUARD; |
| 3363 | EXTRACT_PARAM_OR_FAIL(p_style, rp_style); |
| 3364 | |
| 3365 | if (data.theme_style_override.has(p_name)) { |
| 3366 | data.theme_style_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 3367 | } |
| 3368 | |
| 3369 | data.theme_style_override[p_name] = p_style; |
| 3370 | data.theme_style_override[p_name]->connect_changed(callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); |
| 3371 | _notify_theme_override_changed(); |
| 3372 | } |
| 3373 | |
| 3374 | void Control::add_theme_font_override(const StringName &p_name, RequiredParam<Font> rp_font) { |
| 3375 | ERR_MAIN_THREAD_GUARD; |
| 3376 | EXTRACT_PARAM_OR_FAIL(p_font, rp_font); |
| 3377 | |
| 3378 | if (data.theme_font_override.has(p_name)) { |
| 3379 | data.theme_font_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 3380 | } |
| 3381 | |
| 3382 | data.theme_font_override[p_name] = p_font; |
| 3383 | data.theme_font_override[p_name]->connect_changed(callable_mp(this, &Control::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED); |
| 3384 | _notify_theme_override_changed(); |
| 3385 | } |
| 3386 | |
| 3387 | void Control::add_theme_font_size_override(const StringName &p_name, int p_font_size) { |
| 3388 | ERR_MAIN_THREAD_GUARD; |
| 3389 | data.theme_font_size_override[p_name] = p_font_size; |
| 3390 | _notify_theme_override_changed(); |
| 3391 | } |
| 3392 | |
| 3393 | void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) { |
| 3394 | ERR_MAIN_THREAD_GUARD; |
| 3395 | data.theme_color_override[p_name] = p_color; |
| 3396 | _notify_theme_override_changed(); |
| 3397 | } |
| 3398 | |
| 3399 | void Control::add_theme_constant_override(const StringName &p_name, int p_constant) { |
| 3400 | ERR_MAIN_THREAD_GUARD; |
| 3401 | data.theme_constant_override[p_name] = p_constant; |
| 3402 | _notify_theme_override_changed(); |
| 3403 | } |
| 3404 | |
| 3405 | void Control::remove_theme_icon_override(const StringName &p_name) { |
| 3406 | ERR_MAIN_THREAD_GUARD; |
| 3407 | if (data.theme_icon_override.has(p_name)) { |
| 3408 | data.theme_icon_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 3409 | } |
| 3410 | |
| 3411 | data.theme_icon_override.erase(p_name); |
| 3412 | _notify_theme_override_changed(); |
| 3413 | } |
| 3414 | |
| 3415 | void Control::remove_theme_style_override(const StringName &p_name) { |
| 3416 | ERR_MAIN_THREAD_GUARD; |
| 3417 | if (data.theme_style_override.has(p_name)) { |
| 3418 | data.theme_style_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 3419 | } |
| 3420 | |
| 3421 | data.theme_style_override.erase(p_name); |
| 3422 | _notify_theme_override_changed(); |
| 3423 | } |
| 3424 | |
| 3425 | void Control::remove_theme_font_override(const StringName &p_name) { |
| 3426 | ERR_MAIN_THREAD_GUARD; |
| 3427 | if (data.theme_font_override.has(p_name)) { |
| 3428 | data.theme_font_override[p_name]->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 3429 | } |
| 3430 | |
| 3431 | data.theme_font_override.erase(p_name); |
| 3432 | _notify_theme_override_changed(); |
| 3433 | } |
| 3434 | |
| 3435 | void Control::remove_theme_font_size_override(const StringName &p_name) { |
| 3436 | ERR_MAIN_THREAD_GUARD; |
| 3437 | data.theme_font_size_override.erase(p_name); |
| 3438 | _notify_theme_override_changed(); |
| 3439 | } |
| 3440 | |
| 3441 | void Control::remove_theme_color_override(const StringName &p_name) { |
| 3442 | ERR_MAIN_THREAD_GUARD; |
| 3443 | data.theme_color_override.erase(p_name); |
| 3444 | _notify_theme_override_changed(); |
| 3445 | } |
| 3446 | |
| 3447 | void Control::remove_theme_constant_override(const StringName &p_name) { |
| 3448 | ERR_MAIN_THREAD_GUARD; |
| 3449 | data.theme_constant_override.erase(p_name); |
| 3450 | _notify_theme_override_changed(); |
| 3451 | } |
| 3452 | |
| 3453 | bool Control::has_theme_icon_override(const StringName &p_name) const { |
| 3454 | ERR_READ_THREAD_GUARD_V(false); |
| 3455 | const Ref<Texture2D> *tex = data.theme_icon_override.getptr(p_name); |
| 3456 | return tex != nullptr; |
| 3457 | } |
| 3458 | |
| 3459 | bool Control::has_theme_stylebox_override(const StringName &p_name) const { |
| 3460 | ERR_READ_THREAD_GUARD_V(false); |
| 3461 | const Ref<StyleBox> *style = data.theme_style_override.getptr(p_name); |
| 3462 | return style != nullptr; |
| 3463 | } |
| 3464 | |
| 3465 | bool Control::has_theme_font_override(const StringName &p_name) const { |
| 3466 | ERR_READ_THREAD_GUARD_V(false); |
| 3467 | const Ref<Font> *font = data.theme_font_override.getptr(p_name); |
| 3468 | return font != nullptr; |
| 3469 | } |
| 3470 | |
| 3471 | bool Control::has_theme_font_size_override(const StringName &p_name) const { |
| 3472 | ERR_READ_THREAD_GUARD_V(false); |
| 3473 | const int *font_size = data.theme_font_size_override.getptr(p_name); |
| 3474 | return font_size != nullptr; |
| 3475 | } |
| 3476 | |
| 3477 | bool Control::has_theme_color_override(const StringName &p_name) const { |
| 3478 | ERR_READ_THREAD_GUARD_V(false); |
| 3479 | const Color *color = data.theme_color_override.getptr(p_name); |
| 3480 | return color != nullptr; |
| 3481 | } |
| 3482 | |
| 3483 | bool Control::has_theme_constant_override(const StringName &p_name) const { |
| 3484 | ERR_READ_THREAD_GUARD_V(false); |
| 3485 | const int *constant = data.theme_constant_override.getptr(p_name); |
| 3486 | return constant != nullptr; |
| 3487 | } |
| 3488 | |
| 3489 | /// Default theme properties. |
| 3490 | |
| 3491 | float Control::get_theme_default_base_scale() const { |
| 3492 | ERR_READ_THREAD_GUARD_V(0); |
| 3493 | return data.theme_owner->get_theme_default_base_scale(); |
| 3494 | } |
| 3495 | |
| 3496 | Ref<Font> Control::get_theme_default_font() const { |
| 3497 | ERR_READ_THREAD_GUARD_V(Ref<Font>()); |
| 3498 | return data.theme_owner->get_theme_default_font(); |
| 3499 | } |
| 3500 | |
| 3501 | int Control::get_theme_default_font_size() const { |
| 3502 | ERR_READ_THREAD_GUARD_V(0); |
| 3503 | return data.theme_owner->get_theme_default_font_size(); |
| 3504 | } |
| 3505 | |
| 3506 | /// Bulk actions. |
| 3507 | |
| 3508 | void Control::begin_bulk_theme_override() { |
| 3509 | ERR_MAIN_THREAD_GUARD; |
| 3510 | data.bulk_theme_override = true; |
| 3511 | } |
| 3512 | |
| 3513 | void Control::end_bulk_theme_override() { |
| 3514 | ERR_MAIN_THREAD_GUARD; |
| 3515 | ERR_FAIL_COND(!data.bulk_theme_override); |
| 3516 | |
| 3517 | data.bulk_theme_override = false; |
| 3518 | _notify_theme_override_changed(); |
| 3519 | } |
| 3520 | |
| 3521 | // Internationalization. |
| 3522 | |
| 3523 | TypedArray<Vector3i> Control::structured_text_parser(TextServer::StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const { |
| 3524 | ERR_READ_THREAD_GUARD_V(TypedArray<Vector3i>()); |
| 3525 | if (p_parser_type == TextServer::STRUCTURED_TEXT_CUSTOM) { |
| 3526 | TypedArray<Vector3i> ret; |
| 3527 | GDVIRTUAL_CALL(_structured_text_parser, p_args, p_text, ret); |
| 3528 | return ret; |
| 3529 | } else { |
| 3530 | return TS->parse_structured_text(p_parser_type, p_args, p_text); |
| 3531 | } |
| 3532 | } |
| 3533 | |
| 3534 | void Control::set_layout_direction(Control::LayoutDirection p_direction) { |
| 3535 | ERR_MAIN_THREAD_GUARD; |
| 3536 | if (data.layout_dir == p_direction) { |
| 3537 | return; |
| 3538 | } |
| 3539 | ERR_FAIL_INDEX(p_direction, LAYOUT_DIRECTION_MAX); |
| 3540 | |
| 3541 | data.layout_dir = p_direction; |
| 3542 | |
| 3543 | propagate_notification(NOTIFICATION_LAYOUT_DIRECTION_CHANGED); |
| 3544 | } |
| 3545 | |
| 3546 | Control::LayoutDirection Control::get_layout_direction() const { |
| 3547 | ERR_READ_THREAD_GUARD_V(LAYOUT_DIRECTION_INHERITED); |
| 3548 | return data.layout_dir; |
| 3549 | } |
| 3550 | |
| 3551 | bool Control::is_layout_rtl() const { |
| 3552 | ERR_READ_THREAD_GUARD_V(false); |
| 3553 | if (data.is_rtl_dirty) { |
| 3554 | data.is_rtl_dirty = false; |
| 3555 | if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) { |
| 3556 | #ifdef TOOLS_ENABLED |
| 3557 | if (is_part_of_edited_scene() && GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) { |
| 3558 | data.is_rtl = true; |
| 3559 | return data.is_rtl; |
| 3560 | } |
| 3561 | if (is_inside_tree()) { |
| 3562 | Node *edited_scene_root = get_tree()->get_edited_scene_root(); |
| 3563 | if (edited_scene_root == this) { |
| 3564 | int proj_root_layout_direction = GLOBAL_GET_CACHED(int, "internationalization/rendering/root_node_layout_direction"); |
| 3565 | if (proj_root_layout_direction == 1) { |
| 3566 | data.is_rtl = false; |
| 3567 | } else if (proj_root_layout_direction == 2) { |
| 3568 | data.is_rtl = true; |
| 3569 | } else if (proj_root_layout_direction == 3) { |
| 3570 | data.is_rtl = TS->is_locale_right_to_left(OS::get_singleton()->get_locale()); |
| 3571 | } else { |
| 3572 | data.is_rtl = TS->is_locale_right_to_left(_get_locale()); |
| 3573 | } |
| 3574 | return data.is_rtl; |
| 3575 | } |
| 3576 | } |
| 3577 | #else |
| 3578 | if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) { |
| 3579 | data.is_rtl = true; |
| 3580 | return data.is_rtl; |
| 3581 | } |
| 3582 | #endif // TOOLS_ENABLED |
| 3583 | const StringName domain_name = get_translation_domain(); |
| 3584 | Node *parent_node = get_parent(); |
| 3585 | while (parent_node && domain_name == parent_node->get_translation_domain()) { |
| 3586 | Control *parent_control = Object::cast_to<Control>(parent_node); |
| 3587 | if (parent_control) { |
| 3588 | data.is_rtl = parent_control->is_layout_rtl(); |
| 3589 | return data.is_rtl; |
| 3590 | } |
| 3591 | |
| 3592 | Window *parent_window = Object::cast_to<Window>(parent_node); |
| 3593 | if (parent_window) { |
| 3594 | data.is_rtl = parent_window->is_layout_rtl(); |
| 3595 | return data.is_rtl; |
| 3596 | } |
| 3597 | parent_node = parent_node->get_parent(); |
| 3598 | } |
| 3599 | |
| 3600 | if (root_layout_direction == 1) { |
| 3601 | data.is_rtl = false; |
| 3602 | } else if (root_layout_direction == 2) { |
| 3603 | data.is_rtl = true; |
| 3604 | } else if (root_layout_direction == 3) { |
| 3605 | String locale = OS::get_singleton()->get_locale(); |
| 3606 | data.is_rtl = TS->is_locale_right_to_left(locale); |
| 3607 | } else { |
| 3608 | data.is_rtl = TS->is_locale_right_to_left(_get_locale()); |
| 3609 | } |
| 3610 | } else if (data.layout_dir == LAYOUT_DIRECTION_APPLICATION_LOCALE) { |
| 3611 | if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) { |
| 3612 | data.is_rtl = true; |
| 3613 | } else { |
| 3614 | data.is_rtl = TS->is_locale_right_to_left(_get_locale()); |
| 3615 | } |
| 3616 | } else if (data.layout_dir == LAYOUT_DIRECTION_SYSTEM_LOCALE) { |
| 3617 | if (GLOBAL_GET_CACHED(bool, "internationalization/rendering/force_right_to_left_layout_direction")) { |
| 3618 | data.is_rtl = true; |
| 3619 | } else { |
| 3620 | data.is_rtl = TS->is_locale_right_to_left(OS::get_singleton()->get_locale()); |
| 3621 | } |
| 3622 | } else { |
| 3623 | data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL); |
| 3624 | } |
| 3625 | } |
| 3626 | return data.is_rtl; |
| 3627 | } |
| 3628 | |
| 3629 | void Control::set_localize_numeral_system(bool p_enable) { |
| 3630 | ERR_MAIN_THREAD_GUARD; |
| 3631 | if (p_enable == data.localize_numeral_system) { |
| 3632 | return; |
| 3633 | } |
| 3634 | |
| 3635 | data.localize_numeral_system = p_enable; |
| 3636 | |
| 3637 | notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED); |
| 3638 | } |
| 3639 | |
| 3640 | bool Control::is_localizing_numeral_system() const { |
| 3641 | ERR_READ_THREAD_GUARD_V(false); |
| 3642 | return data.localize_numeral_system; |
| 3643 | } |
| 3644 | |
| 3645 | #ifndef DISABLE_DEPRECATED |
| 3646 | void Control::set_auto_translate(bool p_enable) { |
| 3647 | ERR_MAIN_THREAD_GUARD; |
| 3648 | set_auto_translate_mode(p_enable ? AUTO_TRANSLATE_MODE_ALWAYS : AUTO_TRANSLATE_MODE_DISABLED); |
| 3649 | } |
| 3650 | |
| 3651 | bool Control::is_auto_translating() const { |
| 3652 | ERR_READ_THREAD_GUARD_V(false); |
| 3653 | return can_auto_translate(); |
| 3654 | } |
| 3655 | #endif // DISABLE_DEPRECATED |
| 3656 | |
| 3657 | void Control::set_tooltip_auto_translate_mode(AutoTranslateMode p_mode) { |
| 3658 | ERR_MAIN_THREAD_GUARD; |
| 3659 | data.tooltip_auto_translate_mode = p_mode; |
| 3660 | } |
| 3661 | |
| 3662 | Node::AutoTranslateMode Control::get_tooltip_auto_translate_mode() const { |
| 3663 | ERR_READ_THREAD_GUARD_V(AUTO_TRANSLATE_MODE_INHERIT); |
| 3664 | return data.tooltip_auto_translate_mode; |
| 3665 | } |
| 3666 | |
| 3667 | // Extra properties. |
| 3668 | |
| 3669 | void Control::set_tooltip_text(const String &p_hint) { |
| 3670 | ERR_MAIN_THREAD_GUARD; |
| 3671 | data.tooltip = p_hint; |
| 3672 | update_configuration_warnings(); |
| 3673 | } |
| 3674 | |
| 3675 | String Control::get_tooltip_text() const { |
| 3676 | ERR_READ_THREAD_GUARD_V(String()); |
| 3677 | return data.tooltip; |
| 3678 | } |
| 3679 | |
| 3680 | String Control::get_tooltip(const Point2 &p_pos) const { |
| 3681 | ERR_READ_THREAD_GUARD_V(String()); |
| 3682 | String ret; |
| 3683 | if (GDVIRTUAL_CALL(_get_tooltip, p_pos, ret)) { |
| 3684 | return ret; |
| 3685 | } |
| 3686 | return data.tooltip; |
| 3687 | } |
| 3688 | |
| 3689 | String Control::accessibility_get_contextual_info() const { |
| 3690 | ERR_READ_THREAD_GUARD_V(String()); |
| 3691 | String ret; |
| 3692 | GDVIRTUAL_CALL(_accessibility_get_contextual_info, ret); |
| 3693 | return ret; |
| 3694 | } |
| 3695 | |
| 3696 | Control *Control::make_custom_tooltip(const String &p_text) const { |
| 3697 | ERR_READ_THREAD_GUARD_V(nullptr); |
| 3698 | Object *ret = nullptr; |
| 3699 | GDVIRTUAL_CALL(_make_custom_tooltip, p_text, ret); |
| 3700 | return Object::cast_to<Control>(ret); |
| 3701 | } |
| 3702 | |
| 3703 | // Base object overrides. |
| 3704 | |
| 3705 | void Control::_accessibility_action_foucs(const Variant &p_data) { |
| 3706 | grab_focus(); |
| 3707 | } |
| 3708 | |
| 3709 | void Control::_accessibility_action_blur(const Variant &p_data) { |
| 3710 | release_focus(); |
| 3711 | } |
| 3712 | |
| 3713 | void Control::_accessibility_action_show_tooltip(const Variant &p_data) { |
| 3714 | Viewport *vp = get_viewport(); |
| 3715 | if (vp) { |
| 3716 | vp->show_tooltip(this); |
| 3717 | } |
| 3718 | } |
| 3719 | |
| 3720 | void Control::_accessibility_action_hide_tooltip(const Variant &p_data) { |
| 3721 | Viewport *vp = get_viewport(); |
| 3722 | if (vp) { |
| 3723 | vp->cancel_tooltip(); |
| 3724 | } |
| 3725 | } |
| 3726 | |
| 3727 | void Control::_accessibility_action_scroll_into_view(const Variant &p_data) { |
| 3728 | ScrollContainer *sc = Object::cast_to<ScrollContainer>(get_parent()); |
| 3729 | if (sc) { |
| 3730 | sc->ensure_control_visible(this); |
| 3731 | } |
| 3732 | } |
| 3733 | |
| 3734 | void Control::_notification(int p_notification) { |
| 3735 | ERR_MAIN_THREAD_GUARD; |
| 3736 | switch (p_notification) { |
| 3737 | #ifdef TOOLS_ENABLED |
| 3738 | case NOTIFICATION_EDITOR_PRE_SAVE: { |
| 3739 | saving = true; |
| 3740 | } break; |
| 3741 | case NOTIFICATION_EDITOR_POST_SAVE: { |
| 3742 | saving = false; |
| 3743 | } break; |
| 3744 | #endif // TOOLS_ENABLED |
| 3745 | |
| 3746 | case NOTIFICATION_ACCESSIBILITY_UPDATE: { |
| 3747 | RID ae = get_accessibility_element(); |
| 3748 | ERR_FAIL_COND(ae.is_null()); |
| 3749 | |
| 3750 | // Base info. |
| 3751 | if (get_parent_control()) { |
| 3752 | String container_info = get_parent_control()->get_accessibility_container_name(this); |
| 3753 | DisplayServer::get_singleton()->accessibility_update_set_name(ae, container_info.is_empty() ? get_accessibility_name() : get_accessibility_name() + " " + container_info); |
| 3754 | } else { |
| 3755 | DisplayServer::get_singleton()->accessibility_update_set_name(ae, get_accessibility_name()); |
| 3756 | } |
| 3757 | DisplayServer::get_singleton()->accessibility_update_set_description(ae, get_accessibility_description()); |
| 3758 | DisplayServer::get_singleton()->accessibility_update_set_live(ae, get_accessibility_live()); |
| 3759 | |
| 3760 | DisplayServer::get_singleton()->accessibility_update_set_transform(ae, get_transform()); |
| 3761 | DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, Rect2(Vector2(), data.size_cache)); |
| 3762 | DisplayServer::get_singleton()->accessibility_update_set_tooltip(ae, data.tooltip); |
| 3763 | DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_CLIPS_CHILDREN, data.clip_contents); |
| 3764 | DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_TOUCH_PASSTHROUGH, data.mouse_filter == MOUSE_FILTER_PASS); |
| 3765 | |
| 3766 | if (_is_focusable()) { |
| 3767 | DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_FOCUS, callable_mp(this, &Control::_accessibility_action_foucs)); |
| 3768 | DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_BLUR, callable_mp(this, &Control::_accessibility_action_blur)); |
| 3769 | } |
| 3770 | DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SHOW_TOOLTIP, callable_mp(this, &Control::_accessibility_action_show_tooltip)); |
| 3771 | DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_HIDE_TOOLTIP, callable_mp(this, &Control::_accessibility_action_hide_tooltip)); |
| 3772 | DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SCROLL_INTO_VIEW, callable_mp(this, &Control::_accessibility_action_scroll_into_view)); |
| 3773 | if (is_inside_tree() && get_viewport()->gui_is_dragging()) { |
| 3774 | if (can_drop_data(Vector2(Math::INF, Math::INF), get_viewport()->gui_get_drag_data())) { |
| 3775 | DisplayServer::get_singleton()->accessibility_update_set_extra_info(ae, vformat(RTR("%s can be dropped here. Use %s to drop, use %s to cancel."), get_viewport()->gui_get_drag_description(), InputMap::get_singleton()->get_action_description("ui_accessibility_drag_and_drop"), InputMap::get_singleton()->get_action_description("ui_cancel"))); |
| 3776 | } else { |
| 3777 | DisplayServer::get_singleton()->accessibility_update_set_extra_info(ae, vformat(RTR("%s can not be dropped here. Use %s to cancel."), get_viewport()->gui_get_drag_description(), InputMap::get_singleton()->get_action_description("ui_cancel"))); |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | // Related nodes. |
| 3782 | for (int i = 0; i < data.accessibility_controls_nodes.size(); i++) { |
| 3783 | const NodePath &np = data.accessibility_controls_nodes[i]; |
| 3784 | if (!np.is_empty()) { |
| 3785 | Node *n = get_node(np); |
| 3786 | if (n && !n->is_part_of_edited_scene()) { |
| 3787 | DisplayServer::get_singleton()->accessibility_update_add_related_controls(ae, n->get_accessibility_element()); |
| 3788 | } |
| 3789 | } |
| 3790 | } |
| 3791 | for (int i = 0; i < data.accessibility_described_by_nodes.size(); i++) { |
| 3792 | const NodePath &np = data.accessibility_described_by_nodes[i]; |
| 3793 | if (!np.is_empty()) { |
| 3794 | Node *n = get_node(np); |
| 3795 | if (n && !n->is_part_of_edited_scene()) { |
| 3796 | DisplayServer::get_singleton()->accessibility_update_add_related_described_by(ae, n->get_accessibility_element()); |
| 3797 | } |
| 3798 | } |
| 3799 | } |
| 3800 | for (int i = 0; i < data.accessibility_labeled_by_nodes.size(); i++) { |
| 3801 | const NodePath &np = data.accessibility_labeled_by_nodes[i]; |
| 3802 | if (!np.is_empty()) { |
| 3803 | Node *n = get_node(np); |
| 3804 | if (n && !n->is_part_of_edited_scene()) { |
| 3805 | DisplayServer::get_singleton()->accessibility_update_add_related_labeled_by(ae, n->get_accessibility_element()); |
| 3806 | } |
| 3807 | } |
| 3808 | } |
| 3809 | for (int i = 0; i < data.accessibility_flow_to_nodes.size(); i++) { |
| 3810 | const NodePath &np = data.accessibility_flow_to_nodes[i]; |
| 3811 | if (!np.is_empty()) { |
| 3812 | Node *n = get_node(np); |
| 3813 | if (n && !n->is_part_of_edited_scene()) { |
| 3814 | DisplayServer::get_singleton()->accessibility_update_add_related_flow_to(ae, n->get_accessibility_element()); |
| 3815 | } |
| 3816 | } |
| 3817 | } |
| 3818 | } break; |
| 3819 | |
| 3820 | case NOTIFICATION_POSTINITIALIZE: { |
| 3821 | data.initialized = true; |
| 3822 | |
| 3823 | _invalidate_theme_cache(); |
| 3824 | _update_theme_item_cache(); |
| 3825 | } break; |
| 3826 | |
| 3827 | case NOTIFICATION_PARENTED: { |
| 3828 | Node *parent_node = get_parent(); |
| 3829 | data.parent_control = Object::cast_to<Control>(parent_node); |
| 3830 | data.parent_window = Object::cast_to<Window>(parent_node); |
| 3831 | |
| 3832 | data.theme_owner->assign_theme_on_parented(this); |
| 3833 | |
| 3834 | _update_layout_mode(); |
| 3835 | |
| 3836 | _update_focus_behavior_recursive(); |
| 3837 | _update_mouse_behavior_recursive(); |
| 3838 | } break; |
| 3839 | |
| 3840 | case NOTIFICATION_UNPARENTED: { |
| 3841 | data.parent_control = nullptr; |
| 3842 | data.parent_window = nullptr; |
| 3843 | |
| 3844 | data.theme_owner->clear_theme_on_unparented(this); |
| 3845 | } break; |
| 3846 | |
| 3847 | case NOTIFICATION_ENTER_TREE: { |
| 3848 | // Emits NOTIFICATION_THEME_CHANGED internally. |
| 3849 | set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this)); |
| 3850 | } break; |
| 3851 | |
| 3852 | case NOTIFICATION_POST_ENTER_TREE: { |
| 3853 | data.is_rtl_dirty = true; |
| 3854 | update_minimum_size(); |
| 3855 | _size_changed(); |
| 3856 | } break; |
| 3857 | |
| 3858 | case NOTIFICATION_EXIT_TREE: { |
| 3859 | set_theme_context(nullptr, false); |
| 3860 | |
| 3861 | release_focus(); |
| 3862 | get_viewport()->_gui_remove_control(this); |
| 3863 | } break; |
| 3864 | |
| 3865 | case NOTIFICATION_READY: { |
| 3866 | #ifdef DEBUG_ENABLED |
| 3867 | connect(SceneStringName(ready), callable_mp(this, &Control::_clear_size_warning), CONNECT_DEFERRED | CONNECT_ONE_SHOT); |
| 3868 | #endif // DEBUG_ENABLED |
| 3869 | } break; |
| 3870 | |
| 3871 | case NOTIFICATION_ENTER_CANVAS: { |
| 3872 | data.is_rtl_dirty = true; |
| 3873 | |
| 3874 | CanvasItem *node = this; |
| 3875 | bool has_parent_control = false; |
| 3876 | |
| 3877 | while (!node->is_set_as_top_level()) { |
| 3878 | CanvasItem *parent = Object::cast_to<CanvasItem>(node->get_parent()); |
| 3879 | if (!parent) { |
| 3880 | break; |
| 3881 | } |
| 3882 | |
| 3883 | Control *parent_control = Object::cast_to<Control>(parent); |
| 3884 | if (parent_control) { |
| 3885 | has_parent_control = true; |
| 3886 | break; |
| 3887 | } |
| 3888 | |
| 3889 | node = parent; |
| 3890 | } |
| 3891 | |
| 3892 | if (has_parent_control) { |
| 3893 | // Do nothing, has a parent control. |
| 3894 | } else { |
| 3895 | // Is a regular root control or top_level. |
| 3896 | Viewport *viewport = get_viewport(); |
| 3897 | ERR_FAIL_NULL(viewport); |
| 3898 | data.RI = viewport->_gui_add_root_control(this); |
| 3899 | |
| 3900 | get_parent()->connect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty), CONNECT_REFERENCE_COUNTED); |
| 3901 | } |
| 3902 | |
| 3903 | data.parent_canvas_item = get_parent_item(); |
| 3904 | |
| 3905 | if (data.parent_canvas_item) { |
| 3906 | data.parent_canvas_item->connect(SceneStringName(item_rect_changed), callable_mp(this, &Control::_size_changed)); |
| 3907 | } else { |
| 3908 | // Connect viewport. |
| 3909 | Viewport *viewport = get_viewport(); |
| 3910 | ERR_FAIL_NULL(viewport); |
| 3911 | viewport->connect("size_changed", callable_mp(this, &Control::_size_changed)); |
| 3912 | } |
| 3913 | } break; |
| 3914 | |
| 3915 | case NOTIFICATION_EXIT_CANVAS: { |
| 3916 | if (data.parent_canvas_item) { |
| 3917 | data.parent_canvas_item->disconnect(SceneStringName(item_rect_changed), callable_mp(this, &Control::_size_changed)); |
| 3918 | data.parent_canvas_item = nullptr; |
| 3919 | } else { |
| 3920 | // Disconnect viewport. |
| 3921 | Viewport *viewport = get_viewport(); |
| 3922 | ERR_FAIL_NULL(viewport); |
| 3923 | viewport->disconnect("size_changed", callable_mp(this, &Control::_size_changed)); |
| 3924 | } |
| 3925 | |
| 3926 | if (data.RI) { |
| 3927 | get_viewport()->_gui_remove_root_control(data.RI); |
| 3928 | data.RI = nullptr; |
| 3929 | get_parent()->disconnect(SNAME("child_order_changed"), callable_mp(get_viewport(), &Viewport::gui_set_root_order_dirty)); |
| 3930 | } |
| 3931 | |
| 3932 | data.parent_canvas_item = nullptr; |
| 3933 | data.is_rtl_dirty = true; |
| 3934 | } break; |
| 3935 | |
| 3936 | case NOTIFICATION_CHILD_ORDER_CHANGED: { |
| 3937 | // Some parents need to know the order of the children to draw (like TabContainer), |
| 3938 | // so we update them just in case. |
| 3939 | queue_redraw(); |
| 3940 | } break; |
| 3941 | |
| 3942 | case NOTIFICATION_RESIZED: { |
| 3943 | emit_signal(SceneStringName(resized)); |
| 3944 | } break; |
| 3945 | |
| 3946 | case NOTIFICATION_DRAW: { |
| 3947 | _update_canvas_item_transform(); |
| 3948 | RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size())); |
| 3949 | RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents); |
| 3950 | } break; |
| 3951 | |
| 3952 | case NOTIFICATION_FOCUS_ENTER: { |
| 3953 | emit_signal(SceneStringName(focus_entered)); |
| 3954 | queue_redraw(); |
| 3955 | } break; |
| 3956 | |
| 3957 | case NOTIFICATION_FOCUS_EXIT: { |
| 3958 | emit_signal(SceneStringName(focus_exited)); |
| 3959 | queue_redraw(); |
| 3960 | } break; |
| 3961 | |
| 3962 | case NOTIFICATION_THEME_CHANGED: { |
| 3963 | emit_signal(SceneStringName(theme_changed)); |
| 3964 | |
| 3965 | _invalidate_theme_cache(); |
| 3966 | _update_theme_item_cache(); |
| 3967 | queue_redraw(); |
| 3968 | |
| 3969 | update_minimum_size(); |
| 3970 | _size_changed(); |
| 3971 | } break; |
| 3972 | |
| 3973 | case NOTIFICATION_VISIBILITY_CHANGED: { |
| 3974 | if (!is_visible_in_tree()) { |
| 3975 | if (get_viewport() != nullptr) { |
| 3976 | get_viewport()->_gui_hide_control(this); |
| 3977 | } |
| 3978 | } else { |
| 3979 | update_minimum_size(); |
| 3980 | _size_changed(); |
| 3981 | } |
| 3982 | } break; |
| 3983 | |
| 3984 | case NOTIFICATION_TRANSLATION_CHANGED: |
| 3985 | case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { |
| 3986 | if (is_inside_tree()) { |
| 3987 | data.is_rtl_dirty = true; |
| 3988 | |
| 3989 | _invalidate_theme_cache(); |
| 3990 | _update_theme_item_cache(); |
| 3991 | queue_redraw(); |
| 3992 | |
| 3993 | update_minimum_size(); |
| 3994 | _size_changed(); |
| 3995 | } |
| 3996 | } break; |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | void Control::_bind_methods() { |
| 4001 | ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event); |
| 4002 | ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size); |
| 4003 | ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size); |
| 4004 | |
| 4005 | ClassDB::bind_method(D_METHOD("_set_layout_mode", "mode"), &Control::_set_layout_mode); |
| 4006 | ClassDB::bind_method(D_METHOD("_get_layout_mode"), &Control::_get_layout_mode); |
| 4007 | ClassDB::bind_method(D_METHOD("_set_anchors_layout_preset", "preset"), &Control::_set_anchors_layout_preset); |
| 4008 | ClassDB::bind_method(D_METHOD("_get_anchors_layout_preset"), &Control::_get_anchors_layout_preset); |
| 4009 | ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_offsets"), &Control::set_anchors_preset, DEFVAL(false)); |
| 4010 | ClassDB::bind_method(D_METHOD("set_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0)); |
| 4011 | ClassDB::bind_method(D_METHOD("set_anchors_and_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_anchors_and_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0)); |
| 4012 | |
| 4013 | ClassDB::bind_method(D_METHOD("_set_anchor", "side", "anchor"), &Control::_set_anchor); |
| 4014 | ClassDB::bind_method(D_METHOD("set_anchor", "side", "anchor", "keep_offset", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true)); |
| 4015 | ClassDB::bind_method(D_METHOD("get_anchor", "side"), &Control::get_anchor); |
| 4016 | ClassDB::bind_method(D_METHOD("set_offset", "side", "offset"), &Control::set_offset); |
| 4017 | ClassDB::bind_method(D_METHOD("get_offset", "offset"), &Control::get_offset); |
| 4018 | ClassDB::bind_method(D_METHOD("set_anchor_and_offset", "side", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_offset, DEFVAL(false)); |
| 4019 | |
| 4020 | ClassDB::bind_method(D_METHOD("set_begin", "position"), &Control::set_begin); |
| 4021 | ClassDB::bind_method(D_METHOD("set_end", "position"), &Control::set_end); |
| 4022 | ClassDB::bind_method(D_METHOD("set_position", "position", "keep_offsets"), &Control::set_position, DEFVAL(false)); |
| 4023 | ClassDB::bind_method(D_METHOD("_set_position", "position"), &Control::_set_position); |
| 4024 | ClassDB::bind_method(D_METHOD("set_size", "size", "keep_offsets"), &Control::set_size, DEFVAL(false)); |
| 4025 | ClassDB::bind_method(D_METHOD("reset_size"), &Control::reset_size); |
| 4026 | ClassDB::bind_method(D_METHOD("_set_size", "size"), &Control::_set_size); |
| 4027 | ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size); |
| 4028 | ClassDB::bind_method(D_METHOD("set_global_position", "position", "keep_offsets"), &Control::set_global_position, DEFVAL(false)); |
| 4029 | ClassDB::bind_method(D_METHOD("_set_global_position", "position"), &Control::_set_global_position); |
| 4030 | ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation); |
| 4031 | ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Control::set_rotation_degrees); |
| 4032 | ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale); |
| 4033 | ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset); |
| 4034 | ClassDB::bind_method(D_METHOD("set_pivot_offset_ratio", "ratio"), &Control::set_pivot_offset_ratio); |
| 4035 | ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin); |
| 4036 | ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end); |
| 4037 | ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position); |
| 4038 | ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size); |
| 4039 | ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation); |
| 4040 | ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Control::get_rotation_degrees); |
| 4041 | ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale); |
| 4042 | ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset); |
| 4043 | ClassDB::bind_method(D_METHOD("get_pivot_offset_ratio"), &Control::get_pivot_offset_ratio); |
| 4044 | ClassDB::bind_method(D_METHOD("get_combined_pivot_offset"), &Control::get_combined_pivot_offset); |
| 4045 | ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size); |
| 4046 | ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_parent_area_size); |
| 4047 | ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position); |
| 4048 | ClassDB::bind_method(D_METHOD("get_screen_position"), &Control::get_screen_position); |
| 4049 | ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect); |
| 4050 | ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect); |
| 4051 | ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode); |
| 4052 | ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode); |
| 4053 | ClassDB::bind_method(D_METHOD("get_focus_mode_with_override"), &Control::get_focus_mode_with_override); |
| 4054 | ClassDB::bind_method(D_METHOD("set_focus_behavior_recursive", "focus_behavior_recursive"), &Control::set_focus_behavior_recursive); |
| 4055 | ClassDB::bind_method(D_METHOD("get_focus_behavior_recursive"), &Control::get_focus_behavior_recursive); |
| 4056 | ClassDB::bind_method(D_METHOD("has_focus", "ignore_hidden_focus"), &Control::has_focus, DEFVAL(false)); |
| 4057 | ClassDB::bind_method(D_METHOD("grab_focus", "hide_focus"), &Control::grab_focus, DEFVAL(false)); |
| 4058 | ClassDB::bind_method(D_METHOD("release_focus"), &Control::release_focus); |
| 4059 | ClassDB::bind_method(D_METHOD("find_prev_valid_focus"), &Control::find_prev_valid_focus); |
| 4060 | ClassDB::bind_method(D_METHOD("find_next_valid_focus"), &Control::find_next_valid_focus); |
| 4061 | ClassDB::bind_method(D_METHOD("find_valid_focus_neighbor", "side"), &Control::find_valid_focus_neighbor); |
| 4062 | |
| 4063 | ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags); |
| 4064 | ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags); |
| 4065 | |
| 4066 | ClassDB::bind_method(D_METHOD("set_stretch_ratio", "ratio"), &Control::set_stretch_ratio); |
| 4067 | ClassDB::bind_method(D_METHOD("get_stretch_ratio"), &Control::get_stretch_ratio); |
| 4068 | |
| 4069 | ClassDB::bind_method(D_METHOD("set_v_size_flags", "flags"), &Control::set_v_size_flags); |
| 4070 | ClassDB::bind_method(D_METHOD("get_v_size_flags"), &Control::get_v_size_flags); |
| 4071 | |
| 4072 | ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Control::set_theme); |
| 4073 | ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme); |
| 4074 | |
| 4075 | ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Control::set_theme_type_variation); |
| 4076 | ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Control::get_theme_type_variation); |
| 4077 | |
| 4078 | ClassDB::bind_method(D_METHOD("begin_bulk_theme_override"), &Control::begin_bulk_theme_override); |
| 4079 | ClassDB::bind_method(D_METHOD("end_bulk_theme_override"), &Control::end_bulk_theme_override); |
| 4080 | |
| 4081 | ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override); |
| 4082 | ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override); |
| 4083 | ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Control::add_theme_font_override); |
| 4084 | ClassDB::bind_method(D_METHOD("add_theme_font_size_override", "name", "font_size"), &Control::add_theme_font_size_override); |
| 4085 | ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Control::add_theme_color_override); |
| 4086 | ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Control::add_theme_constant_override); |
| 4087 | |
| 4088 | ClassDB::bind_method(D_METHOD("remove_theme_icon_override", "name"), &Control::remove_theme_icon_override); |
| 4089 | ClassDB::bind_method(D_METHOD("remove_theme_stylebox_override", "name"), &Control::remove_theme_style_override); |
| 4090 | ClassDB::bind_method(D_METHOD("remove_theme_font_override", "name"), &Control::remove_theme_font_override); |
| 4091 | ClassDB::bind_method(D_METHOD("remove_theme_font_size_override", "name"), &Control::remove_theme_font_size_override); |
| 4092 | ClassDB::bind_method(D_METHOD("remove_theme_color_override", "name"), &Control::remove_theme_color_override); |
| 4093 | ClassDB::bind_method(D_METHOD("remove_theme_constant_override", "name"), &Control::remove_theme_constant_override); |
| 4094 | |
| 4095 | ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Control::get_theme_icon, DEFVAL(StringName())); |
| 4096 | ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Control::get_theme_stylebox, DEFVAL(StringName())); |
| 4097 | ClassDB::bind_method(D_METHOD("get_theme_font", "name", "theme_type"), &Control::get_theme_font, DEFVAL(StringName())); |
| 4098 | ClassDB::bind_method(D_METHOD("get_theme_font_size", "name", "theme_type"), &Control::get_theme_font_size, DEFVAL(StringName())); |
| 4099 | ClassDB::bind_method(D_METHOD("get_theme_color", "name", "theme_type"), &Control::get_theme_color, DEFVAL(StringName())); |
| 4100 | ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "theme_type"), &Control::get_theme_constant, DEFVAL(StringName())); |
| 4101 | |
| 4102 | ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Control::has_theme_icon_override); |
| 4103 | ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Control::has_theme_stylebox_override); |
| 4104 | ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Control::has_theme_font_override); |
| 4105 | ClassDB::bind_method(D_METHOD("has_theme_font_size_override", "name"), &Control::has_theme_font_size_override); |
| 4106 | ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Control::has_theme_color_override); |
| 4107 | ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Control::has_theme_constant_override); |
| 4108 | |
| 4109 | ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "theme_type"), &Control::has_theme_icon, DEFVAL(StringName())); |
| 4110 | ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "theme_type"), &Control::has_theme_stylebox, DEFVAL(StringName())); |
| 4111 | ClassDB::bind_method(D_METHOD("has_theme_font", "name", "theme_type"), &Control::has_theme_font, DEFVAL(StringName())); |
| 4112 | ClassDB::bind_method(D_METHOD("has_theme_font_size", "name", "theme_type"), &Control::has_theme_font_size, DEFVAL(StringName())); |
| 4113 | ClassDB::bind_method(D_METHOD("has_theme_color", "name", "theme_type"), &Control::has_theme_color, DEFVAL(StringName())); |
| 4114 | ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "theme_type"), &Control::has_theme_constant, DEFVAL(StringName())); |
| 4115 | |
| 4116 | ClassDB::bind_method(D_METHOD("get_theme_default_base_scale"), &Control::get_theme_default_base_scale); |
| 4117 | ClassDB::bind_method(D_METHOD("get_theme_default_font"), &Control::get_theme_default_font); |
| 4118 | ClassDB::bind_method(D_METHOD("get_theme_default_font_size"), &Control::get_theme_default_font_size); |
| 4119 | |
| 4120 | ClassDB::bind_method(D_METHOD("get_parent_control"), &Control::get_parent_control); |
| 4121 | |
| 4122 | ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction); |
| 4123 | ClassDB::bind_method(D_METHOD("get_h_grow_direction"), &Control::get_h_grow_direction); |
| 4124 | |
| 4125 | ClassDB::bind_method(D_METHOD("set_v_grow_direction", "direction"), &Control::set_v_grow_direction); |
| 4126 | ClassDB::bind_method(D_METHOD("get_v_grow_direction"), &Control::get_v_grow_direction); |
| 4127 | |
| 4128 | ClassDB::bind_method(D_METHOD("set_tooltip_auto_translate_mode", "mode"), &Control::set_tooltip_auto_translate_mode); |
| 4129 | ClassDB::bind_method(D_METHOD("get_tooltip_auto_translate_mode"), &Control::get_tooltip_auto_translate_mode); |
| 4130 | ClassDB::bind_method(D_METHOD("set_tooltip_text", "hint"), &Control::set_tooltip_text); |
| 4131 | ClassDB::bind_method(D_METHOD("get_tooltip_text"), &Control::get_tooltip_text); |
| 4132 | ClassDB::bind_method(D_METHOD("get_tooltip", "at_position"), &Control::get_tooltip, DEFVAL(Point2())); |
| 4133 | |
| 4134 | ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Control::set_default_cursor_shape); |
| 4135 | ClassDB::bind_method(D_METHOD("get_default_cursor_shape"), &Control::get_default_cursor_shape); |
| 4136 | ClassDB::bind_method(D_METHOD("get_cursor_shape", "position"), &Control::get_cursor_shape, DEFVAL(Point2())); |
| 4137 | |
| 4138 | ClassDB::bind_method(D_METHOD("set_focus_neighbor", "side", "neighbor"), &Control::set_focus_neighbor); |
| 4139 | ClassDB::bind_method(D_METHOD("get_focus_neighbor", "side"), &Control::get_focus_neighbor); |
| 4140 | |
| 4141 | ClassDB::bind_method(D_METHOD("set_focus_next", "next"), &Control::set_focus_next); |
| 4142 | ClassDB::bind_method(D_METHOD("get_focus_next"), &Control::get_focus_next); |
| 4143 | |
| 4144 | ClassDB::bind_method(D_METHOD("set_focus_previous", "previous"), &Control::set_focus_previous); |
| 4145 | ClassDB::bind_method(D_METHOD("get_focus_previous"), &Control::get_focus_previous); |
| 4146 | |
| 4147 | ClassDB::bind_method(D_METHOD("force_drag", "data", "preview"), &Control::force_drag); |
| 4148 | |
| 4149 | ClassDB::bind_method(D_METHOD("accessibility_drag"), &Control::accessibility_drag); |
| 4150 | ClassDB::bind_method(D_METHOD("accessibility_drop"), &Control::accessibility_drop); |
| 4151 | |
| 4152 | ClassDB::bind_method(D_METHOD("set_accessibility_name", "name"), &Control::set_accessibility_name); |
| 4153 | ClassDB::bind_method(D_METHOD("get_accessibility_name"), &Control::get_accessibility_name); |
| 4154 | ClassDB::bind_method(D_METHOD("set_accessibility_description", "description"), &Control::set_accessibility_description); |
| 4155 | ClassDB::bind_method(D_METHOD("get_accessibility_description"), &Control::get_accessibility_description); |
| 4156 | ClassDB::bind_method(D_METHOD("set_accessibility_live", "mode"), &Control::set_accessibility_live); |
| 4157 | ClassDB::bind_method(D_METHOD("get_accessibility_live"), &Control::get_accessibility_live); |
| 4158 | |
| 4159 | ClassDB::bind_method(D_METHOD("set_accessibility_controls_nodes", "node_path"), &Control::set_accessibility_controls_nodes); |
| 4160 | ClassDB::bind_method(D_METHOD("get_accessibility_controls_nodes"), &Control::get_accessibility_controls_nodes); |
| 4161 | ClassDB::bind_method(D_METHOD("set_accessibility_described_by_nodes", "node_path"), &Control::set_accessibility_described_by_nodes); |
| 4162 | ClassDB::bind_method(D_METHOD("get_accessibility_described_by_nodes"), &Control::get_accessibility_described_by_nodes); |
| 4163 | ClassDB::bind_method(D_METHOD("set_accessibility_labeled_by_nodes", "node_path"), &Control::set_accessibility_labeled_by_nodes); |
| 4164 | ClassDB::bind_method(D_METHOD("get_accessibility_labeled_by_nodes"), &Control::get_accessibility_labeled_by_nodes); |
| 4165 | ClassDB::bind_method(D_METHOD("set_accessibility_flow_to_nodes", "node_path"), &Control::set_accessibility_flow_to_nodes); |
| 4166 | ClassDB::bind_method(D_METHOD("get_accessibility_flow_to_nodes"), &Control::get_accessibility_flow_to_nodes); |
| 4167 | |
| 4168 | ClassDB::bind_method(D_METHOD("set_mouse_filter", "filter"), &Control::set_mouse_filter); |
| 4169 | ClassDB::bind_method(D_METHOD("get_mouse_filter"), &Control::get_mouse_filter); |
| 4170 | ClassDB::bind_method(D_METHOD("get_mouse_filter_with_override"), &Control::get_mouse_filter_with_override); |
| 4171 | |
| 4172 | ClassDB::bind_method(D_METHOD("set_mouse_behavior_recursive", "mouse_behavior_recursive"), &Control::set_mouse_behavior_recursive); |
| 4173 | ClassDB::bind_method(D_METHOD("get_mouse_behavior_recursive"), &Control::get_mouse_behavior_recursive); |
| 4174 | |
| 4175 | ClassDB::bind_method(D_METHOD("set_force_pass_scroll_events", "force_pass_scroll_events"), &Control::set_force_pass_scroll_events); |
| 4176 | ClassDB::bind_method(D_METHOD("is_force_pass_scroll_events"), &Control::is_force_pass_scroll_events); |
| 4177 | |
| 4178 | ClassDB::bind_method(D_METHOD("set_clip_contents", "enable"), &Control::set_clip_contents); |
| 4179 | ClassDB::bind_method(D_METHOD("is_clipping_contents"), &Control::is_clipping_contents); |
| 4180 | |
| 4181 | ClassDB::bind_method(D_METHOD("grab_click_focus"), &Control::grab_click_focus); |
| 4182 | |
| 4183 | ClassDB::bind_method(D_METHOD("set_drag_forwarding", "drag_func", "can_drop_func", "drop_func"), &Control::set_drag_forwarding); |
| 4184 | ClassDB::bind_method(D_METHOD("set_drag_preview", "control"), &Control::set_drag_preview); |
| 4185 | ClassDB::bind_method(D_METHOD("is_drag_successful"), &Control::is_drag_successful); |
| 4186 | |
| 4187 | ClassDB::bind_method(D_METHOD("warp_mouse", "position"), &Control::warp_mouse); |
| 4188 | |
| 4189 | ClassDB::bind_method(D_METHOD("set_shortcut_context", "node"), &Control::set_shortcut_context); |
| 4190 | ClassDB::bind_method(D_METHOD("get_shortcut_context"), &Control::get_shortcut_context); |
| 4191 | |
| 4192 | ClassDB::bind_method(D_METHOD("update_minimum_size"), &Control::update_minimum_size); |
| 4193 | |
| 4194 | ClassDB::bind_method(D_METHOD("set_layout_direction", "direction"), &Control::set_layout_direction); |
| 4195 | ClassDB::bind_method(D_METHOD("get_layout_direction"), &Control::get_layout_direction); |
| 4196 | ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Control::is_layout_rtl); |
| 4197 | |
| 4198 | #ifndef DISABLE_DEPRECATED |
| 4199 | ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate); |
| 4200 | ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating); |
| 4201 | #endif // DISABLE_DEPRECATED |
| 4202 | |
| 4203 | ClassDB::bind_method(D_METHOD("set_localize_numeral_system", "enable"), &Control::set_localize_numeral_system); |
| 4204 | ClassDB::bind_method(D_METHOD("is_localizing_numeral_system"), &Control::is_localizing_numeral_system); |
| 4205 | |
| 4206 | ADD_GROUP("Layout", ""); |
| 4207 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_contents"), "set_clip_contents", "is_clipping_contents"); |
| 4208 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "custom_minimum_size", PROPERTY_HINT_NONE, "suffix:px"), "set_custom_minimum_size", "get_custom_minimum_size"); |
| 4209 | ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale"), "set_layout_direction", "get_layout_direction"); |
| 4210 | ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_mode", PROPERTY_HINT_ENUM, "Position,Anchors,Container,Uncontrolled", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_layout_mode", "_get_layout_mode"); |
| 4211 | ADD_PROPERTY_DEFAULT("layout_mode", LayoutMode::LAYOUT_MODE_POSITION); |
| 4212 | |
| 4213 | constexpr struct { |
| 4214 | const char *name; |
| 4215 | LayoutPreset value; |
| 4216 | } anchors_presets[] = { |
| 4217 | { TTRC("Full Rect"), PRESET_FULL_RECT }, |
| 4218 | { TTRC("Top Left"), PRESET_TOP_LEFT }, |
| 4219 | { TTRC("Top Right"), PRESET_TOP_RIGHT }, |
| 4220 | { TTRC("Bottom Right"), PRESET_BOTTOM_RIGHT }, |
| 4221 | { TTRC("Bottom Left"), PRESET_BOTTOM_LEFT }, |
| 4222 | { TTRC("Center Left"), PRESET_CENTER_LEFT }, |
| 4223 | { TTRC("Center Top"), PRESET_CENTER_TOP }, |
| 4224 | { TTRC("Center Right"), PRESET_CENTER_RIGHT }, |
| 4225 | { TTRC("Center Bottom"), PRESET_CENTER_BOTTOM }, |
| 4226 | { TTRC("Center"), PRESET_CENTER }, |
| 4227 | { TTRC("Left Wide"), PRESET_LEFT_WIDE }, |
| 4228 | { TTRC("Top Wide"), PRESET_TOP_WIDE }, |
| 4229 | { TTRC("Right Wide"), PRESET_RIGHT_WIDE }, |
| 4230 | { TTRC("Bottom Wide"), PRESET_BOTTOM_WIDE }, |
| 4231 | { TTRC("VCenter Wide"), PRESET_VCENTER_WIDE }, |
| 4232 | { TTRC("HCenter Wide"), PRESET_HCENTER_WIDE }, |
| 4233 | }; |
| 4234 | StringBuilder builder; |
| 4235 | builder.append(TTRC("Custom")); |
| 4236 | builder.append(":-1"); |
| 4237 | for (size_t i = 0; i < std_size(anchors_presets); i++) { |
| 4238 | builder.append(","); |
| 4239 | builder.append(anchors_presets[i].name); |
| 4240 | builder.append(":"); |
| 4241 | builder.append(itos(anchors_presets[i].value)); |
| 4242 | } |
| 4243 | const String anchors_presets_options = builder.as_string(); |
| 4244 | |
| 4245 | ADD_PROPERTY(PropertyInfo(Variant::INT, "anchors_preset", PROPERTY_HINT_ENUM, anchors_presets_options, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "_set_anchors_layout_preset", "_get_anchors_layout_preset"); |
| 4246 | ADD_PROPERTY_DEFAULT("anchors_preset", -1); |
| 4247 | |
| 4248 | ADD_SUBGROUP_INDENT("Anchor Points", "anchor_", 1); |
| 4249 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT); |
| 4250 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_TOP); |
| 4251 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_RIGHT); |
| 4252 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.001,or_less,or_greater"), "_set_anchor", "get_anchor", SIDE_BOTTOM); |
| 4253 | |
| 4254 | ADD_SUBGROUP_INDENT("Anchor Offsets", "offset_", 1); |
| 4255 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "offset_left", PROPERTY_HINT_RANGE, "-4096,4096,1,or_less,or_greater,suffix:px"), "set_offset", "get_offset", SIDE_LEFT); |
| 4256 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "offset_top", PROPERTY_HINT_RANGE, "-4096,4096,1,or_less,or_greater,suffix:px"), "set_offset", "get_offset", SIDE_TOP); |
| 4257 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "offset_right", PROPERTY_HINT_RANGE, "-4096,4096,1,or_less,or_greater,suffix:px"), "set_offset", "get_offset", SIDE_RIGHT); |
| 4258 | ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "offset_bottom", PROPERTY_HINT_RANGE, "-4096,4096,1,or_less,or_greater,suffix:px"), "set_offset", "get_offset", SIDE_BOTTOM); |
| 4259 | |
| 4260 | ADD_SUBGROUP_INDENT("Grow Direction", "grow_", 1); |
| 4261 | ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Left,Right,Both"), "set_h_grow_direction", "get_h_grow_direction"); |
| 4262 | ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Top,Bottom,Both"), "set_v_grow_direction", "get_v_grow_direction"); |
| 4263 | |
| 4264 | ADD_SUBGROUP("Transform", ""); |
| 4265 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_EDITOR), "_set_size", "get_size"); |
| 4266 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_EDITOR), "_set_position", "get_position"); |
| 4267 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position"); |
| 4268 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_less,or_greater,radians_as_degrees"), "set_rotation", "get_rotation"); |
| 4269 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_rotation_degrees", "get_rotation_degrees"); |
| 4270 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale"); |
| 4271 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pivot_offset", PROPERTY_HINT_NONE, "suffix:px"), "set_pivot_offset", "get_pivot_offset"); |
| 4272 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pivot_offset_ratio"), "set_pivot_offset_ratio", "get_pivot_offset_ratio"); |
| 4273 | |
| 4274 | ADD_SUBGROUP("Container Sizing", "size_flags_"); |
| 4275 | ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_h_size_flags", "get_h_size_flags"); |
| 4276 | ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_v_size_flags", "get_v_size_flags"); |
| 4277 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio"); |
| 4278 | |
| 4279 | ADD_GROUP("Localization", ""); |
| 4280 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "localize_numeral_system"), "set_localize_numeral_system", "is_localizing_numeral_system"); |
| 4281 | |
| 4282 | #ifndef DISABLE_DEPRECATED |
| 4283 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_auto_translate", "is_auto_translating"); |
| 4284 | #endif // DISABLE_DEPRECATED |
| 4285 | |
| 4286 | ADD_GROUP("Tooltip", "tooltip_"); |
| 4287 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "tooltip_text", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip_text", "get_tooltip_text"); |
| 4288 | ADD_PROPERTY(PropertyInfo(Variant::INT, "tooltip_auto_translate_mode", PROPERTY_HINT_ENUM, "Inherit,Always,Disabled"), "set_tooltip_auto_translate_mode", "get_tooltip_auto_translate_mode"); |
| 4289 | |
| 4290 | ADD_GROUP("Focus", "focus_"); |
| 4291 | ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_left", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_LEFT); |
| 4292 | ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_top", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_TOP); |
| 4293 | ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_right", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_RIGHT); |
| 4294 | ADD_PROPERTYI(PropertyInfo(Variant::NODE_PATH, "focus_neighbor_bottom", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbor", "get_focus_neighbor", SIDE_BOTTOM); |
| 4295 | ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "focus_next", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_next", "get_focus_next"); |
| 4296 | ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "focus_previous", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_previous", "get_focus_previous"); |
| 4297 | ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All,Accessibility"), "set_focus_mode", "get_focus_mode"); |
| 4298 | ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_behavior_recursive", PROPERTY_HINT_ENUM, "Inherited,Disabled,Enabled"), "set_focus_behavior_recursive", "get_focus_behavior_recursive"); |
| 4299 | |
| 4300 | ADD_GROUP("Mouse", "mouse_"); |
| 4301 | ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass (Propagate Up),Ignore"), "set_mouse_filter", "get_mouse_filter"); |
| 4302 | ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_behavior_recursive", PROPERTY_HINT_ENUM, "Inherited,Disabled,Enabled"), "set_mouse_behavior_recursive", "get_mouse_behavior_recursive"); |
| 4303 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "mouse_force_pass_scroll_events"), "set_force_pass_scroll_events", "is_force_pass_scroll_events"); |
| 4304 | ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,I-Beam,Pointing Hand,Cross,Wait,Busy,Drag,Can Drop,Forbidden,Vertical Resize,Horizontal Resize,Secondary Diagonal Resize,Main Diagonal Resize,Move,Vertical Split,Horizontal Split,Help"), "set_default_cursor_shape", "get_default_cursor_shape"); |
| 4305 | |
| 4306 | ADD_GROUP("Input", ""); |
| 4307 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut_context", PROPERTY_HINT_NODE_TYPE, "Node"), "set_shortcut_context", "get_shortcut_context"); |
| 4308 | |
| 4309 | ADD_GROUP("Accessibility", "accessibility_"); |
| 4310 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "accessibility_name"), "set_accessibility_name", "get_accessibility_name"); |
| 4311 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "accessibility_description"), "set_accessibility_description", "get_accessibility_description"); |
| 4312 | ADD_PROPERTY(PropertyInfo(Variant::INT, "accessibility_live", PROPERTY_HINT_ENUM, "Off,Polite,Assertive"), "set_accessibility_live", "get_accessibility_live"); |
| 4313 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "accessibility_controls_nodes", PROPERTY_HINT_ARRAY_TYPE, "NodePath"), "set_accessibility_controls_nodes", "get_accessibility_controls_nodes"); |
| 4314 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "accessibility_described_by_nodes", PROPERTY_HINT_ARRAY_TYPE, "NodePath"), "set_accessibility_described_by_nodes", "get_accessibility_described_by_nodes"); |
| 4315 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "accessibility_labeled_by_nodes", PROPERTY_HINT_ARRAY_TYPE, "NodePath"), "set_accessibility_labeled_by_nodes", "get_accessibility_labeled_by_nodes"); |
| 4316 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "accessibility_flow_to_nodes", PROPERTY_HINT_ARRAY_TYPE, "NodePath"), "set_accessibility_flow_to_nodes", "get_accessibility_flow_to_nodes"); |
| 4317 | |
| 4318 | ADD_GROUP("Theme", "theme_"); |
| 4319 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); |
| 4320 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation"); |
| 4321 | |
| 4322 | BIND_ENUM_CONSTANT(FOCUS_NONE); |
| 4323 | BIND_ENUM_CONSTANT(FOCUS_CLICK); |
| 4324 | BIND_ENUM_CONSTANT(FOCUS_ALL); |
| 4325 | BIND_ENUM_CONSTANT(FOCUS_ACCESSIBILITY); |
| 4326 | |
| 4327 | BIND_ENUM_CONSTANT(FOCUS_BEHAVIOR_INHERITED); |
| 4328 | BIND_ENUM_CONSTANT(FOCUS_BEHAVIOR_DISABLED); |
| 4329 | BIND_ENUM_CONSTANT(FOCUS_BEHAVIOR_ENABLED); |
| 4330 | |
| 4331 | BIND_ENUM_CONSTANT(MOUSE_BEHAVIOR_INHERITED); |
| 4332 | BIND_ENUM_CONSTANT(MOUSE_BEHAVIOR_DISABLED); |
| 4333 | BIND_ENUM_CONSTANT(MOUSE_BEHAVIOR_ENABLED); |
| 4334 | |
| 4335 | BIND_CONSTANT(NOTIFICATION_RESIZED); |
| 4336 | BIND_CONSTANT(NOTIFICATION_MOUSE_ENTER); |
| 4337 | BIND_CONSTANT(NOTIFICATION_MOUSE_EXIT); |
| 4338 | BIND_CONSTANT(NOTIFICATION_MOUSE_ENTER_SELF); |
| 4339 | BIND_CONSTANT(NOTIFICATION_MOUSE_EXIT_SELF); |
| 4340 | BIND_CONSTANT(NOTIFICATION_FOCUS_ENTER); |
| 4341 | BIND_CONSTANT(NOTIFICATION_FOCUS_EXIT); |
| 4342 | BIND_CONSTANT(NOTIFICATION_THEME_CHANGED); |
| 4343 | BIND_CONSTANT(NOTIFICATION_SCROLL_BEGIN); |
| 4344 | BIND_CONSTANT(NOTIFICATION_SCROLL_END); |
| 4345 | BIND_CONSTANT(NOTIFICATION_LAYOUT_DIRECTION_CHANGED); |
| 4346 | |
| 4347 | BIND_ENUM_CONSTANT(CURSOR_ARROW); |
| 4348 | BIND_ENUM_CONSTANT(CURSOR_IBEAM); |
| 4349 | BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND); |
| 4350 | BIND_ENUM_CONSTANT(CURSOR_CROSS); |
| 4351 | BIND_ENUM_CONSTANT(CURSOR_WAIT); |
| 4352 | BIND_ENUM_CONSTANT(CURSOR_BUSY); |
| 4353 | BIND_ENUM_CONSTANT(CURSOR_DRAG); |
| 4354 | BIND_ENUM_CONSTANT(CURSOR_CAN_DROP); |
| 4355 | BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN); |
| 4356 | BIND_ENUM_CONSTANT(CURSOR_VSIZE); |
| 4357 | BIND_ENUM_CONSTANT(CURSOR_HSIZE); |
| 4358 | BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE); |
| 4359 | BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE); |
| 4360 | BIND_ENUM_CONSTANT(CURSOR_MOVE); |
| 4361 | BIND_ENUM_CONSTANT(CURSOR_VSPLIT); |
| 4362 | BIND_ENUM_CONSTANT(CURSOR_HSPLIT); |
| 4363 | BIND_ENUM_CONSTANT(CURSOR_HELP); |
| 4364 | |
| 4365 | BIND_ENUM_CONSTANT(PRESET_TOP_LEFT); |
| 4366 | BIND_ENUM_CONSTANT(PRESET_TOP_RIGHT); |
| 4367 | BIND_ENUM_CONSTANT(PRESET_BOTTOM_LEFT); |
| 4368 | BIND_ENUM_CONSTANT(PRESET_BOTTOM_RIGHT); |
| 4369 | BIND_ENUM_CONSTANT(PRESET_CENTER_LEFT); |
| 4370 | BIND_ENUM_CONSTANT(PRESET_CENTER_TOP); |
| 4371 | BIND_ENUM_CONSTANT(PRESET_CENTER_RIGHT); |
| 4372 | BIND_ENUM_CONSTANT(PRESET_CENTER_BOTTOM); |
| 4373 | BIND_ENUM_CONSTANT(PRESET_CENTER); |
| 4374 | BIND_ENUM_CONSTANT(PRESET_LEFT_WIDE); |
| 4375 | BIND_ENUM_CONSTANT(PRESET_TOP_WIDE); |
| 4376 | BIND_ENUM_CONSTANT(PRESET_RIGHT_WIDE); |
| 4377 | BIND_ENUM_CONSTANT(PRESET_BOTTOM_WIDE); |
| 4378 | BIND_ENUM_CONSTANT(PRESET_VCENTER_WIDE); |
| 4379 | BIND_ENUM_CONSTANT(PRESET_HCENTER_WIDE); |
| 4380 | BIND_ENUM_CONSTANT(PRESET_FULL_RECT); |
| 4381 | |
| 4382 | BIND_ENUM_CONSTANT(PRESET_MODE_MINSIZE); |
| 4383 | BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_WIDTH); |
| 4384 | BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT); |
| 4385 | BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE); |
| 4386 | |
| 4387 | BIND_BITFIELD_FLAG(SIZE_SHRINK_BEGIN); |
| 4388 | BIND_BITFIELD_FLAG(SIZE_FILL); |
| 4389 | BIND_BITFIELD_FLAG(SIZE_EXPAND); |
| 4390 | BIND_BITFIELD_FLAG(SIZE_EXPAND_FILL); |
| 4391 | BIND_BITFIELD_FLAG(SIZE_SHRINK_CENTER); |
| 4392 | BIND_BITFIELD_FLAG(SIZE_SHRINK_END); |
| 4393 | |
| 4394 | BIND_ENUM_CONSTANT(MOUSE_FILTER_STOP); |
| 4395 | BIND_ENUM_CONSTANT(MOUSE_FILTER_PASS); |
| 4396 | BIND_ENUM_CONSTANT(MOUSE_FILTER_IGNORE); |
| 4397 | |
| 4398 | BIND_ENUM_CONSTANT(GROW_DIRECTION_BEGIN); |
| 4399 | BIND_ENUM_CONSTANT(GROW_DIRECTION_END); |
| 4400 | BIND_ENUM_CONSTANT(GROW_DIRECTION_BOTH); |
| 4401 | |
| 4402 | BIND_ENUM_CONSTANT(ANCHOR_BEGIN); |
| 4403 | BIND_ENUM_CONSTANT(ANCHOR_END); |
| 4404 | |
| 4405 | BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_INHERITED); |
| 4406 | BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_APPLICATION_LOCALE); |
| 4407 | BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR); |
| 4408 | BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL); |
| 4409 | BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_SYSTEM_LOCALE); |
| 4410 | BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_MAX); |
| 4411 | #ifndef DISABLE_DEPRECATED |
| 4412 | BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE); |
| 4413 | #endif // DISABLE_DEPRECATED |
| 4414 | |
| 4415 | BIND_ENUM_CONSTANT(TEXT_DIRECTION_INHERITED); |
| 4416 | BIND_ENUM_CONSTANT(TEXT_DIRECTION_AUTO); |
| 4417 | BIND_ENUM_CONSTANT(TEXT_DIRECTION_LTR); |
| 4418 | BIND_ENUM_CONSTANT(TEXT_DIRECTION_RTL); |
| 4419 | |
| 4420 | ADD_SIGNAL(MethodInfo("resized")); |
| 4421 | ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); |
| 4422 | ADD_SIGNAL(MethodInfo("mouse_entered")); |
| 4423 | ADD_SIGNAL(MethodInfo("mouse_exited")); |
| 4424 | ADD_SIGNAL(MethodInfo("focus_entered")); |
| 4425 | ADD_SIGNAL(MethodInfo("focus_exited")); |
| 4426 | ADD_SIGNAL(MethodInfo("size_flags_changed")); |
| 4427 | ADD_SIGNAL(MethodInfo("minimum_size_changed")); |
| 4428 | ADD_SIGNAL(MethodInfo("theme_changed")); |
| 4429 | |
| 4430 | GDVIRTUAL_BIND(_has_point, "point"); |
| 4431 | GDVIRTUAL_BIND(_structured_text_parser, "args", "text"); |
| 4432 | GDVIRTUAL_BIND(_get_minimum_size); |
| 4433 | GDVIRTUAL_BIND(_get_tooltip, "at_position"); |
| 4434 | |
| 4435 | GDVIRTUAL_BIND(_get_drag_data, "at_position"); |
| 4436 | GDVIRTUAL_BIND(_can_drop_data, "at_position", "data"); |
| 4437 | GDVIRTUAL_BIND(_drop_data, "at_position", "data"); |
| 4438 | GDVIRTUAL_BIND(_make_custom_tooltip, "for_text"); |
| 4439 | |
| 4440 | GDVIRTUAL_BIND(_accessibility_get_contextual_info); |
| 4441 | GDVIRTUAL_BIND(_get_accessibility_container_name, "node"); |
| 4442 | |
| 4443 | GDVIRTUAL_BIND(_gui_input, "event"); |
| 4444 | } |
| 4445 | |
| 4446 | Control::Control() { |
| 4447 | _define_ancestry(AncestralClass::CONTROL); |
| 4448 | |
| 4449 | data.theme_owner = memnew(ThemeOwner(this)); |
| 4450 | |
| 4451 | set_physics_interpolation_mode(Node::PHYSICS_INTERPOLATION_MODE_OFF); |
| 4452 | } |
| 4453 | |
| 4454 | Control::~Control() { |
| 4455 | memdelete(data.theme_owner); |
| 4456 | |
| 4457 | // Resources need to be disconnected. |
| 4458 | for (KeyValue<StringName, Ref<Texture2D>> &E : data.theme_icon_override) { |
| 4459 | E.value->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 4460 | } |
| 4461 | for (KeyValue<StringName, Ref<StyleBox>> &E : data.theme_style_override) { |
| 4462 | E.value->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 4463 | } |
| 4464 | for (KeyValue<StringName, Ref<Font>> &E : data.theme_font_override) { |
| 4465 | E.value->disconnect_changed(callable_mp(this, &Control::_notify_theme_override_changed)); |
| 4466 | } |
| 4467 | |
| 4468 | // Then override maps can be simply cleared. |
| 4469 | data.theme_icon_override.clear(); |
| 4470 | data.theme_style_override.clear(); |
| 4471 | data.theme_font_override.clear(); |
| 4472 | data.theme_font_size_override.clear(); |
| 4473 | data.theme_color_override.clear(); |
| 4474 | data.theme_constant_override.clear(); |
| 4475 | } |