]> git.mxchange.org Git - flightgear.git/blob - src/Main/WindowSystemAdapter.cxx
Merge commit 'refs/merge-requests/1552' of git@gitorious.org:fg/flightgear into next
[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 "CameraGroup.hxx"
26 #include "WindowSystemAdapter.hxx"
27
28 #include <osg/Camera>
29 #include <osg/GraphicsContext>
30 #include <osg/Viewport>
31
32 using namespace osg;
33 using namespace std;
34
35 namespace flightgear
36 {
37 ref_ptr<WindowSystemAdapter> WindowSystemAdapter::_wsa;
38
39 void GraphicsContextOperation::operator()(GraphicsContext* gc)
40 {
41     run(gc);
42     ++done;
43 }
44
45 WindowSystemAdapter::WindowSystemAdapter() :
46     _nextWindowID(0), _isPuInitialized(false)
47 {
48 }
49
50 GraphicsWindow*
51 WindowSystemAdapter::registerWindow(GraphicsContext* gc,
52                                     const string& windowName)
53 {
54     GraphicsWindow* window = new GraphicsWindow(gc, windowName,
55                                                 _nextWindowID++);
56     windows.push_back(window);
57     return window;
58 }
59
60 // The pu getWindow callback is supposed to return a window ID that
61 // would allow drawing a GUI on different windows. All that stuff is
62 // broken in multi-threaded OSG, and we only have one GUI "window"
63 // anyway, so just return a constant. 
64 int WindowSystemAdapter::puGetWindow()
65 {
66     return 1;
67 }
68
69 void WindowSystemAdapter::puGetWindowSize(int* width, int* height)
70 {
71     *width = 0;
72     *height = 0;
73     Camera* camera = getGUICamera(CameraGroup::getDefault());
74     if (!camera)
75         return;
76     Viewport* vport = camera->getViewport();
77     *width = (int)vport->width();
78     *height = (int)vport->height();
79 }
80
81 void WindowSystemAdapter::puInitialize()
82 {
83     puSetWindowFuncs(puGetWindow, 0, puGetWindowSize, 0);
84     puRealInit();
85 }
86
87 GraphicsWindow* WindowSystemAdapter::findWindow(const string& name)
88 {
89     for (WindowVector::iterator iter = windows.begin(), e = windows.end();
90          iter != e;
91          ++iter) {
92         if ((*iter)->name == name)
93             return iter->get();
94     }
95     return 0;
96 }
97 }