(Lakka) Remove libpng dependancy and use lowercase variables

This commit is contained in:
Jean-André Santoni 2014-08-08 23:29:36 +02:00
parent 85666a1cba
commit db5d88641a
3 changed files with 171 additions and 302 deletions

View File

@ -43,7 +43,7 @@ static void lakka_switch_categories(void)
int i, j; int i, j;
// translation // translation
add_tween(DELAY, -menu_active_category * HSPACING, &all_categories_x, &inOutQuad, NULL); add_tween(DELAY, -menu_active_category * hspacing, &all_categories_x, &inOutQuad, NULL);
// alpha tweening // alpha tweening
for (i = 0; i < num_categories; i++) for (i = 0; i < num_categories; i++)
@ -55,7 +55,7 @@ static void lakka_switch_categories(void)
continue; continue;
ca = (i == menu_active_category) ? 1.0 : 0.5; ca = (i == menu_active_category) ? 1.0 : 0.5;
cz = (i == menu_active_category) ? C_ACTIVE_ZOOM : C_PASSIVE_ZOOM; cz = (i == menu_active_category) ? c_active_zoom : c_passive_zoom;
add_tween(DELAY, ca, &category->alpha, &inOutQuad, NULL); add_tween(DELAY, ca, &category->alpha, &inOutQuad, NULL);
add_tween(DELAY, cz, &category->zoom, &inOutQuad, NULL); add_tween(DELAY, cz, &category->zoom, &inOutQuad, NULL);
@ -83,10 +83,10 @@ static void lakka_switch_items(void)
continue; continue;
ia = (j == active_category->active_item) ? 1.0 : 0.5; ia = (j == active_category->active_item) ? 1.0 : 0.5;
iz = (j == active_category->active_item) ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM; iz = (j == active_category->active_item) ? i_active_zoom : i_passive_zoom;
iy = (j == active_category->active_item) ? VSPACING*ACTIVE_ITEM_FACTOR : iy = (j == active_category->active_item) ? vspacing*active_item_factor :
(j < active_category->active_item) ? VSPACING*(j - active_category->active_item + ABOVE_ITEM_OFFSET) : (j < active_category->active_item) ? vspacing*(j - active_category->active_item + above_item_offset) :
VSPACING*(j - active_category->active_item + UNDER_ITEM_OFFSET); vspacing*(j - active_category->active_item + under_item_offset);
add_tween(DELAY, ia, &active_item->alpha, &inOutQuad, NULL); add_tween(DELAY, ia, &active_item->alpha, &inOutQuad, NULL);
add_tween(DELAY, iz, &active_item->zoom, &inOutQuad, NULL); add_tween(DELAY, iz, &active_item->zoom, &inOutQuad, NULL);
@ -111,22 +111,22 @@ static void lakka_switch_subitems(void)
{ {
// Above items // Above items
add_tween(DELAY, 0.5, &subitem->alpha, &inOutQuad, NULL); add_tween(DELAY, 0.5, &subitem->alpha, &inOutQuad, NULL);
add_tween(DELAY, VSPACING*(k - item->active_subitem + ABOVE_SUBITEM_OFFSET), &subitem->y, &inOutQuad, NULL); add_tween(DELAY, vspacing*(k - item->active_subitem + above_subitem_offset), &subitem->y, &inOutQuad, NULL);
add_tween(DELAY, I_PASSIVE_ZOOM, &subitem->zoom, &inOutQuad, NULL); add_tween(DELAY, i_passive_zoom, &subitem->zoom, &inOutQuad, NULL);
} }
else if (k == item->active_subitem) else if (k == item->active_subitem)
{ {
// Active item // Active item
add_tween(DELAY, 1.0, &subitem->alpha, &inOutQuad, NULL); add_tween(DELAY, 1.0, &subitem->alpha, &inOutQuad, NULL);
add_tween(DELAY, VSPACING*ACTIVE_ITEM_FACTOR, &subitem->y, &inOutQuad, NULL); add_tween(DELAY, vspacing*active_item_factor, &subitem->y, &inOutQuad, NULL);
add_tween(DELAY, I_ACTIVE_ZOOM, &subitem->zoom, &inOutQuad, NULL); add_tween(DELAY, i_active_zoom, &subitem->zoom, &inOutQuad, NULL);
} }
else if (k > item->active_subitem) else if (k > item->active_subitem)
{ {
// Under items // Under items
add_tween(DELAY, 0.5, &subitem->alpha, &inOutQuad, NULL); add_tween(DELAY, 0.5, &subitem->alpha, &inOutQuad, NULL);
add_tween(DELAY, VSPACING*(k - item->active_subitem + UNDER_ITEM_OFFSET), &subitem->y, &inOutQuad, NULL); add_tween(DELAY, vspacing*(k - item->active_subitem + under_item_offset), &subitem->y, &inOutQuad, NULL);
add_tween(DELAY, I_PASSIVE_ZOOM, &subitem->zoom, &inOutQuad, NULL); add_tween(DELAY, i_passive_zoom, &subitem->zoom, &inOutQuad, NULL);
} }
} }
} }
@ -161,8 +161,8 @@ static void lakka_reset_submenu(void)
continue; continue;
subitem->alpha = 0; subitem->alpha = 0;
subitem->zoom = k == category->items[j].active_subitem ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM; subitem->zoom = k == category->items[j].active_subitem ? i_active_zoom : i_passive_zoom;
subitem->y = k == 0 ? VSPACING * ACTIVE_ITEM_FACTOR : VSPACING * (3+k); subitem->y = k == 0 ? vspacing * active_item_factor : vspacing * (3+k);
} }
} }
} }
@ -172,7 +172,7 @@ static void lakka_reset_submenu(void)
static void lakka_open_submenu(void) static void lakka_open_submenu(void)
{ {
int i, j, k; int i, j, k;
add_tween(DELAY, -HSPACING * (menu_active_category+1), &all_categories_x, &inOutQuad, NULL); add_tween(DELAY, -hspacing * (menu_active_category+1), &all_categories_x, &inOutQuad, NULL);
add_tween(DELAY, 1.0, &arrow_alpha, &inOutQuad, NULL); add_tween(DELAY, 1.0, &arrow_alpha, &inOutQuad, NULL);
// Reset contextual menu style // Reset contextual menu style
@ -202,12 +202,12 @@ static void lakka_open_submenu(void)
if (k == category->items[j].active_subitem) if (k == category->items[j].active_subitem)
{ {
add_tween(DELAY, 1.0, &subitem->alpha, &inOutQuad, NULL); add_tween(DELAY, 1.0, &subitem->alpha, &inOutQuad, NULL);
add_tween(DELAY, I_ACTIVE_ZOOM, &subitem->zoom, &inOutQuad, NULL); add_tween(DELAY, i_active_zoom, &subitem->zoom, &inOutQuad, NULL);
} }
else else
{ {
add_tween(DELAY, 0.5, &subitem->alpha, &inOutQuad, NULL); add_tween(DELAY, 0.5, &subitem->alpha, &inOutQuad, NULL);
add_tween(DELAY, I_PASSIVE_ZOOM, &subitem->zoom, &inOutQuad, NULL); add_tween(DELAY, i_passive_zoom, &subitem->zoom, &inOutQuad, NULL);
} }
} }
} }
@ -221,7 +221,7 @@ static void lakka_open_submenu(void)
static void lakka_close_submenu(void) static void lakka_close_submenu(void)
{ {
int i, j, k; int i, j, k;
add_tween(DELAY, -HSPACING * menu_active_category, &all_categories_x, &inOutQuad, NULL); add_tween(DELAY, -hspacing * menu_active_category, &all_categories_x, &inOutQuad, NULL);
add_tween(DELAY, 0.0, &arrow_alpha, &inOutQuad, NULL); add_tween(DELAY, 0.0, &arrow_alpha, &inOutQuad, NULL);
for (i = 0; i < num_categories; i++) for (i = 0; i < num_categories; i++)
@ -234,7 +234,7 @@ static void lakka_close_submenu(void)
if (i == menu_active_category) if (i == menu_active_category)
{ {
add_tween(DELAY, 1.0, &category->alpha, &inOutQuad, NULL); add_tween(DELAY, 1.0, &category->alpha, &inOutQuad, NULL);
add_tween(DELAY, C_ACTIVE_ZOOM, &category->zoom, &inOutQuad, NULL); add_tween(DELAY, c_active_zoom, &category->zoom, &inOutQuad, NULL);
for (j = 0; j < category->num_items; j++) for (j = 0; j < category->num_items; j++)
{ {
@ -252,7 +252,7 @@ static void lakka_close_submenu(void)
else else
{ {
add_tween(DELAY, 0.5, &category->alpha, &inOutQuad, NULL); add_tween(DELAY, 0.5, &category->alpha, &inOutQuad, NULL);
add_tween(DELAY, C_PASSIVE_ZOOM, &category->zoom, &inOutQuad, NULL); add_tween(DELAY, c_passive_zoom, &category->zoom, &inOutQuad, NULL);
for (j = 0; j < category->num_items; j++) for (j = 0; j < category->num_items; j++)
add_tween(DELAY, 0, &category->items[j].alpha, &inOutQuad, NULL); add_tween(DELAY, 0, &category->items[j].alpha, &inOutQuad, NULL);

View File

@ -40,7 +40,6 @@
#include "../../../gfx/fonts/bitmap.h" #include "../../../gfx/fonts/bitmap.h"
#include "lakka.h" #include "lakka.h"
#include <png.h>
// Category variables // Category variables
menu_category_t *categories; menu_category_t *categories;
@ -50,36 +49,43 @@ int menu_active_category = 0;
float all_categories_x = 0; float all_categories_x = 0;
float global_alpha = 0; float global_alpha = 0;
float arrow_alpha = 0; float arrow_alpha = 0;
float HSPACING; float hspacing;
float VSPACING; float vspacing;
float C_ACTIVE_ZOOM; float c_active_zoom;
float C_PASSIVE_ZOOM; float c_passive_zoom;
float I_ACTIVE_ZOOM; float i_active_zoom;
float I_PASSIVE_ZOOM; float i_passive_zoom;
float FONT_SIZE; float lakka_font_size;
float MARGIN_LEFT; float margin_left;
float MARGIN_TOP; float margin_top;
float TITLE_MARGIN_LEFT; float title_margin_left;
float TITLE_MARGIN_TOP; float title_margin_top;
float LABEL_MARGIN_LEFT; float label_margin_left;
float LABEL_MARGIN_TOP; float label_margin_top;
int ICON_SIZE; int icon_size;
char ICON_DIR[3]; char icon_dir[3];
float ABOVE_SUBITEM_OFFSET; float above_subitem_offset;
float ABOVE_ITEM_OFFSET; float above_item_offset;
float ACTIVE_ITEM_FACTOR; float active_item_factor;
float UNDER_ITEM_OFFSET; float under_item_offset;
// Font variables // Font variables
void *font; void *font;
const gl_font_renderer_t *font_driver; const gl_font_renderer_t *font_driver;
char font_path[PATH_MAX]; char font_path[PATH_MAX];
static const GLfloat vtest[] = { static const GLfloat vertex[] = {
0, 0, 0, 0,
1, 0, 1, 0,
0, 1, 0, 1,
1, 1 1, 1,
};
static const GLfloat tex_coord[] = {
0, 1,
1, 1,
0, 0,
1, 0,
}; };
enum enum
@ -117,76 +123,76 @@ static void lakka_responsive(void)
if (!gl) if (!gl)
return; return;
C_ACTIVE_ZOOM = 1.0; c_active_zoom = 1.0;
C_PASSIVE_ZOOM = 0.5; c_passive_zoom = 0.5;
I_ACTIVE_ZOOM = 1.0; i_active_zoom = 1.0;
I_PASSIVE_ZOOM = 0.5; i_passive_zoom = 0.5;
ABOVE_SUBITEM_OFFSET = 1.5; above_subitem_offset = 1.5;
ABOVE_ITEM_OFFSET = -1.0; above_item_offset = -1.0;
ACTIVE_ITEM_FACTOR = 2.25; active_item_factor = 2.25;
UNDER_ITEM_OFFSET = 3.0; under_item_offset = 3.0;
if (gl->win_width >= 2560) if (gl->win_width >= 2560)
{ {
ICON_SIZE = 256; icon_size = 256;
HSPACING = 400; hspacing = 400;
VSPACING = 128; vspacing = 128;
FONT_SIZE = 42.0; lakka_font_size = 42.0;
MARGIN_LEFT = 200.0; margin_left = 200.0;
MARGIN_TOP = 384.0; margin_top = 384.0;
TITLE_MARGIN_LEFT = 20.0; title_margin_left = 20.0;
TITLE_MARGIN_TOP = 50.0; title_margin_top = 50.0;
LABEL_MARGIN_LEFT = 128 + 16.0; label_margin_left = 128 + 16.0;
LABEL_MARGIN_TOP = 15; label_margin_top = 15;
strcpy(ICON_DIR, "256"); strcpy(icon_dir, "256");
return; return;
} }
if (gl->win_width >= 1920) if (1)//(gl->win_width >= 1920)
{ {
ICON_SIZE = 192; icon_size = 192;
HSPACING = 300; hspacing = 300;
VSPACING = 96; vspacing = 96;
FONT_SIZE = 32.0; lakka_font_size = 32.0;
MARGIN_LEFT = 156.0; margin_left = 156.0;
MARGIN_TOP = 288.0; margin_top = 288.0;
TITLE_MARGIN_LEFT = 15.0; title_margin_left = 15.0;
TITLE_MARGIN_TOP = 40.0; title_margin_top = 40.0;
LABEL_MARGIN_LEFT = 96.0 + 12.0; label_margin_left = 96.0 + 12.0;
LABEL_MARGIN_TOP = 11.0; label_margin_top = 11.0;
strcpy(ICON_DIR, "192"); strcpy(icon_dir, "192");
return; return;
} }
if (gl->win_width <= 640) if (gl->win_width <= 640)
{ {
ICON_SIZE = 64; icon_size = 64;
HSPACING = 100.0; hspacing = 100.0;
VSPACING = 32.0; vspacing = 32.0;
FONT_SIZE = 16; lakka_font_size = 16;
MARGIN_LEFT = 60.0; margin_left = 60.0;
MARGIN_TOP = 96.0; margin_top = 96.0;
TITLE_MARGIN_LEFT = 10.0; title_margin_left = 10.0;
TITLE_MARGIN_TOP = 24.0; title_margin_top = 24.0;
LABEL_MARGIN_LEFT = 32.0 + 4.0; label_margin_left = 32.0 + 4.0;
LABEL_MARGIN_TOP = 6.0; label_margin_top = 6.0;
strcpy(ICON_DIR, "64"); strcpy(icon_dir, "64");
return; return;
} }
ICON_SIZE = 128; icon_size = 128;
HSPACING = 200.0; hspacing = 200.0;
VSPACING = 64.0; vspacing = 64.0;
FONT_SIZE = 24; lakka_font_size = 24;
MARGIN_LEFT = 120.0; margin_left = 120.0;
MARGIN_TOP = 192.0; margin_top = 192.0;
TITLE_MARGIN_LEFT = 15.0; title_margin_left = 15.0;
TITLE_MARGIN_TOP = 35.0; title_margin_top = 35.0;
LABEL_MARGIN_LEFT = 64.0 + 8.0; label_margin_left = 64.0 + 8.0;
LABEL_MARGIN_TOP = 8.0; label_margin_top = 8.0;
strcpy(ICON_DIR, "128"); strcpy(icon_dir, "128");
} }
static char *str_replace (const char *string, const char *substr, const char *replacement) static char *str_replace (const char *string, const char *substr, const char *replacement)
@ -312,7 +318,7 @@ static void lakka_draw_text(const char *str, float x, float y, float scale, floa
if (!gl) if (!gl)
return; return;
if (x < -ICON_SIZE || x > gl->win_width + ICON_SIZE || y < -ICON_SIZE || y > gl->win_height + ICON_SIZE) if (x < -icon_size || x > gl->win_width + icon_size || y < -icon_size || y > gl->win_height + icon_size)
return; return;
gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); gl_set_viewport(gl, gl->win_width, gl->win_height, false, false);
@ -347,8 +353,8 @@ void lakka_draw_background(void)
glEnable(GL_BLEND); glEnable(GL_BLEND);
gl->coords.vertex = vtest; gl->coords.vertex = vertex;
gl->coords.tex_coord = vtest; gl->coords.tex_coord = tex_coord;
gl->coords.color = color; gl->coords.color = color;
glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_BG].id); glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_BG].id);
@ -376,7 +382,7 @@ void lakka_draw_icon(GLuint texture, float x, float y, float alpha, float rotati
if (!gl) if (!gl)
return; return;
if (x < -ICON_SIZE || x > gl->win_width + ICON_SIZE || y < -ICON_SIZE || y > gl->win_height + ICON_SIZE) if (x < -icon_size || x > gl->win_width + icon_size || y < -icon_size || y > gl->win_height + icon_size)
return; return;
GLfloat color[] = { GLfloat color[] = {
@ -386,12 +392,12 @@ void lakka_draw_icon(GLuint texture, float x, float y, float alpha, float rotati
1.0f, 1.0f, 1.0f, alpha, 1.0f, 1.0f, 1.0f, alpha,
}; };
glViewport(x, gl->win_height - y, ICON_SIZE, ICON_SIZE); glViewport(x, gl->win_height - y, icon_size, icon_size);
glEnable(GL_BLEND); glEnable(GL_BLEND);
gl->coords.vertex = vtest; gl->coords.vertex = vertex;
gl->coords.tex_coord = vtest; gl->coords.tex_coord = tex_coord;
gl->coords.color = color; gl->coords.color = color;
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
@ -439,14 +445,14 @@ static void lakka_draw_subitems(int i, int j)
&& strcmp(g_extern.fullpath, &active_item->rom) == 0) && strcmp(g_extern.fullpath, &active_item->rom) == 0)
{ {
lakka_draw_icon(textures[TEXTURE_RESUME].id, lakka_draw_icon(textures[TEXTURE_RESUME].id,
MARGIN_LEFT + HSPACING*(i+2.25) + all_categories_x - ICON_SIZE/2.0, margin_left + hspacing*(i+2.25) + all_categories_x - icon_size/2.0,
MARGIN_TOP + subitem->y + ICON_SIZE/2.0, margin_top + subitem->y + icon_size/2.0,
subitem->alpha, subitem->alpha,
0, 0,
subitem->zoom); subitem->zoom);
lakka_draw_text("Resume", lakka_draw_text("Resume",
MARGIN_LEFT + HSPACING*(i+2.25) + all_categories_x + LABEL_MARGIN_LEFT, margin_left + hspacing*(i+2.25) + all_categories_x + label_margin_left,
MARGIN_TOP + subitem->y + LABEL_MARGIN_TOP, margin_top + subitem->y + label_margin_top,
1, 1,
subitem->alpha); subitem->alpha);
} }
@ -457,14 +463,14 @@ static void lakka_draw_subitems(int i, int j)
strcmp(g_extern.fullpath, &active_item->rom) == 0)) strcmp(g_extern.fullpath, &active_item->rom) == 0))
{ {
lakka_draw_icon(subitem->icon, lakka_draw_icon(subitem->icon,
MARGIN_LEFT + HSPACING*(i+2.25) + all_categories_x - ICON_SIZE/2.0, margin_left + hspacing*(i+2.25) + all_categories_x - icon_size/2.0,
MARGIN_TOP + subitem->y + ICON_SIZE/2.0, margin_top + subitem->y + icon_size/2.0,
subitem->alpha, subitem->alpha,
0, 0,
subitem->zoom); subitem->zoom);
lakka_draw_text(subitem->name, lakka_draw_text(subitem->name,
MARGIN_LEFT + HSPACING * (i+2.25) + all_categories_x + LABEL_MARGIN_LEFT, margin_left + hspacing * (i+2.25) + all_categories_x + label_margin_left,
MARGIN_TOP + subitem->y + LABEL_MARGIN_TOP, margin_top + subitem->y + label_margin_top,
1, 1,
subitem->alpha); subitem->alpha);
} }
@ -490,16 +496,16 @@ static void lakka_draw_items(int i)
i <= menu_active_category + 1) // performance improvement i <= menu_active_category + 1) // performance improvement
{ {
lakka_draw_icon(category->item_icon, lakka_draw_icon(category->item_icon,
MARGIN_LEFT + HSPACING*(i+1) + all_categories_x - ICON_SIZE/2.0, margin_left + hspacing*(i+1) + all_categories_x - icon_size/2.0,
MARGIN_TOP + item->y + ICON_SIZE/2.0, margin_top + item->y + icon_size/2.0,
item->alpha, item->alpha,
0, 0,
item->zoom); item->zoom);
if (depth == 0) if (depth == 0)
lakka_draw_text(item->name, lakka_draw_text(item->name,
MARGIN_LEFT + HSPACING * (i+1) + all_categories_x + LABEL_MARGIN_LEFT, margin_left + hspacing * (i+1) + all_categories_x + label_margin_left,
MARGIN_TOP + item->y + LABEL_MARGIN_TOP, margin_top + item->y + label_margin_top,
1, 1,
item->alpha); item->alpha);
} }
@ -525,8 +531,8 @@ static void lakka_draw_categories(void)
// draw category icon // draw category icon
lakka_draw_icon(category->icon, lakka_draw_icon(category->icon,
MARGIN_LEFT + (HSPACING*(i+1)) + all_categories_x - ICON_SIZE/2.0, margin_left + (hspacing*(i+1)) + all_categories_x - icon_size/2.0,
MARGIN_TOP + ICON_SIZE/2.0, margin_top + icon_size/2.0,
category->alpha, category->alpha,
0, 0,
category->zoom); category->zoom);
@ -554,170 +560,31 @@ static void lakka_frame(void)
lakka_draw_categories(); lakka_draw_categories();
if (depth == 0 && active_category) if (depth == 0 && active_category)
lakka_draw_text(active_category->name, TITLE_MARGIN_LEFT, TITLE_MARGIN_TOP, 1, 1.0); lakka_draw_text(active_category->name, title_margin_left, title_margin_top, 1, 1.0);
else if (active_item) else if (active_item)
lakka_draw_text(active_item->name, TITLE_MARGIN_LEFT, TITLE_MARGIN_TOP, 1, 1.0); lakka_draw_text(active_item->name, title_margin_left, title_margin_top, 1, 1.0);
lakka_draw_icon(textures[TEXTURE_ARROW].id, lakka_draw_icon(textures[TEXTURE_ARROW].id,
MARGIN_LEFT + HSPACING*(menu_active_category+1) + all_categories_x + ICON_SIZE/2.0, margin_left + hspacing*(menu_active_category+1) + all_categories_x + icon_size/2.0,
MARGIN_TOP + VSPACING*ACTIVE_ITEM_FACTOR + ICON_SIZE/2.0, arrow_alpha, 0, I_ACTIVE_ZOOM); margin_top + vspacing*active_item_factor + icon_size/2.0, arrow_alpha, 0, i_active_zoom);
gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); gl_set_viewport(gl, gl->win_width, gl->win_height, false, false);
} }
// thanks to https://github.com/DavidEGrayson/ahrs-visualizer/blob/master/png_texture.cpp static GLuint png_texture_load(const char * file_name)
static GLuint png_texture_load(const char * file_name, int * width, int * height)
{ {
png_byte header[8]; struct texture_image ti;
texture_image_load(&ti, file_name);
FILE *fp = fopen(file_name, "rb"); // Generate the OpenGL texture object
if (fp == 0) GLuint texture;
{ glGenTextures(1, &texture);
perror(file_name); glBindTexture(GL_TEXTURE_2D, texture);
return 0; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ti.width, ti.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, ti.pixels);
} glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// read the header return texture;
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;
} }
static void lakka_context_destroy(void *data) static void lakka_context_destroy(void *data)
@ -771,7 +638,7 @@ void lakka_init_settings(void)
strlcpy(category->name, "Settings", sizeof(category->name)); strlcpy(category->name, "Settings", sizeof(category->name));
category->alpha = 1.0; category->alpha = 1.0;
category->zoom = C_ACTIVE_ZOOM; category->zoom = c_active_zoom;
category->active_item = 0; category->active_item = 0;
category->num_items = 0; category->num_items = 0;
category->items = (menu_item_t*)calloc(category->num_items, sizeof(menu_item_t)); category->items = (menu_item_t*)calloc(category->num_items, sizeof(menu_item_t));
@ -788,8 +655,8 @@ void lakka_init_settings(void)
strlcpy(item0->name, "General Options", sizeof(item0->name)); strlcpy(item0->name, "General Options", sizeof(item0->name));
item0->alpha = j ? 0.5 : 1.0; item0->alpha = j ? 0.5 : 1.0;
item0->zoom = j ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM; item0->zoom = j ? i_passive_zoom : i_active_zoom;
item0->y = j ? VSPACING*(UNDER_ITEM_OFFSET+j) : VSPACING * ACTIVE_ITEM_FACTOR; item0->y = j ? vspacing*(under_item_offset+j) : vspacing * active_item_factor;
item0->active_subitem = 0; item0->active_subitem = 0;
item0->num_subitems = 0; item0->num_subitems = 0;
@ -804,8 +671,8 @@ void lakka_init_settings(void)
strlcpy(subitem0->name, "Libretro Logging Level", sizeof(subitem0->name)); strlcpy(subitem0->name, "Libretro Logging Level", sizeof(subitem0->name));
subitem0->alpha = k ? 1.0 : 0.5; subitem0->alpha = k ? 1.0 : 0.5;
subitem0->zoom = k ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM; subitem0->zoom = k ? i_active_zoom : i_passive_zoom;
subitem0->y = k ? VSPACING * (3+k) : VSPACING * ACTIVE_ITEM_FACTOR; subitem0->y = k ? vspacing * (3+k) : vspacing * active_item_factor;
k = 1; k = 1;
item0->num_subitems++; item0->num_subitems++;
@ -816,8 +683,8 @@ void lakka_init_settings(void)
strlcpy(subitem1->name, "Logging Verbosity", sizeof(subitem1->name)); strlcpy(subitem1->name, "Logging Verbosity", sizeof(subitem1->name));
subitem1->alpha = k ? 1.0 : 0.5; subitem1->alpha = k ? 1.0 : 0.5;
subitem1->zoom = k ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM; subitem1->zoom = k ? i_active_zoom : i_passive_zoom;
subitem1->y = k ? VSPACING * (3+k) : VSPACING * ACTIVE_ITEM_FACTOR; subitem1->y = k ? vspacing * (3+k) : vspacing * active_item_factor;
k = 2; k = 2;
item0->num_subitems++; item0->num_subitems++;
@ -828,8 +695,8 @@ void lakka_init_settings(void)
strlcpy(subitem2->name, "Configuration Save On Exit", sizeof(subitem2->name)); strlcpy(subitem2->name, "Configuration Save On Exit", sizeof(subitem2->name));
subitem2->alpha = k ? 1.0 : 0.5; subitem2->alpha = k ? 1.0 : 0.5;
subitem2->zoom = k ? I_ACTIVE_ZOOM : I_PASSIVE_ZOOM; subitem2->zoom = k ? i_active_zoom : i_passive_zoom;
subitem2->y = k ? VSPACING * (3+k) : VSPACING * ACTIVE_ITEM_FACTOR; subitem2->y = k ? vspacing * (3+k) : vspacing * active_item_factor;
// Quit item // Quit item
@ -841,8 +708,8 @@ void lakka_init_settings(void)
strlcpy(item1->name, "Quit RetroArch", sizeof(item1->name)); strlcpy(item1->name, "Quit RetroArch", sizeof(item1->name));
item1->alpha = j ? 0.5 : 1.0; item1->alpha = j ? 0.5 : 1.0;
item1->zoom = j ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM; item1->zoom = j ? i_passive_zoom : i_active_zoom;
item1->y = j ? VSPACING*(UNDER_ITEM_OFFSET+j) : VSPACING * ACTIVE_ITEM_FACTOR; item1->y = j ? vspacing*(under_item_offset+j) : vspacing * active_item_factor;
item1->active_subitem = 0; item1->active_subitem = 0;
item1->num_subitems = 0; item1->num_subitems = 0;
} }
@ -888,12 +755,12 @@ static void lakka_context_reset(void *data)
fill_pathname_join(mediapath, g_settings.assets_directory, "lakka", sizeof(mediapath)); fill_pathname_join(mediapath, g_settings.assets_directory, "lakka", sizeof(mediapath));
fill_pathname_join(themepath, mediapath, THEME, sizeof(themepath)); fill_pathname_join(themepath, mediapath, THEME, sizeof(themepath));
fill_pathname_join(iconpath, themepath, ICON_DIR, sizeof(iconpath)); fill_pathname_join(iconpath, themepath, icon_dir, sizeof(iconpath));
fill_pathname_slash(iconpath, sizeof(iconpath)); fill_pathname_slash(iconpath, sizeof(iconpath));
fill_pathname_join(font_path, themepath, "font.ttf", sizeof(font_path)); fill_pathname_join(font_path, themepath, "font.ttf", sizeof(font_path));
gl_font_init_first(&font_driver, &font, gl, font_path, FONT_SIZE); gl_font_init_first(&font_driver, &font, gl, font_path, lakka_font_size);
fill_pathname_join(textures[TEXTURE_BG].path, iconpath, "bg.png", sizeof(textures[TEXTURE_BG].path)); fill_pathname_join(textures[TEXTURE_BG].path, iconpath, "bg.png", sizeof(textures[TEXTURE_BG].path));
fill_pathname_join(textures[TEXTURE_SETTINGS].path, iconpath, "settings.png", sizeof(textures[TEXTURE_SETTINGS].path)); fill_pathname_join(textures[TEXTURE_SETTINGS].path, iconpath, "settings.png", sizeof(textures[TEXTURE_SETTINGS].path));
@ -908,7 +775,7 @@ static void lakka_context_reset(void *data)
fill_pathname_join(textures[TEXTURE_RELOAD].path, iconpath, "reload.png", sizeof(textures[TEXTURE_RELOAD].path)); fill_pathname_join(textures[TEXTURE_RELOAD].path, iconpath, "reload.png", sizeof(textures[TEXTURE_RELOAD].path));
for (k = 0; k < TEXTURE_LAST; k++) for (k = 0; k < TEXTURE_LAST; k++)
textures[k].id = png_texture_load(textures[k].path, &ICON_SIZE, &ICON_SIZE); textures[k].id = png_texture_load(textures[k].path);
lakka_settings_context_reset(); lakka_settings_context_reset();
for (i = 1; i < num_categories; i++) for (i = 1; i < num_categories; i++)
@ -921,7 +788,7 @@ static void lakka_context_reset(void *data)
fill_pathname_join(mediapath, g_settings.assets_directory, "lakka", sizeof(mediapath)); fill_pathname_join(mediapath, g_settings.assets_directory, "lakka", sizeof(mediapath));
fill_pathname_join(themepath, mediapath, THEME, sizeof(themepath)); fill_pathname_join(themepath, mediapath, THEME, sizeof(themepath));
fill_pathname_join(iconpath, themepath, ICON_DIR, sizeof(iconpath)); fill_pathname_join(iconpath, themepath, icon_dir, sizeof(iconpath));
fill_pathname_slash(iconpath, sizeof(iconpath)); fill_pathname_slash(iconpath, sizeof(iconpath));
info_list = (core_info_list_t*)menu->core_info; info_list = (core_info_list_t*)menu->core_info;
@ -945,8 +812,8 @@ static void lakka_context_reset(void *data)
strlcat(content_texturepath, core_id, sizeof(content_texturepath)); strlcat(content_texturepath, core_id, sizeof(content_texturepath));
strlcat(content_texturepath, "-content.png", sizeof(content_texturepath)); strlcat(content_texturepath, "-content.png", sizeof(content_texturepath));
category->icon = png_texture_load(texturepath, &ICON_SIZE, &ICON_SIZE); category->icon = png_texture_load(texturepath);
category->item_icon = png_texture_load(content_texturepath, &ICON_SIZE, &ICON_SIZE); category->item_icon = png_texture_load(content_texturepath);
for (j = 0; j < category->num_items; j++) for (j = 0; j < category->num_items; j++)
{ {
@ -1005,8 +872,8 @@ static void lakka_init_items(int i, menu_category_t *category, core_info_t *info
strlcpy(item->name, path_basename(list->elems[j].data), sizeof(item->name)); strlcpy(item->name, path_basename(list->elems[j].data), sizeof(item->name));
strlcpy(item->rom, list->elems[j].data, sizeof(item->rom)); strlcpy(item->rom, list->elems[j].data, sizeof(item->rom));
item->alpha = i != menu_active_category ? 0 : n ? 0.5 : 1; item->alpha = i != menu_active_category ? 0 : n ? 0.5 : 1;
item->zoom = n ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM; item->zoom = n ? i_passive_zoom : i_active_zoom;
item->y = n ? VSPACING*(UNDER_ITEM_OFFSET+n) : VSPACING*ACTIVE_ITEM_FACTOR; item->y = n ? vspacing*(under_item_offset+n) : vspacing*active_item_factor;
item->active_subitem = 0; item->active_subitem = 0;
item->num_subitems = 5; item->num_subitems = 5;
item->subitems = (menu_subitem_t*)calloc(item->num_subitems, sizeof(menu_subitem_t)); item->subitems = (menu_subitem_t*)calloc(item->num_subitems, sizeof(menu_subitem_t));
@ -1037,8 +904,8 @@ static void lakka_init_items(int i, menu_category_t *category, core_info_t *info
break; break;
} }
subitem->alpha = 0; subitem->alpha = 0;
subitem->zoom = k ? I_PASSIVE_ZOOM : I_ACTIVE_ZOOM; subitem->zoom = k ? i_passive_zoom : i_active_zoom;
subitem->y = k ? VSPACING * (3+k) : VSPACING * ACTIVE_ITEM_FACTOR; subitem->y = k ? vspacing * (3+k) : vspacing * active_item_factor;
} }
} }
} }
@ -1094,6 +961,8 @@ static void *lakka_init(void)
if (!menu || !gl) if (!menu || !gl)
return NULL; return NULL;
driver.gfx_use_rgba = true;
lakka_responsive(); lakka_responsive();
lakka_init_core_info(menu); lakka_init_core_info(menu);
@ -1116,7 +985,7 @@ static void *lakka_init(void)
strlcpy(category->name, info->display_name, sizeof(category->name)); strlcpy(category->name, info->display_name, sizeof(category->name));
strlcpy(category->libretro, info->path, sizeof(category->libretro)); strlcpy(category->libretro, info->path, sizeof(category->libretro));
category->alpha = 0.5; category->alpha = 0.5;
category->zoom = C_PASSIVE_ZOOM; category->zoom = c_passive_zoom;
category->active_item = 0; category->active_item = 0;
category->num_items = 0; category->num_items = 0;
category->items = (menu_item_t*)calloc(category->num_items, sizeof(menu_item_t)); category->items = (menu_item_t*)calloc(category->num_items, sizeof(menu_item_t));

View File

@ -30,16 +30,16 @@ extern float all_categories_x;
extern int menu_active_category; extern int menu_active_category;
extern float global_alpha; extern float global_alpha;
extern float arrow_alpha; extern float arrow_alpha;
extern float HSPACING; extern float hspacing;
extern float VSPACING; extern float vspacing;
extern float C_ACTIVE_ZOOM; extern float c_active_zoom;
extern float C_PASSIVE_ZOOM; extern float c_passive_zoom;
extern float I_ACTIVE_ZOOM; extern float i_active_zoom;
extern float I_PASSIVE_ZOOM; extern float i_passive_zoom;
extern float ABOVE_SUBITEM_OFFSET; extern float above_subitem_offset;
extern float ABOVE_ITEM_OFFSET; extern float above_item_offset;
extern float ACTIVE_ITEM_FACTOR; extern float active_item_factor;
extern float UNDER_ITEM_OFFSET; extern float under_item_offset;
typedef struct typedef struct
{ {