forked from Mirror/GodMode9
Change how TouchboxGet() works
This commit is contained in:
parent
f4fc17f145
commit
ca8c2070f5
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user