control.h 26 KB

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