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.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.control; 24 import godot.inputevent; 25 import godot.hboxcontainer; 26 import godot.canvasitem; 27 import godot.node; 28 /** 29 GraphEdit is an area capable of showing various GraphNodes. It manages connection events between them. 30 31 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 GraphNodes slots is disabled by default. 32 It is greatly advised to enable low processor usage mode (see $(D OS.setLowProcessorUsageMode)) when using GraphEdits. 33 */ 34 @GodotBaseClass struct GraphEdit 35 { 36 enum string _GODOT_internal_name = "GraphEdit"; 37 public: 38 @nogc nothrow: 39 union { godot_object _godot_object; Control _GODOT_base; } 40 alias _GODOT_base this; 41 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 42 package(godot) __gshared bool _classBindingInitialized = false; 43 package(godot) static struct _classBinding 44 { 45 __gshared: 46 @GodotName("connect_node") GodotMethod!(GodotError, String, long, String, long) connectNode; 47 @GodotName("is_node_connected") GodotMethod!(bool, String, long, String, long) isNodeConnected; 48 @GodotName("disconnect_node") GodotMethod!(void, String, long, String, long) disconnectNode; 49 @GodotName("set_connection_activity") GodotMethod!(void, String, long, String, long, double) setConnectionActivity; 50 @GodotName("get_connection_list") GodotMethod!(Array) getConnectionList; 51 @GodotName("clear_connections") GodotMethod!(void) clearConnections; 52 @GodotName("get_scroll_ofs") GodotMethod!(Vector2) getScrollOfs; 53 @GodotName("set_scroll_ofs") GodotMethod!(void, Vector2) setScrollOfs; 54 @GodotName("add_valid_right_disconnect_type") GodotMethod!(void, long) addValidRightDisconnectType; 55 @GodotName("remove_valid_right_disconnect_type") GodotMethod!(void, long) removeValidRightDisconnectType; 56 @GodotName("add_valid_left_disconnect_type") GodotMethod!(void, long) addValidLeftDisconnectType; 57 @GodotName("remove_valid_left_disconnect_type") GodotMethod!(void, long) removeValidLeftDisconnectType; 58 @GodotName("add_valid_connection_type") GodotMethod!(void, long, long) addValidConnectionType; 59 @GodotName("remove_valid_connection_type") GodotMethod!(void, long, long) removeValidConnectionType; 60 @GodotName("is_valid_connection_type") GodotMethod!(bool, long, long) isValidConnectionType; 61 @GodotName("set_zoom") GodotMethod!(void, double) setZoom; 62 @GodotName("get_zoom") GodotMethod!(double) getZoom; 63 @GodotName("set_snap") GodotMethod!(void, long) setSnap; 64 @GodotName("get_snap") GodotMethod!(long) getSnap; 65 @GodotName("set_use_snap") GodotMethod!(void, bool) setUseSnap; 66 @GodotName("is_using_snap") GodotMethod!(bool) isUsingSnap; 67 @GodotName("set_right_disconnects") GodotMethod!(void, bool) setRightDisconnects; 68 @GodotName("is_right_disconnects_enabled") GodotMethod!(bool) isRightDisconnectsEnabled; 69 @GodotName("_graph_node_moved") GodotMethod!(void, GodotObject) _graphNodeMoved; 70 @GodotName("_graph_node_raised") GodotMethod!(void, GodotObject) _graphNodeRaised; 71 @GodotName("_top_layer_input") GodotMethod!(void, InputEvent) _topLayerInput; 72 @GodotName("_top_layer_draw") GodotMethod!(void) _topLayerDraw; 73 @GodotName("_scroll_moved") GodotMethod!(void, double) _scrollMoved; 74 @GodotName("_zoom_minus") GodotMethod!(void) _zoomMinus; 75 @GodotName("_zoom_reset") GodotMethod!(void) _zoomReset; 76 @GodotName("_zoom_plus") GodotMethod!(void) _zoomPlus; 77 @GodotName("_snap_toggled") GodotMethod!(void) _snapToggled; 78 @GodotName("_snap_value_changed") GodotMethod!(void, double) _snapValueChanged; 79 @GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput; 80 @GodotName("_update_scroll_offset") GodotMethod!(void) _updateScrollOffset; 81 @GodotName("_connections_layer_draw") GodotMethod!(void) _connectionsLayerDraw; 82 @GodotName("get_zoom_hbox") GodotMethod!(HBoxContainer) getZoomHbox; 83 @GodotName("set_selected") GodotMethod!(void, GodotObject) setSelected; 84 } 85 bool opEquals(in GraphEdit other) const { return _godot_object.ptr is other._godot_object.ptr; } 86 GraphEdit opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 87 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 88 mixin baseCasts; 89 static GraphEdit _new() 90 { 91 static godot_class_constructor constructor; 92 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("GraphEdit"); 93 if(constructor is null) return typeof(this).init; 94 return cast(GraphEdit)(constructor()); 95 } 96 @disable new(size_t s); 97 /** 98 Create a connection between 'from_port' slot of 'from' GraphNode and 'to_port' slot of 'to' GraphNode. If the connection already exists, no connection is created. 99 */ 100 GodotError connectNode(StringArg0, StringArg2)(in StringArg0 from, in long from_port, in StringArg2 to, in long to_port) 101 { 102 checkClassBinding!(typeof(this))(); 103 return ptrcall!(GodotError)(_classBinding.connectNode, _godot_object, from, from_port, to, to_port); 104 } 105 /** 106 Return true if the 'from_port' slot of 'from' GraphNode is connected to the 'to_port' slot of 'to' GraphNode. 107 */ 108 bool isNodeConnected(StringArg0, StringArg2)(in StringArg0 from, in long from_port, in StringArg2 to, in long to_port) 109 { 110 checkClassBinding!(typeof(this))(); 111 return ptrcall!(bool)(_classBinding.isNodeConnected, _godot_object, from, from_port, to, to_port); 112 } 113 /** 114 Remove the connection between 'from_port' slot of 'from' GraphNode and 'to_port' slot of 'to' GraphNode, if connection exists. 115 */ 116 void disconnectNode(StringArg0, StringArg2)(in StringArg0 from, in long from_port, in StringArg2 to, in long to_port) 117 { 118 checkClassBinding!(typeof(this))(); 119 ptrcall!(void)(_classBinding.disconnectNode, _godot_object, from, from_port, to, to_port); 120 } 121 /** 122 123 */ 124 void setConnectionActivity(StringArg0, StringArg2)(in StringArg0 from, in long from_port, in StringArg2 to, in long to_port, in double amount) 125 { 126 checkClassBinding!(typeof(this))(); 127 ptrcall!(void)(_classBinding.setConnectionActivity, _godot_object, from, from_port, to, to_port, amount); 128 } 129 /** 130 Return an Array containing the list of connections. A connection consists in a structure of the form {from_slot: 0, from: "GraphNode name 0", to_slot: 1, to: "GraphNode name 1" } 131 */ 132 Array getConnectionList() const 133 { 134 checkClassBinding!(typeof(this))(); 135 return ptrcall!(Array)(_classBinding.getConnectionList, _godot_object); 136 } 137 /** 138 Remove all connections between nodes. 139 */ 140 void clearConnections() 141 { 142 checkClassBinding!(typeof(this))(); 143 ptrcall!(void)(_classBinding.clearConnections, _godot_object); 144 } 145 /** 146 147 */ 148 Vector2 getScrollOfs() const 149 { 150 checkClassBinding!(typeof(this))(); 151 return ptrcall!(Vector2)(_classBinding.getScrollOfs, _godot_object); 152 } 153 /** 154 155 */ 156 void setScrollOfs(in Vector2 ofs) 157 { 158 checkClassBinding!(typeof(this))(); 159 ptrcall!(void)(_classBinding.setScrollOfs, _godot_object, ofs); 160 } 161 /** 162 Makes possible to disconnect nodes when dragging from the slot at the right if it has the specified type. 163 */ 164 void addValidRightDisconnectType(in long type) 165 { 166 checkClassBinding!(typeof(this))(); 167 ptrcall!(void)(_classBinding.addValidRightDisconnectType, _godot_object, type); 168 } 169 /** 170 Removes the possibility to disconnect nodes when dragging from the slot at the right if it has the specified type. 171 */ 172 void removeValidRightDisconnectType(in long type) 173 { 174 checkClassBinding!(typeof(this))(); 175 ptrcall!(void)(_classBinding.removeValidRightDisconnectType, _godot_object, type); 176 } 177 /** 178 Makes possible to disconnect nodes when dragging from the slot at the left if it has the specified type. 179 */ 180 void addValidLeftDisconnectType(in long type) 181 { 182 checkClassBinding!(typeof(this))(); 183 ptrcall!(void)(_classBinding.addValidLeftDisconnectType, _godot_object, type); 184 } 185 /** 186 Removes the possibility to disconnect nodes when dragging from the slot at the left if it has the specified type. 187 */ 188 void removeValidLeftDisconnectType(in long type) 189 { 190 checkClassBinding!(typeof(this))(); 191 ptrcall!(void)(_classBinding.removeValidLeftDisconnectType, _godot_object, type); 192 } 193 /** 194 Makes possible the connection between two different slot types. The type is defined with the $(D GraphNode.setSlot) method. 195 */ 196 void addValidConnectionType(in long from_type, in long to_type) 197 { 198 checkClassBinding!(typeof(this))(); 199 ptrcall!(void)(_classBinding.addValidConnectionType, _godot_object, from_type, to_type); 200 } 201 /** 202 Makes it not possible to connect between two different slot types. The type is defined with the $(D GraphNode.setSlot) method. 203 */ 204 void removeValidConnectionType(in long from_type, in long to_type) 205 { 206 checkClassBinding!(typeof(this))(); 207 ptrcall!(void)(_classBinding.removeValidConnectionType, _godot_object, from_type, to_type); 208 } 209 /** 210 Returns whether it's possible to connect slots of the specified types. 211 */ 212 bool isValidConnectionType(in long from_type, in long to_type) const 213 { 214 checkClassBinding!(typeof(this))(); 215 return ptrcall!(bool)(_classBinding.isValidConnectionType, _godot_object, from_type, to_type); 216 } 217 /** 218 219 */ 220 void setZoom(in double p_zoom) 221 { 222 checkClassBinding!(typeof(this))(); 223 ptrcall!(void)(_classBinding.setZoom, _godot_object, p_zoom); 224 } 225 /** 226 227 */ 228 double getZoom() const 229 { 230 checkClassBinding!(typeof(this))(); 231 return ptrcall!(double)(_classBinding.getZoom, _godot_object); 232 } 233 /** 234 235 */ 236 void setSnap(in long pixels) 237 { 238 checkClassBinding!(typeof(this))(); 239 ptrcall!(void)(_classBinding.setSnap, _godot_object, pixels); 240 } 241 /** 242 243 */ 244 long getSnap() const 245 { 246 checkClassBinding!(typeof(this))(); 247 return ptrcall!(long)(_classBinding.getSnap, _godot_object); 248 } 249 /** 250 251 */ 252 void setUseSnap(in bool enable) 253 { 254 checkClassBinding!(typeof(this))(); 255 ptrcall!(void)(_classBinding.setUseSnap, _godot_object, enable); 256 } 257 /** 258 259 */ 260 bool isUsingSnap() const 261 { 262 checkClassBinding!(typeof(this))(); 263 return ptrcall!(bool)(_classBinding.isUsingSnap, _godot_object); 264 } 265 /** 266 267 */ 268 void setRightDisconnects(in bool enable) 269 { 270 checkClassBinding!(typeof(this))(); 271 ptrcall!(void)(_classBinding.setRightDisconnects, _godot_object, enable); 272 } 273 /** 274 275 */ 276 bool isRightDisconnectsEnabled() const 277 { 278 checkClassBinding!(typeof(this))(); 279 return ptrcall!(bool)(_classBinding.isRightDisconnectsEnabled, _godot_object); 280 } 281 /** 282 283 */ 284 void _graphNodeMoved(GodotObject arg0) 285 { 286 Array _GODOT_args = Array.empty_array; 287 _GODOT_args.append(arg0); 288 String _GODOT_method_name = String("_graph_node_moved"); 289 this.callv(_GODOT_method_name, _GODOT_args); 290 } 291 /** 292 293 */ 294 void _graphNodeRaised(GodotObject arg0) 295 { 296 Array _GODOT_args = Array.empty_array; 297 _GODOT_args.append(arg0); 298 String _GODOT_method_name = String("_graph_node_raised"); 299 this.callv(_GODOT_method_name, _GODOT_args); 300 } 301 /** 302 303 */ 304 void _topLayerInput(InputEvent arg0) 305 { 306 Array _GODOT_args = Array.empty_array; 307 _GODOT_args.append(arg0); 308 String _GODOT_method_name = String("_top_layer_input"); 309 this.callv(_GODOT_method_name, _GODOT_args); 310 } 311 /** 312 313 */ 314 void _topLayerDraw() 315 { 316 Array _GODOT_args = Array.empty_array; 317 String _GODOT_method_name = String("_top_layer_draw"); 318 this.callv(_GODOT_method_name, _GODOT_args); 319 } 320 /** 321 322 */ 323 void _scrollMoved(in double arg0) 324 { 325 Array _GODOT_args = Array.empty_array; 326 _GODOT_args.append(arg0); 327 String _GODOT_method_name = String("_scroll_moved"); 328 this.callv(_GODOT_method_name, _GODOT_args); 329 } 330 /** 331 332 */ 333 void _zoomMinus() 334 { 335 Array _GODOT_args = Array.empty_array; 336 String _GODOT_method_name = String("_zoom_minus"); 337 this.callv(_GODOT_method_name, _GODOT_args); 338 } 339 /** 340 341 */ 342 void _zoomReset() 343 { 344 Array _GODOT_args = Array.empty_array; 345 String _GODOT_method_name = String("_zoom_reset"); 346 this.callv(_GODOT_method_name, _GODOT_args); 347 } 348 /** 349 350 */ 351 void _zoomPlus() 352 { 353 Array _GODOT_args = Array.empty_array; 354 String _GODOT_method_name = String("_zoom_plus"); 355 this.callv(_GODOT_method_name, _GODOT_args); 356 } 357 /** 358 359 */ 360 void _snapToggled() 361 { 362 Array _GODOT_args = Array.empty_array; 363 String _GODOT_method_name = String("_snap_toggled"); 364 this.callv(_GODOT_method_name, _GODOT_args); 365 } 366 /** 367 368 */ 369 void _snapValueChanged(in double arg0) 370 { 371 Array _GODOT_args = Array.empty_array; 372 _GODOT_args.append(arg0); 373 String _GODOT_method_name = String("_snap_value_changed"); 374 this.callv(_GODOT_method_name, _GODOT_args); 375 } 376 /** 377 378 */ 379 void _guiInput(InputEvent arg0) 380 { 381 Array _GODOT_args = Array.empty_array; 382 _GODOT_args.append(arg0); 383 String _GODOT_method_name = String("_gui_input"); 384 this.callv(_GODOT_method_name, _GODOT_args); 385 } 386 /** 387 388 */ 389 void _updateScrollOffset() 390 { 391 Array _GODOT_args = Array.empty_array; 392 String _GODOT_method_name = String("_update_scroll_offset"); 393 this.callv(_GODOT_method_name, _GODOT_args); 394 } 395 /** 396 397 */ 398 void _connectionsLayerDraw() 399 { 400 Array _GODOT_args = Array.empty_array; 401 String _GODOT_method_name = String("_connections_layer_draw"); 402 this.callv(_GODOT_method_name, _GODOT_args); 403 } 404 /** 405 406 */ 407 HBoxContainer getZoomHbox() 408 { 409 checkClassBinding!(typeof(this))(); 410 return ptrcall!(HBoxContainer)(_classBinding.getZoomHbox, _godot_object); 411 } 412 /** 413 Sets the specified `node` as the one selected. 414 */ 415 void setSelected(GodotObject node) 416 { 417 checkClassBinding!(typeof(this))(); 418 ptrcall!(void)(_classBinding.setSelected, _godot_object, node); 419 } 420 /** 421 If `true`, enables disconnection of existing connections in the GraphEdit by dragging the right end. 422 */ 423 @property bool rightDisconnects() 424 { 425 return isRightDisconnectsEnabled(); 426 } 427 /// ditto 428 @property void rightDisconnects(bool v) 429 { 430 setRightDisconnects(v); 431 } 432 /** 433 The scroll offset. 434 */ 435 @property Vector2 scrollOffset() 436 { 437 return getScrollOfs(); 438 } 439 /// ditto 440 @property void scrollOffset(Vector2 v) 441 { 442 setScrollOfs(v); 443 } 444 /** 445 The snapping distance in pixels. 446 */ 447 @property long snapDistance() 448 { 449 return getSnap(); 450 } 451 /// ditto 452 @property void snapDistance(long v) 453 { 454 setSnap(v); 455 } 456 /** 457 If `true`, enables snapping. 458 */ 459 @property bool useSnap() 460 { 461 return isUsingSnap(); 462 } 463 /// ditto 464 @property void useSnap(bool v) 465 { 466 setUseSnap(v); 467 } 468 /** 469 The current zoom value. 470 */ 471 @property double zoom() 472 { 473 return getZoom(); 474 } 475 /// ditto 476 @property void zoom(double v) 477 { 478 setZoom(v); 479 } 480 }