Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CGUIText.cpp
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | void SGenerateTextImage::SetupSpriteCall( | ||||
SpriteCall.m_CellID = CellID; | SpriteCall.m_CellID = CellID; | ||||
SpriteCall.m_Sprite = TextureName; | SpriteCall.m_Sprite = TextureName; | ||||
m_YFrom = SpriteCall.m_Area.top - BufferZone; | m_YFrom = SpriteCall.m_Area.top - BufferZone; | ||||
m_YTo = SpriteCall.m_Area.bottom + BufferZone; | m_YTo = SpriteCall.m_Area.bottom + BufferZone; | ||||
m_Indentation = Size.cx + BufferZone * 2; | m_Indentation = Size.cx + BufferZone * 2; | ||||
} | } | ||||
CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, const float Width, const float BufferZone, const IGUIObject* pObject) | CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& FontW, float Width, const float BufferZone, const IGUIObject* pObject) | ||||
{ | { | ||||
if (string.m_Words.empty()) | if (string.m_Words.empty()) | ||||
return; | return; | ||||
CStrIntern Font(FontW.ToUTF8()); | CStrIntern Font(FontW.ToUTF8()); | ||||
float x = BufferZone, y = BufferZone; // drawing pointer | float x = BufferZone, y = BufferZone; // drawing pointer | ||||
int from = 0; | int from = 0; | ||||
bool FirstLine = true; // Necessary because text in the first line is shorter | bool FirstLine = true; // Necessary because text in the first line is shorter | ||||
// (it doesn't count the line spacing) | // (it doesn't count the line spacing) | ||||
// Images on the left or the right side. | // Images on the left or the right side. | ||||
SGenerateTextImages Images; | SGenerateTextImages Images; | ||||
int pos_last_img = -1; // Position in the string where last img (either left or right) were encountered. | int pos_last_img = -1; // Position in the string where last img (either left or right) were encountered. | ||||
// in order to avoid duplicate processing. | // in order to avoid duplicate processing. | ||||
// get the alignment type for the control we are computing the text for since | // get the alignment type for the control we are computing the text for since | ||||
// we are computing the horizontal alignment in this method in order to not have | // we are computing the horizontal alignment in this method in order to not have | ||||
// to run through the TextCalls a second time in the CalculateTextPosition method again | // to run through the TextCalls a second time in the CalculateTextPosition method again | ||||
EAlign align = EAlign_Left; | EAlign align = EAlign_Left; | ||||
if (pObject->SettingExists("text_align")) | if (pObject->SettingExists("text_align")) | ||||
align = pObject->GetSetting<EAlign>("text_align"); | align = pObject->GetSetting<EAlign>("text_align"); | ||||
bool noWrap = pObject->SettingExists("no_text_wrap") && pObject->GetSetting<bool>("no_text_wrap"); | |||||
vladislavbelov: `const bool noWrap`. | |||||
// Go through string word by word | // Go through string word by word | ||||
for (int i = 0; i < static_cast<int>(string.m_Words.size()) - 1; ++i) | for (int i = 0; i < static_cast<int>(string.m_Words.size()) - 1; ++i) | ||||
{ | { | ||||
// Pre-process each line one time, so we know which floating images | // Pre-process each line one time, so we know which floating images | ||||
// will be added for that line. | // will be added for that line. | ||||
// Generated stuff is stored in Feedback. | // Generated stuff is stored in Feedback. | ||||
CGUIString::SFeedback Feedback; | CGUIString::SFeedback Feedback; | ||||
// Preliminary line height, used for word-wrapping with floating images. | // Preliminary line height, used for word-wrapping with floating images. | ||||
float prelim_line_height = 0.f; | float prelim_line_height = 0.f; | ||||
// Width and height of all text calls generated. | // Width and height of all text calls generated. | ||||
string.GenerateTextCall(pGUI, Feedback, Font, string.m_Words[i], string.m_Words[i+1], FirstLine); | string.GenerateTextCall(pGUI, Feedback, Font, string.m_Words[i], string.m_Words[i+1], FirstLine); | ||||
SetupSpriteCalls(pGUI, Feedback.m_Images, y, Width, BufferZone, i, pos_last_img, Images); | SetupSpriteCalls(pGUI, Feedback.m_Images, y, Width, BufferZone, i, pos_last_img, Images); | ||||
pos_last_img = std::max(pos_last_img, i); | pos_last_img = std::max(pos_last_img, i); | ||||
x += Feedback.m_Size.cx; | x += Feedback.m_Size.cx; | ||||
prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.cy); | prelim_line_height = std::max(prelim_line_height, Feedback.m_Size.cy); | ||||
if (Width != 0 && noWrap) | |||||
Width = x + BufferZone; | |||||
// If Width is 0, then there's no word-wrapping, disable NewLine. | // If Width is 0, then there's no word-wrapping, disable NewLine. | ||||
if (((Width != 0 && (x > Width - BufferZone || Feedback.m_NewLine)) || i == static_cast<int>(string.m_Words.size()) - 2) && | if (((Width != 0 && (x > Width - BufferZone || Feedback.m_NewLine)) || i == static_cast<int>(string.m_Words.size()) - 2) && | ||||
ProcessLine(pGUI, string, Font, pObject, Images, align, prelim_line_height, Width, BufferZone, FirstLine, x, y, i, from)) | ProcessLine(pGUI, string, Font, pObject, Images, align, prelim_line_height, Width, BufferZone, FirstLine, x, y, i, from)) | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
// Loop through our images queues, to see if images have been added. | // Loop through our images queues, to see if images have been added. | ||||
▲ Show 20 Lines • Show All 355 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
const bool noWrap.