#include "../../input.h"\r
#include "../../state.h"\r
#include "../../palette.h"\r
+#include "readpng.h"\r
\r
#ifndef _DIRENT_HAVE_D_TYPE\r
#error "need d_type for file browser\r
\r
\r
static char path_buffer[PATH_MAX];\r
+static unsigned short *menu_bg = 0;\r
+static int txt_xmin, txt_xmax, txt_ymin, txt_ymax;\r
\r
char menuErrorMsg[40] = {0, };\r
\r
-// TODO\r
-void gp2x_fceu_copy_bg(void)\r
+static void gp2x_fceu_darken_reset(void)\r
+{\r
+ txt_xmin = 320; txt_xmax = 0;\r
+ txt_ymin = 240; txt_ymax = 0;\r
+}\r
+\r
+static void gp2x_fceu_copy_bg(void)\r
+{\r
+ if (menu_bg)\r
+ memcpy(gp2x_screen, menu_bg, 320*240*2);\r
+ else memset(gp2x_screen, 0, 320*240*2);\r
+ gp2x_fceu_darken_reset();\r
+}\r
+\r
+static void gp2x_fceu_darken_text_bg(void)\r
{\r
- memset(gp2x_screen, 0, 320*240*2);\r
+ int x, y, xmin, xmax, ymax;\r
+ unsigned short *screen = gp2x_screen;\r
+\r
+ xmin = txt_xmin - 3;\r
+ if (xmin < 0) xmin = 0;\r
+ xmax = txt_xmax + 2;\r
+ if (xmax > 319) xmax = 319;\r
+\r
+ y = txt_ymin - 3;\r
+ if (y < 0) y = 0;\r
+ ymax = txt_ymax + 2;\r
+ if (ymax > 239) ymax = 239;\r
+\r
+ for (x = xmin; x <= xmax; x++)\r
+ screen[y*320+x] = 0xa514;\r
+ for (y++; y < ymax; y++)\r
+ {\r
+ screen[y*320+xmin] = 0xffff;\r
+ for (x = xmin+1; x < xmax; x++)\r
+ {\r
+ unsigned int p = screen[y*320+x];\r
+ if (p != 0xffff)\r
+ screen[y*320+x] = ((p&0xf79e)>>1) - ((p&0xc618)>>3);\r
+ }\r
+ screen[y*320+xmax] = 0xffff;\r
+ }\r
+ for (x = xmin; x <= xmax; x++)\r
+ screen[y*320+x] = 0xffff;\r
+}\r
+\r
+static void gp2x_fceu_darken_all(void)\r
+{\r
+ unsigned int *screen = gp2x_screen;\r
+ int count = 320*240/2;\r
+\r
+ while (count--)\r
+ {\r
+ unsigned int p = screen[count];\r
+ screen[count] = ((p&0xf79ef79e)>>1) - ((p&0xc618c618)>>3);\r
+ }\r
}\r
\r
// draws white text to current bbp15 screen\r
}\r
screen += 8;\r
}\r
+ if (x < txt_xmin) txt_xmin = x;\r
+ if (x+i*8 > txt_xmax) txt_xmax = x+i*8;\r
+ if (y < txt_ymin) txt_ymin = y;\r
+ if (y+8 > txt_ymax) txt_ymax = y+8;\r
}\r
\r
void gp2x_text_out15(int x, int y, const char *texto, ...)\r
start = 12 - sel;\r
n--; // exclude current dir (".")\r
\r
- //memset(gp2x_screen, 0, 320*240);\r
gp2x_fceu_copy_bg();\r
+ gp2x_fceu_darken_all();\r
\r
if(start - 2 >= 0)\r
gp2x_smalltext8_lim(14, (start - 2)*10, curdir, 53-2);\r
} else {\r
strcpy(newdir, curr_path);\r
p = newdir + strlen(newdir) - 1;\r
- while (*p == '/' && p >= newdir) *p-- = 0;\r
+ while (p >= newdir && *p == '/') *p-- = 0;\r
strcat(newdir, "/");\r
strcat(newdir, namelist[sel+1]->d_name);\r
}\r
// draw cursor\r
gp2x_text_out15(x - 16, tl_y + sel*10, ">");\r
\r
+ gp2x_fceu_darken_text_bg();\r
+ gp2x_fceu_darken_reset();\r
+\r
if (sel < opt_cnt) {\r
gp2x_text_out15(30, 190, "Press a button to bind/unbind");\r
gp2x_text_out15(30, 200, "Use VOL+ to clear");\r
gp2x_text_out15(30, 210, "to save controls");\r
gp2x_text_out15(30, 220, "Press B or X to exit");\r
}\r
+ gp2x_fceu_darken_text_bg();\r
gp2x_video_flip();\r
}\r
\r
gp2x_text_out15(tl_x, (y+=10), "none");\r
}\r
\r
+ gp2x_fceu_darken_text_bg();\r
gp2x_video_flip();\r
}\r
\r
gp2x_text_out15(tl_x, (y+=10), "Disable 8 sprite limit %s", (eoptions&EO_NO8LIM)?"ON":"OFF");\r
gp2x_text_out15(tl_x, (y+=10), "Done"); // 10\r
\r
+ // draw cursor\r
+ gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
+\r
if (menu_sel == 0) {\r
+ gp2x_fceu_darken_text_bg();\r
+ gp2x_fceu_darken_reset();\r
+\r
gp2x_text_out15(30, 210, "Press B to browse,");\r
gp2x_text_out15(30, 220, "START to use default");\r
}\r
\r
- // draw cursor\r
- gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
-\r
+ gp2x_fceu_darken_text_bg();\r
gp2x_video_flip();\r
}\r
\r
// draw cursor\r
gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
\r
+ gp2x_fceu_darken_text_bg();\r
gp2x_video_flip();\r
}\r
\r
static int menu_loop_options(void)\r
{\r
static int menu_sel = 0;\r
- int menu_sel_max = 15;\r
+ int menu_sel_max = 14;\r
unsigned long inp = 0;\r
\r
if (fceugi) menu_sel_max++;\r
gp2x_text_out15(20, 180, " cpuctrl, gamma libs");\r
gp2x_text_out15(20, 190, "Squidge: squidgehack");\r
\r
+ gp2x_fceu_darken_text_bg();\r
gp2x_video_flip();\r
}\r
\r
\r
// draw cursor\r
gp2x_text_out15(tl_x - 16, tl_y + menu_sel*10, ">");\r
- // error\r
+\r
+ gp2x_fceu_darken_text_bg();\r
+ gp2x_fceu_darken_reset();\r
+\r
+ // error / version\r
if (menuErrorMsg[0]) gp2x_text_out15(1, 230, menuErrorMsg);\r
else {\r
char vstr[16];\r
sprintf(vstr, "v" GP2X_PORT_VERSION " r%i", GP2X_PORT_REV);\r
gp2x_text_out15(320-strlen(vstr)*8-1, 230, vstr);\r
}\r
+ gp2x_fceu_darken_text_bg();\r
gp2x_video_flip();\r
}\r
\r
}\r
\r
\r
+extern unsigned short gp2x_palette16[256];\r
+\r
static void menu_prepare_bg(void)\r
{\r
- // TODO...\r
+ menu_bg = malloc(320*240*2);\r
+ if (menu_bg == NULL) return;\r
+\r
+ if (fceugi)\r
+ {\r
+ /* raw emu frame should now be at gp2x_screen */\r
+ soft_scale((char *)gp2x_screen + 32, gp2x_palette16, srendline, erendline-srendline);\r
+ if (srendline)\r
+ memset32((int *)((char *)gp2x_screen + 32), 0, srendline*320*2/4);\r
+ memcpy(menu_bg, gp2x_screen + 32, 320*240*2);\r
+ }\r
+ else\r
+ {\r
+ memset32((int *)menu_bg, 0, 320*240*2/4);\r
+ readpng(menu_bg, "background.png");\r
+ }\r
}\r
\r
static void menu_gfx_prepare(void)\r
\r
ret = menu_loop_root();\r
\r
+ if (menu_bg) free(menu_bg);\r
+ menu_bg = NULL;\r
menuErrorMsg[0] = 0;\r
\r
return ret;\r
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <png.h>
+
+void readpng(unsigned short *dest, const char *fname)
+{
+ FILE *fp;
+ png_structp png_ptr = NULL;
+ png_infop info_ptr = NULL;
+ png_bytepp row_ptr = NULL;
+ int height, width, h;
+
+ if (dest == NULL || fname == NULL)
+ {
+ return;
+ }
+
+ fp = fopen(fname, "rb");
+ if (fp == NULL)
+ {
+ printf(__FILE__ ": failed to open: %s\n", fname);
+ return;
+ }
+
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ if (!png_ptr)
+ {
+ printf(__FILE__ ": png_create_read_struct() failed\n");
+ fclose(fp);
+ return;
+ }
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ printf(__FILE__ ": png_create_info_struct() failed\n");
+ goto done;
+ }
+
+ // Start reading
+ png_init_io(png_ptr, fp);
+ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_PACKING, NULL);
+ row_ptr = png_get_rows(png_ptr, info_ptr);
+ if (row_ptr == NULL)
+ {
+ printf(__FILE__ ": png_get_rows() failed\n");
+ goto done;
+ }
+
+ height = info_ptr->height;
+ if (height > 240) height = 240;
+ width = info_ptr->width;
+ if (width > 320) width = 320;
+
+ for (h = 0; h < height; h++)
+ {
+ unsigned char *src = row_ptr[h];
+ int len = width;
+ while (len--)
+ {
+ *dest++ = ((src[0]&0xf8)<<8) | ((src[1]&0xf8)<<3) | (src[2] >> 3);
+ src += 3;
+ }
+ dest += 320 - width;
+ }
+
+
+done:
+ png_destroy_read_struct(&png_ptr, info_ptr ? &info_ptr : NULL, (png_infopp)NULL);
+ fclose(fp);
+}
+