Fumofumotris/source/fumoengine/input/platforms/parseinput.c

48 lines
895 B
C
Raw Normal View History

2024-04-24 23:37:47 +00:00
#include "parseinput.h"
2024-04-30 21:41:31 +00:00
2024-05-10 07:38:08 +00:00
void ReadButton(struct InputRecord *rec, u16f code, bool is_down)
2024-04-24 23:37:47 +00:00
{
2024-05-10 07:38:08 +00:00
rec->code = code;
2024-05-09 05:32:58 +00:00
rec->type = BUTTON;
2024-04-24 23:37:47 +00:00
rec->is_down = is_down;
}
2024-05-10 07:38:08 +00:00
void ReadAxis(struct InputRecord *rec, u16f code, u64 value)
2024-04-24 23:37:47 +00:00
{
2024-05-10 07:38:08 +00:00
rec->code = code;
2024-05-09 05:32:58 +00:00
rec->type = AXIS;
2024-05-10 07:38:08 +00:00
rec->data.axis.value = value;
2024-04-24 23:37:47 +00:00
}
2024-05-10 07:38:08 +00:00
void ReadJoystick(struct InputRecord *rec, u16f code, i32 x, i32 y)
2024-04-24 23:37:47 +00:00
{
2024-05-10 07:38:08 +00:00
rec->code = code;
2024-05-09 05:32:58 +00:00
rec->type = JOYSTICK;
2024-05-10 07:38:08 +00:00
rec->data.js.x = x;
rec->data.js.y = y;
}
size_t UCS2ToUTF8(char *buf, u16f ucs2)
2024-05-09 05:32:58 +00:00
{
if (ucs2 < 0xFF) {
buf[0] = ucs2;
return 1;
}
if (ucs2 < 0x7FF) {
buf[0] = 0xC0 + (ucs2 >> 6);
buf[1] = 0x80 + (ucs2 & 0x3F);
return 2;
}
2024-05-10 07:38:08 +00:00
else {
buf[0] = 0xE0 + (ucs2 >> 12);
buf[1] = 0x80 + ((ucs2 >> 6) & 0x3F);
buf[2] = 0x80 + (ucs2 & 0x3F);
return 3;
}
2024-04-24 23:37:47 +00:00
}