diff options
Diffstat (limited to 'indra/llui/llbutton.cpp')
-rw-r--r-- | indra/llui/llbutton.cpp | 182 |
1 files changed, 124 insertions, 58 deletions
diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp index 16b58dcc5b..1bce31edb1 100644 --- a/indra/llui/llbutton.cpp +++ b/indra/llui/llbutton.cpp @@ -43,6 +43,8 @@ #include "llfloater.h" #include "llfloaterreg.h" #include "llfocusmgr.h" +#include "llfontgl.h" +#include "llfontvertexbuffer.h" #include "llwindow.h" #include "llnotificationsutil.h" #include "llrender.h" @@ -56,7 +58,7 @@ static LLDefaultChildRegistry::Register<LLButton> r("button"); // Compiler optimization, generate extern template template class LLButton* LLView::getChild<class LLButton>( - const std::string& name, BOOL recurse) const; + std::string_view name, bool recurse) const; // globals S32 LLBUTTON_H_PAD = 4; @@ -120,14 +122,13 @@ LLButton::Params::Params() LLButton::LLButton(const LLButton::Params& p) -: LLUICtrl(p), + : LLUICtrl(p), LLBadgeOwner(getHandle()), mMouseDownFrame(0), mMouseHeldDownCount(0), - mBorderEnabled( FALSE ), - mFlashing( FALSE ), + mFlashing( false ), mCurGlowStrength(0.f), - mNeedsHighlight(FALSE), + mNeedsHighlight(false), mUnselectedLabel(p.label()), mSelectedLabel(p.label_selected()), mGLFont(p.font), @@ -170,7 +171,7 @@ LLButton::LLButton(const LLButton::Params& p) mHoverGlowStrength(p.hover_glow_amount), mCommitOnReturn(p.commit_on_return), mCommitOnCaptureLost(p.commit_on_capture_lost), - mFadeWhenDisabled(FALSE), + mFadeWhenDisabled(false), mForcePressedState(false), mDisplayPressedState(p.display_pressed_state), mLastDrawCharsCount(0), @@ -188,7 +189,7 @@ LLButton::LLButton(const LLButton::Params& p) // Likewise, missing "p.button_flash_rate" is replaced by gSavedSettings.getF32("FlashPeriod"). // Note: flashing should be allowed in settings.xml (boolean key "EnableButtonFlashing"). S32 flash_count = p.button_flash_count.isProvided()? p.button_flash_count : 0; - F32 flash_rate = p.button_flash_rate.isProvided()? p.button_flash_rate : 0.0; + F32 flash_rate = p.button_flash_rate.isProvided()? p.button_flash_rate : 0.0f; mFlashingTimer = new LLFlashTimer ((LLFlashTimer::callback_t)NULL, flash_count, flash_rate); } else @@ -223,7 +224,7 @@ LLButton::LLButton(const LLButton::Params& p) if (p.image_disabled() == default_params.image_disabled() ) { mImageDisabled = p.image_unselected; - mFadeWhenDisabled = TRUE; + mFadeWhenDisabled = true; } if (p.image_pressed_selected == default_params.image_pressed_selected) @@ -239,7 +240,7 @@ LLButton::LLButton(const LLButton::Params& p) if (p.image_disabled_selected() == default_params.image_disabled_selected()) { mImageDisabledSelected = p.image_selected; - mFadeWhenDisabled = TRUE; + mFadeWhenDisabled = true; } if (p.image_pressed == default_params.image_pressed) @@ -329,6 +330,30 @@ void LLButton::onCommit() LLUICtrl::onCommit(); } +void LLButton::setUnselectedLabelColor(const LLUIColor& c) +{ + mUnselectedLabelColor = c; + mFontBuffer.reset(); +} + +void LLButton::setSelectedLabelColor(const LLUIColor& c) +{ + mSelectedLabelColor = c; + mFontBuffer.reset(); +} + +void LLButton::setUseEllipses(bool use_ellipses) +{ + mUseEllipses = use_ellipses; + mFontBuffer.reset(); +} + +void LLButton::setUseFontColor(bool use_font_color) +{ + mUseFontColor = use_font_color; + mFontBuffer.reset(); +} + boost::signals2::connection LLButton::setClickedCallback(const CommitCallbackParam& cb) { return setClickedCallback(initCommitCallback(cb)); @@ -387,7 +412,7 @@ boost::signals2::connection LLButton::setHeldDownCallback( button_callback_t cb, return setHeldDownCallback(boost::bind(cb, data)); } -BOOL LLButton::postBuild() +bool LLButton::postBuild() { autoResize(); @@ -396,9 +421,21 @@ BOOL LLButton::postBuild() return LLUICtrl::postBuild(); } -BOOL LLButton::handleUnicodeCharHere(llwchar uni_char) +void LLButton::onVisibilityChange(bool new_visibility) +{ + mFontBuffer.reset(); + return LLUICtrl::onVisibilityChange(new_visibility); +} + +void LLButton::dirtyRect() +{ + LLUICtrl::dirtyRect(); + mFontBuffer.reset(); +} + +bool LLButton::handleUnicodeCharHere(llwchar uni_char) { - BOOL handled = FALSE; + bool handled = false; if(' ' == uni_char && !gKeyboard->getKeyRepeated(' ')) { @@ -409,14 +446,14 @@ BOOL LLButton::handleUnicodeCharHere(llwchar uni_char) LLUICtrl::onCommit(); - handled = TRUE; + handled = true; } return handled; } -BOOL LLButton::handleKeyHere(KEY key, MASK mask ) +bool LLButton::handleKeyHere(KEY key, MASK mask ) { - BOOL handled = FALSE; + bool handled = false; if( mCommitOnReturn && KEY_RETURN == key && mask == MASK_NONE && !gKeyboard->getKeyRepeated(key)) { if (mIsToggle) @@ -424,7 +461,7 @@ BOOL LLButton::handleKeyHere(KEY key, MASK mask ) toggleState(); } - handled = TRUE; + handled = true; LLUICtrl::onCommit(); } @@ -432,7 +469,7 @@ BOOL LLButton::handleKeyHere(KEY key, MASK mask ) } -BOOL LLButton::handleMouseDown(S32 x, S32 y, MASK mask) +bool LLButton::handleMouseDown(S32 x, S32 y, MASK mask) { if (!childrenHandleMouseDown(x, y, mask)) { @@ -441,7 +478,7 @@ BOOL LLButton::handleMouseDown(S32 x, S32 y, MASK mask) if (hasTabStop() && !getIsChrome()) { - setFocus(TRUE); + setFocus(true); } if (!mFunctionName.empty()) @@ -472,11 +509,11 @@ BOOL LLButton::handleMouseDown(S32 x, S32 y, MASK mask) make_ui_sound("UISndClick"); } } - return TRUE; + return true; } -BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask) +bool LLButton::handleMouseUp(S32 x, S32 y, MASK mask) { // We only handle the click if the click both started and ended within us if( hasMouseCapture() ) @@ -521,10 +558,10 @@ BOOL LLButton::handleMouseUp(S32 x, S32 y, MASK mask) childrenHandleMouseUp(x, y, mask); } - return TRUE; + return true; } -BOOL LLButton::handleRightMouseDown(S32 x, S32 y, MASK mask) +bool LLButton::handleRightMouseDown(S32 x, S32 y, MASK mask) { if (mHandleRightMouse && !childrenHandleRightMouseDown(x, y, mask)) { @@ -533,7 +570,7 @@ BOOL LLButton::handleRightMouseDown(S32 x, S32 y, MASK mask) if (hasTabStop() && !getIsChrome()) { - setFocus(TRUE); + setFocus(true); } // if (pointInView(x, y)) @@ -546,10 +583,10 @@ BOOL LLButton::handleRightMouseDown(S32 x, S32 y, MASK mask) // if they are not mouse opaque. } - return TRUE; + return true; } -BOOL LLButton::handleRightMouseUp(S32 x, S32 y, MASK mask) +bool LLButton::handleRightMouseUp(S32 x, S32 y, MASK mask) { if (mHandleRightMouse) { @@ -575,26 +612,32 @@ BOOL LLButton::handleRightMouseUp(S32 x, S32 y, MASK mask) // but this might change the mouse handling of existing buttons in a bad way. // if they are not mouse opaque. } - return TRUE; + return true; } void LLButton::onMouseLeave(S32 x, S32 y, MASK mask) { LLUICtrl::onMouseLeave(x, y, mask); - mNeedsHighlight = FALSE; + setHighlight(false); } void LLButton::setHighlight(bool b) { - mNeedsHighlight = b; + if (mNeedsHighlight != b) + { + mNeedsHighlight = b; + mFontBuffer.reset(); + } } -BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) +bool LLButton::handleHover(S32 x, S32 y, MASK mask) { if (isInEnabledChain() && (!gFocusMgr.getMouseCapture() || gFocusMgr.getMouseCapture() == this)) - mNeedsHighlight = TRUE; + { + setHighlight(true); + } if (!childrenHandleHover(x, y, mask)) { @@ -613,7 +656,7 @@ BOOL LLButton::handleHover(S32 x, S32 y, MASK mask) getWindow()->setCursor(UI_CURSOR_ARROW); LL_DEBUGS("UserInput") << "hover handled by " << getName() << LL_ENDL; } - return TRUE; + return true; } void LLButton::getOverlayImageSize(S32& overlay_width, S32& overlay_height) @@ -633,7 +676,7 @@ void LLButton::draw() static LLCachedControl<bool> sEnableButtonFlashing(*LLUI::getInstance()->mSettingGroups["config"], "EnableButtonFlashing", true); F32 alpha = mUseDrawContextAlpha ? getDrawContext().mAlpha : getCurrentTransparency(); - bool pressed_by_keyboard = FALSE; + bool pressed_by_keyboard = false; if (hasFocus()) { pressed_by_keyboard = gKeyboard->getKeyDown(' ') || (mCommitOnReturn && gKeyboard->getKeyDown(KEY_RETURN)); @@ -655,7 +698,7 @@ void LLButton::draw() || mForcePressedState; bool selected = getToggleState(); - bool use_glow_effect = FALSE; + bool use_glow_effect = false; LLColor4 highlighting_color = LLColor4::white; LLColor4 glow_color = LLColor4::white; LLRender::eBlendType glow_type = LLRender::BT_ADD_WITH_ALPHA; @@ -687,7 +730,7 @@ void LLButton::draw() else { imagep = mImageSelected; - use_glow_effect = TRUE; + use_glow_effect = true; } } else @@ -699,7 +742,7 @@ void LLButton::draw() else { imagep = mImageUnselected; - use_glow_effect = TRUE; + use_glow_effect = true; } } } @@ -741,7 +784,7 @@ void LLButton::draw() if (mFlashingTimer) { LLColor4 flash_color = mFlashBgColor.get(); - use_glow_effect = TRUE; + use_glow_effect = true; glow_type = LLRender::BT_ALPHA; // blend the glow if (mFlashingTimer->isCurrentlyHighlighted() || !mFlashingTimer->isFlashingInProgress()) @@ -762,7 +805,7 @@ void LLButton::draw() if (mNeedsHighlight && !imagep) { - use_glow_effect = TRUE; + use_glow_effect = true; } // Figure out appropriate color for the text @@ -796,9 +839,6 @@ void LLButton::draw() if( ll::ui::SearchableControl::getHighlighted() ) label_color = ll::ui::SearchableControl::getHighlightColor(); - // Unselected label assignments - LLWString label = getCurrentLabel(); - // overlay with keyboard focus border if (hasFocus()) { @@ -850,7 +890,7 @@ void LLButton::draw() // no image LL_DEBUGS() << "No image for button " << getName() << LL_ENDL; // draw it in pink so we can find it - gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4::pink1 % alpha, FALSE); + gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0, LLColor4::pink1 % alpha, false); } // let overlay image and text play well together @@ -927,8 +967,9 @@ void LLButton::draw() } // Draw label - if( !label.empty() ) + if( !getCurrentLabel().empty() ) // Unselected label assignments { + LLWString label = getCurrentLabel(); LLWStringUtil::trim(label); S32 x; @@ -956,7 +997,7 @@ void LLButton::draw() // LLFontGL::render expects S32 max_chars variable but process in a separate way -1 value. // Due to U32_MAX is equal to S32 -1 value I have rest this value for non-ellipses mode. // Not sure if it is really needed. Probably S32_MAX should be always passed as max_chars. - mLastDrawCharsCount = mGLFont->render(label, 0, + mLastDrawCharsCount = mFontBuffer.render(mGLFont, label, 0, (F32)x, (F32)(getRect().getHeight() / 2 + mBottomVPad), label_color % alpha, @@ -984,12 +1025,12 @@ void LLButton::drawBorder(LLUIImage* imagep, const LLColor4& color, S32 size) } } -BOOL LLButton::getToggleState() const +bool LLButton::getToggleState() const { return getValue().asBoolean(); } -void LLButton::setToggleState(BOOL b) +void LLButton::setToggleState(bool b) { if( b != getToggleState() ) { @@ -998,6 +1039,7 @@ void LLButton::setToggleState(BOOL b) setFlashing(false); // stop flash state whenever the selected/unselected state if reset // Unselected label assignments autoResize(); + mFontBuffer.reset(); } } @@ -1016,7 +1058,7 @@ void LLButton::setFlashing(bool b, bool force_flashing/* = false */) } } -BOOL LLButton::toggleState() +bool LLButton::toggleState() { bool flipped = ! getToggleState(); setToggleState(flipped); @@ -1027,11 +1069,13 @@ BOOL LLButton::toggleState() void LLButton::setLabel( const std::string& label ) { mUnselectedLabel = mSelectedLabel = label; + mFontBuffer.reset(); } void LLButton::setLabel( const LLUIString& label ) { mUnselectedLabel = mSelectedLabel = label; + mFontBuffer.reset(); } void LLButton::setLabel( const LLStringExplicit& label ) @@ -1041,21 +1085,36 @@ void LLButton::setLabel( const LLStringExplicit& label ) } //virtual -BOOL LLButton::setLabelArg( const std::string& key, const LLStringExplicit& text ) +bool LLButton::setLabelArg( const std::string& key, const LLStringExplicit& text ) { mUnselectedLabel.setArg(key, text); mSelectedLabel.setArg(key, text); - return TRUE; + mFontBuffer.reset(); + return true; } void LLButton::setLabelUnselected( const LLStringExplicit& label ) { mUnselectedLabel = label; + mFontBuffer.reset(); } void LLButton::setLabelSelected( const LLStringExplicit& label ) { mSelectedLabel = label; + mFontBuffer.reset(); +} + +void LLButton::setDisabledLabelColor(const LLUIColor& c) +{ + mDisabledLabelColor = c; + mFontBuffer.reset(); +} + +void LLButton::setFont(const LLFontGL* font) +{ + mGLFont = (font ? font : LLFontGL::getFontSansSerif()); + mFontBuffer.reset(); } bool LLButton::labelIsTruncated() const @@ -1068,6 +1127,12 @@ const LLUIString& LLButton::getCurrentLabel() const return getToggleState() ? mSelectedLabel : mUnselectedLabel; } +void LLButton::setDropShadowedText(bool b) +{ + mDropShadowedText = b; + mFontBuffer.reset(); +} + void LLButton::setImageUnselected(LLPointer<LLUIImage> image) { mImageUnselected = image; @@ -1082,10 +1147,10 @@ void LLButton::autoResize() resize(getCurrentLabel()); } -void LLButton::resize(LLUIString label) +void LLButton::resize(const LLUIString& label) { // get label length - S32 label_width = mGLFont->getWidth(label.getString()); + S32 label_width = mGLFont->getWidth(label.getWString().c_str()); // get current btn length S32 btn_width =getRect().getWidth(); // check if it need resize @@ -1129,12 +1194,12 @@ void LLButton::setImageSelected(LLPointer<LLUIImage> image) mImageSelected = image; } -void LLButton::setImageColor(const LLColor4& c) +void LLButton::setImageColor(const LLUIColor& c) { mImageColor = c; } -void LLButton::setColor(const LLColor4& color) +void LLButton::setColor(const LLUIColor& color) { setImageColor(color); } @@ -1143,14 +1208,15 @@ void LLButton::setImageDisabled(LLPointer<LLUIImage> image) { mImageDisabled = image; mDisabledImageColor = mImageColor; - mFadeWhenDisabled = TRUE; + mFadeWhenDisabled = true; } void LLButton::setImageDisabledSelected(LLPointer<LLUIImage> image) { mImageDisabledSelected = image; mDisabledImageColor = mImageColor; - mFadeWhenDisabled = TRUE; + mFadeWhenDisabled = true; + mFontBuffer.reset(); } void LLButton::setImagePressed(LLPointer<LLUIImage> image) @@ -1243,11 +1309,11 @@ void LLButton::addImageAttributeToXML(LLXMLNodePtr node, { if( !image_name.empty() ) { - node->createChild(xml_tag_name.c_str(), TRUE)->setStringValue(image_name); + node->createChild(xml_tag_name.c_str(), true)->setStringValue(image_name); } else if( image_id != LLUUID::null ) { - node->createChild((xml_tag_name + "_id").c_str(), TRUE)->setUUIDValue(image_id); + node->createChild((xml_tag_name + "_id").c_str(), true)->setUUIDValue(image_id); } } @@ -1273,7 +1339,7 @@ void LLButton::setFloaterToggle(LLUICtrl* ctrl, const LLSD& sdname) // Set the button control value (toggle state) to the floater visibility control (Sets the value as well) button->setControlVariable(LLFloater::getControlGroup()->getControl(vis_control_name)); // Set the clicked callback to toggle the floater - button->setClickedCallback(boost::bind(&LLFloaterReg::toggleInstance, sdname, LLSD())); + button->setClickedCallback([=](LLUICtrl* ctrl, const LLSD& param) -> void { LLFloaterReg::toggleInstance(sdname.asString(), LLSD()); }); } // static @@ -1314,7 +1380,7 @@ void LLButton::resetMouseDownTimer() mMouseDownTimer.reset(); } -BOOL LLButton::handleDoubleClick(S32 x, S32 y, MASK mask) +bool LLButton::handleDoubleClick(S32 x, S32 y, MASK mask) { // just treat a double click as a second click return handleMouseDown(x, y, mask); |