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 // Syd Adams: added instrument clipping
423 instrument_list_type::const_iterator current = _instruments.begin();
424 instrument_list_type::const_iterator end = _instruments.end();
426 GLdouble blx[4]={1.0,0.0,0.0,0.0};
427 GLdouble bly[4]={0.0,1.0,0.0,0.0};
428 GLdouble urx[4]={-1.0,0.0,0.0,0.0};
429 GLdouble ury[4]={0.0,-1.0,0.0,0.0};
431 for ( ; current != end; current++) {
432 FGPanelInstrument * instr = *current;
434 glTranslated(instr->getXPos(), instr->getYPos(), 0);
436 int ix= instr->getWidth();
437 int iy= instr->getHeight();
439 glTranslated(-ix/2,-iy/2,0);
440 glClipPlane(GL_CLIP_PLANE0,blx);
441 glClipPlane(GL_CLIP_PLANE1,bly);
442 glEnable(GL_CLIP_PLANE0);
443 glEnable(GL_CLIP_PLANE1);
445 glTranslated(ix,iy,0);
446 glClipPlane(GL_CLIP_PLANE2,urx);
447 glClipPlane(GL_CLIP_PLANE3,ury);
448 glEnable(GL_CLIP_PLANE2);
449 glEnable(GL_CLIP_PLANE3);
456 glDisable(GL_CLIP_PLANE0);
457 glDisable(GL_CLIP_PLANE1);
458 glDisable(GL_CLIP_PLANE2);
459 glDisable(GL_CLIP_PLANE3);
462 // Draw yellow "hotspots" if directed to. This is a panel authoring
463 // feature; not intended to be high performance or to look good.
464 if ( fgGetBool("/sim/panel-hotspots") ) {
465 glDisable(GL_TEXTURE_2D);
468 for ( unsigned int i = 0; i < _instruments.size(); i++ )
469 _instruments[i]->drawHotspots();
473 // restore some original state
474 if ( _enable_depth_test )
475 glDepthFunc(GL_LESS);
477 glPolygonOffset(0, 0);
478 glDisable(GL_POLYGON_OFFSET_FILL);
482 * Set the panel's visibility.
485 FGPanel::setVisibility (bool visibility)
487 _visibility->setBoolValue( visibility );
492 * Return true if the panel is visible.
495 FGPanel::getVisibility () const
497 return _visibility->getBoolValue();
502 * Set the panel's background texture.
505 FGPanel::setBackground (ssgTexture * texture)
511 * Set the panel's multiple background textures.
514 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
521 * Set the panel's x-offset.
524 FGPanel::setXOffset (int offset)
526 if (offset <= 0 && offset >= -_width + WIN_W)
527 _x_offset->setIntValue( offset );
532 * Set the panel's y-offset.
535 FGPanel::setYOffset (int offset)
537 if (offset <= 0 && offset >= -_height)
538 _y_offset->setIntValue( offset );
542 * Handle a mouse action in panel-local (not screen) coordinates.
543 * Used by the 3D panel code in Model/panelnode.cxx, in situations
544 * where the panel doesn't control its own screen location.
547 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
549 // Note a released button and return
551 if (_mouseInstrument != 0)
552 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
554 _mouseInstrument = 0;
558 // Search for a matching instrument.
559 for (int i = 0; i < (int)_instruments.size(); i++) {
560 FGPanelInstrument *inst = _instruments[i];
561 int ix = inst->getXPos();
562 int iy = inst->getYPos();
563 int iw = inst->getWidth() / 2;
564 int ih = inst->getHeight() / 2;
565 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
568 _mouseInstrument = inst;
569 _mouseButton = button;
572 // Always do the action once.
573 return _mouseInstrument->doMouseAction(_mouseButton, 0,
581 * Perform a mouse action.
584 FGPanel::doMouseAction (int button, int updown, int x, int y)
586 // FIXME: this same code appears in update()
587 int xsize = _xsize_node->getIntValue();
588 int ysize = _ysize_node->getIntValue();
589 float aspect_adjust = get_aspect_adjust(xsize, ysize);
591 // Scale for the real window size.
592 if (aspect_adjust < 1.0) {
593 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
594 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
596 x = int(((float)x / xsize) * WIN_W);
597 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
600 // Adjust for offsets.
601 x -= _x_offset->getIntValue();
602 y -= _y_offset->getIntValue();
604 // Having fixed up the coordinates, fall through to the local
605 // coordinate handler.
606 return doLocalMouseAction(button, updown, x, y);
609 void FGPanel::setDepthTest (bool enable) {
610 _enable_depth_test = enable;
615 ////////////////////////////////////////////////////////////////////////.
616 // Implementation of FGPanelAction.
617 ////////////////////////////////////////////////////////////////////////
619 FGPanelAction::FGPanelAction ()
623 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
625 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
629 FGPanelAction::~FGPanelAction ()
631 for (unsigned int i = 0; i < 2; i++) {
632 for (unsigned int j = 0; j < _bindings[i].size(); j++)
633 delete _bindings[i][j];
638 FGPanelAction::addBinding (FGBinding * binding, int updown)
640 _bindings[updown].push_back(binding);
644 FGPanelAction::doAction (int updown)
647 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
648 int nBindings = _bindings[updown].size();
649 for (int i = 0; i < nBindings; i++)
650 _bindings[updown][i]->fire();
652 _last_state = updown;
661 ////////////////////////////////////////////////////////////////////////
662 // Implementation of FGPanelTransformation.
663 ////////////////////////////////////////////////////////////////////////
665 FGPanelTransformation::FGPanelTransformation ()
670 FGPanelTransformation::~FGPanelTransformation ()
677 ////////////////////////////////////////////////////////////////////////
678 // Implementation of FGPanelInstrument.
679 ////////////////////////////////////////////////////////////////////////
682 FGPanelInstrument::FGPanelInstrument ()
688 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
694 FGPanelInstrument::~FGPanelInstrument ()
696 for (action_list_type::iterator it = _actions.begin();
697 it != _actions.end();
705 FGPanelInstrument::drawHotspots()
707 for ( unsigned int i = 0; i < _actions.size(); i++ ) {
708 FGPanelAction* a = _actions[i];
709 float x1 = getXPos() + a->getX();
710 float x2 = x1 + a->getWidth();
711 float y1 = getYPos() + a->getY();
712 float y2 = y1 + a->getHeight();
714 glBegin(GL_LINE_LOOP);
724 FGPanelInstrument::setPosition (int x, int y)
731 FGPanelInstrument::setSize (int w, int h)
738 FGPanelInstrument::getXPos () const
744 FGPanelInstrument::getYPos () const
750 FGPanelInstrument::getWidth () const
756 FGPanelInstrument::getHeight () const
762 FGPanelInstrument::addAction (FGPanelAction * action)
764 _actions.push_back(action);
767 // Coordinates relative to centre.
769 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
772 action_list_type::iterator it = _actions.begin();
773 action_list_type::iterator last = _actions.end();
774 for ( ; it != last; it++) {
775 if ((*it)->inArea(button, x, y) &&
776 (*it)->doAction(updown))
785 ////////////////////////////////////////////////////////////////////////
786 // Implementation of FGLayeredInstrument.
787 ////////////////////////////////////////////////////////////////////////
789 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
790 : FGPanelInstrument(x, y, w, h)
794 FGLayeredInstrument::~FGLayeredInstrument ()
796 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
803 FGLayeredInstrument::draw ()
808 for (int i = 0; i < (int)_layers.size(); i++) {
816 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
818 int n = _layers.size();
819 if (layer->getWidth() == -1) {
820 layer->setWidth(getWidth());
822 if (layer->getHeight() == -1) {
823 layer->setHeight(getHeight());
825 _layers.push_back(layer);
830 FGLayeredInstrument::addLayer (const FGCroppedTexture &texture,
833 return addLayer(new FGTexturedLayer(texture, w, h));
837 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
839 int layer = _layers.size() - 1;
840 _layers[layer]->addTransformation(transformation);
845 ////////////////////////////////////////////////////////////////////////
846 // Implementation of FGSpecialInstrument.
847 ////////////////////////////////////////////////////////////////////////
849 FGSpecialInstrument::FGSpecialInstrument (DCLGPS* sb)
850 : FGPanelInstrument()
855 FGSpecialInstrument::~FGSpecialInstrument ()
860 FGSpecialInstrument::draw ()
867 ////////////////////////////////////////////////////////////////////////
868 // Implementation of FGInstrumentLayer.
869 ////////////////////////////////////////////////////////////////////////
871 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
877 FGInstrumentLayer::~FGInstrumentLayer ()
879 for (transformation_list::iterator it = _transformations.begin();
880 it != _transformations.end();
888 FGInstrumentLayer::transform () const
890 transformation_list::const_iterator it = _transformations.begin();
891 transformation_list::const_iterator last = _transformations.end();
893 FGPanelTransformation *t = *it;
895 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
898 val = fmod(val, t->mod);
901 } else if (val > t->max) {
906 val = val * t->factor + t->offset;
908 val = t->table->interpolate(val) * t->factor + t->offset;
912 case FGPanelTransformation::XSHIFT:
913 glTranslatef(val, 0.0, 0.0);
915 case FGPanelTransformation::YSHIFT:
916 glTranslatef(0.0, val, 0.0);
918 case FGPanelTransformation::ROTATION:
919 glRotatef(-val, 0.0, 0.0, 1.0);
928 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
930 _transformations.push_back(transformation);
935 ////////////////////////////////////////////////////////////////////////
936 // Implementation of FGGroupLayer.
937 ////////////////////////////////////////////////////////////////////////
939 FGGroupLayer::FGGroupLayer ()
943 FGGroupLayer::~FGGroupLayer ()
945 for (unsigned int i = 0; i < _layers.size(); i++)
950 FGGroupLayer::draw ()
954 int nLayers = _layers.size();
955 for (int i = 0; i < nLayers; i++)
961 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
963 _layers.push_back(layer);
968 ////////////////////////////////////////////////////////////////////////
969 // Implementation of FGTexturedLayer.
970 ////////////////////////////////////////////////////////////////////////
973 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
974 : FGInstrumentLayer(w, h),
981 FGTexturedLayer::~FGTexturedLayer ()
987 FGTexturedLayer::draw ()
994 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
998 glColor4fv( emissive_panel_color );
1000 // From Curt: turn on the panel
1001 // lights after sundown.
1002 glColor4fv( panel_color );
1005 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
1006 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
1007 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
1008 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
1015 ////////////////////////////////////////////////////////////////////////
1016 // Implementation of FGTextLayer.
1017 ////////////////////////////////////////////////////////////////////////
1019 FGTextLayer::FGTextLayer (int w, int h)
1020 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("Helvetica.txf")
1023 _color[0] = _color[1] = _color[2] = 0.0;
1027 FGTextLayer::~FGTextLayer ()
1029 chunk_list::iterator it = _chunks.begin();
1030 chunk_list::iterator last = _chunks.end();
1031 for ( ; it != last; it++) {
1037 FGTextLayer::draw ()
1043 FGFontCache *fc = globals->get_fontcache();
1044 text_renderer.setFont(fc->getTexFont(_font_name.c_str()));
1046 text_renderer.setPointSize(_pointSize);
1047 text_renderer.begin();
1048 text_renderer.start3f(0, 0, 0);
1051 long diff = _now - _then;
1053 if (diff > 100000 || diff < 0 ) {
1054 // ( diff < 0 ) is a sanity check and indicates our time stamp
1055 // difference math probably overflowed. We can handle a max
1056 // difference of 35.8 minutes since the returned value is in
1057 // usec. So if the panel is left off longer than that we can
1058 // over flow the math with it is turned back on. This (diff <
1059 // 0) catches that situation, get's us out of trouble, and
1065 // Something is goofy. The code in this file renders only CCW
1066 // polygons, and I have verified that the font code in plib
1067 // renders only CCW trianbles. Yet they come out backwards.
1068 // Something around here or in plib is either changing the winding
1069 // order or (more likely) pushing a left-handed matrix onto the
1070 // stack. But I can't find it; get out the chainsaw...
1072 text_renderer.puts((char *)(_value.c_str()));
1073 glFrontFace(GL_CCW);
1075 text_renderer.end();
1076 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1081 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1083 _chunks.push_back(chunk);
1087 FGTextLayer::setColor (float r, float g, float b)
1096 FGTextLayer::setPointSize (float size)
1102 FGTextLayer::setFontName(const string &name)
1104 _font_name = name + ".txf";
1109 FGTextLayer::setFont(fntFont * font)
1111 text_renderer.setFont(font);
1116 FGTextLayer::recalc_value () const
1119 chunk_list::const_iterator it = _chunks.begin();
1120 chunk_list::const_iterator last = _chunks.end();
1121 for ( ; it != last; it++) {
1122 _value += (*it)->getValue();
1128 ////////////////////////////////////////////////////////////////////////
1129 // Implementation of FGTextLayer::Chunk.
1130 ////////////////////////////////////////////////////////////////////////
1132 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1133 : _type(FGTextLayer::TEXT), _fmt(fmt)
1140 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1141 const string &fmt, float mult, float offs,
1143 : _type(type), _fmt(fmt), _mult(mult), _offs(offs), _trunc(truncation)
1146 if (type == TEXT_VALUE)
1155 FGTextLayer::Chunk::getValue () const
1161 sprintf(_buf, _fmt.c_str(), _text.c_str());
1164 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1167 double d = _offs + _node->getFloatValue() * _mult;
1168 if (_trunc) d = (d < 0) ? -floor(-d) : floor(d);
1169 sprintf(_buf, _fmt.c_str(), d);
1180 ////////////////////////////////////////////////////////////////////////
1181 // Implementation of FGSwitchLayer.
1182 ////////////////////////////////////////////////////////////////////////
1184 FGSwitchLayer::FGSwitchLayer ()
1190 FGSwitchLayer::draw ()
1194 int nLayers = _layers.size();
1195 for (int i = 0; i < nLayers; i++) {
1196 if (_layers[i]->test()) {