BorderImage.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "GraphicsDefs.h"
  24. #include "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. OBJECT(BorderImage);
  33. public:
  34. /// Construct.
  35. BorderImage(Context* context);
  36. /// Destruct.
  37. virtual ~BorderImage();
  38. /// Register object factory.
  39. static void RegisterObject(Context* context);
  40. /// Return UI rendering batches.
  41. virtual void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
  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 blend mode.
  57. void SetBlendMode(BlendMode mode);
  58. /// Set tiled mode.
  59. void SetTiled(bool enable);
  60. /// Return texture.
  61. Texture* GetTexture() const { return texture_; }
  62. /// Return image rectangle.
  63. const IntRect& GetImageRect() const { return imageRect_; }
  64. /// Return border screen dimensions.
  65. const IntRect& GetBorder() const { return border_; }
  66. /// Return border image dimensions. Zero rect uses border screen dimensions.
  67. const IntRect& GetImageBorder() const { return imageBorder_; }
  68. /// Return offset to image rectangle used on hover.
  69. const IntVector2& GetHoverOffset() const { return hoverOffset_; }
  70. /// Return blend mode.
  71. BlendMode GetBlendMode() const { return blendMode_; }
  72. /// Return whether is tiled.
  73. bool IsTiled() const { return tiled_; }
  74. /// Set texture attribute.
  75. void SetTextureAttr(const ResourceRef& value);
  76. /// Return texture attribute.
  77. ResourceRef GetTextureAttr() const;
  78. protected:
  79. /// Return UI rendering batches with offset to image rectangle.
  80. void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor, const IntVector2& offset);
  81. /// Texture.
  82. SharedPtr<Texture> texture_;
  83. /// Image rectangle.
  84. IntRect imageRect_;
  85. /// Border dimensions on screen.
  86. IntRect border_;
  87. /// Border dimensions on the image.
  88. IntRect imageBorder_;
  89. /// Offset to image rectangle on hover.
  90. IntVector2 hoverOffset_;
  91. /// Blend mode flag.
  92. BlendMode blendMode_;
  93. /// Tiled flag.
  94. bool tiled_;
  95. };
  96. }