Mercurial > hg > dmlib
annotate dmdrawline.h @ 100:f16d102dbbac
Add a function for setting bitmapped font palette.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Oct 2012 20:33:01 +0300 |
parents | 997e26f17946 |
children | 92cc5e1fa180 |
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 | |
8 if (dmClipLineCoords(&x0, &y0, &x1, &y1, screen)) | |
9 return -1; | |
10 | |
11 // Compute initial deltas | |
12 dx = (x1 - x0) * 2; | |
13 dy = (y1 - y0) * 2; | |
14 | |
15 if (dx < 0) | |
16 { | |
17 dx = -dx; | |
18 xstep = -1; | |
19 } | |
20 else | |
21 xstep = 1; | |
22 | |
23 if (dy < 0) | |
24 { | |
25 dy = -dy; | |
26 ystep = -qpitch; | |
27 } | |
28 else | |
29 ystep = qpitch; | |
30 | |
31 // Compute offsets | |
32 y0 *= qpitch; | |
33 y1 *= qpitch; | |
34 | |
35 DM_DRAWLINE_DST_TYPE *pix = screen->pixels; | |
36 | |
37 // Continue based on which delta is larger | |
38 if (dx > dy) | |
39 { | |
40 int afrac = dy - (dx / 2); | |
41 while (x0 != x1) | |
42 { | |
43 if (afrac >= 0) | |
44 { | |
45 y0 += ystep; | |
46 afrac -= dx; | |
47 } | |
48 | |
49 x0 += xstep; | |
50 afrac += dy; | |
51 | |
52 DM_DRAWLINE_INNER | |
53 } | |
54 } | |
55 else | |
56 { | |
57 int afrac = dx - (dy / 2); | |
58 while (y0 != y1) | |
59 { | |
60 if (afrac >= 0) | |
61 { | |
62 x0 += xstep; | |
63 afrac -= dy; | |
64 } | |
65 | |
66 y0 += ystep; | |
67 afrac += dx; | |
68 | |
69 DM_DRAWLINE_INNER | |
70 } | |
71 } | |
72 | |
73 return 0; | |
74 } | |
75 | |
76 #undef DM_DRAWLINE_NAME | |
77 #undef DM_DRAWLINE_DST_BYTES | |
78 #undef DM_DRAWLINE_DST_TYPE |