📄 grary11.h
字号:
void Coordtwo( GrpArr& ag,int i,int hl,int& x1,int& y1,int& x2,int& y2)
{ if (hl<0)
{ Coordsm(ag,i,x1,y1);
Coordsml(ag,i,x2,y2,-hl);
}
else {
Coorddm(ag,i,x1,y1);
Coorddml(ag,i,x2,y2,hl); }
}
void Fifild( GrpArr& ag,int i,int orxor)
{ Coord(ag,i,x,y);
putimage(x+1,y+1,ag.datafild[ag.ho_lev],orxor);
}
int *Relptr(int *p,int rel)
{int * relptr=nil;
relptr=p+rel;
return relptr; }
int * Nextptr(int *p)
{int * nextptr=nil;
nextptr=p+1;
return nextptr;
}
int *Grp_elmn_ptr( GrpArr& ag,int i)
{int * grp_elmn_ptr=nil;
grp_elmn_ptr=Relptr(ag.ag1,i-ag.sub1);
return grp_elmn_ptr;
}
datatype Elmn( GrpArr& ag,int i)
{
datatype elmn= datatype(*Relptr(ag.ag1,i-ag.sub1));
return elmn;
}
void Disnodedat( GrpArr& ag,int i)
{
Fifild(ag,i,0);
Fifild(ag,i,1);
Coord(ag,i,x,y);
Convs(Elmn(ag,i),st);
outtextxy(x+ag.w/6,y+ag.h/2,st);
}
void Disp_elmn_data( GrpArr& ag,int i)
{ Disnodedat(ag,i);
}
void Display_grparr_elmn( GrpArr& ag,int i)
{ Disnodedat(ag,i);
}
void Dissub( GrpArr& ag)
{
for (i=ag.sub1; i<=ag.count+ag.sub1-1;i++)
{ Coordsml(ag,i,x,y,((1-ag.ho_lev)*ag.w+ag.ho_lev*ag.h)/4);
Convs(i,st);
outtextxy(x,y,st);
}
}
void Disp_sub( GrpArr& ag)
{ Dissub(ag); }
void Initelmnsize( GrpArr& ag)
{
if (ag.ho_lev==0)
{ ag.dx=0; ag.dy=16; ag.h=16;ag.w=30; }
else
{ ag.dx=30; ag.dy=0; ag.h=30; ag.w=30; }
}
void Create_grp_arrbb( GrpArr& ag,HorOrLev hl,d_or_i di,
boolean dsub, bb1& b, string title, int fstsub,int lstsub)
{
{ ag.sub1=fstsub;
ag.count=Min(lstsub-fstsub+1,maxnum);
ag.dsb=dsub;
ag.firstptr=NULL;
ag.firstvar=NULL;
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)
{// with ag do
/* ag.sub1=fstsub;
ag.count=min(lstsub-fstsub+1,maxnum);
ag.dsb=true;
ag.firstptr=NULL;
ag.firstvar=NULL;
ag.name=title;
ag.asub1=minsubbb;
ag.asub2=maxnum;
ag.ag1=&b[ag.sub1];
ag.ho_lev=1;
ag.decinc=1;;
ag.havefd=false;
ag.fdsub=ag.ho_lev;
InitElmnSize(ag);
ag.sx=0;
ag.sy=0;*/
ag.sub1=fstsub;
ag.count=Min(lstsub-fstsub+1,maxnum);
ag.dsb=true;
ag.firstptr=NULL;
ag.firstvar=NULL;
ag.name=title;
ag.asub1=minsubbb;
ag.asub2=maxnum;
ag.ag1=&b[ag.sub1];
ag.ho_lev=(HorOrLev)1;
if (Answer_yes(" level [y/n?] ") )
ag.ho_lev=(HorOrLev)1;
if (Answer_yes(" Inc [y/n?]") )
ag.decinc=(d_or_i)1;
else
decinc=-1;
ag.dsb=Answer_yes(" display SUBs [y/n?]");
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)
{
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.ho_lev=(HorOrLev)0;
if (Answer_yes(" level [y/n?]") )
ag.ho_lev=(HorOrLev)1;
if (Answer_yes(" Inc [y/n?]") )
ag. decinc=(d_or_i)1;
else
ag.decinc=(d_or_i)-1;
ag.dsb=Answer_yes(" display SUBs [y/n?]");
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);
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; int size, l;
void * fd0;
ap1=ag.firstptr;
while ((ap1!=nil)&&(strcmp(ap1->ptr_name,ptrname)))
ap1=ap1->next;
if( ap1==nil)
{ p=new arlnode ;
//with p^ do
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,11);
p->fd0=malloc(size);
getimage(1,1,l,11,p->fd0);
putimage(1,1,p->fd0,1);
outtextxy(l/2,5,p->ptr_name);
getimage(1,1,l,11,p->fd0);
putimage(1,1,p->fd0,1);
}
else
Error(" pointer have exist!");
}
/*{ void point_off_on( p:ArrPtr;i:integer; ag:GrpArr;nf:HorOrLev);
curclr,x,y,x1,y1,hh,l:integer;
} {nf=0: clear, nf=1: cover }
{ { curclr:=getcolor; l:=length(p^.ptr_name)*4;
if nf=0 then setcolor(getbkcolor);
outtextxy(p^.oldx+l,p^.oldy+4,p^.ptr_name);
setcolor(getbkcolor); Arrow(x1,y1,x,y);
if nf=0 then setcolor(curclr);
};
}*/
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); 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); 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); 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);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=i;
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;
//// farfree(ap1->fd1);
ap1->hide=true;
ap1=ap1->next;
}
}
/*{ void point_off_on( p:ArrPtr;i:integer; ag:GrpArr;nf:HorOrLev);
curclr,x,y,x1,y1,hh:integer; } {nf=0: clear, nf=1: cover }
{ { putimage(p^.oldx,p^.oldy,ag.datafild[ag.ho_lev]^,1);
curclr:=getcolor; coordtwo(ag,i,p^.hl,x,y,x1,y1);
if nf=0 then
{ putimage(p^.oldx,p^.oldy,ag.datafild[ag.ho_lev]^,0);
putimage(p^.oldx,p^.oldy,ag.datafild[ag.ho_lev]^,1);
setcolor(getbkcolor); Arrow(x1,y1,x,y); setcolor(curclr);
} else with ag do
{ outtextxy(p^.oldx+w div 2,p^.oldy+h div 2,p^.ptr_name);
Arrow(x1,y1,x,y);
};
};
} */
void Put_elmn_value( GrpArr& ag,int i, datatype v, ArrPtr& p)
{int x,y;
// with ag do
*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);
do
delay(20);
while( !kbhit() ) ;
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() ) ;
//{ fifild(ag,i,1);fifild(ag,j,1);}
}
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->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)
{// with p^ do
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)
//{ if ag.ho_lev*(p->vy-iy)+(1-ag.ho_lev)*(p->vx-ix)<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;
string nums;
// {d=-1: -->ag, 1: <--ag}
hh2=-Var_up_left(p,ag,i)*d;
p->varopnum=p->varopnum+1;
Convs(p->varopnum,st);
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -