Update of /cvsroot/super-tux/supertux/lib/video
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9169/lib/video
Modified Files:
font.cpp
Log Message:
get_text_width() was broken. Fixed.
Also, made all text being alligned in draw_text(), instead of a floated alligned text. Might be good to allow a setup of this.
Index: font.cpp
===================================================================
RCS file: /cvsroot/super-tux/supertux/lib/video/font.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- font.cpp 15 Oct 2004 22:40:47 -0000 1.12
+++ font.cpp 16 Oct 2004 11:20:28 -0000 1.13
@@ -74,15 +74,16 @@
Font::get_text_width(const std::string& text) const
{
/** Let's calculate the size of the biggest paragraph */
- std::string::size_type l, hl;
+ std::string::size_type l, hl, ol;
hl = 0; l = 0;
while(true)
{
+ ol = l;
l = text.find("\n", l+1);
if(l == std::string::npos)
break;
- if(hl < l)
- hl = l;
+ if(hl < l-ol)
+ hl = l-ol;
}
if(hl == 0)
hl = text.size();
@@ -99,7 +100,7 @@
while(true)
{
l = text.find("\n", l+1);
- if(l == (int)std::string::npos)
+ if(l == std::string::npos)
break;
hh += h + 2;
}
@@ -116,31 +117,33 @@
void
Font::draw(const std::string& text, const Vector& pos_, int allignment, Uint32 drawing_effect, int alpha)
{
- // calculate X positions based on the allignment type
- Vector pos = Vector(pos_);
- if(allignment == CENTER_ALLIGN)
- pos.x -= get_text_width(text) / 2;
- else if(allignment == RIGHT_ALLIGN)
- pos.x -= get_text_width(text);
-
/* Cut lines changes into seperate strings, needed to support center/right text
allignments with break lines.
Feel free to replace this hack with a more elegant solution
*/
char temp[1024];
std::string::size_type l, i, y;
+ bool done = false;
i = y = 0;
- while(true)
+ while(!done)
{
l = text.find("\n", i);
if(l == std::string::npos)
{
- temp[text.copy(temp, text.size() - i, i)] = '\0';
- draw_text(temp, pos + Vector(0,y), drawing_effect, alpha);
- break;
+ l = text.size();
+ done = true;
}
+
temp[text.copy(temp, l - i, i)] = '\0';
+
+ // calculate X positions based on the allignment type
+ Vector pos = Vector(pos_);
+ if(allignment == CENTER_ALLIGN)
+ pos.x -= get_text_width(temp) / 2;
+ else if(allignment == RIGHT_ALLIGN)
+ pos.x -= get_text_width(temp);
+
draw_text(temp, pos + Vector(0,y), drawing_effect, alpha);
i = l+1;
|