Atlas.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #ifndef SPINE_ATLAS_H_
  31. #define SPINE_ATLAS_H_
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. typedef struct spAtlas spAtlas;
  36. typedef enum {
  37. SP_ATLAS_UNKNOWN_FORMAT,
  38. SP_ATLAS_ALPHA,
  39. SP_ATLAS_INTENSITY,
  40. SP_ATLAS_LUMINANCE_ALPHA,
  41. SP_ATLAS_RGB565,
  42. SP_ATLAS_RGBA4444,
  43. SP_ATLAS_RGB888,
  44. SP_ATLAS_RGBA8888
  45. } spAtlasFormat;
  46. typedef enum {
  47. SP_ATLAS_UNKNOWN_FILTER,
  48. SP_ATLAS_NEAREST,
  49. SP_ATLAS_LINEAR,
  50. SP_ATLAS_MIPMAP,
  51. SP_ATLAS_MIPMAP_NEAREST_NEAREST,
  52. SP_ATLAS_MIPMAP_LINEAR_NEAREST,
  53. SP_ATLAS_MIPMAP_NEAREST_LINEAR,
  54. SP_ATLAS_MIPMAP_LINEAR_LINEAR
  55. } spAtlasFilter;
  56. typedef enum {
  57. SP_ATLAS_MIRROREDREPEAT,
  58. SP_ATLAS_CLAMPTOEDGE,
  59. SP_ATLAS_REPEAT
  60. } spAtlasWrap;
  61. typedef struct spAtlasPage spAtlasPage;
  62. struct spAtlasPage {
  63. const spAtlas* atlas;
  64. const char* name;
  65. spAtlasFormat format;
  66. spAtlasFilter minFilter, magFilter;
  67. spAtlasWrap uWrap, vWrap;
  68. void* rendererObject;
  69. int width, height;
  70. spAtlasPage* next;
  71. };
  72. spAtlasPage* spAtlasPage_create (spAtlas* atlas, const char* name);
  73. void spAtlasPage_dispose (spAtlasPage* self);
  74. #ifdef SPINE_SHORT_NAMES
  75. typedef spAtlasFormat AtlasFormat;
  76. #define ATLAS_UNKNOWN_FORMAT SP_ATLAS_UNKNOWN_FORMAT
  77. #define ATLAS_ALPHA SP_ATLAS_ALPHA
  78. #define ATLAS_INTENSITY SP_ATLAS_INTENSITY
  79. #define ATLAS_LUMINANCE_ALPHA SP_ATLAS_LUMINANCE_ALPHA
  80. #define ATLAS_RGB565 SP_ATLAS_RGB565
  81. #define ATLAS_RGBA4444 SP_ATLAS_RGBA4444
  82. #define ATLAS_RGB888 SP_ATLAS_RGB888
  83. #define ATLAS_RGBA8888 SP_ATLAS_RGBA8888
  84. typedef spAtlasFilter AtlasFilter;
  85. #define ATLAS_UNKNOWN_FILTER SP_ATLAS_UNKNOWN_FILTER
  86. #define ATLAS_NEAREST SP_ATLAS_NEAREST
  87. #define ATLAS_LINEAR SP_ATLAS_LINEAR
  88. #define ATLAS_MIPMAP SP_ATLAS_MIPMAP
  89. #define ATLAS_MIPMAP_NEAREST_NEAREST SP_ATLAS_MIPMAP_NEAREST_NEAREST
  90. #define ATLAS_MIPMAP_LINEAR_NEAREST SP_ATLAS_MIPMAP_LINEAR_NEAREST
  91. #define ATLAS_MIPMAP_NEAREST_LINEAR SP_ATLAS_MIPMAP_NEAREST_LINEAR
  92. #define ATLAS_MIPMAP_LINEAR_LINEAR SP_ATLAS_MIPMAP_LINEAR_LINEAR
  93. typedef spAtlasWrap AtlasWrap;
  94. #define ATLAS_MIRROREDREPEAT SP_ATLAS_MIRROREDREPEAT
  95. #define ATLAS_CLAMPTOEDGE SP_ATLAS_CLAMPTOEDGE
  96. #define ATLAS_REPEAT SP_ATLAS_REPEAT
  97. typedef spAtlasPage AtlasPage;
  98. #define AtlasPage_create(...) spAtlasPage_create(__VA_ARGS__)
  99. #define AtlasPage_dispose(...) spAtlasPage_dispose(__VA_ARGS__)
  100. #endif
  101. /**/
  102. typedef struct spAtlasRegion spAtlasRegion;
  103. struct spAtlasRegion {
  104. const char* name;
  105. int x, y, width, height;
  106. float u, v, u2, v2;
  107. int offsetX, offsetY;
  108. int originalWidth, originalHeight;
  109. int index;
  110. int/*bool*/rotate;
  111. int/*bool*/flip;
  112. int* splits;
  113. int* pads;
  114. spAtlasPage* page;
  115. spAtlasRegion* next;
  116. };
  117. spAtlasRegion* spAtlasRegion_create ();
  118. void spAtlasRegion_dispose (spAtlasRegion* self);
  119. #ifdef SPINE_SHORT_NAMES
  120. typedef spAtlasRegion AtlasRegion;
  121. #define AtlasRegion_create(...) spAtlasRegion_create(__VA_ARGS__)
  122. #define AtlasRegion_dispose(...) spAtlasRegion_dispose(__VA_ARGS__)
  123. #endif
  124. /**/
  125. struct spAtlas {
  126. spAtlasPage* pages;
  127. spAtlasRegion* regions;
  128. void* rendererObject;
  129. };
  130. /* Image files referenced in the atlas file will be prefixed with dir. */
  131. spAtlas* spAtlas_create (const char* data, int length, const char* dir, void* rendererObject);
  132. /* Image files referenced in the atlas file will be prefixed with the directory containing the atlas file. */
  133. spAtlas* spAtlas_createFromFile (const char* path, void* rendererObject);
  134. void spAtlas_dispose (spAtlas* atlas);
  135. /* Returns 0 if the region was not found. */
  136. spAtlasRegion* spAtlas_findRegion (const spAtlas* self, const char* name);
  137. #ifdef SPINE_SHORT_NAMES
  138. typedef spAtlas Atlas;
  139. #define Atlas_create(...) spAtlas_create(__VA_ARGS__)
  140. #define Atlas_createFromFile(...) spAtlas_createFromFile(__VA_ARGS__)
  141. #define Atlas_dispose(...) spAtlas_dispose(__VA_ARGS__)
  142. #define Atlas_findRegion(...) spAtlas_findRegion(__VA_ARGS__)
  143. #endif
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif /* SPINE_ATLAS_H_ */