2021-12-26 23:26:34 +08:00
|
|
|
/**
|
2020-10-18 00:27:23 +08:00
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012-2018 DragonBones team and other contributors
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2020-10-18 00:27:23 +08:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
*
|
2020-10-18 00:27:23 +08:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef DRAGONBONES_H
|
|
|
|
#define DRAGONBONES_H
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <tuple>
|
|
|
|
#include <functional>
|
|
|
|
#include <sstream>
|
|
|
|
#include <assert.h>
|
|
|
|
// dragonBones assert
|
|
|
|
#define DRAGONBONES_ASSERT(cond, msg) \
|
2021-12-25 10:04:45 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
assert(cond); \
|
|
|
|
} while (0)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
// namespace dragonBones {}
|
2021-12-25 10:04:45 +08:00
|
|
|
#define DRAGONBONES_NAMESPACE_BEGIN \
|
|
|
|
namespace dragonBones \
|
|
|
|
{
|
2020-10-18 00:27:23 +08:00
|
|
|
#define DRAGONBONES_NAMESPACE_END }
|
|
|
|
|
|
|
|
// using dragonBones namespace
|
|
|
|
#define DRAGONBONES_USING_NAME_SPACE using namespace dragonBones
|
|
|
|
|
|
|
|
#define ABSTRACT_CLASS(CLASS) \
|
2021-12-25 10:04:45 +08:00
|
|
|
public: \
|
|
|
|
CLASS() {} \
|
2020-10-18 00:27:23 +08:00
|
|
|
virtual ~CLASS(){};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#define BIND_CLASS_TYPE(CLASS) \
|
|
|
|
public: \
|
|
|
|
static std::size_t getTypeIndex() \
|
|
|
|
{ \
|
|
|
|
static const auto typeIndex = typeid(CLASS).hash_code(); \
|
|
|
|
return typeIndex; \
|
|
|
|
} \
|
|
|
|
virtual std::size_t getClassTypeIndex() const override { return CLASS::getTypeIndex(); }
|
|
|
|
|
|
|
|
#define BIND_CLASS_TYPE_A(CLASS) \
|
|
|
|
public: \
|
|
|
|
static std::size_t getTypeIndex() \
|
|
|
|
{ \
|
|
|
|
static const auto typeIndex = typeid(CLASS).hash_code(); \
|
|
|
|
return typeIndex; \
|
|
|
|
} \
|
|
|
|
virtual std::size_t getClassTypeIndex() const override { return CLASS::getTypeIndex(); } \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
CLASS() { _onClear(); } \
|
|
|
|
~CLASS() { _onClear(); } \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
CLASS(const CLASS&); \
|
2020-10-18 00:27:23 +08:00
|
|
|
void operator=(const CLASS&)
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#define BIND_CLASS_TYPE_B(CLASS) \
|
|
|
|
public: \
|
|
|
|
static std::size_t getTypeIndex() \
|
|
|
|
{ \
|
|
|
|
static const auto typeIndex = typeid(CLASS).hash_code(); \
|
|
|
|
return typeIndex; \
|
|
|
|
} \
|
|
|
|
virtual std::size_t getClassTypeIndex() const override { return CLASS::getTypeIndex(); } \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
CLASS(const CLASS&); \
|
2020-10-18 00:27:23 +08:00
|
|
|
void operator=(const CLASS&)
|
|
|
|
|
|
|
|
#define DRAGONBONES_DISALLOW_COPY_AND_ASSIGN(CLASS) \
|
2021-12-25 10:04:45 +08:00
|
|
|
private: \
|
|
|
|
CLASS(const CLASS&); \
|
2020-10-18 00:27:23 +08:00
|
|
|
void operator=(const CLASS&);
|
|
|
|
|
|
|
|
DRAGONBONES_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
enum class BinaryOffset
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
WeigthBoneCount = 0,
|
2020-10-18 00:27:23 +08:00
|
|
|
WeigthFloatOffset = 1,
|
|
|
|
WeigthBoneIndices = 2,
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MeshVertexCount = 0,
|
2020-10-18 00:27:23 +08:00
|
|
|
MeshTriangleCount = 1,
|
2021-12-25 10:04:45 +08:00
|
|
|
MeshFloatOffset = 2,
|
|
|
|
MeshWeightOffset = 3,
|
2020-10-18 00:27:23 +08:00
|
|
|
MeshVertexIndices = 4,
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TimelineScale = 0,
|
|
|
|
TimelineOffset = 1,
|
|
|
|
TimelineKeyFrameCount = 2,
|
|
|
|
TimelineFrameValueCount = 3,
|
2020-10-18 00:27:23 +08:00
|
|
|
TimelineFrameValueOffset = 4,
|
2021-12-25 10:04:45 +08:00
|
|
|
TimelineFrameOffset = 5,
|
2020-10-18 00:27:23 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FramePosition = 0,
|
|
|
|
FrameTweenType = 1,
|
2020-10-18 00:27:23 +08:00
|
|
|
FrameTweenEasingOrCurveSampleCount = 2,
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameCurveSamples = 3,
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
DeformVertexOffset = 0,
|
2021-12-25 10:04:45 +08:00
|
|
|
DeformCount = 1,
|
|
|
|
DeformValueCount = 2,
|
|
|
|
DeformValueOffset = 3,
|
|
|
|
DeformFloatOffset = 4
|
2020-10-18 00:27:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
enum class ArmatureType
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Armature = 0,
|
2020-10-18 00:27:23 +08:00
|
|
|
MovieClip = 1,
|
2021-12-25 10:04:45 +08:00
|
|
|
Stage = 2
|
2020-10-18 00:27:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* - Offset mode.
|
|
|
|
* @version DragonBones 5.5
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 偏移模式。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @version DragonBones 5.5
|
|
|
|
* @language zh_CN
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class OffsetMode
|
|
|
|
{
|
2020-10-18 00:27:23 +08:00
|
|
|
None,
|
|
|
|
Additive,
|
|
|
|
Override
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class DisplayType
|
2020-10-18 00:27:23 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Image = 0,
|
|
|
|
Armature = 1,
|
|
|
|
Mesh = 2,
|
2020-10-18 00:27:23 +08:00
|
|
|
BoundingBox = 3,
|
2021-12-25 10:04:45 +08:00
|
|
|
Path = 4
|
2020-10-18 00:27:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* - Bounding box type.
|
|
|
|
* @version DragonBones 5.0
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 边界框类型。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @version DragonBones 5.0
|
|
|
|
* @language zh_CN
|
|
|
|
*/
|
|
|
|
enum class BoundingBoxType
|
|
|
|
{
|
|
|
|
Rectangle = 0,
|
2021-12-25 10:04:45 +08:00
|
|
|
Ellipse = 1,
|
|
|
|
Polygon = 2
|
2020-10-18 00:27:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class ActionType
|
|
|
|
{
|
|
|
|
Play = 0,
|
2020-10-18 00:27:23 +08:00
|
|
|
Frame = 10,
|
|
|
|
Sound = 11
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class BlendMode
|
2020-10-18 00:27:23 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
Normal = 0,
|
|
|
|
Add = 1,
|
|
|
|
Alpha = 2,
|
|
|
|
Darken = 3,
|
2020-10-18 00:27:23 +08:00
|
|
|
Difference = 4,
|
2021-12-25 10:04:45 +08:00
|
|
|
Erase = 5,
|
|
|
|
HardLight = 6,
|
|
|
|
Invert = 7,
|
|
|
|
Layer = 8,
|
|
|
|
Lighten = 9,
|
|
|
|
Multiply = 10,
|
|
|
|
Overlay = 11,
|
|
|
|
Screen = 12,
|
|
|
|
Subtract = 13
|
2020-10-18 00:27:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class TweenType
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
Line = 1,
|
|
|
|
Curve = 2,
|
|
|
|
QuadIn = 3,
|
|
|
|
QuadOut = 4,
|
2020-10-18 00:27:23 +08:00
|
|
|
QuadInOut = 5
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class TimelineType
|
|
|
|
{
|
2020-10-18 00:27:23 +08:00
|
|
|
Action = 0,
|
|
|
|
ZOrder = 1,
|
|
|
|
|
|
|
|
BoneAll = 10,
|
|
|
|
|
|
|
|
BoneTranslate = 11,
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneRotate = 12,
|
|
|
|
BoneScale = 13,
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
SlotDisplay = 20,
|
2021-12-25 10:04:45 +08:00
|
|
|
SlotColor = 21,
|
|
|
|
SlotDeform = 22,
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
IKConstraint = 30,
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationTime = 40,
|
2020-10-18 00:27:23 +08:00
|
|
|
AnimationWeight = 41
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* - Animation fade out mode.
|
|
|
|
* @version DragonBones 4.5
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 动画淡出模式。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @version DragonBones 4.5
|
|
|
|
* @language zh_CN
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
enum class AnimationFadeOutMode
|
|
|
|
{
|
2020-10-18 00:27:23 +08:00
|
|
|
/**
|
|
|
|
* - Do not fade out of any animation states.
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 不淡出任何的动画状态。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @language zh_CN
|
|
|
|
*/
|
|
|
|
None,
|
|
|
|
/**
|
|
|
|
* - Fade out the animation states of the same layer.
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 淡出同层的动画状态。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @language zh_CN
|
|
|
|
*/
|
|
|
|
SameLayer,
|
|
|
|
/**
|
|
|
|
* - Fade out the animation states of the same group.
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 淡出同组的动画状态。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @language zh_CN
|
|
|
|
*/
|
|
|
|
SameGroup,
|
|
|
|
/**
|
|
|
|
* - Fade out the animation states of the same layer and group.
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 淡出同层并且同组的动画状态。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @language zh_CN
|
|
|
|
*/
|
|
|
|
SameLayerAndGroup,
|
|
|
|
/**
|
|
|
|
* - Fade out of all animation states.
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 淡出所有的动画状态。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @language zh_CN
|
|
|
|
*/
|
|
|
|
All,
|
|
|
|
/**
|
|
|
|
* - Does not replace the animation state with the same name.
|
|
|
|
* @language en_US
|
|
|
|
*/
|
|
|
|
/**
|
2021-12-24 21:11:44 +08:00
|
|
|
* - 不替换同名的动画状态。
|
2020-10-18 00:27:23 +08:00
|
|
|
* @language zh_CN
|
|
|
|
*/
|
|
|
|
Single
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class TextureFormat
|
|
|
|
{
|
|
|
|
DEFAULT,
|
|
|
|
RGBA8888,
|
|
|
|
BGRA8888,
|
|
|
|
RGBA4444,
|
|
|
|
RGB888,
|
|
|
|
RGB565,
|
|
|
|
RGBA5551
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
std::string to_string(const T& value)
|
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
stream << value;
|
|
|
|
return stream.str();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
template <class T>
|
2020-10-18 00:27:23 +08:00
|
|
|
inline int indexOf(const std::vector<T>& vector, const T& value)
|
|
|
|
{
|
|
|
|
for (std::size_t i = 0, l = vector.size(); i < l; ++i)
|
|
|
|
{
|
|
|
|
if (vector[i] == value)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
return (int)i;
|
2020-10-18 00:27:23 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2020-10-18 00:27:23 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
template <class T>
|
2021-12-26 23:26:34 +08:00
|
|
|
inline T* mapFind(const std::map<std::string, T*>& map, std::string_view key)
|
2020-10-18 00:27:23 +08:00
|
|
|
{
|
|
|
|
auto iterator = map.find(key);
|
|
|
|
return (iterator != map.end()) ? iterator->second : nullptr;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
template <class T>
|
2021-12-26 23:26:34 +08:00
|
|
|
inline T* mapFindB(std::map<std::string, T>& map, std::string_view key)
|
2020-10-18 00:27:23 +08:00
|
|
|
{
|
|
|
|
auto iterator = map.find(key);
|
|
|
|
return (iterator != map.end()) ? &iterator->second : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
class Matrix;
|
|
|
|
class Transform;
|
|
|
|
class ColorTransform;
|
|
|
|
class Point;
|
|
|
|
class Rectangle;
|
|
|
|
|
|
|
|
class BaseObject;
|
|
|
|
|
|
|
|
class UserData;
|
|
|
|
class ActionData;
|
|
|
|
class DragonBonesData;
|
|
|
|
class ArmatureData;
|
|
|
|
class CanvasData;
|
|
|
|
class BoneData;
|
|
|
|
class SlotData;
|
|
|
|
class SkinData;
|
|
|
|
class ConstraintData;
|
|
|
|
class IKConstraintData;
|
|
|
|
class DisplayData;
|
|
|
|
class ImageDisplayData;
|
|
|
|
class ArmatureDisplayData;
|
|
|
|
class MeshDisplayData;
|
|
|
|
class VerticesData;
|
|
|
|
class WeightData;
|
|
|
|
class BoundingBoxDisplayData;
|
|
|
|
class BoundingBoxData;
|
|
|
|
class RectangleBoundingBoxData;
|
|
|
|
class EllipseBoundingBoxData;
|
|
|
|
class PolygonBoundingBoxData;
|
|
|
|
class AnimationData;
|
|
|
|
class TimelineData;
|
|
|
|
class AnimationConfig;
|
|
|
|
class TextureAtlasData;
|
|
|
|
class TextureData;
|
|
|
|
|
|
|
|
class IArmatureProxy;
|
|
|
|
class Armature;
|
|
|
|
class TransformObject;
|
|
|
|
class Bone;
|
|
|
|
class Slot;
|
|
|
|
class Constraint;
|
|
|
|
class IKConstraint;
|
|
|
|
class DeformVertices;
|
|
|
|
|
|
|
|
class IAnimatable;
|
|
|
|
class WorldClock;
|
|
|
|
class Animation;
|
|
|
|
class AnimationState;
|
|
|
|
class BonePose;
|
|
|
|
class BlendState;
|
|
|
|
class TimelineState;
|
|
|
|
class TweenTimelineState;
|
|
|
|
class BoneTimelineState;
|
|
|
|
class SlotTimelineState;
|
|
|
|
class ConstraintTimelineState;
|
|
|
|
class ActionTimelineState;
|
|
|
|
class ZOrderTimelineState;
|
|
|
|
class BoneAllTimelineState;
|
|
|
|
class SlotDislayTimelineState;
|
|
|
|
class SlotColorTimelineState;
|
|
|
|
class DeformTimelineState;
|
|
|
|
class IKConstraintTimelineState;
|
|
|
|
|
|
|
|
class IEventDispatcher;
|
|
|
|
class EventObject;
|
|
|
|
|
|
|
|
class DataParser;
|
|
|
|
class JSONDataParser;
|
|
|
|
class BinaryDataParser;
|
|
|
|
|
|
|
|
class BaseFactory;
|
|
|
|
class BuildArmaturePackage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
class DragonBones
|
2020-10-18 00:27:23 +08:00
|
|
|
{
|
|
|
|
DRAGONBONES_DISALLOW_COPY_AND_ASSIGN(DragonBones)
|
|
|
|
|
|
|
|
public:
|
|
|
|
static const std::string VEISION;
|
|
|
|
|
|
|
|
static bool yDown;
|
|
|
|
static bool debug;
|
|
|
|
static bool debugDraw;
|
|
|
|
static bool webAssembly;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<BaseObject*> _objects;
|
|
|
|
std::vector<EventObject*> _events;
|
|
|
|
WorldClock* _clock;
|
|
|
|
IEventDispatcher* _eventManager;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DragonBones(IEventDispatcher* eventManager);
|
|
|
|
virtual ~DragonBones();
|
|
|
|
|
|
|
|
void advanceTime(float passedTime);
|
|
|
|
void bufferEvent(EventObject* value);
|
|
|
|
void bufferObject(BaseObject* object);
|
|
|
|
WorldClock* getClock();
|
2021-12-25 10:04:45 +08:00
|
|
|
IEventDispatcher* getEventManager() const { return _eventManager; }
|
2020-10-18 00:27:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
DRAGONBONES_NAMESPACE_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // DRAGONBONES_H
|