ctr_Repair/trunk/ConsoleDataMigration/sources/common/DrawSystemState.cpp
N2614 9e8a601585 ハードウェア状態に依存する処理を分離
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@223 385bec56-5757-e545-9c3a-d8741f4650f1
2011-04-26 09:46:49 +00:00

188 lines
6.1 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 <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];
bit64 s_DeviceId;
char8 s_MacAddress[nn::nwm::Mac::MAC_STRING_SIZE];
u64 s_FriendCode;
u8 s_BatteryRemain;
std::string s_AdapterState;
u8 s_Progress;
::std::vector<std::string>* s_OperationMessage;
}
u32 GetRenderTarget(u32 target, bool flip)
{
if(flip)
{
if(target == NN_GX_DISPLAY0)
{
return NN_GX_DISPLAY1;
}
else
{
return NN_GX_DISPLAY0;
}
}
else
{
return target;
}
}
void SetTextWriterCore()
{
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 %llu\n", s_DeviceId);
GetTextWriter()->Printf("MAC Address %s\n", s_MacAddress);
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 Adaper %s\n", s_AdapterState.c_str());
GetTextWriter()->Printf("Progress %02d%%\n", s_Progress);
GetTextWriter()->Print("\n");
::std::vector<std::string>::iterator it;
for (it = s_OperationMessage->begin(); it != s_OperationMessage->end(); it++)
{
GetTextWriter()->Printf("%s\n", it->c_str());
}
}
void DrawSystemState
(
const char* toolName,
demo::RenderSystemDrawing& renderSystem,
nn::util::FloatColor titleColor,
bool flip,
std::string& adapterState,
const char* toolVersion,
u8 cupMajorVersion,
u8 cupMinorVersion,
u8 cupMicroVersion,
u8 nupVersion,
u8 batteryRemain,
u64 deviceId,
u64 friendCode,
u32 progress,
bool isBackupFailed,
bool isBackupSucceeded,
char8* macAddress,
::std::vector<std::string>& operationMessage,
nn::cfg::CTR::CfgRegionCode region,
u8* serialNo
)
{
// パラメータ保存
s_AdapterState = adapterState;
s_CupMajor = cupMajorVersion;
s_CupMinor = cupMinorVersion;
s_CupMicro = cupMicroVersion;
s_NupMajor = nupVersion;
s_BatteryRemain = batteryRemain;
s_DeviceId = deviceId;
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;
// デフォルトで上画面に描画するもの
renderSystem.SetRenderTarget(GetRenderTarget(NN_GX_DISPLAY0, flip));
if (isBackupSucceeded)
{
renderSystem.SetClearColor(GetRenderTarget(NN_GX_DISPLAY0, flip), SUCCESS_COLOR);
}
else if (isBackupFailed)
{
renderSystem.SetClearColor(GetRenderTarget(NN_GX_DISPLAY0, flip), FAIL_COLOR);
}
else
{
renderSystem.SetClearColor(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(GetRenderTarget(NN_GX_DISPLAY0, flip));
renderSystem.SetFontSize(fontwidth);
// ツール名、ハイライト
renderSystem.DrawText(0, line++ * fontheight, "%s %s Rev.%s", toolName, __DATE__, toolVersion);
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;
line += 9;
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, "");
}
}