Hi,
I have a GUI of 9 buttons that may overlap. Their size is based on sprites representing a list box item/ saved game name:

but of course, in terms of buttons, that'd look like something like this:

I have this code from Feria for checking on an individual button (provided it's on top in zorder) whether you're clicking text or a transparent part
Code: ags
but then I'm not sure how to go about checking when it's transparent to go to the next button and do a check there. I tried bringing the next button ID to front and repeating that check, but wasn't working.
Code: ags
Thanks!
I have a GUI of 9 buttons that may overlap. Their size is based on sprites representing a list box item/ saved game name:

but of course, in terms of buttons, that'd look like something like this:

I have this code from Feria for checking on an individual button (provided it's on top in zorder) whether you're clicking text or a transparent part
bool MouseOverPixelPerfect(this Button*)
{
// Calculate mouse coordinates relative to button sprite canvas
int x = mouse.x - this.X - this.OwningGUI.X;
int y = mouse.y - this.Y - this.OwningGUI.Y;
// Get the color on button sprite canvas at mouse cursor pixel
DynamicSprite* buttonMask = DynamicSprite.CreateFromExistingSprite(this.NormalGraphic, false);
DrawingSurface* maskSurface = buttonMask.GetDrawingSurface();
int pixelColor = maskSurface.GetPixel(x,y);
maskSurface.Release();
buttonMask.Delete();
if (pixelColor == COLOR_TRANSPARENT) // if this doesn't work then try your harcoded number, 63519
{
Display("Transparent");
return false;
}
Display("Not transparent");
return true;
}
but then I'm not sure how to go about checking when it's transparent to go to the next button and do a check there. I tried bringing the next button ID to front and repeating that check, but wasn't working.
if(pixelColor == COLOR_TRANSPARENT) // if this doesn't work then try your harcoded number, 63519
{
Display("Transparent on the first layer..");
gGui1.Controls[this.ID+1].AsButton.BringToFront(); // bring the next Button to the front...
DynamicSprite* buttonMask2 = DynamicSprite.CreateFromExistingSprite(gGui1.Controls[this.ID+1].AsButton.NormalGraphic, false);
Display("%d",gGui1.Controls[this.ID+1].AsButton.NormalGraphic);
DrawingSurface* maskSurface2 = buttonMask2.GetDrawingSurface();
int pixelColor2 = maskSurface2.GetPixel(x,y);
maskSurface2.Release();
buttonMask2.Delete();
Display("%d",pixelColor2);
if(pixelColor2 == COLOR_TRANSPARENT) // if this doesn't work then try your harcoded number, 63519
{
Display("I am transparent on the second layer");
} else {
//Text found, do whatever
}
}
Thanks!