00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <stdio.h>
00026 #include <cstring>
00027 #include <stdlib.h>
00028 #include <SDL_image.h>
00029
00030 #include "iconrepository.h"
00031 #include "basestrm.h"
00032 #include "messaginghub.h"
00033
00034
00035 IconRepository::Repository IconRepository::repository;
00036
00037 Surface& IconRepository::getIcon( const ASCString& name )
00038 {
00039 Repository::iterator i = repository.find( name );
00040 if ( i != repository.end() )
00041 return *i->second;
00042 else {
00043 try {
00044 tnfilestream fs ( name, tnstream::reading );
00045 if ( name.endswith(".raw") ) {
00046 repository[name] = new Surface();
00047 repository[name]->read( fs );
00048 } else {
00049 repository[name] = new Surface ( IMG_Load_RW ( SDL_RWFromStream( &fs ), 1));
00050 }
00051 return *repository[name];
00052 }
00053 catch ( tfileerror err ) {
00054 errorMessage("could not load " + err.getFileName() );
00055 if ( name != "dummy.png" )
00056 return getIcon( "dummy.png" );
00057 else
00058 throw;
00059 }
00060 }
00061 }
00062
00063 IconRepository::Repository::~Repository()
00064 {
00065 for ( Repository::iterator i = repository.begin(); i != repository.end(); ++i )
00066 delete i->second;
00067 }
00068
00069 bool IconRepository::exists( const ASCString& name )
00070 {
00071 return repository.find(name) != repository.end();
00072 }
00073
00074 void IconRepository::insert( const ASCString& name, Surface* s )
00075 {
00076 repository[name] = s;
00077 }
00078
00079 int IconRepository::getMemoryFootprint()
00080 {
00081 int size = 0;
00082 for ( Repository::iterator i = repository.begin(); i != repository.end(); ++i )
00083 size += i->second->getMemoryFootprint();
00084 return size;
00085 }
00086