bool PG_MessageObject::ProcessEvent(const SDL_Event* event) { SDL_Event e; // check if we are able to process messages if(!my_canReceiveMessages) { return false; } if(event->type != SDL_USEREVENT) { if(captureObject != this) if(!AcceptEvent(event)) { return false; } } if((captureObject != NULL) && (captureObject != this)) { return false; } while(SDL_PeepEvents(&e, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK) > 0); bool rc = false; // dispatch message switch(event->type) { case SDL_ACTIVEEVENT: rc = eventActive(&event->active) || sigActive(this, &event->active); break; case SDL_KEYDOWN: rc = eventKeyDown(&event->key) || sigKeyDown(this, &event->key); break; case SDL_KEYUP: rc = eventKeyUp(&event->key) || sigKeyUp(this, &event->key);; break; case SDL_MOUSEMOTION: rc = eventMouseMotion(&event->motion) || sigMouseMotion(this, &event->motion); break; case SDL_MOUSEBUTTONDOWN: rc = eventMouseButtonDown(&event->button) || sigMouseButtonDown(this, &event->button); break; case SDL_MOUSEBUTTONUP: rc = eventMouseButtonUp(&event->button) || sigMouseButtonUp(this, &event->button); break; case SDL_QUIT: rc = eventQuit(0, NULL, (unsigned long)&event->quit) || sigQuit(this); break; case SDL_SYSWMEVENT: rc = eventSysWM(&event->syswm) || sigSysWM(this, &event->syswm); break; case SDL_VIDEORESIZE: rc = eventResize(&event->resize) || sigVideoResize(this, &event->resize); break; default: rc = false; break; } return rc; }
bool Window::handleEvent() { SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: case SDL_MOUSEMOTION: input.setLastMouseEvent(Chrono::getCurMillis()); input.setMousePos(Vec2i(event.button.x, event.button.y)); } switch(event.type) { case SDL_QUIT: return false; case SDL_MOUSEBUTTONDOWN: handleMouseDown(event); break; case SDL_MOUSEBUTTONUP: { MouseButton b = Input::getMouseButton(event.button.button); input.setMouseState(b, false); eventMouseUp(event.button.x, event.button.y, b); break; } case SDL_MOUSEMOTION: input.setMouseState(MouseButton::LEFT, event.motion.state & SDL_BUTTON_LMASK); input.setMouseState(MouseButton::RIGHT, event.motion.state & SDL_BUTTON_RMASK); input.setMouseState(MouseButton::MIDDLE, event.motion.state & SDL_BUTTON_MMASK); eventMouseMove(event.motion.x, event.motion.y, input.getMouseState()); break; case SDL_KEYDOWN: /* handle ALT+Return */ if(event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & (KMOD_LALT | KMOD_RALT))) { toggleFullscreen(); } else { eventKeyDown(Key(event.key.keysym)); eventKeyPress(static_cast<char>(event.key.keysym.unicode)); } break; case SDL_KEYUP: eventKeyUp(Key(event.key.keysym)); break; case SDL_ACTIVEEVENT: if(event.active.state & SDL_APPACTIVE){ if(event.active.gain){ // got focus eventResize(ssRestored); }else{ // lost focus (minimized) eventResize(ssMinimized); } } break; } } return true; }