Restructure DashboardItems

- Add a new class DashboardTextItem that is a DashboardItem that can render text with font
This commit is contained in:
Alexander Bock
2020-12-09 00:44:25 +01:00
parent 9c0aecba80
commit eb69d2219a
23 changed files with 107 additions and 640 deletions
@@ -37,22 +37,6 @@
#include <stack>
namespace {
constexpr const char* KeyFontMono = "Mono";
constexpr const float DefaultFontSize = 15.f;
constexpr openspace::properties::Property::PropertyInfo FontNameInfo = {
"FontName",
"Font Name",
"This value is the name of the font that is used. It can either refer to an "
"internal name registered previously, or it can refer to a path that is used."
};
constexpr openspace::properties::Property::PropertyInfo FontSizeInfo = {
"FontSize",
"Font Size",
"This value determines the size of the font that is used to render the date."
};
std::string progressToStr(int size, double t) {
std::string progress = "|";
int g = static_cast<int>((t * (size - 1)) + 1);
@@ -72,62 +56,9 @@ namespace {
namespace openspace {
documentation::Documentation DashboardItemMission::Documentation() {
using namespace documentation;
return {
"DashboardItem Mission",
"base_dashboarditem_mission",
{
{
"Type",
new StringEqualVerifier("DashboardItemMission"),
Optional::No
},
{
FontNameInfo.identifier,
new StringVerifier,
Optional::Yes,
FontNameInfo.description
},
{
FontSizeInfo.identifier,
new IntVerifier,
Optional::Yes,
FontSizeInfo.description
}
}
};
}
DashboardItemMission::DashboardItemMission(const ghoul::Dictionary& dictionary)
: DashboardItem(dictionary)
, _fontName(FontNameInfo, KeyFontMono)
, _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f)
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"DashboardItemMission"
);
if (dictionary.hasKey(FontNameInfo.identifier)) {
_fontName = dictionary.value<std::string>(FontNameInfo.identifier);
}
_fontName.onChange([this](){
_font = global::fontManager->font(_fontName, _fontSize);
});
addProperty(_fontName);
if (dictionary.hasKey(FontSizeInfo.identifier)) {
_fontSize = static_cast<float>(dictionary.value<double>(FontSizeInfo.identifier));
}
_fontSize.onChange([this](){
_font = global::fontManager->font(_fontName, _fontSize);
});
addProperty(_fontSize);
_font = global::fontManager->font(_fontName, _fontSize);
}
: DashboardTextItem(dictionary, 15.f)
{}
void DashboardItemMission::render(glm::vec2& penPosition) {
ZoneScoped