Highly unstable and in no way bulletproof! (It works only with the right sized bmap. But it should give you a start)
// Compares two VECTORS
// v1 = Vector 1
// v2 = Vector 2
// returns: 1 if vectors match, otherwise 0
var VecCompare(VECTOR* v1, VECTOR* v2)
{
if(v1.x == v2.x && v1.z == v2.z && v1.z == v2.z)
return(1);
else
return(0);
}
VECTOR gvBmapSelectionColor;
void BmapMagicWandExFill(BMAP* bmp, vPosX, vPosY, VECTOR* vFillColor, VECTOR* vSelectionColor)
{
if(vPosX < 0)return;
if(vPosX > bmap_width(bmp)-1)return;
if(vPosY < 0)return;
if(vPosY > bmap_height(bmp)-1)return;
var vAlpha;
VECTOR vColor;
var format = bmap_lock(bmp, 0);
var pixel = pixel_for_bmap(bmp, vPosX, vPosY);
pixel_to_vec(vColor, vAlpha, format, pixel);
if(VecCompare(vColor, vSelectionColor))
{
pixel = pixel_for_vec(vFillColor, 100, format);
pixel_to_bmap(bmp, vPosX, vPosY, pixel);
BmapMagicWandExFill(bmp, vPosX-1, vPosY, vFillColor, vSelectionColor);
BmapMagicWandExFill(bmp, vPosX+1, vPosY, vFillColor, vSelectionColor);
BmapMagicWandExFill(bmp, vPosX, vPosY-1, vFillColor, vSelectionColor);
BmapMagicWandExFill(bmp, vPosX, vPosY+1, vFillColor, vSelectionColor);
}
bmap_unlock(bmp);
}
// Magic Wand Fill tool - does a magic wand selection and fills it with vFillColor
// bmp = pointer to bitmap
// vPosX = x position of the selection point
// vPosY = y position of the selection point
// vFillColor = BGR fill color
void BmapMagicWandFill(BMAP* bmp, vPosX, vPosY, VECTOR* vFillColor)
{
var vAlpha;
var format = bmap_lock(bmp, 0);
var pixel = pixel_for_bmap(bmp, vPosX, vPosY);
pixel_to_vec(gvBmapSelectionColor, vAlpha, format, pixel);
bmap_unlock(bmp);
BmapMagicWandExFill(bmp, vPosX, vPosY, vFillColor, gvBmapSelectionColor);
}