#include "renderpng.h" #include "position.h" #include "map.h" #include "cell.h" #include "image.h" #include "palette.h" #include "font.h" #include #include #include #include #include RenderPng::RenderPng( Map &rMap ) : rMap( rMap ) { } RenderPng::~RenderPng() { } void RenderPng::render() { int iDims = rMap.getDims(); int iSize = 1; if( iDims > 2 ) iSize = (int)ceil(sqrt((rMap.getDims()-2)*2)); int iCellSize = 11; int iCellMid = iCellSize/2; int iBufWidth = ((iSize+1)*rMap.getSize( 0 )+1)*iCellSize; int iBufHeight = ((iSize+1)*rMap.getSize( 1 )+1)*iCellSize+12; int ox = 0; int oy = 12; Image im( iBufWidth, iBufHeight ); Font fnt("ter-u12n.bdf"); im.clear( 1 ); Palette pal; pal.addColor( 0, 0, 0 ); pal.addColor( 255, 255, 255 ); Position p( iDims ); for(;;) { int x = p[0]*(iSize+1); int y = p[1]*(iSize+1); int iWalls = rMap[p].iWalls; for( int iRow = 0; iRow < iSize+2; iRow++ ) { for( int iCol = 0; iCol < iSize+2; iCol++ ) { if( (iRow == 0 || iRow == iSize+1) && (iCol == 0 || iCol == iSize+1) ) { im.set( ox+(x+iCol)*iCellSize+iCellMid, oy+(y+iRow)*iCellSize+iCellMid, 0 ); if( iRow == 0 && iCol == 0 ) { if( (iWalls&(1<<2)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+i+iCellMid+1, oy+(y+iRow)*iCellSize+iCellMid, 0 ); } if( (iWalls&(1<<0)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+iCellMid, oy+(y+iRow)*iCellSize+i+iCellMid+1, 0 ); } } else if( iRow == 0 && iCol == iSize+1 ) { if( (iWalls&(1<<2)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+i, oy+(y+iRow)*iCellSize+iCellMid, 0 ); } if( (iWalls&(1<<1)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+iCellMid, oy+(y+iRow)*iCellSize+i+iCellMid+1, 0 ); } } else if( iRow == iSize+1 && iCol == 0 ) { if( (iWalls&(1<<3)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+i+iCellMid+1, oy+(y+iRow)*iCellSize+iCellMid, 0 ); } if( (iWalls&(1<<0)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+iCellMid, oy+(y+iRow)*iCellSize+i, 0 ); } } else if( iRow == iSize+1 && iCol == iSize+1 ) { if( (iWalls&(1<<3)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+i, oy+(y+iRow)*iCellSize+iCellMid, 0 ); } if( (iWalls&(1<<1)) == 0 ) { for( int i = 0; i < iCellMid+1; i++ ) im.set( ox+(x+iCol)*iCellSize+iCellMid, oy+(y+iRow)*iCellSize+i, 0 ); } } } else if( iRow == 0 && (iWalls&(1<<2)) == 0 ) { for( int i = 0; i < iCellSize; i++ ) { im.set( ox+(x+iCol)*iCellSize+i, oy+(y+iRow)*iCellSize+iCellMid, 0 ); } } else if( iRow == iSize+1 && (iWalls&(1<<3)) == 0 ) { for( int i = 0; i < iCellSize; i++ ) { im.set( ox+(x+iCol)*iCellSize+i, oy+(y+iRow)*iCellSize+iCellMid, 0 ); } } else if( iCol == 0 && (iWalls&(1<<0)) == 0 ) { for( int i = 0; i < iCellSize; i++ ) { im.set( ox+(x+iCol)*iCellSize+iCellMid, oy+(y+iRow)*iCellSize+i, 0 ); } } else if( iCol == iSize+1 && (iWalls&(1<<1)) == 0 ) { for( int i = 0; i < iCellSize; i++ ) { im.set( ox+(x+iCol)*iCellSize+iCellMid, oy+(y+iRow)*iCellSize+i, 0 ); } } } } for( int j = 2; j < iDims; j++ ) { for( int side = 0; side < 2; side++ ) { int d = j*2+side; if( iWalls&(1< 2 ) { char buf[1024]; sprintf( buf, "-%d", rMap.getSize(2)-p[2] ); strcat( fname, buf ); sprintf( buf, "Floor: %d", rMap.getSize(2)-p[2] ); strcpy( title, buf ); for( int j = 3; j < iDims; j++ ) { sprintf( buf, "-%d", rMap.getSize(j)-p[j] ); strcat( fname, buf ); sprintf( buf, ", %d", rMap.getSize(j)-p[j] ); strcat( title, buf ); } } else title[0] = '\0'; im.drawText( fnt, ox, oy-2, 0, title ); strcat( fname, ".png"); printf("Output: %s\n", fname ); im.save( fname, pal ); im.clear( 1 ); } } if( iDim == iDims ) break; /* for( int j = 2; j < iDims; j++ ) { for( int side = 0; side < 2; side++ ) { int d = j*2+side; if( iWalls&(1<