summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/engine/engine.c31
-rw-r--r--src/main/engine/engine.h5
-rw-r--r--src/main/ui/ui.h1
-rw-r--r--src/main/ui/x11/ui.c16
4 files changed, 53 insertions, 0 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c
index e45909a..e0da00c 100644
--- a/src/main/engine/engine.c
+++ b/src/main/engine/engine.c
@@ -21,6 +21,11 @@
#include <time.h>
#include <GL/gl.h>
#include "../ui/ui.h"
+#include "engine.h"
+
+#ifdef X11
+#include <X11/Xlib.h>
+#endif
#define RANGE_GL 2.0f
@@ -40,6 +45,8 @@ static time_t start;
static int frames;
static time_t end;
+void (*dispatch_ui_event)(int);
+
void
engine_init(int w, int h)
{
@@ -100,3 +107,27 @@ engine_loop(void (*draw_frame)())
ui_loop();
}
+
+static void
+engine_dispatch_ui_events(int type)
+{
+ int event_type = 0;
+ switch (type) {
+#ifdef X11
+ case ButtonPress:
+ event_type = ENGINE_MOUSE_PRESSED;
+ break;
+#endif
+ default:
+ event_type = 0;
+ break;
+ }
+ dispatch_ui_event(event_type);
+}
+
+void
+engine_input(void (*f_input)(int engine_input))
+{
+ ui_set_generic_listener(engine_dispatch_ui_events);
+ dispatch_ui_event = f_input;
+}
diff --git a/src/main/engine/engine.h b/src/main/engine/engine.h
index 691d8ec..fc4c5b9 100644
--- a/src/main/engine/engine.h
+++ b/src/main/engine/engine.h
@@ -20,8 +20,13 @@
#ifndef __ENGINE_H__
#define __ENGINE_H__
+enum EngineInput {
+ ENGINE_MOUSE_PRESSED = 4
+};
+
void engine_init(int width, int height);
void engine_draw_line(int x1, int y1, int x2, int y2);
void engine_loop(void (*draw_frame)());
+void engine_input(void (*f_input)(int engine_input));
#endif /* __ENGINE_H__ */
diff --git a/src/main/ui/ui.h b/src/main/ui/ui.h
index fcdd99f..06cd515 100644
--- a/src/main/ui/ui.h
+++ b/src/main/ui/ui.h
@@ -25,5 +25,6 @@ void ui_loop(void);
void ui_set_title(const char *title);
void ui_set_loop_listener(void (*event)());
void ui_set_mouse_press_listener(void (*event)());
+void ui_set_generic_listener(void (*generic_event)(int type));
#endif /* __UI_H__ */
diff --git a/src/main/ui/x11/ui.c b/src/main/ui/x11/ui.c
index fc59e4e..69bd5be 100644
--- a/src/main/ui/x11/ui.c
+++ b/src/main/ui/x11/ui.c
@@ -33,6 +33,7 @@ static int close_window = 0;
void (*on_loop_event)();
void (*on_mouse_press_event)();
+void (*on_generic_event)(int);
void cleanup(void);
@@ -143,6 +144,14 @@ ui_on_mouse_release(XEvent event)
if (event.type != ButtonRelease) return;
}
+static void
+ui_on_generic_event(XEvent event)
+{
+ if (on_generic_event != NULL) {
+ on_generic_event(event.type);
+ }
+}
+
void
ui_set_loop_listener(void (*loop_event)())
{
@@ -156,12 +165,19 @@ ui_set_mouse_press_listener(void (*mouse_press_event)())
}
void
+ui_set_generic_listener(void (*generic_event)(int type))
+{
+ on_generic_event = generic_event;
+}
+
+void
ui_loop(void)
{
XEvent event;
while (!close_window) {
while (XPending(display)) {
XNextEvent(display, &event);
+ ui_on_generic_event(event);
ui_on_expose(event);
ui_on_resize(event);
ui_on_keypress(event);