aboutsummaryrefslogtreecommitdiff
path: root/src/cInput.h
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:04:57 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-03-06 15:04:57 +0100
commitf439ae911923ee70937592b1ee535e8e8e133808 (patch)
tree7e23e023d0187caf2d81b26217b3a484bd37f799 /src/cInput.h
parent6856fcf08c8c4686ddf9e5cb60862184e15d6f0b (diff)
downloadtermgl-f439ae911923ee70937592b1ee535e8e8e133808.tar.gz
Directory updates
Moved source files to ./src and exmaple and test to ./example Updated Makefile and .doxygen to use those directorys
Diffstat (limited to 'src/cInput.h')
-rw-r--r--src/cInput.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/cInput.h b/src/cInput.h
new file mode 100644
index 0000000..00ddb7d
--- /dev/null
+++ b/src/cInput.h
@@ -0,0 +1,58 @@
+#ifndef CINPUT_H_
+#define CINPUT_H_
+
+#include <stdio.h>
+#include <unistd.h>
+#include <termios.h>
+#include <sys/select.h>
+
+#ifdef __linux__
+#elif _WIN32
+ #error "Platforn not supported"
+#else
+ #error "Platforn not supported"
+#endif
+
+#define _EVENT_NULL 0
+#define _EVENT_CHAR 1
+#define _EVENT_KEY 2
+#define _EVENT_MOUSE 3
+#define _EVENT_TERM 4
+
+struct sInputEvent
+{
+ unsigned int type;
+ unsigned char c;
+ unsigned int b;
+ int x, y;
+};
+/**
+* ##cInput
+* * puts STDIN in raw mode
+* * activates mouse tracking
+* * reverts console back to normal operation on destruction.
+* Compatible with xterm compatible terminal emulators
+*/
+class cInput
+{
+public:
+ cInput();
+
+ ~cInput();
+
+ /** Reads inputevents
+ * returns event struct
+ * ### sInputEvent.type
+ * * _EVENT_NULL: No input recorded
+ * * _EVENT_CHAR: A Key was pressed, stored in .c
+ * * _EVENT_KEY: Escape sequence recorded, stored in .c without escape char
+ * * _EVENT_MOUSE: Console registered click at (.x, .y) with origin at (0,0) (top left). Mouse button stored in b.
+ * * _EVENT_TERM: Console registered Ctrl+C
+ */
+ sInputEvent poll();
+
+private:
+ struct termios original, raw;
+};
+
+#endif /* end of include guard: */