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 | |
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?).
-rw-r--r-- | src/animatedsprite.cpp | 16 | ||||
-rw-r--r-- | src/being.cpp | 2 | ||||
-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 | ||||
-rw-r--r-- | src/particleemitter.cpp | 5 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 5 | ||||
-rw-r--r-- | src/simpleanimation.cpp | 5 |
9 files changed, 27 insertions, 42 deletions
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index dd43e0f1..34ea60f4 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -195,23 +195,11 @@ AnimatedSprite::setDirection(SpriteDirection direction) int AnimatedSprite::getWidth() const { - if (mFrame) - { - return mFrame->image->getWidth(); - } - else { - return 0; - } + return mframe ? mFrame->image->getWidth() : 0; } int AnimatedSprite::getHeight() const { - if (mFrame) - { - return mFrame->image->getHeight(); - } - else { - return 0; - } + return mFrame ? mFrame->image->getHeight() : 0; } diff --git a/src/being.cpp b/src/being.cpp index 1d7f5ee7..a30bf465 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -443,9 +443,9 @@ void Being::drawSpeech(Graphics *graphics, int offsetX, int offsetY) mSpeechBubble->setWindowName(mName); // Not quite centered, but close enough. However, it's not too important to get // it right right now, as it doesn't take bubble collision into account yet. + mSpeechBubble->setText( mSpeech ); mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() * 4 / 11), py - 70 - (mSpeechBubble->getNumRows()*14)); - mSpeechBubble->setText( mSpeech ); mSpeechBubble->setVisible(true); } else if (mSpeechTime == 0) 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; diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 3e0a3d75..816a5d28 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -213,7 +213,7 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * if (!img) { - logger->log("No image at index " + (index)); + logger->log("No image at index %d", index); continue; } @@ -236,8 +236,7 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * if (!img) { - logger->log("No image at index " + - (start)); + logger->log("No image at index %d", start); continue; } diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index ebc60240..a6d8891e 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -232,7 +232,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, if (!img) { - logger->log("No image at index " + (index + variant_offset)); + logger->log("No image at index %d", index + variant_offset); continue; } @@ -255,8 +255,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, if (!img) { - logger->log("No image at index " + - (start + variant_offset)); + logger->log("No image at index %d", start + variant_offset); continue; } diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp index db1c0c91..a75a3392 100644 --- a/src/simpleanimation.cpp +++ b/src/simpleanimation.cpp @@ -68,7 +68,7 @@ SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): if (!img) { - logger->log("No image at index " + (index)); + logger->log("No image at index %d", index); continue; } @@ -91,8 +91,7 @@ SimpleAnimation::SimpleAnimation(xmlNodePtr animationNode): if (!img) { - logger->log("No image at index " + - (start)); + logger->log("No image at index %d", start); continue; } |