StatsHandler 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* -*-c++-*-
  2. * Copyright (C) 2009 Cedric Pinson <mornifle@plopbyte.net>
  3. *
  4. * This library is open source and may be redistributed and/or modified under
  5. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  6. * (at your option) any later version. The full license is in LICENSE file
  7. * included with this distribution, and on the openscenegraph.org website.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * OpenSceneGraph Public License for more details.
  13. */
  14. #ifndef OSGANIMATION_STATSHANDLER_H
  15. #define OSGANIMATION_STATSHANDLER_H
  16. #include <osgAnimation/Timeline>
  17. #include <osgGA/GUIEventHandler>
  18. #include <osgViewer/ViewerBase>
  19. #include <osgViewer/Viewer>
  20. #include <osgText/Text>
  21. namespace osgAnimation
  22. {
  23. #if 0
  24. struct StatAction
  25. {
  26. std::string _name;
  27. osg::ref_ptr<osg::Group> _group;
  28. osg::ref_ptr<osg::Geode> _label;
  29. osg::ref_ptr<osg::MatrixTransform> _graph;
  30. osg::ref_ptr<osgText::Text> _textLabel;
  31. void init(osg::Stats* stats, const std::string& name, const osg::Vec3& pos, float width, float heigh, const osg::Vec4& color);
  32. void setPosition(const osg::Vec3& pos);
  33. void setAlpha(float v);
  34. };
  35. #endif
  36. /** Event handler for adding on screen stats reporting to Viewers.*/
  37. class OSGANIMATION_EXPORT StatsHandler : public osgGA::GUIEventHandler
  38. {
  39. public:
  40. StatsHandler();
  41. enum StatsType
  42. {
  43. NO_STATS = 0,
  44. FRAME_RATE = 1,
  45. LAST = 2
  46. };
  47. void setKeyEventTogglesOnScreenStats(int key) { _keyEventTogglesOnScreenStats = key; }
  48. int getKeyEventTogglesOnScreenStats() const { return _keyEventTogglesOnScreenStats; }
  49. void setKeyEventPrintsOutStats(int key) { _keyEventPrintsOutStats = key; }
  50. int getKeyEventPrintsOutStats() const { return _keyEventPrintsOutStats; }
  51. double getBlockMultiplier() const { return _blockMultiplier; }
  52. void reset();
  53. osg::Camera* getCamera() { return _camera.get(); }
  54. const osg::Camera* getCamera() const { return _camera.get(); }
  55. virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
  56. /** Get the keyboard and mouse usage of this manipulator.*/
  57. virtual void getUsage(osg::ApplicationUsage& usage) const;
  58. protected:
  59. void setUpHUDCamera(osgViewer::ViewerBase* viewer);
  60. osg::Geometry* createBackgroundRectangle(const osg::Vec3& pos, const float width, const float height, osg::Vec4& color);
  61. osg::Geometry* createGeometry(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numBlocks);
  62. osg::Geometry* createFrameMarkers(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numBlocks);
  63. osg::Geometry* createTick(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numTicks);
  64. osg::Node* createCameraTimeStats(const std::string& font, osg::Vec3& pos, float startBlocks, bool acquireGPUStats, float characterSize, osg::Stats* viewerStats, osg::Camera* camera);
  65. void setUpScene(osgViewer::Viewer* viewer);
  66. int _keyEventTogglesOnScreenStats;
  67. int _keyEventPrintsOutStats;
  68. int _statsType;
  69. bool _initialized;
  70. osg::ref_ptr<osg::Camera> _camera;
  71. osg::ref_ptr<osg::Switch> _switch;
  72. osg::ref_ptr<osg::Group> _group;
  73. unsigned int _frameRateChildNum;
  74. unsigned int _numBlocks;
  75. double _blockMultiplier;
  76. float _statsWidth;
  77. float _statsHeight;
  78. // std::map<std::string, StatAction > _actions;
  79. };
  80. }
  81. #endif