00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef textrendererH
00012 #define textrendererH
00013
00014 #include <list>
00015 #include <pgscrollwidget.h>
00016 #include "../global.h"
00017 #include "../ascstring.h"
00018 #include "../paradialog.h"
00019
00020 class TextRenderer : public PG_ScrollWidget {
00021
00022 struct RenderingAttribute {
00023 RenderingAttribute() : spaceAfter(0), baseline(0),vspace(0), linebreak(false),absolutePosition(-1),firstLineIndent(-1), furtherLineIndent(-1) {};
00024 int spaceAfter;
00025 int baseline;
00026 int vspace;
00027 bool linebreak;
00028 int absolutePosition;
00029 int firstLineIndent;
00030 int furtherLineIndent;
00031 };
00032
00033 struct TextAttributes {
00034 TextAttributes() : fontsize(12), textcolor(-1), backgroundcolor(-1) {};
00035 int fontsize;
00036 int textcolor;
00037 int backgroundcolor;
00038 void assign ( PG_Widget* w );
00039 };
00040
00041 TextAttributes textAttributes;
00042
00043 typedef std::map<PG_Widget*,RenderingAttribute> Attributes;
00044 Attributes attributes;
00045
00046 public:
00047 typedef list<PG_Widget*> Widgets;
00048 private:
00049 Widgets widgets;
00050 PG_Widget* lastWidget;
00051
00052 ASCString my_text;
00053
00054 static const int scrollsize = 40;
00055
00056 protected:
00057
00058
00059 bool isSpace( ASCString::charT character )
00060 {
00061 return character == ' ' || character == '\n' || character=='\r' || character == '\t';
00062 }
00063
00064 bool isBreaker( ASCString::charT character )
00065 {
00066 return character == ':' || character == ',' || character=='.' || character == ';' || character == '-';
00067 }
00068
00069
00070 int arrangeLine( int y, const Widgets& line, int lineHeight, int indent );
00071
00072 int AreaWidth();
00073 void layout();
00074 void addWidget( PG_Widget* w );
00075 void addWidget( Widgets w );
00076 void addSpace( int space );
00077 void addLinebreak( int pixel, int lines );
00078 void addIndentation( int firstLine, int furtherLines );
00079 void addAbsPosition( int pos );
00080 ASCString substr( const ASCString& text, ASCString::const_iterator begin, ASCString::const_iterator end );
00081 ASCString::const_iterator token ( const ASCString& text, ASCString::const_iterator start );
00082 ASCString::const_iterator token_command ( const ASCString& text, ASCString::const_iterator start );
00083 void parse( const ASCString& text );
00084
00085 virtual PG_Widget* render( const ASCString& token );
00086 virtual Widgets eval_command( const ASCString& token );
00087 bool eventKeyDown(const SDL_KeyboardEvent* key);
00088
00089 void clear();
00090
00091 public:
00092 TextRenderer (PG_Widget *parent, const PG_Rect &r, const std::string& text, const std::string &style="ScrollWidget");
00093 TextRenderer (PG_Widget *parent, const PG_Rect &r=PG_Rect::null );
00094 void SetText( const std::string& text );
00095
00096 void saveText( bool stripFormatting );
00097
00098 PG_Widget* parsingError( const ASCString& errorMessage );
00099
00100 class TagRenderer {
00101 public:
00102 virtual bool renderWidget( const ASCString& tag, Widgets& widgets, TextRenderer* parent ) = 0;
00103 virtual ~TagRenderer() {};
00104 };
00105
00106 static bool registerTagRenderer ( TagRenderer* renderer );
00107 };
00108
00109
00110 class ViewFormattedText : public ASC_PG_Dialog {
00111 protected:
00112 bool eventKeyDown(const SDL_KeyboardEvent* key);
00113 public:
00114 ViewFormattedText( const ASCString& title, const ASCString& text, const PG_Rect& pos );
00115 };
00116
00117
00118
00119 #endif