From a9994eab45eae66ab4d16dbf4532b1056d40f304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 6 Jan 2022 02:03:09 +0100 Subject: [PATCH] [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. --- boot/freeldr/freeldr/ui/tui.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/boot/freeldr/freeldr/ui/tui.c b/boot/freeldr/freeldr/ui/tui.c index b985989e699..310c872172d 100644 --- a/boot/freeldr/freeldr/ui/tui.c +++ b/boot/freeldr/freeldr/ui/tui.c @@ -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;