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