File: mapimageexport.cpp

package info (click to toggle)
asc 2.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 75,080 kB
  • ctags: 24,943
  • sloc: cpp: 155,023; sh: 8,829; ansic: 6,890; makefile: 650; perl: 138
file content (97 lines) | stat: -rw-r--r-- 3,733 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

/***************************************************************************
                             mapimageexport.cpp  
                             -------------------
    copyright            : (C) 2005 by Martin Bickel
    email                : bickel@asc-hq.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#include "loadpcx.h"
#include "mapdisplay.h"
#include "mapimageexport.h"
#include "dialogs/fileselector.h"
#include "graphics/surface2png.h"
#include "spfst.h"
#include "iconrepository.h"
#include "viewcalculation.h"

WholeMapRenderer :: WholeMapRenderer ( GameMap* actmap ) : gamemap ( actmap )
{
   int bufsizex = actmap->xsize * fielddistx + 200 ;
   int bufsizey = actmap->ysize * fielddisty + 200 ;
   surface = Surface::createSurface( bufsizex, bufsizey, 32, Surface::transparent << 24 );
}


void WholeMapRenderer::render()
{
   paintTerrain( surface, gamemap, gamemap->getPlayerView(), ViewPort( 0, 0, gamemap->xsize, gamemap->ysize ), MapCoordinate( 0, 0 ) );
   // renderVisibility();
}

void WholeMapRenderer::renderVisibility()
{
   computeview( gamemap );   
   ColorMerger_AlphaMerge<4> cmam;

   PutPixel<4, ColorMerger_AlphaMerge > pp(surface);

   Surface& mask = IconRepository::getIcon("largehex.pcx");
   for ( int y = 0; y < gamemap->ysize; ++y )
      for ( int x = 0; x < gamemap->xsize; ++x ) 
         if ( fieldvisiblenow( gamemap->getField(x,y), gamemap->getPlayerView() )) {
            int view = -1;
            int maxview = 0;
            for ( int i = 1; i < gamemap->getPlayerCount(); ++i )
               if ( gamemap->getField(x,y)->view[i].view > maxview ) {
                  maxview = gamemap->getField(x,y)->view[i].view;
                  view = i;
               }

            if ( view >= 0 )
               for ( int yp = 0; yp < fieldsizey; ++yp)
                  for ( int xp = 0; xp < fieldsizex; ++xp)
                     if ( mask.GetPixel(xp,yp) != 0xff ) 
                        pp.set( getFieldPos(x,y) + SPoint(xp,yp), gamemap->getPlayer( view ).getColor().MapRGBA( surface.getBaseSurface()->format, min(maxview,150)*2/3));
         }
}


void WholeMapRenderer::writePCX( const ASCString& filename )
{
   writepcx( filename, surface, SDLmm::SRect( SPoint( surfaceBorder, surfaceBorder), (gamemap->xsize-1) * fielddistx + fielddisthalfx + fieldsizex, (gamemap->ysize - 1) * fielddisty + fieldysize ) );
}

void WholeMapRenderer::writePNG( const ASCString& filename )
{
   ::writePNG( constructFileName(0,"",filename), surface, SDLmm::SRect( SPoint( surfaceBorder, surfaceBorder), (gamemap->xsize-1) * fielddistx + fielddisthalfx + fieldsizex, (gamemap->ysize - 1) * fielddisty + fieldysize ) );
}

void writemaptopcx ( GameMap* gamemap, bool addview )
{
   ASCString name = selectFile( "*.png", false );
   
   StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "writing map to " + name );
   
   if ( !name.empty() ) {
      WholeMapRenderer wmr( gamemap );
      wmr.render();
      if ( addview ) 
         wmr.renderVisibility();
      
      wmr.writePNG( name );
   }
}