Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ui.c
00001 /* 00002 ui.c 00003 User interface functions. 00004 Part of MicroVGA CONIO library / demo project 00005 Copyright (c) 2008-9 SECONS s.r.o., http://www.MicroVGA.com 00006 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "conio.h" 00022 #include "ui.h" 00023 #include "kbd.h" 00024 00025 00026 int runmenu(char x, char y, ROMDEF char *menu[], int defaultitem) 00027 { 00028 int keys[3], i,j, itemno; 00029 int nitems, width; 00030 ROMDEF char *s; 00031 00032 itemno = defaultitem-1; 00033 width = 20; 00034 00035 width = 10; 00036 nitems = 0; 00037 while (menu[nitems] != 0) { 00038 for (j=0;menu[nitems][j];j++); 00039 if (j>width) 00040 width = j; 00041 nitems++; 00042 } 00043 width+=2; 00044 00045 if (itemno < 0 || itemno > nitems) 00046 itemno = 0; 00047 00048 while (1) { 00049 00050 00051 cursoroff(); 00052 textattr(CYAN<<4 | BLACK); 00053 gotoxy(x,y); 00054 _putch(ACS_ULCORNER); 00055 for (i=0;i<width+2;i++) 00056 _putch(ACS_HLINE); 00057 _putch(ACS_URCORNER); 00058 00059 for (i = 0;i<nitems;i++) { 00060 gotoxy(x,y+i+1); 00061 _putch(ACS_VLINE); 00062 _putch(' '); 00063 if (i == itemno) 00064 textattr(YELLOW); 00065 s = 0; 00066 for (j=0;j<width;j++) { 00067 if (s && *s) 00068 _putch(*s++); 00069 else _putch(' '); 00070 if (s == 0) 00071 s = (ROMDEF char *)menu[i]; 00072 } 00073 textattr(CYAN<<4 | BLACK); 00074 _putch(' '); 00075 _putch(ACS_VLINE); 00076 } 00077 00078 gotoxy(x,y+nitems+1); 00079 _putch(ACS_LLCORNER); 00080 for (i=0;i<width+2;i++) 00081 _putch(ACS_HLINE); 00082 _putch(ACS_LRCORNER); 00083 00084 00085 while (!_kbhit()) ; 00086 00087 if (_kbhit()) { 00088 keys[0] = keys[1]; 00089 keys[1] = keys[2]; 00090 keys[2] = _getch(); 00091 if (keys[0] == 0x1b && keys[1] == 0x5b) 00092 { 00093 switch (keys[2]) { 00094 case 'A': if (itemno>0) itemno--; else itemno = nitems-1; break; 00095 case 'B': itemno++; itemno %= nitems; break; 00096 } 00097 } 00098 else 00099 switch(keys[0]) { 00100 case KB_ENTER : cursoron(); return itemno+1; 00101 case KB_ESC: cursoron(); return 0; 00102 } 00103 } 00104 } 00105 } 00106 00107 00108 00109 void drawfkeys(ROMDEF char *fkeys[]) 00110 { 00111 ROMDEF char *s; 00112 int i, j; 00113 00114 gotoxy(1,25); 00115 for (i=0;i<10;i++) { 00116 textcolor(WHITE); 00117 textbackground(BLACK); 00118 if (i!= 0) 00119 _putch(' '); 00120 if (i== 9) { 00121 _putch('1'); 00122 _putch('0'); 00123 } else 00124 _putch((i%10)+'1'); 00125 textcolor(BLACK); 00126 textbackground(CYAN); 00127 00128 s = fkeys[i] ? fkeys[i] : 0; 00129 for (j=0;j<6;j++) { 00130 if (s && *s) 00131 _putch(*s++); 00132 else _putch(' '); 00133 } 00134 } 00135 } 00136 00137 void drawframe(int x, int y, int width, int height, int color) 00138 { 00139 int i,j; 00140 00141 textattr(color); 00142 gotoxy(x,y); 00143 00144 _putch(ACS_ULCORNER); 00145 for (i=0;i<width+2;i++) 00146 _putch(ACS_HLINE); 00147 _putch(ACS_URCORNER); 00148 00149 for (i = 0;i<height;i++) { 00150 gotoxy(x,y+i+1); 00151 _putch(ACS_VLINE); 00152 _putch(' '); 00153 00154 for (j=0;j<width;j++) { 00155 _putch(' '); 00156 } 00157 _putch(' '); 00158 _putch(ACS_VLINE); 00159 } 00160 00161 gotoxy(x,y+height+1); 00162 _putch(ACS_LLCORNER); 00163 for (i=0;i<width+2;i++) 00164 _putch(ACS_HLINE); 00165 _putch(ACS_LRCORNER); 00166 }
Generated on Thu Jul 14 2022 01:28:10 by
1.7.2