Mercurial > sdl-ios-xcode
annotate test/testintersections.c @ 3133:84119fe89d26 gsoc2009_IME
Draw cursor, underline marked text
author | Jiang Jiang <gzjjgod@gmail.com> |
---|---|
date | Wed, 01 Jul 2009 16:12:00 +0000 |
parents | e4f025078c1c |
children | 438ba87e9578 |
rev | line source |
---|---|
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 /* Simple program: draw as many random objects on the screen as possible */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 #include <stdlib.h> |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 #include <time.h> |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #include "common.h" |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while(0) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 #define NUM_OBJECTS 100 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 static CommonState *state; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 static int num_objects; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 static SDL_bool cycle_color; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 static SDL_bool cycle_alpha; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 static int cycle_direction = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 static int current_alpha = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 static int current_color = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 DrawPoints(SDL_WindowID window) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 int x, y; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 int window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 SDL_SetRenderDrawBlendMode(blendMode); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 for (i = 0; i < num_objects * 4; ++i) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 /* Cycle the color and alpha, if desired */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 if (cycle_color) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 current_color += cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 if (current_color < 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 current_color = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 if (current_color > 255) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 current_color = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 if (cycle_alpha) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 current_alpha += cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 if (current_alpha < 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 current_alpha = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 if (current_alpha > 255) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 current_alpha = 255; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 cycle_direction = -cycle_direction; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 SDL_SetRenderDrawColor(255, (Uint8) current_color, |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 (Uint8) current_color, (Uint8) current_alpha); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 x = rand() % window_w; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 y = rand() % window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 SDL_RenderPoint(x, y); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 #define MAX_LINES 16 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 int num_lines = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 SDL_Rect lines[MAX_LINES]; |
2997 | 70 static int |
71 add_line(int x1, int y1, int x2, int y2) | |
72 { | |
73 if (num_lines >= MAX_LINES) | |
74 return 0; | |
75 if ((x1 == x2) && (y1 == y2)) | |
76 return 0; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 lines[num_lines].x = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 lines[num_lines].y = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 lines[num_lines].w = x2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 lines[num_lines].h = y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 return ++num_lines; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 DrawLines(SDL_WindowID window) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 int x1, y1, x2, y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 int window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 SDL_SetRenderDrawBlendMode(blendMode); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 for (i = 0; i < num_lines; ++i) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 SDL_SetRenderDrawColor(255, 255, 255, 255); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 if (i == -1) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 SDL_RenderLine(0, 0, window_w - 1, window_h - 1); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 SDL_RenderLine(0, window_h - 1, window_w - 1, 0); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 SDL_RenderLine(0, window_h / 2, window_w - 1, window_h / 2); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 SDL_RenderLine(window_w / 2, 0, window_w / 2, window_h - 1); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 } else { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 SDL_RenderLine(lines[i].x, lines[i].y, lines[i].w, lines[i].h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 #define MAX_RECTS 16 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 int num_rects = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 SDL_Rect rects[MAX_RECTS]; |
2997 | 117 static int |
118 add_rect(int x1, int y1, int x2, int y2) | |
119 { | |
120 if (num_rects >= MAX_RECTS) | |
121 return 0; | |
122 if ((x1 == x2) || (y1 == y2)) | |
123 return 0; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 |
2997 | 125 if (x1 > x2) |
126 SWAP(int, x1, x2); | |
127 if (y1 > y2) | |
128 SWAP(int, y1, y2); | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
2997 | 130 printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, |
131 x2 - x1, y2 - y1); | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 rects[num_rects].x = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 rects[num_rects].y = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 rects[num_rects].w = x2 - x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 rects[num_rects].h = y2 - y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 return ++num_rects; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 static void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 DrawRects(SDL_WindowID window) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 int window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 for (i = 0; i < num_rects; ++i) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 SDL_SetRenderDrawColor(255, 127, 0, 255); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 SDL_RenderFill(&rects[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 static void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 DrawRectLineIntersections(SDL_WindowID window) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 int i, j, window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 SDL_GetWindowSize(window, &window_w, &window_h); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 for (i = 0; i < num_rects; i++) |
2997 | 169 for (j = 0; j < num_lines; j++) { |
170 int x1, y1, x2, y2; | |
171 SDL_Rect r; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 |
2997 | 173 r = rects[i]; |
174 x1 = lines[j].x; | |
175 y1 = lines[j].y; | |
176 x2 = lines[j].w; | |
177 y2 = lines[j].h; | |
178 | |
179 if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) { | |
180 SDL_SetRenderDrawColor(0, 255, 55, 255); | |
181 SDL_RenderLine(x1, y1, x2, y2); | |
182 } | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 static void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 DrawRectRectIntersections(SDL_WindowID window) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 int i, j; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 for (i = 0; i < num_rects; i++) |
2997 | 196 for (j = i + 1; j < num_rects; j++) { |
197 SDL_Rect r; | |
198 if (SDL_IntersectRect(&rects[i], &rects[j], &r)) { | |
199 SDL_SetRenderDrawColor(255, 200, 0, 255); | |
200 SDL_RenderFill(&r); | |
201 } | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 int |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 main(int argc, char *argv[]) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 int mouse_begin_x = -1, mouse_begin_y = -1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 int i, done; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 SDL_Event event; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 Uint32 then, now, frames; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 /* Initialize parameters */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 num_objects = NUM_OBJECTS; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 /* Initialize test framework */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 state = CommonCreateState(argv, SDL_INIT_VIDEO); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 if (!state) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 return 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 for (i = 1; i < argc;) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 int consumed; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 consumed = CommonArg(state, i); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 if (consumed == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 consumed = -1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 if (SDL_strcasecmp(argv[i], "--blend") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 if (argv[i + 1]) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 if (SDL_strcasecmp(argv[i + 1], "none") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 blendMode = SDL_BLENDMODE_NONE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 } else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 blendMode = SDL_BLENDMODE_MASK; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 } else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 blendMode = SDL_BLENDMODE_BLEND; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 } else if (SDL_strcasecmp(argv[i + 1], "add") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 blendMode = SDL_BLENDMODE_ADD; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 blendMode = SDL_BLENDMODE_MOD; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 cycle_color = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 consumed = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 cycle_alpha = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 consumed = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 } else if (SDL_isdigit(*argv[i])) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 num_objects = SDL_atoi(argv[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 consumed = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 if (consumed < 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 fprintf(stderr, |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 "Usage: %s %s [--blend none|mask|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 argv[0], CommonUsage(state)); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 return 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 i += consumed; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 if (!CommonInit(state)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 return 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 /* Create the windows and initialize the renderers */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 for (i = 0; i < state->num_windows; ++i) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 SDL_SelectRenderer(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 SDL_RenderFill(NULL); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 srand(time(NULL)); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 /* Main render loop */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 frames = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 then = SDL_GetTicks(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 done = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 while (!done) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 /* Check for events */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 ++frames; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 while (SDL_PollEvent(&event)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 CommonEvent(state, &event, &done); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 switch (event.type) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 case SDL_MOUSEBUTTONDOWN: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 if (event.button.which == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 mouse_begin_x = event.button.x; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 mouse_begin_y = event.button.y; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 case SDL_MOUSEBUTTONUP: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 if (event.button.which == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 if (event.button.button == 3) |
2997 | 299 add_line(mouse_begin_x, mouse_begin_y, event.button.x, |
300 event.button.y); | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 if (event.button.button == 1) |
2997 | 302 add_rect(mouse_begin_x, mouse_begin_y, event.button.x, |
303 event.button.y); | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 case SDL_KEYDOWN: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 switch (event.key.keysym.sym) { |
2997 | 308 case 'l': |
309 if (event.key.keysym.mod & KMOD_SHIFT) | |
310 num_lines = 0; | |
311 else | |
312 add_line(rand() % 640, rand() % 480, rand() % 640, | |
313 rand() % 480); | |
314 break; | |
315 case 'r': | |
316 if (event.key.keysym.mod & KMOD_SHIFT) | |
317 num_rects = 0; | |
318 else | |
319 add_rect(rand() % 640, rand() % 480, rand() % 640, | |
320 rand() % 480); | |
321 break; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 case SDL_WINDOWEVENT: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 switch (event.window.event) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 case SDL_WINDOWEVENT_EXPOSED: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 SDL_SelectRenderer(event.window.windowID); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 SDL_RenderFill(NULL); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 default: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 for (i = 0; i < state->num_windows; ++i) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 SDL_SelectRenderer(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 SDL_RenderFill(NULL); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 DrawRects(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 DrawPoints(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 DrawRectRectIntersections(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 DrawLines(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 DrawRectLineIntersections(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 SDL_RenderPresent(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 /* Print out some timing information */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 now = SDL_GetTicks(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 if (now > then) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 double fps = ((double) frames * 1000) / (now - then); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 printf("%2.2f frames per second\n", fps); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 return 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 /* vi: set ts=4 sw=4 expandtab: */ |