Allow alignment for images in books

deque
MiroslavR 10 years ago
parent 3287d0b6ef
commit a13039ad1f

@ -235,7 +235,8 @@ namespace MWGui
if (!plainText.empty() || brBeforeLastTag || isPrevImg)
{
TextElement elem(paper, pag, mTextStyle, plainText);
TextElement elem(paper, pag, mBlockStyle,
mTextStyle, plainText);
elem.paginate();
}
@ -260,7 +261,8 @@ namespace MWGui
int width = boost::lexical_cast<int>(attr.at("width"));
int height = boost::lexical_cast<int>(attr.at("height"));
ImageElement elem(paper, pag, src, width, height);
ImageElement elem(paper, pag, mBlockStyle,
src, width, height);
elem.paginate();
break;
}
@ -294,9 +296,7 @@ namespace MWGui
void BookFormatter::resetFontProperties()
{
MyGUI::Align align = mTextStyle.mTextAlign;
mTextStyle = TextStyle();
mTextStyle.mTextAlign = align;
}
void BookFormatter::handleDiv(const BookTextParser::Attributes & attr)
@ -307,9 +307,9 @@ namespace MWGui
std::string align = attr.at("align");
if (Misc::StringUtils::ciEqual(align, "center"))
mTextStyle.mTextAlign = MyGUI::Align::HCenter;
mBlockStyle.mAlign = MyGUI::Align::HCenter;
else if (Misc::StringUtils::ciEqual(align, "left"))
mTextStyle.mTextAlign = MyGUI::Align::Left;
mBlockStyle.mAlign = MyGUI::Align::Left;
}
void BookFormatter::handleFont(const BookTextParser::Attributes & attr)
@ -321,7 +321,7 @@ namespace MWGui
ss << attr.at("color");
ss >> std::hex >> color;
mTextStyle.mColour = MyGUI::Colour(
mTextStyle.mColor = MyGUI::Colour(
(color>>16 & 0xFF) / 255.f,
(color>>8 & 0xFF) / 255.f,
(color & 0xFF) / 255.f);
@ -340,8 +340,8 @@ namespace MWGui
}
/* GraphicElement */
GraphicElement::GraphicElement(MyGUI::Widget * parent, Paginator & pag)
: mParent(parent), mPaginator(pag)
GraphicElement::GraphicElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle)
: mParent(parent), mPaginator(pag), mBlockStyle(blockStyle)
{
}
@ -364,10 +364,10 @@ namespace MWGui
}
/* TextElement */
TextElement::TextElement(MyGUI::Widget * parent, Paginator & pag,
const TextStyle & style, const std::string & text)
: GraphicElement(parent, pag),
mStyle(style)
TextElement::TextElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle,
const TextStyle & textStyle, const std::string & text)
: GraphicElement(parent, pag, blockStyle),
mTextStyle(textStyle)
{
MyGUI::EditBox* box = parent->createWidget<MyGUI::EditBox>("NormalText",
MyGUI::IntCoord(0, pag.getCurrentTop(), pag.getPageWidth(), 0), MyGUI::Align::Left | MyGUI::Align::Top,
@ -377,9 +377,9 @@ namespace MWGui
box->setProperty("WordWrap", "true");
box->setProperty("NeedMouse", "false");
box->setMaxTextLength(text.size());
box->setTextAlign(mStyle.mTextAlign);
box->setTextColour(mStyle.mColour);
box->setFontName(mStyle.mFont);
box->setTextAlign(mBlockStyle.mAlign);
box->setTextColour(mTextStyle.mColor);
box->setFontName(mTextStyle.mFont);
box->setCaption(MyGUI::TextIterator::toTagsString(text));
box->setSize(box->getSize().width, box->getTextSize().height);
mEditBox = box;
@ -387,7 +387,7 @@ namespace MWGui
int TextElement::currentFontHeight() const
{
std::string fontName(mStyle.mFont == "Default" ? MyGUI::FontManager::getInstance().getDefaultFont() : mStyle.mFont);
std::string fontName(mTextStyle.mFont == "Default" ? MyGUI::FontManager::getInstance().getDefaultFont() : mTextStyle.mFont);
return MyGUI::FontManager::getInstance().getByName(fontName)->getDefaultHeight();
}
@ -419,13 +419,13 @@ namespace MWGui
}
/* ImageElement */
ImageElement::ImageElement(MyGUI::Widget * parent, Paginator & pag,
ImageElement::ImageElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle,
const std::string & src, int width, int height)
: GraphicElement(parent, pag),
: GraphicElement(parent, pag, blockStyle),
mImageHeight(height)
{
mImageBox = parent->createWidget<MyGUI::ImageBox> ("ImageBox",
MyGUI::IntCoord(0, pag.getCurrentTop(), width, mImageHeight), MyGUI::Align::Left | MyGUI::Align::Top,
MyGUI::IntCoord(0, pag.getCurrentTop(), width, mImageHeight), mBlockStyle.mAlign | MyGUI::Align::Top,
parent->getName() + boost::lexical_cast<std::string>(parent->getChildCount()));
std::string image = Misc::ResourceHelpers::correctBookartPath(src, width, mImageHeight);

@ -11,17 +11,25 @@ namespace MWGui
struct TextStyle
{
TextStyle() :
mColour(0,0,0)
mColor(0,0,0)
, mFont("Default")
, mTextSize(16)
, mTextAlign(MyGUI::Align::Left | MyGUI::Align::Top)
{
}
MyGUI::Colour mColour;
MyGUI::Colour mColor;
std::string mFont;
int mTextSize;
MyGUI::Align mTextAlign;
};
struct BlockStyle
{
BlockStyle() :
mAlign(MyGUI::Align::Left | MyGUI::Align::Top)
{
}
MyGUI::Align mAlign;
};
class BookTextParser
@ -112,12 +120,13 @@ namespace MWGui
void handleFont(const BookTextParser::Attributes & attr);
TextStyle mTextStyle;
BlockStyle mBlockStyle;
};
class GraphicElement
{
public:
GraphicElement(MyGUI::Widget * parent, Paginator & pag);
GraphicElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle);
virtual int getHeight() = 0;
virtual void paginate();
virtual int pageSplit();
@ -125,24 +134,27 @@ namespace MWGui
protected:
MyGUI::Widget * mParent;
Paginator & mPaginator;
BlockStyle mBlockStyle;
};
class TextElement : public GraphicElement
{
public:
TextElement(MyGUI::Widget * parent, Paginator & pag, const TextStyle & style, const std::string & text);
TextElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle,
const TextStyle & textStyle, const std::string & text);
virtual int getHeight();
virtual int pageSplit();
private:
int currentFontHeight() const;
TextStyle mStyle;
TextStyle mTextStyle;
MyGUI::EditBox * mEditBox;
};
class ImageElement : public GraphicElement
{
public:
ImageElement(MyGUI::Widget * parent, Paginator & pag, const std::string & src, int width, int height);
ImageElement(MyGUI::Widget * parent, Paginator & pag, const BlockStyle & blockStyle,
const std::string & src, int width, int height);
virtual int getHeight();
virtual int pageSplit();

Loading…
Cancel
Save