#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
-#include <Main/options.hxx>
-#include <Main/views.hxx>
+
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include <Objects/texload.h>
+#include <Time/light.hxx>
#include "hud.hxx"
#include "panel.hxx"
+bool
+fgPanelVisible ()
+{
+ return ((globals->get_options()->get_panel_status()) &&
+ (globals->get_viewmgr()->get_current() == 0) &&
+ (globals->get_current_view()->get_view_offset() == 0.0));
+}
+
+
\f
////////////////////////////////////////////////////////////////////////
// Implementation of FGTextureManager.
ssgTexture * texture = _textureMap[relativePath];
if (texture == 0) {
cerr << "Texture " << relativePath << " does not yet exist" << endl;
- FGPath tpath(current_options.get_fg_root());
+ FGPath tpath(globals->get_options()->get_fg_root());
tpath.append(relativePath);
texture = new ssgTexture((char *)tpath.c_str(), false, false);
_textureMap[relativePath] = texture;
////////////////////////////////////////////////////////////////////////
FGPanel * current_panel = NULL;
+static fntRenderer text_renderer;
+
-FGPanel::FGPanel (int x, int y, int w, int h)
+/**
+ * Constructor.
+ */
+FGPanel::FGPanel (int window_x, int window_y, int window_w, int window_h)
: _mouseDown(false),
_mouseInstrument(0),
- _x(x), _y(y), _w(w), _h(h)
+ _winx(window_x), _winy(window_y), _winw(window_w), _winh(window_h),
+ _width(_winw), _height(int(_winh * 0.5768 + 1)),
+ _x_offset(0), _y_offset(0), _view_height(int(_winh * 0.4232))
{
- setVisibility(current_options.get_panel_status());
- _panel_h = (int)(h * 0.5768 + 1);
+ setVisibility(fgPanelVisible());
}
+
+/**
+ * Destructor.
+ */
FGPanel::~FGPanel ()
{
+ unbind();
for (instrument_list_type::iterator it = _instruments.begin();
it != _instruments.end();
it++) {
}
}
+
+/**
+ * Add an instrument to the panel.
+ */
void
FGPanel::addInstrument (FGPanelInstrument * instrument)
{
_instruments.push_back(instrument);
}
+
+/**
+ * Initialize the panel.
+ */
+void
+FGPanel::init ()
+{
+ // NO-OP
+}
+
+
+/**
+ * Bind panel properties.
+ */
+void
+FGPanel::bind ()
+{
+ fgTie("/sim/panel/visibility", &_visibility);
+ fgTie("/sim/panel/x-offset", &_x_offset);
+ fgTie("/sim/panel/y-offset", &_y_offset);
+}
+
+
+/**
+ * Unbind panel properties.
+ */
+void
+FGPanel::unbind ()
+{
+ fgUntie("/sim/panel/visibility");
+ fgUntie("/sim/panel/x-offset");
+ fgUntie("/sim/panel/y-offset");
+}
+
+
+/**
+ * Update the panel.
+ */
void
-FGPanel::update () const
+FGPanel::update ()
{
// Do nothing if the panel isn't visible.
- if (!_visibility)
+ if (!fgPanelVisible())
return;
// If the mouse is down, do something
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
- gluOrtho2D(_x, _x + _w, _y, _y + _h);
+ gluOrtho2D(_winx, _winx + _winw, _winy, _winy + _winh);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
+ glTranslated(_x_offset, _y_offset, 0);
+
// Draw the background
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
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);
- glTexCoord2f(10.0, 5.0); glVertex3f(_x + _w, _y + _panel_h, 0);
- glTexCoord2f(0.0, 5.0); glVertex3f(_x, _y + _panel_h, 0);
+ glTexCoord2f(0.0, 0.0); glVertex3f(_winx, _winy, 0);
+ glTexCoord2f(1.0, 0.0); glVertex3f(_winx + _width, _winy, 0);
+ glTexCoord2f(1.0, 1.0); glVertex3f(_winx + _width, _winy + _height, 0);
+ glTexCoord2f(0.0, 1.0); glVertex3f(_winx, _winy + _height, 0);
glEnd();
// Draw the instruments.
for ( ; current != end; current++) {
FGPanelInstrument * instr = *current;
glLoadIdentity();
+ glTranslated(_x_offset, _y_offset, 0);
glTranslated(instr->getXPos(), instr->getYPos(), 0);
instr->draw();
}
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
+
+/**
+ * Set the panel's visibility.
+ */
void
FGPanel::setVisibility (bool visibility)
{
_visibility = visibility;
}
+
+/**
+ * Return true if the panel is visible.
+ */
bool
FGPanel::getVisibility () const
{
return _visibility;
}
+
+/**
+ * Set the panel's background texture.
+ */
void
FGPanel::setBackground (ssgTexture * texture)
{
_bg = texture;
}
+
+/**
+ * Set the panel's x-offset.
+ */
+void
+FGPanel::setXOffset (int offset)
+{
+ if (offset <= 0 && offset >= -_width + _winw)
+ _x_offset = offset;
+}
+
+
+/**
+ * Set the panel's y-offset.
+ */
+void
+FGPanel::setYOffset (int offset)
+{
+ if (offset <= 0 && offset >= -_height)
+ _y_offset = offset;
+}
+
+
+/**
+ * Perform a mouse action.
+ */
bool
FGPanel::doMouseAction (int button, int updown, int x, int y)
{
+
// Note a released button and return
// cerr << "Doing mouse action\n";
if (updown == 1) {
return true;
}
- x = (int)(((float)x / current_view.get_winWidth()) * _w);
- y = (int)(_h - (((float)y / current_view.get_winHeight()) * _h));
+ // Scale for the real window size.
+ x = int(((float)x / globals->get_options()->get_xsize()) * _winw);
+ y = int(_winh - (((float)y / globals->get_options()->get_ysize())
+ * _winh));
+ // Adjust for offsets.
+ x -= _x_offset;
+ y -= _y_offset;
+
+ // Search for a matching instrument.
for (int i = 0; i < (int)_instruments.size(); i++) {
FGPanelInstrument *inst = _instruments[i];
int ix = inst->getXPos();
{
}
-FGPanelTransformation::FGPanelTransformation (Type _type,
- const SGValue * _value,
- float _min, float _max,
- float _factor, float _offset)
- : type(_type), value(_value), min(_min), max(_max),
- factor(_factor), offset(_offset)
-{
-}
-
FGPanelTransformation::~FGPanelTransformation ()
{
}
}
-\f
-////////////////////////////////////////////////////////////////////////
-// Implementation of FGWindowLayer.
-////////////////////////////////////////////////////////////////////////
-
-FGWindowLayer::FGWindowLayer (int w, int h)
- : FGTexturedLayer (w, h)
-{
-}
-
-FGWindowLayer::FGWindowLayer (const FGCroppedTexture &texture, int w, int h)
- : FGTexturedLayer(texture, w, h)
-{
-}
-
-FGWindowLayer::~FGWindowLayer ()
-{
-}
-
-void
-FGWindowLayer::draw ()
-{
- // doesn't do anything yet
- FGTexturedLayer::draw();
-}
-
-
\f
////////////////////////////////////////////////////////////////////////
// Implementation of FGTextLayer.
////////////////////////////////////////////////////////////////////////
-FGTextLayer::FGTextLayer (int w, int h, Chunk * chunk1, Chunk * chunk2,
- Chunk * chunk3)
+FGTextLayer::FGTextLayer (int w, int h)
: FGInstrumentLayer(w, h), _pointSize(14.0)
{
+ _then.stamp();
_color[0] = _color[1] = _color[2] = 0.0;
_color[3] = 1.0;
- if (chunk1)
- addChunk(chunk1);
- if (chunk2)
- addChunk(chunk2);
- if (chunk3)
- addChunk(chunk3);
}
FGTextLayer::~FGTextLayer ()
glPushMatrix();
glColor4fv(_color);
transform();
- _renderer.setFont(guiFntHandle);
- _renderer.setPointSize(_pointSize);
- _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((char *)((*it)->getValue()));
+ text_renderer.setFont(guiFntHandle);
+ text_renderer.setPointSize(_pointSize);
+ text_renderer.begin();
+ text_renderer.start3f(0, 0, 0);
+
+ _now.stamp();
+ if (_now - _then > 100000) {
+ recalc_value();
+ _then = _now;
}
+ text_renderer.puts((char *)(_value.c_str()));
- _renderer.end();
+ text_renderer.end();
glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
glPopMatrix();
}
void
FGTextLayer::setFont(fntFont * font)
{
- _renderer.setFont(font);
+ text_renderer.setFont(font);
+}
+
+
+void
+FGTextLayer::recalc_value () const
+{
+ _value = "";
+ chunk_list::const_iterator it = _chunks.begin();
+ chunk_list::const_iterator last = _chunks.end();
+ for ( ; it != last; it++) {
+ _value += (*it)->getValue();
+ }
}