From 406195e4f20e0bea341c8a7a979b56a8259b8536 Mon Sep 17 00:00:00 2001 From: Leslie Linden Date: Tue, 24 May 2011 09:38:49 -0700 Subject: Added badges version 0.1 to buttons. Reviewed by Richard --- indra/llui/llbutton.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 4 deletions(-) (limited to 'indra/llui/llbutton.cpp') diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp index 45ceaff696..a63281b3c1 100644 --- a/indra/llui/llbutton.cpp +++ b/indra/llui/llbutton.cpp @@ -56,6 +56,9 @@ static LLDefaultChildRegistry::Register r("button"); template class LLButton* LLView::getChild( const std::string& name, BOOL recurse) const; + + + // globals loaded from settings.xml S32 LLBUTTON_H_PAD = 0; S32 BTN_HEIGHT_SMALL= 0; @@ -99,7 +102,8 @@ LLButton::Params::Params() scale_image("scale_image", true), hover_glow_amount("hover_glow_amount"), commit_on_return("commit_on_return", true), - use_draw_context_alpha("use_draw_context_alpha", true) + use_draw_context_alpha("use_draw_context_alpha", true), + badge("badge") { addSynonym(is_toggle, "toggle"); held_down_delay.seconds = 0.5f; @@ -160,8 +164,8 @@ LLButton::LLButton(const LLButton::Params& p) mMouseDownSignal(NULL), mMouseUpSignal(NULL), mHeldDownSignal(NULL), - mUseDrawContextAlpha(p.use_draw_context_alpha) - + mUseDrawContextAlpha(p.use_draw_context_alpha), + mBadge(NULL) { static LLUICachedControl llbutton_orig_h_pad ("UIButtonOrigHPad", 0); static Params default_params(LLUICtrlFactory::getDefaultParams()); @@ -244,6 +248,17 @@ LLButton::LLButton(const LLButton::Params& p) { setHeldDownCallback(initCommitCallback(p.mouse_held_callback)); } + + // Only create a badge here if a non-default one was provided. + if (p.badge.isProvided()) + { + if (!p.badge().equals(LLUICtrlFactory::getDefaultParams())) + { + LLBadge::Params badge_params(p.badge()); + badge_params.owner = getUICtrlHandle(); + mBadge = LLUICtrlFactory::create(badge_params); + } + } } LLButton::~LLButton() @@ -327,6 +342,13 @@ boost::signals2::connection LLButton::setHeldDownCallback( button_callback_t cb, BOOL LLButton::postBuild() { autoResize(); + + // Attach the badge to the appropriate parent panel + if (mBadge) + { + addBadgeToParentPanel(); + } + return TRUE; } BOOL LLButton::handleUnicodeCharHere(llwchar uni_char) @@ -867,7 +889,7 @@ void LLButton::draw() S32_MAX, text_width, NULL, mUseEllipses); } - + LLUICtrl::draw(); } @@ -1063,6 +1085,70 @@ void LLButton::setImageOverlay(const LLUUID& image_id, LLFontGL::HAlign alignmen } } +void LLButton::addBadgeToParentPanel() +{ + if (mBadge) + { + // Find the appropriate parent panel for the badge + + LLPanel * parentPanel = NULL; + LLUICtrl * parent = getParentUICtrl(); + + while (parent) + { + parentPanel = dynamic_cast(parent); + + if (parentPanel != NULL) + { + break; + } + + parent = parent->getParentUICtrl(); + } + + if (parentPanel) + { + parentPanel->addChild(mBadge); + } + else + { + llwarns << "Unable to find parent panel for badge " << mBadge->getName() << " on button " << getName() << llendl; + } + } + else + { + llwarns << "Unable to add NULL badge to button " << getName() << llendl; + } +} + +void LLButton::setBadgeLabel(const LLStringExplicit& label) +{ + if (mBadge == NULL) + { + LLBadge::Params badge_params(LLUICtrlFactory::getDefaultParams()); + badge_params.owner = getUICtrlHandle(); + mBadge = LLUICtrlFactory::create(badge_params); + + addBadgeToParentPanel(); + } + + if (mBadge) + { + mBadge->setLabel(label); + + // + // Push the badge to the front so it renders last + // + + LLUICtrl * parent = mBadge->getParentUICtrl(); + + if (parent) + { + parent->sendChildToFront(mBadge); + } + } +} + void LLButton::onMouseCaptureLost() { resetMouseDownTimer(); -- cgit v1.2.3