Picture PictureBank::makePicture(SDL_Surface *surface, const std::string& resource_name) const { Point offset( 0, 0 ); // decode the picture name => to set the offset manually // resource_name = "buildings/Govt_00005.png" int dot_pos = resource_name.find('.'); std::string filename = resource_name.substr(0, dot_pos); Point pic_info = PictureInfoBank::instance().getOffset(filename); if (pic_info.getX() == -1 && pic_info.getY() == -1) { // this is a tiled picture=> automatic offset correction offset.setY( surface->h-15*((surface->w+2)/60) ); // (w+2)/60 is the size of the tile: (1x1, 2x2, 3x3, ...) } else if (pic_info.getX() == -2 && pic_info.getY() == -2) { // this is a walker picture=> automatic offset correction offset = Point( -surface->w/2, int(surface->h*3./4.) ); } else { offset = pic_info; } Picture pic; pic.init( surface, offset ); pic.setName(filename); return pic; }
void PictureBank::Impl::setPicture( const std::string &name, const Picture& pic ) { int dot_pos = name.find_last_of('.'); std::string rcname = name.substr(0, dot_pos); // first: we deallocate the current picture, if any unsigned int picId = Hash( rcname ); Picture* ptrPic = 0; Impl::ItPicture it = resources.find( picId ); if( it != resources.end() ) { //SDL_DestroyTexture( it->second.texture() ); if( it->second.texture() > 0 ) txCounters[ it->second.texture() ]--; ptrPic = &it->second; } else { resources[ picId ] = Picture(); ptrPic = &resources[ picId ]; } *ptrPic = pic; if( pic.texture() > 0 ) txCounters[ pic.texture() ]++; Point offset( 0, 0 ); // decode the picture name => to set the offset manually Point pic_info = PictureInfoBank::instance().getOffset( rcname ); if( pic_info == PictureInfoBank::instance().getDefaultOffset( PictureInfoBank::tileOffset ) ) { // this is a tiled picture=> automatic offset correction int cw = gfx::tilemap::cellSize().width() * 2; int ch = gfx::tilemap::cellSize().width() / 2; offset.setY( pic.height()-ch*( (pic.width()+2)/cw ) ); // (w+2)/60 is the size of the tile: (1x1, 2x2, 3x3, ...) } else if( pic_info == PictureInfoBank::instance().getDefaultOffset( PictureInfoBank::walkerOffset ) ) { // this is a walker picture=> automatic offset correction offset = Point( -pic.width()/2, int(pic.height()*3./4.) ); } else { offset = pic_info; } ptrPic->setOffset( offset ); ptrPic->setName( rcname ); }
void addPhoneFiles(MobilePhone* mobilePhone) { Picture* picture; Document* document; picture = new Picture(1); picture->setPath("/data/local/tmp"); picture->setName("picture1.png"); picture->setSize(100); picture->setCreatedDate(QDate::currentDate()); mobilePhone->getPhoneFileManager().addPhoneFile(picture); document = new Document(2); document->setPath("/data/local/tmp"); document->setName("document1.png"); document->setSize(1000); document->setCreatedDate(QDate::currentDate()); mobilePhone->getPhoneFileManager().addPhoneFile(document); }