mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 10:59:47 -05:00
Add the ability to DashboardItemSimulationIncrement and DashboardItemDistance to specify fixed unit
This commit is contained in:
@@ -90,6 +90,26 @@ namespace {
|
||||
"km, AU, light years, parsecs, etc. If this value is disabled, it is always "
|
||||
"displayed in meters."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo RequestedUnitInfo = {
|
||||
"RequestedUnit",
|
||||
"Requested Unit",
|
||||
"If the simplification is disabled, this distance unit is used as a destination "
|
||||
"to convert the meters into."
|
||||
};
|
||||
|
||||
std::vector<std::string> unitList() {
|
||||
std::vector<std::string> res(openspace::DistanceUnits.size());
|
||||
std::transform(
|
||||
openspace::DistanceUnits.begin(),
|
||||
openspace::DistanceUnits.end(),
|
||||
res.begin(),
|
||||
[](openspace::DistanceUnit unit) -> std::string {
|
||||
return nameForDistanceUnit(unit);
|
||||
}
|
||||
);
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -150,6 +170,12 @@ documentation::Documentation DashboardItemDistance::Documentation() {
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
SimplificationInfo.description
|
||||
},
|
||||
{
|
||||
RequestedUnitInfo.identifier,
|
||||
new StringInListVerifier(unitList()),
|
||||
Optional::Yes,
|
||||
RequestedUnitInfo.description
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -160,6 +186,7 @@ DashboardItemDistance::DashboardItemDistance(ghoul::Dictionary dictionary)
|
||||
, _fontName(FontNameInfo, KeyFontMono)
|
||||
, _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f)
|
||||
, _doSimplification(SimplificationInfo, true)
|
||||
, _requestedUnit(RequestedUnitInfo, properties::OptionProperty::DisplayType::Dropdown)
|
||||
, _source{
|
||||
properties::OptionProperty(
|
||||
SourceTypeInfo,
|
||||
@@ -306,8 +333,28 @@ DashboardItemDistance::DashboardItemDistance(ghoul::Dictionary dictionary)
|
||||
if (dictionary.hasKey(SimplificationInfo.identifier)) {
|
||||
_doSimplification = dictionary.value<bool>(SimplificationInfo.identifier);
|
||||
}
|
||||
_doSimplification.onChange([this]() {
|
||||
if (_doSimplification) {
|
||||
_requestedUnit.setVisibility(properties::Property::Visibility::Hidden);
|
||||
}
|
||||
else {
|
||||
_requestedUnit.setVisibility(properties::Property::Visibility::User);
|
||||
}
|
||||
});
|
||||
addProperty(_doSimplification);
|
||||
|
||||
for (DistanceUnit u : DistanceUnits) {
|
||||
_requestedUnit.addOption(static_cast<int>(u), nameForDistanceUnit(u));
|
||||
}
|
||||
_requestedUnit = static_cast<int>(DistanceUnit::Meter);
|
||||
if (dictionary.hasKey(RequestedUnitInfo.identifier)) {
|
||||
std::string value = dictionary.value<std::string>(RequestedUnitInfo.identifier);
|
||||
DistanceUnit unit = distanceUnitFromString(value);
|
||||
_requestedUnit = static_cast<int>(unit);
|
||||
}
|
||||
_requestedUnit.setVisibility(properties::Property::Visibility::Hidden);
|
||||
addProperty(_requestedUnit);
|
||||
|
||||
_font = OsEng.fontManager().font(_fontName, _fontSize);
|
||||
}
|
||||
|
||||
@@ -375,10 +422,15 @@ void DashboardItemDistance::render(glm::vec2& penPosition) {
|
||||
);
|
||||
|
||||
double d = glm::length(sourceInfo.first - destinationInfo.first);
|
||||
std::pair<double, std::string> dist =
|
||||
_doSimplification.value() ?
|
||||
simplifyDistance(d) :
|
||||
std::make_pair(d, d == 1.0 ? std::string("meter") : std::string("meters"));
|
||||
std::pair<double, std::string> dist;
|
||||
if (_doSimplification) {
|
||||
dist = simplifyDistance(d);
|
||||
}
|
||||
else {
|
||||
DistanceUnit unit = static_cast<DistanceUnit>(_requestedUnit.value());
|
||||
double convertedD = convertDistance(d, unit);
|
||||
dist = { convertedD, nameForDistanceUnit(unit, convertedD != 1.0) };
|
||||
}
|
||||
|
||||
penPosition.y -= _font->height();
|
||||
RenderFont(
|
||||
@@ -394,10 +446,15 @@ void DashboardItemDistance::render(glm::vec2& penPosition) {
|
||||
|
||||
glm::vec2 DashboardItemDistance::size() const {
|
||||
double d = glm::length(1e20);
|
||||
std::pair<double, std::string> dist =
|
||||
_doSimplification.value() ?
|
||||
simplifyDistance(d) :
|
||||
std::make_pair(d, d == 1.0 ? std::string("meter") : std::string("meters"));
|
||||
std::pair<double, std::string> dist;
|
||||
if (_doSimplification) {
|
||||
dist = simplifyDistance(d);
|
||||
}
|
||||
else {
|
||||
DistanceUnit unit = static_cast<DistanceUnit>(_requestedUnit.value());
|
||||
double convertedD = convertDistance(d, unit);
|
||||
dist = { convertedD, nameForDistanceUnit(unit, convertedD != 1.0) };
|
||||
}
|
||||
|
||||
return ghoul::fontrendering::FontRenderer::defaultRenderer().boundingBox(
|
||||
*_font,
|
||||
|
||||
@@ -73,6 +73,7 @@ private:
|
||||
properties::StringProperty _fontName;
|
||||
properties::FloatProperty _fontSize;
|
||||
properties::BoolProperty _doSimplification;
|
||||
properties::OptionProperty _requestedUnit;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -57,6 +57,26 @@ namespace {
|
||||
"minutes, hours, days, years, etc. If this value is disabled, it is always "
|
||||
"displayed in seconds."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo RequestedUnitInfo = {
|
||||
"RequestedUnit",
|
||||
"Requested Unit",
|
||||
"If the simplification is disabled, this time unit is used as a destination to "
|
||||
"convert the seconds into."
|
||||
};
|
||||
|
||||
std::vector<std::string> unitList() {
|
||||
std::vector<std::string> res(openspace::TimeUnits.size());
|
||||
std::transform(
|
||||
openspace::TimeUnits.begin(),
|
||||
openspace::TimeUnits.end(),
|
||||
res.begin(),
|
||||
[](openspace::TimeUnit unit) -> std::string {
|
||||
return nameForTimeUnit(unit);
|
||||
}
|
||||
);
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -89,6 +109,12 @@ documentation::Documentation DashboardItemSimulationIncrement::Documentation() {
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
SimplificationInfo.description
|
||||
},
|
||||
{
|
||||
RequestedUnitInfo.identifier,
|
||||
new StringInListVerifier(unitList()),
|
||||
Optional::Yes,
|
||||
RequestedUnitInfo.description
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -100,6 +126,7 @@ DashboardItemSimulationIncrement::DashboardItemSimulationIncrement(
|
||||
, _fontName(FontNameInfo, KeyFontMono)
|
||||
, _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f)
|
||||
, _doSimplification(SimplificationInfo, true)
|
||||
, _requestedUnit(RequestedUnitInfo, properties::OptionProperty::DisplayType::Dropdown)
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
@@ -128,18 +155,43 @@ DashboardItemSimulationIncrement::DashboardItemSimulationIncrement(
|
||||
if (dictionary.hasKey(SimplificationInfo.identifier)) {
|
||||
_doSimplification = dictionary.value<bool>(SimplificationInfo.identifier);
|
||||
}
|
||||
_doSimplification.onChange([this]() {
|
||||
if (_doSimplification) {
|
||||
_requestedUnit.setVisibility(properties::Property::Visibility::Hidden);
|
||||
}
|
||||
else {
|
||||
_requestedUnit.setVisibility(properties::Property::Visibility::User);
|
||||
}
|
||||
});
|
||||
addProperty(_doSimplification);
|
||||
|
||||
for (TimeUnit u : TimeUnits) {
|
||||
_requestedUnit.addOption(static_cast<int>(u), nameForTimeUnit(u));
|
||||
}
|
||||
_requestedUnit = static_cast<int>(TimeUnit::Second);
|
||||
if (dictionary.hasKey(RequestedUnitInfo.identifier)) {
|
||||
std::string value = dictionary.value<std::string>(RequestedUnitInfo.identifier);
|
||||
TimeUnit unit = timeUnitFromString(value);
|
||||
_requestedUnit = static_cast<int>(unit);
|
||||
}
|
||||
_requestedUnit.setVisibility(properties::Property::Visibility::Hidden);
|
||||
addProperty(_requestedUnit);
|
||||
|
||||
_font = OsEng.fontManager().font(_fontName, _fontSize);
|
||||
}
|
||||
|
||||
void DashboardItemSimulationIncrement::render(glm::vec2& penPosition) {
|
||||
double t = OsEng.timeManager().time().deltaTime();
|
||||
std::pair<double, std::string> deltaTime =
|
||||
_doSimplification.value() ?
|
||||
simplifyTime(t) :
|
||||
std::make_pair(t, t == 1.0 ? std::string("second") : std::string("seconds"));
|
||||
|
||||
std::pair<double, std::string> deltaTime;
|
||||
if (_doSimplification) {
|
||||
deltaTime = simplifyTime(t);
|
||||
}
|
||||
else {
|
||||
TimeUnit unit = static_cast<TimeUnit>(_requestedUnit.value());
|
||||
double convertedT = convertTime(t, unit);
|
||||
deltaTime = { convertedT, nameForTimeUnit(unit, convertedT != 1.0) };
|
||||
}
|
||||
|
||||
penPosition.y -= _font->height();
|
||||
RenderFont(
|
||||
*_font,
|
||||
@@ -152,10 +204,15 @@ void DashboardItemSimulationIncrement::render(glm::vec2& penPosition) {
|
||||
|
||||
glm::vec2 DashboardItemSimulationIncrement::size() const {
|
||||
double t = OsEng.timeManager().time().deltaTime();
|
||||
std::pair<double, std::string> deltaTime =
|
||||
_doSimplification.value() ?
|
||||
simplifyTime(t) :
|
||||
std::make_pair(t, t == 1.0 ? std::string("seconds") : std::string("second"));
|
||||
std::pair<double, std::string> deltaTime;
|
||||
if (_doSimplification) {
|
||||
deltaTime = simplifyTime(t);
|
||||
}
|
||||
else {
|
||||
TimeUnit unit = static_cast<TimeUnit>(_requestedUnit.value());
|
||||
double convertedT = convertTime(t, unit);
|
||||
deltaTime = { convertedT, nameForTimeUnit(unit, convertedT != 1.0) };
|
||||
}
|
||||
|
||||
return ghoul::fontrendering::FontRenderer::defaultRenderer().boundingBox(
|
||||
*_font,
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
@@ -53,6 +54,7 @@ private:
|
||||
properties::StringProperty _fontName;
|
||||
properties::FloatProperty _fontSize;
|
||||
properties::BoolProperty _doSimplification;
|
||||
properties::OptionProperty _requestedUnit;
|
||||
|
||||
std::shared_ptr<ghoul::fontrendering::Font> _font;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user