[Orxonox-commit 5315] r9978 - in code/trunk/src/libraries/core: . input
landauf at orxonox.net
landauf at orxonox.net
Sat Jan 4 21:48:04 CET 2014
Author: landauf
Date: 2014-01-04 21:48:04 +0100 (Sat, 04 Jan 2014)
New Revision: 9978
Modified:
code/trunk/src/libraries/core/CorePrereqs.h
code/trunk/src/libraries/core/input/Button.cc
code/trunk/src/libraries/core/input/Button.h
code/trunk/src/libraries/core/input/InputCommands.h
code/trunk/src/libraries/core/input/KeyBinder.h
Log:
added new keybind mode 'OnPressAndRelease' which triggers both when a button is pressed and when it's released.
pressed buttons send the value '1' to the bound console command, while released buttons send the value '0'.
Modified: code/trunk/src/libraries/core/CorePrereqs.h
===================================================================
--- code/trunk/src/libraries/core/CorePrereqs.h 2014-01-04 20:42:47 UTC (rev 9977)
+++ code/trunk/src/libraries/core/CorePrereqs.h 2014-01-04 20:48:04 UTC (rev 9978)
@@ -105,6 +105,7 @@
OnPress,
OnHold,
OnRelease,
+ OnPressAndRelease,
None
};
};
Modified: code/trunk/src/libraries/core/input/Button.cc
===================================================================
--- code/trunk/src/libraries/core/input/Button.cc 2014-01-04 20:42:47 UTC (rev 9977)
+++ code/trunk/src/libraries/core/input/Button.cc 2014-01-04 20:48:04 UTC (rev 9978)
@@ -137,6 +137,8 @@
mode = KeybindMode::OnPress;
else if (token == "onrelease")
mode = KeybindMode::OnRelease;
+ else if (token == "onpressandrelease")
+ mode = KeybindMode::OnPressAndRelease;
else if (token == "onhold")
mode = KeybindMode::OnHold;
else if (token == "buttonthreshold")
@@ -215,7 +217,7 @@
if (!addParamCommand(cmd))
{
mode = eval.getConsoleCommand()->getKeybindMode();
- commands[mode].push_back(cmd);
+ this->addCommand(cmd, mode, commands);
}
}
else
@@ -231,7 +233,7 @@
else
cmd->setFixedKeybindMode(true);
- commands[mode].push_back(cmd);
+ this->addCommand(cmd, mode, commands);
}
}
}
@@ -250,6 +252,19 @@
}
}
+ inline void Button::addCommand(BaseCommand* cmd, KeybindMode::Value mode, std::vector<BaseCommand*> commands[3])
+ {
+ if (mode == KeybindMode::OnPressAndRelease)
+ {
+ BaseCommand* cmd2 = cmd->clone();
+
+ commands[KeybindMode::OnPress].push_back(cmd);
+ commands[KeybindMode::OnRelease].push_back(cmd2); // clone
+ }
+ else
+ commands[mode].push_back(cmd);
+ }
+
inline void Button::parseError(const std::string& message, bool serious)
{
if (serious)
Modified: code/trunk/src/libraries/core/input/Button.h
===================================================================
--- code/trunk/src/libraries/core/input/Button.h 2014-01-04 20:42:47 UTC (rev 9977)
+++ code/trunk/src/libraries/core/input/Button.h 2014-01-04 20:48:04 UTC (rev 9978)
@@ -74,6 +74,7 @@
private:
void parseError(const std::string& message, bool serious);
+ void addCommand(BaseCommand* cmd, KeybindMode::Value mode, std::vector<BaseCommand*> commands[3]);
};
inline bool Button::execute(KeybindMode::Value mode, float abs, float rel)
Modified: code/trunk/src/libraries/core/input/InputCommands.h
===================================================================
--- code/trunk/src/libraries/core/input/InputCommands.h 2014-01-04 20:42:47 UTC (rev 9977)
+++ code/trunk/src/libraries/core/input/InputCommands.h 2014-01-04 20:48:04 UTC (rev 9978)
@@ -66,6 +66,8 @@
inline bool hasFixedKeybindMode() const
{ return this->bFixedKeybindMode_; }
+ virtual BaseCommand* clone() = 0;
+
private:
bool bFixedKeybindMode_;
};
@@ -75,6 +77,7 @@
public:
bool execute(float abs = 1.0f, float rel = 1.0f);
CommandEvaluation* getEvaluation();
+ virtual SimpleCommand* clone() { return new SimpleCommand(*this); }
CommandEvaluation evaluation_;
};
@@ -102,6 +105,7 @@
ParamCommand() : scale_(1.0f), paramCommand_(0) { }
bool execute(float abs = 1.0f, float rel = 1.0f);
CommandEvaluation* getEvaluation();
+ virtual ParamCommand* clone() { return new ParamCommand(*this); }
float scale_;
BufferedParamCommand* paramCommand_;
Modified: code/trunk/src/libraries/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.h 2014-01-04 20:42:47 UTC (rev 9977)
+++ code/trunk/src/libraries/core/input/KeyBinder.h 2014-01-04 20:48:04 UTC (rev 9978)
@@ -194,30 +194,30 @@
inline void KeyBinder::buttonPressed (const KeyEvent& evt)
- { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); }
+ { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress, 1); }
inline void KeyBinder::buttonReleased(const KeyEvent& evt)
- { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnRelease); }
+ { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnRelease, 0); }
inline void KeyBinder::buttonHeld (const KeyEvent& evt)
{ assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnHold); }
inline void KeyBinder::buttonPressed (MouseButtonCode::ByEnum button)
- { mouseButtons_[button].execute(KeybindMode::OnPress); }
+ { mouseButtons_[button].execute(KeybindMode::OnPress, 1); }
inline void KeyBinder::buttonReleased(MouseButtonCode::ByEnum button)
- { mouseButtons_[button].execute(KeybindMode::OnRelease); }
+ { mouseButtons_[button].execute(KeybindMode::OnRelease, 0); }
inline void KeyBinder::buttonHeld (MouseButtonCode::ByEnum button)
{ mouseButtons_[button].execute(KeybindMode::OnHold); }
inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button)
- { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress); }
+ { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress, 1); }
inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button)
- { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease); }
+ { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease, 0); }
inline void KeyBinder::buttonHeld (unsigned int device, JoyStickButtonCode::ByEnum button)
{ (*joyStickButtons_[device])[button].execute(KeybindMode::OnHold); }
More information about the Orxonox-commit
mailing list