BorderImage.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Oorni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "UIElement.h"
  25. namespace Urho3D
  26. {
  27. class Texture;
  28. class Texture2D;
  29. /// %Image %UI element with optional border.
  30. class 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<UIQuad>& quads, const IntRect& currentScissor);
  42. /// Set textures.
  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 image border dimensions.
  49. void SetBorder(const IntRect& rect);
  50. /// Set offset to image rectangle used on hover.
  51. void SetHoverOffset(const IntVector2& offset);
  52. /// Set offset to image rectangle used on hover.
  53. void SetHoverOffset(int x, int y);
  54. /// Set tiled.
  55. void SetTiled(bool enable);
  56. /// Return whether is tiled.
  57. bool IsTiled() const { return tiled_; }
  58. /// Return texture.
  59. Texture* GetTexture() const { return texture_; }
  60. /// Return image rectangle.
  61. const IntRect& GetImageRect() const { return imageRect_; }
  62. /// Return image border dimensions.
  63. const IntRect& GetBorder() const { return border_; }
  64. /// Return offset to image rectangle used on hover.
  65. const IntVector2& GetHoverOffset() const { return hoverOffset_; }
  66. /// Set texture attribute.
  67. void SetTextureAttr(ResourceRef value);
  68. /// Return texture attribute.
  69. ResourceRef GetTextureAttr() const;
  70. protected:
  71. /// Return UI rendering batches with offset to image rectangle.
  72. void GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor, const IntVector2& offset);
  73. /// Texture.
  74. SharedPtr<Texture> texture_;
  75. /// Image rectangle.
  76. IntRect imageRect_;
  77. /// Image border dimensions.
  78. IntRect border_;
  79. /// Offset to image rectangle on hover.
  80. IntVector2 hoverOffset_;
  81. /// Tiled flag.
  82. bool tiled_;
  83. };
  84. }