Mercurial > hg > dmlib
annotate src/dmdrawline.h @ 2278:40ccc09f09be
Implement empty channel removal in xm2jss and make JSSMOD format support
channel remapping for this.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 18 Jun 2019 12:12:51 +0300 |
parents | e06abfde6c39 |
children |
rev | line source |
---|---|
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
1 /* |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
2 * DMLib |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
3 * -- Simple Bresenham's style line drawing |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
4 * Programmed and designed by Matti 'ccr' Hamalainen |
863 | 5 * (C) Copyright 2011-2015 Tecnic Software productions (TNSP) |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
6 */ |
0 | 7 |
265
51ba74f7668c
Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
8 int DM_DRAWLINE_NAME (SDL_Surface *screen, DMFloat fx0, DMFloat fy0, DMFloat fx1, DMFloat fy1, const Uint32 col |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
9 #ifdef DM_DRAWLINE_ARGS |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
10 DM_DRAWLINE_ARGS |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
11 #endif |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
12 ) |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
13 #ifdef DM_HEADER |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
14 ; |
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
15 #else |
0 | 16 { |
17 int dx, dy, xstep, ystep; | |
18 const int qpitch = screen->pitch / DM_DRAWLINE_DST_BYTES; | |
758 | 19 (void) qpitch; |
20 (void) col; | |
0 | 21 |
22 // Clipping | |
265
51ba74f7668c
Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
23 if (dmClipLineCoordsFloat(screen, &fx0, &fy0, &fx1, &fy1) < 0) |
0 | 24 return -1; |
25 | |
265
51ba74f7668c
Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
26 int x0 = fx0, y0 = fy0, x1 = fx1, y1 = fy1; |
51ba74f7668c
Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
27 |
0 | 28 // Compute initial deltas |
29 dx = (x1 - x0) * 2; | |
30 dy = (y1 - y0) * 2; | |
31 | |
133
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
32 |
0 | 33 if (dx < 0) |
34 { | |
35 dx = -dx; | |
36 xstep = -1; | |
37 } | |
38 else | |
39 xstep = 1; | |
40 | |
41 if (dy < 0) | |
42 { | |
43 dy = -dy; | |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
44 ystep = -1; |
0 | 45 } |
46 else | |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
47 ystep = 1; |
0 | 48 |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
49 #ifndef DM_DRAWLINE_SPEC |
0 | 50 // Compute offsets |
51 y0 *= qpitch; | |
52 y1 *= qpitch; | |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
53 ystep *= qpitch; |
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
54 #endif |
0 | 55 |
133
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
56 #ifdef DM_DRAWLINE_INIT |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
57 DM_DRAWLINE_INIT |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
58 #endif |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
59 |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
60 DM_DRAWLINE_DST_TYPE *pix = (DM_DRAWLINE_DST_TYPE *) screen->pixels; |
758 | 61 (void) pix; |
0 | 62 |
63 // Continue based on which delta is larger | |
64 if (dx > dy) | |
65 { | |
265
51ba74f7668c
Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
66 int afrac = dy - (dx / 2.0); |
0 | 67 while (x0 != x1) |
68 { | |
69 if (afrac >= 0) | |
70 { | |
71 y0 += ystep; | |
72 afrac -= dx; | |
73 } | |
74 | |
75 x0 += xstep; | |
76 afrac += dy; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
863
diff
changeset
|
77 |
0 | 78 DM_DRAWLINE_INNER |
79 } | |
80 } | |
81 else | |
82 { | |
265
51ba74f7668c
Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
83 int afrac = dx - (dy / 2.0); |
0 | 84 while (y0 != y1) |
85 { | |
86 if (afrac >= 0) | |
87 { | |
88 x0 += xstep; | |
89 afrac -= dy; | |
90 } | |
91 | |
92 y0 += ystep; | |
93 afrac += dx; | |
94 | |
95 DM_DRAWLINE_INNER | |
96 } | |
97 } | |
98 | |
99 return 0; | |
100 } | |
232
79dac918c81e
Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
101 #endif |
0 | 102 |
103 #undef DM_DRAWLINE_NAME | |
234
a2abd0b991b6
Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
104 #undef DM_DRAWLINE_ARGS |
0 | 105 #undef DM_DRAWLINE_DST_BYTES |
106 #undef DM_DRAWLINE_DST_TYPE | |
133
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
107 #undef DM_DRAWLINE_INIT |
92cc5e1fa180
Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
108 #undef DM_DRAWLINE_INNER |