📄 chakri.cpp
字号:
}
fclose(fp);
showmptr();
return 0;
}
load5(int choice)
{
int color,ocolor,x,y,minx,miny,maxx,maxy;
FILE *fp=fopen("eddyop1","r");
switch(choice) {
case 1:minx=95;
miny=70;
maxx=195;
maxy=220;
break;
case 2:minx=215;
miny=70;
maxx=315;
maxy=250;
break;
case 3:minx=335;
miny=70;
maxx=435;
maxy=165;
break;
case 4:minx=124;
miny=125;
maxx=585;
maxy=375;
break;
}
hidemptr();
for(y=miny;y<=maxy;y++)
for(x=minx;x<=maxx;x++) {
fscanf(fp,"%c",&color);
ocolor=color-'a';
putpixel(x,y,ocolor);
}
showmptr();
fclose(fp);
return 0;
}
/* file ,edit ,view options */
void rotate(int xc,int yc,int x,int y,int *x1,int *y1,int t)
{
float t1=t*3.1415928/180;
*x1=xc+(x-xc)*cos(t1)-(y-yc)*sin(t1);
*y1=yc+(x-xc)*sin(t1)+(y-yc)*cos(t1);
}
rotline()
{
int x,y,a,b,butt,x1,y1,i=0,r;
int theta=60;
setfillstyle(1,0);
bar(73,69,636,442);
setcolor(9);
r=150*cos(theta/2*3.1415928/180);
while(butt!=1) {
getmpos(&butt,&a,&b);
rotate(350,240,500,240,&x,&y,i);
rotate(350,240,500,240,&x1,&y1,i+theta);
setcolor(9);
circle(350,240,r);
setcolor(9);
line(x,y,x1,y1);
delay(10);
setcolor(0);
line(x,y,x1,y1);
i++;
i%=360;
}
return 0;
}
_save1(int select[]);
_load1(int select[],int,int);
_load2(int select[]);
_load3(int select2[],int select[]);
disp_rotate(int select[],int ,int,int);
int select2[4]={73,69,636,442};//,bkgrnd;
/**************save functions*******************************/
/* for edit option purposes */
_save1(int select[])
{
int x,y,color,ocolor;
int _WmaxY=select[3];int _WminY=select[1];
int _WminX=select[0];int _WmaxX=select[2];
char fname[]="eddyop";
FILE *fp=fopen(fname,"w");
hidemptr();
ocolor = getpixel(_WminX+2,_WminY+2);
for(y=_WminY;y<=_WmaxY;y++) {
for(x=_WminX;x<=_WmaxX;x++) {
color = getpixel(x,y);
ocolor='a'+color;
fprintf(fp,"%c",ocolor);
}
}
fclose(fp);
showmptr();
return 0;
}
/* for saving the file in the specific name */
_save5(char fnam[])
{
int x,y,color,ocolor;
int _WmaxY=select2[3];int _WminY=select2[1];
int _WminX=select2[0];int _WmaxX=select2[2];
FILE *fp=fopen(fnam,"w");
hidemptr();
ocolor = getpixel(_WminX+2,_WminY+2);
for(y=_WminY;y<=_WmaxY;y++) {
for(x=_WminX;x<=_WmaxX;x++) {
color = getpixel(x,y);
ocolor='a'+color;
fprintf(fp,"%c",ocolor);
}
}
fclose(fp);
showmptr();
return 0;
}
/******** for saving a file dialogue box area ***/
_save4()
{
int x,y,color,ocolor;
int _WmaxY=266;int _WminY=226;
int _WminX=200;int _WmaxX=500;
FILE *fp=fopen("eddyop4","w");
hidemptr();
ocolor = getpixel(_WminX+2,_WminY+2);
for(y=_WminY;y<=_WmaxY;y++) {
for(x=_WminX;x<=_WmaxX;x++) {
color = getpixel(x,y);
ocolor='a'+color;
fprintf(fp,"%c",ocolor);
}
}
fclose(fp);
showmptr();
return 0;
}
/***********load functions**************/
/* load function for translating */
_load1(int select[],int x,int y)
{
char color,ocolor,bkgrnd1;
int x1=x,y1=y;
int diffx=select[2]-select[0];
int diffy=select[3]-select[1];
int _WmaxY=y+diffy;int _WminY=y;
int _WminX=x;int _WmaxX=x+diffx;
FILE *fp=fopen("eddyop","r");
bkgrnd1=bkgrnd;
hidemptr();
for(y=_WminY;y<=_WmaxY;y++)
for(x=_WminX;x<=_WmaxX;x++) {
fscanf(fp,"%c",&color);
ocolor=color-'a';
if(ocolor!=bkgrnd1) {
if((x>73&&x<636)&&(y>69&&y<442))
putpixel(x,y,ocolor);
}
}
showmptr();
fclose(fp);
select[0]=x1;select[1]=y1;
select[2]=_WmaxX;select[3]=_WmaxY;
return 0;
}
/* load for dialogue box */
_load4()
{
char color,ocolor,bkgrnd1;
int x,y;
int _WmaxY=266;int _WminY=226;
int _WminX=200;int _WmaxX=500;
FILE *fp=fopen("eddyop4","r");
bkgrnd1=bkgrnd;
hidemptr();
for(y=_WminY;y<=_WmaxY;y++)
for(x=_WminX;x<=_WmaxX;x++) {
fscanf(fp,"%c",&color);
ocolor=color-'a';
putpixel(x,y,ocolor);
}
showmptr();
fclose(fp);
return 0;
}
/* load for scaling */
_load2(int select[])
{
int x,y,x1,y1;
char color,ocolor,bkgrnd1=bkgrnd;
int _WmaxY=select[3];int _WminY=select[1];
int _WminX=select[0];int _WmaxX=select[2];
FILE *fp=fopen("eddyop","r");
hidemptr();
for(y=_WminY;y<=_WmaxY;y++) {
for(x=_WminX;x<=_WmaxX;x++) {
fscanf(fp,"%c",&color);
ocolor=color-'a';
if(ocolor!=bkgrnd1) {
x1=x*2+select[0]*(1-2);
y1=y*2+select[1]*(1-2);
if((x1>73&&x1<636)&&(y1>69&&y1<442))
putpixel(x1,y1,ocolor);
}
}
}
showmptr();
fclose(fp);
return 0;
}
disp_rotate(int select[],int x,int y,int w)
{
#define ex(a,b,p,q,t) (a+((p-(a))*cos(t))-((q-(b))*sin(t)))
#define ey(a,b,p,q,t) (b+((p-(a))*sin(t))+((q-(b))*cos(t)))
int i,j,k=0,p[10][3],diffx,diffy;
float angle;
int butt,x1,x2,x3,x4,y1,y2,y3,y4;
float sx,sy;
diffx=(x-select[0]);
diffy=(y-select[1]);
x1=select[0];y1=select[1];
x2=select[2];y2=select[3];
//(w*(-3.14))/180;
angle=(float(w*(-3.14)))/float(180.00);
for(i=y1+1;i<y2;++i)
for(j=x1+1;j<x2;++j) {
p[k][1]=ex(x1,y2,j,i,angle);
p[k][2]=ey(x1,y2,j,i,angle);
p[k][3]=getpixel(j,i);
if(p[k][3]!=bkgrnd) {
if((j>73&&j<636)&&(i>69&&i<442))
putpixel(j,i,bkgrnd);
if(((p[k][1]+diffx)>73&&(p[k][1]+diffx)<636)
&&((p[k][2]+diffy)>69&&(p[k][2]+diffy)<442))
putpixel(p[k][1]+diffx,p[k][2]+diffy,p[k][3]);}
}
return 0;
}
/* load for clipping */
_load3(int select2[],int select[])
{
int color,ocolor,x,y;
int _WmaxY=select2[3];int _WminY=select2[1];
int _WminX=select2[0];int _WmaxX=select2[2];
FILE *fp=fopen("eddyop","r");
hidemptr();
for(y=_WminY;y<=_WmaxY;y++)
for(x=_WminX;x<=_WmaxX;x++) {
fscanf(fp,"%c",&color);
ocolor=color-'a';
if((x>select[0]&&x<select[2])&&(y>select[1]&&y<select[3]))
putpixel(x,y,ocolor);
}
showmptr();
fclose(fp);
return 0;
}
/* load for loading file */
int _load5(char fnam[])
{
int color,ocolor,x,y,oo;
int _WmaxY=select2[3];int _WminY=select2[1];
int _WminX=select2[0];int _WmaxX=select2[2];
FILE *fp=fopen(fnam,"r");
hidemptr();
if(fp==NULL) {
gotoxy(46,16);
printf("FILE NOT FOUND !");
getch();
return 1;
}
else {
for(y=_WminY;y<=_WmaxY;y++)
for(x=_WminX;x<=_WmaxX;x++) {
fscanf(fp,"%c",&color);
ocolor=color-'a';
putpixel(x,y,ocolor);
}
}
showmptr();
fclose(fp);
return 0;
}
/*********************************************/
fileop(int menuop)
{
int x,y,butt=0,i,oo=0;
char ch,fnam[15]="Noname.bmp";
restrictmptr(73,69,636,442);
while(menuop==1) {
getmpos(&butt,&x,&y);
if((x>115&&x<170)&&(y>75&&y<100)&&(butt&1==1)) {
hidemptr();
setcolor(8);
outtextxy(125,72,"New");
menuop=0;
setfillstyle(1,15);
fillellipse(110,87,4,4);
delay(300);
setfillstyle(1,15);
bar(73,69,636,441);
setcolor(LIGHTGRAY);
rectangle(95,45,134,63);
showmptr();
butt=0;
return 0;
}
else if((x>115&&x<170)&&(y>115&y<135)&&(butt&1==1)) {
hidemptr();
setcolor(8);
outtextxy(125,110,"Load");
setfillstyle(1,15);
fillellipse(110,124,4,4);
delay(300);
cleanup();
_save4();
setfillstyle(1,1);
bar(200,226,500,266);
outtextxy(215,231,"Enter file name:");
setcolor(7);
for(i=2;i<6;i+=2)
rectangle(202+i,228+i,498-i,264-i);
if((ch=getch())==27) {
_load4();
menuop=0;butt=0;
showmptr();
return 0;
}
else {
gotoxy(48,16);
scanf("%s",fnam);
}
gotoxy(48,16);
printf(" ");
gotoxy(48,16);
printf("PROCESSING ...");
delay(1000);
oo=_load5(fnam);
if(oo) {
_load4();
showmptr();
}
showmptr();
menuop=0;
butt=0;
return 0;
}
else if((x>115&&x<170)&&(y>150&&y<175)&&(butt&1==1)) {
hidemptr();
setcolor(11);
outtextxy(125,147,"Save");
setfillstyle(1,15);
fillellipse(110,161,4,4);
delay(300);
cleanup();
_save4();
setfillstyle(1,0);
bar(200,226,500,266);
outtextxy(215,231,"Enter file name:");
setcolor(7);
for(i=2;i<6;i+=2)
rectangle(202+i,228+i,498-i,264-i);
if((ch=getch())==27) {
_load4();
menuop=0;
butt=0;
showmptr();
return 0;
}
else {
gotoxy(48,16);
scanf("%s",fnam);
}
gotoxy(48,16);
printf(" ");
gotoxy(48,16);
printf("SAVING ... ");
delay(1000);
_load4();
_save5(fnam);
oo=_load5(fnam);
showmptr();
menuop=0;
butt=0;
return 0;
}
else if((x>115&&x<170)&&(y>190&&y<210)&&(butt&1==1)) {
hidemptr();
setcolor(8);
outtextxy(125,184,"Exit");
menuop=0;
setfillstyle(1,15);
fillellipse(110,198,4,4);
delay(300);
exit(1);
}
else {
if(butt==1) {
butt=0;
menuop=0;
cleanup();
return 0;
}
}
}
return 0;
}
/****************************************************/
editop(int menuop,int cbut,int bkgrnd)
{
int x,y,butt=0,i,j;
restrictmptr(73,69,636,442);
while(menuop==2) {
getmpos(&butt,&x,&y);
/* translation */
if((x>231&&x<311)&&(y>225&&y<246)&&(butt==1)) {
hidemptr();
setfillstyle(1,15);
fillellipse(225,237,4,4);
settextstyle(4,0,2);
setcolor(DARKGRAY);
outtextxy(235,222,"Translate");
delay(300);
cleanup();
showmptr();
getmpos(&butt,&x,&y);
hope(9,cbut,0);
_save1(select);
butt=0;
while(butt!=1)
getmpos(&butt,&x,&y);
setfillstyle(1,bkgrnd);
if(select[3]>441)
select[3]=441;
if(select[2]>635)
select[2]=635;
if(select[1]<70)
select[1]=70;
if(select[0]<74)
select[0]=74;
bar(select[0]-1,select[1]-1,select[2]+1,select[3]+1);
_load1(select,x,y);
hidemptr();
showmptr();
menuop=0;
butt=0;
return 0;
}
/* scaling */
if((x>231&&x<291)&&(y>165&&y<188)&&(butt==1)) {
hidemptr();
setfillstyle(1,15);
fillellipse(225,176,4,4);
settextstyle(4,0,2);
setcolor(DARKGRAY);
outtextxy(235,162,"Scale");
delay(300);
cleanup();
showmptr();
getmpos(&butt,&x,&y);
hope(9,cbut,0);
_save1(select);
butt=0;
while(butt!=1)
getmpos(&butt,&x,&y);
setfillstyle(1,bkgrnd);
if(select[3]>441)
select[3]=441;
if(select[2]>635)
select[2]=635;
if(select[1]<70)
select[1]=70;
if(select[0]<74)
select[0]=74;
bar(select[0]-1,select[1]-1,select[2]+1,select[3]+1);
_load2(select);
hidemptr();
showmptr();
menuop=0;
butt=0;
return 0;
}
/* rotation */
int w;
char ch;
if((x>231&&x<296)&&(y>195&&y<217)&&(butt==1)) {
hidemptr();
setfillstyle(1,15);
fillellipse(225,207,4,4);
settextstyle(4,0,2);
setcolor(DARKGRAY);
outtextxy(235,192,"Rotate");
delay(1300);
cleanup();
showmptr();
getmpos(&butt,&x,&y);
hope(9,cbut,0);
restrictmptr(73,69,636,442);
while(butt!=1)
getmpos(&butt,&x,&y);
restrictmptr(1,39,638,478);
hidemptr();
rectangle(select[0]-1,select[1]-1,select[2]+1,select[3]+1);
setfillstyle(1,0);
bar(200,226,526,266);
for(i=2;i<6;i+=2)
rectangle(202+i,228+i,528-i,264-i);
outtextxy(215,231,"Enter the angle of rotation :");
setcolor(7);
gotoxy(58,16);
scanf("%d",&w);
// setcolor(WHITE);
// bar(200,200,500,300);
// gotoxy(58,16);
// printf(" ");
// gotoxy(58,16);
// printf("DISPLAYING ...");
// delay(1000);
// cleanup();
//setfillstyle(1,bkgrnd);
//setcolor(bkgrnd);
setfillstyle(1,15);
bar(200,226,526,266);
// for(i=2;i<6;i+=2)
// rectangle(202+i,228+i,528-i,264-i);
disp_rotate(select,x,y,w);
showmptr();
menuop=0;
butt=0;
return 0;
}
/******** clipping **********/
if((x>231&&x<280)&&(y>78&&y<90)&&(butt==1)) {
hidemptr();
setfillstyle(1,15);
fillellipse(225,86,4,4);
settextstyle(4,0,2);
setcolor(DARKGRAY);
outtextxy(235,72,"Clip");
delay(300);
cleanup();
_save1(select2);
showmptr();
getmpos(&butt,&x,&y);
hope(9,cbut,0);
butt=0;
while(butt!=1)
getmpos(&butt,&x,&y);
setfillstyle(1,bkgrnd);
bar(73,69,636,442);
setlinestyle(DOTTED_LINE,USERBIT_LINE,1);
rectangle(select[0]-1,select[1]-1,select[2]+1,select[3]+1);
hidemptr();
_load3(select2,select);
butt=0;
restrictmptr(73,69,636,442);
while(butt!=1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -