X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCockpit%2Fpanel.cxx;h=bee42a477766ecd75ba3cf9e3eaccf26fa62c670;hb=d982efc4c4d166e144023664b8ac1c63233f5f82;hp=913fc4bfd07556011fd552e12e14fdfe2a72bbe1;hpb=519ac21fa872ae00dfea0e6743fbfbec21a87cd6;p=flightgear.git diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index 913fc4bfd..bee42a477 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -83,16 +83,16 @@ get_aspect_adjust (int xsize, int ysize) bool fgPanelVisible () { - if(current_panel == 0) + if(current_panel == 0) return false; - if(current_panel->getVisibility() == 0) + if(current_panel->getVisibility() == 0) return false; - if(globals->get_viewmgr()->get_current() != 0) + if(globals->get_viewmgr()->get_current() != 0) return false; - if(globals->get_current_view()->get_view_offset() != 0 && - !fgGetBool("/sim/virtual-cockpit")) + if(globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS != 0 && + !fgGetBool("/sim/virtual-cockpit")) return false; - return true; + return true; } @@ -180,7 +180,6 @@ FGPanel::FGPanel () _mouseInstrument(0), _width(WIN_W), _height(int(WIN_H * 0.5768 + 1)), _x_offset(0), _y_offset(0), _view_height(int(WIN_H * 0.4232)), - _bound(false), _jitter(0.0), _xsize_node(fgGetNode("/sim/startup/xsize", true)), _ysize_node(fgGetNode("/sim/startup/ysize", true)) @@ -194,8 +193,6 @@ FGPanel::FGPanel () */ FGPanel::~FGPanel () { - if (_bound) - unbind(); for (instrument_list_type::iterator it = _instruments.begin(); it != _instruments.end(); it++) { @@ -252,15 +249,10 @@ FGPanel::init () void FGPanel::bind () { - fgTie("/sim/panel/visibility", &_visibility); fgSetArchivable("/sim/panel/visibility"); - fgTie("/sim/panel/x-offset", &_x_offset); fgSetArchivable("/sim/panel/x-offset"); - fgTie("/sim/panel/y-offset", &_y_offset); fgSetArchivable("/sim/panel/y-offset"); - fgTie("/sim/panel/jitter", &_jitter); fgSetArchivable("/sim/panel/jitter"); - _bound = true; } @@ -270,10 +262,6 @@ FGPanel::bind () void FGPanel::unbind () { - fgUntie("/sim/panel/visibility"); - fgUntie("/sim/panel/x-offset"); - fgUntie("/sim/panel/y-offset"); - _bound = false; } @@ -281,8 +269,14 @@ FGPanel::unbind () * Update the panel. */ void -FGPanel::update (int dt) +FGPanel::update (double dt) { + // TODO: cache the nodes + _visibility = fgGetBool("/sim/panel/visibility"); + _x_offset = fgGetInt("/sim/panel/x-offset"); + _y_offset = fgGetInt("/sim/panel/y-offset"); + _jitter = fgGetFloat("/sim/panel/jitter"); + // Do nothing if the panel isn't visible. if ( !fgPanelVisible() ) { return; @@ -458,8 +452,8 @@ FGPanel::setupVirtualCockpit() // Generate a "look at" matrix using OpenGL (!) coordinate // conventions. float lookat[3]; - float pitch = view->get_view_tilt(); - float rot = view->get_view_offset(); + float pitch = view->getPitchOffset_deg() * SGD_DEGREES_TO_RADIANS; + float rot = view->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS; lookat[0] = -sin(rot); lookat[1] = sin(pitch) / cos(pitch); lookat[2] = -cos(rot); @@ -588,7 +582,7 @@ FGPanel::doMouseAction (int button, int updown, int x, int y) if (updown == 1) { _mouseDown = false; _mouseInstrument = 0; - return true; + return false; } // Scale for the real window size. @@ -619,8 +613,7 @@ FGPanel::doMouseAction (int button, int updown, int x, int y) _mouseX = x - ix; _mouseY = y - iy; // Always do the action once. - _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY); - return true; + return _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY); } } return false; @@ -793,10 +786,15 @@ void FGLayeredInstrument::draw () { if (test()) { + float z = 0.1f; + float z_inc = 0.01; + bool vc = fgGetBool("/sim/virtual-cockpit"); for (int i = 0; i < (int)_layers.size(); i++) { glPushMatrix(); - if(!fgGetBool("/sim/virtual-cockpit")) - glTranslatef(0.0, 0.0, (i / 100.0) + 0.1); + if(!vc) { + glTranslatef(0.0, 0.0, z); + z += z_inc; + } _layers[i]->draw(); glPopMatrix(); } @@ -1014,7 +1012,29 @@ FGTextLayer::draw () text_renderer.start3f(0, 0, 0); _now.stamp(); - if (_now - _then > 100000) { + long diff = _now - _then; +#if 0 + // It would be nice to keep this #ifdef'd stuff for (04/18/2002 + + // a couple days) as I verify my solution to the panel text + // drawing problem is actually correct. -CLO + cout << "time diff = " << diff << endl; + if ( _now - _then < 0 ) { + cout << "Eeek, the past is now in the future!" << endl; + cout << "Now = " << _now.get_seconds() << " seconds " + << _now.get_usec() << "usecs" << endl; + cout << "Past = " << _then.get_seconds() << " seconds " + << _then.get_usec() << "usecs" << endl; + exit(-1); + } +#endif + if (diff > 100000 || diff < 0 ) { + // ( diff < 0 ) is a sanity check and indicates our time stamp + // difference math probably overflowed. We can handle a max + // difference of 35.8 minutes since the returned value is in + // usec. So if the panel is left off longer than that we can + // over flow the math with it is turned back on. This (diff < + // 0) catches that situation, get's us out of trouble, and + // back on track. recalc_value(); _then = _now; } @@ -1082,7 +1102,7 @@ FGTextLayer::Chunk::Chunk (const string &text, const string &fmt) : _type(FGTextLayer::TEXT), _fmt(fmt) { _text = text; - if (_fmt == "") + if (_fmt.empty()) _fmt = "%s"; } @@ -1090,7 +1110,7 @@ FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node, const string &fmt, float mult) : _type(type), _fmt(fmt), _mult(mult) { - if (_fmt == "") { + if (_fmt.empty()) { if (type == TEXT_VALUE) _fmt = "%s"; else @@ -1103,12 +1123,13 @@ const char * FGTextLayer::Chunk::getValue () const { if (test()) { + _buf[0] = '\0'; switch (_type) { case TEXT: sprintf(_buf, _fmt.c_str(), _text.c_str()); return _buf; case TEXT_VALUE: - sprintf(_buf, _fmt.c_str(), _node->getStringValue().c_str()); + sprintf(_buf, _fmt.c_str(), _node->getStringValue()); break; case DOUBLE_VALUE: sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult); @@ -1156,3 +1177,4 @@ FGSwitchLayer::draw () // end of panel.cxx +