1 #include "FGCanvasSystemAdapter.hxx"
3 #include <Main/globals.hxx>
4 #include <Scripting/NasalSys.hxx>
5 #include <Viewer/renderer.hxx>
7 #include <osgDB/ReadFile>
12 //----------------------------------------------------------------------------
13 simgear::canvas::FontPtr
14 FGCanvasSystemAdapter::getFont(const std::string& name) const
16 SGPath path = globals->resolve_resource_path("Fonts/" + name);
23 "canvas::Text: No such font: " << name
25 return simgear::canvas::FontPtr();
32 "canvas::Text: using font file " << path.str()
35 simgear::canvas::FontPtr font = osgText::readFontFile(path.c_str());
41 "canvas::Text: Failed to open font file " << path.c_str()
47 //----------------------------------------------------------------------------
48 void FGCanvasSystemAdapter::addCamera(osg::Camera* camera) const
50 globals->get_renderer()->addCamera(camera, false);
53 //----------------------------------------------------------------------------
54 void FGCanvasSystemAdapter::removeCamera(osg::Camera* camera) const
56 globals->get_renderer()->removeCamera(camera);
59 //----------------------------------------------------------------------------
60 osg::Image* FGCanvasSystemAdapter::getImage(const std::string& path) const
62 SGPath tpath = globals->resolve_resource_path(path);
63 if( tpath.isNull() || !tpath.exists() )
65 SG_LOG(SG_GL, SG_ALERT, "canvas::Image: No such image: " << path);
69 return osgDB::readImageFile(tpath.c_str());
73 * Get current FGNasalSys instance.
75 static FGNasalSys* getNasalSys()
77 static FGNasalSys* nasal_sys = 0;
78 // TODO if Nasal is able to be removed and/or recreated at runtime we need
79 // to ensure that always the current instance is used
82 nasal_sys = dynamic_cast<FGNasalSys*>(globals->get_subsystem("nasal"));
84 throw std::runtime_error("FGCanvasSystemAdapter: no NasalSys");
90 //----------------------------------------------------------------------------
91 naContext FGCanvasSystemAdapter::getNasalContext() const
93 return getNasalSys()->context();
96 //----------------------------------------------------------------------------
97 int FGCanvasSystemAdapter::gcSave(naRef r)
99 return getNasalSys()->gcSave(r);
102 //----------------------------------------------------------------------------
103 void FGCanvasSystemAdapter::gcRelease(int key)
105 getNasalSys()->gcRelease(key);
108 //------------------------------------------------------------------------------
109 naRef FGCanvasSystemAdapter::callMethod( naRef code,
115 return getNasalSys()->callMethod(code, self, argc, args, locals);