Formatting

This commit is contained in:
Maschell 2022-01-22 14:44:39 +01:00
parent 7e5f174076
commit ad693c94ff
3 changed files with 101 additions and 107 deletions

View File

@ -134,10 +134,9 @@ void bootHomebrewChannel() {
// test if the OHBC or HBC is installed
if (IOSUHAX_FSA_GetStat(fsaFd, "/vol/storage_slccmpt01/title/00010001/4f484243/content/00000000.app", &stat) >= 0) {
titleId = 0x000100014f484243; // 'OHBC'
}
else if (IOSUHAX_FSA_GetStat(fsaFd, "/vol/storage_slccmpt01/title/00010001/4c554c5a/content/00000000.app", &stat) >= 0) {
titleId = 0x000100014c554c5a; // 'LULZ'
titleId = 0x000100014F484243L; // 'OHBC'
} else if (IOSUHAX_FSA_GetStat(fsaFd, "/vol/storage_slccmpt01/title/00010001/4c554c5a/content/00000000.app", &stat) >= 0) {
titleId = 0x000100014C554C5AL; // 'LULZ'
} else {
DEBUG_FUNCTION_LINE("Cannot find HBC, booting vWii System Menu");
}

View File

@ -45,16 +45,14 @@ void* DrawUtils::InitOSScreen(){
return screenBuffer;
}
void DrawUtils::initBuffers(void* tvBuffer, uint32_t tvSize, void* drcBuffer, uint32_t drcSize)
{
void DrawUtils::initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize) {
DrawUtils::tvBuffer = (uint8_t *) tvBuffer;
DrawUtils::tvSize = tvSize;
DrawUtils::drcBuffer = (uint8_t *) drcBuffer;
DrawUtils::drcSize = drcSize;
}
void DrawUtils::beginDraw()
{
void DrawUtils::beginDraw() {
uint32_t pixel = *(uint32_t *) tvBuffer;
// check which buffer is currently used
@ -69,8 +67,7 @@ void DrawUtils::beginDraw()
*(uint32_t *) tvBuffer = pixel;
}
void DrawUtils::endDraw()
{
void DrawUtils::endDraw() {
// OSScreenFlipBuffersEx already flushes the cache?
// DCFlushRange(tvBuffer, tvSize);
// DCFlushRange(drcBuffer, drcSize);
@ -79,14 +76,12 @@ void DrawUtils::endDraw()
OSScreenFlipBuffersEx(SCREEN_TV);
}
void DrawUtils::clear(Color col)
{
void DrawUtils::clear(Color col) {
OSScreenClearBufferEx(SCREEN_TV, col.color);
OSScreenClearBufferEx(SCREEN_DRC, col.color);
}
void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
float opacity = a / 255.0f;
// put pixel in the drc buffer
@ -99,8 +94,7 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
drcBuffer[i] = r;
drcBuffer[i + 1] = g;
drcBuffer[i + 2] = b;
}
else {
} else {
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity);
drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity);
@ -119,8 +113,7 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
tvBuffer[i] = r;
tvBuffer[i + 1] = g;
tvBuffer[i + 2] = b;
}
else {
} else {
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity);
tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity);
@ -130,8 +123,7 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
}
}
void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col)
{
void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col) {
for (uint32_t yy = y; yy < y + h; yy++) {
for (uint32_t xx = x; xx < x + w; xx++) {
drawPixel(xx, yy, col);
@ -139,16 +131,14 @@ void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, C
}
}
void DrawUtils::drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col)
{
void DrawUtils::drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col) {
drawRectFilled(x, y, w, borderSize, col);
drawRectFilled(x, y + h - borderSize, w, borderSize, col);
drawRectFilled(x, y, borderSize, h, col);
drawRectFilled(x + w - borderSize, y, borderSize, h, col);
}
void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t* data)
{
void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data) {
if (data[0] != 'B' || data[1] != 'M') {
// invalid header
return;
@ -174,16 +164,14 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32
}
}
static void png_read_data(png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead)
{
static void png_read_data(png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead) {
void **data = (void **) png_get_io_ptr(png_ptr);
memcpy(outBytes, *data, byteCountToRead);
*((uint8_t **) data) += byteCountToRead;
}
void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
{
void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) {
return;
@ -218,8 +206,7 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
if (colorType == PNG_COLOR_TYPE_RGB_ALPHA) {
uint32_t i = (xx - x) * 4;
drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], rowData[i + 3]);
}
else if (colorType == PNG_COLOR_TYPE_RGB) {
} else if (colorType == PNG_COLOR_TYPE_RGB) {
uint32_t i = (xx - x) * 3;
drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], 0xFF);
}
@ -230,8 +217,7 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
}
void DrawUtils::initFont()
{
void DrawUtils::initFont() {
void *font = NULL;
uint32_t size = 0;
OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size);
@ -242,24 +228,20 @@ void DrawUtils::initFont()
}
}
void DrawUtils::deinitFont()
{
void DrawUtils::deinitFont() {
FT_Done_Face(ft_face);
FT_Done_FreeType(ft_lib);
}
void DrawUtils::setFontSize(uint32_t size)
{
void DrawUtils::setFontSize(uint32_t size) {
FT_Set_Pixel_Sizes(ft_face, 0, size);
}
void DrawUtils::setFontColor(Color col)
{
void DrawUtils::setFontColor(Color col) {
font_col = col;
}
static void draw_freetype_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y)
{
static void draw_freetype_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y) {
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
@ -276,15 +258,13 @@ static void draw_freetype_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y)
}
}
void DrawUtils::print(uint32_t x, uint32_t y, const char* string, bool alignRight)
{
void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRight) {
wchar_t *buffer = new wchar_t[strlen(string) + 1];
size_t num = mbstowcs(buffer, string, strlen(string));
if (num > 0) {
buffer[num] = 0;
}
else {
} else {
wchar_t *tmp = buffer;
while ((*tmp++ = *string++));
}
@ -293,8 +273,7 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char* string, bool alignRigh
delete[] buffer;
}
void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t* string, bool alignRight)
{
void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight) {
FT_GlyphSlot slot = ft_face->glyph;
FT_Vector pen = {(int) x, (int) y};
@ -319,15 +298,13 @@ void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t* string, bool alignR
}
}
uint32_t DrawUtils::getTextWidth(const char* string)
{
uint32_t DrawUtils::getTextWidth(const char *string) {
wchar_t *buffer = new wchar_t[strlen(string) + 1];
size_t num = mbstowcs(buffer, string, strlen(string));
if (num > 0) {
buffer[num] = 0;
}
else {
} else {
wchar_t *tmp = buffer;
while ((*tmp++ = *string++));
}
@ -338,8 +315,7 @@ uint32_t DrawUtils::getTextWidth(const char* string)
return width;
}
uint32_t DrawUtils::getTextWidth(const wchar_t* string)
{
uint32_t DrawUtils::getTextWidth(const wchar_t *string) {
FT_GlyphSlot slot = ft_face->glyph;
uint32_t width = 0;

View File

@ -10,8 +10,12 @@ union Color {
Color(uint32_t color) {
this->color = color;
}
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
this->r = r; this->g = g; this->b = b; this->a = a;
this->r = r;
this->g = g;
this->b = b;
this->a = a;
}
uint32_t color;
@ -26,26 +30,41 @@ union Color {
class DrawUtils {
public:
static void *InitOSScreen();
static void initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize);
static void beginDraw();
static void endDraw();
static void clear(Color col);
static void drawPixel(uint32_t x, uint32_t y, Color col) { drawPixel(x, y, col.r, col.g, col.b, col.a); }
static void drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
static void drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col);
static void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col);
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data);
static void drawPNG(uint32_t x, uint32_t y, const uint8_t *data);
static void initFont();
static void deinitFont();
static void setFontSize(uint32_t size);
static void setFontColor(Color col);
static void print(uint32_t x, uint32_t y, const char *string, bool alignRight = false);
static void print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight = false);
static uint32_t getTextWidth(const char *string);
static uint32_t getTextWidth(const wchar_t *string);
private: