BorderImage.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  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. #ifndef UI_BORDERIMAGE_H
  24. #define UI_BORDERIMAGE_H
  25. #include "UIElement.h"
  26. class Texture;
  27. class Texture2D;
  28. //! An image UI element with optional border
  29. class BorderImage : public UIElement
  30. {
  31. DEFINE_TYPE(BorderImage);
  32. public:
  33. //! Construct with name
  34. BorderImage(const std::string& name = std::string());
  35. //! Destruct
  36. virtual ~BorderImage();
  37. //! Set UI element style from XML data
  38. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  39. //! Return UI rendering batches
  40. virtual void getBatches(std::vector<UIBatch>& batches, std::vector<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. //! Set part of texture to use as the image
  46. void setImageRect(int left, int top, int right, int bottom);
  47. //! Use whole texture as the image
  48. void setFullImageRect();
  49. //! Set image border dimensions
  50. void setBorder(const IntRect& rect);
  51. //! Set image border dimensions
  52. void setBorder(int left, int top, int right, int bottom);
  53. //! Set offset to image rectangle used on hover
  54. void setHoverOffset(const IntVector2& offset);
  55. //! Set offset to image rectangle used on hover
  56. void setHoverOffset(int x, int y);
  57. //! Return texture
  58. Texture* getTexture() const { return mTexture; }
  59. //! Return image rectangle
  60. const IntRect& getImageRect() const { return mImageRect; }
  61. //! Return image border dimensions
  62. const IntRect& getBorder() const { return mBorder; }
  63. //! Return offset to image rectangle used on hover
  64. const IntVector2& getHoverOffset() const { return mHoverOffset; }
  65. protected:
  66. //! Return UI rendering batches with offset to image rectangle
  67. void getBatches(std::vector<UIBatch>& batches, std::vector<UIQuad>& quads, const IntRect& currentScissor, const IntVector2& offset);
  68. //! Texture
  69. SharedPtr<Texture> mTexture;
  70. //! Image rectangle
  71. IntRect mImageRect;
  72. //! Image border dimensions
  73. IntRect mBorder;
  74. //! Offset to image rectangle on hover
  75. IntVector2 mHoverOffset;
  76. };
  77. #endif // UI_BORDERIMAGE_H