Changeset 1637 for code/branches/input/src/core/input/Button.cc
- Timestamp:
- Jul 20, 2008, 6:49:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/input/src/core/input/Button.cc
r1630 r1637 88 88 '\\', false, '"', false, '(', ')', false, '\0'); 89 89 90 unsigned int iToken = 0;91 92 // for real axes, we can feed a ButtonThreshold argument as entire command93 if (getLowercase(tokens[0]) == "buttonthreshold")94 {95 if (tokens.size() == 1)96 continue;97 // may fail, but doesn't matter98 convertValue(&buttonThreshold_, tokens[1]);99 continue;100 }101 102 // first argument can be OnPress, OnHold OnRelease or nothing103 90 KeybindMode::Enum mode = KeybindMode::None; 104 if (getLowercase(tokens[iToken]) == "onpress")105 mode = KeybindMode::OnPress, iToken++;106 if (getLowercase(tokens[iToken]) == "onrelease")107 mode = KeybindMode::OnRelease, iToken++;108 if (getLowercase(tokens[iToken]) == "onhold")109 mode = KeybindMode::OnHold, iToken++;110 111 if (iToken == tokens.size())112 continue;113 114 // second argument can be the amplitude for the case it as an axis command115 // default amplitude is 1.0f116 91 float paramModifier = 1.0f; 117 if (getLowercase(tokens[iToken]) == "scale") 118 { 119 iToken++; 120 if (iToken == tokens.size() || !convertValue(¶mModifier, tokens[iToken])) 121 { 122 COUT(2) << "Error while parsing key binding " << name_ 123 << ". Numeric expression expected afer 'AxisAmp', switching to default value" 124 << std::endl; 92 std::string commandStr = ""; 93 94 for (unsigned int iToken = 0; iToken < tokens.size(); ++iToken) 95 { 96 std::string token = getLowercase(tokens[iToken]); 97 98 if (token == "onpress") 99 mode = KeybindMode::OnPress; 100 else if (token == "onrelease") 101 mode = KeybindMode::OnRelease; 102 else if (token == "onhold") 103 mode = KeybindMode::OnHold; 104 else if (token == "buttonthreshold") 105 { 106 // for real axes, we can feed a ButtonThreshold argument 107 ++iToken; 125 108 if (iToken == tokens.size()) 126 109 continue; 127 } 128 iToken++; 129 } 130 131 // no more arguments expected except for the actual command 132 if (iToken == tokens.size()) 110 // may fail, but doesn't matter (default value already set) 111 if (!convertValue(&buttonThreshold_, tokens[iToken + 1])) 112 parseError("Could not parse 'ButtonThreshold' argument. \ 113 Switching to default value.", true); 114 } 115 else if (token == "scale") 116 { 117 ++iToken; 118 if (iToken == tokens.size() || !convertValue(¶mModifier, tokens[iToken])) 119 parseError("Could not parse 'scale' argument. Switching to default value.", true); 120 } 121 else 122 { 123 // no input related argument 124 // we interpret everything from here as a command string 125 while (iToken != tokens.size()) 126 commandStr += tokens[iToken++] + " "; 127 } 128 } 129 130 if (commandStr == "") 131 { 132 parseError("No command string given.", false); 133 133 continue; 134 135 std::string commandStr; 136 while (iToken != tokens.size()) 137 commandStr += tokens[iToken++] + " "; 134 } 138 135 139 136 // evaluate the command 140 137 CommandEvaluation eval = CommandExecutor::evaluate(commandStr); 141 138 if (!eval.isValid()) 139 { 140 parseError("Command evaluation failed.", true); 142 141 continue; 142 } 143 143 144 144 // check for param command … … 215 215 return true; 216 216 } 217 218 inline void Button::parseError(std::string message, bool serious) 219 { 220 if (serious) 221 { 222 COUT(2) << "Error while parsing binding for button/axis" << this->name_ << ". " 223 << message << std::endl; 224 } 225 else 226 { 227 COUT(3) << "Warning while parsing binding for button/axis" << this->name_ << ". " 228 << message << std::endl; 229 } 230 } 217 231 }
Note: See TracChangeset
for help on using the changeset viewer.