]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/panel.hxx
13e4f4aad0a2f683f249dd788a10cad5187ee208
[flightgear.git] / src / Cockpit / panel.hxx
1 //  panel.hxx - 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 #ifndef __PANEL_HXX
22 #define __PANEL_HXX
23
24 #ifndef __cplusplus                                                          
25 # error This library requires C++
26 #endif                                   
27
28
29 #ifdef HAVE_CONFIG_H
30 #  include <config.h>
31 #endif
32
33 #ifdef HAVE_WINDOWS_H          
34 #  include <windows.h>
35 #endif
36
37 #include <GL/glut.h>
38 #include <plib/ssg.h>
39
40 #include <vector>
41 #include <plib/fnt.h>
42
43 FG_USING_STD(vector);
44
45 class FGPanelInstrument;
46
47
48 \f
49 ////////////////////////////////////////////////////////////////////////
50 // Instrument panel class.
51 ////////////////////////////////////////////////////////////////////////
52
53 class FGPanel
54 {
55 public:
56
57   typedef vector<FGPanelInstrument *> instrument_list_type;
58
59   FGPanel ();
60   virtual ~FGPanel ();
61
62                                 // Legacy interface from old panel.
63   static FGPanel * OurPanel;
64   virtual float get_height () const;
65   virtual void ReInit (int x, int y, int finx, int finy);
66   virtual void Update () const;
67
68 private:
69   int _x, _y, _w, _h;
70   int _panel_h;
71
72   ssgTexture * _bg;
73
74   instrument_list_type _instruments;
75 };
76
77
78 \f
79 ////////////////////////////////////////////////////////////////////////
80 // Instrument base class.
81 ////////////////////////////////////////////////////////////////////////
82
83 class FGPanelInstrument
84 {
85 public:
86   FGPanelInstrument ();
87   FGPanelInstrument (int x, int y, int w, int h);
88   virtual ~FGPanelInstrument ();
89
90   virtual void draw () const = 0;
91
92   virtual void setPosition(int x, int y);
93   virtual void setSize(int w, int h);
94
95   virtual int getXPos () const;
96   virtual int getYPos () const;
97
98 protected:
99   int _x, _y, _w, _h;
100 };
101
102
103 \f
104 ////////////////////////////////////////////////////////////////////////
105 // A single layer of an instrument.
106 ////////////////////////////////////////////////////////////////////////
107
108 /**
109  * A single layer of a multi-layered instrument.
110  *
111  * Each layer can be subject to a series of transformations based
112  * on current FGFS instrument readings: for example, a texture
113  * representing a needle can rotate to show the airspeed.
114  */
115 class FGInstrumentLayer
116 {
117 public:
118   typedef enum {
119     XSHIFT,
120     YSHIFT,
121     ROTATION
122   } transform_type;
123
124   typedef double (*transform_func)();
125
126
127   FGInstrumentLayer ();
128   FGInstrumentLayer (int w, int h, int z);
129   virtual ~FGInstrumentLayer ();
130
131   virtual void draw () const = 0;
132   virtual void transform () const;
133
134   virtual void addTransformation (transform_type type, transform_func func,
135                                   double min, double max,
136                                   double factor = 1.0, double offset = 0.0);
137
138 protected:
139   int _w, _h, _z;
140
141   typedef struct {
142     transform_type type;
143     transform_func func;
144     double min;
145     double max;
146     double factor;
147     double offset;
148   } transformation;
149   typedef vector<transformation *> transformation_list;
150   transformation_list _transformations;
151 };
152
153
154 \f
155 ////////////////////////////////////////////////////////////////////////
156 // An instrument composed of layered textures.
157 ////////////////////////////////////////////////////////////////////////
158
159
160 /**
161  * An instrument constructed of multiple layers.
162  *
163  * Each individual layer can be rotated or shifted to correspond
164  * to internal FGFS instrument readings.
165  */
166 class FGLayeredInstrument : public FGPanelInstrument
167 {
168 public:
169   typedef vector<FGInstrumentLayer *> layer_list;
170   FGLayeredInstrument (int x, int y, int w, int h);
171   virtual ~FGLayeredInstrument ();
172
173   virtual void draw () const;
174
175   virtual void addLayer (FGInstrumentLayer *layer);
176   virtual void addLayer (int i, const char *textureName);
177   virtual void addTransformation (int layer,
178                                   FGInstrumentLayer::transform_type type,
179                                   FGInstrumentLayer::transform_func func,
180                                   double min, double max,
181                                   double factor = 1.0, double offset = 0.0);
182   virtual void addTransformation (int layer,
183                                   FGInstrumentLayer::transform_type type,
184                                   double offset) {
185     addTransformation(layer, type, 0, 0.0, 0.0, 1.0, offset);
186   }
187
188 protected:
189   layer_list _layers;
190 };
191
192
193 \f
194 ////////////////////////////////////////////////////////////////////////
195 // A textured layer of an instrument.
196 ////////////////////////////////////////////////////////////////////////
197
198 /**
199  * A textured layer of an instrument.
200  *
201  * This is a type of layer designed to hold a texture; normally,
202  * the texture's background should be transparent so that
203  * other layers or the panel background show through.
204  */
205 class FGTexturedInstrumentLayer : public FGInstrumentLayer
206 {
207 public:
208   FGTexturedInstrumentLayer (const char * textureName,
209                              int w, int h, int z);
210   FGTexturedInstrumentLayer (ssgTexture * texture,
211                              int w, int h, int z);
212   virtual ~FGTexturedInstrumentLayer ();
213
214   virtual void draw () const;
215
216   virtual void setTexture (const char *textureName);
217   virtual void setTexture (ssgTexture * texture) { _texture = texture; }
218
219 private:
220   ssgTexture * _texture;
221 };
222
223
224 \f
225 ////////////////////////////////////////////////////////////////////////
226 // A text layer of an instrument.
227 ////////////////////////////////////////////////////////////////////////
228
229 class FGCharInstrumentLayer : public FGInstrumentLayer
230 {
231 public:
232   typedef char * (*text_func)(char *);
233   FGCharInstrumentLayer (text_func func,
234                          int w, int h, int z);
235   virtual ~FGCharInstrumentLayer ();
236
237   virtual void draw () const;
238   virtual void setColor (float r, float g, float b);
239   virtual void setPointSize (float size);
240   virtual void setFont (fntFont * font);
241
242 private:
243   text_func _func;
244   float _color[3];
245                                 // FIXME: need only one globally
246   mutable fntRenderer _renderer;
247   mutable char _buf[1024];
248 };
249
250
251 \f
252 #endif // __PANEL_HXX
253
254 // end of panel.hxx
255
256