separate input handling
This commit is contained in:
parent
b34de18b64
commit
27e5ead579
40
input.c
Normal file
40
input.c
Normal file
@ -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;
|
||||
}
|
@ -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
|
||||
|
38
ugui.c
38
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 *
|
||||
*=============================================================================*/
|
||||
|
Loading…
Reference in New Issue
Block a user