BorderImage.h 3.6 KB

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