diff options
author | Jacek Antonelli | 2008-08-15 23:45:27 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:27 -0500 |
commit | a8a62201ba762e98dff92cf49033e577fc34d8d4 (patch) | |
tree | 11f8513c5cdc222f2fac0c93eb724c089803c200 /linden/indra/llui/llslider.cpp | |
parent | Second Life viewer sources 1.18.6.4-RC (diff) | |
download | meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.zip meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.gz meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.bz2 meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.xz |
Second Life viewer sources 1.19.0.0
Diffstat (limited to 'linden/indra/llui/llslider.cpp')
-rw-r--r-- | linden/indra/llui/llslider.cpp | 149 |
1 files changed, 48 insertions, 101 deletions
diff --git a/linden/indra/llui/llslider.cpp b/linden/indra/llui/llslider.cpp index 606a8a1..e03603d 100644 --- a/linden/indra/llui/llslider.cpp +++ b/linden/indra/llui/llslider.cpp | |||
@@ -12,12 +12,12 @@ | |||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | 12 | * ("GPL"), unless you have obtained a separate licensing agreement |
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | 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 | 14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or |
15 | * online at http://secondlife.com/developers/opensource/gplv2 | 15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 |
16 | * | 16 | * |
17 | * There are special exceptions to the terms and conditions of the GPL as | 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 | 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 | 19 | * in the file doc/FLOSS-exception.txt in this software distribution, or |
20 | * online at http://secondlife.com/developers/opensource/flossexception | 20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception |
21 | * | 21 | * |
22 | * By copying, modifying or distributing this software, you acknowledge | 22 | * By copying, modifying or distributing this software, you acknowledge |
23 | * that you have read and understood your obligations described above, | 23 | * that you have read and understood your obligations described above, |
@@ -41,9 +41,6 @@ | |||
41 | #include "llcontrol.h" | 41 | #include "llcontrol.h" |
42 | #include "llimagegl.h" | 42 | #include "llimagegl.h" |
43 | 43 | ||
44 | const S32 THUMB_WIDTH = 8; | ||
45 | const S32 TRACK_HEIGHT = 6; | ||
46 | |||
47 | LLSlider::LLSlider( | 44 | LLSlider::LLSlider( |
48 | const LLString& name, | 45 | const LLString& name, |
49 | const LLRect& rect, | 46 | const LLRect& rect, |
@@ -65,20 +62,24 @@ LLSlider::LLSlider( | |||
65 | mIncrement( increment ), | 62 | mIncrement( increment ), |
66 | mVolumeSlider( volume ), | 63 | mVolumeSlider( volume ), |
67 | mMouseOffset( 0 ), | 64 | mMouseOffset( 0 ), |
68 | mDragStartThumbRect( 0, mRect.getHeight(), THUMB_WIDTH, 0 ), | ||
69 | mThumbRect( 0, mRect.getHeight(), THUMB_WIDTH, 0 ), | ||
70 | mTrackColor( LLUI::sColorsGroup->getColor( "SliderTrackColor" ) ), | 65 | mTrackColor( LLUI::sColorsGroup->getColor( "SliderTrackColor" ) ), |
71 | mThumbOutlineColor( LLUI::sColorsGroup->getColor( "SliderThumbOutlineColor" ) ), | 66 | mThumbOutlineColor( LLUI::sColorsGroup->getColor( "SliderThumbOutlineColor" ) ), |
72 | mThumbCenterColor( LLUI::sColorsGroup->getColor( "SliderThumbCenterColor" ) ), | 67 | mThumbCenterColor( LLUI::sColorsGroup->getColor( "SliderThumbCenterColor" ) ), |
73 | mDisabledThumbColor(LLUI::sColorsGroup->getColor( "SliderDisabledThumbColor" ) ), | ||
74 | mMouseDownCallback( NULL ), | 68 | mMouseDownCallback( NULL ), |
75 | mMouseUpCallback( NULL ) | 69 | mMouseUpCallback( NULL ) |
76 | { | 70 | { |
71 | mThumbImage = LLUI::sImageProvider->getImageByID(LLUUID(LLUI::sAssetsGroup->getString("icn_slide-thumb_dark.tga"))); | ||
72 | mTrackImage = LLUI::sImageProvider->getImageByID(LLUUID(LLUI::sAssetsGroup->getString("icn_slide-groove_dark.tga"))); | ||
73 | mTrackHighlightImage = LLUI::sImageProvider->getImageByID(LLUUID(LLUI::sAssetsGroup->getString("icn_slide-highlight.tga"))); | ||
74 | |||
77 | // properly handle setting the starting thumb rect | 75 | // properly handle setting the starting thumb rect |
78 | // do it this way to handle both the operating-on-settings | 76 | // do it this way to handle both the operating-on-settings |
79 | // and standalone ways of using this | 77 | // and standalone ways of using this |
80 | setControlName(control_name, NULL); | 78 | setControlName(control_name, NULL); |
81 | setValue(getValueF32()); | 79 | setValue(getValueF32()); |
80 | |||
81 | updateThumbRect(); | ||
82 | mDragStartThumbRect = mThumbRect; | ||
82 | } | 83 | } |
83 | 84 | ||
84 | EWidgetType LLSlider::getWidgetType() const | 85 | EWidgetType LLSlider::getWidgetType() const |
@@ -107,17 +108,26 @@ void LLSlider::setValue(F32 value, BOOL from_event) | |||
107 | } | 108 | } |
108 | 109 | ||
109 | mValue = value; | 110 | mValue = value; |
111 | updateThumbRect(); | ||
112 | } | ||
110 | 113 | ||
114 | void LLSlider::updateThumbRect() | ||
115 | { | ||
111 | F32 t = (mValue - mMinValue) / (mMaxValue - mMinValue); | 116 | F32 t = (mValue - mMinValue) / (mMaxValue - mMinValue); |
112 | 117 | ||
113 | S32 left_edge = THUMB_WIDTH/2; | 118 | S32 thumb_width = mThumbImage->getWidth(); |
114 | S32 right_edge = mRect.getWidth() - (THUMB_WIDTH/2); | 119 | S32 thumb_height = mThumbImage->getHeight(); |
120 | S32 left_edge = (thumb_width / 2); | ||
121 | S32 right_edge = mRect.getWidth() - (thumb_width / 2); | ||
115 | 122 | ||
116 | S32 x = left_edge + S32( t * (right_edge - left_edge) ); | 123 | S32 x = left_edge + S32( t * (right_edge - left_edge) ); |
117 | mThumbRect.mLeft = x - (THUMB_WIDTH/2); | 124 | mThumbRect.mLeft = x - (thumb_width / 2); |
118 | mThumbRect.mRight = x + (THUMB_WIDTH/2); | 125 | mThumbRect.mRight = mThumbRect.mLeft + thumb_width; |
126 | mThumbRect.mBottom = getLocalRect().getCenterY() - (thumb_height / 2); | ||
127 | mThumbRect.mTop = mThumbRect.mBottom + thumb_height; | ||
119 | } | 128 | } |
120 | 129 | ||
130 | |||
121 | void LLSlider::setValueAndCommit(F32 value) | 131 | void LLSlider::setValueAndCommit(F32 value) |
122 | { | 132 | { |
123 | F32 old_value = mValue; | 133 | F32 old_value = mValue; |
@@ -139,8 +149,9 @@ BOOL LLSlider::handleHover(S32 x, S32 y, MASK mask) | |||
139 | { | 149 | { |
140 | if( hasMouseCapture() ) | 150 | if( hasMouseCapture() ) |
141 | { | 151 | { |
142 | S32 left_edge = THUMB_WIDTH/2; | 152 | S32 thumb_half_width = mThumbImage->getWidth()/2; |
143 | S32 right_edge = mRect.getWidth() - (THUMB_WIDTH/2); | 153 | S32 left_edge = thumb_half_width; |
154 | S32 right_edge = mRect.getWidth() - (thumb_half_width); | ||
144 | 155 | ||
145 | x += mMouseOffset; | 156 | x += mMouseOffset; |
146 | x = llclamp( x, left_edge, right_edge ); | 157 | x = llclamp( x, left_edge, right_edge ); |
@@ -203,7 +214,7 @@ BOOL LLSlider::handleMouseDown(S32 x, S32 y, MASK mask) | |||
203 | // Find the offset of the actual mouse location from the center of the thumb. | 214 | // Find the offset of the actual mouse location from the center of the thumb. |
204 | if (mThumbRect.pointInRect(x,y)) | 215 | if (mThumbRect.pointInRect(x,y)) |
205 | { | 216 | { |
206 | mMouseOffset = (mThumbRect.mLeft + THUMB_WIDTH/2) - x; | 217 | mMouseOffset = (mThumbRect.mLeft + mThumbImage->getWidth()/2) - x; |
207 | } | 218 | } |
208 | else | 219 | else |
209 | { | 220 | { |
@@ -251,6 +262,9 @@ void LLSlider::draw() | |||
251 | { | 262 | { |
252 | if( getVisible() ) | 263 | if( getVisible() ) |
253 | { | 264 | { |
265 | // since thumb image might still be decoding, need thumb to accomodate image size | ||
266 | updateThumbRect(); | ||
267 | |||
254 | // Draw background and thumb. | 268 | // Draw background and thumb. |
255 | 269 | ||
256 | // drawing solids requires texturing be disabled | 270 | // drawing solids requires texturing be disabled |
@@ -260,104 +274,37 @@ void LLSlider::draw() | |||
260 | 274 | ||
261 | F32 opacity = mEnabled ? 1.f : 0.3f; | 275 | F32 opacity = mEnabled ? 1.f : 0.3f; |
262 | LLColor4 center_color = (mThumbCenterColor % opacity); | 276 | LLColor4 center_color = (mThumbCenterColor % opacity); |
263 | LLColor4 outline_color = (mThumbOutlineColor % opacity); | ||
264 | LLColor4 track_color = (mTrackColor % opacity); | 277 | LLColor4 track_color = (mTrackColor % opacity); |
265 | 278 | ||
266 | LLImageGL* thumb_imagep = NULL; | ||
267 | |||
268 | // Track | 279 | // Track |
269 | if (mVolumeSlider) | 280 | LLRect track_rect(mThumbImage->getWidth() / 2, |
270 | { | 281 | getLocalRect().getCenterY() + (mTrackImage->getHeight() / 2), |
271 | LLRect track(0, mRect.getHeight(), mRect.getWidth(), 0); | 282 | mRect.getWidth() - mThumbImage->getWidth() / 2, |
272 | 283 | getLocalRect().getCenterY() - (mTrackImage->getHeight() / 2) ); | |
273 | track.mBottom += 3; | ||
274 | track.mTop -= 1; | ||
275 | track.mRight -= 1; | ||
276 | |||
277 | gl_triangle_2d(track.mLeft, track.mBottom, | ||
278 | track.mRight, track.mBottom, | ||
279 | track.mRight, track.mTop, | ||
280 | center_color, | ||
281 | TRUE); | ||
282 | gl_triangle_2d(track.mLeft, track.mBottom, | ||
283 | track.mRight, track.mBottom, | ||
284 | track.mRight, track.mTop, | ||
285 | outline_color, | ||
286 | FALSE); | ||
287 | } | ||
288 | else | ||
289 | { | ||
290 | LLUUID thumb_image_id; | ||
291 | thumb_image_id.set(LLUI::sAssetsGroup->getString("rounded_square.tga")); | ||
292 | thumb_imagep = LLUI::sImageProvider->getUIImageByID(thumb_image_id); | ||
293 | 284 | ||
294 | S32 height_offset = (mRect.getHeight() - TRACK_HEIGHT) / 2; | 285 | gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 3, 3, track_rect.getWidth(), track_rect.getHeight(), |
295 | LLRect track_rect(0, mRect.getHeight() - height_offset, mRect.getWidth(), height_offset ); | 286 | mTrackImage, track_color); |
287 | gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 3, 3, mThumbRect.mLeft, track_rect.getHeight(), | ||
288 | mTrackHighlightImage, track_color); | ||
296 | 289 | ||
297 | track_rect.stretch(-1); | ||
298 | gl_draw_scaled_image_with_border(track_rect.mLeft, track_rect.mBottom, 16, 16, track_rect.getWidth(), track_rect.getHeight(), | ||
299 | thumb_imagep, track_color); | ||
300 | } | ||
301 | 290 | ||
302 | // Thumb | 291 | // Thumb |
303 | if (!thumb_imagep) | 292 | if( hasMouseCapture() ) |
304 | { | ||
305 | if (mVolumeSlider) | ||
306 | { | ||
307 | if (hasMouseCapture()) | ||
308 | { | ||
309 | LLRect rect(mDragStartThumbRect); | ||
310 | gl_rect_2d( rect, outline_color ); | ||
311 | rect.stretch(-1); | ||
312 | gl_rect_2d( rect, mThumbCenterColor % 0.3f ); | ||
313 | |||
314 | if (hasFocus()) | ||
315 | { | ||
316 | LLRect thumb_rect = mThumbRect; | ||
317 | thumb_rect.stretch(llround(lerp(1.f, 3.f, gFocusMgr.getFocusFlashAmt()))); | ||
318 | gl_rect_2d(thumb_rect, gFocusMgr.getFocusColor()); | ||
319 | } | ||
320 | gl_rect_2d( mThumbRect, mThumbOutlineColor ); | ||
321 | } | ||
322 | else | ||
323 | { | ||
324 | if (hasFocus()) | ||
325 | { | ||
326 | LLRect thumb_rect = mThumbRect; | ||
327 | thumb_rect.stretch(llround(lerp(1.f, 3.f, gFocusMgr.getFocusFlashAmt()))); | ||
328 | gl_rect_2d(thumb_rect, gFocusMgr.getFocusColor()); | ||
329 | } | ||
330 | LLRect rect(mThumbRect); | ||
331 | gl_rect_2d(rect, outline_color); | ||
332 | rect.stretch(-1); | ||
333 | gl_rect_2d( rect, center_color); | ||
334 | } | ||
335 | } | ||
336 | else | ||
337 | { | ||
338 | gl_rect_2d(mThumbRect, mThumbCenterColor, TRUE); | ||
339 | if (hasMouseCapture()) | ||
340 | { | ||
341 | gl_rect_2d(mDragStartThumbRect, center_color, FALSE); | ||
342 | } | ||
343 | } | ||
344 | } | ||
345 | else if( hasMouseCapture() ) | ||
346 | { | 293 | { |
347 | gl_draw_scaled_image_with_border(mDragStartThumbRect.mLeft, mDragStartThumbRect.mBottom, 16, 16, mDragStartThumbRect.getWidth(), mDragStartThumbRect.getHeight(), | 294 | gl_draw_scaled_image(mDragStartThumbRect.mLeft, mDragStartThumbRect.mBottom, mDragStartThumbRect.getWidth(), mDragStartThumbRect.getHeight(), |
348 | thumb_imagep, mThumbCenterColor % 0.3f, TRUE); | 295 | mThumbImage, mThumbCenterColor % 0.3f); |
349 | 296 | ||
350 | if (hasFocus()) | 297 | if (hasFocus()) |
351 | { | 298 | { |
352 | F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); | 299 | F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); |
353 | LLRect highlight_rect = mThumbRect; | 300 | LLRect highlight_rect = mThumbRect; |
354 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); | 301 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); |
355 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), highlight_rect.getHeight(), | 302 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 0, 0, highlight_rect.getWidth(), highlight_rect.getHeight(), |
356 | thumb_imagep, gFocusMgr.getFocusColor()); | 303 | mThumbImage, gFocusMgr.getFocusColor(), TRUE); |
357 | } | 304 | } |
358 | 305 | ||
359 | gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), | 306 | gl_draw_scaled_image(mThumbRect.mLeft, mThumbRect.mBottom, mThumbRect.getWidth(), mThumbRect.getHeight(), |
360 | thumb_imagep, mThumbOutlineColor, TRUE); | 307 | mThumbImage, mThumbOutlineColor); |
361 | 308 | ||
362 | } | 309 | } |
363 | else | 310 | else |
@@ -367,12 +314,12 @@ void LLSlider::draw() | |||
367 | F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); | 314 | F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); |
368 | LLRect highlight_rect = mThumbRect; | 315 | LLRect highlight_rect = mThumbRect; |
369 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); | 316 | highlight_rect.stretch(llround(lerp(1.f, 3.f, lerp_amt))); |
370 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 16, 16, highlight_rect.getWidth(), highlight_rect.getHeight(), | 317 | gl_draw_scaled_image_with_border(highlight_rect.mLeft, highlight_rect.mBottom, 0, 0, highlight_rect.getWidth(), highlight_rect.getHeight(), |
371 | thumb_imagep, gFocusMgr.getFocusColor()); | 318 | mThumbImage, gFocusMgr.getFocusColor(), TRUE); |
372 | } | 319 | } |
373 | 320 | ||
374 | gl_draw_scaled_image_with_border(mThumbRect.mLeft, mThumbRect.mBottom, 16, 16, mThumbRect.getWidth(), mThumbRect.getHeight(), | 321 | gl_draw_scaled_image(mThumbRect.mLeft, mThumbRect.mBottom, mThumbRect.getWidth(), mThumbRect.getHeight(), |
375 | thumb_imagep, center_color, TRUE); | 322 | mThumbImage, center_color); |
376 | } | 323 | } |
377 | LLUICtrl::draw(); | 324 | LLUICtrl::draw(); |
378 | } | 325 | } |