compare event accepts vector of commands
This commit is contained in:
parent
8eeeb82f4c
commit
5df099354b
|
@ -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<std::string>& commands, const bool& neutral, const bool& cancel)
|
||||
{
|
||||
return event.type == command_event_type and
|
||||
(command == "" or command == *static_cast<std::string*>(event.user.data1)) and
|
||||
(neutral or (cancel == *static_cast<bool*>(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<std::string*>(event.user.data1)) &&
|
||||
(neutral || (cancel == *static_cast<bool*>(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);
|
||||
}
|
||||
|
|
|
@ -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<std::string>&, 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<typename T>
|
||||
void subscribe(void(T::*f)(SDL_Event&), T* o, int type = command_event_type)
|
||||
|
|
Loading…
Reference in New Issue