FlightGear next
WindowSystemAdapter.hxx
Go to the documentation of this file.
1// Copyright (C) 2008 Tim Moore
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 FLIGHTGEAR_WINDOWSYSTEMADAPTER_HXX
18#define FLIGHTGEAR_WINDOWSYSTEMADAPTER_HXX 1
19
20#include <functional>
21#include <string>
22
23#include <osg/Referenced>
24#include <osg/Camera>
25#include <osg/GraphicsThread>
26#include <osg/ref_ptr>
27
28#include <simgear/structure/SGAtomic.hxx>
29
30namespace osg
31{
32class GraphicsContext;
33}
34
35// Flexible window support
36namespace flightgear
37{
40class GraphicsWindow : public osg::Referenced
41{
42public:
43 GraphicsWindow(osg::GraphicsContext* gc_, const std::string& name_,
44 int id_, unsigned flags_ = 0) :
45 gc(gc_), name(name_), id(id_), flags(flags_)
46 {
47 }
48
50 osg::ref_ptr<osg::GraphicsContext> gc;
53 std::string name;
56 int id;
57 enum Flags {
58 GUI = 1
59 };
60
62 unsigned flags;
63};
64
65typedef std::vector<osg::ref_ptr<GraphicsWindow> > WindowVector;
66
72class GraphicsContextOperation : public osg::GraphicsOperation
73{
74public:
75 GraphicsContextOperation(const std::string& name) :
76 osg::GraphicsOperation(name, false)
77 {
78 }
79
81 virtual void operator()(osg::GraphicsContext* gc);
84 virtual void run(osg::GraphicsContext* gc) = 0;
88 bool isFinished() const { return done != 0; }
89private:
90 SGAtomic done;
91};
92
98class WindowSystemAdapter : public osg::Referenced
99{
100public:
111 GraphicsWindow* registerWindow(osg::GraphicsContext* gc,
112 const std::string& windowName);
113
118 GraphicsWindow* findWindow(const std::string& name) const;
126 static WindowSystemAdapter* getWSA() { return _wsa.get(); }
130 static void setWSA(WindowSystemAdapter* wsa) { _wsa = wsa; }
131protected:
133 static osg::ref_ptr<WindowSystemAdapter> _wsa;
134
135};
136
137}
138#endif
GraphicsContextOperation(const std::string &name)
virtual void operator()(osg::GraphicsContext *gc)
Don't override this!
virtual void run(osg::GraphicsContext *gc)=0
The body of the operation.
bool isFinished() const
Test if the operation has completed.
A window with a graphics context and an integer ID.
int id
A unique ID for the window.
unsigned flags
Flags for the window.
GraphicsWindow(osg::GraphicsContext *gc_, const std::string &name_, int id_, unsigned flags_=0)
osg::ref_ptr< osg::GraphicsContext > gc
The OSG graphics context for this window.
std::string name
The window's internal name.
@ GUI
The GUI (and 2D cockpit) will be drawn on this window.
static void setWSA(WindowSystemAdapter *wsa)
Set the global adapter.
GraphicsWindow * getGUIWindow() const
Get the first window marked as GUI (there should only be one).
GraphicsWindow * findWindow(const std::string &name) const
Find a window by name.
WindowVector windows
Vector of all the registered windows.
static WindowSystemAdapter * getWSA()
Get the global WindowSystemAdapter.
GraphicsWindow * registerWindow(osg::GraphicsContext *gc, const std::string &windowName)
Register a window, assigning it an ID.
static osg::ref_ptr< WindowSystemAdapter > _wsa
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
std::vector< osg::ref_ptr< GraphicsWindow > > WindowVector
const char * name
Definition AIBase.hxx:25