Mercurial > sdl-ios-xcode
annotate src/video/SDL_rect.c @ 5142:57851a238c8f
Removed more partially functional renderers
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 31 Jan 2011 22:53:45 -0800 |
parents | 0a5dbe96c3be |
children | fb424691cfc7 |
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 /* |
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
|
2 SDL - Simple DirectMedia Layer |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
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 |
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
|
5 This library is free software; you can redistribute it and/or |
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 modify it under the terms of the GNU Lesser General Public |
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
|
7 License as published by the Free Software Foundation; either |
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 version 2.1 of the License, or (at your option) any later version. |
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 |
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 This library is distributed in the hope that it will be useful, |
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 but WITHOUT ANY WARRANTY; without even the implied warranty of |
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 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
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
|
13 Lesser General Public License for more details. |
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 |
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 You should have received a copy of the GNU Lesser General Public |
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 License along with this library; if not, write to the Free Software |
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 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
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 |
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 Sam Lantinga |
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 slouken@libsdl.org |
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 */ |
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 #include "SDL_config.h" |
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
|
23 |
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
|
24 #include "SDL_video.h" |
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
|
25 #include "SDL_rect_c.h" |
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
|
26 |
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 SDL_bool |
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
|
28 SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B) |
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
|
29 { |
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
|
30 int Amin, Amax, Bmin, Bmax; |
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 |
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
|
32 /* Horizontal intersection */ |
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
|
33 Amin = A->x; |
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
|
34 Amax = Amin + A->w; |
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
|
35 Bmin = B->x; |
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
|
36 Bmax = Bmin + B->w; |
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
|
37 if (Bmin > Amin) |
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 Amin = Bmin; |
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 if (Bmax < Amax) |
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
|
40 Amax = Bmax; |
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
|
41 if (Amax <= Amin) |
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
|
42 return SDL_FALSE; |
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
|
43 |
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 /* Vertical intersection */ |
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 Amin = A->y; |
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
|
46 Amax = Amin + A->h; |
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 Bmin = B->y; |
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 Bmax = Bmin + B->h; |
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 if (Bmin > Amin) |
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 Amin = Bmin; |
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
|
51 if (Bmax < Amax) |
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
|
52 Amax = Bmax; |
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
|
53 if (Amax <= Amin) |
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
|
54 return SDL_FALSE; |
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
|
55 |
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
|
56 return SDL_TRUE; |
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
|
57 } |
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
|
58 |
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
|
59 SDL_bool |
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
|
60 SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) |
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
|
61 { |
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
|
62 int Amin, Amax, Bmin, Bmax; |
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
|
63 |
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
|
64 /* Horizontal intersection */ |
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 Amin = A->x; |
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 Amax = Amin + A->w; |
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 Bmin = B->x; |
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
|
68 Bmax = Bmin + B->w; |
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
|
69 if (Bmin > Amin) |
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 Amin = Bmin; |
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 result->x = Amin; |
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 if (Bmax < Amax) |
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
|
73 Amax = Bmax; |
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
|
74 result->w = Amax - Amin; |
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
|
75 |
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
|
76 /* Vertical intersection */ |
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
|
77 Amin = A->y; |
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
|
78 Amax = Amin + A->h; |
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
|
79 Bmin = B->y; |
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
|
80 Bmax = Bmin + B->h; |
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
|
81 if (Bmin > Amin) |
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
|
82 Amin = Bmin; |
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
|
83 result->y = Amin; |
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
|
84 if (Bmax < Amax) |
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
|
85 Amax = Bmax; |
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
|
86 result->h = Amax - Amin; |
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
|
87 |
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
|
88 return !SDL_RectEmpty(result); |
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
|
89 } |
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
|
90 |
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
|
91 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
|
92 SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) |
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
|
93 { |
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
|
94 int Amin, Amax, Bmin, Bmax; |
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
|
95 |
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
|
96 /* Horizontal union */ |
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
|
97 Amin = A->x; |
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
|
98 Amax = Amin + A->w; |
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
|
99 Bmin = B->x; |
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
|
100 Bmax = Bmin + B->w; |
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
|
101 if (Bmin < Amin) |
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
|
102 Amin = Bmin; |
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
|
103 result->x = Amin; |
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
|
104 if (Bmax > Amax) |
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
|
105 Amax = Bmax; |
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
|
106 result->w = Amax - Amin; |
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
|
107 |
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
|
108 /* Vertical intersection */ |
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
|
109 Amin = A->y; |
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
|
110 Amax = Amin + A->h; |
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
|
111 Bmin = B->y; |
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
|
112 Bmax = Bmin + B->h; |
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
|
113 if (Bmin < Amin) |
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
|
114 Amin = Bmin; |
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
|
115 result->y = Amin; |
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
|
116 if (Bmax > Amax) |
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
|
117 Amax = Bmax; |
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
|
118 result->h = Amax - Amin; |
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
|
119 } |
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
|
120 |
2909 | 121 SDL_bool |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
122 SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip, |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
123 SDL_Rect * result) |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
124 { |
4456
0a5dbe96c3be
Fixed variable use before initialize warnings
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
125 int minx = 0; |
0a5dbe96c3be
Fixed variable use before initialize warnings
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
126 int miny = 0; |
0a5dbe96c3be
Fixed variable use before initialize warnings
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
127 int maxx = 0; |
0a5dbe96c3be
Fixed variable use before initialize warnings
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
128 int maxy = 0; |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
129 int x, y, i; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
130 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
131 if (count < 1) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
132 return SDL_FALSE; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
133 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
134 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
135 if (clip) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
136 SDL_bool added = SDL_FALSE; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
137 int clip_minx = clip->x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
138 int clip_miny = clip->y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
139 int clip_maxx = clip->x+clip->w-1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
140 int clip_maxy = clip->y+clip->h-1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
141 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
142 for (i = 0; i < count; ++i) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
143 x = points[i].x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
144 y = points[i].y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
145 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
146 if (x < clip_minx || x > clip_maxx || |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
147 y < clip_miny || y > clip_maxy) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
148 continue; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
149 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
150 if (!added) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
151 minx = maxx = x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
152 miny = maxy = y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
153 added = SDL_TRUE; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
154 continue; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
155 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
156 if (x < minx) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
157 minx = x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
158 } else if (x > maxx) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
159 maxx = x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
160 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
161 if (y < miny) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
162 miny = y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
163 } else if (y > maxy) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
164 maxy = y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
165 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
166 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
167 if (!added) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
168 return SDL_FALSE; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
169 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
170 } else { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
171 /* No clipping, always add the first point */ |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
172 minx = maxx = points[0].x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
173 miny = maxy = points[0].y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
174 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
175 for (i = 1; i < count; ++i) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
176 x = points[i].x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
177 y = points[i].y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
178 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
179 if (x < minx) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
180 minx = x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
181 } else if (x > maxx) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
182 maxx = x; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
183 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
184 if (y < miny) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
185 miny = y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
186 } else if (y > maxy) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
187 maxy = y; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
188 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
189 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
190 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
191 |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
192 if (result) { |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
193 result->x = minx; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
194 result->y = miny; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
195 result->w = (maxx-minx)+1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
196 result->h = (maxy-miny)+1; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
197 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
198 return SDL_TRUE; |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
199 } |
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
200 |
3541
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
201 /* Use the Cohen-Sutherland algorithm for line clipping */ |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
202 #define CODE_BOTTOM 1 |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
203 #define CODE_TOP 2 |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
204 #define CODE_LEFT 4 |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
205 #define CODE_RIGHT 8 |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
206 |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
207 static int ComputeOutCode(const SDL_Rect * rect, int x, int y) |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
208 { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
209 int code = 0; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
210 if (y < 0) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
211 code |= CODE_TOP; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
212 } else if (y >= rect->y + rect->h) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
213 code |= CODE_BOTTOM; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
214 } |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
215 if (x < 0) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
216 code |= CODE_LEFT; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
217 } else if (x >= rect->x + rect->w) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
218 code |= CODE_RIGHT; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
219 } |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
220 return code; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
221 } |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
222 |
3536
0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
Sam Lantinga <slouken@libsdl.org>
parents:
3046
diff
changeset
|
223 SDL_bool |
2920 | 224 SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, |
225 int *Y2) | |
2909 | 226 { |
4456
0a5dbe96c3be
Fixed variable use before initialize warnings
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
227 int x = 0; |
0a5dbe96c3be
Fixed variable use before initialize warnings
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
228 int y = 0; |
2909 | 229 int x1, y1; |
230 int x2, y2; | |
231 int rectx1; | |
232 int recty1; | |
233 int rectx2; | |
234 int recty2; | |
3541
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
235 int outcode1, outcode2; |
2909 | 236 |
237 if (!rect || !X1 || !Y1 || !X2 || !Y2) { | |
3046
47965eacde88
Fix recommended by Eddy L O Jansson
Sam Lantinga <slouken@libsdl.org>
parents:
3004
diff
changeset
|
238 return SDL_FALSE; |
2909 | 239 } |
240 | |
241 x1 = *X1; | |
242 y1 = *Y1; | |
243 x2 = *X2; | |
244 y2 = *Y2; | |
245 rectx1 = rect->x; | |
246 recty1 = rect->y; | |
247 rectx2 = rect->x + rect->w - 1; | |
248 recty2 = rect->y + rect->h - 1; | |
249 | |
250 /* Check to see if entire line is inside rect */ | |
251 if (x1 >= rectx1 && x1 <= rectx2 && x2 >= rectx1 && x2 <= rectx2 && | |
252 y1 >= recty1 && y1 <= recty2 && y2 >= recty1 && y2 <= recty2) { | |
253 return SDL_TRUE; | |
254 } | |
255 | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
256 /* Check to see if entire line is to one side of rect */ |
2909 | 257 if ((x1 < rectx1 && x2 < rectx1) || (x1 > rectx2 && x2 > rectx2) || |
3004
f3d7226a8dfd
Fixed lines intersecting the top corners of a rectangle
Sam Lantinga <slouken@libsdl.org>
parents:
2997
diff
changeset
|
258 (y1 < recty1 && y2 < recty1) || (y1 > recty2 && y2 > recty2)) { |
2909 | 259 return SDL_FALSE; |
260 } | |
261 | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
262 if (y1 == y2) { |
2909 | 263 /* Horizontal line, easy to clip */ |
264 if (x1 < rectx1) { | |
265 *X1 = rectx1; | |
266 } else if (x1 > rectx2) { | |
267 *X1 = rectx2; | |
268 } | |
269 if (x2 < rectx1) { | |
270 *X2 = rectx1; | |
271 } else if (x2 > rectx2) { | |
272 *X2 = rectx2; | |
273 } | |
274 return SDL_TRUE; | |
275 } | |
276 | |
277 if (x1 == x2) { | |
278 /* Vertical line, easy to clip */ | |
279 if (y1 < recty1) { | |
280 *Y1 = recty1; | |
281 } else if (y1 > recty2) { | |
282 *Y1 = recty2; | |
283 } | |
284 if (y2 < recty1) { | |
285 *Y2 = recty1; | |
286 } else if (y2 > recty2) { | |
287 *Y2 = recty2; | |
288 } | |
289 return SDL_TRUE; | |
290 } | |
291 | |
3541
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
292 /* More complicated Cohen-Sutherland algorithm */ |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
293 outcode1 = ComputeOutCode(rect, x1, y1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
294 outcode2 = ComputeOutCode(rect, x2, y2); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
295 while (outcode1 || outcode2) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
296 if (outcode1 & outcode2) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
297 return SDL_FALSE; |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
298 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
299 |
3541
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
300 if (outcode1) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
301 if (outcode1 & CODE_TOP) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
302 y = recty1; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
303 x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
304 } else if (outcode1 & CODE_BOTTOM) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
305 y = recty2; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
306 x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
307 } else if (outcode1 & CODE_LEFT) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
308 x = rectx1; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
309 y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
310 } else if (outcode1 & CODE_RIGHT) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
311 x = rectx2; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
312 y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
313 } |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
314 x1 = x; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
315 y1 = y; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
316 outcode1 = ComputeOutCode(rect, x, y); |
3542
97eae5a705f9
Make sure we fully clip the first point before starting to adjust the second point.
Sam Lantinga <slouken@libsdl.org>
parents:
3541
diff
changeset
|
317 } else { |
3541
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
318 if (outcode2 & CODE_TOP) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
319 y = recty1; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
320 x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
321 } else if (outcode2 & CODE_BOTTOM) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
322 y = recty2; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
323 x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
324 } else if (outcode2 & CODE_LEFT) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
325 x = rectx1; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
326 y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
327 } else if (outcode2 & CODE_RIGHT) { |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
328 x = rectx2; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
329 y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
330 } |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
331 x2 = x; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
332 y2 = y; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
333 outcode2 = ComputeOutCode(rect, x, y); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
334 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
335 } |
3541
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
336 *X1 = x1; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
337 *Y1 = y1; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
338 *X2 = x2; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
339 *Y2 = y2; |
0c429a5fda8a
Added an automated test for rectangle routines, currently only testing line clipping.
Sam Lantinga <slouken@libsdl.org>
parents:
3536
diff
changeset
|
340 return SDL_TRUE; |
2909 | 341 } |
342 | |
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
|
343 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
|
344 SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect) |
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
|
345 { |
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
|
346 SDL_DirtyRect *dirty; |
2223
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
347 |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
348 /* FIXME: At what point is this optimization too expensive? */ |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
349 for (dirty = list->list; dirty; dirty = dirty->next) { |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
350 if (SDL_HasIntersection(&dirty->rect, rect)) { |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
351 SDL_UnionRect(&dirty->rect, rect, &dirty->rect); |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
352 return; |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
353 } |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
354 } |
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
|
355 |
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
|
356 if (list->free) { |
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
|
357 dirty = list->free; |
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
|
358 list->free = dirty->next; |
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
|
359 } else { |
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
|
360 dirty = (SDL_DirtyRect *) SDL_malloc(sizeof(*dirty)); |
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
|
361 if (!dirty) { |
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
|
362 return; |
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
|
363 } |
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
|
364 } |
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
|
365 dirty->rect = *rect; |
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
|
366 dirty->next = list->list; |
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
|
367 list->list = dirty; |
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
|
368 } |
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
|
369 |
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
|
370 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
|
371 SDL_ClearDirtyRects(SDL_DirtyRectList * list) |
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
|
372 { |
2224
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
373 SDL_DirtyRect *prev, *curr; |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
374 |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
375 /* Skip to the end of the free list */ |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
376 prev = NULL; |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
377 for (curr = list->free; curr; curr = curr->next) { |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
378 prev = curr; |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
379 } |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
380 |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
381 /* Add the list entries to the end */ |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
382 if (prev) { |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
383 prev->next = list->list; |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
384 } else { |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
385 list->free = list->list; |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
386 } |
2223
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
387 list->list = NULL; |
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
|
388 } |
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
|
389 |
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
|
390 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
|
391 SDL_FreeDirtyRects(SDL_DirtyRectList * list) |
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
|
392 { |
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
|
393 while (list->list) { |
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
|
394 SDL_DirtyRect *elem = list->list; |
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
|
395 list->list = elem->next; |
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
|
396 SDL_free(elem); |
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
|
397 } |
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
|
398 while (list->free) { |
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
|
399 SDL_DirtyRect *elem = list->free; |
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
|
400 list->free = elem->next; |
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
|
401 SDL_free(elem); |
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
|
402 } |
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
|
403 } |
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
|
404 |
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
|
405 /* vi: set ts=4 sw=4 expandtab: */ |