-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a new data converter by request from Duo. It defines an input range and maps it to an output range. It includes some extra features like clamping the value, applying a modulo in order to make it loop, and reversing it. And it also takes an interpolator such that the mapping doesn't need to be lineal. @ https://github.com/user-attachments/assets/d18b1269-8b5e-4aad-9504-9f5f3dcdaad9 Diffs= 88543fa792 Nnnn range data converter (#8585) Co-authored-by: hernan <hernan@rive.app>
- Loading branch information
Showing
23 changed files
with
661 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
a2b0cb230ae3f3834d13096d7dc7688ef908c1d3 | ||
88543fa79295566065b700bfcf66130f327ff562 |
39 changes: 39 additions & 0 deletions
39
dev/defs/data_bind/converters/data_converter_range_mapper.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "DataConverterRangeMapper", | ||
"key": { | ||
"int": 518, | ||
"string": "dataconverterrangemapper" | ||
}, | ||
"abstract": true, | ||
"extends": "data_bind/converters/data_converter.json", | ||
"properties": { | ||
"interpolationType": { | ||
"type": "uint", | ||
"initialValue": "0", | ||
"key": { | ||
"int": 713, | ||
"string": "interpolationtype" | ||
}, | ||
"description": "The type of interpolation index in KeyframeInterpolation applied to this layout." | ||
}, | ||
"interpolatorId": { | ||
"type": "Id", | ||
"typeRuntime": "uint", | ||
"initialValue": "Core.missingId", | ||
"initialValueRuntime": "-1", | ||
"key": { | ||
"int": 714, | ||
"string": "interpolatorid" | ||
}, | ||
"description": "The id of the custom interpolator used when interpolation is Cubic." | ||
}, | ||
"flags": { | ||
"type": "uint", | ||
"initialValue": "0", | ||
"key": { | ||
"int": 715, | ||
"string": "flags" | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
dev/defs/data_bind/converters/data_converter_range_mapper_values.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "DataConverterRangeMapperValues", | ||
"key": { | ||
"int": 519, | ||
"string": "dataconverterrangemappervalues" | ||
}, | ||
"extends": "data_bind/converters/data_converter_range_mapper.json", | ||
"properties": { | ||
"minInput": { | ||
"type": "double", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 716, | ||
"string": "mininput" | ||
}, | ||
"description": "Min value the input will map from" | ||
}, | ||
"maxInput": { | ||
"type": "double", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 717, | ||
"string": "maxinput" | ||
}, | ||
"description": "Max value the input will map from" | ||
}, | ||
"minOutput": { | ||
"type": "double", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 718, | ||
"string": "minoutput" | ||
}, | ||
"description": "Min value the output will map to" | ||
}, | ||
"maxOutput": { | ||
"type": "double", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 719, | ||
"string": "maxoutput" | ||
}, | ||
"description": "Max value the output will map to" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
include/rive/animation/data_converter_range_mapper_flags.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_RANGE_MAPPER_FLAGS_HPP_ | ||
#define _RIVE_DATA_CONVERTER_RANGE_MAPPER_FLAGS_HPP_ | ||
|
||
#include "rive/enum_bitset.hpp" | ||
|
||
namespace rive | ||
{ | ||
enum class DataConverterRangeMapperFlags : unsigned short | ||
{ | ||
|
||
/// Whether the lower bound should be clamped | ||
ClampLower = 1 << 0, | ||
|
||
/// Whether the upper bound should be clamped | ||
ClampUpper = 1 << 1, | ||
|
||
/// Whether the value should wrap if it exceeds the range | ||
Modulo = 1 << 2, | ||
|
||
/// Whether to reverse the mapping | ||
Reverse = 1 << 3, | ||
|
||
}; | ||
|
||
RIVE_MAKE_ENUM_BITSET(DataConverterRangeMapperFlags) | ||
} // namespace rive | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
include/rive/data_bind/converters/data_converter_range_mapper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_RANGE_MAPPER_HPP_ | ||
#define _RIVE_DATA_CONVERTER_RANGE_MAPPER_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_range_mapper_base.hpp" | ||
#include "rive/data_bind/data_values/data_value_number.hpp" | ||
#include "rive/data_bind/data_values/data_value.hpp" | ||
#include "rive/animation/keyframe_interpolator.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverterRangeMapper : public DataConverterRangeMapperBase | ||
{ | ||
protected: | ||
KeyFrameInterpolator* m_interpolator; | ||
DataValueNumber* calculateRange(DataValue* input, | ||
float minInput, | ||
float maxInput, | ||
float minOutput, | ||
float maxOutput); | ||
DataValueNumber* calculateReverseRange(DataValue* input, | ||
float minInput, | ||
float maxInput, | ||
float minOutput, | ||
float maxOutput); | ||
|
||
public: | ||
void interpolator(KeyFrameInterpolator* interpolator); | ||
DataType outputType() override { return DataType::number; }; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
15 changes: 15 additions & 0 deletions
15
include/rive/data_bind/converters/data_converter_range_mapper_values.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_RANGE_MAPPER_VALUES_HPP_ | ||
#define _RIVE_DATA_CONVERTER_RANGE_MAPPER_VALUES_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_range_mapper_values_base.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverterRangeMapperValues : public DataConverterRangeMapperValuesBase | ||
{ | ||
public: | ||
DataValue* convert(DataValue* value, DataBind* dataBind) override; | ||
DataValue* reverseConvert(DataValue* value, DataBind* dataBind) override; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.