Mail Archives: djgpp/1998/04/28/10:18:05
Bengt Rosenberger writes:
> I want to use a button (it's a bitmap(125x75)) in the middle of the
> screen. Now I blit a black/white-bitmap of that button directly
> behind the originally one. When the button is pressed with left
> mouse button I try to check if the color behind is white. I use:
>
> col = getpixel(buttonbw, mouse_x, mouse_y);
> if (col = 255)
> button_pressed();
>
> When the button is pressed in the middle of the screen, the return
> col is -1.
This return value should give you a clue what the problem is. From the
Allegro getpixel() docs:
Returns -1 if the point lies outside the bitmap.
The mouse coordinates are an absolute screen position, but from your
description, it sounds like your buttonbw image is being plotted to
some offset into the screen, not the top left corner. This means that
you can't use these screen-space coordinates as a direct offset into
the buttonbw bitmap: you will have to adjust them first to reflect
whatever offset you are drawing this image at.
Shawn Hargreaves.
- Raw text -