64 return iter->second.image;
72 for(
uint32_t i = 0; i < index; ++i, ++iter);
73 return iter->second.image;
77 return m_subimages.insert(std::pair<std::string, AtlasData>(imagename, data)).second;
89 : m_model(model), m_vfs(vfs), m_imageManager(imageManager), m_animationManager(animationManager) {
96 bfs::path atlasPath(filename);
97 std::string atlasFilename = atlasPath.string();
98 TiXmlDocument atlasFile;
107 if (atlasFile.Error()) {
118 }
catch (NotFound&) {
123 TiXmlElement* root = atlasFile.RootElement();
125 if (root && root->ValueStr() ==
"assets") {
126 if (root->FirstChildElement(
"atlas")) {
135 bfs::path atlasPath(filename);
136 bfs::path atlasPathDirectory;
137 std::string atlasFilename = atlasPath.string();
164 catch (NotFound& e) {
176 TiXmlElement* root = doc.RootElement();
178 if (root && root->ValueStr() ==
"assets") {
179 atlas =
loadAtlas(filename, root->FirstChildElement(
"atlas"));
186 bfs::path atlasPath(filename);
187 bfs::path atlasPathDirectory;
188 std::string atlasFilename = atlasPath.string();
196 std::vector<AtlasPtr> atlasVector;
215 catch (NotFound& e) {
227 TiXmlElement* root = doc.RootElement();
229 if (root && root->ValueStr() ==
"assets") {
230 for (TiXmlElement* atlasElem = root->FirstChildElement(
"atlas"); atlasElem; atlasElem = atlasElem->NextSiblingElement(
"atlas")) {
233 atlasVector.push_back(atlas);
247 const std::string* atlasSource = atlasElem->Attribute(std::string(
"source"));
249 const std::string* atlasId = atlasElem->Attribute(std::string(
"id"));
251 bfs::path atlasPath(filename);
252 bfs::path atlasPathDirectory;
259 bfs::path atlasImagePath = atlasPathDirectory / *atlasSource;
260 atlas.
reset(
new Atlas(atlasImagePath.string()));
271 if (atlasElem->FirstChildElement(
"subimage")) {
272 for (TiXmlElement* imageElem = atlasElem->FirstChildElement(
"subimage");
273 imageElem != 0; imageElem = imageElem->NextSiblingElement(
"subimage")) {
275 const std::string* subimageId = imageElem->Attribute(std::string(
"id"));
278 imageElem->QueryValueAttribute(
"xpos", ®ion.
x);
279 imageElem->QueryValueAttribute(
"ypos", ®ion.
y);
280 imageElem->QueryValueAttribute(
"width", ®ion.
w);
281 imageElem->QueryValueAttribute(
"height", ®ion.
h);
283 std::string finalname;
286 finalname = *atlasId +
":" + *subimageId;
288 finalname = *subimageId;
299 AtlasData atlasData = {region, subImage};
300 atlas->addImage(finalname, atlasData);
308 int subimageWidth = 0;
309 int subimageHeight = 0;
310 atlasElem->QueryValueAttribute(
"atlas_width", &atlasWidth);
311 atlasElem->QueryValueAttribute(
"atlas_height", &atlasHeight);
312 atlasElem->QueryValueAttribute(
"subimage_width", &subimageWidth);
313 atlasElem->QueryValueAttribute(
"subimage_height", &subimageHeight);
315 std::string extension = bfs::extension(*atlasSource);
318 atlasId = atlasSource;
321 if (atlasWidth != 0 && atlasHeight != 0 && subimageWidth != 0 && subimageHeight != 0) {
322 int x_rows = atlasWidth / subimageWidth;
323 int y_rows = atlasHeight / subimageHeight;
324 Rect region(0, 0, subimageWidth, subimageHeight);
325 for (
int y = 0; y < y_rows; ++y) {
326 region.
y = y * subimageHeight;
327 for (
int x = 0; x < x_rows; ++x) {
328 region.
x = x * subimageWidth;
331 snprintf(tmp, 64,
"%04d", frame);
332 std::ostringstream finalname;
333 finalname << *atlasId <<
":" << std::string(tmp) << extension;
343 AtlasData atlasData = {region, subImage};
344 atlas->addImage(finalname.str(), atlasData);
357 return new AtlasLoader(model, vfs, imageManager, animationManager);
virtual ImagePtr create(IResourceLoader *loader=0)
Creates a blank Image but does not load it immediately.
size_t getImageCount() const
Returns the number of subimages that belongs to this atlas.
virtual bool exists(const std::string &name)
Checks to see if an Image exists.
T h
Height of the rectangle.
ImagePtr & getPackedImage()
Returns an (packed) Image for this atlas.
void reset(T *ptr=0)
reset this pointer to a null shared pointer this can be used to lower the reference count of the shar...
AtlasLoader * createDefaultAtlasLoader(Model *model, VFS *vfs, ImageManager *imageManager, AnimationManager *animationManager)
convenience function for creating the default fife atlas loader deleting the object returned from thi...
virtual bool isLoadable(const std::string &filename)
RawData * open(const std::string &path)
Open a file.
static Logger _log(LM_AUDIO)
SharedPtr< Image > ImagePtr
virtual ImagePtr getPtr(const std::string &name)
#define FL_ERR(logger, msg)
uint32_t getDataLength() const
get the complete datalength
bool HasParentPath(const bfs::path &path)
Helper function to determine if a path object has a parent path.
ImageManager * m_imageManager
bfs::path GetParentPath(const bfs::path &path)
Helper function to retrieve a parent path object from a path object.
const std::string & getName() const
virtual AtlasPtr load(const std::string &filename)
void setPackedImage(const ImagePtr &image)
Sets the image for atlas to use it for rendering.
AtlasLoader(Model *model, VFS *vfs, ImageManager *imageManager, AnimationManager *animationManager)
A model is a facade for everything in the model.
AtlasPtr loadAtlas(const std::string &filename, TiXmlElement *atlasElem)
std::string readString(size_t len)
read a string with len bytes, not assuming a terminating 0 Appends a null terminator character to the...
the main VFS (virtual file system) class
ImagePtr getImage(const std::string &id)
Return an Image of given id.
virtual void useSharedImage(const ImagePtr &shared, const Rect ®ion)=0
After this call all image data will be taken from the given image and its subregion.
virtual std::vector< AtlasPtr > loadMultiple(const std::string &filename)
T w
Width of the rectangle.
bool addImage(const std::string &imagename, const AtlasData &data)
Adds new information about subimage that belongs to this atlas.
Used to access diffrent kinds of data.