#include "mainevent.h" void MainEvent::handle_event(SDL_Event* event) { switch(event->type) { // Interactions with the WM case SDL_ACTIVEEVENT: switch (event->active.state) { case SDL_APPMOUSEFOCUS: if (event->active.gain) on_mouse_focus(); else on_mouse_blur(); break; case SDL_APPINPUTFOCUS: if (event->active.gain) on_input_focus(); else on_input_blur(); break; case SDL_APPACTIVE: if (event->active.gain) on_restore(); else on_minimize(); break; } break; // keyboard keypresses case SDL_KEYDOWN: on_key_down(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; case SDL_KEYUP: on_key_up(event->key.keysym.sym, event->key.keysym.mod, event->key.keysym.unicode); break; // mouse events case SDL_MOUSEMOTION: on_mouse_move(event->motion.x, event->motion.y, event->motion.xrel, event->motion.yrel, event->motion.state & SDL_BUTTON(SDL_BUTTON_LEFT), event->motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT), event->motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)); break; case SDL_MOUSEBUTTONDOWN: switch(event->button.button) { case SDL_BUTTON_LEFT: on_lbutton_down(event->button.x, event->button.y); break; case SDL_BUTTON_RIGHT: on_rbutton_down(event->button.x, event->button.y); break; case SDL_BUTTON_MIDDLE: on_mbutton_down(event->button.x, event->button.y); break; } break; case SDL_MOUSEBUTTONUP: switch(event->button.button) { case SDL_BUTTON_LEFT: on_lbutton_up(event->button.x, event->button.y); break; case SDL_BUTTON_RIGHT: on_rbutton_up(event->button.x, event->button.y); break; case SDL_BUTTON_MIDDLE: on_mbutton_up(event->button.x, event->button.y); break; } break; // joystick events case SDL_JOYAXISMOTION: on_joy_axis(event->jaxis.which, event->jaxis.axis, event->jaxis.value); break; case SDL_JOYBALLMOTION: on_joy_ball(event->jball.which, event->jball.ball, event->jball.xrel, event->jball.yrel); break; case SDL_JOYHATMOTION: on_joy_hat(event->jhat.which, event->jhat.hat, event->jhat.value); break; case SDL_JOYBUTTONDOWN: on_joy_button_down(event->jbutton.which, event->jbutton.button); break; case SDL_JOYBUTTONUP: on_joy_button_up(event->jbutton.which, event->jbutton.button); break; // Other events case SDL_QUIT: on_exit(); break; case SDL_VIDEORESIZE: on_resize(event->resize.w, event->resize.h); break; case SDL_VIDEOEXPOSE: on_expose(); break; default: on_user(event->user.type, event->user.code, event->user.data1, event->user.data2); } } // handle_event