Version 0.2.0-beta release

This commit is contained in:
SeanOMik 2019-09-19 19:12:38 -05:00
parent d4b1c382e1
commit 7fabb5d3d3
11 changed files with 188 additions and 198 deletions

View File

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

View File

@ -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 WHITE SDL_MakeColour(255, 255, 255, 255)
#define BLACK SDL_MakeColour(0, 0, 0, 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 LIGHT_GRAY SDL_MakeColour(181, 181, 181, 255)
#define DARK_GRAY SDL_MakeColour(148, 148, 148, 255) #define DARK_GRAY SDL_MakeColour(148, 148, 148, 255)
#define BLACK_BG SDL_MakeColour(48, 48, 48, 255) #define BLACK_BG SDL_MakeColour(48, 48, 48, 255)

View File

@ -52,52 +52,6 @@ void SDL_DrawRotatedText(SDL_Renderer *renderer, TTF_Font *font, double rotation
SDL_DestroyTexture(texture); 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, ...) { void SDL_DrawTextf(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char* text, ...) {
char buffer[256]; char buffer[256];
va_list args; va_list args;

View File

@ -82,13 +82,6 @@ void Init_Services() {
} }
std::cout << "Initalized Window and Renderer" << std::endl; 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_SetRenderDrawBlendMode(RENDERER, SDL_BLENDMODE_BLEND);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
@ -131,8 +124,9 @@ void Init_Services() {
std::cout << "Initalized Input" << std::endl; std::cout << "Initalized Input" << std::endl;
FS_RecursiveMakeDir("/switch/eBookReader/books"); FS_RecursiveMakeDir("/switch/eBookReader/books");
std::cout << "Created book directory if needed" << std::endl;
configDarkMode = false; configDarkMode = true;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -140,54 +134,6 @@ int main(int argc, char *argv[]) {
Menu_StartChoosing(); 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(); Term_Services();
return 0; return 0;
} }

View File

@ -4,6 +4,7 @@ extern "C" {
#include "SDL_helper.h" #include "SDL_helper.h"
#include "common.h" #include "common.h"
#include "textures.h" #include "textures.h"
#include "config.h"
} }
#include <switch.h> #include <switch.h>
@ -52,7 +53,10 @@ void Menu_StartChoosing() {
break; 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); SDL_RenderClear(RENDERER);
hidScanInput(); hidScanInput();
@ -60,12 +64,16 @@ void Menu_StartChoosing() {
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) { /*if (!isWarningOnScreen && kDown & KEY_PLUS) {
break; break;
} }*/
if (kDown & KEY_B) { if (kDown & KEY_B) {
isWarningOnScreen = false; if (!isWarningOnScreen) {
break;
} else {
isWarningOnScreen = false;
}
} }
if (kDown & KEY_A) { if (kDown & KEY_A) {
@ -77,9 +85,9 @@ void Menu_StartChoosing() {
if (contains(allowedExtentions, extention)) { if (contains(allowedExtentions, extention)) {
if (bookIndex == choosenIndex) { if (bookIndex == choosenIndex) {
if (contains(warnedExtentions, extention)) { if (contains(warnedExtentions, extention)) {
#ifdef EXPERIMENTAL /*#ifdef EXPERIMENTAL
SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex)); SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex));
#endif #endif*/
if (isWarningOnScreen) { if (isWarningOnScreen) {
goto OPEN_BOOK; goto OPEN_BOOK;
} else { } else {
@ -102,13 +110,28 @@ void Menu_StartChoosing() {
} }
if (kDown & KEY_DUP) { 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 (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; int choosingIndex = 0;
for (const auto & entry : fs::directory_iterator(path)) { for (const auto & entry : fs::directory_iterator(path)) {
string filename = entry.path().filename().string(); string filename = entry.path().filename().string();
@ -116,26 +139,27 @@ void Menu_StartChoosing() {
if (contains(allowedExtentions, extention)) { if (contains(allowedExtentions, extention)) {
if (choosenIndex == choosingIndex) { 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 #ifdef EXPERIMENTAL
if (contains(warnedExtentions, extention)) { if (contains(warnedExtentions, extention)) {
SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex)); //SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex));
} }
#endif #endif
SDL_DrawText(RENDERER, ARIAL_25, 50, 20 + (40 * choosingIndex), BLACK, entry.path().filename().c_str()); SDL_DrawText(RENDERER, ARIAL_25, 50, 20 + (40 * choosingIndex), textColor, entry.path().filename().c_str());
SDL_DrawText(RENDERER, ARIAL_25, windowX - 123, windowY - 35, BLACK, "\"+\" - Exit");
if (isWarningOnScreen) { 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_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, BLACK, "This file is not yet fully supported, and may"); 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, BLACK, "cause a system, or app crash."); 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, BLACK, "\"A\" - Read"); 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, BLACK, "\"B\" - Cancel."); SDL_DrawText(RENDERER, ARIAL_20, (windowX - warningWidth) / 2 + warningWidth - 125, (windowY - warningHeight) / 2 + warningHeight - 30, textColor, "\"B\" - Cancel.");
} }
choosingIndex++; choosingIndex++;

View File

@ -13,6 +13,7 @@ extern "C" {
} }
fz_context *ctx = NULL; fz_context *ctx = NULL;
int windowX, windowY;
/*config_t *config = NULL; /*config_t *config = NULL;
static int load_last_page(const char *book_name) { 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); ctx = fz_new_context(NULL, NULL, 128 << 10);
fz_register_document_handlers(ctx); fz_register_document_handlers(ctx);
} }
SDL_GetWindowSize(WINDOW, &windowX, &windowY);
book_name = std::string(path).substr(std::string(path).find_last_of("/\\") + 1); 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) { if (configDarkMode == true) {
SDL_ClearScreen(RENDERER, BLACK); SDL_ClearScreen(RENDERER, BLACK);
} else { } else {
@ -139,30 +142,54 @@ void BookReader::draw() {
layout->draw_page(); layout->draw_page();
#ifdef __SWITCH__ if (drawHelp) { // Help menu
if (permStatusBar || --status_bar_visible_counter > 0) { int helpWidth = 680;
char *title = layout->info(); int helpHeight = 365;
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); 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); SDL_RenderPresent(RENDERER);
} }

View File

@ -29,7 +29,7 @@ class BookReader {
void move_page_right(); void move_page_right();
void reset_page(); void reset_page();
void switch_page_layout(); void switch_page_layout();
void draw(); void draw(bool drawHelp);
BookPageLayout currentPageLayout() { BookPageLayout currentPageLayout() {
return _currentPageLayout; return _currentPageLayout;

View File

@ -1,5 +1,6 @@
#include "PageLayout.hpp" #include "PageLayout.hpp"
#include <algorithm> #include <algorithm>
#include <iostream>
extern "C" { extern "C" {
#include "common.h" #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); 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) {
/*if (configDarkMode) { fz_invert_pixmap(ctx, pix);
SDL_InvertSurfaceColor(image); }
}*/
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); page_texture = SDL_CreateTextureFromSurface(RENDERER, image);
//SDL_SetTextureColorMod(&page_texture, page_texture)
SDL_FreeSurface(image); SDL_FreeSurface(image);
fz_drop_pixmap(ctx, pix); fz_drop_pixmap(ctx, pix);

View File

@ -2,6 +2,8 @@ extern "C" {
#include "menu_book_reader.h" #include "menu_book_reader.h"
#include "MenuChooser.h" #include "MenuChooser.h"
#include "common.h" #include "common.h"
#include "config.h"
#include "SDL_helper.h"
} }
#include <iostream> #include <iostream>
@ -13,8 +15,11 @@ void Menu_OpenBook(char *path) {
/*TouchInfo touchInfo; /*TouchInfo touchInfo;
Touch_Init(&touchInfo);*/ Touch_Init(&touchInfo);*/
bool helpMenu = false;
while(appletMainLoop()) { while(appletMainLoop()) {
reader->draw(); reader->draw(helpMenu);
hidScanInput(); hidScanInput();
@ -23,82 +28,93 @@ void Menu_OpenBook(char *path) {
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); u64 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
if (kDown & KEY_DLEFT) { if (!helpMenu && kDown & KEY_DLEFT) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
reader->previous_page(1); reader->previous_page(1);
else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
reader->zoom_out(); 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); reader->next_page(1);
else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
reader->zoom_in(); reader->zoom_in();
}
} }
if (kDown & KEY_R) { if (!helpMenu && kDown & KEY_R) {
reader->next_page(10); reader->next_page(10);
} else if (kDown & KEY_L) { } else if (!helpMenu && kDown & KEY_L) {
reader->previous_page(10); 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())) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
reader->zoom_in(); reader->zoom_in();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
reader->previous_page(1); reader->previous_page(1);
} }
//reader->reset_page(); } else if (!helpMenu && ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN))) {
} else if ((kDown & KEY_DDOWN) || (kHeld & KEY_RSTICK_DOWN)) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
reader->zoom_out(); reader->zoom_out();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
reader->next_page(1); reader->next_page(1);
} }
//reader->reset_page();
} }
if (kHeld & KEY_LSTICK_UP) { if (!helpMenu && kHeld & KEY_LSTICK_UP) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
reader->move_page_up(); reader->move_page_up();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
reader->move_page_left(); reader->move_page_left();
} }
} else if (kHeld & KEY_LSTICK_DOWN) { } else if (!helpMenu && kHeld & KEY_LSTICK_DOWN) {
if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) {
reader->move_page_down(); reader->move_page_down();
} else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) { } else if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
reader->move_page_right(); reader->move_page_right();
} }
} else if (kHeld & KEY_LSTICK_RIGHT) { } else if (!helpMenu && kHeld & KEY_LSTICK_RIGHT) {
/*if (reader->currentPageLayout() == BookPageLayoutPortrait || (!hidGetHandheldMode())) { if ((reader->currentPageLayout() == BookPageLayoutLandscape) && (hidGetHandheldMode())) {
reader->move_page_left(); //reader->move_page_up();
} 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())) {
reader->move_page_down(); 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) { if (kDown & KEY_B) {
break; if (helpMenu) {
helpMenu = !helpMenu;
} else {
break;
}
} }
if (kDown & KEY_X) { if (!helpMenu && kDown & KEY_X) {
reader->permStatusBar = !reader->permStatusBar; reader->permStatusBar = !reader->permStatusBar;
} }
if (kDown & KEY_LSTICK || kDown & KEY_RSTICK) { if (!helpMenu && kDown & KEY_LSTICK || kDown & KEY_RSTICK) {
reader->reset_page(); reader->reset_page();
} }
if (kDown & KEY_Y) { if (!helpMenu && kDown & KEY_Y) {
reader->switch_page_layout(); 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) { /*if (touchInfo.state == TouchEnded && touchInfo.tapType != TapNone) {
float tapRegion = 120; float tapRegion = 120;

View File

@ -6,8 +6,7 @@
#include "status_bar.h" #include "status_bar.h"
#include "textures.h" #include "textures.h"
static char *Clock_GetCurrentTime(void) static char *Clock_GetCurrentTime(void) {
{
static char buffer[10]; static char buffer[10];
time_t unixTime = time(NULL); time_t unixTime = time(NULL);
@ -32,8 +31,7 @@ static char *Clock_GetCurrentTime(void)
return buffer; return buffer;
} }
static void StatusBar_GetBatteryStatus(int x, int y) static void StatusBar_GetBatteryStatus(int x, int y) {
{
u32 percent = 0; u32 percent = 0;
ChargerType state; ChargerType state;
int width = 0; int width = 0;
@ -101,19 +99,27 @@ static void StatusBar_GetBatteryStatus(int x, int y)
} }
void StatusBar_DisplayTime(bool portriat) { void StatusBar_DisplayTime(bool portriat) {
int width = 0, height = 0; int timeWidth = 0, timeHeight = 0;
TTF_SizeText(ARIAL_25, Clock_GetCurrentTime(), &width, &height); TTF_SizeText(ARIAL_25, Clock_GetCurrentTime(), &timeWidth, &timeHeight);
int helpWidth, helpHeight;
TTF_SizeText(ARIAL_20, "\"+\" - Help", &helpWidth, &helpHeight);
#ifdef EXPERIMENTAL #ifdef EXPERIMENTAL
//StatusBar_GetBatteryStatus(1260 - width - 44, (40 - height) / 2); //StatusBar_GetBatteryStatus(1260 - width - 44, (40 - height) / 2);
#endif #endif
if (portriat) { if (portriat) {
int x = (1280 - width) + height; //- ((45 - height) / 2); int timeX = (1280 - timeWidth) + timeHeight;
int y = (720 - width) + 15; int timeY = (720 - timeWidth) + 15;
SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, x, y, WHITE, Clock_GetCurrentTime()); 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()); //SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, 1270 - width, (720 - height), WHITE, Clock_GetCurrentTime());
} else { } 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");
} }
} }

View File

@ -25,19 +25,34 @@ void Textures_Load(void) {
SDL_LoadImage(RENDERER, &battery_unknown, "romfs:/resources/images/battery_unknown.png");*/ SDL_LoadImage(RENDERER, &battery_unknown, "romfs:/resources/images/battery_unknown.png");*/
//SDL_LoadImage(RENDERER, &error, "romfs:/resources/images/error.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"); SDL_Surface *imageSurface = IMG_Load("romfs:/resources/images/warning.png");
fprintf(stderr, "LOADED WARNING\n");
if (imageSurface) { if (RENDERER) {
warning = SDL_CreateTextureFromSurface(RENDERER, imageSurface); if (imageSurface) {
if (warning == NULL) { fprintf(stderr, "CREATING TEXTURE\n");
fprintf(stderr, "CreateTextureFromSurface failed: %s\n", SDL_GetError()); 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); exit(1);
} }
printf("Loaded \"romfs:/resources/images/warning.png\"\n");
} else { } 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) { /*if (imageSurface) {
Uint32 colorkey = SDL_MapRGB(imageSurface->format, 0, 0, 0); Uint32 colorkey = SDL_MapRGB(imageSurface->format, 0, 0, 0);
SDL_SetColorKey(imageSurface, SDL_TRUE, colorkey); SDL_SetColorKey(imageSurface, SDL_TRUE, colorkey);