lliconctrl.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * @file lliconctrl.cpp
  3. * @brief LLIconCtrl base class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "lliconctrl.h"
  34. #include "llcontrol.h"
  35. #include "lluictrlfactory.h"
  36. static const std::string LL_ICON_CTRL_TAG = "icon";
  37. static LLRegisterWidget<LLIconCtrl> r05(LL_ICON_CTRL_TAG);
  38. LLIconCtrl::LLIconCtrl(const std::string& name,
  39. const LLRect& rect,
  40. const LLUUID& image_id)
  41. : LLUICtrl(name, rect, false, // mouse opaque
  42. NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP),
  43. mColor(LLColor4::white)
  44. {
  45. setImage(image_id);
  46. setTabStop(false);
  47. }
  48. LLIconCtrl::LLIconCtrl(const std::string& name,
  49. const LLRect& rect,
  50. const std::string& image_name)
  51. : LLUICtrl(name, rect, false, // mouse opaque
  52. NULL, NULL, FOLLOWS_LEFT | FOLLOWS_TOP),
  53. mColor(LLColor4::white),
  54. mImageName(image_name)
  55. {
  56. setImage(image_name);
  57. setTabStop(false);
  58. }
  59. LLIconCtrl::~LLIconCtrl()
  60. {
  61. mImagep = NULL;
  62. }
  63. void LLIconCtrl::setImage(const std::string& image_name)
  64. {
  65. // RN: support UUIDs masquerading as strings
  66. if (LLUUID::validate(image_name))
  67. {
  68. mImageID = LLUUID(image_name);
  69. setImage(mImageID);
  70. }
  71. else
  72. {
  73. mImageName = image_name;
  74. mImagep = LLUI::getUIImage(image_name);
  75. mImageID.setNull();
  76. }
  77. }
  78. void LLIconCtrl::setImage(const LLUUID& image_id)
  79. {
  80. mImageName.clear();
  81. mImagep = LLUI::getUIImageByID(image_id);
  82. mImageID = image_id;
  83. }
  84. void LLIconCtrl::draw()
  85. {
  86. if (mImagep.notNull())
  87. {
  88. mImagep->draw(getLocalRect(), mColor);
  89. }
  90. LLUICtrl::draw();
  91. }
  92. //virtual
  93. void LLIconCtrl::setAlpha(F32 alpha)
  94. {
  95. mColor.setAlpha(alpha);
  96. }
  97. //virtual
  98. void LLIconCtrl::setValue(const LLSD& value)
  99. {
  100. if (value.isUUID())
  101. {
  102. setImage(value.asUUID());
  103. }
  104. else
  105. {
  106. setImage(value.asString());
  107. }
  108. }
  109. //virtual
  110. LLSD LLIconCtrl::getValue() const
  111. {
  112. LLSD ret = getImage();
  113. return ret;
  114. }
  115. //virtual
  116. const std::string& LLIconCtrl::getTag() const
  117. {
  118. return LL_ICON_CTRL_TAG;
  119. }
  120. //virtual
  121. LLXMLNodePtr LLIconCtrl::getXML(bool save_children) const
  122. {
  123. LLXMLNodePtr node = LLUICtrl::getXML();
  124. node->setName(LL_ICON_CTRL_TAG);
  125. if (mImageName != "")
  126. {
  127. node->createChild("image_name", true)->setStringValue(mImageName);
  128. }
  129. node->createChild("color", true)->setFloatValue(4, mColor.mV);
  130. return node;
  131. }
  132. LLView* LLIconCtrl::fromXML(LLXMLNodePtr node, LLView* parent,
  133. LLUICtrlFactory* factory)
  134. {
  135. std::string name = LL_ICON_CTRL_TAG;
  136. node->getAttributeString("name", name);
  137. LLRect rect;
  138. createRect(node, rect, parent, LLRect());
  139. std::string image_name;
  140. if (node->hasAttribute("image_name"))
  141. {
  142. node->getAttributeString("image_name", image_name);
  143. }
  144. LLColor4 color(LLColor4::white);
  145. LLUICtrlFactory::getAttributeColor(node, "color", color);
  146. LLIconCtrl* icon = new LLIconCtrl(name, rect, image_name);
  147. icon->setColor(color);
  148. icon->initFromXML(node, parent);
  149. return icon;
  150. }