OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
formatting.hpp
Go to the documentation of this file.
1 #ifndef MWGUI_FORMATTING_H
2 #define MWGUI_FORMATTING_H
3 
4 #include <MyGUI_Colour.h>
5 #include <map>
6 
7 namespace MWGui
8 {
9  namespace Formatting
10  {
11  struct TextStyle
12  {
14  mColour(0,0,0)
15  , mFont("Default")
16  , mTextSize(16)
17  {
18  }
19 
20  MyGUI::Colour mColour;
21  std::string mFont;
22  int mTextSize;
23  };
24 
25  struct BlockStyle
26  {
28  mAlign(MyGUI::Align::Left | MyGUI::Align::Top)
29  {
30  }
31 
32  MyGUI::Align mAlign;
33  };
34 
36  {
37  public:
38  typedef std::map<std::string, std::string> Attributes;
39  enum Events
40  {
41  Event_None = -2,
42  Event_EOF = -1,
48  };
49 
50  BookTextParser(const std::string & text);
51 
52  Events next();
53 
54  const Attributes & getAttributes() const;
55  std::string getReadyText() const;
56  bool isClosingTag() const;
57 
58  private:
59  void registerTag(const std::string & tag, Events type);
60  void flushBuffer();
61  void parseTag(std::string tag);
62 
63  size_t mIndex;
64  std::string mText;
65  std::string mReadyText;
66 
70  std::string mTag;
72  std::map<std::string, Events> mTagTypes;
73  std::string mBuffer;
74  };
75 
76  class Paginator
77  {
78  public:
79  typedef std::pair<int, int> Page;
80  typedef std::vector<Page> Pages;
81 
82  Paginator(int pageWidth, int pageHeight)
83  : mStartTop(0), mCurrentTop(0),
84  mPageWidth(pageWidth), mPageHeight(pageHeight),
86  {
87  }
88 
89  int getStartTop() const { return mStartTop; }
90  int getCurrentTop() const { return mCurrentTop; }
91  int getPageWidth() const { return mPageWidth; }
92  int getPageHeight() const { return mPageHeight; }
94  Pages getPages() const { return mPages; }
95 
96  void setStartTop(int top) { mStartTop = top; }
97  void setCurrentTop(int top) { mCurrentTop = top; }
98  void setIgnoreLeadingEmptyLines(bool ignore) { mIgnoreLeadingEmptyLines = ignore; }
99 
100  Paginator & operator<<(const Page & page)
101  {
102  mPages.push_back(page);
103  return *this;
104  }
105 
106  private:
111  };
112 
115  {
116  public:
117  Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup, const int pageWidth, const int pageHeight);
118  Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup);
119 
120  private:
121  void resetFontProperties();
122 
123  void handleDiv(const BookTextParser::Attributes & attr);
124  void handleFont(const BookTextParser::Attributes & attr);
125 
128  };
129 
131  {
132  public:
133  GraphicElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle);
134  virtual int getHeight() = 0;
135  virtual void paginate();
136  virtual int pageSplit();
137 
138  protected:
139  virtual ~GraphicElement() {}
140  MyGUI::Widget * mParent;
143  };
144 
146  {
147  public:
148  TextElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle,
149  const TextStyle & textStyle, const std::string & text);
150  virtual int getHeight();
151  virtual int pageSplit();
152  private:
153  int currentFontHeight() const;
155  MyGUI::EditBox * mEditBox;
156  };
157 
159  {
160  public:
161  ImageElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle,
162  const std::string & src, int width, int height);
163  virtual int getHeight();
164  virtual int pageSplit();
165 
166  private:
168  MyGUI::ImageBox * mImageBox;
169  };
170  }
171 }
172 
173 #endif
void setIgnoreLeadingEmptyLines(bool ignore)
Definition: formatting.hpp:98
Paginator & mPaginator
Definition: formatting.hpp:141
bool getIgnoreLeadingEmptyLines() const
Definition: formatting.hpp:93
BlockStyle mBlockStyle
Definition: formatting.hpp:142
BookTextParser(const std::string &text)
Definition: formatting.cpp:26
void setStartTop(int top)
Definition: formatting.hpp:96
int mTextSize
Definition: formatting.hpp:22
ImageElement(MyGUI::Widget *parent, Paginator &pag, const BlockStyle &blockStyle, const std::string &src, int width, int height)
Definition: formatting.cpp:457
Events
Definition: formatting.hpp:39
TextStyle()
Definition: formatting.hpp:13
bool mIgnoreNewlineTags
Definition: formatting.hpp:67
size_t mIndex
Definition: formatting.hpp:63
TextStyle mTextStyle
Definition: formatting.hpp:154
GraphicElement(MyGUI::Widget *parent, Paginator &pag, const BlockStyle &blockStyle)
Definition: formatting.cpp:368
Paginator::Pages markupToWidget(MyGUI::Widget *parent, const std::string &markup, const int pageWidth, const int pageHeight)
Definition: formatting.cpp:190
void setCurrentTop(int top)
Definition: formatting.hpp:97
MyGUI::EditBox * mEditBox
Definition: formatting.hpp:155
void flushBuffer()
Definition: formatting.cpp:111
MyGUI::Colour mColour
Definition: formatting.hpp:20
virtual int getHeight()
Definition: formatting.cpp:479
Attributes mAttributes
Definition: formatting.hpp:69
bool isClosingTag() const
Definition: formatting.cpp:122
Pages mPages
Definition: formatting.hpp:110
virtual int pageSplit()
Definition: formatting.cpp:484
int getStartTop() const
Definition: formatting.hpp:89
int getPageWidth() const
Definition: formatting.hpp:91
Pages getPages() const
Definition: formatting.hpp:94
int mPageHeight
Definition: formatting.hpp:108
int mCurrentTop
Definition: formatting.hpp:107
MyGUI::ImageBox * mImageBox
Definition: formatting.hpp:168
void registerTag(const std::string &tag, Events type)
Definition: formatting.cpp:41
utilities for parsing book/scroll text as mygui widgets
Definition: formatting.hpp:114
std::vector< Page > Pages
Definition: formatting.hpp:80
Definition: formatting.hpp:76
Definition: formatting.hpp:11
bool mIgnoreLineEndings
Definition: formatting.hpp:68
BlockStyle()
Definition: formatting.hpp:27
virtual int pageSplit()
Definition: formatting.cpp:427
std::map< std::string, Events > mTagTypes
Definition: formatting.hpp:72
std::map< std::string, std::string > Attributes
Definition: formatting.hpp:38
std::string mFont
Definition: formatting.hpp:21
BlockStyle mBlockStyle
Definition: formatting.hpp:127
Paginator & operator<<(const Page &page)
Definition: formatting.hpp:100
int currentFontHeight() const
Definition: formatting.cpp:413
std::string getReadyText() const
Definition: formatting.cpp:46
std::pair< int, int > Page
Definition: formatting.hpp:79
void resetFontProperties()
Definition: formatting.cpp:322
int mImageHeight
Definition: formatting.hpp:167
Events next()
Definition: formatting.cpp:51
int mPageWidth
Definition: formatting.hpp:108
void parseTag(std::string tag)
Definition: formatting.cpp:127
bool mIgnoreLeadingEmptyLines
Definition: formatting.hpp:109
virtual int getHeight()
Definition: formatting.cpp:422
std::string mTag
Definition: formatting.hpp:70
MyGUI::Widget * mParent
Definition: formatting.hpp:140
int getCurrentTop() const
Definition: formatting.hpp:90
void handleFont(const BookTextParser::Attributes &attr)
Definition: formatting.cpp:342
virtual void paginate()
Definition: formatting.cpp:373
int getPageHeight() const
Definition: formatting.hpp:92
MyGUI::Align mAlign
Definition: formatting.hpp:32
Definition: formatting.hpp:158
std::string mReadyText
Definition: formatting.hpp:65
TextElement(MyGUI::Widget *parent, Paginator &pag, const BlockStyle &blockStyle, const TextStyle &textStyle, const std::string &text)
Definition: formatting.cpp:392
std::string mBuffer
Definition: formatting.hpp:73
TextStyle mTextStyle
Definition: formatting.hpp:126
void handleDiv(const BookTextParser::Attributes &attr)
Definition: formatting.cpp:327
Definition: formatting.hpp:35
Definition: formatting.hpp:145
bool mClosingTag
Definition: formatting.hpp:71
Paginator(int pageWidth, int pageHeight)
Definition: formatting.hpp:82
virtual int pageSplit()
Definition: formatting.cpp:386
virtual ~GraphicElement()
Definition: formatting.hpp:139
const Attributes & getAttributes() const
Definition: formatting.cpp:117
Definition: formatting.hpp:130
Definition: formatting.hpp:25
int mStartTop
Definition: formatting.hpp:107
std::string mText
Definition: formatting.hpp:64