diff --git a/includes/defines.h b/includes/defines.h index 2c5774cd5..560f2a58b 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -85,7 +85,9 @@ extern unsigned char ZSIZE; #define CIRCLE_BRUSH 0 #define SQUARE_BRUSH 1 -#define BRUSH_NUM 2 +#define TRI_BRUSH 2 +#define BRUSH_NUM 3 + //#define LUACONSOLE //#define PYCONSOLE diff --git a/includes/powder.h b/includes/powder.h index ed52d158d..5ceebb2c7 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -969,6 +969,8 @@ void detach(int i); void part_change_type(int i, int x, int y, int t); +int InCurrentBrush(int i, int j, int rx, int ry); + int create_part(int p, int x, int y, int t); void delete_part(int x, int y); diff --git a/src/graphics.c b/src/graphics.c index 9dd10dda7..2013de604 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -3567,7 +3567,7 @@ void create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int c for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) if(y+j>=0 && x+i>=0 && x+i>8)>=NPART || !rp) continue; @@ -4235,6 +4235,7 @@ void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry) } } else if (CURRENT_BRUSH==CIRCLE_BRUSH) + { for (j=0; j<=ry; j++) for (i=0; i<=rx; i++) if ((pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1 && ((pow(i+1,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))>1 || (pow(i,2))/(pow(rx,2))+(pow(j+1,2))/(pow(ry,2))>1)) @@ -4244,6 +4245,17 @@ void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry) if (i) xor_pixel(x-i, y+j, vid); if (i&&j) xor_pixel(x-i, y-j, vid); } + } + else if (CURRENT_BRUSH==TRI_BRUSH) + { + for (j=-ry; j<=ry; j++) + for (i=-rx; i<=rx; i++) + if ((j <= ry ) && ( j >= (((-2.0*ry)/rx)*i) -ry) && ( j >= (((-2.0*ry)/(-rx))*i)-ry ) && (j+1>ry || (j-1 < (((-2.0*ry)/rx)*i) -ry) || ( j-1 < (((-2.0*ry)/(-rx))*i)-ry )) ) + { + xor_pixel(x+i, y+j, vid); + } + } + } else //wall cursor { diff --git a/src/powder.c b/src/powder.c index 853914d62..6bce79055 100644 --- a/src/powder.c +++ b/src/powder.c @@ -2687,7 +2687,7 @@ int create_parts(int x, int y, int rx, int ry, int c) else for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) - if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + if (InCurrentBrush(i ,j ,rx ,ry)) delete_part(x+i, y+j); return 1; } @@ -2702,7 +2702,7 @@ int create_parts(int x, int y, int rx, int ry, int c) else for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) - if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + if (InCurrentBrush(i ,j ,rx ,ry)) { if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) continue; @@ -2726,7 +2726,7 @@ int create_parts(int x, int y, int rx, int ry, int c) else for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) - if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + if (InCurrentBrush(i ,j ,rx ,ry)) delete_part(x+i, y+j); SLALT = stemp; return 1; @@ -2748,7 +2748,7 @@ int create_parts(int x, int y, int rx, int ry, int c) else for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) - if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + if (InCurrentBrush(i ,j ,rx ,ry)) { if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) continue; @@ -2773,12 +2773,26 @@ int create_parts(int x, int y, int rx, int ry, int c) else for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) - if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + if (InCurrentBrush(i ,j ,rx ,ry)) if (create_part(-2, x+i, y+j, c)==-1) f = 1; return !f; } - +int InCurrentBrush(int i, int j, int rx, int ry) +{ + switch(CURRENT_BRUSH) + { + case CIRCLE_BRUSH: + return ((pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1); + break; + case SQUARE_BRUSH: + return (i*j<=ry*rx); + break; + case TRI_BRUSH: + return (j <= ry ) && ( j >= (((-2.0*ry)/rx)*i) -ry) && ( j >= (((-2.0*ry)/(-rx))*i)-ry ) ; + break; + } +} void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c) { int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;