/////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <bios.h>
///////////////////////////////////////////////////////////////////////
#define SPACE 3
#define HOR 2
#define VAR 3
#define BORDER 1
#define NOBORDER 0
#define MAXFILENAME 13
/////////////////////////////////////////////////////////////////////////
int Border(int startx, int starty, int endx, int endy, int bcolor, int fcolor)
{
int i = 0, x, y;
x = endx - startx;
y = endy - starty;
window(startx+1, starty+1, endx+2, endy+1);
textbackground(BLACK);
clrscr();
window(startx, starty, endx, endy);
textbackground(bcolor);
textcolor(fcolor);
clrscr();
gotoxy(2, 1);
putch(218);
gotoxy(2, y+1);
putch(192);
gotoxy(x, 1);
putch(191);
gotoxy(x, y+1);
putch(217);
for (i = 3; i < x; i++)
{
gotoxy(i, 1);
putch(196);
gotoxy(i, y+1);
putch(196);
}
for(i = 2; i < y+1; i++)
{
gotoxy(2, i);
putch(179);
gotoxy(x, i);
putch(179);
}
return 1;
}
int GetMaxWidthAndHeight(char **p, int *width, int *height)
{
int i = 0, maxw = 0, maxh = 0;
while(p[i])
{
if(maxw < strlen(p[i]))
maxw = strlen(p[i]);
i++;
maxh++;
}
*width = maxw;
*height = maxh;
return 1;
}
int ShowMenu(int x, int y, char **p, int count, int charmode, int borderflag)
{
int width = 0, height = 0, i = 0;
if (charmode == VAR)
{
GetMaxWidthAndHeight(p, &width, &height);
if (borderflag == BORDER)
{
Border(x, y-1, x+width+4, y+height, WHITE, BLACK);
while(i < count)
{
gotoxy(3, i+2);
cprintf("%s", p[i]);
i++;
}
}
}
else if(charmode == HOR)
{
window(1, 1, 80, 1);
textbackground(WHITE);
textcolor(BLACK);
clrscr();
while(i < count)
{
gotoxy(x, y);
cprintf("%s", p[i]);
x = x+strlen(p[i]) + SPACE;
i++;
}
}
return 1;
}
int ActiveMenu(int x, int y, char **p, int menu, int showflag)
{
int width = 0, height = 0;
if (y == 1)
width = strlen(p[menu]);
else
GetMaxWidthAndHeight(p, &width, &height);
window(x, y, x+width, y);
if(showflag == 1)
{
textbackground(GREEN);
textcolor(WHITE);
clrscr();
}
else
{
textbackground(WHITE);
textcolor(BLACK);
clrscr();
}
cprintf("%s", p[menu]);
return 1;
}
char far *SaveData(int startx, int starty, int endx, int endy)
{
char far *p1, far *p;
int i = 0, j = 0, k = 0;
p = (char far *)malloc(sizeof(char)*(endx-startx+4)*(endy-starty+2)*2);
for (i = starty-1; i < endy+1; i++)
for (j = startx-1; j < endx+3; j++)
{
p1 = (char far *)MK_FP(0xb800, j*2+i*160);
p[k++] = *p1++;
p[k++] = *p1;
}
return p;
}
int RestoreData(int startx, int starty, int endx, int endy, char far *p)
{
char far *p1;
int i = 0, j = 0, k = 0;
for (i = starty-1; i < endy+1; i++)
for (j = startx-1; j < endx+3; j++)
{
p1 = (char far *)MK_FP(0xb800, j*2+i*160);
*p1++ = p[k++];
*p1 = p[k++];
}
return 1;
}