[Super-tux-commit] supertux/src button.cpp,1.18,1.19 button.h,1.16,1.17
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-05-02 22:26:12
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25925 Modified Files: button.cpp button.h Log Message: fixed potential bug in Button class event handler Index: button.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/button.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- button.h 2 May 2004 21:28:32 -0000 1.16 +++ button.h 2 May 2004 22:26:04 -0000 1.17 @@ -71,8 +71,8 @@ Button* event(SDL_Event &event); void additem(Button* pbutton, int tag); Button* button_panel_event(SDL_Event& event); - void set_button_size(int w, int h) { bw = w; bh = h; } - Button* manipulate_button(int i) { if(item.size()-1 < i) { return item[item.size()-1]; } else { return item[i]; } }; + void set_button_size(int w, int h); + Button* manipulate_button(int i); private: int bw, bh; Index: button.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/button.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- button.cpp 2 May 2004 21:28:32 -0000 1.18 +++ button.cpp 2 May 2004 22:26:04 -0000 1.19 @@ -144,48 +144,38 @@ { SDLKey key = event.key.keysym.sym; - if(event.motion.x > rect.x && event.motion.x < rect.x + rect.w && - event.motion.y > rect.y && event.motion.y < rect.y + rect.h) + if(event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) { - if(event.type == SDL_MOUSEBUTTONDOWN) - { - if(event.button.button == SDL_BUTTON_LEFT) - { - state = BUTTON_PRESSED; - } - else - { - show_info = true; - } - } - else if(event.type == SDL_MOUSEBUTTONUP) - { - if(event.button.button == SDL_BUTTON_LEFT && state == BUTTON_PRESSED) - { - state = BUTTON_CLICKED; - } - else if(event.button.button != SDL_BUTTON_LEFT && state != BUTTON_PRESSED) - { - show_info = true; - } - } + if(event.button.x < rect.x || event.button.x >= rect.x + rect.w || + event.button.y < rect.y || event.button.y >= rect.y + rect.h) + return; - if(state != BUTTON_PRESSED && state != BUTTON_CLICKED) + if(event.button.button != SDL_BUTTON_LEFT) { - state = BUTTON_HOVER; - mouse_cursor->set_state(MC_LINK); + show_info = true; + return; } + + if(event.type == SDL_MOUSEBUTTONDOWN) + state = BUTTON_PRESSED; + else + state = BUTTON_CLICKED; } - else if((event.type != SDL_KEYDOWN && event.type != SDL_KEYUP) || event.type == SDL_MOUSEMOTION) + else if(event.type == SDL_MOUSEMOTION) { - state = BUTTON_NONE; + if(event.motion.x < rect.x || event.motion.x >= rect.x + rect.w || + event.motion.y < rect.y || event.motion.y >= rect.y + rect.h) + state = BUTTON_NONE; + else + state = BUTTON_HOVER; + + popup_timer.start(1500); if(show_info) { show_info = false; - } + } } - - if(event.type == SDL_KEYDOWN) + else if(event.type == SDL_KEYDOWN) { if(key == shortcut) state = BUTTON_PRESSED; @@ -195,16 +185,6 @@ if(state == BUTTON_PRESSED && key == shortcut) state = BUTTON_CLICKED; } - else if(event.type == SDL_MOUSEMOTION) - { - popup_timer.start(1500); - - if(show_info) - { - show_info = false; - } - } - } int Button::get_state() @@ -292,3 +272,16 @@ } +void ButtonPanel::set_button_size(int w, int h) +{ + bw = w; + bh = h; +} + +Button* ButtonPanel::manipulate_button(int i) +{ + if(int(item.size())-1 < i) + return item[item.size()-1]; + else + return item[i]; +} |