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,22 +1069,23 @@ 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;
unsigned char *bitmap = cBrush->GetBitmap(); radiusY = cBrush->GetRadius().Y;
for (j=-ry; j<=ry; j++)
for (i=-rx; i<=rx; i++) sizeX = cBrush->GetSize().X;
if(bitmap[(j+ry)*((rx*2)+1)+(i+rx+1)]) sizeY = cBrush->GetSize().Y;
{ unsigned char *bitmap = cBrush->GetBitmap();
if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) for(int y = 0; y < sizeY; y++)
continue; for(int x = 0; x < sizeX; x++)
Tool(x+i, y+j, tool, strength); 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);
}
} }
void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength) void Simulation::ToolLine(int x1, int y1, int x2, int y2, int tool, Brush * cBrush, float strength)