StaticSprite2D.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. void SetSprite(Sprite2D* sprite);
  40. /// Set draw rectangle.
  41. void SetDrawRect(const Rect &rect);
  42. /// Set texture rectangle.
  43. void SetTextureRect(const Rect &rect);
  44. /// Set blend mode.
  45. void SetBlendMode(BlendMode blendMode);
  46. /// Set flip.
  47. void SetFlip(bool flipX, bool flipY, bool swapXY = false);
  48. /// Set flip X.
  49. void SetFlipX(bool flipX);
  50. /// Set flip Y.
  51. void SetFlipY(bool flipY);
  52. /// Set swap X and Y.
  53. void SetSwapXY(bool swapXY);
  54. /// Set color.
  55. void SetColor(const Color& color);
  56. /// Set alpha.
  57. void SetAlpha(float alpha);
  58. /// Set whether to use custom-defined hot spot.
  59. void SetUseHotSpot(bool useHotSpot);
  60. /// Set whether to use custom-defined draw rectangle.
  61. void SetUseDrawRect(bool useDrawRect);
  62. /// Set whether to use custom-defined texture rectangle.
  63. void SetUseTextureRect(bool useTextureRect);
  64. /// Set hot spot.
  65. void SetHotSpot(const Vector2& hotspot);
  66. /// Set custom material.
  67. void SetCustomMaterial(Material* customMaterial);
  68. /// Return sprite.
  69. Sprite2D* GetSprite() const;
  70. /// Return draw rect.
  71. const Rect& GetDrawRect() const { return drawRect_; }
  72. /// Return texture rect.
  73. const Rect& GetTextureRect() const { return textureRect_; }
  74. /// Return blend mode.
  75. BlendMode GetBlendMode() const { return blendMode_; }
  76. /// Return flip X.
  77. bool GetFlipX() const { return flipX_; }
  78. /// Return flip Y.
  79. bool GetFlipY() const { return flipY_; }
  80. /// Return swap X and Y.
  81. bool GetSwapXY() const { return swapXY_; }
  82. /// Return color.
  83. const Color& GetColor() const { return color_; }
  84. /// Return alpha.
  85. float GetAlpha() const { return color_.a_; }
  86. /// Return whether to use custom-defined hot spot.
  87. bool GetUseHotSpot() const { return useHotSpot_; }
  88. /// Return whether to use custom-defined draw rectangle.
  89. bool GetUseDrawRect() const { return useDrawRect_; }
  90. /// Return whether to use custom-defined texture rectangle.
  91. bool GetUseTextureRect() const { return useTextureRect_; }
  92. /// Return hot spot.
  93. const Vector2& GetHotSpot() const { return hotSpot_; }
  94. /// Return custom material.
  95. Material* GetCustomMaterial() const;
  96. /// Set sprite attribute.
  97. void SetSpriteAttr(const ResourceRef& value);
  98. /// Return sprite attribute.
  99. ResourceRef GetSpriteAttr() const;
  100. /// Set custom material attribute.
  101. void SetCustomMaterialAttr(const ResourceRef& value);
  102. /// Return custom material attribute.
  103. ResourceRef GetCustomMaterialAttr() const;
  104. protected:
  105. /// Handle scene being assigned.
  106. void OnSceneSet(Scene* scene) override;
  107. /// Recalculate the world-space bounding box.
  108. void OnWorldBoundingBoxUpdate() override;
  109. /// Handle draw order changed.
  110. void OnDrawOrderChanged() override;
  111. /// Update source batches.
  112. void UpdateSourceBatches() override;
  113. /// Update material.
  114. void UpdateMaterial();
  115. /// Update drawRect.
  116. void UpdateDrawRect();
  117. /// Sprite.
  118. SharedPtr<Sprite2D> sprite_;
  119. /// Blend mode.
  120. BlendMode blendMode_;
  121. /// Flip X.
  122. bool flipX_;
  123. /// Flip Y.
  124. bool flipY_;
  125. /// Swap X and Y.
  126. bool swapXY_;
  127. /// Color.
  128. Color color_;
  129. /// Use hot spot flag.
  130. bool useHotSpot_;
  131. /// Use draw rectangle flag.
  132. bool useDrawRect_;
  133. /// Use texture rectangle flag.
  134. bool useTextureRect_;
  135. /// Hot spot.
  136. Vector2 hotSpot_;
  137. /// Draw rectangle.
  138. Rect drawRect_;
  139. /// Texture rectangle.
  140. Rect textureRect_;
  141. /// Custom material.
  142. SharedPtr<Material> customMaterial_;
  143. };
  144. }