mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 10:46:51 -07:00
Add Touch Tracking Functions to Controller State
This commit is contained in:
parent
cd3d700df8
commit
7d4cbccfbf
2 changed files with 53 additions and 0 deletions
|
@ -85,6 +85,15 @@ typedef struct chiaki_controller_state_t
|
|||
|
||||
CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state);
|
||||
|
||||
/**
|
||||
* @return A non-negative newly allocated touch id allocated or -1 if there are no slots left
|
||||
*/
|
||||
CHIAKI_EXPORT int8_t chiaki_controller_state_start_touch(ChiakiControllerState *state, uint16_t x, uint16_t y);
|
||||
|
||||
CHIAKI_EXPORT void chiaki_controller_state_stop_touch(ChiakiControllerState *state, uint8_t id);
|
||||
|
||||
CHIAKI_EXPORT void chiaki_controller_state_set_touch_pos(ChiakiControllerState *state, uint8_t id, uint16_t x, uint16_t y);
|
||||
|
||||
static inline bool chiaki_controller_state_equals(ChiakiControllerState *a, ChiakiControllerState *b)
|
||||
{
|
||||
if(!(a->buttons == b->buttons
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include <chiaki/controller.h>
|
||||
|
||||
#define TOUCH_ID_MASK 0x7f
|
||||
|
||||
CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state)
|
||||
{
|
||||
state->buttons = 0;
|
||||
|
@ -26,6 +28,48 @@ CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state
|
|||
state->right_y = 0;
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT int8_t chiaki_controller_state_start_touch(ChiakiControllerState *state, uint16_t x, uint16_t y)
|
||||
{
|
||||
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||
{
|
||||
if(state->touches[i].id < 0)
|
||||
{
|
||||
state->touches[i].id = state->touch_id_next;
|
||||
state->touch_id_next = (state->touch_id_next + 1) & TOUCH_ID_MASK;
|
||||
state->touches[i].x = x;
|
||||
state->touches[i].y = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT void chiaki_controller_state_stop_touch(ChiakiControllerState *state, uint8_t id)
|
||||
{
|
||||
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||
{
|
||||
if(state->touches[i].id == id)
|
||||
{
|
||||
state->touches[i].id = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT void chiaki_controller_state_set_touch_pos(ChiakiControllerState *state, uint8_t id, uint16_t x, uint16_t y)
|
||||
{
|
||||
id &= TOUCH_ID_MASK;
|
||||
for(size_t i=0; i<CHIAKI_CONTROLLER_TOUCHES_MAX; i++)
|
||||
{
|
||||
if(state->touches[i].id == id)
|
||||
{
|
||||
state->touches[i].x = x;
|
||||
state->touches[i].y = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define ABS(a) ((a) > 0 ? (a) : -(a))
|
||||
#define MAX_ABS(a, b) (ABS(a) > ABS(b) ? (a) : (b))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue