diff --git a/Makefile b/Makefile index 3058a0a..5f03d5d 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 := 1 +VERSION_MINOR := 2 VERSION_MICRO := 0 APP_TITLE := eBookReader diff --git a/include/helpers/SDL_helper.h b/include/helpers/SDL_helper.h index ba00621..b63de6e 100644 --- a/include/helpers/SDL_helper.h +++ b/include/helpers/SDL_helper.h @@ -11,6 +11,8 @@ static inline SDL_Color SDL_MakeColour(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { #define WHITE SDL_MakeColour(255, 255, 255, 255) #define BLACK SDL_MakeColour(0, 0, 0, 255) +#define BACK_WHITE SDL_MakeColour(200, 200, 200, 255) +#define BACK_BLACK SDL_MakeColour(30, 30, 30, 255) #define LIGHT_GRAY SDL_MakeColour(181, 181, 181, 255) #define DARK_GRAY SDL_MakeColour(148, 148, 148, 255) #define BLACK_BG SDL_MakeColour(48, 48, 48, 255) diff --git a/source/helpers/SDL_helper.c b/source/helpers/SDL_helper.c index f4a2247..4b83d45 100644 --- a/source/helpers/SDL_helper.c +++ b/source/helpers/SDL_helper.c @@ -52,52 +52,6 @@ void SDL_DrawRotatedText(SDL_Renderer *renderer, TTF_Font *font, double rotation SDL_DestroyTexture(texture); } -void SDL_InvertSurfaceColor(SDL_Surface *surface) { - for(int x = 0; x < (*surface).w; x++) { - for(int y = 0; y < (*surface).h; y++) { - int r, g, b, a; - Uint32 pixel = SDL_GetPixel32(&surface, x, y); - SDL_GetRGBA(pixel, SDL_GetWindowPixelFormat(&WINDOW), &r, &g, &b, &a); - SDL_Color color = SDL_MakeColour(255 - r, 255 - g, 255 - b, a); - SDL_PutPixel32(&surface, x, y, pixel); - } - } -} - -Uint32 SDL_GetPixel32(SDL_Surface *surface, int x, int y) { - //Lock the surface. - if(SDL_MUSTLOCK(surface)) { - SDL_LockSurface(surface); - } - - //Convert the pixels to 32 bit - Uint32 *pixels = (Uint32 *)surface->pixels; - - //Get the requested pixel - return pixels[ ( y * surface->w ) + x ]; - - //Unlock when we are done. - if(SDL_MUSTLOCK(surface)) - SDL_UnlockSurface(surface); -} - -void SDL_PutPixel32(SDL_Surface *surface, int x, int y, Uint32 pixel) { - //Lock the surface. - if(SDL_MUSTLOCK(surface)) { - SDL_LockSurface(surface); - } - - //Convert the pixels to 32 bit - Uint32 *pixels = (Uint32 *)surface->pixels; - - //Set the pixel - pixels[ ( y * surface->w ) + x ] = pixel; - - //Unlock when we are done. - if(SDL_MUSTLOCK(surface)) - SDL_UnlockSurface(surface); -} - void SDL_DrawTextf(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char* text, ...) { char buffer[256]; va_list args; diff --git a/source/main.cpp b/source/main.cpp index d7f6b67..a2c791d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -82,13 +82,6 @@ void Init_Services() { } std::cout << "Initalized Window and Renderer" << std::endl; - /*WINDOW_SURFACE = SDL_GetWindowSurface(WINDOW); - if (!WINDOW_SURFACE) { - SDL_Log("SDL_GetWindowSurface: %s\n", SDL_GetError()); - Term_Services(); - } - std::cout << "Retrevied Window Surface" << std::endl;*/ - SDL_SetRenderDrawBlendMode(RENDERER, SDL_BLENDMODE_BLEND); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); @@ -131,8 +124,9 @@ void Init_Services() { std::cout << "Initalized Input" << std::endl; FS_RecursiveMakeDir("/switch/eBookReader/books"); + std::cout << "Created book directory if needed" << std::endl; - configDarkMode = false; + configDarkMode = true; } int main(int argc, char *argv[]) { @@ -140,54 +134,6 @@ int main(int argc, char *argv[]) { Menu_StartChoosing(); - bool isBookReading = false; - while (run) { - while (SDL_PollEvent(&EVENT)) { - switch (EVENT.type) { - case SDL_JOYAXISMOTION: - break; - case SDL_JOYBUTTONDOWN: - // https://github.com/devkitPro/SDL/blob/switch-sdl2/src/joystick/switch/SDL_sysjoystick.c#L52 - // seek for joystick #0 - if (EVENT.jbutton.which == 0) { - if (EVENT.jbutton.button == 0) { - // (A) button down - } else if (EVENT.jbutton.button == 10) { - // (+) button down - run = false; - } - } - break; - - default: - break; - } - } - /*SDL_ClearScreen(RENDERER, WHITE); - SDL_RenderClear(RENDERER); - - SDL_RenderPresent(RENDERER);*/ - /*if (!isBookReading) { - SDL_ClearScreen(RENDERER, WHITE); - std::cout << "Cleared Screen" << std::endl; - SDL_RenderClear(RENDERER); - std::cout << "Render Clear" << std::endl;*/ - - /*int space_index = 0; - while ((entry = readdir(dir)) != NULL) { - SDL_DrawText(RENDERER, ARIAL, 20, 20 + (30 * space_index), BLACK, entry->d_name); - space_index++; - //cout << entry->d_name << endl; - }*/ - - /*SDL_DrawText(RENDERER, ARIAL, 50, 50, BLACK, "TEST"); - std::cout << "Draw text" << std::endl; - - SDL_RenderPresent(RENDERER); - std::cout << "Render Present" << std::endl; - }*/ - } - Term_Services(); return 0; -} +} \ No newline at end of file diff --git a/source/menus/book-chooser/MenuChooser.cpp b/source/menus/book-chooser/MenuChooser.cpp index 23a6066..f4c974d 100644 --- a/source/menus/book-chooser/MenuChooser.cpp +++ b/source/menus/book-chooser/MenuChooser.cpp @@ -4,6 +4,7 @@ extern "C" { #include "SDL_helper.h" #include "common.h" #include "textures.h" + #include "config.h" } #include @@ -52,7 +53,10 @@ void Menu_StartChoosing() { break; } - SDL_ClearScreen(RENDERER, WHITE); + SDL_Color textColor = configDarkMode ? WHITE : BLACK; + SDL_Color backColor = configDarkMode ? BACK_BLACK : BACK_WHITE; + + SDL_ClearScreen(RENDERER, backColor); SDL_RenderClear(RENDERER); hidScanInput(); @@ -60,12 +64,16 @@ void Menu_StartChoosing() { u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); - if (kDown & KEY_PLUS) { + /*if (!isWarningOnScreen && kDown & KEY_PLUS) { break; - } + }*/ if (kDown & KEY_B) { - isWarningOnScreen = false; + if (!isWarningOnScreen) { + break; + } else { + isWarningOnScreen = false; + } } if (kDown & KEY_A) { @@ -77,9 +85,9 @@ void Menu_StartChoosing() { if (contains(allowedExtentions, extention)) { if (bookIndex == choosenIndex) { if (contains(warnedExtentions, extention)) { - #ifdef EXPERIMENTAL + /*#ifdef EXPERIMENTAL SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex)); - #endif + #endif*/ if (isWarningOnScreen) { goto OPEN_BOOK; } else { @@ -102,13 +110,28 @@ void Menu_StartChoosing() { } if (kDown & KEY_DUP) { - if (choosenIndex != 0 && !isWarningOnScreen) choosenIndex--; + if (choosenIndex != 0 && !isWarningOnScreen) { + choosenIndex--; + } else if (choosenIndex == 0) { + choosenIndex = amountOfFiles-1; + } } if (kDown & KEY_DDOWN) { - if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) choosenIndex++; + if (choosenIndex == amountOfFiles-1) { + choosenIndex = 0; + } else if (choosenIndex < amountOfFiles-1 && !isWarningOnScreen) { + choosenIndex++; + } } + if (kDown & KEY_MINUS) { + configDarkMode = !configDarkMode; + } + + SDL_DrawText(RENDERER, ARIAL_25, windowX - 123, windowY - 35, textColor, "\"B\" - Exit"); + SDL_DrawText(RENDERER, ARIAL_25, windowX - 200, windowY - 35 * 2, textColor, "\"-\" - Switch theme"); + int choosingIndex = 0; for (const auto & entry : fs::directory_iterator(path)) { string filename = entry.path().filename().string(); @@ -116,26 +139,27 @@ void Menu_StartChoosing() { if (contains(allowedExtentions, extention)) { if (choosenIndex == choosingIndex) { - SDL_DrawRect(RENDERER, 15, 15 + (40 * choosingIndex), 1265, 40, SELECTOR_COLOUR_LIGHT); + SDL_DrawRect(RENDERER, 15, 15 + (40 * choosingIndex), 1265, 40, configDarkMode ? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT); } #ifdef EXPERIMENTAL if (contains(warnedExtentions, extention)) { - SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex)); + //SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex)); } #endif - SDL_DrawText(RENDERER, ARIAL_25, 50, 20 + (40 * choosingIndex), BLACK, entry.path().filename().c_str()); - SDL_DrawText(RENDERER, ARIAL_25, windowX - 123, windowY - 35, BLACK, "\"+\" - Exit"); + SDL_DrawText(RENDERER, ARIAL_25, 50, 20 + (40 * choosingIndex), textColor, entry.path().filename().c_str()); if (isWarningOnScreen) { - SDL_DrawRect(RENDERER, 0, 0, 1280, 720, SDL_MakeColour(50, 50, 50, 150)); + if (!configDarkMode) { // Display a dimmed background if on light mode + SDL_DrawRect(RENDERER, 0, 0, 1280, 720, SDL_MakeColour(50, 50, 50, 150)); + } - SDL_DrawRect(RENDERER, (windowX - warningWidth) / 2, (windowY - warningHeight) / 2, warningWidth, warningHeight, HINT_COLOUR_LIGHT); - SDL_DrawText(RENDERER, ARIAL_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 15, BLACK, "This file is not yet fully supported, and may"); - SDL_DrawText(RENDERER, ARIAL_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 50, BLACK, "cause a system, or app crash."); - SDL_DrawText(RENDERER, ARIAL_20, (windowX - warningWidth) / 2 + warningWidth - 250, (windowY - warningHeight) / 2 + warningHeight - 30, BLACK, "\"A\" - Read"); - SDL_DrawText(RENDERER, ARIAL_20, (windowX - warningWidth) / 2 + warningWidth - 125, (windowY - warningHeight) / 2 + warningHeight - 30, BLACK, "\"B\" - Cancel."); + SDL_DrawRect(RENDERER, (windowX - warningWidth) / 2, (windowY - warningHeight) / 2, warningWidth, warningHeight, configDarkMode ? HINT_COLOUR_DARK : HINT_COLOUR_LIGHT); + SDL_DrawText(RENDERER, ARIAL_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 15, textColor, "This file is not yet fully supported, and may"); + SDL_DrawText(RENDERER, ARIAL_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 50, textColor, "cause a system, or app crash."); + SDL_DrawText(RENDERER, ARIAL_20, (windowX - warningWidth) / 2 + warningWidth - 250, (windowY - warningHeight) / 2 + warningHeight - 30, textColor, "\"A\" - Read"); + SDL_DrawText(RENDERER, ARIAL_20, (windowX - warningWidth) / 2 + warningWidth - 125, (windowY - warningHeight) / 2 + warningHeight - 30, textColor, "\"B\" - Cancel."); } choosingIndex++; diff --git a/source/menus/book/BookReader.cpp b/source/menus/book/BookReader.cpp index 899f258..52734ca 100644 --- a/source/menus/book/BookReader.cpp +++ b/source/menus/book/BookReader.cpp @@ -13,6 +13,7 @@ extern "C" { } fz_context *ctx = NULL; +int windowX, windowY; /*config_t *config = NULL; static int load_last_page(const char *book_name) { @@ -49,6 +50,8 @@ BookReader::BookReader(const char *path) { ctx = fz_new_context(NULL, NULL, 128 << 10); fz_register_document_handlers(ctx); } + + SDL_GetWindowSize(WINDOW, &windowX, &windowY); book_name = std::string(path).substr(std::string(path).find_last_of("/\\") + 1); @@ -128,7 +131,7 @@ void BookReader::switch_page_layout() { } } -void BookReader::draw() { +void BookReader::draw(bool drawHelp) { if (configDarkMode == true) { SDL_ClearScreen(RENDERER, BLACK); } else { @@ -139,30 +142,54 @@ void BookReader::draw() { layout->draw_page(); - #ifdef __SWITCH__ - if (permStatusBar || --status_bar_visible_counter > 0) { - char *title = layout->info(); - - int title_width = 0, title_height = 0; - TTF_SizeText(ARIAL_15, title, &title_width, &title_height); - - SDL_Color color = configDarkMode ? STATUS_BAR_DARK : STATUS_BAR_LIGHT; - - if (_currentPageLayout == BookPageLayoutPortrait) { - SDL_DrawRect(RENDERER, 0, 0, 1280, 45, SDL_MakeColour(color.r, color.g, color.b , 180)); - SDL_DrawText(RENDERER, ARIAL_25, (1280 - title_width) / 2, (40 - title_height) / 2, WHITE, title); - - StatusBar_DisplayTime(false); - } else if (_currentPageLayout == BookPageLayoutLandscape) { - SDL_DrawRect(RENDERER, 1280 - 45, 0, 45, 720, SDL_MakeColour(color.r, color.g, color.b , 180)); - int x = (1280 - title_width) - ((40 - title_height) / 2); - int y = (720 - title_height) / 2; - SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, x, y, WHITE, title); + if (drawHelp) { // Help menu + int helpWidth = 680; + int helpHeight = 365; - StatusBar_DisplayTime(true); - } + if (!configDarkMode) { // Display a dimmed background if on light mode + SDL_DrawRect(RENDERER, 0, 0, 1280, 720, SDL_MakeColour(50, 50, 50, 150)); } - #endif + + SDL_DrawRect(RENDERER, (windowX - helpWidth) / 2, (windowY - helpHeight) / 2, helpWidth, helpHeight, configDarkMode ? HINT_COLOUR_DARK : HINT_COLOUR_LIGHT); + + // These already have margin added to them + int textX = (windowX - helpWidth) / 2 + 20; + int textY = (windowY - helpHeight) / 2 + 75; + SDL_DrawText(RENDERER, ARIAL_30, textX, (windowY - helpHeight) / 2 + 10, configDarkMode ? WHITE : BLACK, "Help Menu:"); + + SDL_DrawText(RENDERER, ARIAL_25, textX, textY, configDarkMode ? WHITE : BLACK, "\"B\" - Stop reading / Close help menu."); + SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35, configDarkMode ? WHITE : BLACK, "\"-\" - Switch to dark/light theme."); + SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 2, configDarkMode ? WHITE : BLACK, "\"Right Stick Up/Down\" - Zoom in/out."); + SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 3, configDarkMode ? WHITE : BLACK, "\"Left Stick Up/Down\" - Page up/down."); + SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 4, configDarkMode ? WHITE : BLACK, "\"Y\" - Rotate page."); + SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 5, configDarkMode ? WHITE : BLACK, "\"X\" - Keep status bar on."); + SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 6, configDarkMode ? WHITE : BLACK, "\"Left/Right DPad\" - Next/previous page."); + SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 7, configDarkMode ? WHITE : BLACK, "\"Left/Right Bumper\" - Skip forward/backward 10 pages."); + } + + if (permStatusBar || --status_bar_visible_counter > 0) { + char *title = layout->info(); + + int title_width = 0, title_height = 0; + TTF_SizeText(ARIAL_15, title, &title_width, &title_height); + + SDL_Color color = configDarkMode ? STATUS_BAR_DARK : STATUS_BAR_LIGHT; + + if (_currentPageLayout == BookPageLayoutPortrait) { + SDL_DrawRect(RENDERER, 0, 0, 1280, 45, SDL_MakeColour(color.r, color.g, color.b , 180)); + SDL_DrawText(RENDERER, ARIAL_25, (1280 - title_width) / 2, (40 - title_height) / 2, WHITE, title); + + StatusBar_DisplayTime(false); + } else if (_currentPageLayout == BookPageLayoutLandscape) { + SDL_DrawRect(RENDERER, 1280 - 45, 0, 45, 720, SDL_MakeColour(color.r, color.g, color.b , 180)); + int x = (1280 - title_width) - ((40 - title_height) / 2); + int y = (720 - title_height) / 2; + SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, x, y, WHITE, title); + + StatusBar_DisplayTime(true); + } + } + SDL_RenderPresent(RENDERER); } diff --git a/source/menus/book/BookReader.hpp b/source/menus/book/BookReader.hpp index 83c328a..69508ed 100644 --- a/source/menus/book/BookReader.hpp +++ b/source/menus/book/BookReader.hpp @@ -29,7 +29,7 @@ class BookReader { void move_page_right(); void reset_page(); void switch_page_layout(); - void draw(); + void draw(bool drawHelp); BookPageLayout currentPageLayout() { return _currentPageLayout; diff --git a/source/menus/book/PageLayout.cpp b/source/menus/book/PageLayout.cpp index 2bee82b..981230e 100644 --- a/source/menus/book/PageLayout.cpp +++ b/source/menus/book/PageLayout.cpp @@ -1,5 +1,6 @@ #include "PageLayout.hpp" #include +#include extern "C" { #include "common.h" @@ -87,13 +88,12 @@ void PageLayout::render_page_to_texture(int num, bool reset_zoom) { } fz_pixmap *pix = fz_new_pixmap_from_page_contents(ctx, page, fz_scale(zoom, zoom), fz_device_rgb(ctx), 0); - SDL_Surface *image = SDL_CreateRGBSurfaceFrom(pix->samples, pix->w, pix->h, pix->n * 8, pix->w * pix->n, 0x000000FF, 0x0000FF00, 0x00FF0000, 0); - /*if (configDarkMode) { - SDL_InvertSurfaceColor(image); - }*/ + if (configDarkMode) { + fz_invert_pixmap(ctx, pix); + } + SDL_Surface *image = SDL_CreateRGBSurfaceFrom(pix->samples, pix->w, pix->h, pix->n * 8, pix->w * pix->n, 0x000000FF, 0x0000FF00, 0x00FF0000, 0); page_texture = SDL_CreateTextureFromSurface(RENDERER, image); - //SDL_SetTextureColorMod(&page_texture, page_texture) SDL_FreeSurface(image); fz_drop_pixmap(ctx, pix); diff --git a/source/menus/book/menu_book_reader.cpp b/source/menus/book/menu_book_reader.cpp index 0489815..76a0aea 100644 --- a/source/menus/book/menu_book_reader.cpp +++ b/source/menus/book/menu_book_reader.cpp @@ -2,6 +2,8 @@ extern "C" { #include "menu_book_reader.h" #include "MenuChooser.h" #include "common.h" + #include "config.h" + #include "SDL_helper.h" } #include @@ -13,8 +15,11 @@ void Menu_OpenBook(char *path) { /*TouchInfo touchInfo; Touch_Init(&touchInfo);*/ + bool helpMenu = false; + + while(appletMainLoop()) { - reader->draw(); + reader->draw(helpMenu); hidScanInput(); @@ -23,82 +28,93 @@ void Menu_OpenBook(char *path) { u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); - if (kDown & KEY_DLEFT) { - if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) + if (!helpMenu && kDown & KEY_DLEFT) { + if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { reader->previous_page(1); - else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) + } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { reader->zoom_out(); - } else if (kDown & KEY_DRIGHT) { - if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) + } + } else if (!helpMenu && kDown & KEY_DRIGHT) { + if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { reader->next_page(1); - else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) + } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { reader->zoom_in(); + } } - if (kDown & KEY_R) { + if (!helpMenu && kDown & KEY_R) { reader->next_page(10); - } else if (kDown & KEY_L) { + } else if (!helpMenu && kDown & KEY_L) { reader->previous_page(10); } - if ((kDown & KEY_DUP) || (kHeld & KEY_RSTICK_UP)) { + if (!helpMenu && ((kDown & KEY_DUP) || (kHeld & KEY_RSTICK_UP))) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { reader->zoom_in(); } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { reader->previous_page(1); } - //reader->reset_page(); - } else if ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN)) { + } else if (!helpMenu && ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN))) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { reader->zoom_out(); } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { reader->next_page(1); } - //reader->reset_page(); } - if (kHeld & KEY_LSTICK_UP) { + if (!helpMenu && kHeld & KEY_LSTICK_UP) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { reader->move_page_up(); } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { reader->move_page_left(); } - } else if (kHeld & KEY_LSTICK_DOWN) { + } else if (!helpMenu && kHeld & KEY_LSTICK_DOWN) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { reader->move_page_down(); } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { reader->move_page_right(); } - } else if (kHeld & KEY_LSTICK_RIGHT) { - /*if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { - reader->move_page_left(); - } else */if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { - reader->move_page_up(); - } - } else if (kHeld & KEY_LSTICK_LEFT) { - /*if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { - reader->move_page_right(); - } else */if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { + } else if (!helpMenu && kHeld & KEY_LSTICK_RIGHT) { + if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { + //reader->move_page_up(); reader->move_page_down(); } + } else if (!helpMenu && kHeld & KEY_LSTICK_LEFT) { + if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { + //reader->move_page_down(); + reader->move_page_up(); + } } if (kDown & KEY_B) { - break; + if (helpMenu) { + helpMenu = !helpMenu; + } else { + break; + } } - if (kDown & KEY_X) { + if (!helpMenu && kDown & KEY_X) { reader->permStatusBar = !reader->permStatusBar; } - if (kDown & KEY_LSTICK || kDown & KEY_RSTICK) { + if (!helpMenu && kDown & KEY_LSTICK || kDown & KEY_RSTICK) { reader->reset_page(); } - if (kDown & KEY_Y) { + if (!helpMenu && kDown & KEY_Y) { reader->switch_page_layout(); } - + + if (!helpMenu && kDown & KEY_MINUS) { + configDarkMode = !configDarkMode; + reader->previous_page(0); + } + + if (kDown & KEY_PLUS) { + helpMenu = !helpMenu; + } + /*if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) { float tapRegion = 120; diff --git a/source/status_bar.c b/source/status_bar.c index 9d57c5f..6d07133 100644 --- a/source/status_bar.c +++ b/source/status_bar.c @@ -6,8 +6,7 @@ #include "status_bar.h" #include "textures.h" -static char *Clock_GetCurrentTime(void) -{ +static char *Clock_GetCurrentTime(void) { static char buffer[10]; time_t unixTime = time(NULL); @@ -32,8 +31,7 @@ static char *Clock_GetCurrentTime(void) return buffer; } -static void StatusBar_GetBatteryStatus(int x, int y) -{ +static void StatusBar_GetBatteryStatus(int x, int y) { u32 percent = 0; ChargerType state; int width = 0; @@ -101,19 +99,27 @@ static void StatusBar_GetBatteryStatus(int x, int y) } void StatusBar_DisplayTime(bool portriat) { - int width = 0, height = 0; - TTF_SizeText(ARIAL_25, Clock_GetCurrentTime(), &width, &height); + int timeWidth = 0, timeHeight = 0; + TTF_SizeText(ARIAL_25, Clock_GetCurrentTime(), &timeWidth, &timeHeight); + int helpWidth, helpHeight; + TTF_SizeText(ARIAL_20, "\"+\" - Help", &helpWidth, &helpHeight); #ifdef EXPERIMENTAL //StatusBar_GetBatteryStatus(1260 - width - 44, (40 - height) / 2); #endif if (portriat) { - int x = (1280 - width) + height; //- ((45 - height) / 2); - int y = (720 - width) + 15; - SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, x, y, WHITE, Clock_GetCurrentTime()); + int timeX = (1280 - timeWidth) + timeHeight; + int timeY = (720 - timeWidth) + 15; + SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, timeX, timeY, WHITE, Clock_GetCurrentTime()); + + int helpX = (1280 - helpWidth) + 21; + int helpY = (720 - helpHeight) - (720 - timeY) - 75; + SDL_DrawRotatedText(RENDERER, ARIAL_20, (double) 90, helpX, helpY, WHITE, "\"+\" - Help"); //SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, 1270 - width, (720 - height), WHITE, Clock_GetCurrentTime()); } else { - SDL_DrawText(RENDERER, ARIAL_25, 1260 - width, (40 - height) / 2, WHITE, Clock_GetCurrentTime()); + SDL_DrawText(RENDERER, ARIAL_25, 1260 - timeWidth, (40 - timeHeight) / 2, WHITE, Clock_GetCurrentTime()); + + SDL_DrawText(RENDERER, ARIAL_20, 1260 - helpWidth - timeWidth - 25, (40 - helpHeight) / 2, WHITE, "\"+\" - Help"); } } \ No newline at end of file diff --git a/source/textures.c b/source/textures.c index 668b6dd..d5392c1 100644 --- a/source/textures.c +++ b/source/textures.c @@ -25,19 +25,34 @@ void Textures_Load(void) { SDL_LoadImage(RENDERER, &battery_unknown, "romfs:/resources/images/battery_unknown.png");*/ //SDL_LoadImage(RENDERER, &error, "romfs:/resources/images/error.png"); + fprintf(stderr, "LOADING WARNING\n"); SDL_Surface *imageSurface = IMG_Load("romfs:/resources/images/warning.png"); + fprintf(stderr, "LOADED WARNING\n"); - if (imageSurface) { - warning = SDL_CreateTextureFromSurface(RENDERER, imageSurface); - if (warning == NULL) { - fprintf(stderr, "CreateTextureFromSurface failed: %s\n", SDL_GetError()); + if (RENDERER) { + if (imageSurface) { + fprintf(stderr, "CREATING TEXTURE\n"); + warning = SDL_CreateTextureFromSurface(RENDERER, imageSurface); + fprintf(stderr, "CREATED TEXTURE\n"); + + if (warning == NULL) { + fprintf(stderr, "CreateTextureFromSurface failed: %s\n", SDL_GetError()); + exit(1); + } else { + fprintf(stderr, "Loaded \"romfs:/resources/images/warning.png\"\n"); + } + } else { + fprintf(stderr, "Failed to load image: \"romfs:/resources/images/warning.png\"\n"); exit(1); } - - printf("Loaded \"romfs:/resources/images/warning.png\"\n"); } else { - printf("Failed to load image: \"romfs:/resources/images/warning.png\"\n"); + fprintf(stderr, "Something wrong with RENDERER"); + exit(1); } + + SDL_FreeSurface(imageSurface); + + /*if (imageSurface) { Uint32 colorkey = SDL_MapRGB(imageSurface->format, 0, 0, 0); SDL_SetColorKey(imageSurface, SDL_TRUE, colorkey);