diff --git a/include/osgViewer/GraphicsWindowCocoa b/include/osgViewer/GraphicsWindowCocoa new file mode 100644 index 000000000..c93453520 --- /dev/null +++ b/include/osgViewer/GraphicsWindowCocoa @@ -0,0 +1,89 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +/* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both + * a guide to use of X11/GLX and copiying directly in the case of setBorder(). + * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns. + */ + +#ifndef OSGVIEWER_GRAPHICSWINDOWCOCOA +#define OSGVIEWER_GRAPHICSWINDOWCOCOA 1 + +#include + +namespace osgViewer +{ + +class GraphicsWindowCocoa : public osgViewer::GraphicsWindow +{ + public: + + GraphicsWindowCocoa(osg::GraphicsContext::Traits* traits): + _valid(false), + _initialized(false), + _realized(false) + { + _traits = traits; + + init(); + + if (valid()) + { + setState( new osg::State ); + getState()->setContextID( osg::GraphicsContext::createNewContextID() ); + } + } + + virtual bool valid() const { return _valid; } + + /** Realise the GraphicsContext.*/ + virtual bool realizeImplementation(); + + /** Return true if the graphics context has been realised and is ready to use.*/ + virtual bool isRealizedImplementation() const { return _realized; } + + /** Close the graphics context.*/ + virtual void closeImplementation(); + + /** Make this graphics context current.*/ + virtual void makeCurrentImplementation(); + + /** Swap the front and back buffers.*/ + virtual void swapBuffersImplementation(); + + /** Check to see if any events have been generated.*/ + virtual void checkEvents(); + + /** Set Window decoration.*/ + virtual void setWindowDecoration(bool flag); + + /** Get focus.*/ + virtual void grabFocus(); + + /** Get focus on if the pointer is in this window.*/ + virtual void grabFocusIfPointerInWindow(); + + protected: + + void init(); + + void transformMouseXY(float& x, float& y); + + bool _valid; + bool _initialized; + bool _realized; +}; + +} + +#endif diff --git a/include/osgViewer/GraphicsWindowWin32 b/include/osgViewer/GraphicsWindowWin32 new file mode 100644 index 000000000..1969b8e31 --- /dev/null +++ b/include/osgViewer/GraphicsWindowWin32 @@ -0,0 +1,89 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +/* Note, elements of GraphicsWindowX11 have used Prodcer/RenderSurface_X11.cpp as both + * a guide to use of X11/GLX and copiying directly in the case of setBorder(). + * These elements are license under OSGPL as above, with Copyright (C) 2001-2004 Don Burns. + */ + +#ifndef OSGVIEWER_GRAPHICSWINDOWWIN32 +#define OSGVIEWER_GRAPHICSWINDOWIN32 1 + +#include + +namespace osgViewer +{ + +class GraphicsWindowWin32 : public osgViewer::GraphicsWindow +{ + public: + + GraphicsWindowWin32(osg::GraphicsContext::Traits* traits): + _valid(false), + _initialized(false), + _realized(false) + { + _traits = traits; + + init(); + + if (valid()) + { + setState( new osg::State ); + getState()->setContextID( osg::GraphicsContext::createNewContextID() ); + } + } + + virtual bool valid() const { return _valid; } + + /** Realise the GraphicsContext.*/ + virtual bool realizeImplementation(); + + /** Return true if the graphics context has been realised and is ready to use.*/ + virtual bool isRealizedImplementation() const { return _realized; } + + /** Close the graphics context.*/ + virtual void closeImplementation(); + + /** Make this graphics context current.*/ + virtual void makeCurrentImplementation(); + + /** Swap the front and back buffers.*/ + virtual void swapBuffersImplementation(); + + /** Check to see if any events have been generated.*/ + virtual void checkEvents(); + + /** Set Window decoration.*/ + virtual void setWindowDecoration(bool flag); + + /** Get focus.*/ + virtual void grabFocus(); + + /** Get focus on if the pointer is in this window.*/ + virtual void grabFocusIfPointerInWindow(); + + protected: + + void init(); + + void transformMouseXY(float& x, float& y); + + bool _valid; + bool _initialized; + bool _realized; +}; + +} + +#endif diff --git a/src/osgViewer/GNUmakefile b/src/osgViewer/GNUmakefile index 58e0593a2..d69407ed0 100644 --- a/src/osgViewer/GNUmakefile +++ b/src/osgViewer/GNUmakefile @@ -13,6 +13,10 @@ CXXFILES = \ CXXFILES += GraphicsWindowX11.cpp\ +# CXXFILES += GraphicsWindowWin32.cpp\ + +# CXXFILES += GraphicsWindowCocoa.cpp\ + DEF += -DOSGVIEWER_LIBRARY diff --git a/src/osgViewer/GraphicsWindowCocoa.cpp b/src/osgViewer/GraphicsWindowCocoa.cpp new file mode 100644 index 000000000..95f64065d --- /dev/null +++ b/src/osgViewer/GraphicsWindowCocoa.cpp @@ -0,0 +1,178 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + + +using namespace osgViewer; + +namespace osgViewer +{ + +/** This is the class we need to create for pbuffers, note its not a GraphicsWindow as it won't need any of the event handling and window mapping facilities.*/ +class GraphicsContextCocoa : public osg::GraphicsContext +{ + public: + + GraphicsContextCocoa(osg::GraphicsContext::Traits* traits): + _valid(false) + { + _traits = traits; + } + + virtual bool valid() const { return _valid; } + + /** Realise the GraphicsContext implementation, + * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ + virtual bool realizeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::realizeImplementation() not implemented."<getUseFixedMouseInputRange()) + { + osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); + x = eventState->getXmin() + (eventState->getXmax()-eventState->getXmin())*x/float(_traits->width); + y = eventState->getYmin() + (eventState->getYmax()-eventState->getYmin())*y/float(_traits->height); + } +} + +struct CocoaWindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface +{ + + CocoaWindowingSystemInterface() + { + + } + + virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) + { + osg::notify(osg::NOTICE)<<"CocoaWindowingSystemInterface::getNumScreens() Please implement me!"<pbuffer) + { + osg::ref_ptr pbuffer = new GraphicsContextCocoa(traits); + if (pbuffer->valid()) return pbuffer.release(); + else return 0; + } + else + { + osg::ref_ptr window = new GraphicsWindowCocoa(traits); + if (window->valid()) return window.release(); + else return 0; + } + } + +}; + +struct RegisterWindowingSystemInterfaceProxy +{ + RegisterWindowingSystemInterfaceProxy() + { + osg::GraphicsContext::setWindowingSystemInterface(new CocoaWindowingSystemInterface); + } + + ~RegisterWindowingSystemInterfaceProxy() + { + osg::GraphicsContext::setWindowingSystemInterface(0); + } +}; + +RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy; diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp new file mode 100644 index 000000000..d1d7368e5 --- /dev/null +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -0,0 +1,178 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + + +using namespace osgViewer; + +namespace osgViewer +{ + +/** This is the class we need to create for pbuffers, note its not a GraphicsWindow as it won't need any of the event handling and window mapping facilities.*/ +class GraphicsContextWin32 : public osg::GraphicsContext +{ + public: + + GraphicsContextWin32(osg::GraphicsContext::Traits* traits): + _valid(false) + { + _traits = traits; + } + + virtual bool valid() const { return _valid; } + + /** Realise the GraphicsContext implementation, + * Pure virtual - must be implemented by concrate implementations of GraphicsContext. */ + virtual bool realizeImplementation() { osg::notify(osg::NOTICE)<<"GraphicsWindow::realizeImplementation() not implemented."<getUseFixedMouseInputRange()) + { + osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); + x = eventState->getXmin() + (eventState->getXmax()-eventState->getXmin())*x/float(_traits->width); + y = eventState->getYmin() + (eventState->getYmax()-eventState->getYmin())*y/float(_traits->height); + } +} + +struct Win32WindowingSystemInterface : public osg::GraphicsContext::WindowingSystemInterface +{ + + Win32WindowingSystemInterface() + { + + } + + virtual unsigned int getNumScreens(const osg::GraphicsContext::ScreenIdentifier& si) + { + osg::notify(osg::NOTICE)<<"Win32WindowingSystemInterface::getNumScreens() Please implement me!"<pbuffer) + { + osg::ref_ptr pbuffer = new GraphicsContextWin32(traits); + if (pbuffer->valid()) return pbuffer.release(); + else return 0; + } + else + { + osg::ref_ptr window = new GraphicsWindowWin32(traits); + if (window->valid()) return window.release(); + else return 0; + } + } + +}; + +struct RegisterWindowingSystemInterfaceProxy +{ + RegisterWindowingSystemInterfaceProxy() + { + osg::GraphicsContext::setWindowingSystemInterface(new Win32WindowingSystemInterface); + } + + ~RegisterWindowingSystemInterfaceProxy() + { + osg::GraphicsContext::setWindowingSystemInterface(0); + } +}; + +RegisterWindowingSystemInterfaceProxy createWindowingSystemInterfaceProxy; diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index c6d25877a..358422b96 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -246,6 +246,8 @@ void Viewer::frame() { if (_done) return; + // osg::notify(osg::NOTICE)<