From 77cce54ca622fa831e9a243b60ecce9c17459be7 Mon Sep 17 00:00:00 2001 From: Question Date: Thu, 29 Jul 2021 04:39:36 -0500 Subject: [PATCH 1/4] Touch screen controls and some other minor changes --- README.md | 10 ++-- source/menus/book-chooser/MenuChooser.cpp | 26 +++++------ source/menus/book/BookReader.hpp | 2 +- source/menus/book/menu_book_reader.cpp | 56 ++++++++++++++++++----- 4 files changed, 61 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 32949144..8a6aa4b9 100644 --- a/README.md +++ b/README.md @@ -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 -``` diff --git a/source/menus/book-chooser/MenuChooser.cpp b/source/menus/book-chooser/MenuChooser.cpp index a2e2bfe0..a3fe9ee9 100644 --- a/source/menus/book-chooser/MenuChooser.cpp +++ b/source/menus/book-chooser/MenuChooser.cpp @@ -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; } diff --git a/source/menus/book/BookReader.hpp b/source/menus/book/BookReader.hpp index 1ed11e9e..254df556 100644 --- a/source/menus/book/BookReader.hpp +++ b/source/menus/book/BookReader.hpp @@ -4,7 +4,7 @@ #include #include #include "PageLayout.hpp" - +#include struct SDL_Texture; typedef enum { diff --git a/source/menus/book/menu_book_reader.cpp b/source/menus/book/menu_book_reader.cpp index 8fe98805..5a80c323 100644 --- a/source/menus/book/menu_book_reader.cpp +++ b/source/menus/book/menu_book_reader.cpp @@ -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 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(); } From 76db35d36e50c56ecfaa7b6979e4617eb621dcbc Mon Sep 17 00:00:00 2001 From: Question Date: Thu, 29 Jul 2021 05:54:19 -0500 Subject: [PATCH 2/4] Updated README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8a6aa4b9..7d018cfa 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,8 @@ make mupdf make ``` to build. + +If you don't have twili debugger installed, delete the `-ltwili` flag on the Makefile to compile: +``` +LIBS: -ltwili +``` From b3847817f4af87c1e8c1cda2444dc7eb43276e91 Mon Sep 17 00:00:00 2001 From: Question Date: Thu, 29 Jul 2021 09:03:36 -0500 Subject: [PATCH 3/4] Some tweaks on the touch controls --- Makefile | 2 +- README.md | 2 +- source/menus/book/menu_book_reader.cpp | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 98d26e6e..3016e9ef 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index e9af6c7d..47a8d04c 100644 --- a/README.md +++ b/README.md @@ -46,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 v2.4.0](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 diff --git a/source/menus/book/menu_book_reader.cpp b/source/menus/book/menu_book_reader.cpp index 5a80c323..1947a263 100644 --- a/source/menus/book/menu_book_reader.cpp +++ b/source/menus/book/menu_book_reader.cpp @@ -47,29 +47,29 @@ void Menu_OpenBook(char *path) { if(hidGetTouchScreenStates(&state, 1)) { if(state.count != prev_touchcount) { prev_touchcount = state.count; - } + } } for(s32 i=0; i 1000) + 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) + 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 && (state.touches[i].x > 280 || state.touches[i].x < 1000)) + 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 && (state.touches[i].x > 280 || state.touches[i].x < 1000)) + if (state.touches[i].y > 500) if (reader->currentPageLayout() == BookPageLayoutPortrait) reader->zoom_out(); else if (reader->currentPageLayout() == BookPageLayoutLandscape) @@ -137,7 +137,7 @@ void Menu_OpenBook(char *path) { else if (!helpMenu && kDown & HidNpadButton_LeftSL) reader->previous_page(10); - if (kDown & HidNpadButton_B) { + if (kUp & HidNpadButton_B) { if (helpMenu) { helpMenu = !helpMenu; } else { @@ -191,4 +191,5 @@ void Menu_OpenBook(char *path) { std::cout << "Opening chooser" << std::endl; Menu_StartChoosing(); delete reader; + // consoleExit(NULL); } From 810dced314044a2466d9d61bba7e2e35a327540d Mon Sep 17 00:00:00 2001 From: Question Date: Thu, 29 Jul 2021 22:50:54 -0500 Subject: [PATCH 4/4] Minor changes on the battery icon --- source/status_bar.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/source/status_bar.c b/source/status_bar.c index d334c2b2..399ca9b1 100644 --- a/source/status_bar.c +++ b/source/status_bar.c @@ -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);*/ } @@ -126,19 +125,16 @@ void StatusBar_DisplayTime(bool portriat) { if (portriat) { int timeX = (1280 - timeWidth) + timeHeight; - int timeY = (720 - timeWidth) + 15; - SDL_DrawRotatedText(RENDERER, ROBOTO_25, (double) 90, timeX, timeY, WHITE, Clock_GetCurrentTime()); + int timeY = (720 - timeWidth) + 15; + SDL_DrawRotatedText(RENDERER, ROBOTO_25, (double) 90, timeX, timeY, WHITE, Clock_GetCurrentTime()); 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 } }