Handle touching the message boxes.

This commit is contained in:
Steven Mattera 2018-05-29 20:37:06 -04:00
parent afbf85a65f
commit 5f04f106cf
6 changed files with 34 additions and 16 deletions

View File

@ -57,6 +57,7 @@ typedef union {
#include "nanojpeg.h"
#include "math.h"
#include "theme.h"
#include "message-box.h"
void menuStartup();
void menuLoop();

View File

@ -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);

View File

@ -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;
}

15
common/message-box.h Normal file
View File

@ -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();

View File

@ -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);

View File

@ -1,6 +1,7 @@
#pragma once
#include <switch.h>
#include "../common/common.h"
struct touchInfo_s {
touchPosition* firstTouch;
@ -9,3 +10,5 @@ struct touchInfo_s {
int initMenuXPos;
int initMenuIndex;
};
void handleTouch(menu_s* menu);