From b03b6c266c7bb35478d54c917e275f318f7e8200 Mon Sep 17 00:00:00 2001 From: Vincent-FK Date: Tue, 18 Feb 2020 23:24:41 +0100 Subject: [PATCH] use static for percentage and other parameters in battery component Signed-off-by: Vincent-FK --- RetroFE/Source/Graphics/Component/Battery.cpp | 37 +++++++++---------- RetroFE/Source/Graphics/Component/Battery.h | 11 +++--- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/RetroFE/Source/Graphics/Component/Battery.cpp b/RetroFE/Source/Graphics/Component/Battery.cpp index 3dcd38f..dc2dd80 100644 --- a/RetroFE/Source/Graphics/Component/Battery.cpp +++ b/RetroFE/Source/Graphics/Component/Battery.cpp @@ -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}}; +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) : Component(p) , texture_(NULL) , texture_prescaled_(NULL) , reloadPeriod_(reloadPeriod) - , currentWaitTime_(0.0f) - , percentage_(0) - , prevPercentage_(0) , scaleX_(scaleX) , scaleY_(scaleY) - , mustRender_(false) , fontColor_(0xff000000 | ((uint32_t)fontColor.b) << 16 | ((uint32_t)fontColor.g) << 8 | ((uint32_t)fontColor.r)) { allocateGraphicsMemory(); @@ -76,9 +78,6 @@ void Battery::freeGraphicsMemory() void Battery::allocateGraphicsMemory() { - int width; - int height; - int i, j; if(!texture_) { @@ -127,8 +126,6 @@ void Battery::allocateGraphicsMemory() void Battery::drawBattery() { - int width; - int height; int i, j; if(texture_ != NULL) @@ -167,8 +164,6 @@ void Battery::drawBattery() void Battery::update(float dt) { - prevPercentage_ = percentage_; - if (currentWaitTime_ < reloadPeriod_) { currentWaitTime_ += dt; @@ -176,16 +171,21 @@ void Battery::update(float dt) else if(baseViewInfo.Alpha > 0.0f) { //printf("Battery check percentage\n"); - percentage_ = (prevPercentage_+1)%101; + prevPercentage_ = percentage_; + percentage_ = (prevPercentage_+1)%101; currentWaitTime_ = 0.0f; } - if (percentage_ != prevPercentage_) - { - //printf(" Redraw Battery\n"); - - drawBattery(); + /* Redraw battery if necessary */ + if(prevPercentage_ != percentage_){ + float percentagePixelWidth = percentage_ * BATTERY_FILL_REGION_OFFSET_WIDTH / 100; + float prevPercentagePixelWidth = prevPercentage_ * BATTERY_FILL_REGION_OFFSET_WIDTH / 100; + if (prevPercentagePixelWidth != percentagePixelWidth) + { + //printf(" Redraw Battery\n"); + drawBattery(); + } } Component::update(dt); @@ -239,8 +239,7 @@ bool Battery::mustRender( ) { if ( Component::mustRender( ) ) return true; - if ( (percentage_ != prevPercentage_ && baseViewInfo.Alpha > 0.0f) || - mustRender_) + if ( mustRender_ && baseViewInfo.Alpha > 0.0f ) { mustRender_ = false; return true; diff --git a/RetroFE/Source/Graphics/Component/Battery.h b/RetroFE/Source/Graphics/Component/Battery.h index ee915d3..7894725 100644 --- a/RetroFE/Source/Graphics/Component/Battery.h +++ b/RetroFE/Source/Graphics/Component/Battery.h @@ -20,12 +20,13 @@ protected: SDL_Surface *texture_; SDL_Surface *texture_prescaled_; uint32_t fontColor_; - int percentage_; - int prevPercentage_; - bool charging_; float scaleX_; float scaleY_; float reloadPeriod_; - float currentWaitTime_; - bool mustRender_; + + static float currentWaitTime_; + static bool mustRender_; + static int percentage_; + static int prevPercentage_; + static bool charging_; };