aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llui/llbutton.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llui/llbutton.cpp
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/llui/llbutton.cpp')
-rw-r--r--linden/indra/llui/llbutton.cpp65
1 files changed, 33 insertions, 32 deletions
diff --git a/linden/indra/llui/llbutton.cpp b/linden/indra/llui/llbutton.cpp
index 7513fc2..4af40ff 100644
--- a/linden/indra/llui/llbutton.cpp
+++ b/linden/indra/llui/llbutton.cpp
@@ -48,6 +48,7 @@
48#include "llglheaders.h" 48#include "llglheaders.h"
49#include "llfocusmgr.h" 49#include "llfocusmgr.h"
50#include "llwindow.h" 50#include "llwindow.h"
51#include "llglimmediate.h"
51 52
52// globals loaded from settings.xml 53// globals loaded from settings.xml
53S32 LLBUTTON_ORIG_H_PAD = 6; // Pre-zoomable UI 54S32 LLBUTTON_ORIG_H_PAD = 6; // Pre-zoomable UI
@@ -189,7 +190,7 @@ void LLButton::init(void (*click_callback)(void*), void *callback_data, const LL
189 mGLFont = ( font ? font : LLFontGL::sSansSerif); 190 mGLFont = ( font ? font : LLFontGL::sSansSerif);
190 191
191 // Hack to make sure there is space for at least one character 192 // Hack to make sure there is space for at least one character
192 if (mRect.getWidth() - (mRightHPad + mLeftHPad) < mGLFont->getWidth(" ")) 193 if (getRect().getWidth() - (mRightHPad + mLeftHPad) < mGLFont->getWidth(" "))
193 { 194 {
194 // Use old defaults 195 // Use old defaults
195 mLeftHPad = LLBUTTON_ORIG_H_PAD; 196 mLeftHPad = LLBUTTON_ORIG_H_PAD;
@@ -252,12 +253,12 @@ void LLButton::onCommit()
252 (*mMouseUpCallback)(mCallbackUserData); 253 (*mMouseUpCallback)(mCallbackUserData);
253 } 254 }
254 255
255 if (mSoundFlags & MOUSE_DOWN) 256 if (getSoundFlags() & MOUSE_DOWN)
256 { 257 {
257 make_ui_sound("UISndClick"); 258 make_ui_sound("UISndClick");
258 } 259 }
259 260
260 if (mSoundFlags & MOUSE_UP) 261 if (getSoundFlags() & MOUSE_UP)
261 { 262 {
262 make_ui_sound("UISndClickRelease"); 263 make_ui_sound("UISndClickRelease");
263 } 264 }
@@ -279,7 +280,7 @@ void LLButton::onCommit()
279BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) 280BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent)
280{ 281{
281 BOOL handled = FALSE; 282 BOOL handled = FALSE;
282 if( getVisible() && mEnabled && !called_from_parent && ' ' == uni_char && !gKeyboard->getKeyRepeated(' ')) 283 if( getVisible() && getEnabled() && !called_from_parent && ' ' == uni_char && !gKeyboard->getKeyRepeated(' '))
283 { 284 {
284 if (mIsToggle) 285 if (mIsToggle)
285 { 286 {
@@ -298,7 +299,7 @@ BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent)
298BOOL LLButton::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) 299BOOL LLButton::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent )
299{ 300{
300 BOOL handled = FALSE; 301 BOOL handled = FALSE;
301 if( getVisible() && mEnabled && !called_from_parent ) 302 if( getVisible() && getEnabled() && !called_from_parent )
302 { 303 {
303 if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) 304 if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key))
304 { 305 {
@@ -337,7 +338,7 @@ BOOL LLButton::handleMouseDown(S32 x, S32 y, MASK mask)
337 mMouseDownTimer.start(); 338 mMouseDownTimer.start();
338 mMouseDownFrame = LLFrameTimer::getFrameCount(); 339 mMouseDownFrame = LLFrameTimer::getFrameCount();
339 340
340 if (mSoundFlags & MOUSE_DOWN) 341 if (getSoundFlags() & MOUSE_DOWN)
341 { 342 {
342 make_ui_sound("UISndClick"); 343 make_ui_sound("UISndClick");
343 } 344 }
@@ -367,7 +368,7 @@ BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask)
367 // If mouseup in the widget, it's been clicked 368 // If mouseup in the widget, it's been clicked
368 if (pointInView(x, y)) 369 if (pointInView(x, y))
369 { 370 {
370 if (mSoundFlags & MOUSE_UP) 371 if (getSoundFlags() & MOUSE_UP)
371 { 372 {
372 make_ui_sound("UISndClickRelease"); 373 make_ui_sound("UISndClickRelease");
373 } 374 }
@@ -400,7 +401,7 @@ BOOL LLButton::handleHover(S32 x, S32 y, MASK mask)
400 401
401 if (mMouseDownTimer.getStarted() && NULL != mHeldDownCallback) 402 if (mMouseDownTimer.getStarted() && NULL != mHeldDownCallback)
402 { 403 {
403 F32 elapsed = mMouseDownTimer.getElapsedTimeF32(); 404 F32 elapsed = getHeldDownTime();
404 if( mHeldDownDelay <= elapsed && mHeldDownFrameDelay <= LLFrameTimer::getFrameCount() - mMouseDownFrame) 405 if( mHeldDownDelay <= elapsed && mHeldDownFrameDelay <= LLFrameTimer::getFrameCount() - mMouseDownFrame)
405 { 406 {
406 mHeldDownCallback( mCallbackUserData ); 407 mHeldDownCallback( mCallbackUserData );
@@ -505,11 +506,11 @@ void LLButton::draw()
505 // enabled and tentative 506 // enabled and tentative
506 // or 507 // or
507 // disabled but checked 508 // disabled but checked
508 if (!mImageDisabledSelected.isNull() && ( (mEnabled && mTentative) || (!mEnabled && pressed ) ) ) 509 if (!mImageDisabledSelected.isNull() && ( (getEnabled() && getTentative()) || (!getEnabled() && pressed ) ) )
509 { 510 {
510 mImagep = mImageDisabledSelected; 511 mImagep = mImageDisabledSelected;
511 } 512 }
512 else if (!mImageDisabled.isNull() && !mEnabled && !pressed) 513 else if (!mImageDisabled.isNull() && !getEnabled() && !pressed)
513 { 514 {
514 mImagep = mImageDisabled; 515 mImagep = mImageDisabled;
515 } 516 }
@@ -523,7 +524,7 @@ void LLButton::draw()
523 LLColor4 label_color; 524 LLColor4 label_color;
524 525
525 // label changes when button state changes, not when pressed 526 // label changes when button state changes, not when pressed
526 if ( mEnabled ) 527 if ( getEnabled() )
527 { 528 {
528 if ( mToggleState ) 529 if ( mToggleState )
529 { 530 {
@@ -551,7 +552,7 @@ void LLButton::draw()
551 552
552 if( mToggleState ) 553 if( mToggleState )
553 { 554 {
554 if( mEnabled || mDisabledSelectedLabel.empty() ) 555 if( getEnabled() || mDisabledSelectedLabel.empty() )
555 { 556 {
556 label = mSelectedLabel; 557 label = mSelectedLabel;
557 } 558 }
@@ -562,7 +563,7 @@ void LLButton::draw()
562 } 563 }
563 else 564 else
564 { 565 {
565 if( mEnabled || mDisabledLabel.empty() ) 566 if( getEnabled() || mDisabledLabel.empty() )
566 { 567 {
567 label = mUnselectedLabel; 568 label = mUnselectedLabel;
568 } 569 }
@@ -573,7 +574,7 @@ void LLButton::draw()
573 } 574 }
574 575
575 // draw default button border 576 // draw default button border
576 if (mEnabled && mBorderEnabled && gFocusMgr.getAppHasFocus()) // because we're the default button in a panel 577 if (getEnabled() && mBorderEnabled && gFocusMgr.getAppHasFocus()) // because we're the default button in a panel
577 { 578 {
578 drawBorder(LLUI::sColorsGroup->getColor( "ButtonBorderColor" ), BORDER_SIZE); 579 drawBorder(LLUI::sColorsGroup->getColor( "ButtonBorderColor" ), BORDER_SIZE);
579 } 580 }
@@ -598,37 +599,37 @@ void LLButton::draw()
598 // Otherwise draw basic rectangular button. 599 // Otherwise draw basic rectangular button.
599 if( mImagep.notNull() && !mScaleImage) 600 if( mImagep.notNull() && !mScaleImage)
600 { 601 {
601 mImagep->draw(0, 0, mEnabled ? mImageColor : mDisabledImageColor ); 602 mImagep->draw(0, 0, getEnabled() ? mImageColor : mDisabledImageColor );
602 if (mCurGlowStrength > 0.01f) 603 if (mCurGlowStrength > 0.01f)
603 { 604 {
604 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 605 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE);
605 mImagep->drawSolid(0, 0, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); 606 mImagep->drawSolid(0, 0, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength));
606 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 607 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
607 } 608 }
608 } 609 }
609 else 610 else
610 if ( mImagep.notNull() && mScaleImage) 611 if ( mImagep.notNull() && mScaleImage)
611 { 612 {
612 mImagep->draw(0, 0, mRect.getWidth(), mRect.getHeight(), mEnabled ? mImageColor : mDisabledImageColor ); 613 mImagep->draw(0, 0, getRect().getWidth(), getRect().getHeight(), getEnabled() ? mImageColor : mDisabledImageColor );
613 if (mCurGlowStrength > 0.01f) 614 if (mCurGlowStrength > 0.01f)
614 { 615 {
615 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 616 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE);
616 mImagep->drawSolid(0, 0, mRect.getWidth(), mRect.getHeight(), LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); 617 mImagep->drawSolid(0, 0, getRect().getWidth(), getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, mCurGlowStrength));
617 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 618 gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
618 } 619 }
619 } 620 }
620 else 621 else
621 { 622 {
622 // no image 623 // no image
623 llwarns << "No image for button " << mName << llendl; 624 llwarns << "No image for button " << getName() << llendl;
624 // draw it in pink so we can find it 625 // draw it in pink so we can find it
625 gl_rect_2d(0, mRect.getHeight(), mRect.getWidth(), 0, LLColor4::pink1, FALSE); 626 gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4::pink1, FALSE);
626 } 627 }
627 628
628 // let overlay image and text play well together 629 // let overlay image and text play well together
629 S32 text_left = mLeftHPad; 630 S32 text_left = mLeftHPad;
630 S32 text_right = mRect.getWidth() - mRightHPad; 631 S32 text_right = getRect().getWidth() - mRightHPad;
631 S32 text_width = mRect.getWidth() - mLeftHPad - mRightHPad; 632 S32 text_width = getRect().getWidth() - mLeftHPad - mRightHPad;
632 633
633 // draw overlay image 634 // draw overlay image
634 if (mImageOverlay.notNull()) 635 if (mImageOverlay.notNull())
@@ -637,7 +638,7 @@ void LLButton::draw()
637 S32 overlay_width = mImageOverlay->getWidth(); 638 S32 overlay_width = mImageOverlay->getWidth();
638 S32 overlay_height = mImageOverlay->getHeight(); 639 S32 overlay_height = mImageOverlay->getHeight();
639 640
640 F32 scale_factor = llmin((F32)mRect.getWidth() / (F32)overlay_width, (F32)mRect.getHeight() / (F32)overlay_height, 1.f); 641 F32 scale_factor = llmin((F32)getRect().getWidth() / (F32)overlay_width, (F32)getRect().getHeight() / (F32)overlay_height, 1.f);
641 overlay_width = llround((F32)overlay_width * scale_factor); 642 overlay_width = llround((F32)overlay_width * scale_factor);
642 overlay_height = llround((F32)overlay_height * scale_factor); 643 overlay_height = llround((F32)overlay_height * scale_factor);
643 644
@@ -682,7 +683,7 @@ void LLButton::draw()
682 text_right -= overlay_width + 1; 683 text_right -= overlay_width + 1;
683 text_width -= overlay_width + 1; 684 text_width -= overlay_width + 1;
684 mImageOverlay->draw( 685 mImageOverlay->draw(
685 mRect.getWidth() - mRightHPad - overlay_width, 686 getRect().getWidth() - mRightHPad - overlay_width,
686 center_y - (overlay_height / 2), 687 center_y - (overlay_height / 2),
687 overlay_width, 688 overlay_width,
688 overlay_height, 689 overlay_height,
@@ -706,7 +707,7 @@ void LLButton::draw()
706 x = text_right; 707 x = text_right;
707 break; 708 break;
708 case LLFontGL::HCENTER: 709 case LLFontGL::HCENTER:
709 x = mRect.getWidth() / 2; 710 x = getRect().getWidth() / 2;
710 break; 711 break;
711 case LLFontGL::LEFT: 712 case LLFontGL::LEFT:
712 default: 713 default:
@@ -714,7 +715,7 @@ void LLButton::draw()
714 break; 715 break;
715 } 716 }
716 717
717 S32 y_offset = 2 + (mRect.getHeight() - 20)/2; 718 S32 y_offset = 2 + (getRect().getHeight() - 20)/2;
718 719
719 if (pressed) 720 if (pressed)
720 { 721 {
@@ -743,8 +744,8 @@ void LLButton::draw()
743void LLButton::drawBorder(const LLColor4& color, S32 size) 744void LLButton::drawBorder(const LLColor4& color, S32 size)
744{ 745{
745 S32 left = -size; 746 S32 left = -size;
746 S32 top = mRect.getHeight() + size; 747 S32 top = getRect().getHeight() + size;
747 S32 right = mRect.getWidth() + size; 748 S32 right = getRect().getWidth() + size;
748 S32 bottom = -size; 749 S32 bottom = -size;
749 750
750 if (mImagep.isNull()) 751 if (mImagep.isNull())
@@ -1146,7 +1147,7 @@ LLView* LLButton::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *fa
1146 return button; 1147 return button;
1147} 1148}
1148 1149
1149void LLButton::setHelpURLCallback(std::string help_url) 1150void LLButton::setHelpURLCallback(const LLString &help_url)
1150{ 1151{
1151 mHelpURL = help_url; 1152 mHelpURL = help_url;
1152 setClickedCallback(clicked_help,this); 1153 setClickedCallback(clicked_help,this);