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;
51 ////////////////////////////////////////////////////////////////////////
52 // Texture manager (should migrate out into FGFS).
53 ////////////////////////////////////////////////////////////////////////
55 class FGTextureManager
58 static ssgTexture * createTexture(const char * relativePath);
60 static map<const char *,ssgTexture *>_textureMap;
64 ////////////////////////////////////////////////////////////////////////
65 // Instrument panel class.
66 ////////////////////////////////////////////////////////////////////////
75 // transfer pointer ownership!!!
76 virtual void addInstrument (FGPanelInstrument * instrument);
77 virtual void init (int x, int y, int finx, int finy);
78 virtual void update () const;
80 virtual bool getVisibility () const;
81 virtual void setVisibility (bool visibility);
83 virtual bool doMouseAction (int button, int updown, int x, int y);
88 typedef vector<FGPanelInstrument *> instrument_list_type;
92 // List of instruments in panel.
93 instrument_list_type _instruments;
98 ////////////////////////////////////////////////////////////////////////
99 // Base class for user action types.
100 ////////////////////////////////////////////////////////////////////////
105 virtual void doAction () = 0;
110 ////////////////////////////////////////////////////////////////////////
111 // Adjustment action.
112 ////////////////////////////////////////////////////////////////////////
114 class FGAdjustAction : public FGPanelAction
117 typedef double (*getter_type)();
118 typedef void (*setter_type)(double);
120 FGAdjustAction (getter_type getter, setter_type setter, double increment,
121 double min, double max, bool wrap=false);
122 virtual ~FGAdjustAction ();
123 virtual void doAction ();
135 ////////////////////////////////////////////////////////////////////////
136 // Instrument base class.
137 ////////////////////////////////////////////////////////////////////////
139 class FGPanelInstrument
142 FGPanelInstrument ();
143 FGPanelInstrument (int x, int y, int w, int h);
144 virtual ~FGPanelInstrument ();
146 virtual void draw () const = 0;
148 virtual void setPosition(int x, int y);
149 virtual void setSize(int w, int h);
151 virtual int getXPos () const;
152 virtual int getYPos () const;
153 virtual int getWidth () const;
154 virtual int getHeight () const;
156 // Coordinates relative to centre.
157 // Transfer pointer ownership!!
158 virtual void addAction (int x, int y, int w, int h,
159 FGPanelAction * action);
161 // Coordinates relative to centre.
162 virtual bool doMouseAction (int button, int updown, int x, int y);
171 FGPanelAction * action;
173 typedef vector<inst_action> action_list_type;
174 action_list_type _actions;
179 ////////////////////////////////////////////////////////////////////////
180 // A single layer of an instrument.
181 ////////////////////////////////////////////////////////////////////////
184 * A single layer of a multi-layered instrument.
186 * Each layer can be subject to a series of transformations based
187 * on current FGFS instrument readings: for example, a texture
188 * representing a needle can rotate to show the airspeed.
190 class FGInstrumentLayer
199 typedef double (*transform_func)();
202 FGInstrumentLayer ();
203 FGInstrumentLayer (int w, int h, int z);
204 virtual ~FGInstrumentLayer ();
206 virtual void draw () const = 0;
207 virtual void transform () const;
209 virtual void addTransformation (transform_type type, transform_func func,
210 double min, double max,
211 double factor = 1.0, double offset = 0.0);
224 typedef vector<transformation *> transformation_list;
225 transformation_list _transformations;
230 ////////////////////////////////////////////////////////////////////////
231 // An instrument composed of layered textures.
232 ////////////////////////////////////////////////////////////////////////
236 * An instrument constructed of multiple layers.
238 * Each individual layer can be rotated or shifted to correspond
239 * to internal FGFS instrument readings.
241 class FGLayeredInstrument : public FGPanelInstrument
244 typedef vector<FGInstrumentLayer *> layer_list;
245 FGLayeredInstrument (int x, int y, int w, int h);
246 virtual ~FGLayeredInstrument ();
248 virtual void draw () const;
250 // Transfer pointer ownership!!
251 virtual void addLayer (FGInstrumentLayer *layer);
252 virtual void addLayer (int i, ssgTexture * texture);
253 virtual void addTransformation (int layer,
254 FGInstrumentLayer::transform_type type,
255 FGInstrumentLayer::transform_func func,
256 double min, double max,
257 double factor = 1.0, double offset = 0.0);
258 virtual void addTransformation (int layer,
259 FGInstrumentLayer::transform_type type,
261 addTransformation(layer, type, 0, 0.0, 0.0, 1.0, offset);
270 ////////////////////////////////////////////////////////////////////////
271 // A textured layer of an instrument.
272 ////////////////////////////////////////////////////////////////////////
275 * A textured layer of an instrument.
277 * This is a type of layer designed to hold a texture; normally,
278 * the texture's background should be transparent so that
279 * other layers or the panel background show through.
281 class FGTexturedInstrumentLayer : public FGInstrumentLayer
284 FGTexturedInstrumentLayer (ssgTexture * texture,
285 int w, int h, int z);
286 virtual ~FGTexturedInstrumentLayer ();
288 virtual void draw () const;
290 virtual void setTexture (ssgTexture * texture) { _texture = texture; }
293 ssgTexture * _texture;
298 ////////////////////////////////////////////////////////////////////////
299 // A text layer of an instrument.
300 ////////////////////////////////////////////////////////////////////////
302 class FGCharInstrumentLayer : public FGInstrumentLayer
305 typedef char * (*text_func)(char *);
306 FGCharInstrumentLayer (text_func func,
307 int w, int h, int z);
308 virtual ~FGCharInstrumentLayer ();
310 virtual void draw () const;
311 virtual void setColor (float r, float g, float b);
312 virtual void setPointSize (float size);
313 virtual void setFont (fntFont * font);
318 // FIXME: need only one globally
319 mutable fntRenderer _renderer;
320 mutable char _buf[1024];
325 ////////////////////////////////////////////////////////////////////////
326 // The current panel, if any.
327 ////////////////////////////////////////////////////////////////////////
329 extern FGPanel current_panel;
333 #endif // __PANEL_HXX