mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-04 02:29:49 -06:00
Make imGUI listen to OpenSpaceEngine properties for visibility for properties and for scene graph nodes
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#define __OPENSPACE_CORE___OPENSPACEENGINE___H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/property.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
@@ -103,6 +104,8 @@ public:
|
||||
std::vector<std::byte> encode();
|
||||
void decode(std::vector<std::byte> data);
|
||||
|
||||
properties::Property::Visibility visibility() const;
|
||||
bool showHiddenSceneGraphNodes() const;
|
||||
void toggleShutdownMode();
|
||||
|
||||
Mode currentMode() const;
|
||||
|
||||
@@ -554,18 +554,6 @@ void ImGUIModule::renderFrame(float deltaTime, const glm::vec2& windowSize,
|
||||
comp->setEnabled(enabled);
|
||||
}
|
||||
|
||||
// Render and Update property visibility
|
||||
// Fragile! Keep this in sync with properties::Property::Visibility
|
||||
using V = properties::Property::Visibility;
|
||||
int t = static_cast<std::underlying_type_t<V>>(_currentVisibility);
|
||||
|
||||
// Array is sorted by importance
|
||||
std::array<const char*, 4> items = { "User", "Developer", "Hidden", "All" };
|
||||
ImGui::Combo("PropertyVisibility", &t, items.data(), static_cast<int>(items.size()));
|
||||
|
||||
_currentVisibility = static_cast<V>(t);
|
||||
_property.setVisibility(_currentVisibility);
|
||||
|
||||
#ifdef SHOW_IMGUI_HELPERS
|
||||
ImGui::Checkbox("ImGUI Internals", &_showInternals);
|
||||
if (_showInternals) {
|
||||
|
||||
@@ -124,9 +124,6 @@ private:
|
||||
UniformCache(tex, ortho) _uniformCache;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _fontTexture;
|
||||
|
||||
properties::Property::Visibility _currentVisibility =
|
||||
properties::Property::Visibility::Developer;
|
||||
|
||||
std::vector<ImGuiContext*> _contexts;
|
||||
|
||||
std::vector<TouchInput> _validTouchStates;
|
||||
|
||||
@@ -52,22 +52,17 @@ public:
|
||||
void setPropertyOwnerFunction(
|
||||
std::function<std::vector<properties::PropertyOwner*>()> func);
|
||||
|
||||
void setVisibility(properties::Property::Visibility visibility);
|
||||
|
||||
void render() override;
|
||||
|
||||
protected:
|
||||
void renderPropertyOwner(properties::PropertyOwner* owner);
|
||||
void renderProperty(properties::Property* prop, properties::PropertyOwner* owner);
|
||||
|
||||
properties::Property::Visibility _visibility = properties::Property::Visibility::User;
|
||||
|
||||
std::vector<properties::PropertyOwner*> _propertyOwners;
|
||||
std::function<std::vector<properties::PropertyOwner*>()> _propertyOwnerFunction;
|
||||
|
||||
properties::BoolProperty _useTreeLayout;
|
||||
properties::StringListProperty _treeOrdering;
|
||||
properties::BoolProperty _ignoreHiddenHint;
|
||||
};
|
||||
|
||||
} // namespace openspace::gui
|
||||
|
||||
@@ -42,7 +42,6 @@ namespace openspace::gui {
|
||||
GuiParallelComponent::GuiParallelComponent()
|
||||
: GuiPropertyComponent("Parallel", "Parallel Connection")
|
||||
{
|
||||
setVisibility(properties::Property::Visibility::Always);
|
||||
}
|
||||
|
||||
void GuiParallelComponent::renderDisconnected() {
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
#include <modules/imgui/include/imgui_include.h>
|
||||
#include <modules/imgui/include/renderproperties.h>
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <ghoul/misc/misc.h>
|
||||
#include <algorithm>
|
||||
@@ -59,15 +61,17 @@ namespace {
|
||||
"the hidden hints are followed."
|
||||
};
|
||||
|
||||
int nVisibleProperties(const std::vector<openspace::properties::Property*>& props,
|
||||
openspace::properties::Property::Visibility visibility)
|
||||
int nVisibleProperties(const std::vector<openspace::properties::Property*>& props)
|
||||
{
|
||||
using Visibility = openspace::properties::Property::Visibility;
|
||||
Visibility visibilityFilter = openspace::global::openSpaceEngine->visibility();
|
||||
|
||||
return static_cast<int>(std::count_if(
|
||||
props.begin(),
|
||||
props.end(),
|
||||
[visibility](openspace::properties::Property* p) {
|
||||
[visibilityFilter](openspace::properties::Property* p) {
|
||||
using V = openspace::properties::Property::Visibility;
|
||||
return static_cast<std::underlying_type_t<V>>(visibility) >=
|
||||
return static_cast<std::underlying_type_t<V>>(visibilityFilter) >=
|
||||
static_cast<std::underlying_type_t<V>>(p->visibility());
|
||||
}
|
||||
));
|
||||
@@ -187,11 +191,9 @@ GuiPropertyComponent::GuiPropertyComponent(std::string identifier, std::string g
|
||||
: GuiComponent(std::move(identifier), std::move(guiName))
|
||||
, _useTreeLayout(UseTreeInfo, useTree)
|
||||
, _treeOrdering(OrderingInfo)
|
||||
, _ignoreHiddenHint(IgnoreHiddenInfo)
|
||||
{
|
||||
addProperty(_useTreeLayout);
|
||||
addProperty(_treeOrdering);
|
||||
addProperty(_ignoreHiddenHint);
|
||||
}
|
||||
|
||||
void GuiPropertyComponent::setPropertyOwners(
|
||||
@@ -206,10 +208,6 @@ void GuiPropertyComponent::setPropertyOwnerFunction(
|
||||
_propertyOwnerFunction = std::move(func);
|
||||
}
|
||||
|
||||
void GuiPropertyComponent::setVisibility(properties::Property::Visibility visibility) {
|
||||
_visibility = visibility;
|
||||
}
|
||||
|
||||
void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner) {
|
||||
using namespace properties;
|
||||
|
||||
@@ -217,12 +215,12 @@ void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner)
|
||||
return;
|
||||
}
|
||||
|
||||
const int nThisProperty = nVisibleProperties(owner->properties(), _visibility);
|
||||
const int nThisProperty = nVisibleProperties(owner->properties());
|
||||
ImGui::PushID(owner->identifier().c_str());
|
||||
const std::vector<PropertyOwner*>& subOwners = owner->propertySubOwners();
|
||||
for (PropertyOwner* subOwner : subOwners) {
|
||||
const std::vector<Property*>& properties = subOwner->propertiesRecursive();
|
||||
int count = nVisibleProperties(properties, _visibility);
|
||||
int count = nVisibleProperties(properties);
|
||||
if (count == 0) {
|
||||
continue;
|
||||
}
|
||||
@@ -286,6 +284,7 @@ void GuiPropertyComponent::render() {
|
||||
ImGui::SetNextWindowBgAlpha(0.75f);
|
||||
ImGui::Begin(guiName().c_str(), &v);
|
||||
_isEnabled = v;
|
||||
bool showHiddenNode = openspace::global::openSpaceEngine->showHiddenSceneGraphNodes();
|
||||
|
||||
_isCollapsed = ImGui::IsWindowCollapsed();
|
||||
using namespace properties;
|
||||
@@ -373,12 +372,14 @@ void GuiPropertyComponent::render() {
|
||||
dynamic_cast<SceneGraphNode*>(*owners.begin())->guiPath().empty());
|
||||
|
||||
auto renderProp = [&](properties::PropertyOwner* pOwner) {
|
||||
const int count = nVisibleProperties(pOwner->propertiesRecursive(), _visibility);
|
||||
const int count = nVisibleProperties(pOwner->propertiesRecursive());
|
||||
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
auto header = [&]() -> bool {
|
||||
if (owners.size() > 1) {
|
||||
// Create a header in case we have multiple owners
|
||||
@@ -402,7 +403,7 @@ void GuiPropertyComponent::render() {
|
||||
};
|
||||
|
||||
if (!_useTreeLayout || noGuiGroups) {
|
||||
if (!_ignoreHiddenHint) {
|
||||
if (!showHiddenNode) {
|
||||
// Remove all of the nodes that we want hidden first
|
||||
owners.erase(
|
||||
std::remove_if(
|
||||
@@ -424,7 +425,7 @@ void GuiPropertyComponent::render() {
|
||||
for (properties::PropertyOwner* pOwner : owners) {
|
||||
// We checked above that pOwner is a SceneGraphNode
|
||||
SceneGraphNode* nOwner = static_cast<SceneGraphNode*>(pOwner);
|
||||
if (!_ignoreHiddenHint && nOwner->hasGuiHintHidden()) {
|
||||
if (!showHiddenNode && nOwner->hasGuiHintHidden()) {
|
||||
continue;
|
||||
}
|
||||
const std::string gui = nOwner->guiPath();
|
||||
@@ -491,7 +492,9 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop,
|
||||
|
||||
// Check if the visibility of the property is high enough to be displayed
|
||||
using V = properties::Property::Visibility;
|
||||
const auto v = static_cast<std::underlying_type_t<V>>(_visibility);
|
||||
using Visibility = openspace::properties::Property::Visibility;
|
||||
Visibility visibilityFilter = openspace::global::openSpaceEngine->visibility();
|
||||
const auto v = static_cast<std::underlying_type_t<V>>(visibilityFilter);
|
||||
const auto propV = static_cast<std::underlying_type_t<V>>(prop->visibility());
|
||||
if (v >= propV) {
|
||||
auto it = FunctionMapping.find(prop->className());
|
||||
|
||||
@@ -1619,6 +1619,14 @@ void OpenSpaceEngine::decode(std::vector<std::byte> data) {
|
||||
global::syncEngine->decodeSyncables(std::move(data));
|
||||
}
|
||||
|
||||
properties::Property::Visibility openspace::OpenSpaceEngine::visibility() const {
|
||||
return static_cast<properties::Property::Visibility>(_visibility.value());
|
||||
}
|
||||
|
||||
bool openspace::OpenSpaceEngine::showHiddenSceneGraphNodes() const {
|
||||
return _showHiddenSceneGraphNodes;
|
||||
}
|
||||
|
||||
void OpenSpaceEngine::toggleShutdownMode() {
|
||||
if (_shutdown.inShutdown) {
|
||||
// If we are already in shutdown mode, we want to disable it
|
||||
|
||||
Reference in New Issue
Block a user