ctr_Repair/trunk/ConsoleDataMigration/sources/common/DrawSystemState.cpp
N2614 707ab24a28 XボタンでデバイスIDをQRコード表示できるように
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@661 385bec56-5757-e545-9c3a-d8741f4650f1
2012-03-12 07:31:40 +00:00

195 lines
6.6 KiB
C++

/*---------------------------------------------------------------------------*
Project: Horizon
File: DrawSystemState.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 "DrawSystemState.h"
#include "ResFont.h"
#include "version.h"
#include "Util.h"
#include <nn/nwm.h>
const u16 PROGRESS_MAX_LINES = 129;
namespace common
{
namespace
{
u8 s_CupMajor;
u8 s_CupMinor;
u8 s_CupMicro;
u8 s_NupMajor;
nn::cfg::CTR::CfgRegionCode s_Region;
u8 s_SerialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN + 1];
char s_DeviceIdStr[30];
char8 s_MacAddress[nn::nwm::Mac::MAC_STRING_SIZE];
u64 s_FriendCode;
u8 s_BatteryRemain;
std::string s_AdapterState;
u8 s_Progress;
OperationMessage* s_OperationMessage;
bool s_ReadFriendCode;
}
void SetTextWriterCore()
{
GetTextWriter()->SetTextColor(nn::util::Color8(255, 255, 255, 255));
GetTextWriter()->Print("\n");
GetTextWriter()->Printf("System Ver. %d.%d.%d-%d\n", s_CupMajor, s_CupMinor, s_CupMicro, s_NupMajor);
GetTextWriter()->Printf("System Region %s\n", nn::cfg::CTR::GetRegionCodeA3(s_Region));
GetTextWriter()->Printf("Serial No. %s\n", s_SerialNo);
GetTextWriter()->Printf("Device ID %s\n", s_DeviceIdStr);
GetTextWriter()->Printf("MAC Address %s\n", s_MacAddress);
if (s_ReadFriendCode)
{
GetTextWriter()->Printf("Friend Code %04u-%04u-%04u\n",
static_cast<u32>(s_FriendCode / 100000000ULL % 10000ULL), static_cast<u32> (s_FriendCode / 10000ULL % 10000ULL),
static_cast<u32> (s_FriendCode % 10000ULL));
}
GetTextWriter()->Printf("Battery %d%%\n", s_BatteryRemain);
GetTextWriter()->Printf("AC Adapter %s\n", s_AdapterState.c_str());
GetTextWriter()->Printf("Progress %02d%%\n", s_Progress);
GetTextWriter()->Print("\n");
for (u32 i = 0; i < s_OperationMessage->GetSize(); i++)
{
GetTextWriter()->SetTextColor(s_OperationMessage->At(i).color);
GetTextWriter()->Printf("%s\n", s_OperationMessage->At(i).str.c_str());
}
}
void DrawSystemState
(
const char* toolName,
demo::RenderSystemDrawing& renderSystem,
nn::util::FloatColor titleColor,
bool flip,
std::string& adapterState,
u8 cupMajorVersion,
u8 cupMinorVersion,
u8 cupMicroVersion,
u8 nupVersion,
u8 batteryRemain,
u64 deviceId,
u64 friendCode,
u32 progress,
bool isProcessFailed,
bool isProcessSucceeded,
bool isProcessWarning,
char8* macAddress,
OperationMessage& operationMessage,
nn::cfg::CTR::CfgRegionCode region,
u8* serialNo,
bool readFriendCode
)
{
// パラメータ保存
s_AdapterState = adapterState;
s_CupMajor = cupMajorVersion;
s_CupMinor = cupMinorVersion;
s_CupMicro = cupMicroVersion;
s_NupMajor = nupVersion;
s_BatteryRemain = batteryRemain;
nn::nstd::TSNPrintf(s_DeviceIdStr, sizeof(s_DeviceIdStr), "%llu", deviceId);
std::string deviceIdString(s_DeviceIdStr);
Util::SplitDeviceidWithSpace(deviceIdString);
std::memcpy(s_DeviceIdStr, deviceIdString.c_str(), deviceIdString.size());
s_FriendCode = friendCode;
s_Progress = progress;
std::memcpy(s_MacAddress, macAddress, sizeof(s_MacAddress));
s_Region = region;
std::memcpy(s_SerialNo, serialNo, sizeof(s_SerialNo));
s_SerialNo[nn::cfg::CTR::CFG_SECURE_INFO_SERIAL_NO_LEN] = '\0';
s_OperationMessage = &operationMessage;
s_ReadFriendCode = readFriendCode;
// デフォルトで上画面に描画するもの
renderSystem.SetRenderTarget(Util::GetRenderTarget(NN_GX_DISPLAY0, flip));
if (isProcessSucceeded)
{
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), SUCCESS_COLOR);
}
else if (isProcessWarning)
{
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), WARN_COLOR);
}
else if (isProcessFailed)
{
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), FAIL_COLOR);
}
else
{
renderSystem.SetClearColor(Util::GetRenderTarget(NN_GX_DISPLAY0, flip), NORMAL_COLOR);
}
renderSystem.Clear();
renderSystem.SetColor(1.f, 1.f, 1.f);
u32 line = 0;
size_t fontwidth = 8;
size_t fontheight = fontwidth + 2;
SetDrawTextHandler(SetTextWriterCore);
DrawResFont(Util::GetRenderTarget(NN_GX_DISPLAY0, flip));
renderSystem.SetFontSize(fontwidth);
// ツール名、ハイライト
renderSystem.DrawText(0, line++ * fontheight, "%s %s-%s-%s", toolName, CONSOLE_REPAIR_VERSION_MAJOR,
CONSOLE_REPAIR_VERSION_MINOR, CONSOLE_REPAIR_VERSION_MICRO);
renderSystem.SetColor(titleColor.r, titleColor.g, titleColor.b);
renderSystem.FillRectangle(0, (line - 1) * fontheight, 400, fontheight);
renderSystem.SetColor(1.f, 1.f, 1.f);
renderSystem.DrawText(0, line++ * fontheight, "");
// プログレスバー
fontwidth = 8;
fontheight = 14;
if(readFriendCode)
{
line += 9;
}
else
{
line += 8;
}
const u8 offset = 19;
const u8 diff = 4;
renderSystem.SetColor(0.f, 0.2f, 0.f);
renderSystem.DrawLine(offset * fontwidth, (line - 1) * fontheight - diff, offset * fontwidth + PROGRESS_MAX_LINES, (line - 1)
* fontheight - diff);
renderSystem.DrawLine(offset * fontwidth, (line - 1) * fontheight - diff, offset * fontwidth, (line) * fontheight - diff);
renderSystem.DrawLine(offset * fontwidth, (line) * fontheight - diff, offset * fontwidth + PROGRESS_MAX_LINES, (line) * fontheight - diff);
renderSystem.DrawLine(offset * fontwidth + PROGRESS_MAX_LINES, (line - 1) * fontheight - diff, offset * fontwidth
+ PROGRESS_MAX_LINES, (line) * fontheight + 1 - diff);
renderSystem.SetColor(0.f, 0.5f, 0.f);
renderSystem.FillRectangle(offset * fontwidth, (line - 1) * fontheight - diff, progress * PROGRESS_MAX_LINES / 100 + 1,
fontheight);
renderSystem.SetColor(1.f, 1.f, 1.f);
renderSystem.DrawText(0, line++ * fontheight, "");
}
}