Touch screen controls and some other minor changes

This commit is contained in:
Question 2021-07-29 04:39:36 -05:00
parent 5ebf896581
commit 77cce54ca6
4 changed files with 61 additions and 33 deletions

View File

@ -8,6 +8,8 @@ This is a project I've recently just started working on again. Currently its usi
* Dark and light mode
* Landscape reading view
* Portrait reading view
* Touch screen controls
* Touch the botton/top of the screen to zoom in/out and left and right to change the page.
### Current State:
* Most PDF files work, and all epub, cbz and xps files I've tested work.
@ -15,7 +17,6 @@ This is a project I've recently just started working on again. Currently its usi
### TODO:
* Do some extra testing on file compatibility.
* 2 pages side by side in landscape.
* Touch screen for going to next page.
* Hardware lock to prevent accidental touches (maybe Vol- ?) (?).
* Save orientation, and dark mode settings.
@ -50,7 +51,7 @@ Light Mode Landscape Reading:
* NX-Shell Team - A good amount of the code is from an old version of their application.
### Building
* Release built with [libnx release v.4.1.3](https://github.com/switchbrew/libnx).
* Release built with [libnx release v2.4.0](https://github.com/switchbrew/libnx).
* Uses `freetype` and other libs which comes with `switch-portlibs` via `devkitPro pacman`:
```
pacman -S libnx switch-portlibs
@ -61,8 +62,3 @@ make mupdf
make
```
to build.
If you don't have twili debugger installed then delete the -ltwili flag on the Makefile to compile:
```
LIBS: -ltwili
```

View File

@ -48,6 +48,12 @@ void Menu_StartChoosing() {
SDL_GetWindowSize(WINDOW, &windowX, &windowY);
int warningWidth = 700;
int warningHeight = 300;
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
PadState pad;
padInitializeDefault(&pad);
while(appletMainLoop()) {
if (readingBook) {
break;
@ -59,23 +65,15 @@ void Menu_StartChoosing() {
SDL_ClearScreen(RENDERER, backColor);
SDL_RenderClear(RENDERER);
//hidScanInput();
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
PadState pad;
padInitializeDefault(&pad);
padUpdate(&pad);
//u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
u64 kDown = padGetButtonsDown(&pad);
u64 kHeld = padGetButtons(&pad);
u64 kUp = padGetButtonsUp(&pad);
/*if (!isWarningOnScreen && kDown & KEY_PLUS) {
if (!isWarningOnScreen && kDown & HidNpadButton_Plus) {
break;
}*/
}
if (kDown & HidNpadButton_B) {
if (!isWarningOnScreen) {
@ -118,7 +116,7 @@ void Menu_StartChoosing() {
}
}
if (kDown & HidNpadButton_Up) {
if (kDown & HidNpadButton_Up || kDown & HidNpadButton_StickRUp) {
if (choosenIndex != 0 && !isWarningOnScreen) {
choosenIndex--;
} else if (choosenIndex == 0) {
@ -126,7 +124,7 @@ void Menu_StartChoosing() {
}
}
if (kDown & HidNpadButton_Down) {
if (kDown & HidNpadButton_Down || kDown & HidNpadButton_StickRDown) {
if (choosenIndex == amountOfFiles-1) {
choosenIndex = 0;
} else if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) {
@ -134,7 +132,7 @@ void Menu_StartChoosing() {
}
}
if (kDown & HidNpadButton_Minus) {
if (kUp & HidNpadButton_Minus) {
configDarkMode = !configDarkMode;
}

View File

@ -4,7 +4,7 @@
#include <mupdf/pdf.h>
#include <string>
#include "PageLayout.hpp"
#include <switch.h>
struct SDL_Texture;
typedef enum {

View File

@ -21,7 +21,9 @@ void Menu_OpenBook(char *path) {
/*TouchInfo touchInfo;
Touch_Init(&touchInfo);*/
hidInitializeTouchScreen();
s32 prev_touchcount=0;
bool helpMenu = false;
// Configure our supported input layout: a single player with standard controller syles
@ -34,17 +36,46 @@ void Menu_OpenBook(char *path) {
while(result >= 0 && appletMainLoop()) {
reader->draw(helpMenu);
//hidScanInput();
//u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
padUpdate(&pad);
u64 kDown = padGetButtonsDown(&pad);
u64 kHeld = padGetButtons(&pad);
u64 kUp = padGetButtonsUp(&pad);
HidTouchScreenState state={0};
if(hidGetTouchScreenStates(&state, 1)) {
if(state.count != prev_touchcount) {
prev_touchcount = state.count;
}
}
for(s32 i=0; i<state.count; i++) {
if (state.touches[i].x > 1000)
if (reader->currentPageLayout() == BookPageLayoutPortrait)
reader->next_page(1);
else if (reader->currentPageLayout() == BookPageLayoutLandscape)
reader->zoom_in();
if (state.touches[i].x < 280)
if (reader->currentPageLayout() == BookPageLayoutPortrait)
reader->previous_page(1);
else if (reader->currentPageLayout() == BookPageLayoutLandscape)
reader->zoom_out();
if (state.touches[i].y < 200 && (state.touches[i].x > 280 || state.touches[i].x < 1000))
if (reader->currentPageLayout() == BookPageLayoutPortrait)
reader->zoom_in();
else if (reader->currentPageLayout() == BookPageLayoutLandscape)
reader->previous_page(1);
if (state.touches[i].y > 500 && (state.touches[i].x > 280 || state.touches[i].x < 1000))
if (reader->currentPageLayout() == BookPageLayoutPortrait)
reader->zoom_out();
else if (reader->currentPageLayout() == BookPageLayoutLandscape)
reader->next_page(1);
}
if (!helpMenu && kDown & HidNpadButton_Left) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->previous_page(1);
@ -83,26 +114,29 @@ void Menu_OpenBook(char *path) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_up();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_left();
reader->move_page_right();
}
} else if (!helpMenu && kHeld & HidNpadButton_StickLDown) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_down();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_right();
reader->move_page_left();
}
} else if (!helpMenu && kHeld & HidNpadButton_StickLRight) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_up();
reader->move_page_down();
}
} else if (!helpMenu && kHeld & HidNpadButton_StickLLeft) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_down();
reader->move_page_up();
}
}
if (!helpMenu && kDown & HidNpadButton_LeftSR)
reader->next_page(10);
else if (!helpMenu && kDown & HidNpadButton_LeftSL)
reader->previous_page(10);
if (kDown & HidNpadButton_B) {
if (helpMenu) {
helpMenu = !helpMenu;
@ -115,7 +149,7 @@ void Menu_OpenBook(char *path) {
reader->permStatusBar = !reader->permStatusBar;
}
if (!helpMenu && kDown & HidNpadButton_StickL || kDown & HidNpadButton_StickR) {
if ((!helpMenu && kDown & HidNpadButton_StickL) || kDown & HidNpadButton_StickR) {
reader->reset_page();
}