大神驾到
发表于 2022-9-6 10:02:52
ZJB19921204 发表于 2022-9-6 09:44
顶一个
哈哈,谢谢:$
jasn
发表于 2022-9-15 10:50:57
顶一个!!
大神驾到
发表于 2022-9-15 13:37:33
jasn 发表于 2022-9-15 10:50
顶一个!!
谢谢:lol
大神驾到
发表于 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;
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 = ' ';
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;
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 != 0)
// {
// if (outStr == ' ')
// wordWidth = (Font_widthAndheighe_7_1252_24X26Font - 1] / 2) + 1;
// else
// wordWidth = Font_widthAndheighe_7_1252_24X26Font - 1] + 1;
// }
// break;
// case FONT32X40:
// if (outStr != 0)
// {
// if (outStr == ' ')
// wordWidth = (Font_widthAndheighe_6_1252_32X40Font - 1] / 2) + 1;
// else
// wordWidth = Font_widthAndheighe_6_1252_32X40Font - 1] + 1;
// }
// break;
// default:
// break;
// }
// break;
// }
// is_NewLineFlagCharInit();
// if(is_NewLineFlagChar(outStr)&&(width+wordWidth>maxWidth))
// {
// inWordCount -= 1;
// outWordCount -= 1;
// width -= wordWidth;
// if (width > calcMaxWidth)
// {
// calcMaxWidth = width;
// }
// outStr = 0x0D;
// outWordCount++;
// outStr = 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;
}
}
crc_3c
发表于 2022-9-16 08:23:12
顶起来:)
大神驾到
发表于 2022-9-16 08:38:09
crc_3c 发表于 2022-9-16 08:23
顶起来
谢谢支持:$
ailex
发表于 2022-10-1 00:01:11
很厉害,希望能完善搞一套ui框架,官方搞图片的ui还是有很多局限
大神驾到
发表于 2022-10-1 09:28:46
ailex 发表于 2022-10-1 00:01
很厉害,希望能完善搞一套ui框架,官方搞图片的ui还是有很多局限
没问题,已经有完整的了,只不过在公司做的要慢慢剥离出来:lol,公司应用场景很复杂的那种
ailex
发表于 2022-12-9 07:29:13
大神 ui框架什么时候出来,期盼很久了:lol
lishenghui
发表于 2022-12-9 11:07:50
码一下0.0