cli,video: add --width and --height arguments to set initial window size

This commit is contained in:
Andrei Alexeyev 2024-05-02 00:24:06 +02:00
parent 8d5ffe4b91
commit 4986c89680
No known key found for this signature in database
GPG key ID: 72D26128040B9690
5 changed files with 41 additions and 6 deletions

View file

@ -96,6 +96,8 @@ int cli_args(int argc, char **argv, CLIAction *a) {
{{"credits", no_argument, 0, 'c'}, "Show the credits scene and exit"},
{{"renderer", required_argument, 0, OPT_RENDERER}, "Choose the rendering backend", renderer_list},
{{"populate-cache", no_argument, 0, OPT_POPCACHE}, "Attempt to load all available resources, populating the cache, then exit"},
{{"width", required_argument, 0, 'W'}, "Set window width", "WIDTH"},
{{"height", required_argument, 0, 'H'}, "Set window height", "HEIGHT"},
{{"help", no_argument, 0, 'h'}, "Print help and exit"},
{{"version", no_argument, 0, 'v'}, "Print version and exit"},
{ 0 }
@ -257,6 +259,12 @@ int cli_args(int argc, char **argv, CLIAction *a) {
case OPT_UNLOCKALL:
a->unlock_all = true;
break;
case 'W':
a->width = strtol(optarg, NULL, 10);
break;
case 'H':
a->height = strtol(optarg, NULL, 10);
break;
default:
UNREACHABLE;
}

View file

@ -36,6 +36,8 @@ struct CLIAction {
CutsceneID cutscene;
bool force_intro;
bool unlock_all;
int width;
int height;
};
int cli_args(int argc, char **argv, CLIAction *a);

View file

@ -380,7 +380,10 @@ static void main_post_vfsinit(CallChainResult ccr) {
time_init();
init_global(&ctx->cli);
events_init();
video_init();
video_init(&(VideoInitParams) {
.width = ctx->cli.width,
.height = ctx->cli.height,
});
filewatch_init();
res_init();
r_post_init();

View file

@ -968,7 +968,7 @@ static void video_init_framedump(void) {
memcpy(video.framedump.name_prefix, framedump_dir, video.framedump.name_prefix_len);
}
void video_init(void) {
void video_init(const VideoInitParams *params) {
video_init_sdl();
const char *driver = SDL_GetCurrentVideoDriver();
@ -1007,11 +1007,28 @@ void video_init(void) {
r_init();
int w, h;
bool fullscreen;
if(params->width > 0 || params->height > 0) {
w = params->width;
h = params->height;
fullscreen = false;
if(w <= 0) {
w = rint(h * VIDEO_ASPECT_RATIO);
} else if(h <= 0) {
h = rint(w / VIDEO_ASPECT_RATIO);
}
} else {
w = config_get_int(CONFIG_VID_WIDTH);
h = config_get_int(CONFIG_VID_HEIGHT);
fullscreen = config_get_int(CONFIG_FULLSCREEN);
}
video_set_mode(
config_get_int(CONFIG_VID_DISPLAY),
config_get_int(CONFIG_VID_WIDTH),
config_get_int(CONFIG_VID_HEIGHT),
config_get_int(CONFIG_FULLSCREEN),
w, h, fullscreen,
config_get_int(CONFIG_VID_RESIZABLE)
);

View file

@ -25,6 +25,11 @@ enum {
#define SCREEN_SIZE { SCREEN_W, SCREEN_H }
typedef struct VideoInitParams {
int width;
int height;
} VideoInitParams;
typedef union VideoMode {
// NOTE: These really should be floats, since this represents abstract screen coordinates, not pixels.
// However, SDL's API expects integers everywhere, so it does not really make sense.
@ -62,7 +67,7 @@ typedef enum VideoCapabilityState {
VIDEO_CURRENTLY_UNAVAILABLE,
} VideoCapabilityState;
void video_init(void);
void video_init(const VideoInitParams *params);
void video_post_init(void);
void video_shutdown(void);
void video_set_mode(uint display, uint w, uint h, bool fs, bool resizable);