1 module spine.atlas; 2 3 import std.string: toStringz; 4 import std.exception; 5 import spine.skeleton: spAttachment; 6 import spine.color: spColor; 7 8 class Atlas 9 { 10 package spAtlas* atlas; 11 12 this(string filename) 13 { 14 atlas = spAtlas_createFromFile(filename.toStringz, null); 15 16 enforce(atlas); 17 } 18 19 ~this() 20 { 21 spAtlas_dispose(atlas); 22 } 23 24 spAtlasRegion* findRegion (string name) const 25 { 26 return spAtlas_findRegion (atlas, name.toStringz); 27 } 28 } 29 30 extern(C): 31 32 enum spAtlasFormat 33 { 34 SP_ATLAS_UNKNOWN_FORMAT, 35 SP_ATLAS_ALPHA, 36 SP_ATLAS_INTENSITY, 37 SP_ATLAS_LUMINANCE_ALPHA, 38 SP_ATLAS_RGB565, 39 SP_ATLAS_RGBA4444, 40 SP_ATLAS_RGB888, 41 SP_ATLAS_RGBA8888 42 }; 43 44 enum spAtlasFilter 45 { 46 SP_ATLAS_UNKNOWN_FILTER, 47 SP_ATLAS_NEAREST, 48 SP_ATLAS_LINEAR, 49 SP_ATLAS_MIPMAP, 50 SP_ATLAS_MIPMAP_NEAREST_NEAREST, 51 SP_ATLAS_MIPMAP_LINEAR_NEAREST, 52 SP_ATLAS_MIPMAP_NEAREST_LINEAR, 53 SP_ATLAS_MIPMAP_LINEAR_LINEAR 54 }; 55 56 enum spAtlasWrap 57 { 58 SP_ATLAS_MIRROREDREPEAT, 59 SP_ATLAS_CLAMPTOEDGE, 60 SP_ATLAS_REPEAT 61 }; 62 63 package: 64 65 struct spAtlasPage 66 { 67 const(spAtlas)* atlas; 68 const(char)* name; 69 spAtlasFormat format; 70 spAtlasFilter minFilter, magFilter; 71 spAtlasWrap uWrap, vWrap; 72 73 void* rendererObject; 74 int width, height; 75 76 spAtlasPage* next; 77 }; 78 79 struct spAtlas; 80 81 public struct spAtlasRegion 82 { 83 const(char)* name; 84 int x, y, width, height; 85 float u, v, u2, v2; 86 int offsetX, offsetY; 87 int originalWidth, originalHeight; 88 int index; 89 int/*bool*/rotate; 90 int/*bool*/flip; 91 int* splits; 92 int* pads; 93 94 spAtlasPage* page; 95 96 spAtlasRegion* next; 97 }; 98 99 struct spRegionAttachment 100 { 101 spAttachment _super; 102 const char* path; 103 float x, y, scaleX, scaleY, rotation, width, height; 104 spColor color; 105 106 void* rendererObject; 107 int regionOffsetX, regionOffsetY; /* Pixels stripped from the bottom left, unrotated. */ 108 int regionWidth, regionHeight; /* Unrotated, stripped pixel size. */ 109 int regionOriginalWidth, regionOriginalHeight; /* Unrotated, unstripped pixel size. */ 110 111 float[8] offset; 112 float[8] uvs; 113 } 114 115 enum spVertexIndex 116 { 117 //~ BLX = 0, BLY, ULX, ULY, URX, URY, BRX, BRY 118 X1 = 0, 119 Y1, 120 X2, 121 Y2, 122 X3, 123 Y3, 124 X4, 125 Y4 126 } 127 128 struct spVertexAttachment 129 { 130 spAttachment _super; 131 132 int bonesCount; 133 int* bones; 134 135 int verticesCount; 136 float* vertices; 137 138 int worldVerticesLength; 139 }; 140 141 struct spMeshAttachment 142 { 143 spVertexAttachment _super; 144 145 void* rendererObject; 146 int regionOffsetX, regionOffsetY; /* Pixels stripped from the bottom left, unrotated. */ 147 int regionWidth, regionHeight; /* Unrotated, stripped pixel size. */ 148 int regionOriginalWidth, regionOriginalHeight; /* Unrotated, unstripped pixel size. */ 149 float regionU, regionV, regionU2, regionV2; 150 int/*bool*/regionRotate; 151 152 const(char)* path; 153 154 float* regionUVs; 155 float* uvs; 156 157 int trianglesCount; 158 ushort* triangles; 159 160 spColor color; 161 162 int hullLength; 163 164 const(spMeshAttachment)* parentMesh; 165 int/*bool*/inheritDeform; 166 167 /* Nonessential. */ 168 int edgesCount; 169 int* edges; 170 float width, height; 171 } 172 173 private: 174 175 spAtlas* spAtlas_createFromFile (const(char)* path, void* rendererObject); 176 177 void spAtlas_dispose (spAtlas* atlas); 178 179 char* _spUtil_readFile(const(char)* path, int* length) 180 { 181 return _spReadFile(path, length); // TODO: it is need to set up something like errno here 182 } 183 184 char* _spReadFile (const(char)* path, int* length); 185 186 spAtlasRegion* spAtlas_findRegion (const(spAtlas)* self, const(char)* name);