21 #ifndef _OF_WINDOWPROXY_ 22 #define _OF_WINDOWPROXY_ 28 #include <OpenThreads/Thread> 29 #include <osg/FrameStamp> 31 #include <osg/Referenced> 32 #include <osg/observer_ptr> 33 #include <osg/ref_ptr> 34 #include <osgViewer/CompositeViewer> 35 #include <osgViewer/GraphicsWindow> 40 #define BASIC_CALLBACK_SIG unsigned int *winID, unsigned int *row, unsigned int *col 41 #define KEYPRESS_SIG BASIC_CALLBACK_SIG, int *key 42 #define MOUSEMOTION_SIG BASIC_CALLBACK_SIG, float *x, float *y 43 #define BUTTON_SIG MOUSEMOTION_SIG, unsigned int *button 44 #define VR_SIG BASIC_CALLBACK_SIG, const OpenVREvent *vrEvent 64 virtual bool isSameKindAs(
const Object*
object)
const {
return dynamic_cast<const EmbeddedGraphics*
>(object)!=0; }
65 virtual const char* libraryName()
const {
return "OpenFrames"; }
66 virtual const char* className()
const {
return "EmbeddedGraphics"; }
70 virtual void setWindowName(
const std::string& name) { _traits->windowName = name; }
74 virtual void swapBuffersImplementation();
82 bool updateContextImplementation();
89 virtual bool isRealizedImplementation()
const {
return _realized; }
92 virtual bool valid()
const {
return true; }
93 virtual bool releaseContextImplementation() {
return true; }
94 virtual void closeImplementation() {}
95 virtual void grabFocus() {}
96 virtual void grabFocusIfPointerInWindow() {}
97 virtual void raiseWindow() {}
100 virtual ~EmbeddedGraphics();
104 void (*_updateContext)(
unsigned int *winID,
bool *success);
105 void (*_swapBuffers)(
unsigned int *winID);
123 bool handle(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
126 void windowModified();
131 { _keyPressCallback = fcn; }
134 { _mouseMotionCallback = fcn; }
136 void setButtonPressCallback(
void (*fcn)(
BUTTON_SIG))
137 { _buttonPressCallback = fcn; }
139 void setButtonReleaseCallback(
void (*fcn)(
BUTTON_SIG))
140 { _buttonReleaseCallback = fcn; }
142 void setVREventCallback(
void (*fcn)(VR_SIG))
143 { _vrEventCallback = fcn; }
148 void getRenderRectangle(
float x,
float y,
unsigned int &row,
unsigned int &col);
149 void selectRenderRectangle(
unsigned int row,
unsigned int col);
152 unsigned int _currentRow, _currentCol;
158 void (*_vrEventCallback)(VR_SIG);
172 class OF_EXPORT
WindowProxy :
public OpenThreads::Thread,
public osg::Referenced
176 typedef std::vector<osg::ref_ptr<RenderRectangle> > RenderList;
179 unsigned int width,
unsigned int height,
180 unsigned int nrow,
unsigned int ncol,
181 bool embedded =
false,
bool useVR =
false);
183 virtual void cancelCleanup();
188 void setWindowName(
const std::string& name);
190 unsigned int getWindowWidth()
const;
191 unsigned int getWindowHeight()
const;
193 bool isEmbedded()
const {
return _isEmbedded; }
200 void keyPress(
int key);
201 void keyRelease(
int key);
202 void mouseMotion(
float x,
float y);
203 void buttonPress(
float x,
float y,
unsigned int button);
204 void buttonRelease(
float x,
float y,
unsigned int button);
205 void resizeWindow(
int x,
int y,
unsigned int width,
unsigned int height);
208 void setupGrid(
unsigned int width,
unsigned int height);
214 void setTime(
double time);
215 double getTime()
const 217 if(_timeSyncWinProxy.valid())
return _timeSyncWinProxy->getTime();
218 else return _currTime;
222 void setTimeRange(
double tMin,
double tMax);
223 void getTimeRange(
double& tMin,
double& tMax)
const;
225 void pauseTime(
bool pause);
226 bool isTimePaused()
const 228 if(_timeSyncWinProxy.valid())
return _timeSyncWinProxy->isTimePaused();
229 else return _timePaused;
232 void setTimeScale(
double tscale);
233 double getTimeScale()
const 235 if(_timeSyncWinProxy.valid())
return _timeSyncWinProxy->getTimeScale();
236 else return _timeScale;
247 bool synchronizeTime(WindowProxy *winproxy);
248 WindowProxy* getTimeSyncWindow()
const {
return _timeSyncWinProxy.get(); }
266 void pauseAnimation(
bool pause);
272 bool isAnimating()
const {
return ((_animationState == ANIMATING) || (_animationState == PAUSED)); }
275 bool doneAnimating()
const {
return ((_animationState == FAILED) || (_animationState == SUCCESS)); }
282 { _frameThrottle.setDesiredFramerate(fps); }
286 {
return _frameThrottle.getDesiredFramerate(); }
290 {
return _frameThrottle.getFramerate(); }
292 osgViewer::CompositeViewer* getViewer()
const {
return _viewer.get(); }
295 void setGridSize(
unsigned int row,
unsigned int col);
296 inline unsigned int getNumRows()
const {
return _nRow; }
297 inline unsigned int getNumCols()
const {
return _nCol; }
299 void setScene(FrameManager *fm,
unsigned int row,
unsigned int col);
300 FrameManager* getScene(
unsigned int row,
unsigned int col);
303 RenderRectangle* getGridPosition(
unsigned int row,
unsigned int col);
306 void setMakeCurrentFunction(
void (*fcn)(
unsigned int *winID,
bool *success));
311 void setUpdateContextFunction(
void (*fcn)(
unsigned int *winID,
bool *success));
314 void setSwapBuffersFunction(
void (*fcn)(
unsigned int *winID));
318 { _eventHandler->setKeyPressCallback(fcn); }
321 { _eventHandler->setMouseMotionCallback(fcn); }
323 void setButtonPressCallback(
void (*fcn)(
BUTTON_SIG))
324 { _eventHandler->setButtonPressCallback(fcn); }
326 void setButtonReleaseCallback(
void (*fcn)(
BUTTON_SIG))
327 { _eventHandler->setButtonReleaseCallback(fcn); }
329 void setVREventCallback(
void (*fcn)(VR_SIG))
330 { _eventHandler->setVREventCallback(fcn); }
334 inline void setID(
unsigned int id) { _winID = id; }
335 inline unsigned int getID()
const {
return _winID; }
346 if (_useVR) _ovrDevice->setWorldUnitsPerMeter(worldUnitsPerMeter);
348 double getWorldUnitsPerMeter()
350 if (_useVR)
return _ovrDevice->getWorldUnitsPerMeter();
357 if (_useVR) _ovrDevice->setWorldUnitsPerMeterLimits(minWorldUnitsPerMeter, maxWorldUnitsPerMeter);
359 void getWorldUnitsPerMeterLimits(
double &minWorldUnitsPerMeter,
double &maxWorldUnitsPerMeter)
361 if (_useVR) _ovrDevice->getWorldUnitsPerMeterLimits(minWorldUnitsPerMeter, maxWorldUnitsPerMeter);
367 if (_useVR) _ovrDevice->setUserHeight(height);
377 void captureWindow();
382 void setWindowCaptureFile(
const std::string& fname,
const std::string& fext);
387 { _screenCaptureHandler->setKeyEventTakeScreenShot(key); }
393 void collectScenes();
400 unsigned int _nRow, _nCol;
404 RenderList _renderList;
406 typedef std::set<FrameManager*> SceneSet;
410 osg::ref_ptr<osgViewer::CompositeViewer>
_viewer;
413 osg::ref_ptr<osgViewer::GraphicsWindow>
_window;
431 bool _pauseAnimation;
434 double _currTime, _offsetTime, _timeScale;
435 double _minTime, _maxTime;
436 osg::observer_ptr<WindowProxy> _timeSyncWinProxy;
439 osg::ref_ptr<OpenVRDevice> _ovrDevice;
440 osg::ref_ptr<VRTextureBuffer> _vrTextureBuffer;
osg::ref_ptr< WindowEventHandler > _eventHandler
Definition: WindowProxy.hpp:419
void setDesiredFramerate(const double &fps)
Definition: WindowProxy.hpp:281
void setWindowCaptureKey(int key)
Definition: WindowProxy.hpp:386
This class implements a framerate-limiting algorithm.
Definition: FramerateLimiter.hpp:40
Represents data needed to use an OpenVR-supported HMD.
Definition: OpenVRDevice.hpp:87
void shutdown()
Definition: WindowProxy.hpp:211
void resetAnimationState()
If animation is done, then reset the animation state.
Definition: WindowProxy.hpp:278
const OpenVRDevice * getOpenVRDevice() const
Definition: WindowProxy.hpp:341
virtual bool makeCurrentImplementation()
virtual bool realizeImplementation()
void setUpdateContextFunction(void(*fcn)(unsigned int *winID, bool *success))
osg::ref_ptr< osgViewer::GraphicsWindow > _window
Definition: WindowProxy.hpp:413
osg::ref_ptr< osgViewer::ScreenCaptureHandler > _screenCaptureHandler
Definition: WindowProxy.hpp:425
void setMakeCurrentFunction(void(*fcn)(unsigned int *winID, bool *success))
unsigned int _winID
Definition: WindowProxy.hpp:398
void setWorldUnitsPerMeter(double worldUnitsPerMeter)
Definition: WindowProxy.hpp:344
AnimationState _animationState
Definition: WindowProxy.hpp:430
Defines an interface that can draw a scene onto any window.
Definition: WindowProxy.hpp:172
Definition: CoordinateAxes.hpp:29
virtual bool valid() const
Definition: WindowProxy.hpp:92
void setUserHeight(const double &height)
Definition: WindowProxy.hpp:365
#define KEYPRESS_SIG
Definition: OF_Interface.h:53
This class handles incoming events.
Definition: WindowProxy.hpp:117
void(* _makeCurrent)(unsigned int *winID, bool *success)
Definition: WindowProxy.hpp:103
AnimationState
Definition: WindowProxy.hpp:251
AnimationState getAnimationState() const
Get the current animation state.
Definition: WindowProxy.hpp:269
void setID(unsigned int id)
Definition: WindowProxy.hpp:334
void setSwapBuffersFunction(void(*fcn)(unsigned int *winID))
osg::ref_ptr< EmbeddedGraphics > _embeddedGraphics
Definition: WindowProxy.hpp:416
double getFramerate()
Definition: WindowProxy.hpp:289
virtual void setWindowName(const std::string &name)
Definition: WindowProxy.hpp:70
#define BUTTON_SIG
Definition: OF_Interface.h:57
double getDesiredFramerate()
Definition: WindowProxy.hpp:285
osg::ref_ptr< osgViewer::StatsHandler > _statsHandler
Definition: WindowProxy.hpp:422
The class of GraphicsWindow used for embedded graphics.
Definition: WindowProxy.hpp:59
void setWorldUnitsPerMeterLimits(const double &minWorldUnitsPerMeter, const double &maxWorldUnitsPerMeter)
Definition: WindowProxy.hpp:355
#define MOUSEMOTION_SIG
Definition: OF_Interface.h:55
osg::ref_ptr< osgViewer::CompositeViewer > _viewer
Definition: WindowProxy.hpp:410
bool isAnimating() const
Determine whether WindowProxy is in its animation loop.
Definition: WindowProxy.hpp:272
void setKeyPressCallback(void(*fcn)(KEYPRESS_SIG))
Definition: WindowProxy.hpp:317
bool doneAnimating() const
Determine whether WindowProxy is done animating.
Definition: WindowProxy.hpp:275
bool getUseVR()
Definition: WindowProxy.hpp:338