From aa28f603577627cd8a65d242bb261f2e2a5b82a1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 16 Mar 2007 13:22:05 +0000 Subject: [PATCH] Added WindowData structures to GraphicsWindowX11,Win32 and Carbon to help support GraphicsWindow inheriting their window handles from an external toolkit --- include/osg/GraphicsContext | 2 +- include/osgViewer/GraphicsWindowCarbon | 15 +++++++++++++-- include/osgViewer/GraphicsWindowWin32 | 13 ++++++++++++- include/osgViewer/GraphicsWindowX11 | 14 ++++++++++++-- src/osgViewer/GraphicsWindowCarbon.cpp | 2 +- src/osgViewer/GraphicsWindowWin32.cpp | 8 +++++--- src/osgViewer/GraphicsWindowX11.cpp | 2 +- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/include/osg/GraphicsContext b/include/osg/GraphicsContext index 6b621f2a6..805bd8b96 100644 --- a/include/osg/GraphicsContext +++ b/include/osg/GraphicsContext @@ -125,7 +125,7 @@ class OSG_EXPORT GraphicsContext : public Object // shared context GraphicsContext* sharedContext; - osg::ref_ptr inhertedWindowData; + osg::ref_ptr inheritedWindowData; }; diff --git a/include/osgViewer/GraphicsWindowCarbon b/include/osgViewer/GraphicsWindowCarbon index 81cbae150..28efe109f 100644 --- a/include/osgViewer/GraphicsWindowCarbon +++ b/include/osgViewer/GraphicsWindowCarbon @@ -32,13 +32,14 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow public: GraphicsWindowCarbon(osg::GraphicsContext::Traits* traits): + _ownWindow(true), _valid(false), _initialized(false), _realized(false) { _traits = traits; - init(); + init(traits ? dynamic_cast(traits->inheritedWindowData.get()) : 0); if (valid()) { @@ -98,9 +99,18 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow bool handleMouseEvent(EventRef theEvent); bool handleKeyboardEvent(EventRef theEvent); + /** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */ + struct WindowData : public osg::Referenced + { + WindowData(Window window): + _window(window) {} + + Window _window; + }; + protected: - void init(); + void init(WindowData* inheritedWindowData=0); void transformMouseXY(float& x, float& y); @@ -111,6 +121,7 @@ class GraphicsWindowCarbon : public osgViewer::GraphicsWindow bool _realized; bool _useWindowDecoration; + bool _ownsWindow; WindowRef _window; AGLContext _context; AGLPixelFormat _pixelFormat; diff --git a/include/osgViewer/GraphicsWindowWin32 b/include/osgViewer/GraphicsWindowWin32 index 24da74e52..c4900cf93 100644 --- a/include/osgViewer/GraphicsWindowWin32 +++ b/include/osgViewer/GraphicsWindowWin32 @@ -78,9 +78,19 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow /** Handle a native (Win32) windowing event as received from the system */ virtual LRESULT handleNativeWindowingEvent( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); + /** WindowData is used to pass in the Win32 window handle attached the GraphicsContext::Traits structure.*/ + struct WindowData : public osg::Referenced + { + WindowData(HWND window): + _hwnd(window) {} + + HWND _hwnd; + }; + + protected: - void init(); + void init(WindowData* inheritedWindowData=0); void registerWindowClass(); @@ -100,6 +110,7 @@ class GraphicsWindowWin32 : public osgViewer::GraphicsWindow HGLRC getWGLContext() { return _hglrc; } + bool _ownsWindow; HWND _hwnd; HDC _hdc; HGLRC _hglrc; diff --git a/include/osgViewer/GraphicsWindowX11 b/include/osgViewer/GraphicsWindowX11 index b0097dcb3..01efa739f 100644 --- a/include/osgViewer/GraphicsWindowX11 +++ b/include/osgViewer/GraphicsWindowX11 @@ -50,7 +50,7 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow { _traits = traits; - init(); + init(traits ? dynamic_cast(traits->inheritedWindowData.get()) : 0); if (valid()) { @@ -108,6 +108,15 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow /** Switch on/off the cursor.*/ virtual void useCursor(bool cursorOn); + /** WindowData is used to pass in the X11 window handle attached the GraphicsContext::Traits structure. */ + struct WindowData : public osg::Referenced + { + WindowData(Window window): + _window(window) {} + + Window _window; + }; + public: // X11 specific aces functions @@ -127,7 +136,8 @@ class GraphicsWindowX11 : public osgViewer::GraphicsWindow ~GraphicsWindowX11(); bool createVisualInfo(); - void init(); + + void init(WindowData* inheritedWindowData=0); void transformMouseXY(float& x, float& y); void adaptKey(XKeyEvent& keyevent, int& keySymbol, unsigned int& modifierMask); diff --git a/src/osgViewer/GraphicsWindowCarbon.cpp b/src/osgViewer/GraphicsWindowCarbon.cpp index e16e80035..05ca650aa 100644 --- a/src/osgViewer/GraphicsWindowCarbon.cpp +++ b/src/osgViewer/GraphicsWindowCarbon.cpp @@ -536,7 +536,7 @@ void GraphicsWindowCarbon::setWindowDecoration(bool flag) _useWindowDecoration = flag; } -void GraphicsWindowCarbon::init() +void GraphicsWindowCarbon::init(WindowData* inheritedWindowData) { _closeRequested = false; _context = NULL; diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index 00dca8427..dd9277b41 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -980,7 +980,9 @@ osgViewer::GraphicsWindowWin32* Win32WindowingSystem::getGraphicsWindowFor( HWND ////////////////////////////////////////////////////////////////////////////// GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits ) -: _hwnd(0), +: + _ownsWindow(true), + _hwnd(0), _hdc(0), _hglrc(0), _timeOfLastCheckEvents(-1.0), @@ -1000,7 +1002,7 @@ GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits ) { _traits = traits; - init(); + init(traits ? dynamic_cast(traits->inheritedWindowData.get()) : 0); if (valid()) { @@ -1025,7 +1027,7 @@ GraphicsWindowWin32::~GraphicsWindowWin32() destroyWindow(); } -void GraphicsWindowWin32::init() +void GraphicsWindowWin32::init(WindowData* inheritedWindowData) { if (!_initialized) { diff --git a/src/osgViewer/GraphicsWindowX11.cpp b/src/osgViewer/GraphicsWindowX11.cpp index 3d15a6130..66df5add0 100644 --- a/src/osgViewer/GraphicsWindowX11.cpp +++ b/src/osgViewer/GraphicsWindowX11.cpp @@ -367,7 +367,7 @@ void GraphicsWindowX11::useCursor(bool cursorOn) } -void GraphicsWindowX11::init() +void GraphicsWindowX11::init(WindowData* inheritedWindowData) { if (_initialized) return;