Advanced Strategic Command
textrenderer.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 #ifndef textrendererH
12 #define textrendererH
13 
14 #include <list>
15 #include <pgscrollwidget.h>
16 #include "../global.h"
17 #include "../ascstring.h"
18 #include "../paradialog.h"
19 
20 class TextRenderer : public PG_ScrollWidget {
21 
22  struct RenderingAttribute {
23  RenderingAttribute() : spaceAfter(0), baseline(0),vspace(0), linebreak(false),absolutePosition(-1),firstLineIndent(-1), furtherLineIndent(-1) {};
24  int spaceAfter;
25  int baseline;
26  int vspace;
27  bool linebreak;
28  int absolutePosition;
29  int firstLineIndent;
30  int furtherLineIndent;
31  };
32 
33  struct TextAttributes {
34  TextAttributes() : fontsize(12), textcolor(-1), backgroundcolor(-1) {};
35  int fontsize;
36  int textcolor;
37  int backgroundcolor;
38  void assign ( PG_Widget* w );
39  };
40 
41  TextAttributes textAttributes;
42 
43  typedef std::map<PG_Widget*,RenderingAttribute> Attributes;
44  Attributes attributes;
45 
46  public:
47  typedef list<PG_Widget*> Widgets;
48  private:
49  Widgets widgets;
50  PG_Widget* lastWidget;
51 
52  ASCString my_text;
53 
54  static const int scrollsize = 40;
55 
56  protected:
57 
58 
59  bool isSpace( ASCString::charT character )
60  {
61  return character == ' ' || character == '\n' || character=='\r' || character == '\t';
62  }
63 
64  bool isBreaker( ASCString::charT character )
65  {
66  return character == ':' || character == ',' || character=='.' || character == ';' || character == '-';
67  }
68 
69 
70  int arrangeLine( int y, const Widgets& line, int lineHeight, int indent );
71 
72  int AreaWidth();
73  void layout();
74  void addWidget( PG_Widget* w );
75  void addWidget( Widgets w );
76  void addSpace( int space );
77  void addLinebreak( int pixel, int lines );
78  void addIndentation( int firstLine, int furtherLines );
79  void addAbsPosition( int pos );
80  ASCString substr( const ASCString& text, ASCString::const_iterator begin, ASCString::const_iterator end );
81  ASCString::const_iterator token ( const ASCString& text, ASCString::const_iterator start );
82  ASCString::const_iterator token_command ( const ASCString& text, ASCString::const_iterator start );
83  void parse( const ASCString& text );
84 
85  virtual PG_Widget* render( const ASCString& token );
86  virtual Widgets eval_command( const ASCString& token );
87  bool eventKeyDown(const SDL_KeyboardEvent* key);
88 
89  void clear();
90 
91  public:
92  TextRenderer (PG_Widget *parent, const PG_Rect &r, const std::string& text, const std::string &style="ScrollWidget");
93  TextRenderer (PG_Widget *parent, const PG_Rect &r=PG_Rect::null );
94  void SetText( const std::string& text );
95  virtual const PG_String& GetText();
96 
97  void saveText( bool stripFormatting );
98 
99  PG_Widget* parsingError( const ASCString& errorMessage );
100 
101  class TagRenderer {
102  public:
103  virtual bool renderWidget( const ASCString& tag, Widgets& widgets, TextRenderer* parent ) = 0;
104  virtual ~TagRenderer() {};
105  };
106 
107  static bool registerTagRenderer ( TagRenderer* renderer );
108 };
109 
110 
112  protected:
113  bool eventKeyDown(const SDL_KeyboardEvent* key);
114  public:
115  ViewFormattedText( const ASCString& title, const ASCString& text, const PG_Rect& pos );
116 };
117 
118 
119 
120 #endif
virtual PG_Widget * render(const ASCString &token)
bool eventKeyDown(const SDL_KeyboardEvent *key)
ASCStringHelpers::charT charT
Definition: ascstring.h:22
virtual Widgets eval_command(const ASCString &token)
ASCString substr(const ASCString &text, ASCString::const_iterator begin, ASCString::const_iterator end)
void lines(int x1, int y1, int x2, int y2)
Definition: edmisc.cpp:223
virtual const PG_String & GetText()
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
bool eventKeyDown(const SDL_KeyboardEvent *key)
ViewFormattedText(const ASCString &title, const ASCString &text, const PG_Rect &pos)
void addAbsPosition(int pos)
void SetText(const std::string &text)
int arrangeLine(int y, const Widgets &line, int lineHeight, int indent)
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
bool isSpace(ASCString::charT character)
Definition: textrenderer.h:59
bool isBreaker(ASCString::charT character)
Definition: textrenderer.h:64
static bool registerTagRenderer(TagRenderer *renderer)
void addLinebreak(int pixel, int lines)
void errorMessage(const ASCString &string)
void addSpace(int space)
ASCString::const_iterator token_command(const ASCString &text, ASCString::const_iterator start)
ASCString::const_iterator token(const ASCString &text, ASCString::const_iterator start)
TextRenderer(PG_Widget *parent, const PG_Rect &r, const std::string &text, const std::string &style="ScrollWidget")
void addIndentation(int firstLine, int furtherLines)
void saveText(bool stripFormatting)
list< PG_Widget * > Widgets
Definition: textrenderer.h:47
PG_Widget * parsingError(const ASCString &errorMessage)
void parse(const ASCString &text)
void addWidget(PG_Widget *w)
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181
virtual bool renderWidget(const ASCString &tag, Widgets &widgets, TextRenderer *parent)=0