diff --git a/arm9/source/common/hid.c b/arm9/source/common/hid.c index 9b0cb63..0850bd7 100644 --- a/arm9/source/common/hid.c +++ b/arm9/source/common/hid.c @@ -106,21 +106,20 @@ bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, in return true; } -bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn) { - *id = 0; - - // read coordinates, check if inside touchbox - if (!HID_ReadTouchState(x, y)) return false; - for (u32 i = 0; i < tbn; i++) { +TouchBox* TouchBoxGet(u32* id, const u16 x, const u16 y, const TouchBox* tbs, const u32 tbn) { + // check if inside touchbox + for (u32 i = 0; !tbn || (i < tbn); i++) { const TouchBox* tb = tbs + i; - if ((*x >= tb->x) && (*y >= tb->y) && - (*x < tb->x + tb->w) && (*y < tb->y + tb->h)) { - *id = tb->id; - break; + if (tb->id == 0) break; + if ((x >= tb->x) && (y >= tb->y) && + (x < tb->x + tb->w) && (y < tb->y + tb->h)) { + if (id) *id = tb->id; + return tb; } } - return true; + if (id) *id = 0; + return NULL; } u32 InputWait(u32 timeout_sec) { diff --git a/arm9/source/common/hid.h b/arm9/source/common/hid.h index b8b5fad..74abbf3 100644 --- a/arm9/source/common/hid.h +++ b/arm9/source/common/hid.h @@ -32,10 +32,10 @@ typedef struct { u16 w; u16 h; u32 id; // shouldn't be zero -} __attribute__((packed)) TouchBox; +} TouchBox; // 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); bool CheckButton(u32 button); diff --git a/arm9/source/utils/paint9.c b/arm9/source/utils/paint9.c index 8d7603f..aa43a6b 100644 --- a/arm9/source/utils/paint9.c +++ b/arm9/source/utils/paint9.c @@ -169,9 +169,10 @@ u32 Paint9(void) { u16 tx, ty; 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, "Touchscreen coordinates (%d/%d) ", tx, ty); + TouchBoxGet(&tb_id, tx, ty, paint9_boxes, 8); if (tb_id == P9BOX_CANVAS) { Paint9_DrawBrush(tx, ty, color, COLOR_TRANSPARENT, brush_id); continue;