1
0
Fork 0

Codechange: Pass NewsItem by reference. (#13898)

pull/13900/head
Peter Nelson 2025-03-26 18:56:33 +00:00 committed by GitHub
parent 422ff9dbd8
commit 5331389765
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -1187,10 +1187,10 @@ void ShowLastNewsMessage()
* @param colour the colour the string will be shown in * @param colour the colour the string will be shown in
* @param *ni NewsItem being printed * @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. */ /* 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 */ /* Truncate and show string; postfixed by '...' if necessary */
DrawString(left, right, y, message, colour); DrawString(left, right, y, message, colour);
@ -1239,7 +1239,7 @@ struct MessageHistoryWindow : Window {
for (auto ni = first; ni != last; ++ni) { for (auto ni = first; ni != last; ++ni) {
DrawString(date.left, date.right, y, GetString(STR_JUST_DATE_TINY, ni->date), TC_WHITE); 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; y += this->line_height;
} }
} }

View File

@ -36,10 +36,10 @@
#include "safeguards.h" #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. */ /* 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; DrawPixelInfo tmp_dpi;
if (!FillDrawPixelInfo(&tmp_dpi, left, top, right - left, bottom)) return true; 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); DrawString(tr, msg, TC_FROMSTRING, SA_HOR_CENTER);
} else if (this->ticker_scroll < TICKER_STOP && GetStatusbarNews() != nullptr && !GetStatusbarNews()->headline.empty()) { } else if (this->ticker_scroll < TICKER_STOP && GetStatusbarNews() != nullptr && !GetStatusbarNews()->headline.empty()) {
/* Draw the scrolling news text */ /* 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); InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED);
if (Company::IsValidID(_local_company)) { if (Company::IsValidID(_local_company)) {
/* This is the default text */ /* This is the default text */