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 return (fgGetBool("/sim/virtual-cockpit") ||
87 ((current_panel != 0) &&
88 (current_panel->getVisibility()) &&
89 (globals->get_viewmgr()->get_current() == 0) &&
90 (globals->get_current_view()->get_view_offset() == 0.0)));
95 ////////////////////////////////////////////////////////////////////////
96 // Implementation of FGTextureManager.
97 ////////////////////////////////////////////////////////////////////////
99 map<string,ssgTexture *> FGTextureManager::_textureMap;
102 FGTextureManager::createTexture (const string &relativePath)
104 ssgTexture * texture = _textureMap[relativePath];
106 SG_LOG( SG_COCKPIT, SG_DEBUG,
107 "Texture " << relativePath << " does not yet exist" );
108 SGPath tpath(globals->get_fg_root());
109 tpath.append(relativePath);
110 texture = new ssgTexture((char *)tpath.c_str(), false, false);
111 _textureMap[relativePath] = texture;
112 if (_textureMap[relativePath] == 0)
113 SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
114 SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
115 << " handle=" << texture->getHandle() );
124 ////////////////////////////////////////////////////////////////////////
125 // Implementation of FGCropped Texture.
126 ////////////////////////////////////////////////////////////////////////
129 FGCroppedTexture::FGCroppedTexture ()
130 : _path(""), _texture(0),
131 _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
136 FGCroppedTexture::FGCroppedTexture (const string &path,
137 float minX, float minY,
138 float maxX, float maxY)
139 : _path(path), _texture(0),
140 _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
145 FGCroppedTexture::~FGCroppedTexture ()
151 FGCroppedTexture::getTexture ()
154 _texture = FGTextureManager::createTexture(_path);
161 ////////////////////////////////////////////////////////////////////////
162 // Implementation of FGPanel.
163 ////////////////////////////////////////////////////////////////////////
165 FGPanel * current_panel = NULL;
166 static fntRenderer text_renderer;
167 static fntTexFont *default_font;
168 static fntTexFont *led_font;
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)),
180 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
181 _ysize_node(fgGetNode("/sim/startup/ysize", true))
183 setVisibility(fgPanelVisible());
194 for (instrument_list_type::iterator it = _instruments.begin();
195 it != _instruments.end();
204 * Add an instrument to the panel.
207 FGPanel::addInstrument (FGPanelInstrument * instrument)
209 _instruments.push_back(instrument);
214 * Initialize the panel.
220 char* envp = ::getenv( "FG_FONTS" );
221 if ( envp != NULL ) {
222 base_path.set( envp );
224 base_path.set( globals->get_fg_root() );
225 base_path.append( "Fonts" );
230 // Install the default font
232 fntpath.append( "typewriter.txf" );
233 default_font = new fntTexFont ;
234 default_font -> load ( (char *)fntpath.c_str() ) ;
236 // Install the LED font
238 fntpath.append( "led.txf" );
239 led_font = new fntTexFont ;
240 led_font -> load ( (char *)fntpath.c_str() ) ;
245 * Bind panel properties.
250 fgTie("/sim/panel/visibility", &_visibility);
251 fgSetArchivable("/sim/panel/visibility");
252 fgTie("/sim/panel/x-offset", &_x_offset);
253 fgSetArchivable("/sim/panel/x-offset");
254 fgTie("/sim/panel/y-offset", &_y_offset);
255 fgSetArchivable("/sim/panel/y-offset");
256 fgTie("/sim/panel/jitter", &_jitter);
257 fgSetArchivable("/sim/panel/jitter");
263 * Unbind panel properties.
268 fgUntie("/sim/panel/visibility");
269 fgUntie("/sim/panel/x-offset");
270 fgUntie("/sim/panel/y-offset");
279 FGPanel::update (int dt)
281 // Do nothing if the panel isn't visible.
282 if ( !fgPanelVisible() ) {
286 // If the mouse is down, do something
289 if (_mouseDelay < 0) {
290 _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
295 // Now, draw the panel
296 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
297 _ysize_node->getIntValue());
298 if (aspect_adjust <1.0)
299 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
301 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
306 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
308 // Calculate accelerations
309 // and jiggle the panel accordingly
310 // The factors and bounds are just
311 // initial guesses; using sqrt smooths
313 double x_offset = _x_offset;
314 double y_offset = _y_offset;
316 if (_jitter != 0.0) {
317 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
318 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
319 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
321 double a_zx_pilot = a_z_pilot - a_x_pilot;
323 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter)) *
324 (a_y_pilot < 0 ? -1 : 1);
325 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter)) *
326 (a_zx_pilot < 0 ? -1 : 1);
328 // adjustments in screen coordinates
329 x_offset += x_adjust;
330 y_offset += y_adjust;
333 if(fgGetBool("/sim/virtual-cockpit")) {
334 setupVirtualCockpit();
336 glMatrixMode(GL_PROJECTION);
339 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
340 // gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
342 glMatrixMode(GL_MODELVIEW);
346 glTranslated(x_offset, y_offset, 0);
349 // Draw the background
350 glEnable(GL_TEXTURE_2D);
351 glDisable(GL_LIGHTING);
353 glEnable(GL_ALPHA_TEST);
354 glEnable(GL_COLOR_MATERIAL);
355 // glColor4f(1.0, 1.0, 1.0, 1.0);
356 if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
357 glColor4fv( cur_light_params.scene_diffuse );
359 glColor4f(0.7, 0.2, 0.2, 1.0);
362 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
363 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
364 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
365 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
367 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
368 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
369 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
370 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
373 for (int i = 0; i < 4; i ++) {
374 // top row of textures...(1,3,5,7)
375 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
376 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
378 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
379 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
380 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + _height, 0);
381 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + _height, 0);
383 // bottom row of textures...(2,4,6,8)
384 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
385 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
387 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y, 0);
388 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y, 0);
389 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
390 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
396 // Draw the instruments.
397 instrument_list_type::const_iterator current = _instruments.begin();
398 instrument_list_type::const_iterator end = _instruments.end();
400 for ( ; current != end; current++) {
401 FGPanelInstrument * instr = *current;
403 glTranslated(instr->getXPos(), instr->getYPos(), 0);
408 if(fgGetBool("/sim/virtual-cockpit")) {
409 cleanupVirtualCockpit();
411 glMatrixMode(GL_PROJECTION);
413 glMatrixMode(GL_MODELVIEW);
417 ssgForceBasicState();
418 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
422 FGPanel::setupVirtualCockpit()
425 FGViewer* view = globals->get_current_view();
427 // Generate corners for the panel quad. Put the top edge of the
428 // panel 1m in and 6 degrees down from the forward direction, and
429 // make the whole thing 60 degrees wide. In principle, these
430 // should be settable per-panel, so that you can have lots of
431 // panel objects plastered about the cockpit in realistic
432 // positions and orientations.
433 float a[3], b[3], c[3];
434 float pw = tan(30*SGD_DEGREES_TO_RADIANS);
435 float ph = 2 * pw * (float)_height/(float)_width;
436 float ptop = -tan(6*SGD_DEGREES_TO_RADIANS);
437 a[0] = -pw; a[1] = ptop-ph; a[2] = -1; // bottom left
438 b[0] = pw; b[1] = ptop-ph; b[2] = -1; // bottom right
439 c[0] = -pw; c[1] = ptop; c[2] = -1; // top left
441 // A standard projection, in meters, with especially close clip
443 glMatrixMode(GL_PROJECTION);
446 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(),
449 glMatrixMode(GL_MODELVIEW);
453 // Generate a "look at" matrix using OpenGL (!) coordinate
456 float pitch = view->get_view_tilt();
457 float rot = view->get_view_offset();
458 lookat[0] = -sin(rot);
459 lookat[1] = sin(pitch) / cos(pitch);
460 lookat[2] = -cos(rot);
461 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
462 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
464 // Translate the origin to the location of the panel quad
465 glTranslatef(a[0], a[1], a[2]);
467 // Generate a matrix to translate unit square coordinates from the
468 // panel to real world coordinates. Use a transposed basis for
469 // the panel quad. Note: this matrix is relatively expensive to
470 // compute, and is invariant. Consider precomputing and storing
471 // it. Also, consider using the plib vector math routines, so the
472 // reuse junkies don't yell at me. (Fine, I hard-coded a cross
473 // product. Just shoot me and be done with it.)
474 float u[3], v[3], w[3], m[16];
475 for(i=0; i<3; i++) u[i] = b[i] - a[i]; // U = B - A
476 for(i=0; i<3; i++) v[i] = c[i] - a[i]; // V = C - A
477 w[0] = u[1]*v[2] - v[1]*u[2]; // W = U x V
478 w[1] = u[2]*v[0] - v[2]*u[0];
479 w[2] = u[0]*v[1] - v[0]*u[1];
481 m[0] = u[0]; m[4] = v[0]; m[8] = w[0]; m[12] = 0; // |Ux Vx Wx|
482 m[1] = u[1]; m[5] = v[1]; m[9] = w[1]; m[13] = 0; // m = |Uy Vy Wy|
483 m[2] = u[2]; m[6] = v[2]; m[10] = w[2]; m[14] = 0; // |Uz Vz Wz|
484 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
487 // Finally, a scaling factor to map the panel's width and height
488 // to the unit square.
489 glScalef(1./_width, 1./_height, 1);
491 // Now, turn off the Z buffer. The panel code doesn't need
492 // it, and we're using different clip planes anyway (meaning we
493 // can't share it without glDepthRange() hackery or much
494 // framebuffer bandwidth wasteage)
495 glDisable(GL_DEPTH_TEST);
499 FGPanel::cleanupVirtualCockpit()
501 glMatrixMode(GL_PROJECTION);
503 glMatrixMode(GL_MODELVIEW);
505 glEnable(GL_DEPTH_TEST);
510 * Set the panel's visibility.
513 FGPanel::setVisibility (bool visibility)
515 _visibility = visibility;
520 * Return true if the panel is visible.
523 FGPanel::getVisibility () const
530 * Set the panel's background texture.
533 FGPanel::setBackground (ssgTexture * texture)
539 * Set the panel's multiple background textures.
542 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
549 * Set the panel's x-offset.
552 FGPanel::setXOffset (int offset)
554 if (offset <= 0 && offset >= -_width + WIN_W)
560 * Set the panel's y-offset.
563 FGPanel::setYOffset (int offset)
565 if (offset <= 0 && offset >= -_height)
571 * Perform a mouse action.
574 FGPanel::doMouseAction (int button, int updown, int x, int y)
576 // FIXME: this same code appears in update()
577 int xsize = _xsize_node->getIntValue();
578 int ysize = _ysize_node->getIntValue();
579 float aspect_adjust = get_aspect_adjust(xsize, ysize);
581 // Note a released button and return
582 // cerr << "Doing mouse action\n";
585 _mouseInstrument = 0;
589 // Scale for the real window size.
590 if (aspect_adjust < 1.0) {
591 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
592 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
594 x = int(((float)x / xsize) * WIN_W);
595 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
598 // Adjust for offsets.
602 // Search for a matching instrument.
603 for (int i = 0; i < (int)_instruments.size(); i++) {
604 FGPanelInstrument *inst = _instruments[i];
605 int ix = inst->getXPos();
606 int iy = inst->getYPos();
607 int iw = inst->getWidth() / 2;
608 int ih = inst->getHeight() / 2;
609 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
612 _mouseInstrument = inst;
613 _mouseButton = button;
616 // Always do the action once.
617 _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
626 ////////////////////////////////////////////////////////////////////////.
627 // Implementation of FGPanelAction.
628 ////////////////////////////////////////////////////////////////////////
630 FGPanelAction::FGPanelAction ()
634 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h)
635 : _button(button), _x(x), _y(y), _w(w), _h(h)
637 for (unsigned int i = 0; i < _bindings.size(); i++)
641 FGPanelAction::~FGPanelAction ()
646 FGPanelAction::addBinding (FGBinding * binding)
648 _bindings.push_back(binding);
652 FGPanelAction::doAction ()
655 int nBindings = _bindings.size();
656 for (int i = 0; i < nBindings; i++) {
657 _bindings[i]->fire();
664 ////////////////////////////////////////////////////////////////////////
665 // Implementation of FGPanelTransformation.
666 ////////////////////////////////////////////////////////////////////////
668 FGPanelTransformation::FGPanelTransformation ()
673 FGPanelTransformation::~FGPanelTransformation ()
680 ////////////////////////////////////////////////////////////////////////
681 // Implementation of FGPanelInstrument.
682 ////////////////////////////////////////////////////////////////////////
685 FGPanelInstrument::FGPanelInstrument ()
691 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
697 FGPanelInstrument::~FGPanelInstrument ()
699 for (action_list_type::iterator it = _actions.begin();
700 it != _actions.end();
708 FGPanelInstrument::setPosition (int x, int y)
715 FGPanelInstrument::setSize (int w, int h)
722 FGPanelInstrument::getXPos () const
728 FGPanelInstrument::getYPos () const
734 FGPanelInstrument::getWidth () const
740 FGPanelInstrument::getHeight () const
746 FGPanelInstrument::addAction (FGPanelAction * action)
748 _actions.push_back(action);
751 // Coordinates relative to centre.
753 FGPanelInstrument::doMouseAction (int button, int x, int y)
756 action_list_type::iterator it = _actions.begin();
757 action_list_type::iterator last = _actions.end();
758 for ( ; it != last; it++) {
759 if ((*it)->inArea(button, x, y)) {
770 ////////////////////////////////////////////////////////////////////////
771 // Implementation of FGLayeredInstrument.
772 ////////////////////////////////////////////////////////////////////////
774 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
775 : FGPanelInstrument(x, y, w, h)
779 FGLayeredInstrument::~FGLayeredInstrument ()
781 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
788 FGLayeredInstrument::draw ()
791 for (int i = 0; i < (int)_layers.size(); i++) {
793 if(!fgGetBool("/sim/virtual-cockpit"))
794 glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
802 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
804 int n = _layers.size();
805 if (layer->getWidth() == -1) {
806 layer->setWidth(getWidth());
808 if (layer->getHeight() == -1) {
809 layer->setHeight(getHeight());
811 _layers.push_back(layer);
816 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
819 return addLayer(new FGTexturedLayer(texture, w, h));
823 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
825 int layer = _layers.size() - 1;
826 _layers[layer]->addTransformation(transformation);
831 ////////////////////////////////////////////////////////////////////////
832 // Implementation of FGInstrumentLayer.
833 ////////////////////////////////////////////////////////////////////////
835 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
841 FGInstrumentLayer::~FGInstrumentLayer ()
843 for (transformation_list::iterator it = _transformations.begin();
844 it != _transformations.end();
852 FGInstrumentLayer::transform () const
854 transformation_list::const_iterator it = _transformations.begin();
855 transformation_list::const_iterator last = _transformations.end();
857 FGPanelTransformation *t = *it;
859 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
862 } else if (val > t->max) {
866 val = val * t->factor + t->offset;
868 val = t->table->interpolate(val) * t->factor + t->offset;
872 case FGPanelTransformation::XSHIFT:
873 glTranslatef(val, 0.0, 0.0);
875 case FGPanelTransformation::YSHIFT:
876 glTranslatef(0.0, val, 0.0);
878 case FGPanelTransformation::ROTATION:
879 glRotatef(-val, 0.0, 0.0, 1.0);
888 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
890 _transformations.push_back(transformation);
895 ////////////////////////////////////////////////////////////////////////
896 // Implementation of FGGroupLayer.
897 ////////////////////////////////////////////////////////////////////////
899 FGGroupLayer::FGGroupLayer ()
903 FGGroupLayer::~FGGroupLayer ()
905 for (unsigned int i = 0; i < _layers.size(); i++)
910 FGGroupLayer::draw ()
913 int nLayers = _layers.size();
914 for (int i = 0; i < nLayers; i++)
920 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
922 _layers.push_back(layer);
927 ////////////////////////////////////////////////////////////////////////
928 // Implementation of FGTexturedLayer.
929 ////////////////////////////////////////////////////////////////////////
932 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
933 : FGInstrumentLayer(w, h)
939 FGTexturedLayer::~FGTexturedLayer ()
945 FGTexturedLayer::draw ()
952 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
955 // From Curt: turn on the panel
956 // lights after sundown.
957 if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
958 glColor4fv( cur_light_params.scene_diffuse );
960 glColor4f(0.7, 0.2, 0.2, 1.0);
964 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
965 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
966 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
967 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
974 ////////////////////////////////////////////////////////////////////////
975 // Implementation of FGTextLayer.
976 ////////////////////////////////////////////////////////////////////////
978 FGTextLayer::FGTextLayer (int w, int h)
979 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
982 _color[0] = _color[1] = _color[2] = 0.0;
986 FGTextLayer::~FGTextLayer ()
988 chunk_list::iterator it = _chunks.begin();
989 chunk_list::iterator last = _chunks.end();
990 for ( ; it != last; it++) {
1002 if ( _font_name == "led" ) {
1003 text_renderer.setFont(led_font);
1005 text_renderer.setFont(guiFntHandle);
1007 text_renderer.setPointSize(_pointSize);
1008 text_renderer.begin();
1009 text_renderer.start3f(0, 0, 0);
1012 if (_now - _then > 100000) {
1016 text_renderer.puts((char *)(_value.c_str()));
1018 text_renderer.end();
1019 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1025 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1027 _chunks.push_back(chunk);
1031 FGTextLayer::setColor (float r, float g, float b)
1040 FGTextLayer::setPointSize (float size)
1046 FGTextLayer::setFontName(const string &name)
1053 FGTextLayer::setFont(fntFont * font)
1055 text_renderer.setFont(font);
1060 FGTextLayer::recalc_value () const
1063 chunk_list::const_iterator it = _chunks.begin();
1064 chunk_list::const_iterator last = _chunks.end();
1065 for ( ; it != last; it++) {
1066 _value += (*it)->getValue();
1072 ////////////////////////////////////////////////////////////////////////
1073 // Implementation of FGTextLayer::Chunk.
1074 ////////////////////////////////////////////////////////////////////////
1076 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1077 : _type(FGTextLayer::TEXT), _fmt(fmt)
1084 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1085 const string &fmt, float mult)
1086 : _type(type), _fmt(fmt), _mult(mult)
1089 if (type == TEXT_VALUE)
1098 FGTextLayer::Chunk::getValue () const
1103 sprintf(_buf, _fmt.c_str(), _text.c_str());
1106 sprintf(_buf, _fmt.c_str(), _node->getStringValue().c_str());
1109 sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
1120 ////////////////////////////////////////////////////////////////////////
1121 // Implementation of FGSwitchLayer.
1122 ////////////////////////////////////////////////////////////////////////
1124 FGSwitchLayer::FGSwitchLayer (int w, int h, const SGPropertyNode * node,
1125 FGInstrumentLayer * layer1,
1126 FGInstrumentLayer * layer2)
1127 : FGInstrumentLayer(w, h), _node(node), _layer1(layer1), _layer2(layer2)
1131 FGSwitchLayer::~FGSwitchLayer ()
1138 FGSwitchLayer::draw ()
1142 if (_node->getBoolValue()) {