Changeset 2814
- Timestamp:
- Mar 21, 2009, 5:30:16 PM (16 years ago)
- Location:
- code/branches/gui/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/input/InputManager.cc
r2800 r2814 174 174 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); 175 175 //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND"))); 176 #if defined O IS_LINUX_PLATFORM176 #if defined ORXONOX_PLATFORM_LINUX 177 177 paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true"))); 178 178 paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true")); … … 219 219 220 220 // Lowest priority empty InputState 221 stateEmpty_ = createInputState<SimpleInputState>("empty", -1);221 stateEmpty_ = createInputState<SimpleInputState>("empty", InputStatePriority::Empty); 222 222 stateEmpty_->setHandler(&EMPTY_HANDLER); 223 223 activeStates_[stateEmpty_->getPriority()] = stateEmpty_; … … 229 229 230 230 // KeyDetector to evaluate a pressed key's name 231 SimpleInputState* detector = createInputState<SimpleInputState>("detector", 101);231 SimpleInputState* detector = createInputState<SimpleInputState>("detector", InputStatePriority::Detector); 232 232 keyDetector_ = new KeyDetector(); 233 233 detector->setHandler(keyDetector_); 234 234 235 235 // Joy stick calibration helper callback 236 SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", 100);236 SimpleInputState* calibrator = createInputState<SimpleInputState>("calibrator", InputStatePriority::Calibrator); 237 237 calibrator->setHandler(&EMPTY_HANDLER); 238 238 calibratorCallbackBuffer_ = new InputBuffer(); … … 428 428 429 429 // inform all states 430 for (std::map< int, InputState*>::const_iterator it = inputStatesByPriority_.begin();431 it != inputStatesBy Priority_.end(); ++it)430 for (std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.begin(); 431 it != inputStatesByName_.end(); ++it) 432 432 { 433 433 it->second->setNumOfJoySticks(joySticksSize_); … … 555 555 556 556 // destroy all user InputStates 557 while (inputStatesBy Priority_.size() > 0)558 _destroyState((*inputStatesBy Priority_.rbegin()).second);557 while (inputStatesByName_.size() > 0) 558 _destroyState((*inputStatesByName_.rbegin()).second); 559 559 560 560 // destroy the devices … … 640 640 _updateActiveStates(); 641 641 } 642 inputStatesByPriority_.erase(state->getPriority());643 642 inputStatesByName_.erase(state->getName()); 644 643 delete state; … … 768 767 769 768 activeStates_.erase((*rit)->getPriority()); 769 if ((*rit)->getPriority() < InputStatePriority::HighPriority) 770 (*rit)->setPriority(0); 770 771 _updateActiveStates(); 771 772 } … … 782 783 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 783 784 785 if ((*rit)->getPriority() == 0) 786 { 787 // Get smallest possible priority between 1 and maxStateStackSize_s 788 for(std::map<int, InputState*>::const_reverse_iterator rit2 = activeStates_.rbegin(); 789 rit2 != activeStates_.rend(); ++rit2) 790 { 791 if (rit2->first < InputStatePriority::HighPriority) 792 { 793 (*rit)->setPriority(rit2->first + 1); 794 break; 795 } 796 } 797 // In case no normal handler was on the stack 798 if ((*rit)->getPriority() == 0) 799 (*rit)->setPriority(1); 800 } 784 801 activeStates_[(*rit)->getPriority()] = (*rit); 785 802 _updateActiveStates(); … … 813 830 _updateActiveStates(); 814 831 815 // mark that we capture and distributeinput832 // mark that we now start capturing and distributing input 816 833 internalState_ |= Ticking; 817 834 … … 1246 1263 Unique name of the handler. 1247 1264 @param priority 1248 Unique integer number. Higher means more prioritised. 1265 Determines which InputState gets the input. Higher is better. 1266 Use 0 to handle it implicitely by the order of activation. 1267 Otherwise numbers larger than maxStateStackSize_s have to be used! 1249 1268 @return 1250 1269 True if added, false if name or priority already existed. … … 1258 1277 if (inputStatesByName_.find(name) == inputStatesByName_.end()) 1259 1278 { 1260 if (inputStatesByPriority_.find(priority) 1261 == inputStatesByPriority_.end()) 1262 { 1263 inputStatesByName_[name] = state; 1264 inputStatesByPriority_[priority] = state; 1265 state->setNumOfJoySticks(numberOfJoySticks()); 1266 state->setName(name); 1279 if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty) 1280 { 1281 // Make sure we don't add two high priority states with the same priority 1282 for (std::map<std::string, InputState*>::const_iterator it = this->inputStatesByName_.begin(); 1283 it != this->inputStatesByName_.end(); ++it) 1284 { 1285 if (it->second->getPriority() == priority) 1286 { 1287 COUT(2) << "Warning: Could not add an InputState with the same priority '" 1288 << priority << "' != 0." << std::endl; 1289 return false; 1290 } 1291 } 1292 } 1293 inputStatesByName_[name] = state; 1294 state->setNumOfJoySticks(numberOfJoySticks()); 1295 state->setName(name); 1296 if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty) 1267 1297 state->setPriority(priority); 1268 return true; 1269 } 1270 else 1271 { 1272 COUT(2) << "Warning: Could not add an InputState with the same priority '" 1273 << priority << "'." << std::endl; 1274 return false; 1275 } 1298 return true; 1276 1299 } 1277 1300 else … … 1372 1395 { 1373 1396 // not scheduled for destruction 1374 // setprevents a state being added multiple times1397 // prevents a state being added multiple times 1375 1398 stateEnterRequests_.insert(it->second); 1376 1399 return true; … … 1391 1414 bool InputManager::requestLeaveState(const std::string& name) 1392 1415 { 1416 if (name == "empty") 1417 { 1418 COUT(2) << "InputManager: Leaving the empty state is not allowed!" << std::endl; 1419 return false; 1420 } 1393 1421 // get pointer from the map with all stored handlers 1394 1422 std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name); -
code/branches/gui/src/core/input/InputManager.h
r2800 r2814 43 43 #include <stack> 44 44 #include "util/Math.h" 45 #include "util/OrxEnum.h" 45 46 #include "core/OrxonoxClass.h" 46 47 #include "InputInterfaces.h" … … 74 75 float positiveCoeff[24]; 75 76 float negativeCoeff[24]; 77 }; 78 79 struct InputStatePriority : OrxEnum<InputStatePriority> 80 { 81 OrxEnumConstructors(InputStatePriority); 82 83 static const int Empty = -1; 84 static const int Dynamic = 0; 85 86 static const int HighPriority = 1000; 87 static const int Console = HighPriority + 0; 88 static const int Calibrator = HighPriority + 1; 89 static const int Detector = HighPriority + 2; 76 90 }; 77 91 … … 116 130 117 131 template <class T> 118 T* createInputState(const std::string& name, int priority);132 T* createInputState(const std::string& name, InputStatePriority priority = InputStatePriority::Dynamic); 119 133 120 134 InputState* getState (const std::string& name); … … 202 216 203 217 std::map<std::string, InputState*> inputStatesByName_; 204 std::map<int, InputState*> inputStatesByPriority_;205 218 206 219 std::set<InputState*> stateEnterRequests_; //!< Request to enter a new state … … 249 262 */ 250 263 template <class T> 251 T* InputManager::createInputState(const std::string& name, intpriority)264 T* InputManager::createInputState(const std::string& name, InputStatePriority priority) 252 265 { 253 266 T* state = new T; -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r2801 r2814 82 82 if (Core::showsGraphics()) 83 83 { 84 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game" , 20);84 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game"); 85 85 keyBinder_ = new KeyBinder(); 86 86 keyBinder_->loadBindings("keybindings.ini"); -
code/branches/gui/src/orxonox/gui/GUIManager.cc
r2808 r2814 167 167 168 168 // register us as input handler 169 SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui" , 30);169 SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui"); 170 170 state->setHandler(this); 171 171 state->setJoyStickHandler(&InputManager::EMPTY_HANDLER); -
code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc
r2801 r2814 173 173 { 174 174 // create the corresponding input state 175 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", 40);175 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("console", InputStatePriority::Console); 176 176 inputState_->setKeyHandler(Shell::getInstance().getInputBuffer()); 177 177 bHidesAllInputChanged();
Note: See TracChangeset
for help on using the changeset viewer.