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