StaticSprite2D.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Urho2D/Drawable2D.h"
  24. namespace Urho3D
  25. {
  26. class Sprite2D;
  27. /// Static sprite component.
  28. class URHO3D_API StaticSprite2D : public Drawable2D
  29. {
  30. URHO3D_OBJECT(StaticSprite2D, Drawable2D);
  31. public:
  32. /// Construct.
  33. explicit StaticSprite2D(Context* context);
  34. /// Destruct.
  35. ~StaticSprite2D() override;
  36. /// Register object factory. Drawable2D must be registered first.
  37. static void RegisterObject(Context* context);
  38. /// Set sprite.
  39. /// @property
  40. void SetSprite(Sprite2D* sprite);
  41. /// Set draw rectangle.
  42. /// @property
  43. void SetDrawRect(const Rect &rect);
  44. /// Set texture rectangle.
  45. /// @property
  46. void SetTextureRect(const Rect &rect);
  47. /// Set blend mode.
  48. /// @property
  49. void SetBlendMode(BlendMode blendMode);
  50. /// Set flip.
  51. void SetFlip(bool flipX, bool flipY, bool swapXY = false);
  52. /// Set flip X.
  53. /// @property
  54. void SetFlipX(bool flipX);
  55. /// Set flip Y.
  56. /// @property
  57. void SetFlipY(bool flipY);
  58. /// Set swap X and Y.
  59. /// @property
  60. void SetSwapXY(bool swapXY);
  61. /// Set color.
  62. /// @property
  63. void SetColor(const Color& color);
  64. /// Set alpha.
  65. /// @property
  66. void SetAlpha(float alpha);
  67. /// Set whether to use custom-defined hot spot.
  68. /// @property
  69. void SetUseHotSpot(bool useHotSpot);
  70. /// Set whether to use custom-defined draw rectangle.
  71. /// @property
  72. void SetUseDrawRect(bool useDrawRect);
  73. /// Set whether to use custom-defined texture rectangle.
  74. /// @property
  75. void SetUseTextureRect(bool useTextureRect);
  76. /// Set hot spot.
  77. /// @property
  78. void SetHotSpot(const Vector2& hotspot);
  79. /// Set custom material.
  80. /// @property
  81. void SetCustomMaterial(Material* customMaterial);
  82. /// Return sprite.
  83. /// @property
  84. Sprite2D* GetSprite() const;
  85. /// Return draw rect.
  86. /// @property
  87. const Rect& GetDrawRect() const { return drawRect_; }
  88. /// Return texture rect.
  89. /// @property
  90. const Rect& GetTextureRect() const { return textureRect_; }
  91. /// Return blend mode.
  92. /// @property
  93. BlendMode GetBlendMode() const { return blendMode_; }
  94. /// Return flip X.
  95. /// @property
  96. bool GetFlipX() const { return flipX_; }
  97. /// Return flip Y.
  98. /// @property
  99. bool GetFlipY() const { return flipY_; }
  100. /// Return swap X and Y.
  101. /// @property
  102. bool GetSwapXY() const { return swapXY_; }
  103. /// Return color.
  104. /// @property
  105. const Color& GetColor() const { return color_; }
  106. /// Return alpha.
  107. /// @property
  108. float GetAlpha() const { return color_.a_; }
  109. /// Return whether to use custom-defined hot spot.
  110. /// @property
  111. bool GetUseHotSpot() const { return useHotSpot_; }
  112. /// Return whether to use custom-defined draw rectangle.
  113. /// @property
  114. bool GetUseDrawRect() const { return useDrawRect_; }
  115. /// Return whether to use custom-defined texture rectangle.
  116. /// @property
  117. bool GetUseTextureRect() const { return useTextureRect_; }
  118. /// Return hot spot.
  119. /// @property
  120. const Vector2& GetHotSpot() const { return hotSpot_; }
  121. /// Return custom material.
  122. /// @property
  123. Material* GetCustomMaterial() const;
  124. /// Set sprite attribute.
  125. void SetSpriteAttr(const ResourceRef& value);
  126. /// Return sprite attribute.
  127. ResourceRef GetSpriteAttr() const;
  128. /// Set custom material attribute.
  129. void SetCustomMaterialAttr(const ResourceRef& value);
  130. /// Return custom material attribute.
  131. ResourceRef GetCustomMaterialAttr() const;
  132. protected:
  133. /// Handle scene being assigned.
  134. void OnSceneSet(Scene* scene) override;
  135. /// Recalculate the world-space bounding box.
  136. void OnWorldBoundingBoxUpdate() override;
  137. /// Handle draw order changed.
  138. void OnDrawOrderChanged() override;
  139. /// Update source batches.
  140. void UpdateSourceBatches() override;
  141. /// Update material.
  142. void UpdateMaterial();
  143. /// Update drawRect.
  144. void UpdateDrawRect();
  145. /// Sprite.
  146. SharedPtr<Sprite2D> sprite_;
  147. /// Blend mode.
  148. BlendMode blendMode_;
  149. /// Flip X.
  150. bool flipX_;
  151. /// Flip Y.
  152. bool flipY_;
  153. /// Swap X and Y.
  154. bool swapXY_;
  155. /// Color.
  156. Color color_;
  157. /// Use hot spot flag.
  158. bool useHotSpot_;
  159. /// Use draw rectangle flag.
  160. bool useDrawRect_;
  161. /// Use texture rectangle flag.
  162. bool useTextureRect_;
  163. /// Hot spot.
  164. Vector2 hotSpot_;
  165. /// Draw rectangle.
  166. Rect drawRect_;
  167. /// Texture rectangle.
  168. Rect textureRect_;
  169. /// Custom material.
  170. SharedPtr<Material> customMaterial_;
  171. };
  172. }