Mercurial > sdl-ios-xcode
annotate test/testintersections.c @ 2994:7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
From: "Donny Viszneki"
Subject: Re: [SDL] Want to help with SDL 1.3?
>> > For example, here's a good quick project for someone from the TODO list:
>> > * Add diagonal line clipping to SDL_IntersectRectAndLine()
Just wanted to point out that the patch is available at
http://codebad.com/rect-line-ix.patch
I hereby grant Sam Lantinga an irrevocable non-exclusive distribution
license to this patch to do with as he wishes.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 04 Jan 2009 19:33:21 +0000 |
parents | |
children | e4f025078c1c |
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]; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 static int add_line(int x1, int y1, int x2, int y2) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 if (num_lines >= MAX_LINES) return 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 if ((x1 == x2) && (y1 == y2)) return 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 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
|
75 lines[num_lines].x = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 lines[num_lines].y = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 lines[num_lines].w = x2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 lines[num_lines].h = y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 return ++num_lines; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 |
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 void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 DrawLines(SDL_WindowID window) |
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 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 int x1, y1, x2, y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 int window_w, window_h; |
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 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 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
|
93 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 SDL_SetRenderDrawBlendMode(blendMode); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 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
|
96 SDL_SetRenderDrawColor(255, 255, 255, 255); |
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 if (i == -1) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 } else { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 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
|
105 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 } |
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 #define MAX_RECTS 16 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 int num_rects = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 SDL_Rect rects[MAX_RECTS]; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 static int add_rect(int x1, int y1, int x2, int y2) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 if (num_rects >= MAX_RECTS) return 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 if ((x1 == x2) || (y1 == y2)) return 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 if (x1 > x2) SWAP(int, x1, x2); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 if (y1 > y2) SWAP(int, y1, y2); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, x2-x1, y2-y1); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 rects[num_rects].x = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 rects[num_rects].y = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 rects[num_rects].w = x2 - x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 rects[num_rects].h = y2 - y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 return ++num_rects; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 static void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 DrawRects(SDL_WindowID window) |
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 int i; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 int window_w, window_h; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 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
|
138 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 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
|
141 SDL_SetRenderDrawColor(255, 127, 0, 255); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 SDL_RenderFill(&rects[i]); |
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 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 } |
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 static void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 DrawRectLineIntersections(SDL_WindowID window) |
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 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
|
151 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 /* Query the sizes */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 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
|
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 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
|
158 for (j = 0; j < num_lines; j++) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 int x1, y1, x2, y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 SDL_Rect r; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 r = rects[i]; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 x1 = lines[j].x; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 y1 = lines[j].y; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 x2 = lines[j].w; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 y2 = lines[j].h; |
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 if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 SDL_SetRenderDrawColor(0, 255, 55, 255); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 SDL_RenderLine(x1, y1, x2, y2); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 static void |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 DrawRectRectIntersections(SDL_WindowID window) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 int i, j; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); |
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 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
|
185 for (j = i+1; j < num_rects; j++) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 SDL_Rect r; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 if (SDL_IntersectRect(&rects[i], &rects[j], &r)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 SDL_SetRenderDrawColor(255, 200, 0, 255); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 SDL_RenderFill(&r); |
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 } |
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 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 int |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 main(int argc, char *argv[]) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 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
|
200 int i, done; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 SDL_Event event; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 Uint32 then, now, frames; |
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 /* Initialize parameters */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 num_objects = NUM_OBJECTS; |
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 /* Initialize test framework */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 state = CommonCreateState(argv, SDL_INIT_VIDEO); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 if (!state) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 return 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 for (i = 1; i < argc;) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 int consumed; |
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 consumed = CommonArg(state, i); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 if (consumed == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 consumed = -1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 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
|
219 if (argv[i + 1]) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 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
|
221 blendMode = SDL_BLENDMODE_NONE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 } 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
|
224 blendMode = SDL_BLENDMODE_MASK; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 } 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
|
227 blendMode = SDL_BLENDMODE_BLEND; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 } 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
|
230 blendMode = SDL_BLENDMODE_ADD; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 } 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
|
233 blendMode = SDL_BLENDMODE_MOD; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 consumed = 2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 } |
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], "--cyclecolor") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 cycle_color = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 consumed = 1; |
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], "--cyclealpha") == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 cycle_alpha = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 consumed = 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 } else if (SDL_isdigit(*argv[i])) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 num_objects = SDL_atoi(argv[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 consumed = 1; |
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 if (consumed < 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 fprintf(stderr, |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 "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
|
251 argv[0], CommonUsage(state)); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 return 1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 i += consumed; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 if (!CommonInit(state)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 return 2; |
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 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 /* 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
|
261 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
|
262 SDL_SelectRenderer(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 SDL_RenderFill(NULL); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 } |
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 srand(time(NULL)); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 /* Main render loop */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 frames = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 then = SDL_GetTicks(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 done = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 while (!done) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 /* Check for events */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 ++frames; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 while (SDL_PollEvent(&event)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 CommonEvent(state, &event, &done); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 switch (event.type) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 case SDL_MOUSEBUTTONDOWN: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 if (event.button.which == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 mouse_begin_x = event.button.x; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 mouse_begin_y = event.button.y; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 case SDL_MOUSEBUTTONUP: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 if (event.button.which == 0) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 if (event.button.button == 3) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 add_line(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 if (event.button.button == 1) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 add_rect(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 case SDL_KEYDOWN: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 switch (event.key.keysym.sym) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 case 'l': |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 if (event.key.keysym.mod & KMOD_SHIFT) num_lines = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 else add_line(rand()%640, rand()%480, rand()%640, rand()%480); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 case 'r': |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 if (event.key.keysym.mod & KMOD_SHIFT) num_rects = 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 else add_rect(rand()%640, rand()%480, rand()%640, rand()%480); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 case SDL_WINDOWEVENT: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 switch (event.window.event) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 case SDL_WINDOWEVENT_EXPOSED: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 SDL_SelectRenderer(event.window.windowID); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 SDL_RenderFill(NULL); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 default: |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 break; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 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
|
319 SDL_SelectRenderer(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 SDL_RenderFill(NULL); |
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 DrawRects(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 DrawPoints(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 DrawRectRectIntersections(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 DrawLines(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 DrawRectLineIntersections(state->windows[i]); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 SDL_RenderPresent(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 } |
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 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 /* Print out some timing information */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 now = SDL_GetTicks(); |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 if (now > then) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 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
|
337 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
|
338 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 return 0; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 } |
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 /* vi: set ts=4 sw=4 expandtab: */ |