mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
More menu_display_ctl refactors
This commit is contained in:
parent
16eb95d3aa
commit
515c8c6322
@ -72,6 +72,7 @@ static const GRfloat glui_tex_coords[] = {
|
||||
static void glui_blit_line(float x, float y, unsigned width, unsigned height,
|
||||
const char *message, uint32_t color, enum text_alignment text_align)
|
||||
{
|
||||
int font_size;
|
||||
glui_handle_t *glui = NULL;
|
||||
struct font_params params = {0};
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
@ -82,8 +83,10 @@ static void glui_blit_line(float x, float y, unsigned width, unsigned height,
|
||||
|
||||
glui = (glui_handle_t*)menu->userdata;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FONT_SIZE, &font_size);
|
||||
|
||||
params.x = x / width;
|
||||
params.y = 1.0f - (y + glui->line_height/2 + disp->font.size/3)
|
||||
params.y = 1.0f - (y + glui->line_height / 2 + font_size / 3)
|
||||
/ height;
|
||||
params.scale = 1.0;
|
||||
params.color = color;
|
||||
@ -169,7 +172,7 @@ static void glui_render_messagebox(const char *message)
|
||||
unsigned i;
|
||||
unsigned width, height;
|
||||
uint32_t normal_color;
|
||||
int x, y;
|
||||
int x, y, font_size;
|
||||
struct string_list *list = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
@ -188,8 +191,10 @@ static void glui_render_messagebox(const char *message)
|
||||
|
||||
video_driver_get_size(&width, &height);
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FONT_SIZE, &font_size);
|
||||
|
||||
x = width / 2;
|
||||
y = height / 2 - list->size * disp->font.size / 2;
|
||||
y = height / 2 - list->size * font_size / 2;
|
||||
|
||||
normal_color = FONT_COLOR_ARGB_TO_RGBA(settings->menu.entry_normal_color);
|
||||
|
||||
@ -197,7 +202,7 @@ static void glui_render_messagebox(const char *message)
|
||||
{
|
||||
const char *msg = list->elems[i].data;
|
||||
if (msg)
|
||||
glui_blit_line(x, y + i * disp->font.size,
|
||||
glui_blit_line(x, y + i * font_size,
|
||||
width, height,
|
||||
msg, normal_color, TEXT_ALIGN_CENTER);
|
||||
}
|
||||
@ -550,20 +555,24 @@ static void glui_allocate_white_texture(glui_handle_t *glui)
|
||||
|
||||
static void glui_font(menu_handle_t *menu)
|
||||
{
|
||||
int font_size;
|
||||
const char *font_path = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
|
||||
font_path = settings->video.font_enable ? settings->video.font_path : NULL;
|
||||
|
||||
if (!menu_display_init_main_font(menu, font_path, disp->font.size))
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FONT_SIZE, &font_size);
|
||||
|
||||
if (!menu_display_init_main_font(menu, font_path, font_size))
|
||||
RARCH_ERR("Failed to load font.");
|
||||
}
|
||||
|
||||
static void glui_layout(menu_handle_t *menu, glui_handle_t *glui)
|
||||
{
|
||||
float scale_factor;
|
||||
unsigned width, height;
|
||||
int new_font_size;
|
||||
unsigned width, height, new_header_height;
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
|
||||
video_driver_get_size(&width, &height);
|
||||
@ -574,12 +583,17 @@ static void glui_layout(menu_handle_t *menu, glui_handle_t *glui)
|
||||
proportional to the display width. */
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_GET_DPI, &scale_factor);
|
||||
|
||||
new_header_height = scale_factor / 3;
|
||||
new_font_size = scale_factor / 10;
|
||||
|
||||
glui->line_height = scale_factor / 3;
|
||||
glui->margin = scale_factor / 6;
|
||||
disp->header_height = scale_factor / 3;
|
||||
disp->font.size = scale_factor / 10;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEADER_HEIGHT, &new_header_height);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_FONT_SIZE, &new_font_size);
|
||||
|
||||
/* we assume the average glyph aspect ratio is close to 3:4 */
|
||||
glui->glyph_width = disp->font.size * 3/4;
|
||||
glui->glyph_width = new_font_size * 3/4;
|
||||
|
||||
glui_font(menu);
|
||||
|
||||
|
@ -644,11 +644,10 @@ static void rgui_render(void)
|
||||
static void *rgui_init(void)
|
||||
{
|
||||
size_t fb_pitch;
|
||||
unsigned fb_width, fb_height;
|
||||
unsigned fb_width, fb_height, new_font_height;
|
||||
uint16_t *fb_data = NULL;
|
||||
rgui_t *rgui = NULL;
|
||||
bool ret = false;
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
|
||||
|
||||
if (!menu)
|
||||
@ -668,14 +667,13 @@ static void *rgui_init(void)
|
||||
fb_width = 320;
|
||||
fb_height = 240;
|
||||
fb_pitch = fb_width * sizeof(uint16_t);
|
||||
new_font_height = FONT_HEIGHT_STRIDE * 2;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_WIDTH, &fb_width);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEIGHT, &fb_height);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_FB_DATA, fb_data);
|
||||
|
||||
disp->header_height = FONT_HEIGHT_STRIDE * 2;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_FB_PITCH, &fb_pitch);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_WIDTH, &fb_width);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEIGHT, &fb_height);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_FB_DATA, fb_data);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEADER_HEIGHT, &new_font_height);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_FB_PITCH, &fb_pitch);
|
||||
|
||||
menu_entries_set_start(0);
|
||||
|
||||
|
@ -491,14 +491,13 @@ static void xmb_render_messagebox_internal(const char *message)
|
||||
|
||||
static void xmb_frame_messagebox(const char *message)
|
||||
{
|
||||
int x, y;
|
||||
int x, y, font_size;
|
||||
unsigned i;
|
||||
unsigned width, height;
|
||||
struct string_list *list = NULL;
|
||||
gl_t *gl = NULL;
|
||||
xmb_handle_t *xmb = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
|
||||
if (!menu)
|
||||
return;
|
||||
@ -522,8 +521,10 @@ static void xmb_frame_messagebox(const char *message)
|
||||
if (list->elems == 0)
|
||||
goto end;
|
||||
|
||||
x = width / 2 - strlen(list->elems[0].data) * disp->font.size / 4;
|
||||
y = height / 2 - list->size * disp->font.size / 2;
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FONT_SIZE, &font_size);
|
||||
|
||||
x = width / 2 - strlen(list->elems[0].data) * font_size / 4;
|
||||
y = height / 2 - list->size * font_size / 2;
|
||||
|
||||
for (i = 0; i < list->size; i++)
|
||||
{
|
||||
@ -534,7 +535,7 @@ static void xmb_frame_messagebox(const char *message)
|
||||
xmb,
|
||||
msg,
|
||||
x,
|
||||
y + i * disp->font.size,
|
||||
y + i * font_size,
|
||||
1,
|
||||
1,
|
||||
TEXT_ALIGN_LEFT,
|
||||
@ -1694,47 +1695,53 @@ static void xmb_init_horizontal_list(menu_handle_t *menu, xmb_handle_t *xmb)
|
||||
|
||||
static void xmb_font(menu_handle_t *menu)
|
||||
{
|
||||
int font_size;
|
||||
char mediapath[PATH_MAX_LENGTH], themepath[PATH_MAX_LENGTH], fontpath[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_FONT_SIZE, &font_size);
|
||||
|
||||
fill_pathname_join(mediapath, settings->assets_directory, "xmb", sizeof(mediapath));
|
||||
fill_pathname_join(themepath, mediapath, XMB_THEME, sizeof(themepath));
|
||||
fill_pathname_join(fontpath, themepath, "font.ttf", sizeof(fontpath));
|
||||
|
||||
if (!menu_display_init_main_font(menu, fontpath, disp->font.size))
|
||||
if (!menu_display_init_main_font(menu, fontpath, font_size))
|
||||
RARCH_WARN("Failed to load font.");
|
||||
}
|
||||
|
||||
static void xmb_layout(menu_handle_t *menu, xmb_handle_t *xmb)
|
||||
{
|
||||
int new_font_size;
|
||||
size_t selection;
|
||||
float scale_factor;
|
||||
unsigned width, height, i, current, end;
|
||||
unsigned width, height, i, current, end, new_header_height;
|
||||
menu_list_t *menu_list = menu_list_get_ptr();
|
||||
menu_display_t *disp = menu_display_get_ptr();
|
||||
|
||||
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
|
||||
return;
|
||||
|
||||
video_driver_get_size(&width, &height);
|
||||
|
||||
scale_factor = width / 1920.0;
|
||||
scale_factor = width / 1920.0;
|
||||
new_font_size = 32.0 * scale_factor;
|
||||
new_header_height = 128.0 * scale_factor;
|
||||
|
||||
xmb->boxart_size = 460.0 * scale_factor;
|
||||
xmb->cursor.size = 48.0;
|
||||
disp->font.size = 32.0 * scale_factor;
|
||||
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_FONT_SIZE, &new_font_size);
|
||||
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEADER_HEIGHT, &new_header_height);
|
||||
|
||||
xmb->icon.spacing.horizontal = 200.0 * scale_factor;
|
||||
xmb->icon.spacing.vertical = 64.0 * scale_factor;
|
||||
xmb->margins.screen.left = 336.0 * scale_factor;
|
||||
xmb->margins.screen.top = (256+32) * scale_factor;
|
||||
xmb->margins.title.left = 60 * scale_factor;
|
||||
xmb->margins.title.top = 60 * scale_factor + disp->font.size/3;
|
||||
xmb->margins.title.bottom = 60 * scale_factor - disp->font.size/3;
|
||||
xmb->margins.title.top = 60 * scale_factor + new_font_size / 3;
|
||||
xmb->margins.title.bottom = 60 * scale_factor - new_font_size / 3;
|
||||
xmb->margins.label.left = 85.0 * scale_factor;
|
||||
xmb->margins.label.top = disp->font.size / 3.0;
|
||||
xmb->margins.label.top = new_font_size / 3.0;
|
||||
xmb->margins.setting.left = 600.0 * scale_factor;
|
||||
disp->header_height = 128.0 * scale_factor;
|
||||
|
||||
if (width >= 3840)
|
||||
scale_factor = 2.0;
|
||||
|
@ -246,6 +246,30 @@ bool menu_display_ctl(enum menu_display_ctl_state state, void *data)
|
||||
*ptr = disp->header_height;
|
||||
}
|
||||
return true;
|
||||
case MENU_DISPLAY_CTL_SET_HEADER_HEIGHT:
|
||||
{
|
||||
unsigned *ptr = (unsigned*)data;
|
||||
if (!ptr)
|
||||
return false;
|
||||
disp->header_height = *ptr;
|
||||
}
|
||||
return true;
|
||||
case MENU_DISPLAY_CTL_FONT_SIZE:
|
||||
{
|
||||
unsigned *ptr = (unsigned*)data;
|
||||
if (!ptr)
|
||||
return false;
|
||||
*ptr = disp->font.size;
|
||||
}
|
||||
return true;
|
||||
case MENU_DISPLAY_CTL_SET_FONT_SIZE:
|
||||
{
|
||||
unsigned *ptr = (unsigned*)data;
|
||||
if (!ptr)
|
||||
return false;
|
||||
disp->font.size = *ptr;
|
||||
}
|
||||
return true;
|
||||
case MENU_DISPLAY_CTL_SET_HEIGHT:
|
||||
{
|
||||
unsigned *ptr = (unsigned*)data;
|
||||
|
@ -40,6 +40,7 @@ enum menu_display_ctl_state
|
||||
MENU_DISPLAY_CTL_WIDTH,
|
||||
MENU_DISPLAY_CTL_HEIGHT,
|
||||
MENU_DISPLAY_CTL_HEADER_HEIGHT,
|
||||
MENU_DISPLAY_CTL_SET_HEADER_HEIGHT,
|
||||
MENU_DISPLAY_CTL_SET_WIDTH,
|
||||
MENU_DISPLAY_CTL_SET_HEIGHT,
|
||||
MENU_DISPLAY_CTL_FB_DATA,
|
||||
@ -48,7 +49,9 @@ enum menu_display_ctl_state
|
||||
MENU_DISPLAY_CTL_SET_FB_PITCH,
|
||||
MENU_DISPLAY_CTL_LIBRETRO,
|
||||
MENU_DISPLAY_CTL_FONT_DATA_INIT,
|
||||
MENU_DISPLAY_CTL_SET_FONT_DATA_INIT
|
||||
MENU_DISPLAY_CTL_SET_FONT_DATA_INIT,
|
||||
MENU_DISPLAY_CTL_FONT_SIZE,
|
||||
MENU_DISPLAY_CTL_SET_FONT_SIZE
|
||||
};
|
||||
|
||||
typedef struct menu_display
|
||||
|
Loading…
x
Reference in New Issue
Block a user