1
0
Fork 0

Allow panel mouse bindings to use mod-up.

Ensure that if a condition for a panel mouse binding fails, other
bindings for the same area will have a chance to run.

Add a repeatable flag for panel mouse bindings (defaults to true).
This commit is contained in:
david 2002-12-28 19:05:45 +00:00
parent f85b9589da
commit d31e0e7071
3 changed files with 48 additions and 26 deletions

View file

@ -300,7 +300,7 @@ void FGPanel::updateMouseDelay()
if (_mouseDown) { if (_mouseDown) {
_mouseDelay--; _mouseDelay--;
if (_mouseDelay < 0) { if (_mouseDelay < 0) {
_mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY); _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
_mouseDelay = 2; _mouseDelay = 2;
} }
} }
@ -527,6 +527,8 @@ FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
{ {
// Note a released button and return // Note a released button and return
if (updown == 1) { if (updown == 1) {
if (_mouseInstrument != 0)
_mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
_mouseDown = false; _mouseDown = false;
_mouseInstrument = 0; _mouseInstrument = 0;
return false; return false;
@ -547,7 +549,8 @@ FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
_mouseX = x - ix; _mouseX = x - ix;
_mouseY = y - iy; _mouseY = y - iy;
// Always do the action once. // Always do the action once.
return _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY); return _mouseInstrument->doMouseAction(_mouseButton, 0,
_mouseX, _mouseY);
} }
} }
return false; return false;
@ -592,11 +595,14 @@ FGPanelAction::FGPanelAction ()
{ {
} }
FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h) FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
: _button(button), _x(x), _y(y), _w(w), _h(h) bool repeatable)
: _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
{ {
for (unsigned int i = 0; i < _bindings.size(); i++) for (unsigned int i = 0; i < 2; i++) {
delete _bindings[i]; for (unsigned int j = 0; j < _bindings[i].size(); j++)
delete _bindings[i][j];
}
} }
FGPanelAction::~FGPanelAction () FGPanelAction::~FGPanelAction ()
@ -604,19 +610,24 @@ FGPanelAction::~FGPanelAction ()
} }
void void
FGPanelAction::addBinding (FGBinding * binding) FGPanelAction::addBinding (FGBinding * binding, int updown)
{ {
_bindings.push_back(binding); _bindings[updown].push_back(binding);
} }
void bool
FGPanelAction::doAction () FGPanelAction::doAction (int updown)
{ {
if (test()) { if (test()) {
int nBindings = _bindings.size(); if ((updown != _last_state) || (updown == 0 && _repeatable)) {
for (int i = 0; i < nBindings; i++) { int nBindings = _bindings[updown].size();
_bindings[i]->fire(); for (int i = 0; i < nBindings; i++)
_bindings[updown][i]->fire();
} }
_last_state = updown;
return true;
} else {
return false;
} }
} }
@ -730,16 +741,15 @@ FGPanelInstrument::addAction (FGPanelAction * action)
// Coordinates relative to centre. // Coordinates relative to centre.
bool bool
FGPanelInstrument::doMouseAction (int button, int x, int y) FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
{ {
if (test()) { if (test()) {
action_list_type::iterator it = _actions.begin(); action_list_type::iterator it = _actions.begin();
action_list_type::iterator last = _actions.end(); action_list_type::iterator last = _actions.end();
for ( ; it != last; it++) { for ( ; it != last; it++) {
if ((*it)->inArea(button, x, y)) { if ((*it)->inArea(button, x, y) &&
(*it)->doAction(); (*it)->doAction(updown))
return true; return true;
}
} }
} }
return false; return false;

View file

@ -230,7 +230,7 @@ class FGPanelAction : public FGConditional
{ {
public: public:
FGPanelAction (); FGPanelAction ();
FGPanelAction (int button, int x, int y, int w, int h); FGPanelAction (int button, int x, int y, int w, int h, bool repeatable);
virtual ~FGPanelAction (); virtual ~FGPanelAction ();
// Getters. // Getters.
@ -243,7 +243,7 @@ public:
// Setters. // Setters.
// transfer pointer ownership // transfer pointer ownership
virtual void addBinding (FGBinding * binding); virtual void addBinding (FGBinding * binding, int updown);
virtual void setButton (int button) { _button = button; } virtual void setButton (int button) { _button = button; }
virtual void setX (int x) { _x = x; } virtual void setX (int x) { _x = x; }
virtual void setY (int y) { _y = y; } virtual void setY (int y) { _y = y; }
@ -261,7 +261,7 @@ public:
} }
// Perform the action. // Perform the action.
virtual void doAction (); virtual bool doAction (int updown);
private: private:
typedef vector<FGBinding *> binding_list_t; typedef vector<FGBinding *> binding_list_t;
@ -271,7 +271,9 @@ private:
int _y; int _y;
int _w; int _w;
int _h; int _h;
binding_list_t _bindings; bool _repeatable;
int _last_state;
binding_list_t _bindings[2];
}; };
@ -386,7 +388,7 @@ public:
virtual void addAction (FGPanelAction * action); virtual void addAction (FGPanelAction * action);
// Coordinates relative to centre. // Coordinates relative to centre.
virtual bool doMouseAction (int button, int x, int y); virtual bool doMouseAction (int button, int updown, int x, int y);
protected: protected:
int _x, _y, _w, _h; int _x, _y, _w, _h;

View file

@ -179,14 +179,24 @@ readAction (const SGPropertyNode * node, float w_scale, float h_scale)
int y = int(node->getIntValue("y") * h_scale); int y = int(node->getIntValue("y") * h_scale);
int w = int(node->getIntValue("w") * w_scale); int w = int(node->getIntValue("w") * w_scale);
int h = int(node->getIntValue("h") * h_scale); int h = int(node->getIntValue("h") * h_scale);
bool repeatable = node->getBoolValue("repeatable", true);
FGPanelAction * action = new FGPanelAction(button, x, y, w, h); FGPanelAction * action = new FGPanelAction(button, x, y, w, h, repeatable);
vector<SGPropertyNode_ptr>bindings = node->getChildren("binding"); vector<SGPropertyNode_ptr>bindings = node->getChildren("binding");
for (unsigned int i = 0; i < bindings.size(); i++) {
unsigned int i;
for (i = 0; i < bindings.size(); i++) {
SG_LOG(SG_INPUT, SG_INFO, "Reading binding " SG_LOG(SG_INPUT, SG_INFO, "Reading binding "
<< bindings[i]->getStringValue("command")); << bindings[i]->getStringValue("command"));
action->addBinding(new FGBinding(bindings[i])); // TODO: allow modifiers action->addBinding(new FGBinding(bindings[i]), 0);
}
if (node->hasChild("mod-up")) {
bindings = node->getChild("mod-up")->getChildren("binding");
for (i = 0; i < bindings.size(); i++) {
action->addBinding(new FGBinding(bindings[i]), 1);
}
} }
readConditions(action, node); readConditions(action, node);