Debian Codegraph @

utils/fgviewer/Drawable.hxx

raw symbols SCIP
1 // Copyright (C) 2009 - 2012 Mathias Froehlich
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17 #ifndef _fgviewer_Drawable_hxx
18 #define _fgviewer_Drawable_hxx
19
20 #include <string>
21 #include <list>
22 #include <osg/GraphicsContext>
23 #include <simgear/math/SGMath.hxx>
24 #include <simgear/structure/SGWeakReferenced.hxx>
25
26 namespace fgviewer {
27
28 class Viewer;
29 class SlaveCamera;
30
31 class Drawable : public SGWeakReferenced {
32 public:
33 Drawable(const std::string& name);
34 virtual ~Drawable();
35
36 const std::string& getName() const
37 { return _name; }
38
39 virtual bool setScreenIdentifier(const std::string& screenIdentifier)
40 {
41 if (_graphicsContext.valid())
42 return false;
43 _screenIdentifier = screenIdentifier;
44 return true;
45 }
46 const std::string& getScreenIdentifier() const
47 { return _screenIdentifier; }
48
49 virtual bool setPosition(const SGVec2i& position)
50 { _position = position; return true; }
51 const SGVec2i& getPosition() const
52 { return _position; }
53
54 virtual bool setSize(const SGVec2i& size)
55 { _size = size; return true; }
56 const SGVec2i& getSize() const
57 { return _size; }
58
59 virtual bool setOffscreen(bool offscreen)
60 {
61 if (_graphicsContext.valid())
62 return false;
63 _offscreen = offscreen;
64 return true;
65 }
66 bool getOffscreen() const
67 { return _offscreen; }
68
69 virtual bool setFullscreen(bool fullscreen)
70 { _fullscreen = fullscreen; return true; }
71 bool getFullscreen() const
72 { return _fullscreen; }
73
74 osg::GraphicsContext* getGraphicsContext()
75 { return _graphicsContext.get(); }
76
77 void attachSlaveCamera(SlaveCamera* slaveCamera);
78
79 virtual bool resize(int x, int y, int width, int height);
80
81 bool realize(Viewer& viewer);
82
83 protected:
84 virtual osg::GraphicsContext* _realizeImplementation(Viewer& viewer);
85 osg::ref_ptr<osg::GraphicsContext::Traits> _getTraits(Viewer& viewer);
86
87 private:
88 Drawable(const Drawable&);
89 Drawable& operator=(const Drawable&);
90
91 class _ResizedCallback;
92
93 /// The immutable name that is used to reference this slave camera.
94 const std::string _name;
95 std::string _screenIdentifier;
96 SGVec2i _position;
97 SGVec2i _size;
98 bool _offscreen;
99 bool _fullscreen;
100 osg::ref_ptr<osg::GraphicsContext> _graphicsContext;
101 std::list<SGSharedPtr<SlaveCamera> > _slaveCameraList;
102 };
103
104 } // namespace fgviewer
105
106 #endif