annotate dmdrawline.h @ 570:a26636faa6b7

Update copyright.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 05 Jan 2013 19:58:23 +0200
parents 51ba74f7668c
children cf7612c8de1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
5 * (C) Copyright 2011-2012 Tecnic Software productions (TNSP)
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
6 */
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 int dx, dy, xstep, ystep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 const int qpitch = screen->pitch / DM_DRAWLINE_DST_BYTES;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 // Clipping
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
21 if (dmClipLineCoordsFloat(screen, &fx0, &fy0, &fx1, &fy1) < 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 return -1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
24 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
25
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 // Compute initial deltas
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 dx = (x1 - x0) * 2;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 dy = (y1 - y0) * 2;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
133
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
30
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 if (dx < 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 dx = -dx;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 xstep = -1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 xstep = 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 if (dy < 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 dy = -dy;
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
42 ystep = -1;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 else
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
45 ystep = 1;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
47 #ifndef DM_DRAWLINE_SPEC
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 // Compute offsets
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 y0 *= qpitch;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 y1 *= qpitch;
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
51 ystep *= qpitch;
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
52 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
133
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
54 #ifdef DM_DRAWLINE_INIT
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
55 DM_DRAWLINE_INIT
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
56 #endif
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
57
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
58 DM_DRAWLINE_DST_TYPE *pix = (DM_DRAWLINE_DST_TYPE *) screen->pixels;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 // Continue based on which delta is larger
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 if (dx > dy)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
63 int afrac = dy - (dx / 2.0);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 while (x0 != x1)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 if (afrac >= 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 y0 += ystep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 afrac -= dx;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 x0 += xstep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 afrac += dy;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 DM_DRAWLINE_INNER
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 {
265
51ba74f7668c Make line clipping floating point only.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
80 int afrac = dx - (dy / 2.0);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 while (y0 != y1)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 if (afrac >= 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 x0 += xstep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 afrac -= dy;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 y0 += ystep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 afrac += dx;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 DM_DRAWLINE_INNER
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
98 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 #undef DM_DRAWLINE_NAME
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
101 #undef DM_DRAWLINE_ARGS
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 #undef DM_DRAWLINE_DST_BYTES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 #undef DM_DRAWLINE_DST_TYPE
133
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
104 #undef DM_DRAWLINE_INIT
92cc5e1fa180 Some work on line drawing routines.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
105 #undef DM_DRAWLINE_INNER