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 "CameraGroup.hxx"
26 #include "WindowSystemAdapter.hxx"
29 #include <osg/GraphicsContext>
30 #include <osg/Viewport>
37 ref_ptr<WindowSystemAdapter> WindowSystemAdapter::_wsa;
39 void GraphicsContextOperation::operator()(GraphicsContext* gc)
45 WindowSystemAdapter::WindowSystemAdapter() :
46 _nextWindowID(0), _isPuInitialized(false)
51 WindowSystemAdapter::registerWindow(GraphicsContext* gc,
52 const string& windowName)
54 GraphicsWindow* window = new GraphicsWindow(gc, windowName,
56 windows.push_back(window);
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()
69 void WindowSystemAdapter::puGetWindowSize(int* width, int* height)
73 Camera* camera = getGUICamera(CameraGroup::getDefault());
76 Viewport* vport = camera->getViewport();
77 *width = (int)vport->width();
78 *height = (int)vport->height();
81 void WindowSystemAdapter::puInitialize()
83 puSetWindowFuncs(puGetWindow, 0, puGetWindowSize, 0);
87 GraphicsWindow* WindowSystemAdapter::findWindow(const string& name)
89 for (WindowVector::iterator iter = windows.begin(), e = windows.end();
92 if ((*iter)->name == name)