llvoiceremotectrl.cpp

Go to the documentation of this file.
00001 /* @file llvoiceremotectrl.cpp
00002  * @brief A remote control for voice chat
00003  *
00004  * $LicenseInfo:firstyear=2005&license=viewergpl$
00005  * 
00006  * Copyright (c) 2005-2008, Linden Research, Inc.
00007  * 
00008  * Second Life Viewer Source Code
00009  * The source code in this file ("Source Code") is provided by Linden Lab
00010  * to you under the terms of the GNU General Public License, version 2.0
00011  * ("GPL"), unless you have obtained a separate licensing agreement
00012  * ("Other License"), formally executed by you and Linden Lab.  Terms of
00013  * the GPL can be found in doc/GPL-license.txt in this distribution, or
00014  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
00015  * 
00016  * There are special exceptions to the terms and conditions of the GPL as
00017  * it is applied to this Source Code. View the full text of the exception
00018  * in the file doc/FLOSS-exception.txt in this software distribution, or
00019  * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
00020  * 
00021  * By copying, modifying or distributing this software, you acknowledge
00022  * that you have read and understood your obligations described above,
00023  * and agree to abide by those obligations.
00024  * 
00025  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
00026  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
00027  * COMPLETENESS OR PERFORMANCE.
00028  * $/LicenseInfo$
00029  */
00030 
00031 #include "llviewerprecompiledheaders.h"
00032 
00033 #include "llvoiceremotectrl.h"
00034 
00035 #include "llagent.h"
00036 #include "llui.h"
00037 #include "llbutton.h"
00038 #include "lluictrlfactory.h"
00039 #include "llviewercontrol.h"
00040 #include "llvoiceclient.h"
00041 #include "llimpanel.h"
00042 #include "llfloateractivespeakers.h"
00043 #include "llfloaterchatterbox.h"
00044 #include "lliconctrl.h"
00045 #include "lloverlaybar.h"
00046 #include "lltextbox.h"
00047 
00048 LLVoiceRemoteCtrl::LLVoiceRemoteCtrl (const LLString& name) : LLPanel(name)
00049 {
00050         setIsChrome(TRUE);
00051 
00052         if (gSavedSettings.getBOOL("ShowVoiceChannelPopup"))
00053         {
00054                 LLUICtrlFactory::getInstance()->buildPanel(this, "panel_voice_remote_expanded.xml");
00055         }
00056         else
00057         {
00058                 LLUICtrlFactory::getInstance()->buildPanel(this, "panel_voice_remote.xml");
00059         }
00060 
00061         setFocusRoot(TRUE);
00062 }
00063 
00064 LLVoiceRemoteCtrl::~LLVoiceRemoteCtrl()
00065 {
00066 }
00067 
00068 BOOL LLVoiceRemoteCtrl::postBuild()
00069 {
00070         mTalkBtn = getChild<LLButton>("push_to_talk");
00071         mTalkBtn->setClickedCallback(onBtnTalkClicked);
00072         mTalkBtn->setHeldDownCallback(onBtnTalkHeld);
00073         mTalkBtn->setMouseUpCallback(onBtnTalkReleased);
00074 
00075         mTalkLockBtn = getChild<LLButton>("ptt_lock");
00076         mTalkLockBtn->setClickedCallback(onBtnLock);
00077         mTalkLockBtn->setCallbackUserData(this);
00078 
00079         mSpeakersBtn = getChild<LLButton>("speakers_btn");
00080         mSpeakersBtn->setClickedCallback(onClickSpeakers);
00081         mSpeakersBtn->setCallbackUserData(this);
00082 
00083         childSetAction("show_channel", onClickPopupBtn, this);
00084         childSetAction("end_call_btn", onClickEndCall, this);
00085 
00086         LLTextBox* text = getChild<LLTextBox>("channel_label");
00087         if (text)
00088         {
00089                 text->setUseEllipses(TRUE);
00090         }
00091 
00092         childSetAction("voice_channel_bg", onClickVoiceChannel, this);
00093 
00094 
00095         return TRUE;
00096 }
00097 
00098 void LLVoiceRemoteCtrl::draw()
00099 {
00100         BOOL voice_active = FALSE;
00101         LLVoiceChannel* channelp = LLVoiceChannel::getCurrentVoiceChannel();
00102         if (channelp)
00103         {
00104                 voice_active = channelp->isActive();
00105         }
00106 
00107         mTalkBtn->setEnabled(voice_active);
00108         mTalkLockBtn->setEnabled(voice_active);
00109 
00110         // propagate ptt state to button display,
00111         if (!mTalkBtn->hasMouseCapture())
00112         {
00113                 // not in push to talk mode, or push to talk is active means I'm talking
00114                 mTalkBtn->setToggleState(!gSavedSettings.getBOOL("PTTCurrentlyEnabled") || gVoiceClient->getUserPTTState());
00115         }
00116         mSpeakersBtn->setToggleState(LLFloaterActiveSpeakers::instanceVisible(LLSD()));
00117         mTalkLockBtn->setToggleState(!gSavedSettings.getBOOL("PTTCurrentlyEnabled"));
00118 
00119         LLString talk_blip_image;
00120         if (gVoiceClient->getIsSpeaking(gAgent.getID()))
00121         {
00122                 F32 voice_power = gVoiceClient->getCurrentPower(gAgent.getID());
00123 
00124                 if (voice_power > LLVoiceClient::OVERDRIVEN_POWER_LEVEL)
00125                 {
00126                         talk_blip_image = "icn_voice_ptt-on-lvl3.tga";
00127                 }
00128                 else
00129                 {
00130                         F32 power = gVoiceClient->getCurrentPower(gAgent.getID());
00131                         S32 icon_image_idx = llmin(2, llfloor((power / LLVoiceClient::OVERDRIVEN_POWER_LEVEL) * 3.f));
00132 
00133                         switch(icon_image_idx)
00134                         {
00135                         case 0:
00136                                 talk_blip_image = "icn_voice_ptt-on.tga";
00137                                 break;
00138                         case 1:
00139                                 talk_blip_image = "icn_voice_ptt-on-lvl1.tga";
00140                                 break;
00141                         case 2:
00142                                 talk_blip_image = "icn_voice_ptt-on-lvl2.tga";
00143                                 break;
00144                         }
00145                 }
00146         }
00147         else
00148         {
00149                 talk_blip_image = "icn_voice_ptt-off.tga";
00150         }
00151 
00152         LLIconCtrl* icon = getChild<LLIconCtrl>("voice_volume");
00153         if (icon)
00154         {
00155                 icon->setImage(talk_blip_image);
00156         }
00157 
00158         LLFloater* voice_floater = LLFloaterChatterBox::getInstance()->getCurrentVoiceFloater();
00159         LLString active_channel_name;
00160         if (voice_floater)
00161         {
00162                 active_channel_name = voice_floater->getShortTitle();
00163         }
00164 
00165         LLVoiceChannel* current_channel = LLVoiceChannel::getCurrentVoiceChannel();
00166         childSetEnabled("end_call_btn", LLVoiceClient::voiceEnabled() 
00167                                                                 && current_channel
00168                                                                 && current_channel->isActive()
00169                                                                 && current_channel != LLVoiceChannelProximal::getInstance());
00170 
00171         childSetValue("channel_label", active_channel_name);
00172         childSetToolTip("voice_channel_bg", active_channel_name);
00173 
00174         if (current_channel)
00175         {
00176                 LLIconCtrl* voice_channel_icon = getChild<LLIconCtrl>("voice_channel_icon");
00177                 if (voice_channel_icon && voice_floater)
00178                 {
00179                         voice_channel_icon->setImage(voice_floater->getUIString("voice_icon"));
00180                 }
00181 
00182                 LLButton* voice_channel_bg = getChild<LLButton>("voice_channel_bg");
00183                 if (voice_channel_bg)
00184                 {
00185                         LLColor4 bg_color;
00186                         if (current_channel->isActive())
00187                         {
00188                                 bg_color = lerp(LLColor4::green, LLColor4::white, 0.7f);
00189                         }
00190                         else if (current_channel->getState() == LLVoiceChannel::STATE_ERROR)
00191                         {
00192                                 bg_color = lerp(LLColor4::red, LLColor4::white, 0.7f);
00193                         }
00194                         else // active, but not connected
00195                         {
00196                                 bg_color = lerp(LLColor4::yellow, LLColor4::white, 0.7f);
00197                         }
00198                         voice_channel_bg->setImageColor(bg_color);
00199                 }
00200         }
00201 
00202         LLButton* expand_button = getChild<LLButton>("show_channel");
00203         if (expand_button)
00204         {
00205                 if (expand_button->getToggleState())
00206                 {
00207                         expand_button->setImageOverlay("arrow_down.tga");
00208                 }
00209                 else
00210                 {
00211                         expand_button->setImageOverlay("arrow_up.tga");
00212                 }
00213         }
00214 
00215         LLPanel::draw();
00216 }
00217 
00218 void LLVoiceRemoteCtrl::onBtnTalkClicked(void *user_data)
00219 {
00220         // when in toggle mode, clicking talk button turns mic on/off
00221         if (gSavedSettings.getBOOL("PushToTalkToggle"))
00222         {
00223                 gVoiceClient->toggleUserPTTState();
00224         }
00225 }
00226 
00227 void LLVoiceRemoteCtrl::onBtnTalkHeld(void *user_data)
00228 {
00229         // when not in toggle mode, holding down talk button turns on mic
00230         if (!gSavedSettings.getBOOL("PushToTalkToggle"))
00231         {
00232                 gVoiceClient->setUserPTTState(true);
00233         }
00234 }
00235 
00236 void LLVoiceRemoteCtrl::onBtnTalkReleased(void* user_data)
00237 {
00238         // when not in toggle mode, releasing talk button turns off mic
00239         if (!gSavedSettings.getBOOL("PushToTalkToggle"))
00240         {
00241                 gVoiceClient->setUserPTTState(false);
00242         }
00243 }
00244 
00245 void LLVoiceRemoteCtrl::onBtnLock(void* user_data)
00246 {
00247         LLVoiceRemoteCtrl* remotep = (LLVoiceRemoteCtrl*)user_data;
00248 
00249         gSavedSettings.setBOOL("PTTCurrentlyEnabled", !remotep->mTalkLockBtn->getToggleState());
00250 }
00251 
00252 //static
00253 void LLVoiceRemoteCtrl::onClickPopupBtn(void* user_data)
00254 {
00255         LLVoiceRemoteCtrl* remotep = (LLVoiceRemoteCtrl*)user_data;
00256 
00257         remotep->deleteAllChildren();
00258         if (gSavedSettings.getBOOL("ShowVoiceChannelPopup"))
00259         {
00260                 LLUICtrlFactory::getInstance()->buildPanel(remotep, "panel_voice_remote_expanded.xml");
00261         }
00262         else
00263         {
00264                 LLUICtrlFactory::getInstance()->buildPanel(remotep, "panel_voice_remote.xml");
00265         }
00266         gOverlayBar->layoutButtons();
00267 }
00268 
00269 //static
00270 void LLVoiceRemoteCtrl::onClickEndCall(void* user_data)
00271 {
00272         LLVoiceChannel* current_channel = LLVoiceChannel::getCurrentVoiceChannel();
00273 
00274         if (current_channel && current_channel != LLVoiceChannelProximal::getInstance())
00275         {
00276                 current_channel->deactivate();
00277         }
00278 }
00279 
00280 
00281 void LLVoiceRemoteCtrl::onClickSpeakers(void *user_data)
00282 {
00283         LLFloaterActiveSpeakers::toggleInstance(LLSD());
00284 }
00285 
00286 //static 
00287 void LLVoiceRemoteCtrl::onClickVoiceChannel(void* user_data)
00288 {
00289         LLFloaterChatterBox::showInstance();
00290 }

Generated on Fri May 16 08:34:22 2008 for SecondLife by  doxygen 1.5.5