Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from Quest84/master
Browse files Browse the repository at this point in the history
Fix deprecated hid functions
  • Loading branch information
SeanOMik authored Jul 13, 2021
2 parents 2fae85c + 5ebf896 commit f07e1ed
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 50 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ INCLUDES := include include/menus/book include/menus/book-chooser include/he
ROMFS := romfs

VERSION_MAJOR := 0
VERSION_MINOR := 2
VERSION_MICRO := 2
VERSION_MINOR := 3
VERSION_MICRO := 0

APP_TITLE := eBookReader
APP_AUTHOR := SeanOMik
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 v.4.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
Expand All @@ -61,3 +61,8 @@ 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
```
27 changes: 18 additions & 9 deletions source/menus/book-chooser/MenuChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,33 @@ void Menu_StartChoosing() {
SDL_ClearScreen(RENDERER, backColor);
SDL_RenderClear(RENDERER);

hidScanInput();
//hidScanInput();
padConfigureInput(1, HidNpadStyleSet_NpadStandard);

u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
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);

/*if (!isWarningOnScreen && kDown & KEY_PLUS) {
break;
}*/

if (kDown & KEY_B) {
if (kDown & HidNpadButton_B) {
if (!isWarningOnScreen) {
break;
} else {
isWarningOnScreen = false;
}
}

if (kDown & KEY_A) {
if (kDown & HidNpadButton_A) {
int bookIndex = 0;
for (const auto & entry : fs::directory_iterator(path)) {
string filename = entry.path().filename().string();
Expand Down Expand Up @@ -109,23 +118,23 @@ void Menu_StartChoosing() {
}
}

if (kDown & KEY_DUP) {
if (kDown & HidNpadButton_Up) {
if (choosenIndex != 0 && !isWarningOnScreen) {
choosenIndex--;
} else if (choosenIndex == 0) {
choosenIndex = amountOfFiles-1;
}
}

if (kDown & KEY_DDOWN) {
if (kDown & HidNpadButton_Down) {
if (choosenIndex == amountOfFiles-1) {
choosenIndex = 0;
} else if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) {
choosenIndex++;
}
}

if (kDown & KEY_MINUS) {
if (kDown & HidNpadButton_Minus) {
configDarkMode = !configDarkMode;
}

Expand Down Expand Up @@ -171,4 +180,4 @@ void Menu_StartChoosing() {

SDL_RenderPresent(RENDERER);
}
}
}
83 changes: 47 additions & 36 deletions source/menus/book/menu_book_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,103 +24,114 @@ void Menu_OpenBook(char *path) {

bool helpMenu = false;

// Configure our supported input layout: a single player with standard controller syles
padConfigureInput(1, HidNpadStyleSet_NpadStandard);
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
PadState pad;
padInitializeDefault(&pad);
//Touch_Process(&touchInfo);

while(result >= 0 && appletMainLoop()) {
reader->draw(helpMenu);

hidScanInput();
//hidScanInput();

//u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);

padUpdate(&pad);

//Touch_Process(&touchInfo);
u64 kDown = padGetButtonsDown(&pad);
u64 kHeld = padGetButtons(&pad);
u64 kUp = padGetButtonsUp(&pad);

u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);

if (!helpMenu && kDown & KEY_DLEFT) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
if (!helpMenu && kDown & HidNpadButton_Left) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->previous_page(1);
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_out();
}
} else if (!helpMenu && kDown & KEY_DRIGHT) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
} else if (!helpMenu && kDown & HidNpadButton_Right) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->next_page(1);
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_in();
}
}

if (!helpMenu && kDown & KEY_R) {
if (!helpMenu && kDown & HidNpadButton_R) {
reader->next_page(10);
} else if (!helpMenu && kDown & KEY_L) {
} else if (!helpMenu && kDown & HidNpadButton_L) {
reader->previous_page(10);
}

if (!helpMenu && ((kDown & KEY_DUP) || (kHeld & KEY_RSTICK_UP))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
if (!helpMenu && ((kDown & HidNpadButton_Up) || (kHeld & HidNpadButton_StickRUp))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_in();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->previous_page(1);
}
} else if (!helpMenu && ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
} else if (!helpMenu && ((kDown & HidNpadButton_Down) || (kHeld & HidNpadButton_StickRDown))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_out();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->next_page(1);
}
}

if (!helpMenu && kHeld & KEY_LSTICK_UP) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
if (!helpMenu && kHeld & HidNpadButton_StickLUp) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_up();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_left();
}
} else if (!helpMenu && kHeld & KEY_LSTICK_DOWN) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
} else if (!helpMenu && kHeld & HidNpadButton_StickLDown) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_down();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_right();
}
} else if (!helpMenu && kHeld & KEY_LSTICK_RIGHT) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if (!helpMenu && kHeld & HidNpadButton_StickLRight) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_up();
reader->move_page_down();
}
} else if (!helpMenu && kHeld & KEY_LSTICK_LEFT) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
} else if (!helpMenu && kHeld & HidNpadButton_StickLLeft) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
//reader->move_page_down();
reader->move_page_up();
}
}

if (kDown & KEY_B) {
if (kDown & HidNpadButton_B) {
if (helpMenu) {
helpMenu = !helpMenu;
} else {
break;
}
}

if (!helpMenu && kDown & KEY_X) {
if (!helpMenu && kDown & HidNpadButton_X) {
reader->permStatusBar = !reader->permStatusBar;
}

if (!helpMenu && kDown & KEY_LSTICK || kDown & KEY_RSTICK) {
if (!helpMenu && kDown & HidNpadButton_StickL || kDown & HidNpadButton_StickR) {
reader->reset_page();
}

if (!helpMenu && kDown & KEY_Y) {
if (!helpMenu && kDown & HidNpadButton_Y) {
reader->switch_page_layout();
}

if (!helpMenu && kDown & KEY_MINUS) {
if (!helpMenu && kUp & HidNpadButton_Minus) {
configDarkMode = !configDarkMode;
reader->previous_page(0);
}

if (kDown & KEY_PLUS) {
if (kDown & HidNpadButton_Plus) {
helpMenu = !helpMenu;
}

/*if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
float tapRegion = 120;
Expand Down
5 changes: 3 additions & 2 deletions source/status_bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static char *Clock_GetCurrentTime(void) {

static void StatusBar_GetBatteryStatus(int x, int y) {
u32 percent = 0;
ChargerType state;
//ChargerType state;
PsmChargerType state;
int width = 0;
char buf[5];

Expand Down Expand Up @@ -140,4 +141,4 @@ void StatusBar_DisplayTime(bool portriat) {

StatusBar_GetBatteryStatus(1260 - (timeWidth + helpWidth) - 110, (40 - timeHeight) / 2 + 34); // 34 is height of battery img
}
}
}

0 comments on commit f07e1ed

Please sign in to comment.