/********************************************************************* * * GUI_DispString */ void GUI_DispString(const char GUI_UNI_PTR *s) { int xAdjust, yAdjust, xOrg; int FontSizeY; if (!s) return; GUI_LOCK(); FontSizeY = GUI_GetFontDistY(); 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); int xLineSize = GUI__GetLineDistX(s, LineNumChars); /* 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; GUI__DispLine(s, LineNumChars, &r); GUI_Context.DispPosY = r.y0; s += GUI_UC__NumChars2NumBytes(s, LineNumChars); if ((*s == '\n') || (*s == '\r')) { switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) { case GUI_TA_CENTER: case GUI_TA_RIGHT: GUI_Context.DispPosX = 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) /* end of string (last line) reached ? */ break; } GUI_Context.DispPosY += yAdjust; GUI_Context.TextAlign &= ~GUI_TA_HORIZONTAL; GUI_UNLOCK(); }
static void _DispStringInRect(const char GUI_FAR *s, GUI_RECT* pRect, int TextAlign) { GUI_RECT r; GUI_RECT rLine; int y = 0; int NumLines; const char *sOrg =s; int FontYSize; int xLine = 0; FontYSize = GUI_GetFontSizeY(); if (pRect) { r = *pRect; } else { GUI_GetClientRect(&r); } /* Count the number of lines for vertical alignment */ for (NumLines=1; ;NumLines++) { int LineLen= GUI__GetLineLen(s,0x7fff); s += LineLen; if (GUI__HandleEOLine(&s)) break; } /* Do the vertical alignment */ switch (TextAlign & GUI_TA_VERTICAL) { case GUI_TA_TOP: y = r.y0; break; case GUI_TA_BASELINE: case GUI_TA_BOTTOM: y = r.y1 -NumLines * FontYSize+1; break; case GUI_TA_VCENTER: y = r.y0+(r.y1-r.y0+1 -NumLines * FontYSize) /2; break; } for (s=sOrg; ;) { int LineLen= GUI__GetLineLen(s,0x7fff); int xLineSize = GUI_GetLineDistX(s, LineLen); switch (TextAlign & GUI_TA_HORIZONTAL) { case GUI_TA_HCENTER: xLine = r.x0+(r.x1-r.x0-xLineSize)/2; break; case GUI_TA_LEFT: xLine = r.x0; break; case GUI_TA_RIGHT: xLine = r.x1 -xLineSize; } rLine.x0 = GUI_Context.DispPosX = xLine; rLine.x1 = rLine.x0 + xLineSize-1; rLine.y0 = GUI_Context.DispPosY = y; rLine.y1 = y + FontYSize-1; GUI__DispLine(s, LineLen, &rLine); s += LineLen; y += GUI_GetFontDistY(); if (GUI__HandleEOLine(&s)) break; } }
/********************************************************************* * * GUI__DispStringInRect */ void GUI__DispStringInRect(const char GUI_UNI_PTR *s, GUI_RECT* pRect, int TextAlign, int MaxNumChars) { GUI_RECT r; GUI_RECT rLine; int y = 0; const char GUI_UNI_PTR *sOrg =s; int FontYSize; int xLine = 0; int LineLen; int NumCharsRem; /* Number of remaining characters */ FontYSize = GUI_GetFontSizeY(); if (pRect) { r = *pRect; } else { GUI_GetClientRect(&r); } /* handle vertical alignment */ if ((TextAlign & GUI_TA_VERTICAL) == GUI_TA_TOP) { y = r.y0; } else { int NumLines; /* Count the number of lines */ for (NumCharsRem = MaxNumChars, NumLines = 1; NumCharsRem ;NumLines++) { LineLen = GUI__GetLineNumChars(s, NumCharsRem); if(LineLen == 0) { break; } NumCharsRem -= LineLen; s += GUI_UC__NumChars2NumBytes(s, LineLen); if (GUI__HandleEOLine(&s)) break; } /* Do the vertical alignment */ switch (TextAlign & GUI_TA_VERTICAL) { case GUI_TA_BASELINE: case GUI_TA_BOTTOM: y = r.y1 -NumLines * FontYSize+1; break; case GUI_TA_VCENTER: y = r.y0+(r.y1-r.y0+1 -NumLines * FontYSize) /2; break; } } /* Output string */ for (NumCharsRem = MaxNumChars, s = sOrg; NumCharsRem;) { int xLineSize; LineLen = GUI__GetLineNumChars(s, NumCharsRem); if(LineLen == 0) { break; } NumCharsRem -= LineLen; xLineSize = GUI__GetLineDistX(s, LineLen); switch (TextAlign & GUI_TA_HORIZONTAL) { case GUI_TA_HCENTER: xLine = r.x0+(r.x1-r.x0-xLineSize)/2; break; case GUI_TA_LEFT: xLine = r.x0; break; case GUI_TA_RIGHT: xLine = r.x1 -xLineSize + 1; } rLine.x0 = GUI_Context.DispPosX[GUI_Context.SelLayer] = xLine; rLine.x1 = rLine.x0 + xLineSize-1; rLine.y0 = GUI_Context.DispPosY[GUI_Context.SelLayer] = y; rLine.y1 = y + FontYSize-1; GUI__DispLine(s, LineLen, &rLine); s += GUI_UC__NumChars2NumBytes(s, LineLen); y += GUI_GetFontDistY(); if (GUI__HandleEOLine(&s)) break; } }
/********************************************************************* * * GUI_DispStringInRectWrap */ void GUI_DispStringInRectWrap(const char GUI_UNI_PTR * s, GUI_RECT * pRect, int TextAlign, GUI_WRAPMODE WrapMode) { const GUI_RECT * pOldClipRect; GUI_RECT Rect; int xSize, ySizeFont, NumBytesToNextLine, NumCharsDisp; if (!s) { return; } GUI_LOCK(); Rect = *pRect; xSize = Rect.x1 - Rect.x0 + 1; ySizeFont = GUI_GetFontDistY(); /* Vertical alignment */ if ((TextAlign & GUI_TA_VERTICAL) != GUI_TA_TOP) { int NumLines = 0; const char GUI_UNI_PTR * pText; pText = s; /* Count the number of lines */ do { NumBytesToNextLine = GUI__WrapGetNumBytesToNextLine(pText, xSize, WrapMode); pText += NumBytesToNextLine; if (NumBytesToNextLine) { NumLines++; } } while (NumBytesToNextLine); /* Do the vertical alignment */ switch (TextAlign & GUI_TA_VERTICAL) { case GUI_TA_BASELINE: case GUI_TA_BOTTOM: Rect.y0 = Rect.y1 - NumLines * ySizeFont + 1; break; case GUI_TA_VCENTER: Rect.y0 = Rect.y0 + (Rect.y1 - Rect.y0 + 1 - NumLines * ySizeFont) / 2; break; } } pOldClipRect = GUI_SetClipRect(pRect); do { int xLineSize; GUI_RECT RectText; NumCharsDisp = GUI__WrapGetNumCharsDisp(s, xSize, WrapMode); Rect.y1 = Rect.y0 + ySizeFont - 1; RectText = Rect; /* Horizontal alignment */ xLineSize = GUI__GetLineDistX(s, NumCharsDisp); switch (TextAlign & GUI_TA_HORIZONTAL) { case GUI_TA_HCENTER: RectText.x0 = pRect->x0 + (pRect->x1 - pRect->x0 - xLineSize) / 2; break; case GUI_TA_LEFT: RectText.x0 = pRect->x0; break; case GUI_TA_RIGHT: RectText.x0 = pRect->x1 - xLineSize + 1; break; } GUI__DispLine(s, NumCharsDisp, &RectText); s += GUI__WrapGetNumBytesToNextLine(s, xSize, WrapMode); Rect.y0 += ySizeFont; } while (*s); GUI_SetClipRect(pOldClipRect); GUI_UNLOCK(); }