1 /** 2 Casts light in a 2D environment. 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.light2d; 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.node2d; 25 import godot.texture; 26 /** 27 Casts light in a 2D environment. 28 29 Light is defined by a (usually grayscale) texture, a color, an energy value, a mode (see constants), and various other parameters (range and shadows-related). 30 $(B Note:) Light2D can also be used as a mask. 31 */ 32 @GodotBaseClass struct Light2D 33 { 34 package(godot) enum string _GODOT_internal_name = "Light2D"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Node2D _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("get_color") GodotMethod!(Color) getColor; 45 @GodotName("get_energy") GodotMethod!(double) getEnergy; 46 @GodotName("get_height") GodotMethod!(double) getHeight; 47 @GodotName("get_item_cull_mask") GodotMethod!(long) getItemCullMask; 48 @GodotName("get_item_shadow_cull_mask") GodotMethod!(long) getItemShadowCullMask; 49 @GodotName("get_layer_range_max") GodotMethod!(long) getLayerRangeMax; 50 @GodotName("get_layer_range_min") GodotMethod!(long) getLayerRangeMin; 51 @GodotName("get_mode") GodotMethod!(Light2D.Mode) getMode; 52 @GodotName("get_shadow_buffer_size") GodotMethod!(long) getShadowBufferSize; 53 @GodotName("get_shadow_color") GodotMethod!(Color) getShadowColor; 54 @GodotName("get_shadow_filter") GodotMethod!(Light2D.ShadowFilter) getShadowFilter; 55 @GodotName("get_shadow_gradient_length") GodotMethod!(double) getShadowGradientLength; 56 @GodotName("get_shadow_smooth") GodotMethod!(double) getShadowSmooth; 57 @GodotName("get_texture") GodotMethod!(Texture) getTexture; 58 @GodotName("get_texture_offset") GodotMethod!(Vector2) getTextureOffset; 59 @GodotName("get_texture_scale") GodotMethod!(double) getTextureScale; 60 @GodotName("get_z_range_max") GodotMethod!(long) getZRangeMax; 61 @GodotName("get_z_range_min") GodotMethod!(long) getZRangeMin; 62 @GodotName("is_editor_only") GodotMethod!(bool) isEditorOnly; 63 @GodotName("is_enabled") GodotMethod!(bool) isEnabled; 64 @GodotName("is_shadow_enabled") GodotMethod!(bool) isShadowEnabled; 65 @GodotName("set_color") GodotMethod!(void, Color) setColor; 66 @GodotName("set_editor_only") GodotMethod!(void, bool) setEditorOnly; 67 @GodotName("set_enabled") GodotMethod!(void, bool) setEnabled; 68 @GodotName("set_energy") GodotMethod!(void, double) setEnergy; 69 @GodotName("set_height") GodotMethod!(void, double) setHeight; 70 @GodotName("set_item_cull_mask") GodotMethod!(void, long) setItemCullMask; 71 @GodotName("set_item_shadow_cull_mask") GodotMethod!(void, long) setItemShadowCullMask; 72 @GodotName("set_layer_range_max") GodotMethod!(void, long) setLayerRangeMax; 73 @GodotName("set_layer_range_min") GodotMethod!(void, long) setLayerRangeMin; 74 @GodotName("set_mode") GodotMethod!(void, long) setMode; 75 @GodotName("set_shadow_buffer_size") GodotMethod!(void, long) setShadowBufferSize; 76 @GodotName("set_shadow_color") GodotMethod!(void, Color) setShadowColor; 77 @GodotName("set_shadow_enabled") GodotMethod!(void, bool) setShadowEnabled; 78 @GodotName("set_shadow_filter") GodotMethod!(void, long) setShadowFilter; 79 @GodotName("set_shadow_gradient_length") GodotMethod!(void, double) setShadowGradientLength; 80 @GodotName("set_shadow_smooth") GodotMethod!(void, double) setShadowSmooth; 81 @GodotName("set_texture") GodotMethod!(void, Texture) setTexture; 82 @GodotName("set_texture_offset") GodotMethod!(void, Vector2) setTextureOffset; 83 @GodotName("set_texture_scale") GodotMethod!(void, double) setTextureScale; 84 @GodotName("set_z_range_max") GodotMethod!(void, long) setZRangeMax; 85 @GodotName("set_z_range_min") GodotMethod!(void, long) setZRangeMin; 86 } 87 /// 88 pragma(inline, true) bool opEquals(in Light2D other) const 89 { return _godot_object.ptr is other._godot_object.ptr; } 90 /// 91 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 92 { _godot_object.ptr = n; return null; } 93 /// 94 pragma(inline, true) bool opEquals(typeof(null) n) const 95 { return _godot_object.ptr is n; } 96 /// 97 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 98 mixin baseCasts; 99 /// Construct a new instance of Light2D. 100 /// Note: use `memnew!Light2D` instead. 101 static Light2D _new() 102 { 103 static godot_class_constructor constructor; 104 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Light2D"); 105 if(constructor is null) return typeof(this).init; 106 return cast(Light2D)(constructor()); 107 } 108 @disable new(size_t s); 109 /// 110 enum ShadowFilter : int 111 { 112 /** 113 No filter applies to the shadow map. See $(D shadowFilter). 114 */ 115 shadowFilterNone = 0, 116 /** 117 Percentage closer filtering (3 samples) applies to the shadow map. See $(D shadowFilter). 118 */ 119 shadowFilterPcf3 = 1, 120 /** 121 Percentage closer filtering (5 samples) applies to the shadow map. See $(D shadowFilter). 122 */ 123 shadowFilterPcf5 = 2, 124 /** 125 Percentage closer filtering (7 samples) applies to the shadow map. See $(D shadowFilter). 126 */ 127 shadowFilterPcf7 = 3, 128 /** 129 Percentage closer filtering (9 samples) applies to the shadow map. See $(D shadowFilter). 130 */ 131 shadowFilterPcf9 = 4, 132 /** 133 Percentage closer filtering (13 samples) applies to the shadow map. See $(D shadowFilter). 134 */ 135 shadowFilterPcf13 = 5, 136 } 137 /// 138 enum Mode : int 139 { 140 /** 141 Adds the value of pixels corresponding to the Light2D to the values of pixels under it. This is the common behavior of a light. 142 */ 143 modeAdd = 0, 144 /** 145 Subtracts the value of pixels corresponding to the Light2D to the values of pixels under it, resulting in inversed light effect. 146 */ 147 modeSub = 1, 148 /** 149 Mix the value of pixels corresponding to the Light2D to the values of pixels under it by linear interpolation. 150 */ 151 modeMix = 2, 152 /** 153 The light texture of the Light2D is used as a mask, hiding or revealing parts of the screen underneath depending on the value of each pixel of the light (mask) texture. 154 */ 155 modeMask = 3, 156 } 157 /// 158 enum Constants : int 159 { 160 modeAdd = 0, 161 shadowFilterNone = 0, 162 modeSub = 1, 163 shadowFilterPcf3 = 1, 164 modeMix = 2, 165 shadowFilterPcf5 = 2, 166 modeMask = 3, 167 shadowFilterPcf7 = 3, 168 shadowFilterPcf9 = 4, 169 shadowFilterPcf13 = 5, 170 } 171 /** 172 173 */ 174 Color getColor() const 175 { 176 checkClassBinding!(typeof(this))(); 177 return ptrcall!(Color)(GDNativeClassBinding.getColor, _godot_object); 178 } 179 /** 180 181 */ 182 double getEnergy() const 183 { 184 checkClassBinding!(typeof(this))(); 185 return ptrcall!(double)(GDNativeClassBinding.getEnergy, _godot_object); 186 } 187 /** 188 189 */ 190 double getHeight() const 191 { 192 checkClassBinding!(typeof(this))(); 193 return ptrcall!(double)(GDNativeClassBinding.getHeight, _godot_object); 194 } 195 /** 196 197 */ 198 long getItemCullMask() const 199 { 200 checkClassBinding!(typeof(this))(); 201 return ptrcall!(long)(GDNativeClassBinding.getItemCullMask, _godot_object); 202 } 203 /** 204 205 */ 206 long getItemShadowCullMask() const 207 { 208 checkClassBinding!(typeof(this))(); 209 return ptrcall!(long)(GDNativeClassBinding.getItemShadowCullMask, _godot_object); 210 } 211 /** 212 213 */ 214 long getLayerRangeMax() const 215 { 216 checkClassBinding!(typeof(this))(); 217 return ptrcall!(long)(GDNativeClassBinding.getLayerRangeMax, _godot_object); 218 } 219 /** 220 221 */ 222 long getLayerRangeMin() const 223 { 224 checkClassBinding!(typeof(this))(); 225 return ptrcall!(long)(GDNativeClassBinding.getLayerRangeMin, _godot_object); 226 } 227 /** 228 229 */ 230 Light2D.Mode getMode() const 231 { 232 checkClassBinding!(typeof(this))(); 233 return ptrcall!(Light2D.Mode)(GDNativeClassBinding.getMode, _godot_object); 234 } 235 /** 236 237 */ 238 long getShadowBufferSize() const 239 { 240 checkClassBinding!(typeof(this))(); 241 return ptrcall!(long)(GDNativeClassBinding.getShadowBufferSize, _godot_object); 242 } 243 /** 244 245 */ 246 Color getShadowColor() const 247 { 248 checkClassBinding!(typeof(this))(); 249 return ptrcall!(Color)(GDNativeClassBinding.getShadowColor, _godot_object); 250 } 251 /** 252 253 */ 254 Light2D.ShadowFilter getShadowFilter() const 255 { 256 checkClassBinding!(typeof(this))(); 257 return ptrcall!(Light2D.ShadowFilter)(GDNativeClassBinding.getShadowFilter, _godot_object); 258 } 259 /** 260 261 */ 262 double getShadowGradientLength() const 263 { 264 checkClassBinding!(typeof(this))(); 265 return ptrcall!(double)(GDNativeClassBinding.getShadowGradientLength, _godot_object); 266 } 267 /** 268 269 */ 270 double getShadowSmooth() const 271 { 272 checkClassBinding!(typeof(this))(); 273 return ptrcall!(double)(GDNativeClassBinding.getShadowSmooth, _godot_object); 274 } 275 /** 276 277 */ 278 Ref!Texture getTexture() const 279 { 280 checkClassBinding!(typeof(this))(); 281 return ptrcall!(Texture)(GDNativeClassBinding.getTexture, _godot_object); 282 } 283 /** 284 285 */ 286 Vector2 getTextureOffset() const 287 { 288 checkClassBinding!(typeof(this))(); 289 return ptrcall!(Vector2)(GDNativeClassBinding.getTextureOffset, _godot_object); 290 } 291 /** 292 293 */ 294 double getTextureScale() const 295 { 296 checkClassBinding!(typeof(this))(); 297 return ptrcall!(double)(GDNativeClassBinding.getTextureScale, _godot_object); 298 } 299 /** 300 301 */ 302 long getZRangeMax() const 303 { 304 checkClassBinding!(typeof(this))(); 305 return ptrcall!(long)(GDNativeClassBinding.getZRangeMax, _godot_object); 306 } 307 /** 308 309 */ 310 long getZRangeMin() const 311 { 312 checkClassBinding!(typeof(this))(); 313 return ptrcall!(long)(GDNativeClassBinding.getZRangeMin, _godot_object); 314 } 315 /** 316 317 */ 318 bool isEditorOnly() const 319 { 320 checkClassBinding!(typeof(this))(); 321 return ptrcall!(bool)(GDNativeClassBinding.isEditorOnly, _godot_object); 322 } 323 /** 324 325 */ 326 bool isEnabled() const 327 { 328 checkClassBinding!(typeof(this))(); 329 return ptrcall!(bool)(GDNativeClassBinding.isEnabled, _godot_object); 330 } 331 /** 332 333 */ 334 bool isShadowEnabled() const 335 { 336 checkClassBinding!(typeof(this))(); 337 return ptrcall!(bool)(GDNativeClassBinding.isShadowEnabled, _godot_object); 338 } 339 /** 340 341 */ 342 void setColor(in Color color) 343 { 344 checkClassBinding!(typeof(this))(); 345 ptrcall!(void)(GDNativeClassBinding.setColor, _godot_object, color); 346 } 347 /** 348 349 */ 350 void setEditorOnly(in bool editor_only) 351 { 352 checkClassBinding!(typeof(this))(); 353 ptrcall!(void)(GDNativeClassBinding.setEditorOnly, _godot_object, editor_only); 354 } 355 /** 356 357 */ 358 void setEnabled(in bool enabled) 359 { 360 checkClassBinding!(typeof(this))(); 361 ptrcall!(void)(GDNativeClassBinding.setEnabled, _godot_object, enabled); 362 } 363 /** 364 365 */ 366 void setEnergy(in double energy) 367 { 368 checkClassBinding!(typeof(this))(); 369 ptrcall!(void)(GDNativeClassBinding.setEnergy, _godot_object, energy); 370 } 371 /** 372 373 */ 374 void setHeight(in double height) 375 { 376 checkClassBinding!(typeof(this))(); 377 ptrcall!(void)(GDNativeClassBinding.setHeight, _godot_object, height); 378 } 379 /** 380 381 */ 382 void setItemCullMask(in long item_cull_mask) 383 { 384 checkClassBinding!(typeof(this))(); 385 ptrcall!(void)(GDNativeClassBinding.setItemCullMask, _godot_object, item_cull_mask); 386 } 387 /** 388 389 */ 390 void setItemShadowCullMask(in long item_shadow_cull_mask) 391 { 392 checkClassBinding!(typeof(this))(); 393 ptrcall!(void)(GDNativeClassBinding.setItemShadowCullMask, _godot_object, item_shadow_cull_mask); 394 } 395 /** 396 397 */ 398 void setLayerRangeMax(in long layer) 399 { 400 checkClassBinding!(typeof(this))(); 401 ptrcall!(void)(GDNativeClassBinding.setLayerRangeMax, _godot_object, layer); 402 } 403 /** 404 405 */ 406 void setLayerRangeMin(in long layer) 407 { 408 checkClassBinding!(typeof(this))(); 409 ptrcall!(void)(GDNativeClassBinding.setLayerRangeMin, _godot_object, layer); 410 } 411 /** 412 413 */ 414 void setMode(in long mode) 415 { 416 checkClassBinding!(typeof(this))(); 417 ptrcall!(void)(GDNativeClassBinding.setMode, _godot_object, mode); 418 } 419 /** 420 421 */ 422 void setShadowBufferSize(in long size) 423 { 424 checkClassBinding!(typeof(this))(); 425 ptrcall!(void)(GDNativeClassBinding.setShadowBufferSize, _godot_object, size); 426 } 427 /** 428 429 */ 430 void setShadowColor(in Color shadow_color) 431 { 432 checkClassBinding!(typeof(this))(); 433 ptrcall!(void)(GDNativeClassBinding.setShadowColor, _godot_object, shadow_color); 434 } 435 /** 436 437 */ 438 void setShadowEnabled(in bool enabled) 439 { 440 checkClassBinding!(typeof(this))(); 441 ptrcall!(void)(GDNativeClassBinding.setShadowEnabled, _godot_object, enabled); 442 } 443 /** 444 445 */ 446 void setShadowFilter(in long filter) 447 { 448 checkClassBinding!(typeof(this))(); 449 ptrcall!(void)(GDNativeClassBinding.setShadowFilter, _godot_object, filter); 450 } 451 /** 452 453 */ 454 void setShadowGradientLength(in double multiplier) 455 { 456 checkClassBinding!(typeof(this))(); 457 ptrcall!(void)(GDNativeClassBinding.setShadowGradientLength, _godot_object, multiplier); 458 } 459 /** 460 461 */ 462 void setShadowSmooth(in double smooth) 463 { 464 checkClassBinding!(typeof(this))(); 465 ptrcall!(void)(GDNativeClassBinding.setShadowSmooth, _godot_object, smooth); 466 } 467 /** 468 469 */ 470 void setTexture(Texture texture) 471 { 472 checkClassBinding!(typeof(this))(); 473 ptrcall!(void)(GDNativeClassBinding.setTexture, _godot_object, texture); 474 } 475 /** 476 477 */ 478 void setTextureOffset(in Vector2 texture_offset) 479 { 480 checkClassBinding!(typeof(this))(); 481 ptrcall!(void)(GDNativeClassBinding.setTextureOffset, _godot_object, texture_offset); 482 } 483 /** 484 485 */ 486 void setTextureScale(in double texture_scale) 487 { 488 checkClassBinding!(typeof(this))(); 489 ptrcall!(void)(GDNativeClassBinding.setTextureScale, _godot_object, texture_scale); 490 } 491 /** 492 493 */ 494 void setZRangeMax(in long z) 495 { 496 checkClassBinding!(typeof(this))(); 497 ptrcall!(void)(GDNativeClassBinding.setZRangeMax, _godot_object, z); 498 } 499 /** 500 501 */ 502 void setZRangeMin(in long z) 503 { 504 checkClassBinding!(typeof(this))(); 505 ptrcall!(void)(GDNativeClassBinding.setZRangeMin, _godot_object, z); 506 } 507 /** 508 The Light2D's $(D Color). 509 */ 510 @property Color color() 511 { 512 return getColor(); 513 } 514 /// ditto 515 @property void color(Color v) 516 { 517 setColor(v); 518 } 519 /** 520 If `true`, Light2D will only appear when editing the scene. 521 */ 522 @property bool editorOnly() 523 { 524 return isEditorOnly(); 525 } 526 /// ditto 527 @property void editorOnly(bool v) 528 { 529 setEditorOnly(v); 530 } 531 /** 532 If `true`, Light2D will emit light. 533 */ 534 @property bool enabled() 535 { 536 return isEnabled(); 537 } 538 /// ditto 539 @property void enabled(bool v) 540 { 541 setEnabled(v); 542 } 543 /** 544 The Light2D's energy value. The larger the value, the stronger the light. 545 */ 546 @property double energy() 547 { 548 return getEnergy(); 549 } 550 /// ditto 551 @property void energy(double v) 552 { 553 setEnergy(v); 554 } 555 /** 556 The Light2D's mode. See $(D mode) constants for values. 557 */ 558 @property Light2D.Mode mode() 559 { 560 return getMode(); 561 } 562 /// ditto 563 @property void mode(long v) 564 { 565 setMode(v); 566 } 567 /** 568 The offset of the Light2D's `texture`. 569 */ 570 @property Vector2 offset() 571 { 572 return getTextureOffset(); 573 } 574 /// ditto 575 @property void offset(Vector2 v) 576 { 577 setTextureOffset(v); 578 } 579 /** 580 The height of the Light2D. Used with 2D normal mapping. 581 */ 582 @property double rangeHeight() 583 { 584 return getHeight(); 585 } 586 /// ditto 587 @property void rangeHeight(double v) 588 { 589 setHeight(v); 590 } 591 /** 592 The layer mask. Only objects with a matching mask will be affected by the Light2D. 593 */ 594 @property long rangeItemCullMask() 595 { 596 return getItemCullMask(); 597 } 598 /// ditto 599 @property void rangeItemCullMask(long v) 600 { 601 setItemCullMask(v); 602 } 603 /** 604 Maximum layer value of objects that are affected by the Light2D. 605 */ 606 @property long rangeLayerMax() 607 { 608 return getLayerRangeMax(); 609 } 610 /// ditto 611 @property void rangeLayerMax(long v) 612 { 613 setLayerRangeMax(v); 614 } 615 /** 616 Minimum layer value of objects that are affected by the Light2D. 617 */ 618 @property long rangeLayerMin() 619 { 620 return getLayerRangeMin(); 621 } 622 /// ditto 623 @property void rangeLayerMin(long v) 624 { 625 setLayerRangeMin(v); 626 } 627 /** 628 Maximum `z` value of objects that are affected by the Light2D. 629 */ 630 @property long rangeZMax() 631 { 632 return getZRangeMax(); 633 } 634 /// ditto 635 @property void rangeZMax(long v) 636 { 637 setZRangeMax(v); 638 } 639 /** 640 Minimum `z` value of objects that are affected by the Light2D. 641 */ 642 @property long rangeZMin() 643 { 644 return getZRangeMin(); 645 } 646 /// ditto 647 @property void rangeZMin(long v) 648 { 649 setZRangeMin(v); 650 } 651 /** 652 Shadow buffer size. 653 */ 654 @property long shadowBufferSize() 655 { 656 return getShadowBufferSize(); 657 } 658 /// ditto 659 @property void shadowBufferSize(long v) 660 { 661 setShadowBufferSize(v); 662 } 663 /** 664 $(D Color) of shadows cast by the Light2D. 665 */ 666 @property Color shadowColor() 667 { 668 return getShadowColor(); 669 } 670 /// ditto 671 @property void shadowColor(Color v) 672 { 673 setShadowColor(v); 674 } 675 /** 676 If `true`, the Light2D will cast shadows. 677 */ 678 @property bool shadowEnabled() 679 { 680 return isShadowEnabled(); 681 } 682 /// ditto 683 @property void shadowEnabled(bool v) 684 { 685 setShadowEnabled(v); 686 } 687 /** 688 Shadow filter type. See $(D shadowfilter) for possible values. 689 */ 690 @property Light2D.ShadowFilter shadowFilter() 691 { 692 return getShadowFilter(); 693 } 694 /// ditto 695 @property void shadowFilter(long v) 696 { 697 setShadowFilter(v); 698 } 699 /** 700 Smoothing value for shadows. 701 */ 702 @property double shadowFilterSmooth() 703 { 704 return getShadowSmooth(); 705 } 706 /// ditto 707 @property void shadowFilterSmooth(double v) 708 { 709 setShadowSmooth(v); 710 } 711 /** 712 Smooth shadow gradient length. 713 */ 714 @property double shadowGradientLength() 715 { 716 return getShadowGradientLength(); 717 } 718 /// ditto 719 @property void shadowGradientLength(double v) 720 { 721 setShadowGradientLength(v); 722 } 723 /** 724 The shadow mask. Used with $(D LightOccluder2D) to cast shadows. Only occluders with a matching light mask will cast shadows. 725 */ 726 @property long shadowItemCullMask() 727 { 728 return getItemShadowCullMask(); 729 } 730 /// ditto 731 @property void shadowItemCullMask(long v) 732 { 733 setItemShadowCullMask(v); 734 } 735 /** 736 $(D Texture) used for the Light2D's appearance. 737 */ 738 @property Texture texture() 739 { 740 return getTexture(); 741 } 742 /// ditto 743 @property void texture(Texture v) 744 { 745 setTexture(v); 746 } 747 /** 748 The `texture`'s scale factor. 749 */ 750 @property double textureScale() 751 { 752 return getTextureScale(); 753 } 754 /// ditto 755 @property void textureScale(double v) 756 { 757 setTextureScale(v); 758 } 759 }