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

📄 apiosdrender.c

📁 mstar 776 开发的车载dvd
💻 C
📖 第 1 页 / 共 5 页
字号:

//-------------------------------------------------------------------------------------------------
// MApi_Osd_GetStrWidth : Get the string width in pixels
/// @param  pGC             \b IN: the GC
/// @param  hFont           \b IN: the font handle
/// @param  pString         \b IN: the output string
/// @param  u16strLen       \b IN: the string length you want to calculate
/// @return string width in pixels
//-------------------------------------------------------------------------------------------------
/*U32 MApi_Osd_GetStrWidth(   OsdGC *pGC,
                            SystemFont eSystemFont,
                            U8 flag,
                            U8 u8dis,
                            U8 *pString,
                            U16 u16strLen )
{
#if 0
    FONTHANDLE hFont;
	GE_TEXT_OUT_INFO fmt;
    U32 u32FontType;
	U32 u32StrWidth = 0, u32TmpStrWidth;
    GE_FONT_INFO fontInfo;
    U8 *pTmpString;
    U16 u16TmpStrLen;

    MApi_Osd_GCGetSysFont(pGC, eSystemFont ,&hFont, &u32FontType);

    if (hFont == ERR_HANDLE)
    {
        PRINTE("MApi_Osd_GetStrWidth : Can't Get Font Handle\n");
        return 0;
    }

    MDrv_GE_PE_GetFontInfo(hFont, &fontInfo);

	//2. Get text display length
    fmt.dstblk.width= fontInfo.width;
    fmt.dstblk.height = fontInfo.height;
    fmt.dstblk.x = 0;
    fmt.dstblk.y = 0;
    fmt.dis    = u8dis;
    fmt.flag = flag;

    pTmpString = pString;
    u16TmpStrLen = u16strLen;
    while (u16TmpStrLen > MaxTextOutLen)
    {

        AnsiToWStrIndex(pTmpString, MaxTextOutLen, u32FontType, _pWstringBuf);
	    MDrv_GE_PE_QueryTextDispLength(hFont, (U8*)_pWstringBuf, 2, &fmt, &u32TmpStrWidth);
        u32StrWidth += u32TmpStrWidth;
        pTmpString = pTmpString + MaxTextOutLen;
        u16TmpStrLen -= MaxTextOutLen;
    }

    AnsiToWStrIndex(pTmpString, u16TmpStrLen, u32FontType, _pWstringBuf);
    MDrv_GE_PE_QueryTextDispLength(hFont, (U8*)_pWstringBuf, 2, &fmt, &u32TmpStrWidth);
    u32StrWidth += u32TmpStrWidth;

	return u32StrWidth;
#endif
	return 0;
}*/

//-------------------------------------------------------------------------------------------------
/// MApi_Osd_BoxTextOut : Textout on Box of screen
/// @param  pGC             \b IN: the GC
/// @param  eSysFont        \b IN: the System Font Type
/// @param  rect            \b IN: the output rectangle
/// @param  pString         \b IN: the output string
/// @param  eOSD_COLOR_FMT  \b IN: input color format
/// @param  TextColor       \b IN: input color
/// @param  eTextAttrib     \b IN: Text Attibute
/// @param flag
///            --#define GEFONT_FLAG_DEFAULT                 0x0
///            --#define GEFONT_FLAG_COMPACT                 0x4
///            --#define GEFONT_FLAG_VARWIDTH                0x20
///            --#define GEFONT_FLAG_GAP                     0x40
/// @param dis               \b IN: set compact or Gap distant(take indent effect) when GEFONT_FLAG_COMPACT or GEFONT_FLAG_GAP is set
/// @param  bShadow         \bIN:  TRUE/FALSE  enable shadow/disable shadow
/// @return TRUE/FALSE : Sucess/Fail
//-------------------------------------------------------------------------------------------------
BOOLEAN MApi_Osd_BoxTextOut(  OsdGC *pGC,
                            SystemFont eSysFont,
                            Rect *rect,
                            U8 *pString,
                            OSD_COLOR_FMT eOSD_COLOR_FMT,
                            OSD_COLOR TextColor,
                            TextAttrib eTextAttrib,
                            U8 u8Flag,
                            U8 u8Gap,
                            BOOLEAN bShadow)
{
    FONTHANDLE s8FontHandle;

	//PRINTE("\r\n[BoxTextOut] enter, rect(%d, %d, %d, %d) pString = %s", rect->left, rect->top, rect->width, rect->height, pString);

    _OSD_Render_BeginDraw (pGC);

    clrBtn1.x = rect->left;
    clrBtn1.y = rect->top;
    clrBtn1.width = rect->width;
    clrBtn1.height = rect->height;
    clrBtn1.t_clr = TextColor;
    clrBtn1.Fontfmt.flag = u8Flag;
    clrBtn1.Fontfmt.ifont_gap = u8Gap;
	clrBtn1.bStringIndexWidth = CHAR_IDX_2BYTE;

	switch (eTextAttrib)
	{
		case eTextAlignLeft:
			clrBtn1.enTextAlign = EN_ALIGNMENT_LEFT;
			break;
	   	case eTextAlignMiddle:
		case eTextAlignMiddleWH:
		case eTextAlignLeft_MiddleH:
   		case eTextAlignRight_MiddleH:
			clrBtn1.enTextAlign = EN_ALIGNMENT_CENTER;
			break;
   		case eTextAlignRight:
			clrBtn1.enTextAlign = EN_ALIGNMENT_LEFT;
			break;
		default:
			clrBtn1.enTextAlign = EN_ALIGNMENT_DEFAULT;
			break;
	}

    s8FontHandle = eSysFont;
	//PRINTE("\r\n[BoxTextOut] font handle = %d", (U16)eSysFont);
	//PRINTE("\r\n[BoxTextOut] rect = (%d, %d, %d, %d", rect->left, rect->top, rect->width, rect->height);
    msAPI_OSD_DrawPunctuatedString(Font[s8FontHandle].fHandle, (U16*)pString, &clrBtn1, 1);

    MApi_Osd_EndDraw(pGC);

    /*Rect r;
    U8 *ptr;
    FONTHANDLE hFont;
    U16 u16Row;
    U16 u16CurLen;
    U16 u16FontWidth, u16FontHeight;
    U16 i, j;
    U16 u16Len;// = __strlen(pString);
    U16 u16DispChar = 0;
    U16 u16Lines = 1;
    U16 u16LineIdx = 0;
    U32 u32RealWidth;
    U32 u32FontType;
    GE_TEXT_OUT_INFO stTextInfo;

    MApi_Osd_GCGetSysFont(pGC, eSysFont, &hFont, &u32FontType);
    if (hFont == ERR_HANDLE)
    {
        PRINTE("MApi_Osd_BoxTextOut : Can't Get Font Handle\n");
        return FALSE;
    }

    _MApi_Osd_GetFontInfo(pGC, eSysFont, rect, &u16FontWidth, &u16FontHeight, &u16Row);
    RECT(r, rect->left, rect->top, rect->width, u16FontHeight);
    stTextInfo.dis = u8Gap;
    stTextInfo.flag = u8Flag;
    stTextInfo.dstblk.height = u16FontHeight;
    stTextInfo.dstblk.width = u16FontWidth;

    for (i=0; i<u16Len; i++)
    {
        if (pString[i] == '\r' || pString[i] == '\a') { u16Lines++; }
    }

    while (u16DispChar < u16Len)
    {
        ptr = pString + u16DispChar;

        for (j=u16DispChar; j<u16Len; j++)
        {
            if (pString[j] == '\r' || pString[j] == '\a') { break; }
        }
        u16CurLen = (j - u16DispChar);

        for (i=u16CurLen; i>0; i--)
        {
            u32RealWidth = MApi_Osd_GetStrWidth(pGC, eSysFont, u8Flag, u8Gap, (pString + u16DispChar), i);
            if (u32RealWidth <= rect->width)
            {
                u16CurLen = i;
                break;
            }
        }

        if (eTextAttrib == eTextAlignMiddle)
        {
            r.left = rect->left + ((rect->width - u32RealWidth) >> 1);
            r.top = rect->top;
        }
        else if (eTextAttrib == eTextAlignRight)
        {
            r.left = rect->left + rect->width - u32RealWidth;
            r.top = rect->top;
        }
        else if (eTextAttrib == eTextAlignLeft)
        {
            r.left = rect->left;
            r.top = rect->top;
        }
        else if (eTextAttrib == eTextAlignMiddleWH)
        {
            r.left = rect->left + ((rect->width - u32RealWidth) >> 1);
            r.top = rect->top + ((rect->height - u16Lines*u16FontHeight) >> 1);
        }
        else if (eTextAttrib == eTextAlignLeft_MiddleH)
        {
            r.left = rect->left;
            r.top = rect->top  + ((rect->height - u16Lines*u16FontHeight) >> 1);
        }
        else if (eTextAttrib == eTextAlignRight_MiddleH)
        {
            r.left = rect->left + rect->width - u32RealWidth;
            r.top = rect->top + ((rect->height - u16Lines*u16FontHeight) >> 1);
        }

        r.width = u32RealWidth;
        r.top += (u16LineIdx * u16FontHeight);

        _MApi_Osd_TextOutNew(pGC,
                             eOSD_COLOR_FMT,
                             TextColor,
                             eSysFont,
                             &r,
                             ptr,
                             u16CurLen,
                             u8Flag,
                             u8Gap,
                             bShadow);

        u16LineIdx++;
        u16DispChar += (BYTE_PER_CHAR * u16CurLen);  // next line
        if (pString[u16DispChar] == '\r' || pString[u16DispChar] == '\a')
        {
            u16DispChar++;
        }
    }*/

    return TRUE;
}

//-------------------------------------------------------------------------------------------------
/// MApi_Osd_BoxTextOutConstAlpha : Textout on Box of screen with constant alpha
/// @param  pGC             \b IN: the GC
/// @param  eSysFont        \b IN: the System Font Type
/// @param  rect            \b IN: the output rectangle
/// @param  pString         \b IN: the output string
/// @param  eOSD_COLOR_FMT  \b IN: input color format
/// @param  TextColor       \b IN: input color
/// @param  eTextAttrib     \b IN: Text Attibute
/// @param flag
///            --#define GEFONT_FLAG_DEFAULT                 0x0
///            --#define GEFONT_FLAG_COMPACT                 0x4
///            --#define GEFONT_FLAG_VARWIDTH                0x20
///            --#define GEFONT_FLAG_GAP                     0x40
/// @param dis               \b IN: set compact or Gap distant(take indent effect) when GEFONT_FLAG_COMPACT or GEFONT_FLAG_GAP is set
/// @param u8Alpah			\b IN: constant alpha
/// @param  bShadow         \bIN:  TRUE/FALSE  enable shadow/disable shadow
/// @return TRUE/FALSE : Sucess/Fail
//-------------------------------------------------------------------------------------------------
BOOLEAN MApi_Osd_BoxTextOutConstAlpha(  OsdGC *pGC,
                            SystemFont eSysFont,
                            Rect *rect,
                            U8 *pString,
                            OSD_COLOR_FMT eOSD_COLOR_FMT,
                            OSD_COLOR TextColor,
                            TextAttrib eTextAttrib,
                            U8 u8Flag,
                            U8 u8Gap,
                            U8 u8Alpha,
                            BOOLEAN bShadow)
{
    /*Rect r;
    U8 *ptr;
    FONTHANDLE hFont;
    U16 u16Row;
    U16 u16CurLen;
    U16 u16FontWidth, u16FontHeight;
    U16 i, j;
    U16 u16Len;// = strlen(pString);
    U16 u16DispChar = 0;
    U16 u16Lines = 1;
    U16 u16LineIdx = 0;
    U32 u32RealWidth;
    U32 u32FontType;
    GE_TEXT_OUT_INFO stTextInfo;

    MApi_Osd_GCGetSysFont(pGC, eSysFont, &hFont, &u32FontType);
    if (hFont == ERR_HANDLE)
    {
        PRINTE("MApi_Osd_BoxTextOut : Can't Get Font Handle\n");
        return FALSE;
    }

    _MApi_Osd_GetFontInfo(pGC, eSysFont, rect, &u16FontWidth, &u16FontHeight, &u16Row);
    RECT(r, rect->left, rect->top, rect->width, u16FontHeight);
    stTextInfo.dis = u8Gap;
    stTextInfo.flag = u8Flag;
    stTextInfo.dstblk.height = u16FontHeight;
    stTextInfo.dstblk.width = u16FontWidth;

    for (i=0; i<u16Len; i++)
    {
        if (pString[i] == '\r' || pString[i] == '\a') { u16Lines++; }
    }

    while (u16DispChar < u16Len)
    {
        ptr = pString + u16DispChar;

        for (j=u16DispChar; j<u16Len; j++)
        {
            if (pString[j] == '\r' || pString[j] == '\a') { break; }
        }
        u16CurLen = (j - u16DispChar);

        for (i=u16CurLen; i>0; i--)
        {
            u32RealWidth = MApi_Osd_GetStrWidth(pGC, eSysFont, u8Flag, u8Gap, (pString + u16DispChar), i);
            if (u32RealWidth <= rect->width)
            {
                u16CurLen = i;
                break;
            }
        }

        if (eTextAttrib == eTextAlignMiddle)
        {
            r.left = rect->left + ((rect->width - u32RealWidth) >> 1);
            r.top = rect->top;
        }
        else if (eTextAttrib == eTextAlignRight)
        {
            r.left = rect->left + rect->width - u32RealWidth;
            r.top = rect->top;
        }
        else if (eTextAttrib == eTextAlignLeft)
        {
            r.left = rect->left;
            r.top = rect->top;
        }
        else if (eTextAttrib == eTextAlignMiddleWH)
        {
            r.left = rect->left + ((rect->width - u32RealWidth) >> 1);
            r.top = rect->top + ((rect->height - u16Lines*u16FontHeight) >> 1);
        }
        else if (eTextAttrib == eTextAlignLeft_MiddleH)
        {
            r.left = rect->left;
            r.top = rect->top  + ((rect->height - u16Lines*u16FontHeight) >> 1);
        }
        else if (eTextAttrib == eTextAlignRight_MiddleH)
        {
            r.left = rect->left + rect->width - u32RealWidth;
            r.top = rect->top + ((rect->height - u16Lines*u16FontHeight) >> 1);
        }

        r.width = u32RealWidth;
        r.top += (u16LineIdx * u16FontHeight);

        MApi_Osd_TextOutConstAlpha(pGC,

⌨️ 快捷键说明

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