void Event::onEvent(SDL_Event* event) { switch (event->type) { case SDL_ACTIVEEVENT: { switch(event->active.state) { case SDL_APPMOUSEFOCUS: { if (event->active.gain) onMouseFocus(); else onMouseBlur(); break; } case SDL_APPINPUTFOCUS: { if (event->active.gain) onInputFocus(); else onInputBlur(); break; } case SDL_APPACTIVE: { if (event->active.gain) onRestore(); else onMinimize(); break; } } break; } case SDL_KEYDOWN: { onKeyDown(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; } case SDL_KEYUP: { onKeyUp(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; } case SDL_MOUSEMOTION: { onMouseMove(event->motion.x, event->motion.y, event->motion.xrel, event->motion.yrel, (event->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT)) != 0, (event->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0, (event->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0); break; } case SDL_MOUSEBUTTONDOWN: { switch(event->button.button) { case SDL_BUTTON_LEFT: { onLButtonDown(event->button.x, event->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonDown(event->button.x, event->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonDown(event->button.x, event->button.y); break; } } break; } case SDL_MOUSEBUTTONUP: { switch(event->button.button) { case SDL_BUTTON_LEFT: { onLButtonUp(event->button.x, event->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonUp(event->button.x, event->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonUp(event->button.x, event->button.y); break; } } break; } case SDL_JOYAXISMOTION: { onJoyAxis(event->jaxis.which, event->jaxis.axis, event->jaxis.value); break; } case SDL_JOYBALLMOTION: { onJoyBall(event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel); break; } case SDL_JOYHATMOTION: { onJoyHat(event->jhat.which, event->jhat.hat, event->jhat.value); break; } case SDL_JOYBUTTONDOWN: { onJoyButtonDown(event->jbutton.which, event->jbutton.button); break; } case SDL_JOYBUTTONUP: { onJoyButtonUp(event->jbutton.which, event->jbutton.button); break; } case SDL_QUIT: { onExit(); break; } case SDL_SYSWMEVENT: { onResize(event->resize.w, event->resize.h); break; } case SDL_VIDEOEXPOSE: { onExpose(); break; } default: { onUser(event->user.type, event->user.code, event->user.data1, event->user.data2); break; } } }
//============================================================================== void CEvent::onEvent(SDL_Event *anEvent) { switch(anEvent->type) { case SDL_WINDOWEVENT: { switch(anEvent->window.event) { case SDL_WINDOWEVENT_ENTER:{ onMouseFocus(); break; } case SDL_WINDOWEVENT_LEAVE:{ onMouseBlur(); break; } case SDL_WINDOWEVENT_FOCUS_GAINED: { onInputFocus(); break; } case SDL_WINDOWEVENT_FOCUS_LOST: { onInputBlur(); break; } case SDL_WINDOWEVENT_RESTORED: { onRestore(); break; } case SDL_WINDOWEVENT_MINIMIZED: { onMinimize(); break; } } break; } case SDL_KEYDOWN: { onKeyPress(anEvent->key.keysym.sym, anEvent->key.keysym.mod); break; } case SDL_KEYUP: { onKeyRelease(anEvent->key.keysym.sym,anEvent->key.keysym.mod); break; } case SDL_MOUSEMOTION: { onMouseMove(anEvent->motion.x, anEvent->motion.y, anEvent->motion.xrel, anEvent->motion.yrel,(anEvent->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(anEvent->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(anEvent->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0); break; } case SDL_MOUSEBUTTONDOWN: { switch(anEvent->button.button) { case SDL_BUTTON_LEFT: { onLButtonDown(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonDown(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonDown(anEvent->button.x,anEvent->button.y); break; } } break; } case SDL_MOUSEBUTTONUP: { switch(anEvent->button.button) { case SDL_BUTTON_LEFT: { onLButtonUp(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonUp(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonUp(anEvent->button.x,anEvent->button.y); break; } } break; } case SDL_QUIT: { onExit(); break; } case SDL_SYSWMEVENT: { //Ignore break; } case SDL_WINDOWEVENT_RESIZED: { onResize(anEvent->window.data1,anEvent->window.data2); break; } case SDL_WINDOWEVENT_EXPOSED: { onExpose(); break; } default: { onUser(anEvent->user.type,anEvent->user.code,anEvent->user.data1,anEvent->user.data2); break; } } }