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

📄 calendars.c

📁 使用C语言实现图文日历时钟
💻 C
📖 第 1 页 / 共 3 页
字号:
	//如果iYear年有闰月,则为13个月
    if(gLanarMonth[iYear - START_YEAR]) 
		month ++;
    //如果某月是三十天则days++
	while(month >=0 && (gLanarMonthDay[iYear - START_YEAR] & (1 << (16 - month))))
	{   
		days ++; 
	    month --;
	}
	return days;
	*/
	UINT16 days =0;
	for(i=1; i<=12; i++)
	{ 
        tmp = CAL_LunarMonthDays(iLunarYear ,i); 
		days += HIWORD(tmp);
		days += LOWORD(tmp);
	}
    return days;
}

void CAL_FormatLunarYear(UINT16  iYear, UINT8 *pBuffer)
{	
	UINT8 szText1[]="甲乙丙丁戊己庚辛壬癸";
	UINT8 szText2[]="子丑寅卯辰巳午未申酉戌亥";
	UINT8 szText3[]="鼠牛虎免龙蛇马羊猴鸡狗猪";

	memcpy(pBuffer,  szText1+((iYear-4)%10)*2,2);
	memcpy(pBuffer+2,szText2+((iYear-4)%12)*2,2);
	pBuffer[4]=' ';
	memcpy(pBuffer+5,szText3+((iYear-4)%12)*2,2);
	strcpy(pBuffer+7,"年");
}

void CAL_FormatMonth(UINT16 iMonth, UINT8 *pBuffer, BOOL bLunar)
{
   UINT8 szText[]="正二三四五六七八九十";

   if(!bLunar && iMonth==1)
   {
	   strcpy(pBuffer, "一月");
	   return;
   }

   if(iMonth<=10)
   {
       memcpy(pBuffer, szText + (iMonth -1)*2, 2);
       strcpy(pBuffer+2 , "月");
	   return;
   }
   if (iMonth == 11)
	   strcpy(pBuffer, "十一");
   else
	   strcpy(pBuffer, "十二");
    strcpy(pBuffer+4 , "月");  
}


void CAL_FormatLunarDay(UINT16  iDay, UINT8 *pBuffer)
{
    UINT8 szText1[]="初十廿三";
	UINT8 szText2[]="一二三四五六七八九十";
	if(iDay != 20 && iDay !=30)
	{
		memcpy(pBuffer, szText1 + (iDay-1)/10*2 ,2);
		memcpy(pBuffer+2, szText2 + ((iDay-1)%10)*2 ,2);
		pBuffer[4]='\0';
	}
	else
	{
        memcpy(pBuffer, szText1 + iDay/10*2, 2);
		strcpy(pBuffer+2, szText2 +18);
	}
}

void CAL_PaintChineseInfo(UINT16 x, UINT16 y, UINT16 iHolDay)
{
	UINT8 text[5];
    UINT8 *HolText[] ={"小寒", "大寒", "立春", "雨水",
		              "惊蛰", "春分", "清明", "谷雨",
					  "立夏", "小满", "芒种", "夏至",
                      "小暑", "大暑", "立秋", "处暑",
					  "白露", "秋分", "寒露", "霜降",
					  "立冬", "小雪", "大雪", "冬至"};

	if(iHolDay)
	{
	   strcpy(text, HolText[iHolDay-1]);
	   outtextxy(x, y, text); 
	}
}

BOOL   CAL_GetHoilday(UINT16 iMonth, UINT16 iDay, UINT16 lMonth, UINT16 lDay)
{
   if(iMonth==1&&iDay ==1)
   	  return TRUE;
   else if (iMonth==5&&(iDay==1||iDay==2||iDay==3))
   	  return TRUE;
   else if (iMonth==10&&(iDay==1||iDay==2||iDay==3))
   	  return TRUE;
   else if (iMonth==3 && iDay == 8)
   	  return TRUE;
   else if(lMonth ==1 && (lDay==1||lDay==2||lDay==3))
   	  return TRUE;
   return FALSE;
}

#undef COL_WIDTH
#undef ROW_HEIGHT
#undef TITLE_HEIGHT

static UINT8 calendarTitleString[32];
static T_OSGRect CalTitleRect =  {150, 90,400,42};
static T_OSGRect CalendarRect = {150,132,400,320};

static UINT32 CAL_DetailPaint(void)
{

  setfillstyle(0,NB_COLOR);
  bar(CalendarRect.x,CalendarRect.y, CalendarRect.x+CalendarRect.width, CalendarRect.y+CalendarRect.height);
  CAL_PaintTitle(CalendarRect);
  CAL_PaintDate(CalendarRect);

  return(APP_OK);  
}

static void CAL_UpdateTitle(void)
{
  UINT16 iLunarYear, iLunarMonth, iLunarDay;

  CAL_GetLunarDate(m_iYear, m_iMonth, m_iDay, &iLunarYear, &iLunarMonth, &iLunarDay);
  sprintf(calendarTitleString, "%4d", m_iYear);  
  strcat(&calendarTitleString[4], "年");
  sprintf(&calendarTitleString[6], "%2d", m_iMonth);
  strcat(&calendarTitleString[8], "月");
  strcat(&calendarTitleString[10], "    ");
  CAL_FormatLunarYear(iLunarYear, &calendarTitleString[14]);
  strcat(&calendarTitleString[23], " ");
  CAL_FormatMonth(iLunarMonth, &calendarTitleString[24], TRUE);
  if(iLunarMonth>10)
  {
    calendarTitleString[30]=0;
  }
  else
  {
    calendarTitleString[28]=0;  
  }
  setfont(FONT_24X24);
  DrawButtonItem(CalTitleRect.x, CalTitleRect.y, CalTitleRect.width, calendarTitleString, HT_COLOR, HB_COLOR, 0);
}


typedef struct
{
	UINT32 preColorSet;
	UINT32 createFlag;
} T_CalendarState;

T_CalendarState  CalendarState;

static UINT32 createCalendar(UINT32 flag)
{

  CalendarState.preColorSet	= MenuGetColorSet();
  CalendarState.createFlag	= flag;
  SetMenuColor(1);

  if(flag)
	 OsdHandle->CLUTP = FTACreatePalette(MenuGetOpacity(), PALETTEmainbar/*PALETTEicnsdbr*/);

  if(UTCGetCurrentDate())
  {
    UINT32 year, month, day, weekDay;

    UTCConvertMJDDate(UTCGetCurrentDate(), &year, &month, &day, &weekDay);	

    if( month > 12 )
    {
      year++; 
      month -= 12;
    }
    m_iYear = (UINT16)year;
    m_iMonth= (UINT16)month;
    m_iDay  = (UINT16)day;    
  }

  CAL_UpdateTitle();
  CAL_DetailPaint();

  return (APP_OK);

}

static UINT32 destroyCalendar(void)
{
   erase(CalTitleRect.x,  CalTitleRect.y,  CalTitleRect.width,  CalTitleRect.height);
   erase(CalendarRect.x, CalendarRect.y, CalendarRect.width, CalendarRect.height);
   SetMenuColor((UINT8)CalendarState.preColorSet);

   if(CalendarState.createFlag)
   	 return (APP_CLOSE_PARENT);
   else
     return (APP_CLOSE);
}

static UINT32 keyDown(void)
{
   m_iYear --;
   if(m_iYear==1900)
   	 m_iYear = 2050;    		
   CAL_UpdateTitle();
   CAL_DetailPaint();
   return (APP_OK);
}

static UINT32 keyUp(void)
{
   m_iYear ++;
   if(m_iYear>2050)
	 m_iYear = 1901;    		
   CAL_UpdateTitle();
   CAL_DetailPaint();
   return (APP_OK);
}

static UINT32 keyLeft(void)
{
   	m_iMonth--;
   	if(m_iMonth==0)
   	{
   		m_iMonth=12;
   		m_iYear --;
   		if(m_iYear==1900)
   			m_iYear = 2050;    		
   	}
    CAL_UpdateTitle();
    CAL_DetailPaint();
    return (APP_OK);
}

static UINT32 keyRight(void)
{
   	m_iMonth++;
   	if(m_iMonth>12)
   	{
   		m_iMonth=1;
   		m_iYear ++;
   		if(m_iYear>2050)
   			m_iYear = 1901;    		
   	}
    CAL_UpdateTitle();
    CAL_DetailPaint();
    return (APP_OK);
}

UINT32 HKCalendarEH(T_FTAEvent *event)
{
  UINT32 status = APP_OK;
    
  if (event->code == APP_CREATE)
  {
    status = createCalendar(event->param1);
  }
  else if (event->code == APP_DESTROY)
  {
    status = destroyCalendar();
  }
  else if (event->code == APP_INITIALIZE)
  {
  }
  else
  {  
      switch (event->code)
      {
        case UI_FP_MENU:
        case UI_IR_MENU:
        case UI_IR_CLEAR:
           status = destroyCalendar();
           break;
        case UI_FP_UP:
        case UI_IR_UP:
        	keyUp();
            break;
        case UI_FP_DOWN:
        case UI_IR_DOWN: 
        	keyDown();
		    break; 
        case UI_FP_LEFT:
        case UI_IR_LEFT:
        	keyLeft();
			break;
        case UI_FP_RIGHT:
        case UI_IR_RIGHT:
        	keyRight();
		    break;   
        case UI_FP_SELECT:
        case UI_IR_SELECT:
            break;
        case TIMER_1SEC:
            break;
        default:
            break;
      }                     
  }
  return(status); 
} 

⌨️ 快捷键说明

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