PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lluiimage.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 124 lines | 74 code | 22 blank | 28 comment | 0 complexity | ad77bf428f0b4397f8f460af698fc27f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lluiimage.h
  3. * @brief wrapper for images used in the UI that handles smart scaling, etc.
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLUIIMAGE_H
  27. #define LL_LLUIIMAGE_H
  28. #include "v4color.h"
  29. #include "llpointer.h"
  30. #include "llrefcount.h"
  31. #include "llrefcount.h"
  32. #include "llrect.h"
  33. #include <boost/function.hpp>
  34. #include <boost/signals2.hpp>
  35. #include "llinitparam.h"
  36. #include "lltexture.h"
  37. extern const LLColor4 UI_VERTEX_COLOR;
  38. class LLUIImage : public LLRefCount
  39. {
  40. public:
  41. typedef boost::signals2::signal<void (void)> image_loaded_signal_t;
  42. LLUIImage(const std::string& name, LLPointer<LLTexture> image);
  43. virtual ~LLUIImage();
  44. void setClipRegion(const LLRectf& region);
  45. void setScaleRegion(const LLRectf& region);
  46. LLPointer<LLTexture> getImage() { return mImage; }
  47. const LLPointer<LLTexture>& getImage() const { return mImage; }
  48. void draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color = UI_VERTEX_COLOR) const;
  49. void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const;
  50. void draw(const LLRect& rect, const LLColor4& color = UI_VERTEX_COLOR) const { draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
  51. void drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const;
  52. void drawSolid(const LLRect& rect, const LLColor4& color) const { drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color); }
  53. void drawSolid(S32 x, S32 y, const LLColor4& color) const { drawSolid(x, y, getWidth(), getHeight(), color); }
  54. void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const;
  55. void drawBorder(const LLRect& rect, const LLColor4& color, S32 border_width) const { drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(), color, border_width); }
  56. void drawBorder(S32 x, S32 y, const LLColor4& color, S32 border_width) const { drawBorder(x, y, getWidth(), getHeight(), color, border_width); }
  57. const std::string& getName() const { return mName; }
  58. virtual S32 getWidth() const;
  59. virtual S32 getHeight() const;
  60. // returns dimensions of underlying textures, which might not be equal to ui image portion
  61. S32 getTextureWidth() const;
  62. S32 getTextureHeight() const;
  63. boost::signals2::connection addLoadedCallback( const image_loaded_signal_t::slot_type& cb );
  64. void onImageLoaded();
  65. protected:
  66. image_loaded_signal_t* mImageLoaded;
  67. std::string mName;
  68. LLRectf mScaleRegion;
  69. LLRectf mClipRegion;
  70. LLPointer<LLTexture> mImage;
  71. BOOL mUniformScaling;
  72. BOOL mNoClip;
  73. };
  74. namespace LLInitParam
  75. {
  76. template<>
  77. class ParamValue<LLUIImage*, TypeValues<LLUIImage*> >
  78. : public CustomParamValue<LLUIImage*>
  79. {
  80. typedef boost::add_reference<boost::add_const<LLUIImage*>::type>::type T_const_ref;
  81. typedef CustomParamValue<LLUIImage*> super_t;
  82. public:
  83. Optional<std::string> name;
  84. ParamValue(LLUIImage* const& image)
  85. : super_t(image)
  86. {
  87. updateBlockFromValue(false);
  88. addSynonym(name, "name");
  89. }
  90. void updateValueFromBlock();
  91. void updateBlockFromValue(bool make_block_authoritative);
  92. };
  93. // Need custom comparison function for our test app, which only loads
  94. // LLUIImage* as NULL.
  95. template<>
  96. struct ParamCompare<LLUIImage*, false>
  97. {
  98. static bool equals(LLUIImage* const &a, LLUIImage* const &b);
  99. };
  100. }
  101. typedef LLPointer<LLUIImage> LLUIImagePtr;
  102. #endif