Mercurial > sdl-ios-xcode
annotate test/testwm2.c @ 5267:b530ef003506
Happy 2011! :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 11 Feb 2011 22:37:15 -0800 |
parents | 58265e606e4e |
children |
rev | line source |
---|---|
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
2 #include <stdlib.h> |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
3 #include <stdio.h> |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
5 #include "common.h" |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
7 static CommonState *state; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 quit(int rc) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
13 CommonQuit(state); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 exit(rc); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 main(int argc, char *argv[]) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 int i, done; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
23 /* Initialize test framework */ |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
24 state = CommonCreateState(argv, SDL_INIT_VIDEO); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
25 if (!state) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
26 return 1; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
28 state->skip_renderer = SDL_TRUE; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
29 for (i = 1; i < argc;) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
30 int consumed; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
32 consumed = CommonArg(state, i); |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
33 if (consumed == 0) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
34 consumed = -1; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
35 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
36 if (consumed < 0) { |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1933
diff
changeset
|
37 fprintf(stderr, "Usage: %s %s\n", argv[0], CommonUsage(state)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 quit(1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 } |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
40 i += consumed; |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
41 } |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
42 if (!CommonInit(state)) { |
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
43 quit(2); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
46 /* Main render loop */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 done = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 while (!done) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 /* Check for events */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 while (SDL_PollEvent(&event)) { |
1933
7ee5297340f7
Implemented Cocoa window support
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
51 CommonEvent(state, &event, &done); |
5251
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
52 |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
53 if (event.type == SDL_WINDOWEVENT) { |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
54 if (event.window.event == SDL_WINDOWEVENT_MOVED) { |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
55 SDL_Window *window = SDL_GetWindowFromID(event.window.windowID); |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
56 if (window) { |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
57 printf("Window %d moved to %d,%d (display %d)\n", |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
58 event.window.windowID, |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
59 event.window.data1, |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
60 event.window.data2, |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
61 SDL_GetWindowDisplay(window)); |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
62 } |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
63 } |
58265e606e4e
Window coordinates are in the global space and windows are not tied to a particular display.
Sam Lantinga <slouken@libsdl.org>
parents:
3338
diff
changeset
|
64 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 quit(0); |
3338 | 68 // keep the compiler happy ... |
69 return(0); | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 /* vi: set ts=4 sw=4 expandtab: */ |