Ticket #723: multiline-center-2.patch

File multiline-center-2.patch, 1.9 KB (added by Philip Taylor, 13 years ago)

alternative approach (incomplete)

  • source/gui/CGUI.cpp

    diff -r e8d1f9ceddb6 source/gui/CGUI.cpp
    a b  
    810810            //  if all characters processed, will actually be involved
    811811            //  in that line.
    812812            float line_height=0.f;
     813            float line_width=0.f;
    813814            for (int j=temp_from; j<=i; ++j)
    814815            {
    815816                // We don't want to use Feedback now, so we'll have to use
     
    832833                // Let line_height be the maximum m_Height we encounter.
    833834                line_height = std::max(line_height, Feedback2.m_Size.cy);
    834835
     836                line_width += Feedback2.m_Size.cx;
     837
    835838                if (WordWrapping && Feedback2.m_NewLine)
    836839                    break;
    837840            }
    838841
     842            float dx = ((width_range[To] - width_range[From]) - line_width) / 2;
    839843            // Reset x once more
    840844            x = width_range[From];
    841845            // Move down, because font drawing starts from the baseline
     
    862866                std::vector<SGUIText::STextCall>::iterator it;
    863867                for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it)
    864868                {
    865                     it->m_Pos = CPos(x + x_pointer, y);
     869                    it->m_Pos = CPos(dx + x + x_pointer, y);
    866870
    867871                    x_pointer += it->m_Size.cx;
    868872
  • source/gui/IGUITextOwner.cpp

    diff -r e8d1f9ceddb6 source/gui/IGUITextOwner.cpp
    a b  
    106106    GUI<EAlign>::GetSetting(this, "text_align", align);
    107107    GUI<EVAlign>::GetSetting(this, "text_valign", valign);
    108108
    109     switch (align)
    110     {
    111     case EAlign_Left:
    112         TextPos.x = ObjSize.left;
    113         break;
    114     case EAlign_Center:
    115         // Round to integer pixel values, else the fonts look awful
    116         TextPos.x = floorf(ObjSize.CenterPoint().x - Text.m_Size.cx/2.f);
    117         break;
    118     case EAlign_Right:
    119         TextPos.x = ObjSize.right - Text.m_Size.cx;
    120         break;
    121     default:
    122         debug_warn(L"Broken EAlign in CButton::SetupText()");
    123         break;
    124     }
     109    TextPos.x = ObjSize.left;
    125110
    126111    switch (valign)
    127112    {