OpenWalnut  1.5.0dev
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 <memory>
29 
30 #include <osgViewer/GraphicsWindow>
31 
32 /**
33  * Class managing a single graphics context and OSG GraphicsWindow.
34  * \ingroup ge
35  */
37 {
38 public:
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  /**
112  * Check if the windows is open.
113  *
114  * \return false if the window is not open anymore.
115  */
116  virtual bool isClosed() const;
117 
118  /**
119  * Set closed state.
120  *
121  * \param closed true if widget should be marked as closed.
122  *
123  */
124  virtual void setClosed( bool closed = true );
125 protected:
126  /**
127  * OpenSceneGraph render window.
128  */
129  osg::ref_ptr<osgViewer::GraphicsWindow> m_GraphicsWindow;
130 
131 private:
132  /**
133  * Mark the window opened or closed.
134  */
135  bool m_closed;
136 };
137 
138 #endif // WGEGRAPHICSWINDOW_H
139 
Class managing a single graphics context and OSG GraphicsWindow.
virtual void mouseEvent(MouseEvents eventType, int x, int y, int button)
Handles mouse events forwarded from widget.
virtual bool isClosed() const
Check if the windows is open.
KeyEvents
Event types for the keyEvent() handler.
virtual void close()
Initiates a close event for this viewer.
virtual void resize(int width, int height)
Updates size information.
osg::ref_ptr< osgViewer::GraphicsWindow > m_GraphicsWindow
OpenSceneGraph render window.
virtual void setClosed(bool closed=true)
Set closed state.
virtual void keyEvent(KeyEvents eventType, int key)
Handles key events (if forwarded to this Viewer instance).
MouseEvents
Mouse event types for the mouseEvent() handler.
osg::ref_ptr< osgViewer::GraphicsWindow > getGraphicsWindow()
Getter for m_GraphicsWindow.
virtual ~WGEGraphicsWindow()
Destructor.
WGEGraphicsWindow(osg::ref_ptr< osg::Referenced > wdata, int x, int y, int width, int height)
Default constructor.
bool m_closed
Mark the window opened or closed.