aboutsummaryrefslogtreecommitdiffstats
path: root/src/window/EventsManager.hpp
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-03-26 20:30:13 +0000
committerJoursoir <chat@joursoir.net>2021-03-26 20:30:13 +0000
commit7f7123ef4ca5e37da45907eeb7f29ed15e535dce (patch)
treec1ac4e1ac3af95aba2e0b53ec3b37748ea932f84 /src/window/EventsManager.hpp
parentaee5bf7802f112111961faa824deb6f97ef80203 (diff)
downloadspace-simulator-7f7123ef4ca5e37da45907eeb7f29ed15e535dce.tar.gz
space-simulator-7f7123ef4ca5e37da45907eeb7f29ed15e535dce.tar.bz2
space-simulator-7f7123ef4ca5e37da45907eeb7f29ed15e535dce.zip
add events manager
Diffstat (limited to 'src/window/EventsManager.hpp')
-rw-r--r--src/window/EventsManager.hpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/window/EventsManager.hpp b/src/window/EventsManager.hpp
new file mode 100644
index 0000000..29a4524
--- /dev/null
+++ b/src/window/EventsManager.hpp
@@ -0,0 +1,93 @@
+#ifndef ENGINE_EVENTSMANAGER_H
+#define ENGINE_EVENTSMANAGER_H
+
+class Events;
+
+enum em_listen {
+ EM_LISTEN_KEY = 1,
+ EM_LISTEN_CURSOR = 2,
+ EM_LISTEN_MBUTTON = 4,
+ EM_LISTEN_WINDOWSIZE = 8,
+ EM_LISTEN_MSCROLL = 16
+};
+
+struct lStorage {
+ Events **list;
+ GLFWwindow **win;
+ int *listen_events;
+ int max_n;
+
+ lStorage(int n) : max_n(n)
+ {
+ int i;
+ list = new Events*[n];
+ win = new GLFWwindow*[n];
+ listen_events = new int[n];
+ for(i = 0; i < n; i++) {
+ list[i] = 0;
+ win[i] = 0;
+ listen_events[i] = 0;
+ }
+ }
+
+ ~lStorage()
+ {
+ delete[] list;
+ delete[] win;
+ delete[] listen_events;
+ }
+
+ void Add(Events *e, GLFWwindow *w, int listen)
+ {
+ int i;
+ for(i = 0; i < max_n; i++) {
+ if(list[i] == 0) {
+ list[i] = e;
+ win[i] = w;
+ listen_events[i] = listen;
+ break;
+ }
+ }
+
+ // realloc memory:
+ Events **tmp_list = list;
+ GLFWwindow **tmp_win = win;
+ int *tmp_levents = listen_events;
+
+ list = new Events*[max_n + 1];
+ win = new GLFWwindow*[max_n + 1];
+ listen_events = new int[max_n + 1];
+
+ for(i = 0; i < max_n; i++) {
+ list[i] = tmp_list[i];
+ win[i] = tmp_win[i];
+ listen_events[i] = tmp_levents[i];
+ }
+ list[max_n] = e;
+ win[max_n] = w;
+ tmp_levents[max_n] = listen;
+
+ delete[] tmp_list;
+ delete[] tmp_win;
+ delete[] tmp_levents;
+ }
+};
+
+class EventsManager {
+ static struct lStorage listeners;
+
+public:
+ static void PollEvents();
+ static void AddListener(Events *e, int listen);
+
+private:
+ EventsManager() { }
+
+ static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mode);
+ static void cursor_pos_callback(GLFWwindow *window, double xpos, double ypos);
+ static void mouse_button_callback(GLFWwindow *window, int button, int action, int mode);
+ static void window_size_callback(GLFWwindow *window, int width, int height);
+ static void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
+};
+
+#endif /* ENGINE_EVENTSMANAGER_H */