1 // Integrate Canvas into FlightGear
3 // Copyright (C) 2012 Thomas Geymayer <tomgey@gmail.com>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "FGCanvasSystemAdapter.hxx"
21 #include <Main/globals.hxx>
22 #include <Main/util.hxx>
23 #include <Network/HTTPClient.hxx>
24 #include <Viewer/renderer.hxx>
26 #include <osgDB/ReadFile>
31 //----------------------------------------------------------------------------
32 simgear::canvas::FontPtr
33 FGCanvasSystemAdapter::getFont(const std::string& name) const
35 SGPath path = globals->resolve_resource_path("Fonts/" + name);
42 "canvas::Text: No such font: " << name
44 return simgear::canvas::FontPtr();
51 "canvas::Text: using font file " << path.str()
54 simgear::canvas::FontPtr font = osgText::readFontFile(path.c_str());
60 "canvas::Text: Failed to open font file " << path.c_str()
66 //----------------------------------------------------------------------------
67 void FGCanvasSystemAdapter::addCamera(osg::Camera* camera) const
69 globals->get_renderer()->addCamera(camera, false);
72 //----------------------------------------------------------------------------
73 void FGCanvasSystemAdapter::removeCamera(osg::Camera* camera) const
75 if( globals->get_renderer() )
76 globals->get_renderer()->removeCamera(camera);
79 //----------------------------------------------------------------------------
80 osg::Image* FGCanvasSystemAdapter::getImage(const std::string& path) const
82 if( SGPath(path).isAbsolute() )
84 std::string valid_path = fgValidatePath(path, false);
85 if( !valid_path.empty() )
86 return osgDB::readImageFile(valid_path.c_str());
88 SG_LOG(SG_IO, SG_ALERT, "canvas::Image: reading '" << path << "' denied");
92 SGPath tpath = globals->resolve_resource_path(path);
94 return osgDB::readImageFile(tpath.c_str());
96 SG_LOG(SG_IO, SG_ALERT, "canvas::Image: No such image: '" << path << "'");
102 //----------------------------------------------------------------------------
104 FGCanvasSystemAdapter::getSubsystem(const std::string& name) const
106 return globals->get_subsystem(name.c_str());
109 //----------------------------------------------------------------------------
110 simgear::HTTP::Client* FGCanvasSystemAdapter::getHTTPClient() const
112 FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
115 return http->client();
119 "FGCanvasSystemAdapter: Failed to get HTTP subsystem" );