root/OpenSceneGraph/trunk/include/osgAnimation/StatsHandler @ 10344

Revision 10344, 4.2 kB (checked in by cedricpinson, 6 years ago)

From Cedric Pinson, split timeline classes in differents files, cleanup and add a statshandler to visualize current action in timeline

Line 
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
15#ifndef OSGANIMATION_STATSHANDLER_H
16#define OSGANIMATION_STATSHANDLER_H
17
18#include <osgAnimation/Timeline>
19#include <osgGA/GUIEventHandler>
20#include <osgViewer/ViewerBase>
21#include <osgViewer/Viewer>
22#include <osgText/Text>
23
24namespace osgAnimation
25{
26#if 0
27    struct StatAction
28    {
29       
30        std::string _name;
31        osg::ref_ptr<osg::Group> _group;
32        osg::ref_ptr<osg::Geode> _label;
33        osg::ref_ptr<osg::MatrixTransform> _graph;
34        osg::ref_ptr<osgText::Text> _textLabel;
35
36        void init(osg::Stats* stats, const std::string& name, const osg::Vec3& pos, float width, float heigh, const osg::Vec4& color);
37        void setPosition(const osg::Vec3& pos);
38        void setAlpha(float v);
39    };
40
41#endif
42
43/** Event handler for adding on screen stats reporting to Viewers.*/
44    class OSGANIMATION_EXPORT StatsHandler : public osgGA::GUIEventHandler
45    {
46    public:
47
48        StatsHandler();
49
50        enum StatsType
51        {
52            NO_STATS = 0,
53            FRAME_RATE = 1,
54            LAST = 2
55        };
56       
57        void setKeyEventTogglesOnScreenStats(int key) { _keyEventTogglesOnScreenStats = key; }
58        int getKeyEventTogglesOnScreenStats() const { return _keyEventTogglesOnScreenStats; }
59       
60        void setKeyEventPrintsOutStats(int key) { _keyEventPrintsOutStats = key; }
61        int getKeyEventPrintsOutStats() const { return _keyEventPrintsOutStats; }
62
63        double getBlockMultiplier() const { return _blockMultiplier; }
64
65        void reset();
66
67        osg::Camera* getCamera() { return _camera.get(); }
68        const osg::Camera* getCamera() const { return _camera.get(); }
69
70        virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
71
72        /** Get the keyboard and mouse usage of this manipulator.*/
73        virtual void getUsage(osg::ApplicationUsage& usage) const;
74
75        void updateGraph(osgAnimation::StatsActionVisitor* visitor); //, float width, float height, float ystart);
76
77    protected:
78
79        void setUpHUDCamera(osgViewer::ViewerBase* viewer);
80
81        osg::Geometry* createBackgroundRectangle(const osg::Vec3& pos, const float width, const float height, osg::Vec4& color);
82
83        osg::Geometry* createGeometry(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numBlocks);
84
85        osg::Geometry* createFrameMarkers(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numBlocks);
86
87        osg::Geometry* createTick(const osg::Vec3& pos, float height, const osg::Vec4& colour, unsigned int numTicks);
88       
89        osg::Node* createCameraTimeStats(const std::string& font, osg::Vec3& pos, float startBlocks, bool acquireGPUStats, float characterSize, osg::Stats* viewerStats, osg::Camera* camera);
90
91        void setUpScene(osgViewer::Viewer* viewer);
92       
93        int                                 _keyEventTogglesOnScreenStats;
94        int                                 _keyEventPrintsOutStats;
95
96        int                                 _statsType;
97
98        bool                                _initialized;
99        osg::ref_ptr<osg::Camera>           _camera;
100       
101        osg::ref_ptr<osg::Switch>           _switch;
102        osg::ref_ptr<osg::Group>            _group;
103       
104        unsigned int                        _frameRateChildNum;
105        unsigned int                        _numBlocks;
106        double                              _blockMultiplier;
107       
108        float                               _statsWidth;
109        float                               _statsHeight;
110
111//        std::map<std::string, StatAction >      _actions;
112    };
113
114}
115#endif
Note: See TracBrowser for help on using the browser.