-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add time based converter interpolator
new time based interpolator converter. This is the first type of converter that holds state and also is dependent on time. So this PR does 3 things: - makes converters advanceable - clones converters when assigned to data binds - adds support for the time based interpolator Diffs= c23d37a730 add time based converter interpolator (#8936) 86f65a5bb7 Fix text rendering with overflow clip (#8933) Co-authored-by: Philip Chung <[email protected]> Co-authored-by: hernan <[email protected]>
- Loading branch information
1 parent
c486b7e
commit 6764397
Showing
17 changed files
with
470 additions
and
14 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 @@ | ||
3dd8f44cf2d303d43c1aea514be6b0382a0c4bb9 | ||
c23d37a730a0496a4923bd85b8ffe0af90b738d7 |
40 changes: 40 additions & 0 deletions
40
dev/defs/data_bind/converters/data_converter_interpolator.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,40 @@ | ||
{ | ||
"name": "DataConverterInterpolator", | ||
"key": { | ||
"int": 534, | ||
"string": "dataconverterinterpolator" | ||
}, | ||
"extends": "data_bind/converters/data_converter.json", | ||
"properties": { | ||
"interpolationType": { | ||
"type": "uint", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 757, | ||
"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": 758, | ||
"string": "interpolatorid" | ||
}, | ||
"description": "The id of the custom interpolator used when interpolation is Cubic." | ||
}, | ||
"duration": { | ||
"type": "double", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 756, | ||
"string": "duration" | ||
}, | ||
"description": "Duration of the interpolation", | ||
"bindable": true | ||
} | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
include/rive/data_bind/converters/data_converter_interpolator.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,52 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_INTERPOLATOR_HPP_ | ||
#define _RIVE_DATA_CONVERTER_INTERPOLATOR_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_interpolator_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 | ||
{ | ||
|
||
struct InterpolatorAnimationData | ||
{ | ||
float elapsedSeconds = 0.0f; | ||
float from; | ||
float to; | ||
float interpolate(float f) const | ||
{ | ||
float fi = 1.0f - f; | ||
return to * f + from * fi; | ||
} | ||
void copy(const InterpolatorAnimationData& source); | ||
}; | ||
class DataConverterInterpolator : public DataConverterInterpolatorBase | ||
{ | ||
protected: | ||
KeyFrameInterpolator* m_interpolator = nullptr; | ||
|
||
public: | ||
void interpolator(KeyFrameInterpolator* interpolator); | ||
KeyFrameInterpolator* interpolator() const { return m_interpolator; }; | ||
DataType outputType() override { return DataType::number; }; | ||
DataValue* convert(DataValue* value, DataBind* dataBind) override; | ||
DataValue* reverseConvert(DataValue* value, DataBind* dataBind) override; | ||
bool advance(float elapsedTime) override; | ||
void copy(const DataConverterInterpolatorBase& object); | ||
|
||
private: | ||
DataValueNumber m_output; | ||
float m_currentValue; | ||
bool m_isFirstRun = true; | ||
|
||
InterpolatorAnimationData m_animationDataA; | ||
InterpolatorAnimationData m_animationDataB; | ||
bool m_isSmoothingAnimation = false; | ||
InterpolatorAnimationData* currentAnimationData(); | ||
void advanceAnimationData(float elapsedTime); | ||
|
||
public: | ||
}; | ||
} // 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
108 changes: 108 additions & 0 deletions
108
include/rive/generated/data_bind/converters/data_converter_interpolator_base.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,108 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_INTERPOLATOR_BASE_HPP_ | ||
#define _RIVE_DATA_CONVERTER_INTERPOLATOR_BASE_HPP_ | ||
#include "rive/core/field_types/core_double_type.hpp" | ||
#include "rive/core/field_types/core_uint_type.hpp" | ||
#include "rive/data_bind/converters/data_converter.hpp" | ||
namespace rive | ||
{ | ||
class DataConverterInterpolatorBase : public DataConverter | ||
{ | ||
protected: | ||
typedef DataConverter Super; | ||
|
||
public: | ||
static const uint16_t typeKey = 534; | ||
|
||
/// Helper to quickly determine if a core object extends another without | ||
/// RTTI at runtime. | ||
bool isTypeOf(uint16_t typeKey) const override | ||
{ | ||
switch (typeKey) | ||
{ | ||
case DataConverterInterpolatorBase::typeKey: | ||
case DataConverterBase::typeKey: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
uint16_t coreType() const override { return typeKey; } | ||
|
||
static const uint16_t interpolationTypePropertyKey = 757; | ||
static const uint16_t interpolatorIdPropertyKey = 758; | ||
static const uint16_t durationPropertyKey = 756; | ||
|
||
protected: | ||
uint32_t m_InterpolationType = 1; | ||
uint32_t m_InterpolatorId = -1; | ||
float m_Duration = 1.0f; | ||
|
||
public: | ||
inline uint32_t interpolationType() const { return m_InterpolationType; } | ||
void interpolationType(uint32_t value) | ||
{ | ||
if (m_InterpolationType == value) | ||
{ | ||
return; | ||
} | ||
m_InterpolationType = value; | ||
interpolationTypeChanged(); | ||
} | ||
|
||
inline uint32_t interpolatorId() const { return m_InterpolatorId; } | ||
void interpolatorId(uint32_t value) | ||
{ | ||
if (m_InterpolatorId == value) | ||
{ | ||
return; | ||
} | ||
m_InterpolatorId = value; | ||
interpolatorIdChanged(); | ||
} | ||
|
||
inline float duration() const { return m_Duration; } | ||
void duration(float value) | ||
{ | ||
if (m_Duration == value) | ||
{ | ||
return; | ||
} | ||
m_Duration = value; | ||
durationChanged(); | ||
} | ||
|
||
Core* clone() const override; | ||
void copy(const DataConverterInterpolatorBase& object) | ||
{ | ||
m_InterpolationType = object.m_InterpolationType; | ||
m_InterpolatorId = object.m_InterpolatorId; | ||
m_Duration = object.m_Duration; | ||
DataConverter::copy(object); | ||
} | ||
|
||
bool deserialize(uint16_t propertyKey, BinaryReader& reader) override | ||
{ | ||
switch (propertyKey) | ||
{ | ||
case interpolationTypePropertyKey: | ||
m_InterpolationType = CoreUintType::deserialize(reader); | ||
return true; | ||
case interpolatorIdPropertyKey: | ||
m_InterpolatorId = CoreUintType::deserialize(reader); | ||
return true; | ||
case durationPropertyKey: | ||
m_Duration = CoreDoubleType::deserialize(reader); | ||
return true; | ||
} | ||
return DataConverter::deserialize(propertyKey, reader); | ||
} | ||
|
||
protected: | ||
virtual void interpolationTypeChanged() {} | ||
virtual void interpolatorIdChanged() {} | ||
virtual void durationChanged() {} | ||
}; | ||
} // 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
Oops, something went wrong.