File: textrenderer-addons.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 (101 lines) | stat: -rw-r--r-- 3,571 bytes parent folder | download | duplicates (3)
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
98
99
100
101
/***************************************************************************
                          paradialog.cpp  -  description
                             -------------------
    begin                : Thu Feb 21 2002
    copyright            : (C) 2002 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 <boost/regex.hpp>
#include <pglabel.h>
#include <pgimage.h>

#include "../global.h"

#include "textrenderer.h"
#include "../graphics/surface.h"
#include "../iconrepository.h"
#include "targetcoordinatelocator.h"

#include "../vehicletype.h"
#include "../itemrepository.h"


class VehicleTypeRenderer: public TextRenderer::TagRenderer
{
      boost::regex vehicletypetag;
   public:
      VehicleTypeRenderer() : vehicletypetag("#vehicletype=(\\d+)#")  {};

      bool renderWidget( const ASCString& tag, TextRenderer::Widgets& widgets, TextRenderer* parent  )
      {
         boost::smatch what;
         if( boost::regex_match( tag, what, vehicletypetag)) {
            ASCString s ( what[1] );
            int id = atoi ( s.c_str() );
            Vehicletype* vt = vehicleTypeRepository.getObject_byID( id );
            if ( vt ) {
               Surface& surf = vt->getImage();
               widgets.push_back( new PG_Image( parent, PG_Point(0,0), surf.getBaseSurface(), false ));
            } else {
               widgets.push_back ( parent->parsingError ( "VehicleType " + ASCString::toString(id) + " not found" ) );
            }
            return true;
         }
         return false;
      }
};


class TargetCoordinateRenderer: public TextRenderer::TagRenderer
{
      boost::regex coordinates;
   public:
      TargetCoordinateRenderer() : coordinates( "#coord\\((.*)\\)#")  {};

      bool renderWidget( const ASCString& tag, TextRenderer::Widgets& widgets, TextRenderer* parent  )
      {
         boost::smatch what;
         if( boost::regex_match( tag, what, coordinates)) {
            ASCString s ( what[1] );

            static boost::regex coordinates2( ";?(\\d+)/(\\d+)(.*)");
            while ( boost::regex_match( s, what, coordinates2)) {
               ASCString s2 ( what[1] );
               int x = strtol(s2.c_str(), NULL, 0 );
               int y = strtol( ASCString(what[2]).c_str(), NULL, 0 );

               SelectFromMap::CoordinateList positions;
               positions.push_back( MapCoordinate(x,y));
               
               s.assign( what[3].first, what[3].second );

               widgets.push_back( new TargetCoordinateLocator( parent, PG_Point(0,0), positions ) );
            }
            return true;
         }
         return false;
      }
};


namespace {
   const bool r1 = TextRenderer::registerTagRenderer( new VehicleTypeRenderer );
   const bool r2 = TextRenderer::registerTagRenderer( new TargetCoordinateRenderer );
}

void uselessCallToTextRenderAddons()
{
   
}