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