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