StaticSprite2D.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright (c) 2008-2015 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. OBJECT(StaticSprite2D);
  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 blend mode.
  41. void SetBlendMode(BlendMode blendMode);
  42. /// Set flip.
  43. void SetFlip(bool flipX, bool flipY);
  44. /// Set flip X.
  45. void SetFlipX(bool flipX);
  46. /// Set flip Y.
  47. void SetFlipY(bool flipY);
  48. /// Set color.
  49. void SetColor(const Color& color);
  50. /// Set alpha.
  51. void SetAlpha(float alpha);
  52. /// Set use hot spot.
  53. void SetUseHotSpot(bool useHotSpot);
  54. /// Set hot spot.
  55. void SetHotSpot(const Vector2& hotspot);
  56. /// Set custom material.
  57. void SetCustomMaterial(Material* customMaterial);
  58. /// Return sprite.
  59. Sprite2D* GetSprite() const;
  60. /// Return blend mode.
  61. BlendMode GetBlendMode() const { return blendMode_; }
  62. /// Return flip X.
  63. bool GetFlipX() const { return flipX_; }
  64. /// Return flip Y.
  65. bool GetFlipY() const { return flipY_; }
  66. /// Return color.
  67. const Color& GetColor() const { return color_; }
  68. /// Return alpha.
  69. float GetAlpha() const { return color_.a_; }
  70. /// Return use hot spot.
  71. bool GetUseHotSpot() const { return useHotSpot_; }
  72. /// Return hot spot.
  73. const Vector2& GetHotSpot() const { return hotSpot_; }
  74. /// Return custom material.
  75. Material* GetCustomMaterial() const;
  76. /// Set sprite attribute.
  77. void SetSpriteAttr(const ResourceRef& value);
  78. /// Return sprite attribute.
  79. ResourceRef GetSpriteAttr() const;
  80. /// Set custom material attribute.
  81. void SetCustomMaterialAttr(const ResourceRef& value);
  82. /// Return custom material attribute.
  83. ResourceRef GetCustomMaterialAttr() const;
  84. protected:
  85. /// Recalculate the world-space bounding box.
  86. virtual void OnWorldBoundingBoxUpdate();
  87. /// Handle draw order changed.
  88. virtual void OnDrawOrderChanged();
  89. /// Update source batches.
  90. virtual void UpdateSourceBatches();
  91. /// Handle flip changed.
  92. virtual void OnFlipChanged();
  93. /// Update material.
  94. void UpdateMaterial();
  95. /// Sprite.
  96. SharedPtr<Sprite2D> sprite_;
  97. /// Blend mode.
  98. BlendMode blendMode_;
  99. /// Flip X.
  100. bool flipX_;
  101. /// Flip Y.
  102. bool flipY_;
  103. /// Color.
  104. Color color_;
  105. /// Use hot spot.
  106. bool useHotSpot_;
  107. /// Hot spot.
  108. Vector2 hotSpot_;
  109. /// Custom material.
  110. SharedPtr<Material> customMaterial_;
  111. };
  112. }