Vultraz

Untitled

Jul 13th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. bool has_focus(const sdl_handler* hand, const SDL_Event* event)
  2. {
  3.     if(event_contexts.empty()) {
  4.         return true;
  5.     }
  6.  
  7.     if(hand->requires_event_focus(event) == false) {
  8.         return true;
  9.     }
  10.  
  11.     const handler_list::iterator foc = event_contexts.back().focused_handler;
  12.  
  13.     //if no-one has focus at the moment, this handler obviously wants
  14.     //focus, so give it to it.
  15.     if(foc == handlers.end()) {
  16.         focus_handler(hand);
  17.         return true;
  18.     }
  19.  
  20.     sdl_handler* const foc_hand = *foc;
  21.     if(foc_hand == hand){
  22.         return true;
  23.     } else if(!foc_hand->requires_event_focus(event)) {
  24.         //if the currently focused handler doesn't need focus for this event
  25.         //allow the most recent interested handler to take care of it
  26.         auto handlers& = event_contexts.back().handlers;
  27.  
  28.         //auto back = handlers.end();
  29.         //--back;
  30.         for(auto i = handlers.rbegin(); i != handlers.rend(); ++i) {
  31.             sdl_handler* const thief_hand = *i;
  32.             if(i != foc && thief_hand->requires_event_focus(event)) {
  33.                 //steal focus
  34.                 focus_handler(thief_hand);
  35.  
  36.                 //position the previously focused handler to allow stealing back
  37.                 //event_contexts.back().delete_handler_index(foc);
  38.                 //event_contexts.back().add_handler(foc_hand);
  39.                 handlers.splice(handlers.end(), handlers, foc);
  40.  
  41.                 return thief_hand == hand;
  42.             }
  43.         }
  44.     }
  45.     return false;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment