int _tmain(int argc, _TCHAR* argv[]) { if (!init()) { printf("Failed to initialize!\n"); return 0; } bool quit = false; while (!quit) { SDL_Event e; while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } else if (e.type == SDL_MOUSEBUTTONDOWN) { onMouseDown(e.button); } else if (e.type == SDL_MOUSEBUTTONUP) { onMouseUp(e.button); } else if (e.type == SDL_MOUSEWHEEL) { onMouseWheel(e.wheel); } else if (e.type == SDL_KEYDOWN) { OnKeyDown(e.key); } else if (e.type == SDL_WINDOWEVENT) { onWindowEvent(e.window); } } // Render render(); // Update screen SDL_GL_SwapWindow(gWindow); } // Free resources and close SDL close(); return 0; }
void SDLEventHandler::HandleEvent(const SDL_Event& e) { switch (e.type) { case SDL_KEYDOWN: case SDL_KEYUP: onKeyboardEvent(e.key); break; case SDL_MOUSEMOTION: onMouseMotionEvent(e.motion); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: onMouseButtonEvent(e.button); break; case SDL_QUIT: onQuitEvent(); break; case SDL_JOYAXISMOTION: onJoyAxisEvent(e.jaxis); break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: onJoyButtonEvent(e.jbutton); break; case SDL_JOYHATMOTION: onJoyHatEvent(e.jhat); break; case SDL_JOYBALLMOTION: onJoyBallEvent(e.jball); break; case SDL_WINDOWEVENT: onWindowEvent(e.window); break; default: // Unexpected event type! //assert(0); break; } }