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()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 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)),
184 _xsize_node(fgGetNode("/sim/startup/xsize", true)),
185 _ysize_node(fgGetNode("/sim/startup/ysize", true))
187 setVisibility(fgPanelVisible());
196 for (instrument_list_type::iterator it = _instruments.begin();
197 it != _instruments.end();
206 * Add an instrument to the panel.
209 FGPanel::addInstrument (FGPanelInstrument * instrument)
211 _instruments.push_back(instrument);
216 * Initialize the panel.
222 char* envp = ::getenv( "FG_FONTS" );
223 if ( envp != NULL ) {
224 base_path.set( envp );
226 base_path.set( globals->get_fg_root() );
227 base_path.append( "Fonts" );
232 // Install the default font
234 fntpath.append( "typewriter.txf" );
235 default_font = new fntTexFont ;
236 default_font -> load ( (char *)fntpath.c_str() ) ;
238 // Install the LED font
240 fntpath.append( "led.txf" );
241 led_font = new fntTexFont ;
242 led_font -> load ( (char *)fntpath.c_str() ) ;
247 * Bind panel properties.
252 fgSetArchivable("/sim/panel/visibility");
253 fgSetArchivable("/sim/panel/x-offset");
254 fgSetArchivable("/sim/panel/y-offset");
255 fgSetArchivable("/sim/panel/jitter");
260 * Unbind panel properties.
272 FGPanel::update (int dt)
274 // TODO: cache the nodes
275 _visibility = fgGetBool("/sim/panel/visibility");
276 _x_offset = fgGetInt("/sim/panel/x-offset");
277 _y_offset = fgGetInt("/sim/panel/y-offset");
278 _jitter = fgGetFloat("/sim/panel/jitter");
280 // Do nothing if the panel isn't visible.
281 if ( !fgPanelVisible() ) {
285 // If the mouse is down, do something
288 if (_mouseDelay < 0) {
289 _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
294 // Now, draw the panel
295 float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
296 _ysize_node->getIntValue());
297 if (aspect_adjust <1.0)
298 update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
300 update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
305 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
307 // Calculate accelerations
308 // and jiggle the panel accordingly
309 // The factors and bounds are just
310 // initial guesses; using sqrt smooths
312 double x_offset = _x_offset;
313 double y_offset = _y_offset;
315 if (_jitter != 0.0) {
316 double a_x_pilot = current_aircraft.fdm_state->get_A_X_pilot();
317 double a_y_pilot = current_aircraft.fdm_state->get_A_Y_pilot();
318 double a_z_pilot = current_aircraft.fdm_state->get_A_Z_pilot();
320 double a_zx_pilot = a_z_pilot - a_x_pilot;
322 int x_adjust = int(sqrt(fabs(a_y_pilot) * _jitter)) *
323 (a_y_pilot < 0 ? -1 : 1);
324 int y_adjust = int(sqrt(fabs(a_zx_pilot) * _jitter)) *
325 (a_zx_pilot < 0 ? -1 : 1);
327 // adjustments in screen coordinates
328 x_offset += x_adjust;
329 y_offset += y_adjust;
332 if(fgGetBool("/sim/virtual-cockpit")) {
333 setupVirtualCockpit();
335 glMatrixMode(GL_PROJECTION);
338 gluOrtho2D(winx, winx + winw, winy, winy + winh); /* right side up */
339 // gluOrtho2D(winx + winw, winx, winy + winh, winy); /* up side down */
341 glMatrixMode(GL_MODELVIEW);
345 glTranslated(x_offset, y_offset, 0);
348 // Draw the background
349 glEnable(GL_TEXTURE_2D);
350 glDisable(GL_LIGHTING);
352 glEnable(GL_ALPHA_TEST);
353 glEnable(GL_COLOR_MATERIAL);
354 // glColor4f(1.0, 1.0, 1.0, 1.0);
355 if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
356 glColor4fv( cur_light_params.scene_diffuse );
358 glColor4f(0.7, 0.2, 0.2, 1.0);
361 glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
362 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
363 // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
364 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
366 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
367 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
368 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
369 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
372 for (int i = 0; i < 4; i ++) {
373 // top row of textures...(1,3,5,7)
374 glBindTexture(GL_TEXTURE_2D, _mbg[i*2]->getHandle());
375 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
377 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
378 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
379 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + _height, 0);
380 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + _height, 0);
382 // bottom row of textures...(2,4,6,8)
383 glBindTexture(GL_TEXTURE_2D, _mbg[(i*2)+1]->getHandle());
384 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
386 glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y, 0);
387 glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y, 0);
388 glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + (_width/4) * (i+1), WIN_Y + (_height/2), 0);
389 glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X + (_width/4) * i, WIN_Y + (_height/2), 0);
395 // Draw the instruments.
396 instrument_list_type::const_iterator current = _instruments.begin();
397 instrument_list_type::const_iterator end = _instruments.end();
399 for ( ; current != end; current++) {
400 FGPanelInstrument * instr = *current;
402 glTranslated(instr->getXPos(), instr->getYPos(), 0);
407 if(fgGetBool("/sim/virtual-cockpit")) {
408 cleanupVirtualCockpit();
410 glMatrixMode(GL_PROJECTION);
412 glMatrixMode(GL_MODELVIEW);
416 ssgForceBasicState();
417 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
421 FGPanel::setupVirtualCockpit()
424 FGViewer* view = globals->get_current_view();
426 // Generate corners for the panel quad. Put the top edge of the
427 // panel 1m in and 6 degrees down from the forward direction, and
428 // make the whole thing 60 degrees wide. In principle, these
429 // should be settable per-panel, so that you can have lots of
430 // panel objects plastered about the cockpit in realistic
431 // positions and orientations.
432 float a[3], b[3], c[3];
433 float pw = tan(30*SGD_DEGREES_TO_RADIANS);
434 float ph = 2 * pw * (float)_height/(float)_width;
435 float ptop = -tan(6*SGD_DEGREES_TO_RADIANS);
436 a[0] = -pw; a[1] = ptop-ph; a[2] = -1; // bottom left
437 b[0] = pw; b[1] = ptop-ph; b[2] = -1; // bottom right
438 c[0] = -pw; c[1] = ptop; c[2] = -1; // top left
440 // A standard projection, in meters, with especially close clip
442 glMatrixMode(GL_PROJECTION);
445 gluPerspective(view->get_v_fov(), 1/view->get_aspect_ratio(),
448 glMatrixMode(GL_MODELVIEW);
452 // Generate a "look at" matrix using OpenGL (!) coordinate
455 float pitch = view->getPitchOffset_deg() * SGD_DEGREES_TO_RADIANS;
456 float rot = view->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
457 lookat[0] = -sin(rot);
458 lookat[1] = sin(pitch) / cos(pitch);
459 lookat[2] = -cos(rot);
460 if(fabs(lookat[1]) > 9999) lookat[1] = 9999; // FPU sanity
461 gluLookAt(0, 0, 0, lookat[0], lookat[1], lookat[2], 0, 1, 0);
463 // Translate the origin to the location of the panel quad
464 glTranslatef(a[0], a[1], a[2]);
466 // Generate a matrix to translate unit square coordinates from the
467 // panel to real world coordinates. Use a transposed basis for
468 // the panel quad. Note: this matrix is relatively expensive to
469 // compute, and is invariant. Consider precomputing and storing
470 // it. Also, consider using the plib vector math routines, so the
471 // reuse junkies don't yell at me. (Fine, I hard-coded a cross
472 // product. Just shoot me and be done with it.)
473 float u[3], v[3], w[3], m[16];
474 for(i=0; i<3; i++) u[i] = b[i] - a[i]; // U = B - A
475 for(i=0; i<3; i++) v[i] = c[i] - a[i]; // V = C - A
476 w[0] = u[1]*v[2] - v[1]*u[2]; // W = U x V
477 w[1] = u[2]*v[0] - v[2]*u[0];
478 w[2] = u[0]*v[1] - v[0]*u[1];
480 m[0] = u[0]; m[4] = v[0]; m[8] = w[0]; m[12] = 0; // |Ux Vx Wx|
481 m[1] = u[1]; m[5] = v[1]; m[9] = w[1]; m[13] = 0; // m = |Uy Vy Wy|
482 m[2] = u[2]; m[6] = v[2]; m[10] = w[2]; m[14] = 0; // |Uz Vz Wz|
483 m[3] = 0; m[7] = 0; m[11] = 0; m[15] = 1;
486 // Finally, a scaling factor to map the panel's width and height
487 // to the unit square.
488 glScalef(1./_width, 1./_height, 1);
490 // Now, turn off the Z buffer. The panel code doesn't need
491 // it, and we're using different clip planes anyway (meaning we
492 // can't share it without glDepthRange() hackery or much
493 // framebuffer bandwidth wasteage)
494 glDisable(GL_DEPTH_TEST);
498 FGPanel::cleanupVirtualCockpit()
500 glMatrixMode(GL_PROJECTION);
502 glMatrixMode(GL_MODELVIEW);
504 glEnable(GL_DEPTH_TEST);
509 * Set the panel's visibility.
512 FGPanel::setVisibility (bool visibility)
514 _visibility = visibility;
519 * Return true if the panel is visible.
522 FGPanel::getVisibility () const
529 * Set the panel's background texture.
532 FGPanel::setBackground (ssgTexture * texture)
538 * Set the panel's multiple background textures.
541 FGPanel::setMultiBackground (ssgTexture * texture, int idx)
548 * Set the panel's x-offset.
551 FGPanel::setXOffset (int offset)
553 if (offset <= 0 && offset >= -_width + WIN_W)
559 * Set the panel's y-offset.
562 FGPanel::setYOffset (int offset)
564 if (offset <= 0 && offset >= -_height)
570 * Perform a mouse action.
573 FGPanel::doMouseAction (int button, int updown, int x, int y)
575 // FIXME: this same code appears in update()
576 int xsize = _xsize_node->getIntValue();
577 int ysize = _ysize_node->getIntValue();
578 float aspect_adjust = get_aspect_adjust(xsize, ysize);
580 // Note a released button and return
581 // cerr << "Doing mouse action\n";
584 _mouseInstrument = 0;
588 // Scale for the real window size.
589 if (aspect_adjust < 1.0) {
590 x = int(((float)x / xsize) * WIN_W * aspect_adjust);
591 y = int(WIN_H - ((float(y) / ysize) * WIN_H));
593 x = int(((float)x / xsize) * WIN_W);
594 y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
597 // Adjust for offsets.
601 // Search for a matching instrument.
602 for (int i = 0; i < (int)_instruments.size(); i++) {
603 FGPanelInstrument *inst = _instruments[i];
604 int ix = inst->getXPos();
605 int iy = inst->getYPos();
606 int iw = inst->getWidth() / 2;
607 int ih = inst->getHeight() / 2;
608 if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
611 _mouseInstrument = inst;
612 _mouseButton = button;
615 // Always do the action once.
616 return _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
624 ////////////////////////////////////////////////////////////////////////.
625 // Implementation of FGPanelAction.
626 ////////////////////////////////////////////////////////////////////////
628 FGPanelAction::FGPanelAction ()
632 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h)
633 : _button(button), _x(x), _y(y), _w(w), _h(h)
635 for (unsigned int i = 0; i < _bindings.size(); i++)
639 FGPanelAction::~FGPanelAction ()
644 FGPanelAction::addBinding (FGBinding * binding)
646 _bindings.push_back(binding);
650 FGPanelAction::doAction ()
653 int nBindings = _bindings.size();
654 for (int i = 0; i < nBindings; i++) {
655 _bindings[i]->fire();
662 ////////////////////////////////////////////////////////////////////////
663 // Implementation of FGPanelTransformation.
664 ////////////////////////////////////////////////////////////////////////
666 FGPanelTransformation::FGPanelTransformation ()
671 FGPanelTransformation::~FGPanelTransformation ()
678 ////////////////////////////////////////////////////////////////////////
679 // Implementation of FGPanelInstrument.
680 ////////////////////////////////////////////////////////////////////////
683 FGPanelInstrument::FGPanelInstrument ()
689 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
695 FGPanelInstrument::~FGPanelInstrument ()
697 for (action_list_type::iterator it = _actions.begin();
698 it != _actions.end();
706 FGPanelInstrument::setPosition (int x, int y)
713 FGPanelInstrument::setSize (int w, int h)
720 FGPanelInstrument::getXPos () const
726 FGPanelInstrument::getYPos () const
732 FGPanelInstrument::getWidth () const
738 FGPanelInstrument::getHeight () const
744 FGPanelInstrument::addAction (FGPanelAction * action)
746 _actions.push_back(action);
749 // Coordinates relative to centre.
751 FGPanelInstrument::doMouseAction (int button, int x, int y)
754 action_list_type::iterator it = _actions.begin();
755 action_list_type::iterator last = _actions.end();
756 for ( ; it != last; it++) {
757 if ((*it)->inArea(button, x, y)) {
768 ////////////////////////////////////////////////////////////////////////
769 // Implementation of FGLayeredInstrument.
770 ////////////////////////////////////////////////////////////////////////
772 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
773 : FGPanelInstrument(x, y, w, h)
777 FGLayeredInstrument::~FGLayeredInstrument ()
779 for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
786 FGLayeredInstrument::draw ()
791 bool vc = fgGetBool("/sim/virtual-cockpit");
792 for (int i = 0; i < (int)_layers.size(); i++) {
795 glTranslatef(0.0, 0.0, z);
805 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
807 int n = _layers.size();
808 if (layer->getWidth() == -1) {
809 layer->setWidth(getWidth());
811 if (layer->getHeight() == -1) {
812 layer->setHeight(getHeight());
814 _layers.push_back(layer);
819 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
822 return addLayer(new FGTexturedLayer(texture, w, h));
826 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
828 int layer = _layers.size() - 1;
829 _layers[layer]->addTransformation(transformation);
834 ////////////////////////////////////////////////////////////////////////
835 // Implementation of FGInstrumentLayer.
836 ////////////////////////////////////////////////////////////////////////
838 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
844 FGInstrumentLayer::~FGInstrumentLayer ()
846 for (transformation_list::iterator it = _transformations.begin();
847 it != _transformations.end();
855 FGInstrumentLayer::transform () const
857 transformation_list::const_iterator it = _transformations.begin();
858 transformation_list::const_iterator last = _transformations.end();
860 FGPanelTransformation *t = *it;
862 float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
865 } else if (val > t->max) {
869 val = val * t->factor + t->offset;
871 val = t->table->interpolate(val) * t->factor + t->offset;
875 case FGPanelTransformation::XSHIFT:
876 glTranslatef(val, 0.0, 0.0);
878 case FGPanelTransformation::YSHIFT:
879 glTranslatef(0.0, val, 0.0);
881 case FGPanelTransformation::ROTATION:
882 glRotatef(-val, 0.0, 0.0, 1.0);
891 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
893 _transformations.push_back(transformation);
898 ////////////////////////////////////////////////////////////////////////
899 // Implementation of FGGroupLayer.
900 ////////////////////////////////////////////////////////////////////////
902 FGGroupLayer::FGGroupLayer ()
906 FGGroupLayer::~FGGroupLayer ()
908 for (unsigned int i = 0; i < _layers.size(); i++)
913 FGGroupLayer::draw ()
916 int nLayers = _layers.size();
917 for (int i = 0; i < nLayers; i++)
923 FGGroupLayer::addLayer (FGInstrumentLayer * layer)
925 _layers.push_back(layer);
930 ////////////////////////////////////////////////////////////////////////
931 // Implementation of FGTexturedLayer.
932 ////////////////////////////////////////////////////////////////////////
935 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
936 : FGInstrumentLayer(w, h)
942 FGTexturedLayer::~FGTexturedLayer ()
948 FGTexturedLayer::draw ()
955 glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
958 // From Curt: turn on the panel
959 // lights after sundown.
960 if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
961 glColor4fv( cur_light_params.scene_diffuse );
963 glColor4f(0.7, 0.2, 0.2, 1.0);
967 glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
968 glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
969 glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
970 glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
977 ////////////////////////////////////////////////////////////////////////
978 // Implementation of FGTextLayer.
979 ////////////////////////////////////////////////////////////////////////
981 FGTextLayer::FGTextLayer (int w, int h)
982 : FGInstrumentLayer(w, h), _pointSize(14.0), _font_name("default")
985 _color[0] = _color[1] = _color[2] = 0.0;
989 FGTextLayer::~FGTextLayer ()
991 chunk_list::iterator it = _chunks.begin();
992 chunk_list::iterator last = _chunks.end();
993 for ( ; it != last; it++) {
1005 if ( _font_name == "led" ) {
1006 text_renderer.setFont(led_font);
1008 text_renderer.setFont(guiFntHandle);
1010 text_renderer.setPointSize(_pointSize);
1011 text_renderer.begin();
1012 text_renderer.start3f(0, 0, 0);
1015 long diff = _now - _then;
1017 // It would be nice to keep this #ifdef'd stuff for (04/18/2002 +
1018 // a couple days) as I verify my solution to the panel text
1019 // drawing problem is actually correct. -CLO
1020 cout << "time diff = " << diff << endl;
1021 if ( _now - _then < 0 ) {
1022 cout << "Eeek, the past is now in the future!" << endl;
1023 cout << "Now = " << _now.get_seconds() << " seconds "
1024 << _now.get_usec() << "usecs" << endl;
1025 cout << "Past = " << _then.get_seconds() << " seconds "
1026 << _then.get_usec() << "usecs" << endl;
1030 if (diff > 100000 || diff < 0 ) {
1031 // ( diff < 0 ) is a sanity check and indicates our time stamp
1032 // difference math probably overflowed. We can handle a max
1033 // difference of 35.8 minutes since the returned value is in
1034 // usec. So if the panel is left off longer than that we can
1035 // over flow the math with it is turned back on. This (diff <
1036 // 0) catches that situation, get's us out of trouble, and
1041 text_renderer.puts((char *)(_value.c_str()));
1043 text_renderer.end();
1044 glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
1050 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
1052 _chunks.push_back(chunk);
1056 FGTextLayer::setColor (float r, float g, float b)
1065 FGTextLayer::setPointSize (float size)
1071 FGTextLayer::setFontName(const string &name)
1078 FGTextLayer::setFont(fntFont * font)
1080 text_renderer.setFont(font);
1085 FGTextLayer::recalc_value () const
1088 chunk_list::const_iterator it = _chunks.begin();
1089 chunk_list::const_iterator last = _chunks.end();
1090 for ( ; it != last; it++) {
1091 _value += (*it)->getValue();
1097 ////////////////////////////////////////////////////////////////////////
1098 // Implementation of FGTextLayer::Chunk.
1099 ////////////////////////////////////////////////////////////////////////
1101 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
1102 : _type(FGTextLayer::TEXT), _fmt(fmt)
1109 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
1110 const string &fmt, float mult)
1111 : _type(type), _fmt(fmt), _mult(mult)
1114 if (type == TEXT_VALUE)
1123 FGTextLayer::Chunk::getValue () const
1129 sprintf(_buf, _fmt.c_str(), _text.c_str());
1132 sprintf(_buf, _fmt.c_str(), _node->getStringValue());
1135 sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
1146 ////////////////////////////////////////////////////////////////////////
1147 // Implementation of FGSwitchLayer.
1148 ////////////////////////////////////////////////////////////////////////
1150 FGSwitchLayer::FGSwitchLayer (int w, int h, const SGPropertyNode * node,
1151 FGInstrumentLayer * layer1,
1152 FGInstrumentLayer * layer2)
1153 : FGInstrumentLayer(w, h), _node(node), _layer1(layer1), _layer2(layer2)
1157 FGSwitchLayer::~FGSwitchLayer ()
1164 FGSwitchLayer::draw ()
1168 if (_node->getBoolValue()) {