1
0
Fork 0
flightgear/src/Cockpit/panel.hxx

257 lines
6.3 KiB
C++
Raw Normal View History

// panel.hxx - default, 2D single-engine prop instrument panel
2000-02-15 03:30:01 +00:00
//
// Written by David Megginson, started January 2000.
//
1999-01-07 19:25:53 +00:00
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
1999-01-07 19:25:53 +00:00
// $Id$
2000-02-15 03:30:01 +00:00
#ifndef __PANEL_HXX
#define __PANEL_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
1998-11-09 23:38:50 +00:00
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
1999-01-07 19:25:53 +00:00
#ifdef HAVE_WINDOWS_H
1998-11-09 23:38:50 +00:00
# include <windows.h>
#endif
#include <GL/glut.h>
2000-02-15 03:30:01 +00:00
#include <plib/ssg.h>
1998-11-09 23:38:50 +00:00
#include <vector>
#include <plib/fnt.h>
FG_USING_STD(vector);
2000-02-15 03:30:01 +00:00
class FGPanelInstrument;
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
// Instrument panel class.
////////////////////////////////////////////////////////////////////////
2000-02-15 03:30:01 +00:00
class FGPanel
{
public:
typedef vector<FGPanelInstrument *> instrument_list_type;
2000-02-15 03:30:01 +00:00
FGPanel ();
virtual ~FGPanel ();
2000-02-15 03:30:01 +00:00
// Legacy interface from old panel.
static FGPanel * OurPanel;
virtual float get_height () const;
virtual void ReInit (int x, int y, int finx, int finy);
virtual void Update () const;
2000-02-15 03:30:01 +00:00
private:
int _x, _y, _w, _h;
int _panel_h;
ssgTexture * _bg;
instrument_list_type _instruments;
};
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
// Instrument base class.
////////////////////////////////////////////////////////////////////////
2000-02-15 03:30:01 +00:00
class FGPanelInstrument
{
public:
2000-02-15 03:30:01 +00:00
FGPanelInstrument ();
FGPanelInstrument (int x, int y, int w, int h);
virtual ~FGPanelInstrument ();
2000-02-15 03:30:01 +00:00
virtual void draw () const = 0;
2000-02-15 03:30:01 +00:00
virtual void setPosition(int x, int y);
virtual void setSize(int w, int h);
2000-02-15 03:30:01 +00:00
virtual int getXPos () const;
virtual int getYPos () const;
2000-02-15 03:30:01 +00:00
protected:
int _x, _y, _w, _h;
};
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
// A single layer of an instrument.
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
/**
* A single layer of a multi-layered instrument.
*
* Each layer can be subject to a series of transformations based
* on current FGFS instrument readings: for example, a texture
* representing a needle can rotate to show the airspeed.
*/
class FGInstrumentLayer
{
public:
typedef enum {
XSHIFT,
YSHIFT,
ROTATION
} transform_type;
2000-02-15 03:30:01 +00:00
typedef double (*transform_func)();
FGInstrumentLayer ();
FGInstrumentLayer (int w, int h, int z);
virtual ~FGInstrumentLayer ();
virtual void draw () const = 0;
virtual void transform () const;
virtual void addTransformation (transform_type type, transform_func func,
double min, double max,
double factor = 1.0, double offset = 0.0);
2000-02-15 03:30:01 +00:00
protected:
int _w, _h, _z;
typedef struct {
transform_type type;
transform_func func;
double min;
double max;
double factor;
double offset;
} transformation;
typedef vector<transformation *> transformation_list;
transformation_list _transformations;
};
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
// An instrument composed of layered textures.
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
/**
* An instrument constructed of multiple layers.
*
* Each individual layer can be rotated or shifted to correspond
* to internal FGFS instrument readings.
*/
class FGLayeredInstrument : public FGPanelInstrument
2000-02-15 03:30:01 +00:00
{
public:
typedef vector<FGInstrumentLayer *> layer_list;
FGLayeredInstrument (int x, int y, int w, int h);
virtual ~FGLayeredInstrument ();
virtual void draw () const;
virtual void addLayer (FGInstrumentLayer *layer);
virtual void addLayer (int i, const char *textureName);
virtual void addTransformation (int layer,
FGInstrumentLayer::transform_type type,
FGInstrumentLayer::transform_func func,
double min, double max,
double factor = 1.0, double offset = 0.0);
virtual void addTransformation (int layer,
FGInstrumentLayer::transform_type type,
double offset) {
addTransformation(layer, type, 0, 0.0, 0.0, 1.0, offset);
}
2000-02-15 03:30:01 +00:00
protected:
layer_list _layers;
2000-02-15 03:30:01 +00:00
};
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
// A textured layer of an instrument.
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
/**
* A textured layer of an instrument.
*
* This is a type of layer designed to hold a texture; normally,
* the texture's background should be transparent so that
* other layers or the panel background show through.
*/
class FGTexturedInstrumentLayer : public FGInstrumentLayer
2000-02-15 03:30:01 +00:00
{
public:
FGTexturedInstrumentLayer (const char * textureName,
int w, int h, int z);
FGTexturedInstrumentLayer (ssgTexture * texture,
int w, int h, int z);
virtual ~FGTexturedInstrumentLayer ();
virtual void draw () const;
virtual void setTexture (const char *textureName);
virtual void setTexture (ssgTexture * texture) { _texture = texture; }
2000-02-15 03:30:01 +00:00
private:
ssgTexture * _texture;
2000-02-15 03:30:01 +00:00
};
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
// A text layer of an instrument.
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
class FGCharInstrumentLayer : public FGInstrumentLayer
2000-02-15 03:30:01 +00:00
{
public:
typedef char * (*text_func)(char *);
FGCharInstrumentLayer (text_func func,
int w, int h, int z);
virtual ~FGCharInstrumentLayer ();
2000-02-15 03:30:01 +00:00
virtual void draw () const;
virtual void setColor (float r, float g, float b);
virtual void setPointSize (float size);
virtual void setFont (fntFont * font);
private:
text_func _func;
float _color[3];
// FIXME: need only one globally
mutable fntRenderer _renderer;
mutable char _buf[1024];
};
2000-02-15 03:30:01 +00:00
#endif // __PANEL_HXX
// end of panel.hxx
1998-11-09 23:38:50 +00:00