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