Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

mapimageexport.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003                              mapimageexport.cpp  
00004                              -------------------
00005     copyright            : (C) 2005 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 
00019 #include "loadpcx.h"
00020 #include "mapdisplay.h"
00021 #include "mapimageexport.h"
00022 #include "dialogs/fileselector.h"
00023 #include "graphics/surface2png.h"
00024 #include "spfst.h"
00025 #include "iconrepository.h"
00026 
00027 WholeMapRenderer :: WholeMapRenderer ( GameMap* actmap ) : gamemap ( actmap )
00028 {
00029    int bufsizex = actmap->xsize * fielddistx + 200 ;
00030    int bufsizey = actmap->ysize * fielddisty + 200 ;
00031    surface = Surface::createSurface( bufsizex, bufsizey, 32, Surface::transparent << 24 );
00032 }
00033 
00034 
00035 void WholeMapRenderer::render()
00036 {
00037    paintTerrain( surface, gamemap, gamemap->getPlayerView(), ViewPort( 0, 0, gamemap->xsize, gamemap->ysize ), MapCoordinate( 0, 0 ) );
00038    // renderVisibility();
00039 }
00040 
00041 void WholeMapRenderer::renderVisibility()
00042 {
00043    ColorMerger_AlphaMerge<4> cmam;
00044 
00045    PutPixel<4, ColorMerger_AlphaMerge > pp(surface);
00046 
00047    Surface& mask = IconRepository::getIcon("largehex.pcx");
00048    for ( int y = 0; y < gamemap->ysize; ++y )
00049       for ( int x = 0; x < gamemap->xsize; ++x ) 
00050          if ( fieldvisiblenow( gamemap->getField(x,y), gamemap->getPlayerView(), gamemap )) {
00051             int view = -1;
00052             int maxview = 0;
00053             for ( int i = 1; i < gamemap->getPlayerCount(); ++i )
00054                if ( gamemap->getField(x,y)->view[i].view > maxview ) {
00055                   maxview = gamemap->getField(x,y)->view[i].view;
00056                   view = i;
00057                }
00058 
00059             if ( view >= 0 )
00060                for ( int yp = 0; yp < fieldsizey; ++yp)
00061                   for ( int xp = 0; xp < fieldsizex; ++xp)
00062                      if ( mask.GetPixel(xp,yp) != 0xff ) 
00063                         pp.set( getFieldPos(x,y) + SPoint(xp,yp), gamemap->getPlayer( view ).getColor().MapRGBA( surface.getBaseSurface()->format, min(maxview,150)*2/3));
00064          }
00065 }
00066 
00067 
00068 void WholeMapRenderer::writePCX( const ASCString& filename )
00069 {
00070    writepcx( filename, surface, SDLmm::SRect( SPoint( surfaceBorder, surfaceBorder), (gamemap->xsize-1) * fielddistx + fielddisthalfx + fieldsizex, (gamemap->ysize - 1) * fielddisty + fieldysize ) );
00071 }
00072 
00073 void WholeMapRenderer::writePNG( const ASCString& filename )
00074 {
00075    ::writePNG( constructFileName(0,"",filename), surface, SDLmm::SRect( SPoint( surfaceBorder, surfaceBorder), (gamemap->xsize-1) * fielddistx + fielddisthalfx + fieldsizex, (gamemap->ysize - 1) * fielddisty + fieldysize ) );
00076 }
00077 
00078 void writemaptopcx ( GameMap* gamemap, bool addview )
00079 {
00080    ASCString name = selectFile( "*.png", false );
00081    
00082    StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "writing map to " + name );
00083    
00084    if ( !name.empty() ) {
00085       WholeMapRenderer wmr( gamemap );
00086       wmr.render();
00087       if ( addview ) 
00088          wmr.renderVisibility();
00089       
00090       wmr.writePNG( name );
00091    }
00092 }
00093 
00094 
00095 

Generated on Tue Jun 24 01:27:45 2008 for Advanced Strategic Command by  doxygen 1.4.2