llvoiceremotectrl.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llvoiceremotectrl.h"
00035 
00036 #include "llagent.h"
00037 #include "llui.h"
00038 #include "llbutton.h"
00039 #include "llvieweruictrlfactory.h"
00040 #include "llviewercontrol.h"
00041 #include "llvoiceclient.h"
00042 #include "llimpanel.h"
00043 #include "llfloateractivespeakers.h"
00044 #include "lliconctrl.h"
00045 
00046 LLVoiceRemoteCtrl::LLVoiceRemoteCtrl (const LLString& name) : LLPanel(name)
00047 {
00048         setIsChrome(TRUE);
00049 
00050         gUICtrlFactory->buildPanel(this, "panel_voice_remote.xml");
00051 
00052         mTalkBtn = LLUICtrlFactory::getButtonByName(this, "push_to_talk");
00053         mTalkBtn->setClickedCallback(onBtnTalkClicked);
00054         mTalkBtn->setHeldDownCallback(onBtnTalkHeld);
00055         mTalkBtn->setMouseUpCallback(onBtnTalkReleased);
00056 
00057         mTalkLockBtn = LLUICtrlFactory::getButtonByName(this, "ptt_lock");
00058         mTalkLockBtn->setClickedCallback(onBtnLock);
00059 
00060         mSpeakersBtn = LLUICtrlFactory::getButtonByName(this, "speakers_btn");
00061         mSpeakersBtn->setClickedCallback(onClickSpeakers);
00062 
00063         mIsFocusRoot = TRUE;
00064 }
00065 
00066 LLVoiceRemoteCtrl::~LLVoiceRemoteCtrl()
00067 {
00068 }
00069 
00070 void LLVoiceRemoteCtrl::draw()
00071 {
00072         BOOL voice_active = FALSE;
00073         LLVoiceChannel* channelp = LLVoiceChannel::getCurrentVoiceChannel();
00074         if (channelp)
00075         {
00076                 voice_active = channelp->isActive();
00077         }
00078 
00079         mTalkBtn->setEnabled(voice_active);
00080         mTalkLockBtn->setEnabled(voice_active);
00081 
00082 //      if (voice_active)
00083 //      {
00084 //              mTalkBtn->setToolTip("");
00085 //              mTalkLockBtn->setToolTip("");
00086 //      }
00087 //      else
00088 //      {
00089 //              mTalkBtn->setToolTip("");
00090 //              mTalkLockBtn->setToolTip("");
00091 //      }
00092 
00093         // propagate ptt state to button display,
00094         if (!mTalkBtn->hasMouseCapture())
00095         {
00096                 // not in push to talk mode, or push to talk is active means I'm talking
00097                 mTalkBtn->setToggleState(!gSavedSettings.getBOOL("PTTCurrentlyEnabled") || gVoiceClient->getUserPTTState());
00098         }
00099         mSpeakersBtn->setToggleState(LLFloaterActiveSpeakers::instanceVisible(LLSD()));
00100         mTalkLockBtn->setToggleState(!gSavedSettings.getBOOL("PTTCurrentlyEnabled"));
00101 
00102         LLUUID talk_blip_image_id;
00103         if (gVoiceClient->getIsSpeaking(gAgent.getID()))
00104         {
00105                 F32 voice_power = gVoiceClient->getCurrentPower(gAgent.getID());
00106 
00107                 if (voice_power > LLVoiceClient::OVERDRIVEN_POWER_LEVEL)
00108                 {
00109                         talk_blip_image_id = LLUUID(gViewerArt.getString("icn_voice_ptt-on-lvl3.tga"));
00110                 }
00111                 else
00112                 {
00113                         F32 power = gVoiceClient->getCurrentPower(gAgent.getID());
00114                         S32 icon_image_idx = llmin(2, llfloor((power / LLVoiceClient::OVERDRIVEN_POWER_LEVEL) * 3.f));
00115 
00116                         switch(icon_image_idx)
00117                         {
00118                         case 0:
00119                                 talk_blip_image_id = LLUUID(gViewerArt.getString("icn_voice_ptt-on.tga"));
00120                                 break;
00121                         case 1:
00122                                 talk_blip_image_id = LLUUID(gViewerArt.getString("icn_voice_ptt-on-lvl1.tga"));
00123                                 break;
00124                         case 2:
00125                                 talk_blip_image_id = LLUUID(gViewerArt.getString("icn_voice_ptt-on-lvl2.tga"));
00126                                 break;
00127                         }
00128                 }
00129         }
00130         else
00131         {
00132                 talk_blip_image_id = LLUUID(gViewerArt.getString("icn_voice_ptt-off.tga"));
00133         }
00134 
00135         LLIconCtrl* icon = LLUICtrlFactory::getIconByName(this, "voice_volume");
00136         if (icon)
00137         {
00138                 icon->setImage(talk_blip_image_id);
00139         }
00140 
00141         LLPanel::draw();
00142 }
00143 
00144 void LLVoiceRemoteCtrl::onBtnTalkClicked(void *user_data)
00145 {
00146         // when in toggle mode, clicking talk button turns mic on/off
00147         if (gSavedSettings.getBOOL("PushToTalkToggle"))
00148         {
00149                 gVoiceClient->toggleUserPTTState();
00150         }
00151 }
00152 
00153 void LLVoiceRemoteCtrl::onBtnTalkHeld(void *user_data)
00154 {
00155         // when not in toggle mode, holding down talk button turns on mic
00156         if (!gSavedSettings.getBOOL("PushToTalkToggle"))
00157         {
00158                 gVoiceClient->setUserPTTState(true);
00159         }
00160 }
00161 
00162 void LLVoiceRemoteCtrl::onBtnTalkReleased(void* user_data)
00163 {
00164         // when not in toggle mode, releasing talk button turns off mic
00165         if (!gSavedSettings.getBOOL("PushToTalkToggle"))
00166         {
00167                 gVoiceClient->setUserPTTState(false);
00168         }
00169 }
00170 
00171 void LLVoiceRemoteCtrl::onBtnLock(void* user_data)
00172 {
00173         LLVoiceRemoteCtrl* remotep = (LLVoiceRemoteCtrl*)user_data;
00174 
00175         remotep->mTalkLockBtn->toggleState();
00176         gSavedSettings.setBOOL("PTTCurrentlyEnabled", !remotep->mTalkLockBtn->getToggleState());
00177 }
00178 
00179 void LLVoiceRemoteCtrl::onClickSpeakers(void *user_data)
00180 {
00181         LLFloaterActiveSpeakers::toggleInstance(LLSD());
00182 }
00183 

Generated on Thu Jul 1 06:09:37 2010 for Second Life Viewer by  doxygen 1.4.7