UIImage.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // Copyright (c) 2008-2014 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 "Drawable2D.h"
  24. namespace Urho3D
  25. {
  26. class Sprite2D;
  27. class UIRect;
  28. /// UI image draw mode.
  29. enum UIDrawMode
  30. {
  31. UIDM_SIMPLE = 0,
  32. UIDM_TILED,
  33. UIDM_SLICED,
  34. UIDM_FILLED,
  35. };
  36. /// UI image fill type.
  37. enum UIFillType
  38. {
  39. UIFT_HORIZONTAL = 0,
  40. UIFT_VERTICAL,
  41. UIFT_RADIAL,
  42. };
  43. /// UI drawable component.
  44. class URHO3D_API UIImage : public Drawable2D
  45. {
  46. OBJECT(UIImage);
  47. public:
  48. /// Construct.
  49. UIImage(Context* scontext);
  50. /// Destruct.
  51. virtual ~UIImage();
  52. /// Register object factory.
  53. static void RegisterObject(Context* context);
  54. /// Set sprite.
  55. void SetSprite(Sprite2D* sprite);
  56. /// Set color.
  57. void SetColor(const Color& color);
  58. /// Set draw mode.
  59. void SetDrawMode(UIDrawMode mode);
  60. /// Set horizontal slice size (for sliced mode).
  61. void SetHorizontalSliceSize(int size);
  62. /// Set vertical slice size (for sliced mode).
  63. void SetVerticalSliceSize(int size);
  64. /// Set fill type (for fill mode).
  65. void SetFillType(UIFillType fillType);
  66. /// Set fill amount (for fill mode).
  67. void SetFillAmount(float amount);
  68. /// Set Fill inverse (for fill mode).
  69. void SetFillInverse(bool inverse);
  70. /// Return sprite.
  71. Sprite2D* GetSprite() const;
  72. /// Return color.
  73. const Color& GetColor() const { return color_; }
  74. /// Return draw mode.
  75. UIDrawMode GetDrawMode() const { return drawMode_; }
  76. /// Return horizontal slice size (for sliced mode).
  77. int GetHorizontalSliceSize() const { return horizontalSliceSize_;}
  78. /// Return vertical slice size (for sliced mode).
  79. int GetVerticalSliceSize() const { return verticalSliceSize_;}
  80. /// Return fill type (for filled mode).
  81. UIFillType GetFillType() const { return fillType_; }
  82. /// Return fill amount (for fill mode).
  83. float GetFillAmount() const { return fillAmount_; }
  84. /// Return is fill inverse (for fill mode).
  85. bool IsFillInverse() const { return fillInverse_; }
  86. /// Set sprite attribute.
  87. void SetSpriteAttr(const ResourceRef& value);
  88. /// Return sprite attribute.
  89. ResourceRef GetSpriteAttr() const;
  90. private:
  91. /// Handle node being assigned.
  92. virtual void OnNodeSet(Node* node);
  93. /// Recalculate the world-space bounding box.
  94. virtual void OnWorldBoundingBoxUpdate();
  95. /// Update vertices.
  96. virtual void UpdateVertices();
  97. /// Update vertices simple mode.
  98. void UpdateVerticesSimpleMode();
  99. /// Update vertices tiled mode.
  100. void UpdateVerticesTiledMode();
  101. /// Update vertices sliced mode.
  102. void UpdateVerticesSlicedMode();
  103. /// Update vertices filled mode.
  104. void UpdateVerticesFilledMode();
  105. /// Update vertices filled mode radial.
  106. void UpdateVerticesFilledModeRadial();
  107. /// Return sprite texture coords.
  108. void GetSpriteTextureCoords(float& left, float& right, float& top, float& bottom) const;
  109. /// Add quad.
  110. void AddQuad(float left, float right, float top, float bottom, float uLeft, float uRight, float vTop, float vBottom);
  111. /// handle rect changed.
  112. void HandleRectDirtied(StringHash eventType, VariantMap& eventData);
  113. /// UIRect
  114. WeakPtr<UIRect> uiRect_;
  115. /// Sprite.
  116. SharedPtr<Sprite2D> sprite_;
  117. /// Color.
  118. Color color_;
  119. /// Draw mode.
  120. UIDrawMode drawMode_;
  121. /// X slice size.
  122. int horizontalSliceSize_;
  123. /// Y slice size.
  124. int verticalSliceSize_;
  125. /// Fill type.
  126. UIFillType fillType_;
  127. /// Fill amount.
  128. float fillAmount_;
  129. /// Fill inverse.
  130. bool fillInverse_;
  131. };
  132. }