PageRenderTime 99ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/lliconctrl.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 121 lines | 75 code | 16 blank | 30 comment | 10 complexity | fd643af34d8c86d871de0a1fd3676412 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lliconctrl.cpp
  3. * @brief LLIconCtrl base class
  4. *
  5. * $LicenseInfo:firstyear=2001&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. #include "linden_common.h"
  27. #include "lliconctrl.h"
  28. // Linden library includes
  29. // Project includes
  30. #include "llcontrol.h"
  31. #include "llui.h"
  32. #include "lluictrlfactory.h"
  33. #include "lluiimage.h"
  34. static LLDefaultChildRegistry::Register<LLIconCtrl> r("icon");
  35. LLIconCtrl::Params::Params()
  36. : image("image_name"),
  37. color("color"),
  38. use_draw_context_alpha("use_draw_context_alpha", true),
  39. scale_image("scale_image")
  40. {}
  41. LLIconCtrl::LLIconCtrl(const LLIconCtrl::Params& p)
  42. : LLUICtrl(p),
  43. mColor(p.color()),
  44. mImagep(p.image),
  45. mUseDrawContextAlpha(p.use_draw_context_alpha),
  46. mPriority(0),
  47. mDrawWidth(0),
  48. mDrawHeight(0)
  49. {
  50. if (mImagep.notNull())
  51. {
  52. LLUICtrl::setValue(mImagep->getName());
  53. }
  54. }
  55. LLIconCtrl::~LLIconCtrl()
  56. {
  57. mImagep = NULL;
  58. }
  59. void LLIconCtrl::draw()
  60. {
  61. if( mImagep.notNull() )
  62. {
  63. const F32 alpha = mUseDrawContextAlpha ? getDrawContext().mAlpha : getCurrentTransparency();
  64. mImagep->draw(getLocalRect(), mColor.get() % alpha );
  65. }
  66. LLUICtrl::draw();
  67. }
  68. // virtual
  69. // value might be a string or a UUID
  70. void LLIconCtrl::setValue(const LLSD& value )
  71. {
  72. LLSD tvalue(value);
  73. if (value.isString() && LLUUID::validate(value.asString()))
  74. {
  75. //RN: support UUIDs masquerading as strings
  76. tvalue = LLSD(LLUUID(value.asString()));
  77. }
  78. LLUICtrl::setValue(tvalue);
  79. if (tvalue.isUUID())
  80. {
  81. mImagep = LLUI::getUIImageByID(tvalue.asUUID(), mPriority);
  82. }
  83. else
  84. {
  85. mImagep = LLUI::getUIImage(tvalue.asString(), mPriority);
  86. }
  87. setIconImageDrawSize();
  88. }
  89. std::string LLIconCtrl::getImageName() const
  90. {
  91. if (getValue().isString())
  92. return getValue().asString();
  93. else
  94. return std::string();
  95. }
  96. void LLIconCtrl::setIconImageDrawSize()
  97. {
  98. if(mImagep.notNull() && mDrawWidth && mDrawHeight)
  99. {
  100. if(mImagep->getImage().notNull())
  101. {
  102. mImagep->getImage()->setKnownDrawSize(mDrawWidth, mDrawHeight) ;
  103. }
  104. }
  105. }