Changeset 2814 for code/branches/gui/src/core/input/InputManager.cc
- Timestamp:
- Mar 21, 2009, 5:30:16 PM (16 years ago)
- File:
-
- 1 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);
Note: See TracChangeset
for help on using the changeset viewer.