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

338 lines
8.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 <map>
#include <plib/fnt.h>
FG_USING_STD(vector);
FG_USING_STD(map);
2000-02-15 03:30:01 +00:00
class FGPanelInstrument;
////////////////////////////////////////////////////////////////////////
// Texture manager (should migrate out into FGFS).
////////////////////////////////////////////////////////////////////////
class FGTextureManager
{
public:
static ssgTexture * createTexture(const char * relativePath);
private:
static map<const char *,ssgTexture *>_textureMap;
};
2000-02-15 03:30:01 +00:00
////////////////////////////////////////////////////////////////////////
// Instrument panel class.
////////////////////////////////////////////////////////////////////////
2000-02-15 03:30:01 +00:00
class FGPanel
{
public:
2000-02-15 03:30:01 +00:00
FGPanel ();
virtual ~FGPanel ();
// transfer pointer ownership!!!
virtual void addInstrument (FGPanelInstrument * instrument);
virtual void init (int x, int y, int finx, int finy);
virtual void update () const;
virtual bool getVisibility () const;
virtual void setVisibility (bool visibility);
virtual bool doMouseAction (int button, int updown, int x, int y);
2000-02-15 03:30:01 +00:00
private:
bool _initialized;
bool _visibility;
typedef vector<FGPanelInstrument *> instrument_list_type;
2000-02-15 03:30:01 +00:00
int _x, _y, _w, _h;
int _panel_h;
ssgTexture * _bg;
// List of instruments in panel.
instrument_list_type _instruments;
};
////////////////////////////////////////////////////////////////////////
// Base class for user action types.
////////////////////////////////////////////////////////////////////////
class FGPanelAction
{
public:
virtual void doAction () = 0;
};
////////////////////////////////////////////////////////////////////////
// Adjustment action.
////////////////////////////////////////////////////////////////////////
class FGAdjustAction : public FGPanelAction
{
public:
typedef double (*getter_type)();
typedef void (*setter_type)(double);
FGAdjustAction (getter_type getter, setter_type setter, double increment,
double min, double max, bool wrap=false);
virtual ~FGAdjustAction ();
virtual void doAction ();
private:
getter_type _getter;
setter_type _setter;
double _increment;
double _min;
double _max;
bool _wrap;
};
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;
virtual int getWidth () const;
virtual int getHeight () const;
// Coordinates relative to centre.
// Transfer pointer ownership!!
virtual void addAction (int x, int y, int w, int h,
FGPanelAction * action);
// Coordinates relative to centre.
virtual bool doMouseAction (int button, int updown, int x, int y);
2000-02-15 03:30:01 +00:00
protected:
int _x, _y, _w, _h;
typedef struct {
int x;
int y;
int w;
int h;
FGPanelAction * action;
} inst_action;
typedef vector<inst_action> action_list_type;
action_list_type _actions;
};
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;
// Transfer pointer ownership!!
virtual void addLayer (FGInstrumentLayer *layer);
virtual void addLayer (int i, ssgTexture * texture);
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 (ssgTexture * texture,
int w, int h, int z);
virtual ~FGTexturedInstrumentLayer ();
virtual void draw () const;
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;
2000-03-17 06:16:15 +00:00
float _color[4];
// FIXME: need only one globally
mutable fntRenderer _renderer;
mutable char _buf[1024];
};
////////////////////////////////////////////////////////////////////////
// The current panel, if any.
////////////////////////////////////////////////////////////////////////
extern FGPanel current_panel;
2000-02-15 03:30:01 +00:00
#endif // __PANEL_HXX
// end of panel.hxx
1998-11-09 23:38:50 +00:00