diff --git a/RetroFE/Source/CMakeLists.txt b/RetroFE/Source/CMakeLists.txt index 54dca20..636a548 100755 --- a/RetroFE/Source/CMakeLists.txt +++ b/RetroFE/Source/CMakeLists.txt @@ -145,6 +145,7 @@ set(RETROFE_HEADERS "${RETROFE_DIR}/Source/Graphics/Component/Container.h" "${RETROFE_DIR}/Source/Graphics/Component/Component.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/ReloadableMedia.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/Component.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/Text.cpp" "${RETROFE_DIR}/Source/Graphics/Component/ReloadableMedia.cpp" diff --git a/RetroFE/Source/Database/Configuration.cpp b/RetroFE/Source/Database/Configuration.cpp index 3a656d1..dfafab7 100644 --- a/RetroFE/Source/Database/Configuration.cpp +++ b/RetroFE/Source/Database/Configuration.cpp @@ -58,7 +58,7 @@ void Configuration::initialize() // Or check for home based flat file works on linux/mac else if (retrofe_path && std::getline( retrofe_path, absolutePath )) { - retrofe_path.close(); + retrofe_path.close(); } #endif // Or check executable for path @@ -72,8 +72,8 @@ void Configuration::initialize() sPath = Utils::getDirectory(sPath); sPath = Utils::getParentDirectory(sPath); #elif __APPLE__ - char exepath[PROC_PIDPATHINFO_MAXSIZE]; - if( proc_pidpath (getpid(), exepath, sizeof(exepath)) <= 0 ) // Error to console if no path to write logs… + char exepath[PROC_PIDPATHINFO_MAXSIZE]; + if( proc_pidpath (getpid(), exepath, sizeof(exepath)) <= 0 ) // Error to console if no path to write logs… fprintf(stderr, "Cannot set absolutePath: %s\nOverride with RETROFE_PATH env var\n", strerror(errno)); std::string sPath = Utils::getDirectory(exepath); @@ -82,7 +82,7 @@ void Configuration::initialize() // as an example /usr/local/opt/retro/RetroFE.app/Contents/MacOS becomes /usr/local/opt/retrofe // Note: executing 'brew applinks retrofe' - should create symlink to /Applications/RetroFE.app size_t rootPos = sPath.find("/RetroFE.app/Contents/MacOS"); - if(rootPos!=std::string::npos) + if(rootPos!=std::string::npos) sPath = sPath.erase(rootPos); #else char exepath[1024] = {}; @@ -136,6 +136,62 @@ bool Configuration::import(std::string collection, std::string keyPrefix, std::s 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) { @@ -147,7 +203,7 @@ bool Configuration::parseLine(std::string collection, std::string keyPrefix, std // strip out any comments line = Utils::filterComments(line); - + if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos)) { retVal = true; @@ -172,6 +228,14 @@ bool Configuration::parseLine(std::string collection, std::string keyPrefix, std { 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 */ properties_.insert(PropertiesPair(key, value)); std::stringstream ss; @@ -372,7 +436,7 @@ void Configuration::getMediaPropertyAbsolutePath(std::string collectionName, std void Configuration::getMediaPropertyAbsolutePath(std::string collectionName, std::string mediaType, bool system, std::string &value) { std::string key = "collections." + collectionName + ".media." + mediaType; - if (system) + if (system) { key = "collections." + collectionName + ".media.system_artwork"; } diff --git a/RetroFE/Source/Database/Configuration.h b/RetroFE/Source/Database/Configuration.h index 1ab8c63..01d655b 100644 --- a/RetroFE/Source/Database/Configuration.h +++ b/RetroFE/Source/Database/Configuration.h @@ -30,6 +30,7 @@ public: // gets the global configuration bool import(std::string keyPrefix, std::string file); 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, int &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 getCollectionAbsolutePath(std::string collectionName, std::string &value); static std::string absolutePath; + std::vector layouts_; private: bool getRawProperty(std::string key, std::string &value); diff --git a/RetroFE/Source/Graphics/Component/Battery.cpp b/RetroFE/Source/Graphics/Component/Battery.cpp new file mode 100644 index 0000000..3dcd38f --- /dev/null +++ b/RetroFE/Source/Graphics/Component/Battery.cpp @@ -0,0 +1,250 @@ +#include "Battery.h" +#include "../ViewInfo.h" +#include "../../SDL.h" +#include "../../Utility/Log.h" +#include + + +#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(baseViewInfo.XRelativeToOrigin()); + rect.y = static_cast(baseViewInfo.YRelativeToOrigin()); + rect.h = static_cast(baseViewInfo.ScaledHeight()); + rect.w = static_cast(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; +} diff --git a/RetroFE/Source/Graphics/Component/Battery.h b/RetroFE/Source/Graphics/Component/Battery.h new file mode 100644 index 0000000..ee915d3 --- /dev/null +++ b/RetroFE/Source/Graphics/Component/Battery.h @@ -0,0 +1,31 @@ +#pragma once + +#include "Component.h" +#include +#include + +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_; +}; diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 9ae7b9d..9ae53d7 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -283,7 +283,7 @@ bool Page::mustRender() for(std::vector::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) { - render = (*it)->mustRender(); + render |= (*it)->mustRender(); } return render; diff --git a/RetroFE/Source/Graphics/PageBuilder.cpp b/RetroFE/Source/Graphics/PageBuilder.cpp index e07d668..53ca31e 100644 --- a/RetroFE/Source/Graphics/PageBuilder.cpp +++ b/RetroFE/Source/Graphics/PageBuilder.cpp @@ -19,6 +19,7 @@ #include "ViewInfo.h" #include "Component/Container.h" #include "Component/Image.h" +#include "Component/Battery.h" #include "Component/Text.h" #include "Component/ReloadableText.h" #include "Component/ReloadableMedia.h" @@ -207,7 +208,7 @@ Page *PageBuilder::buildPage( std::string collectionName ) page = new Page(config_); - if(minShowTimeXml) + if(minShowTimeXml) { page->setMinShowTime(Utils::convertFloat(minShowTimeXml->value())); } @@ -387,6 +388,42 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page) 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")) { @@ -531,7 +568,7 @@ bool PageBuilder::buildComponents(xml_node<> *layout, Page *page) void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName, Page *page) { - + for(xml_node<> *componentXml = layout->first_node(tagName.c_str()); componentXml; componentXml = componentXml->next_sibling(tagName.c_str())) { std::string reloadableImagePath; @@ -615,7 +652,7 @@ void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName, } } - if(selectedOffsetXml) + if(selectedOffsetXml) { std::stringstream ss; ss << selectedOffsetXml->value(); @@ -711,7 +748,7 @@ void PageBuilder::loadReloadableImages(xml_node<> *layout, std::string tagName, { alignment = alignmentXml->value(); } - + std::string singlePrefix = ""; if (singlePrefixXml) { @@ -1195,7 +1232,7 @@ void PageBuilder::buildVerticalMenu(ScrollingList *menu, xml_node<> *menuXml, xm std::stringstream ss; - ss << "Design error! Selected menu item was set to " << selectedIndex + ss << "Design error! Selected menu item was set to " << selectedIndex << " although there are only " << points->size() << " menu points that can be displayed"; diff --git a/RetroFE/Source/Main.cpp b/RetroFE/Source/Main.cpp index f27af0d..fa3d33c 100644 --- a/RetroFE/Source/Main.cpp +++ b/RetroFE/Source/Main.cpp @@ -122,15 +122,40 @@ bool ImportConfiguration(Configuration *c) DIR *dp; struct dirent *dirp; + /* Read settings file */ std::string settingsConfPath = Utils::combinePath(configPath, "settings.conf"); if(!c->import("", settingsConfPath)) { Logger::write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + settingsConfPath + "\""); 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) { Logger::write(Logger::ZONE_INFO, "RetroFE", "Could not read directory \"" + launchersPath + "\""); diff --git a/RetroFE/Source/Menu/MenuMode.cpp b/RetroFE/Source/Menu/MenuMode.cpp index a40caa6..fd37da9 100644 --- a/RetroFE/Source/Menu/MenuMode.cpp +++ b/RetroFE/Source/Menu/MenuMode.cpp @@ -70,6 +70,7 @@ int *MenuMode::idx_menus = NULL; int MenuMode::nb_menu_zones = 0; int MenuMode::menuItem=0; int MenuMode::stop_menu_loop = 0; +std::vector MenuMode::layouts_; SDL_Color MenuMode::text_color = {GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B}; int MenuMode::padding_y_from_center_menu_zone = 18; @@ -98,7 +99,7 @@ int usb_mounted = 0; /// -------------- FUNCTIONS IMPLEMENTATION -------------- -void MenuMode::init( ) +void MenuMode::init(Configuration &c) { MENU_DEBUG_PRINTF("Init MenuMode\n"); /// ----- Loading the fonts ----- @@ -133,6 +134,14 @@ void MenuMode::init( ) MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError()); } + /// ------ Copy config's layouts ------ + layouts_ = c.layouts_; + + std::vector::iterator it; + for (it= layouts_.begin(); it < layouts_.end(); it++){ + printf("%s\n", (*it).c_str()); + } + /// ------ 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]) { MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError()); } + /// --------- Init Common Variables -------- SDL_Surface *text_surface = NULL; 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; SDL_BlitSurface(text_surface, NULL, surface, &text_pos);*/ 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: MENU_DEBUG_PRINTF("Init MENU_TYPE_POWERDOWN\n"); /// ------ Text ------ @@ -347,6 +365,8 @@ void MenuMode::init_menu_zones(){ //add_menu_zone(MENU_TYPE_EXIT); /// Init USB Menu add_menu_zone(MENU_TYPE_USB); + /// Init Theme Menu + add_menu_zone(MENU_TYPE_THEME); /// Init Powerdown Menu add_menu_zone(MENU_TYPE_POWERDOWN); } diff --git a/RetroFE/Source/Menu/MenuMode.h b/RetroFE/Source/Menu/MenuMode.h index 5306e5e..7cf410a 100644 --- a/RetroFE/Source/Menu/MenuMode.h +++ b/RetroFE/Source/Menu/MenuMode.h @@ -3,6 +3,7 @@ #include #include #include +#include "../Database/Configuration.h" typedef enum{ MENU_TYPE_VOLUME, @@ -11,6 +12,7 @@ typedef enum{ MENU_TYPE_LOAD, MENU_TYPE_ASPECT_RATIO, MENU_TYPE_USB, + MENU_TYPE_THEME, MENU_TYPE_EXIT, MENU_TYPE_POWERDOWN, NB_MENU_TYPES, @@ -48,7 +50,7 @@ class MenuMode public: //MenuMode(); - static void init(); + static void init(Configuration &c); static void end(); static void launch( ); @@ -129,4 +131,6 @@ private: static int aspect_ratio_factor_step; static int savestate_slot; + + static std::vector layouts_; }; diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index ecbc3a3..8a092df 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -264,7 +264,7 @@ void RetroFE::allocateGraphicsMemory( ) currentPage_->initializeFonts( ); // Init MenuMode - MenuMode::init( ); + MenuMode::init( config_ ); } // Allocate textures @@ -323,7 +323,7 @@ void RetroFE::run( ) fontcache_.initialize( ); // Initialize MenuMode - MenuMode::init(); + MenuMode::init( config_ ); // Define control configuration std::string controlsConfPath = Utils::combinePath( Configuration::absolutePath, "controls.conf" );