Replace explicit Lua commands to toggle onscreen gui with a global property

This commit is contained in:
Alexander Bock
2016-11-22 09:49:22 +01:00
parent ceac5db8c5
commit f711e192fb
17 changed files with 73 additions and 41 deletions

View File

@@ -61,8 +61,6 @@ public:
void render();
static openspace::scripting::LuaLibrary luaLibrary();
//protected:
GuiHelpComponent _help;
GuiOriginComponent _origin;

View File

@@ -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

View File

@@ -32,6 +32,8 @@ namespace gui {
class GuiHelpComponent : public GuiComponent {
public:
GuiHelpComponent();
void render() override;
};

View File

@@ -32,6 +32,8 @@ namespace gui {
class GuiOriginComponent : public GuiComponent {
public:
GuiOriginComponent();
void render() override;
};

View File

@@ -40,6 +40,8 @@ namespace gui {
class GuiPerformanceComponent : public GuiComponent {
public:
GuiPerformanceComponent();
void render() override;
protected:

View File

@@ -56,7 +56,6 @@ protected:
void renderPropertyOwner(properties::PropertyOwner* owner);
void renderProperty(properties::Property* prop, properties::PropertyOwner* owner);
std::string _name;
SourceFunction _function;
};

View File

@@ -32,6 +32,8 @@ namespace gui {
class GuiTimeComponent : public GuiComponent {
public:
GuiTimeComponent();
void render() override;
};

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -36,6 +36,10 @@
namespace openspace {
namespace gui {
GuiOriginComponent::GuiOriginComponent()
: GuiComponent("Origin")
{}
void GuiOriginComponent::render() {
SceneGraphNode* currentFocus = OsEng.interactionHandler().focusNode();

View File

@@ -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);

View File

@@ -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();

View File

@@ -32,6 +32,10 @@
namespace openspace {
namespace gui {
GuiTimeComponent::GuiTimeComponent()
: GuiComponent("Time")
{}
void GuiTimeComponent::render() {
float deltaTime = static_cast<float>(Time::ref().deltaTime());

View File

@@ -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(

View File

@@ -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());