From 39e76aaea873094114471ff80203f941d108f7b8 Mon Sep 17 00:00:00 2001 From: MaximB ProductEngine Date: Wed, 1 Jan 2014 03:43:56 +0200 Subject: MAINT-3592 (Viewer opening square textures should set the 1:1 size constraint) --- indra/newview/llpreviewtexture.cpp | 69 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'indra/newview/llpreviewtexture.cpp') 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("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("combo_aspect_ratio"); + + for (std::vector::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("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("combo_aspect_ratio"); + if (combo) + { + std::string ratio = std::to_string((ULONGLONG)num) + ":" + std::to_string((ULONGLONG)denom); + std::vector::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(getItem()); -- cgit v1.2.3 From dd1bd943b9b0a91ccd4d7676bba5eb5277bf0fbe Mon Sep 17 00:00:00 2001 From: MaximB ProductEngine Date: Thu, 2 Jan 2014 22:29:46 +0200 Subject: MAINT-3592 (Viewer opening square textures should set the 1:1 size constraint) --- indra/newview/llpreviewtexture.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'indra/newview/llpreviewtexture.cpp') diff --git a/indra/newview/llpreviewtexture.cpp b/indra/newview/llpreviewtexture.cpp index 0ef7326678..50af5aea1f 100755 --- a/indra/newview/llpreviewtexture.cpp +++ b/indra/newview/llpreviewtexture.cpp @@ -131,7 +131,7 @@ BOOL LLPreviewTexture::postBuild() // Fill in ratios list with common aspect ratio values mRatiosList.clear(); - mRatiosList.push_back("Unconstrained"); + mRatiosList.push_back(LLTrans::getString("Unconstrained")); mRatiosList.push_back("1:1"); mRatiosList.push_back("4:3"); mRatiosList.push_back("10:7"); @@ -142,6 +142,7 @@ BOOL LLPreviewTexture::postBuild() // Now fill combo box with provided list LLComboBox* combo = getChild("combo_aspect_ratio"); + combo->removeall(); for (std::vector::const_iterator it = mRatiosList.begin(); it != mRatiosList.end(); ++it) { -- cgit v1.2.3 From a773cdd6f7e95c44c2fc11e020addf60a970cb8f Mon Sep 17 00:00:00 2001 From: Simon Linden Date: Wed, 8 Jan 2014 02:36:12 +0000 Subject: Fix linux build --- indra/newview/llpreviewtexture.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/llpreviewtexture.cpp') diff --git a/indra/newview/llpreviewtexture.cpp b/indra/newview/llpreviewtexture.cpp index 50af5aea1f..5c41c5ad97 100755 --- a/indra/newview/llpreviewtexture.cpp +++ b/indra/newview/llpreviewtexture.cpp @@ -71,8 +71,7 @@ LLPreviewTexture::LLPreviewTexture(const LLSD& key) mAspectRatio(0.f), mPreviewToSave(FALSE), mImage(NULL), - mImageOldBoostLevel(LLGLTexture::BOOST_NONE), - mRatiosList(NULL) + mImageOldBoostLevel(LLGLTexture::BOOST_NONE) { updateImageID(); if (key.has("save_as")) @@ -551,8 +550,9 @@ void LLPreviewTexture::adjustAspectRatio() LLComboBox* combo = getChild("combo_aspect_ratio"); if (combo) { - std::string ratio = std::to_string((ULONGLONG)num) + ":" + std::to_string((ULONGLONG)denom); - std::vector::const_iterator found = std::find(mRatiosList.begin(), mRatiosList.end(), ratio); + std::ostringstream ratio; + ratio << num << ":" << denom; + std::vector::const_iterator found = std::find(mRatiosList.begin(), mRatiosList.end(), ratio.str()); if (found == mRatiosList.end()) { combo->setCurrentByIndex(0); -- cgit v1.2.3