Graphical C++ – GCPPFUNC.H

/* Almost complete header file for creating greatest graphical objects ever
using turbo c++ */

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream.h>
#include<fstream.h>
#include<dos.h>
#include<graphics.h>
#include<alloc.h>
#include<process.h>
#include<time.h>
#include<fcntl.h>
#include<math.h>
#include<dir.h>
#ifndef min
#define min(n,m)  ((n) < (m) ? (n) : (m))
#define max(n,m)  ((n) > (m) ? (n) : (m))
#endif

#define Esc 0x1b

#define ON 1
#define OFF 0
#define CRITICAL 1
#define QUESTION 2
#define EXCLAMATION 3
#define INFORMATION 4
#define THREE-D 1
#define FLAT 0
#define OFF 0
#define ON 1

extern int x=0,y=0,button=0,loopmain=1;
union REGS i,o;
struct SREGS s;

	/* Declaration area for all functions implimented here */
void graph();
void svga();
void highgraph();
int Val(char *);
char* Str(int);
char* Today();
char* Now();
char* Cwd();
void Print(int,int,char*);
void Vprint(int,int,char*);
void initmouse();
void showmouse();
void hidemouse();
void pointer(int pt=1);
int inkey();
int getscan();
void getmouse(int &button,int &x,int &y);
void setmouse(int x,int y);
void getmousepos(int *button,int *x,int *y);
void restrictmouse(int,int,int,int);
void mouseptr(int mark[50],int xstart,int ystart);
void getclick(int,int,int [][5]);
int getlink(int,int,int [][5]);
void invertcolors(int,int,int,int);
void activate(int,int,int,int,int,int [][5],int);
void back(int x1=0,int y1=0,int x2=0,int y2=0,int mode=0,char *file="tempfl.dat");
void sel(int,int,int,int,int);
void select(int,int,int,int,int);
void select_with_color(int,int,int,int,int);
void deselect_with_color(int,int,int,int,int);
void say(char *text="",char *title="");
int confirm(char *text="",char *title="");
char* intext(int,int);
void openwindow(int x1=1,int y1=1,int x2=638,int y2=478,char text[]="",int fillst=1,int titlecolor=1,int darkshade=8,int lightshade=15,int normalshade=7);
void openwindow2(int x1=1,int y1=1,int x2=638,int y2=478,char text[]="",int fillst=1,int titlecolor=1,int darkshade=8,int lightshade=15,int normalshade=7);
void buttonon(int,int,int,int,char *,int);
void image(int,int,int,int,char *);
void iconbtn(int,int,int,int,char *,int,int [][5],int);
void cmdbtn(int,int,int,int,char *,int,int,int [][5],int);
void buttoneffect(int,int,int,int);
void buttonclick(int,int,int,int);
void initaddons(char *dir="");
char* textfield(int,int,int);
void checkbox(int,int,int);
void progressbar(int,int,int,int);
void menu(int,int,char*,int,int);
int activemenu(int,int,char *,int,int);
void marquee(char *,int,int,int,int);
void pressbtn(int,int [][5]);
void liftbtn(int,int [][5]);
void endgui();
void getstr(int,char *);
int cur(int);
void isigraph(char *,int);
void getpassword(char *,char *,int s);
char* inputbox(char *,char *,int);
void MsgBox(char*, char*, int);
void MsgBox(char*,char*);
void MsgBox(char*);
void popmenu(int,int,int,int);
void combolist(int,int,int,int);
int mymenu(int,int,char *[],int,int);
int popupmenu(int,int,char *[],int,int);
void mybutton(int,int,int,int);
void textarea(char *,int,int,int);
void load_icon ( char *,int,int);
int Hue(int,int,int,int,int,int);

int md=2;
// return the desired mode
int huge Mode() { md++;return(md);}
int hg=3;
// return the desired mode
int huge mode() { hg++;return(hg);}
unsigned char icon_image[40][32] ;

struct ColorValue
{
    unsigned char Rvalue, Gvalue, Bvalue; //This structure have RGB values.
};

typedef struct ColorValue VGAPaletteType[256]; //ColorValue declared as VGAPaletteType[256] with all 256 colors.

int xasp, yasp;


void graph()
{
	int gd=VGA,gm=VGAHI;
	initgraph(&gd,&gm," ");
}

void svga()
{
	installuserdriver("SVGA256",Mode);
	int gd=DETECT,gm;
	initgraph(&gd,&gm," ");
}

void highgraph()
{
	installuserdriver("SVGA256",mode);
	int gd=DETECT,gm;
	initgraph(&gd,&gm," ");
}

int getscan(void)
{
	union REGS in,out;
	in.h.ah=0;
	fflush(stdin);
	while(!kbhit());
	int86(0x16,&in,&out);
	return(out.h.ah);
}

Val(char *str)
{
	int ret=atoi(str);
	return ret;
}

char* Str(int integer)
{
	char *ret;
	itoa(integer,ret,10);
	return ret;
}

char* Str(long int integer)
{
	char *ret;
	ltoa(integer,ret,10);
	return ret;
}

char* Today()
{
	char d[80];
	_strdate(d);
	return (d);
}

char* Now()
{
	char t[80];
	_strtime(t);
	return (t);
}

char *Cwd()
{
   char curdir[MAXPATH];
   strcpy(curdir, "X:\\");
   curdir[0] = 'A' + getdisk();
   getcurdir(0, curdir+3);
   return(curdir);
}

void Print(int x,int y,char *print)
{
	setcolor(0);
	settextstyle(SMALL_FONT,HORIZ_DIR,4);
	outtextxy(x,y,print);
}

void Vprint(int x,int y,char *print)
{
	setcolor(0);
	settextstyle(SMALL_FONT,VERT_DIR,4);
	outtextxy(x,y,print);
}

void popmenu(int l,int t,int r,int b)
{
	setfillstyle(1,15);
	bar(l,t,r,b);
	setcolor(0);
	rectangle(l,t,r,b);
}

int mymenu(int xc1,int yc1,char *list[],int rows,int cols)
{
	hidemouse();
	int h=((rows*15)+10);
	int w=((cols*8)+10);
	setfillstyle(1,7);
	float *bck;
	float sz=imagesize(xc1,yc1,xc1+w,yc1+h);
	bck=new float[sz];
	getimage(xc1,yc1,xc1+w,yc1+h,bck);
	bar(xc1,yc1,xc1+w,yc1+h);
	popmenu(xc1,yc1,xc1+w,yc1+h);
	settextstyle(2,HORIZ_DIR,4);
	setcolor(0);
	for(int a=0;a<rows;a++)
		outtextxy(xc1+3,(yc1+2+(a*15)),list[a]);
	showmouse();
	getmouse(button,x,y);
	int lc=1,fnc=0,over=-1;
	delay(50);
	while(lc==1)
	{
		getmouse(button,x,y);
		for(int b=0;b<rows;b++)
		{
			if(button==1)
			{
				if((x>xc1+w)||(x<xc1)||(y>yc1+h)||(y<yc1))
				{
					fnc=0;lc=0;
				}
				else if((y>(yc1+(15*b)))&&(y<(yc1+(15*b)+15)))
				{
					fnc=b+1;lc=0;
				}

			}
			if(button==0)
			{
				if((y>(yc1+(15*b)))&&(y<(yc1+(15*b)+15)))
				{
					if((b!=over)||(over==-1))
					{
						if(over!=-1)
						{
							invertcolors(xc1+2,yc1+(15*over)+1,xc1+w-2,yc1+(15*over)+13);
						}
							invertcolors(xc1+2,yc1+(15*b)+1,xc1+w-2,yc1+(15*b)+13);over=b;
					}
					over=b;
				}
			}
		}
	}
	hidemouse();
	putimage(xc1,yc1,bck,COPY_PUT);
	showmouse();
	delete bck;
	return(fnc);
}

void load_icon ( char *file, int x, int y )
{
	int xx, yy ;
	FILE *fp ;

	/* open the specified icon file */
	fp = fopen ( file, "rb" ) ;

	/* if unable to open file */
	if ( fp == NULL )
	{
		outtextxy ( 160, 184, "Unable to open file! Press any key..." ) ;
		getch() ;

		/* shut down the graphics system */
		closegraph() ;
		restorecrtmode() ;
		exit ( 3 ) ;
	}

	/* read the bit image of icon */
	fread ( icon_image, sizeof ( icon_image ), 1, fp ) ;

	/* output the icon on the screen */
	for ( xx = x ; xx < x + 40 ; xx++ )
	{
		for ( yy = y ; yy < y + 32 ; yy++ )
			putpixel ( xx, yy, icon_image[xx - x][yy - y] ) ;
	}

	fclose ( fp ) ;
}

void combolist(int l,int t,int r,int b)
{
	setfillstyle(1,15);
	bar(l,t,r,b);
	setcolor(0);
	rectangle(l,t,r,b);
}

int popupmenu(int xc1,int yc1,char *list[],int rows,int cols)
{
	hidemouse();
	int h=((rows*15)+10);
	int w=((cols*8)+10);
	setfillstyle(1,7);
	float *bck;
	float sz=imagesize(xc1,yc1,xc1+w,yc1+h);
	bck=new float[sz];
	getimage(xc1,yc1,xc1+w,yc1+h,bck);
	bar(xc1,yc1,xc1+w,yc1+h);
	popmenu(xc1,yc1,xc1+w,yc1+h);
	settextstyle(2,HORIZ_DIR,4);
	setcolor(0);
	for(int a=0;a<rows;a++)
		outtextxy(xc1+3,(yc1+2+(a*15)),list[a]);
	showmouse();
	getmouse(button,x,y);
	int lc=1,fnc=0,over=-1;
	delay(50);
	while(lc==1)
	{
		getmouse(button,x,y);
		for(int b=0;b<rows;b++)
		{
			if(button==1)
			{
				if((x>xc1+w)||(x<xc1)||(y>yc1+h)||(y<yc1))
				{
					fnc=0;lc=0;
				}
				else if((y>(yc1+(15*b)))&&(y<(yc1+(15*b)+15)))
				{
					fnc=b+1;lc=0;
				}

			}
			if(button==0)
			{
				if((y>(yc1+(15*b)))&&(y<(yc1+(15*b)+15)))
				{
					if((b!=over)||(over==-1))
					{
						if(over!=-1)
						{
							invertcolors(xc1+2,yc1+(15*over)+1,xc1+w-2,yc1+(15*over)+13);
						}
							invertcolors(xc1+2,yc1+(15*b)+1,xc1+w-2,yc1+(15*b)+13);over=b;
					}
					over=b;
				}
			}
		}
	}
	hidemouse();
	putimage(xc1,yc1,bck,COPY_PUT);
	showmouse();
	delete bck;
	return(fnc);
}

void buttonpush(int x1,int y1,int x2,int y2,int state)
{
  if(state==1)
  {
  setcolor(15);
  line(x1,y1,x2,y1);
  line(x1,y1,x1,y2);
  setcolor(8);
  line(x2,y1,x2,y2);
  line(x1,y2,x2,y2);
  }
  else
  {
  setcolor(7);
  line(x1,y1,x2,y1);
  line(x1,y1,x1,y2);
  setcolor(7);
  line(x2,y1,x2,y2);
  line(x1,y2,x2,y2);
  }
}

void mybutton(int x1,int y1,int x2,int y2)
{
	setfillstyle(1,7);
	bar(x1,y1,x2,y2);
	setcolor(15);
	line(x1,y1,x2,y1);
	line(x1,y1,x1,y2);
	setcolor(8);
	line(x2,y1,x2,y2);
	line(x1,y2,x2,y2);
}

void textarea(char *list,int x1,int y1,int length)
{
	char str[40];
	setfillstyle(1,15);
	int right;
	right=x1+(8*length);
	bar(x1,y1,right,y1+15);
	buttonclick(x1,y1,right,y1+15);
	settextstyle(SMALL_FONT,HORIZ_DIR,4);
	setcolor(BLUE);
	outtextxy(x1+2,y1+1,list);
	setcolor(0);
}

void MsgBox(char text[])
{
	hidemouse();
	settextstyle(2,0,4);
	int width;
	width=textwidth(text)+20;
	int height=60;
	int xcol1=320-(width/2),xcol2=320+(width/2);
	int ycol1=240-(height/2),ycol2=240+(height/2);
	back(xcol1,ycol1,xcol2,ycol2,0);
	openwindow(xcol1,ycol1,xcol2,ycol2,"GcMsgBox");
	setcolor(0);
	buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
	setcolor(0);
	outtextxy(xcol1+10,ycol1+20,text);
	showmouse();
	int lc=1;
	while(lc==1)
	{
		getmouse(button,x,y);
		if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
		{
			buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
			lc=0;
		}
		if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
		{
			buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
			lc=0;
		}
		if(inkey()==13)
		{ lc=0; }
	}
	hidemouse();
	back(xcol1,ycol1,xcol2,ycol2,1);
	showmouse();
	delay(90);
}

int MsgOkCancel(char text[],char title[])
{
	hidemouse();
	settextstyle(2,0,4);
	int xcol1,ycol1,xcol2,ycol2;
	int width;
	if(textwidth(text)>=textwidth(title))
	width=textwidth(text)+20;
	if(textwidth(title)>textwidth(text))
	width=textwidth(title)+20;
	int height=60;
	if(width>50)
	{
		xcol1=320-(width/2),xcol2=320+(width/2);
		ycol1=240-(height/2),ycol2=240+(height/2);
	}
	if(width<=50)
	{
		xcol1=320-50,xcol2=320+50;
		ycol1=240-(height/2),ycol2=240+(height/2);
	}
	back(xcol1,ycol1,xcol2,ycol2,0);
	openwindow(xcol1,ycol1,xcol2,ycol2,title);
	setcolor(0);
	buttonon(320-31,ycol2-17,320-1,ycol2-2,"OK",6);
	buttonon(320+1,ycol2-17,320+41,ycol2-2,"Cancel",3);
	sel(320+1,ycol2-17,320+41,ycol2-3,1);
	setcolor(0);
	outtextxy(xcol1+10,ycol1+20,text);
	showmouse();
	int lc=1,ans=0,opt=2,in;
	while(lc==1)
	{
		getmouse(button,x,y); //Get Mouse
		in=inkey();      //Get Keyboard.
		if((x>320-31)&&(x<320-1)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
		{
			buttonclick(320-31,ycol2-17,320-1,ycol2-2);delay(50);ans=1;
			lc=0;
		}       //OK button Click check.
		if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
		{
			buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
			lc=0;
		}
			//Cancel button Click check.
		if((x>320+1)&&(x<320+41)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
		{
			buttonclick(320+1,ycol2-17,320+41,ycol2-2);delay(50);ans=0;
			lc=0;
		}
		if(in==13)
		{
			if(opt==1)
			{ans=1;}
			else if(opt==2)
			{ans=0;}
			lc=0;
		}
		if(in==75)
		{
			opt=1;
			sel(320-31,ycol2-17,320-1,ycol2-3,1);
			sel(320+1,ycol2-17,320+41,ycol2-3,0);
		}
		if(in==77)
		{
			opt=2;
			sel(320-31,ycol2-17,320-1,ycol2-3,0);
			sel(320+1,ycol2-17,320+41,ycol2-3,1);
		}
	}
	hidemouse();
	back(xcol1,ycol1,xcol2,ycol2,1);
	showmouse();
	delay(90);
	return(ans);
}

void MsgBox(char text[],char title[])
{
	hidemouse();
	int width;
	settextstyle(2,0,4);
	if(textwidth(text)>=textwidth(title))
	width=textwidth(text)+20;
	if(textwidth(title)>textwidth(text))
	width=textwidth(title)+20;
	int height=60;
	int xcol1=320-(width/2),xcol2=320+(width/2);
	int ycol1=240-(height/2),ycol2=240+(height/2);
	back(xcol1,ycol1,xcol2,ycol2,0);
	openwindow(xcol1,ycol1,xcol2,ycol2,title);
	setcolor(0);
	buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
	setcolor(0);
	outtextxy(xcol1+10,ycol1+20,text);
	showmouse();
	int lc=1;               //x2-15,y1+2,x2-3,y1+15
	while(lc==1)
	{
		getmouse(button,x,y);
		if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
		{
			buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
			lc=0;
		}
		if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
		{
			buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
			lc=0;
		}
		if(inkey()==13)
		{ lc=0; }
	}
	hidemouse();
	back(xcol1,ycol1,xcol2,ycol2,1);
	showmouse();
	delay(90);
}

void MsgBox(char text[],char title[],int style)
{
	hidemouse();
	settextstyle(2,0,4);
	int width,height,xcol1,ycol1,xcol2,ycol2;
	if(style==0)
	{
		int width;
		if(textwidth(text)>=textwidth(title))
		width=textwidth(text)+20;
		if(textwidth(title)>textwidth(text))
		width=textwidth(title)+20;
		height=60;
		xcol1=320-(width/2),xcol2=320+(width/2);
		ycol1=240-(height/2),ycol2=240+(height/2);

		back(xcol1,ycol1,xcol2,ycol2,0);
		openwindow(xcol1,ycol1,xcol2,ycol2,title);
		setcolor(0);
		buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
		setcolor(0);
		outtextxy(xcol1+10,ycol1+20,text);
		showmouse();
		int lc=1;
		while(lc==1)
		{
			getmouse(button,x,y);
			if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
			{
				buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
				lc=0;
			}
			if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
			{
				buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
				lc=0;
			}
			if(inkey()==13)
			{ lc=0; }
		}
		hidemouse();
		back(xcol1,ycol1,xcol2,ycol2,1);
		showmouse();
		delay(90);
	}

	else if(style==1)
	{
		int width;
		if(textwidth(text)>=textwidth(title))
		width=textwidth(text)+20+45;
		if(textwidth(title)>textwidth(text))
		width=textwidth(title)+20+45;
		height=60;
		xcol1=320-(width/2),xcol2=320+(width/2);
		ycol1=240-(height/2),ycol2=240+(height/2);

		back(xcol1,ycol1,xcol2,ycol2,0);
		openwindow(xcol1,ycol1,xcol2,ycol2,title);
		setcolor(0);
		buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
		setfillstyle(SOLID_FILL,RED);
		fillellipse(xcol1+15,ycol1+30,10,10);
		setcolor(15);
		setlinestyle(SOLID_LINE,5,3);
		line(xcol1+10,ycol1+25,xcol1+20,ycol1+35);
		line(xcol1+20,ycol1+25,xcol1+10,ycol1+35);
		setlinestyle(SOLID_LINE,5,1);
		setcolor(0);
		outtextxy(xcol1+10+20,ycol1+25,text);
		showmouse();
		int lc=1;
		while(lc==1)
		{
			getmouse(button,x,y);
			if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
			{
				buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
				lc=0;
			}
			if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
			{
				buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
				lc=0;
			}
			if(inkey()==13)
			{ lc=0; }
		}
		hidemouse();
		back(xcol1,ycol1,xcol2,ycol2,1);
		showmouse();
		delay(90);
	}

	else if(style==2)
	{
		int width;
		if(textwidth(text)>=textwidth(title))
		width=textwidth(text)+20+45;
		if(textwidth(title)>textwidth(text))
		width=textwidth(title)+20+45;
		height=60;
		xcol1=320-(width/2),xcol2=320+(width/2);
		ycol1=240-(height/2),ycol2=240+(height/2);

		back(xcol1,ycol1,xcol2,ycol2,0);
		openwindow(xcol1,ycol1,xcol2,ycol2,title);
		setcolor(0);
		buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
		setfillstyle(SOLID_FILL,RED);
		fillellipse(xcol1+15,ycol1+30,10,10);
		setcolor(15);
		settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);
		outtextxy(xcol1+12,ycol1+18,"?");
		settextstyle(SMALL_FONT,HORIZ_DIR,4);
		setlinestyle(SOLID_LINE,5,1);
		setcolor(0);
		outtextxy(xcol1+10+20,ycol1+25,text);
		showmouse();
		int lc=1;
		while(lc==1)
		{
			getmouse(button,x,y);
			if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
			{
				buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
				lc=0;
			}
			if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
			{
				buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
				lc=0;
			}
			if(inkey()==13)
			{ lc=0; }
		}
		hidemouse();
		back(xcol1,ycol1,xcol2,ycol2,1);
		showmouse();
		delay(90);
	}

	else if(style==3)
	{
		int width;
		if(textwidth(text)>=textwidth(title))
		width=textwidth(text)+20+45;
		if(textwidth(title)>textwidth(text))
		width=textwidth(title)+20+45;
		height=60;
		xcol1=320-(width/2),xcol2=320+(width/2);
		ycol1=240-(height/2),ycol2=240+(height/2);

		back(xcol1,ycol1,xcol2,ycol2,0);
		openwindow(xcol1,ycol1,xcol2,ycol2,title);
		setcolor(0);
		buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
		setfillstyle(SOLID_FILL,RED);
		fillellipse(xcol1+15,ycol1+30,10,10);
		setcolor(15);
		settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);
		outtextxy(xcol1+15,ycol1+18,"!");
		settextstyle(SMALL_FONT,HORIZ_DIR,4);
		setlinestyle(SOLID_LINE,5,1);
		setcolor(0);
		outtextxy(xcol1+10+20,ycol1+25,text);
		showmouse();
		int lc=1;
		while(lc==1)
		{
			getmouse(button,x,y);
			if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
			{
				buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
				lc=0;
			}
			if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
			{
				buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
				lc=0;
			}
			if(inkey()==13)
			{ lc=0; }
		}
		hidemouse();
		back(xcol1,ycol1,xcol2,ycol2,1);
		showmouse();
		delay(90);
	}

	else if(style==4)
	{
		int width;
		if(textwidth(text)>=textwidth(title))
		width=textwidth(text)+20+45;
		if(textwidth(title)>textwidth(text))
		width=textwidth(title)+20+45;
		height=60;
		xcol1=320-(width/2),xcol2=320+(width/2);
		ycol1=240-(height/2),ycol2=240+(height/2);

		back(xcol1,ycol1,xcol2,ycol2,0);
		openwindow(xcol1,ycol1,xcol2,ycol2,title);
		setcolor(0);
		buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
		setfillstyle(SOLID_FILL,RED);
		fillellipse(xcol1+15,ycol1+30,10,10);
		setcolor(15);
		settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
		outtextxy(xcol1+8,ycol1+23,"i");
		settextstyle(SMALL_FONT,HORIZ_DIR,4);
		setlinestyle(SOLID_LINE,5,1);
		setcolor(0);
		outtextxy(xcol1+10+20,ycol1+25,text);
		showmouse();
		int lc=1;
		while(lc==1)
		{
			getmouse(button,x,y);
			if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
			{
				buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
				lc=0;
			}
			if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
			{
				buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
				lc=0;
			}
			if(inkey()==13)
			{ lc=0; }
		}
		hidemouse();
		back(xcol1,ycol1,xcol2,ycol2,1);
		showmouse();
		delay(90);
	}

	else
	MsgBox("Invalid property value for calling MsgBox style. Please enter 1 to 4.","Wrong Parameter",CRITICAL);
}

char* textfield(int x1,int y1,int length)
{
	char str[40];
	setfillstyle(1,15);
	bar(x1,y1,(x1+(8*length)),y1+15);
	buttonclick(x1,y1,(x1+(8*length)),y1+15);
	moveto(x1+2,y1);
	settextstyle(SMALL_FONT,HORIZ_DIR,4);
	isigraph(str,length);
	return (str);
}

char* inputbox(char *text,char *title,int length)
{
	hidemouse();
	settextstyle(2,0,4);
	char str[80];
	int height,xcol1,ycol1,xcol2,ycol2,len,width;
	len=length*8;
	width=strlen(text)*8;
	if(len<width)
	{
		height=60;
		xcol1=320-(width/2),xcol2=320+(width/2);
		ycol1=240-(height/2),ycol2=240+(height/2);
	}
	if(len>width)
	{
		height=60;
		xcol1=320-(len/2),xcol2=320+(len/2);
		ycol1=240-(height/2),ycol2=240+(height/2);
	}
	back(xcol1,ycol1,xcol2,ycol2+15,0);
	openwindow2(xcol1,ycol1,xcol2,ycol2+15,title);
	setcolor(0);
	buttonon(310,ycol2-5,330,ycol2+10,"OK",3);
	setcolor(0);
	outtextxy(xcol1+10,ycol1+15,text);
	setfillstyle(1,15);
	bar(xcol1+5,ycol1+30,xcol2-6,ycol1+45);
	buttonclick(xcol1+5,ycol1+30,xcol2-6,ycol1+45);
	moveto(xcol1+8,ycol1+30);
	isigraph(str,length);
	showmouse();
	showmouse();
	int lc=1;
	while(lc==1)
	{
		getmouse(button,x,y);
		if((x>310)&&(x<330)&&(y>ycol2-5)&&(y<ycol2+10)&&(button==1))
		{
			buttonclick(310,ycol2-7,330,ycol2+10);delay(50);
			lc=0;
		}
		if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
		{
			buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
			lc=0;
		}
		if(inkey()==13)
		{ lc=0; }
	}
	hidemouse();
	back(xcol1,ycol1,xcol2,ycol2+15,1);
	showmouse();
	delay(90);
	return (str);
}

void openwindow2(int x1,int y1,int x2,int y2,char text[],int fillst,int titlecolor,int darkshade,int lightshade,int normalshade)
{
	hidemouse();
	setfillstyle(fillst,normalshade);
	bar(x1,y1,x2,y2);
	setfillstyle(1,titlecolor);
	bar(x1+1,y1+1,x2-1,y1+15);
	setfillstyle(1,normalshade);
	bar(x2-13,y1+3,x2-3,y1+12);
	settextstyle(2,HORIZ_DIR,4);
	setcolor(15);
	outtextxy(x1+2,y1+2,text);
	setcolor(lightshade);
	line(x1,y1,x2,y1);
	line(x1,y1,x1,y2);
	setcolor(darkshade);
	line(x2,y1,x2,y2);
	line(x2,y2,x1,y2);
	buttonon(x2-15,y1+2,x2-3,y1+15,"X",3);
	showmouse();
}

void openwindow(int x1,int y1,int x2,int y2,char text[],int fillst,int titlecolor,int darkshade,int lightshade,int normalshade)
{
	hidemouse();
	setfillstyle(fillst,normalshade);
	bar(x1,y1,x2,y2);
	setfillstyle(1,titlecolor);
	bar(x1+1,y1+1,x2-1,y1+15);
	setfillstyle(1,normalshade);
	bar(x2-13,y1+3,x2-3,y1+12);
	settextstyle(2,HORIZ_DIR,4);
	setcolor(15);
	outtextxy(x1+2,y1+2,text);
	setcolor(lightshade);
	line(x1,y1,x2,y1);
	line(x1,y1,x1,y2);
	setcolor(darkshade);
	line(x2,y1,x2,y2);
	line(x2,y2,x1,y2);
	buttonon(x2-15,y1+2,x2-3,y1+15,"X",3);
	showmouse();
}

void buttonon(int x1,int y1,int x2,int y2,char text[],int spc)
{
	hidemouse();
	setfillstyle(1,7);
	bar(x1,y1,x2,y2);
	setcolor(0);
	settextstyle(2,HORIZ_DIR,4);
	outtextxy(x1+1+spc,y1+1,text);
	buttoneffect(x1,y1,x2,y2);
	showmouse();
}

void buttoneffect(int x1,int y1,int x2,int y2)
{
	setcolor(15);
	line(x1,y1,x2,y1);
	line(x1,y1,x1,y2);
	setcolor(8);
	line(x2,y1,x2,y2);
	line(x1,y2,x2,y2);
}

void initaddons(char dir[])
{
	int gd=VGA,gm=VGAHI;
	initgraph(&gd,&gm,dir);
	initmouse();
	showmouse();
}

void buttonclick(int x1,int y1,int x2,int y2)
{
	hidemouse();
	setcolor(0);
	line(x1,y1,x2,y1);
	line(x1,y1,x1,y2);
	setcolor(15);
	line(x2,y1,x2,y2);
	line(x1-1,y2,x2,y2);
	setcolor(8);
	line(x1-1,y1-1,x2-1,y1-1);
	line(x1-1,y1-1,x1-1,y2-1);
	setcolor(7);
	line(x2-1,y1,x2-1,y2-1);
	line(x1-1,y2-1,x2-1,y2-1);
	showmouse();
}

cur(int on)
{
	int curx,oc;
	char ub[2]={'_',0};
	settextstyle(SMALL_FONT,HORIZ_DIR,4);
	setcolor(1);
	if(!(on))
	{
		oc=getcolor();
		setcolor(15);
	}
	curx=getx();
	outtext(ub);
	moveto(curx,gety());
	if(!on)
	setcolor(oc);
}

void isigraph(char *input,int s)
{
	int std=0,oc,c=0;
	char ch,out[2];
	int xval[255];
	out[1]=0;
	xval[0]=getx();
	do
	{
	cur(ON);
	ch=getch();
	cur(OFF);
	if(ch==0)
	getch();
	else
	{
		if(ch==8)
		{
			oc=getcolor();
			--std;
			if(std<0)
			std=0;
			moveto(xval[std],gety());
			setcolor(15);
			out[0]=input[std];
			outtext(out);
			moveto(xval[std],gety());
			setcolor(oc);
			c--;

		}
		else
		{
			input[std]=ch;
			out[0]=ch;
			if(c<s)
			{
			outtext(out);
			++std;
			xval[std]=getx();
			c++;
			}
		}
	}
}while((c<s&&ch!=13)||(ch!=13&&ch!=10));
input[std]=0;
}

void getpassword(char *input,char *passchar,int s)
{
	int std=0,oc,c=0;
	char ch,out[2];
	int xval[255];
	out[1]=0;
	xval[0]=getx();
	settextstyle(SMALL_FONT,HORIZ_DIR,4);
	do
	{
	cur(ON);
	ch=getch();
	cur(OFF);
	if(ch==0)
	getch();
	else
	{
		if(ch==8)
		{
			oc=getcolor();
			--std;
			if(std<0)
			std=0;
			moveto(xval[std],gety());
			setcolor(15);
			out[0]=input[std];
			outtext(passchar);
			moveto(xval[std],gety());
			setcolor(oc);
			c--;

		}
		else
		{
			input[std]=ch;
			out[0]=ch;
			if(c<s)
			{
			if(ch!=13)
			outtext(passchar);
			++std;
			xval[std]=getx();
			c++;
			}
		}
	}
}while((c<s&&ch!=13)||(ch!=13&&ch!=10));
input[std]=0;
}

void getstr(int s,char *input)
{
	int std=0,oc,c=0;
	char ch,out[2];
	int xval[255];
	out[1]=0;
	xval[0]=getx();
	do
	{
	cur(ON);
	ch=getch();
	cur(OFF);
	if(ch==0)
	getch();
	else
	{
		if(ch==8)
		{
			oc=getcolor();
			--std;
			if(std<0)
			std=0;
			moveto(xval[std],gety());
			setcolor(15);
			out[0]=input[std];
			outtext(out);
			moveto(xval[std],gety());
			setcolor(oc);
			c--;
		}
		else
		{
			input[std]=ch;
			out[0]=ch;
			outtext(out);
			++std;
			xval[std]=getx();
		}
	}
}while(c<s&&ch!=13&&ch!=10);
input[std]=0;
}

void checkbox(int x1,int y1,int status)
{
	setfillstyle(1,15);
	bar(x1,y1,x1+8,y1+10);
	buttonclick(x1,y1,x1+8,y1+10);
	if(status==1)
	{
		setfillstyle(1,0);
		bar(x1+2,y1+2,x1+6,y1+8);
	}
	if(status==0)
	{
		setfillstyle(1,15);
		bar(x1+2,y1+2,x1+6,y1+8);
	}
}

void progressbar(int x1,int y1,int status,int display)
{
	if(display==1)        //make
	{
		setfillstyle(1,7);
		bar(x1,y1,x1+50,y1+10);
		buttonclick(x1,y1,x1+54,y1+10);
		setfillstyle(1,2);
		bar(x1+2,y1+2,(x1+(status/2)),y1+8);
	}
	else if(display==0)         //operate
	{
		setfillstyle(1,2);
		bar(x1+2,y1+2,(x1+(status/2)),y1+8);
	}
}

void menu(int xcol,int ycol,char *list[],int height,int width)
{
	int h=(height*15)+10;
	int w=width*8;
	setfillstyle(1,7);
	bar(xcol,ycol,xcol+w,ycol+h);
	buttoneffect(xcol,ycol,xcol+w,ycol+h);
	settextstyle(2,HORIZ_DIR,4);
	setcolor(0);
	for(int a=0;a<height;a++)
	{
		outtextxy(xcol+3,(ycol+2+(a*15)),list[a]);
	}
}


void marquee(char text[],int x1,int y1,int x2,int dir)
{
	int c=getcolor(),d,e=0;
	float *backgr;
	backgr=new float[100];
	for(int col=x2;col>=x1;col--)
	{
		if(col>x2+200)
		{
			e=x2-col;
		}
		else
		{
			e=200;
		}
		getimage(col-1,y1,(col-1)+textwidth(text),y1+textheight(text)+10,backgr);
		outtextxy(col,y1,text);
		delay(20);
		putimage(col-1,y1,backgr,COPY_PUT);
	}
	delete backgr;
}

// Now I introduce Mouse Functions

void initmouse()
{
	i.x.ax=0;
	int86(0x33,&i,&o);
}

void showmouse()
{
       i.x.ax=1;
       int86(0x33,&i,&o);
}

void hidemouse()
{
       i.x.ax=2;
       int86(0x33,&i,&o);
}

void getmouse(int& button,int& x,int& y)
{
       i.x.ax=3;
       int86(0x33,&i,&o);
       button= o.x.bx;
       x=o.x.cx;
       y=o.x.dx;
}
void setmouse(int x,int y)
{
	i.x.ax=4;
	i.x.cx=x;
	i.x.dx=y;
	int86(0x33,&i,&o);
}

void getmousepos(int *button,int *x,int *y)
{
       i.x.ax=3;
       int86(0x33,&i,&o);
       *button= o.x.bx;
       *x=o.x.cx;
       *y=o.x.dx;
}

void restrictmouse(int x1,int y1,int x2,int y2)
{
      i.x.ax=7;
      i.x.cx=x1;
      i.x.dx=x2;
      int86(0x33,&i,&o);
      i.x.ax=8;
      i.x.cx=y1;
      i.x.dx=y2;
      int86(0x33,&i,&o);
}

void mouseptr(int mark[50],int xstart,int ystart)
{
      i.x.ax=9;
      i.x.bx=xstart;
      i.x.cx=ystart;
      i.x.dx=(int)mark;
      segread(&s);
      s.es=s.ds;
      int86x(0x33,&i,&i,&s);
}

void getclick(int bta,int btb,int link[][5])
{
	while(loopmain!=0)
	{
		getmouse(button,x,y);
		for(int bd=bta;bd<=btb;bd++)
		{
			getmouse(button,x,y);

		}
	}
}

int getlink(int bta,int btb,int link[][5])
{
	while(loopmain!=0)
	{
		getmouse(button,x,y);
		for(int bd=bta;bd<=btb;bd++)
		{
			getmouse(button,x,y);
			if((x>link[bd][0])&&(y>link[bd][1])&&(x<link[bd][2])&&(y<link[bd][3])&&(button==link[bd][4]))
			{
				return(bd);
			}
		}
	}
	return(0);
}


void activate(int x1,int y1,int x2,int y2,int n,int link[][5],int forbtn)
{ link[n][0]=x1;
  link[n][1]=y1;
  link[n][2]=x2;
  link[n][3]=y2;
  link[n][4]=forbtn;
}

void pressbtn(int no,int link[][5])
{ hidemouse();
  buttonclick(link[no][0],link[no][1],link[no][2],link[no][3]);
  showmouse();
}

void liftbtn(int no,int link [][5])
{ hidemouse();
  buttoneffect(link[no][0],link[no][1],link[no][2],link[no][3]);
  showmouse();
}

void endgui()
{ closegraph();restorecrtmode();exit(1);
}

int activemenu(int xc1,int yc1,char *list[],int rows,int cols)
{ hidemouse();
  /*back(xc1,yc1,xc1+(rows*15)+10,yc1+(cols*8)+10,0);*/
  /*menu(xc1,yc1,test,rows,cols);*/
  int h=((rows*15)+10);
  int w=((cols*8)+10);
  setfillstyle(1,7);
  float *bck;
  float sz=imagesize(xc1,yc1,xc1+w,yc1+h);
  bck=new float[sz];
  getimage(xc1,yc1,xc1+w,yc1+h,bck);
  bar(xc1,yc1,xc1+w,yc1+h);
  buttoneffect(xc1,yc1,xc1+w,yc1+h);
  settextstyle(2,HORIZ_DIR,4);
  setcolor(0);
  for(int a=0;a<rows;a++)
  { outtextxy(xc1+3,(yc1+2+(a*15)),list[a]);
  }
  showmouse();
  getmouse(button,x,y);
  int lc=1,fnc=0,over=-1;
  delay(50);
  while(lc==1)
  { getmouse(button,x,y);
    for(int b=0;b<rows;b++)
    { if(button==1)
      { if((x>xc1+w)||(x<xc1)||(y>yc1+h)||(y<yc1))
	  { fnc=0;lc=0;
	  }
	else if((y>(yc1+(15*b)))&&(y<(yc1+(15*b)+15)))
	  { fnc=b+1;
	    lc=0;
	  }

      }
      if(button==0)
      { if((y>(yc1+(15*b)))&&(y<(yc1+(15*b)+15)))
	{ if((b!=over)||(over==-1))
	  { if(over!=-1)
	     {invertcolors(xc1+2,yc1+(15*over)+1,xc1+w-2,yc1+(15*over)+13);}
	    invertcolors(xc1+2,yc1+(15*b)+1,xc1+w-2,yc1+(15*b)+13);over=b;
	  }
	  over=b;
	}
      }
    }
  }
    hidemouse();
    putimage(xc1,yc1,bck,COPY_PUT);
    showmouse();
    delete bck;
    return(fnc);

}

void back(int x1,int y1,int x2,int y2,int mode,char *file)
{  int ch;char c2;
   if(mode==0)
   {
     float sts=4;
     ofstream outfile(file);
     for(int b=y1;b<=y2;b++)
     { for(int a=x1;a<=x2;a++)
       { ch=getpixel(a,b);
	 outfile<<(char)(ch+28);
       }
       sts+=(((a-x1)/(x2-x1))*100);
     }
     outfile.close();
   }
   else if(mode==1)
   {
     ifstream infile(file);
     for(int b=y1;b<=y2;b++)
     { for(int a=x1;a<=x2;a++)
       { infile.get(c2);ch=(int)c2;
	 putpixel(a,b,ch-28);
       }
     }
     infile.close();

   }
}

void say(char text[],char title[])
{
  hidemouse();
  settextstyle(2,0,4);
  int width=textwidth(text)+20;
  int height=60;
  int xcol1=320-(width/2),xcol2=320+(width/2);
  int ycol1=240-(height/2),ycol2=240+(height/2);
/*  float sz=imagesize(xcol1,ycol1,xcol2,ycol2);
  float *bk;
  bk=new float[sz];
  getimage(xcol1,ycol1,xcol2,ycol2,bk);*/
  back(xcol1,ycol1,xcol2,ycol2,0);
  openwindow(xcol1,ycol1,xcol2,ycol2,title);
  setcolor(0);
  buttonon(310,ycol2-17,330,ycol2-2,"OK",3);
  setcolor(0);
  outtextxy(xcol1+10,ycol1+20,text);
  showmouse();
  int lc=1;               //x2-15,y1+2,x2-3,y1+15
  while(lc==1)
  { getmouse(button,x,y);
    if((x>310)&&(x<330)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
    { buttonclick(310,ycol2-17,330,ycol2-2);delay(50);
      lc=0;
    }
    if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
    { buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
      lc=0;
    }
    if(inkey()==13)
    { lc=0; }
  }
  hidemouse();
 back(xcol1,ycol1,xcol2,ycol2,1);
  showmouse();
  delay(90);
}

char* intext(int x1,int y1)   //intext
{ setcolor(0);
  settextstyle(2,0,4);
  int xcn=0;int in2=0;
  char in[2];
  char *yotext;
  in[1]='\0';
  while(*in!=(char)13)
  { st:
    in[0]=getch();
    if(in[0]==(char)13)
     { break;
     }
    else if
    (in[0]==(char)8)
    {in2-=6;xcn--;setfillstyle(1,15);bar(x1+in2,y1,x1+in2+textwidth("W"),y1+textheight("Wg"));goto st;}
    setfillstyle(1,15);bar(x1+in2,y1,x1+in2+textwidth(in),y1+textheight(in));
    outtextxy(x1+in2,y1,in);
    in2+=6;
    yotext[xcn]=in[0];
    xcn++;
  }
  yotext[xcn]='\0';
  return(yotext);
}

int confirm(char text[],char title[])
{
  hidemouse();
  settextstyle(2,0,4);
  int width=textwidth(text)+20;
  int height=60;
  int xcol1=320-(width/2),xcol2=320+(width/2);
  int ycol1=240-(height/2),ycol2=240+(height/2);
  /*float sz=imagesize(xcol1,ycol1,xcol2,ycol2);
  float *bk;
  bk=new float[sz];
  getimage(xcol1,ycol1,xcol2,ycol2,bk);*/
  back(xcol1,ycol1,xcol2,ycol2,0);
  openwindow(xcol1,ycol1,xcol2,ycol2,title);
  setcolor(0);
  buttonon(320-31,ycol2-17,320-1,ycol2-2,"OK",6);
  buttonon(320+1,ycol2-17,320+41,ycol2-2,"Cancel",3);
  sel(320+1,ycol2-17,320+41,ycol2-3,1);
  setcolor(0);
  outtextxy(xcol1+10,ycol1+20,text);
  showmouse();
  int lc=1,ans=0,opt=2,in;               //x2-15,y1+2,x2-3,y1+15
  while(lc==1)
  { getmouse(button,x,y);
    in=inkey();
    if((x>320-31)&&(x<320-1)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
    { buttonclick(320-31,ycol2-17,320-1,ycol2-2);delay(50);ans=1;
      lc=0;
    }
    if((x>xcol2-15)&&(y>ycol1+2)&&(x<xcol2-3)&&(y<ycol1+15)&&(button==1))
    { buttonclick(xcol2-15,ycol1+2,xcol2-3,ycol1+15);delay(50);
      lc=0;
    }
     if((x>320+1)&&(x<320+41)&&(y>ycol2-17)&&(y<ycol2-2)&&(button==1))
     { buttonclick(320+1,ycol2-17,320+41,ycol2-2);delay(50);ans=0;
       lc=0;
     }

     if(in==13)
     { if(opt==1) {ans=1;}
       else if(opt==2) {ans=0;}
       lc=0;
     }
     if(in==75)
     { opt=1;
       sel(320-31,ycol2-17,320-1,ycol2-3,1);
       sel(320+1,ycol2-17,320+41,ycol2-3,0);
     }
     if(in==77)
     { opt=2;
       sel(320-31,ycol2-17,320-1,ycol2-3,0);
       sel(320+1,ycol2-17,320+41,ycol2-3,1);
     }

  }
  hidemouse();
  back(xcol1,ycol1,xcol2,ycol2,1);
  /*putimage(xcol1,ycol1,bk,COPY_PUT);
  delete bk;*/
  showmouse();
  delay(90);
  return(ans);
}

void cmdbtn(int x1,int y1,int x2,int y2,char text[],int no,int link[][5],int forbtn)
{ buttonon(x1,y1,x2,y2,text,3);
  activate(x1,y1,x2,y2,no,link,forbtn);
}
void iconbtn(int x1,int y1,int x2,int y2,char text[],int no,int link[][5],int forbtn)
{ buttonon(x1,y1,x2,y2,"",3);
  activate(x1,y1,x2,y2,no,link,forbtn);
  image(x1+3,y1+3,x2-3,y2-3,text);
}

void image(int x1,int y1,int x2,int y2,char filename[])
{
     char c2;
     int width,height,ch;
     ifstream infile(filename);
     if(infile)
     {	infile>>width>>height;
	setviewport(x1,y1,x2,y2,1);
	hidemouse();
	for(int a=0;a<=width;a++)
	{ for(int b=0;b<=height;b++)
	  { infile.get(c2);ch=(int)c2;
	    putpixel(a,b,ch-28);
	  }
	}
	setviewport(0,0,639,479,1);
	showmouse();
     }
     infile.close();
}


class windows
{ private:
   int xcol1,ycol1,xcol2,ycol2;
   char *titleofwindow;
  public:
   void newwindow(int x1,int y1,int x2,int y2,char tit[])
    { xcol1=x1;ycol1=y1;xcol2=x2;ycol2=y2;
      titleofwindow=tit;
      hidemouse();
      back(xcol1,ycol1,xcol2,ycol2,0,tit);
      openwindow(xcol1,ycol1,xcol2,ycol2,tit);
      showmouse();
    }
   void setcolors(int titlecol,int darkshade,int lightshade,int normalfill,int fillstyle)
    { openwindow(xcol1,ycol1,xcol2,ycol2,titleofwindow,fillstyle,titlecol,darkshade,lightshade,normalfill);
    }
   void closewindow()
    { hidemouse();
      back(xcol1,ycol1,xcol2,ycol2,1,titleofwindow);
      showmouse();
      remove(titleofwindow);
    }
};

class textbox
{ private:
    char *textfill;
    int x1,y1,len;
    int *bck;
  public:
  void make(int xc1,int yc1,int leng)
  { bck=new int[imagesize(xc1,yc1,xc1+(8*leng),yc1+15)];
    getimage(xc1,yc1,xc1+(8*leng),yc1+15,bck);
    x1=xc1; y1=yc1; len=leng;
    textfield(xc1,yc1,leng);
  }
  void text(char tex[])
  { setfillstyle(1,15);
    bar(x1+2,y1+2,x1+textwidth(tex),y1+13);
    settextstyle(2,HORIZ_DIR,4);
    setcolor(0);
    outtextxy(x1+2,y1+2,tex);
    textfill=strcpy(textfill,tex);
  }
  char *qtext()
  { return(textfill);}
  void clear()
  { putimage(x1,y1,bck,COPY_PUT); }
};

class check
{ private:
   int x1,y1;
  public:
   int stat;
   void make(int xc1,int yc1)
   { checkbox(xc1,yc1,0);
     x1=xc1; y1=yc1; stat=0;
   }
   void on()
   { checkbox(x1,y1,1); stat=1; }
   void off()
   { checkbox(x1,y1,0); stat=0; }

};

void pointer(int pt)
{
 int arrow[32]={ 0x9fff,0x8fff,0x87ff,0x83ff,0x81ff,0x80ff,0x807f,0x803f,0x801f,0x800f,0x80ff,
	       0x887f,0x987f,0xfc3f,0xfc3f,0xfe3f,0x0000,0x2000,0x3000,0x3800,0x3c00,0x3e00,
	       0x3f00,0x3f80,0x3fc0,0x3e00,0x3600,0x2300,0x0300,0x0180,0x0180,0x0000
	    };
int ibeam[32]={ 0xe187,0xe007,0xfc3f,0xfc3f,0xfc3f,0xfc3f,0xfc3f,0xfc3f,0xfc3f,0xfc3f,0xfc3f,
	      0xfc3f,0xfc3f,0xfc3f,0xe007,0xe187,0x0000,0x0e70,0x0180,0x0180,0x0180,0x0180,
	      0x0180,0x0180,0x0180,0x0180,0x0180,0x0180,0x0180,0x0180,0x0e70,0x0000
	    };
int cursor[32]={ 0xff7f,0xff7f,0xff7f,0xff7f,0xff7f,0xff7f,0xff7f,0xff7f,
		   0x0080,0xff7f,0xff7f,0xff7f,0xff7f,0xff7f,0xff7f,0xff7f,
		   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
		   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
		    };
int wait[32]={ 0x8001,0xc003,0xc003,0xc003,0xc003,0xe007,0xf00f,0xf81f,0xf81f,0xf00f,0xe007,
	       0xc003,0xc003,0xc003,0xc003,0x8001,0x7ffe,0x2004,0x2004,0x2004,0x2664,0x13c8,
	       0x0990,0x0420,0x0420,0x0990,0x13c8,0x27e4,0x2ff4,0x2ff4,0x2004,0x7ffe
	      };
int icon[32]={ 0xffff,0xffff,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,0xc003,
	       0xc003,0xc003,0xc003,0xffff,0xffff,0x0000,0x0000,0x3ffc,0x3ffc,0x300c,0x300c,
	       0x33cc,0x33cc,0x33cc,0x33cc,0x300c,0x300c,0x3ffc,0x3ffc,0x0000,0x0000
	      };



hidemouse();
switch(pt)
{ case 1: mouseptr(arrow,1,1);break;
  case 2: mouseptr(ibeam,1,1);break;
  case 3: mouseptr(wait,1,5);break;
  case 4: mouseptr(icon,8,8);break;
  default:break;
}
showmouse();
}

int inkey()
{ char k;
  if(kbhit())
  { k=getch();
    if(k==0)
    { k=getch();
      return((int)k);
    }
    else{ return((int)k);}
  }
  return(0);
}

void sel(int x1,int y1,int x2,int y2,int md)
{ hidemouse();
  if(md==1)  // select
  { setcolor(0);
    rectangle(x1-1,y1-1,x2+1,y2+2);
  }
  else
  { setcolor(7);
    rectangle(x1-1,y1-1,x2+1,y2+2);
  }
  showmouse();
}

void select(int x1,int y1,int x2,int y2,int md)
{
	setlinestyle(DOTTED_LINE,0,1);
	if(md==1)  // Select
	{
		setcolor(0);
		rectangle(x1-1,y1-1,x2+1,y2+2);
	}
	else      // Deselect
	{
		setcolor(7);
		rectangle(x1-1,y1-1,x2+1,y2+2);
	}
	setlinestyle(SOLID_LINE,0,1);
}

void select_with_color(int x1,int y1,int x2,int y2,int color)
{
	setlinestyle(DOTTED_LINE,0,1);
	setcolor(color);
	rectangle(x1-1,y1-1,x2,y2);
	setlinestyle(SOLID_LINE,0,1);
}

void deselect_with_color(int x1,int y1,int x2,int y2,int color)
{
	setlinestyle(DOTTED_LINE,0,1);
	setcolor(color);
	rectangle(x1-1,y1-1,x2,y2);
	setlinestyle(SOLID_LINE,0,1);
}

void invertcolors(int x1,int y1,int x2,int y2)
{  int cl;
   hidemouse();
   for(int a=x1;a<=x2;a++)
   { for(int b=y1;b<=y2;b++)
     { cl=getpixel(a,b);
       putpixel(a,b,15-cl);
     }
   }
   showmouse();
}


/*******************************************************/
/*                                                     */
/*  VGASetAllPalette sets 256 colors and border color  */
/*						       */
/*******************************************************/

void VGASetAllPalette (VGAPaletteType P)  //This function gets a structure f all 256 colors.
{
    struct REGPACK Regs;
    Regs.r_ax = 0x1012;
    Regs.r_bx = 0;
    Regs.r_cx = 256;
    Regs.r_es = FP_SEG (P);
    Regs.r_dx = FP_OFF (P);

    intr (0x10, &Regs);
} /* VGASetAllPalette*/


/*****************************************************/
/*                                                   */
/*  HSI2Rgb converts hue H, Saturation S and         */
/*          Intensity I to Red-Green-Blue components */
/*						     */
/*****************************************************/

void Hsi2Rgb (double H, double S, double I, struct ColorValue * C)
{
    double T  = 2 * M_PI * H;                   /* direction on the circle */
    double Rv = 1 + S * sin(T - 2 * M_PI / 3);  /* R \                     */
    double Gv = 1 + S * sin(T);                 /* G  > components (0..2)  */
    double Bv = 1 + S * sin(T + 2 * M_PI / 3);  /* B /                     */

    T = 63.999 * I / 2;				/* max color intensity = 63*/

    C->Rvalue = (int)(Rv * T);
    C->Gvalue = (int)(Gv * T);
    C->Bvalue = (int)(Bv * T);

} /*{ Hsi2Rgb }*/

int AddColor (int *colorno, struct ColorValue *C, VGAPaletteType P)
{
    int i, curcolor;

    for (curcolor = 0, i = 1; i < *colorno; i++)  /* scan those already existing */
    {
	if (P[i].Rvalue == C->Rvalue     /* if we 		*/
	&&  P[i].Gvalue == C->Gvalue     /* already have		*/
	&&  P[i].Bvalue == C->Bvalue)    /* this color		*/
	{
	    curcolor = i;		/* then use this color  */
	    break;
	}
    }

    if (!curcolor)			/* Otherwise!    */
    {
	if (*colorno < 255)		/* if not overflow */
	{
	    curcolor = (*colorno)++;    /* add then a new color */
	    P[curcolor] = *C;		/* to the palette */
	    VGASetAllPalette(P);	/* and reset the palette */
	}
    }

    return curcolor;
}



/***********************************************/
/*                                             */
/*   Hue demonstrates a hue circle         */
/*           of maximal saturations            */
/*                                             */
/***********************************************/


int Hue(int left,int top,int right,int bottom,int xcent,int ycent)
{
    const int xcenter =xcent, ycenter = ycent;//ycenter is top. xcenter is middle from top.
    char buf[281];        	/* buffer for sprintf */
    double H, S;
    VGAPaletteType P;		/* contains all 256 colors definition */
    struct ColorValue C;
    int     x,  y, Z;
    double rx, ry;
    int colorno = 1, curcolor;

    getaspectratio (&xasp, &yasp);
/* make almost all colors blackest black */
    for (Z = 0; Z < 255; Z++)
    {
	P[Z].Rvalue = 0;
	P[Z].Gvalue = 0;
	P[Z].Bvalue = 0;
    }
/* make color 255 whitest white */
    P[253].Rvalue = 63;
    P[253].Gvalue = 63;
    P[253].Bvalue = 63;

    VGASetAllPalette(P);  /* A preparatory measure */

    for (y = top; y < bottom  ; y++)  /*scan a square round the circle*/
    {
    for (x = left; x < right; x++)              /*scan the square*/ //0 is left and 800 is right.
    {
	rx = (double)(x - xcenter) / yasp;  /* weighted x-distance */
	ry = (double)(y - ycenter) / xasp;  /* weighted y-distance */

	S =  sqrt (rx * rx + ry * ry);  /* distance to center */ //1000 is square and 10000 is round.

	if (S < 1.)                         /* not too far? */
	{
	    if (S > .0000001)               /* not too near? */
		H = .5 + atan2 (ry, rx) / M_PI / 2; /* hue circular value */
	    else
		H = 0.;		    /* atan2 does not work in microcosm */

	    H = (int)(H*290.5)/ 290.5; /* discretize it to avoid color overflow */

	    Hsi2Rgb (H, 1., 1., &C); /* convert to RGB */

	    curcolor = AddColor (&colorno, &C, P);
	    if (curcolor)
		putpixel (x, y, curcolor);
	    else
	    {
		setcolor (1);
		outtextxy (1, ycenter, "Out of colors, press a key!");
		while (!kbhit());
		break;
	    }
	}
    }
    }

    VGASetAllPalette(P);
}

class ComboMenu
{
	private:

	int l,t,r,b,btop,bbottom,length;
	int row;

	public:

	void Show(int left,int top,char*list[],int rows)
	{

		int h=((rows*15)+10);
		int s=1,size;

		settextstyle(2,0,4);
		for ( int i = 0 ; i < rows ; i++ )
		{
			if ( strlen ( list[i] ) > s )
			{
				s = strlen ( list[i] ) ;
				s=s;
			}
		}
		s=s*8+20;
		size=s;
		int w=size;
		length=w;

		back(left,top,left+w,top+h,0);

		setfillstyle(1,15);
		bar(left,top,left+w,top+h);
		//buttoneffect(left,top,left+w,top+h);
		settextstyle(2,HORIZ_DIR,4);
		setcolor(0);
		for(int a=0;a<rows;a++)
			outtextxy(left+3,(top+2+(a*15)),list[a]);

		l=left,t=top,r=left+w,b=top+h;
		btop=t;bbottom=btop+15;
		row=rows;
		invertcolors(l+2,t+2,r-3,t+15);
	}

	int Keypress(char *list[])
	{
		static int counter=0;
		static int scrollup=0;
		static int scrolldown=0;
		int scrolltime=row;

		int h=((row*15)+10);
		int s=1,size;

		settextstyle(2,0,4);
		for ( int i = 0 ; i < row ; i++ )
		{
			if ( strlen ( list[i] ) > s )
			{
				s = strlen ( list[i] ) ;
				s=s;
			}
		}
		s=s*8+20;
		size=s;
		int w=size;
		length=w;

		while(1)
		{
			int in,ret;
			in=inkey();

			if(in==72)
			{
				if(scrollup>0)
				{
					scrollup--;
					invertcolors(l+2,btop+2,r-3,bbottom);
					btop=btop-15;
					bbottom=bbottom-15;
					invertcolors(l+2,btop+2,r-3,bbottom);
					scrolldown=scrollup;
					counter=scrollup;
					return scrollup+1;
				}
			}

			if(in==80)
			{
				if(scrolldown<scrolltime-1)
				{
					scrolldown++;
					counter++;
					invertcolors(l+2,btop+2,r-3,bbottom);
					btop=btop+15;
					bbottom=bbottom+15;
					invertcolors(l+2,btop+2,r-3,bbottom);
					scrollup=counter;
					ret=scrolldown+1;
					//counter=scrolldown;
					return ret;
				}
			}
			if(in==13)
			{
				counter=0;
				scrolldown=0;
				scrollup=0;
				back(l,t,l+w,t+h,1);
				return -1;
				break;
			}
		}
		counter=0;
		scrolldown=0;
	}
};

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *