?? display.cpp
字號:
#include <vcl.h>
#include "math.h"
#include "stdlib.h"
#include "Sim_Valve.h"
//Windows圖形顯示,
//單片機中無用
void TMainForm:: Work_Disp_Curve(void)
{
unsigned int valve_pos;
unsigned char Valve_Code[6];
double x0,y0,r,x,y,j;
Valve_Panel->Top=2*m_Valve_Pos; //需修改 顯示
x0=Shape1->Left+(Shape1->Width)/2;
y0=Shape1->Top+(Shape1->Height)/2;
j=3.1415/2*m_Valve_Pos/100.0;
r=(Shape1->Width)/2.5;
x=x0+r*sin(j);
y=y0-r*cos(j);
Shape2->Left=x;
Shape2->Top=y;
}
void TMainForm::Disp_Num(char Data[4])
{
//TODO: Add your source code here
int x0,y0,x1,y1;
TCanvas *pCanvas;
pCanvas=PaintBox2->Canvas;
x0=0;
y0=0;
x1=PaintBox2->Width;
y1=PaintBox2->Height;
pCanvas->Pen->Color=clBtnFace;
pCanvas->Pen->Style=psSolid;
pCanvas->Brush->Color=clBtnFace;
pCanvas->Brush->Style=bsSolid;
pCanvas->Rectangle(x0,y0,x1,y1);
pCanvas->Pen->Color=clBlack;
pCanvas->Pen->Style=psSolid;
pCanvas->Pen->Width=3;
Draw_Num(1,Data[0],Data[1],pCanvas);
Draw_Num(0,Data[2],Data[3],pCanvas);
}
void TMainForm::Draw_Circle(TCanvas *pCanvas)
{
int i;
pCanvas->Ellipse(35,10,55,30);
}
void TMainForm::Draw_UP_Arrow(TCanvas *pCanvas)
{
int i;
int x0,y0,x1,y1;
x0=40;
y0=40;
x1=x0-5;
y1=y0+30;
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x1,y1);
}
void TMainForm::Draw_DN_Arrow(TCanvas *pCanvas)
{
int i;
int x0,y0,x1,y1;
x0=35;
y0=80;
x1=x0-5;
y1=y0+30;
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x1,y1);
}
void TMainForm::Draw_Menus(TCanvas *pCanvas)
{
int i;
int x0,y0,x1,y1;
x0=25;
y0=75;
x1=x0+20;
y1=75;
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x1,y1);
}
void TMainForm::Disp_Number(void)
{
unsigned char Valve_Code[12];
unsigned char Number[4];
Disp_HexToDec(m_Set_Num+1,Valve_Code);
Disp_Process_Data(4,Valve_Code);
Number[0]=Valve_Code[0];
Number[1]=Valve_Code[1];
Number[2]=Valve_Code[2];
Number[3]=Valve_Code[3];
Disp_Num(Number);
}
void TMainForm::Disp_HexToDec(unsigned long f,unsigned char Data[12])
{
unsigned int d[6];
int i,j;
unsigned int o=10000;
unsigned int c[6];
if(f>=100000) f=99999;
for(i=0;i<5;i++)
{
d[4-i]=(unsigned int)(f/o);
f=f-d[4-i]*o;
o=o/10;
}
for(i=0;i<5;i++)
{
j=d[i];
// c[i]=m_Code[j];
Data[i*2]=m_Code[j][0];
Data[i*2+1]=m_Code[j][1];
// Data[i]=d[i];
}
}
void TMainForm::Disp_HexToDecM(unsigned int f,unsigned char Data[6])
{
unsigned int d[6];
int i,j;
unsigned int o=10000;
unsigned int c[6];
for(i=0;i<5;i++)
{
d[i]=(unsigned int)(f/o);
f=f-d[i]*o;
o=o/10;
}
for(i=0;i<5;i++)
{
Data[i]=d[i]+0x30;
}
}
int TMainForm::Disp_Process_Data(unsigned int f,unsigned char Data[12])
{
int i;
int j;
j=(f+2)*2-1;
for(i=9;i>=j;i-=2)
{
if(Data[i]==m_Code[0][1] && Data[i-1]==m_Code[0][0])
{
Data[i]=0x00;
Data[i-1]=0x00;
}
else
return(i);
}
return(i);
}
void TMainForm::Disp_Data(char Data[12])
{
//TODO: Add your source code here
//低層顯示,顯示數據,顯示Data[6]中的6個字符
//單片機中需修改為液晶顯示
TCanvas *pCanvas;
pCanvas=PaintBox1->Canvas;
int x0,y0,x1,y1;
x0=PaintBox1->Left;
y0=PaintBox1->Top;
x1=PaintBox1->Left+Width;
y1=PaintBox1->Height+Top;
pCanvas->Pen->Color=clBtnFace;
pCanvas->Pen->Style=psSolid;
pCanvas->Brush->Color=clBtnFace;
pCanvas->Brush->Style=bsSolid;
pCanvas->Rectangle(x0,y0,x1,y1);
int i,d[6];
for(i=0;i<6;i++)
d[i]=Data[i];
pCanvas->Pen->Color=clBlack;
pCanvas->Pen->Style=psSolid;
pCanvas->Pen->Width=5;
/*
if(Data[5]&0x01)
Draw_UP_Arrow(pCanvas);
if(Data[5]&0x02)
Draw_DN_Arrow(pCanvas);
if(Data[5]&0x04)
Draw_Menus(pCanvas);
if(Data[5]&0x08)
Draw_Circle(pCanvas);
*/
Draw_Data(4,Data[0],Data[1],pCanvas);
Draw_Data(3,Data[2],Data[3],pCanvas);
Draw_Data(2,Data[4],Data[5],pCanvas);
Draw_Data(1,Data[6],Data[7],pCanvas);
Draw_Data(0,Data[8],Data[9],pCanvas);
}
//顯示譯碼程序
//輸入的是六個字符,輸出為18個碼
void TMainForm::Disp_State(unsigned char Data[6])
{
//TODO: Add your source code here
//輸入的是六個字符,輸出為18個碼
int i,s;
int wei[5]={0,4,7,11,14};
char D_Code[18];
for(i=0;i<18;i++)
D_Code[i]=0;
//字符譯碼與顯示
//共18位碼,T5為根號,T1為小圓
for(i=0;i<5;i++)
{
//大寫字母
if(Data[i]>='A' && Data[i]<='Z')
s=Data[i]-'A'+10;
else if(Data[i]>=0x30 && Data[i]<0x030+10)
s=Data[i]-0x30;
else if(Data[i]>='a' && Data[i]<'a'+26)
s=Data[i]-'a'+10+26;
D_Code[wei[i]+0]=m_CodeM[s][0];
D_Code[wei[i]+1]=m_CodeM[s][1];
D_Code[wei[i]+2]=m_CodeM[s][2];
if(i/2*2==i)
D_Code[wei[i]+3]|=(m_CodeM[s][3])<<2;
else
D_Code[wei[i]+6]|=m_CodeM[s][3];
}
//根號顯示
if(Data[5]&0x01)
D_Code[3]|=0x02;
//上小圓顯示
if(Data[5]&0x02)
D_Code[3]|=0x01;
Disp_State_All(D_Code);
}
void TMainForm::Disp_State_All(char D_Code[])
{
//TODO: Add your source code here
//輸入的是六個字符,輸出為18個碼
int x0,y0,x1,y1,i,s;
char d[4];
int wei[5]={0,4,7,11,14};
TCanvas *pCanvas;
pCanvas=PaintBox3->Canvas;
x0=0;
y0=0;
x1=Width;
y1=Height;
pCanvas->Pen->Color=clBtnFace;
pCanvas->Pen->Style=psSolid;
if(CheckBox1->Checked==false)
pCanvas->Brush->Color=clBtnFace;
else
pCanvas->Brush->Color=clRed;
pCanvas->Brush->Style=bsSolid;
pCanvas->Rectangle(x0,y0,x1,y1);
pCanvas->Pen->Color=clBlack;
pCanvas->Pen->Style=psSolid;
pCanvas->Pen->Width=3;
pCanvas->Pen->Color=clBlack;
pCanvas->Pen->Style=psSolid;
pCanvas->Pen->Width=3;
x0=10;
y0=60;
//字符譯碼與顯示
//共18位碼,T5為根號,T1為小圓
for(i=0;i<5;i++)
{
d[0]=D_Code[wei[i]+0];
d[1]=D_Code[wei[i]+1];
d[2]=D_Code[wei[i]+2];
if(i/2*2==i)
d[3]=D_Code[wei[i]+3]>>2;
else
d[3]=D_Code[wei[i]+6];
Draw_State(i,d,pCanvas);//顯示
}
//根號顯示
if(D_Code[3]&0x02)
{
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x0+10,y0);
pCanvas->LineTo(x0+15,y0+10);
pCanvas->LineTo(x0+17,y0-20);
pCanvas->LineTo(x0+30,y0-20);
}
//上小圓顯示
if(D_Code[3]&0x01)
{
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x0+10,y0);
pCanvas->LineTo(x0+15,y0+10);
pCanvas->LineTo(x0+17,y0-20);
pCanvas->LineTo(x0+30,y0-20);
}
}
void TMainForm::Draw_Data(unsigned char n,char data1,char data2,TCanvas *pCanvas)
{
int i;
int w=35,j=55,cx=100;
int h=40,cy=40;
int x0,y0,x1,y1;
//a
x0=n*j+cx;
y0=cy;
x1=x0+w;
y1=y0;
if(data1&0x08)
{
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x1,y1);
}
//b
x0=x1;
y0=y1;
x1=x0-5;
y1=y0+h;
if(data1&0x04)
{
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x1,y1);
}
//c
x0=x1;
y0=y1;
x1=x0-5;
y1=y0+h;
if(data1&0x02)
{
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x1,y1);
}
//d
x0=x1;
y0=y1;
x1=x0-w;
y1=y0;
if(data1&0x01)
{
pCanvas->MoveTo(x0,y0);
pCanvas->LineTo(x1,y1);
}
//e
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -