mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 20:39:08 -06:00
Replace explicit Lua commands to toggle onscreen gui with a global property
This commit is contained in:
@@ -61,8 +61,6 @@ public:
|
||||
|
||||
void render();
|
||||
|
||||
static openspace::scripting::LuaLibrary luaLibrary();
|
||||
|
||||
//protected:
|
||||
GuiHelpComponent _help;
|
||||
GuiOriginComponent _origin;
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef __GUICOMPONENT_H__
|
||||
#define __GUICOMPONENT_H__
|
||||
|
||||
#include <openspace/properties/propertyowner.h>
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
|
||||
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:
|
||||
/// <code>true</code> if this component is enabled and visible on the screen
|
||||
bool _isEnabled = false;
|
||||
properties::BoolProperty _isEnabled;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace gui {
|
||||
|
||||
class GuiHelpComponent : public GuiComponent {
|
||||
public:
|
||||
GuiHelpComponent();
|
||||
|
||||
void render() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace gui {
|
||||
|
||||
class GuiOriginComponent : public GuiComponent {
|
||||
public:
|
||||
GuiOriginComponent();
|
||||
|
||||
void render() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace gui {
|
||||
|
||||
class GuiPerformanceComponent : public GuiComponent {
|
||||
public:
|
||||
GuiPerformanceComponent();
|
||||
|
||||
void render() override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -56,7 +56,6 @@ protected:
|
||||
void renderPropertyOwner(properties::PropertyOwner* owner);
|
||||
void renderProperty(properties::Property* prop, properties::PropertyOwner* owner);
|
||||
|
||||
std::string _name;
|
||||
SourceFunction _function;
|
||||
};
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace gui {
|
||||
|
||||
class GuiTimeComponent : public GuiComponent {
|
||||
public:
|
||||
GuiTimeComponent();
|
||||
|
||||
void render() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,10 +24,16 @@
|
||||
|
||||
#include <modules/onscreengui/onscreenguimodule.h>
|
||||
|
||||
#include <modules/onscreengui/include/gui.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
OnScreenGUIModule::OnScreenGUIModule()
|
||||
: OpenSpaceModule("OnScreenGUI")
|
||||
{}
|
||||
{
|
||||
addPropertySubOwner(OsEng.gui());
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@
|
||||
namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
GuiOriginComponent::GuiOriginComponent()
|
||||
: GuiComponent("Origin")
|
||||
{}
|
||||
|
||||
void GuiOriginComponent::render() {
|
||||
SceneGraphNode* currentFocus = OsEng.interactionHandler().focusNode();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
GuiTimeComponent::GuiTimeComponent()
|
||||
: GuiComponent("Time")
|
||||
{}
|
||||
|
||||
void GuiTimeComponent::render() {
|
||||
float deltaTime = static_cast<float>(Time::ref().deltaTime());
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user