Create menu_display_get_ptr

This commit is contained in:
twinaphex 2015-06-14 15:34:05 +02:00
parent dae1821d1e
commit 6a2b871f16
8 changed files with 115 additions and 80 deletions

View File

@ -64,6 +64,7 @@ static void glui_blit_line(float x, float y,
glui_handle_t *glui = NULL;
struct font_params params = {0};
menu_handle_t *menu = menu_driver_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
if (!menu)
return;
@ -73,14 +74,14 @@ static void glui_blit_line(float x, float y,
glui = (glui_handle_t*)menu->userdata;
params.x = x / width;
params.y = 1.0f - (y + glui->line_height/2 + menu->font.size/3)
params.y = 1.0f - (y + glui->line_height/2 + disp->font.size/3)
/ height;
params.scale = 1.0;
params.color = color;
params.full_screen = true;
params.text_align = text_align;
video_driver_set_osd_msg(message, &params, menu->font.buf);
video_driver_set_osd_msg(message, &params, disp->font.buf);
}
static void glui_render_quad(gl_t *gl, int x, int y, int w, int h,
@ -136,9 +137,10 @@ static void glui_draw_scrollbar(gl_t *gl)
{
unsigned width, height;
float content_height, total_height, scrollbar_height, y;
int scrollbar_width = 4;
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
int scrollbar_width = 4;
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
if (!menu)
return;
@ -147,7 +149,7 @@ static void glui_draw_scrollbar(gl_t *gl)
glui = (glui_handle_t*)menu->userdata;
content_height = menu_entries_get_end() * glui->line_height;
total_height = height - menu->header_height * 2;
total_height = height - disp->header_height * 2;
scrollbar_height = total_height / (content_height / total_height);
y = total_height * menu->scroll_y / content_height;
@ -156,7 +158,7 @@ static void glui_draw_scrollbar(gl_t *gl)
glui_render_quad(gl,
width - scrollbar_width,
menu->header_height + y,
disp->header_height + y,
scrollbar_width,
scrollbar_height,
1, 1, 1, 1);
@ -187,9 +189,10 @@ static void glui_render_messagebox(const char *message)
int x, y;
struct string_list *list = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
settings_t *settings = config_get_ptr();
if (!menu || !menu->userdata)
if (!menu || !disp || !menu->userdata)
return;
list = (struct string_list*)string_split(message, "\n");
@ -203,7 +206,7 @@ static void glui_render_messagebox(const char *message)
video_driver_get_size(&width, &height);
x = width / 2;
y = height / 2 - list->size * menu->font.size / 2;
y = height / 2 - list->size * disp->font.size / 2;
normal_color = FONT_COLOR_ARGB_TO_RGBA(settings->menu.entry_normal_color);
@ -211,7 +214,7 @@ static void glui_render_messagebox(const char *message)
{
const char *msg = list->elems[i].data;
if (msg)
glui_blit_line(x, y + i * menu->font.size, msg, normal_color, TEXT_ALIGN_CENTER);
glui_blit_line(x, y + i * disp->font.size, msg, normal_color, TEXT_ALIGN_CENTER);
}
end:
@ -223,6 +226,7 @@ static void glui_render(void)
int bottom;
unsigned width, height;
glui_handle_t *glui = NULL;
menu_display_t *disp = menu_display_get_ptr();
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
menu_handle_t *menu = menu_driver_get_ptr();
menu_input_t *menu_input = menu_input_get_ptr();
@ -270,12 +274,12 @@ static void glui_render(void)
menu->scroll_y = 0;
bottom = menu_entries_get_end() * glui->line_height
- height + menu->header_height * 2;
- height + disp->header_height * 2;
if (menu->scroll_y > bottom)
menu->scroll_y = bottom;
if (menu_entries_get_end() * glui->line_height
< height - menu->header_height*2)
< height - disp->header_height*2)
menu->scroll_y = 0;
}
@ -288,6 +292,7 @@ static void glui_render_menu_list(glui_handle_t *glui,
size_t i = 0;
uint64_t frame_count = video_driver_get_frame_count();
size_t end = menu_entries_get_end();
menu_display_t *disp = menu_display_get_ptr();
if (!menu_display_update_pending())
return;
@ -304,7 +309,7 @@ static void glui_render_menu_list(glui_handle_t *glui,
char message[PATH_MAX_LENGTH] = {0};
char entry_title_buf[PATH_MAX_LENGTH] = {0};
char type_str_buf[PATH_MAX_LENGTH] = {0};
int y = menu->header_height - menu->scroll_y + (glui->line_height * i);
int y = disp->header_height - menu->scroll_y + (glui->line_height * i);
if (y > height || ((y + (int)glui->line_height) < 0))
continue;
@ -342,6 +347,7 @@ static void glui_frame(void)
menu_handle_t *menu = menu_driver_get_ptr();
menu_animation_t *anim = menu_animation_get_ptr();
menu_navigation_t *nav = menu_navigation_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
settings_t *settings = config_get_ptr();
menu_input_t *menu_input = menu_input_get_ptr();
uint64_t frame_count = video_driver_get_frame_count();
@ -386,7 +392,7 @@ static void glui_frame(void)
menu_display_font_flush_block(menu, font_driver);
glui_render_quad(gl, 0,
menu->header_height - menu->scroll_y + glui->line_height *
disp->header_height - menu->scroll_y + glui->line_height *
nav->selection_ptr,
width, glui->line_height, 1, 1, 1, 0.1);
@ -394,7 +400,7 @@ static void glui_frame(void)
menu->label.is_updated = false;
glui_render_quad(gl, 0, 0, width,
menu->header_height, 0.2, 0.2, 0.2, 1);
disp->header_height, 0.2, 0.2, 0.2, 1);
menu_animation_ticker_line(title_buf, glui->ticker_limit,
frame_count / 100, title, true);
@ -405,9 +411,11 @@ static void glui_frame(void)
glui_blit_line(glui->margin, 0, "BACK",
title_color, TEXT_ALIGN_LEFT);
glui_render_quad(gl, 0,
height - menu->header_height,
width, menu->header_height,
glui_render_quad(gl,
0,
height - disp->header_height,
width,
disp->header_height,
0.2, 0.2, 0.2, 1);
glui_draw_scrollbar(gl);
@ -495,15 +503,15 @@ static void *glui_init(void)
if (!menu->userdata)
goto error;
glui = (glui_handle_t*)menu->userdata;
dpi = menu_display_get_dpi();
glui = (glui_handle_t*)menu->userdata;
dpi = menu_display_get_dpi();
glui->line_height = dpi / 3;
glui->margin = dpi / 6;
glui->ticker_limit = dpi / 3;
menu->header_height = dpi / 3;
menu->font.size = dpi / 8;
glui->textures.bg.id = 0;
glui->line_height = dpi / 3;
glui->margin = dpi / 6;
glui->ticker_limit = dpi / 3;
menu->display.header_height = dpi / 3;
menu->display.font.size = dpi / 8;
glui->textures.bg.id = 0;
glui_allocate_white_texture(glui);
@ -677,7 +685,7 @@ static void glui_context_reset(void)
glui = (glui_handle_t*)menu->userdata;
font_path = settings->video.font_enable ? settings->video.font_path : NULL;
if (!menu_display_init_main_font(menu, font_path, menu->font.size))
if (!menu_display_init_main_font(menu, font_path, menu->display.font.size))
RARCH_WARN("Failed to load font.");
glui_context_bg_destroy(glui);

View File

@ -149,6 +149,7 @@ static void blit_line(menu_handle_t *menu, int x, int y,
{
unsigned i, j;
menu_framebuf_t *frame_buf = menu_display_fb_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
while (*message)
{
@ -158,7 +159,7 @@ static void blit_line(menu_handle_t *menu, int x, int y,
{
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
int offset = (i + j * FONT_WIDTH) >> 3;
bool col = (menu->font.framebuf[FONT_OFFSET
bool col = (disp->font.framebuf[FONT_OFFSET
((unsigned char)*message) + offset] & rem);
if (!col)
@ -185,7 +186,7 @@ static bool init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf)
return false;
}
menu->font.alloc_framebuf = true;
menu->display.font.alloc_framebuf = true;
for (i = 0; i < 256; i++)
{
unsigned y = i / 16;
@ -194,7 +195,7 @@ static bool init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf)
font_bmp_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x));
}
menu->font.framebuf = font;
menu->display.font.framebuf = font;
return true;
}
@ -212,7 +213,7 @@ static bool rguidisp_init_font(menu_handle_t *menu)
if (!font_bin_buf)
return false;
menu->font.framebuf = font_bin_buf;
menu->display.font.framebuf = font_bin_buf;
return true;
}
@ -527,7 +528,7 @@ static void *rgui_init(void)
if (!menu)
return NULL;
frame_buf = &menu->frame_buf;
frame_buf = &menu->display.frame_buf;
/* 4 extra lines to cache the checked background */
frame_buf->data = (uint16_t*)calloc(400 * (240 + 4), sizeof(uint16_t));
@ -535,11 +536,11 @@ static void *rgui_init(void)
if (!frame_buf->data)
goto error;
frame_buf->width = 320;
frame_buf->height = 240;
menu->header_height = FONT_HEIGHT_STRIDE * 2;
menu->begin = 0;
frame_buf->pitch = frame_buf->width * sizeof(uint16_t);
frame_buf->width = 320;
frame_buf->height = 240;
menu->display.header_height = FONT_HEIGHT_STRIDE * 2;
menu->begin = 0;
frame_buf->pitch = frame_buf->width * sizeof(uint16_t);
ret = rguidisp_init_font(menu);
@ -570,17 +571,19 @@ error:
static void rgui_free(void *data)
{
menu_handle_t *menu = (menu_handle_t*)data;
menu_handle_t *menu = (menu_handle_t*)data;
menu_display_t *disp = menu ? &menu->display : NULL;
if (!menu)
if (!menu || !disp)
return;
if (menu->userdata)
free(menu->userdata);
menu->userdata = NULL;
if (menu->font.alloc_framebuf)
free((uint8_t*)menu->font.framebuf);
if (disp->font.alloc_framebuf)
free((uint8_t*)disp->font.framebuf);
disp->font.alloc_framebuf = NULL;
}
static void rgui_set_texture(void)

View File

@ -435,7 +435,7 @@ static void xmb_draw_text(menu_handle_t *menu,
params.full_screen = true;
params.text_align = text_align;
video_driver_set_osd_msg(str, &params, menu->font.buf);
video_driver_set_osd_msg(str, &params, menu->display.font.buf);
}
static void xmb_render_messagebox_internal(const char *message)
@ -486,16 +486,22 @@ static void xmb_frame_messagebox(const char *message)
if (list->elems == 0)
goto end;
x = width / 2 - strlen(list->elems[0].data) * menu->font.size / 4;
y = height / 2 - list->size * menu->font.size / 2;
x = width / 2 - strlen(list->elems[0].data) * menu->display.font.size / 4;
y = height / 2 - list->size * menu->display.font.size / 2;
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
if (msg)
xmb_draw_text(menu, xmb, msg, x,
y + i * menu->font.size, 1, 1, TEXT_ALIGN_LEFT);
xmb_draw_text(menu,
xmb,
msg,
x,
y + i * menu->display.font.size,
1,
1,
TEXT_ALIGN_LEFT);
}
end:
@ -1467,7 +1473,7 @@ static void *xmb_init(void)
if (!menu)
goto error;
frame_buf = &menu->frame_buf;
frame_buf = &menu->display.frame_buf;
video_driver_get_size(&width, &height);
@ -1537,19 +1543,19 @@ static void *xmb_init(void)
xmb->icon.size = 128.0 * scale_factor;
xmb->cursor.size = 48.0;
menu->font.size = 32.0 * scale_factor;
menu->display.font.size = 32.0 * scale_factor;
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 + menu->font.size/3;
xmb->margins.title.bottom = 60 * scale_factor - menu->font.size/3;
xmb->margins.title.top = 60 * scale_factor + menu->display.font.size/3;
xmb->margins.title.bottom = 60 * scale_factor - menu->display.font.size/3;
xmb->margins.label.left = 85.0 * scale_factor;
xmb->margins.label.top = menu->font.size/3.0;
xmb->margins.label.top = menu->display.font.size / 3.0;
xmb->margins.setting.left = 600.0 * scale_factor;
menu->header_height = xmb->icon.size;
menu->display.header_height = xmb->icon.size;
xmb_init_horizontal_list(menu, xmb);
@ -1869,7 +1875,7 @@ static void xmb_context_reset(void)
fill_pathname_join(fontpath, themepath, "font.ttf", sizeof(fontpath));
if (!menu_display_init_main_font(menu, fontpath, menu->font.size))
if (!menu_display_init_main_font(menu, fontpath, menu->display.font.size))
RARCH_WARN("Failed to load font.");
xmb_context_reset_textures(xmb, iconpath);

View File

@ -221,9 +221,9 @@ static void menu_free_list(menu_handle_t *menu)
return;
menu_setting_free(menu->list_settings);
menu_list_free(menu->menu_list);
menu->list_settings = NULL;
menu_list_free(menu->menu_list);
menu->menu_list = NULL;
}

View File

@ -25,12 +25,20 @@
#include "../gfx/video_thread_wrapper.h"
#include "menu_list.h"
menu_framebuf_t *menu_display_fb_get_ptr(void)
menu_display_t *menu_display_get_ptr(void)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return NULL;
return &menu->frame_buf;
return &menu->display;
}
menu_framebuf_t *menu_display_fb_get_ptr(void)
{
menu_display_t *disp = menu_display_get_ptr();
if (!disp)
return NULL;
return &disp->frame_buf;
}
static bool menu_display_fb_in_use(menu_framebuf_t *frame_buf)
@ -119,7 +127,7 @@ void menu_display_free(void *data)
menu_animation_free(menu->animation);
menu->animation = NULL;
menu_display_fb_free(&menu->frame_buf);
menu_display_fb_free(&menu->display.frame_buf);
}
bool menu_display_init(void *data)
@ -197,7 +205,7 @@ bool menu_display_font_bind_block(void *data,
if (!font_driver || !font_driver->bind_block)
return false;
font_driver->bind_block(menu->font.buf, userdata);
font_driver->bind_block(menu->display.font.buf, userdata);
return true;
}
@ -209,7 +217,7 @@ bool menu_display_font_flush_block(void *data,
if (!font_driver || !font_driver->flush)
return false;
font_driver->flush(menu->font.buf);
font_driver->flush(menu->display.font.buf);
return menu_display_font_bind_block(menu,
font_driver, NULL);
@ -220,10 +228,10 @@ void menu_display_free_main_font(void *data)
menu_handle_t *menu = (menu_handle_t*)data;
driver_t *driver = driver_get_ptr();
if (menu->font.buf)
if (menu->display.font.buf)
{
driver->font_osd_driver->free(menu->font.buf);
menu->font.buf = NULL;
driver->font_osd_driver->free(menu->display.font.buf);
menu->display.font.buf = NULL;
}
}
@ -235,17 +243,17 @@ bool menu_display_init_main_font(void *data,
driver_t *driver = driver_get_ptr();
void *video = video_driver_get_ptr(NULL);
if (menu->font.buf)
if (menu->display.font.buf)
menu_display_free_main_font(menu);
ret = menu_display_font_init_first(
(const void**)&driver->font_osd_driver, &menu->font.buf, video,
(const void**)&driver->font_osd_driver, &menu->display.font.buf, video,
font_path, font_size);
if (ret)
menu->font.size = font_size;
menu->display.font.size = font_size;
else
menu->font.buf = NULL;
menu->display.font.buf = NULL;
return ret;
}

View File

@ -35,6 +35,24 @@ typedef struct menu_framebuf
bool dirty;
} menu_framebuf_t;
typedef struct menu_display
{
menu_framebuf_t frame_buf;
struct
{
void *buf;
int size;
const uint8_t *framebuf;
bool alloc_framebuf;
} font;
unsigned header_height;
} menu_display_t;
menu_display_t *menu_display_get_ptr(void);
menu_framebuf_t *menu_display_fb_get_ptr(void);
void menu_display_fb(void);

View File

@ -60,7 +60,6 @@ typedef struct
} delay;
size_t begin;
unsigned header_height;
float scroll_y;
menu_list_t *menu_list;
@ -90,16 +89,7 @@ typedef struct
char default_glslp[PATH_MAX_LENGTH];
char default_cgp[PATH_MAX_LENGTH];
menu_framebuf_t frame_buf;
struct
{
void *buf;
int size;
const uint8_t *framebuf;
bool alloc_framebuf;
} font;
menu_display_t display;
bool load_no_content;

View File

@ -770,6 +770,7 @@ static int menu_input_mouse_post_iterate(uint64_t *input_mouse,
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
menu_handle_t *menu = menu_driver_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
menu_input_t *menu_input = menu_input_get_ptr();
menu_list_t *menu_list = menu_list_get_ptr();
menu_navigation_t *nav = menu_navigation_get_ptr();
@ -802,7 +803,7 @@ static int menu_input_mouse_post_iterate(uint64_t *input_mouse,
menu_list->selection_buf->list[nav->selection_ptr].label);
menu_input->mouse.oldleft = true;
if (menu_input->mouse.y < menu->header_height)
if (menu_input->mouse.y < disp->header_height)
{
menu_list_pop_stack(menu_list);
return 0;
@ -884,6 +885,7 @@ static int menu_input_pointer_post_iterate(menu_file_list_cbs_t *cbs,
{
int ret = 0;
menu_handle_t *menu = menu_driver_get_ptr();
menu_display_t *disp = menu_display_get_ptr();
menu_list_t *menu_list = menu_list_get_ptr();
menu_input_t *menu_input = menu_input_get_ptr();
driver_t *driver = driver_get_ptr();
@ -925,7 +927,7 @@ static int menu_input_pointer_post_iterate(menu_file_list_cbs_t *cbs,
{
if (!menu_input->pointer.dragging)
{
if (menu_input->pointer.start_y < menu->header_height)
if (menu_input->pointer.start_y < disp->header_height)
menu_list_pop_stack(menu_list);
else if (menu_input->pointer.ptr <= menu_list_get_size(menu_list)-1)
{