-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add arithmetic operation and group converters
two new converters: - arithmetic operation, that applies a basic arithmetic operation to an input - group converter: this is a special converter that is used to apply a sequence of converters to a data bound property. https://github.com/user-attachments/assets/50a0226c-343f-4252-923b-4f0c51ca6c8b Diffs= ad34dd4da add arithmetic operation and group converters (#7801) Co-authored-by: hernan <[email protected]>
- Loading branch information
Showing
23 changed files
with
589 additions
and
2 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 @@ | ||
f99c93181b2073db07b0c54f766648ce56c89df9 | ||
ad34dd4dae54aa071ca80c457e375c015b9497a8 |
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,8 @@ | ||
{ | ||
"name": "DataConverterGroup", | ||
"key": { | ||
"int": 499, | ||
"string": "dataconvertergroup" | ||
}, | ||
"extends": "data_bind/converters/data_converter.json" | ||
} |
39 changes: 39 additions & 0 deletions
39
dev/defs/data_bind/converters/data_converter_group_item.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": "DataConverterGroupItem", | ||
"key": { | ||
"int": 498, | ||
"string": "dataconvertergroupitem" | ||
}, | ||
"properties": { | ||
"order": { | ||
"type": "FractionalIndex", | ||
"initialValue": "FractionalIndex.invalid", | ||
"key": { | ||
"int": 678, | ||
"string": "order" | ||
}, | ||
"runtime": false | ||
}, | ||
"converterId": { | ||
"type": "Id", | ||
"typeRuntime": "uint", | ||
"initialValue": "Core.missingId", | ||
"initialValueRuntime": "-1", | ||
"key": { | ||
"int": 679, | ||
"string": "converterid" | ||
}, | ||
"description": "Id of the converter" | ||
}, | ||
"groupId": { | ||
"type": "Id", | ||
"initialValue": "Core.missingId", | ||
"key": { | ||
"int": 680, | ||
"string": "groupid" | ||
}, | ||
"description": "Id of the group this item belongs to", | ||
"runtime": false | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
dev/defs/data_bind/converters/data_converter_operation.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,28 @@ | ||
{ | ||
"name": "DataConverterOperation", | ||
"key": { | ||
"int": 500, | ||
"string": "dataconverteroperation" | ||
}, | ||
"extends": "data_bind/converters/data_converter.json", | ||
"properties": { | ||
"value": { | ||
"type": "double", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 681, | ||
"string": "value" | ||
}, | ||
"description": "Number to multiply the input to" | ||
}, | ||
"operationType": { | ||
"type": "uint", | ||
"initialValue": "0", | ||
"key": { | ||
"int": 682, | ||
"string": "operationtype" | ||
}, | ||
"description": "The operation tu use for the input and value" | ||
} | ||
} | ||
} |
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,16 @@ | ||
#ifndef _RIVE_ARITHMETIC_OPERATION_HPP_ | ||
#define _RIVE_ARITHMETIC_OPERATION_HPP_ | ||
|
||
namespace rive | ||
{ | ||
enum class ArithmeticOperation : int | ||
{ | ||
add = 0, | ||
subtract = 1, | ||
multiply = 2, | ||
divide = 3, | ||
modulo = 4, | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
28 changes: 28 additions & 0 deletions
28
include/rive/data_bind/converters/data_converter_group.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,28 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_GROUP_HPP_ | ||
#define _RIVE_DATA_CONVERTER_GROUP_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_group_base.hpp" | ||
#include "rive/data_bind/converters/data_converter_group_item.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverterGroup : public DataConverterGroupBase | ||
{ | ||
public: | ||
DataValue* convert(DataValue* value) override; | ||
DataValue* reverseConvert(DataValue* value) override; | ||
void addItem(DataConverterGroupItem* item); | ||
DataType outputType() override | ||
{ | ||
if (m_items.size() > 0) | ||
{ | ||
return m_items.back()->converter()->outputType(); | ||
}; | ||
return Super::outputType(); | ||
} | ||
|
||
private: | ||
std::vector<DataConverterGroupItem*> m_items; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
20 changes: 20 additions & 0 deletions
20
include/rive/data_bind/converters/data_converter_group_item.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,20 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_GROUP_ITEM_HPP_ | ||
#define _RIVE_DATA_CONVERTER_GROUP_ITEM_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_group_item_base.hpp" | ||
#include "rive/data_bind/converters/data_converter.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverterGroupItem : public DataConverterGroupItemBase | ||
{ | ||
public: | ||
StatusCode import(ImportStack& importStack) override; | ||
DataConverter* converter() const { return m_dataConverter; }; | ||
void converter(DataConverter* value) { m_dataConverter = value; }; | ||
|
||
protected: | ||
DataConverter* m_dataConverter; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
18 changes: 18 additions & 0 deletions
18
include/rive/data_bind/converters/data_converter_operation.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,18 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_OPERATION_HPP_ | ||
#define _RIVE_DATA_CONVERTER_OPERATION_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_operation_base.hpp" | ||
#include "rive/animation/arithmetic_operation.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverterOperation : public DataConverterOperationBase | ||
{ | ||
public: | ||
DataValue* convert(DataValue* value) override; | ||
DataValue* reverseConvert(DataValue* value) override; | ||
DataType outputType() override { return DataType::number; }; | ||
ArithmeticOperation op() const { return (ArithmeticOperation)operationType(); } | ||
}; | ||
} // 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
36 changes: 36 additions & 0 deletions
36
include/rive/generated/data_bind/converters/data_converter_group_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,36 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_GROUP_BASE_HPP_ | ||
#define _RIVE_DATA_CONVERTER_GROUP_BASE_HPP_ | ||
#include "rive/data_bind/converters/data_converter.hpp" | ||
namespace rive | ||
{ | ||
class DataConverterGroupBase : public DataConverter | ||
{ | ||
protected: | ||
typedef DataConverter Super; | ||
|
||
public: | ||
static const uint16_t typeKey = 499; | ||
|
||
/// Helper to quickly determine if a core object extends another without RTTI | ||
/// at runtime. | ||
bool isTypeOf(uint16_t typeKey) const override | ||
{ | ||
switch (typeKey) | ||
{ | ||
case DataConverterGroupBase::typeKey: | ||
case DataConverterBase::typeKey: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
uint16_t coreType() const override { return typeKey; } | ||
|
||
Core* clone() const override; | ||
|
||
protected: | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
66 changes: 66 additions & 0 deletions
66
include/rive/generated/data_bind/converters/data_converter_group_item_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,66 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_GROUP_ITEM_BASE_HPP_ | ||
#define _RIVE_DATA_CONVERTER_GROUP_ITEM_BASE_HPP_ | ||
#include "rive/core.hpp" | ||
#include "rive/core/field_types/core_uint_type.hpp" | ||
namespace rive | ||
{ | ||
class DataConverterGroupItemBase : public Core | ||
{ | ||
protected: | ||
typedef Core Super; | ||
|
||
public: | ||
static const uint16_t typeKey = 498; | ||
|
||
/// Helper to quickly determine if a core object extends another without RTTI | ||
/// at runtime. | ||
bool isTypeOf(uint16_t typeKey) const override | ||
{ | ||
switch (typeKey) | ||
{ | ||
case DataConverterGroupItemBase::typeKey: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
uint16_t coreType() const override { return typeKey; } | ||
|
||
static const uint16_t converterIdPropertyKey = 679; | ||
|
||
private: | ||
uint32_t m_ConverterId = -1; | ||
|
||
public: | ||
inline uint32_t converterId() const { return m_ConverterId; } | ||
void converterId(uint32_t value) | ||
{ | ||
if (m_ConverterId == value) | ||
{ | ||
return; | ||
} | ||
m_ConverterId = value; | ||
converterIdChanged(); | ||
} | ||
|
||
Core* clone() const override; | ||
void copy(const DataConverterGroupItemBase& object) { m_ConverterId = object.m_ConverterId; } | ||
|
||
bool deserialize(uint16_t propertyKey, BinaryReader& reader) override | ||
{ | ||
switch (propertyKey) | ||
{ | ||
case converterIdPropertyKey: | ||
m_ConverterId = CoreUintType::deserialize(reader); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
protected: | ||
virtual void converterIdChanged() {} | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
Oops, something went wrong.