Enable ImGui to handle StringProperty type

This commit is contained in:
Alexander Bock
2015-02-20 16:54:24 +01:00
parent 3c67788300
commit 08061a74e9
2 changed files with 30 additions and 9 deletions

View File

@@ -86,9 +86,9 @@ protected:
std::set<properties::Property*> _vec3Properties;
std::set<properties::Property*> _vec4Properties;
std::set<properties::Property*> _stringProperties;
std::set<properties::Property*> _optionProperty;
std::set<properties::Property*> _selectionProperty;
std::set<properties::Property*> _triggerProperty;
std::set<properties::Property*> _optionProperties;
std::set<properties::Property*> _selectionProperties;
std::set<properties::Property*> _triggerProperties;
std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
//std::vector<Property> _properties;

View File

@@ -30,8 +30,10 @@
#include <openspace/properties/scalarproperty.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/selectionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/assert.h>
#include "imgui.h"
@@ -103,6 +105,20 @@ namespace {
}
}
void renderStringProperty(Property* prop, const std::string& ownerName) {
StringProperty* p = static_cast<StringProperty*>(prop);
std::string name = p->guiName();
static const int bufferSize = 256;
static char buffer[bufferSize];
strcpy(buffer, p->value().c_str());
ImGui::InputText((ownerName + "." + name).c_str(), buffer, bufferSize);
std::string newValue(buffer);
if (newValue != p->value() && FileSys.fileExists(newValue))
executeScript(p->fullyQualifiedIdentifier(), "'" + newValue + "'");
}
void renderIntProperty(Property* prop, const std::string& ownerName) {
IntProperty* p = static_cast<IntProperty*>(prop);
std::string name = p->guiName();
@@ -336,11 +352,11 @@ void GuiPropertyComponent::registerProperty(properties::Property* prop) {
else if (className == "Vec4Property")
_vec4Properties.insert(prop);
else if (className == "OptionProperty")
_optionProperty.insert(prop);
_optionProperties.insert(prop);
else if (className == "TriggerProperty")
_triggerProperty.insert(prop);
_triggerProperties.insert(prop);
else if (className == "SelectionProperty")
_selectionProperty.insert(prop);
_selectionProperties.insert(prop);
else {
LWARNING("Class name '" << className << "' not handled in GUI generation");
return;
@@ -447,20 +463,25 @@ void GuiPropertyComponent::render() {
continue;
}
if (_optionProperty.find(prop) != _optionProperty.end()) {
if (_optionProperties.find(prop) != _optionProperties.end()) {
renderOptionProperty(prop, p.first);
continue;
}
if (_triggerProperty.find(prop) != _triggerProperty.end()) {
if (_triggerProperties.find(prop) != _triggerProperties.end()) {
renderTriggerProperty(prop, p.first);
continue;
}
if (_selectionProperty.find(prop) != _selectionProperty.end()) {
if (_selectionProperties.find(prop) != _selectionProperties.end()) {
renderSelectionProperty(prop, p.first);
continue;
}
if (_stringProperties.find(prop) != _stringProperties.end()) {
renderStringProperty(prop, p.first);
continue;
}
}
}
}