Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool has_focus(const sdl_handler* hand, const SDL_Event* event)
- {
- if(event_contexts.empty()) {
- return true;
- }
- if(hand->requires_event_focus(event) == false) {
- return true;
- }
- const handler_list::iterator foc = event_contexts.back().focused_handler;
- //if no-one has focus at the moment, this handler obviously wants
- //focus, so give it to it.
- if(foc == handlers.end()) {
- focus_handler(hand);
- return true;
- }
- sdl_handler* const foc_hand = *foc;
- if(foc_hand == hand){
- return true;
- } else if(!foc_hand->requires_event_focus(event)) {
- //if the currently focused handler doesn't need focus for this event
- //allow the most recent interested handler to take care of it
- auto handlers& = event_contexts.back().handlers;
- //auto back = handlers.end();
- //--back;
- for(auto i = handlers.rbegin(); i != handlers.rend(); ++i) {
- sdl_handler* const thief_hand = *i;
- if(i != foc && thief_hand->requires_event_focus(event)) {
- //steal focus
- focus_handler(thief_hand);
- //position the previously focused handler to allow stealing back
- //event_contexts.back().delete_handler_index(foc);
- //event_contexts.back().add_handler(foc_hand);
- handlers.splice(handlers.end(), handlers, foc);
- return thief_hand == hand;
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment