From c3152838db850d94af918338f8bdfd5d7929292e Mon Sep 17 00:00:00 2001 From: d0k3 Date: Fri, 3 May 2019 01:37:41 +0200 Subject: [PATCH] Move touchbox functions to hid.c / hid.h --- arm9/source/common/hid.c | 17 +++++++++++++++++ arm9/source/common/hid.h | 11 +++++++++++ arm9/source/common/touchui.c | 20 -------------------- arm9/source/common/touchui.h | 15 --------------- arm9/source/utils/paint9.c | 1 - 5 files changed, 28 insertions(+), 36 deletions(-) delete mode 100644 arm9/source/common/touchui.c delete mode 100644 arm9/source/common/touchui.h diff --git a/arm9/source/common/hid.c b/arm9/source/common/hid.c index 4ca9c8f..3dfb271 100644 --- a/arm9/source/common/hid.c +++ b/arm9/source/common/hid.c @@ -106,6 +106,23 @@ 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++) { + 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; + } + } + + return true; +} + u32 InputWait(u32 timeout_sec) { static u64 delay = 0; u64 timer = timer_start(); diff --git a/arm9/source/common/hid.h b/arm9/source/common/hid.h index c2619fb..b8b5fad 100644 --- a/arm9/source/common/hid.h +++ b/arm9/source/common/hid.h @@ -26,6 +26,17 @@ u32 HID_ReadRawTouchState(void); bool HID_ReadTouchState(u16 *x, u16 *y); bool HID_SetCalibrationData(const HID_CalibrationData *calibs, int point_cnt, int screen_w, int screen_h); +typedef struct { + u16 x; + u16 y; + u16 w; + u16 h; + u32 id; // shouldn't be zero +} __attribute__((packed)) 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); + u32 InputWait(u32 timeout_sec); bool CheckButton(u32 button); diff --git a/arm9/source/common/touchui.c b/arm9/source/common/touchui.c deleted file mode 100644 index 80e93fd..0000000 --- a/arm9/source/common/touchui.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "touchui.h" -#include "hid.h" - - -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++) { - 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; - } - } - - return true; -} diff --git a/arm9/source/common/touchui.h b/arm9/source/common/touchui.h deleted file mode 100644 index 787686e..0000000 --- a/arm9/source/common/touchui.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "common.h" - - -typedef struct { - u16 x; - u16 y; - u16 w; - u16 h; - u32 id; // shouldn't be zero -} __attribute__((packed)) TouchBox; - -// this assumes the touchscreen is actually in use -bool TouchBoxGet(u16* x, u16* y, u32* id, const TouchBox* tbs, const u32 tbn); diff --git a/arm9/source/utils/paint9.c b/arm9/source/utils/paint9.c index fa88412..8d7603f 100644 --- a/arm9/source/utils/paint9.c +++ b/arm9/source/utils/paint9.c @@ -1,5 +1,4 @@ #include "paint9.h" -#include "touchui.h" #include "hid.h" #include "ui.h"