1 // Copyright (C) 2008 Tim Moore
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.
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.
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.
25 #include "WindowSystemAdapter.hxx"
30 using namespace flightgear;
32 ref_ptr<WindowSystemAdapter> WindowSystemAdapter::_wsa;
34 void GraphicsContextOperation::operator()(GraphicsContext* gc)
40 WindowSystemAdapter::WindowSystemAdapter() :
41 _nextWindowID(0), _nextCameraID(0), _isPuInitialized(false)
46 WindowSystemAdapter::registerWindow(GraphicsContext* gc,
47 const string& windowName)
49 GraphicsWindow* window = new GraphicsWindow(gc, windowName,
51 windows.push_back(window);
56 WindowSystemAdapter::registerCamera3D(GraphicsWindow* gw, Camera* camera,
57 const string& cameraName)
59 Camera3D* camera3D = new Camera3D(gw, camera, cameraName);
60 cameras.push_back(camera3D);
65 WindowSystemAdapter::getGUIWindow()
67 WindowVector::const_iterator contextIter
68 = std::find_if(windows.begin(), windows.end(),
69 FlagTester<GraphicsWindow>(GraphicsWindow::GUI));
70 if (contextIter == windows.end())
73 return contextIter->get();
77 WindowSystemAdapter::getGUIWindowID()
79 const GraphicsWindow* gw = getGUIWindow();
87 WindowSystemAdapter::getGUIGraphicsContext()
89 GraphicsWindow* gw = getGUIWindow();
97 int WindowSystemAdapter::puGetWindow()
99 WindowSystemAdapter* wsa = getWSA();
100 return wsa->getGUIWindowID();
103 void WindowSystemAdapter::puGetWindowSize(int* width, int* height)
105 // XXX This will have to be different when multiple cameras share
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;
114 bool WindowSystemAdapter::puInitialize()
116 puSetWindowFuncs(puGetWindow, 0, puGetWindowSize, 0);