00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <iostream>
00026
00027 #include "WGEGraphicsWindow.h"
00028
00029 #include "exceptions/WGEInitFailed.h"
00030
00031 WGEGraphicsWindow::WGEGraphicsWindow( osg::ref_ptr<osg::Referenced>
00032 #ifndef __APPLE__
00033 wdata
00034 #endif
00035 ,
00036 int x,
00037 int y,
00038 int width,
00039 int height )
00040 {
00041 #ifndef __APPLE__
00042
00043 m_WindowData = wdata;
00044 try
00045 {
00046 createContext( x, y, width, height );
00047 }
00048 catch( ... )
00049 {
00050
00051 throw WGEInitFailed( "Initialization of OpenGL graphics context failed." );
00052 }
00053 #else
00054 m_GraphicsWindow = osg::ref_ptr<osgViewer::GraphicsWindow>(
00055 static_cast<osgViewer::GraphicsWindow*>( new osgViewer::GraphicsWindowEmbedded( x, y, width, height ) ) );
00056 #endif
00057 }
00058
00059 WGEGraphicsWindow::~WGEGraphicsWindow()
00060 {
00061
00062 }
00063
00064 osg::ref_ptr<osgViewer::GraphicsWindow> WGEGraphicsWindow::getGraphicsWindow()
00065 {
00066 return m_GraphicsWindow;
00067 }
00068
00069 #ifndef __APPLE__
00070 void WGEGraphicsWindow::createContext( int x, int y, int width, int height )
00071 {
00072
00073 osg::ref_ptr<osg::DisplaySettings> ds = osg::DisplaySettings::instance();
00074 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
00075
00076
00077 traits->readDISPLAY();
00078 if( traits->displayNum < 0 )
00079 {
00080 traits->displayNum = 0;
00081 }
00082
00083
00084 traits->windowName = "OpenWalnut";
00085 traits->screenNum = 0;
00086 traits->x = x;
00087 traits->y = y;
00088 traits->width = width;
00089 traits->height = height;
00090 traits->alpha = ds->getMinimumNumAlphaBits();
00091 traits->stencil = ds->getMinimumNumStencilBits();
00092
00093 traits->doubleBuffer = true;
00094 traits->sharedContext = 0;
00095 traits->sampleBuffers = ds->getMultiSamples();
00096 traits->samples = ds->getNumMultiSamples();
00097 traits->inheritedWindowData = m_WindowData;
00098
00099
00100 m_GraphicsContext = osg::GraphicsContext::createGraphicsContext( traits.get() );
00101
00102 m_GraphicsWindow = osg::ref_ptr<osgViewer::GraphicsWindow>(
00103 static_cast<osgViewer::GraphicsWindow*>( m_GraphicsContext.get() ) );
00104
00105
00106 traits->x = x;
00107 traits->y = x;
00108 traits->width = width;
00109 traits->height = height;
00110 }
00111 #endif
00112
00113 void WGEGraphicsWindow::resize( int width, int height )
00114 {
00115 m_GraphicsWindow->getEventQueue()->windowResize( 0, 0, width, height );
00116 m_GraphicsWindow->resized( 0, 0, width, height );
00117 }
00118
00119 void WGEGraphicsWindow::close()
00120 {
00121 m_GraphicsWindow->getEventQueue()->closeWindow();
00122 }
00123
00124 void WGEGraphicsWindow::keyEvent( KeyEvents eventType, int key )
00125 {
00126 switch( eventType )
00127 {
00128 case KEYPRESS:
00129 m_GraphicsWindow->getEventQueue()->keyPress( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
00130 break;
00131 case KEYRELEASE:
00132 m_GraphicsWindow->getEventQueue()->keyRelease( static_cast<osgGA::GUIEventAdapter::KeySymbol>( key ) );
00133 break;
00134 }
00135 }
00136
00137 void WGEGraphicsWindow::mouseEvent( MouseEvents eventType, int x, int y, int button )
00138 {
00139 switch( eventType )
00140 {
00141 case MOUSEPRESS:
00142 m_GraphicsWindow->getEventQueue()->mouseButtonPress( x, y, button );
00143 break;
00144 case MOUSERELEASE:
00145 m_GraphicsWindow->getEventQueue()->mouseButtonRelease( x, y, button );
00146 break;
00147 case MOUSEDOUBLECLICK:
00148 m_GraphicsWindow->getEventQueue()->mouseDoubleButtonPress( x, y, button );
00149 break;
00150 case MOUSEMOVE:
00151 m_GraphicsWindow->getEventQueue()->mouseMotion( x, y );
00152 break;
00153 case MOUSESCROLL:
00154 m_GraphicsWindow->getEventQueue()->mouseScroll2D( x, y );
00155 break;
00156 }
00157 }
00158