1 #ifndef _RIVE_STROKE_BASE_HPP_
2 #define _RIVE_STROKE_BASE_HPP_
3 #include "rive/core/field_types/core_bool_type.hpp"
4 #include "rive/core/field_types/core_double_type.hpp"
5 #include "rive/core/field_types/core_uint_type.hpp"
6 #include "rive/shapes/paint/shape_paint.hpp"
8 class StrokeBase : public ShapePaint {
10 typedef ShapePaint Super;
13 static const uint16_t typeKey = 24;
15 /// Helper to quickly determine if a core object extends another without RTTI
17 bool isTypeOf(uint16_t typeKey) const override {
19 case StrokeBase::typeKey:
20 case ShapePaintBase::typeKey:
21 case ContainerComponentBase::typeKey:
22 case ComponentBase::typeKey:
29 uint16_t coreType() const override { return typeKey; }
31 static const uint16_t thicknessPropertyKey = 47;
32 static const uint16_t capPropertyKey = 48;
33 static const uint16_t joinPropertyKey = 49;
34 static const uint16_t transformAffectsStrokePropertyKey = 50;
37 float m_Thickness = 1.0f;
40 bool m_TransformAffectsStroke = true;
43 inline float thickness() const { return m_Thickness; }
44 void thickness(float value) {
45 if (m_Thickness == value) {
52 inline uint32_t cap() const { return m_Cap; }
53 void cap(uint32_t value) {
61 inline uint32_t join() const { return m_Join; }
62 void join(uint32_t value) {
63 if (m_Join == value) {
70 inline bool transformAffectsStroke() const { return m_TransformAffectsStroke; }
71 void transformAffectsStroke(bool value) {
72 if (m_TransformAffectsStroke == value) {
75 m_TransformAffectsStroke = value;
76 transformAffectsStrokeChanged();
79 Core* clone() const override;
80 void copy(const StrokeBase& object) {
81 m_Thickness = object.m_Thickness;
83 m_Join = object.m_Join;
84 m_TransformAffectsStroke = object.m_TransformAffectsStroke;
85 ShapePaint::copy(object);
88 bool deserialize(uint16_t propertyKey, BinaryReader& reader) override {
89 switch (propertyKey) {
90 case thicknessPropertyKey:
91 m_Thickness = CoreDoubleType::deserialize(reader);
94 m_Cap = CoreUintType::deserialize(reader);
97 m_Join = CoreUintType::deserialize(reader);
99 case transformAffectsStrokePropertyKey:
100 m_TransformAffectsStroke = CoreBoolType::deserialize(reader);
103 return ShapePaint::deserialize(propertyKey, reader);
107 virtual void thicknessChanged() {}
108 virtual void capChanged() {}
109 virtual void joinChanged() {}
110 virtual void transformAffectsStrokeChanged() {}