I have four TImages, all same size layered above each other.
The bottom one has a texture atlas loaded as the bitmap and is not transparent.
The top three are transparent with clBlack as the transparent colour.
In the top TImage's (ImageOverlay) MouseDown event I have the following code which is supposed to highlight the individual texture under the mouse pointer with a frame. The frame is to be drawn on the second from top TImage canvas (ImageHilite).
The code only works if I make that TImage not transparent which is no good since the texture atlas bitmap can no longer be seen.
I copied this code from a Delphi program.
I am using Windows 8.1 and CodeTyphon 4.80.
var
wad:TWad;
...
procedure TForm1.ImageOverlayMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i,index:Integer;
br : TRect;
begin
// Nothing to do, exit.
if wad.numTextures = 0 then exit;
// Left button only.
if not ( Button = mbLeft ) then exit;
// Scan the rectangles list to find the one that includes (x,y).
index := -1;
for i := 0 to wad.numTextures - 1 do
begin
if PtInRect( wad.SampleRect[i], Point( X, Y ) ) then
begin index := i; break; end;
end;
// Found?
if index = -1 then begin beep; exit; end;
br := Rect( 0, 0, Form1.ImageHilite.Width, Form1.ImageHilite.Height );
ImageHilite.Canvas.Brush.Style := bsSolid;
ImageHilite.Canvas.Brush.Color := clBlack;
ImageHilite.Canvas.FillRect( br ); //erases old framerect
ImageHilite.Canvas.Brush.Color := clLime;
ImageHilite.Canvas.FrameRect( wad.SampleRect[index] );
end;