pandora: allow to move the overlay partially offscreen

to allow to cut off black bars, if the user chooses to do so
This commit is contained in:
notaz 2024-01-07 00:46:36 +02:00 committed by irixxxx
parent 70db485b44
commit ca980e1b0a
3 changed files with 86 additions and 51 deletions

View 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), \