mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-20 02:58:31 -05:00
Intermediate work on making imgui into components
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class GUI;
|
||||
class SyncBuffer;
|
||||
class LuaConsole;
|
||||
|
||||
@@ -59,7 +58,7 @@ public:
|
||||
scripting::ScriptEngine& scriptEngine();
|
||||
LuaConsole& console();
|
||||
|
||||
GUI& gui();
|
||||
gui::GUI& gui();
|
||||
|
||||
// SGCT callbacks
|
||||
bool initializeGL();
|
||||
@@ -97,7 +96,7 @@ private:
|
||||
scripting::ScriptEngine _scriptEngine;
|
||||
ghoul::cmdparser::CommandlineParser _commandlineParser;
|
||||
LuaConsole _console;
|
||||
GUI _gui;
|
||||
gui::GUI _gui;
|
||||
|
||||
SyncBuffer* _syncBuffer;
|
||||
|
||||
|
||||
+11
-42
@@ -25,40 +25,27 @@
|
||||
#ifndef __GUI_H__
|
||||
#define __GUI_H__
|
||||
|
||||
#include <openspace/gui/guicomponent.h>
|
||||
#include <openspace/gui/guiperformancecomponent.h>
|
||||
#include <openspace/gui/guipropertycomponent.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ghoul {
|
||||
class SharedMemory;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace properties {
|
||||
class Property;
|
||||
}
|
||||
namespace gui {
|
||||
|
||||
class GUI {
|
||||
public:
|
||||
GUI();
|
||||
~GUI();
|
||||
|
||||
bool isEnabled() const;
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
void initialize();
|
||||
void deinitialize();
|
||||
|
||||
void initializeGL();
|
||||
void deinitializeGL();
|
||||
|
||||
void registerProperty(properties::Property* prop);
|
||||
|
||||
bool mouseButtonCallback(int key, int action);
|
||||
bool mouseWheelCallback(int position);
|
||||
bool keyCallback(int key, int action);
|
||||
@@ -67,38 +54,20 @@ public:
|
||||
void startFrame(float deltaTime, const glm::vec2& windowSize, const glm::vec2& mousePos, bool mouseButtonsPressed[2]);
|
||||
void endFrame();
|
||||
|
||||
|
||||
static scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
private:
|
||||
void renderMainWindow();
|
||||
|
||||
void renderPropertyWindow();
|
||||
void renderPerformanceWindow();
|
||||
static openspace::scripting::ScriptEngine::LuaLibrary luaLibrary();
|
||||
|
||||
//protected:
|
||||
GuiPerformanceComponent _performance;
|
||||
GuiPropertyComponent _property;
|
||||
|
||||
bool _isEnabled;
|
||||
|
||||
bool _showPropertyWindow;
|
||||
bool _showPerformanceWindow;
|
||||
bool _showHelp;
|
||||
|
||||
|
||||
ghoul::SharedMemory* _performanceMemory;
|
||||
float _minMaxValues[2];
|
||||
|
||||
std::set<properties::Property*> _boolProperties;
|
||||
std::set<properties::Property*> _intProperties;
|
||||
std::set<properties::Property*> _floatProperties;
|
||||
std::set<properties::Property*> _vec2Properties;
|
||||
std::set<properties::Property*> _vec3Properties;
|
||||
std::set<properties::Property*> _stringProperties;
|
||||
std::set<properties::Property*> _optionProperty;
|
||||
std::set<properties::Property*> _selectionProperty;
|
||||
std::set<properties::Property*> _triggerProperty;
|
||||
|
||||
std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __GUI_H__
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __GUICOMPONENT_H__
|
||||
#define __GUICOMPONENT_H__
|
||||
|
||||
namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
/**
|
||||
* The base class for a GUI component that can be rendered to the screen.
|
||||
*/
|
||||
class GuiComponent {
|
||||
public:
|
||||
/**
|
||||
* Returns if this component is enabled, that is, if it is currently active and
|
||||
* visible on the screen.
|
||||
* \return <code>true</code> if this component is enabled, <code>false</code>
|
||||
* otherwise
|
||||
*/
|
||||
bool isEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets if this component is enabled, that is, if it is currently active and visible
|
||||
* on the screen.
|
||||
* \param enabled The new enabled status of this component
|
||||
*/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
/// Initializes the component with everything that does not require an OpenGL context
|
||||
virtual void initialize();
|
||||
/// Initializes the component with everything that requires an OpenGL context
|
||||
virtual void initializeGL();
|
||||
|
||||
/// Deinitializes the component with things that do not require an OpenGL context
|
||||
virtual void deinitialize();
|
||||
|
||||
/// Deinitializes the component with things that require an OpenGL context
|
||||
virtual void deinitializeGL();
|
||||
|
||||
/// Renders the individual subcomponents to the screen
|
||||
virtual void render() = 0;
|
||||
|
||||
protected:
|
||||
/// <code>true</code> if this component is enabled and visible on the screen
|
||||
bool _isEnabled;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __GUICOMPONENT_H__
|
||||
@@ -0,0 +1,51 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __GUIPERFORMANCECOMPONENT_H__
|
||||
#define __GUIPERFORMANCECOMPONENT_H__
|
||||
|
||||
#include <openspace/gui/guicomponent.h>
|
||||
|
||||
namespace ghoul {
|
||||
class SharedMemory;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
class GuiPerformanceComponent : public GuiComponent {
|
||||
public:
|
||||
void initialize();
|
||||
|
||||
void render();
|
||||
|
||||
protected:
|
||||
ghoul::SharedMemory* _performanceMemory;
|
||||
float _minMaxValues[2];
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __GUIPERFORMANCECOMPONENT_H__
|
||||
@@ -0,0 +1,64 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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 __GUIPROPERTYCOMPONENT_H__
|
||||
#define __GUIPROPERTYCOMPONENT_H__
|
||||
|
||||
#include <openspace/gui/guicomponent.h>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace properties {
|
||||
class Property;
|
||||
}
|
||||
|
||||
namespace gui {
|
||||
|
||||
class GuiPropertyComponent : public GuiComponent {
|
||||
public:
|
||||
void registerProperty(properties::Property* prop);
|
||||
void render();
|
||||
|
||||
protected:
|
||||
std::set<properties::Property*> _boolProperties;
|
||||
std::set<properties::Property*> _intProperties;
|
||||
std::set<properties::Property*> _floatProperties;
|
||||
std::set<properties::Property*> _vec2Properties;
|
||||
std::set<properties::Property*> _vec3Properties;
|
||||
std::set<properties::Property*> _stringProperties;
|
||||
std::set<properties::Property*> _optionProperty;
|
||||
std::set<properties::Property*> _selectionProperty;
|
||||
std::set<properties::Property*> _triggerProperty;
|
||||
|
||||
std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __GUIPROPERTYCOMPONENT_H__
|
||||
@@ -242,7 +242,7 @@ bool OpenSpaceEngine::initialize() {
|
||||
_scriptEngine.addLibrary(Time::luaLibrary());
|
||||
_scriptEngine.addLibrary(interaction::InteractionHandler::luaLibrary());
|
||||
_scriptEngine.addLibrary(LuaConsole::luaLibrary());
|
||||
_scriptEngine.addLibrary(GUI::luaLibrary());
|
||||
_scriptEngine.addLibrary(gui::GUI::luaLibrary());
|
||||
|
||||
// TODO: Maybe move all scenegraph and renderengine stuff to initializeGL
|
||||
scriptEngine().initialize();
|
||||
@@ -479,7 +479,7 @@ LuaConsole& OpenSpaceEngine::console() {
|
||||
return _console;
|
||||
}
|
||||
|
||||
GUI& OpenSpaceEngine::gui() {
|
||||
gui::GUI& OpenSpaceEngine::gui() {
|
||||
return _gui;
|
||||
}
|
||||
|
||||
|
||||
+534
-392
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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/gui/guicomponent.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
bool GuiComponent::isEnabled() const {
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
void GuiComponent::setEnabled(bool enabled) {
|
||||
_isEnabled = enabled;
|
||||
}
|
||||
|
||||
void GuiComponent::initialize() {}
|
||||
|
||||
void GuiComponent::initializeGL() {}
|
||||
|
||||
void GuiComponent::deinitialize() {}
|
||||
|
||||
void GuiComponent::deinitializeGL() {}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,107 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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/gui/guiperformancecomponent.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <ghoul/misc/sharedmemory.h>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "GuiPerformanceComponent";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
void GuiPerformanceComponent::initialize() {
|
||||
}
|
||||
|
||||
void GuiPerformanceComponent::render() {
|
||||
// Copy and paste from renderengine.cpp::storePerformanceMeasurements method
|
||||
const int8_t Version = 0;
|
||||
const int nValues = 250;
|
||||
const int lengthName = 256;
|
||||
const int maxValues = 50;
|
||||
|
||||
struct PerformanceLayout {
|
||||
int8_t version;
|
||||
int32_t nValuesPerEntry;
|
||||
int32_t nEntries;
|
||||
int32_t maxNameLength;
|
||||
int32_t maxEntries;
|
||||
|
||||
struct PerformanceLayoutEntry {
|
||||
char name[lengthName];
|
||||
float renderTime[nValues];
|
||||
float updateRenderable[nValues];
|
||||
float updateEphemeris[nValues];
|
||||
|
||||
int32_t currentRenderTime;
|
||||
int32_t currentUpdateRenderable;
|
||||
int32_t currentUpdateEphemeris;
|
||||
};
|
||||
|
||||
PerformanceLayoutEntry entries[maxValues];
|
||||
};
|
||||
|
||||
ImGui::Begin("Performance", &_isEnabled);
|
||||
if (OsEng.renderEngine().doesPerformanceMeasurements() &&
|
||||
ghoul::SharedMemory::exists(RenderEngine::PerformanceMeasurementSharedData))
|
||||
{
|
||||
ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 10000.f);
|
||||
_minMaxValues[1] = std::max(_minMaxValues[0], _minMaxValues[1]);
|
||||
|
||||
if (!_performanceMemory)
|
||||
_performanceMemory = new ghoul::SharedMemory(RenderEngine::PerformanceMeasurementSharedData);
|
||||
|
||||
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(_performanceMemory->pointer());
|
||||
|
||||
for (int i = 0; i < layout->nEntries; ++i) {
|
||||
const PerformanceLayout::PerformanceLayoutEntry& entry = layout->entries[i];
|
||||
|
||||
if (ImGui::CollapsingHeader(entry.name)) {
|
||||
std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us";
|
||||
ImGui::PlotLines("UpdateEphemeris", &entry.updateEphemeris[0], layout->nValuesPerEntry, 0, updateEphemerisTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
|
||||
std::string updateRenderableTime = std::to_string(entry.updateRenderable[entry.currentUpdateRenderable - 1]) + "us";
|
||||
ImGui::PlotLines("UpdateRender", &entry.updateRenderable[0], layout->nValuesPerEntry, 0, updateRenderableTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
|
||||
std::string renderTime = std::to_string(entry.renderTime[entry.currentRenderTime - 1]) + "us";
|
||||
ImGui::PlotLines("RenderTime", &entry.renderTime[0], layout->nValuesPerEntry, 0, renderTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ImGui::TextWrapped("Performance monitoring is disabled. Enable with "
|
||||
"'openspace.setPerformanceMeasurement(true)'");
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
} // namespace gui
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,237 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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/gui/guipropertycomponent.h>
|
||||
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/selectionproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "GuiPropertyComponent";
|
||||
const ImVec2 size = ImVec2(350, 500);
|
||||
|
||||
using namespace openspace::properties;
|
||||
|
||||
void renderBoolProperty(Property* prop, const std::string& ownerName) {
|
||||
BoolProperty* p = static_cast<BoolProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
BoolProperty::ValueType value = *p;
|
||||
ImGui::Checkbox((ownerName + "." + name).c_str(), &value);
|
||||
p->set(value);
|
||||
}
|
||||
|
||||
void renderOptionProperty(Property* prop, const std::string& ownerName) {
|
||||
OptionProperty* p = static_cast<OptionProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
int value = *p;
|
||||
std::vector<OptionProperty::Option> options = p->options();
|
||||
for (const OptionProperty::Option& o : options) {
|
||||
ImGui::RadioButton((ownerName + "." + name).c_str(), &value, o.value);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text(o.description.c_str());
|
||||
}
|
||||
p->set(value);
|
||||
}
|
||||
|
||||
void renderSelectionProperty(Property* prop, const std::string& ownerName) {
|
||||
SelectionProperty* p = static_cast<SelectionProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
if (ImGui::CollapsingHeader((ownerName + "." + name).c_str())) {
|
||||
const std::vector<SelectionProperty::Option>& options = p->options();
|
||||
std::vector<int> newSelectedIndices;
|
||||
|
||||
std::vector<int> selectedIndices = p->value();
|
||||
|
||||
for (int i = 0; i < options.size(); ++i) {
|
||||
std::string description = options[i].description;
|
||||
bool selected = std::find(selectedIndices.begin(), selectedIndices.end(), i) != selectedIndices.end();
|
||||
ImGui::Checkbox(description.c_str(), &selected);
|
||||
|
||||
if (selected)
|
||||
newSelectedIndices.push_back(i);
|
||||
}
|
||||
|
||||
p->setValue(std::move(newSelectedIndices));
|
||||
}
|
||||
}
|
||||
|
||||
void renderIntProperty(Property* prop, const std::string& ownerName) {
|
||||
IntProperty* p = static_cast<IntProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
IntProperty::ValueType value = *p;
|
||||
ImGui::SliderInt((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
|
||||
p->set(value);
|
||||
}
|
||||
|
||||
void renderFloatProperty(Property* prop, const std::string& ownerName) {
|
||||
FloatProperty* p = static_cast<FloatProperty*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
FloatProperty::ValueType value = *p;
|
||||
ImGui::SliderFloat((ownerName + "." + name).c_str(), &value, p->minValue(), p->maxValue());
|
||||
p->set(value);
|
||||
}
|
||||
|
||||
void renderVec2Property(Property* prop, const std::string& ownerName) {
|
||||
Vec2Property* p = static_cast<Vec2Property*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
Vec2Property::ValueType value = *p;
|
||||
|
||||
ImGui::SliderFloat2((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
|
||||
p->set(value);
|
||||
}
|
||||
|
||||
|
||||
void renderVec3Property(Property* prop, const std::string& ownerName) {
|
||||
Vec3Property* p = static_cast<Vec3Property*>(prop);
|
||||
std::string name = p->guiName();
|
||||
|
||||
Vec3Property::ValueType value = *p;
|
||||
|
||||
ImGui::SliderFloat3((ownerName + "." + name).c_str(), &value.x, p->minValue().x, p->maxValue().x);
|
||||
p->set(value);
|
||||
}
|
||||
|
||||
void renderTriggerProperty(Property* prop, const std::string& ownerName) {
|
||||
std::string name = prop->guiName();
|
||||
bool pressed = ImGui::Button((ownerName + "." + name).c_str());
|
||||
if (pressed)
|
||||
prop->set(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
void GuiPropertyComponent::registerProperty(properties::Property* prop) {
|
||||
using namespace properties;
|
||||
|
||||
std::string className = prop->className();
|
||||
|
||||
if (className == "BoolProperty")
|
||||
_boolProperties.insert(prop);
|
||||
else if (className == "IntProperty")
|
||||
_intProperties.insert(prop);
|
||||
else if (className == "FloatProperty")
|
||||
_floatProperties.insert(prop);
|
||||
else if (className == "StringProperty")
|
||||
_stringProperties.insert(prop);
|
||||
else if (className == "Vec2Property")
|
||||
_vec2Properties.insert(prop);
|
||||
else if (className == "Vec3Property")
|
||||
_vec3Properties.insert(prop);
|
||||
else if (className == "OptionProperty")
|
||||
_optionProperty.insert(prop);
|
||||
else if (className == "TriggerProperty")
|
||||
_triggerProperty.insert(prop);
|
||||
else if (className == "SelectionProperty")
|
||||
_selectionProperty.insert(prop);
|
||||
else {
|
||||
LWARNING("Class name '" << className << "' not handled in GUI generation");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string fullyQualifiedId = prop->fullyQualifiedIdentifier();
|
||||
size_t pos = fullyQualifiedId.find('.');
|
||||
std::string owner = fullyQualifiedId.substr(0, pos);
|
||||
|
||||
auto it = _propertiesByOwner.find(owner);
|
||||
if (it == _propertiesByOwner.end())
|
||||
_propertiesByOwner[owner] = { prop };
|
||||
else
|
||||
it->second.push_back(prop);
|
||||
|
||||
}
|
||||
|
||||
void GuiPropertyComponent::render() {
|
||||
using namespace openspace::properties;
|
||||
|
||||
ImGui::Begin("Properties", &_isEnabled, size, 0.5f);
|
||||
|
||||
//ImGui::ShowUserGuide();
|
||||
ImGui::Spacing();
|
||||
|
||||
for (const auto& p : _propertiesByOwner) {
|
||||
if (ImGui::CollapsingHeader(p.first.c_str())) {
|
||||
for (properties::Property* prop : p.second) {
|
||||
if (_boolProperties.find(prop) != _boolProperties.end()) {
|
||||
renderBoolProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_intProperties.find(prop) != _intProperties.end()) {
|
||||
renderIntProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_floatProperties.find(prop) != _floatProperties.end()) {
|
||||
renderFloatProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_vec2Properties.find(prop) != _vec2Properties.end()) {
|
||||
renderVec2Property(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_vec3Properties.find(prop) != _vec3Properties.end()) {
|
||||
renderVec3Property(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_optionProperty.find(prop) != _optionProperty.end()) {
|
||||
renderOptionProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_triggerProperty.find(prop) != _triggerProperty.end()) {
|
||||
renderTriggerProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_selectionProperty.find(prop) != _selectionProperty.end()) {
|
||||
renderSelectionProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
} // gui
|
||||
} // openspace
|
||||
@@ -445,7 +445,7 @@ bool SceneGraph::loadSceneInternal(const std::string& sceneDescriptionFilePath)
|
||||
for (SceneGraphNode* node : _nodes) {
|
||||
std::vector<properties::Property*> properties = node->propertiesRecursive();
|
||||
for (properties::Property* p : properties) {
|
||||
OsEng.gui().registerProperty(p);
|
||||
OsEng.gui()._property.registerProperty(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user