电子万年历代码.docx
《电子万年历代码.docx》由会员分享,可在线阅读,更多相关《电子万年历代码.docx(59页珍藏版)》请在冰豆网上搜索。
电子万年历代码
//====================================================================================
//文件名:
Calendar_Interface.c
//功能描述:
月历界面
//维护记录:
2007年6月17日
#include"SystemHeader.h"
#include"string.h"
DATECalendar_Date[31];
CALENDAR*pCalendar;
//=============================================================
//语法格式:
INT8Calendar_Month(INT16Year,INT16Month)
//实现功能:
(内部函数)对指定月中的每天进行计算,填充Calendar_Date数组
//参数:
Year:
年
//Month:
月
//返回值:
无
{
INT8Ret;
INT16i;
Ret=Date_GetMonthDays(Year,Month);
for(i=1;i<=Ret;i++)
if(Date_Generate(Year,Month,i,&Calendar_Date[i-1])!
=0)
break;
}
if(i<=Ret)Ret=-1;
returnRet;
voidCalendar_Show(CALENDAR*pCalendarWindow,INT16Year,INT16Month)
显示月历
pCalendarWindow:
月历配置结构体
//Year:
INT16Tempx,Tempy,TempColor,i;
INT8Days;
INT8TempStr[20];
STR_WINDOWwCalendar;
STR_FONTFontCn12={12,12,RES_HZK12};
STR_FONTFontAsc24={12,24,RES_ASC24};
CLOCKNow;
INT8*T_WeekdayStr[]={
"日","一","二","三","四","五","六"
};
pCalendar=pCalendarWindow;
Days=Calendar_Month(Year,Month);
TFT_CreateWindow(&wCalendar,0,0,319,239,0);
TFT_LoadAsciiFont(&wCalendar,&FontAsc24);
TFT_LoadChineseFont(&wCalendar,&FontCn12);
TFT_PutBitMap(&wCalendar,0,0,pCalendar->BGImage);//背景图片
TFT_SetChineseFont(&wCalendar,0);//题头
TFT_SetAsciiFont(&wCalendar,0);
TFT_SetColor(&wCalendar,pCalendar->HeadColor);
TFT_SetBGColor(&wCalendar,0);
TFT_SetTextPos(&wCalendar,20,0);
TFT_Print(&wCalendar,"%d年%d月",Year,Month);
TFT_SetTextPos(&wCalendar,120,0);
TFT_Print(&wCalendar,"农历%s年(%s年)",Calendar_Date[0].GanZhiYearStr,Calendar_Date[0].AnimalStr);
TFT_SetColor(&wCalendar,pCalendar->TableHeadColor);//星期
for(i=0;i<7;i++)
Tempx=((7-pCalendar->FirstWeekDay+i)%7)*40+12;
TFT_SetTextPos(&wCalendar,Tempx,24);
TFT_Print(&wCalendar,"%s",T_WeekdayStr[i]);
Tempy=41;
TFT_SetAsciiFont(&wCalendar,1);
TFT_SetChineseFont(&wCalendar,1);
for(i=0;i{Clock_Get(&Now);if(Year==Now.Year&&Month==Now.Mon&&i==Now.Day-1)//今日{Tempx=((7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7)*40+1;TFT_SetColor(&wCalendar,pCalendar->TodayColor);TFT_Rectangle(&wCalendar,Tempx,Tempy,Tempx+38,Tempy+38,PAINT_SOLID);}TempColor=pCalendar->CommonColor;if(Calendar_Date[i].Weekday==0||Calendar_Date[i].Weekday==6)TempColor=pCalendar->WeekendColor;if((Month==1&&i==0)//元旦、五一、十一、春节||(Month==5&&i==0)||(Month==10&&i==0)||(Calendar_Date[i].LunarMonth==1&&Calendar_Date[i].LunarDay==1)){TempColor=pCalendar->WeekendColor;}if(i<9)//一位数Tempx=((7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7)*40+14;else//两位数Tempx=((7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7)*40+8;TFT_SetTextPos(&wCalendar,Tempx,Tempy);TFT_SetColor(&wCalendar,TempColor);TFT_Print(&wCalendar,"%d",i+1);TempColor=pCalendar->LunarColor;if((Calendar_Date[i].Fu&0x00FF)==1)//伏{strcpy(TempStr,Calendar_Date[i].FuStr);TempStr[4]='\0';TempColor=pCalendar->SpecialColor;}if((Calendar_Date[i].Jiu&0x00FF)==1)//九{strcpy(TempStr,Calendar_Date[i].JiuStr);TempStr[4]='\0';TempColor=pCalendar->SpecialColor;}if(Calendar_Date[i].SolarTerm!=-1)//节气{TempColor=pCalendar->SpecialColor;strcpy(TempStr,Calendar_Date[i].SolarTermStr);}if(Calendar_Date[i].LunarFestivalStr[0]!='\0')//农历节日{TempColor=pCalendar->SpecialColor;strcpy(TempStr,Calendar_Date[i].LunarFestivalStr);}if(Calendar_Date[i].FestivalStr[0]!='\0')//公历节日{TempColor=pCalendar->SpecialColor;strcpy(TempStr,Calendar_Date[i].FestivalStr);}if(TempColor==pCalendar->LunarColor)//普通农历{if(Calendar_Date[i].LunarDay==1)//初一显示月号{strcpy(TempStr,Calendar_Date[i].LunarMonthStr);if(strlen(TempStr)<=4)strcat(TempStr,"月");}elsestrcpy(TempStr,Calendar_Date[i].LunarDayStr);}if(strlen(TempStr)==4)//两个字Tempx=(7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7*40+8;else//三个字Tempx=(7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7*40+2;TFT_SetColor(&wCalendar,TempColor);TFT_SetTextPos(&wCalendar,Tempx,Tempy+24);TFT_Print(&wCalendar,TempStr);if(Calendar_Date[i].Weekday==(pCalendar->FirstWeekDay+6)%7)//换行{Tempy+=40;if(Tempy>=240)Tempy=41;}}}//=============================================================//语法格式:INT16Calendar_GetKey(INT16x,INT16y)//实现功能:判断坐标是否落在功能按钮上//参数:x:x坐标//y:y坐标//返回值:键值//=============================================================INT16Calendar_GetKey(INT16x,INT16y){INT16Tempx,Tempy;INT16Ret=-1;Tempx=x;Tempy=y;if(Tempx>=0&&Tempx<280&&Tempy>=40&&Tempy<240)//日历区域{Ret=Tempx/40+(Tempy-40)/40*7;}elseif(Tempx>=283&&Tempx<=316&&Tempy>=4&&Tempy<=37)//前一年Ret=100;elseif(Tempx>=283&&Tempx<=316&&Tempy>=44&&Tempy<=77)//后一年Ret=101;elseif(Tempx>=283&&Tempx<=316&&Tempy>=91&&Tempy<=124)//后一月Ret=102;elseif(Tempx>=283&&Tempx<=316&&Tempy>=131&&Tempy<=164)//后一月Ret=103;elseif(Tempx>=283&&Tempx<=316&&Tempy>=196&&Tempy<=229)//返回Ret=104;returnRet;}//=============================================================//语法格式:INT16Calendar_GetKey(INT16x,INT16y)//实现功能:判断坐标是否落在功能按钮上//参数:x:x坐标//y:y坐标//返回值:键值//=============================================================voidCalendar_ShowDay(CALENDAR*pCalendar,INT16Key){STR_WINDOWwDay,wFestival;INT16x,y,Day,Temp;INT32i;DATE*pDate;INT8*T_WeekdayStr[]={"日","一","二","三","四","五","六"};Day=Key-Calendar_Date[0].Weekday+pCalendar->FirstWeekDay+1;if(Day<1)//检查3x号移动到第一行的情况{Temp=35-Calendar_Date[0].Weekday+pCalendar->FirstWeekDay;//最后一格的日期if(Date_GetMonthDays(Calendar_Date[0].Year,Calendar_Date[0].Month)>Temp)Day=Key+Temp+1;}if(Day<1||Day>Date_GetMonthDays(Calendar_Date[0].Year,Calendar_Date[0].Month))return;pDate=&Calendar_Date[Day-1];TFT_CreateWindow(&wDay,20,60,259,219,RGB(0xE0,0xE0,0xE0));TFT_SetColor(&wDay,RGB(0xF0,0x30,0x00));TFT_Rectangle(&wDay,0,0,239,159,PAINT_HOLLOW);TFT_SetColor(&wDay,COLOR_MAGENTA);TFT_SetTextPos(&wDay,10,10);TFT_Print(&wDay,"%4d年%d月%d日星期%s",pDate->Year,pDate->Month,pDate->Day,T_WeekdayStr[(unsignedchar)(pDate->Weekday)]);TFT_SetTextPos(&wDay,10,34);TFT_SetColor(&wDay,RGB(0x20,0x20,0x80));TFT_Print(&wDay,"星座:%s座",pDate->ZodiacStr);TFT_SetTextPos(&wDay,10,54);TFT_SetColor(&wDay,RGB(0x20,0x20,0x80));TFT_Print(&wDay,"生肖:%s",pDate->AnimalStr);TFT_SetTextPos(&wDay,10,74);TFT_SetColor(&wDay,RGB(0x20,0x20,0x80));TFT_Print(&wDay,"农历:%s月%s",pDate->LunarMonthStr,pDate->LunarDayStr);TFT_SetTextPos(&wDay,10,94);TFT_SetColor(&wDay,RGB(0x20,0x20,0x80));TFT_Print(&wDay,"干支:%s年%s月%s日",pDate->GanZhiYearStr,pDate->GanZhiMonthStr,pDate->GanZhiDayStr);TFT_CreateWindow(&wFestival,30,180,249,209,RGB(0xE0,0xE0,0xE0));TFT_SetTextPos(&wFestival,0,0);TFT_SetColor(&wFestival,COLOR_RED);if(pDate->FestivalStr[0]!='\0')TFT_Print(&wFestival,"%s",pDate->FestivalStr);if(pDate->LunarFestivalStr[0]!='\0')TFT_Print(&wFestival,"%s",pDate->LunarFestivalStr);if(pDate->SolarTerm!=-1)TFT_Print(&wFestival,"%s",pDate->SolarTermStr);if(pDate->Fu!=0)TFT_Print(&wFestival,"%s",pDate->FuStr);if(pDate->Jiu!=0)TFT_Print(&wFestival,"%s",pDate->JiuStr);for(i=0;i<1000000;i++);while(1){Touch_Get(&x,&y);if(x!=-1)break;}}//=============================================================//语法格式:voidCalendar_Interface(CALENDAR*pCalendar)//实现功能:月历界面//参数:pCalendar:月历配置结构体//返回值:无//=============================================================voidCalendar_Interface(CALENDAR*pCalendar){externINT16gFrameType;CLOCKClock;INT16Year,Month,x,y,Key;gFrameType=1;Clock_Get(&Clock);Year=Clock.Year;Month=Clock.Mon;Calendar_Show(pCalendar,Year,Month);while(1){Touch_Get(&x,&y);if(x!=-1){Key=Calendar_GetKey(x,y);switch(Key){case-1:break;case100://上年if(Year>1901)Year-=1;break;case101://下年if(Year<2100)Year+=1;break;case102://上月Month-=1;if(Month==0){Month=12;Year-=1;if(Year<1901){Year=1901;Month=1;}}break;case103://下月Month+=1;if(Month==13){Month=1;Year+=1;if(Year>2100){Year=2100;Month=12;}}break;case104://返回return;default:Calendar_ShowDay(pCalendar,Key);break;}if(Key!=-1)Calendar_Show(pCalendar,Year,Month);}}}……………………………………………………………………………………………………………………….闹铃部分。。。。。。。。。。。。。。。。
Clock_Get(&Now);
if(Year==Now.Year&&Month==Now.Mon&&i==Now.Day-1)//今日
Tempx=((7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7)*40+1;
TFT_SetColor(&wCalendar,pCalendar->TodayColor);
TFT_Rectangle(&wCalendar,Tempx,Tempy,Tempx+38,Tempy+38,PAINT_SOLID);
TempColor=pCalendar->CommonColor;
if(Calendar_Date[i].Weekday==0||Calendar_Date[i].Weekday==6)
TempColor=pCalendar->WeekendColor;
if((Month==1&&i==0)//元旦、五一、十一、春节
||(Month==5&&i==0)
||(Month==10&&i==0)
||(Calendar_Date[i].LunarMonth==1&&Calendar_Date[i].LunarDay==1))
if(i<9)//一位数
Tempx=((7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7)*40+14;
else//两位数
Tempx=((7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7)*40+8;
TFT_SetTextPos(&wCalendar,Tempx,Tempy);
TFT_SetColor(&wCalendar,TempColor);
TFT_Print(&wCalendar,"%d",i+1);
TempColor=pCalendar->LunarColor;
if((Calendar_Date[i].Fu&0x00FF)==1)//伏
strcpy(TempStr,Calendar_Date[i].FuStr);
TempStr[4]='\0';
TempColor=pCalendar->SpecialColor;
if((Calendar_Date[i].Jiu&0x00FF)==1)//九
strcpy(TempStr,Calendar_Date[i].JiuStr);
if(Calendar_Date[i].SolarTerm!
=-1)//节气
strcpy(TempStr,Calendar_Date[i].SolarTermStr);
if(Calendar_Date[i].LunarFestivalStr[0]!
='\0')//农历节日
strcpy(TempStr,Calendar_Date[i].LunarFestivalStr);
if(Calendar_Date[i].FestivalStr[0]!
='\0')//公历节日
strcpy(TempStr,Calendar_Date[i].FestivalStr);
if(TempColor==pCalendar->LunarColor)//普通农历
if(Calendar_Date[i].LunarDay==1)//初一显示月号
strcpy(TempStr,Calendar_Date[i].LunarMonthStr);
if(strlen(TempStr)<=4)
strcat(TempStr,"月");
else
strcpy(TempStr,Calendar_Date[i].LunarDayStr);
if(strlen(TempStr)==4)//两个字
Tempx=(7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7*40+8;
else//三个字
Tempx=(7-pCalendar->FirstWeekDay+Calendar_Date[i].Weekday)%7*40+2;
TFT_SetTextPos(&wCalendar,Tempx,Tempy+24);
TFT_Print(&wCalendar,TempStr);
if(Calendar_Date[i].Weekday==(pCalendar->FirstWeekDay+6)%7)//换行
Tempy+=40;
if(Tempy>=240)Tempy=41;
INT16Calendar_GetKey(INT16x,INT16y)
判断坐标是否落在功能按钮上
x:
x坐标
//y:
y坐标
键值
INT16Tempx,Tempy;
INT16Ret=-1;
Tempx=x;
Tempy=y;
if(Tempx>=0&&Tempx<280&&Tempy>=40&&Tempy<240)//日历区域
Ret=Tempx/40+(Tempy-40)/40*7;
elseif(Tempx>=283&&Tempx<=316&&Tempy>=4&&Tempy<=37)//前一年
Ret=100;
elseif(Tempx>=283&&Tempx<=316&&Tempy>=44&&Tempy<=77)//后一年
Ret=101;
elseif(Tempx>=283&&Tempx<=316&&Tempy>=91&&Tempy<=124)//后一月
Ret=102;
elseif(Tempx>=283&&Tempx<=316&&Tempy>=131&&Tempy<=164)//后一月
Ret=103;
elseif(Tempx>=283&&Tempx<=316&&Tempy>=196&&Tempy<=229)//返回
Ret=104;
voidCalendar_ShowDay(CALENDAR*pCalendar,INT16Key)
STR_WINDOWwDay,wFestival;
INT16x,y,Day,Temp;
INT32i;
DATE*pDate;
Day=Key-Calendar_Date[0].Weekday+pCalendar->FirstWeekDay+1;
if(Day<1)//检查3x号移动到第一行的情况
Temp=35-Calendar_Date[0].Weekday+pCalendar->FirstWeekDay;//最后一格的日期
if(Date_GetMonthDays(Calendar_Date[0].Year,Calendar_Date[0].Month)>Temp)
Day=Key+Temp+1;
if(Day<1||Day>Date_GetMonthDays(Calendar_Date[0].Year,Calendar_Date[0].Month))
return;
pDate=&Calendar_Date[Day-1];
TFT_CreateWindow(&wDay,20,60,259,219,RGB(0xE0,0xE0,0xE0));
TFT_SetColor(&wDay,RGB(0xF0,0x30,0x00));
TFT_Rectangle(&wDay,0,0,239,159,PAINT_HOLLOW);
TFT_SetColor(&wDay,COLOR_MAGENTA);
TFT_SetTextPos(&wDay,10,10);
TFT_Print(&wDay,"%4d年%d月%d日星期%s",pDate->Year,pDate->Month,pDate->Day,T_WeekdayStr[(unsignedchar)(pDate->Weekday)]);
TFT_SetTextPos(&wDay,10,34);
TFT_SetColor(&wDay,RGB(0x20,0x20,0x80));
TFT_Print(&wDay,"星座:
%s座",pDate->ZodiacStr);
TFT_SetTextPos(&wDay,10,54);
TFT_Print(&wDay,"生肖:
%s",pDate->AnimalStr);
TFT_SetTextPos(&wDay,10,74);
TFT_Print(&wDay,"农历:
%s月%s",pDate->LunarMonthStr,pDate->LunarDayStr);
TFT_SetTextPos(&wDay,10,94);
TFT_Print(&wDay,"干支:
%s年%s月%s日",pDate->GanZhiYearStr,pDate->GanZhiMonthStr,pDate->GanZhiDayStr);
TFT_CreateWindow(&wFestival,30,180,249,209,RGB(0xE0,0xE0,0xE0));
TFT_SetTextPos(&wFestival,0,0);
TFT_SetColor(&wFestival,COLOR_RED);
if(pDate->FestivalStr[0]!
='\0')
TFT_Print(&wFestival,"%s",pDate->FestivalStr);
if(pDate->LunarFestivalStr[0]!
TFT_Print(&wFestival,"%s",pDate->LunarFestivalStr);
if(pDate->SolarTerm!
=-1)
TFT_Print(&wFestival,"%s",pDate->SolarTermStr);
if(pDate->Fu!
TFT_Print(&wFestival,"%s",pDate->FuStr);
if(pDate->Jiu!
TFT_Print(&wFestival,"%s",pDate->JiuStr);
for(i=0;i<1000000;i++);
while
(1)
Touch_Get(&x,&y);
if(x!
voidCalendar_Interface(CALENDAR*pCalendar)
pCalendar:
externINT16gFrameType;
CLOCKClock;
INT16Year,Month,x,y,Key;
gFrameType=1;
Clock_Get(&Clock);
Year=Clock.Year;
Month=Clock.Mon;
Calendar_Show(pCalendar,Year,Month);
Key=Calendar_GetKey(x,y);
switch(Key)
case-1:
case100:
//上年
if(Year>1901)Year-=1;
case101:
//下年
if(Year<2100)Year+=1;
case102:
//上月
Month-=1;
if(Month==0)
Month=12;
Year-=1;
if(Year<1901)
Year=1901;
Month=1;
case103:
//下月
Month+=1;
if(Month==13)
Year+=1;
if(Year>2100)
Year=2100;
case104:
//返回
default:
Calendar_ShowDay(pCalendar,Key);
if(Key!
……………………………………………………………………………………………………………………….闹铃部分。
。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1