mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-23 09:49:34 -10:00
With a box up, rgui_set_message() forced a redraw every iteration and the box's drawing forced one for the next, so RGUI repainted its whole framebuffer every frame; and the runloop marked the framebuffer dirty whenever a box was up, so it was uploaded every frame too - for a box that stays the same until it is answered. RGUI now keeps the text and button state the framebuffer shows, and redraws when the text, the box, the highlighted button or the one under the pointer changes, or once more when the box is gone. A box no longer marks the framebuffer dirty by itself: RGUI marks it when it repaints. The pointer and animations still redraw as before.
10089 lines
356 KiB
C
10089 lines
356 KiB
C
/* RetroArch - A frontend for libretro.
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
|
* Copyright (C) 2012-2015 - Michael Lelli
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
|
*
|
|
* 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 <stdlib.h>
|
|
#include <time.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
|
|
#include <string/stdstring.h>
|
|
#include <memalign.h>
|
|
#include <lists/file_list.h>
|
|
#include <compat/strl.h>
|
|
#include <compat/posix_string.h>
|
|
#include <encodings/utf.h>
|
|
#include <file/config_file.h>
|
|
#include <file/file_path.h>
|
|
#include <formats/image.h>
|
|
#include <gfx/scaler/scaler.h>
|
|
#include <retro_inline.h>
|
|
#include <retro_math.h>
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "../../config.h"
|
|
#endif
|
|
|
|
#include "../../frontend/frontend_driver.h"
|
|
|
|
#include "../menu_driver.h"
|
|
#include "../menu_media_controls.h"
|
|
#include "../menu_media_browser.h"
|
|
#include "../../gfx/gfx_media_cpu.h"
|
|
#include "../../gfx/gfx_surface.h"
|
|
#include "../../gfx/gfx_animation.h"
|
|
#include "../../gfx/gfx_thumbnail.h"
|
|
|
|
#include "../../msg_hash_lbl_str.h"
|
|
#include "../../configuration.h"
|
|
#include "../../file_path_special.h"
|
|
#include "../../input/input_osk.h"
|
|
#include "../../tasks/tasks_internal.h"
|
|
|
|
#include "../../gfx/bitmapfont.h"
|
|
#ifdef HAVE_LANGEXTRA
|
|
#include "rgui_bitmapfont.h"
|
|
#endif
|
|
|
|
#ifdef HAVE_AUDIOMIXER
|
|
#include "../../audio/audio_driver.h"
|
|
#endif
|
|
|
|
#if defined(GEKKO)
|
|
/* Required for the Wii build, since we have
|
|
* to query the hardware for the actual display
|
|
* aspect ratio... */
|
|
#if defined(HAVE_LIBOGC)
|
|
#include <ogc/conf.h>
|
|
#elif defined(HW_RVL)
|
|
#include <gekko/conf.h>
|
|
#endif
|
|
|
|
/* When running on the Wii, need to round down the
|
|
* frame buffer width value such that the last two
|
|
* bits are zero */
|
|
#define RGUI_ROUND_FB_WIDTH(width) ((unsigned)(width) & ~3)
|
|
#else
|
|
/* On all other platforms, just want to round width
|
|
* down to the nearest multiple of 2 */
|
|
#define RGUI_ROUND_FB_WIDTH(width) ((unsigned)(width) & ~1)
|
|
#endif
|
|
|
|
#define RGUI_MIN_FB_HEIGHT 192
|
|
#define RGUI_MIN_FB_WIDTH 256
|
|
#define RGUI_MAX_FB_WIDTH 560
|
|
|
|
#if defined(DINGUX)
|
|
#if defined(RS90) && !defined(MIYOO)
|
|
/* The RS-90 uses a fixed framebuffer size
|
|
* of 240x160 */
|
|
#define RGUI_DINGUX_ASPECT_RATIO RGUI_ASPECT_RATIO_3_2
|
|
#define RGUI_DINGUX_FB_WIDTH 240
|
|
#define RGUI_DINGUX_FB_HEIGHT 160
|
|
#else
|
|
/* Other Dingux devices (RG350 etc.) use a
|
|
* fixed framebuffer size of 320x240 */
|
|
#define RGUI_DINGUX_ASPECT_RATIO RGUI_ASPECT_RATIO_4_3
|
|
#define RGUI_DINGUX_FB_WIDTH 320
|
|
#define RGUI_DINGUX_FB_HEIGHT 240
|
|
#endif
|
|
#endif
|
|
#define RGUI_VITA_FB_HEIGHT 272
|
|
#define RGUI_DOS_FB_HEIGHT 200
|
|
#define RGUI_DOS_FB_WIDTH 320
|
|
|
|
/* Maximum entry value length in characters
|
|
* when using fixed with layouts
|
|
* (i.e. Maximum possible 'spacing' as
|
|
* defined in menu_cbs_get_value.c) */
|
|
#define RGUI_ENTRY_VALUE_MAXLEN 19
|
|
|
|
/* Maximum fraction of the terminal width that
|
|
* may be used for displaying entry values */
|
|
#define RGUI_ENTRY_VALUE_MAXLEN_FRACTION (3.0f / 8.0f)
|
|
|
|
#define RGUI_TICKER_SPACER " | "
|
|
|
|
#define RGUI_NUM_FONT_GLYPHS_REGULAR 128
|
|
#define RGUI_NUM_FONT_GLYPHS_EXTENDED 256
|
|
|
|
#define RGUI_NUM_PARTICLES 256
|
|
|
|
#ifndef PI
|
|
#define PI 3.14159265359f
|
|
#endif
|
|
|
|
#define RGUI_BATTERY_WARN_THRESHOLD 20
|
|
|
|
#define RGUI_SYMBOL_WIDTH FONT_WIDTH
|
|
#define RGUI_SYMBOL_HEIGHT FONT_HEIGHT
|
|
#define RGUI_SYMBOL_WIDTH_STRIDE (RGUI_SYMBOL_WIDTH + 1)
|
|
#define RGUI_SYMBOL_HEIGHT_STRIDE (RGUI_SYMBOL_HEIGHT + 1)
|
|
|
|
/* When the mouse wheel moves, this is the number of rows that
|
|
* that will be scrolled. */
|
|
#define RGUI_WHEEL_SCROLL_ROWS 3
|
|
|
|
enum rgui_playlist_mainmenu_selection
|
|
{
|
|
RGUI_MAINMENU_HISTORY = 0,
|
|
RGUI_MAINMENU_FAVORITES,
|
|
RGUI_MAINMENU_LAST
|
|
};
|
|
|
|
/* Defines all possible entry value types
|
|
* > Note: These are not necessarily 'values',
|
|
* but they correspond to the object drawn in
|
|
* the 'value' location when rendering
|
|
* menu lists */
|
|
enum rgui_entry_value_type
|
|
{
|
|
RGUI_ENTRY_VALUE_NONE = 0,
|
|
RGUI_ENTRY_VALUE_TEXT,
|
|
RGUI_ENTRY_VALUE_SWITCH_ON,
|
|
RGUI_ENTRY_VALUE_SWITCH_OFF,
|
|
RGUI_ENTRY_VALUE_CHECKMARK
|
|
};
|
|
|
|
enum rgui_symbol_type
|
|
{
|
|
RGUI_SYMBOL_BACKSPACE = 0,
|
|
RGUI_SYMBOL_ENTER,
|
|
RGUI_SYMBOL_SHIFT_UP,
|
|
RGUI_SYMBOL_SHIFT_DOWN,
|
|
RGUI_SYMBOL_NEXT,
|
|
RGUI_SYMBOL_TEXT_CURSOR,
|
|
RGUI_SYMBOL_CHARGING,
|
|
RGUI_SYMBOL_BATTERY_100,
|
|
RGUI_SYMBOL_BATTERY_80,
|
|
RGUI_SYMBOL_BATTERY_60,
|
|
RGUI_SYMBOL_BATTERY_40,
|
|
RGUI_SYMBOL_BATTERY_20,
|
|
RGUI_SYMBOL_CHECKMARK,
|
|
RGUI_SYMBOL_SWITCH_ON_LEFT,
|
|
RGUI_SYMBOL_SWITCH_ON_CENTRE,
|
|
RGUI_SYMBOL_SWITCH_ON_RIGHT,
|
|
RGUI_SYMBOL_SWITCH_OFF_LEFT,
|
|
RGUI_SYMBOL_SWITCH_OFF_CENTRE,
|
|
RGUI_SYMBOL_SWITCH_OFF_RIGHT
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
uint32_t hover_color;
|
|
uint32_t normal_color;
|
|
uint32_t title_color;
|
|
uint32_t bg_dark_color;
|
|
uint32_t bg_light_color;
|
|
uint32_t border_dark_color;
|
|
uint32_t border_light_color;
|
|
uint32_t shadow_color;
|
|
uint32_t particle_color;
|
|
} rgui_theme_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t hover_color;
|
|
uint16_t normal_color;
|
|
uint16_t title_color;
|
|
uint16_t bg_dark_color;
|
|
uint16_t bg_light_color;
|
|
uint16_t border_dark_color;
|
|
uint16_t border_light_color;
|
|
uint16_t shadow_color;
|
|
uint16_t particle_color;
|
|
/* Screensaver colors */
|
|
uint16_t ss_bg_color;
|
|
uint16_t ss_particle_color;
|
|
/* Null color */
|
|
uint16_t disabled_color;
|
|
} rgui_colors_t;
|
|
|
|
typedef struct
|
|
{
|
|
unsigned start_x;
|
|
unsigned start_y;
|
|
unsigned width;
|
|
unsigned height;
|
|
unsigned value_maxlen;
|
|
} rgui_term_layout_t;
|
|
|
|
typedef struct
|
|
{
|
|
video_viewport_t vp; /* int alignment */
|
|
unsigned aspect_ratio_idx;
|
|
} rgui_video_settings_t;
|
|
|
|
/* A 'particle' is just 4 float variables that can
|
|
* be used for any purpose - e.g.:
|
|
* > a = x pos
|
|
* > b = y pos
|
|
* > c = x velocity
|
|
* or:
|
|
* > a = radius
|
|
* > b = theta
|
|
* etc. */
|
|
typedef struct
|
|
{
|
|
float a;
|
|
float b;
|
|
float c;
|
|
float d;
|
|
} rgui_particle_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t *data;
|
|
/* The largest the thumbnail may be drawn, and the size it
|
|
* actually is, both in VIDEO_SCALE_PACK's layout. */
|
|
unsigned max_dims;
|
|
unsigned dims;
|
|
char path[PATH_MAX_LENGTH];
|
|
bool is_valid;
|
|
} thumbnail_t;
|
|
|
|
typedef struct
|
|
{
|
|
uint16_t *data;
|
|
unsigned width;
|
|
unsigned height;
|
|
} frame_buf_t;
|
|
|
|
enum rgui_flags
|
|
{
|
|
RGUI_FLAG_BG_MODIFIED = (1 << 0),
|
|
RGUI_FLAG_FORCE_REDRAW = (1 << 1),
|
|
RGUI_FLAG_FORCE_MENU_REFRESH = (1 << 2),
|
|
RGUI_FLAG_RESTORE_ASPECT_LOCK = (1 << 3),
|
|
RGUI_FLAG_SHOW_MOUSE = (1 << 4),
|
|
RGUI_FLAG_SHOW_SCREENSAVER = (1 << 5),
|
|
RGUI_FLAG_SHOW_WALLPAPER = (1 << 6),
|
|
RGUI_FLAG_IGNORE_RESIZE_EVENTS = (1 << 7),
|
|
RGUI_FLAG_BG_THICKNESS = (1 << 8),
|
|
RGUI_FLAG_BORDER_THICKNESS = (1 << 9),
|
|
RGUI_FLAG_BORDER_ENABLE = (1 << 10),
|
|
RGUI_FLAG_TRANSPARENCY_SUPPORTED = (1 << 11),
|
|
RGUI_FLAG_TRANSPARENCY_ENABLE = (1 << 12),
|
|
RGUI_FLAG_SHADOW_ENABLE = (1 << 13),
|
|
RGUI_FLAG_EXTENDED_ASCII_ENABLE = (1 << 14),
|
|
RGUI_FLAG_IS_PLAYLIST = (1 << 15),
|
|
RGUI_FLAG_IS_EXPLORE_LIST = (1 << 16),
|
|
RGUI_FLAG_IS_STATE_SLOT = (1 << 17),
|
|
RGUI_FLAG_THUMBNAIL_LOAD_PENDING = (1 << 19),
|
|
RGUI_FLAG_ASPECT_UPDATE_PENDING = (1 << 20),
|
|
RGUI_FLAG_ENTRY_HAS_THUMBNAIL = (1 << 21),
|
|
RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL = (1 << 22),
|
|
RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL = (1 << 23),
|
|
RGUI_FLAG_IS_PLAYLISTS_TAB = (1 << 24),
|
|
RGUI_FLAG_IS_QUICK_MENU = (1 << 25),
|
|
RGUI_FLAG_DRAW_ENTRY_SKIP = (1 << 26)
|
|
};
|
|
|
|
typedef struct rgui_media_gpu_view
|
|
{
|
|
uintptr_t texture;
|
|
gfx_media_rect_t rect;
|
|
unsigned source_dims;
|
|
unsigned texture_dims;
|
|
float alpha;
|
|
uint8_t flags;
|
|
bool visible;
|
|
} rgui_media_gpu_view_t;
|
|
|
|
typedef struct
|
|
{
|
|
retro_time_t thumbnail_load_trigger_time; /* uint64_t */
|
|
retro_time_t draw_entry_hold_until;
|
|
gfx_media_cpu_t *media_player;
|
|
gfx_thumbnail_t media_gpu;
|
|
rgui_media_gpu_view_t media_gpu_views[3];
|
|
retro_atomic_int_t media_gpu_states[3];
|
|
rgui_media_gpu_view_t media_gpu_pending;
|
|
rgui_media_gpu_view_t media_gpu_view;
|
|
menu_media_controls_t media;
|
|
menu_input_pointer_t media_pointer;
|
|
char media_path[PATH_MAX_LENGTH];
|
|
char media_requested_path[PATH_MAX_LENGTH];
|
|
|
|
struct
|
|
{
|
|
bitmapfont_lut_t *regular;
|
|
|
|
#ifdef HAVE_LANGEXTRA
|
|
bitmapfont_lut_t *eng_6x10;
|
|
bitmapfont_lut_t *lse_6x10;
|
|
bitmapfont_lut_t *eng_10x10;
|
|
bitmapfont_lut_t *chn_10x10;
|
|
bitmapfont_lut_t *jpn_10x10;
|
|
bitmapfont_lut_t *kor_10x10;
|
|
bitmapfont_lut_t *rus_10x10;
|
|
#endif
|
|
} fonts;
|
|
|
|
/* Backing storage for frame_buf, background_buf, fs_thumbnail,
|
|
* mini_thumbnail and mini_left_thumbnail. Their data pointers are
|
|
* 64-byte aligned views into this block; rgui_buffers_free() releases
|
|
* all five at once. upscale_buf is separate: it is sized on demand
|
|
* from the display, not from the menu geometry. */
|
|
uint16_t *fb_arena;
|
|
|
|
frame_buf_t frame_buf;
|
|
frame_buf_t background_buf;
|
|
frame_buf_t upscale_buf;
|
|
/* For the upscale: the source column of each output column, then
|
|
* one output row, built once and copied to each row that repeats
|
|
* it (the output may be a loaned driver buffer, which is not read
|
|
* back). Grown only when the output gets wider. */
|
|
uint16_t *upscale_line;
|
|
/* The menu's own text, drawn by the next rgui_render() */
|
|
const char *msgbox;
|
|
/* The dialog's buttons as the framebuffer shows them */
|
|
int msgbox_highlight;
|
|
int msgbox_hover;
|
|
uint8_t msgbox_epoch;
|
|
unsigned upscale_line_width;
|
|
unsigned upscale_map_src_width;
|
|
unsigned upscale_map_width;
|
|
|
|
thumbnail_t fs_thumbnail;
|
|
thumbnail_t mini_thumbnail;
|
|
thumbnail_t mini_left_thumbnail;
|
|
|
|
rgui_video_settings_t menu_video_settings;
|
|
/* Copy staged by a delay_update publish (the frame path under
|
|
* threaded video); rgui_render() on the main thread - which owns
|
|
* settings writes - applies it under RGUI_FLAG_ASPECT_UPDATE_PENDING
|
|
* before firing CMD_EVENT_VIDEO_SET_ASPECT_RATIO. */
|
|
rgui_video_settings_t pending_video_config; /* int alignment */
|
|
rgui_video_settings_t content_video_settings; /* int alignment */
|
|
|
|
/* The glyph cell, one word, VIDEO_SCALE_PACK's layout. */
|
|
unsigned font_dims;
|
|
unsigned font_width_stride;
|
|
unsigned font_height_stride;
|
|
|
|
/* The cap a mini thumbnail is fitted into, one word. */
|
|
unsigned mini_thumbnail_max_dims;
|
|
unsigned mini_thumbnail_delay;
|
|
/* The video size this was last laid out for, one word,
|
|
* VIDEO_SCALE_PACK's layout. */
|
|
unsigned last_dims;
|
|
/* The window this was laid out for, one word. */
|
|
unsigned window_dims;
|
|
unsigned particle_effect;
|
|
unsigned color_theme;
|
|
unsigned menu_aspect_ratio;
|
|
unsigned menu_aspect_ratio_lock;
|
|
unsigned language;
|
|
|
|
rgui_term_layout_t term_layout;
|
|
|
|
uint32_t thumbnail_queue_size;
|
|
uint32_t left_thumbnail_queue_size;
|
|
uint32_t flags;
|
|
/* Pixel offset of the list, term rows * font_height_stride;
|
|
* int16_t overflows on playlists past a few thousand entries. */
|
|
int32_t scroll_y;
|
|
int8_t gfx_thumbnails_prev;
|
|
|
|
rgui_particle_t particles[RGUI_NUM_PARTICLES]; /* float alignment */
|
|
|
|
ssize_t playlist_index;
|
|
uint8_t settings_selection_ptr;
|
|
size_t playlist_selection_ptr;
|
|
size_t playlist_selection[NAME_MAX_LENGTH];
|
|
size_t playlist_mainmenu_selection[RGUI_MAINMENU_LAST]; /* History + Favorites */
|
|
rgui_colors_t colors; /* int16_t alignment */
|
|
|
|
struct scaler_ctx image_scaler;
|
|
menu_input_pointer_t pointer;
|
|
|
|
char entry_index_str[32];
|
|
char entry_index_offset;
|
|
|
|
char menu_title[NAME_MAX_LENGTH]; /* Must be a fixed length array... */
|
|
/* The message box text the framebuffer shows, empty for none */
|
|
char msgbox_drawn[MENU_LABEL_MAX_LENGTH];
|
|
char savestate_thumbnail_file_path[PATH_MAX_LENGTH];
|
|
char theme_preset_path[PATH_MAX_LENGTH]; /* Must be a fixed length array... */
|
|
char theme_dynamic_path[PATH_MAX_LENGTH]; /* Must be a fixed length array... */
|
|
char last_theme_dynamic_path[PATH_MAX_LENGTH]; /* Must be a fixed length array... */
|
|
/* What rendering one entry needs. Here rather than in the loop that
|
|
* renders them: a menu_entry_t is 3872 bytes on its own, and with
|
|
* the sublabel buffer beside it the frame came to 5912 - past what
|
|
* this tree allows, on a function that runs every frame. One entry
|
|
* is rendered at a time. */
|
|
menu_entry_t render_entry;
|
|
char render_sublabel_buf[MENU_LABEL_MAX_LENGTH];
|
|
char menu_sublabel[MENU_LABEL_MAX_LENGTH]; /* Must be a fixed length array... */
|
|
} rgui_t;
|
|
|
|
static const rgui_theme_t rgui_theme_classic_red = {
|
|
0xFFFF362B, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFFF362B, /* title_color */
|
|
0xC0202020, /* bg_dark_color */
|
|
0xC0404040, /* bg_light_color */
|
|
0xC08C0000, /* border_dark_color */
|
|
0xC0CC0E03, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC09E8686 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_classic_red = {
|
|
0xFFFF362B, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFFF362B, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF6D0000, /* border_dark_color */
|
|
0xFFA30000, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF7A6D6D /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_classic_orange = {
|
|
0xFFF87217, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFF87217, /* title_color */
|
|
0xC0202020, /* bg_dark_color */
|
|
0xC0404040, /* bg_light_color */
|
|
0xC0962800, /* border_dark_color */
|
|
0xC0E46C03, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC09E9286 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_classic_orange = {
|
|
0xFFF87217, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFF87217, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF7A1B00, /* border_dark_color */
|
|
0xFFBE5200, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF7A7A6D /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_classic_yellow = {
|
|
0xFFFFD801, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFFFD801, /* title_color */
|
|
0xC0202020, /* bg_dark_color */
|
|
0xC0404040, /* bg_light_color */
|
|
0xC0AC7800, /* border_dark_color */
|
|
0xC0F3C60D, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC0999581 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_classic_yellow = {
|
|
0xFFFFD801, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFFFD801, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF885F00, /* border_dark_color */
|
|
0xFFCCA300, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF7A7A6D /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_classic_green = {
|
|
0xFF64FF64, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFF64FF64, /* title_color */
|
|
0xC0202020, /* bg_dark_color */
|
|
0xC0404040, /* bg_light_color */
|
|
0xC0204020, /* border_dark_color */
|
|
0xC0408040, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC0879E87 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_classic_green = {
|
|
0xFF64FF64, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFF64FF64, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF1B361B, /* border_dark_color */
|
|
0xFF366D36, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF6D7A6D /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_classic_blue = {
|
|
0xFF48BEFF, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFF48BEFF, /* title_color */
|
|
0xC0202020, /* bg_dark_color */
|
|
0xC0404040, /* bg_light_color */
|
|
0xC0005BA6, /* border_dark_color */
|
|
0xC02E94E2, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC086949E /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_classic_blue = {
|
|
0xFF48BEFF, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFF48BEFF, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF004488, /* border_dark_color */
|
|
0xFF1B7ABE, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF6D7A7A /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_classic_violet = {
|
|
0xFFD86EFF, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFD86EFF, /* title_color */
|
|
0xC0202020, /* bg_dark_color */
|
|
0xC0404040, /* bg_light_color */
|
|
0xC04C0A60, /* border_dark_color */
|
|
0xC0842DCE, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC08E8299 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_classic_violet = {
|
|
0xFFD86EFF, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFD86EFF, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF360052, /* border_dark_color */
|
|
0xFF6D1BA3, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF6D6D7A /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_classic_grey = {
|
|
0xFFB6C1C7, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFB6C1C7, /* title_color */
|
|
0xC0202020, /* bg_dark_color */
|
|
0xC0404040, /* bg_light_color */
|
|
0xC0505050, /* border_dark_color */
|
|
0xC0798A99, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC078828A /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_classic_grey = {
|
|
0xFFB6C1C7, /* hover_color */
|
|
0xFFFFFFFF, /* normal_color */
|
|
0xFFB6C1C7, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF444444, /* border_dark_color */
|
|
0xFF5F6D7A, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF5F6D6D /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_legacy_red = {
|
|
0xFFFFBDBD, /* hover_color */
|
|
0xFFFAF6D5, /* normal_color */
|
|
0xFFFF948A, /* title_color */
|
|
0xC09E4137, /* bg_dark_color */
|
|
0xC0B34B41, /* bg_light_color */
|
|
0xC0BF5E58, /* border_dark_color */
|
|
0xC0F27A6F, /* border_light_color */
|
|
0xC01F0C0A, /* shadow_color */
|
|
0xC0F75431 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_legacy_red = {
|
|
0xFFFFBDBD, /* hover_color */
|
|
0xFFFAF6D5, /* normal_color */
|
|
0xFFFF948A, /* title_color */
|
|
0xFF7A3629, /* bg_dark_color */
|
|
0xFF963636, /* bg_light_color */
|
|
0xFF964444, /* border_dark_color */
|
|
0xFFCC5F52, /* border_light_color */
|
|
0xFF0E0000, /* shadow_color */
|
|
0xFFCC4429 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_dark_purple = {
|
|
0xFFF2B5D6, /* hover_color */
|
|
0xFFE8D0CC, /* normal_color */
|
|
0xFFC79FC2, /* title_color */
|
|
0xC0562D56, /* bg_dark_color */
|
|
0xC0663A66, /* bg_light_color */
|
|
0xC0885783, /* border_dark_color */
|
|
0xC0A675A1, /* border_light_color */
|
|
0xC0140A14, /* shadow_color */
|
|
0xC09786A0 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_dark_purple = {
|
|
0xFFF2B5D6, /* hover_color */
|
|
0xFFE8D0CC, /* normal_color */
|
|
0xFFC79FC2, /* title_color */
|
|
0xFF441B44, /* bg_dark_color */
|
|
0xFF522952, /* bg_light_color */
|
|
0xFF6D446D, /* border_dark_color */
|
|
0xFF885F88, /* border_light_color */
|
|
0xFF0E000E, /* shadow_color */
|
|
0xFF7A6D88 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_midnight_blue = {
|
|
0xFFB2D3ED, /* hover_color */
|
|
0xFFD3DCDE, /* normal_color */
|
|
0xFF86A1BA, /* title_color */
|
|
0xC024374A, /* bg_dark_color */
|
|
0xC03C4D5E, /* bg_light_color */
|
|
0xC046586A, /* border_dark_color */
|
|
0xC06D7F91, /* border_light_color */
|
|
0xC00A0F14, /* shadow_color */
|
|
0xC084849E /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_midnight_blue = {
|
|
0xFFB2D3ED, /* hover_color */
|
|
0xFFD3DCDE, /* normal_color */
|
|
0xFF86A1BA, /* title_color */
|
|
0xFF1B2936, /* bg_dark_color */
|
|
0xFF293644, /* bg_light_color */
|
|
0xFF364452, /* border_dark_color */
|
|
0xFF525F7A, /* border_light_color */
|
|
0xFF00000E, /* shadow_color */
|
|
0xFF6D6D7A /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_golden = {
|
|
0xFFFFE666, /* hover_color */
|
|
0xFFFFFFDC, /* normal_color */
|
|
0xFFFFCC00, /* title_color */
|
|
0xC0B88D0B, /* bg_dark_color */
|
|
0xC0BF962B, /* bg_light_color */
|
|
0xC0E1AD21, /* border_dark_color */
|
|
0xC0FCC717, /* border_light_color */
|
|
0xC0382B03, /* shadow_color */
|
|
0xC0F7D15E /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_golden = {
|
|
0xFFFFE666, /* hover_color */
|
|
0xFFFFFFDC, /* normal_color */
|
|
0xFFFFCC00, /* title_color */
|
|
0xFF966D00, /* bg_dark_color */
|
|
0xFF967A1B, /* bg_light_color */
|
|
0xFFBE881B, /* border_dark_color */
|
|
0xFFCCA30E, /* border_light_color */
|
|
0xFF291B00, /* shadow_color */
|
|
0xFFCCB144 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_electric_blue = {
|
|
0xFF7DF9FF, /* hover_color */
|
|
0xFFDBE9F4, /* normal_color */
|
|
0xFF86CDE0, /* title_color */
|
|
0xC02E69C6, /* bg_dark_color */
|
|
0xC0007FFF, /* bg_light_color */
|
|
0xC034A5D8, /* border_dark_color */
|
|
0xC070C9FF, /* border_light_color */
|
|
0xC012294D, /* shadow_color */
|
|
0xC080C7E6 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_electric_blue = {
|
|
0xFF7DF9FF, /* hover_color */
|
|
0xFFDBE9F4, /* normal_color */
|
|
0xFF86CDE0, /* title_color */
|
|
0xFF1B52A3, /* bg_dark_color */
|
|
0xFF0065D9, /* bg_light_color */
|
|
0xFF2988B1, /* border_dark_color */
|
|
0xFF5FA3CC, /* border_light_color */
|
|
0xFF0E1B36, /* shadow_color */
|
|
0xFF6DA3BE /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_apple_green = {
|
|
0xFFB0FC64, /* hover_color */
|
|
0xFFD8F2CB, /* normal_color */
|
|
0xFFA6D652, /* title_color */
|
|
0xC04F7942, /* bg_dark_color */
|
|
0xC0688539, /* bg_light_color */
|
|
0xC0608E3A, /* border_dark_color */
|
|
0xC09AB973, /* border_light_color */
|
|
0xC01F2E19, /* shadow_color */
|
|
0xC0A3C44E /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_apple_green = {
|
|
0xFFB0FC64, /* hover_color */
|
|
0xFFD8F2CB, /* normal_color */
|
|
0xFFA6D652, /* title_color */
|
|
0xFF365F36, /* bg_dark_color */
|
|
0xFF526D29, /* bg_light_color */
|
|
0xFF526D29, /* border_dark_color */
|
|
0xFF7A965F, /* border_light_color */
|
|
0xFF0E1B0E, /* shadow_color */
|
|
0xFF88A336 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_volcanic_red = {
|
|
0xFFFFCC99, /* hover_color */
|
|
0xFFD3D3D3, /* normal_color */
|
|
0xFFDDADAF, /* title_color */
|
|
0xC0922724, /* bg_dark_color */
|
|
0xC0BD0F1E, /* bg_light_color */
|
|
0xC0CE2029, /* border_dark_color */
|
|
0xC0FF0000, /* border_light_color */
|
|
0xC0330D0D, /* shadow_color */
|
|
0xC0E67D45 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_volcanic_red = {
|
|
0xFFFFCC99, /* hover_color */
|
|
0xFFD3D3D3, /* normal_color */
|
|
0xFFDDADAF, /* title_color */
|
|
0xFF7A1B1B, /* bg_dark_color */
|
|
0xFF96000E, /* bg_light_color */
|
|
0xFFA31B1B, /* border_dark_color */
|
|
0xFFCC0000, /* border_light_color */
|
|
0xFF290000, /* shadow_color */
|
|
0xFFBE5F36 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_lagoon = {
|
|
0xFFBCE1EB, /* hover_color */
|
|
0xFFCFCFC4, /* normal_color */
|
|
0xFF86C7C7, /* title_color */
|
|
0xC0495C6B, /* bg_dark_color */
|
|
0xC0526778, /* bg_light_color */
|
|
0xC058848F, /* border_dark_color */
|
|
0xC060909C, /* border_light_color */
|
|
0xC01C2329, /* shadow_color */
|
|
0xC09FB1C7 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_lagoon = {
|
|
0xFFBCE1EB, /* hover_color */
|
|
0xFFCFCFC4, /* normal_color */
|
|
0xFF86C7C7, /* title_color */
|
|
0xFF364452, /* bg_dark_color */
|
|
0xFF44525F, /* bg_light_color */
|
|
0xFF446D6D, /* border_dark_color */
|
|
0xFF527A7A, /* border_light_color */
|
|
0xFF0E1B1B, /* shadow_color */
|
|
0xFF7A96A3 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_brogrammer = {
|
|
0xFF3498DB, /* hover_color */
|
|
0xFFECF0F1, /* normal_color */
|
|
0xFF2ECC71, /* title_color */
|
|
0xC0242424, /* bg_dark_color */
|
|
0xC0242424, /* bg_light_color */
|
|
0xC0E74C3C, /* border_dark_color */
|
|
0xC0E74C3C, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC0606060 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_brogrammer = {
|
|
0xFF3498DB, /* hover_color */
|
|
0xFFECF0F1, /* normal_color */
|
|
0xFF2ECC71, /* title_color */
|
|
0xFF1B1B1B, /* bg_dark_color */
|
|
0xFF1B1B1B, /* bg_light_color */
|
|
0xFFBE3629, /* border_dark_color */
|
|
0xFFBE3629, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF525252 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_dracula = {
|
|
0xFFFF79C6, /* hover_color */
|
|
0xFFF8F8F2, /* normal_color */
|
|
0xFFBD93F9, /* title_color */
|
|
0xE6282A36, /* bg_dark_color */
|
|
0xE6282A36, /* bg_light_color */
|
|
0xE644475A, /* border_dark_color */
|
|
0xE644475A, /* border_light_color */
|
|
0xFF22212C, /* shadow_color */
|
|
0xE6525F88 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_dracula = {
|
|
0xFFFF79C6, /* hover_color */
|
|
0xFFF8F8F2, /* normal_color */
|
|
0xFFBD93F9, /* title_color */
|
|
0xFF282A36, /* bg_dark_color */
|
|
0xFF282A36, /* bg_light_color */
|
|
0xFF44475A, /* border_dark_color */
|
|
0xFF44475A, /* border_light_color */
|
|
0xFF22212C, /* shadow_color */
|
|
0xFF525F88 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_evergarden = {
|
|
0xFFCBE3B3, /* hover_color */
|
|
0xFFDDEEDD, /* normal_color */
|
|
0xFF96B4AA, /* title_color */
|
|
0xC0112222, /* bg_dark_color */
|
|
0xC0112222, /* bg_light_color */
|
|
0xC0374145, /* border_dark_color */
|
|
0xC0374145, /* border_light_color */
|
|
0xFF171C1F, /* shadow_color */
|
|
0xC06F8788 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_evergarden = {
|
|
0xFFCBE3B3, /* hover_color */
|
|
0xFFDDEEDD, /* normal_color */
|
|
0xFF96B4AA, /* title_color */
|
|
0xFF112222, /* bg_dark_color */
|
|
0xFF112222, /* bg_light_color */
|
|
0xFF374145, /* border_dark_color */
|
|
0xFF374145, /* border_light_color */
|
|
0xFF171C1F, /* shadow_color */
|
|
0xFF6F8788 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_fairyfloss = {
|
|
0xFFFFF352, /* hover_color */
|
|
0xFFF8F8F2, /* normal_color */
|
|
0xFFFFB8D1, /* title_color */
|
|
0xC0675F87, /* bg_dark_color */
|
|
0xC0675F87, /* bg_light_color */
|
|
0xC08077A8, /* border_dark_color */
|
|
0xC08077A8, /* border_light_color */
|
|
0xC0262433, /* shadow_color */
|
|
0xC0C5A3FF /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_fairyfloss = {
|
|
0xFFFFF352, /* hover_color */
|
|
0xFFF8F8F2, /* normal_color */
|
|
0xFFFFB8D1, /* title_color */
|
|
0xFF52446D, /* bg_dark_color */
|
|
0xFF52446D, /* bg_light_color */
|
|
0xFF706087, /* border_dark_color */
|
|
0xFF706087, /* border_light_color */
|
|
0xFF1B1B29, /* shadow_color */
|
|
0xFFA388CC /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_flatui = {
|
|
0xFF0A74B9, /* hover_color */
|
|
0xFF2C3E50, /* normal_color */
|
|
0xFF8E44AD, /* title_color */
|
|
0xE0ECF0F1, /* bg_dark_color */
|
|
0xE0ECF0F1, /* bg_light_color */
|
|
0xE095A5A6, /* border_dark_color */
|
|
0xE095A5A6, /* border_light_color */
|
|
0xE0C3DBDE, /* shadow_color */
|
|
0xE0B3DFFF /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_flatui = {
|
|
0xFF0A74B9, /* hover_color */
|
|
0xFF2C3E50, /* normal_color */
|
|
0xFF8E44AD, /* title_color */
|
|
0xFFDEEEEE, /* bg_dark_color */
|
|
0xFFDEEEEE, /* bg_light_color */
|
|
0xFF8F9F9F, /* border_dark_color */
|
|
0xFF8F9F9F, /* border_light_color */
|
|
0xFFBECECE, /* shadow_color */
|
|
0xFFAFCEEE /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_gruvbox_dark = {
|
|
0xFFFE8019, /* hover_color */
|
|
0xFFEBDBB2, /* normal_color */
|
|
0xFF83A598, /* title_color */
|
|
0xC03D3D3D, /* bg_dark_color */
|
|
0xC03D3D3D, /* bg_light_color */
|
|
0xC099897A, /* border_dark_color */
|
|
0xC099897A, /* border_light_color */
|
|
0xC0000000, /* shadow_color */
|
|
0xC098971A /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_gruvbox_dark = {
|
|
0xFFFE8019, /* hover_color */
|
|
0xFFEBDBB2, /* normal_color */
|
|
0xFF83A598, /* title_color */
|
|
0xFF292929, /* bg_dark_color */
|
|
0xFF292929, /* bg_light_color */
|
|
0xFF7A6D5F, /* border_dark_color */
|
|
0xFF7A6D5F, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF7A7A0E /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_gruvbox_light = {
|
|
0xFFAF3A03, /* hover_color */
|
|
0xFF3C3836, /* normal_color */
|
|
0xFF076678, /* title_color */
|
|
0xE0FBEBC7, /* bg_dark_color */
|
|
0xE0FBEBC7, /* bg_light_color */
|
|
0xE0928374, /* border_dark_color */
|
|
0xE0928374, /* border_light_color */
|
|
0xE0D5C4A1, /* shadow_color */
|
|
0xE0D5C4A1 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_gruvbox_light = {
|
|
0xFFAF3A03, /* hover_color */
|
|
0xFF3C3836, /* normal_color */
|
|
0xFF076678, /* title_color */
|
|
0xFFEEDEBE, /* bg_dark_color */
|
|
0xFFEEDEBE, /* bg_light_color */
|
|
0xFF8F7F6F, /* border_dark_color */
|
|
0xFF8F7F6F, /* border_light_color */
|
|
0xFFCEBE9F, /* shadow_color */
|
|
0xFFCEBE9F /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_hacking_the_kernel = {
|
|
0xFF83FF83, /* hover_color */
|
|
0xFF00E000, /* normal_color */
|
|
0xFF00FF00, /* title_color */
|
|
0xC0000000, /* bg_dark_color */
|
|
0xC0000000, /* bg_light_color */
|
|
0xC0036303, /* border_dark_color */
|
|
0xC0036303, /* border_light_color */
|
|
0xC0154D2B, /* shadow_color */
|
|
0xC0008C00 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_hacking_the_kernel = {
|
|
0xFF83FF83, /* hover_color */
|
|
0xFF00E000, /* normal_color */
|
|
0xFF00FF00, /* title_color */
|
|
0xFF000000, /* bg_dark_color */
|
|
0xFF000000, /* bg_light_color */
|
|
0xFF005200, /* border_dark_color */
|
|
0xFF005200, /* border_light_color */
|
|
0xFF0E361B, /* shadow_color */
|
|
0xFF006D00 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_nord = {
|
|
0xFF8FBCBB, /* hover_color */
|
|
0xFFD8DEE9, /* normal_color */
|
|
0xFF81A1C1, /* title_color */
|
|
0xC0363C4F, /* bg_dark_color */
|
|
0xC0363C4F, /* bg_light_color */
|
|
0xC04E596E, /* border_dark_color */
|
|
0xC04E596E, /* border_light_color */
|
|
0xC0040505, /* shadow_color */
|
|
0xC05E81AC /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_nord = {
|
|
0xFF8FBCBB, /* hover_color */
|
|
0xFFD8DEE9, /* normal_color */
|
|
0xFF81A1C1, /* title_color */
|
|
0xFF292936, /* bg_dark_color */
|
|
0xFF292936, /* bg_light_color */
|
|
0xFF364452, /* border_dark_color */
|
|
0xFF364452, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF446D88 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_nova = {
|
|
0XFF7FC1CA, /* hover_color */
|
|
0XFFC5D4DD, /* normal_color */
|
|
0XFF9A93E1, /* title_color */
|
|
0xC0485B66, /* bg_dark_color */
|
|
0xC0485B66, /* bg_light_color */
|
|
0xC0627985, /* border_dark_color */
|
|
0xC0627985, /* border_light_color */
|
|
0xC01E272C, /* shadow_color */
|
|
0xC0889BA7 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_nova = {
|
|
0XFF7FC1CA, /* hover_color */
|
|
0XFFC5D4DD, /* normal_color */
|
|
0XFF9A93E1, /* title_color */
|
|
0xFF364452, /* bg_dark_color */
|
|
0xFF364452, /* bg_light_color */
|
|
0xFF546370, /* border_dark_color */
|
|
0xFF546370, /* border_light_color */
|
|
0xFF0E1B1B, /* shadow_color */
|
|
0xFF6D7A88 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_one_dark = {
|
|
0XFF98C379, /* hover_color */
|
|
0XFFBBBBBB, /* normal_color */
|
|
0XFFD19A66, /* title_color */
|
|
0xC02D323B, /* bg_dark_color */
|
|
0xC02D323B, /* bg_light_color */
|
|
0xC0495162, /* border_dark_color */
|
|
0xC0495162, /* border_light_color */
|
|
0xC007080A, /* shadow_color */
|
|
0xC05F697A /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_one_dark = {
|
|
0XFF98C379, /* hover_color */
|
|
0XFFBBBBBB, /* normal_color */
|
|
0XFFD19A66, /* title_color */
|
|
0xFF1B2929, /* bg_dark_color */
|
|
0xFF1B2929, /* bg_light_color */
|
|
0xFF364452, /* border_dark_color */
|
|
0xFF364452, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xFF44525F /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_palenight = {
|
|
0xFFC792EA, /* hover_color */
|
|
0xFFBFC7D5, /* normal_color */
|
|
0xFF82AAFF, /* title_color */
|
|
0xC02F3347, /* bg_dark_color */
|
|
0xC02F3347, /* bg_light_color */
|
|
0xC0697098, /* border_dark_color */
|
|
0xC0697098, /* border_light_color */
|
|
0xC00D0E14, /* shadow_color */
|
|
0xC0697098 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_palenight = {
|
|
0xFFC792EA, /* hover_color */
|
|
0xFFBFC7D5, /* normal_color */
|
|
0xFF82AAFF, /* title_color */
|
|
0xFF1B2936, /* bg_dark_color */
|
|
0xFF1B2936, /* bg_light_color */
|
|
0xFF51617A, /* border_dark_color */
|
|
0xFF51617A, /* border_light_color */
|
|
0xFF00000E, /* shadow_color */
|
|
0xFF525F7A /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_solarized_dark = {
|
|
0xFFB58900, /* hover_color */
|
|
0xFF839496, /* normal_color */
|
|
0xFF268BD2, /* title_color */
|
|
0xC0003542, /* bg_dark_color */
|
|
0xC0003542, /* bg_light_color */
|
|
0xC093A1A1, /* border_dark_color */
|
|
0xC093A1A1, /* border_light_color */
|
|
0xC000141A, /* shadow_color */
|
|
0xC0586E75 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_solarized_dark = {
|
|
0xFFB58900, /* hover_color */
|
|
0xFF839496, /* normal_color */
|
|
0xFF268BD2, /* title_color */
|
|
0xFF002936, /* bg_dark_color */
|
|
0xFF002936, /* bg_light_color */
|
|
0xFF7A8888, /* border_dark_color */
|
|
0xFF7A8888, /* border_light_color */
|
|
0xFF000E0E, /* shadow_color */
|
|
0xFF44525F /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_solarized_light = {
|
|
0xFFB58900, /* hover_color */
|
|
0xFF657B83, /* normal_color */
|
|
0xFF268BD2, /* title_color */
|
|
0xE0FDEDDF, /* bg_dark_color */
|
|
0xE0FDEDDF, /* bg_light_color */
|
|
0xE093A1A1, /* border_dark_color */
|
|
0xE093A1A1, /* border_light_color */
|
|
0xE0E0DBC9, /* shadow_color */
|
|
0xE0FFC5AD /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_solarized_light = {
|
|
0xFFB58900, /* hover_color */
|
|
0xFF657B83, /* normal_color */
|
|
0xFF268BD2, /* title_color */
|
|
0xFFEEDECE, /* bg_dark_color */
|
|
0xFFEEDECE, /* bg_light_color */
|
|
0xFF8F9F9F, /* border_dark_color */
|
|
0xFF8F9F9F, /* border_light_color */
|
|
0xFFDECEBE, /* shadow_color */
|
|
0xFFEEBE9F /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_tango_dark = {
|
|
0xFF8AE234, /* hover_color */
|
|
0xFFEEEEEC, /* normal_color */
|
|
0xFF729FCF, /* title_color */
|
|
0xC0384042, /* bg_dark_color */
|
|
0xC0384042, /* bg_light_color */
|
|
0xC06A767A, /* border_dark_color */
|
|
0xC06A767A, /* border_light_color */
|
|
0xC01A1A1A, /* shadow_color */
|
|
0xC0C4A000 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_tango_dark = {
|
|
0xFF8AE234, /* hover_color */
|
|
0xFFEEEEEC, /* normal_color */
|
|
0xFF729FCF, /* title_color */
|
|
0xFF293636, /* bg_dark_color */
|
|
0xFF293636, /* bg_light_color */
|
|
0xFF556160, /* border_dark_color */
|
|
0xFF556160, /* border_light_color */
|
|
0xFF0E0E0E, /* shadow_color */
|
|
0xFFA38800 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_tango_light = {
|
|
0xFF4E9A06, /* hover_color */
|
|
0xFF2E3436, /* normal_color */
|
|
0xFF204A87, /* title_color */
|
|
0xE0EEEEEC, /* bg_dark_color */
|
|
0xE0EEEEEC, /* bg_light_color */
|
|
0xE0C7C7C7, /* border_dark_color */
|
|
0xE0C7C7C7, /* border_light_color */
|
|
0xE0D3D7CF, /* shadow_color */
|
|
0xE0FFCA78 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_tango_light = {
|
|
0xFF4E9A06, /* hover_color */
|
|
0xFF2E3436, /* normal_color */
|
|
0xFF204A87, /* title_color */
|
|
0xFFDEDEDE, /* bg_dark_color */
|
|
0xFFDEDEDE, /* bg_light_color */
|
|
0xFFBEBEBE, /* border_dark_color */
|
|
0xFFBEBEBE, /* border_light_color */
|
|
0xFFCECEBE, /* shadow_color */
|
|
0xFFEEBE6F /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_zenburn = {
|
|
0xFFF0DFAF, /* hover_color */
|
|
0xFFDCDCCC, /* normal_color */
|
|
0xFF8FB28F, /* title_color */
|
|
0xC04F4F4F, /* bg_dark_color */
|
|
0xC04F4F4F, /* bg_light_color */
|
|
0xC0636363, /* border_dark_color */
|
|
0xC0636363, /* border_light_color */
|
|
0xC01F1F1F, /* shadow_color */
|
|
0xC0AC7373 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_zenburn = {
|
|
0xFFF0DFAF, /* hover_color */
|
|
0xFFDCDCCC, /* normal_color */
|
|
0xFF8FB28F, /* title_color */
|
|
0xFF363636, /* bg_dark_color */
|
|
0xFF363636, /* bg_light_color */
|
|
0xFF505050, /* border_dark_color */
|
|
0xFF505050, /* border_light_color */
|
|
0xFF0E0E0E, /* shadow_color */
|
|
0xFF885F5F /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_anti_zenburn = {
|
|
0xFF336C6C, /* hover_color */
|
|
0xFF232333, /* normal_color */
|
|
0xFF205070, /* title_color */
|
|
0xE0C0C0C0, /* bg_dark_color */
|
|
0xE0C0C0C0, /* bg_light_color */
|
|
0xE0A0A0A0, /* border_dark_color */
|
|
0xE0A0A0A0, /* border_light_color */
|
|
0xE0B0B0B0, /* shadow_color */
|
|
0xE0B090B0 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_anti_zenburn = {
|
|
0xFF336C6C, /* hover_color */
|
|
0xFF232333, /* normal_color */
|
|
0xFF205070, /* title_color */
|
|
0xFFBEBEBE, /* bg_dark_color */
|
|
0xFFBEBEBE, /* bg_light_color */
|
|
0xFF9F9F9F, /* border_dark_color */
|
|
0xFF9F9F9F, /* border_light_color */
|
|
0xFFAFAFAF, /* shadow_color */
|
|
0xFFAF8FAF /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_flux = {
|
|
0xFF6FCB9F, /* hover_color */
|
|
0xFF666547, /* normal_color */
|
|
0xFFFB2E01, /* title_color */
|
|
0xE0FFFEB3, /* bg_dark_color */
|
|
0xE0FFFEB3, /* bg_light_color */
|
|
0xE0FFE28A, /* border_dark_color */
|
|
0xE0FFE28A, /* border_light_color */
|
|
0xE0FFE28A, /* shadow_color */
|
|
0xE0FB2E01 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_flux = {
|
|
0xFF6FCB9F, /* hover_color */
|
|
0xFF666547, /* normal_color */
|
|
0xFFFB2E01, /* title_color */
|
|
0xFFEEEEAF, /* bg_dark_color */
|
|
0xFFEEEEAF, /* bg_light_color */
|
|
0xFFEEDE7F, /* border_dark_color */
|
|
0xFFEEDE7F, /* border_light_color */
|
|
0xFFEEDE7F, /* shadow_color */
|
|
0xFFEE2000 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_gray_dark = {
|
|
0xFFFFFFFF, /* hover_color */
|
|
0xFF808080, /* normal_color */
|
|
0xFFFFFFFF, /* title_color */
|
|
0xE0101010, /* bg_dark_color */
|
|
0xE0101010, /* bg_light_color */
|
|
0xE0202020, /* border_dark_color */
|
|
0xE0202020, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xE0202020 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_gray_dark = {
|
|
0xFFFFFFFF, /* hover_color */
|
|
0xFF808080, /* normal_color */
|
|
0xFFFFFFFF, /* title_color */
|
|
0xFF101010, /* bg_dark_color */
|
|
0xFF101010, /* bg_light_color */
|
|
0xFF202020, /* border_dark_color */
|
|
0xFF202020, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xE0202020 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_gray_light = {
|
|
0xFFFFFFFF, /* hover_color */
|
|
0xFF808080, /* normal_color */
|
|
0xFFFFFFFF, /* title_color */
|
|
0xE0202020, /* bg_dark_color */
|
|
0xE0202020, /* bg_light_color */
|
|
0xE0101010, /* border_dark_color */
|
|
0xE0101010, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xE0202020 /* particle_color */
|
|
};
|
|
|
|
static const rgui_theme_t rgui_theme_opaque_gray_light = {
|
|
0xFFFFFFFF, /* hover_color */
|
|
0xFF808080, /* normal_color */
|
|
0xFFFFFFFF, /* title_color */
|
|
0xFF202020, /* bg_dark_color */
|
|
0xFF202020, /* bg_light_color */
|
|
0xFF101010, /* border_dark_color */
|
|
0xFF101010, /* border_light_color */
|
|
0xFF000000, /* shadow_color */
|
|
0xE0202020 /* particle_color */
|
|
};
|
|
|
|
/* Particle effect animations update at a base rate
|
|
* of 60Hz (-> 16.666 ms update period) */
|
|
static const float particle_effect_period = (1.0f / 60.0f) * 1000.0f;
|
|
|
|
/* Cheap inline PRNG for the cosmetic particle effects. libc
|
|
* rand()/random() are ~10x slower than needed (call overhead +
|
|
* internal state/locking), random() is not portable, and the
|
|
* particle effects do not need their statistical quality. xorshift32
|
|
* is deterministic, multiply-free, has a single word of state, and
|
|
* inlines to register-only shift/xor. Returns [0, RGUI_RAND_MAX]. */
|
|
#define RGUI_RAND_MAX 0xFFFFFFFFu
|
|
|
|
static uint32_t rgui_rng_state = 0;
|
|
|
|
static INLINE uint32_t rgui_rand(void)
|
|
{
|
|
uint32_t x = rgui_rng_state;
|
|
/* Lazy seed; xorshift state must never be zero. */
|
|
if (!x)
|
|
{
|
|
x = (uint32_t)time(NULL) * 2654435761u;
|
|
if (!x)
|
|
x = 2463534242u;
|
|
}
|
|
x ^= x << 13;
|
|
x ^= x >> 17;
|
|
x ^= x << 5;
|
|
rgui_rng_state = x;
|
|
return x;
|
|
}
|
|
|
|
/* ==============================
|
|
* pixel format conversion START
|
|
* ============================== */
|
|
|
|
/* 8-bit -> N-bit channel quantisation.
|
|
*
|
|
* These formats reconstruct an N-bit value by bit replication: a 4-bit
|
|
* v is displayed as (v << 4) | v, i.e. v * 17, and a 5-bit v as
|
|
* v * 33 / 4. Quantising with a plain shift assumes a step of 16 (or
|
|
* 8) against a reconstruction spaced by 17 (or 33/4), which biases
|
|
* every channel downwards - 127 truncates to 7, shown as 119, when 8
|
|
* would show as 136 and 127 sits almost exactly between the two. The
|
|
* whole menu is slightly dark as a result.
|
|
*
|
|
* Divide by the actual step instead, rounding to nearest. */
|
|
static INLINE unsigned rgui_quant4(unsigned v)
|
|
{
|
|
unsigned q = ((v * 15) + 127) / 255;
|
|
return (q > 15) ? 15 : q;
|
|
}
|
|
|
|
static INLINE unsigned rgui_quant5(unsigned v)
|
|
{
|
|
unsigned q = ((v * 31) + 127) / 255;
|
|
return (q > 31) ? 31 : q;
|
|
}
|
|
|
|
static INLINE unsigned rgui_quant6(unsigned v)
|
|
{
|
|
unsigned q = ((v * 63) + 127) / 255;
|
|
return (q > 63) ? 63 : q;
|
|
}
|
|
|
|
/* Ordered (Bayer) dither threshold, 0..15 for a 4x4 cell.
|
|
*
|
|
* Rounding alone still lands every pixel of a slow gradient on the
|
|
* same level until the source crosses a step boundary, so the banding
|
|
* remains - 4 bits is only 16 levels. Dithering pushes pixels either
|
|
* side of the boundary in a fixed pattern, so the local average
|
|
* follows the source continuously even though no single pixel can.
|
|
* The eye integrates over the pattern and sees a smooth ramp.
|
|
*
|
|
* Only worth applying to photographic sources - thumbnails and
|
|
* wallpaper. A flat UI colour has no spatial extent to average
|
|
* over, so dithering it would just add visible noise. */
|
|
static const uint8_t rgui_bayer4x4[4][4] = {
|
|
{ 0, 8, 2, 10 },
|
|
{ 12, 4, 14, 6 },
|
|
{ 3, 11, 1, 9 },
|
|
{ 15, 7, 13, 5 }
|
|
};
|
|
|
|
static INLINE unsigned rgui_quant4_dither(unsigned v, unsigned x, unsigned y)
|
|
{
|
|
unsigned n = v * 15;
|
|
unsigned q = n / 255;
|
|
unsigned f = n % 255;
|
|
|
|
if ((f > ((unsigned)rgui_bayer4x4[y & 3][x & 3] * 255) / 16) && (q < 15))
|
|
q++;
|
|
|
|
return (q > 15) ? 15 : q;
|
|
}
|
|
|
|
static INLINE unsigned rgui_quant5_dither(unsigned v, unsigned x, unsigned y)
|
|
{
|
|
unsigned n = v * 31;
|
|
unsigned q = n / 255;
|
|
unsigned f = n % 255;
|
|
|
|
if ((f > ((unsigned)rgui_bayer4x4[y & 3][x & 3] * 255) / 16) && (q < 31))
|
|
q++;
|
|
|
|
return (q > 31) ? 31 : q;
|
|
}
|
|
|
|
static INLINE unsigned rgui_quant6_dither(unsigned v, unsigned x, unsigned y)
|
|
{
|
|
unsigned n = v * 63;
|
|
unsigned q = n / 255;
|
|
unsigned f = n % 255;
|
|
|
|
if ((f > ((unsigned)rgui_bayer4x4[y & 3][x & 3] * 255) / 16) && (q < 63))
|
|
q++;
|
|
|
|
return (q > 63) ? 63 : q;
|
|
}
|
|
|
|
/* PS2 */
|
|
static uint16_t argb32_to_abgr1555(uint32_t col)
|
|
{
|
|
/* Extract colour components */
|
|
unsigned a = (col >> 24) & 0xFF;
|
|
unsigned r = (col >> 16) & 0xFF;
|
|
unsigned g = (col >> 8) & 0xFF;
|
|
unsigned b = col & 0xFF;
|
|
if (a < 0xFF)
|
|
{
|
|
/* Background and border colours are normally semi-transparent
|
|
* (so we can see suspended content when opening the quick menu).
|
|
* When no content is loaded, the 'image' behind the RGUI background
|
|
* and border is black - which has the effect of darkening the
|
|
* perceived background/border colours. All the preset theme (and
|
|
* default 'custom') colour values have been adjusted to account for
|
|
* this, but abgr1555 only has a 1 bit alpha channel. This means all
|
|
* colours become fully opaque, and consequently backgrounds/borders
|
|
* become abnormally bright.
|
|
* We therefore have to darken each RGB value according to the alpha
|
|
* component of the input colour... */
|
|
float a_factor = (float)a * (1.0f / 255.0f);
|
|
r = (unsigned)(((float)r * a_factor) + 0.5f) & 0xFF;
|
|
g = (unsigned)(((float)g * a_factor) + 0.5f) & 0xFF;
|
|
b = (unsigned)(((float)b * a_factor) + 0.5f) & 0xFF;
|
|
}
|
|
/* Convert from 8 bit to 5 bit */
|
|
r = rgui_quant5(r);
|
|
g = rgui_quant5(g);
|
|
b = rgui_quant5(b);
|
|
/* Return final value - alpha always set to 1 */
|
|
return (1 << 15) | (b << 10) | (g << 5) | r;
|
|
}
|
|
|
|
/* GEKKO */
|
|
static uint16_t argb32_to_rgb5a3(uint32_t col)
|
|
{
|
|
/* Extract colour components */
|
|
unsigned a = (col >> 24) & 0xFF;
|
|
unsigned r = (col >> 16) & 0xFF;
|
|
unsigned g = (col >> 8) & 0xFF;
|
|
unsigned b = col & 0xFF;
|
|
unsigned a3 = a >> 5;
|
|
if (a < 0xFF)
|
|
{
|
|
/* Gekko platforms only have a 3 bit alpha channel, which
|
|
* is one bit less than all 'standard' target platforms.
|
|
* As a result, Gekko colours are effectively ~6-7% less
|
|
* transparent than expected, which causes backgrounds and
|
|
* borders to appear too bright. We therefore have to darken
|
|
* each RGB component according to the difference between Gekko
|
|
* alpha and normal 4 bit alpha values... */
|
|
unsigned a4 = a >> 4;
|
|
float a_factor = 1.0f;
|
|
if (a3 > 0) /* Avoid divide by zero errors... */
|
|
a_factor = ((float)a4 * (1.0f / 15.0f)) / ((float)a3 * (1.0f / 7.0f));
|
|
r = (unsigned)(((float)r * a_factor) + 0.5f);
|
|
g = (unsigned)(((float)g * a_factor) + 0.5f);
|
|
b = (unsigned)(((float)b * a_factor) + 0.5f);
|
|
/* a_factor can actually be greater than 1. This will never happen
|
|
* with the current preset theme colour values, but users can set
|
|
* any custom values they like, so we have to play it safe... */
|
|
if (r >= 0xFF)
|
|
r = 0xFF;
|
|
if (g >= 0xFF)
|
|
g = 0xFF;
|
|
if (b >= 0xFF)
|
|
b = 0xFF;
|
|
}
|
|
/* Convert RGB from 8 bit to 4 bit */
|
|
r = rgui_quant4(r);
|
|
g = rgui_quant4(g);
|
|
b = rgui_quant4(b);
|
|
/* Return final value */
|
|
return (a3 << 12) | (r << 8) | (g << 4) | b;
|
|
}
|
|
|
|
/* PSP */
|
|
static uint16_t argb32_to_abgr4444(uint32_t col)
|
|
{
|
|
unsigned a = rgui_quant4((col >> 24) & 0xFF);
|
|
unsigned r = rgui_quant4((col >> 16) & 0xFF);
|
|
unsigned g = rgui_quant4((col >> 8) & 0xFF);
|
|
unsigned b = rgui_quant4( col & 0xFF);
|
|
return (a << 12) | (b << 8) | (g << 4) | r;
|
|
}
|
|
|
|
/* PS3 */
|
|
static uint16_t argb32_to_argb4444(uint32_t col)
|
|
{
|
|
unsigned a = rgui_quant4((col >> 24) & 0xFF);
|
|
unsigned r = rgui_quant4((col >> 16) & 0xFF);
|
|
unsigned g = rgui_quant4((col >> 8) & 0xFF);
|
|
unsigned b = rgui_quant4( col & 0xFF);
|
|
return (a << 12) | (r << 8) | (g << 4) | b;
|
|
}
|
|
|
|
/* D3D10/11/12 */
|
|
static uint16_t argb32_to_bgra4444(uint32_t col)
|
|
{
|
|
unsigned a = rgui_quant4((col >> 24) & 0xFF);
|
|
unsigned r = rgui_quant4((col >> 16) & 0xFF);
|
|
unsigned g = rgui_quant4((col >> 8) & 0xFF);
|
|
unsigned b = rgui_quant4( col & 0xFF);
|
|
return (b << 12) | (g << 8) | (r << 4) | a;
|
|
}
|
|
|
|
/* DINGUX SDL */
|
|
static uint16_t argb32_to_rgb565(uint32_t col)
|
|
{
|
|
/* Extract colour components */
|
|
unsigned a = (col >> 24) & 0xFF;
|
|
unsigned r = (col >> 16) & 0xFF;
|
|
unsigned g = (col >> 8) & 0xFF;
|
|
unsigned b = col & 0xFF;
|
|
if (a < 0xFF)
|
|
{
|
|
/* RGB565 has no alpha component - as with PS2 colour conversion,
|
|
* have to darken each RGB value according to the alpha component
|
|
* of the input colour... */
|
|
float a_factor = (float)a * (1.0f / 255.0f);
|
|
r = (unsigned)(((float)r * a_factor) + 0.5f) & 0xFF;
|
|
g = (unsigned)(((float)g * a_factor) + 0.5f) & 0xFF;
|
|
b = (unsigned)(((float)b * a_factor) + 0.5f) & 0xFF;
|
|
}
|
|
/* Convert from 8 bit to 5/6 bit */
|
|
r = rgui_quant5(r);
|
|
g = rgui_quant6(g);
|
|
b = rgui_quant5(b);
|
|
/* Return final value */
|
|
return (r << 11) | (g << 5) | b;
|
|
}
|
|
|
|
/* All other platforms */
|
|
static uint16_t argb32_to_rgba4444(uint32_t col)
|
|
{
|
|
unsigned a = rgui_quant4((col >> 24) & 0xFF);
|
|
unsigned r = rgui_quant4((col >> 16) & 0xFF);
|
|
unsigned g = rgui_quant4((col >> 8) & 0xFF);
|
|
unsigned b = rgui_quant4( col & 0xFF);
|
|
return (r << 12) | (g << 8) | (b << 4) | a;
|
|
}
|
|
|
|
static uint16_t (*argb32_to_pixel_platform_format)(uint32_t col) = argb32_to_rgba4444;
|
|
|
|
/* Dithered variants, for photographic sources only (thumbnails and
|
|
* wallpaper). Identical to the plain conversions above except that
|
|
* the channel quantisation is dithered against the pixel position;
|
|
* see rgui_quant4_dither(). */
|
|
|
|
/* PS2 */
|
|
static uint16_t argb32_to_abgr1555_dither(uint32_t col,
|
|
unsigned x, unsigned y)
|
|
{
|
|
unsigned a = (col >> 24) & 0xFF;
|
|
unsigned r = (col >> 16) & 0xFF;
|
|
unsigned g = (col >> 8) & 0xFF;
|
|
unsigned b = col & 0xFF;
|
|
if (a < 0xFF)
|
|
{
|
|
float a_factor = (float)a * (1.0f / 255.0f);
|
|
r = (unsigned)(((float)r * a_factor) + 0.5f) & 0xFF;
|
|
g = (unsigned)(((float)g * a_factor) + 0.5f) & 0xFF;
|
|
b = (unsigned)(((float)b * a_factor) + 0.5f) & 0xFF;
|
|
}
|
|
r = rgui_quant5_dither(r, x, y);
|
|
g = rgui_quant5_dither(g, x, y);
|
|
b = rgui_quant5_dither(b, x, y);
|
|
return (1 << 15) | (b << 10) | (g << 5) | r;
|
|
}
|
|
|
|
/* GEKKO */
|
|
static uint16_t argb32_to_rgb5a3_dither(uint32_t col,
|
|
unsigned x, unsigned y)
|
|
{
|
|
unsigned a = (col >> 24) & 0xFF;
|
|
unsigned r = (col >> 16) & 0xFF;
|
|
unsigned g = (col >> 8) & 0xFF;
|
|
unsigned b = col & 0xFF;
|
|
unsigned a3 = a >> 5;
|
|
if (a < 0xFF)
|
|
{
|
|
unsigned a4 = a >> 4;
|
|
float a_factor = (a4 > 0)
|
|
? ((float)((a3 << 1) | (a3 >> 2)) / (float)a4)
|
|
: 1.0f;
|
|
r = (unsigned)(((float)r * a_factor) + 0.5f);
|
|
g = (unsigned)(((float)g * a_factor) + 0.5f);
|
|
b = (unsigned)(((float)b * a_factor) + 0.5f);
|
|
if (r >= 0xFF)
|
|
r = 0xFF;
|
|
if (g >= 0xFF)
|
|
g = 0xFF;
|
|
if (b >= 0xFF)
|
|
b = 0xFF;
|
|
}
|
|
r = rgui_quant4_dither(r, x, y);
|
|
g = rgui_quant4_dither(g, x, y);
|
|
b = rgui_quant4_dither(b, x, y);
|
|
return (a3 << 12) | (r << 8) | (g << 4) | b;
|
|
}
|
|
|
|
/* PSP */
|
|
static uint16_t argb32_to_abgr4444_dither(uint32_t col,
|
|
unsigned x, unsigned y)
|
|
{
|
|
unsigned a = rgui_quant4_dither((col >> 24) & 0xFF, x, y);
|
|
unsigned r = rgui_quant4_dither((col >> 16) & 0xFF, x, y);
|
|
unsigned g = rgui_quant4_dither((col >> 8) & 0xFF, x, y);
|
|
unsigned b = rgui_quant4_dither( col & 0xFF, x, y);
|
|
return (a << 12) | (b << 8) | (g << 4) | r;
|
|
}
|
|
|
|
/* PS3 */
|
|
static uint16_t argb32_to_argb4444_dither(uint32_t col,
|
|
unsigned x, unsigned y)
|
|
{
|
|
unsigned a = rgui_quant4_dither((col >> 24) & 0xFF, x, y);
|
|
unsigned r = rgui_quant4_dither((col >> 16) & 0xFF, x, y);
|
|
unsigned g = rgui_quant4_dither((col >> 8) & 0xFF, x, y);
|
|
unsigned b = rgui_quant4_dither( col & 0xFF, x, y);
|
|
return (a << 12) | (r << 8) | (g << 4) | b;
|
|
}
|
|
|
|
/* D3D10/11/12 */
|
|
static uint16_t argb32_to_bgra4444_dither(uint32_t col,
|
|
unsigned x, unsigned y)
|
|
{
|
|
unsigned a = rgui_quant4_dither((col >> 24) & 0xFF, x, y);
|
|
unsigned r = rgui_quant4_dither((col >> 16) & 0xFF, x, y);
|
|
unsigned g = rgui_quant4_dither((col >> 8) & 0xFF, x, y);
|
|
unsigned b = rgui_quant4_dither( col & 0xFF, x, y);
|
|
return (b << 12) | (g << 8) | (r << 4) | a;
|
|
}
|
|
|
|
/* DINGUX SDL */
|
|
static uint16_t argb32_to_rgb565_dither(uint32_t col,
|
|
unsigned x, unsigned y)
|
|
{
|
|
unsigned a = (col >> 24) & 0xFF;
|
|
unsigned r = (col >> 16) & 0xFF;
|
|
unsigned g = (col >> 8) & 0xFF;
|
|
unsigned b = col & 0xFF;
|
|
if (a < 0xFF)
|
|
{
|
|
float a_factor = (float)a * (1.0f / 255.0f);
|
|
r = (unsigned)(((float)r * a_factor) + 0.5f) & 0xFF;
|
|
g = (unsigned)(((float)g * a_factor) + 0.5f) & 0xFF;
|
|
b = (unsigned)(((float)b * a_factor) + 0.5f) & 0xFF;
|
|
}
|
|
r = rgui_quant5_dither(r, x, y);
|
|
g = rgui_quant6_dither(g, x, y);
|
|
b = rgui_quant5_dither(b, x, y);
|
|
return (r << 11) | (g << 5) | b;
|
|
}
|
|
|
|
/* All other platforms */
|
|
static uint16_t argb32_to_rgba4444_dither(uint32_t col,
|
|
unsigned x, unsigned y)
|
|
{
|
|
unsigned a = rgui_quant4_dither((col >> 24) & 0xFF, x, y);
|
|
unsigned r = rgui_quant4_dither((col >> 16) & 0xFF, x, y);
|
|
unsigned g = rgui_quant4_dither((col >> 8) & 0xFF, x, y);
|
|
unsigned b = rgui_quant4_dither( col & 0xFF, x, y);
|
|
return (r << 12) | (g << 8) | (b << 4) | a;
|
|
}
|
|
|
|
static uint16_t (*argb32_to_pixel_platform_format_dither)(
|
|
uint32_t col, unsigned x, unsigned y) = argb32_to_rgba4444_dither;
|
|
|
|
/* Per-driver RGUI pixel-format dispatch.
|
|
*
|
|
* Each entry maps a video driver ident to:
|
|
* - the conversion function used to produce the platform's
|
|
* 16bpp menu framebuffer format from the source ARGB32, and
|
|
* - whether that platform format carries usable alpha
|
|
* (i.e. supports framebuffer transparency in RGUI).
|
|
*
|
|
* The list is scanned in order; the first ident match wins. When
|
|
* adding a new driver, append a single entry here -- no other
|
|
* changes in this function are needed. Any driver not in the table
|
|
* gets the default fallback specified below the table. */
|
|
typedef struct
|
|
{
|
|
const char *driver_ident;
|
|
uint16_t (*conv)(uint32_t);
|
|
uint16_t (*conv_dither)(uint32_t, unsigned, unsigned);
|
|
bool transparency_supported;
|
|
} rgui_pixel_format_entry;
|
|
|
|
static const rgui_pixel_format_entry rgui_pixel_format_map[] =
|
|
{
|
|
{ "ps2", argb32_to_abgr1555, argb32_to_abgr1555_dither, false }, /* PS2 */
|
|
{ "gx", argb32_to_rgb5a3, argb32_to_rgb5a3_dither, true }, /* GEKKO */
|
|
{ "psp1", argb32_to_abgr4444, argb32_to_abgr4444_dither, true }, /* PSP */
|
|
{ "rsx", argb32_to_argb4444, argb32_to_argb4444_dither, true }, /* PS3 */
|
|
{ "d3d8", argb32_to_argb4444, argb32_to_argb4444_dither, true }, /* D3D8 (Original Xbox + legacy Windows) */
|
|
{ "d3d9_hlsl", argb32_to_argb4444, argb32_to_argb4444_dither, true }, /* D3D9 PC/Xbox 360 */
|
|
{ "d3d9_cg", argb32_to_argb4444, argb32_to_argb4444_dither, true }, /* D3D9 PC */
|
|
{ "d3d10", argb32_to_bgra4444, argb32_to_bgra4444_dither, true }, /* D3D10/11/12 */
|
|
{ "d3d11", argb32_to_bgra4444, argb32_to_bgra4444_dither, true },
|
|
{ "d3d12", argb32_to_bgra4444, argb32_to_bgra4444_dither, true },
|
|
{ "metal", argb32_to_bgra4444, argb32_to_bgra4444_dither, true }, /* Metal */
|
|
{ "sdl_dingux", argb32_to_rgb565, argb32_to_rgb565_dither, false }, /* DINGUX SDL */
|
|
{ "sdl_rs90", argb32_to_rgb565, argb32_to_rgb565_dither, false }
|
|
};
|
|
|
|
/* Returns true if current pixel format supports
|
|
* framebuffer transparency */
|
|
static bool rgui_set_pixel_format_function(void)
|
|
{
|
|
const char *driver_ident = video_driver_get_ident();
|
|
size_t i;
|
|
|
|
if (driver_ident && *driver_ident)
|
|
{
|
|
for (i = 0; i < ARRAY_SIZE(rgui_pixel_format_map); i++)
|
|
{
|
|
if (string_is_equal(driver_ident,
|
|
rgui_pixel_format_map[i].driver_ident))
|
|
{
|
|
argb32_to_pixel_platform_format =
|
|
rgui_pixel_format_map[i].conv;
|
|
argb32_to_pixel_platform_format_dither =
|
|
rgui_pixel_format_map[i].conv_dither;
|
|
return rgui_pixel_format_map[i].transparency_supported;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Default fallback for unknown / empty driver ident:
|
|
* RGBA4444 with transparency support. */
|
|
argb32_to_pixel_platform_format = argb32_to_rgba4444;
|
|
argb32_to_pixel_platform_format_dither = argb32_to_rgba4444_dither;
|
|
return true;
|
|
}
|
|
|
|
/* ==============================
|
|
* pixel format conversion END
|
|
* ============================== */
|
|
|
|
static void rgui_fonts_free(rgui_t *rgui)
|
|
{
|
|
if (!rgui)
|
|
return;
|
|
|
|
if (rgui->fonts.regular)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.regular);
|
|
rgui->fonts.regular = NULL;
|
|
}
|
|
|
|
#ifdef HAVE_LANGEXTRA
|
|
if (rgui->fonts.eng_6x10)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.eng_6x10);
|
|
rgui->fonts.eng_6x10 = NULL;
|
|
}
|
|
|
|
if (rgui->fonts.lse_6x10)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.lse_6x10);
|
|
rgui->fonts.lse_6x10 = NULL;
|
|
}
|
|
|
|
if (rgui->fonts.eng_10x10)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.eng_10x10);
|
|
rgui->fonts.eng_10x10 = NULL;
|
|
}
|
|
|
|
if (rgui->fonts.chn_10x10)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.chn_10x10);
|
|
rgui->fonts.chn_10x10 = NULL;
|
|
}
|
|
|
|
if (rgui->fonts.jpn_10x10)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.jpn_10x10);
|
|
rgui->fonts.jpn_10x10 = NULL;
|
|
}
|
|
|
|
if (rgui->fonts.kor_10x10)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.kor_10x10);
|
|
rgui->fonts.kor_10x10 = NULL;
|
|
}
|
|
|
|
if (rgui->fonts.rus_10x10)
|
|
{
|
|
bitmapfont_free_lut(rgui->fonts.rus_10x10);
|
|
rgui->fonts.rus_10x10 = NULL;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
static bool rgui_fonts_init(rgui_t *rgui)
|
|
{
|
|
#ifdef HAVE_LANGEXTRA
|
|
unsigned language = *msg_hash_get_uint(MSG_HASH_USER_LANGUAGE);
|
|
|
|
switch (language)
|
|
{
|
|
case RETRO_LANGUAGE_ENGLISH:
|
|
case RETRO_LANGUAGE_BRITISH_ENGLISH:
|
|
goto english;
|
|
|
|
case RETRO_LANGUAGE_FRENCH:
|
|
case RETRO_LANGUAGE_SPANISH:
|
|
case RETRO_LANGUAGE_GERMAN:
|
|
case RETRO_LANGUAGE_ITALIAN:
|
|
case RETRO_LANGUAGE_DUTCH:
|
|
case RETRO_LANGUAGE_PORTUGUESE_BRAZIL:
|
|
case RETRO_LANGUAGE_PORTUGUESE_PORTUGAL:
|
|
case RETRO_LANGUAGE_VIETNAMESE:
|
|
case RETRO_LANGUAGE_ASTURIAN:
|
|
case RETRO_LANGUAGE_FINNISH:
|
|
case RETRO_LANGUAGE_INDONESIAN:
|
|
case RETRO_LANGUAGE_SWEDISH:
|
|
case RETRO_LANGUAGE_CATALAN_VALENCIA:
|
|
case RETRO_LANGUAGE_CATALAN:
|
|
case RETRO_LANGUAGE_GALICIAN:
|
|
case RETRO_LANGUAGE_NORWEGIAN:
|
|
case RETRO_LANGUAGE_IRISH:
|
|
/* We have at least partial support for
|
|
* these languages, but extended ASCII
|
|
* is required */
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
configuration_set_bool(settings,
|
|
settings->bools.menu_rgui_extended_ascii, true);
|
|
rgui->flags |= RGUI_FLAG_EXTENDED_ASCII_ENABLE;
|
|
rgui->language = language;
|
|
goto english;
|
|
}
|
|
|
|
case RETRO_LANGUAGE_JAPANESE:
|
|
case RETRO_LANGUAGE_KOREAN:
|
|
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
|
|
case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
|
|
{
|
|
rgui->fonts.eng_10x10 = bitmapfont_10x10_load(RETRO_LANGUAGE_ENGLISH);
|
|
rgui->fonts.chn_10x10 = bitmapfont_10x10_load(RETRO_LANGUAGE_CHINESE_SIMPLIFIED);
|
|
rgui->fonts.jpn_10x10 = bitmapfont_10x10_load(RETRO_LANGUAGE_JAPANESE);
|
|
rgui->fonts.kor_10x10 = bitmapfont_10x10_load(RETRO_LANGUAGE_KOREAN);
|
|
|
|
if ( !rgui->fonts.eng_10x10
|
|
|| !rgui->fonts.chn_10x10
|
|
|| !rgui->fonts.jpn_10x10
|
|
|| !rgui->fonts.kor_10x10)
|
|
{
|
|
const char *_msg = msg_hash_to_str(MSG_RGUI_MISSING_FONTS);
|
|
rgui_fonts_free(rgui);
|
|
*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE) = RETRO_LANGUAGE_ENGLISH;
|
|
runloop_msg_queue_push(_msg, strlen(_msg), 1, 256, false, NULL,
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
goto english;
|
|
}
|
|
|
|
rgui->font_dims = VIDEO_SCALE_PACK(FONT_10X10_WIDTH,
|
|
FONT_10X10_HEIGHT);
|
|
rgui->font_width_stride = FONT_10X10_WIDTH_STRIDE;
|
|
rgui->font_height_stride = FONT_10X10_HEIGHT_STRIDE;
|
|
rgui->language = language;
|
|
break;
|
|
}
|
|
|
|
case RETRO_LANGUAGE_RUSSIAN:
|
|
case RETRO_LANGUAGE_BELARUSIAN:
|
|
{
|
|
rgui->fonts.eng_10x10 = bitmapfont_10x10_load(RETRO_LANGUAGE_ENGLISH);
|
|
rgui->fonts.rus_10x10 = bitmapfont_10x10_load(RETRO_LANGUAGE_RUSSIAN);
|
|
|
|
if ( !rgui->fonts.eng_10x10
|
|
|| !rgui->fonts.rus_10x10)
|
|
{
|
|
const char *_msg = msg_hash_to_str(MSG_RGUI_MISSING_FONTS);
|
|
rgui_fonts_free(rgui);
|
|
*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE) = RETRO_LANGUAGE_ENGLISH;
|
|
runloop_msg_queue_push(_msg, strlen(_msg), 1, 256, false, NULL,
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
goto english;
|
|
}
|
|
|
|
rgui->font_dims = VIDEO_SCALE_PACK(FONT_10X10_WIDTH,
|
|
FONT_10X10_HEIGHT);
|
|
rgui->font_width_stride = FONT_10X10_WIDTH_STRIDE;
|
|
rgui->font_height_stride = FONT_10X10_HEIGHT_STRIDE;
|
|
rgui->language = language;
|
|
break;
|
|
}
|
|
|
|
case RETRO_LANGUAGE_ESPERANTO:
|
|
case RETRO_LANGUAGE_POLISH:
|
|
case RETRO_LANGUAGE_TURKISH:
|
|
case RETRO_LANGUAGE_SLOVAK:
|
|
case RETRO_LANGUAGE_CZECH:
|
|
case RETRO_LANGUAGE_HUNGARIAN:
|
|
/* These languages are not yet implemented
|
|
case RETRO_LANGUAGE_ROMANIAN:
|
|
case RETRO_LANGUAGE_CROATIAN:
|
|
case RETRO_LANGUAGE_SERBIAN:
|
|
case RETRO_LANGUAGE_WELSH:
|
|
*/
|
|
/* 6x10 fonts, including:
|
|
* Latin Extended A + B
|
|
*
|
|
*/
|
|
{
|
|
rgui->fonts.eng_6x10 = bitmapfont_6x10_load(RETRO_LANGUAGE_ENGLISH);
|
|
rgui->fonts.lse_6x10 = bitmapfont_6x10_load(language);
|
|
|
|
if ( !rgui->fonts.eng_6x10
|
|
|| !rgui->fonts.lse_6x10)
|
|
{
|
|
const char *_msg = msg_hash_to_str(MSG_RGUI_MISSING_FONTS);
|
|
rgui_fonts_free(rgui);
|
|
*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE) = RETRO_LANGUAGE_ENGLISH;
|
|
runloop_msg_queue_push(_msg, strlen(_msg), 1, 256, false, NULL,
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
goto english;
|
|
}
|
|
|
|
rgui->font_dims = VIDEO_SCALE_PACK(FONT_6X10_WIDTH,
|
|
FONT_6X10_HEIGHT);
|
|
rgui->font_width_stride = FONT_6X10_WIDTH_STRIDE;
|
|
rgui->font_height_stride = FONT_6X10_HEIGHT_STRIDE;
|
|
rgui->language = language;
|
|
break;
|
|
}
|
|
|
|
case RETRO_LANGUAGE_ARABIC:
|
|
case RETRO_LANGUAGE_GREEK:
|
|
case RETRO_LANGUAGE_PERSIAN:
|
|
case RETRO_LANGUAGE_HEBREW:
|
|
default:
|
|
{
|
|
const char *_msg = msg_hash_to_str(MSG_RGUI_INVALID_LANGUAGE);
|
|
/* We do not have fonts for these
|
|
* languages - fallback to English */
|
|
*msg_hash_get_uint(MSG_HASH_USER_LANGUAGE) = RETRO_LANGUAGE_ENGLISH;
|
|
runloop_msg_queue_push(_msg, strlen(_msg), 1, 256, false, NULL,
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
goto english;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
|
|
english:
|
|
#endif
|
|
rgui->fonts.regular = bitmapfont_get_lut();
|
|
|
|
if (!rgui->fonts.regular)
|
|
return false;
|
|
|
|
if (rgui->fonts.regular->glyph_max <
|
|
(RGUI_NUM_FONT_GLYPHS_EXTENDED - 1))
|
|
{
|
|
rgui_fonts_free(rgui);
|
|
return false;
|
|
}
|
|
|
|
rgui->font_dims = VIDEO_SCALE_PACK(FONT_WIDTH, FONT_HEIGHT);
|
|
rgui->font_width_stride = FONT_WIDTH_STRIDE;
|
|
rgui->font_height_stride = FONT_HEIGHT_STRIDE;
|
|
|
|
rgui->language = RETRO_LANGUAGE_ENGLISH;
|
|
|
|
return true;
|
|
}
|
|
|
|
static void rgui_fill_rect(
|
|
uint16_t *data,
|
|
unsigned fb_dims,
|
|
unsigned x,
|
|
unsigned y,
|
|
unsigned width,
|
|
unsigned height,
|
|
uint16_t dark_color,
|
|
uint16_t light_color,
|
|
bool thickness)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
unsigned x_index, y_index;
|
|
uint16_t scanline_even[RGUI_MAX_FB_WIDTH]; /* Initial values don't matter here */
|
|
uint16_t scanline_odd[RGUI_MAX_FB_WIDTH];
|
|
unsigned x_start = (x <= fb_width) ? x : fb_width;
|
|
unsigned y_start = (y <= fb_height) ? y : fb_height;
|
|
unsigned x_end_i = x + width;
|
|
unsigned y_end_i = y + height;
|
|
/* Note: unlike rgui_color_rect() and rgui_draw_particle(),
|
|
* this function is frequently used to fill large areas.
|
|
* We therefore gain significant performance benefits
|
|
* from using memcpy() tricks... */
|
|
unsigned x_end = (x_end_i <= fb_width) ? x_end_i : fb_width;
|
|
unsigned y_end = (y_end_i <= fb_height) ? y_end_i : fb_height;
|
|
size_t x_size = (x_end - x_start) * sizeof(uint16_t);
|
|
|
|
/* Sanity check */
|
|
if (x_size == 0)
|
|
return;
|
|
|
|
/* If dark_color and light_color are the same,
|
|
* perform a solid fill */
|
|
if (dark_color == light_color)
|
|
{
|
|
uint16_t *src = scanline_even + x_start;
|
|
uint16_t *dst = data + x_start;
|
|
|
|
/* Populate source array */
|
|
for (x_index = x_start; x_index < x_end; x_index++)
|
|
*(scanline_even + x_index) = dark_color;
|
|
|
|
/* Fill destination array */
|
|
for (y_index = y_start; y_index < y_end; y_index++)
|
|
memcpy(dst + (y_index * fb_width), src, x_size);
|
|
}
|
|
else if (thickness)
|
|
{
|
|
uint16_t *src_a = NULL;
|
|
uint16_t *src_b = NULL;
|
|
uint16_t *src_c = NULL;
|
|
uint16_t *src_d = NULL;
|
|
uint16_t *dst = data + x_start;
|
|
|
|
/* Determine in which order the source arrays
|
|
* should be copied */
|
|
switch (y_start & 0x3)
|
|
{
|
|
case 0x1:
|
|
src_a = scanline_even + x_start;
|
|
src_b = scanline_odd + x_start;
|
|
src_c = src_b;
|
|
src_d = src_a;
|
|
break;
|
|
case 0x2:
|
|
src_a = scanline_odd + x_start;
|
|
src_b = src_a;
|
|
src_c = scanline_even + x_start;
|
|
src_d = src_c;
|
|
break;
|
|
case 0x3:
|
|
src_a = scanline_odd + x_start;
|
|
src_b = scanline_even + x_start;
|
|
src_c = src_b;
|
|
src_d = src_a;
|
|
break;
|
|
case 0x0:
|
|
default:
|
|
src_a = scanline_even + x_start;
|
|
src_b = src_a;
|
|
src_c = scanline_odd + x_start;
|
|
src_d = src_c;
|
|
break;
|
|
}
|
|
|
|
/* Populate source arrays */
|
|
for (x_index = x_start; x_index < x_end; x_index++)
|
|
{
|
|
bool x_is_even = (((x_index >> 1) & 1) == 0);
|
|
*(scanline_even + x_index) = x_is_even ? dark_color : light_color;
|
|
*(scanline_odd + x_index) = x_is_even ? light_color : dark_color;
|
|
}
|
|
|
|
/* Fill destination array */
|
|
for (y_index = y_start ; y_index < y_end; y_index += 4)
|
|
memcpy(dst + (y_index * fb_width), src_a, x_size);
|
|
|
|
for (y_index = y_start + 1; y_index < y_end; y_index += 4)
|
|
memcpy(dst + (y_index * fb_width), src_b, x_size);
|
|
|
|
for (y_index = y_start + 2; y_index < y_end; y_index += 4)
|
|
memcpy(dst + (y_index * fb_width), src_c, x_size);
|
|
|
|
for (y_index = y_start + 3; y_index < y_end; y_index += 4)
|
|
memcpy(dst + (y_index * fb_width), src_d, x_size);
|
|
}
|
|
else
|
|
{
|
|
uint16_t *src_a = NULL;
|
|
uint16_t *src_b = NULL;
|
|
uint16_t *dst = data + x_start;
|
|
|
|
/* Determine in which order the source arrays
|
|
* should be copied */
|
|
if ((y_start & 1) == 0)
|
|
{
|
|
src_a = scanline_even + x_start;
|
|
src_b = scanline_odd + x_start;
|
|
}
|
|
else
|
|
{
|
|
src_a = scanline_odd + x_start;
|
|
src_b = scanline_even + x_start;
|
|
}
|
|
|
|
/* Populate source arrays */
|
|
for (x_index = x_start; x_index < x_end; x_index++)
|
|
{
|
|
bool x_is_even = ((x_index & 1) == 0);
|
|
*(scanline_even + x_index) = x_is_even ? dark_color : light_color;
|
|
*(scanline_odd + x_index) = x_is_even ? light_color : dark_color;
|
|
}
|
|
|
|
/* Fill destination array */
|
|
for (y_index = y_start ; y_index < y_end; y_index += 2)
|
|
memcpy(dst + (y_index * fb_width), src_a, x_size);
|
|
|
|
for (y_index = y_start + 1; y_index < y_end; y_index += 2)
|
|
memcpy(dst + (y_index * fb_width), src_b, x_size);
|
|
}
|
|
}
|
|
|
|
static void rgui_color_rect(
|
|
uint16_t *data,
|
|
unsigned fb_dims,
|
|
unsigned x,
|
|
unsigned y,
|
|
unsigned width,
|
|
unsigned height,
|
|
uint16_t color)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
unsigned x_index, y_index;
|
|
unsigned x_start = (x <= fb_width) ? x : fb_width;
|
|
unsigned y_start = (y <= fb_height) ? y : fb_height;
|
|
unsigned x_end = x + width;
|
|
unsigned y_end = y + height;
|
|
|
|
if (x_end > fb_width)
|
|
x_end = fb_width;
|
|
if (y_end > fb_height)
|
|
y_end = fb_height;
|
|
|
|
for (y_index = y_start; y_index < y_end; y_index++)
|
|
{
|
|
uint16_t *data_ptr = data + (y_index * fb_width);
|
|
for (x_index = x_start; x_index < x_end; x_index++)
|
|
*(data_ptr + x_index) = color;
|
|
}
|
|
}
|
|
|
|
/* Force a render phase out of line even though it has a single call
|
|
* site. Follows the RXML_NOINLINE precedent in
|
|
* libretro-common/formats/xml/rxml.c.
|
|
*
|
|
* rgui_render() is already factored into named phases, but at -O3 the
|
|
* ones called exactly once are all inlined straight back into it,
|
|
* producing a single 25 KB function -- about 80% of a 32 KB L1i on its
|
|
* own, entered every frame -- where most of the code belongs to
|
|
* branches that are not taken on a given frame. Keeping the phases
|
|
* separate costs one call each and lets the fall-through path stay
|
|
* resident. Under -Os the compiler already optimises for size and the
|
|
* forced outlining only adds call overhead, so it is disabled. */
|
|
#if defined(__OPTIMIZE_SIZE__)
|
|
#define RGUI_NOINLINE
|
|
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
|
|
#define RGUI_NOINLINE __attribute__((noinline))
|
|
#elif defined(_MSC_VER)
|
|
#define RGUI_NOINLINE __declspec(noinline)
|
|
#else
|
|
#define RGUI_NOINLINE
|
|
#endif
|
|
|
|
static void rgui_render_border(
|
|
rgui_t *rgui,
|
|
uint16_t *data,
|
|
unsigned fb_dims)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
uint16_t dark_color = rgui->colors.border_dark_color;
|
|
uint16_t light_color = rgui->colors.border_light_color;
|
|
bool thickness = (rgui->flags & RGUI_FLAG_BORDER_THICKNESS) ? true : false;
|
|
|
|
/* Draw border */
|
|
rgui_fill_rect(data, fb_dims,
|
|
5, 5, fb_width - 10, 5,
|
|
dark_color, light_color, thickness);
|
|
rgui_fill_rect(data, fb_dims,
|
|
5, fb_height - 10, fb_width - 10, 5,
|
|
dark_color, light_color, thickness);
|
|
rgui_fill_rect(data, fb_dims,
|
|
5, 5, 5, fb_height - 10,
|
|
dark_color, light_color, thickness);
|
|
rgui_fill_rect(data, fb_dims,
|
|
fb_width - 10, 5, 5, fb_height - 10,
|
|
dark_color, light_color, thickness);
|
|
|
|
/* Draw drop shadow, if required */
|
|
if (rgui->flags & RGUI_FLAG_SHADOW_ENABLE)
|
|
{
|
|
uint16_t shadow_color = rgui->colors.shadow_color;
|
|
|
|
rgui_color_rect(data, fb_dims,
|
|
10, 10, 1, fb_height - 20, shadow_color);
|
|
rgui_color_rect(data, fb_dims,
|
|
10, 10, fb_width - 20, 1, shadow_color);
|
|
rgui_color_rect(data, fb_dims,
|
|
fb_width - 5, 6, 1, fb_height - 10, shadow_color);
|
|
rgui_color_rect(data, fb_dims,
|
|
6, fb_height - 5, fb_width - 10, 1, shadow_color);
|
|
}
|
|
}
|
|
|
|
/* Returns true if particle is on screen */
|
|
static INLINE bool rgui_draw_particle(
|
|
uint16_t *data,
|
|
unsigned fb_dims,
|
|
int x,
|
|
int y,
|
|
unsigned width,
|
|
unsigned height,
|
|
uint16_t color)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
unsigned x_index, y_index;
|
|
|
|
/* This great convoluted mess just saves us
|
|
* having to perform comparisons on every
|
|
* iteration of the for loops... */
|
|
unsigned x_start_i = (x > 0) ? x : 0;
|
|
unsigned y_start_i = (y > 0) ? y : 0;
|
|
int x_end = x + width;
|
|
int y_end = y + height;
|
|
int x_start = (x_start_i <= fb_width) ? x_start_i : fb_width;
|
|
int y_start = (y_start_i <= fb_height) ? y_start_i : fb_height;
|
|
|
|
if (x_end <= 0)
|
|
x_end = 0;
|
|
else if (x_end > (int)fb_width)
|
|
x_end = fb_width;
|
|
|
|
if (y_end <= 0)
|
|
y_end = 0;
|
|
else if (y_end > (int)fb_height)
|
|
y_end = fb_height;
|
|
|
|
for (y_index = (unsigned)y_start; y_index < (unsigned)y_end; y_index++)
|
|
{
|
|
uint16_t *data_ptr = data + (y_index * fb_width);
|
|
for (x_index = (unsigned)x_start; x_index < (unsigned)x_end; x_index++)
|
|
*(data_ptr + x_index) = color;
|
|
}
|
|
|
|
return (x_end > x_start) && (y_end > y_start);
|
|
}
|
|
|
|
static void rgui_init_particle_effect(
|
|
rgui_t *rgui,
|
|
gfx_display_t *p_disp)
|
|
{
|
|
size_t i;
|
|
unsigned fb_width = VIDEO_SCALE_W(p_disp->framebuf_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(p_disp->framebuf_dims);
|
|
|
|
switch (rgui->particle_effect)
|
|
{
|
|
case RGUI_PARTICLE_EFFECT_SNOW:
|
|
case RGUI_PARTICLE_EFFECT_SNOW_ALT:
|
|
{
|
|
for (i = 0; i < RGUI_NUM_PARTICLES; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
particle->a = (float)(rgui_rand() % fb_width);
|
|
particle->b = (float)(rgui_rand() % fb_height);
|
|
particle->c = (float)(rgui_rand() % 64 - 16) * 0.1f;
|
|
particle->d = (float)(rgui_rand() % 64 - 48) * 0.1f;
|
|
}
|
|
}
|
|
break;
|
|
case RGUI_PARTICLE_EFFECT_RAIN:
|
|
{
|
|
uint8_t weights[] = { /* 60 entries */
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
5, 5, 5, 5, 5, 5, 5, 5,
|
|
6, 6, 6, 6, 6, 6,
|
|
7, 7, 7, 7,
|
|
8, 8, 8,
|
|
9, 9,
|
|
10};
|
|
unsigned num_drops = (unsigned)(0.85f * ((float)fb_width / (float)RGUI_MAX_FB_WIDTH) * (float)RGUI_NUM_PARTICLES);
|
|
if (num_drops >= RGUI_NUM_PARTICLES)
|
|
num_drops = RGUI_NUM_PARTICLES;
|
|
|
|
for (i = 0; i < num_drops; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
/* x pos */
|
|
particle->a = (float)(rgui_rand() % (fb_width / 3)) * 3.0f;
|
|
/* y pos */
|
|
particle->b = (float)(rgui_rand() % fb_height);
|
|
/* drop length */
|
|
particle->c = (float)weights[(unsigned)(rgui_rand() % 60)];
|
|
/* drop speed (larger drops fall faster) */
|
|
particle->d = (particle->c / 12.0f) * (0.5f + ((float)(rgui_rand() % 150) / 200.0f));
|
|
}
|
|
}
|
|
break;
|
|
case RGUI_PARTICLE_EFFECT_VORTEX:
|
|
{
|
|
float max_radius = (float)sqrt((double)((fb_width * fb_width) + (fb_height * fb_height))) / 2.0f;
|
|
float one_degree_radians = PI / 360.0f;
|
|
|
|
for (i = 0; i < RGUI_NUM_PARTICLES; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
/* radius */
|
|
particle->a = 1.0f + (((float)rgui_rand() / (float)RGUI_RAND_MAX) * max_radius);
|
|
/* theta */
|
|
particle->b = ((float)rgui_rand() / (float)RGUI_RAND_MAX) * 2.0f * PI;
|
|
/* radial speed */
|
|
particle->c = (float)((rgui_rand() % 100) + 1) * 0.001f;
|
|
/* rotational speed */
|
|
particle->d = (((float)((rgui_rand() % 50) + 1) / 200.0f) + 0.1f) * one_degree_radians;
|
|
}
|
|
}
|
|
break;
|
|
case RGUI_PARTICLE_EFFECT_STARFIELD:
|
|
{
|
|
for (i = 0; i < RGUI_NUM_PARTICLES; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
/* x pos */
|
|
particle->a = (float)(rgui_rand() % fb_width);
|
|
/* y pos */
|
|
particle->b = (float)(rgui_rand() % fb_height);
|
|
/* depth */
|
|
particle->c = (float)fb_width;
|
|
/* speed */
|
|
particle->d = 1.0f + ((float)(rgui_rand() % 20) * 0.01f);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
/* Do nothing... */
|
|
break;
|
|
}
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_render_particle_effect(
|
|
rgui_t *rgui,
|
|
gfx_animation_t *p_anim,
|
|
uint16_t *frame_buf_data,
|
|
float particle_effect_speed,
|
|
bool particle_effect_screensaver,
|
|
unsigned fb_dims)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
size_t i;
|
|
uint16_t particle_color;
|
|
/* Give speed factor a long, awkward name to minimise
|
|
* risk of clashing with specific particle effect
|
|
* implementation variables... */
|
|
float global_speed_factor = 1.0f;
|
|
|
|
/* Check whether screensaver is currently active */
|
|
if (rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER)
|
|
{
|
|
/* Return early if screensaver animation is
|
|
* disabled */
|
|
if (!particle_effect_screensaver)
|
|
return;
|
|
particle_color = rgui->colors.ss_particle_color;
|
|
}
|
|
else
|
|
particle_color = rgui->colors.particle_color;
|
|
|
|
/* Adjust global animation speed */
|
|
/* > Apply user configured speed multiplier */
|
|
if (particle_effect_speed > 0.0001f)
|
|
global_speed_factor = particle_effect_speed;
|
|
|
|
/* > Account for non-standard frame times
|
|
* (high/low refresh rates, or frame drops) */
|
|
global_speed_factor *= p_anim->delta_time / particle_effect_period;
|
|
|
|
/* Note: It would be more elegant to have 'update' and 'draw'
|
|
* as separate functions, since 'update' is the part that
|
|
* varies with particle effect whereas 'draw' is always
|
|
* pretty much the same. However, this has the following
|
|
* disadvantages:
|
|
* - It means we have to loop through all particles twice,
|
|
* and given that we're already using a heap of CPU cycles
|
|
* to draw these effects any further performance overheads
|
|
* are to be avoided
|
|
* - It locks us into a particular draw style. e.g. What if
|
|
* an effect calls for round particles, instead of square
|
|
* ones? This would make a mess of any 'standardised'
|
|
* drawing
|
|
* So we go with the simple option of having the entire
|
|
* update/draw sequence here. This results in some code
|
|
* repetition, but it has better performance and allows for
|
|
* complete flexibility */
|
|
|
|
switch (rgui->particle_effect)
|
|
{
|
|
case RGUI_PARTICLE_EFFECT_SNOW:
|
|
case RGUI_PARTICLE_EFFECT_SNOW_ALT:
|
|
{
|
|
unsigned particle_size;
|
|
bool on_screen;
|
|
|
|
for (i = 0; i < RGUI_NUM_PARTICLES; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
/* Update particle 'speed' */
|
|
particle->c = particle->c + (float)(rgui_rand() % 16 - 9) * 0.01f;
|
|
particle->d = particle->d + (float)(rgui_rand() % 16 - 7) * 0.01f;
|
|
|
|
if (particle->c < -0.4f)
|
|
particle->c = -0.4f;
|
|
else if (particle->c > 0.1f)
|
|
particle->c = 0.1f;
|
|
|
|
if (particle->d < -0.1f)
|
|
particle->d = -0.1f;
|
|
else if (particle->d > 0.4f)
|
|
particle->d = 0.4f;
|
|
|
|
/* Update particle location */
|
|
particle->a = fmod(particle->a + (global_speed_factor * particle->c), fb_width);
|
|
particle->b = fmod(particle->b + (global_speed_factor * particle->d), fb_height);
|
|
|
|
/* Get particle size */
|
|
particle_size = 1;
|
|
if (rgui->particle_effect == RGUI_PARTICLE_EFFECT_SNOW_ALT)
|
|
{
|
|
/* Gives the following distribution:
|
|
* 1x1: 96
|
|
* 2x2: 128
|
|
* 3x3: 32 */
|
|
if (!(i & 0x2))
|
|
particle_size = 2;
|
|
else if ((i & 0x7) == 0x7)
|
|
particle_size = 3;
|
|
}
|
|
|
|
/* Draw particle */
|
|
on_screen = rgui_draw_particle(frame_buf_data, fb_dims,
|
|
(int)particle->a, (int)particle->b,
|
|
particle_size, particle_size, particle_color);
|
|
|
|
/* Reset particle if it has fallen off screen */
|
|
if (!on_screen)
|
|
{
|
|
if (particle->a < 0.0f)
|
|
particle->a = (particle->a + (float)fb_width);
|
|
if (particle->b < 0.0f)
|
|
particle->b = (particle->b + (float)fb_height);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case RGUI_PARTICLE_EFFECT_RAIN:
|
|
{
|
|
uint8_t weights[] = { /* 60 entries */
|
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
5, 5, 5, 5, 5, 5, 5, 5,
|
|
6, 6, 6, 6, 6, 6,
|
|
7, 7, 7, 7,
|
|
8, 8, 8,
|
|
9, 9,
|
|
10};
|
|
bool on_screen = false;
|
|
unsigned num_drops = (unsigned)(0.85f * ((float)fb_width / (float)RGUI_MAX_FB_WIDTH) * (float)RGUI_NUM_PARTICLES);
|
|
if (num_drops >= RGUI_NUM_PARTICLES)
|
|
num_drops = RGUI_NUM_PARTICLES;
|
|
|
|
for (i = 0; i < num_drops; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
/* Draw particle */
|
|
on_screen = rgui_draw_particle(
|
|
frame_buf_data, fb_dims,
|
|
(int)particle->a, (int)particle->b,
|
|
2, (unsigned)particle->c, particle_color);
|
|
|
|
/* Update y pos */
|
|
particle->b += particle->d * global_speed_factor;
|
|
|
|
/* Reset particle if it has fallen off
|
|
the bottom of the screen */
|
|
if (!on_screen)
|
|
{
|
|
/* x pos */
|
|
particle->a = (float)(rgui_rand() % (fb_width / 3)) * 3.0f;
|
|
/* y pos */
|
|
particle->b = 0.0f;
|
|
/* drop length */
|
|
particle->c = (float)weights[(unsigned)(rgui_rand() % 60)];
|
|
/* drop speed (larger drops fall faster) */
|
|
particle->d = (particle->c / 12.0f) * (0.5f + ((float)(rgui_rand() % 150) / 200.0f));
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case RGUI_PARTICLE_EFFECT_VORTEX:
|
|
{
|
|
float max_radius = (float)sqrt((double)((fb_width * fb_width) + (fb_height * fb_height))) / 2.0f;
|
|
float one_degree_radians = PI / 360.0f;
|
|
int x_centre = (int)(fb_width >> 1);
|
|
int y_centre = (int)(fb_height >> 1);
|
|
unsigned particle_size;
|
|
float r_speed, theta_speed;
|
|
int x, y;
|
|
|
|
for (i = 0; i < RGUI_NUM_PARTICLES; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
/* Get particle location */
|
|
x = (int)(particle->a * cos(particle->b)) + x_centre;
|
|
y = (int)(particle->a * sin(particle->b)) + y_centre;
|
|
|
|
/* Get particle size */
|
|
particle_size = 1 + (unsigned)(((1.0f - ((max_radius - particle->a) / max_radius)) * 3.5f) + 0.5f);
|
|
|
|
/* Draw particle */
|
|
rgui_draw_particle(frame_buf_data, fb_dims,
|
|
x, y, particle_size, particle_size, particle_color);
|
|
|
|
/* Update particle speed */
|
|
r_speed = particle->c * global_speed_factor;
|
|
theta_speed = particle->d * global_speed_factor;
|
|
if ((particle->a > 0.0f) && (particle->a < (float)fb_height))
|
|
{
|
|
float base_scale_factor = ((float)fb_height - particle->a) / (float)fb_height;
|
|
r_speed *= 1.0f + (base_scale_factor * 8.0f);
|
|
theta_speed *= 1.0f + (base_scale_factor * base_scale_factor * 6.0f);
|
|
}
|
|
particle->a -= r_speed;
|
|
particle->b += theta_speed;
|
|
|
|
/* Reset particle if it has reached the centre of the screen */
|
|
if (particle->a < 0.0f)
|
|
{
|
|
/* radius
|
|
* Note: In theory, this should be:
|
|
* > particle->a = max_radius;
|
|
* ...but it turns out that spawning new particles at random
|
|
* locations produces a more visually appealing result... */
|
|
particle->a = 1.0f + (((float)rgui_rand() / (float)RGUI_RAND_MAX) * max_radius);
|
|
/* theta */
|
|
particle->b = ((float)rgui_rand() / (float)RGUI_RAND_MAX) * 2.0f * PI;
|
|
/* radial speed */
|
|
particle->c = (float)((rgui_rand() % 100) + 1) * 0.001f;
|
|
/* rotational speed */
|
|
particle->d = (((float)((rgui_rand() % 50) + 1) / 200.0f) + 0.1f) * one_degree_radians;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case RGUI_PARTICLE_EFFECT_STARFIELD:
|
|
{
|
|
float focal_length = (float)fb_width * 2.0f;
|
|
int x_centre = (int)(fb_width >> 1);
|
|
int y_centre = (int)(fb_height >> 1);
|
|
unsigned particle_size;
|
|
int x, y;
|
|
bool on_screen;
|
|
|
|
/* Based on an example found here:
|
|
* https://codepen.io/nodws/pen/pejBNb */
|
|
for (i = 0; i < RGUI_NUM_PARTICLES; i++)
|
|
{
|
|
rgui_particle_t *particle = &rgui->particles[i];
|
|
|
|
/* Get particle location */
|
|
x = (int)((particle->a - (float)x_centre) * (focal_length / particle->c));
|
|
x += x_centre;
|
|
|
|
y = (int)((particle->b - (float)y_centre) * (focal_length / particle->c));
|
|
y += y_centre;
|
|
|
|
/* Get particle size */
|
|
particle_size = (unsigned)(focal_length / (2.0f * particle->c));
|
|
|
|
/* Draw particle */
|
|
on_screen = rgui_draw_particle(frame_buf_data, fb_dims,
|
|
x, y, particle_size, particle_size, particle_color);
|
|
|
|
/* Update depth */
|
|
particle->c -= particle->d * global_speed_factor;
|
|
|
|
/* Reset particle if it has:
|
|
* - Dropped off the edge of the screen
|
|
* - Reached the screen depth
|
|
* - Grown larger than 16 pixels across
|
|
* (this is an arbitrary limit, set to reduce overall
|
|
* performance impact - i.e. larger particles are slower
|
|
* to draw, and without setting a limit they can fill the screen...) */
|
|
if (!on_screen || (particle->c <= 0.0f) || particle_size > 16)
|
|
{
|
|
/* x pos */
|
|
particle->a = (float)(rgui_rand() % fb_width);
|
|
/* y pos */
|
|
particle->b = (float)(rgui_rand() % fb_height);
|
|
/* depth */
|
|
particle->c = (float)fb_width;
|
|
/* speed */
|
|
particle->d = 1.0f + ((float)(rgui_rand() % 20) * 0.01f);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
/* Do nothing... */
|
|
break;
|
|
}
|
|
|
|
/* If border is enabled, it must be drawn *above*
|
|
* particle effect
|
|
* (Wastes CPU cycles, but nothing we can do about it...) */
|
|
if ( (rgui->flags & RGUI_FLAG_BORDER_ENABLE)
|
|
&& (!(rgui->flags & RGUI_FLAG_SHOW_WALLPAPER))
|
|
&& (!(rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER)))
|
|
rgui_render_border(rgui, frame_buf_data, fb_dims);
|
|
}
|
|
|
|
static void rgui_process_wallpaper(
|
|
rgui_t *rgui,
|
|
struct texture_image *image)
|
|
{
|
|
unsigned x, y;
|
|
unsigned x_crop_offset;
|
|
unsigned y_crop_offset;
|
|
settings_t *settings = config_get_ptr();
|
|
bool dither = settings->bools.menu_rgui_thumbnail_dither;
|
|
frame_buf_t *background_buf = &rgui->background_buf;
|
|
|
|
/* Sanity check */
|
|
if ( (!image->pixels)
|
|
|| (image->width < background_buf->width)
|
|
|| (image->height < background_buf->height)
|
|
|| (!background_buf->data))
|
|
return;
|
|
|
|
/* In most cases, image size will be identical
|
|
* to wallpaper buffer size - but wallpaper buffer
|
|
* will be smaller than expected if:
|
|
* - This is a GEKKO platform (these only support
|
|
* a 16:9 framebuffer width of 424 instead of
|
|
* the usual 426...)
|
|
* - The current display resolution is less than
|
|
* 240p - in which case, the framebuffer will
|
|
* scale down to a minimum of 192p
|
|
* If the wallpaper buffer is undersized, we have
|
|
* to crop the source image */
|
|
x_crop_offset = (image->width - background_buf->width) >> 1;
|
|
y_crop_offset = (image->height - background_buf->height) >> 1;
|
|
|
|
/* Copy image to wallpaper buffer, performing pixel format conversion.
|
|
* Both buffers are row-major, so iterate rows in the outer loop to
|
|
* keep source and destination accesses sequential. */
|
|
for (y = 0; y < background_buf->height; y++)
|
|
{
|
|
uint16_t *dst = background_buf->data + y * background_buf->width;
|
|
const uint32_t *src = image->pixels + x_crop_offset
|
|
+ (y + y_crop_offset) * image->width;
|
|
if (dither)
|
|
{
|
|
for (x = 0; x < background_buf->width; x++)
|
|
dst[x] = argb32_to_pixel_platform_format_dither(src[x], x, y);
|
|
}
|
|
else
|
|
{
|
|
for (x = 0; x < background_buf->width; x++)
|
|
dst[x] = argb32_to_pixel_platform_format(src[x]);
|
|
}
|
|
}
|
|
|
|
/* Tell menu that a display update is required */
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW
|
|
| RGUI_FLAG_SHOW_WALLPAPER;
|
|
}
|
|
|
|
static void rgui_handle_thumbnail_upload(
|
|
retro_task_t *task,
|
|
void *task_data,
|
|
void *user_data, const char *err)
|
|
{
|
|
menu_display_common_image_upload(
|
|
(struct texture_image*)task_data,
|
|
user_data,
|
|
MENU_IMAGE_THUMBNAIL);
|
|
}
|
|
|
|
static void rgui_handle_left_thumbnail_upload(
|
|
retro_task_t *task,
|
|
void *task_data,
|
|
void *user_data, const char *err)
|
|
{
|
|
menu_display_common_image_upload(
|
|
(struct texture_image*)task_data,
|
|
user_data,
|
|
MENU_IMAGE_LEFT_THUMBNAIL);
|
|
}
|
|
|
|
static bool rgui_request_thumbnail(
|
|
thumbnail_t *thumbnail,
|
|
enum gfx_thumbnail_id thumbnail_id,
|
|
uint32_t *queue_size,
|
|
const char *path,
|
|
bool *file_missing)
|
|
{
|
|
/* Do nothing if current thumbnail path hasn't changed */
|
|
if ((path && *path) && *thumbnail->path)
|
|
if (string_is_equal(thumbnail->path, path))
|
|
return true;
|
|
|
|
/* 'Reset' current thumbnail */
|
|
thumbnail->dims = 0;
|
|
thumbnail->is_valid = false;
|
|
thumbnail->path[0] = '\0';
|
|
|
|
/* Ensure that new path is valid... */
|
|
if (path && *path)
|
|
{
|
|
strlcpy(thumbnail->path, path, sizeof(thumbnail->path));
|
|
if (path_is_valid(path))
|
|
{
|
|
if (image_texture_get_type(path) == IMAGE_TYPE_MP4
|
|
|| image_texture_get_type(path) == IMAGE_TYPE_WEBM)
|
|
return true;
|
|
/* Would like to cancel any existing image load tasks
|
|
* here, but can't see how to do it... */
|
|
if (task_push_image_load(thumbnail->path,
|
|
gfx_surface_wants_rgba(),
|
|
0,
|
|
0,
|
|
(thumbnail_id == GFX_THUMBNAIL_LEFT)
|
|
? rgui_handle_left_thumbnail_upload
|
|
: rgui_handle_thumbnail_upload,
|
|
NULL))
|
|
{
|
|
*queue_size = *queue_size + 1;
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
*file_missing = true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/* TODO/FIXME - we can remove the dependency on rgui struct here */
|
|
|
|
/* Integer box decimate by 'f', averaging f*f ARGB8888 pixels.
|
|
*
|
|
* RGUI reduces thumbnails to a framebuffer at most 560 pixels wide -
|
|
* mini thumbnails to roughly half that - so an arbitrary source lands
|
|
* at a large ratio: a 4K screenshot in a mini thumbnail is a 15.7:1
|
|
* reduction. The sinc kernel widens with the ratio (128 taps there)
|
|
* and the scaler's accumulate truncates once per tap, so the result
|
|
* comes back measurably dark: -7.8% at that ratio, -4.7% for a 1080p
|
|
* screenshot, against -0.8% at the 8-tap minimum.
|
|
*
|
|
* Decimating first keeps the sinc stage below 2:1 and so at 8 taps.
|
|
* Box averaging is exact here - it averages precisely the pixels being
|
|
* discarded - so this costs nothing in quality, and it is faster
|
|
* besides, the expensive filter seeing far fewer input pixels. */
|
|
static uint32_t *rgui_downscale_box(const uint32_t *src,
|
|
unsigned src_dims, unsigned f, unsigned *out_dims)
|
|
{
|
|
unsigned x, y, i, j;
|
|
unsigned n = f * f;
|
|
unsigned sw = VIDEO_SCALE_W(src_dims);
|
|
unsigned dw = sw / f;
|
|
unsigned dh = VIDEO_SCALE_H(src_dims) / f;
|
|
uint32_t *d;
|
|
|
|
if ((dw < 1) || (dh < 1))
|
|
return NULL;
|
|
|
|
if (!(d = (uint32_t*)malloc((size_t)dw * dh * sizeof(uint32_t))))
|
|
return NULL;
|
|
|
|
for (y = 0; y < dh; y++)
|
|
{
|
|
for (x = 0; x < dw; x++)
|
|
{
|
|
unsigned a = 0, r = 0, g = 0, b = 0;
|
|
|
|
for (j = 0; j < f; j++)
|
|
{
|
|
const uint32_t *row = src + (size_t)(y * f + j) * sw + x * f;
|
|
|
|
for (i = 0; i < f; i++)
|
|
{
|
|
uint32_t p = row[i];
|
|
a += (p >> 24) & 0xff;
|
|
r += (p >> 16) & 0xff;
|
|
g += (p >> 8) & 0xff;
|
|
b += p & 0xff;
|
|
}
|
|
}
|
|
|
|
d[(size_t)y * dw + x] =
|
|
((a / n) << 24) | ((r / n) << 16)
|
|
| ((g / n) << 8) | (b / n);
|
|
}
|
|
}
|
|
|
|
*out_dims = VIDEO_SCALE_PACK(dw, dh);
|
|
return d;
|
|
}
|
|
|
|
static bool rgui_downscale_thumbnail(
|
|
rgui_t *rgui,
|
|
unsigned max_dims,
|
|
unsigned thumbnail_downscaler,
|
|
struct texture_image *image_src,
|
|
struct texture_image *image_dst)
|
|
{
|
|
video_driver_state_t *video_st = video_state_get_ptr();
|
|
bool thumbnail_core_aspect = *rgui->savestate_thumbnail_file_path;
|
|
unsigned max_width = VIDEO_SCALE_W(max_dims);
|
|
unsigned max_height = VIDEO_SCALE_H(max_dims);
|
|
/* Determine output dimensions */
|
|
float display_aspect_ratio = (float)max_width / (float)max_height;
|
|
float aspect_ratio = (float)image_src->width / (float)image_src->height;
|
|
float core_aspect = (thumbnail_core_aspect
|
|
&& video_st && video_st->av_info.geometry.aspect_ratio > 0)
|
|
? video_st->av_info.geometry.aspect_ratio
|
|
: aspect_ratio;
|
|
|
|
if (aspect_ratio > display_aspect_ratio)
|
|
{
|
|
image_dst->width = max_width;
|
|
image_dst->height = image_src->height * max_width / image_src->width;
|
|
|
|
if (thumbnail_core_aspect)
|
|
{
|
|
image_dst->height = image_dst->height * (aspect_ratio / core_aspect);
|
|
|
|
if (image_dst->height > image_src->height)
|
|
{
|
|
image_dst->height = image_src->height;
|
|
image_dst->width = (float)image_src->width * (image_dst->height / (float)image_src->height);
|
|
image_dst->width = image_dst->width / (aspect_ratio / core_aspect);
|
|
}
|
|
}
|
|
|
|
/* Account for any possible rounding errors... */
|
|
if (image_dst->height < 1)
|
|
image_dst->height = 1;
|
|
else if (image_dst->height > max_height)
|
|
image_dst->height = max_height;
|
|
}
|
|
else
|
|
{
|
|
image_dst->height = max_height;
|
|
image_dst->width = image_src->width * max_height / image_src->height;
|
|
|
|
if (thumbnail_core_aspect)
|
|
image_dst->width = image_dst->width / (aspect_ratio / core_aspect);
|
|
|
|
/* Account for any possible rounding errors... */
|
|
if (image_dst->width < 1)
|
|
image_dst->width = 1;
|
|
if (image_dst->width > max_width)
|
|
image_dst->width = max_width;
|
|
}
|
|
|
|
/* Allocate pixel buffer */
|
|
if (!(image_dst->pixels = (uint32_t*)calloc(image_dst->width * image_dst->height, sizeof(uint32_t))))
|
|
return false;
|
|
|
|
/* Determine scaling method */
|
|
if (thumbnail_downscaler == RGUI_THUMB_SCALE_POINT)
|
|
{
|
|
unsigned x_dst, y_dst;
|
|
/* Perform nearest neighbour resampling
|
|
* > Fastest method, minimal performance impact */
|
|
uint32_t x_ratio = ((image_src->width << 16) / image_dst->width);
|
|
uint32_t y_ratio = ((image_src->height << 16) / image_dst->height);
|
|
|
|
for (y_dst = 0; y_dst < image_dst->height; y_dst++)
|
|
{
|
|
unsigned y_src = (y_dst * y_ratio) >> 16;
|
|
for (x_dst = 0; x_dst < image_dst->width; x_dst++)
|
|
{
|
|
unsigned x_src = (x_dst * x_ratio) >> 16;
|
|
image_dst->pixels[(y_dst * image_dst->width) + x_dst] = image_src->pixels[(y_src * image_src->width) + x_src];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* Perform either bilinear or sinc (Lanczos3) resampling
|
|
* using libretro-common scaler
|
|
* > Better quality, but substantially higher performance
|
|
* impact - although not an issue on desktop-class
|
|
* hardware */
|
|
const uint32_t *scale_src = image_src->pixels;
|
|
unsigned scale_width = image_src->width;
|
|
unsigned scale_height = image_src->height;
|
|
uint32_t *box_buf = NULL;
|
|
unsigned f;
|
|
|
|
/* Decimate first while doing so does not undershoot the
|
|
* target, so the filter below runs at its minimum kernel
|
|
* rather than one widened by the ratio. See
|
|
* rgui_downscale_box(). */
|
|
for (f = 1; (scale_width / (f * 2)) >= image_dst->width; f *= 2) ;
|
|
|
|
if (f > 1 && VIDEO_SCALE_FITS(scale_width, scale_height))
|
|
{
|
|
unsigned box_dims;
|
|
|
|
if ((box_buf = rgui_downscale_box(scale_src,
|
|
VIDEO_SCALE_PACK(scale_width, scale_height), f, &box_dims)))
|
|
{
|
|
scale_src = box_buf;
|
|
scale_width = VIDEO_SCALE_W(box_dims);
|
|
scale_height = VIDEO_SCALE_H(box_dims);
|
|
}
|
|
}
|
|
|
|
rgui->image_scaler.in_width = scale_width;
|
|
rgui->image_scaler.in_height = scale_height;
|
|
rgui->image_scaler.in_stride = scale_width * sizeof(uint32_t);
|
|
rgui->image_scaler.in_fmt = SCALER_FMT_ARGB8888;
|
|
|
|
rgui->image_scaler.out_width = image_dst->width;
|
|
rgui->image_scaler.out_height = image_dst->height;
|
|
rgui->image_scaler.out_stride = image_dst->width * sizeof(uint32_t);
|
|
rgui->image_scaler.out_fmt = SCALER_FMT_ARGB8888;
|
|
|
|
rgui->image_scaler.scaler_type = (thumbnail_downscaler == RGUI_THUMB_SCALE_SINC)
|
|
? SCALER_TYPE_SINC
|
|
: SCALER_TYPE_BILINEAR;
|
|
|
|
/* This reset is redundant, since scaler_ctx_gen_filter()
|
|
* calls it - but do it anyway in case the
|
|
* scaler_ctx_gen_filter() internals ever change... */
|
|
scaler_ctx_gen_reset(&rgui->image_scaler);
|
|
if (!scaler_ctx_gen_filter(&rgui->image_scaler))
|
|
{
|
|
/* Could be leftovers if scaler_ctx_gen_filter()
|
|
* fails, so reset just in case... */
|
|
scaler_ctx_gen_reset(&rgui->image_scaler);
|
|
free(box_buf);
|
|
return false;
|
|
}
|
|
|
|
scaler_ctx_scale(&rgui->image_scaler, image_dst->pixels, scale_src);
|
|
free(box_buf);
|
|
/* Reset again - don't want to leave anything hanging around
|
|
* if the user switches back to nearest neighbour scaling */
|
|
scaler_ctx_gen_reset(&rgui->image_scaler);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static void rgui_process_thumbnail(
|
|
rgui_t *rgui,
|
|
thumbnail_t *thumbnail,
|
|
uint32_t *queue_size,
|
|
unsigned menu_rgui_thumbnail_downscaler,
|
|
bool dither,
|
|
struct texture_image *image_src)
|
|
{
|
|
unsigned x, y;
|
|
unsigned max_width = VIDEO_SCALE_W(thumbnail->max_dims);
|
|
unsigned max_height = VIDEO_SCALE_H(thumbnail->max_dims);
|
|
unsigned thumb_width = 0;
|
|
unsigned thumb_height = 0;
|
|
struct texture_image *image = NULL;
|
|
struct texture_image image_resampled = {
|
|
NULL,
|
|
0,
|
|
0,
|
|
false
|
|
};
|
|
|
|
/* Ensure that we only process the most recently loaded
|
|
* thumbnail image (i.e. don't waste CPU cycles processing
|
|
* old images if we have a backlog) */
|
|
if (*queue_size > 0)
|
|
if ((*queue_size = *queue_size - 1) > 0)
|
|
return;
|
|
|
|
/* Sanity check */
|
|
if (!image_src->pixels || (image_src->width < 1) || (image_src->height < 1) || !thumbnail->data)
|
|
return;
|
|
|
|
/* Downscale thumbnail if it exceeds maximum size limits */
|
|
if ( (image_src->width > max_width)
|
|
|| (image_src->height > max_height))
|
|
{
|
|
if (!rgui_downscale_thumbnail(rgui,
|
|
thumbnail->max_dims,
|
|
menu_rgui_thumbnail_downscaler,
|
|
image_src,
|
|
&image_resampled))
|
|
{
|
|
if (image_resampled.pixels)
|
|
free(image_resampled.pixels);
|
|
return;
|
|
}
|
|
image = &image_resampled;
|
|
}
|
|
else
|
|
image = image_src;
|
|
|
|
/* Read the halves back out of the packed field rather than from
|
|
* the image, so the copy below walks exactly the rectangle the
|
|
* thumbnail now claims to be even if the pack had to clamp. */
|
|
thumbnail->dims = VIDEO_SCALE_PACK(image->width, image->height);
|
|
thumb_width = VIDEO_SCALE_W(thumbnail->dims);
|
|
thumb_height = VIDEO_SCALE_H(thumbnail->dims);
|
|
|
|
/* Copy image to thumbnail buffer, performing pixel format conversion.
|
|
* Iterate rows in the outer loop so the row-major source and
|
|
* destination are walked sequentially. */
|
|
for (y = 0; y < thumb_height; y++)
|
|
{
|
|
uint16_t *dst = thumbnail->data + y * thumb_width;
|
|
const uint32_t *src = image->pixels + y * thumb_width;
|
|
if (dither)
|
|
{
|
|
for (x = 0; x < thumb_width; x++)
|
|
dst[x] = argb32_to_pixel_platform_format_dither(src[x], x, y);
|
|
}
|
|
else
|
|
{
|
|
for (x = 0; x < thumb_width; x++)
|
|
dst[x] = argb32_to_pixel_platform_format(src[x]);
|
|
}
|
|
}
|
|
|
|
thumbnail->is_valid = true;
|
|
|
|
/* Tell menu that a display update is required */
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
|
|
/* Clean up */
|
|
image = NULL;
|
|
if (image_resampled.pixels)
|
|
free(image_resampled.pixels);
|
|
image_resampled.pixels = NULL;
|
|
}
|
|
|
|
static void rgui_media_gpu_publish(rgui_t *rgui, const rgui_media_gpu_view_t *view)
|
|
{
|
|
unsigned slot, i;
|
|
if (view->visible != rgui->media_gpu_pending.visible
|
|
|| (view->visible && (view->texture != rgui->media_gpu_pending.texture
|
|
|| view->texture_dims != rgui->media_gpu_pending.texture_dims
|
|
|| view->source_dims != rgui->media_gpu_pending.source_dims
|
|
|| memcmp(&view->rect, &rgui->media_gpu_pending.rect, sizeof(view->rect)))))
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
rgui->media_gpu_pending = *view;
|
|
for (slot = 0; slot < 3; slot++)
|
|
if (retro_atomic_cas_int(&rgui->media_gpu_states[slot], 0, 1)) break;
|
|
if (slot == 3) return;
|
|
rgui->media_gpu_views[slot] = *view;
|
|
for (i = 0; i < 3; i++)
|
|
if (i != slot) retro_atomic_cas_int(&rgui->media_gpu_states[i], 2, 0);
|
|
retro_atomic_store_release_int(&rgui->media_gpu_states[slot], 2);
|
|
}
|
|
|
|
static void rgui_media_gpu_consume(rgui_t *rgui)
|
|
{
|
|
unsigned i;
|
|
for (i = 0; i < 3; i++)
|
|
if (retro_atomic_cas_int(&rgui->media_gpu_states[i], 2, 3))
|
|
{
|
|
rgui->media_gpu_view = rgui->media_gpu_views[i];
|
|
retro_atomic_store_release_int(&rgui->media_gpu_states[i], 0);
|
|
return;
|
|
}
|
|
}
|
|
|
|
static void rgui_media_close(rgui_t *rgui, bool context_reset)
|
|
{
|
|
rgui_media_gpu_view_t draw;
|
|
menu_media_controls_context_reset(&rgui->media, context_reset);
|
|
memset(&draw, 0, sizeof(draw));
|
|
rgui_media_gpu_publish(rgui, &draw);
|
|
gfx_media_cpu_retire(rgui->media_player);
|
|
rgui->media_player = NULL;
|
|
if (retro_atomic_load_acquire_int(&rgui->media_gpu.status)
|
|
== GFX_THUMBNAIL_STATUS_PENDING)
|
|
gfx_thumbnail_cancel_pending_requests();
|
|
gfx_thumbnail_reset(&rgui->media_gpu);
|
|
rgui->media_path[0] = '\0';
|
|
if (!context_reset)
|
|
gfx_media_subtitle_update(rgui->media.subtitle, NULL, NULL, 0, 0, false);
|
|
}
|
|
|
|
static bool rgui_media_present(void *user, const video_player_frame_t *frame)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)user;
|
|
struct texture_image image;
|
|
uint32_t queue_size = 0;
|
|
settings_t *settings = config_get_ptr();
|
|
unsigned i;
|
|
thumbnail_t *thumbnails[2];
|
|
thumbnails[0] = &rgui->fs_thumbnail;
|
|
thumbnails[1] = &rgui->mini_thumbnail;
|
|
if (!frame->native || !frame->pixels) return false;
|
|
image.pixels = (uint32_t*)frame->pixels;
|
|
image.width = frame->width; image.height = frame->height; image.pix10 = false;
|
|
for (i = 0; i < 2; i++)
|
|
{
|
|
rgui_process_thumbnail(rgui, thumbnails[i], &queue_size,
|
|
settings->uints.menu_rgui_thumbnail_downscaler,
|
|
settings->bools.menu_rgui_thumbnail_dither, &image);
|
|
strlcpy(thumbnails[i]->path, rgui->media_path, sizeof(thumbnails[i]->path));
|
|
}
|
|
return rgui->fs_thumbnail.is_valid && rgui->mini_thumbnail.is_valid;
|
|
}
|
|
|
|
static bool rgui_media_state(void *user, int64_t now, gfx_media_playback_state_t *state)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)user;
|
|
return rgui->media_player ? gfx_media_cpu_state(rgui->media_player, now, state)
|
|
: gfx_thumbnail_get_playback_state(&rgui->media_gpu, now, state);
|
|
}
|
|
|
|
static bool rgui_media_pause(void *user, bool paused, int64_t now)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)user;
|
|
return rgui->media_player ? gfx_media_cpu_pause(rgui->media_player, paused, now)
|
|
: gfx_thumbnail_set_paused(&rgui->media_gpu, paused, now);
|
|
}
|
|
|
|
static bool rgui_media_seek(void *user, int64_t target_us, int64_t now)
|
|
{
|
|
unsigned rate = 0;
|
|
bool s16 = false;
|
|
rgui_t *rgui = (rgui_t*)user;
|
|
if (!rgui->media_player)
|
|
return gfx_thumbnail_seek(&rgui->media_gpu, target_us, now);
|
|
#if (defined(HAVE_RWEBM) || defined(HAVE_RMP4)) && defined(HAVE_AUDIOMIXER) && \
|
|
(defined(HAVE_ROPUS) || defined(HAVE_RVORBIS) || defined(HAVE_RAAC))
|
|
if (config_get_ptr()->bools.menu_thumbnail_preview_audio)
|
|
audio_driver_mixer_prepare_format(&rate, &s16);
|
|
#endif
|
|
return gfx_media_cpu_seek(((rgui_t*)user)->media_player, target_us, rate, s16, now);
|
|
}
|
|
|
|
static bool rgui_media_gpu_supported(void)
|
|
{
|
|
video_device_info_t info;
|
|
if (!disp_get_ptr()->dispctx || !video_driver_get_device(&info)
|
|
|| !(info.import_formats & IMAGE_PIXFMT_NV12))
|
|
return false;
|
|
return info.api == VIDEO_DEVICE_VULKAN || info.api == VIDEO_DEVICE_D3D11
|
|
|| info.api == VIDEO_DEVICE_D3D12;
|
|
}
|
|
|
|
static void rgui_media_settings_show(void *user)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)user;
|
|
rgui->flags |= RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL | RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
static void rgui_media_settings_hide(void *user)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)user;
|
|
rgui->flags &= ~RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL;
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_media_update(rgui_t *rgui, unsigned dims)
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
gfx_media_target_t target;
|
|
gfx_media_controls_t *controls = &rgui->media.controls;
|
|
int64_t now = menu_driver_get_current_time();
|
|
int64_t old_position = controls->playback.position_us, old_drag = controls->drag_us;
|
|
bool old_visible = controls->visible, old_paused = controls->playback.paused;
|
|
bool old_seeking = controls->playback.seeking, old_focus = controls->row_focus;
|
|
unsigned old_button = controls->focus;
|
|
int old_hover = controls->hover;
|
|
bool wanted, once;
|
|
menu_media_controls_settings_iterate(&rgui->media);
|
|
wanted = *rgui->media_requested_path
|
|
&& ((rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
|| settings->bools.menu_rgui_inline_thumbnails
|
|
|| menu_media_controls_settings_active(&rgui->media));
|
|
once = menu_media_controls_continuous(&rgui->media,
|
|
(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL) != 0);
|
|
gfx_media_cpu_reap();
|
|
memset(&target, 0, sizeof(target));
|
|
if (!wanted || !string_is_equal(rgui->media_requested_path, rgui->media_path))
|
|
{
|
|
rgui_media_close(rgui, wanted && rgui->media.context_reset);
|
|
if (wanted)
|
|
{
|
|
gfx_anim_preview_t *session;
|
|
bool gpu = rgui_media_gpu_supported();
|
|
strlcpy(rgui->media_path, rgui->media_requested_path, sizeof(rgui->media_path));
|
|
if (gpu)
|
|
gfx_thumbnail_request_file(rgui->media_path, &rgui->media_gpu, 0);
|
|
session = rgui->media_gpu.anim_sess ? NULL
|
|
: gfx_anim_preview_open(rgui->media_path, -1);
|
|
if (session)
|
|
{
|
|
rgui->media_player = gfx_media_cpu_new(session, rgui_media_present, rgui, 0);
|
|
if (!rgui->media_player) gfx_anim_preview_close(session);
|
|
}
|
|
if (rgui->media_player && gpu)
|
|
{
|
|
if (retro_atomic_load_acquire_int(&rgui->media_gpu.status)
|
|
== GFX_THUMBNAIL_STATUS_PENDING)
|
|
gfx_thumbnail_cancel_pending_requests();
|
|
gfx_thumbnail_reset(&rgui->media_gpu);
|
|
}
|
|
else if (!rgui->media_player && !gpu)
|
|
{
|
|
if (disp_get_ptr()->dispctx)
|
|
gfx_thumbnail_request_file(rgui->media_path, &rgui->media_gpu, 0);
|
|
else
|
|
retro_atomic_store_release_int(&rgui->media_gpu.status,
|
|
GFX_THUMBNAIL_STATUS_MISSING);
|
|
}
|
|
}
|
|
}
|
|
if (rgui->media_gpu.anim_sess)
|
|
{
|
|
gfx_thumbnail_set_repeat(&rgui->media_gpu, !once);
|
|
gfx_thumbnail_animate(&rgui->media_gpu, now);
|
|
if (!rgui->media.settings_open && gfx_thumbnail_take_completed(&rgui->media_gpu) && once)
|
|
menu_media_controls_complete(&rgui->media);
|
|
if ((rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& !(rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER)
|
|
&& !menu_input_dialog_get_display_kb())
|
|
{
|
|
target.user = rgui;
|
|
target.identity = rgui->media_gpu.anim_sess;
|
|
target.state = rgui_media_state; target.pause = rgui_media_pause;
|
|
target.seek = rgui_media_seek;
|
|
}
|
|
}
|
|
if (rgui->media_player)
|
|
{
|
|
video_player_set_threads(gfx_thumbnail_anim_threads_wanted());
|
|
gfx_media_cpu_set_repeat(rgui->media_player, !once);
|
|
if (gfx_media_cpu_poll(rgui->media_player, now) == VIDEO_PLAYER_ENDED)
|
|
{
|
|
if (gfx_media_cpu_completed(rgui->media_player))
|
|
{
|
|
if (!rgui->media.settings_open && gfx_media_cpu_take_completed(rgui->media_player) && once)
|
|
menu_media_controls_complete(&rgui->media);
|
|
}
|
|
else
|
|
{
|
|
gfx_media_cpu_retire(rgui->media_player);
|
|
rgui->media_player = NULL;
|
|
if (!rgui->fs_thumbnail.is_valid)
|
|
{
|
|
if (disp_get_ptr()->dispctx)
|
|
gfx_thumbnail_request_file(rgui->media_path, &rgui->media_gpu, 0);
|
|
else
|
|
retro_atomic_store_release_int(&rgui->media_gpu.status,
|
|
GFX_THUMBNAIL_STATUS_MISSING);
|
|
}
|
|
}
|
|
}
|
|
if (rgui->media_player && (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& !(rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER)
|
|
&& !menu_input_dialog_get_display_kb())
|
|
{
|
|
target.user = rgui;
|
|
target.identity = rgui->media_player;
|
|
target.state = rgui_media_state; target.pause = rgui_media_pause;
|
|
target.seek = rgui_media_seek;
|
|
}
|
|
}
|
|
if (rgui->media.resume_path && !target.user)
|
|
{
|
|
target.user = rgui;
|
|
target.identity = rgui->media_player ? (void*)rgui->media_player
|
|
: rgui->media_gpu.anim_sess;
|
|
target.state = rgui_media_state;
|
|
target.pause = rgui_media_pause;
|
|
target.seek = rgui_media_seek;
|
|
target.source_path = rgui->media_path;
|
|
menu_media_controls_resume(&rgui->media, &target, now);
|
|
memset(&target, 0, sizeof(target));
|
|
}
|
|
target.source_path = target.user ? rgui->media_path : NULL;
|
|
menu_input_get_pointer_state(&rgui->media_pointer);
|
|
rgui->media.settings_user = rgui;
|
|
rgui->media.settings_hide = rgui_media_settings_hide;
|
|
rgui->media.settings_show = rgui_media_settings_show;
|
|
if (menu_media_controls_update(&rgui->media, &target, VIDEO_SCALE_W(dims),
|
|
VIDEO_SCALE_H(dims), &rgui->media_pointer, now))
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
{
|
|
rgui_media_gpu_view_t draw;
|
|
memset(&draw, 0, sizeof(draw));
|
|
draw.visible = wanted && rgui->media_gpu.anim_sess
|
|
&& !(rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER)
|
|
&& !menu_input_dialog_get_display_kb()
|
|
&& retro_atomic_load_acquire_int(&rgui->media_gpu.status)
|
|
== GFX_THUMBNAIL_STATUS_AVAILABLE;
|
|
if (draw.visible)
|
|
{
|
|
draw.texture = rgui->media_gpu.texture;
|
|
draw.texture_dims = rgui->media_gpu.dims;
|
|
draw.alpha = rgui->media_gpu.alpha;
|
|
draw.flags = rgui->media_gpu.flags;
|
|
}
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
{
|
|
draw.rect.x = 0;
|
|
draw.rect.y = rgui->font_height_stride + 1;
|
|
draw.rect.w = VIDEO_SCALE_W(dims);
|
|
draw.rect.h = controls->layout.panel.y - draw.rect.y - 2;
|
|
}
|
|
else
|
|
{
|
|
draw.rect.w = VIDEO_SCALE_W(rgui->mini_thumbnail_max_dims);
|
|
draw.rect.h = VIDEO_SCALE_H(rgui->mini_thumbnail_max_dims);
|
|
draw.rect.x = rgui->term_layout.start_x
|
|
+ rgui->term_layout.width * rgui->font_width_stride - draw.rect.w;
|
|
draw.rect.y = rgui->term_layout.start_y;
|
|
}
|
|
draw.source_dims = dims;
|
|
rgui_media_gpu_publish(rgui, &draw);
|
|
}
|
|
if (old_position != controls->playback.position_us || old_drag != controls->drag_us
|
|
|| old_visible != controls->visible || old_paused != controls->playback.paused
|
|
|| old_seeking != controls->playback.seeking || old_focus != controls->row_focus
|
|
|| old_button != controls->focus || old_hover != controls->hover)
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
static bool rgui_load_image(
|
|
void *userdata,
|
|
void *data,
|
|
enum menu_image_type type)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)userdata;
|
|
|
|
if (!rgui)
|
|
return false;
|
|
|
|
if (!data)
|
|
{
|
|
/* This means we have a 'broken' image. There is no
|
|
* data, but we still have to decrement any thumbnail
|
|
* queues (otherwise further thumbnail processing will
|
|
* be blocked) */
|
|
switch (type)
|
|
{
|
|
case MENU_IMAGE_THUMBNAIL:
|
|
if (rgui->thumbnail_queue_size > 0)
|
|
rgui->thumbnail_queue_size--;
|
|
break;
|
|
case MENU_IMAGE_LEFT_THUMBNAIL:
|
|
if (rgui->left_thumbnail_queue_size > 0)
|
|
rgui->left_thumbnail_queue_size--;
|
|
break;
|
|
case MENU_IMAGE_NONE:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
if (type == MENU_IMAGE_THUMBNAIL && *rgui->media_requested_path)
|
|
{
|
|
if (rgui->thumbnail_queue_size) rgui->thumbnail_queue_size--;
|
|
return false;
|
|
}
|
|
|
|
/* The load asks for 10-bit wherever the driver samples it, and RGUI
|
|
* draws in software from 8-bit ARGB words: a 16-bit PNG comes here
|
|
* as packed XRGB2101010, narrowed back to the words it reads. */
|
|
if (((struct texture_image*)data)->pix10)
|
|
image_texture_narrow_10bit((struct texture_image*)data);
|
|
|
|
switch (type)
|
|
{
|
|
case MENU_IMAGE_WALLPAPER:
|
|
rgui_process_wallpaper(rgui, (struct texture_image*)data);
|
|
break;
|
|
case MENU_IMAGE_THUMBNAIL:
|
|
{
|
|
struct texture_image *image = (struct texture_image*)data;
|
|
settings_t *settings = config_get_ptr();
|
|
unsigned menu_rgui_thumbnail_downscaler =
|
|
settings->uints.menu_rgui_thumbnail_downscaler;
|
|
bool dither =
|
|
settings->bools.menu_rgui_thumbnail_dither;
|
|
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
rgui_process_thumbnail(rgui,
|
|
&rgui->fs_thumbnail,
|
|
&rgui->thumbnail_queue_size,
|
|
menu_rgui_thumbnail_downscaler,
|
|
dither,
|
|
image);
|
|
else
|
|
rgui_process_thumbnail(rgui,
|
|
&rgui->mini_thumbnail,
|
|
&rgui->thumbnail_queue_size,
|
|
menu_rgui_thumbnail_downscaler,
|
|
dither,
|
|
image);
|
|
|
|
/* If user toggles settings rapidly on very slow systems,
|
|
* it is possible for a thumbnail to be requested without
|
|
* it ever being processed. In this case, we still have to
|
|
* decrement the thumbnail queue (otherwise image updates
|
|
* will get 'stuck') */
|
|
if (rgui->thumbnail_queue_size > 0)
|
|
rgui->thumbnail_queue_size--;
|
|
}
|
|
break;
|
|
case MENU_IMAGE_LEFT_THUMBNAIL:
|
|
{
|
|
struct texture_image *image = (struct texture_image*)data;
|
|
settings_t *settings = config_get_ptr();
|
|
unsigned menu_rgui_thumbnail_downscaler =
|
|
settings->uints.menu_rgui_thumbnail_downscaler;
|
|
bool dither =
|
|
settings->bools.menu_rgui_thumbnail_dither;
|
|
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
rgui_process_thumbnail(rgui,
|
|
&rgui->fs_thumbnail,
|
|
&rgui->left_thumbnail_queue_size,
|
|
menu_rgui_thumbnail_downscaler,
|
|
dither,
|
|
image);
|
|
else
|
|
rgui_process_thumbnail(rgui,
|
|
&rgui->mini_left_thumbnail,
|
|
&rgui->left_thumbnail_queue_size,
|
|
menu_rgui_thumbnail_downscaler,
|
|
dither,
|
|
image);
|
|
|
|
if (rgui->left_thumbnail_queue_size > 0)
|
|
rgui->left_thumbnail_queue_size--;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_render_background(
|
|
rgui_t *rgui,
|
|
unsigned fb_dims,
|
|
size_t fb_pitch)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
frame_buf_t *frame_buf = &rgui->frame_buf;
|
|
frame_buf_t *background_buf = &rgui->background_buf;
|
|
|
|
/* Sanity check */
|
|
if ( !frame_buf->data
|
|
|| (fb_width != frame_buf->width)
|
|
|| (fb_height != frame_buf->height)
|
|
|| (fb_pitch != frame_buf->width << 1))
|
|
return;
|
|
|
|
/* If screensaver is active, 'zero out' framebuffer */
|
|
if (rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER)
|
|
{
|
|
size_t i;
|
|
uint16_t ss_bg_color = rgui->colors.ss_bg_color;
|
|
uint16_t *frame_buf_ptr = frame_buf->data;
|
|
|
|
for (i = 0; i < frame_buf->width * frame_buf->height; i++)
|
|
*(frame_buf_ptr++) = ss_bg_color;
|
|
}
|
|
/* Otherwise copy background to framebuffer */
|
|
else if (background_buf->data)
|
|
memcpy(frame_buf->data, background_buf->data,
|
|
(size_t)frame_buf->width * (size_t)frame_buf->height * sizeof(uint16_t));
|
|
}
|
|
|
|
/* Forward declaration */
|
|
static void rgui_render_messagebox(
|
|
rgui_t *rgui,
|
|
const char *message,
|
|
unsigned fb_dims);
|
|
|
|
RGUI_NOINLINE static void rgui_render_fs_thumbnail(
|
|
rgui_t *rgui,
|
|
unsigned fb_dims,
|
|
size_t fb_pitch)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
uint16_t *fs_thumbnail_data = rgui->fs_thumbnail.data;
|
|
|
|
if (rgui->fs_thumbnail.is_valid && frame_buf_data && fs_thumbnail_data)
|
|
{
|
|
unsigned y;
|
|
unsigned fb_x_offset, fb_y_offset;
|
|
unsigned thumb_x_offset, thumb_y_offset;
|
|
unsigned width, height;
|
|
unsigned fs_thumbnail_width = VIDEO_SCALE_W(rgui->fs_thumbnail.dims);
|
|
unsigned fs_thumbnail_height = VIDEO_SCALE_H(rgui->fs_thumbnail.dims);
|
|
uint16_t *src = NULL;
|
|
uint16_t *dst = NULL;
|
|
uint8_t border_width = 1;
|
|
|
|
/* Ensure that thumbnail is centred
|
|
* > Have to perform some stupid tests here because we
|
|
* cannot assume fb_width and fb_height are constant and
|
|
* >= thumbnail.width and thumbnail.height (even though
|
|
* they are...) */
|
|
if (fs_thumbnail_width <= fb_width)
|
|
{
|
|
thumb_x_offset = 0;
|
|
fb_x_offset = (fb_width - fs_thumbnail_width) >> 1;
|
|
width = fs_thumbnail_width;
|
|
}
|
|
else
|
|
{
|
|
thumb_x_offset = (fs_thumbnail_width - fb_width) >> 1;
|
|
fb_x_offset = 0;
|
|
width = fb_width;
|
|
}
|
|
if (fs_thumbnail_height <= fb_height)
|
|
{
|
|
thumb_y_offset = 0;
|
|
fb_y_offset = (fb_height - fs_thumbnail_height) >> 1;
|
|
height = fs_thumbnail_height;
|
|
}
|
|
else
|
|
{
|
|
thumb_y_offset = (fs_thumbnail_height - fb_height) >> 1;
|
|
fb_y_offset = 0;
|
|
height = fb_height;
|
|
}
|
|
|
|
/* Copy thumbnail to framebuffer */
|
|
for (y = 0; y < height; y++)
|
|
{
|
|
src = fs_thumbnail_data + thumb_x_offset + ((y + thumb_y_offset) * fs_thumbnail_width);
|
|
dst = frame_buf_data + (y + fb_y_offset) * (fb_pitch >> 1) + fb_x_offset;
|
|
|
|
memcpy(dst, src, width * sizeof(uint16_t));
|
|
}
|
|
|
|
/* Draw border */
|
|
/* Top */
|
|
if ((int)(fb_y_offset - border_width) >= 0)
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
fb_x_offset, fb_y_offset - border_width, width, border_width,
|
|
rgui->colors.shadow_color, rgui->colors.shadow_color, false);
|
|
|
|
/* Bottom */
|
|
if (height + border_width <= fb_height)
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
fb_x_offset, fb_y_offset + height, width, border_width,
|
|
rgui->colors.shadow_color, rgui->colors.shadow_color, false);
|
|
|
|
/* Left */
|
|
if ( (int)(fb_x_offset - border_width) >= 0
|
|
&& (int)(fb_y_offset - border_width) >= 0
|
|
&& (height + border_width * 2) <= fb_height)
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
fb_x_offset - border_width, fb_y_offset - border_width, border_width, height + border_width * 2,
|
|
rgui->colors.shadow_color, rgui->colors.shadow_color, false);
|
|
|
|
/* Right */
|
|
if ( (int)(fb_y_offset - border_width) >= 0
|
|
&& (height + border_width * 2) <= fb_height)
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
fb_x_offset + width, fb_y_offset - border_width, border_width, height + border_width * 2,
|
|
rgui->colors.shadow_color, rgui->colors.shadow_color, false);
|
|
}
|
|
else
|
|
{
|
|
/* Draw background */
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
0, 0, fb_width, fb_height,
|
|
rgui->colors.bg_dark_color,
|
|
rgui->colors.bg_dark_color,
|
|
false);
|
|
|
|
/* Draw "No thumbnail available" */
|
|
if ( !(rgui->flags & RGUI_FLAG_ENTRY_HAS_THUMBNAIL)
|
|
&& !(rgui->flags & RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL))
|
|
rgui_render_messagebox(rgui,
|
|
msg_hash_to_str(MSG_NO_THUMBNAIL_AVAILABLE), fb_dims);
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_regular(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color);
|
|
static void (*rgui_blit_line)(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color) = rgui_blit_line_regular;
|
|
|
|
static INLINE unsigned rgui_get_mini_thumbnail_fullwidth(rgui_t *rgui)
|
|
{
|
|
unsigned width = rgui->mini_thumbnail.is_valid
|
|
? VIDEO_SCALE_W(rgui->mini_thumbnail.dims) : 0;
|
|
unsigned left_width = rgui->mini_left_thumbnail.is_valid
|
|
? VIDEO_SCALE_W(rgui->mini_left_thumbnail.dims) : 0;
|
|
if (retro_atomic_load_acquire_int(&rgui->media_gpu.status) == GFX_THUMBNAIL_STATUS_AVAILABLE)
|
|
width = VIDEO_SCALE_W(rgui->mini_thumbnail_max_dims);
|
|
return width >= left_width ? width : left_width;
|
|
}
|
|
|
|
static void rgui_render_mini_thumbnail(
|
|
rgui_t *rgui,
|
|
thumbnail_t *thumbnail,
|
|
uint16_t *frame_buf_data,
|
|
enum gfx_thumbnail_id thumbnail_id,
|
|
unsigned fb_dims,
|
|
size_t fb_pitch,
|
|
bool swap_thumbnails,
|
|
bool thumbnail_background,
|
|
bool savestate)
|
|
{
|
|
if (thumbnail->is_valid && frame_buf_data && thumbnail->data)
|
|
{
|
|
unsigned y;
|
|
unsigned fb_x_offset, fb_y_offset;
|
|
unsigned thumbnail_fullwidth = rgui_get_mini_thumbnail_fullwidth(rgui);
|
|
uint16_t *src = NULL;
|
|
uint16_t *dst = NULL;
|
|
unsigned term_width = rgui->term_layout.width * rgui->font_width_stride;
|
|
unsigned term_height = rgui->term_layout.height * rgui->font_height_stride;
|
|
unsigned thumb_width = VIDEO_SCALE_W(thumbnail->dims);
|
|
unsigned thumb_height = VIDEO_SCALE_H(thumbnail->dims);
|
|
unsigned max_height = VIDEO_SCALE_H(thumbnail->max_dims);
|
|
|
|
/* Sanity check (this can never, ever happen, so just return
|
|
* instead of trying to crop the thumbnail image...) */
|
|
if ( (thumbnail_fullwidth > term_width)
|
|
|| (thumb_height > term_height))
|
|
return;
|
|
|
|
fb_x_offset = (rgui->term_layout.start_x + term_width) -
|
|
(thumb_width + ((thumbnail_fullwidth - thumb_width) >> 1));
|
|
|
|
if ( ((thumbnail_id == GFX_THUMBNAIL_RIGHT) && !swap_thumbnails)
|
|
|| ((thumbnail_id == GFX_THUMBNAIL_LEFT) && swap_thumbnails))
|
|
fb_y_offset = rgui->term_layout.start_y
|
|
+ ((max_height - thumb_height) >> 1);
|
|
else
|
|
fb_y_offset = (rgui->term_layout.start_y + term_height) -
|
|
(thumb_height + ((max_height - thumb_height) >> 1));
|
|
|
|
/* Draw background */
|
|
if (thumbnail_background)
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
rgui->term_layout.start_x + term_width - thumbnail_fullwidth,
|
|
( ((thumbnail_id == GFX_THUMBNAIL_RIGHT) && !swap_thumbnails)
|
|
|| ((thumbnail_id == GFX_THUMBNAIL_LEFT) && swap_thumbnails))
|
|
? fb_y_offset
|
|
: fb_y_offset - ((max_height - thumb_height) >> 1),
|
|
thumbnail_fullwidth, max_height,
|
|
rgui->colors.shadow_color,
|
|
rgui->colors.shadow_color,
|
|
false);
|
|
|
|
/* Copy thumbnail to framebuffer */
|
|
for (y = 0; y < thumb_height; y++)
|
|
{
|
|
src = thumbnail->data + (y * thumb_width);
|
|
dst = frame_buf_data + (y + fb_y_offset) *
|
|
(fb_pitch >> 1) + fb_x_offset;
|
|
|
|
memcpy(dst, src, thumb_width * sizeof(uint16_t));
|
|
}
|
|
}
|
|
/* Draw "not available" placeholder for unused save state thumbnails */
|
|
else if (savestate && frame_buf_data)
|
|
{
|
|
unsigned fb_y_offset;
|
|
unsigned term_width = rgui->term_layout.width * rgui->font_width_stride;
|
|
unsigned term_height = rgui->term_layout.height * rgui->font_height_stride;
|
|
unsigned max_width = VIDEO_SCALE_W(thumbnail->max_dims);
|
|
unsigned max_height = VIDEO_SCALE_H(thumbnail->max_dims);
|
|
|
|
if ( ((thumbnail_id == GFX_THUMBNAIL_RIGHT) && !swap_thumbnails)
|
|
|| ((thumbnail_id == GFX_THUMBNAIL_LEFT) && swap_thumbnails))
|
|
fb_y_offset = rgui->term_layout.start_y;
|
|
else
|
|
fb_y_offset = (rgui->term_layout.start_y + term_height) - max_height;
|
|
|
|
/* Draw background. No label goes on top of it: a missing image
|
|
* file is not something to caption, and the one for a missing
|
|
* state file has yet to be written. */
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
rgui->term_layout.start_x + term_width - max_width,
|
|
fb_y_offset,
|
|
max_width, max_height,
|
|
rgui->colors.shadow_color,
|
|
rgui->colors.shadow_color,
|
|
false);
|
|
}
|
|
}
|
|
|
|
static const rgui_theme_t *rgui_get_theme(rgui_t *rgui)
|
|
{
|
|
bool transparent = (rgui->flags & RGUI_FLAG_TRANSPARENCY_SUPPORTED)
|
|
&& (rgui->flags & RGUI_FLAG_TRANSPARENCY_ENABLE);
|
|
|
|
switch (rgui->color_theme)
|
|
{
|
|
case RGUI_THEME_CLASSIC_RED:
|
|
return transparent
|
|
? &rgui_theme_classic_red
|
|
: &rgui_theme_opaque_classic_red;
|
|
case RGUI_THEME_CLASSIC_ORANGE:
|
|
return transparent
|
|
? &rgui_theme_classic_orange
|
|
: &rgui_theme_opaque_classic_orange;
|
|
case RGUI_THEME_CLASSIC_YELLOW:
|
|
return transparent
|
|
? &rgui_theme_classic_yellow
|
|
: &rgui_theme_opaque_classic_yellow;
|
|
case RGUI_THEME_CLASSIC_GREEN:
|
|
return transparent
|
|
? &rgui_theme_classic_green
|
|
: &rgui_theme_opaque_classic_green;
|
|
case RGUI_THEME_CLASSIC_BLUE:
|
|
return transparent
|
|
? &rgui_theme_classic_blue
|
|
: &rgui_theme_opaque_classic_blue;
|
|
case RGUI_THEME_CLASSIC_VIOLET:
|
|
return transparent
|
|
? &rgui_theme_classic_violet
|
|
: &rgui_theme_opaque_classic_violet;
|
|
case RGUI_THEME_CLASSIC_GREY:
|
|
return transparent
|
|
? &rgui_theme_classic_grey
|
|
: &rgui_theme_opaque_classic_grey;
|
|
case RGUI_THEME_LEGACY_RED:
|
|
return transparent
|
|
? &rgui_theme_legacy_red
|
|
: &rgui_theme_opaque_legacy_red;
|
|
case RGUI_THEME_DARK_PURPLE:
|
|
return transparent
|
|
? &rgui_theme_dark_purple
|
|
: &rgui_theme_opaque_dark_purple;
|
|
case RGUI_THEME_MIDNIGHT_BLUE:
|
|
return transparent
|
|
? &rgui_theme_midnight_blue
|
|
: &rgui_theme_opaque_midnight_blue;
|
|
case RGUI_THEME_GOLDEN:
|
|
return transparent
|
|
? &rgui_theme_golden
|
|
: &rgui_theme_opaque_golden;
|
|
case RGUI_THEME_ELECTRIC_BLUE:
|
|
return transparent
|
|
? &rgui_theme_electric_blue
|
|
: &rgui_theme_opaque_electric_blue;
|
|
case RGUI_THEME_APPLE_GREEN:
|
|
return transparent
|
|
? &rgui_theme_apple_green
|
|
: &rgui_theme_opaque_apple_green;
|
|
case RGUI_THEME_VOLCANIC_RED:
|
|
return transparent
|
|
? &rgui_theme_volcanic_red
|
|
: &rgui_theme_opaque_volcanic_red;
|
|
case RGUI_THEME_LAGOON:
|
|
return transparent
|
|
? &rgui_theme_lagoon
|
|
: &rgui_theme_opaque_lagoon;
|
|
case RGUI_THEME_BROGRAMMER:
|
|
return transparent
|
|
? &rgui_theme_brogrammer
|
|
: &rgui_theme_opaque_brogrammer;
|
|
case RGUI_THEME_DRACULA:
|
|
return transparent
|
|
? &rgui_theme_dracula
|
|
: &rgui_theme_opaque_dracula;
|
|
case RGUI_THEME_EVERGARDEN:
|
|
return transparent
|
|
? &rgui_theme_evergarden
|
|
: &rgui_theme_opaque_evergarden;
|
|
case RGUI_THEME_FAIRYFLOSS:
|
|
return transparent
|
|
? &rgui_theme_fairyfloss
|
|
: &rgui_theme_opaque_fairyfloss;
|
|
case RGUI_THEME_FLATUI:
|
|
return transparent
|
|
? &rgui_theme_flatui
|
|
: &rgui_theme_opaque_flatui;
|
|
case RGUI_THEME_GRUVBOX_DARK:
|
|
return transparent
|
|
? &rgui_theme_gruvbox_dark
|
|
: &rgui_theme_opaque_gruvbox_dark;
|
|
case RGUI_THEME_GRUVBOX_LIGHT:
|
|
return transparent
|
|
? &rgui_theme_gruvbox_light
|
|
: &rgui_theme_opaque_gruvbox_light;
|
|
case RGUI_THEME_HACKING_THE_KERNEL:
|
|
return transparent
|
|
? &rgui_theme_hacking_the_kernel
|
|
: &rgui_theme_opaque_hacking_the_kernel;
|
|
case RGUI_THEME_NORD:
|
|
return transparent
|
|
? &rgui_theme_nord
|
|
: &rgui_theme_opaque_nord;
|
|
case RGUI_THEME_NOVA:
|
|
return transparent
|
|
? &rgui_theme_nova
|
|
: &rgui_theme_opaque_nova;
|
|
case RGUI_THEME_ONE_DARK:
|
|
return transparent
|
|
? &rgui_theme_one_dark
|
|
: &rgui_theme_opaque_one_dark;
|
|
case RGUI_THEME_PALENIGHT:
|
|
return transparent
|
|
? &rgui_theme_palenight
|
|
: &rgui_theme_opaque_palenight;
|
|
case RGUI_THEME_SOLARIZED_DARK:
|
|
return transparent
|
|
? &rgui_theme_solarized_dark
|
|
: &rgui_theme_opaque_solarized_dark;
|
|
case RGUI_THEME_SOLARIZED_LIGHT:
|
|
return transparent
|
|
? &rgui_theme_solarized_light
|
|
: &rgui_theme_opaque_solarized_light;
|
|
case RGUI_THEME_TANGO_DARK:
|
|
return transparent
|
|
? &rgui_theme_tango_dark
|
|
: &rgui_theme_opaque_tango_dark;
|
|
case RGUI_THEME_TANGO_LIGHT:
|
|
return transparent
|
|
? &rgui_theme_tango_light
|
|
: &rgui_theme_opaque_tango_light;
|
|
case RGUI_THEME_ZENBURN:
|
|
return transparent
|
|
? &rgui_theme_zenburn
|
|
: &rgui_theme_opaque_zenburn;
|
|
case RGUI_THEME_ANTI_ZENBURN:
|
|
return transparent
|
|
? &rgui_theme_anti_zenburn
|
|
: &rgui_theme_opaque_anti_zenburn;
|
|
case RGUI_THEME_FLUX:
|
|
return transparent
|
|
? &rgui_theme_flux
|
|
: &rgui_theme_opaque_flux;
|
|
case RGUI_THEME_GRAY_DARK:
|
|
return transparent
|
|
? &rgui_theme_gray_dark
|
|
: &rgui_theme_opaque_gray_dark;
|
|
case RGUI_THEME_GRAY_LIGHT:
|
|
return transparent
|
|
? &rgui_theme_gray_light
|
|
: &rgui_theme_opaque_gray_light;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return transparent
|
|
? &rgui_theme_classic_green
|
|
: &rgui_theme_opaque_classic_green;
|
|
}
|
|
|
|
static void rgui_update_dynamic_theme_path(
|
|
rgui_t *rgui,
|
|
const char *theme_dir)
|
|
{
|
|
bool use_playlist_theme = false;
|
|
|
|
if (!theme_dir || !*theme_dir)
|
|
{
|
|
rgui->theme_dynamic_path[0] = '\0';
|
|
return;
|
|
}
|
|
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
&& *rgui->menu_title)
|
|
{
|
|
size_t _len = fill_pathname_join_special(rgui->theme_dynamic_path, theme_dir,
|
|
rgui->menu_title, sizeof(rgui->theme_dynamic_path));
|
|
rgui->theme_dynamic_path[ _len] = '.';
|
|
rgui->theme_dynamic_path[++_len] = 'c';
|
|
rgui->theme_dynamic_path[++_len] = 'f';
|
|
rgui->theme_dynamic_path[++_len] = 'g';
|
|
rgui->theme_dynamic_path[++_len] = '\0';
|
|
use_playlist_theme = path_is_valid(rgui->theme_dynamic_path);
|
|
}
|
|
|
|
if (!use_playlist_theme)
|
|
fill_pathname_join_special(rgui->theme_dynamic_path, theme_dir,
|
|
"default.cfg", sizeof(rgui->theme_dynamic_path));
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_queue_wallpaper(
|
|
const char *theme_path, const char *wallpaper_file)
|
|
{
|
|
char wallpaper_path[PATH_MAX_LENGTH];
|
|
wallpaper_path[0] = '\0';
|
|
fill_pathname_resolve_relative(wallpaper_path, theme_path,
|
|
wallpaper_file, sizeof(wallpaper_path));
|
|
if (path_is_valid(wallpaper_path))
|
|
task_push_image_load(wallpaper_path,
|
|
gfx_surface_wants_rgba(), 0, 0,
|
|
menu_display_handle_wallpaper_upload, NULL);
|
|
}
|
|
|
|
static void rgui_load_custom_theme(
|
|
rgui_t *rgui,
|
|
rgui_theme_t *theme_colors,
|
|
const char *theme_path,
|
|
unsigned menu_rgui_aspect_ratio)
|
|
{
|
|
char wallpaper_file[PATH_MAX_LENGTH];
|
|
unsigned normal_color = 0;
|
|
unsigned hover_color = 0;
|
|
unsigned title_color = 0;
|
|
unsigned bg_dark_color = 0;
|
|
unsigned bg_light_color = 0;
|
|
unsigned border_dark_color = 0;
|
|
unsigned border_light_color = 0;
|
|
unsigned shadow_color = 0;
|
|
unsigned particle_color = 0;
|
|
config_file_t *conf = NULL;
|
|
const char *wallpaper_key = NULL;
|
|
bool ret = false;
|
|
#if defined(DINGUX)
|
|
menu_rgui_aspect_ratio = RGUI_DINGUX_ASPECT_RATIO;
|
|
#endif
|
|
|
|
/* Determine which type of wallpaper to load */
|
|
switch (menu_rgui_aspect_ratio)
|
|
{
|
|
case RGUI_ASPECT_RATIO_16_9:
|
|
case RGUI_ASPECT_RATIO_16_9_CENTRE:
|
|
wallpaper_key = "rgui_wallpaper_16_9";
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_10:
|
|
case RGUI_ASPECT_RATIO_16_10_CENTRE:
|
|
wallpaper_key = "rgui_wallpaper_16_10";
|
|
break;
|
|
case RGUI_ASPECT_RATIO_21_9:
|
|
case RGUI_ASPECT_RATIO_21_9_CENTRE:
|
|
wallpaper_key = "rgui_wallpaper_21_9";
|
|
break;
|
|
case RGUI_ASPECT_RATIO_3_2:
|
|
case RGUI_ASPECT_RATIO_3_2_CENTRE:
|
|
wallpaper_key = "rgui_wallpaper_3_2";
|
|
break;
|
|
case RGUI_ASPECT_RATIO_5_3:
|
|
case RGUI_ASPECT_RATIO_5_3_CENTRE:
|
|
wallpaper_key = "rgui_wallpaper_5_3";
|
|
break;
|
|
default:
|
|
/* 4:3 */
|
|
wallpaper_key = "rgui_wallpaper";
|
|
break;
|
|
}
|
|
|
|
wallpaper_file[0] = '\0';
|
|
|
|
/* Sanity check */
|
|
if (!theme_path || !*theme_path)
|
|
goto end;
|
|
if (!path_is_valid(theme_path))
|
|
goto end;
|
|
|
|
/* Open config file */
|
|
if (!(conf = config_file_new_from_path_to_string(theme_path)))
|
|
goto end;
|
|
|
|
/* Parse config file */
|
|
if (!config_get_hex(conf, "rgui_entry_normal_color", &normal_color))
|
|
goto end;
|
|
|
|
if (!config_get_hex(conf, "rgui_entry_hover_color", &hover_color))
|
|
goto end;
|
|
|
|
if (!config_get_hex(conf, "rgui_title_color", &title_color))
|
|
goto end;
|
|
|
|
if (!config_get_hex(conf, "rgui_bg_dark_color", &bg_dark_color))
|
|
goto end;
|
|
|
|
if (!config_get_hex(conf, "rgui_bg_light_color", &bg_light_color))
|
|
goto end;
|
|
|
|
if (!config_get_hex(conf, "rgui_border_dark_color", &border_dark_color))
|
|
goto end;
|
|
|
|
if (!config_get_hex(conf, "rgui_border_light_color", &border_light_color))
|
|
goto end;
|
|
|
|
/* Make shadow colour optional (fallback to fully opaque black)
|
|
* - i.e. if user has no intention of enabling shadows, they
|
|
* should not have to include this entry */
|
|
if (!config_get_hex(conf, "rgui_shadow_color", &shadow_color))
|
|
shadow_color = 0xFF000000;
|
|
|
|
/* Make particle colour optional too (fallback to normal
|
|
* rgb with bg_light alpha) */
|
|
if (!config_get_hex(conf, "rgui_particle_color", &particle_color))
|
|
particle_color = (normal_color & 0x00FFFFFF) |
|
|
(bg_light_color & 0xFF000000);
|
|
|
|
ret = true;
|
|
|
|
end:
|
|
|
|
if (ret)
|
|
{
|
|
theme_colors->normal_color = (uint32_t)normal_color;
|
|
theme_colors->hover_color = (uint32_t)hover_color;
|
|
theme_colors->title_color = (uint32_t)title_color;
|
|
theme_colors->bg_dark_color = (uint32_t)bg_dark_color;
|
|
theme_colors->bg_light_color = (uint32_t)bg_light_color;
|
|
theme_colors->border_dark_color = (uint32_t)border_dark_color;
|
|
theme_colors->border_light_color = (uint32_t)border_light_color;
|
|
theme_colors->shadow_color = (uint32_t)shadow_color;
|
|
theme_colors->particle_color = (uint32_t)particle_color;
|
|
|
|
|
|
/* Load wallpaper, if required */
|
|
if (config_get_array(conf, wallpaper_key,
|
|
wallpaper_file, sizeof(wallpaper_file)))
|
|
rgui_queue_wallpaper(theme_path, wallpaper_file);
|
|
}
|
|
else
|
|
{
|
|
/* Use 'Classic Green' fallback */
|
|
const rgui_theme_t *fallback_theme =
|
|
( (rgui->flags & RGUI_FLAG_TRANSPARENCY_SUPPORTED)
|
|
&& (rgui->flags & RGUI_FLAG_TRANSPARENCY_ENABLE))
|
|
? &rgui_theme_classic_green
|
|
: &rgui_theme_opaque_classic_green;
|
|
|
|
theme_colors->normal_color = fallback_theme->normal_color;
|
|
theme_colors->hover_color = fallback_theme->hover_color;
|
|
theme_colors->title_color = fallback_theme->title_color;
|
|
theme_colors->bg_dark_color = fallback_theme->bg_dark_color;
|
|
theme_colors->bg_light_color = fallback_theme->bg_light_color;
|
|
theme_colors->border_dark_color = fallback_theme->border_dark_color;
|
|
theme_colors->border_light_color = fallback_theme->border_light_color;
|
|
theme_colors->shadow_color = fallback_theme->shadow_color;
|
|
theme_colors->particle_color = fallback_theme->particle_color;
|
|
}
|
|
|
|
if (conf)
|
|
config_file_free(conf);
|
|
conf = NULL;
|
|
}
|
|
|
|
static void rgui_cache_background(
|
|
rgui_t *rgui,
|
|
unsigned fb_dims,
|
|
size_t fb_pitch)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
frame_buf_t *background_buf = &rgui->background_buf;
|
|
|
|
/* Sanity check */
|
|
if ( (fb_width != background_buf->width)
|
|
|| (fb_height != background_buf->height)
|
|
|| (fb_pitch != background_buf->width << 1)
|
|
|| !background_buf->data)
|
|
return;
|
|
|
|
/* Fill background buffer with standard chequer pattern */
|
|
rgui_fill_rect(background_buf->data, fb_dims,
|
|
0, 0, fb_width, fb_height,
|
|
rgui->colors.bg_dark_color, rgui->colors.bg_light_color,
|
|
(rgui->flags & RGUI_FLAG_BG_THICKNESS) ? true : false);
|
|
|
|
/* Draw border, if required */
|
|
if (rgui->flags & RGUI_FLAG_BORDER_ENABLE)
|
|
rgui_render_border(rgui, background_buf->data, fb_dims);
|
|
}
|
|
|
|
static void rgui_prepare_colors(
|
|
rgui_t *rgui,
|
|
unsigned menu_rgui_color_theme,
|
|
const char *path_rgui_theme_preset,
|
|
bool menu_rgui_transparency,
|
|
unsigned menu_rgui_aspect_ratio)
|
|
{
|
|
rgui_theme_t theme_colors;
|
|
uint32_t ss_particle_color_argb32 = 0;
|
|
uint32_t disabled_color_argb32 = 0;
|
|
|
|
rgui->color_theme = menu_rgui_color_theme;
|
|
rgui->flags &= ~RGUI_FLAG_SHOW_WALLPAPER;
|
|
if (menu_rgui_transparency)
|
|
rgui->flags |= RGUI_FLAG_TRANSPARENCY_ENABLE;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_TRANSPARENCY_ENABLE;
|
|
|
|
if (rgui->color_theme == RGUI_THEME_CUSTOM)
|
|
{
|
|
strlcpy(rgui->theme_preset_path,
|
|
path_rgui_theme_preset,
|
|
sizeof(rgui->theme_preset_path));
|
|
rgui_load_custom_theme(rgui, &theme_colors,
|
|
path_rgui_theme_preset,
|
|
menu_rgui_aspect_ratio);
|
|
}
|
|
else if (rgui->color_theme == RGUI_THEME_DYNAMIC)
|
|
{
|
|
strlcpy(rgui->last_theme_dynamic_path, rgui->theme_dynamic_path,
|
|
sizeof(rgui->last_theme_dynamic_path));
|
|
rgui_load_custom_theme(rgui, &theme_colors, rgui->theme_dynamic_path,
|
|
menu_rgui_aspect_ratio);
|
|
}
|
|
else
|
|
{
|
|
const rgui_theme_t *current_theme = rgui_get_theme(rgui);
|
|
|
|
theme_colors.hover_color = current_theme->hover_color;
|
|
theme_colors.normal_color = current_theme->normal_color;
|
|
theme_colors.title_color = current_theme->title_color;
|
|
theme_colors.bg_dark_color = current_theme->bg_dark_color;
|
|
theme_colors.bg_light_color = current_theme->bg_light_color;
|
|
theme_colors.border_dark_color = current_theme->border_dark_color;
|
|
theme_colors.border_light_color = current_theme->border_light_color;
|
|
theme_colors.shadow_color = current_theme->shadow_color;
|
|
theme_colors.particle_color = current_theme->particle_color;
|
|
}
|
|
|
|
rgui->colors.hover_color = argb32_to_pixel_platform_format(theme_colors.hover_color);
|
|
rgui->colors.normal_color = argb32_to_pixel_platform_format(theme_colors.normal_color);
|
|
rgui->colors.title_color = argb32_to_pixel_platform_format(theme_colors.title_color);
|
|
rgui->colors.bg_dark_color = argb32_to_pixel_platform_format(theme_colors.bg_dark_color);
|
|
rgui->colors.bg_light_color = argb32_to_pixel_platform_format(theme_colors.bg_light_color);
|
|
rgui->colors.border_dark_color = argb32_to_pixel_platform_format(theme_colors.border_dark_color);
|
|
rgui->colors.border_light_color = argb32_to_pixel_platform_format(theme_colors.border_light_color);
|
|
rgui->colors.shadow_color = argb32_to_pixel_platform_format(theme_colors.shadow_color);
|
|
rgui->colors.particle_color = argb32_to_pixel_platform_format(theme_colors.particle_color);
|
|
|
|
/* Screensaver background is black, 100% opacity */
|
|
rgui->colors.ss_bg_color = argb32_to_pixel_platform_format(0xFF000000);
|
|
/* Screensaver particles are a 75:25 mix of
|
|
* regular background animation particle colour
|
|
* and black, with 100% opacity */
|
|
ss_particle_color_argb32 = (theme_colors.particle_color +
|
|
(theme_colors.particle_color & 0x1010101)) >> 1;
|
|
ss_particle_color_argb32 = (theme_colors.particle_color +
|
|
ss_particle_color_argb32 +
|
|
((theme_colors.particle_color ^ ss_particle_color_argb32) & 0x1010101)) >> 1;
|
|
rgui->colors.ss_particle_color = argb32_to_pixel_platform_format(
|
|
ss_particle_color_argb32 | 0xFF000000);
|
|
|
|
/* Disabled color is a mix of normal color and shadow color, with 100% opacity */
|
|
disabled_color_argb32 = (theme_colors.normal_color +
|
|
theme_colors.shadow_color +
|
|
((theme_colors.normal_color ^ theme_colors.shadow_color) & 0x1010101)) >> 1;
|
|
rgui->colors.disabled_color = argb32_to_pixel_platform_format(
|
|
disabled_color_argb32 | 0xFF000000);
|
|
|
|
rgui->flags |= RGUI_FLAG_BG_MODIFIED
|
|
| RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
/* ==============================
|
|
* rgui_blit_line/rgui_blit_symbol() START
|
|
* ============================== */
|
|
|
|
/* NOTE 1: These functions are WET (Write Everything Twice).
|
|
* This is bad design and difficult to maintain, but we have
|
|
* no other choice here. rgui_blit_line() is so performance
|
|
* critical that we simply cannot afford to check user
|
|
* settings internally. */
|
|
|
|
/* NOTE 2: We should really be using:
|
|
* - the two halves of rgui->font_dims
|
|
* - rgui->font_width_stride
|
|
* ...in these functions. This would ensure compatibility
|
|
* with any future font modifications, but unfortunately
|
|
* this kind of memory access has a catastrophic performance
|
|
* impact. We therefore have to use the raw defines instead:
|
|
* > For regular/extended blitting:
|
|
* - FONT_WIDTH
|
|
* - FONT_HEIGHT
|
|
* - FONT_WIDTH_STRIDE
|
|
* > For CJK blitting:
|
|
* - FONT_10X10_WIDTH
|
|
* - FONT_10X10_HEIGHT
|
|
* - FONT_10X10_WIDTH_STRIDE
|
|
* This is 'safe', because we have absolute control over
|
|
* which blitting function is used when specific fonts
|
|
* are 'active' - but other devs should be very careful
|
|
* when adding new fonts in the future */
|
|
|
|
/* rgui_blit_line() */
|
|
|
|
/* A blit walks only the pixels a glyph has: each row mask
|
|
* (bitmapfont_lut_t.rows) is taken 5 columns at a time, and these
|
|
* give the set columns of each 5-bit run, in ascending order, so
|
|
* pixels are written in the same order as a scan of the row. */
|
|
static const uint8_t rgui_glyph_run_count[32] = {
|
|
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
|
|
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5
|
|
};
|
|
|
|
static const uint8_t rgui_glyph_run_cols[32][5] = {
|
|
{0, 0, 0, 0, 0},
|
|
{0, 0, 0, 0, 0},
|
|
{1, 0, 0, 0, 0},
|
|
{0, 1, 0, 0, 0},
|
|
{2, 0, 0, 0, 0},
|
|
{0, 2, 0, 0, 0},
|
|
{1, 2, 0, 0, 0},
|
|
{0, 1, 2, 0, 0},
|
|
{3, 0, 0, 0, 0},
|
|
{0, 3, 0, 0, 0},
|
|
{1, 3, 0, 0, 0},
|
|
{0, 1, 3, 0, 0},
|
|
{2, 3, 0, 0, 0},
|
|
{0, 2, 3, 0, 0},
|
|
{1, 2, 3, 0, 0},
|
|
{0, 1, 2, 3, 0},
|
|
{4, 0, 0, 0, 0},
|
|
{0, 4, 0, 0, 0},
|
|
{1, 4, 0, 0, 0},
|
|
{0, 1, 4, 0, 0},
|
|
{2, 4, 0, 0, 0},
|
|
{0, 2, 4, 0, 0},
|
|
{1, 2, 4, 0, 0},
|
|
{0, 1, 2, 4, 0},
|
|
{3, 4, 0, 0, 0},
|
|
{0, 3, 4, 0, 0},
|
|
{1, 3, 4, 0, 0},
|
|
{0, 1, 3, 4, 0},
|
|
{2, 3, 4, 0, 0},
|
|
{0, 2, 3, 4, 0},
|
|
{1, 2, 3, 4, 0},
|
|
{0, 1, 2, 3, 4}
|
|
};
|
|
|
|
static INLINE void rgui_blit_glyph(uint16_t *dst, unsigned fb_width,
|
|
const uint16_t *rows, unsigned height, uint16_t color)
|
|
{
|
|
unsigned j;
|
|
|
|
for (j = 0; j < height; j++, dst += fb_width)
|
|
{
|
|
unsigned mask = rows[j];
|
|
uint16_t *run = dst;
|
|
|
|
for (; mask; mask >>= 5, run += 5)
|
|
{
|
|
const uint8_t *cols = rgui_glyph_run_cols[mask & 31];
|
|
unsigned count = rgui_glyph_run_count[mask & 31];
|
|
unsigned k;
|
|
|
|
for (k = 0; k < count; k++)
|
|
run[cols[k]] = color;
|
|
}
|
|
}
|
|
}
|
|
|
|
static INLINE void rgui_blit_glyph_shadow(uint16_t *dst, unsigned fb_width,
|
|
const uint16_t *rows, unsigned height,
|
|
const uint16_t *color_buf, const uint16_t *shadow_color_buf)
|
|
{
|
|
unsigned j;
|
|
|
|
for (j = 0; j < height; j++, dst += fb_width)
|
|
{
|
|
unsigned mask = rows[j];
|
|
uint16_t *run = dst;
|
|
|
|
for (; mask; mask >>= 5, run += 5)
|
|
{
|
|
const uint8_t *cols = rgui_glyph_run_cols[mask & 31];
|
|
unsigned count = rgui_glyph_run_count[mask & 31];
|
|
unsigned k;
|
|
|
|
for (k = 0; k < count; k++)
|
|
{
|
|
uint16_t *frame_buf_ptr = run + cols[k];
|
|
|
|
/* Text pixel + right shadow */
|
|
memcpy(frame_buf_ptr, color_buf, 2 * sizeof(uint16_t));
|
|
|
|
/* Bottom shadow */
|
|
frame_buf_ptr += fb_width;
|
|
memcpy(frame_buf_ptr, shadow_color_buf, 2 * sizeof(uint16_t));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_regular(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
const uint16_t *rows = rgui->fonts.regular->rows;
|
|
|
|
while (message && *message)
|
|
{
|
|
uint8_t symbol = (uint8_t)*message++;
|
|
|
|
if (symbol >= RGUI_NUM_FONT_GLYPHS_REGULAR)
|
|
continue;
|
|
|
|
if (symbol != ' ')
|
|
{
|
|
const uint16_t *symbol_rows = rows + (symbol * FONT_HEIGHT);
|
|
|
|
rgui_blit_glyph(frame_buf_data + (y * fb_width) + x, fb_width,
|
|
symbol_rows, FONT_HEIGHT, color);
|
|
}
|
|
|
|
x += FONT_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_regular_shadow(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
const uint16_t *rows = rgui->fonts.regular->rows;
|
|
uint16_t color_buf[2];
|
|
uint16_t shadow_color_buf[2];
|
|
|
|
color_buf[0] = color;
|
|
color_buf[1] = shadow_color;
|
|
|
|
shadow_color_buf[0] = shadow_color;
|
|
shadow_color_buf[1] = shadow_color;
|
|
|
|
while (message && *message)
|
|
{
|
|
uint8_t symbol = (uint8_t)*message++;
|
|
|
|
if (symbol >= RGUI_NUM_FONT_GLYPHS_REGULAR)
|
|
continue;
|
|
|
|
if (symbol != ' ')
|
|
{
|
|
const uint16_t *symbol_rows = rows + (symbol * FONT_HEIGHT);
|
|
|
|
rgui_blit_glyph_shadow(frame_buf_data + (y * fb_width) + x,
|
|
fb_width, symbol_rows, FONT_HEIGHT, color_buf, shadow_color_buf);
|
|
}
|
|
|
|
x += FONT_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_extended(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
const uint16_t *rows = rgui->fonts.regular->rows;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* Stupid cretinous hack: 'oe' ligatures are not
|
|
* really standard extended ASCII, so we have to
|
|
* waste CPU cycles performing a conversion from
|
|
* the unicode values...
|
|
* (Note: This is only really required for msg_hash_fr.h) */
|
|
if (symbol == 339) /* Latin small ligature oe */
|
|
symbol = 156;
|
|
if (symbol == 338) /* Latin capital ligature oe */
|
|
symbol = 140;
|
|
|
|
if (symbol >= RGUI_NUM_FONT_GLYPHS_EXTENDED)
|
|
continue;
|
|
|
|
symbol_rows = rows + (symbol * FONT_HEIGHT);
|
|
|
|
rgui_blit_glyph(frame_buf_data + (y * fb_width) + x, fb_width,
|
|
symbol_rows, FONT_HEIGHT, color);
|
|
}
|
|
|
|
x += FONT_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_extended_shadow(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t color_buf[2];
|
|
uint16_t shadow_color_buf[2];
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
const uint16_t *rows = rgui->fonts.regular->rows;
|
|
|
|
color_buf[0] = color;
|
|
color_buf[1] = shadow_color;
|
|
|
|
shadow_color_buf[0] = shadow_color;
|
|
shadow_color_buf[1] = shadow_color;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* Stupid cretinous hack: 'oe' ligatures are not
|
|
* really standard extended ASCII, so we have to
|
|
* waste CPU cycles performing a conversion from
|
|
* the unicode values...
|
|
* (Note: This is only really required for msg_hash_fr.h) */
|
|
if (symbol == 339) /* Latin small ligature oe */
|
|
symbol = 156;
|
|
if (symbol == 338) /* Latin capital ligature oe */
|
|
symbol = 140;
|
|
|
|
if (symbol >= RGUI_NUM_FONT_GLYPHS_EXTENDED)
|
|
continue;
|
|
|
|
symbol_rows = rows + (symbol * FONT_HEIGHT);
|
|
|
|
rgui_blit_glyph_shadow(frame_buf_data + (y * fb_width) + x,
|
|
fb_width, symbol_rows, FONT_HEIGHT, color_buf, shadow_color_buf);
|
|
}
|
|
|
|
x += FONT_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
#ifdef HAVE_LANGEXTRA
|
|
static void rgui_blit_line_cjk(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
bitmapfont_lut_t *font_eng = rgui->fonts.eng_10x10;
|
|
bitmapfont_lut_t *font_chn = rgui->fonts.chn_10x10;
|
|
bitmapfont_lut_t *font_jpn = rgui->fonts.jpn_10x10;
|
|
bitmapfont_lut_t *font_kor = rgui->fonts.kor_10x10;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* TODO/FIXME: check if really needed */
|
|
if (symbol == 339) /* Latin small ligature oe */
|
|
symbol = 156;
|
|
if (symbol == 338) /* Latin capital ligature oe */
|
|
symbol = 140;
|
|
|
|
/* Find glyph LUT data */
|
|
if (symbol <= font_eng->glyph_max)
|
|
symbol_rows = font_eng->rows + (symbol * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_chn->glyph_min) && (symbol <= font_chn->glyph_max))
|
|
symbol_rows = font_chn->rows + ((symbol - font_chn->glyph_min) * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_jpn->glyph_min) && (symbol <= font_jpn->glyph_max))
|
|
symbol_rows = font_jpn->rows + ((symbol - font_jpn->glyph_min) * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_kor->glyph_min) && (symbol <= font_kor->glyph_max))
|
|
symbol_rows = font_kor->rows + ((symbol - font_kor->glyph_min) * FONT_10X10_HEIGHT);
|
|
else
|
|
continue;
|
|
|
|
rgui_blit_glyph(frame_buf_data + (y * fb_width) + x, fb_width,
|
|
symbol_rows, FONT_10X10_HEIGHT, color);
|
|
}
|
|
|
|
x += FONT_10X10_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_cjk_shadow(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t color_buf[2];
|
|
uint16_t shadow_color_buf[2];
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
bitmapfont_lut_t *font_eng = rgui->fonts.eng_10x10;
|
|
bitmapfont_lut_t *font_chn = rgui->fonts.chn_10x10;
|
|
bitmapfont_lut_t *font_jpn = rgui->fonts.jpn_10x10;
|
|
bitmapfont_lut_t *font_kor = rgui->fonts.kor_10x10;
|
|
|
|
color_buf[0] = color;
|
|
color_buf[1] = shadow_color;
|
|
|
|
shadow_color_buf[0] = shadow_color;
|
|
shadow_color_buf[1] = shadow_color;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* TODO/FIXME: check if really needed */
|
|
if (symbol == 339) /* Latin small ligature oe */
|
|
symbol = 156;
|
|
if (symbol == 338) /* Latin capital ligature oe */
|
|
symbol = 140;
|
|
|
|
/* Find glyph LUT data */
|
|
if (symbol <= font_eng->glyph_max)
|
|
symbol_rows = font_eng->rows + (symbol * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_chn->glyph_min) && (symbol <= font_chn->glyph_max))
|
|
symbol_rows = font_chn->rows + ((symbol - font_chn->glyph_min) * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_jpn->glyph_min) && (symbol <= font_jpn->glyph_max))
|
|
symbol_rows = font_jpn->rows + ((symbol - font_jpn->glyph_min) * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_kor->glyph_min) && (symbol <= font_kor->glyph_max))
|
|
symbol_rows = font_kor->rows + ((symbol - font_kor->glyph_min) * FONT_10X10_HEIGHT);
|
|
else
|
|
continue;
|
|
|
|
rgui_blit_glyph_shadow(frame_buf_data + (y * fb_width) + x,
|
|
fb_width, symbol_rows, FONT_10X10_HEIGHT, color_buf, shadow_color_buf);
|
|
}
|
|
|
|
x += FONT_10X10_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_rus(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
bitmapfont_lut_t *font_eng = rgui->fonts.eng_10x10;
|
|
bitmapfont_lut_t *font_rus = rgui->fonts.rus_10x10;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* TODO/FIXME: check if really needed */
|
|
if (symbol == 339) /* Latin small ligature oe */
|
|
symbol = 156;
|
|
if (symbol == 338) /* Latin capital ligature oe */
|
|
symbol = 140;
|
|
|
|
/* Find glyph LUT data */
|
|
if (symbol <= font_eng->glyph_max)
|
|
symbol_rows = font_eng->rows + (symbol * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_rus->glyph_min) && (symbol <= font_rus->glyph_max))
|
|
symbol_rows = font_rus->rows + ((symbol - font_rus->glyph_min) * FONT_10X10_HEIGHT);
|
|
else
|
|
continue;
|
|
|
|
rgui_blit_glyph(frame_buf_data + (y * fb_width) + x, fb_width,
|
|
symbol_rows, FONT_10X10_HEIGHT, color);
|
|
}
|
|
|
|
x += FONT_10X10_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_rus_shadow(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t color_buf[2];
|
|
uint16_t shadow_color_buf[2];
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
bitmapfont_lut_t *font_eng = rgui->fonts.eng_10x10;
|
|
bitmapfont_lut_t *font_rus = rgui->fonts.rus_10x10;
|
|
|
|
color_buf[0] = color;
|
|
color_buf[1] = shadow_color;
|
|
|
|
shadow_color_buf[0] = shadow_color;
|
|
shadow_color_buf[1] = shadow_color;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* TODO/FIXME: check if really needed */
|
|
if (symbol == 339) /* Latin small ligature oe */
|
|
symbol = 156;
|
|
if (symbol == 338) /* Latin capital ligature oe */
|
|
symbol = 140;
|
|
|
|
/* Find glyph LUT data */
|
|
if (symbol <= font_eng->glyph_max)
|
|
symbol_rows = font_eng->rows + (symbol * FONT_10X10_HEIGHT);
|
|
else if ((symbol >= font_rus->glyph_min) && (symbol <= font_rus->glyph_max))
|
|
symbol_rows = font_rus->rows + ((symbol - font_rus->glyph_min) * FONT_10X10_HEIGHT);
|
|
else
|
|
continue;
|
|
|
|
rgui_blit_glyph_shadow(frame_buf_data + (y * fb_width) + x,
|
|
fb_width, symbol_rows, FONT_10X10_HEIGHT, color_buf, shadow_color_buf);
|
|
}
|
|
|
|
x += FONT_10X10_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_6x10(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
bitmapfont_lut_t *font_eng = rgui->fonts.eng_6x10;
|
|
bitmapfont_lut_t *font_lse = rgui->fonts.lse_6x10;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* Find glyph LUT data */
|
|
if (symbol <= font_eng->glyph_max)
|
|
symbol_rows = font_eng->rows + (symbol * FONT_6X10_HEIGHT);
|
|
else if ((symbol >= font_lse->glyph_min) && (symbol <= font_lse->glyph_max))
|
|
symbol_rows = font_lse->rows + ((symbol - font_lse->glyph_min) * FONT_6X10_HEIGHT);
|
|
else
|
|
continue;
|
|
|
|
rgui_blit_glyph(frame_buf_data + (y * fb_width) + x, fb_width,
|
|
symbol_rows, FONT_6X10_HEIGHT, color);
|
|
}
|
|
|
|
x += FONT_6X10_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_line_6x10_shadow(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
const char *message,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
uint16_t color_buf[2];
|
|
uint16_t shadow_color_buf[2];
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
bitmapfont_lut_t *font_eng = rgui->fonts.eng_6x10;
|
|
bitmapfont_lut_t *font_lse = rgui->fonts.lse_6x10;
|
|
|
|
color_buf[0] = color;
|
|
color_buf[1] = shadow_color;
|
|
|
|
shadow_color_buf[0] = shadow_color;
|
|
shadow_color_buf[1] = shadow_color;
|
|
|
|
while (message && *message)
|
|
{
|
|
/* Deal with spaces first, for efficiency */
|
|
if (*message == ' ')
|
|
message++;
|
|
else
|
|
{
|
|
const uint16_t *symbol_rows = NULL;
|
|
uint32_t symbol = utf8_walk(&message);
|
|
|
|
/* Find glyph LUT data */
|
|
if (symbol <= font_eng->glyph_max)
|
|
symbol_rows = font_eng->rows + (symbol * FONT_6X10_HEIGHT);
|
|
else if ((symbol >= font_lse->glyph_min) && (symbol <= font_lse->glyph_max))
|
|
symbol_rows = font_lse->rows + ((symbol - font_lse->glyph_min) * FONT_6X10_HEIGHT);
|
|
else
|
|
continue;
|
|
|
|
rgui_blit_glyph_shadow(frame_buf_data + (y * fb_width) + x,
|
|
fb_width, symbol_rows, FONT_6X10_HEIGHT, color_buf, shadow_color_buf);
|
|
}
|
|
|
|
x += FONT_6X10_WIDTH_STRIDE;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* rgui_blit_symbol() */
|
|
|
|
static const uint8_t *rgui_get_symbol_data(enum rgui_symbol_type symbol)
|
|
{
|
|
/* All custom symbols must have dimensions
|
|
* of exactly RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT */
|
|
static const uint8_t rgui_symbol_data_backspace[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 1, 0, 0,
|
|
0, 1, 0, 0, 0,
|
|
1, 1, 1, 1, 1,
|
|
0, 1, 0, 0, 0,
|
|
0, 0, 1, 0, 0,
|
|
0, 0, 0, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_enter[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 1,
|
|
0, 0, 0, 0, 1,
|
|
0, 0, 0, 0, 1,
|
|
0, 0, 1, 0, 1,
|
|
0, 1, 0, 0, 1,
|
|
1, 1, 1, 1, 1,
|
|
0, 1, 0, 0, 0, /* Baseline */
|
|
0, 0, 1, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_shift_up[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 1, 0, 0,
|
|
0, 1, 1, 1, 0,
|
|
1, 1, 0, 1, 1,
|
|
0, 1, 0, 1, 0,
|
|
0, 1, 0, 1, 0,
|
|
0, 1, 0, 1, 0,
|
|
0, 1, 1, 1, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_shift_down[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 0,
|
|
0, 1, 0, 1, 0,
|
|
0, 1, 0, 1, 0,
|
|
0, 1, 0, 1, 0,
|
|
1, 1, 0, 1, 1,
|
|
0, 1, 1, 1, 0,
|
|
0, 0, 1, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_next[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 0,
|
|
1, 0, 1, 0, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 0, 1, 0, 1,
|
|
0, 1, 1, 1, 0,
|
|
0, 0, 0, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_text_cursor[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1, /* Baseline */
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1};
|
|
|
|
static const uint8_t rgui_symbol_data_charging[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 1, 0, 1, 0,
|
|
0, 1, 0, 1, 0,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 0,
|
|
0, 0, 1, 0, 0,
|
|
0, 0, 1, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_battery_100[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 1, 1, 0,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_battery_80[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 1, 1, 0,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_battery_60[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 1, 1, 0,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_battery_40[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 1, 1, 0,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_battery_20[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 1, 1, 0,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 0, 0, 1,
|
|
0, 1, 1, 1, 1, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
/* Note: This is not actually a 'checkmark' - we don't
|
|
* have enough pixels to draw one effectively. The 'icon'
|
|
* is merely named according to its function... */
|
|
static const uint8_t rgui_symbol_data_checkmark[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 1, 1, 0, 0,
|
|
0, 1, 1, 0, 0,
|
|
0, 1, 1, 0, 0,
|
|
0, 1, 1, 0, 0,
|
|
0, 1, 1, 0, 0,
|
|
0, 1, 1, 0, 0,
|
|
0, 1, 1, 0, 0,
|
|
0, 1, 1, 0, 0, /* Baseline */
|
|
0, 1, 1, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_switch_on_left[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 1,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_switch_on_centre[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
1, 1, 1, 1, 0,
|
|
1, 1, 1, 1, 0,
|
|
1, 1, 1, 1, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_switch_on_right[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 0,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
1, 1, 1, 1, 1,
|
|
0, 1, 1, 1, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_switch_off_left[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 0,
|
|
1, 0, 0, 0, 1,
|
|
1, 0, 0, 0, 1,
|
|
1, 0, 0, 0, 1,
|
|
1, 0, 0, 0, 1,
|
|
1, 0, 0, 0, 1,
|
|
0, 1, 1, 1, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_switch_off_centre[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 1, 1, 1, 1,
|
|
0, 1, 0, 0, 0,
|
|
0, 1, 1, 1, 1,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
static const uint8_t rgui_symbol_data_switch_off_right[RGUI_SYMBOL_WIDTH * RGUI_SYMBOL_HEIGHT] = {
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0,
|
|
1, 1, 1, 1, 0,
|
|
0, 0, 0, 0, 1,
|
|
1, 1, 1, 1, 0,
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, /* Baseline */
|
|
0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0};
|
|
|
|
switch (symbol)
|
|
{
|
|
case RGUI_SYMBOL_BACKSPACE:
|
|
return rgui_symbol_data_backspace;
|
|
case RGUI_SYMBOL_ENTER:
|
|
return rgui_symbol_data_enter;
|
|
case RGUI_SYMBOL_SHIFT_UP:
|
|
return rgui_symbol_data_shift_up;
|
|
case RGUI_SYMBOL_SHIFT_DOWN:
|
|
return rgui_symbol_data_shift_down;
|
|
case RGUI_SYMBOL_NEXT:
|
|
return rgui_symbol_data_next;
|
|
case RGUI_SYMBOL_TEXT_CURSOR:
|
|
return rgui_symbol_data_text_cursor;
|
|
case RGUI_SYMBOL_CHARGING:
|
|
return rgui_symbol_data_charging;
|
|
case RGUI_SYMBOL_BATTERY_100:
|
|
return rgui_symbol_data_battery_100;
|
|
case RGUI_SYMBOL_BATTERY_80:
|
|
return rgui_symbol_data_battery_80;
|
|
case RGUI_SYMBOL_BATTERY_60:
|
|
return rgui_symbol_data_battery_60;
|
|
case RGUI_SYMBOL_BATTERY_40:
|
|
return rgui_symbol_data_battery_40;
|
|
case RGUI_SYMBOL_BATTERY_20:
|
|
return rgui_symbol_data_battery_20;
|
|
case RGUI_SYMBOL_CHECKMARK:
|
|
return rgui_symbol_data_checkmark;
|
|
case RGUI_SYMBOL_SWITCH_ON_LEFT:
|
|
return rgui_symbol_data_switch_on_left;
|
|
case RGUI_SYMBOL_SWITCH_ON_CENTRE:
|
|
return rgui_symbol_data_switch_on_centre;
|
|
case RGUI_SYMBOL_SWITCH_ON_RIGHT:
|
|
return rgui_symbol_data_switch_on_right;
|
|
case RGUI_SYMBOL_SWITCH_OFF_LEFT:
|
|
return rgui_symbol_data_switch_off_left;
|
|
case RGUI_SYMBOL_SWITCH_OFF_CENTRE:
|
|
return rgui_symbol_data_switch_off_centre;
|
|
case RGUI_SYMBOL_SWITCH_OFF_RIGHT:
|
|
return rgui_symbol_data_switch_off_right;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
static void rgui_blit_symbol_regular(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
enum rgui_symbol_type symbol,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
unsigned i, j;
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
const uint8_t *symbol_data = rgui_get_symbol_data(symbol);
|
|
|
|
if (!symbol_data)
|
|
return;
|
|
|
|
for (j = 0; j < RGUI_SYMBOL_HEIGHT; j++)
|
|
{
|
|
unsigned buff_offset = ((y + j) * fb_width) + x;
|
|
|
|
for (i = 0; i < RGUI_SYMBOL_WIDTH; i++)
|
|
{
|
|
if (*symbol_data++ == 1)
|
|
*(frame_buf_data + buff_offset + i) = color;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rgui_blit_symbol_shadow(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
enum rgui_symbol_type symbol,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
unsigned i, j;
|
|
uint16_t color_buf[2];
|
|
uint16_t shadow_color_buf[2];
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
const uint8_t *symbol_data = rgui_get_symbol_data(symbol);
|
|
|
|
color_buf[0] = color;
|
|
color_buf[1] = shadow_color;
|
|
|
|
shadow_color_buf[0] = shadow_color;
|
|
shadow_color_buf[1] = shadow_color;
|
|
|
|
if (!symbol_data)
|
|
return;
|
|
|
|
for (j = 0; j < RGUI_SYMBOL_HEIGHT; j++)
|
|
{
|
|
unsigned buff_offset = ((y + j) * fb_width) + x;
|
|
|
|
for (i = 0; i < RGUI_SYMBOL_WIDTH; i++)
|
|
{
|
|
if (*symbol_data++ == 1)
|
|
{
|
|
uint16_t *frame_buf_ptr = frame_buf_data + buff_offset + i;
|
|
|
|
/* Symbol pixel + right shadow */
|
|
memcpy(frame_buf_ptr, color_buf, sizeof(color_buf));
|
|
|
|
/* Bottom shadow */
|
|
frame_buf_ptr += fb_width;
|
|
memcpy(frame_buf_ptr, shadow_color_buf, sizeof(shadow_color_buf));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void (*rgui_blit_symbol)(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
enum rgui_symbol_type symbol,
|
|
uint16_t color,
|
|
uint16_t shadow_color) = rgui_blit_symbol_regular;
|
|
|
|
static void rgui_set_blit_functions(
|
|
unsigned language,
|
|
bool draw_shadow,
|
|
bool extended_ascii)
|
|
{
|
|
if (draw_shadow)
|
|
{
|
|
#ifdef HAVE_LANGEXTRA
|
|
switch (language)
|
|
{
|
|
case RETRO_LANGUAGE_JAPANESE:
|
|
case RETRO_LANGUAGE_KOREAN:
|
|
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
|
|
case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
|
|
rgui_blit_line = rgui_blit_line_cjk_shadow;
|
|
break;
|
|
case RETRO_LANGUAGE_RUSSIAN:
|
|
case RETRO_LANGUAGE_BELARUSIAN:
|
|
rgui_blit_line = rgui_blit_line_rus_shadow;
|
|
break;
|
|
case RETRO_LANGUAGE_ESPERANTO:
|
|
case RETRO_LANGUAGE_POLISH:
|
|
case RETRO_LANGUAGE_TURKISH:
|
|
case RETRO_LANGUAGE_SLOVAK:
|
|
case RETRO_LANGUAGE_CZECH:
|
|
case RETRO_LANGUAGE_HUNGARIAN:
|
|
rgui_blit_line = rgui_blit_line_6x10_shadow;
|
|
break;
|
|
default:
|
|
if (extended_ascii)
|
|
rgui_blit_line = rgui_blit_line_extended_shadow;
|
|
else
|
|
rgui_blit_line = rgui_blit_line_regular_shadow;
|
|
break;
|
|
}
|
|
#else
|
|
if (extended_ascii)
|
|
rgui_blit_line = rgui_blit_line_extended_shadow;
|
|
else
|
|
rgui_blit_line = rgui_blit_line_regular_shadow;
|
|
#endif
|
|
|
|
rgui_blit_symbol = rgui_blit_symbol_shadow;
|
|
}
|
|
else
|
|
{
|
|
#ifdef HAVE_LANGEXTRA
|
|
switch (language)
|
|
{
|
|
case RETRO_LANGUAGE_JAPANESE:
|
|
case RETRO_LANGUAGE_KOREAN:
|
|
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
|
|
case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
|
|
rgui_blit_line = rgui_blit_line_cjk;
|
|
break;
|
|
case RETRO_LANGUAGE_RUSSIAN:
|
|
case RETRO_LANGUAGE_BELARUSIAN:
|
|
rgui_blit_line = rgui_blit_line_rus;
|
|
break;
|
|
case RETRO_LANGUAGE_ESPERANTO:
|
|
case RETRO_LANGUAGE_POLISH:
|
|
case RETRO_LANGUAGE_TURKISH:
|
|
case RETRO_LANGUAGE_SLOVAK:
|
|
case RETRO_LANGUAGE_CZECH:
|
|
case RETRO_LANGUAGE_HUNGARIAN:
|
|
rgui_blit_line = rgui_blit_line_6x10;
|
|
break;
|
|
default:
|
|
if (extended_ascii)
|
|
rgui_blit_line = rgui_blit_line_extended;
|
|
else
|
|
rgui_blit_line = rgui_blit_line_regular;
|
|
break;
|
|
}
|
|
#else
|
|
if (extended_ascii)
|
|
rgui_blit_line = rgui_blit_line_extended;
|
|
else
|
|
rgui_blit_line = rgui_blit_line_regular;
|
|
#endif
|
|
|
|
rgui_blit_symbol = rgui_blit_symbol_regular;
|
|
}
|
|
}
|
|
|
|
/* ==============================
|
|
* rgui_blit_line/rgui_blit_symbol() END
|
|
* ============================== */
|
|
|
|
/* The button under the pointer, as the dialog's buttons show it */
|
|
static int rgui_msgbox_hover(const menu_dialog_t *d)
|
|
{
|
|
if (d->button_count)
|
|
return d->button_hover;
|
|
if (d->confirm_hover_back)
|
|
return 0;
|
|
return d->confirm_hover_ok ? 1 : -1;
|
|
}
|
|
|
|
static void rgui_set_message(void *data, const char *message)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
const menu_dialog_t *d = &menu_state_get_ptr()->dialog_st;
|
|
|
|
if (!rgui || !message)
|
|
return;
|
|
|
|
rgui->msgbox = message;
|
|
|
|
/* The framebuffer keeps the box: drawn again only when it changed */
|
|
if ( rgui->msgbox_epoch != d->button_epoch
|
|
|| rgui->msgbox_highlight != d->button_highlight
|
|
|| rgui->msgbox_hover != rgui_msgbox_hover(d)
|
|
|| strcmp(rgui->msgbox_drawn, message))
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
static void rgui_render_messagebox(
|
|
rgui_t *rgui,
|
|
const char *message,
|
|
unsigned fb_dims)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
int x, y;
|
|
size_t i;
|
|
char wrapped_message[MENU_LABEL_MAX_LENGTH];
|
|
unsigned width = 0;
|
|
unsigned glyphs_width = 0;
|
|
unsigned height = 0;
|
|
unsigned line_count = 0;
|
|
char *lines[128];
|
|
unsigned glyphs[128];
|
|
size_t msg_len;
|
|
size_t wrapped_len;
|
|
uint16_t *frame_buf_data = rgui->frame_buf.data;
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
menu_dialog_buttons_t buttons;
|
|
int button_w[MENU_DIALOG_BUTTONS_MAX];
|
|
int button_x[MENU_DIALOG_BUTTONS_MAX];
|
|
unsigned button_rows = 0;
|
|
int row_step = 0;
|
|
int rows_y = 0;
|
|
unsigned firmware_line_state = 0;
|
|
|
|
wrapped_message[0] = '\0';
|
|
menu_dialog_get_buttons(menu_st, &buttons);
|
|
|
|
msg_len = strlen(message);
|
|
|
|
/* Split message into lines */
|
|
wrapped_len = word_wrap(
|
|
wrapped_message, sizeof(wrapped_message),
|
|
message, msg_len,
|
|
rgui->term_layout.width,
|
|
100, 0);
|
|
|
|
/* Tokenize wrapped message by newlines in-place */
|
|
{
|
|
char *p = wrapped_message;
|
|
char *end = p + wrapped_len;
|
|
while (p < end && line_count < ARRAY_SIZE(lines))
|
|
{
|
|
char *nl = (char*)memchr(p, '\n', end - p);
|
|
lines[line_count++] = p;
|
|
if (nl)
|
|
{
|
|
*nl = '\0';
|
|
p = nl + 1;
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (line_count == 0)
|
|
return;
|
|
|
|
for (i = 0; i < line_count; i++)
|
|
{
|
|
unsigned msglen = (unsigned)utf8len(lines[i]);
|
|
unsigned line_width = msglen * rgui->font_width_stride - 1 + 6 + 10;
|
|
glyphs[i] = msglen;
|
|
width = MAX(width, line_width);
|
|
glyphs_width = MAX(glyphs_width, msglen);
|
|
}
|
|
|
|
/* The buttons: a glyph either side of each label, two between */
|
|
if (buttons.count)
|
|
{
|
|
int stride = (int)rgui->font_width_stride;
|
|
/* The most glyphs a box on this framebuffer can be wide */
|
|
int fit = ((int)fb_width - 15) / stride;
|
|
int need;
|
|
unsigned b;
|
|
for (b = 0; b < buttons.count; b++)
|
|
button_w[b] = ((int)utf8len(msg_hash_to_str(
|
|
(enum msg_hash_enums)buttons.label[b])) + 2) * stride;
|
|
need = menu_dialog_buttons_layout(button_w, buttons.count,
|
|
stride * 2, 0, 0, NULL);
|
|
row_step = (int)rgui->font_height_stride + 2;
|
|
button_rows = 1;
|
|
/* Wider than the widest box: one button per line */
|
|
if (need > fit * stride)
|
|
{
|
|
button_rows = buttons.count;
|
|
need = 0;
|
|
for (b = 0; b < buttons.count; b++)
|
|
need = MAX(need, button_w[b]);
|
|
}
|
|
if (need > (int)glyphs_width * stride)
|
|
{
|
|
int cells = (need + stride - 1) / stride;
|
|
if (cells > fit)
|
|
cells = fit;
|
|
if (cells > (int)glyphs_width)
|
|
{
|
|
glyphs_width = (unsigned)cells;
|
|
width = glyphs_width * stride - 1 + 6 + 10;
|
|
}
|
|
}
|
|
}
|
|
|
|
height = (unsigned)(rgui->font_height_stride * line_count + 6 + 10);
|
|
|
|
if (buttons.count)
|
|
height += (unsigned)(row_step * (int)button_rows)
|
|
+ rgui->font_height_stride;
|
|
|
|
x = ((int)fb_width - (int)width) / 2;
|
|
y = ((int)fb_height - (int)height) / 2;
|
|
|
|
if (height > fb_height)
|
|
height = fb_height;
|
|
if (x < 0)
|
|
x = 0;
|
|
if (y < 0)
|
|
y = 0;
|
|
if (buttons.count)
|
|
rows_y = y + (int)height - row_step * (int)button_rows
|
|
- (int)(rgui->font_height_stride / 2) - 2;
|
|
|
|
if (frame_buf_data)
|
|
{
|
|
uint16_t border_dark_color = rgui->colors.border_dark_color;
|
|
uint16_t border_light_color = rgui->colors.border_light_color;
|
|
uint8_t border_width = 2;
|
|
bool border_thickness = (rgui->flags & RGUI_FLAG_BORDER_THICKNESS) ? true : false;
|
|
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
x + border_width, y + border_width,
|
|
width - border_width * 2, height - border_width * 2,
|
|
rgui->colors.bg_dark_color, rgui->colors.bg_light_color,
|
|
(rgui->flags & RGUI_FLAG_BG_THICKNESS) ? true : false);
|
|
|
|
/* Note: We draw borders around message boxes regardless
|
|
* of the rgui->border_enable setting, because they look
|
|
* ridiculous without... */
|
|
|
|
/* Draw drop shadow, if required */
|
|
if (rgui->flags & RGUI_FLAG_SHADOW_ENABLE)
|
|
{
|
|
uint16_t shadow_color = rgui->colors.shadow_color;
|
|
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
x + border_width, y + border_width, 1, height - border_width, shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
x + border_width, y + border_width, width - border_width, 1, shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
x + width, y + 1, 1, height, shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
x + 1, y + height, width, 1, shadow_color);
|
|
}
|
|
|
|
/* Draw border */
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
x, y, width - border_width, border_width,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
x + width - border_width, y, border_width, height - border_width,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
x + border_width, y + height - border_width, width - border_width, border_width,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
x, y + border_width, border_width, height - border_width,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
|
|
/* Draw text */
|
|
for (i = 0; i < line_count; i++)
|
|
{
|
|
const char *msg = lines[i];
|
|
const char *path = menu_dialog_firmware_path_line(menu_st,
|
|
msg, &firmware_line_state);
|
|
int offset_x = (int)(rgui->font_width_stride * (glyphs_width - glyphs[i]) / 2);
|
|
int offset_y = (int)(rgui->font_height_stride * i);
|
|
int text_x = x + 8 + offset_x;
|
|
int text_y = y + 8 + offset_y;
|
|
|
|
/* Ensure we remain within the bounds of the
|
|
* framebuffer */
|
|
if (text_y > (int)fb_height - 10 - (int)rgui->font_height_stride)
|
|
break;
|
|
/* A box taller than the screen keeps its buttons */
|
|
if (buttons.count && text_y + (int)rgui->font_height_stride > rows_y)
|
|
break;
|
|
|
|
rgui_blit_line(rgui, fb_width, text_x, text_y, msg,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
|
|
if (path)
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
text_x + (path - msg) * rgui->font_width_stride,
|
|
text_y + VIDEO_SCALE_H(rgui->font_dims),
|
|
utf8len(path) * rgui->font_width_stride - 1, 1,
|
|
rgui->colors.normal_color);
|
|
}
|
|
|
|
if (buttons.count)
|
|
{
|
|
int cursor_h = (int)rgui->font_height_stride;
|
|
int hover = -1;
|
|
unsigned b;
|
|
|
|
if (button_rows == 1)
|
|
menu_dialog_buttons_layout(button_w, buttons.count,
|
|
(int)rgui->font_width_stride * 2, x + 8,
|
|
(int)(glyphs_width * rgui->font_width_stride), button_x);
|
|
else
|
|
for (b = 0; b < buttons.count; b++)
|
|
button_x[b] = x + ((int)width - button_w[b]) / 2;
|
|
|
|
for (b = 0; b < buttons.count; b++)
|
|
{
|
|
const char *str = msg_hash_to_str(
|
|
(enum msg_hash_enums)buttons.label[b]);
|
|
int label_y = rows_y
|
|
+ ((button_rows == 1) ? 0 : row_step * (int)b);
|
|
int cursor_y = label_y - 2;
|
|
/* A button wider than the screen is lit where it shows */
|
|
int fill_x = MAX(button_x[b], 0);
|
|
bool lit;
|
|
|
|
if ( VIDEO_POS_X(rgui->pointer.pos) >= button_x[b]
|
|
&& VIDEO_POS_X(rgui->pointer.pos) <= button_x[b] + button_w[b]
|
|
&& VIDEO_POS_Y(rgui->pointer.pos) >= cursor_y
|
|
&& VIDEO_POS_Y(rgui->pointer.pos) <= cursor_y + cursor_h)
|
|
hover = (int)b;
|
|
|
|
lit = ((int)b == buttons.highlight) || ((int)b == hover);
|
|
if (lit)
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
fill_x, cursor_y, button_w[b] - (fill_x - button_x[b]),
|
|
cursor_h,
|
|
rgui->colors.bg_dark_color, rgui->colors.bg_light_color,
|
|
(rgui->flags & RGUI_FLAG_BG_THICKNESS) ? true : false);
|
|
|
|
rgui_blit_line(rgui, fb_width,
|
|
button_x[b] + (int)rgui->font_width_stride, label_y, str,
|
|
lit ? rgui->colors.hover_color : rgui->colors.normal_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
|
|
menu_dialog_set_hover(menu_st, hover);
|
|
}
|
|
}
|
|
}
|
|
|
|
static bool rgui_osk_pointer_over_textbox(
|
|
void *data,
|
|
int x,
|
|
int y,
|
|
unsigned dims)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if (!rgui)
|
|
return false;
|
|
|
|
{
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
unsigned key_width = VIDEO_SCALE_W(rgui->font_dims) + 16;
|
|
unsigned key_height = VIDEO_SCALE_H(rgui->font_dims) + 12;
|
|
unsigned keyboard_offset_y = 10 + 15 + (2 * rgui->font_height_stride);
|
|
unsigned osk_width = (key_width * OSK_CHARS_PER_LINE) + 20;
|
|
unsigned osk_height = keyboard_offset_y + (key_height * 4) + 10;
|
|
unsigned osk_x = (VIDEO_SCALE_W(p_disp->framebuf_dims) - osk_width) / 2;
|
|
unsigned osk_y = (VIDEO_SCALE_H(p_disp->framebuf_dims) - osk_height) / 2;
|
|
|
|
return (unsigned)x > osk_x + 5
|
|
&& (unsigned)x < osk_x + osk_width - 5
|
|
&& (unsigned)y > osk_y + 5
|
|
&& (unsigned)y < osk_y + keyboard_offset_y - 10;
|
|
}
|
|
}
|
|
|
|
static int rgui_osk_ptr_at_pos(
|
|
void *data,
|
|
int x,
|
|
int y,
|
|
unsigned dims)
|
|
{
|
|
/* This is a lazy copy/paste from rgui_render_osk(),
|
|
* but it will do for now... */
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if (rgui)
|
|
{
|
|
size_t key_index;
|
|
const unsigned key_text_offset_x = 8;
|
|
const unsigned key_text_offset_y = 6;
|
|
const unsigned ptr_offset_x = 2;
|
|
const unsigned ptr_offset_y = 2;
|
|
const unsigned keyboard_offset_x = 10;
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
unsigned key_width = VIDEO_SCALE_W(rgui->font_dims) +(key_text_offset_x * 2);
|
|
unsigned key_height = VIDEO_SCALE_H(rgui->font_dims) +(key_text_offset_y * 2);
|
|
unsigned ptr_width = key_width - (ptr_offset_x * 2);
|
|
unsigned ptr_height = key_height - (ptr_offset_y * 2);
|
|
unsigned keyboard_width = key_width * OSK_CHARS_PER_LINE;
|
|
unsigned keyboard_height = key_height * 4;
|
|
unsigned keyboard_offset_y = 10 + 15 + (2 * rgui->font_height_stride);
|
|
unsigned osk_width = keyboard_width + 20;
|
|
unsigned osk_height = keyboard_offset_y + keyboard_height + 10;
|
|
/* Get dimensions/layout */
|
|
unsigned fb_width = VIDEO_SCALE_W(p_disp->framebuf_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(p_disp->framebuf_dims);
|
|
unsigned osk_x = (fb_width - osk_width) / 2;
|
|
unsigned osk_y = (fb_height - osk_height) / 2;
|
|
|
|
if ( (unsigned)x > osk_x + 5
|
|
&& (unsigned)x < osk_x + osk_width - 5
|
|
&& (unsigned)y > osk_y + keyboard_offset_y - 10
|
|
&& (unsigned)y < osk_y + osk_height - 5)
|
|
{
|
|
unsigned key_row = ((unsigned)y > osk_y + keyboard_offset_y)
|
|
? ((unsigned)y - osk_y - keyboard_offset_y) / key_height : 0;
|
|
unsigned key_column = ((unsigned)x > osk_x + keyboard_offset_x)
|
|
? ((unsigned)x - osk_x - keyboard_offset_x) / key_width : 0;
|
|
|
|
if (key_row > 3)
|
|
key_row = 3;
|
|
if (key_column > OSK_CHARS_PER_LINE - 1)
|
|
key_column = OSK_CHARS_PER_LINE - 1;
|
|
|
|
return (int)(key_row * OSK_CHARS_PER_LINE + key_column);
|
|
}
|
|
|
|
for (key_index = 0; key_index < 44; key_index++)
|
|
{
|
|
unsigned key_row = (unsigned)(key_index / OSK_CHARS_PER_LINE);
|
|
unsigned key_column = (unsigned)(key_index - (key_row * OSK_CHARS_PER_LINE));
|
|
|
|
unsigned osk_ptr_x = osk_x + keyboard_offset_x + ptr_offset_x + (key_column * key_width);
|
|
unsigned osk_ptr_y = osk_y + keyboard_offset_y + ptr_offset_y + (key_row * key_height);
|
|
|
|
if ((unsigned)x > osk_ptr_x && (unsigned)x < osk_ptr_x + ptr_width &&
|
|
(unsigned)y > osk_ptr_y && (unsigned)y < osk_ptr_y + ptr_height)
|
|
return (int)key_index;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_render_osk(
|
|
rgui_t *rgui,
|
|
uint16_t *frame_buf_data,
|
|
gfx_animation_ctx_ticker_t *ticker,
|
|
gfx_animation_ctx_ticker_smooth_t *ticker_smooth,
|
|
bool use_smooth_ticker,
|
|
unsigned fb_dims)
|
|
{
|
|
unsigned fb_width = VIDEO_SCALE_W(fb_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(fb_dims);
|
|
int key_index;
|
|
|
|
unsigned input_label_max_length;
|
|
unsigned input_str_max_length;
|
|
unsigned input_offset_x, input_offset_y;
|
|
|
|
unsigned key_width, key_height;
|
|
unsigned key_text_offset_x, key_text_offset_y;
|
|
unsigned ptr_width, ptr_height;
|
|
unsigned ptr_offset_x, ptr_offset_y;
|
|
|
|
unsigned keyboard_width, keyboard_height;
|
|
unsigned keyboard_offset_x, keyboard_offset_y;
|
|
|
|
unsigned osk_width, osk_height;
|
|
unsigned osk_x, osk_y;
|
|
|
|
size_t line_cursor = 0;
|
|
const char *line_text = input_driver_keyboard_line_view(&line_cursor);
|
|
bool textbox_focus = input_driver_keyboard_textbox_focus();
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
int osk_ptr = menu_st->osk_ptr;
|
|
char **osk_grid = menu_st->osk_grid;
|
|
const char *input_str = menu_input_dialog_get_buffer();
|
|
const char *input_label = menu_st->input_dialog_kb_label;
|
|
/* A system keyboard panel is up and owns text entry: draw the
|
|
* label and the entry field, but not a second set of keys on top
|
|
* of it. The grid is not iterated in that state either, so
|
|
* osk_grid may legitimately be empty. */
|
|
bool native_kb = input_osk_native_active();
|
|
|
|
/* Sanity check 1 */
|
|
if (!native_kb && (osk_ptr < 0 || osk_ptr >= 44 || !osk_grid[0]))
|
|
return;
|
|
|
|
key_text_offset_x = 8;
|
|
key_text_offset_y = 6;
|
|
key_width = VIDEO_SCALE_W(rgui->font_dims) + (key_text_offset_x * 2);
|
|
key_height = VIDEO_SCALE_H(rgui->font_dims) + (key_text_offset_y * 2);
|
|
ptr_offset_x = 2;
|
|
ptr_offset_y = 2;
|
|
ptr_width = key_width - (ptr_offset_x * 2);
|
|
ptr_height = key_height - (ptr_offset_y * 2);
|
|
keyboard_width = key_width * OSK_CHARS_PER_LINE;
|
|
keyboard_height = native_kb ? 0 : key_height * 4;
|
|
keyboard_offset_x = 10;
|
|
keyboard_offset_y = 10 + 15 + (2 * rgui->font_height_stride);
|
|
input_label_max_length = (keyboard_width / rgui->font_width_stride);
|
|
input_str_max_length = input_label_max_length - 1;
|
|
input_offset_x = 10 + (keyboard_width - (input_label_max_length * rgui->font_width_stride)) / 2;
|
|
input_offset_y = 10;
|
|
osk_width = keyboard_width + 20;
|
|
osk_height = keyboard_offset_y + keyboard_height + 10;
|
|
osk_x = (fb_width - osk_width) / 2;
|
|
osk_y = (fb_height - osk_height) / 2;
|
|
|
|
/* Sanity check 2 */
|
|
if ((osk_width + 2 > fb_width) || (osk_height + 2 > fb_height))
|
|
{
|
|
/* This can never happen, but have to make sure...
|
|
* If OSK cannot physically fit on the screen,
|
|
* fallback to old style 'message box' implementation */
|
|
char msg[NAME_MAX_LENGTH];
|
|
size_t _len = 0;
|
|
strlcpy_append(msg, sizeof(msg), &_len, input_label);
|
|
strlcpy_append(msg, sizeof(msg), &_len, "\n");
|
|
strlcpy_append(msg, sizeof(msg), &_len, input_str);
|
|
rgui_render_messagebox(rgui, msg, fb_dims);
|
|
return;
|
|
}
|
|
|
|
/* Draw background */
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
osk_x + 5, osk_y + 5, osk_width - 10, osk_height - 10,
|
|
rgui->colors.bg_dark_color, rgui->colors.bg_light_color,
|
|
(rgui->flags & RGUI_FLAG_BG_THICKNESS) ? true : false);
|
|
|
|
/* Draw border */
|
|
if (rgui->flags & RGUI_FLAG_BORDER_ENABLE)
|
|
{
|
|
uint16_t border_dark_color = rgui->colors.border_dark_color;
|
|
uint16_t border_light_color = rgui->colors.border_light_color;
|
|
bool border_thickness = (rgui->flags & RGUI_FLAG_BORDER_THICKNESS) ? true : false;
|
|
|
|
/* Draw drop shadow, if required */
|
|
if (rgui->flags & RGUI_FLAG_SHADOW_ENABLE)
|
|
{
|
|
uint16_t shadow_color = rgui->colors.shadow_color;
|
|
|
|
/* Frame */
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_x + 5, osk_y + 5, osk_width - 10, 1, shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_x + osk_width, osk_y + 1, 1, osk_height, shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_x + 1, osk_y + osk_height, osk_width, 1, shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_x + 5, osk_y + 5, 1, osk_height - 10, shadow_color);
|
|
/* Divider */
|
|
if (!native_kb)
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_x + 5, osk_y + keyboard_offset_y - 5, osk_width - 10, 1, shadow_color);
|
|
}
|
|
|
|
/* Frame */
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
osk_x, osk_y, osk_width - 5, 5,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
osk_x + osk_width - 5, osk_y, 5, osk_height - 5,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
osk_x + 5, osk_y + osk_height - 5, osk_width - 5, 5,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
osk_x, osk_y + 5, 5, osk_height - 5,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
/* Divider */
|
|
if (!native_kb)
|
|
rgui_fill_rect(frame_buf_data, fb_dims,
|
|
osk_x + 5, osk_y + keyboard_offset_y - 10, osk_width - 10, 5,
|
|
border_dark_color, border_light_color, border_thickness);
|
|
}
|
|
|
|
/* Draw input label text */
|
|
if (input_label && *input_label)
|
|
{
|
|
char input_label_buf[NAME_MAX_LENGTH];
|
|
unsigned input_label_length;
|
|
int input_label_x, input_label_y;
|
|
unsigned ticker_x_offset = 0;
|
|
|
|
input_label_buf[0] = '\0';
|
|
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth->selected = true;
|
|
ticker_smooth->field_width = input_label_max_length * rgui->font_width_stride;
|
|
ticker_smooth->src_str = input_label;
|
|
ticker_smooth->dst_str = input_label_buf;
|
|
ticker_smooth->dst_str_len = sizeof(input_label_buf);
|
|
ticker_smooth->x_offset = &ticker_x_offset;
|
|
|
|
gfx_animation_ticker_smooth(ticker_smooth);
|
|
}
|
|
else
|
|
{
|
|
ticker->s = input_label_buf;
|
|
ticker->len = input_label_max_length;
|
|
ticker->str = input_label;
|
|
ticker->selected = true;
|
|
|
|
gfx_animation_ticker(ticker);
|
|
}
|
|
|
|
input_label_length = (unsigned)(utf8len(input_label_buf) * rgui->font_width_stride);
|
|
input_label_x = ticker_x_offset + osk_x + input_offset_x
|
|
+ ((input_label_max_length * rgui->font_width_stride) - input_label_length) / 2;
|
|
input_label_y = osk_y + input_offset_y;
|
|
|
|
rgui_blit_line(rgui, fb_width, input_label_x, input_label_y, input_label_buf,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
}
|
|
|
|
/* Draw input buffer text */
|
|
{
|
|
int input_str_x, input_str_y;
|
|
int text_cursor_x;
|
|
unsigned input_str_char_offset = 0;
|
|
unsigned input_str_length = (unsigned)utf8len(input_str);
|
|
unsigned input_str_cursor = input_str_length;
|
|
static const char *last_cursor_buffer = NULL;
|
|
static size_t last_cursor_ptr = 0;
|
|
static retro_time_t last_cursor_time = 0;
|
|
retro_time_t current_time = menu_driver_get_current_time();
|
|
size_t cursor_ptr = input_str_cursor;
|
|
const char *input_str_visible = NULL;
|
|
|
|
if (input_str && line_text)
|
|
{
|
|
size_t ptr = line_cursor;
|
|
const char *cursor = line_text;
|
|
const char *end;
|
|
|
|
input_str_cursor = 0;
|
|
|
|
cursor_ptr = ptr;
|
|
end = cursor + ptr;
|
|
|
|
while (cursor < end && *cursor)
|
|
{
|
|
utf8_walk(&cursor);
|
|
input_str_cursor++;
|
|
}
|
|
}
|
|
|
|
if (input_str_length > input_str_max_length)
|
|
{
|
|
input_str_char_offset = (input_str_cursor > input_str_max_length)
|
|
? input_str_cursor - input_str_max_length : 0;
|
|
input_str_length = input_str_max_length;
|
|
}
|
|
|
|
input_str_x = osk_x + input_offset_x;
|
|
input_str_y = osk_y + input_offset_y + rgui->font_height_stride;
|
|
input_str_visible = utf8skip(input_str, input_str_char_offset);
|
|
|
|
if (input_driver_keyboard_line_selected())
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
input_str_x, input_str_y,
|
|
input_str_length * rgui->font_width_stride,
|
|
VIDEO_SCALE_H(rgui->font_dims), rgui->colors.hover_color);
|
|
|
|
if (input_str_visible && *input_str_visible)
|
|
rgui_blit_line(rgui, fb_width, input_str_x, input_str_y, input_str_visible,
|
|
input_driver_keyboard_line_selected()
|
|
? rgui->colors.bg_dark_color : rgui->colors.hover_color,
|
|
rgui->colors.shadow_color);
|
|
|
|
/* Draw text cursor */
|
|
text_cursor_x = osk_x + input_offset_x
|
|
+ ((input_str_cursor - input_str_char_offset)
|
|
* rgui->font_width_stride);
|
|
|
|
if ((last_cursor_buffer != line_text) || (last_cursor_ptr != cursor_ptr))
|
|
{
|
|
last_cursor_buffer = line_text;
|
|
last_cursor_ptr = cursor_ptr;
|
|
last_cursor_time = current_time;
|
|
}
|
|
|
|
if (textbox_focus)
|
|
{
|
|
unsigned input_ptr_x = osk_x + 5;
|
|
unsigned input_ptr_y = osk_y + 5;
|
|
unsigned input_ptr_width = osk_width - 10;
|
|
unsigned input_ptr_height = keyboard_offset_y - 15;
|
|
unsigned j;
|
|
|
|
for (j = 0; j < 4; j++)
|
|
{
|
|
unsigned rect_x = (j == 3) ? input_ptr_x + input_ptr_width - 1 : input_ptr_x;
|
|
unsigned rect_y = (j == 1) ? input_ptr_y + input_ptr_height - 1 : input_ptr_y;
|
|
unsigned rect_w = (j < 2) ? input_ptr_width : 1;
|
|
unsigned rect_h = (j < 2) ? 1 : input_ptr_height;
|
|
|
|
if (rgui->flags & RGUI_FLAG_SHADOW_ENABLE)
|
|
rgui_color_rect(
|
|
frame_buf_data,
|
|
fb_dims,
|
|
rect_x + 1,
|
|
rect_y + 1,
|
|
rect_w,
|
|
rect_h,
|
|
rgui->colors.shadow_color);
|
|
|
|
rgui_color_rect(
|
|
frame_buf_data,
|
|
fb_dims,
|
|
rect_x,
|
|
rect_y,
|
|
rect_w,
|
|
rect_h,
|
|
rgui->colors.hover_color);
|
|
}
|
|
}
|
|
|
|
if (!input_driver_keyboard_line_selected()
|
|
&& !(((current_time - last_cursor_time) / 500000) & 1))
|
|
rgui_blit_symbol(rgui, fb_width, text_cursor_x, input_str_y, RGUI_SYMBOL_TEXT_CURSOR,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
}
|
|
|
|
/* Draw keyboard 'keys' */
|
|
if (native_kb)
|
|
return;
|
|
|
|
for (key_index = 0; key_index < 44; key_index++)
|
|
{
|
|
unsigned key_row = (unsigned)(key_index / OSK_CHARS_PER_LINE);
|
|
unsigned key_column = (unsigned)(key_index - (key_row * OSK_CHARS_PER_LINE));
|
|
|
|
int key_text_x = osk_x + keyboard_offset_x + key_text_offset_x + (key_column * key_width);
|
|
int key_text_y = osk_y + keyboard_offset_y + key_text_offset_y + (key_row * key_height);
|
|
|
|
const char *key_text = osk_grid[key_index];
|
|
|
|
/* 'Command' keys use custom symbols - have to
|
|
* detect them and use rgui_blit_symbol(). Everything
|
|
* else is plain text, and can be drawn directly
|
|
* using rgui_blit_line(). */
|
|
#ifdef HAVE_LANGEXTRA
|
|
if ( string_is_equal(key_text, "\xe2\x87\xa6")) /* backspace character */
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_BACKSPACE,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "\xe2\x8f\x8e")) /* return character */
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_ENTER,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "\xe2\x87\xa7")) /* up arrow */
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_SHIFT_UP,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "\xe2\x87\xa9")) /* down arrow */
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_SHIFT_DOWN,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "\xe2\x8a\x95")) /* plus sign (next button) */
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_NEXT,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
#else
|
|
if ( string_is_equal(key_text, "Bksp"))
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_BACKSPACE,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "Enter"))
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_ENTER,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "Upper"))
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_SHIFT_UP,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "Lower"))
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_SHIFT_DOWN,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else if (string_is_equal(key_text, "Next"))
|
|
rgui_blit_symbol(rgui, fb_width, key_text_x, key_text_y, RGUI_SYMBOL_NEXT,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
#endif
|
|
else
|
|
rgui_blit_line(rgui, fb_width, key_text_x, key_text_y, key_text,
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
|
|
/* Draw selection pointer */
|
|
if (!textbox_focus && (key_index == osk_ptr))
|
|
{
|
|
unsigned osk_ptr_x = osk_x + keyboard_offset_x + ptr_offset_x + (key_column * key_width);
|
|
unsigned osk_ptr_y = osk_y + keyboard_offset_y + ptr_offset_y + (key_row * key_height);
|
|
|
|
/* Draw drop shadow, if required */
|
|
if (rgui->flags & RGUI_FLAG_SHADOW_ENABLE)
|
|
{
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x + 1, osk_ptr_y + 1, 1, ptr_height, rgui->colors.shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x + 1, osk_ptr_y + 1, ptr_width, 1, rgui->colors.shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x + ptr_width, osk_ptr_y + 1, 1, ptr_height, rgui->colors.shadow_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x + 1, osk_ptr_y + ptr_height, ptr_width, 1, rgui->colors.shadow_color);
|
|
}
|
|
|
|
/* Draw selection rectangle */
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x, osk_ptr_y, 1, ptr_height, rgui->colors.hover_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x, osk_ptr_y, ptr_width, 1, rgui->colors.hover_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x + ptr_width - 1, osk_ptr_y, 1, ptr_height, rgui->colors.hover_color);
|
|
rgui_color_rect(frame_buf_data, fb_dims,
|
|
osk_ptr_x, osk_ptr_y + ptr_height - 1, ptr_width, 1, rgui->colors.hover_color);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rgui_render_toggle_switch(
|
|
rgui_t *rgui,
|
|
unsigned fb_width,
|
|
int x,
|
|
int y,
|
|
bool on,
|
|
uint16_t color,
|
|
uint16_t shadow_color)
|
|
{
|
|
int x_current = x;
|
|
|
|
/* Toggle switch is just 3 adjacent symbols
|
|
* > Note that we indent the left/right symbols
|
|
* by 1 pixel, to avoid the gap that is normally
|
|
* present between symbols/characters */
|
|
rgui_blit_symbol(rgui, fb_width, x_current + 1, y,
|
|
on ? RGUI_SYMBOL_SWITCH_ON_LEFT : RGUI_SYMBOL_SWITCH_OFF_LEFT,
|
|
color, shadow_color);
|
|
x_current += RGUI_SYMBOL_WIDTH_STRIDE;
|
|
|
|
rgui_blit_symbol(rgui, fb_width, x_current, y,
|
|
on ? RGUI_SYMBOL_SWITCH_ON_CENTRE : RGUI_SYMBOL_SWITCH_OFF_CENTRE,
|
|
color, shadow_color);
|
|
x_current += RGUI_SYMBOL_WIDTH_STRIDE;
|
|
|
|
rgui_blit_symbol(rgui, fb_width, x_current - 1, y,
|
|
on ? RGUI_SYMBOL_SWITCH_ON_RIGHT : RGUI_SYMBOL_SWITCH_OFF_RIGHT,
|
|
color, shadow_color);
|
|
}
|
|
|
|
static enum rgui_entry_value_type rgui_get_entry_value_type(
|
|
const char *entry_value,
|
|
uint8_t entry_setting_type,
|
|
bool entry_checked,
|
|
bool switch_icons_enabled)
|
|
{
|
|
if (entry_value && *entry_value)
|
|
{
|
|
if (switch_icons_enabled && entry_setting_type == ST_BOOL)
|
|
{
|
|
/* Toggle switch off */
|
|
if ( string_is_equal(entry_value, msg_hash_to_str(MENU_ENUM_LABEL_DISABLED))
|
|
|| string_is_equal(entry_value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF)))
|
|
return RGUI_ENTRY_VALUE_SWITCH_OFF;
|
|
/* Toggle switch on */
|
|
else if ( string_is_equal(entry_value, msg_hash_to_str(MENU_ENUM_LABEL_ENABLED))
|
|
|| string_is_equal(entry_value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ON)))
|
|
return RGUI_ENTRY_VALUE_SWITCH_ON;
|
|
}
|
|
else if (string_is_equal(entry_value, "(RDB)"))
|
|
return RGUI_ENTRY_VALUE_NONE;
|
|
return RGUI_ENTRY_VALUE_TEXT;
|
|
}
|
|
else if (entry_checked)
|
|
return RGUI_ENTRY_VALUE_CHECKMARK;
|
|
return RGUI_ENTRY_VALUE_NONE;
|
|
}
|
|
|
|
#if defined(GEKKO)
|
|
/* Need to forward declare this for the Wii build
|
|
* (I'm not going to reorder the functions and mess
|
|
* up the git diff for a single platform...) */
|
|
static bool rgui_set_aspect_ratio(
|
|
rgui_t *rgui,
|
|
gfx_display_t *p_disp,
|
|
bool delay_update,
|
|
unsigned aspect_ratio,
|
|
unsigned aspect_ratio_lock);
|
|
#endif
|
|
|
|
/* Forward: rgui_render()'s pending-aspect pump and its
|
|
* framebuffer-resize flush both run before the definitions. */
|
|
static void rgui_apply_video_config(
|
|
const rgui_video_settings_t *video_settings);
|
|
static void rgui_flush_video_config(rgui_t *rgui);
|
|
|
|
/* Fetches current thumbnail label.
|
|
* Returns true if label is valid. */
|
|
static bool gfx_thumbnail_get_label(
|
|
gfx_thumbnail_path_data_t *path_data, const char **label)
|
|
{
|
|
if (!path_data || !label || !*path_data->content_label)
|
|
return false;
|
|
*label = string_is_equal(path_data->content_core_name, "imageviewer")
|
|
&& *path_data->content_path ? path_basename(path_data->content_path)
|
|
: path_data->content_label;
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Moves the list by whole rows while keeping the selection the
|
|
* same.
|
|
* Returns true whenever the list is what the wheel drives, even
|
|
* where it has nowhere to go, so that a notch never steps the
|
|
* selection. False falls back to that step. */
|
|
static bool rgui_wheel_scroll(void *data, int notches)
|
|
{
|
|
int start;
|
|
int bottom;
|
|
size_t entries_end;
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
menu_list_t *menu_list = menu_st->entries.list;
|
|
|
|
if (!rgui || !menu_list)
|
|
return false;
|
|
|
|
/* A fullscreen thumbnail hides the list, and the wheel is
|
|
* better spent stepping through the playlist behind it. */
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
return false;
|
|
|
|
entries_end = MENU_LIST_GET_SELECTION(menu_list, 0)->size;
|
|
bottom = (int)entries_end - (int)rgui->term_layout.height;
|
|
start = (int)menu_st->entries.begin + (notches * RGUI_WHEEL_SCROLL_ROWS);
|
|
if (start > bottom)
|
|
start = bottom;
|
|
if (start < 0)
|
|
start = 0;
|
|
|
|
menu_st->entries.begin = (size_t)start;
|
|
rgui->scroll_y = start * (int32_t)rgui->font_height_stride;
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
return true;
|
|
}
|
|
|
|
static void rgui_media_gpu_cutout(rgui_t *rgui, unsigned dims)
|
|
{
|
|
const rgui_media_gpu_view_t *view = &rgui->media_gpu_pending;
|
|
const gfx_media_rect_t *rect = &view->rect;
|
|
gfx_thumbnail_t thumbnail;
|
|
float width, height, left, top;
|
|
int x, y, right, bottom;
|
|
if (!view->visible || rect->w <= 0 || rect->h <= 0)
|
|
return;
|
|
gfx_thumbnail_init_blank(&thumbnail);
|
|
thumbnail.dims = view->texture_dims;
|
|
thumbnail.flags = view->flags;
|
|
retro_atomic_store_release_int(&thumbnail.status, GFX_THUMBNAIL_STATUS_AVAILABLE);
|
|
gfx_thumbnail_get_draw_dimensions(&thumbnail,
|
|
VIDEO_SCALE_PACK(rect->w, rect->h), 1.0f, &width, &height);
|
|
left = rect->x + (rect->w - width) * 0.5f;
|
|
top = rect->y + (rect->h - height) * 0.5f;
|
|
x = (int)floor(left);
|
|
y = (int)floor(top);
|
|
right = (int)ceil(left + width);
|
|
bottom = (int)ceil(top + height);
|
|
if (x < 0) x = 0;
|
|
if (y < 0) y = 0;
|
|
if (right <= x || bottom <= y)
|
|
return;
|
|
/* Some drivers composite the software menu after the GPU picture. */
|
|
rgui_color_rect(rgui->frame_buf.data, dims, x, y,
|
|
(unsigned)(right - x), (unsigned)(bottom - y), 0);
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_media_subtitle_draw(rgui_t *rgui, unsigned dims)
|
|
{
|
|
char wrapped[GFX_MEDIA_SUBTITLE_TEXT_SIZE];
|
|
char *lines[8];
|
|
char *line;
|
|
unsigned count = 0, i;
|
|
unsigned width = VIDEO_SCALE_W(dims);
|
|
unsigned height = VIDEO_SCALE_H(dims);
|
|
unsigned columns;
|
|
int bottom;
|
|
gfx_media_subtitle_consume(&rgui->media.subtitle_mailbox,
|
|
&rgui->media.subtitle_view);
|
|
if (!rgui->media.subtitle_view.text[0] || !rgui->font_width_stride
|
|
|| !rgui->font_height_stride || width < 96 || height < 96)
|
|
return;
|
|
columns = width * 4 / (5 * rgui->font_width_stride);
|
|
wrapped[0] = '\0';
|
|
word_wrap(wrapped, sizeof(wrapped), rgui->media.subtitle_view.text,
|
|
strlen(rgui->media.subtitle_view.text), columns, 100, 8);
|
|
line = wrapped;
|
|
while (*line && count < ARRAY_SIZE(lines))
|
|
{
|
|
char *next = strchr(line, '\n');
|
|
lines[count++] = line;
|
|
if (!next)
|
|
break;
|
|
*next = '\0';
|
|
line = next + 1;
|
|
}
|
|
bottom = rgui->media.view.visible ? rgui->media.view.layout.panel.y - 2
|
|
: (int)height - (int)rgui->font_height_stride;
|
|
for (i = 0; i < count; i++)
|
|
{
|
|
size_t len = utf8len(lines[i]);
|
|
unsigned glyphs;
|
|
int x, y;
|
|
if (len > columns)
|
|
{
|
|
char *end = (char*)utf8skip(lines[i], columns);
|
|
*end = '\0';
|
|
glyphs = columns;
|
|
}
|
|
else
|
|
glyphs = (unsigned)len;
|
|
x = (width - glyphs * rgui->font_width_stride) / 2;
|
|
y = bottom - ((int)count - (int)i) * rgui->font_height_stride;
|
|
if (y < (int)rgui->font_height_stride)
|
|
continue;
|
|
rgui_color_rect(rgui->frame_buf.data, dims, x - 2, y - 1,
|
|
glyphs * rgui->font_width_stride + 4, rgui->font_height_stride,
|
|
rgui->colors.shadow_color);
|
|
if (rgui->fonts.regular
|
|
&& rgui->font_dims == VIDEO_SCALE_PACK(FONT_WIDTH, FONT_HEIGHT))
|
|
rgui_blit_line_extended(rgui, width, x, y, lines[i],
|
|
rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
else
|
|
rgui_blit_line(rgui, width, x, y, lines[i], rgui->colors.normal_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_media_draw(rgui_t *rgui, unsigned dims)
|
|
{
|
|
gfx_media_view_t *view = &rgui->media.view;
|
|
gfx_media_rect_t bar;
|
|
unsigned i, width = VIDEO_SCALE_W(dims);
|
|
int64_t position;
|
|
char elapsed[24], duration[24], caption[56];
|
|
char seek_back[16], seek_forward[16];
|
|
size_t limit;
|
|
const char *labels[8];
|
|
gfx_media_controls_consume(&rgui->media.mailbox, view);
|
|
rgui_media_subtitle_draw(rgui, dims);
|
|
if (!view->visible || !view->layout.unit) return;
|
|
bar = view->layout.panel;
|
|
rgui_color_rect(rgui->frame_buf.data, dims, bar.x, bar.y, bar.w, bar.h,
|
|
rgui->colors.shadow_color);
|
|
bar = view->layout.timeline;
|
|
rgui_color_rect(rgui->frame_buf.data, dims, bar.x, bar.y, bar.w, bar.h,
|
|
rgui->colors.bg_light_color);
|
|
position = view->dragging ? view->drag_us : view->playback.position_us;
|
|
if (view->playback.duration_us > 0)
|
|
{
|
|
double fraction = (double)position / (double)view->playback.duration_us;
|
|
if (fraction < 0.0) fraction = 0.0;
|
|
if (fraction > 1.0) fraction = 1.0;
|
|
bar.w = (int)(bar.w * fraction);
|
|
rgui_color_rect(rgui->frame_buf.data, dims, bar.x, bar.y, bar.w, bar.h,
|
|
rgui->colors.hover_color);
|
|
}
|
|
menu_media_controls_time(elapsed, sizeof(elapsed), position);
|
|
menu_media_controls_time(duration, sizeof(duration), view->playback.duration_us);
|
|
snprintf(caption, sizeof(caption), "%s / %s", elapsed, duration);
|
|
limit = rgui->font_width_stride
|
|
? (width - view->layout.timeline.x - 2) / rgui->font_width_stride : 0;
|
|
if (limit < sizeof(caption)) caption[limit] = '\0';
|
|
rgui_blit_line(rgui, width, view->layout.timeline.x,
|
|
view->layout.panel.y + 1, caption, rgui->colors.normal_color,
|
|
rgui->colors.shadow_color);
|
|
labels[0] = view->playback.paused ? ">" : "||";
|
|
snprintf(seek_back, sizeof(seek_back), "-%u", view->seek_seconds);
|
|
snprintf(seek_forward, sizeof(seek_forward), "+%u", view->seek_seconds);
|
|
labels[1] = seek_back; labels[2] = seek_forward; labels[3] = "[]";
|
|
labels[4] = "|<";
|
|
labels[5] = ">|";
|
|
labels[6] = "...";
|
|
if (view->subtitle_tracks)
|
|
labels[view->layout.button_count - 1] = "CC";
|
|
for (i = 0; i < view->layout.button_count; i++)
|
|
{
|
|
const gfx_media_rect_t *button = &view->layout.buttons[i];
|
|
bool focused = (view->row_focus && view->focus == i) || view->hover == (int)i;
|
|
bool enabled = (view->subtitle_tracks && i + 1 == view->layout.button_count)
|
|
|| i == 6 || (i >= 4
|
|
? (view->directions & (i == 4 ? 1u : 2u)) != 0
|
|
: !i || view->playback.seekable);
|
|
int x = button->x + (button->w - (int)(strlen(labels[i]) * rgui->font_width_stride)) / 2;
|
|
int y = button->y + (button->h - (int)VIDEO_SCALE_H(rgui->font_dims)) / 2;
|
|
rgui_color_rect(rgui->frame_buf.data, dims, button->x, button->y,
|
|
button->w, button->h, focused ? rgui->colors.border_light_color
|
|
: rgui->colors.bg_dark_color);
|
|
rgui_blit_line(rgui, width, x, y, labels[i], enabled
|
|
? rgui->colors.normal_color : rgui->colors.disabled_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
if (view->subtitle_tracks)
|
|
{
|
|
char track[160];
|
|
size_t columns = rgui->font_width_stride
|
|
? view->layout.timeline.w / rgui->font_width_stride : 0;
|
|
menu_media_controls_subtitle_caption(&rgui->media.subtitle_view, track, sizeof(track));
|
|
if (utf8len(track) > columns)
|
|
*(char*)utf8skip(track, columns) = '\0';
|
|
rgui_blit_line(rgui, width, view->layout.timeline.x,
|
|
view->layout.panel.y + 3 * view->layout.unit + view->layout.unit / 2,
|
|
track, rgui->colors.normal_color, rgui->colors.shadow_color);
|
|
}
|
|
|
|
}
|
|
|
|
static void rgui_render(void *data, unsigned dims,
|
|
bool is_idle)
|
|
{
|
|
unsigned x, y;
|
|
unsigned fb_width;
|
|
gfx_animation_ctx_ticker_t ticker;
|
|
size_t i, end, fb_pitch, old_start, new_start;
|
|
gfx_animation_ctx_ticker_smooth_t ticker_smooth;
|
|
static bool display_kb = false;
|
|
int bottom = 0;
|
|
unsigned ticker_x_offset = 0;
|
|
size_t entries_end = 0;
|
|
bool msg_force = false;
|
|
bool fb_size_changed = false;
|
|
settings_t *settings = config_get_ptr();
|
|
gfx_animation_t *p_anim = anim_get_ptr();
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
menu_input_t *menu_input = &menu_st->input_state;
|
|
menu_list_t *menu_list = menu_st->entries.list;
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
enum gfx_animation_ticker_type
|
|
menu_ticker_type = (enum gfx_animation_ticker_type)settings->uints.menu_ticker_type;
|
|
bool rgui_inline_thumbnails = settings->bools.menu_rgui_inline_thumbnails || (rgui->flags & RGUI_FLAG_IS_QUICK_MENU);
|
|
bool menu_battery_level_enable = settings->bools.menu_battery_level_enable;
|
|
bool use_smooth_ticker = settings->bools.menu_ticker_smooth;
|
|
bool thumbnail_background = settings->bools.menu_thumbnail_background_enable;
|
|
bool rgui_swap_thumbnails = settings->bools.menu_rgui_swap_thumbnails;
|
|
bool rgui_full_width_layout = settings->bools.menu_rgui_full_width_layout;
|
|
bool rgui_switch_icons = settings->bools.menu_rgui_switch_icons;
|
|
bool menu_show_sublabels = settings->bools.menu_show_sublabels;
|
|
bool video_fullscreen = settings->bools.video_fullscreen;
|
|
bool menu_mouse_enable = settings->bools.menu_mouse_enable;
|
|
bool menu_core_enable = settings->bools.menu_core_enable;
|
|
bool menu_timedate_enable = settings->bools.menu_timedate_enable;
|
|
float menu_rgui_particle_effect_speed
|
|
= settings->floats.menu_rgui_particle_effect_speed;
|
|
bool menu_rgui_particle_effect_screensaver
|
|
= settings->bools.menu_rgui_particle_effect_screensaver;
|
|
bool current_display_cb = false;
|
|
bool show_fs_thumbnail = (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL);
|
|
const char *msgbox = NULL;
|
|
|
|
/* Sanity check */
|
|
if (!rgui || !rgui->frame_buf.data)
|
|
return;
|
|
|
|
/* This iteration's box, if it has one; a box gone since it was
|
|
* drawn is painted over */
|
|
msgbox = rgui->msgbox;
|
|
rgui->msgbox = NULL;
|
|
if (!msgbox && *rgui->msgbox_drawn)
|
|
{
|
|
rgui->msgbox_drawn[0] = '\0';
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
/* Show thumbnails only after certain period to prevent flashing */
|
|
if (rgui->mini_thumbnail_delay > 0)
|
|
{
|
|
rgui_inline_thumbnails = false;
|
|
rgui->mini_thumbnail_delay--;
|
|
}
|
|
|
|
/* Apply pending aspect ratio update: the staged settings writes
|
|
* land here, on the thread that owns them, before the command
|
|
* that consumes them fires. */
|
|
if (rgui->flags & RGUI_FLAG_ASPECT_UPDATE_PENDING)
|
|
{
|
|
rgui_apply_video_config(&rgui->pending_video_config);
|
|
command_event(CMD_EVENT_VIDEO_SET_ASPECT_RATIO, NULL);
|
|
rgui->flags &= ~RGUI_FLAG_ASPECT_UPDATE_PENDING;
|
|
}
|
|
|
|
/* Refresh current menu, if required */
|
|
if (rgui->flags & RGUI_FLAG_FORCE_MENU_REFRESH)
|
|
{
|
|
menu_st->flags |= MENU_ST_FLAG_ENTRIES_NEED_REFRESH
|
|
| MENU_ST_FLAG_PREVENT_POPULATE;
|
|
/* Menu entries may change as a result of the
|
|
* refresh; skip rendering of the 'obsolete'
|
|
* menu this frame, and force a redraw of the
|
|
* updated menu on the next frame */
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
rgui->flags &= ~RGUI_FLAG_FORCE_MENU_REFRESH;
|
|
return;
|
|
}
|
|
|
|
rgui_media_update(rgui, p_disp->framebuf_dims);
|
|
show_fs_thumbnail = (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL);
|
|
current_display_cb = menu_input_dialog_get_display_kb();
|
|
|
|
if (!(rgui->flags & RGUI_FLAG_FORCE_REDRAW))
|
|
{
|
|
msg_force = p_disp->flags & GFX_DISP_FLAG_MSG_FORCE;
|
|
|
|
if (MENU_ENTRIES_NEEDS_REFRESH(menu_st) && !msg_force)
|
|
return;
|
|
|
|
if ( !display_kb &&
|
|
!current_display_cb &&
|
|
(is_idle || !GFX_DISPLAY_GET_UPDATE_PENDING(p_anim, p_disp)))
|
|
return;
|
|
}
|
|
|
|
display_kb = current_display_cb;
|
|
fb_width = VIDEO_SCALE_W(p_disp->framebuf_dims);
|
|
fb_pitch = p_disp->framebuf_pitch;
|
|
|
|
/* If the framebuffer changed size, or the background config has
|
|
* changed, recache the background buffer */
|
|
fb_size_changed = (rgui->last_dims
|
|
!= p_disp->framebuf_dims);
|
|
|
|
#if defined(GEKKO)
|
|
/* Wii gfx driver changes menu framebuffer size at
|
|
* will... If a change is detected, all texture buffers
|
|
* must be regenerated - easiest way is to just call
|
|
* rgui_set_aspect_ratio() */
|
|
if (fb_size_changed)
|
|
{
|
|
rgui_set_aspect_ratio(rgui, p_disp, false,
|
|
settings->uints.menu_rgui_aspect_ratio,
|
|
settings->uints.menu_rgui_aspect_ratio_lock);
|
|
rgui_flush_video_config(rgui);
|
|
}
|
|
#endif
|
|
|
|
if ( (rgui->flags & RGUI_FLAG_BG_MODIFIED)
|
|
|| (fb_size_changed))
|
|
{
|
|
/* Only regenerate the background if we are *not*
|
|
* currently showing a wallpaper image */
|
|
if (!(rgui->flags & RGUI_FLAG_SHOW_WALLPAPER))
|
|
rgui_cache_background(rgui, p_disp->framebuf_dims, fb_pitch);
|
|
|
|
/* Reinitialise particle effect, if required */
|
|
if ( fb_size_changed
|
|
&& (rgui->particle_effect != RGUI_PARTICLE_EFFECT_NONE))
|
|
rgui_init_particle_effect(rgui, p_disp);
|
|
|
|
rgui->last_dims = p_disp->framebuf_dims;
|
|
}
|
|
|
|
if (rgui->flags & RGUI_FLAG_BG_MODIFIED)
|
|
rgui->flags &= ~RGUI_FLAG_BG_MODIFIED;
|
|
|
|
p_disp->flags |= GFX_DISP_FLAG_FB_DIRTY;
|
|
GFX_ANIMATION_CLEAR_ACTIVE(p_anim);
|
|
|
|
rgui->flags &= ~RGUI_FLAG_FORCE_REDRAW;
|
|
|
|
entries_end = menu_list ? MENU_LIST_GET_SELECTION(menu_list, 0)->size : 0;
|
|
|
|
/* Get offset of bottommost entry */
|
|
bottom = (int)(entries_end - rgui->term_layout.height);
|
|
old_start = menu_st->entries.begin;
|
|
|
|
if (old_start > (unsigned)bottom)
|
|
menu_st->entries.begin = (size_t)bottom;
|
|
|
|
/* Handle pointer input
|
|
* Note: This is ignored when showing a fullscreen thumbnail */
|
|
if ( (rgui->pointer.type != MENU_POINTER_DISABLED)
|
|
&& (rgui->pointer.flags & MENU_INP_PTR_FLG_ACTIVE)
|
|
&& !show_fs_thumbnail)
|
|
{
|
|
/* Update currently 'highlighted' item */
|
|
if (VIDEO_POS_Y(rgui->pointer.pos) > (int)rgui->term_layout.start_y)
|
|
{
|
|
old_start = menu_st->entries.begin;
|
|
/* NOTE: It's okay for this to go out of range
|
|
* (limits are checked in rgui_pointer_up()) */
|
|
menu_input->ptr = (unsigned)(((VIDEO_POS_Y(rgui->pointer.pos) - rgui->term_layout.start_y) / rgui->font_height_stride) + old_start);
|
|
}
|
|
|
|
/* Allow drag-scrolling if items are currently off-screen */
|
|
if ( (rgui->pointer.flags & MENU_INP_PTR_FLG_DRAGGED)
|
|
&& (bottom > 0))
|
|
{
|
|
int32_t scroll_y_max = bottom * (int32_t)rgui->font_height_stride;
|
|
rgui->scroll_y += -1 * VIDEO_POS_Y(rgui->pointer.delta);
|
|
if (rgui->scroll_y < 0)
|
|
rgui->scroll_y = 0;
|
|
if (rgui->scroll_y > scroll_y_max)
|
|
rgui->scroll_y = scroll_y_max;
|
|
|
|
menu_st->entries.begin = rgui->scroll_y / rgui->font_height_stride;
|
|
}
|
|
}
|
|
|
|
/* Start position may have changed - get current
|
|
* value and determine index of last displayed entry */
|
|
old_start = menu_st->entries.begin;
|
|
end = ((old_start + rgui->term_layout.height) <= entries_end)
|
|
? old_start + rgui->term_layout.height
|
|
: entries_end;
|
|
|
|
/* Do not scroll if all items are visible. */
|
|
if (entries_end <= rgui->term_layout.height)
|
|
menu_st->entries.begin = 0;
|
|
|
|
/* Render background */
|
|
rgui_render_background(rgui, p_disp->framebuf_dims, fb_pitch);
|
|
|
|
/* Render particle effect, if required */
|
|
if (rgui->particle_effect != RGUI_PARTICLE_EFFECT_NONE)
|
|
rgui_render_particle_effect(rgui, p_anim, rgui->frame_buf.data,
|
|
menu_rgui_particle_effect_speed,
|
|
menu_rgui_particle_effect_screensaver,
|
|
p_disp->framebuf_dims);
|
|
|
|
/* If screensaver is active, skip drawing of
|
|
* text/thumbnails */
|
|
if (rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER)
|
|
return;
|
|
|
|
/* We use a single ticker for all text animations,
|
|
* with the following configuration: */
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth.idx = p_anim->ticker_pixel_idx;
|
|
ticker_smooth.font = NULL;
|
|
ticker_smooth.glyph_width = rgui->font_width_stride;
|
|
ticker_smooth.type_enum = menu_ticker_type;
|
|
ticker_smooth.spacer = RGUI_TICKER_SPACER;
|
|
ticker_smooth.dst_str_width = NULL;
|
|
}
|
|
else
|
|
{
|
|
ticker.idx = p_anim->ticker_idx;
|
|
ticker.type_enum = menu_ticker_type;
|
|
ticker.spacer = RGUI_TICKER_SPACER;
|
|
}
|
|
|
|
/* Note: On-screen keyboard takes precedence over
|
|
* normal menu thumbnail/text list display modes */
|
|
if (current_display_cb)
|
|
rgui_render_osk(rgui, rgui->frame_buf.data,
|
|
&ticker, &ticker_smooth, use_smooth_ticker,
|
|
p_disp->framebuf_dims);
|
|
else if (show_fs_thumbnail)
|
|
{
|
|
/* If fullscreen thumbnails are enabled and we are viewing a playlist,
|
|
* switch to fullscreen thumbnail view mode if either current thumbnail
|
|
* is valid or we are waiting for current thumbnail to load
|
|
* (if load is pending we'll get a blank screen + title, but
|
|
* this is better than switching back to the text playlist
|
|
* view, which causes ugly flickering when scrolling quickly
|
|
* through a list...) */
|
|
char thumbnail_title_buf[NAME_MAX_LENGTH];
|
|
unsigned title_x, title_width;
|
|
const char *thumbnail_title = NULL;
|
|
bool is_state_slot = *rgui->savestate_thumbnail_file_path;
|
|
thumbnail_title_buf[0] = '\0';
|
|
|
|
/* Draw thumbnail */
|
|
rgui_render_fs_thumbnail(rgui, p_disp->framebuf_dims, fb_pitch);
|
|
rgui_media_gpu_cutout(rgui, p_disp->framebuf_dims);
|
|
rgui_media_draw(rgui, p_disp->framebuf_dims);
|
|
|
|
/* Get thumbnail title */
|
|
if ( gfx_thumbnail_get_label(menu_st->thumbnail_path_data, &thumbnail_title)
|
|
|| is_state_slot)
|
|
{
|
|
/* State slot title */
|
|
if (is_state_slot)
|
|
{
|
|
menu_update_fullscreen_thumbnail_label(
|
|
thumbnail_title_buf,
|
|
sizeof(thumbnail_title_buf),
|
|
(rgui->flags & RGUI_FLAG_IS_QUICK_MENU) ? true : false,
|
|
NULL);
|
|
thumbnail_title = thumbnail_title_buf;
|
|
}
|
|
|
|
/* Format thumbnail title */
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth.selected = true;
|
|
ticker_smooth.field_width = (rgui->term_layout.width) * rgui->font_width_stride;
|
|
ticker_smooth.src_str = thumbnail_title;
|
|
ticker_smooth.dst_str = thumbnail_title_buf;
|
|
ticker_smooth.dst_str_len = sizeof(thumbnail_title_buf);
|
|
ticker_smooth.x_offset = &ticker_x_offset;
|
|
|
|
/* If title is scrolling, then width == field_width */
|
|
if (gfx_animation_ticker_smooth(&ticker_smooth))
|
|
title_width = ticker_smooth.field_width;
|
|
else
|
|
title_width = (unsigned)(utf8len(thumbnail_title_buf) * rgui->font_width_stride);
|
|
}
|
|
else
|
|
{
|
|
ticker.s = thumbnail_title_buf;
|
|
ticker.s_len = sizeof(thumbnail_title_buf);
|
|
ticker.len = rgui->term_layout.width;
|
|
ticker.str = thumbnail_title;
|
|
ticker.selected = true;
|
|
|
|
gfx_animation_ticker(&ticker);
|
|
|
|
title_width = (unsigned)(utf8len(thumbnail_title_buf) * rgui->font_width_stride);
|
|
}
|
|
|
|
title_x = (unsigned)(rgui->term_layout.start_x
|
|
+ ((rgui->term_layout.width * rgui->font_width_stride)
|
|
- title_width) / 2);
|
|
|
|
/* Draw thumbnail title background */
|
|
rgui_fill_rect(rgui->frame_buf.data, p_disp->framebuf_dims,
|
|
title_x - 5, 0, title_width + 10, rgui->font_height_stride - 1,
|
|
rgui->colors.shadow_color, rgui->colors.shadow_color,
|
|
(rgui->flags & RGUI_FLAG_BG_THICKNESS) ? true : false);
|
|
|
|
/* Draw thumbnail title */
|
|
rgui_blit_line(rgui, fb_width, ticker_x_offset + title_x,
|
|
0, thumbnail_title_buf,
|
|
rgui->colors.hover_color, rgui->colors.shadow_color);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* Render usual text */
|
|
unsigned title_x;
|
|
size_t title_max_len;
|
|
char title_buf[NAME_MAX_LENGTH];
|
|
size_t selection = menu_st->selection_ptr;
|
|
unsigned title_y = rgui->term_layout.start_y - rgui->font_height_stride - 1;
|
|
unsigned sublabel_y = (rgui->term_layout.height * rgui->font_height_stride) + rgui->term_layout.start_y + 4;
|
|
unsigned term_end_x = rgui->term_layout.start_x + (rgui->term_layout.width * rgui->font_width_stride);
|
|
bool show_entries = (rgui->flags & RGUI_FLAG_DRAW_ENTRY_SKIP) ? false : true;
|
|
bool show_mini_thumbnails = rgui->media.settings_open || (rgui_inline_thumbnails
|
|
&& rgui->playlist_index >= 0
|
|
&& ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
|| ((rgui->flags & RGUI_FLAG_IS_QUICK_MENU) && !menu_is_running_quick_menu())));
|
|
bool show_thumbnail = false;
|
|
bool show_left_thumbnail = false;
|
|
bool show_savestate_thumbnail = (*rgui->savestate_thumbnail_file_path
|
|
&& ( (rgui->flags & RGUI_FLAG_IS_STATE_SLOT)
|
|
|| ((rgui->flags & RGUI_FLAG_IS_QUICK_MENU) && menu_is_running_quick_menu())));
|
|
unsigned thumbnail_panel_width = 0;
|
|
unsigned term_mid_point = 0;
|
|
size_t powerstate_len = 0;
|
|
size_t timedate_len = 0;
|
|
size_t sublabel_len = 0;
|
|
|
|
/* Cache mini thumbnail related parameters, if required */
|
|
if (show_mini_thumbnails)
|
|
{
|
|
/* Get whether each thumbnail type is enabled */
|
|
show_thumbnail = (rgui->media.settings_open || (rgui->flags & RGUI_FLAG_ENTRY_HAS_THUMBNAIL))
|
|
&& (rgui->mini_thumbnail.is_valid || (rgui->thumbnail_queue_size > 0));
|
|
show_left_thumbnail = (rgui->flags & RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL)
|
|
&& (rgui->mini_left_thumbnail.is_valid || (rgui->left_thumbnail_queue_size > 0));
|
|
|
|
/* Images playlist needs to show only the bottom thumbnail */
|
|
if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_IMAGES_TAB)))
|
|
{
|
|
if (rgui_swap_thumbnails)
|
|
show_left_thumbnail = false;
|
|
else
|
|
show_thumbnail = false;
|
|
}
|
|
|
|
/* Get maximum width of thumbnail 'panel' on right side
|
|
* of screen */
|
|
thumbnail_panel_width = rgui_get_mini_thumbnail_fullwidth(rgui);
|
|
|
|
if ( ( (rgui->flags & RGUI_FLAG_ENTRY_HAS_THUMBNAIL)
|
|
&& rgui->thumbnail_queue_size > 0)
|
|
||
|
|
( (rgui->flags & RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL)
|
|
&& rgui->left_thumbnail_queue_size > 0))
|
|
thumbnail_panel_width = VIDEO_SCALE_W(rgui->mini_thumbnail_max_dims);
|
|
|
|
/* Index (relative to first displayed menu entry) of
|
|
* the vertical centre of RGUI's 'terminal'
|
|
* (required to determine whether a particular entry
|
|
* is adjacent to the 'right' or 'left' thumbnail) */
|
|
term_mid_point = (unsigned)((rgui->term_layout.height * 0.5f) + 0.5f) - 1;
|
|
}
|
|
|
|
/* Show battery indicator, if required */
|
|
if (menu_battery_level_enable)
|
|
{
|
|
gfx_display_ctx_powerstate_t powerstate;
|
|
char percent_str[12];
|
|
|
|
percent_str[0] = '\0';
|
|
|
|
menu_display_powerstate(&powerstate, percent_str, sizeof(percent_str));
|
|
|
|
if (powerstate.battery_enabled)
|
|
{
|
|
powerstate_len = utf8len(percent_str);
|
|
|
|
if (powerstate_len > 0)
|
|
{
|
|
unsigned powerstate_x;
|
|
enum rgui_symbol_type powerstate_symbol;
|
|
uint16_t powerstate_color = (powerstate.percent > RGUI_BATTERY_WARN_THRESHOLD || powerstate.charging)
|
|
? rgui->colors.title_color
|
|
: rgui->colors.hover_color;
|
|
|
|
if (powerstate.charging)
|
|
powerstate_symbol = RGUI_SYMBOL_CHARGING;
|
|
else
|
|
{
|
|
if (powerstate.percent > 80)
|
|
powerstate_symbol = RGUI_SYMBOL_BATTERY_100;
|
|
else if (powerstate.percent > 60)
|
|
powerstate_symbol = RGUI_SYMBOL_BATTERY_80;
|
|
else if (powerstate.percent > 40)
|
|
powerstate_symbol = RGUI_SYMBOL_BATTERY_60;
|
|
else if (powerstate.percent > 20)
|
|
powerstate_symbol = RGUI_SYMBOL_BATTERY_40;
|
|
else
|
|
powerstate_symbol = RGUI_SYMBOL_BATTERY_20;
|
|
}
|
|
|
|
/* Note: percent symbol is particularly hideous when
|
|
* drawn using RGUI's bitmap font, so strip it off the
|
|
* end of the output string... */
|
|
percent_str[powerstate_len - 1] = '\0';
|
|
|
|
powerstate_x = (unsigned)(term_end_x -
|
|
(powerstate_len * rgui->font_width_stride));
|
|
|
|
/* Draw symbol */
|
|
rgui_blit_symbol(rgui,
|
|
fb_width,
|
|
powerstate_x,
|
|
title_y,
|
|
powerstate_symbol,
|
|
powerstate_color,
|
|
rgui->colors.shadow_color);
|
|
|
|
/* Print text */
|
|
rgui_blit_line(rgui,
|
|
fb_width,
|
|
powerstate_x + rgui->font_width_stride,
|
|
title_y,
|
|
percent_str,
|
|
powerstate_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Print clock (if required) */
|
|
if (menu_timedate_enable)
|
|
{
|
|
char timedate[20];
|
|
gfx_display_ctx_datetime_t datetime;
|
|
datetime.time_mode = settings->uints.menu_timedate_style;
|
|
datetime.date_separator = settings->uints.menu_timedate_date_separator;
|
|
|
|
menu_display_timedate(&datetime, timedate, sizeof(timedate));
|
|
timedate_len = utf8len(timedate);
|
|
|
|
/* Add battery spacer */
|
|
if (powerstate_len)
|
|
powerstate_len++;
|
|
|
|
rgui_blit_line(rgui,
|
|
fb_width,
|
|
(int)(term_end_x
|
|
- (powerstate_len * rgui->font_width_stride)
|
|
- (timedate_len * rgui->font_width_stride)),
|
|
title_y,
|
|
timedate,
|
|
rgui->colors.hover_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
|
|
/* Print title */
|
|
title_max_len = rgui->term_layout.width - powerstate_len - timedate_len;
|
|
if (powerstate_len || timedate_len)
|
|
title_max_len--;
|
|
|
|
title_buf[0] = '\0';
|
|
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth.selected = true;
|
|
ticker_smooth.field_width = (unsigned)(title_max_len * rgui->font_width_stride);
|
|
ticker_smooth.src_str = rgui->menu_title;
|
|
ticker_smooth.dst_str = title_buf;
|
|
ticker_smooth.dst_str_len = sizeof(title_buf);
|
|
ticker_smooth.x_offset = &ticker_x_offset;
|
|
|
|
/* If title is scrolling, then title_len == title_max_len */
|
|
gfx_animation_ticker_smooth(&ticker_smooth);
|
|
}
|
|
else
|
|
{
|
|
ticker.s = title_buf;
|
|
ticker.s_len = sizeof(title_buf);
|
|
ticker.len = title_max_len;
|
|
ticker.str = rgui->menu_title;
|
|
ticker.selected = true;
|
|
|
|
gfx_animation_ticker(&ticker);
|
|
}
|
|
|
|
string_to_upper(title_buf);
|
|
|
|
title_x = (unsigned)(ticker_x_offset + rgui->term_layout.start_x);
|
|
|
|
rgui_blit_line(rgui, fb_width, title_x, title_y,
|
|
title_buf, rgui->colors.title_color, rgui->colors.shadow_color);
|
|
|
|
/* Print menu entries */
|
|
x = rgui->term_layout.start_x;
|
|
y = rgui->term_layout.start_y;
|
|
new_start = menu_st->entries.begin;
|
|
|
|
for (i = new_start; i < end && show_entries; i++, y += rgui->font_height_stride)
|
|
{
|
|
char entry_title_buf[NAME_MAX_LENGTH];
|
|
char type_str_buf[NAME_MAX_LENGTH];
|
|
menu_entry_t *entry = &rgui->render_entry;
|
|
const char *entry_value = NULL;
|
|
size_t entry_title_max_len = 0;
|
|
unsigned entry_value_len = 0;
|
|
enum rgui_entry_value_type entry_value_type = RGUI_ENTRY_VALUE_NONE;
|
|
bool entry_selected = (i == selection);
|
|
uint16_t entry_color = entry_selected
|
|
? rgui->colors.hover_color
|
|
: rgui->colors.normal_color;
|
|
|
|
if (i > (selection + 100))
|
|
continue;
|
|
|
|
entry_title_buf[0] = '\0';
|
|
type_str_buf[0] = '\0';
|
|
|
|
/* Get current entry */
|
|
MENU_ENTRY_INITIALIZE((*entry));
|
|
entry->flags |= MENU_ENTRY_FLAG_RICH_LABEL_ENABLED
|
|
| MENU_ENTRY_FLAG_VALUE_ENABLED;
|
|
menu_entry_get(entry, 0, (unsigned)i, NULL, true);
|
|
|
|
if (entry->enum_idx == MENU_ENUM_LABEL_CHEEVOS_PASSWORD)
|
|
entry_value = entry->password_value;
|
|
else
|
|
entry_value = entry->value;
|
|
|
|
/* Get base length of entry title field */
|
|
entry_title_max_len = rgui->term_layout.width - (1 + 2);
|
|
|
|
/* If showing mini thumbnails, reduce title field length accordingly */
|
|
if (show_mini_thumbnails)
|
|
{
|
|
unsigned term_offset = rgui_swap_thumbnails
|
|
? (unsigned)(rgui->term_layout.height - (i - new_start) - 1)
|
|
: (unsigned)(i - new_start);
|
|
unsigned thumbnail_width = 0;
|
|
|
|
/* Note:
|
|
* - 'Right' thumbnail is drawn at the top
|
|
* - 'Left' thumbnail is drawn at the bottom
|
|
* ...unless thumbnail positions are swapped.
|
|
* (legacy naming, unfortunately...) */
|
|
|
|
/* An annoyance - cannot assume terminal will have a
|
|
* standard layout (even though it always will...),
|
|
* so have to check whether there are an odd or even
|
|
* number of entries... */
|
|
if ((rgui->term_layout.height & 1) == 0)
|
|
{
|
|
/* Even number of entries */
|
|
if ( (show_thumbnail && (term_offset <= term_mid_point))
|
|
|| (show_left_thumbnail && (term_offset > term_mid_point)))
|
|
thumbnail_width = thumbnail_panel_width;
|
|
}
|
|
else
|
|
{
|
|
/* Odd number of entries (will always be the case) */
|
|
if ( (show_thumbnail && (term_offset < term_mid_point))
|
|
|| (show_left_thumbnail && (term_offset > term_mid_point))
|
|
|| ((show_thumbnail || show_left_thumbnail) && (term_offset == term_mid_point)))
|
|
thumbnail_width = thumbnail_panel_width;
|
|
}
|
|
|
|
entry_title_max_len -= (thumbnail_width / rgui->font_width_stride);
|
|
}
|
|
|
|
/* Get 'type' of entry value component */
|
|
entry_value_type = rgui_get_entry_value_type(
|
|
entry_value,
|
|
entry->setting_type,
|
|
(entry->flags & MENU_ENTRY_FLAG_CHECKED) ? true : false,
|
|
rgui_switch_icons);
|
|
|
|
switch (entry_value_type)
|
|
{
|
|
case RGUI_ENTRY_VALUE_TEXT:
|
|
/* If using full width layout, resize fields
|
|
* according to actual length of value string.
|
|
* Otherwise, use classic fixed widths 'rounded
|
|
* down' to current value_maxlen */
|
|
entry_value_len = rgui_full_width_layout
|
|
? (unsigned)utf8len(entry_value)
|
|
: entry->spacing;
|
|
|
|
entry_value_len = (entry_value_len > rgui->term_layout.value_maxlen)
|
|
? rgui->term_layout.value_maxlen
|
|
: entry_value_len;
|
|
|
|
/* Update width of entry title field */
|
|
entry_title_max_len -= entry_value_len + 2;
|
|
break;
|
|
case RGUI_ENTRY_VALUE_SWITCH_ON:
|
|
case RGUI_ENTRY_VALUE_SWITCH_OFF:
|
|
/* Switch icon is 3 characters wide
|
|
* (if using classic fixed width layout,
|
|
* set maximum width to ensure icon is
|
|
* aligned with left hand edge of values
|
|
* column) */
|
|
entry_value_len = rgui_full_width_layout
|
|
? 3
|
|
: (RGUI_ENTRY_VALUE_MAXLEN > rgui->term_layout.value_maxlen)
|
|
? rgui->term_layout.value_maxlen
|
|
: RGUI_ENTRY_VALUE_MAXLEN;
|
|
|
|
/* Update width of entry title field */
|
|
entry_title_max_len -= entry_value_len + 2;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
/* Format entry title string */
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth.selected = entry_selected;
|
|
ticker_smooth.field_width = (unsigned)(entry_title_max_len * rgui->font_width_stride);
|
|
if (*entry->rich_label)
|
|
ticker_smooth.src_str = entry->rich_label;
|
|
else
|
|
ticker_smooth.src_str = entry->path;
|
|
ticker_smooth.dst_str = entry_title_buf;
|
|
ticker_smooth.dst_str_len = sizeof(entry_title_buf);
|
|
ticker_smooth.x_offset = &ticker_x_offset;
|
|
|
|
gfx_animation_ticker_smooth(&ticker_smooth);
|
|
}
|
|
else
|
|
{
|
|
ticker.s = entry_title_buf;
|
|
ticker.s_len = sizeof(entry_title_buf);
|
|
ticker.len = entry_title_max_len;
|
|
if (*entry->rich_label)
|
|
ticker.str = entry->rich_label;
|
|
else
|
|
ticker.str = entry->path;
|
|
ticker.selected = entry_selected;
|
|
|
|
gfx_animation_ticker(&ticker);
|
|
}
|
|
|
|
/* Print entry title */
|
|
rgui_blit_line(rgui,
|
|
fb_width,
|
|
ticker_x_offset + x + (2 * rgui->font_width_stride),
|
|
y,
|
|
entry_title_buf,
|
|
entry_color,
|
|
rgui->colors.shadow_color);
|
|
|
|
/* Print entry value, if required */
|
|
switch (entry_value_type)
|
|
{
|
|
case RGUI_ENTRY_VALUE_TEXT:
|
|
/* Format entry value string */
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth.field_width = entry_value_len * rgui->font_width_stride;
|
|
ticker_smooth.src_str = entry_value;
|
|
ticker_smooth.dst_str = type_str_buf;
|
|
ticker_smooth.dst_str_len = sizeof(type_str_buf);
|
|
ticker_smooth.x_offset = &ticker_x_offset;
|
|
|
|
gfx_animation_ticker_smooth(&ticker_smooth);
|
|
}
|
|
else
|
|
{
|
|
ticker.s = type_str_buf;
|
|
ticker.s_len = sizeof(type_str_buf);
|
|
ticker.len = entry_value_len;
|
|
ticker.str = entry_value;
|
|
|
|
gfx_animation_ticker(&ticker);
|
|
}
|
|
|
|
{
|
|
uint16_t entry_value_color = entry_color;
|
|
|
|
if (!entry_selected &&
|
|
( string_is_equal(entry_value, "null")
|
|
|| string_is_equal(entry_value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OFF))
|
|
|| string_is_equal(entry_value, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MORE))))
|
|
entry_value_color = rgui->colors.disabled_color;
|
|
|
|
/* Print entry value */
|
|
rgui_blit_line(rgui,
|
|
fb_width,
|
|
ticker_x_offset + term_end_x - ((entry_value_len + 1) * rgui->font_width_stride),
|
|
y,
|
|
type_str_buf,
|
|
entry_value_color, rgui->colors.shadow_color);
|
|
}
|
|
break;
|
|
case RGUI_ENTRY_VALUE_SWITCH_ON:
|
|
rgui_render_toggle_switch(rgui,
|
|
fb_width,
|
|
rgui_full_width_layout
|
|
? (term_end_x - ((RGUI_SYMBOL_WIDTH_STRIDE * 3) + rgui->font_width_stride))
|
|
: (term_end_x - ((entry_value_len + 1) * rgui->font_width_stride)),
|
|
y,
|
|
true,
|
|
entry_color,
|
|
rgui->colors.shadow_color);
|
|
break;
|
|
case RGUI_ENTRY_VALUE_SWITCH_OFF:
|
|
rgui_render_toggle_switch(rgui,
|
|
fb_width,
|
|
rgui_full_width_layout
|
|
? (term_end_x - ((RGUI_SYMBOL_WIDTH_STRIDE * 3) + rgui->font_width_stride))
|
|
: (term_end_x - ((entry_value_len + 1) * rgui->font_width_stride)),
|
|
y,
|
|
false,
|
|
(entry_selected) ? entry_color : rgui->colors.disabled_color,
|
|
rgui->colors.shadow_color);
|
|
break;
|
|
case RGUI_ENTRY_VALUE_CHECKMARK:
|
|
/* Print marker for currently selected
|
|
* item in drop-down lists */
|
|
rgui_blit_symbol(rgui,
|
|
fb_width,
|
|
x + rgui->font_width_stride,
|
|
y,
|
|
RGUI_SYMBOL_CHECKMARK,
|
|
entry_color,
|
|
rgui->colors.shadow_color);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
/* Print selection marker, if required */
|
|
if (entry_selected)
|
|
rgui_blit_line(rgui, fb_width, x, y, ">",
|
|
entry_color, rgui->colors.shadow_color);
|
|
}
|
|
|
|
/* Draw mini thumbnails, if required */
|
|
if (show_savestate_thumbnail)
|
|
{
|
|
thumbnail_t *thumbnail_savestate = &rgui->mini_left_thumbnail;
|
|
if (show_savestate_thumbnail && thumbnail_savestate)
|
|
rgui_render_mini_thumbnail(rgui, thumbnail_savestate,
|
|
rgui->frame_buf.data,
|
|
(rgui_swap_thumbnails) ? GFX_THUMBNAIL_RIGHT : GFX_THUMBNAIL_LEFT,
|
|
p_disp->framebuf_dims, fb_pitch,
|
|
rgui_swap_thumbnails, thumbnail_background, true);
|
|
}
|
|
else if (show_mini_thumbnails)
|
|
{
|
|
thumbnail_t *thumbnail1 = &rgui->mini_thumbnail;
|
|
thumbnail_t *thumbnail2 = &rgui->mini_left_thumbnail;
|
|
if (show_thumbnail && thumbnail1)
|
|
rgui_render_mini_thumbnail(rgui, thumbnail1,
|
|
rgui->frame_buf.data,
|
|
GFX_THUMBNAIL_RIGHT,
|
|
p_disp->framebuf_dims, fb_pitch,
|
|
rgui_swap_thumbnails, thumbnail_background, false);
|
|
if (show_left_thumbnail && thumbnail2)
|
|
rgui_render_mini_thumbnail(rgui, thumbnail2,
|
|
rgui->frame_buf.data,
|
|
GFX_THUMBNAIL_LEFT,
|
|
p_disp->framebuf_dims, fb_pitch,
|
|
rgui_swap_thumbnails, thumbnail_background, false);
|
|
}
|
|
|
|
/* Draw entry index of current selection */
|
|
if (*rgui->entry_index_str)
|
|
{
|
|
size_t len = strlen(rgui->entry_index_str);
|
|
|
|
/* Subtract from sublabel width */
|
|
sublabel_len += len + 1;
|
|
|
|
rgui_blit_line(rgui,
|
|
fb_width,
|
|
(int)(term_end_x - (len * rgui->font_width_stride)),
|
|
sublabel_y,
|
|
rgui->entry_index_str,
|
|
rgui->colors.hover_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
|
|
/* Print menu sublabel/core name (if required) */
|
|
if (menu_show_sublabels && *rgui->menu_sublabel)
|
|
{
|
|
char *sublabel_buf = rgui->render_sublabel_buf;
|
|
sublabel_buf[0] = '\0';
|
|
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth.selected = true;
|
|
ticker_smooth.field_width = (unsigned)((rgui->term_layout.width - sublabel_len) * rgui->font_width_stride);
|
|
ticker_smooth.src_str = rgui->menu_sublabel;
|
|
ticker_smooth.dst_str = sublabel_buf;
|
|
ticker_smooth.dst_str_len = MENU_LABEL_MAX_LENGTH;
|
|
ticker_smooth.x_offset = &ticker_x_offset;
|
|
|
|
gfx_animation_ticker_smooth(&ticker_smooth);
|
|
}
|
|
else
|
|
{
|
|
ticker.s = sublabel_buf;
|
|
ticker.s_len = MENU_LABEL_MAX_LENGTH;
|
|
ticker.len = rgui->term_layout.width - sublabel_len;
|
|
ticker.str = rgui->menu_sublabel;
|
|
ticker.selected = true;
|
|
|
|
gfx_animation_ticker(&ticker);
|
|
}
|
|
|
|
rgui_blit_line(rgui,
|
|
fb_width,
|
|
ticker_x_offset + rgui->term_layout.start_x,
|
|
sublabel_y,
|
|
sublabel_buf,
|
|
rgui->colors.hover_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
else if (menu_core_enable)
|
|
{
|
|
char core_title[64];
|
|
char core_title_buf[64];
|
|
core_title[0] = core_title_buf[0] = '\0';
|
|
|
|
menu_entries_get_core_title(core_title, sizeof(core_title));
|
|
|
|
if (use_smooth_ticker)
|
|
{
|
|
ticker_smooth.selected = true;
|
|
ticker_smooth.field_width = (unsigned)((rgui->term_layout.width - sublabel_len) * rgui->font_width_stride);
|
|
ticker_smooth.src_str = core_title;
|
|
ticker_smooth.dst_str = core_title_buf;
|
|
ticker_smooth.dst_str_len = sizeof(core_title_buf);
|
|
ticker_smooth.x_offset = &ticker_x_offset;
|
|
|
|
gfx_animation_ticker_smooth(&ticker_smooth);
|
|
}
|
|
else
|
|
{
|
|
ticker.s = core_title_buf;
|
|
ticker.s_len = sizeof(core_title_buf);
|
|
ticker.len = rgui->term_layout.width - sublabel_len;
|
|
ticker.str = core_title;
|
|
ticker.selected = true;
|
|
|
|
gfx_animation_ticker(&ticker);
|
|
}
|
|
|
|
rgui_blit_line(rgui,
|
|
fb_width,
|
|
ticker_x_offset + rgui->term_layout.start_x,
|
|
sublabel_y,
|
|
core_title_buf,
|
|
rgui->colors.hover_color,
|
|
rgui->colors.shadow_color);
|
|
}
|
|
}
|
|
|
|
if (show_fs_thumbnail && !rgui->thumbnail_queue_size
|
|
&& (rgui->fs_thumbnail.is_valid
|
|
|| (!*rgui->media_requested_path && *rgui->fs_thumbnail.path)
|
|
|| rgui->media_gpu.status == GFX_THUMBNAIL_STATUS_MISSING))
|
|
menu_driver_media_startup_ready(menu_driver_media_startup_token());
|
|
if (!show_fs_thumbnail)
|
|
rgui_media_gpu_cutout(rgui, p_disp->framebuf_dims);
|
|
if (msgbox && *msgbox)
|
|
{
|
|
const menu_dialog_t *d = &menu_st->dialog_st;
|
|
/* Draw popup directly on top of the menu; the messagebox
|
|
* paints its own opaque background within its footprint. */
|
|
rgui_render_messagebox(rgui, msgbox, p_disp->framebuf_dims);
|
|
if (strcmp(rgui->msgbox_drawn, msgbox))
|
|
strlcpy(rgui->msgbox_drawn, msgbox, sizeof(rgui->msgbox_drawn));
|
|
rgui->msgbox_epoch = d->button_epoch;
|
|
rgui->msgbox_highlight = d->button_highlight;
|
|
rgui->msgbox_hover = rgui_msgbox_hover(d);
|
|
}
|
|
|
|
if (rgui->flags & RGUI_FLAG_SHOW_MOUSE)
|
|
{
|
|
bool cursor_visible = video_fullscreen
|
|
&& menu_mouse_enable;
|
|
|
|
/* Blit cursor */
|
|
if (cursor_visible && rgui->frame_buf.data)
|
|
{
|
|
rgui_color_rect(rgui->frame_buf.data, p_disp->framebuf_dims,
|
|
VIDEO_POS_X(rgui->pointer.pos), VIDEO_POS_Y(rgui->pointer.pos) - 5, 1, 11, rgui->colors.normal_color);
|
|
rgui_color_rect(rgui->frame_buf.data, p_disp->framebuf_dims,
|
|
VIDEO_POS_X(rgui->pointer.pos) - 5, VIDEO_POS_Y(rgui->pointer.pos), 11, 1, rgui->colors.normal_color);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* Region spacing inside the menu buffer arena, in uint16_t elements:
|
|
* 64 bytes, so every buffer starts on a cache line and consecutive
|
|
* buffers are never a multiple of 4 KiB apart. */
|
|
#define RGUI_ARENA_ALIGN 32
|
|
#define RGUI_ARENA_NEXT(cur, n) \
|
|
((((cur) + (n) + RGUI_ARENA_ALIGN - 1) / RGUI_ARENA_ALIGN) \
|
|
* RGUI_ARENA_ALIGN + RGUI_ARENA_ALIGN)
|
|
|
|
/* Only resets the descriptor; the storage belongs to rgui->fb_arena. */
|
|
static void rgui_framebuffer_reset(frame_buf_t *framebuffer)
|
|
{
|
|
framebuffer->width = 0;
|
|
framebuffer->height = 0;
|
|
framebuffer->data = NULL;
|
|
}
|
|
|
|
static void rgui_thumbnail_reset(thumbnail_t *thumbnail)
|
|
{
|
|
thumbnail->max_dims = 0;
|
|
thumbnail->dims = 0;
|
|
thumbnail->is_valid = false;
|
|
thumbnail->path[0] = '\0';
|
|
thumbnail->data = NULL;
|
|
}
|
|
|
|
/* upscale_buf is not part of the arena and is freed by its own user. */
|
|
static void rgui_upscale_buf_free(frame_buf_t *framebuffer)
|
|
{
|
|
framebuffer->width = 0;
|
|
framebuffer->height = 0;
|
|
if (framebuffer->data)
|
|
free(framebuffer->data);
|
|
framebuffer->data = NULL;
|
|
}
|
|
|
|
static void rgui_buffers_free(rgui_t *rgui)
|
|
{
|
|
rgui_framebuffer_reset(&rgui->frame_buf);
|
|
rgui_framebuffer_reset(&rgui->background_buf);
|
|
rgui_thumbnail_reset(&rgui->fs_thumbnail);
|
|
rgui_thumbnail_reset(&rgui->mini_thumbnail);
|
|
rgui_thumbnail_reset(&rgui->mini_left_thumbnail);
|
|
|
|
if (rgui->fb_arena)
|
|
memalign_free(rgui->fb_arena);
|
|
rgui->fb_arena = NULL;
|
|
}
|
|
|
|
bool rgui_is_video_config_equal(
|
|
rgui_video_settings_t *config_a,
|
|
rgui_video_settings_t *config_b)
|
|
{
|
|
return (config_a->aspect_ratio_idx == config_b->aspect_ratio_idx)
|
|
&& (VIDEO_SCALE_W(config_a->vp.dims) == VIDEO_SCALE_W(config_b->vp.dims))
|
|
&& (VIDEO_SCALE_H(config_a->vp.dims) == VIDEO_SCALE_H(config_b->vp.dims))
|
|
&& (VIDEO_POS_X(config_a->vp.pos) == VIDEO_POS_X(config_b->vp.pos))
|
|
&& (VIDEO_POS_Y(config_a->vp.pos) == VIDEO_POS_Y(config_b->vp.pos));
|
|
}
|
|
|
|
static void rgui_get_video_config(
|
|
rgui_video_settings_t *video_settings,
|
|
settings_t *settings,
|
|
unsigned video_aspect_ratio_idx)
|
|
{
|
|
/* Could use settings->video_vp_custom directly,
|
|
* but this seems to be the standard way of doing it... */
|
|
video_viewport_settings_t *custom_vp = &settings->video_vp_custom;
|
|
video_settings->aspect_ratio_idx = video_aspect_ratio_idx;
|
|
video_settings->vp.dims = custom_vp->dims;
|
|
video_settings->vp.pos = custom_vp->pos;
|
|
}
|
|
|
|
/* Main thread only: writes the aspect index and custom viewport into
|
|
* the configuration and refreshes the custom-aspect LUT entry. */
|
|
static void rgui_apply_video_config(
|
|
const rgui_video_settings_t *video_settings)
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
/* Could use settings->video_vp_custom directly,
|
|
* but this seems to be the standard way of doing it... */
|
|
video_viewport_settings_t *custom_vp = &settings->video_vp_custom;
|
|
settings->uints.video_aspect_ratio_idx = video_settings->aspect_ratio_idx;
|
|
custom_vp->dims = video_settings->vp.dims;
|
|
custom_vp->pos = video_settings->vp.pos;
|
|
|
|
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
|
|
(float)VIDEO_SCALE_W(custom_vp->dims)
|
|
/ VIDEO_SCALE_H(custom_vp->dims);
|
|
}
|
|
|
|
/* Stage a video configuration for rgui_render() to apply. The frame
|
|
* path reaches here under threaded video, and both the settings
|
|
* writes and CMD_EVENT_VIDEO_SET_ASPECT_RATIO belong to the main
|
|
* thread (the command deadlocks from the frame - see the note in
|
|
* rgui_frame); main-side callers that want the deferral (populate)
|
|
* use it too. Latest staged wins. */
|
|
static void rgui_stage_video_config(
|
|
rgui_t *rgui,
|
|
const rgui_video_settings_t *video_settings)
|
|
{
|
|
rgui->pending_video_config = *video_settings;
|
|
rgui->flags |= RGUI_FLAG_ASPECT_UPDATE_PENDING;
|
|
}
|
|
|
|
/* Main thread only: apply and signal immediately. */
|
|
static void rgui_set_video_config_now(
|
|
rgui_t *rgui,
|
|
const rgui_video_settings_t *video_settings)
|
|
{
|
|
rgui_apply_video_config(video_settings);
|
|
command_event(CMD_EVENT_VIDEO_SET_ASPECT_RATIO, NULL);
|
|
rgui->flags &= ~RGUI_FLAG_ASPECT_UPDATE_PENDING;
|
|
}
|
|
|
|
/* Main thread only: apply whatever rgui_set_aspect_ratio() staged,
|
|
* for callers that need the configuration in place before they
|
|
* proceed (video init, menu toggle) rather than at the next
|
|
* rgui_render(). */
|
|
static void rgui_flush_video_config(rgui_t *rgui)
|
|
{
|
|
if (rgui->flags & RGUI_FLAG_ASPECT_UPDATE_PENDING)
|
|
rgui_set_video_config_now(rgui, &rgui->pending_video_config);
|
|
}
|
|
|
|
/* Note: This function is only called when aspect ratio
|
|
* lock is enabled */
|
|
static void rgui_update_menu_viewport(
|
|
rgui_t *rgui,
|
|
gfx_display_t *p_disp,
|
|
unsigned menu_rgui_aspect_ratio_lock)
|
|
{
|
|
struct video_viewport vp;
|
|
unsigned fb_width = VIDEO_SCALE_W(p_disp->framebuf_dims);
|
|
unsigned fb_height = VIDEO_SCALE_H(p_disp->framebuf_dims);
|
|
|
|
#ifndef GEKKO
|
|
#ifdef DINGUX
|
|
menu_rgui_aspect_ratio_lock = RGUI_ASPECT_RATIO_LOCK_NONE;
|
|
#endif
|
|
#endif
|
|
|
|
video_driver_get_viewport_info(&vp);
|
|
|
|
/* Could do this once in rgui_init(), but seems cleaner to
|
|
* handle all video config in one place... */
|
|
rgui->menu_video_settings.aspect_ratio_idx = ASPECT_RATIO_CUSTOM;
|
|
|
|
/* Determine custom viewport layout */
|
|
if (fb_width > 0 && fb_height > 0 && VIDEO_SCALE_W(vp.full_dims) > 0 && VIDEO_SCALE_H(vp.full_dims) > 0)
|
|
{
|
|
#if defined(GEKKO)
|
|
/* The Wii is a special case, since it uses anamorphic
|
|
* widescreen. The display aspect ratio cannot therefore
|
|
* be determined simply by dividing viewport width by height */
|
|
float delta;
|
|
#if defined(HW_RVL) && defined(HAVE_LIBOGC)
|
|
float device_aspect = (CONF_GetAspectRatio() == CONF_ASPECT_4_3)
|
|
? (4.0f / 3.0f)
|
|
: (16.0f / 9.0f);
|
|
#elif defined(HW_RVL)
|
|
float device_aspect = gk_conf_wide() > 0
|
|
? (16.0f / 9.0f)
|
|
: (4.0f / 3.0f);
|
|
#else
|
|
float device_aspect = (4.0f / 3.0f);
|
|
#endif
|
|
float desired_aspect = (float)fb_width / (float)fb_height;
|
|
|
|
if (device_aspect > desired_aspect)
|
|
{
|
|
delta = (desired_aspect / device_aspect - 1.0f) / 2.0f + 0.5f;
|
|
rgui->menu_video_settings.vp.dims = VIDEO_SCALE_PACK((unsigned)(2.0f * (float)VIDEO_SCALE_W(vp.full_dims) * delta),
|
|
VIDEO_SCALE_H(vp.full_dims));
|
|
}
|
|
else
|
|
{
|
|
delta = (device_aspect / desired_aspect - 1.0f) / 2.0f + 0.5f;
|
|
rgui->menu_video_settings.vp.dims = VIDEO_SCALE_PACK(VIDEO_SCALE_W(vp.full_dims),
|
|
(unsigned)(2.0f * (float)VIDEO_SCALE_H(vp.full_dims) * delta));
|
|
}
|
|
#else
|
|
/* Check whether we need to perform integer scaling */
|
|
bool do_integer_scaling = (menu_rgui_aspect_ratio_lock == RGUI_ASPECT_RATIO_LOCK_INTEGER);
|
|
|
|
if (do_integer_scaling)
|
|
{
|
|
unsigned width_scale = (VIDEO_SCALE_W(vp.full_dims) / fb_width);
|
|
unsigned height_scale = (VIDEO_SCALE_H(vp.full_dims) / fb_height);
|
|
unsigned scale = (width_scale <= height_scale)
|
|
? width_scale
|
|
: height_scale;
|
|
|
|
if (scale > 0)
|
|
{
|
|
rgui->menu_video_settings.vp.dims = VIDEO_SCALE_PACK(scale * fb_width,
|
|
scale * fb_height);
|
|
}
|
|
else
|
|
do_integer_scaling = false;
|
|
}
|
|
|
|
/* Check whether menu should be stretched to
|
|
* fill the screen, regardless of internal
|
|
* aspect ratio */
|
|
if (menu_rgui_aspect_ratio_lock == RGUI_ASPECT_RATIO_LOCK_FILL_SCREEN)
|
|
{
|
|
rgui->menu_video_settings.vp.dims = vp.full_dims;
|
|
}
|
|
/* Normal non-integer aspect-ratio-correct scaling */
|
|
else if (!do_integer_scaling)
|
|
{
|
|
float display_aspect_ratio = (float)VIDEO_SCALE_W(vp.full_dims) / (float)VIDEO_SCALE_H(vp.full_dims);
|
|
float aspect_ratio = (float)fb_width / (float)fb_height;
|
|
|
|
if (aspect_ratio > display_aspect_ratio)
|
|
{
|
|
rgui->menu_video_settings.vp.dims = VIDEO_SCALE_PACK(VIDEO_SCALE_W(vp.full_dims),
|
|
fb_height * VIDEO_SCALE_W(vp.full_dims) / fb_width);
|
|
}
|
|
else
|
|
{
|
|
rgui->menu_video_settings.vp.dims = VIDEO_SCALE_PACK(fb_width * VIDEO_SCALE_H(vp.full_dims) / fb_height,
|
|
VIDEO_SCALE_H(vp.full_dims));
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* Sanity check */
|
|
if (VIDEO_SCALE_W(rgui->menu_video_settings.vp.dims) < 1)
|
|
VIDEO_SCALE_PUT_W(rgui->menu_video_settings.vp.dims, 1);
|
|
if (VIDEO_SCALE_H(rgui->menu_video_settings.vp.dims) < 1)
|
|
VIDEO_SCALE_PUT_H(rgui->menu_video_settings.vp.dims, 1);
|
|
}
|
|
else
|
|
{
|
|
rgui->menu_video_settings.vp.dims = VIDEO_SCALE_PACK(1, 1);
|
|
}
|
|
|
|
/* Leave the viewport at the origin and let the video driver's
|
|
* viewport-bias logic centre it (default bias 0.5 == centred).
|
|
* Pre-centring here as well (vp.x = (full_width - width) / 2)
|
|
* double-applies the offset since 439c672c22 made the
|
|
* ASPECT_RATIO_CUSTOM path add padding * bias on top of vp.x,
|
|
* which pushed the menu hard against the right/bottom edge on
|
|
* wide screens. */
|
|
rgui->menu_video_settings.vp.pos = VIDEO_POS_PACK(0, 0);
|
|
}
|
|
|
|
/* Dual-context: rgui_render(), init, populate and toggle call this
|
|
* on the main thread; rgui_frame() calls it on the video thread
|
|
* under threaded video. The two settings it needs arrive as
|
|
* arguments, supplied from each caller's own context - the live
|
|
* settings on the main paths, the snapshot on the frame path. */
|
|
static bool rgui_set_aspect_ratio(
|
|
rgui_t *rgui,
|
|
gfx_display_t *p_disp,
|
|
bool delay_update,
|
|
unsigned aspect_ratio,
|
|
unsigned aspect_ratio_lock)
|
|
{
|
|
unsigned base_term_width;
|
|
unsigned mini_thumbnail_term_width;
|
|
#if defined(GEKKO)
|
|
/* Note: Maximum Wii frame buffer width is 424, not
|
|
* the usual 426, since the last two bits of the
|
|
* width value must be zero... */
|
|
unsigned max_frame_buf_width = 424;
|
|
#elif defined(DINGUX)
|
|
/* Dingux devices use a fixed framebuffer size */
|
|
unsigned max_frame_buf_width = RGUI_DINGUX_FB_WIDTH;
|
|
#elif defined(DJGPP)
|
|
unsigned max_frame_buf_width = RGUI_DOS_FB_WIDTH;
|
|
#else
|
|
unsigned max_frame_buf_width = RGUI_MAX_FB_WIDTH;
|
|
#endif
|
|
#if !defined(GEKKO) && !defined(DINGUX)
|
|
struct video_viewport vp;
|
|
#endif
|
|
|
|
#if defined(DINGUX)
|
|
/* Dingux devices run a fixed aspect regardless of configuration:
|
|
* override the caller-supplied values. */
|
|
aspect_ratio = RGUI_DINGUX_ASPECT_RATIO;
|
|
aspect_ratio_lock = RGUI_ASPECT_RATIO_LOCK_NONE;
|
|
#endif
|
|
|
|
rgui_buffers_free(rgui);
|
|
|
|
/* Cache new aspect ratio */
|
|
rgui->menu_aspect_ratio = aspect_ratio;
|
|
|
|
/* Set frame buffer dimensions: */
|
|
|
|
/* Frame buffer height */
|
|
#if defined(GEKKO)
|
|
/* Since Wii graphics driver can change frame buffer
|
|
* dimensions at will, have to read currently set
|
|
* values */
|
|
rgui->frame_buf.height = VIDEO_SCALE_H(p_disp->framebuf_dims);
|
|
#elif defined(DINGUX)
|
|
/* Dingux devices use a fixed framebuffer size */
|
|
rgui->frame_buf.height = RGUI_DINGUX_FB_HEIGHT;
|
|
#elif defined(VITA)
|
|
/* Vita screen does not match 240 */
|
|
rgui->frame_buf.height = RGUI_VITA_FB_HEIGHT;
|
|
video_driver_get_viewport_info(&vp);
|
|
#elif defined(DJGPP)
|
|
rgui->frame_buf.height = RGUI_DOS_FB_HEIGHT;
|
|
video_driver_get_viewport_info(&vp);
|
|
#else
|
|
/* If window height is less than RGUI default
|
|
* height of 240, allow the frame buffer to
|
|
* 'shrink' to a minimum height of 192 */
|
|
rgui->frame_buf.height = 240;
|
|
video_driver_get_viewport_info(&vp);
|
|
if (VIDEO_SCALE_H(vp.full_dims) < rgui->frame_buf.height)
|
|
rgui->frame_buf.height = (VIDEO_SCALE_H(vp.full_dims) > RGUI_MIN_FB_HEIGHT)
|
|
? VIDEO_SCALE_H(vp.full_dims)
|
|
: RGUI_MIN_FB_HEIGHT;
|
|
#endif
|
|
|
|
/* Frame buffer width */
|
|
switch (rgui->menu_aspect_ratio)
|
|
{
|
|
case RGUI_ASPECT_RATIO_16_9:
|
|
if (rgui->frame_buf.height == 240)
|
|
rgui->frame_buf.width = 424;
|
|
else
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(16.0f / 9.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_9_CENTRE:
|
|
if (rgui->frame_buf.height == 240)
|
|
{
|
|
rgui->frame_buf.width = 424;
|
|
base_term_width = 320;
|
|
}
|
|
else
|
|
{
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(16.0f / 9.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
}
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_10:
|
|
if (rgui->frame_buf.height == 240)
|
|
rgui->frame_buf.width = 384;
|
|
else
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(16.0f / 10.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_10_CENTRE:
|
|
if (rgui->frame_buf.height == 240)
|
|
{
|
|
rgui->frame_buf.width = 384;
|
|
base_term_width = 320;
|
|
}
|
|
else
|
|
{
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(16.0f / 10.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
}
|
|
break;
|
|
case RGUI_ASPECT_RATIO_21_9:
|
|
if (rgui->frame_buf.height == 240)
|
|
rgui->frame_buf.width = max_frame_buf_width;
|
|
else
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(21.0f / 9.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_21_9_CENTRE:
|
|
if (rgui->frame_buf.height == 240)
|
|
{
|
|
rgui->frame_buf.width = max_frame_buf_width;
|
|
base_term_width = 320;
|
|
}
|
|
else
|
|
{
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(21.0f / 9.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
}
|
|
break;
|
|
case RGUI_ASPECT_RATIO_3_2:
|
|
if (rgui->frame_buf.height == 240)
|
|
rgui->frame_buf.width = 360;
|
|
else
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(3.0f / 2.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_3_2_CENTRE:
|
|
if (rgui->frame_buf.height == 240)
|
|
{
|
|
rgui->frame_buf.width = 360;
|
|
base_term_width = 320;
|
|
}
|
|
else
|
|
{
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(3.0f / 2.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
}
|
|
break;
|
|
case RGUI_ASPECT_RATIO_5_3:
|
|
if (rgui->frame_buf.height == 240)
|
|
rgui->frame_buf.width = 400;
|
|
else
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(5.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_5_3_CENTRE:
|
|
if (rgui->frame_buf.height == 240)
|
|
{
|
|
rgui->frame_buf.width = 400;
|
|
base_term_width = 320;
|
|
}
|
|
else
|
|
{
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(5.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
}
|
|
break;
|
|
case RGUI_ASPECT_RATIO_AUTO:
|
|
{
|
|
#if !defined(DJGPP)
|
|
/* Use 4:3 as base, and adjust width according to core geometry */
|
|
video_driver_state_t *video_st = video_state_get_ptr();
|
|
if (rgui->frame_buf.height == 240)
|
|
rgui->frame_buf.width = 320;
|
|
else
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
(4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
if (video_st && video_st->av_info.geometry.aspect_ratio > 0)
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
rgui->frame_buf.height * video_st->av_info.geometry.aspect_ratio);
|
|
#else
|
|
rgui->frame_buf.width = RGUI_DOS_FB_WIDTH;
|
|
base_term_width = rgui->frame_buf.width;
|
|
#endif
|
|
}
|
|
break;
|
|
case RGUI_ASPECT_RATIO_1_1:
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
default:
|
|
/* 4:3 */
|
|
if (rgui->frame_buf.height == 240)
|
|
rgui->frame_buf.width = 320;
|
|
else
|
|
rgui->frame_buf.width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
}
|
|
|
|
/* Ensure frame buffer/terminal width is sane
|
|
* - Must be less than max_frame_buf_width
|
|
* (note that this is a redundant safety
|
|
* check - it can never actually happen...)
|
|
* - On platforms other than Wii and dingux, must
|
|
* be less than window width but greater than
|
|
* defined minimum width */
|
|
rgui->frame_buf.width = (rgui->frame_buf.width > max_frame_buf_width)
|
|
? max_frame_buf_width
|
|
: rgui->frame_buf.width;
|
|
base_term_width = (base_term_width > rgui->frame_buf.width)
|
|
? rgui->frame_buf.width
|
|
: base_term_width;
|
|
#if !(defined(GEKKO) || defined(DINGUX) || defined(DJGPP))
|
|
if (VIDEO_SCALE_W(vp.full_dims) < rgui->frame_buf.width)
|
|
{
|
|
rgui->frame_buf.width = (VIDEO_SCALE_W(vp.full_dims) > RGUI_MIN_FB_WIDTH)
|
|
? RGUI_ROUND_FB_WIDTH(VIDEO_SCALE_W(vp.full_dims))
|
|
: RGUI_MIN_FB_WIDTH;
|
|
|
|
/* An annoyance: have to rescale the frame buffer
|
|
* height and terminal width to maintain the correct
|
|
* aspect ratio... */
|
|
switch (rgui->menu_aspect_ratio)
|
|
{
|
|
case RGUI_ASPECT_RATIO_16_9:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
( 9.0f / 16.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_9_CENTRE:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
( 9.0f / 16.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = (base_term_width < RGUI_MIN_FB_WIDTH) ?
|
|
RGUI_MIN_FB_WIDTH : base_term_width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_10:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
(10.0f / 16.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_10_CENTRE:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
(10.0f / 16.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = (base_term_width < RGUI_MIN_FB_WIDTH) ?
|
|
RGUI_MIN_FB_WIDTH : base_term_width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_21_9:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
( 9.0f / 21.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_21_9_CENTRE:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
( 9.0f / 21.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = (base_term_width < RGUI_MIN_FB_WIDTH) ?
|
|
RGUI_MIN_FB_WIDTH : base_term_width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_3_2:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
(3.0f / 2.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_3_2_CENTRE:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
(3.0f / 2.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = (base_term_width < RGUI_MIN_FB_WIDTH) ?
|
|
RGUI_MIN_FB_WIDTH : base_term_width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_5_3:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
(5.0f / 3.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_5_3_CENTRE:
|
|
rgui->frame_buf.height = (unsigned)(
|
|
(5.0f / 3.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = RGUI_ROUND_FB_WIDTH(
|
|
( 4.0f / 3.0f) * (float)rgui->frame_buf.height);
|
|
base_term_width = (base_term_width < RGUI_MIN_FB_WIDTH) ?
|
|
RGUI_MIN_FB_WIDTH : base_term_width;
|
|
break;
|
|
|
|
case RGUI_ASPECT_RATIO_1_1:
|
|
rgui->frame_buf.height = rgui->frame_buf.width;
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
default:
|
|
/* 4:3 */
|
|
rgui->frame_buf.height = (unsigned)(
|
|
( 3.0f / 4.0f) * (float)rgui->frame_buf.width);
|
|
base_term_width = rgui->frame_buf.width;
|
|
break;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* Configure 'menu display' settings */
|
|
p_disp->framebuf_dims = VIDEO_SCALE_PACK(rgui->frame_buf.width, rgui->frame_buf.height);
|
|
p_disp->framebuf_pitch = rgui->frame_buf.width * sizeof(uint16_t);
|
|
|
|
/* Determine terminal layout */
|
|
rgui->term_layout.start_x = (3 * 5) + 1;
|
|
rgui->term_layout.start_y = (3 * 5) + rgui->font_height_stride;
|
|
rgui->term_layout.width = (base_term_width - (2 * rgui->term_layout.start_x)) / rgui->font_width_stride;
|
|
rgui->term_layout.height = (rgui->frame_buf.height - (2 * rgui->term_layout.start_y)) / rgui->font_height_stride;
|
|
rgui->term_layout.value_maxlen = (unsigned)((RGUI_ENTRY_VALUE_MAXLEN_FRACTION * (float)rgui->term_layout.width) + 1.0f);
|
|
|
|
/* > 'Start X/Y' adjustments */
|
|
rgui->term_layout.start_x = (rgui->frame_buf.width - (rgui->term_layout.width * rgui->font_width_stride)) / 2;
|
|
rgui->term_layout.start_y = (rgui->frame_buf.height - (rgui->term_layout.height * rgui->font_height_stride)) / 2;
|
|
|
|
/* Background buffer matches the frame buffer */
|
|
rgui->background_buf.width = rgui->frame_buf.width;
|
|
rgui->background_buf.height = rgui->frame_buf.height;
|
|
|
|
/* Fullscreen thumbnail */
|
|
rgui->fs_thumbnail.max_dims = VIDEO_SCALE_PACK(rgui->frame_buf.width,
|
|
rgui->frame_buf.height
|
|
- (unsigned)(rgui->font_height_stride * 2.0f) + 2);
|
|
|
|
/* Mini thumbnails */
|
|
mini_thumbnail_term_width = (unsigned)((float)rgui->term_layout.width * (2.0f / 5.0f));
|
|
if (mini_thumbnail_term_width > 19)
|
|
mini_thumbnail_term_width = 19;
|
|
rgui->mini_thumbnail_max_dims = VIDEO_SCALE_PACK(mini_thumbnail_term_width * rgui->font_width_stride,
|
|
(unsigned)((rgui->term_layout.height * rgui->font_height_stride) * 0.5f) - 2);
|
|
|
|
rgui->mini_thumbnail.max_dims = rgui->mini_thumbnail_max_dims;
|
|
rgui->mini_left_thumbnail.max_dims = rgui->mini_thumbnail_max_dims;
|
|
|
|
/* One block for all five buffers, in the order above. Cursors are
|
|
* in uint16_t elements. */
|
|
{
|
|
size_t n_frame = (size_t)rgui->frame_buf.width * rgui->frame_buf.height;
|
|
size_t n_bg = (size_t)rgui->background_buf.width * rgui->background_buf.height;
|
|
size_t n_fs = VIDEO_SCALE_AREA(rgui->fs_thumbnail.max_dims);
|
|
size_t n_mini = VIDEO_SCALE_AREA(rgui->mini_thumbnail.max_dims);
|
|
size_t off_frame = 0;
|
|
size_t off_bg = RGUI_ARENA_NEXT(off_frame, n_frame);
|
|
size_t off_fs = RGUI_ARENA_NEXT(off_bg, n_bg);
|
|
size_t off_mini = RGUI_ARENA_NEXT(off_fs, n_fs);
|
|
size_t off_minil = RGUI_ARENA_NEXT(off_mini, n_mini);
|
|
size_t total = off_minil + n_mini;
|
|
uint16_t *arena = (uint16_t*)memalign_alloc(64, total * sizeof(uint16_t));
|
|
|
|
if (!arena)
|
|
return false;
|
|
|
|
memset(arena, 0, total * sizeof(uint16_t));
|
|
|
|
rgui->fb_arena = arena;
|
|
rgui->frame_buf.data = arena + off_frame;
|
|
rgui->background_buf.data = arena + off_bg;
|
|
rgui->fs_thumbnail.data = arena + off_fs;
|
|
rgui->mini_thumbnail.data = arena + off_mini;
|
|
rgui->mini_left_thumbnail.data = arena + off_minil;
|
|
}
|
|
|
|
/* Trigger background/display update */
|
|
rgui->theme_preset_path[0] = '\0';
|
|
rgui->last_theme_dynamic_path[0] = '\0';
|
|
rgui->flags |= RGUI_FLAG_BG_MODIFIED
|
|
| RGUI_FLAG_FORCE_REDRAW;
|
|
|
|
/* If aspect ratio lock is enabled, notify
|
|
* video driver of change */
|
|
if ( (aspect_ratio_lock != RGUI_ASPECT_RATIO_LOCK_NONE)
|
|
&& (!(rgui->flags & RGUI_FLAG_IGNORE_RESIZE_EVENTS)))
|
|
{
|
|
rgui_update_menu_viewport(rgui, p_disp, aspect_ratio_lock);
|
|
/* Always staged: this function is frame-reachable, and the
|
|
* settings writes plus the aspect command belong to the main
|
|
* thread. Main-side callers that need the update applied
|
|
* before they proceed call rgui_flush_video_config() on
|
|
* return; everyone else picks it up at the next
|
|
* rgui_render(). */
|
|
rgui_stage_video_config(rgui, &rgui->menu_video_settings);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static void rgui_menu_animation_update_time(
|
|
float *ticker_pixel_increment,
|
|
unsigned video_dims)
|
|
{
|
|
/* RGUI framebuffer size is independent of
|
|
* display resolution, so have to use a fixed
|
|
* multiplier for smooth scrolling ticker text.
|
|
* We choose a value such that text is scrolled
|
|
* 1 pixel every 4 frames when ticker speed is 1x,
|
|
* which matches almost exactly the scroll speed
|
|
* of non-smooth ticker text (scrolling 1 pixel
|
|
* every 2 frames is optimal, but may be too fast
|
|
* for some users - so play it safe. Users can always
|
|
* set ticker speed to 2x if they prefer) */
|
|
*(ticker_pixel_increment) *= 0.25f;
|
|
}
|
|
|
|
static void *rgui_init(void **userdata, bool video_is_threaded)
|
|
{
|
|
unsigned new_font_height;
|
|
struct video_viewport vp;
|
|
size_t start = 0;
|
|
rgui_t *rgui = NULL;
|
|
settings_t *settings = config_get_ptr();
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
gfx_animation_t *p_anim = anim_get_ptr();
|
|
#if defined(DINGUX)
|
|
unsigned aspect_ratio_lock = RGUI_ASPECT_RATIO_LOCK_NONE;
|
|
#else
|
|
unsigned aspect_ratio_lock = settings->uints.menu_rgui_aspect_ratio_lock;
|
|
#endif
|
|
unsigned rgui_color_theme = settings->uints.menu_rgui_color_theme;
|
|
const char *dynamic_theme_dir = settings->paths.directory_dynamic_wallpapers;
|
|
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
|
|
if (!menu)
|
|
return NULL;
|
|
|
|
if (!(rgui = (rgui_t*)calloc(1, sizeof(rgui_t))))
|
|
goto error;
|
|
|
|
gfx_thumbnail_init_blank(&rgui->media_gpu);
|
|
retro_atomic_int_init(&rgui->media_gpu_states[0], 0);
|
|
retro_atomic_int_init(&rgui->media_gpu_states[1], 0);
|
|
retro_atomic_int_init(&rgui->media_gpu_states[2], 0);
|
|
*userdata = rgui;
|
|
|
|
rgui->menu_title[0] = '\0';
|
|
rgui->menu_sublabel[0] = '\0';
|
|
rgui->flags &= ~RGUI_FLAG_IS_PLAYLIST;
|
|
|
|
/* Set pixel format conversion function */
|
|
if (rgui_set_pixel_format_function())
|
|
rgui->flags |= RGUI_FLAG_TRANSPARENCY_SUPPORTED;
|
|
|
|
/* Initialise fonts */
|
|
if (!rgui_fonts_init(rgui))
|
|
goto error;
|
|
|
|
/* Cache initial video settings */
|
|
rgui_get_video_config(&rgui->content_video_settings, settings, settings->uints.video_aspect_ratio_idx);
|
|
|
|
/* Get initial 'window' dimensions */
|
|
video_driver_get_viewport_info(&vp);
|
|
rgui->window_dims = vp.full_dims;
|
|
rgui->flags &= ~RGUI_FLAG_IGNORE_RESIZE_EVENTS;
|
|
|
|
/* Set aspect ratio
|
|
* - Allocates frame buffer
|
|
* - Configures variable 'menu display' settings */
|
|
rgui->menu_aspect_ratio_lock = aspect_ratio_lock;
|
|
rgui->flags &= ~RGUI_FLAG_ASPECT_UPDATE_PENDING;
|
|
if (!rgui_set_aspect_ratio(rgui, p_disp, false,
|
|
settings->uints.menu_rgui_aspect_ratio,
|
|
settings->uints.menu_rgui_aspect_ratio_lock))
|
|
goto error;
|
|
/* Video init reads the aspect settings next: apply what was
|
|
* staged before proceeding. */
|
|
rgui_flush_video_config(rgui);
|
|
|
|
/* Fixed 'menu display' settings */
|
|
new_font_height = rgui->font_height_stride * 2;
|
|
p_disp->header_height = new_font_height;
|
|
|
|
/* Prepare RGUI colors, to improve performance */
|
|
rgui->theme_preset_path[0] = '\0';
|
|
rgui->theme_dynamic_path[0] = '\0';
|
|
rgui->last_theme_dynamic_path[0] = '\0';
|
|
if (rgui_color_theme == RGUI_THEME_DYNAMIC)
|
|
rgui_update_dynamic_theme_path(rgui, dynamic_theme_dir);
|
|
|
|
rgui_prepare_colors(rgui,
|
|
settings->uints.menu_rgui_color_theme,
|
|
settings->paths.path_rgui_theme_preset,
|
|
settings->bools.menu_rgui_transparency,
|
|
settings->uints.menu_rgui_aspect_ratio
|
|
);
|
|
|
|
menu_st->entries.begin = start;
|
|
rgui->scroll_y = 0;
|
|
|
|
if (settings->bools.menu_rgui_background_filler_thickness_enable)
|
|
rgui->flags |= RGUI_FLAG_BG_THICKNESS;
|
|
if (settings->bools.menu_rgui_border_filler_thickness_enable)
|
|
rgui->flags |= RGUI_FLAG_BORDER_THICKNESS;
|
|
if (settings->bools.menu_rgui_border_filler_enable)
|
|
rgui->flags |= RGUI_FLAG_BORDER_ENABLE;
|
|
if (settings->bools.menu_rgui_shadows)
|
|
rgui->flags |= RGUI_FLAG_SHADOW_ENABLE;
|
|
rgui->particle_effect = settings->uints.menu_rgui_particle_effect;
|
|
if (settings->bools.menu_rgui_extended_ascii)
|
|
rgui->flags |= RGUI_FLAG_EXTENDED_ASCII_ENABLE;
|
|
|
|
rgui->last_dims = VIDEO_SCALE_PACK(rgui->frame_buf.width,
|
|
rgui->frame_buf.height);
|
|
|
|
rgui->flags &= ~(RGUI_FLAG_SHOW_MOUSE
|
|
| RGUI_FLAG_SHOW_SCREENSAVER);
|
|
|
|
/* Initialise particle effect, if required */
|
|
if (rgui->particle_effect != RGUI_PARTICLE_EFFECT_NONE)
|
|
rgui_init_particle_effect(rgui, p_disp);
|
|
|
|
/* Set initial 'rgui_blit_line/rgui_blit_symbol' functions */
|
|
rgui_set_blit_functions(
|
|
rgui->language,
|
|
settings->bools.menu_rgui_shadows,
|
|
settings->bools.menu_rgui_extended_ascii);
|
|
|
|
rgui->thumbnail_queue_size = 0;
|
|
rgui->left_thumbnail_queue_size = 0;
|
|
rgui->gfx_thumbnails_prev = -1;
|
|
rgui->flags &= ~RGUI_FLAG_THUMBNAIL_LOAD_PENDING;
|
|
rgui->thumbnail_load_trigger_time = 0;
|
|
/* Ensure that we start with fullscreen thumbnails disabled */
|
|
rgui->flags &= ~RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL;
|
|
|
|
rgui->playlist_index = 0;
|
|
rgui->settings_selection_ptr = 0;
|
|
rgui->playlist_selection_ptr = 0;
|
|
memset(rgui->playlist_selection, 0, sizeof(rgui->playlist_selection));
|
|
|
|
rgui->savestate_thumbnail_file_path[0] = '\0';
|
|
|
|
/* Ensure that pointer device starts with well defined
|
|
* values (should not be necessary, but some platforms may
|
|
* not handle struct initialisation correctly...) */
|
|
memset(&rgui->pointer, 0, sizeof(menu_input_pointer_t));
|
|
|
|
p_anim->updatetime_cb = rgui_menu_animation_update_time;
|
|
|
|
return menu;
|
|
|
|
error:
|
|
if (rgui)
|
|
{
|
|
rgui_fonts_free(rgui);
|
|
rgui_buffers_free(rgui);
|
|
}
|
|
|
|
if (menu)
|
|
free(menu);
|
|
return NULL;
|
|
}
|
|
|
|
static void rgui_free(void *data)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if (!rgui)
|
|
return;
|
|
|
|
rgui_media_close(rgui, false);
|
|
rgui_fonts_free(rgui);
|
|
rgui_buffers_free(rgui);
|
|
rgui_upscale_buf_free(&rgui->upscale_buf);
|
|
free(rgui->upscale_line);
|
|
rgui->upscale_line = NULL;
|
|
rgui->upscale_line_width = 0;
|
|
rgui->upscale_map_src_width = 0;
|
|
rgui->upscale_map_width = 0;
|
|
}
|
|
|
|
static void rgui_set_texture_frame(video_driver_state_t *video_st,
|
|
const void *frame, bool rgb32,
|
|
unsigned dims, float alpha)
|
|
{
|
|
if ( video_st->poke
|
|
&& video_st->poke->set_texture_frame)
|
|
video_st->poke->set_texture_frame(video_st->data,
|
|
frame, rgb32, dims, alpha);
|
|
}
|
|
|
|
RGUI_NOINLINE static void rgui_upscale_map(rgui_t *rgui,
|
|
unsigned fb_width, unsigned out_width)
|
|
{
|
|
unsigned x_dst, x_src, rem;
|
|
uint16_t *cols = rgui->upscale_line;
|
|
for (x_dst = 0, x_src = 0, rem = 0; x_dst < out_width; x_dst++)
|
|
{
|
|
cols[x_dst] = (uint16_t)x_src;
|
|
for (rem += fb_width; rem >= out_width; rem -= out_width)
|
|
x_src++;
|
|
}
|
|
rgui->upscale_map_src_width = fb_width;
|
|
rgui->upscale_map_width = out_width;
|
|
}
|
|
|
|
static void rgui_set_texture(void *data)
|
|
{
|
|
unsigned fb_width, fb_height;
|
|
video_driver_state_t *video_st = video_state_get_ptr();
|
|
settings_t *settings = config_get_ptr();
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
#if defined(DINGUX)
|
|
unsigned internal_upscale_level = RGUI_UPSCALE_NONE;
|
|
#else
|
|
unsigned internal_upscale_level = settings->uints.menu_rgui_internal_upscale_level;
|
|
#endif
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if (rgui && rgui->frame_buf.data && menu_driver_media_startup_token())
|
|
{
|
|
memset(rgui->frame_buf.data, 0,
|
|
(size_t)VIDEO_SCALE_AREA(p_disp->framebuf_dims) * sizeof(uint16_t));
|
|
rgui_set_texture_frame(video_st, rgui->frame_buf.data,
|
|
false, p_disp->framebuf_dims, 1.0f);
|
|
p_disp->flags |= GFX_DISP_FLAG_FB_DIRTY;
|
|
return;
|
|
}
|
|
|
|
/* Framebuffer is dirty and needs to be updated? */
|
|
if (!rgui || !(p_disp->flags & GFX_DISP_FLAG_FB_DIRTY))
|
|
return;
|
|
|
|
fb_width = VIDEO_SCALE_W(p_disp->framebuf_dims);
|
|
fb_height = VIDEO_SCALE_H(p_disp->framebuf_dims);
|
|
|
|
p_disp->flags &= ~GFX_DISP_FLAG_FB_DIRTY;
|
|
|
|
if (internal_upscale_level == RGUI_UPSCALE_NONE)
|
|
rgui_set_texture_frame(video_st, rgui->frame_buf.data,
|
|
false, p_disp->framebuf_dims, 1.0f);
|
|
else
|
|
{
|
|
struct video_viewport vp;
|
|
|
|
/* Get viewport dimensions */
|
|
video_driver_get_viewport_info(&vp);
|
|
|
|
/* If viewport is currently the same size (or smaller)
|
|
* than the menu framebuffer, no scaling is required */
|
|
if ((VIDEO_SCALE_W(vp.dims) <= fb_width) && (VIDEO_SCALE_H(vp.dims) <= fb_height))
|
|
rgui_set_texture_frame(video_st, rgui->frame_buf.data,
|
|
false, p_disp->framebuf_dims, 1.0f);
|
|
else
|
|
{
|
|
unsigned out_width;
|
|
unsigned out_height;
|
|
unsigned y_src, prev_y_src, rem;
|
|
unsigned x_dst, y_dst;
|
|
size_t out_pitch;
|
|
uint16_t *cols, *line;
|
|
uint16_t *out_frame = NULL;
|
|
frame_buf_t *frame_buf = &rgui->frame_buf;
|
|
frame_buf_t *upscale_buf = &rgui->upscale_buf;
|
|
|
|
/* Determine output size */
|
|
if (internal_upscale_level == RGUI_UPSCALE_AUTO)
|
|
{
|
|
out_width = ((VIDEO_SCALE_W(vp.dims) / fb_width) + 1) * fb_width;
|
|
out_height = ((VIDEO_SCALE_H(vp.dims) / fb_height) + 1) * fb_height;
|
|
}
|
|
else
|
|
{
|
|
out_width = internal_upscale_level * fb_width;
|
|
out_height = internal_upscale_level * fb_height;
|
|
}
|
|
|
|
if (rgui->upscale_line_width < out_width)
|
|
{
|
|
uint16_t *upscale_line = (uint16_t*)realloc(rgui->upscale_line,
|
|
(size_t)out_width * 2 * sizeof(uint16_t));
|
|
if (!upscale_line)
|
|
goto upscale_failed;
|
|
rgui->upscale_line = upscale_line;
|
|
rgui->upscale_line_width = out_width;
|
|
}
|
|
|
|
out_pitch = (size_t)out_width * sizeof(uint16_t);
|
|
/* Render into the unpublished upload slot when available. */
|
|
if (VIDEO_SCALE_FITS(out_width, out_height))
|
|
out_frame = (uint16_t*)video_driver_get_menu_framebuffer(
|
|
VIDEO_SCALE_PACK(out_width, out_height), false, &out_pitch);
|
|
/* Allocate upscaling buffer, if required */
|
|
if (!out_frame && ((upscale_buf->width != out_width)
|
|
|| (upscale_buf->height != out_height)
|
|
|| !upscale_buf->data))
|
|
{
|
|
upscale_buf->width = out_width;
|
|
upscale_buf->height = out_height;
|
|
|
|
if (upscale_buf->data)
|
|
{
|
|
free(upscale_buf->data);
|
|
upscale_buf->data = NULL;
|
|
}
|
|
|
|
if (!(upscale_buf->data = (uint16_t*)
|
|
calloc(out_width * out_height, sizeof(uint16_t))))
|
|
goto upscale_failed;
|
|
}
|
|
|
|
if (!out_frame)
|
|
{
|
|
out_frame = upscale_buf->data;
|
|
out_pitch = (size_t)out_width * sizeof(uint16_t);
|
|
}
|
|
|
|
/* Perform nearest neighbour upscaling
|
|
* NB: We're duplicating code here, but trying to handle
|
|
* this with a polymorphic function is too much of a drag... */
|
|
cols = rgui->upscale_line;
|
|
line = cols + out_width;
|
|
prev_y_src = fb_height;
|
|
|
|
/* Source of each output pixel: floor(dst * fb / out),
|
|
* stepped, so at a whole factor each source pixel is
|
|
* repeated exactly that many times */
|
|
if ( rgui->upscale_map_src_width != fb_width
|
|
|| rgui->upscale_map_width != out_width)
|
|
rgui_upscale_map(rgui, fb_width, out_width);
|
|
|
|
for (y_dst = 0, y_src = 0, rem = 0; y_dst < out_height; y_dst++)
|
|
{
|
|
if (y_src != prev_y_src)
|
|
{
|
|
const uint16_t *src = frame_buf->data + (y_src * fb_width);
|
|
for (x_dst = 0; x_dst < out_width; x_dst++)
|
|
line[x_dst] = src[cols[x_dst]];
|
|
prev_y_src = y_src;
|
|
}
|
|
memcpy((uint8_t*)out_frame + y_dst * out_pitch, line,
|
|
out_width * sizeof(uint16_t));
|
|
for (rem += fb_height; rem >= out_height; rem -= out_height)
|
|
y_src++;
|
|
}
|
|
|
|
/* Draw upscaled texture */
|
|
rgui_set_texture_frame(video_st, out_frame,
|
|
false, VIDEO_SCALE_PACK(out_width, out_height), 1.0f);
|
|
}
|
|
}
|
|
return;
|
|
|
|
upscale_failed:
|
|
/* Uh oh... This could mean we don't have enough
|
|
* memory, so disable upscaling and draw the usual
|
|
* framebuffer... */
|
|
configuration_set_uint(settings,
|
|
settings->uints.menu_rgui_internal_upscale_level,
|
|
RGUI_UPSCALE_NONE);
|
|
rgui_set_texture_frame(video_st, rgui->frame_buf.data,
|
|
false, p_disp->framebuf_dims, 1.0f);
|
|
}
|
|
|
|
static void rgui_navigation_clear(void *data, bool pending_push)
|
|
{
|
|
size_t start = 0;
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
if (!rgui)
|
|
return;
|
|
|
|
menu_st->entries.begin = start;
|
|
rgui->scroll_y = 0;
|
|
}
|
|
|
|
static void rgui_load_current_thumbnails(rgui_t *rgui, struct menu_state *menu_st, bool download_missing)
|
|
{
|
|
bool thumbnails_missing = false;
|
|
|
|
/* Right (or fullscreen) thumbnail */
|
|
rgui->flags &= ~RGUI_FLAG_ENTRY_HAS_THUMBNAIL;
|
|
if (*menu_st->thumbnail_path_data->right_path)
|
|
{
|
|
if (rgui_request_thumbnail(
|
|
(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
? &rgui->fs_thumbnail
|
|
: &rgui->mini_thumbnail,
|
|
GFX_THUMBNAIL_RIGHT,
|
|
&rgui->thumbnail_queue_size,
|
|
menu_st->thumbnail_path_data->right_path,
|
|
&thumbnails_missing))
|
|
rgui->flags |= RGUI_FLAG_ENTRY_HAS_THUMBNAIL;
|
|
}
|
|
else if (*menu_st->thumbnail_path_data->left_path)
|
|
{
|
|
if (rgui_request_thumbnail(
|
|
(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
? &rgui->fs_thumbnail
|
|
: &rgui->mini_left_thumbnail,
|
|
GFX_THUMBNAIL_LEFT,
|
|
&rgui->left_thumbnail_queue_size,
|
|
menu_st->thumbnail_path_data->left_path,
|
|
&thumbnails_missing))
|
|
rgui->flags |= RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
}
|
|
|
|
/* Left thumbnail
|
|
* (Note: there is no need to load this when viewing
|
|
* fullscreen thumbnails) */
|
|
if ( !(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& !*rgui->savestate_thumbnail_file_path)
|
|
{
|
|
rgui->flags &= ~RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
if (*menu_st->thumbnail_path_data->left_path)
|
|
{
|
|
if (rgui_request_thumbnail(
|
|
&rgui->mini_left_thumbnail,
|
|
GFX_THUMBNAIL_LEFT,
|
|
&rgui->left_thumbnail_queue_size,
|
|
menu_st->thumbnail_path_data->left_path,
|
|
&thumbnails_missing))
|
|
rgui->flags |= RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
}
|
|
}
|
|
else if (*rgui->savestate_thumbnail_file_path)
|
|
{
|
|
rgui->flags &= ~RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
if (*menu_st->thumbnail_path_data->left_path)
|
|
{
|
|
if (rgui_request_thumbnail(
|
|
&rgui->mini_left_thumbnail,
|
|
GFX_THUMBNAIL_LEFT,
|
|
&rgui->left_thumbnail_queue_size,
|
|
rgui->savestate_thumbnail_file_path,
|
|
&thumbnails_missing))
|
|
rgui->flags |= RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
}
|
|
}
|
|
|
|
/* Reset 'load pending' state */
|
|
rgui->flags &= ~RGUI_FLAG_THUMBNAIL_LOAD_PENDING;
|
|
/* Force a redraw (so 'entry_has_thumbnail' values are
|
|
* applied immediately) */
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
|
|
#ifdef HAVE_NETWORKING
|
|
/* On demand thumbnail downloads */
|
|
if (thumbnails_missing && download_missing)
|
|
{
|
|
playlist_t *playlist = playlist_get_cached();
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
size_t selection = menu_st->selection_ptr;
|
|
|
|
/* Explore list needs cached selection index */
|
|
if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
selection = menu_st->thumbnail_path_data
|
|
? menu_st->thumbnail_path_data->playlist_index
|
|
: 0;
|
|
|
|
if (*menu_st->thumbnail_path_data->system)
|
|
task_push_pl_entry_thumbnail_download(
|
|
menu_st->thumbnail_path_data->system,
|
|
playlist, (unsigned)selection,
|
|
false, true);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
static void rgui_update_savestate_thumbnail_path(void *data, unsigned i)
|
|
{
|
|
/* Off the frame: a path and a menu_entry_t came to 5960 bytes where
|
|
* this tree allows four thousand. This runs when the selection
|
|
* moves, not every frame, so one allocation costs less than the
|
|
* frame did. */
|
|
struct rgui_savestate_thumb_scratch
|
|
{
|
|
menu_entry_t entry;
|
|
char path[PATH_MAX_LENGTH];
|
|
} *scratch;
|
|
settings_t *settings = config_get_ptr();
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
bool savestate_thumbnail = settings->bools.savestate_thumbnail_enable;
|
|
|
|
if (!(scratch = (struct rgui_savestate_thumb_scratch*)malloc(sizeof(*scratch))))
|
|
return;
|
|
|
|
if (!rgui)
|
|
{ free(scratch); return; }
|
|
rgui->savestate_thumbnail_file_path[0] = '\0';
|
|
|
|
/* Savestate thumbnails are only relevant
|
|
* when viewing the running quick menu or state slots */
|
|
if (!( (rgui->flags & RGUI_FLAG_IS_QUICK_MENU && menu_is_running_quick_menu())
|
|
|| (rgui->flags & RGUI_FLAG_IS_STATE_SLOT)))
|
|
{ free(scratch); return; }
|
|
if (savestate_thumbnail)
|
|
{
|
|
menu_entry_t *entry = &scratch->entry;
|
|
|
|
MENU_ENTRY_INITIALIZE((*entry));
|
|
entry->flags |= MENU_ENTRY_FLAG_LABEL_ENABLED;
|
|
menu_entry_get(entry, 0, i, NULL, true);
|
|
|
|
if (*entry->label)
|
|
{
|
|
unsigned _state_slot = string_to_unsigned(entry->label);
|
|
if ( _state_slot == MENU_ENUM_LABEL_STATE_SLOT
|
|
|| string_is_equal(entry->label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR)
|
|
|| string_is_equal(entry->label, MENU_ENUM_LABEL_STATE_SLOT_STR)
|
|
|| string_is_equal(entry->label, MENU_ENUM_LABEL_LOAD_STATE_STR)
|
|
|| string_is_equal(entry->label, MENU_ENUM_LABEL_SAVE_STATE_STR))
|
|
{
|
|
char *path = scratch->path;
|
|
runloop_state_t *runloop_st = runloop_state_get_ptr();
|
|
int state_slot = settings->ints.state_slot;
|
|
|
|
/* State slot dropdown */
|
|
if ( _state_slot == MENU_ENUM_LABEL_STATE_SLOT
|
|
|| string_is_equal(entry->label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR))
|
|
{
|
|
state_slot = i - 1;
|
|
rgui->flags |= RGUI_FLAG_IS_STATE_SLOT;
|
|
}
|
|
|
|
gfx_savestate_thumbnail_get_path(path, PATH_MAX_LENGTH,
|
|
runloop_st->name.savestate, state_slot);
|
|
|
|
strlcpy(rgui->savestate_thumbnail_file_path,
|
|
path,
|
|
sizeof(rgui->savestate_thumbnail_file_path));
|
|
}
|
|
}
|
|
}
|
|
free(scratch);
|
|
}
|
|
|
|
static void rgui_reset_savestate_thumbnail(void *data)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if (!*rgui->savestate_thumbnail_file_path)
|
|
return;
|
|
|
|
rgui->mini_left_thumbnail.dims = 0;
|
|
rgui->mini_left_thumbnail.is_valid = false;
|
|
rgui->mini_left_thumbnail.path[0] = '\0';
|
|
|
|
rgui->fs_thumbnail.dims = 0;
|
|
rgui->fs_thumbnail.is_valid = false;
|
|
rgui->fs_thumbnail.path[0] = '\0';
|
|
|
|
rgui->flags &= ~RGUI_FLAG_ENTRY_HAS_THUMBNAIL;
|
|
rgui->flags &= ~RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
}
|
|
|
|
static void rgui_update_savestate_thumbnail_image(void *data)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
if (!rgui)
|
|
return;
|
|
|
|
/* If path is empty, just reset thumbnail */
|
|
if ( !*rgui->savestate_thumbnail_file_path
|
|
|| !path_is_valid(rgui->savestate_thumbnail_file_path))
|
|
rgui_reset_savestate_thumbnail(rgui);
|
|
else
|
|
{
|
|
bool thumbnails_missing = false;
|
|
rgui->flags &= ~RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
|
|
if (rgui_request_thumbnail(
|
|
&rgui->mini_left_thumbnail,
|
|
GFX_THUMBNAIL_LEFT,
|
|
&rgui->left_thumbnail_queue_size,
|
|
rgui->savestate_thumbnail_file_path,
|
|
&thumbnails_missing))
|
|
rgui->flags |= RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL;
|
|
}
|
|
}
|
|
|
|
static void rgui_scan_selected_entry_thumbnail(rgui_t *rgui, bool force_load)
|
|
{
|
|
bool has_thumbnail = false;
|
|
settings_t *settings = config_get_ptr();
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
menu_list_t *menu_list = menu_st->entries.list;
|
|
size_t selection = menu_st->selection_ptr;
|
|
file_list_t *list = menu_list ? MENU_LIST_GET_SELECTION(menu_list, 0) : NULL;
|
|
size_t list_size = list ? list->size : 0;
|
|
unsigned menu_rgui_thumbnail_delay= settings->uints.menu_rgui_thumbnail_delay;
|
|
bool network_on_demand_thumbnails = settings->bools.network_on_demand_thumbnails;
|
|
if (menu_media_controls_settings_active(&rgui->media)) return;
|
|
rgui->flags &= ~(RGUI_FLAG_THUMBNAIL_LOAD_PENDING
|
|
| RGUI_FLAG_ENTRY_HAS_THUMBNAIL
|
|
| RGUI_FLAG_ENTRY_HAS_LEFT_THUMBNAIL
|
|
);
|
|
|
|
rgui->media_requested_path[0] = '\0';
|
|
|
|
/* Reset savestate thumbnails always */
|
|
if (selection < list_size)
|
|
{
|
|
rgui_update_savestate_thumbnail_path(rgui, (unsigned)selection);
|
|
rgui_update_savestate_thumbnail_image(rgui);
|
|
}
|
|
|
|
/* Update thumbnail content/path */
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_QUICK_MENU))
|
|
{
|
|
bool playlist_valid = false;
|
|
size_t playlist_index = selection;
|
|
|
|
if (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
{
|
|
/* Get playlist index corresponding
|
|
* to the selected entry */
|
|
if ( (list)
|
|
&& (selection < list_size)
|
|
&& (list->list[selection].type == FILE_TYPE_RPL_ENTRY))
|
|
{
|
|
playlist_valid = true;
|
|
playlist_index = list->list[selection].entry_idx;
|
|
rgui->playlist_index = playlist_index;
|
|
}
|
|
|
|
gfx_thumbnail_set_content_playlist(menu_st->thumbnail_path_data,
|
|
playlist_valid ? playlist_get_cached() : NULL, playlist_index);
|
|
}
|
|
else if (rgui->flags & RGUI_FLAG_IS_QUICK_MENU)
|
|
{
|
|
if (!*rgui->savestate_thumbnail_file_path)
|
|
playlist_valid = true;
|
|
|
|
playlist_index = rgui->playlist_index;
|
|
|
|
gfx_thumbnail_set_content_playlist(menu_st->thumbnail_path_data,
|
|
playlist_valid ? playlist_get_cached() : NULL, playlist_index);
|
|
}
|
|
#if defined(HAVE_LIBRETRODB)
|
|
else if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
{
|
|
/* Get playlist index corresponding
|
|
* to the selected entry */
|
|
if (list && selection < list_size)
|
|
{
|
|
/* Selected entry */
|
|
menu_entry_t entry;
|
|
MENU_ENTRY_INITIALIZE(entry);
|
|
entry.flags |= MENU_ENTRY_FLAG_PATH_ENABLED;
|
|
menu_entry_get(&entry, 0, selection, NULL, true);
|
|
|
|
rgui->playlist_index =
|
|
menu_explore_set_playlist_thumbnail(entry.type, menu_st->thumbnail_path_data);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
if (gfx_thumbnail_is_enabled(menu_st->thumbnail_path_data, GFX_THUMBNAIL_RIGHT))
|
|
has_thumbnail = gfx_thumbnail_update_path(menu_st->thumbnail_path_data, GFX_THUMBNAIL_RIGHT);
|
|
|
|
if (gfx_thumbnail_is_enabled(menu_st->thumbnail_path_data, GFX_THUMBNAIL_LEFT))
|
|
has_thumbnail = gfx_thumbnail_update_path(menu_st->thumbnail_path_data, GFX_THUMBNAIL_LEFT) || has_thumbnail;
|
|
}
|
|
|
|
if (!(rgui->flags & (RGUI_FLAG_IS_PLAYLIST | RGUI_FLAG_IS_EXPLORE_LIST
|
|
| RGUI_FLAG_IS_QUICK_MENU)) && list && selection < list_size)
|
|
{
|
|
const struct item_file *item = &list->list[selection];
|
|
enum image_type_enum type = image_texture_get_type(item->path);
|
|
file_list_t *stack = MENU_LIST_GET(menu_list, 0);
|
|
if (stack && stack->size && (item->type == FILE_TYPE_IMAGEVIEWER
|
|
|| item->type == FILE_TYPE_IMAGE || type == IMAGE_TYPE_MP4
|
|
|| type == IMAGE_TYPE_WEBM)
|
|
&& gfx_thumbnail_set_content_image(menu_st->thumbnail_path_data,
|
|
stack->list[stack->size - 1].path, item->path))
|
|
{
|
|
strlcpy(menu_st->thumbnail_path_data->right_path,
|
|
menu_st->thumbnail_path_data->content_path,
|
|
sizeof(menu_st->thumbnail_path_data->right_path));
|
|
has_thumbnail = true;
|
|
}
|
|
}
|
|
/* The open viewer shows an image history entry itself, whatever
|
|
* the playlist thumbnail settings */
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
&& (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
{
|
|
char history_dir[DIR_MAX_LENGTH];
|
|
const char *image = menu_media_selected_history_image(menu_st);
|
|
if (image)
|
|
{
|
|
fill_pathname_basedir(history_dir, image, sizeof(history_dir));
|
|
if (gfx_thumbnail_set_content_image(menu_st->thumbnail_path_data,
|
|
history_dir, path_basename(image)))
|
|
{
|
|
strlcpy(menu_st->thumbnail_path_data->right_path,
|
|
menu_st->thumbnail_path_data->content_path,
|
|
sizeof(menu_st->thumbnail_path_data->right_path));
|
|
has_thumbnail = true;
|
|
}
|
|
}
|
|
}
|
|
if (has_thumbnail)
|
|
{
|
|
enum image_type_enum type = image_texture_get_type(menu_st->thumbnail_path_data->right_path);
|
|
if (type == IMAGE_TYPE_MP4 || type == IMAGE_TYPE_WEBM)
|
|
strlcpy(rgui->media_requested_path, menu_st->thumbnail_path_data->right_path,
|
|
sizeof(rgui->media_requested_path));
|
|
}
|
|
|
|
/* Check whether thumbnails should be loaded */
|
|
if (has_thumbnail)
|
|
{
|
|
/* Check whether thumbnails should be loaded immediately */
|
|
if ((menu_rgui_thumbnail_delay == 0) || force_load)
|
|
rgui_load_current_thumbnails(rgui, menu_st, network_on_demand_thumbnails);
|
|
else
|
|
{
|
|
/* Schedule a delayed load */
|
|
rgui->flags |= RGUI_FLAG_THUMBNAIL_LOAD_PENDING;
|
|
rgui->thumbnail_load_trigger_time = menu_driver_get_current_time();
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rgui_update_thumbnail_image(void *data)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST))
|
|
rgui_scan_selected_entry_thumbnail(rgui, true);
|
|
}
|
|
|
|
static void rgui_toggle_fs_thumbnail(rgui_t *rgui,
|
|
bool menu_rgui_inline_thumbnails)
|
|
{
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
rgui->flags &= ~RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL;
|
|
else
|
|
rgui->flags |= RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL;
|
|
|
|
/* It is possible that we are waiting for a 'right' thumbnail
|
|
* image to load at this point. If so, and we are displaying
|
|
* inline thumbnails, then 'fs_thumbnail' and 'mini_thumbnail'
|
|
* can get mixed up. To avoid this, we simply 'reset' the
|
|
* currently inactive right thumbnail. */
|
|
if (menu_rgui_inline_thumbnails && !*rgui->media_requested_path)
|
|
{
|
|
if (*rgui->savestate_thumbnail_file_path)
|
|
rgui_reset_savestate_thumbnail(rgui);
|
|
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
{
|
|
rgui->mini_thumbnail.dims = 0;
|
|
rgui->mini_thumbnail.is_valid = false;
|
|
rgui->mini_thumbnail.path[0] = '\0';
|
|
}
|
|
else
|
|
{
|
|
rgui->fs_thumbnail.dims = 0;
|
|
rgui->fs_thumbnail.is_valid = false;
|
|
rgui->fs_thumbnail.path[0] = '\0';
|
|
}
|
|
}
|
|
|
|
/* Note that we always load thumbnails immediately
|
|
* when toggling via a RetroPad button (scheduling a
|
|
* delayed load here would make for a poor user
|
|
* experience...) */
|
|
rgui_scan_selected_entry_thumbnail(rgui, true);
|
|
}
|
|
|
|
static void rgui_refresh_thumbnail_image(void *userdata, size_t i)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)userdata;
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
settings_t *settings = config_get_ptr();
|
|
bool rgui_inline_thumbnails = false;
|
|
if (!rgui || !settings)
|
|
return;
|
|
rgui_inline_thumbnails = settings->bools.menu_rgui_inline_thumbnails
|
|
|| (rgui->flags & RGUI_FLAG_IS_QUICK_MENU);
|
|
|
|
/* Only refresh thumbnails if thumbnails are visible */
|
|
if ((rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL) || rgui_inline_thumbnails)
|
|
{
|
|
/* In all cases, reset current thumbnails */
|
|
rgui->fs_thumbnail.dims = 0;
|
|
rgui->fs_thumbnail.is_valid = false;
|
|
rgui->fs_thumbnail.path[0] = '\0';
|
|
|
|
rgui->mini_thumbnail.dims = 0;
|
|
rgui->mini_thumbnail.is_valid = false;
|
|
rgui->mini_thumbnail.path[0] = '\0';
|
|
|
|
rgui->mini_left_thumbnail.dims = 0;
|
|
rgui->mini_left_thumbnail.is_valid = false;
|
|
rgui->mini_left_thumbnail.path[0] = '\0';
|
|
|
|
/* Skip thumbnail scan if neither are enabled */
|
|
if ( !gfx_thumbnail_is_enabled(menu_st->thumbnail_path_data, GFX_THUMBNAIL_RIGHT)
|
|
&& !gfx_thumbnail_is_enabled(menu_st->thumbnail_path_data, GFX_THUMBNAIL_LEFT))
|
|
return;
|
|
|
|
/* Only load thumbnails if currently viewing a
|
|
* playlist (note that thumbnails are loaded
|
|
* immediately, for an optimal user experience) */
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_QUICK_MENU))
|
|
rgui_scan_selected_entry_thumbnail(rgui, true);
|
|
}
|
|
}
|
|
|
|
static void rgui_action_switch_thumbnail(rgui_t *rgui)
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
if (!settings)
|
|
return;
|
|
|
|
if (settings->uints.gfx_thumbnails)
|
|
{
|
|
uint8_t cur_primary = settings->uints.gfx_thumbnails;
|
|
uint8_t cur_secondary = settings->uints.menu_left_thumbnails;
|
|
|
|
cur_primary++;
|
|
|
|
/* Prevent dupe image */
|
|
if ( (!(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
&& (cur_primary == cur_secondary && cur_secondary))
|
|
cur_primary++;
|
|
|
|
/* Wrap primary to first image type, and skip logo */
|
|
if (cur_primary > PLAYLIST_THUMBNAIL_MODE_LAST - PLAYLIST_THUMBNAIL_MODE_OFF - 2)
|
|
cur_primary = 1;
|
|
|
|
/* Final dupe check */
|
|
if ( (!(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
&& (cur_primary == cur_secondary && cur_secondary))
|
|
cur_primary++;
|
|
|
|
configuration_set_uint(settings, settings->uints.gfx_thumbnails, cur_primary);
|
|
}
|
|
else
|
|
{
|
|
uint8_t cur_primary = settings->uints.gfx_thumbnails;
|
|
uint8_t cur_secondary = settings->uints.menu_left_thumbnails;
|
|
|
|
cur_secondary++;
|
|
|
|
/* Prevent dupe image */
|
|
if ( (!(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
&& (cur_primary == cur_secondary))
|
|
cur_secondary++;
|
|
|
|
/* Wrap secondary to no image, and skip logo */
|
|
if (cur_secondary > PLAYLIST_THUMBNAIL_MODE_LAST - PLAYLIST_THUMBNAIL_MODE_OFF - 2)
|
|
cur_secondary = (cur_primary) ? 0 : 1;
|
|
|
|
configuration_set_uint(settings, settings->uints.menu_left_thumbnails, cur_secondary);
|
|
}
|
|
|
|
rgui_refresh_thumbnail_image(rgui, 0);
|
|
}
|
|
|
|
static void rgui_update_menu_sublabel(rgui_t *rgui, size_t selection)
|
|
{
|
|
menu_entry_t entry;
|
|
MENU_ENTRY_INITIALIZE(entry);
|
|
entry.flags |= MENU_ENTRY_FLAG_SUBLABEL_ENABLED;
|
|
menu_entry_get(&entry, 0, (unsigned)selection, NULL, true);
|
|
rgui->menu_sublabel[0] = '\0';
|
|
if (*entry.sublabel)
|
|
{
|
|
const char *src = entry.sublabel;
|
|
size_t offset = 0;
|
|
size_t buf_size = sizeof(rgui->menu_sublabel);
|
|
|
|
while (*src)
|
|
{
|
|
const char *line_start;
|
|
const char *line_end;
|
|
size_t len;
|
|
|
|
/* Skip leading whitespace and newlines */
|
|
while (*src == ' ' || *src == '\t' || *src == '\n' || *src == '\r')
|
|
src++;
|
|
|
|
if (*src == '\0')
|
|
break;
|
|
|
|
/* Find end of this line */
|
|
line_start = src;
|
|
while (*src && *src != '\n' && *src != '\r')
|
|
src++;
|
|
|
|
/* Trim trailing whitespace */
|
|
line_end = src;
|
|
while (line_end > line_start
|
|
&& (*(line_end - 1) == ' ' || *(line_end - 1) == '\t'))
|
|
line_end--;
|
|
|
|
len = (size_t)(line_end - line_start);
|
|
if (len == 0)
|
|
continue;
|
|
|
|
/* Insert spacer between lines */
|
|
if (offset > 0 && offset + 1 < buf_size)
|
|
{
|
|
size_t spacer_len = strlcpy(
|
|
rgui->menu_sublabel + offset,
|
|
RGUI_TICKER_SPACER,
|
|
buf_size - offset);
|
|
if (offset + spacer_len < buf_size)
|
|
offset += spacer_len;
|
|
else
|
|
offset = buf_size - 1;
|
|
}
|
|
|
|
/* Append trimmed line */
|
|
if (offset + 1 < buf_size)
|
|
{
|
|
if (len > buf_size - offset - 1)
|
|
len = buf_size - offset - 1;
|
|
memcpy(rgui->menu_sublabel + offset, line_start, len);
|
|
offset += len;
|
|
rgui->menu_sublabel[offset] = '\0';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static void rgui_navigation_set(void *data, bool scroll)
|
|
{
|
|
size_t start = 0;
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
menu_list_t *menu_list = menu_st->entries.list;
|
|
size_t end = menu_list ? MENU_LIST_GET_SELECTION(menu_list, 0)->size : 0;
|
|
size_t selection = menu_st->selection_ptr;
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if (!rgui)
|
|
return;
|
|
|
|
if (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
{
|
|
if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_HISTORY_TAB)))
|
|
rgui->playlist_mainmenu_selection[RGUI_MAINMENU_HISTORY] = selection;
|
|
else if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES_TAB)))
|
|
rgui->playlist_mainmenu_selection[RGUI_MAINMENU_FAVORITES] = selection;
|
|
/* one slot per playlist, for as many as the array holds */
|
|
else if (rgui->playlist_selection_ptr < ARRAY_SIZE(rgui->playlist_selection))
|
|
rgui->playlist_selection[rgui->playlist_selection_ptr] = selection;
|
|
}
|
|
else if (rgui->flags & RGUI_FLAG_IS_PLAYLISTS_TAB)
|
|
rgui->playlist_selection_ptr = selection;
|
|
else if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SETTINGS)))
|
|
rgui->settings_selection_ptr = selection;
|
|
|
|
rgui_scan_selected_entry_thumbnail(rgui, false);
|
|
|
|
rgui->menu_sublabel[0] = '\0';
|
|
if (config_get_ptr()->bools.menu_show_sublabels && selection < end)
|
|
rgui_update_menu_sublabel(rgui, selection);
|
|
|
|
/* Update entry index text */
|
|
rgui->entry_index_str[0] = '\0';
|
|
if ( config_get_ptr()->bools.playlist_show_entry_idx
|
|
&& ((rgui->flags & RGUI_FLAG_IS_PLAYLIST) || (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)))
|
|
{
|
|
size_t entry_idx_selection = selection + 1;
|
|
size_t list_size = MENU_LIST_GET_SELECTION(menu_list, 0)->size;
|
|
unsigned entry_idx_offset = rgui->entry_index_offset;
|
|
bool show_entry_idx = true;
|
|
|
|
if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
{
|
|
if (entry_idx_selection > entry_idx_offset && entry_idx_offset)
|
|
entry_idx_selection -= entry_idx_offset;
|
|
else
|
|
show_entry_idx = false;
|
|
|
|
if (list_size >= entry_idx_offset)
|
|
list_size -= entry_idx_offset;
|
|
}
|
|
|
|
if (show_entry_idx)
|
|
snprintf(rgui->entry_index_str, sizeof(rgui->entry_index_str),
|
|
"%lu/%lu", (unsigned long)entry_idx_selection,
|
|
(unsigned long)list_size);
|
|
}
|
|
|
|
if (!scroll)
|
|
return;
|
|
|
|
if (selection < rgui->term_layout.height / 2) { }
|
|
else if (selection >= (rgui->term_layout.height / 2)
|
|
&& selection < (end - rgui->term_layout.height / 2))
|
|
start = selection - rgui->term_layout.height / 2;
|
|
else if (selection >= (end - rgui->term_layout.height / 2))
|
|
start = end - rgui->term_layout.height;
|
|
else
|
|
return;
|
|
|
|
menu_st->entries.begin = start;
|
|
rgui->scroll_y = (int32_t)(start * rgui->font_height_stride);
|
|
}
|
|
|
|
static void rgui_navigation_set_last(void *data)
|
|
{
|
|
rgui_navigation_set(data, true);
|
|
}
|
|
|
|
static void rgui_navigation_descend_alphabet(void *data, size_t *unused)
|
|
{
|
|
rgui_navigation_set(data, true);
|
|
}
|
|
|
|
static void rgui_navigation_ascend_alphabet(void *data, size_t *unused)
|
|
{
|
|
rgui_navigation_set(data, true);
|
|
}
|
|
|
|
static void rgui_populate_entries(
|
|
void *data,
|
|
const char *path,
|
|
const char *label,
|
|
unsigned k)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
settings_t *settings = config_get_ptr();
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
#if defined(DINGUX)
|
|
unsigned aspect_ratio_lock = RGUI_ASPECT_RATIO_LOCK_NONE;
|
|
#else
|
|
unsigned aspect_ratio_lock = settings->uints.menu_rgui_aspect_ratio_lock;
|
|
#endif
|
|
const char *dynamic_theme_dir = settings->paths.directory_dynamic_wallpapers;
|
|
uint8_t remember_selection = settings->uints.menu_remember_selection;
|
|
#ifdef HAVE_LANGEXTRA
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
#endif
|
|
|
|
if (!rgui)
|
|
return;
|
|
|
|
#ifdef HAVE_LANGEXTRA
|
|
/* Check whether user language has changed */
|
|
if (rgui->language != *msg_hash_get_uint(MSG_HASH_USER_LANGUAGE))
|
|
{
|
|
/* Reinitialize fonts */
|
|
rgui_fonts_free(rgui);
|
|
rgui_fonts_init(rgui);
|
|
|
|
/* Update rgui_blit_line functions */
|
|
rgui_set_blit_functions(
|
|
rgui->language,
|
|
(rgui->flags & RGUI_FLAG_SHADOW_ENABLE) ? true : false,
|
|
(rgui->flags & RGUI_FLAG_EXTENDED_ASCII_ENABLE) ? true : false);
|
|
|
|
/* Need to recalculate terminal dimensions
|
|
* > easiest method is to call
|
|
* rgui_set_aspect_ratio() */
|
|
rgui_set_aspect_ratio(rgui, p_disp, true,
|
|
settings->uints.menu_rgui_aspect_ratio,
|
|
settings->uints.menu_rgui_aspect_ratio_lock);
|
|
}
|
|
#endif
|
|
|
|
/* Check whether we are currently viewing a playlist */
|
|
if ( string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_PLAYLIST_LIST_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_LOAD_CONTENT_HISTORY_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_FAVORITES_LIST_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_IMAGES_LIST_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_MUSIC_LIST_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_VIDEO_LIST_STR)
|
|
)
|
|
rgui->flags |= RGUI_FLAG_IS_PLAYLIST;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_IS_PLAYLIST;
|
|
|
|
if (string_is_equal(label, MENU_ENUM_LABEL_PLAYLISTS_TAB_STR))
|
|
rgui->flags |= RGUI_FLAG_IS_PLAYLISTS_TAB;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_IS_PLAYLISTS_TAB;
|
|
|
|
/* Determine whether this is the quick menu */
|
|
if ( string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_RPL_ENTRY_ACTIONS_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_CONTENT_SETTINGS_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_SAVESTATE_LIST_STR))
|
|
rgui->flags |= RGUI_FLAG_IS_QUICK_MENU;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_IS_QUICK_MENU;
|
|
|
|
if ( string_to_unsigned(path) == MENU_ENUM_LABEL_STATE_SLOT
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_STATE_SLOT_RUN_STR))
|
|
rgui->flags |= RGUI_FLAG_IS_STATE_SLOT;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_IS_STATE_SLOT;
|
|
|
|
#if defined(HAVE_LIBRETRODB)
|
|
if ( string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_EXPLORE_LIST_STR)
|
|
|| string_is_equal(label, MENU_ENUM_LABEL_EXPLORE_TAB_STR))
|
|
rgui->flags |= RGUI_FLAG_IS_EXPLORE_LIST;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_IS_EXPLORE_LIST;
|
|
|
|
/* Quick Menu under Explore list must also be Quick Menu */
|
|
if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
{
|
|
menu_entry_t entry;
|
|
MENU_ENTRY_INITIALIZE(entry);
|
|
entry.flags |= MENU_ENTRY_FLAG_LABEL_ENABLED;
|
|
menu_entry_get(&entry, 0, 0, NULL, true);
|
|
|
|
/* Quick Menu under Explore list must also be Quick Menu */
|
|
if ( string_is_equal(entry.label, MENU_ENUM_LABEL_RUN_STR)
|
|
|| string_is_equal(entry.label, MENU_ENUM_LABEL_RESUME_CONTENT_STR)
|
|
|| string_is_equal(entry.label, MENU_ENUM_LABEL_STATE_SLOT_STR)
|
|
)
|
|
{
|
|
rgui->flags |= RGUI_FLAG_IS_QUICK_MENU;
|
|
rgui->flags &= ~RGUI_FLAG_IS_EXPLORE_LIST;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* Set menu title */
|
|
menu_entries_get_title(rgui->menu_title, sizeof(rgui->menu_title));
|
|
|
|
/* If dynamic themes are enabled, update the theme path */
|
|
if (rgui->color_theme == RGUI_THEME_DYNAMIC)
|
|
rgui_update_dynamic_theme_path(rgui, dynamic_theme_dir);
|
|
|
|
/* Cancel any pending thumbnail load operations */
|
|
rgui->flags &= ~RGUI_FLAG_THUMBNAIL_LOAD_PENDING;
|
|
|
|
if (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
{
|
|
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|
|
|| remember_selection == MENU_REMEMBER_SELECTION_PLAYLISTS)
|
|
{
|
|
if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_HISTORY_TAB)))
|
|
menu_st->selection_ptr = rgui->playlist_mainmenu_selection[RGUI_MAINMENU_HISTORY];
|
|
else if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES_TAB)))
|
|
menu_st->selection_ptr = rgui->playlist_mainmenu_selection[RGUI_MAINMENU_FAVORITES];
|
|
else if (rgui->playlist_selection_ptr < ARRAY_SIZE(rgui->playlist_selection))
|
|
menu_st->selection_ptr = rgui->playlist_selection[rgui->playlist_selection_ptr];
|
|
}
|
|
}
|
|
else if (rgui->flags & RGUI_FLAG_IS_PLAYLISTS_TAB)
|
|
{
|
|
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|
|
|| remember_selection == MENU_REMEMBER_SELECTION_PLAYLISTS)
|
|
menu_st->selection_ptr = rgui->playlist_selection_ptr;
|
|
}
|
|
else if (string_is_equal(label, MENU_ENUM_LABEL_SETTINGS_STR))
|
|
{
|
|
if ( remember_selection == MENU_REMEMBER_SELECTION_ALWAYS
|
|
|| remember_selection == MENU_REMEMBER_SELECTION_MAIN)
|
|
menu_st->selection_ptr = rgui->settings_selection_ptr;
|
|
}
|
|
|
|
/* a selection remembered from a longer list lands on its last entry */
|
|
{
|
|
menu_list_t *menu_list = menu_st->entries.list;
|
|
if (menu_list)
|
|
menu_st->selection_ptr = menu_entries_restorable_selection(
|
|
MENU_LIST_GET_SELECTION(menu_list, 0),
|
|
menu_st->selection_ptr);
|
|
}
|
|
|
|
rgui_navigation_set(data, true);
|
|
|
|
/* Determine whether to show entry index */
|
|
rgui->entry_index_str[0] = '\0';
|
|
if ( settings->bools.playlist_show_entry_idx
|
|
&& ((rgui->flags & RGUI_FLAG_IS_PLAYLIST) || (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)))
|
|
{
|
|
menu_list_t *menu_list = menu_st->entries.list;
|
|
size_t entry_idx_selection = menu_st->selection_ptr + 1;
|
|
size_t list_size = MENU_LIST_GET_SELECTION(menu_list, 0)->size;
|
|
unsigned entry_idx_offset = 0;
|
|
bool show_entry_idx = true;
|
|
|
|
if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
{
|
|
if (string_is_equal(path, MENU_ENUM_LABEL_GOTO_EXPLORE_STR))
|
|
show_entry_idx = false;
|
|
else
|
|
{
|
|
/* Skip header items (Search Name + Add Additional Filter + Save as View + Delete this View) */
|
|
menu_entry_t entry;
|
|
MENU_ENTRY_INITIALIZE(entry);
|
|
menu_entry_get(&entry, 0, 0, NULL, true);
|
|
|
|
if (entry.type == MENU_SETTINGS_LAST + 1 || entry.type == FILE_TYPE_PLAIN)
|
|
entry_idx_offset = 1;
|
|
else if (entry.type == FILE_TYPE_RDB)
|
|
entry_idx_offset = 2;
|
|
}
|
|
|
|
if (entry_idx_selection > entry_idx_offset && entry_idx_offset)
|
|
entry_idx_selection -= entry_idx_offset;
|
|
else
|
|
show_entry_idx = false;
|
|
|
|
if (list_size >= entry_idx_offset)
|
|
list_size -= entry_idx_offset;
|
|
}
|
|
|
|
rgui->entry_index_offset = entry_idx_offset;
|
|
|
|
if (show_entry_idx)
|
|
snprintf(rgui->entry_index_str, sizeof(rgui->entry_index_str),
|
|
"%lu/%lu", (unsigned long)entry_idx_selection,
|
|
(unsigned long)list_size);
|
|
}
|
|
|
|
/* If aspect ratio lock is enabled, must restore
|
|
* content video settings when accessing the video
|
|
* scaling settings menu... */
|
|
if (aspect_ratio_lock != RGUI_ASPECT_RATIO_LOCK_NONE)
|
|
{
|
|
#if defined(GEKKO)
|
|
/* On the Wii, have to restore content video settings
|
|
* at the top level video menu, otherwise changing
|
|
* resolutions is cumbersome (if menu aspect ratio
|
|
* is locked while this occurs, menu dimensions
|
|
* go out of sync...) */
|
|
if (string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_VIDEO_SETTINGS_LIST_STR))
|
|
#else
|
|
if (string_is_equal(label, MENU_ENUM_LABEL_DEFERRED_VIDEO_SCALING_SETTINGS_LIST_STR))
|
|
#endif
|
|
{
|
|
/* Make sure that any changes made while accessing
|
|
* the video settings menu are preserved */
|
|
rgui_video_settings_t current_video_settings = {{0}};
|
|
rgui_get_video_config(¤t_video_settings, settings, settings->uints.video_aspect_ratio_idx);
|
|
if (rgui_is_video_config_equal(¤t_video_settings, &rgui->menu_video_settings))
|
|
{
|
|
rgui_set_video_config_now(rgui, &rgui->content_video_settings);
|
|
/* Menu viewport has been overridden - must ignore
|
|
* resize events until the menu is next toggled off */
|
|
rgui->flags |= RGUI_FLAG_IGNORE_RESIZE_EVENTS;
|
|
#if !defined(GEKKO)
|
|
/* Changing the video config may alter the list
|
|
* of entries that should be displayed in the
|
|
* video scaling menu. The current menu layout
|
|
* was generated using the previous video config;
|
|
* we therefore have to force a menu refresh */
|
|
rgui->flags |= RGUI_FLAG_FORCE_MENU_REFRESH;
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static int rgui_environ(
|
|
enum menu_environ_cb type,
|
|
void *data,
|
|
void *userdata)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)userdata;
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
|
|
if (!rgui)
|
|
return -1;
|
|
|
|
switch (type)
|
|
{
|
|
case MENU_ENVIRON_ENABLE_MOUSE_CURSOR:
|
|
rgui->flags |= RGUI_FLAG_SHOW_MOUSE;
|
|
p_disp->flags |= GFX_DISP_FLAG_FB_DIRTY;
|
|
break;
|
|
case MENU_ENVIRON_DISABLE_MOUSE_CURSOR:
|
|
rgui->flags &= ~RGUI_FLAG_SHOW_MOUSE;
|
|
p_disp->flags &= ~GFX_DISP_FLAG_FB_DIRTY;
|
|
break;
|
|
case MENU_ENVIRON_ENABLE_SCREENSAVER:
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW
|
|
| RGUI_FLAG_SHOW_SCREENSAVER;
|
|
break;
|
|
case MENU_ENVIRON_DISABLE_SCREENSAVER:
|
|
rgui->flags &= ~RGUI_FLAG_SHOW_SCREENSAVER;
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
break;
|
|
default:
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Forward declaration */
|
|
static int rgui_menu_entry_action(
|
|
void *userdata, menu_entry_t *entry,
|
|
size_t i, enum menu_action action);
|
|
|
|
static int rgui_pointer_up(
|
|
void *data,
|
|
unsigned x, unsigned y, unsigned ptr,
|
|
enum menu_input_pointer_gesture gesture,
|
|
menu_file_list_cbs_t *cbs,
|
|
menu_entry_t *entry,
|
|
unsigned action)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
menu_list_t *menu_list = menu_st->entries.list;
|
|
size_t selection = menu_st->selection_ptr;
|
|
size_t end = menu_list ? MENU_LIST_GET_SELECTION(menu_list, 0)->size : 0;
|
|
|
|
if (!rgui)
|
|
return -1;
|
|
|
|
if ((rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& menu_media_controls_release(&rgui->media, x, y, menu_driver_get_current_time()))
|
|
{
|
|
menu_st->input_state.pointer.y_accel = 0.0f;
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
return 0;
|
|
}
|
|
|
|
switch (gesture)
|
|
{
|
|
case MENU_INPUT_GESTURE_TAP:
|
|
case MENU_INPUT_GESTURE_SHORT_PRESS:
|
|
{
|
|
bool show_fs_thumbnail =
|
|
(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& (rgui->flags & RGUI_FLAG_ENTRY_HAS_THUMBNAIL)
|
|
&& (rgui->fs_thumbnail.is_valid || (rgui->thumbnail_queue_size > 0));
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
unsigned header_height = p_disp->header_height;
|
|
|
|
/* Normal pointer input */
|
|
if (show_fs_thumbnail)
|
|
{
|
|
/* If we are currently showing a fullscreen thumbnail:
|
|
* - Must provide a mechanism for toggling it off
|
|
* - A normal mouse press should just select the current
|
|
* entry (for which the thumbnail is being shown) */
|
|
if (y >= header_height)
|
|
return rgui_menu_entry_action(rgui, entry, selection, MENU_ACTION_SELECT);
|
|
rgui_toggle_fs_thumbnail(rgui, config_get_ptr()->bools.menu_rgui_inline_thumbnails);
|
|
}
|
|
else
|
|
{
|
|
if (y < header_height)
|
|
return rgui_menu_entry_action(rgui, entry, selection, MENU_ACTION_CANCEL);
|
|
else if (ptr <= (end - 1))
|
|
{
|
|
/* Perform 'select' on the pointed item */
|
|
menu_st->selection_ptr = ptr;
|
|
rgui_navigation_set(rgui, false);
|
|
return rgui_menu_entry_action(rgui, entry, ptr, MENU_ACTION_SELECT);
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case MENU_INPUT_GESTURE_LONG_PRESS:
|
|
/* 'Reset to default' action */
|
|
if ((ptr <= (end - 1)) &&
|
|
(ptr == selection))
|
|
return rgui_menu_entry_action(rgui, entry, selection, MENU_ACTION_START);
|
|
break;
|
|
default:
|
|
/* Ignore input */
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void rgui_media_gpu_draw(rgui_t *rgui, video_frame_info_t *video_info)
|
|
{
|
|
gfx_thumbnail_t thumbnail;
|
|
video_driver_state_t *video_st = video_state_get_ptr();
|
|
rgui_media_gpu_view_t *view = &rgui->media_gpu_view;
|
|
gfx_media_rect_t *rect = &view->rect;
|
|
unsigned dims = video_info->dims;
|
|
struct video_viewport vp;
|
|
float sx, sy;
|
|
int startup_token = menu_driver_media_startup_token();
|
|
rgui_media_gpu_consume(rgui);
|
|
if (startup_token && view->visible && view->texture
|
|
&& view->alpha >= 0.9999f
|
|
&& (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
menu_driver_media_startup_ready(startup_token);
|
|
if (!view->visible || rect->w <= 0 || rect->h <= 0
|
|
|| !VIDEO_SCALE_W(view->source_dims) || !VIDEO_SCALE_H(view->source_dims)) return;
|
|
vp.pos = 0;
|
|
vp.dims = 0;
|
|
vp.full_dims = 0;
|
|
if (!video_driver_get_viewport_info(&vp)
|
|
|| !VIDEO_SCALE_W(vp.dims) || !VIDEO_SCALE_H(vp.dims))
|
|
vp.dims = dims;
|
|
if (video_st->current_video && video_st->current_video->set_viewport)
|
|
video_st->current_video->set_viewport(
|
|
video_st->data, dims, true, false);
|
|
sx = (float)VIDEO_SCALE_W(vp.dims) / VIDEO_SCALE_W(view->source_dims);
|
|
sy = (float)VIDEO_SCALE_H(vp.dims) / VIDEO_SCALE_H(view->source_dims);
|
|
gfx_thumbnail_init_blank(&thumbnail);
|
|
thumbnail.texture = view->texture;
|
|
thumbnail.dims = view->texture_dims;
|
|
thumbnail.alpha = view->alpha;
|
|
thumbnail.flags = view->flags;
|
|
retro_atomic_store_release_int(&thumbnail.status, GFX_THUMBNAIL_STATUS_AVAILABLE);
|
|
gfx_thumbnail_draw(video_info->userdata, dims, &thumbnail,
|
|
VIDEO_POS_X(vp.pos) + rect->x * sx,
|
|
VIDEO_POS_Y(vp.pos) + rect->y * sy,
|
|
VIDEO_SCALE_PACK((unsigned)(rect->w * sx), (unsigned)(rect->h * sy)),
|
|
GFX_THUMBNAIL_ALIGN_CENTRE, 1.0f, 1.0f, NULL);
|
|
if (video_st->current_video && video_st->current_video->set_viewport)
|
|
video_st->current_video->set_viewport(
|
|
video_st->data, dims, false, true);
|
|
}
|
|
|
|
static void rgui_frame(void *data, video_frame_info_t *video_info)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
bool bg_filler_thickness_enable = ((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_BACKGROUND_FILLER_THICKNESS_ENABLE) ? true : false);
|
|
bool border_filler_thickness_enable = ((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_BORDER_FILLER_THICKNESS_ENABLE) ? true : false);
|
|
#if defined(DINGUX)
|
|
unsigned aspect_ratio = RGUI_DINGUX_ASPECT_RATIO;
|
|
unsigned aspect_ratio_lock = RGUI_ASPECT_RATIO_LOCK_NONE;
|
|
#else
|
|
unsigned aspect_ratio = video_info->menu.rgui_aspect_ratio;
|
|
unsigned aspect_ratio_lock = video_info->menu.rgui_aspect_ratio_lock;
|
|
#endif
|
|
bool border_filler_enable = ((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_BORDER_FILLER_ENABLE) ? true : false);
|
|
unsigned video_width = VIDEO_SCALE_W(video_info->dims);
|
|
unsigned video_height = VIDEO_SCALE_H(video_info->dims);
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
|
|
if (bg_filler_thickness_enable != ((rgui->flags & RGUI_FLAG_BG_THICKNESS) > 0))
|
|
{
|
|
rgui->flags |= RGUI_FLAG_BG_MODIFIED
|
|
| RGUI_FLAG_FORCE_REDRAW;
|
|
if (bg_filler_thickness_enable)
|
|
rgui->flags |= RGUI_FLAG_BG_THICKNESS;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_BG_THICKNESS;
|
|
}
|
|
|
|
if (border_filler_thickness_enable != ((rgui->flags & RGUI_FLAG_BORDER_THICKNESS) > 0))
|
|
{
|
|
rgui->flags |= RGUI_FLAG_BG_MODIFIED
|
|
| RGUI_FLAG_FORCE_REDRAW;
|
|
if (border_filler_thickness_enable)
|
|
rgui->flags |= RGUI_FLAG_BORDER_THICKNESS;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_BORDER_THICKNESS;
|
|
}
|
|
|
|
if (border_filler_enable != ((rgui->flags & RGUI_FLAG_BORDER_ENABLE) > 0))
|
|
{
|
|
rgui->flags |= RGUI_FLAG_BG_MODIFIED
|
|
| RGUI_FLAG_FORCE_REDRAW;
|
|
if (border_filler_enable)
|
|
rgui->flags |= RGUI_FLAG_BORDER_ENABLE;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_BORDER_ENABLE;
|
|
}
|
|
|
|
if (((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_SHADOWS) ? true : false) != ((rgui->flags & RGUI_FLAG_SHADOW_ENABLE) > 0))
|
|
{
|
|
rgui_set_blit_functions(
|
|
rgui->language,
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_SHADOWS) ? true : false),
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_EXTENDED_ASCII) ? true : false));
|
|
|
|
rgui->flags |= RGUI_FLAG_BG_MODIFIED
|
|
| RGUI_FLAG_FORCE_REDRAW;
|
|
if (((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_SHADOWS) ? true : false))
|
|
rgui->flags |= RGUI_FLAG_SHADOW_ENABLE;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_SHADOW_ENABLE;
|
|
}
|
|
|
|
if (video_info->menu.rgui_particle_effect != rgui->particle_effect)
|
|
{
|
|
rgui->particle_effect = video_info->menu.rgui_particle_effect;
|
|
|
|
if (rgui->particle_effect != RGUI_PARTICLE_EFFECT_NONE)
|
|
rgui_init_particle_effect(rgui, p_disp);
|
|
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
if ( (rgui->particle_effect != RGUI_PARTICLE_EFFECT_NONE)
|
|
&& ( (!(rgui->flags & RGUI_FLAG_SHOW_SCREENSAVER))
|
|
|| (((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_PARTICLE_EFFECT_SCREENSAVER) ? true : false))))
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
|
|
if (((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_EXTENDED_ASCII) ? true : false) != ((rgui->flags & RGUI_FLAG_EXTENDED_ASCII_ENABLE) > 0))
|
|
{
|
|
rgui_set_blit_functions(
|
|
rgui->language,
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_SHADOWS) ? true : false),
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_EXTENDED_ASCII) ? true : false));
|
|
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
if (((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_EXTENDED_ASCII) ? true : false))
|
|
rgui->flags |= RGUI_FLAG_EXTENDED_ASCII_ENABLE;
|
|
else
|
|
rgui->flags &= ~RGUI_FLAG_EXTENDED_ASCII_ENABLE;
|
|
}
|
|
|
|
if ( (video_info->menu.rgui_color_theme != rgui->color_theme)
|
|
|| ( (rgui->flags & RGUI_FLAG_TRANSPARENCY_SUPPORTED)
|
|
&& (((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_TRANSPARENCY) ? true : false) !=
|
|
((rgui->flags & RGUI_FLAG_TRANSPARENCY_ENABLE) > 0))))
|
|
{
|
|
if (video_info->menu.rgui_color_theme == RGUI_THEME_DYNAMIC)
|
|
rgui_update_dynamic_theme_path(rgui,
|
|
video_info->menu.dynamic_wallpapers_dir);
|
|
|
|
rgui_prepare_colors(rgui,
|
|
video_info->menu.rgui_color_theme,
|
|
video_info->menu.rgui_theme_preset,
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_TRANSPARENCY) ? true : false),
|
|
video_info->menu.rgui_aspect_ratio
|
|
);
|
|
}
|
|
else if (video_info->menu.rgui_color_theme == RGUI_THEME_CUSTOM)
|
|
{
|
|
if (!string_is_equal(video_info->menu.rgui_theme_preset,
|
|
rgui->theme_preset_path))
|
|
rgui_prepare_colors(rgui,
|
|
video_info->menu.rgui_color_theme,
|
|
video_info->menu.rgui_theme_preset,
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_TRANSPARENCY) ? true : false),
|
|
video_info->menu.rgui_aspect_ratio
|
|
);
|
|
}
|
|
else if (video_info->menu.rgui_color_theme == RGUI_THEME_DYNAMIC)
|
|
{
|
|
if (!string_is_equal(rgui->last_theme_dynamic_path,
|
|
rgui->theme_dynamic_path))
|
|
rgui_prepare_colors(rgui,
|
|
video_info->menu.rgui_color_theme,
|
|
video_info->menu.rgui_theme_preset,
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_RGUI_TRANSPARENCY) ? true : false),
|
|
video_info->menu.rgui_aspect_ratio
|
|
);
|
|
}
|
|
|
|
/* Single-click playlist button hold delay */
|
|
if ( rgui->flags & RGUI_FLAG_DRAW_ENTRY_SKIP
|
|
&& rgui->draw_entry_hold_until
|
|
&& menu_driver_get_current_time() >= rgui->draw_entry_hold_until)
|
|
{
|
|
rgui->draw_entry_hold_until = 0;
|
|
rgui->flags &= ~RGUI_FLAG_DRAW_ENTRY_SKIP;
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
|
|
/* Note: both rgui_set_aspect_ratio() and the video-config path
|
|
* normally call command_event(CMD_EVENT_VIDEO_SET_ASPECT_RATIO, NULL)
|
|
* ## THIS CANNOT BE DONE INSIDE rgui_frame() IF THREADED VIDEO IS ENABLED ##
|
|
* Attempting to do so creates a deadlock, and causes RetroArch to hang.
|
|
* We therefore have to set the 'delay_update' argument, which causes
|
|
* command_event(CMD_EVENT_VIDEO_SET_ASPECT_RATIO, NULL) to be called at
|
|
* the next instance of rgui_render() */
|
|
|
|
/* > Check for changes in aspect ratio */
|
|
if (aspect_ratio != rgui->menu_aspect_ratio)
|
|
{
|
|
/* If user changes aspect ratio directly after opening
|
|
* the video scaling settings menu, then all bets are off
|
|
* - we can no longer guarantee that changes to aspect ratio
|
|
* and custom viewport settings will be preserved. So it
|
|
* no longer makes sense to ignore resize events */
|
|
rgui->flags &= ~RGUI_FLAG_IGNORE_RESIZE_EVENTS;
|
|
|
|
rgui_set_aspect_ratio(rgui, p_disp, true,
|
|
video_info->menu.rgui_aspect_ratio,
|
|
video_info->menu.rgui_aspect_ratio_lock);
|
|
}
|
|
|
|
/* > Check for changes in aspect ratio lock setting */
|
|
if ( (aspect_ratio_lock != rgui->menu_aspect_ratio_lock)
|
|
|| (rgui->flags & RGUI_FLAG_RESTORE_ASPECT_LOCK))
|
|
{
|
|
rgui->menu_aspect_ratio_lock = aspect_ratio_lock;
|
|
|
|
if (aspect_ratio_lock == RGUI_ASPECT_RATIO_LOCK_NONE)
|
|
rgui_stage_video_config(rgui, &rgui->content_video_settings);
|
|
else
|
|
{
|
|
/* As with changes in aspect ratio, if we reach this point
|
|
* after visiting the video scaling settings menu, resize
|
|
* events should be monitored again */
|
|
rgui->flags &= ~RGUI_FLAG_IGNORE_RESIZE_EVENTS;
|
|
rgui_update_menu_viewport(rgui, p_disp, video_info->menu.rgui_aspect_ratio_lock);
|
|
rgui_stage_video_config(rgui, &rgui->menu_video_settings);
|
|
}
|
|
|
|
/* Clear any pending 'restore aspect lock' flags */
|
|
rgui->flags &= ~RGUI_FLAG_RESTORE_ASPECT_LOCK;
|
|
}
|
|
|
|
/* > Check for changes in window (display) dimensions */
|
|
if ( (VIDEO_SCALE_W(rgui->window_dims) != video_width)
|
|
|| (VIDEO_SCALE_H(rgui->window_dims) != video_height))
|
|
{
|
|
#if !defined(GEKKO) && !defined(DINGUX)
|
|
/* If window width or height are less than the
|
|
* RGUI default size of (320-426)x240, must enable
|
|
* dynamic menu 'downscaling'.
|
|
* All texture buffers must be regenerated in this
|
|
* case - easiest way is to just call
|
|
* rgui_set_aspect_ratio()
|
|
* > rgui_set_aspect_ratio() must also be called
|
|
* when transitioning from a 'downscaled' size
|
|
* back the default */
|
|
unsigned default_fb_width;
|
|
|
|
switch (rgui->menu_aspect_ratio)
|
|
{
|
|
case RGUI_ASPECT_RATIO_16_9:
|
|
case RGUI_ASPECT_RATIO_16_9_CENTRE:
|
|
default_fb_width = 426;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_16_10:
|
|
case RGUI_ASPECT_RATIO_16_10_CENTRE:
|
|
default_fb_width = 384;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_21_9:
|
|
case RGUI_ASPECT_RATIO_21_9_CENTRE:
|
|
default_fb_width = RGUI_MAX_FB_WIDTH;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_3_2:
|
|
case RGUI_ASPECT_RATIO_3_2_CENTRE:
|
|
default_fb_width = 360;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_5_3:
|
|
case RGUI_ASPECT_RATIO_5_3_CENTRE:
|
|
default_fb_width = 400;
|
|
break;
|
|
case RGUI_ASPECT_RATIO_1_1:
|
|
default_fb_width = 240;
|
|
break;
|
|
default:
|
|
/* 4:3 */
|
|
default_fb_width = 320;
|
|
break;
|
|
}
|
|
|
|
if ( (video_width < default_fb_width)
|
|
|| (VIDEO_SCALE_W(rgui->window_dims) < default_fb_width)
|
|
|| (video_height < 240)
|
|
|| (VIDEO_SCALE_H(rgui->window_dims) < 240))
|
|
rgui_set_aspect_ratio(rgui, p_disp, true,
|
|
video_info->menu.rgui_aspect_ratio,
|
|
video_info->menu.rgui_aspect_ratio_lock);
|
|
#endif
|
|
|
|
/* If aspect ratio is locked, have to update viewport */
|
|
if ( (aspect_ratio_lock != RGUI_ASPECT_RATIO_LOCK_NONE)
|
|
&& (!(rgui->flags & RGUI_FLAG_IGNORE_RESIZE_EVENTS)))
|
|
{
|
|
rgui_update_menu_viewport(rgui, p_disp, video_info->menu.rgui_aspect_ratio_lock);
|
|
rgui_stage_video_config(rgui, &rgui->menu_video_settings);
|
|
}
|
|
|
|
rgui->window_dims = VIDEO_SCALE_PACK(video_width, video_height);
|
|
}
|
|
|
|
/* Handle pending thumbnail load operations */
|
|
if (rgui->flags & RGUI_FLAG_THUMBNAIL_LOAD_PENDING)
|
|
{
|
|
/* Check whether current 'load delay' duration has elapsed
|
|
* Note: Delay is increased when viewing fullscreen thumbnails,
|
|
* since the flicker when switching between playlist view and
|
|
* fullscreen thumbnail view is incredibly jarring...) */
|
|
if ((menu_driver_get_current_time() - rgui->thumbnail_load_trigger_time) >=
|
|
(video_info->menu.rgui_thumbnail_delay * 1000 * ((rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
? 1.5f
|
|
: 1.0f)))
|
|
rgui_load_current_thumbnails(rgui, menu_st,
|
|
((video_info->menu.flags & VIDEO_MENU_FLAG_NETWORK_ON_DEMAND_THUMBNAILS) ? true : false));
|
|
}
|
|
|
|
/* Read pointer input */
|
|
if ( ((video_info->menu.flags & VIDEO_MENU_FLAG_MOUSE_ENABLE) ? true : false)
|
|
|| ((video_info->menu.flags & VIDEO_MENU_FLAG_POINTER_ENABLE) ? true : false))
|
|
{
|
|
menu_input_get_pointer_state(&rgui->pointer);
|
|
|
|
/* Screen must be redrawn whenever pointer is active */
|
|
if ( (rgui->pointer.type != MENU_POINTER_DISABLED)
|
|
&& (rgui->pointer.flags & MENU_INP_PTR_FLG_ACTIVE))
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
else
|
|
rgui->pointer.type = MENU_POINTER_DISABLED;
|
|
rgui_media_gpu_draw(rgui, video_info);
|
|
}
|
|
|
|
static void rgui_toggle(void *userdata, bool menu_on)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)userdata;
|
|
settings_t *settings = config_get_ptr();
|
|
gfx_display_t *p_disp = disp_get_ptr();
|
|
#if defined(DINGUX)
|
|
unsigned aspect_ratio_lock = RGUI_ASPECT_RATIO_LOCK_NONE;
|
|
#else
|
|
unsigned aspect_ratio_lock = settings ? settings->uints.menu_rgui_aspect_ratio_lock : 0;
|
|
#endif
|
|
|
|
/* TODO/FIXME - when we close RetroArch, this function
|
|
* gets called and settings is NULL at this point.
|
|
* Maybe fundamentally change control flow so that on RetroArch
|
|
* exit, this doesn't get called. */
|
|
if (!rgui || !settings)
|
|
return;
|
|
|
|
/* Reset */
|
|
rgui->flags &= ~RGUI_FLAG_DRAW_ENTRY_SKIP;
|
|
|
|
/* Forget history playlist selection in order to
|
|
* focus back on the same launched entry. */
|
|
rgui->playlist_mainmenu_selection[0] = 0;
|
|
|
|
/* Have to reset this, otherwise savestate
|
|
* thumbnail won't update after selecting
|
|
* 'save state' option */
|
|
if (rgui->flags & RGUI_FLAG_IS_QUICK_MENU)
|
|
{
|
|
rgui_reset_savestate_thumbnail(rgui);
|
|
|
|
/* Prevent thumbnail flashing after toggling menu */
|
|
if (!menu_on)
|
|
rgui->mini_thumbnail_delay = 1;
|
|
}
|
|
|
|
if (menu_on)
|
|
{
|
|
if (aspect_ratio_lock != RGUI_ASPECT_RATIO_LOCK_NONE)
|
|
{
|
|
/* Cache content video settings */
|
|
rgui_get_video_config(&rgui->content_video_settings, settings, settings->uints.video_aspect_ratio_idx);
|
|
/* Update menu viewport */
|
|
rgui_update_menu_viewport(rgui, p_disp, settings->uints.menu_rgui_aspect_ratio_lock);
|
|
/* Apply menu video settings */
|
|
rgui_set_video_config_now(rgui, &rgui->menu_video_settings);
|
|
}
|
|
else if (rgui->menu_aspect_ratio == RGUI_ASPECT_RATIO_AUTO)
|
|
{
|
|
rgui_set_aspect_ratio(rgui, p_disp, false,
|
|
settings->uints.menu_rgui_aspect_ratio,
|
|
settings->uints.menu_rgui_aspect_ratio_lock);
|
|
rgui_flush_video_config(rgui);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (aspect_ratio_lock != RGUI_ASPECT_RATIO_LOCK_NONE)
|
|
{
|
|
/* Restore content video settings *if* user
|
|
* has not changed video settings since menu was
|
|
* last toggled on */
|
|
rgui_video_settings_t current_video_settings = {{0}};
|
|
rgui_get_video_config(¤t_video_settings, settings, settings->uints.video_aspect_ratio_idx);
|
|
|
|
if (rgui_is_video_config_equal(¤t_video_settings, &rgui->menu_video_settings))
|
|
rgui_set_video_config_now(rgui, &rgui->content_video_settings);
|
|
|
|
/* Any modified video scaling settings have now been
|
|
* registered, so it is again 'safe' to respond to window
|
|
* resize events */
|
|
rgui->flags &= ~RGUI_FLAG_IGNORE_RESIZE_EVENTS;
|
|
}
|
|
|
|
/* Upscaling buffer is only required while menu is on. Save
|
|
* memory by freeing it whenever we switch back to the current
|
|
* content */
|
|
if (rgui->upscale_buf.data)
|
|
{
|
|
free(rgui->upscale_buf.data);
|
|
rgui->upscale_buf.data = NULL;
|
|
}
|
|
free(rgui->upscale_line);
|
|
rgui->upscale_line = NULL;
|
|
rgui->upscale_line_width = 0;
|
|
rgui->upscale_map_src_width = 0;
|
|
rgui->upscale_map_width = 0;
|
|
}
|
|
}
|
|
|
|
static void rgui_context_destroy(void *data)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
if (rgui) rgui_media_close(rgui, true);
|
|
}
|
|
|
|
static void rgui_context_reset(void *data, bool is_threaded)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)data;
|
|
|
|
if (!rgui)
|
|
return;
|
|
|
|
menu_media_controls_context_reset(&rgui->media, true);
|
|
if (!disp_get_ptr()->dispctx)
|
|
gfx_display_init_first_driver(disp_get_ptr(), is_threaded);
|
|
video_driver_monitor_reset();
|
|
/* A new video driver holds no menu texture until the next upload */
|
|
disp_get_ptr()->flags |= GFX_DISP_FLAG_FB_DIRTY;
|
|
}
|
|
|
|
static void rgui_thumbnail_cycle_dupe(rgui_t *rgui)
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
if ( settings->uints.gfx_thumbnails == settings->uints.menu_left_thumbnails
|
|
&& settings->uints.gfx_thumbnails)
|
|
{
|
|
unsigned tmp = (rgui->gfx_thumbnails_prev > 0)
|
|
? (unsigned)rgui->gfx_thumbnails_prev
|
|
: settings->uints.gfx_thumbnails + 1;
|
|
|
|
if (tmp > 3)
|
|
tmp = 1;
|
|
|
|
configuration_set_uint(settings,
|
|
settings->uints.gfx_thumbnails, tmp);
|
|
}
|
|
}
|
|
|
|
static enum menu_action rgui_parse_menu_entry_action(
|
|
rgui_t *rgui,
|
|
menu_entry_t *entry,
|
|
enum menu_action action)
|
|
{
|
|
struct menu_state *menu_st = menu_state_get_ptr();
|
|
enum menu_action new_action = action;
|
|
|
|
if (!(rgui->flags & (RGUI_FLAG_IS_PLAYLIST | RGUI_FLAG_IS_EXPLORE_LIST
|
|
| RGUI_FLAG_IS_QUICK_MENU)) && menu_st->entries.list)
|
|
{
|
|
file_list_t *list = MENU_LIST_GET_SELECTION(menu_st->entries.list, 0);
|
|
if (list && menu_st->selection_ptr < list->size
|
|
&& (list->list[menu_st->selection_ptr].type == FILE_TYPE_IMAGE
|
|
|| list->list[menu_st->selection_ptr].type == FILE_TYPE_IMAGEVIEWER))
|
|
{
|
|
bool fullscreen = (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL) != 0;
|
|
/* OK views only viewer content; an image pick keeps its action */
|
|
bool viewable = list->list[menu_st->selection_ptr].type
|
|
== FILE_TYPE_IMAGEVIEWER;
|
|
if (action == MENU_ACTION_START || action == MENU_ACTION_SELECT
|
|
|| (action == MENU_ACTION_OK && !fullscreen && viewable)
|
|
|| (action == MENU_ACTION_CANCEL && fullscreen))
|
|
{
|
|
rgui_toggle_fs_thumbnail(rgui, config_get_ptr()->bools.menu_rgui_inline_thumbnails);
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
return MENU_ACTION_NOOP;
|
|
}
|
|
if (fullscreen && action == MENU_ACTION_OK && viewable)
|
|
return MENU_ACTION_NOOP;
|
|
}
|
|
}
|
|
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
&& action == MENU_ACTION_OK
|
|
&& menu_media_selected_in_history(menu_st))
|
|
{
|
|
if (!(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
{
|
|
rgui_toggle_fs_thumbnail(rgui, config_get_ptr()->bools.menu_rgui_inline_thumbnails);
|
|
rgui_scan_selected_entry_thumbnail(rgui, true);
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
}
|
|
return MENU_ACTION_NOOP;
|
|
}
|
|
|
|
if (*rgui->media_requested_path)
|
|
{
|
|
bool fullscreen = (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL) != 0;
|
|
if ((fullscreen && (action == MENU_ACTION_CANCEL || action == MENU_ACTION_SELECT))
|
|
|| (!fullscreen && (action == MENU_ACTION_OK || action == MENU_ACTION_START
|
|
|| action == MENU_ACTION_SELECT)))
|
|
{
|
|
rgui_toggle_fs_thumbnail(rgui, config_get_ptr()->bools.menu_rgui_inline_thumbnails);
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
return MENU_ACTION_NOOP;
|
|
}
|
|
}
|
|
if ((rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& menu_media_controls_action(&rgui->media, action, menu_driver_get_current_time()))
|
|
{
|
|
rgui->flags |= RGUI_FLAG_FORCE_REDRAW;
|
|
return MENU_ACTION_NOOP;
|
|
}
|
|
|
|
/* Scan user inputs */
|
|
switch (action)
|
|
{
|
|
case MENU_ACTION_OK:
|
|
/* If aspect ratio lock is enabled, must restore
|
|
* content video settings when saving configuration
|
|
* files/overrides - otherwise RGUI's custom viewport
|
|
* parameters will be included in the generated output */
|
|
if ( (rgui->menu_aspect_ratio_lock != RGUI_ASPECT_RATIO_LOCK_NONE)
|
|
&& ( (entry->enum_idx == MENU_ENUM_LABEL_SAVE_CURRENT_CONFIG_OVERRIDE_CORE)
|
|
|| (entry->enum_idx == MENU_ENUM_LABEL_SAVE_CURRENT_CONFIG_OVERRIDE_CONTENT_DIR)
|
|
|| (entry->enum_idx == MENU_ENUM_LABEL_SAVE_CURRENT_CONFIG_OVERRIDE_GAME)
|
|
|| (entry->enum_idx == MENU_ENUM_LABEL_SAVE_CURRENT_CONFIG)
|
|
|| (entry->enum_idx == MENU_ENUM_LABEL_SAVE_NEW_CONFIG)))
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
rgui_video_settings_t current_video_settings = {{0}};
|
|
rgui_get_video_config(¤t_video_settings, settings, settings->uints.video_aspect_ratio_idx);
|
|
if (rgui_is_video_config_equal(¤t_video_settings,
|
|
&rgui->menu_video_settings))
|
|
{
|
|
/* This is identical to the temporary 'aspect
|
|
* ratio unlock' that is applied when accessing
|
|
* the video settings menu. There is, however,
|
|
* no need in this case to ignore resize events
|
|
* until the menu is next toggled off; this is a
|
|
* one-shot 'fix' that should only be active
|
|
* during the config save operation */
|
|
rgui_set_video_config_now(rgui, &rgui->content_video_settings);
|
|
/* Schedule a restoration of the aspect ratio
|
|
* lock on the next frame */
|
|
rgui->flags |= RGUI_FLAG_RESTORE_ASPECT_LOCK;
|
|
}
|
|
}
|
|
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
{
|
|
rgui_thumbnail_cycle_dupe(rgui);
|
|
rgui_toggle_fs_thumbnail(rgui, config_get_ptr()->bools.menu_rgui_inline_thumbnails);
|
|
|
|
if ( (!(rgui->flags & RGUI_FLAG_IS_STATE_SLOT))
|
|
&& (!(rgui->flags & RGUI_FLAG_IS_PLAYLIST))
|
|
&& (!(rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)))
|
|
new_action = MENU_ACTION_NOOP;
|
|
}
|
|
|
|
/* Make transition smoother for single-click playlist launching */
|
|
if ( config_get_ptr()->bools.input_menu_singleclick_playlists
|
|
&& ( rgui->flags & RGUI_FLAG_IS_PLAYLIST
|
|
|| rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST))
|
|
{
|
|
if (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
{
|
|
#if defined(HAVE_LIBRETRODB)
|
|
menu_entry_t entry;
|
|
MENU_ENTRY_INITIALIZE(entry);
|
|
menu_entry_get(&entry, 0, menu_st->selection_ptr, NULL, true);
|
|
if ( entry.type == FILE_TYPE_RDB
|
|
|| entry.type == FILE_TYPE_PLAIN
|
|
|| !menu_explore_is_content_list())
|
|
break;
|
|
#endif
|
|
}
|
|
rgui->flags |= RGUI_FLAG_DRAW_ENTRY_SKIP;
|
|
rgui->draw_entry_hold_until = menu_driver_get_current_time()
|
|
+ MENU_DRAW_ENTRY_DELAY;
|
|
}
|
|
break;
|
|
case MENU_ACTION_CANCEL:
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
{
|
|
if ( ((rgui->flags & RGUI_FLAG_IS_STATE_SLOT) || (rgui->flags & RGUI_FLAG_IS_QUICK_MENU))
|
|
&& *rgui->savestate_thumbnail_file_path)
|
|
{
|
|
rgui_toggle_fs_thumbnail(rgui, true);
|
|
}
|
|
else
|
|
{
|
|
rgui_thumbnail_cycle_dupe(rgui);
|
|
rgui_toggle_fs_thumbnail(rgui, config_get_ptr()->bools.menu_rgui_inline_thumbnails);
|
|
}
|
|
new_action = MENU_ACTION_NOOP;
|
|
break;
|
|
}
|
|
|
|
if (string_is_equal(rgui->menu_title, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_MAIN_MENU)))
|
|
{
|
|
/* Jump to first item on Main Menu */
|
|
menu_st->selection_ptr = 0;
|
|
new_action = MENU_ACTION_NOOP;
|
|
}
|
|
break;
|
|
case MENU_ACTION_START:
|
|
/* Playlist thumbnail fullscreen toggle */
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST)
|
|
|| ((rgui->flags & RGUI_FLAG_IS_QUICK_MENU) && !menu_is_running_quick_menu()))
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
new_action = MENU_ACTION_NOOP;
|
|
|
|
if ( (!(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
&& rgui->gfx_thumbnails_prev < 0
|
|
&& settings->uints.gfx_thumbnails)
|
|
rgui->gfx_thumbnails_prev = settings->uints.gfx_thumbnails;
|
|
|
|
/* Avoid showing the same thumbnail after returning from fullscreen mode after cycling images */
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
rgui_thumbnail_cycle_dupe(rgui);
|
|
|
|
rgui_toggle_fs_thumbnail(rgui, config_get_ptr()->bools.menu_rgui_inline_thumbnails);
|
|
|
|
if (!(rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL))
|
|
rgui->gfx_thumbnails_prev = -1;
|
|
}
|
|
break;
|
|
case MENU_ACTION_SCAN:
|
|
if (rgui->flags & RGUI_FLAG_IS_PLAYLISTS_TAB)
|
|
{
|
|
size_t selection = menu_st->selection_ptr;
|
|
size_t new_selection = menu_playlists_tab_random_selection(selection);
|
|
|
|
if (new_selection != selection)
|
|
{
|
|
menu_st->selection_ptr = new_selection;
|
|
if (menu_st->driver_ctx->navigation_set)
|
|
menu_st->driver_ctx->navigation_set(menu_st->userdata, true);
|
|
}
|
|
|
|
new_action = MENU_ACTION_NOOP;
|
|
|
|
#ifdef HAVE_AUDIOMIXER
|
|
if (new_selection != selection)
|
|
audio_driver_mixer_play_scroll_sound(true);
|
|
#endif
|
|
break;
|
|
}
|
|
else if ((rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST))
|
|
{
|
|
size_t selection = menu_st->selection_ptr;
|
|
size_t new_selection = menu_playlist_random_selection(selection, rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST);
|
|
|
|
if (new_selection != selection)
|
|
{
|
|
menu_st->selection_ptr = new_selection;
|
|
if (menu_st->driver_ctx->navigation_set)
|
|
menu_st->driver_ctx->navigation_set(menu_st->userdata, true);
|
|
}
|
|
|
|
new_action = MENU_ACTION_NOOP;
|
|
|
|
#ifdef HAVE_AUDIOMIXER
|
|
if (new_selection != selection)
|
|
audio_driver_mixer_play_scroll_sound(true);
|
|
#endif
|
|
break;
|
|
}
|
|
|
|
/* Save state slot fullscreen toggle */
|
|
if ( ((rgui->flags & RGUI_FLAG_IS_STATE_SLOT) || (rgui->flags & RGUI_FLAG_IS_QUICK_MENU))
|
|
&& *rgui->savestate_thumbnail_file_path)
|
|
{
|
|
rgui_toggle_fs_thumbnail(rgui, true);
|
|
new_action = MENU_ACTION_NOOP;
|
|
}
|
|
break;
|
|
case MENU_ACTION_SEARCH:
|
|
/* Playlist thumbnail cycle */
|
|
if ( (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
|| ((rgui->flags & RGUI_FLAG_IS_QUICK_MENU) && !menu_is_running_quick_menu()))
|
|
{
|
|
rgui_action_switch_thumbnail(rgui);
|
|
new_action = MENU_ACTION_NOOP;
|
|
}
|
|
break;
|
|
case MENU_ACTION_CYCLE_THUMBNAIL_PRIMARY:
|
|
case MENU_ACTION_CYCLE_THUMBNAIL_SECONDARY:
|
|
/* Use rgui internal cycle method always in fullscreen mode */
|
|
if (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
{
|
|
rgui_action_switch_thumbnail(rgui);
|
|
new_action = MENU_ACTION_NOOP;
|
|
}
|
|
break;
|
|
case MENU_ACTION_INFO:
|
|
if ( (rgui->flags & RGUI_FLAG_IS_PLAYLIST)
|
|
|| (rgui->flags & RGUI_FLAG_IS_EXPLORE_LIST))
|
|
{
|
|
settings_t *settings = config_get_ptr();
|
|
configuration_set_uint(settings,
|
|
settings->bools.menu_rgui_inline_thumbnails,
|
|
!settings->bools.menu_rgui_inline_thumbnails);
|
|
|
|
rgui_refresh_thumbnail_image(rgui, 0);
|
|
new_action = MENU_ACTION_NOOP;
|
|
}
|
|
break;
|
|
case MENU_ACTION_UP:
|
|
case MENU_ACTION_DOWN:
|
|
case MENU_ACTION_SCROLL_UP:
|
|
case MENU_ACTION_SCROLL_DOWN:
|
|
if ( (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& (rgui->flags & RGUI_FLAG_IS_QUICK_MENU))
|
|
new_action = MENU_ACTION_NOOP;
|
|
break;
|
|
case MENU_ACTION_LEFT:
|
|
case MENU_ACTION_RIGHT:
|
|
if ( (rgui->flags & RGUI_FLAG_SHOW_FULLSCREEN_THUMBNAIL)
|
|
&& ((rgui->flags & RGUI_FLAG_IS_QUICK_MENU) && !menu_is_running_quick_menu()))
|
|
new_action = MENU_ACTION_NOOP;
|
|
break;
|
|
default:
|
|
/* In all other cases, pass through input
|
|
* menu action without intervention */
|
|
break;
|
|
}
|
|
|
|
switch (new_action)
|
|
{
|
|
case MENU_ACTION_UP:
|
|
case MENU_ACTION_DOWN:
|
|
case MENU_ACTION_LEFT:
|
|
case MENU_ACTION_RIGHT:
|
|
case MENU_ACTION_CANCEL:
|
|
if ( config_get_ptr()->bools.input_menu_singleclick_playlists
|
|
&& rgui->flags & RGUI_FLAG_DRAW_ENTRY_SKIP)
|
|
{
|
|
rgui->flags &= ~RGUI_FLAG_DRAW_ENTRY_SKIP;
|
|
new_action = MENU_ACTION_NOOP;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return new_action;
|
|
}
|
|
|
|
/* Menu entry action callback */
|
|
static int rgui_menu_entry_action(
|
|
void *userdata, menu_entry_t *entry,
|
|
size_t i, enum menu_action action)
|
|
{
|
|
rgui_t *rgui = (rgui_t*)userdata;
|
|
|
|
/* Process input action */
|
|
enum menu_action new_action = rgui_parse_menu_entry_action(rgui, entry, action);
|
|
|
|
/* Call standard generic_menu_entry_action() function */
|
|
return generic_menu_entry_action(userdata, entry, i, new_action);
|
|
}
|
|
|
|
menu_ctx_driver_t menu_ctx_rgui = {
|
|
rgui_set_texture,
|
|
rgui_set_message,
|
|
rgui_render,
|
|
rgui_frame,
|
|
rgui_init,
|
|
rgui_free,
|
|
rgui_context_reset,
|
|
rgui_context_destroy,
|
|
rgui_populate_entries,
|
|
rgui_toggle,
|
|
rgui_navigation_clear,
|
|
NULL,
|
|
NULL,
|
|
rgui_navigation_set,
|
|
rgui_navigation_set_last,
|
|
rgui_navigation_descend_alphabet,
|
|
rgui_navigation_ascend_alphabet,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
rgui_load_image,
|
|
"rgui",
|
|
rgui_environ,
|
|
NULL, /* update_thumbnail_path */
|
|
rgui_update_thumbnail_image,
|
|
rgui_refresh_thumbnail_image,
|
|
NULL, /* set_thumbnail_content */
|
|
rgui_osk_ptr_at_pos,
|
|
rgui_osk_pointer_over_textbox,
|
|
rgui_update_savestate_thumbnail_path,
|
|
rgui_update_savestate_thumbnail_image,
|
|
NULL, /* pointer_down */
|
|
rgui_pointer_up,
|
|
rgui_menu_entry_action,
|
|
rgui_wheel_scroll
|
|
};
|