mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
Split DashboardTextItem from DashboardItem
This commit is contained in:
@@ -28,12 +28,9 @@
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
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<ghoul::fontrendering::Font> _font;
|
||||
};
|
||||
|
||||
} // openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___DASHBOARDITEM___H__
|
||||
|
||||
56
include/openspace/rendering/dashboardtextitem.h
Normal file
56
include/openspace/rendering/dashboardtextitem.h
Normal file
@@ -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 <openspace/rendering/dashboarditem.h>
|
||||
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
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<ghoul::fontrendering::Font> _font;
|
||||
};
|
||||
|
||||
} // openspace
|
||||
|
||||
#endif // __OPENSPACE_CORE___DASHBOARDITEM___H__
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMANGLE___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMANGLE___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMDATE___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMDATE___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMDISTANCE___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMDISTANCE___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMFRAMERATE___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMFRAMERATE___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMMISSION___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMMISSION___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMPARALLELCONNECTION___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMPARALLELCONNECTION___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMPROPERTYVALUE___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMPROPERTYVALUE___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMSIMULATIONINCREMENT___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMSIMULATIONINCREMENT___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMTEXT___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMTEXT___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#ifndef __OPENSPACE_MODULE_BASE___DASHBOARDITEMVELOCITY___H__
|
||||
#define __OPENSPACE_MODULE_BASE___DASHBOARDITEMVELOCITY___H__
|
||||
|
||||
#include <openspace/rendering/dashboarditem.h>
|
||||
#include <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <optional>
|
||||
|
||||
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<std::string> 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<Parameters>();
|
||||
doc.id = "dashboarditem";
|
||||
return doc;
|
||||
}
|
||||
|
||||
std::unique_ptr<DashboardItem> 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<std::string>(IdentifierInfo.identifier);
|
||||
setIdentifier(std::move(identifier));
|
||||
|
||||
if (dictionary.hasValue<std::string>(GuiNameInfo.identifier)) {
|
||||
std::string guiName = dictionary.value<std::string>(GuiNameInfo.identifier);
|
||||
setGuiName(std::move(guiName));
|
||||
const Parameters p = codegen::bake<Parameters>(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<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);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
88
src/rendering/dashboardtextitem.cpp
Normal file
88
src/rendering/dashboardtextitem.cpp
Normal file
@@ -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 <openspace/rendering/dashboardtextitem.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <optional>
|
||||
|
||||
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<std::string> fontName;
|
||||
|
||||
// [[codegen::verbatim(FontSizeInfo.description)]]
|
||||
std::optional<float> fontSize;
|
||||
};
|
||||
#include "dashboardtextitem_codegen.cpp"
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation DashboardTextItem::Documentation() {
|
||||
documentation::Documentation doc = codegen::doc<Parameters>();
|
||||
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<Parameters>(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
|
||||
Reference in New Issue
Block a user