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.
29 #include <stdio.h> // sprintf
32 #include <simgear/compiler.h>
39 #include <simgear/debug/logstream.hxx>
40 #include <simgear/misc/sg_path.hxx>
42 #include <Main/globals.hxx>
43 #include <Main/fg_props.hxx>
44 #include <Main/viewmgr.hxx>
45 #include <Time/light.hxx>
55 // The number of polygon-offset "units" to place between layers. In
56 // principle, one is supposed to be enough. In practice, I find that
57 // my hardware/driver requires many more.
60 ////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////
66 * Calculate the aspect adjustment for the panel.
69 get_aspect_adjust (int xsize, int ysize)
71 float ideal_aspect = float(WIN_W) / float(WIN_H);
72 float real_aspect = float(xsize) / float(ysize);
73 return (real_aspect / ideal_aspect);
78 ////////////////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////////////////
85 if(globals->get_current_panel() == 0)
87 if(globals->get_current_panel()->getVisibility() == 0)
89 if(globals->get_viewmgr()->get_current() != 0)
91 if(globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
98 ////////////////////////////////////////////////////////////////////////
99 // Implementation of FGTextureManager.
100 ////////////////////////////////////////////////////////////////////////
102 map<string,ssgTexture *> FGTextureManager::_textureMap;
105 FGTextureManager::createTexture (const string &relativePath)
107 ssgTexture * texture = _textureMap[relativePath];
109 SG_LOG( SG_COCKPIT, SG_DEBUG,
110 "Texture " << relativePath << " does not yet exist" );
111 SGPath tpath(globals->get_fg_root());
112 tpath.append(relativePath);
113 texture = new ssgTexture((char *)tpath.c_str(), false, false);
114 _textureMap[relativePath] = texture;
115 if (_textureMap[relativePath] == 0)
116 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
117 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
118 << " handle=" << texture->getHandle() );
127 ////////////////////////////////////////////////////////////////////////
128 // Implementation of FGCropped Texture.
129 ////////////////////////////////////////////////////////////////////////
132 FGCroppedTexture::FGCroppedTexture ()
133 : _path(""), _texture(0),
134 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
139 FGCroppedTexture::FGCroppedTexture (const string &path,
140 float minX, float minY,
141 float maxX, float maxY)
142 : _path(path), _texture(0),
143 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
148 FGCroppedTexture::~FGCroppedTexture ()
154 FGCroppedTexture::getTexture ()
157 _texture = FGTextureManager::createTexture(_path);
164 ////////////////////////////////////////////////////////////////////////
165 // Implementation of FGPanel.
166 ////////////////////////////////////////////////////////////////////////
168 static fntRenderer text_renderer;
169 static fntTexFont *default_font = 0;
170 static fntTexFont *led_font = 0;
171 static sgVec4 panel_color;
179 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
180 _view_height(int(WIN_H * 0.4232)),
181 _visibility(fgGetNode("/sim/panel/visibility", true)),
182 _x_offset(fgGetNode("/sim/panel/x-offset", true)),
183 _y_offset(fgGetNode("/sim/panel/y-offset", true)),
184 _jitter(fgGetNode("/sim/panel/jitter", true)),
185 _flipx(fgGetNode("/sim/panel/flip-x", true)),
186 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
187 _ysize_node(fgGetNode("/sim/startup/ysize", true)),
188 _enable_depth_test(false)
198 for (instrument_list_type::iterator it = _instruments.begin();
199 it != _instruments.end();
208 * Add an instrument to the panel.
211 FGPanel::addInstrument (FGPanelInstrument * instrument)
213 _instruments.push_back(instrument);
218 * Initialize the panel.
224 char* envp = ::getenv( "FG_FONTS" );
225 if ( envp != NULL ) {
226 base_path.set( envp );
228 base_path.set( globals->get_fg_root() );
229 base_path.append( "Fonts" );
234 // Install the default font
236 fntpath.append( "typewriter.txf" );
237 default_font = new fntTexFont ;
238 default_font -> load ( (char *)fntpath.c_str() ) ;
240 // Install the LED font
242 fntpath.append( "led.txf" );
243 led_font = new fntTexFont ;
244 led_font -> load ( (char *)fntpath.c_str() ) ;
249 * Bind panel properties.
254 fgSetArchivable("/sim/panel/visibility");
255 fgSetArchivable("/sim/panel/x-offset");
256 fgSetArchivable("/sim/panel/y-offset");
257 fgSetArchivable("/sim/panel/jitter");
262 * Unbind panel properties.
274 FGPanel::update (double dt)
276 // Do nothing if the panel isn't visible.
277 if ( !fgPanelVisible() ) {
283 // Now, draw the panel
284 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
285 _ysize_node->getIntValue());
286 if (aspect_adjust <1.0)
287 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
289 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
293 * Handle repeatable mouse events. Called from update() and from
294 * fgUpdate3DPanels(). This functionality needs to move into the
295 * input subsystem. Counting a tick every two frames is clumsy...
297 void FGPanel::updateMouseDelay()
301 if (_mouseDelay < 0) {
302 _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
310 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
312 // Calculate accelerations
313 // and jiggle the panel accordingly
314 // The factors and bounds are just
315 // initial guesses; using sqrt smooths
317 double x_offset = _x_offset->getIntValue();
318 double y_offset = _y_offset->getIntValue();
321 if (_jitter->getFloatValue() != 0.0) {
322 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
323 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
324 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
326 double a_zx_pilot = a_z_pilot - a_x_pilot;
328 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter->getFloatValue())) *
329 (a_y_pilot < 0 ? -1 : 1);
330 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter->getFloatValue())) *
331 (a_zx_pilot < 0 ? -1 : 1);
333 // adjustments in screen coordinates
334 x_offset += x_adjust;
335 y_offset += y_adjust;
339 glMatrixMode(GL_PROJECTION);
342 if ( _flipx->getBoolValue() ) {
343 gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
345 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
348 glMatrixMode(GL_MODELVIEW);
352 glTranslated(x_offset, y_offset, 0);
356 glMatrixMode(GL_PROJECTION);
358 glMatrixMode(GL_MODELVIEW);
361 ssgForceBasicState();
362 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
368 // In 3D mode, it's possible that we are being drawn exactly on top
369 // of an existing polygon. Use an offset to prevent z-fighting. In
370 // 2D mode, this is a no-op.
371 glEnable(GL_POLYGON_OFFSET_FILL);
372 glPolygonOffset(-1, -POFF_UNITS);
375 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT
376 | GL_TEXTURE_BIT | GL_PIXEL_MODE_BIT | GL_CULL_FACE
377 | GL_DEPTH_BUFFER_BIT );
379 // Draw the background
380 glEnable(GL_TEXTURE_2D);
381 glDisable(GL_LIGHTING);
383 glEnable(GL_ALPHA_TEST);
384 glEnable(GL_COLOR_MATERIAL);
385 glEnable(GL_CULL_FACE);
387 if( _enable_depth_test )
388 glDepthFunc(GL_ALWAYS);
390 glDisable(GL_DEPTH_TEST);
392 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
393 sgCopyVec4( panel_color, l->scene_diffuse());
394 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
395 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
396 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
397 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
399 glColor4fv( panel_color );
401 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
402 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
403 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
404 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
406 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
407 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
408 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
409 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
412 for (int i = 0; i < 4; i ++) {
413 // top row of textures...(1,3,5,7)
414 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
415 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
417 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
418 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
419 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
420 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
422 // bottom row of textures...(2,4,6,8)
423 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
424 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
426 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
427 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
428 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
429 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
434 // Draw the instruments.
435 instrument_list_type::const_iterator current = _instruments.begin();
436 instrument_list_type::const_iterator end = _instruments.end();
438 for ( ; current != end; current++) {
439 FGPanelInstrument * instr = *current;
441 glTranslated(instr->getXPos(), instr->getYPos(), 0);
446 // Draw yellow "hotspots" if directed to. This is a panel authoring
447 // feature; not intended to be high performance or to look good.
448 if ( fgGetBool("/sim/panel-hotspots") ) {
449 glDisable(GL_TEXTURE_2D);
452 for ( unsigned int i = 0; i < _instruments.size(); i++ )
453 _instruments[i]->drawHotspots();
457 // restore some original state
458 if( _enable_depth_test )
459 glDepthFunc(GL_LESS);
461 glPolygonOffset(0, 0);
462 glDisable(GL_POLYGON_OFFSET_FILL);
466 * Set the panel's visibility.
469 FGPanel::setVisibility (bool visibility)
471 _visibility->setBoolValue( visibility );
476 * Return true if the panel is visible.
479 FGPanel::getVisibility () const
481 return _visibility->getBoolValue();
486 * Set the panel's background texture.
489 FGPanel::setBackground (ssgTexture * texture)
495 * Set the panel's multiple background textures.
498 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
505 * Set the panel's x-offset.
508 FGPanel::setXOffset (int offset)
510 if (offset <= 0 && offset >= -_width + WIN_W)
511 _x_offset->setIntValue( offset );
516 * Set the panel's y-offset.
519 FGPanel::setYOffset (int offset)
521 if (offset <= 0 && offset >= -_height)
522 _y_offset->setIntValue( offset );
526 * Handle a mouse action in panel-local (not screen) coordinates.
527 * Used by the 3D panel code in Model/panelnode.cxx, in situations
528 * where the panel doesn't control its own screen location.
531 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
533 // Note a released button and return
535 if (_mouseInstrument != 0)
536 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
538 _mouseInstrument = 0;
542 // Search for a matching instrument.
543 for (int i = 0; i < (int)_instruments.size(); i++) {
544 FGPanelInstrument *inst = _instruments[i];
545 int ix = inst->getXPos();
546 int iy = inst->getYPos();
547 int iw = inst->getWidth() / 2;
548 int ih = inst->getHeight() / 2;
549 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
552 _mouseInstrument = inst;
553 _mouseButton = button;
556 // Always do the action once.
557 return _mouseInstrument->doMouseAction(_mouseButton, 0,
565 * Perform a mouse action.
568 FGPanel::doMouseAction (int button, int updown, int x, int y)
570 // FIXME: this same code appears in update()
571 int xsize = _xsize_node->getIntValue();
572 int ysize = _ysize_node->getIntValue();
573 float aspect_adjust = get_aspect_adjust(xsize, ysize);
575 // Scale for the real window size.
576 if (aspect_adjust < 1.0) {
577 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
578 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
580 x = int(((float)x / xsize) * WIN_W);
581 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
584 // Adjust for offsets.
585 x -= _x_offset->getIntValue();
586 y -= _y_offset->getIntValue();
588 // Having fixed up the coordinates, fall through to the local
589 // coordinate handler.
590 return doLocalMouseAction(button, updown, x, y);
593 void FGPanel::setDepthTest (bool enable) {
594 _enable_depth_test = enable;
599 ////////////////////////////////////////////////////////////////////////.
600 // Implementation of FGPanelAction.
601 ////////////////////////////////////////////////////////////////////////
603 FGPanelAction::FGPanelAction ()
607 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
609 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
613 FGPanelAction::~FGPanelAction ()
615 for (unsigned int i = 0; i < 2; i++) {
616 for (unsigned int j = 0; j < _bindings[i].size(); j++)
617 delete _bindings[i][j];
622 FGPanelAction::addBinding (FGBinding * binding, int updown)
624 _bindings[updown].push_back(binding);
628 FGPanelAction::doAction (int updown)
631 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
632 int nBindings = _bindings[updown].size();
633 for (int i = 0; i < nBindings; i++)
634 _bindings[updown][i]->fire();
636 _last_state = updown;
645 ////////////////////////////////////////////////////////////////////////
646 // Implementation of FGPanelTransformation.
647 ////////////////////////////////////////////////////////////////////////
649 FGPanelTransformation::FGPanelTransformation ()
654 FGPanelTransformation::~FGPanelTransformation ()
661 ////////////////////////////////////////////////////////////////////////
662 // Implementation of FGPanelInstrument.
663 ////////////////////////////////////////////////////////////////////////
666 FGPanelInstrument::FGPanelInstrument ()
672 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
678 FGPanelInstrument::~FGPanelInstrument ()
680 for (action_list_type::iterator it = _actions.begin();
681 it != _actions.end();
689 FGPanelInstrument::drawHotspots()
691 for ( unsigned int i = 0; i < _actions.size(); i++ ) {
692 FGPanelAction* a = _actions[i];
693 float x1 = getXPos() + a->getX();
694 float x2 = x1 + a->getWidth();
695 float y1 = getYPos() + a->getY();
696 float y2 = y1 + a->getHeight();
698 glBegin(GL_LINE_LOOP);
708 FGPanelInstrument::setPosition (int x, int y)
715 FGPanelInstrument::setSize (int w, int h)
722 FGPanelInstrument::getXPos () const
728 FGPanelInstrument::getYPos () const
734 FGPanelInstrument::getWidth () const
740 FGPanelInstrument::getHeight () const
746 FGPanelInstrument::addAction (FGPanelAction * action)
748 _actions.push_back(action);
751 // Coordinates relative to centre.
753 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
756 action_list_type::iterator it = _actions.begin();
757 action_list_type::iterator last = _actions.end();
758 for ( ; it != last; it++) {
759 if ((*it)->inArea(button, x, y) &&
760 (*it)->doAction(updown))
769 ////////////////////////////////////////////////////////////////////////
770 // Implementation of FGLayeredInstrument.
771 ////////////////////////////////////////////////////////////////////////
773 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
774 : FGPanelInstrument(x, y, w, h)
778 FGLayeredInstrument::~FGLayeredInstrument ()
780 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
787 FGLayeredInstrument::draw ()
792 for (int i = 0; i < (int)_layers.size(); i++) {
800 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
802 int n = _layers.size();
803 if (layer->getWidth() == -1) {
804 layer->setWidth(getWidth());
806 if (layer->getHeight() == -1) {
807 layer->setHeight(getHeight());
809 _layers.push_back(layer);
814 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
817 return addLayer(new FGTexturedLayer(texture, w, h));
821 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
823 int layer = _layers.size() - 1;
824 _layers[layer]->addTransformation(transformation);
829 ////////////////////////////////////////////////////////////////////////
830 // Implementation of FGInstrumentLayer.
831 ////////////////////////////////////////////////////////////////////////
833 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
839 FGInstrumentLayer::~FGInstrumentLayer ()
841 for (transformation_list::iterator it = _transformations.begin();
842 it != _transformations.end();
850 FGInstrumentLayer::transform () const
852 transformation_list::const_iterator it = _transformations.begin();
853 transformation_list::const_iterator last = _transformations.end();
855 FGPanelTransformation *t = *it;
857 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
860 val = fmod(val, t->mod);
863 } else if (val > t->max) {
868 val = val * t->factor + t->offset;
870 val = t->table->interpolate(val) * t->factor + t->offset;
874 case FGPanelTransformation::XSHIFT:
875 glTranslatef(val, 0.0, 0.0);
877 case FGPanelTransformation::YSHIFT:
878 glTranslatef(0.0, val, 0.0);
880 case FGPanelTransformation::ROTATION:
881 glRotatef(-val, 0.0, 0.0, 1.0);
890 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
892 _transformations.push_back(transformation);
897 ////////////////////////////////////////////////////////////////////////
898 // Implementation of FGGroupLayer.
899 ////////////////////////////////////////////////////////////////////////
901 FGGroupLayer::FGGroupLayer ()
905 FGGroupLayer::~FGGroupLayer ()
907 for (unsigned int i = 0; i < _layers.size(); i++)
912 FGGroupLayer::draw ()
916 int nLayers = _layers.size();
917 for (int i = 0; i < nLayers; i++)
923 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
925 _layers.push_back(layer);
930 ////////////////////////////////////////////////////////////////////////
931 // Implementation of FGTexturedLayer.
932 ////////////////////////////////////////////////////////////////////////
935 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
936 : FGInstrumentLayer(w, h)
942 FGTexturedLayer::~FGTexturedLayer ()
948 FGTexturedLayer::draw ()
955 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
958 // From Curt: turn on the panel
959 // lights after sundown.
960 glColor4fv( panel_color );
962 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
963 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
964 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
965 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
972 ////////////////////////////////////////////////////////////////////////
973 // Implementation of FGTextLayer.
974 ////////////////////////////////////////////////////////////////////////
976 FGTextLayer::FGTextLayer (int w, int h)
977 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
980 _color[0] = _color[1] = _color[2] = 0.0;
984 FGTextLayer::~FGTextLayer ()
986 chunk_list::iterator it = _chunks.begin();
987 chunk_list::iterator last = _chunks.end();
988 for ( ; it != last; it++) {
999 if ( _font_name == "led" && led_font != 0) {
1000 text_renderer.setFont(led_font);
1002 text_renderer.setFont(guiFntHandle);
1004 text_renderer.setPointSize(_pointSize);
1005 text_renderer.begin();
1006 text_renderer.start3f(0, 0, 0);
1009 long diff = _now - _then;
1011 if (diff > 100000 || diff < 0 ) {
1012 // ( diff < 0 ) is a sanity check and indicates our time stamp
1013 // difference math probably overflowed. We can handle a max
1014 // difference of 35.8 minutes since the returned value is in
1015 // usec. So if the panel is left off longer than that we can
1016 // over flow the math with it is turned back on. This (diff <
1017 // 0) catches that situation, get's us out of trouble, and
1023 // Something is goofy. The code in this file renders only CCW
1024 // polygons, and I have verified that the font code in plib
1025 // renders only CCW trianbles. Yet they come out backwards.
1026 // Something around here or in plib is either changing the winding
1027 // order or (more likely) pushing a left-handed matrix onto the
1028 // stack. But I can't find it; get out the chainsaw...
1030 text_renderer.puts((char *)(_value.c_str()));
1031 glFrontFace(GL_CCW);
1033 text_renderer.end();
1034 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1039 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1041 _chunks.push_back(chunk);
1045 FGTextLayer::setColor (float r, float g, float b)
1054 FGTextLayer::setPointSize (float size)
1060 FGTextLayer::setFontName(const string &name)
1067 FGTextLayer::setFont(fntFont * font)
1069 text_renderer.setFont(font);
1074 FGTextLayer::recalc_value () const
1077 chunk_list::const_iterator it = _chunks.begin();
1078 chunk_list::const_iterator last = _chunks.end();
1079 for ( ; it != last; it++) {
1080 _value += (*it)->getValue();
1086 ////////////////////////////////////////////////////////////////////////
1087 // Implementation of FGTextLayer::Chunk.
1088 ////////////////////////////////////////////////////////////////////////
1090 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1091 : _type(FGTextLayer::TEXT), _fmt(fmt)
1098 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1099 const string &fmt, float mult, float offs,
1101 : _type(type), _fmt(fmt), _mult(mult), _offs(offs), _trunc(truncation)
1104 if (type == TEXT_VALUE)
1113 FGTextLayer::Chunk::getValue () const
1119 sprintf(_buf, _fmt.c_str(), _text.c_str());
1122 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1125 double d = _offs + _node->getFloatValue() * _mult;
1126 if (_trunc) d = (d < 0) ? -floor(-d) : floor(d);
1127 sprintf(_buf, _fmt.c_str(), d);
1138 ////////////////////////////////////////////////////////////////////////
1139 // Implementation of FGSwitchLayer.
1140 ////////////////////////////////////////////////////////////////////////
1142 FGSwitchLayer::FGSwitchLayer ()
1148 FGSwitchLayer::draw ()
1152 int nLayers = _layers.size();
1153 for (int i = 0; i < nLayers; i++) {
1154 if (_layers[i]->test()) {