diff --git a/modules/onscreengui/include/gui.h b/modules/onscreengui/include/gui.h index 2c25bb36fd..7f696a609e 100644 --- a/modules/onscreengui/include/gui.h +++ b/modules/onscreengui/include/gui.h @@ -61,8 +61,6 @@ public: void render(); - static openspace::scripting::LuaLibrary luaLibrary(); - //protected: GuiHelpComponent _help; GuiOriginComponent _origin; diff --git a/modules/onscreengui/include/guicomponent.h b/modules/onscreengui/include/guicomponent.h index 1a44757ba0..dd4baeba70 100644 --- a/modules/onscreengui/include/guicomponent.h +++ b/modules/onscreengui/include/guicomponent.h @@ -25,6 +25,9 @@ #ifndef __GUICOMPONENT_H__ #define __GUICOMPONENT_H__ +#include +#include + namespace openspace { namespace gui { @@ -33,8 +36,11 @@ class GUI; /** * The base class for a GUI component that can be rendered to the screen. */ -class GuiComponent { +class GuiComponent : public properties::PropertyOwner { public: + /// Constructor that initializes this components member variables + GuiComponent(std::string name); + /** * Returns if this component is enabled, that is, if it is currently active and * visible on the screen. @@ -66,7 +72,7 @@ public: protected: /// true if this component is enabled and visible on the screen - bool _isEnabled = false; + properties::BoolProperty _isEnabled; }; } // namespace gui diff --git a/modules/onscreengui/include/guihelpcomponent.h b/modules/onscreengui/include/guihelpcomponent.h index 8f6e82e2c0..6740166d75 100644 --- a/modules/onscreengui/include/guihelpcomponent.h +++ b/modules/onscreengui/include/guihelpcomponent.h @@ -32,6 +32,8 @@ namespace gui { class GuiHelpComponent : public GuiComponent { public: + GuiHelpComponent(); + void render() override; }; diff --git a/modules/onscreengui/include/guiorigincomponent.h b/modules/onscreengui/include/guiorigincomponent.h index 8598b784e4..159331a752 100644 --- a/modules/onscreengui/include/guiorigincomponent.h +++ b/modules/onscreengui/include/guiorigincomponent.h @@ -32,6 +32,8 @@ namespace gui { class GuiOriginComponent : public GuiComponent { public: + GuiOriginComponent(); + void render() override; }; diff --git a/modules/onscreengui/include/guiperformancecomponent.h b/modules/onscreengui/include/guiperformancecomponent.h index 647b44e406..3bba754a00 100644 --- a/modules/onscreengui/include/guiperformancecomponent.h +++ b/modules/onscreengui/include/guiperformancecomponent.h @@ -40,6 +40,8 @@ namespace gui { class GuiPerformanceComponent : public GuiComponent { public: + GuiPerformanceComponent(); + void render() override; protected: diff --git a/modules/onscreengui/include/guipropertycomponent.h b/modules/onscreengui/include/guipropertycomponent.h index 2be19af00a..bf836660a2 100644 --- a/modules/onscreengui/include/guipropertycomponent.h +++ b/modules/onscreengui/include/guipropertycomponent.h @@ -56,7 +56,6 @@ protected: void renderPropertyOwner(properties::PropertyOwner* owner); void renderProperty(properties::Property* prop, properties::PropertyOwner* owner); - std::string _name; SourceFunction _function; }; diff --git a/modules/onscreengui/include/guitimecomponent.h b/modules/onscreengui/include/guitimecomponent.h index dcdb9f78ab..32c5e7a3de 100644 --- a/modules/onscreengui/include/guitimecomponent.h +++ b/modules/onscreengui/include/guitimecomponent.h @@ -32,6 +32,8 @@ namespace gui { class GuiTimeComponent : public GuiComponent { public: + GuiTimeComponent(); + void render() override; }; diff --git a/modules/onscreengui/onscreenguimodule.cpp b/modules/onscreengui/onscreenguimodule.cpp index 472d26c947..118beeb259 100644 --- a/modules/onscreengui/onscreenguimodule.cpp +++ b/modules/onscreengui/onscreenguimodule.cpp @@ -24,10 +24,16 @@ #include +#include + +#include + namespace openspace { OnScreenGUIModule::OnScreenGUIModule() : OpenSpaceModule("OnScreenGUI") -{} +{ + addPropertySubOwner(OsEng.gui()); +} } // namespace openspace diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index 8e1de8b71a..d98bc05e82 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -221,11 +221,20 @@ namespace openspace { namespace gui { GUI::GUI() - : GuiComponent() + : GuiComponent("Main") , _globalProperty("Global") , _property("Properties") , _screenSpaceProperty("ScreenSpace Properties") -{} +{ + addPropertySubOwner(_help); + addPropertySubOwner(_origin); + addPropertySubOwner(_performance); + addPropertySubOwner(_globalProperty); + addPropertySubOwner(_property); + addPropertySubOwner(_screenSpaceProperty); + addPropertySubOwner(_time); + addPropertySubOwner(_iswa); +} GUI::~GUI() { ImGui::Shutdown(); @@ -565,31 +574,5 @@ void GUI::render() { ImGui::End(); } -scripting::LuaLibrary GUI::luaLibrary() { - return { - "gui", - { - { - "show", - &luascriptfunctions::gui::show, - "", - "Shows the console" - }, - { - "hide", - &luascriptfunctions::gui::hide, - "", - "Hides the console" - }, - { - "toggle", - &luascriptfunctions::gui::toggle, - "", - "Toggles the console" - } - } - }; -} - } // namespace gui } // namespace openspace diff --git a/modules/onscreengui/src/guicomponent.cpp b/modules/onscreengui/src/guicomponent.cpp index afd9b5ab6a..27373aadf7 100644 --- a/modules/onscreengui/src/guicomponent.cpp +++ b/modules/onscreengui/src/guicomponent.cpp @@ -27,6 +27,14 @@ namespace openspace { namespace gui { +GuiComponent::GuiComponent(std::string name) + : _isEnabled("enabled", "Is Enabled", false) +{ + setName(std::move(name)); + + addProperty(_isEnabled); +} + bool GuiComponent::isEnabled() const { return _isEnabled; } diff --git a/modules/onscreengui/src/guihelpcomponent.cpp b/modules/onscreengui/src/guihelpcomponent.cpp index c38e2ebe38..f7a7bf7aad 100644 --- a/modules/onscreengui/src/guihelpcomponent.cpp +++ b/modules/onscreengui/src/guihelpcomponent.cpp @@ -33,8 +33,14 @@ namespace { namespace openspace { namespace gui { +GuiHelpComponent::GuiHelpComponent() + : GuiComponent("Help") +{} + void GuiHelpComponent::render() { - ImGui::Begin("Help", &_isEnabled, size, 0.5f); + bool v = _isEnabled; + ImGui::Begin("Help", &v, size, 0.5f); + _isEnabled = v; ImGui::ShowUserGuide(); ImGui::End(); } diff --git a/modules/onscreengui/src/guiorigincomponent.cpp b/modules/onscreengui/src/guiorigincomponent.cpp index 6ddb14224e..1e6efdd7aa 100644 --- a/modules/onscreengui/src/guiorigincomponent.cpp +++ b/modules/onscreengui/src/guiorigincomponent.cpp @@ -36,6 +36,10 @@ namespace openspace { namespace gui { +GuiOriginComponent::GuiOriginComponent() + : GuiComponent("Origin") +{} + void GuiOriginComponent::render() { SceneGraphNode* currentFocus = OsEng.interactionHandler().focusNode(); diff --git a/modules/onscreengui/src/guiperformancecomponent.cpp b/modules/onscreengui/src/guiperformancecomponent.cpp index 0eb360aaca..787e8e6314 100644 --- a/modules/onscreengui/src/guiperformancecomponent.cpp +++ b/modules/onscreengui/src/guiperformancecomponent.cpp @@ -54,12 +54,18 @@ namespace { namespace openspace { namespace gui { +GuiPerformanceComponent::GuiPerformanceComponent() + : GuiComponent("PerformanceComponent") +{} + void GuiPerformanceComponent::render() { using ghoul::SharedMemory; using namespace performance; - ImGui::Begin("Performance", &_isEnabled); - PerformanceLayout* layout = OsEng.renderEngine().performanceManager()->performanceData(); + bool v = _isEnabled; + ImGui::Begin("Performance", &v); + _isEnabled = v; + PerformanceLayout* layout = OsEng.renderEngine().performanceManager()->performanceData(); ImGui::Checkbox("SceneGraph", &_sceneGraphIsEnabled); ImGui::Checkbox("Functions", &_functionsIsEnabled); diff --git a/modules/onscreengui/src/guipropertycomponent.cpp b/modules/onscreengui/src/guipropertycomponent.cpp index b3ba64a9b8..bbd9431fd4 100644 --- a/modules/onscreengui/src/guipropertycomponent.cpp +++ b/modules/onscreengui/src/guipropertycomponent.cpp @@ -39,7 +39,7 @@ namespace openspace { namespace gui { GuiPropertyComponent::GuiPropertyComponent(std::string name) - : _name(std::move(name)) + : GuiComponent(std::move(name)) {} void GuiPropertyComponent::setSource(SourceFunction function) { @@ -54,6 +54,9 @@ void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner) ImGui::PushID(owner->name().c_str()); const auto& subOwners = owner->propertySubOwners(); for (properties::PropertyOwner* subOwner : subOwners) { + if (subOwner->propertiesRecursive().empty()) { + continue; + } if (subOwners.size() == 1) { renderPropertyOwner(subOwner); } @@ -101,7 +104,9 @@ void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner) } void GuiPropertyComponent::render() { - ImGui::Begin(_name.c_str(), &_isEnabled, size, 0.5f); + bool v = _isEnabled; + ImGui::Begin(name().c_str(), &v, size, 0.5f); + _isEnabled = v; ImGui::Spacing(); diff --git a/modules/onscreengui/src/guitimecomponent.cpp b/modules/onscreengui/src/guitimecomponent.cpp index c2b1d15d0d..59a1ef1694 100644 --- a/modules/onscreengui/src/guitimecomponent.cpp +++ b/modules/onscreengui/src/guitimecomponent.cpp @@ -32,6 +32,10 @@ namespace openspace { namespace gui { +GuiTimeComponent::GuiTimeComponent() + : GuiComponent("Time") +{} + void GuiTimeComponent::render() { float deltaTime = static_cast(Time::ref().deltaTime()); diff --git a/scripts/common.lua b/scripts/common.lua index 66ba39b3bb..0ba8dd21fd 100644 --- a/scripts/common.lua +++ b/scripts/common.lua @@ -14,7 +14,7 @@ helper.scheduledScript.reversible = {} helper.setCommonKeys = function() openspace.bindKeyLocal( "F1", - "openspace.gui.toggle()", + helper.property.invert('Global Properties.OnScreenGUI.Main.enabled'), "Toggles the visibility of the on-screen GUI." ) openspace.bindKeyLocal( diff --git a/src/documentation/core_registration.cpp b/src/documentation/core_registration.cpp index 4f87a5ee20..946a87e494 100644 --- a/src/documentation/core_registration.cpp +++ b/src/documentation/core_registration.cpp @@ -73,7 +73,6 @@ void registerCoreClasses(scripting::ScriptEngine& engine) { engine.addLibrary(Time::luaLibrary()); engine.addLibrary(interaction::InteractionHandler::luaLibrary()); engine.addLibrary(LuaConsole::luaLibrary()); - engine.addLibrary(gui::GUI::luaLibrary()); engine.addLibrary(ParallelConnection::luaLibrary()); engine.addLibrary(ModuleEngine::luaLibrary()); engine.addLibrary(scripting::ScriptScheduler::luaLibrary());