迪文科技论坛

 找回密码
 立即注册
搜索
楼主: 大神驾到

【开源】开源一套使用者能自主控制并设计的迪文屏显示

[复制链接]

3

主题

41

回帖

600

积分

高级会员

Rank: 4

积分
600
 楼主| 发表于 2022-9-6 10:02:52 | 显示全部楼层

哈哈,谢谢
回复

使用道具 举报

3

主题

2

回帖

62

积分

注册会员

Rank: 2

积分
62
发表于 2022-9-15 10:50:57 | 显示全部楼层
顶一个!!
回复

使用道具 举报

3

主题

41

回帖

600

积分

高级会员

Rank: 4

积分
600
 楼主| 发表于 2022-9-15 13:37:33 | 显示全部楼层

谢谢
回复

使用道具 举报

3

主题

41

回帖

600

积分

高级会员

Rank: 4

积分
600
 楼主| 发表于 2022-9-15 17:10:14 | 显示全部楼层
本帖最后由 大神驾到 于 2022-9-15 17:40 编辑

优化了单词截断函数
void calc_DgusStrShowLocat_AndOutStr(bool fnew_field,bool endRowNoDelete, char* inStr, uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t* outStartX, uint16_t* outStartY, uint16_t* outShowStrPos, uint32_t* outStr, uint8_t langType, uint8_t alignType, uint8_t fontSize, uint16_t* outShowHigh)
{
        int i = 0;
        int a = 0;
        char word = 0;
        bool isInitiativeLine = true;
        char Blank[1];
        uint16_t threePosWidth;
        uint16_t width = 0;
        uint16_t hight = 0;
        uint16_t hight1 = 0;
        uint16_t inWordCount = 0;
        uint16_t outWordCount = 0;
        uint16_t calcMaxWidth = 0;
        uint16_t calcMaxHight = 0;
        uint16_t calcWidth = 0;
        uint16_t wordWidth = 0;
        uint16_t maxWidth = 0;
        uint16_t maxHigh = 0;
        uint16_t otherWidth;
        bool isMax1024;
        char posWord;

        posWord='.';
        if (inStr == NULL || strlen(inStr) == 0)
        {
                oldSize = 0;
                newSize = 0;
                pOutStrBuff = NULL;
                set_OutBuff(0xFF,outWordCount);
                outWordCount++;
                set_OutBuff(0xFF,outWordCount);
                outWordCount++;
                set_OutBuff(0x00,outWordCount);
                outWordCount++;
                *outStr = (uint32_t)pOutStrBuff;
                return;
        }

        oldSize = 0;
        newSize = 0;
        pOutStrBuff = NULL;
        isHaveBlank = false;
        Blank[0] = ' ';
        maxWidth = ex - sx;
        switch (fontSize)//迪文屏字符计算不准,需要减少一个最大字符分辨率来弥补
        {
        case FONT24X32:
                maxWidth -= WIDTH_FONT24X32;
                otherWidth = WIDTH_FONT24X32;
                break;
        case FONT32X40:
                maxWidth -= WIDTH_FONT32X40;
                otherWidth = WIDTH_FONT32X40;
                break;
        default:
                break;
        }
        maxHigh = ey - sy;

        if (!fnew_field)
        {
                isInitiativeLine = false;
        }

        switch (fontSize)
        {
        case FONT24X32:
                hight1 = HIGH_FONT24X32;
                hight += hight1;
                break;
        case FONT32X40:
                hight1 = HIGH_FONT32X40;
                hight += hight1;
                break;
        default:
                break;
        }

        while (1)
        {
                /*
                如果是主动换行
                */
                if (isInitiativeLine && fnew_field)
                {
                        isInitiativeLine = false;
                        set_OutBuff(' ',outWordCount);
                        outWordCount++;
                        set_OutBuff(' ',outWordCount);
                        outWordCount++;
                        width += get_CharWidth(Blank, langType, fontSize);
                        width += get_CharWidth(Blank, langType, fontSize);
                }
                word = inStr[inWordCount];

                if (word == 0)
                {
                        if (width > calcMaxWidth)
                        {
                                calcMaxWidth = width;
                        }
                        calcMaxHight = hight;
                        break;
                }

                if (word == 0x0A)
                {
                        if (width > calcMaxWidth)
                        {
                                calcMaxWidth = width;
                        }

                        if (hight > maxHigh - hight1)
                        {
                                calcMaxHight = hight;
                                inWordCount++;
                                break;
                        }
                        hight += hight1;
                        width = 0;
                        set_OutBuff(0x0D,outWordCount);
                        outWordCount++;
                        set_OutBuff(0x0A,outWordCount);
                        outWordCount++;
                        isHaveBlank = false;
                        isInitiativeLine = true;
                        inWordCount++;
                        continue;
                }
                inWordCount++;
                set_OutBuff(word,outWordCount);
                outWordCount++;
                width += get_CharWidth(&word, langType, fontSize);
                threePosWidth=0;
                if (width > maxWidth)
                {
                        isMax1024 = false;
                        is_NewLineFlagCharInit();
                        calcWidth = 0;
                        threePosWidth +=get_CharWidth(&posWord, langType, fontSize)+1;
                        threePosWidth +=get_CharWidth(&posWord, langType, fontSize)+1;
                        threePosWidth +=get_CharWidth(&posWord, langType, fontSize)+1;
                        for (i = inWordCount - 1; i >= 0; i--)
                        {
                                if((endRowNoDelete==true)&&(hight > maxHigh - hight1))//是最后一行并且使能了最后一行不删减单词功能
                                {
                                        calcWidth += get_CharWidth(&inStr, langType, fontSize);
                                        if (width -calcWidth+threePosWidth<=maxWidth)
                                        {
                                                a = (inWordCount - i);
                                                if (a == 0)
                                                {
                                                        a = 1;
                                                }
                                                outWordCount -= a;
                                                width -= calcWidth;

                                                if (width > calcMaxWidth)
                                                {
                                                        calcMaxWidth = width;
                                                }

                                                calcWidth = 0;
                                                if (width <= maxWidth)
                                                {
                                                        inWordCount -= a;
                                                        set_OutBuff('.',outWordCount);
                                                        outWordCount++;
                                                        set_OutBuff('.',outWordCount);
                                                        outWordCount++;
                                                        set_OutBuff('.',outWordCount);
                                                        outWordCount++;
                                                        break;
                                                }
                                        }                                       
                                }
                                else
                                {
                                        if (is_NewLineFlagChar(inStr) || !isHaveBlank)
                                        {
                                                calcWidth += get_CharWidth(&inStr, langType, fontSize);       
                                                if (width -calcWidth <= maxWidth && outWordCount <= 1024)
                                                {
                                                        a = (inWordCount - (i+1))+1;
                                                        inWordCount -= a;
                                                        outWordCount -= a;
                                                        width -=calcWidth;
                                                        if (width > calcMaxWidth)
                                                        {
                                                                calcMaxWidth = width;
                                                        }
                                                        calcWidth = 0;                                                       
                                                        break;
                                                }
                                                       
                                                is_NewLineFlagCharInit();

                                                if (outWordCount > 1024)
                                                {
                                                        isMax1024 = true;
                                                }
                                        }
                                        else
                                        {
                                                calcWidth += get_CharWidth(&inStr, langType, fontSize);       
                                        }                                               
                                }
                        }

                        if (hight > maxHigh - hight1)
                        {
                                calcMaxHight = hight;
                                break;
                        }

                        if (isMax1024 == true)
                        {
                                calcMaxHight = hight;
                                break;
                        }
                        hight += hight1;
                        //                        switch (langType)
                        //                        {
                        //                        case CM_LANG_EN:
                        //                                switch (fontSize)
                        //                                {
                        //                                case FONT24X26:
                        //                                        if (outStr[outWordCount - 1] != 0)
                        //                                        {
                        //                                                if (outStr[outWordCount - 1] == ' ')
                        //                                                        wordWidth = (Font_widthAndheighe_7_1252_24X26Font[outStr[outWordCount - 1] - 1][1] / 2) + 1;
                        //                                                else
                        //                                                        wordWidth = Font_widthAndheighe_7_1252_24X26Font[outStr[outWordCount - 1] - 1][1] + 1;
                        //                                        }
                        //                                        break;
                        //                                case FONT32X40:
                        //                                        if (outStr[outWordCount - 1] != 0)
                        //                                        {
                        //                                                if (outStr[outWordCount - 1] == ' ')
                        //                                                        wordWidth = (Font_widthAndheighe_6_1252_32X40Font[outStr[outWordCount - 1] - 1][1] / 2) + 1;
                        //                                                else
                        //                                                        wordWidth = Font_widthAndheighe_6_1252_32X40Font[outStr[outWordCount - 1] - 1][1] + 1;
                        //                                        }
                        //                                        break;
                        //                                default:
                        //                                        break;
                        //                                }
                        //                                break;
                        //                        }
                        //                        is_NewLineFlagCharInit();
                        //                        if(is_NewLineFlagChar(outStr[outWordCount-1])&&(width+wordWidth>maxWidth))
                        //                        {
                        //                                inWordCount -= 1;
                        //                                outWordCount -= 1;
                        //                                width -= wordWidth;
                        //                                if (width > calcMaxWidth)
                        //                                {
                        //                                        calcMaxWidth = width;
                        //                                }                               
                        //                                outStr[outWordCount] = 0x0D;
                        //                                outWordCount++;
                        //                                outStr[outWordCount] = 0x0A;       
                        //                                outWordCount++;
                        //                        }
                        //                        else
                        {
                                if (width > calcMaxWidth)
                                {
                                        calcMaxWidth = width;
                                }

                                if (isHaveBlank)
                                {
                                        set_OutBuff(0x0D,outWordCount);
                                        outWordCount++;
                                        set_OutBuff(0x0A,outWordCount);
                                        outWordCount++;
                                }
                        }
                        width = 0;
                }
                else
                {
                        if (outWordCount > 1024)
                        {
                                isMax1024 = true;

                                is_NewLineFlagCharInit();
                                calcWidth = 0;
                                for (i = inWordCount - 1; i >= 0; i--)
                                {
                                        if (is_NewLineFlagChar(inStr))
                                        {
                                                a = (inWordCount - i) - 1;
                                                if (a == 0)
                                                {
                                                        a = 1;
                                                        calcWidth += get_CharWidth(&inStr, langType, fontSize);
                                                }
                                                outWordCount -= a;
                                                width -= calcWidth;
                                                calcWidth = 0;
                                                if (width <= maxWidth && outWordCount <= 1024)
                                                {
                                                        inWordCount -= a;
                                                        break;
                                                }
                                                else
                                                {
                                                        inWordCount -= a;
                                                        i = inWordCount;
                                                        is_NewLineFlagCharInit();
                                                }
                                        }

                                        calcWidth += get_CharWidth(&inStr, langType, fontSize);
                                }

                                if (hight > maxHigh - hight1)
                                {
                                        calcMaxHight = hight;
                                        break;
                                }

                                if (isMax1024 == true)
                                {
                                        calcMaxHight = hight;
                                        break;
                                }
                                hight += hight1;
                        }
                }
        }
        set_OutBuff(0xFF,outWordCount);
        outWordCount++;
        set_OutBuff(0xFF,outWordCount);
        outWordCount++;
        set_OutBuff(0x00,outWordCount);
        outWordCount++;
        *outShowStrPos = inWordCount;

        //这里为了测量显示位置是否正确,正式版本需要屏蔽       
        //        DGUS_ShowBasicGraphDesctibe_t GraphDesctibe;
        //        GraphDesctibe.basicGraphAddr = 0x1D40;
        //        memset(GraphDesctibe.buff, 0x0, 12);
        //        GraphDesctibe.startX = 0;
        //        GraphDesctibe.startY = 0;
        //        GraphDesctibe.endX = 800;
        //        GraphDesctibe.endY = 480;
        //        GraphDesctibe.dasheLineEn = 0;
        //        GraphDesctibe.dashSet = 0;
        //        GraphDesctibe.pielScale = 1;
        //        show_BasicGraphInit(&GraphDesctibe, 0x91E0);       
        //       
        //        show_DrawLineByAddr(GraphDesctibe.basicGraphAddr,0x0000,calcMaxWidth,0,calcMaxWidth,480,1);

        if (outShowHigh != NULL)
                *outShowHigh = calcMaxHight;

        *outStr = (uint32_t)pOutStrBuff;
        switch (alignType)
        {
        case ALIGN_LEFT:
                *outStartX = sx;
                *outStartY = (sy + (maxHigh / 2)) - (calcMaxHight / 2);
                break;
        case ALIGN_CENTER:
                if (((sx + ((ex -sx) / 2)) - (calcMaxWidth / 2) + calcMaxWidth) > ex - otherWidth)
                {
                        *outStartX = ((sx + ((ex -sx) / 2)) - (calcMaxWidth / 2)) - (((sx + ((ex -sx) / 2)) - (calcMaxWidth / 2) + calcMaxWidth) - (ex - otherWidth));
                }
                else
                {
                        *outStartX = (sx + ((ex -sx) / 2)) - (calcMaxWidth / 2);
                }
                *outStartY = (sy + (maxHigh / 2)) - (calcMaxHight / 2);
                break;
        case ALIGN_RIGHT:
                switch (fontSize)//迪文屏字符计算不准,需要减少一个最大字符分辨率来弥补
                {
                case FONT24X32:
                        *outStartX = ex - calcMaxWidth - WIDTH_FONT24X32;
                        break;
                case FONT32X40:
                        *outStartX = ex - calcMaxWidth - WIDTH_FONT32X40;
                        break;
                default:
                        break;
                }
                *outStartY = (sy + (maxHigh / 2)) - (calcMaxHight / 2);
                break;
        default:
                break;
        }
}
回复

使用道具 举报

0

主题

33

回帖

856

积分

高级会员

Rank: 4

积分
856
发表于 2022-9-16 08:23:12 | 显示全部楼层
顶起来
回复

使用道具 举报

3

主题

41

回帖

600

积分

高级会员

Rank: 4

积分
600
 楼主| 发表于 2022-9-16 08:38:09 | 显示全部楼层

谢谢支持
回复

使用道具 举报

2

主题

29

回帖

547

积分

高级会员

Rank: 4

积分
547
发表于 2022-10-1 00:01:11 | 显示全部楼层
很厉害,希望能完善搞一套ui框架,官方搞图片的ui还是有很多局限
回复

使用道具 举报

3

主题

41

回帖

600

积分

高级会员

Rank: 4

积分
600
 楼主| 发表于 2022-10-1 09:28:46 | 显示全部楼层
ailex 发表于 2022-10-1 00:01
很厉害,希望能完善搞一套ui框架,官方搞图片的ui还是有很多局限

没问题,已经有完整的了,只不过在公司做的要慢慢剥离出来,公司应用场景很复杂的那种
回复

使用道具 举报

2

主题

29

回帖

547

积分

高级会员

Rank: 4

积分
547
发表于 2022-12-9 07:29:13 | 显示全部楼层
大神 ui框架什么时候出来,期盼很久了
回复

使用道具 举报

0

主题

1

回帖

295

积分

中级会员

Rank: 3Rank: 3

积分
295
发表于 2022-12-9 11:07:50 | 显示全部楼层
码一下0.0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|迪文科技论坛 ( 京ICP备05033781号-1 )

GMT+8, 2025-8-12 16:44 , Processed in 0.033851 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表