From 2e6078898ea86a00aea61721029965fe751246e3 Mon Sep 17 00:00:00 2001 From: rti Date: Sun, 13 Jun 2010 20:24:58 +0200 Subject: [PATCH] Changed: #947 fixed multi screen window positioning, implemented getCurrentScreenMode, (IDriver::InterfaceVersion = 0x67 to enable negative window positions) --- code/nel/include/nel/3d/driver.h | 4 +- code/nel/include/nel/3d/driver_user.h | 4 +- code/nel/include/nel/3d/u_driver.h | 4 +- code/nel/src/3d/driver.cpp | 2 +- .../3d/driver/direct3d/driver_direct3d.cpp | 8 +-- .../src/3d/driver/direct3d/driver_direct3d.h | 4 +- code/nel/src/3d/driver/opengl/driver_opengl.h | 4 +- .../3d/driver/opengl/driver_opengl_window.cpp | 19 ++++--- .../src/3d/driver/opengl/mac/cocoa_adapter.h | 7 ++- .../src/3d/driver/opengl/mac/cocoa_adapter.mm | 52 +++++++++++++++---- code/nel/src/3d/driver_user.cpp | 4 +- code/ryzom/client/src/client_cfg.cpp | 3 +- code/ryzom/client/src/client_cfg.h | 4 +- code/ryzom/client/src/init.cpp | 2 +- 14 files changed, 78 insertions(+), 43 deletions(-) diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 2396d9d62..878db5c5d 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -187,7 +187,7 @@ public: virtual void setWindowTitle(const ucstring &title)=0; /// Set the position of the NeL window - virtual void setWindowPos(uint32 x, uint32 y)=0; + virtual void setWindowPos(sint32 x, sint32 y)=0; /// Show or hide the NeL window virtual void showWindow(bool show)=0; @@ -748,7 +748,7 @@ public: virtual void getWindowSize (uint32 &width, uint32 &height) = 0; /// Get the position of the window always (0,0) in fullscreen - virtual void getWindowPos (uint32 &x, uint32 &y) = 0; + virtual void getWindowPos (sint32 &x, sint32 &y) = 0; /** get the RGBA back buffer. After swapBuffers(), the content of the back buffer is undefined. * diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h index 1d2c2aaed..1bda23c27 100644 --- a/code/nel/include/nel/3d/driver_user.h +++ b/code/nel/include/nel/3d/driver_user.h @@ -149,7 +149,7 @@ public: virtual void setWindowTitle(const ucstring &title); /// Set the position of the NeL window - virtual void setWindowPos(uint32 x, uint32 y); + virtual void setWindowPos(sint32 x, sint32 y); /// Show or hide the NeL window virtual void showWindow(bool show); @@ -396,7 +396,7 @@ public: virtual void getWindowSize (uint32 &width, uint32 &height); virtual uint getWindowWidth (); virtual uint getWindowHeight (); - virtual void getWindowPos (uint32 &x, uint32 &y); + virtual void getWindowPos (sint32 &x, sint32 &y); virtual uint32 getAvailableVertexAGPMemory (); virtual uint32 getAvailableVertexVRAMMemory (); virtual void getBuffer (CBitmap &bitmap); diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index 7641fdb2d..be77999c8 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -187,7 +187,7 @@ public: virtual void setWindowTitle(const ucstring &title)=0; /// Set the position of the NeL window - virtual void setWindowPos(uint32 x, uint32 y)=0; + virtual void setWindowPos(sint32 x, sint32 y)=0; /// Show or hide the NeL window virtual void showWindow(bool show = true)=0; @@ -499,7 +499,7 @@ public: virtual uint getWindowHeight () =0; /// Get the x and y coord of the windows always (0,0) in fullscreen - virtual void getWindowPos (uint32 &x, uint32 &y) = 0; + virtual void getWindowPos (sint32 &x, sint32 &y) = 0; /** Return the amount of AGP memory allocated by initVertexArrayRange() to store vertices. */ diff --git a/code/nel/src/3d/driver.cpp b/code/nel/src/3d/driver.cpp index b00c44388..9aefb3e51 100644 --- a/code/nel/src/3d/driver.cpp +++ b/code/nel/src/3d/driver.cpp @@ -34,7 +34,7 @@ namespace NL3D { // *************************************************************************** -const uint32 IDriver::InterfaceVersion = 0x66; // added IEventEmitter::emulateMouseRawMode(bool) +const uint32 IDriver::InterfaceVersion = 0x67; // changed window pos from uint32 to sint32 // *************************************************************************** IDriver::IDriver() : _SyncTexDrvInfos( "IDriver::_SyncTexDrvInfos" ) diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp index 161a67e76..cbafa50a1 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -1817,7 +1817,7 @@ void CDriverD3D::getWindowSize (uint32 &width, uint32 &height) // *************************************************************************** -void CDriverD3D::getWindowPos (uint32 &x, uint32 &y) +void CDriverD3D::getWindowPos (sint32 &x, sint32 &y) { H_AUTO_D3D(CDriverD3D_getWindowPos); x = _WindowX; @@ -2187,10 +2187,10 @@ void CDriverD3D::setWindowTitle(const ucstring &title) } // *************************************************************************** -void CDriverD3D::setWindowPos(uint32 x, uint32 y) +void CDriverD3D::setWindowPos(sint32 x, sint32 y) { - _WindowX = (sint32)x; - _WindowY = (sint32)y; + _WindowX = x; + _WindowY = y; SetWindowPos(_HWnd, NULL, _WindowX, _WindowY, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE); } diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 1811b92ca..d9baa1b34 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -753,14 +753,14 @@ public: virtual emptyProc getWindowProc(); virtual NLMISC::IEventEmitter *getEventEmitter(); virtual void getWindowSize (uint32 &width, uint32 &height); - virtual void getWindowPos (uint32 &x, uint32 &y); + virtual void getWindowPos (sint32 &x, sint32 &y); virtual uint8 getBitPerPixel (); /// Set the title of the NeL window virtual void setWindowTitle(const ucstring &title); /// Set the position of the NeL window - virtual void setWindowPos(uint32 x, uint32 y); + virtual void setWindowPos(sint32 x, sint32 y); /// Show or hide the NeL window virtual void showWindow(bool show); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index e8001014c..4543430b9 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -298,7 +298,7 @@ public: virtual void setWindowTitle(const ucstring &title); /// Set the position of the NeL window - virtual void setWindowPos(uint32 x, uint32 y); + virtual void setWindowPos(sint32 x, sint32 y); /// Show or hide the NeL window virtual void showWindow(bool show); @@ -502,7 +502,7 @@ public: virtual void getWindowSize (uint32 &width, uint32 &height); - virtual void getWindowPos (uint32 &x, uint32 &y); + virtual void getWindowPos (sint32 &x, sint32 &y); virtual void getBuffer (CBitmap &bitmap); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index a863a898b..03b3f5f79 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -862,7 +862,7 @@ bool CDriverGL::setScreenMode(const GfxMode &mode) #elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE) - // TODO + return NL3D::MAC::setMode(mode); #elif defined(NL_OS_UNIX) @@ -1237,9 +1237,8 @@ bool CDriverGL::getCurrentScreenMode(GfxMode &mode) mode.AntiAlias = _AntiAliasing; #elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE) -# warning "OpenGL Driver: Temporary Mac Implementation" - nlwarning("OpenGL Driver: Temporary Mac Implementation"); - mode.Depth = 24; + + NL3D::MAC::getCurrentScreenMode(mode); #elif defined(NL_OS_MAC) /* @@ -1309,10 +1308,10 @@ void CDriverGL::setWindowTitle(const ucstring &title) } // *************************************************************************** -void CDriverGL::setWindowPos(uint32 x, uint32 y) +void CDriverGL::setWindowPos(sint32 x, sint32 y) { - _WindowX = (sint32)x; - _WindowY = (sint32)y; + _WindowX = x; + _WindowY = y; #ifdef NL_OS_WINDOWS @@ -1557,7 +1556,7 @@ void CDriverGL::getWindowSize(uint32 &width, uint32 &height) #endif // NL_OS_UNIX } -void CDriverGL::getWindowPos(uint32 &x, uint32 &y) +void CDriverGL::getWindowPos(sint32 &x, sint32 &y) { H_AUTO_OGL(CDriverGL_getWindowPos) @@ -1575,8 +1574,8 @@ void CDriverGL::getWindowPos(uint32 &x, uint32 &y) { if (_win) { - x = (uint32)_WindowX; - y = (uint32)_WindowY; + x = _WindowX; + y = _WindowY; } } diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h index 4f89f97eb..a2d0dddf6 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.h @@ -58,14 +58,17 @@ bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable); /// mac specific stuff while calling CDriverGL::setMode() bool setMode(const GfxMode& mode); +/// mac specific stuff while calling CDriverGL::getCurrentScreenMode() +void getCurrentScreenMode(GfxMode& mode); + /// mac specific stuff while calling CDriverGL::getWindowSize() void getWindowSize(uint32 &width, uint32 &height); /// mac specific stuff while calling CDriverGL::getWindowPos() -void getWindowPos(uint32 &x, uint32 &y); +void getWindowPos(sint32 &x, sint32 &y); /// mac specific stuff while calling CDriverGL::setWindowPos() -void setWindowPos(uint32 x, uint32 y); +void setWindowPos(sint32 x, sint32 y); /// mac specific stuff while calling CDriverGL::setWindowTitle() void setWindowTitle(const ucstring &title); diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm index c236cc9d2..212a7f077 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_adapter.mm @@ -237,11 +237,36 @@ bool setMode(const GfxMode& mode) return true; } +void getCurrentScreenMode(GfxMode& mode) +{ + // the sceen with the menu bar + NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; + + mode.OffScreen = false; + mode.Frequency = 0; + mode.Depth = NSBitsPerPixelFromDepth([screen depth]); + + // in fullscreen mode + if([g_glview isInFullScreenMode]) + { + // return the size of the back buffer (like having switched monitor mode) + mode.Windowed = false; + mode.Width = (uint16)g_bufferSize[0]; + mode.Height = (uint16)g_bufferSize[1]; + } + + // in windowes mode + else + { + // return the size of the screen with menu bar + mode.Windowed = true; + mode.Width = (uint16)[screen frame].size.width; + mode.Height = (uint16)[screen frame].size.height; + } +} + void getWindowSize(uint32 &width, uint32 &height) { - if(!g_glctx) - return; - // A cocoa fullscreen view stays at the native resolution of the display. // When changing the rendering resolution, the size of the back buffer gets // changed, but the view still stays at full resolution. So the scaling of @@ -313,10 +338,17 @@ void getWindowSize(uint32 &width, uint32 &height) #endif } -void getWindowPos(uint32 &x, uint32 &y) +void getWindowPos(sint32 &x, sint32 &y) { - // get the rect (position, size) of the screen - NSRect screenRect = [[g_window screen] frame]; + // for IDriver conformity + if([g_glview isInFullScreenMode]) + { + x = y = 0; + return; + } + + // get the rect (position, size) of the screen with menu bar + NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame]; // get the rect (position, size) of the window NSRect windowRect = [g_window frame]; @@ -328,12 +360,12 @@ void getWindowPos(uint32 &x, uint32 &y) y = screenRect.size.height - windowRect.size.height - windowRect.origin.y; } -void setWindowPos(uint32 x, uint32 y) +void setWindowPos(sint32 x, sint32 y) { - // get the size of the screen - NSRect screenRect = [[g_window screen] frame]; + // get the rect (position, size) of the screen with menu bar + NSRect screenRect = [[[NSScreen screens] objectAtIndex:0] frame]; - // get the size of the window + // get the rect (position, size) of the window NSRect windowRect = [g_window frame]; // convert y from NeL coordinates to cocoa coordinates diff --git a/code/nel/src/3d/driver_user.cpp b/code/nel/src/3d/driver_user.cpp index 255d3e4ed..5afebf8e3 100644 --- a/code/nel/src/3d/driver_user.cpp +++ b/code/nel/src/3d/driver_user.cpp @@ -328,7 +328,7 @@ void CDriverUser::setWindowTitle(const ucstring &title) } // *************************************************************************** -void CDriverUser::setWindowPos(uint32 x, uint32 y) +void CDriverUser::setWindowPos(sint32 x, sint32 y) { NL3D_HAUTO_UI_DRIVER; _Driver->setWindowPos(x, y); @@ -1530,7 +1530,7 @@ uint CDriverUser::getWindowHeight () _Driver->getWindowSize (width, height); return height; } -void CDriverUser::getWindowPos (uint32 &x, uint32 &y) +void CDriverUser::getWindowPos (sint32 &x, sint32 &y) { NL3D_HAUTO_UI_DRIVER; diff --git a/code/ryzom/client/src/client_cfg.cpp b/code/ryzom/client/src/client_cfg.cpp index 7e927717b..87d4f038c 100644 --- a/code/ryzom/client/src/client_cfg.cpp +++ b/code/ryzom/client/src/client_cfg.cpp @@ -2009,7 +2009,8 @@ void CClientConfig::release () // Driver still alive ? if (Driver && Driver->isActive ()) { - uint32 x, y, width, height; + sint32 x, y; + uint32 width, height; Driver->getWindowPos(x, y); Driver->getWindowSize(width, height); diff --git a/code/ryzom/client/src/client_cfg.h b/code/ryzom/client/src/client_cfg.h index 196374712..33a20fa63 100644 --- a/code/ryzom/client/src/client_cfg.h +++ b/code/ryzom/client/src/client_cfg.h @@ -61,8 +61,8 @@ struct CClientConfig bool SaveConfig; /// Window position in windowed mode - sint PositionX; - sint PositionY; + sint32 PositionX; + sint32 PositionY; /// Window frequency uint Frequency; diff --git a/code/ryzom/client/src/init.cpp b/code/ryzom/client/src/init.cpp index a232b835f..fe6fd7f8e 100644 --- a/code/ryzom/client/src/init.cpp +++ b/code/ryzom/client/src/init.cpp @@ -908,7 +908,7 @@ void prelogInit() // Set the title Driver->setWindowTitle(CI18N::get("TheSagaOfRyzom")); - uint32 posX = 0, posY = 0; + sint32 posX = 0, posY = 0; if (ClientCfg.Windowed) {