Advanced Strategic Command
textrenderer-addons.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  paradialog.cpp - description
3  -------------------
4  begin : Thu Feb 21 2002
5  copyright : (C) 2002 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 
20 #include <boost/regex.hpp>
21 #include <pglabel.h>
22 #include <pgimage.h>
23 
24 #include "../global.h"
25 
26 #include "textrenderer.h"
27 #include "../graphics/surface.h"
28 #include "../iconrepository.h"
30 
31 #include "../vehicletype.h"
32 #include "../itemrepository.h"
33 
34 
36 {
37  boost::regex vehicletypetag;
38  public:
39  VehicleTypeRenderer() : vehicletypetag("#vehicletype=(\\d+)#") {};
40 
41  bool renderWidget( const ASCString& tag, TextRenderer::Widgets& widgets, TextRenderer* parent )
42  {
43  boost::smatch what;
44  if( boost::regex_match( tag, what, vehicletypetag)) {
45  ASCString s ( what[1] );
46  int id = atoi ( s.c_str() );
47  VehicleType* vt = vehicleTypeRepository.getObject_byID( id );
48  if ( vt ) {
49  Surface& surf = vt->getImage();
50  widgets.push_back( new PG_Image( parent, PG_Point(0,0), surf.getBaseSurface(), false ));
51  } else {
52  widgets.push_back ( parent->parsingError ( "VehicleType " + ASCString::toString(id) + " not found" ) );
53  }
54  return true;
55  }
56  return false;
57  }
58 };
59 
60 
62 {
63  boost::regex coordinates;
64  public:
65  TargetCoordinateRenderer() : coordinates( "#coord\\((.*)\\)#") {};
66 
67  bool renderWidget( const ASCString& tag, TextRenderer::Widgets& widgets, TextRenderer* parent )
68  {
69  boost::smatch what;
70  if( boost::regex_match( tag, what, coordinates)) {
71  ASCString s ( what[1] );
72 
73  static boost::regex coordinates2( ";?(\\d+)/(\\d+)(.*)");
74  while ( boost::regex_match( s, what, coordinates2)) {
75  ASCString s2 ( what[1] );
76  int x = strtol(s2.c_str(), NULL, 0 );
77  int y = strtol( ASCString(what[2]).c_str(), NULL, 0 );
78 
80  positions.push_back( MapCoordinate(x,y));
81 
82  s.assign( what[3].first, what[3].second );
83 
84  widgets.push_back( new TargetCoordinateLocator( parent, PG_Point(0,0), positions ) );
85  }
86  return true;
87  }
88  return false;
89  }
90 };
91 
92 
93 namespace {
96 }
97 
99 {
100 
101 }
SDL_Surface * getBaseSurface()
Definition: surface.h:116
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
ItemRepositoryLoader< VehicleType > vehicleTypeRepository("vehicletype")
void uselessCallToTextRenderAddons()
Coordinate on the twodimensional map.
Definition: typen.h:202
static bool registerTagRenderer(TagRenderer *renderer)
int atoi(const std::string &s)
Definition: misc.cpp:152
vector< MapCoordinate > CoordinateList
Definition: fieldmarker.h:45
bool renderWidget(const ASCString &tag, TextRenderer::Widgets &widgets, TextRenderer *parent)
list< PG_Widget * > Widgets
Definition: textrenderer.h:47
bool renderWidget(const ASCString &tag, TextRenderer::Widgets &widgets, TextRenderer *parent)
PG_Widget * parsingError(const ASCString &errorMessage)