From: Matthias Braun Date: Sun, 2 May 2004 22:26:04 +0000 (+0000) Subject: fixed potential bug in Button class event handler X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0199662b9a4742a7b9e8f93170b901c71a8523df;p=supertux.git fixed potential bug in Button class event handler SVN-Revision: 928 --- diff --git a/src/button.cpp b/src/button.cpp index a62aac81d..03fa0c932 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -144,48 +144,38 @@ void Button::event(SDL_Event &event) { 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 @@ void Button::event(SDL_Event &event) 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::additem(Button* pbutton, int tag) } +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]; +} diff --git a/src/button.h b/src/button.h index d96428955..552fd22c6 100644 --- a/src/button.h +++ b/src/button.h @@ -71,8 +71,8 @@ public: 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;