Change the menu index incrementally redraws the minimum amount of screen to show the new info (this prevents flicker/flash and saves battery life) returns the new menu index
| 1027 | // returns the new menu index |
| 1028 | // |
| 1029 | int obdMenuDelta(SIMPLEMENU *sm, int iDelta) |
| 1030 | { |
| 1031 | int i, x, iNewIndex, iCount; |
| 1032 | int iStart1, iStart2; |
| 1033 | char szTemp[64]; |
| 1034 | |
| 1035 | if (iDelta == 0) |
| 1036 | return sm->iMenuIndex; // nothing to do |
| 1037 | |
| 1038 | iNewIndex = sm->iMenuIndex + iDelta; |
| 1039 | if (!sm->bOneButton && (iNewIndex < 0 || iNewIndex >= sm->iMenuLen)) // no change possible, exit |
| 1040 | return sm->iMenuIndex; // unchanged |
| 1041 | // If we are using a single button, wrap around the ends |
| 1042 | if (iNewIndex < 0) |
| 1043 | iNewIndex = (sm->iMenuLen - 1); |
| 1044 | else if (iNewIndex > sm->iMenuLen - 1) |
| 1045 | iNewIndex = 0; |
| 1046 | |
| 1047 | iCount = (sm->iDispY / 8) - 1; // DEBUG - number of visible menu lines |
| 1048 | iStart1 = iStart2 = 0; |
| 1049 | if (sm->iMenuIndex > iCount - 1) |
| 1050 | iStart1 = sm->iMenuIndex - (iCount - 1); |
| 1051 | if (iNewIndex > iCount - 1) // needs to scroll up |
| 1052 | iStart2 = iNewIndex - (iCount - 1); |
| 1053 | if (iStart1 != iStart2) // need to redraw all items |
| 1054 | { |
| 1055 | for (i = 0; i < iCount; i++) |
| 1056 | { |
| 1057 | x = obdMenuGetItem(sm, i + iStart2 + 1, szTemp); |
| 1058 | if (x >= 0) |
| 1059 | obdMenuShowItem(sm->pOBD, x, i + 1, szTemp, (i + iStart2 == iNewIndex), 1, sm->iFontSize, 0); |
| 1060 | } |
| 1061 | obdDumpBuffer(sm->pOBD, NULL); |
| 1062 | } |
| 1063 | else // need to redraw only the new and old items |
| 1064 | { |
| 1065 | i = sm->iMenuIndex - iStart1; |
| 1066 | x = obdMenuGetItem(sm, sm->iMenuIndex + 1, szTemp); |
| 1067 | if (x >= 0) |
| 1068 | obdMenuShowItem(sm->pOBD, x, i + 1, szTemp, 0, 0, sm->iFontSize, 1); |
| 1069 | i = iNewIndex - iStart2; |
| 1070 | x = obdMenuGetItem(sm, iNewIndex + 1, szTemp); |
| 1071 | if (x >= 0) |
| 1072 | obdMenuShowItem(sm->pOBD, x, i + 1, szTemp, 1, 0, sm->iFontSize, 1); |
| 1073 | } |
| 1074 | sm->iMenuIndex = iNewIndex; |
| 1075 | return iNewIndex; |
| 1076 | } /* obdMenuDelta() */ |
| 1077 | |
| 1078 | // |
| 1079 | // With the given setup, check for button presses |
no test coverage detected