Use dpi ref in Graph.cpp and InGameConsole.cpp

This commit is contained in:
Gymnasiast 2023-04-03 21:41:56 +02:00 committed by duncanspumpkin
parent f98818f8e5
commit f09df5a06a
7 changed files with 50 additions and 50 deletions

View File

@ -146,7 +146,7 @@ public:
{ {
auto bgColour = ThemeGetColour(WindowClass::Chat, 0); auto bgColour = ThemeGetColour(WindowClass::Chat, 0);
ChatDraw(dpi, bgColour); ChatDraw(dpi, bgColour);
_inGameConsole.Draw(dpi); _inGameConsole.Draw(*dpi);
} }
// Window // Window

View File

@ -16,7 +16,7 @@
namespace Graph namespace Graph
{ {
static void DrawMonths(DrawPixelInfo* dpi, const uint8_t* history, int32_t count, const ScreenCoordsXY& origCoords) static void DrawMonths(DrawPixelInfo& dpi, const uint8_t* history, int32_t count, const ScreenCoordsXY& origCoords)
{ {
auto& date = GetDate(); auto& date = GetDate();
int32_t currentMonth = date.GetMonth(); int32_t currentMonth = date.GetMonth();
@ -31,11 +31,11 @@ namespace Graph
auto ft = Formatter(); auto ft = Formatter();
ft.Add<uint32_t>(DateGameShortMonthNames[DateGetMonth((yearOver32 / 4) + MONTH_COUNT)]); ft.Add<uint32_t>(DateGameShortMonthNames[DateGetMonth((yearOver32 / 4) + MONTH_COUNT)]);
DrawTextBasic( DrawTextBasic(
*dpi, screenCoords - ScreenCoordsXY{ 0, 10 }, STR_GRAPH_LABEL, ft, dpi, screenCoords - ScreenCoordsXY{ 0, 10 }, STR_GRAPH_LABEL, ft,
{ FontStyle::Small, TextAlignment::CENTRE }); { FontStyle::Small, TextAlignment::CENTRE });
// Draw month mark // Draw month mark
GfxFillRect(dpi, { screenCoords, screenCoords + ScreenCoordsXY{ 0, 3 } }, PALETTE_INDEX_10); GfxFillRect(&dpi, { screenCoords, screenCoords + ScreenCoordsXY{ 0, 3 } }, PALETTE_INDEX_10);
} }
yearOver32 = (yearOver32 + 1) % 32; yearOver32 = (yearOver32 + 1) % 32;
@ -43,7 +43,7 @@ namespace Graph
} }
} }
static void DrawLineA(DrawPixelInfo* dpi, const uint8_t* history, int32_t count, const ScreenCoordsXY& origCoords) static void DrawLineA(DrawPixelInfo& dpi, const uint8_t* history, int32_t count, const ScreenCoordsXY& origCoords)
{ {
auto lastCoords = ScreenCoordsXY{ -1, -1 }; auto lastCoords = ScreenCoordsXY{ -1, -1 };
auto coords = origCoords; auto coords = origCoords;
@ -59,11 +59,11 @@ namespace Graph
auto rightBottom1 = coords + ScreenCoordsXY{ 1, 1 }; auto rightBottom1 = coords + ScreenCoordsXY{ 1, 1 };
auto leftTop2 = lastCoords + ScreenCoordsXY{ 0, 1 }; auto leftTop2 = lastCoords + ScreenCoordsXY{ 0, 1 };
auto rightBottom2 = coords + ScreenCoordsXY{ 0, 1 }; auto rightBottom2 = coords + ScreenCoordsXY{ 0, 1 };
GfxDrawLine(dpi, { leftTop1, rightBottom1 }, PALETTE_INDEX_10); GfxDrawLine(&dpi, { leftTop1, rightBottom1 }, PALETTE_INDEX_10);
GfxDrawLine(dpi, { leftTop2, rightBottom2 }, PALETTE_INDEX_10); GfxDrawLine(&dpi, { leftTop2, rightBottom2 }, PALETTE_INDEX_10);
} }
if (i == 0) if (i == 0)
GfxFillRect(dpi, { coords, coords + ScreenCoordsXY{ 2, 2 } }, PALETTE_INDEX_10); GfxFillRect(&dpi, { coords, coords + ScreenCoordsXY{ 2, 2 } }, PALETTE_INDEX_10);
lastCoords = coords; lastCoords = coords;
} }
@ -71,7 +71,7 @@ namespace Graph
} }
} }
static void DrawLineB(DrawPixelInfo* dpi, const uint8_t* history, int32_t count, const ScreenCoordsXY& origCoords) static void DrawLineB(DrawPixelInfo& dpi, const uint8_t* history, int32_t count, const ScreenCoordsXY& origCoords)
{ {
auto lastCoords = ScreenCoordsXY{ -1, -1 }; auto lastCoords = ScreenCoordsXY{ -1, -1 };
auto coords = origCoords; auto coords = origCoords;
@ -85,10 +85,10 @@ namespace Graph
{ {
auto leftTop = lastCoords; auto leftTop = lastCoords;
auto rightBottom = coords; auto rightBottom = coords;
GfxDrawLine(dpi, { leftTop, rightBottom }, PALETTE_INDEX_21); GfxDrawLine(&dpi, { leftTop, rightBottom }, PALETTE_INDEX_21);
} }
if (i == 0) if (i == 0)
GfxFillRect(dpi, { coords - ScreenCoordsXY{ 1, 1 }, coords + ScreenCoordsXY{ 1, 1 } }, PALETTE_INDEX_21); GfxFillRect(&dpi, { coords - ScreenCoordsXY{ 1, 1 }, coords + ScreenCoordsXY{ 1, 1 } }, PALETTE_INDEX_21);
lastCoords = coords; lastCoords = coords;
} }
@ -96,7 +96,7 @@ namespace Graph
} }
} }
void Draw(DrawPixelInfo* dpi, uint8_t* history, int32_t count, const ScreenCoordsXY& screenPos) void Draw(DrawPixelInfo& dpi, uint8_t* history, int32_t count, const ScreenCoordsXY& screenPos)
{ {
DrawMonths(dpi, history, count, screenPos); DrawMonths(dpi, history, count, screenPos);
DrawLineA(dpi, history, count, screenPos); DrawLineA(dpi, history, count, screenPos);
@ -152,7 +152,7 @@ static const FinancialTooltipInfo FinanceTooltipInfoFromMoney(
namespace Graph namespace Graph
{ {
static void DrawMonths(DrawPixelInfo* dpi, const money64* history, int32_t count, const ScreenCoordsXY& origCoords) static void DrawMonths(DrawPixelInfo& dpi, const money64* history, int32_t count, const ScreenCoordsXY& origCoords)
{ {
auto& date = GetDate(); auto& date = GetDate();
int32_t currentMonth = date.GetMonth(); int32_t currentMonth = date.GetMonth();
@ -167,11 +167,11 @@ namespace Graph
auto ft = Formatter(); auto ft = Formatter();
ft.Add<StringId>(DateGameShortMonthNames[DateGetMonth((yearOver32 / 4) + MONTH_COUNT)]); ft.Add<StringId>(DateGameShortMonthNames[DateGetMonth((yearOver32 / 4) + MONTH_COUNT)]);
DrawTextBasic( DrawTextBasic(
*dpi, screenCoords - ScreenCoordsXY{ 0, 10 }, STR_GRAPH_LABEL, ft, dpi, screenCoords - ScreenCoordsXY{ 0, 10 }, STR_GRAPH_LABEL, ft,
{ FontStyle::Small, TextAlignment::CENTRE }); { FontStyle::Small, TextAlignment::CENTRE });
// Draw month mark // Draw month mark
GfxFillRect(dpi, { screenCoords, screenCoords + ScreenCoordsXY{ 0, 3 } }, PALETTE_INDEX_10); GfxFillRect(&dpi, { screenCoords, screenCoords + ScreenCoordsXY{ 0, 3 } }, PALETTE_INDEX_10);
} }
yearOver32 = (yearOver32 + 1) % 32; yearOver32 = (yearOver32 + 1) % 32;
@ -180,7 +180,7 @@ namespace Graph
} }
static void DrawLineA( static void DrawLineA(
DrawPixelInfo* dpi, const money64* history, int32_t count, const ScreenCoordsXY& origCoords, int32_t modifier, DrawPixelInfo& dpi, const money64* history, int32_t count, const ScreenCoordsXY& origCoords, int32_t modifier,
int32_t offset) int32_t offset)
{ {
auto lastCoords = ScreenCoordsXY{ -1, -1 }; auto lastCoords = ScreenCoordsXY{ -1, -1 };
@ -197,11 +197,11 @@ namespace Graph
auto rightBottom1 = coords + ScreenCoordsXY{ 1, 1 }; auto rightBottom1 = coords + ScreenCoordsXY{ 1, 1 };
auto leftTop2 = lastCoords + ScreenCoordsXY{ 0, 1 }; auto leftTop2 = lastCoords + ScreenCoordsXY{ 0, 1 };
auto rightBottom2 = coords + ScreenCoordsXY{ 0, 1 }; auto rightBottom2 = coords + ScreenCoordsXY{ 0, 1 };
GfxDrawLine(dpi, { leftTop1, rightBottom1 }, PALETTE_INDEX_10); GfxDrawLine(&dpi, { leftTop1, rightBottom1 }, PALETTE_INDEX_10);
GfxDrawLine(dpi, { leftTop2, rightBottom2 }, PALETTE_INDEX_10); GfxDrawLine(&dpi, { leftTop2, rightBottom2 }, PALETTE_INDEX_10);
} }
if (i == 0) if (i == 0)
GfxFillRect(dpi, { coords, coords + ScreenCoordsXY{ 2, 2 } }, PALETTE_INDEX_10); GfxFillRect(&dpi, { coords, coords + ScreenCoordsXY{ 2, 2 } }, PALETTE_INDEX_10);
lastCoords = coords; lastCoords = coords;
} }
@ -210,7 +210,7 @@ namespace Graph
} }
static void DrawLineB( static void DrawLineB(
DrawPixelInfo* dpi, const money64* history, int32_t count, const ScreenCoordsXY& origCoords, int32_t modifier, DrawPixelInfo& dpi, const money64* history, int32_t count, const ScreenCoordsXY& origCoords, int32_t modifier,
int32_t offset) int32_t offset)
{ {
auto lastCoords = ScreenCoordsXY{ -1, -1 }; auto lastCoords = ScreenCoordsXY{ -1, -1 };
@ -225,10 +225,10 @@ namespace Graph
{ {
auto leftTop = lastCoords; auto leftTop = lastCoords;
auto rightBottom = coords; auto rightBottom = coords;
GfxDrawLine(dpi, { leftTop, rightBottom }, PALETTE_INDEX_21); GfxDrawLine(&dpi, { leftTop, rightBottom }, PALETTE_INDEX_21);
} }
if (i == 0) if (i == 0)
GfxFillRect(dpi, { coords - ScreenCoordsXY{ 1, 1 }, coords + ScreenCoordsXY{ 1, 1 } }, PALETTE_INDEX_21); GfxFillRect(&dpi, { coords - ScreenCoordsXY{ 1, 1 }, coords + ScreenCoordsXY{ 1, 1 } }, PALETTE_INDEX_21);
lastCoords = coords; lastCoords = coords;
} }
@ -237,7 +237,7 @@ namespace Graph
} }
static void DrawHoveredValue( static void DrawHoveredValue(
DrawPixelInfo* dpi, const money64* history, const int32_t historyCount, const ScreenCoordsXY& screenCoords, DrawPixelInfo& dpi, const money64* history, const int32_t historyCount, const ScreenCoordsXY& screenCoords,
const int32_t modifier, const int32_t offset) const int32_t modifier, const int32_t offset)
{ {
const auto cursorPosition = ContextGetCursorPositionScaled(); const auto cursorPosition = ContextGetCursorPositionScaled();
@ -254,26 +254,26 @@ namespace Graph
{ {
return; return;
} }
GfxDrawDashedLine(dpi, { { info.coords.x, chartFrame.GetTop() }, info.coords }, DefaultDashedLength, 0); GfxDrawDashedLine(&dpi, { { info.coords.x, chartFrame.GetTop() }, info.coords }, DefaultDashedLength, 0);
GfxDrawDashedLine(dpi, { { chartFrame.GetLeft() - 10, info.coords.y }, info.coords }, DefaultDashedLength, 0); GfxDrawDashedLine(&dpi, { { chartFrame.GetLeft() - 10, info.coords.y }, info.coords }, DefaultDashedLength, 0);
if (cursorPosition.y > info.coords.y) if (cursorPosition.y > info.coords.y)
{ {
GfxDrawDashedLine(dpi, { info.coords, { info.coords.x, cursorPosition.y } }, DefaultDashedLength, 0); GfxDrawDashedLine(&dpi, { info.coords, { info.coords.x, cursorPosition.y } }, DefaultDashedLength, 0);
} }
auto ft = Formatter(); auto ft = Formatter();
ft.Add<money64>(info.money); ft.Add<money64>(info.money);
DrawTextBasic( DrawTextBasic(
*dpi, info.coords - ScreenCoordsXY{ 0, 16 }, STR_FINANCES_SUMMARY_EXPENDITURE_VALUE, ft, { TextAlignment::CENTRE }); dpi, info.coords - ScreenCoordsXY{ 0, 16 }, STR_FINANCES_SUMMARY_EXPENDITURE_VALUE, ft, { TextAlignment::CENTRE });
GfxFillRect(dpi, { { info.coords - ScreenCoordsXY{ 2, 2 } }, info.coords + ScreenCoordsXY{ 2, 2 } }, PALETTE_INDEX_10); GfxFillRect(&dpi, { { info.coords - ScreenCoordsXY{ 2, 2 } }, info.coords + ScreenCoordsXY{ 2, 2 } }, PALETTE_INDEX_10);
GfxFillRect( GfxFillRect(
dpi, { { info.coords - ScreenCoordsXY{ 1, 1 } }, { info.coords + ScreenCoordsXY{ 1, 1 } } }, PALETTE_INDEX_21); &dpi, { { info.coords - ScreenCoordsXY{ 1, 1 } }, { info.coords + ScreenCoordsXY{ 1, 1 } } }, PALETTE_INDEX_21);
} }
void Draw( void Draw(
DrawPixelInfo* dpi, const money64* history, const int32_t count, const ScreenCoordsXY& screenCoords, DrawPixelInfo& dpi, const money64* history, const int32_t count, const ScreenCoordsXY& screenCoords,
const int32_t modifier, const int32_t offset) const int32_t modifier, const int32_t offset)
{ {
DrawMonths(dpi, history, count, screenCoords); DrawMonths(dpi, history, count, screenCoords);

View File

@ -15,8 +15,8 @@
namespace Graph namespace Graph
{ {
void Draw(DrawPixelInfo* dpi, uint8_t* history, int32_t count, const ScreenCoordsXY& screenPos); void Draw(DrawPixelInfo& dpi, uint8_t* history, int32_t count, const ScreenCoordsXY& screenPos);
void Draw( void Draw(
DrawPixelInfo* dpi, const money64* history, const int32_t count, const ScreenCoordsXY& coords, const int32_t modifier, DrawPixelInfo& dpi, const money64* history, const int32_t count, const ScreenCoordsXY& coords, const int32_t modifier,
const int32_t offset); const int32_t offset);
} // namespace Graph } // namespace Graph

View File

@ -264,7 +264,7 @@ void InGameConsole::Update()
_consoleCaretTicks = (_consoleCaretTicks + 1) % 30; _consoleCaretTicks = (_consoleCaretTicks + 1) % 30;
} }
void InGameConsole::Draw(DrawPixelInfo* dpi) const void InGameConsole::Draw(DrawPixelInfo& dpi) const
{ {
if (!_isOpen) if (!_isOpen)
return; return;
@ -292,18 +292,18 @@ void InGameConsole::Draw(DrawPixelInfo* dpi) const
Invalidate(); Invalidate();
// Give console area a translucent effect. // Give console area a translucent effect.
GfxFilterRect(dpi, { _consoleTopLeft, _consoleBottomRight }, FilterPaletteID::Palette51); GfxFilterRect(&dpi, { _consoleTopLeft, _consoleBottomRight }, FilterPaletteID::Palette51);
// Make input area more opaque. // Make input area more opaque.
GfxFilterRect( GfxFilterRect(
dpi, { { _consoleTopLeft.x, _consoleBottomRight.y - lineHeight - 10 }, _consoleBottomRight - ScreenCoordsXY{ 0, 1 } }, &dpi, { { _consoleTopLeft.x, _consoleBottomRight.y - lineHeight - 10 }, _consoleBottomRight - ScreenCoordsXY{ 0, 1 } },
FilterPaletteID::Palette51); FilterPaletteID::Palette51);
// Paint background colour. // Paint background colour.
uint8_t backgroundColour = ThemeGetColour(WindowClass::Console, 0); uint8_t backgroundColour = ThemeGetColour(WindowClass::Console, 0);
GfxFillRectInset(dpi, { _consoleTopLeft, _consoleBottomRight }, backgroundColour, INSET_RECT_FLAG_FILL_NONE); GfxFillRectInset(&dpi, { _consoleTopLeft, _consoleBottomRight }, backgroundColour, INSET_RECT_FLAG_FILL_NONE);
GfxFillRectInset( GfxFillRectInset(
dpi, { _consoleTopLeft + ScreenCoordsXY{ 1, 1 }, _consoleBottomRight - ScreenCoordsXY{ 1, 1 } }, backgroundColour, &dpi, { _consoleTopLeft + ScreenCoordsXY{ 1, 1 }, _consoleBottomRight - ScreenCoordsXY{ 1, 1 } }, backgroundColour,
INSET_RECT_FLAG_BORDER_INSET); INSET_RECT_FLAG_BORDER_INSET);
std::string lineBuffer; std::string lineBuffer;
@ -314,7 +314,7 @@ void InGameConsole::Draw(DrawPixelInfo* dpi) const
{ {
const size_t index = i + _consoleScrollPos; const size_t index = i + _consoleScrollPos;
lineBuffer = _colourFormatStr + _consoleLines[index]; lineBuffer = _colourFormatStr + _consoleLines[index];
GfxDrawString(*dpi, screenCoords, lineBuffer.c_str(), { textColour, InGameConsoleGetFontStyle() }); GfxDrawString(dpi, screenCoords, lineBuffer.c_str(), { textColour, InGameConsoleGetFontStyle() });
screenCoords.y += lineHeight; screenCoords.y += lineHeight;
} }
@ -322,14 +322,14 @@ void InGameConsole::Draw(DrawPixelInfo* dpi) const
// Draw current line // Draw current line
lineBuffer = _colourFormatStr + _consoleCurrentLine; lineBuffer = _colourFormatStr + _consoleCurrentLine;
DrawText(*dpi, screenCoords, { TEXT_COLOUR_255, InGameConsoleGetFontStyle() }, lineBuffer.c_str(), true); DrawText(dpi, screenCoords, { TEXT_COLOUR_255, InGameConsoleGetFontStyle() }, lineBuffer.c_str(), true);
// Draw caret // Draw caret
if (_consoleCaretTicks < CONSOLE_CARET_FLASH_THRESHOLD) if (_consoleCaretTicks < CONSOLE_CARET_FLASH_THRESHOLD)
{ {
auto caret = screenCoords + ScreenCoordsXY{ _caretScreenPosX, lineHeight }; auto caret = screenCoords + ScreenCoordsXY{ _caretScreenPosX, lineHeight };
uint8_t caretColour = ColourMapA[BASE_COLOUR(textColour)].lightest; uint8_t caretColour = ColourMapA[BASE_COLOUR(textColour)].lightest;
GfxFillRect(dpi, { caret, caret + ScreenCoordsXY{ CONSOLE_CARET_WIDTH, 1 } }, caretColour); GfxFillRect(&dpi, { caret, caret + ScreenCoordsXY{ CONSOLE_CARET_WIDTH, 1 } }, caretColour);
} }
// What about border colours? // What about border colours?
@ -338,21 +338,21 @@ void InGameConsole::Draw(DrawPixelInfo* dpi) const
// Input area top border // Input area top border
GfxFillRect( GfxFillRect(
dpi, &dpi,
{ { _consoleTopLeft.x, _consoleBottomRight.y - lineHeight - 11 }, { { _consoleTopLeft.x, _consoleBottomRight.y - lineHeight - 11 },
{ _consoleBottomRight.x, _consoleBottomRight.y - lineHeight - 11 } }, { _consoleBottomRight.x, _consoleBottomRight.y - lineHeight - 11 } },
borderColour1); borderColour1);
GfxFillRect( GfxFillRect(
dpi, &dpi,
{ { _consoleTopLeft.x, _consoleBottomRight.y - lineHeight - 10 }, { { _consoleTopLeft.x, _consoleBottomRight.y - lineHeight - 10 },
{ _consoleBottomRight.x, _consoleBottomRight.y - lineHeight - 10 } }, { _consoleBottomRight.x, _consoleBottomRight.y - lineHeight - 10 } },
borderColour2); borderColour2);
// Input area bottom border // Input area bottom border
GfxFillRect( GfxFillRect(
dpi, { { _consoleTopLeft.x, _consoleBottomRight.y - 1 }, { _consoleBottomRight.x, _consoleBottomRight.y - 1 } }, &dpi, { { _consoleTopLeft.x, _consoleBottomRight.y - 1 }, { _consoleBottomRight.x, _consoleBottomRight.y - 1 } },
borderColour1); borderColour1);
GfxFillRect(dpi, { { _consoleTopLeft.x, _consoleBottomRight.y }, _consoleBottomRight }, borderColour2); GfxFillRect(&dpi, { { _consoleTopLeft.x, _consoleBottomRight.y }, _consoleBottomRight }, borderColour2);
} }
// Calculates the amount of visible lines, based on the console size, excluding the input line. // Calculates the amount of visible lines, based on the console size, excluding the input line.

View File

@ -65,7 +65,7 @@ namespace OpenRCT2::Ui
void Scroll(int32_t linesToScroll); void Scroll(int32_t linesToScroll);
void Update(); void Update();
void Draw(DrawPixelInfo* dpi) const; void Draw(DrawPixelInfo& dpi) const;
private: private:
void ClearInput(); void ClearInput();

View File

@ -656,7 +656,7 @@ public:
// X axis labels and values // X axis labels and values
coords = graphTopLeft + ScreenCoordsXY{ 98, 17 }; coords = graphTopLeft + ScreenCoordsXY{ 98, 17 };
Graph::Draw(&dpi, gCashHistory, 64, coords, yAxisScale, 128); Graph::Draw(dpi, gCashHistory, 64, coords, yAxisScale, 128);
} }
#pragma endregion #pragma endregion
@ -713,7 +713,7 @@ public:
// X axis labels and values // X axis labels and values
coords = graphTopLeft + ScreenCoordsXY{ 98, 17 }; coords = graphTopLeft + ScreenCoordsXY{ 98, 17 };
Graph::Draw(&dpi, gParkValueHistory, 64, coords, yAxisScale, 0); Graph::Draw(dpi, gParkValueHistory, 64, coords, yAxisScale, 0);
} }
#pragma endregion #pragma endregion
@ -772,7 +772,7 @@ public:
// X axis labels and values // X axis labels and values
screenPos = graphTopLeft + ScreenCoordsXY{ 98, 17 }; screenPos = graphTopLeft + ScreenCoordsXY{ 98, 17 };
Graph::Draw(&dpi, gWeeklyProfitHistory, 64, screenPos, yAxisScale, 128); Graph::Draw(dpi, gWeeklyProfitHistory, 64, screenPos, yAxisScale, 128);
} }
#pragma endregion #pragma endregion

View File

@ -723,7 +723,7 @@ private:
// Graph // Graph
screenPos = windowPos + ScreenCoordsXY{ widget->left + 47, widget->top + 26 }; screenPos = windowPos + ScreenCoordsXY{ widget->left + 47, widget->top + 26 };
Graph::Draw(&dpi, gParkRatingHistory, 32, screenPos); Graph::Draw(dpi, gParkRatingHistory, 32, screenPos);
} }
#pragma endregion #pragma endregion
@ -808,7 +808,7 @@ private:
cappedHistory[i] = std::numeric_limits<uint8_t>::max(); cappedHistory[i] = std::numeric_limits<uint8_t>::max();
} }
} }
Graph::Draw(&dpi, cappedHistory, static_cast<int32_t>(std::size(cappedHistory)), screenPos); Graph::Draw(dpi, cappedHistory, static_cast<int32_t>(std::size(cappedHistory)), screenPos);
} }
#pragma endregion #pragma endregion