Set up LLButton::Params and LLButton::initFromParams

This commit is contained in:
Lirusaito
2019-01-21 09:27:03 -05:00
parent bde8782328
commit 54cf0a6a91
2 changed files with 274 additions and 120 deletions

View File

@@ -61,67 +61,92 @@ S32 BTN_HEIGHT = 0;
S32 BTN_GRID = 12;
S32 BORDER_SIZE = 1;
LLButton::Params::Params()
: label_selected("label_selected"), // requires is_toggle true
label_shadow("label_shadow", true),
auto_resize("auto_resize", false),
use_ellipses("use_ellipses", false),
image_unselected("image_unselected", LLUI::getUIImage("button_enabled_32x128.tga")),
image_selected("image_selected", LLUI::getUIImage("button_enabled_selected_32x128.tga")),
image_hover_selected("image_hover_selected"),
image_hover_unselected("image_hover_unselected"),
image_disabled_selected("image_disabled_selected", LLUI::getUIImage("button_disabled_32x128.tga")),
image_disabled("image_disabled", LLUI::getUIImage("button_disabled_32x128.tga")),
image_pressed("image_pressed", LLUI::getUIImage("button_enabled_selected_32x128.tga")),
image_pressed_selected("image_pressed_selected", LLUI::getUIImage("button_enabled_32x128.tga")),
image_overlay("image_overlay"),
image_overlay_selected("image_overlay_selected"),
image_overlay_alignment("image_overlay_alignment", std::string("center")),
image_overlay_enable("image_overlay_enable", true),
label_color("label_color", LLUI::sColorsGroup->getColor("ButtonLabelColor")),
label_color_selected("label_color_selected", LLUI::sColorsGroup->getColor("ButtonLabelSelectedColor")),
label_color_disabled("label_color_disabled", LLUI::sColorsGroup->getColor("ButtonLabelDisabledColor")),
label_color_disabled_selected("label_color_disabled_selected", LLUI::sColorsGroup->getColor("ButtonLabelSelectedDisabledColor")),
image_color("image_color", LLUI::sColorsGroup->getColor("ButtonImageColor")), // requires is_toggle true
image_color_disabled("image_color_disabled", LLUI::sColorsGroup->getColor("ButtonImageColor")),
image_overlay_color("image_overlay_color", LLColor4::white),
image_overlay_selected_color("image_overlay_selected_color", LLColor4::white),
image_overlay_disabled_color("image_overlay_disabled_color", LLColor4(1.f, 1.f, 1.f, .5f)),
flash_color("flash_color", LLUI::sColorsGroup->getColor("ButtonFlashBgColor")),
pad_right("pad_right", LLUI::sConfigGroup->getS32("ButtonHPad")),
pad_left("pad_left", LLUI::sConfigGroup->getS32("ButtonHPad")),
pad_bottom("pad_bottom", LLUI::sConfigGroup->getS32("ButtonVPad")),
image_top_pad("image_top_pad"),
image_bottom_pad("image_bottom_pad"),
imgoverlay_label_space("imgoverlay_label_space", 1),
click_callback("click_callback"),
mouse_down_callback("mouse_down_callback"),
mouse_up_callback("mouse_up_callback"),
mouse_held_callback("mouse_held_callback"),
is_toggle("is_toggle", false),
scale_image("scale_image", true),
commit_on_return("commit_on_return", true),
display_pressed_state("display_pressed_state", true),
hover_glow_amount("hover_glow_amount", 0.25f),
//held_down_delay("held_down_delay"),
use_draw_context_alpha("use_draw_context_alpha", true),
//badge("badge"),
handle_right_mouse("handle_right_mouse", false),
button_flash_enable("button_flash_enable", false),
button_flash_count("button_flash_count", LLUI::sConfigGroup->getS32("ButtonFlashCount")),
button_flash_rate("button_flash_rate", LLUI::sConfigGroup->getF32("ButtonFlashRate")),
fade_when_disabled("fade_when_disabled", false),
help_url("help_url")
{
addSynonym(is_toggle, "toggle");
changeDefault(initial_value, LLSD(false));
changeDefault(font_halign, LLFontGL::HCENTER);
}
LLButton::LLButton( const std::string& name, const LLRect& rect, const std::string& control_name, commit_callback_t commit_callback)
: LLUICtrl(name, rect, TRUE, commit_callback),
mMouseDownFrame( 0 ),
mMouseDownFrame(0),
mMouseHeldDownCount(0),
mBorderEnabled( FALSE ),
mFlashing( FALSE ),
mBorderEnabled(FALSE),
mFlashing(FALSE),
mCurGlowStrength(0.f),
mNeedsHighlight(FALSE),
mUnselectedLabel(name),
mSelectedLabel(name),
mGLFont( LLFontGL::getFontSansSerif() ),
mHeldDownDelay( 0.5f ), // seconds until held-down callback is called
mHeldDownFrameDelay( 0 ),
mImageUnselected(LLUI::getUIImage("button_enabled_32x128.tga")),
mImageSelected(LLUI::getUIImage("button_enabled_selected_32x128.tga")),
mImageDisabled(LLUI::getUIImage("button_disabled_32x128.tga")),
mImageDisabledSelected(LLUI::getUIImage("button_disabled_32x128.tga")),
mImagePressed(LLUI::getUIImage("button_enabled_selected_32x128.tga")),
mImagePressedSelected(LLUI::getUIImage("button_enabled_32x128.tga")),
mHeldDownDelay(0.5f), // seconds until held-down callback is called
mHeldDownFrameDelay(0),
mImageFlash(NULL),
mImageHoverSelected( NULL ),
mImageHoverUnselected( NULL ),
mUnselectedLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelColor" )),
mSelectedLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelSelectedColor")),
mDisabledLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelDisabledColor")),
mDisabledSelectedLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelSelectedDisabledColor")),
mImageColor(LLUI::sColorsGroup->getColor("ButtonImageColor")),
mFlashBgColor(LLUI::sColorsGroup->getColor("ButtonFlashBgColor")),
mDisabledImageColor(LLUI::sColorsGroup->getColor("ButtonImageColor")),
mImageOverlay(NULL),
mImageOverlaySelected(NULL),
mImageOverlayColor(LLColor4::white),
mImageOverlayDisabledColor(LLColor4(1.f,1.f,1.f,.5f)),
mImageOverlaySelectedColor(LLColor4::white),
mImageOverlayAlignment(LLFontGL::HCENTER),
mImageOverlayTopPad(0),
mImageOverlayBottomPad(0),
mImgOverlayLabelSpace(1),
mIsToggle( FALSE ),
mScaleImage( TRUE ),
mDropShadowedText( TRUE ),
mAutoResize( FALSE ),
mHAlign( LLFontGL::HCENTER ),
mLeftHPad( LLBUTTON_H_PAD ),
mRightHPad( LLBUTTON_H_PAD ),
mBottomVPad( LLBUTTON_V_PAD ),
mHoverGlowStrength(0.25f),
mCommitOnReturn(TRUE),
mFadeWhenDisabled(FALSE),
mDropShadowedText(TRUE),
mForcePressedState(false),
mDisplayPressedState(TRUE),
mMouseDownSignal(NULL),
mMouseUpSignal(NULL),
mHeldDownSignal(NULL),
mHandleRightMouse(false),
mButtonFlashCount(LLUI::sConfigGroup->getS32("ButtonFlashCount")),
mButtonFlashRate(LLUI::sConfigGroup->getF32("ButtonFlashRate")),
mAlpha(1.f)
mAlpha(1.f),
mMouseDownSignal(nullptr),
mMouseUpSignal(nullptr),
mHeldDownSignal(nullptr)
{
init(control_name);
Params params;
params.label_selected(name)
.label(name)
.control_name(control_name)
.name(name)
.rect(rect);
initFromParams(params);
}
@@ -134,93 +159,133 @@ LLButton::LLButton(const std::string& name, const LLRect& rect,
const std::string& unselected_label,
const std::string& selected_label )
: LLUICtrl(name, rect, TRUE, commit_callback),
mMouseDownFrame( 0 ),
mMouseDownFrame(0),
mMouseHeldDownCount(0),
mBorderEnabled( FALSE ),
mFlashing( FALSE ),
mBorderEnabled(FALSE),
mFlashing(FALSE),
mCurGlowStrength(0.f),
mNeedsHighlight(FALSE),
mUnselectedLabel(unselected_label),
mSelectedLabel(selected_label),
mGLFont( font ? font : LLFontGL::getFontSansSerif() ),
mHeldDownDelay( 0.5f ), // seconds until held-down callback is called
mHeldDownFrameDelay( 0 ),
mImageUnselected(LLUI::getUIImage("button_enabled_32x128.tga")),
mImageSelected(LLUI::getUIImage("button_enabled_selected_32x128.tga")),
mImageDisabled(LLUI::getUIImage("button_disabled_32x128.tga")),
mImageDisabledSelected(LLUI::getUIImage("button_disabled_32x128.tga")),
mImagePressed(LLUI::getUIImage("button_enabled_selected_32x128.tga")),
mImagePressedSelected(LLUI::getUIImage("button_enabled_32x128.tga")),
mHeldDownDelay(0.5f), // seconds until held-down callback is called
mHeldDownFrameDelay(0),
mImageFlash(NULL),
mImageHoverSelected( NULL ),
mImageHoverUnselected( NULL ),
mUnselectedLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelColor" )),
mSelectedLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelSelectedColor")),
mDisabledLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelDisabledColor")),
mDisabledSelectedLabelColor(LLUI::sColorsGroup->getColor("ButtonLabelSelectedDisabledColor")),
mImageColor(LLUI::sColorsGroup->getColor("ButtonImageColor")),
mFlashBgColor(LLUI::sColorsGroup->getColor("ButtonFlashBgColor")),
mDisabledImageColor(LLUI::sColorsGroup->getColor("ButtonImageColor")),
mImageOverlay(NULL),
mImageOverlaySelected(NULL),
mImageOverlayColor(LLColor4::white),
mImageOverlayDisabledColor(LLColor4(1.f,1.f,1.f,.5f)),
mImageOverlaySelectedColor(LLColor4::white),
mImageOverlayAlignment(LLFontGL::HCENTER),
mImageOverlayTopPad(0),
mImageOverlayBottomPad(0),
mImgOverlayLabelSpace(1),
mIsToggle( FALSE ),
mScaleImage( TRUE ),
mDropShadowedText( TRUE ),
mAutoResize( FALSE ),
mHAlign( LLFontGL::HCENTER ),
mLeftHPad( LLBUTTON_H_PAD ),
mRightHPad( LLBUTTON_H_PAD ),
mBottomVPad( LLBUTTON_V_PAD ),
mHoverGlowStrength(0.25f),
mCommitOnReturn(TRUE),
mFadeWhenDisabled(FALSE),
mDropShadowedText(TRUE),
mForcePressedState(false),
mDisplayPressedState(TRUE),
mMouseDownSignal(NULL),
mMouseUpSignal(NULL),
mHeldDownSignal(NULL),
mHandleRightMouse(false),
mButtonFlashCount(LLUI::sConfigGroup->getS32("ButtonFlashCount")),
mButtonFlashRate(LLUI::sConfigGroup->getF32("ButtonFlashRate")),
mAlpha(1.f)
mAlpha(1.f),
mMouseDownSignal(nullptr),
mMouseUpSignal(nullptr),
mHeldDownSignal(nullptr)
{
Params params;
params.label_selected(selected_label)
.label(unselected_label)
.font(font)
.control_name(control_name)
.name(name)
.rect(rect);
if( unselected_image_name != "" )
if (!unselected_image_name.empty())
{
// user-specified image - don't use fixed borders unless requested
mImageUnselected = LLUI::getUIImage(unselected_image_name);
mImageDisabled = mImageUnselected;
auto image = LLUI::getUIImage(unselected_image_name);
params.image_unselected(image)
.image_disabled(image)
.image_pressed_selected(image)
mFadeWhenDisabled = TRUE;
//mScaleImage = FALSE;
mImagePressedSelected = mImageUnselected;
.fade_when_disabled(true);
//params.scale_image(false);
}
if( selected_image_name != "" )
if (!selected_image_name.empty())
{
// user-specified image - don't use fixed borders unless requested
mImageSelected = LLUI::getUIImage(selected_image_name);
mImageDisabledSelected = mImageSelected;
auto image = LLUI::getUIImage(selected_image_name);
params.image_selected(image)
.image_disabled_selected(image)
.image_pressed(image)
mFadeWhenDisabled = TRUE;
//mScaleImage = FALSE;
mImagePressed = mImageSelected;
.fade_when_disabled(true);
//params.scale_image(false);
}
init(control_name);
initFromParams(params);
}
void LLButton::init(const std::string& control_name)
LLButton::LLButton(const Params& params)
: LLUICtrl(params),
mMouseDownFrame(0),
mMouseHeldDownCount(0),
mBorderEnabled(FALSE),
mFlashing(FALSE),
mCurGlowStrength(0.f),
mNeedsHighlight(FALSE),
mHeldDownDelay(0.5f), // seconds until held-down callback is called
mHeldDownFrameDelay(0),
mImageFlash(NULL),
mImageOverlayTopPad(0),
mImageOverlayBottomPad(0),
mImgOverlayLabelSpace(1),
mDropShadowedText(TRUE),
mForcePressedState(false),
mAlpha(1.f),
mMouseDownSignal(nullptr),
mMouseUpSignal(nullptr),
mHeldDownSignal(nullptr)
{
initFromParams(params);
}
void LLButton::initFromParams(const Params& params)
{
LLUICtrl::initFromParams(params);
mUnselectedLabel = params.label;
mSelectedLabel = params.label_selected;
auto font = params.font();
mGLFont = font ? font : LLFontGL::getFontSansSerif();
mHAlign = params.font_halign;
mImageUnselected = params.image_unselected;
mImageSelected = params.image_selected;
mImageDisabled = params.image_disabled;
mImageDisabledSelected = params.image_disabled_selected;
mImagePressed = params.image_pressed;
mImagePressedSelected = params.image_pressed_selected;
mImageHoverSelected = params.image_hover_selected;
mImageHoverUnselected = params.image_hover_unselected;
mUnselectedLabelColor = params.label_color;
mSelectedLabelColor = params.label_color_selected;
mDisabledLabelColor = params.label_color_disabled;
mDisabledSelectedLabelColor = params.label_color_disabled_selected;
mImageColor = params.image_color;
mFlashBgColor = params.flash_color;
mDisabledImageColor = params.image_color_disabled;
mImageOverlay = params.image_overlay;
mImageOverlaySelected = params.image_overlay_selected;
mImageOverlayColor = params.image_overlay_color;
mImageOverlayDisabledColor = params.image_overlay_disabled_color;
mImageOverlaySelectedColor = params.image_overlay_selected_color;
mImageOverlayAlignment = LLFontGL::hAlignFromName(params.image_overlay_alignment);
mIsToggle = params.is_toggle;
mScaleImage = params.scale_image;
mAutoResize = params.auto_resize;
mLeftHPad = params.pad_left;
mRightHPad = params.pad_right;
mBottomVPad = params.pad_bottom;
mHoverGlowStrength = params.hover_glow_amount;
mCommitOnReturn = params.commit_on_return;
mFadeWhenDisabled = params.fade_when_disabled;
mDisplayPressedState = params.display_pressed_state;
if (params.mouse_down_callback.isProvided())
setMouseDownCallback(params.mouse_down_callback);
if (params.mouse_up_callback.isProvided())
setMouseUpCallback(params.mouse_up_callback);
if (params.mouse_held_callback.isProvided())
setHeldDownCallback(params.mouse_held_callback);
mHandleRightMouse = params.handle_right_mouse;
mButtonFlashCount = params.button_flash_count;
mButtonFlashRate = params.button_flash_rate;
// Hack to make sure there is space for at least one character
if (getRect().getWidth() - (mRightHPad + mLeftHPad) < mGLFont->getWidth(std::string(" ")))
{
@@ -231,9 +296,16 @@ void LLButton::init(const std::string& control_name)
mMouseDownTimer.stop();
setControlName(control_name, NULL);
setControlName(params.control_name, NULL);
}
//static
const LLButton::Params& LLButton::getDefaultParams()
{
// Singu Note: We diverge here, not using LLUICtrlFactory::getDefaultParams
static const Params p;
return p;
}
// virtual
LLButton::~LLButton()

View File

@@ -74,6 +74,87 @@ class LLButton
: public LLUICtrl
{
public:
struct Params
: public LLInitParam::Block<Params, LLUICtrl::Params>
{
// text label
Optional<std::string> label_selected;
Optional<bool> label_shadow;
Optional<bool> auto_resize;
Optional<bool> use_ellipses;
// images
Optional<LLUIImage*> image_unselected,
image_selected,
image_hover_selected,
image_hover_unselected,
image_disabled_selected,
image_disabled,
image_flash,
image_pressed,
image_pressed_selected,
image_overlay,
image_overlay_selected;
Optional<std::string> image_overlay_alignment;
Optional<bool> image_overlay_enable;
// colors
Optional<LLUIColor> label_color,
label_color_selected,
label_color_disabled,
label_color_disabled_selected,
image_color,
image_color_disabled,
image_overlay_color,
image_overlay_selected_color,
image_overlay_disabled_color,
flash_color;
// layout
Optional<S32> pad_right;
Optional<S32> pad_left;
Optional<S32> pad_bottom; // under text label
//image overlay paddings
Optional<S32> image_top_pad;
Optional<S32> image_bottom_pad;
/**
* Space between image_overlay and label
*/
Optional<S32> imgoverlay_label_space;
// callbacks
Optional<CommitCallbackParam> click_callback, // alias -> commit_callback
mouse_down_callback,
mouse_up_callback,
mouse_held_callback;
// misc
Optional<bool> is_toggle,
scale_image,
commit_on_return,
display_pressed_state;
Optional<F32> hover_glow_amount;
//Optional<TimeIntervalParam> held_down_delay;
Optional<bool> use_draw_context_alpha;
//Optional<LLBadge::Params> badge;
Optional<bool> handle_right_mouse;
Optional<bool> button_flash_enable;
Optional<S32> button_flash_count;
Optional<F32> button_flash_rate;
Optional<bool> fade_when_disabled;
Optional<std::string> help_url;
Params();
};
// simple button with text label
LLButton(const std::string& name, const LLRect &rect = LLRect(), const std::string& control_name = std::string(),
commit_callback_t commit_callback = NULL);
@@ -86,6 +167,11 @@ public:
const LLFontGL* mGLFont = NULL,
const std::string& unselected_label = LLStringUtil::null,
const std::string& selected_label = LLStringUtil::null );
void initFromParams(const Params& p);
static const LLButton::Params& getDefaultParams();
LLButton(const Params& p = getDefaultParams());
public:
~LLButton();
@@ -93,7 +179,6 @@ public:
typedef boost::function<void(void*)> button_callback_t;
void addImageAttributeToXML(LLXMLNodePtr node, const LLPointer<LLUIImage>, const std::string& xmlTagName) const;
void init(const std::string& control_name);
virtual LLXMLNodePtr getXML(bool save_children = true) const;
static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
@@ -161,7 +246,6 @@ public:
const std::string getLabelUnselected() const { return wstring_to_utf8str(mUnselectedLabel); }
const std::string getLabelSelected() const { return wstring_to_utf8str(mSelectedLabel); }
void setImageColor(const std::string& color_control);
void setImageColor(const LLColor4& c);
/*virtual*/ void setColor(const LLColor4& c);
@@ -205,9 +289,7 @@ public:
void setImageDisabled(LLPointer<LLUIImage> image);
void setImageDisabledSelected(LLPointer<LLUIImage> image);
void setImageFlash(LLPointer<LLUIImage> image);
void setImagePressed(LLPointer<LLUIImage> image);
static void onHeldDown(void *userdata); // to be called by gIdleCallbacks
void setHelpURLCallback(const std::string &help_url);
const std::string& getHelpURL() const { return mHelpURL; }