PageRenderTime 33ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llinventoryicon.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 183 lines | 139 code | 19 blank | 25 comment | 4 complexity | 1d64105d3b9af9153b1a52de8f876e5c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llinventoryicon.cpp
  3. * @brief Implementation of the inventory icon.
  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 "llviewerprecompiledheaders.h"
  27. #include "llinventoryicon.h"
  28. #include "lldictionary.h"
  29. #include "llinventorydefines.h"
  30. #include "llui.h"
  31. #include "llwearabletype.h"
  32. struct IconEntry : public LLDictionaryEntry
  33. {
  34. IconEntry(const std::string &item_name)
  35. :
  36. LLDictionaryEntry(item_name)
  37. {}
  38. };
  39. class LLIconDictionary : public LLSingleton<LLIconDictionary>,
  40. public LLDictionary<LLInventoryIcon::EIconName, IconEntry>
  41. {
  42. public:
  43. LLIconDictionary();
  44. };
  45. LLIconDictionary::LLIconDictionary()
  46. {
  47. addEntry(LLInventoryIcon::ICONNAME_TEXTURE, new IconEntry("Inv_Texture"));
  48. addEntry(LLInventoryIcon::ICONNAME_SOUND, new IconEntry("Inv_Sound"));
  49. addEntry(LLInventoryIcon::ICONNAME_CALLINGCARD_ONLINE, new IconEntry("Inv_CallingCard"));
  50. addEntry(LLInventoryIcon::ICONNAME_CALLINGCARD_OFFLINE, new IconEntry("Inv_CallingCard"));
  51. addEntry(LLInventoryIcon::ICONNAME_LANDMARK, new IconEntry("Inv_Landmark"));
  52. addEntry(LLInventoryIcon::ICONNAME_LANDMARK_VISITED, new IconEntry("Inv_Landmark"));
  53. addEntry(LLInventoryIcon::ICONNAME_SCRIPT, new IconEntry("Inv_Script"));
  54. addEntry(LLInventoryIcon::ICONNAME_CLOTHING, new IconEntry("Inv_Clothing"));
  55. addEntry(LLInventoryIcon::ICONNAME_OBJECT, new IconEntry("Inv_Object"));
  56. addEntry(LLInventoryIcon::ICONNAME_OBJECT_MULTI, new IconEntry("Inv_Object_Multi"));
  57. addEntry(LLInventoryIcon::ICONNAME_NOTECARD, new IconEntry("Inv_Notecard"));
  58. addEntry(LLInventoryIcon::ICONNAME_BODYPART, new IconEntry("Inv_Skin"));
  59. addEntry(LLInventoryIcon::ICONNAME_SNAPSHOT, new IconEntry("Inv_Snapshot"));
  60. addEntry(LLInventoryIcon::ICONNAME_BODYPART_SHAPE, new IconEntry("Inv_BodyShape"));
  61. addEntry(LLInventoryIcon::ICONNAME_BODYPART_SKIN, new IconEntry("Inv_Skin"));
  62. addEntry(LLInventoryIcon::ICONNAME_BODYPART_HAIR, new IconEntry("Inv_Hair"));
  63. addEntry(LLInventoryIcon::ICONNAME_BODYPART_EYES, new IconEntry("Inv_Eye"));
  64. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_SHIRT, new IconEntry("Inv_Shirt"));
  65. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_PANTS, new IconEntry("Inv_Pants"));
  66. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_SHOES, new IconEntry("Inv_Shoe"));
  67. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_SOCKS, new IconEntry("Inv_Socks"));
  68. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_JACKET, new IconEntry("Inv_Jacket"));
  69. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_GLOVES, new IconEntry("Inv_Gloves"));
  70. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_UNDERSHIRT, new IconEntry("Inv_Undershirt"));
  71. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_UNDERPANTS, new IconEntry("Inv_Underpants"));
  72. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_SKIRT, new IconEntry("Inv_Skirt"));
  73. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_ALPHA, new IconEntry("Inv_Alpha"));
  74. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_TATTOO, new IconEntry("Inv_Tattoo"));
  75. addEntry(LLInventoryIcon::ICONNAME_ANIMATION, new IconEntry("Inv_Animation"));
  76. addEntry(LLInventoryIcon::ICONNAME_GESTURE, new IconEntry("Inv_Gesture"));
  77. addEntry(LLInventoryIcon::ICONNAME_CLOTHING_PHYSICS, new IconEntry("Inv_Physics"));
  78. addEntry(LLInventoryIcon::ICONNAME_LINKITEM, new IconEntry("Inv_LinkItem"));
  79. addEntry(LLInventoryIcon::ICONNAME_LINKFOLDER, new IconEntry("Inv_LinkFolder"));
  80. addEntry(LLInventoryIcon::ICONNAME_MESH, new IconEntry("Inv_Mesh"));
  81. addEntry(LLInventoryIcon::ICONNAME_INVALID, new IconEntry("Inv_Invalid"));
  82. addEntry(LLInventoryIcon::ICONNAME_NONE, new IconEntry("NONE"));
  83. }
  84. LLUIImagePtr LLInventoryIcon::getIcon(LLAssetType::EType asset_type,
  85. LLInventoryType::EType inventory_type,
  86. U32 misc_flag,
  87. BOOL item_is_multi)
  88. {
  89. const std::string& icon_name = getIconName(asset_type, inventory_type, misc_flag, item_is_multi);
  90. return LLUI::getUIImage(icon_name);
  91. }
  92. LLUIImagePtr LLInventoryIcon::getIcon(EIconName idx)
  93. {
  94. return LLUI::getUIImage(getIconName(idx));
  95. }
  96. const std::string& LLInventoryIcon::getIconName(LLAssetType::EType asset_type,
  97. LLInventoryType::EType inventory_type,
  98. U32 misc_flag,
  99. BOOL item_is_multi)
  100. {
  101. EIconName idx = ICONNAME_OBJECT;
  102. if (item_is_multi)
  103. {
  104. idx = ICONNAME_OBJECT_MULTI;
  105. return getIconName(idx);
  106. }
  107. switch(asset_type)
  108. {
  109. case LLAssetType::AT_TEXTURE:
  110. idx = (inventory_type == LLInventoryType::IT_SNAPSHOT) ? ICONNAME_SNAPSHOT : ICONNAME_TEXTURE;
  111. break;
  112. case LLAssetType::AT_SOUND:
  113. idx = ICONNAME_SOUND;
  114. break;
  115. case LLAssetType::AT_CALLINGCARD:
  116. idx = (misc_flag != 0) ? ICONNAME_CALLINGCARD_ONLINE : ICONNAME_CALLINGCARD_OFFLINE;
  117. break;
  118. case LLAssetType::AT_LANDMARK:
  119. idx = (misc_flag != 0) ? ICONNAME_LANDMARK_VISITED : ICONNAME_LANDMARK;
  120. break;
  121. case LLAssetType::AT_SCRIPT:
  122. case LLAssetType::AT_LSL_TEXT:
  123. case LLAssetType::AT_LSL_BYTECODE:
  124. idx = ICONNAME_SCRIPT;
  125. break;
  126. case LLAssetType::AT_CLOTHING:
  127. case LLAssetType::AT_BODYPART:
  128. idx = assignWearableIcon(misc_flag);
  129. break;
  130. case LLAssetType::AT_NOTECARD:
  131. idx = ICONNAME_NOTECARD;
  132. break;
  133. case LLAssetType::AT_ANIMATION:
  134. idx = ICONNAME_ANIMATION;
  135. break;
  136. case LLAssetType::AT_GESTURE:
  137. idx = ICONNAME_GESTURE;
  138. break;
  139. case LLAssetType::AT_LINK:
  140. idx = ICONNAME_LINKITEM;
  141. break;
  142. case LLAssetType::AT_LINK_FOLDER:
  143. idx = ICONNAME_LINKFOLDER;
  144. break;
  145. case LLAssetType::AT_OBJECT:
  146. idx = ICONNAME_OBJECT;
  147. break;
  148. case LLAssetType::AT_MESH:
  149. idx = ICONNAME_MESH;
  150. default:
  151. break;
  152. }
  153. return getIconName(idx);
  154. }
  155. const std::string& LLInventoryIcon::getIconName(EIconName idx)
  156. {
  157. const IconEntry *entry = LLIconDictionary::instance().lookup(idx);
  158. return entry->mName;
  159. }
  160. LLInventoryIcon::EIconName LLInventoryIcon::assignWearableIcon(U32 misc_flag)
  161. {
  162. const LLWearableType::EType wearable_type = LLWearableType::EType(LLInventoryItemFlags::II_FLAGS_WEARABLES_MASK & misc_flag);
  163. return LLWearableType::getIconName(wearable_type);
  164. }