/* 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 __TextureAtlas_H__ #define __TextureAtlas_H__ #ifdef __cplusplus extern "C" { #endif typedef struct TextureAtlas TextureAtlas; #define TextureAtlas_superclass StemObject #include "gamemath/Rect4f.h" #include "gamemath/Vector2f.h" #include "stemobject/StemObject.h" #include "utilities/HashTable.h" #include #define TextureAtlas_ivars \ StemObject_ivars \ \ unsigned int pixelWidth; \ unsigned int pixelHeight; \ HashTable * private_ivar(hashTable); #define TextureAtlas_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(TextureAtlas) // Both pixelWidth and pixelHeight must be greater than 0 TextureAtlas * TextureAtlas_create(unsigned int pixelWidth, unsigned int pixelHeight); bool TextureAtlas_init(TextureAtlas * self, unsigned int pixelWidth, unsigned int pixelHeight); void TextureAtlas_dispose(TextureAtlas * self); // Both pixelWidth and pixelHeight must be greater than 0 void TextureAtlas_setPixelDimensions(TextureAtlas * self, unsigned int pixelWidth, unsigned int pixelHeight); // Caller is responsible for freeing returned pointer (but not elements within it) HashTable_key * TextureAtlas_listKeys(TextureAtlas * self, size_t * outCount); size_t TextureAtlas_getKeyCount(TextureAtlas * self); HashTable_key * TextureAtlas_keyAtIndex(TextureAtlas * self, size_t keyIndex); bool TextureAtlas_hasKey(TextureAtlas * self, HashTable_key key); bool TextureAtlas_removeEntry(TextureAtlas * self, HashTable_key key); void TextureAtlas_removeAllEntries(TextureAtlas * self); // Rects are stored in relative coordinates (0-1) on both axes, as opposed to TextureAtlasData which stores pixel coordinates void TextureAtlas_setEntry(TextureAtlas * self, HashTable_key key, Rect4f entry); Rect4f TextureAtlas_lookup(TextureAtlas * self, HashTable_key key); // Returns the size in pixels of the specified entry Vector2f TextureAtlas_getEntryPixelDimensions(TextureAtlas * self, Rect4f entry); // Translates between relative and absolute coordinates, by multiplying/dividing each component by pixelWidth/pixelHeight Rect4f TextureAtlas_entryToPixelCoordinates(TextureAtlas * self, Rect4f entry); Rect4f TextureAtlas_pixelToEntryCoordinates(TextureAtlas * self, Rect4f entry); #ifdef __cplusplus } #endif #endif