MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / WrapText

Function WrapText

Source/SysPSP/Graphics/DrawText.cpp:177–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175 }
176
177 void WrapText( CDrawText::EFont font, s32 width, const char * p_str, u32 length, std::vector<u32> & lengths, bool & match )
178 {
179 lengths.clear();
180
181 // Manual line breaking (Used for translations)
182 if(gGlobalPreferences.Language != 0)
183 {
184 u32 i, j;
185 for (i = 0, j = 0; i < length; i++)
186 {
187 match = true;
188 if (p_str[i] == '\n')
189 {
190 j++;
191 lengths.push_back( match );
192 }
193 }
194 if( match )
195 {
196 lengths.push_back( match );
197 }
198
199 return;
200 }
201
202 // Auto-linebreaking
203 const char * p_line_str( p_str );
204 const char * p_str_end( p_str + length );
205
206 while( p_line_str < p_str_end )
207 {
208 u32 length_remaining( p_str_end - p_line_str );
209 s32 chunk_width( CDrawText::GetTextWidth( font, p_line_str, length_remaining ) );
210
211 if( chunk_width <= width )
212 {
213 lengths.push_back( length_remaining );
214 p_line_str += length_remaining;
215 }
216 else
217 {
218 // Search backwards until we find a break
219 const char * p_chunk_end( p_str_end );
220 bool found_chunk( false );
221 while( p_chunk_end > p_line_str )
222 {
223 const char * p_space( FindPreviousSpace( p_line_str, p_chunk_end ) );
224
225 if( p_space != nullptr )
226 {
227 u32 chunk_length( p_space + 1 - p_line_str );
228 chunk_width = CDrawText::GetTextWidth( font, p_line_str, chunk_length );
229 if( chunk_width <= width )
230 {
231 lengths.push_back( chunk_length );
232 p_line_str += chunk_length;
233 found_chunk = true;
234 break;

Callers 1

DrawTextAreaMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected