1 | |
---|
2 | #include <osgDB/WriteFile> |
---|
3 | #include <osgDB/FileNameUtils> |
---|
4 | #include "customviewereventhandler.h" |
---|
5 | |
---|
6 | using namespace osg; |
---|
7 | |
---|
8 | CustomViewerEventHandler::CustomViewerEventHandler(osgProducer::OsgCameraGroup* cg) : |
---|
9 | osgProducer::ViewerEventHandler(cg) |
---|
10 | { |
---|
11 | } |
---|
12 | |
---|
13 | |
---|
14 | void CustomViewerEventHandler::getUsage(osg::ApplicationUsage& usage) const |
---|
15 | { |
---|
16 | usage.addKeyboardMouseBinding("f","Toggle fullscreen"); |
---|
17 | usage.addKeyboardMouseBinding("h","Display help"); |
---|
18 | usage.addKeyboardMouseBinding("O/PrintScreen","Screen capture to \"saved_image*.jpg\""); |
---|
19 | usage.addKeyboardMouseBinding("Space","Toggle surface data time stepping"); |
---|
20 | usage.addKeyboardMouseBinding("c","Toggle steep surface triangle culling"); |
---|
21 | usage.addKeyboardMouseBinding("w","Toggle wireframe mode for surface triangles"); |
---|
22 | usage.addKeyboardMouseBinding("1","Toggle recording."); |
---|
23 | usage.addKeyboardMouseBinding("2","Toggle playback of recorded information"); |
---|
24 | usage.addKeyboardMouseBinding("3","Save recorded macro to \"movie.swm\""); |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | bool CustomViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) |
---|
29 | { |
---|
30 | if(!_cg) return false; |
---|
31 | |
---|
32 | if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN) |
---|
33 | { |
---|
34 | |
---|
35 | switch( ea.getKey() ) |
---|
36 | { |
---|
37 | case 's' : |
---|
38 | { |
---|
39 | FrameStatsMode newFrameStatsMode = (FrameStatsMode)((_frameStatsMode+1)%3); |
---|
40 | setFrameStatsMode(newFrameStatsMode); |
---|
41 | return true; |
---|
42 | } |
---|
43 | |
---|
44 | case 'f' : |
---|
45 | { |
---|
46 | Producer::CameraConfig* cfg = _cg->getCameraConfig(); |
---|
47 | |
---|
48 | bool shouldBeFullScreen = false; |
---|
49 | bool flag = true; |
---|
50 | for( unsigned int i = 0; i < cfg->getNumberOfCameras(); ++i ) |
---|
51 | { |
---|
52 | Producer::Camera *cam = cfg->getCamera(i); |
---|
53 | Producer::RenderSurface* rs = cam->getRenderSurface(); |
---|
54 | if( rs->getDrawableType() != Producer::RenderSurface::DrawableType_Window ) |
---|
55 | continue; |
---|
56 | |
---|
57 | if( flag ) |
---|
58 | { |
---|
59 | shouldBeFullScreen =! rs->isFullScreen(); // Remember the initial state of the first render surface |
---|
60 | flag = false; |
---|
61 | } |
---|
62 | |
---|
63 | if ( shouldBeFullScreen!=rs->isFullScreen() ) // If the current render surface hasn't been modified already |
---|
64 | { |
---|
65 | if (_firstTimeTogglingFullScreen && rs->isFullScreen()) |
---|
66 | { |
---|
67 | unsigned int screenWidth; |
---|
68 | unsigned int screenHeight; |
---|
69 | unsigned int windowWidth; |
---|
70 | unsigned int windowHeight; |
---|
71 | rs->getScreenSize( screenWidth, screenHeight ); |
---|
72 | if( screenHeight > screenWidth ) |
---|
73 | { |
---|
74 | windowWidth = (unsigned int)((float)screenWidth * 0.625); |
---|
75 | windowHeight = (unsigned int)((float)windowWidth * 0.75); |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | windowHeight = (unsigned int)((float)screenHeight * 0.625); |
---|
80 | windowWidth = (unsigned int)((float)windowHeight * 1.334); |
---|
81 | } |
---|
82 | int x = (screenWidth - windowWidth) >> 1; |
---|
83 | int y = (screenHeight - windowHeight) >> 1; |
---|
84 | #ifndef WIN32 |
---|
85 | rs->useBorder(true); |
---|
86 | #else |
---|
87 | rs->fullScreen(false); |
---|
88 | #endif |
---|
89 | rs->setWindowRectangle( x, y, windowWidth, windowHeight ); |
---|
90 | } |
---|
91 | else |
---|
92 | { |
---|
93 | rs->fullScreen(!rs->isFullScreen()); |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | _firstTimeTogglingFullScreen = false; |
---|
98 | |
---|
99 | return true; |
---|
100 | } |
---|
101 | |
---|
102 | case osgGA::GUIEventAdapter::KEY_Print : |
---|
103 | case 'O' : |
---|
104 | { |
---|
105 | setWriteImageOnNextFrame(true); |
---|
106 | return true; |
---|
107 | } |
---|
108 | case '+' : |
---|
109 | { |
---|
110 | //_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()*1.25f); |
---|
111 | return true; |
---|
112 | } |
---|
113 | case '-' : |
---|
114 | { |
---|
115 | //_camera->setFusionDistanceRatio(_camera->getFusionDistanceRatio()/1.25f); |
---|
116 | return true; |
---|
117 | } |
---|
118 | |
---|
119 | case osgGA::GUIEventAdapter::KEY_Help : |
---|
120 | case 'h' : |
---|
121 | { |
---|
122 | setDisplayHelp(!getDisplayHelp()); |
---|
123 | return true; |
---|
124 | } |
---|
125 | |
---|
126 | default: |
---|
127 | break; |
---|
128 | |
---|
129 | } |
---|
130 | } |
---|
131 | return false; |
---|
132 | |
---|
133 | } |
---|