Merge pull request #9 from Quest84/master

Simple touch controls
This commit is contained in:
SeanOMik 2021-07-30 18:08:37 -04:00 committed by GitHub
commit d6ef58d8a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 39 deletions

View File

@ -45,7 +45,7 @@ INCLUDES := include include/menus/book include/menus/book-chooser include/he
ROMFS := romfs
VERSION_MAJOR := 0
VERSION_MINOR := 3
VERSION_MINOR := 4
VERSION_MICRO := 0
APP_TITLE := eBookReader

View File

@ -6,11 +6,12 @@
* 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.
### 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.
@ -45,7 +46,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 v4.1.3](https://github.com/switchbrew/libnx).
* Uses `freetype` and other libs which comes with `switch-portlibs` via `devkitPro pacman`:
```
pacman -S libnx switch-portlibs
@ -57,7 +58,7 @@ make
```
to build.
If you don't have twili debugger installed then delete the -ltwili flag on the Makefile to compile:
If you don't have twili debugger installed, 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 && (state.touches[i].y > 200 && state.touches[i].y < 500))
if (reader->currentPageLayout() == BookPageLayoutPortrait)
reader->next_page(1);
else if (reader->currentPageLayout() == BookPageLayoutLandscape)
reader->zoom_in();
if (state.touches[i].x < 280 && (state.touches[i].y > 200 && state.touches[i].y < 500))
if (reader->currentPageLayout() == BookPageLayoutPortrait)
reader->previous_page(1);
else if (reader->currentPageLayout() == BookPageLayoutLandscape)
reader->zoom_out();
if (state.touches[i].y < 200)
if (reader->currentPageLayout() == BookPageLayoutPortrait)
reader->zoom_in();
else if (reader->currentPageLayout() == BookPageLayoutLandscape)
reader->previous_page(1);
if (state.touches[i].y > 500)
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,27 +114,30 @@ 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 (kDown & HidNpadButton_B) {
if (!helpMenu && kDown & HidNpadButton_LeftSR)
reader->next_page(10);
else if (!helpMenu && kDown & HidNpadButton_LeftSL)
reader->previous_page(10);
if (kUp & HidNpadButton_B) {
if (helpMenu) {
helpMenu = !helpMenu;
} else {
@ -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();
}
@ -157,4 +191,5 @@ void Menu_OpenBook(char *path) {
std::cout << "Opening chooser" << std::endl;
Menu_StartChoosing();
delete reader;
// consoleExit(NULL);
}

View File

@ -106,13 +106,12 @@ static void StatusBar_GetBatteryStatus(int x, int y) {
snprintf(buf, 5, "%d%%", percent);
TTF_SizeText(ROBOTO_20, buf, &width, NULL);
SDL_DrawHorizonalAlignedImageText(RENDERER, batteryImage, ROBOTO_20, WHITE, buf, (x + width + 5), y, 34, 34, -2, -7);
SDL_DrawHorizonalAlignedImageText(RENDERER, batteryImage, ROBOTO_20, WHITE, buf, (x + width - 30), y, 34, 34, -2, 0);
//SDL_DrawText(RENDERER, ROBOTO_20, (x + width + 5), y, WHITE, buf);
} else {
snprintf(buf, 5, "%d%%", percent);
TTF_SizeText(ROBOTO_20, buf, &width, NULL);
SDL_DrawHorizonalAlignedImageText(RENDERER, battery_unknown, ROBOTO_20, WHITE, buf, x, y, 34, 34, -2, -7);
SDL_DrawHorizonalAlignedImageText(RENDERER, battery_unknown, ROBOTO_20, WHITE, buf, x, y, 34, 34, -2, 0);
/*SDL_DrawText(RENDERER, ROBOTO_20, (x + width + 5), y, WHITE, buf);
SDL_DrawImage(RENDERER, battery_unknown, x, 1);*/
}
@ -132,13 +131,10 @@ void StatusBar_DisplayTime(bool portriat) {
int helpX = (1280 - helpWidth) + 21;
int helpY = (720 - helpHeight) - (720 - timeY) - 75;
SDL_DrawRotatedText(RENDERER, ROBOTO_20, (double) 90, helpX, helpY, WHITE, "\"+\" - Help");
//SDL_DrawRotatedText(RENDERER, ROBOTO_25, (double) 90, 1270 - width, (720 - height), WHITE, Clock_GetCurrentTime());
} else {
SDL_DrawText(RENDERER, ROBOTO_25, 1260 - timeWidth, (40 - timeHeight) / 2, WHITE, Clock_GetCurrentTime());
SDL_DrawText(RENDERER, ROBOTO_20, 1260 - helpWidth - timeWidth - 25, (40 - helpHeight) / 2, WHITE, "\"+\" - Help");
StatusBar_GetBatteryStatus(1260 - (timeWidth + helpWidth) - 110, (40 - timeHeight) / 2 + 34); // 34 is height of battery img
}
}