mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
82 lines
1.6 KiB
C++
82 lines
1.6 KiB
C++
#ifndef _RIVE_NODE_BASE_HPP_
|
|
#define _RIVE_NODE_BASE_HPP_
|
|
#include "core/field_types/core_double_type.hpp"
|
|
#include "transform_component.hpp"
|
|
namespace rive
|
|
{
|
|
class NodeBase : public TransformComponent
|
|
{
|
|
protected:
|
|
typedef TransformComponent Super;
|
|
|
|
public:
|
|
static const int typeKey = 2;
|
|
|
|
/// Helper to quickly determine if a core object extends another without
|
|
/// RTTI at runtime.
|
|
bool isTypeOf(int typeKey) const override
|
|
{
|
|
switch (typeKey)
|
|
{
|
|
case NodeBase::typeKey:
|
|
case TransformComponentBase::typeKey:
|
|
case ContainerComponentBase::typeKey:
|
|
case ComponentBase::typeKey:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
int coreType() const override { return typeKey; }
|
|
|
|
static const int xPropertyKey = 13;
|
|
static const int yPropertyKey = 14;
|
|
|
|
private:
|
|
float m_X = 0;
|
|
float m_Y = 0;
|
|
public:
|
|
inline float x() const override { return m_X; }
|
|
void x(float value)
|
|
{
|
|
if (m_X == value)
|
|
{
|
|
return;
|
|
}
|
|
m_X = value;
|
|
xChanged();
|
|
}
|
|
|
|
inline float y() const override { return m_Y; }
|
|
void y(float value)
|
|
{
|
|
if (m_Y == value)
|
|
{
|
|
return;
|
|
}
|
|
m_Y = value;
|
|
yChanged();
|
|
}
|
|
|
|
bool deserialize(int propertyKey, BinaryReader& reader) override
|
|
{
|
|
switch (propertyKey)
|
|
{
|
|
case xPropertyKey:
|
|
m_X = CoreDoubleType::deserialize(reader);
|
|
return true;
|
|
case yPropertyKey:
|
|
m_Y = CoreDoubleType::deserialize(reader);
|
|
return true;
|
|
}
|
|
return TransformComponent::deserialize(propertyKey, reader);
|
|
}
|
|
|
|
protected:
|
|
virtual void xChanged() {}
|
|
virtual void yChanged() {}
|
|
};
|
|
} // namespace rive
|
|
|
|
#endif |