]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
added real FULLSCREEN -> F10
authorPeter Schaefer <schaeferpm@gmail.com>
Thu, 25 Jun 2015 18:49:49 +0000 (20:49 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Thu, 25 Jun 2015 18:49:49 +0000 (20:49 +0200)
Weave/Events.cpp
Weave/Graphix/Graphix.cpp
Weave/Graphix/Graphix.h

index 5d1b1cbe6f87fbd911f62fff375fff93259e447d..e763a11bc334f8a571c4f6cfe93b9a4ad7c2d922 100644 (file)
@@ -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++;
index 961ed2d82363ab9d6e8ec291f147d7a6dedbc2e6..5f91b012f06cb7202b51ba21b6ca4fb11dafd4e6 100644 (file)
@@ -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;
index ea8285c7cae22d8abe12ea507b7bc227c67a123b..3d4d3cbdd989d322af8a9c9e0b89a320e3eeed0d 100644 (file)
@@ -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;