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

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

@ -47,6 +47,7 @@ namespace MWGui::Formatting
registerTag("img", Event_ImgTag); registerTag("img", Event_ImgTag);
registerTag("div", Event_DivTag); registerTag("div", Event_DivTag);
registerTag("font", Event_FontTag); registerTag("font", Event_FontTag);
registerTag("body", Event_BodyTag);
} }
void BookTextParser::registerTag(const std::string & tag, BookTextParser::Events type) void BookTextParser::registerTag(const std::string & tag, BookTextParser::Events type)
@ -199,7 +200,7 @@ namespace MWGui::Formatting
} }
/* BookFormatter */ /* 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); Paginator pag(pageWidth, pageHeight);
@ -311,6 +312,18 @@ namespace MWGui::Formatting
case BookTextParser::Event_DivTag: case BookTextParser::Event_DivTag:
handleDiv(parser.getAttributes()); handleDiv(parser.getAttributes());
break; 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: default:
break; break;
} }
@ -325,9 +338,9 @@ namespace MWGui::Formatting
return pag.getPages(); 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() void BookFormatter::resetFontProperties()

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

@ -25,6 +25,8 @@ namespace MWGui
, mTakeButtonAllowed(true) , mTakeButtonAllowed(true)
{ {
getWidget(mTextView, "TextView"); getWidget(mTextView, "TextView");
getWidget(mBackgroundImage, "ScrollImage");
mDefaultBackground = mBackgroundImage->_getTextureName();
getWidget(mCloseButton, "CloseButton"); getWidget(mCloseButton, "CloseButton");
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onCloseButtonClicked); mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ScrollWindow::onCloseButtonClicked);
@ -50,10 +52,16 @@ namespace MWGui
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>(); MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
std::string backgroundImage;
Formatting::BookFormatter formatter; 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(); 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 // 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);
if (size.height > mTextView->getSize().height) if (size.height > mTextView->getSize().height)

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

Loading…
Cancel
Save