PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llpanelprimmediacontrols.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 1380 lines | 1066 code | 188 blank | 126 comment | 158 complexity | 9ed2e03068db42eecd838d87866ccc65 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelprimmediacontrols.cpp
  3. * @brief media controls popup panel
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llagent.h"
  28. #include "llagentcamera.h"
  29. #include "llparcel.h"
  30. #include "llpanel.h"
  31. #include "llselectmgr.h"
  32. #include "llmediaentry.h"
  33. #include "llrender.h"
  34. #include "lldrawable.h"
  35. #include "llviewerwindow.h"
  36. #include "lluictrlfactory.h"
  37. #include "llbutton.h"
  38. #include "llface.h"
  39. #include "llcombobox.h"
  40. #include "lllayoutstack.h"
  41. #include "llslider.h"
  42. #include "llhudview.h"
  43. #include "lliconctrl.h"
  44. #include "lltoolpie.h"
  45. #include "llviewercamera.h"
  46. #include "llviewerobjectlist.h"
  47. #include "llpanelprimmediacontrols.h"
  48. #include "llpluginclassmedia.h"
  49. #include "llprogressbar.h"
  50. #include "llsliderctrl.h"
  51. #include "llstring.h"
  52. #include "llviewercontrol.h"
  53. #include "llviewerdisplay.h"
  54. #include "llviewerparcelmgr.h"
  55. #include "llviewermedia.h"
  56. #include "llviewermediafocus.h"
  57. #include "llvovolume.h"
  58. #include "llweb.h"
  59. #include "llwindow.h"
  60. #include "llwindowshade.h"
  61. #include "llfloatertools.h" // to enable hide if build tools are up
  62. #include "llvector4a.h"
  63. // Functions pulled from pipeline.cpp
  64. glh::matrix4f glh_get_current_modelview();
  65. glh::matrix4f glh_get_current_projection();
  66. // Functions pulled from llviewerdisplay.cpp
  67. bool get_hud_matrices(glh::matrix4f &proj, glh::matrix4f &model);
  68. // Warning: make sure these two match!
  69. const LLPanelPrimMediaControls::EZoomLevel LLPanelPrimMediaControls::kZoomLevels[] = { ZOOM_NONE, ZOOM_MEDIUM };
  70. const int LLPanelPrimMediaControls::kNumZoomLevels = 2;
  71. //
  72. // LLPanelPrimMediaControls
  73. //
  74. LLPanelPrimMediaControls::LLPanelPrimMediaControls() :
  75. mAlpha(1.f),
  76. mCurrentURL(""),
  77. mPreviousURL(""),
  78. mPauseFadeout(false),
  79. mUpdateSlider(true),
  80. mClearFaceOnFade(false),
  81. mCurrentRate(0.0),
  82. mMovieDuration(0.0),
  83. mTargetObjectID(LLUUID::null),
  84. mTargetObjectFace(0),
  85. mTargetImplID(LLUUID::null),
  86. mTargetObjectNormal(LLVector3::zero),
  87. mZoomObjectID(LLUUID::null),
  88. mZoomObjectFace(0),
  89. mVolumeSliderVisible(0),
  90. mWindowShade(NULL),
  91. mHideImmediately(false)
  92. {
  93. mCommitCallbackRegistrar.add("MediaCtrl.Close", boost::bind(&LLPanelPrimMediaControls::onClickClose, this));
  94. mCommitCallbackRegistrar.add("MediaCtrl.Back", boost::bind(&LLPanelPrimMediaControls::onClickBack, this));
  95. mCommitCallbackRegistrar.add("MediaCtrl.Forward", boost::bind(&LLPanelPrimMediaControls::onClickForward, this));
  96. mCommitCallbackRegistrar.add("MediaCtrl.Home", boost::bind(&LLPanelPrimMediaControls::onClickHome, this));
  97. mCommitCallbackRegistrar.add("MediaCtrl.Stop", boost::bind(&LLPanelPrimMediaControls::onClickStop, this));
  98. mCommitCallbackRegistrar.add("MediaCtrl.MediaStop", boost::bind(&LLPanelPrimMediaControls::onClickMediaStop, this));
  99. mCommitCallbackRegistrar.add("MediaCtrl.Reload", boost::bind(&LLPanelPrimMediaControls::onClickReload, this));
  100. mCommitCallbackRegistrar.add("MediaCtrl.Play", boost::bind(&LLPanelPrimMediaControls::onClickPlay, this));
  101. mCommitCallbackRegistrar.add("MediaCtrl.Pause", boost::bind(&LLPanelPrimMediaControls::onClickPause, this));
  102. mCommitCallbackRegistrar.add("MediaCtrl.Open", boost::bind(&LLPanelPrimMediaControls::onClickOpen, this));
  103. mCommitCallbackRegistrar.add("MediaCtrl.Zoom", boost::bind(&LLPanelPrimMediaControls::onClickZoom, this));
  104. mCommitCallbackRegistrar.add("MediaCtrl.CommitURL", boost::bind(&LLPanelPrimMediaControls::onCommitURL, this));
  105. mCommitCallbackRegistrar.add("MediaCtrl.JumpProgress", boost::bind(&LLPanelPrimMediaControls::onCommitSlider, this));
  106. mCommitCallbackRegistrar.add("MediaCtrl.CommitVolumeUp", boost::bind(&LLPanelPrimMediaControls::onCommitVolumeUp, this));
  107. mCommitCallbackRegistrar.add("MediaCtrl.CommitVolumeDown", boost::bind(&LLPanelPrimMediaControls::onCommitVolumeDown, this));
  108. mCommitCallbackRegistrar.add("MediaCtrl.Volume", boost::bind(&LLPanelPrimMediaControls::onCommitVolumeSlider, this));
  109. mCommitCallbackRegistrar.add("MediaCtrl.ToggleMute", boost::bind(&LLPanelPrimMediaControls::onToggleMute, this));
  110. mCommitCallbackRegistrar.add("MediaCtrl.ShowVolumeSlider", boost::bind(&LLPanelPrimMediaControls::showVolumeSlider, this));
  111. mCommitCallbackRegistrar.add("MediaCtrl.HideVolumeSlider", boost::bind(&LLPanelPrimMediaControls::hideVolumeSlider, this));
  112. mCommitCallbackRegistrar.add("MediaCtrl.SkipBack", boost::bind(&LLPanelPrimMediaControls::onClickSkipBack, this));
  113. mCommitCallbackRegistrar.add("MediaCtrl.SkipForward", boost::bind(&LLPanelPrimMediaControls::onClickSkipForward, this));
  114. buildFromFile( "panel_prim_media_controls.xml");
  115. mInactivityTimer.reset();
  116. mFadeTimer.stop();
  117. mCurrentZoom = ZOOM_NONE;
  118. mScrollState = SCROLL_NONE;
  119. mPanelHandle.bind(this);
  120. mInactiveTimeout = gSavedSettings.getF32("MediaControlTimeout");
  121. mControlFadeTime = gSavedSettings.getF32("MediaControlFadeTime");
  122. }
  123. LLPanelPrimMediaControls::~LLPanelPrimMediaControls()
  124. {
  125. }
  126. BOOL LLPanelPrimMediaControls::postBuild()
  127. {
  128. mMediaRegion = getChild<LLView>("media_region");
  129. mBackCtrl = getChild<LLUICtrl>("back");
  130. mFwdCtrl = getChild<LLUICtrl>("fwd");
  131. mReloadCtrl = getChild<LLUICtrl>("reload");
  132. mPlayCtrl = getChild<LLUICtrl>("play");
  133. mPauseCtrl = getChild<LLUICtrl>("pause");
  134. mStopCtrl = getChild<LLUICtrl>("stop");
  135. mMediaStopCtrl = getChild<LLUICtrl>("media_stop");
  136. mHomeCtrl = getChild<LLUICtrl>("home");
  137. mUnzoomCtrl = getChild<LLUICtrl>("close"); // This is actually "unzoom"
  138. mOpenCtrl = getChild<LLUICtrl>("new_window");
  139. mZoomCtrl = getChild<LLUICtrl>("zoom_frame");
  140. mMediaProgressPanel = getChild<LLPanel>("media_progress_indicator");
  141. mMediaProgressBar = getChild<LLProgressBar>("media_progress_bar");
  142. mMediaAddressCtrl = getChild<LLUICtrl>("media_address");
  143. mMediaAddress = getChild<LLUICtrl>("media_address_url");
  144. mMediaPlaySliderPanel = getChild<LLUICtrl>("media_play_position");
  145. mMediaPlaySliderCtrl = getChild<LLUICtrl>("media_play_slider");
  146. mSkipFwdCtrl = getChild<LLUICtrl>("skip_forward");
  147. mSkipBackCtrl = getChild<LLUICtrl>("skip_back");
  148. mVolumeCtrl = getChild<LLUICtrl>("media_volume");
  149. mMuteBtn = getChild<LLButton>("media_mute_button");
  150. mVolumeSliderCtrl = getChild<LLSliderCtrl>("volume_slider");
  151. mWhitelistIcon = getChild<LLIconCtrl>("media_whitelist_flag");
  152. mSecureLockIcon = getChild<LLIconCtrl>("media_secure_lock_flag");
  153. mMediaControlsStack = getChild<LLLayoutStack>("media_controls");
  154. mLeftBookend = getChild<LLUICtrl>("left_bookend");
  155. mRightBookend = getChild<LLUICtrl>("right_bookend");
  156. mBackgroundImage = LLUI::getUIImage(getString("control_background_image_name"));
  157. mVolumeSliderBackgroundImage = LLUI::getUIImage(getString("control_background_image_name"));
  158. LLStringUtil::convertToF32(getString("skip_step"), mSkipStep);
  159. LLStringUtil::convertToS32(getString("min_width"), mMinWidth);
  160. LLStringUtil::convertToS32(getString("min_height"), mMinHeight);
  161. LLStringUtil::convertToF32(getString("zoom_near_padding"), mZoomNearPadding);
  162. LLStringUtil::convertToF32(getString("zoom_medium_padding"), mZoomMediumPadding);
  163. LLStringUtil::convertToF32(getString("zoom_far_padding"), mZoomFarPadding);
  164. LLStringUtil::convertToS32(getString("top_world_view_avoid_zone"), mTopWorldViewAvoidZone);
  165. // These are currently removed...but getChild creates a "dummy" widget.
  166. // This class handles them missing.
  167. mMediaPanelScroll = findChild<LLUICtrl>("media_panel_scroll");
  168. mScrollUpCtrl = findChild<LLButton>("scrollup");
  169. mScrollLeftCtrl = findChild<LLButton>("scrollleft");
  170. mScrollRightCtrl = findChild<LLButton>("scrollright");
  171. mScrollDownCtrl = findChild<LLButton>("scrolldown");
  172. if (mScrollUpCtrl)
  173. {
  174. mScrollUpCtrl->setClickedCallback(onScrollUp, this);
  175. mScrollUpCtrl->setHeldDownCallback(onScrollUpHeld, this);
  176. mScrollUpCtrl->setMouseUpCallback(onScrollStop, this);
  177. }
  178. if (mScrollLeftCtrl)
  179. {
  180. mScrollLeftCtrl->setClickedCallback(onScrollLeft, this);
  181. mScrollLeftCtrl->setHeldDownCallback(onScrollLeftHeld, this);
  182. mScrollLeftCtrl->setMouseUpCallback(onScrollStop, this);
  183. }
  184. if (mScrollRightCtrl)
  185. {
  186. mScrollRightCtrl->setClickedCallback(onScrollRight, this);
  187. mScrollRightCtrl->setHeldDownCallback(onScrollRightHeld, this);
  188. mScrollRightCtrl->setMouseUpCallback(onScrollStop, this);
  189. }
  190. if (mScrollDownCtrl)
  191. {
  192. mScrollDownCtrl->setClickedCallback(onScrollDown, this);
  193. mScrollDownCtrl->setHeldDownCallback(onScrollDownHeld, this);
  194. mScrollDownCtrl->setMouseUpCallback(onScrollStop, this);
  195. }
  196. mMediaAddress->setFocusReceivedCallback(boost::bind(&LLPanelPrimMediaControls::onInputURL, _1, this ));
  197. gAgent.setMouselookModeInCallback(boost::bind(&LLPanelPrimMediaControls::onMouselookModeIn, this));
  198. LLWindowShade::Params window_shade_params;
  199. window_shade_params.name = "window_shade";
  200. mCurrentZoom = ZOOM_NONE;
  201. // clicks on buttons do not remove keyboard focus from media
  202. setIsChrome(TRUE);
  203. return TRUE;
  204. }
  205. void LLPanelPrimMediaControls::setMediaFace(LLPointer<LLViewerObject> objectp, S32 face, viewer_media_t media_impl, LLVector3 pick_normal)
  206. {
  207. if (media_impl.notNull() && objectp.notNull())
  208. {
  209. LLUUID prev_id = mTargetImplID;
  210. mTargetImplID = media_impl->getMediaTextureID();
  211. mTargetObjectID = objectp->getID();
  212. mTargetObjectFace = face;
  213. mTargetObjectNormal = pick_normal;
  214. mClearFaceOnFade = false;
  215. if (prev_id != mTargetImplID)
  216. mVolumeSliderCtrl->setValue(media_impl->getVolume());
  217. }
  218. else
  219. {
  220. // This happens on a timer now.
  221. // mTargetImplID = LLUUID::null;
  222. // mTargetObjectID = LLUUID::null;
  223. // mTargetObjectFace = 0;
  224. mClearFaceOnFade = true;
  225. }
  226. updateShape();
  227. }
  228. void LLPanelPrimMediaControls::focusOnTarget()
  229. {
  230. // Sets the media focus to the current target of the LLPanelPrimMediaControls.
  231. // This is how we transition from hover to focus when the user clicks on a control.
  232. LLViewerMediaImpl* media_impl = getTargetMediaImpl();
  233. if(media_impl)
  234. {
  235. if(!media_impl->hasFocus())
  236. {
  237. // The current target doesn't have media focus -- focus on it.
  238. LLViewerObject* objectp = getTargetObject();
  239. LLViewerMediaFocus::getInstance()->setFocusFace(objectp, mTargetObjectFace, media_impl, mTargetObjectNormal);
  240. }
  241. }
  242. }
  243. LLViewerMediaImpl* LLPanelPrimMediaControls::getTargetMediaImpl()
  244. {
  245. return LLViewerMedia::getMediaImplFromTextureID(mTargetImplID);
  246. }
  247. LLViewerObject* LLPanelPrimMediaControls::getTargetObject()
  248. {
  249. return gObjectList.findObject(mTargetObjectID);
  250. }
  251. LLPluginClassMedia* LLPanelPrimMediaControls::getTargetMediaPlugin()
  252. {
  253. LLViewerMediaImpl* impl = getTargetMediaImpl();
  254. if(impl && impl->hasMedia())
  255. {
  256. return impl->getMediaPlugin();
  257. }
  258. return NULL;
  259. }
  260. void LLPanelPrimMediaControls::updateShape()
  261. {
  262. LLViewerMediaImpl* media_impl = getTargetMediaImpl();
  263. LLViewerObject* objectp = getTargetObject();
  264. if(!media_impl || gFloaterTools->getVisible())
  265. {
  266. setVisible(FALSE);
  267. return;
  268. }
  269. LLPluginClassMedia* media_plugin = NULL;
  270. if(media_impl->hasMedia())
  271. {
  272. media_plugin = media_impl->getMediaPlugin();
  273. }
  274. LLParcel *parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  275. bool can_navigate = parcel->getMediaAllowNavigate();
  276. bool enabled = false;
  277. bool is_zoomed = (mCurrentZoom != ZOOM_NONE) && (mTargetObjectID == mZoomObjectID) && (mTargetObjectFace == mZoomObjectFace);
  278. // There is no such thing as "has_focus" being different from normal controls set
  279. // anymore (as of user feedback from bri 10/09). So we cheat here and force 'has_focus'
  280. // to 'true' (or, actually, we use a setting)
  281. bool has_focus = (gSavedSettings.getBOOL("PrimMediaControlsUseHoverControlSet")) ? media_impl->hasFocus() : true;
  282. setVisible(enabled);
  283. if (objectp)
  284. {
  285. bool mini_controls = false;
  286. LLMediaEntry *media_data = objectp->getTE(mTargetObjectFace)->getMediaData();
  287. if (media_data && NULL != dynamic_cast<LLVOVolume*>(objectp))
  288. {
  289. // Don't show the media controls if we do not have permissions
  290. enabled = dynamic_cast<LLVOVolume*>(objectp)->hasMediaPermission(media_data, LLVOVolume::MEDIA_PERM_CONTROL);
  291. mini_controls = (LLMediaEntry::MINI == media_data->getControls());
  292. }
  293. const bool is_hud = objectp->isHUDAttachment();
  294. //
  295. // Set the state of the buttons
  296. //
  297. // XXX RSP: TODO: FIXME: clean this up so that it is clearer what mode we are in,
  298. // and that only the proper controls get made visible/enabled according to that mode.
  299. mBackCtrl->setVisible(has_focus);
  300. mFwdCtrl->setVisible(has_focus);
  301. mReloadCtrl->setVisible(has_focus);
  302. mStopCtrl->setVisible(false);
  303. mHomeCtrl->setVisible(has_focus);
  304. mZoomCtrl->setVisible(!is_zoomed);
  305. mUnzoomCtrl->setVisible(is_zoomed);
  306. mOpenCtrl->setVisible(true);
  307. mMediaAddressCtrl->setVisible(has_focus && !mini_controls);
  308. mMediaPlaySliderPanel->setVisible(has_focus && !mini_controls);
  309. mVolumeCtrl->setVisible(false);
  310. mWhitelistIcon->setVisible(!mini_controls && (media_data)?media_data->getWhiteListEnable():false);
  311. // Disable zoom if HUD
  312. mZoomCtrl->setEnabled(!is_hud);
  313. mUnzoomCtrl->setEnabled(!is_hud);
  314. mSecureLockIcon->setVisible(false);
  315. mCurrentURL = media_impl->getCurrentMediaURL();
  316. mBackCtrl->setEnabled((media_impl != NULL) && media_impl->canNavigateBack() && can_navigate);
  317. mFwdCtrl->setEnabled((media_impl != NULL) && media_impl->canNavigateForward() && can_navigate);
  318. mStopCtrl->setEnabled(has_focus && can_navigate);
  319. mHomeCtrl->setEnabled(has_focus && can_navigate);
  320. LLPluginClassMediaOwner::EMediaStatus result = ((media_impl != NULL) && media_impl->hasMedia()) ? media_plugin->getStatus() : LLPluginClassMediaOwner::MEDIA_NONE;
  321. mVolumeCtrl->setVisible(has_focus);
  322. mVolumeCtrl->setEnabled(has_focus);
  323. mVolumeSliderCtrl->setEnabled(has_focus && shouldVolumeSliderBeVisible());
  324. mVolumeSliderCtrl->setVisible(has_focus && shouldVolumeSliderBeVisible());
  325. if(media_plugin && media_plugin->pluginSupportsMediaTime())
  326. {
  327. mReloadCtrl->setEnabled(false);
  328. mReloadCtrl->setVisible(false);
  329. mMediaStopCtrl->setVisible(has_focus);
  330. mHomeCtrl->setVisible(has_focus);
  331. mBackCtrl->setVisible(false);
  332. mFwdCtrl->setVisible(false);
  333. mMediaAddressCtrl->setVisible(false);
  334. mMediaAddressCtrl->setEnabled(false);
  335. mMediaPlaySliderPanel->setVisible(has_focus && !mini_controls);
  336. mMediaPlaySliderPanel->setEnabled(has_focus && !mini_controls);
  337. mSkipFwdCtrl->setVisible(has_focus && !mini_controls);
  338. mSkipFwdCtrl->setEnabled(has_focus && !mini_controls);
  339. mSkipBackCtrl->setVisible(has_focus && !mini_controls);
  340. mSkipBackCtrl->setEnabled(has_focus && !mini_controls);
  341. mVolumeCtrl->setVisible(has_focus);
  342. mVolumeCtrl->setEnabled(has_focus);
  343. mVolumeSliderCtrl->setEnabled(has_focus && shouldVolumeSliderBeVisible());
  344. mVolumeSliderCtrl->setVisible(has_focus && shouldVolumeSliderBeVisible());
  345. mWhitelistIcon->setVisible(false);
  346. mSecureLockIcon->setVisible(false);
  347. if (mMediaPanelScroll)
  348. {
  349. mMediaPanelScroll->setVisible(false);
  350. mScrollUpCtrl->setVisible(false);
  351. mScrollDownCtrl->setVisible(false);
  352. mScrollRightCtrl->setVisible(false);
  353. mScrollDownCtrl->setVisible(false);
  354. }
  355. F32 volume = media_impl->getVolume();
  356. // movie's url changed
  357. if(mCurrentURL!=mPreviousURL)
  358. {
  359. mMovieDuration = media_plugin->getDuration();
  360. mPreviousURL = mCurrentURL;
  361. }
  362. if(mMovieDuration == 0)
  363. {
  364. mMovieDuration = media_plugin->getDuration();
  365. mMediaPlaySliderCtrl->setValue(0);
  366. mMediaPlaySliderCtrl->setEnabled(false);
  367. }
  368. // TODO: What if it's not fully loaded
  369. if(mUpdateSlider && mMovieDuration!= 0)
  370. {
  371. F64 current_time = media_plugin->getCurrentTime();
  372. F32 percent = current_time / mMovieDuration;
  373. mMediaPlaySliderCtrl->setValue(percent);
  374. mMediaPlaySliderCtrl->setEnabled(true);
  375. }
  376. // video vloume
  377. if(volume <= 0.0)
  378. {
  379. mMuteBtn->setToggleState(true);
  380. }
  381. else if (volume >= 1.0)
  382. {
  383. mMuteBtn->setToggleState(false);
  384. }
  385. else
  386. {
  387. mMuteBtn->setToggleState(false);
  388. }
  389. switch(result)
  390. {
  391. case LLPluginClassMediaOwner::MEDIA_PLAYING:
  392. mPlayCtrl->setEnabled(FALSE);
  393. mPlayCtrl->setVisible(FALSE);
  394. mPauseCtrl->setEnabled(TRUE);
  395. mPauseCtrl->setVisible(has_focus);
  396. break;
  397. case LLPluginClassMediaOwner::MEDIA_PAUSED:
  398. default:
  399. mPauseCtrl->setEnabled(FALSE);
  400. mPauseCtrl->setVisible(FALSE);
  401. mPlayCtrl->setEnabled(TRUE);
  402. mPlayCtrl->setVisible(has_focus);
  403. break;
  404. }
  405. }
  406. else // web based
  407. {
  408. if(media_plugin)
  409. {
  410. mCurrentURL = media_plugin->getLocation();
  411. }
  412. else
  413. {
  414. mCurrentURL.clear();
  415. }
  416. mPlayCtrl->setVisible(FALSE);
  417. mPauseCtrl->setVisible(FALSE);
  418. mMediaStopCtrl->setVisible(FALSE);
  419. mMediaAddressCtrl->setVisible(has_focus && !mini_controls);
  420. mMediaAddressCtrl->setEnabled(has_focus && !mini_controls);
  421. mMediaPlaySliderPanel->setVisible(FALSE);
  422. mMediaPlaySliderPanel->setEnabled(FALSE);
  423. mSkipFwdCtrl->setVisible(FALSE);
  424. mSkipFwdCtrl->setEnabled(FALSE);
  425. mSkipBackCtrl->setVisible(FALSE);
  426. mSkipBackCtrl->setEnabled(FALSE);
  427. if(media_impl->getVolume() <= 0.0)
  428. {
  429. mMuteBtn->setToggleState(true);
  430. }
  431. else
  432. {
  433. mMuteBtn->setToggleState(false);
  434. }
  435. if (mMediaPanelScroll)
  436. {
  437. mMediaPanelScroll->setVisible(has_focus);
  438. mScrollUpCtrl->setVisible(has_focus);
  439. mScrollDownCtrl->setVisible(has_focus);
  440. mScrollRightCtrl->setVisible(has_focus);
  441. mScrollDownCtrl->setVisible(has_focus);
  442. }
  443. // TODO: get the secure lock bool from media plug in
  444. std::string prefix = std::string("https://");
  445. std::string test_prefix = mCurrentURL.substr(0, prefix.length());
  446. LLStringUtil::toLower(test_prefix);
  447. if(test_prefix == prefix)
  448. {
  449. mSecureLockIcon->setVisible(has_focus);
  450. }
  451. if(mCurrentURL!=mPreviousURL)
  452. {
  453. setCurrentURL();
  454. mPreviousURL = mCurrentURL;
  455. }
  456. if(result == LLPluginClassMediaOwner::MEDIA_LOADING)
  457. {
  458. mReloadCtrl->setEnabled(FALSE);
  459. mReloadCtrl->setVisible(FALSE);
  460. mStopCtrl->setEnabled(TRUE);
  461. mStopCtrl->setVisible(has_focus);
  462. }
  463. else
  464. {
  465. mReloadCtrl->setEnabled(TRUE);
  466. mReloadCtrl->setVisible(has_focus);
  467. mStopCtrl->setEnabled(FALSE);
  468. mStopCtrl->setVisible(FALSE);
  469. }
  470. }
  471. if(media_plugin)
  472. {
  473. //
  474. // Handle progress bar
  475. //
  476. if(LLPluginClassMediaOwner::MEDIA_LOADING == media_plugin->getStatus())
  477. {
  478. mMediaProgressPanel->setVisible(true);
  479. mMediaProgressBar->setValue(media_plugin->getProgressPercent());
  480. }
  481. else
  482. {
  483. mMediaProgressPanel->setVisible(false);
  484. }
  485. }
  486. if(media_impl)
  487. {
  488. //
  489. // Handle Scrolling
  490. //
  491. switch (mScrollState)
  492. {
  493. case SCROLL_UP:
  494. media_impl->scrollWheel(0, -1, MASK_NONE);
  495. break;
  496. case SCROLL_DOWN:
  497. media_impl->scrollWheel(0, 1, MASK_NONE);
  498. break;
  499. case SCROLL_LEFT:
  500. media_impl->scrollWheel(1, 0, MASK_NONE);
  501. // media_impl->handleKeyHere(KEY_LEFT, MASK_NONE);
  502. break;
  503. case SCROLL_RIGHT:
  504. media_impl->scrollWheel(-1, 0, MASK_NONE);
  505. // media_impl->handleKeyHere(KEY_RIGHT, MASK_NONE);
  506. break;
  507. case SCROLL_NONE:
  508. default:
  509. break;
  510. }
  511. }
  512. setVisible(enabled);
  513. //
  514. // Calculate position and shape of the controls
  515. //
  516. std::vector<LLVector3>::iterator vert_it;
  517. std::vector<LLVector3>::iterator vert_end;
  518. std::vector<LLVector3> vect_face;
  519. LLVolume* volume = objectp->getVolume();
  520. if (volume)
  521. {
  522. const LLVolumeFace& vf = volume->getVolumeFace(mTargetObjectFace);
  523. LLVector3 ext[2];
  524. ext[0].set(vf.mExtents[0].getF32ptr());
  525. ext[1].set(vf.mExtents[1].getF32ptr());
  526. LLVector3 center = (ext[0]+ext[1])*0.5f;
  527. LLVector3 size = (ext[1]-ext[0])*0.5f;
  528. LLVector3 vert[] =
  529. {
  530. center + size.scaledVec(LLVector3(1,1,1)),
  531. center + size.scaledVec(LLVector3(-1,1,1)),
  532. center + size.scaledVec(LLVector3(1,-1,1)),
  533. center + size.scaledVec(LLVector3(-1,-1,1)),
  534. center + size.scaledVec(LLVector3(1,1,-1)),
  535. center + size.scaledVec(LLVector3(-1,1,-1)),
  536. center + size.scaledVec(LLVector3(1,-1,-1)),
  537. center + size.scaledVec(LLVector3(-1,-1,-1)),
  538. };
  539. LLVOVolume* vo = (LLVOVolume*) objectp;
  540. for (U32 i = 0; i < 8; i++)
  541. {
  542. vect_face.push_back(vo->volumePositionToAgent(vert[i]));
  543. }
  544. }
  545. vert_it = vect_face.begin();
  546. vert_end = vect_face.end();
  547. glh::matrix4f mat;
  548. if (!is_hud)
  549. {
  550. mat = glh_get_current_projection() * glh_get_current_modelview();
  551. }
  552. else {
  553. glh::matrix4f proj, modelview;
  554. if (get_hud_matrices(proj, modelview))
  555. mat = proj * modelview;
  556. }
  557. LLVector3 min = LLVector3(1,1,1);
  558. LLVector3 max = LLVector3(-1,-1,-1);
  559. for(; vert_it != vert_end; ++vert_it)
  560. {
  561. // project silhouette vertices into screen space
  562. glh::vec3f screen_vert = glh::vec3f(vert_it->mV);
  563. mat.mult_matrix_vec(screen_vert);
  564. // add to screenspace bounding box
  565. update_min_max(min, max, LLVector3(screen_vert.v));
  566. }
  567. // convert screenspace bbox to pixels (in screen coords)
  568. LLRect window_rect = gViewerWindow->getWorldViewRectScaled();
  569. LLCoordGL screen_min;
  570. screen_min.mX = llround((F32)window_rect.mLeft + (F32)window_rect.getWidth() * (min.mV[VX] + 1.f) * 0.5f);
  571. screen_min.mY = llround((F32)window_rect.mBottom + (F32)window_rect.getHeight() * (min.mV[VY] + 1.f) * 0.5f);
  572. LLCoordGL screen_max;
  573. screen_max.mX = llround((F32)window_rect.mLeft + (F32)window_rect.getWidth() * (max.mV[VX] + 1.f) * 0.5f);
  574. screen_max.mY = llround((F32)window_rect.mBottom + (F32)window_rect.getHeight() * (max.mV[VY] + 1.f) * 0.5f);
  575. // grow panel so that screenspace bounding box fits inside "media_region" element of panel
  576. LLRect media_panel_rect;
  577. // Get the height of the controls (less the volume slider)
  578. S32 controls_height = mMediaControlsStack->getRect().getHeight() - mVolumeSliderCtrl->getRect().getHeight();
  579. getParent()->screenRectToLocal(LLRect(screen_min.mX, screen_max.mY, screen_max.mX, screen_min.mY), &media_panel_rect);
  580. media_panel_rect.mTop += controls_height;
  581. // keep all parts of panel on-screen
  582. // Area of the top of the world view to avoid putting the controls
  583. window_rect.mTop -= mTopWorldViewAvoidZone;
  584. // Don't include "spacing" bookends on left & right of the media controls
  585. window_rect.mLeft -= mLeftBookend->getRect().getWidth();
  586. window_rect.mRight += mRightBookend->getRect().getWidth();
  587. // Don't include the volume slider
  588. window_rect.mBottom -= mVolumeSliderCtrl->getRect().getHeight();
  589. media_panel_rect.intersectWith(window_rect);
  590. // clamp to minimum size, keeping rect inside window
  591. S32 centerX = media_panel_rect.getCenterX();
  592. S32 centerY = media_panel_rect.getCenterY();
  593. // Shrink screen rect by min width and height, to ensure containment
  594. window_rect.stretch(-mMinWidth/2, -mMinHeight/2);
  595. window_rect.clampPointToRect(centerX, centerY);
  596. media_panel_rect.setCenterAndSize(centerX, centerY,
  597. llmax(mMinWidth, media_panel_rect.getWidth()),
  598. llmax(mMinHeight, media_panel_rect.getHeight()));
  599. // Finally set the size of the panel
  600. setShape(media_panel_rect, true);
  601. // Test mouse position to see if the cursor is stationary
  602. LLCoordWindow cursor_pos_window;
  603. getWindow()->getCursorPosition(&cursor_pos_window);
  604. // If last pos is not equal to current pos, the mouse has moved
  605. // We need to reset the timer, and make sure the panel is visible
  606. if(cursor_pos_window.mX != mLastCursorPos.mX ||
  607. cursor_pos_window.mY != mLastCursorPos.mY ||
  608. mScrollState != SCROLL_NONE)
  609. {
  610. mInactivityTimer.start();
  611. mLastCursorPos = cursor_pos_window;
  612. }
  613. if(isMouseOver() || hasFocus())
  614. {
  615. // Never fade the controls if the mouse is over them or they have keyboard focus.
  616. mFadeTimer.stop();
  617. }
  618. else if(!mClearFaceOnFade && (mInactivityTimer.getElapsedTimeF32() < mInactiveTimeout))
  619. {
  620. // Mouse is over the object, but has not been stationary for long enough to fade the UI
  621. mFadeTimer.stop();
  622. }
  623. else if(! mFadeTimer.getStarted() )
  624. {
  625. // we need to start fading the UI (and we have not already started)
  626. mFadeTimer.reset();
  627. mFadeTimer.start();
  628. }
  629. else
  630. {
  631. // I don't think this is correct anymore. This is done in draw() after the fade has completed.
  632. // setVisible(FALSE);
  633. }
  634. }
  635. }
  636. /*virtual*/
  637. void LLPanelPrimMediaControls::draw()
  638. {
  639. LLViewerMediaImpl* impl = getTargetMediaImpl();
  640. if (impl)
  641. {
  642. LLNotificationPtr notification = impl->getCurrentNotification();
  643. if (notification != mActiveNotification)
  644. {
  645. mActiveNotification = notification;
  646. if (notification)
  647. {
  648. showNotification(notification);
  649. }
  650. else
  651. {
  652. hideNotification();
  653. }
  654. }
  655. }
  656. F32 alpha = getDrawContext().mAlpha;
  657. if(mHideImmediately)
  658. {
  659. //hide this panel
  660. clearFaceOnFade();
  661. mHideImmediately = false;
  662. }
  663. else if(mFadeTimer.getStarted())
  664. {
  665. F32 time = mFadeTimer.getElapsedTimeF32();
  666. alpha *= llmax(lerp(1.0, 0.0, time / mControlFadeTime), 0.0f);
  667. if(time >= mControlFadeTime)
  668. {
  669. //hide this panel
  670. clearFaceOnFade();
  671. }
  672. }
  673. // Build rect for icon area in coord system of this panel
  674. // Assumes layout_stack is a direct child of this panel
  675. mMediaControlsStack->updateLayout();
  676. // adjust for layout stack spacing
  677. S32 space = mMediaControlsStack->getPanelSpacing() + 2;
  678. LLRect controls_bg_area = mMediaControlsStack->getRect();
  679. controls_bg_area.mTop += space + 2;
  680. // adjust to ignore space from volume slider
  681. controls_bg_area.mBottom += mVolumeSliderCtrl->getRect().getHeight();
  682. // adjust to ignore space from left bookend padding
  683. controls_bg_area.mLeft += mLeftBookend->getRect().getWidth() - space;
  684. // ignore space from right bookend padding
  685. controls_bg_area.mRight -= mRightBookend->getRect().getWidth() - space - 2;
  686. // draw control background UI image
  687. mBackgroundImage->draw( controls_bg_area, UI_VERTEX_COLOR % alpha);
  688. // draw volume slider background UI image
  689. if (mVolumeSliderCtrl->getVisible())
  690. {
  691. LLRect volume_slider_rect;
  692. screenRectToLocal(mVolumeSliderCtrl->calcScreenRect(), &volume_slider_rect);
  693. mVolumeSliderBackgroundImage->draw(volume_slider_rect, UI_VERTEX_COLOR % alpha);
  694. }
  695. {
  696. LLViewDrawContext context(alpha);
  697. LLPanel::draw();
  698. }
  699. }
  700. BOOL LLPanelPrimMediaControls::handleScrollWheel(S32 x, S32 y, S32 clicks)
  701. {
  702. mInactivityTimer.start();
  703. return LLViewerMediaFocus::getInstance()->handleScrollWheel(x, y, clicks);
  704. }
  705. BOOL LLPanelPrimMediaControls::handleMouseDown(S32 x, S32 y, MASK mask)
  706. {
  707. mInactivityTimer.start();
  708. return LLPanel::handleMouseDown(x, y, mask);
  709. }
  710. BOOL LLPanelPrimMediaControls::handleMouseUp(S32 x, S32 y, MASK mask)
  711. {
  712. mInactivityTimer.start();
  713. return LLPanel::handleMouseUp(x, y, mask);
  714. }
  715. BOOL LLPanelPrimMediaControls::handleKeyHere( KEY key, MASK mask )
  716. {
  717. mInactivityTimer.start();
  718. return LLPanel::handleKeyHere(key, mask);
  719. }
  720. bool LLPanelPrimMediaControls::isMouseOver()
  721. {
  722. bool result = false;
  723. if( getVisible() )
  724. {
  725. LLCoordWindow cursor_pos_window;
  726. LLCoordScreen cursor_pos_screen;
  727. LLCoordGL cursor_pos_gl;
  728. S32 x, y;
  729. getWindow()->getCursorPosition(&cursor_pos_window);
  730. getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl);
  731. if(mMediaControlsStack->getVisible())
  732. {
  733. mMediaControlsStack->screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &x, &y);
  734. LLView *hit_child = mMediaControlsStack->childFromPoint(x, y);
  735. if(hit_child && hit_child->getVisible())
  736. {
  737. // This was useful for debugging both coordinate translation and view hieararchy problems...
  738. // llinfos << "mouse coords: " << x << ", " << y << " hit child " << hit_child->getName() << llendl;
  739. // This will be a direct child of the LLLayoutStack, which should be a layout_panel.
  740. // These may not shown/hidden by the logic in updateShape(), so we need to do another hit test on the children of the layout panel,
  741. // which are the actual controls.
  742. hit_child->screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &x, &y);
  743. LLView *hit_child_2 = hit_child->childFromPoint(x, y);
  744. if(hit_child_2 && hit_child_2->getVisible())
  745. {
  746. // This was useful for debugging both coordinate translation and view hieararchy problems...
  747. // llinfos << " mouse coords: " << x << ", " << y << " hit child 2 " << hit_child_2->getName() << llendl;
  748. result = true;
  749. }
  750. }
  751. }
  752. }
  753. return result;
  754. }
  755. void LLPanelPrimMediaControls::onClickClose()
  756. {
  757. close();
  758. }
  759. void LLPanelPrimMediaControls::close()
  760. {
  761. resetZoomLevel(true);
  762. LLViewerMediaFocus::getInstance()->clearFocus();
  763. setVisible(FALSE);
  764. }
  765. void LLPanelPrimMediaControls::onClickBack()
  766. {
  767. focusOnTarget();
  768. LLViewerMediaImpl* impl =getTargetMediaImpl();
  769. if (impl)
  770. {
  771. impl->navigateBack();
  772. }
  773. }
  774. void LLPanelPrimMediaControls::onClickForward()
  775. {
  776. focusOnTarget();
  777. LLViewerMediaImpl* impl = getTargetMediaImpl();
  778. if (impl)
  779. {
  780. impl->navigateForward();
  781. }
  782. }
  783. void LLPanelPrimMediaControls::onClickHome()
  784. {
  785. focusOnTarget();
  786. LLViewerMediaImpl* impl = getTargetMediaImpl();
  787. if(impl)
  788. {
  789. impl->navigateHome();
  790. }
  791. }
  792. void LLPanelPrimMediaControls::onClickOpen()
  793. {
  794. LLViewerMediaImpl* impl = getTargetMediaImpl();
  795. if(impl)
  796. {
  797. LLWeb::loadURL(impl->getCurrentMediaURL());
  798. }
  799. }
  800. void LLPanelPrimMediaControls::onClickReload()
  801. {
  802. focusOnTarget();
  803. //LLViewerMedia::navigateHome();
  804. LLViewerMediaImpl* impl = getTargetMediaImpl();
  805. if(impl)
  806. {
  807. impl->navigateReload();
  808. }
  809. }
  810. void LLPanelPrimMediaControls::onClickPlay()
  811. {
  812. focusOnTarget();
  813. LLViewerMediaImpl* impl = getTargetMediaImpl();
  814. if(impl)
  815. {
  816. impl->play();
  817. }
  818. }
  819. void LLPanelPrimMediaControls::onClickPause()
  820. {
  821. focusOnTarget();
  822. LLViewerMediaImpl* impl = getTargetMediaImpl();
  823. if(impl)
  824. {
  825. impl->pause();
  826. }
  827. }
  828. void LLPanelPrimMediaControls::onClickStop()
  829. {
  830. focusOnTarget();
  831. LLViewerMediaImpl* impl = getTargetMediaImpl();
  832. if(impl)
  833. {
  834. impl->navigateStop();
  835. }
  836. }
  837. void LLPanelPrimMediaControls::onClickMediaStop()
  838. {
  839. focusOnTarget();
  840. LLViewerMediaImpl* impl = getTargetMediaImpl();
  841. if(impl)
  842. {
  843. impl->stop();
  844. }
  845. }
  846. void LLPanelPrimMediaControls::onClickSkipBack()
  847. {
  848. focusOnTarget();
  849. LLViewerMediaImpl* impl =getTargetMediaImpl();
  850. if (impl)
  851. {
  852. impl->skipBack(mSkipStep);
  853. }
  854. }
  855. void LLPanelPrimMediaControls::onClickSkipForward()
  856. {
  857. focusOnTarget();
  858. LLViewerMediaImpl* impl = getTargetMediaImpl();
  859. if (impl)
  860. {
  861. impl->skipForward(mSkipStep);
  862. }
  863. }
  864. void LLPanelPrimMediaControls::onClickZoom()
  865. {
  866. focusOnTarget();
  867. if(mCurrentZoom == ZOOM_NONE)
  868. {
  869. nextZoomLevel();
  870. }
  871. }
  872. void LLPanelPrimMediaControls::nextZoomLevel()
  873. {
  874. LLViewerObject* objectp = getTargetObject();
  875. if(objectp && objectp->isHUDAttachment())
  876. {
  877. // Never allow zooming on HUD attachments.
  878. return;
  879. }
  880. int index = 0;
  881. while (index < kNumZoomLevels)
  882. {
  883. if (kZoomLevels[index] == mCurrentZoom)
  884. {
  885. index++;
  886. break;
  887. }
  888. index++;
  889. }
  890. mCurrentZoom = kZoomLevels[index % kNumZoomLevels];
  891. updateZoom();
  892. }
  893. void LLPanelPrimMediaControls::resetZoomLevel(bool reset_camera)
  894. {
  895. if(mCurrentZoom != ZOOM_NONE)
  896. {
  897. mCurrentZoom = ZOOM_NONE;
  898. if(reset_camera)
  899. {
  900. updateZoom();
  901. }
  902. }
  903. }
  904. void LLPanelPrimMediaControls::updateZoom()
  905. {
  906. F32 zoom_padding = 0.0f;
  907. switch (mCurrentZoom)
  908. {
  909. case ZOOM_NONE:
  910. {
  911. gAgentCamera.setFocusOnAvatar(TRUE, ANIMATE);
  912. break;
  913. }
  914. case ZOOM_FAR:
  915. {
  916. zoom_padding = mZoomFarPadding;
  917. break;
  918. }
  919. case ZOOM_MEDIUM:
  920. {
  921. zoom_padding = mZoomMediumPadding;
  922. break;
  923. }
  924. case ZOOM_NEAR:
  925. {
  926. zoom_padding = mZoomNearPadding;
  927. break;
  928. }
  929. default:
  930. {
  931. gAgentCamera.setFocusOnAvatar(TRUE, ANIMATE);
  932. break;
  933. }
  934. }
  935. if (zoom_padding > 0.0f)
  936. {
  937. // since we only zoom into medium for now, always set zoom_in constraint to true
  938. LLViewerMediaFocus::setCameraZoom(getTargetObject(), mTargetObjectNormal, zoom_padding, true);
  939. }
  940. // Remember the object ID/face we zoomed into, so we can update the zoom icon appropriately
  941. mZoomObjectID = mTargetObjectID;
  942. mZoomObjectFace = mTargetObjectFace;
  943. }
  944. void LLPanelPrimMediaControls::onScrollUp(void* user_data)
  945. {
  946. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  947. this_panel->focusOnTarget();
  948. LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
  949. if(impl)
  950. {
  951. impl->scrollWheel(0, -1, MASK_NONE);
  952. }
  953. }
  954. void LLPanelPrimMediaControls::onScrollUpHeld(void* user_data)
  955. {
  956. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  957. this_panel->mScrollState = SCROLL_UP;
  958. }
  959. void LLPanelPrimMediaControls::onScrollRight(void* user_data)
  960. {
  961. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  962. this_panel->focusOnTarget();
  963. LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
  964. if(impl)
  965. {
  966. impl->scrollWheel(-1, 0, MASK_NONE);
  967. // impl->handleKeyHere(KEY_RIGHT, MASK_NONE);
  968. }
  969. }
  970. void LLPanelPrimMediaControls::onScrollRightHeld(void* user_data)
  971. {
  972. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  973. this_panel->mScrollState = SCROLL_RIGHT;
  974. }
  975. void LLPanelPrimMediaControls::onScrollLeft(void* user_data)
  976. {
  977. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  978. this_panel->focusOnTarget();
  979. LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
  980. if(impl)
  981. {
  982. impl->scrollWheel(1, 0, MASK_NONE);
  983. // impl->handleKeyHere(KEY_LEFT, MASK_NONE);
  984. }
  985. }
  986. void LLPanelPrimMediaControls::onScrollLeftHeld(void* user_data)
  987. {
  988. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  989. this_panel->mScrollState = SCROLL_LEFT;
  990. }
  991. void LLPanelPrimMediaControls::onScrollDown(void* user_data)
  992. {
  993. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  994. this_panel->focusOnTarget();
  995. LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
  996. if(impl)
  997. {
  998. impl->scrollWheel(0, 1, MASK_NONE);
  999. }
  1000. }
  1001. void LLPanelPrimMediaControls::onScrollDownHeld(void* user_data)
  1002. {
  1003. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  1004. this_panel->mScrollState = SCROLL_DOWN;
  1005. }
  1006. void LLPanelPrimMediaControls::onScrollStop(void* user_data)
  1007. {
  1008. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
  1009. this_panel->mScrollState = SCROLL_NONE;
  1010. }
  1011. void LLPanelPrimMediaControls::onCommitURL()
  1012. {
  1013. focusOnTarget();
  1014. std::string url = mMediaAddress->getValue().asString();
  1015. if(getTargetMediaImpl() && !url.empty())
  1016. {
  1017. getTargetMediaImpl()->navigateTo( url, "", true);
  1018. // Make sure keyboard focus is set to the media focus object.
  1019. gFocusMgr.setKeyboardFocus(LLViewerMediaFocus::getInstance());
  1020. }
  1021. mPauseFadeout = false;
  1022. mFadeTimer.start();
  1023. }
  1024. void LLPanelPrimMediaControls::onInputURL(LLFocusableElement* caller, void *userdata)
  1025. {
  1026. LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (userdata);
  1027. this_panel->focusOnTarget();
  1028. this_panel->mPauseFadeout = true;
  1029. this_panel->mFadeTimer.stop();
  1030. this_panel->mFadeTimer.reset();
  1031. }
  1032. void LLPanelPrimMediaControls::setCurrentURL()
  1033. {
  1034. #ifdef USE_COMBO_BOX_FOR_MEDIA_URL
  1035. // LLComboBox* media_address_combo = getChild<LLComboBox>("media_address_combo");
  1036. // // redirects will navigate momentarily to about:blank, don't add to history
  1037. // if (media_address_combo && mCurrentURL != "about:blank")
  1038. // {
  1039. // media_address_combo->remove(mCurrentURL);
  1040. // media_address_combo->add(mCurrentURL);
  1041. // media_address_combo->selectByValue(mCurrentURL);
  1042. // }
  1043. #else // USE_COMBO_BOX_FOR_MEDIA_URL
  1044. if (mMediaAddress && mCurrentURL != "about:blank")
  1045. {
  1046. mMediaAddress->setValue(mCurrentURL);
  1047. }
  1048. #endif // USE_COMBO_BOX_FOR_MEDIA_URL
  1049. }
  1050. void LLPanelPrimMediaControls::onCommitSlider()
  1051. {
  1052. focusOnTarget();
  1053. LLViewerMediaImpl* media_impl = getTargetMediaImpl();
  1054. if (media_impl)
  1055. {
  1056. // get slider value
  1057. F64 slider_value = mMediaPlaySliderCtrl->getValue().asReal();
  1058. if(slider_value <= 0.0)
  1059. {
  1060. media_impl->stop();
  1061. }
  1062. else
  1063. {
  1064. media_impl->seek(slider_value*mMovieDuration);
  1065. //mUpdateSlider= false;
  1066. }
  1067. }
  1068. }
  1069. void LLPanelPrimMediaControls::onCommitVolumeUp()
  1070. {
  1071. focusOnTarget();
  1072. LLViewerMediaImpl* media_impl = getTargetMediaImpl();
  1073. if (media_impl)
  1074. {
  1075. F32 volume = media_impl->getVolume();
  1076. volume += 0.1f;
  1077. if(volume >= 1.0f)
  1078. {
  1079. volume = 1.0f;
  1080. }
  1081. media_impl->setVolume(volume);
  1082. mMuteBtn->setToggleState(false);
  1083. }
  1084. }
  1085. void LLPanelPrimMediaControls::onCommitVolumeDown()
  1086. {
  1087. focusOnTarget();
  1088. LLViewerMediaImpl* media_impl = getTargetMediaImpl();
  1089. if (media_impl)
  1090. {
  1091. F32 volume = media_impl->getVolume();
  1092. volume -= 0.1f;
  1093. if(volume <= 0.0f)
  1094. {
  1095. volume = 0.0f;
  1096. }
  1097. media_impl->setVolume(volume);
  1098. mMuteBtn->setToggleState(false);
  1099. }
  1100. }
  1101. void LLPanelPrimMediaControls::onCommitVolumeSlider()
  1102. {
  1103. focusOnTarget();
  1104. LLViewerMediaImpl* media_impl = getTargetMediaImpl();
  1105. if (media_impl)
  1106. {
  1107. media_impl->setVolume(mVolumeSliderCtrl->getValueF32());
  1108. }
  1109. }
  1110. void LLPanelPrimMediaControls::onToggleMute()
  1111. {
  1112. focusOnTarget();
  1113. LLViewerMediaImpl* media_impl = getTargetMediaImpl();
  1114. if (media_impl)
  1115. {
  1116. F32 volume = media_impl->getVolume();
  1117. if(volume > 0.0)
  1118. {
  1119. media_impl->setVolume(0.0);
  1120. }
  1121. else if (mVolumeSliderCtrl->getValueF32() == 0.0)
  1122. {
  1123. media_impl->setVolume(1.0);
  1124. mVolumeSliderCtrl->setValue(1.0);
  1125. }
  1126. else
  1127. {
  1128. media_impl->setVolume(mVolumeSliderCtrl->getValueF32());
  1129. }
  1130. }
  1131. }
  1132. void LLPanelPrimMediaControls::showVolumeSlider()
  1133. {
  1134. mVolumeSliderVisible++;
  1135. }
  1136. void LLPanelPrimMediaControls::hideVolumeSlider()
  1137. {
  1138. mVolumeSliderVisible--;
  1139. }
  1140. bool LLPanelPrimMediaControls::shouldVolumeSliderBeVisible()
  1141. {
  1142. return mVolumeSliderVisible > 0;
  1143. }
  1144. void LLPanelPrimMediaControls::clearFaceOnFade()
  1145. {
  1146. if(mClearFaceOnFade)
  1147. {
  1148. // Hiding this object makes scroll events go missing after it fades out
  1149. // (see DEV-41755 for a full description of the train wreck).
  1150. // Only hide the controls when we're untargeting.
  1151. setVisible(FALSE);
  1152. mClearFaceOnFade = false;
  1153. mVolumeSliderVisible = 0;
  1154. mTargetImplID = LLUUID::null;
  1155. mTargetObjectID = LLUUID::null;
  1156. mTargetObjectFace = 0;
  1157. }
  1158. }
  1159. void LLPanelPrimMediaControls::onMouselookModeIn()
  1160. {
  1161. LLViewerMediaFocus::getInstance()->clearHover();
  1162. mHideImmediately = true;
  1163. }
  1164. void LLPanelPrimMediaControls::showNotification(LLNotificationPtr notify)
  1165. {
  1166. delete mWindowShade;
  1167. LLWindowShade::Params params;
  1168. params.rect = mMediaRegion->getLocalRect();
  1169. params.follows.flags = FOLLOWS_ALL;
  1170. //HACK: don't hardcode this
  1171. if (notify->getIcon() == "Popup_Caution")
  1172. {
  1173. params.bg_image.name = "Yellow_Gradient";
  1174. params.text_color = LLColor4::black;
  1175. }
  1176. else
  1177. {
  1178. //HACK: make this a property of the notification itself, "cancellable"
  1179. params.can_close = false;
  1180. params.text_color.control = "LabelTextColor";
  1181. }
  1182. mWindowShade = LLUICtrlFactory::create<LLWindowShade>(params);
  1183. mMediaRegion->addChild(mWindowShade);
  1184. mWindowShade->show(notify);
  1185. }
  1186. void LLPanelPrimMediaControls::hideNotification()
  1187. {
  1188. if (mWindowShade)
  1189. {
  1190. mWindowShade->hide();
  1191. }
  1192. }