diff options
author | MaximB ProductEngine <mberezhnoy@productengine.com> | 2014-01-01 03:43:56 +0200 |
---|---|---|
committer | MaximB ProductEngine <mberezhnoy@productengine.com> | 2014-01-01 03:43:56 +0200 |
commit | 39e76aaea873094114471ff80203f941d108f7b8 (patch) | |
tree | d7b3149c19a6fb6cf40efa5ad766d6ef38076f38 /indra/newview | |
parent | ab71e294e00270aada33b283bdae7566ef93f6e2 (diff) |
MAINT-3592 (Viewer opening square textures should set the 1:1 size constraint)
Diffstat (limited to 'indra/newview')
-rwxr-xr-x | indra/newview/llpreviewtexture.cpp | 69 | ||||
-rwxr-xr-x | indra/newview/llpreviewtexture.h | 2 | ||||
-rwxr-xr-x | indra/newview/skins/default/xui/en/floater_preview_texture.xml | 24 |
3 files changed, 69 insertions, 26 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()); diff --git a/indra/newview/llpreviewtexture.h b/indra/newview/llpreviewtexture.h index cd16bacde2..97e74706cc 100755 --- a/indra/newview/llpreviewtexture.h +++ b/indra/newview/llpreviewtexture.h @@ -70,6 +70,7 @@ protected: /* virtual */ BOOL postBuild(); bool setAspectRatio(const F32 width, const F32 height); static void onAspectRatioCommit(LLUICtrl*,void* userdata); + void adjustAspectRatio(); private: void updateImageID(); // set what image is being uploaded. @@ -95,5 +96,6 @@ private: F32 mAspectRatio; LLLoadedCallbackEntry::source_callback_list_t mCallbackTextureList ; + std::vector<std::string> mRatiosList; }; #endif // LL_LLPREVIEWTEXTURE_H diff --git a/indra/newview/skins/default/xui/en/floater_preview_texture.xml b/indra/newview/skins/default/xui/en/floater_preview_texture.xml index 137e278ddc..e1e7e1c8c8 100755 --- a/indra/newview/skins/default/xui/en/floater_preview_texture.xml +++ b/indra/newview/skins/default/xui/en/floater_preview_texture.xml @@ -79,30 +79,6 @@ width="108" name="combo_aspect_ratio" tool_tip="Preview at a fixed aspect ratio"> - <combo_item name="Unconstrained" value="Unconstrained"> - Unconstrained - </combo_item> - <combo_item name="1:1" value="1:1" tool_tip="Group insignia or Real World profile"> - 1:1 - </combo_item> - <combo_item name="4:3" value="4:3" tool_tip="[SECOND_LIFE] profile"> - 4:3 - </combo_item> - <combo_item name="10:7" value="10:7" tool_tip="Classifieds and search listings, landmarks"> - 10:7 - </combo_item> - <combo_item name="3:2" value="3:2" tool_tip="About land"> - 3:2 - </combo_item> - <combo_item name="16:10" value="16:10"> - 16:10 - </combo_item> - <combo_item name="16:9" value="16:9" tool_tip="Profile picks"> - 16:9 - </combo_item> - <combo_item name="2:1" value="2:1"> - 2:1 - </combo_item> </combo_box> <button follows="right|bottom" |