mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 01:39:47 -05:00
Add a TriggerProperty that fires a single event when a value is passed
This commit is contained in:
+1
-1
Submodule ext/ghoul updated: 8418f394f4...9bf35183c1
@@ -93,6 +93,7 @@ private:
|
||||
std::set<properties::Property*> _vec3Properties;
|
||||
std::set<properties::Property*> _stringProperties;
|
||||
std::set<properties::Property*> _optionProperty;
|
||||
std::set<properties::Property*> _triggerProperty;
|
||||
|
||||
std::map<std::string, std::vector<properties::Property*>> _propertiesByOwner;
|
||||
};
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
* *
|
||||
* 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 __PROPERTY_H__
|
||||
#define __PROPERTY_H__
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 __TRIGGERPROPERTY_H__
|
||||
#define __TRIGGERPROPERTY_H__
|
||||
|
||||
#include <openspace/properties/property.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
/**
|
||||
* TriggerProperty that can be used to fire events into your code using the callback
|
||||
* method #onChange.
|
||||
*/
|
||||
class TriggerProperty : public Property {
|
||||
public:
|
||||
/**
|
||||
* Initializes the TriggerProperty by delegating the <code>identifier</code> and
|
||||
* <code>guiName</code> to the Property constructor.
|
||||
* \param identifier The unique identifier used for this Property
|
||||
* \param guiName The human-readable name of this Property
|
||||
*/
|
||||
TriggerProperty(std::string identifier, std::string guiName);
|
||||
|
||||
/**
|
||||
* Returns the class name <code>TriggerProperty</code>.
|
||||
* \return The class name <code>TriggerProperty</code>
|
||||
*/
|
||||
std::string className() const;
|
||||
|
||||
/**
|
||||
* Accepts only the <code>LUA_TNIL</code> type and will notify all the listeners
|
||||
* that the event has been triggered.
|
||||
* \param state The unused Lua state
|
||||
* \return Returns always <code>true</code>
|
||||
*/
|
||||
bool setLua(lua_State* state);
|
||||
|
||||
/**
|
||||
* Silently ignores any value that is passed into this function and will trigger the
|
||||
* listeners regardless of the value
|
||||
* \param value The ignored value
|
||||
*/
|
||||
void set(boost::any value);
|
||||
};
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __TRIGGERPROPERTY_H__
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/filesystem/cachemanager.h>
|
||||
@@ -199,6 +200,13 @@ void renderVec3Property(Property* prop, const std::string& ownerName) {
|
||||
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 {
|
||||
@@ -395,6 +403,8 @@ void GUI::registerProperty(properties::Property* prop) {
|
||||
_vec3Properties.insert(prop);
|
||||
else if (className == "OptionProperty")
|
||||
_optionProperty.insert(prop);
|
||||
else if (className == "TriggerProperty")
|
||||
_triggerProperty.insert(prop);
|
||||
else {
|
||||
LWARNING("Class name '" << className << "' not handled in GUI generation");
|
||||
return;
|
||||
@@ -469,6 +479,11 @@ void GUI::renderPropertyWindow() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_triggerProperty.find(prop) != _triggerProperty.end()) {
|
||||
renderTriggerProperty(prop, p.first);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-25
@@ -1,26 +1,26 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
* *
|
||||
* 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/properties/property.h>
|
||||
|
||||
@@ -84,10 +84,11 @@ bool Property::getLua(lua_State* state) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Property::set(boost::any value) {}
|
||||
void Property::set(boost::any value) {
|
||||
}
|
||||
|
||||
bool Property::setLua(lua_State* state) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::type_info& Property::type() const {
|
||||
@@ -95,7 +96,7 @@ const std::type_info& Property::type() const {
|
||||
}
|
||||
|
||||
int Property::typeLua() const {
|
||||
return LUA_TNONE;
|
||||
return LUA_TNIL;
|
||||
}
|
||||
|
||||
std::string Property::guiName() const {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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/properties/triggerproperty.h>
|
||||
|
||||
namespace openspace {
|
||||
namespace properties {
|
||||
|
||||
TriggerProperty::TriggerProperty(std::string identifier, std::string guiName)
|
||||
: Property(std::move(identifier), std::move(guiName))
|
||||
{}
|
||||
|
||||
std::string TriggerProperty::className() const {
|
||||
return "TriggerProperty";
|
||||
}
|
||||
|
||||
bool TriggerProperty::setLua(lua_State* state) {
|
||||
notifyListener();
|
||||
return true;
|
||||
}
|
||||
|
||||
void TriggerProperty::set(boost::any value) {
|
||||
notifyListener();
|
||||
}
|
||||
|
||||
} // namespace properties
|
||||
} // namespace openspace
|
||||
Reference in New Issue
Block a user