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 "llagent.h"
00041 #include "llbutton.h"
00042 #include "llfocusmgr.h"
00043 #include "llimview.h"
00044 #include "llmediaengine.h"
00045 #include "llmediaremotectrl.h"
00046 #include "llpanelaudiovolume.h"
00047 #include "llparcel.h"
00048 #include "lltextbox.h"
00049 #include "llui.h"
00050 #include "llviewercontrol.h"
00051 #include "llviewerimagelist.h"
00052 #include "llviewermenu.h"       // handle_reset_view()
00053 #include "llviewerparcelmgr.h"
00054 #include "llvieweruictrlfactory.h"
00055 #include "llviewerwindow.h"
00056 #include "llvoiceclient.h"
00057 #include "llvoavatar.h"
00058 #include "llvoiceremotectrl.h"
00059 #include "llwebbrowserctrl.h"
00060 #include "viewer.h"
00061 
00062 //
00063 // Globals
00064 //
00065 
00066 LLOverlayBar *gOverlayBar = NULL;
00067 
00068 extern S32 MENU_BAR_HEIGHT;
00069 
00070 //
00071 // Functions
00072 //
00073 
00074 
00075 //static
00076 void* LLOverlayBar::createMasterRemote(void* userdata)
00077 {
00078         LLOverlayBar *self = (LLOverlayBar*)userdata;   
00079         self->mMasterRemote =  new LLMediaRemoteCtrl ( "master_volume",
00080                                                                                                    "volume",
00081                                                                                                    LLRect(),
00082                                                                                                    "panel_master_volume.xml");
00083         return self->mMasterRemote;
00084 }
00085 
00086 void* LLOverlayBar::createMediaRemote(void* userdata)
00087 {
00088         LLOverlayBar *self = (LLOverlayBar*)userdata;   
00089         self->mMediaRemote =  new LLMediaRemoteCtrl ( "media_remote",
00090                                                                                                   "media",
00091                                                                                                   LLRect(),
00092                                                                                                   "panel_media_remote.xml");
00093         return self->mMediaRemote;
00094 }
00095 
00096 void* LLOverlayBar::createMusicRemote(void* userdata)
00097 {
00098         LLOverlayBar *self = (LLOverlayBar*)userdata;
00099         self->mMusicRemote =  new LLMediaRemoteCtrl ( "music_remote",
00100                                                                                                   "music",
00101                                                                                                   LLRect(),
00102                                                                                                   "panel_music_remote.xml" );           
00103         return self->mMusicRemote;
00104 }
00105 
00106 void* LLOverlayBar::createVoiceRemote(void* userdata)
00107 {
00108         LLOverlayBar *self = (LLOverlayBar*)userdata;   
00109         self->mVoiceRemote = new LLVoiceRemoteCtrl("voice_remote");
00110         return self->mVoiceRemote;
00111 }
00112 
00113 
00114 
00115 
00116 LLOverlayBar::LLOverlayBar(const std::string& name, const LLRect& rect)
00117         :       LLPanel(name, rect, FALSE),             // not bordered
00118                 mMasterRemote(NULL),
00119                 mMusicRemote(NULL),
00120                 mMediaRemote(NULL),
00121                 mVoiceRemote(NULL),
00122                 mMediaState(STOPPED),
00123                 mMusicState(STOPPED)
00124 {
00125         setMouseOpaque(FALSE);
00126         setIsChrome(TRUE);
00127 
00128         mBuilt = false;
00129 
00130         LLCallbackMap::map_t factory_map;
00131         factory_map["master_volume"] = LLCallbackMap(LLOverlayBar::createMasterRemote, this);
00132         factory_map["media_remote"] = LLCallbackMap(LLOverlayBar::createMediaRemote, this);
00133         factory_map["music_remote"] = LLCallbackMap(LLOverlayBar::createMusicRemote, this);
00134         factory_map["voice_remote"] = LLCallbackMap(LLOverlayBar::createVoiceRemote, this);
00135         
00136         gUICtrlFactory->buildPanel(this, "panel_overlaybar.xml", &factory_map);
00137         
00138         childSetAction("IM Received",onClickIMReceived,this);
00139         childSetAction("Set Not Busy",onClickSetNotBusy,this);
00140         childSetAction("Release Keys",onClickReleaseKeys,this);
00141         childSetAction("Mouselook",onClickMouselook,this);
00142         childSetAction("Stand Up",onClickStandUp,this);
00143 
00144         mIsFocusRoot = TRUE;
00145         mBuilt = true;
00146 
00147         // make overlay bar conform to window size
00148         setRect(rect);
00149         layoutButtons();
00150 }
00151 
00152 LLOverlayBar::~LLOverlayBar()
00153 {
00154         // LLView destructor cleans up children
00155 }
00156 
00157 EWidgetType LLOverlayBar::getWidgetType() const
00158 {
00159         return WIDGET_TYPE_OVERLAY_BAR;
00160 }
00161 
00162 LLString LLOverlayBar::getWidgetTag() const
00163 {
00164         return LL_OVERLAY_BAR_TAG;
00165 }
00166 
00167 // virtual
00168 void LLOverlayBar::reshape(S32 width, S32 height, BOOL called_from_parent)
00169 {
00170         LLView::reshape(width, height, called_from_parent);
00171 
00172         if (mBuilt) 
00173         {
00174                 layoutButtons();
00175         }
00176 }
00177 
00178 void LLOverlayBar::layoutButtons()
00179 {
00180         S32 width = mRect.getWidth();
00181         if (width > 1024) width = 1024;
00182 
00183         S32 count = getChildCount();
00184         const S32 PAD = gSavedSettings.getS32("StatusBarPad");
00185 
00186         const S32 num_media_controls = 3;
00187         S32 media_remote_width = mMediaRemote ? mMediaRemote->getRect().getWidth() : 0;
00188         S32 music_remote_width = mMusicRemote ? mMusicRemote->getRect().getWidth() : 0;
00189         S32 voice_remote_width = mVoiceRemote ? mVoiceRemote->getRect().getWidth() : 0;
00190         S32 master_remote_width = mMasterRemote ? mMasterRemote->getRect().getWidth() : 0;
00191 
00192         // total reserved width for all media remotes
00193         const S32 ENDPAD = 20;
00194         S32 remote_total_width = media_remote_width + PAD + music_remote_width + PAD + voice_remote_width + PAD + master_remote_width + ENDPAD;
00195 
00196         // calculate button widths
00197         F32 segment_width = (F32)(width - remote_total_width) / (F32)(count - num_media_controls);
00198 
00199         S32 btn_width = lltrunc(segment_width - PAD);
00200 
00201         // Evenly space all views
00202         LLRect r;
00203         S32 i = 0;
00204         for (child_list_const_iter_t child_iter = getChildList()->begin();
00205                  child_iter != getChildList()->end(); ++child_iter)
00206         {
00207                 LLView *view = *child_iter;
00208                 r = view->getRect();
00209                 r.mLeft = (width) - llround(remote_total_width + (i-num_media_controls+1)*segment_width);
00210                 r.mRight = r.mLeft + btn_width;
00211                 view->setRect(r);
00212                 i++;
00213         }
00214 
00215         // Fix up remotes to have constant width because they can't shrink
00216         S32 right = mRect.getWidth() - remote_total_width - PAD;
00217         if (mMediaRemote)
00218         {
00219                 r = mMediaRemote->getRect();
00220                 r.mLeft = right + PAD;
00221                 right = r.mLeft + media_remote_width;
00222                 r.mRight = right;
00223                 mMediaRemote->setRect(r);
00224         }
00225         if (mMusicRemote)
00226         {
00227                 r = mMusicRemote->getRect();
00228                 r.mLeft = right + PAD;
00229                 right = r.mLeft + music_remote_width;
00230                 r.mRight = right;
00231                 mMusicRemote->setRect(r);
00232         }
00233         if (mVoiceRemote)
00234         {
00235                 r = mVoiceRemote->getRect();
00236                 r.mLeft = right + PAD;
00237                 right = r.mLeft + voice_remote_width;
00238                 r.mRight = right;
00239                 mVoiceRemote->setRect(r);
00240         }
00241         if (mMasterRemote)
00242         {
00243                 r = mMasterRemote->getRect();
00244                 r.mLeft = right + PAD;
00245                 right = r.mLeft + master_remote_width;
00246                 r.mRight = right;
00247                 mMasterRemote->setRect(r);
00248         }
00249         
00250         updateRect();
00251 }
00252 
00253 void LLOverlayBar::draw()
00254 {
00255         // retrieve rounded rect image
00256         LLUUID image_id;
00257         image_id.set(gViewerArt.getString("rounded_square.tga"));
00258         LLViewerImage* imagep = gImageList.getImage(image_id, MIPMAP_FALSE, TRUE);
00259 
00260         if (imagep)
00261         {
00262                 LLGLSTexture texture_enabled;
00263                 LLViewerImage::bindTexture(imagep);
00264 
00265                 const S32 PAD = gSavedSettings.getS32("StatusBarPad");
00266 
00267                 // draw rounded rect tabs behind all children
00268                 LLRect r;
00269                 // focus highlights
00270                 LLColor4 color = gColors.getColor("FloaterFocusBorderColor");
00271                 glColor4fv(color.mV);
00272                 if(gFocusMgr.childHasKeyboardFocus(gBottomPanel))
00273                 {
00274                         for (child_list_const_iter_t child_iter = getChildList()->begin();
00275                                 child_iter != getChildList()->end(); ++child_iter)
00276                         {
00277                                 LLView *view = *child_iter;
00278                                 if(view->getEnabled() && view->getVisible())
00279                                 {
00280                                         r = view->getRect();
00281                                         gl_segmented_rect_2d_tex(r.mLeft - PAD/3 - 1, 
00282                                                                                         r.mTop + 3, 
00283                                                                                         r.mRight + PAD/3 + 1,
00284                                                                                         r.mBottom, 
00285                                                                                         imagep->getWidth(), 
00286                                                                                         imagep->getHeight(), 
00287                                                                                         16, 
00288                                                                                         ROUNDED_RECT_TOP);
00289                                 }
00290                         }
00291                 }
00292 
00293                 // main tabs
00294                 for (child_list_const_iter_t child_iter = getChildList()->begin();
00295                         child_iter != getChildList()->end(); ++child_iter)
00296                 {
00297                         LLView *view = *child_iter;
00298                         if(view->getEnabled() && view->getVisible())
00299                         {
00300                                 r = view->getRect();
00301                                 // draw a nice little pseudo-3D outline
00302                                 color = gColors.getColor("DefaultShadowDark");
00303                                 glColor4fv(color.mV);
00304                                 gl_segmented_rect_2d_tex(r.mLeft - PAD/3 + 1, r.mTop + 2, r.mRight + PAD/3, r.mBottom, 
00305                                                                                  imagep->getWidth(), imagep->getHeight(), 16, ROUNDED_RECT_TOP);
00306                                 color = gColors.getColor("DefaultHighlightLight");
00307                                 glColor4fv(color.mV);
00308                                 gl_segmented_rect_2d_tex(r.mLeft - PAD/3, r.mTop + 2, r.mRight + PAD/3 - 3, r.mBottom, 
00309                                                                                  imagep->getWidth(), imagep->getHeight(), 16, ROUNDED_RECT_TOP);
00310                                 // here's the main background.  Note that it overhangs on the bottom so as to hide the
00311                                 // focus highlight on the bottom panel, thus producing the illusion that the focus highlight
00312                                 // continues around the tabs
00313                                 color = gColors.getColor("FocusBackgroundColor");
00314                                 glColor4fv(color.mV);
00315                                 gl_segmented_rect_2d_tex(r.mLeft - PAD/3 + 1, r.mTop + 1, r.mRight + PAD/3 - 1, r.mBottom - 1, 
00316                                                                                  imagep->getWidth(), imagep->getHeight(), 16, ROUNDED_RECT_TOP);
00317                         }
00318                 }
00319         }
00320 
00321         // draw children on top
00322         LLPanel::draw();
00323 }
00324 
00325 
00326 // Per-frame updates of visibility
00327 void LLOverlayBar::refresh()
00328 {
00329         BOOL im_received = gIMMgr->getIMReceived();
00330         childSetVisible("IM Received", im_received);
00331         childSetEnabled("IM Received", im_received);
00332 
00333         BOOL busy = gAgent.getBusy();
00334         childSetVisible("Set Not Busy", busy);
00335         childSetEnabled("Set Not Busy", busy);
00336 
00337         BOOL controls_grabbed = gAgent.anyControlGrabbed();
00338         
00339         childSetVisible("Release Keys", controls_grabbed);
00340         childSetEnabled("Release Keys", controls_grabbed);
00341 
00342 
00343         BOOL mouselook_grabbed;
00344         mouselook_grabbed = gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_DOWN_INDEX)
00345                                                 || gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_UP_INDEX);
00346 
00347         
00348         childSetVisible("Mouselook", mouselook_grabbed);
00349         childSetEnabled("Mouselook", mouselook_grabbed);
00350 
00351         BOOL sitting = FALSE;
00352         if (gAgent.getAvatarObject())
00353         {
00354                 sitting = gAgent.getAvatarObject()->mIsSitting;
00355                 childSetVisible("Stand Up", sitting);
00356                 childSetEnabled("Stand Up", sitting);
00357                 
00358         }
00359 
00360         if ( mMusicRemote && gAudiop )
00361         {
00362                 LLParcel* parcel = gParcelMgr->getAgentParcel();
00363                 if (!parcel 
00364                         || parcel->getMusicURL().empty()
00365                         || !gSavedSettings.getBOOL("AudioStreamingMusic"))
00366                 {
00367                         mMusicRemote->setVisible(FALSE);
00368                         mMusicRemote->setEnabled(FALSE);
00369                 }
00370                 else
00371                 {
00372                         mMusicRemote->setVisible(TRUE);
00373                         mMusicRemote->setEnabled(TRUE);
00374                 }
00375         }
00376 
00377         // if there is a url and a texture and media is enabled and available and media streaming is on... (phew!)
00378         if ( mMediaRemote )
00379         {
00380                 if (LLMediaEngine::getInstance () &&
00381                         LLMediaEngine::getInstance ()->getUrl ().length () && 
00382                         LLMediaEngine::getInstance ()->getImageUUID ().notNull () &&
00383                         LLMediaEngine::getInstance ()->isEnabled () &&
00384                         LLMediaEngine::getInstance ()->isAvailable () &&
00385                         gSavedSettings.getBOOL ( "AudioStreamingVideo" ) )
00386                 {
00387                         // display remote control 
00388                         mMediaRemote->setVisible ( TRUE );
00389                         mMediaRemote->setEnabled ( TRUE );
00390                 }
00391                 else
00392                 {
00393                         mMediaRemote->setVisible ( FALSE );
00394                         mMediaRemote->setEnabled ( FALSE );
00395                 }
00396         }
00397         if (mVoiceRemote)
00398         {
00399                 mVoiceRemote->setVisible(LLVoiceClient::voiceEnabled());
00400         }
00401         
00402         // turn off the whole bar in mouselook
00403         if (gAgent.cameraMouselook())
00404         {
00405                 setVisible(FALSE);
00406         }
00407         else
00408         {
00409                 setVisible(TRUE);
00410         }
00411 }
00412 
00413 //-----------------------------------------------------------------------
00414 // Static functions
00415 //-----------------------------------------------------------------------
00416 
00417 // static
00418 void LLOverlayBar::onClickIMReceived(void*)
00419 {
00420         gIMMgr->setFloaterOpen(TRUE);
00421 }
00422 
00423 
00424 // static
00425 void LLOverlayBar::onClickSetNotBusy(void*)
00426 {
00427         gAgent.clearBusy();
00428 }
00429 
00430 
00431 // static
00432 void LLOverlayBar::onClickReleaseKeys(void*)
00433 {
00434         gAgent.forceReleaseControls();
00435 }
00436 
00437 // static
00438 void LLOverlayBar::onClickResetView(void* data)
00439 {
00440         handle_reset_view();
00441 }
00442 
00443 //static
00444 void LLOverlayBar::onClickMouselook(void*)
00445 {
00446         gAgent.changeCameraToMouselook();
00447 }
00448 
00449 //static
00450 void LLOverlayBar::onClickStandUp(void*)
00451 {
00452         gAgent.setControlFlags(AGENT_CONTROL_STAND_UP);
00453 }
00454 
00456 // static media helpers
00457 // *TODO: Move this into an audio manager abstraction
00458 
00459 //static
00460 void LLOverlayBar::mediaPlay(void*)
00461 {
00462         if (!gOverlayBar)
00463         {
00464                 return;
00465         }
00466         gOverlayBar->mMediaState = PLAYING; // desired state
00467         LLParcel* parcel = gParcelMgr->getAgentParcel();
00468         if (parcel)
00469         {
00470                 LLString path("");
00471                 LLMediaEngine::getInstance()->convertImageAndLoadUrl( true, false, path );
00472         }
00473 }
00474 //static
00475 void LLOverlayBar::mediaPause(void*)
00476 {
00477         if (!gOverlayBar)
00478         {
00479                 return;
00480         }
00481         gOverlayBar->mMediaState = PAUSED; // desired state
00482         LLMediaEngine::getInstance()->pause();
00483 }
00484 //static
00485 void LLOverlayBar::mediaStop(void*)
00486 {
00487         if (!gOverlayBar)
00488         {
00489                 return;
00490         }
00491         gOverlayBar->mMediaState = STOPPED; // desired state
00492         LLMediaEngine::getInstance()->stop();
00493 }
00494 
00495 //static
00496 void LLOverlayBar::musicPlay(void*)
00497 {
00498         if (!gOverlayBar)
00499         {
00500                 return;
00501         }
00502         gOverlayBar->mMusicState = PLAYING; // desired state
00503         if (gAudiop)
00504         {
00505                 LLParcel* parcel = gParcelMgr->getAgentParcel();
00506                 if ( parcel )
00507                 {
00508                         // this doesn't work properly when crossing parcel boundaries - even when the 
00509                         // stream is stopped, it doesn't return the right thing - commenting out for now.
00510 //                      if ( gAudiop->isInternetStreamPlaying() == 0 )
00511                         {
00512                                 gAudiop->startInternetStream(parcel->getMusicURL().c_str());
00513                         }
00514                 }
00515         }
00516 }
00517 //static
00518 void LLOverlayBar::musicPause(void*)
00519 {
00520         if (!gOverlayBar)
00521         {
00522                 return;
00523         }
00524         gOverlayBar->mMusicState = PAUSED; // desired state
00525         if (gAudiop)
00526         {
00527                 gAudiop->pauseInternetStream(1);
00528         }
00529 }
00530 //static
00531 void LLOverlayBar::musicStop(void*)
00532 {
00533         if (!gOverlayBar)
00534         {
00535                 return;
00536         }
00537         gOverlayBar->mMusicState = STOPPED; // desired state
00538         if (gAudiop)
00539         {
00540                 gAudiop->stopInternetStream();
00541         }
00542 }
00543 
00544 //static
00545 void LLOverlayBar::enableMusicButtons(LLPanel* panel)
00546 {       
00547         BOOL play_enabled = FALSE;
00548         BOOL play_visible = TRUE;
00549         BOOL pause_visible = FALSE;
00550         BOOL stop_enabled = FALSE;
00551         if ( gAudiop && gOverlayBar && gSavedSettings.getBOOL("AudioStreamingMusic"))
00552         {
00553                 play_enabled = TRUE;
00554                 S32 is_playing = gAudiop->isInternetStreamPlaying();
00555                 if (is_playing == 1)
00556                 {
00557                         play_visible = FALSE;
00558                         pause_visible = TRUE;
00559                         stop_enabled = TRUE;
00560                 }
00561                 else if (is_playing == 2)
00562                 {
00563                         play_visible = TRUE;
00564                         pause_visible = FALSE;
00565                         stop_enabled = TRUE;
00566                 }
00567         }
00568         panel->childSetEnabled("music_play", play_enabled);
00569         panel->childSetEnabled("music_pause", play_enabled);
00570         panel->childSetVisible("music_play", play_visible);
00571         panel->childSetVisible("music_pause", pause_visible);
00572         panel->childSetEnabled("music_stop", stop_enabled);
00573 }
00574 
00575 //static
00576 void LLOverlayBar::enableMediaButtons(LLPanel* panel)
00577 {
00578         // Media
00579         BOOL play_enabled = FALSE;
00580         BOOL play_visible = TRUE;
00581         BOOL pause_visible = FALSE;
00582         BOOL stop_enabled = FALSE;
00583 
00584         if ( LLMediaEngine::getInstance() && gOverlayBar && gSavedSettings.getBOOL("AudioStreamingVideo") )
00585         {
00586                 play_enabled = TRUE;
00587                 if (LLMediaEngine::getInstance()->getMediaRenderer())
00588                 {
00589                         if ( LLMediaEngine::getInstance()->getMediaRenderer()->isPlaying() ||
00590                                  LLMediaEngine::getInstance()->getMediaRenderer()->isLooping() )
00591                         {
00592                                 play_visible = FALSE;
00593                                 pause_visible = TRUE;
00594                                 stop_enabled = TRUE;
00595                         }
00596                         else if ( LLMediaEngine::getInstance()->getMediaRenderer()->isPaused() )
00597                         {
00598                                 play_visible = TRUE;
00599                                 pause_visible = FALSE;
00600                                 stop_enabled = TRUE;
00601                         }
00602                 }
00603         }
00604         panel->childSetEnabled("media_play", play_enabled);
00605         panel->childSetEnabled("media_pause", play_enabled);
00606         panel->childSetVisible("media_play", play_visible);
00607         panel->childSetVisible("media_pause", pause_visible);
00608         panel->childSetEnabled("media_stop", stop_enabled);
00609 }
00610 
00611 void LLOverlayBar::toggleAudioVolumeFloater(void* user_data)
00612 {
00613         LLFloaterAudioVolume::toggleInstance(LLSD());
00614 }

Generated on Thu Jul 1 06:08:55 2010 for Second Life Viewer by  doxygen 1.4.7