diff options
author | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
commit | ce28e056c20bf2723f565bbf464b87781ec248a2 (patch) | |
tree | ef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/llui/llbutton.cpp | |
parent | Second Life viewer sources 1.19.1.4b (diff) | |
download | meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2 meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz |
Second Life viewer sources 1.20.2
Diffstat (limited to 'linden/indra/llui/llbutton.cpp')
-rw-r--r-- | linden/indra/llui/llbutton.cpp | 578 |
1 files changed, 269 insertions, 309 deletions
diff --git a/linden/indra/llui/llbutton.cpp b/linden/indra/llui/llbutton.cpp index 4af40ff..3ada389 100644 --- a/linden/indra/llui/llbutton.cpp +++ b/linden/indra/llui/llbutton.cpp | |||
@@ -50,6 +50,8 @@ | |||
50 | #include "llwindow.h" | 50 | #include "llwindow.h" |
51 | #include "llglimmediate.h" | 51 | #include "llglimmediate.h" |
52 | 52 | ||
53 | static LLRegisterWidget<LLButton> r("button"); | ||
54 | |||
53 | // globals loaded from settings.xml | 55 | // globals loaded from settings.xml |
54 | S32 LLBUTTON_ORIG_H_PAD = 6; // Pre-zoomable UI | 56 | S32 LLBUTTON_ORIG_H_PAD = 6; // Pre-zoomable UI |
55 | S32 LLBUTTON_H_PAD = 0; | 57 | S32 LLBUTTON_H_PAD = 0; |
@@ -222,18 +224,6 @@ LLButton::~LLButton() | |||
222 | } | 224 | } |
223 | } | 225 | } |
224 | 226 | ||
225 | // virtual | ||
226 | EWidgetType LLButton::getWidgetType() const | ||
227 | { | ||
228 | return WIDGET_TYPE_BUTTON; | ||
229 | } | ||
230 | |||
231 | // virtual | ||
232 | LLString LLButton::getWidgetTag() const | ||
233 | { | ||
234 | return LL_BUTTON_TAG; | ||
235 | } | ||
236 | |||
237 | // HACK: Committing a button is the same as instantly clicking it. | 227 | // HACK: Committing a button is the same as instantly clicking it. |
238 | // virtual | 228 | // virtual |
239 | void LLButton::onCommit() | 229 | void LLButton::onCommit() |
@@ -277,10 +267,11 @@ void LLButton::onCommit() | |||
277 | 267 | ||
278 | 268 | ||
279 | 269 | ||
280 | BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) | 270 | BOOL LLButton::handleUnicodeCharHere(llwchar uni_char) |
281 | { | 271 | { |
282 | BOOL handled = FALSE; | 272 | BOOL handled = FALSE; |
283 | if( getVisible() && getEnabled() && !called_from_parent && ' ' == uni_char && !gKeyboard->getKeyRepeated(' ')) | 273 | if(' ' == uni_char |
274 | && !gKeyboard->getKeyRepeated(' ')) | ||
284 | { | 275 | { |
285 | if (mIsToggle) | 276 | if (mIsToggle) |
286 | { | 277 | { |
@@ -296,24 +287,21 @@ BOOL LLButton::handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent) | |||
296 | return handled; | 287 | return handled; |
297 | } | 288 | } |
298 | 289 | ||
299 | BOOL LLButton::handleKeyHere(KEY key, MASK mask, BOOL called_from_parent ) | 290 | BOOL LLButton::handleKeyHere(KEY key, MASK mask ) |
300 | { | 291 | { |
301 | BOOL handled = FALSE; | 292 | BOOL handled = FALSE; |
302 | if( getVisible() && getEnabled() && !called_from_parent ) | 293 | if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) |
303 | { | 294 | { |
304 | if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) | 295 | if (mIsToggle) |
305 | { | 296 | { |
306 | if (mIsToggle) | 297 | toggleState(); |
307 | { | 298 | } |
308 | toggleState(); | ||
309 | } | ||
310 | 299 | ||
311 | handled = TRUE; | 300 | handled = TRUE; |
312 | 301 | ||
313 | if (mClickedCallback) | 302 | if (mClickedCallback) |
314 | { | 303 | { |
315 | (*mClickedCallback)( mCallbackUserData ); | 304 | (*mClickedCallback)( mCallbackUserData ); |
316 | } | ||
317 | } | 305 | } |
318 | } | 306 | } |
319 | return handled; | 307 | return handled; |
@@ -391,8 +379,6 @@ BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask) | |||
391 | 379 | ||
392 | BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) | 380 | BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) |
393 | { | 381 | { |
394 | BOOL handled = FALSE; | ||
395 | |||
396 | LLMouseHandler* other_captor = gFocusMgr.getMouseCapture(); | 382 | LLMouseHandler* other_captor = gFocusMgr.getMouseCapture(); |
397 | mNeedsHighlight = other_captor == NULL || | 383 | mNeedsHighlight = other_captor == NULL || |
398 | other_captor == this || | 384 | other_captor == this || |
@@ -409,358 +395,333 @@ BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) | |||
409 | } | 395 | } |
410 | 396 | ||
411 | // We only handle the click if the click both started and ended within us | 397 | // We only handle the click if the click both started and ended within us |
412 | if( hasMouseCapture() ) | 398 | getWindow()->setCursor(UI_CURSOR_ARROW); |
413 | { | 399 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << llendl; |
414 | handled = TRUE; | ||
415 | } | ||
416 | else if( getVisible() ) | ||
417 | { | ||
418 | // Opaque | ||
419 | handled = TRUE; | ||
420 | } | ||
421 | 400 | ||
422 | if( handled ) | 401 | return TRUE; |
423 | { | ||
424 | getWindow()->setCursor(UI_CURSOR_ARROW); | ||
425 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << llendl; | ||
426 | } | ||
427 | |||
428 | return handled; | ||
429 | } | 402 | } |
430 | 403 | ||
431 | 404 | ||
432 | // virtual | 405 | // virtual |
433 | void LLButton::draw() | 406 | void LLButton::draw() |
434 | { | 407 | { |
435 | if( getVisible() ) | 408 | BOOL flash = FALSE; |
409 | if( mFlashing ) | ||
436 | { | 410 | { |
437 | BOOL flash = FALSE; | 411 | F32 elapsed = mFlashingTimer.getElapsedTimeF32(); |
438 | if( mFlashing ) | 412 | S32 flash_count = S32(elapsed * LLUI::sConfigGroup->getF32("ButtonFlashRate") * 2.f); |
439 | { | 413 | // flash on or off? |
440 | F32 elapsed = mFlashingTimer.getElapsedTimeF32(); | 414 | flash = (flash_count % 2 == 0) || flash_count > S32((F32)LLUI::sConfigGroup->getS32("ButtonFlashCount") * 2.f); |
441 | S32 flash_count = S32(elapsed * LLUI::sConfigGroup->getF32("ButtonFlashRate") * 2.f); | 415 | } |
442 | // flash on or off? | ||
443 | flash = (flash_count % 2 == 0) || flash_count > (F32)LLUI::sConfigGroup->getS32("ButtonFlashCount"); | ||
444 | } | ||
445 | 416 | ||
446 | BOOL pressed_by_keyboard = FALSE; | 417 | BOOL pressed_by_keyboard = FALSE; |
447 | if (hasFocus()) | 418 | if (hasFocus()) |
448 | { | 419 | { |
449 | pressed_by_keyboard = gKeyboard->getKeyDown(' ') || (mCommitOnReturn && gKeyboard->getKeyDown(KEY_RETURN)); | 420 | pressed_by_keyboard = gKeyboard->getKeyDown(' ') || (mCommitOnReturn && gKeyboard->getKeyDown(KEY_RETURN)); |
450 | } | 421 | } |
451 | 422 | ||
452 | // Unselected image assignments | 423 | // Unselected image assignments |
453 | S32 local_mouse_x; | 424 | S32 local_mouse_x; |
454 | S32 local_mouse_y; | 425 | S32 local_mouse_y; |
455 | LLCoordWindow cursor_pos_window; | 426 | LLCoordWindow cursor_pos_window; |
456 | getWindow()->getCursorPosition(&cursor_pos_window); | 427 | getWindow()->getCursorPosition(&cursor_pos_window); |
457 | LLCoordGL cursor_pos_gl; | 428 | LLCoordGL cursor_pos_gl; |
458 | getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl); | 429 | getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl); |
459 | cursor_pos_gl.mX = llround((F32)cursor_pos_gl.mX / LLUI::sGLScaleFactor.mV[VX]); | 430 | cursor_pos_gl.mX = llround((F32)cursor_pos_gl.mX / LLUI::sGLScaleFactor.mV[VX]); |
460 | cursor_pos_gl.mY = llround((F32)cursor_pos_gl.mY / LLUI::sGLScaleFactor.mV[VY]); | 431 | cursor_pos_gl.mY = llround((F32)cursor_pos_gl.mY / LLUI::sGLScaleFactor.mV[VY]); |
461 | screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); | 432 | screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &local_mouse_x, &local_mouse_y); |
462 | 433 | ||
463 | BOOL pressed = pressed_by_keyboard | 434 | BOOL pressed = pressed_by_keyboard |
464 | || (hasMouseCapture() && pointInView(local_mouse_x, local_mouse_y)) | 435 | || (hasMouseCapture() && pointInView(local_mouse_x, local_mouse_y)) |
465 | || mToggleState; | 436 | || mToggleState; |
466 | 437 | ||
467 | BOOL use_glow_effect = FALSE; | 438 | BOOL use_glow_effect = FALSE; |
468 | if ( mNeedsHighlight || flash ) | 439 | if ( mNeedsHighlight || flash ) |
440 | { | ||
441 | if (pressed) | ||
469 | { | 442 | { |
470 | if (pressed) | 443 | if (mImageHoverSelected) |
471 | { | 444 | { |
472 | if (mImageHoverSelected) | 445 | mImagep = mImageHoverSelected; |
473 | { | ||
474 | mImagep = mImageHoverSelected; | ||
475 | } | ||
476 | else | ||
477 | { | ||
478 | mImagep = mImageSelected; | ||
479 | use_glow_effect = TRUE; | ||
480 | } | ||
481 | } | 446 | } |
482 | else | 447 | else |
483 | { | 448 | { |
484 | if (mImageHoverUnselected) | 449 | mImagep = mImageSelected; |
485 | { | 450 | use_glow_effect = TRUE; |
486 | mImagep = mImageHoverUnselected; | ||
487 | } | ||
488 | else | ||
489 | { | ||
490 | mImagep = mImageUnselected; | ||
491 | use_glow_effect = TRUE; | ||
492 | } | ||
493 | } | 451 | } |
494 | } | 452 | } |
495 | else if ( pressed ) | ||
496 | { | ||
497 | mImagep = mImageSelected; | ||
498 | } | ||
499 | else | 453 | else |
500 | { | 454 | { |
501 | mImagep = mImageUnselected; | 455 | if (mImageHoverUnselected) |
456 | { | ||
457 | mImagep = mImageHoverUnselected; | ||
458 | } | ||
459 | else | ||
460 | { | ||
461 | mImagep = mImageUnselected; | ||
462 | use_glow_effect = TRUE; | ||
463 | } | ||
502 | } | 464 | } |
465 | } | ||
466 | else if ( pressed ) | ||
467 | { | ||
468 | mImagep = mImageSelected; | ||
469 | } | ||
470 | else | ||
471 | { | ||
472 | mImagep = mImageUnselected; | ||
473 | } | ||
503 | 474 | ||
504 | // Override if more data is available | 475 | // Override if more data is available |
505 | // HACK: Use gray checked state to mean either: | 476 | // HACK: Use gray checked state to mean either: |
506 | // enabled and tentative | 477 | // enabled and tentative |
507 | // or | 478 | // or |
508 | // disabled but checked | 479 | // disabled but checked |
509 | if (!mImageDisabledSelected.isNull() && ( (getEnabled() && getTentative()) || (!getEnabled() && pressed ) ) ) | 480 | if (!mImageDisabledSelected.isNull() |
510 | { | 481 | && |
511 | mImagep = mImageDisabledSelected; | 482 | ( (getEnabled() && getTentative()) |
512 | } | 483 | || (!getEnabled() && pressed ) ) ) |
513 | else if (!mImageDisabled.isNull() && !getEnabled() && !pressed) | 484 | { |
514 | { | 485 | mImagep = mImageDisabledSelected; |
515 | mImagep = mImageDisabled; | 486 | } |
516 | } | 487 | else if (!mImageDisabled.isNull() |
488 | && !getEnabled() | ||
489 | && !pressed) | ||
490 | { | ||
491 | mImagep = mImageDisabled; | ||
492 | } | ||
517 | 493 | ||
518 | if (mNeedsHighlight && !mImagep) | 494 | if (mNeedsHighlight && !mImagep) |
519 | { | 495 | { |
520 | use_glow_effect = TRUE; | 496 | use_glow_effect = TRUE; |
521 | } | 497 | } |
522 | 498 | ||
523 | // Figure out appropriate color for the text | 499 | // Figure out appropriate color for the text |
524 | LLColor4 label_color; | 500 | LLColor4 label_color; |
525 | 501 | ||
526 | // label changes when button state changes, not when pressed | 502 | // label changes when button state changes, not when pressed |
527 | if ( getEnabled() ) | 503 | if ( getEnabled() ) |
504 | { | ||
505 | if ( mToggleState ) | ||
528 | { | 506 | { |
529 | if ( mToggleState ) | 507 | label_color = mSelectedLabelColor; |
530 | { | ||
531 | label_color = mSelectedLabelColor; | ||
532 | } | ||
533 | else | ||
534 | { | ||
535 | label_color = mUnselectedLabelColor; | ||
536 | } | ||
537 | } | 508 | } |
538 | else | 509 | else |
539 | { | 510 | { |
540 | if ( mToggleState ) | 511 | label_color = mUnselectedLabelColor; |
541 | { | ||
542 | label_color = mDisabledSelectedLabelColor; | ||
543 | } | ||
544 | else | ||
545 | { | ||
546 | label_color = mDisabledLabelColor; | ||
547 | } | ||
548 | } | 512 | } |
549 | 513 | } | |
550 | // Unselected label assignments | 514 | else |
551 | LLWString label; | 515 | { |
552 | 516 | if ( mToggleState ) | |
553 | if( mToggleState ) | ||
554 | { | 517 | { |
555 | if( getEnabled() || mDisabledSelectedLabel.empty() ) | 518 | label_color = mDisabledSelectedLabelColor; |
556 | { | ||
557 | label = mSelectedLabel; | ||
558 | } | ||
559 | else | ||
560 | { | ||
561 | label = mDisabledSelectedLabel; | ||
562 | } | ||
563 | } | 519 | } |
564 | else | 520 | else |
565 | { | 521 | { |
566 | if( getEnabled() || mDisabledLabel.empty() ) | 522 | label_color = mDisabledLabelColor; |
567 | { | ||
568 | label = mUnselectedLabel; | ||
569 | } | ||
570 | else | ||
571 | { | ||
572 | label = mDisabledLabel; | ||
573 | } | ||
574 | } | 523 | } |
575 | 524 | } | |
576 | // draw default button border | 525 | |
577 | if (getEnabled() && mBorderEnabled && gFocusMgr.getAppHasFocus()) // because we're the default button in a panel | 526 | // Unselected label assignments |
527 | LLWString label; | ||
528 | |||
529 | if( mToggleState ) | ||
530 | { | ||
531 | if( getEnabled() || mDisabledSelectedLabel.empty() ) | ||
578 | { | 532 | { |
579 | drawBorder(LLUI::sColorsGroup->getColor( "ButtonBorderColor" ), BORDER_SIZE); | 533 | label = mSelectedLabel; |
580 | } | 534 | } |
581 | 535 | else | |
582 | // overlay with keyboard focus border | ||
583 | if (hasFocus()) | ||
584 | { | 536 | { |
585 | F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); | 537 | label = mDisabledSelectedLabel; |
586 | drawBorder(gFocusMgr.getFocusColor(), llround(lerp(1.f, 3.f, lerp_amt))); | ||
587 | } | 538 | } |
588 | 539 | } | |
589 | if (use_glow_effect) | 540 | else |
541 | { | ||
542 | if( getEnabled() || mDisabledLabel.empty() ) | ||
590 | { | 543 | { |
591 | mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLCriticalDamp::getInterpolant(0.05f)); | 544 | label = mUnselectedLabel; |
592 | } | 545 | } |
593 | else | 546 | else |
594 | { | 547 | { |
595 | mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f)); | 548 | label = mDisabledLabel; |
596 | } | 549 | } |
550 | } | ||
597 | 551 | ||
598 | // Draw button image, if available. | 552 | // overlay with keyboard focus border |
599 | // Otherwise draw basic rectangular button. | 553 | if (hasFocus()) |
600 | if( mImagep.notNull() && !mScaleImage) | 554 | { |
555 | F32 lerp_amt = gFocusMgr.getFocusFlashAmt(); | ||
556 | drawBorder(gFocusMgr.getFocusColor(), llround(lerp(1.f, 3.f, lerp_amt))); | ||
557 | } | ||
558 | |||
559 | if (use_glow_effect) | ||
560 | { | ||
561 | mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLCriticalDamp::getInterpolant(0.05f)); | ||
562 | } | ||
563 | else | ||
564 | { | ||
565 | mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f)); | ||
566 | } | ||
567 | |||
568 | // Draw button image, if available. | ||
569 | // Otherwise draw basic rectangular button. | ||
570 | if (mImagep.notNull()) | ||
571 | { | ||
572 | if ( mScaleImage) | ||
601 | { | 573 | { |
602 | mImagep->draw(0, 0, getEnabled() ? mImageColor : mDisabledImageColor ); | 574 | mImagep->draw(getLocalRect(), getEnabled() ? mImageColor : mDisabledImageColor ); |
603 | if (mCurGlowStrength > 0.01f) | 575 | if (mCurGlowStrength > 0.01f) |
604 | { | 576 | { |
605 | gGL.blendFunc(GL_SRC_ALPHA, GL_ONE); | 577 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
606 | mImagep->drawSolid(0, 0, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); | 578 | mImagep->drawSolid(0, 0, getRect().getWidth(), getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); |
607 | gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 579 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
608 | } | 580 | } |
609 | } | 581 | } |
610 | else | 582 | else |
611 | if ( mImagep.notNull() && mScaleImage) | ||
612 | { | 583 | { |
613 | mImagep->draw(0, 0, getRect().getWidth(), getRect().getHeight(), getEnabled() ? mImageColor : mDisabledImageColor ); | 584 | mImagep->draw(0, 0, getEnabled() ? mImageColor : mDisabledImageColor ); |
614 | if (mCurGlowStrength > 0.01f) | 585 | if (mCurGlowStrength > 0.01f) |
615 | { | 586 | { |
616 | gGL.blendFunc(GL_SRC_ALPHA, GL_ONE); | 587 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
617 | mImagep->drawSolid(0, 0, getRect().getWidth(), getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); | 588 | mImagep->drawSolid(0, 0, LLColor4(1.f, 1.f, 1.f, mCurGlowStrength)); |
618 | gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 589 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
619 | } | 590 | } |
620 | } | 591 | } |
621 | else | 592 | } |
622 | { | 593 | else |
623 | // no image | 594 | { |
624 | llwarns << "No image for button " << getName() << llendl; | 595 | // no image |
625 | // draw it in pink so we can find it | 596 | llwarns << "No image for button " << getName() << llendl; |
626 | gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4::pink1, FALSE); | 597 | // draw it in pink so we can find it |
627 | } | 598 | gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4::pink1, FALSE); |
628 | 599 | } | |
629 | // let overlay image and text play well together | ||
630 | S32 text_left = mLeftHPad; | ||
631 | S32 text_right = getRect().getWidth() - mRightHPad; | ||
632 | S32 text_width = getRect().getWidth() - mLeftHPad - mRightHPad; | ||
633 | |||
634 | // draw overlay image | ||
635 | if (mImageOverlay.notNull()) | ||
636 | { | ||
637 | // get max width and height (discard level 0) | ||
638 | S32 overlay_width = mImageOverlay->getWidth(); | ||
639 | S32 overlay_height = mImageOverlay->getHeight(); | ||
640 | 600 | ||
641 | F32 scale_factor = llmin((F32)getRect().getWidth() / (F32)overlay_width, (F32)getRect().getHeight() / (F32)overlay_height, 1.f); | 601 | // let overlay image and text play well together |
642 | overlay_width = llround((F32)overlay_width * scale_factor); | 602 | S32 text_left = mLeftHPad; |
643 | overlay_height = llround((F32)overlay_height * scale_factor); | 603 | S32 text_right = getRect().getWidth() - mRightHPad; |
604 | S32 text_width = getRect().getWidth() - mLeftHPad - mRightHPad; | ||
644 | 605 | ||
645 | S32 center_x = getLocalRect().getCenterX(); | 606 | // draw overlay image |
646 | S32 center_y = getLocalRect().getCenterY(); | 607 | if (mImageOverlay.notNull()) |
608 | { | ||
609 | // get max width and height (discard level 0) | ||
610 | S32 overlay_width = mImageOverlay->getWidth(); | ||
611 | S32 overlay_height = mImageOverlay->getHeight(); | ||
647 | 612 | ||
648 | //FUGLY HACK FOR "DEPRESSED" BUTTONS | 613 | F32 scale_factor = llmin((F32)getRect().getWidth() / (F32)overlay_width, (F32)getRect().getHeight() / (F32)overlay_height, 1.f); |
649 | if (pressed) | 614 | overlay_width = llround((F32)overlay_width * scale_factor); |
650 | { | 615 | overlay_height = llround((F32)overlay_height * scale_factor); |
651 | center_y--; | ||
652 | center_x++; | ||
653 | } | ||
654 | 616 | ||
655 | // fade out overlay images on disabled buttons | 617 | S32 center_x = getLocalRect().getCenterX(); |
656 | LLColor4 overlay_color = mImageOverlayColor; | 618 | S32 center_y = getLocalRect().getCenterY(); |
657 | if (!getEnabled()) | ||
658 | { | ||
659 | overlay_color.mV[VALPHA] = 0.5f; | ||
660 | } | ||
661 | 619 | ||
662 | switch(mImageOverlayAlignment) | 620 | //FUGLY HACK FOR "DEPRESSED" BUTTONS |
663 | { | 621 | if (pressed) |
664 | case LLFontGL::LEFT: | 622 | { |
665 | text_left += overlay_width + 1; | 623 | center_y--; |
666 | text_width -= overlay_width + 1; | 624 | center_x++; |
667 | mImageOverlay->draw( | ||
668 | mLeftHPad, | ||
669 | center_y - (overlay_height / 2), | ||
670 | overlay_width, | ||
671 | overlay_height, | ||
672 | overlay_color); | ||
673 | break; | ||
674 | case LLFontGL::HCENTER: | ||
675 | mImageOverlay->draw( | ||
676 | center_x - (overlay_width / 2), | ||
677 | center_y - (overlay_height / 2), | ||
678 | overlay_width, | ||
679 | overlay_height, | ||
680 | overlay_color); | ||
681 | break; | ||
682 | case LLFontGL::RIGHT: | ||
683 | text_right -= overlay_width + 1; | ||
684 | text_width -= overlay_width + 1; | ||
685 | mImageOverlay->draw( | ||
686 | getRect().getWidth() - mRightHPad - overlay_width, | ||
687 | center_y - (overlay_height / 2), | ||
688 | overlay_width, | ||
689 | overlay_height, | ||
690 | overlay_color); | ||
691 | break; | ||
692 | default: | ||
693 | // draw nothing | ||
694 | break; | ||
695 | } | ||
696 | } | 625 | } |
697 | 626 | ||
698 | // Draw label | 627 | // fade out overlay images on disabled buttons |
699 | if( !label.empty() ) | 628 | LLColor4 overlay_color = mImageOverlayColor; |
629 | if (!getEnabled()) | ||
700 | { | 630 | { |
701 | LLWString::trim(label); | 631 | overlay_color.mV[VALPHA] = 0.5f; |
632 | } | ||
702 | 633 | ||
703 | S32 x; | 634 | switch(mImageOverlayAlignment) |
704 | switch( mHAlign ) | 635 | { |
705 | { | 636 | case LLFontGL::LEFT: |
706 | case LLFontGL::RIGHT: | 637 | text_left += overlay_width + 1; |
707 | x = text_right; | 638 | text_width -= overlay_width + 1; |
708 | break; | 639 | mImageOverlay->draw( |
709 | case LLFontGL::HCENTER: | 640 | mLeftHPad, |
710 | x = getRect().getWidth() / 2; | 641 | center_y - (overlay_height / 2), |
711 | break; | 642 | overlay_width, |
712 | case LLFontGL::LEFT: | 643 | overlay_height, |
713 | default: | 644 | overlay_color); |
714 | x = text_left; | 645 | break; |
715 | break; | 646 | case LLFontGL::HCENTER: |
716 | } | 647 | mImageOverlay->draw( |
648 | center_x - (overlay_width / 2), | ||
649 | center_y - (overlay_height / 2), | ||
650 | overlay_width, | ||
651 | overlay_height, | ||
652 | overlay_color); | ||
653 | break; | ||
654 | case LLFontGL::RIGHT: | ||
655 | text_right -= overlay_width + 1; | ||
656 | text_width -= overlay_width + 1; | ||
657 | mImageOverlay->draw( | ||
658 | getRect().getWidth() - mRightHPad - overlay_width, | ||
659 | center_y - (overlay_height / 2), | ||
660 | overlay_width, | ||
661 | overlay_height, | ||
662 | overlay_color); | ||
663 | break; | ||
664 | default: | ||
665 | // draw nothing | ||
666 | break; | ||
667 | } | ||
668 | } | ||
717 | 669 | ||
718 | S32 y_offset = 2 + (getRect().getHeight() - 20)/2; | 670 | // Draw label |
719 | 671 | if( !label.empty() ) | |
720 | if (pressed) | 672 | { |
721 | { | 673 | LLWString::trim(label); |
722 | y_offset--; | ||
723 | x++; | ||
724 | } | ||
725 | 674 | ||
726 | mGLFont->render(label, 0, (F32)x, (F32)(LLBUTTON_V_PAD + y_offset), | 675 | S32 x; |
727 | label_color, | 676 | switch( mHAlign ) |
728 | mHAlign, LLFontGL::BOTTOM, | 677 | { |
729 | mDropShadowedText ? LLFontGL::DROP_SHADOW_SOFT : LLFontGL::NORMAL, | 678 | case LLFontGL::RIGHT: |
730 | U32_MAX, text_width, | 679 | x = text_right; |
731 | NULL, FALSE, FALSE); | 680 | break; |
681 | case LLFontGL::HCENTER: | ||
682 | x = getRect().getWidth() / 2; | ||
683 | break; | ||
684 | case LLFontGL::LEFT: | ||
685 | default: | ||
686 | x = text_left; | ||
687 | break; | ||
732 | } | 688 | } |
733 | 689 | ||
734 | if (sDebugRects | 690 | S32 y_offset = 2 + (getRect().getHeight() - 20)/2; |
735 | || (LLView::sEditingUI && this == LLView::sEditingUIView)) | 691 | |
692 | if (pressed) | ||
736 | { | 693 | { |
737 | drawDebugRect(); | 694 | y_offset--; |
695 | x++; | ||
738 | } | 696 | } |
697 | |||
698 | mGLFont->render(label, 0, (F32)x, (F32)(LLBUTTON_V_PAD + y_offset), | ||
699 | label_color, | ||
700 | mHAlign, LLFontGL::BOTTOM, | ||
701 | mDropShadowedText ? LLFontGL::DROP_SHADOW_SOFT : LLFontGL::NORMAL, | ||
702 | U32_MAX, text_width, | ||
703 | NULL, FALSE, FALSE); | ||
739 | } | 704 | } |
705 | |||
706 | if (sDebugRects | ||
707 | || (LLView::sEditingUI && this == LLView::sEditingUIView)) | ||
708 | { | ||
709 | drawDebugRect(); | ||
710 | } | ||
711 | |||
740 | // reset hover status for next frame | 712 | // reset hover status for next frame |
741 | mNeedsHighlight = FALSE; | 713 | mNeedsHighlight = FALSE; |
742 | } | 714 | } |
743 | 715 | ||
744 | void LLButton::drawBorder(const LLColor4& color, S32 size) | 716 | void LLButton::drawBorder(const LLColor4& color, S32 size) |
745 | { | 717 | { |
746 | S32 left = -size; | ||
747 | S32 top = getRect().getHeight() + size; | ||
748 | S32 right = getRect().getWidth() + size; | ||
749 | S32 bottom = -size; | ||
750 | |||
751 | if (mImagep.isNull()) | ||
752 | { | ||
753 | gl_rect_2d(left, top, right, bottom, color, FALSE); | ||
754 | return; | ||
755 | } | ||
756 | |||
757 | if (mScaleImage) | 718 | if (mScaleImage) |
758 | { | 719 | { |
759 | mImagep->drawSolid(left, bottom, right-left, top-bottom, color); | 720 | mImagep->drawBorder(getLocalRect(), color, size); |
760 | } | 721 | } |
761 | else | 722 | else |
762 | { | 723 | { |
763 | mImagep->drawSolid(left, bottom, mImagep->getWidth() + size * 2, mImagep->getHeight() + size * 2, color); | 724 | mImagep->drawBorder(0, 0, color, size); |
764 | } | 725 | } |
765 | } | 726 | } |
766 | 727 | ||
@@ -778,9 +739,8 @@ void LLButton::setToggleState(BOOL b) | |||
778 | { | 739 | { |
779 | if( b != mToggleState ) | 740 | if( b != mToggleState ) |
780 | { | 741 | { |
781 | mToggleState = b; | 742 | setControlValue(b); // will fire LLControlVariable callbacks (if any) |
782 | LLValueChangedEvent *evt = new LLValueChangedEvent(this, mToggleState); | 743 | mToggleState = b; // may or may not be redundant |
783 | fireEvent(evt, ""); | ||
784 | } | 744 | } |
785 | } | 745 | } |
786 | 746 | ||
@@ -924,7 +884,7 @@ void LLButton::setImageOverlay(const LLString &image_name, LLFontGL::HAlign alig | |||
924 | } | 884 | } |
925 | else | 885 | else |
926 | { | 886 | { |
927 | mImageOverlay = LLUI::getUIImageByName(image_name); | 887 | mImageOverlay = LLUI::getUIImage(image_name); |
928 | mImageOverlayAlignment = alignment; | 888 | mImageOverlayAlignment = alignment; |
929 | mImageOverlayColor = color; | 889 | mImageOverlayColor = color; |
930 | } | 890 | } |
@@ -957,37 +917,37 @@ S32 round_up(S32 grid, S32 value) | |||
957 | 917 | ||
958 | void LLButton::setImageUnselected(const LLString &image_name) | 918 | void LLButton::setImageUnselected(const LLString &image_name) |
959 | { | 919 | { |
960 | setImageUnselected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); | 920 | setImageUnselected(LLUI::getUIImage(image_name)); |
961 | mImageUnselectedName = image_name; | 921 | mImageUnselectedName = image_name; |
962 | } | 922 | } |
963 | 923 | ||
964 | void LLButton::setImageSelected(const LLString &image_name) | 924 | void LLButton::setImageSelected(const LLString &image_name) |
965 | { | 925 | { |
966 | setImageSelected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); | 926 | setImageSelected(LLUI::getUIImage(image_name)); |
967 | mImageSelectedName = image_name; | 927 | mImageSelectedName = image_name; |
968 | } | 928 | } |
969 | 929 | ||
970 | void LLButton::setImageHoverSelected(const LLString &image_name) | 930 | void LLButton::setImageHoverSelected(const LLString &image_name) |
971 | { | 931 | { |
972 | setImageHoverSelected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); | 932 | setImageHoverSelected(LLUI::getUIImage(image_name)); |
973 | mImageHoverSelectedName = image_name; | 933 | mImageHoverSelectedName = image_name; |
974 | } | 934 | } |
975 | 935 | ||
976 | void LLButton::setImageHoverUnselected(const LLString &image_name) | 936 | void LLButton::setImageHoverUnselected(const LLString &image_name) |
977 | { | 937 | { |
978 | setImageHoverUnselected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); | 938 | setImageHoverUnselected(LLUI::getUIImage(image_name)); |
979 | mImageHoverUnselectedName = image_name; | 939 | mImageHoverUnselectedName = image_name; |
980 | } | 940 | } |
981 | 941 | ||
982 | void LLButton::setImageDisabled(const LLString &image_name) | 942 | void LLButton::setImageDisabled(const LLString &image_name) |
983 | { | 943 | { |
984 | setImageDisabled(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); | 944 | setImageDisabled(LLUI::getUIImage(image_name)); |
985 | mImageDisabledName = image_name; | 945 | mImageDisabledName = image_name; |
986 | } | 946 | } |
987 | 947 | ||
988 | void LLButton::setImageDisabledSelected(const LLString &image_name) | 948 | void LLButton::setImageDisabledSelected(const LLString &image_name) |
989 | { | 949 | { |
990 | setImageDisabledSelected(image_name.empty() ? NULL : LLUI::getUIImageByName(image_name)); | 950 | setImageDisabledSelected(LLUI::getUIImage(image_name)); |
991 | mImageDisabledSelectedName = image_name; | 951 | mImageDisabledSelectedName = image_name; |
992 | } | 952 | } |
993 | 953 | ||
@@ -1038,7 +998,7 @@ void clicked_help(void* data) | |||
1038 | return; | 998 | return; |
1039 | } | 999 | } |
1040 | 1000 | ||
1041 | LLUI::sHtmlHelp->show(self->getHelpURL(), ""); | 1001 | LLUI::sHtmlHelp->show(self->getHelpURL()); |
1042 | } | 1002 | } |
1043 | 1003 | ||
1044 | // static | 1004 | // static |