unit ui;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
procedure drawfkeys(x, y: integer; fkeys: array of string);
procedure drawframe(x, y, width, height, color : integer);
function runmenu(x, y : byte; menu : array of PAnsiChar; defaultitem: integer): integer;
procedure drawbox(x, y, width, height, color, border: integer);
procedure drawboxnum(num, x, y, color, border: integer);
implementation
uses
gconst, conio, kbd;
procedure drawfkeys(x, y: integer; fkeys: array of string);
var
i, j: integer;
s: string;
begin
gotoxy(x, y);
for i := 0 to 9 do
begin
textcolor(WHITE);
textbackground(BLACK);
if (i <> 0) then
_putch(SPACE);
if (i = 9) then
begin
_putch($31);
_putch($30);
end
else _putch((i mod 10) + $31);
textcolor(BLACK);
textbackground(CYAN);
if (fkeys[i] <> #0) then
s := fkeys[i]
else s := #0;
for j := 0 to 5 do
begin
if ((s <> '') and (s[j] <> #0)) then
_putch(Ord(s[j]))
else _putch(SPACE);
end;
end;
end;
procedure drawframe(x, y, width, height, color : integer);
var
i, j : integer;
begin
textattr(color);
gotoxy(x,y);
_putch(ACS_ULCORNER);
i := 0;
while i < (width + 2) do
begin
_putch(ACS_HLINE);
i := i + 1;
end;
_putch(ACS_URCORNER);
for i := 0 to (height - 1) do
begin
gotoxy(x, y + i + 1);
_putch(ACS_VLINE);
_putch(SPACE);
for j := 0 to width - 1 do
_putch(SPACE);
_putch(SPACE);
_putch(ACS_VLINE);
end;
gotoxy(x, y + height +1);
_putch(ACS_LLCORNER);
i := 0;
while i < (width + 2) do
begin
_putch(ACS_HLINE);
i := i + 1;
end;
_putch(ACS_LRCORNER);
end;
function runmenu(x, y : byte; menu : array of PAnsiChar; defaultitem: integer): integer;
var
key : byte;
i, j, itemno: integer;
nitems : integer;
width: integer;
s: PAnsiChar;
begin
itemno := defaultitem-1;
width := 22;
nitems := 0;
while (menu[nitems] <> '') do
begin
j := 0;
while (menu[nitems][j] <> #0) do Inc(j);
if (j > width) then
width := j;
nitems := nitems + 1;
end;
width+=2;
if ((itemno < 0) or (itemno > nitems)) then
itemno := 0;
while (true) do
begin
cursoroff();
textattr((CYAN << 4) or BLACK);
gotoxy(x,y);
_putch(ACS_ULCORNER);
i := 0;
while( i < (width + 2)) do
begin
_putch(ACS_HLINE);
Inc(i);
end;
_putch(ACS_URCORNER);
for i := 0 to (nitems - 1) do
begin
gotoxy(x,y+i+1);
_putch(ACS_VLINE);
_putch(SPACE);
if (i = itemno) then
textattr(YELLOW);
s := nil;
for j := 0 to (width - 1) do
begin
if (s <> nil) and (s^ <> #0) then
begin
_putch(Byte(s^));
Inc(s);
end
else _putch(SPACE);
if (s = nil) then
s := PAnsiChar(menu[i]);
end;
textattr(CYAN<<4 or BLACK);
_putch(SPACE);
_putch(ACS_VLINE);
end;
gotoxy(x,y+nitems+1);
_putch(ACS_LLCORNER);
i := 0;
while (i < (width+2)) do
begin
_putch(ACS_HLINE);
i := i + 1;
end;
_putch(ACS_LRCORNER);
key := _getch;
case (key) of
KB_UP: begin if (itemno > 0) then itemno := itemno - 1 else itemno := nitems-1; end;
KB_DOWN: begin Inc(itemno); itemno := itemno mod nitems; end;
KB_ESC: begin cursoron(); result := 0; exit; end;
KB_ENTER: begin cursoron(); result := itemno+1; exit; end;
end;
end;
end;
procedure drawbox(x, y, width, height, color, border: integer);
var
i, j: integer;
begin
if (x < 1) then x := 1;
if (y < 1) then y := 1;
if (x > 80) then x := 80;
if (y > 24) then y := 24;
if (width < 1) then width := 1;
if (height < 0) then height := 0;
textattr(color);
gotoxy(x,y);
if (border = 1) then
begin
_putch(ACS_ULCORNER);
i := 0;
while (i < width+1) do
begin
_putch(ACS_HLINE);
Inc(i);
end;
_putch(ACS_URCORNER);
end
else
begin
_putch(SPACE);
i := 0;
while (i < width+1) do
begin
_putch(SPACE);
end;
_putch(SPACE);
end;
if (border = 1) then
begin
for i := 0 to (height-1) do
begin
gotoxy(x,y+i+1);
_putch(ACS_VLINE);
_putch(SPACE);
for j := 0 to (width-1) do
begin
_putch(SPACE);
end;
_putch(ACS_VLINE);
end;
end
else
begin
for i := 0 to (height-1) do
begin
gotoxy(x,y+i+1);
_putch(SPACE);
_putch(SPACE);
for j := 0 to (width-1) do
begin
_putch(SPACE);
end;
_putch(SPACE);
end;
end;
if (border = 1) then
begin
gotoxy(x,y+height+1);
_putch(ACS_LLCORNER);
i := 0;
while (i < (width+1)) do
begin
_putch(ACS_HLINE);
Inc(i);
end;
_putch(ACS_LRCORNER);
end
else
begin
gotoxy(x,y+height+1);
_putch(SPACE);
i := 0;
while (i < (width+1)) do
begin
_putch(SPACE);
Inc(i);
end;
_putch(SPACE);
end;
textattr(LIGHTGRAY or BLACK <<4);
end;
procedure drawboxnum(num, x, y, color, border: integer);
var
i, j, width, height: integer;
begin
if ((num < 48) or (num > 57)) then exit;
width := 2;
height := 1;
if (x < 1) then x := 1;
if (y < 1) then y := 1;
if (x > 80) then x := 80;
if (y > 24) then y := 24;
if (width < 1) then width := 1;
if (height < 0) then height := 0;
textattr(color);
gotoxy(x,y);
if (border = 1) then
begin
_putch(ACS_ULCORNER);
i := 0;
while (i < width+1) do
begin
_putch(ACS_HLINE);
Inc(i);
end;
_putch(ACS_URCORNER);
end
else
begin
_putch(SPACE);
i := 0;
while (i < width+1) do
begin
_putch(SPACE);
end;
_putch(SPACE);
end;
if (border = 1) then
begin
for i := 0 to (height-1) do
begin
gotoxy(x,y+i+1);
_putch(ACS_VLINE);
_putch(SPACE);
for j := 0 to (width-1) do
begin
if (j = 0) then _putch(num)
else _putch(SPACE);
end;
_putch(ACS_VLINE);
end;
end
else
begin
for i := 0 to (height-1) do
begin
gotoxy(x,y+i+1);
_putch(SPACE);
_putch(SPACE);
for j := 0 to (width-1) do
begin
if (j = 0) then _putch(num)
else _putch(SPACE);
end;
_putch(SPACE);
end;
end;
if (border = 1) then
begin
gotoxy(x,y+height+1);
_putch(ACS_LLCORNER);
i := 0;
while (i < (width+1)) do
begin
_putch(ACS_HLINE);
Inc(i);
end;
_putch(ACS_LRCORNER);
end
else
begin
gotoxy(x,y+height+1);
_putch(SPACE);
i := 0;
while (i < (width+1)) do
begin
_putch(SPACE);
Inc(i);
end;
_putch(SPACE);
end;
textattr(LIGHTGRAY or BLACK <<4);
end;
end.