Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. void ptHUDTextItem::changeText(const char * _textInput)
  2. {
  3.     int l_inputCharCount = 0;
  4.     char*  l_textOutput = new char[m_characterCount];
  5.  
  6.     //Count how many characters in the new input
  7.     while (_textInput[l_inputCharCount] != '\0')
  8.     {
  9.         l_inputCharCount++;
  10.     }
  11.    
  12.     //If the new text input is less than the max character count
  13.     if (l_inputCharCount < m_characterCount)
  14.     {
  15.         //find the difference
  16.         int t_charDifference = m_characterCount - l_inputCharCount;
  17.         if (m_verbose) { printf("Character Difference is %i\n", t_charDifference); }
  18.  
  19.         //Copy input to the ouput
  20.         for (int i = 0; i < l_inputCharCount; i++)
  21.         {
  22.             l_textOutput[i] = _textInput[i];
  23.         }
  24.        
  25.         //Fill empty spaces with spaces
  26.         for (int i = 0; i < t_charDifference; i++)
  27.         {
  28.             l_textOutput[i + l_inputCharCount] = ' ';
  29.         }
  30.  
  31.         assignData(l_textOutput);
  32.     }
  33.     //if the new text input is greater than the max character count
  34.     else if (l_inputCharCount > m_characterCount)
  35.     {
  36.         printf("Warning: text input is greater than the max character count! Truncating text.\n");
  37.  
  38.         //Copy input to the ouput
  39.         for (int i = 0; i < m_characterCount; i++)
  40.         {
  41.             l_textOutput[i] = _textInput[i];
  42.         }
  43.  
  44.         assignData(l_textOutput);
  45.     }
  46.     //Otherwise text input should be the same as the character count
  47.     else
  48.     {
  49.         assignData(_textInput);
  50.     }
  51.     delete[] l_textOutput;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement