OpenWalnut  1.5.0dev
WGEGraphicsWindow.cpp
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 #include <iostream>
26 
27 #include "core/common/WLogger.h"
28 
29 #include "WGEGraphicsWindow.h"
30 
31 #include "exceptions/WGEInitFailed.h"
32 
33 WGEGraphicsWindow::WGEGraphicsWindow( osg::ref_ptr< osg::Referenced >, int x, int y, int width, int height ) : m_closed( false )
34 {
35  m_GraphicsWindow = osg::ref_ptr<osgViewer::GraphicsWindow>(
36  static_cast<osgViewer::GraphicsWindow*>( new osgViewer::GraphicsWindowEmbedded( x, y, width, height ) ) );
37 }
38 
40 {
41  // cleanup
42 }
43 
44 osg::ref_ptr<osgViewer::GraphicsWindow> WGEGraphicsWindow::getGraphicsWindow()
45 {
46  return m_GraphicsWindow;
47 }
48 
49 void WGEGraphicsWindow::resize( int width, int height )
50 {
51  if( !m_GraphicsWindow )
52  {
53  return;
54  }
55 
56  m_GraphicsWindow->getEventQueue()->windowResize( 0, 0, width, height );
57  m_GraphicsWindow->resized( 0, 0, width, height );
58 }
59 
61 {
62  setClosed( true );
63 
64  // this causes segfaults ...
65  // m_GraphicsWindow->getEventQueue()->closeWindow();
66 }
67 
68 void WGEGraphicsWindow::keyEvent( KeyEvents eventType, int key )
69 {
70  if( !m_GraphicsWindow )
71  {
72  return;
73  }
74 
75  switch( eventType )
76  {
77  case KEYPRESS:
78  m_GraphicsWindow->getEventQueue()->keyPress( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
79  break;
80  case KEYRELEASE:
81  m_GraphicsWindow->getEventQueue()->keyRelease( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
82  break;
83  }
84 }
85 
86 void WGEGraphicsWindow::mouseEvent( MouseEvents eventType, int x, int y, int button )
87 {
88  if( !m_GraphicsWindow )
89  {
90  return;
91  }
92  switch( eventType )
93  {
94  case MOUSEPRESS:
95  m_GraphicsWindow->getEventQueue()->mouseButtonPress( x, y, button );
96  break;
97  case MOUSERELEASE:
98  m_GraphicsWindow->getEventQueue()->mouseButtonRelease( x, y, button );
99  break;
100  case MOUSEDOUBLECLICK:
101  m_GraphicsWindow->getEventQueue()->mouseDoubleButtonPress( x, y, button );
102  break;
103  case MOUSEMOVE:
104  m_GraphicsWindow->getEventQueue()->mouseMotion( x, y );
105  break;
106  case MOUSESCROLL:
107  m_GraphicsWindow->getEventQueue()->mouseScroll2D( x, y );
108  break;
109  }
110 }
111 
113 {
114  return m_closed;
115 }
116 
117 void WGEGraphicsWindow::setClosed( bool closed )
118 {
119  m_closed = closed;
120 }
121 
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.