From 14144bbad3b2c1b4c37a04fa49085c6bdfd4aa55 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 23 Feb 2015 23:01:57 +0100 Subject: [PATCH] Add Gui component for manipulating time --- include/openspace/gui/gui.h | 4 +- include/openspace/gui/guitimecomponent.h | 97 ++++++++++++++++++++++++ src/gui/gui.cpp | 1 + src/gui/guiorigincomponent.cpp | 3 - src/gui/guitimecomponent.cpp | 79 +++++++++++++++++++ 5 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 include/openspace/gui/guitimecomponent.h create mode 100644 src/gui/guitimecomponent.cpp diff --git a/include/openspace/gui/gui.h b/include/openspace/gui/gui.h index 661b63f597..73555d488e 100644 --- a/include/openspace/gui/gui.h +++ b/include/openspace/gui/gui.h @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace openspace { @@ -61,10 +62,11 @@ public: static openspace::scripting::ScriptEngine::LuaLibrary luaLibrary(); //protected: + GuiHelpComponent _help; GuiOriginComponent _origin; GuiPerformanceComponent _performance; GuiPropertyComponent _property; - GuiHelpComponent _help; + GuiTimeComponent _time; bool _isEnabled; diff --git a/include/openspace/gui/guitimecomponent.h b/include/openspace/gui/guitimecomponent.h new file mode 100644 index 0000000000..d8a8b286e8 --- /dev/null +++ b/include/openspace/gui/guitimecomponent.h @@ -0,0 +1,97 @@ +/***************************************************************************************** + * * + * 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 __GUITIMECOMPONENT_H__ +#define __GUITIMECOMPONENT_H__ + +#include + +namespace openspace { + +namespace gui { + +class GuiTimeComponent : public GuiComponent { +public: + void render() override; +}; + +// +//class GuiPropertyComponent : public GuiComponent { +//public: +// //void registerProperty(const std::string& propertyDescription); +// void registerProperty(properties::Property* prop); +// void render(); +// +//protected: +// enum class PropertyType { +// BoolProperty = 0, +// IntProperty, +// FloatProperty, +// Vec2Property, +// Vec3Property, +// StringProperty, +// OptionProperty, +// SelectionProperty, +// TriggerProperty, +// InvalidPropertyType +// }; +// +// struct PropertyInfo { +// PropertyType type; +// std::string identifier; +// std::string name; +// std::string group; +// }; +// typedef std::string PropertyOwner; +// +// struct Property { +// PropertyOwner owner; +// std::vector properties; +// }; +// +// void handleProperty(const ghoul::Dictionary& value); +// +// PropertyType toPropertyType(const std::string& name) const; +// +// void renderProperty(const PropertyInfo& info) const; +// +// std::set _boolProperties; +// std::set _intProperties; +// std::set _floatProperties; +// std::set _vec2Properties; +// std::set _vec3Properties; +// std::set _vec4Properties; +// std::set _stringProperties; +// std::set _optionProperties; +// std::set _selectionProperties; +// std::set _triggerProperties; +// std::map> _propertiesByOwner; +// +// //std::vector _properties; +//}; + +} // namespace gui +} // namespace openspace + +#endif // __GUITIMECOMPONENT_H__ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index ee84e1efaa..b48b6e81b7 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -467,6 +467,7 @@ void GUI::renderMainWindow() { ImGui::Checkbox("Properties", &_property._isEnabled); ImGui::Checkbox("Performance", &_performance._isEnabled); _origin.render(); + _time.render(); // These are temporary until the scalegraph is in effect ---abock bool toSun = ImGui::Button("Coordinate System to Sun"); diff --git a/src/gui/guiorigincomponent.cpp b/src/gui/guiorigincomponent.cpp index c62430d52f..5c3225154c 100644 --- a/src/gui/guiorigincomponent.cpp +++ b/src/gui/guiorigincomponent.cpp @@ -33,9 +33,6 @@ namespace { const std::string _loggerCat = "GuiOriginComponent"; - const ImVec2 size = ImVec2(350, 500); - - //OsEng.scriptEngine()->queueScript(script); } namespace openspace { diff --git a/src/gui/guitimecomponent.cpp b/src/gui/guitimecomponent.cpp new file mode 100644 index 0000000000..139e548d76 --- /dev/null +++ b/src/gui/guitimecomponent.cpp @@ -0,0 +1,79 @@ +/***************************************************************************************** + * * + * 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 + +#include +#include + +#include +#include "imgui.h" + +namespace { + const std::string _loggerCat = "GuiTimeComponent"; +} + +namespace openspace { +namespace gui { + +void GuiTimeComponent::render() { + float deltaTime = Time::ref().deltaTime(); + + + bool changed = ImGui::SliderFloat("Delta Time", &deltaTime, -100.f, 100.f); + if (changed) + OsEng.scriptEngine()->queueScript("openspace.time.setDeltaTime(" + std::to_string(deltaTime) + ")"); + + + //char dateBuffer[512] = {}; + //ImGui::InputText("Date", dateBuffer, 512); + //bool pressed = ImGui::Button("Set Date"); + //if (pressed) + // OsEng.scriptEngine()->queueScript("openspace.time.setTime('" + std::string(dateBuffer) + "')"); + + //const SceneGraphNode* currentFocus = OsEng.interactionHandler()->focusNode(); + + //std::vector nodes = OsEng.renderEngine()->sceneGraph()->allSceneGraphNodes(); + //std::sort(nodes.begin(), nodes.end(), [](SceneGraphNode* lhs, SceneGraphNode* rhs) { return lhs->name() < rhs->name(); }); + //auto it = std::find(nodes.begin(), nodes.end(), currentFocus); + //ghoul_assert(it != nodes.end(), "Focus node not found"); + + //std::string nodeNames = ""; + //for (SceneGraphNode* n : nodes) + // nodeNames += n->name() + '\0'; + + + //int position = it - nodes.begin(); + + //bool result = ImGui::Combo("Origin", &position, nodeNames.c_str()); + + //if (result) { + // LINFO("openspace.setOrigin('" + nodes[position]->name() + "');"); + // OsEng.scriptEngine()->queueScript("openspace.setOrigin('" + nodes[position]->name() + "');"); + //} + +} + +} // gui +} // openspace