MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / renderJustifiedText

Method renderJustifiedText

Engine/source/gui/core/guiControl.cpp:617–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

615//-----------------------------------------------------------------------------
616
617void GuiControl::renderJustifiedText(Point2I offset, Point2I extent, const char *text)
618{
619 GFont *font = mProfile->mFont;
620 if(!font)
621 return;
622 S32 textWidth = font->getStrWidthPrecise((const UTF8*)text);
623 U32 textHeight = font->getHeight();
624
625 Point2I start( 0, 0 );
626
627 // Align horizontal.
628
629 if( textWidth > extent.x )
630 {
631 // If the text is longer then the box size, (it'll get clipped) so
632 // force Left Justify
633 start.x = 0;
634 }
635 else
636 switch( mProfile->mAlignment )
637 {
638 case GuiControlProfile::RightJustify:
639 start.x = extent.x - textWidth;
640 break;
641
642 case GuiControlProfile::TopJustify:
643 case GuiControlProfile::BottomJustify:
644 case GuiControlProfile::CenterJustify:
645 start.x = ( extent.x - textWidth) / 2;
646 break;
647
648 case GuiControlProfile::LeftJustify:
649 start.x = 0;
650 break;
651 }
652
653 // Align vertical.
654
655 if( textHeight > extent.y )
656 {
657 start.y = 0 - ( textHeight - extent.y ) / 2;
658 }
659 else
660 switch( mProfile->mAlignment )
661 {
662 case GuiControlProfile::TopJustify:
663 start.y = 0;
664 break;
665
666 case GuiControlProfile::BottomJustify:
667 start.y = extent.y - textHeight - 1;
668 break;
669
670 default:
671 // Center vertical.
672 start.y = ( extent.y - font->getHeight() ) / 2;
673 break;
674 }

Callers

nothing calls this directly

Calls 4

getStrWidthPreciseMethod · 0.80
getDrawUtilMethod · 0.80
getHeightMethod · 0.45
drawTextMethod · 0.45

Tested by

no test coverage detected