]> git.mxchange.org Git - flightgear.git/commitdiff
David Megginson writes:
authorcurt <curt>
Fri, 6 Oct 2000 21:16:01 +0000 (21:16 +0000)
committercurt <curt>
Fri, 6 Oct 2000 21:16:01 +0000 (21:16 +0000)
I have a scrollable panel working (it didn't take long in the end).  A
panel can now be much wider or higher than the available area, and the
user can scroll around using [Shift]F5, [Shift]F6, [Shift]F7, and
[Shift]F8.  The user can also scroll the panel down to get a bigger
external view.  Mouse clicks seem still to be working correctly.

To set the panel's (virtual) height and width, use the panel file's /w
and /h properties in a panel XML file; to set the initial x- and y-
offsets (untested), use the panel file's /x-offset and /y-offset
properties; to set the initial height of the external view (untested
and optional), use the panel file's /view-height property.  Note that
none of these show up in the regular FGFS property manager.

Unfortunately, these patches will not affect your initialization
problems with the property manager -- I'm having a hard time tracking
them down because I cannot reproduce them.

I have also made some patches to main.cxx and views.cxx to do two
things:

1. Expand or shrink the external view as the panel moves up and down.

2. Set the window ratio correctly, so that we don't get an oval sun
   and flat clouds when the panel is visible (the problem before was
   integer division, so I added casts).

Unfortunately, the window ratio is not set properly at start-up --
there are too many dependencies, and I haven't figured that part out
yet.  As soon as you hide and redisplay the panel or move it
vertically (i.e. force fgReshape to be called), you'll see the correct
ratio.

src/Cockpit/panel.cxx
src/Cockpit/panel.hxx
src/Cockpit/panel_io.cxx
src/FDM/LaRCsim.cxx
src/Main/main.cxx
src/Main/views.cxx
src/Objects/matlib.cxx

index cf4a9baf9eb756913f5b2cdf6c4d1b2f8ae7a215..4b72ce0f2cb767f68d339e3fd2cbedf5d301ae12 100644 (file)
@@ -115,15 +115,23 @@ 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);
 }
 
+
+/**
+ * Destructor.
+ */
 FGPanel::~FGPanel ()
 {
   for (instrument_list_type::iterator it = _instruments.begin();
@@ -134,12 +142,20 @@ FGPanel::~FGPanel ()
   }
 }
 
+
+/**
+ * Add an instrument to the panel.
+ */
 void
 FGPanel::addInstrument (FGPanelInstrument * instrument)
 {
   _instruments.push_back(instrument);
 }
 
+
+/**
+ * Update the panel.
+ */
 void
 FGPanel::update () const
 {
@@ -160,12 +176,14 @@ 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);
@@ -183,10 +201,10 @@ FGPanel::update () const
   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.
@@ -196,6 +214,7 @@ FGPanel::update () const
   for ( ; current != end; current++) {
     FGPanelInstrument * instr = *current;
     glLoadIdentity();
+    glTranslated(_x_offset, _y_offset, 0);
     glTranslated(instr->getXPos(), instr->getYPos(), 0);
     instr->draw();
   }
@@ -208,27 +227,66 @@ FGPanel::update () const
   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) {
@@ -237,9 +295,15 @@ FGPanel::doMouseAction (int button, int updown, int x, int y)
     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();
index 85b035f6bc0dbaec6ddd06062b4819c4ee5f0f5a..25c0037ac5ad87574da1558b634589a99b8d585c 100644 (file)
@@ -123,7 +123,7 @@ class FGPanel
 {
 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!!!
@@ -139,6 +139,26 @@ public:
   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);
 
@@ -149,8 +169,13 @@ private:
   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;
index 3c97c4c8f85f463af630b53d6d65927f40264cc5..da80239e9cb997696cedb374de61513806fa1828 100644 (file)
@@ -700,6 +700,34 @@ fgReadPanel (istream &input)
   //
   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.
   //
index a22b1059fb2d6e0bad04104b9d77ea8e1eb7bee6..7d32831e37375c88c9c3ea1628e029aa549f2047 100644 (file)
@@ -112,7 +112,8 @@ int FGLaRCsim::update( int multiloop ) {
     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();
@@ -122,6 +123,7 @@ int FGLaRCsim::update( int multiloop ) {
     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
index 0c15a3ffb27d449334b9fbf77522a97867d0772c..bf37839ecb9c24f97c38756b639a814a3b5929f1 100644 (file)
@@ -1156,12 +1156,15 @@ static void fgIdleFunction ( void ) {
 // 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 );
index a183a5de629c6cee32b5c0651abbc2260e9d3e75..240aefc6e93fb89638325aba752d102eb47ce4c4 100644 (file)
@@ -98,11 +98,7 @@ void FGView::Init( void ) {
     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
@@ -173,8 +169,11 @@ void FGView::UpdateViewParams( const FGInterface& f ) {
     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) );
     }
 }
 
index 7f8fcb658bc8abc3a0e62a49212a8aa582a7842c..5dbdbf139e6dfd88103c09cfb0b97d5017aa83e3 100644 (file)
@@ -45,6 +45,7 @@
 #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>
@@ -123,7 +124,8 @@ bool FGMaterialLib::load( const string& mpath ) {
 
            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" );
            }