Commit 7662962d authored by Supernature2k's avatar Supernature2k

add battery % in main menu

parent 3ee3c1ce
This diff is collapsed.
......@@ -490,3 +490,19 @@ bool RecalboxSystem::ping() {
return exitcode == 0;
}
std::pair<std::string, int> RecalboxSystem::getBatteryInfo(){
std::pair<std::string, int> result;
int percent;
SDL_GetPowerInfo(NULL,&percent);
result.second = percent;
if (percent>66)
result.first = "\uF1ba";
else if (percent>33)
result.first = "\uF1b8";
else if (percent>15)
result.first = "\uF1b1";
else
result.first = "\uF1b5";
return result;
}
......@@ -68,6 +68,8 @@ public:
std::pair<std::string, int> execute(std::string command);
std::pair<std::string, int> getBatteryInfo();
private:
static RecalboxSystem *instance;
......
#include <Settings.h>
#include <recalbox/RecalboxSystem.h>
#include "components/MenuComponent.h"
#include "components/ButtonComponent.h"
#include "Locale.h"
......@@ -34,15 +35,35 @@ MenuComponent::MenuComponent(Window* window, const char* title, const std::share
if (title == _("MAIN MENU") && Settings::getInstance()->getBool("ShowClock")) {
if (title == _("MAIN MENU") ) {
mDateTime = std::make_shared<DateTimeComponent>(mWindow);
mDateTime->setDisplayMode(DateTimeComponent::DISP_TIME);
mDateTime->setFont(menuTheme->menuText.font);
mDateTime->setColor(menuTheme->menuText.color);
auto headerGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(7, 1));
headerGrid->setEntry(mDateTime, Vector2i(6, 0), false);
mGrid.setEntry(headerGrid, Vector2i(0, 0), false);
auto batt = RecalboxSystem::getInstance()->getBatteryInfo();
auto headerGrid = std::make_shared<ComponentGrid>(mWindow, Vector2i(7, 1));
if (batt.second != -1){
auto batDisplay = std::make_shared<TextComponent>(mWindow);
batDisplay->setFont(menuTheme->menuText.font);
if (batt.second <= 15)
batDisplay->setColor(0xFF0000FF);
else
batDisplay->setColor(menuTheme->menuText.color);
batDisplay->setText(batt.first + " " + std::to_string(batt.second) + "%");
batDisplay->setHorizontalAlignment(ALIGN_CENTER);
headerGrid->setEntry(batDisplay, Vector2i(0,0), false);
}
if (Settings::getInstance()->getBool("ShowClock")) {
mDateTime = std::make_shared<DateTimeComponent>(mWindow);
mDateTime->setDisplayMode(DateTimeComponent::DISP_TIME);
mDateTime->setFont(menuTheme->menuText.font);
mDateTime->setColor(menuTheme->menuText.color);
headerGrid->setEntry(mDateTime, Vector2i(6, 0), false);
}
mGrid.setEntry(headerGrid, Vector2i(0, 0), false);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment