[sdl2] add --scale=<float> option to scale up/down the size of SDL2's window

This commit is contained in:
Gwenhael Le Moine 2024-09-07 21:13:47 +02:00
parent a5ff52d7c0
commit a825ed2ba6
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
4 changed files with 19 additions and 1 deletions

2
dist/x48ng.man.1 vendored
View file

@ -100,6 +100,8 @@ where options include (depending on compiled front-ends):
\-\-no\-chrome only display the LCD (default: false)
.br
\-\-fullscreen make the UI fullscreen (default: false)
.br
\-\-scale=<float> scale the SDL2 UI by <float>
.br
\-\-netbook make the UI horizontal (default: false)
.br

View file

@ -43,6 +43,7 @@ config_t config = {
/* sdl */
.hide_chrome = false,
.show_ui_fullscreen = false,
.scale = 1.0,
/* x11 */
.netbook = false,
@ -245,6 +246,7 @@ int config_init( int argc, char* argv[] )
int clopt_throttle = -1;
int clopt_hide_chrome = -1;
int clopt_show_ui_fullscreen = -1;
double clopt_scale = -1.0;
int clopt_netbook = -1;
int clopt_mono = -1;
int clopt_gray = -1;
@ -282,6 +284,7 @@ int config_init( int argc, char* argv[] )
{"sdl", no_argument, &clopt_frontend_type, FRONTEND_SDL },
{"no-chrome", no_argument, &clopt_hide_chrome, true },
{"fullscreen", no_argument, &clopt_show_ui_fullscreen, true },
{"scale", required_argument, NULL, 7110 },
{"x11", no_argument, &clopt_frontend_type, FRONTEND_X11 },
{"netbook", no_argument, &clopt_netbook, true },
@ -404,6 +407,9 @@ int config_init( int argc, char* argv[] )
case 1015:
clopt_serialLine = optarg;
break;
case 7110:
clopt_scale = atof( optarg );
break;
case 8110:
clopt_x11_visual = optarg;
break;
@ -562,6 +568,9 @@ int config_init( int argc, char* argv[] )
lua_getglobal( config_lua_values, "fullscreen" );
config.show_ui_fullscreen = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "scale" );
config.scale = lua_tonumber( config_lua_values, -1.0 );
lua_getglobal( config_lua_values, "netbook" );
config.netbook = lua_toboolean( config_lua_values, -1 );
@ -644,6 +653,8 @@ int config_init( int argc, char* argv[] )
config.hide_chrome = clopt_hide_chrome;
if ( clopt_show_ui_fullscreen != -1 )
config.show_ui_fullscreen = clopt_show_ui_fullscreen;
if ( clopt_scale != -1.0 )
config.scale = clopt_scale;
if ( clopt_netbook != -1 )
config.netbook = clopt_netbook;
if ( clopt_mono != -1 )
@ -715,6 +726,7 @@ int config_init( int argc, char* argv[] )
fprintf( stdout, "\" -- possible values: \"x11\", \"sdl2\", \"sdl\" (deprecated), \"tui\", \"tui-small\", \"tui-tiny\"\n" );
fprintf( stdout, "hide_chrome = %s\n", config.hide_chrome ? "true" : "false" );
fprintf( stdout, "fullscreen = %s\n", config.show_ui_fullscreen ? "true" : "false" );
fprintf( stdout, "scale = %f -- applies only to sdl2\n", config.scale );
fprintf( stdout, "mono = %s\n", config.mono ? "true" : "false" );
fprintf( stdout, "gray = %s\n", config.gray ? "true" : "false" );
fprintf( stdout, "leave_shift_keys = %s\n", config.leave_shift_keys ? "true" : "false" );

View file

@ -35,6 +35,7 @@ typedef struct {
/* sdl */
bool hide_chrome;
bool show_ui_fullscreen;
double scale;
/* x11 */
bool netbook;

View file

@ -1101,7 +1101,8 @@ void init_sdl2_ui( int argc, char** argv )
else
window_flags |= SDL_WINDOW_RESIZABLE;
window = SDL_CreateWindow( config.progname, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, window_flags );
window = SDL_CreateWindow( config.progname, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width * config.scale,
height * config.scale, window_flags );
if ( window == NULL ) {
printf( "Couldn't create window: %s\n", SDL_GetError() );
exit( 1 );
@ -1111,6 +1112,8 @@ void init_sdl2_ui( int argc, char** argv )
if ( renderer == NULL )
exit( 2 );
SDL_RenderSetLogicalSize( renderer, width, height );
main_texture = SDL_CreateTexture( renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height );
SDL_SetRenderTarget( renderer, main_texture );