📄 menus.c
字号:
availableWidth)) { LCDUIdrawChars(blackPixel, clip, NULL, 0, FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM, curX, curY, LEFT | TOP, menu[i].longChars, menu[i].numLongChars); } else { LCDUIdrawChars(blackPixel, clip, NULL, 0, FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM, curX, curY, LEFT | TOP, menu[i].chars, menu[i].numChars); } curX -= 2; } } if (menuHeight > itemSpace) { LCDUIsetVerticalScroll(scrollY * 100 / (menuHeight - itemSpace), (itemSpace * 100) / menuHeight); } LCDUIrefresh(menuXOffset, menuYOffset, screenWidth, screenHeight);}static voidhideMenu(){ if(inMenu) { /* restore the arrows */ LCDUIsetVerticalScroll(0, 100); restoreEmulatorScreenMode(); /* restore the soft buttons */ LCDUIupdateCommandSet(menuList, menuLength); } inMenu = KNI_FALSE;}voidLCDUIdismissMenu() { hideMenu();}static voidinitMenu(){ LCDUIupdateCommandSet(menuList, menuLength); setEmulatorScreenMode(KNI_FALSE); /* * There are (menuLength - offMenuCommands) * itemHeight * commands. */ menuHeight = (menuLength - offMenuCommands) * itemHeight; /* was itemSpace = screenHeight - itemHeight - 3; */ /* 19 = bottom bar height */ /* -6 = spacer pixels in menu heading */ itemSpace = screenHeight - menuYOffset - boldHeight - 6 - 19 - 11; if (menuHeight < itemSpace) { menuHeight = itemSpace; } scrollPosition = 0; menuCurrent = 0; scrollY = 0; /* HI guide says: back button only appears on the left soft button, * but that both buttons should dismiss the menu */ buttonCommands[0] = BUTTON_DISMISSES_MENU; buttonCommands[1] = BUTTON_DISMISSES_MENU; LCDUIsetSoftButton(0, _back_, _backlen_); LCDUIsetSoftButton(1, NULL, 0); if (menuHeight <= itemSpace) { LCDUIsetVerticalScroll(0, 100); } inMenu = KNI_TRUE;}static jbooleanhandleSoftKey(int button, KVMEventType *evt){ int index = (button == KEY_SOFT1) ? 0 : 1; if (buttonCommands[index] >= 0) { evt->chr = buttonCommands[index]; evt->type = commandKVMEvent; return KNI_TRUE; } else if (buttonCommands[index] == BUTTON_INVOKES_MENU) { if (inMenu) { return KNI_FALSE; } initMenu(); evt->chr = BUTTON_INVOKES_MENU; evt->type = commandKVMEvent; return KNI_TRUE; } else if (buttonCommands[index] == BUTTON_DISMISSES_MENU) { if (inMenu) { evt->type = commandKVMEvent; evt->chr = BUTTON_DISMISSES_MENU; hideMenu(); return KNI_TRUE; } } return KNI_FALSE;}jbooleanLCDUImenuInternalEvent(int button, KVMEventType *evt){ switch (button) { case KEY_SOFT1: case KEY_SOFT2: return handleSoftKey(button, evt); case KEY_UP: if (!inMenu) { return KNI_FALSE; } evt->type = invalidKVMEvent; if (menuCurrent > 0 || scrollY > 0) { if (menuCurrent > 0) { --menuCurrent; if (menuCurrent >= scrollPosition) { LCDUIpaintMenuPartial(menuCurrent, menuCurrent + 1); } else { --scrollPosition; scrollY -= itemHeight; LCDUIpaintMenu(); } } else { scrollY = 0; LCDUIpaintMenu(); } } return KNI_TRUE; case KEY_DOWN: if (!inMenu) { return KNI_FALSE; } evt->type = invalidKVMEvent; if (menuCurrent < menuLength - offMenuCommands - 1 || (scrollY + menuYOffset + 6 + boldHeight + itemSpace) < menuHeight) { if (menuCurrent < menuLength - offMenuCommands - 1) { int bottomMenuCurrent; ++menuCurrent; bottomMenuCurrent = (menuCurrent - scrollPosition + 1) * itemHeight; if (bottomMenuCurrent <= itemSpace) { LCDUIpaintMenuPartial(menuCurrent-1, menuCurrent); } else { ++ scrollPosition; scrollY += itemHeight; LCDUIpaintMenu(); } } else { LCDUIpaintMenu(); } } return KNI_TRUE; case KEY_SELECT: if (!inMenu) { return KNI_FALSE; } evt->type = commandKVMEvent; evt->chr = menuList[menuCurrent + offMenuCommands].id; hideMenu(); return KNI_TRUE; case KEY_1: case KEY_2: case KEY_3: case KEY_4: case KEY_5: case KEY_6: case KEY_7: case KEY_8: case KEY_9: if (!inMenu) { return KNI_FALSE; } if (menuLength - offMenuCommands < 10) { /* cmd is the index of the command */ int cmd = (button - KEY_0 - 1); if (cmd + offMenuCommands < menuLength) { evt->type = commandKVMEvent; evt->chr = menuList[cmd + offMenuCommands].id; hideMenu(); return KNI_TRUE; } } } return KNI_FALSE;}voidLCDUIupdateCommandSet(commandStruct *menu, int length){ int dummy; int availableWidth = 0; int longCharsWidth = 0; if (menuList != menu) { freeMenuList(); } menuList = menu; menuLength = length; LCDUIgetDisplayParams(&screenWidth, &screenHeight, &dummy, &dummy, &dummy, &dummy, &dummy); if (length <= 0) { buttonCommands[0] = buttonCommands[1] = BUTTON_NOT_SET; LCDUIsetSoftButton(0, NULL, 0); LCDUIsetSoftButton(1, NULL, 0); return; } else { if (inFullScreenMode == KNI_TRUE) { /* This case occurs when we are in full screen mode. We want all commands on the menu screen. */ buttonCommands[0] = BUTTON_INVOKES_MENU; buttonCommands[1] = BUTTON_INVOKES_MENU; LCDUIsetSoftButton(0, NULL, 0); LCDUIsetSoftButton(1, NULL, 0); } else { /* highest-priority negative command on LEFT soft button */ if (menu[0].type == COMMAND_TYPE_BACK || menu[0].type == COMMAND_TYPE_CANCEL || menu[0].type == COMMAND_TYPE_STOP || menu[0].type == COMMAND_TYPE_EXIT) { buttonCommands[0] = menu[0].id; offMenuCommands = 1; } else { buttonCommands[0] = BUTTON_NOT_SET; offMenuCommands = 0; } /* decide between short and long label */ /* First see if the long label fits, if yes use long label */ /* else use short label */ /* labels are clipped if there isn't sufficient space */ if (menu[0].useLongChars == 1) { availableWidth = LCDUIcharsWidth(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM, menu[0].longChars, MAX_SOFTBUTTON_COMMAND_LENGTH); longCharsWidth = LCDUIcharsWidth(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM, menu[0].longChars, menu[0].numLongChars); } if (offMenuCommands == 1) { if ((menu[0].useLongChars == 1) && (longCharsWidth <= availableWidth)) { LCDUIsetSoftButton(0, menu[0].longChars, menu[0].numLongChars); }else { LCDUIsetSoftButton(0, menu[0].chars, menu[0].numChars); } } else { /* blank out the left button */ LCDUIsetSoftButton(0, NULL, 0); } if (length > 2 || (length == 2 && offMenuCommands == 0)) { buttonCommands[1] = BUTTON_INVOKES_MENU; LCDUIsetSoftButton(1, _menu_, _menulen_); } else if (length == 1 && offMenuCommands == 0 || length == 2 && offMenuCommands == 1) { int idx = (offMenuCommands == 0) ? 0 : 1; buttonCommands[1] = menu[idx].id; if (menu[idx].useLongChars == 1) { availableWidth = LCDUIcharsWidth(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM, menu[idx].longChars, MAX_SOFTBUTTON_COMMAND_LENGTH); longCharsWidth = LCDUIcharsWidth(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM, menu[idx].longChars, menu[idx].numLongChars); } if ((menu[idx].useLongChars == 1) && (longCharsWidth <= availableWidth)) { LCDUIsetSoftButton(1, menu[idx].longChars, menu[idx].numLongChars); }else { LCDUIsetSoftButton(1, menu[idx].chars, menu[idx].numChars); } } else { /* length == 0 || (length == 1 & offMenuCommands == 1)*/ buttonCommands[1] = BUTTON_NOT_SET; LCDUIsetSoftButton(1, NULL, 0); } } /* * When there is 10 or more menu items, the number prefix are not * drawn. So the line height is just the height of the plain font * because bold font for the number is not used. * * This is necessary because it cannot be assumed that the height * of the plain font is the same as the bold font. The tallest of * font determines the item height. */ if (length - offMenuCommands > 10) { /* no bold font on the line */ itemHeight = plainHeight; } }}intLCDUIhandleMenuEvent(enum KVMEventTypes t, int a, int b){ return inMenu;}void setCommandsFullScreenMode(jboolean fullscreenMode) { if (KNI_TRUE == fullscreenMode) { inFullScreenMode = KNI_TRUE; } else { inFullScreenMode = KNI_FALSE; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -