(RGUI) Start refactoring menu_display code in RGUI

This commit is contained in:
twinaphex 2015-09-27 00:00:54 +02:00
parent f83e26ea32
commit 057b498bb1
3 changed files with 43 additions and 13 deletions

View File

@ -185,11 +185,13 @@ static void blit_line(uint16_t *data,
const char *message, uint16_t color) const char *message, uint16_t color)
{ {
unsigned i, j; unsigned i, j;
menu_display_t *disp = menu_display_get_ptr();
while (*message) while (*message)
{ {
uint32_t symbol = string_walk(&message); uint8_t *font_fb;
uint32_t symbol = string_walk(&message);
menu_display_ctl(MENU_DISPLAY_CTL_FONT_FB, &font_fb);
for (j = 0; j < FONT_HEIGHT; j++) for (j = 0; j < FONT_HEIGHT; j++)
{ {
@ -197,7 +199,7 @@ static void blit_line(uint16_t *data,
{ {
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7); uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
int offset = (i + j * FONT_WIDTH) >> 3; int offset = (i + j * FONT_WIDTH) >> 3;
bool col = (disp->font.framebuf[FONT_OFFSET(symbol) + offset] & rem); bool col = (font_fb[FONT_OFFSET(symbol) + offset] & rem);
if (!col) if (!col)
continue; continue;
@ -215,7 +217,6 @@ static bool init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf)
unsigned i; unsigned i;
uint8_t *font = (uint8_t *) calloc(1, FONT_OFFSET(256)); uint8_t *font = (uint8_t *) calloc(1, FONT_OFFSET(256));
bool fb_font_inited = true; bool fb_font_inited = true;
menu_display_t *disp = menu_display_get_ptr();
if (!font) if (!font)
return false; return false;
@ -230,7 +231,8 @@ 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)); font_bmp_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x));
} }
disp->font.framebuf = font; menu_display_ctl(MENU_DISPLAY_CTL_SET_FONT_FB, &font);
return true; return true;
} }
@ -238,7 +240,6 @@ static bool rguidisp_init_font(menu_handle_t *menu)
{ {
const uint8_t *font_bmp_buf = NULL; const uint8_t *font_bmp_buf = NULL;
const uint8_t *font_bin_buf = bitmap_bin; const uint8_t *font_bin_buf = bitmap_bin;
menu_display_t *disp = menu_display_get_ptr();
if (!menu) if (!menu)
return false; return false;
@ -249,7 +250,7 @@ static bool rguidisp_init_font(menu_handle_t *menu)
if (!font_bin_buf) if (!font_bin_buf)
return false; return false;
disp->font.framebuf = font_bin_buf; menu_display_ctl(MENU_DISPLAY_CTL_SET_FONT_FB, &font_bin_buf);
return true; return true;
} }
@ -711,11 +712,11 @@ error:
static void rgui_free(void *data) static void rgui_free(void *data)
{ {
uint8_t *font_fb;
bool fb_font_inited = false; bool fb_font_inited = false;
menu_handle_t *menu = (menu_handle_t*)data; menu_handle_t *menu = (menu_handle_t*)data;
menu_display_t *disp = menu_display_get_ptr();
if (!menu || !disp) if (!menu)
return; return;
if (menu->userdata) if (menu->userdata)
@ -723,9 +724,10 @@ static void rgui_free(void *data)
menu->userdata = NULL; menu->userdata = NULL;
menu_display_ctl(MENU_DISPLAY_CTL_FONT_DATA_INIT, &fb_font_inited); menu_display_ctl(MENU_DISPLAY_CTL_FONT_DATA_INIT, &fb_font_inited);
menu_display_ctl(MENU_DISPLAY_CTL_FONT_FB, &font_fb);
if (fb_font_inited) if (fb_font_inited)
free((uint8_t*)disp->font.framebuf); free(font_fb);
fb_font_inited = false; fb_font_inited = false;

View File

@ -45,8 +45,6 @@ static menu_framebuf_t *menu_display_fb_get_ptr(void)
return &frame_buf_state; return &frame_buf_state;
} }
static void menu_display_fb_free(menu_framebuf_t *frame_buf) static void menu_display_fb_free(menu_framebuf_t *frame_buf)
{ {
if (!frame_buf) if (!frame_buf)
@ -194,6 +192,32 @@ bool menu_display_ctl(enum menu_display_ctl_state state, void *data)
switch (state) switch (state)
{ {
case MENU_DISPLAY_CTL_FONT_BUF:
if (!data)
return false;
data = disp->font.buf;
return true;
case MENU_DISPLAY_CTL_SET_FONT_BUF:
if (!data)
return false;
disp->font.buf = data;
return true;
case MENU_DISPLAY_CTL_FONT_FB:
{
uint8_t **ptr = (uint8_t**)data;
if (!ptr)
return false;
*ptr = (uint8_t*)disp->font.framebuf;
}
return true;
case MENU_DISPLAY_CTL_SET_FONT_FB:
{
uint8_t **ptr = (uint8_t**)data;
if (!ptr)
return false;
disp->font.framebuf = *ptr;
}
return true;
case MENU_DISPLAY_CTL_LIBRETRO: case MENU_DISPLAY_CTL_LIBRETRO:
video_driver_set_texture_enable(true, false); video_driver_set_texture_enable(true, false);

View File

@ -53,7 +53,11 @@ enum menu_display_ctl_state
MENU_DISPLAY_CTL_FONT_SIZE, MENU_DISPLAY_CTL_FONT_SIZE,
MENU_DISPLAY_CTL_SET_FONT_SIZE, MENU_DISPLAY_CTL_SET_FONT_SIZE,
MENU_DISPLAY_CTL_MSG_FORCE, MENU_DISPLAY_CTL_MSG_FORCE,
MENU_DISPLAY_CTL_SET_MSG_FORCE MENU_DISPLAY_CTL_SET_MSG_FORCE,
MENU_DISPLAY_CTL_FONT_BUF,
MENU_DISPLAY_CTL_SET_FONT_BUF,
MENU_DISPLAY_CTL_FONT_FB,
MENU_DISPLAY_CTL_SET_FONT_FB
}; };
typedef struct menu_display typedef struct menu_display