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(current_panel == 0)
85 if(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 FGPanel * current_panel = NULL;
167 static fntRenderer text_renderer;
168 static fntTexFont *default_font = 0;
169 static fntTexFont *led_font = 0;
177 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
178 _x_offset(0), _y_offset(0), _view_height(int(WIN_H * 0.4232)),
180 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
181 _ysize_node(fgGetNode("/sim/startup/ysize", true))
183 setVisibility(fgPanelVisible());
192 for (instrument_list_type::iterator it = _instruments.begin();
193 it != _instruments.end();
202 * Add an instrument to the panel.
205 FGPanel::addInstrument (FGPanelInstrument * instrument)
207 _instruments.push_back(instrument);
212 * Initialize the panel.
218 char* envp = ::getenv( "FG_FONTS" );
219 if ( envp != NULL ) {
220 base_path.set( envp );
222 base_path.set( globals->get_fg_root() );
223 base_path.append( "Fonts" );
228 // Install the default font
230 fntpath.append( "typewriter.txf" );
231 default_font = new fntTexFont ;
232 default_font -> load ( (char *)fntpath.c_str() ) ;
234 // Install the LED font
236 fntpath.append( "led.txf" );
237 led_font = new fntTexFont ;
238 led_font -> load ( (char *)fntpath.c_str() ) ;
243 * Bind panel properties.
248 fgSetArchivable("/sim/panel/visibility");
249 fgSetArchivable("/sim/panel/x-offset");
250 fgSetArchivable("/sim/panel/y-offset");
251 fgSetArchivable("/sim/panel/jitter");
256 * Unbind panel properties.
268 FGPanel::update (double dt)
270 // TODO: cache the nodes
271 _visibility = fgGetBool("/sim/panel/visibility");
272 _x_offset = fgGetInt("/sim/panel/x-offset");
273 _y_offset = fgGetInt("/sim/panel/y-offset");
274 _jitter = fgGetFloat("/sim/panel/jitter");
275 _flipx = fgGetBool("/sim/panel/flip-x");
277 // Do nothing if the panel isn't visible.
278 if ( !fgPanelVisible() ) {
284 // Now, draw the panel
285 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
286 _ysize_node->getIntValue());
287 if (aspect_adjust <1.0)
288 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
290 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
294 * Handle repeatable mouse events. Called from update() and from
295 * fgUpdate3DPanels(). This functionality needs to move into the
296 * input subsystem. Counting a tick every two frames is clumsy...
298 void FGPanel::updateMouseDelay()
302 if (_mouseDelay < 0) {
303 _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
311 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
313 // Calculate accelerations
314 // and jiggle the panel accordingly
315 // The factors and bounds are just
316 // initial guesses; using sqrt smooths
318 double x_offset = _x_offset;
319 double y_offset = _y_offset;
322 if (_jitter != 0.0) {
323 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
324 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
325 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
327 double a_zx_pilot = a_z_pilot - a_x_pilot;
329 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter)) *
330 (a_y_pilot < 0 ? -1 : 1);
331 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter)) *
332 (a_zx_pilot < 0 ? -1 : 1);
334 // adjustments in screen coordinates
335 x_offset += x_adjust;
336 y_offset += y_adjust;
340 glMatrixMode(GL_PROJECTION);
344 gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
346 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
349 glMatrixMode(GL_MODELVIEW);
353 glTranslated(x_offset, y_offset, 0);
357 glMatrixMode(GL_PROJECTION);
359 glMatrixMode(GL_MODELVIEW);
362 ssgForceBasicState();
363 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
369 // In 3D mode, it's possible that we are being drawn exactly on top
370 // of an existing polygon. Use an offset to prevent z-fighting. In
371 // 2D mode, this is a no-op.
372 glEnable(GL_POLYGON_OFFSET_FILL);
373 glPolygonOffset(-1, -POFF_UNITS);
376 glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT
377 | GL_TEXTURE_BIT | GL_PIXEL_MODE_BIT );
379 // Draw the background
380 glEnable(GL_TEXTURE_2D);
381 glDisable(GL_LIGHTING);
383 glEnable(GL_ALPHA_TEST);
384 glEnable(GL_COLOR_MATERIAL);
386 sgCopyVec4( panel_color, cur_light_params.scene_diffuse );
387 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
388 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
389 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
390 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
392 glColor4fv( panel_color );
394 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
395 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
396 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
397 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
399 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X, WIN_Y);
400 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + _width, WIN_Y);
401 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + _width, WIN_Y + _height);
402 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X, WIN_Y + _height);
405 for (int i = 0; i < 4; i ++) {
406 // top row of textures...(1,3,5,7)
407 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
408 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
410 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
411 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
412 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + _height);
413 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + _height);
415 // bottom row of textures...(2,4,6,8)
416 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
417 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
419 glTexCoord2f(0.0, 0.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y);
420 glTexCoord2f(1.0, 0.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y);
421 glTexCoord2f(1.0, 1.0); glVertex2f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2));
422 glTexCoord2f(0.0, 1.0); glVertex2f(WIN_X + (_width/4) * i, WIN_Y + (_height/2));
427 // Draw the instruments.
428 instrument_list_type::const_iterator current = _instruments.begin();
429 instrument_list_type::const_iterator end = _instruments.end();
431 for ( ; current != end; current++) {
432 FGPanelInstrument * instr = *current;
434 glTranslated(instr->getXPos(), instr->getYPos(), 0);
439 // Draw yellow "hotspots" if directed to. This is a panel authoring
440 // feature; not intended to be high performance or to look good.
441 if(fgGetBool("/sim/panel-hotspots")) {
442 glPushAttrib(GL_ALL_ATTRIB_BITS);
443 glDisable(GL_DEPTH_TEST);
444 glDisable(GL_TEXTURE_2D);
447 for(int i=0; i<_instruments.size(); i++)
448 _instruments[i]->drawHotspots();
454 // restore some original state
456 glPolygonOffset(0, 0);
457 glDisable(GL_POLYGON_OFFSET_FILL);
461 * Set the panel's visibility.
464 FGPanel::setVisibility (bool visibility)
466 _visibility = visibility;
471 * Return true if the panel is visible.
474 FGPanel::getVisibility () const
481 * Set the panel's background texture.
484 FGPanel::setBackground (ssgTexture * texture)
490 * Set the panel's multiple background textures.
493 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
500 * Set the panel's x-offset.
503 FGPanel::setXOffset (int offset)
505 if (offset <= 0 && offset >= -_width + WIN_W)
511 * Set the panel's y-offset.
514 FGPanel::setYOffset (int offset)
516 if (offset <= 0 && offset >= -_height)
521 * Handle a mouse action in panel-local (not screen) coordinates.
522 * Used by the 3D panel code in Model/panelnode.cxx, in situations
523 * where the panel doesn't control its own screen location.
526 FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
528 // Note a released button and return
530 if (_mouseInstrument != 0)
531 _mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
533 _mouseInstrument = 0;
537 // Search for a matching instrument.
538 for (int i = 0; i < (int)_instruments.size(); i++) {
539 FGPanelInstrument *inst = _instruments[i];
540 int ix = inst->getXPos();
541 int iy = inst->getYPos();
542 int iw = inst->getWidth() / 2;
543 int ih = inst->getHeight() / 2;
544 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
547 _mouseInstrument = inst;
548 _mouseButton = button;
551 // Always do the action once.
552 return _mouseInstrument->doMouseAction(_mouseButton, 0,
560 * Perform a mouse action.
563 FGPanel::doMouseAction (int button, int updown, int x, int y)
565 // FIXME: this same code appears in update()
566 int xsize = _xsize_node->getIntValue();
567 int ysize = _ysize_node->getIntValue();
568 float aspect_adjust = get_aspect_adjust(xsize, ysize);
570 // Scale for the real window size.
571 if (aspect_adjust < 1.0) {
572 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
573 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
575 x = int(((float)x / xsize) * WIN_W);
576 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
579 // Adjust for offsets.
583 // Having fixed up the coordinates, fall through to the local
584 // coordinate handler.
585 doLocalMouseAction(button, updown, x, y);
590 ////////////////////////////////////////////////////////////////////////.
591 // Implementation of FGPanelAction.
592 ////////////////////////////////////////////////////////////////////////
594 FGPanelAction::FGPanelAction ()
598 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
600 : _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
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];
608 FGPanelAction::~FGPanelAction ()
613 FGPanelAction::addBinding (FGBinding * binding, int updown)
615 _bindings[updown].push_back(binding);
619 FGPanelAction::doAction (int updown)
622 if ((updown != _last_state) || (updown == 0 && _repeatable)) {
623 int nBindings = _bindings[updown].size();
624 for (int i = 0; i < nBindings; i++)
625 _bindings[updown][i]->fire();
627 _last_state = updown;
636 ////////////////////////////////////////////////////////////////////////
637 // Implementation of FGPanelTransformation.
638 ////////////////////////////////////////////////////////////////////////
640 FGPanelTransformation::FGPanelTransformation ()
645 FGPanelTransformation::~FGPanelTransformation ()
652 ////////////////////////////////////////////////////////////////////////
653 // Implementation of FGPanelInstrument.
654 ////////////////////////////////////////////////////////////////////////
657 FGPanelInstrument::FGPanelInstrument ()
663 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
669 FGPanelInstrument::~FGPanelInstrument ()
671 for (action_list_type::iterator it = _actions.begin();
672 it != _actions.end();
680 FGPanelInstrument::drawHotspots()
682 for(int i=0; i<_actions.size(); i++) {
683 FGPanelAction* a = _actions[i];
684 float x1 = getXPos() + a->getX();
685 float x2 = x1 + a->getWidth();
686 float y1 = getYPos() + a->getY();
687 float y2 = y1 + a->getHeight();
689 glBegin(GL_LINE_LOOP);
699 FGPanelInstrument::setPosition (int x, int y)
706 FGPanelInstrument::setSize (int w, int h)
713 FGPanelInstrument::getXPos () const
719 FGPanelInstrument::getYPos () const
725 FGPanelInstrument::getWidth () const
731 FGPanelInstrument::getHeight () const
737 FGPanelInstrument::addAction (FGPanelAction * action)
739 _actions.push_back(action);
742 // Coordinates relative to centre.
744 FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
747 action_list_type::iterator it = _actions.begin();
748 action_list_type::iterator last = _actions.end();
749 for ( ; it != last; it++) {
750 if ((*it)->inArea(button, x, y) &&
751 (*it)->doAction(updown))
760 ////////////////////////////////////////////////////////////////////////
761 // Implementation of FGLayeredInstrument.
762 ////////////////////////////////////////////////////////////////////////
764 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
765 : FGPanelInstrument(x, y, w, h)
769 FGLayeredInstrument::~FGLayeredInstrument ()
771 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
778 FGLayeredInstrument::draw ()
783 for (int i = 0; i < (int)_layers.size(); i++) {
785 glPolygonOffset(-1, -POFF_UNITS*(i+2));
792 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
794 int n = _layers.size();
795 if (layer->getWidth() == -1) {
796 layer->setWidth(getWidth());
798 if (layer->getHeight() == -1) {
799 layer->setHeight(getHeight());
801 _layers.push_back(layer);
806 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
809 return addLayer(new FGTexturedLayer(texture, w, h));
813 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
815 int layer = _layers.size() - 1;
816 _layers[layer]->addTransformation(transformation);
821 ////////////////////////////////////////////////////////////////////////
822 // Implementation of FGInstrumentLayer.
823 ////////////////////////////////////////////////////////////////////////
825 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
831 FGInstrumentLayer::~FGInstrumentLayer ()
833 for (transformation_list::iterator it = _transformations.begin();
834 it != _transformations.end();
842 FGInstrumentLayer::transform () const
844 transformation_list::const_iterator it = _transformations.begin();
845 transformation_list::const_iterator last = _transformations.end();
847 FGPanelTransformation *t = *it;
849 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
852 } else if (val > t->max) {
856 val = val * t->factor + t->offset;
858 val = t->table->interpolate(val) * t->factor + t->offset;
862 case FGPanelTransformation::XSHIFT:
863 glTranslatef(val, 0.0, 0.0);
865 case FGPanelTransformation::YSHIFT:
866 glTranslatef(0.0, val, 0.0);
868 case FGPanelTransformation::ROTATION:
869 glRotatef(-val, 0.0, 0.0, 1.0);
878 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
880 _transformations.push_back(transformation);
885 ////////////////////////////////////////////////////////////////////////
886 // Implementation of FGGroupLayer.
887 ////////////////////////////////////////////////////////////////////////
889 FGGroupLayer::FGGroupLayer ()
893 FGGroupLayer::~FGGroupLayer ()
895 for (unsigned int i = 0; i < _layers.size(); i++)
900 FGGroupLayer::draw ()
903 int nLayers = _layers.size();
904 for (int i = 0; i < nLayers; i++)
910 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
912 _layers.push_back(layer);
917 ////////////////////////////////////////////////////////////////////////
918 // Implementation of FGTexturedLayer.
919 ////////////////////////////////////////////////////////////////////////
922 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
923 : FGInstrumentLayer(w, h)
929 FGTexturedLayer::~FGTexturedLayer ()
935 FGTexturedLayer::draw ()
942 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
945 // From Curt: turn on the panel
946 // lights after sundown.
948 sgCopyVec4( panel_color, cur_light_params.scene_diffuse );
949 if ( fgGetDouble("/systems/electrical/outputs/instrument-lights") > 1.0 ) {
950 if ( panel_color[0] < 0.7 ) panel_color[0] = 0.7;
951 if ( panel_color[1] < 0.2 ) panel_color[1] = 0.2;
952 if ( panel_color[2] < 0.2 ) panel_color[2] = 0.2;
954 glColor4fv( panel_color );
956 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
957 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
958 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
959 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
966 ////////////////////////////////////////////////////////////////////////
967 // Implementation of FGTextLayer.
968 ////////////////////////////////////////////////////////////////////////
970 FGTextLayer::FGTextLayer (int w, int h)
971 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
974 _color[0] = _color[1] = _color[2] = 0.0;
978 FGTextLayer::~FGTextLayer ()
980 chunk_list::iterator it = _chunks.begin();
981 chunk_list::iterator last = _chunks.end();
982 for ( ; it != last; it++) {
993 if ( _font_name == "led" && led_font != 0) {
994 text_renderer.setFont(led_font);
996 text_renderer.setFont(guiFntHandle);
998 text_renderer.setPointSize(_pointSize);
999 text_renderer.begin();
1000 text_renderer.start3f(0, 0, 0);
1003 long diff = _now - _then;
1005 if (diff > 100000 || diff < 0 ) {
1006 // ( diff < 0 ) is a sanity check and indicates our time stamp
1007 // difference math probably overflowed. We can handle a max
1008 // difference of 35.8 minutes since the returned value is in
1009 // usec. So if the panel is left off longer than that we can
1010 // over flow the math with it is turned back on. This (diff <
1011 // 0) catches that situation, get's us out of trouble, and
1017 // Something is goofy. The code in this file renders only CCW
1018 // polygons, and I have verified that the font code in plib
1019 // renders only CCW trianbles. Yet they come out backwards.
1020 // Something around here or in plib is either changing the winding
1021 // order or (more likely) pushing a left-handed matrix onto the
1022 // stack. But I can't find it; get out the chainsaw...
1024 text_renderer.puts((char *)(_value.c_str()));
1025 glFrontFace(GL_CCW);
1027 text_renderer.end();
1028 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1033 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1035 _chunks.push_back(chunk);
1039 FGTextLayer::setColor (float r, float g, float b)
1048 FGTextLayer::setPointSize (float size)
1054 FGTextLayer::setFontName(const string &name)
1061 FGTextLayer::setFont(fntFont * font)
1063 text_renderer.setFont(font);
1068 FGTextLayer::recalc_value () const
1071 chunk_list::const_iterator it = _chunks.begin();
1072 chunk_list::const_iterator last = _chunks.end();
1073 for ( ; it != last; it++) {
1074 _value += (*it)->getValue();
1080 ////////////////////////////////////////////////////////////////////////
1081 // Implementation of FGTextLayer::Chunk.
1082 ////////////////////////////////////////////////////////////////////////
1084 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1085 : _type(FGTextLayer::TEXT), _fmt(fmt)
1092 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1093 const string &fmt, float mult)
1094 : _type(type), _fmt(fmt), _mult(mult)
1097 if (type == TEXT_VALUE)
1106 FGTextLayer::Chunk::getValue () const
1112 sprintf(_buf, _fmt.c_str(), _text.c_str());
1115 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1118 sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
1129 ////////////////////////////////////////////////////////////////////////
1130 // Implementation of FGSwitchLayer.
1131 ////////////////////////////////////////////////////////////////////////
1133 FGSwitchLayer::FGSwitchLayer (int w, int h, const SGPropertyNode * node,
1134 FGInstrumentLayer * layer1,
1135 FGInstrumentLayer * layer2)
1136 : FGInstrumentLayer(w, h), _node(node), _layer1(layer1), _layer2(layer2)
1140 FGSwitchLayer::~FGSwitchLayer ()
1147 FGSwitchLayer::draw ()
1151 if (_node->getBoolValue()) {