]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/panel.cxx
Autopilot: use SimGear function
[flightgear.git] / src / Cockpit / panel.cxx
index 890b9a39dbb6961b54fed45fcb6bda2119d549a1..7c7dd810c690e1f21119b43f8657453db7046f5f 100644 (file)
 #  include <config.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
+#include "panel.hxx"
 
 #include <stdio.h>     // sprintf
 #include <string.h>
+#include <iostream>
 
 #include <osg/CullFace>
 #include <osg/Depth>
 #include <osg/Material>
+#include <osg/Matrixf>
 #include <osg/TexEnv>
 #include <osg/PolygonOffset>
 
 #include <simgear/compiler.h>
 
-#include SG_GLU_H
-
 #include <plib/fnt.h>
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/model/model.hxx>
+#include <osg/GLU>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Main/viewmgr.hxx>
 #include <Time/light.hxx>
 #include <GUI/new_gui.hxx>     // FGFontCache
-
-#include "hud.hxx"
-#include "panel.hxx"
+#include <Main/viewer.hxx>
+#include <Instrumentation/dclgps.hxx>
 
 #define WIN_X 0
 #define WIN_Y 0
@@ -98,18 +96,18 @@ get_aspect_adjust (int xsize, int ysize)
 bool
 fgPanelVisible ()
 {
-     if (globals->get_current_panel() == 0)
+     const FGPanel* current = globals->get_current_panel();
+     if (current == 0)
        return false;
-     if (globals->get_current_panel()->getVisibility() == 0)
+     if (current->getVisibility() == 0)
        return false;
      if (globals->get_viewmgr()->get_current() != 0)
        return false;
-     if (globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
+     if (current->getAutohide() && globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
        return false;
      return true;
 }
 
-
 \f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of FGTextureManager.
@@ -118,16 +116,12 @@ fgPanelVisible ()
 map<string,osg::ref_ptr<osg::Texture2D> > FGTextureManager::_textureMap;
 
 osg::Texture2D*
-FGTextureManager::createTexture (const string &relativePath)
+FGTextureManager::createTexture (const string &relativePath, bool staticTexture)
 {
   osg::Texture2D* texture = _textureMap[relativePath].get();
   if (texture == 0) {
-    SG_LOG( SG_COCKPIT, SG_DEBUG,
-            "Texture " << relativePath << " does not yet exist" );
-    SGPath tpath(globals->get_fg_root());
-    tpath.append(relativePath);
-
-    texture = SGLoadTexture2D(tpath);
+    SGPath tpath = globals->resolve_aircraft_path(relativePath);
+    texture = SGLoadTexture2D(staticTexture, tpath);
 
     _textureMap[relativePath] = texture;
     if (!_textureMap[relativePath].valid()) 
@@ -277,6 +271,7 @@ FGPanel::update (double dt)
 void
 FGPanel::update (osg::State& state, GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
 {
+  using namespace osg;
                                // Calculate accelerations
                                // and jiggle the panel accordingly
                                // The factors and bounds are just
@@ -288,12 +283,13 @@ FGPanel::update (osg::State& state, GLfloat winx, GLfloat winw, GLfloat winy, GL
 
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
-  glLoadIdentity();
+  Matrixf proj;
   if ( _flipx->getBoolValue() ) {
-    gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
+      proj = Matrixf::ortho2D(winx + winw, winx, winy + winh, winy); /* up side down */
   } else {
-    gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
+      proj = Matrixf::ortho2D(winx, winx + winw, winy, winy + winh); /* right side up */
   }
+  glLoadMatrix(proj.ptr());
   
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
@@ -918,7 +914,7 @@ FGSpecialInstrument::~FGSpecialInstrument ()
 void
 FGSpecialInstrument::draw (osg::State& state)
 {
-  complex->draw();
+  complex->draw(state);
 }
 
 
@@ -1109,14 +1105,19 @@ FGTextLayer::draw (osg::State& state)
     transform();
 
     FGFontCache *fc = globals->get_fontcache();
-    text_renderer.setFont(fc->getTexFont(_font_name.c_str()));
+    fntFont* font = fc->getTexFont(_font_name.c_str());
+    if (!font) {
+        return; // don't crash on missing fonts
+    }
+    
+    text_renderer.setFont(font);
 
     text_renderer.setPointSize(_pointSize);
     text_renderer.begin();
     text_renderer.start3f(0, 0, 0);
 
     _now.stamp();
-    long diff = _now - _then;
+    double diff = (_now - _then).toUSecs();
 
     if (diff > 100000 || diff < 0 ) {
       // ( diff < 0 ) is a sanity check and indicates our time stamp
@@ -1170,6 +1171,11 @@ void
 FGTextLayer::setFontName(const string &name)
 {
   _font_name = name + ".txf";
+  FGFontCache *fc = globals->get_fontcache();
+  fntFont* font = fc->getTexFont(_font_name.c_str());
+  if (!font) {
+      SG_LOG(SG_GENERAL, SG_WARN, "unable to find font:" << name);
+  }
 }