aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile16
-rw-r--r--effect-pad.c79
2 files changed, 95 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..00f72ad
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+CC := gcc
+
+SDL_CFLAGS := $(shell sdl-config --cflags)
+SDL_LDFLAGS := $(shell sdl-config --libs)
+
+CFLAGS := -std=c99 -Wall -g -O0 \
+ $(SDL_CFLAGS)
+LDFLAGS := $(SDL_LDFLAGS)
+
+all : effect-pad
+
+effect-pad : effect-pad.o
+ $(CC) $(LDFLAGS) $^ -o $@
+
+clean:
+ $(RM) *.o effect-pad{,.exe}
diff --git a/effect-pad.c b/effect-pad.c
new file mode 100644
index 0000000..61e0c79
--- /dev/null
+++ b/effect-pad.c
@@ -0,0 +1,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;
+}