cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/28/10:54:41

From: G DOT DegliEsposti AT ads DOT it
To: "Bengt Rosenberger" <rosenberger AT berlin DOT snafu DOT de>
cc: djgpp AT delorie DOT com
Message-ID: <C12565F4.00507C08.00@vega.ads.it>
Date: Tue, 28 Apr 1998 16:48:40 +0200
Subject: Re: allegro getpixel()-problem!
Mime-Version: 1.0




>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. But if I press the left mouse button in the upper left corner, the
>return col is 255 but the b/w button is in the middle of the screen. And
it
This behaviour is because if you click in the middle of the screen (let's
say
at 320, 240 as example) then the point you check (320,240 in the example)
is
outside the button bitmap, so the -1 is explained.

>seems as the button would be in the upper left corner but is shown in
>SCREEN_W / 2 - button->w/2, SCREEN_H / 2 - button->h/2

Of course. if you click in the upper left corner your mouse is at (0,0) and
then if you check point (0,0) in the bitmap you will have some meaningful
result.

The getpixel function has no way to discover that you are passing it the
mouse x and y, and if it could then it couldn't know that you want
those coordinates relative to the bitmap. You will have to do it yourself!
:-)

You have to check the point ( mouse_x - buttonbw_x, mouse_y - buttonbw_y)
where
buttonbw_x/y are the coordinates where you blit the bitmap.
ciao
  Giacomo


- Raw text -


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