Mercurial > hg > dmlib
diff dmline.c @ 0:32250b436bca
Initial re-import.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Sep 2012 01:54:23 +0300 |
parents | |
children | 997e26f17946 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmline.c Fri Sep 28 01:54:23 2012 +0300 @@ -0,0 +1,81 @@ +/* + * DMLib + * -- Arbitrary line drawing functions + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2011 Tecnic Software productions (TNSP) + */ +#include "dmlib.h" + + +/* Clip line coordinates. Return value: + * = 0 : No clipping needed. + * > 0 : Clipped. Line partially inside the clipping area. + * < 0 : Line completely outside the clipping area. + */ +int dmClipLineCoords(int *x0, int *y0, int *x1, int *y1, SDL_Surface *screen) +{ +#if 0 + const int clipX0 = screen->clip_rect.x, + clipY0 = screen->clip_rect.y; + const int clipX1 = clipX0 + screen->clip_rect.w - 1, + clipY1 = clipY0 + screen->clip_rect.h - 1; + const int dx = *x1 - *x0, + dy = *y1 - *y0; + DMFixedPoint k, kdx, kdy; + + // Is line completely outside the clipping area? + if ((*x0 < clipX0 && *x1 < clipX0) || (*x0 > clipX1 && *x1 > clipX1) || + (*y0 < clipY0 && *y1 < clipY0) || (*y0 > clipY1 && *y1 > clipY1)) + return -1; + + FP_SETHL(kdx, dx); + FP_SETHL(kdy, dy); +#endif + + return 0; +} + + +int dmTestLineCoords(int x0, int y0, int x1, int y1, SDL_Surface *screen) +{ + return dmClipLineCoords(&x0, &y0, &x1, &y1, screen); +} + + +#include "dmlinefunc.h" + +static const DMDrawLineFunc dmDrawLineTable[DMD_NMODES][DMD_NBITDEPTHS] = +{ + /* DMD_NONE */ { dmDrawLine8 , dmDrawLine32 }, + /* DMD_TRANSPARENT */ { dmDrawLine8Transparent , dmDrawLine32Transparent }, + /* DMD_SATURATE */ { dmDrawLine8Saturate , dmDrawLine32Saturate }, + /* DMD_NONE + AA */ { NULL, NULL }, + /* DMD_TRANSP + AA */ { NULL, NULL }, + /* DMD_SATURATE + AA */ { dmDrawLine8AASaturate , dmDrawLine32AASaturate }, +}; + + +DMDrawLineFunc dmGetDrawLineFunc(SDL_PixelFormat *dst, int mode) +{ + int index; + if (dst == NULL || mode < 0 || + mode >= sizeof(dmDrawLineTable) / sizeof(dmDrawLineTable[0])) + return NULL; + + if ((index = dmBitsPerPixel2Index(src->BitsPerPixel)) < 0) + return NULL; + + return dmDrawLineTable[mode] +} + + +int dmDrawLineAny(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col, int mode) +{ + DMDrawLineFunc bfunc = dmGetDrawLineFunc(screen->format, mode); + + if (bfunc == NULL) + return -15; + + return bfunc(screen, x0, y0, x1, y1, col); +} +