From: Peter Schaefer Date: Thu, 25 Jun 2015 18:49:49 +0000 (+0200) Subject: added real FULLSCREEN -> F10 X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=9c6966fdc162f88d0b405a24ff1877e8681cecf2;p=cgue_weave.git added real FULLSCREEN -> F10 --- diff --git a/Weave/Events.cpp b/Weave/Events.cpp index 5d1b1cb..e763a11 100644 --- a/Weave/Events.cpp +++ b/Weave/Events.cpp @@ -27,11 +27,11 @@ void Events::processEvents() { case SDL_WINDOWEVENT_FOCUS_GAINED: window_focus = true; - Graphix::catchMouse(); + Graphix::hideMouse(true); break; case SDL_WINDOWEVENT_FOCUS_LOST: window_focus = false; - Graphix::freeMouse(); + Graphix::hideMouse(false); break; case SDL_WINDOWEVENT_RESIZED: Graphix::setWindowSize(sdl_event.window.data1, sdl_event.window.data2); @@ -124,7 +124,11 @@ void Events::KeyDown(int _key) //TRANSPARENCY break; case SDLK_F10: - //??? + //??? FullScreen + if (key_toggle[SDLK_F10]) + Graphix::FullScreen(false,true); + else + Graphix::FullScreen(true,true); break; case SDLK_SPACE: jump++; diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index 961ed2d..5f91b01 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -77,6 +77,8 @@ void Graphix::init() Message::error((string)"glewInit: " + (char*)glewGetErrorString(err)); } + SDL_ShowCursor(SDL_DISABLE); + glEnable(GL_DEPTH_TEST); //SDL_SetWindowGrab(sdl_window, SDL_TRUE); @@ -99,18 +101,60 @@ void Graphix::init() shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl"); } +void Graphix::FullScreen(bool _enable, bool _keepDesktopResolution) +{ + if (_enable) + { + if (_keepDesktopResolution) + { + width_bkp = width; + height_bkp = height; + + SDL_DisplayMode dm; + if (SDL_GetDesktopDisplayMode(0, &dm) != 0) + Message::error((string)"SDL_GetDesktopDisplayMode failed:" + SDL_GetError()); + + width = dm.w; + height = dm.h; + + SDL_SetWindowSize(sdl_window, width, height); + } + SDL_SetWindowFullscreen(sdl_window, SDL_WINDOW_FULLSCREEN); + } + else + { + if (_keepDesktopResolution && width_bkp !=0) + { + width = width_bkp; + height = height_bkp; + + SDL_SetWindowSize(sdl_window, width, height); + } + SDL_SetWindowFullscreen(sdl_window, 0); + } + +} + void Graphix::catchMouse() { - SDL_SetWindowGrab(sdl_window, SDL_TRUE); + //SDL_SetWindowGrab(sdl_window, SDL_TRUE); SDL_ShowCursor(SDL_DISABLE); //TODO eventuell nicht nötig } void Graphix::freeMouse() { - SDL_SetWindowGrab(sdl_window, SDL_FALSE); + //SDL_SetWindowGrab(sdl_window, SDL_FALSE); SDL_ShowCursor(SDL_ENABLE); //TODO eventuell nicht nötig } +void Graphix::hideMouse(bool _enable) +{ + if (_enable) + SDL_ShowCursor(SDL_DISABLE); + else + SDL_ShowCursor(SDL_ENABLE); +} + void Graphix::clear() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -137,7 +181,7 @@ void Graphix::cleanup() { delete shader_BBox; - SDL_SetWindowGrab(sdl_window, SDL_FALSE); + //SDL_SetWindowGrab(sdl_window, SDL_FALSE); SDL_GL_DeleteContext(sdl_glcontext); SDL_DestroyWindow(sdl_window); @@ -176,12 +220,15 @@ unsigned int Graphix::getGlError() unsigned int Graphix::width = 1024; unsigned int Graphix::height = 768; -unsigned int Graphix::xpos = 200; -unsigned int Graphix::ypos = 100; +unsigned int Graphix::xpos = SDL_WINDOWPOS_UNDEFINED; +unsigned int Graphix::ypos = SDL_WINDOWPOS_UNDEFINED; + +unsigned int Graphix::width_bkp = 0; +unsigned int Graphix::height_bkp = 0; string Graphix::windowTitle = "Weave"; -Uint32 Graphix::windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; +Uint32 Graphix::windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_INPUT_GRABBED; Uint32 Graphix::sdlFlags = SDL_INIT_VIDEO | SDL_INIT_TIMER; SDL_Window* Graphix::sdl_window; diff --git a/Weave/Graphix/Graphix.h b/Weave/Graphix/Graphix.h index ea8285c..3d4d3cb 100644 --- a/Weave/Graphix/Graphix.h +++ b/Weave/Graphix/Graphix.h @@ -24,8 +24,11 @@ public: static unsigned int getWindowHeight(); static unsigned int getWindowWidth(); + static void FullScreen(bool enable, bool keepDesktopResolution = true); + static void catchMouse(); static void freeMouse(); + static void hideMouse(bool enable = true); static void enableEffects(Effects eff); static void disableEffects(Effects eff); @@ -42,11 +45,8 @@ public: static Shader* shader_BBox; private: - static unsigned int width; - static unsigned int height; - - static unsigned int xpos; - static unsigned int ypos; + static unsigned int xpos, ypos, width, height; + static unsigned int width_bkp, height_bkp; static std::string windowTitle;