Refactored power-related code, added drawIcon
-Removed unneeded white charge icon -Added common power interface
This commit is contained in:
parent
caedcab0ac
commit
47bd2d31c6
@ -26,7 +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/charging_icon.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 $@
|
||||
|
||||
@ -90,12 +90,7 @@ 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
|
||||
build_pc/charging_icon.bin.o : data/charging_icon.bin
|
||||
mkdir -p $(dir $@)
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
@ -58,6 +58,7 @@ typedef union {
|
||||
#include "math.h"
|
||||
#include "theme.h"
|
||||
#include "message-box.h"
|
||||
#include "power.h"
|
||||
|
||||
void menuStartupPath(void);
|
||||
void menuStartup(void);
|
||||
|
@ -6,8 +6,7 @@
|
||||
#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"
|
||||
#include "charging_icon_bin.h"
|
||||
|
||||
char rootPathBase[PATH_MAX];
|
||||
char rootPath[PATH_MAX+8];
|
||||
@ -109,6 +108,21 @@ static void drawImage(int x, int y, int width, int height, const uint8_t *image,
|
||||
}
|
||||
}
|
||||
|
||||
//Draws an RGBA8888 image masked by the passed color.
|
||||
static void drawIcon(int x, int y, int width, int height, const uint8_t *image, color_t color) {
|
||||
int tmpx, tmpy;
|
||||
int pos;
|
||||
color_t current_color;
|
||||
|
||||
for (tmpy=0; tmpy<height; tmpy++) {
|
||||
for (tmpx=0; tmpx<width; tmpx++) {
|
||||
pos = ((tmpy*width) + tmpx) * 4;
|
||||
current_color = MakeColor(color.r, color.g, color.b, image[pos+3]);
|
||||
DrawPixel(x+tmpx, y+tmpy, current_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *folder_icon_small;
|
||||
uint8_t *invalid_icon_small;
|
||||
uint8_t *theme_icon_small;
|
||||
@ -323,9 +337,6 @@ void menuStartupPath(void) {
|
||||
}
|
||||
|
||||
uint8_t *charging_icon_small;
|
||||
#ifdef __SWITCH__
|
||||
static bool psmInitialized = false;
|
||||
#endif
|
||||
|
||||
void menuStartup(void) {
|
||||
menuScan(rootPath);
|
||||
@ -333,38 +344,12 @@ void menuStartup(void) {
|
||||
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, 9, 15, 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, 9, 15, IMAGE_MODE_RGBA32);
|
||||
}
|
||||
charging_icon_small = downscaleImg(charging_icon_bin, 155, 256, 9, 15, 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) {
|
||||
@ -441,30 +426,20 @@ void drawTime() {
|
||||
}
|
||||
|
||||
void drawCharge() {
|
||||
|
||||
char chargeString[5];
|
||||
|
||||
uint32_t batteryCharge;
|
||||
ChargerType chargeType = ChargerType_None;
|
||||
bool isCharging;
|
||||
|
||||
powerGetDetails(&batteryCharge, &isCharging);
|
||||
batteryCharge = (batteryCharge > 100) ? 100 : batteryCharge;
|
||||
|
||||
#ifdef __SWITCH__
|
||||
if (psmInitialized)
|
||||
{
|
||||
psmGetBatteryChargePercentage(&batteryCharge);
|
||||
psmGetChargerType(&chargeType);
|
||||
}
|
||||
#else
|
||||
batteryCharge = 100;
|
||||
#endif
|
||||
|
||||
sprintf(chargeString, "%d%%", (int)batteryCharge);
|
||||
sprintf(chargeString, "%d%%", batteryCharge);
|
||||
|
||||
int tmpX = GetTextXCoordinate(interuiregular14, 1180, chargeString, 'r');
|
||||
|
||||
DrawText(interuiregular14, tmpX, 0 + 47 + 10 + 21, themeCurrent.textColor, chargeString);
|
||||
|
||||
if (chargeType > (ChargerType)ChargerType_None)
|
||||
drawImage(tmpX - 20, 0 + 47 + 10 + 5, 9, 15, charging_icon_small, IMAGE_MODE_RGBA32);
|
||||
if (isCharging)
|
||||
drawIcon(tmpX - 20, 0 + 47 + 10 + 5, 9, 15, charging_icon_small, themeCurrent.textColor);
|
||||
}
|
||||
|
||||
void drawBackBtn(menu_s* menu, bool emptyDir) {
|
||||
|
8
common/power.h
Normal file
8
common/power.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include "common.h"
|
||||
|
||||
void powerInit(void);
|
||||
|
||||
void powerGetDetails(uint32_t *batteryCharge, bool *isCharging);
|
||||
|
||||
void powerExit(void);
|
Binary file not shown.
@ -45,6 +45,7 @@ int main(int argc, char **argv)
|
||||
|
||||
themeStartup((ThemePreset)theme);
|
||||
textInit();
|
||||
powerInit();
|
||||
menuStartup();
|
||||
|
||||
launchInit();
|
||||
@ -101,7 +102,7 @@ int main(int argc, char **argv)
|
||||
|
||||
fontExit();
|
||||
launchExit();
|
||||
menuExit();
|
||||
powerExit();
|
||||
plExit();
|
||||
setsysExit();
|
||||
|
||||
|
38
nx_main/nx_power.c
Normal file
38
nx_main/nx_power.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include <switch.h>
|
||||
#include "../common/common.h"
|
||||
|
||||
static bool psmInitialized;
|
||||
|
||||
|
||||
void powerGetDetails(uint32_t *batteryCharge, bool *isCharging) {
|
||||
ChargerType charger = ChargerType_None;
|
||||
|
||||
*isCharging = false;
|
||||
*batteryCharge = 0;
|
||||
|
||||
if (psmInitialized)
|
||||
{
|
||||
psmGetBatteryChargePercentage(batteryCharge);
|
||||
psmGetChargerType(&charger);
|
||||
*isCharging = (charger > ChargerType_None);
|
||||
}
|
||||
}
|
||||
|
||||
void powerInit(void) {
|
||||
if (!psmInitialized)
|
||||
{
|
||||
Result rc = psmInitialize();
|
||||
if (R_SUCCEEDED(rc))
|
||||
{
|
||||
psmInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void powerExit(void) {
|
||||
if (psmInitialized)
|
||||
{
|
||||
psmExit();
|
||||
psmInitialized = false;
|
||||
}
|
||||
}
|
15
pc_main/pc_power.c
Normal file
15
pc_main/pc_power.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include "../common/common.h"
|
||||
|
||||
|
||||
void powerInit(void) {
|
||||
|
||||
}
|
||||
|
||||
void powerExit(void) {
|
||||
|
||||
}
|
||||
|
||||
void powerGetDetails(uint32_t *batteryCharge, bool *isCharging)
|
||||
*isCharging = false;
|
||||
*batteryCharge = 100;
|
||||
}
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.9 KiB |
Loading…
Reference in New Issue
Block a user