WGEGraphicsWindow.h

00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WGEGRAPHICSWINDOW_H
00026 #define WGEGRAPHICSWINDOW_H
00027 
00028 #include <boost/shared_ptr.hpp>
00029 #include <osgViewer/GraphicsWindow>
00030 
00031 /**
00032  * Class managing a single graphics context and OSG GraphicsWindow.
00033  * \ingroup ge
00034  */
00035 class WGEGraphicsWindow
00036 {
00037 public:
00038 
00039     /**
00040      * Default constructor.
00041      *
00042      * \param wdata the WindowData instance for the widget to use as render widget. NULL on Mac!
00043      * \param x X coordinate of widget where to create the context.
00044      * \param y Y coordinate of widget where to create the context.
00045      * \param width Width of the widget.
00046      * \param height Height of the Widget.
00047      * \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
00048      */
00049     WGEGraphicsWindow( osg::ref_ptr<osg::Referenced> wdata, int x, int y, int width, int height );
00050 
00051     /**
00052      * Destructor.
00053      */
00054     virtual ~WGEGraphicsWindow();
00055 
00056     /**
00057      * Getter for m_GraphicsWindow.
00058      *
00059      * \return the OSG GraphicsWindow instance.
00060      */
00061     osg::ref_ptr<osgViewer::GraphicsWindow> getGraphicsWindow();
00062 
00063     /**
00064      * Event types for the keyEvent() handler.
00065      */
00066     enum KeyEvents
00067     {
00068         KEYPRESS, KEYRELEASE
00069     };
00070 
00071     /**
00072      * Mouse event types for the mouseEvent() handler.
00073      */
00074     enum MouseEvents
00075     {
00076         MOUSEPRESS, MOUSERELEASE, MOUSEDOUBLECLICK, MOUSEMOVE, MOUSESCROLL
00077     };
00078 
00079     /**
00080      * Updates size information.
00081      *
00082      * \param width new width.
00083      * \param height new height.
00084      */
00085     virtual void resize( int width, int height );
00086 
00087     /**
00088      * Initiates a close event for this viewer. It destroys the graphics context and invalidates the viewer.
00089      * This should be called whenever a QT Widget closes to also free its OSG Viewer resources.
00090      */
00091     virtual void close();
00092 
00093     /**
00094      * Handles key events (if forwarded to this Viewer instance).
00095      *
00096      * \param key the key code.
00097      * \param eventType the type of event.
00098      */
00099     virtual void keyEvent( KeyEvents eventType, int key );
00100 
00101     /**
00102      * Handles mouse events forwarded from widget.
00103      *
00104      * \param eventType the event type.
00105      * \param x x coordinate of event.
00106      * \param y y coordinate of event.
00107      * \param button mouse button.
00108      */
00109     virtual void mouseEvent( MouseEvents eventType, int x, int y, int button );
00110 
00111 protected:
00112     /**
00113      * OpenSceneGraph render window.
00114      */
00115     osg::ref_ptr<osgViewer::GraphicsWindow> m_GraphicsWindow;
00116 
00117 #ifndef __APPLE__
00118      /**
00119      * Creates a new OpenGL context in the calling thread. Needs to be called before any other OpenGL operation.
00120      *
00121      * \param x X coordinate of widget where to create the context.
00122      * \param y Y coordinate of widget where to create the context.
00123      * \param width Width of the widget.
00124      * \param height Height of the Widget.
00125      */
00126     void createContext( int x, int y, int width, int height );
00127 
00128     /**
00129      * OpenSceneGraph render context.
00130      */
00131     osg::ref_ptr<osg::GraphicsContext> m_GraphicsContext;
00132 
00133     /**
00134      * Widget window data.
00135      */
00136     osg::ref_ptr<osg::Referenced> m_WindowData;
00137 #endif
00138 private:
00139 };
00140 
00141 #endif  // WGEGRAPHICSWINDOW_H
00142 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends