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 "llglimmediate.h"
00040 #include "llui.h"
00041 #include "llfontgl.h"
00042 #include "llimagegl.h"
00043 #include "lltimer.h"
00044 #include "llglheaders.h"
00045
00046 #include "llagent.h"
00047 #include "llbutton.h"
00048 #include "llfocusmgr.h"
00049 #include "llstartup.h"
00050 #include "llviewercontrol.h"
00051 #include "llviewerimagelist.h"
00052 #include "llviewerwindow.h"
00053 #include "llappviewer.h"
00054 #include "llweb.h"
00055
00056 LLProgressView* LLProgressView::sInstance = NULL;
00057
00058 S32 gStartImageWidth = 1;
00059 S32 gStartImageHeight = 1;
00060 const F32 FADE_IN_TIME = 1.f;
00061
00062 const LLString ANIMATION_FILENAME = "Login Sequence ";
00063 const LLString ANIMATION_SUFFIX = ".jpg";
00064 const F32 TOTAL_LOGIN_TIME = 10.f;
00065 S32 gLastStartAnimationFrame = 0;
00066 const S32 ANIMATION_FRAMES = 1;
00067
00068
00069 LLProgressView::LLProgressView(const std::string& name, const LLRect &rect)
00070 : LLPanel(name, rect, FALSE),
00071 mPercentDone( 0.f ),
00072 mMouseDownInActiveArea( false )
00073 {
00074 const S32 CANCEL_BTN_WIDTH = 70;
00075 const S32 CANCEL_BTN_OFFSET = 16;
00076 LLRect r;
00077 r.setOriginAndSize(
00078 getRect().getWidth() - CANCEL_BTN_OFFSET - CANCEL_BTN_WIDTH, CANCEL_BTN_OFFSET,
00079 CANCEL_BTN_WIDTH, BTN_HEIGHT );
00080
00081 mCancelBtn = new LLButton(
00082 "Quit",
00083 r,
00084 "",
00085 LLProgressView::onCancelButtonClicked,
00086 NULL );
00087 mCancelBtn->setFollows( FOLLOWS_RIGHT | FOLLOWS_BOTTOM );
00088 addChild( mCancelBtn );
00089 mFadeTimer.stop();
00090 setVisible(FALSE);
00091
00092 mOutlineRect.set( 0, 0, 0, 0 );
00093
00094 sInstance = this;
00095 }
00096
00097
00098 LLProgressView::~LLProgressView()
00099 {
00100 gFocusMgr.releaseFocusIfNeeded( this );
00101
00102 sInstance = NULL;
00103 }
00104
00105 BOOL LLProgressView::handleMouseDown(S32 x, S32 y, MASK mask)
00106 {
00107 if ( mOutlineRect.pointInRect( x, y ) )
00108 {
00109 mMouseDownInActiveArea = TRUE;
00110 return TRUE;
00111 };
00112
00113 return LLPanel::handleMouseDown(x, y, mask);
00114 }
00115
00116 BOOL LLProgressView::handleMouseUp(S32 x, S32 y, MASK mask)
00117 {
00118 if ( mOutlineRect.pointInRect( x, y ) )
00119 {
00120 if ( mMouseDownInActiveArea )
00121 {
00122 if ( ! mMessage.empty() )
00123 {
00124 std::string url_to_open( "" );
00125
00126 size_t start_pos = mMessage.find( "http://" );
00127 if ( start_pos != std::string::npos )
00128 {
00129 size_t end_pos = mMessage.find_first_of( " \n\r\t", start_pos );
00130 if ( end_pos != std::string::npos )
00131 url_to_open = mMessage.substr( start_pos, end_pos - start_pos );
00132 else
00133 url_to_open = mMessage.substr( start_pos );
00134
00135 LLWeb::loadURLExternal( url_to_open );
00136 };
00137 };
00138 return TRUE;
00139 };
00140 };
00141
00142 return LLPanel::handleMouseUp(x, y, mask);
00143 }
00144
00145 BOOL LLProgressView::handleHover(S32 x, S32 y, MASK mask)
00146 {
00147 if( childrenHandleHover( x, y, mask ) == NULL )
00148 {
00149 lldebugst(LLERR_USER_INPUT) << "hover handled by LLProgressView" << llendl;
00150 if ( mOutlineRect.pointInRect( x, y ) )
00151 {
00152 gViewerWindow->setCursor(UI_CURSOR_ARROW);
00153 }
00154 else
00155 {
00156 gViewerWindow->setCursor(UI_CURSOR_WAIT);
00157 }
00158 }
00159 return TRUE;
00160 }
00161
00162
00163 BOOL LLProgressView::handleKeyHere(KEY key, MASK mask)
00164 {
00165
00166 if( ('Q' == key) && (MASK_CONTROL == mask) )
00167 {
00168 LLAppViewer::instance()->userQuit();
00169 }
00170 return TRUE;
00171 }
00172
00173 void LLProgressView::setVisible(BOOL visible)
00174 {
00175 if (getVisible() && !visible)
00176 {
00177 mFadeTimer.start();
00178 }
00179 else if (!getVisible() && visible)
00180 {
00181 gFocusMgr.setTopCtrl(this);
00182 setFocus(TRUE);
00183 mFadeTimer.stop();
00184 mProgressTimer.start();
00185 LLView::setVisible(visible);
00186 }
00187 }
00188
00189
00190 void LLProgressView::draw()
00191 {
00192 static LLTimer timer;
00193
00194 if (gNoRender)
00195 {
00196 return;
00197 }
00198
00199
00200 S32 width = gViewerWindow->getWindowWidth();
00201 S32 height = gViewerWindow->getWindowHeight();
00202 if( (width != getRect().getWidth()) || (height != getRect().getHeight()) )
00203 {
00204 reshape( width, height );
00205 }
00206
00207
00208 glPushMatrix();
00209 if (gStartImageGL)
00210 {
00211 LLGLSUIDefault gls_ui;
00212 LLViewerImage::bindTexture(gStartImageGL);
00213 gGL.color4f(1.f, 1.f, 1.f, mFadeTimer.getStarted() ? clamp_rescale(mFadeTimer.getElapsedTimeF32(), 0.f, FADE_IN_TIME, 1.f, 0.f) : 1.f);
00214 F32 image_aspect = (F32)gStartImageWidth / (F32)gStartImageHeight;
00215 F32 view_aspect = (F32)width / (F32)height;
00216
00217 if (image_aspect > view_aspect)
00218 {
00219 glTranslatef(-0.5f * (image_aspect / view_aspect - 1.f) * width, 0.f, 0.f);
00220 glScalef(image_aspect / view_aspect, 1.f, 1.f);
00221 }
00222 else
00223 {
00224 glTranslatef(0.f, -0.5f * (view_aspect / image_aspect - 1.f) * height, 0.f);
00225 glScalef(1.f, view_aspect / image_aspect, 1.f);
00226 }
00227 gl_rect_2d_simple_tex( getRect().getWidth(), getRect().getHeight() );
00228 gStartImageGL->unbindTexture(0, GL_TEXTURE_2D);
00229 }
00230 else
00231 {
00232 LLGLSNoTexture gls_no_texture;
00233 gGL.color4f(0.f, 0.f, 0.f, 1.f);
00234 gl_rect_2d(getRect());
00235 }
00236 glPopMatrix();
00237
00238
00239 if (mFadeTimer.getStarted())
00240 {
00241 LLView::draw();
00242 if (mFadeTimer.getElapsedTimeF32() > FADE_IN_TIME)
00243 {
00244 gFocusMgr.removeTopCtrlWithoutCallback(this);
00245 LLView::setVisible(FALSE);
00246 gStartImageGL = NULL;
00247 }
00248 return;
00249 }
00250
00251 S32 line_x = getRect().getWidth() / 2;
00252 S32 line_one_y = getRect().getHeight() / 2 + 64;
00253 const S32 LINE_SPACING = 25;
00254 S32 line_two_y = line_one_y - LINE_SPACING;
00255 const LLFontGL* font = LLFontGL::sSansSerif;
00256
00257 LLUIImagePtr shadow_imagep = LLUI::getUIImage("rounded_square_soft.tga");
00258 LLUIImagePtr bar_fg_imagep = LLUI::getUIImage("progressbar_fill.tga");
00259 LLUIImagePtr bar_bg_imagep = LLUI::getUIImage("progressbar_track.tga");
00260 LLUIImagePtr bar_imagep = LLUI::getUIImage("rounded_square.tga");
00261
00262 LLColor4 background_color = gColors.getColor("LoginProgressBarBgColor");
00263
00264 F32 alpha = 0.5f + 0.5f*0.5f*(1.f + (F32)sin(3.f*timer.getElapsedTimeF32()));
00265
00266
00267 LLString top_line = LLAppViewer::instance()->getSecondLifeTitle();
00268
00269 S32 bar_bottom = line_two_y - 30;
00270 S32 bar_height = 18;
00271 S32 bar_width = getRect().getWidth() * 2 / 3;
00272 S32 bar_left = (getRect().getWidth() / 2) - (bar_width / 2);
00273
00274
00275 S32 background_box_left = ( ( ( getRect().getWidth() / 2 ) - ( bar_width / 2 ) ) / 4 ) * 3;
00276 S32 background_box_top = ( getRect().getHeight() / 2 ) + LINE_SPACING * 5;
00277 S32 background_box_right = getRect().getWidth() - background_box_left;
00278 S32 background_box_bottom = ( getRect().getHeight() / 2 ) - LINE_SPACING * 5;
00279 S32 background_box_width = background_box_right - background_box_left + 1;
00280 S32 background_box_height = background_box_top - background_box_bottom + 1;
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 bar_imagep->draw( background_box_left + 1,
00294 background_box_bottom + 1,
00295 background_box_width - 2,
00296 background_box_height - 2,
00297 gColors.getColor("LoginProgressBoxCenterColor") );
00298
00299
00300 if ( mMessage.find( "http://" ) != std::string::npos )
00301 mOutlineRect.set( background_box_left, background_box_top, background_box_right, background_box_bottom );
00302 else
00303 mOutlineRect.set( 0, 0, 0, 0 );
00304
00305
00306 font->renderUTF8(top_line, 0,
00307 line_x, line_one_y,
00308
00309 gColors.getColor("LoginProgressBoxTextColor"),
00310 LLFontGL::HCENTER, LLFontGL::BASELINE,
00311 LLFontGL::DROP_SHADOW);
00312 font->renderUTF8(mText, 0,
00313 line_x, line_two_y,
00314
00315 gColors.getColor("LoginProgressBoxTextColor"),
00316 LLFontGL::HCENTER, LLFontGL::BASELINE,
00317 LLFontGL::DROP_SHADOW);
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 bar_bg_imagep->draw(
00334 bar_left + 2,
00335 bar_bottom + 2,
00336 bar_width - 4,
00337 bar_height - 4,
00338 background_color);
00339
00340 LLColor4 bar_color = gColors.getColor("LoginProgressBarFgColor");
00341 bar_color.mV[3] = alpha;
00342 bar_fg_imagep->draw(
00343 bar_left + 2,
00344 bar_bottom + 2,
00345 llround((bar_width - 4) * (mPercentDone / 100.f)),
00346 bar_height - 4,
00347 bar_color);
00348
00349 S32 line_three_y = line_two_y - LINE_SPACING * 3;
00350
00351
00352 if(!mMessage.empty())
00353 {
00354 LLColor4 text_message_color = gColors.getColor("LoginProgressBoxTextColor");
00355 LLWString wmessage = utf8str_to_wstring(mMessage);
00356 const F32 MAX_PIXELS = 640.0f;
00357 S32 chars_left = wmessage.length();
00358 S32 chars_this_time = 0;
00359 S32 msgidx = 0;
00360 while(chars_left > 0)
00361 {
00362 chars_this_time = font->maxDrawableChars(wmessage.substr(msgidx).c_str(),
00363 MAX_PIXELS,
00364 MAX_STRING - 1,
00365 TRUE);
00366 LLWString wbuffer = wmessage.substr(msgidx, chars_this_time);
00367 font->render(wbuffer, 0,
00368 (F32)line_x, (F32)line_three_y,
00369
00370 gColors.getColor("LoginProgressBoxTextColor"),
00371 LLFontGL::HCENTER, LLFontGL::BASELINE,
00372 LLFontGL::DROP_SHADOW);
00373 msgidx += chars_this_time;
00374 chars_left -= chars_this_time;
00375 line_three_y -= LINE_SPACING;
00376 }
00377 }
00378
00379
00380 LLView::draw();
00381 }
00382
00383 void LLProgressView::setText(const LLString& text)
00384 {
00385 mText = text;
00386 }
00387
00388 void LLProgressView::setPercent(const F32 percent)
00389 {
00390 mPercentDone = llclamp(percent, 0.f, 100.f);
00391 }
00392
00393 void LLProgressView::setMessage(const LLString& msg)
00394 {
00395 mMessage = msg;
00396 }
00397
00398 void LLProgressView::setCancelButtonVisible(BOOL b, const LLString& label)
00399 {
00400 mCancelBtn->setVisible( b );
00401 mCancelBtn->setEnabled( b );
00402 mCancelBtn->setLabelSelected(label);
00403 mCancelBtn->setLabelUnselected(label);
00404 }
00405
00406
00407 void LLProgressView::onCancelButtonClicked(void*)
00408 {
00409 if (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE)
00410 {
00411 LLAppViewer::instance()->requestQuit();
00412 }
00413 else
00414 {
00415 gAgent.teleportCancel();
00416 sInstance->mCancelBtn->setEnabled(FALSE);
00417 sInstance->setVisible(FALSE);
00418 }
00419 }