mirror of
https://github.com/libretro/RetroArch
synced 2025-03-06 13:13:57 +00:00
Merge pull request #10275 from natinusala/split-widgets
gfx_widgets: move generic message to its own file
This commit is contained in:
commit
e138bfbfaf
@ -842,7 +842,8 @@ endif
|
|||||||
ifeq ($(HAVE_GFX_WIDGETS), 1)
|
ifeq ($(HAVE_GFX_WIDGETS), 1)
|
||||||
OBJ += gfx/gfx_widgets.o \
|
OBJ += gfx/gfx_widgets.o \
|
||||||
gfx/widgets/gfx_widget_screenshot.o \
|
gfx/widgets/gfx_widget_screenshot.o \
|
||||||
gfx/widgets/gfx_widget_volume.o
|
gfx/widgets/gfx_widget_volume.o \
|
||||||
|
gfx/widgets/gfx_widget_generic_message.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(HAVE_OVERLAY), 1)
|
ifeq ($(HAVE_OVERLAY), 1)
|
||||||
|
@ -286,11 +286,6 @@ static unsigned ai_service_overlay_height = 0;
|
|||||||
static uintptr_t ai_service_overlay_texture = 0;
|
static uintptr_t ai_service_overlay_texture = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Generic message */
|
|
||||||
static gfx_timer_t generic_message_timer;
|
|
||||||
static float generic_message_alpha = 0.0f;
|
|
||||||
static char generic_message[256] = {'\0'};
|
|
||||||
|
|
||||||
/* Libretro message */
|
/* Libretro message */
|
||||||
|
|
||||||
static gfx_timer_t libretro_message_timer;
|
static gfx_timer_t libretro_message_timer;
|
||||||
@ -351,7 +346,12 @@ static unsigned msg_queue_task_rect_start_x;
|
|||||||
static unsigned msg_queue_task_hourglass_x;
|
static unsigned msg_queue_task_hourglass_x;
|
||||||
|
|
||||||
/* Used for both generic and libretro messages */
|
/* Used for both generic and libretro messages */
|
||||||
static unsigned generic_message_height;
|
static unsigned generic_message_height;
|
||||||
|
|
||||||
|
unsigned gfx_widgets_get_generic_message_height(void)
|
||||||
|
{
|
||||||
|
return generic_message_height;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned divider_width_1px = 1;
|
static unsigned divider_width_1px = 1;
|
||||||
|
|
||||||
@ -371,7 +371,8 @@ unsigned gfx_widgets_get_last_video_height(void)
|
|||||||
/* Widgets list */
|
/* Widgets list */
|
||||||
const static gfx_widget_t* const widgets[] = {
|
const static gfx_widget_t* const widgets[] = {
|
||||||
&gfx_widget_screenshot,
|
&gfx_widget_screenshot,
|
||||||
&gfx_widget_volume
|
&gfx_widget_volume,
|
||||||
|
&gfx_widget_generic_message
|
||||||
};
|
};
|
||||||
|
|
||||||
static const size_t widgets_len = sizeof(widgets) / sizeof(widgets[0]);
|
static const size_t widgets_len = sizeof(widgets) / sizeof(widgets[0]);
|
||||||
@ -1606,27 +1607,6 @@ void gfx_widgets_frame(void *data)
|
|||||||
1, false, 0, false);
|
1, false, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generic message */
|
|
||||||
if (generic_message_alpha > 0.0f)
|
|
||||||
{
|
|
||||||
unsigned text_color = COLOR_TEXT_ALPHA(0xffffffff, (unsigned)(generic_message_alpha*255.0f));
|
|
||||||
gfx_display_set_alpha(gfx_widgets_backdrop_orig, generic_message_alpha);
|
|
||||||
|
|
||||||
gfx_display_draw_quad(userdata,
|
|
||||||
video_width, video_height,
|
|
||||||
0, video_height - generic_message_height,
|
|
||||||
video_width, generic_message_height,
|
|
||||||
video_width, video_height,
|
|
||||||
gfx_widgets_backdrop_orig);
|
|
||||||
|
|
||||||
gfx_display_draw_text(font_regular, generic_message,
|
|
||||||
video_width/2,
|
|
||||||
video_height - generic_message_height/2 + widget_font_size/4,
|
|
||||||
video_width, video_height,
|
|
||||||
text_color, TEXT_ALIGN_CENTER,
|
|
||||||
1, false, 0, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
/* Achievement notification */
|
/* Achievement notification */
|
||||||
if (cheevo_popup_queue_read_index >= 0 && cheevo_popup_queue[cheevo_popup_queue_read_index].title)
|
if (cheevo_popup_queue_read_index >= 0 && cheevo_popup_queue[cheevo_popup_queue_read_index].title)
|
||||||
@ -2253,9 +2233,6 @@ static void gfx_widgets_free(void)
|
|||||||
font_driver_bind_block(NULL, NULL);
|
font_driver_bind_block(NULL, NULL);
|
||||||
|
|
||||||
/* Reset state of all other widgets */
|
/* Reset state of all other widgets */
|
||||||
/* Generic message*/
|
|
||||||
generic_message_alpha = 0.0f;
|
|
||||||
|
|
||||||
/* Libretro message */
|
/* Libretro message */
|
||||||
libretro_tag = (uintptr_t) &libretro_message_timer;
|
libretro_tag = (uintptr_t) &libretro_message_timer;
|
||||||
libretro_message_alpha = 0.0f;
|
libretro_message_alpha = 0.0f;
|
||||||
@ -2569,46 +2546,6 @@ void gfx_widgets_push_achievement(const char *title, const char *badge)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void gfx_widgets_generic_message_fadeout(void *userdata)
|
|
||||||
{
|
|
||||||
gfx_animation_ctx_entry_t entry;
|
|
||||||
gfx_animation_ctx_tag tag = (uintptr_t) &generic_message_timer;
|
|
||||||
|
|
||||||
/* Start fade out animation */
|
|
||||||
entry.cb = NULL;
|
|
||||||
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
|
|
||||||
entry.easing_enum = EASING_OUT_QUAD;
|
|
||||||
entry.subject = &generic_message_alpha;
|
|
||||||
entry.tag = tag;
|
|
||||||
entry.target_value = 0.0f;
|
|
||||||
entry.userdata = NULL;
|
|
||||||
|
|
||||||
gfx_animation_push(&entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
void gfx_widgets_set_message(char *msg)
|
|
||||||
{
|
|
||||||
gfx_timer_ctx_entry_t timer;
|
|
||||||
gfx_animation_ctx_tag tag = (uintptr_t) &generic_message_timer;
|
|
||||||
|
|
||||||
if (!widgets_active)
|
|
||||||
return;
|
|
||||||
|
|
||||||
strlcpy(generic_message, msg, sizeof(generic_message));
|
|
||||||
|
|
||||||
generic_message_alpha = DEFAULT_BACKDROP;
|
|
||||||
|
|
||||||
/* Kill and restart the timer / animation */
|
|
||||||
gfx_timer_kill(&generic_message_timer);
|
|
||||||
gfx_animation_kill_by_tag(&tag);
|
|
||||||
|
|
||||||
timer.cb = gfx_widgets_generic_message_fadeout;
|
|
||||||
timer.duration = GENERIC_MESSAGE_DURATION;
|
|
||||||
timer.userdata = NULL;
|
|
||||||
|
|
||||||
gfx_timer_start(&generic_message_timer, &timer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gfx_widgets_libretro_message_fadeout(void *userdata)
|
static void gfx_widgets_libretro_message_fadeout(void *userdata)
|
||||||
{
|
{
|
||||||
gfx_animation_ctx_entry_t entry;
|
gfx_animation_ctx_entry_t entry;
|
||||||
|
@ -99,6 +99,7 @@ font_data_t* gfx_widgets_get_font_bold(void);
|
|||||||
float* gfx_widgets_get_backdrop_orig(void);
|
float* gfx_widgets_get_backdrop_orig(void);
|
||||||
unsigned gfx_widgets_get_last_video_width(void);
|
unsigned gfx_widgets_get_last_video_width(void);
|
||||||
unsigned gfx_widgets_get_last_video_height(void);
|
unsigned gfx_widgets_get_last_video_height(void);
|
||||||
|
unsigned gfx_widgets_get_generic_message_height(void);
|
||||||
|
|
||||||
float gfx_widgets_get_thumbnail_scale_factor(
|
float gfx_widgets_get_thumbnail_scale_factor(
|
||||||
const float dst_width, const float dst_height,
|
const float dst_width, const float dst_height,
|
||||||
@ -120,6 +121,7 @@ typedef struct gfx_widget gfx_widget_t;
|
|||||||
|
|
||||||
extern const gfx_widget_t gfx_widget_screenshot;
|
extern const gfx_widget_t gfx_widget_screenshot;
|
||||||
extern const gfx_widget_t gfx_widget_volume;
|
extern const gfx_widget_t gfx_widget_volume;
|
||||||
|
extern const gfx_widget_t gfx_widget_generic_message;
|
||||||
|
|
||||||
bool gfx_widgets_active(void);
|
bool gfx_widgets_active(void);
|
||||||
void gfx_widgets_set_persistence(bool persist);
|
void gfx_widgets_set_persistence(bool persist);
|
||||||
@ -169,7 +171,7 @@ void gfx_widgets_cleanup_load_content_animation(void);
|
|||||||
void gfx_widgets_push_achievement(const char *title, const char *badge);
|
void gfx_widgets_push_achievement(const char *title, const char *badge);
|
||||||
|
|
||||||
/* Warning: not thread safe! */
|
/* Warning: not thread safe! */
|
||||||
void gfx_widgets_set_message(char *message);
|
void gfx_widget_set_message(char *message);
|
||||||
|
|
||||||
/* Warning: not thread safe! */
|
/* Warning: not thread safe! */
|
||||||
void gfx_widgets_set_libretro_message(const char *message, unsigned duration);
|
void gfx_widgets_set_libretro_message(const char *message, unsigned duration);
|
||||||
|
131
gfx/widgets/gfx_widget_generic_message.c
Normal file
131
gfx/widgets/gfx_widget_generic_message.c
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
/* 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"
|
||||||
|
|
||||||
|
struct gfx_widget_generic_message_state
|
||||||
|
{
|
||||||
|
gfx_timer_t timer;
|
||||||
|
float alpha;
|
||||||
|
char message[256];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct gfx_widget_generic_message_state gfx_widget_generic_message_state_t;
|
||||||
|
|
||||||
|
static gfx_widget_generic_message_state_t p_w_generic_message_st = {
|
||||||
|
0.0f,
|
||||||
|
0.0f,
|
||||||
|
{'\0'}
|
||||||
|
};
|
||||||
|
|
||||||
|
static gfx_widget_generic_message_state_t* gfx_widget_generic_message_get_ptr()
|
||||||
|
{
|
||||||
|
return &p_w_generic_message_st;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gfx_widget_generic_message_fadeout(void *userdata)
|
||||||
|
{
|
||||||
|
gfx_widget_generic_message_state_t* state = gfx_widget_generic_message_get_ptr();
|
||||||
|
gfx_animation_ctx_entry_t entry;
|
||||||
|
gfx_animation_ctx_tag tag = (uintptr_t) &state->timer;
|
||||||
|
|
||||||
|
/* Start fade out animation */
|
||||||
|
entry.cb = NULL;
|
||||||
|
entry.duration = MSG_QUEUE_ANIMATION_DURATION;
|
||||||
|
entry.easing_enum = EASING_OUT_QUAD;
|
||||||
|
entry.subject = &state->alpha;
|
||||||
|
entry.tag = tag;
|
||||||
|
entry.target_value = 0.0f;
|
||||||
|
entry.userdata = NULL;
|
||||||
|
|
||||||
|
gfx_animation_push(&entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gfx_widget_set_message(char *msg)
|
||||||
|
{
|
||||||
|
gfx_widget_generic_message_state_t* state = gfx_widget_generic_message_get_ptr();
|
||||||
|
gfx_timer_ctx_entry_t timer;
|
||||||
|
gfx_animation_ctx_tag tag = (uintptr_t) &state->timer;
|
||||||
|
|
||||||
|
if (!gfx_widgets_active())
|
||||||
|
return;
|
||||||
|
|
||||||
|
strlcpy(state->message, msg, sizeof(state->message));
|
||||||
|
|
||||||
|
state->alpha = DEFAULT_BACKDROP;
|
||||||
|
|
||||||
|
/* Kill and restart the timer / animation */
|
||||||
|
gfx_timer_kill(&state->timer);
|
||||||
|
gfx_animation_kill_by_tag(&tag);
|
||||||
|
|
||||||
|
timer.cb = gfx_widget_generic_message_fadeout;
|
||||||
|
timer.duration = GENERIC_MESSAGE_DURATION;
|
||||||
|
timer.userdata = NULL;
|
||||||
|
|
||||||
|
gfx_timer_start(&state->timer, &timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gfx_widget_generic_message_frame(void* data)
|
||||||
|
{
|
||||||
|
gfx_widget_generic_message_state_t* state = gfx_widget_generic_message_get_ptr();
|
||||||
|
|
||||||
|
if (state->alpha > 0.0f)
|
||||||
|
{
|
||||||
|
video_frame_info_t* video_info = (video_frame_info_t*)data;
|
||||||
|
void* userdata = video_info->userdata;
|
||||||
|
unsigned video_width = video_info->width;
|
||||||
|
unsigned video_height = video_info->height;
|
||||||
|
|
||||||
|
unsigned height = gfx_widgets_get_generic_message_height();
|
||||||
|
|
||||||
|
unsigned text_color = COLOR_TEXT_ALPHA(0xffffffff, (unsigned)(state->alpha*255.0f));
|
||||||
|
gfx_display_set_alpha(gfx_widgets_get_backdrop_orig(), state->alpha);
|
||||||
|
|
||||||
|
gfx_display_draw_quad(userdata,
|
||||||
|
video_width, video_height,
|
||||||
|
0, video_height - height,
|
||||||
|
video_width, height,
|
||||||
|
video_width, video_height,
|
||||||
|
gfx_widgets_get_backdrop_orig());
|
||||||
|
|
||||||
|
gfx_display_draw_text(gfx_widgets_get_font_regular(), state->message,
|
||||||
|
video_width/2,
|
||||||
|
video_height - height/2 + gfx_widgets_get_font_size()/4,
|
||||||
|
video_width, video_height,
|
||||||
|
text_color, TEXT_ALIGN_CENTER,
|
||||||
|
1, false, 0, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gfx_widget_generic_message_free(void)
|
||||||
|
{
|
||||||
|
gfx_widget_generic_message_state_t* state = gfx_widget_generic_message_get_ptr();
|
||||||
|
state->alpha = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gfx_widget_t gfx_widget_generic_message = {
|
||||||
|
NULL, /* init */
|
||||||
|
gfx_widget_generic_message_free,
|
||||||
|
NULL, /* context_reset*/
|
||||||
|
NULL, /* context_destroy */
|
||||||
|
NULL, /* layout */
|
||||||
|
NULL, /* iterate */
|
||||||
|
gfx_widget_generic_message_frame
|
||||||
|
};
|
@ -1263,6 +1263,7 @@ MENU
|
|||||||
#include "../gfx/gfx_widgets.c"
|
#include "../gfx/gfx_widgets.c"
|
||||||
#include "../gfx/widgets/gfx_widget_screenshot.c"
|
#include "../gfx/widgets/gfx_widget_screenshot.c"
|
||||||
#include "../gfx/widgets/gfx_widget_volume.c"
|
#include "../gfx/widgets/gfx_widget_volume.c"
|
||||||
|
#include "../gfx/widgets/gfx_widget_generic_message.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../input/input_osk.c"
|
#include "../input/input_osk.c"
|
||||||
|
@ -5555,7 +5555,7 @@ bool retroarch_apply_shader(enum rarch_shader_type type, const char *preset_path
|
|||||||
preset_file ? preset_file : "None");
|
preset_file ? preset_file : "None");
|
||||||
#ifdef HAVE_GFX_WIDGETS
|
#ifdef HAVE_GFX_WIDGETS
|
||||||
if (gfx_widgets_active())
|
if (gfx_widgets_active())
|
||||||
gfx_widgets_set_message(msg);
|
gfx_widget_set_message(msg);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
runloop_msg_queue_push(msg, 1, 120, true, NULL,
|
runloop_msg_queue_push(msg, 1, 120, true, NULL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user