From dd9395e65d98e08517c14ce33fd59953ae2482a0 Mon Sep 17 00:00:00 2001 From: gewlitys Date: Fri, 27 Jul 2007 23:19:40 +0000 Subject: [PATCH] added fullscreen/windowed toggle key F11 git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2821 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 1 + sc2/content/menu.key | 1 + sc2/doc/users/manual.txt | 1 + sc2/src/sc2code/controls.h | 1 + sc2/src/sc2code/libs/graphics/gfx_common.h | 9 ++ sc2/src/sc2code/libs/graphics/sdl/opengl.c | 87 +++++++++++-------- sc2/src/sc2code/libs/graphics/sdl/opengl.h | 2 +- sc2/src/sc2code/libs/graphics/sdl/pure.c | 9 +- sc2/src/sc2code/libs/graphics/sdl/pure.h | 2 +- .../sc2code/libs/graphics/sdl/sdl_common.c | 36 ++++++-- sc2/src/sc2code/libs/input/sdl/input.c | 1 + 11 files changed, 100 insertions(+), 50 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 220f5ea6a..ceb8e22c2 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,5 @@ Changes towards version 0.7: +- Added fullscreen/windowed toggle key F11 - Mika - Allow building without ogg vorbis support (bug #852) - SvdB - Reworked SuperMelee fleet loading (fixes bug #823) - SvdB - Fixed enemy ships getting recrewed between ecnounters in HyperSpace diff --git a/sc2/content/menu.key b/sc2/content/menu.key index 02242e958..f702d0d0f 100644 --- a/sc2/content/menu.key +++ b/sc2/content/menu.key @@ -51,6 +51,7 @@ menu.next.1 = key Tab menu.pause.1 = key Pause menu.pause.2 = key F1 menu.exit.1 = key F10 +menu.fullscreen.1 = key F11 menu.special.1 = key LeftAlt menu.special.2 = key RightAlt diff --git a/sc2/doc/users/manual.txt b/sc2/doc/users/manual.txt index 33c1766e9..08d470813 100644 --- a/sc2/doc/users/manual.txt +++ b/sc2/doc/users/manual.txt @@ -656,6 +656,7 @@ the QUIT button in the lower right. F1 or PAUSE Pause game F10 Exit game +F11 Toggle between fullscreen and windowed mode FULL GAME CONTROLS SUMMARY diff --git a/sc2/src/sc2code/controls.h b/sc2/src/sc2code/controls.h index 3ecef43d9..d8980061b 100644 --- a/sc2/src/sc2code/controls.h +++ b/sc2/src/sc2code/controls.h @@ -42,6 +42,7 @@ enum { KEY_EXIT, KEY_ABORT, KEY_DEBUG, + KEY_FULLSCREEN, KEY_MENU_UP, KEY_MENU_DOWN, KEY_MENU_LEFT, diff --git a/sc2/src/sc2code/libs/graphics/gfx_common.h b/sc2/src/sc2code/libs/graphics/gfx_common.h index 60a7b3565..f2d14b89f 100644 --- a/sc2/src/sc2code/libs/graphics/gfx_common.h +++ b/sc2/src/sc2code/libs/graphics/gfx_common.h @@ -32,6 +32,15 @@ enum TFB_GFXDRIVER_SDL_PURE, }; +// forced redraw +enum +{ + TFB_REDRAW_NO = 0, + TFB_REDRAW_FADING, + TFB_REDRAW_EXPOSE, + TFB_REDRAW_YES +}; + // flags for TFB_InitGraphics #define TFB_GFXFLAGS_FULLSCREEN (1<<0) #define TFB_GFXFLAGS_SHOWFPS (1<<1) diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.c b/sc2/src/sc2code/libs/graphics/sdl/opengl.c index c15bc33c7..ae8b6b470 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.c +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.c @@ -160,7 +160,7 @@ AttemptColorDepth (int flags, int width, int height, int bpp) } int -TFB_GL_ConfigureVideo (int driver, int flags, int width, int height) +TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen) { int i, texture_width, texture_height; GraphicsDriver = driver; @@ -172,56 +172,62 @@ TFB_GL_ConfigureVideo (int driver, int flags, int width, int height) log_add (log_Error, "Couldn't set any OpenGL %ix%i video mode!", width, height); return -1; - } - - if (format_conv_surf) - SDL_FreeSurface (format_conv_surf); - format_conv_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0, 32, - R_MASK, G_MASK, B_MASK, A_MASK); - if (format_conv_surf == NULL) - { - log_add (log_Error, "Couldn't create format_conv_surf: %s", - SDL_GetError()); - return -1; } - for (i = 0; i < TFB_GFX_NUMSCREENS; i++) + if (!togglefullscreen) { - if (0 != ReInit_Screen (&SDL_Screens[i], format_conv_surf, - ScreenWidth, ScreenHeight)) + if (format_conv_surf) + SDL_FreeSurface (format_conv_surf); + format_conv_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, 0, 0, 32, + R_MASK, G_MASK, B_MASK, A_MASK); + if (format_conv_surf == NULL) + { + log_add (log_Error, "Couldn't create format_conv_surf: %s", + SDL_GetError()); return -1; - } + } - SDL_Screen = SDL_Screens[0]; - TransitionScreen = SDL_Screens[2]; - - if (first_init) - { for (i = 0; i < TFB_GFX_NUMSCREENS; i++) { - GL_Screens[i].scaled = NULL; - GL_Screens[i].dirty = TRUE; - GL_Screens[i].active = TRUE; + if (0 != ReInit_Screen (&SDL_Screens[i], format_conv_surf, + ScreenWidth, ScreenHeight)) + return -1; + } + + SDL_Screen = SDL_Screens[0]; + TransitionScreen = SDL_Screens[2]; + + if (first_init) + { + for (i = 0; i < TFB_GFX_NUMSCREENS; i++) + { + GL_Screens[i].scaled = NULL; + GL_Screens[i].dirty = TRUE; + GL_Screens[i].active = TRUE; + } + GL_Screens[1].active = FALSE; + first_init = FALSE; } - GL_Screens[1].active = FALSE; - first_init = FALSE; } if (GfxFlags & TFB_GFXFLAGS_SCALE_SOFT_ONLY) { - for (i = 0; i < TFB_GFX_NUMSCREENS; i++) + if (!togglefullscreen) { - if (!GL_Screens[i].active) - continue; - if (0 != ReInit_Screen (&GL_Screens[i].scaled, format_conv_surf, - ScreenWidth * 2, ScreenHeight * 2)) - return -1; + for (i = 0; i < TFB_GFX_NUMSCREENS; i++) + { + if (!GL_Screens[i].active) + continue; + if (0 != ReInit_Screen (&GL_Screens[i].scaled, format_conv_surf, + ScreenWidth * 2, ScreenHeight * 2)) + return -1; + } + scaler = Scale_PrepPlatform (flags, SDL_Screen->format); } texture_width = 1024; texture_height = 512; - scaler = Scale_PrepPlatform (flags, SDL_Screen->format); graphics_backend = &opengl_scaled_backend; } else @@ -233,6 +239,7 @@ TFB_GL_ConfigureVideo (int driver, int flags, int width, int height) graphics_backend = &opengl_unscaled_backend; } + if (GfxFlags & TFB_GFXFLAGS_SCALE_ANY) ScreenFilterMode = GL_LINEAR; else @@ -277,7 +284,7 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height) ScreenWidth = 320; ScreenHeight = 240; - if (TFB_GL_ConfigureVideo (driver, flags, width, height)) + if (TFB_GL_ConfigureVideo (driver, flags, width, height, 0)) { log_add (log_Fatal, "Could not initialize video: " "no fallback at start of program!"); @@ -367,10 +374,18 @@ TFB_GL_Preprocess (int force_full_redraw, int transition_amount, int fade_amount glOrtho (0,ScreenWidthActual,ScreenHeightActual, 0, -1, 1); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); - (void) force_full_redraw; (void) transition_amount; (void) fade_amount; - if (TFB_BBox.valid) + + if (force_full_redraw == TFB_REDRAW_YES) + { + GL_Screens[TFB_SCREEN_MAIN].updated.x = 0; + GL_Screens[TFB_SCREEN_MAIN].updated.y = 0; + GL_Screens[TFB_SCREEN_MAIN].updated.w = ScreenWidth; + GL_Screens[TFB_SCREEN_MAIN].updated.h = ScreenHeight; + GL_Screens[TFB_SCREEN_MAIN].dirty = TRUE; + } + else if (TFB_BBox.valid) { GL_Screens[TFB_SCREEN_MAIN].updated.x = TFB_BBox.region.corner.x; GL_Screens[TFB_SCREEN_MAIN].updated.y = TFB_BBox.region.corner.y; diff --git a/sc2/src/sc2code/libs/graphics/sdl/opengl.h b/sc2/src/sc2code/libs/graphics/sdl/opengl.h index 90ab5f461..f5094462b 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/opengl.h +++ b/sc2/src/sc2code/libs/graphics/sdl/opengl.h @@ -22,7 +22,7 @@ #include "libs/graphics/sdl/sdl_common.h" int TFB_GL_InitGraphics (int driver, int flags, int width, int height); -int TFB_GL_ConfigureVideo (int driver, int flags, int width, int height); +int TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen); void TFB_GL_UploadTransitionScreen (void); #ifdef HAVE_OPENGL diff --git a/sc2/src/sc2code/libs/graphics/sdl/pure.c b/sc2/src/sc2code/libs/graphics/sdl/pure.c index 9faf7d758..b16898782 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/pure.c +++ b/sc2/src/sc2code/libs/graphics/sdl/pure.c @@ -74,7 +74,7 @@ ReInit_Screen (SDL_Surface **screen, SDL_Surface *template, int w, int h) } int -TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height) +TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen) { int i, videomode_flags; SDL_Surface *temp_surf; @@ -124,6 +124,9 @@ TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height) SDL_GetVideoSurface()->w, SDL_GetVideoSurface()->h, SDL_GetVideoSurface()->format->BitsPerPixel); ScreenColorDepth = SDL_GetVideoSurface()->format->BitsPerPixel; + + if (togglefullscreen) + return 0; } // Create a 32bpp surface in a compatible format which will supply @@ -210,7 +213,7 @@ TFB_Pure_InitGraphics (int driver, int flags, int width, int height) ScreenWidth = 320; ScreenHeight = 240; - if (TFB_Pure_ConfigureVideo (driver, flags, width, height)) + if (TFB_Pure_ConfigureVideo (driver, flags, width, height, 0)) { log_add (log_Fatal, "Could not initialize video: " "no fallback at start of program!"); @@ -286,7 +289,7 @@ TFB_Pure_Scaled_Preprocess (int force_full_redraw, int transition_amount, int fa static void TFB_Pure_Unscaled_Preprocess (int force_full_redraw, int transition_amount, int fade_amount) { - if (force_full_redraw) + if (force_full_redraw != TFB_REDRAW_NO) { updated.x = updated.y = 0; updated.w = ScreenWidth; diff --git a/sc2/src/sc2code/libs/graphics/sdl/pure.h b/sc2/src/sc2code/libs/graphics/sdl/pure.h index 8d0a82567..07f067a48 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/pure.h +++ b/sc2/src/sc2code/libs/graphics/sdl/pure.h @@ -22,6 +22,6 @@ #include "libs/graphics/sdl/sdl_common.h" int TFB_Pure_InitGraphics (int driver, int flags, int width, int height); -int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height); +int TFB_Pure_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen); #endif diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index b3325c520..8618d09bd 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -32,6 +32,7 @@ #include "libs/uio.h" #include "libs/log.h" #include "controls.h" +#include "vidlib.h" // XXX: Should not be included from here. #include "uqmdebug.h" #include SDL_INCLUDE(SDL_thread.h) @@ -82,14 +83,21 @@ int TFB_ReInitGraphics (int driver, int flags, int width, int height) { int result; + int togglefullscreen = 0; char caption[200]; + if (GfxFlags == (flags ^ TFB_GFXFLAGS_FULLSCREEN) && driver == GraphicsDriver && + width == ScreenWidthActual && height == ScreenHeightActual) + { + togglefullscreen = 1; + } + GfxFlags = flags; if (driver == TFB_GFXDRIVER_SDL_OPENGL) { #ifdef HAVE_OPENGL - result = TFB_GL_ConfigureVideo (driver, flags, width, height); + result = TFB_GL_ConfigureVideo (driver, flags, width, height, togglefullscreen); #else driver = TFB_GFXDRIVER_SDL_PURE; log_add (log_Warning, "OpenGL support not compiled in," @@ -99,7 +107,7 @@ TFB_ReInitGraphics (int driver, int flags, int width, int height) } else { - result = TFB_Pure_ConfigureVideo (driver, flags, width, height); + result = TFB_Pure_ConfigureVideo (driver, flags, width, height, togglefullscreen); } sprintf (caption, "The Ur-Quan Masters v%d.%d.%d%s", @@ -194,17 +202,27 @@ TFB_ProcessEvents () // TODO break; case SDL_VIDEOEXPOSE: /* Screen needs to be redrawn */ - TFB_SwapBuffers (1); + TFB_SwapBuffers (TFB_REDRAW_EXPOSE); break; default: break; } } + if (ImmediateInputState.menu[KEY_ABORT] || abortFlag) { log_showBox (false, false); exit (EXIT_SUCCESS); } + + if (ImmediateInputState.menu[KEY_FULLSCREEN]) + { + int flags = GfxFlags ^ TFB_GFXFLAGS_FULLSCREEN; + FlushInput (); + TFB_ReInitGraphics (GraphicsDriver, flags, ScreenWidthActual, ScreenHeightActual); + TFB_SwapBuffers (TFB_REDRAW_YES); + } + #if defined(DEBUG) || defined(USE_DEBUG_KEY) if (ImmediateInputState.menu[KEY_DEBUG]) { @@ -242,15 +260,15 @@ TFB_SwapBuffers (int force_full_redraw) fade_amount = FadeAmount; transition_amount = TransitionAmount; - if (!force_full_redraw && !TFB_BBox.valid && + if (force_full_redraw == TFB_REDRAW_NO && !TFB_BBox.valid && fade_amount == 255 && transition_amount == 255 && last_fade_amount == 255 && last_transition_amount == 255) return; - if (fade_amount != 255 || transition_amount != 255 || - last_fade_amount != 255 || last_transition_amount != 255) + if (force_full_redraw == TFB_REDRAW_NO && (fade_amount != 255 || transition_amount != 255 || + last_fade_amount != 255 || last_transition_amount != 255)) { - force_full_redraw = 1; + force_full_redraw = TFB_REDRAW_FADING; } last_fade_amount = fade_amount; @@ -605,7 +623,7 @@ TFB_FlushGraphics () // Only call from main thread!! (current_fade == 255 && last_fade != 255) || (current_transition == 255 && last_transition != 255)) { - TFB_SwapBuffers (1); // if fading, redraw every frame + TFB_SwapBuffers (TFB_REDRAW_FADING); // if fading, redraw every frame } else { @@ -888,7 +906,7 @@ TFB_FlushGraphics () // Only call from main thread!! Unlock_DCQ (); } - TFB_SwapBuffers (0); + TFB_SwapBuffers (TFB_REDRAW_NO); RenderedFrames++; BroadcastCondVar (RenderingCond); } diff --git a/sc2/src/sc2code/libs/input/sdl/input.c b/sc2/src/sc2code/libs/input/sdl/input.c index 3d82416be..eebfd1577 100644 --- a/sc2/src/sc2code/libs/input/sdl/input.c +++ b/sc2/src/sc2code/libs/input/sdl/input.c @@ -49,6 +49,7 @@ static const char *menu_res_names[] = { "exit", "abort", "debug", + "fullscreen", "up", "down", "left",