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