delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/28/10:18:05

Message-ID: <D1FB30BBA491D1118E6D006097BCAE392E4D72@Probe-nt-2a.Probe.co.uk>
From: Shawn Hargreaves <ShawnH AT Probe DOT co DOT uk>
To: djgpp AT delorie DOT com
Subject: Re: allegro getpixel()-problem!
Date: Tue, 28 Apr 1998 15:18:11 +0100
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019