23 #include <SDL2/SDL_events.h>
40 template<event_category C>
57 const auto queue_check = [&](
auto& queue_set) {
58 return !queue_set.queue[event].empty(queue_type);
82 throw std::invalid_argument(
"Event is not categorized");
138 template<event_category C>
139 std::vector<std::pair<widget*, ui_event>>
145 std::vector<std::pair<widget*, ui_event>> result;
149 result.emplace_back(
w, event);
173 std::vector<std::pair<widget*, ui_event>>
202 std::vector<std::pair<widget*, ui_event>>
203 build_event_chain<event_category::message>(
const ui_event event, widget* dispatcher, widget*
w)
207 assert(
w == dispatcher);
209 std::vector<std::pair<widget*, ui_event>> result;
212 while((
w =
w->parent())) {
216 result.emplace(result.begin(),
w, event);
231 const std::vector<std::pair<widget*, ui_event>>& event_chain,
236 bool handled =
false;
241 const auto&
signal = dispatcher_implementation::event_signal<C>(*chain_target, chain_event);
243 for(
const auto& pre_func :
signal.pre_child) {
244 pre_func(*
dispatcher, chain_event, handled, halt, std::forward<F>(params)...);
259 const auto&
signal = dispatcher_implementation::event_signal<C>(*
w, event);
261 for(
const auto& func :
signal.child) {
262 func(*
dispatcher, event, handled, halt, std::forward<F>(params)...);
276 for(
const auto& [chain_target, chain_event] : event_chain) {
277 const auto&
signal = dispatcher_implementation::event_signal<C>(*chain_target, chain_event);
279 for(
const auto& post_func :
signal.post_child) {
280 post_func(*
dispatcher, chain_event, handled, halt, std::forward<F>(params)...);
294 assert(handled ==
false);
329 std::vector<std::pair<widget*, ui_event>> event_chain =
330 implementation::build_event_chain<C>(event, dispatcher_w,
w);
332 return implementation::fire_event<C>(event, event_chain, dispatcher_w,
w, std::forward<F>(params)...);
344 std::vector<std::pair<widget*, ui_event>> event_chain;
352 if(std::invoke(wants_double_click,
w)) {
354 event_chain.emplace_back(
w, double_click);
358 event_chain.emplace_back(
w,
click);
363 if(std::invoke(wants_double_click, wgt)) {
365 return implementation::fire_event<C>(double_click, event_chain,
d, wgt, std::forward<F>(params)...);
368 return implementation::fire_event<C>(
click, event_chain,
d, wgt, std::forward<F>(params)...);
Base class for event handling.
signal_queue< signal_touch_gesture > signal_touch_gesture_queue_
Signal queue for callbacks in event_category::touch_gesture.
auto & get_signal_queue()
signal_queue< signal_message > signal_message_queue_
Signal queue for callbacks in event_category::message.
signal_queue< signal_text_input > signal_text_input_queue_
Signal queue for callbacks in event_category::text_input.
signal_queue< signal_raw_event > signal_raw_event_queue_
Signal queue for callbacks in event_category::raw_event.
signal_queue< signal_notification > signal_notification_queue_
Signal queue for callbacks in event_category::notification.
signal_queue< signal > signal_queue_
Signal queue for callbacks in event_category::general.
signal_queue< signal_touch_motion > signal_touch_motion_queue_
Signal queue for callbacks in event_category::touch_motion.
signal_queue< signal_keyboard > signal_keyboard_queue_
Signal queue for callbacks in event_category::keyboard.
signal_queue< signal_mouse > signal_mouse_queue_
Signal queue for callbacks in event_category::mouse.
std::vector< std::pair< widget *, ui_event > > build_event_chain(const ui_event event, widget *dispatcher, widget *w)
Build the event chain.
bool fire_event(const ui_event event, const std::vector< std::pair< widget *, ui_event >> &event_chain, widget *dispatcher, widget *w, F &&... params)
Helper function for fire_event.
ui_event
The event sent to the dispatcher.
bool fire_event_double_click(dispatcher *dsp, widget *wgt, F &&... params)
constexpr event_category get_event_category(const ui_event event)
Returns the category of a given event.
bool fire_event(const ui_event event, dispatcher *d, widget *w, F &&... params)
Fires an event.
dispatcher_callback<> signal
Used for events in event_category::general.
event_category
Event category masks.
@ notification
Callbacks with a sender aka notification messages.
@ keyboard
Callbacks with the keyboard values (these haven't been determined yet).
@ mouse
Callbacks with a coordinate as extra parameter.
@ message
Callbacks with a sender aka notification messages.
@ general
Callbacks without extra parameters.
Contains the implementation details for lexical_cast and shouldn't be used directly.
auto reversed_view(T &container)
static auto & event_signal(dispatcher &dispatcher, const ui_event event)
Returns the appropriate signal queue for an event by category.
static bool has_handler(dispatcher &dispatcher, const dispatcher::event_queue_type queue_type, ui_event event)
A helper to test whether dispatcher has an handler for a certain event.