projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
get_text_width() was broken. Fixed.
[supertux.git]
/
lib
/
video
/
font.cpp
diff --git
a/lib/video/font.cpp
b/lib/video/font.cpp
index
0ab700a
..
8f34991
100644
(file)
--- a/
lib/video/font.cpp
+++ b/
lib/video/font.cpp
@@
-74,15
+74,16
@@
float
Font::get_text_width(const std::string& text) const
{
/** Let's calculate the size of the biggest paragraph */
Font::get_text_width(const std::string& text) const
{
/** Let's calculate the size of the biggest paragraph */
- std::string::size_type l, hl;
- hl = 0; l =
-1
;
+ std::string::size_type l, hl
, ol
;
+ hl = 0; l =
0
;
while(true)
{
while(true)
{
+ ol = l;
l = text.find("\n", l+1);
if(l == std::string::npos)
break;
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();
}
if(hl == 0)
hl = text.size();
@@
-95,11
+96,11
@@
Font::get_text_height(const std::string& text) const
{
/** Let's calculate height of the text */
std::string::size_type l, hh;
{
/** Let's calculate height of the text */
std::string::size_type l, hh;
- hh = h; l =
-1
;
+ hh = h; l =
0
;
while(true)
{
l = text.find("\n", l+1);
while(true)
{
l = text.find("\n", l+1);
- if(l ==
(int)
std::string::npos)
+ if(l == std::string::npos)
break;
hh += h + 2;
}
break;
hh += h + 2;
}
@@
-116,31
+117,33
@@
Font::get_height() const
void
Font::draw(const std::string& text, const Vector& pos_, int allignment, Uint32 drawing_effect, int alpha)
{
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;
/* 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;
i = y = 0;
- while(
tru
e)
+ while(
!don
e)
{
l = text.find("\n", i);
if(l == std::string::npos)
{
{
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';
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;
draw_text(temp, pos + Vector(0,y), drawing_effect, alpha);
i = l+1;
@@
-217,7
+220,7
@@
void SuperTux::display_text_file(const std::string& file, float scroll_speed, Fo
// Split text string lines into a vector
names.clear();
// Split text string lines into a vector
names.clear();
-
unsigned int
i, l;
+
std::string::size_type
i, l;
i = 0;
while(true)
{
i = 0;
while(true)
{