MApp_ZUI_CTL_MarqueeTextWinProc字串滚动
阅读原文时间:2023年07月12日阅读:1

///////////////////////////////////////////////////////////////////////////////
/// global MApp_ZUI_CTL_MarqueeTextWinProc
/// Window Proc for "marquee text" control,
/// which display a static text by clipped string with dynamic color
/// if the string content is more than boundary, it will set a timer for text rotation (once)
///
/// rule: if window data == 0, no marquee animation
/// if window is not focus state, no marquee animation
/// if dynamic string content is shorter than boundary, no marquee animation
/// if pData->u8ShowStartPosition==0xFF, animation disabled
/// if pData->u8ShowStartPosition>=strlen, animation disabled
///
///
/// @param [in] hWnd HWND window handle
/// @param [in] pMsg PMSG message type
///
/// @return S32 message execute result
///
/// @author MStarSemi @date 2007/1/25
///////////////////////////////////////////////////////////////////////////////

S32 MApp_ZUI_CTL_MarqueeTextWinProc(HWND hWnd, PMSG pMsg)
{
GUI_DATA_MARQUEE_VARDATA * pData =
(GUI_DATA_MARQUEE_VARDATA*)MApp_ZUI_API_GetWindowData(hWnd);

switch(pMsg->message)  
{  
    case MSG\_TIMER:  
        if (pData)  
        {  
            if (pData->u8ShowStartPosition == 0)  
                MApp\_ZUI\_API\_SetTimer(hWnd, pMsg->wParam, ZUI\_MARQUEE\_ANIMATION\_INTERVAL\_MS);  
            pData->u8ShowStartPosition++;  
            MApp\_ZUI\_API\_InvalidateWindow(hWnd);  
        }  
        return 0;

    case MSG\_PAINT:  
        {  
            //get buffer GC for offline drawing...  
            PAINT\_PARAM \* param = (PAINT\_PARAM\*)pMsg->wParam;  
            DRAWSTYLE\_TYPE ds\_type = DS\_NORMAL;

            if (param->bIsDisable)  
            {  
                param->dc.u8ConstantAlpha = MApp\_ZUI\_API\_GetDisableAlpha(hWnd);  
                ds\_type = DS\_DISABLE;  
            }  
            else if (param->bIsFocus) //the same focus group  
            {  
                param->dc.u8ConstantAlpha = MApp\_ZUI\_API\_GetFocusAlpha(hWnd);  
                ds\_type = DS\_FOCUS;  
            }  
            else  
            {  
                param->dc.u8ConstantAlpha = MApp\_ZUI\_API\_GetNormalAlpha(hWnd);  
            }

            \_MApp\_ZUI\_API\_DefaultOnPaint(hWnd, param, FALSE);  
            {  
                U16 u16TxtComponentIndex = \_MApp\_ZUI\_API\_FindFirstComponentIndex(hWnd, ds\_type, CP\_TEXT\_OUT);  
                LPTSTR pStr = MApp\_ZUI\_ACT\_GetDynamicText(hWnd);  
                if (u16TxtComponentIndex != 0xFFFF && pStr)  
                {  
                    DRAW\_TEXT\_OUT\_DYNAMIC dyna;

                    \_MApp\_ZUI\_API\_ConvertTextComponentToDynamic(u16TxtComponentIndex, &dyna);  
                    dyna.pString = pStr;  
                    dyna.TextColor = MApp\_ZUI\_ACT\_GetDynamicColor(hWnd, ds\_type, dyna.TextColor);

                    //marquee animation:  
                    if (ds\_type == DS\_FOCUS && pData != NULL &&  
                        pData->u8ShowStartPosition != 0xFF)  
                    {  
                        if (pData->u8ShowStartPosition >= MApp\_ZUI\_API\_Strlen(pStr))  
                        {  
                            pData->u8ShowStartPosition = 0xFF;  
                            MApp\_ZUI\_API\_KillTimer(hWnd, 0);  
                        }  
                        else if (pData->u8ShowStartPosition == 0)  
                        {  
                            U16 width;  
                            clrBtn1.Fontfmt.flag = dyna.flag;  
                            clrBtn1.Fontfmt.ifont\_gap = dyna.u8dis;  
                            clrBtn1.bStringIndexWidth = CHAR\_IDX\_2BYTE;  
                            width = msAPI\_OSD\_GetStrWidth(Font\[dyna.eSystemFont\].fHandle, (U8\*)pStr, &clrBtn1);  
                            //note: add border for a little truncate case..  
                            if (width+BTN\_TEXT\_GAP\*2 <= param->rect->width)  
                            {  
                                pData->u8ShowStartPosition = 0xFF;  
                                MApp\_ZUI\_API\_KillTimer(hWnd, 0);  
                            }  
                        }  
                        else  
                        {  
                            dyna.pString += pData->u8ShowStartPosition;  
                            dyna.u8dots = 0; //note: don't show dots for animation..  
                        }  
                    }  
                    else  
                    {  
                        //note: pData may be shared with others, so don't clear them  
                        //      but we need to stop the timer if animation still going  
                        MApp\_ZUI\_API\_KillTimer(hWnd, 0);  
                    }

                    \_MApp\_ZUI\_API\_DrawDynamicComponent(CP\_TEXT\_OUT\_DYNAMIC, &dyna, &param->dc, param->rect);  
                }  
            }

        }  
        return 0;

        default:  
            break;  
}

return DEFAULTWINPROC(hWnd, pMsg);  

}

///////////////////////////////////////////////////////////////
// methods

void MApp_ZUI_CTL_MarqueeTextEnableAnimation(HWND hwnd, BOOLEAN bEnable)
{
//note: if enable, try to check string length is long enough, and then start animation
// if disable, stop and clear to normal status

if (hwnd != HWND\_INVALID)  
{  
    GUI\_DATA\_MARQUEE\_VARDATA \* pData =  
        (GUI\_DATA\_MARQUEE\_VARDATA\*)MApp\_ZUI\_API\_GetWindowData(hwnd);

    if (pData == NULL)  
        return;

    if (bEnable)  
    {  
        pData->u8ShowStartPosition = 0;  
        MApp\_ZUI\_API\_SetTimer(hwnd, 0, ZUI\_MARQUEE\_INITIAL\_INTERVAL\_MS);  
    }  
    else  
    {  
        pData->u8ShowStartPosition = 0xFF;  
        MApp\_ZUI\_API\_KillTimer(hwnd, 0);  
    }  
    MApp\_ZUI\_API\_InvalidateWindow(hwnd);  
}  

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章