AtlasAttachmentLoader.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/AtlasAttachmentLoader.h>
  29. #include <spine/extension.h>
  30. spAttachment* _spAtlasAttachmentLoader_newAttachment (spAttachmentLoader* loader, spSkin* skin, spAttachmentType type,
  31. const char* name) {
  32. spAtlasAttachmentLoader* self = SUB_CAST(spAtlasAttachmentLoader, loader);
  33. switch (type) {
  34. case ATTACHMENT_REGION: {
  35. spRegionAttachment* attachment;
  36. spAtlasRegion* region = spAtlas_findRegion(self->atlas, name);
  37. if (!region) {
  38. _spAttachmentLoader_setError(loader, "Region not found: ", name);
  39. return 0;
  40. }
  41. attachment = spRegionAttachment_create(name);
  42. attachment->rendererObject = region;
  43. spRegionAttachment_setUVs(attachment, region->u, region->v, region->u2, region->v2, region->rotate);
  44. attachment->regionOffsetX = region->offsetX;
  45. attachment->regionOffsetY = region->offsetY;
  46. attachment->regionWidth = region->width;
  47. attachment->regionHeight = region->height;
  48. attachment->regionOriginalWidth = region->originalWidth;
  49. attachment->regionOriginalHeight = region->originalHeight;
  50. return SUPER(attachment);
  51. }
  52. case ATTACHMENT_BOUNDING_BOX:
  53. return SUPER(spBoundingBoxAttachment_create(name));
  54. default:
  55. _spAttachmentLoader_setUnknownTypeError(loader, type);
  56. return 0;
  57. }
  58. }
  59. spAtlasAttachmentLoader* spAtlasAttachmentLoader_create (spAtlas* atlas) {
  60. spAtlasAttachmentLoader* self = NEW(spAtlasAttachmentLoader);
  61. _spAttachmentLoader_init(SUPER(self), _spAttachmentLoader_deinit, _spAtlasAttachmentLoader_newAttachment);
  62. self->atlas = atlas;
  63. return self;
  64. }