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

📄 calenui.c

📁 ct952 source code use for Digital Frame Photo
💻 C
📖 第 1 页 / 共 3 页
字号:
                _CALENDAR_SET_DATE.bMonth = _bCurrentMonth;
                _CALENDAR_SET_DATE.bDate = _bCurrentDate;

                _hCALENDARSetDate  = SETDATE_Create(&_CALENDAR_SET_DATE, &_CALENDAR_SET_DATE_Action);
                if (_hCALENDARSetDate != SETDATE_HANDLE_INVALID)
                {
                    SETDATE_Show(_hCALENDARSetDate, MAINMENU_PALETTE_ENTRY_CONTENT_REGION, __SetupInfo.bUIStyle-SETUP_CUSTOM_UI_STYLE_BEGIN);
                }
                break;
            case CALENDAR_MAIN_EXIT:
                CALENDAR_Exit(FALSE);
                POWERONMENU_BackToMainMenu();                        
                break;
            default:
                break;
            }            
        }
    }
    else if (_bCALENDARMode == CALENDAR_MODE_SET_DATE)
    {
        if ((__bKey == KEY_FUNCTION) || (__bKey == KEY_EXIT))
        {
            CALENDAR_Exit(TRUE);
            POWERONMENU_BackToMainMenu();            
        }
        SETDATE_ProcessKey(_hCALENDARSetDate, __bKey);
    }
#endif //SUPPORT_SET_DATE_BY_MENU
    else
    {
        switch (__bKey)
        {        
        case KEY_STOP: //go to the change month mode.
            if (_bCALENDARMode == CALENDAR_MODE_SETTING)
            {
                if(__bCalSelectMenuID==DATA_CHANGE)
                {
                    calendar_draw_item_HighLight(__bCalselectdata, FALSE);
                    __bCalSelectMenuID=YEAR_MONTH_CHANGE;
                    calendar_draw_title(TRUE);
                }
                else
                {
                    calendar_draw_title(FALSE);
                    __bCalSelectMenuID=DATA_CHANGE;
                    if(__bCalselectdata>_bLastDay)
                        __bCalselectdata=_bLastDay;
                    calendar_draw_item_HighLight(__bCalselectdata, TRUE);
                }
            }
            break;
        case KEY_DOWN:
            if (_bCALENDARMode == CALENDAR_MODE_DISPLAY_PERPETUAL_CALENDAR)
            {
                __bCalSelectMenuID = YEAR_MONTH_CHANGE;
            }

            if(__bCalSelectMenuID==YEAR_MONTH_CHANGE)
            {
                if(_bCurrentMonth>1)
                {
                    _bCurrentMonth--;
                }
                else
                {
                    if(_wCurrentYear>CAL_FIRSTYEAR)
                    {
                        _wCurrentYear--;
                        _bCurrentMonth = 12;
                    }
                }
                
                _bLastDay = Calendar_GetDaysofMonth(_wCurrentYear, _bCurrentMonth);
                calendar_draw_all();
            }
            else  if(__bCalSelectMenuID==DATA_CHANGE)
            {
                if(__bCalselectdata<=(_bLastDay-7))
                {
                    calendar_draw_item_HighLight(__bCalselectdata, FALSE);
                    __bCalselectdata +=7;
                    calendar_draw_item_HighLight(__bCalselectdata, TRUE);
                }
            }
            break;
        case KEY_UP:
            if (_bCALENDARMode == CALENDAR_MODE_DISPLAY_PERPETUAL_CALENDAR)
            {
                __bCalSelectMenuID = YEAR_MONTH_CHANGE;
            }

            if(__bCalSelectMenuID==YEAR_MONTH_CHANGE)
            {
                if(_bCurrentMonth<12)
                    _bCurrentMonth++;
                else
                {
                    if(_wCurrentYear<CAL_LASTYEAR)
                    {
                        _wCurrentYear++;
                        _bCurrentMonth = 1;
                    }
                }
                
                _bLastDay = Calendar_GetDaysofMonth(_wCurrentYear, _bCurrentMonth);
                calendar_draw_all();
            }
            else  if(__bCalSelectMenuID==DATA_CHANGE)
            {
                if( __bCalselectdata>7 )
                {
                    calendar_draw_item_HighLight(__bCalselectdata, FALSE);
                    __bCalselectdata -=7;
                    calendar_draw_item_HighLight(__bCalselectdata, TRUE);
                }
            }
            
            break;
        case KEY_LEFT:
            if (_bCALENDARMode == CALENDAR_MODE_DISPLAY_PERPETUAL_CALENDAR)
            {
                __bCalSelectMenuID = YEAR_MONTH_CHANGE;
            }

            if(__bCalSelectMenuID==YEAR_MONTH_CHANGE)
            {
                if(_wCurrentYear>CAL_FIRSTYEAR)
                    _wCurrentYear--;
                else
                    _wCurrentYear=CAL_LASTYEAR;
                _bLastDay = Calendar_GetDaysofMonth(_wCurrentYear, _bCurrentMonth);
                calendar_draw_all();
            }
            else  if(__bCalSelectMenuID==DATA_CHANGE)
            {
                _bCalX = Calendar_SolarCalendar(_wCurrentYear,_bCurrentMonth,__bCalselectdata);
                if((_bCalX>0)&&(__bCalselectdata>1))
                {
                    
                    calendar_draw_item_HighLight(__bCalselectdata, FALSE);
                    __bCalselectdata --;
                    calendar_draw_item_HighLight(__bCalselectdata, TRUE);
                }
            }
            
            break;
            
        case KEY_RIGHT:
            if (_bCALENDARMode == CALENDAR_MODE_DISPLAY_PERPETUAL_CALENDAR)
            {
                __bCalSelectMenuID = YEAR_MONTH_CHANGE;
            }

            if(__bCalSelectMenuID==YEAR_MONTH_CHANGE)
            {
                if(_wCurrentYear<CAL_LASTYEAR)
                    _wCurrentYear++;
                else
                    _wCurrentYear=CAL_FIRSTYEAR;
                
                _bLastDay = Calendar_GetDaysofMonth(_wCurrentYear, _bCurrentMonth);
                calendar_draw_all();
            }
            else  if(__bCalSelectMenuID==DATA_CHANGE)
            {
                _bCalX = Calendar_SolarCalendar(_wCurrentYear,_bCurrentMonth,__bCalselectdata);
                if((_bCalX<6)&&(__bCalselectdata<_bLastDay))
                {
                    calendar_draw_item_HighLight(__bCalselectdata, FALSE);
                    __bCalselectdata ++;
                    calendar_draw_item_HighLight(__bCalselectdata, TRUE);
                }
            }
            break;
            
        case KEY_PLAY:
        case KEY_ENTER:
        case KEY_PLAY_PAUSE:
            if (_bCALENDARMode == CALENDAR_MODE_SETTING)
            {
                _bCurrentDate = __bCalselectdata;
                _CALENDAR_Set_YYMMDD();
                calendar_draw_title(FALSE);
            }
            break;           
        case KEY_FUNCTION:
        case KEY_EXIT:
            if (_bCALENDARMode == CALENDAR_MODE_SETTING)
            {
                CALENDAR_Exit(TRUE);
                POWERONMENU_BackToMainMenu();
            }
#ifdef SUPPORT_SET_DATE_BY_MENU
            else if (_bCALENDARMode == CALENDAR_MODE_DISPLAY_PERPETUAL_CALENDAR)
            {
                _bCALENDARMode = CALENDAR_MODE_MENU;
                _CALENDAR_ShowMenu();
            }
#endif //SUPPORT_SET_DATE_BY_MENU
            return KEY_NO_KEY;            
        default:
            break;
        }
    }
    
    return KEY_NO_KEY;    
}

void CALENDAR_Exit(BYTE bClearBackground)
{
    __bCalselectdata = 0;
    __bCalSelectMenuID =0;
    _bCurrentDate= 0;
    _bCurrentMonth =0;
    _wCurrentYear=0;

    if (bClearBackground)
    {
        GDI_ClearRegion(0);
    }

#ifdef SUPPORT_SET_DATE_BY_MENU
    if (_hCALENDARDateMenu != MENU_HANDLE_INVALID)
    {
        MENU_DeleteMenu(_hCALENDARDateMenu, FALSE);
        _hCALENDARDateMenu = MENU_HANDLE_INVALID;
    }

    if (_hCALENDARSetDate != SETDATE_HANDLE_INVALID)
    {
        SETDATE_Exit(_hCALENDARSetDate, FALSE);
    }
#endif //SUPPORT_SET_DATE_BY_MENU
}

//get data from clock,now use constant
void  _CALENDAR_Set_YYMMDD(void)
{
    RTC_TM Calendar;

    RTC_GetTime(&Calendar);

#ifdef CT950_STYLE
    Calendar.bYear = _wCurrentYear-2000;
    Calendar.bMon = _bCurrentMonth;
    Calendar.bDate = _bCurrentDate;

    RTC_SetTime(&Calendar);
#endif //CT950_STYLE
}

BYTE _CALENDAR_ShowTime(BYTE bImmediate)
{
    RTC_TM RTCTime;

    if (!bImmediate)
    {        
        if ((OS_GetSysTimer() - _dwCALENDARTriggerTime) > COUNT_500_MSEC)
        {
            RTC_GetTime(&RTCTime);
            
            if ((_CALENDARCurrnetRTCTime.bSec == RTCTime.bSec) &&
                (_CALENDARCurrnetRTCTime.bMin == RTCTime.bMin) &&
                (_CALENDARCurrnetRTCTime.bHr == RTCTime.bHr))
            {
                return FALSE;
            }
            else
            {   
                if ((RTCTime.bSec == 0) && (RTCTime.bMin == 0) && (RTCTime.bHr == 0))
                {
                    if (CALENDA_Get_YYMMDD())
                    { 
                        _wCurrentYear = Calenda_Info.u16CalenderYear;
                        _bCurrentMonth =Calenda_Info.u8CalenderMonth;
                        _bCurrentDate = Calenda_Info.u8CalenderDate;
                    }

                    __bCalSelectMenuID=DATA_CHANGE;
                    __bCalselectdata=_bCurrentDate; 
                    calendar_draw_all();
                }   

                _CALENDAR_ShowTimeContent(&RTCTime);
                
                _CALENDARCurrnetRTCTime.bSec = RTCTime.bSec;
                _CALENDARCurrnetRTCTime.bMin = RTCTime.bMin;
                _CALENDARCurrnetRTCTime.bHr = RTCTime.bHr;
                
                _dwCALENDARTriggerTime = OS_GetSysTimer();
            }
        }
    }
    else
    {
        RTC_GetTime(&RTCTime);
        _CALENDAR_ShowTimeContent(&RTCTime);
    }
        
    return TRUE;
}

void _CALENDAR_ShowTimeContent(PRTC_TM pRTCTime)
{
    PARM_DRAW_STRING strTime;

    if ((pRTCTime->bHr == 0) && (pRTCTime->bMin == 0) && (pRTCTime->bSec == 0))
    {
         calendar_draw_title(FALSE);
    }

    OSDUTL_PrepareOutputString();
    OSDUTL_OutputNumFromIndex(pRTCTime->bHr/10);    
    OSDUTL_OutputNumFromIndex(pRTCTime->bHr%10);
    OSDUTL_CopyStringFromIndex(aCALENDARColon);
    OSDUTL_OutputNumFromIndex(pRTCTime->bMin/10);    
    OSDUTL_OutputNumFromIndex(pRTCTime->bMin%10);
    OSDUTL_CopyStringFromIndex(aCALENDARColon);
    OSDUTL_OutputNumFromIndex(pRTCTime->bSec/10);    
    OSDUTL_OutputNumFromIndex(pRTCTime->bSec%10);
    
    strTime.bBackground = _bHeadBackColor;
    strTime.bColorKey = 0;
    strTime.bTextColor =_bHeadFront2Color;    
    strTime.bShadow1 = PAL_ENTRY_COLOR_TRANSPARENT;
    strTime.bShadow2 = PAL_ENTRY_COLOR_TRANSPARENT;
    strTime.wX = _wCALENDARUpdateTimePosX+CALENDAR_DATA_TIME_DISTANCE_H;
    strTime.wY = _wCALENDARUpdateTimePosY;
    
    GDI_DrawString_909(0, &strTime, __pOSDUTLOutputString);
}


void CALENDAR_Trigger(void)
{
    if (_bCALENDARMode == CALENDAR_MODE_DISPLAY_CLOCK_AND_TIME)
    {
        //update time
        _CALENDAR_ShowTime(FALSE);
    }
}

#ifdef SUPPORT_SET_DATE_BY_MENU
void _CALENDAR_ShowMenu(void)
{    
    MAINMENU_InitializeGDI(__SetupInfo.bUIStyle-SETUP_CUSTOM_UI_STYLE_BEGIN);
    MAINMENU_DrawMainBackground();
    MAINMENU_DrawSelectionHelp(FALSE, FALSE);
    
    //Draw the title
    MAINMENU_DrawTitleString(aPOWERONIconCalendar, NULL, NULL);
    
    if (_hCALENDARDateMenu == MENU_HANDLE_INVALID)
    {
        _hCALENDARDateMenu = MENU_CreateMenu(&_MENU_CALENDAR, CALENDAR_MAX_VISIBLE_MENU_ITEM_NUM, _bCALENDARExitKey);
    }
    
    MENU_ShowMenu(_hCALENDARDateMenu, TRUE, MAINMENU_PALETTE_ENTRY_CONTENT_REGION);        
}

void CALENDAR_SetDate(WORD wYear, BYTE bMonth, BYTE bDate)
{
    Calenda_Info.u16CalenderYear  = wYear;
    Calenda_Info.u8CalenderMonth = bMonth;
    Calenda_Info.u8CalenderDate = bDate;

    _wCurrentYear = Calenda_Info.u16CalenderYear;
    _bCurrentMonth =Calenda_Info.u8CalenderMonth;
    _bCurrentDate = Calenda_Info.u8CalenderDate;

    _CALENDAR_Set_YYMMDD();
        
    SETDATE_Exit(_hCALENDARSetDate, TRUE);
    MENU_ShowMenu(_hCALENDARDateMenu, TRUE, MAINMENU_PALETTE_ENTRY_CONTENT_REGION); 

    _bCALENDARMode = CALENDAR_MODE_MENU;
}

void CALENDAR_CancelSetDate(void)
{
    SETDATE_Exit(_hCALENDARSetDate, TRUE);
    MENU_ShowMenu(_hCALENDARDateMenu, TRUE, MAINMENU_PALETTE_ENTRY_CONTENT_REGION); 

    _bCALENDARMode = CALENDAR_MODE_MENU;
}

#endif //SUPPORT_SET_DATE_BY_MENU

⌨️ 快捷键说明

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