OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bookpage.hpp
Go to the documentation of this file.
1 #ifndef MWGUI_BOOKPAGE_HPP
2 #define MWGUI_BOOKPAGE_HPP
3 
4 #include "MyGUI_Colour.h"
5 #include "MyGUI_Widget.h"
6 #include "MyGUI_FontManager.h"
7 
8 #include <functional>
9 #include <stdint.h>
10 
13 
14 #include "../mwbase/environment.hpp"
15 #include "../mwbase/windowmanager.hpp"
16 
17 namespace MWGui
18 {
21  struct TypesetBook
22  {
23  typedef std::shared_ptr <TypesetBook> Ptr;
25 
27  virtual size_t pageCount () const = 0;
28 
35  virtual std::pair <unsigned int, unsigned int> getSize () const = 0;
36  };
37 
38  struct GlyphInfo
39  {
40  char codePoint;
41  float width;
42  float height;
43  float advance;
44  float bearingX;
45  float bearingY;
46  MyGUI::FloatRect uvRect;
47 
48  GlyphInfo(MyGUI::IFont* font, MyGUI::Char ch)
49  {
50  static const int fontHeight = MWBase::Environment::get().getWindowManager()->getFontHeight();
51 
52  MyGUI::GlyphInfo* gi = font->getGlyphInfo(ch);
53  if (gi)
54  {
55  const float scale = font->getDefaultHeight() / (float) fontHeight;
56 
57  codePoint = gi->codePoint;
58  bearingX = (int) gi->bearingX / scale;
59  bearingY = (int) gi->bearingY / scale;
60  width = (int) gi->width / scale;
61  height = (int) gi->height / scale;
62  advance = (int) gi->advance / scale;
63  uvRect = gi->uvRect;
64  }
65  else
66  {
67  codePoint = -1;
68  bearingX = 0;
69  bearingY = 0;
70  width = 0;
71  height = 0;
72  advance = 0;
73  }
74  }
75  };
76 
79  {
80  typedef std::shared_ptr <BookTypesetter> Ptr;
82  typedef MyGUI::Colour Colour;
83  typedef uint8_t const * Utf8Point;
84  typedef std::pair <Utf8Point, Utf8Point> Utf8Span;
85 
86 
87 
88 
89  enum Alignment {
90  AlignLeft = -1,
93  };
94 
99  struct Style;
100 
102  static Ptr create (int pageWidth, int pageHeight);
103 
105  virtual Style* createStyle (const std::string& fontName, const Colour& colour, bool useBookFont=true) = 0;
106 
110  virtual Style* createHotStyle (Style * BaseStyle, const Colour& NormalColour, const Colour& HoverColour,
111  const Colour& ActiveColour, InteractiveId Id, bool Unique = true) = 0;
112 
116  virtual void lineBreak (float margin = 0) = 0;
117 
122  virtual void sectionBreak (int margin = 0) = 0;
123 
125  virtual void setSectionAlignment (Alignment sectionAlignment) = 0;
126 
127  // Layout a block of text with the specified style into the document.
128  virtual void write (Style * Style, Utf8Span Text) = 0;
129 
133  virtual intptr_t addContent (Utf8Span Text, bool Select = true) = 0;
134 
136  virtual void selectContent (intptr_t contentHandle) = 0;
137 
140  virtual void write (Style * Style, size_t Begin, size_t End) = 0;
141 
143  virtual TypesetBook::Ptr complete () = 0;
144  };
145 
147  class BookPage : public MyGUI::Widget
148  {
149  MYGUI_RTTI_DERIVED(BookPage)
150  public:
151 
153  typedef std::function <void (InteractiveId)> ClickCallback;
154 
156  virtual void showPage (TypesetBook::Ptr Book, size_t Page) = 0;
157 
159  virtual void adviseLinkClicked (ClickCallback callback) = 0;
160 
162  virtual void unadviseLinkClicked () = 0;
163 
166  static void registerMyGUIComponents ();
167  };
168 }
169 
170 #endif // MWGUI_BOOKPAGE_HPP
virtual void showPage(TypesetBook::Ptr Book, size_t Page)=0
Make the widget display the specified page from the specified book.
float advance
Definition: bookpage.hpp:43
uint8_t const * Utf8Point
Definition: bookpage.hpp:83
static Ptr create(int pageWidth, int pageHeight)
A factory function for creating the default implementation of a book typesetter.
Definition: bookpage.cpp:639
Alignment
Definition: bookpage.hpp:89
static const Environment & get()
Return instance of this class.
Definition: environment.cpp:196
float height
Definition: bookpage.hpp:42
float width
Definition: bookpage.hpp:41
TypesetBook::InteractiveId InteractiveId
Definition: bookpage.hpp:152
virtual intptr_t addContent(Utf8Span Text, bool Select=true)=0
WindowManager * getWindowManager() const
Definition: environment.cpp:125
virtual Style * createStyle(const std::string &fontName, const Colour &colour, bool useBookFont=true)=0
Create a simple text style consisting of a font and a text color.
GlyphInfo(MyGUI::IFont *font, MyGUI::Char ch)
Definition: bookpage.hpp:48
virtual TypesetBook::Ptr complete()=0
Finalize the document layout, and return a pointer to it.
virtual Style * createHotStyle(Style *BaseStyle, const Colour &NormalColour, const Colour &HoverColour, const Colour &ActiveColour, InteractiveId Id, bool Unique=true)=0
Definition: bookpage.hpp:21
Definition: bookpage.hpp:92
std::shared_ptr< BookTypesetter > Ptr
Definition: bookpage.hpp:80
std::pair< Utf8Point, Utf8Point > Utf8Span
Definition: bookpage.hpp:84
virtual void setSectionAlignment(Alignment sectionAlignment)=0
Changes the alignment for the current section of text.
float bearingY
Definition: bookpage.hpp:45
static void registerMyGUIComponents()
Definition: bookpage.cpp:1332
virtual void unadviseLinkClicked()=0
Clear the hyper-link click callback.
virtual void selectContent(intptr_t contentHandle)=0
Select a previously created content block for future writes.
std::function< void(InteractiveId)> ClickCallback
Definition: bookpage.hpp:153
virtual void sectionBreak(int margin=0)=0
MyGUI::Colour Colour
Definition: bookpage.hpp:82
virtual size_t pageCount() const =0
Returns the number of pages in the document.
Definition: bookpage.hpp:91
virtual std::pair< unsigned int, unsigned int > getSize() const =0
intptr_t InteractiveId
Definition: bookpage.hpp:24
A factory class for creating a typeset book instance.
Definition: bookpage.hpp:78
std::shared_ptr< TypesetBook > Ptr
Definition: bookpage.hpp:23
Definition: bookpage.hpp:38
An interface to the BookPage widget.
Definition: bookpage.hpp:147
virtual void lineBreak(float margin=0)=0
char codePoint
Definition: bookpage.hpp:40
float bearingX
Definition: bookpage.hpp:44
MyGUI::FloatRect uvRect
Definition: bookpage.hpp:46
virtual void write(Style *Style, Utf8Span Text)=0
TypesetBook::InteractiveId InteractiveId
Definition: bookpage.hpp:81
virtual void adviseLinkClicked(ClickCallback callback)=0
Set the callback for a clicking a hyper-link in the document.
virtual int getFontHeight() const =0
Definition: bookpage.hpp:90