Skip to content

Commit

Permalink
GUI2: reformat dispatcher code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Apr 29, 2017
1 parent b1d4be2 commit 9742a15
Showing 1 changed file with 64 additions and 125 deletions.
189 changes: 64 additions & 125 deletions src/gui/core/event/dispatcher.cpp
Expand Up @@ -20,10 +20,8 @@

namespace gui2
{

namespace event
{

/***** dispatcher class. *****/

dispatcher::dispatcher()
Expand Down Expand Up @@ -76,30 +74,20 @@ bool dispatcher::has_event(const ui_event event, const event_queue_type event_ty
<< ".\n";
#endif

return find<set_event>(
event,
dispatcher_implementation::has_handler(event_type, *this))
|| find<set_event_mouse>(event,
dispatcher_implementation::has_handler(
event_type, *this))
|| find<set_event_keyboard>(
event,
dispatcher_implementation::has_handler(event_type,
*this))
|| find<set_event_touch>(
event,
dispatcher_implementation::has_handler(event_type,
*this))
|| find<set_event_notification>(
event,
dispatcher_implementation::has_handler(event_type,
*this))
|| find<set_event_message>(event,
dispatcher_implementation::has_handler(
event_type, *this))
|| find<set_event_raw_event>(event,
dispatcher_implementation::has_handler(
event_type, *this));
return find<set_event>(event,
dispatcher_implementation::has_handler(event_type, *this))
|| find<set_event_mouse>(event,
dispatcher_implementation::has_handler(event_type, *this))
|| find<set_event_keyboard>(event,
dispatcher_implementation::has_handler(event_type, *this))
|| find<set_event_touch>(event,
dispatcher_implementation::has_handler(event_type, *this))
|| find<set_event_notification>(event,
dispatcher_implementation::has_handler(event_type, *this))
|| find<set_event_message>(event,
dispatcher_implementation::has_handler(event_type, *this))
|| find<set_event_raw_event>(event,
dispatcher_implementation::has_handler(event_type, *this));
}

/**
Expand Down Expand Up @@ -138,11 +126,8 @@ class event_in_set
class trigger
{
public:
void operator()(signal_function functor,
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt) const
void operator()(signal_function functor, dispatcher& dispatcher,
const ui_event event, bool& handled, bool& halt) const
{
functor(dispatcher, event, handled, halt);
}
Expand All @@ -153,48 +138,36 @@ bool dispatcher::fire(const ui_event event, widget& target)
assert(find<set_event>(event, event_in_set()));
switch(event) {
case LEFT_BUTTON_DOUBLE_CLICK:
return fire_event_double_click<LEFT_BUTTON_CLICK,
LEFT_BUTTON_DOUBLE_CLICK,
&event_executor::
wants_mouse_left_double_click,
signal_function>(
return fire_event_double_click<LEFT_BUTTON_CLICK, LEFT_BUTTON_DOUBLE_CLICK,
&event_executor::wants_mouse_left_double_click, signal_function>(
dynamic_cast<widget*>(this), &target, trigger());

case MIDDLE_BUTTON_DOUBLE_CLICK:
return fire_event_double_click<MIDDLE_BUTTON_CLICK,
MIDDLE_BUTTON_DOUBLE_CLICK,
&event_executor::
wants_mouse_middle_double_click,
signal_function>(
return fire_event_double_click<MIDDLE_BUTTON_CLICK, MIDDLE_BUTTON_DOUBLE_CLICK,
&event_executor::wants_mouse_middle_double_click, signal_function>(
dynamic_cast<widget*>(this), &target, trigger());

case RIGHT_BUTTON_DOUBLE_CLICK:
return fire_event_double_click<RIGHT_BUTTON_CLICK,
RIGHT_BUTTON_DOUBLE_CLICK,
&event_executor::
wants_mouse_right_double_click,
signal_function>(
return fire_event_double_click<RIGHT_BUTTON_CLICK, RIGHT_BUTTON_DOUBLE_CLICK,
&event_executor::wants_mouse_right_double_click, signal_function>(
dynamic_cast<widget*>(this), &target, trigger());

default:
return fire_event<signal_function>(
event, dynamic_cast<widget*>(this), &target, trigger());
return fire_event<signal_function>(event, dynamic_cast<widget*>(this), &target, trigger());
}
}

/** Helper struct to wrap the functor call. */
class trigger_mouse
{
public:
explicit trigger_mouse(const point& coordinate) : coordinate_(coordinate)
explicit trigger_mouse(const point& coordinate)
: coordinate_(coordinate)
{
}

void operator()(signal_mouse_function functor,
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt)
void operator()(signal_mouse_function functor, dispatcher& dispatcher,
const ui_event event, bool& handled, bool& halt)
{
functor(dispatcher, event, handled, halt, coordinate_);
}
Expand All @@ -203,32 +176,26 @@ class trigger_mouse
point coordinate_;
};

bool
dispatcher::fire(const ui_event event, widget& target, const point& coordinate)
bool dispatcher::fire(const ui_event event, widget& target, const point& coordinate)
{
assert(find<set_event_mouse>(event, event_in_set()));
return fire_event<signal_mouse_function>(event,
dynamic_cast<widget*>(this),
&target,
trigger_mouse(coordinate));
return fire_event<signal_mouse_function>(
event, dynamic_cast<widget*>(this), &target, trigger_mouse(coordinate));
}

/** Helper struct to wrap the functor call. */
class trigger_keyboard
{
public:
trigger_keyboard(const SDL_Keycode key,
const SDL_Keymod modifier,
const utf8::string& unicode)
: key_(key), modifier_(modifier), unicode_(unicode)
trigger_keyboard(const SDL_Keycode key, const SDL_Keymod modifier, const utf8::string& unicode)
: key_(key)
, modifier_(modifier)
, unicode_(unicode)
{
}

void operator()(signal_keyboard_function functor,
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt)
void operator()(signal_keyboard_function functor, dispatcher& dispatcher,
const ui_event event, bool& handled, bool& halt)
{
functor(dispatcher, event, handled, halt, key_, modifier_, unicode_);
}
Expand All @@ -240,32 +207,27 @@ class trigger_keyboard
};

bool dispatcher::fire(const ui_event event,
widget& target,
const SDL_Keycode key,
const SDL_Keymod modifier,
const utf8::string& unicode)
widget& target,
const SDL_Keycode key,
const SDL_Keymod modifier,
const utf8::string& unicode)
{
assert(find<set_event_keyboard>(event, event_in_set()));
return fire_event<signal_keyboard_function>(
event,
dynamic_cast<widget*>(this),
&target,
trigger_keyboard(key, modifier, unicode));
event, dynamic_cast<widget*>(this), &target, trigger_keyboard(key, modifier, unicode));
}

/** Helper struct to wrap the functor call. */
class trigger_raw_event
{
public:
trigger_raw_event(const SDL_Event& sdlevent) : sdl_event_(sdlevent)
trigger_raw_event(const SDL_Event& sdlevent)
: sdl_event_(sdlevent)
{
}

void operator()(signal_raw_event_function functor,
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt)
void operator()(signal_raw_event_function functor, dispatcher& dispatcher,
const ui_event event, bool& handled, bool& halt)
{
functor(dispatcher, event, handled, halt, sdl_event_);
}
Expand All @@ -274,16 +236,11 @@ class trigger_raw_event
const SDL_Event& sdl_event_;
};

bool dispatcher::fire(const ui_event event,
widget& target,
const SDL_Event& sdlevent)
bool dispatcher::fire(const ui_event event, widget& target, const SDL_Event& sdlevent)
{
assert(find<set_event_raw_event>(event, event_in_set()));
return fire_event<signal_raw_event_function>(
event,
dynamic_cast<widget*>(this),
&target,
trigger_raw_event(sdlevent));
event, dynamic_cast<widget*>(this), &target, trigger_raw_event(sdlevent));
}

/** Helper struct to wrap the functor call. */
Expand All @@ -296,11 +253,8 @@ class trigger_touch
{
}

void operator()(signal_touch_function functor,
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt)
void operator()(signal_touch_function functor, dispatcher& dispatcher,
const ui_event event, bool& handled, bool& halt)
{
functor(dispatcher, event, handled, halt, pos_, distance_);
}
Expand All @@ -310,28 +264,22 @@ class trigger_touch
point distance_;
};

bool dispatcher::fire(const ui_event event,
widget& target,
const point& pos,
const point& distance)
bool dispatcher::fire(const ui_event event, widget& target, const point& pos, const point& distance)
{
assert(find<set_event_touch>(event, event_in_set()));
return fire_event<signal_touch_function>(
event,
dynamic_cast<widget*>(this),
&target,
trigger_touch(pos, distance));
event, dynamic_cast<widget*>(this), &target, trigger_touch(pos, distance));
}

/** Helper struct to wrap the functor call. */
class trigger_notification
{
public:
void operator()(signal_notification_function functor,
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt) const
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt) const
{
functor(dispatcher, event, handled, halt, nullptr);
}
Expand All @@ -341,25 +289,20 @@ bool dispatcher::fire(const ui_event event, widget& target, void*)
{
assert(find<set_event_notification>(event, event_in_set()));
return fire_event<signal_notification_function>(
event,
dynamic_cast<widget*>(this),
&target,
trigger_notification());
event, dynamic_cast<widget*>(this), &target, trigger_notification());
}

/** Helper struct to wrap the functor call. */
class trigger_message
{
public:
explicit trigger_message(message& msg) : message_(msg)
explicit trigger_message(message& msg)
: message_(msg)
{
}

void operator()(signal_message_function functor,
dispatcher& dispatcher,
const ui_event event,
bool& handled,
bool& halt)
void operator()(signal_message_function functor, dispatcher& dispatcher,
const ui_event event, bool& handled, bool& halt)
{
functor(dispatcher, event, handled, halt, message_);
}
Expand All @@ -371,22 +314,18 @@ class trigger_message
bool dispatcher::fire(const ui_event event, widget& target, message& msg)
{
assert(find<set_event_message>(event, event_in_set()));
return fire_event<signal_message_function>(event,
dynamic_cast<widget*>(this),
&target,
trigger_message(msg));
return fire_event<signal_message_function>(
event, dynamic_cast<widget*>(this), &target, trigger_message(msg));
}

void dispatcher::register_hotkey(const hotkey::HOTKEY_COMMAND id,
const thotkey_function& function)
void dispatcher::register_hotkey(const hotkey::HOTKEY_COMMAND id, const thotkey_function& function)
{
hotkeys_[id] = function;
}

bool dispatcher::execute_hotkey(const hotkey::HOTKEY_COMMAND id)
{
std::map<hotkey::HOTKEY_COMMAND, thotkey_function>::iterator itor
= hotkeys_.find(id);
std::map<hotkey::HOTKEY_COMMAND, thotkey_function>::iterator itor = hotkeys_.find(id);

if(itor == hotkeys_.end()) {
return false;
Expand Down

0 comments on commit 9742a15

Please sign in to comment.