2017-12-30 17:27:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkottyProperties_DEFINED
|
|
|
|
#define SkottyProperties_DEFINED
|
|
|
|
|
2018-01-09 18:11:56 +00:00
|
|
|
#include "SkColor.h"
|
2018-01-02 20:33:18 +00:00
|
|
|
#include "SkPath.h"
|
2017-12-30 17:27:00 +00:00
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkSize.h"
|
|
|
|
#include "SkottyPriv.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkTArray.h"
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#include <memory>
|
2018-01-09 00:23:08 +00:00
|
|
|
#include <vector>
|
2017-12-30 17:27:00 +00:00
|
|
|
|
|
|
|
namespace sksg {
|
2018-01-09 18:11:56 +00:00
|
|
|
class Color;
|
2018-01-05 02:11:55 +00:00
|
|
|
class Matrix;
|
2018-01-04 16:27:09 +00:00
|
|
|
class Path;
|
2018-01-02 15:40:00 +00:00
|
|
|
class RRect;
|
2018-01-05 02:11:55 +00:00
|
|
|
class RenderNode;;
|
2017-12-30 17:27:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace skotty {
|
|
|
|
|
2018-01-09 00:23:08 +00:00
|
|
|
template <typename T>
|
|
|
|
struct ValueTraits {
|
|
|
|
static bool Parse(const Json::Value&, T*);
|
|
|
|
static size_t Cardinality(const T&);
|
2017-12-30 17:27:00 +00:00
|
|
|
|
2018-01-09 00:23:08 +00:00
|
|
|
template <typename U>
|
|
|
|
static U As(const T&);
|
2017-12-30 17:27:00 +00:00
|
|
|
};
|
|
|
|
|
2018-01-09 00:23:08 +00:00
|
|
|
using ScalarValue = SkScalar;
|
|
|
|
using VectorValue = std::vector<ScalarValue>;
|
|
|
|
using ShapeValue = SkPath;
|
2017-12-30 17:27:00 +00:00
|
|
|
|
|
|
|
// Composite properties.
|
|
|
|
|
|
|
|
#define COMPOSITE_PROPERTY(p_name, p_type, p_default) \
|
|
|
|
void set##p_name(const p_type& p) { \
|
|
|
|
if (p == f##p_name) return; \
|
|
|
|
f##p_name = p; \
|
|
|
|
this->apply(); \
|
|
|
|
} \
|
|
|
|
private: \
|
|
|
|
p_type f##p_name = p_default; \
|
|
|
|
public:
|
|
|
|
|
2018-01-09 18:11:56 +00:00
|
|
|
class CompositeColor final : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
explicit CompositeColor(sk_sp<sksg::Color>);
|
|
|
|
|
|
|
|
COMPOSITE_PROPERTY(Color , SkColor , SK_ColorBLACK)
|
|
|
|
COMPOSITE_PROPERTY(Opacity, SkScalar, 100 )
|
|
|
|
|
|
|
|
private:
|
|
|
|
void apply();
|
|
|
|
|
|
|
|
sk_sp<sksg::Color> fColorNode;
|
|
|
|
|
|
|
|
using INHERITED = SkRefCnt;
|
|
|
|
};
|
|
|
|
|
2018-01-02 15:40:00 +00:00
|
|
|
class CompositeRRect final : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
explicit CompositeRRect(sk_sp<sksg::RRect>);
|
|
|
|
|
|
|
|
COMPOSITE_PROPERTY(Position, SkPoint , SkPoint::Make(0, 0))
|
|
|
|
COMPOSITE_PROPERTY(Size , SkSize , SkSize::Make(0, 0))
|
2018-01-04 15:26:35 +00:00
|
|
|
COMPOSITE_PROPERTY(Radius , SkSize , SkSize::Make(0, 0))
|
2018-01-02 15:40:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void apply();
|
|
|
|
|
|
|
|
sk_sp<sksg::RRect> fRRectNode;
|
|
|
|
|
|
|
|
using INHERITED = SkRefCnt;
|
|
|
|
};
|
|
|
|
|
2018-01-04 16:27:09 +00:00
|
|
|
class CompositePolyStar final : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
kStar, kPoly,
|
|
|
|
};
|
|
|
|
|
|
|
|
CompositePolyStar(sk_sp<sksg::Path>, Type);
|
|
|
|
|
|
|
|
COMPOSITE_PROPERTY(Position , SkPoint , SkPoint::Make(0, 0))
|
|
|
|
COMPOSITE_PROPERTY(PointCount , SkScalar, 0)
|
|
|
|
COMPOSITE_PROPERTY(InnerRadius , SkScalar, 0)
|
|
|
|
COMPOSITE_PROPERTY(OuterRadius , SkScalar, 0)
|
|
|
|
COMPOSITE_PROPERTY(InnerRoundness, SkScalar, 0)
|
|
|
|
COMPOSITE_PROPERTY(OuterRoundness, SkScalar, 0)
|
|
|
|
COMPOSITE_PROPERTY(Rotation , SkScalar, 0)
|
|
|
|
|
|
|
|
private:
|
|
|
|
void apply();
|
|
|
|
|
|
|
|
sk_sp<sksg::Path> fPathNode;
|
|
|
|
Type fType;
|
|
|
|
|
|
|
|
using INHERITED = SkRefCnt;
|
|
|
|
};
|
|
|
|
|
2017-12-30 17:27:00 +00:00
|
|
|
class CompositeTransform final : public SkRefCnt {
|
|
|
|
public:
|
2018-01-05 02:11:55 +00:00
|
|
|
explicit CompositeTransform(sk_sp<sksg::Matrix>);
|
2017-12-30 17:27:00 +00:00
|
|
|
|
|
|
|
COMPOSITE_PROPERTY(AnchorPoint, SkPoint , SkPoint::Make(0, 0))
|
|
|
|
COMPOSITE_PROPERTY(Position , SkPoint , SkPoint::Make(0, 0))
|
|
|
|
COMPOSITE_PROPERTY(Scale , SkVector, SkPoint::Make(100, 100))
|
|
|
|
COMPOSITE_PROPERTY(Rotation , SkScalar, 0)
|
|
|
|
COMPOSITE_PROPERTY(Skew , SkScalar, 0)
|
|
|
|
COMPOSITE_PROPERTY(SkewAxis , SkScalar, 0)
|
|
|
|
|
|
|
|
private:
|
|
|
|
void apply();
|
|
|
|
|
2018-01-05 02:11:55 +00:00
|
|
|
sk_sp<sksg::Matrix> fMatrixNode;
|
2017-12-30 17:27:00 +00:00
|
|
|
|
|
|
|
using INHERITED = SkRefCnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef COMPOSITE_PROPERTY
|
|
|
|
|
|
|
|
} // namespace skotty
|
|
|
|
|
|
|
|
#endif // SkottyProperties_DEFINED
|