pandora: allow to move the overlay partially offscreen
authornotaz <notasas@gmail.com>
Sat, 6 Jan 2024 22:46:36 +0000 (00:46 +0200)
committeririxxxx <31696370+irixxxx@users.noreply.github.com>
Sun, 7 Jan 2024 10:32:53 +0000 (11:32 +0100)
to allow to cut off black bars, if the user chooses to do so

platform/pandora/menu.c
platform/pandora/plat.c
platform/pandora/plat.h

index 476af31..45936d9 100644 (file)
@@ -1,5 +1,8 @@
 #include "plat.h"
 
+static int min(int x, int y) { return x < y ? x : y; }
+static int max(int x, int y) { return x > y ? x : y; }
+
 static const char *men_scaler[] = { "1x1, 1x1", "2x2, 3x2", "2x2, 2x2", "fullscreen", "custom", NULL };
 static const char h_scaler[]    = "Scalers for 40 and 32 column modes\n"
                                  "(320 and 256 pixel wide horizontal)";
@@ -8,6 +11,7 @@ static const char h_cscaler[]   = "Displays the scaler layer, you can resize it\
 
 static int menu_loop_cscaler(int id, int keys)
 {
+       int was_layer_clipped = 0;
        unsigned int inp;
 
        currentConfig.scaling = SCALE_CUSTOM;
@@ -15,21 +19,32 @@ static int menu_loop_cscaler(int id, int keys)
        pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
        pnd_restore_layer_data();
 
+       menu_draw_begin(0, 1);
+       menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
+       menu_draw_end();
+
        for (;;)
        {
-               menu_draw_begin(0, 1);
-               menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
-               text_out16(2, 480 - 18, "%dx%d | d-pad to resize, R+d-pad to move", g_layer_cw, g_layer_ch);
-               menu_draw_end();
+               int top_x = max(0, -g_layer_cx * g_screen_ppitch / 800) + 1;
+               int top_y = max(0, -g_layer_cy * g_screen_height / 480) + 1;
+               char text[128];
+               memcpy(g_screen_ptr, g_menubg_src_ptr,
+                       g_screen_ppitch * g_screen_height * 2);
+               snprintf(text, sizeof(text), "%d,%d %dx%d",
+                       g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
+               basic_text_out16_nf(g_screen_ptr, g_screen_ppitch,
+                       saved_start_col + top_x, saved_start_line + top_y, text);
+               basic_text_out16_nf(g_screen_ptr, g_screen_ppitch, 2,
+                       g_screen_height - 20, "d-pad: resize, R+d-pad: move");
+               plat_video_flip();
 
                inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT
                                   |PBTN_R|PBTN_MOK|PBTN_MBACK, NULL, 40);
-               if (inp & PBTN_R) {
-                       if (inp & PBTN_UP)    g_layer_cy--;
-                       if (inp & PBTN_DOWN)  g_layer_cy++;
-                       if (inp & PBTN_LEFT)  g_layer_cx--;
-                       if (inp & PBTN_RIGHT) g_layer_cx++;
-               } else {
+               if (inp & PBTN_UP)    g_layer_cy--;
+               if (inp & PBTN_DOWN)  g_layer_cy++;
+               if (inp & PBTN_LEFT)  g_layer_cx--;
+               if (inp & PBTN_RIGHT) g_layer_cx++;
+               if (!(inp & PBTN_R)) {
                        if (inp & PBTN_UP)    g_layer_ch += 2;
                        if (inp & PBTN_DOWN)  g_layer_ch -= 2;
                        if (inp & PBTN_LEFT)  g_layer_cw += 2;
@@ -39,17 +54,25 @@ static int menu_loop_cscaler(int id, int keys)
                        break;
 
                if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
-                       if (g_layer_cx < 0)   g_layer_cx = 0;
-                       if (g_layer_cx > 640) g_layer_cx = 640;
-                       if (g_layer_cy < 0)   g_layer_cy = 0;
-                       if (g_layer_cy > 420) g_layer_cy = 420;
-                       if (g_layer_cw < 160) g_layer_cw = 160;
-                       if (g_layer_ch < 60)  g_layer_ch = 60;
-                       if (g_layer_cx + g_layer_cw > 800)
-                               g_layer_cw = 800 - g_layer_cx;
-                       if (g_layer_cy + g_layer_ch > 480)
-                               g_layer_ch = 480 - g_layer_cy;
+                       int layer_clipped = 0;
+                       g_layer_cx = max(-320, min(g_layer_cx, 640));
+                       g_layer_cy = max(-240, min(g_layer_cy, 420));
+                       g_layer_cw = max(160, g_layer_cw);
+                       g_layer_ch = max( 60, g_layer_ch);
+                       if (g_layer_cx < 0 || g_layer_cx + g_layer_cw > 800)
+                               layer_clipped = 1;
+                       if (g_layer_cw > 800+400)
+                               g_layer_cw = 800+400;
+                       if (g_layer_cy < 0 || g_layer_cy + g_layer_ch > 480)
+                               layer_clipped = 1;
+                       if (g_layer_ch > 480+360)
+                               g_layer_ch = 480+360;
+                       // resize the layer
                        pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
+                       if (layer_clipped || was_layer_clipped)
+                               emu_video_mode_change(saved_start_line, saved_line_count,
+                                       saved_start_col, saved_col_count);
+                       was_layer_clipped = layer_clipped;
                }
        }
 
@@ -62,9 +85,9 @@ static int menu_loop_cscaler(int id, int keys)
        mee_enum_h    ("Scaler",                   MA_OPT_SCALING,        currentConfig.scaling, \
                                                                          men_scaler, h_scaler), \
        mee_onoff     ("Vsync",                    MA_OPT2_VSYNC,         currentConfig.EmuOpt, EOPT_VSYNC), \
-       mee_cust_h    ("Setup custom scaler",      MA_NONE,               menu_loop_cscaler, NULL, h_cscaler), \
-       mee_range_hide("layer_x",                  MA_OPT3_LAYER_X,       g_layer_cx, 0, 640), \
-       mee_range_hide("layer_y",                  MA_OPT3_LAYER_Y,       g_layer_cy, 0, 420), \
+       mee_cust_s_h  ("Setup custom scaler",      MA_NONE, 0,            menu_loop_cscaler, NULL, h_cscaler), \
+       mee_range_hide("layer_x",                  MA_OPT3_LAYER_X,       g_layer_cx, -320, 640), \
+       mee_range_hide("layer_y",                  MA_OPT3_LAYER_Y,       g_layer_cy, -240, 420), \
        mee_range_hide("layer_w",                  MA_OPT3_LAYER_W,       g_layer_cw, 160, 800), \
        mee_range_hide("layer_h",                  MA_OPT3_LAYER_H,       g_layer_ch,  60, 480), \
 
index be1f578..e072a26 100644 (file)
@@ -38,6 +38,8 @@
 static struct vout_fbdev *main_fb, *layer_fb;\r
 // g_layer_* - in use, g_layer_c* - configured custom\r
 int g_layer_cx = 80, g_layer_cy, g_layer_cw = 640, g_layer_ch = 480;\r
+int saved_start_line = 0, saved_line_count = 240;\r
+int saved_start_col = 0, saved_col_count = 320;\r
 static int g_layer_x, g_layer_y;\r
 static int g_layer_w = 320, g_layer_h = 240;\r
 static int g_osd_start_x, g_osd_fps_x, g_osd_y, doing_bg_frame;\r
@@ -47,22 +49,6 @@ static void *temp_frame;
 const char *renderer_names[] = { NULL };\r
 const char *renderer_names32x[] = { NULL };\r
 \r
-static const char * const pandora_gpio_keys[KEY_MAX + 1] = {\r
-       [KEY_UP]        = "Up",\r
-       [KEY_LEFT]      = "Left",\r
-       [KEY_RIGHT]     = "Right",\r
-       [KEY_DOWN]      = "Down",\r
-       [KEY_HOME]      = "A",\r
-       [KEY_PAGEDOWN]  = "X",\r
-       [KEY_END]       = "B",\r
-       [KEY_PAGEUP]    = "Y",\r
-       [KEY_RIGHTSHIFT]= "L",\r
-       [KEY_RIGHTCTRL] = "R",\r
-       [KEY_LEFTALT]   = "Start",\r
-       [KEY_LEFTCTRL]  = "Select",\r
-       [KEY_MENU]      = "Pandora",\r
-};\r
-\r
 static struct in_default_bind in_evdev_defbinds[] =\r
 {\r
        { KEY_UP,       IN_BINDTYPE_PLAYER12, GBTN_UP },\r
@@ -314,6 +300,13 @@ static int pnd_setup_layer_(int fd, int enabled, int x, int y, int w, int h)
 \r
 int pnd_setup_layer(int enabled, int x, int y, int w, int h)\r
 {\r
+       // it's not allowed for the layer to be partially offscreen,\r
+       // instead it is faked by emu_video_mode_change()\r
+       if (x < 0) { w += x; x = 0; }\r
+       if (y < 0) { h += y; y = 0; }\r
+       if (x + w > 800) w = 800 - x;\r
+       if (y + h > 480) h = 480 - y;\r
+\r
        return pnd_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled, x, y, w, h);\r
 }\r
 \r
@@ -332,26 +325,22 @@ void pnd_restore_layer_data(void)
 \r
 void emu_video_mode_change(int start_line, int line_count, int start_col, int col_count)\r
 {\r
-       int fb_w = 320, fb_h = 240, fb_left = 0, fb_right = 0, fb_top = 0, fb_bottom = 0;\r
+       int fb_w, fb_h = 240, fb_left = 0, fb_right = 0, fb_top = 0, fb_bottom = 0;\r
 \r
        if (doing_bg_frame)\r
                return;\r
 \r
-       fb_w = col_count;\r
-       fb_left = start_col;\r
-       fb_right = 320 - (fb_w + fb_left);\r
-\r
        switch (currentConfig.scaling) {\r
        case SCALE_1x1:\r
-               g_layer_w = fb_w;\r
+               g_layer_w = col_count;\r
                g_layer_h = fb_h;\r
                break;\r
        case SCALE_2x2_3x2:\r
-               g_layer_w = fb_w * (col_count < 320 ? 3 : 2);\r
+               g_layer_w = col_count * (col_count < 320 ? 3 : 2);\r
                g_layer_h = fb_h * 2;\r
                break;\r
        case SCALE_2x2_2x2:\r
-               g_layer_w = fb_w * 2;\r
+               g_layer_w = col_count * 2;\r
                g_layer_h = fb_h * 2;\r
                break;\r
        case SCALE_FULLSCREEN:\r
@@ -376,17 +365,38 @@ void emu_video_mode_change(int start_line, int line_count, int start_col, int co
        case SCALE_FULLSCREEN:\r
        case SCALE_CUSTOM:\r
                fb_top = start_line;\r
-               fb_h = line_count;\r
+               fb_h = start_line + line_count;\r
                break;\r
        }\r
-       g_osd_start_x = start_col;\r
-       g_osd_fps_x = start_col + col_count - 5*8 - 2;\r
-       g_osd_y = fb_top + fb_h - 8;\r
+       fb_w = 320;\r
+       fb_left = start_col;\r
+       fb_right = 320 - (start_col + col_count);\r
+       if (currentConfig.scaling == SCALE_CUSTOM) {\r
+               int right = g_layer_x + g_layer_w;\r
+               int bottom = g_layer_y + g_layer_h;\r
+               if (g_layer_x < 0)\r
+                       fb_left += -g_layer_x * col_count / g_menuscreen_w;\r
+               if (g_layer_y < 0)\r
+                       fb_top += -g_layer_y * line_count / g_menuscreen_h;\r
+               if (right > g_menuscreen_w)\r
+                       fb_right += (right - g_menuscreen_w) * col_count / g_menuscreen_w;\r
+               if (bottom > g_menuscreen_h)\r
+                       fb_bottom += (bottom - g_menuscreen_h) * line_count / g_menuscreen_h;\r
+       }\r
+       fb_w -= fb_left + fb_right;\r
+       fb_h -= fb_top + fb_bottom;\r
 \r
        pnd_setup_layer(1, g_layer_x, g_layer_y, g_layer_w, g_layer_h);\r
        vout_fbdev_resize(layer_fb, fb_w, fb_h, 16, fb_left, fb_right, fb_top, fb_bottom, 4, 0);\r
        vout_fbdev_clear(layer_fb);\r
        plat_video_flip();\r
+\r
+       g_osd_start_x = start_col;\r
+       g_osd_fps_x = start_col + col_count - 5*8 - 2;\r
+       g_osd_y = fb_top + fb_h - 8;\r
+\r
+       saved_start_line = start_line, saved_line_count = line_count;\r
+       saved_start_col = start_col, saved_col_count = col_count;\r
 }\r
 \r
 void plat_video_loop_prepare(void)\r
index 8e6816a..2ac1b09 100644 (file)
@@ -1,6 +1,8 @@
 
 extern int g_layer_cx, g_layer_cy;
 extern int g_layer_cw, g_layer_ch;
+extern int saved_start_line, saved_line_count;
+extern int saved_start_col, saved_col_count;
 
 void pnd_menu_init(void);
 int  pnd_setup_layer(int enabled, int x, int y, int w, int h);