From 27e5ead579148b5ddfb6ad8ccd3eb28e4b71f777 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sat, 14 Jan 2023 23:30:39 +0100 Subject: [PATCH] separate input handling --- input.c | 40 ++++++++++++++++++++++++++++++++++++++++ test/Makefile | 5 +++-- ugui.c | 38 -------------------------------------- 3 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 input.c diff --git a/input.c b/input.c new file mode 100644 index 0000000..4eff88b --- /dev/null +++ b/input.c @@ -0,0 +1,40 @@ +#include "ugui.h" + +/*=============================================================================* + * Input Handling * + *=============================================================================*/ + + +#define TEST_CTX(ctx) { if (!ctx) return -1; } + + +int ug_input_mousemove(ug_ctx_t *ctx, int x, int y) +{ + TEST_CTX(ctx) + if (x < 0 || y < 0) + return 0; + + ctx->mouse.pos = (ug_vec2_t){.x = x, .y = y}; + + return 0; +} + + +int ug_input_mousedown(ug_ctx_t *ctx, unsigned int mask) +{ + TEST_CTX(ctx); + + ctx->mouse.update |= mask; + + return 0; +} + + +int ug_input_mouseup(ug_ctx_t *ctx, unsigned int mask) +{ + TEST_CTX(ctx); + + ctx->mouse.update |= mask; + + return 0; +} diff --git a/test/Makefile b/test/Makefile index 1deee1c..aa3facf 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,10 +1,11 @@ CFLAGS = -Wall -Wextra -Wpedantic -std=c11 -g LDFLAGS = -lSDL2 -lm -test: main.c ../ugui.c ../ugui.h ../def_style.h +test: main.c ../ugui.c ../ugui.h ../def_style.h ../input.c gcc ${CFLAGS} -c ../ugui.c -o ugui.o + gcc ${CFLAGS} -c ../input.c -o input.o gcc ${CFLAGS} -c main.c -o main.o - gcc ${LDFLAGS} main.o ugui.o -o test + gcc ${LDFLAGS} main.o ugui.o input.o -o test clean: rm -f main.o ugui.o diff --git a/ugui.c b/ugui.c index cead3c6..ee9f32f 100644 --- a/ugui.c +++ b/ugui.c @@ -923,44 +923,6 @@ ug_rect_t ug_container_get_rect(ug_ctx_t *ctx, const char *name) } -/*=============================================================================* - * Input Handling * - *=============================================================================*/ - - -int ug_input_mousemove(ug_ctx_t *ctx, int x, int y) -{ - TEST_CTX(ctx) - if (x < 0 || y < 0) - return 0; - - ctx->mouse.pos = (ug_vec2_t){.x = x, .y = y}; - - return 0; -} - - -int ug_input_mousedown(ug_ctx_t *ctx, unsigned int mask) -{ - TEST_CTX(ctx); - - ctx->mouse.update |= mask; - - return 0; -} - - -int ug_input_mouseup(ug_ctx_t *ctx, unsigned int mask) -{ - TEST_CTX(ctx); - - ctx->mouse.update |= mask; - - return 0; -} - - - /*=============================================================================* * Frame Handling * *=============================================================================*/