From 184598a43548642b9a4bfe8c2fce58e4a966d0bb Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 23 Aug 2008 19:27:10 +0000 Subject: instant r_fullscreen switching, bound to alt+enter --- src/client/client.cc | 8 +------- src/client/keyboard.cc | 3 ++- src/client/video.cc | 20 ++++++++++++++++++++ src/client/video.h | 3 +++ 4 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/client') diff --git a/src/client/client.cc b/src/client/client.cc index f67cce0..7ba61d6 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -46,13 +46,7 @@ void func_snd_restart(std::string const &args) void func_r_restart(std::string const &args) { - video::shutdown(); - - if (!video::init()) { - app.quit(1); - } - - input::reset(); + video::restart(); } //--- public ------------------------------------------------------ diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index af7f2ed..aac6548 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -57,7 +57,8 @@ Keyboard::Keyboard() add_key("backspace", SDLK_BACKSPACE); add_key("tab", SDLK_TAB, 0, "impulse"); add_key("clear", SDLK_CLEAR); - add_key("enter", SDLK_RETURN); + key = add_key("enter", SDLK_RETURN); + key->assign(Key::Alt, "toggle r_fullscreen"); add_key("pause", SDLK_PAUSE); add_key("esc", SDLK_ESCAPE); add_key("space", SDLK_SPACE, ' ', "ui_control"); diff --git a/src/client/video.cc b/src/client/video.cc index aed25ae..39e2c2a 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -9,7 +9,9 @@ #include "auxiliary/functions.h" #include "client/video.h" +#include "client/input.h" #include "client/view.h" +#include "client/client.h" #include "render/camera.h" #include "render/render.h" #include "render/tga.h" @@ -26,6 +28,8 @@ namespace client { namespace video { +float fullscreen = 0; + int width = 0; int height = 0; @@ -45,6 +49,17 @@ core::Cvar *r_fullscreen; core::Cvar *screenshotformat; +void restart() +{ + shutdown(); + + if (!init()) { + client()->quit(1); + } + + input::reset(); +} + void reset() { // setup our viewport. @@ -116,6 +131,7 @@ bool init() SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1); + fullscreen = r_fullscreen->value(); if (r_fullscreen->value()) { flags = SDL_OPENGL | SDL_FULLSCREEN; } else { @@ -170,6 +186,10 @@ bool init() void frame(float seconds) { + // detect fullscreen/windowed mode switch + if (fullscreen != r_fullscreen->value()) + restart(); + // render a client frame view::frame(seconds); diff --git a/src/client/video.h b/src/client/video.h index 20cd875..59939e6 100644 --- a/src/client/video.h +++ b/src/client/video.h @@ -24,6 +24,9 @@ namespace video /// reset and clear the viewport void reset(); + /// restart the video subsystem + void restart(); + /// make a screenshot void screenshot(); -- cgit v1.2.3