Skip to content
Snippets Groups Projects
Commit 39e76aae authored by MaximB ProductEngine's avatar MaximB ProductEngine
Browse files

MAINT-3592 (Viewer opening square textures should set the 1:1 size constraint)

parent ab71e294
Branches
Tags
No related merge requests found
...@@ -71,7 +71,8 @@ LLPreviewTexture::LLPreviewTexture(const LLSD& key) ...@@ -71,7 +71,8 @@ LLPreviewTexture::LLPreviewTexture(const LLSD& key)
mAspectRatio(0.f), mAspectRatio(0.f),
mPreviewToSave(FALSE), mPreviewToSave(FALSE),
mImage(NULL), mImage(NULL),
mImageOldBoostLevel(LLGLTexture::BOOST_NONE) mImageOldBoostLevel(LLGLTexture::BOOST_NONE),
mRatiosList(NULL)
{ {
updateImageID(); updateImageID();
if (key.has("save_as")) if (key.has("save_as"))
...@@ -128,8 +129,26 @@ BOOL LLPreviewTexture::postBuild() ...@@ -128,8 +129,26 @@ BOOL LLPreviewTexture::postBuild()
} }
} }
childSetCommitCallback("combo_aspect_ratio", onAspectRatioCommit, this); // 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");
// Now fill combo box with provided list
LLComboBox* combo = getChild<LLComboBox>("combo_aspect_ratio"); 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); combo->setCurrentByIndex(0);
return LLPreview::postBuild(); return LLPreview::postBuild();
...@@ -415,6 +434,13 @@ void LLPreviewTexture::updateDimensions() ...@@ -415,6 +434,13 @@ void LLPreviewTexture::updateDimensions()
return; 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 // Update the width/height display every time
getChild<LLUICtrl>("dimensions")->setTextArg("[WIDTH]", llformat("%d", mImage->getFullWidth())); getChild<LLUICtrl>("dimensions")->setTextArg("[WIDTH]", llformat("%d", mImage->getFullWidth()));
getChild<LLUICtrl>("dimensions")->setTextArg("[HEIGHT]", llformat("%d", mImage->getFullHeight())); getChild<LLUICtrl>("dimensions")->setTextArg("[HEIGHT]", llformat("%d", mImage->getFullHeight()));
...@@ -501,6 +527,45 @@ LLPreview::EAssetStatus LLPreviewTexture::getAssetStatus() ...@@ -501,6 +527,45 @@ LLPreview::EAssetStatus LLPreviewTexture::getAssetStatus()
return mAssetStatus; 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() void LLPreviewTexture::updateImageID()
{ {
const LLViewerInventoryItem *item = static_cast<const LLViewerInventoryItem*>(getItem()); const LLViewerInventoryItem *item = static_cast<const LLViewerInventoryItem*>(getItem());
......
...@@ -70,6 +70,7 @@ class LLPreviewTexture : public LLPreview ...@@ -70,6 +70,7 @@ class LLPreviewTexture : public LLPreview
/* virtual */ BOOL postBuild(); /* virtual */ BOOL postBuild();
bool setAspectRatio(const F32 width, const F32 height); bool setAspectRatio(const F32 width, const F32 height);
static void onAspectRatioCommit(LLUICtrl*,void* userdata); static void onAspectRatioCommit(LLUICtrl*,void* userdata);
void adjustAspectRatio();
private: private:
void updateImageID(); // set what image is being uploaded. void updateImageID(); // set what image is being uploaded.
...@@ -95,5 +96,6 @@ class LLPreviewTexture : public LLPreview ...@@ -95,5 +96,6 @@ class LLPreviewTexture : public LLPreview
F32 mAspectRatio; F32 mAspectRatio;
LLLoadedCallbackEntry::source_callback_list_t mCallbackTextureList ; LLLoadedCallbackEntry::source_callback_list_t mCallbackTextureList ;
std::vector<std::string> mRatiosList;
}; };
#endif // LL_LLPREVIEWTEXTURE_H #endif // LL_LLPREVIEWTEXTURE_H
...@@ -79,30 +79,6 @@ ...@@ -79,30 +79,6 @@
width="108" width="108"
name="combo_aspect_ratio" name="combo_aspect_ratio"
tool_tip="Preview at a fixed 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> </combo_box>
<button <button
follows="right|bottom" follows="right|bottom"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment