]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/panel.cxx
Attempt to merge LED font patches back in (they were wiped out by
[flightgear.git] / src / Cockpit / panel.cxx
index 9a8a65862ba334f8979aab14d5543aeebca596aa..23f8e4b28c488bd3c4b0a4c58f764f55716d48e1 100644 (file)
@@ -26,6 +26,7 @@
 #  include <windows.h>
 #endif
 
+#include <stdio.h>     // sprintf
 #include <string.h>
 
 #include <plib/ssg.h>
@@ -163,7 +164,8 @@ FGCroppedTexture::getTexture ()
 
 FGPanel * current_panel = NULL;
 static fntRenderer text_renderer;
-
+static fntTexFont *default_font;
+static fntTexFont *led_font;
 
 /**
  * Constructor.
@@ -214,7 +216,28 @@ FGPanel::addInstrument (FGPanelInstrument * instrument)
 void
 FGPanel::init ()
 {
-  // NO-OP
+    SGPath base_path;
+    char* envp = ::getenv( "FG_FONTS" );
+    if ( envp != NULL ) {
+        base_path.set( envp );
+    } else {
+        base_path.set( globals->get_fg_root() );
+       base_path.append( "Fonts" );
+    }
+
+    SGPath fntpath;
+
+    // Install the default font
+    fntpath = base_path;
+    fntpath.append( "typewriter.txf" );
+    default_font = new fntTexFont ;
+    default_font -> load ( (char *)fntpath.c_str() ) ;
+
+    // Install the LED font
+    fntpath = base_path;
+    fntpath.append( "led.txf" );
+    led_font = new fntTexFont ;
+    led_font -> load ( (char *)fntpath.c_str() ) ;
 }
 
 
@@ -253,11 +276,12 @@ FGPanel::unbind ()
  * Update the panel.
  */
 void
-FGPanel::update ()
+FGPanel::update (int dt)
 {
                                // Do nothing if the panel isn't visible.
-    if (!fgPanelVisible())
+    if ( !fgPanelVisible() ) {
         return;
+    }
 
                                // If the mouse is down, do something
     if (_mouseDown) {
@@ -330,16 +354,40 @@ FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
   } else {
       glColor4f(0.7, 0.2, 0.2, 1.0);
   }
-  glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
-  // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-  // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-  glBegin(GL_POLYGON);
-  glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
-  glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
-  glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
-  glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
-  glEnd();
+  if (_bg != 0) {
+    glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
+    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+    glBegin(GL_POLYGON);
+    glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
+    glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
+    glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
+    glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
+    glEnd();
+  } else {
+    for (int i = 0; i < 4; i ++) {
+      // top row of textures...(1,3,5,7)
+      glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
+      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+      glBegin(GL_POLYGON);
+      glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
+      glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
+      glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + _height, 0);
+      glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + _height, 0);
+      glEnd();
+      // bottom row of textures...(2,4,6,8)
+      glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
+      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+      glBegin(GL_POLYGON);
+      glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y, 0);
+      glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y, 0);
+      glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
+      glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
+      glEnd();
+    }
+
+  }
 
                                // Draw the instruments.
   instrument_list_type::const_iterator current = _instruments.begin();
@@ -391,6 +439,15 @@ FGPanel::setBackground (ssgTexture * texture)
   _bg = texture;
 }
 
+/**
+ * Set the panel's multiple background textures.
+ */
+void
+FGPanel::setMultiBackground (ssgTexture * texture, int idx)
+{
+  _bg = 0;
+  _mbg[idx] = texture;
+}
 
 /**
  * Set the panel's x-offset.
@@ -519,6 +576,7 @@ FGPanelTransformation::FGPanelTransformation ()
 
 FGPanelTransformation::~FGPanelTransformation ()
 {
+  delete table;
 }
 
 
@@ -821,7 +879,7 @@ FGTexturedLayer::draw ()
 ////////////////////////////////////////////////////////////////////////
 
 FGTextLayer::FGTextLayer (int w, int h)
-  : FGInstrumentLayer(w, h), _pointSize(14.0)
+  : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
 {
   _then.stamp();
   _color[0] = _color[1] = _color[2] = 0.0;
@@ -844,7 +902,11 @@ FGTextLayer::draw ()
     glPushMatrix();
     glColor4fv(_color);
     transform();
-    text_renderer.setFont(guiFntHandle);
+    if ( _font_name == "led" ) {
+       text_renderer.setFont(led_font);
+    } else {
+       text_renderer.setFont(guiFntHandle);
+    }
     text_renderer.setPointSize(_pointSize);
     text_renderer.begin();
     text_renderer.start3f(0, 0, 0);
@@ -883,6 +945,13 @@ FGTextLayer::setPointSize (float size)
   _pointSize = size;
 }
 
+void
+FGTextLayer::setFontName(const string &name)
+{
+  _font_name = name;
+}
+
+
 void
 FGTextLayer::setFont(fntFont * font)
 {
@@ -983,3 +1052,5 @@ FGSwitchLayer::draw ()
 
 \f
 // end of panel.cxx
+
+