bool button::handle_event(const SDL_Event& event, bool claimed) { #if SDL_VERSION_ATLEAST(2, 0, 0) if((event.type == SDL_MOUSEWHEEL) #else if((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) && (event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN) #endif && in_widget(event.button.x, event.button.y)) { // skip processing if mousewheel event return claimed; } if(claimed) { current_button_image_set_ = normal_button_image_set_; down_ = false; } if(event.type == SDL_MOUSEMOTION) { const SDL_MouseMotionEvent& e = event.motion; if(in_widget(e.x,e.y)) { current_button_image_set_ = down_ ? depressed_button_image_set_ : focus_button_image_set_; } else { current_button_image_set_ = normal_button_image_set_; } } else if(event.type == SDL_MOUSEBUTTONDOWN) { const SDL_MouseButtonEvent& e = event.button; if(in_widget(e.x,e.y)) { std::cerr << "ZZZ: Widget: " << e.x << ", " << e.y << ": "; if(clip_area()) { std::cerr << *clip_area() << "\n"; } else { std::cerr << "(null)\n"; } current_button_image_set_ = depressed_button_image_set_; down_ = true; claimed = claim_mouse_events(); } } else if(event.type == SDL_MOUSEBUTTONUP) { down_ = false; const SDL_MouseButtonEvent& e = event.button; if(current_button_image_set_ == depressed_button_image_set_) { if(in_widget(e.x,e.y)) { current_button_image_set_ = focus_button_image_set_; onclick_(); claimed = claim_mouse_events(); } else { current_button_image_set_ = normal_button_image_set_; } } } return claimed; }
void menubar_handle_click(widget_ptr p, int button, int x, int y) { int i; menubar_ptr m = (menubar_ptr) p; menuitem_ptr it; for (i=0; i<m->item_count; i++) { it = m->item_list[i]; if (in_widget((widget_ptr) it, x, y)) { widget_raise_signal((widget_ptr) it, signal_activate); return; } } }
void button_update(widget_ptr p) { SDL_Rect dst; label_ptr l = (label_ptr) p; if (state == state_button && button_selection == p && in_widget(p, lastmousex, lastmousey)) { widget_lowered_background(p); } else { widget_raised_background(p); } if (l->img) { dst.x = 5; dst.y = 2; widget_blit(l, l->img, NULL, &dst); } }
void menu_update(menu_ptr m) { int i; menuitem_ptr it; SDL_Rect rect; widget_fill((widget_ptr) m, c_background); for (i=0; i<m->item_count; i++) { it = m->item_list[i]; if (in_widget((widget_ptr) it, lastmousex, lastmousey)) { rect.x = 2; rect.y = vsize * i; rect.w = ((widget_ptr) it)->w - 4; rect.h = vsize; widget_fillrect((widget_ptr) m, &rect, c_menubg); } rect.x = 8; rect.y = vsize * i + 4; widget_blit((widget_ptr) m, it->img, NULL, &rect); } }