Woopsi 1.3
Nintendo DS Gui Framework
libwoopsi/include/document.h
00001 #ifndef _TEXT_H_
00002 #define _TEXT_H_
00003 
00004 #include <nds.h>
00005 #include "fontbase.h"
00006 #include "woopsiarray.h"
00007 #include "woopsistring.h"
00008 
00009 namespace WoopsiUI {
00010 
00015     class Document {
00016 
00017     public:
00018 
00025         Document(FontBase* font, const WoopsiString& text, u16 width);
00026         
00030         virtual ~Document() { };
00031 
00036         virtual void setText(const WoopsiString& text);
00037 
00042         virtual void setText(const char* text);
00043 
00048         virtual void setText(const u32 text);
00049         
00054         virtual void append(const WoopsiString& text);
00055 
00061         virtual void insert(const WoopsiString& text, const s32 index);
00062 
00067         virtual void remove(const s32 startIndex);
00068 
00074         virtual void remove(const s32 startIndex, const s32 count);
00075         
00080         void setLineSpacing(u8 lineSpacing);
00081 
00087         void setWidth(u16 width);
00088 
00093         void setFont(FontBase* font);
00094 
00100         const u8 getLineLength(const s32 lineNumber) const;
00101 
00108         const s16 getLineTrimmedLength(const s32 lineNumber) const;
00109 
00115         const s16 getLinePixelLength(const s32 lineNumber) const;
00116 
00123         const s16 getLineTrimmedPixelLength(const s32 lineNumber) const;
00124 
00129         inline const s32 getPixelHeight() const { return _textPixelHeight; };
00130 
00135         inline const u8 getPixelWidth() const { return _textPixelWidth; };
00136 
00141         inline const u8 getLineSpacing() const { return _lineSpacing; };
00142 
00148         inline const u8 getLineHeight() const { return _font->getHeight() + _lineSpacing; };
00149 
00154         inline const s32 getLineCount() const { return _linePositions.size() - 1; };
00155 
00160         FontBase* getFont() const;
00161 
00166         void stripTopLines(const s32 lines);
00167         
00171         void wrap();
00172 
00179         void wrap(s32 charIndex);
00180 
00188         const s32 getLineContainingCharIndex(const s32 index) const;
00189 
00197         const s32 getLineStartIndex(const s32 line) const { return _linePositions[line]; };
00198 
00205         const WoopsiString& getText() const { return _text; };
00206 
00207     private:
00212         typedef struct {
00213             s32 index;
00214             u8 width;
00215         } LongestLine;
00216         
00217         FontBase* _font;                            
00218         WoopsiArray<s32> _linePositions;            
00219         WoopsiArray<LongestLine> _longestLines;     
00220         u8 _lineSpacing;                            
00221         s32 _textPixelHeight;                       
00222         u8 _textPixelWidth;                         
00223         u16 _width;                                 
00224         WoopsiString _text;                         
00225     };
00226 }
00227 
00228 #endif
 All Classes Functions Variables Enumerations Enumerator