Fix some naming guidelines, fix topic index exception, fix exception in keyword search for some journal entries

pull/16/head
scrawl 12 years ago
parent 8bc59f8fe6
commit 3c68c87923

@ -23,18 +23,18 @@ namespace MWGui
using namespace MyGUI; using namespace MyGUI;
using namespace MWGui; using namespace MWGui;
static bool ucs_space (int code_point); static bool ucsSpace (int codePoint);
static bool ucs_line_break (int code_point); static bool ucsLineBreak (int codePoint);
static bool ucs_breaking_space (int code_point); static bool ucsBreakingSpace (int codePoint);
struct BookTypesetter::Style { virtual ~Style () {} }; struct BookTypesetter::Style { virtual ~Style () {} };
struct MWGui::TypesetBookImpl : TypesetBook struct MWGui::TypesetBookImpl : TypesetBook
{ {
typedef std::vector <uint8_t> content; typedef std::vector <uint8_t> Content;
typedef std::list <content> contents; typedef std::list <Content> Contents;
typedef utf8_stream::point utf8_point; typedef Utf8Stream::Point Utf8Point;
typedef std::pair <utf8_point, utf8_point> range; typedef std::pair <Utf8Point, Utf8Point> Range;
struct StyleImpl : BookTypesetter::Style struct StyleImpl : BookTypesetter::Style
{ {
@ -42,7 +42,7 @@ struct MWGui::TypesetBookImpl : TypesetBook
Colour mHotColour; Colour mHotColour;
Colour mActiveColour; Colour mActiveColour;
Colour mNormalColour; Colour mNormalColour;
interactive_id mInteractiveId; InteractiveId mInteractiveId;
bool match (IFont* tstFont, Colour tstHotColour, Colour tstActiveColour, Colour tstNormalColour, intptr_t tstInteractiveId) bool match (IFont* tstFont, Colour tstHotColour, Colour tstActiveColour, Colour tstNormalColour, intptr_t tstInteractiveId)
{ {
@ -66,56 +66,56 @@ struct MWGui::TypesetBookImpl : TypesetBook
} }
}; };
typedef std::list <StyleImpl> styles; typedef std::list <StyleImpl> Styles;
struct Run struct Run
{ {
StyleImpl* mStyle; StyleImpl* mStyle;
range mRange; Range mRange;
int mLeft, mRight; int mLeft, mRight;
int mPrintableChars; int mPrintableChars;
}; };
typedef std::vector <Run> runs; typedef std::vector <Run> Runs;
struct Line struct Line
{ {
runs mRuns; Runs mRuns;
IntRect mRect; IntRect mRect;
}; };
typedef std::vector <Line> lines; typedef std::vector <Line> Lines;
struct Section struct Section
{ {
lines mLines; Lines mLines;
IntRect mRect; IntRect mRect;
}; };
typedef std::vector <Section> sections; typedef std::vector <Section> Sections;
typedef std::pair <int, int> page; typedef std::pair <int, int> Page;
typedef std::vector <page> pages; typedef std::vector <Page> Pages;
pages mPages; Pages mPages;
sections mSections; Sections mSections;
contents mContents; Contents mContents;
styles mStyles; Styles mStyles;
IntRect mRect; IntRect mRect;
virtual ~TypesetBookImpl () {} virtual ~TypesetBookImpl () {}
range addContent (BookTypesetter::utf8_span Text) Range addContent (BookTypesetter::Utf8Span text)
{ {
contents::iterator i = mContents.insert (mContents.end (), content (Text.first, Text.second)); Contents::iterator i = mContents.insert (mContents.end (), Content (text.first, text.second));
if (i->size () == 0) if (i->size () == 0)
return range (utf8_point (NULL), utf8_point (NULL)); return Range (Utf8Point (NULL), Utf8Point (NULL));
utf8_point begin = &i->front (); Utf8Point begin = &i->front ();
utf8_point end = &i->front () + i->size (); Utf8Point end = &i->front () + i->size ();
return range (begin, end); return Range (begin, end);
} }
size_t pageCount () const { return mPages.size (); } size_t pageCount () const { return mPages.size (); }
@ -125,49 +125,49 @@ struct MWGui::TypesetBookImpl : TypesetBook
return std::make_pair (mRect.width (), mRect.height ()); return std::make_pair (mRect.width (), mRect.height ());
} }
template <typename visitor> template <typename Visitor>
void visitRuns (int top, int bottom, IFont* Font, visitor const & Visitor) const void visitRuns (int top, int bottom, IFont* Font, Visitor const & visitor) const
{ {
for (sections::const_iterator i = mSections.begin (); i != mSections.end (); ++i) for (Sections::const_iterator i = mSections.begin (); i != mSections.end (); ++i)
{ {
if (top >= mRect.bottom || bottom <= i->mRect.top) if (top >= mRect.bottom || bottom <= i->mRect.top)
continue; continue;
for (lines::const_iterator j = i->mLines.begin (); j != i->mLines.end (); ++j) for (Lines::const_iterator j = i->mLines.begin (); j != i->mLines.end (); ++j)
{ {
if (top >= j->mRect.bottom || bottom <= j->mRect.top) if (top >= j->mRect.bottom || bottom <= j->mRect.top)
continue; continue;
for (runs::const_iterator k = j->mRuns.begin (); k != j->mRuns.end (); ++k) for (Runs::const_iterator k = j->mRuns.begin (); k != j->mRuns.end (); ++k)
if (!Font || k->mStyle->mFont == Font) if (!Font || k->mStyle->mFont == Font)
Visitor (*i, *j, *k); visitor (*i, *j, *k);
} }
} }
} }
template <typename visitor> template <typename Visitor>
void visitRuns (int top, int bottom, visitor const & Visitor) const void visitRuns (int top, int bottom, Visitor const & visitor) const
{ {
visitRuns (top, bottom, NULL, Visitor); visitRuns (top, bottom, NULL, visitor);
} }
StyleImpl * hitTest (int left, int top) const StyleImpl * hitTest (int left, int top) const
{ {
for (sections::const_iterator i = mSections.begin (); i != mSections.end (); ++i) for (Sections::const_iterator i = mSections.begin (); i != mSections.end (); ++i)
{ {
if (top < i->mRect.top || top >= i->mRect.bottom) if (top < i->mRect.top || top >= i->mRect.bottom)
continue; continue;
int left1 = left - i->mRect.left; int left1 = left - i->mRect.left;
for (lines::const_iterator j = i->mLines.begin (); j != i->mLines.end (); ++j) for (Lines::const_iterator j = i->mLines.begin (); j != i->mLines.end (); ++j)
{ {
if (top < j->mRect.top || top >= j->mRect.bottom) if (top < j->mRect.top || top >= j->mRect.bottom)
continue; continue;
int left2 = left1 - j->mRect.left; int left2 = left1 - j->mRect.left;
for (runs::const_iterator k = j->mRuns.begin (); k != j->mRuns.end (); ++k) for (Runs::const_iterator k = j->mRuns.begin (); k != j->mRuns.end (); ++k)
{ {
if (left2 < k->mLeft || left2 >= k->mRight) if (left2 < k->mLeft || left2 >= k->mRight)
continue; continue;
@ -180,10 +180,10 @@ struct MWGui::TypesetBookImpl : TypesetBook
return nullptr; return nullptr;
} }
IFont* affectedFont (StyleImpl* Style) IFont* affectedFont (StyleImpl* style)
{ {
for (styles::iterator i = mStyles.begin (); i != mStyles.end (); ++i) for (Styles::iterator i = mStyles.begin (); i != mStyles.end (); ++i)
if (&*i == Style) if (&*i == style)
return i->mFont; return i->mFont;
return NULL; return NULL;
} }
@ -193,92 +193,92 @@ struct MWGui::TypesetBookImpl : TypesetBook
struct TypesetBookImpl::Typesetter : BookTypesetter struct TypesetBookImpl::Typesetter : BookTypesetter
{ {
typedef TypesetBookImpl book; typedef TypesetBookImpl Book;
typedef boost::shared_ptr <book> book_ptr; typedef boost::shared_ptr <Book> BookPtr;
int mPageWidth; int mPageWidth;
int mPageHeight; int mPageHeight;
book_ptr mBook; BookPtr mBook;
Section * mSection; Section * mSection;
Line * mLine; Line * mLine;
Run * mRun; Run * mRun;
std::vector <alignment> mSectionAlignment; std::vector <Alignment> mSectionAlignment;
book::content const * mCurrentContent; Book::Content const * mCurrentContent;
alignment mCurrentAlignment; Alignment mCurrentAlignment;
Typesetter (size_t Width, size_t Height) : Typesetter (size_t width, size_t height) :
mPageWidth (Width), mPageHeight(Height), mPageWidth (width), mPageHeight(height),
mSection (NULL), mLine (NULL), mRun (NULL), mSection (NULL), mLine (NULL), mRun (NULL),
mCurrentAlignment (alignLeft), mCurrentAlignment (AlignLeft),
mCurrentContent (NULL) mCurrentContent (NULL)
{ {
mBook = boost::make_shared <book> (); mBook = boost::make_shared <Book> ();
} }
virtual ~Typesetter () virtual ~Typesetter ()
{ {
} }
Style * createStyle (char const * FontName, Colour FontColour) Style * createStyle (char const * fontName, Colour fontColour)
{ {
for (styles::iterator i = mBook->mStyles.begin (); i != mBook->mStyles.end (); ++i) for (Styles::iterator i = mBook->mStyles.begin (); i != mBook->mStyles.end (); ++i)
if (i->match (FontName, FontColour, FontColour, FontColour, 0)) if (i->match (fontName, fontColour, fontColour, fontColour, 0))
return &*i; return &*i;
StyleImpl & style = *mBook->mStyles.insert (mBook->mStyles.end (), StyleImpl ()); StyleImpl & style = *mBook->mStyles.insert (mBook->mStyles.end (), StyleImpl ());
style.mFont = FontManager::getInstance().getByName(FontName); style.mFont = FontManager::getInstance().getByName(fontName);
style.mHotColour = FontColour; style.mHotColour = fontColour;
style.mActiveColour = FontColour; style.mActiveColour = fontColour;
style.mNormalColour = FontColour; style.mNormalColour = fontColour;
style.mInteractiveId = 0; style.mInteractiveId = 0;
return &style; return &style;
} }
Style* createHotStyle (Style* _BaseStyle, coulour NormalColour, coulour HoverColour, coulour ActiveColour, interactive_id Id, bool Unique) Style* createHotStyle (Style* baseStyle, Colour normalColour, Colour hoverColour, Colour activeColour, InteractiveId id, bool unique)
{ {
StyleImpl* BaseStyle = dynamic_cast <StyleImpl*> (_BaseStyle); StyleImpl* BaseStyle = dynamic_cast <StyleImpl*> (baseStyle);
if (!Unique) if (!unique)
for (styles::iterator i = mBook->mStyles.begin (); i != mBook->mStyles.end (); ++i) for (Styles::iterator i = mBook->mStyles.begin (); i != mBook->mStyles.end (); ++i)
if (i->match (BaseStyle->mFont, HoverColour, ActiveColour, NormalColour, Id)) if (i->match (BaseStyle->mFont, hoverColour, activeColour, normalColour, id))
return &*i; return &*i;
StyleImpl & style = *mBook->mStyles.insert (mBook->mStyles.end (), StyleImpl ()); StyleImpl & style = *mBook->mStyles.insert (mBook->mStyles.end (), StyleImpl ());
style.mFont = BaseStyle->mFont; style.mFont = BaseStyle->mFont;
style.mHotColour = HoverColour; style.mHotColour = hoverColour;
style.mActiveColour = ActiveColour; style.mActiveColour = activeColour;
style.mNormalColour = NormalColour; style.mNormalColour = normalColour;
style.mInteractiveId = Id; style.mInteractiveId = id;
return &style; return &style;
} }
void write (Style * _Style, utf8_span Text) void write (Style * style, Utf8Span text)
{ {
range text = mBook->addContent (Text); Range range = mBook->addContent (text);
write_impl (dynamic_cast <StyleImpl*> (_Style), text.first, text.second); writeImpl (dynamic_cast <StyleImpl*> (style), range.first, range.second);
} }
intptr_t add_content (utf8_span Text, bool Select) intptr_t addContent (Utf8Span text, bool select)
{ {
contents::iterator i = mBook->mContents.insert (mBook->mContents.end (), content (Text.first, Text.second)); Contents::iterator i = mBook->mContents.insert (mBook->mContents.end (), Content (text.first, text.second));
if (Select) if (select)
mCurrentContent = &(*i); mCurrentContent = &(*i);
return reinterpret_cast <intptr_t> (&(*i)); return reinterpret_cast <intptr_t> (&(*i));
} }
void select_content (intptr_t contentHandle) void selectContent (intptr_t contentHandle)
{ {
mCurrentContent = reinterpret_cast <content const *> (contentHandle); mCurrentContent = reinterpret_cast <Content const *> (contentHandle);
} }
void write (Style * style, size_t begin, size_t end) void write (Style * style, size_t begin, size_t end)
@ -287,10 +287,10 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
assert (end <= mCurrentContent->size ()); assert (end <= mCurrentContent->size ());
assert (begin <= mCurrentContent->size ()); assert (begin <= mCurrentContent->size ());
utf8_point begin_ = &mCurrentContent->front () + begin; Utf8Point begin_ = &mCurrentContent->front () + begin;
utf8_point end_ = &mCurrentContent->front () + end ; Utf8Point end_ = &mCurrentContent->front () + end ;
write_impl (dynamic_cast <StyleImpl*> (style), begin_, end_); writeImpl (dynamic_cast <StyleImpl*> (style), begin_, end_);
} }
void lineBreak (float margin) void lineBreak (float margin)
@ -314,23 +314,23 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
} }
} }
void setSectionAlignment (alignment sectionAlignment) void setSectionAlignment (Alignment sectionAlignment)
{ {
if (mSection != NULL) if (mSection != NULL)
mSectionAlignment.back () = sectionAlignment; mSectionAlignment.back () = sectionAlignment;
mCurrentAlignment = sectionAlignment; mCurrentAlignment = sectionAlignment;
} }
TypesetBook::ptr complete () TypesetBook::Ptr complete ()
{ {
int curPageStart = 0; int curPageStart = 0;
int curPageStop = 0; int curPageStop = 0;
std::vector <alignment>::iterator sa = mSectionAlignment.begin (); std::vector <Alignment>::iterator sa = mSectionAlignment.begin ();
for (sections::iterator i = mBook->mSections.begin (); i != mBook->mSections.end (); ++i, ++sa) for (Sections::iterator i = mBook->mSections.begin (); i != mBook->mSections.end (); ++i, ++sa)
{ {
// apply alignment to individual lines... // apply alignment to individual lines...
for (lines::iterator j = i->mLines.begin (); j != i->mLines.end (); ++j) for (Lines::iterator j = i->mLines.begin (); j != i->mLines.end (); ++j)
{ {
int width = j->mRect.width (); int width = j->mRect.width ();
int excess = mPageWidth - width; int excess = mPageWidth - width;
@ -338,9 +338,9 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
switch (*sa) switch (*sa)
{ {
default: default:
case alignLeft: j->mRect.left = 0; break; case AlignLeft: j->mRect.left = 0; break;
case alignCenter: j->mRect.left = excess/2; break; case AlignCenter: j->mRect.left = excess/2; break;
case alignRight: j->mRect.left = excess; break; case AlignRight: j->mRect.left = excess; break;
} }
j->mRect.right = j->mRect.left + width; j->mRect.right = j->mRect.left + width;
@ -361,7 +361,7 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
{ {
assert (curPageStart != curPageStop); assert (curPageStart != curPageStop);
mBook->mPages.push_back (page (curPageStart, curPageStop)); mBook->mPages.push_back (Page (curPageStart, curPageStop));
curPageStart = i->mRect.top; curPageStart = i->mRect.top;
curPageStop = i->mRect.bottom; curPageStop = i->mRect.bottom;
@ -376,20 +376,20 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
} }
if (curPageStart != curPageStop) if (curPageStart != curPageStop)
mBook->mPages.push_back (page (curPageStart, curPageStop)); mBook->mPages.push_back (Page (curPageStart, curPageStop));
return mBook; return mBook;
} }
void write_impl (StyleImpl * Style, utf8_stream::point _begin, utf8_stream::point _end) void writeImpl (StyleImpl * style, Utf8Stream::Point _begin, Utf8Stream::Point _end)
{ {
int line_height = Style->mFont->getDefaultHeight (); int line_height = style->mFont->getDefaultHeight ();
utf8_stream stream (_begin, _end); Utf8Stream stream (_begin, _end);
while (!stream.eof ()) while (!stream.eof ())
{ {
if (ucs_line_break (stream.peek ())) if (ucsLineBreak (stream.peek ()))
{ {
stream.consume (); stream.consume ();
mLine = NULL, mRun = NULL; mLine = NULL, mRun = NULL;
@ -401,27 +401,27 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
int space_width = 0; int space_width = 0;
int character_count = 0; int character_count = 0;
utf8_stream::point lead = stream.current (); Utf8Stream::Point lead = stream.current ();
while (!stream.eof () && !ucs_line_break (stream.peek ()) && ucs_breaking_space (stream.peek ())) while (!stream.eof () && !ucsLineBreak (stream.peek ()) && ucsBreakingSpace (stream.peek ()))
{ {
GlyphInfo* gi = Style->mFont->getGlyphInfo (stream.peek ()); GlyphInfo* gi = style->mFont->getGlyphInfo (stream.peek ());
space_width += gi->advance; space_width += gi->advance;
stream.consume (); stream.consume ();
} }
utf8_stream::point origin = stream.current (); Utf8Stream::Point origin = stream.current ();
while (!stream.eof () && !ucs_line_break (stream.peek ()) && !ucs_breaking_space (stream.peek ())) while (!stream.eof () && !ucsLineBreak (stream.peek ()) && !ucsBreakingSpace (stream.peek ()))
{ {
GlyphInfo* gi = Style->mFont->getGlyphInfo (stream.peek ()); GlyphInfo* gi = style->mFont->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 ();
} }
utf8_stream::point extent = stream.current (); Utf8Stream::Point extent = stream.current ();
if (lead == extent) if (lead == extent)
break; break;
@ -432,18 +432,18 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
{ {
mLine = NULL, mRun = NULL; mLine = NULL, mRun = NULL;
append_run (Style, origin, extent, extent - origin, word_width, mBook->mRect.bottom + word_height); append_run (style, origin, extent, extent - origin, word_width, mBook->mRect.bottom + word_height);
} }
else else
{ {
int top = mLine ? mLine->mRect.top : mBook->mRect.bottom; int top = mLine ? mLine->mRect.top : mBook->mRect.bottom;
append_run (Style, lead, extent, extent - origin, left + space_width + word_width, top + word_height); append_run (style, lead, extent, extent - origin, left + space_width + word_width, top + word_height);
} }
} }
} }
void append_run (StyleImpl * style, utf8_stream::point begin, utf8_stream::point end, int pc, int right, int bottom) void append_run (StyleImpl * style, Utf8Stream::Point begin, Utf8Stream::Point end, int pc, int right, int bottom)
{ {
if (mSection == NULL) if (mSection == NULL)
{ {
@ -501,7 +501,7 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
} }
}; };
BookTypesetter::ptr BookTypesetter::create (int pageWidth, int pageHeight) BookTypesetter::Ptr BookTypesetter::create (int pageWidth, int pageHeight)
{ {
return boost::make_shared <TypesetBookImpl::Typesetter> (pageWidth, pageHeight); return boost::make_shared <TypesetBookImpl::Typesetter> (pageWidth, pageHeight);
} }
@ -663,15 +663,15 @@ namespace
vertex (vr.right, vr.bottom, tr.right, tr.bottom); vertex (vr.right, vr.bottom, tr.right, tr.bottom);
} }
void vertex (float X, float Y, float U, float V) void vertex (float x, float y, float u, float v)
{ {
FloatPoint 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 ;
mVertices->z = mZ; mVertices->z = mZ;
mVertices->u = U; mVertices->u = u;
mVertices->v = V; mVertices->v = v;
mVertices->colour = mC; mVertices->colour = mC;
++mVertices; ++mVertices;
@ -690,19 +690,19 @@ protected:
struct TextFormat : ISubWidget struct TextFormat : ISubWidget
{ {
typedef IFont* id; typedef IFont* Id;
id mFont; Id mFont;
int mCountVertex; int mCountVertex;
ITexture* mTexture; ITexture* mTexture;
RenderItem* mRenderItem; RenderItem* mRenderItem;
PageDisplay * mDisplay; PageDisplay * mDisplay;
TextFormat (IFont* Id, PageDisplay * Display) : TextFormat (IFont* id, PageDisplay * display) :
mFont (Id), mFont (id),
mTexture (NULL), mTexture (NULL),
mRenderItem (NULL), mRenderItem (NULL),
mDisplay (Display), mDisplay (display),
mCountVertex (0) mCountVertex (0)
{ {
} }
@ -739,13 +739,13 @@ protected:
public: public:
typedef TypesetBookImpl::StyleImpl style; typedef TypesetBookImpl::StyleImpl Style;
typedef std::map <TextFormat::id, TextFormat*> active_text_formats; typedef std::map <TextFormat::Id, TextFormat*> ActiveTextFormats;
int mViewTop; int mViewTop;
int mViewBottom; int mViewBottom;
style* mFocusItem; Style* mFocusItem;
bool mItemActive; bool mItemActive;
MouseButton mLastDown; MouseButton mLastDown;
boost::function <void (intptr_t)> mLinkClicked; boost::function <void (intptr_t)> mLinkClicked;
@ -755,7 +755,7 @@ public:
size_t mPage; size_t mPage;
ILayerNode* mNode; ILayerNode* mNode;
active_text_formats mActiveTextFormats; ActiveTextFormats mActiveTextFormats;
PageDisplay () PageDisplay ()
{ {
@ -768,7 +768,7 @@ public:
{ {
IFont* Font = mBook->affectedFont (mFocusItem); IFont* Font = mBook->affectedFont (mFocusItem);
active_text_formats::iterator i = mActiveTextFormats.find (Font); ActiveTextFormats::iterator i = mActiveTextFormats.find (Font);
mNode->outOfDate (i->second->mRenderItem); mNode->outOfDate (i->second->mRenderItem);
} }
@ -785,15 +785,15 @@ public:
mItemActive = false; mItemActive = false;
} }
void onMouseMove (int _left, int _top) void onMouseMove (int left, int top)
{ {
if (!mBook) if (!mBook)
return; return;
_left -= mCroppedParent->getAbsoluteLeft (); left -= mCroppedParent->getAbsoluteLeft ();
_top -= mCroppedParent->getAbsoluteTop (); top -= mCroppedParent->getAbsoluteTop ();
style * Hit = mBook->hitTest (_left, mViewTop + _top); Style * Hit = mBook->hitTest (left, mViewTop + top);
if (mLastDown == MouseButton::None) if (mLastDown == MouseButton::None)
{ {
@ -821,36 +821,36 @@ public:
} }
} }
void onMouseButtonPressed (int _left, int _top, MouseButton _id) void onMouseButtonPressed (int left, int top, MouseButton id)
{ {
if (!mBook) if (!mBook)
return; return;
_left -= mCroppedParent->getAbsoluteLeft (); left -= mCroppedParent->getAbsoluteLeft ();
_top -= mCroppedParent->getAbsoluteTop (); top -= mCroppedParent->getAbsoluteTop ();
if (mLastDown == MouseButton::None) if (mLastDown == MouseButton::None)
{ {
mFocusItem = mBook->hitTest (_left, mViewTop + _top); mFocusItem = mBook->hitTest (left, mViewTop + top);
mItemActive = true; mItemActive = true;
dirtyFocusItem (); dirtyFocusItem ();
mLastDown = _id; mLastDown = id;
} }
} }
void onMouseButtonReleased(int _left, int _top, MouseButton _id) void onMouseButtonReleased(int left, int top, MouseButton id)
{ {
if (!mBook) if (!mBook)
return; return;
_left -= mCroppedParent->getAbsoluteLeft (); left -= mCroppedParent->getAbsoluteLeft ();
_top -= mCroppedParent->getAbsoluteTop (); top -= mCroppedParent->getAbsoluteTop ();
if (mLastDown == _id) if (mLastDown == id)
{ {
style * mItem = mBook->hitTest (_left, mViewTop + _top); Style * mItem = mBook->hitTest (left, mViewTop + top);
bool clicked = mFocusItem == mItem; bool clicked = mFocusItem == mItem;
@ -865,16 +865,16 @@ public:
} }
} }
void showPage (TypesetBook::ptr _Book, size_t newPage) void showPage (TypesetBook::Ptr book, size_t newPage)
{ {
boost::shared_ptr <TypesetBookImpl> newBook = boost::dynamic_pointer_cast <TypesetBookImpl> (_Book); boost::shared_ptr <TypesetBookImpl> newBook = boost::dynamic_pointer_cast <TypesetBookImpl> (book);
if (mBook != newBook) if (mBook != newBook)
{ {
mFocusItem = nullptr; mFocusItem = nullptr;
mItemActive = 0; mItemActive = 0;
for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (ActiveTextFormats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
{ {
if (mNode != NULL) if (mNode != NULL)
i->second->destroyDrawItem (mNode); i->second->destroyDrawItem (mNode);
@ -913,7 +913,7 @@ public:
if (mBook && mPage != newPage) if (mBook && mPage != newPage)
{ {
if (mNode != NULL) if (mNode != NULL)
for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (ActiveTextFormats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
mNode->outOfDate(i->second->mRenderItem); mNode->outOfDate(i->second->mRenderItem);
mPage = newPage; mPage = newPage;
@ -931,17 +931,17 @@ public:
} }
} }
struct createActiveFormat struct CreateActiveFormat
{ {
PageDisplay * this_; PageDisplay * this_;
createActiveFormat (PageDisplay * this_) : this_ (this_) {} CreateActiveFormat (PageDisplay * this_) : this_ (this_) {}
void operator () (Section const & Section, Line const & Line, Run const & Run) const void operator () (Section const & section, Line const & line, Run const & run) const
{ {
IFont* Font = Run.mStyle->mFont; IFont* Font = run.mStyle->mFont;
active_text_formats::iterator j = this_->mActiveTextFormats.find (Font); ActiveTextFormats::iterator j = this_->mActiveTextFormats.find (Font);
if (j == this_->mActiveTextFormats.end ()) if (j == this_->mActiveTextFormats.end ())
{ {
@ -952,16 +952,16 @@ public:
j = this_->mActiveTextFormats.insert (std::make_pair (Font, textFormat)).first; j = this_->mActiveTextFormats.insert (std::make_pair (Font, textFormat)).first;
} }
j->second->mCountVertex += Run.mPrintableChars * 6; j->second->mCountVertex += run.mPrintableChars * 6;
} }
}; };
void createActiveFormats (boost::shared_ptr <TypesetBookImpl> newBook) void createActiveFormats (boost::shared_ptr <TypesetBookImpl> newBook)
{ {
newBook->visitRuns (0, 0x7FFFFFFF, createActiveFormat (this)); newBook->visitRuns (0, 0x7FFFFFFF, CreateActiveFormat (this));
if (mNode != NULL) if (mNode != NULL)
for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (ActiveTextFormats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
i->second->createDrawItem (mNode); i->second->createDrawItem (mNode);
} }
@ -982,46 +982,46 @@ public:
if (nullptr != mNode) if (nullptr != mNode)
{ {
for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (ActiveTextFormats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
mNode->outOfDate(i->second->mRenderItem); mNode->outOfDate(i->second->mRenderItem);
} }
} }
void createDrawItem(ITexture* _texture, ILayerNode* _node) void createDrawItem(ITexture* texture, ILayerNode* node)
{ {
//test (); //test ();
mNode = _node; mNode = node;
for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (ActiveTextFormats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
i->second->createDrawItem (_node); i->second->createDrawItem (node);
} }
struct renderRun struct RenderRun
{ {
PageDisplay * this_; PageDisplay * this_;
GlyphStream &glyphStream; GlyphStream &glyphStream;
renderRun (PageDisplay * this_, GlyphStream &glyphStream) : RenderRun (PageDisplay * this_, GlyphStream &glyphStream) :
this_(this_), glyphStream (glyphStream) this_(this_), glyphStream (glyphStream)
{ {
} }
void operator () (Section const & Section, Line const & Line, Run const & Run) const void operator () (Section const & section, Line const & line, Run const & run) const
{ {
bool isActive = Run.mStyle->mInteractiveId && (Run.mStyle == this_->mFocusItem); bool isActive = run.mStyle->mInteractiveId && (run.mStyle == this_->mFocusItem);
Colour colour = isActive ? (this_->mItemActive ? Run.mStyle->mActiveColour: Run.mStyle->mHotColour) : Run.mStyle->mNormalColour; Colour colour = isActive ? (this_->mItemActive ? run.mStyle->mActiveColour: run.mStyle->mHotColour) : run.mStyle->mNormalColour;
glyphStream.reset (Section.mRect.left + Line.mRect.left + Run.mLeft, Line.mRect.top, colour); glyphStream.reset (section.mRect.left + line.mRect.left + run.mLeft, line.mRect.top, colour);
utf8_stream stream (Run.mRange); Utf8Stream stream (run.mRange);
while (!stream.eof ()) while (!stream.eof ())
{ {
utf8_stream::unicode_char code_point = stream.consume (); Utf8Stream::UnicodeChar code_point = stream.consume ();
if (!ucs_space (code_point)) if (!ucsSpace (code_point))
glyphStream.emitGlyph (code_point); glyphStream.emitGlyph (code_point);
else else
glyphStream.emitSpace (code_point); glyphStream.emitSpace (code_point);
@ -1047,7 +1047,7 @@ public:
int visit_top = (std::max) (mViewTop, mViewTop + int (renderXform.clipTop )); int visit_top = (std::max) (mViewTop, mViewTop + int (renderXform.clipTop ));
int visit_bottom = (std::min) (mViewBottom, mViewTop + int (renderXform.clipBottom)); int visit_bottom = (std::min) (mViewBottom, mViewTop + int (renderXform.clipBottom));
mBook->visitRuns (visit_top, visit_bottom, textFormat.mFont, renderRun (this, glyphStream)); mBook->visitRuns (visit_top, visit_bottom, textFormat.mFont, RenderRun (this, glyphStream));
textFormat.mRenderItem->setLastVertexCount(glyphStream.end () - vertices); textFormat.mRenderItem->setLastVertexCount(glyphStream.end () - vertices);
} }
@ -1065,14 +1065,14 @@ public:
_checkMargin (); _checkMargin ();
if (mNode != NULL) if (mNode != NULL)
for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (ActiveTextFormats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
mNode->outOfDate (i->second->mRenderItem); mNode->outOfDate (i->second->mRenderItem);
} }
void destroyDrawItem() void destroyDrawItem()
{ {
for (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i) for (ActiveTextFormats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
i->second->destroyDrawItem (mNode); i->second->destroyDrawItem (mNode);
mNode = NULL; mNode = NULL;
@ -1086,15 +1086,15 @@ MYGUI_RTTI_DERIVED(BookPage)
public: public:
void showPage (TypesetBook::ptr Book, size_t Page) void showPage (TypesetBook::Ptr book, size_t page)
{ {
if (PageDisplay* 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 (boost::function <void (interactive_id)> linkClicked) void adviseLinkClicked (boost::function <void (InteractiveId)> linkClicked)
{ {
if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
@ -1106,7 +1106,7 @@ public:
{ {
if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->mLinkClicked = boost::function <void (interactive_id)> (); pd->mLinkClicked = boost::function <void (InteractiveId)> ();
} }
} }
@ -1121,34 +1121,34 @@ protected:
Widget::onMouseLostFocus (_new); Widget::onMouseLostFocus (_new);
} }
void onMouseMove(int _left, int _top) void onMouseMove(int left, int top)
{ {
if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->onMouseMove (_left, _top); pd->onMouseMove (left, top);
} }
else else
Widget::onMouseMove (_left, _top); Widget::onMouseMove (left, top);
} }
void onMouseButtonPressed (int _left, int _top, MouseButton _id) void onMouseButtonPressed (int left, int top, MouseButton id)
{ {
if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->onMouseButtonPressed (_left, _top, _id); pd->onMouseButtonPressed (left, top, id);
} }
else else
Widget::onMouseButtonPressed (_left, _top, _id); Widget::onMouseButtonPressed (left, top, id);
} }
void onMouseButtonReleased(int _left, int _top, MouseButton _id) void onMouseButtonReleased(int left, int top, MouseButton id)
{ {
if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ())) if (PageDisplay* pd = dynamic_cast <PageDisplay*> (getSubWidgetText ()))
{ {
pd->onMouseButtonReleased (_left, _top, _id); pd->onMouseButtonReleased (left, top, id);
} }
else else
Widget::onMouseButtonReleased (_left, _top, _id); Widget::onMouseButtonReleased (left, top, id);
} }
}; };
@ -1160,14 +1160,14 @@ void BookPage::registerMyGUIComponents ()
factory.registerFactory<PageDisplay>("BasisSkin"); factory.registerFactory<PageDisplay>("BasisSkin");
} }
static bool ucs_line_break (int code_point) static bool ucsLineBreak (int codePoint)
{ {
return code_point == '\n'; return codePoint == '\n';
} }
static bool ucs_space (int code_point) static bool ucsSpace (int codePoint)
{ {
switch (code_point) switch (codePoint)
{ {
case 0x0020: // SPACE case 0x0020: // SPACE
case 0x00A0: // NO-BREAK SPACE case 0x00A0: // NO-BREAK SPACE
@ -1195,9 +1195,9 @@ static bool ucs_space (int code_point)
} }
} }
static bool ucs_breaking_space (int code_point) static bool ucsBreakingSpace (int codePoint)
{ {
switch (code_point) switch (codePoint)
{ {
case 0x0020: // SPACE case 0x0020: // SPACE
//case 0x00A0: // NO-BREAK SPACE //case 0x00A0: // NO-BREAK SPACE

@ -15,8 +15,8 @@ namespace MWGui
/// the book page widget. /// the book page widget.
struct TypesetBook struct TypesetBook
{ {
typedef boost::shared_ptr <TypesetBook> ptr; typedef boost::shared_ptr <TypesetBook> Ptr;
typedef intptr_t interactive_id; typedef intptr_t InteractiveId;
/// Returns the number of pages in the document. /// Returns the number of pages in the document.
virtual size_t pageCount () const = 0; virtual size_t pageCount () const = 0;
@ -33,16 +33,16 @@ namespace MWGui
/// A factory class for creating a typeset book instance. /// A factory class for creating a typeset book instance.
struct BookTypesetter struct BookTypesetter
{ {
typedef boost::shared_ptr <BookTypesetter> ptr; typedef boost::shared_ptr <BookTypesetter> Ptr;
typedef TypesetBook::interactive_id interactive_id; typedef TypesetBook::InteractiveId InteractiveId;
typedef MyGUI::Colour coulour; typedef MyGUI::Colour Colour;
typedef uint8_t const * utf8_point; typedef uint8_t const * Utf8Point;
typedef std::pair <utf8_point, utf8_point> utf8_span; typedef std::pair <Utf8Point, Utf8Point> Utf8Span;
enum alignment { enum Alignment {
alignLeft = -1, AlignLeft = -1,
alignCenter = 0, AlignCenter = 0,
alignRight = +1 AlignRight = +1
}; };
/// Styles are used to control the character level formatting /// Styles are used to control the character level formatting
@ -52,15 +52,15 @@ namespace MWGui
struct Style; struct Style;
/// A factory function for creating the default implementation of a book typesetter /// A factory function for creating the default implementation of a book typesetter
static ptr create (int pageWidth, int pageHeight); static Ptr create (int pageWidth, int pageHeight);
/// Create a simple text style consisting of a font and a text color. /// Create a simple text style consisting of a font and a text color.
virtual Style* createStyle (char const * Font, coulour Colour) = 0; virtual Style* createStyle (char const * Font, Colour Colour) = 0;
/// Create a hyper-link style with a user-defined identifier based on an /// Create a hyper-link style with a user-defined identifier based on an
/// existing style. The unique flag forces a new instance of this style /// existing style. The unique flag forces a new instance of this style
/// to be created even if an existing instance is present. /// to be created even if an existing instance is present.
virtual Style* createHotStyle (Style * BaseStyle, coulour NormalColour, coulour HoverColour, coulour ActiveColour, interactive_id Id, bool Unique = true) = 0; virtual Style* createHotStyle (Style * BaseStyle, Colour NormalColour, Colour HoverColour, Colour ActiveColour, InteractiveId Id, bool Unique = true) = 0;
/// Insert a line break into the document. Newline characters in the input /// Insert a line break into the document. Newline characters in the input
/// text have the same affect. The margin parameter adds additional space /// text have the same affect. The margin parameter adds additional space
@ -74,25 +74,25 @@ namespace MWGui
virtual void sectionBreak (float margin = 0) = 0; virtual void sectionBreak (float margin = 0) = 0;
/// Changes the alignment for the current section of text. /// Changes the alignment for the current section of text.
virtual void setSectionAlignment (alignment sectionAlignment) = 0; virtual void setSectionAlignment (Alignment sectionAlignment) = 0;
// Layout a block of text with the specified style into the document. // Layout a block of text with the specified style into the document.
virtual void write (Style * Style, utf8_span Text) = 0; virtual void write (Style * Style, Utf8Span Text) = 0;
/// Adds a content block to the document without laying it out. An /// Adds a content block to the document without laying it out. An
/// identifier is returned that can be used to refer to it. If select /// identifier is returned that can be used to refer to it. If select
/// is true, the block is activated to be references by future writes. /// is true, the block is activated to be references by future writes.
virtual intptr_t add_content (utf8_span Text, bool Select = true) = 0; virtual intptr_t addContent (Utf8Span Text, bool Select = true) = 0;
/// Select a previously created content block for future writes. /// Select a previously created content block for future writes.
virtual void select_content (intptr_t contentHandle) = 0; virtual void selectContent (intptr_t contentHandle) = 0;
/// Layout a span of the selected content block into the document /// Layout a span of the selected content block into the document
/// using the specified style. /// using the specified style.
virtual void write (Style * Style, size_t Begin, size_t End) = 0; virtual void write (Style * Style, size_t Begin, size_t End) = 0;
/// Finalize the document layout, and return a pointer to it. /// Finalize the document layout, and return a pointer to it.
virtual TypesetBook::ptr complete () = 0; virtual TypesetBook::Ptr complete () = 0;
}; };
/// An interface to the BookPage widget. /// An interface to the BookPage widget.
@ -101,14 +101,14 @@ namespace MWGui
MYGUI_RTTI_DERIVED(BookPage) MYGUI_RTTI_DERIVED(BookPage)
public: public:
typedef TypesetBook::interactive_id interactive_id; typedef TypesetBook::InteractiveId InteractiveId;
typedef boost::function <void (interactive_id)> click_callback; typedef boost::function <void (InteractiveId)> ClickCallback;
/// 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 (TypesetBook::ptr Book, size_t Page) = 0; virtual void showPage (TypesetBook::Ptr Book, size_t Page) = 0;
/// Set the callback for a clicking a hyper-link in the document. /// Set the callback for a clicking a hyper-link in the document.
virtual void adviseLinkClicked (click_callback callback) = 0; virtual void adviseLinkClicked (ClickCallback callback) = 0;
/// Clear the hyper-link click callback. /// Clear the hyper-link click callback.
virtual void unadviseLinkClicked () = 0; virtual void unadviseLinkClicked () = 0;

@ -4,189 +4,189 @@ using namespace MWGui;
namespace namespace
{ {
BookTypesetter::utf8_span to_utf8_span (char const * Text) BookTypesetter::Utf8Span to_utf8_span (char const * text)
{ {
typedef BookTypesetter::utf8_point point; typedef BookTypesetter::Utf8Point point;
point begin = reinterpret_cast <point> (Text); point begin = reinterpret_cast <point> (text);
return BookTypesetter::utf8_span (begin, begin + strlen (Text)); return BookTypesetter::Utf8Span (begin, begin + strlen (text));
} }
const MyGUI::Colour linkHot (0.40f, 0.40f, 0.80f); const MyGUI::Colour linkHot (0.40f, 0.40f, 0.80f);
const MyGUI::Colour linkNormal (0.20f, 0.20f, 0.60f); const MyGUI::Colour linkNormal (0.20f, 0.20f, 0.60f);
const MyGUI::Colour linkActive (0.50f, 0.50f, 1.00f); const MyGUI::Colour linkActive (0.50f, 0.50f, 1.00f);
struct addContent struct AddContent
{ {
BookTypesetter::ptr typesetter; BookTypesetter::Ptr mTypesetter;
BookTypesetter::Style* body_style; BookTypesetter::Style* mBodyStyle;
addContent (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style) : AddContent (BookTypesetter::Ptr typesetter, BookTypesetter::Style* body_style) :
typesetter (typesetter), body_style (body_style) mTypesetter (typesetter), mBodyStyle (body_style)
{ {
} }
}; };
struct addSpan : addContent struct AddSpan : AddContent
{ {
addSpan (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style) : AddSpan (BookTypesetter::Ptr typesetter, BookTypesetter::Style* body_style) :
addContent (typesetter, body_style) AddContent (typesetter, body_style)
{ {
} }
void operator () (intptr_t topicId, size_t begin, size_t end) void operator () (intptr_t topicId, size_t begin, size_t end)
{ {
BookTypesetter::Style* style = body_style; BookTypesetter::Style* style = mBodyStyle;
if (topicId) if (topicId)
style = typesetter->createHotStyle (body_style, linkNormal, linkHot, linkActive, topicId); style = mTypesetter->createHotStyle (mBodyStyle, linkNormal, linkHot, linkActive, topicId);
typesetter->write (style, begin, end); mTypesetter->write (style, begin, end);
} }
}; };
struct addEntry struct AddEntry
{ {
BookTypesetter::ptr typesetter; BookTypesetter::Ptr mTypesetter;
BookTypesetter::Style* body_style; BookTypesetter::Style* mBodyStyle;
addEntry (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style) : AddEntry (BookTypesetter::Ptr typesetter, BookTypesetter::Style* body_style) :
typesetter (typesetter), body_style (body_style) mTypesetter (typesetter), mBodyStyle (body_style)
{ {
} }
void operator () (JournalViewModel::Entry const & Entry) void operator () (JournalViewModel::Entry const & entry)
{ {
typesetter->add_content (Entry.body ()); mTypesetter->addContent (entry.body ());
Entry.visitSpans (addSpan (typesetter, body_style)); entry.visitSpans (AddSpan (mTypesetter, mBodyStyle));
} }
}; };
struct addJournalEntry : addEntry struct AddJournalEntry : AddEntry
{ {
bool add_header; bool mAddHeader;
BookTypesetter::Style* header_style; BookTypesetter::Style* mHeaderStyle;
addJournalEntry (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style, AddJournalEntry (BookTypesetter::Ptr typesetter, BookTypesetter::Style* body_style,
BookTypesetter::Style* header_style, bool add_header) : BookTypesetter::Style* header_style, bool add_header) :
addEntry (typesetter, body_style), AddEntry (typesetter, body_style),
header_style (header_style), mHeaderStyle (header_style),
add_header (add_header) mAddHeader (add_header)
{ {
} }
void operator () (JournalViewModel::JournalEntry const & Entry) void operator () (JournalViewModel::JournalEntry const & entry)
{ {
if (add_header) if (mAddHeader)
{ {
typesetter->write (header_style, Entry.timestamp ()); mTypesetter->write (mHeaderStyle, entry.timestamp ());
typesetter->lineBreak (); mTypesetter->lineBreak ();
} }
addEntry::operator () (Entry); AddEntry::operator () (entry);
typesetter->sectionBreak (10); mTypesetter->sectionBreak (10);
} }
}; };
struct addTopicEntry : addEntry struct AddTopicEntry : AddEntry
{ {
intptr_t contentId; intptr_t mContentId;
BookTypesetter::Style* header_style; BookTypesetter::Style* mHeaderStyle;
addTopicEntry (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style, AddTopicEntry (BookTypesetter::Ptr typesetter, BookTypesetter::Style* body_style,
BookTypesetter::Style* header_style, intptr_t contentId) : BookTypesetter::Style* header_style, intptr_t contentId) :
addEntry (typesetter, body_style), header_style (header_style), contentId (contentId) AddEntry (typesetter, body_style), mHeaderStyle (header_style), mContentId (contentId)
{ {
} }
void operator () (JournalViewModel::TopicEntry const & Entry) void operator () (JournalViewModel::TopicEntry const & entry)
{ {
typesetter->write (body_style, Entry.source ()); mTypesetter->write (mBodyStyle, entry.source ());
typesetter->write (body_style, 0, 3);// begin mTypesetter->write (mBodyStyle, 0, 3);// begin
addEntry::operator() (Entry); AddEntry::operator() (entry);
typesetter->select_content (contentId); mTypesetter->selectContent (mContentId);
typesetter->write (body_style, 2, 3);// end quote mTypesetter->write (mBodyStyle, 2, 3);// end quote
typesetter->sectionBreak (10); mTypesetter->sectionBreak (10);
} }
}; };
struct addTopicName : addContent struct AddTopicName : AddContent
{ {
addTopicName (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) : AddTopicName (BookTypesetter::Ptr typesetter, BookTypesetter::Style* style) :
addContent (typesetter, style) AddContent (typesetter, style)
{ {
} }
void operator () (JournalViewModel::utf8_span topicName) void operator () (JournalViewModel::Utf8Span topicName)
{ {
typesetter->write (body_style, topicName); mTypesetter->write (mBodyStyle, topicName);
typesetter->sectionBreak (10); mTypesetter->sectionBreak (10);
} }
}; };
struct addQuestName : addContent struct AddQuestName : AddContent
{ {
addQuestName (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) : AddQuestName (BookTypesetter::Ptr typesetter, BookTypesetter::Style* style) :
addContent (typesetter, style) AddContent (typesetter, style)
{ {
} }
void operator () (JournalViewModel::utf8_span topicName) void operator () (JournalViewModel::Utf8Span topicName)
{ {
typesetter->write (body_style, topicName); mTypesetter->write (mBodyStyle, topicName);
typesetter->sectionBreak (10); mTypesetter->sectionBreak (10);
} }
}; };
struct addTopicLink : addContent struct AddTopicLink : AddContent
{ {
addTopicLink (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) : AddTopicLink (BookTypesetter::Ptr typesetter, BookTypesetter::Style* style) :
addContent (typesetter, style) AddContent (typesetter, style)
{ {
} }
void operator () (JournalViewModel::topic_id topicId, JournalViewModel::utf8_span name) void operator () (JournalViewModel::TopicId topicId, JournalViewModel::Utf8Span name)
{ {
BookTypesetter::Style* link = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, topicId); BookTypesetter::Style* link = mTypesetter->createHotStyle (mBodyStyle, MyGUI::Colour::Black, linkHot, linkActive, topicId);
typesetter->write (link, name); mTypesetter->write (link, name);
typesetter->lineBreak (); mTypesetter->lineBreak ();
} }
}; };
struct addQuestLink : addContent struct AddQuestLink : AddContent
{ {
addQuestLink (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) : AddQuestLink (BookTypesetter::Ptr typesetter, BookTypesetter::Style* style) :
addContent (typesetter, style) AddContent (typesetter, style)
{ {
} }
void operator () (JournalViewModel::quest_id id, JournalViewModel::utf8_span name) void operator () (JournalViewModel::QuestId id, JournalViewModel::Utf8Span name)
{ {
BookTypesetter::Style* style = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, id); BookTypesetter::Style* style = mTypesetter->createHotStyle (mBodyStyle, MyGUI::Colour::Black, linkHot, linkActive, id);
typesetter->write (style, name); mTypesetter->write (style, name);
typesetter->lineBreak (); mTypesetter->lineBreak ();
} }
}; };
} }
typedef TypesetBook::ptr book; typedef TypesetBook::Ptr book;
JournalBooks::JournalBooks (JournalViewModel::ptr Model) : JournalBooks::JournalBooks (JournalViewModel::Ptr model) :
Model (Model) mModel (model)
{ {
} }
book JournalBooks::createEmptyJournalBook () book JournalBooks::createEmptyJournalBook ()
{ {
BookTypesetter::ptr typesetter = createTypesetter (); BookTypesetter::Ptr typesetter = createTypesetter ();
BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
@ -228,51 +228,51 @@ book JournalBooks::createEmptyJournalBook ()
book JournalBooks::createJournalBook () book JournalBooks::createJournalBook ()
{ {
BookTypesetter::ptr typesetter = createTypesetter (); BookTypesetter::Ptr typesetter = createTypesetter ();
BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visitJournalEntries (0, addJournalEntry (typesetter, body, header, true)); mModel->visitJournalEntries (0, AddJournalEntry (typesetter, body, header, true));
return typesetter->complete (); return typesetter->complete ();
} }
book JournalBooks::createTopicBook (uintptr_t topicId) book JournalBooks::createTopicBook (uintptr_t topicId)
{ {
BookTypesetter::ptr typesetter = createTypesetter (); BookTypesetter::Ptr typesetter = createTypesetter ();
BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visitTopicName (topicId, addTopicName (typesetter, header)); mModel->visitTopicName (topicId, AddTopicName (typesetter, header));
intptr_t contentId = typesetter->add_content (to_utf8_span (", \"")); intptr_t contentId = typesetter->addContent (to_utf8_span (", \""));
Model->visitTopicEntries (topicId, addTopicEntry (typesetter, body, header, contentId)); mModel->visitTopicEntries (topicId, AddTopicEntry (typesetter, body, header, contentId));
return typesetter->complete (); return typesetter->complete ();
} }
book JournalBooks::createQuestBook (uintptr_t questId) book JournalBooks::createQuestBook (uintptr_t questId)
{ {
BookTypesetter::ptr typesetter = createTypesetter (); BookTypesetter::Ptr typesetter = createTypesetter ();
BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); BookTypesetter::Style* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visitQuestName (questId, addQuestName (typesetter, header)); mModel->visitQuestName (questId, AddQuestName (typesetter, header));
Model->visitJournalEntries (questId, addJournalEntry (typesetter, body, header, false)); mModel->visitJournalEntries (questId, AddJournalEntry (typesetter, body, header, false));
return typesetter->complete (); return typesetter->complete ();
} }
book JournalBooks::createTopicIndexBook () book JournalBooks::createTopicIndexBook ()
{ {
BookTypesetter::ptr typesetter = BookTypesetter::create (92, 250); BookTypesetter::Ptr typesetter = BookTypesetter::create (92, 250);
typesetter->setSectionAlignment (BookTypesetter::alignCenter); typesetter->setSectionAlignment (BookTypesetter::AlignCenter);
BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
@ -298,25 +298,25 @@ book JournalBooks::createTopicIndexBook ()
book JournalBooks::createTopicIndexBook (char character) book JournalBooks::createTopicIndexBook (char character)
{ {
BookTypesetter::ptr typesetter = BookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF); BookTypesetter::Ptr typesetter = BookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
BookTypesetter::Style* style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); BookTypesetter::Style* style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visitTopicNamesStartingWith (character, addTopicLink (typesetter, style)); mModel->visitTopicNamesStartingWith (character, AddTopicLink (typesetter, style));
return typesetter->complete (); return typesetter->complete ();
} }
book JournalBooks::createQuestIndexBook (bool activeOnly) book JournalBooks::createQuestIndexBook (bool activeOnly)
{ {
BookTypesetter::ptr typesetter = BookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF); BookTypesetter::Ptr typesetter = BookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
BookTypesetter::Style* base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); BookTypesetter::Style* base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visitQuestNames (activeOnly, addQuestLink (typesetter, base)); mModel->visitQuestNames (activeOnly, AddQuestLink (typesetter, base));
return typesetter->complete (); return typesetter->complete ();
} }
BookTypesetter::ptr JournalBooks::createTypesetter () BookTypesetter::Ptr JournalBooks::createTypesetter ()
{ {
//TODO: determine page size from layout... //TODO: determine page size from layout...
return BookTypesetter::create (240, 300); return BookTypesetter::create (240, 300);

@ -8,21 +8,21 @@ namespace MWGui
{ {
struct JournalBooks struct JournalBooks
{ {
typedef TypesetBook::ptr book; typedef TypesetBook::Ptr Book;
JournalViewModel::ptr Model; JournalViewModel::Ptr mModel;
JournalBooks (JournalViewModel::ptr Model); JournalBooks (JournalViewModel::Ptr model);
book createEmptyJournalBook (); Book createEmptyJournalBook ();
book createJournalBook (); Book createJournalBook ();
book createTopicBook (uintptr_t topicId); Book createTopicBook (uintptr_t topicId);
book createQuestBook (uintptr_t questId); Book createQuestBook (uintptr_t questId);
book createTopicIndexBook (); Book createTopicIndexBook ();
book createTopicIndexBook (char character); Book createTopicIndexBook (char character);
book createQuestIndexBook (bool showAll); Book createQuestIndexBook (bool showAll);
private: private:
BookTypesetter::ptr createTypesetter (); BookTypesetter::Ptr createTypesetter ();
}; };
} }

@ -5,7 +5,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwdialogue/journalentry.hpp" #include "../mwdialogue/journalentry.hpp"
//#include "MyGUI_LanguageManager.h" #include <MyGUI_LanguageManager.h>
#include <components/misc/utf8stream.hpp> #include <components/misc/utf8stream.hpp>
@ -24,18 +24,18 @@ class KeywordSearch
{ {
public: public:
typedef typename string_t::const_iterator point; typedef typename string_t::const_iterator Point;
struct Match struct Match
{ {
point mBeg; Point mBeg;
point mEnd; Point mEnd;
value_t mValue; value_t mValue;
}; };
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, mRoot); seed_impl (/*std::move*/ (keyword), /*std::move*/ (value), 0, mRoot);
} }
void clear () void clear ()
@ -44,9 +44,9 @@ public:
mRoot.mKeyword.clear (); mRoot.mKeyword.clear ();
} }
bool search (point Beg, point End, Match & Match) bool search (Point beg, Point end, Match & match)
{ {
for (point i = Beg; i != End; ++i) for (Point i = beg; i != end; ++i)
{ {
// check first character // check first character
typename Entry::childen_t::iterator candidate = mRoot.mChildren.find (std::tolower (*i, mLocale)); typename Entry::childen_t::iterator candidate = mRoot.mChildren.find (std::tolower (*i, mLocale));
@ -56,9 +56,9 @@ public:
continue; continue;
// see how far the match goes // see how far the match goes
point j = i; Point j = i;
while ((j + 1) != End) while ((j + 1) != end)
{ {
typename Entry::childen_t::iterator next = candidate->second.mChildren.find (std::tolower (*++j, mLocale)); typename Entry::childen_t::iterator next = candidate->second.mChildren.find (std::tolower (*++j, mLocale));
@ -75,7 +75,7 @@ public:
// match the rest of the keyword // match the rest of the keyword
typename string_t::const_iterator t = candidate->second.mKeyword.begin () + (j - i); typename string_t::const_iterator t = candidate->second.mKeyword.begin () + (j - i);
while (j != End && t != candidate->second.mKeyword.end ()) while (j != end && t != candidate->second.mKeyword.end ())
{ {
if (std::tolower (*j, mLocale) != std::tolower (*t, mLocale)) if (std::tolower (*j, mLocale) != std::tolower (*t, mLocale))
break; break;
@ -88,9 +88,9 @@ public:
continue; continue;
// we did it, report the good news // we did it, report the good news
Match.mValue = candidate->second.mValue; match.mValue = candidate->second.mValue;
Match.mBeg = i; match.mBeg = i;
Match.mEnd = j; match.mEnd = j;
return true; return true;
} }
@ -110,22 +110,22 @@ private:
childen_t mChildren; childen_t mChildren;
}; };
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)
{ {
int ch = tolower (Keyword.at (Depth), mLocale); int ch = tolower (keyword.at (depth), mLocale);
typename Entry::childen_t::iterator j = Entry.mChildren.find (ch); typename Entry::childen_t::iterator j = entry.mChildren.find (ch);
if (j == Entry.mChildren.end ()) if (j == entry.mChildren.end ())
{ {
Entry.mChildren [ch].mValue = /*std::move*/ (Value); entry.mChildren [ch].mValue = /*std::move*/ (value);
Entry.mChildren [ch].mKeyword = /*std::move*/ (Keyword); entry.mChildren [ch].mKeyword = /*std::move*/ (keyword);
} }
else else
{ {
if (j->second.mKeyword.size () > 0) if (j->second.mKeyword.size () > 0)
{ {
if (Keyword == j->second.mKeyword) if (keyword == j->second.mKeyword)
throw std::runtime_error ("duplicate keyword inserted"); throw std::runtime_error ("duplicate keyword inserted");
value_t pushValue = /*std::move*/ (j->second.mValue); value_t pushValue = /*std::move*/ (j->second.mValue);
@ -133,13 +133,15 @@ private:
j->second.mKeyword.clear (); j->second.mKeyword.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); if (depth+1 < pushKeyword.size())
seed_impl (/*std::move*/ (pushKeyword), /*std::move*/ (pushValue), depth+1, j->second);
} }
seed_impl (/*std::move*/ (Keyword), /*std::move*/ (Value), Depth+1, j->second); if (depth+1 < keyword.size())
seed_impl (/*std::move*/ (keyword), /*std::move*/ (value), depth+1, j->second);
} }
} }
@ -166,15 +168,15 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
{ {
} }
//TODO: replace this nasty BS /// \todo replace this nasty BS
static utf8_span toUtf8Span (std::string const & str) static Utf8Span toUtf8Span (std::string const & str)
{ {
if (str.size () == 0) if (str.size () == 0)
return utf8_span (utf8_point (NULL), utf8_point (NULL)); return Utf8Span (Utf8Point (NULL), Utf8Point (NULL));
utf8_point point = reinterpret_cast <utf8_point> (str.c_str ()); Utf8Point point = reinterpret_cast <Utf8Point> (str.c_str ());
return utf8_span (point, point + str.size ()); return Utf8Span (point, point + str.size ());
} }
void load () void load ()
@ -215,10 +217,10 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
typedef t_iterator iterator_t; typedef t_iterator iterator_t;
iterator_t itr; iterator_t itr;
JournalViewModelImpl const * Model; JournalViewModelImpl const * mModel;
BaseEntry (JournalViewModelImpl const * Model, iterator_t itr) : BaseEntry (JournalViewModelImpl const * model, iterator_t itr) :
Model (Model), itr (itr), loaded (false) mModel (model), itr (itr), loaded (false)
{} {}
virtual ~BaseEntry () {} virtual ~BaseEntry () {}
@ -237,23 +239,23 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
} }
} }
utf8_span body () const Utf8Span body () const
{ {
ensureLoaded (); ensureLoaded ();
return toUtf8Span (utf8text); return toUtf8Span (utf8text);
} }
void visitSpans (boost::function < void (topic_id, size_t, size_t)> visitor) const void visitSpans (boost::function < void (TopicId, size_t, size_t)> visitor) const
{ {
ensureLoaded (); ensureLoaded ();
Model->ensureKeyWordSearchLoaded (); mModel->ensureKeyWordSearchLoaded ();
std::string::const_iterator i = utf8text.begin (); std::string::const_iterator i = utf8text.begin ();
keyword_search_t::Match match; keyword_search_t::Match match;
while (i != utf8text.end () && Model->mKeywordSearch.search (i, utf8text.end (), match)) while (i != utf8text.end () && mModel->mKeywordSearch.search (i, utf8text.end (), match))
{ {
if (i != match.mBeg) if (i != match.mBeg)
visitor (0, i - utf8text.begin (), match.mBeg - utf8text.begin ()); visitor (0, i - utf8text.begin (), match.mBeg - utf8text.begin ());
@ -269,7 +271,7 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
}; };
void visitQuestNames (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const void visitQuestNames (bool active_only, boost::function <void (QuestId, Utf8Span)> visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get ().getJournal (); MWBase::Journal * journal = MWBase::Environment::get ().getJournal ();
@ -278,11 +280,11 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
if (active_only && i->second.isFinished ()) if (active_only && i->second.isFinished ())
continue; continue;
visitor (reinterpret_cast <quest_id> (&i->second), toUtf8Span (i->first)); visitor (reinterpret_cast <QuestId> (&i->second), toUtf8Span (i->first));
} }
} }
void visitQuestName (quest_id questId, boost::function <void (utf8_span)> visitor) const void visitQuestName (QuestId questId, boost::function <void (Utf8Span)> visitor) const
{ {
MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId); MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId);
@ -307,7 +309,7 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
return itr->getText(MWBase::Environment::get().getWorld()->getStore()); return itr->getText(MWBase::Environment::get().getWorld()->getStore());
} }
utf8_span timestamp () const Utf8Span timestamp () const
{ {
if (timestamp_buffer.empty ()) if (timestamp_buffer.empty ())
{ {
@ -317,7 +319,8 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
injectMonthName (os, itr->mMonth); injectMonthName (os, itr->mMonth);
os << " (Day " << (itr->mDay + 1) << ')'; const std::string& dayStr = MyGUI::LanguageManager::getInstance().replaceTags("#{sDay}");
os << " (" << dayStr << " " << (itr->mDay + 1) << ')';
timestamp_buffer = os.str (); timestamp_buffer = os.str ();
} }
@ -326,7 +329,7 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
} }
}; };
void visitJournalEntries (quest_id questId, boost::function <void (JournalEntry const &)> visitor) const void visitJournalEntries (QuestId questId, boost::function <void (JournalEntry const &)> visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
@ -350,19 +353,19 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
} }
} }
void visitTopics (boost::function <void (topic_id, utf8_span)> visitor) const void visitTopics (boost::function <void (TopicId, Utf8Span)> visitor) const
{ {
throw std::runtime_error ("not implemented"); throw std::runtime_error ("not implemented");
} }
void visitTopicName (topic_id topicId, boost::function <void (utf8_span)> visitor) const void visitTopicName (TopicId topicId, boost::function <void (Utf8Span)> visitor) const
{ {
MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId); MWDialogue::Topic const & topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
visitor (toUtf8Span (Topic.getName ())); visitor (toUtf8Span (topic.getName ()));
} }
void visitTopicNamesStartingWith (int character, boost::function < void (topic_id , utf8_span) > visitor) const void visitTopicNamesStartingWith (char character, boost::function < void (TopicId , Utf8Span) > visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
@ -371,28 +374,29 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
if (i->first [0] != std::tolower (character, mLocale)) if (i->first [0] != std::tolower (character, mLocale))
continue; continue;
visitor (topic_id (&i->second), toUtf8Span (i->first)); visitor (TopicId (&i->second), toUtf8Span (i->first));
} }
} }
struct TopicEntryImpl : BaseEntry <MWDialogue::Topic::TEntryIter, TopicEntry> struct TopicEntryImpl : BaseEntry <MWDialogue::Topic::TEntryIter, TopicEntry>
{ {
MWDialogue::Topic const & Topic; MWDialogue::Topic const & mTopic;
mutable std::string source_buffer; mutable std::string source_buffer;
TopicEntryImpl (JournalViewModelImpl const * Model, MWDialogue::Topic const & Topic, iterator_t itr) : TopicEntryImpl (JournalViewModelImpl const * model, MWDialogue::Topic const & topic, iterator_t itr) :
BaseEntry (Model, itr), Topic (Topic) BaseEntry (model, itr), mTopic (topic)
{} {}
std::string getText () const std::string getText () const
{ {
return Topic.getEntry (*itr).getText(MWBase::Environment::get().getWorld()->getStore()); /// \todo defines are not replaced (%PCName etc). should probably be done elsewhere though since we need the actor
return mTopic.getEntry (*itr).getText(MWBase::Environment::get().getWorld()->getStore());
} }
utf8_span source () const Utf8Span source () const
{ {
if (source_buffer.empty ()) if (source_buffer.empty ())
source_buffer = "someone"; source_buffer = "someone";
@ -401,72 +405,50 @@ struct MWGui::JournalViewModelImpl : JournalViewModel
}; };
void visitTopicEntries (topic_id topicId, boost::function <void (TopicEntry const &)> visitor) const void visitTopicEntries (TopicId topicId, boost::function <void (TopicEntry const &)> visitor) const
{ {
typedef MWDialogue::Topic::TEntryIter iterator_t; typedef MWDialogue::Topic::TEntryIter iterator_t;
MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId); MWDialogue::Topic const & topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
for (iterator_t i = Topic.begin (); i != Topic.end (); ++i) for (iterator_t i = topic.begin (); i != topic.end (); ++i)
visitor (TopicEntryImpl (this, Topic, i)); visitor (TopicEntryImpl (this, topic, i));
} }
}; };
static void injectMonthName (std::ostream & os, int month) static void injectMonthName (std::ostream & os, int month)
{ {
#ifndef MYGUI_SIGNLETON_FIXED_FOR_MSVC MyGUI::LanguageManager& lm = MyGUI::LanguageManager::getInstance();
static char const * month_names [] =
{
"Morning Star",
"Sun's Dawn",
"First Seed",
"Rain's Hand",
"Second Seed",
"Midyear",
"Sun's Height",
"Last Seed",
"Hearthfire",
"Frostfall",
"Sun's Dusk",
"Evening Star",
};
if (month >= 0 && month <= 11)
os << month_names [month ];
else
os << month ;
#else
auto lm = MyGUI::LanguageManager::getInstance();
if (month == 0) if (month == 0)
os << lm.getTag ("sMonthMorningstar"); os << lm.replaceTags ("#{sMonthMorningstar}");
else if (month == 1) else if (month == 1)
os << lm.getTag ("sMonthSunsdawn"); os << lm.replaceTags ("#{sMonthSunsdawn}");
else if (month == 2) else if (month == 2)
os << lm.getTag ("sMonthFirstseed"); os << lm.replaceTags ("#{sMonthFirstseed}");
else if (month == 3) else if (month == 3)
os << lm.getTag ("sMonthRainshand"); os << lm.replaceTags ("#{sMonthRainshand}");
else if (month == 4) else if (month == 4)
os << lm.getTag ("sMonthSecondseed"); os << lm.replaceTags ("#{sMonthSecondseed}");
else if (month == 5) else if (month == 5)
os << lm.getTag ("sMonthMidyear"); os << lm.replaceTags ("#{sMonthMidyear}");
else if (month == 6) else if (month == 6)
os << lm.getTag ("sMonthSunsheight"); os << lm.replaceTags ("#{sMonthSunsheight}");
else if (month == 7) else if (month == 7)
os << lm.getTag ("sMonthLastseed"); os << lm.replaceTags ("#{sMonthLastseed}");
else if (month == 8) else if (month == 8)
os << lm.getTag ("sMonthHeartfire"); os << lm.replaceTags ("#{sMonthHeartfire}");
else if (month == 9) else if (month == 9)
os << lm.getTag ("sMonthFrostfall"); os << lm.replaceTags ("#{sMonthFrostfall}");
else if (month == 10) else if (month == 10)
os << lm.getTag ("sMonthSunsdusk"); os << lm.replaceTags ("#{sMonthSunsdusk}");
else if (month == 11) else if (month == 11)
os << lm.getTag ("sMonthEveningstar"); os << lm.replaceTags ("#{sMonthEveningstar}");
else else
os << month; os << month;
#endif
} }
JournalViewModel::ptr JournalViewModel::create () JournalViewModel::Ptr JournalViewModel::create ()
{ {
return boost::make_shared <JournalViewModelImpl> (); return boost::make_shared <JournalViewModelImpl> ();
} }

@ -13,17 +13,17 @@ namespace MWGui
/// View-Model for the journal GUI /// View-Model for the journal GUI
/// ///
/// This interface defines an abstract data model suited /// This interface defines an abstract data model suited
// specifically to the needs of the journal GUI. It isolates /// specifically to the needs of the journal GUI. It isolates
/// the journal GUI from the implementation details of the /// the journal GUI from the implementation details of the
/// game data store. /// game data store.
struct JournalViewModel struct JournalViewModel
{ {
typedef boost::shared_ptr <JournalViewModel> ptr; typedef boost::shared_ptr <JournalViewModel> Ptr;
typedef intptr_t quest_id; typedef intptr_t QuestId;
typedef intptr_t topic_id; typedef intptr_t TopicId;
typedef uint8_t const * utf8_point; typedef uint8_t const * Utf8Point;
typedef std::pair <utf8_point, utf8_point> utf8_span; typedef std::pair <Utf8Point, Utf8Point> Utf8Span;
/// The base interface for both journal entries and topics. /// The base interface for both journal entries and topics.
struct Entry struct Entry
@ -33,12 +33,12 @@ namespace MWGui
/// This function returns a borrowed reference to the body of the /// This function returns a borrowed reference to the body of the
/// journal entry. The returned reference becomes invalid when the /// journal entry. The returned reference becomes invalid when the
/// entry is destroyed. /// entry is destroyed.
virtual utf8_span body () const = 0; virtual Utf8Span body () const = 0;
/// 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 visitSpans (boost::function <void (topic_id, size_t, size_t)> visitor) const = 0; virtual void visitSpans (boost::function <void (TopicId, size_t, size_t)> visitor) const = 0;
}; };
/// An interface to topic data. /// An interface to topic data.
@ -46,7 +46,7 @@ namespace MWGui
{ {
/// Returns a pre-formatted span of UTF8 encoded text representing /// Returns a pre-formatted span of UTF8 encoded text representing
/// the name of the NPC this portion of dialog was heard from. /// the name of the NPC this portion of dialog was heard from.
virtual utf8_span source () const = 0; virtual Utf8Span source () const = 0;
}; };
/// An interface to journal data. /// An interface to journal data.
@ -54,7 +54,7 @@ namespace MWGui
{ {
/// Returns a pre-formatted span of UTF8 encoded text representing /// Returns a pre-formatted span of UTF8 encoded text representing
/// the in-game date this entry was added to the journal. /// the in-game date this entry was added to the journal.
virtual utf8_span timestamp () const = 0; virtual Utf8Span timestamp () const = 0;
}; };
@ -68,25 +68,25 @@ namespace MWGui
virtual bool isEmpty () const = 0; virtual bool isEmpty () 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 visitQuestName (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0; virtual void visitQuestName (TopicId topicId, boost::function <void (Utf8Span)> 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 visitQuestNames (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const = 0; virtual void visitQuestNames (bool active_only, boost::function <void (QuestId, Utf8Span)> 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 visitJournalEntries (quest_id questId, boost::function <void (JournalEntry const &)> visitor) const = 0; virtual void visitJournalEntries (QuestId questId, boost::function <void (JournalEntry 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 visitTopicName (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0; virtual void visitTopicName (TopicId topicId, boost::function <void (Utf8Span)> 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 visitTopicNamesStartingWith (int character, boost::function < void (topic_id , utf8_span) > visitor) const = 0; virtual void visitTopicNamesStartingWith (char character, boost::function < void (TopicId , Utf8Span) > 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 visitTopicEntries (topic_id topicId, boost::function <void (TopicEntry const &)> visitor) const = 0; virtual void visitTopicEntries (TopicId topicId, boost::function <void (TopicEntry 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 ();
}; };
} }

@ -51,21 +51,21 @@ namespace
{ {
struct DisplayState struct DisplayState
{ {
int mPage; unsigned int mPage;
book mBook; Book mBook;
}; };
typedef std::stack <DisplayState> display_state_stack; typedef std::stack <DisplayState> DisplayStateStack;
display_state_stack mStates; DisplayStateStack mStates;
book mTopicIndexBook; Book mTopicIndexBook;
bool mQuestMode; bool mQuestMode;
bool mAllQuests; bool mAllQuests;
template <typename widget_type> template <typename T>
widget_type * getWidget (char const * name) T * getWidget (char const * name)
{ {
widget_type * widget; T * widget;
WindowBase::getWidget (widget, name); WindowBase::getWidget (widget, name);
return widget; return widget;
} }
@ -94,7 +94,7 @@ namespace
return getWidget <MWGui::BookPage> (name); return getWidget <MWGui::BookPage> (name);
} }
JournalWindowImpl (JournalViewModel::ptr Model) JournalWindowImpl (JournalViewModel::Ptr Model)
: WindowBase("openmw_journal.layout"), JournalBooks (Model) : WindowBase("openmw_journal.layout"), JournalBooks (Model)
{ {
mMainWidget->setVisible(false); mMainWidget->setVisible(false);
@ -114,7 +114,7 @@ namespace
adviseButtonClick (ShowActiveBTN, &JournalWindowImpl::notifyShowActive); adviseButtonClick (ShowActiveBTN, &JournalWindowImpl::notifyShowActive);
{ {
BookPage::click_callback callback; BookPage::ClickCallback callback;
callback = boost::bind (&JournalWindowImpl::notifyTopicClicked, this, _1); callback = boost::bind (&JournalWindowImpl::notifyTopicClicked, this, _1);
@ -124,7 +124,7 @@ namespace
} }
{ {
BookPage::click_callback callback; BookPage::ClickCallback callback;
callback = boost::bind (&JournalWindowImpl::notifyIndexLinkClicked, this, _1); callback = boost::bind (&JournalWindowImpl::notifyIndexLinkClicked, this, _1);
@ -133,7 +133,7 @@ namespace
} }
{ {
BookPage::click_callback callback; BookPage::ClickCallback callback;
callback = boost::bind (&JournalWindowImpl::notifyQuestClicked, this, _1); callback = boost::bind (&JournalWindowImpl::notifyQuestClicked, this, _1);
@ -146,14 +146,14 @@ namespace
void open() void open()
{ {
Model->load (); mModel->load ();
setBookMode (); setBookMode ();
MWBase::Environment::get().getSoundManager()->playSound ("book open", 1.0, 1.0); MWBase::Environment::get().getSoundManager()->playSound ("book open", 1.0, 1.0);
book journalBook; Book journalBook;
if (Model->isEmpty ()) if (mModel->isEmpty ())
journalBook = createEmptyJournalBook (); journalBook = createEmptyJournalBook ();
else else
journalBook = createJournalBook (); journalBook = createJournalBook ();
@ -163,10 +163,10 @@ namespace
void close() void close()
{ {
Model->unload (); mModel->unload ();
getPage (LeftBookPage)->showPage (book (), 0); getPage (LeftBookPage)->showPage (Book (), 0);
getPage (RightBookPage)->showPage (book (), 0); getPage (RightBookPage)->showPage (Book (), 0);
while (!mStates.empty ()) while (!mStates.empty ())
mStates.pop (); mStates.pop ();
@ -209,24 +209,24 @@ namespace
//TODO: figure out how to make "options" page overlay book page //TODO: figure out how to make "options" page overlay book page
// correctly, so that text may show underneath // correctly, so that text may show underneath
getPage (RightBookPage)->showPage (book (), 0); getPage (RightBookPage)->showPage (Book (), 0);
} }
void pushBook (book Book, int Page) void pushBook (Book book, unsigned int page)
{ {
DisplayState bs; DisplayState bs;
bs.mPage = Page; bs.mPage = page;
bs.mBook = Book; bs.mBook = book;
mStates.push (bs); mStates.push (bs);
updateShowingPages (); updateShowingPages ();
updateCloseJournalButton (); updateCloseJournalButton ();
} }
void replaceBook (book Book, int Page) void replaceBook (Book book, unsigned int page)
{ {
assert (!mStates.empty ()); assert (!mStates.empty ());
mStates.top ().mBook = Book; mStates.top ().mBook = book;
mStates.top ().mPage = Page; mStates.top ().mPage = page;
updateShowingPages (); updateShowingPages ();
} }
@ -245,38 +245,38 @@ namespace
void updateShowingPages () void updateShowingPages ()
{ {
book Book; Book book;
int Page; unsigned int page;
int relPages; unsigned int relPages;
if (!mStates.empty ()) if (!mStates.empty ())
{ {
Book = mStates.top ().mBook; book = mStates.top ().mBook;
Page = mStates.top ().mPage; page = mStates.top ().mPage;
relPages = Book->pageCount () - Page; relPages = book->pageCount () - page;
} }
else else
{ {
Page = 0; page = 0;
relPages = 0; relPages = 0;
} }
setVisible (PrevPageBTN, Page > 0); setVisible (PrevPageBTN, page > 0);
setVisible (NextPageBTN, relPages > 2); setVisible (NextPageBTN, relPages > 2);
setVisible (PageOneNum, relPages > 0); setVisible (PageOneNum, relPages > 0);
setVisible (PageTwoNum, relPages > 1); setVisible (PageTwoNum, relPages > 1);
getPage (LeftBookPage)->showPage ((relPages > 0) ? Book : book (), Page+0); getPage (LeftBookPage)->showPage ((relPages > 0) ? book : Book (), page+0);
getPage (RightBookPage)->showPage ((relPages > 0) ? Book : book (), Page+1); getPage (RightBookPage)->showPage ((relPages > 0) ? book : Book (), page+1);
setText (PageOneNum, Page + 1); setText (PageOneNum, page + 1);
setText (PageTwoNum, Page + 2); setText (PageTwoNum, page + 2);
} }
void notifyTopicClicked (intptr_t linkId) void notifyTopicClicked (intptr_t linkId)
{ {
book topicBook = createTopicBook (linkId); Book topicBook = createTopicBook (linkId);
if (mStates.size () > 1) if (mStates.size () > 1)
replaceBook (topicBook, 0); replaceBook (topicBook, 0);
@ -290,12 +290,12 @@ namespace
void notifyQuestClicked (intptr_t questId) void notifyQuestClicked (intptr_t questId)
{ {
book Book = createQuestBook (questId); Book book = createQuestBook (questId);
if (mStates.size () > 1) if (mStates.size () > 1)
replaceBook (Book, 0); replaceBook (book, 0);
else else
pushBook (Book, 0); pushBook (book, 0);
setVisible (OptionsOverlay, false); setVisible (OptionsOverlay, false);
setVisible (OptionsBTN, true); setVisible (OptionsBTN, true);
@ -319,16 +319,16 @@ namespace
popBook (); popBook ();
} }
void showList (char const * ListId, char const * PageId, book book) void showList (char const * listId, char const * pageId, Book book)
{ {
std::pair <int, int> size = book->getSize (); std::pair <int, int> size = book->getSize ();
getPage (PageId)->showPage (book, 0); getPage (pageId)->showPage (book, 0);
getWidget <ScrollView> (ListId)->setCanvasSize (size.first, size.second); getWidget <ScrollView> (listId)->setCanvasSize (size.first, size.second);
} }
void notifyIndexLinkClicked (TypesetBook::interactive_id character) void notifyIndexLinkClicked (TypesetBook::InteractiveId character)
{ {
setVisible (LeftTopicIndex, false); setVisible (LeftTopicIndex, false);
setVisible (RightTopicIndex, false); setVisible (RightTopicIndex, false);
@ -392,12 +392,12 @@ namespace
{ {
if (!mStates.empty ()) if (!mStates.empty ())
{ {
int & Page = mStates.top ().mPage; unsigned int & page = mStates.top ().mPage;
book Book = mStates.top ().mBook; Book book = mStates.top ().mBook;
if (Page < Book->pageCount () - 2) if (page < book->pageCount () - 2)
{ {
Page += 2; page += 2;
updateShowingPages (); updateShowingPages ();
} }
} }
@ -407,11 +407,11 @@ namespace
{ {
if (!mStates.empty ()) if (!mStates.empty ())
{ {
int & Page = mStates.top ().mPage; unsigned int & page = mStates.top ().mPage;
if(Page > 0) if(page > 0)
{ {
Page -= 2; page -= 2;
updateShowingPages (); updateShowingPages ();
} }
} }
@ -420,7 +420,7 @@ namespace
} }
// glue the implementation to the interface // glue the implementation to the interface
JournalWindow * MWGui::JournalWindow::create (JournalViewModel::ptr Model) JournalWindow * MWGui::JournalWindow::create (JournalViewModel::Ptr Model)
{ {
return new JournalWindowImpl (Model); return new JournalWindowImpl (Model);
} }

@ -3,22 +3,22 @@
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
class utf8_stream class Utf8Stream
{ {
public: public:
typedef uint32_t unicode_char; typedef uint32_t UnicodeChar;
typedef unsigned char const * point; typedef unsigned char const * Point;
//static const unicode_char sBadChar = 0xFFFFFFFF; gcc can't handle this //static const unicode_char sBadChar = 0xFFFFFFFF; gcc can't handle this
static unicode_char sBadChar () { return unicode_char (0xFFFFFFFF); } static UnicodeChar sBadChar () { return UnicodeChar (0xFFFFFFFF); }
utf8_stream (point begin, point end) : Utf8Stream (Point begin, Point end) :
cur (begin), nxt (begin), end (end) cur (begin), nxt (begin), end (end)
{ {
} }
utf8_stream (std::pair <point, point> range) : Utf8Stream (std::pair <Point, Point> range) :
cur (range.first), nxt (range.first), end (range.second) cur (range.first), nxt (range.first), end (range.second)
{ {
} }
@ -28,19 +28,19 @@ public:
return cur == end; return cur == end;
} }
point current () const Point current () const
{ {
return cur; return cur;
} }
unicode_char peek () UnicodeChar peek ()
{ {
if (cur == nxt) if (cur == nxt)
next (); next ();
return val; return val;
} }
unicode_char consume () UnicodeChar consume ()
{ {
if (cur == nxt) if (cur == nxt)
next (); next ();
@ -48,24 +48,24 @@ public:
return val; return val;
} }
static std::pair <unicode_char, point> decode (point cur, point end) static std::pair <UnicodeChar, Point> decode (Point cur, Point end)
{ {
if ((*cur & 0x80) == 0) if ((*cur & 0x80) == 0)
{ {
unicode_char chr = *cur++; UnicodeChar chr = *cur++;
return std::make_pair (chr, cur); return std::make_pair (chr, cur);
} }
int octets; int octets;
unicode_char chr; UnicodeChar chr;
boost::tie (octets, chr) = octet_count (*cur++); boost::tie (octets, chr) = octet_count (*cur++);
if (octets > 5) if (octets > 5)
return std::make_pair (sBadChar(), cur); return std::make_pair (sBadChar(), cur);
point 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);
@ -75,7 +75,7 @@ public:
if ((*cur & 0xC0) != 0x80) // check continuation mark if ((*cur & 0xC0) != 0x80) // check continuation mark
return std::make_pair (sBadChar(), cur);; return std::make_pair (sBadChar(), cur);;
chr = (chr << 6) | unicode_char ((*cur++) & 0x3F); chr = (chr << 6) | UnicodeChar ((*cur++) & 0x3F);
} }
return std::make_pair (chr, cur); return std::make_pair (chr, cur);
@ -83,7 +83,7 @@ public:
private: private:
static std::pair <int, unicode_char> octet_count (unsigned char octet) static std::pair <int, UnicodeChar> octet_count (unsigned char octet)
{ {
int octets; int octets;
@ -107,10 +107,10 @@ private:
boost::tie (val, nxt) = decode (nxt, end); boost::tie (val, nxt) = decode (nxt, end);
} }
point cur; Point cur;
point nxt; Point nxt;
point end; Point end;
unicode_char val; UnicodeChar val;
}; };
#endif #endif

Loading…
Cancel
Save