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 #if defined( NONE ) && defined( _MSC_VER )
53 # pragma message( "A sloppy coder has defined NONE as a macro!!!" )
56 # pragma warn A sloppy coder has defined NONE as a macro!!!
61 ////////////////////////////////////////////////////////////////////////
63 ////////////////////////////////////////////////////////////////////////
67 * Calculate the aspect adjustment for the panel.
70 get_aspect_adjust (int xsize, int ysize)
72 float ideal_aspect = float(WIN_W) / float(WIN_H);
73 float real_aspect = float(xsize) / float(ysize);
74 return (real_aspect / ideal_aspect);
79 ////////////////////////////////////////////////////////////////////////
81 ////////////////////////////////////////////////////////////////////////
86 if(current_panel == 0)
88 if(current_panel->getVisibility() == 0)
90 if(globals->get_viewmgr()->get_current() != 0)
92 if(globals->get_current_view()->get_view_offset() != 0 &&
93 !fgGetBool("/sim/virtual-cockpit"))
100 ////////////////////////////////////////////////////////////////////////
101 // Implementation of FGTextureManager.
102 ////////////////////////////////////////////////////////////////////////
104 map<string,ssgTexture *> FGTextureManager::_textureMap;
107 FGTextureManager::createTexture (const string &relativePath)
109 ssgTexture * texture = _textureMap[relativePath];
111 SG_LOG( SG_COCKPIT, SG_DEBUG,
112 "Texture " << relativePath << " does not yet exist" );
113 SGPath tpath(globals->get_fg_root());
114 tpath.append(relativePath);
115 texture = new ssgTexture((char *)tpath.c_str(), false, false);
116 _textureMap[relativePath] = texture;
117 if (_textureMap[relativePath] == 0)
118 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
119 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
120 << " handle=" << texture->getHandle() );
129 ////////////////////////////////////////////////////////////////////////
130 // Implementation of FGCropped Texture.
131 ////////////////////////////////////////////////////////////////////////
134 FGCroppedTexture::FGCroppedTexture ()
135 : _path(""), _texture(0),
136 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
141 FGCroppedTexture::FGCroppedTexture (const string &path,
142 float minX, float minY,
143 float maxX, float maxY)
144 : _path(path), _texture(0),
145 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
150 FGCroppedTexture::~FGCroppedTexture ()
156 FGCroppedTexture::getTexture ()
159 _texture = FGTextureManager::createTexture(_path);
166 ////////////////////////////////////////////////////////////////////////
167 // Implementation of FGPanel.
168 ////////////////////////////////////////////////////////////////////////
170 FGPanel * current_panel = NULL;
171 static fntRenderer text_renderer;
172 static fntTexFont *default_font;
173 static fntTexFont *led_font;
181 _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
182 _x_offset(0), _y_offset(0), _view_height(int(WIN_H * 0.4232)),
185 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
186 _ysize_node(fgGetNode("/sim/startup/ysize", true))
188 setVisibility(fgPanelVisible());
199 for (instrument_list_type::iterator it = _instruments.begin();
200 it != _instruments.end();
209 * Add an instrument to the panel.
212 FGPanel::addInstrument (FGPanelInstrument * instrument)
214 _instruments.push_back(instrument);
219 * Initialize the panel.
225 char* envp = ::getenv( "FG_FONTS" );
226 if ( envp != NULL ) {
227 base_path.set( envp );
229 base_path.set( globals->get_fg_root() );
230 base_path.append( "Fonts" );
235 // Install the default font
237 fntpath.append( "typewriter.txf" );
238 default_font = new fntTexFont ;
239 default_font -> load ( (char *)fntpath.c_str() ) ;
241 // Install the LED font
243 fntpath.append( "led.txf" );
244 led_font = new fntTexFont ;
245 led_font -> load ( (char *)fntpath.c_str() ) ;
250 * Bind panel properties.
255 fgTie("/sim/panel/visibility", &_visibility);
256 fgSetArchivable("/sim/panel/visibility");
257 fgTie("/sim/panel/x-offset", &_x_offset);
258 fgSetArchivable("/sim/panel/x-offset");
259 fgTie("/sim/panel/y-offset", &_y_offset);
260 fgSetArchivable("/sim/panel/y-offset");
261 fgTie("/sim/panel/jitter", &_jitter);
262 fgSetArchivable("/sim/panel/jitter");
268 * Unbind panel properties.
273 fgUntie("/sim/panel/visibility");
274 fgUntie("/sim/panel/x-offset");
275 fgUntie("/sim/panel/y-offset");
284 FGPanel::update (int dt)
286 // Do nothing if the panel isn't visible.
287 if ( !fgPanelVisible() ) {
291 // If the mouse is down, do something
294 if (_mouseDelay < 0) {
295 _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
300 // Now, draw the panel
301 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
302 _ysize_node->getIntValue());
303 if (aspect_adjust <1.0)
304 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
306 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
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;
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;
338 if(fgGetBool("/sim/virtual-cockpit")) {
339 setupVirtualCockpit();
341 glMatrixMode(GL_PROJECTION);
344 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
345 // gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
347 glMatrixMode(GL_MODELVIEW);
351 glTranslated(x_offset, y_offset, 0);
354 // Draw the background
355 glEnable(GL_TEXTURE_2D);
356 glDisable(GL_LIGHTING);
358 glEnable(GL_ALPHA_TEST);
359 glEnable(GL_COLOR_MATERIAL);
360 // glColor4f(1.0, 1.0, 1.0, 1.0);
361 if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
362 glColor4fv( cur_light_params.scene_diffuse );
364 glColor4f(0.7, 0.2, 0.2, 1.0);
367 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
368 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
369 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
370 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
372 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
373 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
374 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
375 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
378 for (int i = 0; i < 4; i ++) {
379 // top row of textures...(1,3,5,7)
380 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
381 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
383 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
384 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
385 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + _height, 0);
386 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + _height, 0);
388 // bottom row of textures...(2,4,6,8)
389 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
390 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
392 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y, 0);
393 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y, 0);
394 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
395 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
401 // Draw the instruments.
402 instrument_list_type::const_iterator current = _instruments.begin();
403 instrument_list_type::const_iterator end = _instruments.end();
405 for ( ; current != end; current++) {
406 FGPanelInstrument * instr = *current;
408 glTranslated(instr->getXPos(), instr->getYPos(), 0);
413 if(fgGetBool("/sim/virtual-cockpit")) {
414 cleanupVirtualCockpit();
416 glMatrixMode(GL_PROJECTION);
418 glMatrixMode(GL_MODELVIEW);
422 ssgForceBasicState();
423 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
427 FGPanel::setupVirtualCockpit()
430 FGViewer* view = globals->get_current_view();
432 // Generate corners for the panel quad. Put the top edge of the
433 // panel 1m in and 6 degrees down from the forward direction, and
434 // make the whole thing 60 degrees wide. In principle, these
435 // should be settable per-panel, so that you can have lots of
436 // panel objects plastered about the cockpit in realistic
437 // positions and orientations.
438 float a[3], b[3], c[3];
439 float pw = tan(30*SGD_DEGREES_TO_RADIANS);
440 float ph = 2 * pw * (float)_height/(float)_width;
441 float ptop = -tan(6*SGD_DEGREES_TO_RADIANS);
442 a[0] = -pw; a[1] = ptop-ph; a[2] = -1; // bottom left
443 b[0] = pw; b[1] = ptop-ph; b[2] = -1; // bottom right
444 c[0] = -pw; c[1] = ptop; c[2] = -1; // top left
446 // A standard projection, in meters, with especially close clip
448 glMatrixMode(GL_PROJECTION);
451 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(),
454 glMatrixMode(GL_MODELVIEW);
458 // Generate a "look at" matrix using OpenGL (!) coordinate
461 float pitch = view->get_view_tilt();
462 float rot = view->get_view_offset();
463 lookat[0] = -sin(rot);
464 lookat[1] = sin(pitch) / cos(pitch);
465 lookat[2] = -cos(rot);
466 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
467 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
469 // Translate the origin to the location of the panel quad
470 glTranslatef(a[0], a[1], a[2]);
472 // Generate a matrix to translate unit square coordinates from the
473 // panel to real world coordinates. Use a transposed basis for
474 // the panel quad. Note: this matrix is relatively expensive to
475 // compute, and is invariant. Consider precomputing and storing
476 // it. Also, consider using the plib vector math routines, so the
477 // reuse junkies don't yell at me. (Fine, I hard-coded a cross
478 // product. Just shoot me and be done with it.)
479 float u[3], v[3], w[3], m[16];
480 for(i=0; i<3; i++) u[i] = b[i] - a[i]; // U = B - A
481 for(i=0; i<3; i++) v[i] = c[i] - a[i]; // V = C - A
482 w[0] = u[1]*v[2] - v[1]*u[2]; // W = U x V
483 w[1] = u[2]*v[0] - v[2]*u[0];
484 w[2] = u[0]*v[1] - v[0]*u[1];
486 m[0] = u[0]; m[4] = v[0]; m[8] = w[0]; m[12] = 0; // |Ux Vx Wx|
487 m[1] = u[1]; m[5] = v[1]; m[9] = w[1]; m[13] = 0; // m = |Uy Vy Wy|
488 m[2] = u[2]; m[6] = v[2]; m[10] = w[2]; m[14] = 0; // |Uz Vz Wz|
489 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
492 // Finally, a scaling factor to map the panel's width and height
493 // to the unit square.
494 glScalef(1./_width, 1./_height, 1);
496 // Now, turn off the Z buffer. The panel code doesn't need
497 // it, and we're using different clip planes anyway (meaning we
498 // can't share it without glDepthRange() hackery or much
499 // framebuffer bandwidth wasteage)
500 glDisable(GL_DEPTH_TEST);
504 FGPanel::cleanupVirtualCockpit()
506 glMatrixMode(GL_PROJECTION);
508 glMatrixMode(GL_MODELVIEW);
510 glEnable(GL_DEPTH_TEST);
515 * Set the panel's visibility.
518 FGPanel::setVisibility (bool visibility)
520 _visibility = visibility;
525 * Return true if the panel is visible.
528 FGPanel::getVisibility () const
535 * Set the panel's background texture.
538 FGPanel::setBackground (ssgTexture * texture)
544 * Set the panel's multiple background textures.
547 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
554 * Set the panel's x-offset.
557 FGPanel::setXOffset (int offset)
559 if (offset <= 0 && offset >= -_width + WIN_W)
565 * Set the panel's y-offset.
568 FGPanel::setYOffset (int offset)
570 if (offset <= 0 && offset >= -_height)
576 * Perform a mouse action.
579 FGPanel::doMouseAction (int button, int updown, int x, int y)
581 // FIXME: this same code appears in update()
582 int xsize = _xsize_node->getIntValue();
583 int ysize = _ysize_node->getIntValue();
584 float aspect_adjust = get_aspect_adjust(xsize, ysize);
586 // Note a released button and return
587 // cerr << "Doing mouse action\n";
590 _mouseInstrument = 0;
594 // Scale for the real window size.
595 if (aspect_adjust < 1.0) {
596 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
597 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
599 x = int(((float)x / xsize) * WIN_W);
600 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
603 // Adjust for offsets.
607 // Search for a matching instrument.
608 for (int i = 0; i < (int)_instruments.size(); i++) {
609 FGPanelInstrument *inst = _instruments[i];
610 int ix = inst->getXPos();
611 int iy = inst->getYPos();
612 int iw = inst->getWidth() / 2;
613 int ih = inst->getHeight() / 2;
614 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
617 _mouseInstrument = inst;
618 _mouseButton = button;
621 // Always do the action once.
622 _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
631 ////////////////////////////////////////////////////////////////////////.
632 // Implementation of FGPanelAction.
633 ////////////////////////////////////////////////////////////////////////
635 FGPanelAction::FGPanelAction ()
639 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h)
640 : _button(button), _x(x), _y(y), _w(w), _h(h)
642 for (unsigned int i = 0; i < _bindings.size(); i++)
646 FGPanelAction::~FGPanelAction ()
651 FGPanelAction::addBinding (FGBinding * binding)
653 _bindings.push_back(binding);
657 FGPanelAction::doAction ()
660 int nBindings = _bindings.size();
661 for (int i = 0; i < nBindings; i++) {
662 _bindings[i]->fire();
669 ////////////////////////////////////////////////////////////////////////
670 // Implementation of FGPanelTransformation.
671 ////////////////////////////////////////////////////////////////////////
673 FGPanelTransformation::FGPanelTransformation ()
678 FGPanelTransformation::~FGPanelTransformation ()
685 ////////////////////////////////////////////////////////////////////////
686 // Implementation of FGPanelInstrument.
687 ////////////////////////////////////////////////////////////////////////
690 FGPanelInstrument::FGPanelInstrument ()
696 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
702 FGPanelInstrument::~FGPanelInstrument ()
704 for (action_list_type::iterator it = _actions.begin();
705 it != _actions.end();
713 FGPanelInstrument::setPosition (int x, int y)
720 FGPanelInstrument::setSize (int w, int h)
727 FGPanelInstrument::getXPos () const
733 FGPanelInstrument::getYPos () const
739 FGPanelInstrument::getWidth () const
745 FGPanelInstrument::getHeight () const
751 FGPanelInstrument::addAction (FGPanelAction * action)
753 _actions.push_back(action);
756 // Coordinates relative to centre.
758 FGPanelInstrument::doMouseAction (int button, int x, int y)
761 action_list_type::iterator it = _actions.begin();
762 action_list_type::iterator last = _actions.end();
763 for ( ; it != last; it++) {
764 if ((*it)->inArea(button, x, y)) {
775 ////////////////////////////////////////////////////////////////////////
776 // Implementation of FGLayeredInstrument.
777 ////////////////////////////////////////////////////////////////////////
779 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
780 : FGPanelInstrument(x, y, w, h)
784 FGLayeredInstrument::~FGLayeredInstrument ()
786 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
793 FGLayeredInstrument::draw ()
796 for (int i = 0; i < (int)_layers.size(); i++) {
798 if(!fgGetBool("/sim/virtual-cockpit"))
799 glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
807 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
809 int n = _layers.size();
810 if (layer->getWidth() == -1) {
811 layer->setWidth(getWidth());
813 if (layer->getHeight() == -1) {
814 layer->setHeight(getHeight());
816 _layers.push_back(layer);
821 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
824 return addLayer(new FGTexturedLayer(texture, w, h));
828 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
830 int layer = _layers.size() - 1;
831 _layers[layer]->addTransformation(transformation);
836 ////////////////////////////////////////////////////////////////////////
837 // Implementation of FGInstrumentLayer.
838 ////////////////////////////////////////////////////////////////////////
840 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
846 FGInstrumentLayer::~FGInstrumentLayer ()
848 for (transformation_list::iterator it = _transformations.begin();
849 it != _transformations.end();
857 FGInstrumentLayer::transform () const
859 transformation_list::const_iterator it = _transformations.begin();
860 transformation_list::const_iterator last = _transformations.end();
862 FGPanelTransformation *t = *it;
864 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
867 } else if (val > t->max) {
871 val = val * t->factor + t->offset;
873 val = t->table->interpolate(val) * t->factor + t->offset;
877 case FGPanelTransformation::XSHIFT:
878 glTranslatef(val, 0.0, 0.0);
880 case FGPanelTransformation::YSHIFT:
881 glTranslatef(0.0, val, 0.0);
883 case FGPanelTransformation::ROTATION:
884 glRotatef(-val, 0.0, 0.0, 1.0);
893 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
895 _transformations.push_back(transformation);
900 ////////////////////////////////////////////////////////////////////////
901 // Implementation of FGGroupLayer.
902 ////////////////////////////////////////////////////////////////////////
904 FGGroupLayer::FGGroupLayer ()
908 FGGroupLayer::~FGGroupLayer ()
910 for (unsigned int i = 0; i < _layers.size(); i++)
915 FGGroupLayer::draw ()
918 int nLayers = _layers.size();
919 for (int i = 0; i < nLayers; i++)
925 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
927 _layers.push_back(layer);
932 ////////////////////////////////////////////////////////////////////////
933 // Implementation of FGTexturedLayer.
934 ////////////////////////////////////////////////////////////////////////
937 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
938 : FGInstrumentLayer(w, h)
944 FGTexturedLayer::~FGTexturedLayer ()
950 FGTexturedLayer::draw ()
957 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
960 // From Curt: turn on the panel
961 // lights after sundown.
962 if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
963 glColor4fv( cur_light_params.scene_diffuse );
965 glColor4f(0.7, 0.2, 0.2, 1.0);
969 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
970 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
971 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
972 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
979 ////////////////////////////////////////////////////////////////////////
980 // Implementation of FGTextLayer.
981 ////////////////////////////////////////////////////////////////////////
983 FGTextLayer::FGTextLayer (int w, int h)
984 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
987 _color[0] = _color[1] = _color[2] = 0.0;
991 FGTextLayer::~FGTextLayer ()
993 chunk_list::iterator it = _chunks.begin();
994 chunk_list::iterator last = _chunks.end();
995 for ( ; it != last; it++) {
1001 FGTextLayer::draw ()
1007 if ( _font_name == "led" ) {
1008 text_renderer.setFont(led_font);
1010 text_renderer.setFont(guiFntHandle);
1012 text_renderer.setPointSize(_pointSize);
1013 text_renderer.begin();
1014 text_renderer.start3f(0, 0, 0);
1017 if (_now - _then > 100000) {
1021 text_renderer.puts((char *)(_value.c_str()));
1023 text_renderer.end();
1024 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1030 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1032 _chunks.push_back(chunk);
1036 FGTextLayer::setColor (float r, float g, float b)
1045 FGTextLayer::setPointSize (float size)
1051 FGTextLayer::setFontName(const string &name)
1058 FGTextLayer::setFont(fntFont * font)
1060 text_renderer.setFont(font);
1065 FGTextLayer::recalc_value () const
1068 chunk_list::const_iterator it = _chunks.begin();
1069 chunk_list::const_iterator last = _chunks.end();
1070 for ( ; it != last; it++) {
1071 _value += (*it)->getValue();
1077 ////////////////////////////////////////////////////////////////////////
1078 // Implementation of FGTextLayer::Chunk.
1079 ////////////////////////////////////////////////////////////////////////
1081 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1082 : _type(FGTextLayer::TEXT), _fmt(fmt)
1089 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1090 const string &fmt, float mult)
1091 : _type(type), _fmt(fmt), _mult(mult)
1094 if (type == TEXT_VALUE)
1103 FGTextLayer::Chunk::getValue () const
1108 sprintf(_buf, _fmt.c_str(), _text.c_str());
1111 sprintf(_buf, _fmt.c_str(), _node->getStringValue().c_str());
1114 sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
1125 ////////////////////////////////////////////////////////////////////////
1126 // Implementation of FGSwitchLayer.
1127 ////////////////////////////////////////////////////////////////////////
1129 FGSwitchLayer::FGSwitchLayer (int w, int h, const SGPropertyNode * node,
1130 FGInstrumentLayer * layer1,
1131 FGInstrumentLayer * layer2)
1132 : FGInstrumentLayer(w, h), _node(node), _layer1(layer1), _layer2(layer2)
1136 FGSwitchLayer::~FGSwitchLayer ()
1143 FGSwitchLayer::draw ()
1147 if (_node->getBoolValue()) {