summaryrefslogtreecommitdiff
path: root/src/ctrl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ctrl')
-rw-r--r--src/ctrl/src/input.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/ctrl/src/input.c b/src/ctrl/src/input.c
index 5fe643e..cbfd576 100644
--- a/src/ctrl/src/input.c
+++ b/src/ctrl/src/input.c
@@ -1,8 +1,10 @@
+#include <errno.h>
+#include <string.h>
+
#include <engine/core/dltools.h>
#include <engine/core/logging.h>
#include <engine/core/platform.h>
#include <engine/ctrl/input.h>
-#include <string.h>
extern input_callback_t* callbacks[128];
extern usize callbacks_len;
@@ -330,3 +332,59 @@ void i_bind_alt(binding_t* b, scancode_t s) {
b->scancode_alt = s;
}
+
+/* Pushes an input context onto the input handling stack */
+void i_ctx_push(i_ctx* ctx) {
+ if (GLOBAL_PLATFORM->bindings == NULL) {
+ GLOBAL_PLATFORM->bindings = calloc(8, sizeof(i_ctx*));
+ GLOBAL_PLATFORM->bindings_sz = 8;
+ }
+
+ if (GLOBAL_PLATFORM->bindings_len + 1 >= GLOBAL_PLATFORM->bindings_sz) {
+ void* m =
+ realloc(GLOBAL_PLATFORM->bindings, GLOBAL_PLATFORM->bindings_sz + 8);
+ if (m == NULL) {
+ ERROR("Failed to allocate 8 bytes (%d): %s", errno, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ GLOBAL_PLATFORM->bindings_sz += 8;
+ }
+
+ LOG("Bindings in ctx[%d]:", GLOBAL_PLATFORM->bindings_len);
+ for (isize i = 0; i < ctx->len; i++) {
+ switch (ctx->bindings[i].action.type) {
+ case InputType_error:
+ LOG("(error)");
+ break;
+
+ case InputType_action:
+ LOG("(action) %s", ctx->bindings[i].action.action.callback_str);
+ break;
+
+ case InputType_state:
+ LOG("(+state) %s", ctx->bindings[i].action.state.activate_str);
+ LOG("(-state) %s", ctx->bindings[i].action.state.deactivate_str);
+ break;
+
+ case InputType_range:
+ LOG("(range) --unhandled--");
+ break;
+ }
+ }
+
+ GLOBAL_PLATFORM->bindings[GLOBAL_PLATFORM->bindings_len++] = ctx;
+}
+
+/* Pops an input context from the input stack */
+void i_ctx_pop(void) {
+ if (GLOBAL_PLATFORM->bindings == NULL || GLOBAL_PLATFORM->bindings_sz == 0)
+ return;
+ i_ctx_t_free(GLOBAL_PLATFORM->bindings[--GLOBAL_PLATFORM->bindings_len]);
+}
+
+/* Removes all input contexts from the input stack */
+void i_ctx_reset(void) {
+ while (GLOBAL_PLATFORM->bindings_len > 0) {
+ i_ctx_t_free(GLOBAL_PLATFORM->bindings[--GLOBAL_PLATFORM->bindings_len]);
+ }
+}