1 // panel.cxx - default, 2D single-engine prop instrument panel
3 // Written by David Megginson, started January 2000.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 // On 2D panels all instruments include light sources were in night displayed
23 // with a red mask (instrument light). It is not correct for light sources
24 // (bulbs). There is added new layer property "emissive" (boolean) (only for
26 // If a layer has to shine set it in the "instrument_def_file.xml" inside the
27 // <layer> tag by adding <emissive>true</emissive> tag. When omitted the default
28 // value is for backward compatibility set to false.
38 #include <stdio.h> // sprintf
41 #include <simgear/compiler.h>
48 #include <simgear/debug/logstream.hxx>
49 #include <simgear/misc/sg_path.hxx>
51 #include <Main/globals.hxx>
52 #include <Main/fg_props.hxx>
53 #include <Main/viewmgr.hxx>
54 #include <Time/light.hxx>
64 // The number of polygon-offset "units" to place between layers. In
65 // principle, one is supposed to be enough. In practice, I find that
66 // my hardware/driver requires many more.
69 ////////////////////////////////////////////////////////////////////////
71 ////////////////////////////////////////////////////////////////////////
75 * Calculate the aspect adjustment for the panel.
78 get_aspect_adjust (int xsize, int ysize)
80 float ideal_aspect = float(WIN_W) / float(WIN_H);
81 float real_aspect = float(xsize) / float(ysize);
82 return (real_aspect / ideal_aspect);
87 ////////////////////////////////////////////////////////////////////////
89 ////////////////////////////////////////////////////////////////////////
94 if(globals->get_current_panel() == 0)
96 if(globals->get_current_panel()->getVisibility() == 0)
98 if(globals->get_viewmgr()->get_current() != 0)
100 if(globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
107 ////////////////////////////////////////////////////////////////////////
108 // Implementation of FGTextureManager.
109 ////////////////////////////////////////////////////////////////////////
111 map<string,ssgTexture *> FGTextureManager::_textureMap;
114 FGTextureManager::createTexture (const string &relativePath)
116 ssgTexture * texture = _textureMap[relativePath];
118 SG_LOG( SG_COCKPIT, SG_DEBUG,
119 "Texture " << relativePath << " does not yet exist" );
120 SGPath tpath(globals->get_fg_root());
121 tpath.append(relativePath);
122 texture = new ssgTexture((char *)tpath.c_str(), false, false);
123 _textureMap[relativePath] = texture;
124 if (_textureMap[relativePath] == 0)
125 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
126 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
127 << " handle=" << texture->getHandle() );
136 ////////////////////////////////////////////////////////////////////////
137 // Implementation of FGCropped Texture.
138 ////////////////////////////////////////////////////////////////////////
141 FGCroppedTexture::FGCroppedTexture ()
142 : _path(""), _texture(0),
143 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
148 FGCroppedTexture::FGCroppedTexture (const string &path,
149 float minX, float minY,
150 float maxX, float maxY)
151 : _path(path), _texture(0),
152 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
157 FGCroppedTexture::~FGCroppedTexture ()
163 FGCroppedTexture::getTexture ()
166 _texture = FGTextureManager::createTexture(_path);
173 ////////////////////////////////////////////////////////////////////////
174 // Implementation of FGPanel.
175 ////////////////////////////////////////////////////////////////////////
177 static fntRenderer text_renderer;
178 static fntTexFont *default_font = 0;
179 static fntTexFont *led_font = 0;
180 static sgVec4 panel_color;
181 static sgVec4 emissive_panel_color = {1,1,1,1};
189 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
190 _view_height(int(WIN_H * 0.4232)),
191 _visibility(fgGetNode("/sim/panel/visibility", true)),
192 _x_offset(fgGetNode("/sim/panel/x-offset", true)),
193 _y_offset(fgGetNode("/sim/panel/y-offset", true)),
194 _jitter(fgGetNode("/sim/panel/jitter", true)),
195 _flipx(fgGetNode("/sim/panel/flip-x", true)),
196 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
197 _ysize_node(fgGetNode("/sim/startup/ysize", true)),
198 _enable_depth_test(false)
208 for (instrument_list_type::iterator it = _instruments.begin();
209 it != _instruments.end();
218 * Add an instrument to the panel.
221 FGPanel::addInstrument (FGPanelInstrument * instrument)
223 _instruments.push_back(instrument);
228 * Initialize the panel.
234 char* envp = ::getenv( "FG_FONTS" );
235 if ( envp != NULL ) {
236 base_path.set( envp );
238 base_path.set( globals->get_fg_root() );
239 base_path.append( "Fonts" );
244 // Install the default font
246 fntpath.append( "typewriter.txf" );
247 default_font = new fntTexFont ;
248 default_font -> load ( (char *)fntpath.c_str() ) ;
250 // Install the LED font
252 fntpath.append( "led.txf" );
253 led_font = new fntTexFont ;
254 led_font -> load ( (char *)fntpath.c_str() ) ;
259 * Bind panel properties.
264 fgSetArchivable("/sim/panel/visibility");
265 fgSetArchivable("/sim/panel/x-offset");
266 fgSetArchivable("/sim/panel/y-offset");
267 fgSetArchivable("/sim/panel/jitter");
272 * Unbind panel properties.
284 FGPanel::update (double dt)
286 // Do nothing if the panel isn't visible.
287 if ( !fgPanelVisible() ) {
293 // Now, draw the panel
294 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
295 _ysize_node->getIntValue());
296 if (aspect_adjust <1.0)
297 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
299 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
303 * Handle repeatable mouse events. Called from update() and from
304 * fgUpdate3DPanels(). This functionality needs to move into the
305 * input subsystem. Counting a tick every two frames is clumsy...
307 void FGPanel::updateMouseDelay()
311 if (_mouseDelay < 0) {
312 _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
320 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
322 // Calculate accelerations
323 // and jiggle the panel accordingly
324 // The factors and bounds are just
325 // initial guesses; using sqrt smooths
327 double x_offset = _x_offset->getIntValue();
328 double y_offset = _y_offset->getIntValue();
331 if (_jitter->getFloatValue() != 0.0) {
332 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
333 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
334 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
336 double a_zx_pilot = a_z_pilot - a_x_pilot;
338 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter->getFloatValue())) *
339 (a_y_pilot < 0 ? -1 : 1);
340 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter->getFloatValue())) *
341 (a_zx_pilot < 0 ? -1 : 1);
343 // adjustments in screen coordinates
344 x_offset += x_adjust;
345 y_offset += y_adjust;
349 glMatrixMode(GL_PROJECTION);
352 if ( _flipx->getBoolValue() ) {
353 gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
355 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
358 glMatrixMode(GL_MODELVIEW);
362 glTranslated(x_offset, y_offset, 0);
366 glMatrixMode(GL_PROJECTION);
368 glMatrixMode(GL_MODELVIEW);
371 ssgForceBasicState();
372 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
378 // In 3D mode, it's possible that we are being drawn exactly on top
379 // of an existing polygon. Use an offset to prevent z-fighting. In
380 // 2D mode, this is a no-op.
381 glEnable(GL_POLYGON_OFFSET_FILL);
382 glPolygonOffset(-1, -POFF_UNITS);
385 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT
386 | GL_TEXTURE_BIT | GL_PIXEL_MODE_BIT | GL_CULL_FACE
387 | GL_DEPTH_BUFFER_BIT );
389 // Draw the background
390 glEnable(GL_TEXTURE_2D);
391 glDisable(GL_LIGHTING);
393 glEnable(GL_ALPHA_TEST);
394 glEnable(GL_COLOR_MATERIAL);
395 glEnable(GL_CULL_FACE);
397 if( _enable_depth_test )
398 glDepthFunc(GL_ALWAYS);
400 glDisable(GL_DEPTH_TEST);
402 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
403 sgCopyVec4( panel_color, l->scene_diffuse());
404 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
405 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
406 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
407 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
409 glColor4fv( panel_color );
411 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
412 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
413 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
414 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
416 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
417 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
418 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
419 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
422 for (int i = 0; i < 4; i ++) {
423 // top row of textures...(1,3,5,7)
424 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
425 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
427 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
428 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
429 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
430 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
432 // bottom row of textures...(2,4,6,8)
433 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
434 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
436 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
437 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
438 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
439 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
444 // Draw the instruments.
445 instrument_list_type::const_iterator current = _instruments.begin();
446 instrument_list_type::const_iterator end = _instruments.end();
448 for ( ; current != end; current++) {
449 FGPanelInstrument * instr = *current;
451 glTranslated(instr->getXPos(), instr->getYPos(), 0);
456 // Draw yellow "hotspots" if directed to. This is a panel authoring
457 // feature; not intended to be high performance or to look good.
458 if ( fgGetBool("/sim/panel-hotspots") ) {
459 glDisable(GL_TEXTURE_2D);
462 for ( unsigned int i = 0; i < _instruments.size(); i++ )
463 _instruments[i]->drawHotspots();
467 // restore some original state
468 if( _enable_depth_test )
469 glDepthFunc(GL_LESS);
471 glPolygonOffset(0, 0);
472 glDisable(GL_POLYGON_OFFSET_FILL);
476 * Set the panel's visibility.
479 FGPanel::setVisibility (bool visibility)
481 _visibility->setBoolValue( visibility );
486 * Return true if the panel is visible.
489 FGPanel::getVisibility () const
491 return _visibility->getBoolValue();
496 * Set the panel's background texture.
499 FGPanel::setBackground (ssgTexture * texture)
505 * Set the panel's multiple background textures.
508 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
515 * Set the panel's x-offset.
518 FGPanel::setXOffset (int offset)
520 if (offset <= 0 && offset >= -_width + WIN_W)
521 _x_offset->setIntValue( offset );
526 * Set the panel's y-offset.
529 FGPanel::setYOffset (int offset)
531 if (offset <= 0 && offset >= -_height)
532 _y_offset->setIntValue( offset );
536 * Handle a mouse action in panel-local (not screen) coordinates.
537 * Used by the 3D panel code in Model/panelnode.cxx, in situations
538 * where the panel doesn't control its own screen location.
541 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
543 // Note a released button and return
545 if (_mouseInstrument != 0)
546 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
548 _mouseInstrument = 0;
552 // Search for a matching instrument.
553 for (int i = 0; i < (int)_instruments.size(); i++) {
554 FGPanelInstrument *inst = _instruments[i];
555 int ix = inst->getXPos();
556 int iy = inst->getYPos();
557 int iw = inst->getWidth() / 2;
558 int ih = inst->getHeight() / 2;
559 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
562 _mouseInstrument = inst;
563 _mouseButton = button;
566 // Always do the action once.
567 return _mouseInstrument->doMouseAction(_mouseButton, 0,
575 * Perform a mouse action.
578 FGPanel::doMouseAction (int button, int updown, int x, int y)
580 // FIXME: this same code appears in update()
581 int xsize = _xsize_node->getIntValue();
582 int ysize = _ysize_node->getIntValue();
583 float aspect_adjust = get_aspect_adjust(xsize, ysize);
585 // Scale for the real window size.
586 if (aspect_adjust < 1.0) {
587 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
588 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
590 x = int(((float)x / xsize) * WIN_W);
591 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
594 // Adjust for offsets.
595 x -= _x_offset->getIntValue();
596 y -= _y_offset->getIntValue();
598 // Having fixed up the coordinates, fall through to the local
599 // coordinate handler.
600 return doLocalMouseAction(button, updown, x, y);
603 void FGPanel::setDepthTest (bool enable) {
604 _enable_depth_test = enable;
609 ////////////////////////////////////////////////////////////////////////.
610 // Implementation of FGPanelAction.
611 ////////////////////////////////////////////////////////////////////////
613 FGPanelAction::FGPanelAction ()
617 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
619 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
623 FGPanelAction::~FGPanelAction ()
625 for (unsigned int i = 0; i < 2; i++) {
626 for (unsigned int j = 0; j < _bindings[i].size(); j++)
627 delete _bindings[i][j];
632 FGPanelAction::addBinding (FGBinding * binding, int updown)
634 _bindings[updown].push_back(binding);
638 FGPanelAction::doAction (int updown)
641 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
642 int nBindings = _bindings[updown].size();
643 for (int i = 0; i < nBindings; i++)
644 _bindings[updown][i]->fire();
646 _last_state = updown;
655 ////////////////////////////////////////////////////////////////////////
656 // Implementation of FGPanelTransformation.
657 ////////////////////////////////////////////////////////////////////////
659 FGPanelTransformation::FGPanelTransformation ()
664 FGPanelTransformation::~FGPanelTransformation ()
671 ////////////////////////////////////////////////////////////////////////
672 // Implementation of FGPanelInstrument.
673 ////////////////////////////////////////////////////////////////////////
676 FGPanelInstrument::FGPanelInstrument ()
682 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
688 FGPanelInstrument::~FGPanelInstrument ()
690 for (action_list_type::iterator it = _actions.begin();
691 it != _actions.end();
699 FGPanelInstrument::drawHotspots()
701 for ( unsigned int i = 0; i < _actions.size(); i++ ) {
702 FGPanelAction* a = _actions[i];
703 float x1 = getXPos() + a->getX();
704 float x2 = x1 + a->getWidth();
705 float y1 = getYPos() + a->getY();
706 float y2 = y1 + a->getHeight();
708 glBegin(GL_LINE_LOOP);
718 FGPanelInstrument::setPosition (int x, int y)
725 FGPanelInstrument::setSize (int w, int h)
732 FGPanelInstrument::getXPos () const
738 FGPanelInstrument::getYPos () const
744 FGPanelInstrument::getWidth () const
750 FGPanelInstrument::getHeight () const
756 FGPanelInstrument::addAction (FGPanelAction * action)
758 _actions.push_back(action);
761 // Coordinates relative to centre.
763 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
766 action_list_type::iterator it = _actions.begin();
767 action_list_type::iterator last = _actions.end();
768 for ( ; it != last; it++) {
769 if ((*it)->inArea(button, x, y) &&
770 (*it)->doAction(updown))
779 ////////////////////////////////////////////////////////////////////////
780 // Implementation of FGLayeredInstrument.
781 ////////////////////////////////////////////////////////////////////////
783 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
784 : FGPanelInstrument(x, y, w, h)
788 FGLayeredInstrument::~FGLayeredInstrument ()
790 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
797 FGLayeredInstrument::draw ()
802 for (int i = 0; i < (int)_layers.size(); i++) {
810 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
812 int n = _layers.size();
813 if (layer->getWidth() == -1) {
814 layer->setWidth(getWidth());
816 if (layer->getHeight() == -1) {
817 layer->setHeight(getHeight());
819 _layers.push_back(layer);
824 FGLayeredInstrument::addLayer (const FGCroppedTexture &texture,
827 return addLayer(new FGTexturedLayer(texture, w, h));
831 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
833 int layer = _layers.size() - 1;
834 _layers[layer]->addTransformation(transformation);
839 ////////////////////////////////////////////////////////////////////////
840 // Implementation of FGSpecialInstrument.
841 ////////////////////////////////////////////////////////////////////////
843 FGSpecialInstrument::FGSpecialInstrument (DCLGPS* sb)
844 : FGPanelInstrument()
849 FGSpecialInstrument::~FGSpecialInstrument ()
854 FGSpecialInstrument::draw ()
861 ////////////////////////////////////////////////////////////////////////
862 // Implementation of FGInstrumentLayer.
863 ////////////////////////////////////////////////////////////////////////
865 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
871 FGInstrumentLayer::~FGInstrumentLayer ()
873 for (transformation_list::iterator it = _transformations.begin();
874 it != _transformations.end();
882 FGInstrumentLayer::transform () const
884 transformation_list::const_iterator it = _transformations.begin();
885 transformation_list::const_iterator last = _transformations.end();
887 FGPanelTransformation *t = *it;
889 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
892 val = fmod(val, t->mod);
895 } else if (val > t->max) {
900 val = val * t->factor + t->offset;
902 val = t->table->interpolate(val) * t->factor + t->offset;
906 case FGPanelTransformation::XSHIFT:
907 glTranslatef(val, 0.0, 0.0);
909 case FGPanelTransformation::YSHIFT:
910 glTranslatef(0.0, val, 0.0);
912 case FGPanelTransformation::ROTATION:
913 glRotatef(-val, 0.0, 0.0, 1.0);
922 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
924 _transformations.push_back(transformation);
929 ////////////////////////////////////////////////////////////////////////
930 // Implementation of FGGroupLayer.
931 ////////////////////////////////////////////////////////////////////////
933 FGGroupLayer::FGGroupLayer ()
937 FGGroupLayer::~FGGroupLayer ()
939 for (unsigned int i = 0; i < _layers.size(); i++)
944 FGGroupLayer::draw ()
948 int nLayers = _layers.size();
949 for (int i = 0; i < nLayers; i++)
955 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
957 _layers.push_back(layer);
962 ////////////////////////////////////////////////////////////////////////
963 // Implementation of FGTexturedLayer.
964 ////////////////////////////////////////////////////////////////////////
967 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
968 : FGInstrumentLayer(w, h),
975 FGTexturedLayer::~FGTexturedLayer ()
981 FGTexturedLayer::draw ()
988 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
992 glColor4fv( emissive_panel_color );
994 // From Curt: turn on the panel
995 // lights after sundown.
996 glColor4fv( panel_color );
999 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
1000 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
1001 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
1002 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
1009 ////////////////////////////////////////////////////////////////////////
1010 // Implementation of FGTextLayer.
1011 ////////////////////////////////////////////////////////////////////////
1013 FGTextLayer::FGTextLayer (int w, int h)
1014 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
1017 _color[0] = _color[1] = _color[2] = 0.0;
1021 FGTextLayer::~FGTextLayer ()
1023 chunk_list::iterator it = _chunks.begin();
1024 chunk_list::iterator last = _chunks.end();
1025 for ( ; it != last; it++) {
1031 FGTextLayer::draw ()
1036 if ( _font_name == "led" && led_font != 0) {
1037 text_renderer.setFont(led_font);
1039 text_renderer.setFont(guiFntHandle);
1041 text_renderer.setPointSize(_pointSize);
1042 text_renderer.begin();
1043 text_renderer.start3f(0, 0, 0);
1046 long diff = _now - _then;
1048 if (diff > 100000 || diff < 0 ) {
1049 // ( diff < 0 ) is a sanity check and indicates our time stamp
1050 // difference math probably overflowed. We can handle a max
1051 // difference of 35.8 minutes since the returned value is in
1052 // usec. So if the panel is left off longer than that we can
1053 // over flow the math with it is turned back on. This (diff <
1054 // 0) catches that situation, get's us out of trouble, and
1060 // Something is goofy. The code in this file renders only CCW
1061 // polygons, and I have verified that the font code in plib
1062 // renders only CCW trianbles. Yet they come out backwards.
1063 // Something around here or in plib is either changing the winding
1064 // order or (more likely) pushing a left-handed matrix onto the
1065 // stack. But I can't find it; get out the chainsaw...
1067 text_renderer.puts((char *)(_value.c_str()));
1068 glFrontFace(GL_CCW);
1070 text_renderer.end();
1071 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1076 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1078 _chunks.push_back(chunk);
1082 FGTextLayer::setColor (float r, float g, float b)
1091 FGTextLayer::setPointSize (float size)
1097 FGTextLayer::setFontName(const string &name)
1104 FGTextLayer::setFont(fntFont * font)
1106 text_renderer.setFont(font);
1111 FGTextLayer::recalc_value () const
1114 chunk_list::const_iterator it = _chunks.begin();
1115 chunk_list::const_iterator last = _chunks.end();
1116 for ( ; it != last; it++) {
1117 _value += (*it)->getValue();
1123 ////////////////////////////////////////////////////////////////////////
1124 // Implementation of FGTextLayer::Chunk.
1125 ////////////////////////////////////////////////////////////////////////
1127 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1128 : _type(FGTextLayer::TEXT), _fmt(fmt)
1135 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1136 const string &fmt, float mult, float offs,
1138 : _type(type), _fmt(fmt), _mult(mult), _offs(offs), _trunc(truncation)
1141 if (type == TEXT_VALUE)
1150 FGTextLayer::Chunk::getValue () const
1156 sprintf(_buf, _fmt.c_str(), _text.c_str());
1159 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1162 double d = _offs + _node->getFloatValue() * _mult;
1163 if (_trunc) d = (d < 0) ? -floor(-d) : floor(d);
1164 sprintf(_buf, _fmt.c_str(), d);
1175 ////////////////////////////////////////////////////////////////////////
1176 // Implementation of FGSwitchLayer.
1177 ////////////////////////////////////////////////////////////////////////
1179 FGSwitchLayer::FGSwitchLayer ()
1185 FGSwitchLayer::draw ()
1189 int nLayers = _layers.size();
1190 for (int i = 0; i < nLayers; i++) {
1191 if (_layers[i]->test()) {