Mercurial > hg > dmlib
annotate dmline.c @ 60:f28cd66356f6
Initial work for bitmapped fonts and text drawing. Also moved TTF header
stuff to dmtext.h.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 01 Oct 2012 09:46:56 +0300 |
parents | 997e26f17946 |
children | 92cc5e1fa180 |
rev | line source |
---|---|
0 | 1 /* |
2 * DMLib | |
3 * -- Arbitrary line drawing functions | |
4 * Programmed and designed by Matti 'ccr' Hamalainen | |
5 * (C) Copyright 2011 Tecnic Software productions (TNSP) | |
6 */ | |
7 #include "dmlib.h" | |
8 | |
9 | |
10 /* Clip line coordinates. Return value: | |
11 * = 0 : No clipping needed. | |
12 * > 0 : Clipped. Line partially inside the clipping area. | |
13 * < 0 : Line completely outside the clipping area. | |
14 */ | |
15 int dmClipLineCoords(int *x0, int *y0, int *x1, int *y1, SDL_Surface *screen) | |
16 { | |
17 #if 0 | |
18 const int clipX0 = screen->clip_rect.x, | |
19 clipY0 = screen->clip_rect.y; | |
20 const int clipX1 = clipX0 + screen->clip_rect.w - 1, | |
21 clipY1 = clipY0 + screen->clip_rect.h - 1; | |
22 const int dx = *x1 - *x0, | |
23 dy = *y1 - *y0; | |
24 DMFixedPoint k, kdx, kdy; | |
25 | |
26 // Is line completely outside the clipping area? | |
27 if ((*x0 < clipX0 && *x1 < clipX0) || (*x0 > clipX1 && *x1 > clipX1) || | |
28 (*y0 < clipY0 && *y1 < clipY0) || (*y0 > clipY1 && *y1 > clipY1)) | |
29 return -1; | |
30 | |
31 FP_SETHL(kdx, dx); | |
32 FP_SETHL(kdy, dy); | |
33 #endif | |
34 | |
35 return 0; | |
36 } | |
37 | |
38 | |
39 int dmTestLineCoords(int x0, int y0, int x1, int y1, SDL_Surface *screen) | |
40 { | |
41 return dmClipLineCoords(&x0, &y0, &x1, &y1, screen); | |
42 } | |
43 | |
44 | |
45 #include "dmlinefunc.h" | |
46 | |
47 static const DMDrawLineFunc dmDrawLineTable[DMD_NMODES][DMD_NBITDEPTHS] = | |
48 { | |
49 /* DMD_NONE */ { dmDrawLine8 , dmDrawLine32 }, | |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 #if 0 |
0 | 51 /* DMD_TRANSPARENT */ { dmDrawLine8Transparent , dmDrawLine32Transparent }, |
52 /* DMD_SATURATE */ { dmDrawLine8Saturate , dmDrawLine32Saturate }, | |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
53 |
0 | 54 /* DMD_NONE + AA */ { NULL, NULL }, |
55 /* DMD_TRANSP + AA */ { NULL, NULL }, | |
56 /* DMD_SATURATE + AA */ { dmDrawLine8AASaturate , dmDrawLine32AASaturate }, | |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
57 #endif |
0 | 58 }; |
59 | |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
60 static const int ndmDrawLineTable = sizeof(dmDrawLineTable) / sizeof(dmDrawLineTable[0]); |
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
61 |
0 | 62 |
63 DMDrawLineFunc dmGetDrawLineFunc(SDL_PixelFormat *dst, int mode) | |
64 { | |
65 int index; | |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
66 if (dst == NULL || mode < 0 || mode >= ndmDrawLineTable) |
0 | 67 return NULL; |
68 | |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
69 if ((index = dmBitsPerPixel2Index(dst->BitsPerPixel)) < 0) |
0 | 70 return NULL; |
71 | |
22
997e26f17946
Initial fixes for getting the line drawing functions "working".
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
72 return dmDrawLineTable[mode][index]; |
0 | 73 } |
74 | |
75 | |
76 int dmDrawLineAny(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col, int mode) | |
77 { | |
78 DMDrawLineFunc bfunc = dmGetDrawLineFunc(screen->format, mode); | |
79 | |
80 if (bfunc == NULL) | |
81 return -15; | |
82 | |
83 return bfunc(screen, x0, y0, x1, y1, col); | |
84 } |