port code to C++03

pull/16/head
Nathan Jeffords 12 years ago
parent 6e7c9ebbe6
commit c7ede9b523

@ -7,6 +7,9 @@
#include "MyGUI_FactoryManager.h"
#include <platform/stdint.h>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <components/misc/utf8stream.hpp>
@ -104,7 +107,7 @@ struct MWGui::TypesetBook : ITypesetBook
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)
return range (utf8_point (NULL), utf8_point (NULL));
@ -125,17 +128,17 @@ struct MWGui::TypesetBook : ITypesetBook
template <typename visitor>
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)
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)
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)
Visitor (*i, *j, *k);
}
@ -148,23 +151,23 @@ struct MWGui::TypesetBook : ITypesetBook
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)
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)
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)
continue;
@ -179,7 +182,7 @@ struct MWGui::TypesetBook : ITypesetBook
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)
return i->Font;
return NULL;
@ -191,7 +194,7 @@ struct MWGui::TypesetBook : ITypesetBook
struct TypesetBook::Typesetter : IBookTypesetter
{
typedef TypesetBook book;
typedef std::shared_ptr <book> book_ptr;
typedef boost::shared_ptr <book> book_ptr;
int mPageWidth;
int mPageHeight;
@ -212,7 +215,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
mCurrentAlignment (alignLeft),
mCurrentContent (NULL)
{
Book = std::make_shared <book> ();
Book = boost::make_shared <book> ();
}
virtual ~Typesetter ()
@ -221,11 +224,11 @@ struct TypesetBook::Typesetter : IBookTypesetter
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))
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.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)
{
auto BaseStyle = dynamic_cast <style*> (_BaseStyle);
style* BaseStyle = dynamic_cast <style*> (_BaseStyle);
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))
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.HotColour = HoverColour;
@ -258,14 +261,14 @@ struct TypesetBook::Typesetter : IBookTypesetter
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);
}
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)
mCurrentContent = &(*i);
@ -323,14 +326,14 @@ struct TypesetBook::Typesetter : IBookTypesetter
int curPageStart = 0;
int curPageStop = 0;
auto sa = mSectionAlignment.begin ();
for (auto i = Book->Sections.begin (); i != Book->Sections.end (); ++i, ++sa)
std::vector <alignment>::iterator sa = mSectionAlignment.begin ();
for (sections::iterator i = Book->Sections.begin (); i != Book->Sections.end (); ++i, ++sa)
{
// 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 ();
auto excess = mPageWidth - width;
int width = j->Rect.width ();
int excess = mPageWidth - width;
switch (*sa)
{
@ -349,8 +352,8 @@ struct TypesetBook::Typesetter : IBookTypesetter
curPageStop = i->Rect.top;
}
auto spaceLeft = mPageHeight - (curPageStop - curPageStart);
auto sectionHeight = i->Rect.height ();
int spaceLeft = mPageHeight - (curPageStop - curPageStart);
int sectionHeight = i->Rect.height ();
if (sectionHeight <= mPageHeight)
{
@ -380,7 +383,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
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);
@ -398,27 +401,27 @@ struct TypesetBook::Typesetter : IBookTypesetter
int space_width = 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 ()))
{
auto gi = Style->Font->getGlyphInfo (stream.peek ());
GlyphInfo* gi = Style->Font->getGlyphInfo (stream.peek ());
space_width += gi->advance;
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 ()))
{
auto gi = Style->Font->getGlyphInfo (stream.peek ());
GlyphInfo* gi = Style->Font->getGlyphInfo (stream.peek ());
word_width += gi->advance + gi->bearingX;
word_height = line_height;
++character_count;
stream.consume ();
}
auto extent = stream.current ();
utf8_stream::point extent = stream.current ();
if (lead == extent)
break;
@ -477,7 +480,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
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 ());
Run = &Line->Runs.back ();
@ -500,7 +503,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
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
@ -624,7 +627,7 @@ namespace
void emit_glyph (wchar_t ch)
{
auto gi = mFont->getGlyphInfo (ch);
GlyphInfo* gi = mFont->getGlyphInfo (ch);
FloatRect vr;
@ -643,7 +646,7 @@ namespace
void emit_space (wchar_t ch)
{
auto gi = mFont->getGlyphInfo (ch);
GlyphInfo* gi = mFont->getGlyphInfo (ch);
mCursor.left += gi->bearingX + gi->advance;
}
@ -662,7 +665,7 @@ namespace
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->y = pt.top ;
@ -743,14 +746,15 @@ public:
style* mFocusItem;
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;
ILayerNode* mNode;
std::map <TextFormat::id, TextFormat*> mActiveTextFormats;
typedef std::map <TextFormat::id, TextFormat*> active_text_formats;
active_text_formats mActiveTextFormats;
PageDisplay ()
{
@ -763,9 +767,9 @@ public:
{
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);
}
@ -790,7 +794,7 @@ public:
_left -= mCroppedParent->getAbsoluteLeft ();
_top -= mCroppedParent->getAbsoluteTop ();
auto Hit = mBook->hitTest (_left, view_top + _top);
style * Hit = mBook->hitTest (_left, view_top + _top);
if (mLastDown == MouseButton::None)
{
@ -807,7 +811,7 @@ public:
else
if (mFocusItem != 0)
{
auto newItemActive = Hit == mFocusItem;
bool newItemActive = Hit == mFocusItem;
if (newItemActive != mItemActive)
{
@ -847,9 +851,9 @@ public:
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;
@ -864,14 +868,14 @@ public:
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)
{
mFocusItem = nullptr;
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)
i->second->destroyDrawItem (mNode);
@ -910,7 +914,7 @@ public:
if (mBook && mPage != newPage)
{
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);
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;
active_text_formats::iterator j = this_->mActiveTextFormats.find (Font);
if (j == mActiveTextFormats.end ())
if (j == this_->mActiveTextFormats.end ())
{
auto textFormat = new TextFormat (Font, this);
TextFormat * textFormat = new TextFormat (Font, this_);
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;
}
};
});
void createActiveFormats (boost::shared_ptr <TypesetBook> newBook)
{
newBook->visit_runs (0, 0x7FFFFFFF, createActiveFormat (this));
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);
}
@ -971,7 +983,7 @@ public:
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);
}
}
@ -982,34 +994,25 @@ public:
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);
}
/*
queue up rendering operations for this text format
*/
void doRender(TextFormat & textFormat)
struct renderRun
{
if (!mVisible)
return;
auto vertices = textFormat.mRenderItem->getCurrentVertexBuffer();
render_xform renderXform (mCroppedParent, textFormat.mRenderItem->getRenderTarget()->getInfo());
PageDisplay * this_;
glyph_stream &glyphStream;
glyph_stream glyphStream (textFormat.mFont, mCoord.left, mCoord.top-view_top,
-1 /*mNode->getNodeDepth()*/, vertices, renderXform);
auto visit_top = (std::max) (view_top, view_top + int (renderXform.clipTop ));
auto visit_bottom = (std::min) (view_bottom, view_top + int (renderXform.clipBottom));
renderRun (PageDisplay * this_, glyph_stream &glyphStream) :
this_(this_), glyphStream (glyphStream)
{
}
mBook->visit_runs (visit_top, visit_bottom, textFormat.mFont,
[this, &glyphStream] (section const & Section, line const & Line, run const & Run)
void operator () (section const & Section, line const & Line, run const & Run) const
{
bool isActive = Run.Style->InteractiveId && (Run.Style == mFocusItem);
bool isActive = Run.Style->InteractiveId && (Run.Style == this_->mFocusItem);
Colour colour = isActive ? (mItemActive ? Run.Style->ActiveColour: Run.Style->HotColour) : Run.Style->NormalColour;
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);
@ -1017,7 +1020,7 @@ public:
while (!stream.eof ())
{
auto code_point = stream.consume ();
utf8_stream::unicode_char code_point = stream.consume ();
if (!ucs_space (code_point))
glyphStream.emit_glyph (code_point);
@ -1025,7 +1028,27 @@ public:
glyphStream.emit_space (code_point);
}
}
);
};
/*
queue up rendering operations for this text format
*/
void doRender(TextFormat & textFormat)
{
if (!mVisible)
return;
Vertex* vertices = textFormat.mRenderItem->getCurrentVertexBuffer();
render_xform renderXform (mCroppedParent, textFormat.mRenderItem->getRenderTarget()->getInfo());
glyph_stream glyphStream (textFormat.mFont, mCoord.left, mCoord.top-view_top,
-1 /*mNode->getNodeDepth()*/, vertices, renderXform);
int visit_top = (std::max) (view_top, view_top + int (renderXform.clipTop ));
int visit_bottom = (std::min) (view_bottom, view_top + int (renderXform.clipBottom));
mBook->visit_runs (visit_top, visit_bottom, textFormat.mFont, renderRun (this, glyphStream));
textFormat.mRenderItem->setLastVertexCount(glyphStream.end () - vertices);
}
@ -1043,14 +1066,14 @@ public:
_checkMargin ();
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);
}
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);
mNode = NULL;
@ -1066,15 +1089,15 @@ public:
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);
else
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;
}
@ -1082,16 +1105,16 @@ public:
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:
void onMouseLostFocus(Widget* _new)
{
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{
pd->onMouseLostFocus ();
}
@ -1101,7 +1124,7 @@ protected:
void onMouseMove(int _left, int _top)
{
if (auto pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{
pd->onMouseMove (_left, _top);
}
@ -1111,7 +1134,7 @@ protected:
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);
}
@ -1121,7 +1144,7 @@ protected:
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);
}
@ -1132,7 +1155,7 @@ protected:
void IBookPage::registerMyGUIComponents ()
{
auto & factory = FactoryManager::getInstance();
FactoryManager & factory = FactoryManager::getInstance();
factory.registerFactory<BookPage>("Widget");
factory.registerFactory<PageDisplay>("BasisSkin");

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

@ -37,7 +37,7 @@ namespace
void operator () (intptr_t topicId, size_t begin, size_t end)
{
auto style = body_style;
IBookTypesetter::IStyle* style = body_style;
if (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)
{
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->lineBreak ();
@ -169,7 +169,7 @@ namespace
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->lineBreak ();
@ -186,17 +186,17 @@ JournalBooks::JournalBooks (IJournalViewModel::ptr Model) :
book JournalBooks::createEmptyJournalBook ()
{
auto typesetter = createTypesetter ();
IBookTypesetter::ptr typesetter = createTypesetter ();
auto header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
typesetter->write (header, to_utf8_span ("You have no journal entries!"));
typesetter->lineBreak ();
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);
auto test = typesetter->createStyle ("MonoFont", MyGUI::Colour::Blue);
IBookTypesetter::IStyle* big = typesetter->createStyle ("EB Garamond 24", MyGUI::Colour::Black);
IBookTypesetter::IStyle* test = typesetter->createStyle ("MonoFont", MyGUI::Colour::Blue);
typesetter->sectionBreak (20);
typesetter->write (body, to_utf8_span (
@ -228,10 +228,10 @@ book JournalBooks::createEmptyJournalBook ()
book JournalBooks::createJournalBook ()
{
auto typesetter = createTypesetter ();
IBookTypesetter::ptr typesetter = createTypesetter ();
auto header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_journal_entries (0, addJournalEntry (typesetter, body, header, true));
@ -240,14 +240,14 @@ book JournalBooks::createJournalBook ()
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));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
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));
@ -256,10 +256,10 @@ book JournalBooks::createTopicBook (uintptr_t topicId)
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));
auto body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_quest_name (questId, addQuestName (typesetter, header));
@ -270,11 +270,11 @@ book JournalBooks::createQuestBook (uintptr_t questId)
book JournalBooks::createTopicIndexBook ()
{
auto typesetter = IBookTypesetter::create (92, 250);
IBookTypesetter::ptr typesetter = IBookTypesetter::create (92, 250);
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)
{
@ -284,7 +284,7 @@ book JournalBooks::createTopicIndexBook ()
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)
typesetter->sectionBreak ();
@ -298,8 +298,8 @@ book JournalBooks::createTopicIndexBook ()
book JournalBooks::createTopicIndexBook (char character)
{
auto typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
auto style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
IBookTypesetter::IStyle* style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_topic_names_starting_with (character, addTopicLink (typesetter, style));
@ -308,8 +308,8 @@ book JournalBooks::createTopicIndexBook (char character)
book JournalBooks::createQuestIndexBook (bool activeOnly)
{
auto typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
auto base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
IBookTypesetter::IStyle* base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_quest_names (activeOnly, addQuestLink (typesetter, base));

@ -11,6 +11,7 @@
#include <map>
#include <sstream>
#include <boost/make_shared.hpp>
using namespace MWGui;
@ -34,7 +35,7 @@ public:
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 ()
@ -45,21 +46,21 @@ public:
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
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
if (candidate == Root.Children.end ())
continue;
// see how far the match goes
auto j = i;
point j = i;
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 ())
break;
@ -72,7 +73,7 @@ public:
continue;
// 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 ())
{
@ -111,14 +112,14 @@ private:
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 ())
{
Entry.Children [ch].Value = std::move (Value);
Entry.Children [ch].Keyword = std::move (Keyword);
Entry.Children [ch].Value = /*std::move*/ (Value);
Entry.Children [ch].Keyword = /*std::move*/ (Keyword);
}
else
{
@ -127,18 +128,18 @@ private:
if (Keyword == j->second.Keyword)
throw std::runtime_error ("duplicate keyword inserted");
auto pushValue = std::move (j->second.Value);
auto pushKeyword = std::move (j->second.Keyword);
value_t pushValue = /*std::move*/ (j->second.Value);
string_t pushKeyword = /*std::move*/ (j->second.Keyword);
j->second.Keyword.clear ();
if (Depth >= pushKeyword.size ())
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)
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 ());
}
@ -190,9 +191,9 @@ struct MWGui::JournalViewModel : IJournalViewModel
{
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_loaded = true;
@ -203,14 +204,16 @@ struct MWGui::JournalViewModel : IJournalViewModel
bool is_empty () const
{
auto journal = MWBase::Environment::get().getJournal();
MWBase::Journal * journal = MWBase::Environment::get().getJournal();
return journal->begin () == journal->end ();
}
template <typename iterator_t, typename IInterface>
template <typename t_iterator, typename IInterface>
struct base_entry : IInterface
{
typedef t_iterator iterator_t;
iterator_t itr;
JournalViewModel const * Model;
@ -241,7 +244,7 @@ struct MWGui::JournalViewModel : IJournalViewModel
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 ();
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 ())
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);
auto name = quest->getName ();
std::string name = quest->getName ();
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)
{
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)
visitor (journal_entry <decltype (i)> (this, i));
visitor (journal_entry <MWBase::Journal::TEntryIter> (this, i));
}
}
}
else
{
for(auto i = journal->begin(); i != journal->end (); ++i)
visitor (journal_entry <decltype (i)> (this, i));
for(MWBase::Journal::TEntryIter i = journal->begin(); i != journal->end (); ++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");
}
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 ()));
}
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))
continue;
@ -373,22 +376,13 @@ struct MWGui::JournalViewModel : IJournalViewModel
}
void visit_topic_entries (topic_id topicId, std::function <void (ITopicEntry const &)> visitor) const
{
auto & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
for (auto i = Topic.begin (); i != Topic.end (); ++i)
{
typedef decltype (Topic.begin()) iterator_t;
struct entry : base_entry <iterator_t, ITopicEntry>
struct topicEntry : base_entry <MWDialogue::Topic::TEntryIter, ITopicEntry>
{
MWDialogue::Topic const & Topic;
mutable std::string source_buffer;
entry (JournalViewModel const * Model, MWDialogue::Topic const & Topic, iterator_t itr) :
topicEntry (JournalViewModel const * Model, MWDialogue::Topic const & Topic, iterator_t itr) :
base_entry (Model, itr), Topic (Topic)
{}
@ -407,8 +401,14 @@ struct MWGui::JournalViewModel : IJournalViewModel
};
visitor (entry (this, Topic, i));
}
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 ()
{
return std::make_shared <JournalViewModel> ();
return boost::make_shared <JournalViewModel> ();
}

@ -5,6 +5,8 @@
#include <memory>
#include <functional>
#include <platform/stdint.h>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
namespace MWGui
{
@ -16,7 +18,7 @@ namespace MWGui
/// game data store.
struct IJournalViewModel
{
typedef std::shared_ptr <IJournalViewModel> ptr;
typedef boost::shared_ptr <IJournalViewModel> ptr;
typedef intptr_t quest_id;
typedef intptr_t topic_id;
@ -36,7 +38,7 @@ namespace MWGui
/// 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
/// 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.
@ -66,22 +68,22 @@ namespace MWGui
virtual bool is_empty () const = 0;
/// 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
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
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
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
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
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
static ptr create ();

@ -10,6 +10,8 @@
#include <stack>
#include <string>
#include <utility>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include "boost/lexical_cast.hpp"
#include "bookpage.hpp"
@ -24,11 +26,10 @@ using namespace MWGui;
namespace
{
#define CONTROL_ID(name) \
static char const name [] = #name;
static char const name [] = #name
CONTROL_ID(OptionsOverlay)
CONTROL_ID(OptionsBTN)
CONTROL_ID(OptionsOverlay);
CONTROL_ID(OptionsBTN);
CONTROL_ID(PrevPageBTN);
CONTROL_ID(NextPageBTN);
CONTROL_ID(CloseBTN);
@ -38,8 +39,8 @@ namespace
CONTROL_ID(CancelBTN);
CONTROL_ID(ShowAllBTN);
CONTROL_ID(ShowActiveBTN);
CONTROL_ID(PageOneNum)
CONTROL_ID(PageTwoNum)
CONTROL_ID(PageOneNum);
CONTROL_ID(PageTwoNum);
CONTROL_ID(TopicsList);
CONTROL_ID(TopicsPage);
CONTROL_ID(QuestsList);
@ -116,7 +117,9 @@ namespace
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 (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 (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);
}
@ -164,8 +171,8 @@ namespace
getPage (LeftBookPage)->showPage (book (), 0);
getPage (RightBookPage)->showPage (book (), 0);
decltype (mStates) clr;
mStates.swap (clr);
while (!mStates.empty ())
mStates.pop ();
mTopicIndexBook.reset ();
@ -272,7 +279,7 @@ namespace
void notifyTopicClicked (intptr_t linkId)
{
auto topicBook = createTopicBook (linkId);
book topicBook = createTopicBook (linkId);
if (mStates.size () > 1)
replaceBook (topicBook, 0);
@ -286,7 +293,7 @@ namespace
void notifyQuestClicked (intptr_t questId)
{
auto Book = createQuestBook (questId);
book Book = createQuestBook (questId);
if (mStates.size () > 1)
replaceBook (Book, 0);
@ -317,7 +324,7 @@ namespace
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);
@ -388,8 +395,8 @@ namespace
{
if (!mStates.empty ())
{
auto & Page = mStates.top ().mPage;
auto Book = mStates.top ().mBook;
int & Page = mStates.top ().mPage;
book Book = mStates.top ().mBook;
if (Page < Book->pageCount () - 2)
{
@ -403,7 +410,7 @@ namespace
{
if (!mStates.empty ())
{
auto & Page = mStates.top ().mPage;
int & Page = mStates.top ().mPage;
if(Page > 0)
{

@ -2,6 +2,7 @@
#define MWGUI_JOURNAL_H
#include <memory>
#include <boost/shared_ptr.hpp>
namespace MWBase { class WindowManager; }
@ -12,7 +13,7 @@ namespace MWGui
struct IJournalWindow
{
/// 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
virtual ~IJournalWindow () {};

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

Loading…
Cancel
Save