diff options
Diffstat (limited to 'linden/indra/llui/llslider.cpp')
-rw-r--r-- | linden/indra/llui/llslider.cpp | 158 |
1 files changed, 108 insertions, 50 deletions
diff --git a/linden/indra/llui/llslider.cpp b/linden/indra/llui/llslider.cpp index 8c0d2a1..e3a3153 100644 --- a/linden/indra/llui/llslider.cpp +++ b/linden/indra/llui/llslider.cpp | |||
@@ -50,6 +50,7 @@ LLSlider::LLSlider( | |||
50 | F32 min_value, | 50 | F32 min_value, |
51 | F32 max_value, | 51 | F32 max_value, |
52 | F32 increment, | 52 | F32 increment, |
53 | BOOL volume, | ||
53 | const LLString& control_name) | 54 | const LLString& control_name) |
54 | : | 55 | : |
55 | LLUICtrl( name, rect, TRUE, on_commit_callback, callback_userdata, | 56 | LLUICtrl( name, rect, TRUE, on_commit_callback, callback_userdata, |
@@ -59,6 +60,7 @@ LLSlider::LLSlider( | |||
59 | mMinValue( min_value ), | 60 | mMinValue( min_value ), |
60 | mMaxValue( max_value ), | 61 | mMaxValue( max_value ), |
61 | mIncrement( increment ), | 62 | mIncrement( increment ), |
63 | mVolumeSlider( volume ), | ||
62 | mMouseOffset( 0 ), | 64 | mMouseOffset( 0 ), |
63 | mDragStartThumbRect( 0, mRect.getHeight(), THUMB_WIDTH, 0 ), | 65 | mDragStartThumbRect( 0, mRect.getHeight(), THUMB_WIDTH, 0 ), |
64 | mThumbRect( 0, mRect.getHeight(), THUMB_WIDTH, 0 ), | 66 | mThumbRect( 0, mRect.getHeight(), THUMB_WIDTH, 0 ), |
@@ -69,7 +71,7 @@ LLSlider::LLSlider( | |||
69 | mMouseDownCallback( NULL ), | 71 | mMouseDownCallback( NULL ), |
70 | mMouseUpCallback( NULL ) | 72 | mMouseUpCallback( NULL ) |
71 | { | 73 | { |
72 | // prperly handle setting the starting thumb rect | 74 | // properly handle setting the starting thumb rect |
73 | // do it this way to handle both the operating-on-settings | 75 | // do it this way to handle both the operating-on-settings |
74 | // and standalone ways of using this | 76 | // and standalone ways of using this |
75 | setControlName(control_name, NULL); | 77 | setControlName(control_name, NULL); |
@@ -94,13 +96,15 @@ void LLSlider::setValue(F32 value, BOOL from_event) | |||
94 | value -= mMinValue; | 96 | value -= mMinValue; |
95 | value += mIncrement/2.0001f; | 97 | value += mIncrement/2.0001f; |
96 | value -= fmod(value, mIncrement); | 98 | value -= fmod(value, mIncrement); |
97 | mValue = mMinValue + value; | 99 | value += mMinValue; |
98 | 100 | ||
99 | if (!from_event) | 101 | if (!from_event && mValue != value) |
100 | { | 102 | { |
101 | setControlValue(mValue); | 103 | setControlValue(value); |
102 | } | 104 | } |
103 | 105 | ||
106 | mValue = value; | ||
107 | |||
104 | F32 t = (mValue - mMinValue) / (mMaxValue - mMinValue); | 108 | F32 t = (mValue - mMinValue) / (mMaxValue - mMinValue); |
105 | 109 | ||
106 | S32 left_edge = THUMB_WIDTH/2; | 110 | S32 left_edge = THUMB_WIDTH/2; |
@@ -111,6 +115,18 @@ void LLSlider::setValue(F32 value, BOOL from_event) | |||
111 | mThumbRect.mRight = x + (THUMB_WIDTH/2); | 115 | mThumbRect.mRight = x + (THUMB_WIDTH/2); |
112 | } | 116 | } |
113 | 117 | ||
118 | void LLSlider::setValueAndCommit(F32 value) | ||
119 | { | ||
120 | F32 old_value = mValue; | ||
121 | setValue(value); | ||
122 | |||
123 | if (mValue != old_value) | ||
124 | { | ||
125 | onCommit(); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | |||
114 | F32 LLSlider::getValueF32() const | 130 | F32 LLSlider::getValueF32() const |
115 | { | 131 | { |
116 | return mValue; | 132 | return mValue; |
@@ -127,8 +143,7 @@ BOOL LLSlider::handleHover(S32 x, S32 y, MASK mask) | |||
127 | x = llclamp( x, left_edge, right_edge ); | 143 | x = llclamp( x, left_edge, right_edge ); |
128 | 144 | ||
129 | F32 t = F32(x - left_edge) / (right_edge - left_edge); | 145 | F32 t = F32(x - left_edge) / (right_edge - left_edge); |
130 | setValue(t * (mMaxValue - mMinValue) + mMinValue ); | 146 | setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue ); |
131 | onCommit(); | ||
132 | 147 | ||
133 | getWindow()->setCursor(UI_CURSOR_ARROW); | 148 | getWindow()->setCursor(UI_CURSOR_ARROW); |
134 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; | 149 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; |
@@ -178,8 +193,7 @@ BOOL LLSlider::handleMouseDown(S32 x, S32 y, MASK mask) | |||
178 | 193 | ||
179 | if (MASK_CONTROL & mask) // if CTRL is modifying | 194 | if (MASK_CONTROL & mask) // if CTRL is modifying |
180 | { | 195 | { |
181 | setValue(mInitialValue); | 196 | setValueAndCommit(mInitialValue); |
182 | onCommit(); | ||
183 | } | 197 | } |
184 | else | 198 | else |
185 | { | 199 | { |
@@ -216,13 +230,11 @@ BOOL LLSlider::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent) | |||
216 | handled = TRUE; | 230 | handled = TRUE; |
217 | break; | 231 | break; |
218 | case KEY_LEFT: | 232 | case KEY_LEFT: |
219 | setValue(getValueF32() - getIncrement()); | 233 | setValueAndCommit(getValueF32() - getIncrement()); |
220 | onCommit(); | ||
221 | handled = TRUE; | 234 | handled = TRUE; |
222 | break; | 235 | break; |
223 | case KEY_RIGHT: | 236 | case KEY_RIGHT: |
224 | setValue(getValueF32() + getIncrement()); | 237 | setValueAndCommit(getValueF32() + getIncrement()); |
225 | onCommit(); | ||
226 | handled = TRUE; | 238 | handled = TRUE; |
227 | break; | 239 | break; |
228 | default: | 240 | default: |
@@ -244,33 +256,93 @@ void LLSlider::draw() | |||
244 | LLRect rect(mDragStartThumbRect); | 256 | LLRect rect(mDragStartThumbRect); |
245 | 257 | ||
246 | F32 opacity = mEnabled ? 1.f : 0.3f; | 258 | F32 opacity = mEnabled ? 1.f : 0.3f; |
259 | LLColor4 center_color = (mThumbCenterColor % opacity); | ||
260 | LLColor4 outline_color = (mThumbOutlineColor % opacity); | ||
261 | LLColor4 track_color = (mTrackColor % opacity); | ||
247 | 262 | ||
263 | LLImageGL* thumb_imagep = NULL; | ||
264 | |||
248 | // Track | 265 | // Track |
266 | if (mVolumeSlider) | ||
267 | { | ||
268 | LLRect track(0, mRect.getHeight(), mRect.getWidth(), 0); | ||
269 | |||
270 | track.mBottom += 3; | ||
271 | track.mTop -= 1; | ||
272 | track.mRight -= 1; | ||
273 | |||
274 | gl_triangle_2d(track.mLeft, track.mBottom, | ||
275 | track.mRight, track.mBottom, | ||
276 | track.mRight, track.mTop, | ||
277 | center_color, | ||
278 | TRUE); | ||
279 | gl_triangle_2d(track.mLeft, track.mBottom, | ||
280 | track.mRight, track.mBottom, | ||
281 | track.mRight, track.mTop, | ||
282 | outline_color, | ||
283 | FALSE); | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | LLUUID thumb_image_id; | ||
288 | thumb_image_id.set(LLUI::sAssetsGroup->getString("rounded_square.tga")); | ||
289 | thumb_imagep = LLUI::sImageProvider->getUIImageByID(thumb_image_id); | ||
249 | 290 | ||
250 | LLUUID thumb_image_id; | 291 | S32 height_offset = (mRect.getHeight() - TRACK_HEIGHT) / 2; |
251 | thumb_image_id.set(LLUI::sAssetsGroup->getString("rounded_square.tga")); | 292 | LLRect track_rect(0, mRect.getHeight() - height_offset, mRect.getWidth(), height_offset ); |
252 | LLImageGL* thumb_imagep = LLUI::sImageProvider->getUIImageByID(thumb_image_id); | ||
253 | |||
254 | S32 height_offset = (mRect.getHeight() - TRACK_HEIGHT) / 2; | ||
255 | LLRect track_rect(0, mRect.getHeight() - height_offset, mRect.getWidth(), height_offset ); | ||
256 | 293 | ||
257 | track_rect.stretch(-1); | 294 | track_rect.stretch(-1); |
258 | gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 16, 16, track_rect.getWidth(), track_rect.getHeight(), | 295 | gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 16, 16, track_rect.getWidth(), track_rect.getHeight(), |
259 | thumb_imagep, mTrackColor % opacity); | 296 | thumb_imagep, track_color); |
260 | //gl_rect_2d( track_rect, mThumbOutlineColor % opacity ); | 297 | } |
261 | 298 | ||
299 | // Thumb | ||
262 | if (!thumb_imagep) | 300 | if (!thumb_imagep) |
263 | { | 301 | { |
264 | gl_rect_2d(mThumbRect, mThumbCenterColor, TRUE); | 302 | if (mVolumeSlider) |
265 | if (hasMouseCapture()) | 303 | { |
304 | if (hasMouseCapture()) | ||
305 | { | ||
306 | LLRect rect(mDragStartThumbRect); | ||
307 | gl_rect_2d( rect, outline_color ); | ||
308 | rect.stretch(-1); | ||
309 | gl_rect_2d( rect, mThumbCenterColor % 0.3f ); | ||
310 | |||
311 | if (hasFocus()) | ||
312 | { | ||
313 | LLRect thumb_rect = mThumbRect; | ||
314 | thumb_rect.stretch(llround(lerp(1.f, 3.f, gFocusMgr.getFocusFlashAmt()))); | ||
315 | gl_rect_2d(thumb_rect, gFocusMgr.getFocusColor()); | ||
316 | } | ||
317 | gl_rect_2d( mThumbRect, mThumbOutlineColor ); | ||
318 | } | ||
319 | else | ||
320 | { | ||
321 | if (hasFocus()) | ||
322 | { | ||
323 | LLRect thumb_rect = mThumbRect; | ||
324 | thumb_rect.stretch(llround(lerp(1.f, 3.f, gFocusMgr.getFocusFlashAmt()))); | ||
325 | gl_rect_2d(thumb_rect, gFocusMgr.getFocusColor()); | ||
326 | } | ||
327 | LLRect rect(mThumbRect); | ||
328 | gl_rect_2d(rect, outline_color); | ||
329 | rect.stretch(-1); | ||
330 | gl_rect_2d( rect, center_color); | ||
331 | } | ||
332 | } | ||
333 | else | ||
266 | { | 334 | { |
267 | gl_rect_2d(mDragStartThumbRect, mThumbCenterColor % opacity, FALSE); | 335 | gl_rect_2d(mThumbRect, mThumbCenterColor, TRUE); |
336 | if (hasMouseCapture()) | ||
337 | { | ||
338 | gl_rect_2d(mDragStartThumbRect, center_color, FALSE); | ||
339 | } | ||
268 | } | 340 | } |
269 | } | 341 | } |
270 | else if( hasMouseCapture() ) | 342 | else if( hasMouseCapture() ) |
271 | { | 343 | { |
272 | gl_draw_scaled_image_with_border(mDragStartThumbRect.mLeft, mDragStartThumbRect.mBottom, 16, 16, mDragStartThumbRect.getWidth(), mDragStartThumbRect.getHeight(), | 344 | gl_draw_scaled_image_with_border(mDragStartThumbRect.mLeft, mDragStartThumbRect.mBottom, 16, 16, mDragStartThumbRect.getWidth(), mDragStartThumbRect.getHeight(), |
273 | thumb_imagep, mThumbCenterColor % 0.3f, TRUE); | 345 | thumb_imagep, mThumbCenterColor % 0.3f, TRUE); |
274 | 346 | ||
275 | if (hasFocus()) | 347 | if (hasFocus()) |
276 | { | 348 | { |
@@ -278,20 +350,12 @@ void LLSlider::draw() | |||
278 | LLRect highlight_rect = mThumbRect; | 350 | LLRect highlight_rect = mThumbRect; |
279 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); | 351 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); |
280 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), highlight_rect.getHeight(), | 352 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), highlight_rect.getHeight(), |
281 | thumb_imagep, gFocusMgr.getFocusColor()); | 353 | thumb_imagep, gFocusMgr.getFocusColor()); |
282 | } | 354 | } |
283 | 355 | ||
284 | |||
285 | gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), | 356 | gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), |
286 | thumb_imagep, mThumbOutlineColor, TRUE); | 357 | thumb_imagep, mThumbOutlineColor, TRUE); |
287 | |||
288 | //// Start Thumb | ||
289 | //gl_rect_2d( mDragStartThumbRect, mThumbOutlineColor % 0.3f ); | ||
290 | //rect.stretch(-1); | ||
291 | //gl_rect_2d( rect, mThumbCenterColor % 0.3f ); | ||
292 | 358 | ||
293 | //// Thumb | ||
294 | //gl_rect_2d( mThumbRect, mThumbOutlineColor ); | ||
295 | } | 359 | } |
296 | else | 360 | else |
297 | { | 361 | { |
@@ -301,22 +365,12 @@ void LLSlider::draw() | |||
301 | LLRect highlight_rect = mThumbRect; | 365 | LLRect highlight_rect = mThumbRect; |
302 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); | 366 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); |
303 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), highlight_rect.getHeight(), | 367 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), highlight_rect.getHeight(), |
304 | thumb_imagep, gFocusMgr.getFocusColor()); | 368 | thumb_imagep, gFocusMgr.getFocusColor()); |
305 | } | 369 | } |
306 | 370 | ||
307 | gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), | 371 | gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), |
308 | thumb_imagep, mThumbCenterColor % opacity, TRUE); | 372 | thumb_imagep, center_color, TRUE); |
309 | //rect = mThumbRect; | ||
310 | |||
311 | //gl_rect_2d( mThumbRect, mThumbOutlineColor % opacity ); | ||
312 | // | ||
313 | //rect.stretch(-1); | ||
314 | |||
315 | //// Thumb | ||
316 | //gl_rect_2d( rect, mThumbCenterColor % opacity ); | ||
317 | |||
318 | } | 373 | } |
319 | |||
320 | LLUICtrl::draw(); | 374 | LLUICtrl::draw(); |
321 | } | 375 | } |
322 | } | 376 | } |
@@ -330,6 +384,7 @@ LLXMLNodePtr LLSlider::getXML(bool save_children) const | |||
330 | node->createChild("min_val", TRUE)->setFloatValue(getMinValue()); | 384 | node->createChild("min_val", TRUE)->setFloatValue(getMinValue()); |
331 | node->createChild("max_val", TRUE)->setFloatValue(getMaxValue()); | 385 | node->createChild("max_val", TRUE)->setFloatValue(getMaxValue()); |
332 | node->createChild("increment", TRUE)->setFloatValue(getIncrement()); | 386 | node->createChild("increment", TRUE)->setFloatValue(getIncrement()); |
387 | node->createChild("volume", TRUE)->setBoolValue(getVolumeSlider()); | ||
333 | 388 | ||
334 | return node; | 389 | return node; |
335 | } | 390 | } |
@@ -356,6 +411,8 @@ LLView* LLSlider::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *fa | |||
356 | F32 increment = 0.1f; | 411 | F32 increment = 0.1f; |
357 | node->getAttributeF32("increment", increment); | 412 | node->getAttributeF32("increment", increment); |
358 | 413 | ||
414 | BOOL volume = node->hasName("volume_slider") ? TRUE : FALSE; | ||
415 | node->getAttributeBOOL("volume", volume); | ||
359 | 416 | ||
360 | LLSlider* slider = new LLSlider(name, | 417 | LLSlider* slider = new LLSlider(name, |
361 | rect, | 418 | rect, |
@@ -364,7 +421,8 @@ LLView* LLSlider::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *fa | |||
364 | initial_value, | 421 | initial_value, |
365 | min_value, | 422 | min_value, |
366 | max_value, | 423 | max_value, |
367 | increment); | 424 | increment, |
425 | volume); | ||
368 | 426 | ||
369 | slider->initFromXML(node, parent); | 427 | slider->initFromXML(node, parent); |
370 | 428 | ||