llprogressview.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /**
  2. * @file llprogressview.cpp
  3. * @brief LLProgressView class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llprogressview.h"
  34. #include "llbutton.h"
  35. #include "llgl.h"
  36. #include "llimagegl.h"
  37. #include "llprogressbar.h"
  38. #include "llrender.h"
  39. #include "lluictrlfactory.h"
  40. #include "llagent.h"
  41. #include "llappviewer.h"
  42. #include "llstartup.h"
  43. #include "llviewercontrol.h"
  44. #include "llviewertexturelist.h"
  45. #include "llviewerwindow.h"
  46. #include "llweb.h"
  47. LLProgressView* LLProgressView::sInstance = NULL;
  48. S32 gStartImageWidth = 1;
  49. S32 gStartImageHeight = 1;
  50. constexpr F32 FADE_IN_TIME = 1.f;
  51. const std::string ANIMATION_FILENAME = "Login Sequence ";
  52. const std::string ANIMATION_SUFFIX = ".jpg";
  53. LLProgressView::LLProgressView(const std::string& name, const LLRect& rect)
  54. : LLPanel(name, rect, false),
  55. mPercentDone(0.f),
  56. mURLInMessage(false),
  57. mMouseDownInActiveArea(false)
  58. {
  59. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_progress.xml");
  60. reshape(rect.getWidth(), rect.getHeight());
  61. sInstance = this;
  62. }
  63. bool LLProgressView::postBuild()
  64. {
  65. mProgressBar = getChild<LLProgressBar>("login_progress_bar");
  66. mCancelBtn = getChild<LLButton>("cancel_btn");
  67. mCancelBtn->setClickedCallback(LLProgressView::onCancelButtonClicked);
  68. mFadeTimer.stop();
  69. getChild<LLTextBox>("title_text")->setText(gSecondLife);
  70. getChild<LLTextBox>("message_text")->setClickedCallback(onClickMessage,
  71. this);
  72. return true;
  73. }
  74. LLProgressView::~LLProgressView()
  75. {
  76. gFocusMgr.releaseFocusIfNeeded(this);
  77. sInstance = NULL;
  78. }
  79. bool LLProgressView::handleHover(S32 x, S32 y, MASK mask)
  80. {
  81. if (!childrenHandleHover(x, y, mask))
  82. {
  83. gViewerWindowp->setCursor(UI_CURSOR_WAIT);
  84. }
  85. return true;
  86. }
  87. bool LLProgressView::handleKeyHere(KEY key, MASK mask)
  88. {
  89. // Suck up all keystokes except CTRL-Q.
  90. if (key == 'Q' && mask == MASK_CONTROL)
  91. {
  92. gAppViewerp->userQuit();
  93. }
  94. return true;
  95. }
  96. void LLProgressView::setVisible(bool visible)
  97. {
  98. if (!visible && getVisible())
  99. {
  100. mFadeTimer.start();
  101. }
  102. else if (visible && !getVisible())
  103. {
  104. gFocusMgr.setTopCtrl(this);
  105. setFocus(true);
  106. mFadeTimer.stop();
  107. mProgressTimer.start();
  108. LLPanel::setVisible(visible);
  109. }
  110. }
  111. void LLProgressView::draw()
  112. {
  113. static LLTimer timer;
  114. LLTexUnit* unit0 = gGL.getTexUnit(0);
  115. // Paint bitmap if we have got one
  116. gGL.pushMatrix();
  117. if (gStartTexture)
  118. {
  119. LLGLSUIDefault gls_ui;
  120. unit0->bind(gStartTexture);
  121. gGL.color4f(1.f, 1.f, 1.f,
  122. mFadeTimer.getStarted() ?
  123. clamp_rescale(mFadeTimer.getElapsedTimeF32(),
  124. 0.f, FADE_IN_TIME, 1.f, 0.f)
  125. : 1.f);
  126. F32 image_aspect = (F32)gStartImageWidth / (F32)gStartImageHeight;
  127. S32 width = getRect().getWidth();
  128. S32 height = getRect().getHeight();
  129. F32 view_aspect = (F32)width / (F32)height;
  130. // stretch image to maintain aspect ratio
  131. if (image_aspect > view_aspect)
  132. {
  133. gGL.translatef(-0.5f * (image_aspect / view_aspect - 1.f) * width,
  134. 0.f, 0.f);
  135. gGL.scalef(image_aspect / view_aspect, 1.f, 1.f);
  136. }
  137. else
  138. {
  139. gGL.translatef(0.f,
  140. -0.5f * (view_aspect / image_aspect - 1.f) * height,
  141. 0.f);
  142. gGL.scalef(1.f, view_aspect / image_aspect, 1.f);
  143. }
  144. gl_rect_2d_simple_tex(getRect().getWidth(), getRect().getHeight());
  145. unit0->unbind(LLTexUnit::TT_TEXTURE);
  146. }
  147. else
  148. {
  149. unit0->unbind(LLTexUnit::TT_TEXTURE);
  150. gGL.color4f(0.f, 0.f, 0.f, 1.f);
  151. gl_rect_2d(getRect());
  152. }
  153. gGL.popMatrix();
  154. // Handle fade-in animation
  155. if (mFadeTimer.getStarted())
  156. {
  157. LLPanel::draw();
  158. if (mFadeTimer.getElapsedTimeF32() > FADE_IN_TIME)
  159. {
  160. gFocusMgr.removeTopCtrlWithoutCallback(this);
  161. LLPanel::setVisible(false);
  162. gStartTexture = NULL;
  163. }
  164. return;
  165. }
  166. LLPanel::draw();
  167. }
  168. void LLProgressView::setText(const std::string& text)
  169. {
  170. getChild<LLTextBox>("progress_text")->setWrappedText(text);
  171. }
  172. void LLProgressView::setPercent(F32 percent)
  173. {
  174. mProgressBar->setPercent(percent);
  175. }
  176. void LLProgressView::setMessage(const std::string& msg)
  177. {
  178. mMessage = msg;
  179. mURLInMessage = mMessage.find("https://") != std::string::npos ||
  180. mMessage.find("http://") != std::string::npos ||
  181. mMessage.find("ftp://") != std::string::npos;
  182. getChild<LLTextBox>("message_text")->setWrappedText(mMessage);
  183. getChild<LLTextBox>("message_text")->setHoverActive(mURLInMessage);
  184. }
  185. void LLProgressView::setCancelButtonVisible(bool b, const std::string& label)
  186. {
  187. mCancelBtn->setVisible(b);
  188. mCancelBtn->setEnabled(b);
  189. mCancelBtn->setLabelSelected(label);
  190. mCancelBtn->setLabelUnselected(label);
  191. }
  192. //static
  193. void LLProgressView::onCancelButtonClicked(void*)
  194. {
  195. if (gAgent.teleportInProgress())
  196. {
  197. gAgent.teleportCancel();
  198. sInstance->mCancelBtn->setEnabled(false);
  199. sInstance->setVisible(false);
  200. }
  201. else
  202. {
  203. llinfos << "User requested quit during login." << llendl;
  204. gAppViewerp->requestQuit();
  205. }
  206. }
  207. //static
  208. void LLProgressView::onClickMessage(void* data)
  209. {
  210. LLProgressView* viewp = (LLProgressView*)data;
  211. if (!viewp || viewp->mMessage.empty())
  212. {
  213. return;
  214. }
  215. size_t start_pos = viewp->mMessage.find("https://");
  216. if (start_pos == std::string::npos)
  217. {
  218. start_pos = viewp->mMessage.find("http://");
  219. }
  220. if (start_pos == std::string::npos)
  221. {
  222. start_pos = viewp->mMessage.find("ftp://");
  223. }
  224. if (start_pos == std::string::npos)
  225. {
  226. return;
  227. }
  228. std::string url_to_open;
  229. size_t end_pos = viewp->mMessage.find_first_of(" \n\r\t", start_pos);
  230. if (end_pos != std::string::npos)
  231. {
  232. url_to_open = viewp->mMessage.substr(start_pos, end_pos - start_pos);
  233. }
  234. else
  235. {
  236. url_to_open = viewp->mMessage.substr(start_pos);
  237. }
  238. LLWeb::loadURLExternal(url_to_open);
  239. }