Commit e373bc4c authored by cutealien's avatar cutealien

Merged revision 3847 from 1.7 branch. Fix problems in textwrapping in...

Merged revision 3847 from 1.7 branch. Fix problems in textwrapping in CGUIStaticText. Did use wrong size and did ignore last word of the text. NOTE: this will need some more work now in trunk as trunk supports by now right-to-left text which probably needs similar fixes. 


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3874 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 0e61ebeb
...@@ -286,6 +286,8 @@ The following names can be queried for the given types: ...@@ -286,6 +286,8 @@ The following names can be queried for the given types:
----------------------------- -----------------------------
Changes in 1.7.3 (??.??.2011) Changes in 1.7.3 (??.??.2011)
- Fix problems in Textwrapping in CGUIStaticText. Did use wrong size and did ignore last word of the text in wrapping (thx @ Reiko for bugreport)
- Fix crash in collada (.dae) loading - Fix crash in collada (.dae) loading
- Fix memory-leaks in example 22 MaterialViewer - Fix memory-leaks in example 22 MaterialViewer
......
...@@ -288,26 +288,29 @@ void CGUIStaticText::breakText() ...@@ -288,26 +288,29 @@ void CGUIStaticText::breakText()
BrokenText.clear(); BrokenText.clear();
IGUISkin* skin = Environment->getSkin();
IGUIFont* font = getActiveFont(); IGUIFont* font = getActiveFont();
if (!font) if (!font)
return; return;
LastBreakFont = font; LastBreakFont = font;
core::stringw line;
core::stringw word;
core::stringw whitespace;
s32 size = Text.size();
s32 length = 0;
s32 elWidth = RelativeRect.getWidth();
if (Border)
elWidth -= 2*skin->getSize(EGDS_TEXT_DISTANCE_X);
wchar_t c;
// We have to deal with right-to-left and left-to-right differently // We have to deal with right-to-left and left-to-right differently
// However, most parts of the following code is the same, it's just // However, most parts of the following code is the same, it's just
// some order and boundaries which change. // some order and boundaries which change.
if (!RightToLeft) if (!RightToLeft)
{ {
// regular (left-to-right) // regular (left-to-right)
core::stringw line;
core::stringw word;
core::stringw whitespace;
s32 size = Text.size();
s32 length = 0;
s32 elWidth = RelativeRect.getWidth() - 6;
wchar_t c;
for (s32 i=0; i<size; ++i) for (s32 i=0; i<size; ++i)
{ {
c = Text[i]; c = Text[i];
...@@ -329,7 +332,14 @@ void CGUIStaticText::breakText() ...@@ -329,7 +332,14 @@ void CGUIStaticText::breakText()
c = '\0'; c = '\0';
} }
if (c==L' ' || c==0 || i==(size-1)) bool isWhitespace = (c == L' ' || c == 0);
if ( !isWhitespace )
{
// part of a word
word += c;
}
if ( isWhitespace || i == (size-1))
{ {
if (word.size()) if (word.size())
{ {
...@@ -383,7 +393,10 @@ void CGUIStaticText::breakText() ...@@ -383,7 +393,10 @@ void CGUIStaticText::breakText()
whitespace = L""; whitespace = L"";
} }
whitespace += c; if ( isWhitespace )
{
whitespace += c;
}
// compute line break // compute line break
if (lineBreak) if (lineBreak)
...@@ -397,11 +410,6 @@ void CGUIStaticText::breakText() ...@@ -397,11 +410,6 @@ void CGUIStaticText::breakText()
length = 0; length = 0;
} }
} }
else
{
// yippee this is a word..
word += c;
}
} }
line += whitespace; line += whitespace;
...@@ -411,14 +419,6 @@ void CGUIStaticText::breakText() ...@@ -411,14 +419,6 @@ void CGUIStaticText::breakText()
else else
{ {
// right-to-left // right-to-left
core::stringw line;
core::stringw word;
core::stringw whitespace;
s32 size = Text.size();
s32 length = 0;
s32 elWidth = RelativeRect.getWidth() - 6;
wchar_t c;
for (s32 i=size; i>=0; --i) for (s32 i=size; i>=0; --i)
{ {
c = Text[i]; c = Text[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment