PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lloverlaybar.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 378 lines | 255 code | 55 blank | 68 comment | 36 complexity | b28699902fceaaed0aa723992a780e1d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lloverlaybar.cpp
  3. * @brief LLOverlayBar class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&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. // Temporary buttons that appear at the bottom of the screen when you
  27. // are in a mode.
  28. #include "llviewerprecompiledheaders.h"
  29. #include "lloverlaybar.h"
  30. #include "llaudioengine.h"
  31. #include "llrender.h"
  32. #include "llagent.h"
  33. #include "llbutton.h"
  34. #include "llfocusmgr.h"
  35. #include "llimview.h"
  36. #include "llmediaremotectrl.h"
  37. #include "llparcel.h"
  38. #include "lltextbox.h"
  39. #include "llui.h"
  40. #include "llviewercontrol.h"
  41. #include "llviewertexturelist.h"
  42. #include "llviewerjoystick.h"
  43. #include "llviewermedia.h"
  44. #include "llviewermenu.h" // handle_reset_view()
  45. #include "llviewermedia.h"
  46. #include "llviewerparcelmedia.h"
  47. #include "llviewerparcelmgr.h"
  48. #include "lluictrlfactory.h"
  49. #include "llviewerwindow.h"
  50. #include "llvoiceclient.h"
  51. #include "llvoavatarself.h"
  52. #include "llvoiceremotectrl.h"
  53. #include "llmediactrl.h"
  54. #include "llselectmgr.h"
  55. //
  56. // Globals
  57. //
  58. LLOverlayBar *gOverlayBar = NULL;
  59. extern S32 MENU_BAR_HEIGHT;
  60. //
  61. // Functions
  62. //
  63. void* LLOverlayBar::createMediaRemote(void* userdata)
  64. {
  65. LLOverlayBar *self = (LLOverlayBar*)userdata;
  66. self->mMediaRemote = new LLMediaRemoteCtrl ();
  67. return self->mMediaRemote;
  68. }
  69. void* LLOverlayBar::createVoiceRemote(void* userdata)
  70. {
  71. LLOverlayBar *self = (LLOverlayBar*)userdata;
  72. self->mVoiceRemote = new LLVoiceRemoteCtrl();
  73. return self->mVoiceRemote;
  74. }
  75. LLOverlayBar::LLOverlayBar()
  76. : LLPanel(),
  77. mMediaRemote(NULL),
  78. mVoiceRemote(NULL),
  79. mMusicState(STOPPED)
  80. {
  81. setMouseOpaque(FALSE);
  82. setIsChrome(TRUE);
  83. mBuilt = false;
  84. mFactoryMap["media_remote"] = LLCallbackMap(LLOverlayBar::createMediaRemote, this);
  85. mFactoryMap["voice_remote"] = LLCallbackMap(LLOverlayBar::createVoiceRemote, this);
  86. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_overlaybar.xml");
  87. }
  88. BOOL LLOverlayBar::postBuild()
  89. {
  90. childSetAction("Set Not Busy",onClickSetNotBusy,this);
  91. childSetAction("Mouselook",onClickMouselook,this);
  92. childSetAction("Stand Up",onClickStandUp,this);
  93. childSetAction("Flycam",onClickFlycam,this);
  94. childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible"));
  95. mVoiceRemote->expandOrCollapse();
  96. mMediaRemote->expandOrCollapse();
  97. setFocusRoot(TRUE);
  98. mBuilt = true;
  99. layoutButtons();
  100. return TRUE;
  101. }
  102. LLOverlayBar::~LLOverlayBar()
  103. {
  104. // LLView destructor cleans up children
  105. }
  106. // virtual
  107. void LLOverlayBar::reshape(S32 width, S32 height, BOOL called_from_parent)
  108. {
  109. LLView::reshape(width, height, called_from_parent);
  110. if (mBuilt)
  111. {
  112. layoutButtons();
  113. }
  114. }
  115. void LLOverlayBar::layoutButtons()
  116. {
  117. LLView* state_buttons_panel = getChildView("state_buttons");
  118. if (state_buttons_panel->getVisible())
  119. {
  120. LLViewQuery query;
  121. LLWidgetTypeFilter<LLButton> widget_filter;
  122. query.addPreFilter(LLEnabledFilter::getInstance());
  123. query.addPreFilter(&widget_filter);
  124. child_list_t button_list = query(state_buttons_panel);
  125. const S32 MAX_BAR_WIDTH = 600;
  126. S32 bar_width = llclamp(state_buttons_panel->getRect().getWidth(), 0, MAX_BAR_WIDTH);
  127. // calculate button widths
  128. const S32 MAX_BUTTON_WIDTH = 150;
  129. const S32 STATUS_BAR_PAD = 10;
  130. S32 segment_width = llclamp(lltrunc((F32)(bar_width) / (F32)button_list.size()), 0, MAX_BUTTON_WIDTH);
  131. S32 btn_width = segment_width - STATUS_BAR_PAD;
  132. // Evenly space all buttons, starting from left
  133. S32 left = 0;
  134. S32 bottom = 1;
  135. for (child_list_reverse_iter_t child_iter = button_list.rbegin();
  136. child_iter != button_list.rend(); ++child_iter)
  137. {
  138. LLView *view = *child_iter;
  139. LLRect r = view->getRect();
  140. r.setOriginAndSize(left, bottom, btn_width, r.getHeight());
  141. view->setRect(r);
  142. left += segment_width;
  143. }
  144. }
  145. }
  146. // Per-frame updates of visibility
  147. void LLOverlayBar::refresh()
  148. {
  149. BOOL buttons_changed = FALSE;
  150. BOOL im_received = gIMMgr->getIMReceived();
  151. LLButton* button = getChild<LLButton>("IM Received");
  152. if (button && button->getVisible() != im_received)
  153. {
  154. button->setVisible(im_received);
  155. sendChildToFront(button);
  156. moveChildToBackOfTabGroup(button);
  157. buttons_changed = TRUE;
  158. }
  159. BOOL busy = gAgent.getBusy();
  160. button = getChild<LLButton>("Set Not Busy");
  161. if (button && button->getVisible() != busy)
  162. {
  163. button->setVisible(busy);
  164. sendChildToFront(button);
  165. moveChildToBackOfTabGroup(button);
  166. buttons_changed = TRUE;
  167. }
  168. BOOL flycam = LLViewerJoystick::getInstance()->getOverrideCamera();
  169. button = getChild<LLButton>("Flycam");
  170. if (button && button->getVisible() != flycam)
  171. {
  172. button->setVisible(flycam);
  173. sendChildToFront(button);
  174. moveChildToBackOfTabGroup(button);
  175. buttons_changed = TRUE;
  176. }
  177. BOOL mouselook_grabbed;
  178. mouselook_grabbed = gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_DOWN_INDEX)
  179. || gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_UP_INDEX);
  180. button = getChild<LLButton>("Mouselook");
  181. if (button && button->getVisible() != mouselook_grabbed)
  182. {
  183. button->setVisible(mouselook_grabbed);
  184. sendChildToFront(button);
  185. moveChildToBackOfTabGroup(button);
  186. buttons_changed = TRUE;
  187. }
  188. BOOL sitting = FALSE;
  189. if (gAgent.getAvatarObject())
  190. {
  191. sitting = gAgent.getAvatarObject()->isSitting();
  192. }
  193. button = getChild<LLButton>("Stand Up");
  194. if (button && button->getVisible() != sitting)
  195. {
  196. button->setVisible(sitting);
  197. sendChildToFront(button);
  198. moveChildToBackOfTabGroup(button);
  199. buttons_changed = TRUE;
  200. }
  201. moveChildToBackOfTabGroup(mMediaRemote);
  202. moveChildToBackOfTabGroup(mVoiceRemote);
  203. // turn off the whole bar in mouselook
  204. if (gAgent.cameraMouselook())
  205. {
  206. childSetVisible("media_remote_container", FALSE);
  207. childSetVisible("voice_remote_container", FALSE);
  208. childSetVisible("state_buttons", FALSE);
  209. }
  210. else
  211. {
  212. // update "remotes"
  213. childSetVisible("media_remote_container", TRUE);
  214. childSetVisible("voice_remote_container", LLVoiceClient::getInstance()->voiceEnabled());
  215. childSetVisible("state_buttons", TRUE);
  216. }
  217. // always let user toggle into and out of chatbar
  218. childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible"));
  219. if (buttons_changed)
  220. {
  221. layoutButtons();
  222. }
  223. }
  224. //-----------------------------------------------------------------------
  225. // Static functions
  226. //-----------------------------------------------------------------------
  227. // static
  228. void LLOverlayBar::onClickSetNotBusy(void*)
  229. {
  230. gAgent.clearBusy();
  231. }
  232. // static
  233. void LLOverlayBar::onClickFlycam(void*)
  234. {
  235. LLViewerJoystick::getInstance()->toggleFlycam();
  236. }
  237. // static
  238. void LLOverlayBar::onClickResetView(void* data)
  239. {
  240. handle_reset_view();
  241. }
  242. //static
  243. void LLOverlayBar::onClickMouselook(void*)
  244. {
  245. gAgent.changeCameraToMouselook();
  246. }
  247. //static
  248. void LLOverlayBar::onClickStandUp(void*)
  249. {
  250. LLSelectMgr::getInstance()->deselectAllForStandingUp();
  251. gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
  252. }
  253. ////////////////////////////////////////////////////////////////////////////////
  254. // static media helpers
  255. // *TODO: Move this into an audio manager abstraction
  256. //static
  257. void LLOverlayBar::mediaStop(void*)
  258. {
  259. if (!gOverlayBar)
  260. {
  261. // return;
  262. }
  263. LLViewerParcelMedia::stop();
  264. }
  265. //static
  266. void LLOverlayBar::toggleMediaPlay(void*)
  267. {
  268. if (!gOverlayBar)
  269. {
  270. // return;
  271. }
  272. if (LLViewerParcelMedia::getStatus() == LLViewerMediaImpl::MEDIA_PAUSED)
  273. {
  274. LLViewerParcelMedia::start();
  275. }
  276. else if(LLViewerParcelMedia::getStatus() == LLViewerMediaImpl::MEDIA_PLAYING)
  277. {
  278. LLViewerParcelMedia::pause();
  279. }
  280. else
  281. {
  282. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  283. if (parcel)
  284. {
  285. LLViewerParcelMedia::play(parcel);
  286. }
  287. }
  288. }
  289. //static
  290. void LLOverlayBar::toggleMusicPlay(void*)
  291. {
  292. if (gAudiop->isInternetStreamPlaying() != 1)
  293. {
  294. if (gAudiop)
  295. {
  296. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  297. if ( parcel )
  298. {
  299. // this doesn't work properly when crossing parcel boundaries - even when the
  300. // stream is stopped, it doesn't return the right thing - commenting out for now.
  301. // if ( gAudiop->isInternetStreamPlaying() == 0 )
  302. {
  303. gAudiop->startInternetStream(parcel->getMusicURL());
  304. }
  305. }
  306. }
  307. }
  308. //else
  309. //{
  310. // gOverlayBar->mMusicState = PAUSED; // desired state
  311. // if (gAudiop)
  312. // {
  313. // gAudiop->pauseInternetStream(1);
  314. // }
  315. //}
  316. else
  317. {
  318. if (gAudiop)
  319. {
  320. gAudiop->stopInternetStream();
  321. }
  322. }
  323. }