mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-15 19:28:53 +01:00
add battery component, BUG correction: mustRender in page was rewritten at each component
Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
parent
b15e0874da
commit
b19c27656f
@ -145,6 +145,7 @@ set(RETROFE_HEADERS
|
|||||||
"${RETROFE_DIR}/Source/Graphics/Component/Container.h"
|
"${RETROFE_DIR}/Source/Graphics/Component/Container.h"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/Component.h"
|
"${RETROFE_DIR}/Source/Graphics/Component/Component.h"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/Image.h"
|
"${RETROFE_DIR}/Source/Graphics/Component/Image.h"
|
||||||
|
"${RETROFE_DIR}/Source/Graphics/Component/Battery.h"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/ImageBuilder.h"
|
"${RETROFE_DIR}/Source/Graphics/Component/ImageBuilder.h"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/ReloadableMedia.h"
|
"${RETROFE_DIR}/Source/Graphics/Component/ReloadableMedia.h"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/ReloadableText.h"
|
"${RETROFE_DIR}/Source/Graphics/Component/ReloadableText.h"
|
||||||
@ -203,6 +204,7 @@ set(RETROFE_SOURCES
|
|||||||
"${RETROFE_DIR}/Source/Graphics/Component/Container.cpp"
|
"${RETROFE_DIR}/Source/Graphics/Component/Container.cpp"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/Component.cpp"
|
"${RETROFE_DIR}/Source/Graphics/Component/Component.cpp"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/Image.cpp"
|
"${RETROFE_DIR}/Source/Graphics/Component/Image.cpp"
|
||||||
|
"${RETROFE_DIR}/Source/Graphics/Component/Battery.cpp"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/ImageBuilder.cpp"
|
"${RETROFE_DIR}/Source/Graphics/Component/ImageBuilder.cpp"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/Text.cpp"
|
"${RETROFE_DIR}/Source/Graphics/Component/Text.cpp"
|
||||||
"${RETROFE_DIR}/Source/Graphics/Component/ReloadableMedia.cpp"
|
"${RETROFE_DIR}/Source/Graphics/Component/ReloadableMedia.cpp"
|
||||||
|
|||||||
@ -136,6 +136,62 @@ bool Configuration::import(std::string collection, std::string keyPrefix, std::s
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Configuration::importLayouts(std::string folder, std::string file, bool mustExist)
|
||||||
|
{
|
||||||
|
bool retVal = true;
|
||||||
|
int lineCount = 0;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
Logger::write(Logger::ZONE_INFO, "Configuration", "Importing layouts from \"" + file + "\"");
|
||||||
|
|
||||||
|
std::ifstream ifs(file.c_str());
|
||||||
|
|
||||||
|
if (!ifs.is_open())
|
||||||
|
{
|
||||||
|
if (mustExist)
|
||||||
|
{
|
||||||
|
Logger::write(Logger::ZONE_ERROR, "Configuration", "Could not open " + file + "\"");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::write(Logger::ZONE_INFO, "Configuration", "Could not open " + file + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (std::getline (ifs, line))
|
||||||
|
{
|
||||||
|
lineCount++;
|
||||||
|
|
||||||
|
// strip out any comments
|
||||||
|
line = Utils::filterComments(line);
|
||||||
|
|
||||||
|
if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos))
|
||||||
|
{
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string layoutName = trimEnds(line);
|
||||||
|
std::string layoutPath = Utils::combinePath(folder, layoutName);
|
||||||
|
|
||||||
|
/* Set new layoutPath */
|
||||||
|
layouts_.push_back(layoutPath);
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Dump layouts: " << "\"" << layoutPath << "\"";
|
||||||
|
|
||||||
|
Logger::write(Logger::ZONE_INFO, "Configuration", ss.str());
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ifs.close();
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Configuration::parseLine(std::string collection, std::string keyPrefix, std::string line, int lineCount)
|
bool Configuration::parseLine(std::string collection, std::string keyPrefix, std::string line, int lineCount)
|
||||||
{
|
{
|
||||||
@ -172,6 +228,14 @@ bool Configuration::parseLine(std::string collection, std::string keyPrefix, std
|
|||||||
{
|
{
|
||||||
value = Utils::replace(value, "%ITEM_COLLECTION_NAME%", collection);
|
value = Utils::replace(value, "%ITEM_COLLECTION_NAME%", collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove property if key already exists */
|
||||||
|
if(properties_.find(key) != properties_.end())
|
||||||
|
{
|
||||||
|
properties_.erase(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set new pair <key, value> */
|
||||||
properties_.insert(PropertiesPair(key, value));
|
properties_.insert(PropertiesPair(key, value));
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|||||||
@ -30,6 +30,7 @@ public:
|
|||||||
// gets the global configuration
|
// gets the global configuration
|
||||||
bool import(std::string keyPrefix, std::string file);
|
bool import(std::string keyPrefix, std::string file);
|
||||||
bool import(std::string collection, std::string keyPrefix, std::string file, bool mustExist = true);
|
bool import(std::string collection, std::string keyPrefix, std::string file, bool mustExist = true);
|
||||||
|
bool importLayouts(std::string folder, std::string file, bool mustExist = true);
|
||||||
bool getProperty(std::string key, std::string &value);
|
bool getProperty(std::string key, std::string &value);
|
||||||
bool getProperty(std::string key, int &value);
|
bool getProperty(std::string key, int &value);
|
||||||
bool getProperty(std::string key, bool &value);
|
bool getProperty(std::string key, bool &value);
|
||||||
@ -42,6 +43,7 @@ public:
|
|||||||
void getMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, bool system, std::string &value);
|
void getMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, bool system, std::string &value);
|
||||||
void getCollectionAbsolutePath(std::string collectionName, std::string &value);
|
void getCollectionAbsolutePath(std::string collectionName, std::string &value);
|
||||||
static std::string absolutePath;
|
static std::string absolutePath;
|
||||||
|
std::vector<std::string> layouts_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool getRawProperty(std::string key, std::string &value);
|
bool getRawProperty(std::string key, std::string &value);
|
||||||
|
|||||||
250
RetroFE/Source/Graphics/Component/Battery.cpp
Normal file
250
RetroFE/Source/Graphics/Component/Battery.cpp
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
#include "Battery.h"
|
||||||
|
#include "../ViewInfo.h"
|
||||||
|
#include "../../SDL.h"
|
||||||
|
#include "../../Utility/Log.h"
|
||||||
|
#include <SDL/SDL_image.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define BATTERY_ICON_WIDTH 34
|
||||||
|
#define BATTERY_ICON_HEIGHT 16
|
||||||
|
|
||||||
|
#define BATTERY_FILL_REGION_OFFSET_X 5
|
||||||
|
#define BATTERY_FILL_REGION_OFFSET_Y 5
|
||||||
|
#define BATTERY_FILL_REGION_OFFSET_WIDTH (BATTERY_ICON_WIDTH-12)
|
||||||
|
#define BATTERY_FILL_REGION_OFFSET_HEIGHT (BATTERY_ICON_HEIGHT-10)
|
||||||
|
|
||||||
|
#define BATTERY_BACK_COLOR 0x00000000
|
||||||
|
#define BATTERY_FORE_COLOR 0xffffffff
|
||||||
|
|
||||||
|
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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
|
||||||
|
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
|
||||||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
|
||||||
|
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
|
||||||
|
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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}};
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
Battery::~Battery()
|
||||||
|
{
|
||||||
|
freeGraphicsMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Battery::freeGraphicsMemory()
|
||||||
|
{
|
||||||
|
Component::freeGraphicsMemory();
|
||||||
|
|
||||||
|
SDL_LockMutex(SDL::getMutex());
|
||||||
|
if (texture_ != NULL)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(texture_);
|
||||||
|
texture_ = NULL;
|
||||||
|
}
|
||||||
|
if (texture_prescaled_ != NULL)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(texture_prescaled_);
|
||||||
|
texture_prescaled_ = NULL;
|
||||||
|
}
|
||||||
|
SDL_UnlockMutex(SDL::getMutex());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Battery::allocateGraphicsMemory()
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
if(!texture_)
|
||||||
|
{
|
||||||
|
SDL_LockMutex(SDL::getMutex());
|
||||||
|
|
||||||
|
/* Load image */
|
||||||
|
unsigned int rmask;
|
||||||
|
unsigned int gmask;
|
||||||
|
unsigned int bmask;
|
||||||
|
unsigned int amask;
|
||||||
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||||
|
rmask = 0xff000000;
|
||||||
|
gmask = 0x00ff0000;
|
||||||
|
bmask = 0x0000ff00;
|
||||||
|
amask = 0x000000ff;
|
||||||
|
#else
|
||||||
|
rmask = 0x000000ff;
|
||||||
|
gmask = 0x0000ff00;
|
||||||
|
bmask = 0x00ff0000;
|
||||||
|
amask = 0xff000000;
|
||||||
|
#endif
|
||||||
|
texture_ = SDL_CreateRGBSurface(0, BATTERY_ICON_WIDTH, BATTERY_ICON_HEIGHT, 32, rmask, gmask, bmask, amask);
|
||||||
|
if (!texture_ )
|
||||||
|
{
|
||||||
|
printf(" Failed-> creating battery icon surface: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (texture_ != NULL)
|
||||||
|
{
|
||||||
|
drawBattery();
|
||||||
|
|
||||||
|
//SDL_SetAlpha(texture_, SDL_SRCALPHA, 255);
|
||||||
|
|
||||||
|
/* Set real dimensions */
|
||||||
|
baseViewInfo.ImageWidth = texture_->w * scaleX_;
|
||||||
|
baseViewInfo.ImageHeight = texture_->h * scaleY_;
|
||||||
|
}
|
||||||
|
SDL_UnlockMutex(SDL::getMutex());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Component::allocateGraphicsMemory();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Battery::drawBattery()
|
||||||
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
if(texture_ != NULL)
|
||||||
|
{
|
||||||
|
SDL_LockMutex(SDL::getMutex());
|
||||||
|
|
||||||
|
/* Draw empty battery container */
|
||||||
|
uint32_t *texturePixels = (uint32_t*)texture_->pixels;
|
||||||
|
for(i = 0; i < BATTERY_ICON_HEIGHT; i++){
|
||||||
|
for(j = 0; j < BATTERY_ICON_WIDTH; j++){
|
||||||
|
uint32_t *currentPixel = texturePixels + BATTERY_ICON_WIDTH*i + j;
|
||||||
|
*currentPixel = batteryIcon[i][j] ? fontColor_ : BATTERY_BACK_COLOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fill battery */
|
||||||
|
for(i = 0; i < BATTERY_FILL_REGION_OFFSET_HEIGHT; i++){
|
||||||
|
for(j = 0; j < BATTERY_FILL_REGION_OFFSET_WIDTH; j++){
|
||||||
|
uint32_t *currentPixel = texturePixels +
|
||||||
|
(BATTERY_ICON_WIDTH)*(i+BATTERY_FILL_REGION_OFFSET_Y) +
|
||||||
|
(j+BATTERY_FILL_REGION_OFFSET_X);
|
||||||
|
*currentPixel = (j <= BATTERY_FILL_REGION_OFFSET_WIDTH*percentage_/100) ? fontColor_ : BATTERY_BACK_COLOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Force render*/
|
||||||
|
mustRender_ = true;
|
||||||
|
|
||||||
|
SDL_UnlockMutex(SDL::getMutex());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Component::allocateGraphicsMemory();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Battery::update(float dt)
|
||||||
|
{
|
||||||
|
prevPercentage_ = percentage_;
|
||||||
|
|
||||||
|
if (currentWaitTime_ < reloadPeriod_)
|
||||||
|
{
|
||||||
|
currentWaitTime_ += dt;
|
||||||
|
}
|
||||||
|
else if(baseViewInfo.Alpha > 0.0f)
|
||||||
|
{
|
||||||
|
//printf("Battery check percentage\n");
|
||||||
|
percentage_ = (prevPercentage_+1)%101;
|
||||||
|
|
||||||
|
currentWaitTime_ = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (percentage_ != prevPercentage_)
|
||||||
|
{
|
||||||
|
//printf(" Redraw Battery\n");
|
||||||
|
|
||||||
|
drawBattery();
|
||||||
|
}
|
||||||
|
|
||||||
|
Component::update(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Battery::draw()
|
||||||
|
{
|
||||||
|
bool scaling_needed = false;
|
||||||
|
bool cache_scaling_needed = false;
|
||||||
|
bool use_prescaled = false;
|
||||||
|
|
||||||
|
Component::draw();
|
||||||
|
|
||||||
|
if(texture_)
|
||||||
|
{
|
||||||
|
SDL_Rect rect;
|
||||||
|
rect.x = static_cast<int>(baseViewInfo.XRelativeToOrigin());
|
||||||
|
rect.y = static_cast<int>(baseViewInfo.YRelativeToOrigin());
|
||||||
|
rect.h = static_cast<int>(baseViewInfo.ScaledHeight());
|
||||||
|
rect.w = static_cast<int>(baseViewInfo.ScaledWidth());
|
||||||
|
|
||||||
|
/* Cache scaling */
|
||||||
|
scaling_needed = rect.w!=0 && rect.h!=0 && (texture_->w != rect.w || texture_->h != rect.h);
|
||||||
|
if(scaling_needed){
|
||||||
|
cache_scaling_needed = (texture_prescaled_ == NULL)?true:(texture_prescaled_->w != rect.w || texture_prescaled_->h != rect.h);
|
||||||
|
if(cache_scaling_needed){
|
||||||
|
texture_prescaled_ = SDL::zoomSurface(texture_, NULL, &rect);
|
||||||
|
if(texture_prescaled_ == NULL){
|
||||||
|
printf("ERROR in %s - Could not create texture_prescaled_\n", __func__);
|
||||||
|
use_prescaled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(texture_prescaled_ != NULL){
|
||||||
|
use_prescaled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(use_prescaled && texture_prescaled_ != NULL){
|
||||||
|
SDL::renderCopy(texture_prescaled_, baseViewInfo.Alpha, NULL, &rect, baseViewInfo);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
SDL::renderCopy(texture_, baseViewInfo.Alpha, NULL, &rect, baseViewInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Battery::mustRender( )
|
||||||
|
{
|
||||||
|
if ( Component::mustRender( ) ) return true;
|
||||||
|
|
||||||
|
if ( (percentage_ != prevPercentage_ && baseViewInfo.Alpha > 0.0f) ||
|
||||||
|
mustRender_)
|
||||||
|
{
|
||||||
|
mustRender_ = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
31
RetroFE/Source/Graphics/Component/Battery.h
Normal file
31
RetroFE/Source/Graphics/Component/Battery.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Battery : public Component
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Battery(Page &p, float scaleX, float scaleY, float reloadPeriod, SDL_Color fontColor);
|
||||||
|
virtual ~Battery();
|
||||||
|
void freeGraphicsMemory();
|
||||||
|
void allocateGraphicsMemory();
|
||||||
|
void drawBattery();
|
||||||
|
void update(float dt);
|
||||||
|
void draw();
|
||||||
|
bool mustRender();
|
||||||
|
|
||||||
|
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_;
|
||||||
|
};
|
||||||
@ -283,7 +283,7 @@ bool Page::mustRender()
|
|||||||
|
|
||||||
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
|
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
|
||||||
{
|
{
|
||||||
render = (*it)->mustRender();
|
render |= (*it)->mustRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
return render;
|
return render;
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#include "ViewInfo.h"
|
#include "ViewInfo.h"
|
||||||
#include "Component/Container.h"
|
#include "Component/Container.h"
|
||||||
#include "Component/Image.h"
|
#include "Component/Image.h"
|
||||||
|
#include "Component/Battery.h"
|
||||||
#include "Component/Text.h"
|
#include "Component/Text.h"
|
||||||
#include "Component/ReloadableText.h"
|
#include "Component/ReloadableText.h"
|
||||||
#include "Component/ReloadableMedia.h"
|
#include "Component/ReloadableMedia.h"
|
||||||
@ -387,6 +388,42 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page)
|
|||||||
page->addComponent(c);
|
page->addComponent(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(xml_node<> *componentXml = layout->first_node("battery"); componentXml; componentXml = componentXml->next_sibling("battery"))
|
||||||
|
{
|
||||||
|
xml_attribute<> *idReloadPeriod = componentXml->first_attribute("reloadPeriod");
|
||||||
|
xml_attribute<> *fontColorXml = componentXml->first_attribute("fontColor");
|
||||||
|
|
||||||
|
int reloadPeriod = 5;
|
||||||
|
if (idReloadPeriod)
|
||||||
|
{
|
||||||
|
reloadPeriod = Utils::convertInt(idReloadPeriod->value());
|
||||||
|
if(reloadPeriod < 1){
|
||||||
|
reloadPeriod = 1;
|
||||||
|
Logger::write(Logger::ZONE_ERROR, "Layout", "Battery component - reloadPeriod cannot be lower than 1, setting 1 as default");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Color fontColor = fontColor_;
|
||||||
|
if(fontColorXml)
|
||||||
|
{
|
||||||
|
int intColor = 0;
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::hex << fontColorXml->value();
|
||||||
|
ss >> intColor;
|
||||||
|
|
||||||
|
fontColor.b = intColor & 0xFF;
|
||||||
|
intColor >>= 8;
|
||||||
|
fontColor.g = intColor & 0xFF;
|
||||||
|
intColor >>= 8;
|
||||||
|
fontColor.r = intColor & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
Battery *c = new Battery(*page, scaleX_, scaleY_, reloadPeriod, fontColor);
|
||||||
|
buildViewInfo(componentXml, c->baseViewInfo);
|
||||||
|
loadTweens(c, componentXml);
|
||||||
|
page->addComponent(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for(xml_node<> *componentXml = layout->first_node("image"); componentXml; componentXml = componentXml->next_sibling("image"))
|
for(xml_node<> *componentXml = layout->first_node("image"); componentXml; componentXml = componentXml->next_sibling("image"))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -122,6 +122,7 @@ bool ImportConfiguration(Configuration *c)
|
|||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *dirp;
|
struct dirent *dirp;
|
||||||
|
|
||||||
|
/* Read settings file */
|
||||||
std::string settingsConfPath = Utils::combinePath(configPath, "settings.conf");
|
std::string settingsConfPath = Utils::combinePath(configPath, "settings.conf");
|
||||||
if(!c->import("", settingsConfPath))
|
if(!c->import("", settingsConfPath))
|
||||||
{
|
{
|
||||||
@ -129,8 +130,32 @@ bool ImportConfiguration(Configuration *c)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dp = opendir(launchersPath.c_str());
|
/* Read current layout */
|
||||||
|
std::string layoutConfPath = Utils::combinePath(configPath, "layout.conf");
|
||||||
|
if(!c->import("", layoutConfPath))
|
||||||
|
{
|
||||||
|
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + layoutConfPath + "\"");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read layouts */
|
||||||
|
std::string layoutDefaultPath = Utils::combinePath(Configuration::absolutePath, "layouts");
|
||||||
|
std::string layoutListDefaultPath = Utils::combinePath(layoutDefaultPath, "layouts.list");
|
||||||
|
if(!c->importLayouts(layoutDefaultPath, layoutListDefaultPath))
|
||||||
|
{
|
||||||
|
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + layoutListDefaultPath + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read layouts on user partition */
|
||||||
|
std::string layoutUserPath = Utils::combinePath(std::string("/mnt"), "themes");
|
||||||
|
std::string layoutListUserPath = Utils::combinePath(layoutUserPath, "themes.list");
|
||||||
|
if(!c->importLayouts(layoutUserPath, layoutListUserPath))
|
||||||
|
{
|
||||||
|
Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + layoutListUserPath + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open Launchers folder */
|
||||||
|
dp = opendir(launchersPath.c_str());
|
||||||
if(dp == NULL)
|
if(dp == NULL)
|
||||||
{
|
{
|
||||||
Logger::write(Logger::ZONE_INFO, "RetroFE", "Could not read directory \"" + launchersPath + "\"");
|
Logger::write(Logger::ZONE_INFO, "RetroFE", "Could not read directory \"" + launchersPath + "\"");
|
||||||
|
|||||||
@ -70,6 +70,7 @@ int *MenuMode::idx_menus = NULL;
|
|||||||
int MenuMode::nb_menu_zones = 0;
|
int MenuMode::nb_menu_zones = 0;
|
||||||
int MenuMode::menuItem=0;
|
int MenuMode::menuItem=0;
|
||||||
int MenuMode::stop_menu_loop = 0;
|
int MenuMode::stop_menu_loop = 0;
|
||||||
|
std::vector<std::string> MenuMode::layouts_;
|
||||||
|
|
||||||
SDL_Color MenuMode::text_color = {GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B};
|
SDL_Color MenuMode::text_color = {GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B};
|
||||||
int MenuMode::padding_y_from_center_menu_zone = 18;
|
int MenuMode::padding_y_from_center_menu_zone = 18;
|
||||||
@ -98,7 +99,7 @@ int usb_mounted = 0;
|
|||||||
|
|
||||||
|
|
||||||
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
/// -------------- FUNCTIONS IMPLEMENTATION --------------
|
||||||
void MenuMode::init( )
|
void MenuMode::init(Configuration &c)
|
||||||
{
|
{
|
||||||
MENU_DEBUG_PRINTF("Init MenuMode\n");
|
MENU_DEBUG_PRINTF("Init MenuMode\n");
|
||||||
/// ----- Loading the fonts -----
|
/// ----- Loading the fonts -----
|
||||||
@ -133,6 +134,14 @@ void MenuMode::init( )
|
|||||||
MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
|
MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ------ Copy config's layouts ------
|
||||||
|
layouts_ = c.layouts_;
|
||||||
|
|
||||||
|
std::vector<std::string>::iterator it;
|
||||||
|
for (it= layouts_.begin(); it < layouts_.end(); it++){
|
||||||
|
printf("%s\n", (*it).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
/// ------ Init menu zones ------
|
/// ------ Init menu zones ------
|
||||||
init_menu_zones();
|
init_menu_zones();
|
||||||
|
|
||||||
@ -242,6 +251,7 @@ void MenuMode::add_menu_zone(ENUM_MENU_TYPE menu_type){
|
|||||||
if(!menu_zone_surfaces[nb_menu_zones-1]) {
|
if(!menu_zone_surfaces[nb_menu_zones-1]) {
|
||||||
MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
|
MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// --------- Init Common Variables --------
|
/// --------- Init Common Variables --------
|
||||||
SDL_Surface *text_surface = NULL;
|
SDL_Surface *text_surface = NULL;
|
||||||
SDL_Surface *surface = menu_zone_surfaces[nb_menu_zones-1];
|
SDL_Surface *surface = menu_zone_surfaces[nb_menu_zones-1];
|
||||||
@ -315,6 +325,14 @@ void MenuMode::add_menu_zone(ENUM_MENU_TYPE menu_type){
|
|||||||
text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
|
text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
|
||||||
SDL_BlitSurface(text_surface, NULL, surface, &text_pos);*/
|
SDL_BlitSurface(text_surface, NULL, surface, &text_pos);*/
|
||||||
break;
|
break;
|
||||||
|
case MENU_TYPE_THEME:
|
||||||
|
MENU_DEBUG_PRINTF("Init MENU_TYPE_THEME\n");
|
||||||
|
/// ------ Text ------
|
||||||
|
text_surface = TTF_RenderText_Blended(menu_title_font, "SET THEME", text_color);
|
||||||
|
text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
|
||||||
|
text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone*2;
|
||||||
|
SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
|
||||||
|
break;
|
||||||
case MENU_TYPE_POWERDOWN:
|
case MENU_TYPE_POWERDOWN:
|
||||||
MENU_DEBUG_PRINTF("Init MENU_TYPE_POWERDOWN\n");
|
MENU_DEBUG_PRINTF("Init MENU_TYPE_POWERDOWN\n");
|
||||||
/// ------ Text ------
|
/// ------ Text ------
|
||||||
@ -347,6 +365,8 @@ void MenuMode::init_menu_zones(){
|
|||||||
//add_menu_zone(MENU_TYPE_EXIT);
|
//add_menu_zone(MENU_TYPE_EXIT);
|
||||||
/// Init USB Menu
|
/// Init USB Menu
|
||||||
add_menu_zone(MENU_TYPE_USB);
|
add_menu_zone(MENU_TYPE_USB);
|
||||||
|
/// Init Theme Menu
|
||||||
|
add_menu_zone(MENU_TYPE_THEME);
|
||||||
/// Init Powerdown Menu
|
/// Init Powerdown Menu
|
||||||
add_menu_zone(MENU_TYPE_POWERDOWN);
|
add_menu_zone(MENU_TYPE_POWERDOWN);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
#include <SDL/SDL_ttf.h>
|
#include <SDL/SDL_ttf.h>
|
||||||
#include <SDL/SDL_image.h>
|
#include <SDL/SDL_image.h>
|
||||||
|
#include "../Database/Configuration.h"
|
||||||
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
MENU_TYPE_VOLUME,
|
MENU_TYPE_VOLUME,
|
||||||
@ -11,6 +12,7 @@ typedef enum{
|
|||||||
MENU_TYPE_LOAD,
|
MENU_TYPE_LOAD,
|
||||||
MENU_TYPE_ASPECT_RATIO,
|
MENU_TYPE_ASPECT_RATIO,
|
||||||
MENU_TYPE_USB,
|
MENU_TYPE_USB,
|
||||||
|
MENU_TYPE_THEME,
|
||||||
MENU_TYPE_EXIT,
|
MENU_TYPE_EXIT,
|
||||||
MENU_TYPE_POWERDOWN,
|
MENU_TYPE_POWERDOWN,
|
||||||
NB_MENU_TYPES,
|
NB_MENU_TYPES,
|
||||||
@ -48,7 +50,7 @@ class MenuMode
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
//MenuMode();
|
//MenuMode();
|
||||||
static void init();
|
static void init(Configuration &c);
|
||||||
static void end();
|
static void end();
|
||||||
static void launch( );
|
static void launch( );
|
||||||
|
|
||||||
@ -129,4 +131,6 @@ private:
|
|||||||
static int aspect_ratio_factor_step;
|
static int aspect_ratio_factor_step;
|
||||||
|
|
||||||
static int savestate_slot;
|
static int savestate_slot;
|
||||||
|
|
||||||
|
static std::vector<std::string> layouts_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -264,7 +264,7 @@ void RetroFE::allocateGraphicsMemory( )
|
|||||||
currentPage_->initializeFonts( );
|
currentPage_->initializeFonts( );
|
||||||
|
|
||||||
// Init MenuMode
|
// Init MenuMode
|
||||||
MenuMode::init( );
|
MenuMode::init( config_ );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate textures
|
// Allocate textures
|
||||||
@ -323,7 +323,7 @@ void RetroFE::run( )
|
|||||||
fontcache_.initialize( );
|
fontcache_.initialize( );
|
||||||
|
|
||||||
// Initialize MenuMode
|
// Initialize MenuMode
|
||||||
MenuMode::init();
|
MenuMode::init( config_ );
|
||||||
|
|
||||||
// Define control configuration
|
// Define control configuration
|
||||||
std::string controlsConfPath = Utils::combinePath( Configuration::absolutePath, "controls.conf" );
|
std::string controlsConfPath = Utils::combinePath( Configuration::absolutePath, "controls.conf" );
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user