1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/**
* @file lloutputmonitorctrl.cpp
* @brief LLOutputMonitorCtrl base class
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "lloutputmonitorctrl.h"
// library includes
#include "llui.h"
// viewer includes
#include "llvoiceclient.h"
#include "llmutelist.h"
#include "llagent.h"
// default options set in output_monitor.xml
static LLDefaultChildRegistry::Register<LLOutputMonitorCtrl> r("output_monitor");
// The defaults will be initialized in the constructor.
//LLColor4 LLOutputMonitorCtrl::sColorMuted;
//LLColor4 LLOutputMonitorCtrl::sColorOverdriven;
//LLColor4 LLOutputMonitorCtrl::sColorNormal;
LLColor4 LLOutputMonitorCtrl::sColorBound;
//S32 LLOutputMonitorCtrl::sRectsNumber = 0;
//F32 LLOutputMonitorCtrl::sRectWidthRatio = 0.f;
//F32 LLOutputMonitorCtrl::sRectHeightRatio = 0.f;
LLOutputMonitorCtrl::Params::Params()
: draw_border("draw_border"),
image_mute("image_mute"),
image_off("image_off"),
image_on("image_on"),
image_level_1("image_level_1"),
image_level_2("image_level_2"),
image_level_3("image_level_3"),
auto_update("auto_update"),
speaker_id("speaker_id")
{
};
LLOutputMonitorCtrl::LLOutputMonitorCtrl(const LLOutputMonitorCtrl::Params& p)
: LLView(p),
mPower(0),
mImageMute(p.image_mute),
mImageOff(p.image_off),
mImageOn(p.image_on),
mImageLevel1(p.image_level_1),
mImageLevel2(p.image_level_2),
mImageLevel3(p.image_level_3),
mAutoUpdate(p.auto_update),
mSpeakerId(p.speaker_id),
mIsAgentControl(false),
mIsSwitchDirty(false),
mShouldSwitchOn(false)
{
//static LLUIColor output_monitor_muted_color = LLUIColorTable::instance().getColor("OutputMonitorMutedColor", LLColor4::orange);
//static LLUIColor output_monitor_overdriven_color = LLUIColorTable::instance().getColor("OutputMonitorOverdrivenColor", LLColor4::red);
//static LLUIColor output_monitor_normal_color = LLUIColorTable::instance().getColor("OutputMonitorNotmalColor", LLColor4::green);
static LLUIColor output_monitor_bound_color = LLUIColorTable::instance().getColor("OutputMonitorBoundColor", LLColor4::white);
//static LLUICachedControl<S32> output_monitor_rects_number("OutputMonitorRectanglesNumber", 20);
//static LLUICachedControl<F32> output_monitor_rect_width_ratio("OutputMonitorRectangleWidthRatio", 0.5f);
//static LLUICachedControl<F32> output_monitor_rect_height_ratio("OutputMonitorRectangleHeightRatio", 0.8f);
// IAN BUG compare to existing pattern where these are members - some will change per-widget and need to be anyway
// sent feedback to PE
// *TODO: it looks suboptimal to load the defaults every time an output monitor is constructed.
//sColorMuted = output_monitor_muted_color;
//sColorOverdriven = output_monitor_overdriven_color;
//sColorNormal = output_monitor_normal_color;
sColorBound = output_monitor_bound_color;
//sRectsNumber = output_monitor_rects_number;
//sRectWidthRatio = output_monitor_rect_width_ratio;
//sRectHeightRatio = output_monitor_rect_height_ratio;
mBorder = p.draw_border;
//with checking mute state
setSpeakerId(mSpeakerId);
}
LLOutputMonitorCtrl::~LLOutputMonitorCtrl()
{
LLMuteList::getInstance()->removeObserver(this);
LLSpeakingIndicatorManager::unregisterSpeakingIndicator(mSpeakerId, this);
}
void LLOutputMonitorCtrl::setPower(F32 val)
{
mPower = llmax(0.f, llmin(1.f, val));
}
void LLOutputMonitorCtrl::draw()
{
// see also switchIndicator()
if (mIsSwitchDirty)
{
mIsSwitchDirty = false;
if (mShouldSwitchOn)
{
// just notify parent visibility may have changed
notifyParentVisibilityChanged();
}
else
{
// make itself invisible and notify parent about this
setVisible(FALSE);
notifyParentVisibilityChanged();
// no needs to render for invisible element
return;
}
}
// Copied from llmediaremotectrl.cpp
// *TODO: Give the LLOutputMonitorCtrl an agent-id to monitor, then
// call directly into gVoiceClient to ask if that agent-id is muted, is
// speaking, and what power. This avoids duplicating data, which can get
// out of sync.
const F32 LEVEL_0 = LLVoiceClient::OVERDRIVEN_POWER_LEVEL / 3.f;
const F32 LEVEL_1 = LLVoiceClient::OVERDRIVEN_POWER_LEVEL * 2.f / 3.f;
const F32 LEVEL_2 = LLVoiceClient::OVERDRIVEN_POWER_LEVEL;
if (getVisible() && mAutoUpdate && !mIsMuted && mSpeakerId.notNull())
{
setPower(gVoiceClient->getCurrentPower(mSpeakerId));
if(mIsAgentControl)
{
setIsTalking(gVoiceClient->getUserPTTState());
}
else
{
setIsTalking(gVoiceClient->getIsSpeaking(mSpeakerId));
}
}
LLPointer<LLUIImage> icon;
if (mIsMuted)
{
icon = mImageMute;
}
else if (mPower == 0.f && !mIsTalking)
{
// only show off if PTT is not engaged
icon = mImageOff;
}
else if (mPower < LEVEL_0)
{
// PTT is on, possibly with quiet background noise
icon = mImageOn;
}
else if (mPower < LEVEL_1)
{
icon = mImageLevel1;
}
else if (mPower < LEVEL_2)
{
icon = mImageLevel2;
}
else
{
// overdriven
icon = mImageLevel3;
}
if (icon)
{
icon->draw(0, 0);
}
//
// Fill the monitor with a bunch of small rectangles.
// The rectangles will be filled with gradient color,
// beginning with sColorNormal and ending with sColorOverdriven.
//
// *TODO: would using a (partially drawn) pixmap instead be faster?
//
const int monh = getRect().getHeight();
const int monw = getRect().getWidth();
//int maxrects = sRectsNumber;
//const int period = llmax(1, monw / maxrects, 0, 0); // "1" - min value for the period
//const int rectw = llmax(1, llfloor(period * sRectWidthRatio), 0, 0); // "1" - min value for the rect's width
//const int recth = llfloor(monh * sRectHeightRatio);
//if(period == 1 && rectw == 1) //if we have so small control, then "maxrects = monitor's_width - 2*monitor_border's_width
// maxrects = monw-2;
//const int nrects = mIsMuted ? maxrects : llfloor(mPower * maxrects); // how many rects to draw?
//const int rectbtm = (monh - recth) / 2;
//const int recttop = rectbtm + recth;
//
//LLColor4 rect_color;
//
//for (int i=1, xpos = 0; i <= nrects; i++)
//{
// // Calculate color to use for the current rectangle.
// if (mIsMuted)
// {
// rect_color = sColorMuted;
// }
// else
// {
// F32 frac = (mPower * i/nrects) / LLVoiceClient::OVERDRIVEN_POWER_LEVEL;
// // Use overdriven color if the power exceeds overdriven level.
// if (frac > 1.0f)
// frac = 1.0f;
// rect_color = lerp(sColorNormal, sColorOverdriven, frac);
// }
// // Draw rectangle filled with the color.
// gl_rect_2d(xpos, recttop, xpos+rectw, rectbtm, rect_color, TRUE);
// xpos += period;
//}
//
// Draw bounding box.
//
if(mBorder)
gl_rect_2d(0, monh, monw, 0, sColorBound, FALSE);
}
void LLOutputMonitorCtrl::setSpeakerId(const LLUUID& speaker_id, const LLUUID& session_id/* = LLUUID::null*/)
{
if (speaker_id.isNull() && mSpeakerId.notNull())
{
LLSpeakingIndicatorManager::unregisterSpeakingIndicator(mSpeakerId, this);
}
if (speaker_id.isNull() || speaker_id == mSpeakerId) return;
if (mSpeakerId.notNull())
{
// Unregister previous registration to avoid crash. EXT-4782.
LLSpeakingIndicatorManager::unregisterSpeakingIndicator(mSpeakerId, this);
}
mSpeakerId = speaker_id;
LLSpeakingIndicatorManager::registerSpeakingIndicator(mSpeakerId, this);
//mute management
if (mAutoUpdate)
{
if (speaker_id == gAgentID)
{
setIsMuted(false);
}
else
{
// check only blocking on voice. EXT-3542
setIsMuted(LLMuteList::getInstance()->isMuted(mSpeakerId, LLMute::flagVoiceChat));
LLMuteList::getInstance()->addObserver(this);
}
}
}
void LLOutputMonitorCtrl::onChange()
{
// check only blocking on voice. EXT-3542
setIsMuted(LLMuteList::getInstance()->isMuted(mSpeakerId, LLMute::flagVoiceChat));
}
// virtual
void LLOutputMonitorCtrl::switchIndicator(bool switch_on)
{
// ensure indicator is visible in case it is not in visible chain
// to be called when parent became visible next time to notify parent that visibility is changed.
setVisible(TRUE);
// if parent is in visible chain apply switch_on state and notify it immediately
if (getParent() && getParent()->isInVisibleChain())
{
LL_DEBUGS("SpeakingIndicator") << "Indicator is in visible chain, notifying parent: " << mSpeakerId << LL_ENDL;
setVisible((BOOL)switch_on);
notifyParentVisibilityChanged();
}
// otherwise remember necessary state and mark itself as dirty.
// State will be applied i next draw when parents chain became visible.
else
{
LL_DEBUGS("SpeakingIndicator") << "Indicator is not in visible chain, parent won't be notified: " << mSpeakerId << LL_ENDL;
mIsSwitchDirty = true;
mShouldSwitchOn = switch_on;
}
}
//////////////////////////////////////////////////////////////////////////
// PRIVATE SECTION
//////////////////////////////////////////////////////////////////////////
void LLOutputMonitorCtrl::notifyParentVisibilityChanged()
{
LL_DEBUGS("SpeakingIndicator") << "Notify parent that visibility was changed: " << mSpeakerId << " ,new_visibility: " << getVisible() << LL_ENDL;
LLSD params = LLSD().with("visibility_changed", getVisible());
notifyParent(params);
}
// EOF
|