Changeset 7895 in orxonox.OLD for branches/gui/src/lib/event
- Timestamp:
- May 27, 2006, 5:29:48 AM (18 years ago)
- Location:
- branches/gui/src/lib/event
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gui/src/lib/event/event_handler.cc
r7868 r7895 42 42 43 43 /* now initialize them all to zero */ 44 this->withUNICODE(false); 44 for (unsigned int i = 0; i < ES_NUMBER; i++) 45 this->bUNICODE[i] = false; 45 46 this->grabEvents(false); 46 47 … … 87 88 this->keyMapper.loadKeyBindings(); 88 89 } 90 91 /** 92 * @param state: to which the event handler shall change 93 */ 94 void EventHandler::setState(elState state) 95 { 96 this->state = state; 97 SDL_EnableUNICODE(this->bUNICODE[state]); 98 }; 99 89 100 90 101 /** … … 144 155 { 145 156 for(unsigned int i = 0; i < ES_NUMBER; i++) 146 {147 if( !likely(this->listeners[i][eventType].empty()))148 {149 PRINTF(2)("'%s' of class '%s' tried to subscribe to event %i @ state %i but this event has already been subscribed\n", el->getName(), el->getClassName(), eventType, state);150 }151 157 this->listeners[i][eventType].push_back(el); 152 } 153 } 154 else 155 { 156 if( likely(!this->listeners[state][eventType].empty())) 157 { 158 PRINTF(2)("%s of class %s tried to subscribe to event %i @ state %i but this event has already been subscribed\n", el->getName(), el->getClassName(), eventType, state); 159 } 158 } 159 else 160 160 this->listeners[state][eventType].push_back(el); 161 }162 161 } 163 162 … … 178 177 { 179 178 std::vector<EventListener*>::iterator listener = 180 181 182 179 std::find(this->listeners[i][eventType].begin(), 180 this->listeners[i][eventType].end(), 181 el); 183 182 if (listener != this->listeners[i][eventType].end()) 184 183 this->listeners[i][eventType].erase(listener); … … 187 186 { 188 187 std::vector<EventListener*>::iterator listener = 189 190 191 188 std::find(this->listeners[state][eventType].begin(), 189 this->listeners[state][eventType].end(), 190 el); 192 191 if (listener != this->listeners[state][eventType].end()) 193 192 this->listeners[state][eventType].erase(listener); … … 261 260 262 261 263 void EventHandler::withUNICODE(bool enableUNICODE) 264 { 265 SDL_EnableUNICODE(enableUNICODE); 266 this->bUNICODE = enableUNICODE; 262 void EventHandler::withUNICODE(elState state, bool enableUNICODE) 263 { 264 this->bUNICODE[state] = enableUNICODE; 265 if (this->state == state) 266 SDL_EnableUNICODE(enableUNICODE); 267 267 } 268 268 … … 283 283 284 284 /** 285 * core function of event handler: receives all events from SDL286 287 288 */285 * @brief core function of event handler: receives all events from SDL 286 * 287 * The event from the SDL framework are collected here and distributed to all listeners. 288 */ 289 289 void EventHandler::process() 290 290 { … … 299 299 ev.bPressed = true; 300 300 ev.type = event.key.keysym.sym; 301 if (unlikely(this->bUNICODE ))301 if (unlikely(this->bUNICODE[this->state])) 302 302 ev.x = event.key.keysym.unicode; 303 303 break; … … 305 305 ev.bPressed = false; 306 306 ev.type = event.key.keysym.sym; 307 if (unlikely(this->bUNICODE ))307 if (unlikely(this->bUNICODE[this->state])) 308 308 ev.x = event.key.keysym.unicode; 309 309 break; … … 358 358 /* small debug routine: shows all events dispatched by the event handler */ 359 359 PRINT(4)("\n==========================| EventHandler::process () |===\n"); 360 PRINT(4)("= Got Event nr %i, for state %i", ev.type, this->state); 361 362 363 for (unsigned int i = 0; i < this->listeners[this->state][ev.type].size(); i++) 360 PRINT(4)("= Got Event nr %i, for state %i\n", ev.type, this->state); 361 362 /// setting a temporary state in case of an EventListener's process changes the state. 363 elState currentState = this->state; 364 for (unsigned int i = 0; i < this->listeners[currentState][ev.type].size(); i++) 364 365 { 365 366 PRINT(4)("= Event dispatcher msg: This event has been consumed\n"); 367 PRINT(4)("= Got Event nr %i, for state %i %s::%s\n", ev.type, currentState, this->listeners[this->state][ev.type][i]->getClassName(), this->listeners[currentState][ev.type][i]->getName()); 366 368 PRINT(4)("=======================================================\n"); 367 listeners[this->state][ev.type][i]->process(ev);369 this->listeners[currentState][ev.type][i]->process(ev); 368 370 } 369 371 /* else … … 375 377 } 376 378 377 379 /** 380 * @brief An eventFilter. 381 * @param event the Event to be filtered. 382 * @returns 0 on filtered Event. 1 Otherwise. 383 */ 378 384 int EventHandler::eventFilter(const SDL_Event *event) 379 385 { … … 400 406 401 407 /** 402 * outputs some nice information about the EventHandler408 * @brief outputs some nice information about the EventHandler 403 409 */ 404 410 void EventHandler::debug() const … … 408 414 PRINT(0)("===============================\n"); 409 415 for(int i = 0; i < ES_NUMBER; ++i) 416 { 410 417 for(int j = 0; j < EV_NUMBER; ++j) 411 418 for (unsigned int evl = 0; evl < this->listeners[i][j].size(); evl++) 412 419 PRINT(0)("Event %d of State %d subscribed to %s (%p)\n", j, i, this->listeners[i][j][evl]->getName(), this->listeners[i][j][evl]); 420 } 413 421 PRINT(0)("============================EH=\n"); 414 422 } -
branches/gui/src/lib/event/event_handler.h
r7868 r7895 26 26 void init(); 27 27 28 /** @param state: to which the event handler shall change */ 29 inline void setState(elState state) { this->state = state; }; 28 void setState(elState state); 30 29 /** @returns the current state */ 31 30 inline elState getState() const { return this->state; }; … … 42 41 43 42 44 void withUNICODE( bool enableUNICODE);43 void withUNICODE(elState state, bool enableUNICODE); 45 44 void grabEvents(bool grabEvents); 46 45 bool grabbedEvents() const { return this->eventsGrabbed; }; … … 62 61 KeyMapper keyMapper; //!< reference to the key mapper. 63 62 64 bool bUNICODE ;//!< If unicode should be enabled.63 bool bUNICODE[ES_NUMBER]; //!< If unicode should be enabled. 65 64 bool eventsGrabbed; //!< If the events should be grabbed 66 65 };
Note: See TracChangeset
for help on using the changeset viewer.