22 #include <SDL2/SDL_events.h>
50 template<
typename... T>
224 const SDL_Keycode key,
225 const SDL_Keymod modifier,
226 const std::string& unicode);
248 bool fire(
const ui_event event,
widget& target,
const point& center,
float dTheta,
float dDist, uint8_t numFingers);
350 template<ui_event E,
typename F>
353 get_signal_queue<get_event_category(E)>().connect_signal(E, position, func);
369 template<ui_event E,
typename F>
372 get_signal_queue<get_event_category(E)>().disconnect_signal(E, position, func);
503 std::map<ui_event, signal_type<T>>
queue;
534 const auto predicate = [&
signal](
const T& element) {
return signal.target_type() == element.target_type(); };
547 queue[event].pre_child.remove_if(predicate);
553 queue[event].child.remove_if(predicate);
559 queue[event].post_child.remove_if(predicate);
611 std::map<hotkey::HOTKEY_COMMAND, hotkey_function>
hotkeys_;
613 template<event_category cat>
Base class for event handling.
void connect_signal(const F &func, const queue_position position=back_child)
Adds a callback to the appropriate queue based on event type.
void connect()
Connects the dispatcher to the event handler.
signal_queue< signal_touch_gesture > signal_touch_gesture_queue_
Signal queue for callbacks in event_category::touch_gesture.
queue_position
The position where to add a new callback in the signal handler.
auto & get_signal_queue()
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
bool has_event(const ui_event event, const event_queue_type event_type)
void set_mouse_behavior(const mouse_behavior mouse_behavior)
virtual bool is_at(const point &coordinate) const =0
Determines whether the location is inside an active widget.
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.
mouse_behavior
The behavior of the mouse events.
bool get_want_keyboard_input() const
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.
void disconnect()
Disconnects the dispatcher from the event handler.
signal_queue< signal > signal_queue_
Signal queue for callbacks in event_category::general.
mouse_behavior mouse_behavior_
The mouse behavior for the dispatcher.
bool want_keyboard_input_
Does the dispatcher want to receive keyboard input.
void set_want_keyboard_input(const bool want_keyboard_input)
void capture_mouse()
Captures the mouse.
signal_queue< signal_touch_motion > signal_touch_motion_queue_
Signal queue for callbacks in event_category::touch_motion.
void disconnect_signal(const F &func, const queue_position position=back_child)
Removes a callback from the appropriate queue based on event type.
bool connected_
Are we connected to the event handler.
bool execute_hotkey(const hotkey::HOTKEY_COMMAND id)
Executes a hotkey.
mouse_behavior get_mouse_behavior() const
void register_hotkey(const hotkey::HOTKEY_COMMAND id, const hotkey_function &function)
Registers a hotkey.
bool is_connected() const
Return whether the dispatcher is currently connected.
signal_queue< signal_keyboard > signal_keyboard_queue_
Signal queue for callbacks in event_category::keyboard.
void release_mouse()
Releases the mouse capture.
signal_queue< signal_mouse > signal_mouse_queue_
Signal queue for callbacks in event_category::mouse.
std::map< hotkey::HOTKEY_COMMAND, hotkey_function > hotkeys_
The registered hotkeys for this dispatcher.
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
dispatcher_callback< const point &, float, float, uint8_t > signal_touch_gesture
Used for events in event_category::touch_gesture.
std::function< void(widget &dispatcher, hotkey::HOTKEY_COMMAND id)> hotkey_function
Hotkey function handler signature.
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard &signal)
Connects the signal for 'snooping' on the keypress.
ui_event
The event sent to the dispatcher.
void disconnect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Disconnects a signal handler for a left mouse button click.
dispatcher_callback< const std::string &, int32_t, int32_t > signal_text_input
Used for eventsin event_category::text_input.
dispatcher_callback< void * > signal_notification
Used for events in event_category::notification.
void capture_mouse(dispatcher *dispatcher)
Captures the mouse.
void release_mouse(dispatcher *dispatcher)
Releases a captured mouse.
void disconnect_signal_mouse_left_release(dispatcher &dispatcher, const signal &signal)
Disconnects a signal handler for a left mouse button release.
dispatcher_callback<> signal
Used for events in event_category::general.
@ 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.
void connect_signal_mouse_left_release(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button release.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
dispatcher_callback< const message & > signal_message
Used for events in event_category::message.
std::function< void(widget &, const ui_event, bool &, bool &, T...)> dispatcher_callback
Callback function signature alias template.
dispatcher_callback< const SDL_Event & > signal_raw_event
Used for events in event_category::raw_event.
dispatcher_callback< const point &, const point & > signal_touch_motion
Used for events in event_category::touch_motion.
dispatcher_callback< const SDL_Keycode, const SDL_Keymod, const std::string & > signal_keyboard
Used for events in event_category::keyboard.
dispatcher_callback< const point & > signal_mouse
Used for events in event_category::mouse.
void connect_signal_mouse_left_double_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button double click.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
constexpr bool dependent_false_v
Workaround for the fact that static_assert(false) is invalid.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Helper struct to generate the various event queues.
signal_queue & operator=(const signal_queue &)=delete
signal_queue(const signal_queue &)=delete
void disconnect_signal(const ui_event event, const queue_position position, const T &signal)
void connect_signal(const ui_event event, const queue_position position, const T &signal)
std::map< ui_event, signal_type< T > > queue
Helper struct to generate the various signal types.
bool empty(const dispatcher::event_queue_type queue_type) const
Checks whether the queue of a given type is empty.
std::list< T > post_child
The message callbacks hold a reference to a message.