RetroArch/menu/drivers/glui.c

861 lines
22 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - Daniel De Matteis
* Copyright (C) 2014-2015 - Jean-André Santoni
*
* 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/>.
*/
2015-01-26 09:54:13 +00:00
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
2015-01-10 03:53:37 +00:00
#include "../menu.h"
#include "../menu_display.h"
#include "../../runloop_data.h"
2014-10-21 22:23:06 +00:00
#include <file/file_path.h>
#include "../../gfx/video_thread_wrapper.h"
2015-04-09 02:57:17 +00:00
#include "../../gfx/drivers/gl_common.h"
#include "../../gfx/font_driver.h"
#include "../../gfx/video_texture.h"
2014-10-21 05:58:58 +00:00
#include <compat/posix_string.h>
#include "shared.h"
typedef struct glui_handle
{
unsigned line_height;
unsigned margin;
2015-04-04 19:26:11 +00:00
unsigned ticker_limit;
char box_message[PATH_MAX_LENGTH];
struct
{
void *buf;
int size;
} font;
struct
{
struct
{
GLuint id;
char path[PATH_MAX_LENGTH];
} bg;
} textures;
gl_font_raster_block_t list_block;
2015-03-26 17:07:39 +00:00
bool use_blocks;
} glui_handle_t;
static int glui_entry_iterate(unsigned action)
2015-01-26 09:54:13 +00:00
{
2015-04-09 03:57:34 +00:00
const char *label = NULL;
menu_file_list_cbs_t *cbs = NULL;
2015-04-09 03:57:34 +00:00
menu_handle_t *menu = menu_driver_get_ptr();
runloop_t *runloop = rarch_main_get_ptr();
if (!menu || !runloop)
return -1;
if (action != MENU_ACTION_NOOP || menu->need_refresh ||
runloop->frames.video.current.menu.label.is_updated ||
runloop->frames.video.current.menu.animation.is_active)
{
runloop->frames.video.current.menu.framebuf.dirty = true;
}
cbs = (menu_file_list_cbs_t*)menu_list_get_actiondata_at_offset(
2015-02-13 23:47:42 +00:00
menu->menu_list->selection_buf, menu->navigation.selection_ptr);
2015-01-26 09:54:13 +00:00
2015-02-11 18:28:06 +00:00
menu_list_get_last_stack(menu->menu_list, NULL, &label, NULL);
2015-01-26 09:54:13 +00:00
if (cbs && cbs->action_iterate)
return cbs->action_iterate(label, action);
return -1;
}
2015-04-21 14:59:02 +00:00
static void glui_blit_line(gl_t *gl, float x, float y,
const char *message, uint32_t color, enum text_alignment text_align)
{
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
glui = (glui_handle_t*)menu->userdata;
struct font_params params = {0};
2015-01-19 05:44:46 +00:00
params.x = x / gl->win_width;
2015-04-21 14:59:02 +00:00
params.y = 1.0f - (y + glui->line_height/2 + glui->font.size/3)
/ gl->win_height;
2015-01-19 05:44:46 +00:00
params.scale = 1.0;
2015-03-14 22:44:27 +00:00
params.color = color;
params.full_screen = true;
2015-04-04 19:26:11 +00:00
params.text_align = text_align;
2015-01-19 05:44:46 +00:00
video_driver_set_osd_msg(message, &params, glui->font.buf);
}
static void glui_render_background(settings_t *settings, gl_t *gl,
glui_handle_t *glui)
{
static const GLfloat vertex[] = {
0, 0,
1, 0,
0, 1,
1, 1,
};
static const GLfloat tex_coord[] = {
0, 1,
1, 1,
0, 0,
1, 0,
};
struct gl_coords coords;
float alpha = 0.75f;
GLfloat color[] = {
1.0f, 1.0f, 1.0f, alpha,
1.0f, 1.0f, 1.0f, alpha,
1.0f, 1.0f, 1.0f, alpha,
1.0f, 1.0f, 1.0f, alpha,
};
GLfloat black_color[] = {
0.0f, 0.0f, 0.0f, alpha,
0.0f, 0.0f, 0.0f, alpha,
0.0f, 0.0f, 0.0f, alpha,
0.0f, 0.0f, 0.0f, alpha,
};
2015-03-21 04:42:49 +00:00
global_t *global = global_get_ptr();
glViewport(0, 0, gl->win_width, gl->win_height);
coords.vertices = 4;
coords.vertex = vertex;
coords.tex_coord = tex_coord;
coords.lut_tex_coord = tex_coord;
2015-03-20 21:22:06 +00:00
if ((settings->menu.pause_libretro
2015-03-21 04:42:49 +00:00
|| !global->main_is_init || global->libretro_dummy)
&& glui->textures.bg.id)
{
coords.color = color;
glBindTexture(GL_TEXTURE_2D, glui->textures.bg.id);
}
else
{
coords.color = black_color;
glBindTexture(GL_TEXTURE_2D, 0);
}
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
gl->shader->set_coords(&coords);
gl->shader->set_mvp(gl, &gl->mvp_no_rot);
glEnable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_BLEND);
gl->coords.color = gl->white_color_ptr;
}
2015-04-04 19:26:11 +00:00
static void glui_render_quad(gl_t *gl, int x, int y, int w, int h,
float r, float g, float b, float a)
2014-10-26 23:55:14 +00:00
{
static const GLfloat vertex[] = {
0, 0,
1, 0,
0, 1,
1, 1,
};
static const GLfloat tex_coord[] = {
0, 1,
1, 1,
0, 0,
1, 0,
};
2015-04-04 19:26:11 +00:00
struct gl_coords coords;
GLfloat color[] = {
2015-04-04 19:26:11 +00:00
r, g, b, a,
r, g, b, a,
r, g, b, a,
r, g, b, a,
};
2014-10-26 23:55:14 +00:00
2015-04-04 19:26:11 +00:00
glViewport(x, gl->win_height - y - h, w, h);
2014-10-26 23:55:14 +00:00
coords.vertices = 4;
coords.vertex = vertex;
coords.tex_coord = tex_coord;
2014-10-26 23:55:14 +00:00
coords.lut_tex_coord = tex_coord;
coords.color = color;
glBindTexture(GL_TEXTURE_2D, 0);
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
gl->shader->set_coords(&coords);
gl->shader->set_mvp(gl, &gl->mvp_no_rot);
glEnable(GL_BLEND);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_BLEND);
gl->coords.color = gl->white_color_ptr;
}
2015-04-04 19:26:11 +00:00
static void glui_draw_cursor(gl_t *gl, float x, float y)
{
glui_render_quad(gl, x-5, y-5, 10, 10, 1, 1, 1, 1);
}
2015-04-21 02:47:02 +00:00
static void glui_draw_scrollbar(gl_t *gl)
{
2015-04-21 14:59:02 +00:00
float content_height, total_height, height, y;
2015-04-21 02:47:02 +00:00
int width = 4;
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
2015-04-21 14:59:02 +00:00
glui = (glui_handle_t*)menu->userdata;
content_height = menu_list_get_size(menu->menu_list)
* glui->line_height;
total_height = gl->win_height - menu->header_height * 2;
height = total_height / (content_height / total_height);
y = total_height * menu->scroll_y / content_height;
2015-04-21 02:47:02 +00:00
if (content_height < total_height)
return;
glui_render_quad(gl,
gl->win_width - width,
menu->header_height + y,
width,
height,
1, 1, 1, 1);
}
static void glui_get_message(const char *message)
2014-09-15 10:36:52 +00:00
{
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
2014-09-15 10:36:52 +00:00
if (!menu)
return;
if (!message || !*message)
2014-09-15 10:36:52 +00:00
return;
glui = (glui_handle_t*)menu->userdata;
2015-02-02 17:51:48 +00:00
if (glui)
strlcpy(glui->box_message, message, sizeof(glui->box_message));
2014-09-15 10:36:52 +00:00
}
static void glui_render_messagebox(const char *message)
{
unsigned i;
2015-03-16 15:57:27 +00:00
uint32_t normal_color;
int x, y;
struct string_list *list = NULL;
glui_handle_t *glui = NULL;
gl_t *gl = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
2015-03-20 21:22:06 +00:00
settings_t *settings = config_get_ptr();
2014-09-15 10:36:52 +00:00
if (!menu)
return;
gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
2014-09-15 10:36:52 +00:00
return;
glui = (glui_handle_t*)menu->userdata;
if (!glui)
return;
list = (struct string_list*)string_split(message, "\n");
2014-09-15 10:36:52 +00:00
if (!list)
return;
2014-09-15 10:36:52 +00:00
if (list->elems == 0)
2015-02-02 17:51:48 +00:00
goto end;
2014-09-15 10:36:52 +00:00
2015-04-04 19:26:11 +00:00
x = gl->win_width / 2;
y = gl->win_height / 2 - list->size * glui->font.size / 2;
2015-03-20 21:22:06 +00:00
normal_color = FONT_COLOR_ARGB_TO_RGBA(settings->menu.entry_normal_color);
2014-09-15 10:36:52 +00:00
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
2015-02-02 17:51:48 +00:00
if (msg)
glui_blit_line(gl, x, y + i * glui->font.size, msg, normal_color, TEXT_ALIGN_CENTER);
2014-09-15 10:36:52 +00:00
}
2015-02-02 17:51:48 +00:00
end:
2014-09-15 10:36:52 +00:00
string_list_free(list);
}
static void glui_render(void)
{
2015-04-04 19:26:11 +00:00
int bottom;
glui_handle_t *glui = NULL;
gl_t *gl = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
2015-03-20 21:22:06 +00:00
settings_t *settings = config_get_ptr();
if (!menu)
return;
glui = (glui_handle_t*)menu->userdata;
if (!glui)
return;
gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return;
2015-04-20 14:22:55 +00:00
menu_animation_update(menu->animation, menu->dt / IDEAL_DT);
menu->frame_buf.width = gl->win_width;
menu->frame_buf.height = gl->win_height;
2015-04-04 19:26:11 +00:00
if (settings->menu.pointer.enable)
{
menu->pointer.ptr =
(menu->pointer.y - glui->line_height + menu->scroll_y - 16)
/ glui->line_height;
if (menu->pointer.dragging)
menu->scroll_y -= menu->pointer.dy;
}
if (settings->menu.mouse.enable)
{
if (menu->mouse.scrolldown)
menu->scroll_y += 10;
2014-10-26 23:55:14 +00:00
2015-04-04 19:26:11 +00:00
if (menu->mouse.scrollup)
menu->scroll_y -= 10;
2015-04-04 19:26:11 +00:00
menu->mouse.ptr =
(menu->mouse.y - glui->line_height + menu->scroll_y - 16)
/ glui->line_height;
}
2015-04-04 19:26:11 +00:00
if (menu->scroll_y < 0)
menu->scroll_y = 0;
bottom = menu_list_get_size(menu->menu_list) * glui->line_height
2015-04-04 19:26:11 +00:00
- gl->win_height + menu->header_height * 2;
if (menu->scroll_y > bottom)
menu->scroll_y = bottom;
if (menu_list_get_size(menu->menu_list) * glui->line_height
2015-04-04 19:26:11 +00:00
< gl->win_height - menu->header_height*2)
menu->scroll_y = 0;
}
2015-04-21 14:59:02 +00:00
static void glui_render_menu_list(runloop_t *runloop,
gl_t *gl, glui_handle_t *glui, menu_handle_t *menu,
const char *label, uint32_t normal_color,
uint32_t hover_color)
{
size_t i = 0;
2015-04-21 14:59:02 +00:00
const struct font_renderer *font_driver = (const struct font_renderer *)
gl->font_driver;
if (glui->use_blocks)
font_driver->bind_block(gl->font_handle, &glui->list_block);
if (!menu_display_update_pending())
goto draw_text;
glui->list_block.carr.coords.vertices = 0;
for (i = 0; i < menu_list_get_size(menu->menu_list); i++)
{
2015-04-21 14:59:02 +00:00
unsigned y;
char message[PATH_MAX_LENGTH], type_str[PATH_MAX_LENGTH],
2015-04-21 14:59:02 +00:00
entry_title_buf[PATH_MAX_LENGTH], type_str_buf[PATH_MAX_LENGTH],
path_buf[PATH_MAX_LENGTH];
const char *path = NULL;
const char *entry_label = NULL;
unsigned type = 0;
unsigned w = 0;
bool selected = false;
menu_file_list_cbs_t *cbs = NULL;
menu_list_get_at_offset(menu->menu_list->selection_buf, i, &path,
&entry_label, &type);
cbs = (menu_file_list_cbs_t*)
2015-04-21 14:59:02 +00:00
menu_list_get_actiondata_at_offset(
menu->menu_list->selection_buf, i);
if (cbs && cbs->action_get_representation)
cbs->action_get_representation(menu->menu_list->selection_buf,
2015-04-21 14:59:02 +00:00
&w, type, i, label, type_str, sizeof(type_str),
entry_label, path, path_buf, sizeof(path_buf));
selected = (i == menu->navigation.selection_ptr);
menu_animation_ticker_line(entry_title_buf, glui->ticker_limit,
runloop->frames.video.count / 100, path_buf, selected);
menu_animation_ticker_line(type_str_buf, glui->ticker_limit,
runloop->frames.video.count / 100, type_str, selected);
strlcpy(message, entry_title_buf, sizeof(message));
2015-04-21 14:59:02 +00:00
y = menu->header_height - menu->scroll_y + (glui->line_height * i);
glui_blit_line(gl, glui->margin, y, message,
selected ? hover_color : normal_color, TEXT_ALIGN_LEFT);
glui_blit_line(gl, gl->win_width - glui->margin, y, type_str_buf,
selected ? hover_color : normal_color, TEXT_ALIGN_RIGHT);
}
draw_text:
if (glui->use_blocks)
{
font_driver->flush(gl->font_handle);
font_driver->bind_block(gl->font_handle, NULL);
}
}
static void glui_frame(void)
{
2015-04-21 14:59:02 +00:00
char title[PATH_MAX_LENGTH], title_buf[PATH_MAX_LENGTH],
title_msg[PATH_MAX_LENGTH], timedate[PATH_MAX_LENGTH];
const char *dir = NULL;
const char *label = NULL;
unsigned menu_type = 0;
gl_t *gl = NULL;
glui_handle_t *glui = NULL;
const char *core_name = NULL;
const char *core_version = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
settings_t *settings = config_get_ptr();
const uint32_t normal_color = FONT_COLOR_ARGB_TO_RGBA(
settings->menu.entry_normal_color);
const uint32_t hover_color = FONT_COLOR_ARGB_TO_RGBA(
settings->menu.entry_hover_color);
const uint32_t title_color = FONT_COLOR_ARGB_TO_RGBA(
settings->menu.title_color);
runloop_t *runloop = rarch_main_get_ptr();
global_t *global = global_get_ptr();
if (!menu)
return;
gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return;
glui = (glui_handle_t*)menu->userdata;
if (!glui)
return;
if (menu->need_refresh
2015-03-18 05:47:22 +00:00
&& runloop->is_menu
&& !menu->msg_force)
return;
2015-03-26 17:07:39 +00:00
gl_set_viewport(gl, gl->win_width, gl->win_height, true, false);
glui_render_background(settings, gl, glui);
menu_list_get_last_stack(menu->menu_list, &dir, &label, &menu_type);
get_title(label, dir, menu_type, title, sizeof(title));
2015-04-04 19:26:11 +00:00
glui_render_quad(gl, 0,
menu->header_height - menu->scroll_y + glui->line_height *
menu->navigation.selection_ptr,
2015-04-04 19:26:11 +00:00
gl->win_width, glui->line_height, 1, 1, 1, 0.1);
2015-04-21 14:59:02 +00:00
glui_render_menu_list(runloop, gl, glui, menu,
label, normal_color, hover_color);
runloop->frames.video.current.menu.animation.is_active = true;
runloop->frames.video.current.menu.label.is_updated = false;
runloop->frames.video.current.menu.framebuf.dirty = false;
2015-04-04 19:26:11 +00:00
glui_render_quad(gl, 0, 0, gl->win_width,
menu->header_height, 0.2, 0.2, 0.2, 1);
2015-04-04 19:26:11 +00:00
menu_animation_ticker_line(title_buf, glui->ticker_limit,
runloop->frames.video.count / 100, title, true);
2015-04-21 14:59:02 +00:00
glui_blit_line(gl, gl->win_width/2, 0, title_buf,
title_color, TEXT_ALIGN_CENTER);
2015-04-04 19:26:11 +00:00
if (file_list_get_size(menu->menu_list->menu_stack) > 1)
2015-04-21 14:59:02 +00:00
glui_blit_line(gl, glui->margin, 0, "BACK",
title_color, TEXT_ALIGN_LEFT);
2015-04-04 19:26:11 +00:00
glui_render_quad(gl, 0,
gl->win_height - menu->header_height,
gl->win_width, menu->header_height,
2015-04-04 19:26:11 +00:00
0.2, 0.2, 0.2, 1);
2015-04-21 02:47:02 +00:00
glui_draw_scrollbar(gl);
2015-04-04 19:26:11 +00:00
core_name = global->menu.info.library_name;
if (!core_name)
core_name = global->system.info.library_name;
if (!core_name)
core_name = "No Core";
if (settings->menu.core_enable)
{
core_version = global->menu.info.library_version;
if (!core_version)
core_version = global->system.info.library_version;
if (!core_version)
core_version = "";
2015-04-21 14:59:02 +00:00
snprintf(title_msg, sizeof(title_msg),
"%s - %s %s", PACKAGE_VERSION,
2015-04-04 19:26:11 +00:00
core_name, core_version);
2015-04-21 14:59:02 +00:00
glui_blit_line(gl, glui->margin,
gl->win_height - glui->line_height, title_msg,
2015-04-04 19:26:11 +00:00
title_color, TEXT_ALIGN_LEFT);
}
if (settings->menu.timedate_enable)
{
disp_timedate_set_label(timedate, sizeof(timedate), 0);
glui_blit_line(gl, gl->win_width - glui->margin,
gl->win_height - glui->line_height, timedate, hover_color,
TEXT_ALIGN_RIGHT);
}
if (menu->keyboard.display)
{
char msg[PATH_MAX_LENGTH];
const char *str = *menu->keyboard.buffer;
if (!str)
str = "";
glui_render_quad(gl, 0, 0, gl->win_width, gl->win_height, 0, 0, 0, 0.75);
snprintf(msg, sizeof(msg), "%s\n%s", menu->keyboard.label, str);
glui_render_messagebox(msg);
}
if (glui->box_message[0] != '\0')
2014-09-15 10:36:52 +00:00
{
glui_render_quad(gl, 0, 0, gl->win_width, gl->win_height, 0, 0, 0, 0.75);
glui_render_messagebox(glui->box_message);
glui->box_message[0] = '\0';
2014-09-15 10:36:52 +00:00
}
2015-03-27 19:17:11 +00:00
if (settings->menu.mouse.enable)
glui_draw_cursor(gl, menu->mouse.x, menu->mouse.y);
2015-03-01 16:50:40 +00:00
gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
}
static void *glui_init(void)
{
2015-04-21 14:59:02 +00:00
float dpi;
glui_handle_t *glui = NULL;
const video_driver_t *video_driver = NULL;
const struct font_renderer *font_driver = NULL;
2015-04-21 14:59:02 +00:00
menu_handle_t *menu = NULL;
settings_t *settings = config_get_ptr();
gl_t *gl = (gl_t*)
video_driver_get_ptr(&video_driver);
if (video_driver != &video_gl || !gl)
{
RARCH_ERR("Cannot initialize GLUI menu driver: gl video driver is not active.\n");
return NULL;
}
2015-04-21 14:59:02 +00:00
font_driver = (const struct font_renderer*)gl->font_driver;
menu = (menu_handle_t*)calloc(1, sizeof(*menu));
if (!menu)
2015-02-02 17:51:48 +00:00
goto error;
2015-04-21 14:59:02 +00:00
menu->userdata = (glui_handle_t*)calloc(1, sizeof(glui_handle_t));
if (!menu->userdata)
2015-02-02 17:51:48 +00:00
goto error;
2015-04-21 14:59:02 +00:00
glui = (glui_handle_t*)menu->userdata;
dpi = menu_display_get_dpi(menu);
2015-04-21 13:45:03 +00:00
glui->line_height = dpi / 3;
glui->margin = dpi / 6;
glui->ticker_limit = dpi / 3;
menu->header_height = dpi / 3;
glui->font.size = dpi / 8;
glui->textures.bg.id = 0;
2015-03-28 19:50:51 +00:00
if (font_driver->bind_block && font_driver->flush)
2015-04-21 14:59:02 +00:00
glui->use_blocks = true;
2015-03-26 17:07:39 +00:00
2015-04-21 14:59:02 +00:00
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE,
settings->menu.wallpaper, "cb_menu_wallpaper", 0, 1, true);
return menu;
2015-02-02 17:51:48 +00:00
error:
if (menu)
free(menu);
return NULL;
}
static void glui_free(void *data)
{
2015-04-21 14:59:02 +00:00
gl_t *gl = NULL;
const struct font_renderer *font_driver = NULL;
2015-04-21 14:59:02 +00:00
menu_handle_t *menu = (menu_handle_t*)data;
glui_handle_t *glui = (glui_handle_t*)menu->userdata;
2015-04-21 14:59:02 +00:00
if (!glui || !menu)
return;
gl_coord_array_free(&glui->list_block.carr);
2015-04-21 14:59:02 +00:00
gl = (gl_t*)video_driver_get_ptr(NULL);
2015-03-28 19:50:51 +00:00
2015-04-21 14:59:02 +00:00
font_driver = gl ? (const struct font_renderer*)gl->font_driver : NULL;
if (glui->use_blocks && font_driver)
2015-03-28 19:50:51 +00:00
font_driver->bind_block(gl->font_handle, NULL);
if (menu->alloc_font)
free((uint8_t*)menu->font);
if (menu->userdata)
free(menu->userdata);
}
static void glui_context_destroy(void)
{
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
glui = (glui_handle_t*)menu->userdata;
if (!glui)
return;
if (glui->textures.bg.id)
glDeleteTextures(1, &glui->textures.bg.id);
}
static bool glui_load_wallpaper(void *data)
{
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return false;
glui = (glui_handle_t*)menu->userdata;
if (!glui)
return false;
if (glui->textures.bg.id)
glDeleteTextures(1, &glui->textures.bg.id);
glui->textures.bg.id = video_texture_load(data,
TEXTURE_BACKEND_OPENGL, TEXTURE_FILTER_MIPMAP_LINEAR);
return true;
}
static float glui_get_scroll()
2014-10-26 23:55:14 +00:00
{
2015-04-21 14:59:02 +00:00
int half;
2014-10-26 23:55:14 +00:00
glui_handle_t *glui = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
2015-04-21 14:59:02 +00:00
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
2014-10-26 23:55:14 +00:00
if (!menu)
return 0;
2015-04-21 14:59:02 +00:00
2014-10-26 23:55:14 +00:00
glui = (glui_handle_t*)menu->userdata;
if (!glui)
return 0;
2014-10-26 23:55:14 +00:00
2015-04-21 14:59:02 +00:00
half = (gl->win_height / glui->line_height) / 2;
2015-04-04 19:26:11 +00:00
if (menu->navigation.selection_ptr < half)
return 0;
2015-04-21 14:59:02 +00:00
return ((menu->navigation.selection_ptr + 2 - half) * glui->line_height);
}
static void glui_navigation_set(bool scroll)
{
menu_handle_t *menu = menu_driver_get_ptr();
2015-04-20 14:22:55 +00:00
2015-04-21 14:59:02 +00:00
if (!menu || !scroll)
return;
menu_animation_push(menu->animation, 10, glui_get_scroll(),
2015-04-20 14:22:55 +00:00
&menu->scroll_y, EASING_IN_OUT_QUAD, NULL);
2014-10-26 23:55:14 +00:00
}
static void glui_navigation_clear(bool pending_push)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
2015-04-21 14:59:02 +00:00
menu->begin = 0;
menu->scroll_y = 0;
}
static void glui_navigation_set_last(void)
{
glui_navigation_set(true);
}
static void glui_navigation_descend_alphabet(size_t *unused)
{
glui_navigation_set(true);
}
static void glui_navigation_ascend_alphabet(size_t *unused)
{
glui_navigation_set(true);
}
static void glui_populate_entries(const char *path,
const char *label, unsigned i)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
2015-04-21 14:59:02 +00:00
menu->scroll_y = glui_get_scroll();
}
static bool glui_font_init_first(const void **font_driver,
void **font_handle, void *video_data, const char *font_path,
float font_size)
{
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
if (settings->video.threaded
&& !global->system.hw_render_callback.context_type)
{
driver_t *driver = driver_get_ptr();
2015-04-21 14:59:02 +00:00
thread_video_t *thr = driver ? (thread_video_t*)driver->video_data : NULL;
if (!thr)
return false;
thr->cmd_data.font_init.method = font_init_first;
thr->cmd_data.font_init.font_driver = (const void**)font_driver;
thr->cmd_data.font_init.font_handle = font_handle;
2015-04-21 14:59:02 +00:00
thr->cmd_data.font_init.video_data = video_data;
thr->cmd_data.font_init.font_path = font_path;
thr->cmd_data.font_init.font_size = font_size;
thr->cmd_data.font_init.api = FONT_DRIVER_RENDER_OPENGL_API;
2015-04-21 14:59:02 +00:00
thr->send_cmd_func(thr, CMD_FONT_INIT);
thr->wait_reply_func(thr, CMD_FONT_INIT);
return thr->cmd_data.font_init.return_value;
}
return font_init_first(font_driver, font_handle, video_data,
font_path, font_size, FONT_DRIVER_RENDER_OPENGL_API);
}
static void glui_context_reset(void)
{
2015-04-21 14:59:02 +00:00
gl_t *gl = NULL;
glui_handle_t *glui = NULL;
const font_renderer_driver_t *font_drv = NULL;
2015-04-21 14:59:02 +00:00
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
2015-04-21 14:59:02 +00:00
glui = (glui_handle_t*)menu->userdata;
if (!glui)
return;
2015-04-21 14:59:02 +00:00
gl = (gl_t*)video_driver_get_ptr(NULL);
if (!gl)
return;
font_drv = (const font_renderer_driver_t *)gl->font_driver;
glui_font_init_first(&gl->font_driver,
&glui->font.buf,
gl,
NULL,
2015-04-21 14:59:02 +00:00
glui->font.size);
}
2014-09-11 05:06:20 +00:00
menu_ctx_driver_t menu_ctx_glui = {
NULL,
2014-09-15 10:36:52 +00:00
glui_get_message,
glui_render,
glui_frame,
glui_init,
glui_free,
glui_context_reset,
glui_context_destroy,
glui_populate_entries,
NULL,
2014-10-26 23:55:14 +00:00
glui_navigation_clear,
NULL,
NULL,
2014-10-26 23:55:14 +00:00
glui_navigation_set,
glui_navigation_set_last,
glui_navigation_descend_alphabet,
glui_navigation_ascend_alphabet,
NULL,
NULL,
NULL,
NULL,
NULL,
2015-01-26 09:54:13 +00:00
glui_entry_iterate,
glui_load_wallpaper,
"glui",
};