llvoiceremotectrl.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /**
  2. * @file llvoiceremotectrl.cpp
  3. * @brief A remote control for voice chat
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewergpl$
  6. *
  7. * Copyright (c) 2005-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llvoiceremotectrl.h"
  34. #include "llbutton.h"
  35. #include "lliconctrl.h"
  36. #include "lltextbox.h"
  37. #include "lluictrlfactory.h"
  38. #include "llagent.h"
  39. #include "llfloaterchatterbox.h"
  40. #include "llfloateractivespeakers.h"
  41. #include "lloverlaybar.h"
  42. #include "llviewercontrol.h"
  43. #include "llviewerparcelmgr.h"
  44. #include "llvoicechannel.h"
  45. LLVoiceRemoteCtrl::LLVoiceRemoteCtrl (const std::string& name)
  46. : LLPanel(name)
  47. {
  48. setIsChrome(true);
  49. #if EXPANDED_VOICE_CTRL
  50. if (gSavedSettings.getBool("ShowVoiceChannelPopup"))
  51. {
  52. LLUICtrlFactory::getInstance()->buildPanel(this,
  53. "panel_voice_remote_expanded.xml");
  54. }
  55. else
  56. {
  57. LLUICtrlFactory::getInstance()->buildPanel(this,
  58. "panel_voice_remote.xml");
  59. }
  60. #else
  61. LLUICtrlFactory::getInstance()->buildPanel(this, "panel_voice_remote.xml");
  62. #endif
  63. setFocusRoot(true);
  64. }
  65. bool LLVoiceRemoteCtrl::postBuild()
  66. {
  67. mTalkBtn = getChild<LLButton>("push_to_talk");
  68. mTalkBtn->setClickedCallback(onBtnTalkClicked);
  69. mTalkBtn->setHeldDownCallback(onBtnTalkHeld);
  70. mTalkBtn->setMouseUpCallback(onBtnTalkReleased);
  71. mTalkLockBtn = getChild<LLButton>("ptt_lock");
  72. mTalkLockBtn->setClickedCallback(onBtnLock);
  73. mTalkLockBtn->setCallbackUserData(this);
  74. mSpeakersBtn = getChild<LLButton>("speakers_btn");
  75. mSpeakersBtn->setClickedCallback(onClickSpeakers);
  76. mSpeakersBtn->setCallbackUserData(this);
  77. mIcon = getChild<LLIconCtrl>("voice_volume");
  78. #if EXPANDED_VOICE_CTRL
  79. childSetAction("show_channel", onClickPopupBtn, this);
  80. childSetAction("end_call_btn", onClickEndCall, this);
  81. LLTextBox* text = getChild<LLTextBox>("channel_label");
  82. if (text)
  83. {
  84. text->setUseEllipses(true);
  85. }
  86. childSetAction("voice_channel_bg", onClickVoiceChannel, this);
  87. #endif
  88. return true;
  89. }
  90. void LLVoiceRemoteCtrl::draw()
  91. {
  92. bool voice_active = false;
  93. if (gViewerParcelMgr.allowAgentVoice())
  94. {
  95. LLVoiceChannel* channelp = LLVoiceChannel::getCurrentVoiceChannel();
  96. if (channelp)
  97. {
  98. voice_active = channelp->isActive();
  99. }
  100. }
  101. mTalkBtn->setEnabled(voice_active);
  102. mTalkLockBtn->setEnabled(voice_active);
  103. // Propagate PTT state to button display,
  104. if (!mTalkBtn->hasMouseCapture())
  105. {
  106. mTalkBtn->setToggleState(gVoiceClient.isAgentMicOpen());
  107. }
  108. mSpeakersBtn->setToggleState(LLFloaterActiveSpeakers::instanceVisible(LLSD()));
  109. static LLCachedControl<bool> ptt_enabled(gSavedSettings,
  110. "PTTCurrentlyEnabled");
  111. mTalkLockBtn->setToggleState(!ptt_enabled);
  112. static S32 last_icon_number = -1;
  113. S32 icon_number = 4;
  114. std::string talk_blip_image;
  115. if (gVoiceClient.getIsSpeaking(gAgentID))
  116. {
  117. F32 voice_power = gVoiceClient.getCurrentPower(gAgentID);
  118. if (voice_power > OVERDRIVEN_POWER_LEVEL)
  119. {
  120. talk_blip_image = "icn_voice_ptt-on-lvl3.tga";
  121. icon_number = 3;
  122. }
  123. else
  124. {
  125. F32 power = gVoiceClient.getCurrentPower(gAgentID);
  126. S32 icon_image_idx =
  127. llmin(2, llfloor((power / OVERDRIVEN_POWER_LEVEL) * 3.f));
  128. icon_number = icon_image_idx;
  129. switch (icon_image_idx)
  130. {
  131. case 0:
  132. talk_blip_image = "icn_voice_ptt-on.tga";
  133. break;
  134. case 1:
  135. talk_blip_image = "icn_voice_ptt-on-lvl1.tga";
  136. break;
  137. case 2:
  138. talk_blip_image = "icn_voice_ptt-on-lvl2.tga";
  139. }
  140. }
  141. }
  142. else
  143. {
  144. talk_blip_image = "icn_voice_ptt-off.tga";
  145. }
  146. if (icon_number != last_icon_number)
  147. {
  148. last_icon_number = icon_number;
  149. mIcon->setImage(talk_blip_image);
  150. }
  151. LLFloater* floaterp =
  152. LLFloaterChatterBox::getInstance()->getCurrentVoiceFloater();
  153. std::string active_channel_name;
  154. if (floaterp)
  155. {
  156. active_channel_name = floaterp->getTitle();
  157. }
  158. #if EXPANDED_VOICE_CTRL
  159. LLVoiceChannel* curchannelp = LLVoiceChannel::getCurrentVoiceChannel();
  160. childSetEnabled("end_call_btn",
  161. LLVoiceClient::voiceEnabled() && curchannelp &&
  162. curchannelp->isActive() &&
  163. curchannelp != LLVoiceChannelProximal::getInstance());
  164. childSetValue("channel_label", active_channel_name);
  165. childSetToolTip("voice_channel_bg", active_channel_name);
  166. if (curchannelp)
  167. {
  168. LLIconCtrl* iconp = getChild<LLIconCtrl>("voice_channel_icon");
  169. if (iconp && floaterp)
  170. {
  171. iconp->setImage(floaterp->getString("voice_icon"));
  172. }
  173. LLButton* buttonp = getChild<LLButton>("voice_channel_bg");
  174. if (buttonp)
  175. {
  176. LLColor4 bg_color;
  177. if (curchannelp->isActive())
  178. {
  179. bg_color = lerp(LLColor4::green, LLColor4::white, 0.7f);
  180. }
  181. else if (curchannelp->getState() == LLVoiceChannel::STATE_ERROR)
  182. {
  183. bg_color = lerp(LLColor4::red, LLColor4::white, 0.7f);
  184. }
  185. else // active, but not connected
  186. {
  187. bg_color = lerp(LLColor4::yellow, LLColor4::white, 0.7f);
  188. }
  189. buttonp->setImageColor(bg_color);
  190. }
  191. }
  192. LLButton* buttonp = getChild<LLButton>("show_channel");
  193. if (buttonp)
  194. {
  195. if (buttonp->getToggleState())
  196. {
  197. buttonp->setImageOverlay(std::string("arrow_down.tga"));
  198. }
  199. else
  200. {
  201. buttonp->setImageOverlay(std::string("arrow_up.tga"));
  202. }
  203. }
  204. #endif
  205. LLPanel::draw();
  206. }
  207. //static
  208. void LLVoiceRemoteCtrl::onBtnTalkClicked(void *user_data)
  209. {
  210. // when in toggle mode, clicking talk button turns mic on/off
  211. if (gSavedSettings.getBool("PushToTalkToggle"))
  212. {
  213. gVoiceClient.toggleUserPTTState();
  214. }
  215. }
  216. //static
  217. void LLVoiceRemoteCtrl::onBtnTalkHeld(void *user_data)
  218. {
  219. // when not in toggle mode, holding down talk button turns on mic
  220. if (!gSavedSettings.getBool("PushToTalkToggle"))
  221. {
  222. gVoiceClient.setUserPTTState(true);
  223. }
  224. }
  225. //static
  226. void LLVoiceRemoteCtrl::onBtnTalkReleased(void* user_data)
  227. {
  228. // when not in toggle mode, releasing talk button turns off mic
  229. if (!gSavedSettings.getBool("PushToTalkToggle"))
  230. {
  231. gVoiceClient.setUserPTTState(false);
  232. }
  233. }
  234. //static
  235. void LLVoiceRemoteCtrl::onBtnLock(void* user_data)
  236. {
  237. LLVoiceRemoteCtrl* self = (LLVoiceRemoteCtrl*)user_data;
  238. if (self)
  239. {
  240. gSavedSettings.setBool("PTTCurrentlyEnabled",
  241. !self->mTalkLockBtn->getToggleState());
  242. }
  243. }
  244. //static
  245. void LLVoiceRemoteCtrl::onClickSpeakers(void *user_data)
  246. {
  247. LLFloaterActiveSpeakers::toggleInstance(LLSD());
  248. }
  249. #if EXPANDED_VOICE_CTRL
  250. //static
  251. void LLVoiceRemoteCtrl::onClickPopupBtn(void* user_data)
  252. {
  253. LLVoiceRemoteCtrl* self = (LLVoiceRemoteCtrl*)user_data;
  254. remotep->deleteAllChildren();
  255. if (gSavedSettings.getBool("ShowVoiceChannelPopup"))
  256. {
  257. LLUICtrlFactory::getInstance()->buildPanel(self,
  258. "panel_voice_remote_expanded.xml");
  259. }
  260. else
  261. {
  262. LLUICtrlFactory::getInstance()->buildPanel(self,
  263. "panel_voice_remote.xml");
  264. }
  265. if (gOverlayBarp)
  266. {
  267. gOverlayBarp->setDirty();
  268. }
  269. }
  270. //static
  271. void LLVoiceRemoteCtrl::onClickEndCall(void* user_data)
  272. {
  273. LLVoiceChannel* curchannelp = LLVoiceChannel::getCurrentVoiceChannel();
  274. if (curchannelp && curchannelp != LLVoiceChannelProximal::getInstance())
  275. {
  276. curchannelp->deactivate();
  277. }
  278. }
  279. //static
  280. void LLVoiceRemoteCtrl::onClickVoiceChannel(void* user_data)
  281. {
  282. LLFloaterChatterBox::showInstance();
  283. }
  284. #endif