]> git.mxchange.org Git - flightgear.git/blobdiff - src/Canvas/FGCanvasSystemAdapter.cxx
Fix stray back-button in Qt launcher
[flightgear.git] / src / Canvas / FGCanvasSystemAdapter.cxx
index c91c5d17caf754e2f6dfb46d4af6ed0e0a5beef6..894ca0bdc6b213d312ad196f3da9e0f89644a95f 100644 (file)
@@ -19,7 +19,8 @@
 #include "FGCanvasSystemAdapter.hxx"
 
 #include <Main/globals.hxx>
-#include <Scripting/NasalSys.hxx>
+#include <Main/util.hxx>
+#include <Network/HTTPClient.hxx>
 #include <Viewer/renderer.hxx>
 
 #include <osgDB/ReadFile>
@@ -71,66 +72,52 @@ namespace canvas
   //----------------------------------------------------------------------------
   void FGCanvasSystemAdapter::removeCamera(osg::Camera* camera) const
   {
-    globals->get_renderer()->removeCamera(camera);
+    if( globals->get_renderer() )
+      globals->get_renderer()->removeCamera(camera);
   }
 
   //----------------------------------------------------------------------------
-  osg::Image* FGCanvasSystemAdapter::getImage(const std::string& path) const
+  osg::ref_ptr<osg::Image> FGCanvasSystemAdapter::getImage(const std::string& path) const
   {
-    SGPath tpath = globals->resolve_resource_path(path);
-    if( tpath.isNull() || !tpath.exists() )
+    if( SGPath(path).isAbsolute() )
     {
-      SG_LOG(SG_GL, SG_ALERT, "canvas::Image: No such image: " << path);
-      return 0;
-    }
-
-    return osgDB::readImageFile(tpath.c_str());
-  }
+      std::string valid_path = fgValidatePath(path, false);
+      if( !valid_path.empty() )
+        return osgDB::readImageFile(valid_path.c_str());
 
-  /**
-   * Get current FGNasalSys instance.
-   */
-  static FGNasalSys* getNasalSys()
-  {
-    static FGNasalSys* nasal_sys = 0;
-    // TODO if Nasal is able to be removed and/or recreated at runtime we need
-    //      to ensure that always the current instance is used
-    if( !nasal_sys )
+      SG_LOG(SG_IO, SG_ALERT, "canvas::Image: reading '" << path << "' denied");
+    }
+    else
     {
-      nasal_sys = dynamic_cast<FGNasalSys*>(globals->get_subsystem("nasal"));
-      if( !nasal_sys )
-        throw std::runtime_error("FGCanvasSystemAdapter: no NasalSys");
+      SGPath tpath = globals->resolve_resource_path(path);
+      if( !tpath.isNull() )
+        return osgDB::readRefImageFile(tpath.c_str());
+
+      SG_LOG(SG_IO, SG_ALERT, "canvas::Image: No such image: '" << path << "'");
     }
 
-    return nasal_sys;
+    return 0;
   }
 
   //----------------------------------------------------------------------------
-  naContext FGCanvasSystemAdapter::getNasalContext() const
+  SGSubsystem*
+  FGCanvasSystemAdapter::getSubsystem(const std::string& name) const
   {
-    return getNasalSys()->context();
+    return globals->get_subsystem(name.c_str());
   }
 
   //----------------------------------------------------------------------------
-  int FGCanvasSystemAdapter::gcSave(naRef r)
+  simgear::HTTP::Client* FGCanvasSystemAdapter::getHTTPClient() const
   {
-    return getNasalSys()->gcSave(r);
-  }
+    FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
 
-  //----------------------------------------------------------------------------
-  void FGCanvasSystemAdapter::gcRelease(int key)
-  {
-    getNasalSys()->gcRelease(key);
-  }
+    if( http )
+      return http->client();
 
-  //------------------------------------------------------------------------------
-  naRef FGCanvasSystemAdapter::callMethod( naRef code,
-                                           naRef self,
-                                           int argc,
-                                           naRef* args,
-                                           naRef locals )
-  {
-    return getNasalSys()->callMethod(code, self, argc, args, locals);
+    SG_LOG( SG_IO,
+            SG_ALERT,
+            "FGCanvasSystemAdapter: Failed to get HTTP subsystem" );
+    return 0;
   }
 
 }