diff --git a/src/Delegate.cpp b/src/Delegate.cpp index 17b8f61..cd2f9ed 100644 --- a/src/Delegate.cpp +++ b/src/Delegate.cpp @@ -38,19 +38,31 @@ void Delegate::dispatch() } } -bool Delegate::compare(SDL_Event& event, std::string command, bool neutral, bool cancel) +bool Delegate::compare(SDL_Event& event, const std::vector& commands, const bool& neutral, const bool& cancel) { - return event.type == command_event_type and - (command == "" or command == *static_cast(event.user.data1)) and - (neutral or (cancel == *static_cast(event.user.data2))); + for (const std::string& command : commands) + { + if (compare(event, command, neutral, cancel)) + { + return true; + } + } + return false; } -bool Delegate::compare_cancel(SDL_Event& event, std::string command) +bool Delegate::compare(SDL_Event& event, const std::string& command, const bool& neutral, const bool& cancel) +{ + return event.type == command_event_type && + (command == "" || command == *static_cast(event.user.data1)) && + (neutral || (cancel == *static_cast(event.user.data2))); +} + +bool Delegate::compare_cancel(SDL_Event& event, const std::string& command) { return compare(event, command, false, true); } -bool Delegate::compare_neutral(SDL_Event& event, std::string command) +bool Delegate::compare_neutral(SDL_Event& event, const std::string& command) { return compare(event, command, true); } diff --git a/src/Delegate.hpp b/src/Delegate.hpp index 12a2302..669da66 100644 --- a/src/Delegate.hpp +++ b/src/Delegate.hpp @@ -27,9 +27,10 @@ struct Delegate : Node Delegate(Node*); void add_subscriber(Subscriber, int); void dispatch(); - bool compare(SDL_Event&, std::string = "", bool = false, bool = false); - bool compare_cancel(SDL_Event&, std::string = ""); - bool compare_neutral(SDL_Event&, std::string = ""); + bool compare(SDL_Event&, const std::vector&, const bool& = false, const bool& = false); + bool compare(SDL_Event&, const std::string& = "", const bool& = false, const bool& = false); + bool compare_cancel(SDL_Event&, const std::string& = ""); + bool compare_neutral(SDL_Event&, const std::string& = ""); template void subscribe(void(T::*f)(SDL_Event&), T* o, int type = command_event_type)