lloverlaybar.cpp

Go to the documentation of this file.
00001 
00032 // Temporary buttons that appear at the bottom of the screen when you
00033 // are in a mode.
00034 
00035 #include "llviewerprecompiledheaders.h"
00036 
00037 #include "lloverlaybar.h"
00038 
00039 #include "audioengine.h"
00040 #include "llglimmediate.h"
00041 #include "llagent.h"
00042 #include "llbutton.h"
00043 #include "llchatbar.h"
00044 #include "llfocusmgr.h"
00045 #include "llimview.h"
00046 #include "llmediaremotectrl.h"
00047 #include "llpanelaudiovolume.h"
00048 #include "llparcel.h"
00049 #include "lltextbox.h"
00050 #include "llui.h"
00051 #include "llviewercontrol.h"
00052 #include "llviewerimagelist.h"
00053 #include "llviewermedia.h"
00054 #include "llviewermenu.h"       // handle_reset_view()
00055 #include "llviewermedia.h"
00056 #include "llviewerparcelmedia.h"
00057 #include "llviewerparcelmgr.h"
00058 #include "lluictrlfactory.h"
00059 #include "llviewerwindow.h"
00060 #include "llvoiceclient.h"
00061 #include "llvoavatar.h"
00062 #include "llvoiceremotectrl.h"
00063 #include "llwebbrowserctrl.h"
00064 #include "llselectmgr.h"
00065 
00066 //
00067 // Globals
00068 //
00069 
00070 LLOverlayBar *gOverlayBar = NULL;
00071 
00072 extern S32 MENU_BAR_HEIGHT;
00073 
00074 //
00075 // Functions
00076 //
00077 
00078 
00079 
00080 void* LLOverlayBar::createMediaRemote(void* userdata)
00081 {
00082         LLOverlayBar *self = (LLOverlayBar*)userdata;   
00083         self->mMediaRemote =  new LLMediaRemoteCtrl ();
00084         return self->mMediaRemote;
00085 }
00086 
00087 void* LLOverlayBar::createVoiceRemote(void* userdata)
00088 {
00089         LLOverlayBar *self = (LLOverlayBar*)userdata;   
00090         self->mVoiceRemote = new LLVoiceRemoteCtrl("voice_remote");
00091         return self->mVoiceRemote;
00092 }
00093 
00094 void* LLOverlayBar::createChatBar(void* userdata)
00095 {
00096         gChatBar = new LLChatBar();
00097         return gChatBar;
00098 }
00099 
00100 LLOverlayBar::LLOverlayBar()
00101         :       LLPanel(),
00102                 mMediaRemote(NULL),
00103                 mVoiceRemote(NULL),
00104                 mMusicState(STOPPED)
00105 {
00106         setMouseOpaque(FALSE);
00107         setIsChrome(TRUE);
00108 
00109         mBuilt = false;
00110 
00111         LLCallbackMap::map_t factory_map;
00112         factory_map["media_remote"] = LLCallbackMap(LLOverlayBar::createMediaRemote, this);
00113         factory_map["voice_remote"] = LLCallbackMap(LLOverlayBar::createVoiceRemote, this);
00114         factory_map["chat_bar"] = LLCallbackMap(LLOverlayBar::createChatBar, this);
00115         
00116         LLUICtrlFactory::getInstance()->buildPanel(this, "panel_overlaybar.xml", &factory_map);
00117 }
00118 
00119 BOOL LLOverlayBar::postBuild()
00120 {
00121         childSetAction("IM Received",onClickIMReceived,this);
00122         childSetAction("Set Not Busy",onClickSetNotBusy,this);
00123         childSetAction("Release Keys",onClickReleaseKeys,this);
00124         childSetAction("Mouselook",onClickMouselook,this);
00125         childSetAction("Stand Up",onClickStandUp,this);
00126         childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible"));
00127 
00128         setFocusRoot(TRUE);
00129         mBuilt = true;
00130 
00131         layoutButtons();
00132         return TRUE;
00133 }
00134 
00135 LLOverlayBar::~LLOverlayBar()
00136 {
00137         // LLView destructor cleans up children
00138 }
00139 
00140 // virtual
00141 void LLOverlayBar::reshape(S32 width, S32 height, BOOL called_from_parent)
00142 {
00143         LLView::reshape(width, height, called_from_parent);
00144 
00145         if (mBuilt) 
00146         {
00147                 layoutButtons();
00148         }
00149 }
00150 
00151 void LLOverlayBar::layoutButtons()
00152 {
00153         LLView* state_buttons_panel = getChildView("state_buttons");
00154 
00155         if (state_buttons_panel->getVisible())
00156         {
00157                 LLViewQuery query;
00158                 LLWidgetTypeFilter<LLButton> widget_filter;
00159                 query.addPreFilter(LLEnabledFilter::getInstance());
00160                 query.addPreFilter(&widget_filter);
00161 
00162                 child_list_t button_list = query(state_buttons_panel);
00163 
00164                 const S32 MAX_BAR_WIDTH = 600;
00165                 S32 bar_width = llclamp(state_buttons_panel->getRect().getWidth(), 0, MAX_BAR_WIDTH);
00166 
00167                 // calculate button widths
00168                 const S32 MAX_BUTTON_WIDTH = 150;
00169                 S32 segment_width = llclamp(lltrunc((F32)(bar_width) / (F32)button_list.size()), 0, MAX_BUTTON_WIDTH);
00170                 S32 btn_width = segment_width - gSavedSettings.getS32("StatusBarPad");
00171 
00172                 // Evenly space all buttons, starting from left
00173                 S32 left = 0;
00174                 S32 bottom = 1;
00175 
00176                 for (child_list_reverse_iter_t child_iter = button_list.rbegin();
00177                         child_iter != button_list.rend(); ++child_iter)
00178                 {
00179                         LLView *view = *child_iter;
00180                         LLRect r = view->getRect();
00181                         r.setOriginAndSize(left, bottom, btn_width, r.getHeight());
00182                         view->setRect(r);
00183                         left += segment_width;
00184                 }
00185         }
00186 }
00187 
00188 // Per-frame updates of visibility
00189 void LLOverlayBar::refresh()
00190 {
00191         BOOL buttons_changed = FALSE;
00192 
00193         BOOL im_received = gIMMgr->getIMReceived();
00194         LLButton* button = getChild<LLButton>("IM Received");
00195         if (button && button->getVisible() != im_received)
00196         {
00197                 button->setVisible(im_received);
00198                 sendChildToFront(button);
00199                 moveChildToBackOfTabGroup(button);
00200                 buttons_changed = TRUE;
00201         }
00202 
00203         BOOL busy = gAgent.getBusy();
00204         button = getChild<LLButton>("Set Not Busy");
00205         if (button && button->getVisible() != busy)
00206         {
00207                 button->setVisible(busy);
00208                 sendChildToFront(button);
00209                 moveChildToBackOfTabGroup(button);
00210                 buttons_changed = TRUE;
00211         }
00212 
00213         BOOL controls_grabbed = gAgent.anyControlGrabbed();
00214         button = getChild<LLButton>("Release Keys");
00215 
00216         if (button && button->getVisible() != controls_grabbed)
00217         {
00218                 button->setVisible(controls_grabbed);
00219                 sendChildToFront(button);
00220                 moveChildToBackOfTabGroup(button);
00221                 buttons_changed = TRUE;
00222         }
00223 
00224         BOOL mouselook_grabbed;
00225         mouselook_grabbed = gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_DOWN_INDEX)
00226                 || gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_UP_INDEX);
00227         button = getChild<LLButton>("Mouselook");
00228 
00229         if (button && button->getVisible() != mouselook_grabbed)
00230         {
00231                 button->setVisible(mouselook_grabbed);
00232                 sendChildToFront(button);
00233                 moveChildToBackOfTabGroup(button);
00234                 buttons_changed = TRUE;
00235         }
00236 
00237         BOOL sitting = FALSE;
00238         if (gAgent.getAvatarObject())
00239         {
00240                 sitting = gAgent.getAvatarObject()->mIsSitting;
00241         }
00242         button = getChild<LLButton>("Stand Up");
00243 
00244         if (button && button->getVisible() != sitting)
00245         {
00246                 button->setVisible(sitting);
00247                 sendChildToFront(button);
00248                 moveChildToBackOfTabGroup(button);
00249                 buttons_changed = TRUE;
00250         }
00251 
00252 
00253         moveChildToBackOfTabGroup(mMediaRemote);
00254         moveChildToBackOfTabGroup(mVoiceRemote);
00255 
00256         // turn off the whole bar in mouselook
00257         if (gAgent.cameraMouselook())
00258         {
00259                 childSetVisible("media_remote_container", FALSE);
00260                 childSetVisible("voice_remote_container", FALSE);
00261                 childSetVisible("state_buttons", FALSE);
00262         }
00263         else
00264         {
00265                 // update "remotes"
00266                 childSetVisible("media_remote_container", TRUE);
00267                 childSetVisible("voice_remote_container", LLVoiceClient::voiceEnabled());
00268                 childSetVisible("state_buttons", TRUE);
00269         }
00270 
00271         // always let user toggle into and out of chatbar
00272         childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible"));
00273 
00274         if (buttons_changed)
00275         {
00276                 layoutButtons();
00277         }
00278 }
00279 
00280 //-----------------------------------------------------------------------
00281 // Static functions
00282 //-----------------------------------------------------------------------
00283 
00284 // static
00285 void LLOverlayBar::onClickIMReceived(void*)
00286 {
00287         gIMMgr->setFloaterOpen(TRUE);
00288 }
00289 
00290 
00291 // static
00292 void LLOverlayBar::onClickSetNotBusy(void*)
00293 {
00294         gAgent.clearBusy();
00295 }
00296 
00297 
00298 // static
00299 void LLOverlayBar::onClickReleaseKeys(void*)
00300 {
00301         gAgent.forceReleaseControls();
00302 }
00303 
00304 // static
00305 void LLOverlayBar::onClickResetView(void* data)
00306 {
00307         handle_reset_view();
00308 }
00309 
00310 //static
00311 void LLOverlayBar::onClickMouselook(void*)
00312 {
00313         gAgent.changeCameraToMouselook();
00314 }
00315 
00316 //static
00317 void LLOverlayBar::onClickStandUp(void*)
00318 {
00319         LLSelectMgr::getInstance()->deselectAllForStandingUp();
00320         gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
00321 }
00322 
00324 // static media helpers
00325 // *TODO: Move this into an audio manager abstraction
00326 //static
00327 void LLOverlayBar::mediaStop(void*)
00328 {
00329         if (!gOverlayBar)
00330         {
00331                 return;
00332         }
00333         LLViewerParcelMedia::stop();
00334 }
00335 //static
00336 void LLOverlayBar::toggleMediaPlay(void*)
00337 {
00338         if (!gOverlayBar)
00339         {
00340                 return;
00341         }
00342 
00343         
00344         if (LLViewerMedia::isMediaPaused())
00345         {
00346                 LLViewerParcelMedia::start();
00347         }
00348         else if(LLViewerMedia::isMediaPlaying())
00349         {
00350                 LLViewerParcelMedia::pause();
00351         }
00352         else
00353         {
00354                 LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
00355                 if (parcel)
00356                 {
00357                         LLViewerParcelMedia::play(parcel);
00358                 }
00359         }
00360 }
00361 
00362 //static
00363 void LLOverlayBar::toggleMusicPlay(void*)
00364 {
00365         if (!gOverlayBar)
00366         {
00367                 return;
00368         }
00369         
00370         if (gOverlayBar->mMusicState != PLAYING)
00371         {
00372                 gOverlayBar->mMusicState = PLAYING; // desired state
00373                 if (gAudiop)
00374                 {
00375                         LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
00376                         if ( parcel )
00377                         {
00378                                 // this doesn't work properly when crossing parcel boundaries - even when the 
00379                                 // stream is stopped, it doesn't return the right thing - commenting out for now.
00380         //                      if ( gAudiop->isInternetStreamPlaying() == 0 )
00381                                 {
00382                                         gAudiop->startInternetStream(parcel->getMusicURL().c_str());
00383                                 }
00384                         }
00385                 }
00386         }
00387         //else
00388         //{
00389         //      gOverlayBar->mMusicState = PAUSED; // desired state
00390         //      if (gAudiop)
00391         //      {
00392         //              gAudiop->pauseInternetStream(1);
00393         //      }
00394         //}
00395         else
00396         {
00397                 gOverlayBar->mMusicState = STOPPED; // desired state
00398                 if (gAudiop)
00399                 {
00400                         gAudiop->stopInternetStream();
00401                 }
00402         }
00403 }
00404 

Generated on Fri May 16 08:33:48 2008 for SecondLife by  doxygen 1.5.5