From e36b0cb8f32fc4302499c87e5c2b4c1ecc7a6543 Mon Sep 17 00:00:00 2001 From: Thomas Szepe Date: Tue, 7 Apr 2015 18:32:25 +0200 Subject: BGE: New API method getDisplayDimensions This patch adds a new API function to get the actual display dimensions in pixels. Reviewers: dfelinto, sybren, lordloki, moguri Reviewed By: lordloki, moguri Differential Revision: https://developer.blender.org/D648 --- source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp | 5 +++++ source/gameengine/BlenderRoutines/KX_BlenderCanvas.h | 2 ++ source/gameengine/GamePlayer/common/GPC_Canvas.h | 2 ++ source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp | 12 ++++++++++++ source/gameengine/GamePlayer/ghost/GPG_Canvas.h | 2 ++ source/gameengine/Ketsji/KX_PythonInit.cpp | 16 ++++++++++++++++ source/gameengine/Rasterizer/RAS_ICanvas.h | 2 ++ 7 files changed, 41 insertions(+) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp index 3a31806fad4..e37818678d6 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -97,6 +97,11 @@ bool KX_BlenderCanvas::GetSwapInterval(int &intervalOut) return wm_window_get_swap_interval(m_win, &intervalOut); } +void KX_BlenderCanvas::GetDisplayDimensions(int &width, int &height) +{ + wm_get_screensize(&width, &height); +} + void KX_BlenderCanvas::ResizeWindow(int width, int height) { // Not implemented for the embedded player diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h index c150af21230..817a667d783 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h @@ -87,6 +87,8 @@ public: int &intervalOut ); + void GetDisplayDimensions(int &width, int &height); + void ResizeWindow( int width, diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.h b/source/gameengine/GamePlayer/common/GPC_Canvas.h index acbea477e38..34cc9759a08 100644 --- a/source/gameengine/GamePlayer/common/GPC_Canvas.h +++ b/source/gameengine/GamePlayer/common/GPC_Canvas.h @@ -71,6 +71,8 @@ public: virtual void ResizeWindow(int width, int height) {} + virtual void GetDisplayDimensions(int &width, int &height) {} + /** * \section Methods inherited from abstract base class RAS_ICanvas. */ diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp index 556f85804ea..09eb1691dae 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp @@ -121,6 +121,18 @@ bool GPG_Canvas::GetSwapInterval(int& intervalOut) return false; } +void GPG_Canvas::GetDisplayDimensions(int &width, int &height) + { + unsigned int uiwidth; + unsigned int uiheight; + + GHOST_ISystem *system = GHOST_ISystem::getSystem(); + system->getMainDisplayDimensions(uiwidth, uiheight); + + width = uiwidth; + height = uiheight; +} + void GPG_Canvas::ResizeWindow(int width, int height) { if (m_window->getState() == GHOST_kWindowStateFullScreen) diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h index 337c2cedf55..18afbf6cd9e 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h +++ b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h @@ -63,6 +63,8 @@ public: virtual float GetMouseNormalizedX(int x); virtual float GetMouseNormalizedY(int y); + virtual void GetDisplayDimensions(int &width, int &height); + virtual void ResizeWindow(int width, int height); virtual void SetFullScreen(bool enable); virtual bool GetFullScreen(); diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 18b25d340dd..420e0be8c5d 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -1403,6 +1403,20 @@ static PyObject *gPyClearDebugList(PyObject *) Py_RETURN_NONE; } +static PyObject *gPyGetDisplayDimensions(PyObject *) +{ + PyObject *list = PyList_New(0); + int width; + int height; + + gp_Canvas->GetDisplayDimensions(width, height); + + PyList_Append(list, PyLong_FromLong(width)); + PyList_Append(list, PyLong_FromLong(height)); + + return list; +} + PyDoc_STRVAR(Rasterizer_module_documentation, "This is the Python API for the game engine of Rasterizer" ); @@ -1446,6 +1460,8 @@ static struct PyMethodDef rasterizer_methods[] = { {"setWindowSize", (PyCFunction) gPySetWindowSize, METH_VARARGS, ""}, {"setFullScreen", (PyCFunction) gPySetFullScreen, METH_O, ""}, {"getFullScreen", (PyCFunction) gPyGetFullScreen, METH_NOARGS, ""}, + {"getDisplayDimensions", (PyCFunction) gPyGetDisplayDimensions, METH_NOARGS, + "Get the actual dimensions, in pixels, of the physical display (e.g., the monitor)."}, {"setMipmapping", (PyCFunction) gPySetMipmapping, METH_VARARGS, ""}, {"getMipmapping", (PyCFunction) gPyGetMipmapping, METH_NOARGS, ""}, {"setVsync", (PyCFunction) gPySetVsync, METH_VARARGS, ""}, diff --git a/source/gameengine/Rasterizer/RAS_ICanvas.h b/source/gameengine/Rasterizer/RAS_ICanvas.h index d90cbea286e..471c2c97fa1 100644 --- a/source/gameengine/Rasterizer/RAS_ICanvas.h +++ b/source/gameengine/Rasterizer/RAS_ICanvas.h @@ -237,6 +237,8 @@ public: const char* filename )=0; + virtual void GetDisplayDimensions(int &width, int &height) = 0; + virtual void ResizeWindow( -- cgit v1.2.3