mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-29 09:29:31 +02:00
use static for percentage and other parameters in battery component
Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
@@ -34,18 +34,20 @@ static uint32_t batteryIcon [BATTERY_ICON_HEIGHT][BATTERY_ICON_WIDTH] = {
|
|||||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
||||||
|
|
||||||
|
int Battery::percentage_ = 0;
|
||||||
|
int Battery::prevPercentage_ = 0;
|
||||||
|
bool Battery::charging_ = false;
|
||||||
|
float Battery::currentWaitTime_ = 0.0f;
|
||||||
|
bool Battery::mustRender_ = false;
|
||||||
|
|
||||||
|
|
||||||
Battery::Battery(Page &p, float scaleX, float scaleY, float reloadPeriod, SDL_Color fontColor)
|
Battery::Battery(Page &p, float scaleX, float scaleY, float reloadPeriod, SDL_Color fontColor)
|
||||||
: Component(p)
|
: Component(p)
|
||||||
, texture_(NULL)
|
, texture_(NULL)
|
||||||
, texture_prescaled_(NULL)
|
, texture_prescaled_(NULL)
|
||||||
, reloadPeriod_(reloadPeriod)
|
, reloadPeriod_(reloadPeriod)
|
||||||
, currentWaitTime_(0.0f)
|
|
||||||
, percentage_(0)
|
|
||||||
, prevPercentage_(0)
|
|
||||||
, scaleX_(scaleX)
|
, scaleX_(scaleX)
|
||||||
, scaleY_(scaleY)
|
, scaleY_(scaleY)
|
||||||
, mustRender_(false)
|
|
||||||
, fontColor_(0xff000000 | ((uint32_t)fontColor.b) << 16 | ((uint32_t)fontColor.g) << 8 | ((uint32_t)fontColor.r))
|
, fontColor_(0xff000000 | ((uint32_t)fontColor.b) << 16 | ((uint32_t)fontColor.g) << 8 | ((uint32_t)fontColor.r))
|
||||||
{
|
{
|
||||||
allocateGraphicsMemory();
|
allocateGraphicsMemory();
|
||||||
@@ -76,9 +78,6 @@ void Battery::freeGraphicsMemory()
|
|||||||
|
|
||||||
void Battery::allocateGraphicsMemory()
|
void Battery::allocateGraphicsMemory()
|
||||||
{
|
{
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
if(!texture_)
|
if(!texture_)
|
||||||
{
|
{
|
||||||
@@ -127,8 +126,6 @@ void Battery::allocateGraphicsMemory()
|
|||||||
|
|
||||||
void Battery::drawBattery()
|
void Battery::drawBattery()
|
||||||
{
|
{
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
if(texture_ != NULL)
|
if(texture_ != NULL)
|
||||||
@@ -167,8 +164,6 @@ void Battery::drawBattery()
|
|||||||
|
|
||||||
void Battery::update(float dt)
|
void Battery::update(float dt)
|
||||||
{
|
{
|
||||||
prevPercentage_ = percentage_;
|
|
||||||
|
|
||||||
if (currentWaitTime_ < reloadPeriod_)
|
if (currentWaitTime_ < reloadPeriod_)
|
||||||
{
|
{
|
||||||
currentWaitTime_ += dt;
|
currentWaitTime_ += dt;
|
||||||
@@ -176,16 +171,21 @@ void Battery::update(float dt)
|
|||||||
else if(baseViewInfo.Alpha > 0.0f)
|
else if(baseViewInfo.Alpha > 0.0f)
|
||||||
{
|
{
|
||||||
//printf("Battery check percentage\n");
|
//printf("Battery check percentage\n");
|
||||||
percentage_ = (prevPercentage_+1)%101;
|
prevPercentage_ = percentage_;
|
||||||
|
percentage_ = (prevPercentage_+1)%101;
|
||||||
|
|
||||||
currentWaitTime_ = 0.0f;
|
currentWaitTime_ = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (percentage_ != prevPercentage_)
|
/* Redraw battery if necessary */
|
||||||
{
|
if(prevPercentage_ != percentage_){
|
||||||
//printf(" Redraw Battery\n");
|
float percentagePixelWidth = percentage_ * BATTERY_FILL_REGION_OFFSET_WIDTH / 100;
|
||||||
|
float prevPercentagePixelWidth = prevPercentage_ * BATTERY_FILL_REGION_OFFSET_WIDTH / 100;
|
||||||
drawBattery();
|
if (prevPercentagePixelWidth != percentagePixelWidth)
|
||||||
|
{
|
||||||
|
//printf(" Redraw Battery\n");
|
||||||
|
drawBattery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component::update(dt);
|
Component::update(dt);
|
||||||
@@ -239,8 +239,7 @@ bool Battery::mustRender( )
|
|||||||
{
|
{
|
||||||
if ( Component::mustRender( ) ) return true;
|
if ( Component::mustRender( ) ) return true;
|
||||||
|
|
||||||
if ( (percentage_ != prevPercentage_ && baseViewInfo.Alpha > 0.0f) ||
|
if ( mustRender_ && baseViewInfo.Alpha > 0.0f )
|
||||||
mustRender_)
|
|
||||||
{
|
{
|
||||||
mustRender_ = false;
|
mustRender_ = false;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ protected:
|
|||||||
SDL_Surface *texture_;
|
SDL_Surface *texture_;
|
||||||
SDL_Surface *texture_prescaled_;
|
SDL_Surface *texture_prescaled_;
|
||||||
uint32_t fontColor_;
|
uint32_t fontColor_;
|
||||||
int percentage_;
|
|
||||||
int prevPercentage_;
|
|
||||||
bool charging_;
|
|
||||||
float scaleX_;
|
float scaleX_;
|
||||||
float scaleY_;
|
float scaleY_;
|
||||||
float reloadPeriod_;
|
float reloadPeriod_;
|
||||||
float currentWaitTime_;
|
|
||||||
bool mustRender_;
|
static float currentWaitTime_;
|
||||||
|
static bool mustRender_;
|
||||||
|
static int percentage_;
|
||||||
|
static int prevPercentage_;
|
||||||
|
static bool charging_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user