Ticket #7330: 0001-PowerStatus-New-Extended-info-window-s-layout.patch

File 0001-PowerStatus-New-Extended-info-window-s-layout.patch, 11.7 KB (added by KapiX, 8 years ago)
  • src/apps/powerstatus/ExtendedInfoWindow.cpp

    From 168bde0a953fadeb721267f697515662f54a63b9 Mon Sep 17 00:00:00 2001
    From: Kacper Kasper <kacperkasper@gmail.com>
    Date: Sun, 11 Sep 2016 12:46:01 +0000
    Subject: [PATCH] PowerStatus: New Extended info window's layout.
    
    * Fixes #7330.
    ---
     src/apps/powerstatus/ExtendedInfoWindow.cpp | 87 ++++++++++++++++-------------
     src/apps/powerstatus/ExtendedInfoWindow.h   | 11 +++-
     src/apps/powerstatus/PowerStatusView.cpp    | 60 ++++++++++----------
     src/apps/powerstatus/PowerStatusView.h      |  3 +-
     src/apps/powerstatus/PowerStatusWindow.cpp  |  4 +-
     5 files changed, 89 insertions(+), 76 deletions(-)
    
    diff --git a/src/apps/powerstatus/ExtendedInfoWindow.cpp b/src/apps/powerstatus/ExtendedInfoWindow.cpp
    index 543fb87..9f8cdf1 100644
    a b  
    11/*
    2  * Copyright 2009-2015, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2009-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    2020
    2121
    2222const int kLineSpacing = 5;
     23const float kBorderMargin = 10.0f;
    2324
    2425
    2526FontString::FontString()
    BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo)  
    6061void
    6162BatteryInfoView::Draw(BRect updateRect)
    6263{
    63     SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     64    float fontHeight = _MeasureString("").height;
     65    BPoint point(0.0f, kBorderMargin + fontHeight);
    6466
    65     BPoint point(10, 10);
    66 
    67     float space = _MeasureString("").height + kLineSpacing;
     67    float space = fontHeight + kLineSpacing;
    6868
    6969    for (int i = 0; i < fStringList.CountItems(); i++) {
    7070        FontString* fontString = fStringList.ItemAt(i);
    BatteryInfoView::_FillStringList()  
    235235    fontString->string += fBatteryExtendedInfo.oem_info;
    236236    _AddToStringList(fontString);
    237237
    238     fPreferredSize.width = fMaxStringSize.width + 10;
     238    fPreferredSize.width = fMaxStringSize.width + kBorderMargin;
    239239    fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) *
    240         fStringList.CountItems();
     240        fStringList.CountItems() - kLineSpacing + kBorderMargin * 2;
    241241}
    242242
    243243
    ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface,  
    279279void
    280280ExtPowerStatusView::Draw(BRect updateRect)
    281281{
    282     if (fSelected)
    283         SetLowColor(102, 152, 203);
    284     else
    285         SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     282    // TODO: Use BeginLayer/EndLayer when #12937 is fixed
     283    if (fDriverInterface->GetBatteryCount() > 1) {
     284        if(fSelected == true) {
     285            fAlpha = 255;
     286        } else {
     287            fAlpha = 100;
     288        }
     289    }
    286290
    287291    PowerStatusView::Draw(updateRect);
    288292}
    ExtPowerStatusView::Update(bool force)  
    334338//  #pragma mark -
    335339
    336340
     341BatteryView::BatteryView(BLayout* layout)
     342    :
     343    BView("battery view", B_WILL_DRAW | B_DRAW_ON_CHILDREN, layout)
     344{
     345}
     346
     347
     348void
     349BatteryView::Draw(BRect updateRect)
     350{
     351    SetHighUIColor(B_PANEL_BACKGROUND_COLOR, B_DARKEN_2_TINT);
     352    BRect drawBounds(Bounds());
     353    drawBounds.right /= 2;
     354    FillRect(drawBounds);
     355}
     356
     357
     358//  #pragma mark -
     359
     360
    337361ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
    338362    :
    339363    BWindow(BRect(100, 150, 500, 500), B_TRANSLATE("Extended battery info"),
    ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)  
    345369{
    346370    fDriverInterface->AcquireReference();
    347371
    348     BView *view = new BView(Bounds(), "view", B_FOLLOW_ALL, 0);
    349     view->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
    350     AddChild(view);
    351 
    352     BGroupLayout* mainLayout = new BGroupLayout(B_VERTICAL);
    353     mainLayout->SetSpacing(10);
    354     mainLayout->SetInsets(10, 10, 10, 10);
    355     view->SetLayout(mainLayout);
    356 
    357     BRect rect = Bounds();
    358     rect.InsetBy(5, 5);
    359     BBox *infoBox = new BBox(rect, B_TRANSLATE("Power status box"));
    360     infoBox->SetLabel(B_TRANSLATE("Battery info"));
    361     BGroupLayout* infoLayout = new BGroupLayout(B_HORIZONTAL);
    362     infoLayout->SetInsets(10, infoBox->TopBorderOffset() * 2 + 10, 10, 10);
    363     infoLayout->SetSpacing(10);
    364     infoBox->SetLayout(infoLayout);
    365     mainLayout->AddView(infoBox);
    366 
    367     BGroupView* batteryView = new BGroupView(B_VERTICAL);
    368     batteryView->GroupLayout()->SetSpacing(10);
    369     infoLayout->AddView(batteryView);
    370 
    371     // create before the battery views
     372    BGroupLayout* mainLayout = new BGroupLayout(B_HORIZONTAL, 0);
     373    SetLayout(mainLayout);
     374
     375    BGroupLayout* batteryLayout = new BGroupLayout(B_VERTICAL, kBorderMargin);
     376    batteryLayout->SetInsets(kBorderMargin);
     377
     378    BatteryView* batteryView = new BatteryView(batteryLayout);
     379    mainLayout->AddView(batteryView);
     380
    372381    fBatteryInfoView = new BatteryInfoView();
     382    mainLayout->AddView(fBatteryInfoView);
    373383
    374     BGroupLayout* batteryLayout = batteryView->GroupLayout();
    375384    BRect batteryRect(0, 0, 50, 30);
    376385    for (int i = 0; i < interface->GetBatteryCount(); i++) {
    377386        ExtPowerStatusView* view = new ExtPowerStatusView(interface,
    378387            batteryRect, B_FOLLOW_NONE, i, this);
    379         view->SetExplicitMaxSize(BSize(70, 80));
    380         view->SetExplicitMinSize(BSize(70, 80));
     388        view->SetExplicitMaxSize(BSize(70, 70));
     389        view->SetExplicitMinSize(BSize(70, 70));
    381390
    382391        batteryLayout->AddView(view);
    383392        fBatteryViewList.AddItem(view);
    ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)  
    388397
    389398    batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
    390399
    391     infoLayout->AddView(fBatteryInfoView);
    392 
    393400    if (!fSelectedView && fBatteryViewList.CountItems() > 0)
    394401        fSelectedView = fBatteryViewList.ItemAt(0);
    395402    fSelectedView->Select();
  • src/apps/powerstatus/ExtendedInfoWindow.h

    diff --git a/src/apps/powerstatus/ExtendedInfoWindow.h b/src/apps/powerstatus/ExtendedInfoWindow.h
    index 82b8748..15139d2 100644
    a b  
    11/*
    2  * Copyright 2009, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2009-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    private:  
    8383};
    8484
    8585
     86class BatteryView : public BView
     87{
     88public:
     89            BatteryView(BLayout* layout);
     90
     91    void    Draw(BRect updateRect);
     92};
     93
     94
    8695class ExtendedInfoWindow : public BWindow
    8796{
    8897public:
  • src/apps/powerstatus/PowerStatusView.cpp

    diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp
    index 8e8dc34..d114feb 100644
    a b  
    11/*
    2  * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2006-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    PowerStatusView::_Init()  
    111111    fPercent = 100;
    112112    fOnline = true;
    113113    fTimeLeft = 0;
     114    fAlpha = 255;
    114115}
    115116
    116117
    PowerStatusView::MessageReceived(BMessage *message)  
    155156void
    156157PowerStatusView::_DrawBattery(BRect rect)
    157158{
     159    SetDrawingMode(B_OP_ALPHA);
    158160    float quarter = floorf((rect.Height() + 1) / 4);
    159161    rect.top += quarter;
    160162    rect.bottom -= quarter;
    PowerStatusView::_DrawBattery(BRect rect)  
    165167    rect.left += rect.Width() / 11;
    166168
    167169    if (LowColor().Brightness() > 100)
    168         SetHighColor(0, 0, 0);
     170        SetHighColor(0, 0, 0, fAlpha);
    169171    else
    170         SetHighColor(128, 128, 128);
     172        SetHighColor(128, 128, 128, fAlpha);
    171173
    172174    float gap = 1;
    173175    if (rect.Height() > 8) {
    PowerStatusView::_DrawBattery(BRect rect)  
    198200
    199201    if (percent > 0) {
    200202        rect.InsetBy(gap, gap);
    201         rgb_color base = (rgb_color){84, 84, 84, 255};
     203        rgb_color base = (rgb_color){84, 84, 84, fAlpha};
    202204        if (LowColor().Brightness() < 128)
    203             base = (rgb_color){172, 172, 172, 255};
     205            base = (rgb_color){172, 172, 172, fAlpha};
    204206
    205207        if (be_control_look != NULL) {
    206208            BRect empty = rect;
    PowerStatusView::_DrawBattery(BRect rect)  
    218220
    219221        if (fHasBattery) {
    220222            if (percent <= kLowBatteryPercentage)
    221                 base.set_to(180, 0, 0);
     223                base.set_to(180, 0, 0, fAlpha);
    222224            else if (percent <= kNoteBatteryPercentage)
    223                 base.set_to(200, 140, 0);
     225                base.set_to(200, 140, 0, fAlpha);
    224226            else
    225                 base.set_to(20, 180, 0);
     227                base.set_to(20, 180, 0, fAlpha);
    226228
    227229            rect.right = rect.left + rect.Width() * percent / 100.0;
    228230
    PowerStatusView::_DrawBattery(BRect rect)  
    236238
    237239    if (fOnline) {
    238240        // When charging, draw a lightning symbol over the battery.
    239         SetHighColor(255, 255, 0, 180);
    240         SetDrawingMode(B_OP_ALPHA);
     241        float alphaPercent = ((180 / 255.0f) * (fAlpha / 255.0f));
     242        uint8 alpha = static_cast<uint8>(alphaPercent * 255);
     243        SetHighColor(255, 255, 0, alpha);
    241244        SetScale(std::min(Bounds().Width(), Bounds().Height()) / 16);
    242245
    243246        static const BPoint points[] = {
    PowerStatusView::_DrawBattery(BRect rect)  
    251254        FillPolygon(points, 6);
    252255
    253256        SetScale(1);
    254         SetDrawingMode(B_OP_OVER);
    255257    }
    256258
    257     SetHighColor(0, 0, 0);
     259    SetHighColor(0, 0, 0, fAlpha);
     260    SetDrawingMode(B_OP_OVER);
    258261}
    259262
    260263
    261264void
    262265PowerStatusView::Draw(BRect updateRect)
    263266{
    264     bool drawBackground = Parent() == NULL
    265         || (Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0;
    266     if (drawBackground)
    267         FillRect(updateRect, B_SOLID_LOW);
    268 
    269     float aspect = Bounds().Width() / Bounds().Height();
    270     bool below = aspect <= 1.0f;
     267    bool inside = Bounds().Width() >= 70.0f && Bounds().Height() >= 40.0f;
    271268
    272269    font_height fontHeight;
    273270    GetFontHeight(&fontHeight);
    PowerStatusView::Draw(BRect updateRect)  
    285282    if (fShowStatusIcon) {
    286283        iconRect = Bounds();
    287284        if (showLabel) {
    288             if (below)
    289                 iconRect.bottom -= textHeight + 4;
    290             else
     285            if (inside == false)
    291286                iconRect.right -= textWidth + 4;
    292287        }
    293288
    PowerStatusView::Draw(BRect updateRect)  
    308303        BPoint point(0, baseLine);
    309304
    310305        if (iconRect.IsValid()) {
    311             if (below) {
    312                 point.x = (iconRect.Width() - textWidth) / 2;
    313                 point.y += iconRect.Height() + 2;
     306            if (inside == true) {
     307                point.x = (iconRect.Width() - textWidth) / 2 +
     308                    iconRect.Width() / 20;
     309                point.y += (iconRect.Height() - textHeight) / 2;
    314310            } else {
    315311                point.x = iconRect.Width() + 2;
    316312                point.y += (iconRect.Height() - textHeight) / 2;
    PowerStatusView::Draw(BRect updateRect)  
    320316            point.y += (Bounds().Height() - textHeight) / 2;
    321317        }
    322318
    323         if (drawBackground)
    324             SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
     319        SetDrawingMode(B_OP_ALPHA);
     320        if (inside == false)
     321            SetHighUIColor(B_CONTROL_TEXT_COLOR);
    325322        else {
    326             SetDrawingMode(B_OP_OVER);
    327             if (LowColor().Brightness() > 100)
    328                 SetHighColor(0, 0, 0);
    329             else
    330                 SetHighColor(255, 255, 255);
     323            SetHighColor(255, 255, 255, fAlpha);
     324            DrawString(text, BPoint(point.x + 1, point.y + 1));
     325            SetHighColor(0, 0, 0, fAlpha);
    331326        }
    332327
    333328        DrawString(text, point);
     329        SetDrawingMode(B_OP_OVER);
    334330    }
    335331}
    336332
  • src/apps/powerstatus/PowerStatusView.h

    diff --git a/src/apps/powerstatus/PowerStatusView.h b/src/apps/powerstatus/PowerStatusView.h
    index ca0d62e..220b90f 100644
    a b  
    11/*
    2  * Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2006-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
    protected:  
    6767            time_t          fTimeLeft;
    6868            bool            fOnline;
    6969            bool            fHasBattery;
     70            uint8           fAlpha;
    7071};
    7172
    7273
  • src/apps/powerstatus/PowerStatusWindow.cpp

    diff --git a/src/apps/powerstatus/PowerStatusWindow.cpp b/src/apps/powerstatus/PowerStatusWindow.cpp
    index 6333e17..7e5388c 100644
    a b  
    11/*
    2  * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
     2 * Copyright 2006-2016, Haiku, Inc. All Rights Reserved.
    33 * Distributed under the terms of the MIT License.
    44 *
    55 * Authors:
     
    1616
    1717PowerStatusWindow::PowerStatusWindow()
    1818    :
    19     BWindow(BRect(100, 150, 281, 299), B_TRANSLATE_SYSTEM_NAME("PowerStatus"),
     19    BWindow(BRect(100, 150, 250, 300), B_TRANSLATE_SYSTEM_NAME("PowerStatus"),
    2020        B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
    2121{
    2222    BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);