BorderImage.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // Copyright (c) 2008-2015 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 "UIElement.h"
  25. namespace Atomic
  26. {
  27. class Texture;
  28. class Texture2D;
  29. namespace SystemUI
  30. {
  31. /// %Image %UI element with optional border.
  32. class ATOMIC_API BorderImage : public UIElement
  33. {
  34. OBJECT(BorderImage);
  35. public:
  36. /// Construct.
  37. BorderImage(Context* context);
  38. /// Destruct.
  39. virtual ~BorderImage();
  40. /// Register object factory.
  41. static void RegisterObject(Context* context);
  42. /// Return UI rendering batches.
  43. virtual void GetBatches(PODVector<SystemUIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
  44. /// Set texture.
  45. void SetTexture(Texture* texture);
  46. /// Set part of texture to use as the image.
  47. void SetImageRect(const IntRect& rect);
  48. /// Use whole texture as the image.
  49. void SetFullImageRect();
  50. /// Set border dimensions on the screen.
  51. void SetBorder(const IntRect& rect);
  52. /// Set border dimensions on the image. If zero (default) uses the screen dimensions, resulting in pixel-perfect borders.
  53. void SetImageBorder(const IntRect& rect);
  54. /// Set offset to image rectangle used on hover.
  55. void SetHoverOffset(const IntVector2& offset);
  56. /// Set offset to image rectangle used on hover.
  57. void SetHoverOffset(int x, int y);
  58. /// Set blend mode.
  59. void SetBlendMode(BlendMode mode);
  60. /// Set tiled mode.
  61. void SetTiled(bool enable);
  62. /// Return texture.
  63. Texture* GetTexture() const { return texture_; }
  64. /// Return image rectangle.
  65. const IntRect& GetImageRect() const { return imageRect_; }
  66. /// Return border screen dimensions.
  67. const IntRect& GetBorder() const { return border_; }
  68. /// Return border image dimensions. Zero rect uses border screen dimensions.
  69. const IntRect& GetImageBorder() const { return imageBorder_; }
  70. /// Return offset to image rectangle used on hover.
  71. const IntVector2& GetHoverOffset() const { return hoverOffset_; }
  72. /// Return blend mode.
  73. BlendMode GetBlendMode() const { return blendMode_; }
  74. /// Return whether is tiled.
  75. bool IsTiled() const { return tiled_; }
  76. /// Set texture attribute.
  77. void SetTextureAttr(const ResourceRef& value);
  78. /// Return texture attribute.
  79. ResourceRef GetTextureAttr() const;
  80. protected:
  81. /// Return UI rendering batches with offset to image rectangle.
  82. void GetBatches
  83. (PODVector<SystemUIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor, const IntVector2& offset);
  84. /// Texture.
  85. SharedPtr<Texture> texture_;
  86. /// Image rectangle.
  87. IntRect imageRect_;
  88. /// Border dimensions on screen.
  89. IntRect border_;
  90. /// Border dimensions on the image.
  91. IntRect imageBorder_;
  92. /// Offset to image rectangle on hover.
  93. IntVector2 hoverOffset_;
  94. /// Blend mode flag.
  95. BlendMode blendMode_;
  96. /// Tiled flag.
  97. bool tiled_;
  98. };
  99. }
  100. }