forked from rive-app/rive-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewmodel_instance_number_base.hpp
More file actions
79 lines (69 loc) · 2.19 KB
/
Copy pathviewmodel_instance_number_base.hpp
File metadata and controls
79 lines (69 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef _RIVE_VIEW_MODEL_INSTANCE_NUMBER_BASE_HPP_
#define _RIVE_VIEW_MODEL_INSTANCE_NUMBER_BASE_HPP_
#include <atomic>
#include "rive/core/field_types/core_double_type.hpp"
#include "rive/viewmodel/viewmodel_instance_value.hpp"
namespace rive
{
class ViewModelInstanceNumberBase : public ViewModelInstanceValue
{
protected:
typedef ViewModelInstanceValue Super;
public:
static const uint16_t typeKey = 442;
/// Helper to quickly determine if a core object extends another without
/// RTTI at runtime.
bool isTypeOf(uint16_t typeKey) const override
{
switch (typeKey)
{
case ViewModelInstanceNumberBase::typeKey:
case ViewModelInstanceValueBase::typeKey:
return true;
default:
return false;
}
}
uint16_t coreType() const override { return typeKey; }
static const uint16_t propertyValuePropertyKey = 575;
protected:
std::atomic<float> m_PropertyValue{0.0f};
public:
inline float propertyValue() const
{
return m_PropertyValue.load(std::memory_order_relaxed);
}
void propertyValue(float value)
{
if (m_PropertyValue.load(std::memory_order_relaxed) == value)
{
return;
}
m_PropertyValue.store(value, std::memory_order_relaxed);
propertyValueChanged();
}
std::atomic<float>* atomicPropertyValue() { return &m_PropertyValue; }
Core* clone() const override;
void copy(const ViewModelInstanceNumberBase& object)
{
m_PropertyValue.store(
object.m_PropertyValue.load(std::memory_order_relaxed),
std::memory_order_relaxed);
ViewModelInstanceValue::copy(object);
}
bool deserialize(uint16_t propertyKey, BinaryReader& reader) override
{
switch (propertyKey)
{
case propertyValuePropertyKey:
m_PropertyValue.store(CoreDoubleType::deserialize(reader),
std::memory_order_relaxed);
return true;
}
return ViewModelInstanceValue::deserialize(propertyKey, reader);
}
protected:
virtual void propertyValueChanged() {}
};
} // namespace rive
#endif