From 9ed249bdb9083bbbad8446373c55514bb7d6cf32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Colin?= <48470491+Raphalex46@users.noreply.github.com> Date: Sat, 12 Nov 2022 04:18:45 +0100 Subject: [PATCH] Add scrollbar to help window (#5481) * Add scrollbar to help window. Also reduced the help window's text width to make space for the scrollbar. --- Source/help.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Source/help.cpp b/Source/help.cpp index af082f865..90d814d3b 100644 --- a/Source/help.cpp +++ b/Source/help.cpp @@ -7,6 +7,7 @@ #include #include "DiabloUI/ui_flags.hpp" +#include "engine/render/clx_render.hpp" #include "engine/render/text_render.hpp" #include "init.h" #include "minitext.h" @@ -101,7 +102,7 @@ constexpr int PaddingTop = 32; constexpr int PaddingLeft = 32; constexpr int PanelHeight = 297; -constexpr int ContentTextWidth = 577; +constexpr int ContentTextWidth = 565; int LineHeight() { @@ -138,6 +139,29 @@ int NumVisibleLines() return (ContentsTextHeight() - 1) / LineHeight() + 1; // Ceil } +void DrawHelpSlider(const Surface &out) +{ + const Point uiPosition = GetUIRectangle().position; + const int sliderXPos = ContentTextWidth + uiPosition.x + 36; + const Point sliderPosition = uiPosition; + int sliderStart = uiPosition.y + HeaderHeight() + LineHeight() + 3; + int sliderEnd = uiPosition.y + PaddingTop + PanelHeight - 12; + ClxDraw(out, { sliderXPos, sliderStart }, (*pSTextSlidCels)[11]); + sliderStart += 12; + int sliderCurrent = sliderStart; + for (; sliderCurrent < sliderEnd; sliderCurrent += 12) { + ClxDraw(out, { sliderXPos, sliderCurrent }, (*pSTextSlidCels)[13]); + } + ClxDraw(out, { sliderXPos, sliderCurrent }, (*pSTextSlidCels)[10]); + // Subtract visible lines from the total number of lines to get the actual + // scroll range + const int scrollRange = HelpTextLines.size() - NumVisibleLines(); + // Subtract the size of the arrow buttons to get the length of the interior + // part of the slider + const int sliderLength = sliderCurrent - 12 - sliderStart; + ClxDraw(out, { sliderXPos, sliderStart + ((SkipLines * sliderLength) / scrollRange) }, (*pSTextSlidCels)[12]); +} + } // namespace void InitHelp() @@ -149,7 +173,7 @@ void InitHelp() HelpFlag = false; for (const auto *text : HelpText) { - const std::string paragraph = WordWrapString(_(text), 577); + const std::string paragraph = WordWrapString(_(text), ContentTextWidth); size_t previous = 0; while (true) { @@ -210,6 +234,8 @@ void DrawHelp(const Surface &out) DrawString(out, _("Press ESC to end or the arrow keys to scroll."), { { sx, contentY + ContentsTextHeight() + ContentPaddingY() + blankLineHeight }, { ContentTextWidth, lineHeight } }, UiFlags::ColorWhitegold | UiFlags::AlignCenter); + + DrawHelpSlider(out); } void DisplayHelp()