2008-05-19 21:21:03 +00:00
|
|
|
// Copyright (C) 2008 Tim Moore
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <plib/pu.h>
|
|
|
|
|
|
|
|
#include<algorithm>
|
|
|
|
#include <functional>
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
#include "CameraGroup.hxx"
|
2008-05-19 21:21:03 +00:00
|
|
|
#include "WindowSystemAdapter.hxx"
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
#include <osg/Camera>
|
|
|
|
#include <osg/GraphicsContext>
|
|
|
|
#include <osg/Viewport>
|
|
|
|
|
2008-05-19 21:21:03 +00:00
|
|
|
using namespace osg;
|
|
|
|
using namespace std;
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
namespace flightgear
|
|
|
|
{
|
2008-05-19 21:21:03 +00:00
|
|
|
ref_ptr<WindowSystemAdapter> WindowSystemAdapter::_wsa;
|
|
|
|
|
|
|
|
void GraphicsContextOperation::operator()(GraphicsContext* gc)
|
|
|
|
{
|
|
|
|
run(gc);
|
|
|
|
++done;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowSystemAdapter::WindowSystemAdapter() :
|
2008-08-01 15:57:29 +00:00
|
|
|
_nextWindowID(0), _isPuInitialized(false)
|
2008-05-19 21:21:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsWindow*
|
|
|
|
WindowSystemAdapter::registerWindow(GraphicsContext* gc,
|
|
|
|
const string& windowName)
|
|
|
|
{
|
|
|
|
GraphicsWindow* window = new GraphicsWindow(gc, windowName,
|
|
|
|
_nextWindowID++);
|
|
|
|
windows.push_back(window);
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2008-08-01 15:57:29 +00:00
|
|
|
// The pu getWindow callback is supposed to return a window ID that
|
|
|
|
// would allow drawing a GUI on different windows. All that stuff is
|
|
|
|
// broken in multi-threaded OSG, and we only have one GUI "window"
|
|
|
|
// anyway, so just return a constant.
|
2008-05-19 21:21:03 +00:00
|
|
|
int WindowSystemAdapter::puGetWindow()
|
|
|
|
{
|
2008-08-01 15:57:29 +00:00
|
|
|
return 1;
|
2008-05-19 21:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowSystemAdapter::puGetWindowSize(int* width, int* height)
|
|
|
|
{
|
2008-08-01 15:57:29 +00:00
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
Camera* camera = getGUICamera(CameraGroup::getDefault());
|
|
|
|
if (!camera)
|
|
|
|
return;
|
|
|
|
Viewport* vport = camera->getViewport();
|
|
|
|
*width = (int)vport->width();
|
|
|
|
*height = (int)vport->height();
|
2008-05-19 21:21:03 +00:00
|
|
|
}
|
|
|
|
|
2008-05-20 06:35:37 +00:00
|
|
|
void WindowSystemAdapter::puInitialize()
|
2008-05-19 21:21:03 +00:00
|
|
|
{
|
|
|
|
puSetWindowFuncs(puGetWindow, 0, puGetWindowSize, 0);
|
|
|
|
puRealInit();
|
|
|
|
}
|
2008-08-01 15:57:29 +00:00
|
|
|
|
|
|
|
GraphicsWindow* WindowSystemAdapter::findWindow(const string& name)
|
|
|
|
{
|
|
|
|
for (WindowVector::iterator iter = windows.begin(), e = windows.end();
|
|
|
|
iter != e;
|
|
|
|
++iter) {
|
|
|
|
if ((*iter)->name == name)
|
|
|
|
return iter->get();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|