[zr] remove most glui drawing code

This commit is contained in:
radius 2016-03-02 19:23:34 -05:00
parent d5bc3c4d5b
commit c2bd46e3cb

View File

@ -1016,211 +1016,6 @@ static void wimp_context_reset_textures(wimp_handle_t *wimp,
}
}
static void wimp_draw_icon(wimp_handle_t *wimp,
uintptr_t texture,
float x, float y,
unsigned width, unsigned height,
float rotation, float scale_factor,
float *color)
{
menu_display_ctx_rotate_draw_t rotate_draw;
menu_display_ctx_draw_t draw;
struct gfx_coords coords;
math_matrix_4x4 mymat;
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_BEGIN, NULL);
rotate_draw.matrix = &mymat;
rotate_draw.rotation = rotation;
rotate_draw.scale_x = scale_factor;
rotate_draw.scale_y = scale_factor;
rotate_draw.scale_z = 1;
rotate_draw.scale_enable = true;
menu_display_ctl(MENU_DISPLAY_CTL_ROTATE_Z, &rotate_draw);
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
coords.color = (const float*)color;
draw.x = x;
draw.y = height - y - wimp->icon_size;
draw.width = wimp->icon_size;
draw.height = wimp->icon_size;
draw.coords = &coords;
draw.matrix_data = &mymat;
draw.texture = texture;
draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP;
menu_display_ctl(MENU_DISPLAY_CTL_DRAW, &draw);
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_END, NULL);
}
static void wimp_draw_tab(wimp_handle_t *wimp,
unsigned i,
unsigned width, unsigned height,
float *pure_white)
{
unsigned tab_icon;
switch (i)
{
case ZR_SYSTEM_TAB_MAIN:
tab_icon = (i == wimp->categories.selection_ptr)
? ZR_TEXTURE_TAB_MAIN_ACTIVE
: ZR_TEXTURE_TAB_MAIN_PASSIVE;
break;
case ZR_SYSTEM_TAB_PLAYLISTS:
tab_icon = (i == wimp->categories.selection_ptr)
? ZR_TEXTURE_TAB_PLAYLISTS_ACTIVE
: ZR_TEXTURE_TAB_PLAYLISTS_PASSIVE;
break;
case ZR_SYSTEM_TAB_SETTINGS:
tab_icon = (i == wimp->categories.selection_ptr)
? ZR_TEXTURE_TAB_SETTINGS_ACTIVE
: ZR_TEXTURE_TAB_SETTINGS_PASSIVE;
break;
}
wimp_draw_icon(wimp, wimp->textures.list[tab_icon].id,
width / (ZR_SYSTEM_TAB_END+1) * (i+0.5) - wimp->icon_size/2,
height - wimp->tabs_height,
width, height, 0, 1, &pure_white[0]);
}
static void wimp_blit_line(float x, float y, unsigned width, unsigned height,
const char *message, uint32_t color, enum text_alignment text_align)
{
int font_size;
struct font_params params;
void *fb_buf = NULL;
menu_display_ctl(MENU_DISPLAY_CTL_FONT_SIZE, &font_size);
params.x = x / width;
params.y = 1.0f - (y + font_size / 3) / height;
params.scale = 1.0f;
params.drop_mod = 0.0f;
params.drop_x = 0.0f;
params.drop_y = 0.0f;
params.color = color;
params.full_screen = true;
params.text_align = text_align;
menu_display_ctl(MENU_DISPLAY_CTL_FONT_BUF, &fb_buf);
video_driver_set_osd_msg(message, &params, fb_buf);
}
static void wimp_render_quad(wimp_handle_t *wimp,
int x, int y, unsigned w, unsigned h,
unsigned width, unsigned height,
float *coord_color)
{
menu_display_ctx_draw_t draw;
struct gfx_coords coords;
coords.vertices = 4;
coords.vertex = NULL;
coords.tex_coord = NULL;
coords.lut_tex_coord = NULL;
coords.color = coord_color;
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_BEGIN, NULL);
draw.x = x;
draw.y = (int)height - y - (int)h;
draw.width = w;
draw.height = h;
draw.coords = &coords;
draw.matrix_data = NULL;
draw.texture = wimp->textures.white;
draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP;
menu_display_ctl(MENU_DISPLAY_CTL_DRAW, &draw);
menu_display_ctl(MENU_DISPLAY_CTL_BLEND_END, NULL);
}
static void wimp_draw_tab_begin(wimp_handle_t *wimp,
unsigned width, unsigned height,
float *white_bg, float *grey_bg)
{
float scale_factor;
menu_display_ctl(MENU_DISPLAY_CTL_GET_DPI, &scale_factor);
wimp->tabs_height = scale_factor / 3;
/* tabs background */
wimp_render_quad(wimp, 0, height - wimp->tabs_height, width,
wimp->tabs_height,
width, height,
white_bg);
/* tabs separator */
wimp_render_quad(wimp, 0, height - wimp->tabs_height, width,
1,
width, height,
grey_bg);
}
static void wimp_draw_tab_end(wimp_handle_t *wimp,
unsigned width, unsigned height,
unsigned header_height,
float *blue_bg)
{
/* active tab marker */
unsigned tab_width = width / (ZR_SYSTEM_TAB_END+1);
wimp_render_quad(wimp, wimp->categories.selection_ptr * tab_width,
height - (header_height/16),
tab_width,
header_height/16,
width, height,
&blue_bg[0]);
}
static void wimp_draw_scrollbar(wimp_handle_t *wimp,
unsigned width, unsigned height, float *coord_color)
{
unsigned header_height;
float content_height, total_height,
scrollbar_height, scrollbar_margin, y;
if (!wimp)
return;
menu_display_ctl(MENU_DISPLAY_CTL_HEADER_HEIGHT, &header_height);
content_height = menu_entries_get_end() * wimp->line_height;
total_height = height - header_height - wimp->tabs_height;
scrollbar_margin = wimp->scrollbar_width;
scrollbar_height = total_height / (content_height / total_height);
y = total_height * wimp->scroll_y / content_height;
/* apply a margin on the top and bottom of the scrollbar for aestetic */
scrollbar_height -= scrollbar_margin * 2;
y += scrollbar_margin;
if (content_height >= total_height)
{
/* if the scrollbar is extremely short, display it as a square */
if (scrollbar_height <= wimp->scrollbar_width)
scrollbar_height = wimp->scrollbar_width;
wimp_render_quad(wimp,
width - wimp->scrollbar_width - scrollbar_margin,
header_height + y,
wimp->scrollbar_width,
scrollbar_height,
width, height,
coord_color);
}
}
static void wimp_get_message(void *data, const char *message)
{
wimp_handle_t *wimp = (wimp_handle_t*)data;
@ -1231,42 +1026,6 @@ static void wimp_get_message(void *data, const char *message)
strlcpy(wimp->box_message, message, sizeof(wimp->box_message));
}
static void wimp_render_messagebox(const char *message)
{
unsigned i, width, height;
uint32_t normal_color;
int x, y, font_size;
settings_t *settings = config_get_ptr();
struct string_list *list = (struct string_list*)
string_split(message, "\n");
if (!list)
return;
if (list->elems == 0)
goto end;
video_driver_get_size(&width, &height);
menu_display_ctl(MENU_DISPLAY_CTL_FONT_SIZE, &font_size);
x = width / 2;
y = height / 2 - list->size * font_size / 2;
normal_color = FONT_COLOR_ARGB_TO_RGBA(settings->menu.entry_normal_color);
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
if (msg)
wimp_blit_line(x, y + i * font_size,
width, height,
msg, normal_color, TEXT_ALIGN_CENTER);
}
end:
string_list_free(list);
}
static void wimp_render(void *data)
{
size_t i = 0;
@ -1329,161 +1088,6 @@ static void wimp_render(void *data)
menu_entries_ctl(MENU_ENTRIES_CTL_SET_START, &i);
}
static void wimp_render_label_value(wimp_handle_t *wimp,
int y, unsigned width, unsigned height,
uint64_t index, uint32_t color, bool selected, const char *label,
const char *value, float *pure_white)
{
menu_animation_ctx_ticker_t ticker;
char label_str[PATH_MAX_LENGTH];
char value_str[PATH_MAX_LENGTH];
int value_len = strlen(value);
int ticker_limit = 0;
size_t usable_width = 0;
uintptr_t texture_switch = 0;
bool do_draw_text = false;
uint32_t hash_value = 0;
usable_width = width - (wimp->margin * 2);
if (value_len * wimp->glyph_width > usable_width / 2)
value_len = (usable_width/2) / wimp->glyph_width;
ticker_limit = (usable_width / wimp->glyph_width) - (value_len + 2);
ticker.s = label_str;
ticker.len = ticker_limit;
ticker.idx = index;
ticker.str = label;
ticker.selected = selected;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
ticker.s = value_str;
ticker.len = value_len;
ticker.str = value;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
wimp_blit_line(wimp->margin, y + wimp->line_height / 2,
width, height, label_str, color, TEXT_ALIGN_LEFT);
hash_value = menu_hash_calculate(value);
if (string_is_equal(value, "disabled") || string_is_equal(value, "off"))
{
if (wimp->textures.list[ZR_TEXTURE_SWITCH_OFF].id)
texture_switch = wimp->textures.list[ZR_TEXTURE_SWITCH_OFF].id;
else
do_draw_text = true;
}
else if (string_is_equal(value, "enabled") || string_is_equal(value, "on"))
{
if (wimp->textures.list[ZR_TEXTURE_SWITCH_ON].id)
texture_switch = wimp->textures.list[ZR_TEXTURE_SWITCH_ON].id;
else
do_draw_text = true;
}
else
{
switch (hash_value)
{
case MENU_VALUE_COMP:
break;
case MENU_VALUE_MORE:
break;
case MENU_VALUE_CORE:
break;
case MENU_VALUE_RDB:
break;
case MENU_VALUE_CURSOR:
break;
case MENU_VALUE_FILE:
break;
case MENU_VALUE_DIR:
break;
case MENU_VALUE_MUSIC:
break;
case MENU_VALUE_IMAGE:
break;
case MENU_VALUE_MOVIE:
break;
case MENU_VALUE_ON:
if (wimp->textures.list[ZR_TEXTURE_SWITCH_ON].id)
texture_switch = wimp->textures.list[ZR_TEXTURE_SWITCH_ON].id;
else
do_draw_text = true;
break;
case MENU_VALUE_OFF:
if (wimp->textures.list[ZR_TEXTURE_SWITCH_OFF].id)
texture_switch = wimp->textures.list[ZR_TEXTURE_SWITCH_OFF].id;
else
do_draw_text = true;
break;
default:
do_draw_text = true;
break;
}
}
if (do_draw_text)
wimp_blit_line(width - wimp->margin,
y + wimp->line_height / 2,
width, height, value_str, color, TEXT_ALIGN_RIGHT);
if (texture_switch)
wimp_draw_icon(wimp, texture_switch,
width - wimp->margin - wimp->icon_size, y,
width, height, 0, 1, &pure_white[0]);
}
static void wimp_render_menu_list(wimp_handle_t *wimp,
unsigned width, unsigned height,
uint32_t normal_color,
uint32_t hover_color,
float *pure_white)
{
unsigned header_height;
uint64_t *frame_count;
size_t i = 0;
size_t end = menu_entries_get_end();
video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count);
if (!menu_display_ctl(MENU_DISPLAY_CTL_UPDATE_PENDING, NULL))
return;
menu_display_ctl(MENU_DISPLAY_CTL_HEADER_HEIGHT, &header_height);
wimp->list_block.carr.coords.vertices = 0;
menu_entries_ctl(MENU_ENTRIES_CTL_START_GET, &i);
for (; i < end; i++)
{
int y;
size_t selection;
bool entry_selected;
menu_entry_t entry;
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
continue;
y = header_height - wimp->scroll_y + (wimp->line_height * i);
if ((y - (int)wimp->line_height) > (int)height
|| ((y + (int)wimp->line_height) < 0))
continue;
menu_entry_get(&entry, 0, i, NULL, true);
entry_selected = selection == i;
wimp_render_label_value(wimp, y, width, height, *frame_count / 20,
entry_selected ? hover_color : normal_color, entry_selected,
entry.path, entry.value, pure_white);
}
}
static void wimp_draw_cursor(wimp_handle_t *wimp,
float *color,
float x, float y, unsigned width, unsigned height)
@ -1533,307 +1137,24 @@ static size_t wimp_list_get_size(void *data, enum menu_list_type type)
return list_size;
}
static void bgcolor_setalpha(float *bg, float alpha)
{
bg[3] = alpha;
bg[7] = alpha;
bg[11] = alpha;
bg[15] = alpha;
}
static int wimp_get_core_title(char *s, size_t len)
{
struct retro_system_info *system = NULL;
rarch_system_info_t *info = NULL;
settings_t *settings = config_get_ptr();
const char *core_name = NULL;
const char *core_version = NULL;
menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_GET,
&system);
core_name = system->library_name;
core_version = system->library_version;
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info);
if (!settings->menu.core_enable)
return -1;
if (string_is_empty(core_name))
core_name = info->info.library_name;
if (string_is_empty(core_name))
core_name = menu_hash_to_str(MENU_VALUE_NO_CORE);
if (!core_version)
core_version = info->info.library_version;
if (!core_version)
core_version = "";
snprintf(s, len, "%s %s", core_name, core_version);
return 0;
}
static void wimp_frame(void *data)
{
unsigned header_height;
bool display_kb;
float black_bg[16] = {
0, 0, 0, 0.75,
0, 0, 0, 0.75,
0, 0, 0, 0.75,
0, 0, 0, 0.75,
};
float blue_bg[16] = {
0.13, 0.59, 0.95, 1,
0.13, 0.59, 0.95, 1,
0.13, 0.59, 0.95, 1,
0.13, 0.59, 0.95, 1,
};
float lightblue_bg[16] = {
0.89, 0.95, 0.99, 1.00,
0.89, 0.95, 0.99, 1.00,
0.89, 0.95, 0.99, 1.00,
0.89, 0.95, 0.99, 1.00,
};
float pure_white[16]= {
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
1, 1, 1, 1,
};
float white_bg[16]= {
0.98, 0.98, 0.98, 1,
0.98, 0.98, 0.98, 1,
0.98, 0.98, 0.98, 1,
0.98, 0.98, 0.98, 1,
};
float white_transp_bg[16]= {
0.98, 0.98, 0.98, 0.90,
0.98, 0.98, 0.98, 0.90,
0.98, 0.98, 0.98, 0.90,
0.98, 0.98, 0.98, 0.90,
};
float grey_bg[16]= {
0.78, 0.78, 0.78, 1,
0.78, 0.78, 0.78, 1,
0.78, 0.78, 0.78, 1,
0.78, 0.78, 0.78, 1,
};
float shadow_bg[16]= {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0.2,
0, 0, 0, 0.2,
};
menu_animation_ctx_ticker_t ticker;
unsigned width, height, ticker_limit, i;
char msg[256];
char title[256];
char title_buf[256];
char title_msg[256];
size_t selection;
size_t title_margin;
uint64_t *frame_count;
menu_display_ctx_draw_t draw;
wimp_handle_t *wimp = (wimp_handle_t*)data;
settings_t *settings = config_get_ptr();
const uint32_t normal_color = 0x212121ff;
const uint32_t hover_color = 0x212121ff;
const uint32_t title_color = 0xffffffff;
const uint32_t activetab_color = 0x0096f2ff;
const uint32_t passivetab_color = 0x9e9e9eff;
bool background_rendered = false;
bool libretro_running = menu_display_ctl(
MENU_DISPLAY_CTL_LIBRETRO_RUNNING, NULL);
video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count);
(void)passivetab_color;
(void)activetab_color;
if (!wimp)
return;
video_driver_get_size(&width, &height);
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
menu_display_ctl(MENU_DISPLAY_CTL_HEADER_HEIGHT, &header_height);
if (libretro_running)
{
memset(&draw, 0, sizeof(menu_display_ctx_draw_t));
draw.width = width;
draw.height = height;
draw.texture = wimp->textures.white;
draw.handle_alpha = 0.75f;
draw.force_transparency = false;
draw.color = &white_transp_bg[0];
draw.color2 = &white_bg[0];
draw.vertex = NULL;
draw.tex_coord = NULL;
draw.vertex_count = 4;
draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP;
menu_display_ctl(MENU_DISPLAY_CTL_DRAW_BG, &draw);
}
else
{
menu_display_ctx_clearcolor_t clearcolor;
clearcolor.r = 1.0f;
clearcolor.g = 1.0f;
clearcolor.b = 1.0f;
clearcolor.a = 0.75f;
menu_display_ctl(MENU_DISPLAY_CTL_CLEAR_COLOR, &clearcolor);
if (wimp->textures.bg.id)
{
background_rendered = true;
/* Set new opacity for transposed white background */
bgcolor_setalpha(white_transp_bg, 0.30);
memset(&draw, 0, sizeof(menu_display_ctx_draw_t));
draw.width = width;
draw.height = height;
draw.texture = wimp->textures.bg.id;
draw.handle_alpha = 0.75f;
draw.force_transparency = true;
draw.color = &white_transp_bg[0];
draw.color2 = &white_bg[0];
draw.vertex = NULL;
draw.tex_coord = NULL;
draw.vertex_count = 4;
draw.prim_type = MENU_DISPLAY_PRIM_TRIANGLESTRIP;
menu_display_ctl(MENU_DISPLAY_CTL_DRAW_BG, &draw);
/* Restore opacity of transposed white background */
bgcolor_setalpha(white_transp_bg, 0.90);
}
}
menu_entries_get_title(title, sizeof(title));
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
return;
if (background_rendered || libretro_running)
bgcolor_setalpha(lightblue_bg, 0.75);
else
bgcolor_setalpha(lightblue_bg, 1.0);
/* highlighted entry */
wimp_render_quad(wimp, 0,
header_height - wimp->scroll_y + wimp->line_height *
selection, width, wimp->line_height,
width, height,
&lightblue_bg[0]);
menu_display_ctl(MENU_DISPLAY_CTL_FONT_BIND_BLOCK, &wimp->list_block);
wimp_render_menu_list(wimp, width, height,
normal_color, hover_color, &pure_white[0]);
menu_display_ctl(MENU_DISPLAY_CTL_FONT_FLUSH_BLOCK, NULL);
menu_animation_ctl(MENU_ANIMATION_CTL_SET_ACTIVE, NULL);
/* header */
wimp_render_quad(wimp, 0, 0, width, header_height,
width, height, &blue_bg[0]);
wimp->tabs_height = 0;
/* display tabs if depth equal one, if not hide them */
if (wimp_list_get_size(wimp, MENU_LIST_PLAIN) == 1)
{
wimp_draw_tab_begin(wimp, width, height, &white_bg[0], &grey_bg[0]);
for (i = 0; i <= ZR_SYSTEM_TAB_END; i++)
wimp_draw_tab(wimp, i, width, height, &pure_white[0]);
wimp_draw_tab_end(wimp, width, height, header_height, &blue_bg[0]);
}
wimp_render_quad(wimp, 0, header_height, width,
wimp->shadow_height,
width, height,
&shadow_bg[0]);
title_margin = wimp->margin;
if (menu_entries_ctl(MENU_ENTRIES_CTL_SHOW_BACK, NULL))
{
title_margin = wimp->icon_size;
wimp_draw_icon(wimp, wimp->textures.list[ZR_TEXTURE_BACK].id,
0, 0, width, height, 0, 1, &pure_white[0]);
}
ticker_limit = (width - wimp->margin*2) / wimp->glyph_width;
ticker.s = title_buf;
ticker.len = ticker_limit;
ticker.idx = *frame_count / 100;
ticker.str = title;
ticker.selected = true;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
/* Title */
if (wimp_get_core_title(title_msg, sizeof(title_msg)) == 0)
{
char title_buf_msg_tmp[256];
char title_buf_msg[256];
size_t usable_width = width - (wimp->margin * 2);
int ticker_limit, value_len;
snprintf(title_buf_msg, sizeof(title_buf), "%s (%s)",
title_buf, title_msg);
value_len = strlen(title_buf);
ticker_limit = (usable_width / wimp->glyph_width) - (value_len + 2);
ticker.s = title_buf_msg_tmp;
ticker.len = ticker_limit;
ticker.idx = *frame_count / 20;
ticker.str = title_buf_msg;
ticker.selected = true;
menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker);
strlcpy(title_buf, title_buf_msg_tmp, sizeof(title_buf));
}
wimp_blit_line(title_margin, header_height / 2, width, height,
title_buf, title_color, TEXT_ALIGN_LEFT);
wimp_draw_scrollbar(wimp, width, height, &grey_bg[0]);
menu_input_ctl(MENU_INPUT_CTL_KEYBOARD_DISPLAY, &display_kb);
if (display_kb)
{
const char *str = NULL, *label = NULL;
menu_input_ctl(MENU_INPUT_CTL_KEYBOARD_BUFF_PTR, &str);
menu_input_ctl(MENU_INPUT_CTL_KEYBOARD_LABEL, &label);
if (!str)
str = "";
wimp_render_quad(wimp, 0, 0, width, height, width, height, &black_bg[0]);
snprintf(msg, sizeof(msg), "%s\n%s", label, str);
wimp_render_messagebox(msg);
}
if (!string_is_empty(wimp->box_message))
{
wimp_render_quad(wimp, 0, 0, width, height, width, height, &black_bg[0]);
wimp_render_messagebox(wimp->box_message);
wimp->box_message[0] = '\0';
}
menu_display_ctl(MENU_DISPLAY_CTL_SET_VIEWPORT, NULL);
zr_input_begin(&gui.ctx);
@ -1845,7 +1166,6 @@ static void wimp_frame(void *data)
zrmenu_frame(&gui, width, height);
zr_device_draw(&device, &gui.ctx, width, height, ZR_ANTI_ALIASING_ON);
/* zahnrad code */
if (settings->menu.mouse.enable && (settings->video.fullscreen
|| !video_driver_ctl(RARCH_DISPLAY_CTL_HAS_WINDOWED, NULL)))
{