1 /** 2 GraphEdit is an area capable of showing various GraphNodes. It manages connection events between them. 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.graphedit; 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.control; 25 import godot.canvasitem; 26 import godot.node; 27 import godot.inputevent; 28 import godot.hboxcontainer; 29 /** 30 GraphEdit is an area capable of showing various GraphNodes. It manages connection events between them. 31 32 GraphEdit manages the showing of GraphNodes it contains, as well as connections and disconnections between them. Signals are sent for each of these two events. Disconnection between GraphNode slots is disabled by default. 33 It is greatly advised to enable low-processor usage mode (see $(D OS.lowProcessorUsageMode)) when using GraphEdits. 34 */ 35 @GodotBaseClass struct GraphEdit 36 { 37 package(godot) enum string _GODOT_internal_name = "GraphEdit"; 38 public: 39 @nogc nothrow: 40 union { /** */ godot_object _godot_object; /** */ Control _GODOT_base; } 41 alias _GODOT_base this; 42 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 43 package(godot) __gshared bool _classBindingInitialized = false; 44 package(godot) static struct GDNativeClassBinding 45 { 46 __gshared: 47 @GodotName("_connections_layer_draw") GodotMethod!(void) _connectionsLayerDraw; 48 @GodotName("_graph_node_moved") GodotMethod!(void, Node) _graphNodeMoved; 49 @GodotName("_graph_node_raised") GodotMethod!(void, Node) _graphNodeRaised; 50 @GodotName("_graph_node_slot_updated") GodotMethod!(void, long, Node) _graphNodeSlotUpdated; 51 @GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput; 52 @GodotName("_minimap_draw") GodotMethod!(void) _minimapDraw; 53 @GodotName("_minimap_toggled") GodotMethod!(void) _minimapToggled; 54 @GodotName("_scroll_moved") GodotMethod!(void, double) _scrollMoved; 55 @GodotName("_snap_toggled") GodotMethod!(void) _snapToggled; 56 @GodotName("_snap_value_changed") GodotMethod!(void, double) _snapValueChanged; 57 @GodotName("_top_layer_draw") GodotMethod!(void) _topLayerDraw; 58 @GodotName("_top_layer_input") GodotMethod!(void, InputEvent) _topLayerInput; 59 @GodotName("_update_scroll_offset") GodotMethod!(void) _updateScrollOffset; 60 @GodotName("_zoom_minus") GodotMethod!(void) _zoomMinus; 61 @GodotName("_zoom_plus") GodotMethod!(void) _zoomPlus; 62 @GodotName("_zoom_reset") GodotMethod!(void) _zoomReset; 63 @GodotName("add_valid_connection_type") GodotMethod!(void, long, long) addValidConnectionType; 64 @GodotName("add_valid_left_disconnect_type") GodotMethod!(void, long) addValidLeftDisconnectType; 65 @GodotName("add_valid_right_disconnect_type") GodotMethod!(void, long) addValidRightDisconnectType; 66 @GodotName("clear_connections") GodotMethod!(void) clearConnections; 67 @GodotName("connect_node") GodotMethod!(GodotError, String, long, String, long) connectNode; 68 @GodotName("disconnect_node") GodotMethod!(void, String, long, String, long) disconnectNode; 69 @GodotName("get_connection_list") GodotMethod!(Array) getConnectionList; 70 @GodotName("get_minimap_opacity") GodotMethod!(double) getMinimapOpacity; 71 @GodotName("get_minimap_size") GodotMethod!(Vector2) getMinimapSize; 72 @GodotName("get_scroll_ofs") GodotMethod!(Vector2) getScrollOfs; 73 @GodotName("get_snap") GodotMethod!(long) getSnap; 74 @GodotName("get_zoom") GodotMethod!(double) getZoom; 75 @GodotName("get_zoom_hbox") GodotMethod!(HBoxContainer) getZoomHbox; 76 @GodotName("is_minimap_enabled") GodotMethod!(bool) isMinimapEnabled; 77 @GodotName("is_node_connected") GodotMethod!(bool, String, long, String, long) isNodeConnected; 78 @GodotName("is_right_disconnects_enabled") GodotMethod!(bool) isRightDisconnectsEnabled; 79 @GodotName("is_using_snap") GodotMethod!(bool) isUsingSnap; 80 @GodotName("is_valid_connection_type") GodotMethod!(bool, long, long) isValidConnectionType; 81 @GodotName("remove_valid_connection_type") GodotMethod!(void, long, long) removeValidConnectionType; 82 @GodotName("remove_valid_left_disconnect_type") GodotMethod!(void, long) removeValidLeftDisconnectType; 83 @GodotName("remove_valid_right_disconnect_type") GodotMethod!(void, long) removeValidRightDisconnectType; 84 @GodotName("set_connection_activity") GodotMethod!(void, String, long, String, long, double) setConnectionActivity; 85 @GodotName("set_minimap_enabled") GodotMethod!(void, bool) setMinimapEnabled; 86 @GodotName("set_minimap_opacity") GodotMethod!(void, double) setMinimapOpacity; 87 @GodotName("set_minimap_size") GodotMethod!(void, Vector2) setMinimapSize; 88 @GodotName("set_right_disconnects") GodotMethod!(void, bool) setRightDisconnects; 89 @GodotName("set_scroll_ofs") GodotMethod!(void, Vector2) setScrollOfs; 90 @GodotName("set_selected") GodotMethod!(void, Node) setSelected; 91 @GodotName("set_snap") GodotMethod!(void, long) setSnap; 92 @GodotName("set_use_snap") GodotMethod!(void, bool) setUseSnap; 93 @GodotName("set_zoom") GodotMethod!(void, double) setZoom; 94 } 95 /// 96 pragma(inline, true) bool opEquals(in GraphEdit other) const 97 { return _godot_object.ptr is other._godot_object.ptr; } 98 /// 99 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 100 { _godot_object.ptr = n; return null; } 101 /// 102 pragma(inline, true) bool opEquals(typeof(null) n) const 103 { return _godot_object.ptr is n; } 104 /// 105 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 106 mixin baseCasts; 107 /// Construct a new instance of GraphEdit. 108 /// Note: use `memnew!GraphEdit` instead. 109 static GraphEdit _new() 110 { 111 static godot_class_constructor constructor; 112 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("GraphEdit"); 113 if(constructor is null) return typeof(this).init; 114 return cast(GraphEdit)(constructor()); 115 } 116 @disable new(size_t s); 117 /** 118 119 */ 120 void _connectionsLayerDraw() 121 { 122 Array _GODOT_args = Array.make(); 123 String _GODOT_method_name = String("_connections_layer_draw"); 124 this.callv(_GODOT_method_name, _GODOT_args); 125 } 126 /** 127 128 */ 129 void _graphNodeMoved(Node arg0) 130 { 131 Array _GODOT_args = Array.make(); 132 _GODOT_args.append(arg0); 133 String _GODOT_method_name = String("_graph_node_moved"); 134 this.callv(_GODOT_method_name, _GODOT_args); 135 } 136 /** 137 138 */ 139 void _graphNodeRaised(Node arg0) 140 { 141 Array _GODOT_args = Array.make(); 142 _GODOT_args.append(arg0); 143 String _GODOT_method_name = String("_graph_node_raised"); 144 this.callv(_GODOT_method_name, _GODOT_args); 145 } 146 /** 147 148 */ 149 void _graphNodeSlotUpdated(in long arg0, Node arg1) 150 { 151 Array _GODOT_args = Array.make(); 152 _GODOT_args.append(arg0); 153 _GODOT_args.append(arg1); 154 String _GODOT_method_name = String("_graph_node_slot_updated"); 155 this.callv(_GODOT_method_name, _GODOT_args); 156 } 157 /** 158 159 */ 160 void _guiInput(InputEvent arg0) 161 { 162 Array _GODOT_args = Array.make(); 163 _GODOT_args.append(arg0); 164 String _GODOT_method_name = String("_gui_input"); 165 this.callv(_GODOT_method_name, _GODOT_args); 166 } 167 /** 168 169 */ 170 void _minimapDraw() 171 { 172 Array _GODOT_args = Array.make(); 173 String _GODOT_method_name = String("_minimap_draw"); 174 this.callv(_GODOT_method_name, _GODOT_args); 175 } 176 /** 177 178 */ 179 void _minimapToggled() 180 { 181 Array _GODOT_args = Array.make(); 182 String _GODOT_method_name = String("_minimap_toggled"); 183 this.callv(_GODOT_method_name, _GODOT_args); 184 } 185 /** 186 187 */ 188 void _scrollMoved(in double arg0) 189 { 190 Array _GODOT_args = Array.make(); 191 _GODOT_args.append(arg0); 192 String _GODOT_method_name = String("_scroll_moved"); 193 this.callv(_GODOT_method_name, _GODOT_args); 194 } 195 /** 196 197 */ 198 void _snapToggled() 199 { 200 Array _GODOT_args = Array.make(); 201 String _GODOT_method_name = String("_snap_toggled"); 202 this.callv(_GODOT_method_name, _GODOT_args); 203 } 204 /** 205 206 */ 207 void _snapValueChanged(in double arg0) 208 { 209 Array _GODOT_args = Array.make(); 210 _GODOT_args.append(arg0); 211 String _GODOT_method_name = String("_snap_value_changed"); 212 this.callv(_GODOT_method_name, _GODOT_args); 213 } 214 /** 215 216 */ 217 void _topLayerDraw() 218 { 219 Array _GODOT_args = Array.make(); 220 String _GODOT_method_name = String("_top_layer_draw"); 221 this.callv(_GODOT_method_name, _GODOT_args); 222 } 223 /** 224 225 */ 226 void _topLayerInput(InputEvent arg0) 227 { 228 Array _GODOT_args = Array.make(); 229 _GODOT_args.append(arg0); 230 String _GODOT_method_name = String("_top_layer_input"); 231 this.callv(_GODOT_method_name, _GODOT_args); 232 } 233 /** 234 235 */ 236 void _updateScrollOffset() 237 { 238 Array _GODOT_args = Array.make(); 239 String _GODOT_method_name = String("_update_scroll_offset"); 240 this.callv(_GODOT_method_name, _GODOT_args); 241 } 242 /** 243 244 */ 245 void _zoomMinus() 246 { 247 Array _GODOT_args = Array.make(); 248 String _GODOT_method_name = String("_zoom_minus"); 249 this.callv(_GODOT_method_name, _GODOT_args); 250 } 251 /** 252 253 */ 254 void _zoomPlus() 255 { 256 Array _GODOT_args = Array.make(); 257 String _GODOT_method_name = String("_zoom_plus"); 258 this.callv(_GODOT_method_name, _GODOT_args); 259 } 260 /** 261 262 */ 263 void _zoomReset() 264 { 265 Array _GODOT_args = Array.make(); 266 String _GODOT_method_name = String("_zoom_reset"); 267 this.callv(_GODOT_method_name, _GODOT_args); 268 } 269 /** 270 Makes possible the connection between two different slot types. The type is defined with the $(D GraphNode.setSlot) method. 271 */ 272 void addValidConnectionType(in long from_type, in long to_type) 273 { 274 checkClassBinding!(typeof(this))(); 275 ptrcall!(void)(GDNativeClassBinding.addValidConnectionType, _godot_object, from_type, to_type); 276 } 277 /** 278 Makes possible to disconnect nodes when dragging from the slot at the left if it has the specified type. 279 */ 280 void addValidLeftDisconnectType(in long type) 281 { 282 checkClassBinding!(typeof(this))(); 283 ptrcall!(void)(GDNativeClassBinding.addValidLeftDisconnectType, _godot_object, type); 284 } 285 /** 286 Makes possible to disconnect nodes when dragging from the slot at the right if it has the specified type. 287 */ 288 void addValidRightDisconnectType(in long type) 289 { 290 checkClassBinding!(typeof(this))(); 291 ptrcall!(void)(GDNativeClassBinding.addValidRightDisconnectType, _godot_object, type); 292 } 293 /** 294 Removes all connections between nodes. 295 */ 296 void clearConnections() 297 { 298 checkClassBinding!(typeof(this))(); 299 ptrcall!(void)(GDNativeClassBinding.clearConnections, _godot_object); 300 } 301 /** 302 Create a connection between the `from_port` slot of the `from` GraphNode and the `to_port` slot of the `to` GraphNode. If the connection already exists, no connection is created. 303 */ 304 GodotError connectNode(in String from, in long from_port, in String to, in long to_port) 305 { 306 checkClassBinding!(typeof(this))(); 307 return ptrcall!(GodotError)(GDNativeClassBinding.connectNode, _godot_object, from, from_port, to, to_port); 308 } 309 /** 310 Removes the connection between the `from_port` slot of the `from` GraphNode and the `to_port` slot of the `to` GraphNode. If the connection does not exist, no connection is removed. 311 */ 312 void disconnectNode(in String from, in long from_port, in String to, in long to_port) 313 { 314 checkClassBinding!(typeof(this))(); 315 ptrcall!(void)(GDNativeClassBinding.disconnectNode, _godot_object, from, from_port, to, to_port); 316 } 317 /** 318 Returns an Array containing the list of connections. A connection consists in a structure of the form `{ from_port: 0, from: "GraphNode name 0", to_port: 1, to: "GraphNode name 1" }`. 319 */ 320 Array getConnectionList() const 321 { 322 checkClassBinding!(typeof(this))(); 323 return ptrcall!(Array)(GDNativeClassBinding.getConnectionList, _godot_object); 324 } 325 /** 326 327 */ 328 double getMinimapOpacity() const 329 { 330 checkClassBinding!(typeof(this))(); 331 return ptrcall!(double)(GDNativeClassBinding.getMinimapOpacity, _godot_object); 332 } 333 /** 334 335 */ 336 Vector2 getMinimapSize() const 337 { 338 checkClassBinding!(typeof(this))(); 339 return ptrcall!(Vector2)(GDNativeClassBinding.getMinimapSize, _godot_object); 340 } 341 /** 342 343 */ 344 Vector2 getScrollOfs() const 345 { 346 checkClassBinding!(typeof(this))(); 347 return ptrcall!(Vector2)(GDNativeClassBinding.getScrollOfs, _godot_object); 348 } 349 /** 350 351 */ 352 long getSnap() const 353 { 354 checkClassBinding!(typeof(this))(); 355 return ptrcall!(long)(GDNativeClassBinding.getSnap, _godot_object); 356 } 357 /** 358 359 */ 360 double getZoom() const 361 { 362 checkClassBinding!(typeof(this))(); 363 return ptrcall!(double)(GDNativeClassBinding.getZoom, _godot_object); 364 } 365 /** 366 Gets the $(D HBoxContainer) that contains the zooming and grid snap controls in the top left of the graph. 367 Warning: The intended usage of this function is to allow you to reposition or add your own custom controls to the container. This is an internal control and as such should not be freed. If you wish to hide this or any of its children, use their $(D CanvasItem.visible) property instead. 368 */ 369 HBoxContainer getZoomHbox() 370 { 371 checkClassBinding!(typeof(this))(); 372 return ptrcall!(HBoxContainer)(GDNativeClassBinding.getZoomHbox, _godot_object); 373 } 374 /** 375 376 */ 377 bool isMinimapEnabled() const 378 { 379 checkClassBinding!(typeof(this))(); 380 return ptrcall!(bool)(GDNativeClassBinding.isMinimapEnabled, _godot_object); 381 } 382 /** 383 Returns `true` if the `from_port` slot of the `from` GraphNode is connected to the `to_port` slot of the `to` GraphNode. 384 */ 385 bool isNodeConnected(in String from, in long from_port, in String to, in long to_port) 386 { 387 checkClassBinding!(typeof(this))(); 388 return ptrcall!(bool)(GDNativeClassBinding.isNodeConnected, _godot_object, from, from_port, to, to_port); 389 } 390 /** 391 392 */ 393 bool isRightDisconnectsEnabled() const 394 { 395 checkClassBinding!(typeof(this))(); 396 return ptrcall!(bool)(GDNativeClassBinding.isRightDisconnectsEnabled, _godot_object); 397 } 398 /** 399 400 */ 401 bool isUsingSnap() const 402 { 403 checkClassBinding!(typeof(this))(); 404 return ptrcall!(bool)(GDNativeClassBinding.isUsingSnap, _godot_object); 405 } 406 /** 407 Returns whether it's possible to connect slots of the specified types. 408 */ 409 bool isValidConnectionType(in long from_type, in long to_type) const 410 { 411 checkClassBinding!(typeof(this))(); 412 return ptrcall!(bool)(GDNativeClassBinding.isValidConnectionType, _godot_object, from_type, to_type); 413 } 414 /** 415 Makes it not possible to connect between two different slot types. The type is defined with the $(D GraphNode.setSlot) method. 416 */ 417 void removeValidConnectionType(in long from_type, in long to_type) 418 { 419 checkClassBinding!(typeof(this))(); 420 ptrcall!(void)(GDNativeClassBinding.removeValidConnectionType, _godot_object, from_type, to_type); 421 } 422 /** 423 Removes the possibility to disconnect nodes when dragging from the slot at the left if it has the specified type. 424 */ 425 void removeValidLeftDisconnectType(in long type) 426 { 427 checkClassBinding!(typeof(this))(); 428 ptrcall!(void)(GDNativeClassBinding.removeValidLeftDisconnectType, _godot_object, type); 429 } 430 /** 431 Removes the possibility to disconnect nodes when dragging from the slot at the right if it has the specified type. 432 */ 433 void removeValidRightDisconnectType(in long type) 434 { 435 checkClassBinding!(typeof(this))(); 436 ptrcall!(void)(GDNativeClassBinding.removeValidRightDisconnectType, _godot_object, type); 437 } 438 /** 439 Sets the coloration of the connection between `from`'s `from_port` and `to`'s `to_port` with the color provided in the `activity` theme property. 440 */ 441 void setConnectionActivity(in String from, in long from_port, in String to, in long to_port, in double amount) 442 { 443 checkClassBinding!(typeof(this))(); 444 ptrcall!(void)(GDNativeClassBinding.setConnectionActivity, _godot_object, from, from_port, to, to_port, amount); 445 } 446 /** 447 448 */ 449 void setMinimapEnabled(in bool enable) 450 { 451 checkClassBinding!(typeof(this))(); 452 ptrcall!(void)(GDNativeClassBinding.setMinimapEnabled, _godot_object, enable); 453 } 454 /** 455 456 */ 457 void setMinimapOpacity(in double p_opacity) 458 { 459 checkClassBinding!(typeof(this))(); 460 ptrcall!(void)(GDNativeClassBinding.setMinimapOpacity, _godot_object, p_opacity); 461 } 462 /** 463 464 */ 465 void setMinimapSize(in Vector2 p_size) 466 { 467 checkClassBinding!(typeof(this))(); 468 ptrcall!(void)(GDNativeClassBinding.setMinimapSize, _godot_object, p_size); 469 } 470 /** 471 472 */ 473 void setRightDisconnects(in bool enable) 474 { 475 checkClassBinding!(typeof(this))(); 476 ptrcall!(void)(GDNativeClassBinding.setRightDisconnects, _godot_object, enable); 477 } 478 /** 479 480 */ 481 void setScrollOfs(in Vector2 ofs) 482 { 483 checkClassBinding!(typeof(this))(); 484 ptrcall!(void)(GDNativeClassBinding.setScrollOfs, _godot_object, ofs); 485 } 486 /** 487 Sets the specified `node` as the one selected. 488 */ 489 void setSelected(Node node) 490 { 491 checkClassBinding!(typeof(this))(); 492 ptrcall!(void)(GDNativeClassBinding.setSelected, _godot_object, node); 493 } 494 /** 495 496 */ 497 void setSnap(in long pixels) 498 { 499 checkClassBinding!(typeof(this))(); 500 ptrcall!(void)(GDNativeClassBinding.setSnap, _godot_object, pixels); 501 } 502 /** 503 504 */ 505 void setUseSnap(in bool enable) 506 { 507 checkClassBinding!(typeof(this))(); 508 ptrcall!(void)(GDNativeClassBinding.setUseSnap, _godot_object, enable); 509 } 510 /** 511 512 */ 513 void setZoom(in double p_zoom) 514 { 515 checkClassBinding!(typeof(this))(); 516 ptrcall!(void)(GDNativeClassBinding.setZoom, _godot_object, p_zoom); 517 } 518 /** 519 If `true`, the minimap is visible. 520 */ 521 @property bool minimapEnabled() 522 { 523 return isMinimapEnabled(); 524 } 525 /// ditto 526 @property void minimapEnabled(bool v) 527 { 528 setMinimapEnabled(v); 529 } 530 /** 531 The opacity of the minimap rectangle. 532 */ 533 @property double minimapOpacity() 534 { 535 return getMinimapOpacity(); 536 } 537 /// ditto 538 @property void minimapOpacity(double v) 539 { 540 setMinimapOpacity(v); 541 } 542 /** 543 The size of the minimap rectangle. The map itself is based on the size of the grid area and is scaled to fit this rectangle. 544 */ 545 @property Vector2 minimapSize() 546 { 547 return getMinimapSize(); 548 } 549 /// ditto 550 @property void minimapSize(Vector2 v) 551 { 552 setMinimapSize(v); 553 } 554 /** 555 If `true`, enables disconnection of existing connections in the GraphEdit by dragging the right end. 556 */ 557 @property bool rightDisconnects() 558 { 559 return isRightDisconnectsEnabled(); 560 } 561 /// ditto 562 @property void rightDisconnects(bool v) 563 { 564 setRightDisconnects(v); 565 } 566 /** 567 The scroll offset. 568 */ 569 @property Vector2 scrollOffset() 570 { 571 return getScrollOfs(); 572 } 573 /// ditto 574 @property void scrollOffset(Vector2 v) 575 { 576 setScrollOfs(v); 577 } 578 /** 579 The snapping distance in pixels. 580 */ 581 @property long snapDistance() 582 { 583 return getSnap(); 584 } 585 /// ditto 586 @property void snapDistance(long v) 587 { 588 setSnap(v); 589 } 590 /** 591 If `true`, enables snapping. 592 */ 593 @property bool useSnap() 594 { 595 return isUsingSnap(); 596 } 597 /// ditto 598 @property void useSnap(bool v) 599 { 600 setUseSnap(v); 601 } 602 /** 603 The current zoom value. 604 */ 605 @property double zoom() 606 { 607 return getZoom(); 608 } 609 /// ditto 610 @property void zoom(double v) 611 { 612 setZoom(v); 613 } 614 }