* Worked over the battery look a bit, looks much better now IMO.

* Made the replicant transparent (for background images).
* Fixed many of Clemen's coding style violations.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32255 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-08-11 17:00:31 +00:00
parent a068dcb15a
commit bd767f5a4e
5 changed files with 268 additions and 233 deletions
+30 -28
View File
@@ -1,11 +1,12 @@
/* /*
* Copyright 2006, Haiku, Inc. All Rights Reserved. * Copyright 2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Clemens Zeidler, [email protected] * Clemens Zeidler, [email protected]
*/ */
#include "ExtendedInfoWindow.h" #include "ExtendedInfoWindow.h"
#include <Box.h> #include <Box.h>
@@ -16,18 +17,21 @@
#include <String.h> #include <String.h>
const int kLineSpacing = 5;
FontString::FontString() FontString::FontString()
{ {
font = be_plain_font; font = be_plain_font;
} }
const int kLineSpacing = 5; // #pragma mark -
BatteryInfoView::BatteryInfoView() BatteryInfoView::BatteryInfoView()
: :
BView("battery info view", B_WILL_DRAW | BView("battery info view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
B_FULL_UPDATE_ON_RESIZE),
fPreferredSize(200, 200), fPreferredSize(200, 200),
fMaxStringSize(0, 0) fMaxStringSize(0, 0)
{ {
@@ -60,8 +64,7 @@ BatteryInfoView::Draw(BRect updateRect)
float space = _MeasureString("").height + kLineSpacing; float space = _MeasureString("").height + kLineSpacing;
for (int i = 0; i < fStringList.CountItems(); i ++) for (int i = 0; i < fStringList.CountItems(); i++) {
{
FontString* fontString = fStringList.ItemAt(i); FontString* fontString = fStringList.ItemAt(i);
SetFont(fontString->font); SetFont(fontString->font);
DrawString(fontString->string.String(), point); DrawString(fontString->string.String(), point);
@@ -256,32 +259,28 @@ BatteryInfoView::_ClearStringList()
} }
// #pragma mark -
ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface, ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode, int batteryId, BRect frame, int32 resizingMode, int batteryID,
ExtendedInfoWindow* window) ExtendedInfoWindow* window)
: :
PowerStatusView(interface, frame, resizingMode, batteryId), PowerStatusView(interface, frame, resizingMode, batteryID),
fExtendedInfoWindow(window), fExtendedInfoWindow(window),
fBatteryInfoView(window->GetExtendedBatteryInfoView()), fBatteryInfoView(window->GetExtendedBatteryInfoView()),
fSelected(false) fSelected(false)
{ {
} }
void void
ExtPowerStatusView::Draw(BRect updateRect) ExtPowerStatusView::Draw(BRect updateRect)
{ {
if (fSelected) { if (fSelected)
SetLowColor(102, 152, 203); SetLowColor(102, 152, 203);
SetHighColor(102, 152, 203); else
FillRect(updateRect);
}
else {
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
FillRect(updateRect);
}
PowerStatusView::Draw(updateRect); PowerStatusView::Draw(updateRect);
} }
@@ -292,8 +291,10 @@ ExtPowerStatusView::MouseDown(BPoint where)
{ {
if (!fSelected) { if (!fSelected) {
fSelected = true; fSelected = true;
_Update(true); Update(true);
fExtendedInfoWindow->BatterySelected(this); if (ExtendedInfoWindow* window
= dynamic_cast<ExtendedInfoWindow*>(Window()))
window->BatterySelected(this);
} }
} }
@@ -302,34 +303,35 @@ void
ExtPowerStatusView::Select(bool select) ExtPowerStatusView::Select(bool select)
{ {
fSelected = select; fSelected = select;
_Update(true); Update(true);
} }
bool bool
ExtPowerStatusView::IsValid() ExtPowerStatusView::IsCritical()
{ {
if (fBatteryInfo.state & BATTERY_CRITICAL_STATE) return (fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0;
return false;
return true;
} }
void void
ExtPowerStatusView::_Update(bool force) ExtPowerStatusView::Update(bool force)
{ {
PowerStatusView::_Update(force); PowerStatusView::Update(force);
if (!fSelected) if (!fSelected)
return; return;
acpi_extended_battery_info extInfo; acpi_extended_battery_info extInfo;
fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryId); fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryID);
fBatteryInfoView->Update(fBatteryInfo, extInfo); fBatteryInfoView->Update(fBatteryInfo, extInfo);
fBatteryInfoView->Invalidate(); fBatteryInfoView->Invalidate();
} }
// #pragma mark -
ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface) ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
: :
BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW, BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW,
@@ -377,7 +379,7 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
batteryLayout->AddView(view); batteryLayout->AddView(view);
fBatteryViewList.AddItem(view); fBatteryViewList.AddItem(view);
fDriverInterface->StartWatching(view); fDriverInterface->StartWatching(view);
if (view->IsValid()) if (!view->IsCritical())
fSelectedView = view; fSelectedView = view;
} }
+12 -13
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006, Haiku, Inc. All Rights Reserved. * Copyright 2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,6 +9,7 @@
#ifndef EXTENDED_INFO_WINDOW_H #ifndef EXTENDED_INFO_WINDOW_H
#define EXTENDED_INFO_WINDOW_H #define EXTENDED_INFO_WINDOW_H
#include <ObjectList.h> #include <ObjectList.h>
#include <String.h> #include <String.h>
#include <View.h> #include <View.h>
@@ -18,8 +19,7 @@
#include "PowerStatusView.h" #include "PowerStatusView.h"
class FontString class FontString {
{
public: public:
FontString(); FontString();
@@ -28,8 +28,7 @@ public:
}; };
class BatteryInfoView : public BView class BatteryInfoView : public BView {
{
public: public:
BatteryInfoView(); BatteryInfoView();
~BatteryInfoView(); ~BatteryInfoView();
@@ -58,23 +57,23 @@ class BatteryInfoView : public BView
class ExtendedInfoWindow; class ExtendedInfoWindow;
class ExtPowerStatusView : public PowerStatusView class ExtPowerStatusView : public PowerStatusView {
{
public: public:
ExtPowerStatusView(PowerStatusDriverInterface* interface, ExtPowerStatusView(
BRect frame, int32 resizingMode, int batteryId, PowerStatusDriverInterface* interface,
ExtendedInfoWindow* window); BRect frame, int32 resizingMode,
int batteryID, ExtendedInfoWindow* window);
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void Select(bool select = true); virtual void Select(bool select = true);
// return true if it battery is in a none critical state // return true if it battery is in a critical state
virtual bool IsValid(); virtual bool IsCritical();
protected: protected:
virtual void _Update(bool force = false); virtual void Update(bool force = false);
private: private:
ExtendedInfoWindow* fExtendedInfoWindow; ExtendedInfoWindow* fExtendedInfoWindow;
+1
View File
@@ -79,6 +79,7 @@ PowerStatus::ReadyToRun()
isInstalled = deskbar.HasItem(kDeskbarItemName); isInstalled = deskbar.HasItem(kDeskbarItemName);
} }
isInstalled = true;
if (isDeskbarRunning && !isInstalled) { if (isDeskbarRunning && !isInstalled) {
BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?", BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?",
"Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); "Don't", "Install", NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
+82 -50
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006, Haiku, Inc. All Rights Reserved. * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -13,6 +13,7 @@
#include <Alert.h> #include <Alert.h>
#include <Application.h> #include <Application.h>
#include <ControlLook.h>
#include <Deskbar.h> #include <Deskbar.h>
#include <Dragger.h> #include <Dragger.h>
#include <Drivers.h> #include <Drivers.h>
@@ -43,12 +44,12 @@ const uint32 kMinIconHeight = 16;
PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface, PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode, int batteryId, bool inDeskbar) BRect frame, int32 resizingMode, int batteryID, bool inDeskbar)
: :
BView(frame, kDeskbarItemName, resizingMode, BView(frame, kDeskbarItemName, resizingMode,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fDriverInterface(interface), fDriverInterface(interface),
fBatteryId(batteryId), fBatteryID(batteryID),
fInDeskbar(inDeskbar) fInDeskbar(inDeskbar)
{ {
fPreferredSize.width = frame.Width(); fPreferredSize.width = frame.Width();
@@ -71,14 +72,12 @@ PowerStatusView::PowerStatusView(BMessage* archive)
fShowTime = value; fShowTime = value;
int32 intValue; int32 intValue;
if (archive->FindInt32("battery id", &intValue) == B_OK) if (archive->FindInt32("battery id", &intValue) == B_OK)
fBatteryId = intValue; fBatteryID = intValue;
} }
PowerStatusView::~PowerStatusView() PowerStatusView::~PowerStatusView()
{ {
} }
@@ -93,7 +92,7 @@ PowerStatusView::Archive(BMessage* archive, bool deep) const
if (status == B_OK) if (status == B_OK)
status = archive->AddBool("show time", fShowTime); status = archive->AddBool("show time", fShowTime);
if (status == B_OK) if (status == B_OK)
status = archive->AddInt32("battery id", fBatteryId); status = archive->AddInt32("battery id", fBatteryID);
return status; return status;
} }
@@ -102,6 +101,8 @@ PowerStatusView::Archive(BMessage* archive, bool deep) const
void void
PowerStatusView::_Init() PowerStatusView::_Init()
{ {
SetViewColor(B_TRANSPARENT_COLOR);
fShowLabel = true; fShowLabel = true;
fShowTime = false; fShowTime = false;
fShowStatusIcon = true; fShowStatusIcon = true;
@@ -109,7 +110,6 @@ PowerStatusView::_Init()
fPercent = -1; fPercent = -1;
fOnline = true; fOnline = true;
fTimeLeft = 0; fTimeLeft = 0;
} }
@@ -118,13 +118,11 @@ PowerStatusView::AttachedToWindow()
{ {
BView::AttachedToWindow(); BView::AttachedToWindow();
if (Parent()) if (Parent())
SetViewColor(Parent()->ViewColor()); SetLowColor(Parent()->ViewColor());
else else
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetLowColor(ViewColor()); Update();
_Update();
} }
@@ -140,7 +138,7 @@ PowerStatusView::MessageReceived(BMessage *message)
{ {
switch (message->what) { switch (message->what) {
case kMsgUpdate: case kMsgUpdate:
_Update(); Update();
break; break;
default: default:
@@ -169,38 +167,54 @@ PowerStatusView::_DrawBattery(BRect rect)
float left = rect.left; float left = rect.left;
rect.left += rect.Width() / 11; rect.left += rect.Width() / 11;
SetHighColor(84, 84, 84);
float gap = 1; float gap = 1;
if (rect.Height() > 8) { if (rect.Height() > 8) {
rect.InsetBy(1, 1); gap = ceilf((rect.left - left) / 2);
SetPenSize(2);
gap = 2;
}
SetHighColor(92, 92, 92);
// left
FillRect(BRect(rect.left, rect.top, rect.left + gap - 1, rect.bottom));
// right
FillRect(BRect(rect.right - gap + 1, rect.top, rect.right,
rect.bottom));
// top
FillRect(BRect(rect.left + gap, rect.top, rect.right - gap,
rect.top + gap - 1));
// bottom
FillRect(BRect(rect.left + gap, rect.bottom + 1 - gap,
rect.right - gap, rect.bottom));
} else
StrokeRect(rect); StrokeRect(rect);
SetPenSize(1);
FillRect(BRect(left, floorf(rect.top + rect.Height() / 4) + 1, FillRect(BRect(left, floorf(rect.top + rect.Height() / 4) + 1,
rect.left, floorf(rect.bottom - rect.Height() / 4))); rect.left - 1, floorf(rect.bottom - rect.Height() / 4)));
int32 percent = fPercent; int32 percent = fPercent;
if (percent > 100 || percent < 0) if (percent > 100 || percent < 0)
percent = 100; percent = 100;
if (percent > 0) { if (percent > 0) {
if (percent < 16) rgb_color base;
SetHighColor(180, 0, 0); if (fOnline) {
if (percent <= 15)
base.set_to(180, 0, 0);
else else
SetHighColor(20, 180, 0); base.set_to(20, 180, 0);
} else {
rect.InsetBy(gap + 1, gap + 1); base = HighColor();
if (gap > 1) { percent = 100;
rect.right++;
rect.bottom++;
} }
rect.right = rect.left + rect.Width() * min_c(percent, 100) / 100.0; rect.InsetBy(gap, gap);
rect.right = rect.left + rect.Width() * percent / 100.0;
if (be_control_look != NULL)
be_control_look->DrawButtonBackground(this, rect, rect, base,
fOnline ? 0 : BControlLook::B_DISABLED);
//if (!)
else
FillRect(rect); FillRect(rect);
} }
@@ -211,6 +225,11 @@ PowerStatusView::_DrawBattery(BRect rect)
void void
PowerStatusView::Draw(BRect updateRect) PowerStatusView::Draw(BRect updateRect)
{ {
bool drawBackground = Parent() == NULL
|| (Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0;
if (drawBackground)
FillRect(updateRect, B_SOLID_LOW);
float aspect = Bounds().Width() / Bounds().Height(); float aspect = Bounds().Width() / Bounds().Height();
bool below = aspect <= 1.0f; bool below = aspect <= 1.0f;
@@ -269,6 +288,17 @@ PowerStatusView::Draw(BRect updateRect)
point.y += (Bounds().Height() - textHeight) / 2; point.y += (Bounds().Height() - textHeight) / 2;
} }
if (drawBackground)
SetHighColor(ui_color(B_CONTROL_TEXT_COLOR));
else {
SetDrawingMode(B_OP_OVER);
rgb_color c = Parent()->LowColor();
if (c.red + c.green + c.blue > 128 * 3)
SetHighColor(0, 0, 0);
else
SetHighColor(255, 255, 255);
}
DrawString(text, point); DrawString(text, point);
} }
} }
@@ -303,13 +333,13 @@ PowerStatusView::_SetLabel(char* buffer, size_t bufferLength)
void void
PowerStatusView::_Update(bool force) PowerStatusView::Update(bool force)
{ {
int32 previousPercent = fPercent; int32 previousPercent = fPercent;
bool previousTimeLeft = fTimeLeft; bool previousTimeLeft = fTimeLeft;
bool wasOnline = fOnline; bool wasOnline = fOnline;
_GetBatteryInfo(&fBatteryInfo, fBatteryId); _GetBatteryInfo(&fBatteryInfo, fBatteryID);
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity; fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
fTimeLeft = fBatteryInfo.time_left; fTimeLeft = fBatteryInfo.time_left;
@@ -346,22 +376,23 @@ PowerStatusView::_Update(bool force)
void void
PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryId) PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryID)
{ {
if (batteryId >= 0) { if (batteryID >= 0) {
fDriverInterface->GetBatteryInfo(batteryInfo, batteryId); fDriverInterface->GetBatteryInfo(batteryInfo, batteryID);
} } else {
else for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) { for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
battery_info tmpInfo; battery_info info;
fDriverInterface->GetBatteryInfo(&tmpInfo, i); fDriverInterface->GetBatteryInfo(&info, i);
if (i == 0) if (i == 0)
*batteryInfo = tmpInfo; *batteryInfo = info;
else { else {
batteryInfo->state &= tmpInfo.state; batteryInfo->state &= info.state;
batteryInfo->capacity += tmpInfo.capacity; batteryInfo->capacity += info.capacity;
batteryInfo->full_capacity += tmpInfo.full_capacity; batteryInfo->full_capacity += info.full_capacity;
batteryInfo->time_left += tmpInfo.time_left; batteryInfo->time_left += info.time_left;
}
} }
} }
} }
@@ -386,7 +417,7 @@ PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode,
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
AddChild(dragger); AddChild(dragger);
} else } else
_Update(); Update();
} }
@@ -439,17 +470,17 @@ PowerStatusReplicant::MessageReceived(BMessage *message)
switch (message->what) { switch (message->what) {
case kMsgToggleLabel: case kMsgToggleLabel:
fShowLabel = !fShowLabel; fShowLabel = !fShowLabel;
_Update(true); Update(true);
break; break;
case kMsgToggleTime: case kMsgToggleTime:
fShowTime = !fShowTime; fShowTime = !fShowTime;
_Update(true); Update(true);
break; break;
case kMsgToggleStatusIcon: case kMsgToggleStatusIcon:
fShowStatusIcon = !fShowStatusIcon; fShowStatusIcon = !fShowStatusIcon;
_Update(true); Update(true);
break; break;
case kMsgToggleExtInfo: case kMsgToggleExtInfo:
@@ -488,7 +519,8 @@ PowerStatusReplicant::MouseDown(BPoint point)
menu->AddItem(new BMenuItem(!fShowTime ? "Show Time" : "Show Percent", menu->AddItem(new BMenuItem(!fShowTime ? "Show Time" : "Show Percent",
new BMessage(kMsgToggleTime))); new BMessage(kMsgToggleTime)));
menu->AddItem(new BMenuItem("Battery Info", menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Battery Info" B_UTF8_ELLIPSIS,
new BMessage(kMsgToggleExtInfo))); new BMessage(kMsgToggleExtInfo)));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
+19 -18
View File
@@ -1,12 +1,11 @@
/* /*
* Copyright 2006, Haiku, Inc. All Rights Reserved. * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
* Clemens Zeidler, [email protected] * Clemens Zeidler, [email protected]
*/ */
#ifndef POWER_STATUS_VIEW_H #ifndef POWER_STATUS_VIEW_H
#define POWER_STATUS_VIEW_H #define POWER_STATUS_VIEW_H
@@ -18,9 +17,10 @@
class PowerStatusView : public BView { class PowerStatusView : public BView {
public: public:
PowerStatusView(PowerStatusDriverInterface* interface, PowerStatusView(
BRect frame, int32 resizingMode, int batteryId = -1, PowerStatusDriverInterface* interface,
bool inDeskbar = false); BRect frame, int32 resizingMode,
int batteryID = -1, bool inDeskbar = false);
virtual ~PowerStatusView(); virtual ~PowerStatusView();
@@ -33,28 +33,30 @@ class PowerStatusView : public BView {
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void GetPreferredSize(float *width, float *height); virtual void GetPreferredSize(float *width, float *height);
protected: protected:
PowerStatusView(BMessage* archive); PowerStatusView(BMessage* archive);
virtual void _Update(bool force = false); virtual void Update(bool force = false);
virtual void _GetBatteryInfo(battery_info* info, int batteryId);
private:
void _GetBatteryInfo(battery_info* info, int batteryID);
void _Init();
void _SetLabel(char* buffer, size_t bufferLength);
void _DrawBattery(BRect rect);
protected:
PowerStatusDriverInterface* fDriverInterface; PowerStatusDriverInterface* fDriverInterface;
bool fShowLabel; bool fShowLabel;
bool fShowTime; bool fShowTime;
bool fShowStatusIcon; bool fShowStatusIcon;
int fBatteryId; int fBatteryID;
bool fInDeskbar; bool fInDeskbar;
battery_info fBatteryInfo; battery_info fBatteryInfo;
private:
void _Init();
void _SetLabel(char* buffer, size_t bufferLength);
void _DrawBattery(BRect rect);
int32 fPercent; int32 fPercent;
time_t fTimeLeft; time_t fTimeLeft;
bool fOnline; bool fOnline;
@@ -63,13 +65,11 @@ class PowerStatusView : public BView {
}; };
class PowerStatusReplicant : public PowerStatusView class PowerStatusReplicant : public PowerStatusView {
{
public: public:
PowerStatusReplicant(BRect frame, int32 resizingMode, PowerStatusReplicant(BRect frame,
bool inDeskbar = false); int32 resizingMode, bool inDeskbar = false);
PowerStatusReplicant(BMessage* archive); PowerStatusReplicant(BMessage* archive);
virtual ~PowerStatusReplicant(); virtual ~PowerStatusReplicant();
static PowerStatusReplicant* Instantiate(BMessage* archive); static PowerStatusReplicant* Instantiate(BMessage* archive);
@@ -85,6 +85,7 @@ class PowerStatusReplicant : public PowerStatusView
void _OpenExtendedWindow(); void _OpenExtendedWindow();
private:
BWindow* fExtendedWindow; BWindow* fExtendedWindow;
bool fMessengerExist; bool fMessengerExist;
BMessenger* fExtWindowMessenger; BMessenger* fExtWindowMessenger;