Ticket #12604: BButton-Augment-12604.patch

File BButton-Augment-12604.patch, 4.0 KB (added by looncraz, 8 years ago)

Augmented Patch - SetButtonColor, SetLabelColor

  • headers/os/interface/Button.h

    From 6fbedc2a890f926e9d1597a4c092078eb85cdb47 Mon Sep 17 00:00:00 2001
    From: looncraz <looncraz@looncraz.net>
    Date: Mon, 11 Jul 2016 04:53:33 +0000
    Subject: [PATCH] Add BButton SetButtonColor and SetLabelColor
    
    Also corrects ticket# 12604
    
    Usage of the new methods requires an active attachment to a window or
    view, otherwise the colors will become overridden by the default
    AttachedToWindow() logic.  A debugger call is made to make this failure
    obvious.
    
    In the future, adding two rgb_color members for the colors will be preferred,
    for now there is no ABI room.
    ---
     headers/os/interface/Button.h | 38 ++++++++++++++++++++++++++++++
     src/kits/interface/Button.cpp | 54 +++++++++++++++++++++++++++++++++++++++----
     2 files changed, 88 insertions(+), 4 deletions(-)
    
    diff --git a/headers/os/interface/Button.h b/headers/os/interface/Button.h
    index 71dfac5..aba1341 100644
    a b public:  
    8383
    8484    virtual status_t            SetIcon(const BBitmap* icon, uint32 flags = 0);
    8585
     86    virtual void                SetHighColor(rgb_color color);
     87    virtual void                SetLowColor(rgb_color color);
     88
     89            void                SetButtonColor(rgb_color color);
     90            void                SetButtonColor(uchar red, uchar green,
     91                                    uchar blue, uchar alpha = 255);
     92
     93            void                SetLabelColor(rgb_color color);
     94            void                SetLabelColor(uchar red, uchar green,
     95                                    uchar blue, uchar alpha = 255);
     96
    8697protected:
    8798    virtual void                LayoutInvalidated(bool descendants = false);
    8899
    private:  
    108119};
    109120
    110121
     122// #pragma mark - inline definitions
     123
     124
     125inline void
     126BButton::SetButtonColor(uchar red, uchar green, uchar blue, uchar alpha)
     127{
     128    rgb_color color;
     129    color.red = red;
     130    color.green = green;
     131    color.blue = blue;
     132    color.alpha = alpha;
     133    SetButtonColor(color);
     134}
     135
     136
     137inline void
     138BButton::SetLabelColor(uchar red, uchar green, uchar blue, uchar alpha)
     139{
     140    rgb_color color;
     141    color.red = red;
     142    color.green = green;
     143    color.blue = blue;
     144    color.alpha = alpha;
     145    SetLabelColor(color);
     146}
     147
     148
    111149#endif  // _BUTTON_H
  • src/kits/interface/Button.cpp

    diff --git a/src/kits/interface/Button.cpp b/src/kits/interface/Button.cpp
    index 6d3fd4b..babe619 100644
    a b enum {  
    3232    FLAG_FLAT           = 0x02,
    3333    FLAG_INSIDE         = 0x04,
    3434    FLAG_WAS_PRESSED    = 0x08,
     35    FLAG_CUSTOM_COLORS  = 0x10,
     36    FLAG_ATTACHED       = 0x20,
    3537};
    3638
    3739
    BButton::Draw(BRect updateRect)  
    137139    rgb_color base = LowColor();
    138140    rgb_color textColor = HighColor();
    139141
     142    if (!_Flag(FLAG_CUSTOM_COLORS)) {
     143        textColor = ui_color(B_CONTROL_TEXT_COLOR);
     144        base = tint_color(ui_color(B_CONTROL_BACKGROUND_COLOR), 1.115);
     145    }
     146
    140147    uint32 flags = be_control_look->Flags(this);
    141148    if (_Flag(FLAG_DEFAULT))
    142149        flags |= BControlLook::B_DEFAULT_BUTTON;
    BButton::MouseDown(BPoint where)  
    226233    }
    227234}
    228235
     236
    229237void
    230238BButton::AttachedToWindow()
    231239{
    232240    BControl::AttachedToWindow();
    233241
    234     // Tint default control background color to match default panel background.
    235     SetLowUIColor(B_CONTROL_BACKGROUND_COLOR, 1.115);
    236     SetHighUIColor(B_CONTROL_TEXT_COLOR);
    237 
    238242    if (IsDefault())
    239243        Window()->SetDefaultButton(this);
     244
     245    _SetFlag(FLAG_ATTACHED, true);
    240246}
    241247
    242248
    void  
    418424BButton::DetachedFromWindow()
    419425{
    420426    BControl::DetachedFromWindow();
     427
     428    _SetFlag(FLAG_ATTACHED, false);
    421429}
    422430
    423431
    BButton::SetIcon(const BBitmap* icon, uint32 flags)  
    618626
    619627
    620628void
     629BButton::SetHighColor(rgb_color color)
     630{
     631    // Disabled.
     632}
     633
     634
     635void
     636BButton::SetLowColor(rgb_color color)
     637{
     638    // Disabled.
     639}
     640
     641
     642void
     643BButton::SetButtonColor(rgb_color color)
     644{
     645    if (!_Flag(FLAG_ATTACHED))
     646        debugger("BButton must be attached to parent!");
     647
     648    _SetFlag(FLAG_CUSTOM_COLORS, true);
     649    BView::SetLowColor(color);
     650    Invalidate();
     651}
     652
     653
     654void
     655BButton::SetLabelColor(rgb_color color)
     656{
     657    if (!_Flag(FLAG_ATTACHED))
     658        debugger("BButton must be attached to parent!");
     659
     660    _SetFlag(FLAG_CUSTOM_COLORS, true);
     661    BView::SetHighColor(color);
     662    Invalidate();
     663}
     664
     665
     666void
    621667BButton::LayoutInvalidated(bool descendants)
    622668{
    623669    // invalidate cached preferred size