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

textrenderer-addons.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           paradialog.cpp  -  description
00003                              -------------------
00004     begin                : Thu Feb 21 2002
00005     copyright            : (C) 2002 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 
00020 #include <boost/regex.hpp>
00021 #include <pglabel.h>
00022 #include <pgimage.h>
00023 
00024 #include "../global.h"
00025 
00026 #include "textrenderer.h"
00027 #include "../graphics/surface.h"
00028 #include "../iconrepository.h"
00029 #include "targetcoordinatelocator.h"
00030 
00031 #include "../vehicletype.h"
00032 #include "../itemrepository.h"
00033 
00034 
00035 class VehicleTypeRenderer: public TextRenderer::TagRenderer
00036 {
00037       boost::regex vehicletypetag;
00038    public:
00039       VehicleTypeRenderer() : vehicletypetag("#vehicletype=(\\d+)#")  {};
00040 
00041       bool renderWidget( const ASCString& tag, TextRenderer::Widgets& widgets, TextRenderer* parent  )
00042       {
00043          boost::smatch what;
00044          if( boost::regex_match( tag, what, vehicletypetag)) {
00045             ASCString s ( what[1] );
00046             int id = atoi ( s.c_str() );
00047             Vehicletype* vt = vehicleTypeRepository.getObject_byID( id );
00048             if ( vt ) {
00049                Surface& surf = vt->getImage();
00050                widgets.push_back( new PG_Image( parent, PG_Point(0,0), surf.getBaseSurface(), false ));
00051             } else {
00052                widgets.push_back ( parent->parsingError ( "VehicleType " + ASCString::toString(id) + " not found" ) );
00053             }
00054             return true;
00055          }
00056          return false;
00057       }
00058 };
00059 
00060 
00061 class TargetCoordinateRenderer: public TextRenderer::TagRenderer
00062 {
00063       boost::regex coordinates;
00064    public:
00065       TargetCoordinateRenderer() : coordinates( "#coord\\((.*)\\)#")  {};
00066 
00067       bool renderWidget( const ASCString& tag, TextRenderer::Widgets& widgets, TextRenderer* parent  )
00068       {
00069          boost::smatch what;
00070          if( boost::regex_match( tag, what, coordinates)) {
00071             ASCString s ( what[1] );
00072 
00073             static boost::regex coordinates2( ";?(\\d+)/(\\d+)(.*)");
00074             while ( boost::regex_match( s, what, coordinates2)) {
00075                ASCString s2 ( what[1] );
00076                int x = strtol(s2.c_str(), NULL, 0 );
00077                int y = strtol( ASCString(what[2]).c_str(), NULL, 0 );
00078 
00079                SelectFromMap::CoordinateList positions;
00080                positions.push_back( MapCoordinate(x,y));
00081                
00082                s.assign( what[3].first, what[3].second );
00083 
00084                widgets.push_back( new TargetCoordinateLocator( parent, PG_Point(0,0), positions ) );
00085             }
00086             return true;
00087          }
00088          return false;
00089       }
00090 };
00091 
00092 
00093 namespace {
00094    const bool r1 = TextRenderer::registerTagRenderer( new VehicleTypeRenderer );
00095    const bool r2 = TextRenderer::registerTagRenderer( new TargetCoordinateRenderer );
00096 }
00097 
00098 void uselessCallToTextRenderAddons()
00099 {
00100    
00101 }

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