Simplified some code and variable names, re-added std::string as the buffer in output.cpp
This commit is contained in:
parent
5ec2f38c9a
commit
ddf3f4c9dd
@ -10,9 +10,8 @@
|
||||
|
||||
#include "text.h"
|
||||
|
||||
static char bufferTop[8192];
|
||||
static char bufferBottom[8192];
|
||||
static int cnt;
|
||||
static std::string bufferTop;
|
||||
static std::string bufferBottom;
|
||||
|
||||
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)
|
||||
{
|
||||
int screenWidth;
|
||||
std::string textBuffer;
|
||||
if (screen == GFX_TOP) {
|
||||
screenWidth = 400;
|
||||
textBuffer = bufferTop;
|
||||
} else {
|
||||
screenWidth = 320;
|
||||
textBuffer = bufferBottom;
|
||||
}
|
||||
int screenHeight = 240;
|
||||
int screenWidth = (screen == GFX_TOP) ? 400 : 320;
|
||||
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
|
||||
|
||||
u8* bufAdr = gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);
|
||||
int x, y;
|
||||
for (x = 1; x < screenWidth; x++) {
|
||||
for (y = 1; y < 240; y++) {
|
||||
u32 v=(y + x * 240) * 3;
|
||||
bufAdr[v] = b;
|
||||
bufAdr[v+1] = g;
|
||||
bufAdr[v+2] = r;
|
||||
}
|
||||
for (int i = 0; i < screenWidth * screenHeight * 3; i += 3) {
|
||||
bufAdr[i] = b;
|
||||
bufAdr[i+1] = g;
|
||||
bufAdr[i+2] = r;
|
||||
}
|
||||
|
||||
x = countLines(textBuffer);
|
||||
while (x > (240 / fontDefault.height - 3)) {
|
||||
int lines = countLines(textBuffer);
|
||||
while (lines > (screenHeight / fontDefault.height - 3)) {
|
||||
deleteFirstLine(&textBuffer);
|
||||
x--;
|
||||
lines--;
|
||||
}
|
||||
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), 240 - fontDefault.height * 3, 10);
|
||||
cnt++;
|
||||
gfxDrawText(screen, GFX_LEFT, NULL, textBuffer.c_str(), screenHeight - fontDefault.height * 3, 10);
|
||||
}
|
||||
|
||||
void drawFrames()
|
||||
@ -84,7 +72,7 @@ void drawFrames()
|
||||
|
||||
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;
|
||||
char newStr[512];
|
||||
|
||||
@ -92,7 +80,7 @@ void print(gfxScreen_t screen, const char* format, ...)
|
||||
vsprintf(newStr, format, arguments);
|
||||
va_end(arguments);
|
||||
|
||||
sprintf(&textBuffer[strlen(textBuffer)], newStr);
|
||||
textBuffer += std::string(newStr);
|
||||
svcOutputDebugString(newStr, strlen(newStr));
|
||||
|
||||
drawFrames();
|
||||
@ -100,7 +88,8 @@ void print(gfxScreen_t screen, const char* format, ...)
|
||||
|
||||
void clearScreen(gfxScreen_t screen)
|
||||
{
|
||||
bufferTop[0] = 0;
|
||||
std::string& textBuffer = (screen == GFX_TOP) ? bufferTop : bufferBottom;
|
||||
textBuffer.clear();
|
||||
drawFrames();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user