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
35 #include <simgear/debug/logstream.hxx>
36 #include <simgear/misc/sg_path.hxx>
38 #include <Main/globals.hxx>
39 #include <Main/fg_props.hxx>
40 #include <Main/viewmgr.hxx>
41 #include <Objects/texload.h>
42 #include <Time/light.hxx>
52 // The number of polygon-offset "units" to place between layers. In
53 // principle, one is supposed to be enough. In practice, I find that
54 // my hardware/driver requires many more.
58 ////////////////////////////////////////////////////////////////////////
60 ////////////////////////////////////////////////////////////////////////
64 * Calculate the aspect adjustment for the panel.
67 get_aspect_adjust (int xsize, int ysize)
69 float ideal_aspect = float(WIN_W) / float(WIN_H);
70 float real_aspect = float(xsize) / float(ysize);
71 return (real_aspect / ideal_aspect);
76 ////////////////////////////////////////////////////////////////////////
78 ////////////////////////////////////////////////////////////////////////
83 if(globals->get_current_panel() == 0)
85 if(globals->get_current_panel()->getVisibility() == 0)
87 if(globals->get_viewmgr()->get_current() != 0)
89 if(globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0)
96 ////////////////////////////////////////////////////////////////////////
97 // Implementation of FGTextureManager.
98 ////////////////////////////////////////////////////////////////////////
100 map<string,ssgTexture *> FGTextureManager::_textureMap;
103 FGTextureManager::createTexture (const string &relativePath)
105 ssgTexture * texture = _textureMap[relativePath];
107 SG_LOG( SG_COCKPIT, SG_DEBUG,
108 "Texture " << relativePath << " does not yet exist" );
109 SGPath tpath(globals->get_fg_root());
110 tpath.append(relativePath);
111 texture = new ssgTexture((char *)tpath.c_str(), false, false);
112 _textureMap[relativePath] = texture;
113 if (_textureMap[relativePath] == 0)
114 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
115 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
116 << " handle=" << texture->getHandle() );
125 ////////////////////////////////////////////////////////////////////////
126 // Implementation of FGCropped Texture.
127 ////////////////////////////////////////////////////////////////////////
130 FGCroppedTexture::FGCroppedTexture ()
131 : _path(""), _texture(0),
132 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
137 FGCroppedTexture::FGCroppedTexture (const string &path,
138 float minX, float minY,
139 float maxX, float maxY)
140 : _path(path), _texture(0),
141 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
146 FGCroppedTexture::~FGCroppedTexture ()
152 FGCroppedTexture::getTexture ()
155 _texture = FGTextureManager::createTexture(_path);
162 ////////////////////////////////////////////////////////////////////////
163 // Implementation of FGPanel.
164 ////////////////////////////////////////////////////////////////////////
166 static fntRenderer text_renderer;
167 static fntTexFont *default_font = 0;
168 static fntTexFont *led_font = 0;
176 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
177 _x_offset(0), _y_offset(0), _view_height(int(WIN_H * 0.4232)),
179 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
180 _ysize_node(fgGetNode("/sim/startup/ysize", true))
182 setVisibility(fgPanelVisible());
191 for (instrument_list_type::iterator it = _instruments.begin();
192 it != _instruments.end();
201 * Add an instrument to the panel.
204 FGPanel::addInstrument (FGPanelInstrument * instrument)
206 _instruments.push_back(instrument);
211 * Initialize the panel.
217 char* envp = ::getenv( "FG_FONTS" );
218 if ( envp != NULL ) {
219 base_path.set( envp );
221 base_path.set( globals->get_fg_root() );
222 base_path.append( "Fonts" );
227 // Install the default font
229 fntpath.append( "typewriter.txf" );
230 default_font = new fntTexFont ;
231 default_font -> load ( (char *)fntpath.c_str() ) ;
233 // Install the LED font
235 fntpath.append( "led.txf" );
236 led_font = new fntTexFont ;
237 led_font -> load ( (char *)fntpath.c_str() ) ;
242 * Bind panel properties.
247 fgSetArchivable("/sim/panel/visibility");
248 fgSetArchivable("/sim/panel/x-offset");
249 fgSetArchivable("/sim/panel/y-offset");
250 fgSetArchivable("/sim/panel/jitter");
255 * Unbind panel properties.
267 FGPanel::update (double dt)
269 // TODO: cache the nodes
270 _visibility = fgGetBool("/sim/panel/visibility");
271 _x_offset = fgGetInt("/sim/panel/x-offset");
272 _y_offset = fgGetInt("/sim/panel/y-offset");
273 _jitter = fgGetFloat("/sim/panel/jitter");
274 _flipx = fgGetBool("/sim/panel/flip-x");
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;
318 double y_offset = _y_offset;
321 if (_jitter != 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)) *
329 (a_y_pilot < 0 ? -1 : 1);
330 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter)) *
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);
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 );
378 // Draw the background
379 glEnable(GL_TEXTURE_2D);
380 glDisable(GL_LIGHTING);
382 glEnable(GL_ALPHA_TEST);
383 glEnable(GL_COLOR_MATERIAL);
385 sgCopyVec4( panel_color, cur_light_params.scene_diffuse );
386 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
387 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
388 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
389 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
391 glColor4fv( panel_color );
393 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
394 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
395 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
396 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
398 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
399 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
400 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
401 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
404 for (int i = 0; i < 4; i ++) {
405 // top row of textures...(1,3,5,7)
406 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
407 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
409 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
410 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
411 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
412 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
414 // bottom row of textures...(2,4,6,8)
415 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
416 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
418 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
419 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
420 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
421 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
426 // Draw the instruments.
427 instrument_list_type::const_iterator current = _instruments.begin();
428 instrument_list_type::const_iterator end = _instruments.end();
430 for ( ; current != end; current++) {
431 FGPanelInstrument * instr = *current;
433 glTranslated(instr->getXPos(), instr->getYPos(), 0);
438 // Draw yellow "hotspots" if directed to. This is a panel authoring
439 // feature; not intended to be high performance or to look good.
440 if(fgGetBool("/sim/panel-hotspots")) {
441 glPushAttrib(GL_ALL_ATTRIB_BITS);
442 glDisable(GL_DEPTH_TEST);
443 glDisable(GL_TEXTURE_2D);
446 for(int i=0; i<_instruments.size(); i++)
447 _instruments[i]->drawHotspots();
453 // restore some original state
455 glPolygonOffset(0, 0);
456 glDisable(GL_POLYGON_OFFSET_FILL);
460 * Set the panel's visibility.
463 FGPanel::setVisibility (bool visibility)
465 _visibility = visibility;
470 * Return true if the panel is visible.
473 FGPanel::getVisibility () const
480 * Set the panel's background texture.
483 FGPanel::setBackground (ssgTexture * texture)
489 * Set the panel's multiple background textures.
492 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
499 * Set the panel's x-offset.
502 FGPanel::setXOffset (int offset)
504 if (offset <= 0 && offset >= -_width + WIN_W)
510 * Set the panel's y-offset.
513 FGPanel::setYOffset (int offset)
515 if (offset <= 0 && offset >= -_height)
520 * Handle a mouse action in panel-local (not screen) coordinates.
521 * Used by the 3D panel code in Model/panelnode.cxx, in situations
522 * where the panel doesn't control its own screen location.
525 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
527 // Note a released button and return
529 if (_mouseInstrument != 0)
530 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
532 _mouseInstrument = 0;
536 // Search for a matching instrument.
537 for (int i = 0; i < (int)_instruments.size(); i++) {
538 FGPanelInstrument *inst = _instruments[i];
539 int ix = inst->getXPos();
540 int iy = inst->getYPos();
541 int iw = inst->getWidth() / 2;
542 int ih = inst->getHeight() / 2;
543 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
546 _mouseInstrument = inst;
547 _mouseButton = button;
550 // Always do the action once.
551 return _mouseInstrument->doMouseAction(_mouseButton, 0,
559 * Perform a mouse action.
562 FGPanel::doMouseAction (int button, int updown, int x, int y)
564 // FIXME: this same code appears in update()
565 int xsize = _xsize_node->getIntValue();
566 int ysize = _ysize_node->getIntValue();
567 float aspect_adjust = get_aspect_adjust(xsize, ysize);
569 // Scale for the real window size.
570 if (aspect_adjust < 1.0) {
571 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
572 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
574 x = int(((float)x / xsize) * WIN_W);
575 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
578 // Adjust for offsets.
582 // Having fixed up the coordinates, fall through to the local
583 // coordinate handler.
584 return doLocalMouseAction(button, updown, x, y);
589 ////////////////////////////////////////////////////////////////////////.
590 // Implementation of FGPanelAction.
591 ////////////////////////////////////////////////////////////////////////
593 FGPanelAction::FGPanelAction ()
597 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
599 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
601 for (unsigned int i = 0; i < 2; i++) {
602 for (unsigned int j = 0; j < _bindings[i].size(); j++)
603 delete _bindings[i][j];
607 FGPanelAction::~FGPanelAction ()
612 FGPanelAction::addBinding (FGBinding * binding, int updown)
614 _bindings[updown].push_back(binding);
618 FGPanelAction::doAction (int updown)
621 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
622 int nBindings = _bindings[updown].size();
623 for (int i = 0; i < nBindings; i++)
624 _bindings[updown][i]->fire();
626 _last_state = updown;
635 ////////////////////////////////////////////////////////////////////////
636 // Implementation of FGPanelTransformation.
637 ////////////////////////////////////////////////////////////////////////
639 FGPanelTransformation::FGPanelTransformation ()
644 FGPanelTransformation::~FGPanelTransformation ()
651 ////////////////////////////////////////////////////////////////////////
652 // Implementation of FGPanelInstrument.
653 ////////////////////////////////////////////////////////////////////////
656 FGPanelInstrument::FGPanelInstrument ()
662 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
668 FGPanelInstrument::~FGPanelInstrument ()
670 for (action_list_type::iterator it = _actions.begin();
671 it != _actions.end();
679 FGPanelInstrument::drawHotspots()
681 for(int i=0; i<_actions.size(); i++) {
682 FGPanelAction* a = _actions[i];
683 float x1 = getXPos() + a->getX();
684 float x2 = x1 + a->getWidth();
685 float y1 = getYPos() + a->getY();
686 float y2 = y1 + a->getHeight();
688 glBegin(GL_LINE_LOOP);
698 FGPanelInstrument::setPosition (int x, int y)
705 FGPanelInstrument::setSize (int w, int h)
712 FGPanelInstrument::getXPos () const
718 FGPanelInstrument::getYPos () const
724 FGPanelInstrument::getWidth () const
730 FGPanelInstrument::getHeight () const
736 FGPanelInstrument::addAction (FGPanelAction * action)
738 _actions.push_back(action);
741 // Coordinates relative to centre.
743 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
746 action_list_type::iterator it = _actions.begin();
747 action_list_type::iterator last = _actions.end();
748 for ( ; it != last; it++) {
749 if ((*it)->inArea(button, x, y) &&
750 (*it)->doAction(updown))
759 ////////////////////////////////////////////////////////////////////////
760 // Implementation of FGLayeredInstrument.
761 ////////////////////////////////////////////////////////////////////////
763 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
764 : FGPanelInstrument(x, y, w, h)
768 FGLayeredInstrument::~FGLayeredInstrument ()
770 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
777 FGLayeredInstrument::draw ()
782 for (int i = 0; i < (int)_layers.size(); i++) {
784 glPolygonOffset(-1, -POFF_UNITS*(i+2));
791 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
793 int n = _layers.size();
794 if (layer->getWidth() == -1) {
795 layer->setWidth(getWidth());
797 if (layer->getHeight() == -1) {
798 layer->setHeight(getHeight());
800 _layers.push_back(layer);
805 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
808 return addLayer(new FGTexturedLayer(texture, w, h));
812 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
814 int layer = _layers.size() - 1;
815 _layers[layer]->addTransformation(transformation);
820 ////////////////////////////////////////////////////////////////////////
821 // Implementation of FGInstrumentLayer.
822 ////////////////////////////////////////////////////////////////////////
824 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
830 FGInstrumentLayer::~FGInstrumentLayer ()
832 for (transformation_list::iterator it = _transformations.begin();
833 it != _transformations.end();
841 FGInstrumentLayer::transform () const
843 transformation_list::const_iterator it = _transformations.begin();
844 transformation_list::const_iterator last = _transformations.end();
846 FGPanelTransformation *t = *it;
848 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
851 val = fmod(val, t->mod);
854 } else if (val > t->max) {
859 val = val * t->factor + t->offset;
861 val = t->table->interpolate(val) * t->factor + t->offset;
865 case FGPanelTransformation::XSHIFT:
866 glTranslatef(val, 0.0, 0.0);
868 case FGPanelTransformation::YSHIFT:
869 glTranslatef(0.0, val, 0.0);
871 case FGPanelTransformation::ROTATION:
872 glRotatef(-val, 0.0, 0.0, 1.0);
881 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
883 _transformations.push_back(transformation);
888 ////////////////////////////////////////////////////////////////////////
889 // Implementation of FGGroupLayer.
890 ////////////////////////////////////////////////////////////////////////
892 FGGroupLayer::FGGroupLayer ()
896 FGGroupLayer::~FGGroupLayer ()
898 for (unsigned int i = 0; i < _layers.size(); i++)
903 FGGroupLayer::draw ()
907 int nLayers = _layers.size();
908 for (int i = 0; i < nLayers; i++)
914 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
916 _layers.push_back(layer);
921 ////////////////////////////////////////////////////////////////////////
922 // Implementation of FGTexturedLayer.
923 ////////////////////////////////////////////////////////////////////////
926 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
927 : FGInstrumentLayer(w, h)
933 FGTexturedLayer::~FGTexturedLayer ()
939 FGTexturedLayer::draw ()
946 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
949 // From Curt: turn on the panel
950 // lights after sundown.
952 sgCopyVec4( panel_color, cur_light_params.scene_diffuse );
953 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
954 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
955 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
956 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
958 glColor4fv( panel_color );
960 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
961 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
962 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
963 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
970 ////////////////////////////////////////////////////////////////////////
971 // Implementation of FGTextLayer.
972 ////////////////////////////////////////////////////////////////////////
974 FGTextLayer::FGTextLayer (int w, int h)
975 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
978 _color[0] = _color[1] = _color[2] = 0.0;
982 FGTextLayer::~FGTextLayer ()
984 chunk_list::iterator it = _chunks.begin();
985 chunk_list::iterator last = _chunks.end();
986 for ( ; it != last; it++) {
997 if ( _font_name == "led" && led_font != 0) {
998 text_renderer.setFont(led_font);
1000 text_renderer.setFont(guiFntHandle);
1002 text_renderer.setPointSize(_pointSize);
1003 text_renderer.begin();
1004 text_renderer.start3f(0, 0, 0);
1007 long diff = _now - _then;
1009 if (diff > 100000 || diff < 0 ) {
1010 // ( diff < 0 ) is a sanity check and indicates our time stamp
1011 // difference math probably overflowed. We can handle a max
1012 // difference of 35.8 minutes since the returned value is in
1013 // usec. So if the panel is left off longer than that we can
1014 // over flow the math with it is turned back on. This (diff <
1015 // 0) catches that situation, get's us out of trouble, and
1021 // Something is goofy. The code in this file renders only CCW
1022 // polygons, and I have verified that the font code in plib
1023 // renders only CCW trianbles. Yet they come out backwards.
1024 // Something around here or in plib is either changing the winding
1025 // order or (more likely) pushing a left-handed matrix onto the
1026 // stack. But I can't find it; get out the chainsaw...
1028 text_renderer.puts((char *)(_value.c_str()));
1029 glFrontFace(GL_CCW);
1031 text_renderer.end();
1032 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1037 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1039 _chunks.push_back(chunk);
1043 FGTextLayer::setColor (float r, float g, float b)
1052 FGTextLayer::setPointSize (float size)
1058 FGTextLayer::setFontName(const string &name)
1065 FGTextLayer::setFont(fntFont * font)
1067 text_renderer.setFont(font);
1072 FGTextLayer::recalc_value () const
1075 chunk_list::const_iterator it = _chunks.begin();
1076 chunk_list::const_iterator last = _chunks.end();
1077 for ( ; it != last; it++) {
1078 _value += (*it)->getValue();
1084 ////////////////////////////////////////////////////////////////////////
1085 // Implementation of FGTextLayer::Chunk.
1086 ////////////////////////////////////////////////////////////////////////
1088 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1089 : _type(FGTextLayer::TEXT), _fmt(fmt)
1096 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1097 const string &fmt, float mult)
1098 : _type(type), _fmt(fmt), _mult(mult)
1101 if (type == TEXT_VALUE)
1110 FGTextLayer::Chunk::getValue () const
1116 sprintf(_buf, _fmt.c_str(), _text.c_str());
1119 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1122 sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
1133 ////////////////////////////////////////////////////////////////////////
1134 // Implementation of FGSwitchLayer.
1135 ////////////////////////////////////////////////////////////////////////
1137 FGSwitchLayer::FGSwitchLayer ()
1143 FGSwitchLayer::draw ()
1147 int nLayers = _layers.size();
1148 for (int i = 0; i < nLayers; i++) {
1149 if (_layers[i]->test()) {