📄 amain.cpp
字号:
bar(210,430,260,445);
PutCC16(270,430,0,14,pstr);
setfillstyle(1,VCOLOR);
bar(410,430,460,445);
PutCC16(470,430,0,14,vstr);
setcolor(oldcolor);
setwritemode(COPY_PUT);
}
//----------------------------------------------------//
//函数名:SHOWGRAPH()
//功能: 在作图区显示曲线
//入口参数:
// yratio: 作图比例
// 1----2:1
// 2----1:1
//出口参数:
//----------------------------------------------------//
void ShowGraph(int yratio)
{
int x,y;
register int i,j;
x=130;
y=410;
for(i=x0;(i-x0)<=50;i++) //在当前作图范围显示两条曲线
{
if (((head[i].y-y0)<=80/yratio) && (head[i].y>=y0))
ShowElement(x+(head[i].x-x0)*10,y-(head[i].y-y0)*5*yratio,
0,360,2,head[i].color);
}
for(i=x0+100;(i-x0-100)<=50;i++)
{
if (((head[i].y-y0)<=80/yratio) && (head[i].y>=y0))
ShowElement(x+(head[i].x-x0)*10,y-(head[i].y-y0)*5*yratio,
0,360,2,head[i].color);
}
}
//----------------------------------------------------//
//函数名:SHOWELEMENT()
//功能: 以饼图方式显示曲线上的点
//入口参数:
// x,y: 屏幕上点的座标
// stangle: 饼图起始角
// endangle: 饼图结束角
// radius: 饼图半径
// color: 饼图颜色
//出口参数:
//----------------------------------------------------//
void ShowElement(int x,int y,int stangle,int endangle,int radius,int color)
{
int oldcolor;
oldcolor=getcolor();
setcolor(color);
pieslice(x,y,stangle,endangle,radius);
setcolor(oldcolor);
}
//----------------------------------------------//
//函数名:FULLGRAPH()
//功能: 全图显示
//入口参数:
//出口参数:
//----------------------------------------------//
void FullGraph()
{
int oldcolor,btn=0;
int i,oldx0,oldy0,x,y;
char *help="右键结束";
oldcolor=getcolor();
oldx0=x0; //保存当前作图信息:坐标参考点
oldy0=y0;
x=130;
y=410;
x0=0;
y0=0;
setfillstyle(1,0);
bar(100,6,128,414);
bar(106,412,638,428);
bar(128,8,638,412);
ClearState();
PutCC16(81,461,0,14,help);
setcolor(14);
setlinestyle(0,0,1);
i=0;
line(130+i*10,10,130+i*10,410); //重画坐标轴
line(130,410+i*10,631,410+i*10);
line(131+i*10,10,131+i*10,410);
line(130,409+i*10,630,409+i*10);
for (i=0;i<200;i++) //水平方向缩小一倍,垂直方向缩小十倍,显示曲线
ShowElement(x+(head[i].x-x0)*5,y-(head[i].y-y0)*1.5,0,360,1,head[i].color);
while(btn!=RIGHT) ReadMouse(&btn,&x,&y);
while(RightPrsd()); //按鼠标右键结束,返回主界面
x0=oldx0;
y0=oldy0;
HideMouse();
ShowBkGrnd(1);
ShowCoord(10,20);
if (graphexist==TRUE) ShowGraph(1); //主界面有曲线,显示之
ShowMouse();
ClearState();
ShowCurState();
setcolor(oldcolor);
}
//----------------------------------------------//
//函数名:PAGEUP()
//功能: 页面上移
//入口参数:
//出口参数:
//----------------------------------------------//
void PageUp()
{
if (y0>=175) return; //纵坐标上限为215+40
y0+=step; //更新坐标参考点
ShowBkGrnd(1); //更新画图区
ShowCoord(10,20);
ShowGraph(1);
}
//----------------------------------------------//
//函数名:PAGEDOWN()
//功能: 页面下移
//入口参数:
//出口参数:
//----------------------------------------------//
void PageDown()
{
if (y0<=0) return; //纵坐标上限为215+40
y0-=step; //更新坐标参考点
ShowBkGrnd(1); //更新画图区
ShowCoord(10,20);
ShowGraph(1);
}
//----------------------------------------------//
//函数名:PAGELEFT()
//功能: 页面左移
//入口参数:
//出口参数:
//----------------------------------------------//
void PageLeft()
{
if (x0<=0) return; //横坐标下限为0
x0-=step; //更新坐标参考点
ShowBkGrnd(1); //更新画图区
ShowCoord(10,20);
ShowGraph(1);
}
//----------------------------------------------//
//函数名:PAGERIGHT()
//功能: 页面右移
//入口参数:
//出口参数:
//----------------------------------------------//
void PageRight()
{
if (x0>=50) return; //横坐标上限为50+50
x0+=step; //更新坐标参考点
ShowBkGrnd(1); //更新画图区
ShowCoord(10,20);
ShowGraph(1);
}
//--------------------------------------------------------//
//函数名:SETSYSPARA()
//功能: 设置系统参数
//入口参数:
//出口参数:
//--------------------------------------------------------//
void SetSysPara()
{
int x1,y1,len,high,i;
int x,y,btn,choice;
void *buf;
char *help="左键选择,右键返回";
char *item[]={ "机台编号",
"气门型号",
"杆 长",
"杆 径"};
char oldcolor;
HideMouse();
oldcolor=getcolor();
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(15);
x1=83;
y1=26+35*7;
len=80;
high=30;
buf=malloc(imagesize(x1-2,y1-2,x1+len+2,y1+high*4+2));
getimage(x1-2,y1-2,x1+len+2,y1+high*4+2,buf);
bar(x1-2,y1-2,x1+len+2,y1+high*4+2);
rectangle(x1-2,y1-2,x1+len+2,y1+high*4+2);
for(i=0;i<4;i++) //显示子菜单
{
PutCC16(x1+12,y1+high*i+6,0,1,item[i]);
setcolor(15);
rectangle(x1,y1+high*i,x1+len,y1+high*(i+1));
}
ShowMouse();
for (;;)
{
choice=0;
btn=0;
ClearState();
PutCC16(81,461,0,14,help);
while(btn!=LEFT && btn!=RIGHT) ReadMouse(&btn,&x,&y);
while(LeftPrsd() || RightPrsd());
if (btn==RIGHT) break;
for(i=0;i<4;i++) //判断所选的子菜单功能
{
if (MsInBox(x1,y1+high*i,x1+len,y1+high*(i+1),x,y))
{
choice=i+1;
break;
}
}
switch(choice)
{
case 1:
GetPara(MNUMBER,mnumber);
break;
case 2:
GetPara(MTYPE,mtype);
break;
case 3:
GetPara(MLEN,mlen);
break;
case 4:
GetPara(MRADIUS,mradius);
break;
}
}
HideMouse();
putimage(x1-2,y1-2,buf,COPY_PUT);
free(buf);
ClearState();
ShowCurState();
setcolor(oldcolor);
ShowMouse();
}
//----------------------------------------------------//
//函数名:GETPARA()
//功能: 获取有效参数
//入口参数:
// flag:调用方式
// MNUMBER:机台编号
// MTYPE: 气门型号
// MLEN: 杆长
// MRADIUS:杆径
//出口参数:
// 0:无效
// 1:有效
// para:参数指针
//----------------------------------------------------//
int GetPara(char flag,char *para)
{
int x1,y1,len,high,i,j;
FILE *fp;
char *buf;
char oldcolor;
char *msg;
char *help="按ESC键取消";
ClearState();
PutCC16(81,461,0,14,help);
HideMouse();
oldcolor=getcolor();
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(15);
x1=170;
y1=28+35*9;
if (flag==MNUMBER) msg="N0:";
if (flag==MTYPE) msg="TYPE:";
if (flag==MLEN) msg="LEN:";
if (flag==MRADIUS) msg="RADIUS";
len=230;
high=50;
buf=(char*)malloc(imagesize(x1,y1,x1+len,y1+high));
getimage(x1,y1,x1+len,y1+high,buf);
bar(x1,y1,x1+len,y1+high);
rectangle(x1,y1,x1+len,y1+high);
rectangle(x1+2,y1+2,x1+len-2,y1+high-2);
setfillstyle(1,7);
bar(x1+4,y1+4,x1+len-4,y1+high-4);
PutCC16(x1+18,y1+17,0,14,msg);
if ((flag==MLEN)||(flag==MRADIUS))
GetData(NUMBER,x1+18,y1+17,msg,para,4);
if (flag==MNUMBER)
GetData(NUMBER,x1+18,y1+17,msg,para,2);
if (flag==MTYPE)
GetData(TEXT,x1+18,y1+17,msg,para,12);
putimage(x1,y1,buf,COPY_PUT);
ClearState();
ShowCurState();
free(buf);
ShowMouse();
setcolor(oldcolor);
if (strchr(para,' ')||!strcmp(para,"")) return(0);
return 1;
}
//--------------------------------------------------------//
//函数名:PRINTGRAPH()
//功能: 当前作图区图形打印
//入口参数:
//出口参数:
//--------------------------------------------------------//
void PrintGraph()
{
int x1,y1,len,high,i;
int x,y,btn,choice;
void *buf;
char *item[]={ "确 定",
"取 消"};
char oldcolor;
oldcolor=getcolor();
HideMouse();
setfillstyle(1,7);
setlinestyle(0,0,1);
setcolor(15);
x1=83;
y1=341;
len=80;
high=30;
buf=malloc(imagesize(x1-2,y1-2,x1+len+2,y1+high*2+2));
getimage(x1-2,y1-2,x1+len+2,y1+high*3+2,buf);
bar(x1-2,y1-2,x1+len+2,y1+high*2+2);
rectangle(x1-2,y1-2,x1+len+2,y1+high*2+2);
for(i=0;i<2;i++) //显示子菜单
{
PutCC16(x1+12,y1+high*i+6,0,1,item[i]);
setcolor(15);
rectangle(x1,y1+high*i,x1+len,y1+high*(i+1));
}
ShowMouse();
btn=0;
while(btn!=LEFT) ReadMouse(&btn,&x,&y);
while(LeftPrsd());
for(i=0;i<2;i++) //判断所选的子菜单功能
{
if (MsInBox(x1,y1+high*i,x1+len,y1+high*(i+1),x,y))
{
choice=i+1;
break;
}
}
HideMouse();
putimage(x1-2,y1-2,buf,COPY_PUT);
free(buf);
setcolor(oldcolor);
switch(choice)
{
case 1:
if (graphexist==TRUE) PrintScr(80,6,640,479,0,39);
break;
case 2:
break;
}
ShowMouse();
}
//--------------------------------------------------------//
//函数名:PRINTSCR
//功能: 屏幕图形打印----点阵方式
//入口参数:
// x1,y1:屏幕左上角座标
// x2,y2:屏幕右上角座标
// rev: 标志,0:正向打印;1:反向打印
// m: 打印模式号(39---三倍密度,180,24针)
//出口参数:
//--------------------------------------------------------//
void PrintScr(int x1,int y1,int x2,int y2,int rev,int m)
{
int i,j,k,p,t;
int n,n1,n2;
int pinum,linum,mode;
unsigned char pt;
static unsigned char ch;
fprintf(stdprn,"%c%c\n",27,'@'); //打印机初始化
fprintf(stdprn,"%c%c%c\n",27,'3',24); //打印机行距设为24/280
n=2*(x2-x1+1); //计算打印列
n2=n/256;
n1=n-n2*256;
mode=m; //打印方式
linum=(y2-y1+12)/12; //计算打印行
pinum=24; //24针打印
for(i=0;i<linum;i++) //打印行数
{
fputc(27,stdprn); //ESC
fputc('*',stdprn); //设定图形打印命令
fputc(mode,stdprn); //打印方式:图象密度
fputc(n1,stdprn);
fputc(n2,stdprn); //打印列数(n1+n2*256)=n
for(j=0;j<n;j++)
{
k=y1+i*pinum/2; //对指定区域
for(p=0;p<pinum/8;p++) //连续获得垂直方向12个象素
{
for(ch=0,t=0;t<4;t++,k++)
if(k<=y2) //右边界检查
{
pt=getpixel(x1+j/2,k); //获得屏幕像素值
if(j/2==(float)j/2)
{
if(pt&8) ch|=1<<(7-2*t); //第四位为1
if(pt&4) ch|=1<<(7-2*t-1); //第三位为1
}
else
{
if(pt&2) ch|=1<<(7-2*t); //第二位为1
if(pt&1) ch|=1<<(7-2*t-1); //第一位为1
}
}
if(rev) ch=~ch; //反相打印
fprintf(stdprn,"%c",ch); //打印出该字节
}
}
fprintf(stdprn,"\n"); //换行
}
fprintf(stdprn,"\n"); //换行
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -