OpenGL: param and key shortcut to control win size

This commit is contained in:
Martin Pulec
2014-01-20 17:28:46 +01:00
parent 216c1b19a9
commit 8445909116

View File

@@ -203,6 +203,8 @@ struct state_gl {
bool show_cursor;
bool should_exit_main_loop;
double window_size_factor;
};
static struct state_gl *gl;
@@ -231,12 +233,24 @@ void NSApplicationLoad(void);
*/
static void gl_show_help(void) {
printf("GL options:\n");
printf("\t-d gl[:d|:fs|:aspect=<v>/<h>|:single|:cursor]* | help\n\n");
printf("\t-d gl[:d|:fs|:aspect=<v>/<h>|:single|:cursor:|size=X%%]* | help\n\n");
printf("\t\td\t\tdeinterlace\n");
printf("\t\tfs\t\tfullscreen\n");
printf("\t\nnovsync\t\tdo not turn sync on VBlank\n");
printf("\t\taspect=<w>/<h>\trequested video aspect (eg. 16/9). Leave unset if PAR = 1.\n");
printf("\t\tcursor\t\tshow visible cursor\n");
printf("\t\tsize\t\tspecifies desired size of window compared "
" to native resolution (in percents)\n");
printf("\n\nKeyboard shortcuts:\n");
printf("\t\t'f'\t\ttoggle fullscreen\n");
printf("\t\t'q'\t\tquit\n");
printf("\t\t'd'\t\ttoggle deinterlace\n");
printf("\t\t' '\t\tpause video\n");
printf("\t\t's'\t\tscreenshot\n");
printf("\t\t'm'\t\tshow/hide cursor\n");
printf("\t\t'+'\t\tmake window smaller by factor 50%%\n");
printf("\t\t'-'\t\tmake window twice as bigger\n");
}
static void gl_load_splashscreen(struct state_gl *s)
@@ -294,6 +308,7 @@ void * display_gl_init(char *fmt, unsigned int flags) {
s->double_buf = TRUE;
s->sync_on_vblank = true;
s->window_size_factor = 1.0;
// parse parameters
if (fmt != NULL) {
@@ -321,6 +336,10 @@ void * display_gl_init(char *fmt, unsigned int flags) {
s->sync_on_vblank = false;
} else if (!strcasecmp(tok, "cursor")) {
s->show_cursor = true;
} else if(!strncmp(tok, "size=",
strlen("size="))) {
s->window_size_factor =
atof(tok + strlen("size=")) / 100.0;
} else {
fprintf(stderr, "[GL] Unknown option: %s\n", tok);
}
@@ -470,7 +489,10 @@ int display_gl_reconfigure(void *state, struct video_desc desc)
static void glut_resize_window(struct state_gl *s)
{
if (!s->fs) {
glutReshapeWindow(s->tile->height * s->aspect, s->tile->height);
glutReshapeWindow(s->window_size_factor *
s->tile->height * s->aspect,
s->window_size_factor *
s->tile->height);
} else {
glutFullScreen();
}
@@ -795,6 +817,14 @@ static void glut_key_callback(unsigned char key, int x, int y)
gl->show_cursor = !gl->show_cursor;
glutSetCursor(gl->show_cursor ? GLUT_CURSOR_CROSSHAIR : GLUT_CURSOR_NONE);
break;
case '+':
gl->window_size_factor *= 2;
glut_resize_window(gl);
break;
case '-':
gl->window_size_factor /= 2;
glut_resize_window(gl);
break;
}
}