#include <iostream.h>
#include <fstream.h>
#include <process.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
#include <iomanip.h>
#include <graphics.h>
#include <stdlib.h>
char filename[15];
char wpad[21][51];
int cl=0;
void TITLE_BAR()
{
outtextxy(getmaxx()-120,12,"NONAME");
rectangle(getmaxx()-200,5,getmaxx()-5,25);
rectangle(getmaxx()-70,25,getmaxx()-5,45);
outtextxy(getmaxx()-65,32,"Veditor");
}
void WRITING_PAD()
{
rectangle(5,50,getmaxx()-200,getmaxy()-45);
rectangle(5,getmaxy()-45,100,getmaxy()-25);
}
void ERASE_LINE(int posy)
{
int poly[8];
poly[0]=16;
poly[1]=79+posy-2*textheight("W");
poly[2]=getmaxx()-205;
poly[3]=79+posy-2*textheight("W");
poly[4]=getmaxx()-205;
poly[5]=79+posy;
poly[6]=16;
poly[7]=79+posy;
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(4,poly);
}
void CURSOR(int posx,int posy)
{
if(posx==0 &&posy==0)
{
while(!kbhit())
{
setcolor(15);
outtextxy(16,73,"_");
delay(150);
setcolor(0);
outtextxy(16,73,"_");
delay(150);
}
}
else
{
setcolor(0);
outtextxy(16+posx-textwidth("W"),73+posy,"_");
while(!kbhit())
{
setcolor(15);
outtextxy(16+posx,73+posy,"_");
delay(150);
setcolor(0);
outtextxy(16+posx,73+posy,"_");
delay(150);
}
}
}
void BCURSOR(int posx,int posy)
{
setcolor(0);
outtextxy(16+posx,73+posy,"_");
}
void ERASE_GRAPHH()
{
int poly[8];
poly[0]=getmaxx()-170;
poly[1]=70;
poly[2]=getmaxx()-5;
poly[3]=70;
poly[4]=getmaxx()-5;
poly[5]=163;
poly[6]=getmaxx()-170;
poly[7]=163;
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(4,poly);
}
void WPAD_INACTIVE()
{
int poly[8];
poly[0]=8;
poly[1]=53;
poly[2]=getmaxx()-203;
poly[3]=53;
poly[4]=getmaxx()-203;
poly[5]=getmaxy()-48;
poly[6]=8;
poly[7]=getmaxy()-48;
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(4,poly);
}
void FILE_SAVING(char wpad[72][51],int cl)
{
if(filename[0]=='\0')
{
setcolor(15);
rectangle(getmaxx()-170,70,getmaxx()-5,160);
outtextxy(getmaxx()-150,90,"ENTER_FILENAME");
rectangle(getmaxx()-150,110,getmaxx()-20,130);
gotoxy(63,8);
gets(filename);
ERASE_GRAPHH();
outtextxy(getmaxx()-120,12,"NONAME");
setcolor(15);
outtextxy(getmaxx()-120,12,filename);
}
ofstream out(filename);
for(int fip=0;fip<=cl;fip++)
{
for(int fjp=0;wpad[fip][fjp]!='\0';fjp++)
{
out.put(wpad[fip][fjp]);
}
out.put('\n');
}
out.close();
setcolor(15);
outtextxy(getmaxx()-300,getmaxy()-40,"FILE_SAVED");
delay(500);
setcolor(0);
outtextxy(getmaxx()-300,getmaxy()-40,"FILE_SAVED");
setcolor(15);
}
void WPAD_ACTIVE()
{
char ch[1],chh;
int ip,i,j,x,y,q,posx=0,posy=0,len,da=0,v=0,halt=1;
filename[0]='\0';
for(i=0;i<21;i++)
{
for(j=0;j<51;j++)
{
wpad[i][j]='\0';
}
}
setcolor(5);
rectangle(5,50,getmaxx()-200,getmaxy()-45);
rectangle(5,getmaxy()-45,100,getmaxy()-25);
setcolor(15);
gotoxy(3,5);
label1:
CURSOR(posx,posy);
for(i=0;i<21;i++,cl++)
{
for(j=0;j<51;j++)
{
label:
chh=getch();
ip=chh;
if(ip==00)//ARRWOS AND OTHER FUNCTION
{
ip=getch();
if(ip=='<') // F2 (FILE SAVING)
{
FILE_SAVING(wpad,cl);
CURSOR(posx,posy);
goto label;
}
if(ip=='-') //ALT+X (MENU MOVEMENT)
{
halt=0;
setcolor(15);
rectangle(5,50,getmaxx()-200,getmaxy()-45);
rectangle(5,getmaxy()-45,100,getmaxy()-25);
break;
}
if(ip==72)//UP_ARROW
{
if(i==0)
{
CURSOR(posx,posy);
goto label;
}
if(strlen(wpad[i-1])<j)
{
posx=strlen(wpad[i-1])*textwidth("W");
j=strlen(wpad[i-1]);
}
posy-=2*textheight("W");
i=i-1;
CURSOR(posx,posy);
gotoxy(3+j,5-i);
goto label;
} //UP_ARROW_FINISH
if(ip==80)//DOWN_ARROW
{
if(i==cl)
{
CURSOR(posx,posy);
goto label;
}
da=1;
if(j>strlen(wpad[i+1]))
{
posx=strlen(wpad[i+1])*textwidth("W");
j=strlen(wpad[i+1]);
}
posy+=2*textheight("W");
i=i+1;
CURSOR(posx,posy);
gotoxy(3+j,5+i);
goto label;
} //DOWN_ARROW_FINISH
if(ip==75)//LEFT_ARROW
{
if(i==0 && j==0)
{
CURSOR(posx,posy);
goto label;
}
da=1;
if(j==0)
{
posy-=2*textheight("W");
i=i-1;
j=strlen(wpad[i])+1;
posx=textwidth("W")*j;
}
j--;
BCURSOR(posx-textwidth("W"),posy);
posx-=textwidth("W");
CURSOR(posx,posy);
goto label;
}//LEFT_ARROW_FINISH
if(ip==77)//RIGHT_ARROW
{
if(i==cl && j==strlen(wpad[i]))
{
CURSOR(posx,posy);
goto label;
}
da=1;
if(j==strlen(wpad[i]))
{
posy+=2*textheight("W");
i=i+1;
j=0;
posx=0;
BCURSOR(posx+textwidth("W"),posy);
CURSOR(posx,posy);
goto label;
}
else
j++;
BCURSOR(posx+textwidth("W"),posy);
posx+=textwidth("W");
CURSOR(posx,posy);
goto label;
}//RIGHT_ARROW_FINISH
if(ip==71)//HOME
{
da=1;
j=0;
BCURSOR(posx,posy);
posx=0;
CURSOR(posx,posy);
goto label;
}//HOME_FINISH
if(ip==79)//END
{
da=1;
BCURSOR(posx,posy);
j=strlen(wpad[i]);
posx=textwidth("W")*j;
CURSOR(posx,posy);
goto label;
}//END_FINISH
if(ip==83)//DELETE
{
if(i==cl && j==strlen(wpad[i]))
{
CURSOR(posx,posy);
goto label;
}
if(j==strlen(wpad[i]))
{
ERASE_LINE(cl*2*textheight("W"));
j=strlen(wpad[i]);
strcat(wpad[i],wpad[i+1]);
for(int cpy=i+1;cpy<cl;cpy++)
strcpy(wpad[cpy],wpad[cpy+1]);
wpad[cl][0]='\0';
cl--;
goto prnt;
}
for(x=j;wpad[i][x]!='\0';x++)
wpad[i][x]=wpad[i][x+1];
prnt:
for(int y=i;y<=cl;y++)
{
ERASE_LINE(y*2*textheight("W"));
gotoxy(3,5+y);
for(x=0;wpad[y][x]!='\0';x++)
putchar(wpad[y][x]);
}
CURSOR(posx,posy);
goto label;
}//DELETE_FINISH
}//ARROW_FINISH
if(ip!=8 &&ip!=13) //DATA_INPUT
{
if(cl==i && da==0)
{
wpad[i][j]=chh;
wpad[i][j+1]='\0';
}
else
{
len=strlen(wpad[i]);
for(int l=len+1;l>j;l--)
{
wpad[i][l]=wpad[i][l-1];
}
wpad[i][j]=chh;
wpad[i][len+2]='\0';
}
} //DATA_INPUT_FINISH
if(ip==13) //ENTER
{
if(j<strlen(wpad[i])-1 || i<cl)
{
for(int cpy1=cl+1;cpy1>i+1;cpy1--)
{
strcpy(wpad[cpy1],wpad[cpy1-1]);
wpad[cpy1-1][0]='\0';
}
v=0;
for(int cpy2=j;wpad[i][cpy2]!='\0';cpy2++)
{
wpad[i+1][v++]=wpad[i][cpy2];
}
wpad[i+1][v]='\0';
wpad[i][j]='\0';
for(int yz=i;yz<=cl+1;yz++)
{
ERASE_LINE(yz*2*textheight("W"));
gotoxy(3,5+yz);
for(int qq=0;wpad[yz][qq]!='\0';qq++)
{
putchar(wpad[yz][qq]);
}
}
}
else
{
wpad[i][j]='\0';
BCURSOR(posx-textwidth("W"),posy);
}
break;
} //ENTER_FINISH
if(ip==8) //BACK_SPACE
{
if(i==0 && j==0)
{
goto label1;
}
ERASE_LINE(posy);
if(j==0 && i>0)
{
ERASE_LINE(cl*2*textheight("W"));
posy-=2*textheight("W");
i=i-1;
j=strlen(wpad[i])+1;
strcat(wpad[i],wpad[i+1]);
for(int cpy=i+1;cpy<cl;cpy++)
strcpy(wpad[cpy],wpad[cpy+1]);
wpad[cl][0]='\0';
cl--;
posx=textwidth("W")*j;
goto prnt1;
}
for(x=j-1;wpad[i][x]!='\0';x++)
wpad[i][x]=wpad[i][x+1];
prnt1:
for(int y=i;y<=cl;y++)
{
ERASE_LINE(y*2*textheight("W"));
gotoxy(3,5+y);
for(x=0;wpad[y][x]!='\0';x++)
putchar(wpad[y][x]);
}
j=j-1;
BCURSOR(posx-textwidth("W"),posy);
posx-=textwidth("W");
CURSOR(posx,posy);
goto label;
} //BACKSPACE FINISH
ERASE_LINE(posy);
gotoxy(3,5+i);
for(q=0;wpad[i][q]!='\0';q++)
{
putchar(wpad[i][q]);
}
posx+=textwidth("W");
CURSOR(posx,posy);
} //LOOP_OF_j_FINISH
if(halt==0)
break;
BCURSOR(posx,posy);
gotoxy(3,5+i+1);
posy+=2*textheight(wpad[i]);
posx=0;
CURSOR(posx,posy);
} //LOOP_OF_i_FINISH
}//WPAD_ACTIVE_FINISH
void ERASE_GRAPH()
{
int poly[8];
poly[0]=getmaxx()-155;
poly[1]=getmaxy()/2-50;
poly[2]=getmaxx()-71;
poly[3]=getmaxy()/2-50;
poly[4]=getmaxx()-71;
poly[5]=getmaxy()/2+205;
poly[6]=getmaxx()-155;
poly[7]=getmaxy()/2+205;
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillpoly(4,poly);
}
void MENU_COL_CONTROL(int i)
{
int col0,col1,col2,col3;
if(i==0)
{
col0=2;col1=15;col2=15;col3=15;
}
if(i==1)
{
col0=15;col1=2;col2=15;col3=15;
}
if(i==2)
{
col0=15;col1=15;col2=2;col3=15;
}
if(i==3)
{
col0=15;col1=15;col2=15;col3=2;
}
setcolor(col0);
rectangle(getmaxx()-70,getmaxy()/2-50,getmaxx()-5,getmaxy()/2-30);
outtextxy(getmaxx()-60,getmaxy()/2-43,"NEW");
setcolor(col1);
rectangle(getmaxx()-70,getmaxy()/2-25,getmaxx()-5,getmaxy()/2-5);
outtextxy(getmaxx()-60,getmaxy()/2-18,"SAVE");
setcolor(col2);
rectangle(getmaxx()-70,getmaxy()/2,getmaxx()-5,getmaxy()/2+20);
outtextxy(getmaxx()-60,getmaxy()/2+7,"EXIT");
setcolor(col3);
rectangle(getmaxx()-70,getmaxy()/2+25,getmaxx()-5,getmaxy()/2+45);
outtextxy(getmaxx()-60,getmaxy()/2+32,"HELP");
}
void MENU_BAR_CONTROL()
{
//MENU_BAR
rectangle(getmaxx()-70,getmaxy()/2-50,getmaxx()-5,getmaxy()/2-30);
rectangle(getmaxx()-70,getmaxy()/2-25,getmaxx()-5,getmaxy()/2-5);
rectangle(getmaxx()-70,getmaxy()/2+20,getmaxx()-5,getmaxy()/2);
rectangle(getmaxx()-70,getmaxy()/2+45,getmaxx()-5,getmaxy()/2+25);
outtextxy(getmaxx()-60,getmaxy()/2-43,"NEW");
outtextxy(getmaxx()-60,getmaxy()/2-18,"SAVE");
outtextxy(getmaxx()-60,getmaxy()/2+7,"EXIT");
outtextxy(getmaxx()-60,getmaxy()/2+32,"HELP");
setcolor(2);
outtextxy(getmaxx()-60,getmaxy()/2-43,"NEW");
rectangle(getmaxx()-70,getmaxy()/2-50,getmaxx()-5,getmaxy()/2-30);
setcolor(15);
int key,i=0,done=0;
do
{ key=getch();
switch(key)
{
case 00:
key = getch();
switch(key)
{
case 72:
if(i==0)
i=3;
else
i--;
MENU_COL_CONTROL(i);
break;
case 80:
if(i==3)
i=0;
else
i++;
MENU_COL_CONTROL(i);
}
break;
case 13:
if(i==0)
{
WPAD_INACTIVE();
ERASE_GRAPH();
setcolor(15);
outtextxy(getmaxx()-60,getmaxy()/2-43,"NEW");
rectangle(getmaxx()-70,getmaxy()/2-50,getmaxx()-5,getmaxy()/2-30);
WPAD_ACTIVE();
setcolor(2);
outtextxy(getmaxx()-60,getmaxy()/2-43,"NEW");
rectangle(getmaxx()-70,getmaxy()/2-50,getmaxx()-5,getmaxy()/2-30);
}
if(i==1)
FILE_SAVING(wpad,cl);
if(i==2)
exit(1);
if(i==3)
{
outtextxy(50,150,"This Text_Editor is being created by ");
outtextxy(50,170,"Vishal Sethia");
}
break; case 9:
done=1;
}
}while(done!=1);
}
void main()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "../bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
setcolor(15);
TITLE_BAR();
WRITING_PAD();
MENU_BAR_CONTROL();
getch();
closegraph();
}