* 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:
parent
a068dcb15a
commit
bd767f5a4e
@ -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, haiku@Clemens-Zeidler.de
|
||||
*/
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
@ -46,7 +50,7 @@ BatteryInfoView::Update(battery_info& info, acpi_extended_battery_info& extInfo)
|
||||
{
|
||||
fBatteryInfo = info;
|
||||
fBatteryExtendedInfo = extInfo;
|
||||
|
||||
|
||||
_FillStringList();
|
||||
}
|
||||
|
||||
@ -55,23 +59,22 @@ void
|
||||
BatteryInfoView::Draw(BRect updateRect)
|
||||
{
|
||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
|
||||
BPoint point(10, 10);
|
||||
|
||||
|
||||
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);
|
||||
point.y += space;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BatteryInfoView::GetPreferredSize(float *width, float *height)
|
||||
BatteryInfoView::GetPreferredSize(float* width, float* height)
|
||||
{
|
||||
*width = fPreferredSize.width;
|
||||
*height = fPreferredSize.height;
|
||||
@ -97,7 +100,7 @@ BatteryInfoView::_MeasureString(const BString& string)
|
||||
BFont font;
|
||||
GetFont(&font);
|
||||
BSize size;
|
||||
|
||||
|
||||
size.width = font.StringWidth(string);
|
||||
|
||||
font_height height;
|
||||
@ -120,7 +123,7 @@ BatteryInfoView::_FillStringList()
|
||||
powerUnit = " mWh";
|
||||
rateUnit = " mW";
|
||||
break;
|
||||
|
||||
|
||||
case 1:
|
||||
powerUnit = " mAh";
|
||||
rateUnit = " mA";
|
||||
@ -132,7 +135,7 @@ BatteryInfoView::_FillStringList()
|
||||
fontString = new FontString;
|
||||
fStringList.AddItem(fontString);
|
||||
fontString->font = be_bold_font;
|
||||
|
||||
|
||||
if (fBatteryInfo.state & BATTERY_CHARGING)
|
||||
fontString->string = "Battery charging";
|
||||
else if (fBatteryInfo.state & BATTERY_DISCHARGING)
|
||||
@ -141,35 +144,35 @@ BatteryInfoView::_FillStringList()
|
||||
fontString->string = "Empty Battery Slot";
|
||||
else
|
||||
fontString->string = "Battery unused";
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Capacity: ";
|
||||
fontString->string << fBatteryInfo.capacity;
|
||||
fontString->string << powerUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Last full Charge: ";
|
||||
fontString->string << fBatteryInfo.full_capacity;
|
||||
fontString->string << powerUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Current Rate: ";
|
||||
fontString->string << fBatteryInfo.current_rate;
|
||||
fontString->string << rateUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
// empty line
|
||||
fontString = new FontString;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Design Capacity: ";
|
||||
fontString->string << fBatteryExtendedInfo.design_capacity;
|
||||
fontString->string << powerUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Technology: ";
|
||||
if (fBatteryExtendedInfo.technology == 0)
|
||||
@ -179,57 +182,57 @@ BatteryInfoView::_FillStringList()
|
||||
else
|
||||
fontString->string << "?";
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Design Voltage: ";
|
||||
fontString->string << fBatteryExtendedInfo.design_voltage;
|
||||
fontString->string << " mV";
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Design Capacity Warning: ";
|
||||
fontString->string << fBatteryExtendedInfo.design_capacity_warning;
|
||||
fontString->string << powerUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Design Capacity low Warning: ";
|
||||
fontString->string << fBatteryExtendedInfo.design_capacity_low;
|
||||
fontString->string << powerUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Capacity Granularity 1: ";
|
||||
fontString->string << fBatteryExtendedInfo.capacity_granularity_1;
|
||||
fontString->string << powerUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Capacity Granularity 2: ";
|
||||
fontString->string << fBatteryExtendedInfo.capacity_granularity_2;
|
||||
fontString->string << powerUnit;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Model Number: ";
|
||||
fontString->string << fBatteryExtendedInfo.model_number;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Serial number: ";
|
||||
fontString->string << fBatteryExtendedInfo.serial_number;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "Type: ";
|
||||
fontString->string += fBatteryExtendedInfo.type;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fontString = new FontString;
|
||||
fontString->string = "OEM Info: ";
|
||||
fontString->string += fBatteryExtendedInfo.oem_info;
|
||||
_AddToStringList(fontString);
|
||||
|
||||
|
||||
fPreferredSize.width = fMaxStringSize.width + 10;
|
||||
fPreferredSize.height = (fMaxStringSize.height + kLineSpacing) *
|
||||
fStringList.CountItems();
|
||||
@ -256,32 +259,28 @@ BatteryInfoView::_ClearStringList()
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
ExtPowerStatusView::ExtPowerStatusView(PowerStatusDriverInterface* interface,
|
||||
BRect frame, int32 resizingMode, int batteryId,
|
||||
ExtendedInfoWindow* window)
|
||||
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,44 +291,47 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
@ -348,7 +350,7 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
||||
mainLayout->SetSpacing(10);
|
||||
mainLayout->SetInsets(10, 10, 10, 10);
|
||||
view->SetLayout(mainLayout);
|
||||
|
||||
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(5, 5);
|
||||
BBox *infoBox = new BBox(rect, "Power Status Box");
|
||||
@ -358,14 +360,14 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
||||
infoLayout->SetSpacing(10);
|
||||
infoBox->SetLayout(infoLayout);
|
||||
mainLayout->AddView(infoBox);
|
||||
|
||||
|
||||
BGroupView* batteryView = new BGroupView(B_VERTICAL);
|
||||
batteryView->GroupLayout()->SetSpacing(10);
|
||||
infoLayout->AddView(batteryView);
|
||||
|
||||
// create before the battery views
|
||||
fBatteryInfoView = new BatteryInfoView();
|
||||
|
||||
|
||||
BGroupLayout* batteryLayout = batteryView->GroupLayout();
|
||||
BRect batteryRect(0, 0, 50, 30);
|
||||
for (int i = 0; i < interface->GetBatteryCount(); i++) {
|
||||
@ -377,18 +379,18 @@ ExtendedInfoWindow::ExtendedInfoWindow(PowerStatusDriverInterface* interface)
|
||||
batteryLayout->AddView(view);
|
||||
fBatteryViewList.AddItem(view);
|
||||
fDriverInterface->StartWatching(view);
|
||||
if (view->IsValid())
|
||||
if (!view->IsCritical())
|
||||
fSelectedView = view;
|
||||
}
|
||||
|
||||
batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
|
||||
|
||||
batteryLayout->AddItem(BSpaceLayoutItem::CreateGlue());
|
||||
|
||||
infoLayout->AddView(fBatteryInfoView);
|
||||
|
||||
|
||||
if (!fSelectedView && fBatteryViewList.CountItems() > 0)
|
||||
fSelectedView = fBatteryViewList.ItemAt(0);
|
||||
fSelectedView = fBatteryViewList.ItemAt(0);
|
||||
fSelectedView->Select();
|
||||
|
||||
|
||||
BSize size = mainLayout->PreferredSize();
|
||||
ResizeTo(size.width, size.height);
|
||||
}
|
||||
@ -398,7 +400,7 @@ ExtendedInfoWindow::~ExtendedInfoWindow()
|
||||
{
|
||||
for (int i = 0; i < fBatteryViewList.CountItems(); i++)
|
||||
fDriverInterface->StopWatching(fBatteryViewList.ItemAt(i));
|
||||
|
||||
|
||||
fDriverInterface->ReleaseReference();
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
/*
|
||||
* 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, haiku@Clemens-Zeidler.de
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EXTENDED_INFO_WINDOW_H
|
||||
#define EXTENDED_INFO_WINDOW_H
|
||||
|
||||
|
||||
#include <ObjectList.h>
|
||||
#include <String.h>
|
||||
#include <View.h>
|
||||
@ -18,69 +19,67 @@
|
||||
#include "PowerStatusView.h"
|
||||
|
||||
|
||||
class FontString
|
||||
{
|
||||
class FontString {
|
||||
public:
|
||||
FontString();
|
||||
|
||||
const BFont* font;
|
||||
BString string;
|
||||
BString string;
|
||||
};
|
||||
|
||||
|
||||
class BatteryInfoView : public BView
|
||||
{
|
||||
public:
|
||||
BatteryInfoView();
|
||||
~BatteryInfoView();
|
||||
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 AttachedToWindow();
|
||||
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 AttachedToWindow();
|
||||
|
||||
private:
|
||||
BSize _MeasureString(const BString& string);
|
||||
void _FillStringList();
|
||||
void _AddToStringList(FontString* fontString);
|
||||
void _ClearStringList();
|
||||
private:
|
||||
BSize _MeasureString(const BString& string);
|
||||
void _FillStringList();
|
||||
void _AddToStringList(FontString* fontString);
|
||||
void _ClearStringList();
|
||||
|
||||
battery_info fBatteryInfo;
|
||||
acpi_extended_battery_info fBatteryExtendedInfo;
|
||||
|
||||
BSize fPreferredSize;
|
||||
|
||||
BObjectList<FontString> fStringList;
|
||||
BSize fMaxStringSize;
|
||||
battery_info fBatteryInfo;
|
||||
acpi_extended_battery_info fBatteryExtendedInfo;
|
||||
|
||||
BSize fPreferredSize;
|
||||
|
||||
BObjectList<FontString> fStringList;
|
||||
BSize fMaxStringSize;
|
||||
};
|
||||
|
||||
|
||||
class ExtendedInfoWindow;
|
||||
|
||||
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);
|
||||
class ExtPowerStatusView : public PowerStatusView {
|
||||
public:
|
||||
ExtPowerStatusView(
|
||||
PowerStatusDriverInterface* interface,
|
||||
BRect frame, int32 resizingMode,
|
||||
int batteryID, ExtendedInfoWindow* window);
|
||||
|
||||
virtual void Select(bool select = true);
|
||||
|
||||
// return true if it battery is in a none critical state
|
||||
virtual bool IsValid();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
||||
protected:
|
||||
virtual void _Update(bool force = false);
|
||||
virtual void Select(bool select = true);
|
||||
|
||||
private:
|
||||
ExtendedInfoWindow* fExtendedInfoWindow;
|
||||
BatteryInfoView* fBatteryInfoView;
|
||||
|
||||
bool fSelected;
|
||||
// return true if it battery is in a critical state
|
||||
virtual bool IsCritical();
|
||||
|
||||
protected:
|
||||
virtual void Update(bool force = false);
|
||||
|
||||
private:
|
||||
ExtendedInfoWindow* fExtendedInfoWindow;
|
||||
BatteryInfoView* fBatteryInfoView;
|
||||
|
||||
bool fSelected;
|
||||
};
|
||||
|
||||
|
||||
@ -89,7 +88,7 @@ class ExtendedInfoWindow : public BWindow
|
||||
public:
|
||||
ExtendedInfoWindow(PowerStatusDriverInterface* interface);
|
||||
~ExtendedInfoWindow();
|
||||
|
||||
|
||||
BatteryInfoView* GetExtendedBatteryInfoView();
|
||||
|
||||
void BatterySelected(ExtPowerStatusView* view);
|
||||
@ -97,9 +96,9 @@ public:
|
||||
private:
|
||||
PowerStatusDriverInterface* fDriverInterface;
|
||||
BObjectList<ExtPowerStatusView> fBatteryViewList;
|
||||
|
||||
|
||||
BatteryInfoView* fBatteryInfoView;
|
||||
|
||||
|
||||
ExtPowerStatusView* fSelectedView;
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
@ -87,7 +88,7 @@ PowerStatus::ReadyToRun()
|
||||
if (alert->Go()) {
|
||||
image_info info;
|
||||
entry_ref ref;
|
||||
|
||||
|
||||
if (our_image(info) == B_OK
|
||||
&& get_ref_for_path(info.name, &ref) == B_OK) {
|
||||
BDeskbar deskbar;
|
||||
|
@ -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,39 +167,55 @@ 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;
|
||||
}
|
||||
gap = ceilf((rect.left - left) / 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,
|
||||
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);
|
||||
else
|
||||
SetHighColor(20, 180, 0);
|
||||
|
||||
rect.InsetBy(gap + 1, gap + 1);
|
||||
if (gap > 1) {
|
||||
rect.right++;
|
||||
rect.bottom++;
|
||||
rgb_color base;
|
||||
if (fOnline) {
|
||||
if (percent <= 15)
|
||||
base.set_to(180, 0, 0);
|
||||
else
|
||||
base.set_to(20, 180, 0);
|
||||
} else {
|
||||
base = HighColor();
|
||||
percent = 100;
|
||||
}
|
||||
|
||||
rect.right = rect.left + rect.Width() * min_c(percent, 100) / 100.0;
|
||||
FillRect(rect);
|
||||
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);
|
||||
}
|
||||
|
||||
SetHighColor(0, 0, 0);
|
||||
@ -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;
|
||||
@ -317,7 +347,7 @@ PowerStatusView::_Update(bool force)
|
||||
fOnline = true;
|
||||
else
|
||||
fOnline = false;
|
||||
|
||||
|
||||
if (fInDeskbar) {
|
||||
// make sure the tray icon is large enough
|
||||
float width = fShowStatusIcon ? kMinIconWidth + 2 : 0;
|
||||
@ -346,23 +376,24 @@ 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 (i == 0)
|
||||
*batteryInfo = tmpInfo;
|
||||
else {
|
||||
batteryInfo->state &= tmpInfo.state;
|
||||
batteryInfo->capacity += tmpInfo.capacity;
|
||||
batteryInfo->full_capacity += tmpInfo.full_capacity;
|
||||
batteryInfo->time_left += tmpInfo.time_left;
|
||||
}
|
||||
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 = info;
|
||||
else {
|
||||
batteryInfo->state &= info.state;
|
||||
batteryInfo->capacity += info.capacity;
|
||||
batteryInfo->full_capacity += info.full_capacity;
|
||||
batteryInfo->time_left += info.time_left;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,7 +402,7 @@ PowerStatusView::_GetBatteryInfo(battery_info* batteryInfo, int batteryId)
|
||||
|
||||
|
||||
PowerStatusReplicant::PowerStatusReplicant(BRect frame, int32 resizingMode,
|
||||
bool inDeskbar)
|
||||
bool inDeskbar)
|
||||
:
|
||||
PowerStatusView(NULL, frame, resizingMode, -1, inDeskbar)
|
||||
{
|
||||
@ -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,9 +519,10 @@ 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();
|
||||
menu->AddItem(new BMenuItem("About" B_UTF8_ELLIPSIS,
|
||||
new BMessage(B_ABOUT_REQUESTED)));
|
||||
@ -535,7 +567,7 @@ PowerStatusReplicant::_Init()
|
||||
_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fExtendedWindow = NULL;
|
||||
fMessengerExist = false;
|
||||
fExtWindowMessenger = NULL;
|
||||
|
@ -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,77 +16,79 @@
|
||||
|
||||
|
||||
class PowerStatusView : public BView {
|
||||
public:
|
||||
PowerStatusView(PowerStatusDriverInterface* interface,
|
||||
BRect frame, int32 resizingMode, int batteryId = -1,
|
||||
bool inDeskbar = false);
|
||||
|
||||
virtual ~PowerStatusView();
|
||||
public:
|
||||
PowerStatusView(
|
||||
PowerStatusDriverInterface* interface,
|
||||
BRect frame, int32 resizingMode,
|
||||
int batteryID = -1, bool inDeskbar = false);
|
||||
|
||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||
virtual ~PowerStatusView();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DetachedFromWindow();
|
||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void GetPreferredSize(float *width, float *height);
|
||||
|
||||
protected:
|
||||
PowerStatusView(BMessage* archive);
|
||||
|
||||
virtual void _Update(bool force = false);
|
||||
virtual void _GetBatteryInfo(battery_info* info, int batteryId);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DetachedFromWindow();
|
||||
|
||||
PowerStatusDriverInterface* fDriverInterface;
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void GetPreferredSize(float *width, float *height);
|
||||
|
||||
bool fShowLabel;
|
||||
bool fShowTime;
|
||||
bool fShowStatusIcon;
|
||||
|
||||
int fBatteryId;
|
||||
bool fInDeskbar;
|
||||
|
||||
battery_info fBatteryInfo;
|
||||
protected:
|
||||
PowerStatusView(BMessage* archive);
|
||||
|
||||
private:
|
||||
void _Init();
|
||||
void _SetLabel(char* buffer, size_t bufferLength);
|
||||
void _DrawBattery(BRect rect);
|
||||
virtual void Update(bool force = false);
|
||||
|
||||
int32 fPercent;
|
||||
time_t fTimeLeft;
|
||||
bool fOnline;
|
||||
private:
|
||||
void _GetBatteryInfo(battery_info* info, int batteryID);
|
||||
void _Init();
|
||||
void _SetLabel(char* buffer, size_t bufferLength);
|
||||
void _DrawBattery(BRect rect);
|
||||
|
||||
BSize fPreferredSize;
|
||||
protected:
|
||||
PowerStatusDriverInterface* fDriverInterface;
|
||||
|
||||
bool fShowLabel;
|
||||
bool fShowTime;
|
||||
bool fShowStatusIcon;
|
||||
|
||||
int fBatteryID;
|
||||
bool fInDeskbar;
|
||||
|
||||
battery_info fBatteryInfo;
|
||||
|
||||
int32 fPercent;
|
||||
time_t fTimeLeft;
|
||||
bool fOnline;
|
||||
|
||||
BSize fPreferredSize;
|
||||
};
|
||||
|
||||
|
||||
class PowerStatusReplicant : public PowerStatusView
|
||||
{
|
||||
public:
|
||||
PowerStatusReplicant(BRect frame, int32 resizingMode,
|
||||
bool inDeskbar = false);
|
||||
PowerStatusReplicant(BMessage* archive);
|
||||
class PowerStatusReplicant : public PowerStatusView {
|
||||
public:
|
||||
PowerStatusReplicant(BRect frame,
|
||||
int32 resizingMode, bool inDeskbar = false);
|
||||
PowerStatusReplicant(BMessage* archive);
|
||||
virtual ~PowerStatusReplicant();
|
||||
|
||||
virtual ~PowerStatusReplicant();
|
||||
static PowerStatusReplicant* Instantiate(BMessage* archive);
|
||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||
|
||||
static PowerStatusReplicant* Instantiate(BMessage* archive);
|
||||
virtual status_t Archive(BMessage* archive, bool deep = true) const;
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void MouseDown(BPoint where);
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void MouseDown(BPoint where);
|
||||
private:
|
||||
void _AboutRequested();
|
||||
void _Init();
|
||||
void _Quit();
|
||||
|
||||
private:
|
||||
void _AboutRequested();
|
||||
void _Init();
|
||||
void _Quit();
|
||||
|
||||
void _OpenExtendedWindow();
|
||||
void _OpenExtendedWindow();
|
||||
|
||||
BWindow* fExtendedWindow;
|
||||
bool fMessengerExist;
|
||||
BMessenger* fExtWindowMessenger;
|
||||
private:
|
||||
BWindow* fExtendedWindow;
|
||||
bool fMessengerExist;
|
||||
BMessenger* fExtWindowMessenger;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user