Committing patch "[#27676] Change window size/resolution in realtime" by me.
authorMitchell Stokes <mogurijin@gmail.com>
Sun, 22 Jan 2012 20:25:25 +0000 (20:25 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Sun, 22 Jan 2012 20:25:25 +0000 (20:25 +0000)
Description:
This patch allows the user to change the size of the window (or the resolution in fullscreen mode) using the new bge.render.setWindowSize() method. This only works in the Blenderplayer since it doesn't make a whole lot of sense for the embedded player.

doc/python_api/rst/bge.render.rst
intern/ghost/GHOST_ISystem.h
intern/ghost/intern/GHOST_System.cpp
intern/ghost/intern/GHOST_System.h
source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
source/gameengine/GamePlayer/common/GPC_Canvas.h
source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
source/gameengine/GamePlayer/ghost/GPG_Canvas.h
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/Rasterizer/RAS_ICanvas.h

index eeb50a833ffbd2577b8b141146041f3108450e72..ddc05ac1d8c425127bf5415337206ccdb822fd38 100644 (file)
@@ -77,6 +77,14 @@ Functions
    
    :rtype: integer
 
+.. function:: setWindowSize(width, height)
+
+   Set the width and height of the window (in pixels). This also works for fullscreen applications.
+   
+   :type width: integer
+   :type height: integer
+
+
 .. function:: makeScreenshot(filename)
 
    Writes a screenshot to the given filename.
index 3ec8d3d2fbf9181ca94ef7ff214d94927fef5430..ee67694760bc72f1c62d7214c7c5863fbcebbb96 100644 (file)
@@ -271,6 +271,15 @@ public:
         */
        virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
                const bool stereoVisual, const GHOST_TUns16 numOfAASamples=0) = 0;
+       
+       /**
+        * Updates the resolution while in fullscreen mode.
+        * @param setting       The new setting of the display.
+        * @param window        Window displayed in full screen.
+        *
+        * @return      Indication of success.
+        */
+       virtual GHOST_TSuccess updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window) = 0;
 
        /**
         * Ends full screen mode.
index 4efdcbc6519b590ae330752dd009c326c8b798dc..944ade3f22b1e819504fc5bc2c0dd49f3153fd00 100644 (file)
@@ -168,6 +168,19 @@ GHOST_TSuccess GHOST_System::beginFullScreen(const GHOST_DisplaySetting& setting
 }
 
 
+GHOST_TSuccess GHOST_System::updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window)
+{
+       GHOST_TSuccess success = GHOST_kFailure;
+       GHOST_ASSERT(m_windowManager, "GHOST_System::updateFullScreen(): invalid window manager");
+       if(m_displayManager) {
+               if (m_windowManager->getFullScreen()) {
+                       success = m_displayManager->setCurrentDisplaySetting(GHOST_DisplayManager::kMainDisplay, setting);
+               }
+       }
+
+       return success;
+}
+
 GHOST_TSuccess GHOST_System::endFullScreen(void)
 {
        GHOST_TSuccess success = GHOST_kFailure;
index 6286121719d47e1be3324c551867b0cee78d561e..0bb0387a28786e41da311e6da48969167561a61f 100644 (file)
@@ -145,6 +145,15 @@ public:
         */
        virtual GHOST_TSuccess beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window,
                const bool stereoVisual, const GHOST_TUns16 numOfAASamples=0);
+               
+       /**
+        * Updates the resolution while in fullscreen mode.
+        * @param setting       The new setting of the display.
+        * @param window        Window displayed in full screen.
+        *
+        * @return      Indication of success.
+        */
+       virtual GHOST_TSuccess updateFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow** window);
 
        /**
         * Ends full screen mode.
index 2a21b531b6bf982d5c4b7e57a18c67910f8765f2..7e7b3d2e3d44db69593d31ec33015d04afbab40f 100644 (file)
@@ -59,6 +59,11 @@ void KX_BlenderCanvas::SwapBuffers()
        BL_SwapBuffers(m_win);
 }
 
+void KX_BlenderCanvas::ResizeWindow(int width, int height)
+{
+       // Not implemented for the embedded player
+}
+
 void KX_BlenderCanvas::BeginFrame()
 {
        glEnable(GL_DEPTH_TEST);
index 1f38cf9766d4db0b6061dba2dadb358a7b4d98b4..44dffb5bc5430f044c517ee203fa35d393be182d 100644 (file)
@@ -78,7 +78,7 @@ public:
        SwapBuffers(
        );
                void 
-       Resize(
+       ResizeWindow(
                int width,
                int height
        );
index 6ac1323783bba45d7017ad57a7b9da02b9a143ed..a9d7ab1b93f31b080fc9f4d08d89b08b2b3cf459 100644 (file)
@@ -103,6 +103,7 @@ public:
 
        void Resize(int width, int height);
 
+       virtual void ResizeWindow(int width, int height){};
 
        /**
         * @section Methods inherited from abstract base class RAS_ICanvas.
index 4b5d2bbf96a657f13687048ea31dddd6580bdea9..9b01cb5786f3523bd49342175e20e2665be129e5 100644 (file)
@@ -108,6 +108,26 @@ void GPG_Canvas::SwapBuffers()
        }
 }
 
+void GPG_Canvas::ResizeWindow(int width, int height)
+{
+       if (m_window->getState() == GHOST_kWindowStateFullScreen)
+       {
+               GHOST_ISystem* system = GHOST_ISystem::getSystem();
+               GHOST_DisplaySetting setting;
+               setting.xPixels = width;
+               setting.yPixels = height;
+               //XXX allow these to be changed or kept from previous state
+               setting.bpp = 32;
+               setting.frequency = 60;
+
+               system->updateFullScreen(setting, &m_window);
+       }
+
+       m_window->setClientSize(width, height);
+
+       Resize(width, height);
+}
+
 float GPG_Canvas::GetMouseNormalizedX(int x)
 {
        return float(x)/this->GetWidth();
index c1ebb09251ce665e4324aa1a1a98fabc61a1527c..217cfc5eb88278f9d1f93344791c482373a93fe1 100644 (file)
@@ -60,6 +60,8 @@ public:
        virtual float GetMouseNormalizedX(int x);
        virtual float GetMouseNormalizedY(int y);
 
+       virtual void ResizeWindow(int width, int height);
+
        bool BeginDraw() { return true;};
        void EndDraw() {};
 };
index 114ca735265f006089033b047ed725c28853eafd..32106b1fdd8306254313cfe22c278da22460b3a3 100644 (file)
@@ -1288,6 +1288,16 @@ static PyObject* gPyDrawLine(PyObject*, PyObject* args)
        Py_RETURN_NONE;
 }
 
+static PyObject* gPySetWindowSize(PyObject*, PyObject* args)
+{
+       int width, height;
+       if (!PyArg_ParseTuple(args, "ii:resize", &width, &height))
+               return NULL;
+
+       gp_Canvas->ResizeWindow(width, height);
+       Py_RETURN_NONE;
+}
+
 static struct PyMethodDef rasterizer_methods[] = {
   {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
    METH_VARARGS, "getWindowWidth doc"},
@@ -1329,6 +1339,7 @@ static struct PyMethodDef rasterizer_methods[] = {
   METH_VARARGS, "get the anisotropic filtering level"},
   {"drawLine", (PyCFunction) gPyDrawLine,
    METH_VARARGS, "draw a line on the screen"},
+  {"setWindowSize", (PyCFunction) gPySetWindowSize, METH_VARARGS, ""},
   { NULL, (PyCFunction) NULL, 0, NULL }
 };
 
index d7e2f237bb0401856c2b6ec8aa9484d208b7993d..2c2f62c946eb1914efd6b0675416795efca002af 100644 (file)
@@ -205,6 +205,15 @@ public:
        MakeScreenShot(
                const char* filename
        )=0;
+
+       virtual
+               void 
+       ResizeWindow(
+               int width,
+               int height
+       )=0;
+
+               
        
 protected:
        RAS_MouseState m_mousestate;