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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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>
55 #include <GUI/new_gui.hxx> // FGFontCache
65 // The number of polygon-offset "units" to place between layers. In
66 // principle, one is supposed to be enough. In practice, I find that
67 // my hardware/driver requires many more.
70 ////////////////////////////////////////////////////////////////////////
72 ////////////////////////////////////////////////////////////////////////
76 * Calculate the aspect adjustment for the panel.
79 get_aspect_adjust (int xsize, int ysize)
81 float ideal_aspect = float(WIN_W) / float(WIN_H);
82 float real_aspect = float(xsize) / float(ysize);
83 return (real_aspect / ideal_aspect);
88 ////////////////////////////////////////////////////////////////////////
90 ////////////////////////////////////////////////////////////////////////
95 if (globals->get_current_panel() == 0)
97 if (globals->get_current_panel()->getVisibility() == 0)
99 if (globals->get_viewmgr()->get_current() != 0)
101 if (globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
108 ////////////////////////////////////////////////////////////////////////
109 // Implementation of FGTextureManager.
110 ////////////////////////////////////////////////////////////////////////
112 map<string,ssgTexture *> FGTextureManager::_textureMap;
115 FGTextureManager::createTexture (const string &relativePath)
117 ssgTexture * texture = _textureMap[relativePath];
119 SG_LOG( SG_COCKPIT, SG_DEBUG,
120 "Texture " << relativePath << " does not yet exist" );
121 SGPath tpath(globals->get_fg_root());
122 tpath.append(relativePath);
123 texture = new ssgTexture((char *)tpath.c_str(), false, false);
124 _textureMap[relativePath] = texture;
125 if (_textureMap[relativePath] == 0)
126 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
127 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
128 << " handle=" << texture->getHandle() );
137 ////////////////////////////////////////////////////////////////////////
138 // Implementation of FGCropped Texture.
139 ////////////////////////////////////////////////////////////////////////
142 FGCroppedTexture::FGCroppedTexture ()
143 : _path(""), _texture(0),
144 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
149 FGCroppedTexture::FGCroppedTexture (const string &path,
150 float minX, float minY,
151 float maxX, float maxY)
152 : _path(path), _texture(0),
153 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
158 FGCroppedTexture::~FGCroppedTexture ()
164 FGCroppedTexture::getTexture ()
167 _texture = FGTextureManager::createTexture(_path);
174 ////////////////////////////////////////////////////////////////////////
175 // Implementation of FGPanel.
176 ////////////////////////////////////////////////////////////////////////
178 static fntRenderer text_renderer;
179 static sgVec4 panel_color;
180 static sgVec4 emissive_panel_color = {1,1,1,1};
188 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
189 _view_height(int(WIN_H * 0.4232)),
190 _visibility(fgGetNode("/sim/panel/visibility", true)),
191 _x_offset(fgGetNode("/sim/panel/x-offset", true)),
192 _y_offset(fgGetNode("/sim/panel/y-offset", true)),
193 _jitter(fgGetNode("/sim/panel/jitter", true)),
194 _flipx(fgGetNode("/sim/panel/flip-x", true)),
195 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
196 _ysize_node(fgGetNode("/sim/startup/ysize", true)),
197 _enable_depth_test(false)
207 for (instrument_list_type::iterator it = _instruments.begin();
208 it != _instruments.end();
217 * Add an instrument to the panel.
220 FGPanel::addInstrument (FGPanelInstrument * instrument)
222 _instruments.push_back(instrument);
227 * Initialize the panel.
236 * Bind panel properties.
241 fgSetArchivable("/sim/panel/visibility");
242 fgSetArchivable("/sim/panel/x-offset");
243 fgSetArchivable("/sim/panel/y-offset");
244 fgSetArchivable("/sim/panel/jitter");
249 * Unbind panel properties.
261 FGPanel::update (double dt)
263 // Do nothing if the panel isn't visible.
264 if ( !fgPanelVisible() ) {
270 // Now, draw the panel
271 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
272 _ysize_node->getIntValue());
273 if (aspect_adjust <1.0)
274 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
276 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
280 * Handle repeatable mouse events. Called from update() and from
281 * fgUpdate3DPanels(). This functionality needs to move into the
282 * input subsystem. Counting a tick every two frames is clumsy...
284 void FGPanel::updateMouseDelay()
288 if (_mouseDelay < 0) {
289 _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
297 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
299 // Calculate accelerations
300 // and jiggle the panel accordingly
301 // The factors and bounds are just
302 // initial guesses; using sqrt smooths
304 double x_offset = _x_offset->getIntValue();
305 double y_offset = _y_offset->getIntValue();
308 if (_jitter->getFloatValue() != 0.0) {
309 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
310 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
311 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
313 double a_zx_pilot = a_z_pilot - a_x_pilot;
315 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter->getFloatValue())) *
316 (a_y_pilot < 0 ? -1 : 1);
317 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter->getFloatValue())) *
318 (a_zx_pilot < 0 ? -1 : 1);
320 // adjustments in screen coordinates
321 x_offset += x_adjust;
322 y_offset += y_adjust;
326 glMatrixMode(GL_PROJECTION);
329 if ( _flipx->getBoolValue() ) {
330 gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
332 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
335 glMatrixMode(GL_MODELVIEW);
339 glTranslated(x_offset, y_offset, 0);
343 glMatrixMode(GL_PROJECTION);
345 glMatrixMode(GL_MODELVIEW);
348 ssgForceBasicState();
349 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
355 // In 3D mode, it's possible that we are being drawn exactly on top
356 // of an existing polygon. Use an offset to prevent z-fighting. In
357 // 2D mode, this is a no-op.
358 glEnable(GL_POLYGON_OFFSET_FILL);
359 glPolygonOffset(-1, -POFF_UNITS);
362 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT
363 | GL_TEXTURE_BIT | GL_PIXEL_MODE_BIT | GL_CULL_FACE
364 | GL_DEPTH_BUFFER_BIT );
366 // Draw the background
367 glEnable(GL_TEXTURE_2D);
368 glDisable(GL_LIGHTING);
370 glEnable(GL_ALPHA_TEST);
371 glEnable(GL_COLOR_MATERIAL);
372 glEnable(GL_CULL_FACE);
374 if ( _enable_depth_test )
375 glDepthFunc(GL_ALWAYS);
377 glDisable(GL_DEPTH_TEST);
379 FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
380 sgCopyVec4( panel_color, l->scene_diffuse());
381 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
382 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
383 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
384 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
386 glColor4fv( panel_color );
388 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
389 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
390 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
391 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
393 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
394 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
395 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
396 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
399 for (int i = 0; i < 4; i ++) {
400 // top row of textures...(1,3,5,7)
401 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
402 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
404 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
405 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
406 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
407 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
409 // bottom row of textures...(2,4,6,8)
410 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
411 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
413 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
414 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
415 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
416 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
421 // Draw the instruments.
422 instrument_list_type::const_iterator current = _instruments.begin();
423 instrument_list_type::const_iterator end = _instruments.end();
425 for ( ; current != end; current++) {
426 FGPanelInstrument * instr = *current;
428 glTranslated(instr->getXPos(), instr->getYPos(), 0);
433 // Draw yellow "hotspots" if directed to. This is a panel authoring
434 // feature; not intended to be high performance or to look good.
435 if ( fgGetBool("/sim/panel-hotspots") ) {
436 glDisable(GL_TEXTURE_2D);
439 for ( unsigned int i = 0; i < _instruments.size(); i++ )
440 _instruments[i]->drawHotspots();
444 // restore some original state
445 if ( _enable_depth_test )
446 glDepthFunc(GL_LESS);
448 glPolygonOffset(0, 0);
449 glDisable(GL_POLYGON_OFFSET_FILL);
453 * Set the panel's visibility.
456 FGPanel::setVisibility (bool visibility)
458 _visibility->setBoolValue( visibility );
463 * Return true if the panel is visible.
466 FGPanel::getVisibility () const
468 return _visibility->getBoolValue();
473 * Set the panel's background texture.
476 FGPanel::setBackground (ssgTexture * texture)
482 * Set the panel's multiple background textures.
485 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
492 * Set the panel's x-offset.
495 FGPanel::setXOffset (int offset)
497 if (offset <= 0 && offset >= -_width + WIN_W)
498 _x_offset->setIntValue( offset );
503 * Set the panel's y-offset.
506 FGPanel::setYOffset (int offset)
508 if (offset <= 0 && offset >= -_height)
509 _y_offset->setIntValue( offset );
513 * Handle a mouse action in panel-local (not screen) coordinates.
514 * Used by the 3D panel code in Model/panelnode.cxx, in situations
515 * where the panel doesn't control its own screen location.
518 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
520 // Note a released button and return
522 if (_mouseInstrument != 0)
523 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
525 _mouseInstrument = 0;
529 // Search for a matching instrument.
530 for (int i = 0; i < (int)_instruments.size(); i++) {
531 FGPanelInstrument *inst = _instruments[i];
532 int ix = inst->getXPos();
533 int iy = inst->getYPos();
534 int iw = inst->getWidth() / 2;
535 int ih = inst->getHeight() / 2;
536 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
539 _mouseInstrument = inst;
540 _mouseButton = button;
543 // Always do the action once.
544 return _mouseInstrument->doMouseAction(_mouseButton, 0,
552 * Perform a mouse action.
555 FGPanel::doMouseAction (int button, int updown, int x, int y)
557 // FIXME: this same code appears in update()
558 int xsize = _xsize_node->getIntValue();
559 int ysize = _ysize_node->getIntValue();
560 float aspect_adjust = get_aspect_adjust(xsize, ysize);
562 // Scale for the real window size.
563 if (aspect_adjust < 1.0) {
564 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
565 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
567 x = int(((float)x / xsize) * WIN_W);
568 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
571 // Adjust for offsets.
572 x -= _x_offset->getIntValue();
573 y -= _y_offset->getIntValue();
575 // Having fixed up the coordinates, fall through to the local
576 // coordinate handler.
577 return doLocalMouseAction(button, updown, x, y);
580 void FGPanel::setDepthTest (bool enable) {
581 _enable_depth_test = enable;
586 ////////////////////////////////////////////////////////////////////////.
587 // Implementation of FGPanelAction.
588 ////////////////////////////////////////////////////////////////////////
590 FGPanelAction::FGPanelAction ()
594 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
596 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
600 FGPanelAction::~FGPanelAction ()
602 for (unsigned int i = 0; i < 2; i++) {
603 for (unsigned int j = 0; j < _bindings[i].size(); j++)
604 delete _bindings[i][j];
609 FGPanelAction::addBinding (FGBinding * binding, int updown)
611 _bindings[updown].push_back(binding);
615 FGPanelAction::doAction (int updown)
618 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
619 int nBindings = _bindings[updown].size();
620 for (int i = 0; i < nBindings; i++)
621 _bindings[updown][i]->fire();
623 _last_state = updown;
632 ////////////////////////////////////////////////////////////////////////
633 // Implementation of FGPanelTransformation.
634 ////////////////////////////////////////////////////////////////////////
636 FGPanelTransformation::FGPanelTransformation ()
641 FGPanelTransformation::~FGPanelTransformation ()
648 ////////////////////////////////////////////////////////////////////////
649 // Implementation of FGPanelInstrument.
650 ////////////////////////////////////////////////////////////////////////
653 FGPanelInstrument::FGPanelInstrument ()
659 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
665 FGPanelInstrument::~FGPanelInstrument ()
667 for (action_list_type::iterator it = _actions.begin();
668 it != _actions.end();
676 FGPanelInstrument::drawHotspots()
678 for ( unsigned int i = 0; i < _actions.size(); i++ ) {
679 FGPanelAction* a = _actions[i];
680 float x1 = getXPos() + a->getX();
681 float x2 = x1 + a->getWidth();
682 float y1 = getYPos() + a->getY();
683 float y2 = y1 + a->getHeight();
685 glBegin(GL_LINE_LOOP);
695 FGPanelInstrument::setPosition (int x, int y)
702 FGPanelInstrument::setSize (int w, int h)
709 FGPanelInstrument::getXPos () const
715 FGPanelInstrument::getYPos () const
721 FGPanelInstrument::getWidth () const
727 FGPanelInstrument::getHeight () const
733 FGPanelInstrument::addAction (FGPanelAction * action)
735 _actions.push_back(action);
738 // Coordinates relative to centre.
740 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
743 action_list_type::iterator it = _actions.begin();
744 action_list_type::iterator last = _actions.end();
745 for ( ; it != last; it++) {
746 if ((*it)->inArea(button, x, y) &&
747 (*it)->doAction(updown))
756 ////////////////////////////////////////////////////////////////////////
757 // Implementation of FGLayeredInstrument.
758 ////////////////////////////////////////////////////////////////////////
760 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
761 : FGPanelInstrument(x, y, w, h)
765 FGLayeredInstrument::~FGLayeredInstrument ()
767 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
774 FGLayeredInstrument::draw ()
779 for (int i = 0; i < (int)_layers.size(); i++) {
787 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
789 int n = _layers.size();
790 if (layer->getWidth() == -1) {
791 layer->setWidth(getWidth());
793 if (layer->getHeight() == -1) {
794 layer->setHeight(getHeight());
796 _layers.push_back(layer);
801 FGLayeredInstrument::addLayer (const FGCroppedTexture &texture,
804 return addLayer(new FGTexturedLayer(texture, w, h));
808 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
810 int layer = _layers.size() - 1;
811 _layers[layer]->addTransformation(transformation);
816 ////////////////////////////////////////////////////////////////////////
817 // Implementation of FGSpecialInstrument.
818 ////////////////////////////////////////////////////////////////////////
820 FGSpecialInstrument::FGSpecialInstrument (DCLGPS* sb)
821 : FGPanelInstrument()
826 FGSpecialInstrument::~FGSpecialInstrument ()
831 FGSpecialInstrument::draw ()
838 ////////////////////////////////////////////////////////////////////////
839 // Implementation of FGInstrumentLayer.
840 ////////////////////////////////////////////////////////////////////////
842 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
848 FGInstrumentLayer::~FGInstrumentLayer ()
850 for (transformation_list::iterator it = _transformations.begin();
851 it != _transformations.end();
859 FGInstrumentLayer::transform () const
861 transformation_list::const_iterator it = _transformations.begin();
862 transformation_list::const_iterator last = _transformations.end();
864 FGPanelTransformation *t = *it;
866 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
869 val = fmod(val, t->mod);
872 } else if (val > t->max) {
877 val = val * t->factor + t->offset;
879 val = t->table->interpolate(val) * t->factor + t->offset;
883 case FGPanelTransformation::XSHIFT:
884 glTranslatef(val, 0.0, 0.0);
886 case FGPanelTransformation::YSHIFT:
887 glTranslatef(0.0, val, 0.0);
889 case FGPanelTransformation::ROTATION:
890 glRotatef(-val, 0.0, 0.0, 1.0);
899 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
901 _transformations.push_back(transformation);
906 ////////////////////////////////////////////////////////////////////////
907 // Implementation of FGGroupLayer.
908 ////////////////////////////////////////////////////////////////////////
910 FGGroupLayer::FGGroupLayer ()
914 FGGroupLayer::~FGGroupLayer ()
916 for (unsigned int i = 0; i < _layers.size(); i++)
921 FGGroupLayer::draw ()
925 int nLayers = _layers.size();
926 for (int i = 0; i < nLayers; i++)
932 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
934 _layers.push_back(layer);
939 ////////////////////////////////////////////////////////////////////////
940 // Implementation of FGTexturedLayer.
941 ////////////////////////////////////////////////////////////////////////
944 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
945 : FGInstrumentLayer(w, h),
952 FGTexturedLayer::~FGTexturedLayer ()
958 FGTexturedLayer::draw ()
965 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
969 glColor4fv( emissive_panel_color );
971 // From Curt: turn on the panel
972 // lights after sundown.
973 glColor4fv( panel_color );
976 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
977 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
978 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
979 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
986 ////////////////////////////////////////////////////////////////////////
987 // Implementation of FGTextLayer.
988 ////////////////////////////////////////////////////////////////////////
990 FGTextLayer::FGTextLayer (int w, int h)
991 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("Helvetica.txf")
994 _color[0] = _color[1] = _color[2] = 0.0;
998 FGTextLayer::~FGTextLayer ()
1000 chunk_list::iterator it = _chunks.begin();
1001 chunk_list::iterator last = _chunks.end();
1002 for ( ; it != last; it++) {
1008 FGTextLayer::draw ()
1014 FGFontCache *fc = globals->get_fontcache();
1015 text_renderer.setFont(fc->getTexFont(_font_name.c_str()));
1017 text_renderer.setPointSize(_pointSize);
1018 text_renderer.begin();
1019 text_renderer.start3f(0, 0, 0);
1022 long diff = _now - _then;
1024 if (diff > 100000 || diff < 0 ) {
1025 // ( diff < 0 ) is a sanity check and indicates our time stamp
1026 // difference math probably overflowed. We can handle a max
1027 // difference of 35.8 minutes since the returned value is in
1028 // usec. So if the panel is left off longer than that we can
1029 // over flow the math with it is turned back on. This (diff <
1030 // 0) catches that situation, get's us out of trouble, and
1036 // Something is goofy. The code in this file renders only CCW
1037 // polygons, and I have verified that the font code in plib
1038 // renders only CCW trianbles. Yet they come out backwards.
1039 // Something around here or in plib is either changing the winding
1040 // order or (more likely) pushing a left-handed matrix onto the
1041 // stack. But I can't find it; get out the chainsaw...
1043 text_renderer.puts((char *)(_value.c_str()));
1044 glFrontFace(GL_CCW);
1046 text_renderer.end();
1047 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1052 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1054 _chunks.push_back(chunk);
1058 FGTextLayer::setColor (float r, float g, float b)
1067 FGTextLayer::setPointSize (float size)
1073 FGTextLayer::setFontName(const string &name)
1075 _font_name = name + ".txf";
1080 FGTextLayer::setFont(fntFont * font)
1082 text_renderer.setFont(font);
1087 FGTextLayer::recalc_value () const
1090 chunk_list::const_iterator it = _chunks.begin();
1091 chunk_list::const_iterator last = _chunks.end();
1092 for ( ; it != last; it++) {
1093 _value += (*it)->getValue();
1099 ////////////////////////////////////////////////////////////////////////
1100 // Implementation of FGTextLayer::Chunk.
1101 ////////////////////////////////////////////////////////////////////////
1103 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1104 : _type(FGTextLayer::TEXT), _fmt(fmt)
1111 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1112 const string &fmt, float mult, float offs,
1114 : _type(type), _fmt(fmt), _mult(mult), _offs(offs), _trunc(truncation)
1117 if (type == TEXT_VALUE)
1126 FGTextLayer::Chunk::getValue () const
1132 sprintf(_buf, _fmt.c_str(), _text.c_str());
1135 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1138 double d = _offs + _node->getFloatValue() * _mult;
1139 if (_trunc) d = (d < 0) ? -floor(-d) : floor(d);
1140 sprintf(_buf, _fmt.c_str(), d);
1151 ////////////////////////////////////////////////////////////////////////
1152 // Implementation of FGSwitchLayer.
1153 ////////////////////////////////////////////////////////////////////////
1155 FGSwitchLayer::FGSwitchLayer ()
1161 FGSwitchLayer::draw ()
1165 int nLayers = _layers.size();
1166 for (int i = 0; i < nLayers; i++) {
1167 if (_layers[i]->test()) {