2000-02-21 22:00:24 +00:00
|
|
|
|
// 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-12-23 17:37:18 +00:00
|
|
|
|
//
|
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.
|
1998-11-11 00:19:27 +00:00
|
|
|
|
//
|
1999-01-07 19:25:53 +00:00
|
|
|
|
// $Id$
|
1999-05-12 02:04:38 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
#ifndef __PANEL_HXX
|
|
|
|
|
#define __PANEL_HXX
|
1998-06-27 16:47:53 +00:00
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
#include <vector>
|
2000-03-21 22:06:05 +00:00
|
|
|
|
#include <map>
|
2000-02-21 22:00:24 +00:00
|
|
|
|
#include <plib/fnt.h>
|
|
|
|
|
|
|
|
|
|
FG_USING_STD(vector);
|
2000-03-21 22:06:05 +00:00
|
|
|
|
FG_USING_STD(map);
|
2000-02-21 22:00:24 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
class FGPanelInstrument;
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-04-27 22:45:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// 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.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
class FGPanel
|
|
|
|
|
{
|
|
|
|
|
public:
|
2000-02-21 22:00:24 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
FGPanel ();
|
1999-12-23 17:37:18 +00:00
|
|
|
|
virtual ~FGPanel ();
|
|
|
|
|
|
2000-04-27 22:45:48 +00:00
|
|
|
|
// 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);
|
2000-02-26 18:01:13 +00:00
|
|
|
|
|
2000-04-27 22:45:48 +00:00
|
|
|
|
virtual bool doMouseAction (int button, int updown, int x, int y);
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
private:
|
2000-04-27 22:45:48 +00:00
|
|
|
|
bool _initialized;
|
|
|
|
|
bool _visibility;
|
2000-02-26 18:01:13 +00:00
|
|
|
|
typedef vector<FGPanelInstrument *> instrument_list_type;
|
2000-02-15 03:30:01 +00:00
|
|
|
|
int _x, _y, _w, _h;
|
|
|
|
|
int _panel_h;
|
|
|
|
|
ssgTexture * _bg;
|
2000-02-26 18:01:13 +00:00
|
|
|
|
// List of instruments in panel.
|
2000-02-21 22:00:24 +00:00
|
|
|
|
instrument_list_type _instruments;
|
1999-03-08 21:56:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-04-27 22:45:48 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// 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.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
class FGPanelInstrument
|
|
|
|
|
{
|
1999-12-23 17:37:18 +00:00
|
|
|
|
public:
|
2000-02-15 03:30:01 +00:00
|
|
|
|
FGPanelInstrument ();
|
|
|
|
|
FGPanelInstrument (int x, int y, int w, int h);
|
|
|
|
|
virtual ~FGPanelInstrument ();
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
virtual void draw () const = 0;
|
1999-03-08 21:56:08 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
virtual void setPosition(int x, int y);
|
|
|
|
|
virtual void setSize(int w, int h);
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
virtual int getXPos () const;
|
|
|
|
|
virtual int getYPos () const;
|
2000-04-27 22:45:48 +00:00
|
|
|
|
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);
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
protected:
|
|
|
|
|
int _x, _y, _w, _h;
|
2000-04-27 22:45:48 +00:00
|
|
|
|
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;
|
1999-03-08 21:56:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2000-02-21 22:00:24 +00:00
|
|
|
|
// A single layer of an instrument.
|
2000-02-15 03:30:01 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +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
|
1999-12-23 17:37:18 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2000-02-21 22:00:24 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
XSHIFT,
|
|
|
|
|
YSHIFT,
|
|
|
|
|
ROTATION
|
|
|
|
|
} transform_type;
|
2000-02-15 03:30:01 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
typedef double (*transform_func)();
|
1999-03-08 21:56:08 +00:00
|
|
|
|
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
FGInstrumentLayer ();
|
|
|
|
|
FGInstrumentLayer (int w, int h, int z);
|
|
|
|
|
virtual ~FGInstrumentLayer ();
|
1999-03-08 21:56:08 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
virtual void draw () const = 0;
|
|
|
|
|
virtual void transform () const;
|
1999-03-08 21:56:08 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
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
|
|
|
|
|
2000-02-21 22:00:24 +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;
|
1999-12-23 17:37:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2000-02-21 22:00:24 +00:00
|
|
|
|
// An instrument composed of layered textures.
|
2000-02-15 03:30:01 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2000-02-21 22:00:24 +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:
|
2000-02-21 22:00:24 +00:00
|
|
|
|
typedef vector<FGInstrumentLayer *> layer_list;
|
|
|
|
|
FGLayeredInstrument (int x, int y, int w, int h);
|
|
|
|
|
virtual ~FGLayeredInstrument ();
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
virtual void draw () const;
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-04-27 22:45:48 +00:00
|
|
|
|
// Transfer pointer ownership!!
|
2000-02-21 22:00:24 +00:00
|
|
|
|
virtual void addLayer (FGInstrumentLayer *layer);
|
2000-02-26 18:01:13 +00:00
|
|
|
|
virtual void addLayer (int i, ssgTexture * texture);
|
2000-02-21 22:00:24 +00:00
|
|
|
|
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
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
protected:
|
|
|
|
|
layer_list _layers;
|
2000-02-15 03:30:01 +00:00
|
|
|
|
};
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2000-02-21 22:00:24 +00:00
|
|
|
|
// A textured layer of an instrument.
|
2000-02-15 03:30:01 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2000-02-21 22:00:24 +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:
|
2000-02-21 22:00:24 +00:00
|
|
|
|
FGTexturedInstrumentLayer (ssgTexture * texture,
|
|
|
|
|
int w, int h, int z);
|
|
|
|
|
virtual ~FGTexturedInstrumentLayer ();
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
virtual void draw () const;
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
virtual void setTexture (ssgTexture * texture) { _texture = texture; }
|
2000-02-15 03:30:01 +00:00
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
private:
|
|
|
|
|
ssgTexture * _texture;
|
2000-02-15 03:30:01 +00:00
|
|
|
|
};
|
1999-12-23 17:37:18 +00:00
|
|
|
|
|
2000-02-15 03:30:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2000-02-21 22:00:24 +00:00
|
|
|
|
// A text layer of an instrument.
|
2000-02-15 03:30:01 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2000-02-21 22:00:24 +00:00
|
|
|
|
class FGCharInstrumentLayer : public FGInstrumentLayer
|
2000-02-15 03:30:01 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2000-02-21 22:00:24 +00:00
|
|
|
|
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;
|
2000-02-21 22:00:24 +00:00
|
|
|
|
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];
|
2000-02-21 22:00:24 +00:00
|
|
|
|
// FIXME: need only one globally
|
|
|
|
|
mutable fntRenderer _renderer;
|
|
|
|
|
mutable char _buf[1024];
|
1999-12-23 17:37:18 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2000-04-27 22:45:48 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// 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
|
|
|
|
|