Touch controls (#2)

* Basic foundation for touch controls. Menus touchable.

* Touch controls for settings and menu bar.

* Fixed bug tapping "Ok" in properties.

* Fixed long press. Added NxLink debugging.

* Basic snappy scrolling.
This commit is contained in:
Steven Mattera 2018-06-11 21:48:07 -04:00 committed by Joel
parent a4e09fd6a2
commit 8aab1914a6
15 changed files with 420 additions and 71 deletions

13
.gitignore vendored Normal file
View File

@ -0,0 +1,13 @@
*~
*.exe
*.o
test
tahoma12.c
tahoma24.c
*.zip
build
*.elf
*.nso
*.pfs0
*.nacp
*.nro

View File

@ -16,6 +16,7 @@ typedef struct File
extern File * files;
extern int initialPosition;
extern int position;
extern int fileCount;

View File

@ -1,6 +1,8 @@
#ifndef NX_SHELL_MENU_OPTIONS_H
#define NX_SHELL_MENU_OPTIONS_H
#include "touch_helper.h"
/*
* Copy Flags
*/
@ -10,10 +12,13 @@
#define NOTHING_TO_COPY -1
void Menu_ControlDeleteDialog(u64 input);
void Menu_TouchDeleteDialog(TouchInfo touchInfo);
void Menu_DisplayDeleteDialog(void);
void Menu_ControlProperties(u64 input);
void Menu_TouchProperties(TouchInfo touchInfo);
void Menu_DisplayProperties(void);
void Menu_ControlOptions(u64 input);
void Menu_TouchOptions(TouchInfo touchInfo);
void Menu_DisplayOptions(void);
#endif

View File

@ -1,12 +1,13 @@
#ifndef NX_SHELL_TEXTURES_H
#define NX_SHELL_TEXTURES_H
SDL_Texture *icon_app, *icon_archive, *icon_audio, *icon_dir, *icon_file, *icon_image, *icon_text, *icon_dir_dark, \
*icon_check, *icon_uncheck, *icon_check_dark, *icon_uncheck_dark, *icon_radio_off, *icon_radio_on, \
*icon_radio_dark_off, *icon_radio_dark_on, *icon_toggle_on, *icon_toggle_dark_on, *icon_toggle_off, \
*dialog, *options_dialog, *properties_dialog, *dialog_dark, *options_dialog_dark, *properties_dialog_dark, \
*bg_header, *icon_settings, *icon_sd, *icon_secure, *icon_settings_dark, *icon_sd_dark, *icon_secure_dark, \
*default_artwork, *btn_play, *btn_pause;
*default_artwork, *btn_play, *btn_pause, *icon_menu, *icon_back;
void Textures_Load(void);
void Textures_Free(void);

34
include/touch_helper.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef NX_SHELL_TOUCH_HELPER_H
#define NX_SHELL_TOUCH_HELPER_H
#include <switch.h>
#include <time.h>
#define tapped_inside(touchInfo, x1, y1, x2, y2) (touchInfo.firstTouch.px >= x1 && touchInfo.firstTouch.px <= x2 && touchInfo.firstTouch.py >= y1 && touchInfo.firstTouch.py <= y2)
#define tapped_outside(touchInfo, x1, y1, x2, y2) (touchInfo.firstTouch.px < x1 || touchInfo.firstTouch.px > x2 || touchInfo.firstTouch.py < y1 || touchInfo.firstTouch.py > y2)
typedef enum TouchState {
TouchNone,
TouchStart,
TouchMoving,
TouchEnded
} TouchState;
typedef enum TapType {
TapNone,
TapShort,
TapLong
} TapType;
typedef struct TouchInfo {
TouchState state;
touchPosition firstTouch;
touchPosition prevTouch;
TapType tapType;
u64 touchStart;
} TouchInfo;
void Touch_Init(TouchInfo * touchInfo);
void Touch_Process(TouchInfo * touchInfo);
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

View File

@ -13,6 +13,7 @@
#define TYPE_DIR(n) (n == DT_DIR ? 1 : 0)
int initialPosition = 0;
int position = 0; // menu position
int fileCount = 0; // file count
File * files = NULL; // file list
@ -253,6 +254,7 @@ void Dirbrowse_PopulateFiles(bool clear)
void Dirbrowse_DisplayFiles(void)
{
int title_height = 0;
SDL_DrawImage(RENDERER, icon_menu, 20, 66, 48, 48);
TTF_SizeText(Roboto_large, cwd, NULL, &title_height);
SDL_DrawText(Roboto_large, 170, 40 + ((100 - title_height)/2), WHITE, cwd);

View File

@ -1,6 +1,10 @@
#include <stdio.h>
#include <switch.h>
#ifdef DEBUG
#include <sys/socket.h>
#endif
#include "common.h"
#include "config.h"
#include "fs.h"
@ -22,6 +26,11 @@ static void Term_Services(void)
SDL_FreeSurface(WINDOW_SURFACE);
SDL_DestroyWindow(WINDOW);
#ifdef DEBUG
socketExit();
#endif
timeExit();
SDL_Quit();
romfsExit();
}
@ -30,6 +39,12 @@ static void Init_Services(void)
{
romfsInit();
SDL_Init(SDL_INIT_EVERYTHING);
timeInitialize();
#ifdef DEBUG
socketInitializeDefault();
nxlinkStdio();
#endif
SDL_CreateWindowAndRenderer(1280, 720, 0, &WINDOW, &RENDERER);

View File

@ -1,4 +1,5 @@
#include <switch.h>
#include <math.h>
#include "common.h"
#include "config.h"
@ -9,9 +10,11 @@
#include "SDL_helper.h"
#include "status_bar.h"
#include "textures.h"
#include "touch_helper.h"
#define MENUBAR_X_BOUNDARY 0
static int menubar_x = -400;
static TouchInfo touchInfo;
static void Menu_ControlMenuBar(u64 input)
{
@ -20,11 +23,21 @@ static void Menu_ControlMenuBar(u64 input)
if ((input & KEY_Y) || (input & KEY_B))
{
menubar_x = -400;
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
}
static void Menu_TouchMenuBar(TouchInfo touchInfo)
{
if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
if (touchInfo.firstTouch.px >= menubar_x + 400) {
MENU_DEFAULT_STATE = MENU_STATE_HOME;
} else if (tapped_inside(touchInfo, menubar_x + 20, 630, menubar_x + 80, 710)) {
MENU_DEFAULT_STATE = MENU_STATE_SETTINGS;
}
}
}
static void Menu_DisplayMenuBar(void)
{
SDL_DrawRect(RENDERER, menubar_x, 0, 400, 720, config_dark_theme? BLACK_BG : WHITE);
@ -39,7 +52,7 @@ static void Menu_DisplayMenuBar(void)
SDL_DrawImage(RENDERER, config_dark_theme? icon_settings_dark : icon_settings, menubar_x + 20, 640, 60, 60);
}
static void Menu_HomeControls(u64 input)
static void Menu_ControlHome(u64 input)
{
if (input & KEY_PLUS)
longjmp(exitJmp, 1);
@ -78,8 +91,10 @@ static void Menu_HomeControls(u64 input)
{
if (MENU_DEFAULT_STATE == MENU_STATE_MENUBAR)
MENU_DEFAULT_STATE = MENU_STATE_HOME;
else
else {
menubar_x = -400;
MENU_DEFAULT_STATE = MENU_STATE_MENUBAR;
}
}
if (input & KEY_A)
@ -96,25 +111,74 @@ static void Menu_HomeControls(u64 input)
}
}
static void Menu_TouchHome(TouchInfo touchInfo) {
if (touchInfo.state == TouchStart && tapped_inside(touchInfo, 0, 140, 1280, 720)) {
initialPosition = (position == 0) ? 7 : position;
}
else if (touchInfo.state == TouchMoving && touchInfo.tapType == TapNone && tapped_inside(touchInfo, 0, 140, 1280, 720)) {
int lastPosition = (strcmp(cwd, ROOT_PATH) == 0) ? fileCount - 2 : fileCount - 1;
position = initialPosition + floor(((double) touchInfo.firstTouch.py - (double) touchInfo.prevTouch.py) / 73);
if (position < 7) {
position = 7;
} else if (position >= lastPosition) {
position = lastPosition;
}
}
else if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
if (tapped_inside(touchInfo, 20, 66, 68, 114)) {
menubar_x = -400;
MENU_DEFAULT_STATE = MENU_STATE_MENUBAR;
}
else if (touchInfo.firstTouch.py >= 140)
{
int tapped_selection = floor(((double) touchInfo.firstTouch.py - 140) / 73);
if (position > 7) {
tapped_selection += position - 7;
}
position = tapped_selection;
if ((strcmp(cwd, ROOT_PATH) != 0 && position == 0) || touchInfo.tapType == TapShort) {
Dirbrowse_OpenFile();
} else if (touchInfo.tapType == TapLong) {
MENU_DEFAULT_STATE = MENU_STATE_OPTIONS;
}
}
}
}
static void Menu_Main_Controls(void)
{
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
Touch_Process(&touchInfo);
if (MENU_DEFAULT_STATE == MENU_STATE_HOME)
Menu_HomeControls(kDown);
else if (MENU_DEFAULT_STATE == MENU_STATE_OPTIONS)
if (MENU_DEFAULT_STATE == MENU_STATE_HOME) {
Menu_ControlHome(kDown);
Menu_TouchHome(touchInfo);
}
else if (MENU_DEFAULT_STATE == MENU_STATE_OPTIONS) {
Menu_ControlOptions(kDown);
else if (MENU_DEFAULT_STATE == MENU_STATE_PROPERTIES)
Menu_TouchOptions(touchInfo);
}
else if (MENU_DEFAULT_STATE == MENU_STATE_PROPERTIES) {
Menu_ControlProperties(kDown);
else if (MENU_DEFAULT_STATE == MENU_STATE_DIALOG)
Menu_TouchProperties(touchInfo);
}
else if (MENU_DEFAULT_STATE == MENU_STATE_DIALOG) {
Menu_ControlDeleteDialog(kDown);
else if (MENU_DEFAULT_STATE == MENU_STATE_MENUBAR)
Menu_TouchDeleteDialog(touchInfo);
}
else if (MENU_DEFAULT_STATE == MENU_STATE_MENUBAR) {
Menu_ControlMenuBar(kDown);
Menu_TouchMenuBar(touchInfo);
}
}
void Menu_Main(void)
{
Dirbrowse_PopulateFiles(false);
Touch_Init(&touchInfo);
while(appletMainLoop())
{

View File

@ -28,6 +28,14 @@ static char copysource[1024];
static int delete_dialog_selection = 0, row = 0, column = 0;
static bool copy_status = false, cut_status = false;
static int delete_width = 0, delete_height = 0;
static int delete_confirm_width = 0, delete_confirm_height = 0;
static int delete_cancel_width = 0, delete_cancel_height = 0;
static int properties_ok_width = 0, properties_ok_height = 0;
static int options_cancel_width = 0, options_cancel_height = 0;
static int FileOptions_RmdirRecursive(char *path)
{
File *filelist = NULL;
@ -364,6 +372,13 @@ static Result FileOptions_Paste(void)
return ret; // Return result
}
void HandleDelete() {
if (FileOptions_DeleteFile() == 0)
Dirbrowse_PopulateFiles(true);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
void Menu_ControlDeleteDialog(u64 input)
{
if (input & KEY_RIGHT)
@ -386,11 +401,7 @@ void Menu_ControlDeleteDialog(u64 input)
{
if (delete_dialog_selection == 0)
{
if (FileOptions_DeleteFile() == 0)
Dirbrowse_PopulateFiles(true);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
HandleDelete();
}
else
MENU_DEFAULT_STATE = MENU_STATE_OPTIONS;
@ -399,31 +410,45 @@ void Menu_ControlDeleteDialog(u64 input)
}
}
void Menu_TouchDeleteDialog(TouchInfo touchInfo)
{
if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
// Touched outside
if (tapped_outside(touchInfo, (1280 - delete_width) / 2, (720 - delete_height) / 2, (1280 + delete_width) / 2, (720 + delete_height) / 2)) {
MENU_DEFAULT_STATE = MENU_STATE_OPTIONS;
}
// Confirm Button
else if (tapped_inside(touchInfo, 1010 - delete_confirm_width, (720 - delete_height) / 2 + 225, 1050 + delete_confirm_width, (720 - delete_height) / 2 + 265 + delete_confirm_height)) {
HandleDelete();
}
// Cancel Button
else if (tapped_inside(touchInfo, 895 - delete_confirm_width, (720 - delete_height) / 2 + 225, 935 + delete_confirm_width, (720 - delete_height) / 2 + 265 + delete_cancel_height)) {
MENU_DEFAULT_STATE = MENU_STATE_OPTIONS;
}
}
}
void Menu_DisplayDeleteDialog(void)
{
int text_width = 0;
TTF_SizeText(Roboto, "Do you want to continue?", &text_width, NULL);
int confirm_width = 0, confirm_height = 0;
TTF_SizeText(Roboto, "YES", &confirm_width, &confirm_height);
TTF_SizeText(Roboto, "YES", &delete_confirm_width, &delete_confirm_height);
TTF_SizeText(Roboto, "NO", &delete_cancel_width, &delete_cancel_height);
int cancel_width = 0, cancel_height = 0;
TTF_SizeText(Roboto, "NO", &cancel_width, &cancel_height);
SDL_QueryTexture(dialog, NULL, NULL, &delete_width, &delete_height);
int width = 0, height = 0;
SDL_QueryTexture(dialog, NULL, NULL, &width, &height);
SDL_DrawImage(RENDERER, config_dark_theme? dialog_dark : dialog, ((1280 - (width)) / 2), ((720 - (height)) / 2), 880, 320);
SDL_DrawText(Roboto, ((1280 - (width)) / 2) + 80, ((720 - (height)) / 2) + 45, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "Confirm deletion");
SDL_DrawText(Roboto, ((1280 - (text_width)) / 2), ((720 - (height)) / 2) + 130, config_dark_theme? TEXT_MIN_COLOUR_DARK : TEXT_MIN_COLOUR_LIGHT, "Do you wish to continue?");
SDL_DrawImage(RENDERER, config_dark_theme? dialog_dark : dialog, ((1280 - (delete_width)) / 2), ((720 - (delete_height)) / 2), 880, 320);
SDL_DrawText(Roboto, ((1280 - (delete_width)) / 2) + 80, ((720 - (delete_height)) / 2) + 45, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "Confirm deletion");
SDL_DrawText(Roboto, ((1280 - (text_width)) / 2), ((720 - (delete_height)) / 2) + 130, config_dark_theme? TEXT_MIN_COLOUR_DARK : TEXT_MIN_COLOUR_LIGHT, "Do you wish to continue?");
if (delete_dialog_selection == 0)
SDL_DrawRect(RENDERER, (1030 - (confirm_width)) - 20, (((720 - (height)) / 2) + 245) - 20, confirm_width + 40, confirm_height + 40, config_dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
SDL_DrawRect(RENDERER, (1030 - (delete_confirm_width)) - 20, (((720 - (delete_height)) / 2) + 245) - 20, delete_confirm_width + 40, delete_confirm_height + 40, config_dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
else if (delete_dialog_selection == 1)
SDL_DrawRect(RENDERER, (915 - (confirm_width)) - 20, (((720 - (height)) / 2) + 245) - 20, confirm_width + 40, cancel_height + 40, config_dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
SDL_DrawRect(RENDERER, (915 - (delete_confirm_width)) - 20, (((720 - (delete_height)) / 2) + 245) - 20, delete_confirm_width + 40, delete_cancel_height + 40, config_dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
SDL_DrawText(Roboto, 1030 - (confirm_width), ((720 - (height)) / 2) + 245, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "YES");
SDL_DrawText(Roboto, 910 - (cancel_width), ((720 - (height)) / 2) + 245, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "NO");
SDL_DrawText(Roboto, 1030 - (delete_confirm_width), ((720 - (delete_height)) / 2) + 245, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "YES");
SDL_DrawText(Roboto, 910 - (delete_cancel_width), ((720 - (delete_height)) / 2) + 245, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "NO");
}
void Menu_ControlProperties(u64 input)
@ -432,6 +457,19 @@ void Menu_ControlProperties(u64 input)
MENU_DEFAULT_STATE = MENU_STATE_OPTIONS;
}
void Menu_TouchProperties(TouchInfo touchInfo)
{
if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
if (tapped_outside(touchInfo, 350, 85, 930, 635)) {
MENU_DEFAULT_STATE = MENU_STATE_OPTIONS;
}
// Ok Button
else if (tapped_inside(touchInfo, 870 - properties_ok_width, 575 - properties_ok_height, 910 + properties_ok_width, 615 + properties_ok_height)) {
MENU_DEFAULT_STATE = MENU_STATE_OPTIONS;
}
}
}
void Menu_DisplayProperties(void)
{
// Find File
@ -469,10 +507,47 @@ void Menu_DisplayProperties(void)
SDL_DrawText(Roboto, 390, 383, config_dark_theme? TEXT_MIN_COLOUR_DARK : TEXT_MIN_COLOUR_LIGHT, "Modified: ");
}*/
int width = 0, height = 0;
TTF_SizeText(Roboto, "OK", &width, &height);
SDL_DrawRect(RENDERER, (890 - width) - 20, (595 - height) - 20, width + 40, height + 40, config_dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
SDL_DrawText(Roboto, 890 - width, 595 - height, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "OK");
TTF_SizeText(Roboto, "OK", &properties_ok_width, &properties_ok_height);
SDL_DrawRect(RENDERER, (890 - properties_ok_width) - 20, (595 - properties_ok_height) - 20, properties_ok_width + 40, properties_ok_height + 40, config_dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
SDL_DrawText(Roboto, 890 - properties_ok_width, 595 - properties_ok_height, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "OK");
}
void HandleCopy()
{
if (copy_status == false && cut_status == false)
{
copy_status = true;
FileOptions_Copy(COPY_KEEP_ON_FINISH);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
else if (copy_status == true)
{
if (FileOptions_Paste() == 0)
{
copy_status = false;
Dirbrowse_PopulateFiles(true);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
}
}
void HandleCut()
{
if (cut_status == false && copy_status == false)
{
cut_status = true;
FileOptions_Copy(COPY_DELETE_ON_FINISH);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
else if (cut_status == true)
{
if (FileOptions_Paste() == 0)
{
cut_status = false;
Dirbrowse_PopulateFiles(true);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
}
}
void Menu_ControlOptions(u64 input)
@ -503,39 +578,11 @@ void Menu_ControlOptions(u64 input)
MENU_DEFAULT_STATE = MENU_STATE_PROPERTIES;
if (row == 1 && column == 1)
{
if (copy_status == false && cut_status == false)
{
copy_status = true;
FileOptions_Copy(COPY_KEEP_ON_FINISH);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
else if (copy_status == true)
{
if (FileOptions_Paste() == 0)
{
copy_status = false;
Dirbrowse_PopulateFiles(true);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
}
HandleCopy();
}
else if (row == 0 && column == 2)
{
if (cut_status == false && copy_status == false)
{
cut_status = true;
FileOptions_Copy(COPY_DELETE_ON_FINISH);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
else if (cut_status == true)
{
if (FileOptions_Paste() == 0)
{
cut_status = false;
Dirbrowse_PopulateFiles(true);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
}
HandleCut();
}
else if (row == 1 && column == 2)
MENU_DEFAULT_STATE = MENU_STATE_DIALOG;
@ -554,14 +601,60 @@ void Menu_ControlOptions(u64 input)
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
void Menu_TouchOptions(TouchInfo touchInfo)
{
if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
// Touched outside
if (tapped_outside(touchInfo, 350, 85, 930, 635)) {
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
// Column 0
else if (touchInfo.firstTouch.py >= 188 && touchInfo.firstTouch.py <= 289) {
// Row 0
if (touchInfo.firstTouch.px >= 354 && touchInfo.firstTouch.px <= 638) {
MENU_DEFAULT_STATE = MENU_STATE_PROPERTIES;
}
// Row 1
else if (touchInfo.firstTouch.px >= 639 && touchInfo.firstTouch.px <= 924) {
// TODO
}
}
// Column 1
else if (touchInfo.firstTouch.py >= 291 && touchInfo.firstTouch.py <= 392) {
// Row 0
if (touchInfo.firstTouch.px >= 354 && touchInfo.firstTouch.px <= 638) {
// TODO
}
// Row 1
else if (touchInfo.firstTouch.px >= 639 && touchInfo.firstTouch.px <= 924) {
HandleCopy();
}
}
// Column 2
else if (touchInfo.firstTouch.py >= 393 && touchInfo.firstTouch.py <= 494) {
// Row 0
if (touchInfo.firstTouch.px >= 354 && touchInfo.firstTouch.px <= 638) {
HandleCut();
}
// Row 1
else if (touchInfo.firstTouch.px >= 639 && touchInfo.firstTouch.px <= 924) {
MENU_DEFAULT_STATE = MENU_STATE_DIALOG;
}
}
// Cancel Button
else if (tapped_inside(touchInfo, 880 - options_cancel_width, 585 - options_cancel_height, 920 + options_cancel_width, 625 + options_cancel_height)) {
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}
}
}
void Menu_DisplayOptions(void)
{
SDL_DrawImage(RENDERER, config_dark_theme? options_dialog_dark : options_dialog, 350, 85, 580, 550);
SDL_DrawText(Roboto, 370, 133, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "Actions");
int width = 0, height = 0;
TTF_SizeText(Roboto, "CANCEL", &width, &height);
SDL_DrawText(Roboto, 900 - width, 605 - height, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "CANCEL");
TTF_SizeText(Roboto, "CANCEL", &options_cancel_width, &options_cancel_height);
SDL_DrawText(Roboto, 900 - options_cancel_width, 605 - options_cancel_height, config_dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "CANCEL");
if (row == 0 && column == 0)
SDL_DrawRect(RENDERER, 354, 188, 287, 101, config_dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);

View File

@ -1,3 +1,5 @@
#include <math.h>
#include "common.h"
#include "config.h"
#include "dirbrowse.h"
@ -5,10 +7,13 @@
#include "SDL_helper.h"
#include "status_bar.h"
#include "textures.h"
#include "touch_helper.h"
void Menu_DisplaySortSettings(void)
{
int selection = 0, max_items = 5, height = 0;
TouchInfo touchInfo;
Touch_Init(&touchInfo);
int title_height = 0;
TTF_SizeText(Roboto_large, "Settings", NULL, &title_height);
@ -35,7 +40,8 @@ void Menu_DisplaySortSettings(void)
StatusBar_DisplayTime();
SDL_DrawText(Roboto_large, 40, 40 + ((100 - title_height)/2), WHITE, "Sorting Options");
SDL_DrawImage(RENDERER, icon_back, 40, 66, 48, 48);
SDL_DrawText(Roboto_large, 128, 40 + ((100 - title_height)/2), WHITE, "Sorting Options");
int printed = 0; // Print counter
@ -77,6 +83,7 @@ void Menu_DisplaySortSettings(void)
SDL_RenderPresent(RENDERER);
hidScanInput();
Touch_Process(&touchInfo);
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_B)
@ -123,6 +130,41 @@ void Menu_DisplaySortSettings(void)
Config_Save(config_dark_theme, config_sort_by);
}
if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
if (tapped_inside(touchInfo, 40, 66, 108, 114))
{
break;
}
else if (touchInfo.firstTouch.py >= 140)
{
int tapped_selection = floor(((double) touchInfo.firstTouch.py - 140) / 73);
switch (tapped_selection)
{
case 0:
config_sort_by = 0;
break;
case 1:
config_sort_by = 1;
break;
case 2:
config_sort_by = 2;
break;
case 3:
config_sort_by = 3;
break;
case 4:
config_sort_by = 4;
break;
case 5:
config_sort_by = 5;
break;
}
Config_Save(config_dark_theme, config_sort_by);
}
}
}
Dirbrowse_PopulateFiles(true);
}
@ -130,6 +172,8 @@ void Menu_DisplaySortSettings(void)
void Menu_DisplaySettings(void)
{
int selection = 0, max_items = 2, height = 0;
TouchInfo touchInfo;
Touch_Init(&touchInfo);
int title_height = 0;
TTF_SizeText(Roboto_large, "Settings", NULL, &title_height);
@ -153,7 +197,8 @@ void Menu_DisplaySettings(void)
StatusBar_DisplayTime();
SDL_DrawText(Roboto_large, 40, 40 + ((100 - title_height)/2), WHITE, "Settings");
SDL_DrawImage(RENDERER, icon_back, 40, 66, 48, 48);
SDL_DrawText(Roboto_large, 128, 40 + ((100 - title_height)/2), WHITE, "Settings");
int printed = 0; // Print counter
@ -182,6 +227,7 @@ void Menu_DisplaySettings(void)
SDL_RenderPresent(RENDERER);
hidScanInput();
Touch_Process(&touchInfo);
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_B)
@ -215,7 +261,30 @@ void Menu_DisplaySettings(void)
break;
}
}
if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
if (tapped_inside(touchInfo, 40, 66, 108, 114)) {
break;
}
else if (touchInfo.firstTouch.py >= 140)
{
int tapped_selection = floor(((double) touchInfo.firstTouch.py - 140) / 73);
switch (tapped_selection)
{
case 1:
config_dark_theme = !config_dark_theme;
Config_Save(config_dark_theme, config_sort_by);
break;
case 2:
Menu_DisplaySortSettings();
break;
}
Config_Save(config_dark_theme, config_sort_by);
}
}
}
MENU_DEFAULT_STATE = MENU_STATE_MENUBAR;
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}

View File

@ -9,8 +9,9 @@ static char *Clock_GetCurrentTime(bool _12hour)
{
static char buffer[10];
time_t unix_time = time(NULL);
struct tm* time_struct = gmtime((const time_t *)&unix_time);
u64 current_time;
timeGetCurrentTime(TimeType_UserSystemClock, &current_time);
struct tm* time_struct = gmtime((const time_t *)&current_time);
int hours = time_struct->tm_hour;
int minutes = time_struct->tm_min;
int amOrPm = 0;

View File

@ -39,10 +39,14 @@ void Textures_Load(void)
SDL_LoadImage(RENDERER, &default_artwork, "romfs:/res/drawable/default_artwork.png");
SDL_LoadImage(RENDERER, &btn_play, "romfs:/res/drawable/btn_playback_play.png");
SDL_LoadImage(RENDERER, &btn_pause, "romfs:/res/drawable/btn_playback_pause.png");
SDL_LoadImage(RENDERER, &icon_menu, "romfs:/res/drawable/ic_menu_normal.png");
SDL_LoadImage(RENDERER, &icon_back, "romfs:/res/drawable/ic_arrow_back_normal.png");
}
void Textures_Free(void)
{
SDL_DestroyTexture(icon_back);
SDL_DestroyTexture(icon_menu);
SDL_DestroyTexture(btn_pause);
SDL_DestroyTexture(btn_play);
SDL_DestroyTexture(default_artwork);

47
source/touch_helper.c Normal file
View File

@ -0,0 +1,47 @@
#include <stdlib.h>
#include <stdio.h>
#include "touch_helper.h"
#define TAP_MOVEMENT_GAP 20
#define LONG_TAP_PERIOD 2
void Touch_Init(TouchInfo * touchInfo) {
touchInfo->state = TouchNone;
touchInfo->tapType = TapNone;
}
void Touch_Process(TouchInfo * touchInfo) {
touchPosition currentTouch;
u32 touches = hidTouchCount();
if (touches >= 1)
hidTouchRead(&currentTouch, 0);
u64 current_time;
timeGetCurrentTime(TimeType_UserSystemClock, &current_time);
// On touch start.
if (touches == 1 && (touchInfo->state == TouchNone || touchInfo->state == TouchEnded)) {
touchInfo->state = TouchStart;
touchInfo->firstTouch = currentTouch;
touchInfo->prevTouch = currentTouch;
touchInfo->tapType = TapShort;
touchInfo->touchStart = current_time;
}
// On touch moving.
else if (touches >= 1 && touchInfo->state != TouchNone) {
touchInfo->state = TouchMoving;
touchInfo->prevTouch = currentTouch;
if (touchInfo->tapType != TapNone && (abs(touchInfo->firstTouch.px - currentTouch.px) > TAP_MOVEMENT_GAP || abs(touchInfo->firstTouch.py - currentTouch.py) > TAP_MOVEMENT_GAP)) {
touchInfo->tapType = TapNone;
} else if (touchInfo->tapType == TapShort && current_time - touchInfo->touchStart >= LONG_TAP_PERIOD) {
touchInfo->tapType = TapLong;
}
}
// On touch end.
else {
touchInfo->state = (touchInfo->state == TouchMoving) ? TouchEnded : TouchNone;
}
}