Simplified some code and variable names, re-added std::string as the buffer in output.cpp

This commit is contained in:
archshift 2014-11-22 12:38:59 -08:00
parent 5ec2f38c9a
commit ddf3f4c9dd

View File

@ -10,9 +10,8 @@
#include "text.h" #include "text.h"
static char bufferTop[8192]; static std::string bufferTop;
static char bufferBottom[8192]; static std::string bufferBottom;
static int cnt;
static int countLines(const std::string& str) static int countLines(const std::string& str)
{ {
@ -44,34 +43,23 @@ static void deleteFirstLine(std::string* str)
static void drawFrame(gfxScreen_t screen, char b, char g, char r) static void drawFrame(gfxScreen_t screen, char b, char g, char r)
{ {
int screenWidth; int screenHeight = 240;
std::string textBuffer; int screenWidth = (screen == GFX_TOP) ? 400 : 320;
if (screen == GFX_TOP) { std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
screenWidth = 400;
textBuffer = bufferTop;
} else {
screenWidth = 320;
textBuffer = bufferBottom;
}
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL); u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
int x, y; for (int i = 0; i < screenWidth * screenHeight * 3; i += 3) {
for (x = 1; x < screenWidth; x++) { bufAdr[i] = b;
for (y = 1; y < 240; y++) { bufAdr[i+1] = g;
u32 v=(y + x * 240) * 3; bufAdr[i+2] = r;
bufAdr[v] = b;
bufAdr[v+1] = g;
bufAdr[v+2] = r;
}
} }
x = countLines(textBuffer); int lines = countLines(textBuffer);
while (x > (240 / fontDefault.height - 3)) { while (lines > (screenHeight / fontDefault.height - 3)) {
deleteFirstLine(&textBuffer); deleteFirstLine(&textBuffer);
x--; lines--;
} }
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), 240 - fontDefault.height * 3, 10); gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), screenHeight - fontDefault.height * 3, 10);
cnt++;
} }
void drawFrames() void drawFrames()
@ -84,7 +72,7 @@ void drawFrames()
void print(gfxScreen_t screen, const char* format, ...) void print(gfxScreen_t screen, const char* format, ...)
{ {
char* textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom; std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
va_list arguments; va_list arguments;
char newStr[512]; char newStr[512];
@ -92,7 +80,7 @@ void print(gfxScreen_t screen, const char* format, ...)
vsprintf(newStr, format, arguments); vsprintf(newStr, format, arguments);
va_end(arguments); va_end(arguments);
sprintf(&textBuffer[strlen(textBuffer)], newStr); textBuffer += std::string(newStr);
svcOutputDebugString(newStr, strlen(newStr)); svcOutputDebugString(newStr, strlen(newStr));
drawFrames(); drawFrames();
@ -100,7 +88,8 @@ void print(gfxScreen_t screen, const char* format, ...)
void clearScreen(gfxScreen_t screen) void clearScreen(gfxScreen_t screen)
{ {
bufferTop[0] = 0; std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
textBuffer.clear();
drawFrames(); drawFrames();
} }