Mouse-Over a Bitmap...

Started by
15 comments, last by Dean1988 20 years, 9 months ago
Hey,

Yup i fixed that error.

And i just tried what you said...

this is the code..

if (mouse_x < 230 && mouse_x > test.x && mouse_y < 190 && mouse_y > test.y && hover == 0){    	clear_bitmap(screen);   	draw(test.btn_hover, test.x, test.y); 	hover = 1; 	}else if ((mouse_x > 230 || mouse_x < test.x) && (mouse_y > 190 || mouse_y < test.y) && hover == 1){	clear_bitmap(screen);	draw(test.btn_norm, test.x, test.y); 	hover = 0; 	}


But, it works..ish...It''ll change the bitmap, BUT sometimes it will sometimes it wont :S

Any ideas if it''s the code or my comp?

Thanks.

Dean.
I''m new,so take it easy.
Advertisement
Ok I'm going to try and visual this.

   TestX/TestY        ----------  -       |          |  |       |          |  |Height = TestY + 190       |          |  |        ----------  -       |__________|          Width = TestX + 230

   if((mouse_x > test.x) && (mouse_x < test.x + 230) &&   (mouse_y > test.y) && (mouse_y < test.y + 190) && hover == 0){    clear_bitmap(screen);    draw(test.btn_hover, test.x, test.y);    hover = 1;    break;}else{    clear_bitmap(screen);    draw(test.btn_norm, test.x, test.y);    hover = 0;    break;}


This should work.

EDIT: Forgot about the hover. (Trying to help you and I had a bug )

BTW: You don't need the hover variable. The if statement decides that. If it finds the mouse position is within the buttons bound, it will show the hover image. If not, it will show the default button image. If you want a callback function when the button is pressed, do something like this:

void OnButtonPressCallback(int& ButtonState){    if(ButtonState)    {        //DoButtonPress();    }}//void UpdateButton(void (*OnButtonPress)(int&)){    if((mouse_x > test.x) && (mouse_x < test.x + 230) &&       (mouse_y > test.y) && (mouse_y < test.y + 190))    {        clear_bitmap(screen);        draw(test.btn_hover, test.x, test.y);        OnButtonPress(1);        break;    }    else    {        clear_bitmap(screen);        draw(test.btn_norm, test.x, test.y);        OnButtonPress(0);        break;    }}


Then to use it just call:
UpdateButton(OnButtonPressCallback);


-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on July 26, 2003 1:34:46 PM]
Nope


Heres the whole thing, not the source tho..
if you want the source, just ask and i''ll put that up too.

Thanks.

Dean.

http://www.geocities.com/spikeo_uk/test.zip
I''m new,so take it easy.
I looked at it, and I don''t understand. The examples we gave you should work like a miracle.

Post the actual mouse/checking code.
What are you using for your mouseX and MouseY? Are you calling something like:

POINT CursorPosition;GetCursorPos(&CursorPosition);ScreenToClient(hWnd, &CursorPosition);mouse_x = CursorPosition.x;mouse_y = CursorPosition.y;


Maybe your custom mouse cursor strays from the actual coords?

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"
I''m not using any Custome Mouse Cursors.

In the Allegro source code, there is mouse_y and mouse_x.
And it says that they hold the x and y co-ords of the mouse, so i went along with that.

and here''s the source, for ease


http://www.geocities.com/spikeo_uk/source.zip

Bet it''s something i''m doing wrong hehe.

Thanks.

Dean.
I''m new,so take it easy.
I don't have allegro so I can't test it, but I can give you a few pointers.

1) Take out the else if(*) , it's not needed. Just use else
2) Try the last example I gave. (The if/else one, not the mouse one)

When you check the far boundries, it should be:
Far right button edge = PositionX + Width;
Far bottom button edge = PositionY + Height;

So a boundry rect would look like:
RECT ButtonRect;
ButtonRect.left = test.x;
ButtonRect.top = test.y;
ButtonRect.right = test.x + 230; //--(ButtonWidth)
ButtonRect.bottom = test.y + 190; //--(ButtonHeight)

If you keep the rect in mind, you should have no problem.

-UltimaX-

[edited by - UltimaX on July 26, 2003 2:00:27 PM]
STill not working!!

Anyone else help please?

Thanks.
Dean.
I''m new,so take it easy.

This topic is closed to new replies.

Advertisement