[FREELDR:UI] Couple of fixes for some TUI Draw*Text functions.

- TuiDrawCenteredText: Partly fix centering calculations (susceptible
  to give negative coordinates).

- TuiDrawText2: Don't display anything if X or Y are out of the screen.
This commit is contained in:
Hermès Bélusca-Maïto 2022-01-06 02:03:09 +01:00
parent f6a2438c1f
commit a9994eab45
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -88,6 +88,10 @@ TuiDrawText2(
#endif
ULONG i, j;
/* Don't display anything if we are out of the screen */
if ((X >= UiScreenWidth) || (Y >= UiScreenHeight))
return;
/* Draw the text, not exceeding the width */
for (i = X, j = 0; Text[j] && i < UiScreenWidth && (MaxNumChars > 0 ? j < MaxNumChars : TRUE); i++, j++)
{
@ -148,9 +152,13 @@ TuiDrawCenteredText(
/* Base the box height on the number of lines */
BoxHeight = LineBreakCount + 1;
/* Create the centered coordinates */
RealLeft = (((Right - Left) - BoxWidth) / 2) + Left;
RealTop = (((Bottom - Top) - BoxHeight) / 2) + Top;
/*
* Create the centered coordinates.
* Here, the Left/Top/Right/Bottom rectangle is a hint, around
* which we center the "real" text rectangle RealLeft/RealTop.
*/
RealLeft = (Left + Right - BoxWidth + 1) / 2;
RealTop = (Top + Bottom - BoxHeight + 1) / 2;
/* Now go for a second scan */
LastIndex = 0;