BorderImage.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "../Graphics/GraphicsDefs.h"
  24. #include "../UI/UIElement.h"
  25. namespace Urho3D
  26. {
  27. class Texture;
  28. class Texture2D;
  29. /// %Image %UI element with optional border.
  30. class URHO3D_API BorderImage : public UIElement
  31. {
  32. URHO3D_OBJECT(BorderImage, UIElement);
  33. public:
  34. /// Construct.
  35. explicit BorderImage(Context* context);
  36. /// Destruct.
  37. ~BorderImage() override;
  38. /// Register object factory.
  39. static void RegisterObject(Context* context);
  40. /// Return UI rendering batches.
  41. void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor) override;
  42. /// Set texture.
  43. /// @property
  44. void SetTexture(Texture* texture);
  45. /// Set part of texture to use as the image.
  46. /// @property
  47. void SetImageRect(const IntRect& rect);
  48. /// Use whole texture as the image.
  49. void SetFullImageRect();
  50. /// Set border dimensions on the screen.
  51. /// @property
  52. void SetBorder(const IntRect& rect);
  53. /// Set border dimensions on the image. If zero (default) uses the screen dimensions, resulting in pixel-perfect borders.
  54. /// @property
  55. void SetImageBorder(const IntRect& rect);
  56. /// Set offset to image rectangle used on hover.
  57. /// @property
  58. void SetHoverOffset(const IntVector2& offset);
  59. /// Set offset to image rectangle used on hover.
  60. void SetHoverOffset(int x, int y);
  61. /// Set offset to image rectangle used when disabled.
  62. /// @property
  63. void SetDisabledOffset(const IntVector2& offset);
  64. /// Set offset to image rectangle used when disabled.
  65. void SetDisabledOffset(int x, int y);
  66. /// Set blend mode.
  67. /// @property
  68. void SetBlendMode(BlendMode mode);
  69. /// Set tiled mode.
  70. /// @property
  71. void SetTiled(bool enable);
  72. /// Set material for custom rendering.
  73. /// @property
  74. void SetMaterial(Material* material);
  75. /// Return texture.
  76. /// @property
  77. Texture* GetTexture() const { return texture_; }
  78. /// Return image rectangle.
  79. /// @property
  80. const IntRect& GetImageRect() const { return imageRect_; }
  81. /// Return border screen dimensions.
  82. /// @property
  83. const IntRect& GetBorder() const { return border_; }
  84. /// Return border image dimensions. Zero rect uses border screen dimensions.
  85. /// @property
  86. const IntRect& GetImageBorder() const { return imageBorder_; }
  87. /// Return offset to image rectangle used on hover.
  88. /// @property
  89. const IntVector2& GetHoverOffset() const { return hoverOffset_; }
  90. /// Return offset to image rectangle used when disabled.
  91. /// @property
  92. const IntVector2& GetDisabledOffset() const { return disabledOffset_; }
  93. /// Return blend mode.
  94. /// @property
  95. BlendMode GetBlendMode() const { return blendMode_; }
  96. /// Return whether is tiled.
  97. /// @property
  98. bool IsTiled() const { return tiled_; }
  99. /// Get material used for custom rendering.
  100. /// @property
  101. Material* GetMaterial() const;
  102. /// Set texture attribute.
  103. void SetTextureAttr(const ResourceRef& value);
  104. /// Return texture attribute.
  105. ResourceRef GetTextureAttr() const;
  106. /// Set material attribute.
  107. void SetMaterialAttr(const ResourceRef& value);
  108. /// Get material attribute.
  109. ResourceRef GetMaterialAttr() const;
  110. protected:
  111. /// Return UI rendering batches with offset to image rectangle.
  112. void GetBatches
  113. (PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor, const IntVector2& offset);
  114. /// Texture.
  115. SharedPtr<Texture> texture_;
  116. /// Image rectangle.
  117. IntRect imageRect_;
  118. /// Border dimensions on screen.
  119. IntRect border_;
  120. /// Border dimensions on the image.
  121. IntRect imageBorder_;
  122. /// Offset to image rectangle on hover.
  123. IntVector2 hoverOffset_;
  124. /// Offset to image rectangle when disabled.
  125. IntVector2 disabledOffset_;
  126. /// Blend mode flag.
  127. BlendMode blendMode_;
  128. /// Tiled flag.
  129. bool tiled_;
  130. /// Material used for custom rendering.
  131. SharedPtr<Material> material_;
  132. };
  133. }