#pragma once #include "MiniEngine.h" #include #include typedef SDL_Event Event; int PollEvent(Event& refEvent); int WaitEvent(Event& refEvent); int WaitEventTimeout(Event& refEvent,int ms); int PushEvent(const Event& refEvent); typedef struct { decltype(Event::type) _type_id; int _looper_cnt; }LooperID; bool operator == (const LooperID&,const LooperID&); class Looper { public: typedef decltype(Event::type) _SDLEventType_; Looper(); /// If Callback does not return 0, then stop transferring this event. LooperID add(_SDLEventType_ event_type,const std::function& event_callback); LooperID add(_SDLEventType_ event_type,const std::function& event_callback); LooperID add(_SDLEventType_ event_type,const std::function& event_callback); LooperID add(_SDLEventType_ event_type,const std::function& event_callback); /// If Callback has no return (void), then we assume it returns 0. LooperID add(_SDLEventType_ event_type,const std::function& event_callback); LooperID add(_SDLEventType_ event_type,const std::function& event_callback); LooperID add(_SDLEventType_ event_type,const std::function& event_callback); LooperID add(_SDLEventType_ event_type,const std::function& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); LooperID operator + (const std::pair<_SDLEventType_,std::function>& event_callback); bool remove(const LooperID& looperid); bool operator - (const LooperID& looperid); void dispatch(); void run(); Event GetLastEvent(); void needupdate(); void needstop(); void stop(); void reset(); private: Event _e; bool _running,_update; std::map<_SDLEventType_,std::list>>> _evmap; int _loop_cnt; };