summaryrefslogtreecommitdiff
path: root/src/interface/Label.cpp
diff options
context:
space:
mode:
authorbuild.powdertoy.co.uk <admin@powdertoy.co.uk>2012-07-20 19:10:56 (GMT)
committer build.powdertoy.co.uk <admin@powdertoy.co.uk>2012-07-20 19:10:56 (GMT)
commite77a43d9a4c8c149b26037ce0751bb944c63b3c4 (patch)
tree411058fe9d2a8e0d034c3d9eb64dd831ecfa9f5e /src/interface/Label.cpp
parentd328b84b1330b0e8f3a7f87ce48b9b20ea4b6d01 (diff)
parent0064152442cef712e940b1abce246da9c698f6d3 (diff)
downloadpowder-e77a43d9a4c8c149b26037ce0751bb944c63b3c4.zip
powder-e77a43d9a4c8c149b26037ce0751bb944c63b3c4.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/interface/Label.cpp')
-rw-r--r--src/interface/Label.cpp65
1 files changed, 38 insertions, 27 deletions
diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp
index 35b2000..76ea45f 100644
--- a/src/interface/Label.cpp
+++ b/src/interface/Label.cpp
@@ -48,40 +48,51 @@ void Label::SetText(std::string text)
void Label::updateMultiline()
{
- char * rawText = new char[text.length()+1];
- std::copy(text.begin(), text.end(), rawText);
- rawText[text.length()] = 0;
-
int lines = 1;
- int currentWidth = 0;
- char * lastSpace = NULL;
- char * currentWord = rawText;
- char * nextSpace;
- while(true)
+ if(text.length()>0)
{
- nextSpace = strchr(currentWord+1, ' ');
- if(nextSpace)
- nextSpace[0] = 0;
- int width = Graphics::textwidth(currentWord);
- if(width+currentWidth > Size.X-6)
+ char * rawText = new char[text.length()+1];
+ std::copy(text.begin(), text.end(), rawText);
+ rawText[text.length()] = 0;
+
+ int currentWidth = 0;
+ char * lastSpace = NULL;
+ char * currentWord = rawText;
+ char * nextSpace;
+ while(true)
{
- currentWidth = width;
- currentWord[0] = '\n';
- lines++;
+ nextSpace = strchr(currentWord+1, ' ');
+ if(nextSpace)
+ nextSpace[0] = 0;
+ int width = Graphics::textwidth(currentWord);
+ if(width+currentWidth > Size.X-6)
+ {
+ currentWidth = width;
+ currentWord[0] = '\n';
+ lines++;
+ }
+ else
+ currentWidth += width;
+ if(nextSpace)
+ nextSpace[0] = ' ';
+ if(!currentWord[0] || !currentWord[1] || !(currentWord = strchr(currentWord+1, ' ')))
+ break;
}
- else
- currentWidth += width;
- if(nextSpace)
- nextSpace[0] = ' ';
- if(!(currentWord = strchr(currentWord+1, ' ')))
- break;
+ if(autoHeight)
+ {
+ Size.Y = lines*12;
+ }
+ textLines = std::string(rawText);
+ delete[] rawText;
}
- if(autoHeight)
+ else
{
- Size.Y = lines*12;
+ if(autoHeight)
+ {
+ Size.Y = 12;
+ }
+ textLines = std::string("");
}
- textLines = std::string(rawText);
- delete[] rawText;
}
std::string Label::GetText()