MApp_ZUI_CTL_MarqueeTextWinProc字串滚动

///////////////////////////////////////////////////////////////////////////////
///  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);
    }
}

  

原文地址:https://www.cnblogs.com/yuanqiangfei/p/11536466.html