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/llbutton.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/llbutton.cpp')
-rw-r--r-- | linden/indra/llui/llbutton.cpp | 281 |
1 files changed, 144 insertions, 137 deletions
diff --git a/linden/indra/llui/llbutton.cpp b/linden/indra/llui/llbutton.cpp index 71260b2..9fa1c8e 100644 --- a/linden/indra/llui/llbutton.cpp +++ b/linden/indra/llui/llbutton.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, |
@@ -59,9 +59,6 @@ S32 BTN_HEIGHT = 0; | |||
59 | S32 BTN_GRID = 12; | 59 | S32 BTN_GRID = 12; |
60 | S32 BORDER_SIZE = 1; | 60 | S32 BORDER_SIZE = 1; |
61 | 61 | ||
62 | // static | ||
63 | LLFrameTimer LLButton::sFlashingTimer; | ||
64 | |||
65 | LLButton::LLButton( const LLString& name, const LLRect& rect, const LLString& control_name, void (*click_callback)(void*), void *callback_data) | 62 | LLButton::LLButton( const LLString& name, const LLRect& rect, const LLString& control_name, void (*click_callback)(void*), void *callback_data) |
66 | : LLUICtrl(name, rect, TRUE, NULL, NULL), | 63 | : LLUICtrl(name, rect, TRUE, NULL, NULL), |
67 | mClickedCallback( click_callback ), | 64 | mClickedCallback( click_callback ), |
@@ -79,6 +76,7 @@ LLButton::LLButton( const LLString& name, const LLRect& rect, const LLString& co | |||
79 | mImageDisabled( NULL ), | 76 | mImageDisabled( NULL ), |
80 | mImageDisabledSelected( NULL ), | 77 | mImageDisabledSelected( NULL ), |
81 | mToggleState( FALSE ), | 78 | mToggleState( FALSE ), |
79 | mIsToggle( FALSE ), | ||
82 | mScaleImage( TRUE ), | 80 | mScaleImage( TRUE ), |
83 | mDropShadowedText( TRUE ), | 81 | mDropShadowedText( TRUE ), |
84 | mBorderEnabled( FALSE ), | 82 | mBorderEnabled( FALSE ), |
@@ -86,8 +84,6 @@ LLButton::LLButton( const LLString& name, const LLRect& rect, const LLString& co | |||
86 | mHAlign( LLFontGL::HCENTER ), | 84 | mHAlign( LLFontGL::HCENTER ), |
87 | mLeftHPad( LLBUTTON_H_PAD ), | 85 | mLeftHPad( LLBUTTON_H_PAD ), |
88 | mRightHPad( LLBUTTON_H_PAD ), | 86 | mRightHPad( LLBUTTON_H_PAD ), |
89 | mFixedWidth( 16 ), | ||
90 | mFixedHeight( 16 ), | ||
91 | mHoverGlowStrength(0.15f), | 87 | mHoverGlowStrength(0.15f), |
92 | mCurGlowStrength(0.f), | 88 | mCurGlowStrength(0.f), |
93 | mNeedsHighlight(FALSE), | 89 | mNeedsHighlight(FALSE), |
@@ -134,6 +130,7 @@ LLButton::LLButton(const LLString& name, const LLRect& rect, | |||
134 | mImageDisabled( NULL ), | 130 | mImageDisabled( NULL ), |
135 | mImageDisabledSelected( NULL ), | 131 | mImageDisabledSelected( NULL ), |
136 | mToggleState( FALSE ), | 132 | mToggleState( FALSE ), |
133 | mIsToggle( FALSE ), | ||
137 | mScaleImage( TRUE ), | 134 | mScaleImage( TRUE ), |
138 | mDropShadowedText( TRUE ), | 135 | mDropShadowedText( TRUE ), |
139 | mBorderEnabled( FALSE ), | 136 | mBorderEnabled( FALSE ), |
@@ -141,8 +138,6 @@ LLButton::LLButton(const LLString& name, const LLRect& rect, | |||
141 | mHAlign( LLFontGL::HCENTER ), | 138 | mHAlign( LLFontGL::HCENTER ), |
142 | mLeftHPad( LLBUTTON_H_PAD ), | 139 | mLeftHPad( LLBUTTON_H_PAD ), |
143 | mRightHPad( LLBUTTON_H_PAD ), | 140 | mRightHPad( LLBUTTON_H_PAD ), |
144 | mFixedWidth( 16 ), | ||
145 | mFixedHeight( 16 ), | ||
146 | mHoverGlowStrength(0.25f), | 141 | mHoverGlowStrength(0.25f), |
147 | mCurGlowStrength(0.f), | 142 | mCurGlowStrength(0.f), |
148 | mNeedsHighlight(FALSE), | 143 | mNeedsHighlight(FALSE), |
@@ -158,15 +153,11 @@ LLButton::LLButton(const LLString& name, const LLRect& rect, | |||
158 | 153 | ||
159 | if( unselected_image_name != "" ) | 154 | if( unselected_image_name != "" ) |
160 | { | 155 | { |
156 | // user-specified image - don't use fixed borders unless requested | ||
161 | setImageUnselected(unselected_image_name); | 157 | setImageUnselected(unselected_image_name); |
162 | setImageDisabled(unselected_image_name); | 158 | setImageDisabled(unselected_image_name); |
163 | 159 | ||
164 | mDisabledImageColor.mV[VALPHA] = 0.5f; | 160 | mDisabledImageColor.mV[VALPHA] = 0.5f; |
165 | mImageDisabled = mImageUnselected; | ||
166 | mDisabledImageColor.mV[VALPHA] = 0.5f; | ||
167 | // user-specified image - don't use fixed borders unless requested | ||
168 | mFixedWidth = 0; | ||
169 | mFixedHeight = 0; | ||
170 | mScaleImage = FALSE; | 161 | mScaleImage = FALSE; |
171 | } | 162 | } |
172 | else | 163 | else |
@@ -177,13 +168,11 @@ LLButton::LLButton(const LLString& name, const LLRect& rect, | |||
177 | 168 | ||
178 | if( selected_image_name != "" ) | 169 | if( selected_image_name != "" ) |
179 | { | 170 | { |
171 | // user-specified image - don't use fixed borders unless requested | ||
180 | setImageSelected(selected_image_name); | 172 | setImageSelected(selected_image_name); |
181 | setImageDisabledSelected(selected_image_name); | 173 | setImageDisabledSelected(selected_image_name); |
182 | 174 | ||
183 | mDisabledImageColor.mV[VALPHA] = 0.5f; | 175 | mDisabledImageColor.mV[VALPHA] = 0.5f; |
184 | // user-specified image - don't use fixed borders unless requested | ||
185 | mFixedWidth = 0; | ||
186 | mFixedHeight = 0; | ||
187 | mScaleImage = FALSE; | 176 | mScaleImage = FALSE; |
188 | } | 177 | } |
189 | else | 178 | else |
@@ -273,6 +262,12 @@ void LLButton::onCommit() | |||
273 | make_ui_sound("UISndClickRelease"); | 262 | make_ui_sound("UISndClickRelease"); |
274 | } | 263 | } |
275 | 264 | ||
265 | if (mIsToggle) | ||
266 | { | ||
267 | toggleState(); | ||
268 | } | ||
269 | |||
270 | // do this last, as it can result in destroying this button | ||
276 | if (mClickedCallback) | 271 | if (mClickedCallback) |
277 | { | 272 | { |
278 | (*mClickedCallback)( mCallbackUserData ); | 273 | (*mClickedCallback)( mCallbackUserData ); |
@@ -286,6 +281,11 @@ BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) | |||
286 | BOOL handled = FALSE; | 281 | BOOL handled = FALSE; |
287 | if( getVisible() && mEnabled && !called_from_parent && ' ' == uni_char && !gKeyboard->getKeyRepeated(' ')) | 282 | if( getVisible() && mEnabled && !called_from_parent && ' ' == uni_char && !gKeyboard->getKeyRepeated(' ')) |
288 | { | 283 | { |
284 | if (mIsToggle) | ||
285 | { | ||
286 | toggleState(); | ||
287 | } | ||
288 | |||
289 | if (mClickedCallback) | 289 | if (mClickedCallback) |
290 | { | 290 | { |
291 | (*mClickedCallback)( mCallbackUserData ); | 291 | (*mClickedCallback)( mCallbackUserData ); |
@@ -302,11 +302,17 @@ BOOL LLButton::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) | |||
302 | { | 302 | { |
303 | if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) | 303 | if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) |
304 | { | 304 | { |
305 | if (mIsToggle) | ||
306 | { | ||
307 | toggleState(); | ||
308 | } | ||
309 | |||
310 | handled = TRUE; | ||
311 | |||
305 | if (mClickedCallback) | 312 | if (mClickedCallback) |
306 | { | 313 | { |
307 | (*mClickedCallback)( mCallbackUserData ); | 314 | (*mClickedCallback)( mCallbackUserData ); |
308 | } | 315 | } |
309 | handled = TRUE; | ||
310 | } | 316 | } |
311 | } | 317 | } |
312 | return handled; | 318 | return handled; |
@@ -354,6 +360,9 @@ BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask) | |||
354 | (*mMouseUpCallback)(mCallbackUserData); | 360 | (*mMouseUpCallback)(mCallbackUserData); |
355 | } | 361 | } |
356 | 362 | ||
363 | mMouseDownTimer.stop(); | ||
364 | mMouseDownTimer.reset(); | ||
365 | |||
357 | // DO THIS AT THE VERY END to allow the button to be destroyed as a result of being clicked. | 366 | // DO THIS AT THE VERY END to allow the button to be destroyed as a result of being clicked. |
358 | // If mouseup in the widget, it's been clicked | 367 | // If mouseup in the widget, it's been clicked |
359 | if (pointInView(x, y)) | 368 | if (pointInView(x, y)) |
@@ -363,6 +372,11 @@ BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask) | |||
363 | make_ui_sound("UISndClickRelease"); | 372 | make_ui_sound("UISndClickRelease"); |
364 | } | 373 | } |
365 | 374 | ||
375 | if (mIsToggle) | ||
376 | { | ||
377 | toggleState(); | ||
378 | } | ||
379 | |||
366 | if (mClickedCallback) | 380 | if (mClickedCallback) |
367 | { | 381 | { |
368 | (*mClickedCallback)( mCallbackUserData ); | 382 | (*mClickedCallback)( mCallbackUserData ); |
@@ -422,8 +436,10 @@ void LLButton::draw() | |||
422 | BOOL flash = FALSE; | 436 | BOOL flash = FALSE; |
423 | if( mFlashing ) | 437 | if( mFlashing ) |
424 | { | 438 | { |
425 | F32 elapsed = LLButton::sFlashingTimer.getElapsedTimeF32(); | 439 | F32 elapsed = mFlashingTimer.getElapsedTimeF32(); |
426 | flash = S32(elapsed * 2) & 1; | 440 | S32 flash_count = S32(elapsed * LLUI::sConfigGroup->getF32("ButtonFlashRate") * 2.f); |
441 | // flash on or off? | ||
442 | flash = (flash_count % 2 == 0) || flash_count > (F32)LLUI::sConfigGroup->getS32("ButtonFlashCount"); | ||
427 | } | 443 | } |
428 | 444 | ||
429 | BOOL pressed_by_keyboard = FALSE; | 445 | BOOL pressed_by_keyboard = FALSE; |
@@ -443,24 +459,14 @@ void LLButton::draw() | |||
443 | cursor_pos_gl.mY = llround((F32)cursor_pos_gl.mY / LLUI::sGLScaleFactor.mV[VY]); | 459 | cursor_pos_gl.mY = llround((F32)cursor_pos_gl.mY / LLUI::sGLScaleFactor.mV[VY]); |
444 | screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); | 460 | screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); |
445 | 461 | ||
446 | BOOL pressed = pressed_by_keyboard || (hasMouseCapture() && pointInView(local_mouse_x, local_mouse_y)); | 462 | BOOL pressed = pressed_by_keyboard |
447 | 463 | || (hasMouseCapture() && pointInView(local_mouse_x, local_mouse_y)) | |
448 | BOOL display_state = FALSE; | 464 | || mToggleState; |
449 | if( pressed ) | ||
450 | { | ||
451 | mImagep = mImageSelected; | ||
452 | // show the resulting state after releasing the mouse button while it is down | ||
453 | display_state = mToggleState ? FALSE : TRUE; | ||
454 | } | ||
455 | else | ||
456 | { | ||
457 | display_state = mToggleState || flash; | ||
458 | } | ||
459 | 465 | ||
460 | BOOL use_glow_effect = FALSE; | 466 | BOOL use_glow_effect = FALSE; |
461 | if ( mNeedsHighlight ) | 467 | if ( mNeedsHighlight || flash ) |
462 | { | 468 | { |
463 | if (display_state) | 469 | if (pressed) |
464 | { | 470 | { |
465 | if (mImageHoverSelected) | 471 | if (mImageHoverSelected) |
466 | { | 472 | { |
@@ -485,7 +491,7 @@ void LLButton::draw() | |||
485 | } | 491 | } |
486 | } | 492 | } |
487 | } | 493 | } |
488 | else if ( display_state ) | 494 | else if ( pressed ) |
489 | { | 495 | { |
490 | mImagep = mImageSelected; | 496 | mImagep = mImageSelected; |
491 | } | 497 | } |
@@ -499,11 +505,11 @@ void LLButton::draw() | |||
499 | // enabled and tentative | 505 | // enabled and tentative |
500 | // or | 506 | // or |
501 | // disabled but checked | 507 | // disabled but checked |
502 | if (!mImageDisabledSelected.isNull() && ( (mEnabled && mTentative) || (!mEnabled && display_state ) ) ) | 508 | if (!mImageDisabledSelected.isNull() && ( (mEnabled && mTentative) || (!mEnabled && pressed ) ) ) |
503 | { | 509 | { |
504 | mImagep = mImageDisabledSelected; | 510 | mImagep = mImageDisabledSelected; |
505 | } | 511 | } |
506 | else if (!mImageDisabled.isNull() && !mEnabled && !display_state) | 512 | else if (!mImageDisabled.isNull() && !mEnabled && !pressed) |
507 | { | 513 | { |
508 | mImagep = mImageDisabled; | 514 | mImagep = mImageDisabled; |
509 | } | 515 | } |
@@ -516,33 +522,34 @@ void LLButton::draw() | |||
516 | // Figure out appropriate color for the text | 522 | // Figure out appropriate color for the text |
517 | LLColor4 label_color; | 523 | LLColor4 label_color; |
518 | 524 | ||
525 | // label changes when button state changes, not when pressed | ||
519 | if ( mEnabled ) | 526 | if ( mEnabled ) |
520 | { | 527 | { |
521 | if ( !display_state ) | 528 | if ( mToggleState ) |
522 | { | 529 | { |
523 | label_color = mUnselectedLabelColor; | 530 | label_color = mSelectedLabelColor; |
524 | } | 531 | } |
525 | else | 532 | else |
526 | { | 533 | { |
527 | label_color = mSelectedLabelColor; | 534 | label_color = mUnselectedLabelColor; |
528 | } | 535 | } |
529 | } | 536 | } |
530 | else | 537 | else |
531 | { | 538 | { |
532 | if ( !display_state ) | 539 | if ( mToggleState ) |
533 | { | 540 | { |
534 | label_color = mDisabledLabelColor; | 541 | label_color = mDisabledSelectedLabelColor; |
535 | } | 542 | } |
536 | else | 543 | else |
537 | { | 544 | { |
538 | label_color = mDisabledSelectedLabelColor; | 545 | label_color = mDisabledLabelColor; |
539 | } | 546 | } |
540 | } | 547 | } |
541 | 548 | ||
542 | // Unselected label assignments | 549 | // Unselected label assignments |
543 | LLWString label; | 550 | LLWString label; |
544 | 551 | ||
545 | if( display_state ) | 552 | if( mToggleState ) |
546 | { | 553 | { |
547 | if( mEnabled || mDisabledSelectedLabel.empty() ) | 554 | if( mEnabled || mDisabledSelectedLabel.empty() ) |
548 | { | 555 | { |
@@ -591,24 +598,22 @@ void LLButton::draw() | |||
591 | // Otherwise draw basic rectangular button. | 598 | // Otherwise draw basic rectangular button. |
592 | if( mImagep.notNull() && !mScaleImage) | 599 | if( mImagep.notNull() && !mScaleImage) |
593 | { | 600 | { |
594 | gl_draw_image( 0, 0, mImagep, mEnabled ? mImageColor : mDisabledImageColor ); | 601 | mImagep->draw(0, 0, mEnabled ? mImageColor : mDisabledImageColor ); |
595 | if (mCurGlowStrength > 0.01f) | 602 | if (mCurGlowStrength > 0.01f) |
596 | { | 603 | { |
597 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); | 604 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
598 | gl_draw_scaled_image_with_border(0, 0, 0, 0, mImagep->getWidth(), mImagep->getHeight(), mImagep, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength), TRUE); | 605 | mImagep->drawSolid(0, 0, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); |
599 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 606 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
600 | } | 607 | } |
601 | } | 608 | } |
602 | else | 609 | else |
603 | if ( mImagep.notNull() && mScaleImage) | 610 | if ( mImagep.notNull() && mScaleImage) |
604 | { | 611 | { |
605 | gl_draw_scaled_image_with_border(0, 0, mFixedWidth, mFixedHeight, mRect.getWidth(), mRect.getHeight(), | 612 | mImagep->draw(0, 0, mRect.getWidth(), mRect.getHeight(), mEnabled ? mImageColor : mDisabledImageColor ); |
606 | mImagep, mEnabled ? mImageColor : mDisabledImageColor ); | ||
607 | if (mCurGlowStrength > 0.01f) | 613 | if (mCurGlowStrength > 0.01f) |
608 | { | 614 | { |
609 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); | 615 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
610 | gl_draw_scaled_image_with_border(0, 0, mFixedWidth, mFixedHeight, mRect.getWidth(), mRect.getHeight(), | 616 | mImagep->drawSolid(0, 0, mRect.getWidth(), mRect.getHeight(), LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); |
611 | mImagep, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength), TRUE); | ||
612 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 617 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
613 | } | 618 | } |
614 | } | 619 | } |
@@ -620,13 +625,17 @@ void LLButton::draw() | |||
620 | gl_rect_2d(0, mRect.getHeight(), mRect.getWidth(), 0, LLColor4::pink1, FALSE); | 625 | gl_rect_2d(0, mRect.getHeight(), mRect.getWidth(), 0, LLColor4::pink1, FALSE); |
621 | } | 626 | } |
622 | 627 | ||
628 | // let overlay image and text play well together | ||
629 | S32 text_left = mLeftHPad; | ||
630 | S32 text_right = mRect.getWidth() - mRightHPad; | ||
631 | S32 text_width = mRect.getWidth() - mLeftHPad - mRightHPad; | ||
632 | |||
623 | // draw overlay image | 633 | // draw overlay image |
624 | if (mImageOverlay.notNull()) | 634 | if (mImageOverlay.notNull()) |
625 | { | 635 | { |
626 | const S32 IMG_PAD = 5; | ||
627 | // get max width and height (discard level 0) | 636 | // get max width and height (discard level 0) |
628 | S32 overlay_width = mImageOverlay->getWidth(0); | 637 | S32 overlay_width = mImageOverlay->getWidth(); |
629 | S32 overlay_height = mImageOverlay->getHeight(0); | 638 | S32 overlay_height = mImageOverlay->getHeight(); |
630 | 639 | ||
631 | F32 scale_factor = llmin((F32)mRect.getWidth() / (F32)overlay_width, (F32)mRect.getHeight() / (F32)overlay_height, 1.f); | 640 | F32 scale_factor = llmin((F32)mRect.getWidth() / (F32)overlay_width, (F32)mRect.getHeight() / (F32)overlay_height, 1.f); |
632 | overlay_width = llround((F32)overlay_width * scale_factor); | 641 | overlay_width = llround((F32)overlay_width * scale_factor); |
@@ -635,34 +644,49 @@ void LLButton::draw() | |||
635 | S32 center_x = getLocalRect().getCenterX(); | 644 | S32 center_x = getLocalRect().getCenterX(); |
636 | S32 center_y = getLocalRect().getCenterY(); | 645 | S32 center_y = getLocalRect().getCenterY(); |
637 | 646 | ||
647 | //FUGLY HACK FOR "DEPRESSED" BUTTONS | ||
648 | if (pressed) | ||
649 | { | ||
650 | center_y--; | ||
651 | center_x++; | ||
652 | } | ||
653 | |||
654 | // fade out overlay images on disabled buttons | ||
655 | LLColor4 overlay_color = mImageOverlayColor; | ||
656 | if (!getEnabled()) | ||
657 | { | ||
658 | overlay_color.mV[VALPHA] = 0.5f; | ||
659 | } | ||
660 | |||
638 | switch(mImageOverlayAlignment) | 661 | switch(mImageOverlayAlignment) |
639 | { | 662 | { |
640 | case LLFontGL::LEFT: | 663 | case LLFontGL::LEFT: |
641 | gl_draw_scaled_image( | 664 | text_left += overlay_width + 1; |
642 | IMG_PAD, | 665 | text_width -= overlay_width + 1; |
666 | mImageOverlay->draw( | ||
667 | mLeftHPad, | ||
643 | center_y - (overlay_height / 2), | 668 | center_y - (overlay_height / 2), |
644 | overlay_width, | 669 | overlay_width, |
645 | overlay_height, | 670 | overlay_height, |
646 | mImageOverlay, | 671 | overlay_color); |
647 | mImageOverlayColor); | ||
648 | break; | 672 | break; |
649 | case LLFontGL::HCENTER: | 673 | case LLFontGL::HCENTER: |
650 | gl_draw_scaled_image( | 674 | mImageOverlay->draw( |
651 | center_x - (overlay_width / 2), | 675 | center_x - (overlay_width / 2), |
652 | center_y - (overlay_height / 2), | 676 | center_y - (overlay_height / 2), |
653 | overlay_width, | 677 | overlay_width, |
654 | overlay_height, | 678 | overlay_height, |
655 | mImageOverlay, | 679 | overlay_color); |
656 | mImageOverlayColor); | ||
657 | break; | 680 | break; |
658 | case LLFontGL::RIGHT: | 681 | case LLFontGL::RIGHT: |
659 | gl_draw_scaled_image( | 682 | text_right -= overlay_width + 1; |
660 | mRect.getWidth() - IMG_PAD - overlay_width, | 683 | text_width -= overlay_width + 1; |
684 | mImageOverlay->draw( | ||
685 | mRect.getWidth() - mRightHPad - overlay_width, | ||
661 | center_y - (overlay_height / 2), | 686 | center_y - (overlay_height / 2), |
662 | overlay_width, | 687 | overlay_width, |
663 | overlay_height, | 688 | overlay_height, |
664 | mImageOverlay, | 689 | overlay_color); |
665 | mImageOverlayColor); | ||
666 | break; | 690 | break; |
667 | default: | 691 | default: |
668 | // draw nothing | 692 | // draw nothing |
@@ -673,28 +697,26 @@ void LLButton::draw() | |||
673 | // Draw label | 697 | // Draw label |
674 | if( !label.empty() ) | 698 | if( !label.empty() ) |
675 | { | 699 | { |
676 | S32 drawable_width = mRect.getWidth() - mLeftHPad - mRightHPad; | ||
677 | |||
678 | LLWString::trim(label); | 700 | LLWString::trim(label); |
679 | 701 | ||
680 | S32 x; | 702 | S32 x; |
681 | switch( mHAlign ) | 703 | switch( mHAlign ) |
682 | { | 704 | { |
683 | case LLFontGL::RIGHT: | 705 | case LLFontGL::RIGHT: |
684 | x = mRect.getWidth() - mRightHPad; | 706 | x = text_right; |
685 | break; | 707 | break; |
686 | case LLFontGL::HCENTER: | 708 | case LLFontGL::HCENTER: |
687 | x = mRect.getWidth() / 2; | 709 | x = mRect.getWidth() / 2; |
688 | break; | 710 | break; |
689 | case LLFontGL::LEFT: | 711 | case LLFontGL::LEFT: |
690 | default: | 712 | default: |
691 | x = mLeftHPad; | 713 | x = text_left; |
692 | break; | 714 | break; |
693 | } | 715 | } |
694 | 716 | ||
695 | S32 y_offset = 2 + (mRect.getHeight() - 20)/2; | 717 | S32 y_offset = 2 + (mRect.getHeight() - 20)/2; |
696 | 718 | ||
697 | if (pressed || display_state) | 719 | if (pressed) |
698 | { | 720 | { |
699 | y_offset--; | 721 | y_offset--; |
700 | x++; | 722 | x++; |
@@ -704,7 +726,7 @@ void LLButton::draw() | |||
704 | label_color, | 726 | label_color, |
705 | mHAlign, LLFontGL::BOTTOM, | 727 | mHAlign, LLFontGL::BOTTOM, |
706 | mDropShadowedText ? LLFontGL::DROP_SHADOW_SOFT : LLFontGL::NORMAL, | 728 | mDropShadowedText ? LLFontGL::DROP_SHADOW_SOFT : LLFontGL::NORMAL, |
707 | U32_MAX, drawable_width, | 729 | U32_MAX, text_width, |
708 | NULL, FALSE, FALSE); | 730 | NULL, FALSE, FALSE); |
709 | } | 731 | } |
710 | 732 | ||
@@ -733,13 +755,11 @@ void LLButton::drawBorder(const LLColor4& color, S32 size) | |||
733 | 755 | ||
734 | if (mScaleImage) | 756 | if (mScaleImage) |
735 | { | 757 | { |
736 | gl_draw_scaled_image_with_border(left, bottom, mFixedWidth, mFixedHeight, right-left, top-bottom, | 758 | mImagep->drawSolid(left, bottom, right-left, top-bottom, color); |
737 | mImagep, color, TRUE ); | ||
738 | } | 759 | } |
739 | else | 760 | else |
740 | { | 761 | { |
741 | gl_draw_scaled_image_with_border(left, bottom, 0, 0, mImagep->getWidth() + size * 2, | 762 | mImagep->drawSolid(left, bottom, mImagep->getWidth() + size * 2, mImagep->getHeight() + size * 2, color); |
742 | mImagep->getHeight() + size * 2, mImagep, color, TRUE ); | ||
743 | } | 763 | } |
744 | } | 764 | } |
745 | 765 | ||
@@ -763,6 +783,22 @@ void LLButton::setToggleState(BOOL b) | |||
763 | } | 783 | } |
764 | } | 784 | } |
765 | 785 | ||
786 | void LLButton::setFlashing( BOOL b ) | ||
787 | { | ||
788 | if (b != mFlashing) | ||
789 | { | ||
790 | mFlashing = b; | ||
791 | mFlashingTimer.reset(); | ||
792 | } | ||
793 | } | ||
794 | |||
795 | |||
796 | BOOL LLButton::toggleState() | ||
797 | { | ||
798 | setToggleState( !mToggleState ); | ||
799 | return mToggleState; | ||
800 | } | ||
801 | |||
766 | void LLButton::setValue(const LLSD& value ) | 802 | void LLButton::setValue(const LLSD& value ) |
767 | { | 803 | { |
768 | mToggleState = value.asBoolean(); | 804 | mToggleState = value.asBoolean(); |
@@ -770,7 +806,7 @@ void LLButton::setValue(const LLSD& value ) | |||
770 | 806 | ||
771 | LLSD LLButton::getValue() const | 807 | LLSD LLButton::getValue() const |
772 | { | 808 | { |
773 | return mToggleState; | 809 | return mToggleState == TRUE; |
774 | } | 810 | } |
775 | 811 | ||
776 | void LLButton::setLabel( const LLStringExplicit& label ) | 812 | void LLButton::setLabel( const LLStringExplicit& label ) |
@@ -807,10 +843,9 @@ void LLButton::setDisabledSelectedLabel( const LLStringExplicit& label ) | |||
807 | mDisabledSelectedLabel = label; | 843 | mDisabledSelectedLabel = label; |
808 | } | 844 | } |
809 | 845 | ||
810 | void LLButton::setImageUnselectedID( const LLUUID &image_id ) | 846 | void LLButton::setImageUnselected(LLPointer<LLUIImage> image) |
811 | { | 847 | { |
812 | mImageUnselectedName = ""; | 848 | mImageUnselected = image; |
813 | mImageUnselected = LLUI::sImageProvider->getUIImageByID(image_id); | ||
814 | } | 849 | } |
815 | 850 | ||
816 | void LLButton::setImages( const LLString &image_name, const LLString &selected_name ) | 851 | void LLButton::setImages( const LLString &image_name, const LLString &selected_name ) |
@@ -820,10 +855,9 @@ void LLButton::setImages( const LLString &image_name, const LLString &selected_n | |||
820 | 855 | ||
821 | } | 856 | } |
822 | 857 | ||
823 | void LLButton::setImageSelectedID( const LLUUID &image_id ) | 858 | void LLButton::setImageSelected(LLPointer<LLUIImage> image) |
824 | { | 859 | { |
825 | mImageSelectedName = ""; | 860 | mImageSelected = image; |
826 | mImageSelected = LLUI::sImageProvider->getUIImageByID(image_id); | ||
827 | } | 861 | } |
828 | 862 | ||
829 | void LLButton::setImageColor(const LLColor4& c) | 863 | void LLButton::setImageColor(const LLColor4& c) |
@@ -831,19 +865,22 @@ void LLButton::setImageColor(const LLColor4& c) | |||
831 | mImageColor = c; | 865 | mImageColor = c; |
832 | } | 866 | } |
833 | 867 | ||
868 | void LLButton::setColor(const LLColor4& color) | ||
869 | { | ||
870 | setImageColor(color); | ||
871 | } | ||
872 | |||
834 | 873 | ||
835 | void LLButton::setImageDisabledID( const LLUUID &image_id ) | 874 | void LLButton::setImageDisabled(LLPointer<LLUIImage> image) |
836 | { | 875 | { |
837 | mImageDisabledName = ""; | 876 | mImageDisabled = image; |
838 | mImageDisabled = LLUI::sImageProvider->getUIImageByID(image_id); | ||
839 | mDisabledImageColor = mImageColor; | 877 | mDisabledImageColor = mImageColor; |
840 | mDisabledImageColor.mV[VALPHA] *= 0.5f; | 878 | mDisabledImageColor.mV[VALPHA] *= 0.5f; |
841 | } | 879 | } |
842 | 880 | ||
843 | void LLButton::setImageDisabledSelectedID( const LLUUID &image_id ) | 881 | void LLButton::setImageDisabledSelected(LLPointer<LLUIImage> image) |
844 | { | 882 | { |
845 | mImageDisabledSelectedName = ""; | 883 | mImageDisabledSelected = image; |
846 | mImageDisabledSelected = LLUI::sImageProvider->getUIImageByID(image_id); | ||
847 | mDisabledImageColor = mImageColor; | 884 | mDisabledImageColor = mImageColor; |
848 | mDisabledImageColor.mV[VALPHA] *= 0.5f; | 885 | mDisabledImageColor.mV[VALPHA] *= 0.5f; |
849 | } | 886 | } |
@@ -855,11 +892,9 @@ void LLButton::setDisabledImages( const LLString &image_name, const LLString &se | |||
855 | mDisabledImageColor = c; | 892 | mDisabledImageColor = c; |
856 | } | 893 | } |
857 | 894 | ||
858 | 895 | void LLButton::setImageHoverSelected(LLPointer<LLUIImage> image) | |
859 | void LLButton::setImageHoverSelectedID( const LLUUID& image_id ) | ||
860 | { | 896 | { |
861 | mImageHoverSelectedName = ""; | 897 | mImageHoverSelected = image; |
862 | mImageHoverSelected = LLUI::sImageProvider->getUIImageByID(image_id); | ||
863 | } | 898 | } |
864 | 899 | ||
865 | void LLButton::setDisabledImages( const LLString &image_name, const LLString &selected_name) | 900 | void LLButton::setDisabledImages( const LLString &image_name, const LLString &selected_name) |
@@ -869,10 +904,9 @@ void LLButton::setDisabledImages( const LLString &image_name, const LLString &se | |||
869 | setDisabledImages( image_name, selected_name, clr ); | 904 | setDisabledImages( image_name, selected_name, clr ); |
870 | } | 905 | } |
871 | 906 | ||
872 | void LLButton::setImageHoverUnselectedID( const LLUUID& image_id ) | 907 | void LLButton::setImageHoverUnselected(LLPointer<LLUIImage> image) |
873 | { | 908 | { |
874 | mImageHoverUnselectedName = ""; | 909 | mImageHoverUnselected = image; |
875 | mImageHoverUnselected = LLUI::sImageProvider->getUIImageByID(image_id); | ||
876 | } | 910 | } |
877 | 911 | ||
878 | void LLButton::setHoverImages( const LLString& image_name, const LLString& selected_name ) | 912 | void LLButton::setHoverImages( const LLString& image_name, const LLString& selected_name ) |
@@ -889,8 +923,7 @@ void LLButton::setImageOverlay(const LLString &image_name, LLFontGL::HAlign alig | |||
889 | } | 923 | } |
890 | else | 924 | else |
891 | { | 925 | { |
892 | LLUUID overlay_image_id = LLUI::findAssetUUIDByName(image_name); | 926 | mImageOverlay = LLUI::getUIImageByName(image_name); |
893 | mImageOverlay = LLUI::sImageProvider->getUIImageByID(overlay_image_id); | ||
894 | mImageOverlayAlignment = alignment; | 927 | mImageOverlayAlignment = alignment; |
895 | mImageOverlayColor = color; | 928 | mImageOverlayColor = color; |
896 | } | 929 | } |
@@ -904,34 +937,6 @@ void LLButton::onMouseCaptureLost() | |||
904 | } | 937 | } |
905 | 938 | ||
906 | //------------------------------------------------------------------------- | 939 | //------------------------------------------------------------------------- |
907 | // LLSquareButton | ||
908 | //------------------------------------------------------------------------- | ||
909 | LLSquareButton::LLSquareButton(const LLString& name, const LLRect& rect, | ||
910 | const LLString& label, | ||
911 | const LLFontGL *font, | ||
912 | const LLString& control_name, | ||
913 | void (*click_callback)(void*), | ||
914 | void *callback_data, | ||
915 | const LLString& selected_label ) | ||
916 | : LLButton(name, rect, "","", | ||
917 | control_name, | ||
918 | click_callback, callback_data, | ||
919 | font, | ||
920 | label, | ||
921 | (selected_label.empty() ? label : selected_label) ) | ||
922 | { | ||
923 | setImageUnselected("square_btn_32x128.tga"); | ||
924 | // mImageUnselected = LLUI::sImageProvider->getUIImageByID(LLUUID(LLUI::sAssetsGroup->getString("square_btn_32x128.tga"))); | ||
925 | setImageSelected("square_btn_selected_32x128.tga"); | ||
926 | // mImageSelectedImage = LLUI::sImageProvider->getUIImageByID(LLUUID(LLUI::sAssetsGroup->getString("square_btn_selected_32x128.tga"))); | ||
927 | setImageDisabled("square_btn_32x128.tga"); | ||
928 | //mDisabledImage = LLUI::sImageProvider->getUIImageByID(LLUUID(LLUI::sAssetsGroup->getString("square_btn_32x128.tga"))); | ||
929 | setImageDisabledSelected("square_btn_selected_32x128.tga"); | ||
930 | //mDisabledSelectedImage = LLUI::sImageProvider->getUIImageByID(LLUUID(LLUI::sAssetsGroup->getString("square_btn_selected_32x128.tga"))); | ||
931 | mImageColor = LLUI::sColorsGroup->getColor("ButtonColor"); | ||
932 | } | ||
933 | |||
934 | //------------------------------------------------------------------------- | ||
935 | // Utilities | 940 | // Utilities |
936 | //------------------------------------------------------------------------- | 941 | //------------------------------------------------------------------------- |
937 | S32 round_up(S32 grid, S32 value) | 942 | S32 round_up(S32 grid, S32 value) |
@@ -951,37 +956,37 @@ S32 round_up(S32 grid, S32 value) | |||
951 | 956 | ||
952 | void LLButton::setImageUnselected(const LLString &image_name) | 957 | void LLButton::setImageUnselected(const LLString &image_name) |
953 | { | 958 | { |
954 | setImageUnselectedID(LLUI::findAssetUUIDByName(image_name)); | 959 | setImageUnselected(LLUI::getUIImageByName(image_name)); |
955 | mImageUnselectedName = image_name; | 960 | mImageUnselectedName = image_name; |
956 | } | 961 | } |
957 | 962 | ||
958 | void LLButton::setImageSelected(const LLString &image_name) | 963 | void LLButton::setImageSelected(const LLString &image_name) |
959 | { | 964 | { |
960 | setImageSelectedID(LLUI::findAssetUUIDByName(image_name)); | 965 | setImageSelected(LLUI::getUIImageByName(image_name)); |
961 | mImageSelectedName = image_name; | 966 | mImageSelectedName = image_name; |
962 | } | 967 | } |
963 | 968 | ||
964 | void LLButton::setImageHoverSelected(const LLString &image_name) | 969 | void LLButton::setImageHoverSelected(const LLString &image_name) |
965 | { | 970 | { |
966 | setImageHoverSelectedID(LLUI::findAssetUUIDByName(image_name)); | 971 | setImageHoverSelected(LLUI::getUIImageByName(image_name)); |
967 | mImageHoverSelectedName = image_name; | 972 | mImageHoverSelectedName = image_name; |
968 | } | 973 | } |
969 | 974 | ||
970 | void LLButton::setImageHoverUnselected(const LLString &image_name) | 975 | void LLButton::setImageHoverUnselected(const LLString &image_name) |
971 | { | 976 | { |
972 | setImageHoverUnselectedID(LLUI::findAssetUUIDByName(image_name)); | 977 | setImageHoverUnselected(LLUI::getUIImageByName(image_name)); |
973 | mImageHoverUnselectedName = image_name; | 978 | mImageHoverUnselectedName = image_name; |
974 | } | 979 | } |
975 | 980 | ||
976 | void LLButton::setImageDisabled(const LLString &image_name) | 981 | void LLButton::setImageDisabled(const LLString &image_name) |
977 | { | 982 | { |
978 | setImageDisabledID(LLUI::findAssetUUIDByName(image_name)); | 983 | setImageDisabled(LLUI::getUIImageByName(image_name)); |
979 | mImageDisabledName = image_name; | 984 | mImageDisabledName = image_name; |
980 | } | 985 | } |
981 | 986 | ||
982 | void LLButton::setImageDisabledSelected(const LLString &image_name) | 987 | void LLButton::setImageDisabledSelected(const LLString &image_name) |
983 | { | 988 | { |
984 | setImageDisabledSelectedID(LLUI::findAssetUUIDByName(image_name)); | 989 | setImageDisabledSelected(LLUI::getUIImageByName(image_name)); |
985 | mImageDisabledSelectedName = image_name; | 990 | mImageDisabledSelectedName = image_name; |
986 | } | 991 | } |
987 | 992 | ||
@@ -1009,8 +1014,6 @@ LLXMLNodePtr LLButton::getXML(bool save_children) const | |||
1009 | node->createChild("label_selected", TRUE)->setStringValue(getLabelSelected()); | 1014 | node->createChild("label_selected", TRUE)->setStringValue(getLabelSelected()); |
1010 | node->createChild("font", TRUE)->setStringValue(LLFontGL::nameFromFont(mGLFont)); | 1015 | node->createChild("font", TRUE)->setStringValue(LLFontGL::nameFromFont(mGLFont)); |
1011 | node->createChild("halign", TRUE)->setStringValue(LLFontGL::nameFromHAlign(mHAlign)); | 1016 | node->createChild("halign", TRUE)->setStringValue(LLFontGL::nameFromHAlign(mHAlign)); |
1012 | node->createChild("border_width", TRUE)->setIntValue(mFixedWidth); | ||
1013 | node->createChild("border_height", TRUE)->setIntValue(mFixedHeight); | ||
1014 | 1017 | ||
1015 | addImageAttributeToXML(node,mImageUnselectedName,mImageUnselectedID,"image_unselected"); | 1018 | addImageAttributeToXML(node,mImageUnselectedName,mImageUnselectedID,"image_unselected"); |
1016 | addImageAttributeToXML(node,mImageSelectedName,mImageSelectedID,"image_selected"); | 1019 | addImageAttributeToXML(node,mImageSelectedName,mImageSelectedID,"image_selected"); |
@@ -1092,8 +1095,12 @@ LLView* LLButton::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *fa | |||
1092 | label, | 1095 | label, |
1093 | label_selected); | 1096 | label_selected); |
1094 | 1097 | ||
1095 | node->getAttributeS32("border_width", button->mFixedWidth); | 1098 | node->getAttributeS32("pad_right", button->mRightHPad); |
1096 | node->getAttributeS32("border_height", button->mFixedHeight); | 1099 | node->getAttributeS32("pad_left", button->mLeftHPad); |
1100 | |||
1101 | BOOL is_toggle = button->getIsToggle(); | ||
1102 | node->getAttributeBOOL("toggle", is_toggle); | ||
1103 | button->setIsToggle(is_toggle); | ||
1097 | 1104 | ||
1098 | if(image_hover_selected != LLString::null) button->setImageHoverSelected(image_hover_selected); | 1105 | if(image_hover_selected != LLString::null) button->setImageHoverSelected(image_hover_selected); |
1099 | 1106 | ||