2013-01-27 20:07:28 +00:00
|
|
|
#include "journalbooks.hpp"
|
|
|
|
|
|
|
|
using namespace MWGui;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::utf8_span to_utf8_span (char const * Text)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
typedef BookTypesetter::utf8_point point;
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
point begin = reinterpret_cast <point> (Text);
|
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
return BookTypesetter::utf8_span (begin, begin + strlen (Text));
|
2013-01-27 20:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const MyGUI::Colour linkHot (0.40f, 0.40f, 0.80f);
|
|
|
|
const MyGUI::Colour linkNormal (0.20f, 0.20f, 0.60f);
|
|
|
|
const MyGUI::Colour linkActive (0.50f, 0.50f, 1.00f);
|
|
|
|
|
|
|
|
struct addContent
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter;
|
|
|
|
BookTypesetter::Style* body_style;
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
addContent (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style) :
|
2013-01-27 20:07:28 +00:00
|
|
|
typesetter (typesetter), body_style (body_style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addSpan : addContent
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
addSpan (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style) :
|
2013-01-27 20:07:28 +00:00
|
|
|
addContent (typesetter, body_style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator () (intptr_t topicId, size_t begin, size_t end)
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* style = body_style;
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
if (topicId)
|
|
|
|
style = typesetter->createHotStyle (body_style, linkNormal, linkHot, linkActive, topicId);
|
|
|
|
|
|
|
|
typesetter->write (style, begin, end);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addEntry
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter;
|
|
|
|
BookTypesetter::Style* body_style;
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
addEntry (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style) :
|
2013-01-27 20:07:28 +00:00
|
|
|
typesetter (typesetter), body_style (body_style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void operator () (JournalViewModel::Entry const & Entry)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
|
|
|
typesetter->add_content (Entry.body ());
|
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Entry.visitSpans (addSpan (typesetter, body_style));
|
2013-01-27 20:07:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addJournalEntry : addEntry
|
|
|
|
{
|
|
|
|
bool add_header;
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* header_style;
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
addJournalEntry (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style,
|
|
|
|
BookTypesetter::Style* header_style, bool add_header) :
|
2013-01-27 20:07:28 +00:00
|
|
|
addEntry (typesetter, body_style),
|
|
|
|
header_style (header_style),
|
|
|
|
add_header (add_header)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void operator () (JournalViewModel::JournalEntry const & Entry)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
|
|
|
if (add_header)
|
|
|
|
{
|
|
|
|
typesetter->write (header_style, Entry.timestamp ());
|
|
|
|
typesetter->lineBreak ();
|
|
|
|
}
|
|
|
|
|
|
|
|
addEntry::operator () (Entry);
|
|
|
|
|
|
|
|
typesetter->sectionBreak (10);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addTopicEntry : addEntry
|
|
|
|
{
|
|
|
|
intptr_t contentId;
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* header_style;
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
addTopicEntry (BookTypesetter::ptr typesetter, BookTypesetter::Style* body_style,
|
|
|
|
BookTypesetter::Style* header_style, intptr_t contentId) :
|
2013-01-27 20:07:28 +00:00
|
|
|
addEntry (typesetter, body_style), header_style (header_style), contentId (contentId)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void operator () (JournalViewModel::TopicEntry const & Entry)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
|
|
|
typesetter->write (body_style, Entry.source ());
|
|
|
|
typesetter->write (body_style, 0, 3);// begin
|
|
|
|
|
|
|
|
addEntry::operator() (Entry);
|
|
|
|
|
|
|
|
typesetter->select_content (contentId);
|
|
|
|
typesetter->write (body_style, 2, 3);// end quote
|
|
|
|
|
|
|
|
typesetter->sectionBreak (10);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addTopicName : addContent
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
addTopicName (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) :
|
2013-01-27 20:07:28 +00:00
|
|
|
addContent (typesetter, style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void operator () (JournalViewModel::utf8_span topicName)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
|
|
|
typesetter->write (body_style, topicName);
|
|
|
|
typesetter->sectionBreak (10);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addQuestName : addContent
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
addQuestName (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) :
|
2013-01-27 20:07:28 +00:00
|
|
|
addContent (typesetter, style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void operator () (JournalViewModel::utf8_span topicName)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
|
|
|
typesetter->write (body_style, topicName);
|
|
|
|
typesetter->sectionBreak (10);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addTopicLink : addContent
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
addTopicLink (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) :
|
2013-01-27 20:07:28 +00:00
|
|
|
addContent (typesetter, style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void operator () (JournalViewModel::topic_id topicId, JournalViewModel::utf8_span name)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* link = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, topicId);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
typesetter->write (link, name);
|
|
|
|
typesetter->lineBreak ();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct addQuestLink : addContent
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
addQuestLink (BookTypesetter::ptr typesetter, BookTypesetter::Style* style) :
|
2013-01-27 20:07:28 +00:00
|
|
|
addContent (typesetter, style)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
void operator () (JournalViewModel::quest_id id, JournalViewModel::utf8_span name)
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* style = typesetter->createHotStyle (body_style, MyGUI::Colour::Black, linkHot, linkActive, id);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
typesetter->write (style, name);
|
|
|
|
typesetter->lineBreak ();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
typedef TypesetBook::ptr book;
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-07 04:02:00 +00:00
|
|
|
JournalBooks::JournalBooks (JournalViewModel::ptr Model) :
|
2013-01-27 20:07:28 +00:00
|
|
|
Model (Model)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
book JournalBooks::createEmptyJournalBook ()
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter = createTypesetter ();
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
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);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
typesetter->write (header, to_utf8_span ("You have no journal entries!"));
|
|
|
|
typesetter->lineBreak ();
|
|
|
|
typesetter->write (body, to_utf8_span ("You should have gone though the starting quest and got an initial quest."));
|
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* big = typesetter->createStyle ("EB Garamond 24", MyGUI::Colour::Black);
|
|
|
|
BookTypesetter::Style* test = typesetter->createStyle ("MonoFont", MyGUI::Colour::Blue);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
typesetter->sectionBreak (20);
|
|
|
|
typesetter->write (body, to_utf8_span (
|
|
|
|
"The layout engine doesn't currently support aligning fonts to "
|
|
|
|
"their baseline within a single line so the following text looks "
|
|
|
|
"funny. In order to properly implement it, a stupidly simple "
|
|
|
|
"change is needed in MyGUI to report the where the baseline is for "
|
|
|
|
"a particular font"
|
|
|
|
));
|
|
|
|
|
|
|
|
typesetter->sectionBreak (20);
|
|
|
|
typesetter->write (big, to_utf8_span ("big text g"));
|
|
|
|
typesetter->write (body, to_utf8_span (" проверяем только в дебаге"));
|
|
|
|
typesetter->write (body, to_utf8_span (" normal g"));
|
|
|
|
typesetter->write (big, to_utf8_span (" done g"));
|
|
|
|
|
|
|
|
typesetter->sectionBreak (20);
|
|
|
|
typesetter->write (test, to_utf8_span (
|
|
|
|
"int main (int argc,\n"
|
|
|
|
" char ** argv)\n"
|
|
|
|
"{\n"
|
|
|
|
" print (\"hello world!\\n\");\n"
|
|
|
|
" return 0;\n"
|
|
|
|
"}\n"
|
|
|
|
));
|
|
|
|
|
|
|
|
return typesetter->complete ();
|
|
|
|
}
|
|
|
|
|
|
|
|
book JournalBooks::createJournalBook ()
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter = createTypesetter ();
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
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);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Model->visitJournalEntries (0, addJournalEntry (typesetter, body, header, true));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
return typesetter->complete ();
|
|
|
|
}
|
|
|
|
|
|
|
|
book JournalBooks::createTopicBook (uintptr_t topicId)
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter = createTypesetter ();
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
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);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Model->visitTopicName (topicId, addTopicName (typesetter, header));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-09 18:44:20 +00:00
|
|
|
intptr_t contentId = typesetter->add_content (to_utf8_span (", \""));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Model->visitTopicEntries (topicId, addTopicEntry (typesetter, body, header, contentId));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
return typesetter->complete ();
|
|
|
|
}
|
|
|
|
|
|
|
|
book JournalBooks::createQuestBook (uintptr_t questId)
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter = createTypesetter ();
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
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);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Model->visitQuestName (questId, addQuestName (typesetter, header));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Model->visitJournalEntries (questId, addJournalEntry (typesetter, body, header, false));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
return typesetter->complete ();
|
|
|
|
}
|
|
|
|
|
|
|
|
book JournalBooks::createTopicIndexBook ()
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter = BookTypesetter::create (92, 250);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
typesetter->setSectionAlignment (BookTypesetter::alignCenter);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* body = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 26; ++i)
|
|
|
|
{
|
|
|
|
char ch = 'A' + i;
|
|
|
|
|
|
|
|
char buffer [32];
|
|
|
|
|
|
|
|
sprintf (buffer, "( %c )", ch);
|
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::Style* style = typesetter->createHotStyle (body, MyGUI::Colour::Black, linkHot, linkActive, ch);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
if (i == 13)
|
|
|
|
typesetter->sectionBreak ();
|
|
|
|
|
|
|
|
typesetter->write (style, to_utf8_span (buffer));
|
|
|
|
typesetter->lineBreak ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return typesetter->complete ();
|
|
|
|
}
|
|
|
|
|
|
|
|
book JournalBooks::createTopicIndexBook (char character)
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter = BookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
|
|
|
|
BookTypesetter::Style* style = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Model->visitTopicNamesStartingWith (character, addTopicLink (typesetter, style));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
return typesetter->complete ();
|
|
|
|
}
|
|
|
|
|
|
|
|
book JournalBooks::createQuestIndexBook (bool activeOnly)
|
|
|
|
{
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr typesetter = BookTypesetter::create (0x7FFFFFFF, 0x7FFFFFFF);
|
|
|
|
BookTypesetter::Style* base = typesetter->createStyle ("EB Garamond", MyGUI::Colour::Black);
|
2013-01-27 20:07:28 +00:00
|
|
|
|
2013-02-15 05:37:33 +00:00
|
|
|
Model->visitQuestNames (activeOnly, addQuestLink (typesetter, base));
|
2013-01-27 20:07:28 +00:00
|
|
|
|
|
|
|
return typesetter->complete ();
|
|
|
|
}
|
|
|
|
|
2013-03-06 17:25:50 +00:00
|
|
|
BookTypesetter::ptr JournalBooks::createTypesetter ()
|
2013-01-27 20:07:28 +00:00
|
|
|
{
|
|
|
|
//TODO: determine page size from layout...
|
2013-03-06 17:25:50 +00:00
|
|
|
return BookTypesetter::create (240, 300);
|
2013-01-27 20:07:28 +00:00
|
|
|
}
|