Add support to display current charge, and indicate whether or not device is charging.

Added menuExit function to handle deinit for psm
Not certain how you want that handled for PC, so psm isolated to switch
Updated Makefile.pc to incorporate new icon binaries
This commit is contained in:
Daniel Bernard 2018-10-07 09:57:00 -05:00
parent e1a1bac230
commit 665b017cf0
8 changed files with 75 additions and 0 deletions

View File

@ -26,6 +26,7 @@ test : pc_main/main.cpp pc_main/pc_launch.c \
build_pc/invalid_icon.bin.o build_pc/folder_icon.bin.o \
build_pc/hbmenu_logo_light.bin.o build_pc/hbmenu_logo_dark.bin.o \
build_pc/theme_icon_dark.bin.o build_pc/theme_icon_light.bin.o \
build_pc/charging_icon_black.bin.o build_pc/charging_icon_white.bin.o \
#build_pc/tahoma24.o build_pc/tahoma12.o build_pc/interuimedium20.o build_pc/interuimedium30.o build_pc/interuiregular14.o build_pc/interuiregular18.o
gcc -Wall -O2 -g -DVERSION=\"v$(APP_VERSION)\" $(EXTRA_CFLAGS) `pkg-config freetype2 --cflags` $^ -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ `pkg-config freetype2 --libs` -lm -lz -lconfig -lturbojpeg $(EXTRA_LDFLAGS) -I. -iquote $(DEVKITPRO)/libnx/include -Ibuild_pc -g -o $@
@ -89,6 +90,16 @@ build_pc/theme_icon_dark.bin.o : data/theme_icon_dark.bin
@echo $(notdir $<)
@$(bin2o)
build_pc/charging_icon_black.bin.o : data/charging_icon_black.bin
mkdir -p $(dir $@)
@echo $(notdir $<)
@$(bin2o)
build_pc/charging_icon_white.bin.o : data/charging_icon_white.bin
mkdir -p $(dir $@)
@echo $(notdir $<)
@$(bin2o)
clean:
rm -rf build_pc/ test test.*

View File

@ -63,6 +63,7 @@ void menuStartupPath(void);
void menuStartup(void);
void themeMenuStartup(void);
void menuLoop(void);
void menuExit(void);
static inline uint8_t BlendColor(uint32_t src, uint32_t dst, uint8_t alpha)
{

View File

@ -6,6 +6,8 @@
#include "folder_icon_bin.h"
#include "theme_icon_dark_bin.h"
#include "theme_icon_light_bin.h"
#include "charging_icon_black_bin.h"
#include "charging_icon_white_bin.h"
char rootPathBase[PATH_MAX];
char rootPath[PATH_MAX+8];
@ -320,17 +322,49 @@ void menuStartupPath(void) {
}
}
uint8_t *charging_icon_small;
#ifdef __SWITCH__
static bool psmInitialized = false;
#endif
void menuStartup(void) {
menuScan(rootPath);
folder_icon_small = downscaleImg(folder_icon_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
invalid_icon_small = downscaleImg(invalid_icon_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
if(themeGlobalPreset == THEME_PRESET_DARK)
{
theme_icon_small = downscaleImg(theme_icon_dark_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
charging_icon_small = downscaleImg(charging_icon_white_bin, 155, 256, 14, 23, IMAGE_MODE_RGBA32);
}
else
{
theme_icon_small = downscaleImg(theme_icon_light_bin, 256, 256, 140, 140, IMAGE_MODE_RGB24);
charging_icon_small = downscaleImg(charging_icon_black_bin, 155, 256, 14, 23, IMAGE_MODE_RGBA32);
}
computeFrontGradient(themeCurrent.frontWaveColor, 280);
//menuCreateMsgBox(780, 300, "This is a test");
#ifdef __SWITCH__
if (!psmInitialized)
{
Result rc = psmInitialize();
if (R_SUCCEEDED(rc))
{
psmInitialized = true;
}
}
#endif
}
void menuExit(void) {
#ifdef __SWITCH__
if (psmInitialized)
{
psmExit();
}
#endif
}
void themeMenuStartup(void) {
@ -406,6 +440,33 @@ void drawTime() {
}
void drawCharge() {
char chargeString[5];
uint32_t batteryCharge;
ChargerType chargeType = 0;
#ifdef __SWITCH__
psmGetBatteryChargePercentage(&batteryCharge);
#else
batteryCharge = 100;
#endif
sprintf(chargeString, "%d%%", (int)batteryCharge);
int tmpX = GetTextXCoordinate(interuimedium20, 1180, chargeString, 'r');
DrawText(interuimedium20, tmpX, 0 + 47 + 10 + 32, themeCurrent.textColor, chargeString);
#ifdef __SWITCH__
psmGetChargerType(&chargeType);
#endif
if (chargeType > (ChargerType)ChargerType_None)
drawImage(tmpX - 20, 0 + 47 + 10 + 9, 14, 23, charging_icon_small, IMAGE_MODE_RGBA32);
}
void drawBackBtn(menu_s* menu, bool emptyDir) {
int x_image = 1280 - 252 - 30 - 32;
int x_text = 1280 - 216 - 30 - 32;
@ -462,6 +523,7 @@ void menuLoop(void) {
#endif
drawTime();
drawCharge();
if (menu->nEntries==0 || hbmenu_state == HBMENU_NETLOADER_ACTIVE)
{

Binary file not shown.

Binary file not shown.

View File

@ -101,6 +101,7 @@ int main(int argc, char **argv)
fontExit();
launchExit();
menuExit();
plExit();
setsysExit();

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB