]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/panel.cxx
Tweaks for Mips Irix compilers.
[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/fgpath.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     FGPath 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 * RAD_TO_DEG < 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 {
480 }
481
482 FGPanelTransformation::~FGPanelTransformation ()
483 {
484 }
485
486
487 \f
488 ////////////////////////////////////////////////////////////////////////
489 // Implementation of FGPanelInstrument.
490 ////////////////////////////////////////////////////////////////////////
491
492
493 FGPanelInstrument::FGPanelInstrument ()
494 {
495   setPosition(0, 0);
496   setSize(0, 0);
497 }
498
499 FGPanelInstrument::FGPanelInstrument (int x, int y, int w, int h)
500 {
501   setPosition(x, y);
502   setSize(w, h);
503 }
504
505 FGPanelInstrument::~FGPanelInstrument ()
506 {
507   for (action_list_type::iterator it = _actions.begin();
508        it != _actions.end();
509        it++) {
510     delete *it;
511     *it = 0;
512   }
513 }
514
515 void
516 FGPanelInstrument::setPosition (int x, int y)
517 {
518   _x = x;
519   _y = y;
520 }
521
522 void
523 FGPanelInstrument::setSize (int w, int h)
524 {
525   _w = w;
526   _h = h;
527 }
528
529 int
530 FGPanelInstrument::getXPos () const
531 {
532   return _x;
533 }
534
535 int
536 FGPanelInstrument::getYPos () const
537 {
538   return _y;
539 }
540
541 int
542 FGPanelInstrument::getWidth () const
543 {
544   return _w;
545 }
546
547 int
548 FGPanelInstrument::getHeight () const
549 {
550   return _h;
551 }
552
553 void
554 FGPanelInstrument::addAction (FGPanelAction * action)
555 {
556   _actions.push_back(action);
557 }
558
559                                 // Coordinates relative to centre.
560 bool
561 FGPanelInstrument::doMouseAction (int button, int x, int y)
562 {
563   action_list_type::iterator it = _actions.begin();
564   action_list_type::iterator last = _actions.end();
565   for ( ; it != last; it++) {
566     if ((*it)->inArea(button, x, y)) {
567       (*it)->doAction();
568       return true;
569     }
570   }
571   return false;
572 }
573
574
575 \f
576 ////////////////////////////////////////////////////////////////////////
577 // Implementation of FGLayeredInstrument.
578 ////////////////////////////////////////////////////////////////////////
579
580 FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
581   : FGPanelInstrument(x, y, w, h)
582 {
583 }
584
585 FGLayeredInstrument::~FGLayeredInstrument ()
586 {
587   for (layer_list::iterator it = _layers.begin(); it != _layers.end(); it++) {
588     delete *it;
589     *it = 0;
590   }
591 }
592
593 void
594 FGLayeredInstrument::draw ()
595 {
596   for (int i = 0; i < (int)_layers.size(); i++) {
597     glPushMatrix();
598     glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
599     _layers[i]->draw();
600     glPopMatrix();
601   }
602 }
603
604 int
605 FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
606 {
607   int n = _layers.size();
608   if (layer->getWidth() == -1) {
609     layer->setWidth(getWidth());
610   }
611   if (layer->getHeight() == -1) {
612     layer->setHeight(getHeight());
613   }
614   _layers.push_back(layer);
615   return n;
616 }
617
618 int
619 FGLayeredInstrument::addLayer (FGCroppedTexture &texture,
620                                int w, int h)
621 {
622   return addLayer(new FGTexturedLayer(texture, w, h));
623 }
624
625 void
626 FGLayeredInstrument::addTransformation (FGPanelTransformation * transformation)
627 {
628   int layer = _layers.size() - 1;
629   _layers[layer]->addTransformation(transformation);
630 }
631
632
633 \f
634 ////////////////////////////////////////////////////////////////////////
635 // Implementation of FGInstrumentLayer.
636 ////////////////////////////////////////////////////////////////////////
637
638 FGInstrumentLayer::FGInstrumentLayer (int w, int h)
639   : _w(w),
640     _h(h)
641 {
642 }
643
644 FGInstrumentLayer::~FGInstrumentLayer ()
645 {
646   for (transformation_list::iterator it = _transformations.begin();
647        it != _transformations.end();
648        it++) {
649     delete *it;
650     *it = 0;
651   }
652 }
653
654 void
655 FGInstrumentLayer::transform () const
656 {
657   transformation_list::const_iterator it = _transformations.begin();
658   transformation_list::const_iterator last = _transformations.end();
659   while (it != last) {
660     FGPanelTransformation *t = *it;
661     float val = (t->value == 0 ? 0.0 : t->value->getFloatValue());
662     if (val < t->min) {
663       val = t->min;
664     } else if (val > t->max) {
665       val = t->max;
666     }
667     val = val * t->factor + t->offset;
668
669     switch (t->type) {
670     case FGPanelTransformation::XSHIFT:
671       glTranslatef(val, 0.0, 0.0);
672       break;
673     case FGPanelTransformation::YSHIFT:
674       glTranslatef(0.0, val, 0.0);
675       break;
676     case FGPanelTransformation::ROTATION:
677       glRotatef(-val, 0.0, 0.0, 1.0);
678       break;
679     }
680     it++;
681   }
682 }
683
684 void
685 FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
686 {
687   _transformations.push_back(transformation);
688 }
689
690
691 \f
692 ////////////////////////////////////////////////////////////////////////
693 // Implementation of FGTexturedLayer.
694 ////////////////////////////////////////////////////////////////////////
695
696
697 FGTexturedLayer::FGTexturedLayer (const FGCroppedTexture &texture, int w, int h)
698   : FGInstrumentLayer(w, h)
699 {
700   setTexture(texture);
701 }
702
703
704 FGTexturedLayer::~FGTexturedLayer ()
705 {
706 }
707
708
709 void
710 FGTexturedLayer::draw ()
711 {
712   int w2 = _w / 2;
713   int h2 = _h / 2;
714
715   transform();
716   glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
717   glBegin(GL_POLYGON);
718
719                                 // From Curt: turn on the panel
720                                 // lights after sundown.
721   if ( cur_light_params.sun_angle * RAD_TO_DEG < 95.0 ) {
722       glColor4fv( cur_light_params.scene_diffuse );
723   } else {
724       glColor4f(0.7, 0.2, 0.2, 1.0);
725   }
726
727
728   glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
729   glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
730   glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
731   glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
732   glEnd();
733 }
734
735
736 \f
737 ////////////////////////////////////////////////////////////////////////
738 // Implementation of FGTextLayer.
739 ////////////////////////////////////////////////////////////////////////
740
741 FGTextLayer::FGTextLayer (int w, int h)
742   : FGInstrumentLayer(w, h), _pointSize(14.0)
743 {
744   _then.stamp();
745   _color[0] = _color[1] = _color[2] = 0.0;
746   _color[3] = 1.0;
747 }
748
749 FGTextLayer::~FGTextLayer ()
750 {
751   chunk_list::iterator it = _chunks.begin();
752   chunk_list::iterator last = _chunks.end();
753   for ( ; it != last; it++) {
754     delete *it;
755   }
756 }
757
758 void
759 FGTextLayer::draw ()
760 {
761   glPushMatrix();
762   glColor4fv(_color);
763   transform();
764   text_renderer.setFont(guiFntHandle);
765   text_renderer.setPointSize(_pointSize);
766   text_renderer.begin();
767   text_renderer.start3f(0, 0, 0);
768
769   _now.stamp();
770   if (_now - _then > 100000) {
771     recalc_value();
772     _then = _now;
773   }
774   text_renderer.puts((char *)(_value.c_str()));
775
776   text_renderer.end();
777   glColor4f(1.0, 1.0, 1.0, 1.0);        // FIXME
778   glPopMatrix();
779 }
780
781 void
782 FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
783 {
784   _chunks.push_back(chunk);
785 }
786
787 void
788 FGTextLayer::setColor (float r, float g, float b)
789 {
790   _color[0] = r;
791   _color[1] = g;
792   _color[2] = b;
793   _color[3] = 1.0;
794 }
795
796 void
797 FGTextLayer::setPointSize (float size)
798 {
799   _pointSize = size;
800 }
801
802 void
803 FGTextLayer::setFont(fntFont * font)
804 {
805   text_renderer.setFont(font);
806 }
807
808
809 void
810 FGTextLayer::recalc_value () const
811 {
812   _value = "";
813   chunk_list::const_iterator it = _chunks.begin();
814   chunk_list::const_iterator last = _chunks.end();
815   for ( ; it != last; it++) {
816     _value += (*it)->getValue();
817   }
818 }
819
820
821 \f
822 ////////////////////////////////////////////////////////////////////////
823 // Implementation of FGTextLayer::Chunk.
824 ////////////////////////////////////////////////////////////////////////
825
826 FGTextLayer::Chunk::Chunk (const string &text, const string &fmt)
827   : _type(FGTextLayer::TEXT), _fmt(fmt)
828 {
829   _text = text;
830   if (_fmt == "") 
831     _fmt = "%s";
832 }
833
834 FGTextLayer::Chunk::Chunk (ChunkType type, const SGValue * value,
835                            const string &fmt, float mult)
836   : _type(type), _fmt(fmt), _mult(mult)
837 {
838   if (_fmt == "") {
839     if (type == TEXT_VALUE)
840       _fmt = "%s";
841     else
842       _fmt = "%.2f";
843   }
844   _value = value;
845 }
846
847 const char *
848 FGTextLayer::Chunk::getValue () const
849 {
850   switch (_type) {
851   case TEXT:
852     sprintf(_buf, _fmt.c_str(), _text.c_str());
853     return _buf;
854   case TEXT_VALUE:
855     sprintf(_buf, _fmt.c_str(), _value->getStringValue().c_str());
856     break;
857   case DOUBLE_VALUE:
858     sprintf(_buf, _fmt.c_str(), _value->getFloatValue() * _mult);
859     break;
860   }
861   return _buf;
862 }
863
864
865 \f
866 ////////////////////////////////////////////////////////////////////////
867 // Implementation of FGSwitchLayer.
868 ////////////////////////////////////////////////////////////////////////
869
870 FGSwitchLayer::FGSwitchLayer (int w, int h, const SGValue * value,
871                               FGInstrumentLayer * layer1,
872                               FGInstrumentLayer * layer2)
873   : FGInstrumentLayer(w, h), _value(value), _layer1(layer1), _layer2(layer2)
874 {
875 }
876
877 FGSwitchLayer::~FGSwitchLayer ()
878 {
879   delete _layer1;
880   delete _layer2;
881 }
882
883 void
884 FGSwitchLayer::draw ()
885 {
886   transform();
887   if (_value->getBoolValue()) {
888     _layer1->draw();
889   } else {
890     _layer2->draw();
891   }
892 }
893
894 \f
895 // end of panel.cxx