mirror of
https://github.com/joel16/3DShell.git
synced 2024-11-23 11:39:47 +00:00
touch: Enable touch controls for menu icons
This commit is contained in:
parent
6aa65f2f39
commit
d697ba4155
13
include/touch.h
Normal file
13
include/touch.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef _3D_SHELL_TOUCH_H
|
||||
#define _3D_SHELL_TOUCH_H
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
namespace Touch {
|
||||
void Update(void);
|
||||
u16 GetX(void);
|
||||
u16 GetY(void);
|
||||
bool Rect(u16 x, u16 y, u16 w, u16 h);
|
||||
}
|
||||
|
||||
#endif
|
@ -136,7 +136,5 @@ namespace GUI {
|
||||
}
|
||||
else if (*kDown & KEY_X)
|
||||
item->state = MENU_STATE_OPTIONS;
|
||||
else if (*kDown & KEY_SELECT)
|
||||
item->state = MENU_STATE_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "fs.h"
|
||||
#include "gui.h"
|
||||
#include "textures.h"
|
||||
#include "touch.h"
|
||||
#include "utils.h"
|
||||
|
||||
jmp_buf exit_jmp;
|
||||
@ -86,6 +87,15 @@ namespace GUI {
|
||||
C2D::Image(icon_search, 300, 0);
|
||||
}
|
||||
|
||||
static void ControlTouchButtons(MenuItem *item, u32 *kDown) {
|
||||
if ((*kDown & KEY_TOUCH) && (Touch::Rect(0, 0, 22, 20)))
|
||||
item->state = MENU_STATE_FILEBROWSER;
|
||||
else if ((*kDown & KEY_TOUCH) && (Touch::Rect(23, 0, 47, 20)))
|
||||
item->state = MENU_STATE_OPTIONS;
|
||||
else if ((*kDown & KEY_TOUCH) && (Touch::Rect(48, 0, 72, 20)))
|
||||
item->state = MENU_STATE_SETTINGS;
|
||||
}
|
||||
|
||||
Result Loop(void) {
|
||||
Result ret = 0;
|
||||
|
||||
@ -165,6 +175,9 @@ namespace GUI {
|
||||
break;
|
||||
}
|
||||
|
||||
Touch::Update();
|
||||
GUI::ControlTouchButtons(&item, &kDown);
|
||||
|
||||
if ((kDown & KEY_START) || (setjmp(exit_jmp)))
|
||||
break;
|
||||
}
|
||||
|
21
source/touch.cpp
Normal file
21
source/touch.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "touch.h"
|
||||
|
||||
namespace Touch {
|
||||
static touchPosition position;
|
||||
|
||||
void Update(void) {
|
||||
hidTouchRead(&position);
|
||||
}
|
||||
|
||||
u16 GetX(void) {
|
||||
return position.px;
|
||||
}
|
||||
|
||||
u16 GetY(void) {
|
||||
return position.py;
|
||||
}
|
||||
|
||||
bool Rect(u16 x, u16 y, u16 w, u16 h) {
|
||||
return ((Touch::GetX() >= (x) && Touch::GetX() <= (w)) && (Touch::GetY() >= (y) && Touch::GetY() <= (h)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user