void UIButton::ProcessInput(InputManager* input) { ProcessInputChildren(input); bool hover = (absolute_x()<= input->GetMouseX() && input->GetMouseX() <= absolute_x()+ absolute_width() && absolute_y() <= input->GetMouseY() && input->GetMouseY() <= absolute_y() + absolute_height()); if (hover && input->GetMouseLeftCount() == 1) { if (on_click_) { on_click_(); } } }
bool label::handle_event(const SDL_Event& event, bool claimed) { if(!on_click_ && !highlight_on_mouseover_) { return 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_label(event.button.x, event.button.y)) { // skip processing if mousewheel event return claimed; } if(event.type == SDL_MOUSEMOTION) { const SDL_MouseMotionEvent& e = event.motion; if(highlight_on_mouseover_) { if(in_label(e.x,e.y)) { draw_highlight_ = true; } else { draw_highlight_ = false; } claimed = claim_mouse_events(); } } else if(event.type == SDL_MOUSEBUTTONDOWN) { const SDL_MouseButtonEvent& e = event.button; if(in_label(e.x,e.y)) { down_ = true; claimed = claim_mouse_events(); } } else if(event.type == SDL_MOUSEBUTTONUP) { down_ = false; const SDL_MouseButtonEvent& e = event.button; if(in_label(e.x,e.y)) { if(on_click_) { on_click_(); } claimed = claim_mouse_events(); } } return claimed; }