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-01 19:52:42 +00:00
|
|
|
#include <twili.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "common.h"
|
2019-09-02 20:24:09 +00:00
|
|
|
//#include "SDL_helper.h"
|
2019-09-02 02:55:49 +00:00
|
|
|
#include "textures.h"
|
|
|
|
#include "MenuChooser.h"
|
2019-09-01 19:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Renderer* RENDERER;
|
|
|
|
SDL_Window* WINDOW;
|
|
|
|
SDL_Surface* WINDOW_SURFACE;
|
2019-09-02 20:24:09 +00:00
|
|
|
TTF_Font* ARIAL;
|
2019-09-01 19:52:42 +00:00
|
|
|
SDL_Event EVENT;
|
|
|
|
|
|
|
|
bool run = true;
|
|
|
|
|
|
|
|
void Term_Services() {
|
|
|
|
std::cout << "Terminate Serices" << std::endl;
|
|
|
|
|
2019-09-02 20:24:09 +00:00
|
|
|
timeExit();
|
|
|
|
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();
|
|
|
|
|
|
|
|
SDL_DestroyRenderer(RENDERER);
|
2019-09-02 02:55:49 +00:00
|
|
|
SDL_FreeSurface(WINDOW_SURFACE);
|
2019-09-01 19:52:42 +00:00
|
|
|
SDL_DestroyWindow(WINDOW);
|
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
twiliExit();
|
|
|
|
run = false;
|
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-02 20:24:09 +00:00
|
|
|
timeInitialize();
|
2019-09-01 19:52:42 +00:00
|
|
|
twiliInitialize();
|
|
|
|
std::cout << "Initalize Serices" << 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-02 20:24:09 +00:00
|
|
|
if(TTF_Init()==-1) {
|
|
|
|
printf("TTF_Init: %s\n", TTF_GetError());
|
|
|
|
Term_Services();
|
|
|
|
}
|
|
|
|
std::cout << "Initalized TTF" << std::endl;
|
2019-09-01 19:52:42 +00:00
|
|
|
|
2019-09-01 21:40:08 +00:00
|
|
|
WINDOW = SDL_CreateWindow("sdl2_gles2", 0, 0, 1280, 720, 0);
|
2019-09-01 19:52:42 +00:00
|
|
|
if (!WINDOW) {
|
2019-08-29 02:40:26 +00:00
|
|
|
SDL_Log("SDL_CreateWindow: %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 Window" << std::endl;
|
2019-08-29 02:40:26 +00:00
|
|
|
|
2019-09-01 19:52:42 +00:00
|
|
|
RENDERER = SDL_CreateRenderer(WINDOW, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
|
|
|
if (!RENDERER) {
|
2019-08-29 02:40:26 +00:00
|
|
|
SDL_Log("SDL_CreateRenderer: %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 Renderer" << std::endl;
|
2019-08-29 02:40:26 +00:00
|
|
|
|
2019-09-01 19:52:42 +00:00
|
|
|
WINDOW_SURFACE = SDL_GetWindowSurface(WINDOW);
|
2019-09-02 20:24:09 +00:00
|
|
|
std::cout << "Retrevied Window Surface" << std::endl;
|
2019-09-01 19:52:42 +00:00
|
|
|
|
2019-08-30 14:38:38 +00:00
|
|
|
romfsInit();
|
2019-09-02 20:24:09 +00:00
|
|
|
std::cout << "Initalized RomFs" << std::endl;
|
|
|
|
|
|
|
|
/*std::cout << "Loading Textures" << std::endl;
|
2019-09-02 02:55:49 +00:00
|
|
|
Textures_Load();
|
2019-09-02 20:24:09 +00:00
|
|
|
std::cout << "Loaded Textures" << std::endl;*/
|
|
|
|
|
|
|
|
ARIAL = TTF_OpenFont("romfs:/arial.ttf", 35);
|
|
|
|
if (!ARIAL) {
|
2019-09-01 19:52:42 +00:00
|
|
|
Term_Services();
|
|
|
|
}
|
2019-09-02 20:24:09 +00:00
|
|
|
std::cout << "Gotten 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-01 19:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
Init_Services();
|
|
|
|
|
2019-09-02 02:55:49 +00:00
|
|
|
//std::cout << "Opening test.pdf" << std::endl;
|
|
|
|
//Menu_OpenBook("/switch/eBookReader/books/test.pdf");
|
2019-09-01 19:52:42 +00:00
|
|
|
//Menu_OpenBook("/switch/eBookReader/books/test.epub");
|
2019-09-02 02:55:49 +00:00
|
|
|
Menu_StartChoosing();
|
2019-09-01 19:52:42 +00:00
|
|
|
|
2019-09-02 20:24:09 +00:00
|
|
|
bool isBookReading = false;
|
2019-09-01 19:52:42 +00:00
|
|
|
while (run) {
|
|
|
|
while (SDL_PollEvent(&EVENT)) {
|
|
|
|
switch (EVENT.type) {
|
2019-08-30 14:38:38 +00:00
|
|
|
case SDL_JOYAXISMOTION:
|
2019-09-01 19:52:42 +00:00
|
|
|
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);*/
|
2019-09-02 20:24:09 +00:00
|
|
|
/*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;
|
|
|
|
}*/
|
2019-09-01 19:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Term_Services();
|
2019-08-29 14:52:59 +00:00
|
|
|
return 0;
|
2019-08-29 02:40:26 +00:00
|
|
|
}
|