diff --git a/spine-cpp/spine-cpp/include/spine/Slot.h b/spine-cpp/spine-cpp/include/spine/Slot.h index 1b4e7d0f2..fd731260d 100644 --- a/spine-cpp/spine-cpp/include/spine/Slot.h +++ b/spine-cpp/spine-cpp/include/spine/Slot.h @@ -30,20 +30,21 @@ #ifndef Spine_Slot_h #define Spine_Slot_h +#include +#include +#include #include -#include #include namespace spine { - class SlotData; - class Bone; - class Skeleton; - class Attachment; - class SP_API Slot : public SpineObject { + /// Stores a slot's current pose. Slots organize attachments for Skeleton drawOrder purposes and provide a place to store + /// state for an attachment. State cannot be stored in an attachment itself because attachments are stateless and may be shared + /// across multiple skeletons. + class SP_API Slot : public Posed { friend class VertexAttachment; friend class Skeleton; @@ -91,48 +92,17 @@ namespace spine { friend class TwoColorTimeline; public: - Slot(SlotData &data, Bone &bone); - - void setToSetupPose(); - - SlotData &getData(); + Slot(SlotData &data, Skeleton &skeleton); + /// The bone this slot belongs to. Bone &getBone(); - Skeleton &getSkeleton(); - - Color &getColor(); - - Color &getDarkColor(); - - bool hasDarkColor(); - - /// May be NULL. - Attachment *getAttachment(); - - void setAttachment(Attachment *inValue); - - int getAttachmentState(); - - void setAttachmentState(int state); - - Vector &getDeform(); - - int getSequenceIndex(); - - void setSequenceIndex(int index); + void setupPose(); private: - SlotData &_data; - Bone &_bone; Skeleton &_skeleton; - Color _color; - Color _darkColor; - bool _hasDarkColor; - Attachment *_attachment; + Bone &_bone; int _attachmentState; - int _sequenceIndex; - Vector _deform; }; } diff --git a/spine-cpp/spine-cpp/include/spine/SlotPose.h b/spine-cpp/spine-cpp/include/spine/SlotPose.h index 100223f21..abf229cce 100644 --- a/spine-cpp/spine-cpp/include/spine/SlotPose.h +++ b/spine-cpp/spine-cpp/include/spine/SlotPose.h @@ -41,6 +41,7 @@ namespace spine { class VertexAttachment; class SP_API SlotPose : public Pose { + friend class Slot; friend class SlotCurveTimeline; friend class RGBATimeline; friend class RGBTimeline; diff --git a/spine-cpp/spine-cpp/src/spine/Slot.cpp b/spine-cpp/spine-cpp/src/spine/Slot.cpp index a0079f01c..b97b025d2 100644 --- a/spine-cpp/spine-cpp/src/spine/Slot.cpp +++ b/spine-cpp/spine-cpp/src/spine/Slot.cpp @@ -29,101 +29,40 @@ #include -#include #include #include #include -#include +#include +#include using namespace spine; -Slot::Slot(SlotData &data, Bone &bone) : _data(data), - _bone(bone), - _skeleton(bone.getSkeleton()), - _color(1, 1, 1, 1), - _darkColor(0, 0, 0, 0), - _hasDarkColor(data.hasDarkColor()), - _attachment(NULL), - _attachmentState(0), - _sequenceIndex(0) { - setToSetupPose(); -} - -void Slot::setToSetupPose() { - _color.set(_data.getColor()); - if (_hasDarkColor) _darkColor.set(_data.getDarkColor()); - - const String &attachmentName = _data.getAttachmentName(); - if (attachmentName.length() > 0) { - _attachment = NULL; - setAttachment(_skeleton.getAttachment(_data.getIndex(), attachmentName)); - } else { - setAttachment(NULL); +Slot::Slot(SlotData &data, Skeleton &skeleton) : + Posed(data), + _skeleton(skeleton), + _bone(*skeleton.getBones()[data.getBoneData().getIndex()]), + _attachmentState(0) { + + if (data.getSetupPose().hasDarkColor()) { + _pose._hasDarkColor = true; + _constrained._hasDarkColor = true; } + setupPose(); } -SlotData &Slot::getData() { - return _data; -} Bone &Slot::getBone() { return _bone; } -Skeleton &Slot::getSkeleton() { - return _skeleton; -} - -Color &Slot::getColor() { - return _color; -} - -Color &Slot::getDarkColor() { - return _darkColor; -} - -bool Slot::hasDarkColor() { - return _hasDarkColor; -} - -Attachment *Slot::getAttachment() { - return _attachment; -} - -void Slot::setAttachment(Attachment *inValue) { - if (_attachment == inValue) { - return; +void Slot::setupPose() { + _pose.getColor().set(_data.getSetupPose().getColor()); + if (_pose.hasDarkColor()) _pose.getDarkColor().set(_data.getSetupPose().getDarkColor()); + _pose.setSequenceIndex(_data.getSetupPose().getSequenceIndex()); + if (_data.getAttachmentName().isEmpty()) + _pose.setAttachment(NULL); + else { + _pose.setAttachment(NULL); + _pose.setAttachment(_skeleton.getAttachment(_data.getIndex(), _data.getAttachmentName())); } - - if (!inValue || - !_attachment || - !inValue->getRTTI().instanceOf(VertexAttachment::rtti) || - !_attachment->getRTTI().instanceOf(VertexAttachment::rtti) || - static_cast(inValue)->getTimelineAttachment() != - static_cast(_attachment)->getTimelineAttachment()) { - _deform.clear(); - } - - _attachment = inValue; - _sequenceIndex = -1; -} - -int Slot::getAttachmentState() { - return _attachmentState; -} - -void Slot::setAttachmentState(int state) { - _attachmentState = state; -} - -Vector &Slot::getDeform() { - return _deform; -} - -int Slot::getSequenceIndex() { - return _sequenceIndex; -} - -void Slot::setSequenceIndex(int index) { - _sequenceIndex = index; -} +} \ No newline at end of file