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);
}
+
+/**
+ * Destructor.
+ */
FGPanel::~FGPanel ()
{
for (instrument_list_type::iterator it = _instruments.begin();
}
}
+
+/**
+ * Add an instrument to the panel.
+ */
void
FGPanel::addInstrument (FGPanelInstrument * instrument)
{
_instruments.push_back(instrument);
}
+
+/**
+ * Update the panel.
+ */
void
FGPanel::update () const
{
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(10.0, 0.0); glVertex3f(_winx + _width, _winy, 0);
+ glTexCoord2f(10.0, 5.0); glVertex3f(_winx + _width, _winy + _height, 0);
+ glTexCoord2f(0.0, 5.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 / current_view.get_winWidth()) * _winw);
+ y = int(_winh - (((float)y / current_view.get_winHeight()) * _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();
{
public:
- FGPanel (int x, int y, int w, int h);
+ FGPanel (int window_x, int window_y, int window_w, int window_h);
virtual ~FGPanel ();
// transfer pointer ownership!!!
virtual bool getVisibility () const;
virtual void setVisibility (bool visibility);
+ // Full width of panel.
+ virtual void setWidth (int width) { _width = width; }
+ virtual int getWidth () const { return _width; }
+
+ // Full height of panel.
+ virtual void setHeight (int height) { _height = height; }
+ virtual int getHeight () const { return _height; }
+
+ // X-offset
+ virtual void setXOffset (int offset);
+ virtual int getXOffset () const { return _x_offset; }
+
+ // Y-offset.
+ virtual void setYOffset (int offset);
+ virtual int getYOffset () const { return _y_offset; }
+
+ // View height.
+ virtual void setViewHeight (int height) { _view_height = height; }
+ virtual int getViewHeight () const { return _view_height; }
+
// Handle a mouse click.
virtual bool doMouseAction (int button, int updown, int x, int y);
mutable int _mouseDelay;
mutable FGPanelInstrument * _mouseInstrument;
typedef vector<FGPanelInstrument *> instrument_list_type;
- int _x, _y, _w, _h;
- int _panel_h;
+ int _winx, _winy, _winw, _winh;
+ int _width;
+ int _height;
+ int _x_offset;
+ int _y_offset;
+ int _view_height;
+
ssgTexture * _bg;
// List of instruments in panel.
instrument_list_type _instruments;
//
FGPanel * panel = new FGPanel(0, 0, 1024, 768);// FIXME: use variable size
+
+ //
+ // Grab the panel's dimensions, default to 1024x443.
+ //
+ int panel_w = (props.hasValue("/w") ? props.getIntValue("/w") : 1024);
+ int panel_h = (props.hasValue("/h") ? props.getIntValue("/h") : 443);
+ panel->setWidth(panel_w);
+ panel->setHeight(panel_h);
+
+ //
+ // Grab the visible external viewing area, default to
+ //
+ panel->setViewHeight(props.hasValue("/view-height") ?
+ props.getIntValue("/view-height") :
+ 768 - panel_h + 2);
+
+ //
+ // Grab the panel's initial offsets, default to 0, 0.
+ //
+ int xoffset = (props.hasValue("/x-offset") ?
+ props.getIntValue("x-offset") :
+ 0);
+ int yoffset = (props.hasValue("/y-offset") ?
+ props.getIntValue("y-offset") :
+ 0);
+ panel->setXOffset(xoffset);
+ panel->setYOffset(yoffset);
+
//
// Assign the background texture, if any, or a bogus chequerboard.
//
e->set_Percentage_Power( eng.get_Percentage_Power() );
e->set_EGT( eng.get_EGT() );
e->set_prop_thrust( eng.get_prop_thrust_SI() );
-
+
+#if 0
cout << "Throttle = " << controls.get_throttle( 0 ) * 100.0;
cout << " Mixture = " << controls.get_mixture( 0 ) * 100.0;
cout << " RPM = " << eng.get_RPM();
cout << " EGT = " << eng.get_EGT();
cout << " Thrust (N) " << eng.get_prop_thrust_SI(); // Thrust in Newtons
cout << '\n';
+#endif
F_X_engine = eng.get_prop_thrust_SI() * 0.07;
#endif // USE_NEW_ENGINE_CODE
// Handle new window size or exposure
void fgReshape( int width, int height ) {
if ( ! current_options.get_panel_status() || idle_state != 1000 ) {
- current_view.set_win_ratio( height / width );
+ current_view.set_win_ratio( (float)height / (float)width );
glViewport(0, 0 , (GLint)(width), (GLint)(height) );
} else {
- current_view.set_win_ratio( (height*0.4232) / width );
- glViewport(0, (GLint)((height)*0.5768),
- (GLint)(width), (GLint)((height)*0.4232) );
+ int view_h =
+ int((current_panel->getViewHeight() - current_panel->getYOffset())
+ * (height / 768.0)) + 1;
+ current_view.set_win_ratio( (float)view_h / (float)width );
+ glViewport(0, (GLint)(height - view_h),
+ (GLint)(width), (GLint)(view_h) );
}
current_view.set_winWidth( width );
winWidth = current_options.get_xsize();
winHeight = current_options.get_ysize();
- if ( ! current_options.get_panel_status() ) {
- set_win_ratio( winHeight / winWidth );
- } else {
- set_win_ratio( (winHeight*0.4232) / winWidth );
- }
+ set_win_ratio( winHeight / winWidth );
#ifndef USE_FAST_VIEWROT
// This never changes -- NHV
if ( ! current_options.get_panel_status() ) {
xglViewport(0, 0 , (GLint)(winWidth), (GLint)(winHeight) );
} else {
- xglViewport(0, (GLint)((winHeight)*0.5768), (GLint)(winWidth),
- (GLint)((winHeight)*0.4232) );
+ int view_h =
+ int((current_panel->getViewHeight() - current_panel->getYOffset())
+ * (winHeight / 768.0));
+ glViewport(0, (GLint)(winHeight - view_h),
+ (GLint)(winWidth), (GLint)(view_h) );
}
}
#include <simgear/misc/fgpath.hxx>
#include <simgear/misc/fgstream.hxx>
+#include <Include/general.hxx>
#include <Main/options.hxx>
#include <Main/views.hxx>
#include <Scenery/tileentry.hxx>
FGPath tmp_path = tex_path;
tmp_path.append( m.get_texture_name() );
- if ( ! local_file_exists( tmp_path.str() ) ) {
+ if ( ! local_file_exists(tmp_path.str())
+ || general.get_glMaxTexSize() < 512 ) {
tex_path = FGPath( current_options.get_fg_root() );
tex_path.append( "Textures" );
}