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]