mirror of
https://github.com/joel16/SwitchIdent.git
synced 2024-11-26 21:20:26 +00:00
gui: Remove SDL_FontCache (fixes displaying the '%' symbol)
This commit is contained in:
parent
43f95bf586
commit
8a943aa857
@ -1,327 +0,0 @@
|
||||
/*
|
||||
SDL_FontCache v0.10.0: A font cache for SDL and SDL_ttf
|
||||
by Jonathan Dearborn
|
||||
Dedicated to the memory of Florian Hufsky
|
||||
|
||||
License:
|
||||
The short:
|
||||
Use it however you'd like, but keep the copyright and license notice
|
||||
whenever these files or parts of them are distributed in uncompiled form.
|
||||
|
||||
The long:
|
||||
Copyright (c) 2019 Jonathan Dearborn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _SDL_FONTCACHE_H__
|
||||
#define _SDL_FONTCACHE_H__
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_ttf.h"
|
||||
|
||||
#ifdef FC_USE_SDL_GPU
|
||||
#include "SDL_gpu.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Let's pretend this exists...
|
||||
#define TTF_STYLE_OUTLINE 16
|
||||
|
||||
|
||||
|
||||
// Differences between SDL_Renderer and SDL_gpu
|
||||
#ifdef FC_USE_SDL_GPU
|
||||
#define FC_Rect GPU_Rect
|
||||
#define FC_Target GPU_Target
|
||||
#define FC_Image GPU_Image
|
||||
#define FC_Log GPU_LogError
|
||||
#else
|
||||
#define FC_Rect SDL_Rect
|
||||
#define FC_Target SDL_Renderer
|
||||
#define FC_Image SDL_Texture
|
||||
#define FC_Log SDL_Log
|
||||
#endif
|
||||
|
||||
|
||||
// SDL_FontCache types
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FC_ALIGN_LEFT,
|
||||
FC_ALIGN_CENTER,
|
||||
FC_ALIGN_RIGHT
|
||||
} FC_AlignEnum;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FC_FILTER_NEAREST,
|
||||
FC_FILTER_LINEAR
|
||||
} FC_FilterEnum;
|
||||
|
||||
typedef struct FC_Scale
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
|
||||
} FC_Scale;
|
||||
|
||||
typedef struct FC_Effect
|
||||
{
|
||||
FC_AlignEnum alignment;
|
||||
FC_Scale scale;
|
||||
SDL_Color color;
|
||||
|
||||
} FC_Effect;
|
||||
|
||||
// Opaque type
|
||||
typedef struct FC_Font FC_Font;
|
||||
|
||||
|
||||
typedef struct FC_GlyphData
|
||||
{
|
||||
SDL_Rect rect;
|
||||
int cache_level;
|
||||
|
||||
} FC_GlyphData;
|
||||
|
||||
|
||||
|
||||
|
||||
// Object creation
|
||||
|
||||
FC_Rect FC_MakeRect(float x, float y, float w, float h);
|
||||
|
||||
FC_Scale FC_MakeScale(float x, float y);
|
||||
|
||||
SDL_Color FC_MakeColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
FC_Effect FC_MakeEffect(FC_AlignEnum alignment, FC_Scale scale, SDL_Color color);
|
||||
|
||||
FC_GlyphData FC_MakeGlyphData(int cache_level, Sint16 x, Sint16 y, Uint16 w, Uint16 h);
|
||||
|
||||
|
||||
|
||||
// Font object
|
||||
|
||||
FC_Font* FC_CreateFont(void);
|
||||
|
||||
#ifdef FC_USE_SDL_GPU
|
||||
Uint8 FC_LoadFont(FC_Font* font, const char* filename_ttf, Uint32 pointSize, SDL_Color color, int style);
|
||||
|
||||
Uint8 FC_LoadFontFromTTF(FC_Font* font, TTF_Font* ttf, SDL_Color color);
|
||||
|
||||
Uint8 FC_LoadFont_RW(FC_Font* font, SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, SDL_Color color, int style);
|
||||
#else
|
||||
Uint8 FC_LoadFont(FC_Font* font, SDL_Renderer* renderer, const char* filename_ttf, Uint32 pointSize, SDL_Color color, int style);
|
||||
|
||||
Uint8 FC_LoadFontFromTTF(FC_Font* font, SDL_Renderer* renderer, TTF_Font* ttf, SDL_Color color);
|
||||
|
||||
Uint8 FC_LoadFont_RW(FC_Font* font, SDL_Renderer* renderer, SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, SDL_Color color, int style);
|
||||
#endif
|
||||
|
||||
#ifndef FC_USE_SDL_GPU
|
||||
// note: handle SDL event types SDL_RENDER_TARGETS_RESET(>= SDL 2.0.2) and SDL_RENDER_DEVICE_RESET(>= SDL 2.0.4)
|
||||
void FC_ResetFontFromRendererReset(FC_Font* font, SDL_Renderer* renderer, Uint32 evType);
|
||||
#endif
|
||||
|
||||
void FC_ClearFont(FC_Font* font);
|
||||
|
||||
void FC_FreeFont(FC_Font* font);
|
||||
|
||||
|
||||
|
||||
// Built-in loading strings
|
||||
|
||||
char* FC_GetStringASCII(void);
|
||||
|
||||
char* FC_GetStringLatin1(void);
|
||||
|
||||
char* FC_GetStringASCII_Latin1(void);
|
||||
|
||||
|
||||
// UTF-8 to SDL_FontCache codepoint conversion
|
||||
|
||||
/*!
|
||||
Returns the Uint32 codepoint (not UTF-32) parsed from the given UTF-8 string.
|
||||
\param c A pointer to a string of proper UTF-8 character values.
|
||||
\param advance_pointer If true, the source pointer will be incremented to skip the extra bytes from multibyte codepoints.
|
||||
*/
|
||||
Uint32 FC_GetCodepointFromUTF8(const char** c, Uint8 advance_pointer);
|
||||
|
||||
/*!
|
||||
Parses the given codepoint and stores the UTF-8 bytes in 'result'. The result is NULL terminated.
|
||||
\param result A memory buffer for the UTF-8 values. Must be at least 5 bytes long.
|
||||
\param codepoint The Uint32 codepoint to parse (not UTF-32).
|
||||
*/
|
||||
void FC_GetUTF8FromCodepoint(char* result, Uint32 codepoint);
|
||||
|
||||
|
||||
// UTF-8 string operations
|
||||
|
||||
/*! Allocates a new string of 'size' bytes that is already NULL-terminated. The NULL byte counts toward the size limit, as usual. Returns NULL if size is 0. */
|
||||
char* U8_alloc(unsigned int size);
|
||||
|
||||
/*! Deallocates the given string. */
|
||||
void U8_free(char* string);
|
||||
|
||||
/*! Allocates a copy of the given string. */
|
||||
char* U8_strdup(const char* string);
|
||||
|
||||
/*! Returns the number of UTF-8 characters in the given string. */
|
||||
int U8_strlen(const char* string);
|
||||
|
||||
/*! Returns the number of bytes in the UTF-8 multibyte character pointed at by 'character'. */
|
||||
int U8_charsize(const char* character);
|
||||
|
||||
/*! Copies the source multibyte character into the given buffer without overrunning it. Returns 0 on failure. */
|
||||
int U8_charcpy(char* buffer, const char* source, int buffer_size);
|
||||
|
||||
/*! Returns a pointer to the next UTF-8 character. */
|
||||
const char* U8_next(const char* string);
|
||||
|
||||
/*! Inserts a UTF-8 string into 'string' at the given position. Use a position of -1 to append. Returns 0 when unable to insert the string. */
|
||||
int U8_strinsert(char* string, int position, const char* source, int max_bytes);
|
||||
|
||||
/*! Erases the UTF-8 character at the given position, moving the subsequent characters down. */
|
||||
void U8_strdel(char* string, int position);
|
||||
|
||||
|
||||
// Internal settings
|
||||
|
||||
/*! Sets the string from which to load the initial glyphs. Use this if you need upfront loading for any reason (such as lack of render-target support). */
|
||||
void FC_SetLoadingString(FC_Font* font, const char* string);
|
||||
|
||||
/*! Returns the size of the internal buffer which is used for unpacking variadic text data. This buffer is shared by all FC_Fonts. */
|
||||
unsigned int FC_GetBufferSize(void);
|
||||
|
||||
/*! Changes the size of the internal buffer which is used for unpacking variadic text data. This buffer is shared by all FC_Fonts. */
|
||||
void FC_SetBufferSize(unsigned int size);
|
||||
|
||||
/*! Returns the width of a single horizontal tab in multiples of the width of a space (default: 4) */
|
||||
unsigned int FC_GetTabWidth(void);
|
||||
|
||||
/*! Changes the width of a horizontal tab in multiples of the width of a space (default: 4) */
|
||||
void FC_SetTabWidth(unsigned int width_in_spaces);
|
||||
|
||||
void FC_SetRenderCallback(FC_Rect (*callback)(FC_Image* src, FC_Rect* srcrect, FC_Target* dest, float x, float y, float xscale, float yscale));
|
||||
|
||||
FC_Rect FC_DefaultRenderCallback(FC_Image* src, FC_Rect* srcrect, FC_Target* dest, float x, float y, float xscale, float yscale);
|
||||
|
||||
|
||||
// Custom caching
|
||||
|
||||
/*! Returns the number of cache levels that are active. */
|
||||
int FC_GetNumCacheLevels(FC_Font* font);
|
||||
|
||||
/*! Returns the cache source texture at the given cache level. */
|
||||
FC_Image* FC_GetGlyphCacheLevel(FC_Font* font, int cache_level);
|
||||
|
||||
// TODO: Specify ownership of the texture (should be shareable)
|
||||
/*! Sets a cache source texture for rendering. New cache levels must be sequential. */
|
||||
Uint8 FC_SetGlyphCacheLevel(FC_Font* font, int cache_level, FC_Image* cache_texture);
|
||||
|
||||
/*! Copies the given surface to the given cache level as a texture. New cache levels must be sequential. */
|
||||
Uint8 FC_UploadGlyphCache(FC_Font* font, int cache_level, SDL_Surface* data_surface);
|
||||
|
||||
|
||||
/*! Returns the number of codepoints that are stored in the font's glyph data map. */
|
||||
unsigned int FC_GetNumCodepoints(FC_Font* font);
|
||||
|
||||
/*! Copies the stored codepoints into the given array. */
|
||||
void FC_GetCodepoints(FC_Font* font, Uint32* result);
|
||||
|
||||
/*! Stores the glyph data for the given codepoint in 'result'. Returns 0 if the codepoint was not found in the cache. */
|
||||
Uint8 FC_GetGlyphData(FC_Font* font, FC_GlyphData* result, Uint32 codepoint);
|
||||
|
||||
/*! Sets the glyph data for the given codepoint. Duplicates are not checked. Returns a pointer to the stored data. */
|
||||
FC_GlyphData* FC_SetGlyphData(FC_Font* font, Uint32 codepoint, FC_GlyphData glyph_data);
|
||||
|
||||
|
||||
// Rendering
|
||||
|
||||
FC_Rect FC_Draw(FC_Font* font, FC_Target* dest, float x, float y, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawAlign(FC_Font* font, FC_Target* dest, float x, float y, FC_AlignEnum align, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawScale(FC_Font* font, FC_Target* dest, float x, float y, FC_Scale scale, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawColor(FC_Font* font, FC_Target* dest, float x, float y, SDL_Color color, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawEffect(FC_Font* font, FC_Target* dest, float x, float y, FC_Effect effect, const char* formatted_text, ...);
|
||||
|
||||
FC_Rect FC_DrawBox(FC_Font* font, FC_Target* dest, FC_Rect box, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawBoxAlign(FC_Font* font, FC_Target* dest, FC_Rect box, FC_AlignEnum align, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawBoxScale(FC_Font* font, FC_Target* dest, FC_Rect box, FC_Scale scale, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawBoxColor(FC_Font* font, FC_Target* dest, FC_Rect box, SDL_Color color, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawBoxEffect(FC_Font* font, FC_Target* dest, FC_Rect box, FC_Effect effect, const char* formatted_text, ...);
|
||||
|
||||
FC_Rect FC_DrawColumn(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawColumnAlign(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, FC_AlignEnum align, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawColumnScale(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, FC_Scale scale, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawColumnColor(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, SDL_Color color, const char* formatted_text, ...);
|
||||
FC_Rect FC_DrawColumnEffect(FC_Font* font, FC_Target* dest, float x, float y, Uint16 width, FC_Effect effect, const char* formatted_text, ...);
|
||||
|
||||
|
||||
// Getters
|
||||
|
||||
FC_FilterEnum FC_GetFilterMode(FC_Font* font);
|
||||
Uint16 FC_GetLineHeight(FC_Font* font);
|
||||
Uint16 FC_GetHeight(FC_Font* font, const char* formatted_text, ...);
|
||||
Uint16 FC_GetWidth(FC_Font* font, const char* formatted_text, ...);
|
||||
|
||||
// Returns a 1-pixel wide box in front of the character in the given position (index)
|
||||
FC_Rect FC_GetCharacterOffset(FC_Font* font, Uint16 position_index, int column_width, const char* formatted_text, ...);
|
||||
Uint16 FC_GetColumnHeight(FC_Font* font, Uint16 width, const char* formatted_text, ...);
|
||||
|
||||
int FC_GetAscent(FC_Font* font, const char* formatted_text, ...);
|
||||
int FC_GetDescent(FC_Font* font, const char* formatted_text, ...);
|
||||
int FC_GetBaseline(FC_Font* font);
|
||||
int FC_GetSpacing(FC_Font* font);
|
||||
int FC_GetLineSpacing(FC_Font* font);
|
||||
Uint16 FC_GetMaxWidth(FC_Font* font);
|
||||
SDL_Color FC_GetDefaultColor(FC_Font* font);
|
||||
|
||||
FC_Rect FC_GetBounds(FC_Font* font, float x, float y, FC_AlignEnum align, FC_Scale scale, const char* formatted_text, ...);
|
||||
|
||||
Uint8 FC_InRect(float x, float y, FC_Rect input_rect);
|
||||
// Given an offset (x,y) from the text draw position (the upper-left corner), returns the character position (UTF-8 index)
|
||||
Uint16 FC_GetPositionFromOffset(FC_Font* font, float x, float y, int column_width, FC_AlignEnum align, const char* formatted_text, ...);
|
||||
|
||||
// Returns the number of characters in the new wrapped text written into `result`.
|
||||
int FC_GetWrappedText(FC_Font* font, char* result, int max_result_size, Uint16 width, const char* formatted_text, ...);
|
||||
|
||||
// Setters
|
||||
|
||||
void FC_SetFilterMode(FC_Font* font, FC_FilterEnum filter);
|
||||
void FC_SetSpacing(FC_Font* font, int LetterSpacing);
|
||||
void FC_SetLineSpacing(FC_Font* font, int LineSpacing);
|
||||
void FC_SetDefaultColor(FC_Font* font, SDL_Color color);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -13,7 +13,7 @@ namespace GUI {
|
||||
void DrawRect(int x, int y, int w, int h, SDL_Color colour);
|
||||
void DrawText(int x, int y, int size, SDL_Color colour, const char *text);
|
||||
void DrawTextf(int x, int y, int size, SDL_Color colour, const char* text, ...);
|
||||
void GetTextDimensions(int size, const char *text, u32 *width, u32 *height);
|
||||
void GetTextDimensions(int size, const char *text, int *width, int *height);
|
||||
void DrawImage(SDL_Texture *texture, int x, int y);
|
||||
void Render(void);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,22 +1,24 @@
|
||||
#include <cstdio>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL_ttf.h>
|
||||
|
||||
#include "gui.hpp"
|
||||
#include "SDL_FontCache.h"
|
||||
|
||||
SDL_Texture *banner = nullptr, *drive = nullptr, *menu_icons[8] = { 0 };
|
||||
|
||||
namespace GUI {
|
||||
static SDL_Window *g_window = nullptr;
|
||||
static SDL_Renderer *g_renderer = nullptr;
|
||||
static FC_Font *g_font = nullptr;
|
||||
static TTF_Font *g_font = nullptr;
|
||||
|
||||
static void LoadImage(SDL_Texture **texture, const char *path) {
|
||||
SDL_Surface *image = nullptr;
|
||||
image = IMG_Load(path);
|
||||
|
||||
if (!image)
|
||||
if (!image) {
|
||||
SDL_Log("IMG_Load failed: %s\n", IMG_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGBA8888, 0);
|
||||
*texture = SDL_CreateTextureFromSurface(g_renderer, image);
|
||||
@ -24,19 +26,28 @@ namespace GUI {
|
||||
}
|
||||
|
||||
int Init(void) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
SDL_Log("SDL_Init failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_window = SDL_CreateWindow("SwitchIdent", 0, 0, 1280, 720, SDL_WINDOW_FULLSCREEN);
|
||||
if (g_window == nullptr)
|
||||
g_window = SDL_CreateWindow("SwitchIdent", 0, 0, 1920, 1080, SDL_WINDOW_FULLSCREEN);
|
||||
if (g_window == nullptr) {
|
||||
SDL_Log("SDL_CreateWindow failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_renderer = SDL_CreateRenderer(g_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
||||
g_renderer = SDL_CreateRenderer(g_window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (g_renderer == nullptr) {
|
||||
SDL_Log("SDL_CreateRenderer failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int flags = IMG_INIT_PNG;
|
||||
if ((IMG_Init(flags) & flags) != flags)
|
||||
if ((IMG_Init(flags) & flags) != flags) {
|
||||
SDL_Log("SDL_CreateWindow failed: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
GUI::LoadImage(&banner, "romfs:/banner.png");
|
||||
GUI::LoadImage(&drive, "romfs:/drive.png");
|
||||
@ -48,14 +59,14 @@ namespace GUI {
|
||||
GUI::LoadImage(&menu_icons[5], "romfs:/joycon.png");
|
||||
GUI::LoadImage(&menu_icons[6], "romfs:/misc.png");
|
||||
GUI::LoadImage(&menu_icons[7], "romfs:/exit.png");
|
||||
|
||||
g_font = FC_CreateFont();
|
||||
FC_LoadFont(g_font, g_renderer, "romfs:/Ubuntu-Regular.ttf", 25, FC_MakeColor(0, 0, 0, 255), TTF_STYLE_NORMAL);
|
||||
|
||||
TTF_Init();
|
||||
g_font = TTF_OpenFont("romfs:/Ubuntu-Regular.ttf", 36);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Exit(void) {
|
||||
FC_FreeFont(g_font);
|
||||
TTF_CloseFont(g_font);
|
||||
SDL_DestroyTexture(menu_icons[6]);
|
||||
SDL_DestroyTexture(menu_icons[5]);
|
||||
SDL_DestroyTexture(menu_icons[4]);
|
||||
@ -85,7 +96,16 @@ namespace GUI {
|
||||
}
|
||||
|
||||
void DrawText(int x, int y, int size, SDL_Color colour, const char *text) {
|
||||
FC_DrawColor(g_font, g_renderer, x, y, colour, text);
|
||||
SDL_Surface *surface = nullptr;
|
||||
SDL_Texture *texture = nullptr;
|
||||
|
||||
surface = TTF_RenderUTF8_Blended(g_font, text, colour);
|
||||
texture = SDL_CreateTextureFromSurface(g_renderer, surface);
|
||||
SDL_Rect position = {x, y, surface->w, surface->h};
|
||||
|
||||
SDL_RenderCopy(g_renderer, texture, nullptr, &position);
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
void DrawTextf(int x, int y, int size, SDL_Color colour, const char* text, ...) {
|
||||
@ -97,11 +117,8 @@ namespace GUI {
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void GetTextDimensions(int size, const char *text, u32 *width, u32 *height) {
|
||||
if (width != nullptr)
|
||||
*width = FC_GetWidth(g_font, text);
|
||||
if (height != nullptr)
|
||||
*height = FC_GetHeight(g_font, text);
|
||||
void GetTextDimensions(int size, const char *text, int *width, int *height) {
|
||||
TTF_SizeText(g_font, text, width, height);
|
||||
}
|
||||
|
||||
void DrawImage(SDL_Texture *texture, int x, int y) {
|
||||
|
111
source/menus.cpp
111
source/menus.cpp
@ -4,25 +4,24 @@
|
||||
#include "common.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "menus.hpp"
|
||||
#include "SDL_FontCache.h"
|
||||
|
||||
namespace Menus {
|
||||
// Globals
|
||||
static u32 g_item_height = 0;
|
||||
static int g_item_height = 0;
|
||||
static bool g_is_sd_inserted = false, g_is_gamecard_inserted = false;
|
||||
static HidsysUniquePadId g_unique_pad_ids[2] = {0};
|
||||
static PadState g_pad;
|
||||
static const int g_item_dist = 67;
|
||||
static const int g_start_x = 450;
|
||||
static const int g_start_y = 250;
|
||||
static const int g_start_y = 300;
|
||||
|
||||
// Colours
|
||||
static const SDL_Color bg_colour = FC_MakeColor(62, 62, 62, 255);
|
||||
static const SDL_Color status_bar_colour = FC_MakeColor(44, 44, 44, 255);
|
||||
static const SDL_Color menu_bar_colour = FC_MakeColor(52, 52, 52, 255);
|
||||
static const SDL_Color selector_colour = FC_MakeColor(223, 74, 22, 255);
|
||||
static const SDL_Color title_colour = FC_MakeColor(252, 252, 252, 255);
|
||||
static const SDL_Color descr_colour = FC_MakeColor(182, 182, 182, 255);
|
||||
static const SDL_Color bg_colour = { 62, 62, 62 };
|
||||
static const SDL_Color status_bar_colour = { 44, 44, 44 };
|
||||
static const SDL_Color menu_bar_colour = { 52, 52, 52 };
|
||||
static const SDL_Color selector_colour = { 223, 74, 22 };
|
||||
static const SDL_Color title_colour = { 252, 252, 252 };
|
||||
static const SDL_Color descr_colour = { 182, 182, 182 };
|
||||
|
||||
enum MenuState {
|
||||
STATE_KERNEL_INFO = 0,
|
||||
@ -37,14 +36,14 @@ namespace Menus {
|
||||
};
|
||||
|
||||
static void DrawItem(int x, int y, const char *title, const char *text) {
|
||||
u32 title_width = 0;
|
||||
int title_width = 0;
|
||||
GUI::GetTextDimensions(25, title, &title_width, nullptr);
|
||||
GUI::DrawText(x, y, 25, title_colour, title);
|
||||
GUI::DrawText(x + title_width + 20, y, 25, descr_colour, text);
|
||||
}
|
||||
|
||||
static void DrawItemf(int x, int y, const char *title, const char *text, ...) {
|
||||
u32 title_width = 0;
|
||||
int title_width = 0;
|
||||
GUI::GetTextDimensions(25, title, &title_width, nullptr);
|
||||
GUI::DrawText(x, y, 25, title_colour, title);
|
||||
|
||||
@ -58,36 +57,36 @@ namespace Menus {
|
||||
|
||||
void KernelInfo(void) {
|
||||
SetSysFirmwareVersion ver = SwitchIdent::GetFirmwareVersion();
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "Firmware version:",
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "Firmware version:",
|
||||
"%u.%u.%u-%u%u", ver.major, ver.minor, ver.micro, ver.revision_major, ver.revision_minor);
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 100, "Hardware:", SwitchIdent::GetHardwareType());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 150, "Unit:", SwitchIdent::GetUnit());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 200, "Serial:", SwitchIdent::GetSerialNumber().number);
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 250, "DRAM ID:", SwitchIdent::GetDramDesc());
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Device ID:", "%llu", SwitchIdent::GetDeviceID());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "Hardware:", SwitchIdent::GetHardwareType());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 180, "Unit:", SwitchIdent::GetUnit());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 240, "Serial:", SwitchIdent::GetSerialNumber().number);
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "DRAM ID:", SwitchIdent::GetDramDesc());
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 360, "Device ID:", "%llu", SwitchIdent::GetDeviceID());
|
||||
}
|
||||
|
||||
void SystemInfo(void) {
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "Region:", SwitchIdent::GetRegion());
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 100, "CPU clock:", "%lu MHz", SwitchIdent::GetClock(PcvModule_CpuBus));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 150, "GPU clock:", "%lu MHz", SwitchIdent::GetClock(PcvModule_GPU));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 200, "EMC clock:", "%lu MHz", SwitchIdent::GetClock(PcvModule_EMC));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 250, "Wireless LAN:",
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "Region:", SwitchIdent::GetRegion());
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "CPU clock:", "%lu MHz", SwitchIdent::GetClock(PcvModule_CpuBus));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 180, "GPU clock:", "%lu MHz", SwitchIdent::GetClock(PcvModule_GPU));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 240, "EMC clock:", "%lu MHz", SwitchIdent::GetClock(PcvModule_EMC));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Wireless LAN:",
|
||||
"%s (RSSI: %d) (Quality: %lu)", SwitchIdent::GetWirelessLanEnableFlag()? "Enabled" : "Disabled", SwitchIdent::GetWlanRSSI(), SwitchIdent::GetWlanQuality(SwitchIdent::GetWlanRSSI()));
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Bluetooth:", SwitchIdent::GetBluetoothEnableFlag()? "Enabled" : "Disabled");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 350, "NFC:", SwitchIdent::GetNfcEnableFlag()? "Enabled" : "Disabled");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 360, "Bluetooth:", SwitchIdent::GetBluetoothEnableFlag()? "Enabled" : "Disabled");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 420, "NFC:", SwitchIdent::GetNfcEnableFlag()? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
void BatteryInfo(void) {
|
||||
s32 int_temp = SwitchIdent::GetBatteryTemperature(TsLocation_Internal);
|
||||
s32 ext_temp = SwitchIdent::GetBatteryTemperature(TsLocation_External);
|
||||
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "Percentage:", "%lu %% (%s)", SwitchIdent::GetBatteryPercentage(), SwitchIdent::IsCharging()? "charging" : "not charging");
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 100, "Age percentage:", "%.2f %%", SwitchIdent::GetBatteryAgePercentage());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 150, "Voltage state:", SwitchIdent::GetVoltageState());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 200, "Lot number:", SwitchIdent::GetBatteryLot().lot);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 250, "Internal temperature:", "%d °C (%d °F)", int_temp, ((int_temp * 9/5) + 32));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "External temperature:", "%d °C (%d °F)", ext_temp, ((ext_temp * 9/5) + 32));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "Percentage:", "%lu %% (%s)", SwitchIdent::GetBatteryPercentage(), SwitchIdent::IsCharging()? "charging" : "not charging");
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "Age percentage:", "%.2f %%", SwitchIdent::GetBatteryAgePercentage());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 180, "Voltage state:", SwitchIdent::GetVoltageState());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 240, "Lot number:", SwitchIdent::GetBatteryLot().lot);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Internal temperature:", "%d °C (%d °F)", int_temp, ((int_temp * 9/5) + 32));
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 360, "External temperature:", "%d °C (%d °F)", ext_temp, ((ext_temp * 9/5) + 32));
|
||||
}
|
||||
|
||||
void ChargerInfo(void) {
|
||||
@ -107,14 +106,14 @@ namespace Menus {
|
||||
BatteryChargeInfoFields batteryChargeInfoFields = { 0 };
|
||||
SwitchIdent::GetBatteryChargeInfoFields(&batteryChargeInfoFields);
|
||||
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "Current limit:", "(In: %d mA) (Out: %d mA)", batteryChargeInfoFields.in_curr_limit, batteryChargeInfoFields.out_curr_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 100, "Battery charging current limit:", "%d mA", batteryChargeInfoFields.charge_curr_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 150, "Battery charging voltage limit:", "%d mV", batteryChargeInfoFields.charge_volt_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 200, "Capacity:", "%d pcm (Age: %d pcm)", batteryChargeInfoFields.capacity, batteryChargeInfoFields.battery_age);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 250, "Voltage average:", "%d mV", batteryChargeInfoFields.voltage_avg);
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Charger:", chargers[batteryChargeInfoFields.charger]);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 350, "Charger voltage limit:", "%d mV", batteryChargeInfoFields.charger_volt_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 400, "Charger current limit:", "%d mA", batteryChargeInfoFields.charger_curr_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "Current limit:", "(In: %d mA) (Out: %d mA)", batteryChargeInfoFields.in_curr_limit, batteryChargeInfoFields.out_curr_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "Battery charging current limit:", "%d mA", batteryChargeInfoFields.charge_curr_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 180, "Battery charging voltage limit:", "%d mV", batteryChargeInfoFields.charge_volt_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 240, "Capacity:", "%d pcm (Age: %d pcm)", batteryChargeInfoFields.capacity, batteryChargeInfoFields.battery_age);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Voltage average:", "%d mV", batteryChargeInfoFields.voltage_avg);
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 360, "Charger:", chargers[batteryChargeInfoFields.charger]);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 420, "Charger voltage limit:", "%d mV", batteryChargeInfoFields.charger_volt_limit);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 480, "Charger current limit:", "%d mA", batteryChargeInfoFields.charger_curr_limit);
|
||||
}
|
||||
|
||||
void StorageInfo(void) {
|
||||
@ -177,13 +176,13 @@ namespace Menus {
|
||||
|
||||
void JoyconInfo(void) {
|
||||
// TODO: account for HidNpadIdType_Other;
|
||||
// Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "JC fw:", "%llu", SwitchIdent::GetJoyconFirmwareVersion(g_unique_pad_ids[0]));
|
||||
// Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "JC fw:", "%llu", SwitchIdent::GetJoyconFirmwareVersion(g_unique_pad_ids[0]));
|
||||
|
||||
HidPowerInfo info_left = SwitchIdent::GetJoyconPowerInfoL(padIsHandheld(&g_pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1);
|
||||
HidPowerInfo info_right = SwitchIdent::GetJoyconPowerInfoR(padIsHandheld(&g_pad) ? HidNpadIdType_Handheld : HidNpadIdType_No1);
|
||||
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "Left Joycon battery:", "%lu %% (%s)", (info_left.battery_level * 25), info_left.is_charging? "charging" : "not charging");
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 100, "Right Joycon battery:", "%lu %% (%s)", (info_right.battery_level * 25), info_right.is_charging? "charging" : "not charging");
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "Left Joycon battery:", "%lu %% (%s)", (info_left.battery_level * 25), info_left.is_charging? "charging" : "not charging");
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "Right Joycon battery:", "%lu %% (%s)", (info_right.battery_level * 25), info_right.is_charging? "charging" : "not charging");
|
||||
}
|
||||
|
||||
void MiscInfo(void) {
|
||||
@ -193,25 +192,25 @@ namespace Menus {
|
||||
SetCalBdAddress bd_addr = SwitchIdent::GetBluetoothBdAddress();
|
||||
SetCalMacAddress mac_addr = SwitchIdent::GetWirelessLanMacAddress();
|
||||
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 50, "IP:", R_SUCCEEDED(ret)? hostname : nullptr);
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 100, "State:", SwitchIdent::GetOperationMode());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 150, "Automatic update:", SwitchIdent::GetAutoUpdateEnableFlag()? "Enabled" : "Disabled");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 200, "Console information upload:", SwitchIdent::GetConsoleInformationUploadFlag()? "Enabled" : "Disabled");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 250, "SD card status:", g_is_sd_inserted? "Inserted" : "Not inserted");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "Game card status:", g_is_gamecard_inserted? "Inserted" : "Not inserted");
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 350, "BT address:",
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 60, "IP:", R_SUCCEEDED(ret)? hostname : nullptr);
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 120, "State:", SwitchIdent::GetOperationMode());
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 180, "Automatic update:", SwitchIdent::GetAutoUpdateEnableFlag()? "Enabled" : "Disabled");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 240, "Console information upload:", SwitchIdent::GetConsoleInformationUploadFlag()? "Enabled" : "Disabled");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 300, "SD card status:", g_is_sd_inserted? "Inserted" : "Not inserted");
|
||||
Menus::DrawItem(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 360, "Game card status:", g_is_gamecard_inserted? "Inserted" : "Not inserted");
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 420, "BT address:",
|
||||
"%02X:%02X:%02X:%02X:%02X:%02X", bd_addr.bd_addr[0], bd_addr.bd_addr[1], bd_addr.bd_addr[2], bd_addr.bd_addr[3], bd_addr.bd_addr[4], bd_addr.bd_addr[5]);
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 400, "WLAN address:",
|
||||
Menus::DrawItemf(g_start_x, g_start_y + ((g_item_dist - g_item_height) / 2) + 480, "WLAN address:",
|
||||
"%02X:%02X:%02X:%02X:%02X:%02X", mac_addr.addr[0], mac_addr.addr[1], mac_addr.addr[2], mac_addr.addr[3], mac_addr.addr[4], mac_addr.addr[5]);
|
||||
}
|
||||
|
||||
void Main(void) {
|
||||
u32 title_height = 0;
|
||||
int title_height = 0;
|
||||
GUI::GetTextDimensions(25, "SwitchIdent", nullptr, &title_height);
|
||||
GUI::GetTextDimensions(25, "Item", nullptr, &g_item_height);
|
||||
|
||||
int banner_width = 200;
|
||||
int selection = STATE_KERNEL_INFO;
|
||||
int selection = STATE_EXIT;
|
||||
Result ret = 0;
|
||||
|
||||
FsDeviceOperator fsDeviceOperator;
|
||||
@ -250,17 +249,17 @@ namespace Menus {
|
||||
|
||||
while(appletMainLoop()) {
|
||||
GUI::ClearScreen(bg_colour);
|
||||
GUI::DrawRect(0, 0, 1280, 50, status_bar_colour);
|
||||
GUI::DrawRect(0, 50, 400, 670, menu_bar_colour);
|
||||
GUI::DrawRect(0, 0, 1920, 50, status_bar_colour);
|
||||
GUI::DrawRect(0, 50, 400, 1030, menu_bar_colour);
|
||||
|
||||
GUI::DrawTextf(30, ((50 - title_height) / 2), 25, title_colour, "SwitchIdent v%d.%d", VERSION_MAJOR, VERSION_MINOR);
|
||||
GUI::DrawImage(banner, 400 + ((880 - (banner_width)) / 2), 80);
|
||||
GUI::DrawTextf(30, ((50 - title_height) / 2), 25, title_colour, "SwitchIdent Test v%d.%d", VERSION_MAJOR, VERSION_MINOR);
|
||||
GUI::DrawImage(banner, 400 + ((1320 - (banner_width)) / 2), 80);
|
||||
|
||||
GUI::DrawRect(0, 50 + (g_item_dist * selection), 400, g_item_dist, selector_colour);
|
||||
|
||||
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||
GUI::DrawImage(menu_icons[i], 20, 52 + ((g_item_dist - g_item_height) / 2) + (g_item_dist * i));
|
||||
GUI::DrawText(75, 50 + ((g_item_dist - g_item_height) / 2) + (g_item_dist * i), 25, title_colour, items[i]);
|
||||
GUI::DrawText(75, 45 + ((g_item_dist - g_item_height) / 2) + (g_item_dist * i), 25, title_colour, items[i]);
|
||||
}
|
||||
|
||||
padUpdate(&g_pad);
|
||||
|
Loading…
Reference in New Issue
Block a user