fixup "Make round pens"
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 26 Apr 2015 10:14:26 +0000 (12:14 +0200)
committerroot <root@dion.jolly.ten>
Thu, 14 May 2015 19:09:01 +0000 (21:09 +0200)
gui/image.c

index b21fd0e..164fa61 100644 (file)
@@ -432,20 +432,25 @@ void paint_brush(int x, int y, int size, int paint)
        int x2 = x + size - 1;
        int y1 = y - size + 1;
        int y2 = y + size - 1;
-       int i, j;
+       int clipx = 0, clipy = 0, stride;
+       int i, j, jj;
 
        if (x1 >= img_width)
                return;
-       if (x1 < 0)
+       if (x1 < 0) {
+               clipx = -x1;
                x1 = 0;
+       }
        if (x2 >= img_width)
                x2 = img_width - 1;
        if (x2 < 0)
                return;
        if (y1 >= img_height)
                return;
-       if (y1 < 0)
+       if (y1 < 0) {
+               clipy = -y1;
                y1 = 0;
+       }
        if (y2 >= img_height)
                y2 = img_height - 1;
        if (y2 < 0)
@@ -455,12 +460,14 @@ void paint_brush(int x, int y, int size, int paint)
        if (paint)
                paint = mark_selected + 1;
 
-       mask = brushs[size];
+       stride = size + size - 1;
+       mask = brushs[size] + stride * clipy + clipx;
        for (i = y1; i <= y2; i++) {
-               for (j = x1; j <= x2; j++) {
-                       if (*mask++ == '#')
+               for (j = x1, jj = 0; j <= x2; j++, jj++) {
+                       if (mask[jj] == '#')
                                img_mark_buffer[j+img_width*i] = paint;
                }
+               mask += stride;
        }
 }