From a6bb8cdecb560d2940e0e134888577c6243a6c78 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 24 Mar 2021 17:46:13 +0100 Subject: [PATCH] Split DashboardTextItem from DashboardItem --- include/openspace/rendering/dashboarditem.h | 19 --- .../openspace/rendering/dashboardtextitem.h | 56 ++++++++ modules/base/dashboard/dashboarditemangle.h | 2 +- modules/base/dashboard/dashboarditemdate.h | 2 +- .../base/dashboard/dashboarditemdistance.h | 2 +- .../base/dashboard/dashboarditemframerate.h | 2 +- modules/base/dashboard/dashboarditemmission.h | 2 +- .../dashboarditemparallelconnection.h | 2 +- .../dashboard/dashboarditempropertyvalue.h | 2 +- .../dashboarditemsimulationincrement.h | 2 +- modules/base/dashboard/dashboarditemtext.h | 2 +- .../base/dashboard/dashboarditemvelocity.h | 2 +- src/CMakeLists.txt | 2 + src/rendering/dashboarditem.cpp | 133 +++--------------- src/rendering/dashboardtextitem.cpp | 88 ++++++++++++ 15 files changed, 176 insertions(+), 142 deletions(-) create mode 100644 include/openspace/rendering/dashboardtextitem.h create mode 100644 src/rendering/dashboardtextitem.cpp diff --git a/include/openspace/rendering/dashboarditem.h b/include/openspace/rendering/dashboarditem.h index 11013a5d28..6e5d28060d 100644 --- a/include/openspace/rendering/dashboarditem.h +++ b/include/openspace/rendering/dashboarditem.h @@ -28,12 +28,9 @@ #include #include -#include -#include #include namespace ghoul { class Dictionary; } -namespace ghoul::fontrendering { class Font; } namespace openspace { @@ -58,22 +55,6 @@ 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/include/openspace/rendering/dashboardtextitem.h b/include/openspace/rendering/dashboardtextitem.h new file mode 100644 index 0000000000..5dbeb00de9 --- /dev/null +++ b/include/openspace/rendering/dashboardtextitem.h @@ -0,0 +1,56 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2021 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_CORE___DASHBOARDTEXTITEM___H__ +#define __OPENSPACE_CORE___DASHBOARDTEXTITEM___H__ + +#include + +#include +#include + +namespace ghoul { class Dictionary; } +namespace ghoul::fontrendering { class Font; } + +namespace openspace { + +namespace documentation { struct Documentation; } + +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/dashboard/dashboarditemangle.h b/modules/base/dashboard/dashboarditemangle.h index b6d234d862..69c7e41a65 100644 --- a/modules/base/dashboard/dashboarditemangle.h +++ b/modules/base/dashboard/dashboarditemangle.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMANGLE___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMANGLE___H__ -#include +#include #include #include diff --git a/modules/base/dashboard/dashboarditemdate.h b/modules/base/dashboard/dashboarditemdate.h index 602de7b2c9..6e2acd9c43 100644 --- a/modules/base/dashboard/dashboarditemdate.h +++ b/modules/base/dashboard/dashboarditemdate.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMDATE___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMDATE___H__ -#include +#include #include diff --git a/modules/base/dashboard/dashboarditemdistance.h b/modules/base/dashboard/dashboarditemdistance.h index bb3b7037ef..dc0cd2a64c 100644 --- a/modules/base/dashboard/dashboarditemdistance.h +++ b/modules/base/dashboard/dashboarditemdistance.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMDISTANCE___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMDISTANCE___H__ -#include +#include #include #include diff --git a/modules/base/dashboard/dashboarditemframerate.h b/modules/base/dashboard/dashboarditemframerate.h index 17038cc572..226d488dd8 100644 --- a/modules/base/dashboard/dashboarditemframerate.h +++ b/modules/base/dashboard/dashboarditemframerate.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMFRAMERATE___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMFRAMERATE___H__ -#include +#include #include #include diff --git a/modules/base/dashboard/dashboarditemmission.h b/modules/base/dashboard/dashboarditemmission.h index bb02551fdf..1156cebe4f 100644 --- a/modules/base/dashboard/dashboarditemmission.h +++ b/modules/base/dashboard/dashboarditemmission.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMMISSION___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMMISSION___H__ -#include +#include namespace openspace { diff --git a/modules/base/dashboard/dashboarditemparallelconnection.h b/modules/base/dashboard/dashboarditemparallelconnection.h index 7e13459850..687eb3734b 100644 --- a/modules/base/dashboard/dashboarditemparallelconnection.h +++ b/modules/base/dashboard/dashboarditemparallelconnection.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMPARALLELCONNECTION___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMPARALLELCONNECTION___H__ -#include +#include namespace openspace { diff --git a/modules/base/dashboard/dashboarditempropertyvalue.h b/modules/base/dashboard/dashboarditempropertyvalue.h index 2f14a3aeff..73f2191ba1 100644 --- a/modules/base/dashboard/dashboarditempropertyvalue.h +++ b/modules/base/dashboard/dashboarditempropertyvalue.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMPROPERTYVALUE___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMPROPERTYVALUE___H__ -#include +#include #include diff --git a/modules/base/dashboard/dashboarditemsimulationincrement.h b/modules/base/dashboard/dashboarditemsimulationincrement.h index 7b3367811f..2f214de3f9 100644 --- a/modules/base/dashboard/dashboarditemsimulationincrement.h +++ b/modules/base/dashboard/dashboarditemsimulationincrement.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMSIMULATIONINCREMENT___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMSIMULATIONINCREMENT___H__ -#include +#include #include #include diff --git a/modules/base/dashboard/dashboarditemtext.h b/modules/base/dashboard/dashboarditemtext.h index 648b501805..a5be0355fd 100644 --- a/modules/base/dashboard/dashboarditemtext.h +++ b/modules/base/dashboard/dashboarditemtext.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMTEXT___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMTEXT___H__ -#include +#include #include diff --git a/modules/base/dashboard/dashboarditemvelocity.h b/modules/base/dashboard/dashboarditemvelocity.h index fa2664b2cf..827ab6dc91 100644 --- a/modules/base/dashboard/dashboarditemvelocity.h +++ b/modules/base/dashboard/dashboarditemvelocity.h @@ -25,7 +25,7 @@ #ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMVELOCITY___H__ #define __OPENSPACE_MODULE_BASE___DASHBOARDITEMVELOCITY___H__ -#include +#include #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c68ddecfc6..1efeee4a4d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,6 +132,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/rendering/dashboard.cpp ${OPENSPACE_BASE_DIR}/src/rendering/dashboard_lua.inl ${OPENSPACE_BASE_DIR}/src/rendering/dashboarditem.cpp + ${OPENSPACE_BASE_DIR}/src/rendering/dashboardtextitem.cpp ${OPENSPACE_BASE_DIR}/src/rendering/framebufferrenderer.cpp ${OPENSPACE_BASE_DIR}/src/rendering/deferredcastermanager.cpp ${OPENSPACE_BASE_DIR}/src/rendering/helper.cpp @@ -322,6 +323,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/rendering/abufferrenderer.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/dashboard.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/dashboarditem.h + ${OPENSPACE_BASE_DIR}/include/openspace/rendering/dashboardtextitem.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/framebufferrenderer.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/deferredcaster.h ${OPENSPACE_BASE_DIR}/include/openspace/rendering/deferredcasterlistener.h diff --git a/src/rendering/dashboarditem.cpp b/src/rendering/dashboarditem.cpp index 9dbc2e3604..a0f907f11b 100644 --- a/src/rendering/dashboarditem.cpp +++ b/src/rendering/dashboarditem.cpp @@ -28,8 +28,8 @@ #include #include #include -#include #include +#include namespace { constexpr const char* KeyType = "Type"; @@ -40,12 +40,6 @@ namespace { "If this value is set to 'true' this dashboard item is shown in the dashboard" }; - constexpr openspace::properties::Property::PropertyInfo TypeInfo = { - "Type", - "Type", - "" - }; - constexpr openspace::properties::Property::PropertyInfo IdentifierInfo = { "Identifier", "Identifier", @@ -57,36 +51,25 @@ namespace { "Gui Name", "" }; + + struct [[codegen::Dictionary(DashboardItem)]] Parameters { + std::string type; + + // [[codegen::verbatim(IdentifierInfo.description)]] + std::string identifier; + + // [[codegen::verbatim(GuiNameInfo.description)]] + std::optional guiName; + }; +#include "dashboarditem_codegen.cpp" } // namespace namespace openspace { documentation::Documentation DashboardItem::Documentation() { - using namespace documentation; - return { - "DashboardItem", - "dashboarditem", - { - { - TypeInfo.identifier, - new StringVerifier, - Optional::No, - TypeInfo.description - }, - { - IdentifierInfo.identifier, - new StringVerifier, - Optional::No, - IdentifierInfo.description - }, - { - GuiNameInfo.identifier, - new StringVerifier, - Optional::Yes, - GuiNameInfo.description - } - } - }; + documentation::Documentation doc = codegen::doc(); + doc.id = "dashboarditem"; + return doc; } std::unique_ptr DashboardItem::createFromDictionary( @@ -105,18 +88,11 @@ DashboardItem::DashboardItem(const ghoul::Dictionary& dictionary) : properties::PropertyOwner({ "", "" }) , _isEnabled(EnabledInfo, true) { - documentation::testSpecificationAndThrow( - Documentation(), - dictionary, - "DashboardItem" - ); - - std::string identifier = dictionary.value(IdentifierInfo.identifier); - setIdentifier(std::move(identifier)); - - if (dictionary.hasValue(GuiNameInfo.identifier)) { - std::string guiName = dictionary.value(GuiNameInfo.identifier); - setGuiName(std::move(guiName)); + const Parameters p = codegen::bake(dictionary); + + setIdentifier(p.identifier); + if (p.guiName.has_value()) { + setGuiName(*p.guiName); } addProperty(_isEnabled); @@ -126,73 +102,4 @@ 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) -{ - documentation::testSpecificationAndThrow( - Documentation(), - dictionary, - "DashboardTextItem" - ); - - 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 diff --git a/src/rendering/dashboardtextitem.cpp b/src/rendering/dashboardtextitem.cpp new file mode 100644 index 0000000000..fae12f4403 --- /dev/null +++ b/src/rendering/dashboardtextitem.cpp @@ -0,0 +1,88 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2021 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include + +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." + }; + + struct [[codegen::Dictionary(DashboardTextItem)]] Parameters { + // [[codegen::verbatim(FontNameInfo.description)]] + std::optional fontName; + + // [[codegen::verbatim(FontSizeInfo.description)]] + std::optional fontSize; + }; +#include "dashboardtextitem_codegen.cpp" +} // namespace + +namespace openspace { + +documentation::Documentation DashboardTextItem::Documentation() { + documentation::Documentation doc = codegen::doc(); + doc.id = "dashboardtextitem"; + return doc; +} + +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) +{ + const Parameters p = codegen::bake(dictionary); + + _fontName = p.fontName.value_or(_fontName); + _fontName.onChange([this]() { + _font = global::fontManager->font(_fontName, _fontSize); + }); + addProperty(_fontName); + + _fontSize = p.fontSize.value_or(_fontSize); + _fontSize.onChange([this]() { + _font = global::fontManager->font(_fontName, _fontSize); + }); + addProperty(_fontSize); + + _font = global::fontManager->font(_fontName, _fontSize); +} + +} // namespace openspace