HTM extension for books

wolfgang_html_fun_for_books
Wolfgang Lieff 2 years ago committed by Bret Curtis
parent 451cc6a07c
commit ad3046ade8

@ -43,6 +43,9 @@ namespace MWGui
getWidget(mLeftPage, "LeftPage");
getWidget(mRightPage, "RightPage");
getWidget(mBackgroundImage, "JImage");
mDefaultBackground = mBackgroundImage->_getTextureName();
adjustButton("CloseButton");
adjustButton("TakeButton");
adjustButton("PrevPageBTN");
@ -93,9 +96,15 @@ namespace MWGui
MWWorld::LiveCellRef<ESM::Book> *ref = mBook.get<ESM::Book>();
std::string backgroundImage;
Formatting::BookFormatter formatter;
mPages = formatter.markupToWidget(mLeftPage, ref->mBase->mText);
formatter.markupToWidget(mRightPage, ref->mBase->mText);
mPages = formatter.markupToWidget(mLeftPage, ref->mBase->mText, backgroundImage);
formatter.markupToWidget(mRightPage, ref->mBase->mText, backgroundImage);
if (backgroundImage.empty())
mBackgroundImage->setImageTexture(mDefaultBackground);
else
mBackgroundImage->setImageTexture(backgroundImage);
updatePages();

@ -48,6 +48,8 @@ namespace MWGui
MyGUI::TextBox* mRightPageNumber;
MyGUI::Widget* mLeftPage;
MyGUI::Widget* mRightPage;
MyGUI::ImageBox* mBackgroundImage;
std::string mDefaultBackground;
unsigned int mCurrentPage; // 0 is first page
Pages mPages;

@ -47,6 +47,7 @@ namespace MWGui::Formatting
registerTag("img", Event_ImgTag);
registerTag("div", Event_DivTag);
registerTag("font", Event_FontTag);
registerTag("body", Event_BodyTag);
}
void BookTextParser::registerTag(const std::string & tag, BookTextParser::Events type)
@ -199,7 +200,7 @@ namespace MWGui::Formatting
}
/* BookFormatter */
Paginator::Pages BookFormatter::markupToWidget(MyGUI::Widget * parent, const std::string & markup, const int pageWidth, const int pageHeight)
Paginator::Pages BookFormatter::markupToWidget(MyGUI::Widget * parent, const std::string & markup, const int pageWidth, const int pageHeight, std::string & backgroundImage)
{
Paginator pag(pageWidth, pageHeight);
@ -311,6 +312,18 @@ namespace MWGui::Formatting
case BookTextParser::Event_DivTag:
handleDiv(parser.getAttributes());
break;
case BookTextParser::Event_BodyTag:
{
const BookTextParser::Attributes & attr = parser.getAttributes();
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
backgroundImage = Misc::ResourceHelpers::correctTexturePath(attr.at("background"), vfs);
if (!vfs->exists(backgroundImage))
{
Log(Debug::Warning) << "Warning: Could not find \"" << backgroundImage << "\" referenced by a <body> tag.";
backgroundImage.clear();
}
break;
}
default:
break;
}
@ -325,9 +338,9 @@ namespace MWGui::Formatting
return pag.getPages();
}
Paginator::Pages BookFormatter::markupToWidget(MyGUI::Widget * parent, const std::string & markup)
Paginator::Pages BookFormatter::markupToWidget(MyGUI::Widget * parent, const std::string & markup, std::string & backgroundImage)
{
return markupToWidget(parent, markup, parent->getWidth(), parent->getHeight());
return markupToWidget(parent, markup, parent->getWidth(), parent->getHeight(), backgroundImage);
}
void BookFormatter::resetFontProperties()

@ -46,7 +46,8 @@ namespace MWGui
Event_PTag,
Event_ImgTag,
Event_DivTag,
Event_FontTag
Event_FontTag,
Event_BodyTag
};
BookTextParser(const std::string & text);
@ -118,8 +119,8 @@ namespace MWGui
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);
Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup, const int pageWidth, const int pageHeight, std::string & backgroundImage);
Paginator::Pages markupToWidget(MyGUI::Widget * parent, const std::string & markup, std::string & backgroundImage);
private:
void resetFontProperties();

@ -25,6 +25,8 @@ namespace MWGui
, mTakeButtonAllowed(true)
{
getWidget(mTextView, "TextView");
getWidget(mBackgroundImage, "ScrollImage");
mDefaultBackground = mBackgroundImage->_getTextureName();
getWidget(mCloseButton, "CloseButton");
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onCloseButtonClicked);
@ -50,10 +52,16 @@ namespace MWGui
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
std::string backgroundImage;
Formatting::BookFormatter formatter;
formatter.markupToWidget(mTextView, ref->mBase->mText, 390, mTextView->getHeight());
formatter.markupToWidget(mTextView, ref->mBase->mText, 390, mTextView->getHeight(), backgroundImage);
MyGUI::IntSize size = mTextView->getChildAt(0)->getSize();
if (backgroundImage.empty())
mBackgroundImage->setImageTexture(mDefaultBackground);
else
mBackgroundImage->setImageTexture(backgroundImage);
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
mTextView->setVisibleVScroll(false);
if (size.height > mTextView->getSize().height)

@ -32,6 +32,8 @@ namespace MWGui
Gui::ImageButton* mCloseButton;
Gui::ImageButton* mTakeButton;
MyGUI::ScrollView* mTextView;
MyGUI::ImageBox* mBackgroundImage;
std::string mDefaultBackground;
MWWorld::Ptr mScroll;

Loading…
Cancel
Save