📄 clock.c
字号:
}
void CoverOldMinhand(U32 hGC,U8 x,U8 y,double handlen)
{
double diffangle = 2*pi*(7.0/360);
double angle;
double tarx,tary,mleftx,mlefty,mrightx,mrighty;
angle = ((oldmin*2*pi)/60 - pi/2);
tarx = (x+handlen*cos(angle));tary = (y+handlen*sin(angle));
//DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
//DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
angle = ((oldmin*2*pi)/60-diffangle - pi/2);
mleftx =(x+0.3*handlen*cos(angle));
mlefty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_XOR_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
//刷新残余点
// DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
// DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_XOR_STYLE );
angle =((oldmin*2*pi)/60+diffangle - pi/2);
mrightx =(x+0.3*handlen*cos(angle));
mrighty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_XOR_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
// DrawLine( hGC, GPC_BLACK,mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
// DrawLine( hGC, GPC_BLACK,mrightx, mrighty,tarx,tary,GPC_SOLID_LINE, GPC_XOR_STYLE );
}
void CoverOldSechand(U32 hGC,U8 x,U8 y,double handlen)
{
double diffangle = 2*pi*(13.0/360);
double angle;
double tarx,tary; //,mleftx,mlefty,mrightx,mrighty;
angle = ((oldsec*2*pi)/60 - pi/2);
tarx = (x+handlen*cos(angle));tary = (y+handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
/*
angle = ((oldsec*2*pi)/60-diffangle - pi/2);
mleftx =(x+0.5*handlen*cos(angle));
mlefty =(y+0.5*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_XOR_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
//刷新残余点
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_XOR_STYLE );
angle =((oldsec*2*pi)/60+diffangle - pi/2);
mrightx =(x+0.5*handlen*cos(angle));
mrighty =(y+0.5*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_XOR_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
DrawLine( hGC, GPC_BLACK,mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,mrightx, mrighty,tarx,tary,GPC_SOLID_LINE, GPC_XOR_STYLE );
*/
}
void DrawNewSechand(U32 hGC,U8 x,U8 y,double handlen)
{
double diffangle = 2*pi*(13.0/360);
double angle;
double tarx,tary;//,mleftx,mlefty,mrightx,mrighty;
angle = ((timeParamPtr->second*2*pi)/60 - pi/2);
tarx = (x+handlen*cos(angle));tary = (y+handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
/*
angle = ((timeParamPtr->second*2*pi)/60-diffangle - pi/2);
mleftx =(x+0.5*handlen*cos(angle));
mlefty =(y+0.5*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
angle =((timeParamPtr->second*2*pi)/60+diffangle - pi/2);
mrightx =(x+0.5*handlen*cos(angle));
mrighty =(y+0.5*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
*/
}
void DrawClkPoint(U32 hGC,U8 x,U8 y,double len)
{
U8 i;
double tarx,tary;
double angle;
//SetDotWidth( hGC, 2, NULL);
/*DrawCircle(hGC, GPC_BLACK, x, y, len, GPC_REPLACE_STYLE );
for (i=0;i<60;i++)
{
angle =( i*2*pi)/60- pi/2;
tarx = x+ 1.1*len* cos(angle);tary = y +1.1*len*sin(angle);
// if((i%15) ==0)
// DrawCircle(hGC, GPC_BLACK, tarx, tary, 2, GPC_REPLACE_STYLE );
DrawLine(hGC, GPC_BLACK, x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE);
}
DrawCircle(hGC, GPC_BLACK, x, y, len, GPC_XOR_STYLE );
*/
//SetDotWidth( hGC, 1, NULL);
for (i=0;i<60;i+=5)
{
angle =( i*2*pi)/60- pi/2;
tarx = x+ len* cos(angle);tary = y +len*sin(angle);
DrawCircle(hGC, GPC_BLACK, tarx, tary, 1, GPC_REPLACE_STYLE );
// DrawDot(hGC, GPC_BLACK, tarx, tary, GPC_REPLACE_STYLE);
}
}
void TimePrint(U32 hGC)
{
U8 flag = 0;
U8 *ptr1 = "点 分 秒";
//U8 hourhandold = 0;
const U8 x = cocx,y = cocy-35;
const double lenclock = x *0.75;
const double r_sec =lenclock*0.93,r_min=lenclock*0.85, r_hour=lenclock*0.7;
double tarx =0,tary=0;
//U16 Tmptime = 0,oldhourtime=0,oldmintime=0 ;//none of useage
//double angle;
//caculate clock time
timeParamPtr = &TimeParam;
flag =( timeParamPtr->second)/60;
(timeParamPtr->second) %=60;
(timeParamPtr->minute) += flag;
flag = (timeParamPtr->minute)/60;
(timeParamPtr->minute) %= 60;
(timeParamPtr->hour) += flag;
flag = (timeParamPtr->hour)/24;
(timeParamPtr->hour) %= 24;
//initial clock paint
if (firstprint == 0)
{
//draw clock circle and point
// DrawCircle(hGC, GPC_BLACK, x, y, lenclock, GPC_REPLACE_STYLE );
DrawClkPoint(hGC, x, y, lenclock);
DrawNewSechand( hGC, x, y, r_sec);
DrawNewMinhand(hGC, x, y, r_min);
DrawNewHourhand(hGC, x,y, r_hour);
DrawCircle(hGC, GPC_BLACK, x, y,3, GPC_REPLACE_STYLE );
DrawText(hGC, ptr1, 50,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
DrawText(hGC, GetASIIStr(timeParamPtr->hour), 35,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
DrawText(hGC, GetASIIStr(timeParamPtr->minute), 65,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
DrawText(hGC,GetASIIStr(timeParamPtr->second) , 94,160,150,220, \
HZK_16X16_FONT, GPC_BLACK,GPC_REPLACE_STYLE);
oldhour = timeParamPtr->hour;
oldmin = timeParamPtr->minute;
oldsec = timeParamPtr ->second;
firstprint = 1;
}
if (oldhour != timeParamPtr->hour)
{
DrawText(hGC, GetASIIStr(oldhour), 35,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_XOR_STYLE);
DrawText(hGC, GetASIIStr(timeParamPtr->hour), 35,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
}
if (oldmin != timeParamPtr->minute)
{
DrawText(hGC, GetASIIStr(oldmin), 65,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_XOR_STYLE);
DrawText(hGC, GetASIIStr(timeParamPtr->minute), 65,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
CoverOldMinhand(hGC, x, y, r_min);
CoverOldHourhand(hGC, x, y, r_hour);
/*
CoverOldMinhand(hGC, x, y, r_min);
DrawNewMinhand(hGC, x, y, r_min);
//move hourhand with minutehand moving every 12 min
if ((timeParamPtr->minute%12) == 0)
{
CoverOldHourhand(hGC, x, y, r_hour);
DrawNewHourhand(hGC, x, y, r_hour);
}
*/
// because maybe minhand cover hourhand,so should compansate it****
//*************************************it need modify
#if 0
if(oldmin ==( timeParamPtr->hour%12)*5)
{
angle = (((timeParamPtr->hour%12)*2*pi)/12- pi/2);
tarx = (x+r_hour*cos(angle));tary = (y+r_hour*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
}
//************************************************
#endif
//oldmin = timeParamPtr->minute;
}
if (oldsec != timeParamPtr->second)
{
CoverOldSechand( hGC, x, y, r_sec);
DrawNewSechand( hGC, x, y, r_sec);
DrawNewMinhand(hGC, x, y, r_min);
//move hourhand with minutehand moving every 12 min
// if ((timeParamPtr->minute%12) == 0)
// {
DrawNewHourhand(hGC, x, y, r_hour);
// }
DrawCircle(hGC, GPC_BLACK, x, y, 3, GPC_REPLACE_STYLE );
//it need think deeply!!!!!!
//because secondhand may cover minhand and hourhand,so should compansate
//***************************************************
//********************************************it need modify
#if 0
if ((timeParamPtr->hour%12)*5 == oldsec)
{
angle = ((oldsec*2*pi)/60 - pi/2);
tarx = (x+r_hour*cos(angle));tary = (y+r_hour*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
}
#endif
//*********************************************
/*
if (timeParamPtr->minute == oldsec)
{
if (oldsec == 59)
angle=0 -(1.0/60)*2*pi-pi/2;
else
angle = ((oldsec*2*pi)/60 - pi/2);
tarx = (x+r_min*cos(angle));tary = (y+r_min*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
}
//刷新59分59秒因为在此处有残影
if ((timeParamPtr->minute==0)&&(timeParamPtr->second==0))
{
//刷洗分针残影
angle=(59.0/60)*2*pi-pi/2;
tarx = (x+r_min*cos(angle));tary = (y+r_min*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
//刷新时针残影
angle= (((oldhour%12)*2*pi)/12 - pi/2)+(oldmin/12)*(2*pi/60);
tarx = (x+r_hour*cos(angle));tary = (y+r_hour*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
}
*/
DrawText(hGC,GetASIIStr(oldsec) , 94,160,150,220, \
HZK_16X16_FONT, GPC_BLACK,GPC_XOR_STYLE);
DrawText(hGC,GetASIIStr(timeParamPtr->second) ,94,160,150,220, \
HZK_16X16_FONT, GPC_BLACK,GPC_REPLACE_STYLE);
// oldsec = timeParamPtr ->second;
}
oldhour = timeParamPtr->hour;
oldsec = timeParamPtr ->second;
oldmin = timeParamPtr->minute;
}
void TimePrint1(U32 hGC)
{
U8 flag = 0;
U8 *ptr1 = "点 分 秒";
//U8 hourhandold = 0;
const U8 x = cocx,y = cocy-35;
const double lenclock = x *0.75;
const double r_sec =lenclock*0.93,r_min=lenclock*0.85, r_hour=lenclock*0.7;
double tarx =0,tary=0;
//U16 Tmptime = 0,oldhourtime=0,oldmintime=0 ;//none of useage
//double angle;
//caculate clock time
timeParamPtr = &TimeParam;
flag =( timeParamPtr->second)/60;
(timeParamPtr->second) %=60;
(timeParamPtr->minute) += flag;
flag = (timeParamPtr->minute)/60;
(timeParamPtr->minute) %= 60;
(timeParamPtr->hour) += flag;
flag = (timeParamPtr->hour)/24;
(timeParamPtr->hour) %= 24;
//initial clock paint
if (firstprint == 0)
{
DrawText(hGC, ptr1, 50,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
DrawText(hGC, GetASIIStr(timeParamPtr->hour), 35,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
DrawText(hGC, GetASIIStr(timeParamPtr->minute), 65,160,150,220, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
DrawText(hGC,GetASIIStr(timeParamPtr->second) , 94,160,150,220, \
HZK_16X16_FONT, GPC_BLACK,GPC_REPLACE_STYLE);
oldhour = timeParamPtr->hour;
oldmin = timeParamPtr->minute;
oldsec = timeParamPtr ->second;
firstprint = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -