quick support for doeblesize 'small' font
[libpicofe.git] / common / menu.c
index c2e18fa..b4a76cc 100644 (file)
@@ -33,10 +33,14 @@ static int  menu_error_time = 0;
 static unsigned char *menu_font_data = NULL;\r
 static int menu_text_color = 0xffff; // default to white\r
 static int menu_sel_color = -1; // disabled\r
+\r
+/* note: these might become non-constant in future */\r
 #if MENU_X2\r
 static const int me_mfont_w = 16, me_mfont_h = 20;\r
+static const int me_sfont_w = 12, me_sfont_h = 20;\r
 #else\r
 static const int me_mfont_w = 8, me_mfont_h = 10;\r
+static const int me_sfont_w = 6, me_sfont_h = 10;\r
 #endif\r
 \r
 // draws text to current bbp16 screen\r
@@ -113,35 +117,41 @@ void text_out16(int x, int y, const char *texto, ...)
        text_out16_(x,y,buffer,menu_text_color);\r
 }\r
 \r
-\r
+/* draws in 6x8 font, might multiply size by integer */\r
 static void smalltext_out16_(int x, int y, const char *texto, int color)\r
 {\r
-       int i;\r
        unsigned char  *src;\r
        unsigned short *dst;\r
+       int multiplier = me_sfont_w / 6;\r
+       int i;\r
 \r
-       for (i = 0;; i++, x += 6)\r
+       for (i = 0;; i++, x += me_sfont_w)\r
        {\r
                unsigned char c = (unsigned char) texto[i];\r
                int h = 8;\r
 \r
-               if (!c) break;\r
+               if (!c || c == '\n')\r
+                       break;\r
 \r
                src = fontdata6x8[c];\r
                dst = (unsigned short *)g_screen_ptr + x + y * g_screen_width;\r
 \r
                while (h--)\r
                {\r
-                       int w = 0x20;\r
-                       while (w)\r
+                       int m, w2, h2;\r
+                       for (h2 = multiplier; h2 > 0; h2--)\r
                        {\r
-                               if( *src & w ) *dst = color;\r
-                               dst++;\r
-                               w>>=1;\r
+                               for (m = 0x20; m; m >>= 1) {\r
+                                       if (*src & m)\r
+                                               for (w2 = multiplier; w2 > 0; w2--)\r
+                                                       *dst++ = color;\r
+                                       else\r
+                                               dst += multiplier;\r
+                               }\r
+\r
+                               dst += g_screen_width - me_sfont_w;\r
                        }\r
                        src++;\r
-\r
-                       dst += g_screen_width - 6;\r
                }\r
        }\r
 }\r
@@ -585,15 +595,15 @@ static void cdload_progress_cb(int percent)
        int ln, len = percent * g_screen_width / 100;\r
        unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2;\r
 \r
-       memset(dst, 0xff, g_screen_width * (10 - 2) * 2);\r
+       memset(dst, 0xff, g_screen_width * (me_sfont_h - 2) * 2);\r
 \r
-       smalltext_out16(1, 3 * 10, "Processing CD image / MP3s", 0xffff);\r
-       smalltext_out16(1, 4 * 10, rom_fname_loaded, 0xffff);\r
-       dst += g_screen_width * 30;\r
+       smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);\r
+       smalltext_out16(1, 4 * me_sfont_h, rom_fname_loaded, 0xffff);\r
+       dst += g_screen_width * me_sfont_h * 3;\r
 \r
        if (len > g_screen_width)\r
                len = g_screen_width;\r
-       for (ln = (10 - 2); ln > 0; ln--, dst += g_screen_width)\r
+       for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_screen_width)\r
                memset(dst, 0xff, len * 2);\r
 \r
        plat_video_menu_end();\r
@@ -610,12 +620,12 @@ void menu_romload_prepare(const char *rom_name)
        /* fill both buffers, callbacks won't update in full */\r
        plat_video_menu_begin();\r
        smalltext_out16(1, 1, "Loading", 0xffff);\r
-       smalltext_out16(1, 10, p, 0xffff);\r
+       smalltext_out16(1, me_sfont_h, p, 0xffff);\r
        plat_video_menu_end();\r
 \r
        plat_video_menu_begin();\r
        smalltext_out16(1, 1, "Loading", 0xffff);\r
-       smalltext_out16(1, 10, p, 0xffff);\r
+       smalltext_out16(1, me_sfont_h, p, 0xffff);\r
        plat_video_menu_end();\r
 \r
        PicoCartLoadProgressCB = load_progress_cb;\r
@@ -626,7 +636,7 @@ void menu_romload_prepare(const char *rom_name)
 void menu_romload_end(void)\r
 {\r
        PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL;\r
-       smalltext_out16(1, (cdload_called ? 6 : 3) * 10,\r
+       smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,\r
                "Starting emulation...", 0xffff);\r
        plat_video_menu_end();\r
 }\r
@@ -651,9 +661,9 @@ static unsigned short file2color(const char *fname)
 \r
 static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
 {\r
-       int max_cnt, start, i, pos;\r
+       int max_cnt, start, i, x, pos;\r
 \r
-       max_cnt = g_screen_height / 10;\r
+       max_cnt = g_screen_height / me_sfont_h;\r
        start = max_cnt / 2 - sel;\r
        n--; // exclude current dir (".")\r
 \r
@@ -664,21 +674,22 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)
 \r
        menu_darken_bg((short *)g_screen_ptr + g_screen_width * max_cnt/2 * 10, g_screen_width * 8, 0);\r
 \r
+       x = 5 + me_mfont_w + 1;\r
        if (start - 2 >= 0)\r
-               smalltext_out16(14, (start - 2)*10, curdir, 0xffff);\r
+               smalltext_out16(14, (start - 2) * me_sfont_h, curdir, 0xffff);\r
        for (i = 0; i < n; i++) {\r
                pos = start + i;\r
                if (pos < 0)  continue;\r
                if (pos >= max_cnt) break;\r
                if (namelist[i+1]->d_type == DT_DIR) {\r
-                       smalltext_out16(14,   pos*10, "/", 0xfff6);\r
-                       smalltext_out16(14+6, pos*10, namelist[i+1]->d_name, 0xfff6);\r
+                       smalltext_out16(x, pos * me_sfont_h, "/", 0xfff6);\r
+                       smalltext_out16(x + me_sfont_w, pos * me_sfont_h, namelist[i+1]->d_name, 0xfff6);\r
                } else {\r
                        unsigned short color = file2color(namelist[i+1]->d_name);\r
-                       smalltext_out16(14,   pos*10, namelist[i+1]->d_name, color);\r
+                       smalltext_out16(x, pos * me_sfont_h, namelist[i+1]->d_name, color);\r
                }\r
        }\r
-       smalltext_out16(5, max_cnt/2 * 10, ">", 0xffff);\r
+       smalltext_out16(5, max_cnt/2 * me_sfont_h, ">", 0xffff);\r
        plat_video_menu_end();\r
 }\r
 \r
@@ -855,14 +866,14 @@ static void draw_patchlist(int sel)
                if (pos < 0) continue;\r
                if (pos >= max_cnt) break;\r
                active = PicoPatches[i].active;\r
-               smalltext_out16(14,     pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);\r
-               smalltext_out16(14+6*4, pos*10, PicoPatches[i].name,    active ? 0xfff6 : 0xffff);\r
+               smalltext_out16(14,     pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);\r
+               smalltext_out16(14+6*4, pos * me_sfont_h, PicoPatches[i].name,    active ? 0xfff6 : 0xffff);\r
        }\r
        pos = start + i;\r
        if (pos < max_cnt)\r
-               smalltext_out16(14, pos * 10, "done", 0xffff);\r
+               smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);\r
 \r
-       text_out16(5, max_cnt / 2 * 10, ">");\r
+       text_out16(5, max_cnt / 2 * me_sfont_h, ">");\r
        plat_video_menu_end();\r
 }\r
 \r
@@ -965,7 +976,7 @@ static void draw_savestate_menu(int menu_sel, int is_loading)
        if (state_slot_flags & (1 << menu_sel))\r
                draw_savestate_bg(menu_sel);\r
 \r
-       w = 13 * me_mfont_w + me_mfont_w * 2;\r
+       w = (13 + 2) * me_mfont_w;\r
        h = (1+2+10+1) * me_mfont_h;\r
        x = g_screen_width / 2 - w / 2;\r
        if (x < 0) x = 0;\r
@@ -1048,6 +1059,7 @@ static char *action_binds(int player_idx, int action_mask, int dev_id)
        for (k = 0; k < count; k++)\r
        {\r
                const char *xname;\r
+               int len;\r
                if (!(binds[k] & action_mask))\r
                        continue;\r
 \r
@@ -1055,9 +1067,12 @@ static char *action_binds(int player_idx, int action_mask, int dev_id)
                        continue;\r
 \r
                xname = in_get_key_name(dev_id, k);\r
-               if (static_buff[0])\r
-                       strncat(static_buff, " + ", sizeof(static_buff));\r
-               strncat(static_buff, xname, sizeof(static_buff));\r
+               len = strlen(static_buff);\r
+               if (len) {\r
+                       strncat(static_buff, " + ", sizeof(static_buff) - len - 1);\r
+                       len += 3;\r
+               }\r
+               strncat(static_buff, xname, sizeof(static_buff) - len - 1);\r
        }\r
 \r
        return static_buff;\r
@@ -1677,9 +1692,6 @@ static int menu_loop_options(menu_id id, int keys)
 \r
 // ------------ debug menu ------------\r
 \r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
-\r
 #include <pico/debug.h>\r
 \r
 extern void SekStepM68k(void);\r
@@ -1707,17 +1719,21 @@ static void draw_text_debug(const char *str, int skip, int from)
        p = str;\r
        while (skip-- > 0)\r
        {\r
-               while (*p && *p != '\n') p++;\r
-               if (*p == 0 || p[1] == 0) return;\r
+               while (*p && *p != '\n')\r
+                       p++;\r
+               if (*p == 0 || p[1] == 0)\r
+                       return;\r
                p++;\r
        }\r
 \r
        str = p;\r
-       for (line = from; line < g_screen_height / 10; line++)\r
+       for (line = from; line < g_screen_height / me_sfont_h; line++)\r
        {\r
-               while (*p && *p != '\n') p++;\r
-               smalltext_out16(1, line*10, str, 0xffff);\r
-               if (*p == 0) break;\r
+               smalltext_out16(1, line * me_sfont_h, str, 0xffff);\r
+               while (*p && *p != '\n')\r
+                       p++;\r
+               if (*p == 0)\r
+                       break;\r
                p++; str = p;\r
        }\r
 }\r
@@ -1732,7 +1748,7 @@ static void draw_frame_debug(void)
 \r
        memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);\r
        emu_forcedFrame(0);\r
-       smalltext_out16(4, g_screen_height - 8, layer_str, 0xffff);\r
+       smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff);\r
 }\r
 \r
 static void debug_menu_loop(void)\r
@@ -1750,7 +1766,7 @@ static void debug_menu_loop(void)
                                emu_platformDebugCat(tmp);\r
                                draw_text_debug(tmp, 0, 0);\r
                                if (dumped) {\r
-                                       smalltext_out16(g_screen_width - 6 * me_mfont_h,\r
+                                       smalltext_out16(g_screen_width - 6 * me_sfont_h,\r
                                                g_screen_height - me_mfont_h, "dumped", 0xffff);\r
                                        dumped = 0;\r
                                }\r