port code to C++03

This commit is contained in:
Nathan Jeffords 2013-02-09 10:44:20 -08:00
parent 6e7c9ebbe6
commit c7ede9b523
8 changed files with 260 additions and 225 deletions

View file

@ -7,6 +7,9 @@
#include "MyGUI_FactoryManager.h" #include "MyGUI_FactoryManager.h"
#include <platform/stdint.h> #include <platform/stdint.h>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <components/misc/utf8stream.hpp> #include <components/misc/utf8stream.hpp>
@ -104,7 +107,7 @@ struct MWGui::TypesetBook : ITypesetBook
range addContent (IBookTypesetter::utf8_span Text) range addContent (IBookTypesetter::utf8_span Text)
{ {
auto i = Contents.insert (Contents.end (), content (Text.first, Text.second)); contents::iterator i = Contents.insert (Contents.end (), content (Text.first, Text.second));
if (i->size () == 0) if (i->size () == 0)
return range (utf8_point (NULL), utf8_point (NULL)); return range (utf8_point (NULL), utf8_point (NULL));
@ -125,17 +128,17 @@ struct MWGui::TypesetBook : ITypesetBook
template <typename visitor> template <typename visitor>
void visit_runs (int top, int bottom, IFont* Font, visitor const & Visitor) const void visit_runs (int top, int bottom, IFont* Font, visitor const & Visitor) const
{ {
for (auto i = Sections.begin (); i != Sections.end (); ++i) for (sections::const_iterator i = Sections.begin (); i != Sections.end (); ++i)
{ {
if (top >= Rect.bottom || bottom <= i->Rect.top) if (top >= Rect.bottom || bottom <= i->Rect.top)
continue; continue;
for (auto j = i->Lines.begin (); j != i->Lines.end (); ++j) for (lines::const_iterator j = i->Lines.begin (); j != i->Lines.end (); ++j)
{ {
if (top >= j->Rect.bottom || bottom <= j->Rect.top) if (top >= j->Rect.bottom || bottom <= j->Rect.top)
continue; continue;
for (auto k = j->Runs.begin (); k != j->Runs.end (); ++k) for (runs::const_iterator k = j->Runs.begin (); k != j->Runs.end (); ++k)
if (!Font || k->Style->Font == Font) if (!Font || k->Style->Font == Font)
Visitor (*i, *j, *k); Visitor (*i, *j, *k);
} }
@ -148,23 +151,23 @@ struct MWGui::TypesetBook : ITypesetBook
visit_runs (top, bottom, NULL, Visitor); visit_runs (top, bottom, NULL, Visitor);
} }
style * hitTest (int left, int top) style * hitTest (int left, int top) const
{ {
for (auto i = Sections.begin (); i != Sections.end (); ++i) for (sections::const_iterator i = Sections.begin (); i != Sections.end (); ++i)
{ {
if (top < i->Rect.top || top >= i->Rect.bottom) if (top < i->Rect.top || top >= i->Rect.bottom)
continue; continue;
auto left1 = left - i->Rect.left; int left1 = left - i->Rect.left;
for (auto j = i->Lines.begin (); j != i->Lines.end (); ++j) for (lines::const_iterator j = i->Lines.begin (); j != i->Lines.end (); ++j)
{ {
if (top < j->Rect.top || top >= j->Rect.bottom) if (top < j->Rect.top || top >= j->Rect.bottom)
continue; continue;
auto left2 = left1 - j->Rect.left; int left2 = left1 - j->Rect.left;
for (auto k = j->Runs.begin (); k != j->Runs.end (); ++k) for (runs::const_iterator k = j->Runs.begin (); k != j->Runs.end (); ++k)
{ {
if (left2 < k->Left || left2 >= k->Right) if (left2 < k->Left || left2 >= k->Right)
continue; continue;
@ -179,7 +182,7 @@ struct MWGui::TypesetBook : ITypesetBook
IFont* affectedFont (style* Style) IFont* affectedFont (style* Style)
{ {
for (auto i = Styles.begin (); i != Styles.end (); ++i) for (styles::iterator i = Styles.begin (); i != Styles.end (); ++i)
if (&*i == Style) if (&*i == Style)
return i->Font; return i->Font;
return NULL; return NULL;
@ -191,7 +194,7 @@ struct MWGui::TypesetBook : ITypesetBook
struct TypesetBook::Typesetter : IBookTypesetter struct TypesetBook::Typesetter : IBookTypesetter
{ {
typedef TypesetBook book; typedef TypesetBook book;
typedef std::shared_ptr <book> book_ptr; typedef boost::shared_ptr <book> book_ptr;
int mPageWidth; int mPageWidth;
int mPageHeight; int mPageHeight;
@ -212,7 +215,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
mCurrentAlignment (alignLeft), mCurrentAlignment (alignLeft),
mCurrentContent (NULL) mCurrentContent (NULL)
{ {
Book = std::make_shared <book> (); Book = boost::make_shared <book> ();
} }
virtual ~Typesetter () virtual ~Typesetter ()
@ -221,11 +224,11 @@ struct TypesetBook::Typesetter : IBookTypesetter
IStyle * createStyle (char const * FontName, Colour FontColour) IStyle * createStyle (char const * FontName, Colour FontColour)
{ {
for (auto i = Book->Styles.begin (); i != Book->Styles.end (); ++i) for (styles::iterator i = Book->Styles.begin (); i != Book->Styles.end (); ++i)
if (i->match (FontName, FontColour, FontColour, FontColour, 0)) if (i->match (FontName, FontColour, FontColour, FontColour, 0))
return &*i; return &*i;
auto & Style = *Book->Styles.insert (Book->Styles.end (), style ()); style & Style = *Book->Styles.insert (Book->Styles.end (), style ());
Style.Font = FontManager::getInstance().getByName(FontName); Style.Font = FontManager::getInstance().getByName(FontName);
Style.HotColour = FontColour; Style.HotColour = FontColour;
@ -238,14 +241,14 @@ struct TypesetBook::Typesetter : IBookTypesetter
IStyle* createHotStyle (IStyle * _BaseStyle, coulour NormalColour, coulour HoverColour, coulour ActiveColour, interactive_id Id, bool Unique) IStyle* createHotStyle (IStyle * _BaseStyle, coulour NormalColour, coulour HoverColour, coulour ActiveColour, interactive_id Id, bool Unique)
{ {
auto BaseStyle = dynamic_cast <style*> (_BaseStyle); style* BaseStyle = dynamic_cast <style*> (_BaseStyle);
if (!Unique) if (!Unique)
for (auto i = Book->Styles.begin (); i != Book->Styles.end (); ++i) for (styles::iterator i = Book->Styles.begin (); i != Book->Styles.end (); ++i)
if (i->match (BaseStyle->Font, HoverColour, ActiveColour, NormalColour, Id)) if (i->match (BaseStyle->Font, HoverColour, ActiveColour, NormalColour, Id))
return &*i; return &*i;
auto & Style = *Book->Styles.insert (Book->Styles.end (), style ()); style & Style = *Book->Styles.insert (Book->Styles.end (), style ());
Style.Font = BaseStyle->Font; Style.Font = BaseStyle->Font;
Style.HotColour = HoverColour; Style.HotColour = HoverColour;
@ -258,14 +261,14 @@ struct TypesetBook::Typesetter : IBookTypesetter
void write (IStyle * _Style, utf8_span Text) void write (IStyle * _Style, utf8_span Text)
{ {
auto text = Book->addContent (Text); range text = Book->addContent (Text);
write_impl (dynamic_cast <style*> (_Style), text.first, text.second); write_impl (dynamic_cast <style*> (_Style), text.first, text.second);
} }
intptr_t add_content (utf8_span Text, bool Select) intptr_t add_content (utf8_span Text, bool Select)
{ {
auto i = Book->Contents.insert (Book->Contents.end (), content (Text.first, Text.second)); contents::iterator i = Book->Contents.insert (Book->Contents.end (), content (Text.first, Text.second));
if (Select) if (Select)
mCurrentContent = &(*i); mCurrentContent = &(*i);
@ -323,14 +326,14 @@ struct TypesetBook::Typesetter : IBookTypesetter
int curPageStart = 0; int curPageStart = 0;
int curPageStop = 0; int curPageStop = 0;
auto sa = mSectionAlignment.begin (); std::vector <alignment>::iterator sa = mSectionAlignment.begin ();
for (auto i = Book->Sections.begin (); i != Book->Sections.end (); ++i, ++sa) for (sections::iterator i = Book->Sections.begin (); i != Book->Sections.end (); ++i, ++sa)
{ {
// apply alignment to individual lines... // apply alignment to individual lines...
for (auto j = i->Lines.begin (); j != i->Lines.end (); ++j) for (lines::iterator j = i->Lines.begin (); j != i->Lines.end (); ++j)
{ {
auto width = j->Rect.width (); int width = j->Rect.width ();
auto excess = mPageWidth - width; int excess = mPageWidth - width;
switch (*sa) switch (*sa)
{ {
@ -349,8 +352,8 @@ struct TypesetBook::Typesetter : IBookTypesetter
curPageStop = i->Rect.top; curPageStop = i->Rect.top;
} }
auto spaceLeft = mPageHeight - (curPageStop - curPageStart); int spaceLeft = mPageHeight - (curPageStop - curPageStart);
auto sectionHeight = i->Rect.height (); int sectionHeight = i->Rect.height ();
if (sectionHeight <= mPageHeight) if (sectionHeight <= mPageHeight)
{ {
@ -380,7 +383,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
void write_impl (style * Style, utf8_stream::point _begin, utf8_stream::point _end) void write_impl (style * Style, utf8_stream::point _begin, utf8_stream::point _end)
{ {
auto line_height = Style->Font->getDefaultHeight (); int line_height = Style->Font->getDefaultHeight ();
utf8_stream stream (_begin, _end); utf8_stream stream (_begin, _end);
@ -398,27 +401,27 @@ struct TypesetBook::Typesetter : IBookTypesetter
int space_width = 0; int space_width = 0;
int character_count = 0; int character_count = 0;
auto lead = stream.current (); utf8_stream::point lead = stream.current ();
while (!stream.eof () && !ucs_line_break (stream.peek ()) && ucs_breaking_space (stream.peek ())) while (!stream.eof () && !ucs_line_break (stream.peek ()) && ucs_breaking_space (stream.peek ()))
{ {
auto gi = Style->Font->getGlyphInfo (stream.peek ()); GlyphInfo* gi = Style->Font->getGlyphInfo (stream.peek ());
space_width += gi->advance; space_width += gi->advance;
stream.consume (); stream.consume ();
} }
auto origin = stream.current (); utf8_stream::point origin = stream.current ();
while (!stream.eof () && !ucs_line_break (stream.peek ()) && !ucs_breaking_space (stream.peek ())) while (!stream.eof () && !ucs_line_break (stream.peek ()) && !ucs_breaking_space (stream.peek ()))
{ {
auto gi = Style->Font->getGlyphInfo (stream.peek ()); GlyphInfo* gi = Style->Font->getGlyphInfo (stream.peek ());
word_width += gi->advance + gi->bearingX; word_width += gi->advance + gi->bearingX;
word_height = line_height; word_height = line_height;
++character_count; ++character_count;
stream.consume (); stream.consume ();
} }
auto extent = stream.current (); utf8_stream::point extent = stream.current ();
if (lead == extent) if (lead == extent)
break; break;
@ -477,7 +480,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
if (Run == NULL || Run->Style != Style || Run->Range.second != begin) if (Run == NULL || Run->Style != Style || Run->Range.second != begin)
{ {
auto left = Run ? Run->Right : Line->Rect.left; int left = Run ? Run->Right : Line->Rect.left;
Line->Runs.push_back (run ()); Line->Runs.push_back (run ());
Run = &Line->Runs.back (); Run = &Line->Runs.back ();
@ -500,7 +503,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
IBookTypesetter::ptr IBookTypesetter::create (int pageWidth, int pageHeight) IBookTypesetter::ptr IBookTypesetter::create (int pageWidth, int pageHeight)
{ {
return std::make_shared <TypesetBook::Typesetter> (pageWidth, pageHeight); return boost::make_shared <TypesetBook::Typesetter> (pageWidth, pageHeight);
} }
namespace namespace
@ -624,7 +627,7 @@ namespace
void emit_glyph (wchar_t ch) void emit_glyph (wchar_t ch)
{ {
auto gi = mFont->getGlyphInfo (ch); GlyphInfo* gi = mFont->getGlyphInfo (ch);
FloatRect vr; FloatRect vr;
@ -640,10 +643,10 @@ namespace
mCursor.left += gi->bearingX + gi->advance; mCursor.left += gi->bearingX + gi->advance;
} }
void emit_space (wchar_t ch) void emit_space (wchar_t ch)
{ {
auto gi = mFont->getGlyphInfo (ch); GlyphInfo* gi = mFont->getGlyphInfo (ch);
mCursor.left += gi->bearingX + gi->advance; mCursor.left += gi->bearingX + gi->advance;
} }
@ -662,7 +665,7 @@ namespace
void vertex (float X, float Y, float U, float V) void vertex (float X, float Y, float U, float V)
{ {
auto pt = mRenderXform (FloatPoint (X, Y)); FloatPoint pt = mRenderXform (FloatPoint (X, Y));
mVertices->x = pt.left; mVertices->x = pt.left;
mVertices->y = pt.top ; mVertices->y = pt.top ;
@ -743,14 +746,15 @@ public:
style* mFocusItem; style* mFocusItem;
bool mItemActive; bool mItemActive;
std::function <void (intptr_t)> mLinkClicked; boost::function <void (intptr_t)> mLinkClicked;
std::shared_ptr <TypesetBook> mBook; boost::shared_ptr <TypesetBook> mBook;
size_t mPage; size_t mPage;
ILayerNode* mNode; ILayerNode* mNode;
std::map <TextFormat::id, TextFormat*> mActiveTextFormats; typedef std::map <TextFormat::id, TextFormat*> active_text_formats;
active_text_formats mActiveTextFormats;
PageDisplay () PageDisplay ()
{ {
@ -763,9 +767,9 @@ public:
{ {
if (mFocusItem != 0) if (mFocusItem != 0)
{ {
auto Font = mBook->affectedFont (mFocusItem); IFont* Font = mBook->affectedFont (mFocusItem);
auto i = mActiveTextFormats.find (Font); active_text_formats::iterator i = mActiveTextFormats.find (Font);
mNode->outOfDate (i->second->mRenderItem); mNode->outOfDate (i->second->mRenderItem);
} }
@ -790,7 +794,7 @@ public:
_left -= mCroppedParent->getAbsoluteLeft (); _left -= mCroppedParent->getAbsoluteLeft ();
_top -= mCroppedParent->getAbsoluteTop (); _top -= mCroppedParent->getAbsoluteTop ();
auto Hit = mBook->hitTest (_left, view_top + _top); style * Hit = mBook->hitTest (_left, view_top + _top);
if (mLastDown == MouseButton::None) if (mLastDown == MouseButton::None)
{ {
@ -807,7 +811,7 @@ public:
else else
if (mFocusItem != 0) if (mFocusItem != 0)
{ {
auto newItemActive = Hit == mFocusItem; bool newItemActive = Hit == mFocusItem;
if (newItemActive != mItemActive) if (newItemActive != mItemActive)
{ {
@ -847,9 +851,9 @@ public:
if (mLastDown == _id) if (mLastDown == _id)
{ {
auto mItem = mBook->hitTest (_left, view_top + _top); style * mItem = mBook->hitTest (_left, view_top + _top);
auto clicked = mFocusItem == mItem; bool clicked = mFocusItem == mItem;
mItemActive = false; mItemActive = false;
@ -864,14 +868,14 @@ public:
void showPage (ITypesetBook::ptr _Book, size_t newPage) void showPage (ITypesetBook::ptr _Book, size_t newPage)
{ {
auto newBook = std::dynamic_pointer_cast <TypesetBook> (_Book); boost::shared_ptr <TypesetBook> newBook = boost::dynamic_pointer_cast <TypesetBook> (_Book);
if (mBook != newBook) if (mBook != newBook)
{ {
mFocusItem = nullptr; mFocusItem = nullptr;
mItemActive = 0; mItemActive = 0;
for (auto i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
{ {
if (mNode != NULL) if (mNode != NULL)
i->second->destroyDrawItem (mNode); i->second->destroyDrawItem (mNode);
@ -910,7 +914,7 @@ public:
if (mBook && mPage != newPage) if (mBook && mPage != newPage)
{ {
if (mNode != NULL) if (mNode != NULL)
for (auto i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
mNode->outOfDate(i->second->mRenderItem); mNode->outOfDate(i->second->mRenderItem);
mPage = newPage; mPage = newPage;
@ -928,29 +932,37 @@ public:
} }
} }
void createActiveFormats (std::shared_ptr <TypesetBook> newBook) struct createActiveFormat
{ {
newBook->visit_runs (0, 0x7FFFFFFF, [this] (section const & Section, line const & Line, run const & Run) { PageDisplay * this_;
auto Font = Run.Style->Font; createActiveFormat (PageDisplay * this_) : this_ (this_) {}
auto j = mActiveTextFormats.find (Font); void operator () (section const & Section, line const & Line, run const & Run) const
{
IFont* Font = Run.Style->Font;
if (j == mActiveTextFormats.end ()) active_text_formats::iterator j = this_->mActiveTextFormats.find (Font);
if (j == this_->mActiveTextFormats.end ())
{ {
auto textFormat = new TextFormat (Font, this); TextFormat * textFormat = new TextFormat (Font, this_);
textFormat->mTexture = Font->getTextureFont (); textFormat->mTexture = Font->getTextureFont ();
j = mActiveTextFormats.insert (std::make_pair (Font, textFormat)).first; j = this_->mActiveTextFormats.insert (std::make_pair (Font, textFormat)).first;
} }
j->second->mCountVertex += Run.PrintableChars * 6; j->second->mCountVertex += Run.PrintableChars * 6;
}
};
}); void createActiveFormats (boost::shared_ptr <TypesetBook> newBook)
{
newBook->visit_runs (0, 0x7FFFFFFF, createActiveFormat (this));
if (mNode != NULL) if (mNode != NULL)
for (auto i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
i->second->createDrawItem (mNode); i->second->createDrawItem (mNode);
} }
@ -971,7 +983,7 @@ public:
if (nullptr != mNode) if (nullptr != mNode)
{ {
for (auto i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
mNode->outOfDate(i->second->mRenderItem); mNode->outOfDate(i->second->mRenderItem);
} }
} }
@ -981,11 +993,43 @@ public:
//test (); //test ();
mNode = _node; mNode = _node;
for (auto i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
i->second->createDrawItem (_node); i->second->createDrawItem (_node);
} }
struct renderRun
{
PageDisplay * this_;
glyph_stream &glyphStream;
renderRun (PageDisplay * this_, glyph_stream &glyphStream) :
this_(this_), glyphStream (glyphStream)
{
}
void operator () (section const & Section, line const & Line, run const & Run) const
{
bool isActive = Run.Style->InteractiveId && (Run.Style == this_->mFocusItem);
Colour colour = isActive ? (this_->mItemActive ? Run.Style->ActiveColour: Run.Style->HotColour) : Run.Style->NormalColour;
glyphStream.reset (Section.Rect.left + Line.Rect.left + Run.Left, Line.Rect.top, colour);
utf8_stream stream (Run.Range);
while (!stream.eof ())
{
utf8_stream::unicode_char code_point = stream.consume ();
if (!ucs_space (code_point))
glyphStream.emit_glyph (code_point);
else
glyphStream.emit_space (code_point);
}
}
};
/* /*
queue up rendering operations for this text format queue up rendering operations for this text format
*/ */
@ -994,38 +1038,17 @@ public:
if (!mVisible) if (!mVisible)
return; return;
auto vertices = textFormat.mRenderItem->getCurrentVertexBuffer(); Vertex* vertices = textFormat.mRenderItem->getCurrentVertexBuffer();
render_xform renderXform (mCroppedParent, textFormat.mRenderItem->getRenderTarget()->getInfo()); render_xform renderXform (mCroppedParent, textFormat.mRenderItem->getRenderTarget()->getInfo());
glyph_stream glyphStream (textFormat.mFont, mCoord.left, mCoord.top-view_top, glyph_stream glyphStream (textFormat.mFont, mCoord.left, mCoord.top-view_top,
-1 /*mNode->getNodeDepth()*/, vertices, renderXform); -1 /*mNode->getNodeDepth()*/, vertices, renderXform);
auto visit_top = (std::max) (view_top, view_top + int (renderXform.clipTop )); int visit_top = (std::max) (view_top, view_top + int (renderXform.clipTop ));
auto visit_bottom = (std::min) (view_bottom, view_top + int (renderXform.clipBottom)); int visit_bottom = (std::min) (view_bottom, view_top + int (renderXform.clipBottom));
mBook->visit_runs (visit_top, visit_bottom, textFormat.mFont, mBook->visit_runs (visit_top, visit_bottom, textFormat.mFont, renderRun (this, glyphStream));
[this, &glyphStream] (section const & Section, line const & Line, run const & Run)
{
bool isActive = Run.Style->InteractiveId && (Run.Style == mFocusItem);
Colour colour = isActive ? (mItemActive ? Run.Style->ActiveColour: Run.Style->HotColour) : Run.Style->NormalColour;
glyphStream.reset (Section.Rect.left + Line.Rect.left + Run.Left, Line.Rect.top, colour);
utf8_stream stream (Run.Range);
while (!stream.eof ())
{
auto code_point = stream.consume ();
if (!ucs_space (code_point))
glyphStream.emit_glyph (code_point);
else
glyphStream.emit_space (code_point);
}
}
);
textFormat.mRenderItem->setLastVertexCount(glyphStream.end () - vertices); textFormat.mRenderItem->setLastVertexCount(glyphStream.end () - vertices);
} }
@ -1043,14 +1066,14 @@ public:
_checkMargin (); _checkMargin ();
if (mNode != NULL) if (mNode != NULL)
for (auto i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
mNode->outOfDate (i->second->mRenderItem); mNode->outOfDate (i->second->mRenderItem);
} }
void destroyDrawItem() void destroyDrawItem()
{ {
for (auto i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
i->second->destroyDrawItem (mNode); i->second->destroyDrawItem (mNode);
mNode = NULL; mNode = NULL;
@ -1066,15 +1089,15 @@ public:
void showPage (ITypesetBook::ptr Book, size_t Page) void showPage (ITypesetBook::ptr Book, size_t Page)
{ {
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
pd->showPage (Book, Page); pd->showPage (Book, Page);
else else
throw std::runtime_error ("The main sub-widget for a BookPage must be a PageDisplay."); throw std::runtime_error ("The main sub-widget for a BookPage must be a PageDisplay.");
} }
void adviseLinkClicked (std::function <void (interactive_id)> linkClicked) void adviseLinkClicked (boost::function <void (interactive_id)> linkClicked)
{ {
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->mLinkClicked = linkClicked; pd->mLinkClicked = linkClicked;
} }
@ -1082,16 +1105,16 @@ public:
void unadviseLinkClicked () void unadviseLinkClicked ()
{ {
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->mLinkClicked = std::function <void (interactive_id)> (); pd->mLinkClicked = boost::function <void (interactive_id)> ();
} }
} }
protected: protected:
void onMouseLostFocus(Widget* _new) void onMouseLostFocus(Widget* _new)
{ {
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->onMouseLostFocus (); pd->onMouseLostFocus ();
} }
@ -1101,7 +1124,7 @@ protected:
void onMouseMove(int _left, int _top) void onMouseMove(int _left, int _top)
{ {
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->onMouseMove (_left, _top); pd->onMouseMove (_left, _top);
} }
@ -1111,7 +1134,7 @@ protected:
void onMouseButtonPressed (int _left, int _top, MouseButton _id) void onMouseButtonPressed (int _left, int _top, MouseButton _id)
{ {
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->onMouseButtonPressed (_left, _top, _id); pd->onMouseButtonPressed (_left, _top, _id);
} }
@ -1121,7 +1144,7 @@ protected:
void onMouseButtonReleased(int _left, int _top, MouseButton _id) void onMouseButtonReleased(int _left, int _top, MouseButton _id)
{ {
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->onMouseButtonReleased (_left, _top, _id); pd->onMouseButtonReleased (_left, _top, _id);
} }
@ -1132,7 +1155,7 @@ protected:
void IBookPage::registerMyGUIComponents () void IBookPage::registerMyGUIComponents ()
{ {
auto & factory = FactoryManager::getInstance(); FactoryManager & factory = FactoryManager::getInstance();
factory.registerFactory<BookPage>("Widget"); factory.registerFactory<BookPage>("Widget");
factory.registerFactory<PageDisplay>("BasisSkin"); factory.registerFactory<PageDisplay>("BasisSkin");

View file

@ -6,6 +6,8 @@
#include <functional> #include <functional>
#include <platform/stdint.h> #include <platform/stdint.h>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
namespace MWGui namespace MWGui
{ {
@ -13,7 +15,7 @@ namespace MWGui
/// the book page widget. /// the book page widget.
struct ITypesetBook struct ITypesetBook
{ {
typedef std::shared_ptr <ITypesetBook> ptr; typedef boost::shared_ptr <ITypesetBook> ptr;
typedef intptr_t interactive_id; typedef intptr_t interactive_id;
/// Returns the number of pages in the document. /// Returns the number of pages in the document.
@ -31,7 +33,7 @@ namespace MWGui
/// A factory class for creating a typeset book instance. /// A factory class for creating a typeset book instance.
struct IBookTypesetter struct IBookTypesetter
{ {
typedef std::shared_ptr <IBookTypesetter> ptr; typedef boost::shared_ptr <IBookTypesetter> ptr;
typedef ITypesetBook::interactive_id interactive_id; typedef ITypesetBook::interactive_id interactive_id;
typedef MyGUI::Colour coulour; typedef MyGUI::Colour coulour;
typedef uint8_t const * utf8_point; typedef uint8_t const * utf8_point;
@ -100,7 +102,7 @@ namespace MWGui
public: public:
typedef ITypesetBook::interactive_id interactive_id; typedef ITypesetBook::interactive_id interactive_id;
typedef std::function <void (interactive_id)> click_callback; typedef boost::function <void (interactive_id)> click_callback;
/// Make the widget display the specified page from the specified book. /// Make the widget display the specified page from the specified book.
virtual void showPage (ITypesetBook::ptr Book, size_t Page) = 0; virtual void showPage (ITypesetBook::ptr Book, size_t Page) = 0;

View file

@ -37,7 +37,7 @@ namespace
void operator () (intptr_t topicId, size_t begin, size_t end) void operator () (intptr_t topicId, size_t begin, size_t end)
{ {
auto style = body_style; IBookTypesetter::IStyle* style = body_style;
if (topicId) if (topicId)
style = typesetter->createHotStyle (body_style, linkNormal, linkHot, linkActive, topicId); style = typesetter->createHotStyle (body_style, linkNormal, linkHot, linkActive, topicId);
@ -153,7 +153,7 @@ namespace
void operator () (IJournalViewModel::topic_id topicId, IJournalViewModel::utf8_span name) void operator () (IJournalViewModel::topic_id topicId, IJournalViewModel::utf8_span name)
{ {
auto link = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, topicId); IBookTypesetter::IStyle* link = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, topicId);
typesetter->write (link, name); typesetter->write (link, name);
typesetter->lineBreak (); typesetter->lineBreak ();
@ -169,7 +169,7 @@ namespace
void operator () (IJournalViewModel::quest_id id, IJournalViewModel::utf8_span name) void operator () (IJournalViewModel::quest_id id, IJournalViewModel::utf8_span name)
{ {
auto style = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, id); IBookTypesetter::IStyle* style = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, id);
typesetter->write (style, name); typesetter->write (style, name);
typesetter->lineBreak (); typesetter->lineBreak ();
@ -186,17 +186,17 @@ JournalBooks::JournalBooks (IJournalViewModel::ptr Model) :
book JournalBooks::createEmptyJournalBook () book JournalBooks::createEmptyJournalBook ()
{ {
auto typesetter = createTypesetter (); IBookTypesetter::ptr typesetter = createTypesetter ();
auto header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
typesetter->write (header, to_utf8_span ("You have no journal entries!")); typesetter->write (header, to_utf8_span ("You have no journal entries!"));
typesetter->lineBreak (); typesetter->lineBreak ();
typesetter->write (body, to_utf8_span ("You should have gone though the starting quest and got an initial quest.")); typesetter->write (body, to_utf8_span ("You should have gone though the starting quest and got an initial quest."));
auto big = typesetter->createStyle ("EB Garamond 24", MyGUI::Colour::Black); IBookTypesetter::IStyle* big = typesetter->createStyle ("EB Garamond 24", MyGUI::Colour::Black);
auto test = typesetter->createStyle ("MonoFont", MyGUI::Colour::Blue); IBookTypesetter::IStyle* test = typesetter->createStyle ("MonoFont", MyGUI::Colour::Blue);
typesetter->sectionBreak (20); typesetter->sectionBreak (20);
typesetter->write (body, to_utf8_span ( typesetter->write (body, to_utf8_span (
@ -228,10 +228,10 @@ book JournalBooks::createEmptyJournalBook ()
book JournalBooks::createJournalBook () book JournalBooks::createJournalBook ()
{ {
auto typesetter = createTypesetter (); IBookTypesetter::ptr typesetter = createTypesetter ();
auto header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_journal_entries (0, addJournalEntry (typesetter, body, header, true)); Model->visit_journal_entries (0, addJournalEntry (typesetter, body, header, true));
@ -240,14 +240,14 @@ book JournalBooks::createJournalBook ()
book JournalBooks::createTopicBook (uintptr_t topicId) book JournalBooks::createTopicBook (uintptr_t topicId)
{ {
auto typesetter = createTypesetter (); IBookTypesetter::ptr typesetter = createTypesetter ();
auto header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_topic_name (topicId, addTopicName (typesetter, header)); Model->visit_topic_name (topicId, addTopicName (typesetter, header));
auto contentId = typesetter->add_content (to_utf8_span (", \"")); intptr_t contentId = typesetter->add_content (to_utf8_span (", \""));
Model->visit_topic_entries (topicId, addTopicEntry (typesetter, body, header, contentId)); Model->visit_topic_entries (topicId, addTopicEntry (typesetter, body, header, contentId));
@ -256,10 +256,10 @@ book JournalBooks::createTopicBook (uintptr_t topicId)
book JournalBooks::createQuestBook (uintptr_t questId) book JournalBooks::createQuestBook (uintptr_t questId)
{ {
auto typesetter = createTypesetter (); IBookTypesetter::ptr typesetter = createTypesetter ();
auto header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_quest_name (questId, addQuestName (typesetter, header)); Model->visit_quest_name (questId, addQuestName (typesetter, header));
@ -270,11 +270,11 @@ book JournalBooks::createQuestBook (uintptr_t questId)
book JournalBooks::createTopicIndexBook () book JournalBooks::createTopicIndexBook ()
{ {
auto typesetter = IBookTypesetter::create (92, 250); IBookTypesetter::ptr typesetter = IBookTypesetter::create (92, 250);
typesetter->setSectionAlignment (IBookTypesetter::alignCenter); typesetter->setSectionAlignment (IBookTypesetter::alignCenter);
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
for (int i = 0; i < 26; ++i) for (int i = 0; i < 26; ++i)
{ {
@ -284,7 +284,7 @@ book JournalBooks::createTopicIndexBook ()
sprintf (buffer, "( %c )", ch); sprintf (buffer, "( %c )", ch);
auto style = typesetter->createHotStyle (body, MyGUI::Colour::Black, linkHot, linkActive, ch); IBookTypesetter::IStyle* style = typesetter->createHotStyle (body, MyGUI::Colour::Black, linkHot, linkActive, ch);
if (i == 13) if (i == 13)
typesetter->sectionBreak (); typesetter->sectionBreak ();
@ -298,8 +298,8 @@ book JournalBooks::createTopicIndexBook ()
book JournalBooks::createTopicIndexBook (char character) book JournalBooks::createTopicIndexBook (char character)
{ {
auto typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF); IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
auto style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_topic_names_starting_with (character, addTopicLink (typesetter, style)); Model->visit_topic_names_starting_with (character, addTopicLink (typesetter, style));
@ -308,8 +308,8 @@ book JournalBooks::createTopicIndexBook (char character)
book JournalBooks::createQuestIndexBook (bool activeOnly) book JournalBooks::createQuestIndexBook (bool activeOnly)
{ {
auto typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF); IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
auto base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_quest_names (activeOnly, addQuestLink (typesetter, base)); Model->visit_quest_names (activeOnly, addQuestLink (typesetter, base));

View file

@ -11,6 +11,7 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <boost/make_shared.hpp>
using namespace MWGui; using namespace MWGui;
@ -34,7 +35,7 @@ public:
void seed (string_t Keyword, value_t Value) void seed (string_t Keyword, value_t Value)
{ {
seed_impl (std::move (Keyword), std::move (Value), 0, Root); seed_impl (/*std::move*/ (Keyword), /*std::move*/ (Value), 0, Root);
} }
void clear () void clear ()
@ -45,21 +46,21 @@ public:
bool search (point Beg, point End, match & Match) bool search (point Beg, point End, match & Match)
{ {
for (auto i = Beg; i != End; ++i) for (point i = Beg; i != End; ++i)
{ {
// check first character // check first character
auto candidate = Root.Children.find (std::tolower (*i, Locale)); typename entry::childen_t::iterator candidate = Root.Children.find (std::tolower (*i, Locale));
// no match, on to next character // no match, on to next character
if (candidate == Root.Children.end ()) if (candidate == Root.Children.end ())
continue; continue;
// see how far the match goes // see how far the match goes
auto j = i; point j = i;
while ((j + 1) != End) while ((j + 1) != End)
{ {
auto next = candidate->second.Children.find (std::tolower (*++j, Locale)); typename entry::childen_t::iterator next = candidate->second.Children.find (std::tolower (*++j, Locale));
if (next == candidate->second.Children.end ()) if (next == candidate->second.Children.end ())
break; break;
@ -72,7 +73,7 @@ public:
continue; continue;
// match the rest of the keyword // match the rest of the keyword
auto t = candidate->second.Keyword.begin () + (j - i); typename string_t::const_iterator t = candidate->second.Keyword.begin () + (j - i);
while (j != End && t != candidate->second.Keyword.end ()) while (j != End && t != candidate->second.Keyword.end ())
{ {
@ -111,14 +112,14 @@ private:
void seed_impl (string_t Keyword, value_t Value, size_t Depth, entry & Entry) void seed_impl (string_t Keyword, value_t Value, size_t Depth, entry & Entry)
{ {
auto ch = tolower (Keyword.at (Depth), Locale); int ch = tolower (Keyword.at (Depth), Locale);
auto j = Entry.Children.find (ch); typename entry::childen_t::iterator j = Entry.Children.find (ch);
if (j == Entry.Children.end ()) if (j == Entry.Children.end ())
{ {
Entry.Children [ch].Value = std::move (Value); Entry.Children [ch].Value = /*std::move*/ (Value);
Entry.Children [ch].Keyword = std::move (Keyword); Entry.Children [ch].Keyword = /*std::move*/ (Keyword);
} }
else else
{ {
@ -127,18 +128,18 @@ private:
if (Keyword == j->second.Keyword) if (Keyword == j->second.Keyword)
throw std::runtime_error ("duplicate keyword inserted"); throw std::runtime_error ("duplicate keyword inserted");
auto pushValue = std::move (j->second.Value); value_t pushValue = /*std::move*/ (j->second.Value);
auto pushKeyword = std::move (j->second.Keyword); string_t pushKeyword = /*std::move*/ (j->second.Keyword);
j->second.Keyword.clear (); j->second.Keyword.clear ();
if (Depth >= pushKeyword.size ()) if (Depth >= pushKeyword.size ())
throw std::runtime_error ("unexpected"); throw std::runtime_error ("unexpected");
seed_impl (std::move (pushKeyword), std::move (pushValue), Depth+1, j->second); seed_impl (/*std::move*/ (pushKeyword), /*std::move*/ (pushValue), Depth+1, j->second);
} }
seed_impl (std::move (Keyword), std::move (Value), Depth+1, j->second); seed_impl (/*std::move*/ (Keyword), /*std::move*/ (Value), Depth+1, j->second);
} }
} }
@ -171,7 +172,7 @@ struct MWGui::JournalViewModel : IJournalViewModel
if (str.size () == 0) if (str.size () == 0)
return utf8_span (utf8_point (NULL), utf8_point (NULL)); return utf8_span (utf8_point (NULL), utf8_point (NULL));
utf8_point point = reinterpret_cast <utf8_point> (&str.front ()); utf8_point point = reinterpret_cast <utf8_point> (str.c_str ());
return utf8_span (point, point + str.size ()); return utf8_span (point, point + str.size ());
} }
@ -190,9 +191,9 @@ struct MWGui::JournalViewModel : IJournalViewModel
{ {
if (!FooBar_loaded) if (!FooBar_loaded)
{ {
auto journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
for(auto i = journal->topicBegin(); i != journal->topicEnd (); ++i) for(MWBase::Journal::TTopicIter i = journal->topicBegin(); i != journal->topicEnd (); ++i)
FooBar.seed (i->first, intptr_t (&i->second)); FooBar.seed (i->first, intptr_t (&i->second));
FooBar_loaded = true; FooBar_loaded = true;
@ -203,14 +204,16 @@ struct MWGui::JournalViewModel : IJournalViewModel
bool is_empty () const bool is_empty () const
{ {
auto journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
return journal->begin () == journal->end (); return journal->begin () == journal->end ();
} }
template <typename iterator_t, typename IInterface> template <typename t_iterator, typename IInterface>
struct base_entry : IInterface struct base_entry : IInterface
{ {
typedef t_iterator iterator_t;
iterator_t itr; iterator_t itr;
JournalViewModel const * Model; JournalViewModel const * Model;
@ -241,7 +244,7 @@ struct MWGui::JournalViewModel : IJournalViewModel
return to_utf8_span (utf8text); return to_utf8_span (utf8text);
} }
void visit_spans (std::function < void (topic_id, size_t, size_t)> visitor) const void visit_spans (boost::function < void (topic_id, size_t, size_t)> visitor) const
{ {
ensure_loaded (); ensure_loaded ();
Model->ensure_FooBar_loaded (); Model->ensure_FooBar_loaded ();
@ -266,11 +269,11 @@ struct MWGui::JournalViewModel : IJournalViewModel
}; };
void visit_quest_names (bool active_only, std::function <void (quest_id, utf8_span)> visitor) const void visit_quest_names (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const
{ {
auto journal = MWBase::Environment::get ().getJournal (); MWBase::Journal * journal = MWBase::Environment::get ().getJournal ();
for (auto i = journal->questBegin (); i != journal->questEnd (); ++i) for (MWBase::Journal::TQuestIter i = journal->questBegin (); i != journal->questEnd (); ++i)
{ {
if (active_only && i->second.isFinished ()) if (active_only && i->second.isFinished ())
continue; continue;
@ -279,11 +282,11 @@ struct MWGui::JournalViewModel : IJournalViewModel
} }
} }
void visit_quest_name (quest_id questId, std::function <void (utf8_span)> visitor) const void visit_quest_name (quest_id questId, boost::function <void (utf8_span)> visitor) const
{ {
MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId); MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId);
auto name = quest->getName (); std::string name = quest->getName ();
visitor (to_utf8_span (name)); visitor (to_utf8_span (name));
} }
@ -323,47 +326,47 @@ struct MWGui::JournalViewModel : IJournalViewModel
} }
}; };
void visit_journal_entries (quest_id questId, std::function <void (IJournalEntry const &)> visitor) const void visit_journal_entries (quest_id questId, boost::function <void (IJournalEntry const &)> visitor) const
{ {
auto journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
if (questId != 0) if (questId != 0)
{ {
MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId); MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId);
for(auto i = journal->begin(); i != journal->end (); ++i) for(MWBase::Journal::TEntryIter i = journal->begin(); i != journal->end (); ++i)
{ {
for (auto j = quest->begin (); j != quest->end (); ++j) for (MWDialogue::Topic::TEntryIter j = quest->begin (); j != quest->end (); ++j)
{ {
if (i->mInfoId == *j) if (i->mInfoId == *j)
visitor (journal_entry <decltype (i)> (this, i)); visitor (journal_entry <MWBase::Journal::TEntryIter> (this, i));
} }
} }
} }
else else
{ {
for(auto i = journal->begin(); i != journal->end (); ++i) for(MWBase::Journal::TEntryIter i = journal->begin(); i != journal->end (); ++i)
visitor (journal_entry <decltype (i)> (this, i)); visitor (journal_entry <MWBase::Journal::TEntryIter> (this, i));
} }
} }
void visit_topics (std::function <void (topic_id, utf8_span)> visitor) const void visit_topics (boost::function <void (topic_id, utf8_span)> visitor) const
{ {
throw std::runtime_error ("not implemented"); throw std::runtime_error ("not implemented");
} }
void visit_topic_name (topic_id topicId, std::function <void (utf8_span)> visitor) const void visit_topic_name (topic_id topicId, boost::function <void (utf8_span)> visitor) const
{ {
auto & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId); MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
visitor (to_utf8_span (Topic.getName ())); visitor (to_utf8_span (Topic.getName ()));
} }
void visit_topic_names_starting_with (int character, std::function < void (topic_id , utf8_span) > visitor) const void visit_topic_names_starting_with (int character, boost::function < void (topic_id , utf8_span) > visitor) const
{ {
auto journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
for (auto i = journal->topicBegin (); i != journal->topicEnd (); ++i) for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i)
{ {
if (i->first [0] != std::tolower (character, Locale)) if (i->first [0] != std::tolower (character, Locale))
continue; continue;
@ -373,42 +376,39 @@ struct MWGui::JournalViewModel : IJournalViewModel
} }
void visit_topic_entries (topic_id topicId, std::function <void (ITopicEntry const &)> visitor) const struct topicEntry : base_entry <MWDialogue::Topic::TEntryIter, ITopicEntry>
{ {
auto & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId); MWDialogue::Topic const & Topic;
for (auto i = Topic.begin (); i != Topic.end (); ++i) mutable std::string source_buffer;
topicEntry (JournalViewModel const * Model, MWDialogue::Topic const & Topic, iterator_t itr) :
base_entry (Model, itr), Topic (Topic)
{}
std::string getText () const
{ {
typedef decltype (Topic.begin()) iterator_t; return Topic.getEntry (*itr).getText(MWBase::Environment::get().getWorld()->getStore());
struct entry : base_entry <iterator_t, ITopicEntry>
{
MWDialogue::Topic const & Topic;
mutable std::string source_buffer;
entry (JournalViewModel const * Model, MWDialogue::Topic const & Topic, iterator_t itr) :
base_entry (Model, itr), Topic (Topic)
{}
std::string getText () const
{
return Topic.getEntry (*itr).getText(MWBase::Environment::get().getWorld()->getStore());
}
utf8_span source () const
{
if (source_buffer.empty ())
source_buffer = "someone";
return to_utf8_span (source_buffer);
}
};
visitor (entry (this, Topic, i));
} }
utf8_span source () const
{
if (source_buffer.empty ())
source_buffer = "someone";
return to_utf8_span (source_buffer);
}
};
void visit_topic_entries (topic_id topicId, boost::function <void (ITopicEntry const &)> visitor) const
{
typedef MWDialogue::Topic::TEntryIter iterator_t;
MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
for (iterator_t i = Topic.begin (); i != Topic.end (); ++i)
visitor (topicEntry (this, Topic, i));
} }
}; };
@ -468,5 +468,5 @@ static void injectMonthName (std::ostream & os, int month)
IJournalViewModel::ptr IJournalViewModel::create () IJournalViewModel::ptr IJournalViewModel::create ()
{ {
return std::make_shared <JournalViewModel> (); return boost::make_shared <JournalViewModel> ();
} }

View file

@ -5,6 +5,8 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <platform/stdint.h> #include <platform/stdint.h>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
namespace MWGui namespace MWGui
{ {
@ -16,7 +18,7 @@ namespace MWGui
/// game data store. /// game data store.
struct IJournalViewModel struct IJournalViewModel
{ {
typedef std::shared_ptr <IJournalViewModel> ptr; typedef boost::shared_ptr <IJournalViewModel> ptr;
typedef intptr_t quest_id; typedef intptr_t quest_id;
typedef intptr_t topic_id; typedef intptr_t topic_id;
@ -36,7 +38,7 @@ namespace MWGui
/// Visits each subset of text in the body, delivering the beginning /// Visits each subset of text in the body, delivering the beginning
/// and end of the span relative to the body, and a valid topic ID if /// and end of the span relative to the body, and a valid topic ID if
/// the span represents a keyword, or zero if not. /// the span represents a keyword, or zero if not.
virtual void visit_spans (std::function <void (topic_id, size_t, size_t)> visitor) const = 0; virtual void visit_spans (boost::function <void (topic_id, size_t, size_t)> visitor) const = 0;
}; };
/// An interface to topic data. /// An interface to topic data.
@ -66,22 +68,22 @@ namespace MWGui
virtual bool is_empty () const = 0; virtual bool is_empty () const = 0;
/// provides access to the name of the quest with the specified identifier /// provides access to the name of the quest with the specified identifier
virtual void visit_quest_name (topic_id topicId, std::function <void (utf8_span)> visitor) const = 0; virtual void visit_quest_name (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0;
/// walks the active and optionally completed, quests providing the quest id and name /// walks the active and optionally completed, quests providing the quest id and name
virtual void visit_quest_names (bool active_only, std::function <void (quest_id, utf8_span)> visitor) const = 0; virtual void visit_quest_names (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const = 0;
/// walks over the journal entries related to the specified quest identified by its id /// walks over the journal entries related to the specified quest identified by its id
virtual void visit_journal_entries (quest_id questId, std::function <void (IJournalEntry const &)> visitor) const = 0; virtual void visit_journal_entries (quest_id questId, boost::function <void (IJournalEntry const &)> visitor) const = 0;
/// provides the name of the topic specified by its id /// provides the name of the topic specified by its id
virtual void visit_topic_name (topic_id topicId, std::function <void (utf8_span)> visitor) const = 0; virtual void visit_topic_name (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0;
/// walks over the topics whose names start with the specified character providing the topics id and name /// walks over the topics whose names start with the specified character providing the topics id and name
virtual void visit_topic_names_starting_with (int character, std::function < void (topic_id , utf8_span) > visitor) const = 0; virtual void visit_topic_names_starting_with (int character, boost::function < void (topic_id , utf8_span) > visitor) const = 0;
/// walks over the topic entries for the topic specified by its identifier /// walks over the topic entries for the topic specified by its identifier
virtual void visit_topic_entries (topic_id topicId, std::function <void (ITopicEntry const &)> visitor) const = 0; virtual void visit_topic_entries (topic_id topicId, boost::function <void (ITopicEntry const &)> visitor) const = 0;
// create an instance of the default journal view model implementation // create an instance of the default journal view model implementation
static ptr create (); static ptr create ();

View file

@ -10,6 +10,8 @@
#include <stack> #include <stack>
#include <string> #include <string>
#include <utility> #include <utility>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include "boost/lexical_cast.hpp" #include "boost/lexical_cast.hpp"
#include "bookpage.hpp" #include "bookpage.hpp"
@ -24,11 +26,10 @@ using namespace MWGui;
namespace namespace
{ {
#define CONTROL_ID(name) \ #define CONTROL_ID(name) \
static char const name [] = #name; static char const name [] = #name
CONTROL_ID(OptionsOverlay) CONTROL_ID(OptionsOverlay);
CONTROL_ID(OptionsBTN);
CONTROL_ID(OptionsBTN)
CONTROL_ID(PrevPageBTN); CONTROL_ID(PrevPageBTN);
CONTROL_ID(NextPageBTN); CONTROL_ID(NextPageBTN);
CONTROL_ID(CloseBTN); CONTROL_ID(CloseBTN);
@ -38,8 +39,8 @@ namespace
CONTROL_ID(CancelBTN); CONTROL_ID(CancelBTN);
CONTROL_ID(ShowAllBTN); CONTROL_ID(ShowAllBTN);
CONTROL_ID(ShowActiveBTN); CONTROL_ID(ShowActiveBTN);
CONTROL_ID(PageOneNum) CONTROL_ID(PageOneNum);
CONTROL_ID(PageTwoNum) CONTROL_ID(PageTwoNum);
CONTROL_ID(TopicsList); CONTROL_ID(TopicsList);
CONTROL_ID(TopicsPage); CONTROL_ID(TopicsPage);
CONTROL_ID(QuestsList); CONTROL_ID(QuestsList);
@ -116,7 +117,9 @@ namespace
adviseButtonClick (ShowActiveBTN, &JournalWindow::notifyShowActive); adviseButtonClick (ShowActiveBTN, &JournalWindow::notifyShowActive);
{ {
auto callback = std::bind (&JournalWindow::notifyTopicClicked, this, std::placeholders::_1); IBookPage::click_callback callback;
callback = boost::bind (&JournalWindow::notifyTopicClicked, this, _1);
getPage (TopicsPage)->adviseLinkClicked (callback); getPage (TopicsPage)->adviseLinkClicked (callback);
getPage (LeftBookPage)->adviseLinkClicked (callback); getPage (LeftBookPage)->adviseLinkClicked (callback);
@ -124,14 +127,18 @@ namespace
} }
{ {
auto callback = std::bind (&JournalWindow::notifyIndexLinkClicked, this, std::placeholders::_1); IBookPage::click_callback callback;
callback = boost::bind (&JournalWindow::notifyIndexLinkClicked, this, _1);
getPage (LeftTopicIndex)->adviseLinkClicked (callback); getPage (LeftTopicIndex)->adviseLinkClicked (callback);
getPage (RightTopicIndex)->adviseLinkClicked (callback); getPage (RightTopicIndex)->adviseLinkClicked (callback);
} }
{ {
auto callback = std::bind (&JournalWindow::notifyQuestClicked, this, std::placeholders::_1); IBookPage::click_callback callback;
callback = boost::bind (&JournalWindow::notifyQuestClicked, this, _1);
getPage (QuestsPage)->adviseLinkClicked (callback); getPage (QuestsPage)->adviseLinkClicked (callback);
} }
@ -164,8 +171,8 @@ namespace
getPage (LeftBookPage)->showPage (book (), 0); getPage (LeftBookPage)->showPage (book (), 0);
getPage (RightBookPage)->showPage (book (), 0); getPage (RightBookPage)->showPage (book (), 0);
decltype (mStates) clr; while (!mStates.empty ())
mStates.swap (clr); mStates.pop ();
mTopicIndexBook.reset (); mTopicIndexBook.reset ();
@ -272,7 +279,7 @@ namespace
void notifyTopicClicked (intptr_t linkId) void notifyTopicClicked (intptr_t linkId)
{ {
auto topicBook = createTopicBook (linkId); book topicBook = createTopicBook (linkId);
if (mStates.size () > 1) if (mStates.size () > 1)
replaceBook (topicBook, 0); replaceBook (topicBook, 0);
@ -286,7 +293,7 @@ namespace
void notifyQuestClicked (intptr_t questId) void notifyQuestClicked (intptr_t questId)
{ {
auto Book = createQuestBook (questId); book Book = createQuestBook (questId);
if (mStates.size () > 1) if (mStates.size () > 1)
replaceBook (Book, 0); replaceBook (Book, 0);
@ -317,7 +324,7 @@ namespace
void showList (char const * ListId, char const * PageId, book book) void showList (char const * ListId, char const * PageId, book book)
{ {
auto size = book->getSize (); std::pair <int, int> size = book->getSize ();
getPage (PageId)->showPage (book, 0); getPage (PageId)->showPage (book, 0);
@ -388,8 +395,8 @@ namespace
{ {
if (!mStates.empty ()) if (!mStates.empty ())
{ {
auto & Page = mStates.top ().mPage; int & Page = mStates.top ().mPage;
auto Book = mStates.top ().mBook; book Book = mStates.top ().mBook;
if (Page < Book->pageCount () - 2) if (Page < Book->pageCount () - 2)
{ {
@ -403,7 +410,7 @@ namespace
{ {
if (!mStates.empty ()) if (!mStates.empty ())
{ {
auto & Page = mStates.top ().mPage; int & Page = mStates.top ().mPage;
if(Page > 0) if(Page > 0)
{ {

View file

@ -2,6 +2,7 @@
#define MWGUI_JOURNAL_H #define MWGUI_JOURNAL_H
#include <memory> #include <memory>
#include <boost/shared_ptr.hpp>
namespace MWBase { class WindowManager; } namespace MWBase { class WindowManager; }
@ -12,7 +13,7 @@ namespace MWGui
struct IJournalWindow struct IJournalWindow
{ {
/// construct a new instance of the one JournalWindow implementation /// construct a new instance of the one JournalWindow implementation
static IJournalWindow * create (std::shared_ptr <IJournalViewModel> Model); static IJournalWindow * create (boost::shared_ptr <IJournalViewModel> Model);
/// destroy this instance of the JournalWindow implementation /// destroy this instance of the JournalWindow implementation
virtual ~IJournalWindow () {}; virtual ~IJournalWindow () {};

View file

@ -65,7 +65,7 @@ public:
if (octets > 5) if (octets > 5)
return std::make_pair (sBadChar(), cur); return std::make_pair (sBadChar(), cur);
auto eoc = cur + octets; point eoc = cur + octets;
if (eoc > end) if (eoc > end)
return std::make_pair (sBadChar(), cur); return std::make_pair (sBadChar(), cur);