StaticSprite2D.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //
  2. // Copyright (c) 2008-2017 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 "../Atomic2D/Drawable2D.h"
  24. namespace Atomic
  25. {
  26. class Sprite2D;
  27. /// Static sprite component.
  28. class ATOMIC_API StaticSprite2D : public Drawable2D
  29. {
  30. ATOMIC_OBJECT(StaticSprite2D, Drawable2D);
  31. public:
  32. /// Construct.
  33. StaticSprite2D(Context* context);
  34. /// Destruct.
  35. ~StaticSprite2D();
  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);
  48. /// Set flip X.
  49. void SetFlipX(bool flipX);
  50. /// Set flip Y.
  51. void SetFlipY(bool flipY);
  52. /// Set color.
  53. void SetColor(const Color& color);
  54. /// Set alpha.
  55. void SetAlpha(float alpha);
  56. /// Set whether to use custom-defined hot spot.
  57. void SetUseHotSpot(bool useHotSpot);
  58. /// Set whether to use custom-defined draw rectangle.
  59. void SetUseDrawRect(bool useDrawRect);
  60. /// Set whether to use custom-defined texture rectangle.
  61. void SetUseTextureRect(bool useTextureRect);
  62. /// Set hot spot.
  63. void SetHotSpot(const Vector2& hotspot);
  64. /// Set custom material.
  65. void SetCustomMaterial(Material* customMaterial);
  66. /// Return sprite.
  67. Sprite2D* GetSprite() const;
  68. /// Return draw rect.
  69. const Rect& GetDrawRect() const { return drawRect_; }
  70. /// Return texture rect.
  71. const Rect& GetTextureRect() const { return textureRect_; }
  72. /// Return blend mode.
  73. BlendMode GetBlendMode() const { return blendMode_; }
  74. /// Return flip X.
  75. bool GetFlipX() const { return flipX_; }
  76. /// Return flip Y.
  77. bool GetFlipY() const { return flipY_; }
  78. /// Return color.
  79. const Color& GetColor() const { return color_; }
  80. /// Return alpha.
  81. float GetAlpha() const { return color_.a_; }
  82. /// Return whether to use custom-defined hot spot.
  83. bool GetUseHotSpot() const { return useHotSpot_; }
  84. /// Return whether to use custom-defined draw rectangle.
  85. bool GetUseDrawRect() const { return useDrawRect_; }
  86. /// Return whether to use custom-defined texture rectangle.
  87. bool GetUseTextureRect() const { return useTextureRect_; }
  88. /// Return hot spot.
  89. const Vector2& GetHotSpot() const { return hotSpot_; }
  90. /// Return custom material.
  91. Material* GetCustomMaterial() const;
  92. /// Set sprite attribute.
  93. void SetSpriteAttr(const ResourceRef& value);
  94. /// Return sprite attribute.
  95. ResourceRef GetSpriteAttr() const;
  96. /// Set custom material attribute.
  97. void SetCustomMaterialAttr(const ResourceRef& value);
  98. /// Return custom material attribute.
  99. ResourceRef GetCustomMaterialAttr() const;
  100. protected:
  101. /// Handle scene being assigned.
  102. virtual void OnSceneSet(Scene* scene);
  103. /// Recalculate the world-space bounding box.
  104. virtual void OnWorldBoundingBoxUpdate();
  105. /// Handle draw order changed.
  106. virtual void OnDrawOrderChanged();
  107. /// Update source batches.
  108. virtual void UpdateSourceBatches();
  109. /// Update material.
  110. void UpdateMaterial();
  111. /// Update drawRect.
  112. void UpdateDrawRect();
  113. /// Sprite.
  114. SharedPtr<Sprite2D> sprite_;
  115. /// Blend mode.
  116. BlendMode blendMode_;
  117. /// Flip X.
  118. bool flipX_;
  119. /// Flip Y.
  120. bool flipY_;
  121. /// Color.
  122. Color color_;
  123. /// Use hot spot flag.
  124. bool useHotSpot_;
  125. /// Use draw rectangle flag.
  126. bool useDrawRect_;
  127. /// Use texture rectangle flag.
  128. bool useTextureRect_;
  129. /// Hot spot.
  130. Vector2 hotSpot_;
  131. /// Draw rectangle.
  132. Rect drawRect_;
  133. /// Texture rectangle.
  134. Rect textureRect_;
  135. /// Custom material.
  136. SharedPtr<Material> customMaterial_;
  137. };
  138. }