Mercurial > sdl-ios-xcode
annotate src/video/SDL_rect.c @ 3138:7100a1a20143 gsoc2009_IME
Disable a debug message.
author | Jiang Jiang <gzjjgod@gmail.com> |
---|---|
date | Thu, 20 Aug 2009 04:54:24 +0000 |
parents | 47965eacde88 |
children | 0267b8b1595c |
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 |
2859 | 3 Copyright (C) 1997-2009 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 |
2920 | 122 SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, |
123 int *Y2) | |
2909 | 124 { |
125 int x1, y1; | |
126 int x2, y2; | |
127 int rectx1; | |
128 int recty1; | |
129 int rectx2; | |
130 int recty2; | |
131 | |
132 if (!rect || !X1 || !Y1 || !X2 || !Y2) { | |
3046
47965eacde88
Fix recommended by Eddy L O Jansson
Sam Lantinga <slouken@libsdl.org>
parents:
3004
diff
changeset
|
133 return SDL_FALSE; |
2909 | 134 } |
135 | |
136 x1 = *X1; | |
137 y1 = *Y1; | |
138 x2 = *X2; | |
139 y2 = *Y2; | |
140 rectx1 = rect->x; | |
141 recty1 = rect->y; | |
142 rectx2 = rect->x + rect->w - 1; | |
143 recty2 = rect->y + rect->h - 1; | |
144 | |
145 /* Check to see if entire line is inside rect */ | |
146 if (x1 >= rectx1 && x1 <= rectx2 && x2 >= rectx1 && x2 <= rectx2 && | |
147 y1 >= recty1 && y1 <= recty2 && y2 >= recty1 && y2 <= recty2) { | |
148 return SDL_TRUE; | |
149 } | |
150 | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
151 /* Check to see if entire line is to one side of rect */ |
2909 | 152 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
|
153 (y1 < recty1 && y2 < recty1) || (y1 > recty2 && y2 > recty2)) { |
2909 | 154 return SDL_FALSE; |
155 } | |
156 | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
157 if (y1 == y2) { |
2909 | 158 /* Horizontal line, easy to clip */ |
159 if (x1 < rectx1) { | |
160 *X1 = rectx1; | |
161 } else if (x1 > rectx2) { | |
162 *X1 = rectx2; | |
163 } | |
164 if (x2 < rectx1) { | |
165 *X2 = rectx1; | |
166 } else if (x2 > rectx2) { | |
167 *X2 = rectx2; | |
168 } | |
169 return SDL_TRUE; | |
170 } | |
171 | |
172 if (x1 == x2) { | |
173 /* Vertical line, easy to clip */ | |
174 if (y1 < recty1) { | |
175 *Y1 = recty1; | |
176 } else if (y1 > recty2) { | |
177 *Y1 = recty2; | |
178 } | |
179 if (y2 < recty1) { | |
180 *Y2 = recty1; | |
181 } else if (y2 > recty2) { | |
182 *Y2 = recty2; | |
183 } | |
184 return SDL_TRUE; | |
185 } | |
186 | |
2997 | 187 else { |
188 /* The task of clipping a line with finite slope ratios in a fixed- | |
189 * precision coordinate space is not as immediately simple as it is | |
190 * with coordinates of arbitrary precision. If the ratio of slopes | |
191 * between the input line segment and the result line segment is not | |
192 * a whole number, you have in fact *moved* the line segment a bit, | |
193 * and there can be no avoiding it without more precision | |
194 */ | |
195 int *x_result_[] = { X1, X2, NULL }, **x_result = x_result_; | |
196 int *y_result_[] = { Y1, Y2, NULL }, **y_result = y_result_; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
197 SDL_bool intersection = SDL_FALSE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
198 double b, m, left, right, bottom, top; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
199 int xl, xh, yl, yh; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
200 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
201 /* solve mx+b line formula */ |
2997 | 202 m = (double) (y1 - y2) / (double) (x1 - x2); |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
203 b = y2 - m * (double) x2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
204 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
205 /* find some linear intersections */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
206 left = (m * (double) rectx1) + b; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
207 right = (m * (double) rectx2) + b; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
208 top = (recty1 - b) / m; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
209 bottom = (recty2 - b) / m; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
210 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
211 /* sort end-points' x and y components individually */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
212 if (x1 < x2) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
213 xl = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
214 xh = x2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
215 } else { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
216 xl = x2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
217 xh = x1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
218 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
219 if (y1 < y2) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
220 yl = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
221 yh = y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
222 } else { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
223 yl = y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
224 yh = y1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
225 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
226 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
227 #define RISING(a, b, c) (((a)<=(b))&&((b)<=(c))) |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
228 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
229 /* check for a point that's entirely inside the rect */ |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
230 if (RISING(rectx1, x1, rectx2) && RISING(recty1, y1, recty2)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
231 x_result++; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
232 y_result++; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
233 intersection = SDL_TRUE; |
2997 | 234 } else |
235 /* it was determined earlier that *both* end-points are not contained */ | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
236 if (RISING(rectx1, x2, rectx2) && RISING(recty1, y2, recty2)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
237 **(x_result++) = x2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
238 **(y_result++) = y2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
239 intersection = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
240 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
241 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
242 if (RISING(recty1, left, recty2) && RISING(xl, rectx1, xh)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
243 **(x_result++) = rectx1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
244 **(y_result++) = (int) left; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
245 intersection = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
246 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
247 |
2997 | 248 if (*x_result == NULL) |
249 return intersection; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
250 if (RISING(recty1, right, recty2) && RISING(xl, rectx2, xh)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
251 **(x_result++) = rectx2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
252 **(y_result++) = (int) right; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
253 intersection = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
254 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
255 |
2997 | 256 if (*x_result == NULL) |
257 return intersection; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
258 if (RISING(rectx1, top, rectx2) && RISING(yl, recty1, yh)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
259 **(x_result++) = (int) top; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
260 **(y_result++) = recty1; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
261 intersection = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
262 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
263 |
2997 | 264 if (*x_result == NULL) |
265 return intersection; | |
2994
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
266 if (RISING(rectx1, bottom, rectx2) && RISING(yl, recty2, yh)) { |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
267 **(x_result++) = (int) bottom; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
268 **(y_result++) = recty2; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
269 intersection = SDL_TRUE; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
270 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
271 |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
272 return intersection; |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
273 } |
7563b99e9a49
Date: Sat, 3 Jan 2009 22:11:18 -0500
Sam Lantinga <slouken@libsdl.org>
parents:
2920
diff
changeset
|
274 |
2909 | 275 return SDL_FALSE; |
276 } | |
277 | |
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
|
278 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
|
279 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
|
280 { |
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
|
281 SDL_DirtyRect *dirty; |
2223
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
282 |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
283 /* FIXME: At what point is this optimization too expensive? */ |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
284 for (dirty = list->list; dirty; dirty = dirty->next) { |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
285 if (SDL_HasIntersection(&dirty->rect, rect)) { |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
286 SDL_UnionRect(&dirty->rect, rect, &dirty->rect); |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
287 return; |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
288 } |
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
289 } |
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
|
290 |
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
|
291 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
|
292 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
|
293 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
|
294 } 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
|
295 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
|
296 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
|
297 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
|
298 } |
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
|
299 } |
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
|
300 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
|
301 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
|
302 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
|
303 } |
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
|
304 |
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
|
305 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
|
306 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
|
307 { |
2224
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
308 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
|
309 |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
310 /* 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
|
311 prev = NULL; |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
312 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
|
313 prev = curr; |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
314 } |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
315 |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
316 /* 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
|
317 if (prev) { |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
318 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
|
319 } else { |
29cc9e9c76bd
Whoops, it's not quite that easy - fixed bug in SDL_ClearDirtyRects()
Sam Lantinga <slouken@libsdl.org>
parents:
2223
diff
changeset
|
320 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
|
321 } |
2223
175754591a13
Optimized dirty rect code
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
322 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
|
323 } |
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
|
324 |
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
|
325 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
|
326 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
|
327 { |
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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 } |
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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 } |
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
|
338 } |
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
|
339 |
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
|
340 /* vi: set ts=4 sw=4 expandtab: */ |