mirror of
https://github.com/libretro/RetroArch
synced 2025-02-09 00:40:09 +00:00
Merge pull request #10252 from natinusala/split-widgets
gfx_widgets: move volume into its own file
This commit is contained in:
commit
e1debd6f11
@ -841,7 +841,8 @@ endif
|
||||
|
||||
ifeq ($(HAVE_GFX_WIDGETS), 1)
|
||||
OBJ += gfx/gfx_widgets.o \
|
||||
gfx/widgets/gfx_widget_screenshot.o
|
||||
gfx/widgets/gfx_widget_screenshot.o \
|
||||
gfx/widgets/gfx_widget_volume.o
|
||||
endif
|
||||
|
||||
ifeq ($(HAVE_OVERLAY), 1)
|
||||
|
@ -64,8 +64,6 @@ void gfx_widgets_set_persistence(bool persist)
|
||||
static float msg_queue_background[16] = COLOR_HEX_TO_FLOAT(0x3A3A3A, 1.0f);
|
||||
static float msg_queue_info[16] = COLOR_HEX_TO_FLOAT(0x12ACF8, 1.0f);
|
||||
|
||||
/* TODO: Colors for warning, error and success */
|
||||
|
||||
static float msg_queue_task_progress_1[16] = COLOR_HEX_TO_FLOAT(0x397869, 1.0f); /* Color of first progress bar in a task message */
|
||||
static float msg_queue_task_progress_2[16] = COLOR_HEX_TO_FLOAT(0x317198, 1.0f); /* Color of second progress bar in a task message (for multiple tasks with same message) */
|
||||
|
||||
@ -73,11 +71,6 @@ static float msg_queue_task_progress_2[16] = COLOR_HEX_TO_FLOAT(0x317198, 1.0f);
|
||||
static float color_task_progress_bar[16] = COLOR_HEX_TO_FLOAT(0x22B14C, 1.0f);
|
||||
#endif
|
||||
|
||||
static float volume_bar_background[16] = COLOR_HEX_TO_FLOAT(0x1A1A1A, 1.0f);
|
||||
static float volume_bar_normal[16] = COLOR_HEX_TO_FLOAT(0x198AC6, 1.0f);
|
||||
static float volume_bar_loud[16] = COLOR_HEX_TO_FLOAT(0xF5DD19, 1.0f);
|
||||
static float volume_bar_loudest[16] = COLOR_HEX_TO_FLOAT(0xC23B22, 1.0f);
|
||||
|
||||
static uint64_t gfx_widgets_frame_count = 0;
|
||||
|
||||
/* Font data */
|
||||
@ -234,8 +227,6 @@ static unsigned msg_queue_kill = 0;
|
||||
/* Count of messages bound to a task in current_msgs */
|
||||
static unsigned msg_queue_tasks_count = 0;
|
||||
|
||||
/* TODO: Don't display icons if assets are missing */
|
||||
|
||||
static uintptr_t msg_queue_icon = 0;
|
||||
static uintptr_t msg_queue_icon_outline = 0;
|
||||
static uintptr_t msg_queue_icon_rect = 0;
|
||||
@ -255,12 +246,7 @@ static bool widgets_moving = false;
|
||||
/* Icons */
|
||||
enum gfx_widgets_icon
|
||||
{
|
||||
MENU_WIDGETS_ICON_VOLUME_MED = 0,
|
||||
MENU_WIDGETS_ICON_VOLUME_MAX,
|
||||
MENU_WIDGETS_ICON_VOLUME_MIN,
|
||||
MENU_WIDGETS_ICON_VOLUME_MUTE,
|
||||
|
||||
MENU_WIDGETS_ICON_PAUSED,
|
||||
MENU_WIDGETS_ICON_PAUSED = 0,
|
||||
MENU_WIDGETS_ICON_FAST_FORWARD,
|
||||
MENU_WIDGETS_ICON_REWIND,
|
||||
MENU_WIDGETS_ICON_SLOW_MOTION,
|
||||
@ -276,11 +262,6 @@ enum gfx_widgets_icon
|
||||
};
|
||||
|
||||
static const char *gfx_widgets_icons_names[MENU_WIDGETS_ICON_LAST] = {
|
||||
"menu_volume_med.png",
|
||||
"menu_volume_max.png",
|
||||
"menu_volume_min.png",
|
||||
"menu_volume_mute.png",
|
||||
|
||||
"menu_pause.png",
|
||||
"menu_frameskip.png",
|
||||
"menu_rewind.png",
|
||||
@ -297,17 +278,6 @@ static const char *gfx_widgets_icons_names[MENU_WIDGETS_ICON_LAST] = {
|
||||
static uintptr_t gfx_widgets_icons_textures[
|
||||
MENU_WIDGETS_ICON_LAST] = {0};
|
||||
|
||||
/* Volume */
|
||||
static float volume_db = 0.0f;
|
||||
static float volume_percent = 1.0f;
|
||||
static gfx_timer_t volume_timer = 0.0f;
|
||||
|
||||
static float volume_alpha = 0.0f;
|
||||
static float volume_text_alpha = 0.0f;
|
||||
static gfx_animation_ctx_tag volume_tag = (uintptr_t) &volume_alpha;
|
||||
static bool volume_mute = false;
|
||||
|
||||
|
||||
#ifdef HAVE_TRANSLATE
|
||||
/* AI Service Overlay */
|
||||
static int ai_service_overlay_state = 0;
|
||||
@ -383,17 +353,25 @@ static unsigned msg_queue_task_hourglass_x;
|
||||
/* Used for both generic and libretro messages */
|
||||
static unsigned generic_message_height;
|
||||
|
||||
static unsigned volume_widget_width;
|
||||
static unsigned volume_widget_height;
|
||||
|
||||
static unsigned divider_width_1px = 1;
|
||||
|
||||
static unsigned last_video_width = 0;
|
||||
static unsigned last_video_height = 0;
|
||||
|
||||
unsigned gfx_widgets_get_last_video_width(void)
|
||||
{
|
||||
return last_video_width;
|
||||
}
|
||||
|
||||
unsigned gfx_widgets_get_last_video_height(void)
|
||||
{
|
||||
return last_video_height;
|
||||
}
|
||||
|
||||
/* Widgets list */
|
||||
const static gfx_widget_t* const widgets[] = {
|
||||
&gfx_widget_screenshot
|
||||
&gfx_widget_screenshot,
|
||||
&gfx_widget_volume
|
||||
};
|
||||
|
||||
static const size_t widgets_len = sizeof(widgets) / sizeof(widgets[0]);
|
||||
@ -1756,159 +1734,6 @@ void gfx_widgets_frame(void *data)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Volume */
|
||||
if (volume_alpha > 0.0f)
|
||||
{
|
||||
char msg[255];
|
||||
char percentage_msg[255];
|
||||
|
||||
uintptr_t volume_icon = 0;
|
||||
unsigned icon_size = gfx_widgets_icons_textures[MENU_WIDGETS_ICON_VOLUME_MED] ? volume_widget_height : simple_widget_padding;
|
||||
unsigned text_color = COLOR_TEXT_ALPHA(0xffffffff, (unsigned)(volume_text_alpha*255.0f));
|
||||
unsigned text_color_db = COLOR_TEXT_ALPHA(TEXT_COLOR_FAINT, (unsigned)(volume_text_alpha*255.0f));
|
||||
|
||||
unsigned bar_x = icon_size;
|
||||
unsigned bar_height = widget_font_size / 2;
|
||||
unsigned bar_width = volume_widget_width - bar_x - simple_widget_padding;
|
||||
unsigned bar_y = volume_widget_height / 2 + bar_height/2;
|
||||
|
||||
float *bar_background = NULL;
|
||||
float *bar_foreground = NULL;
|
||||
float bar_percentage = 0.0f;
|
||||
|
||||
unsigned volume_text_y = bar_y - (widget_font_size / 3);
|
||||
|
||||
if (volume_mute)
|
||||
volume_icon = gfx_widgets_icons_textures[MENU_WIDGETS_ICON_VOLUME_MUTE];
|
||||
else if (volume_percent <= 1.0f)
|
||||
{
|
||||
if (volume_percent <= 0.5f)
|
||||
volume_icon = gfx_widgets_icons_textures[MENU_WIDGETS_ICON_VOLUME_MIN];
|
||||
else
|
||||
volume_icon = gfx_widgets_icons_textures[MENU_WIDGETS_ICON_VOLUME_MED];
|
||||
|
||||
bar_background = volume_bar_background;
|
||||
bar_foreground = volume_bar_normal;
|
||||
bar_percentage = volume_percent;
|
||||
}
|
||||
else if (volume_percent > 1.0f && volume_percent <= 2.0f)
|
||||
{
|
||||
volume_icon = gfx_widgets_icons_textures[MENU_WIDGETS_ICON_VOLUME_MAX];
|
||||
|
||||
bar_background = volume_bar_normal;
|
||||
bar_foreground = volume_bar_loud;
|
||||
bar_percentage = volume_percent - 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
volume_icon = gfx_widgets_icons_textures[MENU_WIDGETS_ICON_VOLUME_MAX];
|
||||
|
||||
bar_background = volume_bar_loud;
|
||||
bar_foreground = volume_bar_loudest;
|
||||
bar_percentage = volume_percent - 2.0f;
|
||||
}
|
||||
|
||||
if (bar_percentage > 1.0f)
|
||||
bar_percentage = 1.0f;
|
||||
|
||||
/* Backdrop */
|
||||
gfx_display_set_alpha(gfx_widgets_backdrop_orig, volume_alpha);
|
||||
|
||||
gfx_display_draw_quad(userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
0, 0,
|
||||
volume_widget_width,
|
||||
volume_widget_height,
|
||||
video_width,
|
||||
video_height,
|
||||
gfx_widgets_backdrop_orig
|
||||
);
|
||||
|
||||
/* Icon */
|
||||
if (volume_icon)
|
||||
{
|
||||
gfx_display_set_alpha(gfx_widgets_pure_white, volume_text_alpha);
|
||||
|
||||
gfx_display_blend_begin(userdata);
|
||||
gfx_widgets_draw_icon(
|
||||
userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
icon_size, icon_size,
|
||||
volume_icon,
|
||||
0, 0,
|
||||
video_width, video_height,
|
||||
0, 1, gfx_widgets_pure_white
|
||||
);
|
||||
gfx_display_blend_end(userdata);
|
||||
}
|
||||
|
||||
if (volume_mute)
|
||||
{
|
||||
if (!gfx_widgets_icons_textures[MENU_WIDGETS_ICON_VOLUME_MUTE])
|
||||
{
|
||||
const char *text = msg_hash_to_str(MSG_AUDIO_MUTED);
|
||||
gfx_display_draw_text(font_regular,
|
||||
text,
|
||||
volume_widget_width/2, volume_widget_height/2 + widget_font_size / 3,
|
||||
video_width, video_height,
|
||||
text_color, TEXT_ALIGN_CENTER,
|
||||
1, false, 0, true
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bar */
|
||||
gfx_display_set_alpha(bar_background, volume_text_alpha);
|
||||
gfx_display_set_alpha(bar_foreground, volume_text_alpha);
|
||||
|
||||
gfx_display_draw_quad(userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
bar_x + bar_percentage * bar_width, bar_y,
|
||||
bar_width - bar_percentage * bar_width, bar_height,
|
||||
video_width, video_height,
|
||||
bar_background
|
||||
);
|
||||
|
||||
gfx_display_draw_quad(userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
bar_x, bar_y,
|
||||
bar_percentage * bar_width, bar_height,
|
||||
video_width, video_height,
|
||||
bar_foreground
|
||||
);
|
||||
|
||||
/* Text */
|
||||
snprintf(msg, sizeof(msg), (volume_db >= 0 ? "+%.1f dB" : "%.1f dB"),
|
||||
volume_db);
|
||||
|
||||
snprintf(percentage_msg, sizeof(percentage_msg), "%d%%",
|
||||
(int)(volume_percent * 100.0f));
|
||||
|
||||
gfx_display_draw_text(font_regular,
|
||||
msg,
|
||||
volume_widget_width - simple_widget_padding, volume_text_y,
|
||||
video_width, video_height,
|
||||
text_color_db,
|
||||
TEXT_ALIGN_RIGHT,
|
||||
1, false, 0, false
|
||||
);
|
||||
|
||||
gfx_display_draw_text(font_regular,
|
||||
percentage_msg,
|
||||
icon_size, volume_text_y,
|
||||
video_width, video_height,
|
||||
text_color,
|
||||
TEXT_ALIGN_LEFT,
|
||||
1, false, 0, false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw all messages */
|
||||
for (i = 0; i < current_msgs->size; i++)
|
||||
{
|
||||
@ -2197,16 +2022,6 @@ static void gfx_widgets_layout(
|
||||
load_content_animation_icon_size_target = LOAD_CONTENT_ANIMATION_TARGET_ICON_SIZE * last_scale_factor;
|
||||
#endif
|
||||
|
||||
volume_widget_height = widget_font_size * 4;
|
||||
volume_widget_width = volume_widget_height * 4;
|
||||
/* Volume widget cannot exceed screen width
|
||||
* > If it does, scale it down */
|
||||
if (volume_widget_width > last_video_width)
|
||||
{
|
||||
volume_widget_width = last_video_width;
|
||||
volume_widget_height = volume_widget_width / 4;
|
||||
}
|
||||
|
||||
divider_width_1px = 1;
|
||||
if (last_scale_factor > 1.0f)
|
||||
divider_width_1px = (unsigned)(last_scale_factor + 0.5f);
|
||||
@ -2284,7 +2099,7 @@ static void gfx_widgets_context_reset(bool is_threaded,
|
||||
const gfx_widget_t* widget = widgets[i];
|
||||
|
||||
if (widget->context_reset)
|
||||
widget->context_reset(is_threaded, width, height, fullscreen, dir_assets, font_path);
|
||||
widget->context_reset(is_threaded, width, height, fullscreen, dir_assets, font_path, monochrome_png_path, gfx_widgets_path);
|
||||
}
|
||||
|
||||
/* Update scaling/dimensions */
|
||||
@ -2382,8 +2197,7 @@ static void gfx_widgets_free(void)
|
||||
widget->free();
|
||||
}
|
||||
|
||||
/* Kill any pending animation */
|
||||
gfx_animation_kill_by_tag(&volume_tag);
|
||||
/* Kill all running animations */
|
||||
gfx_animation_kill_by_tag(&gfx_widgets_generic_tag);
|
||||
|
||||
/* Purge everything from the fifo */
|
||||
@ -2450,50 +2264,6 @@ static void gfx_widgets_free(void)
|
||||
|
||||
/* AI Service overlay */
|
||||
/* ... */
|
||||
|
||||
/* Volume */
|
||||
volume_alpha = 0.0f;
|
||||
}
|
||||
|
||||
static void gfx_widgets_volume_timer_end(void *userdata)
|
||||
{
|
||||
gfx_animation_ctx_entry_t entry;
|
||||
|
||||
entry.cb = NULL;
|
||||
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
|
||||
entry.easing_enum = EASING_OUT_QUAD;
|
||||
entry.subject = &volume_alpha;
|
||||
entry.tag = volume_tag;
|
||||
entry.target_value = 0.0f;
|
||||
entry.userdata = NULL;
|
||||
|
||||
gfx_animation_push(&entry);
|
||||
|
||||
entry.subject = &volume_text_alpha;
|
||||
|
||||
gfx_animation_push(&entry);
|
||||
}
|
||||
|
||||
void gfx_widgets_volume_update_and_show(float new_volume, bool mute)
|
||||
{
|
||||
gfx_timer_ctx_entry_t entry;
|
||||
|
||||
if (!widgets_active)
|
||||
return;
|
||||
|
||||
gfx_animation_kill_by_tag(&volume_tag);
|
||||
|
||||
volume_db = new_volume;
|
||||
volume_percent = pow(10, new_volume/20);
|
||||
volume_alpha = DEFAULT_BACKDROP;
|
||||
volume_text_alpha = 1.0f;
|
||||
volume_mute = mute;
|
||||
|
||||
entry.cb = gfx_widgets_volume_timer_end;
|
||||
entry.duration = VOLUME_DURATION;
|
||||
entry.userdata = NULL;
|
||||
|
||||
gfx_timer_start(&volume_timer, &entry);
|
||||
}
|
||||
|
||||
bool gfx_widgets_set_fps_text(const char *new_fps_text)
|
||||
|
@ -32,13 +32,14 @@
|
||||
#define MSG_QUEUE_ONSCREEN_MAX 4
|
||||
|
||||
#define MSG_QUEUE_ANIMATION_DURATION 330
|
||||
#define VOLUME_DURATION 3000
|
||||
#define CHEEVO_NOTIFICATION_DURATION 4000
|
||||
#define TASK_FINISHED_DURATION 3000
|
||||
#define HOURGLASS_INTERVAL 5000
|
||||
#define HOURGLASS_DURATION 1000
|
||||
#define GENERIC_MESSAGE_DURATION 3000
|
||||
|
||||
/* TODO: Colors for warning, error and success */
|
||||
|
||||
#define TEXT_COLOR_INFO 0xD8EEFFFF
|
||||
#if 0
|
||||
#define TEXT_COLOR_SUCCESS 0x22B14CFF
|
||||
@ -62,7 +63,9 @@ struct gfx_widget
|
||||
* -> (re)load the textures here */
|
||||
void (*context_reset)(bool is_threaded,
|
||||
unsigned width, unsigned height, bool fullscreen,
|
||||
const char *dir_assets, char *font_path);
|
||||
const char *dir_assets, char *font_path,
|
||||
char* menu_png_path,
|
||||
char* widgets_png_path);
|
||||
|
||||
/* called when the graphics context is destroyed
|
||||
* -> release the textures here */
|
||||
@ -94,6 +97,8 @@ float gfx_widgets_get_font_size(void);
|
||||
font_data_t* gfx_widgets_get_font_regular(void);
|
||||
font_data_t* gfx_widgets_get_font_bold(void);
|
||||
float* gfx_widgets_get_backdrop_orig(void);
|
||||
unsigned gfx_widgets_get_last_video_width(void);
|
||||
unsigned gfx_widgets_get_last_video_height(void);
|
||||
|
||||
float gfx_widgets_get_thumbnail_scale_factor(
|
||||
const float dst_width, const float dst_height,
|
||||
@ -114,6 +119,7 @@ void gfx_widgets_draw_icon(
|
||||
typedef struct gfx_widget gfx_widget_t;
|
||||
|
||||
extern const gfx_widget_t gfx_widget_screenshot;
|
||||
extern const gfx_widget_t gfx_widget_volume;
|
||||
|
||||
bool gfx_widgets_active(void);
|
||||
void gfx_widgets_set_persistence(bool persist);
|
||||
@ -133,7 +139,7 @@ void gfx_widgets_msg_queue_push(
|
||||
unsigned prio, bool flush,
|
||||
bool menu_is_alive);
|
||||
|
||||
void gfx_widgets_volume_update_and_show(float new_volume,
|
||||
void gfx_widget_volume_update_and_show(float new_volume,
|
||||
bool mute);
|
||||
|
||||
void gfx_widgets_iterate(
|
||||
@ -141,7 +147,7 @@ void gfx_widgets_iterate(
|
||||
const char *dir_assets, char *font_path,
|
||||
bool is_threaded);
|
||||
|
||||
void gfx_widgets_screenshot_taken(const char *shotname, const char *filename);
|
||||
void gfx_widget_screenshot_taken(const char *shotname, const char *filename);
|
||||
|
||||
/* AI Service functions */
|
||||
#ifdef HAVE_TRANSLATE
|
||||
|
@ -72,7 +72,7 @@ static gfx_widget_screenshot_state_t* gfx_widget_screenshot_get_ptr(void)
|
||||
return &p_state;
|
||||
}
|
||||
|
||||
static void gfx_widgets_screenshot_fadeout(void *userdata)
|
||||
static void gfx_widget_screenshot_fadeout(void *userdata)
|
||||
{
|
||||
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
|
||||
gfx_animation_ctx_entry_t entry;
|
||||
@ -93,7 +93,7 @@ static void gfx_widgets_play_screenshot_flash(void)
|
||||
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
|
||||
gfx_animation_ctx_entry_t entry;
|
||||
|
||||
entry.cb = gfx_widgets_screenshot_fadeout;
|
||||
entry.cb = gfx_widget_screenshot_fadeout;
|
||||
entry.duration = SCREENSHOT_DURATION_IN;
|
||||
entry.easing_enum = EASING_IN_QUAD;
|
||||
entry.subject = &state->alpha;
|
||||
@ -104,7 +104,7 @@ static void gfx_widgets_play_screenshot_flash(void)
|
||||
gfx_animation_push(&entry);
|
||||
}
|
||||
|
||||
void gfx_widgets_screenshot_taken(const char *shotname, const char *filename)
|
||||
void gfx_widget_screenshot_taken(const char *shotname, const char *filename)
|
||||
{
|
||||
gfx_widget_screenshot_state_t* state = NULL;
|
||||
|
||||
@ -117,7 +117,7 @@ void gfx_widgets_screenshot_taken(const char *shotname, const char *filename)
|
||||
strlcpy(state->shotname, shotname, sizeof(state->shotname));
|
||||
}
|
||||
|
||||
static void gfx_widgets_screenshot_dispose(void *userdata)
|
||||
static void gfx_widget_screenshot_dispose(void *userdata)
|
||||
{
|
||||
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
|
||||
state->loaded = false;
|
||||
@ -125,12 +125,12 @@ static void gfx_widgets_screenshot_dispose(void *userdata)
|
||||
state->texture = 0;
|
||||
}
|
||||
|
||||
static void gfx_widgets_screenshot_end(void *userdata)
|
||||
static void gfx_widget_screenshot_end(void *userdata)
|
||||
{
|
||||
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
|
||||
gfx_animation_ctx_entry_t entry;
|
||||
|
||||
entry.cb = gfx_widgets_screenshot_dispose;
|
||||
entry.cb = gfx_widget_screenshot_dispose;
|
||||
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
|
||||
entry.easing_enum = EASING_OUT_QUAD;
|
||||
entry.subject = &state->y;
|
||||
@ -145,7 +145,7 @@ static void gfx_widget_screenshot_free(void)
|
||||
{
|
||||
gfx_widget_screenshot_state_t* state = gfx_widget_screenshot_get_ptr();
|
||||
state->alpha = 0.0f;
|
||||
gfx_widgets_screenshot_dispose(NULL);
|
||||
gfx_widget_screenshot_dispose(NULL);
|
||||
}
|
||||
|
||||
static void gfx_widget_screenshot_frame(void* data)
|
||||
@ -273,7 +273,7 @@ static void gfx_widget_screenshot_iterate(unsigned width, unsigned height, bool
|
||||
|
||||
state->y = 0.0f;
|
||||
|
||||
timer.cb = gfx_widgets_screenshot_end;
|
||||
timer.cb = gfx_widget_screenshot_end;
|
||||
timer.duration = SCREENSHOT_NOTIFICATION_DURATION;
|
||||
timer.userdata = NULL;
|
||||
|
||||
|
364
gfx/widgets/gfx_widget_volume.c
Normal file
364
gfx/widgets/gfx_widget_volume.c
Normal file
@ -0,0 +1,364 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2014-2017 - Jean-André Santoni
|
||||
* Copyright (C) 2015-2018 - Andre Leiradella
|
||||
* Copyright (C) 2018-2020 - natinusala
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../gfx_widgets.h"
|
||||
#include "../gfx_animation.h"
|
||||
#include "../gfx_display.h"
|
||||
#include "../../retroarch.h"
|
||||
|
||||
/* Constants */
|
||||
#define VOLUME_DURATION 3000
|
||||
|
||||
enum gfx_widget_volume_icon
|
||||
{
|
||||
ICON_MED = 0,
|
||||
ICON_MAX,
|
||||
ICON_MIN,
|
||||
ICON_MUTE,
|
||||
|
||||
ICON_LAST,
|
||||
};
|
||||
|
||||
static const char* const ICONS_NAMES[ICON_LAST] = {
|
||||
"menu_volume_med.png",
|
||||
"menu_volume_max.png",
|
||||
"menu_volume_min.png",
|
||||
"menu_volume_mute.png",
|
||||
};
|
||||
|
||||
/* Widget state */
|
||||
struct gfx_widget_volume_state
|
||||
{
|
||||
float db;
|
||||
float percent;
|
||||
gfx_timer_t timer;
|
||||
|
||||
float alpha;
|
||||
float text_alpha;
|
||||
gfx_animation_ctx_tag tag;
|
||||
bool mute;
|
||||
|
||||
unsigned widget_width;
|
||||
unsigned widget_height;
|
||||
|
||||
float bar_background[16];
|
||||
float bar_normal[16];
|
||||
float bar_loud[16];
|
||||
float bar_loudest[16];
|
||||
|
||||
uintptr_t textures[ICON_LAST];
|
||||
};
|
||||
|
||||
typedef struct gfx_widget_volume_state gfx_widget_volume_state_t;
|
||||
|
||||
static gfx_widget_volume_state_t p_state = {
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.0f,
|
||||
|
||||
0.0f,
|
||||
0.0f,
|
||||
(uintptr_t) &p_state,
|
||||
false,
|
||||
|
||||
0,
|
||||
0,
|
||||
|
||||
COLOR_HEX_TO_FLOAT(0x1A1A1A, 1.0f),
|
||||
COLOR_HEX_TO_FLOAT(0x198AC6, 1.0f),
|
||||
COLOR_HEX_TO_FLOAT(0xF5DD19, 1.0f),
|
||||
COLOR_HEX_TO_FLOAT(0xC23B22, 1.0f),
|
||||
|
||||
{0},
|
||||
};
|
||||
|
||||
gfx_widget_volume_state_t* gfx_widget_volume_get_ptr(void)
|
||||
{
|
||||
return &p_state;
|
||||
}
|
||||
|
||||
static void gfx_widget_volume_frame(void* data)
|
||||
{
|
||||
gfx_widget_volume_state_t* state = gfx_widget_volume_get_ptr();
|
||||
|
||||
if (state->alpha > 0.0f)
|
||||
{
|
||||
video_frame_info_t *video_info = (video_frame_info_t*)data;
|
||||
|
||||
char msg[255];
|
||||
char percentage_msg[255];
|
||||
|
||||
void *userdata = video_info->userdata;
|
||||
unsigned video_width = video_info->width;
|
||||
unsigned video_height = video_info->height;
|
||||
|
||||
font_data_t* font_regular = gfx_widgets_get_font_regular();
|
||||
|
||||
float font_size = gfx_widgets_get_font_size();
|
||||
unsigned padding = gfx_widgets_get_padding();
|
||||
|
||||
float* backdrop_orig = gfx_widgets_get_backdrop_orig();
|
||||
float* pure_white = gfx_widgets_get_pure_white();
|
||||
|
||||
uintptr_t volume_icon = 0;
|
||||
unsigned icon_size = state->textures[ICON_MED] ? state->widget_height : padding;
|
||||
unsigned text_color = COLOR_TEXT_ALPHA(0xffffffff, (unsigned)(state->text_alpha*255.0f));
|
||||
unsigned text_color_db = COLOR_TEXT_ALPHA(TEXT_COLOR_FAINT, (unsigned)(state->text_alpha*255.0f));
|
||||
|
||||
unsigned bar_x = icon_size;
|
||||
unsigned bar_height = font_size / 2;
|
||||
unsigned bar_width = state->widget_width - bar_x - padding;
|
||||
unsigned bar_y = state->widget_height / 2 + bar_height/2;
|
||||
|
||||
float *bar_background = NULL;
|
||||
float *bar_foreground = NULL;
|
||||
float bar_percentage = 0.0f;
|
||||
|
||||
unsigned volume_text_y = bar_y - (font_size / 3);
|
||||
|
||||
if (state->mute)
|
||||
volume_icon = state->textures[ICON_MUTE];
|
||||
else if (state->percent <= 1.0f)
|
||||
{
|
||||
if (state->percent <= 0.5f)
|
||||
volume_icon = state->textures[ICON_MIN];
|
||||
else
|
||||
volume_icon = state->textures[ICON_MED];
|
||||
|
||||
bar_background = state->bar_background;
|
||||
bar_foreground = state->bar_normal;
|
||||
bar_percentage = state->percent;
|
||||
}
|
||||
else if (state->percent > 1.0f && state->percent <= 2.0f)
|
||||
{
|
||||
volume_icon = state->textures[ICON_MAX];
|
||||
|
||||
bar_background = state->bar_normal;
|
||||
bar_foreground = state->bar_loud;
|
||||
bar_percentage = state->percent - 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
volume_icon = state->textures[ICON_MAX];
|
||||
|
||||
bar_background = state->bar_loud;
|
||||
bar_foreground = state->bar_loudest;
|
||||
bar_percentage = state->percent - 2.0f;
|
||||
}
|
||||
|
||||
if (bar_percentage > 1.0f)
|
||||
bar_percentage = 1.0f;
|
||||
|
||||
/* Backdrop */
|
||||
gfx_display_set_alpha(backdrop_orig, state->alpha);
|
||||
|
||||
gfx_display_draw_quad(userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
0, 0,
|
||||
state->widget_width,
|
||||
state->widget_height,
|
||||
video_width,
|
||||
video_height,
|
||||
backdrop_orig
|
||||
);
|
||||
|
||||
/* Icon */
|
||||
if (volume_icon)
|
||||
{
|
||||
gfx_display_set_alpha(pure_white, state->text_alpha);
|
||||
|
||||
gfx_display_blend_begin(userdata);
|
||||
gfx_widgets_draw_icon(
|
||||
userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
icon_size, icon_size,
|
||||
volume_icon,
|
||||
0, 0,
|
||||
video_width, video_height,
|
||||
0, 1, pure_white
|
||||
);
|
||||
gfx_display_blend_end(userdata);
|
||||
}
|
||||
|
||||
if (state->mute)
|
||||
{
|
||||
if (!state->textures[ICON_MUTE])
|
||||
{
|
||||
const char *text = msg_hash_to_str(MSG_AUDIO_MUTED);
|
||||
gfx_display_draw_text(font_regular,
|
||||
text,
|
||||
state->widget_width/2, state->widget_height/2 + font_size / 3,
|
||||
video_width, video_height,
|
||||
text_color, TEXT_ALIGN_CENTER,
|
||||
1, false, 0, true
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Bar */
|
||||
gfx_display_set_alpha(bar_background, state->text_alpha);
|
||||
gfx_display_set_alpha(bar_foreground, state->text_alpha);
|
||||
|
||||
gfx_display_draw_quad(userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
bar_x + bar_percentage * bar_width, bar_y,
|
||||
bar_width - bar_percentage * bar_width, bar_height,
|
||||
video_width, video_height,
|
||||
bar_background
|
||||
);
|
||||
|
||||
gfx_display_draw_quad(userdata,
|
||||
video_width,
|
||||
video_height,
|
||||
bar_x, bar_y,
|
||||
bar_percentage * bar_width, bar_height,
|
||||
video_width, video_height,
|
||||
bar_foreground
|
||||
);
|
||||
|
||||
/* Text */
|
||||
snprintf(msg, sizeof(msg), (state->db >= 0 ? "+%.1f dB" : "%.1f dB"),
|
||||
state->db);
|
||||
|
||||
snprintf(percentage_msg, sizeof(percentage_msg), "%d%%",
|
||||
(int)(state->percent * 100.0f));
|
||||
|
||||
gfx_display_draw_text(font_regular,
|
||||
msg,
|
||||
state->widget_width - padding, volume_text_y,
|
||||
video_width, video_height,
|
||||
text_color_db,
|
||||
TEXT_ALIGN_RIGHT,
|
||||
1, false, 0, false
|
||||
);
|
||||
|
||||
gfx_display_draw_text(font_regular,
|
||||
percentage_msg,
|
||||
icon_size, volume_text_y,
|
||||
video_width, video_height,
|
||||
text_color,
|
||||
TEXT_ALIGN_LEFT,
|
||||
1, false, 0, false
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void gfx_widget_volume_timer_end(void *userdata)
|
||||
{
|
||||
gfx_widget_volume_state_t* state = gfx_widget_volume_get_ptr();
|
||||
gfx_animation_ctx_entry_t entry;
|
||||
|
||||
entry.cb = NULL;
|
||||
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
|
||||
entry.easing_enum = EASING_OUT_QUAD;
|
||||
entry.subject = &state->alpha;
|
||||
entry.tag = state->tag;
|
||||
entry.target_value = 0.0f;
|
||||
entry.userdata = NULL;
|
||||
|
||||
gfx_animation_push(&entry);
|
||||
|
||||
entry.subject = &state->text_alpha;
|
||||
|
||||
gfx_animation_push(&entry);
|
||||
}
|
||||
|
||||
void gfx_widget_volume_update_and_show(float new_volume, bool mute)
|
||||
{
|
||||
gfx_widget_volume_state_t* state = gfx_widget_volume_get_ptr();
|
||||
gfx_timer_ctx_entry_t entry;
|
||||
|
||||
gfx_animation_kill_by_tag(&state->tag);
|
||||
|
||||
state->db = new_volume;
|
||||
state->percent = pow(10, new_volume/20);
|
||||
state->alpha = DEFAULT_BACKDROP;
|
||||
state->text_alpha = 1.0f;
|
||||
state->mute = mute;
|
||||
|
||||
entry.cb = gfx_widget_volume_timer_end;
|
||||
entry.duration = VOLUME_DURATION;
|
||||
entry.userdata = NULL;
|
||||
|
||||
gfx_timer_start(&state->timer, &entry);
|
||||
}
|
||||
|
||||
static void gfx_widget_volume_layout(bool is_threaded, const char *dir_assets, char *font_path)
|
||||
{
|
||||
gfx_widget_volume_state_t* state = gfx_widget_volume_get_ptr();
|
||||
|
||||
float font_size = gfx_widgets_get_font_size();
|
||||
unsigned last_video_width = gfx_widgets_get_last_video_width();
|
||||
|
||||
state->widget_height = font_size * 4;
|
||||
state->widget_width = state->widget_height * 4;
|
||||
|
||||
/* Volume widget cannot exceed screen width
|
||||
* > If it does, scale it down */
|
||||
if (state->widget_width > last_video_width)
|
||||
{
|
||||
state->widget_width = last_video_width;
|
||||
state->widget_height = state->widget_width / 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void gfx_widget_volume_context_reset(bool is_threaded,
|
||||
unsigned width, unsigned height, bool fullscreen,
|
||||
const char *dir_assets, char *font_path,
|
||||
char* menu_png_path,
|
||||
char* widgets_png_path)
|
||||
{
|
||||
gfx_widget_volume_state_t* state = gfx_widget_volume_get_ptr();
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ICON_LAST; i++)
|
||||
gfx_display_reset_textures_list(ICONS_NAMES[i], menu_png_path, &state->textures[i], TEXTURE_FILTER_MIPMAP_LINEAR, NULL, NULL);
|
||||
}
|
||||
|
||||
static void gfx_widget_volume_context_destroy(void)
|
||||
{
|
||||
gfx_widget_volume_state_t* state = gfx_widget_volume_get_ptr();
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ICON_LAST; i++)
|
||||
video_driver_texture_unload(&state->textures[i]);
|
||||
}
|
||||
|
||||
static void gfx_widget_volume_free(void)
|
||||
{
|
||||
gfx_widget_volume_state_t* state = gfx_widget_volume_get_ptr();
|
||||
|
||||
/* Kill all running animations */
|
||||
gfx_animation_kill_by_tag(&state->tag);
|
||||
|
||||
state->alpha = 0.0f;
|
||||
}
|
||||
|
||||
const gfx_widget_t gfx_widget_volume = {
|
||||
NULL, /* init */
|
||||
gfx_widget_volume_free,
|
||||
gfx_widget_volume_context_reset,
|
||||
gfx_widget_volume_context_destroy,
|
||||
gfx_widget_volume_layout,
|
||||
NULL, /* iterate */
|
||||
gfx_widget_volume_frame
|
||||
};
|
@ -1262,6 +1262,7 @@ MENU
|
||||
#ifdef HAVE_GFX_WIDGETS
|
||||
#include "../gfx/gfx_widgets.c"
|
||||
#include "../gfx/widgets/gfx_widget_screenshot.c"
|
||||
#include "../gfx/widgets/gfx_widget_volume.c"
|
||||
#endif
|
||||
|
||||
#include "../input/input_osk.c"
|
||||
|
@ -6994,7 +6994,7 @@ static void command_event_set_volume(float gain)
|
||||
|
||||
#if defined(HAVE_GFX_WIDGETS)
|
||||
if (gfx_widgets_active())
|
||||
gfx_widgets_volume_update_and_show(new_volume, audio_driver_mute_enable);
|
||||
gfx_widget_volume_update_and_show(new_volume, audio_driver_mute_enable);
|
||||
else
|
||||
#endif
|
||||
runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
||||
@ -8527,7 +8527,7 @@ bool command_event(enum event_command cmd, void *data)
|
||||
|
||||
#if defined(HAVE_GFX_WIDGETS)
|
||||
if (gfx_widgets_active())
|
||||
gfx_widgets_volume_update_and_show(
|
||||
gfx_widget_volume_update_and_show(
|
||||
configuration_settings->floats.audio_volume,
|
||||
audio_driver_mute_enable);
|
||||
else
|
||||
|
@ -213,7 +213,7 @@ static void task_screenshot_callback(retro_task_t *task,
|
||||
return;
|
||||
|
||||
if (state && !state->silence && state->widgets_ready)
|
||||
gfx_widgets_screenshot_taken(state->shotname, state->filename);
|
||||
gfx_widget_screenshot_taken(state->shotname, state->filename);
|
||||
|
||||
free(state);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user