diff options
Diffstat (limited to 'linden/indra/newview/llfloaterassetbrowser.cpp')
-rw-r--r-- | linden/indra/newview/llfloaterassetbrowser.cpp | 466 |
1 files changed, 466 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloaterassetbrowser.cpp b/linden/indra/newview/llfloaterassetbrowser.cpp new file mode 100644 index 0000000..615d21a --- /dev/null +++ b/linden/indra/newview/llfloaterassetbrowser.cpp | |||
@@ -0,0 +1,466 @@ | |||
1 | /** | ||
2 | * @file llfloaterassetbrowser.cpp | ||
3 | * @brief LLFloaterAssetBrowser class implementation | ||
4 | * Phox wuz hurr | ||
5 | */ | ||
6 | |||
7 | #include "llviewerprecompiledheaders.h" | ||
8 | #include "llfloaterassetbrowser.h" | ||
9 | #include "llinventoryview.h" | ||
10 | #include "llinventorymodel.h" | ||
11 | #include "llviewerimagelist.h" | ||
12 | #include "llbutton.h" | ||
13 | #include "lltextbox.h" | ||
14 | #include "llpreview.h" | ||
15 | #include "llinventorybridge.h" | ||
16 | #include "llagent.h" | ||
17 | #include "lltooldraganddrop.h" | ||
18 | #include "llfocusmgr.h" | ||
19 | #include "llview.h" | ||
20 | |||
21 | // Externs | ||
22 | extern LLInventoryModel gInventory; | ||
23 | |||
24 | // Statics | ||
25 | LLFloaterAssetBrowser* LLFloaterAssetBrowser::sInstance = NULL; | ||
26 | |||
27 | LLFloaterAssetBrowser::LLFloaterAssetBrowser() | ||
28 | : LLFloater("floater_asset_browser") | ||
29 | { | ||
30 | LLUICtrlFactory::getInstance()->buildFloater(this, "floater_asset_browser.xml"); | ||
31 | |||
32 | mInventoryPanel = getChild<LLInventoryPanel>("inventory panel"); | ||
33 | |||
34 | //Open all folders and close them in order to make item list up-to-date | ||
35 | //if(gInventory.getItemCount()==0) | ||
36 | mInventoryPanel->openAllFolders(); | ||
37 | |||
38 | //gInventory.startBackgroundFetch(gInventory.findCategoryUUIDForType(LLAssetType::AT_TEXTURE)); | ||
39 | |||
40 | |||
41 | childSetAction("button next", onClickNext, this); | ||
42 | childSetAction("button previous", onClickPrevious, this); | ||
43 | childSetAction("button refresh", onClickRefresh, this); | ||
44 | |||
45 | initialize(); | ||
46 | createThumbnails(); | ||
47 | mInventoryPanel->closeAllFolders(); | ||
48 | } | ||
49 | |||
50 | // static | ||
51 | void LLFloaterAssetBrowser::show(void*) | ||
52 | { | ||
53 | if (!sInstance) | ||
54 | sInstance = new LLFloaterAssetBrowser(); | ||
55 | |||
56 | sInstance->open(); | ||
57 | } | ||
58 | |||
59 | // virtual | ||
60 | LLFloaterAssetBrowser::~LLFloaterAssetBrowser() | ||
61 | { | ||
62 | clearAssetInfoTexts(); | ||
63 | mTextureAssets.clear(); | ||
64 | mMaxIndex = 0; | ||
65 | mFirstIndex = 0; | ||
66 | mMouseOverIndex = 0; | ||
67 | mMouseOverUUID = LLUUID::null; | ||
68 | mMouseOverAssetUUID = LLUUID::null; | ||
69 | mFloaterTitle = ""; | ||
70 | clearNoAssetsText(); | ||
71 | sInstance=NULL; | ||
72 | } | ||
73 | |||
74 | void LLFloaterAssetBrowser::initialize() | ||
75 | { | ||
76 | mMaxIndex = ITEMS_PER_PAGE; | ||
77 | mFirstIndex = 0; | ||
78 | mAssetInfoLabelList.clear(); | ||
79 | mAssetInfoIndex = 0; | ||
80 | mFloaterHeight = getRect().getHeight(); | ||
81 | mFloaterWidth = getRect().getWidth(); | ||
82 | mMouseOverIndex = 0; | ||
83 | mMouseOverUUID = LLUUID::null; | ||
84 | mMouseOverAssetUUID = LLUUID::null; | ||
85 | mFloaterTitle = ""; | ||
86 | |||
87 | S32 image_top = getRect().getHeight(); | ||
88 | S32 image_bottom = BTN_HEIGHT_SMALL; | ||
89 | S32 image_middle = (image_top + image_bottom) / 2; | ||
90 | S32 line_height = llround(LLFontGL::sSansSerifSmall->getLineHeight()); | ||
91 | |||
92 | mNoAssetsLabel = new LLTextBox("mNoAssetsLabel.", | ||
93 | LLRect(getRect().getWidth()/2, | ||
94 | image_middle + line_height / 2, | ||
95 | getRect().getWidth(), | ||
96 | image_middle - line_height / 2 ), | ||
97 | "No assets found.", | ||
98 | LLFontGL::sSansSerifSmall ); | ||
99 | mNoAssetsLabel->setFollowsAll(); | ||
100 | addChild(mNoAssetsLabel); | ||
101 | mNoAssetsLabel->setVisible(FALSE); | ||
102 | } | ||
103 | |||
104 | void LLFloaterAssetBrowser::createThumbnails() | ||
105 | { | ||
106 | LLViewerInventoryCategory::cat_array_t cats; | ||
107 | LLViewerInventoryItem::item_array_t items; | ||
108 | LLIsType isType(LLAssetType::AT_TEXTURE); | ||
109 | |||
110 | gInventory.collectDescendentsIf(LLUUID::null, | ||
111 | cats, | ||
112 | items, | ||
113 | LLInventoryModel::INCLUDE_TRASH, | ||
114 | isType); | ||
115 | |||
116 | //Get UUID, asset UUID and name | ||
117 | for(S32 i = 0; i < items.count(); i++) | ||
118 | { | ||
119 | LLInventoryItem* itemp = items[i]; | ||
120 | LLAssetSelection temp; | ||
121 | temp.mAssetUUID = itemp->getAssetUUID(); | ||
122 | temp.mUUID = itemp->getUUID(); | ||
123 | temp.mName = itemp->getName(); | ||
124 | temp.mTexturep = NULL; | ||
125 | temp.mAssetRect = LLRect::null; | ||
126 | mTextureAssets.push_back(temp); | ||
127 | } | ||
128 | |||
129 | //Get Texturep | ||
130 | for(S32 i = 0; i < items.count(); i++) | ||
131 | { | ||
132 | mTextureAssets[i].mTexturep = gImageList.getImage(mTextureAssets[i].mAssetUUID, MIPMAP_YES, IMMEDIATE_NO); | ||
133 | mTextureAssets[i].mTexturep->setBoostLevel(LLViewerImage::BOOST_PREVIEW); | ||
134 | //mTextureAssets[i].mTexturep->processTextureStats(); | ||
135 | } | ||
136 | |||
137 | //Generate the asset info text | ||
138 | /*for(S32 i = 0; i < items.count(); i++) | ||
139 | { | ||
140 | LLString asset_info; | ||
141 | LLString dimensions; | ||
142 | |||
143 | asset_info.append(mTextureAssets[i].mName); | ||
144 | |||
145 | //if(mTextureAssets[i].mTexturep->mFullWidth == 0 | ||
146 | //|| mTextureAssets[i].mTexturep->mFullHeight == 0) | ||
147 | |||
148 | dimensions = llformat("\n%d x %d", | ||
149 | mTextureAssets[i].mTexturep->mFullWidth, | ||
150 | mTextureAssets[i].mTexturep->mFullHeight); | ||
151 | asset_info.append(dimensions); | ||
152 | |||
153 | mTextureAssets[i].mAssetInfo = asset_info; | ||
154 | }*/ | ||
155 | |||
156 | mFloaterTitle = llformat("Asset Browser (%d assets fetched)", mTextureAssets.size()); | ||
157 | setTitle(mFloaterTitle); | ||
158 | } | ||
159 | |||
160 | // virtual | ||
161 | BOOL LLFloaterAssetBrowser::handleHover(S32 x, S32 y, MASK mask) | ||
162 | { | ||
163 | if(mTextureAssets.size() > 0) | ||
164 | { | ||
165 | for(U32 i = mFirstIndex; i < mMaxIndex; i++) | ||
166 | { | ||
167 | if(i < mTextureAssets.size()) | ||
168 | { | ||
169 | if(mTextureAssets[i].mAssetRect.pointInRect(x,y)) | ||
170 | { | ||
171 | mMouseOverUUID = mTextureAssets[i].mUUID; | ||
172 | mMouseOverIndex = i; | ||
173 | |||
174 | if(hasMouseCapture()) | ||
175 | { | ||
176 | S32 screen_x; | ||
177 | S32 screen_y; | ||
178 | LLUUID mObjectUUID= LLUUID::null; | ||
179 | const LLViewerInventoryItem *item = gInventory.getItem(mMouseOverUUID); | ||
180 | |||
181 | localPointToScreen(x, y, &screen_x, &screen_y ); | ||
182 | |||
183 | if(item && item->getPermissions().allowCopyBy(gAgent.getID(), gAgent.getGroupID()) | ||
184 | && LLToolDragAndDrop::getInstance()->isOverThreshold(screen_x, screen_y)) | ||
185 | { | ||
186 | EDragAndDropType type; | ||
187 | type = LLAssetType::lookupDragAndDropType(item->getType()); | ||
188 | LLToolDragAndDrop::ESource src = LLToolDragAndDrop::SOURCE_LIBRARY; | ||
189 | |||
190 | if(!mObjectUUID.isNull()) | ||
191 | { | ||
192 | src = LLToolDragAndDrop::SOURCE_WORLD; | ||
193 | } | ||
194 | else if(item->getPermissions().getOwner() == gAgent.getID()) | ||
195 | { | ||
196 | src = LLToolDragAndDrop::SOURCE_AGENT; | ||
197 | } | ||
198 | LLToolDragAndDrop::getInstance()->beginDrag(type, | ||
199 | item->getUUID(), | ||
200 | src, | ||
201 | mObjectUUID); | ||
202 | return LLToolDragAndDrop::getInstance()->handleHover(x, y, mask); | ||
203 | } | ||
204 | return TRUE; | ||
205 | } | ||
206 | return LLFloater::handleHover(x, y, mask); | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | return LLFloater::handleHover(x, y, mask); | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | mMouseOverUUID = LLUUID::null; | ||
215 | return LLFloater::handleHover(x, y, mask); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | // virtual | ||
220 | BOOL LLFloaterAssetBrowser::handleMouseDown(S32 x, S32 y, MASK mask) | ||
221 | { | ||
222 | if(mTextureAssets.size() > 0) | ||
223 | { | ||
224 | if(mTextureAssets[mMouseOverIndex].mAssetRect.pointInRect(x,y)) | ||
225 | { | ||
226 | if(mMouseOverUUID.notNull()) | ||
227 | { | ||
228 | gFocusMgr.setMouseCapture(this); | ||
229 | S32 screen_x; | ||
230 | S32 screen_y; | ||
231 | localPointToScreen(x, y, &screen_x, &screen_y); | ||
232 | LLToolDragAndDrop::getInstance()->setDragStart(screen_x, screen_y); | ||
233 | return TRUE; | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | return LLFloater::handleMouseDown(x, y, mask); | ||
238 | } | ||
239 | |||
240 | // virtual | ||
241 | BOOL LLFloaterAssetBrowser::handleMouseUp(S32 x, S32 y, MASK mask) | ||
242 | { | ||
243 | if(hasMouseCapture()) | ||
244 | { | ||
245 | gFocusMgr.setMouseCapture(NULL); | ||
246 | return TRUE; | ||
247 | } | ||
248 | return LLFloater::handleMouseUp(x, y, mask); | ||
249 | } | ||
250 | |||
251 | // virtual | ||
252 | BOOL LLFloaterAssetBrowser::handleDoubleClick(S32 x, S32 y, MASK mask) | ||
253 | { | ||
254 | if(mTextureAssets.size() > 0) | ||
255 | { | ||
256 | if(mTextureAssets[mMouseOverIndex].mAssetRect.pointInRect(x,y)) | ||
257 | { | ||
258 | if(mMouseOverUUID.notNull()) | ||
259 | { | ||
260 | open_texture(mMouseOverUUID, mTextureAssets[mMouseOverIndex].mName, FALSE); | ||
261 | return TRUE; | ||
262 | } | ||
263 | } | ||
264 | } | ||
265 | return LLFloater::handleDoubleClick(x, y, mask); | ||
266 | } | ||
267 | |||
268 | // virtual | ||
269 | void LLFloaterAssetBrowser::draw() | ||
270 | { | ||
271 | LLFloater::draw(); | ||
272 | |||
273 | if(mTextureAssets.size() > 0) | ||
274 | { | ||
275 | S32 hor_pos = 0; | ||
276 | S32 ver_pos = 0; | ||
277 | U32 items_per_row = 0; | ||
278 | S32 height = getRect().getHeight()/8; | ||
279 | S32 width = height; | ||
280 | |||
281 | for(U32 i = mFirstIndex; i < mMaxIndex; i++) | ||
282 | { | ||
283 | if(i < mTextureAssets.size()) | ||
284 | { | ||
285 | mTexturep = NULL; | ||
286 | mImageAssetID = mTextureAssets[i].mAssetUUID; | ||
287 | |||
288 | if(mImageAssetID.notNull()) | ||
289 | { | ||
290 | mTexturep = gImageList.getImage(mImageAssetID, MIPMAP_YES, IMMEDIATE_NO); | ||
291 | //mTexturep->setBoostLevel(LLViewerImage::BOOST_PREVIEW); | ||
292 | mTexturep->processTextureStats(); | ||
293 | mTextureAssets[i].mWidth = mTexturep->mFullWidth; | ||
294 | mTextureAssets[i].mHeight = mTexturep->mFullHeight; | ||
295 | } | ||
296 | |||
297 | if(isMinimized()) | ||
298 | { | ||
299 | return; | ||
300 | } | ||
301 | |||
302 | //Border | ||
303 | LLRect border; | ||
304 | border.mLeft = START_POS + ver_pos; | ||
305 | border.mTop = getRect().getHeight() - LLFLOATER_HEADER_SIZE - BORDER_PAD - hor_pos; | ||
306 | border.mRight = border.mLeft + width; | ||
307 | border.mBottom = border.mTop - height; | ||
308 | |||
309 | //Save the rect for each thumbnail | ||
310 | mTextureAssets[i].mAssetRect = border; | ||
311 | |||
312 | //Asset info rect | ||
313 | LLRect info_rect; | ||
314 | info_rect.mLeft = border.mLeft; | ||
315 | info_rect.mTop = border.mBottom - 3; | ||
316 | info_rect.mRight = border.mLeft + 130; | ||
317 | info_rect.mBottom = border.mBottom - 2*llround(LLFontGL::sSansSerifSmall->getLineHeight()); | ||
318 | |||
319 | gl_rect_2d(border, LLColor4::black, FALSE); | ||
320 | |||
321 | // Interior | ||
322 | LLRect interior = border; | ||
323 | interior.stretch(1); | ||
324 | |||
325 | //Draw the image | ||
326 | if(mTexturep) | ||
327 | { | ||
328 | if(mTexturep->getComponents() == 4) | ||
329 | { | ||
330 | gl_rect_2d_checkerboard(interior); | ||
331 | } | ||
332 | |||
333 | gl_draw_scaled_image(interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), mTexturep); | ||
334 | // Pump the priority | ||
335 | mTexturep->addTextureStats((F32)(interior.getWidth() * interior.getHeight())); | ||
336 | |||
337 | //Generate the asset info text | ||
338 | std::string asset_info; | ||
339 | asset_info.append(mTextureAssets[i].mName); | ||
340 | std::string dimensions = llformat("\n%d x %d", | ||
341 | mTexturep->mFullWidth /*mTextureAssets[i].mWidth*/, | ||
342 | mTexturep->mFullHeight /* mTextureAssets[i].mHeight*/); | ||
343 | asset_info.append(dimensions); | ||
344 | |||
345 | // Draw material info below the asset | ||
346 | // LLTextBox object has to be drawn only once, not non-stop like image | ||
347 | if(mAssetInfoIndex < ITEMS_PER_PAGE && | ||
348 | mAssetInfoIndex < mTextureAssets.size() - mFirstIndex) | ||
349 | { | ||
350 | mAssetInfoLabel = new LLTextBox("Asset Info"/*mTextureAssets[i].mAssetInfo*/, | ||
351 | info_rect, | ||
352 | asset_info, | ||
353 | LLFontGL::sSansSerifSmall); | ||
354 | mAssetInfoLabel->setFollowsAll(); | ||
355 | mAssetInfoLabelList.push_back(mAssetInfoLabel); | ||
356 | addChild(mAssetInfoLabelList[mAssetInfoIndex]); | ||
357 | mAssetInfoLabelList[mAssetInfoIndex]->setVisible(TRUE); | ||
358 | mAssetInfoIndex++; | ||
359 | } | ||
360 | |||
361 | } | ||
362 | else | ||
363 | { | ||
364 | // Draw X | ||
365 | gl_rect_2d(interior, LLColor4::grey, TRUE); | ||
366 | gl_draw_x(interior, LLColor4::black); | ||
367 | } | ||
368 | //Move to the right | ||
369 | ver_pos += getRect().getWidth()/6; | ||
370 | items_per_row++; | ||
371 | |||
372 | //Change the row | ||
373 | if(items_per_row % 4 == 0) | ||
374 | { | ||
375 | ver_pos = 0; | ||
376 | hor_pos += getRect().getHeight()/4; | ||
377 | } | ||
378 | } | ||
379 | }//for | ||
380 | |||
381 | //If the size of the floater has changed, clear the asset info texts | ||
382 | //in order to draw them again into the new position | ||
383 | if(getRect().getWidth() != mFloaterWidth || getRect().getHeight() != mFloaterHeight) | ||
384 | { | ||
385 | clearAssetInfoTexts(); | ||
386 | //Save the size of the current floater | ||
387 | mFloaterWidth = getRect().getWidth(); | ||
388 | mFloaterHeight = getRect().getHeight(); | ||
389 | } | ||
390 | if(mMaxIndex >= mTextureAssets.size()) | ||
391 | { | ||
392 | childDisable("button next"); | ||
393 | childEnable("button previous"); | ||
394 | } | ||
395 | else if(mFirstIndex <= 0) | ||
396 | { | ||
397 | childEnable("button next"); | ||
398 | childDisable("button previous"); | ||
399 | } | ||
400 | else | ||
401 | { | ||
402 | childEnable("button next"); | ||
403 | childEnable("button previous"); | ||
404 | } | ||
405 | } | ||
406 | else | ||
407 | { | ||
408 | //No assets found | ||
409 | mNoAssetsLabel->setVisible(TRUE); | ||
410 | childDisable("button next"); | ||
411 | childDisable("button previous"); | ||
412 | } | ||
413 | } | ||
414 | |||
415 | void LLFloaterAssetBrowser::clearAssetInfoTexts() | ||
416 | { | ||
417 | for(U32 i = 0; i < mAssetInfoLabelList.size(); i++) | ||
418 | { | ||
419 | delete mAssetInfoLabelList[i]; | ||
420 | mAssetInfoLabelList[i] = NULL; | ||
421 | } | ||
422 | mAssetInfoLabelList.clear(); | ||
423 | mAssetInfoIndex = 0; | ||
424 | } | ||
425 | |||
426 | void LLFloaterAssetBrowser::clearNoAssetsText() | ||
427 | { | ||
428 | if(mTextureAssets.size() > 0) | ||
429 | { | ||
430 | delete mNoAssetsLabel; | ||
431 | mNoAssetsLabel = NULL; | ||
432 | } | ||
433 | } | ||
434 | |||
435 | // static | ||
436 | void LLFloaterAssetBrowser::onClickNext(void *userdata) | ||
437 | { | ||
438 | LLFloaterAssetBrowser* self = (LLFloaterAssetBrowser*)userdata; | ||
439 | self->mFirstIndex = self->mMaxIndex; | ||
440 | self->mMaxIndex = self->mFirstIndex + ITEMS_PER_PAGE; | ||
441 | self->clearAssetInfoTexts(); | ||
442 | } | ||
443 | |||
444 | // static | ||
445 | void LLFloaterAssetBrowser::onClickPrevious(void *userdata) | ||
446 | { | ||
447 | LLFloaterAssetBrowser* self = (LLFloaterAssetBrowser*)userdata; | ||
448 | self->mFirstIndex = self->mMaxIndex - (2 * ITEMS_PER_PAGE); | ||
449 | self->mMaxIndex = self->mMaxIndex - ITEMS_PER_PAGE; | ||
450 | self->clearAssetInfoTexts(); | ||
451 | } | ||
452 | |||
453 | // static | ||
454 | void LLFloaterAssetBrowser::onClickRefresh(void *userdata) | ||
455 | { | ||
456 | LLFloaterAssetBrowser* self = (LLFloaterAssetBrowser*)userdata; | ||
457 | for(U32 i = 0; i < self->mTextureAssets.size(); i++) | ||
458 | { | ||
459 | self->mTextureAssets[i].mTexturep = NULL; | ||
460 | } | ||
461 | |||
462 | self->mTextureAssets.clear(); | ||
463 | self->createThumbnails(); | ||
464 | self->clearNoAssetsText(); | ||
465 | self->clearAssetInfoTexts(); | ||
466 | } | ||