PageRenderTime 32ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lluiimage.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 199 lines | 140 code | 25 blank | 34 comment | 25 complexity | af3bcf41039fe042d5810f33c635d6af MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lluiimage.cpp
  3. * @brief UI implementation
  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. // Utilities functions the user interface needs
  27. //#include "llviewerprecompiledheaders.h"
  28. #include "linden_common.h"
  29. // Project includes
  30. #include "lluiimage.h"
  31. #include "llui.h"
  32. LLUIImage::LLUIImage(const std::string& name, LLPointer<LLTexture> image)
  33. : mName(name),
  34. mImage(image),
  35. mScaleRegion(0.f, 1.f, 1.f, 0.f),
  36. mClipRegion(0.f, 1.f, 1.f, 0.f),
  37. mUniformScaling(TRUE),
  38. mNoClip(TRUE),
  39. mImageLoaded(NULL)
  40. {
  41. }
  42. LLUIImage::~LLUIImage()
  43. {
  44. delete mImageLoaded;
  45. }
  46. void LLUIImage::setClipRegion(const LLRectf& region)
  47. {
  48. mClipRegion = region;
  49. mNoClip = mClipRegion.mLeft == 0.f
  50. && mClipRegion.mRight == 1.f
  51. && mClipRegion.mBottom == 0.f
  52. && mClipRegion.mTop == 1.f;
  53. }
  54. void LLUIImage::setScaleRegion(const LLRectf& region)
  55. {
  56. mScaleRegion = region;
  57. mUniformScaling = mScaleRegion.mLeft == 0.f
  58. && mScaleRegion.mRight == 1.f
  59. && mScaleRegion.mBottom == 0.f
  60. && mScaleRegion.mTop == 1.f;
  61. }
  62. //TODO: move drawing implementation inside class
  63. void LLUIImage::draw(S32 x, S32 y, const LLColor4& color) const
  64. {
  65. gl_draw_scaled_image(x, y, getWidth(), getHeight(), mImage, color, mClipRegion);
  66. }
  67. void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const
  68. {
  69. if (mUniformScaling)
  70. {
  71. gl_draw_scaled_image(x, y, width, height, mImage, color, mClipRegion);
  72. }
  73. else
  74. {
  75. gl_draw_scaled_image_with_border(
  76. x, y,
  77. width, height,
  78. mImage,
  79. color,
  80. FALSE,
  81. mClipRegion,
  82. mScaleRegion);
  83. }
  84. }
  85. void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height, const LLColor4& color) const
  86. {
  87. gl_draw_scaled_image_with_border(
  88. x, y,
  89. width, height,
  90. mImage,
  91. color,
  92. TRUE,
  93. mClipRegion,
  94. mScaleRegion);
  95. }
  96. void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color, S32 border_width) const
  97. {
  98. LLRect border_rect;
  99. border_rect.setOriginAndSize(x, y, width, height);
  100. border_rect.stretch(border_width, border_width);
  101. drawSolid(border_rect, color);
  102. }
  103. S32 LLUIImage::getWidth() const
  104. {
  105. // return clipped dimensions of actual image area
  106. return llround((F32)mImage->getWidth(0) * mClipRegion.getWidth());
  107. }
  108. S32 LLUIImage::getHeight() const
  109. {
  110. // return clipped dimensions of actual image area
  111. return llround((F32)mImage->getHeight(0) * mClipRegion.getHeight());
  112. }
  113. S32 LLUIImage::getTextureWidth() const
  114. {
  115. return mImage->getWidth(0);
  116. }
  117. S32 LLUIImage::getTextureHeight() const
  118. {
  119. return mImage->getHeight(0);
  120. }
  121. boost::signals2::connection LLUIImage::addLoadedCallback( const image_loaded_signal_t::slot_type& cb )
  122. {
  123. if (!mImageLoaded)
  124. {
  125. mImageLoaded = new image_loaded_signal_t();
  126. }
  127. return mImageLoaded->connect(cb);
  128. }
  129. void LLUIImage::onImageLoaded()
  130. {
  131. if (mImageLoaded)
  132. {
  133. (*mImageLoaded)();
  134. }
  135. }
  136. namespace LLInitParam
  137. {
  138. void ParamValue<LLUIImage*, TypeValues<LLUIImage*> >::updateValueFromBlock()
  139. {
  140. // The keyword "none" is specifically requesting a null image
  141. // do not default to current value. Used to overwrite template images.
  142. if (name() == "none")
  143. {
  144. updateValue(NULL);
  145. return;
  146. }
  147. LLUIImage* imagep = LLUI::getUIImage(name());
  148. if (imagep)
  149. {
  150. updateValue(imagep);
  151. }
  152. }
  153. void ParamValue<LLUIImage*, TypeValues<LLUIImage*> >::updateBlockFromValue(bool make_block_authoritative)
  154. {
  155. if (getValue() == NULL)
  156. {
  157. name.set("none", make_block_authoritative);
  158. }
  159. else
  160. {
  161. name.set(getValue()->getName(), make_block_authoritative);
  162. }
  163. }
  164. bool ParamCompare<LLUIImage*, false>::equals(
  165. LLUIImage* const &a,
  166. LLUIImage* const &b)
  167. {
  168. // force all LLUIImages for XML UI export to be "non-default"
  169. if (!a && !b)
  170. return false;
  171. else
  172. return (a == b);
  173. }
  174. }