eBookReaderSwitch/source/menus/book/menu_book_reader.cpp

195 lines
6.7 KiB
C++
Raw Normal View History

extern "C" {
#include "menu_book_reader.h"
2019-09-02 20:24:09 +00:00
#include "MenuChooser.h"
#include "common.h"
2019-09-20 00:12:38 +00:00
#include "config.h"
#include "SDL_helper.h"
}
#include <iostream>
#include "BookReader.hpp"
void Menu_OpenBook(char *path) {
BookReader *reader = NULL;
int result = 0;
reader = new BookReader(path, &result);
if(result < 0){
std::cout << "Menu_OpenBook: document not loaded" << std::endl;
}
/*TouchInfo touchInfo;
Touch_Init(&touchInfo);*/
hidInitializeTouchScreen();
s32 prev_touchcount=0;
2019-09-20 00:12:38 +00:00
bool helpMenu = false;
2021-07-13 06:25:32 +00:00
// 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()) {
2019-09-20 00:12:38 +00:00
reader->draw(helpMenu);
2021-07-13 06:25:32 +00:00
padUpdate(&pad);
2021-07-13 06:25:32 +00:00
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);
}
2021-07-13 06:25:32 +00:00
if (!helpMenu && kDown & HidNpadButton_Left) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->previous_page(1);
2021-07-13 06:25:32 +00:00
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_out();
2019-09-20 00:12:38 +00:00
}
2021-07-13 06:25:32 +00:00
} else if (!helpMenu && kDown & HidNpadButton_Right) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->next_page(1);
2021-07-13 06:25:32 +00:00
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->zoom_in();
2019-09-20 00:12:38 +00:00
}
}
2021-07-13 06:25:32 +00:00
if (!helpMenu && kDown & HidNpadButton_R) {
reader->next_page(10);
2021-07-13 06:25:32 +00:00
} else if (!helpMenu && kDown & HidNpadButton_L) {
reader->previous_page(10);
}
2021-07-13 06:25:32 +00:00
if (!helpMenu && ((kDown & HidNpadButton_Up) || (kHeld & HidNpadButton_StickRUp))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_in();
2021-07-13 06:25:32 +00:00
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->previous_page(1);
}
2021-07-13 06:25:32 +00:00
} else if (!helpMenu && ((kDown & HidNpadButton_Down) || (kHeld & HidNpadButton_StickRDown))) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->zoom_out();
2021-07-13 06:25:32 +00:00
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->next_page(1);
}
}
2021-07-13 06:25:32 +00:00
if (!helpMenu && kHeld & HidNpadButton_StickLUp) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_up();
2021-07-13 06:25:32 +00:00
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_right();
}
2021-07-13 06:25:32 +00:00
} else if (!helpMenu && kHeld & HidNpadButton_StickLDown) {
if (reader->currentPageLayout() == BookPageLayoutPortrait ) {
reader->move_page_down();
2021-07-13 06:25:32 +00:00
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_left();
}
2021-07-13 06:25:32 +00:00
} else if (!helpMenu && kHeld & HidNpadButton_StickLRight) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
reader->move_page_down();
}
2021-07-13 06:25:32 +00:00
} else if (!helpMenu && kHeld & HidNpadButton_StickLLeft) {
if ((reader->currentPageLayout() == BookPageLayoutLandscape) ) {
2019-09-20 00:12:38 +00:00
reader->move_page_up();
}
}
if (!helpMenu && kDown & HidNpadButton_LeftSR)
reader->next_page(10);
else if (!helpMenu && kDown & HidNpadButton_LeftSL)
reader->previous_page(10);
2021-07-13 06:25:32 +00:00
if (kDown & HidNpadButton_B) {
2019-09-20 00:12:38 +00:00
if (helpMenu) {
helpMenu = !helpMenu;
} else {
break;
}
}
2021-07-13 06:25:32 +00:00
if (!helpMenu && kDown & HidNpadButton_X) {
reader->permStatusBar = !reader->permStatusBar;
}
if ((!helpMenu && kDown & HidNpadButton_StickL) || kDown & HidNpadButton_StickR) {
reader->reset_page();
}
2021-07-13 06:25:32 +00:00
if (!helpMenu && kDown & HidNpadButton_Y) {
reader->switch_page_layout();
}
2019-09-20 00:12:38 +00:00
2021-07-13 06:25:32 +00:00
if (!helpMenu && kUp & HidNpadButton_Minus) {
2019-09-20 00:12:38 +00:00
configDarkMode = !configDarkMode;
reader->previous_page(0);
}
2021-07-13 06:25:32 +00:00
if (kDown & HidNpadButton_Plus) {
2019-09-20 00:12:38 +00:00
helpMenu = !helpMenu;
}
2021-07-13 06:25:32 +00:00
/*if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
float tapRegion = 120;
switch (reader->currentPageLayout()) {
case BookPageLayoutPortrait:
if (tapped_inside(touchInfo, 0, 0, tapRegion, 720))
reader->previous_page(1);
else if (tapped_inside(touchInfo, 1280 - tapRegion, 0, 1280, 720))
reader->next_page(1);
break;
case BookPageLayoutLandscape:
if (tapped_inside(touchInfo, 0, 0, 1280, tapRegion))
reader->previous_page(1);
else if (tapped_inside(touchInfo, 0, 720 - tapRegion, 1280, 720))
reader->next_page(1);
reader->reset_page();
break;
}
}*/
}
std::cout << "Exiting reader" << std::endl;
std::cout << "Opening chooser" << std::endl;
Menu_StartChoosing();
delete reader;
}