diff options
author | Ira Rice <irarice@gmail.com> | 2008-10-10 17:48:27 +0000 |
---|---|---|
committer | Ira Rice <irarice@gmail.com> | 2008-10-10 17:48:27 +0000 |
commit | 7729faaadff2e6f92d24f43e52d085f4b11be315 (patch) | |
tree | 282a8dd26928a0b71ee0262ff6c9f0e491708026 /src/gui | |
parent | 8d27447b01407d6605b1fed89fcd556572d8cfca (diff) | |
download | Mana-7729faaadff2e6f92d24f43e52d085f4b11be315.tar.gz Mana-7729faaadff2e6f92d24f43e52d085f4b11be315.tar.bz2 Mana-7729faaadff2e6f92d24f43e52d085f4b11be315.tar.xz Mana-7729faaadff2e6f92d24f43e52d085f4b11be315.zip |
Did a little bit of code cleanup (mostly from TMW changes) as well as
properly implemented line wrapping. Now, there are no more visual
artifacts for speech boxes, and it always chooses the most optimal box
size (which required that npc_text use it also. Do any other gui
classes use the textbox class?).
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/npc_text.cpp | 2 | ||||
-rw-r--r-- | src/gui/speechbubble.cpp | 8 | ||||
-rw-r--r-- | src/gui/textbox.cpp | 22 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 4 |
4 files changed, 18 insertions, 18 deletions
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 52f35a88..d51698fb 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -57,12 +57,14 @@ NpcTextDialog::NpcTextDialog(): void NpcTextDialog::setText(const std::string &text) { + mTextBox->setMinWidth(230); mTextBox->setTextWrapped(text); } void NpcTextDialog::addText(const std::string &text) { + mTextBox->setMinWidth(230); mTextBox->setTextWrapped(mTextBox->getText() + text + "\n"); } diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index d71ceedf..c5c653e7 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -61,8 +61,8 @@ SpeechBubble::SpeechBubble()//: void SpeechBubble::setText(const std::string mText) { - mSpeechBox->setTextWrapped( mText ); mSpeechBox->setMinWidth(140); + mSpeechBox->setTextWrapped( mText ); int numRows = mSpeechBox->getNumberOfRows(); @@ -76,10 +76,8 @@ void SpeechBubble::setText(const std::string mText) } else { - int width; - if (this->getCaption().length() > mText.length()) - width = getFont()->getWidth(this->getCaption()); - else + int width = getFont()->getWidth(this->getCaption()); + if (width < getFont()->getWidth(mText)) width = getFont()->getWidth(mText); setContentSize(width + 15, 30); mSpeechArea->setDimension(gcn::Rectangle(4, 15, width + 5, 17)); diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index 4976549f..e779a9bb 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -45,6 +45,7 @@ void TextBox::setTextWrapped(const std::string &text) std::stringstream wrappedStream; std::string::size_type newlinePos, lastNewlinePos = 0; + int minWidth = 0; do { @@ -60,8 +61,6 @@ void TextBox::setTextWrapped(const std::string &text) text.substr(lastNewlinePos, newlinePos - lastNewlinePos); std::string::size_type spacePos, lastSpacePos = 0; int xpos = 0; - mMinWidth = getWidth(); - bool longWord = false; do { @@ -77,25 +76,26 @@ void TextBox::setTextWrapped(const std::string &text) int width = getFont()->getWidth(word); - if (xpos != 0 && xpos + width + getFont()->getWidth(" ") < getWidth()) + if (xpos != 0 && xpos + width + getFont()->getWidth(" ") <= mMinWidth) { xpos += width + getFont()->getWidth(" "); wrappedStream << " " << word; } else if (lastSpacePos == 0) { - if (xpos > mMinWidth) - { - longWord = true; - mMinWidth = xpos; - } xpos += width; wrappedStream << word; } else { - if ((xpos < mMinWidth) && !longWord && spacePos != line.size()) - mMinWidth = xpos; + if (xpos > minWidth) + { + minWidth = xpos; + if (minWidth > mMinWidth) + { + mMinWidth = minWidth; + } + } xpos = width; wrappedStream << "\n" << word; } @@ -107,10 +107,10 @@ void TextBox::setTextWrapped(const std::string &text) { wrappedStream << "\n"; } - lastNewlinePos = newlinePos + 1; } while (newlinePos != text.size()); + mMinWidth = minWidth; gcn::TextBox::setText(wrappedStream.str()); } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index b052e4b6..5e9baa32 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -58,9 +58,9 @@ unsigned long fadler32(FILE *file) // Calculate Adler-32 checksum char *buffer = (char*) malloc(fileSize); - fread(buffer, 1, fileSize, file); + const size_t read = fread(buffer, 1, fileSize, file); unsigned long adler = adler32(0L, Z_NULL, 0); - adler = adler32(adler, (Bytef*) buffer, fileSize); + adler = adler32(adler, (Bytef*) buffer, read); free(buffer); return adler; |