2014-10-29 23:07:11 -07:00
|
|
|
#include "output.h"
|
|
|
|
|
2014-11-21 22:24:04 -08:00
|
|
|
#include <cmath>
|
|
|
|
|
2014-10-29 23:07:11 -07:00
|
|
|
#include <3ds.h>
|
|
|
|
|
|
|
|
#include "text.h"
|
2014-12-10 22:24:26 -08:00
|
|
|
#include "common/string_funcs.h"
|
2014-10-29 23:07:11 -07:00
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
static std::string buffer_top;
|
|
|
|
static std::string buffer_bottom;
|
2014-10-29 23:07:11 -07:00
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
static std::string& GetTextBuffer(gfxScreen_t screen)
|
2014-10-29 23:07:11 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
switch (screen) {
|
|
|
|
case GFX_TOP: return buffer_top;
|
|
|
|
case GFX_BOTTOM: return buffer_bottom;
|
2014-11-21 22:24:04 -08:00
|
|
|
}
|
2014-12-10 22:24:26 -08:00
|
|
|
return buffer_top;
|
2014-10-29 23:07:11 -07:00
|
|
|
}
|
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
static void DrawFrame(gfxScreen_t screen, char b, char g, char r)
|
2014-10-29 23:07:11 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
int screen_height = 240;
|
|
|
|
int screen_width = (screen == GFX_TOP) ? 400 : 320;
|
|
|
|
std::string& text_buffer = GetTextBuffer(screen);
|
|
|
|
|
|
|
|
u8* fb_addr = gfxGetFramebuffer(screen, GFX_LEFT, nullptr, nullptr);
|
|
|
|
for (int i = 0; i < screen_width * screen_height * 3; i += 3) {
|
|
|
|
fb_addr[i] = b;
|
|
|
|
fb_addr[i+1] = g;
|
|
|
|
fb_addr[i+2] = r;
|
2014-11-22 00:58:29 -08:00
|
|
|
}
|
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
int lines = Common::CountLines(text_buffer);
|
|
|
|
while (lines > (screen_height / fontDefault.height - 3)) {
|
|
|
|
Common::DeleteFirstLine(&text_buffer);
|
2014-11-22 12:38:59 -08:00
|
|
|
lines--;
|
2014-11-22 00:58:29 -08:00
|
|
|
}
|
2014-12-10 22:24:26 -08:00
|
|
|
gfxDrawText(screen, GFX_LEFT, nullptr, text_buffer, screen_height - fontDefault.height * 3, 10);
|
2014-10-31 22:20:21 -07:00
|
|
|
}
|
2014-10-29 23:07:11 -07:00
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
void DrawFrames()
|
2014-10-31 22:20:21 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
DrawFrame(GFX_TOP, 0x88, 0x66, 0x00);
|
|
|
|
DrawFrame(GFX_BOTTOM, 0x00, 0x00, 0x00);
|
2014-11-22 00:58:29 -08:00
|
|
|
gfxFlushBuffers();
|
|
|
|
gfxSwapBuffers();
|
2014-10-29 23:07:11 -07:00
|
|
|
}
|
2014-10-30 00:25:12 -07:00
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
void Print(gfxScreen_t screen, const std::string& text)
|
2014-10-30 00:25:12 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
GetTextBuffer(screen) += text;
|
|
|
|
svcOutputDebugString(text.c_str(), text.length());
|
2014-10-30 00:25:12 -07:00
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
DrawFrames();
|
2014-10-31 22:20:21 -07:00
|
|
|
}
|
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
void ClearScreen(gfxScreen_t screen)
|
2014-10-31 22:20:21 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
GetTextBuffer(screen).clear();
|
|
|
|
DrawFrames();
|
2014-10-30 00:25:12 -07:00
|
|
|
}
|
2014-10-30 14:55:01 -07:00
|
|
|
|
2014-12-10 22:24:26 -08:00
|
|
|
void ClearScreens()
|
2014-10-30 14:55:01 -07:00
|
|
|
{
|
2014-12-10 22:24:26 -08:00
|
|
|
ClearScreen(GFX_TOP);
|
|
|
|
ClearScreen(GFX_BOTTOM);
|
2014-10-30 14:55:01 -07:00
|
|
|
}
|