Animation.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifndef Spine_Animation_h
  30. #define Spine_Animation_h
  31. #include <spine/Vector.h>
  32. #include <spine/HashMap.h>
  33. #include <spine/MixBlend.h>
  34. #include <spine/MixDirection.h>
  35. #include <spine/SpineObject.h>
  36. #include <spine/SpineString.h>
  37. namespace spine {
  38. class Timeline;
  39. class Skeleton;
  40. class Event;
  41. class SP_API Animation : public SpineObject {
  42. friend class AnimationState;
  43. friend class TrackEntry;
  44. friend class AnimationStateData;
  45. friend class AttachmentTimeline;
  46. friend class ColorTimeline;
  47. friend class DeformTimeline;
  48. friend class DrawOrderTimeline;
  49. friend class EventTimeline;
  50. friend class IkConstraintTimeline;
  51. friend class PathConstraintMixTimeline;
  52. friend class PathConstraintPositionTimeline;
  53. friend class PathConstraintSpacingTimeline;
  54. friend class RotateTimeline;
  55. friend class ScaleTimeline;
  56. friend class ShearTimeline;
  57. friend class TransformConstraintTimeline;
  58. friend class TranslateTimeline;
  59. friend class TwoColorTimeline;
  60. public:
  61. Animation(const String &name, Vector<Timeline *> &timelines, float duration);
  62. ~Animation();
  63. /// Applies all the animation's timelines to the specified skeleton.
  64. /// See also Timeline::apply(Skeleton&, float, float, Vector, float, MixPose, MixDirection)
  65. void apply(Skeleton &skeleton, float lastTime, float time, bool loop, Vector<Event *> *pEvents, float alpha,
  66. MixBlend blend, MixDirection direction);
  67. const String &getName();
  68. Vector<Timeline *> &getTimelines();
  69. bool hasTimeline(int id);
  70. float getDuration();
  71. void setDuration(float inValue);
  72. private:
  73. Vector<Timeline *> _timelines;
  74. HashMap<int, bool> _timelineIds;
  75. float _duration;
  76. String _name;
  77. /// @param target After the first and before the last entry.
  78. static int binarySearch(Vector<float> &values, float target, int step);
  79. /// @param target After the first and before the last entry.
  80. static int binarySearch(Vector<float> &values, float target);
  81. static int linearSearch(Vector<float> &values, float target, int step);
  82. };
  83. }
  84. #endif /* Spine_Animation_h */