Merge pull request #4281 from bparker06/battery

Add option to show battery level on menu next to the clock
This commit is contained in:
Jean-André Santoni 2016-12-20 00:35:45 +01:00 committed by GitHub
commit 9a0c7f4a07
13 changed files with 110 additions and 3 deletions

View File

@ -787,6 +787,7 @@ static int populate_settings_bool(settings_t *settings, struct config_bool_setti
SETTING_BOOL("menu_mouse_enable", &settings->menu.mouse.enable, true, def_mouse_enable, false);
SETTING_BOOL("menu_pointer_enable", &settings->menu.pointer.enable, true, pointer_enable, false);
SETTING_BOOL("menu_timedate_enable", &settings->menu.timedate_enable, true, true, false);
SETTING_BOOL("menu_battery_level_enable", &settings->menu.battery_level_enable, true, true, false);
SETTING_BOOL("menu_core_enable", &settings->menu.core_enable, true, true, false);
SETTING_BOOL("menu_dynamic_wallpaper_enable", &settings->menu.dynamic_wallpaper_enable, true, false, false);
#ifdef HAVE_XMB

View File

@ -125,6 +125,7 @@ typedef struct settings
char driver[32];
bool pause_libretro;
bool timedate_enable;
bool battery_level_enable;
bool core_enable;
bool dynamic_wallpaper_enable;
unsigned thumbnails;

2
deps/SPIRV-Cross vendored

@ -1 +1 @@
Subproject commit 875c32fd39a06f624814effe5eab691b078429f5
Subproject commit cc207e32c8668bfe5a5cc514394e7df8f020ecf6

@ -1 +1 @@
Subproject commit be8462149a3c150fc89db84e57ef06de3ab90d47
Subproject commit ec2e27adf86a911c5af6c676a539166b5674a09d

View File

@ -2278,3 +2278,5 @@ MSG_HASH(MENU_ENUM_SUBLABEL_VIDEO_FONT_ENABLE,
"OSDメッセージを表する。")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETWORK_USER_REMOTE_ENABLE,
"ユーザー%dのリモートを有効")
MSG_HASH(MENU_ENUM_LABEL_VALUE_BATTERY_LEVEL_ENABLE,
"電池残量を表示")

View File

@ -1163,3 +1163,5 @@ MSG_HASH(MENU_ENUM_LABEL_INPUT_UNIFIED_MENU_CONTROLS,
"unified_menu_controls")
MSG_HASH(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR,
"detect_core_list_push_dir")
MSG_HASH(MENU_ENUM_LABEL_BATTERY_LEVEL_ENABLE,
"menu_battery_level_enable")

View File

@ -1614,6 +1614,10 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
snprintf(s, len,
"Shows current date and/or time inside menu.");
break;
case MENU_ENUM_LABEL_BATTERY_LEVEL_ENABLE:
snprintf(s, len,
"Shows current battery level inside menu.");
break;
case MENU_ENUM_LABEL_CORE_ENABLE:
snprintf(s, len,
"Shows current core inside menu.");

View File

@ -2349,3 +2349,5 @@ MSG_HASH(MENU_ENUM_SUBLABEL_VIDEO_FONT_ENABLE,
"Show onscreen messages.")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETWORK_USER_REMOTE_ENABLE,
"User %d Remote Enable")
MSG_HASH(MENU_ENUM_LABEL_VALUE_BATTERY_LEVEL_ENABLE,
"Display battery level")

View File

@ -29,6 +29,7 @@
#include <lists/string_list.h>
#include <gfx/math/matrix_4x4.h>
#include <encodings/utf.h>
#include <features/features_cpu.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
@ -68,6 +69,8 @@
#define XMB_DELAY 10
#endif
#define BATTERY_LEVEL_CHECK_INTERVAL (30 * 1000000)
#if 0
#define XMB_DEBUG
#endif
@ -126,6 +129,8 @@ enum
XMB_TEXTURE_SWITCH_ON,
XMB_TEXTURE_SWITCH_OFF,
XMB_TEXTURE_CLOCK,
XMB_TEXTURE_BATTERY_FULL,
XMB_TEXTURE_BATTERY_CHARGING,
XMB_TEXTURE_POINTER,
XMB_TEXTURE_ADD,
XMB_TEXTURE_KEY,
@ -2515,6 +2520,7 @@ static void xmb_draw_dark_layer(
static void xmb_frame(void *data)
{
size_t selection;
size_t datetime_width = 0;
math_matrix_4x4 mymat;
unsigned i, width, height;
float item_color[16], coord_black[16], coord_white[16];
@ -2591,7 +2597,6 @@ static void xmb_frame(void *data)
menu_display_rotate_z(&rotate_draw);
menu_display_blend_begin();
/* Clock image */
menu_display_set_alpha(coord_white, MIN(xmb->alpha, 1.00f));
@ -2622,12 +2627,76 @@ static void xmb_frame(void *data)
menu_display_timedate(&datetime);
datetime_width = font_driver_get_message_width(xmb->font, timedate, utf8len(timedate), 1);
xmb_draw_text(xmb, timedate,
width - xmb->margins.title.left - xmb->icon.size / 4,
xmb->margins.title.top, 1, 1, TEXT_ALIGN_RIGHT,
width, height, xmb->font);
}
if (settings->menu.battery_level_enable)
{
static retro_time_t last_time = 0;
static int percent = 0;
static enum frontend_powerstate state = FRONTEND_POWERSTATE_NONE;
int seconds = 0;
bool time_to_update = false;
const frontend_ctx_driver_t *frontend = frontend_get_ptr();
retro_time_t current_time = cpu_features_get_time_usec();
if (current_time - last_time >= BATTERY_LEVEL_CHECK_INTERVAL)
time_to_update = true;
if (frontend && frontend->get_powerstate)
{
char msg[12];
bool charging = (state == FRONTEND_POWERSTATE_CHARGING);
if (time_to_update)
state = frontend->get_powerstate(&seconds, &percent);
*msg = '\0';
last_time = current_time;
if (percent > 0)
{
size_t x_pos = 0;
size_t x_pos_icon = xmb->margins.title.left / 2;
if (datetime_width)
x_pos_icon += datetime_width + (xmb->icon.size / 2) + (xmb->margins.title.left / 2);
if (coord_white[3] != 0)
xmb_draw_icon(
xmb->icon.size,
&mymat,
xmb->textures.list[charging ? XMB_TEXTURE_BATTERY_CHARGING : XMB_TEXTURE_BATTERY_FULL],
width - (xmb->icon.size / 2) - x_pos_icon,
xmb->icon.size,
width,
height,
1,
0,
1,
&coord_white[0],
xmb->shadow_offset);
snprintf(msg, sizeof(msg), "%d%%", percent);
if (datetime_width)
x_pos = datetime_width + (xmb->icon.size / 5) +
xmb->margins.title.left;
xmb_draw_text(xmb, msg,
width - xmb->margins.title.left - x_pos,
xmb->margins.title.top, 1, 1, TEXT_ALIGN_RIGHT,
width, height, xmb->font);
}
}
}
/* Arrow image */
menu_display_set_alpha(coord_white, MIN(xmb->textures.arrow.alpha, xmb->alpha));
@ -3258,6 +3327,10 @@ static const char *xmb_texture_path(unsigned id)
return "resume.png";
case XMB_TEXTURE_CLOCK:
return "clock.png";
case XMB_TEXTURE_BATTERY_FULL:
return "battery-full.png";
case XMB_TEXTURE_BATTERY_CHARGING:
return "battery-charging.png";
case XMB_TEXTURE_POINTER:
return "pointer.png";
case XMB_TEXTURE_SAVESTATE:

View File

@ -4554,6 +4554,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_TIMEDATE_ENABLE,
PARSE_ONLY_BOOL, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_BATTERY_LEVEL_ENABLE,
PARSE_ONLY_BOOL, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_CORE_ENABLE,
PARSE_ONLY_BOOL, false);

View File

@ -5181,6 +5181,21 @@ static bool setting_append_list(
general_read_handler,
SD_FLAG_ADVANCED);
CONFIG_BOOL(
list, list_info,
&settings->menu.battery_level_enable,
MENU_ENUM_LABEL_BATTERY_LEVEL_ENABLE,
MENU_ENUM_LABEL_VALUE_BATTERY_LEVEL_ENABLE,
true,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_ADVANCED);
CONFIG_BOOL(
list, list_info,
&settings->menu.core_enable,

View File

@ -665,6 +665,7 @@ enum msg_hash_enums
MENU_LABEL(XMB_RIBBON_ENABLE),
MENU_LABEL(THUMBNAILS),
MENU_LABEL(TIMEDATE_ENABLE),
MENU_LABEL(BATTERY_LEVEL_ENABLE),
MENU_LABEL(MATERIALUI_MENU_COLOR_THEME),
/* UI settings */

View File

@ -652,6 +652,9 @@
# Shows current date and/or time inside menu.
# menu_timedate_enable = true
# Shows current battery level inside menu.
# menu_battery_level_enable = true
# Shows current core inside menu.
# menu_core_enable = true