From 0af3233f533cf8d61d3bdd8e6867cf421a26396b Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 7 Dec 2017 17:06:55 -0500 Subject: [PATCH 01/11] Move Space/Time component into simple menu version Move regular menu to F3 Move easy menu to F2 Remove extra text --- .../openspace/properties/numericalproperty.inl | 4 ++-- modules/imgui/src/guispacetimecomponent.cpp | 5 +---- scripts/common.lua | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/openspace/properties/numericalproperty.inl b/include/openspace/properties/numericalproperty.inl index 671e2e7fd2..88104ab3cf 100644 --- a/include/openspace/properties/numericalproperty.inl +++ b/include/openspace/properties/numericalproperty.inl @@ -367,12 +367,12 @@ void NumericalProperty::setMaxValue(T value) { template T NumericalProperty::steppingValue() const { - return _steppingValue; + return _stepping; } template void NumericalProperty::setSteppingValue(T value) { - _steppingValue = std::move(value); + _stepping = std::move(value); } template diff --git a/modules/imgui/src/guispacetimecomponent.cpp b/modules/imgui/src/guispacetimecomponent.cpp index 3106d43a24..0bcbfd8b2c 100644 --- a/modules/imgui/src/guispacetimecomponent.cpp +++ b/modules/imgui/src/guispacetimecomponent.cpp @@ -27,7 +27,6 @@ #include #include - #include #include #include @@ -82,8 +81,6 @@ void GuiSpaceTimeComponent::render() { ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.f); - ImGui::Text("%s", "Focus on:"); - ImGui::SameLine(); // Buttons for important SceneGraphNodes for (SceneGraphNode* n : nodes) { const std::vector& tags = n->tags(); @@ -119,7 +116,7 @@ void GuiSpaceTimeComponent::render() { } int currentPosition = static_cast(std::distance(nodes.begin(), iCurrentFocus)); - bool hasChanged = ImGui::Combo("Focus Node", ¤tPosition, nodeNames.c_str()); + bool hasChanged = ImGui::Combo("", ¤tPosition, nodeNames.c_str()); if (hasChanged) { OsEng.scriptEngine().queueScript( "openspace.setPropertyValue('NavigationHandler.Origin', '" + diff --git a/scripts/common.lua b/scripts/common.lua index bec249a5ba..0c63a7747e 100644 --- a/scripts/common.lua +++ b/scripts/common.lua @@ -12,14 +12,6 @@ helper.scheduledScript.reversible = {} -- Function that sets the most common key bindings that are common to most (all?) -- scenes helper.setCommonKeys = function() - openspace.bindKeyLocal( - "F1", - [[local b = openspace.getPropertyValue('Global Properties.ImGUI.Main.Enabled'); - openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.Enabled', not b); - openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.IsHidden', b);]], - "Shows or hides the entire user interface" - ) - openspace.bindKeyLocal( "F2", [[local b = openspace.getPropertyValue('Global Properties.ImGUI.Main.Properties.Enabled'); @@ -31,8 +23,10 @@ helper.setCommonKeys = function() -- windows are hidden openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.IsHidden', false); openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.Properties.Enabled', true); + openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.Space/Time.Enabled', true); else openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.Properties.Enabled', not b); + openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.Space/Time.Enabled', not b); openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.IsHidden', b); end]], "Shows or hides the properties window" @@ -40,6 +34,14 @@ helper.setCommonKeys = function() openspace.bindKeyLocal( "F3", + [[local b = openspace.getPropertyValue('Global Properties.ImGUI.Main.Enabled'); + openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.Enabled', not b); + openspace.setPropertyValueSingle('Global Properties.ImGUI.Main.IsHidden', b);]], + "Shows or hides the entire user interface" + ) + + openspace.bindKeyLocal( + "F4", helper.property.invert("RenderEngine.PerformanceMeasurements"), "Toogles performance measurements that shows rendering time informations." ) From 66b3117064399bd97e1c40e38078b73e6b4f4a99 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Dec 2017 11:37:56 -0500 Subject: [PATCH 02/11] Add a delay to the display of tooltips (closes #426) --- modules/imgui/include/gui.h | 1 + modules/imgui/include/guipropertycomponent.h | 2 + modules/imgui/include/renderproperties.h | 42 +++---- modules/imgui/src/gui.cpp | 37 ++++-- modules/imgui/src/guipropertycomponent.cpp | 13 ++- modules/imgui/src/renderproperties.cpp | 114 ++++++++++++------- 6 files changed, 134 insertions(+), 75 deletions(-) diff --git a/modules/imgui/include/gui.h b/modules/imgui/include/gui.h index 13d15626f5..3227053528 100644 --- a/modules/imgui/include/gui.h +++ b/modules/imgui/include/gui.h @@ -88,6 +88,7 @@ public: bool _showInternals; properties::BoolProperty _showHelpText; + properties::FloatProperty _helpTextDelay; private: void renderAndUpdatePropertyVisibility(); diff --git a/modules/imgui/include/guipropertycomponent.h b/modules/imgui/include/guipropertycomponent.h index b467b2bfe7..194850a723 100644 --- a/modules/imgui/include/guipropertycomponent.h +++ b/modules/imgui/include/guipropertycomponent.h @@ -60,6 +60,7 @@ public: void setVisibility(properties::Property::Visibility visibility); void setHasRegularProperties(bool hasOnlyRegularProperties); void setShowHelpTooltip(bool showHelpTooltip); + void setShowHelpTooltipDelay(double delay); void render() override; @@ -79,6 +80,7 @@ protected: properties::StringListProperty _treeOrdering; bool _showHelpTooltip; + double _tooltipDelay; }; } // namespace openspace::gui diff --git a/modules/imgui/include/renderproperties.h b/modules/imgui/include/renderproperties.h index ee61492052..15ad289a1d 100644 --- a/modules/imgui/include/renderproperties.h +++ b/modules/imgui/include/renderproperties.h @@ -43,87 +43,87 @@ void executeScript(const std::string& id, const std::string& value, void renderBoolProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderOptionProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderSelectionProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderStringProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderStringListProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderDoubleProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderIntProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderIVec2Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderIVec3Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderIVec4Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderFloatProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderVec2Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderVec3Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderVec4Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderDVec2Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderDVec3Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderDVec4Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderDMat2Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderDMat3Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderDMat4Property(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); void renderTriggerProperty(properties::Property* prop, const std::string& ownerName, IsRegularProperty isRegular = IsRegularProperty::Yes, - ShowToolTip showTooltip = ShowToolTip::Yes); + ShowToolTip showTooltip = ShowToolTip::Yes, double tooltipDelay = 1.0); } // namespace openspace diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index 06b95087e0..c26f1c35ea 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -253,6 +253,12 @@ static const openspace::properties::Property::PropertyInfo ShowHelpInfo = { "explaining what impact they have on the visuals." }; +static const openspace::properties::Property::PropertyInfo HelpTextDelayInfo = { + "HelpTextDelay", + "Tooltip Delay (in s)", + "This value determines the delay in seconds after which the tooltip is shown." +}; + static const openspace::properties::Property::PropertyInfo HiddenInfo = { "IsHidden", "Is Hidden", @@ -282,6 +288,7 @@ GUI::GUI() , _featuredProperties("Featured Properties", GuiPropertyComponent::UseTreeLayout::No) , _showInternals(false) , _showHelpText(ShowHelpInfo, true) + , _helpTextDelay(HelpTextDelayInfo, 1.0, 0.0, 10.0) , _currentVisibility(properties::Property::Visibility::Developer) , _allHidden(HiddenInfo, true) { @@ -304,13 +311,29 @@ GUI::GUI() addPropertySubOwner(_iswa); #endif // OPENSPACE_MODULE_ISWA_ENABLED - addProperty(_showHelpText); - _showHelpText.onChange([this](){ - _globalProperty.setShowHelpTooltip(_showHelpText); - _property.setShowHelpTooltip(_showHelpText); - _screenSpaceProperty.setShowHelpTooltip(_showHelpText); - _virtualProperty.setShowHelpTooltip(_showHelpText); - }); + { + auto showHelpTextFunc = [this](){ + _globalProperty.setShowHelpTooltip(_showHelpText); + _property.setShowHelpTooltip(_showHelpText); + _screenSpaceProperty.setShowHelpTooltip(_showHelpText); + _virtualProperty.setShowHelpTooltip(_showHelpText); + }; + showHelpTextFunc(); + _showHelpText.onChange(std::move(showHelpTextFunc)); + addProperty(_showHelpText); + } + + { + auto helpTextDelayFunc = [this](){ + _globalProperty.setShowHelpTooltipDelay(_helpTextDelay); + _property.setShowHelpTooltipDelay(_helpTextDelay); + _screenSpaceProperty.setShowHelpTooltipDelay(_helpTextDelay); + _virtualProperty.setShowHelpTooltipDelay(_helpTextDelay); + }; + helpTextDelayFunc(); + _helpTextDelay.onChange(std::move(helpTextDelayFunc)); + addProperty(_helpTextDelay); + } addProperty(_allHidden); } diff --git a/modules/imgui/src/guipropertycomponent.cpp b/modules/imgui/src/guipropertycomponent.cpp index 1c71cb3013..a7fef02322 100644 --- a/modules/imgui/src/guipropertycomponent.cpp +++ b/modules/imgui/src/guipropertycomponent.cpp @@ -187,6 +187,10 @@ void GuiPropertyComponent::setShowHelpTooltip(bool showHelpTooltip) { _showHelpTooltip = showHelpTooltip; } +void GuiPropertyComponent::setShowHelpTooltipDelay(double delay) { + _tooltipDelay = delay; +} + void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner) { if (owner->propertiesRecursive().empty()) { return; @@ -425,7 +429,8 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop, properties::PropertyOwner* owner) { using Func = std::function< - void(properties::Property*, const std::string&, IsRegularProperty, ShowToolTip) + void(properties::Property*, const std::string&, IsRegularProperty, ShowToolTip, + double) >; static const std::map FunctionMapping = { { "BoolProperty", &renderBoolProperty }, @@ -463,7 +468,8 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop, prop, owner->name(), IsRegularProperty(_hasOnlyRegularProperties), - ShowToolTip(_showHelpTooltip) + ShowToolTip(_showHelpTooltip), + _tooltipDelay ); } else { @@ -471,7 +477,8 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop, prop, "", IsRegularProperty(_hasOnlyRegularProperties), - ShowToolTip(_showHelpTooltip) + ShowToolTip(_showHelpTooltip), + _tooltipDelay ); } } diff --git a/modules/imgui/src/renderproperties.cpp b/modules/imgui/src/renderproperties.cpp index b28549a658..9aa45902ba 100644 --- a/modules/imgui/src/renderproperties.cpp +++ b/modules/imgui/src/renderproperties.cpp @@ -39,12 +39,14 @@ #include #include +#include + namespace openspace { using namespace properties; -void renderTooltip(Property* prop) { - if (ImGui::IsItemHovered()) { +void renderTooltip(Property* prop, double delay) { + if (ImGui::IsItemHovered() && (GImGui->HoveredIdTimer > delay)) { ImGui::BeginTooltip(); if (!prop->description().empty()) { ImGui::TextWrapped("%s", prop->description().c_str()); @@ -88,7 +90,8 @@ void executeScript(const std::string& id, const std::string& value, } void renderBoolProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); BoolProperty* p = static_cast(prop); @@ -98,7 +101,7 @@ void renderBoolProperty(Property* prop, const std::string& ownerName, BoolProperty::ValueType value = *p; ImGui::Checkbox(name.c_str(), &value); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -108,7 +111,8 @@ void renderBoolProperty(Property* prop, const std::string& ownerName, } void renderOptionProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); OptionProperty* p = static_cast(prop); @@ -126,7 +130,7 @@ void renderOptionProperty(Property* prop, const std::string& ownerName, for (const OptionProperty::Option& o : options) { ImGui::RadioButton(o.description.c_str(), &value, o.value); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } } ImGui::Separator(); @@ -151,6 +155,9 @@ void renderOptionProperty(Property* prop, const std::string& ownerName, int oldIdx = idx; ImGui::Combo(name.c_str(), &idx, nodeNames.c_str()); + if (showTooltip) { + renderTooltip(prop, tooltipDelay); + } if (idx != oldIdx) { value = options[idx].value; @@ -166,7 +173,8 @@ void renderOptionProperty(Property* prop, const std::string& ownerName, } void renderSelectionProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); SelectionProperty* p = static_cast(prop); @@ -187,7 +195,7 @@ void renderSelectionProperty(Property* prop, const std::string& ownerName, ImGui::Checkbox(description.c_str(), &selected); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (selected) { @@ -209,7 +217,8 @@ void renderSelectionProperty(Property* prop, const std::string& ownerName, } void renderStringProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); StringProperty* p = static_cast(prop); @@ -232,7 +241,7 @@ void renderStringProperty(Property* prop, const std::string& ownerName, ImGuiInputTextFlags_EnterReturnsTrue ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (hasNewValue) { @@ -247,7 +256,8 @@ void renderStringProperty(Property* prop, const std::string& ownerName, } void renderStringListProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); StringListProperty* p = static_cast(prop); @@ -272,7 +282,7 @@ void renderStringListProperty(Property* prop, const std::string& ownerName, ImGuiInputTextFlags_EnterReturnsTrue ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (hasNewValue) { @@ -297,7 +307,8 @@ void renderStringListProperty(Property* prop, const std::string& ownerName, } void renderDoubleProperty(properties::Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); DoubleProperty* p = static_cast(prop); @@ -310,7 +321,7 @@ void renderDoubleProperty(properties::Property* prop, const std::string& ownerNa ImGui::SliderFloat(name.c_str(), &value, min, max, "%.5f", p->exponent()); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != static_cast(p->value())) { @@ -321,7 +332,8 @@ void renderDoubleProperty(properties::Property* prop, const std::string& ownerNa } void renderIntProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); IntProperty* p = static_cast(prop); @@ -334,7 +346,7 @@ void renderIntProperty(Property* prop, const std::string& ownerName, ImGui::SliderInt(name.c_str(), &value, min, max); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -345,7 +357,8 @@ void renderIntProperty(Property* prop, const std::string& ownerName, } void renderIVec2Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); IVec2Property* p = static_cast(prop); @@ -362,7 +375,7 @@ void renderIVec2Property(Property* prop, const std::string& ownerName, max ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -377,7 +390,8 @@ void renderIVec2Property(Property* prop, const std::string& ownerName, } void renderIVec3Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); IVec3Property* p = static_cast(prop); @@ -395,7 +409,7 @@ void renderIVec3Property(Property* prop, const std::string& ownerName, max ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -409,7 +423,8 @@ void renderIVec3Property(Property* prop, const std::string& ownerName, } void renderIVec4Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); IVec4Property* p = static_cast(prop); @@ -427,7 +442,7 @@ void renderIVec4Property(Property* prop, const std::string& ownerName, max ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -441,7 +456,8 @@ void renderIVec4Property(Property* prop, const std::string& ownerName, } void renderFloatProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); FloatProperty* p = static_cast(prop); @@ -453,7 +469,7 @@ void renderFloatProperty(Property* prop, const std::string& ownerName, float max = p->maxValue(); ImGui::SliderFloat(name.c_str(), &value, min, max, "%.5f", p->exponent()); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -464,7 +480,8 @@ void renderFloatProperty(Property* prop, const std::string& ownerName, } void renderVec2Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); Vec2Property* p = static_cast(prop); @@ -484,7 +501,7 @@ void renderVec2Property(Property* prop, const std::string& ownerName, p->exponent() ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -499,7 +516,8 @@ void renderVec2Property(Property* prop, const std::string& ownerName, } void renderVec3Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); Vec3Property* p = static_cast(prop); @@ -527,7 +545,7 @@ void renderVec3Property(Property* prop, const std::string& ownerName, ); } if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -542,7 +560,8 @@ void renderVec3Property(Property* prop, const std::string& ownerName, } void renderVec4Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); Vec4Property* p = static_cast(prop); @@ -570,7 +589,7 @@ void renderVec4Property(Property* prop, const std::string& ownerName, ); } if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (value != p->value()) { @@ -585,7 +604,8 @@ void renderVec4Property(Property* prop, const std::string& ownerName, } void renderDVec2Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); DVec2Property* p = static_cast(prop); @@ -604,7 +624,7 @@ void renderDVec2Property(Property* prop, const std::string& ownerName, p->exponent() ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (glm::dvec2(value) != p->value()) { @@ -619,7 +639,8 @@ void renderDVec2Property(Property* prop, const std::string& ownerName, } void renderDVec3Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); DVec3Property* p = static_cast(prop); @@ -639,7 +660,7 @@ void renderDVec3Property(Property* prop, const std::string& ownerName, p->exponent() ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (changed) { @@ -654,7 +675,8 @@ void renderDVec3Property(Property* prop, const std::string& ownerName, } void renderDVec4Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); DVec4Property* p = static_cast(prop); @@ -674,7 +696,7 @@ void renderDVec4Property(Property* prop, const std::string& ownerName, p->exponent() ); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (glm::dvec4(value) != p->value()) { @@ -689,7 +711,8 @@ void renderDVec4Property(Property* prop, const std::string& ownerName, } void renderDMat2Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); DMat2Property* p = static_cast(prop); @@ -715,7 +738,7 @@ void renderDMat2Property(Property* prop, const std::string& ownerName, ImGui::SliderFloat2("[1]", glm::value_ptr(value[1]), min, max, "%.5f", p->exponent()); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (glm::dmat2(value) != p->value()) { @@ -730,7 +753,8 @@ void renderDMat2Property(Property* prop, const std::string& ownerName, } void renderDMat3Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); DMat3Property* p = static_cast(prop); @@ -760,7 +784,7 @@ void renderDMat3Property(Property* prop, const std::string& ownerName, ImGui::SliderFloat3("[2]", glm::value_ptr(value[2]), min, max, "%.5f", p->exponent()); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (glm::dmat3(value) != p->value()) { @@ -775,7 +799,8 @@ void renderDMat3Property(Property* prop, const std::string& ownerName, } void renderDMat4Property(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); DMat4Property* p = static_cast(prop); @@ -808,7 +833,7 @@ void renderDMat4Property(Property* prop, const std::string& ownerName, ImGui::SliderFloat4("[3]", glm::value_ptr(value[3]), min, max, "%.5f", p->exponent()); if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } if (glm::dmat4(value) != p->value()) { @@ -823,7 +848,8 @@ void renderDMat4Property(Property* prop, const std::string& ownerName, } void renderTriggerProperty(Property* prop, const std::string& ownerName, - IsRegularProperty isRegular, ShowToolTip showTooltip) + IsRegularProperty isRegular, ShowToolTip showTooltip, + double tooltipDelay) { ghoul_assert(prop, "prop must not be nullptr"); std::string name = prop->guiName(); @@ -834,7 +860,7 @@ void renderTriggerProperty(Property* prop, const std::string& ownerName, executeScript(prop->fullyQualifiedIdentifier(), "nil", isRegular); } if (showTooltip) { - renderTooltip(prop); + renderTooltip(prop, tooltipDelay); } ImGui::PopID(); From bb74db4d28ec1760849dd9ef3244eaaa298cf423 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Dec 2017 12:30:51 -0500 Subject: [PATCH 03/11] Fix error in Lua-serialization of StringListProperty --- src/properties/stringlistproperty.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/properties/stringlistproperty.cpp b/src/properties/stringlistproperty.cpp index ef137f585f..168298a8f4 100644 --- a/src/properties/stringlistproperty.cpp +++ b/src/properties/stringlistproperty.cpp @@ -61,6 +61,7 @@ bool toLuaConversion(lua_State* state, std::vector val) { lua_pushstring(state, std::to_string(i).c_str()); lua_pushstring(state, v.c_str()); lua_settable(state, -3); + ++i; } return true; From bce8e71d9bf285f0eb55bdc7c80bd14cf9719684 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Dec 2017 13:48:45 -0500 Subject: [PATCH 04/11] Another fix for StringListProperty Do not crash if included script file does not provide a documentation key --- src/properties/stringlistproperty.cpp | 2 +- src/scripting/scriptengine.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/properties/stringlistproperty.cpp b/src/properties/stringlistproperty.cpp index 168298a8f4..b3ce643791 100644 --- a/src/properties/stringlistproperty.cpp +++ b/src/properties/stringlistproperty.cpp @@ -58,7 +58,7 @@ bool toLuaConversion(lua_State* state, std::vector val) { int i = 1; for (std::string& v : val) { - lua_pushstring(state, std::to_string(i).c_str()); + lua_pushnumber(state, i); lua_pushstring(state, v.c_str()); lua_settable(state, -3); ++i; diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index c8a93bbc5f..a00f3d72dd 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -274,6 +274,7 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library, ghoul::lua::runScriptFile(state, absPath(script)); library.documentations.clear(); + // Then, we extract the documentation information from the file lua_pushstring(state, "documentation"); lua_gettable(state, -2); @@ -303,10 +304,9 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library, lua_pop(state, 1); library.documentations.push_back({ name, arguments, documentation }); - } - lua_pop(state, 1); } + lua_pop(state, 1); } } From c9aedb084b9a32fda15f14420b8ca2d49d75bf73 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Dec 2017 14:58:18 -0500 Subject: [PATCH 05/11] Add Lua functions to query keyboard bindings and remove individual keybinds Add core script file that defines possibility of rebinding keyboard commands to a different key Enable the execution of global customization scripts Make `scene_helper.lua` a script automatically included in the ScriptScheduler --- data/scene/atmosphereearth.scene | 2 +- data/scene/dawn.scene | 2 +- data/scene/default.scene | 6 +- data/scene/fieldlines.scene | 2 +- data/scene/juno.scene | 6 +- data/scene/newhorizons.scene | 6 +- data/scene/osirisrex.scene | 6 +- data/scene/rosetta.scene | 6 +- data/scene/volumetricmilkyway.scene | 2 +- data/scene/voyager.scene | 6 +- .../openspace/engine/configurationmanager.h | 3 + include/openspace/engine/openspaceengine.h | 4 +- .../openspace/interaction/keybindingmanager.h | 21 ++++--- include/openspace/util/keys.h | 1 + openspace.cfg | 7 +++ scripts/common_scripts.lua | 20 ++++++ scripts/scene_helper.lua | 21 ++++++- src/engine/configurationmanager.cpp | 2 + src/engine/configurationmanager_doc.inl | 8 +++ src/engine/openspaceengine.cpp | 40 ++++++++++++ src/interaction/keybindingmanager.cpp | 62 ++++++++++++++++++- src/interaction/keybindingmanager_lua.inl | 61 +++++++++++++++++- src/scene/scene.cpp | 3 + src/util/keys.cpp | 5 ++ 24 files changed, 258 insertions(+), 44 deletions(-) create mode 100644 scripts/common_scripts.lua diff --git a/data/scene/atmosphereearth.scene b/data/scene/atmosphereearth.scene index 4bfbb611d8..7688996950 100644 --- a/data/scene/atmosphereearth.scene +++ b/data/scene/atmosphereearth.scene @@ -19,7 +19,7 @@ function postInitialization() created and initialized, but before the first render call. This is the place to set graphical settings for the renderables. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.Enabled", false) diff --git a/data/scene/dawn.scene b/data/scene/dawn.scene index 17af47aae4..68c09bd636 100644 --- a/data/scene/dawn.scene +++ b/data/scene/dawn.scene @@ -19,7 +19,7 @@ function postInitialization() created and initialized, but before the first render call. This is the place to set graphical settings for the renderables. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.Enabled", false) diff --git a/data/scene/default.scene b/data/scene/default.scene index 4e28cbb9a4..7fe255644f 100644 --- a/data/scene/default.scene +++ b/data/scene/default.scene @@ -18,8 +18,6 @@ local vrt_folders = { } } -dofile(openspace.absPath('${SCRIPTS}/scene_helper.lua')) - function preInitialization() --[[ The scripts in this function are executed after the scene is loaded but before the @@ -74,7 +72,7 @@ function preInitialization() end function postInitialization() - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.addVirtualProperty( "BoolProperty", @@ -105,7 +103,7 @@ function postInitialization() -- Defined in scene_helper.lua -- Used to create focus buttons for a subset of scenegraph nodes - mark_interesting_nodes({ + openspace.mark_interesting_nodes({ "Earth", "Mars", "Moon" }) end diff --git a/data/scene/fieldlines.scene b/data/scene/fieldlines.scene index f83e512809..eec14509f8 100644 --- a/data/scene/fieldlines.scene +++ b/data/scene/fieldlines.scene @@ -19,7 +19,7 @@ function postInitialization() created and initialized, but before the first render call. This is the place to set graphical settings for the renderables. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.Enabled", false) diff --git a/data/scene/juno.scene b/data/scene/juno.scene index 1a9a1a3924..23fc7bcab7 100755 --- a/data/scene/juno.scene +++ b/data/scene/juno.scene @@ -1,5 +1,3 @@ -dofile(openspace.absPath('${SCRIPTS}/scene_helper.lua')) - function preInitialization() --[[ The scripts in this function are executed after the scene is loaded but before the @@ -27,7 +25,7 @@ function postInitialization() created and initialized, but before the first render call. This is the place to set graphical settings for the renderables. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.Enabled", false) @@ -41,7 +39,7 @@ function postInitialization() openspace.printInfo("Done setting default values") - mark_interesting_nodes({ + openspace.mark_interesting_nodes({ "Jupiter", "Juno" }) end diff --git a/data/scene/newhorizons.scene b/data/scene/newhorizons.scene index 0dd32ec865..1fa63a8573 100644 --- a/data/scene/newhorizons.scene +++ b/data/scene/newhorizons.scene @@ -19,8 +19,6 @@ charon_image = "textures/NH_Charon_mosaic.png" charon_height = "textures/NH_Charon_DTM.png" -- charon_height = "textures/NH_Charon_DTM_8192.png" -dofile(openspace.absPath('${SCRIPTS}/scene_helper.lua')) - function preInitialization() --[[ The scripts in this function are executed after the scene is loaded but before the @@ -28,7 +26,7 @@ function preInitialization() which the scene should start and other settings that might determine initialization critical objects. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.spice.loadKernel("${SPICE}/naif0012.tls") openspace.spice.loadKernel("${SPICE}/pck00010.tpc") @@ -193,7 +191,7 @@ function postInitialization() -- Defined in scene_helper.lua -- Used to create focus buttons for a subset of scenegraph nodes - mark_interesting_nodes({ + openspace.mark_interesting_nodes({ "Pluto", "NewHorizons", "Charon" }) end diff --git a/data/scene/osirisrex.scene b/data/scene/osirisrex.scene index a1b21a8e3c..ca77dc7cdf 100644 --- a/data/scene/osirisrex.scene +++ b/data/scene/osirisrex.scene @@ -1,7 +1,5 @@ KernelCase = 2 -- Right now we only have the image times for case 2 -dofile(openspace.absPath('${SCRIPTS}/scene_helper.lua')) - function preInitialization() --[[ The scripts in this function are executed after the scene is loaded but before the @@ -83,7 +81,7 @@ function postInitialization() created and initialized, but before the first render call. This is the place to set graphical settings for the renderables. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.Enabled", false) @@ -106,7 +104,7 @@ function postInitialization() openspace.navigation.resetCameraDirection() - mark_interesting_nodes({ + openspace.mark_interesting_nodes({ "OsirisRex", "BennuBarycenter", "Earth" }) end diff --git a/data/scene/rosetta.scene b/data/scene/rosetta.scene index 213ec20465..8c6f0acd04 100644 --- a/data/scene/rosetta.scene +++ b/data/scene/rosetta.scene @@ -1,5 +1,3 @@ -dofile(openspace.absPath('${SCRIPTS}/scene_helper.lua')) - function preInitialization() --[[ The scripts in this function are executed after the scene is loaded but before the @@ -93,7 +91,7 @@ function postInitialization() created and initialized, but before the first render call. This is the place to set graphical settings for the renderables. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.Enabled", false) @@ -107,7 +105,7 @@ function postInitialization() openspace.printInfo("Done setting default values") - mark_interesting_nodes({ + openspace.mark_interesting_nodes({ "Pluto", "NewHorizons", "Charon" }) end diff --git a/data/scene/volumetricmilkyway.scene b/data/scene/volumetricmilkyway.scene index 4b2b5ecabf..0a82b3b19a 100644 --- a/data/scene/volumetricmilkyway.scene +++ b/data/scene/volumetricmilkyway.scene @@ -19,7 +19,7 @@ function postInitialization() created and initialized, but before the first render call. This is the place to set graphical settings for the renderables. ]]-- - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.printInfo("Setting default values") openspace.setPropertyValue("Sun.renderable.Enabled", false) diff --git a/data/scene/voyager.scene b/data/scene/voyager.scene index 4b3d77c7fc..7be5b4a3cf 100644 --- a/data/scene/voyager.scene +++ b/data/scene/voyager.scene @@ -1,5 +1,3 @@ -dofile(openspace.absPath('${SCRIPTS}/scene_helper.lua')) - function preInitialization() --[[ The scripts in this function are executed after the scene is loaded but before the @@ -19,7 +17,7 @@ end function postInitialization() openspace.printInfo("Setting default values") - set_default_gui_sorting() + openspace.set_default_gui_sorting() openspace.setPropertyValueSingle("Global Properties.GlobeBrowsing.GdalWrapper.LogGdalErrors", false) openspace.setPropertyValueSingle("Earth.RenderableGlobe.Debug.LevelByProjectedAreaElseDistance", false) @@ -30,7 +28,7 @@ function postInitialization() -- Defined in scene_helper.lua -- Used to create focus buttons for a subset of scenegraph nodes - mark_interesting_nodes({ + openspace.mark_interesting_nodes({ "Earth", "Voyager 1", "Voyager 2", "Jupiter", "Saturn", "Uranus", "Neptune" }) end diff --git a/include/openspace/engine/configurationmanager.h b/include/openspace/engine/configurationmanager.h index 489435dac6..8086898f35 100644 --- a/include/openspace/engine/configurationmanager.h +++ b/include/openspace/engine/configurationmanager.h @@ -51,6 +51,9 @@ public: /// The key that stores the location of the SGCT configuration file that is used on /// application launch static const std::string KeyConfigSgct; + /// The key that defines a list of scripts for global customization that get executed + /// regardless of which scene is loaded + static const std::string KeyGlobalCustomizationScripts; /// The part of the key that defines the type static const std::string PartType; /// The part of the key that defines the file diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 987e03bf56..860c9f69bc 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -104,8 +104,6 @@ public: void writeDocumentation(); void toggleShutdownMode(); - void runPostInitializationScripts(const std::string& sceneDescription); - // Guaranteed to return a valid pointer ConfigurationManager& configurationManager(); LuaConsole& console(); @@ -178,6 +176,8 @@ private: void gatherCommandlineArguments(); void loadFonts(); void runPreInitializationScripts(const std::string& sceneDescription); + void runPostInitializationScripts(const std::string& sceneDescription); + void runGlobalCustomizationScripts(const std::string& sceneDescription); void configureLogging(); // Components diff --git a/include/openspace/interaction/keybindingmanager.h b/include/openspace/interaction/keybindingmanager.h index 7426610a99..b2f97ba854 100644 --- a/include/openspace/interaction/keybindingmanager.h +++ b/include/openspace/interaction/keybindingmanager.h @@ -40,6 +40,15 @@ namespace openspace::interaction { class KeyBindingManager : public DocumentationGenerator { public: + using IsLocalBind = ghoul::Boolean; + using IsSynchronized = ghoul::Boolean; + + struct KeyInformation { + std::string command; + IsSynchronized synchronization; + std::string documentation; + }; + KeyBindingManager(); ~KeyBindingManager() = default; @@ -59,19 +68,17 @@ public: std::string documentation = "" ); + void removeKeyBinding(const std::string& key); + + std::vector> keyBinding( + const std::string& key) const; + static scripting::LuaLibrary luaLibrary(); // Callback functions void keyboardCallback(Key key, KeyModifier modifier, KeyAction action); private: - using Synchronized = ghoul::Boolean; - - struct KeyInformation { - std::string command; - Synchronized synchronization; - std::string documentation; - }; std::string generateJson() const override; diff --git a/include/openspace/util/keys.h b/include/openspace/util/keys.h index 0d30d02379..3cd47b36e5 100644 --- a/include/openspace/util/keys.h +++ b/include/openspace/util/keys.h @@ -217,6 +217,7 @@ struct KeyWithModifier { KeyWithModifier stringToKey(std::string str); bool operator<(const KeyWithModifier& lhs, const KeyWithModifier& rhs); +bool operator==(const KeyWithModifier& lhs, const KeyWithModifier& rhs); static const std::map KeyModifierMapping = { { "SHIFT", KeyModifier::Shift }, diff --git a/openspace.cfg b/openspace.cfg index 8c2e233c27..bbb6b007fc 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -36,6 +36,13 @@ return { TasksRoot = "${OPENSPACE_DATA}/tasks", + -- These scripts are executed after the postInitialization of each scene, thus making + -- it possible to have global overrides to default values or execute other scripts + -- regardless of the scene that is loaded + GlobalCustomizationScripts = { + "${SCRIPTS}/customization.lua" + }, + Paths = { SCRIPTS = "${BASE_PATH}/scripts", SHADERS = "${BASE_PATH}/shaders", diff --git a/scripts/common_scripts.lua b/scripts/common_scripts.lua new file mode 100644 index 0000000000..5c3475edc5 --- /dev/null +++ b/scripts/common_scripts.lua @@ -0,0 +1,20 @@ +openspace.documentation = { + { + Name = "rebindKey", + Arguments = "string, string", + Documentation = "Rebinds all scripts from the old key (first argument) to the " .. + "new key (second argument)." + } +} + +openspace.rebindKey = function(old_key, new_key) + local t = openspace.getKeyBinding(old_key) + openspace.clearKey(old_key) + for _, v in pairs(t) do + if v["Remote"] then + openspace.bindKey(new_key, v["Command"]) + else + openspace.bindKeyLocal(new_key, v["Command"]) + end + end +end diff --git a/scripts/scene_helper.lua b/scripts/scene_helper.lua index ce611a7df9..e8d19c7e98 100644 --- a/scripts/scene_helper.lua +++ b/scripts/scene_helper.lua @@ -1,4 +1,21 @@ -mark_interesting_nodes = function(nodes) +openspace.documentation = { + { + Name = "mark_interating_nodes", + Arguments = "List of nodes", + Documentation = "This function marks the scene graph nodes identified by name " .. + "as interesting, which will provide shortcut access to focus buttons and " .. + "featured properties." + }, + { + Name = "set_default_gui_sorting", + Arguments = "", + Documentation = "This function sets the default GUI sorting for the space " .. + "environment to increasing size, from solar system, through Milky Way, " .. + "Universe and finishing with other elements" + } +} + +openspace.mark_interesting_nodes = function(nodes) for _, n in pairs(nodes) do if openspace.hasSceneGraphNode(n) then openspace.addTag(n, "GUI.Interesting") @@ -6,7 +23,7 @@ mark_interesting_nodes = function(nodes) end end -set_default_gui_sorting = function() +openspace.set_default_gui_sorting = function() openspace.setPropertyValueSingle( 'Global Properties.ImGUI.Main.Properties.Ordering', { diff --git a/src/engine/configurationmanager.cpp b/src/engine/configurationmanager.cpp index 9df4ad3d66..d72afc6453 100644 --- a/src/engine/configurationmanager.cpp +++ b/src/engine/configurationmanager.cpp @@ -48,6 +48,8 @@ const string ConfigurationManager::KeyPaths = "Paths"; const string ConfigurationManager::KeyCache = "CACHE"; const string ConfigurationManager::KeyFonts = "Fonts"; const string ConfigurationManager::KeyConfigSgct = "SGCTConfig"; +const string ConfigurationManager::KeyGlobalCustomizationScripts = + "GlobalCustomizationScripts"; const string ConfigurationManager::PartType = "Type"; const string ConfigurationManager::PartFile = "File"; diff --git a/src/engine/configurationmanager_doc.inl b/src/engine/configurationmanager_doc.inl index bf1bbdf90b..3415e8baef 100644 --- a/src/engine/configurationmanager_doc.inl +++ b/src/engine/configurationmanager_doc.inl @@ -52,6 +52,14 @@ documentation::Documentation ConfigurationManager::Documentation() { "time and other scene-specific settings. More information is provided in " "the Scene documentation." }, + { + ConfigurationManager::KeyGlobalCustomizationScripts, + new StringListVerifier, + Optional::Yes, + "This value names a list of scripts that get executed after initialization " + "of any scene. These scripts can be used for user-specific customization, " + "such as a global rebinding of keys from the default." + }, { ConfigurationManager::KeyConfigTasksRoot, new StringAnnotationVerifier( diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 47267f22f9..0f629da564 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -720,6 +720,13 @@ void OpenSpaceEngine::loadScene(const std::string& scenePath) { LFATALC(e.component, e.message); } + // Run the global configuration scripts + try { + runGlobalCustomizationScripts(scenePath); + } catch (ghoul::RuntimeError& e) { + LERRORC(e.component, e.message); + } + // Write keyboard documentation. if (configurationManager().hasKey(ConfigurationManager::KeyKeyboardShortcuts)) { keyBindingManager().writeDocumentation( @@ -887,6 +894,36 @@ void OpenSpaceEngine::runPostInitializationScripts(const std::string& sceneDescr } } +void OpenSpaceEngine::runGlobalCustomizationScripts(const std::string& sceneDescription) { + // @CLEANUP: Move this into the scene loading? ---abock + LINFO("Running Global initialization scripts"); + ghoul::lua::LuaState state; + OsEng.scriptEngine().initializeLuaState(state); + + // First execute the script to get all global variables + ghoul::lua::runScriptFile(state, absPath(sceneDescription)); + + std::string k = ConfigurationManager::KeyGlobalCustomizationScripts; + if (_configurationManager->hasKey(k)) { + ghoul::Dictionary dict = _configurationManager->value(k); + for (int i = 1; i <= dict.size(); ++i) { + std::string script = dict.value(std::to_string(i)); + + if (FileSys.fileExists(script)) { + try { + LINFO("Running global customization script: " << script); + ghoul::lua::runScriptFile(state, absPath(script)); + } catch (ghoul::RuntimeError& e) { + LERRORC(e.component, e.message); + } + } + else { + LDEBUG("Ignoring non-existing script file: " << script); + } + } + } +} + void OpenSpaceEngine::loadFonts() { ghoul::Dictionary fonts; configurationManager().getValue(ConfigurationManager::KeyFonts, fonts); @@ -1506,6 +1543,9 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { "string, string", "Removes a tag (second argument) from a scene graph node (first argument)" } + }, + { + absPath("${SCRIPTS}/common_scripts.lua") } }; } diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 231d278846..e7752bf32f 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -86,7 +86,7 @@ void KeyBindingManager::bindKeyLocal(Key key, KeyModifier modifier, { key, modifier }, { std::move(luaCommand), - Synchronized::No, + IsSynchronized::No, std::move(documentation) } }); @@ -99,12 +99,55 @@ void KeyBindingManager::bindKey(Key key, KeyModifier modifier, { key, modifier }, { std::move(luaCommand), - Synchronized::Yes, + IsSynchronized::Yes, std::move(documentation) } }); } +void KeyBindingManager::removeKeyBinding(const std::string& key) { + // Erase-remove idiom does not work for std::multimap so we have to do this on foot + + KeyWithModifier k = stringToKey(key); + + for (auto it = _keyLua.begin(); it != _keyLua.end(); ) { + // If the current iterator is the key that we are looking for, delete it + // (std::multimap::erase will return the iterator to the next element for us) + if (it->first == k) { + it = _keyLua.erase(it); + } + else { + // We if it is not, we continue iteration + ++it; + } + } + + // _keyLua.erase( + // std::remove_if( + // _keyLua.begin(), + // _keyLua.end(), + // [key](const std::pair& val) { + // KeyWithModifier k = stringToKey(key); + // return val.first == k; + // } + // ), + // _keyLua.end() + // ); +} + +std::vector> +KeyBindingManager::keyBinding(const std::string& key) const +{ + std::vector> result; + + KeyWithModifier k = stringToKey(key); + auto itRange = _keyLua.equal_range(k); + for (auto it = itRange.first; it != itRange.second; ++it) { + result.push_back({ it->first, it->second }); + } + return result; +} + std::string KeyBindingManager::generateJson() const { std::stringstream json; json << "["; @@ -146,6 +189,12 @@ scripting::LuaLibrary KeyBindingManager::luaLibrary() { "", "Clear all key bindings" }, + { + "clearKey", + &luascriptfunctions::clearKey, + "string", + "Unbinds all of the scripts that are bound to the provided key + modifier" + }, { "bindKey", &luascriptfunctions::bindKey, @@ -165,6 +214,15 @@ scripting::LuaLibrary KeyBindingManager::luaLibrary() { "that is to be executed, and the optional third argument is a human " "readable description of the command for documentation purposes." }, + { + "getKeyBinding", + &luascriptfunctions::getKeyBindings, + "string", + "Returns a list of information about the keybindings for the provided " + "key. Each element in the list is a table describing the 'Command' that " + "was bound and whether it was a 'Remote' script or not." + + } } }; } diff --git a/src/interaction/keybindingmanager_lua.inl b/src/interaction/keybindingmanager_lua.inl index 11618975d7..6ea2cfa44d 100644 --- a/src/interaction/keybindingmanager_lua.inl +++ b/src/interaction/keybindingmanager_lua.inl @@ -118,17 +118,72 @@ int bindKeyLocal(lua_State* L) { return 0; } +/** +* \ingroup LuaScripts +* getKeyBindings(string): +* Returns the strings of the script that are bound to the passed key and whether they were +* local or remote key binds +*/ +int getKeyBindings(lua_State* L) { + int nArguments = lua_gettop(L); + if (nArguments != 1) { + return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); + } + + std::string key = luaL_checkstring(L, -1); + + using KeyInformation = interaction::KeyBindingManager::KeyInformation; + + std::vector> info = + OsEng.keyBindingManager().keyBinding(key); + + lua_createtable(L, static_cast(info.size()), 0); + int i = 1; + for (const std::pair& it : info) { + lua_pushnumber(L, i); + + lua_createtable(L, 2, 0); + lua_pushstring(L, "Command"); + lua_pushstring(L, it.second.command.c_str()); + lua_settable(L, -3); + lua_pushstring(L, "Remote"); + lua_pushboolean(L, it.second.synchronization); + lua_settable(L, -3); + + lua_settable(L, -3); + ++i; + } + return 1; +} + +/** +* \ingroup LuaScripts +* clearKey(string): +* Clears the keybinding of the key named as argument +*/ +int clearKey(lua_State* L) { + int nArguments = lua_gettop(L); + if (nArguments != 1) { + return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments); + } + + std::string key = luaL_checkstring(L, -1); + + OsEng.keyBindingManager().removeKeyBinding(key); + + return 0; +} + /** * \ingroup LuaScripts * clearKeys(): * Clears all key bindings */ int clearKeys(lua_State* L) { - using ghoul::lua::luaTypeToString; - int nArguments = lua_gettop(L); - if (nArguments != 0) + if (nArguments != 0) { return luaL_error(L, "Expected %i arguments, got %i", 0, nArguments); + } OsEng.keyBindingManager().resetKeyBindings(); diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 0478b80f73..6ff87f9d0f 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -489,6 +489,9 @@ scripting::LuaLibrary Scene::luaLibrary() { "Checks whether the specifies SceneGraphNode is present in the current " "scene" } + }, + { + absPath("${SCRIPTS}/scene_helper.lua") } }; } diff --git a/src/util/keys.cpp b/src/util/keys.cpp index 26402835b8..986eecc49e 100644 --- a/src/util/keys.cpp +++ b/src/util/keys.cpp @@ -119,6 +119,11 @@ bool operator<(const KeyWithModifier& lhs, const KeyWithModifier& rhs) { } } +bool operator==(const KeyWithModifier& lhs, const KeyWithModifier& rhs) { + return (lhs.key == rhs.key) && (lhs.modifier == rhs.modifier); +} + + } // namespace openspace namespace std { From d0f66dc75474236b99b26fcec63bcefe9b451f35 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Dec 2017 15:31:48 -0500 Subject: [PATCH 06/11] Add customization.lua to the gitignore list --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4dda8bd97a..8d9383f05c 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,4 @@ data/scene/digitaluniverse/*/textures/*.jpg data/scene/digitaluniverse/*/textures/*.pbm data/scene/digitaluniverse/*/textures/*.png data/scene/digitaluniverse/*/textures/*.sgi +customization.lua From 966b3b5ff4a944486d75d45a38b8e2114af0da63 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Dec 2017 16:18:35 -0500 Subject: [PATCH 07/11] Add ESRI World Imagery WMS file and reference in Earth.mod --- data/scene/earth/earth.mod | 4 ++++ .../ESRI/World_Imagery.wms | 21 +++++++++++++++++++ data/scene/moon/moon.mod | 4 ---- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 data/scene/earth/map_service_configs/ESRI/World_Imagery.wms diff --git a/data/scene/earth/earth.mod b/data/scene/earth/earth.mod index 6155bed1fd..b81fe35ee2 100644 --- a/data/scene/earth/earth.mod +++ b/data/scene/earth/earth.mod @@ -99,6 +99,10 @@ return { Name = "ESRI Imagery World 2D", FilePath = "map_service_configs/ESRI/ESRI_Imagery_World_2D.wms", }, + { + Name = "World Imagery", + FilePath = "map_service_configs/ESRI/World_Imagery.wms", + }, { Name = "Temporal VIIRS SNPP", Type = "TemporalTileLayer", diff --git a/data/scene/earth/map_service_configs/ESRI/World_Imagery.wms b/data/scene/earth/map_service_configs/ESRI/World_Imagery.wms new file mode 100644 index 0000000000..93ec2bae64 --- /dev/null +++ b/data/scene/earth/map_service_configs/ESRI/World_Imagery.wms @@ -0,0 +1,21 @@ + + + http://wi.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/WMTS/tile/1.0.0/World_Imagery/default/default/${z}/${y}/${x}.jpg + + + -180.0 + 90 + 180 + -89.999999 + 19 + 2 + 1 + top + + EPSG:4326 + 256 + 256 + 3 + 5 + false + diff --git a/data/scene/moon/moon.mod b/data/scene/moon/moon.mod index 50af1eccbf..61f0ec2cf7 100644 --- a/data/scene/moon/moon.mod +++ b/data/scene/moon/moon.mod @@ -23,10 +23,6 @@ return { Layers = { ColorLayers = { -- MoonTrek based servers - { - Name = "Apollo 16 Metric Cam Image Mosaic", - FilePath = "map_service_configs/MoonTrek/Apollo16_Metric_Cam_Image_Mosaic.wms" - }, -- Utah based servers { Name = "ClemUvvis", From 3578f528682fc31e3111cadc2d2288932c612b3c Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 8 Dec 2017 16:24:53 -0500 Subject: [PATCH 08/11] Make use of correct file path in TransferFunction (closes #402) --- src/rendering/transferfunction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rendering/transferfunction.cpp b/src/rendering/transferfunction.cpp index efe3f4fdb6..55828788a9 100644 --- a/src/rendering/transferfunction.cpp +++ b/src/rendering/transferfunction.cpp @@ -76,7 +76,7 @@ void TransferFunction::setPath(const std::string& filepath) { } _filepath = f; _file = std::make_unique( - filepath, + _filepath, ghoul::filesystem::File::RawPath::Yes ); _needsUpdate = true; From 44586a0759a28f3654daaf1516e433e9d24f199e Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 11 Dec 2017 09:03:23 -0500 Subject: [PATCH 09/11] Remove EarthAtmosphere and MarsAtmosphere from the list of interesting nodes --- data/scene/default.scene | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/scene/default.scene b/data/scene/default.scene index 051c39c1ef..f58926c12d 100644 --- a/data/scene/default.scene +++ b/data/scene/default.scene @@ -114,7 +114,7 @@ function postInitialization() -- Defined in scene_helper.lua -- Used to create focus buttons for a subset of scenegraph nodes mark_interesting_nodes({ - "Earth", "EarthAtmosphere", "Mars", "MarsAtmosphere", "Moon" + "Earth", "Mars", "Moon" }) end From 7dfa3374fcc5b676925cf311b969930826788c78 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 11 Dec 2017 11:22:22 -0500 Subject: [PATCH 10/11] Update version number Correctly layout tooltips in space/time widget Fall back on old Digital Universe stars Move settings of tooltip delay into each GuiComponent --- CMakeLists.txt | 4 +- data/scene/newhorizons.scene | 3 + .../digitaluniverse/digitaluniverse.data | 2 +- modules/imgui/include/guicomponent.h | 6 ++ modules/imgui/include/guipropertycomponent.h | 5 -- modules/imgui/src/gui.cpp | 26 +++++++ modules/imgui/src/guicomponent.cpp | 8 +++ modules/imgui/src/guipropertycomponent.cpp | 8 --- modules/imgui/src/guispacetimecomponent.cpp | 68 +++++++++++-------- .../rendering/renderableplaneprojection.cpp | 2 - 10 files changed, 85 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a8d682ffa..c5f740804c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,9 @@ project(OpenSpace) message(STATUS "Generating OpenSpace project") set(OPENSPACE_VERSION_MAJOR 0) -set(OPENSPACE_VERSION_MINOR 10) +set(OPENSPACE_VERSION_MINOR 11) set(OPENSPACE_VERSION_PATCH 0) -set(OPENSPACE_VERSION_STRING "prerelease-15 (ASTC)") +set(OPENSPACE_VERSION_STRING "prerelease-16 (Beta) RC2") set(OPENSPACE_BASE_DIR "${PROJECT_SOURCE_DIR}") set(OPENSPACE_APPS_DIR "${OPENSPACE_BASE_DIR}/apps") diff --git a/data/scene/newhorizons.scene b/data/scene/newhorizons.scene index 1fa63a8573..34c5545542 100644 --- a/data/scene/newhorizons.scene +++ b/data/scene/newhorizons.scene @@ -194,6 +194,9 @@ function postInitialization() openspace.mark_interesting_nodes({ "Pluto", "NewHorizons", "Charon" }) + + openspace.printInfo("Receiving four errors about SCLK_DATA_TYPE_98 are expected.") + end return { diff --git a/data/scene/stars/digitaluniverse/digitaluniverse.data b/data/scene/stars/digitaluniverse/digitaluniverse.data index f5379331c4..e1ea7be746 100644 --- a/data/scene/stars/digitaluniverse/digitaluniverse.data +++ b/data/scene/stars/digitaluniverse/digitaluniverse.data @@ -1,7 +1,7 @@ return { FileRequest = { { Identifier = "stars_textures", Destination = "textures", Version = 1 }, - { Identifier = "stars_du", Destination = "speck", Version = 2 }, + { Identifier = "stars_du", Destination = "speck", Version = 1 }, { Identifier = "stars_colormap", Destination = ".", Version = 1 }, }, } \ No newline at end of file diff --git a/modules/imgui/include/guicomponent.h b/modules/imgui/include/guicomponent.h index 9d6e16a998..af94b3815d 100644 --- a/modules/imgui/include/guicomponent.h +++ b/modules/imgui/include/guicomponent.h @@ -69,12 +69,18 @@ public: /// Renders the individual subcomponents to the screen virtual void render() = 0; + void setShowHelpTooltip(bool showHelpTooltip); + void setShowHelpTooltipDelay(double delay); + protected: /// true if this component is enabled and visible on the screen properties::BoolProperty _isEnabled; /// if true this window is currently collapsed. This setting mirrors the /// ImGui internal state of the window properties::BoolProperty _isCollapsed; + + bool _showHelpTooltip; + double _tooltipDelay; }; } // namespace openspace::gui diff --git a/modules/imgui/include/guipropertycomponent.h b/modules/imgui/include/guipropertycomponent.h index 194850a723..9fe45049cd 100644 --- a/modules/imgui/include/guipropertycomponent.h +++ b/modules/imgui/include/guipropertycomponent.h @@ -59,8 +59,6 @@ public: void setVisibility(properties::Property::Visibility visibility); void setHasRegularProperties(bool hasOnlyRegularProperties); - void setShowHelpTooltip(bool showHelpTooltip); - void setShowHelpTooltipDelay(double delay); void render() override; @@ -78,9 +76,6 @@ protected: properties::BoolProperty _useTreeLayout; properties::StringListProperty _treeOrdering; - - bool _showHelpTooltip; - double _tooltipDelay; }; } // namespace openspace::gui diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index c26f1c35ea..da648ae7d4 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -313,10 +313,23 @@ GUI::GUI() { auto showHelpTextFunc = [this](){ + _help.setShowHelpTooltip(_showHelpText); + _filePath.setShowHelpTooltip(_showHelpText); +#ifdef GLOBEBROWSING_USE_GDAL + _globeBrowsing.setShowHelpTooltip(_showHelpText); +#endif // GLOBEBROWSING_USE_GDAL + _performance.setShowHelpTooltip(_showHelpText); _globalProperty.setShowHelpTooltip(_showHelpText); _property.setShowHelpTooltip(_showHelpText); _screenSpaceProperty.setShowHelpTooltip(_showHelpText); _virtualProperty.setShowHelpTooltip(_showHelpText); + _spaceTime.setShowHelpTooltip(_showHelpText); + _mission.setShowHelpTooltip(_showHelpText); +#ifdef OPENSPACE_MODULE_ISWA_ENABLED + _iswa.setShowHelpTooltip(_showHelpText); +#endif // OPENSPACE_MODULE_ISWA_ENABLED + _parallel.setShowHelpTooltip(_showHelpText); + _featuredProperties.setShowHelpTooltip(_showHelpText); }; showHelpTextFunc(); _showHelpText.onChange(std::move(showHelpTextFunc)); @@ -325,10 +338,23 @@ GUI::GUI() { auto helpTextDelayFunc = [this](){ + _help.setShowHelpTooltipDelay(_helpTextDelay); + _filePath.setShowHelpTooltipDelay(_helpTextDelay); +#ifdef GLOBEBROWSING_USE_GDAL + _globeBrowsing.setShowHelpTooltipDelay(_helpTextDelay); +#endif // GLOBEBROWSING_USE_GDAL + _performance.setShowHelpTooltipDelay(_helpTextDelay); _globalProperty.setShowHelpTooltipDelay(_helpTextDelay); _property.setShowHelpTooltipDelay(_helpTextDelay); _screenSpaceProperty.setShowHelpTooltipDelay(_helpTextDelay); _virtualProperty.setShowHelpTooltipDelay(_helpTextDelay); + _spaceTime.setShowHelpTooltipDelay(_helpTextDelay); + _mission.setShowHelpTooltipDelay(_helpTextDelay); +#ifdef OPENSPACE_MODULE_ISWA_ENABLED + _iswa.setShowHelpTooltipDelay(_helpTextDelay); +#endif // OPENSPACE_MODULE_ISWA_ENABLED + _parallel.setShowHelpTooltipDelay(_helpTextDelay); + _featuredProperties.setShowHelpTooltipDelay(_helpTextDelay); }; helpTextDelayFunc(); _helpTextDelay.onChange(std::move(helpTextDelayFunc)); diff --git a/modules/imgui/src/guicomponent.cpp b/modules/imgui/src/guicomponent.cpp index eab952eb7d..a30d275d24 100644 --- a/modules/imgui/src/guicomponent.cpp +++ b/modules/imgui/src/guicomponent.cpp @@ -57,6 +57,14 @@ void GuiComponent::setEnabled(bool enabled) { _isEnabled = enabled; } +void GuiComponent::setShowHelpTooltip(bool showHelpTooltip) { + _showHelpTooltip = showHelpTooltip; +} + +void GuiComponent::setShowHelpTooltipDelay(double delay) { + _tooltipDelay = delay; +} + void GuiComponent::initialize() {} void GuiComponent::initializeGL() {} diff --git a/modules/imgui/src/guipropertycomponent.cpp b/modules/imgui/src/guipropertycomponent.cpp index a7fef02322..a70ba6d359 100644 --- a/modules/imgui/src/guipropertycomponent.cpp +++ b/modules/imgui/src/guipropertycomponent.cpp @@ -183,14 +183,6 @@ void GuiPropertyComponent::setHasRegularProperties(bool hasOnlyRegularProperties _hasOnlyRegularProperties = hasOnlyRegularProperties; } -void GuiPropertyComponent::setShowHelpTooltip(bool showHelpTooltip) { - _showHelpTooltip = showHelpTooltip; -} - -void GuiPropertyComponent::setShowHelpTooltipDelay(double delay) { - _tooltipDelay = delay; -} - void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner) { if (owner->propertiesRecursive().empty()) { return; diff --git a/modules/imgui/src/guispacetimecomponent.cpp b/modules/imgui/src/guispacetimecomponent.cpp index 0bcbfd8b2c..2b02c73f51 100644 --- a/modules/imgui/src/guispacetimecomponent.cpp +++ b/modules/imgui/src/guispacetimecomponent.cpp @@ -35,6 +35,8 @@ #include #include +#include + namespace { static const ImVec2 Size = ImVec2(350, 500); @@ -44,6 +46,27 @@ namespace { "This value determines the minimum and maximum value for the delta time slider." }; + void showTooltip(const std::string& message, double delay) { + // Hackish way to enfore a window size for TextWrapped (SetNextWindowSize did not + // do the trick) + constexpr std::string::size_type FirstLineLength = 64; + if (ImGui::IsItemHovered() && GImGui->HoveredIdTimer > delay) { + ImGui::BeginTooltip(); + ImGui::Text( + "%s", + message.substr(0, std::min(message.size() - 1, FirstLineLength)).c_str() + ); + if (message.size() > FirstLineLength) { + ImGui::TextWrapped( + "%s", + message.substr(std::min(message.size() - 1, FirstLineLength)).c_str() + ); + } + + ImGui::EndTooltip(); + } + } + } // namespace namespace openspace::gui { @@ -152,15 +175,14 @@ void GuiSpaceTimeComponent::render() { scripting::ScriptEngine::RemoteScripting::Yes ); } - if (ImGui::IsItemHovered()) { - ImGui::SetTooltip( - "%s", - "Entering a date here and confirming with ENTER sets the current simulation " - "time to the entered date. The format of the date has to be either ISO 8601 " - "YYYY-MM-DDThh:mm:ss (2017-08-27T04:00:00) or YYYY MMM DD hh:mm:ss " - "(2017 MAY 01 12:00:00). The hours are in 24h and specified as UTC." - ); - } + + showTooltip( + "Entering a date here and confirming with ENTER sets the current simulation time " + "to the entered date. The format of the date has to be either ISO 8601 " + "YYYY-MM-DDThh:mm:ss (2017-08-27T04:00:00) or YYYY MMM DD hh:mm:ss " + "(2017 MAY 01 12:00:00). The hours are in 24h and specified as UTC.", + _tooltipDelay + ); auto incrementTime = [](int days) { using namespace std::chrono; @@ -186,12 +208,7 @@ void GuiSpaceTimeComponent::render() { }; bool minusMonth = ImGui::Button("-Month"); - if (ImGui::IsItemHovered()) { - ImGui::SetTooltip( - "%s", - "OBS: A month here equals 30 days." - ); - } + showTooltip("OBS: A month here equals 30 days.", _tooltipDelay); if (minusMonth) { incrementTime(-30); } @@ -241,12 +258,7 @@ void GuiSpaceTimeComponent::render() { if (plusMonth) { incrementTime(30); } - if (ImGui::IsItemHovered()) { - ImGui::SetTooltip( - "%s", - "OBS: A month here equals 30 days." - ); - } + showTooltip("OBS: A month here equals 30 days.", _tooltipDelay); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 20.f); @@ -273,14 +285,12 @@ void GuiSpaceTimeComponent::render() { scripting::ScriptEngine::RemoteScripting::Yes ); } - if (ImGui::IsItemHovered()) { - ImGui::SetTooltip( - "%s", - "This determines the simulation time increment, that is the passage " - "of time in OpenSpace relative to a wall clock. Times are expressed as " - "simulation time / real world time." - ); - } + showTooltip( + "This determines the simulation time increment, that is the passage of time in " + "OpenSpace relative to a wall clock. Times are expressed as simulation time / " + "real world time.", + _tooltipDelay + ); bool isPaused = OsEng.timeManager().time().paused(); diff --git a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp index 4e2042572a..e90c6b7ed6 100644 --- a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp @@ -82,8 +82,6 @@ RenderablePlaneProjection::RenderablePlaneProjection(const ghoul::Dictionary& di _texturePath = absPath(_texturePath); _textureFile = new ghoul::filesystem::File(_texturePath); } - - loadTexture(); } RenderablePlaneProjection::~RenderablePlaneProjection() { From 7ed683c59cb7d2ea96855171bd48a106e6a63d7c Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 11 Dec 2017 14:31:54 -0500 Subject: [PATCH 11/11] Update ghoul repository --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 347e2bba03..4101865ed5 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 347e2bba03d2788b3ec6ea2031b05675a9dd8dcb +Subproject commit 4101865ed5315ca9d54e4787df9b03ae1ad02145