mirror of
https://github.com/joel16/SwitchIdent.git
synced 2024-11-26 21:20:26 +00:00
GPU acceleration + fix builds + more
- Displays Wlan state and RSSI signals - Properly display voltage states.
This commit is contained in:
parent
cb0199cf7d
commit
552d23c940
102
common/power.c
102
common/power.c
@ -1,44 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#include "power.h"
|
||||
|
||||
static Result psmGetChargerType(Service *srv, u32 *out)
|
||||
{
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 1;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if(R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 voltage;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = resp->voltage;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result psmIsBatteryChargingEnabled(Service *srv, bool *out)
|
||||
{
|
||||
IpcCommand c;
|
||||
@ -235,15 +200,36 @@ u32 SwitchIdent_GetBatteryPercent(void)
|
||||
return out;
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetChargerType(Service *srv)
|
||||
char *SwitchIdent_GetChargerType(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
u32 out = 0;
|
||||
ChargerType charger_type;
|
||||
|
||||
if (R_FAILED(ret = psmGetChargerType(srv, &out)))
|
||||
return -1;
|
||||
if (R_FAILED(ret = psmGetChargerType(&charger_type)))
|
||||
return NULL;
|
||||
|
||||
return out;
|
||||
if (charger_type == ChargerType_Charger)
|
||||
return "Official charger or dock";
|
||||
else if (charger_type == ChargerType_Usb)
|
||||
return "USB-C charger";
|
||||
else
|
||||
return "No charger connected";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool SwitchIdent_IsCharging(void)
|
||||
{
|
||||
Result ret = 0;
|
||||
ChargerType charger_type;
|
||||
|
||||
if (R_FAILED(ret = psmGetChargerType(&charger_type)))
|
||||
return false;
|
||||
|
||||
if ((charger_type == ChargerType_Charger) || (charger_type == ChargerType_Usb))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SwitchIdent_IsChargingEnabled(Service *srv)
|
||||
@ -257,15 +243,39 @@ bool SwitchIdent_IsChargingEnabled(Service *srv)
|
||||
return out;
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetVoltage(Service *srv)
|
||||
char *SwitchIdent_GetVoltageState(Service *srv)
|
||||
{
|
||||
Result ret = 0;
|
||||
u32 out = 0;
|
||||
|
||||
if (R_FAILED(ret = psmGetBatteryVoltageState(srv, &out)))
|
||||
return -1;
|
||||
char *states[]=
|
||||
{
|
||||
"max77620_sd0",
|
||||
"max77620_sd1",
|
||||
"max77620_sd2",
|
||||
"max77620_sd3",
|
||||
"max77620_ldo0 -> 1.2 V",
|
||||
"max77620_ldo1",
|
||||
"max77620_ldo2 -> 3.3 V - 1.8 V",
|
||||
"max77620_ldo3",
|
||||
"max77620_ldo4 -> 0.85 V",
|
||||
"max77620_ldo5",
|
||||
"max77620_ldo6 -> 2.9 V",
|
||||
"max77620_ldo7",
|
||||
"max77620_ldo8 -> 1.05 V",
|
||||
"max77621_cpu",
|
||||
"max77621_gpu",
|
||||
"Unknown"
|
||||
};
|
||||
|
||||
return out;
|
||||
if (R_SUCCEEDED(ret = psmGetBatteryVoltageState(srv, &out)))
|
||||
{
|
||||
if (out < 15)
|
||||
return states[out];
|
||||
}
|
||||
|
||||
printf("psmGetBatteryVoltageState() failed: 0x%x.\n\n", ret);
|
||||
return states[15];
|
||||
}
|
||||
|
||||
u64 SwitchIdent_GetRawBatteryChargePercentage(Service *srv)
|
||||
|
@ -2,9 +2,10 @@
|
||||
#define _SWITCHIDENT_POWER_H_
|
||||
|
||||
u32 SwitchIdent_GetBatteryPercent(void);
|
||||
u32 SwitchIdent_GetChargerType(Service *srv);
|
||||
char *SwitchIdent_GetChargerType(void);
|
||||
bool SwitchIdent_IsCharging(void);
|
||||
bool SwitchIdent_IsChargingEnabled(Service *srv);
|
||||
u32 SwitchIdent_GetVoltage(Service *srv);
|
||||
char *SwitchIdent_GetVoltageState(Service *srv);
|
||||
u64 SwitchIdent_GetRawBatteryChargePercentage(Service *srv);
|
||||
bool SwitchIdent_IsEnoughPowerSupplied(Service *srv);
|
||||
u64 SwitchIdent_GetBatteryAgePercent(Service *srv);
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
#include "setsys.h"
|
||||
|
||||
static Result GetFirmwareVersion(Service *srv, SetSysFirmwareVersion *ver){
|
||||
static Result GetFirmwareVersion(Service *srv, SetSysFirmwareVersion *ver)
|
||||
{
|
||||
char buffer[0x100];
|
||||
size_t size = sizeof(buffer);
|
||||
memset(buffer, 0, size);
|
||||
@ -15,7 +16,7 @@ static Result GetFirmwareVersion(Service *srv, SetSysFirmwareVersion *ver){
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} * raw;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
@ -42,7 +43,8 @@ static Result GetFirmwareVersion(Service *srv, SetSysFirmwareVersion *ver){
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result GetFirmwareVersion2(Service *srv, SetSysFirmwareVersion *ver){
|
||||
static Result GetFirmwareVersion2(Service *srv, SetSysFirmwareVersion *ver)
|
||||
{
|
||||
char buffer[0x100];
|
||||
size_t size = sizeof(buffer);
|
||||
memset(buffer, 0, size);
|
||||
@ -54,7 +56,7 @@ static Result GetFirmwareVersion2(Service *srv, SetSysFirmwareVersion *ver){
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} * raw;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
@ -86,4 +88,80 @@ Result setsysGetFirmwareVersion(Service *srv, SetSysFirmwareVersion *ver)
|
||||
if (kernelAbove200())
|
||||
return GetFirmwareVersion2(srv, ver);
|
||||
return GetFirmwareVersion(srv, ver);
|
||||
}
|
||||
}
|
||||
|
||||
Result setcalGetBluetoothBdAddress(Service *srv, char *address)
|
||||
{
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
if (address) memset(address, 0, 0x7);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 0;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
char address[0x6];
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && address)
|
||||
memcpy(address, resp->address, 0x6);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result setcalGetWirelessLanMacAddress(Service *srv, char *address)
|
||||
{
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
if (address) memset(address, 0, 0x7);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 6;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
char address[0x6];
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc) && address)
|
||||
memcpy(address, resp->address, 0x6);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -10,5 +10,7 @@ typedef struct {
|
||||
} SetSysFirmwareVersion;
|
||||
|
||||
Result setsysGetFirmwareVersion(Service *srv, SetSysFirmwareVersion *ver);
|
||||
Result setcalGetBluetoothBdAddress(Service *srv, char *address);
|
||||
Result setcalGetWirelessLanMacAddress(Service *srv, char *address);
|
||||
|
||||
#endif
|
@ -4,6 +4,7 @@
|
||||
#include <switch.h>
|
||||
|
||||
#include "misc.h"
|
||||
#include "setsys.h"
|
||||
#include "system.h"
|
||||
|
||||
char *SwitchIdent_GetLanguage(void)
|
||||
@ -12,7 +13,7 @@ char *SwitchIdent_GetLanguage(void)
|
||||
u64 language = 0;
|
||||
|
||||
if (R_FAILED(ret = setGetSystemLanguage(&language)))
|
||||
printf("setGetSystemLanguage(language) failed: 0x%x.\n\n", ret);
|
||||
printf("setGetSystemLanguage() failed: 0x%x.\n\n", ret);
|
||||
|
||||
return strupr((char*)&language);
|
||||
}
|
||||
@ -38,7 +39,7 @@ char *SwitchIdent_GetRegion(void)
|
||||
return regions[regionCode];
|
||||
}
|
||||
|
||||
printf("setGetRegionCode(regionCode) failed: 0x%x.\n\n", ret);
|
||||
printf("setGetRegionCode() failed: 0x%x.\n\n", ret);
|
||||
return regions[4];
|
||||
}
|
||||
|
||||
@ -146,3 +147,31 @@ u32 SwitchIdent_GetGPUClock(void)
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
char *SwitchIdent_GetBluetoothBdAddress(Service *srv)
|
||||
{
|
||||
Result ret = 0;
|
||||
static char bd_addr[0x7];
|
||||
|
||||
if (R_FAILED(ret = setcalGetBluetoothBdAddress(srv, bd_addr)))
|
||||
{
|
||||
printf("setcalGetBluetoothBdAddress() failed: 0x%x.\n\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return bd_addr;
|
||||
}
|
||||
|
||||
char *SwitchIdent_GetWirelessLanMacAddress(Service *srv)
|
||||
{
|
||||
Result ret = 0;
|
||||
static char mac_addr[0x7];
|
||||
|
||||
if (R_FAILED(ret = setcalGetWirelessLanMacAddress(srv, mac_addr)))
|
||||
{
|
||||
printf("setcalGetWirelessLanMacAddress() failed: 0x%x.\n\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mac_addr;
|
||||
}
|
||||
|
@ -2,8 +2,10 @@
|
||||
#define _SWITCHIDENT_SYSTEM_H_
|
||||
|
||||
char *SwitchIdent_GetLanguage(void);
|
||||
char *SwitchIdent_GetRegion(void); // Not sure about this yet.
|
||||
char *SwitchIdent_GetRegion(void);
|
||||
u32 SwitchIdent_GetCPUClock(void);
|
||||
u32 SwitchIdent_GetGPUClock(void);
|
||||
char *SwitchIdent_GetBluetoothBdAddress(Service *srv);
|
||||
char *SwitchIdent_GetWirelessLanMacAddress(Service *srv);
|
||||
|
||||
#endif
|
||||
|
84
gui/Makefile
84
gui/Makefile
@ -48,21 +48,24 @@ APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
|
||||
|
||||
CFLAGS := -g -Werror -O2 -ffunction-sections `sdl2-config --cflags` `freetype-config --cflags` \
|
||||
-DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) \
|
||||
$(ARCH) $(DEFINES)
|
||||
CFLAGS := -g -O3 -ffunction-sections -Wall -Wno-write-strings `freetype-config --cflags` `sdl2-config --cflags` \
|
||||
-DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_MICRO=$(VERSION_MICRO) \
|
||||
-DAPP_TITLE="\"$(APP_TITLE)\"" \
|
||||
-DGITVERSION="\"${GITVERSION}\"" \
|
||||
$(ARCH) $(DEFINES)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DSWITCH
|
||||
CFLAGS += $(INCLUDE) -D__SWITCH__
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) -L$(PWD)/$(BUILD)
|
||||
|
||||
LIBS := -lSDL2_ttf -lSDL2_gfx -lSDL2_image \
|
||||
-lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx
|
||||
LIBS := -lSDL2_ttf -lSDL2_image -lSDL2 \
|
||||
-lpng -lz -ljpeg \
|
||||
-lfreetype -lbz2 -lEGL -lglapi -ldrm_nouveau -lnx \
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
@ -78,41 +81,34 @@ LIBDIRS := $(PORTLIBS) $(LIBNX)
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
||||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
|
||||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||
|
||||
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
|
||||
|
||||
@ -169,24 +165,26 @@ DEPENDS := $(OFILES:.o=.d)
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
all : $(OUTPUT).pfs0 $(OUTPUT).nro
|
||||
all : $(OUTPUT).pfs0 $(OUTPUT).nro
|
||||
|
||||
$(OUTPUT).pfs0 : $(OUTPUT).nso
|
||||
$(OUTPUT).pfs0 : $(OUTPUT).nso
|
||||
|
||||
$(OUTPUT).nso : $(OUTPUT).elf
|
||||
$(OUTPUT).nso : $(OUTPUT).elf
|
||||
|
||||
ifeq ($(strip $(NO_NACP)),)
|
||||
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
|
||||
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
|
||||
else
|
||||
$(OUTPUT).nro : $(OUTPUT).elf
|
||||
$(OUTPUT).nro : $(OUTPUT).elf
|
||||
endif
|
||||
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
$(OFILES_SRC) : $(HFILES_BIN)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
%.bin.o %_bin.h : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
@ -195,4 +193,4 @@ $(OUTPUT).elf : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
||||
#---------------------------------------------------------------------------------------
|
||||
|
268
gui/include/SDL_FontCache.h
Normal file
268
gui/include/SDL_FontCache.h
Normal file
@ -0,0 +1,268 @@
|
||||
/*
|
||||
SDL_FontCache v0.9.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) 2016 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"
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Let's pretend this exists...
|
||||
#define TTF_STYLE_OUTLINE 16
|
||||
|
||||
#define FC_Rect SDL_Rect
|
||||
#define FC_Target SDL_Renderer
|
||||
#define FC_Image SDL_Texture
|
||||
#define FC_Log SDL_Log
|
||||
|
||||
// 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);
|
||||
|
||||
Uint8 FC_LoadFontFromTTF(FC_Font* font, SDL_Renderer* renderer, TTF_Font* ttf, TTF_Font* ext, SDL_Color color);
|
||||
|
||||
Uint8 FC_LoadFont_RW(FC_Font* font, SDL_Renderer* renderer, SDL_RWops* file_rwops_ttf, SDL_RWops* file_rwops_ext, Uint8 own_rwops, Uint32 pointSize, SDL_Color color, int style);
|
||||
|
||||
void FC_ClearFont(FC_Font* font);
|
||||
|
||||
void FC_FreeFont(FC_Font* font);
|
||||
|
||||
// Built-in loading strings
|
||||
|
||||
char* FC_GetStringASCII(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);
|
||||
|
||||
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);
|
||||
|
||||
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, ...);
|
||||
|
||||
// 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
|
@ -1,36 +1,29 @@
|
||||
#ifndef _SWITCHIDENT_SDL_HELPER_H_
|
||||
#define _SWITCHIDENT_SDL_HELPER_H_
|
||||
#ifndef NX_SHELL_SDL_HELPER_H
|
||||
#define NX_SHELL_SDL_HELPER_H
|
||||
|
||||
#include <SDL.h>
|
||||
#include <switch.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include "SDL_FontCache.h"
|
||||
|
||||
static inline SDL_Color SDL_MakeColour(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_Color colour = {r, g, b, a};
|
||||
return colour;
|
||||
}
|
||||
|
||||
#define BACKGROUND_COLOUR SDL_MakeColour(242, 241, 240, 255)
|
||||
#define STATUS_BAR_COLOUR SDL_MakeColour(69, 67, 62, 255)
|
||||
#define MENU_BAR_COLOUR SDL_MakeColour(255, 255, 255, 255)
|
||||
#define ITEM_COLOUR SDL_MakeColour(0, 0, 0, 255)
|
||||
#define BACKGROUND_COLOUR FC_MakeColor(242, 241, 240, 255)
|
||||
#define STATUS_BAR_COLOUR FC_MakeColor(69, 67, 62, 255)
|
||||
#define MENU_BAR_COLOUR FC_MakeColor(255, 255, 255, 255)
|
||||
#define ITEM_COLOUR FC_MakeColor(0, 0, 0, 255)
|
||||
#define ITEM_SELECTED_COLOUR MENU_BAR_COLOUR
|
||||
#define MENU_SELECTOR_COLOUR SDL_MakeColour(239, 118, 69, 255)
|
||||
#define MENU_INFO_TITLE_COLOUR SDL_MakeColour(144, 137, 129, 255)
|
||||
#define MENU_INFO_DESC_COLOUR SDL_MakeColour(51, 51, 51, 255)
|
||||
#define MENU_SELECTOR_COLOUR FC_MakeColor(239, 118, 69, 255)
|
||||
#define MENU_INFO_TITLE_COLOUR FC_MakeColor(144, 137, 129, 255)
|
||||
#define MENU_INFO_DESC_COLOUR FC_MakeColor(51, 51, 51, 255)
|
||||
|
||||
SDL_Window *WINDOW;
|
||||
SDL_Surface *WINDOW_SURFACE;
|
||||
SDL_Renderer *RENDERER;
|
||||
SDL_Texture *banner, *drive;
|
||||
TTF_Font *Ubuntu_R_large, *Ubuntu_R;
|
||||
Result SDL_HelperInit(void);
|
||||
void SDL_HelperTerm(void);
|
||||
void SDL_ClearScreen(SDL_Color colour);
|
||||
void SDL_DrawRect(int x, int y, int w, int h, SDL_Color colour);
|
||||
void SDL_DrawText(int x, int y, int size, SDL_Color colour, const char *text);
|
||||
void SDL_DrawTextf(int x, int y, int size, SDL_Color colour, const char* text, ...);
|
||||
void SDL_GetTextDimensions(int size, const char *text, u32 *width, u32 *height);
|
||||
void SDL_DrawBanner(int x, int y);
|
||||
void SDL_DrawDriveIcon(int x, int y);
|
||||
void SDL_Renderdisplay(void);
|
||||
|
||||
void SDL_ClearScreen(SDL_Renderer *renderer, SDL_Color colour);
|
||||
void SDL_DrawRect(SDL_Renderer *renderer, int x, int y, int w, int h, SDL_Color colour);
|
||||
void SDL_DrawText(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char *text);
|
||||
void SDL_DrawTextf(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char* text, ...);
|
||||
void SDL_LoadImage(SDL_Renderer *renderer, SDL_Texture **texture, char *path);
|
||||
void SDL_DrawImage(SDL_Renderer *renderer, SDL_Texture *texture, int x, int y);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
2341
gui/source/SDL_FontCache.c
Normal file
2341
gui/source/SDL_FontCache.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,62 +1,114 @@
|
||||
#include "SDL_helper.h"
|
||||
|
||||
void SDL_ClearScreen(SDL_Renderer *renderer, SDL_Color colour)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, colour.r, colour.g, colour.b, colour.a);
|
||||
SDL_RenderClear(renderer);
|
||||
static SDL_Window *WINDOW;
|
||||
static SDL_Renderer *RENDERER;
|
||||
static FC_Font *font;
|
||||
static PlFontData fontData, fontExtData;
|
||||
static SDL_Texture *banner, *drive;
|
||||
|
||||
static FC_Font *GetFont(int size) {
|
||||
return font;
|
||||
}
|
||||
|
||||
void SDL_DrawRect(SDL_Renderer *renderer, int x, int y, int w, int h, SDL_Color colour)
|
||||
{
|
||||
static void SDL_LoadImage(SDL_Texture **texture, char *path) {
|
||||
SDL_Surface *loaded_surface = NULL;
|
||||
loaded_surface = IMG_Load(path);
|
||||
|
||||
if (loaded_surface) {
|
||||
Uint32 colorkey = SDL_MapRGB(loaded_surface->format, 0, 0, 0);
|
||||
SDL_SetColorKey(loaded_surface, SDL_TRUE, colorkey);
|
||||
*texture = SDL_CreateTextureFromSurface(RENDERER, loaded_surface);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(loaded_surface);
|
||||
}
|
||||
|
||||
Result SDL_HelperInit(void) {
|
||||
Result ret = 0;
|
||||
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
WINDOW = SDL_CreateWindow("SwitchIdent", 0, 0, 1280, 720, SDL_WINDOW_FULLSCREEN);
|
||||
RENDERER = SDL_CreateRenderer(WINDOW, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
SDL_SetRenderDrawBlendMode(RENDERER, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
||||
|
||||
IMG_Init(IMG_INIT_PNG);
|
||||
|
||||
SDL_LoadImage(&banner, "romfs:/banner.png");
|
||||
SDL_LoadImage(&drive, "romfs:/drive.png");
|
||||
|
||||
if (R_FAILED(ret = plGetSharedFontByType(&fontData, PlSharedFontType_Standard)))
|
||||
return ret;
|
||||
|
||||
if (R_FAILED(ret = plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt)))
|
||||
return ret;
|
||||
|
||||
font = FC_CreateFont();
|
||||
FC_LoadFont_RW(font, RENDERER, SDL_RWFromMem((void*)fontData.address, fontData.size), SDL_RWFromMem((void*)fontExtData.address, fontExtData.size), 1, 25, FC_MakeColor(0, 0, 0, 255), TTF_STYLE_NORMAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDL_HelperTerm(void) {
|
||||
FC_FreeFont(font);
|
||||
TTF_Quit();
|
||||
|
||||
IMG_Quit();
|
||||
|
||||
SDL_DestroyRenderer(RENDERER);
|
||||
SDL_DestroyWindow(WINDOW);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void SDL_ClearScreen(SDL_Color colour) {
|
||||
SDL_SetRenderDrawColor(RENDERER, colour.r, colour.g, colour.b, colour.a);
|
||||
SDL_RenderClear(RENDERER);
|
||||
}
|
||||
|
||||
void SDL_DrawRect(int x, int y, int w, int h, SDL_Color colour) {
|
||||
SDL_Rect rect;
|
||||
rect.x = x; rect.y = y; rect.w = w; rect.h = h;
|
||||
SDL_SetRenderDrawColor(RENDERER, colour.r, colour.g, colour.b, colour.a);
|
||||
SDL_RenderFillRect(RENDERER, &rect);
|
||||
}
|
||||
|
||||
void SDL_DrawText(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char *text)
|
||||
{
|
||||
SDL_Surface *surface = TTF_RenderText_Blended_Wrapped(font, text, colour, 1280);
|
||||
SDL_SetSurfaceAlphaMod(surface, colour.a);
|
||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
SDL_Rect position;
|
||||
position.x = x; position.y = y;
|
||||
SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h);
|
||||
SDL_RenderCopy(renderer, texture, NULL, &position);
|
||||
SDL_DestroyTexture(texture);
|
||||
void SDL_DrawText(int x, int y, int size, SDL_Color colour, const char *text) {
|
||||
FC_DrawColor(GetFont(size), RENDERER, x, y, colour, text);
|
||||
}
|
||||
|
||||
void SDL_DrawTextf(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char* text, ...)
|
||||
{
|
||||
void SDL_DrawTextf(int x, int y, int size, SDL_Color colour, const char* text, ...) {
|
||||
char buffer[256];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsnprintf(buffer, 256, text, args);
|
||||
SDL_DrawText(renderer, font, x, y, colour, buffer);
|
||||
SDL_DrawText(x, y, size, colour, buffer);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void SDL_LoadImage(SDL_Renderer *renderer, SDL_Texture **texture, char *path)
|
||||
{
|
||||
SDL_Surface *loaded_surface = NULL;
|
||||
loaded_surface = IMG_Load(path);
|
||||
void SDL_GetTextDimensions(int size, const char *text, u32 *width, u32 *height) {
|
||||
FC_Font *font = GetFont(size);
|
||||
|
||||
if (loaded_surface)
|
||||
{
|
||||
Uint32 colorkey = SDL_MapRGB(loaded_surface->format, 0, 0, 0);
|
||||
SDL_SetColorKey(loaded_surface, SDL_TRUE, colorkey);
|
||||
*texture = SDL_CreateTextureFromSurface(renderer, loaded_surface);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(loaded_surface);
|
||||
if (width != NULL)
|
||||
*width = FC_GetWidth(font, text);
|
||||
if (height != NULL)
|
||||
*height = FC_GetHeight(font, text);
|
||||
}
|
||||
|
||||
void SDL_DrawImage(SDL_Renderer *renderer, SDL_Texture *texture, int x, int y)
|
||||
{
|
||||
static void SDL_DrawImage(SDL_Texture *texture, int x, int y) {
|
||||
SDL_Rect position;
|
||||
position.x = x; position.y = y;
|
||||
SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h);
|
||||
SDL_RenderCopy(renderer, texture, NULL, &position);
|
||||
}
|
||||
SDL_RenderCopy(RENDERER, texture, NULL, &position);
|
||||
}
|
||||
|
||||
void SDL_DrawBanner(int x, int y) {
|
||||
SDL_DrawImage(banner, x, y);
|
||||
}
|
||||
|
||||
void SDL_DrawDriveIcon(int x, int y) {
|
||||
SDL_DrawImage(drive, x, y);
|
||||
}
|
||||
|
||||
void SDL_Renderdisplay(void) {
|
||||
SDL_RenderPresent(RENDERER);
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
#include "menus.h"
|
||||
#include "SDL_helper.h"
|
||||
|
||||
static void Term_Services(void)
|
||||
{
|
||||
static void Term_Services(void) {
|
||||
psmExit();
|
||||
nsExit();
|
||||
apmExit();
|
||||
@ -14,52 +13,23 @@ static void Term_Services(void)
|
||||
splExit();
|
||||
setsysExit();
|
||||
setExit();
|
||||
|
||||
TTF_CloseFont(Ubuntu_R_large);
|
||||
TTF_CloseFont(Ubuntu_R);
|
||||
TTF_Quit();
|
||||
|
||||
SDL_DestroyTexture(drive);
|
||||
SDL_DestroyTexture(banner);
|
||||
|
||||
IMG_Quit();
|
||||
|
||||
SDL_DestroyRenderer(RENDERER);
|
||||
SDL_FreeSurface(WINDOW_SURFACE);
|
||||
SDL_DestroyWindow(WINDOW);
|
||||
|
||||
SDL_Quit();
|
||||
SDL_HelperTerm();
|
||||
plExit();
|
||||
romfsExit();
|
||||
}
|
||||
|
||||
static void Init_Services(void)
|
||||
{
|
||||
romfsInit();
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
|
||||
SDL_CreateWindowAndRenderer(1280, 720, 0, &WINDOW, &RENDERER);
|
||||
|
||||
WINDOW_SURFACE = SDL_GetWindowSurface(WINDOW);
|
||||
|
||||
SDL_SetRenderDrawBlendMode(RENDERER, SDL_BLENDMODE_BLEND);
|
||||
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
|
||||
|
||||
IMG_Init(IMG_INIT_PNG);
|
||||
|
||||
SDL_LoadImage(RENDERER, &banner, "romfs:/banner.png");
|
||||
SDL_LoadImage(RENDERER, &drive, "romfs:/drive.png");
|
||||
|
||||
TTF_Init();
|
||||
|
||||
Ubuntu_R = TTF_OpenFont("romfs:/Ubuntu-R.ttf", 25);
|
||||
Ubuntu_R_large = TTF_OpenFont("romfs:/Ubuntu-R.ttf", 30);
|
||||
|
||||
if (!Ubuntu_R || !Ubuntu_R_large)
|
||||
Term_Services();
|
||||
|
||||
static void Init_Services(void) {
|
||||
Result ret = 0;
|
||||
|
||||
if (R_FAILED(ret = romfsInit()))
|
||||
printf("romfsInit() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (R_FAILED(ret = plInitialize()))
|
||||
printf("plInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (R_FAILED(ret = SDL_HelperInit()))
|
||||
printf("SDL_HelperInit() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (R_FAILED(ret = setInitialize()))
|
||||
printf("setInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
@ -88,8 +58,7 @@ static void Init_Services(void)
|
||||
printf("psmInitialize() failed: 0x%x.\n\n", ret);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
Init_Services();
|
||||
Menu_Main();
|
||||
Term_Services();
|
||||
|
@ -13,26 +13,116 @@
|
||||
#define MENU_Y_DIST 67
|
||||
#define MAX_MENU_ITEMS 5
|
||||
|
||||
static int item_height = 0;
|
||||
static u32 item_height = 0;
|
||||
|
||||
static Service setsys_service, psm_service;
|
||||
static Service setsys_service, setcal_service, psm_service, wlaninf_service;
|
||||
|
||||
static void Menu_DrawItem(int x, int y, char *item_title, const char* text, ...)
|
||||
{
|
||||
int title_width = 0;
|
||||
TTF_SizeText(Ubuntu_R, item_title, &title_width, NULL);
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, x, y, MENU_INFO_TITLE_COLOUR, item_title);
|
||||
static Result wlaninfGetState(Service *srv, u32 *out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 10;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if(R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 state;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = resp->state;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Result wlaninfGetRssi(Service *srv, u32 *out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 12;
|
||||
|
||||
Result rc = serviceIpcDispatch(srv);
|
||||
|
||||
if(R_SUCCEEDED(rc)) {
|
||||
IpcParsedCommand r;
|
||||
ipcParse(&r);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 result;
|
||||
u32 rssi;
|
||||
} *resp = r.Raw;
|
||||
|
||||
rc = resp->result;
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
*out = resp->rssi;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetWlanState(Service *srv) {
|
||||
Result ret = 0;
|
||||
u32 out = 0;
|
||||
|
||||
if (R_FAILED(ret = wlaninfGetState(srv, &out)))
|
||||
return -1;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
u32 SwitchIdent_GetWlanRSSI(Service *srv) {
|
||||
Result ret = 0;
|
||||
u32 out = 0;
|
||||
|
||||
if (R_FAILED(ret = wlaninfGetRssi(srv, &out)))
|
||||
return -1;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
static void Menu_DrawItem(int x, int y, char *item_title, const char* text, ...) {
|
||||
u32 title_width = 0;
|
||||
SDL_GetTextDimensions(25, item_title, &title_width, NULL);
|
||||
SDL_DrawText(x, y, 25, MENU_INFO_TITLE_COLOUR, item_title);
|
||||
|
||||
char buffer[256];
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
vsnprintf(buffer, 256, text, args);
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, x + title_width + 20, y, MENU_INFO_DESC_COLOUR, buffer);
|
||||
SDL_DrawText(x + title_width + 20, y, 25, MENU_INFO_DESC_COLOUR, buffer);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void Menu_Kernel(void)
|
||||
{
|
||||
static void Menu_Kernel(void) {
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 50, "Firmware version:", SwitchIdent_GetFirmwareVersion(&setsys_service));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 100, "Kernel version:", SwitchIdent_GetKernelVersion());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "Hardware:", SwitchIdent_GetHardwareType());
|
||||
@ -42,27 +132,24 @@ static void Menu_Kernel(void)
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 350, "Device ID:", "%llu", SwitchIdent_GetDeviceID());
|
||||
}
|
||||
|
||||
static void Menu_System(void)
|
||||
{
|
||||
static void Menu_System(void) {
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 50, "Region:", SwitchIdent_GetRegion());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 100, "CPU clock:", "%lu MHz", SwitchIdent_GetCPUClock());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "GPU clock:", "%lu MHz", SwitchIdent_GetGPUClock());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "Wireless LAN:", SwitchIdent_GetFlag(SetSysFlag_WirelessLanEnable)? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 250, "Bluetooth:", SwitchIdent_GetFlag(SetSysFlag_BluetoothEnable)? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "Wireless LAN:", "%s (state: %d) (RSSI: %d)", SwitchIdent_GetFlag(SetSysFlag_WirelessLanEnable)? "Enabled" : "Disabled", SwitchIdent_GetWlanState(&wlaninf_service), SwitchIdent_GetWlanRSSI(&wlaninf_service));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 250, "Bluetooth:", "%s", SwitchIdent_GetFlag(SetSysFlag_BluetoothEnable)? "Enabled" : "Disabled");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 300, "NFC:", SwitchIdent_GetFlag(SetSysFlag_NfcEnable)? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
static void Menu_Power(void)
|
||||
{
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 50, "Battery percentage:", "%lu %%", SwitchIdent_GetBatteryPercent());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 100, "Battery voltage:", "%lu", SwitchIdent_GetVoltage(&psm_service));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "Battery charger type:", "%d", SwitchIdent_GetChargerType(&psm_service));
|
||||
static void Menu_Power(void) {
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 50, "Battery percentage:", "%lu %% (%s)", SwitchIdent_GetBatteryPercent(), SwitchIdent_IsCharging()? "charging" : "not charging");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 100, "Battery voltage state:", SwitchIdent_GetVoltageState(&psm_service));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 150, "Battery charger type:", SwitchIdent_GetChargerType());
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "Battery charging enabled:", SwitchIdent_IsChargingEnabled(&psm_service)? "Yes" : "No");
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 250, "Battery ample power supplied:", SwitchIdent_IsEnoughPowerSupplied(&psm_service)? "Yes" : "No");
|
||||
}
|
||||
|
||||
static void Menu_Storage(void)
|
||||
{
|
||||
static void Menu_Storage(void) {
|
||||
u64 sd_used = SwitchIdent_GetUsedStorage(FsStorageId_SdCard);
|
||||
u64 sd_total = SwitchIdent_GetTotalStorage(FsStorageId_SdCard);
|
||||
|
||||
@ -87,41 +174,40 @@ static void Menu_Storage(void)
|
||||
Utils_GetSizeString(nand_s_free_str, SwitchIdent_GetFreeStorage(FsStorageId_NandSystem));
|
||||
Utils_GetSizeString(nand_s_used_str, nand_s_used);
|
||||
|
||||
SDL_DrawRect(RENDERER, 400, 50, 880, 670, BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(400, 50, 880, 670, BACKGROUND_COLOUR);
|
||||
|
||||
SDL_DrawImage(RENDERER, drive, 450, 88);
|
||||
SDL_DrawRect(RENDERER, 450, 226, 128, 25, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(RENDERER, 452, 228, 124, 21, BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(RENDERER, 452, 228, (((double)sd_used / (double)sd_total) * 124.0), 21, MENU_SELECTOR_COLOUR);
|
||||
SDL_DrawDriveIcon(450, 88);
|
||||
SDL_DrawRect(450, 226, 128, 25, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(452, 228, 124, 21, BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(452, 228, (((double)sd_used / (double)sd_total) * 124.0), 21, MENU_SELECTOR_COLOUR);
|
||||
|
||||
SDL_DrawImage(RENDERER, drive, 450, 296);
|
||||
SDL_DrawRect(RENDERER, 450, 434, 128, 25, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(RENDERER, 452, 436, 124, 21, BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(RENDERER, 452, 436, (((double)nand_u_used / (double)nand_u_total) * 124.0), 21, MENU_SELECTOR_COLOUR);
|
||||
SDL_DrawDriveIcon(450, 296);
|
||||
SDL_DrawRect(450, 434, 128, 25, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(452, 436, 124, 21, BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(452, 436, (((double)nand_u_used / (double)nand_u_total) * 124.0), 21, MENU_SELECTOR_COLOUR);
|
||||
|
||||
SDL_DrawImage(RENDERER, drive, 450, 504);
|
||||
SDL_DrawRect(RENDERER, 450, 642, 128, 25, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(RENDERER, 452, 644, 124, 21, BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(RENDERER, 452, 644, (((double)nand_s_used / (double)nand_s_total) * 124.0), 21, MENU_SELECTOR_COLOUR);
|
||||
SDL_DrawDriveIcon(450, 504);
|
||||
SDL_DrawRect(450, 642, 128, 25, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(452, 644, 124, 21, BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(452, 644, (((double)nand_s_used / (double)nand_s_total) * 124.0), 21, MENU_SELECTOR_COLOUR);
|
||||
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 600, 38 + ((MENU_Y_DIST - item_height) / 2) + 50, MENU_INFO_DESC_COLOUR, "SD");
|
||||
SDL_DrawText(600, 38 + ((MENU_Y_DIST - item_height) / 2) + 50, 25, MENU_INFO_DESC_COLOUR, "SD");
|
||||
Menu_DrawItem(600, 38 + ((MENU_Y_DIST - item_height) / 2) + 88, "Total storage capacity:", sd_total_str);
|
||||
Menu_DrawItem(600, 38 + ((MENU_Y_DIST - item_height) / 2) + 126, "Free storage capacity:", sd_free_str);
|
||||
Menu_DrawItem(600, 38 + ((MENU_Y_DIST - item_height) / 2) + 164, "Used storage capacity:", sd_used_str);
|
||||
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 600, 246 + ((MENU_Y_DIST - item_height) / 2) + 50, MENU_INFO_DESC_COLOUR, "NAND User");
|
||||
SDL_DrawText(600, 246 + ((MENU_Y_DIST - item_height) / 2) + 50, 25, MENU_INFO_DESC_COLOUR, "NAND User");
|
||||
Menu_DrawItem(600, 246 + ((MENU_Y_DIST - item_height) / 2) + 88, "Total storage capacity:", nand_u_total_str);
|
||||
Menu_DrawItem(600, 246 + ((MENU_Y_DIST - item_height) / 2) + 126, "Free storage capacity:", nand_u_free_str);
|
||||
Menu_DrawItem(600, 246 + ((MENU_Y_DIST - item_height) / 2) + 164, "Used storage capacity:", nand_u_used_str);
|
||||
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 600, 454 + ((MENU_Y_DIST - item_height) / 2) + 50, MENU_INFO_DESC_COLOUR, "NAND System");
|
||||
SDL_DrawText(600, 454 + ((MENU_Y_DIST - item_height) / 2) + 50, 25, MENU_INFO_DESC_COLOUR, "NAND System");
|
||||
Menu_DrawItem(600, 454 + ((MENU_Y_DIST - item_height) / 2) + 88, "Total storage capacity:", nand_s_total_str);
|
||||
Menu_DrawItem(600, 454 + ((MENU_Y_DIST - item_height) / 2) + 126, "Free storage capacity:", nand_s_free_str);
|
||||
Menu_DrawItem(600, 454 + ((MENU_Y_DIST - item_height) / 2) + 164, "Used storage capacity:", nand_s_used_str);
|
||||
}
|
||||
|
||||
static void Menu_Misc(void)
|
||||
{
|
||||
static void Menu_Misc(void) {
|
||||
char hostname[128];
|
||||
Result ret = gethostname(hostname, sizeof(hostname));
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 50, "IP:", R_SUCCEEDED(ret)? hostname : NULL);
|
||||
@ -130,45 +216,44 @@ static void Menu_Misc(void)
|
||||
Menu_DrawItem(450, 250 + ((MENU_Y_DIST - item_height) / 2) + 200, "Console information upload:", SwitchIdent_GetFlag(SetSysFlag_ConsoleInformationUpload)? "Enabled" : "Disabled");
|
||||
}
|
||||
|
||||
void Menu_Main(void)
|
||||
{
|
||||
int title_height = 0;
|
||||
TTF_SizeText(Ubuntu_R, "SwitchIdent", NULL, &title_height);
|
||||
|
||||
TTF_SizeText(Ubuntu_R, "Test", NULL, &item_height);
|
||||
|
||||
int banner_width = 0;
|
||||
SDL_QueryTexture(banner, NULL, NULL, &banner_width, NULL);
|
||||
void Menu_Main(void) {
|
||||
u32 title_height = 0;
|
||||
SDL_GetTextDimensions(25, "SwitchIdent", NULL, &title_height);
|
||||
SDL_GetTextDimensions(25, "Test", NULL, &item_height);
|
||||
|
||||
int banner_width = 200;
|
||||
int selection = 0;
|
||||
|
||||
Result ret = 0;
|
||||
|
||||
if (R_FAILED(ret = smGetService(&setsys_service, "set:sys")))
|
||||
printf("setsysInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (R_FAILED(ret = smGetService(&setcal_service, "set:cal")))
|
||||
printf("setcalInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
if (R_FAILED(ret = smGetService(&psm_service, "psm")))
|
||||
printf("psmInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
while(appletMainLoop())
|
||||
{
|
||||
SDL_ClearScreen(RENDERER, BACKGROUND_COLOUR);
|
||||
SDL_RenderClear(RENDERER);
|
||||
SDL_DrawRect(RENDERER, 0, 0, 1280, 50, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(RENDERER, 0, 50, 400, 670, MENU_BAR_COLOUR);
|
||||
if (R_FAILED(ret = smGetService(&wlaninf_service, "wlan:inf")))
|
||||
printf("wlaninfInitialize() failed: 0x%x.\n\n", ret);
|
||||
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 40, ((50 - title_height) / 2), BACKGROUND_COLOUR, "SwitchIdent");
|
||||
while(appletMainLoop()) {
|
||||
SDL_ClearScreen(BACKGROUND_COLOUR);
|
||||
SDL_DrawRect(0, 0, 1280, 50, STATUS_BAR_COLOUR);
|
||||
SDL_DrawRect(0, 50, 400, 670, MENU_BAR_COLOUR);
|
||||
|
||||
SDL_DrawImage(RENDERER, banner, 400 + ((880 - (banner_width)) / 2), 80);
|
||||
SDL_DrawText(30, ((50 - title_height) / 2), 25, BACKGROUND_COLOUR, "SwitchIdent");// 0x%lx 0x%lx", connect, disconnect);
|
||||
|
||||
SDL_DrawRect(RENDERER, 0, 50 + (MENU_Y_DIST * selection), 400, MENU_Y_DIST, MENU_SELECTOR_COLOUR);
|
||||
SDL_DrawBanner(400 + ((880 - (banner_width)) / 2), 80);
|
||||
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 30, 50 + ((MENU_Y_DIST - item_height) / 2), selection == 0? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Kernel");
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 1), selection == 1? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "System");
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 2), selection == 2? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Power");
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 3), selection == 3? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Storage");
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 4), selection == 4? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Misc");
|
||||
SDL_DrawText(RENDERER, Ubuntu_R, 30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 5), selection == 5? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Exit");
|
||||
SDL_DrawRect(0, 50 + (MENU_Y_DIST * selection), 400, MENU_Y_DIST, MENU_SELECTOR_COLOUR);
|
||||
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2), 25, selection == 0? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Kernel");
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 1), 25, selection == 1? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "System");
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 2), 25, selection == 2? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Power");
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 3), 25, selection == 3? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Storage");
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 4), 25, selection == 4? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Misc");
|
||||
SDL_DrawText(30, 50 + ((MENU_Y_DIST - item_height) / 2) + (MENU_Y_DIST * 5), 25, selection == 5? ITEM_SELECTED_COLOUR : ITEM_COLOUR, "Exit");
|
||||
|
||||
hidScanInput();
|
||||
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
@ -183,8 +268,7 @@ void Menu_Main(void)
|
||||
if (selection < 0)
|
||||
selection = MAX_MENU_ITEMS;
|
||||
|
||||
switch (selection)
|
||||
{
|
||||
switch (selection) {
|
||||
case 0:
|
||||
Menu_Kernel();
|
||||
break;
|
||||
@ -202,12 +286,14 @@ void Menu_Main(void)
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_RenderPresent(RENDERER);
|
||||
SDL_Renderdisplay();
|
||||
|
||||
if ((kDown & KEY_PLUS) || ((kDown & KEY_A) && (selection == MAX_MENU_ITEMS)))
|
||||
break;
|
||||
}
|
||||
|
||||
serviceClose(&setsys_service);
|
||||
serviceClose(&wlaninf_service);
|
||||
serviceClose(&psm_service);
|
||||
}
|
||||
serviceClose(&setcal_service);
|
||||
serviceClose(&setsys_service);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user