mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@548 385bec56-5757-e545-9c3a-d8741f4650f1
186 lines
4.6 KiB
C++
186 lines
4.6 KiB
C++
/*---------------------------------------------------------------------------*
|
|
Project: Horizon
|
|
File: LogConsole.cpp
|
|
|
|
Copyright 2009 Nintendo. All rights reserved.
|
|
|
|
These coded instructions, statements, and computer programs contain
|
|
proprietary information of Nintendo of America Inc. and/or Nintendo
|
|
Company Ltd., and are protected by Federal copyright law. They may
|
|
not be disclosed to third parties or copied or duplicated in any form,
|
|
in whole or in part, without the prior written consent of Nintendo.
|
|
|
|
$Rev$
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
#include "LogConsole.h"
|
|
#include <nn/nstd.h>
|
|
|
|
namespace common
|
|
{
|
|
|
|
const size_t FONT_WIDTH = 8;
|
|
const size_t FONT_HEIGHT = 10;
|
|
|
|
static LogConsole s_LogConsole;
|
|
|
|
LogConsole* GetConsoleInstance()
|
|
{
|
|
return &s_LogConsole;
|
|
}
|
|
|
|
LogConsole::LogConsole()
|
|
{
|
|
|
|
}
|
|
|
|
LogConsole::~LogConsole()
|
|
{
|
|
|
|
}
|
|
|
|
void LogConsole::Initialize(u32 width, u32 height, u32 maxLine, demo::RenderSystemDrawing* renderSystem)
|
|
{
|
|
m_Width = width;
|
|
m_Height = height;
|
|
m_MaxLine = maxLine;
|
|
m_pRenderSystem = renderSystem;
|
|
m_CurrentViewLine = 0;
|
|
m_LineNum = 0;
|
|
m_ColorRed = 1.0f;
|
|
m_ColorGreen = 1.0f;
|
|
m_ColorBlue = 1.0f;
|
|
m_ColorAlpha = 1.0f;
|
|
}
|
|
|
|
void LogConsole::AddText(const char* fmt, ::std::va_list arg)
|
|
{
|
|
s32 stringSize;
|
|
const size_t STRING_BUFFER_SIZE = 256;
|
|
char formatStr[STRING_BUFFER_SIZE];
|
|
|
|
stringSize = nn::nstd::TVSNPrintf(formatStr, sizeof(formatStr), fmt, arg);
|
|
::std::string str(formatStr);
|
|
|
|
size_t addedText = 0;
|
|
while (addedText < stringSize)
|
|
{
|
|
if(m_LineNum >= m_MaxLine)
|
|
{
|
|
// 満杯なので先頭を削除する
|
|
::std::vector<LogText>::iterator it;
|
|
it = m_Log.begin();
|
|
m_Log.erase(it);
|
|
m_LineNum--;
|
|
}
|
|
|
|
// 部分文字列を追加
|
|
AddWrapedText(str.substr(addedText, m_Width).c_str());
|
|
m_LineNum++;
|
|
|
|
// 画面領域の末尾を描画中 かつ
|
|
// 画面領域以上追加したら末尾にスクロールする
|
|
if(m_CurrentViewLine == (m_LineNum - m_Height - 1) && m_LineNum > m_Height)
|
|
{
|
|
ScrollToEnd();
|
|
}
|
|
|
|
|
|
if(stringSize - addedText > m_Width)
|
|
{
|
|
addedText += m_Width;
|
|
}
|
|
else
|
|
{
|
|
addedText += stringSize - addedText;
|
|
}
|
|
}
|
|
}
|
|
|
|
void LogConsole::SetTextColor(f32 red, f32 green, f32 blue, f32 alpha)
|
|
{
|
|
m_ColorRed = red;
|
|
m_ColorGreen = green;
|
|
m_ColorBlue = blue;
|
|
m_ColorAlpha = alpha;
|
|
}
|
|
|
|
void LogConsole::ScrollUp()
|
|
{
|
|
if(m_CurrentViewLine > 0)
|
|
{
|
|
m_CurrentViewLine--;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void LogConsole::ScrollDown()
|
|
{
|
|
if (m_LineNum > m_Height)
|
|
{
|
|
if (m_CurrentViewLine < m_LineNum - m_Height)
|
|
{
|
|
m_CurrentViewLine++;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
void LogConsole::ScrollToBegin()
|
|
{
|
|
m_CurrentViewLine = 0;
|
|
}
|
|
|
|
void LogConsole::ScrollToEnd()
|
|
{
|
|
if(m_LineNum > m_Height)
|
|
{
|
|
m_CurrentViewLine = m_LineNum - m_Height;
|
|
}
|
|
}
|
|
|
|
|
|
void LogConsole::Print()
|
|
{
|
|
::std::vector<LogText>::iterator it;
|
|
|
|
it = m_Log.begin();
|
|
it += m_CurrentViewLine;
|
|
|
|
u32 count = 0;
|
|
for(; it != m_Log.end() && count < m_Height && count < m_MaxLine; it++)
|
|
{
|
|
m_pRenderSystem->SetColor(it->m_Red, it->m_Green, it->m_Blue, it->m_Alpha);
|
|
m_pRenderSystem->DrawText(0, count++ * 10, "%s", it->m_Text.c_str());
|
|
}
|
|
|
|
if(m_LineNum > m_Height)
|
|
{
|
|
DrawScrollBar();
|
|
}
|
|
}
|
|
|
|
|
|
void LogConsole::AddWrapedText(const char* str)
|
|
{
|
|
m_Log.push_back(LogText(::std::string(str), m_ColorRed, m_ColorGreen, m_ColorBlue, m_ColorAlpha));
|
|
}
|
|
|
|
void LogConsole::DrawScrollBar()
|
|
{
|
|
m_pRenderSystem->SetColor(0.4f, 0.4f, 0.4f);
|
|
m_pRenderSystem->DrawLine((m_Width + 1) * FONT_WIDTH, 0, (m_Width + 2) * FONT_WIDTH - 1, 0);
|
|
m_pRenderSystem->DrawLine((m_Width + 1)* FONT_WIDTH, 0, (m_Width + 1)* FONT_WIDTH, m_Height * FONT_HEIGHT);
|
|
m_pRenderSystem->DrawLine((m_Width + 2) * FONT_WIDTH - 1, 0, (m_Width + 2) * FONT_WIDTH - 1, m_Height * FONT_HEIGHT);
|
|
m_pRenderSystem->DrawLine((m_Width + 1)* FONT_WIDTH, m_Height * FONT_HEIGHT - 1, (m_Width + 2) * FONT_WIDTH - 1, m_Height * FONT_HEIGHT - 1);
|
|
|
|
u32 y = (m_Height * FONT_HEIGHT - 2) * m_CurrentViewLine / m_MaxLine;
|
|
m_pRenderSystem->SetColor(0.7f, 0.7f, 0.7f);
|
|
m_pRenderSystem->FillRectangle((m_Width + 1) * FONT_WIDTH, y + 1, FONT_WIDTH - 1, FONT_HEIGHT - 4);
|
|
|
|
m_pRenderSystem->SetColor(1.f, 1.f, 1.f);
|
|
}
|
|
|
|
} //namespace ConsoleBackup
|