changeset 234:a2abd0b991b6

Modularize line drawing related templates and functions, add clipping functions to dmlib.h.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 08 Oct 2012 15:21:59 +0300
parents e3c1aa3ba88e
children 4a672d96978f
files dmdrawline.h dmlib.h dmline.c dmlineclip.h
diffstat 4 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/dmdrawline.h	Mon Oct 08 09:01:16 2012 +0300
+++ b/dmdrawline.h	Mon Oct 08 15:21:59 2012 +0300
@@ -5,7 +5,11 @@
  * (C) Copyright 2011-2012 Tecnic Software productions (TNSP)
  */
 
-int DM_DRAWLINE_NAME (SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col)
+int DM_DRAWLINE_NAME (SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col
+#ifdef DM_DRAWLINE_ARGS
+    DM_DRAWLINE_ARGS
+#endif
+)
 #ifdef DM_HEADER
 ;
 #else
@@ -14,7 +18,7 @@
     const int qpitch = screen->pitch / DM_DRAWLINE_DST_BYTES;
 
     // Clipping
-    if (dmClipLineCoordsInt(&x0, &y0, &x1, &y1, screen) < 0)
+    if (dmClipLineCoordsInt(screen, &x0, &y0, &x1, &y1) < 0)
         return -1;
 
     // Compute initial deltas
@@ -33,14 +37,17 @@
     if (dy < 0)
     {
         dy = -dy;
-        ystep = -qpitch;
+        ystep = -1;
     }
     else
-        ystep = qpitch;
+        ystep = 1;
 
+#ifndef DM_DRAWLINE_SPEC
     // Compute offsets
     y0 *= qpitch;
     y1 *= qpitch;
+    ystep *= qpitch;
+#endif
 
 #ifdef DM_DRAWLINE_INIT
     DM_DRAWLINE_INIT
@@ -89,6 +96,7 @@
 #endif
 
 #undef DM_DRAWLINE_NAME
+#undef DM_DRAWLINE_ARGS
 #undef DM_DRAWLINE_DST_BYTES
 #undef DM_DRAWLINE_DST_TYPE
 #undef DM_DRAWLINE_INIT
--- a/dmlib.h	Mon Oct 08 09:01:16 2012 +0300
+++ b/dmlib.h	Mon Oct 08 15:21:59 2012 +0300
@@ -272,6 +272,15 @@
 #ifdef DM_GFX_LINES
 #define DM_HEADER
 #include "dmlinefunc.h"
+
+#define DM_CLIP_FUNC dmClipLineCoordsInt
+#define DM_COORD_TYPE int
+#include "dmlineclip.h"
+
+#define DM_CLIP_FUNC dmClipLineCoordsFloat
+#define DM_COORD_TYPE DMFloat
+#include "dmlineclip.h"
+
 #undef DM_HEADER
 #endif
 
--- a/dmline.c	Mon Oct 08 09:01:16 2012 +0300
+++ b/dmline.c	Mon Oct 08 15:21:59 2012 +0300
@@ -32,7 +32,7 @@
 #include "dmlineclip.h"
 
 #define DM_CLIP_FUNC dmClipLineCoordsFloat
-#define DM_COORD_TYPE float
+#define DM_COORD_TYPE DMFloat
 #include "dmlineclip.h"
 
 
--- a/dmlineclip.h	Mon Oct 08 09:01:16 2012 +0300
+++ b/dmlineclip.h	Mon Oct 08 15:21:59 2012 +0300
@@ -1,5 +1,8 @@
 
-int DM_CLIP_FUNC (DM_COORD_TYPE *x0, DM_COORD_TYPE *y0, DM_COORD_TYPE *x1, DM_COORD_TYPE *y1, SDL_Surface *screen)
+int DM_CLIP_FUNC (SDL_Surface *screen, DM_COORD_TYPE *x0, DM_COORD_TYPE *y0, DM_COORD_TYPE *x1, DM_COORD_TYPE *y1)
+#ifdef DM_HEADER
+;
+#else
 {
     const DM_COORD_TYPE
         clipX0 = screen->clip_rect.x,
@@ -231,6 +234,7 @@
 
     return 1;
 }
+#endif
 
 #undef DM_CLIP_FUNC
 #undef DM_COORD_TYPE