File: textrenderer.h

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 (119 lines) | stat: -rw-r--r-- 3,997 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef textrendererH
#define textrendererH

#include <list>
#include <pgscrollwidget.h>
#include "../global.h"
#include "../ascstring.h"
#include "../paradialog.h"

class TextRenderer : public PG_ScrollWidget {

      struct RenderingAttribute {
         RenderingAttribute() : spaceAfter(0), baseline(0),vspace(0), linebreak(false),absolutePosition(-1),firstLineIndent(-1), furtherLineIndent(-1) {};
         int spaceAfter;
         int baseline;
         int vspace;
         bool linebreak;
         int absolutePosition;
         int firstLineIndent;
         int furtherLineIndent;
      };
   
      struct TextAttributes {
         TextAttributes() : fontsize(12), textcolor(-1), backgroundcolor(-1) {};
         int fontsize;
         int textcolor;
         int backgroundcolor;
         void assign ( PG_Widget* w );
      };
   
      TextAttributes textAttributes;
      
      typedef std::map<PG_Widget*,RenderingAttribute> Attributes;
      Attributes attributes;
   
   public:
      typedef list<PG_Widget*> Widgets;
   private:
      Widgets widgets;
      PG_Widget* lastWidget;

      ASCString my_text;

      static const int scrollsize = 40;
      
   protected:
   

      bool isSpace( ASCString::charT character )
      {
         return character == ' ' || character == '\n' || character=='\r' || character == '\t';
      }

      bool isBreaker( ASCString::charT character )
      {
         return character == ':' || character == ',' || character=='.' || character == ';' || character == '-';
      }


      int arrangeLine( int y, const Widgets& line, int lineHeight, int indent );
     
      int AreaWidth();
      void layout();
      void addWidget( PG_Widget* w );
      void addWidget( Widgets w );
      void addSpace( int space );
      void addLinebreak( int pixel, int lines );
      void addIndentation( int firstLine, int furtherLines );
      void addAbsPosition( int pos );
      ASCString substr( const ASCString& text, ASCString::const_iterator begin, ASCString::const_iterator end );
      ASCString::const_iterator token ( const ASCString& text, ASCString::const_iterator start );
      ASCString::const_iterator token_command ( const ASCString& text, ASCString::const_iterator start );
      void parse( const ASCString& text );
      
      virtual PG_Widget* render( const ASCString& token );
      virtual Widgets eval_command( const ASCString& token );
      bool eventKeyDown(const SDL_KeyboardEvent* key);
      
      void clear();
      
   public:
      TextRenderer (PG_Widget *parent, const PG_Rect &r, const std::string& text, const std::string &style="ScrollWidget");
      TextRenderer (PG_Widget *parent, const PG_Rect &r=PG_Rect::null );
      void SetText( const std::string& text );

      void saveText( bool stripFormatting );
      
      PG_Widget* parsingError( const ASCString& errorMessage );

      class TagRenderer {
         public:
            virtual bool renderWidget( const ASCString& tag, Widgets& widgets, TextRenderer* parent  ) = 0;
            virtual ~TagRenderer() {};
      };

      static bool registerTagRenderer ( TagRenderer* renderer );
};


class ViewFormattedText : public ASC_PG_Dialog {
   protected:
      bool eventKeyDown(const SDL_KeyboardEvent* key);
   public:
      ViewFormattedText( const ASCString& title, const ASCString& text, const PG_Rect& pos );
};



#endif