Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (editor.ui.getLineType == TEXT_EDIT_DECIMAL)
- {
- // char format_string[8]
- // char digit[8]
- // int number_format (could use enum)
- PT_ASSERT(editor.ui.numLen < 8);
- // print format string to pad with zeros
- sprintf(format_string, "%%0%ii", editor.ui.numLen);
- // clear all digits
- for (int i = 0; i < editor.ui.numLen; i++) {
- digit[i] = '0';
- }
- for (int i = editor.ui.numLen; i < 8; i++) {
- digit[i] = 0;
- }
- if ((rawKey >= '0') && (rawKey <= '9'))
- {
- // read value
- if (editor.ui.numPtr32) {
- // int32
- number = editor.ui.numPtr32[0];
- number_format = 3;
- } else if (editor.ui.numPtr16) {
- // int 16
- number = editor.ui.numPtr16[0];
- number_format = 2;
- }
- // print value to string
- sprintf(digit, format_string, number);
- // overwrite digit with input
- PT_ASSERT(editor.ui.dstPos < editor.ui.numLen);
- digit[editor.ui.dstPos] = rawKey;
- // read digits and output number
- number = atoi(digit);
- // write value
- switch (number_format) {
- // float
- case 4: PT_ASSERT(0); break;
- // int32
- case 3: editor.ui.numPtr32[0] = number; break;
- // int16
- case 2: editor.ui.numPtr16[0] = number; break;
- // int8
- case 1: PT_ASSERT(0); break;
- // invalid
- case 0: PT_ASSERT(0); break;
- }
- textMarkerMoveRight();
- if (editor.ui.dstPos >= editor.ui.numLen)
- exitGetTextLine(EDIT_TEXT_UPDATE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement