MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / drawText

Method drawText

Engine/source/gui/controls/guiTextEditCtrl.cpp:1244–1443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1242}
1243
1244void GuiTextEditCtrl::drawText( const RectI &drawRect, bool isFocused )
1245{
1246 StringBuffer textBuffer;
1247 Point2I drawPoint = drawRect.point;
1248 Point2I paddingLeftTop, paddingRightBottom;
1249
1250 // Or else just copy it over.
1251 char *renderText = Con::getReturnBuffer( GuiTextEditCtrl::MAX_STRING_LENGTH );
1252 getRenderText( renderText );
1253
1254 // Apply password masking (make the masking char optional perhaps?)
1255 if(mPasswordText)
1256 {
1257 const U32 renderLen = dStrlen( renderText );
1258 for( U32 i = 0; i < renderLen; i++ )
1259 textBuffer.append(mPasswordMask);
1260 }
1261 else
1262 {
1263 textBuffer.set( renderText );
1264 }
1265
1266 bool usePlaceholder = false;
1267 if (textBuffer.length() == 0 && !isFocused)
1268 {
1269 textBuffer.set(mPlaceholderText);
1270 usePlaceholder = true;
1271 }
1272
1273 // Just a little sanity.
1274 if(mCursorPos > textBuffer.length())
1275 mCursorPos = textBuffer.length();
1276
1277 paddingLeftTop.set(( mProfile->mTextOffset.x != 0 ? mProfile->mTextOffset.x : 3 ), mProfile->mTextOffset.y);
1278 paddingRightBottom = paddingLeftTop;
1279
1280 // Center vertically:
1281 drawPoint.y += ( ( drawRect.extent.y - paddingLeftTop.y - paddingRightBottom.y - S32( mProfile->mFont->getHeight() ) ) / 2 ) + paddingLeftTop.y;
1282
1283 // Align horizontally:
1284
1285 S32 textWidth = mProfile->mFont->getStrNWidth(textBuffer.getPtr(), textBuffer.length());
1286
1287 switch( mProfile->mAlignment )
1288 {
1289 case GuiControlProfile::RightJustify:
1290 drawPoint.x += ( drawRect.extent.x - textWidth - paddingRightBottom.x );
1291 break;
1292 case GuiControlProfile::CenterJustify:
1293 drawPoint.x += ( ( drawRect.extent.x - textWidth ) / 2 );
1294 break;
1295 default:
1296 case GuiControlProfile::LeftJustify :
1297 drawPoint.x += paddingLeftTop.x;
1298 break;
1299 }
1300
1301 ColorI fontColor = mActive ? mProfile->mFontColor : mProfile->mFontColorNA;

Callers 15

renderButtonMethod · 0.45
renderJustifiedTextMethod · 0.45
onRenderMethod · 0.45
onRenderMethod · 0.45
onRenderMethod · 0.45
onRenderMethod · 0.45
renderNodeNameMethod · 0.45
onRenderMethod · 0.45
renderGraphTooltipMethod · 0.45
onRenderCellMethod · 0.45
onRenderCellMethod · 0.45
onRenderCellMethod · 0.45

Calls 15

getReturnBufferFunction · 0.85
mFloorFunction · 0.85
getStrNWidthMethod · 0.80
getCharMethod · 0.80
getCharWidthMethod · 0.80
setBitmapModulationMethod · 0.80
getDrawUtilMethod · 0.80
drawRectFillMethod · 0.80
drawTextNMethod · 0.80
dStrlenFunction · 0.50
Point2IClass · 0.50
appendMethod · 0.45

Tested by

no test coverage detected