From ff962b820465f9fc9de4cafc8fa8d3838d7ac0b9 Mon Sep 17 00:00:00 2001 From: Taylor Richards Date: Mon, 28 Apr 2014 10:59:59 -0400 Subject: [PATCH] clean up fullscreen code; fill/plug in gr_toggle_fullscreen --- include/2d.h | 2 ++ include/gropenglinternal.h | 1 + src/graphics/2d.cpp | 13 ++++++++++++- src/graphics/gropengl.cpp | 39 +++++++++++++++++++------------------- src/graphics/gropengl1.cpp | 2 ++ src/osapi/osapi.cpp | 4 +--- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/include/2d.h b/include/2d.h index 928e902..b4add84 100644 --- a/include/2d.h +++ b/include/2d.h @@ -549,6 +549,8 @@ typedef struct screen { void (*gf_force_windowed)(); void (*gf_force_fullscreen)(); + void (*gf_toggle_fullscreen)(); + void (*gf_set_viewport)(int width, int height); void (*gf_activate)(int active); diff --git a/include/gropenglinternal.h b/include/gropenglinternal.h index 4674f24..2498f8f 100644 --- a/include/gropenglinternal.h +++ b/include/gropenglinternal.h @@ -53,6 +53,7 @@ void gr_opengl_get_color( int * r, int * g, int * b ); void gr_opengl_set_color_fast(color *dst); void gr_opengl_force_fullscreen(); void gr_opengl_force_windowed(); +void gr_opengl_toggle_fullscreen(); void gr_opengl_set_viewport(int width, int height); int gr_opengl_zbuffer_get(); int gr_opengl_zbuffer_set(int mode); diff --git a/src/graphics/2d.cpp b/src/graphics/2d.cpp index 171ce02..80a1043 100644 --- a/src/graphics/2d.cpp +++ b/src/graphics/2d.cpp @@ -747,7 +747,18 @@ void gr_toggle_fullscreen() return; } - STUB_FUNCTION; + // skip if a tool is running + if ( Fred_running || Pofview_running || Nebedit_running ) { + return; + } + + if (gr_screen.gf_toggle_fullscreen) { + (*gr_screen.gf_toggle_fullscreen)(); + } + + if (Os_debugger_running) { + SDL_Delay(1000); + } } void gr_activate(int active) diff --git a/src/graphics/gropengl.cpp b/src/graphics/gropengl.cpp index 7a45b30..52f95b9 100644 --- a/src/graphics/gropengl.cpp +++ b/src/graphics/gropengl.cpp @@ -16,6 +16,7 @@ #include "grinternal.h" #include "cmdline.h" #include "mouse.h" +#include "osapi.h" bool OGL_inited = false; @@ -123,14 +124,18 @@ void gr_opengl_force_windowed() void gr_opengl_force_fullscreen() { - int fullscreen = os_config_read_uint(NULL, "Fullscreen", 1); - int flag = SDL_WINDOW_FULLSCREEN_DESKTOP; + SDL_SetWindowFullscreen(GL_window, SDL_WINDOW_FULLSCREEN_DESKTOP); +} - if (fullscreen == 2) { - flag = SDL_WINDOW_FULLSCREEN; - } +void gr_opengl_toggle_fullscreen() +{ + Uint32 flags = SDL_GetWindowFlags(GL_window); - SDL_SetWindowFullscreen(GL_window, flag); + if ( (flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP ) { + gr_opengl_force_windowed(); + } else { + gr_opengl_force_fullscreen(); + } } void gr_opengl_set_color_fast(color *dst) @@ -330,27 +335,23 @@ void gr_opengl_init() SDL_DisableScreenSaver(); SDL_ShowCursor(0); - // initial setup viewport + // initial viewport setup gr_opengl_set_viewport(gr_screen.max_w, gr_screen.max_h); - // maybe go fullscreen - should be done *after* initial viewport setup - int fullscreen = os_config_read_uint(NULL, "Fullscreen", 1); - if ( !Cmdline_window && (fullscreen || Cmdline_fullscreen) ) { - int flag = SDL_WINDOW_FULLSCREEN_DESKTOP; - - if (fullscreen == 2) { - flag = SDL_WINDOW_FULLSCREEN; - } - - SDL_SetWindowFullscreen(GL_window, flag); - } - // set up generic variables before further init() calls opengl_set_variables(); // main GL init opengl1_init(); + // maybe go fullscreen - should be done *after* main GL init + int fullscreen = os_config_read_uint(NULL, "Fullscreen", 1); + if ( !Cmdline_window && (fullscreen || Cmdline_fullscreen) ) { + SDL_SetWindowFullscreen(GL_window, SDL_WINDOW_FULLSCREEN_DESKTOP); + // poll for window events + os_poll(); + } + mprintf(("\n")); diff --git a/src/graphics/gropengl1.cpp b/src/graphics/gropengl1.cpp index ec00435..4b52545 100644 --- a/src/graphics/gropengl1.cpp +++ b/src/graphics/gropengl1.cpp @@ -182,6 +182,8 @@ static void opengl1_init_func_pointers() gr_screen.gf_force_windowed = gr_opengl_force_windowed; gr_screen.gf_force_fullscreen = gr_opengl_force_fullscreen; + gr_screen.gf_toggle_fullscreen = gr_opengl_toggle_fullscreen; + gr_screen.gf_set_viewport = gr_opengl_set_viewport; gr_screen.gf_activate = gr_opengl1_activate; diff --git a/src/osapi/osapi.cpp b/src/osapi/osapi.cpp index 2b7b4b8..7ad9421 100644 --- a/src/osapi/osapi.cpp +++ b/src/osapi/osapi.cpp @@ -339,9 +339,7 @@ void os_poll() case SDL_KEYDOWN: { if (e.key.keysym.mod & KMOD_GUI) { if (e.key.keysym.sym == SDLK_f ) { - gr_force_fullscreen(); - } else if (e.key.keysym.sym == SDLK_w) { - gr_force_windowed(); + gr_toggle_fullscreen(); // } else if (e.key.keysym.sym == SDLK_z) { // SDL_MinimizeWindow(GL_window); } -- 2.39.2