Ticket #723: 0adTicket_723.patch
File 0adTicket_723.patch, 5.4 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/common/common_styles.xml
244 244 dropdown_buffer="1" 245 245 font="serif-bold-stroke-14" 246 246 textcolor="white" 247 text_align=" center"247 text_align="left" 248 248 text_valign="center" 249 249 250 250 sprite="StoneButton" -
source/gui/CGUI.cpp
665 665 // Easier to read. 666 666 bool WordWrapping = (Width != 0); 667 667 668 // get the alignment type for the control we are computing the text for since 669 // we are computing the horizontal alignment in this method in order to not have 670 // to run through the TextCalls a second time in the CalculateTextPosition method again 671 EAlign align; 672 GUI<EAlign>::GetSetting(pObject, "text_align", align); 673 668 674 // Go through string word by word 669 675 for (int i=0; i<(int)string.m_Words.size()-1 && !done; ++i) 670 676 { … … 778 784 // Reset X for the next loop 779 785 x = width_range[From]; 780 786 781 // Now we'll do another loop to figure out the height of 782 // the line (the height of the largest character). This 787 // Now we'll do another loop to figure out the height and width of 788 // the line (the height of the largest character and the width is 789 // the sum of all of the individual widths). This 783 790 // couldn't be determined in the first loop (main loop) 784 791 // because it didn't regard images, so we don't know 785 792 // if all characters processed, will actually be involved 786 793 // in that line. 787 794 float line_height=0.f; 795 float line_width=0.f; 788 796 for (int j=temp_from; j<=i; ++j) 789 797 { 790 798 // We don't want to use Feedback now, so we'll have to use … … 807 815 // Let line_height be the maximum m_Height we encounter. 808 816 line_height = std::max(line_height, Feedback2.m_Size.cy); 809 817 818 line_width += Feedback2.m_Size.cx; 819 810 820 if (WordWrapping && Feedback2.m_NewLine) 811 821 break; 812 822 } 813 823 824 float dx = 0.f; 825 //compute offset based on what kind of alignment 826 switch (align) 827 { 828 case EAlign_Left: 829 //don't add an offset 830 dx = 0.f; 831 break; 832 833 case EAlign_Center: 834 dx = ((width_range[To] - width_range[From]) - line_width) / 2; 835 break; 836 837 case EAlign_Right: 838 dx = width_range[To] - line_width; 839 break; 840 841 default: 842 debug_warn(L"Broken EAlign in CGUI::GenerateText()"); 843 break; 844 } 814 845 // Reset x once more 815 846 x = width_range[From]; 816 847 // Move down, because font drawing starts from the baseline … … 837 868 std::vector<SGUIText::STextCall>::iterator it; 838 869 for (it = Feedback2.m_TextCalls.begin(); it != Feedback2.m_TextCalls.end(); ++it) 839 870 { 840 it->m_Pos = CPos( x + x_pointer, y);871 it->m_Pos = CPos(dx + x + x_pointer, y); 841 872 842 873 x_pointer += it->m_Size.cx; 843 874 -
source/gui/IGUITextOwner.cpp
100 100 101 101 void IGUITextOwner::CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text) 102 102 { 103 EAlign align;104 103 EVAlign valign; 105 GUI<EAlign>::GetSetting(this, "text_align", align);106 104 GUI<EVAlign>::GetSetting(this, "text_valign", valign); 107 105 108 switch (align) 109 { 110 case EAlign_Left: 111 TextPos.x = ObjSize.left; 112 break; 113 case EAlign_Center: 114 // Round to integer pixel values, else the fonts look awful 115 TextPos.x = floorf(ObjSize.CenterPoint().x - Text.m_Size.cx/2.f); 116 break; 117 case EAlign_Right: 118 TextPos.x = ObjSize.right - Text.m_Size.cx; 119 break; 120 default: 121 debug_warn(L"Broken EAlign in CButton::SetupText()"); 122 break; 123 } 106 // The horizontal Alignment is now computed in GenerateText in order to not have to 107 // loop through all of the TextCall objects again. 108 TextPos.x = ObjSize.left; 124 109 125 110 switch (valign) 126 111 { -
source/gui/CGUI.h
241 241 * Generate a SGUIText object from the inputted string. 242 242 * The function will break down the string and its 243 243 * tags to calculate exactly which rendering queries 244 * will be sent to the Renderer. 244 * will be sent to the Renderer. Also, Horizontal Alignment 245 * is taken into acount in this method but NOT Vertical Alignment. 245 246 * 246 247 * Done through the CGUI since it can communicate with 247 248 * -
source/gui/CTooltip.cpp
36 36 AddSetting(GUIST_float, "maxwidth"); 37 37 AddSetting(GUIST_CPos, "offset"); 38 38 AddSetting(GUIST_EVAlign, "anchor"); 39 AddSetting(GUIST_EAlign, "text_align"); 39 40 // This is used for tooltips that are hidden/revealed manually by scripts, rather than through the standard tooltip display mechanism 40 41 AddSetting(GUIST_bool, "independent"); 41 42 … … 49 50 // Defaults 50 51 GUI<int>::SetSetting(this, "delay", 500); 51 52 GUI<EVAlign>::SetSetting(this, "anchor", EVAlign_Bottom); 53 GUI<EAlign>::SetSetting(this, "text_align", EAlign_Left); 52 54 53 55 // Set up a blank piece of text, to be replaced with a more 54 56 // interesting message later