OpenWalnut
1.4.0
|
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 #include "WGraphicsEngineMode.h" 00032 00033 /** 00034 * Class managing a single graphics context and OSG GraphicsWindow. 00035 * \ingroup ge 00036 */ 00037 class WGEGraphicsWindow 00038 { 00039 public: 00040 /** 00041 * Default constructor. 00042 * 00043 * \param wdata the WindowData instance for the widget to use as render widget. NULL on Mac! 00044 * \param x X coordinate of widget where to create the context. 00045 * \param y Y coordinate of widget where to create the context. 00046 * \param width Width of the widget. 00047 * \param height Height of the Widget. 00048 * \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed. 00049 */ 00050 WGEGraphicsWindow( osg::ref_ptr<osg::Referenced> wdata, int x, int y, int width, int height ); 00051 00052 /** 00053 * Destructor. 00054 */ 00055 virtual ~WGEGraphicsWindow(); 00056 00057 /** 00058 * Getter for m_GraphicsWindow. 00059 * 00060 * \return the OSG GraphicsWindow instance. 00061 */ 00062 osg::ref_ptr<osgViewer::GraphicsWindow> getGraphicsWindow(); 00063 00064 /** 00065 * Event types for the keyEvent() handler. 00066 */ 00067 enum KeyEvents 00068 { 00069 KEYPRESS, KEYRELEASE 00070 }; 00071 00072 /** 00073 * Mouse event types for the mouseEvent() handler. 00074 */ 00075 enum MouseEvents 00076 { 00077 MOUSEPRESS, MOUSERELEASE, MOUSEDOUBLECLICK, MOUSEMOVE, MOUSESCROLL 00078 }; 00079 00080 /** 00081 * Updates size information. 00082 * 00083 * \param width new width. 00084 * \param height new height. 00085 */ 00086 virtual void resize( int width, int height ); 00087 00088 /** 00089 * Initiates a close event for this viewer. It destroys the graphics context and invalidates the viewer. 00090 * This should be called whenever a QT Widget closes to also free its OSG Viewer resources. 00091 */ 00092 virtual void close(); 00093 00094 /** 00095 * Handles key events (if forwarded to this Viewer instance). 00096 * 00097 * \param key the key code. 00098 * \param eventType the type of event. 00099 */ 00100 virtual void keyEvent( KeyEvents eventType, int key ); 00101 00102 /** 00103 * Handles mouse events forwarded from widget. 00104 * 00105 * \param eventType the event type. 00106 * \param x x coordinate of event. 00107 * \param y y coordinate of event. 00108 * \param button mouse button. 00109 */ 00110 virtual void mouseEvent( MouseEvents eventType, int x, int y, int button ); 00111 00112 /** 00113 * Check if the windows is open. 00114 * 00115 * \return false if the window is not open anymore. 00116 */ 00117 virtual bool isClosed() const; 00118 00119 /** 00120 * Set closed state. 00121 * 00122 * \param closed true if widget should be marked as closed. 00123 * 00124 */ 00125 virtual void setClosed( bool closed = true ); 00126 protected: 00127 /** 00128 * OpenSceneGraph render window. 00129 */ 00130 osg::ref_ptr<osgViewer::GraphicsWindow> m_GraphicsWindow; 00131 00132 #ifdef WGEMODE_MULTITHREADED 00133 /** 00134 * Creates a new OpenGL context in the calling thread. Needs to be called before any other OpenGL operation. 00135 * 00136 * \param x X coordinate of widget where to create the context. 00137 * \param y Y coordinate of widget where to create the context. 00138 * \param width Width of the widget. 00139 * \param height Height of the Widget. 00140 */ 00141 void createContext( int x, int y, int width, int height ); 00142 00143 /** 00144 * OpenSceneGraph render context. 00145 */ 00146 osg::ref_ptr<osg::GraphicsContext> m_GraphicsContext; 00147 00148 /** 00149 * Widget window data. 00150 */ 00151 osg::ref_ptr<osg::Referenced> m_WindowData; 00152 #endif 00153 private: 00154 /** 00155 * Mark the window opened or closed. 00156 */ 00157 bool m_closed; 00158 }; 00159 00160 #endif // WGEGRAPHICSWINDOW_H 00161