forked from mirror/openmw-tes3mp
Fixes Bug #734 'Book empty line problem'
Hides buttons 'Next' and 'Prev' at the last and at the first page
This commit is contained in:
parent
d5741c7141
commit
28ef4d97da
4 changed files with 77 additions and 11 deletions
|
@ -76,7 +76,7 @@ namespace MWGui
|
||||||
parent = mRightPage;
|
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));
|
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));
|
||||||
parser.parse(*it, pageWidget, mLeftPage->getSize().width);
|
parser.parsePage(*it, pageWidget, mLeftPage->getSize().width);
|
||||||
mPages.push_back(pageWidget);
|
mPages.push_back(pageWidget);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
@ -157,6 +157,21 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If it is the last page, hide the button "Next Page"
|
||||||
|
if ( (mCurrentPage+1)*2 == mPages.size()
|
||||||
|
|| (mCurrentPage+1)*2 == mPages.size() + 1)
|
||||||
|
{
|
||||||
|
mNextPageButton->setVisible(false);
|
||||||
|
} else {
|
||||||
|
mNextPageButton->setVisible(true);
|
||||||
|
}
|
||||||
|
//If it is the fist page, hide the button "Prev Page"
|
||||||
|
if (mCurrentPage == 0) {
|
||||||
|
mPrevPageButton->setVisible(false);
|
||||||
|
} else {
|
||||||
|
mPrevPageButton->setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,10 @@
|
||||||
|
|
||||||
#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>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -74,6 +77,12 @@ namespace
|
||||||
Ogre::UTFString string(s);
|
Ogre::UTFString string(s);
|
||||||
return string.getChar(0);
|
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
|
||||||
|
@ -88,6 +97,7 @@ namespace MWGui
|
||||||
utf8Text = Interpreter::fixDefinesBook(utf8Text, interpreterContext);
|
utf8Text = Interpreter::fixDefinesBook(utf8Text, interpreterContext);
|
||||||
|
|
||||||
boost::algorithm::replace_all(utf8Text, "\n", "");
|
boost::algorithm::replace_all(utf8Text, "\n", "");
|
||||||
|
boost::algorithm::replace_all(utf8Text, "\r", "");
|
||||||
boost::algorithm::replace_all(utf8Text, "<BR>", "\n");
|
boost::algorithm::replace_all(utf8Text, "<BR>", "\n");
|
||||||
boost::algorithm::replace_all(utf8Text, "<P>", "\n\n");
|
boost::algorithm::replace_all(utf8Text, "<P>", "\n\n");
|
||||||
|
|
||||||
|
@ -106,6 +116,14 @@ namespace MWGui
|
||||||
|
|
||||||
size_t currentWordStart = 0;
|
size_t currentWordStart = 0;
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string texToTrim = text.asUTF8();
|
||||||
|
boost::algorithm::trim( texToTrim );
|
||||||
|
text = UTFString(texToTrim);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while (currentHeight <= height - spacing && index < text.size())
|
while (currentHeight <= height - spacing && index < text.size())
|
||||||
{
|
{
|
||||||
const UTFString::unicode_char ch = text.getChar(index);
|
const UTFString::unicode_char ch = text.getChar(index);
|
||||||
|
@ -177,7 +195,9 @@ namespace MWGui
|
||||||
text.erase(0, pageEnd);
|
text.erase(0, pageEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
std::vector<std::string> nonEmptyPages;
|
||||||
|
boost::copy(result | boost::adaptors::filtered(is_not_empty), std::back_inserter(nonEmptyPages));
|
||||||
|
return nonEmptyPages;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BookTextParser::widthForCharGlyph(unsigned unicodeChar) const
|
float BookTextParser::widthForCharGlyph(unsigned unicodeChar) const
|
||||||
|
@ -193,7 +213,30 @@ namespace MWGui
|
||||||
return MyGUI::FontManager::getInstance().getByName(fontName)->getDefaultHeight();
|
return MyGUI::FontManager::getInstance().getByName(fontName)->getDefaultHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::IntSize BookTextParser::parse(std::string text, MyGUI::Widget* parent, const int width)
|
MyGUI::IntSize BookTextParser::parsePage(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));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
|
||||||
text = Interpreter::fixDefinesBook(text, interpreterContext);
|
text = Interpreter::fixDefinesBook(text, interpreterContext);
|
||||||
|
@ -209,12 +252,10 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::algorithm::replace_all(text, "\n", "");
|
boost::algorithm::replace_all(text, "\n", "");
|
||||||
|
boost::algorithm::replace_all(text, "\r", "");
|
||||||
boost::algorithm::replace_all(text, "<BR>", "\n");
|
boost::algorithm::replace_all(text, "<BR>", "\n");
|
||||||
boost::algorithm::replace_all(text, "<P>", "\n\n");
|
boost::algorithm::replace_all(text, "<P>", "\n\n");
|
||||||
|
boost::algorithm::trim_left(text);
|
||||||
// remove leading newlines
|
|
||||||
// while (text[0] == '\n')
|
|
||||||
// text.erase(0);
|
|
||||||
|
|
||||||
// remove trailing "
|
// remove trailing "
|
||||||
if (text[text.size()-1] == '\"')
|
if (text[text.size()-1] == '\"')
|
||||||
|
@ -224,6 +265,7 @@ namespace MWGui
|
||||||
return MyGUI::IntSize(mWidth, mHeight);
|
return MyGUI::IntSize(mWidth, mHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BookTextParser::parseImage(std::string tag, bool createWidget)
|
void BookTextParser::parseImage(std::string tag, bool createWidget)
|
||||||
{
|
{
|
||||||
int src_start = tag.find("SRC=")+5;
|
int src_start = tag.find("SRC=")+5;
|
||||||
|
@ -309,7 +351,7 @@ namespace MWGui
|
||||||
parseImage(tag);
|
parseImage(tag);
|
||||||
if (boost::algorithm::starts_with(tag, "FONT"))
|
if (boost::algorithm::starts_with(tag, "FONT"))
|
||||||
parseFont(tag);
|
parseFont(tag);
|
||||||
if (boost::algorithm::starts_with(tag, "DOV"))
|
if (boost::algorithm::starts_with(tag, "DIV"))
|
||||||
parseDiv(tag);
|
parseDiv(tag);
|
||||||
|
|
||||||
text.erase(0, tagEnd + 1);
|
text.erase(0, tagEnd + 1);
|
||||||
|
|
|
@ -32,7 +32,16 @@ namespace MWGui
|
||||||
* @param maximum width
|
* @param maximum width
|
||||||
* @return size of the created widgets
|
* @return size of the created widgets
|
||||||
*/
|
*/
|
||||||
MyGUI::IntSize parse(std::string text, MyGUI::Widget* parent, const int width);
|
MyGUI::IntSize parsePage(std::string text, MyGUI::Widget* parent, const int width);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse markup as MyGUI widgets
|
||||||
|
* @param markup to parse
|
||||||
|
* @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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split the specified text into pieces that fit in the area specified by width and height parameters
|
* Split the specified text into pieces that fit in the area specified by width and height parameters
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace MWGui
|
||||||
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
|
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
|
||||||
|
|
||||||
BookTextParser parser;
|
BookTextParser parser;
|
||||||
MyGUI::IntSize size = parser.parse(ref->mBase->mText, mTextView, 390);
|
MyGUI::IntSize size = parser.parseScroll(ref->mBase->mText, mTextView, 390);
|
||||||
|
|
||||||
if (size.height > mTextView->getSize().height)
|
if (size.height > mTextView->getSize().height)
|
||||||
mTextView->setCanvasSize(MyGUI::IntSize(410, size.height));
|
mTextView->setCanvasSize(MyGUI::IntSize(410, size.height));
|
||||||
|
|
Loading…
Reference in a new issue