#include <string.h>
#include <plib/ssg.h>
-#include <GL/glut.h>
-#include <simgear/xgl/xgl.h>
+#include <plib/fnt.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
-
#include <Main/options.hxx>
+#include <Main/views.hxx>
#include <Objects/texload.h>
-#include <Autopilot/autopilot.hxx>
-#include "cockpit.hxx"
+#include "hud.hxx"
#include "panel.hxx"
-#define SIX_X 200
-#define SIX_Y 345
-#define SIX_W 128
-#define SIX_SPACING (SIX_W + 5)
-#define SMALL_W 112
-
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGPanel.
+// Implementation of FGTextureManager.
////////////////////////////////////////////////////////////////////////
-FGPanel * FGPanel::OurPanel = 0;
+map<const char *,ssgTexture *> FGTextureManager::_textureMap;
-FGPanel::FGPanel ()
+ssgTexture *
+FGTextureManager::createTexture (const char * relativePath)
{
- if (OurPanel == 0) {
- OurPanel = this;
- } else {
- FG_LOG(FG_GENERAL, FG_ALERT, "Multiple panels");
- exit(-1);
- }
+ ssgTexture *texture;
- int x = SIX_X;
- int y = SIX_Y;
+ texture = _textureMap[relativePath];
+ if (texture == 0) {
+ FGPath tpath(current_options.get_fg_root());
+ tpath.append(relativePath);
+ texture = new ssgTexture((char *)tpath.c_str(), false, false);
+ _textureMap[relativePath] = texture;
+ cerr << "Created texture " << relativePath
+ << " handle=" << texture->getHandle() << endl;
+ }
- FGPath tpath(current_options.get_fg_root());
- tpath.append("Textures/Panel/panel-bg.rgb");
- _bg = new ssgTexture((char *)tpath.c_str(), false, false);
+ return texture;
+}
- _airspeed = new FGAirspeedIndicator(x, y);
- x += SIX_SPACING;
- _horizon = new FGHorizon(x, y);
- x += SIX_SPACING;
- _altimeter = new FGAltimeter(x, y);
- x = SIX_X;
- y -= SIX_SPACING;
- _coordinator = new FGTurnCoordinator(x, y);
- x += SIX_SPACING;
- _gyro = new FGGyroCompass(x, y);
- x += SIX_SPACING;
- _vertical = new FGVerticalVelocity(x, y);
- y -= SIX_SPACING;
- _rpm = new FGRPMGauge(x, y);
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGPanel.
+////////////////////////////////////////////////////////////////////////
- x -= SIX_SPACING;
- _flaps = new FGFlapIndicator(x, y);
-}
+FGPanel * current_panel = NULL;
-FGPanel::~FGPanel ()
+FGPanel::FGPanel (int x, int y, int w, int h)
+ : _mouseDown(false),
+ _mouseInstrument(0),
+ _x(x), _y(y), _w(w), _h(h)
{
- OurPanel = 0;
- delete _airspeed;
- delete _horizon;
- delete _altimeter;
- delete _coordinator;
- delete _gyro;
- delete _vertical;
- delete _rpm;
- delete _flaps;
+ setVisibility(current_options.get_panel_status());
+ _panel_h = (int)(h * 0.5768 + 1);
}
-float
-FGPanel::get_height () const
+FGPanel::~FGPanel ()
{
- return _panel_h;
+ instrument_list_type::iterator current = _instruments.begin();
+ instrument_list_type::iterator last = _instruments.end();
+
+ for ( ; current != last; ++current) {
+ delete *current;
+ *current = 0;
+ }
}
void
-FGPanel::ReInit (int x, int y, int finx, int finy)
+FGPanel::addInstrument (FGPanelInstrument * instrument)
{
- _x = x;
- _y = y;
- _w = finx - x;
- _h = finy - y;
- _panel_h = (int)((finy - y) * 0.5768 + 1);
+ _instruments.push_back(instrument);
}
void
-FGPanel::Update () const
-{
- // glPushAttrib(GL_ALL_ATTRIB_BITS);
+FGPanel::update () const
+{
+ // Do nothing if the panel isn't visible.
+ if (!_visibility)
+ return;
+
+ // If the mouse is down, do something
+ if (_mouseDown) {
+ _mouseDelay--;
+ if (_mouseDelay < 0) {
+ _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
+ _mouseDelay = 2;
+ }
+ }
+ // Now, draw the panel
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glLoadIdentity();
// Draw the background
- glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
- if ( _bg->getHandle() >= 0 ) {
- glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
- } else {
- cout << "invalid texture handle in FGPanel::Update()" << endl;
- }
+ glDisable(GL_LIGHTING);
+ glEnable(GL_BLEND);
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_COLOR_MATERIAL);
+ glColor4f(1.0, 1.0, 1.0, 1.0);
+ glBindTexture(GL_TEXTURE_2D, _bg->getHandle());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex3f(_x, _y, 0);
glTexCoord2f(10.0, 0.0); glVertex3f(_x + _w, _y, 0);
glEnd();
// Draw the instruments.
- glLoadIdentity();
- glTranslated(_airspeed->getXPos(), _airspeed->getYPos(), 0);
- _airspeed->draw();
+ instrument_list_type::const_iterator current = _instruments.begin();
+ instrument_list_type::const_iterator end = _instruments.end();
+
+ for ( ; current != end; current++) {
+ FGPanelInstrument * instr = *current;
+ glLoadIdentity();
+ glTranslated(instr->getXPos(), instr->getYPos(), 0);
+ instr->draw();
+ }
- glLoadIdentity();
- glTranslated(_horizon->getXPos(), _horizon->getYPos(), 0);
- _horizon->draw();
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+ ssgForceBasicState();
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+}
- glLoadIdentity();
- glTranslated(_altimeter->getXPos(), _altimeter->getYPos(), 0);
- _altimeter->draw();
+void
+FGPanel::setVisibility (bool visibility)
+{
+ _visibility = visibility;
+}
- glLoadIdentity();
- glTranslated(_coordinator->getXPos(), _coordinator->getYPos(), 0);
- _coordinator->draw();
+bool
+FGPanel::getVisibility () const
+{
+ return _visibility;
+}
- glLoadIdentity();
- glTranslated(_gyro->getXPos(), _gyro->getYPos(), 0);
- _gyro->draw();
+void
+FGPanel::setBackground (ssgTexture * texture)
+{
+ _bg = texture;
+}
- glLoadIdentity();
- glTranslated(_vertical->getXPos(), _vertical->getYPos(), 0);
- _vertical->draw();
+bool
+FGPanel::doMouseAction (int button, int updown, int x, int y)
+{
+ // Note a released button and return
+ if (updown == 1) {
+ _mouseDown = false;
+ _mouseInstrument = 0;
+ return true;
+ }
- glLoadIdentity();
- glTranslated(_rpm->getXPos(), _rpm->getYPos(), 0);
- _rpm->draw();
+ x = (int)(((float)x / current_view.get_winWidth()) * _w);
+ y = (int)(_h - (((float)y / current_view.get_winHeight()) * _h));
+
+ for (int i = 0; i < _instruments.size(); i++) {
+ FGPanelInstrument *inst = _instruments[i];
+ int ix = inst->getXPos();
+ int iy = inst->getYPos();
+ int iw = inst->getWidth() / 2;
+ int ih = inst->getHeight() / 2;
+ if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
+ cout << "Do mouse action for component " << i << '\n';
+ _mouseDown = true;
+ _mouseDelay = 20;
+ _mouseInstrument = inst;
+ _mouseButton = button;
+ _mouseX = x - ix;
+ _mouseY = y - iy;
+ // Always do the action once.
+ _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
+ return true;
+ }
+ }
+ cout << "Did not click on an instrument\n";
+ return false;
+}
- glLoadIdentity();
- glTranslated(_flaps->getXPos(), _flaps->getYPos(), 0);
- _flaps->draw();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGAdjustAction.
+////////////////////////////////////////////////////////////////////////
+
+FGAdjustAction::FGAdjustAction (getter_type getter, setter_type setter,
+ double increment, double min, double max,
+ bool wrap=false)
+ : _getter(getter), _setter(setter), _increment(increment),
+ _min(min), _max(max), _wrap(wrap)
+{
+}
+
+FGAdjustAction::~FGAdjustAction ()
+{
+}
+
+void
+FGAdjustAction::doAction ()
+{
+ double value = (*_getter)();
+ cout << "Do action; value=" << value << '\n';
+ value += _increment;
+ if (value < _min) {
+ value = (_wrap ? _max : _min);
+ } else if (value > _max) {
+ value = (_wrap ? _min : _max);
+ }
+ cout << "New value is " << value << '\n';
+ (*_setter)(value);
+}
- // glPopAttrib();
-// ssgForceBasicState();
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGSwapAction.
+////////////////////////////////////////////////////////////////////////
+
+FGSwapAction::FGSwapAction (getter_type getter1, setter_type setter1,
+ getter_type getter2, setter_type setter2)
+ : _getter1(getter1), _setter1(setter1),
+ _getter2(getter2), _setter2(setter2)
+{
+}
+
+FGSwapAction::~FGSwapAction ()
+{
+}
+
+void
+FGSwapAction::doAction ()
+{
+ double value = (*_getter1)();
+ (*_setter1)((*_getter2)());
+ (*_setter2)(value);
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGToggleAction.
+////////////////////////////////////////////////////////////////////////
+
+FGToggleAction::FGToggleAction (getter_type getter, setter_type setter)
+ : _getter(getter), _setter(setter)
+{
+}
+
+FGToggleAction::~FGToggleAction ()
+{
+}
+
+void
+FGToggleAction::doAction ()
+{
+ (*_setter)(!((*_getter)()));
}
FGPanelInstrument::~FGPanelInstrument ()
{
+ action_list_type::iterator it = _actions.begin();
+ action_list_type::iterator last = _actions.end();
+ for ( ; it != last; it++) {
+ delete it->action;
+ }
}
void
return _y;
}
-
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of FGTexturedInstrument.
-////////////////////////////////////////////////////////////////////////
-
-FGTexturedInstrument::FGTexturedInstrument (int x, int y, int w, int h)
- : FGPanelInstrument(x, y, w, h)
-{
- for (int i = 0; i < MAX_LAYERS; i++) {
- _layers[i] = false;
- }
-}
-
-FGTexturedInstrument::~FGTexturedInstrument ()
-{
- // FIXME: maybe free textures
-}
-
-void
-FGTexturedInstrument::addLayer (int layer, const char * textureName)
-{
- FGPath tpath(current_options.get_fg_root());
- tpath.append(textureName);
- ssgTexture * texture = new ssgTexture((char *)tpath.c_str(), false, false);
- cerr << "Loaded texture " << textureName << endl;
- addLayer(layer, texture);
-}
-
-void
-FGTexturedInstrument::addLayer (int layer, ssgTexture * texture)
-{
- _layers[layer] = true;
- _textures[layer] = texture;
- _rotation[layer] = 0.0;
- _xoffset[layer] = _yoffset[layer] = 0;
- _xcenter[layer] = _ycenter[layer] = 0;
-}
-
-void
-FGTexturedInstrument::setLayerCenter (int layer, int x, int y)
+int
+FGPanelInstrument::getWidth () const
{
- _xcenter[layer] = x;
- _ycenter[layer] = y;
+ return _w;
}
-void
-FGTexturedInstrument::setLayerRot (int layer, double rotation) const
+int
+FGPanelInstrument::getHeight () const
{
- _rotation[layer] = rotation;
+ return _h;
}
void
-FGTexturedInstrument::setLayerOffset (int layer, int xoff, int yoff) const
+FGPanelInstrument::addAction (int button, int x, int y, int w, int h,
+ FGPanelAction * action)
{
- _xoffset[layer] = xoff;
- _yoffset[layer] = yoff;
+ FGPanelInstrument::inst_action act;
+ act.button = button;
+ act.x = x;
+ act.y = y;
+ act.w = w;
+ act.h = h;
+ act.action = action;
+ _actions.push_back(act);
}
+ // Coordinates relative to centre.
bool
-FGTexturedInstrument::hasLayer (int layer) const
-{
- return _layers[layer];
-}
-
-void
-FGTexturedInstrument::draw () const
-{
- glEnable(GL_TEXTURE_2D);
-
- int i;
- int w2 = _w / 2;
- int h2 = _h / 2;
-
- glMatrixMode(GL_MODELVIEW);
- for (i = 0; i < MAX_LAYERS; i++) {
- if (hasLayer(i)) {
- glPushMatrix();
- glTranslated(_xcenter[i], _ycenter[i], 0);
- glRotatef(0.0 - _rotation[i], 0.0, 0.0, 1.0);
- glTranslated(_xoffset[i], _yoffset[i], 0);
- if ( _textures[i]->getHandle() >= 0 ) {
- glBindTexture(GL_TEXTURE_2D, _textures[i]->getHandle());
- } else {
- cout << "invalid texture handle in FGTexturedInstrument::draw()"
- << endl;
- }
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glBegin(GL_POLYGON);
- // FIXME: is this really correct
- // for layering?
- glTexCoord2f(0.0, 0.0); glVertex3f(-w2, -h2, i / 100.0 + 0.1);
- glTexCoord2f(1.0, 0.0); glVertex3f(w2, -h2, i / 100.0 + 0.1);
- glTexCoord2f(1.0, 1.0); glVertex3f(w2, h2, i / 100.0 + 0.1);
- glTexCoord2f(0.0, 1.0); glVertex3f(-w2, h2, i / 100.0 + 0.1);
- glEnd();
- glPopMatrix();
+FGPanelInstrument::doMouseAction (int button, int x, int y)
+{
+ action_list_type::iterator it = _actions.begin();
+ action_list_type::iterator last = _actions.end();
+ cout << "Mouse action at " << x << ',' << y << '\n';
+ for ( ; it != last; it++) {
+ cout << "Trying action at " << it->x << ',' << it->y << ','
+ << it->w <<',' << it->h << '\n';
+ if (button == it->button &&
+ x >= it->x && x < it->x + it->w && y >= it->y && y < it->y + it->h) {
+ it->action->doAction();
+ return true;
}
}
-
- glDisable(GL_TEXTURE_2D);
+ return false;
}
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGAirspeedIndicator.
+// Implementation of FGLayeredInstrument.
////////////////////////////////////////////////////////////////////////
-FGAirspeedIndicator::FGAirspeedIndicator (int x, int y)
- : FGTexturedInstrument(x, y, SIX_W, SIX_W)
+FGLayeredInstrument::FGLayeredInstrument (int x, int y, int w, int h)
+ : FGPanelInstrument(x, y, w, h)
{
- addLayer(0, "Textures/Panel/airspeed.rgb");
- addLayer(1, "Textures/Panel/long-needle.rgb");
}
-FGAirspeedIndicator::~FGAirspeedIndicator ()
+FGLayeredInstrument::~FGLayeredInstrument ()
{
+ // FIXME: free layers
}
void
-FGAirspeedIndicator::draw () const
+FGLayeredInstrument::draw () const
{
- double speed = get_speed();
- if (speed < 30.0) {
- speed = 30.0;
- } else if (speed > 220.0) {
- speed = 220.0;
+ for (int i = 0; i < _layers.size(); i++) {
+ glPushMatrix();
+ glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
+ _layers[i]->draw();
+ glPopMatrix();
}
- double angle = speed / 20.0 * 36.0 - 54.0;
- setLayerRot(1, angle);
- FGTexturedInstrument::draw();
}
+int
+FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
+{
+ int n = _layers.size();
+ _layers.push_back(layer);
+ return n;
+}
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of FGHorizon.
-////////////////////////////////////////////////////////////////////////
-
-FGHorizon::FGHorizon (int x, int y)
- : FGTexturedInstrument(x, y, SIX_W, SIX_W)
+int
+FGLayeredInstrument::addLayer (ssgTexture * texture)
{
- addLayer(0, "Textures/Panel/horizon-bg.rgb");
- addLayer(1, "Textures/Panel/horizon-float.rgb");
- addLayer(2, "Textures/Panel/horizon-rim.rgb");
- addLayer(3, "Textures/Panel/horizon-fg.rgb");
+ return addLayer(new FGTexturedLayer(texture, _w, _h));
}
-FGHorizon::~FGHorizon ()
+void
+FGLayeredInstrument::addTransformation (FGInstrumentLayer::transform_type type,
+ FGInstrumentLayer::transform_func func,
+ double min, double max,
+ double factor, double offset)
{
+ int layer = _layers.size() - 1;
+ _layers[layer]->addTransformation(type, func, min, max, factor, offset);
}
void
-FGHorizon::draw () const
+FGLayeredInstrument::addTransformation (FGInstrumentLayer::transform_type type,
+ double offset)
{
- double rot = get_roll() * RAD_TO_DEG;
- double pitch = get_pitch() * RAD_TO_DEG;
- if (pitch > 20)
- pitch = 20;
- else if (pitch < -20)
- pitch = -20;
- int yoffset = 0 - (pitch * ((1.5 / 160.0) * _h));
- setLayerRot(0, 0 - rot);
- setLayerRot(1, 0 - rot);
- setLayerOffset(1, 0, yoffset);
- setLayerRot(2, 0 - rot);
- FGTexturedInstrument::draw();
+ addTransformation(type, 0, 0.0, 0.0, 1.0, offset);
}
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGAltimeter.
+// Implementation of FGInstrumentLayer.
////////////////////////////////////////////////////////////////////////
-// TODO: add 10,000 bug
-
-FGAltimeter::FGAltimeter (int x, int y)
- : FGTexturedInstrument(x, y, SIX_W, SIX_W)
+FGInstrumentLayer::FGInstrumentLayer (int w, int h)
+ : _w(w),
+ _h(h)
{
- addLayer(0, "Textures/Panel/altimeter.rgb");
- addLayer(1, "Textures/Panel/long-needle.rgb");
- addLayer(2, "Textures/Panel/short-needle.rgb");
- addLayer(3, "Textures/Panel/bug.rgb");
}
-FGAltimeter::~FGAltimeter ()
+FGInstrumentLayer::~FGInstrumentLayer ()
{
+ transformation_list::iterator it = _transformations.begin();
+ transformation_list::iterator end = _transformations.end();
+ while (it != end) {
+ delete *it;
+ it++;
+ }
}
void
-FGAltimeter::draw () const
+FGInstrumentLayer::transform () const
+{
+ transformation_list::const_iterator it = _transformations.begin();
+ transformation_list::const_iterator last = _transformations.end();
+ while (it != last) {
+ transformation *t = *it;
+ double value = (t->func == 0 ? 0.0 : (*(t->func))());
+ if (value < t->min) {
+ value = t->min;
+ } else if (value > t->max) {
+ value = t->max;
+ }
+ value = value * t->factor + t->offset;
+
+ switch (t->type) {
+ case XSHIFT:
+ glTranslatef(value, 0.0, 0.0);
+ break;
+ case YSHIFT:
+ glTranslatef(0.0, value, 0.0);
+ break;
+ case ROTATION:
+ glRotatef(-value, 0.0, 0.0, 1.0);
+ break;
+ }
+ it++;
+ }
+}
+
+void
+FGInstrumentLayer::addTransformation (transform_type type,
+ transform_func func,
+ double min, double max,
+ double factor, double offset)
{
- long altitude = get_altitude();
- setLayerRot(1, (altitude % 1000) / 1000.0 * 360.0);
- setLayerRot(2, (altitude % 10000) / 10000.0 * 360.0);
- setLayerRot(3, (altitude % 100000) / 100000.0 * 360.0);
- FGTexturedInstrument::draw();
+ transformation *t = new transformation;
+ t->type = type;
+ t->func = func;
+ t->min = min;
+ t->max = max;
+ t->factor = factor;
+ t->offset = offset;
+ _transformations.push_back(t);
}
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGTurnCoordinator.
+// Implementation of FGTexturedLayer.
////////////////////////////////////////////////////////////////////////
-// TODO: add slip/skid ball
-
-FGTurnCoordinator::FGTurnCoordinator (int x, int y)
- : FGTexturedInstrument(x, y, SIX_W, SIX_W)
+FGTexturedLayer::FGTexturedLayer (ssgTexture * texture, int w, int h,
+ double texX1 = 0.0, double texY1 = 0.0,
+ double texX2 = 1.0, double texY2 = 1.0)
+ : FGInstrumentLayer(w, h),
+ _texX1(texX1), _texY1(texY1), _texX2(texX2), _texY2(texY2)
{
- addLayer(0, "Textures/Panel/turn-bg.rgb");
- addLayer(1, "Textures/Panel/turn.rgb");
- addLayer(2, "Textures/Panel/ball.rgb");
+ setTexture(texture);
}
-FGTurnCoordinator::~FGTurnCoordinator ()
+FGTexturedLayer::~FGTexturedLayer ()
{
}
void
-FGTurnCoordinator::draw () const
-{
- // Set little plane
- // FIXME: this should be turn, maybe
- double rot = get_roll() * RAD_TO_DEG;
- if (rot > 30.0)
- rot = 30.0;
- else if (rot < -30.0)
- rot = -30.0;
- setLayerRot(1, rot);
-
- // Set ball
- // FIXME: totally bogus values
- double slip = get_sideslip() * 450;
- if (slip > 45) {
- slip = 45;
- } else if (slip < -45) {
- slip = -45;
- }
- setLayerRot(2, 0 - slip);
+FGTexturedLayer::draw () const
+{
+ int w2 = _w / 2;
+ int h2 = _h / 2;
+
+ transform();
+ glBindTexture(GL_TEXTURE_2D, _texture->getHandle());
+ glBegin(GL_POLYGON);
- FGTexturedInstrument::draw();
+ glTexCoord2f(_texX1, _texY1); glVertex2f(-w2, -h2);
+ glTexCoord2f(_texX2, _texY1); glVertex2f(w2, -h2);
+ glTexCoord2f(_texX2, _texY2); glVertex2f(w2, h2);
+ glTexCoord2f(_texX1, _texY2); glVertex2f(-w2, h2);
+ glEnd();
}
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGGyroCompass.
+// Implementation of FGTextLayer.
////////////////////////////////////////////////////////////////////////
-// TODO: add heading bug
-
-FGGyroCompass::FGGyroCompass (int x, int y)
- : FGTexturedInstrument(x, y, SIX_W, SIX_W)
+FGTextLayer::FGTextLayer (int w, int h)
+ : FGInstrumentLayer(w, h)
{
- addLayer(0, "Textures/Panel/gyro-bg.rgb");
- addLayer(1, "Textures/Panel/bug.rgb");
- addLayer(2, "Textures/Panel/gyro-fg.rgb");
+ _color[0] = _color[1] = _color[2] = 0.0;
+ _color[3] = 1.0;
}
-FGGyroCompass::~FGGyroCompass ()
+FGTextLayer::~FGTextLayer ()
{
+ chunk_list::iterator it = _chunks.begin();
+ chunk_list::iterator last = _chunks.end();
+ for ( ; it != last; it++) {
+ delete *it;
+ }
}
void
-FGGyroCompass::draw () const
+FGTextLayer::draw () const
{
- setLayerRot(0, 0.0 - get_heading());
- setLayerRot(1, 0.0 - get_heading() + fgAPget_TargetHeading());
- FGTexturedInstrument::draw();
-}
+ glPushMatrix();
+ glColor4fv(_color);
+ transform();
+ _renderer.setFont(guiFntHandle);
+ _renderer.setPointSize(14);
+ _renderer.begin();
+ _renderer.start3f(0, 0, 0);
+
+ // Render each of the chunks.
+ chunk_list::const_iterator it = _chunks.begin();
+ chunk_list::const_iterator last = _chunks.end();
+ for ( ; it != last; it++) {
+ _renderer.puts((*it)->getValue());
+ }
+ _renderer.end();
+ glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
+ glPopMatrix();
+}
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of FGVerticalVelocity.
-////////////////////////////////////////////////////////////////////////
+void
+FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
+{
+ _chunks.push_back(chunk);
+}
-FGVerticalVelocity::FGVerticalVelocity (int x, int y)
- : FGTexturedInstrument(x, y, SIX_W, SIX_W)
+void
+FGTextLayer::setColor (float r, float g, float b)
{
- addLayer(0, "Textures/Panel/vertical.rgb");
- addLayer(1, "Textures/Panel/long-needle.rgb");
+ _color[0] = r;
+ _color[1] = g;
+ _color[2] = b;
+ _color[3] = 1.0;
}
-FGVerticalVelocity::~FGVerticalVelocity ()
+void
+FGTextLayer::setPointSize (const float size)
{
+ _renderer.setPointSize(size);
}
void
-FGVerticalVelocity::draw () const
+FGTextLayer::setFont(fntFont * font)
{
- double climb = get_climb_rate() / 500.0;
- if (climb < -4.0) {
- climb = -4.0;
- } else if (climb > 4.0) {
- climb = 4.0;
- }
- double rot = (climb * 42.0) + 270.0;
- // FIXME: why inverted?
- setLayerRot(1, rot);
- FGTexturedInstrument::draw();
+ _renderer.setFont(font);
}
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGRPMGauge.
+// Implementation of FGTextLayer::Chunk.
////////////////////////////////////////////////////////////////////////
-FGRPMGauge::FGRPMGauge (int x, int y)
- : FGTexturedInstrument(x, y, SMALL_W, SMALL_W)
+FGTextLayer::Chunk::Chunk (char * text, char * fmt = "%s")
+ : _type(FGTextLayer::TEXT), _fmt(fmt)
{
- addLayer(0, "Textures/Panel/rpm.rgb");
- addLayer(1, "Textures/Panel/long-needle.rgb");
+ _value._text = text;
}
-FGRPMGauge::~FGRPMGauge ()
+FGTextLayer::Chunk::Chunk (text_func func, char * fmt = "%s")
+ : _type(FGTextLayer::TEXT_FUNC), _fmt(fmt)
{
+ _value._tfunc = func;
}
-void
-FGRPMGauge::draw () const
+FGTextLayer::Chunk::Chunk (double_func func, char * fmt = "%.2f",
+ double mult = 1.0)
+ : _type(FGTextLayer::DOUBLE_FUNC), _fmt(fmt), _mult(mult)
{
- double rot = get_throttleval() * 300 - 150;
- setLayerRot(1, rot);
- FGTexturedInstrument::draw();
+ _value._dfunc = func;
+}
+
+char *
+FGTextLayer::Chunk::getValue () const
+{
+ switch (_type) {
+ case TEXT:
+ sprintf(_buf, _fmt, _value._text);
+ return _buf;
+ case TEXT_FUNC:
+ sprintf(_buf, _fmt, (*(_value._tfunc))());
+ break;
+ case DOUBLE_FUNC:
+ sprintf(_buf, _fmt, (*(_value._dfunc))() * _mult);
+ break;
+ }
+ return _buf;
}
\f
////////////////////////////////////////////////////////////////////////
-// Implementation of FGFlapIndicator.
+// Implementation of FGSwitchLayer.
////////////////////////////////////////////////////////////////////////
-FGFlapIndicator::FGFlapIndicator (int x, int y)
- : FGTexturedInstrument(x, y, SMALL_W, SMALL_W)
+FGSwitchLayer::FGSwitchLayer (int w, int h, switch_func func,
+ FGInstrumentLayer * layer1,
+ FGInstrumentLayer * layer2)
+ : FGInstrumentLayer(w, h), _func(func), _layer1(layer1), _layer2(layer2)
{
- addLayer(0, "Textures/Panel/flaps.rgb");
- addLayer(1, "Textures/Panel/long-needle.rgb");
- setLayerCenter(1, 0 - (SMALL_W / 4) + (SMALL_W / 16), 0);
}
-FGFlapIndicator::~FGFlapIndicator ()
+FGSwitchLayer::~FGSwitchLayer ()
{
+ delete _layer1;
+ delete _layer2;
}
void
-FGFlapIndicator::draw () const
+FGSwitchLayer::draw () const
{
- double rot = controls.get_flaps() * 120 + 30;
- setLayerRot(1, rot);
- FGTexturedInstrument::draw();
+ transform();
+ if ((*_func)()) {
+ _layer1->draw();
+ } else {
+ _layer2->draw();
+ }
}
-
\f
// end of panel.cxx