rewrite how events are held

This commit is contained in:
Andrea Blankenstijn 2021-08-15 20:04:53 +02:00
parent d9eccc940a
commit 9e6e0a1d4c

View file

@ -0,0 +1,45 @@
#ifndef BWIDGETS_MOUSE_HANDLER_IMPL_HPP
#define BWIDGETS_MOUSE_HANDLER_IMPL_HPP
#include <basic_widgets/w/feat/mouse_handler.hpp>
namespace bwidgets
{
class MouseHandlerImpl : public MouseHandler
{
private:
const SDL_Rect* _area {nullptr};
bool _hovered {false};
bool _pushed {false};
std::function<void(const SDL_MouseButtonEvent&)> _click_handler;
std::function<void(const SDL_MouseMotionEvent&)> _motion_handler;
protected:
MouseHandlerImpl() = default;
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*) 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