#include <Cockpit/panel_io.hxx>
#include <GUI/gui.h>
-#ifndef FG_OLD_WEATHER
-# include <WeatherCM/FGLocalWeatherDatabase.h>
-#else
-# include <Weather/weather.hxx>
-#endif
-
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
-#include <Main/options.hxx>
#include "input.hxx"
{
}
-FGBinding::FGBinding (const FGBinding &binding)
- : _command_name(binding._command_name),
- _command(binding._command),
- _arg(new SGPropertyNode),
- _setting(0),
- _command_state(0)
-{
- copyProperties(binding._arg, _arg);
-}
-
FGBinding::FGBinding (const SGPropertyNode * node)
: _command(0),
_arg(new SGPropertyNode),
FGBinding::~FGBinding ()
{
- delete _arg; // Delete the saved arguments
- delete _command_state; // Delete the saved command state
+// delete _arg; // Delete the saved arguments
+// delete _command_state; // Delete the saved command state
}
void
FGBinding::read (const SGPropertyNode * node)
{
+ const SGPropertyNode * conditionNode = node->getChild("condition");
+ if (conditionNode != 0) {
+ cerr << "Adding condition to binding" << endl;
+ setCondition(fgReadCondition(conditionNode));
+ }
+
_command_name = node->getStringValue("command", "");
if (_command_name == "") {
SG_LOG(SG_INPUT, SG_ALERT, "No command supplied for binding.");
void
FGBinding::fire () const
{
- if (_command == 0) {
- SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
- } else if (!(*_command)(_arg, &_command_state)) {
- SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command " << _command_name);
+ if (test()) {
+ if (_command == 0) {
+ SG_LOG(SG_INPUT, SG_ALERT, "No command attached to binding");
+ } else if (!(*_command)(_arg, &_command_state)) {
+ SG_LOG(SG_INPUT, SG_ALERT, "Failed to execute command "
+ << _command_name);
+ }
}
}
void
FGBinding::fire (double setting) const
{
+ if (test()) {
// A value is automatically added to
// the args
- if (_setting == 0) // save the setting node for efficiency
- _setting = _arg->getChild("setting", 0, true);
- _setting->setDoubleValue(setting);
- fire();
+ if (_setting == 0) // save the setting node for efficiency
+ _setting = _arg->getChild("setting", 0, true);
+ _setting->setDoubleValue(setting);
+ fire();
+ }
}
}
void
-FGInput::update ()
+FGInput::update (int dt)
{
_update_keyboard();
_update_joystick();
void
FGInput::doKey (int k, int modifiers, int x, int y)
{
- SG_LOG(SG_INPUT, SG_INFO, "User pressed key " << k
- << " with modifiers " << modifiers);
+ // SG_LOG( SG_INPUT, SG_INFO, "User pressed key " << k
+ // << " with modifiers " << modifiers );
// Sanity check.
if (k < 0 || k >= MAX_KEYS) {
int max = bindings.size();
if (max > 0) {
for (int i = 0; i < max; i++)
- bindings[i].fire();
+ bindings[i]->fire();
return;
}
}
int max = bindings.size();
if (max > 0) {
for (int i = 0; i < max; i++)
- bindings[i].fire();
+ bindings[i]->fire();
return;
}
}
// Use the old, default actions.
- SG_LOG(SG_INPUT, SG_INFO, "(No user binding.)");
+ // SG_LOG( SG_INPUT, SG_INFO, "(No user binding.)" );
if (modifiers&FG_MOD_UP)
return;
- // float fov, tmp;
- static bool winding_ccw = true;
- // int speed;
- // FGInterface *f = current_aircraft.fdm_state;
- // FGViewer *v = globals->get_current_view();
-
// everything after here will be removed sooner or later...
if (modifiers & FG_MOD_SHIFT) {
switch (k) {
- case 18: // Ctrl-R key
- // temporary
- winding_ccw = !winding_ccw;
- if ( winding_ccw ) {
- glFrontFace ( GL_CCW );
- } else {
- glFrontFace ( GL_CW );
- }
- return;
case 72: // H key
HUD_brightkey( true );
return;
// Minimal Hud
fgHUDInit2(¤t_aircraft);
return;
- case 87: // W key
-#if defined(FX) && !defined(WIN32)
- global_fullscreen = ( !global_fullscreen );
-# if defined(XMESA_FX_FULLSCREEN) && defined(XMESA_FX_WINDOW)
- XMesaSetFXmode( global_fullscreen ?
- XMESA_FX_FULLSCREEN : XMESA_FX_WINDOW );
-# endif
-#endif
- return;
-
-// START SPECIALS
-
- case 256+GLUT_KEY_F10: {
- fgToggleFDMdataLogging();
- return;
- }
-
-// END SPECIALS
-
}
// SG_LOG(SG_INPUT, SG_INFO, "There are "
// << a.bindings[modifiers].size() << " bindings");
for (unsigned int k = 0; k < a.bindings[modifiers].size(); k++)
- a.bindings[modifiers][k].fire(axis_values[j]);
+ a.bindings[modifiers][k]->fire(axis_values[j]);
}
// do we have to emulate axis buttons?
if (pressed) {
// The press event may be repeated.
if (!b.last_state || b.is_repeatable) {
- SG_LOG(SG_INPUT, SG_INFO, "Button has been pressed");
+ // SG_LOG( SG_INPUT, SG_INFO, "Button has been pressed" );
for (unsigned int k = 0; k < b.bindings[modifiers].size(); k++)
- b.bindings[modifiers][k].fire();
+ b.bindings[modifiers][k]->fire();
}
} else {
// The release event is never repeated.
if (b.last_state) {
- SG_LOG(SG_INPUT, SG_INFO, "Button has been released");
+ // SG_LOG( SG_INPUT, SG_INFO, "Button has been released" );
for (unsigned int k = 0; k < b.bindings[modifiers|FG_MOD_UP].size(); k++)
- b.bindings[modifiers|FG_MOD_UP][k].fire();
+ b.bindings[modifiers|FG_MOD_UP][k]->fire();
}
}
for (unsigned int i = 0; i < bindings.size(); i++) {
SG_LOG(SG_INPUT, SG_INFO, "Reading binding "
<< bindings[i]->getStringValue("command"));
- binding_list[modifiers].push_back(FGBinding(bindings[i]));
+ binding_list[modifiers].push_back(new FGBinding(bindings[i]));
}
// Read nested bindings for modifiers
}
-const vector<FGBinding> &
+const vector<FGBinding *> &
FGInput::_find_key_bindings (unsigned int k, int modifiers)
{
button &b = _key_bindings[k];
}
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGInput::button.
+////////////////////////////////////////////////////////////////////////
+
+FGInput::button::button ()
+ : is_repeatable(false),
+ last_state(-1)
+{
+}
+
+FGInput::button::~button ()
+{
+ // FIXME: memory leak
+// for (int i = 0; i < FG_MOD_MAX; i++)
+// for (int j = 0; i < bindings[i].size(); j++)
+// delete bindings[i][j];
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGInput::axis.
+////////////////////////////////////////////////////////////////////////
+
+FGInput::axis::axis ()
+ : last_value(9999999),
+ tolerance(0.002),
+ low_threshold(-0.9),
+ high_threshold(0.9)
+{
+}
+
+FGInput::axis::~axis ()
+{
+// for (int i = 0; i < FG_MOD_MAX; i++)
+// for (int j = 0; i < bindings[i].size(); j++)
+// delete bindings[i][j];
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGInput::joystick.
+////////////////////////////////////////////////////////////////////////
+
+FGInput::joystick::joystick ()
+{
+}
+
+FGInput::joystick::~joystick ()
+{
+// delete js;
+// delete[] axes;
+// delete[] buttons;
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of GLUT callbacks.
+////////////////////////////////////////////////////////////////////////
+
+
/**
* Construct the modifiers.
*/