334 lines
7.4 KiB
C
334 lines
7.4 KiB
C
#include "main_inc.h"
|
|
#include "mywin_user_calendar.h"
|
|
|
|
|
|
|
|
|
|
#define WIN_CALENDAR_TYPE "WIN_CalendarStruct"
|
|
|
|
|
|
|
|
const static char g_weektxt[][3]={"日","一","二","三","四","五","六"};
|
|
const static char g_monthtxt[][5]={"一","二","三","四","五","六","七","八","九","十","十一","十二"};
|
|
|
|
|
|
void CALENDAR_Delete(WIN_CalendarStruct *cal);
|
|
|
|
|
|
|
|
//记录窗口句柄用于exit函数
|
|
static WIN_CalendarStruct *g_win_cal=0;
|
|
|
|
|
|
WIN_CalendarStruct *WIN_CreatCalendar (WIN_WindowStruct *base,
|
|
void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
|
|
int x,int y,int x_size,int y_size)
|
|
{
|
|
//重设消息循环
|
|
if (msgLoop==0)
|
|
{
|
|
msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))CALENDAR_DefaultMsgLoop;
|
|
}
|
|
|
|
WIN_CalendarStruct *ret=mymalloc (sizeof ( WIN_CalendarStruct));
|
|
//调用父类的构造函数
|
|
if (ret)
|
|
{
|
|
mymemset (ret,0,sizeof ( WIN_CalendarStruct));
|
|
// if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size))
|
|
if (0==WIN_CreatTouchEx((WIN_TouchWinStruct *)ret,base,msgLoop,x,y,x_size,y_size))
|
|
{
|
|
//创建失败
|
|
myfree (ret);
|
|
ret=0;
|
|
}
|
|
else
|
|
{
|
|
((WIN_WindowStruct *)ret)->winType=WIN_CALENDAR_TYPE;
|
|
((WIN_WindowStruct *)ret)->intercept=1;
|
|
((WIN_WindowStruct *)ret)->color=0xcdb69f;
|
|
((WIN_WindowStruct *)ret)->deleteWindow=(void (*)(struct _WIN_WindowStruct *win))CALENDAR_Delete;
|
|
|
|
//构造一个
|
|
ret->txtColor=0xd55805;
|
|
ret->selectRectColor=0x0000ff;
|
|
ret->backRectColor=0x221f1b;
|
|
ret->margin=0;
|
|
|
|
date_rtc_get_date (&ret->year,&ret->month,&ret->day);
|
|
ret->year_const=ret->year;
|
|
ret->month_const=ret->month;
|
|
|
|
int x=0;
|
|
int y=25;
|
|
int x_size=((WIN_WindowStruct *)ret)->x_size;
|
|
int y_size=((WIN_WindowStruct *)ret)->y_size-y;
|
|
ret->tip_y=0;
|
|
int x_step=x_size/7;
|
|
int y_step=y_size/7;
|
|
x+=(x_size-x_step*7)/2; //重新定位
|
|
y+=(y_size-y_step*7)/2;
|
|
|
|
for (int i=0;i<7;i++)
|
|
{
|
|
mymemcpy (ret->box[i].txt,(void *)g_weektxt[i],3);
|
|
ret->box[i].x=x+x_step*i;
|
|
ret->box[i].y=y;
|
|
ret->box[i].x_size=x_step;
|
|
ret->box[i].y_size=y_step;
|
|
}
|
|
y+=y_step;
|
|
for (int i=1;i<7;i++)
|
|
{
|
|
for (int j=0;j<7;j++)
|
|
{
|
|
ret->box[(i*7)+j].x=x+x_step*j;
|
|
ret->box[(i*7)+j].y=y;
|
|
ret->box[(i*7)+j].x_size=x_step;
|
|
ret->box[(i*7)+j].y_size=y_step;
|
|
}
|
|
y+=y_step;
|
|
}
|
|
CALENDAR_Refresh(ret);
|
|
}
|
|
}
|
|
|
|
global_run_start();
|
|
g_win_cal=ret;
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
void CALENDAR_Delete(WIN_CalendarStruct *cal)
|
|
{
|
|
CALL_BACK_ENTER();
|
|
WIN_DeleteWindow ( (WIN_WindowStruct *)cal);
|
|
g_win_cal=0;
|
|
global_run_exit();
|
|
CALL_BACK_EXIT();
|
|
}
|
|
|
|
|
|
int __app_exit(void *ptr)
|
|
{
|
|
CALL_BACK_ENTER();
|
|
if(g_win_cal)
|
|
CALENDAR_Delete(g_win_cal);
|
|
CALL_BACK_EXIT();
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
//设置标题
|
|
void CALENDAR_SetTitle (WIN_CalendarStruct *calendar,char *txt)
|
|
{
|
|
mymemcpy (calendar->title,txt,strlen(txt)+1);
|
|
}
|
|
|
|
|
|
|
|
//索引增加
|
|
void CALENDAR_IndexAdd (WIN_CalendarStruct *calendar)
|
|
{
|
|
calendar->month++;
|
|
if (calendar->month>12)
|
|
{
|
|
calendar->year++;
|
|
calendar->month=1;
|
|
}
|
|
CALENDAR_Refresh(calendar);
|
|
}
|
|
|
|
//索引减少
|
|
void CALENDAR_IndexSub (WIN_CalendarStruct *calendar)
|
|
{
|
|
calendar->month--;
|
|
if (calendar->month<1)
|
|
{
|
|
calendar->year--;
|
|
calendar->month=12;
|
|
}
|
|
CALENDAR_Refresh (calendar);
|
|
}
|
|
|
|
//刷新
|
|
void CALENDAR_Refresh (WIN_CalendarStruct *calendar)
|
|
{
|
|
int week=date_get_week_by_day (calendar->year,calendar->month,1);
|
|
int dayMax=date_get_month_day_max (calendar->year,calendar->month);
|
|
if (week==7) week=0; //星期天在最前
|
|
|
|
//清除以前的
|
|
for (int i=7;i<7*7;i++)
|
|
{
|
|
calendar->box[i].txt[0]=0;
|
|
calendar->box[i].select=0;
|
|
}
|
|
//填入现在的日历
|
|
for (int i=0;i<dayMax;i++)
|
|
{
|
|
sprintf (calendar->box[i+7+week].txt,"%d",i+1);
|
|
if ((i+1==calendar->day)&&(calendar->month==calendar->month_const)&&(calendar->year==calendar->year_const))
|
|
{
|
|
calendar->box[i+7+week].select=1;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//默认绘制函数
|
|
void CALENDAR_DefaultPaint (WIN_CalendarStruct *calendar)
|
|
{
|
|
|
|
int x=0;
|
|
int y=0;
|
|
int x_size=((WIN_WindowStruct *)calendar)->x_size;
|
|
int y_size=((WIN_WindowStruct *)calendar)->y_size;
|
|
|
|
WIN_PaintBackGround ((WIN_WindowStruct *)calendar);
|
|
u32 font=WIN_SetFontSize(21);
|
|
|
|
//显示日历
|
|
char txt_buf[20]={0};
|
|
int txt_len=0;
|
|
int font_type=21;
|
|
WIN_SetFontSize(font_type);
|
|
sprintf (txt_buf,"%s月",g_monthtxt[calendar->month-1]);
|
|
WIN_SetLcdColor (calendar->txtColor);
|
|
WIN_DrawTxtAt (txt_buf,0,calendar->tip_y);
|
|
txt_len=strlen(txt_buf);
|
|
WIN_SetFontSize(16);
|
|
sprintf (txt_buf,"%d",calendar->year);
|
|
WIN_DrawTxtAt(txt_buf,txt_len*font_type/2,font_type-16);
|
|
|
|
|
|
for (int i=0;i<7*7;i++)
|
|
{
|
|
if (calendar->box[i].txt[0])
|
|
{
|
|
if (calendar->box[i].select==1)
|
|
{
|
|
WIN_SetLcdColor (calendar->selectRectColor);
|
|
WIN_FillRectByColorAlpha (calendar->box[i].x,calendar->box[i].y,calendar->box[i].x_size,calendar->box[i].y_size,16);
|
|
}
|
|
if (i%7==0)
|
|
WIN_SetLcdColor (calendar->txtColor);
|
|
else
|
|
WIN_SetLcdColor (((WIN_WindowStruct *)calendar)->color);
|
|
WIN_DrawTxtHCenterAt (calendar->box[i].txt,calendar->box[i].x+calendar->box[i].x_size/2,
|
|
calendar->box[i].y+calendar->box[i].y_size/2-WIN_GetFontHight()/2);
|
|
}
|
|
}
|
|
WIN_SetFontSize(font);
|
|
|
|
}
|
|
|
|
|
|
//默认消息处理函数
|
|
void CALENDAR_DefaultMsgLoop (WIN_CalendarStruct *calendar,WIN_MsgStruct *msg)
|
|
{
|
|
CALL_BACK_ENTER();
|
|
WIN_KeyStruct *k=0;
|
|
switch (msg->msg)
|
|
{
|
|
case WIN_MSG_PAINT:
|
|
CALENDAR_DefaultPaint(calendar);
|
|
break;
|
|
case WIN_MSG_INIT:
|
|
{
|
|
int x_size=((WIN_WindowStruct *)calendar)->x_size;
|
|
int y_size=((WIN_WindowStruct *)calendar)->y_size;
|
|
// calendar->key_back=WIN_CreatButton(((WIN_WindowStruct *)calendar),0,x_size-65,0,65,30);
|
|
// BUTTON_SetKeyString(calendar->key_back,"返回");
|
|
// calendar->key_sub=WIN_CreatButton(((WIN_WindowStruct *)calendar),0,x_size/4-65/2,calendar->tip_y,65,30);
|
|
// BUTTON_SetKeyString(calendar->key_sub,"<<");
|
|
// calendar->key_add=WIN_CreatButton(((WIN_WindowStruct *)calendar),0,x_size*3/4-65/2,calendar->tip_y,65,30);
|
|
// BUTTON_SetKeyString(calendar->key_add,">>");
|
|
}
|
|
break;
|
|
case WIN_MSG_KEY:
|
|
k=msg->data.p;
|
|
if (k->shortPress&KEY_VALUE_UP)//短按
|
|
{
|
|
CALENDAR_IndexAdd (calendar);
|
|
}
|
|
else if (k->shortPress&KEY_VALUE_DOWN)
|
|
{
|
|
CALENDAR_IndexSub (calendar);
|
|
}
|
|
if (k->shortPress&KEY_VALUE_HOME)
|
|
{
|
|
//返回
|
|
((WIN_WindowStruct *)calendar)->deleteWindow((WIN_WindowStruct *)calendar);
|
|
break;
|
|
}
|
|
if (k->shortPress)
|
|
{
|
|
WIN_SetInvalid ((WIN_WindowStruct *)calendar);
|
|
}
|
|
break;//case WIN_MSG_KEY:
|
|
case WIN_MSG_CHID:
|
|
switch (msg->data.v)
|
|
{
|
|
case CHID_DELETE:
|
|
break;
|
|
case CHID_USER:
|
|
{
|
|
if (msg->data2.v==BUTTON_PRESSED)
|
|
{
|
|
if (msg->srcWin==calendar->key_back)
|
|
{
|
|
//返回
|
|
((WIN_WindowStruct *)calendar)->deleteWindow((WIN_WindowStruct *)calendar);
|
|
}
|
|
else if (msg->srcWin==calendar->key_add)
|
|
{
|
|
CALENDAR_IndexAdd (calendar);
|
|
}
|
|
else if (msg->srcWin==calendar->key_sub)
|
|
{
|
|
CALENDAR_IndexSub (calendar);
|
|
}
|
|
WIN_SetInvalid ((WIN_WindowStruct *)calendar);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)calendar,msg);
|
|
break;
|
|
}
|
|
CALL_BACK_EXIT();
|
|
}
|
|
|
|
|
|
|
|
//查看日期
|
|
WIN_CalendarStruct *CALENDAR_SelectDate (WIN_WindowStruct *base)
|
|
{
|
|
WIN_CalendarStruct *ret=0;
|
|
if (base)
|
|
{
|
|
ret=WIN_CreatCalendar (base,0,0,0,base->x_size,base->y_size);
|
|
}
|
|
else
|
|
{
|
|
ret=WIN_CreatCalendar (0,0,0,0,WIN_GetBaseWindow()->x_size,WIN_GetBaseWindow()->y_size);
|
|
}
|
|
WIN_SetBackPic ((WIN_WindowStruct *)ret);
|
|
CALENDAR_SetTitle (ret,"日历");
|
|
WIN_ShowWindow((WIN_WindowStruct*)ret);
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|