mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] Add a battery icon view
Change-Id: I20a90a2330c7851362dd87bec390241253ff70ef
This commit is contained in:
@@ -10,6 +10,7 @@ app_objs += $(addprefix apps/,\
|
||||
apps_container.o\
|
||||
apps_window.o\
|
||||
banner_view.o\
|
||||
battery_view.o\
|
||||
constant.o\
|
||||
cursor_view.o\
|
||||
curve_view.o\
|
||||
|
||||
37
apps/battery_view.cpp
Normal file
37
apps/battery_view.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "battery_view.h"
|
||||
|
||||
BatteryView::BatteryView() :
|
||||
View(),
|
||||
m_chargeState(Ion::Battery::Charge::SOMEWHERE_INBETWEEN)
|
||||
{
|
||||
}
|
||||
|
||||
void BatteryView::setChargeState(Ion::Battery::Charge chargeState) {
|
||||
if (chargeState != m_chargeState) {
|
||||
m_chargeState = chargeState;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
}
|
||||
|
||||
void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
/* We draw from left to right. The middle part representing the battery
|
||||
*'content' depends on the charge */
|
||||
ctx->fillRect(KDRect(0, 0, k_elementWidth, k_batteryHeight), KDColorWhite);
|
||||
if (m_chargeState == Ion::Battery::Charge::EMPTY) {
|
||||
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, 2*k_elementWidth, k_batteryHeight), Palette::LowBattery);
|
||||
ctx->fillRect(KDRect(3*k_elementWidth+k_separatorThickness, 0, k_batteryWidth-5*k_elementWidth-2*k_separatorThickness, k_batteryHeight), Palette::YellowTwo);
|
||||
}
|
||||
if (m_chargeState == Ion::Battery::Charge::SOMEWHERE_INBETWEEN) {
|
||||
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, (k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, k_batteryHeight), KDColorWhite);
|
||||
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness+(k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, 0, (k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, k_batteryHeight), Palette::YellowTwo);
|
||||
}
|
||||
if (m_chargeState == Ion::Battery::Charge::FULL) {
|
||||
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, k_batteryWidth-3*k_elementWidth-2*k_separatorThickness, k_batteryHeight), KDColorWhite);
|
||||
}
|
||||
ctx->fillRect(KDRect(k_batteryWidth-2*k_elementWidth, 0, k_elementWidth, k_batteryHeight), KDColorWhite);
|
||||
ctx->fillRect(KDRect(k_batteryWidth-k_elementWidth, (k_batteryHeight-k_capHeight)/2, k_elementWidth, k_capHeight), KDColorWhite);
|
||||
}
|
||||
|
||||
KDSize BatteryView::minimalSizeForOptimalDisplay() {
|
||||
return KDSize(k_batteryWidth, k_batteryHeight);
|
||||
}
|
||||
21
apps/battery_view.h
Normal file
21
apps/battery_view.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef APPS_BATTERY_VIEW_H
|
||||
#define APPS_BATTERY_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
|
||||
class BatteryView : public View {
|
||||
public:
|
||||
BatteryView();
|
||||
void setChargeState(Ion::Battery::Charge chargeState);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
KDSize minimalSizeForOptimalDisplay() override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_batteryHeight = 8;
|
||||
constexpr static KDCoordinate k_batteryWidth = 13;
|
||||
constexpr static KDCoordinate k_elementWidth = 1;
|
||||
constexpr static KDCoordinate k_capHeight = 4;
|
||||
constexpr static KDCoordinate k_separatorThickness = 1;
|
||||
Ion::Battery::Charge m_chargeState;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user