* 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
+31 -29
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.
*
* Authors:
* Clemens Zeidler, [email protected]
*/
#include "ExtendedInfoWindow.h"
#include <Box.h>
@@ -16,18 +17,21 @@
#include <String.h>
const int kLineSpacing = 5;
FontString::FontString()
{
font = be_plain_font;
}
const int kLineSpacing = 5;
// #pragma mark -
BatteryInfoView::BatteryInfoView()
:
BView("battery info view", B_WILL_DRAW |
B_FULL_UPDATE_ON_RESIZE),
BView("battery info view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fPreferredSize(200, 200),
fMaxStringSize(0, 0)
{
@@ -60,8 +64,7 @@ BatteryInfoView::Draw(BRect updateRect)
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);
SetFont(fontString->font);
DrawString(fontString->string.String(), point);
@@ -71,7 +74,7 @@ BatteryInfoView::Draw(BRect updateRect)
void
BatteryInfoView::GetPreferredSize(float *width, float *height)
BatteryInfoView::GetPreferredSize(float* width, float* height)
{
*width = fPreferredSize.width;
*height = fPreferredSize.height;
@@ -256,32 +259,28 @@ BatteryInfoView::_ClearStringList()
}
// #pragma mark -
ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode, int batteryId,
BRect frame, int32 resizingMode, int batteryID,
ExtendedInfoWindow* window)
:
PowerStatusView(interface, frame, resizingMode, batteryId),
PowerStatusView(interface, frame, resizingMode, batteryID),
fExtendedInfoWindow(window),
fBatteryInfoView(window->GetExtendedBatteryInfoView()),
fSelected(false)
{
}
void
ExtPowerStatusView::Draw(BRect updateRect)
{
if (fSelected) {
if (fSelected)
SetLowColor(102, 152, 203);
SetHighColor(102, 152, 203);
FillRect(updateRect);
}
else {
else
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
FillRect(updateRect);
}
PowerStatusView::Draw(updateRect);
}
@@ -292,8 +291,10 @@ ExtPowerStatusView::MouseDown(BPoint where)
{
if (!fSelected) {
fSelected = true;
_Update(true);
fExtendedInfoWindow->BatterySelected(this);
Update(true);
if (ExtendedInfoWindow* window
= dynamic_cast<ExtendedInfoWindow*>(Window()))
window->BatterySelected(this);
}
}
@@ -302,34 +303,35 @@ void
ExtPowerStatusView::Select(bool select)
{
fSelected = select;
_Update(true);
Update(true);
}
bool
ExtPowerStatusView::IsValid()
ExtPowerStatusView::IsCritical()
{
if (fBatteryInfo.state & BATTERY_CRITICAL_STATE)
return false;
return true;
return (fBatteryInfo.state & BATTERY_CRITICAL_STATE) != 0;
}
void
ExtPowerStatusView::_Update(bool force)
ExtPowerStatusView::Update(bool force)
{
PowerStatusView::_Update(force);
PowerStatusView::Update(force);
if (!fSelected)
return;
acpi_extended_battery_info extInfo;
fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryId);
fDriverInterface->GetExtendedBatteryInfo(&extInfo, fBatteryID);
fBatteryInfoView->Update(fBatteryInfo, extInfo);
fBatteryInfoView->Invalidate();
}
// #pragma mark -
ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
:
BWindow(BRect(100, 150, 500, 500), "Extended Battery Info", B_TITLED_WINDOW,
@@ -377,7 +379,7 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
batteryLayout->AddView(view);
fBatteryViewList.AddItem(view);
fDriverInterface->StartWatching(view);
if (view->IsValid())
if (!view->IsCritical())
fSelectedView = view;
}
+18 -19
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.
*
* Authors:
@@ -9,6 +9,7 @@
#ifndef EXTENDED_INFO_WINDOW_H
#define EXTENDED_INFO_WINDOW_H
#include <ObjectList.h>
#include <String.h>
#include <View.h>
@@ -18,8 +19,7 @@
#include "PowerStatusView.h"
class FontString
{
class FontString {
public:
FontString();
@@ -28,19 +28,18 @@ public:
};
class BatteryInfoView : public BView
{
public:
class BatteryInfoView : public BView {
public:
BatteryInfoView();
~BatteryInfoView();
virtual void Update(battery_info& info,
acpi_extended_battery_info& extInfo);
virtual void Draw(BRect updateRect);
virtual void GetPreferredSize(float *width, float *height);
virtual void GetPreferredSize(float* width, float* height);
virtual void AttachedToWindow();
private:
private:
BSize _MeasureString(const BString& string);
void _FillStringList();
void _AddToStringList(FontString* fontString);
@@ -58,25 +57,25 @@ class BatteryInfoView : public BView
class ExtendedInfoWindow;
class ExtPowerStatusView : public PowerStatusView
{
public:
ExtPowerStatusView(PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode, int batteryId,
ExtendedInfoWindow* window);
class ExtPowerStatusView : public PowerStatusView {
public:
ExtPowerStatusView(
PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode,
int batteryID, ExtendedInfoWindow* window);
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where);
virtual void Select(bool select = true);
// return true if it battery is in a none critical state
virtual bool IsValid();
// return true if it battery is in a critical state
virtual bool IsCritical();
protected:
virtual void _Update(bool force = false);
protected:
virtual void Update(bool force = false);
private:
private:
ExtendedInfoWindow* fExtendedInfoWindow;
BatteryInfoView* fBatteryInfoView;
+1
View File
@@ -79,6 +79,7 @@ PowerStatus::ReadyToRun()
isInstalled = deskbar.HasItem(kDeskbarItemName);
}
isInstalled = true;
if (isDeskbarRunning && !isInstalled) {
BAlert* alert = new BAlert("", "Do you want PowerStatus to live in the Deskbar?",
"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.
*
* Authors:
@@ -13,6 +13,7 @@
#include <Alert.h>
#include <Application.h>
#include <ControlLook.h>
#include <Deskbar.h>
#include <Dragger.h>
#include <Drivers.h>
@@ -43,12 +44,12 @@ const uint32 kMinIconHeight = 16;
PowerStatusView::PowerStatusView(PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode, int batteryId, bool inDeskbar)
BRect frame, int32 resizingMode, int batteryID, bool inDeskbar)
:
BView(frame, kDeskbarItemName, resizingMode,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fDriverInterface(interface),
fBatteryId(batteryId),
fBatteryID(batteryID),
fInDeskbar(inDeskbar)
{
fPreferredSize.width = frame.Width();
@@ -71,14 +72,12 @@ PowerStatusView::PowerStatusView(BMessage* archive)
fShowTime = value;
int32 intValue;
if (archive->FindInt32("battery id", &intValue) == B_OK)
fBatteryId = intValue;
fBatteryID = intValue;
}
PowerStatusView::~PowerStatusView()
{
}
@@ -93,7 +92,7 @@ PowerStatusView::Archive(BMessage* archive, bool deep) const
if (status == B_OK)
status = archive->AddBool("show time", fShowTime);
if (status == B_OK)
status = archive->AddInt32("battery id", fBatteryId);
status = archive->AddInt32("battery id", fBatteryID);
return status;
}
@@ -102,6 +101,8 @@ PowerStatusView::Archive(BMessage* archive, bool deep) const
void
PowerStatusView::_Init()
{
SetViewColor(B_TRANSPARENT_COLOR);
fShowLabel = true;
fShowTime = false;
fShowStatusIcon = true;
@@ -109,7 +110,6 @@ PowerStatusView::_Init()
fPercent = -1;
fOnline = true;
fTimeLeft = 0;
}
@@ -118,13 +118,11 @@ PowerStatusView::AttachedToWindow()
{
BView::AttachedToWindow();
if (Parent())
SetViewColor(Parent()->ViewColor());
SetLowColor(Parent()->ViewColor());
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) {
case kMsgUpdate:
_Update();
Update();
break;
default:
@@ -169,38 +167,54 @@ PowerStatusView::_DrawBattery(BRect rect)
float left = rect.left;
rect.left += rect.Width() / 11;
SetHighColor(84, 84, 84);
float gap = 1;
if (rect.Height() > 8) {
rect.InsetBy(1, 1);
SetPenSize(2);
gap = 2;
}
SetHighColor(92, 92, 92);
gap = ceilf((rect.left - left) / 2);
// 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);
SetPenSize(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;
if (percent > 100 || percent < 0)
percent = 100;
if (percent > 0) {
if (percent < 16)
SetHighColor(180, 0, 0);
rgb_color base;
if (fOnline) {
if (percent <= 15)
base.set_to(180, 0, 0);
else
SetHighColor(20, 180, 0);
rect.InsetBy(gap + 1, gap + 1);
if (gap > 1) {
rect.right++;
rect.bottom++;
base.set_to(20, 180, 0);
} else {
base = HighColor();
percent = 100;
}
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);
}
@@ -211,6 +225,11 @@ PowerStatusView::_DrawBattery(BRect rect)
void
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();
bool below = aspect <= 1.0f;
@@ -269,6 +288,17 @@ PowerStatusView::Draw(BRect updateRect)
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);
}
}
@@ -303,13 +333,13 @@ PowerStatusView::_SetLabel(char* buffer, size_t bufferLength)
void
PowerStatusView::_Update(bool force)
PowerStatusView::Update(bool force)
{
int32 previousPercent = fPercent;
bool previousTimeLeft = fTimeLeft;
bool wasOnline = fOnline;
_GetBatteryInfo(&fBatteryInfo, fBatteryId);
_GetBatteryInfo(&fBatteryInfo, fBatteryID);
fPercent = (100 * fBatteryInfo.capacity) / fBatteryInfo.full_capacity;
fTimeLeft = fBatteryInfo.time_left;
@@ -346,22 +376,23 @@ PowerStatusView::_Update(bool force)
void
PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryId)
PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryID)
{
if (batteryId >= 0) {
fDriverInterface->GetBatteryInfo(batteryInfo, batteryId);
}
else for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
battery_info tmpInfo;
fDriverInterface->GetBatteryInfo(&tmpInfo, i);
if (batteryID >= 0) {
fDriverInterface->GetBatteryInfo(batteryInfo, batteryID);
} else {
for (int i = 0; i < fDriverInterface->GetBatteryCount(); i++) {
battery_info info;
fDriverInterface->GetBatteryInfo(&info, i);
if (i == 0)
*batteryInfo = tmpInfo;
*batteryInfo = info;
else {
batteryInfo->state &= tmpInfo.state;
batteryInfo->capacity += tmpInfo.capacity;
batteryInfo->full_capacity += tmpInfo.full_capacity;
batteryInfo->time_left += tmpInfo.time_left;
batteryInfo->state &= info.state;
batteryInfo->capacity += info.capacity;
batteryInfo->full_capacity += info.full_capacity;
batteryInfo->time_left += info.time_left;
}
}
}
}
@@ -386,7 +417,7 @@ PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode,
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
AddChild(dragger);
} else
_Update();
Update();
}
@@ -439,17 +470,17 @@ PowerStatusReplicant::MessageReceived(BMessage *message)
switch (message->what) {
case kMsgToggleLabel:
fShowLabel = !fShowLabel;
_Update(true);
Update(true);
break;
case kMsgToggleTime:
fShowTime = !fShowTime;
_Update(true);
Update(true);
break;
case kMsgToggleStatusIcon:
fShowStatusIcon = !fShowStatusIcon;
_Update(true);
Update(true);
break;
case kMsgToggleExtInfo:
@@ -488,7 +519,8 @@ PowerStatusReplicant::MouseDown(BPoint point)
menu->AddItem(new BMenuItem(!fShowTime ? "Show Time" : "Show Percent",
new BMessage(kMsgToggleTime)));
menu->AddItem(new BMenuItem("Battery Info",
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Battery Info" B_UTF8_ELLIPSIS,
new BMessage(kMsgToggleExtInfo)));
menu->AddSeparatorItem();
+23 -22
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.
*
* Authors:
* Axel Dörfler, axeld@pinc-software.de
* Clemens Zeidler, haiku@Clemens-Zeidler.de
*/
#ifndef POWER_STATUS_VIEW_H
#define POWER_STATUS_VIEW_H
@@ -17,10 +16,11 @@
class PowerStatusView : public BView {
public:
PowerStatusView(PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode, int batteryId = -1,
bool inDeskbar = false);
public:
PowerStatusView(
PowerStatusDriverInterface* interface,
BRect frame, int32 resizingMode,
int batteryID = -1, bool inDeskbar = false);
virtual ~PowerStatusView();
@@ -33,28 +33,30 @@ class PowerStatusView : public BView {
virtual void Draw(BRect updateRect);
virtual void GetPreferredSize(float *width, float *height);
protected:
protected:
PowerStatusView(BMessage* archive);
virtual void _Update(bool force = false);
virtual void _GetBatteryInfo(battery_info* info, int batteryId);
virtual void Update(bool force = false);
private:
void _GetBatteryInfo(battery_info* info, int batteryID);
void _Init();
void _SetLabel(char* buffer, size_t bufferLength);
void _DrawBattery(BRect rect);
protected:
PowerStatusDriverInterface* fDriverInterface;
bool fShowLabel;
bool fShowTime;
bool fShowStatusIcon;
int fBatteryId;
int fBatteryID;
bool fInDeskbar;
battery_info fBatteryInfo;
private:
void _Init();
void _SetLabel(char* buffer, size_t bufferLength);
void _DrawBattery(BRect rect);
int32 fPercent;
time_t fTimeLeft;
bool fOnline;
@@ -63,13 +65,11 @@ class PowerStatusView : public BView {
};
class PowerStatusReplicant : public PowerStatusView
{
public:
PowerStatusReplicant(BRect frame, int32 resizingMode,
bool inDeskbar = false);
class PowerStatusReplicant : public PowerStatusView {
public:
PowerStatusReplicant(BRect frame,
int32 resizingMode, bool inDeskbar = false);
PowerStatusReplicant(BMessage* archive);
virtual ~PowerStatusReplicant();
static PowerStatusReplicant* Instantiate(BMessage* archive);
@@ -78,13 +78,14 @@ class PowerStatusReplicant : public PowerStatusView
virtual void MessageReceived(BMessage* message);
virtual void MouseDown(BPoint where);
private:
private:
void _AboutRequested();
void _Init();
void _Quit();
void _OpenExtendedWindow();
private:
BWindow* fExtendedWindow;
bool fMessengerExist;
BMessenger* fExtWindowMessenger;