PDA

View Full Version : Detect Click on Image



cairnswm
05-02-2003, 07:03 AM
I have an image (stored in a TDXImageList) that is displayed on the screen over my Map. This image is used to display the game state (selected units, orders, small map etc).

When the mouse is clicked on the screen how do I know if the mouse was clicked over a non-transparent portion of this image?

I have the Top,Left of the Image and the X,Y of the click, how do I know if the pixel of the image at that X,Y is transparent?

I need this to know when to pass the click through to the Map component of capture it in the game state component.

TheLion
05-02-2003, 09:44 PM
There are two solutions I know for your problem. The first is with a mask (monochrome bitmap black&white) where you can check the transparent and non-transparent areas and check whether the mouse clicked a transparent or non-transparent pixel. This can also be done with a pixel-perfect collision table/array.

The second method is to use the pixel array (not sure if you can access that easily from DelphiX's DXImageList, but I think it's possible) and to check wheter the pixel that the mouse clicked on has the same colour as the transparent color if so then the user clicked on a transparent pixel otherwise the user clicked on a non-transparent pixel! :)