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