llprogressview.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llprogressview.h"
00035 
00036 #include "indra_constants.h"
00037 #include "llmath.h"
00038 #include "llgl.h"
00039 #include "llui.h"
00040 #include "llfontgl.h"
00041 #include "llimagegl.h"
00042 #include "lltimer.h"
00043 #include "llglheaders.h"
00044 
00045 #include "llagent.h"
00046 #include "llbutton.h"
00047 #include "llfocusmgr.h"
00048 #include "llstartup.h"
00049 #include "llviewercontrol.h"
00050 #include "llviewerimagelist.h"
00051 #include "llviewerwindow.h"
00052 #include "viewer.h"
00053 
00054 LLProgressView* LLProgressView::sInstance = NULL;
00055 
00056 S32 gStartImageWidth = 1;
00057 S32 gStartImageHeight = 1;
00058 const F32 FADE_IN_TIME = 1.f;
00059 
00060 const LLString ANIMATION_FILENAME = "Login Sequence ";
00061 const LLString ANIMATION_SUFFIX = ".jpg";
00062 const F32 TOTAL_LOGIN_TIME = 10.f;      // seconds, wild guess at time from GL context to actual world view
00063 S32 gLastStartAnimationFrame = 0;       // human-style indexing, first image = 1
00064 const S32 ANIMATION_FRAMES = 1; //13;
00065 
00066 // XUI:translate
00067 LLProgressView::LLProgressView(const std::string& name, const LLRect &rect) 
00068 : LLPanel(name, rect, FALSE)
00069 {
00070         mPercentDone = 0.f;
00071         mDrawBackground = TRUE;
00072 
00073         const S32 CANCEL_BTN_WIDTH = 70;
00074         const S32 CANCEL_BTN_OFFSET = 16;
00075         LLRect r;
00076         r.setOriginAndSize( 
00077                 mRect.getWidth() - CANCEL_BTN_OFFSET - CANCEL_BTN_WIDTH, CANCEL_BTN_OFFSET,
00078                 CANCEL_BTN_WIDTH, BTN_HEIGHT );
00079         
00080         mCancelBtn = new LLButton( 
00081                 "Quit",
00082                 r,
00083                 "",
00084                 LLProgressView::onCancelButtonClicked,
00085                 NULL );
00086         mCancelBtn->setFollows( FOLLOWS_RIGHT | FOLLOWS_BOTTOM );
00087         addChild( mCancelBtn );
00088         mFadeTimer.stop();
00089         setVisible(FALSE);
00090 
00091         sInstance = this;
00092 }
00093 
00094 
00095 LLProgressView::~LLProgressView()
00096 {
00097         gFocusMgr.releaseFocusIfNeeded( this );
00098 
00099         sInstance = NULL;
00100 }
00101 
00102 EWidgetType LLProgressView::getWidgetType() const
00103 {
00104         return WIDGET_TYPE_PROGRESS_VIEW;
00105 }
00106 
00107 LLString LLProgressView::getWidgetTag() const
00108 {
00109         return LL_PROGRESS_VIEW_TAG;
00110 }
00111 
00112 BOOL LLProgressView::handleHover(S32 x, S32 y, MASK mask)
00113 {
00114         if( childrenHandleHover( x, y, mask ) == NULL )
00115         {
00116                 lldebugst(LLERR_USER_INPUT) << "hover handled by LLProgressView" << llendl;
00117                 gViewerWindow->setCursor(UI_CURSOR_WAIT);
00118         }
00119         return TRUE;
00120 }
00121 
00122 
00123 BOOL LLProgressView::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent)
00124 {
00125         if( getVisible() )
00126         {
00127                 // Suck up all keystokes except CTRL-Q.
00128                 if( ('Q' == key) && (MASK_CONTROL == mask) )
00129                 {
00130                         app_user_quit();
00131                 }
00132                 return TRUE;
00133         }
00134         return FALSE;
00135 }
00136 
00137 void LLProgressView::setVisible(BOOL visible)
00138 {
00139         if (getVisible() && !visible)
00140         {
00141                 mFadeTimer.start();
00142         }
00143         else if (!getVisible() && visible)
00144         {
00145                 gFocusMgr.setTopCtrl(this);
00146                 mFadeTimer.stop();
00147                 mProgressTimer.start();
00148                 LLView::setVisible(visible);
00149         }
00150 }
00151 
00152 
00153 void LLProgressView::draw()
00154 {
00155         static LLTimer timer;
00156 
00157         if (gNoRender)
00158         {
00159                 return;
00160         }
00161 
00162         // Make sure the progress view always fills the entire window.
00163         S32 width = gViewerWindow->getWindowWidth();
00164         S32 height = gViewerWindow->getWindowHeight();
00165         if( (width != mRect.getWidth()) || (height != mRect.getHeight()) )
00166         {
00167                 reshape( width, height );
00168         }
00169 
00170         // Paint bitmap if we've got one
00171         if (mDrawBackground)
00172         {
00173                 glPushMatrix();
00174                 if (gStartImageGL)
00175                 {
00176                         LLGLSUIDefault gls_ui;
00177                         LLViewerImage::bindTexture(gStartImageGL);
00178                         glColor4f(1.f, 1.f, 1.f, mFadeTimer.getStarted() ? clamp_rescale(mFadeTimer.getElapsedTimeF32(), 0.f, FADE_IN_TIME, 1.f, 0.f) : 1.f);
00179                         F32 image_aspect = (F32)gStartImageWidth / (F32)gStartImageHeight;
00180                         F32 view_aspect = (F32)width / (F32)height;
00181                         // stretch image to maintain aspect ratio
00182                         if (image_aspect > view_aspect)
00183                         {
00184                                 glTranslatef(-0.5f * (image_aspect / view_aspect - 1.f) * width, 0.f, 0.f);
00185                                 glScalef(image_aspect / view_aspect, 1.f, 1.f);
00186                         }
00187                         else
00188                         {
00189                                 glTranslatef(0.f, -0.5f * (view_aspect / image_aspect - 1.f) * height, 0.f);
00190                                 glScalef(1.f, view_aspect / image_aspect, 1.f);
00191                         }
00192                         gl_rect_2d_simple_tex( mRect.getWidth(), mRect.getHeight() );
00193                         gStartImageGL->unbindTexture(0, GL_TEXTURE_2D);
00194                 }
00195                 else
00196                 {
00197                         LLGLSNoTexture gls_no_texture;
00198                         glColor4f(0.f, 0.f, 0.f, 1.f);
00199                         gl_rect_2d(mRect);
00200                 }
00201                 glPopMatrix();
00202         }
00203 
00204         if (mFadeTimer.getStarted())
00205         {
00206                 LLView::draw();
00207                 if (mFadeTimer.getElapsedTimeF32() > FADE_IN_TIME)
00208                 {
00209                         gFocusMgr.removeTopCtrlWithoutCallback(this);
00210                         LLView::setVisible(FALSE);
00211                         gStartImageGL = NULL;
00212                 }
00213                 return;
00214         }
00215 
00216         S32 line_x = mRect.getWidth() / 2;
00217         S32 line_one_y = mRect.getHeight() / 2 + 64;
00218         const S32 LINE_SPACING = 25;
00219         S32 line_two_y = line_one_y - LINE_SPACING;
00220         const LLFontGL* font = LLFontGL::sSansSerif;
00221 
00222         LLViewerImage* shadow_imagep = gImageList.getImage(LLUUID(gViewerArt.getString("rounded_square_soft.tga")), MIPMAP_FALSE, TRUE);
00223         LLViewerImage* bar_imagep = gImageList.getImage(LLUUID(gViewerArt.getString("rounded_square.tga")), MIPMAP_FALSE, TRUE);
00224 
00225         //LLColor4 background_color = gColors.getColor("DefaultShadowLight");
00226         LLColor4 background_color = LLColor4(0.3254f, 0.4f, 0.5058f, 1.0f);
00227 
00228         F32 alpha = 0.5f + 0.5f*0.5f*(1.f + (F32)sin(3.f*timer.getElapsedTimeF32()));
00229         // background_color.mV[3] = background_color.mV[3]*alpha;
00230 
00231         LLString top_line = gSecondLife;
00232 
00233         font->renderUTF8(top_line, 0,
00234                 line_x, line_one_y,
00235                 LLColor4::white,
00236                 LLFontGL::HCENTER, LLFontGL::BASELINE,
00237                 LLFontGL::DROP_SHADOW);
00238         font->renderUTF8(mText, 0,
00239                 line_x, line_two_y,
00240                 LLColor4::white,
00241                 LLFontGL::HCENTER, LLFontGL::BASELINE,
00242                 LLFontGL::DROP_SHADOW);
00243 
00244         S32 bar_bottom = line_two_y - 30;
00245         S32 bar_height = 18;
00246         S32 bar_width = mRect.getWidth() * 2 / 3;
00247         S32 bar_left = (mRect.getWidth() / 2) - (bar_width / 2);
00248 
00249         gl_draw_scaled_image_with_border(
00250                 bar_left + 2, 
00251                 bar_bottom - 2, 
00252                 16, 
00253                 16,
00254                 bar_width, 
00255                 bar_height,
00256                 shadow_imagep,
00257                 gColors.getColor("ColorDropShadow"));
00258 
00259         gl_draw_scaled_image_with_border(
00260                 bar_left, 
00261                 bar_bottom, 
00262                 16, 
00263                 16,
00264                 bar_width, 
00265                 bar_height,
00266                 bar_imagep,
00267                 LLColor4(0.7f, 0.7f, 0.8f, 1.0f));
00268 
00269         gl_draw_scaled_image_with_border(bar_left + 2, bar_bottom + 2, 16, 16,
00270                 bar_width - 4, bar_height - 4,
00271                 bar_imagep,
00272                 background_color);
00273 
00274         LLColor4 bar_color = LLColor4(0.5764f, 0.6627f, 0.8352f, 1.0f);
00275         bar_color.mV[3] = alpha;
00276         gl_draw_scaled_image_with_border(bar_left + 2, bar_bottom + 2, 16, 16,
00277                 llround((bar_width - 4) * (mPercentDone / 100.f)), bar_height - 4,
00278                 bar_imagep,
00279                 bar_color);
00280 
00281         S32 line_three_y = line_two_y - LINE_SPACING * 3;
00282         
00283         // draw the message if there is one
00284         if(!mMessage.empty())
00285         {
00286                 LLWString wmessage = utf8str_to_wstring(mMessage);
00287                 const F32 MAX_PIXELS = 640.0f;
00288                 S32 chars_left = wmessage.length();
00289                 S32 chars_this_time = 0;
00290                 S32 msgidx = 0;
00291                 while(chars_left > 0)
00292                 {
00293                         chars_this_time = font->maxDrawableChars(wmessage.substr(msgidx).c_str(),
00294                                                                                                          MAX_PIXELS,
00295                                                                                                          MAX_STRING - 1,
00296                                                                                                          TRUE);
00297                         LLWString wbuffer = wmessage.substr(msgidx, chars_this_time);
00298                         font->render(wbuffer, 0,
00299                                                  (F32)line_x, (F32)line_three_y,
00300                                                  LLColor4::white,
00301                                                  LLFontGL::HCENTER, LLFontGL::BASELINE,
00302                                                  LLFontGL::DROP_SHADOW);
00303                         msgidx += chars_this_time;
00304                         chars_left -= chars_this_time;
00305                         line_three_y -= LINE_SPACING;
00306                 }
00307         }
00308 
00309         // draw children
00310         LLView::draw();
00311 }
00312 
00313 void LLProgressView::setText(const LLString& text)
00314 {
00315         mText = text;
00316 }
00317 
00318 void LLProgressView::setPercent(const F32 percent)
00319 {
00320         mPercentDone = llclamp(percent, 0.f, 100.f);
00321 }
00322 
00323 void LLProgressView::setMessage(const LLString& msg)
00324 {
00325         mMessage = msg;
00326 }
00327 
00328 void LLProgressView::setCancelButtonVisible(BOOL b, const LLString& label)
00329 {
00330         mCancelBtn->setVisible( b );
00331         mCancelBtn->setEnabled( b );
00332         mCancelBtn->setLabelSelected(label);
00333         mCancelBtn->setLabelUnselected(label);
00334 }
00335 
00336 // static
00337 void LLProgressView::onCancelButtonClicked(void*)
00338 {
00339         if (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE)
00340         {
00341                 app_request_quit();
00342         }
00343         else
00344         {
00345                 gAgent.teleportCancel();
00346                 sInstance->mCancelBtn->setEnabled(FALSE);
00347                 sInstance->setVisible(FALSE);
00348         }
00349 }

Generated on Thu Jul 1 06:09:03 2010 for Second Life Viewer by  doxygen 1.4.7