📄 grary1.h
字号:
ag.name=title;
ag.asub1=minsubbb;
ag.asub2=maxnum;
ag.ag1=&b[ag.sub1];
ag.ho_lev=hl;
ag.decinc=di;
ag.havefd=false;
ag.fdsub=ag.ho_lev;
InitElmnSize(ag);
ag.sx=0;
ag.sy=0;
} }
void input_grp_Arrbb( GrpArr& ag, bb1& b,string title,
int fstsub,int lstsub)
{
Into_graph();
if (Answer_yes(" level [y/n?] ") )
ag.ho_lev=(HorOrLev)1;
else
ag.ho_lev=(HorOrLev)0;
if (Answer_yes(" Inc [y/n?] ") )
ag.decinc=(d_or_i)1;
else
ag.decinc=(d_or_i)-1;
if(Answer_yes(" display SUBs [y/n?] ") )
ag.dsb=(boolean)1;
else
ag.dsb=(boolean)0;
ag.sub1=fstsub;
ag.count=Min(lstsub-fstsub+1,maxnum);
ag.firstptr=NULL;
ag.firstvar=NULL;
ag.name=title;
ag.asub1=minsubbb;
ag.asub2=maxnum;
ag.ag1=&b[ag.sub1];
ag.havefd=false;
ag.fdsub=ag.ho_lev;
InitElmnSize(ag);
ag.sx=0;
ag.sy=0;
}
void create_grp_AnyArr( GrpArr& ag,HorOrLev hl,d_or_i di,boolean dsub,
bb1& b,string title,int Arrsub1,int Arrsub2,int fstsub,int lstsub)
{
ag.sub1=fstsub;
ag.count=Min(lstsub-fstsub+1,maxnum);
ag.firstptr=nil;
ag.firstvar=nil;
ag.name=title;
ag.dsb=dsub;
ag.ag1=&b[ag.sub1];
ag.asub1=Arrsub1;
ag.asub2=Arrsub2;
ag.ho_lev=hl;
ag.decinc=di;
ag.havefd=false;
ag.fdsub=ag.ho_lev;
InitElmnSize(ag);
ag.sx=0;
ag.sy=0;
}
void input_grp_AnyArr( GrpArr ag,bb1& b,string title,
int Arrsub1,int Arrsub2,int fstsub,int lstsub)
{
if (Answer_yes(" level [y/n?] ") )
ag.ho_lev=(HorOrLev)1;
else
ag.ho_lev=(HorOrLev)0;
if (Answer_yes(" Inc [y/n?] ") )
ag.decinc=(d_or_i)1;
else
ag.decinc=(d_or_i)-1;
if(Answer_yes(" display SUBs [y/n?] ") )
ag.dsb=(boolean)1;
else
ag.dsb=(boolean)0;
ag.sub1=fstsub;
ag.count=(lstsub-fstsub+1<maxnum)? (lstsub-fstsub+1) : maxnum;
ag.firstptr=nil;
ag.firstvar=nil;
ag.name=title;
ag.ag1=&b[fstsub];
ag.asub1=Arrsub1;
ag.asub2=Arrsub2;
ag.havefd=false;
ag.fdsub=ag.ho_lev;
InitElmnSize(ag);
ag.sx=0;
ag.sy=0;
}
void GrpArr_range( GrpArr& ag, int& x1,int& y1,int& x2,int& y2)
{ int x01=0,y01=0,x02=0,y02=0;
coord(ag,ag.sub1-1,x01,y01);
coord(ag,ag.sub1+ag.count+1,x02,y02);
x01=x01-(1-ag.ho_lev)*ag.w;
y01=y01-ag.ho_lev*ag.h;
x02=x02+(1-ag.ho_lev)*(ag.w+20);
y02=y02+ag.ho_lev*(ag.h+20);
if(x01>x02)
x01=x01+20;
if(y01>y02)
y01=y01+20;
x1=Min(x01,x02);
y1=Min(y01,y02);
x2=Max(x01,x02);
y2=Max(y01,y02);
}
void clear_GrpArr_range( GrpArr& ag)
{int x1,y1,x2,y2;
GrpArr_range(ag, x1,y1,x2,y2);
Clear_range(x1,y1,x2,y2);
}
boolean have_arrptr( GrpArr& ag,string title)
{ ArrPtr ap1;
boolean have_arrptr;
{ ap1=ag.firstptr;
while ((ap1!=nil)&&(!strcmp(ap1->ptr_name,title)))
ap1=ap1->next;
have_arrptr=(boolean)(ap1!=nil);
return have_arrptr;
}
}
void create_arrptr( ArrPtr& p ,string ptrname, GrpArr& ag,int hh)
{ ArrPtr ap1=nil; int size, l;
ap1=ag.firstptr;
while ((ap1!=nil)&&(strcmp(ap1->ptr_name,ptrname)))
ap1=ap1->next;
if( ap1==nil)
{ p=new arlnode ;
p->oldx=-1;
p->oldy=-1;
p->hide=true;
p->ptr_name=ptrname;
p->hl=hh;
p->next=ag.firstptr;
ag.firstptr=p;
l=strlen(p->ptr_name)*16;
size=imagesize(1,1,l,12);
p->fd0=malloc(size);
getimage(1,1,l,12,p->fd0);
putimage(1,1,p->fd0,1);
outtextxy(l/2,5,p->ptr_name);
getimage(1,1,l,12,p->fd0);
putimage(1,1,p->fd0,1);
}
else
Error(" pointer have exist!");
}
void point_to( ArrPtr& p, GrpArr& ag,int num)
{
int x,y,x1,y1,hh,dirnum,l;
int size;
void* pptr;
coord(ag,num,x,y);
hh=abs(p->hl);
dirnum=ag.ho_lev;
l=strlen(p->ptr_name)*16;
if( p->hl>0)
dirnum=dirnum+10;
if ((p->oldx!=-1)&&(p->oldy!=-1)&&(!p->hide))
{ putimage(p->oldx,p->oldy,p->fd0,1);
putimage(p->ox1,p->oy1,p->fd1,1); }
else
{
switch (dirnum)
{ case 0:{ p->size1=imagesize(1,1,hh,5);
pptr= malloc(p->size1);
getimage(1,1,hh,5,pptr);
putimage(1,1,pptr,1);
Arrow(1,3,hh,3);
p->fd1=malloc(p->size1);
getimage(1,1,hh,5,p->fd1);
putimage(1,1,p->fd1,1);
break;
}
case 1 : { p->size1=imagesize(1,1,5,hh);
pptr=malloc(p->size1) ;
getimage(1,1,5,hh,pptr);
putimage(1,1,pptr,1);
Arrow(3,1,3,hh);
p->fd1=malloc(p->size1);
getimage(1,1,5,hh,p->fd1);
putimage(1,1,p->fd1,1);
break;
}
case 10:{ p->size1=imagesize(1,1,hh,5);
pptr=malloc(p->size1);
getimage(1,1,hh,5,pptr);
putimage(1,1,pptr,1);
Arrow(hh,3,1,3);
p->fd1=malloc(p->size1);
getimage(1,1,hh,5,p->fd1);
putimage(1,1,p->fd1,1);
break;
}
case 11:{ p->size1=imagesize(1,1,5,hh);
pptr=malloc(p->size1);
getimage(1,1,5,hh,pptr);
putimage(1,1,pptr,1);
Arrow(3,hh,3,1);
p->fd1=malloc(p->size1);
getimage(1,1,5,hh,p->fd1);
putimage(1,1,p->fd1,1);
break;
}
}
putimage(1,1,pptr,0);
free(pptr);
}
switch (dirnum)
{
case 0:{ p->oldx=x-hh-l;p->oldy=y+ag.h/2-8;p->ox1=x-hh;p->oy1=p->oldy+2;break; }
case 1:{ p->oldx=x+(ag.w-l)/2+3;p->oldy=y-hh-8;p->ox1=x+ag.w/2-3;p->oy1=y-hh; break;}
case 10:{ p->oldx=x+ag.w+hh;p->oldy=y+h/2-8;p->ox1=x+ag.w;p->oy1=y+ag.h/2-3;break; }
case 11:{ p->oldx=x+(ag.w-l)/2+3;p->oldy=y+ag.h+hh;p->ox1=x+ag.w/2-3;p->oy1=y+ag.h;break; }
}
p->cursub=num;
putimage(p->oldx,p->oldy,p->fd0,1);
putimage(p->ox1,p->oy1,p->fd1,1);
p->hide=false;
}
void Arrptr_point_to( ArrPtr& p, GrpArr& ag ,int num)
{ point_to(p,ag,num); }
void Hide_All_arrptr( GrpArr& ag)
{ ArrPtr ap1=nil;
ap1=ag.firstptr;
while (ap1!=nil)
{ ap1->oldx=-1;
ap1->oldy=-1;
free(ap1->fd1);
ap1->hide=true;
ap1=ap1->next;
}
}
void put_elmn_value( GrpArr& ag,int i, datatype v, ArrPtr& p)
{int x,y;
*grp_elmn_ptr(ag,i)=v;
point_to(p,ag,i);
disnodedat(ag,i);
}
void move_elmn_to( GrpArr& ag ,int i,int j, ArrPtr &p)
{int x,y;
fifild(ag,i,1);
point_to(p,ag,i);
do
delay(20);
while( !kbhit() ) ;
fifild(ag,i,1);point_to(p,ag,j); disnodedat(ag,j); fifild(ag,j,1);
*grp_elmn_ptr(ag,j)=elmn(ag,i);
do
delay(20);
while( !kbhit() ) ;
fifild(ag,j,1);
disnodedat(ag,j);
}
void xchg_elmn_with( GrpArr& ag,int i,int j,int hh, ArrPtr& p)
{int x,y; ArrPtr q; datatype te;
create_arrptr(p,"xchg",ag,hh);
fifild(ag,i,1);point_to(p,ag,i);
fifild(ag,j,1);point_to(q,ag,j);
disnodedat(ag,i);disnodedat(ag,j);
te=elmn(ag,i);
* grp_elmn_ptr(ag,i)=elmn(ag,j);
* grp_elmn_ptr(ag,j)=te;
do
delay(20);
while( !kbhit() ) ;
disnodedat(ag,i);disnodedat(ag,j);
do
delay(20);
while( !kbhit() ) ;
}
boolean have_varptr( GrpArr& ag,string title)
{ VarPtr vp1;
boolean have_varptr;
vp1=ag.firstvar;
while ((vp1!=nil) && (strcmp(vp1->var_name,title)))
vp1=vp1->next;
have_varptr=(boolean)(vp1!=nil);
return have_varptr;
}
void create_varptr( VarPtr& p,string ptrname,
GrpArr& ag ,int hh)
{ VarPtr vp1;
vp1=ag.firstvar ;
while ((vp1!=nil) && (strcmp(vp1->var_name,ptrname)))
vp1=vp1->next;
if (vp1==nil)
{ p=new vrlnode;
p->vx=-1;
p->vy=-1;
p->varopnum=0;
p->var_name=ptrname;
p->hl=hh;
p->v=0;
p->next=ag.firstvar ;
ag.firstvar =p;
}
else
Error(" pointer have exist!");
}
void join_varptr_GrpArr( VarPtr& p, GrpArr& ag,int i)
{int x,y,x1,y1,hh;
hh=p->hl;
if (p->hl<0 )
hh=p->hl-(1-ag.ho_lev)*ag.w-ag.ho_lev*ag.h;
coordtwo(ag,i,hh,x,y,x1,y1);
p->vx=x1-ag.ho_lev*ag.w/2;
p->vy=y1-(1-ag.ho_lev)*ag.h/2;
p->cursub=i;
disp_varptr(p,ag);
}
void disvardat( VarPtr& p , GrpArr& ag)
{
unsigned char st[8]="";
putimage(p->vx+1,p->vy+1,ag.datafild[ag.ho_lev],0);
putimage(p->vx+1,p->vy+1,ag.datafild[ag.ho_lev],1);
Convs(p->v,st);
outtextxy(p->vx+ag.w/6,p->vy+ag.h/2, st);
}
void disp_varptr_data( VarPtr& p,GrpArr& ag)
{ disvardat(p,ag); }
void disp_varptr( VarPtr& p, GrpArr& ag)
{ disvardat(p,ag);
rectangle(p->vx,p->vy,p->vx+ag.w,p->vy+ag.h);
outtextxy(p->vx+ag.w/2,p->vy+ag.h+5,p->var_name);
}
void put_var ( VarPtr& p, datatype w, GrpArr& ag)
{ p->v=w;
disvardat(p,ag);
p->varopnum=p->varopnum+1;
}
int var_up_left( VarPtr& p,GrpArr& ag,int i)
{int ix,iy,var_up_left;
coord(ag,i,ix,iy);
if (ag.ho_lev*(p->vx-ix)+(1-ag.ho_lev)*(p->vy-iy)<0)
var_up_left=1;
else var_up_left=-1;
return
var_up_left;
}
void vcrds( VarPtr& p, GrpArr& ag,int d,int i)
{int hhl,hh2,hh3,vi,ix,iy,ixl,iyl,vxl,vyl,n1,n2;
unsigned char nums[20]="";
unsigned char st[8]="";
// {d=-1: -->ag, 1: <--ag}
hh2=-var_up_left(p,ag,i)*d;
p->varopnum=p->varopnum+1;
Convs(p->varopnum,st);
strcpy(nums,st);
if (p->cursub==i)
{ coordtwo(ag,i,p->hl,ix,iy,ixl,iyl);
ixl=ixl+d*ag.ho_lev*ag.w/4;
iyl=iyl+d*(1-ag.ho_lev)*ag.h/4;
ix=ix+d*ag.ho_lev*ag.w/4;
iy=iy+d*(1-ag.ho_lev)*ag.h/4;
if (d==-1)
Arrow(ixl,iyl,ix,iy);
else
Arrow(ix,iy,ixl,iyl);
outtextxy((ixl+ix)/2,(iyl+iy)/2,nums);
}
else
{ hhl=abs(p->hl)+(ag.ho_lev*h+(1-ag.ho_lev)*ag.w)*(2-d)/4;
if (p->hl<0)
hhl=-hhl;
coordtwo(ag,i,hhl,ix,iy,ixl,iyl);
ixl=ixl+ag.ho_lev*ag.w/4*hh2;
iyl=iyl+(1-ag.ho_lev)*ag.h/4*hh2;
ix=ix+ag.ho_lev*ag.w/4*hh2;
iy=iy+(1-ag.ho_lev)*ag.h/4*hh2;
vi=p->cursub;
if (var_up_left(p,ag,i)==1)
vi=vi+ag.decinc;
coordtwo(ag,vi,hhl,n1,n2,vxl,vyl);
vxl=vxl-ag.ho_lev*ag.w/2;
vyl=vyl-(1-ag.ho_lev)*ag.h/2;
outtextxy(ixl-3,iyl-3,nums);
if (d==-1)
{ line(vxl,vyl,ixl,iyl);
Arrow(ixl,iyl,ix,iy);
}
else {
line(ix,iy,ixl,iyl);
Arrow(ixl,iyl,vxl,vyl);
}
}
}
void move_var_GrpArr( VarPtr& p, GrpArr& ag,int i)
{int x,y,x1,y1,hkl,hk;
if ((p->vx==-1) && (p->vy==-1))
join_varptr_GrpArr(p,ag,i);
vcrds(p,ag,-1,i);
put_elmn(ag,i,p->v,0);
}
void move_GrpArr_var ( VarPtr& p,GrpArr& ag,int i)
{int x,y,x1,y1,hh;
if ((p->vx==-1) && (p->vy==-1))
join_varptr_GrpArr(p,ag,i);
vcrds(p,ag,1,i);
p->v=elmn(ag,i);
disp_varptr_data(p,ag);
}
void put_elmn( GrpArr& ag,int i,datatype v,int hl)
{ int x1,y1,x2,y2,lenv,sg;
unsigned char st[8]="";
disnodedat(ag,i);
fifild(ag,i,1);
* grp_elmn_ptr(ag,i)=v;
// {v-->}
coordtwo(ag,i,hl,x1,y1,x2,y2);
sg=Sgn(0,hl);
if (hl!=0)
{Arrow(x2,y2,x1,y1);
Convs(v,st);
lenv=strlen(st)*8/2*sg;
outtextxy(x2+(1-ag.ho_lev)*lenv,y2+ag.ho_lev*6*sg,st);
}
*grp_elmn_ptr(ag,i)=v;
trace1();
disnodedat(ag,i);
trace1();
}
boolean cmp_elmn( GrpArr& ag,int i,int j,string op,int hl)
{int x1,y1,x2,y2,x3,y3,x4,y4;
boolean cmp_elmn;
datatype v1,v2;
boolean cmp;
disnodedat(ag,i);
disnodedat(ag,j);
fifild(ag,i,1);
fifild(ag,j,1);
trace1();
coordtwo(ag,i,hl,x1,y1,x2,y2);
Arrow(x2,y2,x1,y1);
coordtwo(ag,j,hl,x3,y3,x4,y4);
Arrow(x4,y4,x3,y3);
trace1();
disnodedat(ag,i);
disnodedat(ag,j);
v1=elmn(ag,i);
v2=elmn(ag,j);
cmp=(boolean)((!strcmp(op,"=")) && (v1==v2) || (!strcmp(op,">")) && (v1>v2));
cmp=(boolean)(cmp ||(!strcmp(op,"<"))&&(v1<v2)||(!strcmp(op,"<>")) &&(v1!=v2));
cmp=(boolean)(cmp || (!strcmp(op,"<=")) && (v1<=v2) ||(!strcmp(op,">=")) && (v1>=v2));
cmp_elmn=cmp;
return cmp_elmn; //{ write(cmp);}
}
void move_elmn( GrpArr& ag,int i,int j,int hl)
{int x1,y1,x2,y2,x3,y3,x4,y4;
disnodedat(ag,i);
fifild(ag,i,1);
disnodedat(ag,j);
fifild(ag,j,1);
trace1();
*grp_elmn_ptr(ag,j)=elmn(ag,i);
coordtwo(ag,i,hl,x1,y1,x2,y2);
Arrow(x1,y1,x2,y2);
coordtwo(ag,j,hl,x3,y3,x4,y4);
Arrow(x4,y4,x3,y3);
line(x2,y2,x4,y4);
disnodedat(ag,j);
fifild(ag,j,1);
trace1();
fifild(ag,i,1);
fifild(ag,j,1);
}
void xchg_elmn( GrpArr& ag,int i,int j,int hl)
{int x1,y1,x2,y2,x3,y3,x4,y4;
datatype te;
disnodedat(ag,i);
disnodedat(ag,j);
fifild(ag,i,1);
fifild(ag,j,1);
coordtwo(ag,i,hl,x1,y1,x2,y2);
Arrow(x2,y2,x1,y1);
coordtwo(ag,j,hl,x3,y3,x4,y4);
Arrow(x4,y4,x3,y3);
line(x2,y2,x4,y4);
trace1();
te=elmn(ag,i);
*grp_elmn_ptr(ag,i)=elmn(ag,j);
*grp_elmn_ptr(ag,j)=te;
disnodedat(ag,i);disnodedat(ag,j);
fifild(ag,i,1);
fifild(ag,j,1);
trace1();
fifild(ag,i,1);
fifild(ag,j,1);
}
void dec(int& x,int n)
{ x=x-n;
}
void inc(int& x,int n)
{ x=x+n;
}
void elmn_ptr_elmn( GrpArr& ag,int i,int hl)
{int x1,y1,x2,y2,x3,y3,x4,y4,j,dh,dw;
datatype te;
j=elmn(ag,i);
if (j<sub1(ag))
return;
coordtwo(ag,i,hl,x1,y1,x2,y2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -