2021-08-06 14:22:56 +02:00
|
|
|
#ifndef BWIDGETS_KEYBOARD_HANDLER
|
|
|
|
#define BWIDGETS_KEYBOARD_HANDLER
|
2021-07-10 19:55:53 +02:00
|
|
|
|
2021-07-18 18:26:12 +02:00
|
|
|
#include <basic_widgets/w/feat/focus_handler.hpp>
|
2021-07-10 19:55:53 +02:00
|
|
|
|
|
|
|
struct SDL_KeyboardEvent;
|
|
|
|
struct SDL_TextInputEvent;
|
|
|
|
|
2021-08-06 14:22:56 +02:00
|
|
|
namespace bwidgets
|
2021-07-10 19:55:53 +02:00
|
|
|
{
|
2021-07-11 22:03:30 +02:00
|
|
|
class KeyboardHandler : public virtual FocusHandler
|
2021-07-10 19:55:53 +02:00
|
|
|
{
|
2021-07-29 16:06:03 +02:00
|
|
|
protected:
|
|
|
|
virtual void _handle_key(const SDL_KeyboardEvent&) = 0;
|
|
|
|
virtual void _handle_text_input(const SDL_TextInputEvent&) = 0;
|
2021-07-10 19:55:53 +02:00
|
|
|
|
2021-07-29 16:06:03 +02:00
|
|
|
public:
|
2021-08-12 23:50:22 +02:00
|
|
|
using FocusHandler::FocusHandler;
|
|
|
|
|
|
|
|
KeyboardHandler(const KeyboardHandler&) = delete;
|
2021-08-14 09:25:28 +02:00
|
|
|
KeyboardHandler(KeyboardHandler&&) = delete;
|
|
|
|
~KeyboardHandler() override = default;
|
2021-08-12 23:50:22 +02:00
|
|
|
auto operator=(const KeyboardHandler&) = delete;
|
|
|
|
auto operator=(KeyboardHandler&&) = delete;
|
|
|
|
|
2021-08-14 09:17:51 +02:00
|
|
|
virtual auto handle_keyboard(const SDL_KeyboardEvent& ev)
|
2021-08-06 14:22:56 +02:00
|
|
|
-> KeyboardHandler* final
|
2021-07-29 16:06:03 +02:00
|
|
|
{
|
|
|
|
if (_has_focus) _handle_key(ev);
|
2021-08-06 14:22:56 +02:00
|
|
|
return this;
|
2021-07-29 16:06:03 +02:00
|
|
|
}
|
2021-07-10 19:55:53 +02:00
|
|
|
|
2021-08-14 09:17:51 +02:00
|
|
|
virtual auto handle_keyboard(const SDL_TextInputEvent& ev)
|
2021-08-06 14:22:56 +02:00
|
|
|
-> KeyboardHandler* final
|
2021-07-29 16:06:03 +02:00
|
|
|
{
|
|
|
|
if (_has_focus) _handle_text_input(ev);
|
2021-08-06 14:22:56 +02:00
|
|
|
return this;
|
2021-07-29 16:06:03 +02:00
|
|
|
}
|
2021-07-10 19:55:53 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|