bwidgets/inc/basic_widgets/w/feat/mouse_handler_impl.hpp

55 lines
1.5 KiB
C++

#ifndef BWIDGETS_MOUSE_HANDLER_IMPL_HPP
#define BWIDGETS_MOUSE_HANDLER_IMPL_HPP
#include <basic_widgets/w/feat/event_handler_impl.hpp>
#include <basic_widgets/w/feat/focus_handler_impl.hpp>
#include <basic_widgets/w/feat/mouse_handler.hpp>
namespace bwidgets
{
class MouseHandlerImpl : public MouseHandler,
virtual public EventHandlerImpl,
virtual public FocusHandlerImpl
{
private:
bool _hovered {false};
bool _pushed {false};
std::function<void(const SDL_MouseButtonEvent&)> _click_handler {[](auto) {}};
std::function<void(const SDL_MouseMotionEvent&)> _motion_handler {[](auto) {}};
protected:
using MouseHandler::MouseHandler;
void _on_push(bool) override {}
public:
void
click_handler(std::function<void(const SDL_MouseButtonEvent&)> handler) override
{
_click_handler = std::move(handler);
}
void disable_mouse_handler() override;
void enable_mouse_handler(const SDL_Rect*, const SDL_Rect*) override;
[[nodiscard]] bool hovered() const override
{
return _hovered;
}
void mouse_motion_handler(
std::function<void(const SDL_MouseMotionEvent&)> handler) override
{
_motion_handler = std::move(handler);
}
[[nodiscard]] bool pushed() const override
{
return _pushed;
}
};
}
#endif