From: G DOT DegliEsposti AT ads DOT it To: "Bengt Rosenberger" cc: djgpp AT delorie DOT com Message-ID: Date: Tue, 28 Apr 1998 16:48:40 +0200 Subject: Re: allegro getpixel()-problem! Mime-Version: 1.0 Content-type: text/plain; charset=us-ascii Precedence: bulk >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