blob: 61e0c795fa159897b9cd19c042924d8d445a91fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#define SDL_ERROR(FMT, ...) do { \
fprintf(stderr, "%s(%d): " FMT ": %s\n", \
__FILE__, __LINE__, ##__VA_ARGS__, SDL_GetError()); \
} while (0)
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
static SDL_Surface *screen;
static inline void
handle_events(void)
{
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_f:
if (!SDL_WM_ToggleFullScreen(screen)) {
SDL_ERROR("SDL_WM_ToggleFullScreen");
exit(EXIT_FAILURE);
}
break;
case SDLK_m:
SDL_ShowCursor(!SDL_ShowCursor(SDL_QUERY));
break;
case SDLK_ESCAPE:
exit(EXIT_SUCCESS);
default:
break;
}
break;
case SDL_QUIT:
exit(EXIT_SUCCESS);
default:
break;
}
}
}
int
main(int argc, char **argv)
{
if (SDL_Init(SDL_INIT_VIDEO)) {
SDL_ERROR("SDL_Init");
return EXIT_FAILURE;
}
atexit(SDL_Quit);
SDL_WM_SetCaption("Effect Pad", NULL);
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32,
SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL) {
SDL_ERROR("SDL_SetVideoMode");
return EXIT_FAILURE;
}
for (;;) {
handle_events();
SDL_Delay(100);
}
/* never reached */
return EXIT_FAILURE;
}
|