Change how TouchboxGet() works

This commit is contained in:
d0k3 2019-05-08 23:14:11 +02:00
parent f4fc17f145
commit ca8c2070f5
3 changed files with 14 additions and 14 deletions

View File

@ -106,21 +106,20 @@ bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, in
return true; return true;
} }
bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn) { TouchBox* TouchBoxGet(u32* id, const u16 x, const u16 y, const TouchBox* tbs, const u32 tbn) {
*id = 0; // check if inside touchbox
for (u32 i = 0; !tbn || (i < tbn); i++) {
// read coordinates, check if inside touchbox
if (!HID_ReadTouchState(x, y)) return false;
for (u32 i = 0; i < tbn; i++) {
const TouchBox* tb = tbs + i; const TouchBox* tb = tbs + i;
if ((*x >= tb->x) && (*y >= tb->y) && if (tb->id == 0) break;
(*x < tb->x + tb->w) && (*y < tb->y + tb->h)) { if ((x >= tb->x) && (y >= tb->y) &&
*id = tb->id; (x < tb->x + tb->w) && (y < tb->y + tb->h)) {
break; if (id) *id = tb->id;
return tb;
} }
} }
return true; if (id) *id = 0;
return NULL;
} }
u32 InputWait(u32 timeout_sec) { u32 InputWait(u32 timeout_sec) {

View File

@ -32,10 +32,10 @@ typedef struct {
u16 w; u16 w;
u16 h; u16 h;
u32 id; // shouldn't be zero u32 id; // shouldn't be zero
} __attribute__((packed)) TouchBox; } TouchBox;
// abstraction for HID_ReadTouchState, also returns touchbox id (if any) // abstraction for HID_ReadTouchState, also returns touchbox id (if any)
bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn); TouchBox* TouchBoxGet(u32* id, const u16 x, const u16 y, const TouchBox* tbs, const u32 tbn);
u32 InputWait(u32 timeout_sec); u32 InputWait(u32 timeout_sec);
bool CheckButton(u32 button); bool CheckButton(u32 button);

View File

@ -169,9 +169,10 @@ u32 Paint9(void) {
u16 tx, ty; u16 tx, ty;
u32 tb_id; u32 tb_id;
while (TouchBoxGet(&tx, &ty, &tb_id, paint9_boxes, 8)) { while (HID_ReadTouchState(&tx, &ty)) {
DrawStringF(TOP_SCREEN, 16, 16, COLOR_STD_FONT, COLOR_STD_BG, DrawStringF(TOP_SCREEN, 16, 16, COLOR_STD_FONT, COLOR_STD_BG,
"Touchscreen coordinates (%d/%d) ", tx, ty); "Touchscreen coordinates (%d/%d) ", tx, ty);
TouchBoxGet(&tb_id, tx, ty, paint9_boxes, 8);
if (tb_id == P9BOX_CANVAS) { if (tb_id == P9BOX_CANVAS) {
Paint9_DrawBrush(tx, ty, color, COLOR_TRANSPARENT, brush_id); Paint9_DrawBrush(tx, ty, color, COLOR_TRANSPARENT, brush_id);
continue; continue;