(XMB) Use new 'menu_thumbnail' library for loading/rendering thumbnails

This commit is contained in:
jdgleaver 2019-12-10 17:01:52 +00:00
parent 739f7b47fe
commit 2dc9616509
5 changed files with 571 additions and 765 deletions

View File

@ -1862,7 +1862,7 @@ static void materialui_draw_thumbnail(
video_info, thumbnail,
x, y, mui->thumbnail_width_max, mui->thumbnail_height_max,
MENU_THUMBNAIL_ALIGN_CENTRE,
mui->transition_alpha, scale_factor);
mui->transition_alpha, scale_factor, NULL);
}
}
@ -4662,7 +4662,8 @@ static void materialui_render_fullscreen_thumbnails(
(unsigned)thumbnail_box_height,
MENU_THUMBNAIL_ALIGN_CENTRE,
mui->fullscreen_thumbnail_alpha,
1.0f);
1.0f,
NULL);
}
/* > Secondary */
@ -4691,7 +4692,8 @@ static void materialui_render_fullscreen_thumbnails(
(unsigned)thumbnail_box_height,
MENU_THUMBNAIL_ALIGN_CENTRE,
mui->fullscreen_thumbnail_alpha,
1.0f);
1.0f,
NULL);
}
}

View File

@ -798,7 +798,7 @@ void ozone_draw_thumbnail_bar(ozone_handle_t *ozone, video_frame_info_t *video_i
thumbnail_width,
thumbnail_height,
alignment,
1.0f, 1.0f);
1.0f, 1.0f, NULL);
}
else
{
@ -826,7 +826,7 @@ void ozone_draw_thumbnail_bar(ozone_handle_t *ozone, video_frame_info_t *video_i
thumbnail_width,
thumbnail_height,
MENU_THUMBNAIL_ALIGN_TOP,
1.0f, 1.0f);
1.0f, 1.0f, NULL);
}
else if (!ozone->selection_core_is_viewer)
{

File diff suppressed because it is too large Load Diff

View File

@ -299,6 +299,54 @@ void menu_thumbnail_request(
}
}
/* Requests loading of a specific thumbnail image file
* (may be used, for example, to load savestate images)
* - If operation fails, 'thumbnail->status' will be set to
* MUI_THUMBNAIL_STATUS_MISSING
* - If operation is successful, 'thumbnail->status' will be
* set to MUI_THUMBNAIL_STATUS_PENDING
* 'thumbnail' will be populated with texture info/metadata
* once the image load is complete */
void menu_thumbnail_request_file(
const char *file_path, menu_thumbnail_t *thumbnail)
{
settings_t *settings = config_get_ptr();
menu_thumbnail_tag_t *thumbnail_tag = NULL;
if (!thumbnail || !settings)
return;
/* Reset thumbnail, then set 'missing' status by default
* (saves a number of checks later) */
menu_thumbnail_reset(thumbnail);
thumbnail->status = MENU_THUMBNAIL_STATUS_MISSING;
/* Check if file path is valid */
if (string_is_empty(file_path))
return;
if (!path_is_valid(file_path))
return;
/* Load thumbnail */
thumbnail_tag = (menu_thumbnail_tag_t*)calloc(1, sizeof(menu_thumbnail_tag_t));
if (!thumbnail_tag)
return;
/* Configure user data */
thumbnail_tag->thumbnail = thumbnail;
thumbnail_tag->list_id = menu_thumbnail_list_id;
/* Would like to cancel any existing image load tasks
* here, but can't see how to do it... */
if(task_push_image_load(
file_path, video_driver_supports_rgba(),
settings->uints.menu_thumbnail_upscale_threshold,
menu_thumbnail_handle_upload, thumbnail_tag))
thumbnail->status = MENU_THUMBNAIL_STATUS_PENDING;
}
/* Resets (and free()s the current texture of) the
* specified thumbnail */
void menu_thumbnail_reset(menu_thumbnail_t *thumbnail)
@ -555,7 +603,9 @@ error:
/* Draws specified thumbnail with specified alignment
* (and aspect correct scaling) within a rectangle of
* (width x height)
* (width x height).
* 'shadow' defines an optional shadow effect (may be
* set to NULL if a shadow effect is not required).
* NOTE: Setting scale_factor > 1.0f will increase the
* size of the thumbnail beyond the limits of the
* (width x height) rectangle (alignment + aspect
@ -564,7 +614,8 @@ void menu_thumbnail_draw(
video_frame_info_t *video_info, menu_thumbnail_t *thumbnail,
float x, float y, unsigned width, unsigned height,
enum menu_thumbnail_alignment alignment,
float alpha, float scale_factor)
float alpha, float scale_factor,
menu_thumbnail_shadow_t *shadow)
{
/* Sanity check */
if (!video_info || !thumbnail ||
@ -580,6 +631,8 @@ void menu_thumbnail_draw(
math_matrix_4x4 mymat;
float draw_width;
float draw_height;
float draw_x;
float draw_y;
float thumbnail_alpha = thumbnail->alpha * alpha;
float thumbnail_color[16] = {
1.0f, 1.0f, 1.0f, 1.0f,
@ -621,15 +674,14 @@ void menu_thumbnail_draw(
menu_display_rotate_z(&rotate_draw, video_info);
/* Configure draw object */
/* Configure draw object
* > Note: Colour, width/height and position must
* be set *after* drawing any shadow effects */
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
coords.color = (const float*)thumbnail_color;
draw.width = (unsigned)draw_width;
draw.height = (unsigned)draw_height;
draw.scale_factor = 1.0f;
draw.rotation = 0.0f;
draw.coords = &coords;
@ -643,36 +695,99 @@ void menu_thumbnail_draw(
{
case MENU_THUMBNAIL_ALIGN_TOP:
/* Centred horizontally */
draw.x = x + ((float)width - draw_width) / 2.0f;
draw_x = x + ((float)width - draw_width) / 2.0f;
/* Drawn at top of bounding box */
draw.y = (float)video_info->height - y - draw_height;
draw_y = (float)video_info->height - y - draw_height;
break;
case MENU_THUMBNAIL_ALIGN_BOTTOM:
/* Centred horizontally */
draw.x = x + ((float)width - draw_width) / 2.0f;
draw_x = x + ((float)width - draw_width) / 2.0f;
/* Drawn at bottom of bounding box */
draw.y = (float)video_info->height - y - (float)height;
draw_y = (float)video_info->height - y - (float)height;
break;
case MENU_THUMBNAIL_ALIGN_LEFT:
/* Drawn at left side of bounding box */
draw.x = x;
draw_x = x;
/* Centred vertically */
draw.y = (float)video_info->height - y - draw_height - ((float)height - draw_height) / 2.0f;
draw_y = (float)video_info->height - y - draw_height - ((float)height - draw_height) / 2.0f;
break;
case MENU_THUMBNAIL_ALIGN_RIGHT:
/* Drawn at right side of bounding box */
draw.x = x + (float)width - draw_width;
draw_x = x + (float)width - draw_width;
/* Centred vertically */
draw.y = (float)video_info->height - y - draw_height - ((float)height - draw_height) / 2.0f;
draw_y = (float)video_info->height - y - draw_height - ((float)height - draw_height) / 2.0f;
break;
case MENU_THUMBNAIL_ALIGN_CENTRE:
default:
/* Centred both horizontally and vertically */
draw.x = x + ((float)width - draw_width) / 2.0f;
draw.y = (float)video_info->height - y - draw_height - ((float)height - draw_height) / 2.0f;
draw_x = x + ((float)width - draw_width) / 2.0f;
draw_y = (float)video_info->height - y - draw_height - ((float)height - draw_height) / 2.0f;
break;
}
/* Draw shadow effect, if required */
if (shadow)
{
/* Sanity check */
if ((shadow->type != MENU_THUMBNAIL_SHADOW_NONE) &&
(shadow->alpha > 0.0f))
{
float shadow_width;
float shadow_height;
float shadow_x;
float shadow_y;
float shadow_color[16] = {
0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
float shadow_alpha = thumbnail_alpha;
/* Set shadow opacity */
if (shadow->alpha < 1.0f)
shadow_alpha *= shadow->alpha;
menu_display_set_alpha(shadow_color, shadow_alpha);
/* Configure shadow based on effect type
* > Not using a switch() here, since we've
* already eliminated MENU_THUMBNAIL_SHADOW_NONE */
if (shadow->type == MENU_THUMBNAIL_SHADOW_OUTLINE)
{
shadow_width = draw_width + (float)(shadow->outline.width * 2);
shadow_height = draw_height + (float)(shadow->outline.width * 2);
shadow_x = draw_x - (float)shadow->outline.width;
shadow_y = draw_y - (float)shadow->outline.width;
}
/* Default: MENU_THUMBNAIL_SHADOW_DROP */
else
{
shadow_width = draw_width;
shadow_height = draw_height;
shadow_x = draw_x + shadow->drop.x_offset;
shadow_y = draw_y - shadow->drop.y_offset;
}
/* Apply shadow draw object configuration */
coords.color = (const float*)shadow_color;
draw.width = (unsigned)shadow_width;
draw.height = (unsigned)shadow_height;
draw.x = shadow_x;
draw.y = shadow_y;
/* Draw shadow */
menu_display_draw(&draw, video_info);
}
}
/* Final thumbnail draw object configuration */
coords.color = (const float*)thumbnail_color;
draw.width = (unsigned)draw_width;
draw.height = (unsigned)draw_height;
draw.x = draw_x;
draw.y = draw_y;
/* Draw thumbnail */
menu_display_draw(&draw, video_info);
menu_display_blend_end(video_info);

View File

@ -53,6 +53,15 @@ enum menu_thumbnail_alignment
MENU_THUMBNAIL_ALIGN_RIGHT
};
/* Defines all possible thumbnail shadow
* effect types */
enum menu_thumbnail_shadow_type
{
MENU_THUMBNAIL_SHADOW_NONE = 0,
MENU_THUMBNAIL_SHADOW_DROP,
MENU_THUMBNAIL_SHADOW_OUTLINE
};
/* Holds all runtime parameters associated with
* an entry thumbnail */
typedef struct
@ -65,6 +74,23 @@ typedef struct
float delay_timer;
} menu_thumbnail_t;
/* Holds all configuration parameters associated
* with a thumbnail shadow effect */
typedef struct
{
enum menu_thumbnail_shadow_type type;
float alpha;
struct
{
float x_offset;
float y_offset;
} drop;
struct
{
unsigned width;
} outline;
} menu_thumbnail_shadow_t;
/* Setters */
/* When streaming thumbnails, sets time in ms that an
@ -110,6 +136,17 @@ void menu_thumbnail_request(
menu_thumbnail_path_data_t *path_data, enum menu_thumbnail_id thumbnail_id,
playlist_t *playlist, size_t idx, menu_thumbnail_t *thumbnail);
/* Requests loading of a specific thumbnail image file
* (may be used, for example, to load savestate images)
* - If operation fails, 'thumbnail->status' will be set to
* MUI_THUMBNAIL_STATUS_MISSING
* - If operation is successful, 'thumbnail->status' will be
* set to MUI_THUMBNAIL_STATUS_PENDING
* 'thumbnail' will be populated with texture info/metadata
* once the image load is complete */
void menu_thumbnail_request_file(
const char *file_path, menu_thumbnail_t *thumbnail);
/* Resets (and free()s the current texture of) the
* specified thumbnail */
void menu_thumbnail_reset(menu_thumbnail_t *thumbnail);
@ -162,7 +199,9 @@ void menu_thumbnail_get_draw_dimensions(
/* Draws specified thumbnail with specified alignment
* (and aspect correct scaling) within a rectangle of
* (width x height)
* (width x height).
* 'shadow' defines an optional shadow effect (may be
* set to NULL if a shadow effect is not required).
* NOTE: Setting scale_factor > 1.0f will increase the
* size of the thumbnail beyond the limits of the
* (width x height) rectangle (alignment + aspect
@ -171,7 +210,8 @@ void menu_thumbnail_draw(
video_frame_info_t *video_info, menu_thumbnail_t *thumbnail,
float x, float y, unsigned width, unsigned height,
enum menu_thumbnail_alignment alignment,
float alpha, float scale_factor);
float alpha, float scale_factor,
menu_thumbnail_shadow_t *shadow);
RETRO_END_DECLS