1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
|
/**
* @file llpreviewtexture.cpp
* @brief LLPreviewTexture class implementation
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llwindow.h"
#include "llpreviewtexture.h"
#include "llagent.h"
#include "llbutton.h"
#include "llcombobox.h"
#include "llfilepicker.h"
#include "llfloaterreg.h"
#include "llimagetga.h"
#include "llimagepng.h"
#include "llinventory.h"
#include "llinventorymodel.h"
#include "llnotificationsutil.h"
#include "llresmgr.h"
#include "lltrans.h"
#include "lltextbox.h"
#include "lltextureview.h"
#include "llui.h"
#include "llviewerinventory.h"
#include "llviewermenufile.h" // LLFilePickerReplyThread
#include "llviewertexture.h"
#include "llviewertexturelist.h"
#include "lluictrlfactory.h"
#include "llviewercontrol.h"
#include "llviewerwindow.h"
#include "lllineeditor.h"
#include <boost/lexical_cast.hpp>
const S32 CLIENT_RECT_VPAD = 4;
const F32 SECONDS_TO_SHOW_FILE_SAVED_MSG = 8.f;
const F32 PREVIEW_TEXTURE_MAX_ASPECT = 200.f;
const F32 PREVIEW_TEXTURE_MIN_ASPECT = 0.005f;
LLPreviewTexture::LLPreviewTexture(const LLSD& key)
: LLPreview(key),
mLoadingFullImage( false ),
mSavingMultiple(false),
mShowKeepDiscard(false),
mCopyToInv(false),
mIsCopyable(false),
mIsFullPerm(false),
mUpdateDimensions(true),
mLastHeight(0),
mLastWidth(0),
mAspectRatio(0.f),
mPreviewToSave(false),
mImage(NULL),
mImageOldBoostLevel(LLGLTexture::BOOST_NONE)
{
updateImageID();
if (key.has("save_as"))
{
mPreviewToSave = true;
}
}
LLPreviewTexture::~LLPreviewTexture()
{
LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList) ;
if( mLoadingFullImage )
{
getWindow()->decBusyCount();
}
if (mImage.notNull())
{
mImage->setBoostLevel(mImageOldBoostLevel);
mImage = NULL;
}
}
void LLPreviewTexture::populateRatioList()
{
// Fill in ratios list with common aspect ratio values
mRatiosList.clear();
mRatiosList.push_back(LLTrans::getString("Unconstrained"));
mRatiosList.push_back("1:1");
mRatiosList.push_back("4:3");
mRatiosList.push_back("10:7");
mRatiosList.push_back("3:2");
mRatiosList.push_back("16:10");
mRatiosList.push_back("16:9");
mRatiosList.push_back("2:1");
// Now fill combo box with provided list
LLComboBox* combo = getChild<LLComboBox>("combo_aspect_ratio");
combo->removeall();
for (std::vector<std::string>::const_iterator it = mRatiosList.begin(); it != mRatiosList.end(); ++it)
{
combo->add(*it);
}
}
// virtual
bool LLPreviewTexture::postBuild()
{
mButtonsPanel = getChild<LLLayoutPanel>("buttons_panel");
mDimensionsText = getChild<LLUICtrl>("dimensions");
mAspectRatioText = getChild<LLUICtrl>("aspect_ratio");
if (mCopyToInv)
{
getChild<LLButton>("Keep")->setLabel(getString("Copy"));
childSetAction("Keep",LLPreview::onBtnCopyToInv,this);
getChildView("Discard")->setVisible( false);
}
else if (mShowKeepDiscard)
{
childSetAction("Keep",onKeepBtn,this);
childSetAction("Discard",onDiscardBtn,this);
}
else
{
getChildView("Keep")->setVisible( false);
getChildView("Discard")->setVisible( false);
}
childSetAction("save_tex_btn", LLPreviewTexture::onSaveAsBtn, this);
getChildView("save_tex_btn")->setVisible( true);
getChildView("save_tex_btn")->setEnabled(canSaveAs());
const LLInventoryItem* item = getItem();
if (item)
{
if (!mCopyToInv)
{
childSetCommitCallback("desc", LLPreview::onText, this);
getChild<LLUICtrl>("desc")->setValue(item->getDescription());
getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
}
bool source_library = mObjectUUID.isNull() && gInventory.isObjectDescendentOf(item->getUUID(), gInventory.getLibraryRootFolderID());
if (source_library)
{
getChildView("Discard")->setEnabled(false);
}
}
// Fill in ratios list and combo box with common aspect ratio values
populateRatioList();
childSetCommitCallback("combo_aspect_ratio", onAspectRatioCommit, this);
LLComboBox* combo = getChild<LLComboBox>("combo_aspect_ratio");
combo->setCurrentByIndex(0);
return LLPreview::postBuild();
}
// static
void LLPreviewTexture::onSaveAsBtn(void* data)
{
LLPreviewTexture* self = (LLPreviewTexture*)data;
self->saveAs();
}
void LLPreviewTexture::draw()
{
updateDimensions();
LLPreview::draw();
if (!isMinimized())
{
LLGLSUIDefault gls_ui;
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
const LLRect& border = mClientRect;
LLRect interior = mClientRect;
interior.stretch( -PREVIEW_BORDER_WIDTH );
// ...border
gl_rect_2d( border, LLColor4(0.f, 0.f, 0.f, 1.f));
gl_rect_2d_checkerboard( interior );
if ( mImage.notNull() )
{
// Draw the texture
gGL.diffuseColor3f( 1.f, 1.f, 1.f );
gl_draw_scaled_image(interior.mLeft,
interior.mBottom,
interior.getWidth(),
interior.getHeight(),
mImage);
// Pump the texture priority
F32 pixel_area = mLoadingFullImage ? (F32)MAX_IMAGE_AREA : (F32)(interior.getWidth() * interior.getHeight() );
mImage->addTextureStats( pixel_area );
// Don't bother decoding more than we can display, unless
// we're loading the full image.
if (!mLoadingFullImage)
{
S32 int_width = interior.getWidth();
S32 int_height = interior.getHeight();
mImage->setKnownDrawSize(int_width, int_height);
}
else
{
// Don't use this feature
mImage->setKnownDrawSize(0, 0);
}
if( mLoadingFullImage )
{
LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("Receiving"), 0,
interior.mLeft + 4,
interior.mBottom + 4,
LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM,
LLFontGL::NORMAL,
LLFontGL::DROP_SHADOW);
F32 data_progress = mImage->getDownloadProgress() ;
// Draw the progress bar.
const S32 BAR_HEIGHT = 12;
const S32 BAR_LEFT_PAD = 80;
S32 left = interior.mLeft + 4 + BAR_LEFT_PAD;
S32 bar_width = getRect().getWidth() - left - RESIZE_HANDLE_WIDTH - 2;
S32 top = interior.mBottom + 4 + BAR_HEIGHT;
S32 right = left + bar_width;
S32 bottom = top - BAR_HEIGHT;
LLColor4 background_color(0.f, 0.f, 0.f, 0.75f);
LLColor4 decoded_color(0.f, 1.f, 0.f, 1.0f);
LLColor4 downloaded_color(0.f, 0.5f, 0.f, 1.0f);
gl_rect_2d(left, top, right, bottom, background_color);
if (data_progress > 0.0f)
{
// Downloaded bytes
right = left + llfloor(data_progress * (F32)bar_width);
if (right > left)
{
gl_rect_2d(left, top, right, bottom, downloaded_color);
}
}
}
else
if( !mSavedFileTimer.hasExpired() )
{
LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("FileSaved"), 0,
interior.mLeft + 4,
interior.mBottom + 4,
LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM,
LLFontGL::NORMAL,
LLFontGL::DROP_SHADOW);
}
}
}
}
// virtual
bool LLPreviewTexture::canSaveAs() const
{
return mIsFullPerm && !mLoadingFullImage && mImage.notNull() && !mImage->isMissingAsset();
}
// virtual
void LLPreviewTexture::saveAs()
{
if( mLoadingFullImage )
return;
std::string filename = getItem() ? LLDir::getScrubbedFileName(getItem()->getName()) : LLStringUtil::null;
LLFilePickerReplyThread::startPicker(boost::bind(&LLPreviewTexture::saveTextureToFile, this, _1), LLFilePicker::FFSAVE_TGAPNG, filename);
}
void LLPreviewTexture::saveTextureToFile(const std::vector<std::string>& filenames)
{
const LLInventoryItem* item = getItem();
if (item && mPreviewToSave)
{
mPreviewToSave = false;
LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", item->getUUID());
}
// remember the user-approved/edited file name.
mSaveFileName = filenames[0];
mSavingMultiple = false;
mLoadingFullImage = true;
getWindow()->incBusyCount();
LL_DEBUGS("FileSaveAs") << "Scheduling saving file to " << mSaveFileName << LL_ENDL;
mImage->forceToSaveRawImage(0);//re-fetch the raw image if the old one is removed.
mImage->setLoadedCallback(LLPreviewTexture::onFileLoadedForSave,
0, true, false, new LLUUID(mItemUUID), &mCallbackTextureList);
}
void LLPreviewTexture::saveMultipleToFile(const std::string& file_name)
{
std::string texture_location(gSavedSettings.getString("TextureSaveLocation"));
std::string texture_name = LLDir::getScrubbedFileName(file_name.empty() ? getItem()->getName() : file_name);
mSaveFileName = texture_location + gDirUtilp->getDirDelimiter() + texture_name + ".png";
mSavingMultiple = true;
mLoadingFullImage = true;
getWindow()->incBusyCount();
LL_DEBUGS("FileSaveAs") << "Scheduling saving file to " << mSaveFileName << LL_ENDL;
mImage->forceToSaveRawImage(0);//re-fetch the raw image if the old one is removed.
mImage->setLoadedCallback(LLPreviewTexture::onFileLoadedForSave,
0, true, false, new LLUUID(mItemUUID), &mCallbackTextureList);
}
// virtual
void LLPreviewTexture::reshape(S32 width, S32 height, bool called_from_parent)
{
LLPreview::reshape(width, height, called_from_parent);
S32 horiz_pad = 2 * (LLPANEL_BORDER_WIDTH + PREVIEW_PAD) + PREVIEW_RESIZE_HANDLE_SIZE;
// add space for dimensions and aspect ratio
S32 info_height = CLIENT_RECT_VPAD;
if (mDimensionsText)
{
LLRect dim_rect(mDimensionsText->getRect());
info_height += dim_rect.mTop;
}
if (mButtonsPanel && mButtonsPanel->getVisible())
{
info_height += mButtonsPanel->getRect().getHeight();
}
LLRect client_rect(horiz_pad, getRect().getHeight(), getRect().getWidth() - horiz_pad, 0);
client_rect.mTop -= (PREVIEW_HEADER_SIZE + CLIENT_RECT_VPAD);
client_rect.mBottom += PREVIEW_BORDER + CLIENT_RECT_VPAD + info_height ;
S32 client_width = client_rect.getWidth();
S32 client_height = client_rect.getHeight();
if (mAspectRatio > 0.f)
{
if(mAspectRatio > 1.f)
{
client_height = llceil((F32)client_width / mAspectRatio);
if(client_height > client_rect.getHeight())
{
client_height = client_rect.getHeight();
client_width = llceil((F32)client_height * mAspectRatio);
}
}
else//mAspectRatio < 1.f
{
client_width = llceil((F32)client_height * mAspectRatio);
if(client_width > client_rect.getWidth())
{
client_width = client_rect.getWidth();
client_height = llceil((F32)client_width / mAspectRatio);
}
}
}
mClientRect.setLeftTopAndSize(client_rect.getCenterX() - (client_width / 2), client_rect.getCenterY() + (client_height / 2), client_width, client_height);
}
// virtual
void LLPreviewTexture::onFocusReceived()
{
LLPreview::onFocusReceived();
}
void LLPreviewTexture::openToSave()
{
mPreviewToSave = true;
}
void LLPreviewTexture::hideCtrlButtons()
{
getChildView("desc txt")->setVisible(false);
getChildView("desc")->setVisible(false);
getChild<LLLayoutStack>("preview_stack")->collapsePanel(mButtonsPanel, true);
mButtonsPanel->setVisible(false);
getChild<LLComboBox>("combo_aspect_ratio")->setCurrentByIndex(0); //unconstrained
reshape(getRect().getWidth(), getRect().getHeight());
}
// static
void LLPreviewTexture::onFileLoadedForSave(bool success,
LLViewerFetchedTexture *src_vi,
LLImageRaw* src,
LLImageRaw* aux_src,
S32 discard_level,
bool final,
void* userdata)
{
LLUUID* item_uuid = (LLUUID*) userdata;
LLPreviewTexture* self = LLFloaterReg::findTypedInstance<LLPreviewTexture>("preview_texture", *item_uuid);
if( final || !success )
{
delete item_uuid;
if( self )
{
self->getWindow()->decBusyCount();
self->mLoadingFullImage = false;
}
if (!success)
{
LL_WARNS("FileSaveAs") << "Failed to download file " << *item_uuid << " for saving."
<< " Is missing: " << (src_vi->isMissingAsset() ? "true" : "false")
<< " Discard: " << src_vi->getDiscardLevel()
<< " Raw discard: " << discard_level
<< " Size: " << src_vi->getWidth() << "x" << src_vi->getHeight()
<< " Has GL texture: " << (src_vi->hasGLTexture() ? "true" : "false")
<< " Has saved raw image: " << (src_vi->hasSavedRawImage() ? "true" : "false") << LL_ENDL;
}
}
if( self && final && success )
{
LL_DEBUGS("FileSaveAs") << "Saving file to " << self->mSaveFileName << LL_ENDL;
const U32 ext_length = 3;
std::string extension = self->mSaveFileName.substr( self->mSaveFileName.length() - ext_length);
std::string filepath;
if (self->mSavingMultiple)
{
std::string part_path = self->mSaveFileName.substr(0, self->mSaveFileName.length() - ext_length - 1);
S32 i = 0;
S32 err = 0;
do
{
filepath = part_path;
if (i != 0)
{
filepath += llformat("_%.3d", i);
}
filepath += ".";
filepath += extension;
llstat stat_info;
err = LLFile::stat(filepath, &stat_info);
i++;
} while (-1 != err); // Search until the file is not found (i.e., stat() gives an error).
}
else
{
filepath = self->mSaveFileName;
}
LLStringUtil::toLower(extension);
// We only support saving in PNG or TGA format
LLPointer<LLImageFormatted> image;
if(extension == "png")
{
image = new LLImagePNG;
}
else if(extension == "tga")
{
image = new LLImageTGA;
}
if( image && !image->encode( src, 0 ) )
{
LLSD args;
args["FILE"] = filepath;
LLNotificationsUtil::add("CannotEncodeFile", args);
}
else if( image && !image->save(filepath) )
{
LLSD args;
args["FILE"] = filepath;
LLNotificationsUtil::add("CannotWriteFile", args);
}
else
{
self->mSavedFileTimer.reset();
self->mSavedFileTimer.setTimerExpirySec( SECONDS_TO_SHOW_FILE_SAVED_MSG );
}
LL_DEBUGS("FileSaveAs") << "Done saving file to " << filepath << LL_ENDL;
self->mSaveFileName.clear();
}
if( self && !success )
{
LLNotificationsUtil::add("CannotDownloadFile");
}
}
// It takes a while until we get height and width information.
// When we receive it, reshape the window accordingly.
void LLPreviewTexture::updateDimensions()
{
if (!mImage)
{
return;
}
if ((mImage->getFullWidth() * mImage->getFullHeight()) == 0)
{
return;
}
S32 img_width = mImage->getFullWidth();
S32 img_height = mImage->getFullHeight();
if (mAssetStatus != PREVIEW_ASSET_LOADED
|| mLastWidth != img_width
|| mLastHeight != img_height)
{
mAssetStatus = PREVIEW_ASSET_LOADED;
// Asset has been fully loaded, adjust aspect ratio
adjustAspectRatio();
}
// Update the width/height display every time
mDimensionsText->setTextArg("[WIDTH]", llformat("%d", img_width));
mDimensionsText->setTextArg("[HEIGHT]", llformat("%d", img_height));
mLastHeight = img_height;
mLastWidth = img_width;
// Reshape the floater only when required
if (mUpdateDimensions)
{
mUpdateDimensions = false;
//reshape floater
reshape(getRect().getWidth(), getRect().getHeight());
gFloaterView->adjustToFitScreen(this, false);
LLRect dim_rect(mDimensionsText->getRect());
LLRect aspect_label_rect(mAspectRatioText->getRect());
mAspectRatioText->setVisible( dim_rect.mRight < aspect_label_rect.mLeft);
}
}
// Return true if everything went fine, false if we somewhat modified the ratio as we bumped on border values
bool LLPreviewTexture::setAspectRatio(const F32 width, const F32 height)
{
mUpdateDimensions = true;
// We don't allow negative width or height. Also, if height is positive but too small, we reset to default
// A default 0.f value for mAspectRatio means "unconstrained" in the rest of the code
if ((width <= 0.f) || (height <= F_APPROXIMATELY_ZERO))
{
mAspectRatio = 0.f;
return false;
}
// Compute and store the ratio
F32 ratio = width / height;
mAspectRatio = llclamp(ratio, PREVIEW_TEXTURE_MIN_ASPECT, PREVIEW_TEXTURE_MAX_ASPECT);
// Return false if we clamped the value, true otherwise
return (ratio == mAspectRatio);
}
void LLPreviewTexture::onAspectRatioCommit(LLUICtrl* ctrl, void* userdata)
{
LLPreviewTexture* self = (LLPreviewTexture*) userdata;
std::string ratio(ctrl->getValue().asString());
std::string::size_type separator(ratio.find_first_of(":/\\"));
if (std::string::npos == separator) {
// If there's no separator assume we want an unconstrained ratio
self->setAspectRatio( 0.f, 0.f );
return;
}
F32 width, height;
std::istringstream numerator(ratio.substr(0, separator));
std::istringstream denominator(ratio.substr(separator + 1));
numerator >> width;
denominator >> height;
self->setAspectRatio( width, height );
}
void LLPreviewTexture::loadAsset()
{
mImage = LLViewerTextureManager::getFetchedTexture(mImageID, FTT_DEFAULT, MIPMAP_TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
mImageOldBoostLevel = mImage->getBoostLevel();
mImage->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
mImage->forceToSaveRawImage(0) ;
mAssetStatus = PREVIEW_ASSET_LOADING;
mUpdateDimensions = true;
updateDimensions();
getChildView("save_tex_btn")->setEnabled(canSaveAs());
if (mObjectUUID.notNull())
{
// check that we can copy inworld items into inventory
getChildView("Keep")->setEnabled(mIsCopyable);
}
else
{
// check that we can remove item
bool source_library = gInventory.isObjectDescendentOf(mItemUUID, gInventory.getLibraryRootFolderID());
if (source_library)
{
getChildView("Discard")->setEnabled(false);
}
}
}
LLPreview::EAssetStatus LLPreviewTexture::getAssetStatus()
{
if (mImage.notNull() && (mImage->getFullWidth() * mImage->getFullHeight() > 0))
{
mAssetStatus = PREVIEW_ASSET_LOADED;
}
return mAssetStatus;
}
void LLPreviewTexture::adjustAspectRatio()
{
S32 w = mImage->getFullWidth();
S32 h = mImage->getFullHeight();
// Determine aspect ratio of the image
S32 tmp;
while (h != 0)
{
tmp = w % h;
w = h;
h = tmp;
}
S32 divisor = w;
S32 num = mImage->getFullWidth() / divisor;
S32 denom = mImage->getFullHeight() / divisor;
if (setAspectRatio((F32)num, (F32)denom))
{
// Select corresponding ratio entry in the combo list
LLComboBox* combo = getChild<LLComboBox>("combo_aspect_ratio");
if (combo)
{
std::ostringstream ratio;
ratio << num << ":" << denom;
std::vector<std::string>::const_iterator found = std::find(mRatiosList.begin(), mRatiosList.end(), ratio.str());
if (found == mRatiosList.end())
{
// No existing ratio found, create an element that will show image at original ratio
populateRatioList(); // makes sure previous custom ratio is cleared
std::string ratio = std::to_string(num)+":" + std::to_string(denom);
mRatiosList.push_back(ratio);
combo->add(ratio);
combo->setCurrentByIndex(static_cast<S32>(mRatiosList.size()) - 1);
}
else
{
combo->setCurrentByIndex((S32)(found - mRatiosList.begin()));
}
}
}
else
{
// Aspect ratio was set to unconstrained or was clamped
LLComboBox* combo = getChild<LLComboBox>("combo_aspect_ratio");
if (combo)
{
combo->setCurrentByIndex(0); //unconstrained
}
}
mUpdateDimensions = true;
}
void LLPreviewTexture::updateImageID()
{
const LLViewerInventoryItem *item = static_cast<const LLViewerInventoryItem*>(getItem());
if(item)
{
mImageID = item->getAssetUUID();
// here's the old logic...
//mShowKeepDiscard = item->getPermissions().getCreator() != gAgent.getID();
// here's the new logic... 'cos we hate disappearing buttons.
mShowKeepDiscard = true;
mCopyToInv = false;
LLPermissions perm(item->getPermissions());
mIsCopyable = perm.allowCopyBy(gAgent.getID(), gAgent.getGroupID()) && perm.allowTransferTo(gAgent.getID());
mIsFullPerm = item->checkPermissionsSet(PERM_ITEM_UNRESTRICTED);
}
else // not an item, assume it's an asset id
{
mImageID = mItemUUID;
mShowKeepDiscard = false;
mCopyToInv = true;
mIsCopyable = true;
mIsFullPerm = true;
}
}
/* virtual */
void LLPreviewTexture::setObjectID(const LLUUID& object_id)
{
mObjectUUID = object_id;
const LLUUID old_image_id = mImageID;
// Update what image we're pointing to, such as if we just specified the mObjectID
// that this mItemID is part of.
updateImageID();
// If the imageID has changed, start over and reload the new image.
if (mImageID != old_image_id)
{
mAssetStatus = PREVIEW_ASSET_UNLOADED;
loadAsset();
}
refreshFromItem();
}
|