home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 November / VPR9811A.BIN / FFILLY / NandD / draw3d.h < prev    next >
Text File  |  1997-02-12  |  2KB  |  97 lines

  1. //draw3D.h
  2. //長方形を3D風に描きます
  3. //pic :描画するピクチャー番号
  4. //x1,y1,x2,y2 :X座標,Y座標
  5. //color :描画色(BGR各色256段階、0x000000~0xffffff)
  6. //edge :3Dの縁の幅(1~長方形の高さor幅の1/2まで)、デフォルトは4
  7. //cont :縁のコントラスト(パーセント)、デフォルトは40(%)
  8. //type :凸凹の指定(凸=0、凹=1)、デフォルトは凸
  9. int draw3D(int pic,int x1,int y1,int x2,int y2,int color,int edge=4,int cont=40,int type=0){
  10.     int dummyPic;    //ダミーのピクチャー、終了時に削除されます
  11.     int dWidth,dHeight;    //ダミーのピクチャーの幅と高さ
  12.     int orgR,orgG,orgB;    //平面の描画色
  13.     int col[];    //縁の描画色
  14.     int r,g,b;    //縁の描画色のRGB成分
  15.     int eCont[];    //縁のコントラスト
  16.     int i,temp;
  17.  
  18.     dWidth=x2-x1;
  19.     if(dWidth<0){
  20.         dWidth=-dWidth;
  21.         temp=x2;
  22.         x2=x1;
  23.         x1=temp;
  24.     }
  25.     dHeight=y2-y1;
  26.     if(dHeight<0){
  27.         dHeight=-dHeight;
  28.         temp=y2;
  29.         y2=y1;
  30.         y1=temp;
  31.     }
  32.     dWidth=dWidth+1;
  33.     dHeight=dHeight+1;
  34.     if(edge<0||edge*2>dWidth||edge*2>dHeight){    //縁のサイズのチェック
  35.         return(-1);
  36.     }
  37.     if(type!=0&&type!=1){    //typeのチェック
  38.         return(-1);
  39.     }
  40.  
  41.     //縁の描画色の設定
  42.     orgB=color/(256*256);
  43.     orgG=(color-orgB*256*256)/256;
  44.     orgR=color-orgB*256*256-orgG*256;
  45.     dummyPic=CreatePic(pic,dWidth,dHeight);
  46.     if(type==0){    //凸のとき
  47.         eCont[0]=cont*2;
  48.         eCont[1]=cont;
  49.         eCont[2]=-cont;
  50.         eCont[3]=-cont*2;
  51.     }
  52.     if(type==1){    //凹のとき
  53.         eCont[0]=-cont*2;
  54.         eCont[1]=-cont;
  55.         eCont[2]=cont;
  56.         eCont[3]=cont*2;
  57.     }
  58.     for(i=0;i<4;i=i+1){
  59.         b=orgB*(100+eCont[i])/100;
  60.         g=orgG*(100+eCont[i])/100;
  61.         r=orgR*(100+eCont[i])/100;
  62.         if(b>255)b=255;
  63.         if(g>255)g=255;
  64.         if(r>255)r=255;
  65.         if(b<0)b=0;
  66.         if(g<0)g=0;
  67.         if(r<0)r=0;
  68.         col[i]=b*256*256+g*256+r;
  69.     }
  70.  
  71.     //ダミーへの描画
  72.     SetLineSize(1);
  73.     SetPaintColor(col[1]);    //左辺
  74.     for(i=0;i<edge;i=i+1){
  75.         DrawLine(dummyPic,i,i,i,dHeight-i);
  76.     }
  77.     SetPaintColor(col[2]);    //右辺
  78.     for(i=0;i<edge;i=i+1){
  79.         DrawLine(dummyPic,dWidth-i-1,i,dWidth-i-1,dHeight-i);
  80.     }
  81.     SetPaintColor(col[3]);    //底辺
  82.     for(i=0;i<edge;i=i+1){
  83.         DrawLine(dummyPic,i,dHeight-i-1,dWidth-i,dHeight-i-1);
  84.     }
  85.     SetPaintColor(col[0]);    //上辺
  86.     for(i=0;i<edge;i=i+1){
  87.         DrawLine(dummyPic,i,i,dWidth-i,i);
  88.     }
  89.     SetPaintColor(color);//平面
  90.     DrawRect(dummyPic,edge,edge,dWidth-edge,dHeight-edge);
  91.  
  92.     //ピクチャーへの転送とダミーの削除
  93.     MovePic(dummyPic,0,0,dWidth,dHeight,pic,x1,y1);
  94.     DelPic(dummyPic);
  95.     return(0);
  96. }
  97.