From 428d0ce820d351653185de7105361fdd8dc4e901 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 30 Dec 2011 11:39:17 +0100 Subject: [PATCH] journal formating. Problems with french accents. --- apps/openmw/mwgui/journalwindow.cpp | 73 ++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index c42e6de88..9b85e0e0c 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -4,19 +4,31 @@ #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" +struct book +{ + int endLine; + std::list pages; +}; -std::list formatText(std::string text) +book formatText(std::string text,book mBook,int maxLine, int lineSize) { - std::cout << "\n \n \n"; - std::list stringList; //stringList.push_back(""); - int maxLine = 10; - int lineSize = 20; int cLineSize = 0; - int cLine = 0; + int cLine = mBook.endLine +1; std::string cString; + if(mBook.pages.empty()) + { + cString = ""; + cLine = 0; + } + else + { + cString = mBook.pages.back() + std::string("\n"); + mBook.pages.pop_back(); + } + std::string::iterator wordBegin = text.begin(); std::string::iterator wordEnd; @@ -24,17 +36,14 @@ std::list formatText(std::string text) while(cText.length() != 0) { - std::cout << "a"; size_t firstSpace = cText.find_first_of(' '); if(firstSpace == std::string::npos) { cString = cString + cText; - stringList.push_back(cString); + mBook.pages.push_back(cString); //TODO:finnish this - std::cout << "brerak?"; break; } - std::cout << "notbreak"; if(firstSpace + cLineSize <= lineSize) { cLineSize = firstSpace + cLineSize; @@ -51,16 +60,16 @@ std::list formatText(std::string text) else { cLine = 0; - stringList.push_back(cString); + mBook.pages.push_back(cString); cString = cText.substr(0,firstSpace +1); } } //std::cout << cText << "\n"; - std::cout << cText.length(); - if(firstSpace == cText.length()) std::cout << "maxi error en veu"; + //std::cout << cText.length(); cText = cText.substr(firstSpace +1,cText.length() - firstSpace -1); } - return stringList; + mBook.endLine = cLine; + return mBook; //std::string } @@ -99,8 +108,40 @@ void MWGui::JournalWindow::open() { if(mWindowManager.getEnvironment().mJournal->begin()!=mWindowManager.getEnvironment().mJournal->end()) { - std::string a = mWindowManager.getEnvironment().mJournal->begin()->getText(mWindowManager.getEnvironment().mWorld->getStore()); - std::cout << a; + std::vector leftPages; + std::vector rightPages; + + book journal; + journal.endLine = 0; + + for(std::deque::const_iterator it = mWindowManager.getEnvironment().mJournal->begin();it!=mWindowManager.getEnvironment().mJournal->end();it++) + { + std::string a = it->getText(mWindowManager.getEnvironment().mWorld->getStore()); + std::cout << a; + journal = formatText(a,journal,10,20); + journal.endLine = journal.endLine +1; + journal.pages.back() = journal.pages.back() + std::string("\n"); + } + //std::string a = mWindowManager.getEnvironment().mJournal->begin()->getText(mWindowManager.getEnvironment().mWorld->getStore()); + //std::list journal = formatText(a,10,20,1); + bool left = true; + for(std::list::iterator it = journal.pages.begin(); it != journal.pages.end();it++) + { + if(left) + { + leftPages.push_back(*it); + } + else + { + rightPages.push_back(*it); + } + left = !left; + } + if(!left) rightPages.push_back(""); + + displayLeftText(leftPages.back()); + displayRightText(rightPages.back()); + } else {