OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WGEGraphicsWindow.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGEGRAPHICSWINDOW_H
26 #define WGEGRAPHICSWINDOW_H
27 
28 #include <boost/shared_ptr.hpp>
29 #include <osgViewer/GraphicsWindow>
30 
31 /**
32  * Class managing a single graphics context and OSG GraphicsWindow.
33  * \ingroup ge
34  */
36 {
37 public:
38 
39  /**
40  * Default constructor.
41  *
42  * \param wdata the WindowData instance for the widget to use as render widget. NULL on Mac!
43  * \param x X coordinate of widget where to create the context.
44  * \param y Y coordinate of widget where to create the context.
45  * \param width Width of the widget.
46  * \param height Height of the Widget.
47  * \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
48  */
49  WGEGraphicsWindow( osg::ref_ptr<osg::Referenced> wdata, int x, int y, int width, int height );
50 
51  /**
52  * Destructor.
53  */
54  virtual ~WGEGraphicsWindow();
55 
56  /**
57  * Getter for m_GraphicsWindow.
58  *
59  * \return the OSG GraphicsWindow instance.
60  */
61  osg::ref_ptr<osgViewer::GraphicsWindow> getGraphicsWindow();
62 
63  /**
64  * Event types for the keyEvent() handler.
65  */
66  enum KeyEvents
67  {
68  KEYPRESS, KEYRELEASE
69  };
70 
71  /**
72  * Mouse event types for the mouseEvent() handler.
73  */
75  {
76  MOUSEPRESS, MOUSERELEASE, MOUSEDOUBLECLICK, MOUSEMOVE, MOUSESCROLL
77  };
78 
79  /**
80  * Updates size information.
81  *
82  * \param width new width.
83  * \param height new height.
84  */
85  virtual void resize( int width, int height );
86 
87  /**
88  * Initiates a close event for this viewer. It destroys the graphics context and invalidates the viewer.
89  * This should be called whenever a QT Widget closes to also free its OSG Viewer resources.
90  */
91  virtual void close();
92 
93  /**
94  * Handles key events (if forwarded to this Viewer instance).
95  *
96  * \param key the key code.
97  * \param eventType the type of event.
98  */
99  virtual void keyEvent( KeyEvents eventType, int key );
100 
101  /**
102  * Handles mouse events forwarded from widget.
103  *
104  * \param eventType the event type.
105  * \param x x coordinate of event.
106  * \param y y coordinate of event.
107  * \param button mouse button.
108  */
109  virtual void mouseEvent( MouseEvents eventType, int x, int y, int button );
110 
111 protected:
112  /**
113  * OpenSceneGraph render window.
114  */
115  osg::ref_ptr<osgViewer::GraphicsWindow> m_GraphicsWindow;
116 
117 #ifndef __APPLE__
118  /**
119  * Creates a new OpenGL context in the calling thread. Needs to be called before any other OpenGL operation.
120  *
121  * \param x X coordinate of widget where to create the context.
122  * \param y Y coordinate of widget where to create the context.
123  * \param width Width of the widget.
124  * \param height Height of the Widget.
125  */
126  void createContext( int x, int y, int width, int height );
127 
128  /**
129  * OpenSceneGraph render context.
130  */
131  osg::ref_ptr<osg::GraphicsContext> m_GraphicsContext;
132 
133  /**
134  * Widget window data.
135  */
136  osg::ref_ptr<osg::Referenced> m_WindowData;
137 #endif
138 private:
139 };
140 
141 #endif // WGEGRAPHICSWINDOW_H
142