1 /** 2 * Copyright (c) 2006-2016 LOVE Development Team 3 * 4 * This software is provided 'as-is', without any express or implied 5 * warranty. In no event will the authors be held liable for any damages 6 * arising from the use of this software. 7 * 8 * Permission is granted to anyone to use this software for any purpose, 9 * including commercial applications, and to alter it and redistribute it 10 * freely, subject to the following restrictions: 11 * 12 * 1. The origin of this software must not be misrepresented; you must not 13 * claim that you wrote the original software. If you use this software 14 * in a product, an acknowledgment in the product documentation would be 15 * appreciated but is not required. 16 * 2. Altered source versions must be plainly marked as such, and must not be 17 * misrepresented as being the original software. 18 * 3. This notice may not be removed or altered from any source distribution. 19 **/ 20 21 #ifndef LOVE_EVENT_EVENT_H 22 #define LOVE_EVENT_EVENT_H 23 24 // LOVE 25 #include "common/Module.h" 26 #include "common/StringMap.h" 27 #include "common/Variant.h" 28 #include "keyboard/Keyboard.h" 29 #include "mouse/Mouse.h" 30 #include "joystick/Joystick.h" 31 #include "thread/threads.h" 32 33 // C++ 34 #include <queue> 35 #include <vector> 36 37 namespace love 38 { 39 namespace event 40 { 41 42 class Message : public Object 43 { 44 public: 45 46 Message(const std::string &name, const std::vector<Variant> &vargs = {}); 47 ~Message(); 48 49 int toLua(lua_State *L); 50 static Message *fromLua(lua_State *L, int n); 51 52 private: 53 54 std::string name; 55 std::vector<Variant> args; 56 57 }; // Message 58 59 class Event : public Module 60 { 61 public: 62 virtual ~Event(); 63 64 // Implements Module. getModuleType()65 virtual ModuleType getModuleType() const { return M_EVENT; } 66 67 void push(Message *msg); 68 bool poll(Message *&msg); 69 virtual void clear(); 70 71 virtual void pump() = 0; 72 virtual Message *wait() = 0; 73 74 protected: 75 love::thread::MutexRef mutex; 76 std::queue<Message *> queue; 77 78 }; // Event 79 80 } // event 81 } // love 82 83 #endif // LOVE_EVENT_EVENT_H 84