LLButton* LLToastNotifyPanel::createButton(const LLSD& form_element, BOOL is_option) { InstanceAndS32* userdata = new InstanceAndS32; userdata->mSelf = this; userdata->mButtonName = is_option ? form_element["name"].asString() : ""; mBtnCallbackData.push_back(userdata); LLButton::Params p; bool make_small_btn = form_element["index"].asInteger() == -1 || form_element["index"].asInteger() == -2; const LLFontGL* font = make_small_btn ? sFontSmall: sFont; // for block and ignore buttons in script dialog p.name = form_element["name"].asString(); p.label = form_element["text"].asString(); p.font = font; p.rect.height = BTN_HEIGHT; p.click_callback.function(boost::bind(&LLToastNotifyPanel::onClickButton, userdata)); p.rect.width = BUTTON_WIDTH; p.auto_resize = false; p.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM); p.enabled = !form_element.has("enabled") || form_element["enabled"].asBoolean(); if (mIsCaution) { p.image_color(LLUIColorTable::instance().getColor("ButtonCautionImageColor")); p.image_color_disabled(LLUIColorTable::instance().getColor("ButtonCautionImageColor")); } // for the scriptdialog buttons we use fixed button size. This is a limit! if (!mIsScriptDialog && font->getWidth(form_element["text"].asString()) > BUTTON_WIDTH) { p.rect.width = 1; p.auto_resize = true; } else if (mIsScriptDialog && make_small_btn) { // this is ignore button, make it smaller p.rect.height = BTN_HEIGHT_SMALL; p.rect.width = 1; p.auto_resize = true; } LLButton* btn = LLUICtrlFactory::create<LLButton>(p); mNumButtons++; btn->autoResize(); if (form_element["default"].asBoolean()) { setDefaultBtn(btn); } return btn; }
LLButton* LLSideTray::createButton (const std::string& name,const std::string& image,const std::string& tooltip, LLUICtrl::commit_callback_t callback) { static LLSideTray::Params sidetray_params(LLUICtrlFactory::getDefaultParams<LLSideTray>()); LLButton::Params bparams; LLRect rect; rect.setOriginAndSize(0, 0, sidetray_params.default_button_width, sidetray_params.default_button_height); bparams.name(name); bparams.follows.flags (FOLLOWS_LEFT | FOLLOWS_TOP); bparams.rect (rect); bparams.tab_stop(false); bparams.image_unselected(sidetray_params.tab_btn_image_normal); bparams.image_selected(sidetray_params.tab_btn_image_selected); bparams.image_disabled(sidetray_params.tab_btn_image_normal); bparams.image_disabled_selected(sidetray_params.tab_btn_image_selected); LLButton* button; if (name == "sidebar_openclose") { // "Open/Close" button shouldn't allow "tear off" // hence it is created as LLButton instance. button = LLUICtrlFactory::create<LLButton>(bparams); } else { button = LLUICtrlFactory::create<LLSideTrayButton>(bparams); } button->setClickedCallback(callback); button->setToolTip(tooltip); if(image.length()) { button->setImageOverlay(image); } mButtonsPanel->addChildInBack(button); return button; }
void LLToastScriptQuestion::createButtons() { LLNotificationFormPtr form = mNotification->getForm(); int num_elements = form->getNumElements(); int buttons_width = 0; for (int i = 0; i < num_elements; ++i) { LLSD form_element = form->getElement(i); if ("button" == form_element["type"].asString()) { LLButton::Params p; const LLFontGL* font = LLFontGL::getFontSansSerif(); p.name(form_element["name"].asString()); p.label(form_element["text"].asString()); p.layout("topleft"); p.font(font); p.rect.height(BUTTON_HEIGHT); p.click_callback.function(boost::bind(&LLToastScriptQuestion::onButtonClicked, this, form_element["name"].asString())); p.rect.left = LEFT_PAD; p.rect.width = font->getWidth(form_element["text"].asString()); p.auto_resize = true; p.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM); p.image_color(LLUIColorTable::instance().getColor("ButtonCautionImageColor")); p.image_color_disabled(LLUIColorTable::instance().getColor("ButtonCautionImageColor")); LLButton* button = LLUICtrlFactory::create<LLButton>(p); button->autoResize(); getChild<LLPanel>("buttons_panel")->addChild(button); LLRect rect = button->getRect(); rect.setLeftTopAndSize(buttons_width, rect.mTop, rect.getWidth(), rect.getHeight()); button->setRect(rect); buttons_width += rect.getWidth() + LEFT_PAD; } } }
LLButton::LLButton(const LLButton::Params& p) : LLUICtrl(p), mMouseDownFrame(0), mMouseHeldDownCount(0), mBorderEnabled( FALSE ), mFlashing( FALSE ), mCurGlowStrength(0.f), mNeedsHighlight(FALSE), mMouseOver(false), mUnselectedLabel(p.label()), mSelectedLabel(p.label_selected()), mGLFont(p.font), mHeldDownDelay(p.held_down_delay.seconds), // seconds until held-down callback is called mHeldDownFrameDelay(p.held_down_delay.frames), mImageUnselected(p.image_unselected), mImageSelected(p.image_selected), mImageDisabled(p.image_disabled), mImageDisabledSelected(p.image_disabled_selected), mImageFlash(p.image_flash), mImagePressed(p.image_pressed), mImagePressedSelected(p.image_pressed_selected), mImageHoverSelected(p.image_hover_selected), mImageHoverUnselected(p.image_hover_unselected), mUnselectedLabelColor(p.label_color()), mSelectedLabelColor(p.label_color_selected()), mDisabledLabelColor(p.label_color_disabled()), mDisabledSelectedLabelColor(p.label_color_disabled_selected()), mHighlightColor(p.highlight_color()), mImageColor(p.image_color()), mFlashBgColor(p.flash_color()), mDisabledImageColor(p.image_color_disabled()), mImageOverlay(p.image_overlay()), mImageOverlayColor(p.image_overlay_color()), mImageOverlayAlignment(LLFontGL::hAlignFromName(p.image_overlay_alignment)), mImageOverlayTopPad(p.image_top_pad), mImageOverlayBottomPad(p.image_bottom_pad), mImgOverlayLabelSpace(p.imgoverlay_label_space), mIsToggle(p.is_toggle), mScaleImage(p.scale_image), mDropShadowedText(p.label_shadow), mAutoResize(p.auto_resize), mUseEllipses( p.use_ellipses ), mHAlign(p.font_halign), mLeftHPad(p.pad_left), mRightHPad(p.pad_right), mBottomVPad(p.pad_bottom), mHoverGlowStrength(p.hover_glow_amount), mCommitOnReturn(p.commit_on_return), mFadeWhenDisabled(FALSE), mForcePressedState(false), mLastDrawCharsCount(0), mMouseDownSignal(NULL), mMouseUpSignal(NULL), mHeldDownSignal(NULL) { static LLUICachedControl<S32> llbutton_orig_h_pad ("UIButtonOrigHPad", 0); static Params default_params(LLUICtrlFactory::getDefaultParams<LLButton>()); if (!p.label_selected.isProvided()) { mSelectedLabel = mUnselectedLabel; } // Hack to make sure there is space for at least one character if (getRect().getWidth() - (mRightHPad + mLeftHPad) < mGLFont->getWidth(std::string(" "))) { // Use old defaults mLeftHPad = llbutton_orig_h_pad; mRightHPad = llbutton_orig_h_pad; } mMouseDownTimer.stop(); // if custom unselected button image provided... if (p.image_unselected != default_params.image_unselected) { //...fade it out for disabled image by default... if (p.image_disabled() == default_params.image_disabled() ) { mImageDisabled = p.image_unselected; mFadeWhenDisabled = TRUE; } if (p.image_pressed_selected == default_params.image_pressed_selected) { mImagePressedSelected = mImageUnselected; } } // if custom selected button image provided... if (p.image_selected != default_params.image_selected) { //...fade it out for disabled image by default... if (p.image_disabled_selected() == default_params.image_disabled_selected()) { mImageDisabledSelected = p.image_selected; mFadeWhenDisabled = TRUE; } if (p.image_pressed == default_params.image_pressed) { mImagePressed = mImageSelected; } } if (!p.image_pressed.isProvided()) { mImagePressed = mImageSelected; } if (!p.image_pressed_selected.isProvided()) { mImagePressedSelected = mImageUnselected; } if (mImageUnselected.isNull()) { llwarns << "Button: " << getName() << " with no image!" << llendl; } if (p.click_callback.isProvided()) { setCommitCallback(initCommitCallback(p.click_callback)); // alias -> commit_callback } if (p.mouse_down_callback.isProvided()) { setMouseDownCallback(initCommitCallback(p.mouse_down_callback)); } if (p.mouse_up_callback.isProvided()) { setMouseUpCallback(initCommitCallback(p.mouse_up_callback)); } if (p.mouse_held_callback.isProvided()) { setHeldDownCallback(initCommitCallback(p.mouse_held_callback)); } }
LLCheckBoxCtrl::LLCheckBoxCtrl(const LLCheckBoxCtrl::Params& p) : LLUICtrl(p), mTextEnabledColor(p.label_text.text_color()), mTextDisabledColor(p.label_text.text_readonly_color()), mFont(p.font()) { mViewModel->setValue(LLSD(p.initial_value)); mViewModel->resetDirty(); static LLUICachedControl<S32> llcheckboxctrl_spacing ("UICheckboxctrlSpacing", 0); static LLUICachedControl<S32> llcheckboxctrl_hpad ("UICheckboxctrlHPad", 0); static LLUICachedControl<S32> llcheckboxctrl_vpad ("UICheckboxctrlVPad", 0); static LLUICachedControl<S32> llcheckboxctrl_btn_size ("UICheckboxctrlBtnSize", 0); // must be big enough to hold all children setUseBoundingRect(TRUE); // *HACK Get rid of this with SL-55508... // this allows blank check boxes and radio boxes for now std::string local_label = p.label; if(local_label.empty()) { local_label = " "; } LLTextBox::Params tbparams = p.label_text; tbparams.initial_value(local_label); if (p.font.isProvided()) { tbparams.font(p.font); } mLabel = LLUICtrlFactory::create<LLTextBox> (tbparams); mLabel->reshapeToFitText(); addChild(mLabel); LLRect label_rect = mLabel->getRect(); // Button // Note: button cover the label by extending all the way to the right. LLRect btn_rect = p.check_button.rect(); btn_rect.setOriginAndSize( btn_rect.mLeft, btn_rect.mBottom, llmax(btn_rect.mRight, label_rect.mRight - btn_rect.mLeft), llmax( label_rect.getHeight(), btn_rect.mTop)); std::string active_true_id, active_false_id; std::string inactive_true_id, inactive_false_id; LLButton::Params params = p.check_button; params.rect(btn_rect); //params.control_name(p.control_name); params.click_callback.function(boost::bind(&LLCheckBoxCtrl::onButtonPress, this, _2)); params.commit_on_return(false); // Checkboxes only allow boolean initial values, but buttons can // take any LLSD. params.initial_value(LLSD(p.initial_value)); params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM); mButton = LLUICtrlFactory::create<LLButton>(params); addChild(mButton); // <FS:Ansariel> on_check callback parameter if (p.on_check.isProvided()) { setCheckCallback(initEnableCallback(p.on_check)); } // </FS:Ansariel> }
LLButton::LLButton(const LLButton::Params& p) : LLUICtrl(p), LLBadgeOwner(getHandle()), mMouseDownFrame(0), mMouseHeldDownCount(0), mBorderEnabled( FALSE ), mFlashing( FALSE ), mCurGlowStrength(0.f), mNeedsHighlight(FALSE), mUnselectedLabel(p.label()), mSelectedLabel(p.label_selected()), mGLFont(p.font), mHeldDownDelay(p.held_down_delay.seconds), // seconds until held-down callback is called mHeldDownFrameDelay(p.held_down_delay.frames), mImageUnselected(p.image_unselected), mImageSelected(p.image_selected), mImageDisabled(p.image_disabled), mImageDisabledSelected(p.image_disabled_selected), mImageFlash(p.image_flash), mImagePressed(p.image_pressed), mImagePressedSelected(p.image_pressed_selected), mImageHoverSelected(p.image_hover_selected), mImageHoverUnselected(p.image_hover_unselected), mUnselectedLabelColor(p.label_color()), mSelectedLabelColor(p.label_color_selected()), mDisabledLabelColor(p.label_color_disabled()), mDisabledSelectedLabelColor(p.label_color_disabled_selected()), mImageColor(p.image_color()), mFlashBgColor(p.flash_color()), mDisabledImageColor(p.image_color_disabled()), mImageOverlay(p.image_overlay()), mImageOverlayColor(p.image_overlay_color()), mImageOverlayDisabledColor(p.image_overlay_disabled_color()), mImageOverlaySelectedColor(p.image_overlay_selected_color()), mImageOverlayAlignment(LLFontGL::hAlignFromName(p.image_overlay_alignment)), mImageOverlayTopPad(p.image_top_pad), mImageOverlayBottomPad(p.image_bottom_pad), mImgOverlayLabelSpace(p.imgoverlay_label_space), mIsToggle(p.is_toggle), mScaleImage(p.scale_image), mDropShadowedText(p.label_shadow), mAutoResize(p.auto_resize), mUseEllipses( p.use_ellipses ), mHAlign(p.font_halign), mLeftHPad(p.pad_left), mRightHPad(p.pad_right), mBottomVPad(p.pad_bottom), mHoverGlowStrength(p.hover_glow_amount), mCommitOnReturn(p.commit_on_return), mFadeWhenDisabled(FALSE), mForcePressedState(false), mDisplayPressedState(p.display_pressed_state), mLastDrawCharsCount(0), mMouseDownSignal(NULL), mMouseUpSignal(NULL), mHeldDownSignal(NULL), mUseDrawContextAlpha(p.use_draw_context_alpha), mHandleRightMouse(p.handle_right_mouse), // <FS:Zi> Add checkbox control toggle //mFlashingTimer(NULL) mFlashingTimer(NULL), mCheckboxControl(p.checkbox_control), mCheckboxControlPanel(NULL) // </FS:Zi> { if (p.button_flash_enable) { // If optional parameter "p.button_flash_count" is not provided, LLFlashTimer will be // used instead it a "default" value from gSavedSettings.getS32("FlashCount")). // 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; mFlashingTimer = new LLFlashTimer ((LLFlashTimer::callback_t)NULL, flash_count, flash_rate); } else { mButtonFlashCount = p.button_flash_count; mButtonFlashRate = p.button_flash_rate; } static LLUICachedControl<S32> llbutton_orig_h_pad ("UIButtonOrigHPad", 0); static Params default_params(LLUICtrlFactory::getDefaultParams<LLButton>()); if (!p.label_selected.isProvided()) { mSelectedLabel = mUnselectedLabel; } // Hack to make sure there is space for at least one character if (getRect().getWidth() - (mRightHPad + mLeftHPad) < mGLFont->getWidth(std::string(" "))) { // Use old defaults mLeftHPad = llbutton_orig_h_pad; mRightHPad = llbutton_orig_h_pad; } mMouseDownTimer.stop(); // if custom unselected button image provided... if (p.image_unselected != default_params.image_unselected) { //...fade it out for disabled image by default... if (p.image_disabled() == default_params.image_disabled() ) { mImageDisabled = p.image_unselected; mFadeWhenDisabled = TRUE; } if (p.image_pressed_selected == default_params.image_pressed_selected) { mImagePressedSelected = mImageUnselected; } } // if custom selected button image provided... if (p.image_selected != default_params.image_selected) { //...fade it out for disabled image by default... if (p.image_disabled_selected() == default_params.image_disabled_selected()) { mImageDisabledSelected = p.image_selected; mFadeWhenDisabled = TRUE; } if (p.image_pressed == default_params.image_pressed) { mImagePressed = mImageSelected; } } if (!p.image_pressed.isProvided()) { mImagePressed = mImageSelected; } if (!p.image_pressed_selected.isProvided()) { mImagePressedSelected = mImageUnselected; } if (mImageUnselected.isNull()) { LL_WARNS() << "Button: " << getName() << " with no image!" << LL_ENDL; } if (p.click_callback.isProvided()) { setCommitCallback(initCommitCallback(p.click_callback)); // alias -> commit_callback } if (p.mouse_down_callback.isProvided()) { setMouseDownCallback(initCommitCallback(p.mouse_down_callback)); } if (p.mouse_up_callback.isProvided()) { setMouseUpCallback(initCommitCallback(p.mouse_up_callback)); } if (p.mouse_held_callback.isProvided()) { setHeldDownCallback(initCommitCallback(p.mouse_held_callback)); } if (p.badge.isProvided()) { LLBadgeOwner::initBadgeParams(p.badge()); } }
LLCheckBoxCtrl::LLCheckBoxCtrl(const LLCheckBoxCtrl::Params& p) : LLUICtrl(p), mTextEnabledColor(p.text_enabled_color()), mTextDisabledColor(p.text_disabled_color()), mFont(p.font()) { mViewModel->setValue(LLSD(p.initial_value)); mViewModel->resetDirty(); static LLUICachedControl<S32> llcheckboxctrl_spacing ("UICheckboxctrlSpacing", 0); static LLUICachedControl<S32> llcheckboxctrl_hpad ("UICheckboxctrlHPad", 0); static LLUICachedControl<S32> llcheckboxctrl_vpad ("UICheckboxctrlVPad", 0); static LLUICachedControl<S32> llcheckboxctrl_btn_size ("UICheckboxctrlBtnSize", 0); // must be big enough to hold all children setUseBoundingRect(TRUE); // Label (add a little space to make sure text actually renders) const S32 FUDGE = 10; S32 text_width = mFont->getWidth( p.label ) + FUDGE; S32 text_height = llround(mFont->getLineHeight()); LLRect label_rect; label_rect.setOriginAndSize( llcheckboxctrl_hpad + llcheckboxctrl_btn_size + llcheckboxctrl_spacing, llcheckboxctrl_vpad + 1, // padding to get better alignment text_width + llcheckboxctrl_hpad, text_height ); // *HACK Get rid of this with SL-55508... // this allows blank check boxes and radio boxes for now std::string local_label = p.label; if(local_label.empty()) { local_label = " "; } LLTextBox::Params tbparams = p.label_text; tbparams.rect(label_rect); tbparams.initial_value(local_label); if (p.font.isProvided()) { tbparams.font(p.font); } tbparams.text_color( p.enabled() ? p.text_enabled_color() : p.text_disabled_color() ); mLabel = LLUICtrlFactory::create<LLTextBox> (tbparams); addChild(mLabel); // Button // Note: button cover the label by extending all the way to the right. LLRect btn_rect; btn_rect.setOriginAndSize( llcheckboxctrl_hpad, llcheckboxctrl_vpad, llcheckboxctrl_btn_size + llcheckboxctrl_spacing + text_width + llcheckboxctrl_hpad, llmax( text_height, llcheckboxctrl_btn_size() ) + llcheckboxctrl_vpad); std::string active_true_id, active_false_id; std::string inactive_true_id, inactive_false_id; LLButton::Params params = p.check_button; params.rect(btn_rect); //params.control_name(p.control_name); params.click_callback.function(boost::bind(&LLCheckBoxCtrl::onButtonPress, this, _2)); params.commit_on_return(false); // Checkboxes only allow boolean initial values, but buttons can // take any LLSD. params.initial_value(LLSD(p.initial_value)); params.follows.flags(FOLLOWS_LEFT | FOLLOWS_BOTTOM); mButton = LLUICtrlFactory::create<LLButton>(params); addChild(mButton); }
LLDebugVarMessageBox::LLDebugVarMessageBox(const std::string& title, EDebugVarType var_type, void *var) : LLFloater(LLSD()), mVarType(var_type), mVarData(var), mAnimate(FALSE) { setRect(LLRect(10,160,400,10)); LLSliderCtrl::Params slider_p; slider_p.label(title); slider_p.label_width(70); slider_p.text_width(40); slider_p.can_edit_text(true); slider_p.show_text(true); mSlider1 = NULL; mSlider2 = NULL; mSlider3 = NULL; switch(var_type) { case VAR_TYPE_F32: slider_p.name("slider 1"); slider_p.rect(LLRect(20,130,190,110)); slider_p.initial_value(*((F32*)var)); slider_p.min_value(-100.f); slider_p.max_value(100.f); slider_p.increment(0.1f); slider_p.decimal_digits(3); mSlider1 = LLUICtrlFactory::create<LLSliderCtrl>(slider_p); addChild(mSlider1); break; case VAR_TYPE_S32: slider_p.name("slider 1"); slider_p.rect(LLRect(20,100,190,80)); slider_p.initial_value((F32)*((S32*)var)); slider_p.min_value(-255.f); slider_p.max_value(255.f); slider_p.increment(1.f); slider_p.decimal_digits(0); mSlider1 = LLUICtrlFactory::create<LLSliderCtrl>(slider_p); addChild(mSlider1); break; case VAR_TYPE_VEC3: slider_p.name("slider 1"); slider_p.label("x: "); slider_p.rect(LLRect(20,130,190,110)); slider_p.initial_value(((LLVector3*)var)->mV[VX]); slider_p.min_value(-100.f); slider_p.max_value(100.f); slider_p.increment(0.1f); slider_p.decimal_digits(3); mSlider1 = LLUICtrlFactory::create<LLSliderCtrl>(slider_p); slider_p.name("slider 2"); slider_p.label("y: "); slider_p.rect(LLRect(20,100,190,80)); slider_p.initial_value(((LLVector3*)var)->mV[VY]); mSlider2 = LLUICtrlFactory::create<LLSliderCtrl>(slider_p); slider_p.name("slider 3"); slider_p.label("z: "); slider_p.rect(LLRect(20,70,190,50)); slider_p.initial_value(((LLVector3*)var)->mV[VZ]); mSlider2 = LLUICtrlFactory::create<LLSliderCtrl>(slider_p); addChild(mSlider1); addChild(mSlider2); addChild(mSlider3); break; default: llwarns << "Unhandled var type " << var_type << llendl; break; } LLButton::Params p; p.name(std::string("Animate")); p.label(std::string("Animate")); p.rect(LLRect(20, 45, 180, 25)); p.click_callback.function(boost::bind(&LLDebugVarMessageBox::onAnimateClicked, this, _2)); mAnimateButton = LLUICtrlFactory::create<LLButton>(p); addChild(mAnimateButton); LLTextBox::Params params; params.name("value"); params.initial_value(params.name()); params.rect(LLRect(20,20,190,0)); mText = LLUICtrlFactory::create<LLTextBox> (params); addChild(mText); //disable hitting enter closes dialog setDefaultBtn(); }