From 5331389765a694ba4329ea05ffa16a58b3848859 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 26 Mar 2025 18:56:33 +0000 Subject: [PATCH] Codechange: Pass NewsItem by reference. (#13898) --- src/news_gui.cpp | 6 +++--- src/statusbar_gui.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 0bc9177e67..51e51f748f 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -1187,10 +1187,10 @@ void ShowLastNewsMessage() * @param colour the colour the string will be shown in * @param *ni NewsItem being printed */ -static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem *ni) +static void DrawNewsString(uint left, uint right, int y, TextColour colour, const NewsItem &ni) { /* Get the string, replaces newlines with spaces and remove control codes from the string. */ - std::string message = StrMakeValid(ni->GetStatusText(), SVS_REPLACE_TAB_CR_NL_WITH_SPACE); + std::string message = StrMakeValid(ni.GetStatusText(), SVS_REPLACE_TAB_CR_NL_WITH_SPACE); /* Truncate and show string; postfixed by '...' if necessary */ DrawString(left, right, y, message, colour); @@ -1239,7 +1239,7 @@ struct MessageHistoryWindow : Window { for (auto ni = first; ni != last; ++ni) { DrawString(date.left, date.right, y, GetString(STR_JUST_DATE_TINY, ni->date), TC_WHITE); - DrawNewsString(news.left, news.right, y, TC_WHITE, &*ni); + DrawNewsString(news.left, news.right, y, TC_WHITE, *ni); y += this->line_height; } } diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index fc6411c6a1..61aae847af 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -36,10 +36,10 @@ #include "safeguards.h" -static bool DrawScrollingStatusText(const NewsItem *ni, int scroll_pos, int left, int right, int top, int bottom) +static bool DrawScrollingStatusText(const NewsItem &ni, int scroll_pos, int left, int right, int top, int bottom) { /* Replace newlines and the likes with spaces. */ - std::string message = StrMakeValid(ni->GetStatusText(), SVS_REPLACE_TAB_CR_NL_WITH_SPACE); + std::string message = StrMakeValid(ni.GetStatusText(), SVS_REPLACE_TAB_CR_NL_WITH_SPACE); DrawPixelInfo tmp_dpi; if (!FillDrawPixelInfo(&tmp_dpi, left, top, right - left, bottom)) return true; @@ -139,7 +139,7 @@ struct StatusBarWindow : Window { DrawString(tr, msg, TC_FROMSTRING, SA_HOR_CENTER); } else if (this->ticker_scroll < TICKER_STOP && GetStatusbarNews() != nullptr && !GetStatusbarNews()->headline.empty()) { /* Draw the scrolling news text */ - if (!DrawScrollingStatusText(GetStatusbarNews(), ScaleGUITrad(this->ticker_scroll), tr.left, tr.right, tr.top, tr.bottom)) { + if (!DrawScrollingStatusText(*GetStatusbarNews(), ScaleGUITrad(this->ticker_scroll), tr.left, tr.right, tr.top, tr.bottom)) { InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); if (Company::IsValidID(_local_company)) { /* This is the default text */