Skip to content
Snippets Groups Projects
main.cpp 1.79 KiB
Newer Older
PoloNX's avatar
PoloNX committed
#include <iostream>
#include <switch.h>

#include "RenderWindow.hpp"
#include "Menu.hpp"
#include "Reboot.hpp"
#include "Cursor.hpp"

#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL2_gfxPrimitives.h>

void init();

int main(int argc, char *argv[])
{
    init();
  
    RenderWindow window("PayloadReboot", 1280, 720);
    Menu menu (window);
	Cursor cursor;
	Input input;

	SDL_Event event;
	int inputValue = -1;
PoloNX's avatar
PoloNX committed
	int inputcheck = 0;
PoloNX's avatar
PoloNX committed

    bool isOpen = true;

    while (isOpen)
	{
		//input.checkInput();

		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_JOYBUTTONDOWN:
					inputValue = event.jbutton.button;
PoloNX's avatar
PoloNX committed
					inputcheck = cursor.checkInputCursor(inputValue);
					if(inputcheck == 1)
PoloNX's avatar
PoloNX committed
					{
						menu.printAbout();
					}
PoloNX's avatar
PoloNX committed
					else if(inputcheck == 2)
					{
						isOpen = false;
					}
PoloNX's avatar
PoloNX committed
				
				default:
					inputValue = -1;
			}
		}

		window.clear();

        menu.printMenu();

		Reboot reboot;
		//reboot.rebootNow(3);

		cursor.printCursor(window);

		window.display();

		SDL_Delay(1000 / window.getRefreshRate());
	}

PoloNX's avatar
PoloNX committed
	SDL_Quit();
	IMG_Quit();
	TTF_Quit();
	return 0;
PoloNX's avatar
PoloNX committed
}

void init()
{
    socketInitializeDefault();
    nxlinkStdio();  //redirect cout/cer to tcp

    if (SDL_Init(SDL_INIT_VIDEO) > 0)
	{
		std::cout << "HEY... SDL_Init HAS FAILED. SDL_ERROR: " << SDL_GetError() << std::endl;
	}

	if (!(IMG_Init(IMG_INIT_PNG)))
	{
		std::cout << "HEY... IMG_Init HAS FAILED. SDL_ERROR: " << IMG_GetError() << std::endl;
	}

	if (!(TTF_Init()))
	{
PoloNX's avatar
PoloNX committed
		std::cout << "HEY... TTF_Init HAS FAILED. SDL_ERROR: " << TTF_GetError() << std::endl;
PoloNX's avatar
PoloNX committed
	}

    std::cout << "after ttf\n";

    SDL_InitSubSystem(SDL_INIT_EVERYTHING); //Some init 
    SDL_JoystickEventState(SDL_ENABLE); //Joystick
    SDL_JoystickOpen(0);    //Open joystick
    romfsInit();    //Init of romfs
}