MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / createLineWrapping

Method createLineWrapping

Engine/source/gui/game/guiMessageVectorCtrl.cpp:431–531  ·  view source on GitHub ↗

--------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

429
430//--------------------------------------------------------------------------
431void GuiMessageVectorCtrl::createLineWrapping(LineWrapping& rWrapping, const char* string)
432{
433 Vector<TempLineBreak> tempBreaks(__FILE__, __LINE__);
434
435 U32 i;
436 U32 currStart = 0;
437 U32 length = dStrlen(string);
438 if (length != 0) {
439 for (i = 0; i < length; i++) {
440 if (string[i] == '\n') {
441 tempBreaks.increment();
442 tempBreaks.last().start = currStart;
443 tempBreaks.last().end = i-1;
444 currStart = i+1;
445 } else if (i == length - 1) {
446 tempBreaks.increment();
447 tempBreaks.last().start = currStart;
448 tempBreaks.last().end = i;
449 currStart = i+1;
450 }
451 }
452 } else {
453 tempBreaks.increment();
454 tempBreaks.last().start = 0;
455 tempBreaks.last().end = -1;
456 }
457
458 U32 splitWidth = getWidth();
459 U32 currLine = 0;
460 while (currLine < tempBreaks.size()) {
461 TempLineBreak& rLine = tempBreaks[currLine];
462 if (rLine.start >= rLine.end) {
463 if (currLine == 0)
464 splitWidth -= mLineContinuationIndent;
465 currLine++;
466 continue;
467 }
468
469 // Ok, there's some actual text in this line. How long is it?
470 U32 baseLength = mProfile->mFont->getStrNWidthPrecise((const UTF8 *)&string[rLine.start], rLine.end-rLine.start+1);
471 if (baseLength > splitWidth) {
472 // DMMNOTE: Replace with bin search eventually
473 U32 currPos = 0;
474 U32 breakPos = 0;
475 for (currPos = 0; currPos < rLine.end-rLine.start+1; currPos++) {
476 U32 currLength = mProfile->mFont->getStrNWidthPrecise((const UTF8 *)&string[rLine.start], currPos+1);
477 if (currLength > splitWidth)
478 {
479 // Make sure that the currPos has advanced, then set the breakPoint.
480 breakPos = currPos != 0 ? currPos - 1 : 0;
481 break;
482 }
483 }
484 if (currPos == rLine.end-rLine.start+1) {
485 AssertFatal(false, "Error, if the line must be broken, the position must be before this point!");
486 currLine++;
487 continue;
488 }

Callers

nothing calls this directly

Calls 7

getWidthFunction · 0.85
incrementMethod · 0.80
lastMethod · 0.80
getStrNWidthPreciseMethod · 0.80
dStrlenFunction · 0.50
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected