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