mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2024-11-14 21:57:13 +00:00
Refactor GUI initialization and handle errors
This commit is contained in:
parent
33ca4974cb
commit
797b22ff60
8 changed files with 71 additions and 24 deletions
|
@ -36,8 +36,8 @@ APP_DESCRIPTION := Fast and simple save manager
|
|||
APP_AUTHOR := Bernardo Giordano
|
||||
|
||||
VERSION_MAJOR := 3
|
||||
VERSION_MINOR := 4
|
||||
VERSION_MICRO := 2
|
||||
VERSION_MINOR := 5
|
||||
VERSION_MICRO := 0
|
||||
|
||||
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
|
||||
OUTDIR := out
|
||||
|
|
|
@ -31,8 +31,8 @@ include $(DEVKITPRO)/libnx/switch_rules
|
|||
# - <libnx folder>/default_icon.jpg
|
||||
#---------------------------------------------------------------------------------
|
||||
VERSION_MAJOR := 3
|
||||
VERSION_MINOR := 4
|
||||
VERSION_MICRO := 2
|
||||
VERSION_MINOR := 5
|
||||
VERSION_MICRO := 0
|
||||
|
||||
APP_TITLE := Checkpoint
|
||||
APP_AUTHOR := Bernardo Giordano
|
||||
|
@ -68,7 +68,8 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17
|
|||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-no-as-needed,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx
|
||||
LIBS := -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
// #include <SDL2/SDL_mixer.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "SDL_FontCache.h"
|
||||
|
@ -24,5 +25,6 @@ void SDLH_DrawIcon(std::string icon, int x, int y);
|
|||
void SDLH_GetTextDimensions(int size, const char* text, u32* w, u32* h);
|
||||
void SDLH_DrawTextBox(int size, int x, int y, SDL_Color color, int max, const char* text);
|
||||
void SDLH_Render(void);
|
||||
void SDLH_PlayClick(void);
|
||||
|
||||
#endif
|
|
@ -45,7 +45,7 @@
|
|||
|
||||
namespace Gui
|
||||
{
|
||||
void init(void);
|
||||
bool init(void);
|
||||
void exit(void);
|
||||
void draw(u128 uid);
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#define MAIN_HPP
|
||||
|
||||
#include <switch.h>
|
||||
#include "io.hpp"
|
||||
#include "title.hpp"
|
||||
#include "util.hpp"
|
||||
#include "io.hpp"
|
||||
|
||||
extern u128 g_currentUId;
|
||||
extern u8 g_currentUserIndex;
|
||||
|
|
|
@ -5,6 +5,7 @@ static SDL_Renderer* s_renderer;
|
|||
static SDL_Texture* s_star;
|
||||
static SDL_Texture* s_checkbox;
|
||||
static SDL_Texture* s_flag;
|
||||
// static Mix_Music* s_click;
|
||||
|
||||
static PlFontData fontData, fontExtData;
|
||||
static std::unordered_map<int, FC_Font*> s_fonts;
|
||||
|
@ -24,20 +25,46 @@ static FC_Font* getFontFromMap(int size)
|
|||
|
||||
bool SDLH_Init(void)
|
||||
{
|
||||
bool ok = false;
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
|
||||
{
|
||||
fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
s_window = SDL_CreateWindow("Checkpoint", 0, 0, 1280, 720, SDL_WINDOW_FULLSCREEN);
|
||||
if (!s_window)
|
||||
{
|
||||
fprintf(stderr, "SDL_CreateWindow: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
s_renderer = SDL_CreateRenderer(s_window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (!s_renderer)
|
||||
{
|
||||
fprintf(stderr, "SDL_CreateRenderer: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
SDL_SetRenderDrawBlendMode(s_renderer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
||||
IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
|
||||
|
||||
plGetSharedFontByType(&fontData, PlSharedFontType_Standard);
|
||||
plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt);
|
||||
|
||||
const int img_flags = IMG_INIT_PNG | IMG_INIT_JPG;
|
||||
if ((IMG_Init(img_flags) & img_flags) != img_flags)
|
||||
{
|
||||
fprintf(stderr, "IMG_Init: %s\n", IMG_GetError());
|
||||
return false;
|
||||
}
|
||||
SDLH_LoadImage(&s_flag, "romfs:/flag.png");
|
||||
SDLH_LoadImage(&s_star, "romfs:/star.png");
|
||||
SDLH_LoadImage(&s_checkbox, "romfs:/checkbox.png");
|
||||
|
||||
// const int mix_flags = MIX_INIT_OGG;
|
||||
// if ((Mix_Init(mix_flags) & mix_flags) != mix_flags)
|
||||
// {
|
||||
// fprintf(stderr, "Mix_Init: %s\n", Mix_GetError());
|
||||
// }
|
||||
// Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 4096);
|
||||
// s_click = Mix_LoadMUS("romfs:/click.ogg");
|
||||
|
||||
plGetSharedFontByType(&fontData, PlSharedFontType_Standard);
|
||||
plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -50,6 +77,9 @@ void SDLH_Exit(void)
|
|||
}
|
||||
|
||||
TTF_Quit();
|
||||
// Mix_FreeMusic(s_click);
|
||||
// Mix_CloseAudio();
|
||||
// Mix_Quit();
|
||||
SDL_DestroyTexture(s_flag);
|
||||
SDL_DestroyTexture(s_star);
|
||||
SDL_DestroyTexture(s_checkbox);
|
||||
|
@ -163,4 +193,9 @@ void SDLH_DrawIcon(std::string icon, int x, int y)
|
|||
if (t != nullptr) {
|
||||
SDLH_DrawImage(t, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void SDLH_PlayClick(void)
|
||||
// {
|
||||
// Mix_PlayMusic(s_click, 1);
|
||||
// }
|
|
@ -165,7 +165,7 @@ static void drawBackground(void)
|
|||
SDLH_GetTextDimensions(30, "checkpoint", &checkpoint_w, NULL);
|
||||
u32 h = (bar_height - ver_h) / 2 - 1;
|
||||
SDLH_DrawText(23, 10, h + 3, COLOR_GREY_LIGHT, DateTime::timeStr().c_str());
|
||||
SDLH_DrawText(30, 1280 - 10 - ver_w - image_dim - 12 - checkpoint_w, h, COLOR_WHITE, "checkpoint");
|
||||
SDLH_DrawText(30, 1280 - 10 - ver_w - image_dim - 12 - checkpoint_w, h - 2, COLOR_WHITE, "checkpoint");
|
||||
SDLH_DrawText(23, 1280 - 10 - ver_w, h + 3, COLOR_GREY_LIGHT, ver);
|
||||
SDLH_DrawIcon("flag", 1280 - 10 - ver_w - image_dim - 6, -2);
|
||||
// shadow
|
||||
|
@ -232,9 +232,13 @@ bool Gui::askForConfirmation(const std::string& text)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void Gui::init(void)
|
||||
bool Gui::init(void)
|
||||
{
|
||||
SDLH_Init();
|
||||
if (!SDLH_Init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sprintf(ver, "v%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);
|
||||
backupScrollEnabled = false;
|
||||
info = new Info();
|
||||
|
@ -254,6 +258,8 @@ void Gui::init(void)
|
|||
messageBox->push_message("Hold \ue003 to multiselect all titles.");
|
||||
messageBox->push_message("Press \ue041 to move between titles.");
|
||||
messageBox->push_message("Press \ue085/\ue086 to switch user.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Gui::exit(void)
|
||||
|
|
|
@ -40,6 +40,12 @@ void servicesExit(void)
|
|||
|
||||
Result servicesInit(void)
|
||||
{
|
||||
// debug
|
||||
// if (socketInitializeDefault() == 0)
|
||||
// {
|
||||
// nxlinkStdio();
|
||||
// }
|
||||
|
||||
Result res = 0;
|
||||
romfsInit();
|
||||
res = io::createDirectory("sdmc:/switch");
|
||||
|
@ -65,13 +71,10 @@ Result servicesInit(void)
|
|||
return res;
|
||||
}
|
||||
|
||||
Gui::init();
|
||||
|
||||
// debug
|
||||
// if (socketInitializeDefault() == 0)
|
||||
// {
|
||||
// nxlinkStdio();
|
||||
// }
|
||||
if (!Gui::init())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
Configuration::getInstance();
|
||||
|
||||
|
|
Loading…
Reference in a new issue