Slot.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /******************************************************************************
  2. * Spine Runtimes Software License
  3. * Version 2
  4. *
  5. * Copyright (c) 2013, Esoteric Software
  6. * All rights reserved.
  7. *
  8. * You are granted a perpetual, non-exclusive, non-sublicensable and
  9. * non-transferable license to install, execute and perform the Spine Runtimes
  10. * Software (the "Software") solely for internal use. Without the written
  11. * permission of Esoteric Software, you may not (a) modify, translate, adapt or
  12. * otherwise create derivative works, improvements of the Software or develop
  13. * new applications using the Software or (b) remove, delete, alter or obscure
  14. * any trademarks or any copyright, trademark, patent or other intellectual
  15. * property or proprietary rights notices on or in the Software, including
  16. * any copy thereof. Redistributions in binary or source form must include
  17. * this license and terms. THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  19. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTARE BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #include <spine/Slot.h>
  29. #include <spine/extension.h>
  30. #include <spine/Skeleton.h>
  31. typedef struct {
  32. spSlot super;
  33. float attachmentTime;
  34. } _spSlot;
  35. spSlot* spSlot_create (spSlotData* data, spSkeleton* skeleton, spBone* bone) {
  36. spSlot* self = SUPER(NEW(_spSlot));
  37. CONST_CAST(spSlotData*, self->data) = data;
  38. CONST_CAST(spSkeleton*, self->skeleton) = skeleton;
  39. CONST_CAST(spBone*, self->bone) = bone;
  40. spSlot_setToSetupPose(self);
  41. return self;
  42. }
  43. void spSlot_dispose (spSlot* self) {
  44. FREE(self);
  45. }
  46. void spSlot_setAttachment (spSlot* self, spAttachment* attachment) {
  47. CONST_CAST(spAttachment*, self->attachment) = attachment;
  48. SUB_CAST(_spSlot, self) ->attachmentTime = self->skeleton->time;
  49. }
  50. void spSlot_setAttachmentTime (spSlot* self, float time) {
  51. SUB_CAST(_spSlot, self) ->attachmentTime = self->skeleton->time - time;
  52. }
  53. float spSlot_getAttachmentTime (const spSlot* self) {
  54. return self->skeleton->time - SUB_CAST(_spSlot, self) ->attachmentTime;
  55. }
  56. void spSlot_setToSetupPose (spSlot* self) {
  57. spAttachment* attachment = 0;
  58. self->r = self->data->r;
  59. self->g = self->data->g;
  60. self->b = self->data->b;
  61. self->a = self->data->a;
  62. if (self->data->attachmentName) {
  63. /* Find slot index. */
  64. int i;
  65. for (i = 0; i < self->skeleton->data->slotCount; ++i) {
  66. if (self->data == self->skeleton->data->slots[i]) {
  67. attachment = spSkeleton_getAttachmentForSlotIndex(self->skeleton, i, self->data->attachmentName);
  68. break;
  69. }
  70. }
  71. }
  72. spSlot_setAttachment(self, attachment);
  73. }