Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/gui/graph_node.h
20852 views
1
/**************************************************************************/
2
/* graph_node.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
#pragma once
32
33
#include "scene/gui/graph_element.h"
34
35
class HBoxContainer;
36
37
class GraphNode : public GraphElement {
38
GDCLASS(GraphNode, GraphElement);
39
40
friend class GraphEdit;
41
42
struct Slot {
43
bool enable_left = false;
44
int type_left = 0;
45
Color color_left = Color(1, 1, 1, 1);
46
Ref<Texture2D> custom_port_icon_left;
47
Variant metadata_left;
48
49
bool enable_right = false;
50
int type_right = 0;
51
Color color_right = Color(1, 1, 1, 1);
52
Ref<Texture2D> custom_port_icon_right;
53
Variant metadata_right;
54
55
bool draw_stylebox = true;
56
};
57
58
struct PortCache {
59
Vector2 pos;
60
int slot_index;
61
int type = 0;
62
Color color;
63
};
64
65
struct _MinSizeCache {
66
int min_size = 0;
67
bool will_stretch = false;
68
int final_size = 0;
69
};
70
71
enum CustomAccessibilityAction {
72
ACTION_CONNECT_INPUT,
73
ACTION_CONNECT_OUTPUT,
74
ACTION_FOLLOW_INPUT,
75
ACTION_FOLLOW_OUTPUT,
76
};
77
void _accessibility_action_slot(const Variant &p_data);
78
79
HBoxContainer *titlebar_hbox = nullptr;
80
Label *title_label = nullptr;
81
82
String title;
83
84
Vector<PortCache> left_port_cache;
85
Vector<PortCache> right_port_cache;
86
87
HashMap<int, Slot> slot_table;
88
Vector<int> slot_y_cache;
89
90
Control::FocusMode slots_focus_mode = Control::FOCUS_ACCESSIBILITY;
91
int slot_count = 0;
92
int selected_slot = -1;
93
94
struct ThemeCache {
95
Ref<StyleBox> panel;
96
Ref<StyleBox> panel_selected;
97
Ref<StyleBox> panel_focus;
98
Ref<StyleBox> titlebar;
99
Ref<StyleBox> titlebar_selected;
100
Ref<StyleBox> slot;
101
Ref<StyleBox> slot_selected;
102
103
int separation = 0;
104
int port_h_offset = 0;
105
106
Ref<Texture2D> port;
107
Ref<Texture2D> resizer;
108
Color resizer_color;
109
} theme_cache;
110
111
bool port_pos_dirty = true;
112
113
bool ignore_invalid_connection_type = false;
114
115
void _port_pos_update();
116
117
protected:
118
void _notification(int p_what);
119
static void _bind_methods();
120
121
virtual void _resort() override;
122
123
virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color);
124
GDVIRTUAL4(_draw_port, int, Point2i, bool, const Color &);
125
126
bool _set(const StringName &p_name, const Variant &p_value);
127
bool _get(const StringName &p_name, Variant &r_ret) const;
128
void _get_property_list(List<PropertyInfo> *p_list) const;
129
130
public:
131
virtual String get_accessibility_container_name(const Node *p_node) const override;
132
virtual void gui_input(const Ref<InputEvent> &p_event) override;
133
134
void set_title(const String &p_title);
135
String get_title() const;
136
137
HBoxContainer *get_titlebar_hbox();
138
139
void set_slot(int p_slot_index, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture2D> &p_custom_left = Ref<Texture2D>(), const Ref<Texture2D> &p_custom_right = Ref<Texture2D>(), bool p_draw_stylebox = true);
140
void clear_slot(int p_slot_index);
141
void clear_all_slots();
142
143
bool is_slot_enabled_left(int p_slot_index) const;
144
void set_slot_enabled_left(int p_slot_index, bool p_enable);
145
146
void set_slot_type_left(int p_slot_index, int p_type);
147
int get_slot_type_left(int p_slot_index) const;
148
149
void set_slot_color_left(int p_slot_index, const Color &p_color);
150
Color get_slot_color_left(int p_slot_index) const;
151
152
void set_slot_custom_icon_left(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
153
Ref<Texture2D> get_slot_custom_icon_left(int p_slot_index) const;
154
155
void set_slot_metadata_left(int p_slot_index, const Variant &p_value);
156
Variant get_slot_metadata_left(int p_slot_index) const;
157
158
bool is_slot_enabled_right(int p_slot_index) const;
159
void set_slot_enabled_right(int p_slot_index, bool p_enable);
160
161
void set_slot_type_right(int p_slot_index, int p_type);
162
int get_slot_type_right(int p_slot_index) const;
163
164
void set_slot_color_right(int p_slot_index, const Color &p_color);
165
Color get_slot_color_right(int p_slot_index) const;
166
167
void set_slot_custom_icon_right(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
168
Ref<Texture2D> get_slot_custom_icon_right(int p_slot_index) const;
169
170
void set_slot_metadata_right(int p_slot_index, const Variant &p_value);
171
Variant get_slot_metadata_right(int p_slot_index) const;
172
173
bool is_slot_draw_stylebox(int p_slot_index) const;
174
void set_slot_draw_stylebox(int p_slot_index, bool p_enable);
175
176
void set_ignore_invalid_connection_type(bool p_ignore);
177
bool is_ignoring_valid_connection_type() const;
178
179
int get_input_port_count();
180
Vector2 get_input_port_position(int p_port_idx);
181
int get_input_port_type(int p_port_idx);
182
Color get_input_port_color(int p_port_idx);
183
int get_input_port_slot(int p_port_idx);
184
185
int get_output_port_count();
186
Vector2 get_output_port_position(int p_port_idx);
187
int get_output_port_type(int p_port_idx);
188
Color get_output_port_color(int p_port_idx);
189
int get_output_port_slot(int p_port_idx);
190
191
void set_slots_focus_mode(Control::FocusMode p_focus_mode);
192
Control::FocusMode get_slots_focus_mode() const;
193
194
virtual Size2 get_minimum_size() const override;
195
196
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
197
198
virtual Vector<int> get_allowed_size_flags_horizontal() const override;
199
virtual Vector<int> get_allowed_size_flags_vertical() const override;
200
201
GraphNode();
202
};
203
204