⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw3d.c

📁 用于分析各种点阵字库结构和程序
💻 C
字号:
#ifndef __DRAW3D_C
#define __DRAW3D_C

#include <math.h>
#include <string.h>
#include <conio.h>
#include <bios.h>

#include "draw3d.h"
#include "constants.h"
#include "dspstr.h"
#include "gettext.h"

//#define __USE_MOUSE

#ifdef __USE_MOUSE
  #include "mouse.h"
#endif

//-----------------------------
void DrawTable(int x, int y)
{
//Testing.
  setwritemode(COPY_PUT);
  setviewport(0,0,639,479,1);
  setfillstyle(1,0);  outtextxy(x,y,"0");	bar(x+20,y,x+50,y+10);
  setfillstyle(1,1);  outtextxy(x,y+10,"1");	bar(x+20,y+10,x+50,y+20);
  setfillstyle(1,2);  outtextxy(x,y+20,"2");	bar(x+20,y+20,x+50,y+30);
  setfillstyle(1,3);  outtextxy(x,y+30,"3");	bar(x+20,y+30,x+50,y+40);
  setfillstyle(1,4);  outtextxy(x,y+40,"4");	bar(x+20,y+40,x+50,y+50);
  setfillstyle(1,5);  outtextxy(x,y+50,"5");	bar(x+20,y+50,x+50,y+60);
  setfillstyle(1,6);  outtextxy(x,y+60,"6");	bar(x+20,y+60,x+50,y+70);
  setfillstyle(1,7);  outtextxy(x,y+70,"7");	bar(x+20,y+70,x+50,y+80);
  setfillstyle(1,8);  outtextxy(x,y+80,"8");	bar(x+20,y+80,x+50,y+90);
  setfillstyle(1,9);  outtextxy(x,y+90,"9");	bar(x+20,y+90,x+50,y+100);
  setfillstyle(1,10); outtextxy(x,y+100,"10");	bar(x+20,y+100,x+50,y+110);
  setfillstyle(1,11); outtextxy(x,y+110,"11");	bar(x+20,y+110,x+50,y+120);
  setfillstyle(1,12); outtextxy(x,y+120,"12");	bar(x+20,y+120,x+50,y+130);
  setfillstyle(1,13); outtextxy(x,y+130,"13");	bar(x+20,y+130,x+50,y+140);
  setfillstyle(1,14); outtextxy(x,y+140,"14");	bar(x+20,y+140,x+50,y+150);
  setfillstyle(1,15); outtextxy(x,y+150,"15");	bar(x+20,y+150,x+50,y+160);
//--End test.
}

//-----------------------------
int DrawFrame(int xL,int yT,int xR,int yB)
// Draw a frame seemed to a sink in.
{
//  if(xL<0 || yT<0 || xL>MaxX || yT>MaxY)return ERROR;
//  if(xR<0 || yB<0 || xR>MaxX || yB>MaxY)return ERROR;
  if(xL+2>=xR || yT+2>=yB )return ERROR;
//Draw the outside rectangle.
  setwritemode(COPY_PUT);
  moveto(xL,yB);
  setcolor(DARKGRAY);	lineto(xL,yT);	lineto(xR,yT);
  setcolor(WHITE);	lineto(xR,yB);	lineto(xL,yB);
  moveto(xL+1,yB-1);	lineto(xL+1,yT+1);	lineto(xR-1,yT+1);
  setcolor(DARKGRAY);
  moveto(xR-1,yT+2);	lineto(xR-1,yB-1);	lineto(xL+1,yB-1);
  return OK;
}

//-----------------------------
int DrawFrame1(int xL,int yT,int xR,int yB,int FramWidth)
// Draw a frame seemed to a sink in.
{
  int i;
//  if(xL<0 || yT<0 || xL>MaxX || yT>MaxY)return ERROR;
//  if(xR<0 || yB<0 || xR>MaxX || yB>MaxY)return ERROR;
  if(xL+2>=xR || yT+2>=yB )return ERROR;
//Draw the outside rectangle.
  setwritemode(COPY_PUT);
  for(i=0; i<FramWidth; ++i){
    moveto(xL+i,yB-i);
    setcolor(WHITE);	lineto(xL+i,yT+i);	lineto(xR-i,yT+i);
    setcolor(DARKGRAY);	lineto(xR-i,yB-i);	lineto(xL+i,yB-i);
  }
  return OK;
}

//-----------------------------
int DrawFrame2(int xL,int yT,int xR,int yB,int FramWidth)
// Draw a frame seemed to a sink in.
{
  int i;
//  if(xL<0 || yT<0 || xL>MaxX || yT>MaxY)return ERROR;
//  if(xR<0 || yB<0 || xR>MaxX || yB>MaxY)return ERROR;
  if(xL+2>=xR || yT+2>=yB )return ERROR;
//Draw the outside rectangle.
  setwritemode(COPY_PUT);
  for(i=0; i<FramWidth; ++i){
    moveto(xL+i,yB-i);
    setcolor(DARKGRAY);	lineto(xL+i,yT+i);	lineto(xR-i,yT+i);
    setcolor(WHITE);	lineto(xR-i,yB-i);	lineto(xL+i,yB-i);
  }
  return OK;
}

//-----------------------------
int AssignButton(Button *pB,
   int xL,	 int yT,      int xR,	int yB,//Button position
   int FramWidth,int bkcol,   int Active,  int Press, int Select,//Button appearence
   char *str,    int strcol,  int strbkcol,int xAlign, int yAlign//Button text.
)
{ char ch;
  if(xL>=0 && xL<MaxX)pB->xL=xL;	else return ERROR;
  if(xR>=0 && xR<MaxX)pB->xR=xR;	else return ERROR;
  if(yT>=0 && yT<MaxY)pB->yT=yT;	else return ERROR;
  if(yB>=0 && yB<MaxY)pB->yB=yB;	else return ERROR;
  pB->FramWidth=FramWidth;	pB->bkcol=bkcol;
  pB->Active=Active;	pB->Press=Press;	pB->Select=Select;
  if(strlen(str) <= MAXBUTTSTRLEN)strcpy(pB->str,str);
  else {
    ch=str[MAXBUTTSTRLEN]; 	str[MAXBUTTSTRLEN]=0;
    strcpy(pB->str,str);	str[MAXBUTTSTRLEN]=ch;
  }
  pB->strcol=strcol;	pB->strbkcol=strbkcol;
  pB->xAlign=xAlign;	pB->yAlign=yAlign;
  return OK;
}

//-----------------------------
int DrawButton(Button *pB)
// Draw a frame seemed to a sink in.
/*(int xL,	 int yT,      int xR,	int yB,//Button position
   int FramWidth,int bkcol,   int Active,  int Press, int Select,//Button appearence
   char *str,    int strcol,  int strbkcol,int xAlign, int yAlign//Button text.
)*/
//bkcol:	==-1-> not clean the draw area. / ==other-> Clean the given area to color 'bkcol'.
//xAlign,yAlign:==-1->left align / ==0->center / ==1->right align
//Active:	==0 ->no active /  ==1->active;
//Press		==0 ->Up/==1->Down;
{ int i,x,y,len,col1,col2,wid;

  if(pB->xL<0 || pB->yT<0 || pB->xL>MaxX || pB->yT>MaxY)return ERROR;
  if(pB->xR<0 || pB->yB<0 || pB->xR>MaxX || pB->yB>MaxY)return ERROR;
  if(pB->xL+2>=pB->xR || pB->yT+2>=pB->yB )return ERROR;
  if(pB->FramWidth<1)wid=1;
  else	wid = pB->FramWidth;
//Clear area.
  setwritemode(COPY_PUT);
  if(pB->strbkcol>=0){
    setfillstyle(SOLID_FILL,pB->strbkcol);
    bar(pB->xL,pB->yT,pB->xR,pB->yB);
  }

//Draw the framework.
  if(!pB->Press){col1=WHITE;	col2=DARKGRAY;	}//Press UP
  else	{	  col1=DARKGRAY;col2=WHITE;	}//Press Down
  for(i=0; i<wid; ++i)
  { setcolor(col1);
    moveto(pB->xL+i,pB->yB-i);
    lineto(pB->xL+i,pB->yT+i);	lineto(pB->xR-i,pB->yT+i);
    setcolor(col2);
    lineto(pB->xR-i,pB->yB-i);	lineto(pB->xL+i,pB->yB-i);
  }
//Display String.
  len=strlen(pB->str);
  if( len ){
    if( !pB->xAlign )	   x=pB->xL + (pB->xR - pB->xL - 8*len+1)/2;
    else if( pB->xAlign<0 ) x=pB->xL + wid;
    else		   x=pB->xR - 8*len - wid;
    if( x < pB->xL + wid ) x=pB->xL + wid;
    //
    if( !pB->yAlign )	   y=pB->yT + (pB->yB - pB->yT - 16+1)/2;
    else if( pB->yAlign<0 ) y=pB->yT + wid;
    else		   y=pB->yB - 16 - wid;
    if( y < pB->yT + wid ) y=pB->yT + wid;
    //
    if(pB->Press){ x++; y++; }
    if(pB->Active)out16textxy(x,y,pB->str,pB->strcol,pB->strbkcol);
    else	  out16textxy(x,y,pB->str,DARKGRAY,pB->strbkcol);
  }
  return OK;
}

//-----------------------------
int DrawButton1(Button *pB)
{ int i,x,y,len,wid;

  if(pB->xL<0 || pB->yT<0 || pB->xL>MaxX || pB->yT>MaxY)return ERROR;
  if(pB->xR<0 || pB->yB<0 || pB->xR>MaxX || pB->yB>MaxY)return ERROR;
  if(pB->xL+2>=pB->xR || pB->yT+2>=pB->yB )return ERROR;
  if(pB->FramWidth<1)wid=1;
  else	wid = pB->FramWidth;
//Clear area.
  setwritemode(COPY_PUT);
  if(pB->strbkcol>=0){
    setfillstyle(SOLID_FILL,pB->strbkcol);
    bar(pB->xL,pB->yT,pB->xR,pB->yB);
  }

//Draw the outside rectangle.
  if(pB->Select){
    setcolor(teBLACK);
    rectangle(pB->xL,pB->yT,pB->xR,pB->yB);
  }
//Draw the Framework.
  if(!pB->Press){	//Normal Status.
    for(i=1; i<wid+1; ++i) {
      setcolor(WHITE);
      moveto(pB->xL+i,pB->yB-i);
      lineto(pB->xL+i,pB->yT+i);	lineto(pB->xR-i,pB->yT+i);
      setcolor(DARKGRAY);
      lineto(pB->xR-i,pB->yB-i);	lineto(pB->xL+i,pB->yB-i);
    }
  }
  else	{	//Button is pressed.
    for(i=0; i<wid-1; ++i){
      setcolor(teBLACK);
      rectangle(pB->xL+i+1,pB->yT+i+1,pB->xR-i-1,pB->yB-i-1);
    }
    setcolor(DARKGRAY);
    moveto(pB->xL+i+1,pB->yB-i-1);
    lineto(pB->xL+i+1,pB->yT+i+1);	lineto(pB->xR-i-1,pB->yT+i+1);
  }
//Display String.
  len=strlen(pB->str);
  if(len){
    if( !pB->xAlign )	   x=pB->xL + (pB->xR - pB->xL - 8*len+1)/2;
    else if( pB->xAlign<0 ) x=pB->xL + wid;
    else		   x=pB->xR - 8*len - wid;
    if( x < pB->xL + wid ) x=pB->xL + wid;
    //
    if( !pB->yAlign )	   y=pB->yT + (pB->yB - pB->yT - 16+1)/2;
    else if( pB->yAlign<0 ) y=pB->yT + wid;
    else		   y=pB->yB - 16 - wid;
    if( y < pB->yT + wid ) y=pB->yT + wid;
    //
    if(pB->Press){ x++; y++; }
    if(pB->Active)out16textxy(x,y,pB->str,pB->strcol,pB->strbkcol);
    else	  out16textxy(x,y,pB->str,DARKGRAY,pB->strbkcol);
  }
  return OK;
}

//=======================================================
void MarkButton(Button *b, unsigned char col)
{	setwritemode(COPY_PUT);
	setcolor(col);
	rectangle(b->xL-1, b->yT-1, b->xR+1, b->yB+1);
	rectangle(b->xL-2, b->yT-2, b->xR+2, b->yB+2);
}

//=======================================================
int DrawAlarm(int x,int y,int Stat)
{
  int ColH,ColL;

  setwritemode(COPY_PUT);
  if(Stat) { ColH=LIGHTRED; ColL=RED;}
  else { ColH=LIGHTGREEN/*LIGHTGRAY*/; ColL=GREEN/*DARKGRAY*/;}
  if(x<7 || y<7 || x>MaxX-7 || y>MaxY-7)return ERROR;
  setcolor(teBLACK);  circle(x,y,7);
  setfillstyle(SOLID_FILL,teBLACK);  floodfill(x,y,teBLACK);
  setcolor(ColL);  circle(x,y,5);
  setfillstyle(SOLID_FILL,ColL);  floodfill(x,y,ColL);
  setcolor(ColH);  circle(x-1,y-1,4);
  setfillstyle(SOLID_FILL,ColH);  floodfill(x-1,y-1,ColH);
  putpixel(x-1,y-1,WHITE);  putpixel(x-1,y-2,WHITE);
  putpixel(x-2,y-1,WHITE);  putpixel(x-2,y-2,WHITE);
//  setfillstyle(SOLID_FILL,WHITE);  floodfill(x-1,y-1,WHITE);
  return OK;
}

//Display a Dialoge.
#define DIA_WIDTH	200
#define DIA_HEIGHT	120
int DispDialoge(int xL, int yT,// int xR, int yB,
		char *tit, char *MsgStr,int ButtNum)
//When return value ==0:-> Cancel
//		    ==1 -> OK.
{ unsigned int ImgSize;
  void *pImgBuf;
  int len,kte;
  char ActButt=1;//==0 OK/ ==1 Cancel
  char ret_f,exit_f;//,f_flash;
  int xR,yB;
  Button B1={0,0,0,0,2,CYAN,BUT_ACT,BUT_UP,BUT_SEL,"确定",teBLACK,CYAN,0,0};
  Button B2={0,0,0,0,2,CYAN,BUT_ACT,BUT_UP,BUT_SEL,"取消",teBLACK,CYAN,0,0};

  xR=xL+DIA_WIDTH;  yB=yT+DIA_HEIGHT;
  //Check the parameters' legally.
  if(xL<0 || yT<0 || xL>MaxX-DIA_WIDTH || yT>MaxY-DIA_HEIGHT)return ERROR;
  //
  nosound();//Clear the sound.
  ImgSize=imagesize(xL,yT,xR,yB);
  pImgBuf=malloc(ImgSize);
  if(!pImgBuf){
    closegraph();    fcloseall();
    printf("Not enough memory to display Dialoge...%c",7);
    exit(0);//A ERROR happen!! Memory not enongh!
  }
  getimage(xL,yT,xR,yB,pImgBuf);
  //Clear display area.
  setwritemode(COPY_PUT);
  setfillstyle(SOLID_FILL,LIGHTGRAY);
  bar(xL,yT,xR,yB);
  //Draw the basic frame.
  DrawFrame1(xL,yT,xR,yB,2);
  setfillstyle(SOLID_FILL,CYAN);
  bar(xL+3,yT+3,xR-3,yB-3);
  setfillstyle(SOLID_FILL,LIGHTBLUE);
  bar(xL+3,yT+3,xR-3,yT+22);
  //Display title.
  len=strlen(tit)*8;
  out16textxy(xL+(xR-xL-len)/2, yT+5,tit, RED, -1);
  //Display Message.
  len=strlen(MsgStr)*8;
  if(len<xR-xL-4)
    out16textxy(xL+10, yT+35,MsgStr, RED, -1);
  //Draw Buttons.
  if(ButtNum==2){
    B1.xL=xL+30;	B1.xR=xL+75;	B1.yT=yT+85;	B1.yB=yT+109;
    DrawButton1(&B1);
    B2.xL=xL+125;	B2.xR=xL+170;	B2.yT=yT+85;	B2.yB=yT+109;
    DrawButton1(&B2);
  }
  if(ButtNum==1){
    B1.xL=xL+78;	B1.xR=xL+123;	B1.yT=yT+85;	B1.yB=yT+109;
    B1.bkcol=LIGHTRED;
    DrawButton1(&B1);
  }
  //Sound Alarm.
  sound(2000);	delay(10);	nosound();
  //Process Key press.
  ret_f=0;  exit_f=0;  ActButt=1;
  setwritemode(COPY_PUT);
  setcolor(LIGHTRED);
  rectangle(B2.xL-1,B2.yT-1,B2.xR+1,B2.yB+1);
  rectangle(B2.xL-2,B2.yT-2,B2.xR+2,B2.yB+2);
  while(!exit_f){
    if( !bioskey(1) )continue;
    kte=bioskey(0);
//    f_flash=0;
    switch(kte){
      case LARROW:
	if(ActButt==1 && ButtNum==2)  ActButt=0;//B1.Select=BUT_SEL; B2.Select=BUT_NOSEL; f_flash=1;}
	break;
      case RARROW:
	if(ActButt==0 && ButtNum==2) ActButt=1;// B1.Select=BUT_NOSEL; B2.Select=BUT_SEL; f_flash=1;}
	break;
      case TAB:
	if(ButtNum==1)break;// No reply.
	if(ActButt)ActButt=0;//	B1.Select=BUT_SEL;	B2.Select=BUT_NOSEL;}
	else	  ActButt=1;//	B1.Select=BUT_NOSEL;	B2.Select=BUT_SEL;}
//	f_flash=1;
	break;
      case ESC:  exit_f=1; ret_f=0;break;
      case ENTER:exit_f=1; ret_f=!ActButt;break;
      default: break;
    }
    if(exit_f)break;
    if(ActButt==0){
      setcolor(CYAN);
      rectangle(B2.xL-1,B2.yT-1,B2.xR+1,B2.yB+1);
      rectangle(B2.xL-2,B2.yT-2,B2.xR+2,B2.yB+2);
      setcolor(LIGHTRED);
      rectangle(B1.xL-1,B1.yT-1,B1.xR+1,B1.yB+1);
      rectangle(B1.xL-2,B1.yT-2,B1.xR+2,B1.yB+2);
    }
    else {
      setcolor(LIGHTRED);
      rectangle(B2.xL-1,B2.yT-1,B2.xR+1,B2.yB+1);
      rectangle(B2.xL-2,B2.yT-2,B2.xR+2,B2.yB+2);
      setcolor(CYAN);
      rectangle(B1.xL-1,B1.yT-1,B1.xR+1,B1.yB+1);
      rectangle(B1.xL-2,B1.yT-2,B1.xR+2,B1.yB+2);
    }
//    if( f_flash ) { DrawButton1(&B1);	DrawButton1(&B2);}
  }
  putimage(xL,yT,pImgBuf,COPY_PUT);
  free(pImgBuf);
  pImgBuf=0;
  return ret_f;
}

//***************************************************
#define PASS_WID	200
#define PASS_HEI	90
int DispPassDialoge(unsigned xL, unsigned yT)
//When return value ==0:-> Cancel
//		    ==1 -> OK.
{ unsigned int ImgSize;
  unsigned char str[20],*pImgBuf;
  unsigned char Pass1[]="87542835",PassStr[]="1111";
  int xR,yB;

  xR=xL+PASS_WID;  yB=yT+PASS_HEI;
  //Check the parameters' legally.
  if( xL>MaxX-PASS_WID || yT>MaxY-PASS_HEI)return ERROR;
  //
  nosound();//Clear the sound.
  ImgSize=imagesize(xL,yT,xR,yB);
  pImgBuf=malloc(ImgSize);
  if(!pImgBuf){
    closegraph();    fcloseall();
    printf("Not enough memory to display PassDialoge...%c",7);
    exit(0);//A ERROR happen!! Memory not enongh!
  }
  getimage(xL,yT,xR,yB,pImgBuf);
  //Clear display area.
  setwritemode(COPY_PUT);
  setfillstyle(SOLID_FILL,LIGHTGRAY);
  bar(xL,yT,xR,yB);
  //Draw the basic frame.
  DrawFrame1(xL,yT,xR,yB,2);
  setfillstyle(SOLID_FILL,CYAN);
  bar(xL+3,yT+3,xR-3,yB-3);
  setfillstyle(SOLID_FILL,LIGHTBLUE);
  bar(xL+3,yT+3,xR-3,yT+22);
  //Display title.
  out16textxy(xL+(xR-xL-64)/2, yT+5,"校验口令", WHITE, -1);
  //Display Message.
  out16textxy(xL+10, yT+35,"请输入口令:", WHITE, -1);
  //Sound Alarm.
  sound(2000);	delay(10);	nosound();
  GMGetStr(xL+100,yT+35,64,str,1,0,0);
  //Process Key press.
  if( strcmp(str,PassStr) && strcmp(str,Pass1) ){
     out16textxy(xL+10,yT+55,"口令错误!",RED,-1);
     sound(200);	delay(100);	nosound();	delay(100);
     sound(200);	delay(100);	nosound();	delay(100);
     sound(200);	delay(100);	nosound();
     getch();
  }
  putimage(xL,yT,pImgBuf,COPY_PUT);
  free(pImgBuf);
  if( !strcmp(str,PassStr) || !strcmp(str,Pass1) )   return 1;
  else 	return 0;
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -