You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw/mwgui/formatting.hpp

117 lines
3.6 KiB
C++

#ifndef MWGUI_FORMATTING_H
#define MWGUI_FORMATTING_H
#include <MyGUI.h>
namespace MWGui
{
namespace Formatting
{
struct TextStyle
{
TextStyle() :
mColour(0,0,0)
, mFont("Default")
, mTextSize(16)
, mTextAlign(MyGUI::Align::Left | MyGUI::Align::Top)
{
}
MyGUI::Colour mColour;
std::string mFont;
int mTextSize;
MyGUI::Align mTextAlign;
};
class Paginator
{
public:
typedef std::pair<int, int> Page;
typedef std::vector<Page> Pages;
Paginator(int pageWidth, int pageHeight)
: mStartTop(0), mCurrentTop(0),
mPageWidth(pageWidth), mPageHeight(pageHeight)
{
}
int getStartTop() const { return mStartTop; }
int getCurrentTop() const { return mCurrentTop; }
int getPageWidth() const { return mPageWidth; }
int getPageHeight() const { return mPageHeight; }
Pages getPages() const { return mPages; }
void setStartTop(int top) { mStartTop = top; }
void setCurrentTop(int top) { mCurrentTop = top; }
void modifyStartTop(int mod) { mStartTop += mod; }
void modifyCurrentTop(int mod) { mCurrentTop += mod; }
Paginator & operator<<(const Page & page)
{
mPages.push_back(page);
return *this;
}
private:
int mStartTop, mCurrentTop;
int mPageWidth, mPageHeight;
Pages mPages;
};
/// \brief utilities for parsing book/scroll text as mygui widgets
class BookFormatter
{
public:
Paginator::Pages markupToWidget(MyGUI::Widget * parent, std::string utf8Text, const int pageWidth, const int pageHeight);
Paginator::Pages markupToWidget(MyGUI::Widget * parent, std::string utf8Text);
protected:
void parseDiv(std::string tag);
void parseFont(std::string tag);
private:
TextStyle mTextStyle;
};
class GraphicElement
{
public:
GraphicElement(MyGUI::Widget * parent, Paginator & pag, const TextStyle & style);
virtual int getHeight() = 0;
virtual void paginate();
virtual int pageSplit();
protected:
int currentFontHeight() const;
float widthForCharGlyph(MyGUI::Char unicodeChar) const;
MyGUI::Widget * mParent;
Paginator & mPaginator;
TextStyle mStyle;
};
class TextElement : public GraphicElement
{
public:
TextElement(MyGUI::Widget * parent, Paginator & pag, const TextStyle & style, const std::string & text);
virtual int getHeight();
virtual int pageSplit();
private:
MyGUI::EditBox * mEditBox;
};
class ImageElement : public GraphicElement
{
public:
ImageElement(MyGUI::Widget * parent, Paginator & pag, const TextStyle & style, const std::string & tag);
virtual int getHeight();
virtual int pageSplit();
private:
int mImageHeight;
MyGUI::ImageBox * mImageBox;
};
}
}
#endif