From f314041b6b37bb9274d9fc79946858341befa0f2 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 8 Apr 2015 08:40:05 -0600 Subject: Added image goo + font support. --- src/renderpng.cpp | 251 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 160 insertions(+), 91 deletions(-) (limited to 'src/renderpng.cpp') diff --git a/src/renderpng.cpp b/src/renderpng.cpp index 21d35ba..6ff9fbe 100644 --- a/src/renderpng.cpp +++ b/src/renderpng.cpp @@ -3,11 +3,15 @@ #include "map.h" #include "cell.h" +#include "image.h" +#include "palette.h" +#include "font.h" + #include #include #include #include -#include +#include RenderPng::RenderPng( Map &rMap ) : rMap( rMap ) @@ -25,16 +29,18 @@ void RenderPng::render() if( iDims > 2 ) iSize = (int)ceil(sqrt((rMap.getDims()-2)*2)); - int iBufWidth = ((iSize+1)*rMap.getSize( 0 )+1)*5; - int iBufHeight = ((iSize+1)*rMap.getSize( 1 )+1)*5; - int iBufSize = iBufWidth*iBufHeight; - uint8_t *pBuf = new uint8_t[iBufSize]; - uint8_t **pRows = new uint8_t*[iBufHeight]; - for( int r = 0; r < iBufHeight; r++ ) - { - pRows[r] = pBuf+(iBufWidth*r); - } - memset( pBuf, 1, iBufSize ); + 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(;;) @@ -50,86 +56,138 @@ void RenderPng::render() if( (iRow == 0 || iRow == iSize+1) && (iCol == 0 || iCol == iSize+1) ) { - pRows[(y+iRow)*5+2][(x+iCol)*5+2] = 0; + 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 < 3; i++ ) - pRows[(y+iRow)*5+2][(x+iCol)*5+i+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 < 3; i++ ) - pRows[(y+iRow)*5+i+3][(x+iCol)*5+2] = 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 < 3; i++ ) - pRows[(y+iRow)*5+2][(x+iCol)*5+i] = 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 < 3; i++ ) - pRows[(y+iRow)*5+i+3][(x+iCol)*5+2] = 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 < 3; i++ ) - pRows[(y+iRow)*5+2][(x+iCol)*5+i+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 < 3; i++ ) - pRows[(y+iRow)*5+i][(x+iCol)*5+2] = 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 < 3; i++ ) - pRows[(y+iRow)*5+2][(x+iCol)*5+i] = 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 < 3; i++ ) - pRows[(y+iRow)*5+i][(x+iCol)*5+2] = 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 < 5; i++ ) + for( int i = 0; i < iCellSize; i++ ) { - pRows[(y+iRow)*5+2][(x+iCol)*5+i] = 0; + 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 < 5; i++ ) + for( int i = 0; i < iCellSize; i++ ) { - pRows[(y+iRow)*5+2][(x+iCol)*5+i] = 0; + 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 < 5; i++ ) + for( int i = 0; i < iCellSize; i++ ) { - pRows[(y+iRow)*5+i][(x+iCol)*5+2] = 0; + 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 < 5; i++ ) + for( int i = 0; i < iCellSize; i++ ) { - pRows[(y+iRow)*5+i][(x+iCol)*5+2] = 0; + im.set( + ox+(x+iCol)*iCellSize+iCellMid, + oy+(y+iRow)*iCellSize+i, + 0 + ); } } } @@ -142,43 +200,73 @@ void RenderPng::render() int d = j*2+side; if( iWalls&(1<