BorderImage.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../GraphicsAPI/GraphicsDefs.h"
  5. #include "../UI/UIElement.h"
  6. namespace Urho3D
  7. {
  8. class Texture;
  9. class Texture2D;
  10. /// %Image %UI element with optional border.
  11. class URHO3D_API BorderImage : public UIElement
  12. {
  13. URHO3D_OBJECT(BorderImage, UIElement);
  14. public:
  15. /// Construct.
  16. explicit BorderImage(Context* context);
  17. /// Destruct.
  18. ~BorderImage() override;
  19. /// Register object factory.
  20. /// @nobind
  21. static void RegisterObject(Context* context);
  22. /// Return UI rendering batches.
  23. void GetBatches(Vector<UIBatch>& batches, Vector<float>& vertexData, const IntRect& currentScissor) override;
  24. /// Set texture.
  25. /// @property
  26. void SetTexture(Texture* texture);
  27. /// Set part of texture to use as the image.
  28. /// @property
  29. void SetImageRect(const IntRect& rect);
  30. /// Use whole texture as the image.
  31. void SetFullImageRect();
  32. /// Set border dimensions on the screen.
  33. /// @property
  34. void SetBorder(const IntRect& rect);
  35. /// Set border dimensions on the image. If zero (default) uses the screen dimensions, resulting in pixel-perfect borders.
  36. /// @property
  37. void SetImageBorder(const IntRect& rect);
  38. /// Set offset to image rectangle used on hover.
  39. /// @property
  40. void SetHoverOffset(const IntVector2& offset);
  41. /// Set offset to image rectangle used on hover.
  42. void SetHoverOffset(int x, int y);
  43. /// Set offset to image rectangle used when disabled.
  44. /// @property
  45. void SetDisabledOffset(const IntVector2& offset);
  46. /// Set offset to image rectangle used when disabled.
  47. void SetDisabledOffset(int x, int y);
  48. /// Set blend mode.
  49. /// @property
  50. void SetBlendMode(BlendMode mode);
  51. /// Set tiled mode.
  52. /// @property
  53. void SetTiled(bool enable);
  54. /// Set material for custom rendering.
  55. /// @property
  56. void SetMaterial(Material* material);
  57. /// Return texture.
  58. /// @property
  59. Texture* GetTexture() const { return texture_; }
  60. /// Return image rectangle.
  61. /// @property
  62. const IntRect& GetImageRect() const { return imageRect_; }
  63. /// Return border screen dimensions.
  64. /// @property
  65. const IntRect& GetBorder() const { return border_; }
  66. /// Return border image dimensions. Zero rect uses border screen dimensions.
  67. /// @property
  68. const IntRect& GetImageBorder() const { return imageBorder_; }
  69. /// Return offset to image rectangle used on hover.
  70. /// @property
  71. const IntVector2& GetHoverOffset() const { return hoverOffset_; }
  72. /// Return offset to image rectangle used when disabled.
  73. /// @property
  74. const IntVector2& GetDisabledOffset() const { return disabledOffset_; }
  75. /// Return blend mode.
  76. /// @property
  77. BlendMode GetBlendMode() const { return blendMode_; }
  78. /// Return whether is tiled.
  79. /// @property
  80. bool IsTiled() const { return tiled_; }
  81. /// Get material used for custom rendering.
  82. /// @property
  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. (Vector<UIBatch>& batches, Vector<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. }