comparison src/video/SDL_rect.c @ 3536:0267b8b1595c

Added interfaces for batch drawing of points, lines and rects: SDL_DrawPoints() SDL_BlendPoints() SDL_BlendLines() SDL_DrawLines() SDL_FillRects() SDL_BlendRects() SDL_RenderPoints() SDL_RenderLines() SDL_RenderRects() Renamed SDL_RenderFill() to SDL_RenderRect()
author Sam Lantinga <slouken@libsdl.org>
date Wed, 09 Dec 2009 15:56:56 +0000
parents 47965eacde88
children 0c429a5fda8a
comparison
equal deleted inserted replaced
3535:b403f790df65 3536:0267b8b1595c
114 Amin = Bmin; 114 Amin = Bmin;
115 result->y = Amin; 115 result->y = Amin;
116 if (Bmax > Amax) 116 if (Bmax > Amax)
117 Amax = Bmax; 117 Amax = Bmax;
118 result->h = Amax - Amin; 118 result->h = Amax - Amin;
119 }
120
121 SDL_bool
122 SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip,
123 SDL_Rect * result)
124 {
125 int minx, miny;
126 int maxx, maxy;
127 int x, y, i;
128
129 if (count < 1) {
130 return SDL_FALSE;
131 }
132
133 if (clip) {
134 SDL_bool added = SDL_FALSE;
135 int clip_minx = clip->x;
136 int clip_miny = clip->y;
137 int clip_maxx = clip->x+clip->w-1;
138 int clip_maxy = clip->y+clip->h-1;
139
140 for (i = 0; i < count; ++i) {
141 x = points[i].x;
142 y = points[i].y;
143
144 if (x < clip_minx || x > clip_maxx ||
145 y < clip_miny || y > clip_maxy) {
146 continue;
147 }
148 if (!added) {
149 minx = maxx = x;
150 miny = maxy = y;
151 added = SDL_TRUE;
152 continue;
153 }
154 if (x < minx) {
155 minx = x;
156 } else if (x > maxx) {
157 maxx = x;
158 }
159 if (y < miny) {
160 miny = y;
161 } else if (y > maxy) {
162 maxy = y;
163 }
164 }
165 if (!added) {
166 return SDL_FALSE;
167 }
168 } else {
169 /* No clipping, always add the first point */
170 minx = maxx = points[0].x;
171 miny = maxy = points[0].y;
172
173 for (i = 1; i < count; ++i) {
174 x = points[i].x;
175 y = points[i].y;
176
177 if (x < minx) {
178 minx = x;
179 } else if (x > maxx) {
180 maxx = x;
181 }
182 if (y < miny) {
183 miny = y;
184 } else if (y > maxy) {
185 maxy = y;
186 }
187 }
188 }
189
190 if (result) {
191 result->x = minx;
192 result->y = miny;
193 result->w = (maxx-minx)+1;
194 result->h = (maxy-miny)+1;
195 }
196 return SDL_TRUE;
119 } 197 }
120 198
121 SDL_bool 199 SDL_bool
122 SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, 200 SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
123 int *Y2) 201 int *Y2)