https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a9994eab45eae66ab4d16…
commit a9994eab45eae66ab4d16dbf4532b1056d40f304
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Jan 6 02:03:09 2022 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Feb 6 17:52:42 2022 +0100
[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;