/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2021 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * * without restriction, including without limitation the rights to use, copy, modify, * * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to the following * * conditions: * * * * The above copyright notice and this permission notice shall be included in all copies * * or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #include #include #include namespace openspace::properties { template const std::string NumericalProperty::MinimumValueKey = "MinimumValue"; template const std::string NumericalProperty::MaximumValueKey = "MaximumValue"; template const std::string NumericalProperty::SteppingValueKey = "SteppingValue"; template const std::string NumericalProperty::ExponentValueKey = "Exponent"; template NumericalProperty::NumericalProperty(Property::PropertyInfo info, T value, T minimumValue, T maximumValue, T steppingValue, float exponent) : TemplateProperty(std::move(info), std::move(value)) , _minimumValue(std::move(minimumValue)) , _maximumValue(std::move(maximumValue)) , _stepping(std::move(steppingValue)) , _exponent(exponent) {} template T NumericalProperty::minValue() const { return _minimumValue; } template void NumericalProperty::setMinValue(T value) { _minimumValue = std::move(value); } template T NumericalProperty::maxValue() const { return _maximumValue; } template void NumericalProperty::setMaxValue(T value) { _maximumValue = std::move(value); } template T NumericalProperty::steppingValue() const { return _stepping; } template void NumericalProperty::setSteppingValue(T value) { _stepping = std::move(value); } template float NumericalProperty::exponent() const { return _exponent; } template void NumericalProperty::setExponent(float exponent) { _exponent = exponent; } template std::string NumericalProperty::generateAdditionalJsonDescription() const { std::string result = "{ "; result += "\"" + MinimumValueKey + "\": " + luaToJson(ghoul::to_string(_minimumValue)) + ","; result += "\"" + MaximumValueKey + "\": " + luaToJson(ghoul::to_string(_maximumValue)) + ","; result += "\"" + SteppingValueKey + "\": " + luaToJson(ghoul::to_string(_stepping)) + ","; result += "\"" + ExponentValueKey + "\": " + luaToJson(ghoul::to_string(_exponent)); result += " }"; return result; } template std::string NumericalProperty::luaToJson(std::string luaValue) const { if (luaValue[0] == '{') { luaValue.replace(0, 1, "["); } if (luaValue[luaValue.size() - 1] == '}') { luaValue.replace(luaValue.size() - 1, 1, "]"); } return luaValue; } template std::string NumericalProperty::jsonValue() const { std::string value = toStringConversion(); return luaToJson(value); } template void NumericalProperty::setInterpolationTarget(std::any value) { T v = std::any_cast(std::move(value)); _interpolationStart = TemplateProperty::_value; _interpolationEnd = std::move(v); } template void NumericalProperty::setLuaInterpolationTarget(lua_State* state) { bool success = false; T targetValue = fromLuaConversion(state, success); if (success) { _interpolationStart = TemplateProperty::_value; _interpolationEnd = std::move(targetValue); } } template void NumericalProperty::interpolateValue(float t, ghoul::EasingFunc easingFunction) { if (easingFunction) { t = easingFunction(t); } TemplateProperty::setValue(static_cast( glm::mix(_interpolationStart, _interpolationEnd, t) )); } template void NumericalProperty::toLuaConversion(lua_State* state) const { ghoul::lua::push(state, TemplateProperty::_value); } template std::string NumericalProperty::toStringConversion() const { return formatJson(TemplateProperty::_value); } } // namespace openspace::properties