30 |
|
|
31 |
#include "pgdraw.h" |
#include "pgdraw.h" |
32 |
|
|
33 |
void plotpixel(SDL_Surface* surface, Uint32 x, Uint32 y, const SDL_Color& c, Uint8 width, int *pixelflag) { |
void plotpixel(SDL_Surface* surface, Uint32 x, Uint32 y, const PG_Color& c, Uint8 width, int *pixelflag) { |
34 |
Uint32 xp, yp, xf, yf; |
Uint32 xp, yp, xf, yf; |
35 |
static Uint32 oldx, oldy; |
static Uint32 oldx, oldy; |
36 |
|
|
39 |
|
|
40 |
// width=1? Only need to draw 1 pixel |
// width=1? Only need to draw 1 pixel |
41 |
if(width==1) { |
if(width==1) { |
42 |
PG_Draw::SetPixel(x, y, c.r, c.g, c.b, surface); |
PG_Draw::SetPixel(x, y, c, surface); |
43 |
} else { |
} else { |
44 |
|
|
45 |
// calculate new pixel position (shifts are faster) |
// calculate new pixel position (shifts are faster) |
54 |
// draw all pixels needed |
// draw all pixels needed |
55 |
for (xf=0; xf<width; xf++) { |
for (xf=0; xf<width; xf++) { |
56 |
for (yf=0; yf<width; yf++) { |
for (yf=0; yf<width; yf++) { |
57 |
PG_Draw::SetPixel(xf+xp, yf+yp, c.r, c.g, c.b, surface); |
PG_Draw::SetPixel(xf+xp, yf+yp, c, surface); |
58 |
} |
} |
59 |
} |
} |
60 |
} |
} |
67 |
|
|
68 |
// only need to draw the bottom pixels |
// only need to draw the bottom pixels |
69 |
for (xf=0; xf<width; xf++) { |
for (xf=0; xf<width; xf++) { |
70 |
PG_Draw::SetPixel(xf+xp, yp-1+(width-1), c.r, c.g, c.b, surface); |
PG_Draw::SetPixel(xf+xp, yp-1+(width-1), c, surface); |
71 |
} |
} |
72 |
} |
} |
73 |
|
|
75 |
if (xp>oldx) { |
if (xp>oldx) { |
76 |
// only need to draw the most right pixels |
// only need to draw the most right pixels |
77 |
for (yf=0; yf<width; yf++) { |
for (yf=0; yf<width; yf++) { |
78 |
PG_Draw::SetPixel(xp-1+(width-1), yp+yf, c.r, c.g, c.b, surface); |
PG_Draw::SetPixel(xp-1+(width-1), yp+yf, c, surface); |
79 |
} |
} |
80 |
} |
} |
81 |
|
|
84 |
|
|
85 |
// only need to draw the most left pixels |
// only need to draw the most left pixels |
86 |
for (yf=0; yf<width; yf++) { |
for (yf=0; yf<width; yf++) { |
87 |
PG_Draw::SetPixel(xp+1, yp+yf, c.r, c.g, c.b, surface); |
PG_Draw::SetPixel(xp+1, yp+yf, c, surface); |
88 |
} |
} |
89 |
} |
} |
90 |
|
|
96 |
} |
} |
97 |
|
|
98 |
void octant0(SDL_Surface* surface, Uint32 x0, Uint32 y0, Uint32 deltax, Uint32 deltay, |
void octant0(SDL_Surface* surface, Uint32 x0, Uint32 y0, Uint32 deltax, Uint32 deltay, |
99 |
int xdirection, const SDL_Color& color, Uint8 width, int pixelflag) |
int xdirection, const PG_Color& color, Uint8 width, int pixelflag) |
100 |
{ |
{ |
101 |
int deltay2; |
int deltay2; |
102 |
int error; |
int error; |
131 |
} /* end of the function */ |
} /* end of the function */ |
132 |
|
|
133 |
void octant1(SDL_Surface* surface, Uint32 x0, Uint32 y0, Uint32 deltax, Uint32 deltay, |
void octant1(SDL_Surface* surface, Uint32 x0, Uint32 y0, Uint32 deltax, Uint32 deltay, |
134 |
int xdirection, const SDL_Color& color, Uint8 width, int pixelflag) |
int xdirection, const PG_Color& color, Uint8 width, int pixelflag) |
135 |
{ |
{ |
136 |
int deltax2; |
int deltax2; |
137 |
int error; |
int error; |
166 |
|
|
167 |
} /* end of the function */ |
} /* end of the function */ |
168 |
|
|
169 |
void PG_Draw::DrawLine(SDL_Surface* surface, Uint32 x0, Uint32 y0, Uint32 x1, Uint32 y1, const SDL_Color& color, Uint8 width) { |
void PG_Draw::DrawLine(SDL_Surface* surface, Uint32 x0, Uint32 y0, Uint32 x1, Uint32 y1, const PG_Color& color, Uint8 width) { |
170 |
int deltax; |
int deltax; |
171 |
int deltay; |
int deltay; |
172 |
int temp; |
int temp; |