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#ifndef GRAPH_NODE_H
32#define GRAPH_NODE_H
33
34#include "scene/gui/graph_element.h"
35
36class HBoxContainer;
37
38class GraphNode : public GraphElement {
39 GDCLASS(GraphNode, GraphElement);
40
41 friend class GraphEdit;
42
43 struct Slot {
44 bool enable_left = false;
45 int type_left = 0;
46 Color color_left = Color(1, 1, 1, 1);
47 Ref<Texture2D> custom_port_icon_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
54 bool draw_stylebox = true;
55 };
56
57 struct PortCache {
58 Vector2 pos;
59 int slot_index;
60 int type = 0;
61 Color color;
62 };
63
64 struct _MinSizeCache {
65 int min_size;
66 bool will_stretch;
67 int final_size;
68 };
69
70 HBoxContainer *titlebar_hbox = nullptr;
71 Label *title_label = nullptr;
72
73 String title;
74
75 Vector<PortCache> left_port_cache;
76 Vector<PortCache> right_port_cache;
77
78 HashMap<int, Slot> slot_table;
79 Vector<int> slot_y_cache;
80
81 struct ThemeCache {
82 Ref<StyleBox> panel;
83 Ref<StyleBox> panel_selected;
84 Ref<StyleBox> titlebar;
85 Ref<StyleBox> titlebar_selected;
86 Ref<StyleBox> slot;
87
88 int separation = 0;
89 int port_h_offset = 0;
90
91 Ref<Texture2D> port;
92 Ref<Texture2D> resizer;
93 Color resizer_color;
94 } theme_cache;
95
96 bool port_pos_dirty = true;
97
98 void _port_pos_update();
99
100protected:
101 void _notification(int p_what);
102 static void _bind_methods();
103
104 virtual void _resort() override;
105
106 virtual void draw_port(int p_slot_index, Point2i p_pos, bool p_left, const Color &p_color);
107 GDVIRTUAL4(_draw_port, int, Point2i, bool, const Color &);
108
109 bool _set(const StringName &p_name, const Variant &p_value);
110 bool _get(const StringName &p_name, Variant &r_ret) const;
111 void _get_property_list(List<PropertyInfo> *p_list) const;
112
113public:
114 void set_title(const String &p_title);
115 String get_title() const;
116
117 HBoxContainer *get_titlebar_hbox();
118
119 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);
120 void clear_slot(int p_slot_index);
121 void clear_all_slots();
122
123 bool is_slot_enabled_left(int p_slot_index) const;
124 void set_slot_enabled_left(int p_slot_index, bool p_enable);
125
126 void set_slot_type_left(int p_slot_index, int p_type);
127 int get_slot_type_left(int p_slot_index) const;
128
129 void set_slot_color_left(int p_slot_index, const Color &p_color);
130 Color get_slot_color_left(int p_slot_index) const;
131
132 bool is_slot_enabled_right(int p_slot_index) const;
133 void set_slot_enabled_right(int p_slot_index, bool p_enable);
134
135 void set_slot_type_right(int p_slot_index, int p_type);
136 int get_slot_type_right(int p_slot_index) const;
137
138 void set_slot_color_right(int p_slot_index, const Color &p_color);
139 Color get_slot_color_right(int p_slot_index) const;
140
141 bool is_slot_draw_stylebox(int p_slot_index) const;
142 void set_slot_draw_stylebox(int p_slot_index, bool p_enable);
143
144 int get_input_port_count();
145 Vector2 get_input_port_position(int p_port_idx);
146 int get_input_port_type(int p_port_idx);
147 Color get_input_port_color(int p_port_idx);
148 int get_input_port_slot(int p_port_idx);
149
150 int get_output_port_count();
151 Vector2 get_output_port_position(int p_port_idx);
152 int get_output_port_type(int p_port_idx);
153 Color get_output_port_color(int p_port_idx);
154 int get_output_port_slot(int p_port_idx);
155
156 virtual Size2 get_minimum_size() const override;
157
158 virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
159
160 virtual Vector<int> get_allowed_size_flags_horizontal() const override;
161 virtual Vector<int> get_allowed_size_flags_vertical() const override;
162
163 GraphNode();
164};
165
166#endif // GRAPH_NODE_H
167