Fix Simulation Tool brush issue (misalignment/didn't work with small brushes). Fixes #167

This commit is contained in:
Simon Robertshaw 2012-09-01 17:17:15 +01:00
parent 355c43723f
commit 0a67e560f4

View File

@ -1069,21 +1069,22 @@ int Simulation::Tool(int x, int y, int tool, float strength)
return 0; return 0;
} }
int Simulation::ToolBrush(int x, int y, int tool, Brush * cBrush, float strength) int Simulation::ToolBrush(int positionX, int positionY, int tool, Brush * cBrush, float strength)
{ {
int rx, ry, j, i; if(cBrush)
if(!cBrush) {
return 0; int radiusX, radiusY, sizeX, sizeY;
rx = cBrush->GetRadius().X;
ry = cBrush->GetRadius().Y; radiusX = cBrush->GetRadius().X;
radiusY = cBrush->GetRadius().Y;
sizeX = cBrush->GetSize().X;
sizeY = cBrush->GetSize().Y;
unsigned char *bitmap = cBrush->GetBitmap(); unsigned char *bitmap = cBrush->GetBitmap();
for (j=-ry; j<=ry; j++) for(int y = 0; y < sizeY; y++)
for (i=-rx; i<=rx; i++) for(int x = 0; x < sizeX; x++)
if(bitmap[(j+ry)*((rx*2)+1)+(i+rx+1)]) if(bitmap[(y*sizeX)+x] && (positionX+(x-radiusX) >= 0 && positionY+(y-radiusY) >= 0 && positionX+(x-radiusX) < XRES && positionY+(y-radiusY) < YRES))
{ Tool(positionX+(x-radiusX), positionY+(y-radiusY), tool, strength);
if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES)
continue;
Tool(x+i, y+j, tool, strength);
} }
} }