RegionAttachment.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifndef Spine_RegionAttachment_h
  30. #define Spine_RegionAttachment_h
  31. #include <spine/Attachment.h>
  32. #include <spine/Vector.h>
  33. #include <spine/Color.h>
  34. #include <spine/HasRendererObject.h>
  35. #define NUM_UVS 8
  36. namespace spine {
  37. class Bone;
  38. /// Attachment that displays a texture region.
  39. class SP_API RegionAttachment : public Attachment, public HasRendererObject {
  40. friend class SkeletonBinary;
  41. friend class SkeletonJson;
  42. friend class AtlasAttachmentLoader;
  43. RTTI_DECL
  44. public:
  45. explicit RegionAttachment(const String& name);
  46. void updateOffset();
  47. void setUVs(float u, float v, float u2, float v2, bool rotate);
  48. /// Transforms the attachment's four vertices to world coordinates.
  49. /// @param bone The parent bone.
  50. /// @param worldVertices The output world vertices. Must have a length greater than or equal to offset + 8.
  51. /// @param offset The worldVertices index to begin writing values.
  52. /// @param stride The number of worldVertices entries between the value pairs written.
  53. void computeWorldVertices(Bone& bone, float *worldVertices, size_t offset, size_t stride = 2);
  54. void computeWorldVertices(Bone& bone, Vector<float>& worldVertices, size_t offset, size_t stride = 2);
  55. float getX();
  56. void setX(float inValue);
  57. float getY();
  58. void setY(float inValue);
  59. float getRotation();
  60. void setRotation(float inValue);
  61. float getScaleX();
  62. void setScaleX(float inValue);
  63. float getScaleY();
  64. void setScaleY(float inValue);
  65. float getWidth();
  66. void setWidth(float inValue);
  67. float getHeight();
  68. void setHeight(float inValue);
  69. Color& getColor();
  70. const String& getPath();
  71. void setPath(const String& inValue);
  72. float getRegionOffsetX();
  73. void setRegionOffsetX(float inValue);
  74. float getRegionOffsetY();
  75. void setRegionOffsetY(float inValue);
  76. float getRegionWidth();
  77. void setRegionWidth(float inValue);
  78. float getRegionHeight();
  79. void setRegionHeight(float inValue);
  80. float getRegionOriginalWidth();
  81. void setRegionOriginalWidth(float inValue);
  82. float getRegionOriginalHeight();
  83. void setRegionOriginalHeight(float inValue);
  84. Vector<float>& getOffset();
  85. Vector<float>& getUVs();
  86. virtual Attachment* copy();
  87. private:
  88. static const int BLX;
  89. static const int BLY;
  90. static const int ULX;
  91. static const int ULY;
  92. static const int URX;
  93. static const int URY;
  94. static const int BRX;
  95. static const int BRY;
  96. float _x, _y, _rotation, _scaleX, _scaleY, _width, _height;
  97. float _regionOffsetX, _regionOffsetY, _regionWidth, _regionHeight, _regionOriginalWidth, _regionOriginalHeight;
  98. Vector<float> _vertexOffset;
  99. Vector<float> _uvs;
  100. String _path;
  101. float _regionU;
  102. float _regionV;
  103. float _regionU2;
  104. float _regionV2;
  105. Color _color;
  106. };
  107. }
  108. #endif /* Spine_RegionAttachment_h */