made a pass at conforming to established naming convention

This commit is contained in:
Nathan Jeffords 2013-02-14 21:37:33 -08:00
parent c7ede9b523
commit 4c22afc29b
6 changed files with 350 additions and 354 deletions

View file

@ -36,78 +36,78 @@ struct MWGui::TypesetBook : ITypesetBook
typedef utf8_stream::point utf8_point; typedef utf8_stream::point utf8_point;
typedef std::pair <utf8_point, utf8_point> range; typedef std::pair <utf8_point, utf8_point> range;
struct style : IBookTypesetter::IStyle struct Style : IBookTypesetter::IStyle
{ {
IFont* Font; IFont* mFont;
Colour HotColour; Colour mHotColour;
Colour ActiveColour; Colour mActiveColour;
Colour NormalColour; Colour mNormalColour;
interactive_id InteractiveId; interactive_id 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)
{ {
return (Font == tstFont) && return (mFont == tstFont) &&
partal_match (tstHotColour, tstActiveColour, tstNormalColour, tstInteractiveId); partal_match (tstHotColour, tstActiveColour, tstNormalColour, tstInteractiveId);
} }
bool match (char const * tstFont, Colour tstHotColour, Colour tstActiveColour, Colour tstNormalColour, intptr_t tstInteractiveId) bool match (char const * tstFont, Colour tstHotColour, Colour tstActiveColour, Colour tstNormalColour, intptr_t tstInteractiveId)
{ {
return (Font->getResourceName () == tstFont) && return (mFont->getResourceName () == tstFont) &&
partal_match (tstHotColour, tstActiveColour, tstNormalColour, tstInteractiveId); partal_match (tstHotColour, tstActiveColour, tstNormalColour, tstInteractiveId);
} }
bool partal_match (Colour tstHotColour, Colour tstActiveColour, Colour tstNormalColour, intptr_t tstInteractiveId) bool partal_match (Colour tstHotColour, Colour tstActiveColour, Colour tstNormalColour, intptr_t tstInteractiveId)
{ {
return return
(HotColour == tstHotColour ) && (mHotColour == tstHotColour ) &&
(ActiveColour == tstActiveColour ) && (mActiveColour == tstActiveColour ) &&
(NormalColour == tstNormalColour ) && (mNormalColour == tstNormalColour ) &&
(InteractiveId == tstInteractiveId ) ; (mInteractiveId == tstInteractiveId ) ;
} }
}; };
typedef std::list <style> styles; typedef std::list <Style> styles;
struct run struct Run
{ {
style* Style; Style* mStyle;
range Range; range mRange;
int Left, Right; int mLeft, mRight;
int PrintableChars; int mPrintableChars;
}; };
typedef std::vector <run> runs; typedef std::vector <Run> runs;
struct line struct Line
{ {
runs Runs; runs mRuns;
IntRect Rect; IntRect mRect;
}; };
typedef std::vector <line> lines; typedef std::vector <Line> lines;
struct section struct Section
{ {
lines Lines; lines mLines;
IntRect Rect; 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 Pages; pages mPages;
sections Sections; sections mSections;
contents Contents; contents mContents;
styles Styles; styles mStyles;
IntRect Rect; IntRect mRect;
virtual ~TypesetBook () {} virtual ~TypesetBook () {}
range addContent (IBookTypesetter::utf8_span Text) range addContent (IBookTypesetter::utf8_span Text)
{ {
contents::iterator i = Contents.insert (Contents.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 (utf8_point (NULL), utf8_point (NULL));
@ -118,61 +118,61 @@ struct MWGui::TypesetBook : ITypesetBook
return range (begin, end); return range (begin, end);
} }
int pageCount () const { return Pages.size (); } size_t pageCount () const { return mPages.size (); }
std::pair <int, int> getSize () const std::pair <int, int> getSize () const
{ {
return std::make_pair (Rect.width (), Rect.height ()); return std::make_pair (mRect.width (), mRect.height ());
} }
template <typename visitor> template <typename visitor>
void visit_runs (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 = Sections.begin (); i != Sections.end (); ++i) for (sections::const_iterator i = mSections.begin (); i != mSections.end (); ++i)
{ {
if (top >= Rect.bottom || bottom <= i->Rect.top) if (top >= mRect.bottom || bottom <= i->mRect.top)
continue; continue;
for (lines::const_iterator j = i->Lines.begin (); j != i->Lines.end (); ++j) for (lines::const_iterator j = i->mLines.begin (); j != i->mLines.end (); ++j)
{ {
if (top >= j->Rect.bottom || bottom <= j->Rect.top) if (top >= j->mRect.bottom || bottom <= j->mRect.top)
continue; continue;
for (runs::const_iterator k = j->Runs.begin (); k != j->Runs.end (); ++k) for (runs::const_iterator k = j->mRuns.begin (); k != j->mRuns.end (); ++k)
if (!Font || k->Style->Font == Font) if (!Font || k->mStyle->mFont == Font)
Visitor (*i, *j, *k); Visitor (*i, *j, *k);
} }
} }
} }
template <typename visitor> template <typename visitor>
void visit_runs (int top, int bottom, visitor const & Visitor) const void visitRuns (int top, int bottom, visitor const & Visitor) const
{ {
visit_runs (top, bottom, NULL, Visitor); visitRuns (top, bottom, NULL, Visitor);
} }
style * hitTest (int left, int top) const Style * hitTest (int left, int top) const
{ {
for (sections::const_iterator i = Sections.begin (); i != Sections.end (); ++i) for (sections::const_iterator i = mSections.begin (); i != mSections.end (); ++i)
{ {
if (top < i->Rect.top || top >= i->Rect.bottom) if (top < i->mRect.top || top >= i->mRect.bottom)
continue; continue;
int left1 = left - i->Rect.left; int left1 = left - i->mRect.left;
for (lines::const_iterator j = i->Lines.begin (); j != i->Lines.end (); ++j) for (lines::const_iterator j = i->mLines.begin (); j != i->mLines.end (); ++j)
{ {
if (top < j->Rect.top || top >= j->Rect.bottom) if (top < j->mRect.top || top >= j->mRect.bottom)
continue; continue;
int left2 = left1 - j->Rect.left; int left2 = left1 - j->mRect.left;
for (runs::const_iterator k = j->Runs.begin (); k != j->Runs.end (); ++k) for (runs::const_iterator k = j->mRuns.begin (); k != j->mRuns.end (); ++k)
{ {
if (left2 < k->Left || left2 >= k->Right) if (left2 < k->mLeft || left2 >= k->mRight)
continue; continue;
return k->Style; return k->mStyle;
} }
} }
} }
@ -180,11 +180,11 @@ struct MWGui::TypesetBook : ITypesetBook
return nullptr; return nullptr;
} }
IFont* affectedFont (style* Style) IFont* affectedFont (Style* Style)
{ {
for (styles::iterator i = Styles.begin (); i != Styles.end (); ++i) for (styles::iterator i = mStyles.begin (); i != mStyles.end (); ++i)
if (&*i == Style) if (&*i == Style)
return i->Font; return i->mFont;
return NULL; return NULL;
} }
@ -199,10 +199,10 @@ struct TypesetBook::Typesetter : IBookTypesetter
int mPageWidth; int mPageWidth;
int mPageHeight; int mPageHeight;
book_ptr Book; book_ptr mBook;
section * Section; Section * mSection;
line * Line; Line * mLine;
run * Run; Run * mRun;
std::vector <alignment> mSectionAlignment; std::vector <alignment> mSectionAlignment;
@ -211,11 +211,11 @@ struct TypesetBook::Typesetter : IBookTypesetter
Typesetter (size_t Width, size_t Height) : Typesetter (size_t Width, size_t Height) :
mPageWidth (Width), mPageHeight(Height), mPageWidth (Width), mPageHeight(Height),
Section (NULL), Line (NULL), Run (NULL), mSection (NULL), mLine (NULL), mRun (NULL),
mCurrentAlignment (alignLeft), mCurrentAlignment (alignLeft),
mCurrentContent (NULL) mCurrentContent (NULL)
{ {
Book = boost::make_shared <book> (); mBook = boost::make_shared <book> ();
} }
virtual ~Typesetter () virtual ~Typesetter ()
@ -224,51 +224,51 @@ struct TypesetBook::Typesetter : IBookTypesetter
IStyle * createStyle (char const * FontName, Colour FontColour) IStyle * createStyle (char const * FontName, Colour FontColour)
{ {
for (styles::iterator i = Book->Styles.begin (); i != Book->Styles.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;
style & Style = *Book->Styles.insert (Book->Styles.end (), style ()); Style & style = *mBook->mStyles.insert (mBook->mStyles.end (), Style ());
Style.Font = FontManager::getInstance().getByName(FontName); style.mFont = FontManager::getInstance().getByName(FontName);
Style.HotColour = FontColour; style.mHotColour = FontColour;
Style.ActiveColour = FontColour; style.mActiveColour = FontColour;
Style.NormalColour = FontColour; style.mNormalColour = FontColour;
Style.InteractiveId = 0; style.mInteractiveId = 0;
return &Style; return &style;
} }
IStyle* createHotStyle (IStyle * _BaseStyle, coulour NormalColour, coulour HoverColour, coulour ActiveColour, interactive_id Id, bool Unique) IStyle* createHotStyle (IStyle * _BaseStyle, coulour NormalColour, coulour HoverColour, coulour ActiveColour, interactive_id Id, bool Unique)
{ {
style* BaseStyle = dynamic_cast <style*> (_BaseStyle); Style* BaseStyle = dynamic_cast <Style*> (_BaseStyle);
if (!Unique) if (!Unique)
for (styles::iterator i = Book->Styles.begin (); i != Book->Styles.end (); ++i) for (styles::iterator i = mBook->mStyles.begin (); i != mBook->mStyles.end (); ++i)
if (i->match (BaseStyle->Font, HoverColour, ActiveColour, NormalColour, Id)) if (i->match (BaseStyle->mFont, HoverColour, ActiveColour, NormalColour, Id))
return &*i; return &*i;
style & Style = *Book->Styles.insert (Book->Styles.end (), style ()); Style & style = *mBook->mStyles.insert (mBook->mStyles.end (), Style ());
Style.Font = BaseStyle->Font; style.mFont = BaseStyle->mFont;
Style.HotColour = HoverColour; style.mHotColour = HoverColour;
Style.ActiveColour = ActiveColour; style.mActiveColour = ActiveColour;
Style.NormalColour = NormalColour; style.mNormalColour = NormalColour;
Style.InteractiveId = Id; style.mInteractiveId = Id;
return &Style; return &style;
} }
void write (IStyle * _Style, utf8_span Text) void write (IStyle * _Style, utf8_span Text)
{ {
range text = Book->addContent (Text); range text = mBook->addContent (Text);
write_impl (dynamic_cast <style*> (_Style), text.first, text.second); write_impl (dynamic_cast <Style*> (_Style), text.first, text.second);
} }
intptr_t add_content (utf8_span Text, bool Select) intptr_t add_content (utf8_span Text, bool Select)
{ {
contents::iterator i = Book->Contents.insert (Book->Contents.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);
@ -281,42 +281,42 @@ struct TypesetBook::Typesetter : IBookTypesetter
mCurrentContent = reinterpret_cast <content const *> (contentHandle); mCurrentContent = reinterpret_cast <content const *> (contentHandle);
} }
void write (IStyle * Style, size_t Begin, size_t End) void write (IStyle * style, size_t begin, size_t end)
{ {
assert (mCurrentContent != NULL); assert (mCurrentContent != NULL);
assert (End <= mCurrentContent->size ()); assert (end <= mCurrentContent->size ());
assert (Begin <= mCurrentContent->size ()); assert (begin <= mCurrentContent->size ());
utf8_point begin = &mCurrentContent->front () + Begin; utf8_point begin_ = &mCurrentContent->front () + begin;
utf8_point end = &mCurrentContent->front () + End ; utf8_point end_ = &mCurrentContent->front () + end ;
write_impl (dynamic_cast <style*> (Style), begin, end); write_impl (dynamic_cast <Style*> (style), begin_, end_);
} }
void lineBreak (float margin) void lineBreak (float margin)
{ {
assert (margin == 0); //TODO: figure out proper behavior here... assert (margin == 0); //TODO: figure out proper behavior here...
Run = NULL; mRun = NULL;
Line = NULL; mLine = NULL;
} }
void sectionBreak (float margin) void sectionBreak (float margin)
{ {
if (Book->Sections.size () > 0) if (mBook->mSections.size () > 0)
{ {
Run = NULL; mRun = NULL;
Line = NULL; mLine = NULL;
Section = NULL; mSection = NULL;
if (Book->Rect.bottom < (Book->Sections.back ().Rect.bottom + margin)) if (mBook->mRect.bottom < (mBook->mSections.back ().mRect.bottom + margin))
Book->Rect.bottom = (Book->Sections.back ().Rect.bottom + margin); mBook->mRect.bottom = (mBook->mSections.back ().mRect.bottom + margin);
} }
} }
void setSectionAlignment (alignment sectionAlignment) void setSectionAlignment (alignment sectionAlignment)
{ {
if (Section != NULL) if (mSection != NULL)
mSectionAlignment.back () = sectionAlignment; mSectionAlignment.back () = sectionAlignment;
mCurrentAlignment = sectionAlignment; mCurrentAlignment = sectionAlignment;
} }
@ -327,33 +327,33 @@ struct TypesetBook::Typesetter : IBookTypesetter
int curPageStop = 0; int curPageStop = 0;
std::vector <alignment>::iterator sa = mSectionAlignment.begin (); std::vector <alignment>::iterator sa = mSectionAlignment.begin ();
for (sections::iterator i = Book->Sections.begin (); i != Book->Sections.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->Lines.begin (); j != i->Lines.end (); ++j) for (lines::iterator j = i->mLines.begin (); j != i->mLines.end (); ++j)
{ {
int width = j->Rect.width (); int width = j->mRect.width ();
int excess = mPageWidth - width; int excess = mPageWidth - width;
switch (*sa) switch (*sa)
{ {
default: default:
case alignLeft: j->Rect.left = 0; break; case alignLeft: j->mRect.left = 0; break;
case alignCenter: j->Rect.left = excess/2; break; case alignCenter: j->mRect.left = excess/2; break;
case alignRight: j->Rect.left = excess; break; case alignRight: j->mRect.left = excess; break;
} }
j->Rect.right = j->Rect.left + width; j->mRect.right = j->mRect.left + width;
} }
if (curPageStop == curPageStart) if (curPageStop == curPageStart)
{ {
curPageStart = i->Rect.top; curPageStart = i->mRect.top;
curPageStop = i->Rect.top; curPageStop = i->mRect.top;
} }
int spaceLeft = mPageHeight - (curPageStop - curPageStart); int spaceLeft = mPageHeight - (curPageStop - curPageStart);
int sectionHeight = i->Rect.height (); int sectionHeight = i->mRect.height ();
if (sectionHeight <= mPageHeight) if (sectionHeight <= mPageHeight)
{ {
@ -361,13 +361,13 @@ struct TypesetBook::Typesetter : IBookTypesetter
{ {
assert (curPageStart != curPageStop); assert (curPageStart != curPageStop);
Book->Pages.push_back (page (curPageStart, curPageStop)); mBook->mPages.push_back (page (curPageStart, curPageStop));
curPageStart = i->Rect.top; curPageStart = i->mRect.top;
curPageStop = i->Rect.bottom; curPageStop = i->mRect.bottom;
} }
else else
curPageStop = i->Rect.bottom; curPageStop = i->mRect.bottom;
} }
else else
{ {
@ -376,14 +376,14 @@ struct TypesetBook::Typesetter : IBookTypesetter
} }
if (curPageStart != curPageStop) if (curPageStart != curPageStop)
Book->Pages.push_back (page (curPageStart, curPageStop)); mBook->mPages.push_back (page (curPageStart, curPageStop));
return Book; return mBook;
} }
void write_impl (style * Style, utf8_stream::point _begin, utf8_stream::point _end) void write_impl (Style * Style, utf8_stream::point _begin, utf8_stream::point _end)
{ {
int line_height = Style->Font->getDefaultHeight (); int line_height = Style->mFont->getDefaultHeight ();
utf8_stream stream (_begin, _end); utf8_stream stream (_begin, _end);
@ -392,7 +392,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
if (ucs_line_break (stream.peek ())) if (ucs_line_break (stream.peek ()))
{ {
stream.consume (); stream.consume ();
Line = NULL, Run = NULL; mLine = NULL, mRun = NULL;
continue; continue;
} }
@ -405,7 +405,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
while (!stream.eof () && !ucs_line_break (stream.peek ()) && ucs_breaking_space (stream.peek ())) while (!stream.eof () && !ucs_line_break (stream.peek ()) && ucs_breaking_space (stream.peek ()))
{ {
GlyphInfo* gi = Style->Font->getGlyphInfo (stream.peek ()); GlyphInfo* gi = Style->mFont->getGlyphInfo (stream.peek ());
space_width += gi->advance; space_width += gi->advance;
stream.consume (); stream.consume ();
} }
@ -414,7 +414,7 @@ struct TypesetBook::Typesetter : IBookTypesetter
while (!stream.eof () && !ucs_line_break (stream.peek ()) && !ucs_breaking_space (stream.peek ())) while (!stream.eof () && !ucs_line_break (stream.peek ()) && !ucs_breaking_space (stream.peek ()))
{ {
GlyphInfo* gi = Style->Font->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;
@ -426,77 +426,77 @@ struct TypesetBook::Typesetter : IBookTypesetter
if (lead == extent) if (lead == extent)
break; break;
int left = Line ? Line->Rect.right : 0; int left = mLine ? mLine->mRect.right : 0;
if (left + space_width + word_width > mPageWidth) if (left + space_width + word_width > mPageWidth)
{ {
Line = NULL, Run = NULL; mLine = NULL, mRun = NULL;
append_run (Style, origin, extent, extent - origin, word_width, Book->Rect.bottom + word_height); append_run (Style, origin, extent, extent - origin, word_width, mBook->mRect.bottom + word_height);
} }
else else
{ {
int top = Line ? Line->Rect.top : Book->Rect.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 (style * Style, utf8_stream::point begin, utf8_stream::point end, int pc, int right, int bottom) void append_run (Style * style, utf8_stream::point begin, utf8_stream::point end, int pc, int right, int bottom)
{ {
if (Section == NULL) if (mSection == NULL)
{ {
Book->Sections.push_back (section ()); mBook->mSections.push_back (Section ());
Section = &Book->Sections.back (); mSection = &mBook->mSections.back ();
Section->Rect = IntRect (0, Book->Rect.bottom, 0, Book->Rect.bottom); mSection->mRect = IntRect (0, mBook->mRect.bottom, 0, mBook->mRect.bottom);
mSectionAlignment.push_back (mCurrentAlignment); mSectionAlignment.push_back (mCurrentAlignment);
} }
if (Line == NULL) if (mLine == NULL)
{ {
Section->Lines.push_back (line ()); mSection->mLines.push_back (Line ());
Line = &Section->Lines.back (); mLine = &mSection->mLines.back ();
Line->Rect = IntRect (0, Section->Rect.bottom, 0, Book->Rect.bottom); mLine->mRect = IntRect (0, mSection->mRect.bottom, 0, mBook->mRect.bottom);
} }
if (Book->Rect.right < right) if (mBook->mRect.right < right)
Book->Rect.right = right; mBook->mRect.right = right;
if (Book->Rect.bottom < bottom) if (mBook->mRect.bottom < bottom)
Book->Rect.bottom = bottom; mBook->mRect.bottom = bottom;
if (Section->Rect.right < right) if (mSection->mRect.right < right)
Section->Rect.right = right; mSection->mRect.right = right;
if (Section->Rect.bottom < bottom) if (mSection->mRect.bottom < bottom)
Section->Rect.bottom = bottom; mSection->mRect.bottom = bottom;
if (Line->Rect.right < right) if (mLine->mRect.right < right)
Line->Rect.right = right; mLine->mRect.right = right;
if (Line->Rect.bottom < bottom) if (mLine->mRect.bottom < bottom)
Line->Rect.bottom = bottom; mLine->mRect.bottom = bottom;
if (Run == NULL || Run->Style != Style || Run->Range.second != begin) if (mRun == NULL || mRun->mStyle != style || mRun->mRange.second != begin)
{ {
int left = Run ? Run->Right : Line->Rect.left; int left = mRun ? mRun->mRight : mLine->mRect.left;
Line->Runs.push_back (run ()); mLine->mRuns.push_back (Run ());
Run = &Line->Runs.back (); mRun = &mLine->mRuns.back ();
Run->Style = Style; mRun->mStyle = style;
Run->Left = left; mRun->mLeft = left;
Run->Right = right; mRun->mRight = right;
Run->Range.first = begin; mRun->mRange.first = begin;
Run->Range.second = end; mRun->mRange.second = end;
Run->PrintableChars = pc; mRun->mPrintableChars = pc;
//Run->Locale = Locale; //Run->Locale = Locale;
} }
else else
{ {
Run->Right = right; mRun->mRight = right;
Run->Range.second = end; mRun->mRange.second = end;
Run->PrintableChars += pc; mRun->mPrintableChars += pc;
} }
} }
}; };
@ -508,7 +508,7 @@ IBookTypesetter::ptr IBookTypesetter::create (int pageWidth, int pageHeight)
namespace namespace
{ {
struct render_xform struct RenderXform
{ {
public: public:
@ -527,7 +527,7 @@ namespace
float hOffset; float hOffset;
float vOffset; float vOffset;
render_xform (ICroppedRectangle* croppedParent, RenderTargetInfo const & renderTargetInfo) RenderXform (ICroppedRectangle* croppedParent, RenderTargetInfo const & renderTargetInfo)
{ {
clipTop = croppedParent->_getMarginTop (); clipTop = croppedParent->_getMarginTop ();
clipLeft = croppedParent->_getMarginLeft (); clipLeft = croppedParent->_getMarginLeft ();
@ -590,27 +590,27 @@ namespace
} }
}; };
struct glyph_stream struct GlyphStream
{ {
float Z; float mZ;
uint32_t C; uint32_t mC;
IFont* mFont; IFont* mFont;
FloatPoint mOrigin; FloatPoint mOrigin;
FloatPoint mCursor; FloatPoint mCursor;
Vertex* mVertices; Vertex* mVertices;
render_xform mRenderXform; RenderXform mRenderXform;
MyGUI::VertexColourType mVertexColourType; MyGUI::VertexColourType mVertexColourType;
glyph_stream (IFont* font, float left, float top, float Z, GlyphStream (IFont* font, float left, float top, float Z,
Vertex* vertices, render_xform const & renderXform) : Vertex* vertices, RenderXform const & renderXform) :
Z(Z), mOrigin (left, top), mZ(Z), mOrigin (left, top),
mFont (font), mVertices (vertices), mFont (font), mVertices (vertices),
mRenderXform (renderXform) mRenderXform (renderXform)
{ {
mVertexColourType = RenderManager::getInstance().getVertexFormat(); mVertexColourType = RenderManager::getInstance().getVertexFormat();
} }
~glyph_stream () ~GlyphStream ()
{ {
} }
@ -618,14 +618,14 @@ namespace
void reset (float left, float top, Colour colour) void reset (float left, float top, Colour colour)
{ {
C = texture_utility::toColourARGB(colour) | 0xFF000000; mC = texture_utility::toColourARGB(colour) | 0xFF000000;
texture_utility::convertColour(C, mVertexColourType); texture_utility::convertColour(mC, mVertexColourType);
mCursor.left = mOrigin.left + left; mCursor.left = mOrigin.left + left;
mCursor.top = mOrigin.top + top; mCursor.top = mOrigin.top + top;
} }
void emit_glyph (wchar_t ch) void emitGlyph (wchar_t ch)
{ {
GlyphInfo* gi = mFont->getGlyphInfo (ch); GlyphInfo* gi = mFont->getGlyphInfo (ch);
@ -644,7 +644,7 @@ namespace
mCursor.left += gi->bearingX + gi->advance; mCursor.left += gi->bearingX + gi->advance;
} }
void emit_space (wchar_t ch) void emitSpace (wchar_t ch)
{ {
GlyphInfo* gi = mFont->getGlyphInfo (ch); GlyphInfo* gi = mFont->getGlyphInfo (ch);
@ -669,10 +669,10 @@ namespace
mVertices->x = pt.left; mVertices->x = pt.left;
mVertices->y = pt.top ; mVertices->y = pt.top ;
mVertices->z = Z; mVertices->z = mZ;
mVertices->u = U; mVertices->u = U;
mVertices->v = V; mVertices->v = V;
mVertices->colour = C; mVertices->colour = mC;
++mVertices; ++mVertices;
} }
@ -684,9 +684,9 @@ class MWGui::PageDisplay : public ISubWidgetText
MYGUI_RTTI_DERIVED(PageDisplay) MYGUI_RTTI_DERIVED(PageDisplay)
protected: protected:
typedef TypesetBook::section section; typedef TypesetBook::Section Section;
typedef TypesetBook::line line; typedef TypesetBook::Line Line;
typedef TypesetBook::run run; typedef TypesetBook::Run Run;
struct TextFormat : ISubWidget struct TextFormat : ISubWidget
{ {
@ -739,13 +739,15 @@ protected:
public: public:
typedef TypesetBook::style style; typedef TypesetBook::Style style;
typedef std::map <TextFormat::id, TextFormat*> active_text_formats;
int view_top; int mViewTop;
int view_bottom; int mViewBottom;
style* mFocusItem; style* mFocusItem;
bool mItemActive; bool mItemActive;
MouseButton mLastDown;
boost::function <void (intptr_t)> mLinkClicked; boost::function <void (intptr_t)> mLinkClicked;
@ -753,7 +755,6 @@ public:
size_t mPage; size_t mPage;
ILayerNode* mNode; ILayerNode* mNode;
typedef std::map <TextFormat::id, TextFormat*> active_text_formats;
active_text_formats mActiveTextFormats; active_text_formats mActiveTextFormats;
PageDisplay () PageDisplay ()
@ -761,8 +762,6 @@ public:
mPage = -1; mPage = -1;
} }
MouseButton mLastDown;
void dirtyFocusItem () void dirtyFocusItem ()
{ {
if (mFocusItem != 0) if (mFocusItem != 0)
@ -794,7 +793,7 @@ public:
_left -= mCroppedParent->getAbsoluteLeft (); _left -= mCroppedParent->getAbsoluteLeft ();
_top -= mCroppedParent->getAbsoluteTop (); _top -= mCroppedParent->getAbsoluteTop ();
style * Hit = mBook->hitTest (_left, view_top + _top); style * Hit = mBook->hitTest (_left, mViewTop + _top);
if (mLastDown == MouseButton::None) if (mLastDown == MouseButton::None)
{ {
@ -832,7 +831,7 @@ public:
if (mLastDown == MouseButton::None) if (mLastDown == MouseButton::None)
{ {
mFocusItem = mBook->hitTest (_left, view_top + _top); mFocusItem = mBook->hitTest (_left, mViewTop + _top);
mItemActive = true; mItemActive = true;
dirtyFocusItem (); dirtyFocusItem ();
@ -851,7 +850,7 @@ public:
if (mLastDown == _id) if (mLastDown == _id)
{ {
style * mItem = mBook->hitTest (_left, view_top + _top); style * mItem = mBook->hitTest (_left, mViewTop + _top);
bool clicked = mFocusItem == mItem; bool clicked = mFocusItem == mItem;
@ -861,8 +860,8 @@ public:
mLastDown = MouseButton::None; mLastDown = MouseButton::None;
if (clicked && mLinkClicked && mItem && mItem->InteractiveId != 0) if (clicked && mLinkClicked && mItem && mItem->mInteractiveId != 0)
mLinkClicked (mItem->InteractiveId); mLinkClicked (mItem->mInteractiveId);
} }
} }
@ -891,23 +890,23 @@ public:
mBook = newBook; mBook = newBook;
mPage = newPage; mPage = newPage;
if (newPage < mBook->Pages.size ()) if (newPage < mBook->mPages.size ())
{ {
view_top = mBook->Pages [newPage].first; mViewTop = mBook->mPages [newPage].first;
view_bottom = mBook->Pages [newPage].second; mViewBottom = mBook->mPages [newPage].second;
} }
else else
{ {
view_top = 0; mViewTop = 0;
view_bottom = 0; mViewBottom = 0;
} }
} }
else else
{ {
mBook.reset (); mBook.reset ();
mPage = -1; mPage = -1;
view_top = 0; mViewTop = 0;
view_bottom = 0; mViewBottom = 0;
} }
} }
else else
@ -919,15 +918,15 @@ public:
mPage = newPage; mPage = newPage;
if (newPage < mBook->Pages.size ()) if (newPage < mBook->mPages.size ())
{ {
view_top = mBook->Pages [newPage].first; mViewTop = mBook->mPages [newPage].first;
view_bottom = mBook->Pages [newPage].second; mViewBottom = mBook->mPages [newPage].second;
} }
else else
{ {
view_top = 0; mViewTop = 0;
view_bottom = 0; mViewBottom = 0;
} }
} }
} }
@ -938,9 +937,9 @@ public:
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.Style->Font; IFont* Font = Run.mStyle->mFont;
active_text_formats::iterator j = this_->mActiveTextFormats.find (Font); active_text_formats::iterator j = this_->mActiveTextFormats.find (Font);
@ -953,13 +952,13 @@ 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.PrintableChars * 6; j->second->mCountVertex += Run.mPrintableChars * 6;
} }
}; };
void createActiveFormats (boost::shared_ptr <TypesetBook> newBook) void createActiveFormats (boost::shared_ptr <TypesetBook> newBook)
{ {
newBook->visit_runs (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 (active_text_formats::iterator i = mActiveTextFormats.begin (); i != mActiveTextFormats.end (); ++i)
@ -1001,31 +1000,31 @@ public:
struct renderRun struct renderRun
{ {
PageDisplay * this_; PageDisplay * this_;
glyph_stream &glyphStream; GlyphStream &glyphStream;
renderRun (PageDisplay * this_, glyph_stream &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.Style->InteractiveId && (Run.Style == this_->mFocusItem); bool isActive = Run.mStyle->mInteractiveId && (Run.mStyle == this_->mFocusItem);
Colour colour = isActive ? (this_->mItemActive ? Run.Style->ActiveColour: Run.Style->HotColour) : Run.Style->NormalColour; Colour colour = isActive ? (this_->mItemActive ? Run.mStyle->mActiveColour: Run.mStyle->mHotColour) : Run.mStyle->mNormalColour;
glyphStream.reset (Section.Rect.left + Line.Rect.left + Run.Left, Line.Rect.top, colour); glyphStream.reset (Section.mRect.left + Line.mRect.left + Run.mLeft, Line.mRect.top, colour);
utf8_stream stream (Run.Range); utf8_stream stream (Run.mRange);
while (!stream.eof ()) while (!stream.eof ())
{ {
utf8_stream::unicode_char code_point = stream.consume (); utf8_stream::unicode_char code_point = stream.consume ();
if (!ucs_space (code_point)) if (!ucs_space (code_point))
glyphStream.emit_glyph (code_point); glyphStream.emitGlyph (code_point);
else else
glyphStream.emit_space (code_point); glyphStream.emitSpace (code_point);
} }
} }
}; };
@ -1040,15 +1039,15 @@ public:
Vertex* vertices = textFormat.mRenderItem->getCurrentVertexBuffer(); Vertex* vertices = textFormat.mRenderItem->getCurrentVertexBuffer();
render_xform renderXform (mCroppedParent, textFormat.mRenderItem->getRenderTarget()->getInfo()); RenderXform renderXform (mCroppedParent, textFormat.mRenderItem->getRenderTarget()->getInfo());
glyph_stream glyphStream (textFormat.mFont, mCoord.left, mCoord.top-view_top, GlyphStream glyphStream (textFormat.mFont, mCoord.left, mCoord.top-mViewTop,
-1 /*mNode->getNodeDepth()*/, vertices, renderXform); -1 /*mNode->getNodeDepth()*/, vertices, renderXform);
int visit_top = (std::max) (view_top, view_top + int (renderXform.clipTop )); int visit_top = (std::max) (mViewTop, mViewTop + int (renderXform.clipTop ));
int visit_bottom = (std::min) (view_bottom, view_top + int (renderXform.clipBottom)); int visit_bottom = (std::min) (mViewBottom, mViewTop + int (renderXform.clipBottom));
mBook->visit_runs (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);
} }

View file

@ -19,7 +19,7 @@ namespace MWGui
typedef intptr_t interactive_id; typedef intptr_t interactive_id;
/// Returns the number of pages in the document. /// Returns the number of pages in the document.
virtual int pageCount () const = 0; virtual size_t pageCount () const = 0;
/// Return the area covered by the document. The first /// Return the area covered by the document. The first
/// integer is the maximum with of any line. This is not /// integer is the maximum with of any line. This is not

View file

@ -60,7 +60,7 @@ namespace
{ {
typesetter->add_content (Entry.body ()); typesetter->add_content (Entry.body ());
Entry.visit_spans (addSpan (typesetter, body_style)); Entry.visitSpans (addSpan (typesetter, body_style));
} }
}; };
@ -233,7 +233,7 @@ book JournalBooks::createJournalBook ()
IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_journal_entries (0, addJournalEntry (typesetter, body, header, true)); Model->visitJournalEntries (0, addJournalEntry (typesetter, body, header, true));
return typesetter->complete (); return typesetter->complete ();
} }
@ -245,11 +245,11 @@ book JournalBooks::createTopicBook (uintptr_t topicId)
IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_topic_name (topicId, addTopicName (typesetter, header)); Model->visitTopicName (topicId, addTopicName (typesetter, header));
intptr_t contentId = typesetter->add_content (to_utf8_span (", \"")); intptr_t contentId = typesetter->add_content (to_utf8_span (", \""));
Model->visit_topic_entries (topicId, addTopicEntry (typesetter, body, header, contentId)); Model->visitTopicEntries (topicId, addTopicEntry (typesetter, body, header, contentId));
return typesetter->complete (); return typesetter->complete ();
} }
@ -261,9 +261,9 @@ book JournalBooks::createQuestBook (uintptr_t questId)
IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f)); IBookTypesetter::IStyle* header = typesetter->createStyle ("EB Garamond", MyGUI::Colour (0.60f, 0.00f, 0.00f));
IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_quest_name (questId, addQuestName (typesetter, header)); Model->visitQuestName (questId, addQuestName (typesetter, header));
Model->visit_journal_entries (questId, addJournalEntry (typesetter, body, header, false)); Model->visitJournalEntries (questId, addJournalEntry (typesetter, body, header, false));
return typesetter->complete (); return typesetter->complete ();
} }
@ -301,7 +301,7 @@ book JournalBooks::createTopicIndexBook (char character)
IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF); IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
IBookTypesetter::IStyle* style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_topic_names_starting_with (character, addTopicLink (typesetter, style)); Model->visitTopicNamesStartingWith (character, addTopicLink (typesetter, style));
return typesetter->complete (); return typesetter->complete ();
} }
@ -311,7 +311,7 @@ book JournalBooks::createQuestIndexBook (bool activeOnly)
IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF); IBookTypesetter::ptr typesetter = IBookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
IBookTypesetter::IStyle* base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black); IBookTypesetter::IStyle* base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
Model->visit_quest_names (activeOnly, addQuestLink (typesetter, base)); Model->visitQuestNames (activeOnly, addQuestLink (typesetter, base));
return typesetter->complete (); return typesetter->complete ();
} }

View file

@ -20,39 +20,39 @@ namespace MWGui { struct JournalViewModel; }
static void injectMonthName (std::ostream & os, int month); static void injectMonthName (std::ostream & os, int month);
template <typename string_t, typename value_t> template <typename string_t, typename value_t>
class keyword_search class KeywordSearch
{ {
public: public:
typedef typename string_t::const_iterator point; typedef typename string_t::const_iterator point;
struct match struct Match
{ {
point Beg; point mBeg;
point End; point mEnd;
value_t Value; 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, Root); seed_impl (/*std::move*/ (Keyword), /*std::move*/ (Value), 0, mRoot);
} }
void clear () void clear ()
{ {
Root.Children.clear (); mRoot.mChildren.clear ();
Root.Keyword.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 = Root.Children.find (std::tolower (*i, Locale)); typename Entry::childen_t::iterator candidate = mRoot.mChildren.find (std::tolower (*i, mLocale));
// no match, on to next character // no match, on to next character
if (candidate == Root.Children.end ()) if (candidate == mRoot.mChildren.end ())
continue; continue;
// see how far the match goes // see how far the match goes
@ -60,37 +60,37 @@ public:
while ((j + 1) != End) while ((j + 1) != End)
{ {
typename entry::childen_t::iterator next = candidate->second.Children.find (std::tolower (*++j, Locale)); typename Entry::childen_t::iterator next = candidate->second.mChildren.find (std::tolower (*++j, mLocale));
if (next == candidate->second.Children.end ()) if (next == candidate->second.mChildren.end ())
break; break;
candidate = next; candidate = next;
} }
// didn't match enough to disambiguate, on to next character // didn't match enough to disambiguate, on to next character
if (!candidate->second.Keyword.size ()) if (!candidate->second.mKeyword.size ())
continue; continue;
// match the rest of the keyword // match the rest of the keyword
typename string_t::const_iterator t = candidate->second.Keyword.begin () + (j - i); typename string_t::const_iterator t = candidate->second.mKeyword.begin () + (j - i);
while (j != End && t != candidate->second.Keyword.end ()) while (j != End && t != candidate->second.mKeyword.end ())
{ {
if (std::tolower (*j, Locale) != std::tolower (*t, Locale)) if (std::tolower (*j, mLocale) != std::tolower (*t, mLocale))
break; break;
++j, ++t; ++j, ++t;
} }
// didn't match full keyword, on to next character // didn't match full keyword, on to next character
if (t != candidate->second.Keyword.end ()) if (t != candidate->second.mKeyword.end ())
continue; continue;
// we did it, report the good news // we did it, report the good news
Match.Value = candidate->second.Value; Match.mValue = candidate->second.mValue;
Match.Beg = i; Match.mBeg = i;
Match.End = j; Match.mEnd = j;
return true; return true;
} }
@ -101,37 +101,37 @@ public:
private: private:
struct entry struct Entry
{ {
typedef std::map <wchar_t, entry> childen_t; typedef std::map <wchar_t, Entry> childen_t;
string_t Keyword; string_t mKeyword;
value_t Value; value_t mValue;
childen_t Children; 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), Locale); int ch = tolower (Keyword.at (Depth), mLocale);
typename entry::childen_t::iterator j = Entry.Children.find (ch); typename Entry::childen_t::iterator j = Entry.mChildren.find (ch);
if (j == Entry.Children.end ()) if (j == Entry.mChildren.end ())
{ {
Entry.Children [ch].Value = /*std::move*/ (Value); Entry.mChildren [ch].mValue = /*std::move*/ (Value);
Entry.Children [ch].Keyword = /*std::move*/ (Keyword); Entry.mChildren [ch].mKeyword = /*std::move*/ (Keyword);
} }
else else
{ {
if (j->second.Keyword.size () > 0) if (j->second.mKeyword.size () > 0)
{ {
if (Keyword == j->second.Keyword) 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.Value); value_t pushValue = /*std::move*/ (j->second.mValue);
string_t pushKeyword = /*std::move*/ (j->second.Keyword); string_t pushKeyword = /*std::move*/ (j->second.mKeyword);
j->second.Keyword.clear (); j->second.mKeyword.clear ();
if (Depth >= pushKeyword.size ()) if (Depth >= pushKeyword.size ())
throw std::runtime_error ("unexpected"); throw std::runtime_error ("unexpected");
@ -144,22 +144,22 @@ private:
} }
entry Root; Entry mRoot;
std::locale Locale; std::locale mLocale;
}; };
struct MWGui::JournalViewModel : IJournalViewModel struct MWGui::JournalViewModel : IJournalViewModel
{ {
typedef keyword_search <std::string, intptr_t> foobar; typedef KeywordSearch <std::string, intptr_t> keyword_search_t;
mutable bool FooBar_loaded; mutable bool mKeywordSearchLoaded;
mutable foobar FooBar; mutable keyword_search_t mKeywordSearch;
std::locale Locale; std::locale mLocale;
JournalViewModel () JournalViewModel ()
{ {
FooBar_loaded = false; mKeywordSearchLoaded = false;
} }
virtual ~JournalViewModel () virtual ~JournalViewModel ()
@ -167,7 +167,7 @@ struct MWGui::JournalViewModel : IJournalViewModel
} }
//TODO: replace this nasty BS //TODO: replace this nasty BS
static utf8_span to_utf8_span (std::string const & str) static utf8_span toUtf8Span (std::string const & str)
{ {
if (str.size () == 0) if (str.size () == 0)
return utf8_span (utf8_point (NULL), utf8_point (NULL)); return utf8_span (utf8_point (NULL), utf8_point (NULL));
@ -183,26 +183,26 @@ struct MWGui::JournalViewModel : IJournalViewModel
void unload () void unload ()
{ {
FooBar.clear (); mKeywordSearch.clear ();
FooBar_loaded = false; mKeywordSearchLoaded = false;
} }
void ensure_FooBar_loaded () const void ensureKeyWordSearchLoaded () const
{ {
if (!FooBar_loaded) if (!mKeywordSearchLoaded)
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
for(MWBase::Journal::TTopicIter 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)); mKeywordSearch.seed (i->first, intptr_t (&i->second));
FooBar_loaded = true; mKeywordSearchLoaded = true;
} }
} }
wchar_t tolower (wchar_t ch) const { return std::tolower (ch, Locale); } wchar_t tolower (wchar_t ch) const { return std::tolower (ch, mLocale); }
bool is_empty () const bool isEmpty () const
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
@ -210,25 +210,25 @@ struct MWGui::JournalViewModel : IJournalViewModel
} }
template <typename t_iterator, typename IInterface> template <typename t_iterator, typename IInterface>
struct base_entry : IInterface struct BaseEntry : IInterface
{ {
typedef t_iterator iterator_t; typedef t_iterator iterator_t;
iterator_t itr; iterator_t itr;
JournalViewModel const * Model; JournalViewModel const * Model;
base_entry (JournalViewModel const * Model, iterator_t itr) : BaseEntry (JournalViewModel const * Model, iterator_t itr) :
Model (Model), itr (itr), loaded (false) Model (Model), itr (itr), loaded (false)
{} {}
virtual ~base_entry () {} virtual ~BaseEntry () {}
mutable bool loaded; mutable bool loaded;
mutable std::string utf8text; mutable std::string utf8text;
virtual std::string getText () const = 0; virtual std::string getText () const = 0;
void ensure_loaded () const void ensureLoaded () const
{ {
if (!loaded) if (!loaded)
{ {
@ -239,28 +239,28 @@ struct MWGui::JournalViewModel : IJournalViewModel
utf8_span body () const utf8_span body () const
{ {
ensure_loaded (); ensureLoaded ();
return to_utf8_span (utf8text); return toUtf8Span (utf8text);
} }
void visit_spans (boost::function < void (topic_id, size_t, size_t)> visitor) const void visitSpans (boost::function < void (topic_id, size_t, size_t)> visitor) const
{ {
ensure_loaded (); ensureLoaded ();
Model->ensure_FooBar_loaded (); Model->ensureKeyWordSearchLoaded ();
std::string::const_iterator i = utf8text.begin (); std::string::const_iterator i = utf8text.begin ();
foobar::match Match; keyword_search_t::Match match;
while (i != utf8text.end () && Model->FooBar.search (i, utf8text.end (), Match)) while (i != utf8text.end () && Model->mKeywordSearch.search (i, utf8text.end (), match))
{ {
if (i != Match.Beg) if (i != match.mBeg)
visitor (0, i - utf8text.begin (), Match.Beg - utf8text.begin ()); visitor (0, i - utf8text.begin (), match.mBeg - utf8text.begin ());
visitor (Match.Value, Match.Beg - utf8text.begin (), Match.End - utf8text.begin ()); visitor (match.mValue, match.mBeg - utf8text.begin (), match.mEnd - utf8text.begin ());
i = Match.End; i = match.mEnd;
} }
if (i != utf8text.end ()) if (i != utf8text.end ())
@ -269,7 +269,7 @@ struct MWGui::JournalViewModel : IJournalViewModel
}; };
void visit_quest_names (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const void visitQuestNames (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get ().getJournal (); MWBase::Journal * journal = MWBase::Environment::get ().getJournal ();
@ -278,28 +278,28 @@ struct MWGui::JournalViewModel : IJournalViewModel
if (active_only && i->second.isFinished ()) if (active_only && i->second.isFinished ())
continue; continue;
visitor (reinterpret_cast <quest_id> (&i->second), to_utf8_span (i->first)); visitor (reinterpret_cast <quest_id> (&i->second), toUtf8Span (i->first));
} }
} }
void visit_quest_name (quest_id questId, boost::function <void (utf8_span)> visitor) const void visitQuestName (quest_id questId, boost::function <void (utf8_span)> visitor) const
{ {
MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId); MWDialogue::Quest const * quest = reinterpret_cast <MWDialogue::Quest const *> (questId);
std::string name = quest->getName (); std::string name = quest->getName ();
visitor (to_utf8_span (name)); visitor (toUtf8Span (name));
} }
template <typename iterator_t> template <typename iterator_t>
struct journal_entry : base_entry <iterator_t, IJournalEntry> struct JournalEntry : BaseEntry <iterator_t, IJournalEntry>
{ {
using base_entry <iterator_t, IJournalEntry>::itr; using BaseEntry <iterator_t, IJournalEntry>::itr;
mutable std::string timestamp_buffer; mutable std::string timestamp_buffer;
journal_entry (JournalViewModel const * Model, iterator_t itr) : JournalEntry (JournalViewModel const * Model, iterator_t itr) :
base_entry <iterator_t, IJournalEntry> (Model, itr) BaseEntry <iterator_t, IJournalEntry> (Model, itr)
{} {}
std::string getText () const std::string getText () const
@ -322,11 +322,11 @@ struct MWGui::JournalViewModel : IJournalViewModel
timestamp_buffer = os.str (); timestamp_buffer = os.str ();
} }
return to_utf8_span (timestamp_buffer); return toUtf8Span (timestamp_buffer);
} }
}; };
void visit_journal_entries (quest_id questId, boost::function <void (IJournalEntry const &)> visitor) const void visitJournalEntries (quest_id questId, boost::function <void (IJournalEntry const &)> visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
@ -339,51 +339,51 @@ struct MWGui::JournalViewModel : IJournalViewModel
for (MWDialogue::Topic::TEntryIter j = quest->begin (); j != quest->end (); ++j) for (MWDialogue::Topic::TEntryIter j = quest->begin (); j != quest->end (); ++j)
{ {
if (i->mInfoId == *j) if (i->mInfoId == *j)
visitor (journal_entry <MWBase::Journal::TEntryIter> (this, i)); visitor (JournalEntry <MWBase::Journal::TEntryIter> (this, i));
} }
} }
} }
else else
{ {
for(MWBase::Journal::TEntryIter i = journal->begin(); i != journal->end (); ++i) for(MWBase::Journal::TEntryIter i = journal->begin(); i != journal->end (); ++i)
visitor (journal_entry <MWBase::Journal::TEntryIter> (this, i)); visitor (JournalEntry <MWBase::Journal::TEntryIter> (this, i));
} }
} }
void visit_topics (boost::function <void (topic_id, utf8_span)> visitor) const void visitTopics (boost::function <void (topic_id, utf8_span)> visitor) const
{ {
throw std::runtime_error ("not implemented"); throw std::runtime_error ("not implemented");
} }
void visit_topic_name (topic_id topicId, boost::function <void (utf8_span)> visitor) const void visitTopicName (topic_id topicId, boost::function <void (utf8_span)> visitor) const
{ {
MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId); MWDialogue::Topic const & Topic = * reinterpret_cast <MWDialogue::Topic const *> (topicId);
visitor (to_utf8_span (Topic.getName ())); visitor (toUtf8Span (Topic.getName ()));
} }
void visit_topic_names_starting_with (int character, boost::function < void (topic_id , utf8_span) > visitor) const void visitTopicNamesStartingWith (int character, boost::function < void (topic_id , utf8_span) > visitor) const
{ {
MWBase::Journal * journal = MWBase::Environment::get().getJournal(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();
for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i) for (MWBase::Journal::TTopicIter i = journal->topicBegin (); i != journal->topicEnd (); ++i)
{ {
if (i->first [0] != std::tolower (character, Locale)) if (i->first [0] != std::tolower (character, mLocale))
continue; continue;
visitor (topic_id (&i->second), to_utf8_span (i->first)); visitor (topic_id (&i->second), toUtf8Span (i->first));
} }
} }
struct topicEntry : base_entry <MWDialogue::Topic::TEntryIter, ITopicEntry> struct topicEntry : BaseEntry <MWDialogue::Topic::TEntryIter, ITopicEntry>
{ {
MWDialogue::Topic const & Topic; MWDialogue::Topic const & Topic;
mutable std::string source_buffer; mutable std::string source_buffer;
topicEntry (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) BaseEntry (Model, itr), Topic (Topic)
{} {}
std::string getText () const std::string getText () const
@ -396,12 +396,12 @@ struct MWGui::JournalViewModel : IJournalViewModel
{ {
if (source_buffer.empty ()) if (source_buffer.empty ())
source_buffer = "someone"; source_buffer = "someone";
return to_utf8_span (source_buffer); return toUtf8Span (source_buffer);
} }
}; };
void visit_topic_entries (topic_id topicId, boost::function <void (ITopicEntry const &)> visitor) const void visitTopicEntries (topic_id topicId, boost::function <void (ITopicEntry const &)> visitor) const
{ {
typedef MWDialogue::Topic::TEntryIter iterator_t; typedef MWDialogue::Topic::TEntryIter iterator_t;

View file

@ -38,7 +38,7 @@ namespace MWGui
/// Visits each subset of text in the body, delivering the beginning /// Visits each subset of text in the body, delivering the beginning
/// and end of the span relative to the body, and a valid topic ID if /// and end of the span relative to the body, and a valid topic ID if
/// the span represents a keyword, or zero if not. /// the span represents a keyword, or zero if not.
virtual void visit_spans (boost::function <void (topic_id, size_t, size_t)> visitor) const = 0; virtual void visitSpans (boost::function <void (topic_id, size_t, size_t)> visitor) const = 0;
}; };
/// An interface to topic data. /// An interface to topic data.
@ -65,25 +65,25 @@ namespace MWGui
virtual void unload () = 0; virtual void unload () = 0;
/// returns true if their are no journal entries to display /// returns true if their are no journal entries to display
virtual bool is_empty () 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 visit_quest_name (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0; virtual void visitQuestName (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0;
/// walks the active and optionally completed, quests providing the quest id and name /// walks the active and optionally completed, quests providing the quest id and name
virtual void visit_quest_names (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const = 0; virtual void visitQuestNames (bool active_only, boost::function <void (quest_id, utf8_span)> visitor) const = 0;
/// walks over the journal entries related to the specified quest identified by its id /// walks over the journal entries related to the specified quest identified by its id
virtual void visit_journal_entries (quest_id questId, boost::function <void (IJournalEntry const &)> visitor) const = 0; virtual void visitJournalEntries (quest_id questId, boost::function <void (IJournalEntry const &)> visitor) const = 0;
/// provides the name of the topic specified by its id /// provides the name of the topic specified by its id
virtual void visit_topic_name (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0; virtual void visitTopicName (topic_id topicId, boost::function <void (utf8_span)> visitor) const = 0;
/// walks over the topics whose names start with the specified character providing the topics id and name /// walks over the topics whose names start with the specified character providing the topics id and name
virtual void visit_topic_names_starting_with (int character, boost::function < void (topic_id , utf8_span) > visitor) const = 0; virtual void visitTopicNamesStartingWith (int character, boost::function < void (topic_id , utf8_span) > visitor) const = 0;
/// walks over the topic entries for the topic specified by its identifier /// walks over the topic entries for the topic specified by its identifier
virtual void visit_topic_entries (topic_id topicId, boost::function <void (ITopicEntry const &)> visitor) const = 0; virtual void visitTopicEntries (topic_id topicId, boost::function <void (ITopicEntry const &)> visitor) const = 0;
// create an instance of the default journal view model implementation // create an instance of the default journal view model implementation
static ptr create (); static ptr create ();

View file

@ -25,40 +25,37 @@ using namespace MWGui;
namespace namespace
{ {
#define CONTROL_ID(name) \ static char const OptionsOverlay [] = "OptionsOverlay";
static char const name [] = #name static char const OptionsBTN [] = "OptionsBTN";
static char const PrevPageBTN [] = "PrevPageBTN";
CONTROL_ID(OptionsOverlay); static char const NextPageBTN [] = "NextPageBTN";
CONTROL_ID(OptionsBTN); static char const CloseBTN [] = "CloseBTN";
CONTROL_ID(PrevPageBTN); static char const JournalBTN [] = "JournalBTN";
CONTROL_ID(NextPageBTN); static char const TopicsBTN [] = "TopicsBTN";
CONTROL_ID(CloseBTN); static char const QuestsBTN [] = "QuestsBTN";
CONTROL_ID(JournalBTN); static char const CancelBTN [] = "CancelBTN";
CONTROL_ID(TopicsBTN); static char const ShowAllBTN [] = "ShowAllBTN";
CONTROL_ID(QuestsBTN); static char const ShowActiveBTN [] = "ShowActiveBTN";
CONTROL_ID(CancelBTN); static char const PageOneNum [] = "PageOneNum";
CONTROL_ID(ShowAllBTN); static char const PageTwoNum [] = "PageTwoNum";
CONTROL_ID(ShowActiveBTN); static char const TopicsList [] = "TopicsList";
CONTROL_ID(PageOneNum); static char const TopicsPage [] = "TopicsPage";
CONTROL_ID(PageTwoNum); static char const QuestsList [] = "QuestsList";
CONTROL_ID(TopicsList); static char const QuestsPage [] = "QuestsPage";
CONTROL_ID(TopicsPage); static char const LeftBookPage [] = "LeftBookPage";
CONTROL_ID(QuestsList); static char const RightBookPage [] = "RightBookPage";
CONTROL_ID(QuestsPage); static char const LeftTopicIndex [] = "LeftTopicIndex";
CONTROL_ID(LeftBookPage); static char const RightTopicIndex [] = "RightTopicIndex";
CONTROL_ID(RightBookPage);
CONTROL_ID(LeftTopicIndex);
CONTROL_ID(RightTopicIndex);
struct JournalWindow : WindowBase, JournalBooks, IJournalWindow struct JournalWindow : WindowBase, JournalBooks, IJournalWindow
{ {
struct display_state struct DisplayState
{ {
int mPage; int mPage;
book mBook; book mBook;
}; };
typedef std::stack <display_state> display_state_stack; typedef std::stack <DisplayState> display_state_stack;
display_state_stack mStates; display_state_stack mStates;
book mTopicIndexBook; book mTopicIndexBook;
@ -156,7 +153,7 @@ namespace
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->is_empty ()) if (Model->isEmpty ())
journalBook = createEmptyJournalBook (); journalBook = createEmptyJournalBook ();
else else
journalBook = createJournalBook (); journalBook = createJournalBook ();
@ -217,7 +214,7 @@ namespace
void pushBook (book Book, int Page) void pushBook (book Book, int Page)
{ {
display_state bs; DisplayState bs;
bs.mPage = Page; bs.mPage = Page;
bs.mBook = Book; bs.mBook = Book;
mStates.push (bs); mStates.push (bs);