Skip to content

Instantly share code, notes, and snippets.

@jorgenpt
Created June 4, 2013 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgenpt/5710142 to your computer and use it in GitHub Desktop.
Save jorgenpt/5710142 to your computer and use it in GitHub Desktop.
#include <SDL.h>
int PollEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
return 1;
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_ENTER)
printf("Mouse focus gained\n");
else if (event.window.event == SDL_WINDOWEVENT_LEAVE)
printf("Mouse focus lost\n");
break;
case SDL_MOUSEMOTION:
printf("relative mm: %d, %d\n", event.motion.xrel, event.motion.yrel);
break;
default:
break;
}
}
return 0;
}
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *win = SDL_CreateWindow("Test",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
800, 600, 0
);
SDL_ShowCursor(SDL_FALSE);
while (1)
{
if (PollEvents())
break;
}
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment