/* Copyright (c) 2018 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __TextureAtlasData_H__ #define __TextureAtlasData_H__ #ifdef __cplusplus extern "C" { #endif typedef struct TextureAtlasData TextureAtlasData; #define TextureAtlasData_superclass StemObject #include "bitmapimage/BitmapImage.h" #include "gamemath/TextureAtlas.h" #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #include "stemobject/StemObject.h" #define TEXTUREATLASDATA_FORMAT_VERSION 4 #define TEXTUREATLASDATA_FORMAT_TYPE "texture_atlas" struct TextureAtlasData_entry { char * name; Rect4f bounds; // Stored in pixel coordinates (first row is top of image, bottom > top), as opposed to TextureAtlas which stores normalized coordinates (first row is bottom of image, top > bottom) }; #define TextureAtlasData_ivars \ StemObject_ivars \ \ unsigned int entryCount; \ struct TextureAtlasData_entry * entries; \ char * textureName; #define TextureAtlasData_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(TextureAtlasData) // entries is copied TextureAtlasData * TextureAtlasData_create(const char * textureName, unsigned int entryCount, struct TextureAtlasData_entry * entries); bool TextureAtlasData_init(TextureAtlasData * self, const char * textureName, unsigned int entryCount, struct TextureAtlasData_entry * entries); TextureAtlasData * TextureAtlasData_copy(TextureAtlasData * self); void TextureAtlasData_dispose(TextureAtlasData * self); TextureAtlasData * TextureAtlasData_deserialize(compat_type(DeserializationContext *) deserializationContext); bool TextureAtlasData_loadSerializedData(TextureAtlasData * self, compat_type(DeserializationContext *) deserializationContext); void TextureAtlasData_serialize(TextureAtlasData * self, compat_type(SerializationContext *) serializationContext); // Creates a TextureAtlas object initialized with this TextureAtlasData's entries. TextureAtlas * TextureAtlasData_createTextureAtlas(TextureAtlasData * self, unsigned int imageWidth, unsigned int imageHeight); // Transfers all entries in this TextureAtlasData to the specfied TextureAtlas, overwriting entries of the same name void TextureAtlasData_setTextureAtlasEntries(TextureAtlasData * self, TextureAtlas * textureAtlas, unsigned int imageWidth, unsigned int imageHeight); // Given the bounds field of a TextureAtlasData_entry, returns a rectangle appropriate for TextureAtlas, representing the same portion of the image Rect4f TextureAtlasData_convertToTextureAtlasCoodinates(Rect4f bounds, unsigned int imageWidth, unsigned int imageHeight); void TextureAtlasData_setEntry(TextureAtlasData * self, const char * entryName, Rect4f entryBounds); void TextureAtlasData_removeEntry(TextureAtlasData * self, const char * entryName); struct TextureAtlasData_entry * TextureAtlasData_getEntryWithName(TextureAtlasData * self, const char * entryName); #ifdef __cplusplus } #endif #endif