summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewtexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpreviewtexture.cpp')
-rwxr-xr-xindra/newview/llpreviewtexture.cpp69
1 files changed, 67 insertions, 2 deletions
diff --git a/indra/newview/llpreviewtexture.cpp b/indra/newview/llpreviewtexture.cpp
index 1ed48a978f..0ef7326678 100755
--- a/indra/newview/llpreviewtexture.cpp
+++ b/indra/newview/llpreviewtexture.cpp
@@ -71,7 +71,8 @@ LLPreviewTexture::LLPreviewTexture(const LLSD& key)
mAspectRatio(0.f),
mPreviewToSave(FALSE),
mImage(NULL),
- mImageOldBoostLevel(LLGLTexture::BOOST_NONE)
+ mImageOldBoostLevel(LLGLTexture::BOOST_NONE),
+ mRatiosList(NULL)
{
updateImageID();
if (key.has("save_as"))
@@ -127,9 +128,27 @@ BOOL LLPreviewTexture::postBuild()
getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
}
}
+
+ // Fill in ratios list with common aspect ratio values
+ mRatiosList.clear();
+ mRatiosList.push_back("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");
- childSetCommitCallback("combo_aspect_ratio", onAspectRatioCommit, this);
+ // Now fill combo box with provided list
LLComboBox* combo = getChild<LLComboBox>("combo_aspect_ratio");
+
+ for (std::vector<std::string>::const_iterator it = mRatiosList.begin(); it != mRatiosList.end(); ++it)
+ {
+ combo->add(*it);
+ }
+
+ childSetCommitCallback("combo_aspect_ratio", onAspectRatioCommit, this);
combo->setCurrentByIndex(0);
return LLPreview::postBuild();
@@ -414,6 +433,13 @@ void LLPreviewTexture::updateDimensions()
{
return;
}
+
+ if (mAssetStatus != PREVIEW_ASSET_LOADED)
+ {
+ mAssetStatus = PREVIEW_ASSET_LOADED;
+ // Asset has been fully loaded, adjust aspect ratio
+ adjustAspectRatio();
+ }
// Update the width/height display every time
getChild<LLUICtrl>("dimensions")->setTextArg("[WIDTH]", llformat("%d", mImage->getFullWidth()));
@@ -501,6 +527,45 @@ LLPreview::EAssetStatus LLPreviewTexture::getAssetStatus()
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(num, denom))
+ {
+ // Select corresponding ratio entry in the combo list
+ LLComboBox* combo = getChild<LLComboBox>("combo_aspect_ratio");
+ if (combo)
+ {
+ std::string ratio = std::to_string((ULONGLONG)num) + ":" + std::to_string((ULONGLONG)denom);
+ std::vector<std::string>::const_iterator found = std::find(mRatiosList.begin(), mRatiosList.end(), ratio);
+ if (found == mRatiosList.end())
+ {
+ combo->setCurrentByIndex(0);
+ }
+ else
+ {
+ combo->setCurrentByIndex(found - mRatiosList.begin());
+ }
+ }
+ }
+
+ mUpdateDimensions = TRUE;
+}
+
void LLPreviewTexture::updateImageID()
{
const LLViewerInventoryItem *item = static_cast<const LLViewerInventoryItem*>(getItem());