]> git.mxchange.org Git - flightgear.git/blob - src/Main/WindowSystemAdapter.cxx
Clean up OSG camera setup and interface to plib PUI
[flightgear.git] / src / Main / WindowSystemAdapter.cxx
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 #ifdef HAVE_CONFIG_H
17 #  include <config.h>
18 #endif
19
20 #include <plib/pu.h>
21
22 #include<algorithm>
23 #include <functional>
24
25 #include "WindowSystemAdapter.hxx"
26
27 using namespace osg;
28 using namespace std;
29
30 using namespace flightgear;
31
32 ref_ptr<WindowSystemAdapter> WindowSystemAdapter::_wsa;
33
34 void GraphicsContextOperation::operator()(GraphicsContext* gc)
35 {
36     run(gc);
37     ++done;
38 }
39
40 WindowSystemAdapter::WindowSystemAdapter() :
41     _nextWindowID(0), _nextCameraID(0), _isPuInitialized(false)
42 {
43 }
44
45 GraphicsWindow*
46 WindowSystemAdapter::registerWindow(GraphicsContext* gc,
47                                     const string& windowName)
48 {
49     GraphicsWindow* window = new GraphicsWindow(gc, windowName,
50                                                 _nextWindowID++);
51     windows.push_back(window);
52     return window;
53 }
54
55 Camera3D*
56 WindowSystemAdapter::registerCamera3D(GraphicsWindow* gw, Camera* camera,
57                                       const string& cameraName)
58 {
59     Camera3D* camera3D = new Camera3D(gw, camera, cameraName);
60     cameras.push_back(camera3D);
61     return camera3D;
62 }
63
64 GraphicsWindow*
65 WindowSystemAdapter::getGUIWindow()
66 {
67     WindowVector::const_iterator contextIter
68         = std::find_if(windows.begin(), windows.end(),
69                        FlagTester<GraphicsWindow>(GraphicsWindow::GUI));
70     if (contextIter == windows.end())
71         return 0;
72     else
73         return contextIter->get();
74 }
75
76 int
77 WindowSystemAdapter::getGUIWindowID()
78 {
79     const GraphicsWindow* gw = getGUIWindow();
80     if (!gw)
81         return -1;
82     else
83         return gw->id;
84 }
85
86 GraphicsContext*
87 WindowSystemAdapter::getGUIGraphicsContext()
88 {
89     GraphicsWindow* gw = getGUIWindow();
90     if (!gw)
91         return 0;
92     else
93         return gw->gc.get();
94 }
95
96
97 int WindowSystemAdapter::puGetWindow()
98 {
99     WindowSystemAdapter* wsa = getWSA();
100     return wsa->getGUIWindowID();
101 }
102
103 void WindowSystemAdapter::puGetWindowSize(int* width, int* height)
104 {
105     // XXX This will have to be different when multiple cameras share
106     // a single window.
107     WindowSystemAdapter* wsa = getWSA();
108     const GraphicsContext* gc = wsa->getGUIGraphicsContext();
109     const GraphicsContext::Traits *traits = gc->getTraits();
110     *width = traits->width;
111     *height = traits->height;
112 }
113
114 bool WindowSystemAdapter::puInitialize()
115 {
116     puSetWindowFuncs(puGetWindow, 0, puGetWindowSize, 0);
117     puRealInit();
118 }