2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* control.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef CONTROL_H
|
|
|
|
#define CONTROL_H
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/math/transform_2d.h"
|
2021-06-19 17:58:49 +02:00
|
|
|
#include "core/object/gdvirtual.gen.inc"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/templates/rid.h"
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "scene/main/canvas_item.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/main/timer.h"
|
|
|
|
#include "scene/resources/theme.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class Viewport;
|
|
|
|
class Label;
|
|
|
|
class Panel;
|
2022-09-02 16:03:23 +02:00
|
|
|
class ThemeOwner;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class Control : public CanvasItem {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(Control, CanvasItem);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
public:
|
2017-08-16 00:48:38 +02:00
|
|
|
enum Anchor {
|
|
|
|
ANCHOR_BEGIN = 0,
|
|
|
|
ANCHOR_END = 1
|
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-07-06 18:26:39 +02:00
|
|
|
enum GrowDirection {
|
|
|
|
GROW_DIRECTION_BEGIN,
|
2018-02-12 04:58:39 +01:00
|
|
|
GROW_DIRECTION_END,
|
|
|
|
GROW_DIRECTION_BOTH
|
2017-07-06 18:26:39 +02:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
enum FocusMode {
|
|
|
|
FOCUS_NONE,
|
|
|
|
FOCUS_CLICK,
|
|
|
|
FOCUS_ALL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SizeFlags {
|
2021-11-08 21:53:41 +01:00
|
|
|
SIZE_SHRINK_BEGIN = 0,
|
2017-03-05 16:44:50 +01:00
|
|
|
SIZE_FILL = 1,
|
|
|
|
SIZE_EXPAND = 2,
|
2021-11-08 21:53:41 +01:00
|
|
|
SIZE_SHRINK_CENTER = 4,
|
|
|
|
SIZE_SHRINK_END = 8,
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-11-08 21:53:41 +01:00
|
|
|
SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-01-08 23:54:19 +01:00
|
|
|
enum MouseFilter {
|
|
|
|
MOUSE_FILTER_STOP,
|
|
|
|
MOUSE_FILTER_PASS,
|
|
|
|
MOUSE_FILTER_IGNORE
|
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
enum CursorShape {
|
|
|
|
CURSOR_ARROW,
|
|
|
|
CURSOR_IBEAM,
|
|
|
|
CURSOR_POINTING_HAND,
|
|
|
|
CURSOR_CROSS,
|
|
|
|
CURSOR_WAIT,
|
|
|
|
CURSOR_BUSY,
|
|
|
|
CURSOR_DRAG,
|
|
|
|
CURSOR_CAN_DROP,
|
|
|
|
CURSOR_FORBIDDEN,
|
|
|
|
CURSOR_VSIZE,
|
|
|
|
CURSOR_HSIZE,
|
|
|
|
CURSOR_BDIAGSIZE,
|
|
|
|
CURSOR_FDIAGSIZE,
|
|
|
|
CURSOR_MOVE,
|
|
|
|
CURSOR_VSPLIT,
|
|
|
|
CURSOR_HSPLIT,
|
|
|
|
CURSOR_HELP,
|
|
|
|
CURSOR_MAX
|
|
|
|
};
|
|
|
|
|
2017-08-11 18:16:28 +02:00
|
|
|
enum LayoutPreset {
|
|
|
|
PRESET_TOP_LEFT,
|
|
|
|
PRESET_TOP_RIGHT,
|
|
|
|
PRESET_BOTTOM_LEFT,
|
|
|
|
PRESET_BOTTOM_RIGHT,
|
|
|
|
PRESET_CENTER_LEFT,
|
|
|
|
PRESET_CENTER_TOP,
|
|
|
|
PRESET_CENTER_RIGHT,
|
|
|
|
PRESET_CENTER_BOTTOM,
|
|
|
|
PRESET_CENTER,
|
|
|
|
PRESET_LEFT_WIDE,
|
|
|
|
PRESET_TOP_WIDE,
|
|
|
|
PRESET_RIGHT_WIDE,
|
|
|
|
PRESET_BOTTOM_WIDE,
|
|
|
|
PRESET_VCENTER_WIDE,
|
|
|
|
PRESET_HCENTER_WIDE,
|
2022-03-19 01:02:57 +01:00
|
|
|
PRESET_FULL_RECT
|
2017-08-11 18:16:28 +02:00
|
|
|
};
|
|
|
|
|
2017-09-19 22:39:19 +02:00
|
|
|
enum LayoutPresetMode {
|
|
|
|
PRESET_MODE_MINSIZE,
|
|
|
|
PRESET_MODE_KEEP_WIDTH,
|
|
|
|
PRESET_MODE_KEEP_HEIGHT,
|
|
|
|
PRESET_MODE_KEEP_SIZE
|
|
|
|
};
|
|
|
|
|
2021-11-08 21:53:41 +01:00
|
|
|
enum LayoutMode {
|
|
|
|
LAYOUT_MODE_POSITION,
|
|
|
|
LAYOUT_MODE_ANCHORS,
|
|
|
|
LAYOUT_MODE_CONTAINER,
|
|
|
|
LAYOUT_MODE_UNCONTROLLED,
|
|
|
|
};
|
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
enum LayoutDirection {
|
|
|
|
LAYOUT_DIRECTION_INHERITED,
|
|
|
|
LAYOUT_DIRECTION_LOCALE,
|
|
|
|
LAYOUT_DIRECTION_LTR,
|
|
|
|
LAYOUT_DIRECTION_RTL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum TextDirection {
|
|
|
|
TEXT_DIRECTION_AUTO = TextServer::DIRECTION_AUTO,
|
|
|
|
TEXT_DIRECTION_LTR = TextServer::DIRECTION_LTR,
|
|
|
|
TEXT_DIRECTION_RTL = TextServer::DIRECTION_RTL,
|
2023-01-18 08:33:35 +01:00
|
|
|
TEXT_DIRECTION_INHERITED = TextServer::DIRECTION_INHERITED,
|
2020-09-03 13:22:16 +02:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
private:
|
|
|
|
struct CComparator {
|
2017-03-05 16:44:50 +01:00
|
|
|
bool operator()(const Control *p_a, const Control *p_b) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_a->get_canvas_layer() == p_b->get_canvas_layer()) {
|
2016-01-24 14:57:42 +01:00
|
|
|
return p_b->is_greater_than(p_a);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-06-26 15:08:25 +02:00
|
|
|
|
|
|
|
return p_a->get_canvas_layer() < p_b->get_canvas_layer();
|
2016-01-24 14:57:42 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2022-10-13 15:30:23 +02:00
|
|
|
// This Data struct is to avoid namespace pollution in derived classes.
|
2014-02-10 02:10:30 +01:00
|
|
|
struct Data {
|
2023-04-03 18:01:10 +02:00
|
|
|
bool initialized = false;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Global relations.
|
2018-05-15 22:12:35 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
List<Control *>::Element *RI = nullptr;
|
|
|
|
|
2023-01-03 17:21:26 +01:00
|
|
|
Control *parent_control = nullptr;
|
2022-07-22 17:06:03 +02:00
|
|
|
Window *parent_window = nullptr;
|
|
|
|
CanvasItem *parent_canvas_item = nullptr;
|
2023-01-09 19:24:36 +01:00
|
|
|
Callable forward_drag;
|
|
|
|
Callable forward_can_drop;
|
|
|
|
Callable forward_drop;
|
2022-07-22 17:06:03 +02:00
|
|
|
|
|
|
|
// Positioning and sizing.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-08-19 17:36:15 +02:00
|
|
|
LayoutMode stored_layout_mode = LayoutMode::LAYOUT_MODE_POSITION;
|
|
|
|
bool stored_use_custom_anchors = false;
|
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t offset[4] = { 0.0, 0.0, 0.0, 0.0 };
|
|
|
|
real_t anchor[4] = { ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN };
|
2020-12-11 15:54:03 +01:00
|
|
|
FocusMode focus_mode = FOCUS_NONE;
|
|
|
|
GrowDirection h_grow = GROW_DIRECTION_END;
|
|
|
|
GrowDirection v_grow = GROW_DIRECTION_END;
|
2015-12-12 17:54:26 +01:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t rotation = 0.0;
|
2020-12-11 15:54:03 +01:00
|
|
|
Vector2 scale = Vector2(1, 1);
|
2017-07-06 22:42:44 +02:00
|
|
|
Vector2 pivot_offset;
|
2022-07-22 17:06:03 +02:00
|
|
|
|
|
|
|
Point2 pos_cache;
|
|
|
|
Size2 size_cache;
|
|
|
|
Size2 minimum_size_cache;
|
|
|
|
bool minimum_size_valid = false;
|
|
|
|
|
|
|
|
Size2 last_minimum_size;
|
|
|
|
bool updating_last_minimum_size = false;
|
|
|
|
bool block_minimum_size_adjust = false;
|
|
|
|
|
2020-09-30 12:00:21 +02:00
|
|
|
bool size_warning = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Container sizing.
|
|
|
|
|
2023-01-07 20:37:21 +01:00
|
|
|
BitField<SizeFlags> h_size_flags = SIZE_FILL;
|
|
|
|
BitField<SizeFlags> v_size_flags = SIZE_FILL;
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t expand = 1.0;
|
2022-09-23 01:53:24 +02:00
|
|
|
Point2 custom_minimum_size;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Input events and rendering.
|
|
|
|
|
2020-12-11 15:54:03 +01:00
|
|
|
MouseFilter mouse_filter = MOUSE_FILTER_STOP;
|
2022-05-16 15:10:30 +02:00
|
|
|
bool force_pass_scroll_events = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-12-11 15:54:03 +01:00
|
|
|
bool clip_contents = false;
|
|
|
|
bool disable_visibility_clip = false;
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2020-12-11 15:54:03 +01:00
|
|
|
CursorShape default_cursor = CURSOR_ARROW;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Focus.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-12-15 23:42:21 +01:00
|
|
|
NodePath focus_neighbor[4];
|
2017-11-16 10:45:52 +01:00
|
|
|
NodePath focus_next;
|
|
|
|
NodePath focus_prev;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-09-24 16:32:53 +02:00
|
|
|
ObjectID shortcut_context;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Theming.
|
|
|
|
|
2022-09-02 16:03:23 +02:00
|
|
|
ThemeOwner *theme_owner = nullptr;
|
2022-07-22 17:06:03 +02:00
|
|
|
Ref<Theme> theme;
|
|
|
|
StringName theme_type_variation;
|
|
|
|
|
2021-08-12 19:35:42 +02:00
|
|
|
bool bulk_theme_override = false;
|
2022-11-29 21:01:45 +01:00
|
|
|
Theme::ThemeIconMap theme_icon_override;
|
|
|
|
Theme::ThemeStyleMap theme_style_override;
|
|
|
|
Theme::ThemeFontMap theme_font_override;
|
|
|
|
Theme::ThemeFontSizeMap theme_font_size_override;
|
|
|
|
Theme::ThemeColorMap theme_color_override;
|
|
|
|
Theme::ThemeConstantMap theme_constant_override;
|
2016-06-17 21:00:27 +02:00
|
|
|
|
2022-08-12 13:36:06 +02:00
|
|
|
mutable HashMap<StringName, Theme::ThemeIconMap> theme_icon_cache;
|
|
|
|
mutable HashMap<StringName, Theme::ThemeStyleMap> theme_style_cache;
|
|
|
|
mutable HashMap<StringName, Theme::ThemeFontMap> theme_font_cache;
|
|
|
|
mutable HashMap<StringName, Theme::ThemeFontSizeMap> theme_font_size_cache;
|
|
|
|
mutable HashMap<StringName, Theme::ThemeColorMap> theme_color_cache;
|
|
|
|
mutable HashMap<StringName, Theme::ThemeConstantMap> theme_constant_cache;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Internationalization.
|
|
|
|
|
|
|
|
LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED;
|
|
|
|
bool is_rtl_dirty = true;
|
|
|
|
bool is_rtl = false;
|
|
|
|
|
|
|
|
bool auto_translate = true;
|
2022-11-17 13:54:45 +01:00
|
|
|
bool localize_numeral_system = true;
|
2022-07-22 17:06:03 +02:00
|
|
|
|
|
|
|
// Extra properties.
|
|
|
|
|
|
|
|
String tooltip;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} data;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Dynamic properties.
|
|
|
|
|
2021-11-08 21:53:41 +01:00
|
|
|
static constexpr unsigned properties_managed_by_container_count = 12;
|
2021-09-05 22:01:36 +02:00
|
|
|
static String properties_managed_by_container[properties_managed_by_container_count];
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Global relations.
|
|
|
|
|
|
|
|
friend class Viewport;
|
|
|
|
|
|
|
|
// Positioning and sizing.
|
|
|
|
|
|
|
|
void _update_canvas_item_transform();
|
|
|
|
Transform2D _get_internal_transform() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void _set_anchor(Side p_side, real_t p_anchor);
|
2019-03-31 18:53:24 +02:00
|
|
|
void _set_position(const Point2 &p_point);
|
|
|
|
void _set_global_position(const Point2 &p_point);
|
|
|
|
void _set_size(const Size2 &p_size);
|
2016-03-09 17:59:35 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void _compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (&r_offsets)[4]);
|
|
|
|
void _compute_anchors(Rect2 p_rect, const real_t p_offsets[4], real_t (&r_anchors)[4]);
|
|
|
|
|
2021-11-08 21:53:41 +01:00
|
|
|
void _set_layout_mode(LayoutMode p_mode);
|
2023-01-10 21:07:57 +01:00
|
|
|
void _update_layout_mode();
|
2021-11-08 21:53:41 +01:00
|
|
|
LayoutMode _get_layout_mode() const;
|
2022-08-19 17:36:15 +02:00
|
|
|
LayoutMode _get_default_layout_mode() const;
|
2021-11-08 21:53:41 +01:00
|
|
|
void _set_anchors_layout_preset(int p_preset);
|
|
|
|
int _get_anchors_layout_preset() const;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void _update_minimum_size_cache();
|
2014-02-10 02:10:30 +01:00
|
|
|
void _update_minimum_size();
|
2022-07-22 17:06:03 +02:00
|
|
|
void _size_changed();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-02-02 17:20:31 +01:00
|
|
|
void _top_level_changed() override {} // Controls don't need to do anything, only other CanvasItems.
|
|
|
|
void _top_level_changed_on_parent() override;
|
2022-10-16 19:41:42 +02:00
|
|
|
|
2020-09-30 12:00:21 +02:00
|
|
|
void _clear_size_warning();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Input events.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void _call_gui_input(const Ref<InputEvent> &p_event);
|
2016-06-17 21:00:27 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Focus.
|
2016-06-17 21:00:27 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
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);
|
|
|
|
Control *_get_focus_neighbor(Side p_side, int p_count = 0);
|
2017-07-06 22:42:44 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Theming.
|
2016-01-17 02:41:10 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void _theme_changed();
|
2022-07-08 21:29:36 +02:00
|
|
|
void _notify_theme_override_changed();
|
2022-08-12 13:36:06 +02:00
|
|
|
void _invalidate_theme_cache();
|
2021-08-22 17:37:22 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Extra properties.
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-08-25 12:42:17 +02:00
|
|
|
String get_tooltip_text() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
protected:
|
|
|
|
// Dynamic properties.
|
2020-09-03 13:22:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2022-08-12 22:57:11 +02:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2021-11-08 21:53:41 +01:00
|
|
|
|
2022-08-19 17:36:15 +02:00
|
|
|
bool _property_can_revert(const StringName &p_name) const;
|
|
|
|
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
|
|
|
|
|
2022-08-31 14:02:40 +02:00
|
|
|
// Theming.
|
|
|
|
|
|
|
|
virtual void _update_theme_item_cache();
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Internationalization.
|
|
|
|
|
2023-01-18 08:33:35 +01:00
|
|
|
virtual TypedArray<Vector3i> structured_text_parser(TextServer::StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const;
|
2022-07-22 17:06:03 +02:00
|
|
|
|
|
|
|
// Base object overrides.
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _notification(int p_notification);
|
2016-03-09 00:00:52 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Exposed virtual methods.
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-08-22 17:37:22 +02:00
|
|
|
GDVIRTUAL1RC(bool, _has_point, Vector2)
|
2023-01-18 08:33:35 +01:00
|
|
|
GDVIRTUAL2RC(TypedArray<Vector3i>, _structured_text_parser, Array, String)
|
2021-08-22 17:37:22 +02:00
|
|
|
GDVIRTUAL0RC(Vector2, _get_minimum_size)
|
2023-02-23 14:36:10 +01:00
|
|
|
GDVIRTUAL1RC(String, _get_tooltip, Vector2)
|
2021-08-22 17:37:22 +02:00
|
|
|
|
2023-05-23 22:43:15 +02:00
|
|
|
GDVIRTUAL1R(Variant, _get_drag_data, Vector2)
|
2021-08-22 17:37:22 +02:00
|
|
|
GDVIRTUAL2RC(bool, _can_drop_data, Vector2, Variant)
|
|
|
|
GDVIRTUAL2(_drop_data, Vector2, Variant)
|
|
|
|
GDVIRTUAL1RC(Object *, _make_custom_tooltip, String)
|
|
|
|
|
|
|
|
GDVIRTUAL1(_gui_input, Ref<InputEvent>)
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
|
|
|
enum {
|
2017-03-05 16:44:50 +01:00
|
|
|
NOTIFICATION_RESIZED = 40,
|
|
|
|
NOTIFICATION_MOUSE_ENTER = 41,
|
|
|
|
NOTIFICATION_MOUSE_EXIT = 42,
|
|
|
|
NOTIFICATION_FOCUS_ENTER = 43,
|
|
|
|
NOTIFICATION_FOCUS_EXIT = 44,
|
|
|
|
NOTIFICATION_THEME_CHANGED = 45,
|
2018-02-27 16:37:20 +01:00
|
|
|
NOTIFICATION_SCROLL_BEGIN = 47,
|
|
|
|
NOTIFICATION_SCROLL_END = 48,
|
2020-09-03 13:22:16 +02:00
|
|
|
NOTIFICATION_LAYOUT_DIRECTION_CHANGED = 49,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Editor plugin interoperability.
|
|
|
|
|
|
|
|
// TODO: Decouple controls from their editor plugin and get rid of this.
|
2019-10-21 23:37:07 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Dictionary _edit_get_state() const override;
|
|
|
|
virtual void _edit_set_state(const Dictionary &p_state) override;
|
2017-11-15 23:03:25 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _edit_set_position(const Point2 &p_position) override;
|
|
|
|
virtual Point2 _edit_get_position() const override;
|
2017-11-15 23:03:25 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _edit_set_scale(const Size2 &p_scale) override;
|
|
|
|
virtual Size2 _edit_get_scale() const override;
|
2018-03-08 21:35:41 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _edit_set_rect(const Rect2 &p_edit_rect) override;
|
|
|
|
virtual Rect2 _edit_get_rect() const override;
|
|
|
|
virtual bool _edit_use_rect() const override;
|
2017-11-15 23:03:25 +01:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
virtual void _edit_set_rotation(real_t p_rotation) override;
|
|
|
|
virtual real_t _edit_get_rotation() const override;
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual bool _edit_use_rotation() const override;
|
2017-11-15 23:03:25 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _edit_set_pivot(const Point2 &p_pivot) override;
|
|
|
|
virtual Point2 _edit_get_pivot() const override;
|
|
|
|
virtual bool _edit_use_pivot() const override;
|
2017-11-15 23:03:25 +01:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Size2 _edit_get_minimum_size() const override;
|
2019-10-21 23:37:07 +02:00
|
|
|
#endif
|
2020-02-17 18:29:14 +01:00
|
|
|
virtual void reparent(Node *p_parent, bool p_keep_global_transform = true) override;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Editor integration.
|
2021-08-22 17:37:22 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
|
2022-09-19 17:43:15 +02:00
|
|
|
PackedStringArray get_configuration_warnings() const override;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
virtual bool is_text_field() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Global relations.
|
|
|
|
|
|
|
|
bool is_top_level_control() const;
|
2015-12-29 00:36:48 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Control *get_parent_control() const;
|
2021-07-19 19:25:15 +02:00
|
|
|
Window *get_parent_window() const;
|
2022-07-22 17:06:03 +02:00
|
|
|
Control *get_root_parent_control() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
Size2 get_parent_area_size() const;
|
|
|
|
Rect2 get_parent_anchorable_rect() const;
|
2021-05-27 19:31:33 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Positioning and sizing.
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
virtual Transform2D get_transform() const override;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-01-30 05:10:32 +01:00
|
|
|
void set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset = true, bool p_push_opposite_anchor = true);
|
|
|
|
real_t get_anchor(Side p_side) const;
|
|
|
|
void set_offset(Side p_side, real_t p_value);
|
|
|
|
real_t get_offset(Side p_side) const;
|
|
|
|
void set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos, bool p_push_opposite_anchor = true);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// TODO: Rename to set_begin/end_offsets ?
|
|
|
|
void set_begin(const Point2 &p_point);
|
2014-02-10 02:10:30 +01:00
|
|
|
Point2 get_begin() const;
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_end(const Point2 &p_point);
|
2014-02-10 02:10:30 +01:00
|
|
|
Point2 get_end() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_h_grow_direction(GrowDirection p_direction);
|
|
|
|
GrowDirection get_h_grow_direction() const;
|
|
|
|
void set_v_grow_direction(GrowDirection p_direction);
|
|
|
|
GrowDirection get_v_grow_direction() const;
|
|
|
|
|
|
|
|
void set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets = true);
|
|
|
|
void set_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0);
|
|
|
|
void set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0);
|
|
|
|
void set_grow_direction_preset(LayoutPreset p_preset);
|
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
void set_position(const Point2 &p_point, bool p_keep_offsets = false);
|
|
|
|
void set_global_position(const Point2 &p_point, bool p_keep_offsets = false);
|
2017-03-29 17:29:38 +02:00
|
|
|
Point2 get_position() const;
|
|
|
|
Point2 get_global_position() const;
|
2020-03-12 13:37:40 +01:00
|
|
|
Point2 get_screen_position() const;
|
2017-09-19 22:39:19 +02:00
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
void set_size(const Size2 &p_size, bool p_keep_offsets = false);
|
2014-02-10 02:10:30 +01:00
|
|
|
Size2 get_size() const;
|
2021-11-20 09:04:57 +01:00
|
|
|
void reset_size();
|
2017-09-19 22:39:19 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_rect(const Rect2 &p_rect); // Reset anchors to begin and set rect, for faster container children sorting.
|
2014-02-10 02:10:30 +01:00
|
|
|
Rect2 get_rect() const;
|
|
|
|
Rect2 get_global_rect() const;
|
2020-03-12 13:37:40 +01:00
|
|
|
Rect2 get_screen_rect() const;
|
2020-07-10 12:34:39 +02:00
|
|
|
Rect2 get_anchorable_rect() const override;
|
2015-12-12 17:54:26 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_scale(const Vector2 &p_scale);
|
|
|
|
Vector2 get_scale() const;
|
2021-01-30 05:10:32 +01:00
|
|
|
void set_rotation(real_t p_radians);
|
2022-12-18 16:58:19 +01:00
|
|
|
void set_rotation_degrees(real_t p_degrees);
|
2021-01-30 05:10:32 +01:00
|
|
|
real_t get_rotation() const;
|
2022-12-18 16:58:19 +01:00
|
|
|
real_t get_rotation_degrees() const;
|
2017-07-06 22:42:44 +02:00
|
|
|
void set_pivot_offset(const Vector2 &p_pivot);
|
|
|
|
Vector2 get_pivot_offset() const;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void update_minimum_size();
|
2015-12-12 17:54:26 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_block_minimum_size_adjust(bool p_block);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
virtual Size2 get_minimum_size() const;
|
|
|
|
virtual Size2 get_combined_minimum_size() const;
|
|
|
|
|
2022-09-23 01:53:24 +02:00
|
|
|
void set_custom_minimum_size(const Size2 &p_custom);
|
|
|
|
Size2 get_custom_minimum_size() const;
|
2022-07-22 17:06:03 +02:00
|
|
|
|
|
|
|
// Container sizing.
|
2021-03-30 19:16:33 +02:00
|
|
|
|
2023-01-07 20:37:21 +01:00
|
|
|
void set_h_size_flags(BitField<SizeFlags> p_flags);
|
|
|
|
BitField<SizeFlags> get_h_size_flags() const;
|
|
|
|
void set_v_size_flags(BitField<SizeFlags> p_flags);
|
|
|
|
BitField<SizeFlags> get_v_size_flags() const;
|
2021-01-30 05:10:32 +01:00
|
|
|
void set_stretch_ratio(real_t p_ratio);
|
|
|
|
real_t get_stretch_ratio() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Input events.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
virtual void gui_input(const Ref<InputEvent> &p_event);
|
|
|
|
void accept_event();
|
|
|
|
|
|
|
|
virtual bool has_point(const Point2 &p_point) const;
|
|
|
|
|
|
|
|
void set_mouse_filter(MouseFilter p_filter);
|
|
|
|
MouseFilter get_mouse_filter() const;
|
|
|
|
|
|
|
|
void set_force_pass_scroll_events(bool p_force_pass_scroll_events);
|
|
|
|
bool is_force_pass_scroll_events() const;
|
|
|
|
|
|
|
|
void warp_mouse(const Point2 &p_position);
|
|
|
|
|
2022-09-24 16:32:53 +02:00
|
|
|
bool is_focus_owner_in_shortcut_context() const;
|
|
|
|
void set_shortcut_context(const Node *p_node);
|
|
|
|
Node *get_shortcut_context() const;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Drag and drop handling.
|
|
|
|
|
2023-01-09 19:24:36 +01:00
|
|
|
virtual void set_drag_forwarding(const Callable &p_drag, const Callable &p_can_drop, const Callable &p_drop);
|
2022-07-22 17:06:03 +02:00
|
|
|
virtual Variant get_drag_data(const Point2 &p_point);
|
|
|
|
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
|
|
|
|
virtual void drop_data(const Point2 &p_point, const Variant &p_data);
|
|
|
|
void set_drag_preview(Control *p_control);
|
|
|
|
void force_drag(const Variant &p_data, Control *p_control);
|
|
|
|
bool is_drag_successful() const;
|
|
|
|
|
|
|
|
// Focus.
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_focus_mode(FocusMode p_focus_mode);
|
|
|
|
FocusMode get_focus_mode() const;
|
|
|
|
bool has_focus() const;
|
|
|
|
void grab_focus();
|
2022-07-22 17:06:03 +02:00
|
|
|
void grab_click_focus();
|
2014-02-10 02:10:30 +01:00
|
|
|
void release_focus();
|
|
|
|
|
|
|
|
Control *find_next_valid_focus() const;
|
|
|
|
Control *find_prev_valid_focus() const;
|
|
|
|
|
2020-12-22 17:24:29 +01:00
|
|
|
void set_focus_neighbor(Side p_side, const NodePath &p_neighbor);
|
|
|
|
NodePath get_focus_neighbor(Side p_side) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-16 10:45:52 +01:00
|
|
|
void set_focus_next(const NodePath &p_next);
|
|
|
|
NodePath get_focus_next() const;
|
|
|
|
void set_focus_previous(const NodePath &p_prev);
|
|
|
|
NodePath get_focus_previous() const;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Rendering.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_default_cursor_shape(CursorShape p_shape);
|
|
|
|
CursorShape get_default_cursor_shape() const;
|
|
|
|
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
|
|
|
|
|
|
|
|
void set_clip_contents(bool p_clip);
|
|
|
|
bool is_clipping_contents();
|
2022-05-16 15:10:30 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_disable_visibility_clip(bool p_ignore);
|
|
|
|
bool is_visibility_clip_disabled() const;
|
|
|
|
|
|
|
|
// Theming.
|
|
|
|
|
2022-09-02 16:03:23 +02:00
|
|
|
void set_theme_owner_node(Node *p_node);
|
|
|
|
Node *get_theme_owner_node() const;
|
|
|
|
bool has_theme_owner_node() const;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_theme(const Ref<Theme> &p_theme);
|
|
|
|
Ref<Theme> get_theme() const;
|
|
|
|
|
|
|
|
void set_theme_type_variation(const StringName &p_theme_type);
|
|
|
|
StringName get_theme_type_variation() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-08-12 19:35:42 +02:00
|
|
|
void begin_bulk_theme_override();
|
|
|
|
void end_bulk_theme_override();
|
|
|
|
|
2020-03-12 13:37:40 +01:00
|
|
|
void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon);
|
|
|
|
void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style);
|
|
|
|
void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font);
|
2020-09-03 13:22:16 +02:00
|
|
|
void add_theme_font_size_override(const StringName &p_name, int p_font_size);
|
2020-03-12 13:37:40 +01:00
|
|
|
void add_theme_color_override(const StringName &p_name, const Color &p_color);
|
|
|
|
void add_theme_constant_override(const StringName &p_name, int p_constant);
|
|
|
|
|
2021-03-22 02:43:01 +01:00
|
|
|
void remove_theme_icon_override(const StringName &p_name);
|
|
|
|
void remove_theme_style_override(const StringName &p_name);
|
|
|
|
void remove_theme_font_override(const StringName &p_name);
|
|
|
|
void remove_theme_font_size_override(const StringName &p_name);
|
|
|
|
void remove_theme_color_override(const StringName &p_name);
|
|
|
|
void remove_theme_constant_override(const StringName &p_name);
|
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
int get_theme_font_size(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
int get_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
2020-03-12 13:37:40 +01:00
|
|
|
|
|
|
|
bool has_theme_icon_override(const StringName &p_name) const;
|
|
|
|
bool has_theme_stylebox_override(const StringName &p_name) const;
|
|
|
|
bool has_theme_font_override(const StringName &p_name) const;
|
2020-09-03 13:22:16 +02:00
|
|
|
bool has_theme_font_size_override(const StringName &p_name) const;
|
2020-03-12 13:37:40 +01:00
|
|
|
bool has_theme_color_override(const StringName &p_name) const;
|
|
|
|
bool has_theme_constant_override(const StringName &p_name) const;
|
|
|
|
|
2021-03-30 19:16:33 +02:00
|
|
|
bool has_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
bool has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
bool has_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
bool has_theme_font_size(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
bool has_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
|
|
|
bool has_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-10-02 22:06:14 +02:00
|
|
|
float get_theme_default_base_scale() const;
|
|
|
|
Ref<Font> get_theme_default_font() const;
|
|
|
|
int get_theme_default_font_size() const;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Internationalization.
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_layout_direction(LayoutDirection p_direction);
|
|
|
|
LayoutDirection get_layout_direction() const;
|
|
|
|
virtual bool is_layout_rtl() const;
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2022-11-17 13:54:45 +01:00
|
|
|
void set_localize_numeral_system(bool p_enable);
|
|
|
|
bool is_localizing_numeral_system() const;
|
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
void set_auto_translate(bool p_enable);
|
|
|
|
bool is_auto_translating() const;
|
|
|
|
_FORCE_INLINE_ String atr(const String p_string) const {
|
|
|
|
return is_auto_translating() ? tr(p_string) : p_string;
|
|
|
|
};
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2022-07-22 17:06:03 +02:00
|
|
|
// Extra properties.
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2022-08-25 12:42:17 +02:00
|
|
|
void set_tooltip_text(const String &text);
|
2022-07-22 17:06:03 +02:00
|
|
|
virtual String get_tooltip(const Point2 &p_pos) const;
|
|
|
|
virtual Control *make_custom_tooltip(const String &p_text) const;
|
2016-09-11 16:48:31 +02:00
|
|
|
|
2022-09-02 16:03:23 +02:00
|
|
|
Control();
|
2022-08-24 17:45:14 +02:00
|
|
|
~Control();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(Control::FocusMode);
|
2023-01-07 20:37:21 +01:00
|
|
|
VARIANT_BITFIELD_CAST(Control::SizeFlags);
|
2014-02-10 02:10:30 +01:00
|
|
|
VARIANT_ENUM_CAST(Control::CursorShape);
|
2017-08-11 18:16:28 +02:00
|
|
|
VARIANT_ENUM_CAST(Control::LayoutPreset);
|
2017-09-19 22:39:19 +02:00
|
|
|
VARIANT_ENUM_CAST(Control::LayoutPresetMode);
|
2017-01-08 23:54:19 +01:00
|
|
|
VARIANT_ENUM_CAST(Control::MouseFilter);
|
2017-07-06 18:26:39 +02:00
|
|
|
VARIANT_ENUM_CAST(Control::GrowDirection);
|
2017-08-16 00:48:38 +02:00
|
|
|
VARIANT_ENUM_CAST(Control::Anchor);
|
2021-11-08 21:53:41 +01:00
|
|
|
VARIANT_ENUM_CAST(Control::LayoutMode);
|
2020-09-03 13:22:16 +02:00
|
|
|
VARIANT_ENUM_CAST(Control::LayoutDirection);
|
|
|
|
VARIANT_ENUM_CAST(Control::TextDirection);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-01-14 03:37:19 +01:00
|
|
|
// G = get_drag_data_fw, C = can_drop_data_fw, D = drop_data_fw, U = underscore
|
|
|
|
#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));
|
|
|
|
#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));
|
|
|
|
#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));
|
|
|
|
#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));
|
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#endif // CONTROL_H
|