PageRenderTime 1709ms CodeModel.GetById 587ms app.highlight 448ms RepoModel.GetById 663ms app.codeStats 1ms

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