From 5f04f106cfb24c541d945d145177023c70f309aa Mon Sep 17 00:00:00 2001 From: Steven Mattera Date: Tue, 29 May 2018 20:37:06 -0400 Subject: [PATCH] Handle touching the message boxes. --- common/common.h | 1 + common/menu.h | 5 ----- common/message-box.c | 13 +++++-------- common/message-box.h | 15 +++++++++++++++ nx_main/nx_touch.c | 11 +++++++++-- nx_main/nx_touch.h | 5 ++++- 6 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 common/message-box.h diff --git a/common/common.h b/common/common.h index c837087..4457ab5 100644 --- a/common/common.h +++ b/common/common.h @@ -57,6 +57,7 @@ typedef union { #include "nanojpeg.h" #include "math.h" #include "theme.h" +#include "message-box.h" void menuStartup(); void menuLoop(); diff --git a/common/menu.h b/common/menu.h index 1d94ff0..baae21e 100644 --- a/common/menu.h +++ b/common/menu.h @@ -74,11 +74,6 @@ double menuTimer; extern "C" { #endif -void menuCreateMsgBox(int width, int height, const char *text); -void menuCloseMsgBox(); -bool menuIsMsgBoxOpen(); -void menuDrawMsgBox(void); - void menuEntryInit(menuEntry_s* me, MenuEntryType type); void menuEntryFree(menuEntry_s* me); bool fileExists(const char* path); diff --git a/common/message-box.c b/common/message-box.c index cd826ef..d5bee7d 100644 --- a/common/message-box.c +++ b/common/message-box.c @@ -1,12 +1,5 @@ #include "common.h" - -typedef struct -{ - uint32_t width; - uint32_t height; - color_t *bg; - char *text; -} MessageBox; +#include "message-box.h" MessageBox currMsgBox; @@ -177,3 +170,7 @@ void menuCloseMsgBox() { currMsgBox.text = NULL; } } + +MessageBox menuGetCurrentMsgBox() { + return currMsgBox; +} diff --git a/common/message-box.h b/common/message-box.h new file mode 100644 index 0000000..7c62304 --- /dev/null +++ b/common/message-box.h @@ -0,0 +1,15 @@ +#pragma once + +typedef struct +{ + uint32_t width; + uint32_t height; + color_t *bg; + char *text; +} MessageBox; + +void menuCreateMsgBox(int width, int height, const char *text); +void menuCloseMsgBox(); +bool menuIsMsgBoxOpen(); +void menuDrawMsgBox(void); +MessageBox menuGetCurrentMsgBox(); diff --git a/nx_main/nx_touch.c b/nx_main/nx_touch.c index 271131e..d94a7f2 100644 --- a/nx_main/nx_touch.c +++ b/nx_main/nx_touch.c @@ -1,5 +1,4 @@ #include "nx_touch.h" -#include "../common/common.h" #define TAP_MOVEMENT_GAP 20 #define LISTING_START_Y 475 @@ -73,7 +72,15 @@ void handleTouch(menu_s* menu) { // On touch end. else if (touchInfo.firstTouch != NULL) { if (menuIsMsgBoxOpen()) { - // Handle tapping ok. + MessageBox currMsgBox = menuGetCurrentMsgBox(); + int start_x = 1280 / 2 - currMsgBox.width / 2; + int start_y = (720 / 2 - currMsgBox.height / 2) + (currMsgBox.height - 80); + int end_x = start_x + currMsgBox.width; + int end_y = start_y + 80; + + if (touchInfo.firstTouch->px > start_x && touchInfo.firstTouch->px < end_x && touchInfo.firstTouch->py > start_y && touchInfo.firstTouch->py < end_y && touchInfo.isTap) { + menuCloseMsgBox(); + } } else { if (touchInfo.firstTouch->py > LISTING_START_Y && touchInfo.firstTouch->py < LISTING_END_Y && touchInfo.isTap) { handleTap(menu, touchInfo.prevTouch->px); diff --git a/nx_main/nx_touch.h b/nx_main/nx_touch.h index 910d88b..30a3056 100644 --- a/nx_main/nx_touch.h +++ b/nx_main/nx_touch.h @@ -1,6 +1,7 @@ #pragma once #include +#include "../common/common.h" struct touchInfo_s { touchPosition* firstTouch; @@ -8,4 +9,6 @@ struct touchInfo_s { bool isTap; int initMenuXPos; int initMenuIndex; -}; \ No newline at end of file +}; + +void handleTouch(menu_s* menu); \ No newline at end of file