Mercurial > hg > dmlib
annotate dmdrawline.h @ 133:92cc5e1fa180
Some work on line drawing routines.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 05 Oct 2012 00:36:40 +0300 |
parents | 997e26f17946 |
children | 79dac918c81e |
rev | line source |
---|---|
0 | 1 |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
2 static int DM_DRAWLINE_NAME (SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col) |
0 | 3 { |
4 int dx, dy, xstep, ystep; | |
5 const int qpitch = screen->pitch / DM_DRAWLINE_DST_BYTES; | |
6 | |
7 // Clipping | |
133
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
8 if (dmClipLineCoords(&x0, &y0, &x1, &y1, screen) < 0) |
0 | 9 return -1; |
10 | |
11 // Compute initial deltas | |
12 dx = (x1 - x0) * 2; | |
13 dy = (y1 - y0) * 2; | |
14 | |
133
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
15 |
0 | 16 if (dx < 0) |
17 { | |
18 dx = -dx; | |
19 xstep = -1; | |
20 } | |
21 else | |
22 xstep = 1; | |
23 | |
24 if (dy < 0) | |
25 { | |
26 dy = -dy; | |
27 ystep = -qpitch; | |
28 } | |
29 else | |
30 ystep = qpitch; | |
31 | |
32 // Compute offsets | |
33 y0 *= qpitch; | |
34 y1 *= qpitch; | |
35 | |
133
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
36 #ifdef DM_DRAWLINE_INIT |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
37 DM_DRAWLINE_INIT |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
38 #endif |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
39 |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
40 DM_DRAWLINE_DST_TYPE *pix = (DM_DRAWLINE_DST_TYPE *) screen->pixels; |
0 | 41 |
42 // Continue based on which delta is larger | |
43 if (dx > dy) | |
44 { | |
45 int afrac = dy - (dx / 2); | |
46 while (x0 != x1) | |
47 { | |
48 if (afrac >= 0) | |
49 { | |
50 y0 += ystep; | |
51 afrac -= dx; | |
52 } | |
53 | |
54 x0 += xstep; | |
55 afrac += dy; | |
56 | |
57 DM_DRAWLINE_INNER | |
58 } | |
59 } | |
60 else | |
61 { | |
62 int afrac = dx - (dy / 2); | |
63 while (y0 != y1) | |
64 { | |
65 if (afrac >= 0) | |
66 { | |
67 x0 += xstep; | |
68 afrac -= dy; | |
69 } | |
70 | |
71 y0 += ystep; | |
72 afrac += dx; | |
73 | |
74 DM_DRAWLINE_INNER | |
75 } | |
76 } | |
77 | |
78 return 0; | |
79 } | |
80 | |
81 #undef DM_DRAWLINE_NAME | |
82 #undef DM_DRAWLINE_DST_BYTES | |
83 #undef DM_DRAWLINE_DST_TYPE | |
133
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
84 #undef DM_DRAWLINE_INIT |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
85 #undef DM_DRAWLINE_INNER |