Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CChart.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | CSize CChart::AddFormattedValue(const CStrW& format, const float value, const CStrW& font, const float buffer_zone) | ||||
{ | { | ||||
wchar_t buffer[64]; | wchar_t buffer[64]; | ||||
swprintf(buffer, 64, L"%.2f", value); | swprintf(buffer, 64, L"%.2f", value); | ||||
gui_str.SetValue(buffer); | gui_str.SetValue(buffer); | ||||
} | } | ||||
else if (format == L"INTEGER") | else if (format == L"INTEGER") | ||||
{ | { | ||||
wchar_t buffer[64]; | wchar_t buffer[64]; | ||||
swprintf(buffer, 64, L"%d", static_cast<int>(value)); | swprintf(buffer, 64, L"%d", std::lround(value)); | ||||
gui_str.SetValue(buffer); | gui_str.SetValue(buffer); | ||||
} | } | ||||
else if (format == L"DURATION_SHORT") | else if (format == L"DURATION_SHORT") | ||||
{ | { | ||||
const int seconds = value; | const int seconds = value; | ||||
wchar_t buffer[64]; | wchar_t buffer[64]; | ||||
swprintf(buffer, 64, L"%d:%02d", seconds / 60, seconds % 60); | swprintf(buffer, 64, L"%d:%02d", seconds / 60, seconds % 60); | ||||
gui_str.SetValue(buffer); | gui_str.SetValue(buffer); | ||||
} | } | ||||
else if (format == L"PERCENTAGE") | |||||
{ | |||||
wchar_t buffer[64]; | |||||
swprintf(buffer, 64, L"%d%%", std::lround(value)); | |||||
gui_str.SetValue(buffer); | |||||
} | |||||
else | else | ||||
{ | { | ||||
LOGERROR("Unsupported chart format: " + format.EscapeToPrintableASCII()); | LOGERROR("Unsupported chart format: " + format.EscapeToPrintableASCII()); | ||||
return CSize(); | return CSize(); | ||||
} | } | ||||
SGUIText* text = new SGUIText(); | SGUIText* text = new SGUIText(); | ||||
*text = GetGUI()->GenerateText(gui_str, font, 0, buffer_zone, this); | *text = GetGUI()->GenerateText(gui_str, font, 0, buffer_zone, this); | ||||
AddText(text); | AddText(text); | ||||
Show All 33 Lines |
Wildfire Games · Phabricator