2014-02-26 20:10:17 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
|
|
|
* Copyright (C) 2012-2014 - Michael Lelli
|
2014-05-09 15:55:39 +00:00
|
|
|
* Copyright (C) 2014 - Jean-André Santoni
|
2014-02-26 20:10:17 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2014-04-25 23:53:40 +00:00
|
|
|
#include "../backend/menu_common_backend.h"
|
2014-02-26 20:10:17 +00:00
|
|
|
#include "../menu_common.h"
|
2014-03-01 10:41:00 +00:00
|
|
|
#include "../file_list.h"
|
2014-02-26 20:10:17 +00:00
|
|
|
#include "../../../general.h"
|
|
|
|
#include "../../../gfx/gfx_common.h"
|
|
|
|
#include "../../../gfx/gl_common.h"
|
|
|
|
#include "../../../gfx/shader_common.h"
|
|
|
|
#include "../../../config.def.h"
|
|
|
|
#include "../../../file.h"
|
|
|
|
#include "../../../dynamic.h"
|
|
|
|
#include "../../../compat/posix_string.h"
|
|
|
|
#include "../../../gfx/shader_parse.h"
|
|
|
|
#include "../../../performance.h"
|
|
|
|
#include "../../../input/input_common.h"
|
|
|
|
|
|
|
|
#include "../../../screenshot.h"
|
|
|
|
#include "../../../gfx/fonts/bitmap.h"
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
#include "lakka.h"
|
2014-05-26 16:40:27 +00:00
|
|
|
#include <png.h>
|
2014-05-07 18:12:51 +00:00
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
// Category variables
|
2014-05-27 00:02:39 +00:00
|
|
|
menu_category_t *categories;
|
2014-05-07 18:12:51 +00:00
|
|
|
int depth = 0;
|
|
|
|
int num_categories = 0;
|
|
|
|
int menu_active_category = 0;
|
2014-02-26 20:10:17 +00:00
|
|
|
int dim = 192;
|
2014-05-07 18:12:51 +00:00
|
|
|
float all_categories_x = 0;
|
2014-06-03 09:54:48 +00:00
|
|
|
float global_alpha = 0;
|
2014-05-07 18:12:51 +00:00
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
// Font variables
|
2014-05-07 18:12:51 +00:00
|
|
|
void *font;
|
|
|
|
const gl_font_renderer_t *font_ctx;
|
|
|
|
const font_renderer_driver_t *font_driver;
|
|
|
|
GLuint font_tex;
|
|
|
|
GLint max_font_size;
|
|
|
|
int font_tex_w, font_tex_h;
|
|
|
|
uint32_t *font_tex_buf;
|
|
|
|
char font_last_msg[256];
|
|
|
|
int font_last_width, font_last_height;
|
2014-05-10 04:21:03 +00:00
|
|
|
struct font_output_list run_label;
|
|
|
|
struct font_output_list resume_label;
|
|
|
|
|
|
|
|
//GL-specific variables
|
2014-05-07 18:12:51 +00:00
|
|
|
GLfloat font_color[16];
|
|
|
|
GLfloat font_color_dark[16];
|
|
|
|
GLuint texture;
|
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
GLuint settings_icon;
|
2014-06-02 14:34:17 +00:00
|
|
|
GLuint setting_icon;
|
|
|
|
GLuint subsetting_icon;
|
2014-05-10 04:21:03 +00:00
|
|
|
GLuint arrow_icon;
|
|
|
|
GLuint run_icon;
|
|
|
|
GLuint resume_icon;
|
|
|
|
GLuint savestate_icon;
|
|
|
|
GLuint loadstate_icon;
|
|
|
|
GLuint screenshot_icon;
|
|
|
|
GLuint reload_icon;
|
|
|
|
|
2014-05-26 23:31:27 +00:00
|
|
|
static tween_t* tweens = NULL;
|
2014-05-26 16:32:32 +00:00
|
|
|
int numtweens = 0;
|
|
|
|
|
2014-05-31 23:08:39 +00:00
|
|
|
static char *str_replace (const char *string, const char *substr, const char *replacement)
|
|
|
|
{
|
|
|
|
char *tok, *newstr, *oldstr, *head;
|
|
|
|
|
|
|
|
/* if either substr or replacement is NULL, duplicate string a let caller handle it */
|
|
|
|
if (!substr || !replacement)
|
|
|
|
return strdup (string);
|
|
|
|
|
|
|
|
newstr = strdup (string);
|
|
|
|
head = newstr;
|
|
|
|
while ( (tok = strstr ( head, substr )))
|
|
|
|
{
|
|
|
|
oldstr = newstr;
|
|
|
|
newstr = (char*)malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
|
|
|
|
|
|
|
|
if (!newstr)
|
|
|
|
{
|
|
|
|
/*failed to alloc mem, free old string and return NULL */
|
|
|
|
free (oldstr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy ( newstr, oldstr, tok - oldstr );
|
|
|
|
memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) );
|
|
|
|
memcpy ( newstr + (tok - oldstr) + strlen( replacement ), tok + strlen ( substr ), strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) );
|
|
|
|
memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + strlen ( replacement ) , 0, 1 );
|
|
|
|
/* move back head right after the last replacement */
|
|
|
|
head = newstr + (tok - oldstr) + strlen( replacement );
|
|
|
|
free (oldstr);
|
|
|
|
}
|
|
|
|
return newstr;
|
|
|
|
}
|
|
|
|
|
2014-06-03 09:54:48 +00:00
|
|
|
float inOutQuad(float t, float b, float c, float d)
|
2014-05-26 16:32:32 +00:00
|
|
|
{
|
|
|
|
t = t / d * 2;
|
|
|
|
if (t < 1)
|
|
|
|
return c / 2 * pow(t, 2) + b;
|
|
|
|
return -c / 2 * ((t - 1) * (t - 3) - 1) + b;
|
|
|
|
}
|
|
|
|
|
2014-06-03 09:54:48 +00:00
|
|
|
void add_tween(float duration, float target_value, float* subject, easingFunc easing, tweenCallback callback)
|
2014-05-26 16:32:32 +00:00
|
|
|
{
|
2014-05-27 04:32:33 +00:00
|
|
|
tween_t *tween;
|
|
|
|
|
2014-05-26 16:32:32 +00:00
|
|
|
numtweens++;
|
2014-05-26 23:31:27 +00:00
|
|
|
|
2014-05-27 04:32:33 +00:00
|
|
|
tweens = (tween_t*)realloc(tweens, numtweens * sizeof(tween_t));
|
|
|
|
tween = (tween_t*)&tweens[numtweens-1];
|
2014-05-26 23:31:27 +00:00
|
|
|
|
|
|
|
if (!tween)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tween->alive = 1;
|
|
|
|
tween->duration = duration;
|
|
|
|
tween->running_since = 0;
|
|
|
|
tween->initial_value = *subject;
|
|
|
|
tween->target_value = target_value;
|
|
|
|
tween->subject = subject;
|
|
|
|
tween->easing = easing;
|
2014-06-03 09:54:48 +00:00
|
|
|
tween->callback = callback;
|
2014-05-26 16:32:32 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 23:31:27 +00:00
|
|
|
static void update_tween(void *data, float dt)
|
2014-05-26 16:32:32 +00:00
|
|
|
{
|
2014-05-26 23:31:27 +00:00
|
|
|
tween_t *tween = (tween_t*)data;
|
|
|
|
|
2014-05-27 01:06:58 +00:00
|
|
|
if (!tween)
|
|
|
|
return;
|
|
|
|
|
2014-05-27 01:48:08 +00:00
|
|
|
#if 0
|
|
|
|
RARCH_LOG("delta: %f\n", dt);
|
|
|
|
RARCH_LOG("tween running since: %f\n", tween->running_since);
|
|
|
|
RARCH_LOG("tween duration: %f\n", tween->duration);
|
|
|
|
#endif
|
|
|
|
|
2014-05-26 23:31:27 +00:00
|
|
|
if (tween->running_since < tween->duration)
|
2014-05-26 16:32:32 +00:00
|
|
|
{
|
2014-05-26 23:31:27 +00:00
|
|
|
tween->running_since += dt;
|
|
|
|
*tween->subject = tween->easing(
|
|
|
|
tween->running_since,
|
|
|
|
tween->initial_value,
|
|
|
|
tween->target_value - tween->initial_value,
|
|
|
|
tween->duration);
|
2014-06-03 09:54:48 +00:00
|
|
|
if (tween->running_since >= tween->duration) {
|
2014-05-26 23:31:27 +00:00
|
|
|
*tween->subject = tween->target_value;
|
2014-06-03 09:54:48 +00:00
|
|
|
if (tween->callback)
|
|
|
|
tween->callback();
|
|
|
|
}
|
2014-05-26 16:32:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_tweens(float dt)
|
|
|
|
{
|
|
|
|
int i, active_tweens;
|
|
|
|
|
|
|
|
active_tweens = 0;
|
|
|
|
for(i = 0; i < numtweens; i++)
|
|
|
|
{
|
2014-05-26 23:31:27 +00:00
|
|
|
update_tween(&tweens[i], dt);
|
2014-05-26 16:32:32 +00:00
|
|
|
active_tweens += tweens[i].running_since < tweens[i].duration ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numtweens && !active_tweens)
|
|
|
|
numtweens = 0;
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
struct font_rect
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
int x, y;
|
|
|
|
int width, height;
|
|
|
|
int pot_width, pot_height;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* font rendering */
|
|
|
|
|
2014-05-31 23:08:39 +00:00
|
|
|
#if 0
|
|
|
|
static void deinit_font(void *data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
if (font)
|
|
|
|
{
|
|
|
|
if (font_driver)
|
|
|
|
font_driver->free(font);
|
|
|
|
font_driver = NULL;
|
|
|
|
|
|
|
|
glDeleteTextures(1, &font_tex);
|
|
|
|
|
|
|
|
if (font_tex_buf)
|
|
|
|
free(font_tex_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
static bool init_font(void *data, const char *font_path, float font_size, unsigned win_width, unsigned win_height)
|
|
|
|
{
|
|
|
|
size_t i, j;
|
2014-05-10 04:21:03 +00:00
|
|
|
gl_t *gl = (gl_t*)data;
|
2014-05-07 18:12:51 +00:00
|
|
|
(void)win_width;
|
|
|
|
(void)win_height;
|
2014-05-10 04:21:03 +00:00
|
|
|
(void)font_size;
|
2014-05-07 18:12:51 +00:00
|
|
|
|
|
|
|
if (!g_settings.video.font_enable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (font_renderer_create_default(&font_driver, &font))
|
|
|
|
{
|
|
|
|
glGenTextures(1, &font_tex);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, font_tex);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_font_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_WARN("Couldn't init font renderer.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
font_color[4 * i + 0] = g_settings.video.msg_color_r;
|
|
|
|
font_color[4 * i + 1] = g_settings.video.msg_color_g;
|
|
|
|
font_color[4 * i + 2] = g_settings.video.msg_color_b;
|
|
|
|
font_color[4 * i + 3] = 1.0;
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
font_color_dark[4 * i + j] = 0.3 * font_color[4 * i + j];
|
|
|
|
font_color_dark[4 * i + 3] = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
static void calculate_msg_geometry(const struct font_output *head, struct font_rect *rect)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
int x_min = head->off_x;
|
|
|
|
int x_max = head->off_x + head->width+10;
|
|
|
|
int y_min = head->off_y;
|
2014-06-01 20:36:43 +00:00
|
|
|
int y_max = head->off_y + head->height+1;
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
while ((head = head->next))
|
|
|
|
{
|
|
|
|
int left = head->off_x;
|
|
|
|
int right = head->off_x + head->width;
|
|
|
|
int bottom = head->off_y;
|
|
|
|
int top = head->off_y + head->height;
|
|
|
|
|
|
|
|
if (left < x_min)
|
|
|
|
x_min = left;
|
|
|
|
if (right > x_max)
|
|
|
|
x_max = right;
|
|
|
|
|
|
|
|
if (bottom < y_min)
|
|
|
|
y_min = bottom;
|
|
|
|
if (top > y_max)
|
|
|
|
y_max = top;
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
rect->x = x_min;
|
|
|
|
rect->y = y_min;
|
|
|
|
rect->width = x_max - x_min;
|
|
|
|
rect->height = y_max - y_min;
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
static void adjust_power_of_two(gl_t *gl, struct font_rect *geom)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
// Some systems really hate NPOT textures.
|
|
|
|
geom->pot_width = next_pow2(geom->width);
|
|
|
|
geom->pot_height = next_pow2(geom->height);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
if (geom->pot_width > max_font_size)
|
|
|
|
geom->pot_width = max_font_size;
|
|
|
|
if (geom->pot_height > max_font_size)
|
|
|
|
geom->pot_height = max_font_size;
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
if ((geom->pot_width > font_tex_w) || (geom->pot_height > font_tex_h))
|
|
|
|
{
|
|
|
|
font_tex_buf = (uint32_t*)realloc(font_tex_buf,
|
|
|
|
geom->pot_width * geom->pot_height * sizeof(uint32_t));
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, geom->pot_width, geom->pot_height,
|
|
|
|
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
font_tex_w = geom->pot_width;
|
|
|
|
font_tex_h = geom->pot_height;
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
static void copy_glyph(const struct font_output *head, const struct font_rect *geom, uint32_t *buffer, unsigned width, unsigned height)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-09 14:46:35 +00:00
|
|
|
int h, w, x, y, font_width, font_height;
|
|
|
|
uint8_t *src;
|
|
|
|
uint32_t *dst;
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
// head has top-left oriented coords.
|
2014-05-09 14:46:35 +00:00
|
|
|
x = head->off_x - geom->x;
|
|
|
|
y = head->off_y - geom->y;
|
|
|
|
y = height - head->height - y - 1;
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-09 14:46:35 +00:00
|
|
|
src = (uint8_t*)head->output;
|
|
|
|
font_width = head->width + ((x < 0) ? x : 0);
|
|
|
|
font_height = head->height + ((y < 0) ? y : 0);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
if (x < 0)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
src += -x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y < 0)
|
|
|
|
{
|
|
|
|
src += -y * head->pitch;
|
|
|
|
y = 0;
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
if (x + font_width > (int)width)
|
|
|
|
font_width = width - x;
|
|
|
|
|
|
|
|
if (y + font_height > (int)height)
|
|
|
|
font_height = height - y;
|
|
|
|
|
2014-05-09 14:46:35 +00:00
|
|
|
dst = (uint32_t*)(buffer + y * width + x);
|
2014-05-07 18:12:51 +00:00
|
|
|
for (h = 0; h < font_height; h++, dst += width, src += head->pitch)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
uint8_t *d = (uint8_t*)dst;
|
|
|
|
for (w = 0; w < font_width; w++)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
*d++ = 0xff;
|
|
|
|
*d++ = 0xff;
|
|
|
|
*d++ = 0xff;
|
|
|
|
*d++ = src[w];
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-07 18:12:51 +00:00
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
static void blit_fonts(gl_t *gl, const struct font_output *head, const struct font_rect *geom)
|
|
|
|
{
|
|
|
|
memset(font_tex_buf, 0, font_tex_w * font_tex_h * sizeof(uint32_t));
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
while (head)
|
|
|
|
{
|
|
|
|
copy_glyph(head, geom, font_tex_buf, font_tex_w, font_tex_h);
|
|
|
|
head = head->next;
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
|
|
|
|
glTexSubImage2D(GL_TEXTURE_2D,
|
|
|
|
0, 0, 0, font_tex_w, font_tex_h,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, font_tex_buf);
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
static void calculate_font_coords(gl_t *gl,
|
|
|
|
GLfloat font_vertex[8], GLfloat font_vertex_dark[8], GLfloat font_tex_coords[8], GLfloat scale, GLfloat pos_x, GLfloat pos_y)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2014-05-10 04:21:03 +00:00
|
|
|
GLfloat scale_factor, lx, hx, ly, hy, shift_x, shift_y;
|
|
|
|
|
|
|
|
scale_factor = scale;
|
|
|
|
lx = pos_x;
|
|
|
|
hx = (GLfloat)font_last_width * scale_factor / gl->vp.width + lx;
|
|
|
|
ly = pos_y;
|
|
|
|
hy = (GLfloat)font_last_height * scale_factor / gl->vp.height + ly;
|
2014-05-07 18:12:51 +00:00
|
|
|
|
|
|
|
font_vertex[0] = lx;
|
|
|
|
font_vertex[2] = hx;
|
|
|
|
font_vertex[4] = lx;
|
|
|
|
font_vertex[6] = hx;
|
|
|
|
font_vertex[1] = hy;
|
|
|
|
font_vertex[3] = hy;
|
|
|
|
font_vertex[5] = ly;
|
|
|
|
font_vertex[7] = ly;
|
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
shift_x = 2.0f / gl->vp.width;
|
|
|
|
shift_y = 2.0f / gl->vp.height;
|
2014-05-07 18:12:51 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
font_vertex_dark[2 * i + 0] = font_vertex[2 * i + 0] - shift_x;
|
|
|
|
font_vertex_dark[2 * i + 1] = font_vertex[2 * i + 1] - shift_y;
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
lx = 0.0f;
|
|
|
|
hx = (GLfloat)font_last_width / font_tex_w;
|
|
|
|
ly = 1.0f - (GLfloat)font_last_height / font_tex_h;
|
|
|
|
hy = 1.0f;
|
|
|
|
|
|
|
|
font_tex_coords[0] = lx;
|
|
|
|
font_tex_coords[2] = hx;
|
|
|
|
font_tex_coords[4] = lx;
|
|
|
|
font_tex_coords[6] = hx;
|
|
|
|
font_tex_coords[1] = ly;
|
|
|
|
font_tex_coords[3] = ly;
|
|
|
|
font_tex_coords[5] = hy;
|
|
|
|
font_tex_coords[7] = hy;
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
static void lakka_draw_text(struct font_output_list *out, float x, float y, float scale, float alpha)
|
2014-05-07 18:12:51 +00:00
|
|
|
{
|
2014-06-03 09:54:48 +00:00
|
|
|
if (alpha > global_alpha)
|
|
|
|
alpha = global_alpha;
|
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
int i;
|
|
|
|
struct font_output *head;
|
|
|
|
struct font_rect geom;
|
|
|
|
struct gl_ortho ortho = {0, 1, 0, 1, -1, 1};
|
2014-06-02 21:57:19 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2014-05-10 04:21:03 +00:00
|
|
|
|
2014-05-27 00:26:15 +00:00
|
|
|
if (!font || !gl || !out)
|
2014-05-07 18:12:51 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
font_color[4 * i + 0] = 1.0;
|
|
|
|
font_color[4 * i + 1] = 1.0;
|
|
|
|
font_color[4 * i + 2] = 1.0;
|
|
|
|
font_color[4 * i + 3] = alpha;
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
if (gl->shader && gl->shader->use)
|
2014-05-07 18:12:51 +00:00
|
|
|
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, true, false);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
|
|
|
GLfloat font_vertex[8];
|
|
|
|
GLfloat font_vertex_dark[8];
|
|
|
|
GLfloat font_tex_coords[8];
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, font_tex);
|
|
|
|
|
|
|
|
gl->coords.tex_coord = font_tex_coords;
|
|
|
|
|
2014-05-27 00:26:15 +00:00
|
|
|
head = (struct font_output*)out->head;
|
2014-05-07 18:12:51 +00:00
|
|
|
|
|
|
|
calculate_msg_geometry(head, &geom);
|
|
|
|
adjust_power_of_two(gl, &geom);
|
|
|
|
blit_fonts(gl, head, &geom);
|
|
|
|
|
|
|
|
font_last_width = geom.width;
|
|
|
|
font_last_height = geom.height;
|
|
|
|
|
|
|
|
calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords,
|
|
|
|
scale, x / gl->win_width, (gl->win_height - y) / gl->win_height);
|
|
|
|
|
|
|
|
gl->coords.vertex = font_vertex;
|
|
|
|
gl->coords.color = font_color;
|
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
// Post - Go back to old rendering path.
|
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
|
|
|
gl->coords.tex_coord = gl->tex_coords;
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
gl_set_projection(gl, &ortho, true);
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
void lakka_draw_background()
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-06-03 09:54:48 +00:00
|
|
|
GLfloat background_color[] = {
|
|
|
|
0.1, 0.74, 0.61, global_alpha,
|
|
|
|
0.1, 0.74, 0.61, global_alpha,
|
|
|
|
0.1, 0.74, 0.61, global_alpha,
|
|
|
|
0.1, 0.74, 0.61, global_alpha,
|
|
|
|
};
|
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2014-02-26 20:10:17 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
|
|
|
gl->coords.tex_coord = gl->tex_coords;
|
|
|
|
gl->coords.color = background_color;
|
2014-02-26 20:17:50 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
if (gl->shader && gl->shader->use)
|
2014-05-07 18:12:51 +00:00
|
|
|
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
|
2014-02-26 20:10:17 +00:00
|
|
|
gl_shader_set_coords(gl, &gl->coords, &gl->mvp_no_rot);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
}
|
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
void lakka_draw_icon(GLuint texture, float x, float y, float alpha, float rotation, float scale)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-06-03 09:54:48 +00:00
|
|
|
if (alpha > global_alpha)
|
|
|
|
alpha = global_alpha;
|
|
|
|
|
2014-02-26 20:10:17 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GLfloat vtest[] = {
|
|
|
|
0, 0,
|
|
|
|
1, 0,
|
|
|
|
0, 1,
|
|
|
|
1, 1
|
|
|
|
};
|
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2014-05-10 04:21:03 +00:00
|
|
|
|
2014-05-31 11:25:33 +00:00
|
|
|
glViewport(x, gl->win_height - y, dim, dim);
|
2014-05-09 14:46:35 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
2014-02-26 20:10:17 +00:00
|
|
|
gl->coords.vertex = vtest;
|
|
|
|
gl->coords.tex_coord = vtest;
|
|
|
|
gl->coords.color = color;
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
|
2014-05-10 04:21:03 +00:00
|
|
|
if (gl->shader && gl->shader->use)
|
2014-05-07 18:12:51 +00:00
|
|
|
gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
|
|
|
math_matrix mymat;
|
|
|
|
|
|
|
|
math_matrix mrot;
|
|
|
|
matrix_rotate_z(&mrot, rotation);
|
|
|
|
matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot);
|
|
|
|
|
|
|
|
math_matrix mscal;
|
|
|
|
matrix_scale(&mscal, scale, scale, 1);
|
|
|
|
matrix_multiply(&mymat, &mscal, &mymat);
|
|
|
|
|
|
|
|
gl_shader_set_coords(gl, &gl->coords, &mymat);
|
|
|
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
gl->coords.vertex = gl->vertex_ptr;
|
|
|
|
gl->coords.tex_coord = gl->tex_coords;
|
|
|
|
gl->coords.color = gl->white_color_ptr;
|
|
|
|
}
|
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
static void lakka_draw_subitems(int i, int j)
|
2014-05-07 18:12:51 +00:00
|
|
|
{
|
2014-06-02 21:57:19 +00:00
|
|
|
int k;
|
|
|
|
menu_category_t *category = (menu_category_t*)&categories[i];
|
|
|
|
menu_item_t *item = (menu_item_t*)&category->items[j];
|
2014-05-27 00:02:39 +00:00
|
|
|
menu_category_t *active_category = (menu_category_t*)&categories[menu_active_category];
|
2014-06-02 21:57:19 +00:00
|
|
|
menu_item_t *active_item = (menu_item_t*)&active_category->items[active_category->active_item];
|
2014-05-09 15:29:41 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
for(k = 0; k < item->num_subitems; k++)
|
|
|
|
{
|
|
|
|
menu_subitem_t *subitem = (menu_subitem_t*)&item->subitems[k];
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
if (k == 0 && g_extern.main_is_init
|
|
|
|
&& !g_extern.libretro_dummy
|
|
|
|
&& strcmp(g_extern.fullpath, &active_item->rom) == 0)
|
|
|
|
{
|
|
|
|
lakka_draw_icon(resume_icon,
|
|
|
|
156 + HSPACING*(i+2) + all_categories_x - dim/2.0,
|
|
|
|
300 + subitem->y + dim/2.0,
|
|
|
|
subitem->alpha,
|
|
|
|
0,
|
|
|
|
subitem->zoom);
|
|
|
|
lakka_draw_text(&resume_label,
|
|
|
|
156 + HSPACING*(i+2) + all_categories_x + dim/2.0,
|
|
|
|
300 + subitem->y + 15,
|
|
|
|
1,
|
|
|
|
subitem->alpha);
|
|
|
|
}
|
|
|
|
else if (k == 0)
|
|
|
|
{
|
|
|
|
lakka_draw_icon(subitem->icon,
|
|
|
|
156 + HSPACING*(i+2) + all_categories_x - dim/2.0,
|
|
|
|
300 + subitem->y + dim/2.0,
|
|
|
|
subitem->alpha,
|
|
|
|
0,
|
|
|
|
subitem->zoom);
|
|
|
|
lakka_draw_text(&subitem->out,
|
|
|
|
156 + HSPACING * (i+2) + all_categories_x + dim/2.0,
|
|
|
|
300 + subitem->y + 15,
|
|
|
|
1,
|
|
|
|
subitem->alpha);
|
|
|
|
}
|
|
|
|
else if ( // if we are in settings or a rom is launched
|
|
|
|
menu_active_category == 0 ||
|
|
|
|
(g_extern.main_is_init &&
|
|
|
|
!g_extern.libretro_dummy &&
|
|
|
|
strcmp(g_extern.fullpath, &active_item->rom) == 0))
|
|
|
|
{
|
|
|
|
lakka_draw_icon(subitem->icon,
|
|
|
|
156 + HSPACING*(i+2) + all_categories_x - dim/2.0,
|
|
|
|
300 + subitem->y + dim/2.0,
|
|
|
|
subitem->alpha,
|
|
|
|
0,
|
|
|
|
subitem->zoom);
|
|
|
|
lakka_draw_text(&subitem->out,
|
|
|
|
156 + HSPACING * (i+2) + all_categories_x + dim/2.0,
|
|
|
|
300 + subitem->y + 15,
|
|
|
|
1,
|
|
|
|
subitem->alpha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
static void lakka_draw_items(int i)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
menu_category_t *category = (menu_category_t*)&categories[i];
|
|
|
|
menu_category_t *active_category = (menu_category_t*)&categories[menu_active_category];
|
|
|
|
menu_item_t *active_item = (menu_item_t*)&active_category->items[active_category->active_item];
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
for(j = 0; j < category->num_items; j++)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-06-02 21:57:19 +00:00
|
|
|
menu_item_t *item = (menu_item_t*)&category->items[j];
|
2014-05-27 00:02:39 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
if (i == menu_active_category &&
|
|
|
|
j > active_category->active_item - 4 &&
|
|
|
|
j < active_category->active_item + 10) // performance improvement
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-06-03 00:20:14 +00:00
|
|
|
lakka_draw_icon(category->item_icon,
|
2014-05-07 18:12:51 +00:00
|
|
|
156 + HSPACING*(i+1) + all_categories_x - dim/2.0,
|
2014-05-27 01:06:58 +00:00
|
|
|
300 + item->y + dim/2.0,
|
|
|
|
item->alpha,
|
2014-05-07 18:12:51 +00:00
|
|
|
0,
|
2014-05-27 01:06:58 +00:00
|
|
|
item->zoom);
|
2014-05-07 18:12:51 +00:00
|
|
|
|
2014-05-09 14:46:35 +00:00
|
|
|
if (depth == 0)
|
2014-06-02 21:57:19 +00:00
|
|
|
lakka_draw_text(&item->out,
|
|
|
|
156 + HSPACING * (i+1) + all_categories_x + dim/2.0,
|
|
|
|
300 + item->y + 15,
|
|
|
|
1,
|
|
|
|
item->alpha);
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
2014-05-07 18:12:51 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
if (i == menu_active_category && j == category->active_item && depth == 1) // performance improvement
|
|
|
|
lakka_draw_subitems(i, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lakka_draw_categories()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < num_categories; i++)
|
|
|
|
{
|
|
|
|
menu_category_t *category = (menu_category_t*)&categories[i];
|
|
|
|
|
|
|
|
// draw items
|
|
|
|
lakka_draw_items(i);
|
|
|
|
|
|
|
|
// draw category icon
|
|
|
|
lakka_draw_icon(category->icon,
|
2014-05-09 14:46:35 +00:00
|
|
|
156 + (HSPACING*(i+1)) + all_categories_x - dim/2.0,
|
|
|
|
300 + dim/2.0,
|
2014-05-27 00:02:39 +00:00
|
|
|
category->alpha,
|
2014-05-09 14:46:35 +00:00
|
|
|
0,
|
2014-05-27 00:02:39 +00:00
|
|
|
category->zoom);
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
2014-06-02 21:57:19 +00:00
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
static void lakka_frame(void)
|
|
|
|
{
|
|
|
|
struct font_output_list *msg;
|
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
|
|
|
menu_category_t *active_category = (menu_category_t*)&categories[menu_active_category];
|
2014-06-03 14:32:00 +00:00
|
|
|
menu_item_t *active_item;
|
2014-06-02 21:57:19 +00:00
|
|
|
|
2014-06-03 14:32:00 +00:00
|
|
|
if (!driver.menu || !gl || !active_category)
|
2014-06-02 21:57:19 +00:00
|
|
|
return;
|
|
|
|
|
2014-06-03 14:32:00 +00:00
|
|
|
active_item = (menu_item_t*)&active_category->items[active_category->active_item];
|
|
|
|
|
2014-06-02 21:57:19 +00:00
|
|
|
update_tweens(0.002);
|
|
|
|
|
|
|
|
glViewport(0, 0, gl->win_width, gl->win_height);
|
|
|
|
|
|
|
|
lakka_draw_background();
|
|
|
|
|
|
|
|
lakka_draw_categories();
|
|
|
|
|
|
|
|
if (depth == 0) {
|
|
|
|
lakka_draw_text(&active_category->out, 15.0, 40.0, 1, 1.0);
|
|
|
|
} else {
|
|
|
|
lakka_draw_text(&active_item->out, 15.0, 40.0, 1, 1.0);
|
|
|
|
lakka_draw_icon(arrow_icon,
|
|
|
|
156 + HSPACING*(menu_active_category+1) + all_categories_x + 150 +-dim/2.0,
|
|
|
|
300 + VSPACING*2.4 + (dim/2.0), 1, 0, I_ACTIVE_ZOOM);
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
gl_set_viewport(gl, gl->win_width, gl->win_height, false, false);
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-26 16:40:27 +00:00
|
|
|
// thanks to https://github.com/DavidEGrayson/ahrs-visualizer/blob/master/png_texture.cpp
|
|
|
|
static GLuint png_texture_load(const char * file_name, int * width, int * height)
|
|
|
|
{
|
|
|
|
png_byte header[8];
|
|
|
|
|
|
|
|
FILE *fp = fopen(file_name, "rb");
|
|
|
|
if (fp == 0)
|
|
|
|
{
|
|
|
|
perror(file_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the header
|
|
|
|
fread(header, 1, 8, fp);
|
|
|
|
|
|
|
|
if (png_sig_cmp(header, 0, 8))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: %s is not a PNG.\n", file_name);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
|
|
|
if (!png_ptr)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: png_create_read_struct returned 0.\n");
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create png info struct
|
|
|
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
|
|
|
if (!info_ptr)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: png_create_info_struct returned 0.\n");
|
|
|
|
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create png info struct
|
|
|
|
png_infop end_info = png_create_info_struct(png_ptr);
|
|
|
|
if (!end_info)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: png_create_info_struct returned 0.\n");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the code in this if statement gets called if libpng encounters an error
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
|
|
|
fprintf(stderr, "error from libpng\n");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// init png reading
|
|
|
|
png_init_io(png_ptr, fp);
|
|
|
|
|
|
|
|
// let libpng know you already read the first 8 bytes
|
|
|
|
png_set_sig_bytes(png_ptr, 8);
|
|
|
|
|
|
|
|
// read all the info up to the image data
|
|
|
|
png_read_info(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
// variables to pass to get info
|
|
|
|
int bit_depth, color_type;
|
|
|
|
png_uint_32 temp_width, temp_height;
|
|
|
|
|
|
|
|
// get info about png
|
|
|
|
png_get_IHDR(png_ptr, info_ptr, &temp_width, &temp_height, &bit_depth, &color_type,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (width){ *width = temp_width; }
|
|
|
|
if (height){ *height = temp_height; }
|
|
|
|
|
|
|
|
//printf("%s: %lux%lu %d\n", file_name, temp_width, temp_height, color_type);
|
|
|
|
|
|
|
|
if (bit_depth != 8)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: Unsupported bit depth %d. Must be 8.\n", file_name, bit_depth);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLint format;
|
|
|
|
switch(color_type)
|
|
|
|
{
|
|
|
|
case PNG_COLOR_TYPE_RGB:
|
|
|
|
format = GL_RGB;
|
|
|
|
break;
|
|
|
|
case PNG_COLOR_TYPE_RGB_ALPHA:
|
|
|
|
format = GL_RGBA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: Unknown libpng color type %d.\n", file_name, color_type);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the png info struct.
|
|
|
|
png_read_update_info(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
// Row size in bytes.
|
|
|
|
int rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
// glTexImage2d requires rows to be 4-byte aligned
|
|
|
|
rowbytes += 3 - ((rowbytes-1) % 4);
|
|
|
|
|
|
|
|
// Allocate the image_data as a big block, to be given to opengl
|
|
|
|
png_byte * image_data = (png_byte *)malloc(rowbytes * temp_height * sizeof(png_byte)+15);
|
|
|
|
if (image_data == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: could not allocate memory for PNG image data\n");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// row_pointers is for pointing to image_data for reading the png with libpng
|
|
|
|
png_byte ** row_pointers = (png_byte **)malloc(temp_height * sizeof(png_byte *));
|
|
|
|
if (row_pointers == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: could not allocate memory for PNG row pointers\n");
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
|
|
|
free(image_data);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the individual row_pointers to point at the correct offsets of image_data
|
|
|
|
for (unsigned int i = 0; i < temp_height; i++)
|
|
|
|
{
|
|
|
|
row_pointers[temp_height - 1 - i] = image_data + i * rowbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the png into image_data through row_pointers
|
|
|
|
png_read_image(png_ptr, row_pointers);
|
|
|
|
|
|
|
|
// Generate the OpenGL texture object
|
|
|
|
GLuint texture;
|
|
|
|
glGenTextures(1, &texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, format, temp_width, temp_height, 0, format, GL_UNSIGNED_BYTE, image_data);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
|
|
|
free(image_data);
|
|
|
|
free(row_pointers);
|
|
|
|
fclose(fp);
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2014-05-31 21:22:20 +00:00
|
|
|
static void lakka_context_destroy(void *data)
|
2014-05-31 21:19:59 +00:00
|
|
|
{
|
2014-06-01 15:07:03 +00:00
|
|
|
int i, j;
|
2014-05-31 23:08:39 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2014-05-31 21:19:59 +00:00
|
|
|
|
|
|
|
glDeleteTextures(1, &settings_icon);
|
|
|
|
glDeleteTextures(1, &arrow_icon);
|
|
|
|
glDeleteTextures(1, &run_icon);
|
|
|
|
glDeleteTextures(1, &resume_icon);
|
|
|
|
glDeleteTextures(1, &savestate_icon);
|
|
|
|
glDeleteTextures(1, &loadstate_icon);
|
|
|
|
glDeleteTextures(1, &screenshot_icon);
|
|
|
|
glDeleteTextures(1, &reload_icon);
|
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
for (i = 1; i < num_categories; i++)
|
|
|
|
{
|
|
|
|
menu_category_t *category = (menu_category_t*)&categories[i];
|
|
|
|
glDeleteTextures(1, &category->icon);
|
2014-06-03 00:20:14 +00:00
|
|
|
glDeleteTextures(1, &category->item_icon);
|
2014-06-01 15:07:03 +00:00
|
|
|
|
2014-06-03 00:20:14 +00:00
|
|
|
/*for (j = 0; j < category->num_items; j++)
|
2014-06-01 15:07:03 +00:00
|
|
|
{
|
|
|
|
menu_item_t *item = (menu_item_t*)&category->items[j];
|
|
|
|
glDeleteTextures(1, &item->icon);
|
2014-06-03 00:20:14 +00:00
|
|
|
}*/
|
2014-06-01 15:07:03 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 09:54:48 +00:00
|
|
|
//if (numtweens)
|
|
|
|
// free(tweens);
|
2014-05-31 21:19:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
void lakka_init_settings(void)
|
|
|
|
{
|
|
|
|
menu_category_t *category = (menu_category_t*)&categories[0];
|
|
|
|
|
|
|
|
strlcpy(category->name, "Settings", sizeof(category->name));
|
|
|
|
category->alpha = 1.0;
|
|
|
|
category->zoom = C_ACTIVE_ZOOM;
|
|
|
|
category->active_item = 0;
|
|
|
|
category->num_items = 0;
|
|
|
|
category->items = (menu_item_t*)calloc(category->num_items, sizeof(menu_item_t));
|
|
|
|
|
2014-06-02 14:34:17 +00:00
|
|
|
int j, k;
|
|
|
|
|
|
|
|
// General options item
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
category->num_items++;
|
|
|
|
category->items = (menu_item_t*)realloc(category->items, category->num_items * sizeof(menu_item_t));
|
|
|
|
|
|
|
|
menu_item_t *item0 = (menu_item_t*)&category->items[j];
|
|
|
|
|
|
|
|
strlcpy(item0->name, "General Options", sizeof(item0->name));
|
|
|
|
item0->alpha = j ? 0.5 : 1.0;
|
|
|
|
item0->zoom = j ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM;
|
|
|
|
item0->y = j ? VSPACING*(3+j) : VSPACING*2.4;
|
|
|
|
item0->active_subitem = 0;
|
|
|
|
item0->num_subitems = 0;
|
|
|
|
|
|
|
|
// General options subitems
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
item0->num_subitems++;
|
|
|
|
//item0->subitems = (menu_subitem_t*)realloc(item0->subitems, item0->num_subitems * sizeof(menu_subitem_t));
|
|
|
|
item0->subitems = (menu_subitem_t*)calloc(item0->num_subitems, sizeof(menu_subitem_t));
|
|
|
|
|
|
|
|
menu_subitem_t *subitem0 = (menu_subitem_t*)&item0->subitems[k];
|
|
|
|
|
|
|
|
strlcpy(subitem0->name, "Libretro Logging Level", sizeof(subitem0->name));
|
|
|
|
subitem0->alpha = k ? 1.0 : 0.5;
|
|
|
|
subitem0->zoom = k ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM;
|
|
|
|
subitem0->y = k ? VSPACING * (3+k) : VSPACING * 2.4;
|
|
|
|
|
|
|
|
k = 1;
|
|
|
|
item0->num_subitems++;
|
|
|
|
item0->subitems = (menu_subitem_t*)realloc(item0->subitems, item0->num_subitems * sizeof(menu_subitem_t));
|
|
|
|
//item0->subitems = (menu_subitem_t*)calloc(item0->num_subitems, sizeof(menu_subitem_t));
|
|
|
|
|
|
|
|
menu_subitem_t *subitem1 = (menu_subitem_t*)&item0->subitems[k];
|
|
|
|
|
|
|
|
strlcpy(subitem1->name, "Logging Verbosity", sizeof(subitem1->name));
|
|
|
|
subitem1->alpha = k ? 1.0 : 0.5;
|
|
|
|
subitem1->zoom = k ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM;
|
|
|
|
subitem1->y = k ? VSPACING * (3+k) : VSPACING * 2.4;
|
|
|
|
|
|
|
|
k = 2;
|
|
|
|
item0->num_subitems++;
|
|
|
|
item0->subitems = (menu_subitem_t*)realloc(item0->subitems, item0->num_subitems * sizeof(menu_subitem_t));
|
|
|
|
//item0->subitems = (menu_subitem_t*)calloc(item0->num_subitems, sizeof(menu_subitem_t));
|
|
|
|
|
|
|
|
menu_subitem_t *subitem2 = (menu_subitem_t*)&item0->subitems[k];
|
|
|
|
|
|
|
|
strlcpy(subitem2->name, "Configuration Save On Exit", sizeof(subitem2->name));
|
|
|
|
subitem2->alpha = k ? 1.0 : 0.5;
|
|
|
|
subitem2->zoom = k ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM;
|
|
|
|
subitem2->y = k ? VSPACING * (3+k) : VSPACING * 2.4;
|
|
|
|
|
|
|
|
// Quit item
|
|
|
|
|
|
|
|
j = 1;
|
|
|
|
category->num_items++;
|
|
|
|
category->items = (menu_item_t*)realloc(category->items, category->num_items * sizeof(menu_item_t));
|
|
|
|
|
|
|
|
menu_item_t *item1 = (menu_item_t*)&category->items[j];
|
|
|
|
|
|
|
|
strlcpy(item1->name, "Quit RetroArch", sizeof(item1->name));
|
|
|
|
item1->alpha = j ? 0.5 : 1.0;
|
|
|
|
item1->zoom = j ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM;
|
|
|
|
item1->y = j ? VSPACING*(3+j) : VSPACING*2.4;
|
|
|
|
item1->active_subitem = 0;
|
|
|
|
item1->num_subitems = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lakka_settings_context_reset(void)
|
|
|
|
{
|
|
|
|
menu_category_t *category = (menu_category_t*)&categories[0];
|
|
|
|
category->icon = settings_icon;
|
2014-06-03 00:20:14 +00:00
|
|
|
category->item_icon = setting_icon;
|
2014-06-01 15:07:03 +00:00
|
|
|
if (font_driver)
|
|
|
|
font_driver->render_msg(font, category->name, &category->out);
|
2014-06-02 14:34:17 +00:00
|
|
|
|
|
|
|
int j, k;
|
|
|
|
|
|
|
|
// General options item
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
menu_item_t *item0;
|
|
|
|
item0 = (menu_item_t*)&category->items[j];
|
|
|
|
if (font_driver)
|
|
|
|
font_driver->render_msg(font, item0->name, &item0->out);
|
|
|
|
|
|
|
|
// General options subitems
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
menu_subitem_t *subitem0 = (menu_subitem_t*)&item0->subitems[k];
|
|
|
|
subitem0->icon = subsetting_icon;
|
|
|
|
if (font_driver)
|
|
|
|
font_driver->render_msg(font, subitem0->name, &subitem0->out);
|
|
|
|
|
|
|
|
k = 1;
|
|
|
|
menu_subitem_t *subitem1 = (menu_subitem_t*)&item0->subitems[k];
|
|
|
|
subitem1->icon = subsetting_icon;
|
|
|
|
if (font_driver)
|
|
|
|
font_driver->render_msg(font, subitem1->name, &subitem1->out);
|
|
|
|
|
|
|
|
k = 2;
|
|
|
|
menu_subitem_t *subitem2 = (menu_subitem_t*)&item0->subitems[k];
|
|
|
|
subitem2->icon = subsetting_icon;
|
|
|
|
if (font_driver)
|
|
|
|
font_driver->render_msg(font, subitem2->name, &subitem2->out);
|
|
|
|
|
|
|
|
// Quit item
|
|
|
|
|
|
|
|
j = 1;
|
|
|
|
menu_item_t *item1;
|
|
|
|
item1 = (menu_item_t*)&category->items[j];
|
|
|
|
if (font_driver)
|
|
|
|
font_driver->render_msg(font, item1->name, &item1->out);
|
2014-06-01 15:07:03 +00:00
|
|
|
}
|
|
|
|
|
2014-06-02 14:34:17 +00:00
|
|
|
|
2014-05-31 21:22:20 +00:00
|
|
|
static void lakka_context_reset(void *data)
|
2014-05-07 18:12:51 +00:00
|
|
|
{
|
2014-06-01 15:07:03 +00:00
|
|
|
int i, j, k;
|
2014-05-10 03:25:50 +00:00
|
|
|
char path[256], dirpath[256];;
|
2014-05-07 18:12:51 +00:00
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
2014-05-31 23:08:39 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
if (!rgui)
|
|
|
|
return;
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-10 03:25:50 +00:00
|
|
|
fill_pathname_join(dirpath, g_settings.assets_directory, "lakka", sizeof(dirpath));
|
|
|
|
fill_pathname_slash(dirpath, sizeof(dirpath));
|
|
|
|
|
|
|
|
fill_pathname_join(path, dirpath, "settings.png", sizeof(path));
|
|
|
|
settings_icon = png_texture_load(path, &dim, &dim);
|
2014-06-02 14:34:17 +00:00
|
|
|
fill_pathname_join(path, dirpath, "setting.png", sizeof(path));
|
|
|
|
setting_icon = png_texture_load(path, &dim, &dim);
|
|
|
|
fill_pathname_join(path, dirpath, "subsetting.png", sizeof(path));
|
|
|
|
subsetting_icon = png_texture_load(path, &dim, &dim);
|
2014-05-10 03:25:50 +00:00
|
|
|
fill_pathname_join(path, dirpath, "arrow.png", sizeof(path));
|
|
|
|
arrow_icon = png_texture_load(path, &dim, &dim);
|
|
|
|
fill_pathname_join(path, dirpath, "run.png", sizeof(path));
|
|
|
|
run_icon = png_texture_load(path, &dim, &dim);
|
|
|
|
fill_pathname_join(path, dirpath, "resume.png", sizeof(path));
|
|
|
|
resume_icon = png_texture_load(path, &dim, &dim);
|
|
|
|
fill_pathname_join(path, dirpath, "savestate.png", sizeof(path));
|
|
|
|
savestate_icon = png_texture_load(path, &dim, &dim);
|
|
|
|
fill_pathname_join(path, dirpath, "loadstate.png", sizeof(path));
|
|
|
|
loadstate_icon = png_texture_load(path, &dim, &dim);
|
|
|
|
fill_pathname_join(path, dirpath, "screenshot.png", sizeof(path));
|
|
|
|
screenshot_icon = png_texture_load(path, &dim, &dim);
|
|
|
|
fill_pathname_join(path, dirpath, "reload.png", sizeof(path));
|
|
|
|
reload_icon = png_texture_load(path, &dim, &dim);
|
2014-05-07 18:12:51 +00:00
|
|
|
|
2014-05-31 23:08:39 +00:00
|
|
|
if (font_driver)
|
|
|
|
{
|
|
|
|
font_driver->render_msg(font, "Run", &run_label);
|
|
|
|
font_driver->render_msg(font, "Resume", &resume_label);
|
|
|
|
}
|
|
|
|
|
2014-06-02 14:34:17 +00:00
|
|
|
lakka_settings_context_reset();
|
2014-06-01 15:07:03 +00:00
|
|
|
for (i = 1; i < num_categories; i++)
|
2014-05-31 23:08:39 +00:00
|
|
|
{
|
2014-06-01 15:07:03 +00:00
|
|
|
menu_category_t *category = (menu_category_t*)&categories[i];
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-03 00:20:14 +00:00
|
|
|
char core_id[256], texturepath[256], content_texturepath[256], dirpath[256];
|
2014-06-01 15:07:03 +00:00
|
|
|
core_info_t *info;
|
|
|
|
core_info_list_t *info_list;
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
fill_pathname_join(dirpath, g_settings.assets_directory, "lakka", sizeof(dirpath));
|
|
|
|
fill_pathname_slash(dirpath, sizeof(dirpath));
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
info_list = (core_info_list_t*)rgui->core_info;
|
|
|
|
info = NULL;
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
if (info_list)
|
|
|
|
info = (core_info_t*)&info_list->list[i-1];
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
strlcpy(core_id, basename(info->path), sizeof(core_id));
|
|
|
|
strlcpy(core_id, str_replace(core_id, ".so", ""), sizeof(core_id));
|
|
|
|
strlcpy(core_id, str_replace(core_id, ".dll", ""), sizeof(core_id));
|
|
|
|
strlcpy(core_id, str_replace(core_id, ".dylib", ""), sizeof(core_id));
|
|
|
|
strlcpy(core_id, str_replace(core_id, "-libretro", ""), sizeof(core_id));
|
|
|
|
strlcpy(core_id, str_replace(core_id, "_libretro", ""), sizeof(core_id));
|
|
|
|
strlcpy(core_id, str_replace(core_id, "libretro-", ""), sizeof(core_id));
|
|
|
|
strlcpy(core_id, str_replace(core_id, "libretro_", ""), sizeof(core_id));
|
|
|
|
|
|
|
|
strlcpy(texturepath, dirpath, sizeof(texturepath));
|
|
|
|
strlcat(texturepath, core_id, sizeof(texturepath));
|
|
|
|
strlcat(texturepath, ".png", sizeof(texturepath));
|
|
|
|
|
2014-06-03 00:20:14 +00:00
|
|
|
strlcpy(content_texturepath, dirpath, sizeof(content_texturepath));
|
|
|
|
strlcat(content_texturepath, core_id, sizeof(content_texturepath));
|
|
|
|
strlcat(content_texturepath, "-content.png", sizeof(content_texturepath));
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
category->icon = png_texture_load(texturepath, &dim, &dim);
|
2014-06-03 00:20:14 +00:00
|
|
|
category->item_icon = png_texture_load(content_texturepath, &dim, &dim);
|
2014-06-01 15:07:03 +00:00
|
|
|
|
|
|
|
if (font_driver)
|
|
|
|
font_driver->render_msg(font, category->name, &category->out);
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
for (j = 0; j < category->num_items; j++)
|
|
|
|
{
|
|
|
|
menu_item_t *item = (menu_item_t*)&category->items[j];
|
2014-05-31 23:08:39 +00:00
|
|
|
|
|
|
|
if (font_driver)
|
2014-06-01 15:07:03 +00:00
|
|
|
font_driver->render_msg(font, item->name, &item->out);
|
2014-05-31 23:08:39 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
for (k = 0; k < item->num_subitems; k++)
|
2014-05-31 23:08:39 +00:00
|
|
|
{
|
2014-06-01 15:07:03 +00:00
|
|
|
menu_subitem_t *subitem = (menu_subitem_t*)&item->subitems[k];
|
|
|
|
|
|
|
|
switch (k)
|
|
|
|
{
|
|
|
|
case 0: subitem->icon = run_icon; break;
|
|
|
|
case 1: subitem->icon = savestate_icon; break;
|
2014-06-02 14:34:17 +00:00
|
|
|
case 2: subitem->icon = loadstate_icon; break;
|
|
|
|
case 3: subitem->icon = screenshot_icon; break;
|
|
|
|
case 4: subitem->icon = reload_icon; break;
|
2014-06-01 15:07:03 +00:00
|
|
|
}
|
2014-05-31 23:08:39 +00:00
|
|
|
|
|
|
|
if (font_driver)
|
2014-06-01 15:07:03 +00:00
|
|
|
font_driver->render_msg(font, subitem->name, &subitem->out);
|
2014-05-31 23:08:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 18:12:51 +00:00
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
static void lakka_init_items(int i, menu_category_t *category, core_info_t *info, const char* path)
|
2014-05-07 18:12:51 +00:00
|
|
|
{
|
2014-05-12 13:36:01 +00:00
|
|
|
int num_items, j, n, k;
|
2014-05-27 04:27:31 +00:00
|
|
|
struct string_list *list = (struct string_list*)dir_list_new(path, info->supported_extensions, true);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
dir_list_sort(list, true);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-09 14:46:35 +00:00
|
|
|
num_items = list ? list->size : 0;
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-09 14:46:35 +00:00
|
|
|
for (j = 0; j < num_items; j++)
|
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
if (list->elems[j].attr.b) // is a directory
|
2014-06-01 15:07:03 +00:00
|
|
|
lakka_init_items(i, category, info, list->elems[j].data);
|
2014-05-07 18:12:51 +00:00
|
|
|
else
|
|
|
|
{
|
2014-05-27 01:06:58 +00:00
|
|
|
menu_item_t *item;
|
2014-05-09 14:46:35 +00:00
|
|
|
|
2014-05-27 04:27:31 +00:00
|
|
|
n = category->num_items;
|
2014-05-27 01:06:58 +00:00
|
|
|
|
2014-05-27 04:27:31 +00:00
|
|
|
category->num_items++;
|
|
|
|
category->items = (menu_item_t*)realloc(category->items, category->num_items * sizeof(menu_item_t));
|
2014-05-27 20:43:04 +00:00
|
|
|
item = (menu_item_t*)&category->items[n];
|
2014-05-07 18:12:51 +00:00
|
|
|
|
2014-05-27 01:06:58 +00:00
|
|
|
strlcpy(item->name, path_basename(list->elems[j].data), sizeof(item->name));
|
|
|
|
strlcpy(item->rom, list->elems[j].data, sizeof(item->rom));
|
|
|
|
item->alpha = i != menu_active_category ? 0 : n ? 0.5 : 1;
|
|
|
|
item->zoom = n ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM;
|
2014-06-01 20:36:43 +00:00
|
|
|
item->y = n ? VSPACING*(3+n) : VSPACING*2.4;
|
2014-05-27 01:06:58 +00:00
|
|
|
item->active_subitem = 0;
|
|
|
|
item->num_subitems = 5;
|
|
|
|
item->subitems = (menu_subitem_t*)calloc(item->num_subitems, sizeof(menu_subitem_t));
|
|
|
|
|
|
|
|
for (k = 0; k < item->num_subitems; k++)
|
2014-05-09 16:13:28 +00:00
|
|
|
{
|
2014-05-27 01:06:58 +00:00
|
|
|
menu_subitem_t *subitem = (menu_subitem_t*)&item->subitems[k];
|
|
|
|
|
2014-05-09 16:13:28 +00:00
|
|
|
switch (k)
|
|
|
|
{
|
2014-05-07 18:12:51 +00:00
|
|
|
case 0:
|
2014-05-27 01:06:58 +00:00
|
|
|
strlcpy(subitem->name, "Run", sizeof(subitem->name));
|
2014-05-07 18:12:51 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-05-27 01:06:58 +00:00
|
|
|
strlcpy(subitem->name, "Save State", sizeof(subitem->name));
|
2014-05-07 18:12:51 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-06-02 14:34:17 +00:00
|
|
|
strlcpy(subitem->name, "Load State", sizeof(subitem->name));
|
2014-05-07 18:12:51 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-06-02 14:34:17 +00:00
|
|
|
strlcpy(subitem->name, "Take Screenshot", sizeof(subitem->name));
|
2014-05-07 18:12:51 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-06-02 14:34:17 +00:00
|
|
|
strlcpy(subitem->name, "Reset", sizeof(subitem->name));
|
2014-05-07 18:12:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-27 01:06:58 +00:00
|
|
|
subitem->alpha = 0;
|
2014-06-02 14:34:17 +00:00
|
|
|
subitem->zoom = k ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM;
|
|
|
|
subitem->y = k ? VSPACING * (3+k) : VSPACING * 2.4;
|
2014-05-31 23:08:39 +00:00
|
|
|
|
|
|
|
if (font_driver)
|
2014-06-01 15:07:03 +00:00
|
|
|
font_driver->render_msg(font, subitem->name, &subitem->out);
|
2014-05-07 18:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 19:04:59 +00:00
|
|
|
static void lakka_free(void *data)
|
|
|
|
{
|
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
2014-05-10 04:21:03 +00:00
|
|
|
|
2014-05-09 19:04:59 +00:00
|
|
|
if (rgui->alloc_font)
|
|
|
|
free((uint8_t*)rgui->font);
|
|
|
|
}
|
|
|
|
|
2014-05-30 18:53:10 +00:00
|
|
|
static int lakka_input_postprocess(uint64_t old_state)
|
2014-05-09 19:04:59 +00:00
|
|
|
{
|
2014-05-31 20:34:45 +00:00
|
|
|
if ((driver.menu && driver.menu->trigger_state & (1ULL << RARCH_MENU_TOGGLE)) &&
|
2014-05-09 19:04:59 +00:00
|
|
|
g_extern.main_is_init &&
|
|
|
|
!g_extern.libretro_dummy)
|
|
|
|
{
|
2014-06-03 09:54:48 +00:00
|
|
|
global_alpha = 0;
|
2014-05-09 19:04:59 +00:00
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_GAME);
|
2014-06-03 09:54:48 +00:00
|
|
|
return -1;
|
2014-05-09 19:04:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 09:54:48 +00:00
|
|
|
if (! global_alpha)
|
|
|
|
add_tween(DELAY, 1.0, &global_alpha, &inOutQuad, NULL);
|
|
|
|
|
|
|
|
return 0;
|
2014-05-09 19:04:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void lakka_init_core_info(void *data)
|
|
|
|
{
|
2014-05-31 19:17:08 +00:00
|
|
|
core_info_list_t *core;
|
2014-05-09 19:04:59 +00:00
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
|
|
|
|
|
|
|
core_info_list_free(rgui->core_info);
|
|
|
|
rgui->core_info = NULL;
|
|
|
|
|
2014-05-31 19:17:08 +00:00
|
|
|
rgui->core_info = (core_info_list_t*)core_info_list_new(*g_settings.libretro_directory ? g_settings.libretro_directory : "/usr/lib/libretro");
|
2014-05-09 19:04:59 +00:00
|
|
|
|
2014-05-31 19:17:08 +00:00
|
|
|
if (rgui->core_info)
|
|
|
|
{
|
|
|
|
core = (core_info_list_t*)rgui->core_info;
|
|
|
|
num_categories = rgui->core_info ? core->count + 1 : 1;
|
|
|
|
}
|
2014-05-09 19:04:59 +00:00
|
|
|
}
|
|
|
|
|
2014-05-07 18:12:51 +00:00
|
|
|
static void *lakka_init(void)
|
2014-02-26 20:10:17 +00:00
|
|
|
{
|
2014-05-31 11:25:33 +00:00
|
|
|
int i, j;
|
2014-05-07 18:12:51 +00:00
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)calloc(1, sizeof(*rgui));
|
2014-05-31 23:08:39 +00:00
|
|
|
gl_t *gl = (gl_t*)driver.video_data;
|
|
|
|
if (!rgui || !gl)
|
2014-05-09 16:13:28 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-05-31 11:25:33 +00:00
|
|
|
init_font(gl, g_settings.video.font_path, g_settings.video.font_size, gl->win_width, gl->win_height);
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-09 19:00:50 +00:00
|
|
|
lakka_init_core_info(rgui);
|
2014-05-31 11:25:33 +00:00
|
|
|
categories = (menu_category_t*)calloc(num_categories, sizeof(menu_category_t));
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-06-02 14:34:17 +00:00
|
|
|
lakka_init_settings();
|
|
|
|
|
2014-05-31 11:25:33 +00:00
|
|
|
for (i = 1; i < num_categories; i++)
|
2014-05-09 14:46:35 +00:00
|
|
|
{
|
2014-05-27 04:27:31 +00:00
|
|
|
core_info_t *info;
|
2014-05-31 19:17:08 +00:00
|
|
|
core_info_list_t *info_list;
|
2014-05-31 11:25:33 +00:00
|
|
|
menu_category_t *category = (menu_category_t*)&categories[i];
|
2014-05-10 03:25:50 +00:00
|
|
|
|
2014-05-31 19:17:08 +00:00
|
|
|
info_list = (core_info_list_t*)rgui->core_info;
|
|
|
|
info = NULL;
|
|
|
|
|
|
|
|
if (info_list)
|
|
|
|
info = (core_info_t*)&info_list->list[i-1];
|
2014-02-26 20:10:17 +00:00
|
|
|
|
2014-05-27 04:27:31 +00:00
|
|
|
strlcpy(category->name, info->display_name, sizeof(category->name));
|
|
|
|
strlcpy(category->libretro, info->path, sizeof(category->libretro));
|
2014-05-27 00:02:39 +00:00
|
|
|
category->alpha = 0.5;
|
|
|
|
category->zoom = C_PASSIVE_ZOOM;
|
|
|
|
category->active_item = 0;
|
|
|
|
category->num_items = 0;
|
|
|
|
category->items = (menu_item_t*)calloc(category->num_items, sizeof(menu_item_t));
|
2014-05-09 14:46:35 +00:00
|
|
|
|
2014-06-01 15:07:03 +00:00
|
|
|
lakka_init_items(i, category, info, g_settings.content_directory);
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 16:13:28 +00:00
|
|
|
return rgui;
|
2014-02-26 20:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const menu_ctx_driver_t menu_ctx_lakka = {
|
2014-05-10 04:21:03 +00:00
|
|
|
NULL,
|
2014-05-07 18:12:51 +00:00
|
|
|
NULL,
|
2014-04-01 02:45:00 +00:00
|
|
|
NULL,
|
2014-05-11 18:47:44 +00:00
|
|
|
lakka_frame,
|
2014-02-26 20:10:17 +00:00
|
|
|
lakka_init,
|
|
|
|
lakka_free,
|
2014-05-31 21:22:20 +00:00
|
|
|
lakka_context_reset,
|
|
|
|
lakka_context_destroy,
|
2014-02-26 20:10:17 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-02-28 00:44:03 +00:00
|
|
|
lakka_input_postprocess,
|
2014-04-13 21:41:47 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-04-13 22:09:52 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-05-09 19:00:50 +00:00
|
|
|
lakka_init_core_info,
|
2014-05-07 18:12:51 +00:00
|
|
|
&menu_ctx_backend_lakka,
|
2014-02-26 20:10:17 +00:00
|
|
|
"lakka",
|
|
|
|
};
|