1 // panel.hxx - default, 2D single-engine prop instrument panel
3 // Written by David Megginson, started January 2000.
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.
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.
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.
25 # error This library requires C++
47 class FGPanelInstrument;
50 ////////////////////////////////////////////////////////////////////////
51 // Instrument panel class.
52 ////////////////////////////////////////////////////////////////////////
61 virtual ssgTexture * createTexture (const char * relativePath);
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;
71 typedef vector<FGPanelInstrument *> instrument_list_type;
78 // Internalization table.
79 map<const char *,ssgTexture *> _textureMap;
81 // List of instruments in panel.
82 instrument_list_type _instruments;
87 ////////////////////////////////////////////////////////////////////////
88 // Instrument base class.
89 ////////////////////////////////////////////////////////////////////////
91 class FGPanelInstrument
95 FGPanelInstrument (int x, int y, int w, int h);
96 virtual ~FGPanelInstrument ();
98 virtual void draw () const = 0;
100 virtual void setPosition(int x, int y);
101 virtual void setSize(int w, int h);
103 virtual int getXPos () const;
104 virtual int getYPos () const;
112 ////////////////////////////////////////////////////////////////////////
113 // A single layer of an instrument.
114 ////////////////////////////////////////////////////////////////////////
117 * A single layer of a multi-layered instrument.
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.
123 class FGInstrumentLayer
132 typedef double (*transform_func)();
135 FGInstrumentLayer ();
136 FGInstrumentLayer (int w, int h, int z);
137 virtual ~FGInstrumentLayer ();
139 virtual void draw () const = 0;
140 virtual void transform () const;
142 virtual void addTransformation (transform_type type, transform_func func,
143 double min, double max,
144 double factor = 1.0, double offset = 0.0);
157 typedef vector<transformation *> transformation_list;
158 transformation_list _transformations;
163 ////////////////////////////////////////////////////////////////////////
164 // An instrument composed of layered textures.
165 ////////////////////////////////////////////////////////////////////////
169 * An instrument constructed of multiple layers.
171 * Each individual layer can be rotated or shifted to correspond
172 * to internal FGFS instrument readings.
174 class FGLayeredInstrument : public FGPanelInstrument
177 typedef vector<FGInstrumentLayer *> layer_list;
178 FGLayeredInstrument (int x, int y, int w, int h);
179 virtual ~FGLayeredInstrument ();
181 virtual void draw () const;
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,
193 addTransformation(layer, type, 0, 0.0, 0.0, 1.0, offset);
202 ////////////////////////////////////////////////////////////////////////
203 // A textured layer of an instrument.
204 ////////////////////////////////////////////////////////////////////////
207 * A textured layer of an instrument.
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.
213 class FGTexturedInstrumentLayer : public FGInstrumentLayer
216 FGTexturedInstrumentLayer (ssgTexture * texture,
217 int w, int h, int z);
218 virtual ~FGTexturedInstrumentLayer ();
220 virtual void draw () const;
222 virtual void setTexture (ssgTexture * texture) { _texture = texture; }
225 ssgTexture * _texture;
230 ////////////////////////////////////////////////////////////////////////
231 // A text layer of an instrument.
232 ////////////////////////////////////////////////////////////////////////
234 class FGCharInstrumentLayer : public FGInstrumentLayer
237 typedef char * (*text_func)(char *);
238 FGCharInstrumentLayer (text_func func,
239 int w, int h, int z);
240 virtual ~FGCharInstrumentLayer ();
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);
250 // FIXME: need only one globally
251 mutable fntRenderer _renderer;
252 mutable char _buf[1024];
257 #endif // __PANEL_HXX