diff --git a/include/openspace/rendering/dashboarditem.h b/include/openspace/rendering/dashboarditem.h index e33467a555..e51faf6a11 100644 --- a/include/openspace/rendering/dashboarditem.h +++ b/include/openspace/rendering/dashboarditem.h @@ -28,9 +28,12 @@ #include #include +#include +#include #include namespace ghoul { class Dictionary; } +namespace ghoul::fontrendering { class Font; } namespace openspace { @@ -55,6 +58,22 @@ protected: properties::BoolProperty _isEnabled; }; + + +class DashboardTextItem : public DashboardItem { +public: + static documentation::Documentation Documentation(); + + DashboardTextItem(const ghoul::Dictionary& dictionary, float fontSize = 10.f, + const std::string& fontName = "Mono"); + +protected: + properties::StringProperty _fontName; + properties::FloatProperty _fontSize; + + std::shared_ptr _font; +}; + } // openspace #endif // __OPENSPACE_CORE___DASHBOARDITEM___H__ diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index fca97888c9..13a9679993 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -195,7 +195,6 @@ std::vector BaseModule::documentations() const { DashboardItemDistance::Documentation(), DashboardItemFramerate::Documentation(), DashboardItemMission::Documentation(), - DashboardItemParallelConnection::Documentation(), DashboardItemSimulationIncrement::Documentation(), DashboardItemSpacing::Documentation(), DashboardItemVelocity::Documentation(), diff --git a/modules/base/dashboard/dashboarditemangle.cpp b/modules/base/dashboard/dashboarditemangle.cpp index 6ad0945c11..103ce82d57 100644 --- a/modules/base/dashboard/dashboarditemangle.cpp +++ b/modules/base/dashboard/dashboarditemangle.cpp @@ -40,23 +40,6 @@ #include namespace { - constexpr const char* KeyFontMono = "Mono"; - - constexpr const float DefaultFontSize = 10.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." - }; - constexpr openspace::properties::Property::PropertyInfo SourceTypeInfo = { "SourceType", "Source Type", @@ -118,18 +101,6 @@ documentation::Documentation DashboardItemAngle::Documentation() { new StringEqualVerifier("DashboardItemAngle"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { SourceTypeInfo.identifier, new StringInListVerifier({ @@ -177,7 +148,7 @@ documentation::Documentation DashboardItemAngle::Documentation() { } DashboardItemAngle::DashboardItemAngle(const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) + : DashboardTextItem(dictionary) , _source{ properties::OptionProperty( SourceTypeInfo, @@ -202,8 +173,6 @@ DashboardItemAngle::DashboardItemAngle(const ghoul::Dictionary& dictionary) properties::StringProperty(DestinationNodeNameInfo), nullptr } - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) { documentation::testSpecificationAndThrow( Documentation(), @@ -211,23 +180,6 @@ DashboardItemAngle::DashboardItemAngle(const ghoul::Dictionary& dictionary) "DashboardItemAngle" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - - _fontName.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - _fontSize.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - _source.type.addOptions({ { Type::Node, "Node" }, { Type::Focus, "Focus" }, @@ -352,7 +304,6 @@ DashboardItemAngle::DashboardItemAngle(const ghoul::Dictionary& dictionary) } addProperty(_destination.nodeName); - _font = global::fontManager->font(_fontName, _fontSize); _buffer.resize(128); } diff --git a/modules/base/dashboard/dashboarditemangle.h b/modules/base/dashboard/dashboarditemangle.h index 111f1a8a79..f7f450c57f 100644 --- a/modules/base/dashboard/dashboarditemangle.h +++ b/modules/base/dashboard/dashboarditemangle.h @@ -29,18 +29,15 @@ #include #include -#include #include -namespace ghoul::fontrendering { class Font; } - namespace openspace { class SceneGraphNode; namespace documentation { struct Documentation; } -class DashboardItemAngle : public DashboardItem { +class DashboardItemAngle : public DashboardTextItem { public: DashboardItemAngle(const ghoul::Dictionary& dictionary); virtual ~DashboardItemAngle() = default; @@ -70,11 +67,7 @@ private: Component _reference; Component _destination; - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; - std::vector _buffer; - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditemdate.cpp b/modules/base/dashboard/dashboarditemdate.cpp index cdd8e7ba52..1534e052af 100644 --- a/modules/base/dashboard/dashboarditemdate.cpp +++ b/modules/base/dashboard/dashboarditemdate.cpp @@ -36,22 +36,6 @@ #include 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." - }; - constexpr openspace::properties::Property::PropertyInfo FormatStringInfo = { "FormatString", "Format String", @@ -82,18 +66,6 @@ documentation::Documentation DashboardItemDate::Documentation() { new StringEqualVerifier("DashboardItemDate"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { FormatStringInfo.identifier, new StringVerifier, @@ -111,9 +83,7 @@ documentation::Documentation DashboardItemDate::Documentation() { } DashboardItemDate::DashboardItemDate(const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + : DashboardTextItem(dictionary, 15.f) , _formatString(FormatStringInfo, "Date: {} UTC") , _timeFormat(TimeFormatInfo, "YYYY MON DDTHR:MN:SC.### ::RND") { @@ -123,22 +93,6 @@ DashboardItemDate::DashboardItemDate(const ghoul::Dictionary& dictionary) "DashboardItemDate" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - _fontName.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - _fontSize.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - if (dictionary.hasKey(FormatStringInfo.identifier)) { _formatString = dictionary.value(FormatStringInfo.identifier); } @@ -148,8 +102,6 @@ DashboardItemDate::DashboardItemDate(const ghoul::Dictionary& dictionary) _timeFormat = dictionary.value(TimeFormatInfo.identifier); } addProperty(_timeFormat); - - _font = global::fontManager->font(_fontName, _fontSize); } void DashboardItemDate::render(glm::vec2& penPosition) { diff --git a/modules/base/dashboard/dashboarditemdate.h b/modules/base/dashboard/dashboarditemdate.h index 81e7c754e1..80be357f13 100644 --- a/modules/base/dashboard/dashboarditemdate.h +++ b/modules/base/dashboard/dashboarditemdate.h @@ -28,15 +28,12 @@ #include #include -#include - -namespace ghoul::fontrendering { class Font; } namespace openspace { namespace documentation { struct Documentation; } -class DashboardItemDate : public DashboardItem { +class DashboardItemDate : public DashboardTextItem { public: DashboardItemDate(const ghoul::Dictionary& dictionary); ~DashboardItemDate() = default; @@ -48,12 +45,8 @@ public: static documentation::Documentation Documentation(); private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; properties::StringProperty _formatString; properties::StringProperty _timeFormat; - - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditemdistance.cpp b/modules/base/dashboard/dashboarditemdistance.cpp index 1c36425646..38632b97ee 100644 --- a/modules/base/dashboard/dashboarditemdistance.cpp +++ b/modules/base/dashboard/dashboarditemdistance.cpp @@ -41,23 +41,6 @@ #include namespace { - constexpr const char* KeyFontMono = "Mono"; - - constexpr const float DefaultFontSize = 10.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 distance." - }; - constexpr openspace::properties::Property::PropertyInfo SourceTypeInfo = { "SourceType", "Source Type", @@ -136,18 +119,6 @@ documentation::Documentation DashboardItemDistance::Documentation() { new StringEqualVerifier("DashboardItemDistance"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { SourceTypeInfo.identifier, new StringInListVerifier({ @@ -199,9 +170,7 @@ documentation::Documentation DashboardItemDistance::Documentation() { } DashboardItemDistance::DashboardItemDistance(const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + : DashboardTextItem(dictionary) , _doSimplification(SimplificationInfo, true) , _requestedUnit(RequestedUnitInfo, properties::OptionProperty::DisplayType::Dropdown) , _source{ @@ -228,23 +197,6 @@ DashboardItemDistance::DashboardItemDistance(const ghoul::Dictionary& dictionary "DashboardItemDistance" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - - _fontName.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - _fontSize.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - _source.type.addOptions({ { Type::Node, "Node" }, { Type::NodeSurface, "Node Surface" }, @@ -378,8 +330,6 @@ DashboardItemDistance::DashboardItemDistance(const ghoul::Dictionary& dictionary } addProperty(_formatString); - _font = global::fontManager->font(_fontName, _fontSize); - _buffer.resize(256); } diff --git a/modules/base/dashboard/dashboarditemdistance.h b/modules/base/dashboard/dashboarditemdistance.h index 8ac5d5f926..6e95e097fc 100644 --- a/modules/base/dashboard/dashboarditemdistance.h +++ b/modules/base/dashboard/dashboarditemdistance.h @@ -30,18 +30,15 @@ #include #include #include -#include #include -namespace ghoul::fontrendering { class Font; } - namespace openspace { class SceneGraphNode; namespace documentation { struct Documentation; } -class DashboardItemDistance : public DashboardItem { +class DashboardItemDistance : public DashboardTextItem { public: DashboardItemDistance(const ghoul::Dictionary& dictionary); virtual ~DashboardItemDistance() = default; @@ -71,8 +68,6 @@ private: std::pair positionAndLabel(Component& mainComp, Component& otherComp) const; - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; properties::BoolProperty _doSimplification; properties::OptionProperty _requestedUnit; properties::StringProperty _formatString; @@ -81,8 +76,6 @@ private: Component _destination; std::vector _buffer; - - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditemframerate.cpp b/modules/base/dashboard/dashboarditemframerate.cpp index 8453ce627a..1f38996ffb 100644 --- a/modules/base/dashboard/dashboarditemframerate.cpp +++ b/modules/base/dashboard/dashboarditemframerate.cpp @@ -34,22 +34,6 @@ #include namespace { - constexpr const char* KeyFontMono = "Mono"; - constexpr const float DefaultFontSize = 10.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." - }; - constexpr openspace::properties::Property::PropertyInfo FrametimeInfo = { "FrametimeType", "Type of the frame time display", @@ -165,18 +149,6 @@ documentation::Documentation DashboardItemFramerate::Documentation() { new StringEqualVerifier("DashboardItemFramerate"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { FrametimeInfo.identifier, new StringInListVerifier({ ValueDtAvg, ValueDtExtremes, @@ -190,9 +162,7 @@ documentation::Documentation DashboardItemFramerate::Documentation() { } DashboardItemFramerate::DashboardItemFramerate(const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + : DashboardTextItem(dictionary) , _frametimeType(FrametimeInfo, properties::OptionProperty::DisplayType::Dropdown) , _clearCache(ClearCacheInfo) { @@ -202,24 +172,6 @@ DashboardItemFramerate::DashboardItemFramerate(const ghoul::Dictionary& dictiona "DashboardItemFramerate" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - _fontName.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast( - dictionary.value(FontSizeInfo.identifier) - ); - } - _fontSize.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - _frametimeType.addOptions({ { static_cast(FrametimeType::DtTimeAvg), ValueDtAvg }, { static_cast(FrametimeType::DtTimeExtremes), ValueDtExtremes }, @@ -272,8 +224,6 @@ DashboardItemFramerate::DashboardItemFramerate(const ghoul::Dictionary& dictiona }); addProperty(_clearCache); - _font = global::fontManager->font(_fontName, _fontSize); - _buffer.resize(128); } diff --git a/modules/base/dashboard/dashboarditemframerate.h b/modules/base/dashboard/dashboarditemframerate.h index 8fc952f537..629a571c1b 100644 --- a/modules/base/dashboard/dashboarditemframerate.h +++ b/modules/base/dashboard/dashboarditemframerate.h @@ -28,18 +28,15 @@ #include #include -#include #include -#include namespace ghoul { class Dictionary; } -namespace ghoul::fontrendering { class Font; } namespace openspace { namespace documentation { struct Documentation; } -class DashboardItemFramerate : public DashboardItem { +class DashboardItemFramerate : public DashboardTextItem { public: enum class FrametimeType { DtTimeAvg = 0, @@ -58,13 +55,9 @@ public: static documentation::Documentation Documentation(); private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; properties::OptionProperty _frametimeType; properties::TriggerProperty _clearCache; - std::shared_ptr _font; - double _minDeltaTimeCache = 1.0; double _maxDeltaTimeCache = -1.0; bool _shouldClearCache = true; diff --git a/modules/base/dashboard/dashboarditemmission.cpp b/modules/base/dashboard/dashboarditemmission.cpp index 881a12b953..820df4032f 100644 --- a/modules/base/dashboard/dashboarditemmission.cpp +++ b/modules/base/dashboard/dashboarditemmission.cpp @@ -37,22 +37,6 @@ #include 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((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(FontNameInfo.identifier); - } - _fontName.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(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 diff --git a/modules/base/dashboard/dashboarditemmission.h b/modules/base/dashboard/dashboarditemmission.h index bce6364865..6a610b83ce 100644 --- a/modules/base/dashboard/dashboarditemmission.h +++ b/modules/base/dashboard/dashboarditemmission.h @@ -27,16 +27,11 @@ #include -#include -#include - -namespace ghoul::fontrendering { class Font; } - namespace openspace { namespace documentation { struct Documentation; } -class DashboardItemMission : public DashboardItem { +class DashboardItemMission : public DashboardTextItem { public: DashboardItemMission(const ghoul::Dictionary& dictionary); virtual ~DashboardItemMission() = default; @@ -44,14 +39,6 @@ public: void render(glm::vec2& penPosition) override; glm::vec2 size() const override; - - static documentation::Documentation Documentation(); - -private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; - - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditemparallelconnection.cpp b/modules/base/dashboard/dashboarditemparallelconnection.cpp index f2612c6641..8d2d1e3cad 100644 --- a/modules/base/dashboard/dashboarditemparallelconnection.cpp +++ b/modules/base/dashboard/dashboarditemparallelconnection.cpp @@ -36,83 +36,12 @@ #include #include -namespace { - constexpr const char* KeyFontMono = "Mono"; - constexpr const float DefaultFontSize = 10.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." - }; -} // namespace - namespace openspace { -documentation::Documentation DashboardItemParallelConnection::Documentation() { - using namespace documentation; - return { - "DashboardItem Parallel Connection", - "base_dashboarditem_parallelconnection", - { - { - "Type", - new StringEqualVerifier("DashboardItemParallelConnection"), - Optional::No - }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - } - } - }; -} - DashboardItemParallelConnection::DashboardItemParallelConnection( const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) -{ - documentation::testSpecificationAndThrow( - Documentation(), - dictionary, - "DashboardItemParallelConnection" - ); - - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - _fontName.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - _fontSize.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - - _font = global::fontManager->font(_fontName, _fontSize); -} + : DashboardTextItem(dictionary) +{} void DashboardItemParallelConnection::render(glm::vec2& penPosition) { ZoneScoped diff --git a/modules/base/dashboard/dashboarditemparallelconnection.h b/modules/base/dashboard/dashboarditemparallelconnection.h index 5c0bb7f1f5..27817b20ce 100644 --- a/modules/base/dashboard/dashboarditemparallelconnection.h +++ b/modules/base/dashboard/dashboarditemparallelconnection.h @@ -27,16 +27,11 @@ #include -#include -#include - -namespace ghoul::fontrendering { class Font; } - namespace openspace { namespace documentation { struct Documentation; } -class DashboardItemParallelConnection : public DashboardItem { +class DashboardItemParallelConnection : public DashboardTextItem { public: DashboardItemParallelConnection(const ghoul::Dictionary& dictionary); virtual ~DashboardItemParallelConnection() = default; @@ -44,14 +39,6 @@ public: void render(glm::vec2& penPosition) override; glm::vec2 size() const override; - - static documentation::Documentation Documentation(); - -private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; - - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditempropertyvalue.cpp b/modules/base/dashboard/dashboarditempropertyvalue.cpp index 7040b00a07..78893a791a 100644 --- a/modules/base/dashboard/dashboarditempropertyvalue.cpp +++ b/modules/base/dashboard/dashboarditempropertyvalue.cpp @@ -35,22 +35,6 @@ #include namespace { - constexpr const char* KeyFontMono = "Mono"; - constexpr const float DefaultFontSize = 10.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." - }; - constexpr openspace::properties::Property::PropertyInfo PropertyUriInfo = { "URI", "Property URI", @@ -79,18 +63,6 @@ documentation::Documentation DashboardItemPropertyValue::Documentation() { new StringEqualVerifier("DashboardItemPropertyValue"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { PropertyUriInfo.identifier, new StringVerifier, @@ -109,9 +81,7 @@ documentation::Documentation DashboardItemPropertyValue::Documentation() { DashboardItemPropertyValue::DashboardItemPropertyValue( const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + : DashboardTextItem(dictionary) , _propertyUri(PropertyUriInfo) , _displayString(DisplayStringInfo) { @@ -121,22 +91,6 @@ DashboardItemPropertyValue::DashboardItemPropertyValue( "DashboardItemPropertyValue" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - _fontName.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - _fontSize.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - if (dictionary.hasKey(PropertyUriInfo.identifier)) { _propertyUri = dictionary.value(PropertyUriInfo.identifier); } @@ -147,8 +101,6 @@ DashboardItemPropertyValue::DashboardItemPropertyValue( _displayString = dictionary.value(DisplayStringInfo.identifier); } addProperty(_displayString); - - _font = global::fontManager->font(_fontName, _fontSize); } void DashboardItemPropertyValue::render(glm::vec2& penPosition) { diff --git a/modules/base/dashboard/dashboarditempropertyvalue.h b/modules/base/dashboard/dashboarditempropertyvalue.h index 0f5a475e02..0986082a07 100644 --- a/modules/base/dashboard/dashboarditempropertyvalue.h +++ b/modules/base/dashboard/dashboarditempropertyvalue.h @@ -28,9 +28,6 @@ #include #include -#include - -namespace ghoul::fontrendering { class Font; } namespace openspace { @@ -38,7 +35,7 @@ namespace properties { class Property; } namespace documentation { struct Documentation; } -class DashboardItemPropertyValue : public DashboardItem { +class DashboardItemPropertyValue : public DashboardTextItem { public: DashboardItemPropertyValue(const ghoul::Dictionary& dictionary); ~DashboardItemPropertyValue() = default; @@ -50,16 +47,11 @@ public: static documentation::Documentation Documentation(); private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; - properties::Property* _property = nullptr; bool _propertyIsDirty = true; properties::StringProperty _propertyUri; properties::StringProperty _displayString; - - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditemsimulationincrement.cpp b/modules/base/dashboard/dashboarditemsimulationincrement.cpp index 0bf0decd45..ec5bdd3152 100644 --- a/modules/base/dashboard/dashboarditemsimulationincrement.cpp +++ b/modules/base/dashboard/dashboarditemsimulationincrement.cpp @@ -36,22 +36,6 @@ #include namespace { - constexpr const char* KeyFontMono = "Mono"; - constexpr const float DefaultFontSize = 10.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." - }; - constexpr openspace::properties::Property::PropertyInfo SimplificationInfo = { "Simplification", "Time Simplification", @@ -112,18 +96,6 @@ documentation::Documentation DashboardItemSimulationIncrement::Documentation() { new StringEqualVerifier("DashboardItemSimulationIncrement"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { SimplificationInfo.identifier, new BoolVerifier, @@ -154,9 +126,7 @@ documentation::Documentation DashboardItemSimulationIncrement::Documentation() { DashboardItemSimulationIncrement::DashboardItemSimulationIncrement( const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + : DashboardTextItem(dictionary) , _doSimplification(SimplificationInfo, true) , _requestedUnit(RequestedUnitInfo, properties::OptionProperty::DisplayType::Dropdown) , _transitionFormat( @@ -171,22 +141,6 @@ DashboardItemSimulationIncrement::DashboardItemSimulationIncrement( "DashboardItemSimulationIncrement" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - _fontName.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - _fontSize.onChange([this](){ - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - if (dictionary.hasKey(SimplificationInfo.identifier)) { _doSimplification = dictionary.value(SimplificationInfo.identifier); } @@ -222,9 +176,6 @@ DashboardItemSimulationIncrement::DashboardItemSimulationIncrement( _regularFormat = dictionary.value(RegularFormatInfo.identifier); } addProperty(_regularFormat); - - - _font = global::fontManager->font(_fontName, _fontSize); } void DashboardItemSimulationIncrement::render(glm::vec2& penPosition) { diff --git a/modules/base/dashboard/dashboarditemsimulationincrement.h b/modules/base/dashboard/dashboarditemsimulationincrement.h index 3643856205..cb2897dec9 100644 --- a/modules/base/dashboard/dashboarditemsimulationincrement.h +++ b/modules/base/dashboard/dashboarditemsimulationincrement.h @@ -30,15 +30,12 @@ #include #include #include -#include - -namespace ghoul::fontrendering { class Font; } namespace openspace { namespace documentation { struct Documentation; } -class DashboardItemSimulationIncrement : public DashboardItem { +class DashboardItemSimulationIncrement : public DashboardTextItem { public: DashboardItemSimulationIncrement(const ghoul::Dictionary& dictionary); virtual ~DashboardItemSimulationIncrement() = default; @@ -49,15 +46,11 @@ public: static documentation::Documentation Documentation(); private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; properties::BoolProperty _doSimplification; properties::OptionProperty _requestedUnit; properties::StringProperty _transitionFormat; properties::StringProperty _regularFormat; - - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditemtext.cpp b/modules/base/dashboard/dashboarditemtext.cpp index 2423aec13e..68eda26a3d 100644 --- a/modules/base/dashboard/dashboarditemtext.cpp +++ b/modules/base/dashboard/dashboarditemtext.cpp @@ -33,22 +33,6 @@ #include namespace { - constexpr const char* KeyFontMono = "Mono"; - constexpr const float DefaultFontSize = 10.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." - }; - constexpr openspace::properties::Property::PropertyInfo TextInfo = { "Text", "Text", @@ -69,18 +53,6 @@ documentation::Documentation DashboardItemText::Documentation() { new StringEqualVerifier("DashboardItemText"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { TextInfo.identifier, new StringVerifier, @@ -92,9 +64,7 @@ documentation::Documentation DashboardItemText::Documentation() { } DashboardItemText::DashboardItemText(const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + : DashboardTextItem(dictionary) , _text(TextInfo, "") { documentation::testSpecificationAndThrow( @@ -103,28 +73,10 @@ DashboardItemText::DashboardItemText(const ghoul::Dictionary& dictionary) "DashboardItemText" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - _fontName.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - _fontSize.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - if (dictionary.hasKey(TextInfo.identifier)) { _text = dictionary.value(TextInfo.identifier); }; addProperty(_text); - - _font = global::fontManager->font(_fontName, _fontSize); } void DashboardItemText::render(glm::vec2& penPosition) { diff --git a/modules/base/dashboard/dashboarditemtext.h b/modules/base/dashboard/dashboarditemtext.h index 8215b52e7d..8ccdf89263 100644 --- a/modules/base/dashboard/dashboarditemtext.h +++ b/modules/base/dashboard/dashboarditemtext.h @@ -28,15 +28,12 @@ #include #include -#include - -namespace ghoul::fontrendering { class Font; } namespace openspace { namespace documentation { struct Documentation; } -class DashboardItemText : public DashboardItem { +class DashboardItemText : public DashboardTextItem { public: DashboardItemText(const ghoul::Dictionary& dictionary); virtual ~DashboardItemText() = default; @@ -48,11 +45,7 @@ public: static documentation::Documentation Documentation(); private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; properties::StringProperty _text; - - std::shared_ptr _font; }; } // namespace openspace diff --git a/modules/base/dashboard/dashboarditemvelocity.cpp b/modules/base/dashboard/dashboarditemvelocity.cpp index 5431ba92a0..acc9b4a4a2 100644 --- a/modules/base/dashboard/dashboarditemvelocity.cpp +++ b/modules/base/dashboard/dashboarditemvelocity.cpp @@ -41,23 +41,6 @@ #include namespace { - constexpr const char* KeyFontMono = "Mono"; - - constexpr const float DefaultFontSize = 10.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 velocity." - }; - constexpr openspace::properties::Property::PropertyInfo SimplificationInfo = { "Simplification", "Simplification", @@ -100,18 +83,6 @@ documentation::Documentation DashboardItemVelocity::Documentation() { new StringEqualVerifier("DashboardItemVelocity"), Optional::No }, - { - FontNameInfo.identifier, - new StringVerifier, - Optional::Yes, - FontNameInfo.description - }, - { - FontSizeInfo.identifier, - new IntVerifier, - Optional::Yes, - FontSizeInfo.description - }, { SimplificationInfo.identifier, new BoolVerifier, @@ -129,9 +100,7 @@ documentation::Documentation DashboardItemVelocity::Documentation() { } DashboardItemVelocity::DashboardItemVelocity(const ghoul::Dictionary& dictionary) - : DashboardItem(dictionary) - , _fontName(FontNameInfo, KeyFontMono) - , _fontSize(FontSizeInfo, DefaultFontSize, 6.f, 144.f, 1.f) + : DashboardTextItem(dictionary) , _doSimplification(SimplificationInfo, true) , _requestedUnit(RequestedUnitInfo, properties::OptionProperty::DisplayType::Dropdown) { @@ -141,23 +110,6 @@ DashboardItemVelocity::DashboardItemVelocity(const ghoul::Dictionary& dictionary "DashboardItemVelocity" ); - if (dictionary.hasKey(FontNameInfo.identifier)) { - _fontName = dictionary.value(FontNameInfo.identifier); - } - if (dictionary.hasKey(FontSizeInfo.identifier)) { - _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); - } - - _fontName.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontName); - - _fontSize.onChange([this]() { - _font = global::fontManager->font(_fontName, _fontSize); - }); - addProperty(_fontSize); - if (dictionary.hasKey(SimplificationInfo.identifier)) { _doSimplification = dictionary.value(SimplificationInfo.identifier); } @@ -183,8 +135,6 @@ DashboardItemVelocity::DashboardItemVelocity(const ghoul::Dictionary& dictionary } _requestedUnit.setVisibility(properties::Property::Visibility::Hidden); addProperty(_requestedUnit); - - _font = global::fontManager->font(_fontName, _fontSize); } void DashboardItemVelocity::render(glm::vec2& penPosition) { diff --git a/modules/base/dashboard/dashboarditemvelocity.h b/modules/base/dashboard/dashboarditemvelocity.h index 2fcfa4ef16..571c5ffcac 100644 --- a/modules/base/dashboard/dashboarditemvelocity.h +++ b/modules/base/dashboard/dashboarditemvelocity.h @@ -28,20 +28,16 @@ #include #include -#include #include -#include #include -namespace ghoul::fontrendering { class Font; } - namespace openspace { class SceneGraphNode; namespace documentation { struct Documentation; } -class DashboardItemVelocity : public DashboardItem { +class DashboardItemVelocity : public DashboardTextItem { public: DashboardItemVelocity(const ghoul::Dictionary& dictionary); virtual ~DashboardItemVelocity() = default; @@ -53,14 +49,10 @@ public: static documentation::Documentation Documentation(); private: - properties::StringProperty _fontName; - properties::FloatProperty _fontSize; properties::BoolProperty _doSimplification; properties::OptionProperty _requestedUnit; glm::dvec3 _prevPosition = glm::dvec3(0.0); - - std::shared_ptr _font; }; } // namespace openspace diff --git a/src/rendering/dashboarditem.cpp b/src/rendering/dashboarditem.cpp index a075d500ed..183f3e2b06 100644 --- a/src/rendering/dashboarditem.cpp +++ b/src/rendering/dashboarditem.cpp @@ -24,9 +24,11 @@ #include -#include +#include #include #include +#include +#include #include namespace { @@ -124,4 +126,67 @@ bool DashboardItem::isEnabled() const { return _isEnabled; } + +namespace { + 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 distance." + }; +} // namespace + +documentation::Documentation DashboardTextItem::Documentation() { + using namespace documentation; + return { + "DashboardTextItem", + "dashboardtextitem", + { + { + FontNameInfo.identifier, + new StringVerifier, + Optional::Yes, + FontNameInfo.description + }, + { + FontSizeInfo.identifier, + new IntVerifier, + Optional::Yes, + FontSizeInfo.description + } + } + }; +} + +DashboardTextItem::DashboardTextItem(const ghoul::Dictionary& dictionary, float fontSize, + const std::string& fontName) + : DashboardItem(dictionary) + , _fontName(FontNameInfo, fontName) + , _fontSize(FontSizeInfo, fontSize, 6.f, 144.f, 1.f) +{ + if (dictionary.hasKey(FontNameInfo.identifier)) { + _fontName = dictionary.value(FontNameInfo.identifier); + } + _fontName.onChange([this]() { + _font = global::fontManager->font(_fontName, _fontSize); + }); + addProperty(_fontName); + + if (dictionary.hasKey(FontSizeInfo.identifier)) { + _fontSize = static_cast(dictionary.value(FontSizeInfo.identifier)); + } + _fontSize.onChange([this]() { + _font = global::fontManager->font(_fontName, _fontSize); + }); + addProperty(_fontSize); + + _font = global::fontManager->font(_fontName, _fontSize); +} + } // namespace openspace