2019-08-29 02:40:26 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2019-09-01 19:52:42 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2019-08-30 14:38:38 +00:00
|
|
|
#include <switch.h>
|
2019-08-29 02:40:26 +00:00
|
|
|
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include <SDL2/SDL_ttf.h>
|
2019-09-03 22:17:53 +00:00
|
|
|
#include <SDL2/SDL_image.h>
|
2019-08-29 02:40:26 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include <twili.h>
|
|
|
|
#endif
|
2019-09-01 19:52:42 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "common.h"
|
2019-09-02 02:55:49 +00:00
|
|
|
#include "textures.h"
|
|
|
|
#include "MenuChooser.h"
|
2019-09-07 04:45:10 +00:00
|
|
|
#include "fs.h"
|
|
|
|
#include "config.h"
|
2019-09-01 19:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Renderer* RENDERER;
|
|
|
|
SDL_Window* WINDOW;
|
2019-09-03 22:17:53 +00:00
|
|
|
//SDL_Surface* WINDOW_SURFACE;
|
2019-09-01 19:52:42 +00:00
|
|
|
SDL_Event EVENT;
|
2019-09-03 22:17:53 +00:00
|
|
|
TTF_Font *ARIAL, *ARIAL_35, *ARIAL_30, *ARIAL_27, *ARIAL_25, *ARIAL_20, *ARIAL_15;
|
2019-09-07 04:45:10 +00:00
|
|
|
bool configDarkMode;
|
2019-09-01 19:52:42 +00:00
|
|
|
bool run = true;
|
|
|
|
|
|
|
|
void Term_Services() {
|
|
|
|
std::cout << "Terminate Serices" << std::endl;
|
2019-09-03 22:17:53 +00:00
|
|
|
run = false;
|
2019-09-01 19:52:42 +00:00
|
|
|
|
2019-09-02 20:24:09 +00:00
|
|
|
timeExit();
|
2019-09-03 22:17:53 +00:00
|
|
|
TTF_CloseFont(ARIAL_35);
|
|
|
|
TTF_CloseFont(ARIAL_30);
|
|
|
|
TTF_CloseFont(ARIAL_27);
|
|
|
|
TTF_CloseFont(ARIAL_25);
|
|
|
|
TTF_CloseFont(ARIAL_20);
|
|
|
|
TTF_CloseFont(ARIAL_15);
|
2019-09-02 20:24:09 +00:00
|
|
|
TTF_CloseFont(ARIAL);
|
2019-09-01 19:52:42 +00:00
|
|
|
TTF_Quit();
|
|
|
|
|
2019-09-02 02:55:49 +00:00
|
|
|
Textures_Free();
|
2019-09-01 19:52:42 +00:00
|
|
|
romfsExit();
|
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
IMG_Quit();
|
|
|
|
|
2019-09-01 19:52:42 +00:00
|
|
|
SDL_DestroyRenderer(RENDERER);
|
2019-09-03 22:17:53 +00:00
|
|
|
//SDL_FreeSurface(WINDOW_SURFACE);
|
2019-09-01 19:52:42 +00:00
|
|
|
SDL_DestroyWindow(WINDOW);
|
|
|
|
SDL_Quit();
|
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
twiliExit();
|
|
|
|
#endif
|
2019-08-30 14:38:38 +00:00
|
|
|
}
|
2019-08-29 02:40:26 +00:00
|
|
|
|
2019-09-01 19:52:42 +00:00
|
|
|
void Init_Services() {
|
2019-09-03 22:17:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
twiliInitialize();
|
|
|
|
#endif
|
|
|
|
|
2019-09-01 19:52:42 +00:00
|
|
|
std::cout << "Initalize Serices" << std::endl;
|
2019-08-29 02:40:26 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
romfsInit();
|
|
|
|
std::cout << "Initalized RomFs" << std::endl;
|
|
|
|
|
2019-08-29 02:40:26 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
|
|
|
SDL_Log("SDL_Init: %s\n", SDL_GetError());
|
2019-09-01 19:52:42 +00:00
|
|
|
Term_Services();
|
2019-08-29 02:40:26 +00:00
|
|
|
}
|
2019-09-02 20:24:09 +00:00
|
|
|
std::cout << "Initalized SDL" << std::endl;
|
2019-08-29 02:40:26 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
timeInitialize();
|
|
|
|
std::cout << "Initalized Time" << std::endl;
|
2019-09-01 19:52:42 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
if (SDL_CreateWindowAndRenderer(1280, 720, 0, &WINDOW, &RENDERER) == -1) {
|
|
|
|
SDL_Log("SDL_CreateWindowAndRenderer: %s\n", SDL_GetError());
|
2019-09-01 19:52:42 +00:00
|
|
|
Term_Services();
|
2019-08-29 02:40:26 +00:00
|
|
|
}
|
2019-09-03 22:17:53 +00:00
|
|
|
std::cout << "Initalized Window and Renderer" << std::endl;
|
2019-08-29 02:40:26 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
SDL_SetRenderDrawBlendMode(RENDERER, SDL_BLENDMODE_BLEND);
|
|
|
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
2019-09-01 19:52:42 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
if (!IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG)) {
|
|
|
|
SDL_Log("IMG_Init: %s\n", IMG_GetError());
|
|
|
|
Term_Services();
|
|
|
|
}
|
|
|
|
std::cout << "Initalized Image" << std::endl;
|
2019-09-02 20:24:09 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
if(TTF_Init() == -1) {
|
|
|
|
SDL_Log("TTF_Init: %s\n", TTF_GetError());
|
|
|
|
Term_Services();
|
|
|
|
}
|
|
|
|
std::cout << "Initalized TTF" << std::endl;
|
2019-09-02 20:24:09 +00:00
|
|
|
|
2019-09-03 22:17:53 +00:00
|
|
|
#ifdef EXPERIMENTAL
|
|
|
|
std::cout << "Loading Textures" << std::endl;
|
|
|
|
Textures_Load();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ARIAL_35 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 35);
|
|
|
|
ARIAL_30 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 30);
|
|
|
|
ARIAL_27 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 27);
|
|
|
|
ARIAL_25 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 25);
|
|
|
|
ARIAL_20 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 20);
|
|
|
|
ARIAL_15 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 15);
|
|
|
|
ARIAL = TTF_OpenFont("romfs:/resources/font/arial.ttf", 20);
|
|
|
|
if (!ARIAL_35 || !ARIAL_25 || !ARIAL_15 || !ARIAL) {
|
|
|
|
std::cout << "Failure to retrieve fonts" << std::endl;
|
2019-09-01 19:52:42 +00:00
|
|
|
Term_Services();
|
|
|
|
}
|
2019-09-03 22:17:53 +00:00
|
|
|
std::cout << "Retrevied Fonts" << std::endl;
|
2019-09-02 02:55:49 +00:00
|
|
|
|
2019-08-29 14:52:59 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
if (SDL_JoystickOpen(i) == NULL) {
|
|
|
|
SDL_Log("SDL_JoystickOpen: %s\n", SDL_GetError());
|
2019-09-01 19:52:42 +00:00
|
|
|
Term_Services();
|
2019-08-29 14:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-02 20:24:09 +00:00
|
|
|
std::cout << "Initalized Input" << std::endl;
|
2019-09-07 04:45:10 +00:00
|
|
|
|
|
|
|
FS_RecursiveMakeDir("/switch/eBookReader/books");
|
2019-09-20 00:12:38 +00:00
|
|
|
std::cout << "Created book directory if needed" << std::endl;
|
2019-09-07 04:45:10 +00:00
|
|
|
|
2019-09-20 00:12:38 +00:00
|
|
|
configDarkMode = true;
|
2019-09-01 19:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
Init_Services();
|
|
|
|
|
2019-09-02 02:55:49 +00:00
|
|
|
Menu_StartChoosing();
|
2019-09-01 19:52:42 +00:00
|
|
|
|
|
|
|
Term_Services();
|
2019-08-29 14:52:59 +00:00
|
|
|
return 0;
|
2019-09-20 00:12:38 +00:00
|
|
|
}
|