From 77e1d1153e8e59ce0d3a39866a97034bf1f45dbd Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Fri, 24 Feb 2017 11:12:48 +0800 Subject: [PATCH] Update MiniEngine_Simple.hpp --- MiniEngine_Simple.hpp | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/MiniEngine_Simple.hpp b/MiniEngine_Simple.hpp index 1ca5601..585a1f2 100644 --- a/MiniEngine_Simple.hpp +++ b/MiniEngine_Simple.hpp @@ -815,6 +815,63 @@ private: }; +class Event +{ +public: + int gettype() + { + return e.type; + } +protected: + Event()=default; + SDL_Event e; +private: + friend class EventEngine; +}; + +class MouseButtonEvent : public Event +{ +public: + int getx() + { + return e.button.x; + } + int gety() + { + return e.button.y; + } + int getbutton() + { + return e.button.button; + } +}; + +class EventEngine +{ +public: + Event poll(bool mustNew=false) /// mustNew: false=SDL_PollEvent(&e) returns 0 ; true=SDL_PollEvent(&e) returns 1 + { + Event e; + while(1) + { + int ret=SDL_PollEvent(&e.e); + if((mustNew&&ret)||!mustNew) break; + } + return e; + } + Event wait() + { + Event e; + SDL_WaitEvent(&e.e); + return e; + } + Event waitfor(int ms) + { + Event e; + SDL_WaitEventTimeout(&e.e,ms); + return e; + } +}; }/// End of namespace MiniEngine