| 1 | /**************************************************************************/ |
| 2 | /* control.h */ |
| 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 | #ifndef CONTROL_H |
| 32 | #define CONTROL_H |
| 33 | |
| 34 | #include "core/math/transform_2d.h" |
| 35 | #include "core/object/gdvirtual.gen.inc" |
| 36 | #include "core/templates/rid.h" |
| 37 | #include "scene/main/canvas_item.h" |
| 38 | #include "scene/main/timer.h" |
| 39 | #include "scene/resources/theme.h" |
| 40 | |
| 41 | class Viewport; |
| 42 | class Label; |
| 43 | class Panel; |
| 44 | class ThemeOwner; |
| 45 | class ThemeContext; |
| 46 | |
| 47 | class Control : public CanvasItem { |
| 48 | GDCLASS(Control, CanvasItem); |
| 49 | |
| 50 | public: |
| 51 | enum Anchor { |
| 52 | ANCHOR_BEGIN = 0, |
| 53 | ANCHOR_END = 1 |
| 54 | }; |
| 55 | |
| 56 | enum GrowDirection { |
| 57 | GROW_DIRECTION_BEGIN, |
| 58 | GROW_DIRECTION_END, |
| 59 | GROW_DIRECTION_BOTH |
| 60 | }; |
| 61 | |
| 62 | enum FocusMode { |
| 63 | FOCUS_NONE, |
| 64 | FOCUS_CLICK, |
| 65 | FOCUS_ALL |
| 66 | }; |
| 67 | |
| 68 | enum SizeFlags { |
| 69 | SIZE_SHRINK_BEGIN = 0, |
| 70 | SIZE_FILL = 1, |
| 71 | SIZE_EXPAND = 2, |
| 72 | SIZE_SHRINK_CENTER = 4, |
| 73 | SIZE_SHRINK_END = 8, |
| 74 | |
| 75 | SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL, |
| 76 | }; |
| 77 | |
| 78 | enum MouseFilter { |
| 79 | MOUSE_FILTER_STOP, |
| 80 | MOUSE_FILTER_PASS, |
| 81 | MOUSE_FILTER_IGNORE |
| 82 | }; |
| 83 | |
| 84 | enum CursorShape { |
| 85 | CURSOR_ARROW, |
| 86 | CURSOR_IBEAM, |
| 87 | CURSOR_POINTING_HAND, |
| 88 | CURSOR_CROSS, |
| 89 | CURSOR_WAIT, |
| 90 | CURSOR_BUSY, |
| 91 | CURSOR_DRAG, |
| 92 | CURSOR_CAN_DROP, |
| 93 | CURSOR_FORBIDDEN, |
| 94 | CURSOR_VSIZE, |
| 95 | CURSOR_HSIZE, |
| 96 | CURSOR_BDIAGSIZE, |
| 97 | CURSOR_FDIAGSIZE, |
| 98 | CURSOR_MOVE, |
| 99 | CURSOR_VSPLIT, |
| 100 | CURSOR_HSPLIT, |
| 101 | CURSOR_HELP, |
| 102 | CURSOR_MAX |
| 103 | }; |
| 104 | |
| 105 | enum LayoutPreset { |
| 106 | PRESET_TOP_LEFT, |
| 107 | PRESET_TOP_RIGHT, |
| 108 | PRESET_BOTTOM_LEFT, |
| 109 | PRESET_BOTTOM_RIGHT, |
| 110 | PRESET_CENTER_LEFT, |
| 111 | PRESET_CENTER_TOP, |
| 112 | PRESET_CENTER_RIGHT, |
| 113 | PRESET_CENTER_BOTTOM, |
| 114 | PRESET_CENTER, |
| 115 | PRESET_LEFT_WIDE, |
| 116 | PRESET_TOP_WIDE, |
| 117 | PRESET_RIGHT_WIDE, |
| 118 | PRESET_BOTTOM_WIDE, |
| 119 | PRESET_VCENTER_WIDE, |
| 120 | PRESET_HCENTER_WIDE, |
| 121 | PRESET_FULL_RECT |
| 122 | }; |
| 123 | |
| 124 | enum LayoutPresetMode { |
| 125 | PRESET_MODE_MINSIZE, |
| 126 | PRESET_MODE_KEEP_WIDTH, |
| 127 | PRESET_MODE_KEEP_HEIGHT, |
| 128 | PRESET_MODE_KEEP_SIZE |
| 129 | }; |
| 130 | |
| 131 | enum LayoutMode { |
| 132 | LAYOUT_MODE_POSITION, |
| 133 | LAYOUT_MODE_ANCHORS, |
| 134 | LAYOUT_MODE_CONTAINER, |
| 135 | LAYOUT_MODE_UNCONTROLLED, |
| 136 | }; |
| 137 | |
| 138 | enum LayoutDirection { |
| 139 | LAYOUT_DIRECTION_INHERITED, |
| 140 | LAYOUT_DIRECTION_LOCALE, |
| 141 | LAYOUT_DIRECTION_LTR, |
| 142 | LAYOUT_DIRECTION_RTL |
| 143 | }; |
| 144 | |
| 145 | enum TextDirection { |
| 146 | TEXT_DIRECTION_AUTO = TextServer::DIRECTION_AUTO, |
| 147 | TEXT_DIRECTION_LTR = TextServer::DIRECTION_LTR, |
| 148 | TEXT_DIRECTION_RTL = TextServer::DIRECTION_RTL, |
| 149 | TEXT_DIRECTION_INHERITED = TextServer::DIRECTION_INHERITED, |
| 150 | }; |
| 151 | |
| 152 | private: |
| 153 | struct CComparator { |
| 154 | bool operator()(const Control *p_a, const Control *p_b) const { |
| 155 | if (p_a->get_canvas_layer() == p_b->get_canvas_layer()) { |
| 156 | return p_b->is_greater_than(p_a); |
| 157 | } |
| 158 | |
| 159 | return p_a->get_canvas_layer() < p_b->get_canvas_layer(); |
| 160 | } |
| 161 | }; |
| 162 | |
| 163 | // This Data struct is to avoid namespace pollution in derived classes. |
| 164 | struct Data { |
| 165 | bool initialized = false; |
| 166 | |
| 167 | // Global relations. |
| 168 | |
| 169 | List<Control *>::Element *RI = nullptr; |
| 170 | |
| 171 | Control *parent_control = nullptr; |
| 172 | Window *parent_window = nullptr; |
| 173 | CanvasItem *parent_canvas_item = nullptr; |
| 174 | Callable forward_drag; |
| 175 | Callable forward_can_drop; |
| 176 | Callable forward_drop; |
| 177 | |
| 178 | // Positioning and sizing. |
| 179 | |
| 180 | LayoutMode stored_layout_mode = LayoutMode::LAYOUT_MODE_POSITION; |
| 181 | bool stored_use_custom_anchors = false; |
| 182 | |
| 183 | real_t offset[4] = { 0.0, 0.0, 0.0, 0.0 }; |
| 184 | real_t anchor[4] = { ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN }; |
| 185 | FocusMode focus_mode = FOCUS_NONE; |
| 186 | GrowDirection h_grow = GROW_DIRECTION_END; |
| 187 | GrowDirection v_grow = GROW_DIRECTION_END; |
| 188 | |
| 189 | real_t rotation = 0.0; |
| 190 | Vector2 scale = Vector2(1, 1); |
| 191 | Vector2 pivot_offset; |
| 192 | |
| 193 | Point2 pos_cache; |
| 194 | Size2 size_cache; |
| 195 | Size2 minimum_size_cache; |
| 196 | bool minimum_size_valid = false; |
| 197 | |
| 198 | Size2 last_minimum_size; |
| 199 | bool updating_last_minimum_size = false; |
| 200 | bool block_minimum_size_adjust = false; |
| 201 | |
| 202 | bool size_warning = true; |
| 203 | |
| 204 | // Container sizing. |
| 205 | |
| 206 | BitField<SizeFlags> h_size_flags = SIZE_FILL; |
| 207 | BitField<SizeFlags> v_size_flags = SIZE_FILL; |
| 208 | real_t expand = 1.0; |
| 209 | Point2 custom_minimum_size; |
| 210 | |
| 211 | // Input events and rendering. |
| 212 | |
| 213 | MouseFilter mouse_filter = MOUSE_FILTER_STOP; |
| 214 | bool force_pass_scroll_events = true; |
| 215 | |
| 216 | bool clip_contents = false; |
| 217 | bool disable_visibility_clip = false; |
| 218 | |
| 219 | CursorShape default_cursor = CURSOR_ARROW; |
| 220 | |
| 221 | // Focus. |
| 222 | |
| 223 | NodePath focus_neighbor[4]; |
| 224 | NodePath focus_next; |
| 225 | NodePath focus_prev; |
| 226 | |
| 227 | ObjectID shortcut_context; |
| 228 | |
| 229 | // Theming. |
| 230 | |
| 231 | ThemeOwner *theme_owner = nullptr; |
| 232 | Ref<Theme> theme; |
| 233 | StringName theme_type_variation; |
| 234 | |
| 235 | bool bulk_theme_override = false; |
| 236 | Theme::ThemeIconMap theme_icon_override; |
| 237 | Theme::ThemeStyleMap theme_style_override; |
| 238 | Theme::ThemeFontMap theme_font_override; |
| 239 | Theme::ThemeFontSizeMap theme_font_size_override; |
| 240 | Theme::ThemeColorMap theme_color_override; |
| 241 | Theme::ThemeConstantMap theme_constant_override; |
| 242 | |
| 243 | mutable HashMap<StringName, Theme::ThemeIconMap> theme_icon_cache; |
| 244 | mutable HashMap<StringName, Theme::ThemeStyleMap> theme_style_cache; |
| 245 | mutable HashMap<StringName, Theme::ThemeFontMap> theme_font_cache; |
| 246 | mutable HashMap<StringName, Theme::ThemeFontSizeMap> theme_font_size_cache; |
| 247 | mutable HashMap<StringName, Theme::ThemeColorMap> theme_color_cache; |
| 248 | mutable HashMap<StringName, Theme::ThemeConstantMap> theme_constant_cache; |
| 249 | |
| 250 | // Internationalization. |
| 251 | |
| 252 | LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED; |
| 253 | bool is_rtl_dirty = true; |
| 254 | bool is_rtl = false; |
| 255 | |
| 256 | bool auto_translate = true; |
| 257 | bool localize_numeral_system = true; |
| 258 | |
| 259 | // Extra properties. |
| 260 | |
| 261 | String tooltip; |
| 262 | |
| 263 | } data; |
| 264 | |
| 265 | // Dynamic properties. |
| 266 | |
| 267 | static constexpr unsigned properties_managed_by_container_count = 12; |
| 268 | static String properties_managed_by_container[properties_managed_by_container_count]; |
| 269 | |
| 270 | // Global relations. |
| 271 | |
| 272 | friend class Viewport; |
| 273 | |
| 274 | // Positioning and sizing. |
| 275 | |
| 276 | void _update_canvas_item_transform(); |
| 277 | Transform2D _get_internal_transform() const; |
| 278 | |
| 279 | void _set_anchor(Side p_side, real_t p_anchor); |
| 280 | void _set_position(const Point2 &p_point); |
| 281 | void _set_global_position(const Point2 &p_point); |
| 282 | void _set_size(const Size2 &p_size); |
| 283 | |
| 284 | void _compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (&r_offsets)[4]); |
| 285 | void _compute_anchors(Rect2 p_rect, const real_t p_offsets[4], real_t (&r_anchors)[4]); |
| 286 | |
| 287 | void _set_layout_mode(LayoutMode p_mode); |
| 288 | void _update_layout_mode(); |
| 289 | LayoutMode _get_layout_mode() const; |
| 290 | LayoutMode _get_default_layout_mode() const; |
| 291 | void _set_anchors_layout_preset(int p_preset); |
| 292 | int _get_anchors_layout_preset() const; |
| 293 | |
| 294 | void _update_minimum_size_cache(); |
| 295 | void _update_minimum_size(); |
| 296 | void _size_changed(); |
| 297 | |
| 298 | void _top_level_changed() override {} // Controls don't need to do anything, only other CanvasItems. |
| 299 | void _top_level_changed_on_parent() override; |
| 300 | |
| 301 | void _clear_size_warning(); |
| 302 | |
| 303 | // Input events. |
| 304 | |
| 305 | void _call_gui_input(const Ref<InputEvent> &p_event); |
| 306 | |
| 307 | // Focus. |
| 308 | |
| 309 | void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, real_t p_min, real_t &r_closest_dist, Control **r_closest); |
| 310 | Control *_get_focus_neighbor(Side p_side, int p_count = 0); |
| 311 | |
| 312 | // Theming. |
| 313 | |
| 314 | void _theme_changed(); |
| 315 | void _notify_theme_override_changed(); |
| 316 | void _invalidate_theme_cache(); |
| 317 | |
| 318 | // Extra properties. |
| 319 | |
| 320 | String get_tooltip_text() const; |
| 321 | |
| 322 | protected: |
| 323 | // Dynamic properties. |
| 324 | |
| 325 | bool _set(const StringName &p_name, const Variant &p_value); |
| 326 | bool _get(const StringName &p_name, Variant &r_ret) const; |
| 327 | void _get_property_list(List<PropertyInfo> *p_list) const; |
| 328 | void _validate_property(PropertyInfo &p_property) const; |
| 329 | |
| 330 | bool _property_can_revert(const StringName &p_name) const; |
| 331 | bool _property_get_revert(const StringName &p_name, Variant &r_property) const; |
| 332 | |
| 333 | // Theming. |
| 334 | |
| 335 | virtual void _update_theme_item_cache(); |
| 336 | |
| 337 | // Internationalization. |
| 338 | |
| 339 | virtual TypedArray<Vector3i> structured_text_parser(TextServer::StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const; |
| 340 | |
| 341 | // Base object overrides. |
| 342 | |
| 343 | void _notification(int p_notification); |
| 344 | static void _bind_methods(); |
| 345 | |
| 346 | // Exposed virtual methods. |
| 347 | |
| 348 | GDVIRTUAL1RC(bool, _has_point, Vector2) |
| 349 | GDVIRTUAL2RC(TypedArray<Vector3i>, _structured_text_parser, Array, String) |
| 350 | GDVIRTUAL0RC(Vector2, _get_minimum_size) |
| 351 | GDVIRTUAL1RC(String, _get_tooltip, Vector2) |
| 352 | |
| 353 | GDVIRTUAL1R(Variant, _get_drag_data, Vector2) |
| 354 | GDVIRTUAL2RC(bool, _can_drop_data, Vector2, Variant) |
| 355 | GDVIRTUAL2(_drop_data, Vector2, Variant) |
| 356 | GDVIRTUAL1RC(Object *, _make_custom_tooltip, String) |
| 357 | |
| 358 | GDVIRTUAL1(_gui_input, Ref<InputEvent>) |
| 359 | |
| 360 | public: |
| 361 | enum { |
| 362 | NOTIFICATION_RESIZED = 40, |
| 363 | NOTIFICATION_MOUSE_ENTER = 41, |
| 364 | NOTIFICATION_MOUSE_EXIT = 42, |
| 365 | NOTIFICATION_FOCUS_ENTER = 43, |
| 366 | NOTIFICATION_FOCUS_EXIT = 44, |
| 367 | NOTIFICATION_THEME_CHANGED = 45, |
| 368 | NOTIFICATION_SCROLL_BEGIN = 47, |
| 369 | NOTIFICATION_SCROLL_END = 48, |
| 370 | NOTIFICATION_LAYOUT_DIRECTION_CHANGED = 49, |
| 371 | }; |
| 372 | |
| 373 | // Editor plugin interoperability. |
| 374 | |
| 375 | // TODO: Decouple controls from their editor plugin and get rid of this. |
| 376 | #ifdef TOOLS_ENABLED |
| 377 | virtual Dictionary _edit_get_state() const override; |
| 378 | virtual void _edit_set_state(const Dictionary &p_state) override; |
| 379 | |
| 380 | virtual void _edit_set_position(const Point2 &p_position) override; |
| 381 | virtual Point2 _edit_get_position() const override; |
| 382 | |
| 383 | virtual void _edit_set_scale(const Size2 &p_scale) override; |
| 384 | virtual Size2 _edit_get_scale() const override; |
| 385 | |
| 386 | virtual void _edit_set_rect(const Rect2 &p_edit_rect) override; |
| 387 | virtual Rect2 _edit_get_rect() const override; |
| 388 | virtual bool _edit_use_rect() const override; |
| 389 | |
| 390 | virtual void _edit_set_rotation(real_t p_rotation) override; |
| 391 | virtual real_t _edit_get_rotation() const override; |
| 392 | virtual bool _edit_use_rotation() const override; |
| 393 | |
| 394 | virtual void _edit_set_pivot(const Point2 &p_pivot) override; |
| 395 | virtual Point2 _edit_get_pivot() const override; |
| 396 | virtual bool _edit_use_pivot() const override; |
| 397 | |
| 398 | virtual Size2 _edit_get_minimum_size() const override; |
| 399 | #endif |
| 400 | virtual void reparent(Node *p_parent, bool p_keep_global_transform = true) override; |
| 401 | |
| 402 | // Editor integration. |
| 403 | |
| 404 | virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; |
| 405 | PackedStringArray get_configuration_warnings() const override; |
| 406 | |
| 407 | virtual bool is_text_field() const; |
| 408 | |
| 409 | // Global relations. |
| 410 | |
| 411 | bool is_top_level_control() const; |
| 412 | |
| 413 | Control *get_parent_control() const; |
| 414 | Window *get_parent_window() const; |
| 415 | Control *get_root_parent_control() const; |
| 416 | |
| 417 | Size2 get_parent_area_size() const; |
| 418 | Rect2 get_parent_anchorable_rect() const; |
| 419 | |
| 420 | // Positioning and sizing. |
| 421 | |
| 422 | virtual Transform2D get_transform() const override; |
| 423 | |
| 424 | void set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset = true, bool p_push_opposite_anchor = true); |
| 425 | real_t get_anchor(Side p_side) const; |
| 426 | void set_offset(Side p_side, real_t p_value); |
| 427 | real_t get_offset(Side p_side) const; |
| 428 | void set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos, bool p_push_opposite_anchor = true); |
| 429 | |
| 430 | // TODO: Rename to set_begin/end_offsets ? |
| 431 | void set_begin(const Point2 &p_point); |
| 432 | Point2 get_begin() const; |
| 433 | void set_end(const Point2 &p_point); |
| 434 | Point2 get_end() const; |
| 435 | |
| 436 | void set_h_grow_direction(GrowDirection p_direction); |
| 437 | GrowDirection get_h_grow_direction() const; |
| 438 | void set_v_grow_direction(GrowDirection p_direction); |
| 439 | GrowDirection get_v_grow_direction() const; |
| 440 | |
| 441 | void set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets = true); |
| 442 | void set_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); |
| 443 | void set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); |
| 444 | void set_grow_direction_preset(LayoutPreset p_preset); |
| 445 | |
| 446 | void set_position(const Point2 &p_point, bool p_keep_offsets = false); |
| 447 | void set_global_position(const Point2 &p_point, bool p_keep_offsets = false); |
| 448 | Point2 get_position() const; |
| 449 | Point2 get_global_position() const; |
| 450 | Point2 get_screen_position() const; |
| 451 | |
| 452 | void set_size(const Size2 &p_size, bool p_keep_offsets = false); |
| 453 | Size2 get_size() const; |
| 454 | void reset_size(); |
| 455 | |
| 456 | void set_rect(const Rect2 &p_rect); // Reset anchors to begin and set rect, for faster container children sorting. |
| 457 | Rect2 get_rect() const; |
| 458 | Rect2 get_global_rect() const; |
| 459 | Rect2 get_screen_rect() const; |
| 460 | Rect2 get_anchorable_rect() const override; |
| 461 | |
| 462 | void set_scale(const Vector2 &p_scale); |
| 463 | Vector2 get_scale() const; |
| 464 | void set_rotation(real_t p_radians); |
| 465 | void set_rotation_degrees(real_t p_degrees); |
| 466 | real_t get_rotation() const; |
| 467 | real_t get_rotation_degrees() const; |
| 468 | void set_pivot_offset(const Vector2 &p_pivot); |
| 469 | Vector2 get_pivot_offset() const; |
| 470 | |
| 471 | void update_minimum_size(); |
| 472 | |
| 473 | void set_block_minimum_size_adjust(bool p_block); |
| 474 | |
| 475 | virtual Size2 get_minimum_size() const; |
| 476 | virtual Size2 get_combined_minimum_size() const; |
| 477 | |
| 478 | void set_custom_minimum_size(const Size2 &p_custom); |
| 479 | Size2 get_custom_minimum_size() const; |
| 480 | |
| 481 | // Container sizing. |
| 482 | |
| 483 | void set_h_size_flags(BitField<SizeFlags> p_flags); |
| 484 | BitField<SizeFlags> get_h_size_flags() const; |
| 485 | void set_v_size_flags(BitField<SizeFlags> p_flags); |
| 486 | BitField<SizeFlags> get_v_size_flags() const; |
| 487 | void set_stretch_ratio(real_t p_ratio); |
| 488 | real_t get_stretch_ratio() const; |
| 489 | |
| 490 | // Input events. |
| 491 | |
| 492 | virtual void gui_input(const Ref<InputEvent> &p_event); |
| 493 | void accept_event(); |
| 494 | |
| 495 | virtual bool has_point(const Point2 &p_point) const; |
| 496 | |
| 497 | void set_mouse_filter(MouseFilter p_filter); |
| 498 | MouseFilter get_mouse_filter() const; |
| 499 | |
| 500 | void set_force_pass_scroll_events(bool p_force_pass_scroll_events); |
| 501 | bool is_force_pass_scroll_events() const; |
| 502 | |
| 503 | void warp_mouse(const Point2 &p_position); |
| 504 | |
| 505 | bool is_focus_owner_in_shortcut_context() const; |
| 506 | void set_shortcut_context(const Node *p_node); |
| 507 | Node *get_shortcut_context() const; |
| 508 | |
| 509 | // Drag and drop handling. |
| 510 | |
| 511 | virtual void set_drag_forwarding(const Callable &p_drag, const Callable &p_can_drop, const Callable &p_drop); |
| 512 | virtual Variant get_drag_data(const Point2 &p_point); |
| 513 | virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const; |
| 514 | virtual void drop_data(const Point2 &p_point, const Variant &p_data); |
| 515 | void set_drag_preview(Control *p_control); |
| 516 | void force_drag(const Variant &p_data, Control *p_control); |
| 517 | bool is_drag_successful() const; |
| 518 | |
| 519 | // Focus. |
| 520 | |
| 521 | void set_focus_mode(FocusMode p_focus_mode); |
| 522 | FocusMode get_focus_mode() const; |
| 523 | bool has_focus() const; |
| 524 | void grab_focus(); |
| 525 | void grab_click_focus(); |
| 526 | void release_focus(); |
| 527 | |
| 528 | Control *find_next_valid_focus() const; |
| 529 | Control *find_prev_valid_focus() const; |
| 530 | |
| 531 | void set_focus_neighbor(Side p_side, const NodePath &p_neighbor); |
| 532 | NodePath get_focus_neighbor(Side p_side) const; |
| 533 | |
| 534 | void set_focus_next(const NodePath &p_next); |
| 535 | NodePath get_focus_next() const; |
| 536 | void set_focus_previous(const NodePath &p_prev); |
| 537 | NodePath get_focus_previous() const; |
| 538 | |
| 539 | // Rendering. |
| 540 | |
| 541 | void set_default_cursor_shape(CursorShape p_shape); |
| 542 | CursorShape get_default_cursor_shape() const; |
| 543 | virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const; |
| 544 | |
| 545 | void set_clip_contents(bool p_clip); |
| 546 | bool is_clipping_contents(); |
| 547 | |
| 548 | void set_disable_visibility_clip(bool p_ignore); |
| 549 | bool is_visibility_clip_disabled() const; |
| 550 | |
| 551 | // Theming. |
| 552 | |
| 553 | void set_theme_owner_node(Node *p_node); |
| 554 | Node *get_theme_owner_node() const; |
| 555 | bool has_theme_owner_node() const; |
| 556 | |
| 557 | void set_theme_context(ThemeContext *p_context, bool p_propagate = true); |
| 558 | |
| 559 | void set_theme(const Ref<Theme> &p_theme); |
| 560 | Ref<Theme> get_theme() const; |
| 561 | |
| 562 | void set_theme_type_variation(const StringName &p_theme_type); |
| 563 | StringName get_theme_type_variation() const; |
| 564 | |
| 565 | void begin_bulk_theme_override(); |
| 566 | void end_bulk_theme_override(); |
| 567 | |
| 568 | void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon); |
| 569 | void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style); |
| 570 | void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font); |
| 571 | void add_theme_font_size_override(const StringName &p_name, int p_font_size); |
| 572 | void add_theme_color_override(const StringName &p_name, const Color &p_color); |
| 573 | void add_theme_constant_override(const StringName &p_name, int p_constant); |
| 574 | |
| 575 | void remove_theme_icon_override(const StringName &p_name); |
| 576 | void remove_theme_style_override(const StringName &p_name); |
| 577 | void remove_theme_font_override(const StringName &p_name); |
| 578 | void remove_theme_font_size_override(const StringName &p_name); |
| 579 | void remove_theme_color_override(const StringName &p_name); |
| 580 | void remove_theme_constant_override(const StringName &p_name); |
| 581 | |
| 582 | Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 583 | Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 584 | Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 585 | int get_theme_font_size(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 586 | Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 587 | int get_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 588 | Variant get_theme_item(Theme::DataType p_data_type, const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 589 | #ifdef TOOLS_ENABLED |
| 590 | Ref<Texture2D> get_editor_theme_icon(const StringName &p_name) const; |
| 591 | #endif |
| 592 | |
| 593 | bool has_theme_icon_override(const StringName &p_name) const; |
| 594 | bool has_theme_stylebox_override(const StringName &p_name) const; |
| 595 | bool has_theme_font_override(const StringName &p_name) const; |
| 596 | bool has_theme_font_size_override(const StringName &p_name) const; |
| 597 | bool has_theme_color_override(const StringName &p_name) const; |
| 598 | bool has_theme_constant_override(const StringName &p_name) const; |
| 599 | |
| 600 | bool has_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 601 | bool has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 602 | bool has_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 603 | bool has_theme_font_size(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 604 | bool has_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 605 | bool has_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const; |
| 606 | |
| 607 | float get_theme_default_base_scale() const; |
| 608 | Ref<Font> get_theme_default_font() const; |
| 609 | int get_theme_default_font_size() const; |
| 610 | |
| 611 | // Internationalization. |
| 612 | |
| 613 | void set_layout_direction(LayoutDirection p_direction); |
| 614 | LayoutDirection get_layout_direction() const; |
| 615 | virtual bool is_layout_rtl() const; |
| 616 | |
| 617 | void set_localize_numeral_system(bool p_enable); |
| 618 | bool is_localizing_numeral_system() const; |
| 619 | |
| 620 | void set_auto_translate(bool p_enable); |
| 621 | bool is_auto_translating() const; |
| 622 | _FORCE_INLINE_ String atr(const String p_string) const { |
| 623 | return is_auto_translating() ? tr(p_string) : p_string; |
| 624 | }; |
| 625 | |
| 626 | // Extra properties. |
| 627 | |
| 628 | void set_tooltip_text(const String &text); |
| 629 | virtual String get_tooltip(const Point2 &p_pos) const; |
| 630 | virtual Control *make_custom_tooltip(const String &p_text) const; |
| 631 | |
| 632 | Control(); |
| 633 | ~Control(); |
| 634 | }; |
| 635 | |
| 636 | VARIANT_ENUM_CAST(Control::FocusMode); |
| 637 | VARIANT_BITFIELD_CAST(Control::SizeFlags); |
| 638 | VARIANT_ENUM_CAST(Control::CursorShape); |
| 639 | VARIANT_ENUM_CAST(Control::LayoutPreset); |
| 640 | VARIANT_ENUM_CAST(Control::LayoutPresetMode); |
| 641 | VARIANT_ENUM_CAST(Control::MouseFilter); |
| 642 | VARIANT_ENUM_CAST(Control::GrowDirection); |
| 643 | VARIANT_ENUM_CAST(Control::Anchor); |
| 644 | VARIANT_ENUM_CAST(Control::LayoutMode); |
| 645 | VARIANT_ENUM_CAST(Control::LayoutDirection); |
| 646 | VARIANT_ENUM_CAST(Control::TextDirection); |
| 647 | |
| 648 | // G = get_drag_data_fw, C = can_drop_data_fw, D = drop_data_fw, U = underscore |
| 649 | #define SET_DRAG_FORWARDING_CD(from, to) from->set_drag_forwarding(Callable(), callable_mp(this, &to::can_drop_data_fw).bind(from), callable_mp(this, &to::drop_data_fw).bind(from)); |
| 650 | #define SET_DRAG_FORWARDING_CDU(from, to) from->set_drag_forwarding(Callable(), callable_mp(this, &to::_can_drop_data_fw).bind(from), callable_mp(this, &to::_drop_data_fw).bind(from)); |
| 651 | #define SET_DRAG_FORWARDING_GCD(from, to) from->set_drag_forwarding(callable_mp(this, &to::get_drag_data_fw).bind(from), callable_mp(this, &to::can_drop_data_fw).bind(from), callable_mp(this, &to::drop_data_fw).bind(from)); |
| 652 | #define SET_DRAG_FORWARDING_GCDU(from, to) from->set_drag_forwarding(callable_mp(this, &to::_get_drag_data_fw).bind(from), callable_mp(this, &to::_can_drop_data_fw).bind(from), callable_mp(this, &to::_drop_data_fw).bind(from)); |
| 653 | |
| 654 | #endif // CONTROL_H |
| 655 | |