Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/util/events.cpp b/util/events.cpp
new file mode 100644
index 00000000..c9968a17
--- /dev/null
+++ b/util/events.cpp
@@ -0,0 +1,46 @@
+#ifdef USE_SDL
+#include <SDL.h>
+#endif
+#include "events.h"
+#include "shutdown_exception.h"
+
+namespace Util{
+
+EventManager::EventManager(){
+}
+
+#ifdef USE_SDL
+void EventManager::runSDL(){
+ SDL_Event event;
+ if (SDL_PollEvent(&event) == 1){
+ switch (event.type){
+ case SDL_QUIT : {
+ dispatch(CloseWindow);
+ break;
+ }
+ default : {
+ break;
+ }
+ }
+ }
+}
+#endif
+
+void EventManager::run(){
+#ifdef USE_SDL
+ runSDL();
+#endif
+}
+
+EventManager::~EventManager(){
+}
+
+void EventManager::dispatch(Event type){
+ switch (type){
+ case CloseWindow : {
+ throw ShutdownException();
+ }
+ }
+}
+
+}
diff --git a/util/events.h b/util/events.h
new file mode 100644
index 00000000..9855f6f9
--- /dev/null
+++ b/util/events.h
@@ -0,0 +1,31 @@
+#ifndef _paintown_events_h
+#define _paintown_events_h
+
+/* handles global events from the system such as
+ * window manager events (press X button)
+ * keyboard/mouse/joystick input (for some backends like SDL)
+ */
+
+namespace Util{
+
+class EventManager{
+public:
+ EventManager();
+ virtual void run();
+ virtual ~EventManager();
+
+private:
+ enum Event{
+ CloseWindow
+ };
+
+ virtual void dispatch(Event type);
+
+#ifdef USE_SDL
+ virtual void runSDL();
+#endif
+};
+
+}
+
+#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 12:46 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69096
Default Alt Text
(1 KB)

Event Timeline