BorderImage.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. void SetTexture(Texture* texture);
  44. /// Set part of texture to use as the image.
  45. void SetImageRect(const IntRect& rect);
  46. /// Use whole texture as the image.
  47. void SetFullImageRect();
  48. /// Set border dimensions on the screen.
  49. void SetBorder(const IntRect& rect);
  50. /// Set border dimensions on the image. If zero (default) uses the screen dimensions, resulting in pixel-perfect borders.
  51. void SetImageBorder(const IntRect& rect);
  52. /// Set offset to image rectangle used on hover.
  53. void SetHoverOffset(const IntVector2& offset);
  54. /// Set offset to image rectangle used on hover.
  55. void SetHoverOffset(int x, int y);
  56. /// Set offset to image rectangle used when disabled.
  57. void SetDisabledOffset(const IntVector2& offset);
  58. /// Set offset to image rectangle used when disabled.
  59. void SetDisabledOffset(int x, int y);
  60. /// Set blend mode.
  61. void SetBlendMode(BlendMode mode);
  62. /// Set tiled mode.
  63. void SetTiled(bool enable);
  64. /// Set material for custom rendering.
  65. void SetMaterial(Material* material);
  66. /// Return texture.
  67. Texture* GetTexture() const { return texture_; }
  68. /// Return image rectangle.
  69. const IntRect& GetImageRect() const { return imageRect_; }
  70. /// Return border screen dimensions.
  71. const IntRect& GetBorder() const { return border_; }
  72. /// Return border image dimensions. Zero rect uses border screen dimensions.
  73. const IntRect& GetImageBorder() const { return imageBorder_; }
  74. /// Return offset to image rectangle used on hover.
  75. const IntVector2& GetHoverOffset() const { return hoverOffset_; }
  76. /// Return offset to image rectangle used when disabled.
  77. const IntVector2& GetDisabledOffset() const { return disabledOffset_; }
  78. /// Return blend mode.
  79. BlendMode GetBlendMode() const { return blendMode_; }
  80. /// Return whether is tiled.
  81. bool IsTiled() const { return tiled_; }
  82. /// Get material used for custom rendering.
  83. Material* GetMaterial() const;
  84. /// Set texture attribute.
  85. void SetTextureAttr(const ResourceRef& value);
  86. /// Return texture attribute.
  87. ResourceRef GetTextureAttr() const;
  88. /// Set material attribute.
  89. void SetMaterialAttr(const ResourceRef& value);
  90. /// Get material attribute.
  91. ResourceRef GetMaterialAttr() const;
  92. protected:
  93. /// Return UI rendering batches with offset to image rectangle.
  94. void GetBatches
  95. (PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor, const IntVector2& offset);
  96. /// Texture.
  97. SharedPtr<Texture> texture_;
  98. /// Image rectangle.
  99. IntRect imageRect_;
  100. /// Border dimensions on screen.
  101. IntRect border_;
  102. /// Border dimensions on the image.
  103. IntRect imageBorder_;
  104. /// Offset to image rectangle on hover.
  105. IntVector2 hoverOffset_;
  106. /// Offset to image rectangle when disabled.
  107. IntVector2 disabledOffset_;
  108. /// Blend mode flag.
  109. BlendMode blendMode_;
  110. /// Tiled flag.
  111. bool tiled_;
  112. /// Material used for custom rendering.
  113. SharedPtr<Material> material_;
  114. };
  115. }