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:
parent
f85b9589da
commit
d31e0e7071
3 changed files with 48 additions and 26 deletions
|
@ -300,7 +300,7 @@ void FGPanel::updateMouseDelay()
|
|||
if (_mouseDown) {
|
||||
_mouseDelay--;
|
||||
if (_mouseDelay < 0) {
|
||||
_mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
|
||||
_mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
|
||||
_mouseDelay = 2;
|
||||
}
|
||||
}
|
||||
|
@ -527,6 +527,8 @@ FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
|
|||
{
|
||||
// Note a released button and return
|
||||
if (updown == 1) {
|
||||
if (_mouseInstrument != 0)
|
||||
_mouseInstrument->doMouseAction(_mouseButton, 1, _mouseX, _mouseY);
|
||||
_mouseDown = false;
|
||||
_mouseInstrument = 0;
|
||||
return false;
|
||||
|
@ -547,7 +549,8 @@ FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
|
|||
_mouseX = x - ix;
|
||||
_mouseY = y - iy;
|
||||
// Always do the action once.
|
||||
return _mouseInstrument->doMouseAction(_mouseButton, _mouseX, _mouseY);
|
||||
return _mouseInstrument->doMouseAction(_mouseButton, 0,
|
||||
_mouseX, _mouseY);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -592,11 +595,14 @@ FGPanelAction::FGPanelAction ()
|
|||
{
|
||||
}
|
||||
|
||||
FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h)
|
||||
: _button(button), _x(x), _y(y), _w(w), _h(h)
|
||||
FGPanelAction::FGPanelAction (int button, int x, int y, int w, int h,
|
||||
bool repeatable)
|
||||
: _button(button), _x(x), _y(y), _w(w), _h(h), _repeatable(repeatable)
|
||||
{
|
||||
for (unsigned int i = 0; i < _bindings.size(); i++)
|
||||
delete _bindings[i];
|
||||
for (unsigned int i = 0; i < 2; i++) {
|
||||
for (unsigned int j = 0; j < _bindings[i].size(); j++)
|
||||
delete _bindings[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
FGPanelAction::~FGPanelAction ()
|
||||
|
@ -604,19 +610,24 @@ FGPanelAction::~FGPanelAction ()
|
|||
}
|
||||
|
||||
void
|
||||
FGPanelAction::addBinding (FGBinding * binding)
|
||||
FGPanelAction::addBinding (FGBinding * binding, int updown)
|
||||
{
|
||||
_bindings.push_back(binding);
|
||||
_bindings[updown].push_back(binding);
|
||||
}
|
||||
|
||||
void
|
||||
FGPanelAction::doAction ()
|
||||
bool
|
||||
FGPanelAction::doAction (int updown)
|
||||
{
|
||||
if (test()) {
|
||||
int nBindings = _bindings.size();
|
||||
for (int i = 0; i < nBindings; i++) {
|
||||
_bindings[i]->fire();
|
||||
if ((updown != _last_state) || (updown == 0 && _repeatable)) {
|
||||
int nBindings = _bindings[updown].size();
|
||||
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.
|
||||
bool
|
||||
FGPanelInstrument::doMouseAction (int button, int x, int y)
|
||||
FGPanelInstrument::doMouseAction (int button, int updown, int x, int y)
|
||||
{
|
||||
if (test()) {
|
||||
action_list_type::iterator it = _actions.begin();
|
||||
action_list_type::iterator last = _actions.end();
|
||||
for ( ; it != last; it++) {
|
||||
if ((*it)->inArea(button, x, y)) {
|
||||
(*it)->doAction();
|
||||
return true;
|
||||
}
|
||||
if ((*it)->inArea(button, x, y) &&
|
||||
(*it)->doAction(updown))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -230,7 +230,7 @@ class FGPanelAction : public FGConditional
|
|||
{
|
||||
public:
|
||||
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 ();
|
||||
|
||||
// Getters.
|
||||
|
@ -243,7 +243,7 @@ public:
|
|||
// Setters.
|
||||
|
||||
// transfer pointer ownership
|
||||
virtual void addBinding (FGBinding * binding);
|
||||
virtual void addBinding (FGBinding * binding, int updown);
|
||||
virtual void setButton (int button) { _button = button; }
|
||||
virtual void setX (int x) { _x = x; }
|
||||
virtual void setY (int y) { _y = y; }
|
||||
|
@ -261,7 +261,7 @@ public:
|
|||
}
|
||||
|
||||
// Perform the action.
|
||||
virtual void doAction ();
|
||||
virtual bool doAction (int updown);
|
||||
|
||||
private:
|
||||
typedef vector<FGBinding *> binding_list_t;
|
||||
|
@ -271,7 +271,9 @@ private:
|
|||
int _y;
|
||||
int _w;
|
||||
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);
|
||||
|
||||
// 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:
|
||||
int _x, _y, _w, _h;
|
||||
|
|
|
@ -179,14 +179,24 @@ readAction (const SGPropertyNode * node, float w_scale, float h_scale)
|
|||
int y = int(node->getIntValue("y") * h_scale);
|
||||
int w = int(node->getIntValue("w") * w_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");
|
||||
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 "
|
||||
<< 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue