浅析μC/GUI-v3.90a之GUI_DispString函数
文章来源:http://gliethttp.cublog.cn
------------------------------------------------------------------------------------- 1.GUI_DispString()函数 gui/core/GUI_DispString.c void GUI_DispString(const char GUI_UNI_PTR *s) { int xAdjust, yAdjust, xOrg; int FontSizeY; if (!s) return; GUI_LOCK(); FontSizeY = GUI_GetFontDistY(); //Font的y大小,默认8 xOrg = GUI_Context.DispPosX; /* Adjust vertical position */ yAdjust = GUI_GetYAdjust(); //垂直对齐方式 GUI_Context.DispPosY -= yAdjust; for (; *s; s++) { GUI_RECT r; int LineNumChars = GUI__GetLineNumChars(s, 0x7fff); //获取一行\0或\n 8bits字节数[该版本只能显示英文] int xLineSize = GUI__GetLineDistX(s, LineNumChars); //这些数据所占用x轴上横向点阵数 /* Check if x-position needs to be changed due to h-alignment */ switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) { //水平对齐方式 case GUI_TA_CENTER: xAdjust = xLineSize / 2; break; case GUI_TA_RIGHT: xAdjust = xLineSize; break; default: xAdjust = 0; } r.x0 = GUI_Context.DispPosX -= xAdjust; r.x1 = r.x0 + xLineSize - 1; r.y0 = GUI_Context.DispPosY; r.y1 = r.y0 + FontSizeY - 1; //该行字体显示矩形区域r GUI__DispLine(s, LineNumChars, &r); //显示该行数据 GUI_Context.DispPosY = r.y0; s += GUI_UC__NumChars2NumBytes(s, LineNumChars); //s指向下一行待显示的数据区 if ((*s == '\n') || (*s == '\r')) { switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) { case GUI_TA_CENTER: case GUI_TA_RIGHT: GUI_Context.DispPosX = xOrg; //居中和右对齐,传递函数原始位置xOrg break; default: GUI_Context.DispPosX = GUI_Context.LBorder; break; } if (*s == '\n') GUI_Context.DispPosY += FontSizeY; //回车,转入下一行 } else { GUI_Context.DispPosX = r.x0 + xLineSize; //接着上一行的结束位置,继续显示 } if (*s == 0) //待显示数据已经显示完毕 break; } GUI_Context.DispPosY += yAdjust; //将垂直对齐方式还原成未调用GUI_DispString之前值 GUI_Context.TextAlign &= ~GUI_TA_HORIZONTAL; //清除文本水平对齐方式 GUI_UNLOCK(); } ------------------------------------------------------------------------------------- 2.GUI__DispLine()函数 2007-07-11 gliethttp gui/core/GUICharLine.c void GUI__DispLine(const char GUI_UNI_PTR *s, int MaxNumChars, const GUI_RECT* pr) { GUI_RECT r; { r = *pr; #if GUI_WINSUPPORT WM_ADDORG(r.x0, r.y0); WM_ADDORG(r.x1, r.y1); //将矩形(r.x0,r.y0)平移到(GUI_Context.xOff,GUI_Context.yOff)坐标处 WM_ITERATE_START(&r) { //计算剪切域,另用《浅析μC/GUI-v3.90a之WM_ITERATE_START剪切域计算宏》专门讨论 #endif GUI_Context.DispPosX = r.x0; GUI_Context.DispPosY = r.y0; /* Do the actual drawing via routine call. */ _DispLine(s, MaxNumChars, &r); #if GUI_WINSUPPORT } WM_ITERATE_END(); WM_SUBORG(GUI_Context.DispPosX, GUI_Context.DispPosY); #endif } }
|