PowerStatus: Draw battery without BControlLook

Drawing the battery using BControlLook:DrawButtonBackground does not
work as expected with alternative ControlLook installed. Instead
draw the bevel and gradient without using BControlLook.

Renamed empty to unfilled. Replace single base color with unfilledColor
and fillColor.

unfilledColor appears to have change but it is the same #4c4c4c
(75, 75, 75) color just untinted. Specify the color using hex values.

Put all battery drawing inside the fHasBattery conditional block.

Copy rect to fill and use it to draw the filled area.

Use make_color() to make the unfilled color.

Change-Id: I615c4dc1b9e0206b4ac0259d3183fe691584209b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1967
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
John Scipione
2019-11-22 23:21:29 +00:00
committed by waddlesplash
parent 56cddb517d
commit 7586efaf07
+58 -29
View File
@@ -22,13 +22,13 @@
#include <Application.h> #include <Application.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <DataIO.h> #include <DataIO.h>
#include <Deskbar.h> #include <Deskbar.h>
#include <Dragger.h> #include <Dragger.h>
#include <Drivers.h> #include <Drivers.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <GradientLinear.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Notification.h> #include <Notification.h>
@@ -187,7 +187,8 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
gap = ceilf((rect.left - left) / 2); gap = ceilf((rect.left - left) / 2);
// left // left
view->FillRect(BRect(rect.left, rect.top, rect.left + gap - 1, rect.bottom)); view->FillRect(BRect(rect.left, rect.top, rect.left + gap - 1,
rect.bottom));
// right // right
view->FillRect(BRect(rect.right - gap + 1, rect.top, rect.right, view->FillRect(BRect(rect.right - gap + 1, rect.top, rect.right,
rect.bottom)); rect.bottom));
@@ -209,41 +210,69 @@ PowerStatusView::_DrawBattery(BView* view, BRect rect)
else if (percent < 0 || !fHasBattery) else if (percent < 0 || !fHasBattery)
percent = 0; percent = 0;
if (percent > 0) { rect.InsetBy(gap, gap);
rect.InsetBy(gap, gap);
rgb_color base = (rgb_color){84, 84, 84, 255};
if (view->LowColor().Brightness() < 128)
base = (rgb_color){172, 172, 172, 255};
if (be_control_look != NULL) { if (fHasBattery) {
BRect empty = rect; // draw unfilled area
if (fHasBattery && percent > 0) rgb_color unfilledColor = make_color(0x4c, 0x4c, 0x4c);
empty.left += empty.Width() * percent / 100.0; if (view->LowColor().Brightness() < 128) {
unfilledColor.red = 256 - unfilledColor.red;
be_control_look->DrawButtonBackground(view, empty, empty, base, unfilledColor.green = 256 - unfilledColor.green;
fHasBattery unfilledColor.blue = 256 - unfilledColor.blue;
? BControlLook::B_ACTIVATED : BControlLook::B_DISABLED,
fHasBattery && percent > 0
? (BControlLook::B_ALL_BORDERS
& ~BControlLook::B_LEFT_BORDER)
: BControlLook::B_ALL_BORDERS);
} }
if (fHasBattery) { BRect unfilled = rect;
if (percent > 0)
unfilled.left += unfilled.Width() * percent / 100.0;
view->SetHighColor(unfilledColor);
view->FillRect(unfilled);
if (percent > 0) {
// draw filled area
rgb_color fillColor;
if (percent <= kLowBatteryPercentage) if (percent <= kLowBatteryPercentage)
base.set_to(180, 0, 0); fillColor.set_to(180, 0, 0);
else if (percent <= kNoteBatteryPercentage) else if (percent <= kNoteBatteryPercentage)
base.set_to(200, 140, 0); fillColor.set_to(200, 140, 0);
else else
base.set_to(20, 180, 0); fillColor.set_to(20, 180, 0);
rect.right = rect.left + rect.Width() * percent / 100.0; BRect fill = rect;
fill.right = fill.left + fill.Width() * percent / 100.0;
if (be_control_look != NULL) { // draw bevel
be_control_look->DrawButtonBackground(view, rect, rect, base, rgb_color bevelLightColor = tint_color(fillColor, 0.2);
fHasBattery ? 0 : BControlLook::B_DISABLED); rgb_color bevelShadowColor = tint_color(fillColor, 1.08);
} else
view->FillRect(rect); view->BeginLineArray(4);
view->AddLine(BPoint(fill.left, fill.bottom),
BPoint(fill.left, fill.top), bevelLightColor);
view->AddLine(BPoint(fill.left, fill.top),
BPoint(fill.right, fill.top), bevelLightColor);
view->AddLine(BPoint(fill.right, fill.top),
BPoint(fill.right, fill.bottom), bevelShadowColor);
view->AddLine(BPoint(fill.left, fill.bottom),
BPoint(fill.right, fill.bottom), bevelShadowColor);
view->EndLineArray();
fill.InsetBy(1, 1);
// draw gradient
float topTint = 0.49;
float middleTint1 = 0.62;
float middleTint2 = 0.76;
float bottomTint = 0.90;
BGradientLinear gradient;
gradient.AddColor(tint_color(fillColor, topTint), 0);
gradient.AddColor(tint_color(fillColor, middleTint1), 132);
gradient.AddColor(tint_color(fillColor, middleTint2), 136);
gradient.AddColor(tint_color(fillColor, bottomTint), 255);
gradient.SetStart(fill.LeftTop());
gradient.SetEnd(fill.LeftBottom());
view->FillRect(fill, gradient);
} }
} }