aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CGUIStaticText.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CGUIStaticText.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CGUIStaticText.cpp1260
1 files changed, 630 insertions, 630 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CGUIStaticText.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CGUIStaticText.cpp
index ea934d3..39908bd 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CGUIStaticText.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CGUIStaticText.cpp
@@ -1,630 +1,630 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CGUIStaticText.h" 5#include "CGUIStaticText.h"
6#ifdef _IRR_COMPILE_WITH_GUI_ 6#ifdef _IRR_COMPILE_WITH_GUI_
7 7
8#include "IGUISkin.h" 8#include "IGUISkin.h"
9#include "IGUIEnvironment.h" 9#include "IGUIEnvironment.h"
10#include "IGUIFont.h" 10#include "IGUIFont.h"
11#include "IVideoDriver.h" 11#include "IVideoDriver.h"
12#include "rect.h" 12#include "rect.h"
13 13
14namespace irr 14namespace irr
15{ 15{
16namespace gui 16namespace gui
17{ 17{
18 18
19//! constructor 19//! constructor
20CGUIStaticText::CGUIStaticText(const wchar_t* text, bool border, 20CGUIStaticText::CGUIStaticText(const wchar_t* text, bool border,
21 IGUIEnvironment* environment, IGUIElement* parent, 21 IGUIEnvironment* environment, IGUIElement* parent,
22 s32 id, const core::rect<s32>& rectangle, 22 s32 id, const core::rect<s32>& rectangle,
23 bool background) 23 bool background)
24: IGUIStaticText(environment, parent, id, rectangle), 24: IGUIStaticText(environment, parent, id, rectangle),
25 HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_UPPERLEFT), 25 HAlign(EGUIA_UPPERLEFT), VAlign(EGUIA_UPPERLEFT),
26 Border(border), OverrideColorEnabled(false), OverrideBGColorEnabled(false), WordWrap(false), Background(background), 26 Border(border), OverrideColorEnabled(false), OverrideBGColorEnabled(false), WordWrap(false), Background(background),
27 RestrainTextInside(true), RightToLeft(false), 27 RestrainTextInside(true), RightToLeft(false),
28 OverrideColor(video::SColor(101,255,255,255)), BGColor(video::SColor(101,210,210,210)), 28 OverrideColor(video::SColor(101,255,255,255)), BGColor(video::SColor(101,210,210,210)),
29 OverrideFont(0), LastBreakFont(0) 29 OverrideFont(0), LastBreakFont(0)
30{ 30{
31 #ifdef _DEBUG 31 #ifdef _DEBUG
32 setDebugName("CGUIStaticText"); 32 setDebugName("CGUIStaticText");
33 #endif 33 #endif
34 34
35 Text = text; 35 Text = text;
36 if (environment && environment->getSkin()) 36 if (environment && environment->getSkin())
37 { 37 {
38 BGColor = environment->getSkin()->getColor(gui::EGDC_3D_FACE); 38 BGColor = environment->getSkin()->getColor(gui::EGDC_3D_FACE);
39 } 39 }
40} 40}
41 41
42 42
43//! destructor 43//! destructor
44CGUIStaticText::~CGUIStaticText() 44CGUIStaticText::~CGUIStaticText()
45{ 45{
46 if (OverrideFont) 46 if (OverrideFont)
47 OverrideFont->drop(); 47 OverrideFont->drop();
48} 48}
49 49
50 50
51//! draws the element and its children 51//! draws the element and its children
52void CGUIStaticText::draw() 52void CGUIStaticText::draw()
53{ 53{
54 if (!IsVisible) 54 if (!IsVisible)
55 return; 55 return;
56 56
57 IGUISkin* skin = Environment->getSkin(); 57 IGUISkin* skin = Environment->getSkin();
58 if (!skin) 58 if (!skin)
59 return; 59 return;
60 video::IVideoDriver* driver = Environment->getVideoDriver(); 60 video::IVideoDriver* driver = Environment->getVideoDriver();
61 61
62 core::rect<s32> frameRect(AbsoluteRect); 62 core::rect<s32> frameRect(AbsoluteRect);
63 63
64 // draw background 64 // draw background
65 65
66 if (Background) 66 if (Background)
67 { 67 {
68 if ( !OverrideBGColorEnabled ) // skin-colors can change 68 if ( !OverrideBGColorEnabled ) // skin-colors can change
69 BGColor = skin->getColor(gui::EGDC_3D_FACE); 69 BGColor = skin->getColor(gui::EGDC_3D_FACE);
70 70
71 driver->draw2DRectangle(BGColor, frameRect, &AbsoluteClippingRect); 71 driver->draw2DRectangle(BGColor, frameRect, &AbsoluteClippingRect);
72 } 72 }
73 73
74 // draw the border 74 // draw the border
75 75
76 if (Border) 76 if (Border)
77 { 77 {
78 skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect); 78 skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect);
79 frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X); 79 frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
80 } 80 }
81 81
82 // draw the text 82 // draw the text
83 if (Text.size()) 83 if (Text.size())
84 { 84 {
85 IGUIFont* font = getActiveFont(); 85 IGUIFont* font = getActiveFont();
86 86
87 if (font) 87 if (font)
88 { 88 {
89 if (!WordWrap) 89 if (!WordWrap)
90 { 90 {
91 if (VAlign == EGUIA_LOWERRIGHT) 91 if (VAlign == EGUIA_LOWERRIGHT)
92 { 92 {
93 frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y - 93 frameRect.UpperLeftCorner.Y = frameRect.LowerRightCorner.Y -
94 font->getDimension(L"A").Height - font->getKerningHeight(); 94 font->getDimension(L"A").Height - font->getKerningHeight();
95 } 95 }
96 if (HAlign == EGUIA_LOWERRIGHT) 96 if (HAlign == EGUIA_LOWERRIGHT)
97 { 97 {
98 frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 98 frameRect.UpperLeftCorner.X = frameRect.LowerRightCorner.X -
99 font->getDimension(Text.c_str()).Width; 99 font->getDimension(Text.c_str()).Width;
100 } 100 }
101 101
102 font->draw(Text.c_str(), frameRect, 102 font->draw(Text.c_str(), frameRect,
103 OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), 103 OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
104 HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER, (RestrainTextInside ? &AbsoluteClippingRect : NULL)); 104 HAlign == EGUIA_CENTER, VAlign == EGUIA_CENTER, (RestrainTextInside ? &AbsoluteClippingRect : NULL));
105 } 105 }
106 else 106 else
107 { 107 {
108 if (font != LastBreakFont) 108 if (font != LastBreakFont)
109 breakText(); 109 breakText();
110 110
111 core::rect<s32> r = frameRect; 111 core::rect<s32> r = frameRect;
112 s32 height = font->getDimension(L"A").Height + font->getKerningHeight(); 112 s32 height = font->getDimension(L"A").Height + font->getKerningHeight();
113 s32 totalHeight = height * BrokenText.size(); 113 s32 totalHeight = height * BrokenText.size();
114 if (VAlign == EGUIA_CENTER) 114 if (VAlign == EGUIA_CENTER)
115 { 115 {
116 r.UpperLeftCorner.Y = r.getCenter().Y - (totalHeight / 2); 116 r.UpperLeftCorner.Y = r.getCenter().Y - (totalHeight / 2);
117 } 117 }
118 else if (VAlign == EGUIA_LOWERRIGHT) 118 else if (VAlign == EGUIA_LOWERRIGHT)
119 { 119 {
120 r.UpperLeftCorner.Y = r.LowerRightCorner.Y - totalHeight; 120 r.UpperLeftCorner.Y = r.LowerRightCorner.Y - totalHeight;
121 } 121 }
122 122
123 for (u32 i=0; i<BrokenText.size(); ++i) 123 for (u32 i=0; i<BrokenText.size(); ++i)
124 { 124 {
125 if (HAlign == EGUIA_LOWERRIGHT) 125 if (HAlign == EGUIA_LOWERRIGHT)
126 { 126 {
127 r.UpperLeftCorner.X = frameRect.LowerRightCorner.X - 127 r.UpperLeftCorner.X = frameRect.LowerRightCorner.X -
128 font->getDimension(BrokenText[i].c_str()).Width; 128 font->getDimension(BrokenText[i].c_str()).Width;
129 } 129 }
130 130
131 font->draw(BrokenText[i].c_str(), r, 131 font->draw(BrokenText[i].c_str(), r,
132 OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), 132 OverrideColorEnabled ? OverrideColor : skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
133 HAlign == EGUIA_CENTER, false, (RestrainTextInside ? &AbsoluteClippingRect : NULL)); 133 HAlign == EGUIA_CENTER, false, (RestrainTextInside ? &AbsoluteClippingRect : NULL));
134 134
135 r.LowerRightCorner.Y += height; 135 r.LowerRightCorner.Y += height;
136 r.UpperLeftCorner.Y += height; 136 r.UpperLeftCorner.Y += height;
137 } 137 }
138 } 138 }
139 } 139 }
140 } 140 }
141 141
142 IGUIElement::draw(); 142 IGUIElement::draw();
143} 143}
144 144
145 145
146//! Sets another skin independent font. 146//! Sets another skin independent font.
147void CGUIStaticText::setOverrideFont(IGUIFont* font) 147void CGUIStaticText::setOverrideFont(IGUIFont* font)
148{ 148{
149 if (OverrideFont == font) 149 if (OverrideFont == font)
150 return; 150 return;
151 151
152 if (OverrideFont) 152 if (OverrideFont)
153 OverrideFont->drop(); 153 OverrideFont->drop();
154 154
155 OverrideFont = font; 155 OverrideFont = font;
156 156
157 if (OverrideFont) 157 if (OverrideFont)
158 OverrideFont->grab(); 158 OverrideFont->grab();
159 159
160 breakText(); 160 breakText();
161} 161}
162 162
163//! Gets the override font (if any) 163//! Gets the override font (if any)
164IGUIFont * CGUIStaticText::getOverrideFont() const 164IGUIFont * CGUIStaticText::getOverrideFont() const
165{ 165{
166 return OverrideFont; 166 return OverrideFont;
167} 167}
168 168
169//! Get the font which is used right now for drawing 169//! Get the font which is used right now for drawing
170IGUIFont* CGUIStaticText::getActiveFont() const 170IGUIFont* CGUIStaticText::getActiveFont() const
171{ 171{
172 if ( OverrideFont ) 172 if ( OverrideFont )
173 return OverrideFont; 173 return OverrideFont;
174 IGUISkin* skin = Environment->getSkin(); 174 IGUISkin* skin = Environment->getSkin();
175 if (skin) 175 if (skin)
176 return skin->getFont(); 176 return skin->getFont();
177 return 0; 177 return 0;
178} 178}
179 179
180//! Sets another color for the text. 180//! Sets another color for the text.
181void CGUIStaticText::setOverrideColor(video::SColor color) 181void CGUIStaticText::setOverrideColor(video::SColor color)
182{ 182{
183 OverrideColor = color; 183 OverrideColor = color;
184 OverrideColorEnabled = true; 184 OverrideColorEnabled = true;
185} 185}
186 186
187 187
188//! Sets another color for the text. 188//! Sets another color for the text.
189void CGUIStaticText::setBackgroundColor(video::SColor color) 189void CGUIStaticText::setBackgroundColor(video::SColor color)
190{ 190{
191 BGColor = color; 191 BGColor = color;
192 OverrideBGColorEnabled = true; 192 OverrideBGColorEnabled = true;
193 Background = true; 193 Background = true;
194} 194}
195 195
196 196
197//! Sets whether to draw the background 197//! Sets whether to draw the background
198void CGUIStaticText::setDrawBackground(bool draw) 198void CGUIStaticText::setDrawBackground(bool draw)
199{ 199{
200 Background = draw; 200 Background = draw;
201} 201}
202 202
203 203
204//! Gets the background color 204//! Gets the background color
205video::SColor CGUIStaticText::getBackgroundColor() const 205video::SColor CGUIStaticText::getBackgroundColor() const
206{ 206{
207 return BGColor; 207 return BGColor;
208} 208}
209 209
210 210
211//! Checks if background drawing is enabled 211//! Checks if background drawing is enabled
212bool CGUIStaticText::isDrawBackgroundEnabled() const 212bool CGUIStaticText::isDrawBackgroundEnabled() const
213{ 213{
214 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 214 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
215 return Background; 215 return Background;
216} 216}
217 217
218 218
219//! Sets whether to draw the border 219//! Sets whether to draw the border
220void CGUIStaticText::setDrawBorder(bool draw) 220void CGUIStaticText::setDrawBorder(bool draw)
221{ 221{
222 Border = draw; 222 Border = draw;
223} 223}
224 224
225 225
226//! Checks if border drawing is enabled 226//! Checks if border drawing is enabled
227bool CGUIStaticText::isDrawBorderEnabled() const 227bool CGUIStaticText::isDrawBorderEnabled() const
228{ 228{
229 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 229 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
230 return Border; 230 return Border;
231} 231}
232 232
233 233
234void CGUIStaticText::setTextRestrainedInside(bool restrainTextInside) 234void CGUIStaticText::setTextRestrainedInside(bool restrainTextInside)
235{ 235{
236 RestrainTextInside = restrainTextInside; 236 RestrainTextInside = restrainTextInside;
237} 237}
238 238
239 239
240bool CGUIStaticText::isTextRestrainedInside() const 240bool CGUIStaticText::isTextRestrainedInside() const
241{ 241{
242 return RestrainTextInside; 242 return RestrainTextInside;
243} 243}
244 244
245 245
246void CGUIStaticText::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical) 246void CGUIStaticText::setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical)
247{ 247{
248 HAlign = horizontal; 248 HAlign = horizontal;
249 VAlign = vertical; 249 VAlign = vertical;
250} 250}
251 251
252 252
253video::SColor CGUIStaticText::getOverrideColor() const 253video::SColor CGUIStaticText::getOverrideColor() const
254{ 254{
255 return OverrideColor; 255 return OverrideColor;
256} 256}
257 257
258 258
259//! Sets if the static text should use the overide color or the 259//! Sets if the static text should use the overide color or the
260//! color in the gui skin. 260//! color in the gui skin.
261void CGUIStaticText::enableOverrideColor(bool enable) 261void CGUIStaticText::enableOverrideColor(bool enable)
262{ 262{
263 OverrideColorEnabled = enable; 263 OverrideColorEnabled = enable;
264} 264}
265 265
266 266
267bool CGUIStaticText::isOverrideColorEnabled() const 267bool CGUIStaticText::isOverrideColorEnabled() const
268{ 268{
269 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 269 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
270 return OverrideColorEnabled; 270 return OverrideColorEnabled;
271} 271}
272 272
273 273
274//! Enables or disables word wrap for using the static text as 274//! Enables or disables word wrap for using the static text as
275//! multiline text control. 275//! multiline text control.
276void CGUIStaticText::setWordWrap(bool enable) 276void CGUIStaticText::setWordWrap(bool enable)
277{ 277{
278 WordWrap = enable; 278 WordWrap = enable;
279 breakText(); 279 breakText();
280} 280}
281 281
282 282
283bool CGUIStaticText::isWordWrapEnabled() const 283bool CGUIStaticText::isWordWrapEnabled() const
284{ 284{
285 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; 285 _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
286 return WordWrap; 286 return WordWrap;
287} 287}
288 288
289 289
290void CGUIStaticText::setRightToLeft(bool rtl) 290void CGUIStaticText::setRightToLeft(bool rtl)
291{ 291{
292 if (RightToLeft != rtl) 292 if (RightToLeft != rtl)
293 { 293 {
294 RightToLeft = rtl; 294 RightToLeft = rtl;
295 breakText(); 295 breakText();
296 } 296 }
297} 297}
298 298
299 299
300bool CGUIStaticText::isRightToLeft() const 300bool CGUIStaticText::isRightToLeft() const
301{ 301{
302 return RightToLeft; 302 return RightToLeft;
303} 303}
304 304
305 305
306//! Breaks the single text line. 306//! Breaks the single text line.
307void CGUIStaticText::breakText() 307void CGUIStaticText::breakText()
308{ 308{
309 if (!WordWrap) 309 if (!WordWrap)
310 return; 310 return;
311 311
312 BrokenText.clear(); 312 BrokenText.clear();
313 313
314 IGUISkin* skin = Environment->getSkin(); 314 IGUISkin* skin = Environment->getSkin();
315 IGUIFont* font = getActiveFont(); 315 IGUIFont* font = getActiveFont();
316 if (!font) 316 if (!font)
317 return; 317 return;
318 318
319 LastBreakFont = font; 319 LastBreakFont = font;
320 320
321 core::stringw line; 321 core::stringw line;
322 core::stringw word; 322 core::stringw word;
323 core::stringw whitespace; 323 core::stringw whitespace;
324 s32 size = Text.size(); 324 s32 size = Text.size();
325 s32 length = 0; 325 s32 length = 0;
326 s32 elWidth = RelativeRect.getWidth(); 326 s32 elWidth = RelativeRect.getWidth();
327 if (Border) 327 if (Border)
328 elWidth -= 2*skin->getSize(EGDS_TEXT_DISTANCE_X); 328 elWidth -= 2*skin->getSize(EGDS_TEXT_DISTANCE_X);
329 wchar_t c; 329 wchar_t c;
330 330
331 // We have to deal with right-to-left and left-to-right differently 331 // We have to deal with right-to-left and left-to-right differently
332 // However, most parts of the following code is the same, it's just 332 // However, most parts of the following code is the same, it's just
333 // some order and boundaries which change. 333 // some order and boundaries which change.
334 if (!RightToLeft) 334 if (!RightToLeft)
335 { 335 {
336 // regular (left-to-right) 336 // regular (left-to-right)
337 for (s32 i=0; i<size; ++i) 337 for (s32 i=0; i<size; ++i)
338 { 338 {
339 c = Text[i]; 339 c = Text[i];
340 bool lineBreak = false; 340 bool lineBreak = false;
341 341
342 if (c == L'\r') // Mac or Windows breaks 342 if (c == L'\r') // Mac or Windows breaks
343 { 343 {
344 lineBreak = true; 344 lineBreak = true;
345 if (Text[i+1] == L'\n') // Windows breaks 345 if (Text[i+1] == L'\n') // Windows breaks
346 { 346 {
347 Text.erase(i+1); 347 Text.erase(i+1);
348 --size; 348 --size;
349 } 349 }
350 c = '\0'; 350 c = '\0';
351 } 351 }
352 else if (c == L'\n') // Unix breaks 352 else if (c == L'\n') // Unix breaks
353 { 353 {
354 lineBreak = true; 354 lineBreak = true;
355 c = '\0'; 355 c = '\0';
356 } 356 }
357 357
358 bool isWhitespace = (c == L' ' || c == 0); 358 bool isWhitespace = (c == L' ' || c == 0);
359 if ( !isWhitespace ) 359 if ( !isWhitespace )
360 { 360 {
361 // part of a word 361 // part of a word
362 word += c; 362 word += c;
363 } 363 }
364 364
365 if ( isWhitespace || i == (size-1)) 365 if ( isWhitespace || i == (size-1))
366 { 366 {
367 if (word.size()) 367 if (word.size())
368 { 368 {
369 // here comes the next whitespace, look if 369 // here comes the next whitespace, look if
370 // we must break the last word to the next line. 370 // we must break the last word to the next line.
371 const s32 whitelgth = font->getDimension(whitespace.c_str()).Width; 371 const s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
372 const s32 wordlgth = font->getDimension(word.c_str()).Width; 372 const s32 wordlgth = font->getDimension(word.c_str()).Width;
373 373
374 if (wordlgth > elWidth) 374 if (wordlgth > elWidth)
375 { 375 {
376 // This word is too long to fit in the available space, look for 376 // This word is too long to fit in the available space, look for
377 // the Unicode Soft HYphen (SHY / 00AD) character for a place to 377 // the Unicode Soft HYphen (SHY / 00AD) character for a place to
378 // break the word at 378 // break the word at
379 int where = word.findFirst( wchar_t(0x00AD) ); 379 int where = word.findFirst( wchar_t(0x00AD) );
380 if (where != -1) 380 if (where != -1)
381 { 381 {
382 core::stringw first = word.subString(0, where); 382 core::stringw first = word.subString(0, where);
383 core::stringw second = word.subString(where, word.size() - where); 383 core::stringw second = word.subString(where, word.size() - where);
384 BrokenText.push_back(line + first + L"-"); 384 BrokenText.push_back(line + first + L"-");
385 const s32 secondLength = font->getDimension(second.c_str()).Width; 385 const s32 secondLength = font->getDimension(second.c_str()).Width;
386 386
387 length = secondLength; 387 length = secondLength;
388 line = second; 388 line = second;
389 } 389 }
390 else 390 else
391 { 391 {
392 // No soft hyphen found, so there's nothing more we can do 392 // No soft hyphen found, so there's nothing more we can do
393 // break to next line 393 // break to next line
394 if (length) 394 if (length)
395 BrokenText.push_back(line); 395 BrokenText.push_back(line);
396 length = wordlgth; 396 length = wordlgth;
397 line = word; 397 line = word;
398 } 398 }
399 } 399 }
400 else if (length && (length + wordlgth + whitelgth > elWidth)) 400 else if (length && (length + wordlgth + whitelgth > elWidth))
401 { 401 {
402 // break to next line 402 // break to next line
403 BrokenText.push_back(line); 403 BrokenText.push_back(line);
404 length = wordlgth; 404 length = wordlgth;
405 line = word; 405 line = word;
406 } 406 }
407 else 407 else
408 { 408 {
409 // add word to line 409 // add word to line
410 line += whitespace; 410 line += whitespace;
411 line += word; 411 line += word;
412 length += whitelgth + wordlgth; 412 length += whitelgth + wordlgth;
413 } 413 }
414 414
415 word = L""; 415 word = L"";
416 whitespace = L""; 416 whitespace = L"";
417 } 417 }
418 418
419 if ( isWhitespace ) 419 if ( isWhitespace )
420 { 420 {
421 whitespace += c; 421 whitespace += c;
422 } 422 }
423 423
424 // compute line break 424 // compute line break
425 if (lineBreak) 425 if (lineBreak)
426 { 426 {
427 line += whitespace; 427 line += whitespace;
428 line += word; 428 line += word;
429 BrokenText.push_back(line); 429 BrokenText.push_back(line);
430 line = L""; 430 line = L"";
431 word = L""; 431 word = L"";
432 whitespace = L""; 432 whitespace = L"";
433 length = 0; 433 length = 0;
434 } 434 }
435 } 435 }
436 } 436 }
437 437
438 line += whitespace; 438 line += whitespace;
439 line += word; 439 line += word;
440 BrokenText.push_back(line); 440 BrokenText.push_back(line);
441 } 441 }
442 else 442 else
443 { 443 {
444 // right-to-left 444 // right-to-left
445 for (s32 i=size; i>=0; --i) 445 for (s32 i=size; i>=0; --i)
446 { 446 {
447 c = Text[i]; 447 c = Text[i];
448 bool lineBreak = false; 448 bool lineBreak = false;
449 449
450 if (c == L'\r') // Mac or Windows breaks 450 if (c == L'\r') // Mac or Windows breaks
451 { 451 {
452 lineBreak = true; 452 lineBreak = true;
453 if ((i>0) && Text[i-1] == L'\n') // Windows breaks 453 if ((i>0) && Text[i-1] == L'\n') // Windows breaks
454 { 454 {
455 Text.erase(i-1); 455 Text.erase(i-1);
456 --size; 456 --size;
457 } 457 }
458 c = '\0'; 458 c = '\0';
459 } 459 }
460 else if (c == L'\n') // Unix breaks 460 else if (c == L'\n') // Unix breaks
461 { 461 {
462 lineBreak = true; 462 lineBreak = true;
463 c = '\0'; 463 c = '\0';
464 } 464 }
465 465
466 if (c==L' ' || c==0 || i==0) 466 if (c==L' ' || c==0 || i==0)
467 { 467 {
468 if (word.size()) 468 if (word.size())
469 { 469 {
470 // here comes the next whitespace, look if 470 // here comes the next whitespace, look if
471 // we must break the last word to the next line. 471 // we must break the last word to the next line.
472 const s32 whitelgth = font->getDimension(whitespace.c_str()).Width; 472 const s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
473 const s32 wordlgth = font->getDimension(word.c_str()).Width; 473 const s32 wordlgth = font->getDimension(word.c_str()).Width;
474 474
475 if (length && (length + wordlgth + whitelgth > elWidth)) 475 if (length && (length + wordlgth + whitelgth > elWidth))
476 { 476 {
477 // break to next line 477 // break to next line
478 BrokenText.push_back(line); 478 BrokenText.push_back(line);
479 length = wordlgth; 479 length = wordlgth;
480 line = word; 480 line = word;
481 } 481 }
482 else 482 else
483 { 483 {
484 // add word to line 484 // add word to line
485 line = whitespace + line; 485 line = whitespace + line;
486 line = word + line; 486 line = word + line;
487 length += whitelgth + wordlgth; 487 length += whitelgth + wordlgth;
488 } 488 }
489 489
490 word = L""; 490 word = L"";
491 whitespace = L""; 491 whitespace = L"";
492 } 492 }
493 493
494 if (c != 0) 494 if (c != 0)
495 whitespace = core::stringw(&c, 1) + whitespace; 495 whitespace = core::stringw(&c, 1) + whitespace;
496 496
497 // compute line break 497 // compute line break
498 if (lineBreak) 498 if (lineBreak)
499 { 499 {
500 line = whitespace + line; 500 line = whitespace + line;
501 line = word + line; 501 line = word + line;
502 BrokenText.push_back(line); 502 BrokenText.push_back(line);
503 line = L""; 503 line = L"";
504 word = L""; 504 word = L"";
505 whitespace = L""; 505 whitespace = L"";
506 length = 0; 506 length = 0;
507 } 507 }
508 } 508 }
509 else 509 else
510 { 510 {
511 // yippee this is a word.. 511 // yippee this is a word..
512 word = core::stringw(&c, 1) + word; 512 word = core::stringw(&c, 1) + word;
513 } 513 }
514 } 514 }
515 515
516 line = whitespace + line; 516 line = whitespace + line;
517 line = word + line; 517 line = word + line;
518 BrokenText.push_back(line); 518 BrokenText.push_back(line);
519 } 519 }
520} 520}
521 521
522 522
523//! Sets the new caption of this element. 523//! Sets the new caption of this element.
524void CGUIStaticText::setText(const wchar_t* text) 524void CGUIStaticText::setText(const wchar_t* text)
525{ 525{
526 IGUIElement::setText(text); 526 IGUIElement::setText(text);
527 breakText(); 527 breakText();
528} 528}
529 529
530 530
531void CGUIStaticText::updateAbsolutePosition() 531void CGUIStaticText::updateAbsolutePosition()
532{ 532{
533 IGUIElement::updateAbsolutePosition(); 533 IGUIElement::updateAbsolutePosition();
534 breakText(); 534 breakText();
535} 535}
536 536
537 537
538//! Returns the height of the text in pixels when it is drawn. 538//! Returns the height of the text in pixels when it is drawn.
539s32 CGUIStaticText::getTextHeight() const 539s32 CGUIStaticText::getTextHeight() const
540{ 540{
541 IGUIFont* font = getActiveFont(); 541 IGUIFont* font = getActiveFont();
542 if (!font) 542 if (!font)
543 return 0; 543 return 0;
544 544
545 s32 height = font->getDimension(L"A").Height + font->getKerningHeight(); 545 s32 height = font->getDimension(L"A").Height + font->getKerningHeight();
546 546
547 if (WordWrap) 547 if (WordWrap)
548 height *= BrokenText.size(); 548 height *= BrokenText.size();
549 549
550 return height; 550 return height;
551} 551}
552 552
553 553
554s32 CGUIStaticText::getTextWidth() const 554s32 CGUIStaticText::getTextWidth() const
555{ 555{
556 IGUIFont * font = getActiveFont(); 556 IGUIFont * font = getActiveFont();
557 if(!font) 557 if(!font)
558 return 0; 558 return 0;
559 559
560 if(WordWrap) 560 if(WordWrap)
561 { 561 {
562 s32 widest = 0; 562 s32 widest = 0;
563 563
564 for(u32 line = 0; line < BrokenText.size(); ++line) 564 for(u32 line = 0; line < BrokenText.size(); ++line)
565 { 565 {
566 s32 width = font->getDimension(BrokenText[line].c_str()).Width; 566 s32 width = font->getDimension(BrokenText[line].c_str()).Width;
567 567
568 if(width > widest) 568 if(width > widest)
569 widest = width; 569 widest = width;
570 } 570 }
571 571
572 return widest; 572 return widest;
573 } 573 }
574 else 574 else
575 { 575 {
576 return font->getDimension(Text.c_str()).Width; 576 return font->getDimension(Text.c_str()).Width;
577 } 577 }
578} 578}
579 579
580 580
581//! Writes attributes of the element. 581//! Writes attributes of the element.
582//! Implement this to expose the attributes of your element for 582//! Implement this to expose the attributes of your element for
583//! scripting languages, editors, debuggers or xml serialization purposes. 583//! scripting languages, editors, debuggers or xml serialization purposes.
584void CGUIStaticText::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const 584void CGUIStaticText::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
585{ 585{
586 IGUIStaticText::serializeAttributes(out,options); 586 IGUIStaticText::serializeAttributes(out,options);
587 587
588 out->addBool ("Border", Border); 588 out->addBool ("Border", Border);
589 out->addBool ("OverrideColorEnabled",OverrideColorEnabled); 589 out->addBool ("OverrideColorEnabled",OverrideColorEnabled);
590 out->addBool ("OverrideBGColorEnabled",OverrideBGColorEnabled); 590 out->addBool ("OverrideBGColorEnabled",OverrideBGColorEnabled);
591 out->addBool ("WordWrap", WordWrap); 591 out->addBool ("WordWrap", WordWrap);
592 out->addBool ("Background", Background); 592 out->addBool ("Background", Background);
593 out->addBool ("RightToLeft", RightToLeft); 593 out->addBool ("RightToLeft", RightToLeft);
594 out->addBool ("RestrainTextInside", RestrainTextInside); 594 out->addBool ("RestrainTextInside", RestrainTextInside);
595 out->addColor ("OverrideColor", OverrideColor); 595 out->addColor ("OverrideColor", OverrideColor);
596 out->addColor ("BGColor", BGColor); 596 out->addColor ("BGColor", BGColor);
597 out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames); 597 out->addEnum ("HTextAlign", HAlign, GUIAlignmentNames);
598 out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames); 598 out->addEnum ("VTextAlign", VAlign, GUIAlignmentNames);
599 599
600 // out->addFont ("OverrideFont", OverrideFont); 600 // out->addFont ("OverrideFont", OverrideFont);
601} 601}
602 602
603 603
604//! Reads attributes of the element 604//! Reads attributes of the element
605void CGUIStaticText::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) 605void CGUIStaticText::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
606{ 606{
607 IGUIStaticText::deserializeAttributes(in,options); 607 IGUIStaticText::deserializeAttributes(in,options);
608 608
609 Border = in->getAttributeAsBool("Border"); 609 Border = in->getAttributeAsBool("Border");
610 enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled")); 610 enableOverrideColor(in->getAttributeAsBool("OverrideColorEnabled"));
611 OverrideBGColorEnabled = in->getAttributeAsBool("OverrideBGColorEnabled"); 611 OverrideBGColorEnabled = in->getAttributeAsBool("OverrideBGColorEnabled");
612 setWordWrap(in->getAttributeAsBool("WordWrap")); 612 setWordWrap(in->getAttributeAsBool("WordWrap"));
613 Background = in->getAttributeAsBool("Background"); 613 Background = in->getAttributeAsBool("Background");
614 RightToLeft = in->getAttributeAsBool("RightToLeft"); 614 RightToLeft = in->getAttributeAsBool("RightToLeft");
615 RestrainTextInside = in->getAttributeAsBool("RestrainTextInside"); 615 RestrainTextInside = in->getAttributeAsBool("RestrainTextInside");
616 OverrideColor = in->getAttributeAsColor("OverrideColor"); 616 OverrideColor = in->getAttributeAsColor("OverrideColor");
617 BGColor = in->getAttributeAsColor("BGColor"); 617 BGColor = in->getAttributeAsColor("BGColor");
618 618
619 setTextAlignment( (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames), 619 setTextAlignment( (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("HTextAlign", GUIAlignmentNames),
620 (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames)); 620 (EGUI_ALIGNMENT) in->getAttributeAsEnumeration("VTextAlign", GUIAlignmentNames));
621 621
622 // OverrideFont = in->getAttributeAsFont("OverrideFont"); 622 // OverrideFont = in->getAttributeAsFont("OverrideFont");
623} 623}
624 624
625 625
626} // end namespace gui 626} // end namespace gui
627} // end namespace irr 627} // end namespace irr
628 628
629#endif // _IRR_COMPILE_WITH_GUI_ 629#endif // _IRR_COMPILE_WITH_GUI_
630 630