rewrite how events are held
This commit is contained in:
parent
d9eccc940a
commit
9e6e0a1d4c
1 changed files with 45 additions and 0 deletions
45
inc/basic_widgets/impl/mouse_handler_impl.hpp
Normal file
45
inc/basic_widgets/impl/mouse_handler_impl.hpp
Normal 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
|
Loading…
Reference in a new issue