1 /** 2 A GraphNode is a container with potentially several input and output slots allowing connections between GraphNodes. Slots can have different, incompatible types. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.graphnode; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.container; 25 import godot.control; 26 import godot.canvasitem; 27 import godot.node; 28 import godot.inputevent; 29 import godot.texture; 30 /** 31 A GraphNode is a container with potentially several input and output slots allowing connections between GraphNodes. Slots can have different, incompatible types. 32 33 A GraphNode is a container. Each GraphNode can have several input and output slots, sometimes referred to as ports, allowing connections between GraphNodes. To add a slot to GraphNode, add any $(D Control)-derived child node to it. 34 After adding at least one child to GraphNode new sections will be automatically created in the Inspector called 'Slot'. When 'Slot' is expanded you will see list with index number for each slot. You can click on each of them to expand further. 35 In the Inspector you can enable (show) or disable (hide) slots. By default, all slots are disabled so you may not see any slots on your GraphNode initially. You can assign a type to each slot. Only slots of the same type will be able to connect to each other. You can also assign colors to slots. A tuple of input and output slots is defined for each GUI element included in the GraphNode. Input connections are on the left and output connections are on the right side of GraphNode. Only enabled slots are counted as connections. 36 */ 37 @GodotBaseClass struct GraphNode 38 { 39 package(godot) enum string _GODOT_internal_name = "GraphNode"; 40 public: 41 @nogc nothrow: 42 union { /** */ godot_object _godot_object; /** */ Container _GODOT_base; } 43 alias _GODOT_base this; 44 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 45 package(godot) __gshared bool _classBindingInitialized = false; 46 package(godot) static struct GDNativeClassBinding 47 { 48 __gshared: 49 @GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput; 50 @GodotName("clear_all_slots") GodotMethod!(void) clearAllSlots; 51 @GodotName("clear_slot") GodotMethod!(void, long) clearSlot; 52 @GodotName("get_connection_input_color") GodotMethod!(Color, long) getConnectionInputColor; 53 @GodotName("get_connection_input_count") GodotMethod!(long) getConnectionInputCount; 54 @GodotName("get_connection_input_position") GodotMethod!(Vector2, long) getConnectionInputPosition; 55 @GodotName("get_connection_input_type") GodotMethod!(long, long) getConnectionInputType; 56 @GodotName("get_connection_output_color") GodotMethod!(Color, long) getConnectionOutputColor; 57 @GodotName("get_connection_output_count") GodotMethod!(long) getConnectionOutputCount; 58 @GodotName("get_connection_output_position") GodotMethod!(Vector2, long) getConnectionOutputPosition; 59 @GodotName("get_connection_output_type") GodotMethod!(long, long) getConnectionOutputType; 60 @GodotName("get_offset") GodotMethod!(Vector2) getOffset; 61 @GodotName("get_overlay") GodotMethod!(GraphNode.Overlay) getOverlay; 62 @GodotName("get_slot_color_left") GodotMethod!(Color, long) getSlotColorLeft; 63 @GodotName("get_slot_color_right") GodotMethod!(Color, long) getSlotColorRight; 64 @GodotName("get_slot_type_left") GodotMethod!(long, long) getSlotTypeLeft; 65 @GodotName("get_slot_type_right") GodotMethod!(long, long) getSlotTypeRight; 66 @GodotName("get_title") GodotMethod!(String) getTitle; 67 @GodotName("is_close_button_visible") GodotMethod!(bool) isCloseButtonVisible; 68 @GodotName("is_comment") GodotMethod!(bool) isComment; 69 @GodotName("is_resizable") GodotMethod!(bool) isResizable; 70 @GodotName("is_selected") GodotMethod!(bool) isSelected; 71 @GodotName("is_slot_enabled_left") GodotMethod!(bool, long) isSlotEnabledLeft; 72 @GodotName("is_slot_enabled_right") GodotMethod!(bool, long) isSlotEnabledRight; 73 @GodotName("set_comment") GodotMethod!(void, bool) setComment; 74 @GodotName("set_offset") GodotMethod!(void, Vector2) setOffset; 75 @GodotName("set_overlay") GodotMethod!(void, long) setOverlay; 76 @GodotName("set_resizable") GodotMethod!(void, bool) setResizable; 77 @GodotName("set_selected") GodotMethod!(void, bool) setSelected; 78 @GodotName("set_show_close_button") GodotMethod!(void, bool) setShowCloseButton; 79 @GodotName("set_slot") GodotMethod!(void, long, bool, long, Color, bool, long, Color, Texture, Texture) setSlot; 80 @GodotName("set_title") GodotMethod!(void, String) setTitle; 81 } 82 /// 83 pragma(inline, true) bool opEquals(in GraphNode other) const 84 { return _godot_object.ptr is other._godot_object.ptr; } 85 /// 86 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 87 { _godot_object.ptr = n; return null; } 88 /// 89 pragma(inline, true) bool opEquals(typeof(null) n) const 90 { return _godot_object.ptr is n; } 91 /// 92 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 93 mixin baseCasts; 94 /// Construct a new instance of GraphNode. 95 /// Note: use `memnew!GraphNode` instead. 96 static GraphNode _new() 97 { 98 static godot_class_constructor constructor; 99 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("GraphNode"); 100 if(constructor is null) return typeof(this).init; 101 return cast(GraphNode)(constructor()); 102 } 103 @disable new(size_t s); 104 /// 105 enum Overlay : int 106 { 107 /** 108 No overlay is shown. 109 */ 110 overlayDisabled = 0, 111 /** 112 Show overlay set in the `breakpoint` theme property. 113 */ 114 overlayBreakpoint = 1, 115 /** 116 Show overlay set in the `position` theme property. 117 */ 118 overlayPosition = 2, 119 } 120 /// 121 enum Constants : int 122 { 123 overlayDisabled = 0, 124 overlayBreakpoint = 1, 125 overlayPosition = 2, 126 } 127 /** 128 129 */ 130 void _guiInput(InputEvent arg0) 131 { 132 Array _GODOT_args = Array.make(); 133 _GODOT_args.append(arg0); 134 String _GODOT_method_name = String("_gui_input"); 135 this.callv(_GODOT_method_name, _GODOT_args); 136 } 137 /** 138 Disables all input and output slots of the GraphNode. 139 */ 140 void clearAllSlots() 141 { 142 checkClassBinding!(typeof(this))(); 143 ptrcall!(void)(GDNativeClassBinding.clearAllSlots, _godot_object); 144 } 145 /** 146 Disables input and output slot whose index is `idx`. 147 */ 148 void clearSlot(in long idx) 149 { 150 checkClassBinding!(typeof(this))(); 151 ptrcall!(void)(GDNativeClassBinding.clearSlot, _godot_object, idx); 152 } 153 /** 154 Returns the color of the input connection `idx`. 155 */ 156 Color getConnectionInputColor(in long idx) 157 { 158 checkClassBinding!(typeof(this))(); 159 return ptrcall!(Color)(GDNativeClassBinding.getConnectionInputColor, _godot_object, idx); 160 } 161 /** 162 Returns the number of enabled input slots (connections) to the GraphNode. 163 */ 164 long getConnectionInputCount() 165 { 166 checkClassBinding!(typeof(this))(); 167 return ptrcall!(long)(GDNativeClassBinding.getConnectionInputCount, _godot_object); 168 } 169 /** 170 Returns the position of the input connection `idx`. 171 */ 172 Vector2 getConnectionInputPosition(in long idx) 173 { 174 checkClassBinding!(typeof(this))(); 175 return ptrcall!(Vector2)(GDNativeClassBinding.getConnectionInputPosition, _godot_object, idx); 176 } 177 /** 178 Returns the type of the input connection `idx`. 179 */ 180 long getConnectionInputType(in long idx) 181 { 182 checkClassBinding!(typeof(this))(); 183 return ptrcall!(long)(GDNativeClassBinding.getConnectionInputType, _godot_object, idx); 184 } 185 /** 186 Returns the color of the output connection `idx`. 187 */ 188 Color getConnectionOutputColor(in long idx) 189 { 190 checkClassBinding!(typeof(this))(); 191 return ptrcall!(Color)(GDNativeClassBinding.getConnectionOutputColor, _godot_object, idx); 192 } 193 /** 194 Returns the number of enabled output slots (connections) of the GraphNode. 195 */ 196 long getConnectionOutputCount() 197 { 198 checkClassBinding!(typeof(this))(); 199 return ptrcall!(long)(GDNativeClassBinding.getConnectionOutputCount, _godot_object); 200 } 201 /** 202 Returns the position of the output connection `idx`. 203 */ 204 Vector2 getConnectionOutputPosition(in long idx) 205 { 206 checkClassBinding!(typeof(this))(); 207 return ptrcall!(Vector2)(GDNativeClassBinding.getConnectionOutputPosition, _godot_object, idx); 208 } 209 /** 210 Returns the type of the output connection `idx`. 211 */ 212 long getConnectionOutputType(in long idx) 213 { 214 checkClassBinding!(typeof(this))(); 215 return ptrcall!(long)(GDNativeClassBinding.getConnectionOutputType, _godot_object, idx); 216 } 217 /** 218 219 */ 220 Vector2 getOffset() const 221 { 222 checkClassBinding!(typeof(this))(); 223 return ptrcall!(Vector2)(GDNativeClassBinding.getOffset, _godot_object); 224 } 225 /** 226 227 */ 228 GraphNode.Overlay getOverlay() const 229 { 230 checkClassBinding!(typeof(this))(); 231 return ptrcall!(GraphNode.Overlay)(GDNativeClassBinding.getOverlay, _godot_object); 232 } 233 /** 234 Returns the color set to `idx` left (input) slot. 235 */ 236 Color getSlotColorLeft(in long idx) const 237 { 238 checkClassBinding!(typeof(this))(); 239 return ptrcall!(Color)(GDNativeClassBinding.getSlotColorLeft, _godot_object, idx); 240 } 241 /** 242 Returns the color set to `idx` right (output) slot. 243 */ 244 Color getSlotColorRight(in long idx) const 245 { 246 checkClassBinding!(typeof(this))(); 247 return ptrcall!(Color)(GDNativeClassBinding.getSlotColorRight, _godot_object, idx); 248 } 249 /** 250 Returns the (integer) type of left (input) `idx` slot. 251 */ 252 long getSlotTypeLeft(in long idx) const 253 { 254 checkClassBinding!(typeof(this))(); 255 return ptrcall!(long)(GDNativeClassBinding.getSlotTypeLeft, _godot_object, idx); 256 } 257 /** 258 Returns the (integer) type of right (output) `idx` slot. 259 */ 260 long getSlotTypeRight(in long idx) const 261 { 262 checkClassBinding!(typeof(this))(); 263 return ptrcall!(long)(GDNativeClassBinding.getSlotTypeRight, _godot_object, idx); 264 } 265 /** 266 267 */ 268 String getTitle() const 269 { 270 checkClassBinding!(typeof(this))(); 271 return ptrcall!(String)(GDNativeClassBinding.getTitle, _godot_object); 272 } 273 /** 274 275 */ 276 bool isCloseButtonVisible() const 277 { 278 checkClassBinding!(typeof(this))(); 279 return ptrcall!(bool)(GDNativeClassBinding.isCloseButtonVisible, _godot_object); 280 } 281 /** 282 283 */ 284 bool isComment() const 285 { 286 checkClassBinding!(typeof(this))(); 287 return ptrcall!(bool)(GDNativeClassBinding.isComment, _godot_object); 288 } 289 /** 290 291 */ 292 bool isResizable() const 293 { 294 checkClassBinding!(typeof(this))(); 295 return ptrcall!(bool)(GDNativeClassBinding.isResizable, _godot_object); 296 } 297 /** 298 299 */ 300 bool isSelected() 301 { 302 checkClassBinding!(typeof(this))(); 303 return ptrcall!(bool)(GDNativeClassBinding.isSelected, _godot_object); 304 } 305 /** 306 Returns `true` if left (input) slot `idx` is enabled, `false` otherwise. 307 */ 308 bool isSlotEnabledLeft(in long idx) const 309 { 310 checkClassBinding!(typeof(this))(); 311 return ptrcall!(bool)(GDNativeClassBinding.isSlotEnabledLeft, _godot_object, idx); 312 } 313 /** 314 Returns `true` if right (output) slot `idx` is enabled, `false` otherwise. 315 */ 316 bool isSlotEnabledRight(in long idx) const 317 { 318 checkClassBinding!(typeof(this))(); 319 return ptrcall!(bool)(GDNativeClassBinding.isSlotEnabledRight, _godot_object, idx); 320 } 321 /** 322 323 */ 324 void setComment(in bool comment) 325 { 326 checkClassBinding!(typeof(this))(); 327 ptrcall!(void)(GDNativeClassBinding.setComment, _godot_object, comment); 328 } 329 /** 330 331 */ 332 void setOffset(in Vector2 offset) 333 { 334 checkClassBinding!(typeof(this))(); 335 ptrcall!(void)(GDNativeClassBinding.setOffset, _godot_object, offset); 336 } 337 /** 338 339 */ 340 void setOverlay(in long overlay) 341 { 342 checkClassBinding!(typeof(this))(); 343 ptrcall!(void)(GDNativeClassBinding.setOverlay, _godot_object, overlay); 344 } 345 /** 346 347 */ 348 void setResizable(in bool resizable) 349 { 350 checkClassBinding!(typeof(this))(); 351 ptrcall!(void)(GDNativeClassBinding.setResizable, _godot_object, resizable); 352 } 353 /** 354 355 */ 356 void setSelected(in bool selected) 357 { 358 checkClassBinding!(typeof(this))(); 359 ptrcall!(void)(GDNativeClassBinding.setSelected, _godot_object, selected); 360 } 361 /** 362 363 */ 364 void setShowCloseButton(in bool show) 365 { 366 checkClassBinding!(typeof(this))(); 367 ptrcall!(void)(GDNativeClassBinding.setShowCloseButton, _godot_object, show); 368 } 369 /** 370 Sets properties of the slot with ID `idx`. 371 If `enable_left`/`right`, a port will appear and the slot will be able to be connected from this side. 372 `type_left`/`right` is an arbitrary type of the port. Only ports with the same type values can be connected. 373 `color_left`/`right` is the tint of the port's icon on this side. 374 `custom_left`/`right` is a custom texture for this side's port. 375 $(B Note:) This method only sets properties of the slot. To create the slot, add a $(D Control)-derived child to the GraphNode. 376 */ 377 void setSlot(in long idx, in bool enable_left, in long type_left, in Color color_left, in bool enable_right, in long type_right, in Color color_right, Texture custom_left = Texture.init, Texture custom_right = Texture.init) 378 { 379 checkClassBinding!(typeof(this))(); 380 ptrcall!(void)(GDNativeClassBinding.setSlot, _godot_object, idx, enable_left, type_left, color_left, enable_right, type_right, color_right, custom_left, custom_right); 381 } 382 /** 383 384 */ 385 void setTitle(in String title) 386 { 387 checkClassBinding!(typeof(this))(); 388 ptrcall!(void)(GDNativeClassBinding.setTitle, _godot_object, title); 389 } 390 /** 391 If `true`, the GraphNode is a comment node. 392 */ 393 @property bool comment() 394 { 395 return isComment(); 396 } 397 /// ditto 398 @property void comment(bool v) 399 { 400 setComment(v); 401 } 402 /** 403 The offset of the GraphNode, relative to the scroll offset of the $(D GraphEdit). 404 $(B Note:) You cannot use position directly, as $(D GraphEdit) is a $(D Container). 405 */ 406 @property Vector2 offset() 407 { 408 return getOffset(); 409 } 410 /// ditto 411 @property void offset(Vector2 v) 412 { 413 setOffset(v); 414 } 415 /** 416 Sets the overlay shown above the GraphNode. See $(D overlay). 417 */ 418 @property GraphNode.Overlay overlay() 419 { 420 return getOverlay(); 421 } 422 /// ditto 423 @property void overlay(long v) 424 { 425 setOverlay(v); 426 } 427 /** 428 If `true`, the user can resize the GraphNode. 429 $(B Note:) Dragging the handle will only emit the $(D resizeRequest) signal, the GraphNode needs to be resized manually. 430 */ 431 @property bool resizable() 432 { 433 return isResizable(); 434 } 435 /// ditto 436 @property void resizable(bool v) 437 { 438 setResizable(v); 439 } 440 /** 441 If `true`, the GraphNode is selected. 442 */ 443 @property bool selected() 444 { 445 return isSelected(); 446 } 447 /// ditto 448 @property void selected(bool v) 449 { 450 setSelected(v); 451 } 452 /** 453 If `true`, the close button will be visible. 454 $(B Note:) Pressing it will only emit the $(D closeRequest) signal, the GraphNode needs to be removed manually. 455 */ 456 @property bool showClose() 457 { 458 return isCloseButtonVisible(); 459 } 460 /// ditto 461 @property void showClose(bool v) 462 { 463 setShowCloseButton(v); 464 } 465 /** 466 The text displayed in the GraphNode's title bar. 467 */ 468 @property String title() 469 { 470 return getTitle(); 471 } 472 /// ditto 473 @property void title(String v) 474 { 475 setTitle(v); 476 } 477 }