Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ptHUDTextItem::changeText(const char * _textInput)
- {
- int l_inputCharCount = 0;
- char* l_textOutput = new char[m_characterCount];
- //Count how many characters in the new input
- while (_textInput[l_inputCharCount] != '\0')
- {
- l_inputCharCount++;
- }
- //If the new text input is less than the max character count
- if (l_inputCharCount < m_characterCount)
- {
- //find the difference
- int t_charDifference = m_characterCount - l_inputCharCount;
- if (m_verbose) { printf("Character Difference is %i\n", t_charDifference); }
- //Copy input to the ouput
- for (int i = 0; i < l_inputCharCount; i++)
- {
- l_textOutput[i] = _textInput[i];
- }
- //Fill empty spaces with spaces
- for (int i = 0; i < t_charDifference; i++)
- {
- l_textOutput[i + l_inputCharCount] = ' ';
- }
- assignData(l_textOutput);
- }
- //if the new text input is greater than the max character count
- else if (l_inputCharCount > m_characterCount)
- {
- printf("Warning: text input is greater than the max character count! Truncating text.\n");
- //Copy input to the ouput
- for (int i = 0; i < m_characterCount; i++)
- {
- l_textOutput[i] = _textInput[i];
- }
- assignData(l_textOutput);
- }
- //Otherwise text input should be the same as the character count
- else
- {
- assignData(_textInput);
- }
- delete[] l_textOutput;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement