Replaced all tab occurrences with spaces.
This commit is contained in:
parent
e193e1992f
commit
8cc32a952f
@ -2,8 +2,8 @@
|
||||
#include "font.h"
|
||||
|
||||
font_s fontDefault = {
|
||||
font1Data,
|
||||
font1Desc,
|
||||
16,
|
||||
{ 0xFF, 0xFF, 0xFF }
|
||||
font1Data,
|
||||
font1Desc,
|
||||
16,
|
||||
{ 0xFF, 0xFF, 0xFF }
|
||||
};
|
||||
|
@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
struct charDesc_s {
|
||||
char c;
|
||||
int x, y, w, h, xo, yo, xa;
|
||||
u8* data;
|
||||
char c;
|
||||
int x, y, w, h, xo, yo, xa;
|
||||
u8* data;
|
||||
};
|
||||
|
||||
struct font_s {
|
||||
u8* data;
|
||||
charDesc_s* desc;
|
||||
u8 height;
|
||||
u8 color[3];
|
||||
u8* data;
|
||||
charDesc_s* desc;
|
||||
u8 height;
|
||||
u8 color[3];
|
||||
};
|
||||
|
||||
extern u8 font1Data[];
|
||||
|
512
source/font1.cpp
512
source/font1.cpp
File diff suppressed because one or more lines are too long
@ -7,47 +7,47 @@
|
||||
|
||||
static unsigned int testCounter = 0;
|
||||
static void (*tests[]) (void) = {
|
||||
FS::TestAll
|
||||
FS::TestAll
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
srvInit();
|
||||
aptInit();
|
||||
hidInit(NULL);
|
||||
gfxInit();
|
||||
gfxSet3D(false);
|
||||
srvInit();
|
||||
aptInit();
|
||||
hidInit(NULL);
|
||||
gfxInit();
|
||||
gfxSet3D(false);
|
||||
|
||||
clearScreens();
|
||||
print(GFX_TOP, "Press A to begin...\n");
|
||||
clearScreens();
|
||||
print(GFX_TOP, "Press A to begin...\n");
|
||||
|
||||
while (aptMainLoop()) {
|
||||
drawFrames();
|
||||
while (aptMainLoop()) {
|
||||
drawFrames();
|
||||
|
||||
hidScanInput();
|
||||
if (hidKeysDown() & KEY_START) {
|
||||
break;
|
||||
} else if (hidKeysDown() & KEY_A) {
|
||||
clearScreen(GFX_TOP);
|
||||
hidScanInput();
|
||||
if (hidKeysDown() & KEY_START) {
|
||||
break;
|
||||
} else if (hidKeysDown() & KEY_A) {
|
||||
clearScreen(GFX_TOP);
|
||||
|
||||
if (testCounter < (sizeof(tests) / sizeof(tests[0]))) {
|
||||
tests[testCounter]();
|
||||
testCounter++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (testCounter < (sizeof(tests) / sizeof(tests[0]))) {
|
||||
tests[testCounter]();
|
||||
testCounter++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
print(GFX_TOP, "\n");
|
||||
print(GFX_TOP, "Press A to continue...\n");
|
||||
}
|
||||
print(GFX_TOP, "\n");
|
||||
print(GFX_TOP, "Press A to continue...\n");
|
||||
}
|
||||
|
||||
gspWaitForEvent(GSPEVENT_VBlank0, false);
|
||||
}
|
||||
gspWaitForEvent(GSPEVENT_VBlank0, false);
|
||||
}
|
||||
|
||||
clearScreens();
|
||||
gfxExit();
|
||||
hidExit();
|
||||
aptExit();
|
||||
srvExit();
|
||||
return 0;
|
||||
clearScreens();
|
||||
gfxExit();
|
||||
hidExit();
|
||||
aptExit();
|
||||
srvExit();
|
||||
return 0;
|
||||
}
|
||||
|
@ -15,21 +15,21 @@ static std::string bufferBottom;
|
||||
|
||||
static int countLines(const std::string& str)
|
||||
{
|
||||
if (str.empty())
|
||||
return 0;
|
||||
if (str.empty())
|
||||
return 0;
|
||||
|
||||
int cnt = 1;
|
||||
int cnt = 1;
|
||||
for (const char& c : str) {
|
||||
if (c == '\n') cnt++;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static void deleteFirstLine(std::string* str)
|
||||
{
|
||||
if (str->empty())
|
||||
return;
|
||||
if (str->empty())
|
||||
return;
|
||||
|
||||
size_t linebreak = str->find_first_of('\n');
|
||||
|
||||
@ -43,65 +43,65 @@ static void deleteFirstLine(std::string* str)
|
||||
|
||||
static void drawFrame(gfxScreen_t screen, u8 b, u8 g, u8 r)
|
||||
{
|
||||
int screenWidth;
|
||||
std::string textBuffer;
|
||||
if (screen == GFX_TOP) {
|
||||
screenWidth = 400;
|
||||
textBuffer = bufferTop;
|
||||
} else {
|
||||
screenWidth = 320;
|
||||
textBuffer = bufferBottom;
|
||||
}
|
||||
int screenWidth;
|
||||
std::string textBuffer;
|
||||
if (screen == GFX_TOP) {
|
||||
screenWidth = 400;
|
||||
textBuffer = bufferTop;
|
||||
} else {
|
||||
screenWidth = 320;
|
||||
textBuffer = bufferBottom;
|
||||
}
|
||||
|
||||
// Fill screen with color (TODO: find more efficient way to do this)
|
||||
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
|
||||
for (int i = 0; i < screenWidth * 240 * 3; i += 3) {
|
||||
bufAdr[i] = b;
|
||||
bufAdr[i+1] = g;
|
||||
bufAdr[i+2] = r;
|
||||
}
|
||||
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
|
||||
for (int i = 0; i < screenWidth * 240 * 3; i += 3) {
|
||||
bufAdr[i] = b;
|
||||
bufAdr[i+1] = g;
|
||||
bufAdr[i+2] = r;
|
||||
}
|
||||
|
||||
int lines = countLines(textBuffer);
|
||||
while (lines > (240 / fontDefault.height - 3)) {
|
||||
deleteFirstLine(&textBuffer);
|
||||
lines--;
|
||||
}
|
||||
int lines = countLines(textBuffer);
|
||||
while (lines > (240 / fontDefault.height - 3)) {
|
||||
deleteFirstLine(&textBuffer);
|
||||
lines--;
|
||||
}
|
||||
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), 240 - fontDefault.height * 3, 10);
|
||||
}
|
||||
|
||||
void drawFrames()
|
||||
{
|
||||
drawFrame(GFX_TOP, 0x88, 0x66, 0x00);
|
||||
drawFrame(GFX_BOTTOM, 0x00, 0x00, 0x00);
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
drawFrame(GFX_TOP, 0x88, 0x66, 0x00);
|
||||
drawFrame(GFX_BOTTOM, 0x00, 0x00, 0x00);
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
|
||||
void print(gfxScreen_t screen, const char* format, ...)
|
||||
{
|
||||
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
|
||||
va_list arguments;
|
||||
char newStr[512];
|
||||
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
|
||||
va_list arguments;
|
||||
char newStr[512];
|
||||
|
||||
va_start(arguments, format);
|
||||
vsprintf(newStr, format, arguments);
|
||||
va_end(arguments);
|
||||
va_start(arguments, format);
|
||||
vsprintf(newStr, format, arguments);
|
||||
va_end(arguments);
|
||||
|
||||
textBuffer += newStr;
|
||||
svcOutputDebugString(newStr, strlen(newStr));
|
||||
textBuffer += newStr;
|
||||
svcOutputDebugString(newStr, strlen(newStr));
|
||||
|
||||
drawFrames();
|
||||
drawFrames();
|
||||
}
|
||||
|
||||
void clearScreen(gfxScreen_t screen)
|
||||
{
|
||||
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
|
||||
textBuffer.clear();
|
||||
drawFrames();
|
||||
textBuffer.clear();
|
||||
drawFrames();
|
||||
}
|
||||
|
||||
void clearScreens()
|
||||
{
|
||||
clearScreen(GFX_TOP);
|
||||
clearScreen(GFX_BOTTOM);
|
||||
clearScreen(GFX_TOP);
|
||||
clearScreen(GFX_BOTTOM);
|
||||
}
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
void Test(std::string group, std::string name, std::function<bool (void)> test)
|
||||
{
|
||||
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() ? "SUCCESS" : "FAILURE");
|
||||
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() ? "SUCCESS" : "FAILURE");
|
||||
}
|
||||
|
||||
void TestResult(std::string group, std::string name, std::function<int (void)> test)
|
||||
{
|
||||
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() == 0 ? "SUCCESS" : "FAILURE");
|
||||
print(GFX_TOP, "%s: %s - %s\n", group.c_str(), name.c_str(), test() == 0 ? "SUCCESS" : "FAILURE");
|
||||
}
|
||||
|
@ -8,91 +8,91 @@ namespace FS {
|
||||
|
||||
static void TestSDMC()
|
||||
{
|
||||
FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
|
||||
|
||||
FS_path dirPath = FS_makePath(PATH_CHAR, "/new_dir");
|
||||
Handle dirHandle;
|
||||
|
||||
FS_path filePath = FS_makePath(PATH_CHAR, "/new_dir/new_file.txt");
|
||||
Handle fileHandle;
|
||||
u64 fileSize;
|
||||
|
||||
u32 bytesWritten;
|
||||
FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
|
||||
|
||||
FS_path dirPath = FS_makePath(PATH_CHAR, "/new_dir");
|
||||
Handle dirHandle;
|
||||
|
||||
FS_path filePath = FS_makePath(PATH_CHAR, "/new_dir/new_file.txt");
|
||||
Handle fileHandle;
|
||||
u64 fileSize;
|
||||
|
||||
u32 bytesWritten;
|
||||
|
||||
// Open SDMC
|
||||
TestResult("SDMC", "Opening archive", [&]{
|
||||
return FSUSER_OpenArchive(NULL, &sdmcArchive);
|
||||
});
|
||||
// Open SDMC
|
||||
TestResult("SDMC", "Opening archive", [&]{
|
||||
return FSUSER_OpenArchive(NULL, &sdmcArchive);
|
||||
});
|
||||
|
||||
// Create Directory
|
||||
TestResult("SDMC", "Creating directory", [&]{
|
||||
return FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
|
||||
});
|
||||
// Create Directory
|
||||
TestResult("SDMC", "Creating directory", [&]{
|
||||
return FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
|
||||
});
|
||||
|
||||
// Open Directory
|
||||
TestResult("SDMC", "Opening directory handle", [&]{
|
||||
return FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
|
||||
});
|
||||
// Open Directory
|
||||
TestResult("SDMC", "Opening directory handle", [&]{
|
||||
return FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
|
||||
});
|
||||
|
||||
// Open File
|
||||
TestResult("SDMC", "Opening file handle", [&]{
|
||||
return FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_WRITE | FS_OPEN_CREATE, 0);
|
||||
});
|
||||
// Open File
|
||||
TestResult("SDMC", "Opening file handle", [&]{
|
||||
return FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_WRITE | FS_OPEN_CREATE, 0);
|
||||
});
|
||||
|
||||
// Write File
|
||||
TestResult("SDMC", "Writing data to file", [&]{
|
||||
const char* stringWritten = "A string\n";
|
||||
return FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten), FS_WRITE_FLUSH);
|
||||
});
|
||||
// Write File
|
||||
TestResult("SDMC", "Writing data to file", [&]{
|
||||
const char* stringWritten = "A string\n";
|
||||
return FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten), FS_WRITE_FLUSH);
|
||||
});
|
||||
|
||||
// Check File Size
|
||||
TestResult("SDMC", "Getting size of file", [&]{
|
||||
return FSFILE_GetSize(fileHandle, &fileSize);
|
||||
});
|
||||
// Check File Size
|
||||
TestResult("SDMC", "Getting size of file", [&]{
|
||||
return FSFILE_GetSize(fileHandle, &fileSize);
|
||||
});
|
||||
|
||||
// Verify File Size
|
||||
Test("SDMC", "Verifying size with written bytes", [&]{
|
||||
return fileSize == bytesWritten;
|
||||
});
|
||||
// Verify File Size
|
||||
Test("SDMC", "Verifying size with written bytes", [&]{
|
||||
return fileSize == bytesWritten;
|
||||
});
|
||||
|
||||
// Close File
|
||||
TestResult("SDMC", "Closing file handle", [&]{
|
||||
return FSFILE_Close(fileHandle);
|
||||
});
|
||||
// Close File
|
||||
TestResult("SDMC", "Closing file handle", [&]{
|
||||
return FSFILE_Close(fileHandle);
|
||||
});
|
||||
|
||||
// Close Directory
|
||||
TestResult("SDMC", "Closing directory handle", [&]{
|
||||
return FSDIR_Close(dirHandle);
|
||||
});
|
||||
// Close Directory
|
||||
TestResult("SDMC", "Closing directory handle", [&]{
|
||||
return FSDIR_Close(dirHandle);
|
||||
});
|
||||
|
||||
// Delete File
|
||||
TestResult("SDMC", "Deleting file", [&]{
|
||||
return FSUSER_DeleteFile(NULL, sdmcArchive, filePath);
|
||||
});
|
||||
// Delete File
|
||||
TestResult("SDMC", "Deleting file", [&]{
|
||||
return FSUSER_DeleteFile(NULL, sdmcArchive, filePath);
|
||||
});
|
||||
|
||||
// Delete Directory
|
||||
TestResult("SDMC", "Deleting directory", [&]{
|
||||
return FSUSER_DeleteDirectory(NULL, sdmcArchive, dirPath);
|
||||
});
|
||||
// Delete Directory
|
||||
TestResult("SDMC", "Deleting directory", [&]{
|
||||
return FSUSER_DeleteDirectory(NULL, sdmcArchive, dirPath);
|
||||
});
|
||||
|
||||
// Close SDMC
|
||||
TestResult("SDMC", "Closing archive", [&]{
|
||||
return FSUSER_CloseArchive(NULL, &sdmcArchive);
|
||||
});
|
||||
// Close SDMC
|
||||
TestResult("SDMC", "Closing archive", [&]{
|
||||
return FSUSER_CloseArchive(NULL, &sdmcArchive);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void TestAll()
|
||||
{
|
||||
TestResult("FS", "Initializing service", [&]{
|
||||
return fsInit();
|
||||
});
|
||||
TestResult("FS", "Initializing service", [&]{
|
||||
return fsInit();
|
||||
});
|
||||
|
||||
TestSDMC();
|
||||
TestSDMC();
|
||||
|
||||
TestResult("FS", "Exiting service", [&]{
|
||||
return fsExit();
|
||||
});
|
||||
TestResult("FS", "Exiting service", [&]{
|
||||
return fsExit();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
108
source/text.cpp
108
source/text.cpp
@ -9,76 +9,76 @@
|
||||
//this code is not meant to be readable
|
||||
int drawCharacter(u8* fb, font_s* font, char c, s16 x, s16 y, u16 w, u16 h)
|
||||
{
|
||||
charDesc_s* cd = &font->desc[(int)c];
|
||||
charDesc_s* cd = &font->desc[(int)c];
|
||||
|
||||
if (!cd->data)
|
||||
return 0;
|
||||
if (!cd->data)
|
||||
return 0;
|
||||
|
||||
x += cd->xo; y += font->height - cd->yo - cd->h;
|
||||
x += cd->xo; y += font->height - cd->yo - cd->h;
|
||||
|
||||
if (x < 0 || x + cd->w >= w || y < -cd->h || y >= h + cd->h)
|
||||
return 0;
|
||||
if (x < 0 || x + cd->w >= w || y < -cd->h || y >= h + cd->h)
|
||||
return 0;
|
||||
|
||||
u8* charData = cd->data;
|
||||
s16 cy = y, ch = cd->h, cyo = 0;
|
||||
u8* charData = cd->data;
|
||||
s16 cy = y, ch = cd->h, cyo = 0;
|
||||
|
||||
if (y < 0) {
|
||||
cy = 0;
|
||||
cyo = -y;
|
||||
ch = cd->h-cyo;
|
||||
} else if (y + ch > h) {
|
||||
ch = h - y;
|
||||
}
|
||||
if (y < 0) {
|
||||
cy = 0;
|
||||
cyo = -y;
|
||||
ch = cd->h-cyo;
|
||||
} else if (y + ch > h) {
|
||||
ch = h - y;
|
||||
}
|
||||
|
||||
fb += (x * h + cy) * 3;
|
||||
const u8 r = font->color[0];
|
||||
const u8 g = font->color[1];
|
||||
const u8 b = font->color[2];
|
||||
fb += (x * h + cy) * 3;
|
||||
const u8 r = font->color[0];
|
||||
const u8 g = font->color[1];
|
||||
const u8 b = font->color[2];
|
||||
|
||||
int i, j;
|
||||
for (i = 0; i < cd->w; i++) {
|
||||
charData += cyo;
|
||||
for(j = 0; j < ch; j++) {
|
||||
u8 v = *(charData++);
|
||||
if (v) {
|
||||
fb[0] = (fb[0] * (0xFF - v) + (b * v)) >> 8;
|
||||
fb[1] = (fb[1] * (0xFF - v) + (g * v)) >> 8;
|
||||
fb[2] = (fb[2] * (0xFF - v) + (r * v)) >> 8;
|
||||
}
|
||||
fb += 3;
|
||||
}
|
||||
charData += (cd->h - (cyo + ch));
|
||||
fb += (h - ch) * 3;
|
||||
}
|
||||
return cd->xa;
|
||||
int i, j;
|
||||
for (i = 0; i < cd->w; i++) {
|
||||
charData += cyo;
|
||||
for(j = 0; j < ch; j++) {
|
||||
u8 v = *(charData++);
|
||||
if (v) {
|
||||
fb[0] = (fb[0] * (0xFF - v) + (b * v)) >> 8;
|
||||
fb[1] = (fb[1] * (0xFF - v) + (g * v)) >> 8;
|
||||
fb[2] = (fb[2] * (0xFF - v) + (r * v)) >> 8;
|
||||
}
|
||||
fb += 3;
|
||||
}
|
||||
charData += (cd->h - (cyo + ch));
|
||||
fb += (h - ch) * 3;
|
||||
}
|
||||
return cd->xa;
|
||||
}
|
||||
|
||||
void drawString(u8* fb, font_s* f, const char* str, s16 x, s16 y, u16 w, u16 h)
|
||||
{
|
||||
if (!f || !fb || !str)
|
||||
return;
|
||||
if (!f || !fb || !str)
|
||||
return;
|
||||
|
||||
int k, dx = 0, dy = 0;
|
||||
int length = strlen(str);
|
||||
for (k = 0; k < length; k++)
|
||||
{
|
||||
dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h);
|
||||
if(str[k]=='\n') {
|
||||
dx = 0;
|
||||
dy -= f->height;
|
||||
}
|
||||
}
|
||||
int k, dx = 0, dy = 0;
|
||||
int length = strlen(str);
|
||||
for (k = 0; k < length; k++)
|
||||
{
|
||||
dx += drawCharacter(fb, f, str[k], x + dx, y + dy, w, h);
|
||||
if(str[k]=='\n') {
|
||||
dx = 0;
|
||||
dy -= f->height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* font, const char* str, s16 x, s16 y)
|
||||
{
|
||||
if(!str)
|
||||
return;
|
||||
if(!font)
|
||||
font = &fontDefault;
|
||||
if(!str)
|
||||
return;
|
||||
if(!font)
|
||||
font = &fontDefault;
|
||||
|
||||
u16 fbWidth, fbHeight;
|
||||
u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);
|
||||
u16 fbWidth, fbHeight;
|
||||
u8* fbAdr = gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);
|
||||
|
||||
drawString(fbAdr, font, str, y, x, fbHeight, fbWidth);
|
||||
drawString(fbAdr, font, str, y, x, fbHeight, fbWidth);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user