From 7e98922bdd4da23dbcb6a7aa18abcabc786f31e2 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 31 Jul 2016 21:24:12 +0200 Subject: [PATCH] Enable rendering of IVecX properties in the GuiPropertyComponent --- .../onscreengui/include/renderproperties.h | 3 + .../onscreengui/src/guipropertycomponent.cpp | 3 + modules/onscreengui/src/renderproperties.cpp | 81 +++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/modules/onscreengui/include/renderproperties.h b/modules/onscreengui/include/renderproperties.h index d54087bb95..29433f3bba 100644 --- a/modules/onscreengui/include/renderproperties.h +++ b/modules/onscreengui/include/renderproperties.h @@ -39,6 +39,9 @@ void renderOptionProperty(properties::Property* prop, const std::string& ownerNa void renderSelectionProperty(properties::Property* prop, const std::string& ownerName); void renderStringProperty(properties::Property* prop, const std::string& ownerName); void renderIntProperty(properties::Property* prop, const std::string& ownerName); +void renderIVec2Property(properties::Property* prop, const std::string& ownerName); +void renderIVec3Property(properties::Property* prop, const std::string& ownerName); +void renderIVec4Property(properties::Property* prop, const std::string& ownerName); void renderFloatProperty(properties::Property* prop, const std::string& ownerName); void renderVec2Property(properties::Property* prop, const std::string& ownerName); void renderVec3Property(properties::Property* prop, const std::string& ownerName); diff --git a/modules/onscreengui/src/guipropertycomponent.cpp b/modules/onscreengui/src/guipropertycomponent.cpp index 8ee91c4ca4..79af1a59f0 100644 --- a/modules/onscreengui/src/guipropertycomponent.cpp +++ b/modules/onscreengui/src/guipropertycomponent.cpp @@ -135,6 +135,9 @@ void GuiPropertyComponent::renderProperty(properties::Property* prop, properties static std::map FunctionMapping = { { "BoolProperty", &renderBoolProperty }, { "IntProperty", &renderIntProperty }, + { "IVec2Property", &renderIVec2Property }, + { "IVec3Property", &renderIVec3Property }, + { "IVec4Property", &renderIVec4Property }, { "FloatProperty", &renderFloatProperty }, { "Vec2Property", &renderVec2Property }, { "Vec3Property", &renderVec3Property }, diff --git a/modules/onscreengui/src/renderproperties.cpp b/modules/onscreengui/src/renderproperties.cpp index c6098b32eb..47014d4f11 100644 --- a/modules/onscreengui/src/renderproperties.cpp +++ b/modules/onscreengui/src/renderproperties.cpp @@ -172,6 +172,87 @@ void renderIntProperty(Property* prop, const std::string& ownerName) { ImGui::PopID(); } +void renderIVec2Property(Property* prop, const std::string& ownerName) { + IVec2Property* p = static_cast(prop); + std::string name = p->guiName(); + ImGui::PushID((ownerName + "." + name).c_str()); + + IVec2Property::ValueType value = *p; + float min = std::min(p->minValue().x, p->minValue().y); + float max = std::max(p->maxValue().x, p->maxValue().y); + ImGui::SliderInt2( + name.c_str(), + &value.x, + min, + max + ); + renderTooltip(prop); + + if (value != p->value()) { + executeScript(p->fullyQualifiedIdentifier(), + "{" + std::to_string(value.x) + "," + std::to_string(value.y) + "}" + ); + } + + ImGui::PopID(); +} + +void renderIVec3Property(Property* prop, const std::string& ownerName) { + IVec3Property* p = static_cast(prop); + std::string name = p->guiName(); + ImGui::PushID((ownerName + "." + name).c_str()); + + IVec3Property::ValueType value = *p; + float min = std::min(std::min(p->minValue().x, p->minValue().y), p->minValue().z); + float max = std::max(std::max(p->maxValue().x, p->maxValue().y), p->maxValue().z); + + ImGui::SliderInt3( + name.c_str(), + &value.x, + min, + max + ); + renderTooltip(prop); + + if (value != p->value()) + executeScript(p->fullyQualifiedIdentifier(), + "{" + std::to_string(value.x) + "," + + std::to_string(value.y) + "," + + std::to_string(value.z) + "}"); + + ImGui::PopID(); +} + +void renderIVec4Property(Property* prop, const std::string& ownerName) { + IVec4Property* p = static_cast(prop); + std::string name = p->guiName(); + ImGui::PushID((ownerName + "." + name).c_str()); + + IVec4Property::ValueType value = *p; + float min = std::min(std::min(std::min( + p->minValue().x, p->minValue().y), p->minValue().z), p->minValue().w); + float max = std::max(std::max(std::max( + p->maxValue().x, p->maxValue().y), p->maxValue().z), p->maxValue().w); + + ImGui::SliderInt4( + name.c_str(), + &value.x, + min, + max + ); + renderTooltip(prop); + + if (value != p->value()) + executeScript(p->fullyQualifiedIdentifier(), + "{" + std::to_string(value.x) + "," + + std::to_string(value.y) + "," + + std::to_string(value.z) + "," + + std::to_string(value.w) + "}"); + + ImGui::PopID(); +} + + void renderFloatProperty(Property* prop, const std::string& ownerName) { FloatProperty* p = static_cast(prop); std::string name = p->guiName();