diff options
Diffstat (limited to 'indra/newview/llfloatersnapshot.cpp')
-rw-r--r-- | indra/newview/llfloatersnapshot.cpp | 660 |
1 files changed, 273 insertions, 387 deletions
diff --git a/indra/newview/llfloatersnapshot.cpp b/indra/newview/llfloatersnapshot.cpp index 48e6cca623..d8d62e5bbb 100644 --- a/indra/newview/llfloatersnapshot.cpp +++ b/indra/newview/llfloatersnapshot.cpp @@ -100,9 +100,6 @@ S32 BORDER_WIDTH = 6; const S32 MAX_POSTCARD_DATASIZE = 1024 * 1024; // one megabyte const S32 MAX_TEXTURE_SIZE = 512 ; //max upload texture size 512 * 512 -static std::string lastSnapshotWidthName(S32 shot_type); -static std::string lastSnapshotHeightName(S32 shot_type); - static LLDefaultChildRegistry::Register<LLSnapshotFloaterView> r("snapshot_floater_view"); ///---------------------------------------------------------------------------- @@ -138,7 +135,11 @@ public: /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent); void setSize(S32 w, S32 h); + void setWidth(S32 w) { mWidth[mCurImageIndex] = w; } + void setHeight(S32 h) { mHeight[mCurImageIndex] = h; } void getSize(S32& w, S32& h) const; + S32 getWidth() const { return mWidth[mCurImageIndex]; } + S32 getHeight() const { return mHeight[mCurImageIndex]; } S32 getDataSize() const { return mDataSize; } void setMaxImageSize(S32 size) ; S32 getMaxImageSize() {return mMaxImageSize ;} @@ -155,8 +156,9 @@ public: LLViewerTexture* getCurrentImage(); F32 getImageAspect(); F32 getAspect() ; - LLRect getImageRect(); - BOOL isImageScaled(); + const LLRect& getImageRect() const { return mImageRect[mCurImageIndex]; } + BOOL isImageScaled() const { return mImageScaled[mCurImageIndex]; } + void setImageScaled(BOOL scaled) { mImageScaled[mCurImageIndex] = scaled; } const LLVector3d& getPosTakenGlobal() const { return mPosTakenGlobal; } void setSnapshotType(ESnapshotType type) { mSnapshotType = type; } @@ -171,6 +173,7 @@ public: LLPointer<LLImageFormatted> getFormattedImage() const { return mFormattedImage; } LLPointer<LLImageRaw> getEncodedImage() const { return mPreviewImageEncoded; } + /// Sets size of preview thumbnail image and thhe surrounding rect. BOOL setThumbnailImageSize() ; void generateThumbnailImage(BOOL force_update = FALSE) ; void resetThumbnailImage() { mThumbnailImage = NULL ; } @@ -299,7 +302,7 @@ LLViewerTexture* LLSnapshotLivePreview::getCurrentImage() F32 LLSnapshotLivePreview::getAspect() { - F32 image_aspect_ratio = ((F32)mWidth[mCurImageIndex]) / ((F32)mHeight[mCurImageIndex]); + F32 image_aspect_ratio = ((F32)getWidth()) / ((F32)getHeight()); F32 window_aspect_ratio = ((F32)getRect().getWidth()) / ((F32)getRect().getHeight()); if (!mKeepAspectRatio)//gSavedSettings.getBOOL("KeepAspectForSnapshot")) @@ -314,7 +317,7 @@ F32 LLSnapshotLivePreview::getAspect() F32 LLSnapshotLivePreview::getImageAspect() { - if (!mViewerImage[mCurImageIndex]) + if (!getCurrentImage()) { return 0.f; } @@ -322,33 +325,24 @@ F32 LLSnapshotLivePreview::getImageAspect() return getAspect() ; } -LLRect LLSnapshotLivePreview::getImageRect() -{ - return mImageRect[mCurImageIndex]; -} - -BOOL LLSnapshotLivePreview::isImageScaled() -{ - return mImageScaled[mCurImageIndex]; -} - void LLSnapshotLivePreview::updateSnapshot(BOOL new_snapshot, BOOL new_thumbnail, F32 delay) { - lldebugs << "updateSnapshot: mSnapshotUpToDate = " << mSnapshotUpToDate << llendl; - if (mSnapshotUpToDate) + // Invalidate current image. + lldebugs << "updateSnapshot: mSnapshotUpToDate = " << getSnapshotUpToDate() << llendl; + if (getSnapshotUpToDate()) { S32 old_image_index = mCurImageIndex; mCurImageIndex = (mCurImageIndex + 1) % 2; - mWidth[mCurImageIndex] = mWidth[old_image_index]; - mHeight[mCurImageIndex] = mHeight[old_image_index]; + setSize(mWidth[old_image_index], mHeight[old_image_index]); mFallAnimTimer.start(); } mSnapshotUpToDate = FALSE; + // Update snapshot source rect depending on whether we keep the aspect ratio. LLRect& rect = mImageRect[mCurImageIndex]; rect.set(0, getRect().getHeight(), getRect().getWidth(), 0); - F32 image_aspect_ratio = ((F32)mWidth[mCurImageIndex]) / ((F32)mHeight[mCurImageIndex]); + F32 image_aspect_ratio = ((F32)getWidth()) / ((F32)getHeight()); F32 window_aspect_ratio = ((F32)getRect().getWidth()) / ((F32)getRect().getHeight()); if (mKeepAspectRatio)//gSavedSettings.getBOOL("KeepAspectForSnapshot")) @@ -369,18 +363,22 @@ void LLSnapshotLivePreview::updateSnapshot(BOOL new_snapshot, BOOL new_thumbnail } } + // Stop shining animation. mShineAnimTimer.stop(); + + // Update snapshot if requested. if (new_snapshot) { mSnapshotDelayTimer.start(); mSnapshotDelayTimer.setTimerExpirySec(delay); LLFloaterSnapshot::preUpdate(); } + + // Update thumbnail if requested. if(new_thumbnail) { mThumbnailUpToDate = FALSE ; } - setThumbnailImageSize(); } void LLSnapshotLivePreview::setSnapshotQuality(S32 quality) @@ -436,26 +434,26 @@ void LLSnapshotLivePreview::drawPreviewRect(S32 offset_x, S32 offset_y) //called when the frame is frozen. void LLSnapshotLivePreview::draw() { - if (mViewerImage[mCurImageIndex].notNull() && + if (getCurrentImage() && mPreviewImageEncoded.notNull() && - mSnapshotUpToDate) + getSnapshotUpToDate()) { LLColor4 bg_color(0.f, 0.f, 0.3f, 0.4f); gl_rect_2d(getRect(), bg_color); - LLRect &rect = mImageRect[mCurImageIndex]; - LLRect shadow_rect = mImageRect[mCurImageIndex]; + const LLRect& rect = getImageRect(); + LLRect shadow_rect = rect; shadow_rect.stretch(BORDER_WIDTH); gl_drop_shadow(shadow_rect.mLeft, shadow_rect.mTop, shadow_rect.mRight, shadow_rect.mBottom, LLColor4(0.f, 0.f, 0.f, mNeedsFlash ? 0.f :0.5f), 10); LLColor4 image_color(1.f, 1.f, 1.f, 1.f); gGL.color4fv(image_color.mV); - gGL.getTexUnit(0)->bind(mViewerImage[mCurImageIndex]); + gGL.getTexUnit(0)->bind(getCurrentImage()); // calculate UV scale - F32 uv_width = mImageScaled[mCurImageIndex] ? 1.f : llmin((F32)mWidth[mCurImageIndex] / (F32)mViewerImage[mCurImageIndex]->getWidth(), 1.f); - F32 uv_height = mImageScaled[mCurImageIndex] ? 1.f : llmin((F32)mHeight[mCurImageIndex] / (F32)mViewerImage[mCurImageIndex]->getHeight(), 1.f); - glPushMatrix(); + F32 uv_width = isImageScaled() ? 1.f : llmin((F32)getWidth() / (F32)getCurrentImage()->getWidth(), 1.f); + F32 uv_height = isImageScaled() ? 1.f : llmin((F32)getHeight() / (F32)getCurrentImage()->getHeight(), 1.f); + gGL.pushMatrix(); { - glTranslatef((F32)rect.mLeft, (F32)rect.mBottom, 0.f); + gGL.translatef((F32)rect.mLeft, (F32)rect.mBottom, 0.f); gGL.begin(LLRender::QUADS); { gGL.texCoord2f(uv_width, uv_height); @@ -472,7 +470,7 @@ void LLSnapshotLivePreview::draw() } gGL.end(); } - glPopMatrix(); + gGL.popMatrix(); gGL.color4f(1.f, 1.f, 1.f, mFlashAlpha); gl_rect_2d(getRect()); @@ -492,6 +490,7 @@ void LLSnapshotLivePreview::draw() mFlashAlpha = lerp(mFlashAlpha, 0.f, LLCriticalDamp::getInterpolant(0.15f)); } + // Draw shining animation if appropriate. if (mShineCountdown > 0) { mShineCountdown--; @@ -502,6 +501,7 @@ void LLSnapshotLivePreview::draw() } else if (mShineAnimTimer.getStarted()) { + lldebugs << "Drawing shining animation" << llendl; F32 shine_interp = llmin(1.f, mShineAnimTimer.getElapsedTimeF32() / SHINE_TIME); // draw "shine" effect @@ -546,7 +546,7 @@ void LLSnapshotLivePreview::draw() { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.color4f(1.f, 1.f, 1.f, 1.f); - LLRect outline_rect = mImageRect[mCurImageIndex]; + const LLRect& outline_rect = getImageRect(); gGL.begin(LLRender::QUADS); { gGL.vertex2i(outline_rect.mLeft - BORDER_WIDTH, outline_rect.mTop + BORDER_WIDTH); @@ -578,6 +578,7 @@ void LLSnapshotLivePreview::draw() S32 old_image_index = (mCurImageIndex + 1) % 2; if (mViewerImage[old_image_index].notNull() && mFallAnimTimer.getElapsedTimeF32() < FALL_TIME) { + lldebugs << "Drawing fall animation" << llendl; F32 fall_interp = mFallAnimTimer.getElapsedTimeF32() / FALL_TIME; F32 alpha = clamp_rescale(fall_interp, 0.f, 1.f, 0.8f, 0.4f); LLColor4 image_color(1.f, 1.f, 1.f, alpha); @@ -588,11 +589,11 @@ void LLSnapshotLivePreview::draw() BOOL rescale = !mImageScaled[old_image_index] && mViewerImage[mCurImageIndex].notNull(); F32 uv_width = rescale ? llmin((F32)mWidth[old_image_index] / (F32)mViewerImage[mCurImageIndex]->getWidth(), 1.f) : 1.f; F32 uv_height = rescale ? llmin((F32)mHeight[old_image_index] / (F32)mViewerImage[mCurImageIndex]->getHeight(), 1.f) : 1.f; - glPushMatrix(); + gGL.pushMatrix(); { LLRect& rect = mImageRect[old_image_index]; - glTranslatef((F32)rect.mLeft, (F32)rect.mBottom - llround(getRect().getHeight() * 2.f * (fall_interp * fall_interp)), 0.f); - glRotatef(-45.f * fall_interp, 0.f, 0.f, 1.f); + gGL.translatef((F32)rect.mLeft, (F32)rect.mBottom - llround(getRect().getHeight() * 2.f * (fall_interp * fall_interp)), 0.f); + gGL.rotatef(-45.f * fall_interp, 0.f, 0.f, 1.f); gGL.begin(LLRender::QUADS); { gGL.texCoord2f(uv_width, uv_height); @@ -609,7 +610,7 @@ void LLSnapshotLivePreview::draw() } gGL.end(); } - glPopMatrix(); + gGL.popMatrix(); } } } @@ -621,13 +622,14 @@ void LLSnapshotLivePreview::reshape(S32 width, S32 height, BOOL called_from_pare LLView::reshape(width, height, called_from_parent); if (old_rect.getWidth() != width || old_rect.getHeight() != height) { + lldebugs << "window reshaped, updating thumbnail" << llendl; updateSnapshot(FALSE, TRUE); } } BOOL LLSnapshotLivePreview::setThumbnailImageSize() { - if(mWidth[mCurImageIndex] < 10 || mHeight[mCurImageIndex] < 10) + if(getWidth() < 10 || getHeight() < 10) { return FALSE ; } @@ -663,11 +665,11 @@ BOOL LLSnapshotLivePreview::setThumbnailImageSize() S32 left = 0 , top = mThumbnailHeight, right = mThumbnailWidth, bottom = 0 ; if(!mKeepAspectRatio) { - F32 ratio_x = (F32)mWidth[mCurImageIndex] / window_width ; - F32 ratio_y = (F32)mHeight[mCurImageIndex] / window_height ; + F32 ratio_x = (F32)getWidth() / window_width ; + F32 ratio_y = (F32)getHeight() / window_height ; - //if(mWidth[mCurImageIndex] > window_width || - // mHeight[mCurImageIndex] > window_height ) + //if(getWidth() > window_width || + // getHeight() > window_height ) { if(ratio_x > ratio_y) { @@ -699,11 +701,11 @@ void LLSnapshotLivePreview::generateThumbnailImage(BOOL force_update) { return ; } - if(mThumbnailUpToDate && !force_update)//already updated + if(getThumbnailUpToDate() && !force_update)//already updated { return ; } - if(mWidth[mCurImageIndex] < 10 || mHeight[mCurImageIndex] < 10) + if(getWidth() < 10 || getHeight() < 10) { return ; } @@ -723,25 +725,19 @@ void LLSnapshotLivePreview::generateThumbnailImage(BOOL force_update) resetThumbnailImage() ; } - LLPointer<LLImageRaw> raw = NULL ; - S32 w , h ; - w = get_lower_power_two(mThumbnailWidth, 512) * 2 ; - h = get_lower_power_two(mThumbnailHeight, 512) * 2 ; - + LLPointer<LLImageRaw> raw = new LLImageRaw; + if(!gViewerWindow->thumbnailSnapshot(raw, + mThumbnailWidth, mThumbnailHeight, + gSavedSettings.getBOOL("RenderUIInSnapshot"), + FALSE, + mSnapshotBufferType) ) { - raw = new LLImageRaw ; - if(!gViewerWindow->thumbnailSnapshot(raw, - w, h, - gSavedSettings.getBOOL("RenderUIInSnapshot"), - FALSE, - mSnapshotBufferType) ) - { - raw = NULL ; - } + raw = NULL ; } if(raw) { + raw->expandToPowerOfTwo(); mThumbnailImage = LLViewerTextureManager::getLocalTexture(raw.get(), FALSE); mThumbnailUpToDate = TRUE ; } @@ -757,15 +753,13 @@ void LLSnapshotLivePreview::generateThumbnailImage(BOOL force_update) BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview ) { LLSnapshotLivePreview* previewp = (LLSnapshotLivePreview*)snapshot_preview; - -#if 1 // XXX tmp - if (previewp->mWidth[previewp->mCurImageIndex] == 0 || previewp->mHeight[previewp->mCurImageIndex] == 0) + if (previewp->getWidth() == 0 || previewp->getHeight() == 0) { - llwarns << "Incorrect dimensions: " << previewp->mWidth[previewp->mCurImageIndex] << "x" << previewp->mHeight[previewp->mCurImageIndex] << llendl; + llwarns << "Incorrect dimensions: " << previewp->getWidth() << "x" << previewp->getHeight() << llendl; return FALSE; } -#endif + // If we're in freeze-frame mode and camera has moved, update snapshot. LLVector3 new_camera_pos = LLViewerCamera::getInstance()->getOrigin(); LLQuaternion new_camera_rot = LLViewerCamera::getInstance()->getQuaternion(); if (gSavedSettings.getBOOL("FreezeTime") && @@ -775,6 +769,7 @@ BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview ) previewp->mCameraRot = new_camera_rot; // request a new snapshot whenever the camera moves, with a time delay BOOL autosnap = gSavedSettings.getBOOL("AutoSnapshot"); + lldebugs << "camera moved, updating thumbnail" << llendl; previewp->updateSnapshot( autosnap, // whether a new snapshot is needed or merely invalidate the existing one FALSE, // or if 1st arg is false, whether to produce a new thumbnail image. @@ -791,6 +786,7 @@ BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview ) } // time to produce a snapshot + previewp->setThumbnailImageSize(); lldebugs << "producing snapshot" << llendl; if (!previewp->mPreviewImage) @@ -807,13 +803,13 @@ BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview ) previewp->setEnabled(FALSE); previewp->getWindow()->incBusyCount(); - previewp->mImageScaled[previewp->mCurImageIndex] = FALSE; + previewp->setImageScaled(FALSE); // grab the raw image and encode it into desired format if(gViewerWindow->rawSnapshot( previewp->mPreviewImage, - previewp->mWidth[previewp->mCurImageIndex], - previewp->mHeight[previewp->mCurImageIndex], + previewp->getWidth(), + previewp->getHeight(), previewp->mKeepAspectRatio,//gSavedSettings.getBOOL("KeepAspectForSnapshot"), previewp->getSnapshotType() == LLSnapshotLivePreview::SNAPSHOT_TEXTURE, gSavedSettings.getBOOL("RenderUIInSnapshot"), @@ -836,8 +832,8 @@ BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview ) previewp->mPreviewImage->getHeight(), previewp->mPreviewImage->getComponents()); - scaled->biasedScaleToPowerOfTwo(512); - previewp->mImageScaled[previewp->mCurImageIndex] = TRUE; + scaled->biasedScaleToPowerOfTwo(MAX_TEXTURE_SIZE); + previewp->setImageScaled(TRUE); if (formatted->encode(scaled, 0.f)) { previewp->mDataSize = formatted->getDataSize(); @@ -892,7 +888,7 @@ BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview ) { // go ahead and shrink image to appropriate power of 2 for display scaled->biasedScaleToPowerOfTwo(1024); - previewp->mImageScaled[previewp->mCurImageIndex] = TRUE; + previewp->setImageScaled(TRUE); } else { @@ -939,14 +935,14 @@ BOOL LLSnapshotLivePreview::onIdle( void* snapshot_preview ) void LLSnapshotLivePreview::setSize(S32 w, S32 h) { lldebugs << "setSize(" << w << ", " << h << ")" << llendl; - mWidth[mCurImageIndex] = w; - mHeight[mCurImageIndex] = h; + setWidth(w); + setHeight(h); } void LLSnapshotLivePreview::getSize(S32& w, S32& h) const { - w = mWidth[mCurImageIndex]; - h = mHeight[mCurImageIndex]; + w = getWidth(); + h = getHeight(); } void LLSnapshotLivePreview::saveTexture() @@ -963,9 +959,9 @@ void LLSnapshotLivePreview::saveTexture() mPreviewImage->getHeight(), mPreviewImage->getComponents()); - scaled->biasedScaleToPowerOfTwo(512); + scaled->biasedScaleToPowerOfTwo(MAX_TEXTURE_SIZE); lldebugs << "scaled texture to " << scaled->getWidth() << "x" << scaled->getHeight() << llendl; - + if (formatted->encode(scaled, 0.0f)) { LLVFile::writeFile(formatted->getData(), formatted->getDataSize(), gVFS, new_asset_id, LLAssetType::AT_TEXTURE); @@ -1003,13 +999,7 @@ void LLSnapshotLivePreview::saveTexture() BOOL LLSnapshotLivePreview::saveLocal() { - BOOL success = gViewerWindow->saveImageNumbered(mFormattedImage, true); - - // Relinquish image memory. Save button will be disabled as a side-effect. - lldebugs << "resetting formatted image after saving to disk" << llendl; - mFormattedImage = NULL; - mDataSize = 0; - updateSnapshot(FALSE, FALSE); + BOOL success = gViewerWindow->saveImageNumbered(mFormattedImage); if(success) { @@ -1064,6 +1054,7 @@ public: : mAvatarPauseHandles(), mLastToolset(NULL), mAspectRatioCheckOff(false), + mNeedRefresh(false), mStatus(STATUS_READY) { } @@ -1079,25 +1070,18 @@ public: static void onClickMore(void* data) ; static void onClickUICheck(LLUICtrl *ctrl, void* data); static void onClickHUDCheck(LLUICtrl *ctrl, void* data); -#if 0 - static void onClickKeepAspectCheck(LLUICtrl *ctrl, void* data); -#endif static void applyKeepAspectCheck(LLFloaterSnapshot* view, BOOL checked); - static void onCommitResolution(LLUICtrl* ctrl, void* data) { updateResolution(ctrl, data); } static void updateResolution(LLUICtrl* ctrl, void* data, BOOL do_update = TRUE); static void onCommitFreezeFrame(LLUICtrl* ctrl, void* data); static void onCommitLayerTypes(LLUICtrl* ctrl, void*data); static void onImageQualityChange(LLFloaterSnapshot* view, S32 quality_val); static void onImageFormatChange(LLFloaterSnapshot* view); -#if 0 - static void onCommitSnapshotType(LLUICtrl* ctrl, void* data); - static void onCommitCustomResolution(LLUICtrl *ctrl, void* data); -#endif static void applyCustomResolution(LLFloaterSnapshot* view, S32 w, S32 h); static void onSnapshotUploadFinished(bool status); static void onSendingPostcardFinished(bool status); - static void resetSnapshotSizeOnUI(LLFloaterSnapshot *view, S32 width, S32 height) ; static BOOL checkImageSize(LLSnapshotLivePreview* previewp, S32& width, S32& height, BOOL isWidthChanged, S32 max_value); + static void setImageSizeSpinnersValues(LLFloaterSnapshot *view, S32 width, S32 height) ; + static void updateSpinners(LLFloaterSnapshot* view, LLSnapshotLivePreview* previewp, S32& width, S32& height, BOOL is_width_changed); static LLPanelSnapshot* getActivePanel(LLFloaterSnapshot* floater, bool ok_if_not_found = true); static LLSnapshotLivePreview::ESnapshotType getActiveSnapshotType(LLFloaterSnapshot* floater); @@ -1113,6 +1097,7 @@ public: static void updateLayout(LLFloaterSnapshot* floater); static void setStatus(EStatus status, bool ok = true, const std::string& msg = LLStringUtil::null); EStatus getStatus() const { return mStatus; } + static void setNeedRefresh(LLFloaterSnapshot* floater, bool need); private: static LLViewerWindow::ESnapshotType getLayerType(LLFloaterSnapshot* floater); @@ -1129,6 +1114,7 @@ public: LLToolset* mLastToolset; LLHandle<LLView> mPreviewHandle; bool mAspectRatioCheckOff ; + bool mNeedRefresh; EStatus mStatus; }; @@ -1251,7 +1237,7 @@ void LLFloaterSnapshot::Impl::updateLayout(LLFloaterSnapshot* floaterp) // Show/hide advanced options. LLPanel* advanced_options_panel = floaterp->getChild<LLPanel>("advanced_options_panel"); - floaterp->getChild<LLButton>("advanced_options_btn")->setToggleState(advanced); + floaterp->getChild<LLButton>("advanced_options_btn")->setImageOverlay(advanced ? "TabIcon_Open_Off" : "TabIcon_Close_Off"); if (advanced != advanced_options_panel->getVisible()) { S32 panel_width = advanced_options_panel->getRect().getWidth(); @@ -1266,16 +1252,9 @@ void LLFloaterSnapshot::Impl::updateLayout(LLFloaterSnapshot* floaterp) previewp->mKeepAspectRatio = TRUE; floaterp->getChild<LLComboBox>("profile_size_combo")->setCurrentByIndex(0); - gSavedSettings.setS32("SnapshotProfileLastResolution", 0); - floaterp->getChild<LLComboBox>("postcard_size_combo")->setCurrentByIndex(0); - gSavedSettings.setS32("SnapshotPostcardLastResolution", 0); - floaterp->getChild<LLComboBox>("texture_size_combo")->setCurrentByIndex(0); - gSavedSettings.setS32("SnapshotTextureLastResolution", 0); - floaterp->getChild<LLComboBox>("local_size_combo")->setCurrentByIndex(0); - gSavedSettings.setS32("SnapshotLocalLastResolution", 0); LLSnapshotLivePreview* previewp = getPreviewView(floaterp); previewp->setSize(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw()); @@ -1347,6 +1326,7 @@ void LLFloaterSnapshot::Impl::updateLayout(LLFloaterSnapshot* floaterp) // No other methods should be changing any of the controls directly except for helpers called by this method. // The basic pattern for programmatically changing the GUI settings is to first set the // appropriate saved settings and then call this method to sync the GUI with them. +// FIXME: The above comment seems obsolete now. // static void LLFloaterSnapshot::Impl::updateControls(LLFloaterSnapshot* floater) { @@ -1358,19 +1338,7 @@ void LLFloaterSnapshot::Impl::updateControls(LLFloaterSnapshot* floater) floater->getChildView("share_to_web")->setVisible( gSavedSettings.getBOOL("SnapshotSharingEnabled")); #endif -#if 0 - floater->getChildView("postcard_size_combo")->setVisible( FALSE); - floater->getChildView("texture_size_combo")->setVisible( FALSE); - floater->getChildView("local_size_combo")->setVisible( FALSE); -#endif - - floater->getChild<LLComboBox>("profile_size_combo")->selectNthItem(gSavedSettings.getS32("SnapshotProfileLastResolution")); - floater->getChild<LLComboBox>("postcard_size_combo")->selectNthItem(gSavedSettings.getS32("SnapshotPostcardLastResolution")); - floater->getChild<LLComboBox>("texture_size_combo")->selectNthItem(gSavedSettings.getS32("SnapshotTextureLastResolution")); - floater->getChild<LLComboBox>("local_size_combo")->selectNthItem(gSavedSettings.getS32("SnapshotLocalLastResolution")); floater->getChild<LLComboBox>("local_format_combo")->selectNthItem(gSavedSettings.getS32("SnapshotFormat")); - - // *TODO: Separate settings for Web images from postcards enableAspectRatioCheckbox(floater, !floater->impl.mAspectRatioCheckOff); setAspectRatioCheckboxValue(floater, gSavedSettings.getBOOL("KeepAspectForSnapshot")); floater->getChildView("layer_types")->setEnabled(shot_type == LLSnapshotLivePreview::SNAPSHOT_LOCAL); @@ -1384,19 +1352,20 @@ void LLFloaterSnapshot::Impl::updateControls(LLFloaterSnapshot* floater) // Initialize spinners. if (width_ctrl->getValue().asInteger() == 0) { - S32 w = gSavedSettings.getS32(lastSnapshotWidthName(shot_type)); + S32 w = gViewerWindow->getWindowWidthRaw(); lldebugs << "Initializing width spinner (" << width_ctrl->getName() << "): " << w << llendl; width_ctrl->setValue(w); } if (height_ctrl->getValue().asInteger() == 0) { - S32 h = gSavedSettings.getS32(lastSnapshotHeightName(shot_type)); + S32 h = gViewerWindow->getWindowHeightRaw(); lldebugs << "Initializing height spinner (" << height_ctrl->getName() << "): " << h << llendl; height_ctrl->setValue(h); } + // Сlamp snapshot resolution to window size when showing UI or HUD in snapshot. if (gSavedSettings.getBOOL("RenderUIInSnapshot") || gSavedSettings.getBOOL("RenderHUDInSnapshot")) - { //clamp snapshot resolution to window size when showing UI or HUD in snapshot + { S32 width = gViewerWindow->getWindowWidthRaw(); S32 height = gViewerWindow->getWindowHeightRaw(); @@ -1425,7 +1394,7 @@ void LLFloaterSnapshot::Impl::updateControls(LLFloaterSnapshot* floater) BOOL got_snap = previewp && previewp->getSnapshotUpToDate(); // *TODO: Separate maximum size for Web images from postcards - //lldebugs << "Is snapshot up-to-date? " << got_snap << llendl; + lldebugs << "Is snapshot up-to-date? " << got_snap << llendl; LLLocale locale(LLLocale::USER_LOCALE); std::string bytes_string; @@ -1450,6 +1419,7 @@ void LLFloaterSnapshot::Impl::updateControls(LLFloaterSnapshot* floater) && got_bytes && previewp->getDataSize() > MAX_POSTCARD_DATASIZE ? LLUIColor(LLColor4::red) : LLUIColorTable::instance().getColor( "LabelTextColor" )); + // Update the width and height spinners based on the corresponding resolution combos. (?) switch(shot_type) { case LLSnapshotLivePreview::SNAPSHOT_WEB: @@ -1476,7 +1446,6 @@ void LLFloaterSnapshot::Impl::updateControls(LLFloaterSnapshot* floater) if (previewp) { - lldebugs << "Setting snapshot type (" << shot_type << "), format (" << shot_format << ")" << llendl; previewp->setSnapshotType(shot_type); previewp->setSnapshotFormat(shot_format); previewp->setSnapshotBufferType(layer_type); @@ -1489,6 +1458,7 @@ void LLFloaterSnapshot::Impl::updateControls(LLFloaterSnapshot* floater) info["have-snapshot"] = got_snap; current_panel->updateControls(info); } + lldebugs << "finished updating controls" << llendl; } // static @@ -1515,11 +1485,27 @@ void LLFloaterSnapshot::Impl::setStatus(EStatus status, bool ok, const std::stri } // static +void LLFloaterSnapshot::Impl::setNeedRefresh(LLFloaterSnapshot* floater, bool need) +{ + if (!floater) return; + + // Don't display the "Refresh to save" message if we're in auto-refresh mode. + if (gSavedSettings.getBOOL("AutoSnapshot")) + { + need = false; + } + + floater->mRefreshLabel->setVisible(need); + floater->impl.mNeedRefresh = need; +} + +// static void LLFloaterSnapshot::Impl::checkAutoSnapshot(LLSnapshotLivePreview* previewp, BOOL update_thumbnail) { if (previewp) { BOOL autosnap = gSavedSettings.getBOOL("AutoSnapshot"); + lldebugs << "updating " << (autosnap ? "snapshot" : "thumbnail") << llendl; previewp->updateSnapshot(autosnap, update_thumbnail, autosnap ? AUTO_SNAPSHOT_TIME_DELAY : 0.f); } } @@ -1531,6 +1517,8 @@ void LLFloaterSnapshot::Impl::onClickNewSnapshot(void* data) LLFloaterSnapshot *view = (LLFloaterSnapshot *)data; if (previewp && view) { + view->impl.setStatus(Impl::STATUS_READY); + lldebugs << "updating snapshot" << llendl; previewp->updateSnapshot(TRUE); } } @@ -1556,18 +1544,10 @@ void LLFloaterSnapshot::Impl::onClickMore(void* data) LLFloaterSnapshot *view = (LLFloaterSnapshot *)data; if (view) { + view->impl.setStatus(Impl::STATUS_READY); gSavedSettings.setBOOL("AdvanceSnapshot", !visible); -#if 0 - view->translate( 0, view->getUIWinHeightShort() - view->getUIWinHeightLong() ); - view->reshape(view->getRect().getWidth(), view->getUIWinHeightLong()); -#endif updateControls(view) ; updateLayout(view) ; - // *TODO: redundant? - if(getPreviewView(view)) - { - getPreviewView(view)->setThumbnailImageSize() ; - } } } @@ -1599,16 +1579,6 @@ void LLFloaterSnapshot::Impl::onClickHUDCheck(LLUICtrl *ctrl, void* data) } } -#if 0 -// static -void LLFloaterSnapshot::Impl::onClickKeepAspectCheck(LLUICtrl* ctrl, void* data) -{ - LLCheckBoxCtrl *check = (LLCheckBoxCtrl *)ctrl; - LLFloaterSnapshot *view = (LLFloaterSnapshot *)data; - applyKeepAspectCheck(view, check->get()); -} -#endif - // static void LLFloaterSnapshot::Impl::applyKeepAspectCheck(LLFloaterSnapshot* view, BOOL checked) { @@ -1623,11 +1593,9 @@ void LLFloaterSnapshot::Impl::applyKeepAspectCheck(LLFloaterSnapshot* view, BOOL S32 w, h ; previewp->getSize(w, h) ; - if(checkImageSize(previewp, w, h, TRUE, previewp->getMaxImageSize())) - { - resetSnapshotSizeOnUI(view, w, h) ; - } + updateSpinners(view, previewp, w, h, TRUE); // may change w and h + lldebugs << "updating thumbnail" << llendl; previewp->setSize(w, h) ; previewp->updateSnapshot(FALSE, TRUE); checkAutoSnapshot(previewp, TRUE); @@ -1662,41 +1630,34 @@ void LLFloaterSnapshot::Impl::checkAspectRatio(LLFloaterSnapshot *view, S32 inde previewp->mKeepAspectRatio = FALSE ; return ; } - - if(0 == index) //current window size - { - view->impl.mAspectRatioCheckOff = true ; - enableAspectRatioCheckbox(view, FALSE); - if(previewp) - { - previewp->mKeepAspectRatio = TRUE ; - } + BOOL keep_aspect = FALSE, enable_cb = FALSE; + + if (0 == index) // current window size + { + enable_cb = FALSE; + keep_aspect = TRUE; } - else if(-1 == index) //custom + else if (-1 == index) // custom { - view->impl.mAspectRatioCheckOff = false ; - enableAspectRatioCheckbox(view, TRUE); - - if(previewp) - { - previewp->mKeepAspectRatio = gSavedSettings.getBOOL("KeepAspectForSnapshot") ; - } + enable_cb = TRUE; + keep_aspect = gSavedSettings.getBOOL("KeepAspectForSnapshot"); } - else + else // predefined resolution { - view->impl.mAspectRatioCheckOff = true ; - enableAspectRatioCheckbox(view, FALSE); - - if(previewp) - { - previewp->mKeepAspectRatio = FALSE ; - } + enable_cb = FALSE; + keep_aspect = FALSE; } - return ; + view->impl.mAspectRatioCheckOff = !enable_cb; + enableAspectRatioCheckbox(view, enable_cb); + if (previewp) + { + previewp->mKeepAspectRatio = keep_aspect; + } } +// Show/hide upload progress indicators. // static void LLFloaterSnapshot::Impl::setWorking(LLFloaterSnapshot* floater, bool working) { @@ -1712,20 +1673,21 @@ void LLFloaterSnapshot::Impl::setWorking(LLFloaterSnapshot* floater, bool workin working_lbl->setValue(progress_text); } - // All controls should be disable while posting. + // All controls should be disabled while posting. floater->setCtrlsEnabled(!working); LLPanelSnapshot* active_panel = getActivePanel(floater); if (active_panel) { - active_panel->setCtrlsEnabled(!working); + active_panel->enableControls(!working); } } +// Show/hide upload status message. // static void LLFloaterSnapshot::Impl::setFinished(LLFloaterSnapshot* floater, bool finished, bool ok, const std::string& msg) { - floater->getChild<LLUICtrl>("succeeded_panel")->setVisible(finished && ok); - floater->getChild<LLUICtrl>("failed_panel")->setVisible(finished && !ok); + floater->mSucceessLblPanel->setVisible(finished && ok); + floater->mFailureLblPanel->setVisible(finished && !ok); if (finished) { @@ -1739,27 +1701,7 @@ void LLFloaterSnapshot::Impl::setFinished(LLFloaterSnapshot* floater, bool finis } } -static std::string lastSnapshotWidthName(S32 shot_type) -{ - switch (shot_type) - { - case LLSnapshotLivePreview::SNAPSHOT_WEB: return "LastSnapshotToProfileWidth"; - case LLSnapshotLivePreview::SNAPSHOT_POSTCARD: return "LastSnapshotToEmailWidth"; - case LLSnapshotLivePreview::SNAPSHOT_TEXTURE: return "LastSnapshotToInventoryWidth"; - default: return "LastSnapshotToDiskWidth"; - } -} -static std::string lastSnapshotHeightName(S32 shot_type) -{ - switch (shot_type) - { - case LLSnapshotLivePreview::SNAPSHOT_WEB: return "LastSnapshotToProfileHeight"; - case LLSnapshotLivePreview::SNAPSHOT_POSTCARD: return "LastSnapshotToEmailHeight"; - case LLSnapshotLivePreview::SNAPSHOT_TEXTURE: return "LastSnapshotToInventoryHeight"; - default: return "LastSnapshotToDiskHeight"; - } -} - +// Apply a new resolution selected from the given combobox. // static void LLFloaterSnapshot::Impl::updateResolution(LLUICtrl* ctrl, void* data, BOOL do_update) { @@ -1772,12 +1714,6 @@ void LLFloaterSnapshot::Impl::updateResolution(LLUICtrl* ctrl, void* data, BOOL return; } - // save off all selected resolution values - gSavedSettings.setS32("SnapshotProfileLastResolution", view->getChild<LLComboBox>("profile_size_combo")->getCurrentIndex()); - gSavedSettings.setS32("SnapshotPostcardLastResolution", view->getChild<LLComboBox>("postcard_size_combo")->getCurrentIndex()); - gSavedSettings.setS32("SnapshotTextureLastResolution", view->getChild<LLComboBox>("texture_size_combo")->getCurrentIndex()); - gSavedSettings.setS32("SnapshotLocalLastResolution", view->getChild<LLComboBox>("local_size_combo")->getCurrentIndex()); - std::string sdstring = combobox->getSelectedValue(); LLSD sdres; std::stringstream sstream(sdstring); @@ -1801,7 +1737,6 @@ void LLFloaterSnapshot::Impl::updateResolution(LLUICtrl* ctrl, void* data, BOOL else if (width == -1 || height == -1) { // load last custom value -#if 1 S32 new_width = 0, new_height = 0; LLPanelSnapshot* spanel = getActivePanel(view); if (spanel) @@ -1809,26 +1744,24 @@ void LLFloaterSnapshot::Impl::updateResolution(LLUICtrl* ctrl, void* data, BOOL lldebugs << "Loading typed res from panel " << spanel->getName() << llendl; new_width = spanel->getTypedPreviewWidth(); new_height = spanel->getTypedPreviewHeight(); + + // Limit custom size for inventory snapshots to 512x512 px. + if (getActiveSnapshotType(view) == LLSnapshotLivePreview::SNAPSHOT_TEXTURE) + { + new_width = llmin(new_width, MAX_TEXTURE_SIZE); + new_height = llmin(new_height, MAX_TEXTURE_SIZE); + } } else { - const S32 shot_type = getActiveSnapshotType(view); - lldebugs << "Loading saved res for shot_type " << shot_type << llendl; - new_width = gSavedSettings.getS32(lastSnapshotWidthName(shot_type)); - new_height = gSavedSettings.getS32(lastSnapshotHeightName(shot_type)); + lldebugs << "No custom res chosen, setting preview res from window: " + << gViewerWindow->getWindowWidthRaw() << "x" << gViewerWindow->getWindowHeightRaw() << llendl; + new_width = gViewerWindow->getWindowWidthRaw(); + new_height = gViewerWindow->getWindowHeightRaw(); } llassert(new_width > 0 && new_height > 0); previewp->setSize(new_width, new_height); -#else - LLPanelSnapshot* spanel = getActivePanel(view); - if (spanel) - { - lldebugs << "Setting custom preview res : " << spanel->getTypedPreviewWidth() << "x" << spanel->getTypedPreviewHeight() << llendl; - previewp->setSize(spanel->getTypedPreviewWidth(), spanel->getTypedPreviewHeight()); - } - //previewp->setSize(gSavedSettings.getS32(lastSnapshotWidthName()), gSavedSettings.getS32(lastSnapshotHeightName())); -#endif } else { @@ -1847,11 +1780,7 @@ void LLFloaterSnapshot::Impl::updateResolution(LLUICtrl* ctrl, void* data, BOOL height = llmin(height, gViewerWindow->getWindowHeightRaw()); } - - if(checkImageSize(previewp, width, height, TRUE, previewp->getMaxImageSize())) - { - resetSnapshotSizeOnUI(view, width, height) ; - } + updateSpinners(view, previewp, width, height, TRUE); // may change width and height if(getWidthSpinner(view)->getValue().asInteger() != width || getHeightSpinner(view)->getValue().asInteger() != height) { @@ -1865,10 +1794,13 @@ void LLFloaterSnapshot::Impl::updateResolution(LLUICtrl* ctrl, void* data, BOOL // hide old preview as the aspect ratio could be wrong checkAutoSnapshot(previewp, FALSE); + lldebugs << "updating thumbnail" << llendl; getPreviewView(view)->updateSnapshot(FALSE, TRUE); if(do_update) { + lldebugs << "Will update controls" << llendl; updateControls(view); + setNeedRefresh(view, true); } } } @@ -1909,92 +1841,29 @@ void LLFloaterSnapshot::Impl::onImageFormatChange(LLFloaterSnapshot* view) if (view) { gSavedSettings.setS32("SnapshotFormat", getImageFormat(view)); + lldebugs << "image format changed, updating snapshot" << llendl; getPreviewView(view)->updateSnapshot(TRUE); updateControls(view); + setNeedRefresh(view, false); // we're refreshing } } -#if 0 -//static -void LLFloaterSnapshot::Impl::onCommitSnapshotType(LLUICtrl* ctrl, void* data) -{ - LLFloaterSnapshot *view = (LLFloaterSnapshot *)data; - if (view) - { - gSavedSettings.setS32("LastSnapshotType", getTypeIndex(view)); - getPreviewView(view)->updateSnapshot(TRUE); - updateControls(view); - } -} -#endif - // Sets the named size combo to "custom" mode. // static void LLFloaterSnapshot::Impl::comboSetCustom(LLFloaterSnapshot* floater, const std::string& comboname) { LLComboBox* combo = floater->getChild<LLComboBox>(comboname); - combo->setCurrentByIndex(combo->getItemCount() - 1); // "custom" is always the last index - - if(comboname == "postcard_size_combo") - { - gSavedSettings.setS32("SnapshotPostcardLastResolution", combo->getCurrentIndex()); - } - else if(comboname == "profile_size_combo") - { - gSavedSettings.setS32("SnapshotProfileLastResolution", combo->getCurrentIndex()); - } - else if(comboname == "texture_size_combo") - { - gSavedSettings.setS32("SnapshotTextureLastResolution", combo->getCurrentIndex()); - } - else if(comboname == "local_size_combo") - { - gSavedSettings.setS32("SnapshotLocalLastResolution", combo->getCurrentIndex()); - } - checkAspectRatio(floater, -1); // -1 means custom } - - +// Update supplied width and height according to the constrain proportions flag; limit them by max_val. //static BOOL LLFloaterSnapshot::Impl::checkImageSize(LLSnapshotLivePreview* previewp, S32& width, S32& height, BOOL isWidthChanged, S32 max_value) { S32 w = width ; S32 h = height ; - //if texture, ignore aspect ratio setting, round image size to power of 2. -#if 0 // Don't round texture sizes; textures are commonly stretched in world, profiles, etc and need to be "squashed" during upload, not cropped here - if(LLSnapshotLivePreview::SNAPSHOT_TEXTURE == gSavedSettings.getS32("LastSnapshotType")) - { - if(width > max_value) - { - width = max_value ; - } - if(height > max_value) - { - height = max_value ; - } - - //round to nearest power of 2 based on the direction of movement - // i.e. higher power of two if increasing texture resolution - if(gSavedSettings.getS32("LastSnapshotToInventoryWidth") < width || - gSavedSettings.getS32("LastSnapshotToInventoryHeight") < height) - { - // Up arrow pressed - width = get_next_power_two(width, MAX_TEXTURE_SIZE) ; - height = get_next_power_two(height, MAX_TEXTURE_SIZE) ; - } - else - { - // Down or no change - width = get_lower_power_two(width, MAX_TEXTURE_SIZE) ; - height = get_lower_power_two(height, MAX_TEXTURE_SIZE) ; - } - } - else -#endif if(previewp && previewp->mKeepAspectRatio) { if(gViewerWindow->getWindowWidthRaw() < 1 || gViewerWindow->getWindowHeightRaw() < 1) @@ -2008,11 +1877,11 @@ BOOL LLFloaterSnapshot::Impl::checkImageSize(LLSnapshotLivePreview* previewp, S3 //change another value proportionally if(isWidthChanged) { - height = (S32)(width / aspect_ratio) ; + height = llround(width / aspect_ratio) ; } else { - width = (S32)(height * aspect_ratio) ; + width = llround(height * aspect_ratio) ; } //bound w/h by the max_value @@ -2030,93 +1899,63 @@ BOOL LLFloaterSnapshot::Impl::checkImageSize(LLSnapshotLivePreview* previewp, S3 } } } - else - { - } return (w != width || h != height) ; } //static -void LLFloaterSnapshot::Impl::resetSnapshotSizeOnUI(LLFloaterSnapshot *view, S32 width, S32 height) +void LLFloaterSnapshot::Impl::setImageSizeSpinnersValues(LLFloaterSnapshot *view, S32 width, S32 height) { getWidthSpinner(view)->forceSetValue(width); getHeightSpinner(view)->forceSetValue(height); - gSavedSettings.setS32(lastSnapshotWidthName(getActiveSnapshotType(view)), width); - gSavedSettings.setS32(lastSnapshotHeightName(getActiveSnapshotType(view)), height); } -#if 0 -//static -void LLFloaterSnapshot::Impl::onCommitCustomResolution(LLUICtrl *ctrl, void* data) +// static +void LLFloaterSnapshot::Impl::updateSpinners(LLFloaterSnapshot* view, LLSnapshotLivePreview* previewp, S32& width, S32& height, BOOL is_width_changed) { - LLFloaterSnapshot *view = (LLFloaterSnapshot *)data; - S32 w = llfloor((F32)getWidthSpinner(view)->getValue().asReal()); - S32 h = llfloor((F32)getHeightSpinner(view)->getValue().asReal()); - applyCustomResolution(view, w, h); + if (checkImageSize(previewp, width, height, is_width_changed, previewp->getMaxImageSize())) + { + setImageSizeSpinnersValues(view, width, height); + } } -#endif // static void LLFloaterSnapshot::Impl::applyCustomResolution(LLFloaterSnapshot* view, S32 w, S32 h) { + bool need_refresh = false; + lldebugs << "applyCustomResolution(" << w << ", " << h << ")" << llendl; - if (view) + if (!view) return; + + LLSnapshotLivePreview* previewp = getPreviewView(view); + if (previewp) { - LLSnapshotLivePreview* previewp = getPreviewView(view); - if (previewp) + S32 curw,curh; + previewp->getSize(curw, curh); + + if (w != curw || h != curh) { - S32 curw,curh; - previewp->getSize(curw, curh); - - if (w != curw || h != curh) - { - BOOL update_ = FALSE ; - //if to upload a snapshot, process spinner input in a special way. -#if 0 // Don't round texture sizes; textures are commonly stretched in world, profiles, etc and need to be "squashed" during upload, not cropped here - if(LLSnapshotLivePreview::SNAPSHOT_TEXTURE == gSavedSettings.getS32("LastSnapshotType")) - { - S32 spinner_increment = (S32)((LLSpinCtrl*)ctrl)->getIncrement() ; - S32 dw = w - curw ; - S32 dh = h - curh ; - dw = (dw == spinner_increment) ? 1 : ((dw == -spinner_increment) ? -1 : 0) ; - dh = (dh == spinner_increment) ? 1 : ((dh == -spinner_increment) ? -1 : 0) ; - - if(dw) - { - w = (dw > 0) ? curw << dw : curw >> -dw ; - update_ = TRUE ; - } - if(dh) - { - h = (dh > 0) ? curh << dh : curh >> -dh ; - update_ = TRUE ; - } - } -#endif - previewp->setMaxImageSize((S32) getWidthSpinner(view)->getMaxValue()) ; - - // Check image size changes the value of height and width - if(checkImageSize(previewp, w, h, w != curw, previewp->getMaxImageSize()) - || update_) - { - resetSnapshotSizeOnUI(view, w, h) ; - } + //if to upload a snapshot, process spinner input in a special way. + previewp->setMaxImageSize((S32) getWidthSpinner(view)->getMaxValue()) ; - previewp->setSize(w,h); - checkAutoSnapshot(previewp, FALSE); - previewp->updateSnapshot(FALSE, TRUE); - comboSetCustom(view, "profile_size_combo"); - comboSetCustom(view, "postcard_size_combo"); - comboSetCustom(view, "texture_size_combo"); - comboSetCustom(view, "local_size_combo"); - } - } + updateSpinners(view, previewp, w, h, w != curw); // may change w and h - gSavedSettings.setS32(lastSnapshotWidthName(getActiveSnapshotType(view)), w); - gSavedSettings.setS32(lastSnapshotHeightName(getActiveSnapshotType(view)), h); + previewp->setSize(w,h); + checkAutoSnapshot(previewp, FALSE); + lldebugs << "applied custom resolution, updating thumbnail" << llendl; + previewp->updateSnapshot(FALSE, TRUE); + comboSetCustom(view, "profile_size_combo"); + comboSetCustom(view, "postcard_size_combo"); + comboSetCustom(view, "texture_size_combo"); + comboSetCustom(view, "local_size_combo"); + need_refresh = true; + } + } - updateControls(view); + updateControls(view); + if (need_refresh) + { + setNeedRefresh(view, true); // need to do this after updateControls() } } @@ -2140,6 +1979,10 @@ void LLFloaterSnapshot::Impl::onSendingPostcardFinished(bool status) // Default constructor LLFloaterSnapshot::LLFloaterSnapshot(const LLSD& key) : LLFloater(key), + mRefreshBtn(NULL), + mRefreshLabel(NULL), + mSucceessLblPanel(NULL), + mFailureLblPanel(NULL), impl (*(new Impl)) { } @@ -2147,7 +1990,7 @@ LLFloaterSnapshot::LLFloaterSnapshot(const LLSD& key) // Destroys the object LLFloaterSnapshot::~LLFloaterSnapshot() { - delete impl.mPreviewHandle.get(); + if (impl.mPreviewHandle.get()) impl.mPreviewHandle.get()->die(); //unfreeze everything else gSavedSettings.setBOOL("FreezeTime", FALSE); @@ -2169,50 +2012,32 @@ BOOL LLFloaterSnapshot::postBuild() LLWebSharing::instance().init(); } -#if 0 - childSetCommitCallback("snapshot_type_radio", Impl::onCommitSnapshotType, this); -#endif - + mRefreshBtn = getChild<LLUICtrl>("new_snapshot_btn"); childSetAction("new_snapshot_btn", Impl::onClickNewSnapshot, this); + mRefreshLabel = getChild<LLUICtrl>("refresh_lbl"); + mSucceessLblPanel = getChild<LLUICtrl>("succeeded_panel"); + mFailureLblPanel = getChild<LLUICtrl>("failed_panel"); childSetAction("advanced_options_btn", Impl::onClickMore, this); -#if 0 - childSetCommitCallback("snapshot_width", Impl::onCommitCustomResolution, this); - childSetCommitCallback("snapshot_height", Impl::onCommitCustomResolution, this); -#endif - childSetCommitCallback("ui_check", Impl::onClickUICheck, this); getChild<LLUICtrl>("ui_check")->setValue(gSavedSettings.getBOOL("RenderUIInSnapshot")); childSetCommitCallback("hud_check", Impl::onClickHUDCheck, this); getChild<LLUICtrl>("hud_check")->setValue(gSavedSettings.getBOOL("RenderHUDInSnapshot")); -#if 0 - childSetCommitCallback("keep_aspect_check", Impl::onClickKeepAspectCheck, this); -#endif impl.setAspectRatioCheckboxValue(this, gSavedSettings.getBOOL("KeepAspectForSnapshot")); childSetCommitCallback("layer_types", Impl::onCommitLayerTypes, this); getChild<LLUICtrl>("layer_types")->setValue("colors"); getChildView("layer_types")->setEnabled(FALSE); -#if 0 // leads to crash later if one of the settings values is 0 - impl.getWidthSpinner(this)->setValue(gSavedSettings.getS32(lastSnapshotWidthName())); - impl.getHeightSpinner(this)->setValue(gSavedSettings.getS32(lastSnapshotHeightName())); -#endif - getChild<LLUICtrl>("freeze_frame_check")->setValue(gSavedSettings.getBOOL("UseFreezeFrame")); childSetCommitCallback("freeze_frame_check", Impl::onCommitFreezeFrame, this); getChild<LLUICtrl>("auto_snapshot_check")->setValue(gSavedSettings.getBOOL("AutoSnapshot")); childSetCommitCallback("auto_snapshot_check", Impl::onClickAutoSnap, this); - childSetCommitCallback("profile_size_combo", Impl::onCommitResolution, this); - childSetCommitCallback("postcard_size_combo", Impl::onCommitResolution, this); - childSetCommitCallback("texture_size_combo", Impl::onCommitResolution, this); - childSetCommitCallback("local_size_combo", Impl::onCommitResolution, this); - LLWebProfile::setImageUploadResultCallback(boost::bind(&LLFloaterSnapshot::Impl::onSnapshotUploadFinished, _1)); LLPostCard::setPostResultCallback(boost::bind(&LLFloaterSnapshot::Impl::onSendingPostcardFinished, _1)); @@ -2234,6 +2059,13 @@ BOOL LLFloaterSnapshot::postBuild() gFloaterView->removeChild(this); gSnapshotFloaterView->addChild(this); + // Pre-select "Current Window" resolution. + getChild<LLComboBox>("profile_size_combo")->selectNthItem(0); + getChild<LLComboBox>("postcard_size_combo")->selectNthItem(0); + getChild<LLComboBox>("texture_size_combo")->selectNthItem(0); + getChild<LLComboBox>("local_size_combo")->selectNthItem(0); + getChild<LLComboBox>("local_format_combo")->selectNthItem(0); + impl.mPreviewHandle = previewp->getHandle(); impl.updateControls(this); impl.updateLayout(this); @@ -2259,28 +2091,63 @@ void LLFloaterSnapshot::draw() { bool working = impl.getStatus() == Impl::STATUS_WORKING; const LLRect& thumbnail_rect = getThumbnailPlaceholderRect(); - S32 offset_x = thumbnail_rect.mLeft + (thumbnail_rect.getWidth() - previewp->getThumbnailWidth()) / 2 ; - S32 offset_y = thumbnail_rect.mBottom + (thumbnail_rect.getHeight() - previewp->getThumbnailHeight()) / 2 ; + const S32 thumbnail_w = previewp->getThumbnailWidth(); + const S32 thumbnail_h = previewp->getThumbnailHeight(); + + // calc preview offset within the preview rect + const S32 local_offset_x = (thumbnail_rect.getWidth() - thumbnail_w) / 2 ; + const S32 local_offset_y = (thumbnail_rect.getHeight() - thumbnail_h) / 2 ; // preview y pos within the preview rect - glMatrixMode(GL_MODELVIEW); + // calc preview offset within the floater rect + S32 offset_x = thumbnail_rect.mLeft + local_offset_x; + S32 offset_y = thumbnail_rect.mBottom + local_offset_y; + + gGL.matrixMode(LLRender::MM_MODELVIEW); // Apply floater transparency to the texture unless the floater is focused. F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency(); LLColor4 color = working ? LLColor4::grey4 : LLColor4::white; gl_draw_scaled_image(offset_x, offset_y, - previewp->getThumbnailWidth(), previewp->getThumbnailHeight(), + thumbnail_w, thumbnail_h, previewp->getThumbnailImage(), color % alpha); previewp->drawPreviewRect(offset_x, offset_y) ; - // Draw progress indicators on top of the preview. - if (working) + // Draw some controls on top of the preview thumbnail. + static const S32 PADDING = 5; + static const S32 REFRESH_LBL_BG_HEIGHT = 32; + + // Reshape and position the posting result message panels at the top of the thumbnail. + // Do this regardless of current posting status (finished or not) to avoid flicker + // when the result message is displayed for the first time. + // if (impl.getStatus() == Impl::STATUS_FINISHED) { - gGL.pushUIMatrix(); - const LLRect& r = getThumbnailPlaceholderRect(); - LLUI::translate((F32) r.mLeft, (F32) r.mBottom); - sThumbnailPlaceholder->draw(); - gGL.popUIMatrix(); + LLRect result_lbl_rect = mSucceessLblPanel->getRect(); + const S32 result_lbl_h = result_lbl_rect.getHeight(); + result_lbl_rect.setLeftTopAndSize(local_offset_x, local_offset_y + thumbnail_h, thumbnail_w - 1, result_lbl_h); + mSucceessLblPanel->reshape(result_lbl_rect.getWidth(), result_lbl_h); + mSucceessLblPanel->setRect(result_lbl_rect); + mFailureLblPanel->reshape(result_lbl_rect.getWidth(), result_lbl_h); + mFailureLblPanel->setRect(result_lbl_rect); } + + // Position the refresh button in the bottom left corner of the thumbnail. + mRefreshBtn->setOrigin(local_offset_x + PADDING, local_offset_y + PADDING); + + if (impl.mNeedRefresh) + { + // Place the refresh hint text to the right of the refresh button. + const LLRect& refresh_btn_rect = mRefreshBtn->getRect(); + mRefreshLabel->setOrigin(refresh_btn_rect.mLeft + refresh_btn_rect.getWidth() + PADDING, refresh_btn_rect.mBottom); + + // Draw the refresh hint background. + LLRect refresh_label_bg_rect(offset_x, offset_y + REFRESH_LBL_BG_HEIGHT, offset_x + thumbnail_w - 1, offset_y); + gl_rect_2d(refresh_label_bg_rect, LLColor4::white % 0.9f, TRUE); + } + + gGL.pushUIMatrix(); + LLUI::translate((F32) thumbnail_rect.mLeft, (F32) thumbnail_rect.mBottom); + sThumbnailPlaceholder->draw(); + gGL.popUIMatrix(); } } } @@ -2290,6 +2157,7 @@ void LLFloaterSnapshot::onOpen(const LLSD& key) LLSnapshotLivePreview* preview = LLFloaterSnapshot::Impl::getPreviewView(this); if(preview) { + lldebugs << "opened, updating snapshot" << llendl; preview->updateSnapshot(TRUE); } focusFirstItem(FALSE); @@ -2371,6 +2239,7 @@ void LLFloaterSnapshot::update() return; BOOL changed = FALSE; + lldebugs << "npreviews: " << LLSnapshotLivePreview::sList.size() << llendl; for (std::set<LLSnapshotLivePreview*>::iterator iter = LLSnapshotLivePreview::sList.begin(); iter != LLSnapshotLivePreview::sList.end(); ++iter) { @@ -2378,6 +2247,7 @@ void LLFloaterSnapshot::update() } if(changed) { + lldebugs << "changed" << llendl; inst->impl.updateControls(inst); } } @@ -2411,7 +2281,7 @@ void LLFloaterSnapshot::saveTexture() } // static -void LLFloaterSnapshot::saveLocal() +BOOL LLFloaterSnapshot::saveLocal() { lldebugs << "saveLocal" << llendl; // FIXME: duplicated code @@ -2419,16 +2289,16 @@ void LLFloaterSnapshot::saveLocal() if (!instance) { llassert(instance != NULL); - return; + return FALSE; } LLSnapshotLivePreview* previewp = Impl::getPreviewView(instance); if (!previewp) { llassert(previewp != NULL); - return; + return FALSE; } - previewp->saveLocal(); + return previewp->saveLocal(); } // static @@ -2440,6 +2310,9 @@ void LLFloaterSnapshot::preUpdate() { // Disable the send/post/save buttons until snapshot is ready. Impl::updateControls(instance); + + // Force hiding the "Refresh to save" hint because we know we've just started refresh. + Impl::setNeedRefresh(instance, false); } } @@ -2452,6 +2325,16 @@ void LLFloaterSnapshot::postUpdate() { // Enable the send/post/save buttons. Impl::updateControls(instance); + + // We've just done refresh. + Impl::setNeedRefresh(instance, false); + + // The refresh button is initially hidden. We show it after the first update, + // i.e. when preview appears. + if (!instance->mRefreshBtn->getVisible()) + { + instance->mRefreshBtn->setVisible(true); + } } } @@ -2474,6 +2357,9 @@ void LLFloaterSnapshot::postPanelSwitch() { LLFloaterSnapshot* instance = getInstance(); instance->impl.updateControls(instance); + + // Remove the success/failure indicator whenever user presses a snapshot option button. + instance->impl.setStatus(Impl::STATUS_READY); } // static |