Mercurial > pygame
annotate src/draw.c @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 8b94c72abda8 |
| children | 9fcb7abf3185 |
| rev | line source |
|---|---|
| 85 | 1 /* |
| 2 pygame - Python Game Library | |
| 107 | 3 Copyright (C) 2000-2001 Pete Shinners |
| 85 | 4 |
| 5 This library is free software; you can redistribute it and/or | |
| 6 modify it under the terms of the GNU Library General Public | |
| 7 License as published by the Free Software Foundation; either | |
| 8 version 2 of the License, or (at your option) any later version. | |
| 9 | |
| 10 This library is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 Library General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU Library General Public | |
| 16 License along with this library; if not, write to the Free | |
| 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 | |
| 19 Pete Shinners | |
| 20 pete@shinners.org | |
| 21 */ | |
| 22 | |
| 23 /* | |
| 24 * drawing module for pygame | |
| 25 */ | |
| 26 #include "pygame.h" | |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
27 #include "pgcompat.h" |
| 1937 | 28 #include "doc/draw_doc.h" |
| 442 | 29 #include <math.h> |
| 30 | |
| 570 | 31 /* Many C libraries seem to lack the trunc call (added in C99) */ |
| 32 #define trunc(d) (((d) >= 0.0) ? (floor(d)) : (ceil(d))) | |
| 33 #define FRAC(z) ((z) - trunc(z)) | |
| 34 #define INVFRAC(z) (1 - FRAC(z)) | |
| 85 | 35 |
| 93 | 36 static int clip_and_draw_line(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, int* pts); |
| 442 | 37 static int clip_and_draw_aaline(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, float* pts, int blend); |
| 176 | 38 static int clip_and_draw_line_width(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, int width, int* pts); |
| 85 | 39 static int clipline(int* pts, int left, int top, int right, int bottom); |
| 442 | 40 static int clipaaline(float* pts, int left, int top, int right, int bottom); |
| 85 | 41 static void drawline(SDL_Surface* surf, Uint32 color, int startx, int starty, int endx, int endy); |
| 442 | 42 static void drawaaline(SDL_Surface* surf, Uint32 color, float startx, float starty, float endx, float endy, |
| 43 int blend); | |
| 93 | 44 static void drawhorzline(SDL_Surface* surf, Uint32 color, int startx, int starty, int endx); |
| 257 | 45 static void drawvertline(SDL_Surface* surf, Uint32 color, int x1, int y1, int y2); |
| 461 | 46 static void draw_arc(SDL_Surface *dst, int x, int y, int radius1, int radius2, double angle_start, double angle_stop, Uint32 color); |
| 256 | 47 static void draw_ellipse(SDL_Surface *dst, int x, int y, int rx, int ry, Uint32 color); |
| 48 static void draw_fillellipse(SDL_Surface *dst, int x, int y, int rx, int ry, Uint32 color); | |
| 49 static void draw_fillpoly(SDL_Surface *dst, int *vx, int *vy, int n, Uint32 color); | |
| 85 | 50 |
| 51 | |
| 442 | 52 |
| 53 static PyObject* aaline(PyObject* self, PyObject* arg) | |
| 54 { | |
| 55 PyObject *surfobj, *colorobj, *start, *end; | |
| 56 SDL_Surface* surf; | |
| 57 float startx, starty, endx, endy; | |
| 58 int top, left, bottom, right; | |
| 59 int blend=1; | |
| 60 float pts[4]; | |
| 61 Uint8 rgba[4]; | |
| 62 Uint32 color; | |
| 63 int anydraw; | |
| 64 | |
| 65 /*get all the arguments*/ | |
| 66 if(!PyArg_ParseTuple(arg, "O!OOO|i", &PySurface_Type, &surfobj, &colorobj, &start, &end, &blend)) | |
| 67 return NULL; | |
| 68 surf = PySurface_AsSurface(surfobj); | |
| 69 | |
| 70 if(surf->format->BytesPerPixel !=3 && surf->format->BytesPerPixel != 4) | |
| 71 return RAISE(PyExc_ValueError, "unsupported bit depth for aaline draw (supports 32 & 24 bit)"); | |
| 72 | |
| 1037 | 73 if(RGBAFromColorObj(colorobj, rgba)) |
| 442 | 74 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 75 else | |
| 76 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 77 | |
| 78 if(!TwoFloatsFromObj(start, &startx, &starty)) | |
| 79 return RAISE(PyExc_TypeError, "Invalid start position argument"); | |
| 80 if(!TwoFloatsFromObj(end, &endx, &endy)) | |
| 81 return RAISE(PyExc_TypeError, "Invalid end position argument"); | |
| 82 | |
| 83 if(!PySurface_Lock(surfobj)) return NULL; | |
| 84 | |
| 85 pts[0] = startx; pts[1] = starty; | |
| 86 pts[2] = endx; pts[3] = endy; | |
| 87 anydraw = clip_and_draw_aaline(surf, &surf->clip_rect, color, pts, blend); | |
| 88 | |
| 89 if(!PySurface_Unlock(surfobj)) return NULL; | |
| 90 | |
| 91 /*compute return rect*/ | |
| 92 if(!anydraw) | |
| 491 | 93 return PyRect_New4(startx, starty, 0, 0); |
| 442 | 94 if(pts[0] < pts[2]) |
| 95 { | |
| 96 left = (int)(pts[0]); | |
| 97 right = (int)(pts[2]); | |
| 98 } | |
| 99 else | |
| 100 { | |
| 101 left = (int)(pts[2]); | |
| 102 right = (int)(pts[0]); | |
| 103 } | |
| 104 if(pts[1] < pts[3]) | |
| 105 { | |
| 106 top = (int)(pts[1]); | |
| 107 bottom = (int)(pts[3]); | |
| 108 } | |
| 109 else | |
| 110 { | |
| 111 top = (int)(pts[3]); | |
| 112 bottom = (int)(pts[1]); | |
| 113 } | |
| 491 | 114 return PyRect_New4(left, top, right-left+2, bottom-top+2); |
| 442 | 115 } |
| 116 | |
| 85 | 117 |
| 118 static PyObject* line(PyObject* self, PyObject* arg) | |
| 119 { | |
| 120 PyObject *surfobj, *colorobj, *start, *end; | |
| 121 SDL_Surface* surf; | |
| 491 | 122 int startx, starty, endx, endy; |
|
2038
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
123 int dx, dy; |
|
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
124 int rtop, rleft, rwidth, rheight; |
| 176 | 125 int width = 1; |
| 85 | 126 int pts[4]; |
| 127 Uint8 rgba[4]; | |
| 128 Uint32 color; | |
| 93 | 129 int anydraw; |
| 85 | 130 |
| 131 /*get all the arguments*/ | |
| 176 | 132 if(!PyArg_ParseTuple(arg, "O!OOO|i", &PySurface_Type, &surfobj, &colorobj, &start, &end, &width)) |
| 85 | 133 return NULL; |
| 134 surf = PySurface_AsSurface(surfobj); | |
| 135 | |
| 136 if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) | |
| 137 return RAISE(PyExc_ValueError, "unsupport bit depth for line draw"); | |
| 138 | |
| 96 | 139 if(PyInt_Check(colorobj)) |
| 140 color = (Uint32)PyInt_AsLong(colorobj); | |
| 1037 | 141 else if(RGBAFromColorObj(colorobj, rgba)) |
| 96 | 142 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 143 else | |
| 144 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 85 | 145 |
| 491 | 146 if(!TwoIntsFromObj(start, &startx, &starty)) |
| 85 | 147 return RAISE(PyExc_TypeError, "Invalid start position argument"); |
| 491 | 148 if(!TwoIntsFromObj(end, &endx, &endy)) |
| 85 | 149 return RAISE(PyExc_TypeError, "Invalid end position argument"); |
| 176 | 150 |
| 151 if(width < 1) | |
| 152 return PyRect_New4(startx, starty, 0, 0); | |
| 153 | |
| 85 | 154 |
| 90 | 155 if(!PySurface_Lock(surfobj)) return NULL; |
| 85 | 156 |
| 93 | 157 pts[0] = startx; pts[1] = starty; |
| 158 pts[2] = endx; pts[3] = endy; | |
| 176 | 159 anydraw = clip_and_draw_line_width(surf, &surf->clip_rect, color, width, pts); |
| 85 | 160 |
| 90 | 161 if(!PySurface_Unlock(surfobj)) return NULL; |
| 85 | 162 |
| 93 | 163 |
| 85 | 164 /*compute return rect*/ |
| 93 | 165 if(!anydraw) |
| 166 return PyRect_New4(startx, starty, 0, 0); | |
|
2038
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
167 rleft = (startx < endx) ? startx : endx; |
|
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
168 rtop = (starty < endy) ? starty : endy; |
|
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
169 dx = abs(startx - endx); |
|
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
170 dy = abs(starty - endy); |
|
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
171 if (dx > dy) |
| 85 | 172 { |
|
2038
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
173 rwidth = dx + 1; |
|
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
174 rheight = dy + width; |
| 85 | 175 } |
| 176 else | |
| 177 { | |
|
2038
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
178 rwidth = dx + width; |
|
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
179 rheight = dy + 1; |
| 85 | 180 } |
|
2038
8b94c72abda8
Fixes bug in pygame.draw.line where the wrong rectangle was returned
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
181 return PyRect_New4(rleft, rtop, rwidth, rheight); |
| 85 | 182 } |
| 183 | |
| 184 | |
| 442 | 185 static PyObject* aalines(PyObject* self, PyObject* arg) |
| 186 { | |
| 187 PyObject *surfobj, *colorobj, *closedobj, *points, *item; | |
| 188 SDL_Surface* surf; | |
| 189 float x, y; | |
| 190 int top, left, bottom, right; | |
| 191 float pts[4]; | |
| 192 Uint8 rgba[4]; | |
| 193 Uint32 color; | |
| 194 int closed, blend; | |
| 195 int result, loop, length, drawn; | |
| 196 float startx, starty; | |
| 197 | |
| 198 /*get all the arguments*/ | |
| 199 if(!PyArg_ParseTuple(arg, "O!OOO|i", &PySurface_Type, &surfobj, &colorobj, &closedobj, | |
| 200 &points, &blend)) | |
| 201 return NULL; | |
| 202 surf = PySurface_AsSurface(surfobj); | |
| 471 | 203 |
| 442 | 204 if(surf->format->BytesPerPixel !=3 && surf->format->BytesPerPixel != 4) |
| 205 return RAISE(PyExc_ValueError, "unsupported bit depth for aaline draw (supports 32 & 24 bit)"); | |
| 206 | |
| 1037 | 207 if(RGBAFromColorObj(colorobj, rgba)) |
| 442 | 208 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 209 else | |
| 210 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 211 | |
| 212 closed = PyObject_IsTrue(closedobj); | |
| 213 | |
| 214 if(!PySequence_Check(points)) | |
| 215 return RAISE(PyExc_TypeError, "points argument must be a sequence of number pairs"); | |
| 216 length = PySequence_Length(points); | |
| 217 if(length < 2) | |
| 218 return RAISE(PyExc_ValueError, "points argument must contain more than 1 points"); | |
| 219 | |
| 220 item = PySequence_GetItem(points, 0); | |
| 221 result = TwoFloatsFromObj(item, &x, &y); | |
| 222 Py_DECREF(item); | |
| 223 if(!result) return RAISE(PyExc_TypeError, "points must be number pairs"); | |
| 224 | |
| 225 startx = pts[0] = x; | |
| 226 starty = pts[1] = y; | |
| 227 left = right = (int)x; | |
| 228 top = bottom = (int)y; | |
| 229 | |
| 230 if(!PySurface_Lock(surfobj)) return NULL; | |
| 231 | |
| 232 drawn = 1; | |
| 233 for(loop = 1; loop < length; ++loop) | |
| 234 { | |
| 235 item = PySequence_GetItem(points, loop); | |
| 236 result = TwoFloatsFromObj(item, &x, &y); | |
| 237 Py_DECREF(item); | |
| 238 if(!result) continue; /*note, we silently skip over bad points :[ */ | |
| 239 ++drawn; | |
| 240 pts[0] = startx; | |
| 241 pts[1] = starty; | |
| 242 startx = pts[2] = x; | |
| 243 starty = pts[3] = y; | |
| 244 if(clip_and_draw_aaline(surf, &surf->clip_rect, color, pts, blend)) | |
| 245 { | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
246 left = MIN((int)MIN(pts[0], pts[2]), left); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
247 top = MIN((int)MIN(pts[1], pts[3]), top); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
248 right = MAX((int)MAX(pts[0], pts[2]), right); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
249 bottom = MAX((int)MAX(pts[1], pts[3]), bottom); |
| 442 | 250 } |
| 251 } | |
| 252 if(closed && drawn > 2) | |
| 253 { | |
| 254 item = PySequence_GetItem(points, 0); | |
| 255 result = TwoFloatsFromObj(item, &x, &y); | |
| 256 Py_DECREF(item); | |
| 257 if(result) | |
| 258 { | |
| 259 pts[0] = startx; | |
| 260 pts[1] = starty; | |
| 261 pts[2] = x; | |
| 262 pts[3] = y; | |
| 263 clip_and_draw_aaline(surf, &surf->clip_rect, color, pts, blend); | |
| 264 } | |
| 265 } | |
| 266 | |
| 267 if(!PySurface_Unlock(surfobj)) return NULL; | |
| 268 | |
| 269 /*compute return rect*/ | |
| 491 | 270 return PyRect_New4(left, top, right-left+2, bottom-top+2); |
| 442 | 271 } |
| 272 | |
| 93 | 273 |
| 274 static PyObject* lines(PyObject* self, PyObject* arg) | |
| 275 { | |
| 276 PyObject *surfobj, *colorobj, *closedobj, *points, *item; | |
| 277 SDL_Surface* surf; | |
| 491 | 278 int x, y; |
| 93 | 279 int top, left, bottom, right; |
| 176 | 280 int pts[4], width=1; |
| 93 | 281 Uint8 rgba[4]; |
| 282 Uint32 color; | |
| 283 int closed; | |
| 284 int result, loop, length, drawn; | |
| 186 | 285 int startx, starty; |
| 93 | 286 |
| 287 /*get all the arguments*/ | |
| 176 | 288 if(!PyArg_ParseTuple(arg, "O!OOO|i", &PySurface_Type, &surfobj, &colorobj, &closedobj, &points, &width)) |
| 93 | 289 return NULL; |
| 290 surf = PySurface_AsSurface(surfobj); | |
| 291 | |
| 292 if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) | |
| 293 return RAISE(PyExc_ValueError, "unsupport bit depth for line draw"); | |
| 294 | |
| 96 | 295 if(PyInt_Check(colorobj)) |
| 296 color = (Uint32)PyInt_AsLong(colorobj); | |
| 1037 | 297 else if(RGBAFromColorObj(colorobj, rgba)) |
| 96 | 298 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 299 else | |
| 300 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 93 | 301 |
| 302 closed = PyObject_IsTrue(closedobj); | |
| 303 | |
| 304 if(!PySequence_Check(points)) | |
| 305 return RAISE(PyExc_TypeError, "points argument must be a sequence of number pairs"); | |
| 306 length = PySequence_Length(points); | |
| 307 if(length < 2) | |
| 308 return RAISE(PyExc_ValueError, "points argument must contain more than 1 points"); | |
| 244 | 309 |
| 93 | 310 item = PySequence_GetItem(points, 0); |
| 491 | 311 result = TwoIntsFromObj(item, &x, &y); |
| 93 | 312 Py_DECREF(item); |
| 313 if(!result) return RAISE(PyExc_TypeError, "points must be number pairs"); | |
| 314 | |
| 186 | 315 startx = pts[0] = left = right = x; |
| 316 starty = pts[1] = top = bottom = y; | |
| 93 | 317 |
| 176 | 318 if(width < 1) |
| 491 | 319 return PyRect_New4(left, top, 0, 0); |
| 176 | 320 |
| 93 | 321 if(!PySurface_Lock(surfobj)) return NULL; |
| 322 | |
| 323 drawn = 1; | |
| 324 for(loop = 1; loop < length; ++loop) | |
| 325 { | |
| 326 item = PySequence_GetItem(points, loop); | |
| 491 | 327 result = TwoIntsFromObj(item, &x, &y); |
| 93 | 328 Py_DECREF(item); |
| 329 if(!result) continue; /*note, we silently skip over bad points :[ */ | |
| 330 ++drawn; | |
| 186 | 331 pts[0] = startx; |
| 332 pts[1] = starty; | |
| 333 startx = pts[2] = x; | |
| 334 starty = pts[3] = y; | |
| 176 | 335 if(clip_and_draw_line_width(surf, &surf->clip_rect, color, width, pts)) |
| 93 | 336 { |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
337 left = MIN(MIN(pts[0], pts[2]), left); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
338 top = MIN(MIN(pts[1], pts[3]), top); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
339 right = MAX(MAX(pts[0], pts[2]), right); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
340 bottom = MAX(MAX(pts[1], pts[3]), bottom); |
| 93 | 341 } |
| 342 } | |
| 343 if(closed && drawn > 2) | |
| 344 { | |
| 345 item = PySequence_GetItem(points, 0); | |
| 491 | 346 result = TwoIntsFromObj(item, &x, &y); |
| 93 | 347 Py_DECREF(item); |
| 348 if(result) | |
| 349 { | |
| 186 | 350 pts[0] = startx; |
| 351 pts[1] = starty; | |
| 93 | 352 pts[2] = x; |
| 353 pts[3] = y; | |
| 176 | 354 clip_and_draw_line_width(surf, &surf->clip_rect, color, width, pts); |
| 93 | 355 } |
| 356 } | |
| 357 | |
| 358 | |
| 359 if(!PySurface_Unlock(surfobj)) return NULL; | |
| 360 | |
| 361 /*compute return rect*/ | |
| 491 | 362 return PyRect_New4(left, top, right-left+1, bottom-top+1); |
| 93 | 363 } |
| 364 | |
| 365 | |
| 461 | 366 static PyObject* arc(PyObject* self, PyObject* arg) |
| 367 { | |
| 368 PyObject *surfobj, *colorobj, *rectobj; | |
| 369 GAME_Rect *rect, temp; | |
| 370 SDL_Surface* surf; | |
| 371 Uint8 rgba[4]; | |
| 372 Uint32 color; | |
| 373 int width=1, loop, t, l, b, r; | |
| 374 double angle_start, angle_stop; | |
| 375 | |
| 376 /*get all the arguments*/ | |
| 471 | 377 if(!PyArg_ParseTuple(arg, "O!OOdd|i", &PySurface_Type, &surfobj, &colorobj, &rectobj, |
| 461 | 378 &angle_start, &angle_stop, &width)) |
| 379 return NULL; | |
| 380 rect = GameRect_FromObject(rectobj, &temp); | |
| 381 if(!rect) | |
| 382 return RAISE(PyExc_TypeError, "Invalid recstyle argument"); | |
| 383 | |
| 384 surf = PySurface_AsSurface(surfobj); | |
| 385 if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) | |
| 386 return RAISE(PyExc_ValueError, "unsupport bit depth for drawing"); | |
| 387 | |
| 388 if(PyInt_Check(colorobj)) | |
| 389 color = (Uint32)PyInt_AsLong(colorobj); | |
| 1037 | 390 else if(RGBAFromColorObj(colorobj, rgba)) |
| 461 | 391 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 392 else | |
| 393 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 394 | |
| 395 if ( width < 0 ) | |
| 396 return RAISE(PyExc_ValueError, "negative width"); | |
| 397 if ( width > rect->w / 2 || width > rect->h / 2 ) | |
| 398 return RAISE(PyExc_ValueError, "width greater than ellipse radius"); | |
| 399 if ( angle_stop < angle_start ) | |
| 400 angle_stop += 360; | |
| 401 | |
| 402 if(!PySurface_Lock(surfobj)) return NULL; | |
| 403 | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
404 width = MIN(width, MIN(rect->w, rect->h) / 2); |
| 461 | 405 for(loop=0; loop<width; ++loop) |
| 406 { | |
| 407 draw_arc(surf, rect->x+rect->w/2, rect->y+rect->h/2, | |
| 408 rect->w/2-loop, rect->h/2-loop, | |
| 409 angle_start, angle_stop, color); | |
| 410 } | |
| 411 | |
| 412 if(!PySurface_Unlock(surfobj)) return NULL; | |
| 413 | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
414 l = MAX(rect->x, surf->clip_rect.x); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
415 t = MAX(rect->y, surf->clip_rect.y); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
416 r = MIN(rect->x + rect->w, surf->clip_rect.x + surf->clip_rect.w); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
417 b = MIN(rect->y + rect->h, surf->clip_rect.y + surf->clip_rect.h); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
418 return PyRect_New4(l, t, MAX(r-l, 0), MAX(b-t, 0)); |
| 461 | 419 } |
| 420 | |
| 421 | |
| 225 | 422 static PyObject* ellipse(PyObject* self, PyObject* arg) |
| 423 { | |
| 424 PyObject *surfobj, *colorobj, *rectobj; | |
| 425 GAME_Rect *rect, temp; | |
| 426 SDL_Surface* surf; | |
| 427 Uint8 rgba[4]; | |
| 428 Uint32 color; | |
| 349 | 429 int width=0, loop, t, l, b, r; |
| 225 | 430 |
| 431 /*get all the arguments*/ | |
| 349 | 432 if(!PyArg_ParseTuple(arg, "O!OO|i", &PySurface_Type, &surfobj, &colorobj, &rectobj, &width)) |
| 225 | 433 return NULL; |
| 434 rect = GameRect_FromObject(rectobj, &temp); | |
| 435 if(!rect) | |
| 436 return RAISE(PyExc_TypeError, "Invalid recstyle argument"); | |
| 437 | |
| 438 surf = PySurface_AsSurface(surfobj); | |
| 439 if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) | |
| 440 return RAISE(PyExc_ValueError, "unsupport bit depth for drawing"); | |
| 441 | |
| 442 if(PyInt_Check(colorobj)) | |
| 443 color = (Uint32)PyInt_AsLong(colorobj); | |
| 1037 | 444 else if(RGBAFromColorObj(colorobj, rgba)) |
| 225 | 445 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 446 else | |
| 447 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 448 | |
| 257 | 449 if ( width < 0 ) |
| 450 return RAISE(PyExc_ValueError, "negative width"); | |
| 451 if ( width > rect->w / 2 || width > rect->h / 2 ) | |
| 452 return RAISE(PyExc_ValueError, "width greater than ellipse radius"); | |
| 225 | 453 |
| 454 if(!PySurface_Lock(surfobj)) return NULL; | |
| 455 | |
| 456 if(!width) | |
| 256 | 457 draw_fillellipse(surf, (Sint16)(rect->x+rect->w/2), (Sint16)(rect->y+rect->h/2), |
| 225 | 458 (Sint16)(rect->w/2), (Sint16)(rect->h/2), color); |
| 459 else | |
| 460 { | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
461 width = MIN(width, MIN(rect->w, rect->h) / 2); |
| 225 | 462 for(loop=0; loop<width; ++loop) |
| 463 { | |
| 256 | 464 draw_ellipse(surf, rect->x+rect->w/2, rect->y+rect->h/2, |
| 225 | 465 rect->w/2-loop, rect->h/2-loop, color); |
| 466 } | |
| 467 } | |
| 468 | |
| 469 if(!PySurface_Unlock(surfobj)) return NULL; | |
| 470 | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
471 l = MAX(rect->x, surf->clip_rect.x); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
472 t = MAX(rect->y, surf->clip_rect.y); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
473 r = MIN(rect->x + rect->w, surf->clip_rect.x + surf->clip_rect.w); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
474 b = MIN(rect->y + rect->h, surf->clip_rect.y + surf->clip_rect.h); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
475 return PyRect_New4(l, t, MAX(r-l, 0), MAX(b-t, 0)); |
| 225 | 476 } |
| 477 | |
| 478 | |
| 244 | 479 static PyObject* circle(PyObject* self, PyObject* arg) |
| 480 { | |
| 481 PyObject *surfobj, *colorobj; | |
| 482 SDL_Surface* surf; | |
| 483 Uint8 rgba[4]; | |
| 484 Uint32 color; | |
| 256 | 485 int posx, posy, radius, t, l, b, r; |
| 349 | 486 int width=0, loop; |
| 244 | 487 |
| 488 /*get all the arguments*/ | |
| 349 | 489 if(!PyArg_ParseTuple(arg, "O!O(ii)i|i", &PySurface_Type, &surfobj, &colorobj, &posx, &posy, &radius, &width)) |
| 244 | 490 return NULL; |
| 491 | |
| 492 surf = PySurface_AsSurface(surfobj); | |
| 493 if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) | |
| 494 return RAISE(PyExc_ValueError, "unsupport bit depth for drawing"); | |
| 495 | |
| 496 if(PyInt_Check(colorobj)) | |
| 497 color = (Uint32)PyInt_AsLong(colorobj); | |
| 1037 | 498 else if(RGBAFromColorObj(colorobj, rgba)) |
| 244 | 499 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 500 else | |
| 501 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 502 | |
| 257 | 503 if ( radius < 0 ) |
| 504 return RAISE(PyExc_ValueError, "negative radius"); | |
| 505 if ( width < 0 ) | |
| 506 return RAISE(PyExc_ValueError, "negative width"); | |
| 507 if ( width > radius ) | |
| 508 return RAISE(PyExc_ValueError, "width greater than radius"); | |
| 509 | |
| 244 | 510 |
| 511 if(!PySurface_Lock(surfobj)) return NULL; | |
| 512 | |
| 513 if(!width) | |
| 256 | 514 draw_fillellipse(surf, (Sint16)posx, (Sint16)posy, (Sint16)radius, (Sint16)radius, color); |
| 244 | 515 else |
| 516 for(loop=0; loop<width; ++loop) | |
| 256 | 517 draw_ellipse(surf, posx, posy, radius-loop, radius-loop, color); |
| 244 | 518 |
| 519 if(!PySurface_Unlock(surfobj)) return NULL; | |
| 520 | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
521 l = MAX(posx - radius, surf->clip_rect.x); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
522 t = MAX(posy - radius, surf->clip_rect.y); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
523 r = MIN(posx + radius, surf->clip_rect.x + surf->clip_rect.w); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
524 b = MIN(posy + radius, surf->clip_rect.y + surf->clip_rect.h); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
525 return PyRect_New4(l, t, MAX(r-l, 0), MAX(b-t, 0)); |
| 244 | 526 } |
| 527 | |
| 528 | |
| 225 | 529 static PyObject* polygon(PyObject* self, PyObject* arg) |
| 530 { | |
| 531 PyObject *surfobj, *colorobj, *points, *item; | |
| 532 SDL_Surface* surf; | |
| 533 Uint8 rgba[4]; | |
| 534 Uint32 color; | |
| 349 | 535 int width=0, length, loop, numpoints; |
| 225 | 536 int *xlist, *ylist; |
| 491 | 537 int x, y, top, left, bottom, right, result; |
| 225 | 538 |
| 539 /*get all the arguments*/ | |
| 349 | 540 if(!PyArg_ParseTuple(arg, "O!OO|i", &PySurface_Type, &surfobj, &colorobj, &points, &width)) |
| 225 | 541 return NULL; |
| 542 | |
| 471 | 543 |
| 225 | 544 if(width) |
| 545 { | |
| 546 PyObject *args, *ret; | |
| 547 args = Py_BuildValue("(OOiOi)", surfobj, colorobj, 1, points, width); | |
| 548 if(!args) return NULL; | |
| 549 ret = lines(NULL, args); | |
| 550 Py_DECREF(args); | |
| 551 return ret; | |
| 552 } | |
| 244 | 553 |
| 257 | 554 |
| 225 | 555 surf = PySurface_AsSurface(surfobj); |
| 556 | |
| 557 if(surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) | |
| 558 return RAISE(PyExc_ValueError, "unsupport bit depth for line draw"); | |
| 559 | |
| 560 if(PyInt_Check(colorobj)) | |
| 561 color = (Uint32)PyInt_AsLong(colorobj); | |
| 1037 | 562 else if(RGBAFromColorObj(colorobj, rgba)) |
| 225 | 563 color = SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); |
| 564 else | |
| 565 return RAISE(PyExc_TypeError, "invalid color argument"); | |
| 566 | |
| 567 if(!PySequence_Check(points)) | |
| 568 return RAISE(PyExc_TypeError, "points argument must be a sequence of number pairs"); | |
| 569 length = PySequence_Length(points); | |
| 570 if(length < 3) | |
| 571 return RAISE(PyExc_ValueError, "points argument must contain more than 2 points"); | |
| 572 | |
| 573 | |
| 574 item = PySequence_GetItem(points, 0); | |
| 491 | 575 result = TwoIntsFromObj(item, &x, &y); |
| 225 | 576 Py_DECREF(item); |
| 577 if(!result) return RAISE(PyExc_TypeError, "points must be number pairs"); | |
| 578 left = right = x; | |
| 579 top = bottom = y; | |
| 580 | |
| 581 xlist = PyMem_New(int, length); | |
| 582 ylist = PyMem_New(int, length); | |
| 583 | |
| 584 numpoints = 0; | |
| 585 for(loop = 0; loop < length; ++loop) | |
| 586 { | |
| 587 item = PySequence_GetItem(points, loop); | |
| 491 | 588 result = TwoIntsFromObj(item, &x, &y); |
| 225 | 589 Py_DECREF(item); |
| 590 if(!result) continue; /*note, we silently skip over bad points :[ */ | |
| 591 xlist[numpoints] = x; | |
| 592 ylist[numpoints] = y; | |
| 593 ++numpoints; | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
594 left = MIN(x, left); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
595 top = MIN(y, top); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
596 right = MAX(x, right); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
597 bottom = MAX(y, bottom); |
| 225 | 598 } |
| 599 | |
| 600 if(!PySurface_Lock(surfobj)) | |
| 601 { | |
| 602 PyMem_Del(xlist); PyMem_Del(ylist); | |
| 603 return NULL; | |
| 604 } | |
| 605 | |
| 256 | 606 draw_fillpoly(surf, xlist, ylist, numpoints, color); |
| 225 | 607 |
| 608 PyMem_Del(xlist); PyMem_Del(ylist); | |
| 609 if(!PySurface_Unlock(surfobj)) | |
| 610 return NULL; | |
| 611 | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
612 left = MAX(left, surf->clip_rect.x); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
613 top = MAX(top, surf->clip_rect.y); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
614 right = MIN(right, surf->clip_rect.x + surf->clip_rect.w); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
615 bottom = MIN(bottom, surf->clip_rect.y + surf->clip_rect.h); |
| 491 | 616 return PyRect_New4(left, top, right-left+1, bottom-top+1); |
| 225 | 617 } |
| 618 | |
| 619 | |
| 244 | 620 static PyObject* rect(PyObject* self, PyObject* arg) |
| 621 { | |
| 622 PyObject *surfobj, *colorobj, *rectobj, *points, *args, *ret=NULL; | |
| 623 GAME_Rect* rect, temp; | |
| 349 | 624 int t, l, b, r, width=0; |
| 244 | 625 |
| 626 /*get all the arguments*/ | |
| 349 | 627 if(!PyArg_ParseTuple(arg, "O!OO|i", &PySurface_Type, &surfobj, &colorobj, &rectobj, &width)) |
| 244 | 628 return NULL; |
| 629 | |
| 630 if(!(rect = GameRect_FromObject(rectobj, &temp))) | |
| 631 return RAISE(PyExc_TypeError, "Rect argument is invalid"); | |
| 632 | |
| 339 | 633 l = rect->x; r = rect->x + rect->w - 1; |
| 634 t = rect->y; b = rect->y + rect->h - 1; | |
| 244 | 635 |
| 636 /*build the pointlist*/ | |
| 637 points = Py_BuildValue("((ii)(ii)(ii)(ii))", l, t, r, t, r, b, l, b); | |
| 638 | |
|
1340
021525f5770f
Memory leak patch from Campbell Barton
Nirav Patel <nrp@eclecti.cc>
parents:
1037
diff
changeset
|
639 args = Py_BuildValue("(OONi)", surfobj, colorobj, points, width); |
| 244 | 640 if(args) ret = polygon(NULL, args); |
| 641 | |
| 642 Py_XDECREF(args); | |
| 643 return ret; | |
| 644 } | |
| 225 | 645 |
| 646 | |
| 93 | 647 |
| 648 | |
| 649 /*internal drawing tools*/ | |
| 650 | |
| 442 | 651 static int clip_and_draw_aaline(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, float* pts, int blend) |
| 652 { | |
| 653 if(!clipaaline(pts, rect->x+1, rect->y+1, rect->x+rect->w-2, rect->y+rect->h-2)) | |
| 654 return 0; | |
| 655 drawaaline(surf, color, pts[0], pts[1], pts[2], pts[3], blend); | |
| 656 return 1; | |
| 657 } | |
| 658 | |
| 93 | 659 static int clip_and_draw_line(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, int* pts) |
| 660 { | |
| 661 if(!clipline(pts, rect->x, rect->y, rect->x+rect->w-1, rect->y+rect->h-1)) | |
| 662 return 0; | |
| 663 if(pts[1] == pts[3]) | |
| 664 drawhorzline(surf, color, pts[0], pts[1], pts[2]); | |
| 257 | 665 else if(pts[0] == pts[2]) |
| 666 drawvertline(surf, color, pts[0], pts[1], pts[3]); | |
| 93 | 667 else |
| 668 drawline(surf, color, pts[0], pts[1], pts[2], pts[3]); | |
| 669 return 1; | |
| 670 } | |
| 85 | 671 |
| 176 | 672 static int clip_and_draw_line_width(SDL_Surface* surf, SDL_Rect* rect, Uint32 color, int width, int* pts) |
| 673 { | |
| 674 int loop; | |
| 675 int xinc=0, yinc=0; | |
| 676 int newpts[4]; | |
| 677 int range[4]; | |
| 678 int anydrawn = 0; | |
| 679 | |
| 680 if(abs(pts[0]-pts[2]) > abs(pts[1]-pts[3])) | |
| 681 yinc = 1; | |
| 682 else | |
| 683 xinc = 1; | |
| 684 | |
| 685 memcpy(newpts, pts, sizeof(int)*4); | |
| 686 if(clip_and_draw_line(surf, rect, color, newpts)) | |
| 687 { | |
| 688 anydrawn = 1; | |
| 689 memcpy(range, newpts, sizeof(int)*4); | |
| 690 } | |
| 691 else | |
| 692 { | |
| 693 range[0] = range[1] = 10000; | |
| 694 range[2] = range[3] = -10000; | |
| 695 } | |
| 696 | |
| 186 | 697 for(loop = 1; loop < width; loop += 2) |
| 176 | 698 { |
| 699 newpts[0] = pts[0] + xinc*(loop/2+1); | |
| 700 newpts[1] = pts[1] + yinc*(loop/2+1); | |
| 701 newpts[2] = pts[2] + xinc*(loop/2+1); | |
| 702 newpts[3] = pts[3] + yinc*(loop/2+1); | |
| 703 if(clip_and_draw_line(surf, rect, color, newpts)) | |
| 704 { | |
| 705 anydrawn = 1; | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
706 range[0] = MIN(newpts[0], range[0]); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
707 range[1] = MIN(newpts[1], range[1]); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
708 range[2] = MAX(newpts[2], range[2]); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
709 range[3] = MAX(newpts[3], range[3]); |
| 176 | 710 } |
| 711 if(loop+1<width) | |
| 712 { | |
| 225 | 713 newpts[0] = pts[0] - xinc*(loop/2+1); |
| 714 newpts[1] = pts[1] - yinc*(loop/2+1); | |
| 715 newpts[2] = pts[2] - xinc*(loop/2+1); | |
| 716 newpts[3] = pts[3] - yinc*(loop/2+1); | |
| 176 | 717 if(clip_and_draw_line(surf, rect, color, newpts)) |
| 718 { | |
| 719 anydrawn = 1; | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
720 range[0] = MIN(newpts[0], range[0]); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
721 range[1] = MIN(newpts[1], range[1]); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
722 range[2] = MAX(newpts[2], range[2]); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
723 range[3] = MAX(newpts[3], range[3]); |
| 176 | 724 } |
| 725 } | |
| 726 } | |
| 727 if(anydrawn) | |
| 728 memcpy(pts, range, sizeof(int)*4); | |
| 729 return anydrawn; | |
| 730 } | |
| 731 | |
| 85 | 732 |
| 733 /*this line clipping based heavily off of code from | |
| 734 http://www.ncsa.uiuc.edu/Vis/Graphics/src/clipCohSuth.c */ | |
| 735 #define LEFT_EDGE 0x1 | |
| 736 #define RIGHT_EDGE 0x2 | |
| 737 #define BOTTOM_EDGE 0x4 | |
| 738 #define TOP_EDGE 0x8 | |
| 739 #define INSIDE(a) (!a) | |
| 740 #define REJECT(a,b) (a&b) | |
| 741 #define ACCEPT(a,b) (!(a|b)) | |
| 742 | |
| 743 static int encode(int x, int y, int left, int top, int right, int bottom) | |
| 744 { | |
| 745 int code = 0; | |
| 746 if(x < left) code |= LEFT_EDGE; | |
| 747 if(x > right) code |= RIGHT_EDGE; | |
| 748 if(y < top) code |= TOP_EDGE; | |
| 749 if(y > bottom)code |= BOTTOM_EDGE; | |
| 750 return code; | |
| 751 } | |
| 752 | |
| 442 | 753 static int encodeFloat(float x, float y, int left, int top, int right, int bottom) |
| 754 { | |
| 755 int code = 0; | |
| 756 if(x < left) code |= LEFT_EDGE; | |
| 757 if(x > right) code |= RIGHT_EDGE; | |
| 758 if(y < top) code |= TOP_EDGE; | |
| 759 if(y > bottom)code |= BOTTOM_EDGE; | |
| 760 return code; | |
| 761 } | |
| 762 | |
| 763 static int clipaaline(float* pts, int left, int top, int right, int bottom) | |
| 764 { | |
| 765 float x1 = pts[0]; | |
| 766 float y1 = pts[1]; | |
| 767 float x2 = pts[2]; | |
| 768 float y2 = pts[3]; | |
| 769 int code1, code2; | |
| 770 int draw = 0; | |
| 771 float swaptmp; | |
| 772 int intswaptmp; | |
| 773 float m; /*slope*/ | |
| 774 | |
| 775 while(1) { | |
| 776 code1 = encodeFloat(x1, y1, left, top, right, bottom); | |
| 777 code2 = encodeFloat(x2, y2, left, top, right, bottom); | |
| 778 if(ACCEPT(code1, code2)) { | |
| 779 draw = 1; | |
| 780 break; | |
| 781 } | |
| 782 else if(REJECT(code1, code2)) { | |
| 783 break; | |
| 784 } | |
| 785 else { | |
| 786 if(INSIDE(code1)) { | |
| 787 swaptmp = x2; x2 = x1; x1 = swaptmp; | |
| 788 swaptmp = y2; y2 = y1; y1 = swaptmp; | |
| 789 intswaptmp = code2; code2 = code1; code1 = intswaptmp; | |
| 790 } | |
| 471 | 791 if(x2 != x1) |
| 442 | 792 m = (y2 - y1) / (x2 - x1); |
| 793 else | |
| 794 m = 1.0f; | |
| 795 if(code1 & LEFT_EDGE) { | |
| 796 y1 += ((float)left - x1) * m; | |
| 471 | 797 x1 = (float)left; |
| 798 } | |
| 442 | 799 else if(code1 & RIGHT_EDGE) { |
| 800 y1 += ((float)right - x1) * m; | |
| 471 | 801 x1 = (float)right; |
| 802 } | |
| 442 | 803 else if(code1 & BOTTOM_EDGE) { |
| 804 if(x2 != x1) | |
| 805 x1 += ((float)bottom - y1) / m; | |
| 806 y1 = (float)bottom; | |
| 471 | 807 } |
| 442 | 808 else if(code1 & TOP_EDGE) { |
| 809 if(x2 != x1) | |
| 810 x1 += ((float)top - y1) / m; | |
| 811 y1 = (float)top; | |
| 471 | 812 } |
| 442 | 813 } |
| 814 } | |
| 815 if(draw) { | |
| 816 pts[0] = x1; pts[1] = y1; | |
| 817 pts[2] = x2; pts[3] = y2; | |
| 818 } | |
| 819 return draw; | |
| 820 } | |
| 821 | |
| 85 | 822 static int clipline(int* pts, int left, int top, int right, int bottom) |
| 823 { | |
| 824 int x1 = pts[0]; | |
| 825 int y1 = pts[1]; | |
| 826 int x2 = pts[2]; | |
| 827 int y2 = pts[3]; | |
| 828 int code1, code2; | |
| 829 int draw = 0; | |
| 830 int swaptmp; | |
| 831 float m; /*slope*/ | |
| 832 | |
| 833 while(1) | |
| 834 { | |
| 835 code1 = encode(x1, y1, left, top, right, bottom); | |
| 836 code2 = encode(x2, y2, left, top, right, bottom); | |
| 837 if(ACCEPT(code1, code2)) { | |
| 838 draw = 1; | |
| 839 break; | |
| 840 } | |
| 841 else if(REJECT(code1, code2)) | |
| 842 break; | |
| 843 else { | |
| 844 if(INSIDE(code1)) { | |
| 845 swaptmp = x2; x2 = x1; x1 = swaptmp; | |
| 846 swaptmp = y2; y2 = y1; y1 = swaptmp; | |
| 847 swaptmp = code2; code2 = code1; code1 = swaptmp; | |
| 848 } | |
| 471 | 849 if(x2 != x1) |
| 85 | 850 m = (y2 - y1) / (float)(x2 - x1); |
| 99 | 851 else |
| 852 m = 1.0f; | |
| 85 | 853 if(code1 & LEFT_EDGE) { |
| 854 y1 += (int)((left - x1) * m); | |
| 471 | 855 x1 = left; |
| 856 } | |
| 85 | 857 else if(code1 & RIGHT_EDGE) { |
| 858 y1 += (int)((right - x1) * m); | |
| 471 | 859 x1 = right; |
| 860 } | |
| 85 | 861 else if(code1 & BOTTOM_EDGE) { |
| 862 if(x2 != x1) | |
| 863 x1 += (int)((bottom - y1) / m); | |
| 864 y1 = bottom; | |
| 471 | 865 } |
| 85 | 866 else if(code1 & TOP_EDGE) { |
| 867 if(x2 != x1) | |
| 868 x1 += (int)((top - y1) / m); | |
| 869 y1 = top; | |
| 471 | 870 } |
| 85 | 871 } |
| 872 } | |
| 873 if(draw) { | |
| 874 pts[0] = x1; pts[1] = y1; | |
| 875 pts[2] = x2; pts[3] = y2; | |
| 876 } | |
| 877 return draw; | |
| 878 } | |
| 879 | |
| 880 | |
| 881 | |
| 257 | 882 static int set_at(SDL_Surface* surf, int x, int y, Uint32 color) |
| 883 { | |
| 884 SDL_PixelFormat* format = surf->format; | |
| 885 Uint8* pixels = (Uint8*)surf->pixels; | |
| 886 Uint8* byte_buf, rgb[4]; | |
| 887 | |
| 888 if(x < surf->clip_rect.x || x >= surf->clip_rect.x + surf->clip_rect.w || | |
| 889 y < surf->clip_rect.y || y >= surf->clip_rect.y + surf->clip_rect.h) | |
| 890 return 0; | |
| 891 | |
| 892 switch(format->BytesPerPixel) | |
| 893 { | |
| 894 case 1: | |
| 895 *((Uint8*)pixels + y * surf->pitch + x) = (Uint8)color; | |
| 896 break; | |
| 897 case 2: | |
| 898 *((Uint16*)(pixels + y * surf->pitch) + x) = (Uint16)color; | |
| 899 break; | |
| 900 case 4: | |
| 901 *((Uint32*)(pixels + y * surf->pitch) + x) = color; | |
| 902 /* *((Uint32*)(pixels + y * surf->pitch) + x) = | |
| 903 ~(*((Uint32*)(pixels + y * surf->pitch) + x)) * 31; | |
| 904 */ break; | |
| 905 default:/*case 3:*/ | |
| 906 SDL_GetRGB(color, format, rgb, rgb+1, rgb+2); | |
| 907 byte_buf = (Uint8*)(pixels + y * surf->pitch) + x * 3; | |
|
652
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
908 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
909 *(byte_buf + (format->Rshift >> 3)) = rgb[0]; |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
910 *(byte_buf + (format->Gshift >> 3)) = rgb[1]; |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
911 *(byte_buf + (format->Bshift >> 3)) = rgb[2]; |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
912 #else |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
913 *(byte_buf + 2 - (format->Rshift >> 3)) = rgb[0]; |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
914 *(byte_buf + 2 - (format->Gshift >> 3)) = rgb[1]; |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
915 *(byte_buf + 2 - (format->Bshift >> 3)) = rgb[2]; |
|
950417bbf1a7
Endian patch for set_at() from Ivo Danihelka.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
916 #endif |
| 257 | 917 break; |
| 918 } | |
| 919 return 1; | |
| 920 } | |
| 921 | |
| 85 | 922 |
| 442 | 923 #define DRAWPIX32(pixel,colorptr,br,blend) \ |
| 924 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) color <<= 8; \ | |
| 543 | 925 if(blend) { \ |
| 926 int x; \ | |
| 549 | 927 float nbr = 1.0-br; \ |
| 928 x = colorptr[0]*br+pixel[0]*nbr; \ | |
| 543 | 929 pixel[0]= (x>254) ? 255: x; \ |
| 549 | 930 x = colorptr[1]*br+pixel[1]*nbr; \ |
| 543 | 931 pixel[1]= (x>254) ? 255: x; \ |
| 549 | 932 x = colorptr[2]*br+pixel[2]*nbr; \ |
| 543 | 933 pixel[2]= (x>254) ? 255: x; \ |
| 934 if(hasalpha) pixel[3] = pixel[0]+(br*255) - (pixel[3]*br); \ | |
| 935 } else { \ | |
| 936 pixel[0]=(Uint8)(colorptr[0]*br); \ | |
| 937 pixel[1]=(Uint8)(colorptr[1]*br); \ | |
| 938 pixel[2]=(Uint8)(colorptr[2]*br); \ | |
| 939 if(hasalpha) pixel[3] = br*255; \ | |
| 940 } | |
| 442 | 941 |
| 942 /* Adapted from http://freespace.virgin.net/hugo.elias/graphics/x_wuline.htm */ | |
| 943 static void drawaaline(SDL_Surface* surf, Uint32 color, float x1, float y1, float x2, float y2, int blend) { | |
| 944 float grad, xd, yd; | |
| 945 float xgap, ygap, xend, yend, xf, yf; | |
| 946 float brightness1, brightness2; | |
| 947 float swaptmp; | |
| 948 int x, y, ix1, ix2, iy1, iy2; | |
| 949 int pixx, pixy; | |
| 950 Uint8* pixel; | |
| 951 Uint8* pm = (Uint8*)surf->pixels; | |
| 952 Uint8* colorptr = (Uint8*)&color; | |
| 543 | 953 const int hasalpha = surf->format->Amask; |
| 442 | 954 |
| 543 | 955 pixx = surf->format->BytesPerPixel; |
| 442 | 956 pixy = surf->pitch; |
| 957 | |
| 958 xd = x2-x1; | |
| 959 yd = y2-y1; | |
| 995 | 960 |
| 961 if (xd == 0 && yd == 0) | |
| 962 { | |
| 963 /* Single point. Due to the nature of the aaline clipping, this | |
| 964 * is less exact than the normal line. */ | |
| 965 set_at (surf, x1, y1, color); | |
| 966 return; | |
| 967 } | |
| 968 | |
| 442 | 969 if(fabs(xd)>fabs(yd)) { |
| 970 if(x1>x2) { | |
| 971 swaptmp=x1; x1=x2; x2=swaptmp; | |
| 972 swaptmp=y1; y1=y2; y2=swaptmp; | |
| 973 xd = (x2-x1); | |
| 974 yd = (y2-y1); | |
| 975 } | |
| 976 grad = yd/xd; | |
| 977 xend = trunc(x1)+0.5; /* This makes more sense than trunc(x1+0.5) */ | |
| 978 yend = y1+grad*(xend-x1); | |
| 979 xgap = INVFRAC(x1); | |
| 980 ix1 = (int)xend; | |
| 981 iy1 = (int)yend; | |
| 982 yf = yend+grad; | |
| 983 brightness1 = INVFRAC(yend) * xgap; | |
| 984 brightness2 = FRAC(yend) * xgap; | |
| 985 pixel = pm + pixx * ix1 + pixy * iy1; | |
| 986 DRAWPIX32(pixel, colorptr, brightness1, blend) | |
| 987 pixel += pixy; | |
| 988 DRAWPIX32(pixel, colorptr, brightness2, blend) | |
| 989 xend = trunc(x2)+0.5; | |
| 990 yend = y2+grad*(xend-x2); | |
| 991 xgap = FRAC(x2); /* this also differs from Hugo's description. */ | |
| 992 ix2 = (int)xend; | |
| 993 iy2 = (int)yend; | |
| 994 brightness1 = INVFRAC(yend) * xgap; | |
| 995 brightness2 = FRAC(yend) * xgap; | |
| 996 pixel = pm + pixx * ix2 + pixy * iy2; | |
| 997 DRAWPIX32(pixel, colorptr, brightness1, blend) | |
| 471 | 998 pixel += pixy; |
| 442 | 999 DRAWPIX32(pixel, colorptr, brightness2, blend) |
| 1000 for(x=ix1+1; x<ix2; ++x) { | |
| 1001 brightness1=INVFRAC(yf); | |
| 1002 brightness2= FRAC(yf); | |
| 1003 pixel = pm + pixx * x + pixy * (int)yf; | |
| 1004 DRAWPIX32(pixel, colorptr, brightness1, blend) | |
| 1005 pixel += pixy; | |
| 1006 DRAWPIX32(pixel, colorptr, brightness2, blend) | |
| 1007 yf += grad; | |
| 1008 } | |
| 1009 } | |
| 1010 else { | |
| 1011 if(y1>y2) { | |
| 1012 swaptmp=y1; y1=y2; y2=swaptmp; | |
| 1013 swaptmp=x1; x1=x2; x2=swaptmp; | |
| 1014 yd = (y2-y1); | |
| 1015 xd = (x2-x1); | |
| 1016 } | |
| 1017 grad = xd/yd; | |
| 1018 yend = trunc(y1)+0.5; /* This makes more sense than trunc(x1+0.5) */ | |
| 1019 xend = x1+grad*(yend-y1); | |
| 1020 ygap = INVFRAC(y1); | |
| 1021 iy1 = (int)yend; | |
| 1022 ix1 = (int)xend; | |
| 1023 xf = xend+grad; | |
| 1024 brightness1 = INVFRAC(xend) * ygap; | |
| 1025 brightness2 = FRAC(xend) * ygap; | |
| 1026 pixel = pm + pixx * ix1 + pixy * iy1; | |
| 1027 DRAWPIX32(pixel, colorptr, brightness1, blend) | |
| 1028 pixel += pixx; | |
| 1029 DRAWPIX32(pixel, colorptr, brightness2, blend) | |
| 471 | 1030 yend = trunc(y2)+0.5; |
| 442 | 1031 xend = x2+grad*(yend-y2); |
| 1032 ygap = FRAC(y2); | |
| 1033 iy2 = (int)yend; | |
| 1034 ix2 = (int)xend; | |
| 1035 brightness1 = INVFRAC(xend) * ygap; | |
| 1036 brightness2 = FRAC(xend) * ygap; | |
| 1037 pixel = pm + pixx * ix2 + pixy * iy2; | |
| 1038 DRAWPIX32(pixel, colorptr, brightness1, blend) | |
| 471 | 1039 pixel += pixx; |
| 442 | 1040 DRAWPIX32(pixel, colorptr, brightness2, blend) |
| 1041 for(y=iy1+1; y<iy2; ++y) { | |
| 1042 brightness1=INVFRAC(xf); | |
| 1043 brightness2= FRAC(xf); | |
| 1044 pixel = pm + pixx * (int)xf + pixy * y; | |
| 1045 DRAWPIX32(pixel, colorptr, brightness1, blend) | |
| 1046 pixel += pixx; | |
| 1047 DRAWPIX32(pixel, colorptr, brightness2, blend) | |
| 1048 xf += grad; | |
| 1049 } | |
| 1050 } | |
| 1051 } | |
| 1052 | |
| 1053 | |
| 93 | 1054 /*here's my sdl'ized version of bresenham*/ |
| 85 | 1055 static void drawline(SDL_Surface* surf, Uint32 color, int x1, int y1, int x2, int y2) |
| 1056 { | |
| 1057 int deltax, deltay, signx, signy; | |
| 1058 int pixx, pixy; | |
| 1059 int x = 0, y = 0; | |
| 1060 int swaptmp; | |
| 1061 Uint8 *pixel; | |
| 87 | 1062 Uint8 *colorptr; |
| 85 | 1063 |
| 238 | 1064 deltax = x2 - x1; |
| 1065 deltay = y2 - y1; | |
| 1066 signx = (deltax < 0) ? -1 : 1; | |
| 1067 signy = (deltay < 0) ? -1 : 1; | |
| 1068 deltax = signx * deltax + 1; | |
| 1069 deltay = signy * deltay + 1; | |
| 85 | 1070 |
| 1071 pixx = surf->format->BytesPerPixel; | |
| 1072 pixy = surf->pitch; | |
| 1073 pixel = ((Uint8*)surf->pixels) + pixx * x1 + pixy * y1; | |
| 1074 | |
| 1075 pixx *= signx; | |
| 1076 pixy *= signy; | |
| 1077 if(deltax < deltay) /*swap axis if rise > run*/ | |
| 1078 { | |
| 1079 swaptmp = deltax; deltax = deltay; deltay = swaptmp; | |
| 1080 swaptmp = pixx; pixx = pixy; pixy = swaptmp; | |
| 1081 } | |
| 1082 | |
| 1083 switch(surf->format->BytesPerPixel) | |
| 1084 { | |
| 1085 case 1: | |
| 1086 for(; x < deltax; x++, pixel += pixx) { | |
| 1087 *pixel = (Uint8)color; | |
| 1088 y += deltay; if(y >= deltax) {y -= deltax; pixel += pixy;} | |
| 1089 }break; | |
| 1090 case 2: | |
| 1091 for(; x < deltax; x++, pixel += pixx) { | |
| 1092 *(Uint16*)pixel = (Uint16)color; | |
| 1093 y += deltay; if(y >= deltax) {y -= deltax; pixel += pixy;} | |
| 1094 }break; | |
| 1095 case 3: | |
| 87 | 1096 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) color <<= 8; |
| 1097 colorptr = (Uint8*)&color; | |
| 85 | 1098 for(; x < deltax; x++, pixel += pixx) { |
| 87 | 1099 pixel[0] = colorptr[0]; |
| 1100 pixel[1] = colorptr[1]; | |
| 1101 pixel[2] = colorptr[2]; | |
| 85 | 1102 y += deltay; if(y >= deltax) {y -= deltax; pixel += pixy;} |
| 1103 }break; | |
| 1104 default: /*case 4*/ | |
| 1105 for(; x < deltax; x++, pixel += pixx) { | |
| 442 | 1106 *(Uint32*)pixel = (Uint32)color; |
| 85 | 1107 y += deltay; if(y >= deltax) {y -= deltax; pixel += pixy;} |
| 1108 }break; | |
| 1109 } | |
| 1110 } | |
| 1111 | |
| 1112 | |
| 1113 | |
| 93 | 1114 static void drawhorzline(SDL_Surface* surf, Uint32 color, int x1, int y1, int x2) |
| 85 | 1115 { |
| 1116 Uint8 *pixel, *end; | |
| 87 | 1117 Uint8 *colorptr; |
| 85 | 1118 |
| 488 | 1119 if(x1 == x2) |
| 1120 { | |
| 1121 set_at(surf, x1, y1, color); | |
| 1122 return; | |
| 1123 } | |
| 85 | 1124 |
| 1125 pixel = ((Uint8*)surf->pixels) + surf->pitch * y1; | |
| 1126 if(x1 < x2) | |
| 1127 { | |
| 1128 end = pixel + x2 * surf->format->BytesPerPixel; | |
| 1129 pixel += x1 * surf->format->BytesPerPixel; | |
| 1130 } | |
| 1131 else | |
| 1132 { | |
| 1133 end = pixel + x1 * surf->format->BytesPerPixel; | |
| 1134 pixel += x2 * surf->format->BytesPerPixel; | |
| 1135 } | |
| 1136 switch(surf->format->BytesPerPixel) | |
| 1137 { | |
| 1138 case 1: | |
| 1139 for(; pixel <= end; ++pixel) { | |
| 1140 *pixel = (Uint8)color; | |
| 1141 }break; | |
| 1142 case 2: | |
| 110 | 1143 for(; pixel <= end; pixel+=2) { |
| 85 | 1144 *(Uint16*)pixel = (Uint16)color; |
| 1145 }break; | |
| 1146 case 3: | |
| 87 | 1147 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) color <<= 8; |
| 1148 colorptr = (Uint8*)&color; | |
| 110 | 1149 for(; pixel <= end; pixel+=3) { |
| 87 | 1150 pixel[0] = colorptr[0]; |
| 1151 pixel[1] = colorptr[1]; | |
| 1152 pixel[2] = colorptr[2]; | |
| 85 | 1153 }break; |
| 1154 default: /*case 4*/ | |
| 110 | 1155 for(; pixel <= end; pixel+=4) { |
| 225 | 1156 *(Uint32*)pixel = color; |
| 260 | 1157 }break; |
| 85 | 1158 } |
| 1159 } | |
| 1160 | |
| 225 | 1161 static void drawhorzlineclip(SDL_Surface* surf, Uint32 color, int x1, int y1, int x2) |
| 1162 { | |
| 257 | 1163 if(y1 < surf->clip_rect.y || y1 >= surf->clip_rect.y + surf->clip_rect.h) |
| 1164 return; | |
| 1165 | |
| 260 | 1166 if( x2 < x1 ) |
| 257 | 1167 { |
| 260 | 1168 int temp = x1; |
| 1169 x1 = x2; x2 = temp; | |
| 257 | 1170 } |
| 1171 | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
1172 x1 = MAX(x1, surf->clip_rect.x); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
1173 x2 = MIN(x2, surf->clip_rect.x + surf->clip_rect.w-1); |
| 260 | 1174 |
| 1175 if(x2 < surf->clip_rect.x || x1 >= surf->clip_rect.x + surf->clip_rect.w) | |
| 1176 return; | |
| 1177 | |
| 257 | 1178 if(x1 == x2) |
| 260 | 1179 set_at(surf, x1, y1, color); |
| 257 | 1180 else |
| 1181 drawhorzline(surf, color, x1, y1, x2); | |
| 1182 } | |
| 1183 | |
| 1184 static void drawvertline(SDL_Surface* surf, Uint32 color, int x1, int y1, int y2) | |
| 1185 { | |
| 1186 Uint8 *pixel, *end; | |
| 1187 Uint8 *colorptr; | |
| 1188 Uint32 pitch = surf->pitch; | |
| 1189 | |
| 488 | 1190 if(y1 == y2) |
| 1191 { | |
| 1192 set_at(surf, x1, y1, color); | |
| 1193 return; | |
| 1194 } | |
| 257 | 1195 |
| 1196 pixel = ((Uint8*)surf->pixels) + x1 * surf->format->BytesPerPixel; | |
| 1197 if(y1 < y2) | |
| 1198 { | |
| 1199 end = pixel + surf->pitch * y2; | |
| 1200 pixel += surf->pitch * y1; | |
| 1201 } | |
| 1202 else | |
| 1203 { | |
| 1204 end = pixel + surf->pitch * y1; | |
| 1205 pixel += surf->pitch * y2; | |
| 1206 } | |
| 1207 | |
| 1208 switch(surf->format->BytesPerPixel) | |
| 1209 { | |
| 1210 case 1: | |
| 1211 for(; pixel <= end; pixel+=pitch) { | |
| 1212 *pixel = (Uint8)color; | |
| 1213 }break; | |
| 1214 case 2: | |
| 1215 for(; pixel <= end; pixel+=pitch) { | |
| 1216 *(Uint16*)pixel = (Uint16)color; | |
| 1217 }break; | |
| 1218 case 3: | |
| 1219 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) color <<= 8; | |
| 1220 colorptr = (Uint8*)&color; | |
| 1221 for(; pixel <= end; pixel+=pitch) { | |
| 1222 pixel[0] = colorptr[0]; | |
| 1223 pixel[1] = colorptr[1]; | |
| 1224 pixel[2] = colorptr[2]; | |
| 1225 }break; | |
| 1226 default: /*case 4*/ | |
| 1227 for(; pixel <= end; pixel+=pitch) { | |
| 1228 *(Uint32*)pixel = color; | |
| 1229 }break; | |
| 1230 } | |
| 225 | 1231 } |
| 1232 | |
| 1233 | |
| 257 | 1234 static void drawvertlineclip(SDL_Surface* surf, Uint32 color, int x1, int y1, int y2) |
| 225 | 1235 { |
| 257 | 1236 if(x1 < surf->clip_rect.x || x1 >= surf->clip_rect.x + surf->clip_rect.w) |
| 1237 return; | |
| 1238 if ( y2 < y1 ) | |
| 225 | 1239 { |
| 257 | 1240 int temp = y1; |
| 1241 y1 = y2; y2 = temp; | |
| 225 | 1242 } |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
1243 y1 = MAX(y1, surf->clip_rect.y); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
1244 y2 = MIN(y2, surf->clip_rect.y + surf->clip_rect.h-1); |
| 257 | 1245 if(y2 - y1 < 1) |
| 1246 set_at( surf, x1, y1, color); | |
| 1247 else | |
| 1248 drawvertline(surf, color, x1, y1, y2); | |
| 225 | 1249 } |
| 1250 | |
| 461 | 1251 static void draw_arc(SDL_Surface *dst, int x, int y, int radius1, int radius2, |
| 1252 double angle_start, double angle_stop, Uint32 color) | |
| 1253 { | |
| 1254 double aStep; // Angle Step (rad) | |
| 1255 double a; // Current Angle (rad) | |
| 1256 int x_last, x_next, y_last, y_next; | |
| 1257 | |
| 1258 // Angle step in rad | |
| 1259 if (radius1<radius2) { | |
| 1260 if (radius1<1.0e-4) { | |
| 1261 aStep=1.0; | |
| 1262 } else { | |
| 1263 aStep=asin(2.0/radius1); | |
| 1264 } | |
| 1265 } else { | |
| 1266 if (radius2<1.0e-4) { | |
| 1267 aStep=1.0; | |
| 1268 } else { | |
| 1269 aStep=asin(2.0/radius2); | |
| 1270 } | |
| 1271 } | |
| 1272 | |
| 1273 if(aStep<0.05) { | |
| 1274 aStep = 0.05; | |
| 1275 } | |
| 1276 | |
| 1277 x_last = x+cos(angle_start)*radius1; | |
| 1278 y_last = y-sin(angle_start)*radius2; | |
| 1279 for(a=angle_start+aStep; a<=angle_stop; a+=aStep) { | |
| 528 | 1280 int points[4]; |
| 461 | 1281 x_next = x+cos(a)*radius1; |
| 1282 y_next = y-sin(a)*radius2; | |
| 528 | 1283 points[0] = x_last; points[1] = y_last; |
| 1284 points[2] = x_next; points[3] = y_next; | |
| 1285 clip_and_draw_line(dst, &dst->clip_rect, color, points); | |
| 461 | 1286 x_last = x_next; |
| 1287 y_last = y_next; | |
| 1288 } | |
| 1289 } | |
| 1290 | |
| 256 | 1291 static void draw_ellipse(SDL_Surface *dst, int x, int y, int rx, int ry, Uint32 color) |
| 225 | 1292 { |
| 1293 int ix, iy; | |
| 1294 int h, i, j, k; | |
| 1295 int oh, oi, oj, ok; | |
| 1296 int xmh, xph, ypk, ymk; | |
| 1297 int xmi, xpi, ymj, ypj; | |
| 1298 int xmj, xpj, ymi, ypi; | |
| 1299 int xmk, xpk, ymh, yph; | |
| 471 | 1300 |
| 257 | 1301 if (rx==0 && ry==0) { /* Special case - draw a single pixel */ |
| 1302 set_at( dst, x, y, color); | |
| 1303 return; | |
| 225 | 1304 } |
| 257 | 1305 if (rx==0) { /* Special case for rx=0 - draw a vline */ |
| 1306 drawvertlineclip( dst, color, x, (Sint16)(y-ry), (Sint16)(y+ry) ); | |
| 1307 return; | |
| 1308 } | |
| 1309 if (ry==0) { /* Special case for ry=0 - draw a hline */ | |
| 1310 drawhorzlineclip( dst, color, (Sint16)(x-rx), y, (Sint16)(x+rx) ); | |
| 1311 return; | |
| 1312 } | |
| 1313 | |
| 1314 | |
| 225 | 1315 /* Init vars */ |
| 1316 oh = oi = oj = ok = 0xFFFF; | |
| 1317 if (rx > ry) { | |
| 1318 ix = 0; | |
| 1319 iy = rx * 64; | |
| 1320 do { | |
| 257 | 1321 h = (ix + 16) >> 6; |
| 1322 i = (iy + 16) >> 6; | |
| 225 | 1323 j = (h * ry) / rx; |
| 1324 k = (i * ry) / rx; | |
| 257 | 1325 |
| 225 | 1326 if (((ok!=k) && (oj!=k)) || ((oj!=j) && (ok!=j)) || (k!=j)) { |
| 256 | 1327 xph=x+h-1; |
| 225 | 1328 xmh=x-h; |
| 1329 if (k>0) { | |
| 256 | 1330 ypk=y+k-1; |
| 225 | 1331 ymk=y-k; |
| 257 | 1332 if(h > 0) { |
| 1333 set_at(dst, xmh, ypk, color); | |
| 1334 set_at(dst, xmh, ymk, color); | |
| 1335 } | |
| 225 | 1336 set_at(dst, xph, ypk, color); |
| 1337 set_at(dst, xph, ymk, color); | |
| 257 | 1338 } |
| 225 | 1339 ok=k; |
| 256 | 1340 xpi=x+i-1; |
| 225 | 1341 xmi=x-i; |
| 1342 if (j>0) { | |
| 256 | 1343 ypj=y+j-1; |
| 225 | 1344 ymj=y-j; |
| 1345 set_at(dst, xmi, ypj, color); | |
| 1346 set_at(dst, xpi, ypj, color); | |
| 1347 set_at(dst, xmi, ymj, color); | |
| 1348 set_at(dst, xpi, ymj, color); | |
| 257 | 1349 } |
| 225 | 1350 oj=j; |
| 1351 } | |
| 1352 ix = ix + iy / rx; | |
| 1353 iy = iy - ix / rx; | |
| 257 | 1354 |
| 225 | 1355 } while (i > h); |
| 1356 } else { | |
| 1357 ix = 0; | |
| 1358 iy = ry * 64; | |
| 1359 do { | |
| 1360 h = (ix + 32) >> 6; | |
| 1361 i = (iy + 32) >> 6; | |
| 1362 j = (h * rx) / ry; | |
| 1363 k = (i * rx) / ry; | |
| 257 | 1364 |
| 225 | 1365 if (((oi!=i) && (oh!=i)) || ((oh!=h) && (oi!=h) && (i!=h))) { |
| 1366 xmj=x-j; | |
| 256 | 1367 xpj=x+j-1; |
| 225 | 1368 if (i>0) { |
| 256 | 1369 ypi=y+i-1; |
| 225 | 1370 ymi=y-i; |
| 257 | 1371 if(j > 0) { |
| 1372 set_at(dst, xmj, ypi, color); | |
| 1373 set_at(dst, xmj, ymi, color); | |
| 1374 } | |
| 1375 set_at(dst, xpj, ypi, color); | |
| 1376 set_at(dst, xpj, ymi, color); | |
| 1377 } | |
| 225 | 1378 oi=i; |
| 1379 xmk=x-k; | |
| 256 | 1380 xpk=x+k-1; |
| 225 | 1381 if (h>0) { |
| 256 | 1382 yph=y+h-1; |
| 225 | 1383 ymh=y-h; |
| 1384 set_at(dst, xmk, yph, color); | |
| 1385 set_at(dst, xpk, yph, color); | |
| 1386 set_at(dst, xmk, ymh, color); | |
| 1387 set_at(dst, xpk, ymh, color); | |
| 257 | 1388 } |
| 225 | 1389 oh=h; |
| 1390 } | |
| 1391 ix = ix + iy / ry; | |
| 1392 iy = iy - ix / ry; | |
| 1393 } while(i > h); | |
| 1394 } | |
| 1395 } | |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 256 | 1403 static void draw_fillellipse(SDL_Surface *dst, int x, int y, int rx, int ry, Uint32 color) |
| 225 | 1404 { |
| 1405 int ix, iy; | |
| 1406 int h, i, j, k; | |
| 1407 int oh, oi, oj, ok; | |
| 257 | 1408 |
| 1409 if (rx==0 && ry==0) { /* Special case - draw a single pixel */ | |
| 1410 set_at( dst, x, y, color); | |
| 1411 return; | |
| 225 | 1412 } |
| 257 | 1413 if (rx==0) { /* Special case for rx=0 - draw a vline */ |
| 1414 drawvertlineclip( dst, color, x, (Sint16)(y-ry), (Sint16)(y+ry) ); | |
| 1415 return; | |
| 225 | 1416 } |
| 257 | 1417 if (ry==0) { /* Special case for ry=0 - draw a hline */ |
| 1418 drawhorzlineclip( dst, color, (Sint16)(x-rx), y, (Sint16)(x+rx) ); | |
| 1419 return; | |
| 225 | 1420 } |
| 257 | 1421 |
| 225 | 1422 /* Init vars */ |
| 1423 oh = oi = oj = ok = 0xFFFF; | |
| 471 | 1424 |
| 225 | 1425 /* Draw */ |
| 257 | 1426 if (rx >= ry) { |
| 225 | 1427 ix = 0; |
| 1428 iy = rx * 64; | |
| 471 | 1429 |
| 225 | 1430 do { |
| 471 | 1431 h = (ix + 8) >> 6; |
| 1432 i = (iy + 8) >> 6; | |
| 225 | 1433 j = (h * ry) / rx; |
| 1434 k = (i * ry) / rx; | |
| 471 | 1435 if ((ok!=k) && (oj!=k) && (k<ry)) { |
| 1436 drawhorzlineclip(dst, color, x-h, y-k-1, x+h-1); | |
| 257 | 1437 drawhorzlineclip(dst, color, x-h, y+k, x+h-1); |
| 225 | 1438 ok=k; |
| 1439 } | |
| 1440 if ((oj!=j) && (ok!=j) && (k!=j)) { | |
| 257 | 1441 drawhorzlineclip(dst, color, x-i, y+j, x+i-1); |
| 1442 drawhorzlineclip(dst, color, x-i, y-j-1, x+i-1); | |
| 225 | 1443 oj=j; |
| 1444 } | |
| 1445 ix = ix + iy / rx; | |
| 1446 iy = iy - ix / rx; | |
| 471 | 1447 |
| 225 | 1448 } while (i > h); |
| 1449 } else { | |
| 1450 ix = 0; | |
| 1451 iy = ry * 64; | |
| 471 | 1452 |
| 225 | 1453 do { |
| 471 | 1454 h = (ix + 8) >> 6; |
| 1455 i = (iy + 8) >> 6; | |
| 225 | 1456 j = (h * rx) / ry; |
| 1457 k = (i * rx) / ry; | |
| 471 | 1458 |
| 1459 if ((oi!=i) && (oh!=i) && (i<ry)) { | |
| 257 | 1460 drawhorzlineclip(dst, color, x-j, y+i, x+j-1); |
| 1461 drawhorzlineclip(dst, color, x-j, y-i-1, x+j-1); | |
| 225 | 1462 oi=i; |
| 1463 } | |
| 1464 if ((oh!=h) && (oi!=h) && (i!=h)) { | |
| 258 | 1465 drawhorzlineclip(dst, color, x-k, y+h, x+k-1); |
| 1466 drawhorzlineclip(dst, color, x-k, y-h-1, x+k-1); | |
| 225 | 1467 oh=h; |
| 1468 } | |
| 471 | 1469 |
| 225 | 1470 ix = ix + iy / ry; |
| 1471 iy = iy - ix / ry; | |
| 471 | 1472 |
| 225 | 1473 } while(i > h); |
| 1474 } | |
| 1475 } | |
| 1476 | |
| 1477 | |
| 1478 static int compare_int(const void *a, const void *b) | |
| 1479 { | |
| 1480 return (*(const int *)a) - (*(const int *)b); | |
| 1481 } | |
| 1482 | |
| 256 | 1483 static void draw_fillpoly(SDL_Surface *dst, int *vx, int *vy, int n, Uint32 color) |
| 225 | 1484 { |
| 1485 int i; | |
| 1486 int y; | |
| 1487 int miny, maxy; | |
| 1488 int x1, y1; | |
| 1489 int x2, y2; | |
| 1490 int ind1, ind2; | |
| 1491 int ints; | |
| 1492 int *polyints = PyMem_New(int, n); | |
| 553 | 1493 if (polyints == NULL) { |
| 1494 PyErr_NoMemory(); | |
| 1495 return; | |
| 1496 } | |
| 225 | 1497 |
| 471 | 1498 |
| 225 | 1499 /* Determine Y maxima */ |
| 1500 miny = vy[0]; | |
| 1501 maxy = vy[0]; | |
| 1502 for (i=1; (i < n); i++) | |
| 1503 { | |
|
794
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
1504 miny = MIN(miny, vy[i]); |
|
1633c4302f48
Some code cleanups from Marcus von Appen. min->MIN, indentation, other.
Rene Dudfield <renesd@gmail.com>
parents:
652
diff
changeset
|
1505 maxy = MAX(maxy, vy[i]); |
| 225 | 1506 } |
| 471 | 1507 |
| 225 | 1508 /* Draw, scanning y */ |
| 1509 for(y=miny; (y <= maxy); y++) { | |
| 1510 ints = 0; | |
| 1511 for (i=0; (i < n); i++) { | |
| 1512 if (!i) { | |
| 1513 ind1 = n-1; | |
| 1514 ind2 = 0; | |
| 1515 } else { | |
| 1516 ind1 = i-1; | |
| 1517 ind2 = i; | |
| 1518 } | |
| 1519 y1 = vy[ind1]; | |
| 1520 y2 = vy[ind2]; | |
| 1521 if (y1 < y2) { | |
| 1522 x1 = vx[ind1]; | |
| 1523 x2 = vx[ind2]; | |
| 1524 } else if (y1 > y2) { | |
| 1525 y2 = vy[ind1]; | |
| 1526 y1 = vy[ind2]; | |
| 1527 x2 = vx[ind1]; | |
| 1528 x1 = vx[ind2]; | |
| 1529 } else { | |
| 1530 continue; | |
| 1531 } | |
| 1532 if ((y >= y1) && (y < y2)) { | |
| 1533 polyints[ints++] = (y-y1) * (x2-x1) / (y2-y1) + x1; | |
| 1534 } else if ((y == maxy) && (y > y1) && (y <= y2)) { | |
| 1535 polyints[ints++] = (y-y1) * (x2-x1) / (y2-y1) + x1; | |
| 1536 } | |
| 1537 } | |
| 1538 qsort(polyints, ints, sizeof(int), compare_int); | |
| 471 | 1539 |
| 225 | 1540 for (i=0; (i<ints); i+=2) { |
| 1541 drawhorzlineclip(dst, color, polyints[i], y, polyints[i+1]); | |
| 1542 } | |
| 1543 } | |
| 553 | 1544 PyMem_Free(polyints); |
| 225 | 1545 } |
| 1546 | |
| 1547 | |
| 1548 | |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1549 static PyMethodDef _draw_methods[] = |
| 85 | 1550 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1551 { "aaline", aaline, METH_VARARGS, DOC_PYGAMEDRAWAALINE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1552 { "line", line, METH_VARARGS, DOC_PYGAMEDRAWLINE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1553 { "aalines", aalines, METH_VARARGS, DOC_PYGAMEDRAWAALINES }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1554 { "lines", lines, METH_VARARGS, DOC_PYGAMEDRAWLINES }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1555 { "ellipse", ellipse, METH_VARARGS, DOC_PYGAMEDRAWELLIPSE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1556 { "arc", arc, METH_VARARGS, DOC_PYGAMEDRAWARC }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1557 { "circle", circle, METH_VARARGS, DOC_PYGAMEDRAWCIRCLE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1558 { "polygon", polygon, METH_VARARGS, DOC_PYGAMEDRAWPOLYGON }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
1559 { "rect", rect, METH_VARARGS, DOC_PYGAMEDRAWRECT }, |
| 225 | 1560 |
|
798
05346fb84a05
Some cleanups from Marcus to stop compiler warnings.
Rene Dudfield <renesd@gmail.com>
parents:
794
diff
changeset
|
1561 { NULL, NULL, 0, NULL } |
| 85 | 1562 }; |
| 1563 | |
| 1564 | |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1565 MODINIT_DEFINE (draw) |
| 85 | 1566 { |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1567 PyObject *module; |
| 85 | 1568 |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1569 #if PY3 |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1570 static struct PyModuleDef _module = { |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1571 PyModuleDef_HEAD_INIT, |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1572 "draw", |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1573 DOC_PYGAMEDRAW, |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1574 -1, |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1575 _draw_methods, |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1576 NULL, NULL, NULL, NULL |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1577 }; |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1578 #endif |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1579 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1580 /* imported needed apis; Do this first so if there is an error |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1581 the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1582 */ |
| 85 | 1583 import_pygame_base(); |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1584 if (PyErr_Occurred ()) { |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1585 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1586 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1587 import_pygame_color(); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1588 if (PyErr_Occurred ()) { |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1589 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1590 } |
| 85 | 1591 import_pygame_rect(); |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1592 if (PyErr_Occurred ()) { |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1593 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1594 } |
| 85 | 1595 import_pygame_surface(); |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1596 if (PyErr_Occurred ()) { |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1597 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1598 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1599 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1340
diff
changeset
|
1600 /* create the module */ |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1601 #if PY3 |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1602 module = PyModule_Create (&_module); |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1603 #else |
| 1583 | 1604 module = Py_InitModule3(MODPREFIX "draw", _draw_methods, DOC_PYGAMEDRAW); |
|
1563
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1605 #endif |
|
87155b4a2d4c
fix font.c problem with Python 3.1
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1606 MODINIT_RETURN (module); |
| 85 | 1607 } |
| 1608 | |
| 93 | 1609 |
