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 },
|
|
50 /* DMD_TRANSPARENT */ { dmDrawLine8Transparent , dmDrawLine32Transparent },
|
|
51 /* DMD_SATURATE */ { dmDrawLine8Saturate , dmDrawLine32Saturate },
|
|
52 /* DMD_NONE + AA */ { NULL, NULL },
|
|
53 /* DMD_TRANSP + AA */ { NULL, NULL },
|
|
54 /* DMD_SATURATE + AA */ { dmDrawLine8AASaturate , dmDrawLine32AASaturate },
|
|
55 };
|
|
56
|
|
57
|
|
58 DMDrawLineFunc dmGetDrawLineFunc(SDL_PixelFormat *dst, int mode)
|
|
59 {
|
|
60 int index;
|
|
61 if (dst == NULL || mode < 0 ||
|
|
62 mode >= sizeof(dmDrawLineTable) / sizeof(dmDrawLineTable[0]))
|
|
63 return NULL;
|
|
64
|
|
65 if ((index = dmBitsPerPixel2Index(src->BitsPerPixel)) < 0)
|
|
66 return NULL;
|
|
67
|
|
68 return dmDrawLineTable[mode]
|
|
69 }
|
|
70
|
|
71
|
|
72 int dmDrawLineAny(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col, int mode)
|
|
73 {
|
|
74 DMDrawLineFunc bfunc = dmGetDrawLineFunc(screen->format, mode);
|
|
75
|
|
76 if (bfunc == NULL)
|
|
77 return -15;
|
|
78
|
|
79 return bfunc(screen, x0, y0, x1, y1, col);
|
|
80 }
|
|
81
|