]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/panel.cxx
Patches contributed by Norman Vine to do ultra-hires tiled screen dumps.
[flightgear.git] / src / Cockpit / panel.cxx
1 //  panel.cxx - default, 2D single-engine prop instrument panel
2 //
3 //  Written by David Megginson, started January 2000.
4 //
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.
9 // 
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.
14 // 
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.
18 //
19 //  $Id$
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #ifdef HAVE_WINDOWS_H          
26 #  include <windows.h>
27 #endif
28
29 #include <string.h>
30
31 #include <plib/ssg.h>
32 #include <plib/fnt.h>
33
34 #include <simgear/debug/logstream.hxx>
35 #include <simgear/misc/sg_path.hxx>
36
37 #include <Main/globals.hxx>
38 #include <Main/fg_props.hxx>
39 #include <Objects/texload.h>
40 #include <Time/light.hxx>
41
42 #include "hud.hxx"
43 #include "panel.hxx"
44
45 #define WIN_X 0
46 #define WIN_Y 0
47 #define WIN_W 1024
48 #define WIN_H 768
49
50
51 \f
52 ////////////////////////////////////////////////////////////////////////
53 // Local functions.
54 ////////////////////////////////////////////////////////////////////////
55
56
57 /**
58  * Calculate the aspect adjustment for the panel.
59  */
60 static float
61 get_aspect_adjust (int xsize, int ysize)
62 {
63   float ideal_aspect = float(WIN_W) / float(WIN_H);
64   float real_aspect = float(xsize) / float(ysize);
65   return (real_aspect / ideal_aspect);
66 }
67
68
69 \f
70 ////////////////////////////////////////////////////////////////////////
71 // Global functions.
72 ////////////////////////////////////////////////////////////////////////
73
74 bool
75 fgPanelVisible ()
76 {
77   return ((current_panel != 0) &&
78           (current_panel->getVisibility()) &&
79           (globals->get_viewmgr()->get_current() == 0) &&
80           (globals->get_current_view()->get_view_offset() == 0.0));
81 }
82
83
84 \f
85 ////////////////////////////////////////////////////////////////////////
86 // Implementation of FGTextureManager.
87 ////////////////////////////////////////////////////////////////////////
88
89 map<string,ssgTexture *> FGTextureManager::_textureMap;
90
91 ssgTexture *
92 FGTextureManager::createTexture (const string &relativePath)
93 {
94   ssgTexture * texture = _textureMap[relativePath];
95   if (texture == 0) {
96     SG_LOG( SG_COCKPIT, SG_DEBUG,
97             "Texture " << relativePath << " does not yet exist" );
98     SGPath tpath(globals->get_fg_root());
99     tpath.append(relativePath);
100     texture = new ssgTexture((char *)tpath.c_str(), false, false);
101     _textureMap[relativePath] = texture;
102     if (_textureMap[relativePath] == 0) 
103       SG_LOG( SG_COCKPIT, SG_ALERT, "Texture *still* doesn't exist" );
104     SG_LOG( SG_COCKPIT, SG_DEBUG, "Created texture " << relativePath
105             << " handle=" << texture->getHandle() );
106   }
107
108   return texture;
109 }
110
111
112
113 \f
114 ////////////////////////////////////////////////////////////////////////
115 // Implementation of FGCropped Texture.
116 ////////////////////////////////////////////////////////////////////////
117
118
119 FGCroppedTexture::FGCroppedTexture ()
120   : _path(""), _texture(0),
121     _minX(0.0), _minY(0.0), _maxX(1.0), _maxY(1.0)
122 {
123 }
124
125
126 FGCroppedTexture::FGCroppedTexture (const string &path,
127                                     float minX, float minY,
128                                     float maxX, float maxY)
129   : _path(path), _texture(0),
130     _minX(minX), _minY(minY), _maxX(maxX), _maxY(maxY)
131 {
132 }
133
134
135 FGCroppedTexture::~FGCroppedTexture ()
136 {
137 }
138
139
140 ssgTexture *
141 FGCroppedTexture::getTexture ()
142 {
143   if (_texture == 0) {
144     _texture = FGTextureManager::createTexture(_path);
145   }
146   return _texture;
147 }
148
149
150 \f
151 ////////////////////////////////////////////////////////////////////////
152 // Implementation of FGPanel.
153 ////////////////////////////////////////////////////////////////////////
154
155 FGPanel * current_panel = NULL;
156 static fntRenderer text_renderer;
157
158
159 /**
160  * Constructor.
161  */
162 FGPanel::FGPanel ()
163   : _mouseDown(false),
164     _mouseInstrument(0),
165     _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)),
166     _x_offset(0), _y_offset(0), _view_height(int(WIN_H * 0.4232)),
167     _bound(false),
168     _xsize_node(fgGetNode("/sim/startup/xsize", true)),
169     _ysize_node(fgGetNode("/sim/startup/ysize", true))
170 {
171   setVisibility(fgPanelVisible());
172 }
173
174
175 /**
176  * Destructor.
177  */
178 FGPanel::~FGPanel ()
179 {
180   if (_bound)
181     unbind();
182   for (instrument_list_type::iterator it = _instruments.begin();
183        it != _instruments.end();
184        it++) {
185     delete *it;
186     *it = 0;
187   }
188 }
189
190
191 /**
192  * Add an instrument to the panel.
193  */
194 void
195 FGPanel::addInstrument (FGPanelInstrument * instrument)
196 {
197   _instruments.push_back(instrument);
198 }
199
200
201 /**
202  * Initialize the panel.
203  */
204 void
205 FGPanel::init ()
206 {
207   // NO-OP
208 }
209
210
211 /**
212  * Bind panel properties.
213  */
214 void
215 FGPanel::bind ()
216 {
217   fgTie("/sim/panel/visibility", &_visibility);
218   fgTie("/sim/panel/x-offset", &_x_offset);
219   fgTie("/sim/panel/y-offset", &_y_offset);
220   _bound = true;
221 }
222
223
224 /**
225  * Unbind panel properties.
226  */
227 void
228 FGPanel::unbind ()
229 {
230   fgUntie("/sim/panel/visibility");
231   fgUntie("/sim/panel/x-offset");
232   fgUntie("/sim/panel/y-offset");
233   _bound = false;
234 }
235
236
237 /**
238  * Update the panel.
239  */
240 void
241 FGPanel::update ()
242 {
243                                 // Do nothing if the panel isn't visible.
244     if (!fgPanelVisible())
245         return;
246
247                                 // If the mouse is down, do something
248     if (_mouseDown) {
249         _mouseDelay--;
250         if (_mouseDelay < 0) {
251             _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
252             _mouseDelay = 2;
253         }
254     }
255
256                                 // Now, draw the panel
257     float aspect_adjust = get_aspect_adjust(_xsize_node->getIntValue(),
258                                             _ysize_node->getIntValue());
259     if (aspect_adjust <1.0)
260         update(WIN_X, int(WIN_W * aspect_adjust), WIN_Y, WIN_H);
261     else
262         update(WIN_X, WIN_W, WIN_Y, int(WIN_H / aspect_adjust));
263 }
264
265
266 void
267 FGPanel::update (GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh)
268 {
269   glMatrixMode(GL_PROJECTION);
270   glPushMatrix();
271   glLoadIdentity();
272   gluOrtho2D(winx, winx + winw, winy, winy + winh);
273
274   glMatrixMode(GL_MODELVIEW);
275   glPushMatrix();
276   glLoadIdentity();
277
278   glTranslated(_x_offset, _y_offset, 0);
279
280                                 // Draw the background
281   glEnable(GL_TEXTURE_2D);
282   glDisable(GL_LIGHTING);
283   glEnable(GL_BLEND);
284   glEnable(GL_ALPHA_TEST);
285   glEnable(GL_COLOR_MATERIAL);
286   // glColor4f(1.0, 1.0, 1.0, 1.0);
287   if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
288       glColor4fv( cur_light_params.scene_diffuse );
289   } else {
290       glColor4f(0.7, 0.2, 0.2, 1.0);
291   }
292   glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
293   // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
294   // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
295   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
296   glBegin(GL_POLYGON);
297   glTexCoord2f(0.0, 0.0); glVertex3f(WIN_X, WIN_Y, 0);
298   glTexCoord2f(1.0, 0.0); glVertex3f(WIN_X + _width, WIN_Y, 0);
299   glTexCoord2f(1.0, 1.0); glVertex3f(WIN_X + _width, WIN_Y + _height, 0);
300   glTexCoord2f(0.0, 1.0); glVertex3f(WIN_X, WIN_Y + _height, 0);
301   glEnd();
302
303                                 // Draw the instruments.
304   instrument_list_type::const_iterator current = _instruments.begin();
305   instrument_list_type::const_iterator end = _instruments.end();
306
307   for ( ; current != end; current++) {
308     FGPanelInstrument * instr = *current;
309     glLoadIdentity();
310     glTranslated(_x_offset, _y_offset, 0);
311     glTranslated(instr->getXPos(), instr->getYPos(), 0);
312     instr->draw();
313   }
314
315   glMatrixMode(GL_PROJECTION);
316   glPopMatrix();
317   glMatrixMode(GL_MODELVIEW);
318   glPopMatrix();
319   ssgForceBasicState();
320   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
321 }
322
323
324 /**
325  * Set the panel's visibility.
326  */
327 void
328 FGPanel::setVisibility (bool visibility)
329 {
330   _visibility = visibility;
331 }
332
333
334 /**
335  * Return true if the panel is visible.
336  */
337 bool
338 FGPanel::getVisibility () const
339 {
340   return _visibility;
341 }
342
343
344 /**
345  * Set the panel's background texture.
346  */
347 void
348 FGPanel::setBackground (ssgTexture * texture)
349 {
350   _bg = texture;
351 }
352
353
354 /**
355  * Set the panel's x-offset.
356  */
357 void
358 FGPanel::setXOffset (int offset)
359 {
360   if (offset <= 0 && offset >= -_width + WIN_W)
361     _x_offset = offset;
362 }
363
364
365 /**
366  * Set the panel's y-offset.
367  */
368 void
369 FGPanel::setYOffset (int offset)
370 {
371   if (offset <= 0 && offset >= -_height)
372     _y_offset = offset;
373 }
374
375
376 /**
377  * Perform a mouse action.
378  */
379 bool
380 FGPanel::doMouseAction (int button, int updown, int x, int y)
381 {
382                                 // FIXME: this same code appears in update()
383   int xsize = _xsize_node->getIntValue();
384   int ysize = _ysize_node->getIntValue();
385   float aspect_adjust = get_aspect_adjust(xsize, ysize);
386
387                                 // Note a released button and return
388   // cerr << "Doing mouse action\n";
389   if (updown == 1) {
390     _mouseDown = false;
391     _mouseInstrument = 0;
392     return true;
393   }
394
395                                 // Scale for the real window size.
396   if (aspect_adjust < 1.0) {
397     x = int(((float)x / xsize) * WIN_W * aspect_adjust);
398     y = int(WIN_H - ((float(y) / ysize) * WIN_H));
399   } else {
400     x = int(((float)x / xsize) * WIN_W);
401     y = int((WIN_H - ((float(y) / ysize) * WIN_H)) / aspect_adjust);
402   }
403
404                                 // Adjust for offsets.
405   x -= _x_offset;
406   y -= _y_offset;
407
408                                 // Search for a matching instrument.
409   for (int i = 0; i < (int)_instruments.size(); i++) {
410     FGPanelInstrument *inst = _instruments[i];
411     int ix = inst->getXPos();
412     int iy = inst->getYPos();
413     int iw = inst->getWidth() / 2;
414     int ih = inst->getHeight() / 2;
415     if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
416       _mouseDown = true;
417       _mouseDelay = 20;
418       _mouseInstrument = inst;
419       _mouseButton = button;
420       _mouseX = x - ix;
421       _mouseY = y - iy;
422                                 // Always do the action once.
423       _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
424       return true;
425     }
426   }
427   return false;
428 }
429
430
431 \f
432 ////////////////////////////////////////////////////////////////////////.
433 // Implementation of FGPanelAction.
434 ////////////////////////////////////////////////////////////////////////
435
436 FGPanelAction::FGPanelAction ()
437 {
438 }
439
440 FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h)
441   : _button(button), _x(x), _y(y), _w(w), _h(h)
442 {
443 }
444
445 FGPanelAction::~FGPanelAction ()
446 {
447 }
448
449
450 \f
451 ////////////////////////////////////////////////////////////////////////
452 // Implementation of FGAdjustAction.
453 ////////////////////////////////////////////////////////////////////////
454
455 FGAdjustAction::FGAdjustAction (int button, int x, int y, int w, int h,
456                                 SGPropertyNode * node, float increment, 
457                                 float min, float max, bool wrap)
458   : FGPanelAction(button, x, y, w, h),
459     _node(node), _increment(increment), _min(min), _max(max), _wrap(wrap)
460 {
461 }
462
463 FGAdjustAction::~FGAdjustAction ()
464 {
465 }
466
467 void
468 FGAdjustAction::doAction ()
469 {
470   float val = _node->getFloatValue();
471   val += _increment;
472   if (val < _min) {
473     val = (_wrap ? _max : _min);
474   } else if (val > _max) {
475     val = (_wrap ? _min : _max);
476   }
477   _node->setDoubleValue(val);
478 }
479
480
481 \f
482 ////////////////////////////////////////////////////////////////////////
483 // Implementation of FGSwapAction.
484 ////////////////////////////////////////////////////////////////////////
485
486 FGSwapAction::FGSwapAction (int button, int x, int y, int w, int h,
487                             SGPropertyNode * node1, SGPropertyNode * node2)
488   : FGPanelAction(button, x, y, w, h), _node1(node1), _node2(node2)
489 {
490 }
491
492 FGSwapAction::~FGSwapAction ()
493 {
494 }
495
496 void
497 FGSwapAction::doAction ()
498 {
499   float val = _node1->getFloatValue();
500   _node1->setDoubleValue(_node2->getFloatValue());
501   _node2->setDoubleValue(val);
502 }
503
504
505 \f
506 ////////////////////////////////////////////////////////////////////////
507 // Implementation of FGToggleAction.
508 ////////////////////////////////////////////////////////////////////////
509
510 FGToggleAction::FGToggleAction (int button, int x, int y, int w, int h,
511                                 SGPropertyNode * node)
512   : FGPanelAction(button, x, y, w, h), _node(node)
513 {
514 }
515
516 FGToggleAction::~FGToggleAction ()
517 {
518 }
519
520 void
521 FGToggleAction::doAction ()
522 {
523   _node->setBoolValue(!(_node->getBoolValue()));
524 }
525
526
527 \f
528 ////////////////////////////////////////////////////////////////////////
529 // Implementation of FGPanelTransformation.
530 ////////////////////////////////////////////////////////////////////////
531
532 FGPanelTransformation::FGPanelTransformation ()
533   : table(0)
534 {
535 }
536
537 FGPanelTransformation::~FGPanelTransformation ()
538 {
539 }
540
541
542 \f
543 ////////////////////////////////////////////////////////////////////////
544 // Implementation of FGPanelInstrument.
545 ////////////////////////////////////////////////////////////////////////
546
547
548 FGPanelInstrument::FGPanelInstrument ()
549 {
550   setPosition(0, 0);
551   setSize(0, 0);
552 }
553
554 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
555 {
556   setPosition(x, y);
557   setSize(w, h);
558 }
559
560 FGPanelInstrument::~FGPanelInstrument ()
561 {
562   for (action_list_type::iterator it = _actions.begin();
563        it != _actions.end();
564        it++) {
565     delete *it;
566     *it = 0;
567   }
568 }
569
570 void
571 FGPanelInstrument::setPosition (int x, int y)
572 {
573   _x = x;
574   _y = y;
575 }
576
577 void
578 FGPanelInstrument::setSize (int w, int h)
579 {
580   _w = w;
581   _h = h;
582 }
583
584 int
585 FGPanelInstrument::getXPos () const
586 {
587   return _x;
588 }
589
590 int
591 FGPanelInstrument::getYPos () const
592 {
593   return _y;
594 }
595
596 int
597 FGPanelInstrument::getWidth () const
598 {
599   return _w;
600 }
601
602 int
603 FGPanelInstrument::getHeight () const
604 {
605   return _h;
606 }
607
608 void
609 FGPanelInstrument::addAction (FGPanelAction * action)
610 {
611   _actions.push_back(action);
612 }
613
614                                 // Coordinates relative to centre.
615 bool
616 FGPanelInstrument::doMouseAction (int button, int x, int y)
617 {
618   action_list_type::iterator it = _actions.begin();
619   action_list_type::iterator last = _actions.end();
620   for ( ; it != last; it++) {
621     if ((*it)->inArea(button, x, y)) {
622       (*it)->doAction();
623       return true;
624     }
625   }
626   return false;
627 }
628
629
630 \f
631 ////////////////////////////////////////////////////////////////////////
632 // Implementation of FGLayeredInstrument.
633 ////////////////////////////////////////////////////////////////////////
634
635 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
636   : FGPanelInstrument(x, y, w, h)
637 {
638 }
639
640 FGLayeredInstrument::~FGLayeredInstrument ()
641 {
642   for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
643     delete *it;
644     *it = 0;
645   }
646 }
647
648 void
649 FGLayeredInstrument::draw ()
650 {
651   for (int i = 0; i < (int)_layers.size(); i++) {
652     glPushMatrix();
653     glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
654     _layers[i]->draw();
655     glPopMatrix();
656   }
657 }
658
659 int
660 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
661 {
662   int n = _layers.size();
663   if (layer->getWidth() == -1) {
664     layer->setWidth(getWidth());
665   }
666   if (layer->getHeight() == -1) {
667     layer->setHeight(getHeight());
668   }
669   _layers.push_back(layer);
670   return n;
671 }
672
673 int
674 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
675                                int w, int h)
676 {
677   return addLayer(new FGTexturedLayer(texture, w, h));
678 }
679
680 void
681 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
682 {
683   int layer = _layers.size() - 1;
684   _layers[layer]->addTransformation(transformation);
685 }
686
687
688 \f
689 ////////////////////////////////////////////////////////////////////////
690 // Implementation of FGInstrumentLayer.
691 ////////////////////////////////////////////////////////////////////////
692
693 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
694   : _w(w),
695     _h(h)
696 {
697 }
698
699 FGInstrumentLayer::~FGInstrumentLayer ()
700 {
701   for (transformation_list::iterator it = _transformations.begin();
702        it != _transformations.end();
703        it++) {
704     delete *it;
705     *it = 0;
706   }
707 }
708
709 void
710 FGInstrumentLayer::transform () const
711 {
712   transformation_list::const_iterator it = _transformations.begin();
713   transformation_list::const_iterator last = _transformations.end();
714   while (it != last) {
715     FGPanelTransformation *t = *it;
716     float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
717     if (val < t->min) {
718       val = t->min;
719     } else if (val > t->max) {
720       val = t->max;
721     }
722     if(t->table==0) {
723         val = val * t->factor + t->offset;
724     } else {
725         val = t->table->interpolate(val) * t->factor + t->offset;
726     }
727
728     switch (t->type) {
729     case FGPanelTransformation::XSHIFT:
730       glTranslatef(val, 0.0, 0.0);
731       break;
732     case FGPanelTransformation::YSHIFT:
733       glTranslatef(0.0, val, 0.0);
734       break;
735     case FGPanelTransformation::ROTATION:
736       glRotatef(-val, 0.0, 0.0, 1.0);
737       break;
738     }
739     it++;
740   }
741 }
742
743 void
744 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
745 {
746   _transformations.push_back(transformation);
747 }
748
749
750 \f
751 ////////////////////////////////////////////////////////////////////////
752 // Implementation of FGTexturedLayer.
753 ////////////////////////////////////////////////////////////////////////
754
755
756 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
757   : FGInstrumentLayer(w, h)
758 {
759   setTexture(texture);
760 }
761
762
763 FGTexturedLayer::~FGTexturedLayer ()
764 {
765 }
766
767
768 void
769 FGTexturedLayer::draw ()
770 {
771   int w2 = _w / 2;
772   int h2 = _h / 2;
773
774   transform();
775   glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
776   glBegin(GL_POLYGON);
777
778                                 // From Curt: turn on the panel
779                                 // lights after sundown.
780   if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
781       glColor4fv( cur_light_params.scene_diffuse );
782   } else {
783       glColor4f(0.7, 0.2, 0.2, 1.0);
784   }
785
786
787   glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
788   glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
789   glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
790   glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
791   glEnd();
792 }
793
794
795 \f
796 ////////////////////////////////////////////////////////////////////////
797 // Implementation of FGTextLayer.
798 ////////////////////////////////////////////////////////////////////////
799
800 FGTextLayer::FGTextLayer (int w, int h)
801   : FGInstrumentLayer(w, h), _pointSize(14.0)
802 {
803   _then.stamp();
804   _color[0] = _color[1] = _color[2] = 0.0;
805   _color[3] = 1.0;
806 }
807
808 FGTextLayer::~FGTextLayer ()
809 {
810   chunk_list::iterator it = _chunks.begin();
811   chunk_list::iterator last = _chunks.end();
812   for ( ; it != last; it++) {
813     delete *it;
814   }
815 }
816
817 void
818 FGTextLayer::draw ()
819 {
820   glPushMatrix();
821   glColor4fv(_color);
822   transform();
823   text_renderer.setFont(guiFntHandle);
824   text_renderer.setPointSize(_pointSize);
825   text_renderer.begin();
826   text_renderer.start3f(0, 0, 0);
827
828   _now.stamp();
829   if (_now - _then > 100000) {
830     recalc_value();
831     _then = _now;
832   }
833   text_renderer.puts((char *)(_value.c_str()));
834
835   text_renderer.end();
836   glColor4f(1.0, 1.0, 1.0, 1.0);        // FIXME
837   glPopMatrix();
838 }
839
840 void
841 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
842 {
843   _chunks.push_back(chunk);
844 }
845
846 void
847 FGTextLayer::setColor (float r, float g, float b)
848 {
849   _color[0] = r;
850   _color[1] = g;
851   _color[2] = b;
852   _color[3] = 1.0;
853 }
854
855 void
856 FGTextLayer::setPointSize (float size)
857 {
858   _pointSize = size;
859 }
860
861 void
862 FGTextLayer::setFont(fntFont * font)
863 {
864   text_renderer.setFont(font);
865 }
866
867
868 void
869 FGTextLayer::recalc_value () const
870 {
871   _value = "";
872   chunk_list::const_iterator it = _chunks.begin();
873   chunk_list::const_iterator last = _chunks.end();
874   for ( ; it != last; it++) {
875     _value += (*it)->getValue();
876   }
877 }
878
879
880 \f
881 ////////////////////////////////////////////////////////////////////////
882 // Implementation of FGTextLayer::Chunk.
883 ////////////////////////////////////////////////////////////////////////
884
885 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
886   : _type(FGTextLayer::TEXT), _fmt(fmt)
887 {
888   _text = text;
889   if (_fmt == "") 
890     _fmt = "%s";
891 }
892
893 FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
894                            const string &fmt, float mult)
895   : _type(type), _fmt(fmt), _mult(mult)
896 {
897   if (_fmt == "") {
898     if (type == TEXT_VALUE)
899       _fmt = "%s";
900     else
901       _fmt = "%.2f";
902   }
903   _node = node;
904 }
905
906 const char *
907 FGTextLayer::Chunk::getValue () const
908 {
909   switch (_type) {
910   case TEXT:
911     sprintf(_buf, _fmt.c_str(), _text.c_str());
912     return _buf;
913   case TEXT_VALUE:
914     sprintf(_buf, _fmt.c_str(), _node->getStringValue().c_str());
915     break;
916   case DOUBLE_VALUE:
917     sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
918     break;
919   }
920   return _buf;
921 }
922
923
924 \f
925 ////////////////////////////////////////////////////////////////////////
926 // Implementation of FGSwitchLayer.
927 ////////////////////////////////////////////////////////////////////////
928
929 FGSwitchLayer::FGSwitchLayer (int w, int h, const SGPropertyNode * node,
930                               FGInstrumentLayer * layer1,
931                               FGInstrumentLayer * layer2)
932   : FGInstrumentLayer(w, h), _node(node), _layer1(layer1), _layer2(layer2)
933 {
934 }
935
936 FGSwitchLayer::~FGSwitchLayer ()
937 {
938   delete _layer1;
939   delete _layer2;
940 }
941
942 void
943 FGSwitchLayer::draw ()
944 {
945   transform();
946   if (_node->getBoolValue()) {
947     _layer1->draw();
948   } else {
949     _layer2->draw();
950   }
951 }
952
953 \f
954 // end of panel.cxx