#include #include #include #include using namespace bwidgets; auto MouseHandler::handle_mouse(const SDL_MouseButtonEvent& ev, const SDL_Rect& orig) -> MouseHandler* { if (_click_area == nullptr) return this; const SDL_Point p {ev.x, ev.y}; const SDL_Rect vp {rect_offset(*_click_area, orig)}; if (ev.type == SDL_MOUSEBUTTONDOWN) { if (SDL_PointInRect(&p, &vp) == SDL_TRUE) { push(true); _handle_mouse_button(ev, vp); } else focus(false); } else { if (_is_pushed) { if (SDL_PointInRect(&p, &vp) == SDL_TRUE) { focus(true); if (click_handler != nullptr) click_handler(ev); } push(false); _handle_mouse_button(ev, vp); } } return this; } auto MouseHandler::handle_mouse(const SDL_MouseMotionEvent& ev, const SDL_Rect& orig) -> MouseHandler* { if (_click_area == nullptr) return this; const SDL_Point p {ev.x, ev.y}; const SDL_Rect vp {rect_offset(*_click_area, orig)}; _is_hovered = SDL_PointInRect(&p, &vp) != 0; if (_is_hovered) _handle_mouse_motion(ev, orig); return this; } auto MouseHandler::push(bool state) -> MouseHandler* { _on_push(state); _is_pushed = state; return this; }