www.pudn.com > xplhx.rar > SUCCESS.C, change:2003-05-09,size:22938b
#include <stdlib.h>
#include <dos.h>
#include <stdio.h>
#include <math.h>
#include <graphics.h>
#define LINE 1
#define FRAME 2
#define CUT 3
#define REFRESH 4
#define NEW 5
#define EXIT 6
#define TURE 1
#define FAUSE 0
#define LEFT 1
#define RIGHT 2
#define BOTTOM 4
#define TOP 8
typedef struct a
{ int x,y,color;
struct a *next;
}linebody;
typedef struct b
{ int x1,y1,x2,y2;
struct b *next;
}linepoint;
struct tool
{ int x,y,dx,dy;
void *imageback;
void *imagefront;
}toolbar;
struct kuang
{ int xl,yt,xr,yb;
}kuangpoint;
linepoint pointhead;
linebody kuangbody;
drawbar(int x,int y)
{
int linema;
int i,mx,my;
setfillstyle(1,7);
/*drawboard*/
bar(x,y,x+toolbar.dx,y+toolbar.dy);
setcolor(15);
line(x,y,x,y+toolbar.dy);
line(x,y,x+toolbar.dx,y);
setcolor(16);
line(x+toolbar.dx,y,x+toolbar.dx,y+toolbar.dy);
line(x,y+toolbar.dy,x+toolbar.dx,y+toolbar.dy);
/*drawbottom*/
for(i=1;i=6;i++)
{
linema=i*30+x+1;
setcolor(15);
line(linema,y+2,linema+28,y+2);
line(linema,y+2,linema,y+29);
setcolor(0);
line(linema,y+29,linema+28,y+29);
line(linema+28,y+2,linema+28,y+29);
}
/* drawshare*/
setcolor(15);
moveto(x+3,y+2);
lineto(x+2,y+2);
lineto(x+2,y+29);
setcolor(0);
moveto(x+3,y+3);
lineto(x+3,y+29);
lineto(x+2,y+29);
setcolor(0);
line(x+27,y+3,x+27,y+28);
setcolor(15);
line(x+28,y+3,x+28,y+28);
/*move*/
setcolor(15);
moveto(x+14,y+14);
lineto(x+9,y+14);lineto(x+9,y+10);lineto(x+5,y+15);lineto(x+9,y+20);
lineto(x+9,y+16);lineto(x+14,y+16);
lineto(x+14,y+21);lineto(x+10,y+21);lineto(x+15,y+25);lineto(x+20,y+21);
lineto(x+16,y+21);lineto(x+16,y+16);
lineto(x+21,y+16);lineto(x+21,y+20);lineto(x+25,y+15);lineto(x+21,y+10);
lineto(x+21,y+14);lineto(x+16,y+14);
lineto(x+16,y+9);lineto(x+20,y+9);lineto(x+15,y+5);lineto(x+10,y+9);
lineto(x+14,y+9);lineto(x+14,y+14);
setfillstyle(1,0);
floodfill(x+15,y+15,15);
/*drawlines*/
setcolor(9);
setlinestyle(1,1,1);
line(x+35,y+6,x+53,y+8);line(x+35,y+6,x+53,y+12);line(x+35,y+6,x+46,y+20);line(x+35,y+6,x+44,y+23);
setlinestyle(0,0,0);
line(x+35,y+6,x+49,y+16);
setcolor(0);
mx=x+49;my=y+15;
moveto(mx,my);lineto(mx,my+9);lineto(mx+2,my+7);lineto(mx+5,my+12);
lineto(mx+7,my+11);lineto(mx+4,my+6);lineto(mx+7,my+6);lineto(mx,my);
setfillstyle(1,15);
floodfill(mx+1,my+4,0);
/*drawrectangle*/
setcolor(15);
rectangle(x+65,y+6,x+85,y+24);
setcolor(0);
mx=x+65;my=y+6;
moveto(mx,my);lineto(mx,my+9);lineto(mx+2,my+7);lineto(mx+5,my+12);
lineto(mx+7,my+11);lineto(mx+4,my+6);lineto(mx+7,my+6);lineto(mx,my);
setfillstyle(1,15);
floodfill(mx+1,my+4,0);
/*cut*/
setcolor(14);
moveto(x+101,y+6);
lineto(x+104,y+16);
lineto(x+107,y+6);
arc(x+113,y+8,170,235,12);
arc(x+95,y+8,311,374,12);
setcolor(3);
circle(x+104,y+16,1);
setfillstyle(1,3);
floodfill(x+104,y+16,3);
setcolor(1);
ellipse(x+102,y+22,0,360,1,2);
ellipse(x+107,y+22,0,360,1,2);
setcolor(9);
ellipse(x+102,y+22,0,360,1,3);
ellipse(x+107,y+22,0,360,1,3);
/*refresh*/
setcolor(1);
moveto(x+143,y+10);lineto(x+143,y+25);lineto(x+126,y+25);lineto(x+126,y+5);lineto(x+137,y+5);
arc(x+138,y+10,0,90,5);
setfillstyle(1,15);
floodfill(x+138,y+10,1);
moveto(x+139,y+5);
lineto(x+139,y+9);lineto(x+143,y+9);
setcolor(2);
arc(x+134,y+15,40,150,6);
arc(x+133,y+17,40,120,6);
moveto(x+138,y+11);lineto(x+139,y+8);lineto(x+141,y+16);lineto(x+134,y+14);lineto(x+138,y+13);
setfillstyle(1,2);
floodfill(x+139,y+12,2);
arc(x+136,y+16,220,310,6);
arc(x+137,y+14,220,310,6);
moveto(x+132,y+20);lineto(x+131,y+23);lineto(x+129,y+15);lineto(x+136,y+17);lineto(x+133,y+18);
setfillstyle(1,2);
floodfill(x+132,y+19,2);
/*new*/
setcolor(1);
moveto(x+172,y+9);lineto(x+172,y+24);lineto(x+157,y+24);lineto(x+157,y+6);lineto(x+167,y+6);
arc(x+167,y+11,0,90,5);
setfillstyle(1,15);
floodfill(x+168,y+10,1);
moveto(x+168,y+6);
lineto(x+168,y+10);lineto(x+172,y+10);
/*door*/
setcolor(15);
rectangle(x+190,y+5,x+202,y+22);
setfillstyle(1,0);
floodfill(x+191,y+9,15);
setcolor(6);
moveto(x+202,y+5);lineto(x+195,y+9);lineto(x+195,y+26);lineto(x+202,y+22);lineto(x+202,y+5);
setfillstyle(1,6);
floodfill(x+197,y+9,6);
setcolor(12);
circle(x+197,y+17,1);
setfillstyle(1,12);
floodfill(x+197,y+17,12);
setcolor(10);
moveto(x+183,y+12);lineto(x+189,y+12);lineto(x+189,y+9);lineto(x+193,y+14);
lineto(x+189,y+19);lineto(x+189,y+16);lineto(x+183,y+16);lineto(x+183,y+12);
setfillstyle(1,2);
floodfill(x+186,y+13,10);
}
pressed(int x,int y,int pressed)
{
if(pressed)
setcolor(0);
else
setcolor(15);
moveto(x+28,y);
lineto(x,y);
lineto(x,y+27);
if(pressed)
setcolor(15);
else
setcolor(0);
moveto(x+28,y);
lineto(x+28,y+27);
lineto(x,y+27);
}
int pressedbutton()
{ union REGS in,out;
int mx,my,button=0;
in.x.ax=3;
int86(0x33,&in,&out);
mx=out.x.cx;
my=out.x.dx;
if((mx>toolbar.x+31&&mx<toolbar.x+59)&&(my>toolbar.y+2&&my<toolbar.y+29))
{ pressed(toolbar.x+31,toolbar.y+2,1);
button=LINE;
}
if((mx>toolbar.x+61&&mx<toolbar.x+89)&&(my>toolbar.y+2&&my<toolbar.y+29))
{ pressed(toolbar.x+61,toolbar.y+2,1);
button=FRAME;
}
if((mx>toolbar.x+91&&mx<toolbar.x+119)&&(my>toolbar.y+2&&my<toolbar.y+29))
{ pressed(toolbar.x+91,toolbar.y+2,1);
button=CUT;
}
if((mx>toolbar.x+121&&mx<toolbar.x+149)&&(my>toolbar.y+2&&my<toolbar.y+29))
{ pressed(toolbar.x+121,toolbar.y+2,1);
button=REFRESH;
}
if((mx>toolbar.x+151&&mx<toolbar.x+179)&&(my>toolbar.y+2&&my<toolbar.y+29))
{ pressed(toolbar.x+151,toolbar.y+2,1);
button=NEW;
}
if((mx>toolbar.x+181&&mx<toolbar.x+209)&&(my>toolbar.y+2&&my<toolbar.y+29))
{ pressed(toolbar.x+181,toolbar.y+2,1);
button=EXIT;
}
switch(button)
{ case LINE:while(out.x.bx==1&&(out.x.cx>toolbar.x+31&&out.x.cx<toolbar.x+59)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
int86(0x33,&in,&out);
if(out.x.bx==0&&(out.x.cx>toolbar.x+31&&out.x.cx<toolbar.x+59)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+31,toolbar.y+2,0);
return LINE;
}
if(out.x.bx==1&&!(out.x.cx>toolbar.x+31&&out.x.cx<toolbar.x+59&&out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+31,toolbar.y+2,0);
return FAUSE;
}
break;
case FRAME:while(out.x.bx==1&&(out.x.cx>toolbar.x+61&&out.x.cx<toolbar.x+89)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
int86(0x33,&in,&out);
if(out.x.bx==0&&(out.x.cx>toolbar.x+61&&out.x.cx<toolbar.x+89)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+61,toolbar.y+2,0);
return FRAME;
}
if(out.x.bx==1&&!(out.x.cx>toolbar.x+61&&out.x.cx<toolbar.x+89&&out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+61,toolbar.y+2,0);
return FAUSE;
}
break;
case CUT:while(out.x.bx==1&&(out.x.cx>toolbar.x+91&&out.x.cx<toolbar.x+119)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
int86(0x33,&in,&out);
if(out.x.bx==0&&(out.x.cx>toolbar.x+91&&out.x.cx<toolbar.x+119)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+91,toolbar.y+2,0);
return CUT;
}
if(out.x.bx==1&&!(out.x.cx>toolbar.x+91&&out.x.cx<toolbar.x+119&&out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+91,toolbar.y+2,0);
return FAUSE;
}
break;
case REFRESH:while(out.x.bx==1&&(out.x.cx>toolbar.x+121&&out.x.cx<toolbar.x+149)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
int86(0x33,&in,&out);
if(out.x.bx==0&&(out.x.cx>toolbar.x+121&&out.x.cx<toolbar.x+149)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+121,toolbar.y+2,0);
return REFRESH;
}
if(out.x.bx==1&&!(out.x.cx>toolbar.x+121&&out.x.cx<toolbar.x+149&&out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+121,toolbar.y+2,0);
return FAUSE;
}
break;
case NEW:while(out.x.bx==1&&(out.x.cx>toolbar.x+151&&out.x.cx<toolbar.x+179)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
int86(0x33,&in,&out);
if(out.x.bx==0&&(out.x.cx>toolbar.x+151&&out.x.cx<toolbar.x+179)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+151,toolbar.y+2,0);
return NEW;
}
if(out.x.bx==1&&!(out.x.cx>toolbar.x+151&&out.x.cx<toolbar.x+179&&out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+151,toolbar.y+2,0);
return FAUSE;
}
break;
case EXIT:while(out.x.bx==1&&(out.x.cx>toolbar.x+181&&out.x.cx<toolbar.x+209)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
int86(0x33,&in,&out);
if(out.x.bx==0&&(out.x.cx>toolbar.x+181&&out.x.cx<toolbar.x+209)&&(out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+181,toolbar.y+2,0);
return EXIT;
}
if(out.x.bx==1&&!(out.x.cx>toolbar.x+181&&out.x.cx<toolbar.x+209&&out.x.dx>toolbar.y+2&&out.x.dx<toolbar.y+29))
{
pressed(toolbar.x+181,toolbar.y+2,0);
return FAUSE;
}
break;
default:return FAUSE;
}
}
saveimage(int x1,int y1,int x2,int y2,linebody *buf)
{
float x=x1,y=y1,xk,yk;
linebody *p,*q;
p=buf;
if(x1!=x2&&y1!=y2)
{ yk=1.0*(y2-y1)/(x2-x1);
xk=1.0*(x2-x1)/(y2-y1);
if(fabs(yk)<1.0)
{ if(x2>x1)
for(x=x1;x=x2;x++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=(int)(y+0.5);
q->color=getpixel(x,(int)(y+0.5));
p->next=q;
p=q;
p->next=NULL;
y+=yk;
}
else
for(x=x1;x>=x2;x--)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=(int)(y+0.5);
q->color=getpixel(x,(int)(y+0.5));
p->next=q;
p=q;
p->next=NULL;
y-=yk;
}
}
else
{ if(y2>y1)
for(y=y1;y=y2;y++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=(int)(x+0.5);
q->y=y;
q->color=getpixel((int)(x+0.5),y);
p->next=q;
p=q;
p->next=NULL;
x+=xk;
}
else
for(y=y1;y>=y2;y--)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=(int)(x+0.5);
q->y=y;
q->color=getpixel((int)(x+0.5),y);
p->next=q;
p=q;
p->next=NULL;
x-=xk;
}
}
}
else if(x1==x2&&y1!=y2)
{ if(y2>y1)
for(y=y1;y=y2;y++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x1;
q->y=y;
q->color=getpixel(x1,y);
p->next=q;
p=q;
p->next=NULL;
}
else
for(y=y1;y>=y2;y--)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x1;
q->y=y;
q->color=getpixel(x1,y);
p->next=q;
p=q;
p->next=NULL;
}
}
else if(y1==y2&&x1!=x2)
{ if(x2>x1)
for(x=x1;x=x2;x++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=y1;
q->color=getpixel(x,y1);
p->next=q;
p=q;
p->next=NULL;
}
else
for(x=x1;x>=x2;x--)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=y1;
q->color=getpixel(x,y1);
p->next=q;
p=q;
p->next=NULL;
}
}
return;
}
outimage(linebody *buf)
{ linebody *p=buf->next;
while(p!=NULL)
{ putpixel(p->x,p->y,p->color);
p=p->next;
}
}
outline(linebody *buf,int linecolor)
{ linebody *p=buf->next;
while(p!=NULL)
{ putpixel(p->x,p->y,linecolor);
p=p->next;
}
}
freebuf(linebody *buf)
{ linebody *p=buf->next,*q;
while(p!=NULL)
{ q=p;
p=p->next;
free(q);
}
buf->next=NULL;
}
savekuangimage(int x1,int y1,int x2,int y2,linebody *buf)
{ int x,y;
linebody *p,*q;
p=buf;
if(x2>x1)
for(x=x1;x=x2;x++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=y1;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
else
for(x=x2;x=x1;x++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=y1;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
if(x2>x1)
for(x=x1;x=x2;x++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=y2;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
else
for(x=x2;x=x1;x++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x;
q->y=y2;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
if(y2>y1)
for(y=y1;y=y2;y++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x1;
q->y=y;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
else for(y=y2;y=y1;y++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x1;
q->y=y;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
if(y2>y1)
for(y=y1;y=y2;y++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x2;
q->y=y;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
else for(y=y2;y=y1;y++)
{ q=(linebody *)malloc(sizeof(linebody));
q->x=x2;
q->y=y;
q->color=getpixel(q->x,q->y);
p->next=q;
p=q;
p->next=NULL;
}
}
outkuangimage(linebody *buf)
{ linebody *p=buf->next;
while(p!=NULL)
{ putpixel(p->x,p->y,p->color);
p=p->next;}
}
outkuang(linebody *buf,int color)
{
linebody *p=buf->next;
while(p!=NULL)
{ putpixel(p->x,p->y,color);
p=p->next;}
}
mousexy()
{ union REGS in,out;
in.x.ax=3;
int86(0x33,&in,&out);
window(2,3,20,3);
printf("mouse:x=%d,y=%d ",out.x.cx,out.x.dx);
}
movetoolbar()
{ union REGS in,out;
in.x.ax=4;
in.x.cx=toolbar.x+15;
in.x.dx=toolbar.y+15;
int86(0x33,&in,&out);
in.x.ax=7;
in.x.cx=15;in.x.dx=443;
int86(0x33,&in,&out);
in.x.ax=8;
in.x.cx=15;in.x.dx=464;
int86(0x33,&in,&out);
in.x.ax=2;
in.x.bx=1;
int86(0x33,&in,&out);
in.x.ax=3;
while(out.x.bx==1)
{ int86(0x33,&in,&out);
mousexy();
if(toolbar.x!=out.x.cx-15||toolbar.y!=out.x.dx-15)
{ putimage(toolbar.x,toolbar.y,toolbar.imageback,0);
toolbar.x=out.x.cx-15;
toolbar.y=out.x.dx-15;
getimage(toolbar.x,toolbar.y,toolbar.x+toolbar.dx,toolbar.y+toolbar.dy,toolbar.imageback);
putimage(toolbar.x,toolbar.y,toolbar.imagefront,0);
}
}
mousedisplay();
}
drawline(char *key,int linecolor)
{ union REGS in,out;
linebody *buf;
linepoint *q,*p=&pointhead;
int flag,x1,x2,y1,y2;
buf=(linebody *)malloc(sizeof(linebody));
buf->next=NULL;
in.x.ax=3;
int86(0x33,&in,&out);
while(toupper(*key)!='F'&&toupper(*key)!='N'&&toupper(*key)!='C'&&!(out.x.bx==1&&(out.x.cx>toolbar.x&&out.x.cx<toolbar.x+211)&&(out.x.dx>toolbar.y&&out.x.dx<toolbar.y+31)))
{ *key=NULL;
if(kbhit())*key=getch();
if(*key==27){closegraph();exit(0);}
if(toupper(*key)=='R')refresh();
mousexy();
if(out.x.bx==1)
{ flag=1;
x1=out.x.cx;
y1=out.x.dx;
x2=x1;
y2=y1;
in.x.ax=2;
in.x.bx=1;
int86(0x33,&in,&out);
in.x.ax=3;
while(out.x.bx==1)
{ int86(0x33,&in,&out);
mousexy();
if(x2!=out.x.cx||y2!=out.x.dx)
{ outimage(buf);
freebuf(buf);
x2=out.x.cx;
y2=out.x.dx;
saveimage(x1,y1,x2,y2,buf);
outline(buf,linecolor);
}
if(out.x.bx==2||out.x.bx==3||out.x.bx==4){flag=0;break;}
}
if(flag==0)outimage(buf);
freebuf(buf);
if(!(x1==x2&&y1==y2)&&flag==1)
{ while(p->next!=NULL)p=p->next;
q=(linepoint *)malloc(sizeof(linepoint));
q->x1=x1;q->y1=y1;
q->x2=x2;q->y2=y2;
p->next=q;p=q;p->next=NULL;
}
mousedisplay();
} /*if(left button pressed*/
int86(0x33,&in,&out);
} /*while(not in toolbar)*/
} /*if(button==LINE)*/
drawframe(char *key,int *firstflag,int kuangcolor)
{union REGS in,out;
struct kuang *kp;
int flag,x1,y1,x2,y2;
linebody *kuangbuf;
kuangbuf=&kuangbody;
kp=&kuangpoint;
in.x.ax=3;
int86(0x33,&in,&out);
while(toupper(*key)!='L'&&toupper(*key)!='N'&&toupper(*key)!='C'&&!(out.x.bx==1&&(out.x.cx>toolbar.x&&out.x.cx<toolbar.x+211)&&(out.x.dx>toolbar.y&&out.x.dx<toolbar.y+31)))
{ *key=NULL;
if(kbhit())*key=getch();
if(*key==27)
{closegraph();exit(0);}
if(toupper(*key)=='R')
refresh();
mousexy();
if(out.x.bx==1)
{ flag=1;
if(*firstflag==0)*firstflag=1;
else {outkuangimage(kuangbuf);freebuf(kuangbuf);refresh();}
x1=out.x.cx;
y1=out.x.dx;
x2=x1;
y2=y1;
in.x.ax=2;
in.x.bx=1;
int86(0x33,&in,&out);
in.x.ax=3;
int86(0x33,&in,&out);
while(out.x.bx==1)
{ int86(0x33,&in,&out);
mousexy();
if(x2!=out.x.cx||y2!=out.x.dx)
{
outkuangimage(kuangbuf);
freebuf(kuangbuf);
x2=out.x.cx;
y2=out.x.dx;
if(x1!=x2&&y1!=y2)savekuangimage(x1,y1,x2,y2,kuangbuf);
outkuang(kuangbuf,kuangcolor);
}
if(out.x.bx==2||out.x.bx==3||out.x.bx==4){flag=0;break;}
}
if(flag==0){outkuangimage(kuangbuf);freebuf(kuangbuf);}
else if(!(x1==x2&&y1==y2))
{ if(x1<x2)
{ kp->xl=x1;kp->xr=x2;}
else
{ kp->xl=x2;kp->xr=x1;}
if(y1<y2)
{ kp->yt=y1;kp->yb=y2;}
else
{ kp->yt=y2;kp->yb=y1;}
}
mousedisplay();
} /*if(leftbutton pressed)*/
int86(0x33,&in,&out);
} /*while(not in toolbar)*/
} /*if(button==FRAME*/
mousedisplay()
{ int mousex,mousey;
union REGS in,out;
in.x.ax=3;
int86(0x33,&in,&out);
mousex=out.x.cx;
mousey=out.x.dx;
in.x.ax=0;
int86(0x33,&in,&out);
in.x.ax=1;
int86(0x33,&in,&out);
in.x.ax=4;
in.x.cx=mousex;in.x.dx=mousey;
int86(0x33,&in,&out);
}
refresh()
{ linepoint *p=(&pointhead)->next;
int n=0;
cleardevice();
setcolor(15);
rectangle(0,0,639,479);
while(p!=NULL)
{ line(p->x1,p->y1,p->x2,p->y2);
p=p->next;
n++;
}
outkuang(&kuangbody,9);
window(2,2,45,2);
printf("framepoints:xl=%d,yt=%d,xr=%d,yb=%d",kuangpoint.xl,kuangpoint.yt,kuangpoint.xr,kuangpoint.yb);
mousexy();
window(2,4,15,4);
printf("linesnum:%d ",n);
putimage(toolbar.x,toolbar.y,toolbar.imagefront,0);
mousedisplay();
}
delpoint(linepoint *p)
{ linepoint *q=&pointhead;
while(q->next!=p&&q!=NULL)q=q->next;
if(q!=NULL)
{ q->next=p->next;
free(p);
}
}
encode(int x,int y,int *code)
{
int c;
c=0;
if(x<kuangpoint.xl)c=c|LEFT;
else if(x>kuangpoint.xr)c=c|RIGHT;
if(y<kuangpoint.yt)c=c|TOP;
else if(y>kuangpoint.yb)c=c|BOTTOM;
*code=c;
return;
}
scanlines(linepoint *p)
{ int code1=0,code2=0,code=0;
int x,y;
encode(p->x1,p->y1,&code1);
encode(p->x2,p->y2,&code2);
while(code1!=0||code2!=0)
{
if((code1&code2)!=0)
{ delpoint(p);
return;
}
code=code1;
if(code1==0)code=code2;
if((TOP&code)!=0)
{ y=kuangpoint.yt;
x=p->x1+1.0*(p->x2-p->x1)*(kuangpoint.yt-p->y1)/(p->y2-p->y1);
}
else if((BOTTOM&code)!=0)
{ y=kuangpoint.yb;
x=p->x1+1.0*(p->x2-p->x1)*(kuangpoint.yb-p->y1)/(p->y2-p->y1);
}
else if((RIGHT&code)!=0)
{ x=kuangpoint.xr;
y=p->y1+1.0*(p->y2-p->y1)*(kuangpoint.xr-p->x1)/(p->x2-p->x1);
}
else if((LEFT&code)!=0)
{ x=kuangpoint.xl;
y=p->y1+1.0*(p->y2-p->y1)*(kuangpoint.xl-p->x1)/(p->x2-p->x1);
}
if(code==code1)
{p->x1=x;p->y1=y; encode(x,y,&code1);}
else
{p->x2=x;p->y2=y; encode(x,y,&code2);}
}
}
cut()
{ linepoint *p=(&pointhead)->next;
while(p!=NULL)
{
scanlines(p);
p=p->next;
}
}
new()
{ linepoint *q,*p=(&pointhead)->next;
linebody *kuangbuf;
kuangbuf=&kuangbody;
freebuf(kuangbuf);
while(p!=NULL)
{
q=p;
p=p->next;
free(q);
}
(&pointhead)->next=NULL;
kuangpoint.xl=0;kuangpoint.yt=0;kuangpoint.xr=639;kuangpoint.yb=479;
refresh();
}
initboard()
{ union REGS in,out;
int gd=0,gm=1;
kuangbody.next=NULL;
pointhead.next=NULL;
toolbar.x=405;toolbar.y=20;toolbar.dx=211;toolbar.dy=31;
kuangpoint.xl=0;kuangpoint.yt=0;kuangpoint.xr=639;kuangpoint.yb=479;
initgraph(&gd,&gm,"");
setbkcolor(1);
setcolor(15);
rectangle(0,0,639,479);
toolbar.imageback=(void *)malloc(imagesize(toolbar.x,toolbar.y,toolbar.x+toolbar.dx,toolbar.y+toolbar.dy));
toolbar.imagefront=(void *)malloc(imagesize(toolbar.x,toolbar.y,toolbar.x+toolbar.dx,toolbar.y+toolbar.dy));
getimage(toolbar.x,toolbar.y,toolbar.x+toolbar.dx,toolbar.y+toolbar.dy,toolbar.imageback);
drawbar(toolbar.x,toolbar.y);
getimage(toolbar.x,toolbar.y,toolbar.x+toolbar.dx,toolbar.y+toolbar.dy,toolbar.imagefront);
refresh();
in.x.ax=0;
int86(0x33,&in,&out);
in.x.ax=1;
int86(0x33,&in,&out);
}
main()
{ union REGS in,out;
int x1,y1,x2,y2,linecolor=15;
int flag,firstflag=0,kuangcolor=9,button=0;
char key=NULL;
initboard();
in.x.ax=3;
while(1)
{ button=0;
in.x.ax=3;
int86(0x33,&in,&out);
if(out.x.bx==1&&(out.x.cx>toolbar.x+31&&out.x.cx<toolbar.x+211)&&(out.x.dx>toolbar.y&&out.x.dx<toolbar.y+31))
button=pressedbutton();
key=NULL;
if(kbhit())key=getch();
mousexy();
if(button==EXIT||(key==27))
{ closegraph();exit(0);}
if(button==REFRESH||toupper(key)=='R')
refresh();
if(out.x.bx==1&&out.x.cx>toolbar.x+2&&out.x.cx=toolbar.x+27&&out.x.dx>toolbar.y+3&&out.x.dx<toolbar.y+27)
{ movetoolbar();
refresh();
}
DrawFrame:
if(button==FRAME||toupper(key)=='F')
{ drawframe(&key,&firstflag,kuangcolor);
if(toupper(key)=='L')goto DrawLine;
if(toupper(key)=='C')goto Cut;
if(toupper(key)=='N')goto New;
}
DrawLine:
if(button==LINE||toupper(key)=='L')
{ drawline(&key,linecolor);
if(toupper(key)=='F')goto DrawFrame;
if(toupper(key)=='C')goto Cut;
if(toupper(key)=='N')goto New;
}
New:
if(button==NEW||toupper(key)=='N')
new();
Cut:
if(button==CUT||toupper(key)=='C')
{ cut();
refresh();
}
}
}