Committing patch "[#27676] Change window size/resolution in realtime" by me.

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.
This commit is contained in:
Mitchell Stokes 2012-01-22 20:25:25 +00:00
parent 359e961a12
commit 686ce92fe8
11 changed files with 88 additions and 1 deletions

@ -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.

@ -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.

@ -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;

@ -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.

@ -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);

@ -78,7 +78,7 @@ public:
SwapBuffers(
);
void
Resize(
ResizeWindow(
int width,
int height
);

@ -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.

@ -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();

@ -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() {};
};

@ -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 }
};

@ -205,6 +205,15 @@ public:
MakeScreenShot(
const char* filename
)=0;
virtual
void
ResizeWindow(
int width,
int height
)=0;
protected:
RAS_MouseState m_mousestate;