forked from teamnwah/openmw-tes3coop
Merge remote-tracking branch 'miroslavr/master'
This commit is contained in:
commit
56858c98b1
6 changed files with 516 additions and 436 deletions
|
@ -70,11 +70,6 @@ namespace MWGui
|
||||||
|
|
||||||
void BookWindow::clearPages()
|
void BookWindow::clearPages()
|
||||||
{
|
{
|
||||||
for (std::vector<MyGUI::Widget*>::iterator it=mPages.begin();
|
|
||||||
it!=mPages.end(); ++it)
|
|
||||||
{
|
|
||||||
MyGUI::Gui::getInstance().destroyWidget(*it);
|
|
||||||
}
|
|
||||||
mPages.clear();
|
mPages.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,25 +84,9 @@ namespace MWGui
|
||||||
|
|
||||||
MWWorld::LiveCellRef<ESM::Book> *ref = mBook.get<ESM::Book>();
|
MWWorld::LiveCellRef<ESM::Book> *ref = mBook.get<ESM::Book>();
|
||||||
|
|
||||||
BookTextParser parser;
|
Formatting::BookFormatter formatter;
|
||||||
std::vector<std::string> results = parser.split(ref->mBase->mText, mLeftPage->getSize().width, mLeftPage->getSize().height);
|
mPages = formatter.markupToWidget(mLeftPage, ref->mBase->mText);
|
||||||
|
formatter.markupToWidget(mRightPage, ref->mBase->mText);
|
||||||
int i=0;
|
|
||||||
for (std::vector<std::string>::iterator it=results.begin();
|
|
||||||
it!=results.end(); ++it)
|
|
||||||
{
|
|
||||||
MyGUI::Widget* parent;
|
|
||||||
if (i%2 == 0)
|
|
||||||
parent = mLeftPage;
|
|
||||||
else
|
|
||||||
parent = mRightPage;
|
|
||||||
|
|
||||||
MyGUI::Widget* pageWidget = parent->createWidgetReal<MyGUI::Widget>("", MyGUI::FloatCoord(0.0,0.0,1.0,1.0), MyGUI::Align::Default, "BookPage" + boost::lexical_cast<std::string>(i));
|
|
||||||
pageWidget->setNeedMouseFocus(false);
|
|
||||||
parser.parsePage(*it, pageWidget, mLeftPage->getSize().width);
|
|
||||||
mPages.push_back(pageWidget);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePages();
|
updatePages();
|
||||||
|
|
||||||
|
@ -164,19 +143,6 @@ namespace MWGui
|
||||||
mLeftPageNumber->setCaption( boost::lexical_cast<std::string>(mCurrentPage*2 + 1) );
|
mLeftPageNumber->setCaption( boost::lexical_cast<std::string>(mCurrentPage*2 + 1) );
|
||||||
mRightPageNumber->setCaption( boost::lexical_cast<std::string>(mCurrentPage*2 + 2) );
|
mRightPageNumber->setCaption( boost::lexical_cast<std::string>(mCurrentPage*2 + 2) );
|
||||||
|
|
||||||
unsigned int i=0;
|
|
||||||
for (std::vector<MyGUI::Widget*>::iterator it = mPages.begin();
|
|
||||||
it != mPages.end(); ++it)
|
|
||||||
{
|
|
||||||
if (mCurrentPage*2 == i || mCurrentPage*2+1 == i)
|
|
||||||
(*it)->setVisible(true);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
(*it)->setVisible(false);
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If it is the last page, hide the button "Next Page"
|
//If it is the last page, hide the button "Next Page"
|
||||||
if ( (mCurrentPage+1)*2 == mPages.size()
|
if ( (mCurrentPage+1)*2 == mPages.size()
|
||||||
|| (mCurrentPage+1)*2 == mPages.size() + 1)
|
|| (mCurrentPage+1)*2 == mPages.size() + 1)
|
||||||
|
@ -191,6 +157,27 @@ namespace MWGui
|
||||||
} else {
|
} else {
|
||||||
mPrevPageButton->setVisible(true);
|
mPrevPageButton->setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mPages.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
MyGUI::Widget * paper;
|
||||||
|
|
||||||
|
paper = mLeftPage->getChildAt(0);
|
||||||
|
paper->setCoord(paper->getPosition().left, -mPages[mCurrentPage*2].first,
|
||||||
|
paper->getWidth(), mPages[mCurrentPage*2].second);
|
||||||
|
|
||||||
|
paper = mRightPage->getChildAt(0);
|
||||||
|
if ((mCurrentPage+1)*2 <= mPages.size())
|
||||||
|
{
|
||||||
|
paper->setCoord(paper->getPosition().left, -mPages[mCurrentPage*2+1].first,
|
||||||
|
paper->getWidth(), mPages[mCurrentPage*2+1].second);
|
||||||
|
paper->setVisible(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
paper->setVisible(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookWindow::adjustButton (Gui::ImageButton* button)
|
void BookWindow::adjustButton (Gui::ImageButton* button)
|
||||||
|
|
|
@ -34,17 +34,21 @@ namespace MWGui
|
||||||
void adjustButton(Gui::ImageButton* button);
|
void adjustButton(Gui::ImageButton* button);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef std::pair<int, int> Page;
|
||||||
|
typedef std::vector<Page> Pages;
|
||||||
|
|
||||||
Gui::ImageButton* mCloseButton;
|
Gui::ImageButton* mCloseButton;
|
||||||
Gui::ImageButton* mTakeButton;
|
Gui::ImageButton* mTakeButton;
|
||||||
Gui::ImageButton* mNextPageButton;
|
Gui::ImageButton* mNextPageButton;
|
||||||
Gui::ImageButton* mPrevPageButton;
|
Gui::ImageButton* mPrevPageButton;
|
||||||
|
|
||||||
MyGUI::TextBox* mLeftPageNumber;
|
MyGUI::TextBox* mLeftPageNumber;
|
||||||
MyGUI::TextBox* mRightPageNumber;
|
MyGUI::TextBox* mRightPageNumber;
|
||||||
MyGUI::Widget* mLeftPage;
|
MyGUI::Widget* mLeftPage;
|
||||||
MyGUI::Widget* mRightPage;
|
MyGUI::Widget* mRightPage;
|
||||||
|
|
||||||
unsigned int mCurrentPage; // 0 is first page
|
unsigned int mCurrentPage; // 0 is first page
|
||||||
std::vector<MyGUI::Widget*> mPages;
|
Pages mPages;
|
||||||
|
|
||||||
MWWorld::Ptr mBook;
|
MWWorld::Ptr mBook;
|
||||||
|
|
||||||
|
|
|
@ -2,401 +2,405 @@
|
||||||
|
|
||||||
#include <components/interpreter/defines.hpp>
|
#include <components/interpreter/defines.hpp>
|
||||||
#include <components/misc/resourcehelpers.hpp>
|
#include <components/misc/resourcehelpers.hpp>
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
#include "../mwscript/interpretercontext.hpp"
|
#include "../mwscript/interpretercontext.hpp"
|
||||||
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/range/adaptor/filtered.hpp>
|
|
||||||
#include <boost/range/algorithm/copy.hpp>
|
|
||||||
#include <OgreUTFString.h>
|
|
||||||
|
|
||||||
|
#include <OgreUTFString.h>
|
||||||
#include <OgreResourceGroupManager.h>
|
#include <OgreResourceGroupManager.h>
|
||||||
|
|
||||||
namespace
|
#include <MyGUI_EditText.h>
|
||||||
{
|
|
||||||
int convertFromHex(std::string hex)
|
|
||||||
{
|
|
||||||
int value = 0;
|
|
||||||
|
|
||||||
int a = 0;
|
|
||||||
int b = hex.length() - 1;
|
|
||||||
for (; b >= 0; a++, b--)
|
|
||||||
{
|
|
||||||
if (hex[b] >= '0' && hex[b] <= '9')
|
|
||||||
{
|
|
||||||
value += (hex[b] - '0') * (1 << (a * 4));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (hex[b])
|
|
||||||
{
|
|
||||||
case 'A':
|
|
||||||
case 'a':
|
|
||||||
value += 10 * (1 << (a * 4));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'B':
|
|
||||||
case 'b':
|
|
||||||
value += 11 * (1 << (a * 4));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'C':
|
|
||||||
case 'c':
|
|
||||||
value += 12 * (1 << (a * 4));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'D':
|
|
||||||
case 'd':
|
|
||||||
value += 13 * (1 << (a * 4));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'E':
|
|
||||||
case 'e':
|
|
||||||
value += 14 * (1 << (a * 4));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'F':
|
|
||||||
case 'f':
|
|
||||||
value += 15 * (1 << (a * 4));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw std::runtime_error("invalid character in hex number");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ogre::UTFString::unicode_char unicodeCharFromChar(char ch)
|
|
||||||
{
|
|
||||||
std::string s;
|
|
||||||
s += ch;
|
|
||||||
Ogre::UTFString string(s);
|
|
||||||
return string.getChar(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_not_empty(const std::string& s) {
|
|
||||||
std::string temp = s;
|
|
||||||
boost::algorithm::trim(temp);
|
|
||||||
return !temp.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
namespace Formatting
|
||||||
std::vector<std::string> BookTextParser::split(std::string utf8Text, const int width, const int height)
|
{
|
||||||
|
/* BookTextParser */
|
||||||
|
BookTextParser::BookTextParser(const std::string & text)
|
||||||
|
: mIndex(0), mText(text), mIgnoreNewlineTags(true), mIgnoreLineEndings(true)
|
||||||
{
|
{
|
||||||
using Ogre::UTFString;
|
|
||||||
std::vector<std::string> result;
|
|
||||||
|
|
||||||
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
|
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
|
||||||
utf8Text = Interpreter::fixDefinesBook(utf8Text, interpreterContext);
|
mText = Interpreter::fixDefinesBook(mText, interpreterContext);
|
||||||
|
|
||||||
boost::algorithm::replace_all(utf8Text, "\n", "");
|
boost::algorithm::replace_all(mText, "\r", "");
|
||||||
boost::algorithm::replace_all(utf8Text, "\r", "");
|
|
||||||
boost::algorithm::replace_all(utf8Text, "<BR>", "\n");
|
|
||||||
boost::algorithm::replace_all(utf8Text, "<P>", "\n\n");
|
|
||||||
|
|
||||||
UTFString text(utf8Text);
|
registerTag("br", Event_BrTag);
|
||||||
const int spacing = 48;
|
registerTag("p", Event_PTag);
|
||||||
|
registerTag("img", Event_ImgTag);
|
||||||
const UTFString::unicode_char LEFT_ANGLE = unicodeCharFromChar('<');
|
registerTag("div", Event_DivTag);
|
||||||
const UTFString::unicode_char NEWLINE = unicodeCharFromChar('\n');
|
registerTag("font", Event_FontTag);
|
||||||
const UTFString::unicode_char SPACE = unicodeCharFromChar(' ');
|
|
||||||
|
|
||||||
while (!text.empty())
|
|
||||||
{
|
|
||||||
// read in characters until we have exceeded the size, or run out of text
|
|
||||||
int currentWidth = 0;
|
|
||||||
int currentHeight = 0;
|
|
||||||
|
|
||||||
size_t currentWordStart = 0;
|
|
||||||
size_t index = 0;
|
|
||||||
|
|
||||||
{
|
|
||||||
std::string texToTrim = text.asUTF8();
|
|
||||||
boost::algorithm::trim( texToTrim );
|
|
||||||
text = UTFString(texToTrim);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookTextParser::registerTag(const std::string & tag, BookTextParser::Events type)
|
||||||
|
{
|
||||||
|
mTagTypes[tag] = type;
|
||||||
|
}
|
||||||
|
|
||||||
while (currentHeight <= height - spacing && index < text.size())
|
std::string BookTextParser::getReadyText()
|
||||||
{
|
{
|
||||||
const UTFString::unicode_char ch = text.getChar(index);
|
return mReadyText;
|
||||||
if (ch == LEFT_ANGLE)
|
}
|
||||||
|
|
||||||
|
BookTextParser::Events BookTextParser::next()
|
||||||
{
|
{
|
||||||
const size_t tagStart = index + 1;
|
while (mIndex < mText.size())
|
||||||
const size_t tagEnd = text.find('>', tagStart);
|
{
|
||||||
if (tagEnd == UTFString::npos)
|
char ch = mText[mIndex];
|
||||||
|
if (ch == '<')
|
||||||
|
{
|
||||||
|
const size_t tagStart = mIndex + 1;
|
||||||
|
const size_t tagEnd = mText.find('>', tagStart);
|
||||||
|
if (tagEnd == std::string::npos)
|
||||||
throw std::runtime_error("BookTextParser Error: Tag is not terminated");
|
throw std::runtime_error("BookTextParser Error: Tag is not terminated");
|
||||||
const std::string tag = text.substr(tagStart, tagEnd - tagStart).asUTF8();
|
parseTag(mText.substr(tagStart, tagEnd - tagStart));
|
||||||
|
mIndex = tagEnd;
|
||||||
|
|
||||||
if (boost::algorithm::starts_with(tag, "IMG"))
|
if (mTagTypes.find(mTag) != mTagTypes.end())
|
||||||
{
|
{
|
||||||
const int h = mHeight;
|
Events type = mTagTypes.at(mTag);
|
||||||
parseImage(tag, false);
|
|
||||||
currentHeight += (mHeight - h);
|
if (type == Event_BrTag || type == Event_PTag)
|
||||||
currentWidth = 0;
|
|
||||||
}
|
|
||||||
else if (boost::algorithm::starts_with(tag, "FONT"))
|
|
||||||
{
|
{
|
||||||
parseFont(tag);
|
if (!mIgnoreNewlineTags)
|
||||||
if (currentWidth != 0) {
|
|
||||||
currentHeight += currentFontHeight();
|
|
||||||
}
|
|
||||||
currentWidth = 0;
|
|
||||||
}
|
|
||||||
else if (boost::algorithm::starts_with(tag, "DIV"))
|
|
||||||
{
|
{
|
||||||
parseDiv(tag);
|
if (type == Event_BrTag)
|
||||||
if (currentWidth != 0) {
|
mBuffer.push_back('\n');
|
||||||
currentHeight += currentFontHeight();
|
else
|
||||||
currentWidth = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index = tagEnd;
|
|
||||||
}
|
|
||||||
else if (ch == NEWLINE)
|
|
||||||
{
|
{
|
||||||
currentHeight += currentFontHeight();
|
mBuffer.append("\n\n");
|
||||||
currentWidth = 0;
|
|
||||||
currentWordStart = index;
|
|
||||||
}
|
}
|
||||||
else if (ch == SPACE)
|
}
|
||||||
|
mIgnoreLineEndings = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
flushBuffer();
|
||||||
|
|
||||||
|
if (type == Event_ImgTag)
|
||||||
{
|
{
|
||||||
currentWidth += 3; // keep this in sync with the font's SpaceWidth property
|
mIgnoreLineEndings = false;
|
||||||
currentWordStart = index;
|
mIgnoreNewlineTags = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
++mIndex;
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currentWidth += widthForCharGlyph(ch);
|
if (!mIgnoreLineEndings || ch != '\n')
|
||||||
}
|
|
||||||
|
|
||||||
if (currentWidth > width)
|
|
||||||
{
|
{
|
||||||
currentHeight += currentFontHeight();
|
mBuffer.push_back(ch);
|
||||||
currentWidth = 0;
|
mIgnoreLineEndings = false;
|
||||||
// add size of the current word
|
mIgnoreNewlineTags = false;
|
||||||
UTFString word = text.substr(currentWordStart, index - currentWordStart);
|
|
||||||
for (UTFString::const_iterator it = word.begin(), end = word.end(); it != end; ++it)
|
|
||||||
currentWidth += widthForCharGlyph(it.getCharacter());
|
|
||||||
}
|
}
|
||||||
index += UTFString::_utf16_char_length(ch);
|
|
||||||
}
|
|
||||||
const size_t pageEnd = (currentHeight > height - spacing && currentWordStart != 0)
|
|
||||||
? currentWordStart : index;
|
|
||||||
|
|
||||||
result.push_back(text.substr(0, pageEnd).asUTF8());
|
|
||||||
text.erase(0, pageEnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> nonEmptyPages;
|
++mIndex;
|
||||||
boost::copy(result | boost::adaptors::filtered(is_not_empty), std::back_inserter(nonEmptyPages));
|
|
||||||
return nonEmptyPages;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float BookTextParser::widthForCharGlyph(unsigned unicodeChar) const
|
flushBuffer();
|
||||||
|
return Event_EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookTextParser::flushBuffer()
|
||||||
{
|
{
|
||||||
std::string fontName(mTextStyle.mFont == "Default" ? MyGUI::FontManager::getInstance().getDefaultFont() : mTextStyle.mFont);
|
mReadyText = mBuffer;
|
||||||
return MyGUI::FontManager::getInstance().getByName(fontName)
|
mBuffer.clear();
|
||||||
->getGlyphInfo(unicodeChar)->width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float BookTextParser::currentFontHeight() const
|
const BookTextParser::Attributes & BookTextParser::getAttributes() const
|
||||||
{
|
{
|
||||||
std::string fontName(mTextStyle.mFont == "Default" ? MyGUI::FontManager::getInstance().getDefaultFont() : mTextStyle.mFont);
|
return mAttributes;
|
||||||
return MyGUI::FontManager::getInstance().getByName(fontName)->getDefaultHeight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::IntSize BookTextParser::parsePage(std::string text, MyGUI::Widget* parent, const int width)
|
void BookTextParser::parseTag(std::string tag)
|
||||||
{
|
{
|
||||||
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
|
size_t tagNameEndPos = tag.find(' ');
|
||||||
text = Interpreter::fixDefinesBook(text, interpreterContext);
|
mTag = tag.substr(0, tagNameEndPos);
|
||||||
|
Misc::StringUtils::toLower(mTag);
|
||||||
|
mAttributes.clear();
|
||||||
|
if (tagNameEndPos == std::string::npos)
|
||||||
|
return;
|
||||||
|
tag.erase(0, tagNameEndPos+1);
|
||||||
|
|
||||||
mParent = parent;
|
while (!tag.empty())
|
||||||
mWidth = width;
|
|
||||||
mHeight = 0;
|
|
||||||
|
|
||||||
assert(mParent);
|
|
||||||
while (mParent->getChildCount())
|
|
||||||
{
|
{
|
||||||
MyGUI::Gui::getInstance().destroyWidget(mParent->getChildAt(0));
|
size_t sepPos = tag.find('=');
|
||||||
}
|
if (sepPos == std::string::npos)
|
||||||
|
|
||||||
// remove trailing "
|
|
||||||
if (text[text.size()-1] == '\"')
|
|
||||||
text.erase(text.size()-1);
|
|
||||||
|
|
||||||
parseSubText(text);
|
|
||||||
return MyGUI::IntSize(mWidth, mHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
MyGUI::IntSize BookTextParser::parseScroll(std::string text, MyGUI::Widget* parent, const int width)
|
|
||||||
{
|
|
||||||
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
|
|
||||||
text = Interpreter::fixDefinesBook(text, interpreterContext);
|
|
||||||
|
|
||||||
mParent = parent;
|
|
||||||
mWidth = width;
|
|
||||||
mHeight = 0;
|
|
||||||
|
|
||||||
assert(mParent);
|
|
||||||
while (mParent->getChildCount())
|
|
||||||
{
|
|
||||||
MyGUI::Gui::getInstance().destroyWidget(mParent->getChildAt(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::algorithm::replace_all(text, "<BR>", "\n");
|
|
||||||
boost::algorithm::replace_all(text, "<P>", "\n\n");
|
|
||||||
boost::algorithm::trim_left(text);
|
|
||||||
|
|
||||||
// remove trailing "
|
|
||||||
if (text[text.size()-1] == '\"')
|
|
||||||
text.erase(text.size()-1);
|
|
||||||
|
|
||||||
parseSubText(text);
|
|
||||||
return MyGUI::IntSize(mWidth, mHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void BookTextParser::parseImage(std::string tag, bool createWidget)
|
|
||||||
{
|
|
||||||
int src_start = tag.find("SRC=")+5;
|
|
||||||
|
|
||||||
int width_start = tag.find("WIDTH=")+7;
|
|
||||||
int width = boost::lexical_cast<int>(tag.substr(width_start, tag.find('"', width_start)-width_start));
|
|
||||||
|
|
||||||
int height_start = tag.find("HEIGHT=")+8;
|
|
||||||
int height = boost::lexical_cast<int>(tag.substr(height_start, tag.find('"', height_start)-height_start));
|
|
||||||
|
|
||||||
if (createWidget)
|
|
||||||
{
|
|
||||||
MyGUI::ImageBox* box = mParent->createWidget<MyGUI::ImageBox> ("ImageBox",
|
|
||||||
MyGUI::IntCoord(0, mHeight, width, height), MyGUI::Align::Left | MyGUI::Align::Top,
|
|
||||||
mParent->getName() + boost::lexical_cast<std::string>(mParent->getChildCount()));
|
|
||||||
|
|
||||||
std::string image = Misc::ResourceHelpers::correctBookartPath(tag.substr(src_start, tag.find('"', src_start)-src_start), width, height);
|
|
||||||
box->setImageTexture(image);
|
|
||||||
box->setProperty("NeedMouse", "false");
|
|
||||||
}
|
|
||||||
|
|
||||||
mWidth = std::max(mWidth, width);
|
|
||||||
mHeight += height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BookTextParser::parseDiv(std::string tag)
|
|
||||||
{
|
|
||||||
if (tag.find("ALIGN=") == std::string::npos)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int align_start = tag.find("ALIGN=")+7;
|
std::string key = tag.substr(0, sepPos);
|
||||||
std::string align = tag.substr(align_start, tag.find('"', align_start)-align_start);
|
Misc::StringUtils::toLower(key);
|
||||||
if (align == "CENTER")
|
tag.erase(0, sepPos+1);
|
||||||
|
|
||||||
|
std::string value;
|
||||||
|
|
||||||
|
if (tag.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (tag[0] == '"')
|
||||||
|
{
|
||||||
|
size_t quoteEndPos = tag.find('"', 1);
|
||||||
|
if (quoteEndPos == std::string::npos)
|
||||||
|
throw std::runtime_error("BookTextParser Error: Missing end quote in tag");
|
||||||
|
value = tag.substr(1, quoteEndPos-1);
|
||||||
|
tag.erase(0, quoteEndPos+2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t valEndPos = tag.find(' ');
|
||||||
|
if (valEndPos == std::string::npos)
|
||||||
|
{
|
||||||
|
value = tag;
|
||||||
|
tag.erase();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = tag.substr(0, valEndPos);
|
||||||
|
tag.erase(0, valEndPos+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mAttributes[key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BookFormatter */
|
||||||
|
Paginator::Pages BookFormatter::markupToWidget(MyGUI::Widget * parent, const std::string & markup, const int pageWidth, const int pageHeight)
|
||||||
|
{
|
||||||
|
Paginator pag(pageWidth, pageHeight);
|
||||||
|
|
||||||
|
while (parent->getChildCount())
|
||||||
|
{
|
||||||
|
MyGUI::Gui::getInstance().destroyWidget(parent->getChildAt(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
MyGUI::Widget * paper = parent->createWidget<MyGUI::Widget>("Widget", MyGUI::IntCoord(0, 0, pag.getPageWidth(), pag.getPageHeight()), MyGUI::Align::Left | MyGUI::Align::Top);
|
||||||
|
paper->setNeedMouseFocus(false);
|
||||||
|
|
||||||
|
BookTextParser parser(markup);
|
||||||
|
BookTextParser::Events event;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
event = parser.next();
|
||||||
|
if (event == BookTextParser::Event_BrTag || event == BookTextParser::Event_PTag)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string plainText = parser.getReadyText();
|
||||||
|
if (!plainText.empty())
|
||||||
|
{
|
||||||
|
// if there's a newline at the end of the box caption, remove it
|
||||||
|
if (plainText[plainText.size()-1] == '\n')
|
||||||
|
plainText.erase(plainText.end()-1);
|
||||||
|
|
||||||
|
#if (MYGUI_VERSION < MYGUI_DEFINE_VERSION(3, 2, 2))
|
||||||
|
// splitting won't be fully functional until 3.2.2 (see TextElement::pageSplit())
|
||||||
|
// hack: prevent newlines at the end of the book possibly creating unnecessary pages
|
||||||
|
if (event == BookTextParser::Event_EOF)
|
||||||
|
{
|
||||||
|
while (plainText.size() && plainText[plainText.size()-1] == '\n')
|
||||||
|
plainText.erase(plainText.end()-1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TextElement elem(paper, pag, mTextStyle, plainText);
|
||||||
|
elem.paginate();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event == BookTextParser::Event_EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (event)
|
||||||
|
{
|
||||||
|
case BookTextParser::Event_ImgTag:
|
||||||
|
{
|
||||||
|
const BookTextParser::Attributes & attr = parser.getAttributes();
|
||||||
|
|
||||||
|
if (attr.find("src") == attr.end() || attr.find("width") == attr.end() || attr.find("height") == attr.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string src = attr.at("src");
|
||||||
|
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);
|
||||||
|
elem.paginate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BookTextParser::Event_FontTag:
|
||||||
|
handleFont(parser.getAttributes());
|
||||||
|
break;
|
||||||
|
case BookTextParser::Event_DivTag:
|
||||||
|
handleDiv(parser.getAttributes());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// insert last page
|
||||||
|
if (pag.getStartTop() != pag.getCurrentTop())
|
||||||
|
pag << Paginator::Page(pag.getStartTop(), pag.getStartTop() + pag.getPageHeight());
|
||||||
|
|
||||||
|
paper->setSize(paper->getWidth(), pag.getCurrentTop());
|
||||||
|
|
||||||
|
return pag.getPages();
|
||||||
|
}
|
||||||
|
|
||||||
|
Paginator::Pages BookFormatter::markupToWidget(MyGUI::Widget * parent, const std::string & markup)
|
||||||
|
{
|
||||||
|
return markupToWidget(parent, markup, parent->getWidth(), parent->getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookFormatter::handleDiv(const BookTextParser::Attributes & attr)
|
||||||
|
{
|
||||||
|
if (attr.find("align") == attr.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string align = attr.at("align");
|
||||||
|
|
||||||
|
if (Misc::StringUtils::ciEqual(align, "center"))
|
||||||
mTextStyle.mTextAlign = MyGUI::Align::HCenter;
|
mTextStyle.mTextAlign = MyGUI::Align::HCenter;
|
||||||
else if (align == "LEFT")
|
else if (Misc::StringUtils::ciEqual(align, "left"))
|
||||||
mTextStyle.mTextAlign = MyGUI::Align::Left;
|
mTextStyle.mTextAlign = MyGUI::Align::Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookTextParser::parseFont(std::string tag)
|
void BookFormatter::handleFont(const BookTextParser::Attributes & attr)
|
||||||
{
|
{
|
||||||
if (tag.find("COLOR=") != std::string::npos)
|
if (attr.find("color") != attr.end())
|
||||||
{
|
{
|
||||||
int color_start = tag.find("COLOR=")+7;
|
int color;
|
||||||
std::string color = tag.substr(color_start, tag.find('"', color_start)-color_start);
|
std::stringstream ss;
|
||||||
|
ss << attr.at("color");
|
||||||
|
ss >> std::hex >> color;
|
||||||
|
|
||||||
mTextStyle.mColour = MyGUI::Colour(
|
mTextStyle.mColour = MyGUI::Colour(
|
||||||
convertFromHex(color.substr(0, 2))/255.0,
|
(color>>16 & 0xFF) / 255.f,
|
||||||
convertFromHex(color.substr(2, 2))/255.0,
|
(color>>8 & 0xFF) / 255.f,
|
||||||
convertFromHex(color.substr(4, 2))/255.0);
|
(color & 0xFF) / 255.f);
|
||||||
}
|
}
|
||||||
if (tag.find("FACE=") != std::string::npos)
|
if (attr.find("face") != attr.end())
|
||||||
{
|
{
|
||||||
int face_start = tag.find("FACE=")+6;
|
std::string face = attr.at("face");
|
||||||
std::string face = tag.substr(face_start, tag.find('"', face_start)-face_start);
|
|
||||||
|
|
||||||
if (face != "Magic Cards")
|
if (face != "Magic Cards")
|
||||||
mTextStyle.mFont = face;
|
mTextStyle.mFont = face;
|
||||||
}
|
}
|
||||||
if (tag.find("SIZE=") != std::string::npos)
|
if (attr.find("size") != attr.end())
|
||||||
{
|
{
|
||||||
/// \todo
|
/// \todo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookTextParser::parseSubText(std::string text)
|
/* GraphicElement */
|
||||||
|
GraphicElement::GraphicElement(MyGUI::Widget * parent, Paginator & pag)
|
||||||
|
: mParent(parent), mPaginator(pag)
|
||||||
{
|
{
|
||||||
if (text[0] == '<')
|
|
||||||
{
|
|
||||||
const size_t tagStart = 1;
|
|
||||||
const size_t tagEnd = text.find('>', tagStart);
|
|
||||||
if (tagEnd == std::string::npos)
|
|
||||||
throw std::runtime_error("BookTextParser Error: Tag is not terminated");
|
|
||||||
const std::string tag = text.substr(tagStart, tagEnd - tagStart);
|
|
||||||
|
|
||||||
if (boost::algorithm::starts_with(tag, "IMG"))
|
|
||||||
parseImage(tag);
|
|
||||||
if (boost::algorithm::starts_with(tag, "FONT"))
|
|
||||||
parseFont(tag);
|
|
||||||
if (boost::algorithm::starts_with(tag, "DIV"))
|
|
||||||
parseDiv(tag);
|
|
||||||
|
|
||||||
text.erase(0, tagEnd + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t tagStart = std::string::npos;
|
void GraphicElement::paginate()
|
||||||
std::string realText; // real text, without tags
|
|
||||||
for (size_t i = 0; i<text.size(); ++i)
|
|
||||||
{
|
{
|
||||||
char c = text[i];
|
int newTop = mPaginator.getCurrentTop() + getHeight();
|
||||||
if (c == '<')
|
while (newTop-mPaginator.getStartTop() > mPaginator.getPageHeight())
|
||||||
{
|
{
|
||||||
if ((i + 1 < text.size()) && text[i+1] == '/') // ignore closing tags
|
int newStartTop = pageSplit();
|
||||||
{
|
mPaginator << Paginator::Page(mPaginator.getStartTop(), newStartTop);
|
||||||
while (c != '>')
|
mPaginator.setStartTop(newStartTop);
|
||||||
{
|
|
||||||
if (i >= text.size())
|
|
||||||
throw std::runtime_error("BookTextParser Error: Tag is not terminated");
|
|
||||||
++i;
|
|
||||||
c = text[i];
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tagStart = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
realText += c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::EditBox* box = mParent->createWidget<MyGUI::EditBox>("NormalText",
|
mPaginator.setCurrentTop(newTop);
|
||||||
MyGUI::IntCoord(0, mHeight, mWidth, 24), MyGUI::Align::Left | MyGUI::Align::Top,
|
}
|
||||||
mParent->getName() + boost::lexical_cast<std::string>(mParent->getChildCount()));
|
|
||||||
|
int GraphicElement::pageSplit()
|
||||||
|
{
|
||||||
|
return mPaginator.getStartTop() + mPaginator.getPageHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TextElement */
|
||||||
|
TextElement::TextElement(MyGUI::Widget * parent, Paginator & pag,
|
||||||
|
const TextStyle & style, const std::string & text)
|
||||||
|
: GraphicElement(parent, pag),
|
||||||
|
mStyle(style)
|
||||||
|
{
|
||||||
|
MyGUI::EditBox* box = parent->createWidget<MyGUI::EditBox>("NormalText",
|
||||||
|
MyGUI::IntCoord(0, pag.getCurrentTop(), pag.getPageWidth(), 0), MyGUI::Align::Left | MyGUI::Align::Top,
|
||||||
|
parent->getName() + boost::lexical_cast<std::string>(parent->getChildCount()));
|
||||||
box->setProperty("Static", "true");
|
box->setProperty("Static", "true");
|
||||||
box->setProperty("MultiLine", "true");
|
box->setProperty("MultiLine", "true");
|
||||||
box->setProperty("WordWrap", "true");
|
box->setProperty("WordWrap", "true");
|
||||||
box->setProperty("NeedMouse", "false");
|
box->setProperty("NeedMouse", "false");
|
||||||
box->setMaxTextLength(realText.size());
|
box->setMaxTextLength(text.size());
|
||||||
box->setTextAlign(mTextStyle.mTextAlign);
|
box->setTextAlign(mStyle.mTextAlign);
|
||||||
box->setTextColour(mTextStyle.mColour);
|
box->setTextColour(mStyle.mColour);
|
||||||
box->setFontName(mTextStyle.mFont);
|
box->setFontName(mStyle.mFont);
|
||||||
box->setCaption(MyGUI::TextIterator::toTagsString(realText));
|
box->setCaption(MyGUI::TextIterator::toTagsString(text));
|
||||||
box->setSize(box->getSize().width, box->getTextSize().height);
|
box->setSize(box->getSize().width, box->getTextSize().height);
|
||||||
mHeight += box->getTextSize().height;
|
mEditBox = box;
|
||||||
|
}
|
||||||
|
|
||||||
if (tagStart != std::string::npos)
|
int TextElement::currentFontHeight() const
|
||||||
{
|
{
|
||||||
parseSubText(text.substr(tagStart, text.size()));
|
std::string fontName(mStyle.mFont == "Default" ? MyGUI::FontManager::getInstance().getDefaultFont() : mStyle.mFont);
|
||||||
}
|
return MyGUI::FontManager::getInstance().getByName(fontName)->getDefaultHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TextElement::getHeight()
|
||||||
|
{
|
||||||
|
return mEditBox->getTextSize().height;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TextElement::pageSplit()
|
||||||
|
{
|
||||||
|
// split lines
|
||||||
|
const int lineHeight = currentFontHeight();
|
||||||
|
unsigned int lastLine = (mPaginator.getStartTop() + mPaginator.getPageHeight() - mPaginator.getCurrentTop()) / lineHeight;
|
||||||
|
int ret = mPaginator.getCurrentTop() + lastLine * lineHeight;
|
||||||
|
|
||||||
|
// first empty lines that would go to the next page should be ignored
|
||||||
|
// unfortunately, getLineInfo method won't be available until 3.2.2
|
||||||
|
#if (MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3, 2, 2))
|
||||||
|
const MyGUI::VectorLineInfo & lines = mEditBox->getSubWidgetText()->castType<MyGUI::EditText>()->getLineInfo();
|
||||||
|
for (unsigned int i = lastLine; i < lines.size(); ++i)
|
||||||
|
{
|
||||||
|
if (lines[i].width == 0)
|
||||||
|
ret += lineHeight;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ImageElement */
|
||||||
|
ImageElement::ImageElement(MyGUI::Widget * parent, Paginator & pag,
|
||||||
|
const std::string & src, int width, int height)
|
||||||
|
: GraphicElement(parent, pag),
|
||||||
|
mImageHeight(height)
|
||||||
|
{
|
||||||
|
mImageBox = parent->createWidget<MyGUI::ImageBox> ("ImageBox",
|
||||||
|
MyGUI::IntCoord(0, pag.getCurrentTop(), width, mImageHeight), MyGUI::Align::Left | MyGUI::Align::Top,
|
||||||
|
parent->getName() + boost::lexical_cast<std::string>(parent->getChildCount()));
|
||||||
|
|
||||||
|
std::string image = Misc::ResourceHelpers::correctBookartPath(src, width, mImageHeight);
|
||||||
|
mImageBox->setImageTexture(image);
|
||||||
|
mImageBox->setProperty("NeedMouse", "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
int ImageElement::getHeight()
|
||||||
|
{
|
||||||
|
return mImageHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ImageElement::pageSplit()
|
||||||
|
{
|
||||||
|
// if the image is larger than the page, fall back to the default pageSplit implementation
|
||||||
|
if (mImageHeight > mPaginator.getPageHeight())
|
||||||
|
return GraphicElement::pageSplit();
|
||||||
|
return mPaginator.getCurrentTop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
#define MWGUI_FORMATTING_H
|
#define MWGUI_FORMATTING_H
|
||||||
|
|
||||||
#include <MyGUI.h>
|
#include <MyGUI.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
namespace Formatting
|
||||||
|
{
|
||||||
struct TextStyle
|
struct TextStyle
|
||||||
{
|
{
|
||||||
TextStyle() :
|
TextStyle() :
|
||||||
|
@ -21,47 +24,128 @@ namespace MWGui
|
||||||
MyGUI::Align mTextAlign;
|
MyGUI::Align mTextAlign;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief utilities for parsing book/scroll text as mygui widgets
|
|
||||||
class BookTextParser
|
class BookTextParser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
typedef std::map<std::string, std::string> Attributes;
|
||||||
* Parse markup as MyGUI widgets
|
enum Events
|
||||||
* @param markup to parse
|
{
|
||||||
* @param parent for the created widgets
|
Event_None = -2,
|
||||||
* @param maximum width
|
Event_EOF = -1,
|
||||||
* @return size of the created widgets
|
Event_BrTag,
|
||||||
*/
|
Event_PTag,
|
||||||
MyGUI::IntSize parsePage(std::string text, MyGUI::Widget* parent, const int width);
|
Event_ImgTag,
|
||||||
|
Event_DivTag,
|
||||||
|
Event_FontTag
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
BookTextParser(const std::string & text);
|
||||||
* Parse markup as MyGUI widgets
|
void registerTag(const std::string & tag, Events type);
|
||||||
* @param markup to parse
|
std::string getReadyText();
|
||||||
* @param parent for the created widgets
|
|
||||||
* @param maximum width
|
|
||||||
* @return size of the created widgets
|
|
||||||
*/
|
|
||||||
MyGUI::IntSize parseScroll(std::string text, MyGUI::Widget* parent, const int width);
|
|
||||||
|
|
||||||
/**
|
Events next();
|
||||||
* Split the specified text into pieces that fit in the area specified by width and height parameters
|
void flushBuffer();
|
||||||
*/
|
const Attributes & getAttributes() const;
|
||||||
std::vector<std::string> split(std::string text, const int width, const int height);
|
void parseTag(std::string tag);
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t mIndex;
|
||||||
|
std::string mText;
|
||||||
|
std::string mReadyText;
|
||||||
|
|
||||||
|
bool mIgnoreNewlineTags;
|
||||||
|
bool mIgnoreLineEndings;
|
||||||
|
Attributes mAttributes;
|
||||||
|
std::string mTag;
|
||||||
|
std::map<std::string, Events> mTagTypes;
|
||||||
|
std::string mBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
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; }
|
||||||
|
|
||||||
|
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, const std::string & markup, const int pageWidth, const int pageHeight);
|
||||||
|
Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float widthForCharGlyph(unsigned unicodeChar) const;
|
void handleImg(const BookTextParser::Attributes & attr);
|
||||||
float currentFontHeight() const;
|
void handleDiv(const BookTextParser::Attributes & attr);
|
||||||
void parseSubText(std::string text);
|
void handleFont(const BookTextParser::Attributes & attr);
|
||||||
|
|
||||||
void parseImage(std::string tag, bool createWidget=true);
|
|
||||||
void parseDiv(std::string tag);
|
|
||||||
void parseFont(std::string tag);
|
|
||||||
private:
|
private:
|
||||||
MyGUI::Widget* mParent;
|
|
||||||
int mWidth; // maximum width
|
|
||||||
int mHeight; // current height
|
|
||||||
TextStyle mTextStyle;
|
TextStyle mTextStyle;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GraphicElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GraphicElement(MyGUI::Widget * parent, Paginator & pag);
|
||||||
|
virtual int getHeight() = 0;
|
||||||
|
virtual void paginate();
|
||||||
|
virtual int pageSplit();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
MyGUI::Widget * mParent;
|
||||||
|
Paginator & mPaginator;
|
||||||
|
};
|
||||||
|
|
||||||
|
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:
|
||||||
|
int currentFontHeight() const;
|
||||||
|
TextStyle mStyle;
|
||||||
|
MyGUI::EditBox * mEditBox;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ImageElement : public GraphicElement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ImageElement(MyGUI::Widget * parent, Paginator & pag, const std::string & src, int width, int height);
|
||||||
|
virtual int getHeight();
|
||||||
|
virtual int pageSplit();
|
||||||
|
|
||||||
|
private:
|
||||||
|
int mImageHeight;
|
||||||
|
MyGUI::ImageBox * mImageBox;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -54,8 +54,9 @@ namespace MWGui
|
||||||
|
|
||||||
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
|
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
|
||||||
|
|
||||||
BookTextParser parser;
|
Formatting::BookFormatter formatter;
|
||||||
MyGUI::IntSize size = parser.parseScroll(ref->mBase->mText, mTextView, 390);
|
formatter.markupToWidget(mTextView, ref->mBase->mText, 390, mTextView->getHeight());
|
||||||
|
MyGUI::IntSize size = mTextView->getChildAt(0)->getSize();
|
||||||
|
|
||||||
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
||||||
mTextView->setVisibleVScroll(false);
|
mTextView->setVisibleVScroll(false);
|
||||||
|
|
|
@ -41,8 +41,8 @@
|
||||||
<Property key="TextColour" value="0 0 0"/>
|
<Property key="TextColour" value="0 0 0"/>
|
||||||
</Widget>
|
</Widget>
|
||||||
|
|
||||||
<Widget type="Widget" skin="" position="30 22 240 300" name="LeftPage"/>
|
<Widget type="Widget" skin="" position="30 15 240 328" name="LeftPage"/>
|
||||||
<Widget type="Widget" skin="" position="300 22 240 300" name="RightPage"/>
|
<Widget type="Widget" skin="" position="300 15 240 328" name="RightPage"/>
|
||||||
</Widget>
|
</Widget>
|
||||||
</Widget>
|
</Widget>
|
||||||
</Widget>
|
</Widget>
|
||||||
|
|
Loading…
Reference in a new issue