Attempting to add a book chooser. (Doesn't work)

This commit is contained in:
SeanOMik 2019-09-01 21:55:49 -05:00
parent 36400a09d1
commit 14e3d51c4d
30 changed files with 236 additions and 60 deletions

View File

@ -41,7 +41,7 @@ TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
INCLUDES := include include/menus/book include/menus/book-chooser
ROMFS := RomFS
VERSION_MAJOR := 0
@ -70,7 +70,7 @@ LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*
#LIBS := `sdl2-config --libs` -lSDL2_ttf -lSDL2_image
#LIBS := `aarch64-none-elf-pkg-config --libs sdl2 SDL2_ttf SDL2_mixer`
#LIBS := `sdl2-config --libs` -lSDL2_ttf -lSDL2_image -lfreetype -lz -lnx
LIBS := `sdl2-config --libs` -lSDL2_ttf -lSDL2_image -lfreetype -lpng -ljpeg -lz -lbz2 -ltwili -lnx -lmupdf -lmupdf-third
LIBS := `sdl2-config --libs` -lSDL2_ttf -lSDL2_image -lfreetype -lpng -ljpeg -lwebp -lz -lbz2 -ltwili -lnx -lmupdf -lmupdf-third
#LIBS := `aarch64-none-elf-pkg-config --libs sdl2` -lSDL2_ttf #-lSDL2_image -lmupdf -lmupdf-third
#---------------------------------------------------------------------------------

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 551 B

View File

@ -3,6 +3,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include "SDL_helper.h"
extern SDL_Window *WINDOW;
extern SDL_Surface *WINDOW_SURFACE;

View File

@ -0,0 +1,6 @@
#ifndef EBOOK_READER_MENU_CHOOSER_HPP
#define EBOOK_READER_MENU_CHOOSER_HPP
void Menu_StartChoosing();
#endif

12
include/textures.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef NX_SHELL_TEXTURES_H
#define NX_SHELL_TEXTURES_H
SDL_Texture *battery_20, *battery_20_charging, *battery_30, *battery_30_charging, *battery_50, *battery_50_charging, \
*battery_60, *battery_60_charging, *battery_80, *battery_80_charging, *battery_90, *battery_90_charging, \
*battery_full, *battery_full_charging, *battery_low, *battery_unknown;
void Textures_Load(void);
void Textures_Free(void);
#endif

View File

@ -10,28 +10,12 @@
#include <twili.h>
extern "C" {
#include "menu_book_reader.h"
#include "common.h"
#include "SDL_helper.h"
#include "textures.h"
#include "MenuChooser.h"
}
/*void draw_rects(SDL_Renderer *renderer, int x, int y) {
// R
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_Rect r = {x, y, 64, 64};
SDL_RenderFillRect(renderer, &r);
// G
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
SDL_Rect g = {x + 64, y, 64, 64};
SDL_RenderFillRect(renderer, &g);
// B
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_Rect b = {x + 128, y, 64, 64};
SDL_RenderFillRect(renderer, &b);
}*/
SDL_Renderer* RENDERER;
SDL_Window* WINDOW;
SDL_Surface* WINDOW_SURFACE;
@ -46,24 +30,22 @@ void Term_Services() {
TTF_CloseFont(ARIAL_UNICODE);
TTF_Quit();
Textures_Free();
romfsExit();
SDL_DestroyRenderer(RENDERER);
SDL_FreeSurface(WINDOW_SURFACE);
SDL_DestroyWindow(WINDOW);
SDL_Quit();
//socketExit();
twiliExit();
run = false;
}
void Init_Services() {
twiliInitialize();
/*socketInitializeDefault();
nxlinkStdio();*/
std::cout << "Initalize Serices" << std::endl;
// mandatory at least on switch, else gfx is not properly closed
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
SDL_Log("SDL_Init: %s\n", SDL_GetError());
Term_Services();
@ -71,39 +53,27 @@ void Init_Services() {
TTF_Init();
// create an SDL WINDOW (OpenGL ES2 always enabled)
// when SDL_FULLSCREEN flag is not set, viewport is automatically handled by SDL (use SDL_SetWINDOWSize to "change resolution")
// available switch SDL2 video modes :
// 1920 x 1080 @ 32 bpp (SDL_PIXELFORMAT_RGBA8888)
// 1280 x 720 @ 32 bpp (SDL_PIXELFORMAT_RGBA8888)
WINDOW = SDL_CreateWindow("sdl2_gles2", 0, 0, 1280, 720, 0);
if (!WINDOW) {
SDL_Log("SDL_CreateWindow: %s\n", SDL_GetError());
Term_Services();
}
// create a renderer (OpenGL ES2)
RENDERER = SDL_CreateRenderer(WINDOW, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!RENDERER) {
SDL_Log("SDL_CreateRenderer: %s\n", SDL_GetError());
Term_Services();
}
// Get a reference to the window surface
// This has to be ran after you create the renderer.
WINDOW_SURFACE = SDL_GetWindowSurface(WINDOW);
romfsInit();
ARIAL_UNICODE = TTF_OpenFont("romfs:/arial.ttf", 35);
Textures_Load();
ARIAL_UNICODE = TTF_OpenFont("romfs:/res/font/arial.ttf", 35);
if (!ARIAL_UNICODE) {
Term_Services();
}
// open CONTROLLER_PLAYER_1 and CONTROLLER_PLAYER_2
// when railed, both joycons are mapped to joystick #0,
// else joycons are individually mapped to joystick #0, joystick #1, ...
// https://github.com/devkitPro/SDL/blob/switch-sdl2/src/joystick/switch/SDL_sysjoystick.c#L45
for (int i = 0; i < 2; i++) {
if (SDL_JoystickOpen(i) == NULL) {
SDL_Log("SDL_JoystickOpen: %s\n", SDL_GetError());
@ -113,17 +83,12 @@ void Init_Services() {
}
int main(int argc, char *argv[]) {
/*SDL_Renderer* RENDERER;
SDL_Window* WINDOW;
SDL_Surface* WINDOW_SURFACE;
TTF_Font* ARIAL_UNICODE;*/
//int x = 0, w = 1920, h = 1080;
Init_Services();
std::cout << "Opening test.epub" << std::endl;
Menu_OpenBook("/switch/eBookReader/books/test.epub");
//std::cout << "Opening test.pdf" << std::endl;
//Menu_OpenBook("/switch/eBookReader/books/test.pdf");
//Menu_OpenBook("/switch/eBookReader/books/test.epub");
Menu_StartChoosing();
while (run) {
while (SDL_PollEvent(&EVENT)) {

View File

@ -0,0 +1,53 @@
extern "C" {
#include "MenuChooser.h"
#include "common.h"
#include "SDL_helper.h"
}
#include <switch.h>
#include <iostream>
#include <dirent.h>
#include <sys/types.h>
//using namespace std;
void Menu_StartChoosing() {
int choosen_index = 0;
struct dirent *entry;
DIR *dir = opendir("/switch/eBookReader/books");
if (dir == NULL) {
return;
}
while(appletMainLoop()) {
SDL_ClearScreen(RENDERER, WHITE);
SDL_RenderClear(RENDERER);
int space_index = 0;
while ((entry = readdir(dir)) != NULL) {
SDL_DrawText(RENDERER, ARIAL_UNICODE, 20, 20 + (30 * space_index), BLACK, entry->d_name);
space_index++;
//cout << entry->d_name << endl;
}
SDL_RenderPresent(RENDERER);
}
}
/*void list_dir(const char *path) {
struct dirent *entry;
DIR *dir = opendir(path);
if (dir == NULL) {
return;
}
while ((entry = readdir(dir)) != NULL) {
entry->
//cout << entry->d_name << endl;
}
closedir(dir);
}*/

View File

@ -7,14 +7,12 @@
struct SDL_Texture;
typedef enum
{
typedef enum {
BookPageLayoutPortrait,
BookPageLayoutLandscape
} BookPageLayout;
class BookReader
{
class BookReader {
public:
BookReader(const char *path);
~BookReader();
@ -31,8 +29,7 @@ class BookReader
void switch_page_layout();
void draw();
BookPageLayout currentPageLayout()
{
BookPageLayout currentPageLayout() {
return _currentPageLayout;
}

View File

@ -1,7 +1,6 @@
extern "C" {
#include "menu_book_reader.h"
#include "common.h"
//#include "touch_helper.h"
}
#include "BookReader.hpp"

View File

@ -97,14 +97,14 @@ static void StatusBar_GetBatteryStatus(int x, int y)
}
snprintf(buf, 5, "%d%%", percent);
TTF_SizeText(Roboto, buf, &width, NULL);
SDL_DrawText(RENDERER, Roboto, (x - width - 10), y, WHITE, buf);
TTF_SizeText(ARIAL_UNICODE, buf, &width, NULL);
SDL_DrawText(RENDERER, ARIAL_UNICODE, (x - width - 10), y, WHITE, buf);
}
else
{
snprintf(buf, 5, "%d%%", percent);
TTF_SizeText(Roboto, buf, &width, NULL);
SDL_DrawText(RENDERER, Roboto, (x - width - 10), y, WHITE, buf);
TTF_SizeText(ARIAL_UNICODE, buf, &width, NULL);
SDL_DrawText(RENDERER, ARIAL_UNICODE, (x - width - 10), y, WHITE, buf);
SDL_DrawImage(RENDERER, battery_unknown, x, 1);
}
}
@ -112,8 +112,8 @@ static void StatusBar_GetBatteryStatus(int x, int y)
void StatusBar_DisplayTime(void)
{
int width = 0, height = 0;
TTF_SizeText(Roboto, Clock_GetCurrentTime(), &width, &height);
TTF_SizeText(ARIAL_UNICODE, Clock_GetCurrentTime(), &width, &height);
StatusBar_GetBatteryStatus(1260 - width - 44, (40 - height) / 2);
SDL_DrawText(RENDERER, Roboto, 1260 - width, (40 - height) / 2, WHITE, Clock_GetCurrentTime());
SDL_DrawText(RENDERER, ARIAL_UNICODE, 1260 - width, (40 - height) / 2, WHITE, Clock_GetCurrentTime());
}

143
source/textures.c Normal file
View File

@ -0,0 +1,143 @@
#include "common.h"
#include "SDL_helper.h"
#include "textures.h"
void Textures_Load(void) {
/*SDL_LoadImage(RENDERER, &icon_app, "romfs:/res/images/ic_fso_type_executable.png");
SDL_LoadImage(RENDERER, &icon_archive, "romfs:/res/images/ic_fso_type_compress.png");
SDL_LoadImage(RENDERER, &icon_audio, "romfs:/res/images/ic_fso_type_audio.png");
SDL_LoadImage(RENDERER, &icon_dir, "romfs:/res/images/ic_fso_folder.png");
SDL_LoadImage(RENDERER, &icon_dir_dark, "romfs:/res/images/ic_fso_folder_dark.png");
SDL_LoadImage(RENDERER, &icon_doc, "romfs:/res/images/ic_fso_type_document.png");
SDL_LoadImage(RENDERER, &icon_file, "romfs:/res/images/ic_fso_default.png");
SDL_LoadImage(RENDERER, &icon_image, "romfs:/res/images/ic_fso_type_image.png");
SDL_LoadImage(RENDERER, &icon_text, "romfs:/res/images/ic_fso_type_text.png");
SDL_LoadImage(RENDERER, &icon_check, "romfs:/res/images/btn_material_light_check_on_normal.png");
SDL_LoadImage(RENDERER, &icon_check_dark, "romfs:/res/images/btn_material_light_check_on_normal_dark.png");
SDL_LoadImage(RENDERER, &icon_uncheck, "romfs:/res/images/btn_material_light_check_off_normal.png");
SDL_LoadImage(RENDERER, &icon_uncheck_dark, "romfs:/res/images/btn_material_light_check_off_normal_dark.png");
SDL_LoadImage(RENDERER, &dialog, "romfs:/res/images/ic_material_dialog.png");
SDL_LoadImage(RENDERER, &options_dialog, "romfs:/res/images/ic_material_options_dialog.png");
SDL_LoadImage(RENDERER, &properties_dialog, "romfs:/res/images/ic_material_properties_dialog.png");
SDL_LoadImage(RENDERER, &dialog_dark, "romfs:/res/images/ic_material_dialog_dark.png");
SDL_LoadImage(RENDERER, &options_dialog_dark, "romfs:/res/images/ic_material_options_dialog_dark.png");
SDL_LoadImage(RENDERER, &properties_dialog_dark, "romfs:/res/images/ic_material_properties_dialog_dark.png");
SDL_LoadImage(RENDERER, &bg_header, "romfs:/res/images/bg_header.png");
SDL_LoadImage(RENDERER, &icon_settings, "romfs:/res/images/ic_material_light_settings.png");
SDL_LoadImage(RENDERER, &icon_sd, "romfs:/res/images/ic_material_light_sdcard.png");
SDL_LoadImage(RENDERER, &icon_secure, "romfs:/res/images/ic_material_light_secure.png");
SDL_LoadImage(RENDERER, &icon_settings_dark, "romfs:/res/images/ic_material_light_settings_dark.png");
SDL_LoadImage(RENDERER, &icon_sd_dark, "romfs:/res/images/ic_material_light_sdcard_dark.png");
SDL_LoadImage(RENDERER, &icon_secure_dark, "romfs:/res/images/ic_material_light_secure_dark.png");
SDL_LoadImage(RENDERER, &icon_radio_off, "romfs:/res/images/btn_material_light_radio_off_normal.png");
SDL_LoadImage(RENDERER, &icon_radio_on, "romfs:/res/images/btn_material_light_radio_on_normal.png");
SDL_LoadImage(RENDERER, &icon_radio_dark_off, "romfs:/res/images/btn_material_light_radio_off_normal_dark.png");
SDL_LoadImage(RENDERER, &icon_radio_dark_on, "romfs:/res/images/btn_material_light_radio_on_normal_dark.png");
SDL_LoadImage(RENDERER, &icon_toggle_on, "romfs:/res/images/btn_material_light_toggle_on_normal.png");
SDL_LoadImage(RENDERER, &icon_toggle_dark_on, "romfs:/res/images/btn_material_light_toggle_on_normal_dark.png");
SDL_LoadImage(RENDERER, &icon_toggle_off, "romfs:/res/images/btn_material_light_toggle_off_normal.png");
SDL_LoadImage(RENDERER, &default_artwork, "romfs:/res/images/default_artwork.png");
SDL_LoadImage(RENDERER, &default_artwork_blur, "romfs:/res/images/default_artwork_blur.png");
SDL_LoadImage(RENDERER, &btn_play, "romfs:/res/images/btn_playback_play.png");
SDL_LoadImage(RENDERER, &btn_pause, "romfs:/res/images/btn_playback_pause.png");
SDL_LoadImage(RENDERER, &btn_rewind, "romfs:/res/images/btn_playback_rewind.png");
SDL_LoadImage(RENDERER, &btn_forward, "romfs:/res/images/btn_playback_forward.png");
SDL_LoadImage(RENDERER, &btn_repeat, "romfs:/res/images/btn_playback_repeat.png");
SDL_LoadImage(RENDERER, &btn_shuffle, "romfs:/res/images/btn_playback_shuffle.png");
SDL_LoadImage(RENDERER, &btn_repeat_overlay, "romfs:/res/images/btn_playback_repeat_overlay.png");
SDL_LoadImage(RENDERER, &btn_shuffle_overlay, "romfs:/res/images/btn_playback_shuffle_overlay.png");
SDL_LoadImage(RENDERER, &icon_nav_drawer, "romfs:/res/images/ic_material_light_navigation_drawer.png");
SDL_LoadImage(RENDERER, &icon_actions, "romfs:/res/images/ic_material_light_contextual_action.png");
SDL_LoadImage(RENDERER, &icon_back, "romfs:/res/images/ic_arrow_back_normal.png");
SDL_LoadImage(RENDERER, &icon_accept, "romfs:/res/images/ic_material_light_accept.png");
SDL_LoadImage(RENDERER, &icon_accept_dark, "romfs:/res/images/ic_material_light_accept_dark.png");
SDL_LoadImage(RENDERER, &icon_remove, "romfs:/res/images/ic_material_light_remove.png");
SDL_LoadImage(RENDERER, &icon_remove_dark, "romfs:/res/images/ic_material_light_remove_dark.png");*/
SDL_LoadImage(RENDERER, &battery_20, "romfs:/res/images/battery_20.png");
SDL_LoadImage(RENDERER, &battery_20_charging, "romfs:/res/images/battery_20_charging.png");
SDL_LoadImage(RENDERER, &battery_30, "romfs:/res/images/battery_30.png");
SDL_LoadImage(RENDERER, &battery_30_charging, "romfs:/res/images/battery_30_charging.png");
SDL_LoadImage(RENDERER, &battery_50, "romfs:/res/images/battery_50.png");
SDL_LoadImage(RENDERER, &battery_50_charging, "romfs:/res/images/battery_50_charging.png");
SDL_LoadImage(RENDERER, &battery_60, "romfs:/res/images/battery_60.png");
SDL_LoadImage(RENDERER, &battery_60_charging, "romfs:/res/images/battery_60_charging.png");
SDL_LoadImage(RENDERER, &battery_80, "romfs:/res/images/battery_80.png");
SDL_LoadImage(RENDERER, &battery_80_charging, "romfs:/res/images/battery_80_charging.png");
SDL_LoadImage(RENDERER, &battery_90, "romfs:/res/images/battery_90.png");
SDL_LoadImage(RENDERER, &battery_90_charging, "romfs:/res/images/battery_90_charging.png");
SDL_LoadImage(RENDERER, &battery_full, "romfs:/res/images/battery_full.png");
SDL_LoadImage(RENDERER, &battery_full_charging, "romfs:/res/images/battery_full_charging.png");
SDL_LoadImage(RENDERER, &battery_low, "romfs:/res/images/battery_low.png");
SDL_LoadImage(RENDERER, &battery_unknown, "romfs:/res/images/battery_unknown.png");
//SDL_LoadImage(RENDERER, &icon_lock, "romfs:/res/images/ic_material_dialog_fs_locked.png");
}
void Textures_Free(void)
{
//SDL_DestroyTexture(icon_lock);
SDL_DestroyTexture(battery_unknown);
SDL_DestroyTexture(battery_low);
SDL_DestroyTexture(battery_full_charging);
SDL_DestroyTexture(battery_full);
SDL_DestroyTexture(battery_90_charging);
SDL_DestroyTexture(battery_80_charging);
SDL_DestroyTexture(battery_80);
SDL_DestroyTexture(battery_60_charging);
SDL_DestroyTexture(battery_60);
SDL_DestroyTexture(battery_50_charging);
SDL_DestroyTexture(battery_50);
SDL_DestroyTexture(battery_30_charging);
SDL_DestroyTexture(battery_30);
SDL_DestroyTexture(battery_20_charging);
SDL_DestroyTexture(battery_20);
/*SDL_DestroyTexture(icon_remove_dark);
SDL_DestroyTexture(icon_remove);
SDL_DestroyTexture(icon_accept_dark);
SDL_DestroyTexture(icon_accept);
SDL_DestroyTexture(icon_back);
SDL_DestroyTexture(icon_actions);
SDL_DestroyTexture(icon_nav_drawer);
SDL_DestroyTexture(btn_shuffle_overlay);
SDL_DestroyTexture(btn_repeat_overlay);
SDL_DestroyTexture(btn_shuffle);
SDL_DestroyTexture(btn_repeat);
SDL_DestroyTexture(btn_forward);
SDL_DestroyTexture(btn_rewind);
SDL_DestroyTexture(btn_pause);
SDL_DestroyTexture(btn_play);
SDL_DestroyTexture(default_artwork_blur);
SDL_DestroyTexture(default_artwork);
SDL_DestroyTexture(icon_toggle_off);
SDL_DestroyTexture(icon_toggle_dark_on);
SDL_DestroyTexture(icon_toggle_on);
SDL_DestroyTexture(icon_radio_dark_on);
SDL_DestroyTexture(icon_radio_dark_off);
SDL_DestroyTexture(icon_radio_on);
SDL_DestroyTexture(icon_radio_off);
SDL_DestroyTexture(icon_secure_dark);
SDL_DestroyTexture(icon_sd_dark);
SDL_DestroyTexture(icon_settings_dark);
SDL_DestroyTexture(icon_secure);
SDL_DestroyTexture(icon_sd);
SDL_DestroyTexture(icon_settings);
SDL_DestroyTexture(bg_header);
SDL_DestroyTexture(properties_dialog_dark);
SDL_DestroyTexture(options_dialog_dark);
SDL_DestroyTexture(dialog_dark);
SDL_DestroyTexture(properties_dialog);
SDL_DestroyTexture(options_dialog);
SDL_DestroyTexture(dialog);
SDL_DestroyTexture(icon_uncheck_dark);
SDL_DestroyTexture(icon_uncheck);
SDL_DestroyTexture(icon_check_dark);
SDL_DestroyTexture(icon_check);
SDL_DestroyTexture(icon_text);
SDL_DestroyTexture(icon_image);
SDL_DestroyTexture(icon_file);
SDL_DestroyTexture(icon_doc);
SDL_DestroyTexture(icon_dir_dark);
SDL_DestroyTexture(icon_dir);
SDL_DestroyTexture(icon_audio);
SDL_DestroyTexture(icon_archive);
SDL_DestroyTexture(icon_app);*/
}