From 63445f6e0cf002e295152e211baeda807001e0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Wed, 25 Jan 2023 00:21:44 +0200 Subject: [PATCH] Use the drawing context provided by rendering engine --- src/OpenLoco/src/Drawing/FPSCounter.cpp | 7 +- .../src/Drawing/SoftwareDrawingContext.cpp | 56 ++--- .../src/Drawing/SoftwareDrawingContext.h | 4 +- src/OpenLoco/src/Entities/Misc.cpp | 6 +- src/OpenLoco/src/Graphics/Gfx.cpp | 6 +- src/OpenLoco/src/Graphics/Gfx.h | 4 - src/OpenLoco/src/Interop/Hooks.cpp | 7 +- src/OpenLoco/src/Objects/AirportObject.cpp | 4 +- src/OpenLoco/src/Objects/BridgeObject.cpp | 4 +- src/OpenLoco/src/Objects/CliffEdgeObject.cpp | 6 +- src/OpenLoco/src/Objects/CompetitorObject.cpp | 14 +- src/OpenLoco/src/Objects/CurrencyObject.cpp | 4 +- src/OpenLoco/src/Objects/DockObject.cpp | 4 +- src/OpenLoco/src/Objects/HillShapesObject.cpp | 4 +- src/OpenLoco/src/Objects/IndustryObject.cpp | 4 +- .../src/Objects/InterfaceSkinObject.cpp | 5 +- src/OpenLoco/src/Objects/LandObject.cpp | 4 +- .../src/Objects/LevelCrossingObject.cpp | 10 +- src/OpenLoco/src/Objects/ObjectManager.cpp | 7 +- src/OpenLoco/src/Objects/RegionObject.cpp | 4 +- src/OpenLoco/src/Objects/RoadExtraObject.cpp | 12 +- src/OpenLoco/src/Objects/RoadObject.cpp | 10 +- .../src/Objects/RoadStationObject.cpp | 6 +- .../src/Objects/ScaffoldingObject.cpp | 8 +- src/OpenLoco/src/Objects/SnowObject.cpp | 4 +- .../src/Objects/StreetLightObject.cpp | 6 +- src/OpenLoco/src/Objects/TrackExtraObject.cpp | 10 +- src/OpenLoco/src/Objects/TrackObject.cpp | 8 +- .../src/Objects/TrainSignalObject.cpp | 4 +- .../src/Objects/TrainStationObject.cpp | 6 +- src/OpenLoco/src/Objects/TreeObject.cpp | 6 +- src/OpenLoco/src/Objects/TunnelObject.cpp | 6 +- src/OpenLoco/src/Objects/VehicleObject.cpp | 12 +- src/OpenLoco/src/Objects/WallObject.cpp | 8 +- src/OpenLoco/src/Objects/WaterObject.cpp | 6 +- src/OpenLoco/src/OpenLoco.cpp | 8 +- src/OpenLoco/src/Paint/Paint.cpp | 6 +- src/OpenLoco/src/Ui/Dropdown.cpp | 30 +-- src/OpenLoco/src/Ui/TextInput.cpp | 15 +- src/OpenLoco/src/Ui/WindowManager.cpp | 4 +- src/OpenLoco/src/Vehicles/VehicleManager.cpp | 4 +- src/OpenLoco/src/Viewport.cpp | 34 +-- src/OpenLoco/src/Widget.cpp | 201 ++++++++++-------- src/OpenLoco/src/Widget.h | 2 +- src/OpenLoco/src/Window.cpp | 7 +- src/OpenLoco/src/Windows/About.cpp | 24 ++- src/OpenLoco/src/Windows/AboutMusic.cpp | 8 +- src/OpenLoco/src/Windows/BuildVehicle.cpp | 33 +-- src/OpenLoco/src/Windows/Cheats.cpp | 27 ++- .../src/Windows/CompanyFaceSelection.cpp | 20 +- src/OpenLoco/src/Windows/CompanyList.cpp | 51 +++-- src/OpenLoco/src/Windows/CompanyWindow.cpp | 105 +++++---- .../src/Windows/Construction/Common.cpp | 19 +- .../Windows/Construction/ConstructionTab.cpp | 11 +- .../src/Windows/Construction/OverheadTab.cpp | 4 +- .../src/Windows/Construction/SignalTab.cpp | 13 +- .../src/Windows/Construction/StationTab.cpp | 33 +-- .../src/Windows/EditKeyboardShortcut.cpp | 5 +- src/OpenLoco/src/Windows/Error.cpp | 40 ++-- src/OpenLoco/src/Windows/IndustryList.cpp | 33 +-- src/OpenLoco/src/Windows/IndustryWindow.cpp | 34 +-- .../src/Windows/KeyboardShortcuts.cpp | 9 +- .../src/Windows/LandscapeGeneration.cpp | 59 +++-- .../Windows/LandscapeGenerationConfirm.cpp | 5 +- src/OpenLoco/src/Windows/MapToolTip.cpp | 11 +- src/OpenLoco/src/Windows/MapWindow.cpp | 64 ++++-- src/OpenLoco/src/Windows/MessageWindow.cpp | 16 +- src/OpenLoco/src/Windows/MusicSelection.cpp | 13 +- src/OpenLoco/src/Windows/NetworkStatus.cpp | 5 +- src/OpenLoco/src/Windows/News/News.cpp | 43 ++-- src/OpenLoco/src/Windows/News/Ticker.cpp | 4 +- .../src/Windows/ObjectSelectionWindow.cpp | 49 +++-- src/OpenLoco/src/Windows/Options.cpp | 51 +++-- src/OpenLoco/src/Windows/PlayerInfoPanel.cpp | 13 +- src/OpenLoco/src/Windows/ProgressBar.cpp | 7 +- .../src/Windows/PromptBrowseWindow.cpp | 62 +++--- .../src/Windows/PromptOkCancelWindow.cpp | 5 +- src/OpenLoco/src/Windows/ScenarioOptions.cpp | 43 ++-- src/OpenLoco/src/Windows/ScenarioSelect.cpp | 42 ++-- src/OpenLoco/src/Windows/StationList.cpp | 21 +- src/OpenLoco/src/Windows/StationWindow.cpp | 38 ++-- src/OpenLoco/src/Windows/TerraForm.cpp | 48 +++-- src/OpenLoco/src/Windows/TextInputWindow.cpp | 13 +- src/OpenLoco/src/Windows/TileInspector.cpp | 21 +- src/OpenLoco/src/Windows/TimePanel.cpp | 11 +- src/OpenLoco/src/Windows/TitleExit.cpp | 8 +- src/OpenLoco/src/Windows/TitleLogo.cpp | 4 +- src/OpenLoco/src/Windows/TitleMenu.cpp | 19 +- src/OpenLoco/src/Windows/TitleOptions.cpp | 5 +- src/OpenLoco/src/Windows/TitleVersion.cpp | 5 +- src/OpenLoco/src/Windows/ToolTip.cpp | 35 +-- .../src/Windows/ToolbarBottomEditor.cpp | 25 ++- src/OpenLoco/src/Windows/ToolbarTop.cpp | 13 +- src/OpenLoco/src/Windows/ToolbarTopCommon.cpp | 7 +- src/OpenLoco/src/Windows/TownList.cpp | 37 ++-- src/OpenLoco/src/Windows/TownWindow.cpp | 23 +- src/OpenLoco/src/Windows/Tutorial.cpp | 7 +- src/OpenLoco/src/Windows/Vehicle.cpp | 99 +++++---- src/OpenLoco/src/Windows/VehicleList.cpp | 23 +- 99 files changed, 1234 insertions(+), 776 deletions(-) diff --git a/src/OpenLoco/src/Drawing/FPSCounter.cpp b/src/OpenLoco/src/Drawing/FPSCounter.cpp index ee3cb3d3ac..1a22a0cc07 100644 --- a/src/OpenLoco/src/Drawing/FPSCounter.cpp +++ b/src/OpenLoco/src/Drawing/FPSCounter.cpp @@ -1,4 +1,5 @@ #include "FPSCounter.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Localisation/StringManager.h" @@ -35,6 +36,8 @@ namespace OpenLoco::Drawing void drawFPS() { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Measure FPS const float fps = measureFPS(); @@ -50,10 +53,10 @@ namespace OpenLoco::Drawing auto& rt = Gfx::getScreenRT(); // Draw text - const int stringWidth = Gfx::getStringWidth(buffer); + const int stringWidth = drawingCtx.getStringWidth(buffer); const auto x = Ui::width() / 2 - (stringWidth / 2); const auto y = 2; - Gfx::drawString(rt, x, y, Colour::black, buffer); + drawingCtx.drawString(rt, x, y, Colour::black, buffer); // Make area dirty so the text doesn't get drawn over the last Gfx::invalidateRegion(x - 16, y - 4, x + 16, 16); diff --git a/src/OpenLoco/src/Drawing/SoftwareDrawingContext.cpp b/src/OpenLoco/src/Drawing/SoftwareDrawingContext.cpp index 928505dba9..0fa5520dcc 100644 --- a/src/OpenLoco/src/Drawing/SoftwareDrawingContext.cpp +++ b/src/OpenLoco/src/Drawing/SoftwareDrawingContext.cpp @@ -51,7 +51,9 @@ namespace OpenLoco::Drawing } static uint16_t getStringWidth(const char* buffer); - + static std::pair wrapString(char* buffer, uint16_t stringWidth); + static void drawRect(Gfx::RenderTarget& rt, int16_t x, int16_t y, uint16_t dx, uint16_t dy, uint32_t colour); + // 0x0112C876 static int16_t getCurrentFontSpriteBase() { @@ -488,13 +490,7 @@ namespace OpenLoco::Drawing } // 0x00448C79 - void drawImage(Gfx::RenderTarget* rt, int16_t x, int16_t y, uint32_t image) - { - drawImage(*rt, { x, y }, ImageId::fromUInt32(image)); - } - - // 0x00448C79 - void drawImage(Gfx::RenderTarget& rt, const Ui::Point& pos, const ImageId& image) + static void drawImage(Gfx::RenderTarget& rt, const Ui::Point& pos, const ImageId& image) { const auto* noiseImage = getNoiseMaskImageFromImage(image); const auto palette = PaletteMap::getForImage(image); @@ -509,6 +505,12 @@ namespace OpenLoco::Drawing } } + // 0x00448C79 + static void drawImage(Gfx::RenderTarget* rt, int16_t x, int16_t y, uint32_t image) + { + drawImage(*rt, { x, y }, ImageId::fromUInt32(image)); + } + void drawImageSolid(Gfx::RenderTarget& rt, const Ui::Point& pos, const ImageId& image, PaletteIndex_t paletteIndex) { PaletteMap::Buffer palette; @@ -1056,25 +1058,6 @@ namespace OpenLoco::Drawing return point.y; } - // 0x00494B3F - // al: colour - // bx: string id - // cx: x - // dx: y - // esi: args - // edi: rt - static void drawStringLeft( - RenderTarget& rt, - int16_t x, - int16_t y, - AdvancedColour colour, - string_id stringId, - const void* args) - { - Point origin = { x, y }; - drawStringLeft(rt, &origin, colour, stringId, args); - } - /** * * @param rt @ @@ -1100,6 +1083,25 @@ namespace OpenLoco::Drawing origin->y = point.y; } + // 0x00494B3F + // al: colour + // bx: string id + // cx: x + // dx: y + // esi: args + // edi: rt + static void drawStringLeft( + RenderTarget& rt, + int16_t x, + int16_t y, + AdvancedColour colour, + string_id stringId, + const void* args) + { + Point origin = { x, y }; + drawStringLeft(rt, &origin, colour, stringId, args); + } + // 0x00494BBF // al: colour // bx: string id diff --git a/src/OpenLoco/src/Drawing/SoftwareDrawingContext.h b/src/OpenLoco/src/Drawing/SoftwareDrawingContext.h index 41851362c4..db7e9e09aa 100644 --- a/src/OpenLoco/src/Drawing/SoftwareDrawingContext.h +++ b/src/OpenLoco/src/Drawing/SoftwareDrawingContext.h @@ -1,7 +1,7 @@ #pragma once -#include "Graphics/PaletteMap.h" #include "Graphics/Gfx.h" +#include "Graphics/PaletteMap.h" #include "Types.hpp" #include "Ui/Rect.h" #include @@ -9,7 +9,7 @@ namespace OpenLoco::Drawing { class SoftwareDrawingContext - { + { public: void clear(Gfx::RenderTarget& rt, uint32_t fill); void clearSingle(Gfx::RenderTarget& rt, uint8_t paletteId); diff --git a/src/OpenLoco/src/Entities/Misc.cpp b/src/OpenLoco/src/Entities/Misc.cpp index d943be364f..36208a4847 100644 --- a/src/OpenLoco/src/Entities/Misc.cpp +++ b/src/OpenLoco/src/Entities/Misc.cpp @@ -1,4 +1,5 @@ #include "Misc.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "EntityManager.h" #include "Localisation/FormatArguments.hpp" #include "Localisation/StringIds.h" @@ -341,8 +342,9 @@ namespace OpenLoco char buffer[255] = {}; auto args = FormatArguments::common(amount); StringManager::formatString(buffer, strFormat, &args); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - m->offsetX = -Gfx::getStringWidth(buffer) / 2; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + m->offsetX = -drawingCtx.getStringWidth(buffer) / 2; m->wiggle = 0; } return m; diff --git a/src/OpenLoco/src/Graphics/Gfx.cpp b/src/OpenLoco/src/Graphics/Gfx.cpp index d8cda0fc9a..e45dd1b8d6 100644 --- a/src/OpenLoco/src/Graphics/Gfx.cpp +++ b/src/OpenLoco/src/Graphics/Gfx.cpp @@ -341,7 +341,7 @@ namespace OpenLoco::Gfx } loco_global _50B860; - + G1Element* getG1Element(uint32_t imageId) { const auto id = getImageIndex(imageId); @@ -389,10 +389,12 @@ namespace OpenLoco::Gfx /*.zoom_level = */ 0, }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw all the images ontop of the one bitmap for (size_t i = 0; i < numImages; ++i) { - drawImage(rt, { 0, 0 }, baseImageId.withIndexOffset(i)); + drawingCtx.drawImage(rt, { 0, 0 }, baseImageId.withIndexOffset(i)); } // Explore the bitmap to find the extents of the images drawn diff --git a/src/OpenLoco/src/Graphics/Gfx.h b/src/OpenLoco/src/Graphics/Gfx.h index 0c9913ad07..3916b7c586 100644 --- a/src/OpenLoco/src/Graphics/Gfx.h +++ b/src/OpenLoco/src/Graphics/Gfx.h @@ -235,10 +235,6 @@ namespace OpenLoco::Gfx G1Element* getG1Element(uint32_t id); - // 0x0112C876 - int16_t getCurrentFontSpriteBase(); - void setCurrentFontSpriteBase(int16_t base); - Drawing::SoftwareDrawingEngine& getDrawingEngine(); void loadCurrency(); diff --git a/src/OpenLoco/src/Interop/Hooks.cpp b/src/OpenLoco/src/Interop/Hooks.cpp index 0f8e9475f6..1a3f3da8f1 100644 --- a/src/OpenLoco/src/Interop/Hooks.cpp +++ b/src/OpenLoco/src/Interop/Hooks.cpp @@ -9,6 +9,7 @@ #include "Audio/Audio.h" #include "Config.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "Environment.h" #include "Game.h" @@ -682,7 +683,8 @@ void OpenLoco::Interop::registerHooks() 0x00451025, [](registers& regs) FORCE_ALIGN_ARG_POINTER -> uint8_t { registers backup = regs; - auto pos = Gfx::drawString(*X86Pointer(regs.edi), regs.cx, regs.dx, static_cast(regs.al), X86Pointer(regs.esi)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto pos = drawingCtx.drawString(*X86Pointer(regs.edi), regs.cx, regs.dx, static_cast(regs.al), X86Pointer(regs.esi)); regs = backup; regs.cx = pos.x; regs.dx = pos.y; @@ -906,7 +908,8 @@ void OpenLoco::Interop::registerHooks() [](registers& regs) FORCE_ALIGN_ARG_POINTER -> uint8_t { registers backup = regs; Gfx::RenderTarget* rt = X86Pointer(regs.edi); - Gfx::drawImage(*rt, { regs.cx, regs.dx }, ImageId::fromUInt32(regs.ebx)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(*rt, { regs.cx, regs.dx }, ImageId::fromUInt32(regs.ebx)); regs = backup; return 0; diff --git a/src/OpenLoco/src/Objects/AirportObject.cpp b/src/OpenLoco/src/Objects/AirportObject.cpp index f9408023c9..0ef940a6db 100644 --- a/src/OpenLoco/src/Objects/AirportObject.cpp +++ b/src/OpenLoco/src/Objects/AirportObject.cpp @@ -1,4 +1,5 @@ #include "AirportObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -13,7 +14,8 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); - Gfx::drawImage(&rt, x - 34, y - 34, colourImage); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 34, y - 34, colourImage); } // 0x00490DE7 diff --git a/src/OpenLoco/src/Objects/BridgeObject.cpp b/src/OpenLoco/src/Objects/BridgeObject.cpp index 108e7fb2cd..1833870b6c 100644 --- a/src/OpenLoco/src/Objects/BridgeObject.cpp +++ b/src/OpenLoco/src/Objects/BridgeObject.cpp @@ -1,4 +1,5 @@ #include "BridgeObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -13,7 +14,8 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); - Gfx::drawImage(&rt, x - 21, y - 9, colourImage); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 21, y - 9, colourImage); } // 0x0042C651 diff --git a/src/OpenLoco/src/Objects/CliffEdgeObject.cpp b/src/OpenLoco/src/Objects/CliffEdgeObject.cpp index e6620250a9..1dd657eaff 100644 --- a/src/OpenLoco/src/Objects/CliffEdgeObject.cpp +++ b/src/OpenLoco/src/Objects/CliffEdgeObject.cpp @@ -1,4 +1,5 @@ #include "CliffEdgeObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -37,7 +38,8 @@ namespace OpenLoco // 0x00469A06 void CliffEdgeObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { - Gfx::drawImage(&rt, x - 30, y, image); - Gfx::drawImage(&rt, x - 30, y, image + 16); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 30, y, image); + drawingCtx.drawImage(&rt, x - 30, y, image + 16); } } diff --git a/src/OpenLoco/src/Objects/CompetitorObject.cpp b/src/OpenLoco/src/Objects/CompetitorObject.cpp index 9b26d8819a..d6d904e965 100644 --- a/src/OpenLoco/src/Objects/CompetitorObject.cpp +++ b/src/OpenLoco/src/Objects/CompetitorObject.cpp @@ -1,4 +1,5 @@ #include "CompetitorObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -14,22 +15,25 @@ namespace OpenLoco // 0x00434D5B void CompetitorObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { - Gfx::drawRect(rt, 0, 0, kObjectPreviewSize.width, kObjectPreviewSize.height, AdvancedColour(Colour::mutedOrange).inset().u8()); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.drawRect(rt, 0, 0, kObjectPreviewSize.width, kObjectPreviewSize.height, AdvancedColour(Colour::mutedOrange).inset().u8()); auto image = Gfx::recolour(images[0], Colour::mutedSeaGreen); - Gfx::drawImage(&rt, x - 32, y - 32, image); + drawingCtx.drawImage(&rt, x - 32, y - 32, image); } // 0x00434DA7 void CompetitorObject::drawDescription(Gfx::RenderTarget& rt, const int16_t x, const int16_t y, [[maybe_unused]] const int16_t width) const { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); Ui::Point rowPosition = { x, y }; { auto args = FormatArguments(); args.push(intelligence); args.push(aiRatingToLevel(intelligence)); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_intelligence, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_intelligence, &args); rowPosition.y += kDescriptionRowHeight; } { @@ -37,7 +41,7 @@ namespace OpenLoco args.push(aggressiveness); args.push(aiRatingToLevel(aggressiveness)); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_aggressiveness, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_aggressiveness, &args); rowPosition.y += kDescriptionRowHeight; } { @@ -45,7 +49,7 @@ namespace OpenLoco args.push(competitiveness); args.push(aiRatingToLevel(competitiveness)); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_competitiveness, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::company_details_competitiveness, &args); } } diff --git a/src/OpenLoco/src/Objects/CurrencyObject.cpp b/src/OpenLoco/src/Objects/CurrencyObject.cpp index 79bbf6a31a..067e769b30 100644 --- a/src/OpenLoco/src/Objects/CurrencyObject.cpp +++ b/src/OpenLoco/src/Objects/CurrencyObject.cpp @@ -1,4 +1,5 @@ #include "CurrencyObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" @@ -76,7 +77,8 @@ namespace OpenLoco auto defaultWidth = _characterWidths[Font::large + 131]; _characterWidths[Font::large + 131] = currencyElement->width + 1; - Gfx::drawStringCentred(rt, x, y - 9, Colour::black, StringIds::object_currency_big_font); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringCentred(rt, x, y - 9, Colour::black, StringIds::object_currency_big_font); _characterWidths[Font::large + 131] = defaultWidth; *defaultElement = backupElement; diff --git a/src/OpenLoco/src/Objects/DockObject.cpp b/src/OpenLoco/src/Objects/DockObject.cpp index 185f3730f4..61f5a77bf7 100644 --- a/src/OpenLoco/src/Objects/DockObject.cpp +++ b/src/OpenLoco/src/Objects/DockObject.cpp @@ -1,4 +1,5 @@ #include "DockObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -11,7 +12,8 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); - Gfx::drawImage(&rt, x - 34, y - 34, colourImage); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 34, y - 34, colourImage); } // 0x00490F2C diff --git a/src/OpenLoco/src/Objects/HillShapesObject.cpp b/src/OpenLoco/src/Objects/HillShapesObject.cpp index 10418dea5f..50829ae83f 100644 --- a/src/OpenLoco/src/Objects/HillShapesObject.cpp +++ b/src/OpenLoco/src/Objects/HillShapesObject.cpp @@ -1,4 +1,5 @@ #include "HillShapesObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" #include "ObjectImageTable.h" @@ -13,7 +14,8 @@ namespace OpenLoco { auto imageId = image + hillHeightMapCount + mountainHeightMapCount; - Gfx::drawImage(&rt, x, y, imageId); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, imageId); } // 0x00463B70 diff --git a/src/OpenLoco/src/Objects/IndustryObject.cpp b/src/OpenLoco/src/Objects/IndustryObject.cpp index bebb2cddbd..bf13682ee5 100644 --- a/src/OpenLoco/src/Objects/IndustryObject.cpp +++ b/src/OpenLoco/src/Objects/IndustryObject.cpp @@ -1,5 +1,6 @@ #include "IndustryObject.h" #include "CargoObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -103,10 +104,11 @@ namespace OpenLoco : Colour::black; ImageId baseImage(var_12, c); Ui::Point pos{ x, y }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); for (const auto part : getBuildingParts(0)) { auto image = baseImage.withIndexOffset(part * 4 + 1); - Gfx::drawImage(*clipped, pos, image); + drawingCtx.drawImage(*clipped, pos, image); pos.y -= buildingPartHeight[part]; } } diff --git a/src/OpenLoco/src/Objects/InterfaceSkinObject.cpp b/src/OpenLoco/src/Objects/InterfaceSkinObject.cpp index 05f2154439..073b944e2e 100644 --- a/src/OpenLoco/src/Objects/InterfaceSkinObject.cpp +++ b/src/OpenLoco/src/Objects/InterfaceSkinObject.cpp @@ -1,4 +1,5 @@ #include "InterfaceSkinObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -30,7 +31,7 @@ namespace OpenLoco void InterfaceSkinObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { auto image = Gfx::recolour(img + InterfaceSkin::ImageIds::preview_image, Colour::mutedSeaGreen); - - Gfx::drawImage(&rt, x - 32, y - 32, image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 32, y - 32, image); } } diff --git a/src/OpenLoco/src/Objects/LandObject.cpp b/src/OpenLoco/src/Objects/LandObject.cpp index b9aec4d807..820c9bebae 100644 --- a/src/OpenLoco/src/Objects/LandObject.cpp +++ b/src/OpenLoco/src/Objects/LandObject.cpp @@ -1,5 +1,6 @@ #include "LandObject.h" #include "CliffEdgeObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -96,6 +97,7 @@ namespace OpenLoco void LandObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { uint32_t imageId = image + (var_03 - 1) * var_0E; - Gfx::drawImage(&rt, x, y, imageId); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, imageId); } } diff --git a/src/OpenLoco/src/Objects/LevelCrossingObject.cpp b/src/OpenLoco/src/Objects/LevelCrossingObject.cpp index bdb8c17796..892b9d75ef 100644 --- a/src/OpenLoco/src/Objects/LevelCrossingObject.cpp +++ b/src/OpenLoco/src/Objects/LevelCrossingObject.cpp @@ -1,4 +1,5 @@ #include "LevelCrossingObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" #include "ObjectImageTable.h" @@ -70,10 +71,11 @@ namespace OpenLoco imageId += frameIndex; imageId += image; - Gfx::drawImage(&rt, x, y, imageId); - Gfx::drawImage(&rt, x, y, imageId + 1); - Gfx::drawImage(&rt, x, y, imageId + 2); - Gfx::drawImage(&rt, x, y, imageId + 3); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, imageId); + drawingCtx.drawImage(&rt, x, y, imageId + 1); + drawingCtx.drawImage(&rt, x, y, imageId + 2); + drawingCtx.drawImage(&rt, x, y, imageId + 3); } // 0x004781A4 diff --git a/src/OpenLoco/src/Objects/ObjectManager.cpp b/src/OpenLoco/src/Objects/ObjectManager.cpp index 88c35b2420..cf8da2c84e 100644 --- a/src/OpenLoco/src/Objects/ObjectManager.cpp +++ b/src/OpenLoco/src/Objects/ObjectManager.cpp @@ -9,6 +9,7 @@ #include "Console.h" #include "CurrencyObject.h" #include "DockObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Environment.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -1035,11 +1036,13 @@ namespace OpenLoco::ObjectManager void drawGenericDescription(Gfx::RenderTarget& rt, Ui::Point& rowPosition, const uint16_t designed, const uint16_t obsolete) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + if (designed != 0) { FormatArguments args{}; args.push(designed); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_designed, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_designed, &args); rowPosition.y += kDescriptionRowHeight; } @@ -1047,7 +1050,7 @@ namespace OpenLoco::ObjectManager { FormatArguments args{}; args.push(obsolete); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_obsolete, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_obsolete, &args); rowPosition.y += kDescriptionRowHeight; } } diff --git a/src/OpenLoco/src/Objects/RegionObject.cpp b/src/OpenLoco/src/Objects/RegionObject.cpp index 449229d917..ab6d28c4c6 100644 --- a/src/OpenLoco/src/Objects/RegionObject.cpp +++ b/src/OpenLoco/src/Objects/RegionObject.cpp @@ -1,4 +1,5 @@ #include "RegionObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" #include "ObjectManager.h" @@ -8,7 +9,8 @@ namespace OpenLoco // 0x0043CB93 void RegionObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { - Gfx::drawImage(&rt, x, y, image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, image); } // 0x0043CA8C diff --git a/src/OpenLoco/src/Objects/RoadExtraObject.cpp b/src/OpenLoco/src/Objects/RoadExtraObject.cpp index cf1f2739c6..2cbac82cc9 100644 --- a/src/OpenLoco/src/Objects/RoadExtraObject.cpp +++ b/src/OpenLoco/src/Objects/RoadExtraObject.cpp @@ -1,4 +1,5 @@ #include "RoadExtraObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -14,11 +15,12 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); - Gfx::drawImage(&rt, x, y, colourImage + 36); - Gfx::drawImage(&rt, x, y, colourImage + 37); - Gfx::drawImage(&rt, x, y, colourImage); - Gfx::drawImage(&rt, x, y, colourImage + 33); - Gfx::drawImage(&rt, x, y, colourImage + 32); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, colourImage + 36); + drawingCtx.drawImage(&rt, x, y, colourImage + 37); + drawingCtx.drawImage(&rt, x, y, colourImage); + drawingCtx.drawImage(&rt, x, y, colourImage + 33); + drawingCtx.drawImage(&rt, x, y, colourImage + 32); } // 0x00477E92 diff --git a/src/OpenLoco/src/Objects/RoadObject.cpp b/src/OpenLoco/src/Objects/RoadObject.cpp index 13d708f366..ff47be0a26 100644 --- a/src/OpenLoco/src/Objects/RoadObject.cpp +++ b/src/OpenLoco/src/Objects/RoadObject.cpp @@ -1,4 +1,5 @@ #include "RoadObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -9,15 +10,16 @@ namespace OpenLoco void RoadObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); if (paintStyle == 1) { - Gfx::drawImage(&rt, x, y, colourImage + 34); - Gfx::drawImage(&rt, x, y, colourImage + 36); - Gfx::drawImage(&rt, x, y, colourImage + 38); + drawingCtx.drawImage(&rt, x, y, colourImage + 34); + drawingCtx.drawImage(&rt, x, y, colourImage + 36); + drawingCtx.drawImage(&rt, x, y, colourImage + 38); } else { - Gfx::drawImage(&rt, x, y, colourImage + 34); + drawingCtx.drawImage(&rt, x, y, colourImage + 34); } } diff --git a/src/OpenLoco/src/Objects/RoadStationObject.cpp b/src/OpenLoco/src/Objects/RoadStationObject.cpp index 3ada918076..33589f1129 100644 --- a/src/OpenLoco/src/Objects/RoadStationObject.cpp +++ b/src/OpenLoco/src/Objects/RoadStationObject.cpp @@ -1,4 +1,5 @@ #include "RoadStationObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -11,7 +12,8 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); - Gfx::drawImage(&rt, x - 34, y - 34, colourImage); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 34, y - 34, colourImage); auto colour = ExtColour::translucentMutedDarkRed1; if (!(flags & RoadStationFlags::recolourable)) @@ -21,7 +23,7 @@ namespace OpenLoco auto translucentImage = Gfx::recolourTranslucent(image + 1, colour); - Gfx::drawImage(&rt, x - 34, y - 34, translucentImage); + drawingCtx.drawImage(&rt, x - 34, y - 34, translucentImage); } // 0x00490C59 diff --git a/src/OpenLoco/src/Objects/ScaffoldingObject.cpp b/src/OpenLoco/src/Objects/ScaffoldingObject.cpp index b841b08f1a..6dc3170f93 100644 --- a/src/OpenLoco/src/Objects/ScaffoldingObject.cpp +++ b/src/OpenLoco/src/Objects/ScaffoldingObject.cpp @@ -1,4 +1,5 @@ #include "ScaffoldingObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -14,9 +15,10 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::yellow); - Gfx::drawImage(&rt, x, y + 23, colourImage + Scaffolding::ImageIds::type21x1SegmentBack); - Gfx::drawImage(&rt, x, y + 23, colourImage + Scaffolding::ImageIds::type21x1SegmentFront); - Gfx::drawImage(&rt, x, y + 23, colourImage + Scaffolding::ImageIds::type21x1RoofSE); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y + 23, colourImage + Scaffolding::ImageIds::type21x1SegmentBack); + drawingCtx.drawImage(&rt, x, y + 23, colourImage + Scaffolding::ImageIds::type21x1SegmentFront); + drawingCtx.drawImage(&rt, x, y + 23, colourImage + Scaffolding::ImageIds::type21x1RoofSE); } // 0x0042DED8 diff --git a/src/OpenLoco/src/Objects/SnowObject.cpp b/src/OpenLoco/src/Objects/SnowObject.cpp index 905b0295ae..402e50c961 100644 --- a/src/OpenLoco/src/Objects/SnowObject.cpp +++ b/src/OpenLoco/src/Objects/SnowObject.cpp @@ -1,4 +1,5 @@ #include "SnowObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" #include "ObjectImageTable.h" @@ -10,7 +11,8 @@ namespace OpenLoco // 0x00469A75 void SnowObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { - Gfx::drawImage(&rt, x, y, image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, image); } // 0x00469A35 diff --git a/src/OpenLoco/src/Objects/StreetLightObject.cpp b/src/OpenLoco/src/Objects/StreetLightObject.cpp index 241f4b9474..1d536386cb 100644 --- a/src/OpenLoco/src/Objects/StreetLightObject.cpp +++ b/src/OpenLoco/src/Objects/StreetLightObject.cpp @@ -1,4 +1,5 @@ #include "StreetLightObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" #include "ObjectImageTable.h" @@ -15,11 +16,12 @@ namespace OpenLoco void StreetLightObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { Ui::Point imgPosition = Ui::Point{ x, y } - Ui::Point{ 20, 1 }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); for (auto i = 0; i < 3; i++) { auto imageId = (i * 4) + image; - Gfx::drawImage(&rt, imgPosition.x - 14, imgPosition.y, imageId + 2); - Gfx::drawImage(&rt, imgPosition.x, imgPosition.y - 7, imageId); + drawingCtx.drawImage(&rt, imgPosition.x - 14, imgPosition.y, imageId + 2); + drawingCtx.drawImage(&rt, imgPosition.x, imgPosition.y - 7, imageId); imgPosition.x += 20; imgPosition.y += kDescriptionRowHeight; } diff --git a/src/OpenLoco/src/Objects/TrackExtraObject.cpp b/src/OpenLoco/src/Objects/TrackExtraObject.cpp index 9ac19bf429..4e90d4bfff 100644 --- a/src/OpenLoco/src/Objects/TrackExtraObject.cpp +++ b/src/OpenLoco/src/Objects/TrackExtraObject.cpp @@ -1,4 +1,5 @@ #include "TrackExtraObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -14,15 +15,16 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); if (paintStyle == 0) { - Gfx::drawImage(&rt, x, y, colourImage); + drawingCtx.drawImage(&rt, x, y, colourImage); } else { - Gfx::drawImage(&rt, x, y, colourImage); - Gfx::drawImage(&rt, x, y, colourImage + 97); - Gfx::drawImage(&rt, x, y, colourImage + 96); + drawingCtx.drawImage(&rt, x, y, colourImage); + drawingCtx.drawImage(&rt, x, y, colourImage + 97); + drawingCtx.drawImage(&rt, x, y, colourImage + 96); } } diff --git a/src/OpenLoco/src/Objects/TrackObject.cpp b/src/OpenLoco/src/Objects/TrackObject.cpp index 8382d2187e..ce77b3ac32 100644 --- a/src/OpenLoco/src/Objects/TrackObject.cpp +++ b/src/OpenLoco/src/Objects/TrackObject.cpp @@ -1,4 +1,5 @@ #include "TrackObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -11,9 +12,10 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); - Gfx::drawImage(&rt, x, y, colourImage + 18); - Gfx::drawImage(&rt, x, y, colourImage + 20); - Gfx::drawImage(&rt, x, y, colourImage + 22); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, colourImage + 18); + drawingCtx.drawImage(&rt, x, y, colourImage + 20); + drawingCtx.drawImage(&rt, x, y, colourImage + 22); } // 0x004A6C6C diff --git a/src/OpenLoco/src/Objects/TrainSignalObject.cpp b/src/OpenLoco/src/Objects/TrainSignalObject.cpp index d16ad80e69..c4c5bfca1f 100644 --- a/src/OpenLoco/src/Objects/TrainSignalObject.cpp +++ b/src/OpenLoco/src/Objects/TrainSignalObject.cpp @@ -1,4 +1,5 @@ #include "TrainSignalObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -107,6 +108,7 @@ namespace OpenLoco frameIndex *= 8; auto colourImage = image + frameIndex; - Gfx::drawImage(&rt, x, y + 15, colourImage); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y + 15, colourImage); } } diff --git a/src/OpenLoco/src/Objects/TrainStationObject.cpp b/src/OpenLoco/src/Objects/TrainStationObject.cpp index 3e44f4b687..1ded0b40ca 100644 --- a/src/OpenLoco/src/Objects/TrainStationObject.cpp +++ b/src/OpenLoco/src/Objects/TrainStationObject.cpp @@ -1,4 +1,5 @@ #include "TrainStationObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -14,7 +15,8 @@ namespace OpenLoco { auto colourImage = Gfx::recolour(image, Colour::mutedDarkRed); - Gfx::drawImage(&rt, x - 34, y - 34, colourImage); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 34, y - 34, colourImage); auto colour = ExtColour::translucentMutedDarkRed1; if (!(flags & TrainStationFlags::recolourable)) @@ -24,7 +26,7 @@ namespace OpenLoco auto translucentImage = Gfx::recolourTranslucent(image + 1, colour); - Gfx::drawImage(&rt, x - 34, y - 34, translucentImage); + drawingCtx.drawImage(&rt, x - 34, y - 34, translucentImage); } // 0x00490A68 diff --git a/src/OpenLoco/src/Objects/TreeObject.cpp b/src/OpenLoco/src/Objects/TreeObject.cpp index 4150bac874..5a4754164b 100644 --- a/src/OpenLoco/src/Objects/TreeObject.cpp +++ b/src/OpenLoco/src/Objects/TreeObject.cpp @@ -1,4 +1,5 @@ #include "TreeObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -25,6 +26,7 @@ namespace OpenLoco image = Gfx::recolour(image, colour); } + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); Ui::Point treePos = Ui::Point{ x, y } + Ui::Point{ 0, 48 }; if (flags & TreeObjectFlags::hasSnowVariation) @@ -42,10 +44,10 @@ namespace OpenLoco snowImage = Gfx::recolour(snowImage, colour); } treePos.x = x + 28; - Gfx::drawImage(&rt, treePos.x, treePos.y, snowImage); + drawingCtx.drawImage(&rt, treePos.x, treePos.y, snowImage); treePos.x = 28; } - Gfx::drawImage(&rt, treePos.x, treePos.y, image); + drawingCtx.drawImage(&rt, treePos.x, treePos.y, image); } // 0x00500775 diff --git a/src/OpenLoco/src/Objects/TunnelObject.cpp b/src/OpenLoco/src/Objects/TunnelObject.cpp index 8b0c63b96f..680d376d74 100644 --- a/src/OpenLoco/src/Objects/TunnelObject.cpp +++ b/src/OpenLoco/src/Objects/TunnelObject.cpp @@ -1,4 +1,5 @@ #include "TunnelObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" #include "ObjectImageTable.h" @@ -11,8 +12,9 @@ namespace OpenLoco // 0x00469806 void TunnelObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { - Gfx::drawImage(&rt, x - 16, y + 15, image); - Gfx::drawImage(&rt, x - 16, y + 15, image + 1); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x - 16, y + 15, image); + drawingCtx.drawImage(&rt, x - 16, y + 15, image + 1); } // 0x004697C9 diff --git a/src/OpenLoco/src/Objects/VehicleObject.cpp b/src/OpenLoco/src/Objects/VehicleObject.cpp index ca307f6bf0..5cda0247b6 100644 --- a/src/OpenLoco/src/Objects/VehicleObject.cpp +++ b/src/OpenLoco/src/Objects/VehicleObject.cpp @@ -1,5 +1,6 @@ #include "VehicleObject.h" #include "CargoObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Localisation/FormatArguments.hpp" @@ -45,30 +46,31 @@ namespace OpenLoco void VehicleObject::drawDescription(Gfx::RenderTarget& rt, const int16_t x, const int16_t y, const int16_t width) const { Ui::Point rowPosition = { x, y }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); ObjectManager::drawGenericDescription(rt, rowPosition, designed, obsolete); if (power != 0 && (mode == TransportMode::road || mode == TransportMode::rail)) { FormatArguments args{}; args.push(power); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_power, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_power, &args); rowPosition.y += kDescriptionRowHeight; } { FormatArguments args{}; args.push(StringManager::internalLengthToComma1DP(getLength())); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_length, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_length, &args); rowPosition.y += kDescriptionRowHeight; } { FormatArguments args{}; args.push(weight); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_weight, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_weight, &args); rowPosition.y += kDescriptionRowHeight; } { FormatArguments args{}; args.push(speed); - Gfx::drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_max_speed, &args); + drawingCtx.drawStringLeft(rt, rowPosition.x, rowPosition.y, Colour::black, StringIds::object_selection_max_speed, &args); } auto buffer = const_cast(StringManager::getString(StringIds::buffer_1250)); // Clear buffer @@ -78,7 +80,7 @@ namespace OpenLoco if (StringManager::locoStrlen(buffer) != 0) { - Gfx::drawStringLeftWrapped(rt, rowPosition.x, rowPosition.y, width - 4, Colour::black, StringIds::buffer_1250); + drawingCtx.drawStringLeftWrapped(rt, rowPosition.x, rowPosition.y, width - 4, Colour::black, StringIds::buffer_1250); } } diff --git a/src/OpenLoco/src/Objects/WallObject.cpp b/src/OpenLoco/src/Objects/WallObject.cpp index e281afbe61..6be9e54121 100644 --- a/src/OpenLoco/src/Objects/WallObject.cpp +++ b/src/OpenLoco/src/Objects/WallObject.cpp @@ -1,4 +1,5 @@ #include "WallObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -46,16 +47,17 @@ namespace OpenLoco image = Gfx::recolour(sprite, Colour::mutedDarkRed); } - Gfx::drawImage(&rt, x + 14, y + 16 + (var_08 * 2), image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x + 14, y + 16 + (var_08 * 2), image); if (flags & (1 << 1)) { - Gfx::drawImage(&rt, x + 14, y + 16 + (var_08 * 2), Gfx::recolourTranslucent(sprite + 6, ExtColour::unk8C)); + drawingCtx.drawImage(&rt, x + 14, y + 16 + (var_08 * 2), Gfx::recolourTranslucent(sprite + 6, ExtColour::unk8C)); } else { if (flags & (1 << 4)) { - Gfx::drawImage(&rt, x + 14, y + 16 + (var_08 * 2), image + 1); + drawingCtx.drawImage(&rt, x + 14, y + 16 + (var_08 * 2), image + 1); } } } diff --git a/src/OpenLoco/src/Objects/WaterObject.cpp b/src/OpenLoco/src/Objects/WaterObject.cpp index 68ab95836f..e6cb29e925 100644 --- a/src/OpenLoco/src/Objects/WaterObject.cpp +++ b/src/OpenLoco/src/Objects/WaterObject.cpp @@ -1,4 +1,5 @@ #include "WaterObject.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Interop/Interop.hpp" @@ -54,7 +55,8 @@ namespace OpenLoco void WaterObject::drawPreviewImage(Gfx::RenderTarget& rt, const int16_t x, const int16_t y) const { auto colourImage = Gfx::recolourTranslucent(Gfx::recolour(image + 35), ExtColour::null); - Gfx::drawImage(&rt, x, y, colourImage); - Gfx::drawImage(&rt, x, y, image + 30); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(&rt, x, y, colourImage); + drawingCtx.drawImage(&rt, x, y, image + 30); } } diff --git a/src/OpenLoco/src/OpenLoco.cpp b/src/OpenLoco/src/OpenLoco.cpp index 91fd0e283d..83296d4866 100644 --- a/src/OpenLoco/src/OpenLoco.cpp +++ b/src/OpenLoco/src/OpenLoco.cpp @@ -27,6 +27,7 @@ #include "Config.h" #include "Console.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Economy/Economy.h" #include "EditorController.h" #include "Entities/EntityManager.h" @@ -312,7 +313,8 @@ namespace OpenLoco } Title::start(); Gui::init(); - Gfx::clear(Gfx::getScreenRT(), 0x0A0A0A0A); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clear(Gfx::getScreenRT(), 0x0A0A0A0A); } static void loadFile(const fs::path& path) @@ -515,6 +517,8 @@ namespace OpenLoco try { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + addr<0x00113E87C, int32_t>() = 0; addr<0x0005252E0, int32_t>() = 0; if (!isInitialised) @@ -556,7 +560,7 @@ namespace OpenLoco Config::get().old.var_72 = 16; const auto cursor = Ui::getCursorPos(); addr<0x00F2538C, Ui::Point32>() = cursor; - Gfx::clear(Gfx::getScreenRT(), 0); + drawingCtx.clear(Gfx::getScreenRT(), 0); addr<0x00F2539C, int32_t>() = 0; } else diff --git a/src/OpenLoco/src/Paint/Paint.cpp b/src/OpenLoco/src/Paint/Paint.cpp index 78fab355db..aca0f7065e 100644 --- a/src/OpenLoco/src/Paint/Paint.cpp +++ b/src/OpenLoco/src/Paint/Paint.cpp @@ -1,4 +1,5 @@ #include "Paint.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Game.h" #include "Graphics/Gfx.h" #include "Graphics/PaletteMap.h" @@ -783,7 +784,8 @@ namespace OpenLoco::Paint unZoomedRt.width >>= zoom; unZoomedRt.height >>= zoom; - Gfx::setCurrentFontSpriteBase(zoom == 0 ? Font::medium_bold : Font::small); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(zoom == 0 ? Font::medium_bold : Font::small); char buffer[512]{}; @@ -795,7 +797,7 @@ namespace OpenLoco::Paint Ui::WindowManager::setWindowColours(0, AdvancedColour(static_cast(psString->colour))); Ui::WindowManager::setWindowColours(1, AdvancedColour(static_cast(psString->colour))); - Gfx::drawStringYOffsets(unZoomedRt, loc, Colour::black, buffer, psString->yOffsets); + drawingCtx.drawStringYOffsets(unZoomedRt, loc, Colour::black, buffer, psString->yOffsets); } } diff --git a/src/OpenLoco/src/Ui/Dropdown.cpp b/src/OpenLoco/src/Ui/Dropdown.cpp index 4b839c03d9..a9444b3c3c 100644 --- a/src/OpenLoco/src/Ui/Dropdown.cpp +++ b/src/OpenLoco/src/Ui/Dropdown.cpp @@ -1,6 +1,7 @@ #include "Dropdown.h" #include "CompanyManager.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Engine/Limits.h" #include "Graphics/ImageIds.h" #include "Input.h" @@ -185,18 +186,21 @@ namespace OpenLoco::Ui::Dropdown { StringManager::formatString(_byte_112CC04, stringId, &args); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); - Gfx::clipString(width, _byte_112CC04); + drawingCtx.clipString(width, _byte_112CC04); - Gfx::setCurrentFontSpriteBase(Font::m1); + drawingCtx.setCurrentFontSpriteBase(Font::m1); - Gfx::drawString(*rt, x, y, colour, _byte_112CC04); + drawingCtx.drawString(*rt, x, y, colour, _byte_112CC04); } // 0x004CD00E static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); _windowDropdownOnpaintCellX = 0; _windowDropdownOnpaintCellY = 0; @@ -209,7 +213,7 @@ namespace OpenLoco::Ui::Dropdown { auto x = _windowDropdownOnpaintCellX * _dropdownItemWidth + self.x + 2; auto y = _windowDropdownOnpaintCellY * _dropdownItemHeight + self.y + 2; - Gfx::drawRect(*rt, x, y, _dropdownItemWidth, _dropdownItemHeight, (1 << 25) | PaletteIndex::index_2E); + drawingCtx.drawRect(*rt, x, y, _dropdownItemWidth, _dropdownItemHeight, (1 << 25) | PaletteIndex::index_2E); } auto args = FormatArguments(); @@ -262,7 +266,7 @@ namespace OpenLoco::Ui::Dropdown { imageId++; } - Gfx::drawImage(rt, x, y, imageId); + drawingCtx.drawImage(rt, x, y, imageId); } } else @@ -272,16 +276,16 @@ namespace OpenLoco::Ui::Dropdown if (!self.getColour(WindowColour::primary).isTranslucent()) { - Gfx::drawRect(*rt, x, y, _dropdownItemWidth - 1, 1, Colours::getShade(self.getColour(WindowColour::primary).c(), 3)); - Gfx::drawRect(*rt, x, y + 1, _dropdownItemWidth - 1, 1, Colours::getShade(self.getColour(WindowColour::primary).c(), 7)); + drawingCtx.drawRect(*rt, x, y, _dropdownItemWidth - 1, 1, Colours::getShade(self.getColour(WindowColour::primary).c(), 3)); + drawingCtx.drawRect(*rt, x, y + 1, _dropdownItemWidth - 1, 1, Colours::getShade(self.getColour(WindowColour::primary).c(), 7)); } else { uint32_t colour = enumValue(Colours::getTranslucent(self.getColour(WindowColour::primary).c())) | (1 << 25); colour++; // Gets ExtColour::translucentXXX2 highlight - Gfx::drawRect(*rt, x, y, _dropdownItemWidth - 1, 1, colour); + drawingCtx.drawRect(*rt, x, y, _dropdownItemWidth - 1, 1, colour); colour++; // Gets ExtColour::translucentXXX0 shadow - Gfx::drawRect(*rt, x, y + 1, _dropdownItemWidth - 1, 1, colour); + drawingCtx.drawRect(*rt, x, y + 1, _dropdownItemWidth - 1, 1, colour); } } @@ -346,6 +350,8 @@ namespace OpenLoco::Ui::Dropdown // 0x004CCAB2 static void showText(int16_t x, int16_t y, int16_t width, int16_t height, uint8_t itemHeight, AdvancedColour colour, size_t count, uint8_t flags) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + _dropdownColumnCount = 1; _dropdownItemWidth = 0; _dropdownItemHeight = 10; @@ -366,9 +372,9 @@ namespace OpenLoco::Ui::Dropdown StringManager::formatString(_byte_112CC04, _dropdownItemFormats[itemCount], &args); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); - auto stringWidth = Gfx::getMaxStringWidth(_byte_112CC04); + auto stringWidth = drawingCtx.getMaxStringWidth(_byte_112CC04); maxStringWidth = std::max(maxStringWidth, stringWidth); } diff --git a/src/OpenLoco/src/Ui/TextInput.cpp b/src/OpenLoco/src/Ui/TextInput.cpp index 5c6bfe04a6..77034a00a0 100644 --- a/src/OpenLoco/src/Ui/TextInput.cpp +++ b/src/OpenLoco/src/Ui/TextInput.cpp @@ -1,4 +1,5 @@ #include "Ui/TextInput.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Interop/Interop.hpp" #include "Localisation/StringManager.h" @@ -85,9 +86,10 @@ namespace OpenLoco::Ui::TextInput { std::string cursorStr = buffer.substr(0, cursorPosition); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - auto stringWidth = Gfx::getStringWidth(buffer.c_str()); - auto cursorX = Gfx::getStringWidth(cursorStr.c_str()); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + auto stringWidth = drawingCtx.getStringWidth(buffer.c_str()); + auto cursorX = drawingCtx.getStringWidth(cursorStr.c_str()); int x = xOffset + cursorX; @@ -112,9 +114,10 @@ namespace OpenLoco::Ui::TextInput { std::string cursorStr = buffer.substr(0, cursorPosition); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - auto stringWidth = Gfx::getStringWidth(buffer.c_str()); - auto cursorX = Gfx::getStringWidth(cursorStr.c_str()); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + auto stringWidth = drawingCtx.getStringWidth(buffer.c_str()); + auto cursorX = drawingCtx.getStringWidth(cursorStr.c_str()); auto midX = containerWidth / 2; diff --git a/src/OpenLoco/src/Ui/WindowManager.cpp b/src/OpenLoco/src/Ui/WindowManager.cpp index 4a605cfeb9..9688cb0961 100644 --- a/src/OpenLoco/src/Ui/WindowManager.cpp +++ b/src/OpenLoco/src/Ui/WindowManager.cpp @@ -3,6 +3,7 @@ #include "CompanyManager.h" #include "Config.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" #include "GameState.h" @@ -198,7 +199,8 @@ namespace OpenLoco::Ui::WindowManager [](registers& regs) FORCE_ALIGN_ARG_POINTER -> uint8_t { registers backup = regs; const char* buffer = (const char*)regs.esi; - uint16_t width = Gfx::getStringWidth(buffer); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + uint16_t width = drawingCtx.getStringWidth(buffer); regs = backup; regs.cx = width; diff --git a/src/OpenLoco/src/Vehicles/VehicleManager.cpp b/src/OpenLoco/src/Vehicles/VehicleManager.cpp index e88b4269e2..85c1e930cc 100644 --- a/src/OpenLoco/src/Vehicles/VehicleManager.cpp +++ b/src/OpenLoco/src/Vehicles/VehicleManager.cpp @@ -1,6 +1,7 @@ #include "VehicleManager.h" #include "Company.h" #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" #include "GameState.h" @@ -394,6 +395,7 @@ namespace OpenLoco::Vehicles::OrderManager } i = 1; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); for (auto& unk : _displayFrames) { auto order = Vehicles::OrderRingView(unk.orderOffset, 0).begin(); @@ -404,7 +406,7 @@ namespace OpenLoco::Vehicles::OrderManager auto [loc, str] = generateOrderUiStringAndLoc(order->getOffset(), i); const auto pos = Map::gameToScreen(loc, Ui::WindowManager::getCurrentRotation()); - auto stringWidth = Gfx::getStringWidth(str.c_str()); + auto stringWidth = drawingCtx.getStringWidth(str.c_str()); for (auto zoom = 0; zoom < 4; ++zoom) { // The first line of the label will always be at the centre diff --git a/src/OpenLoco/src/Viewport.cpp b/src/OpenLoco/src/Viewport.cpp index 3be2377a20..224ffea093 100644 --- a/src/OpenLoco/src/Viewport.cpp +++ b/src/OpenLoco/src/Viewport.cpp @@ -1,6 +1,7 @@ #include "Viewport.hpp" #include "CompanyManager.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" #include "Input.h" @@ -109,15 +110,16 @@ namespace OpenLoco::Ui Ui::Point bottomRight = { station.labelFrame.right[zoom], station.labelFrame.bottom[zoom] }; - Gfx::drawImage(unZoomedRt, topLeft, ImageId(borderImages.left).withTranslucency(ExtColour::unk34)); - Gfx::drawImage(unZoomedRt, topLeft, ImageId(borderImages.left).withTranslucency(colour)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(unZoomedRt, topLeft, ImageId(borderImages.left).withTranslucency(ExtColour::unk34)); + drawingCtx.drawImage(unZoomedRt, topLeft, ImageId(borderImages.left).withTranslucency(colour)); Ui::Point topRight = { static_cast(bottomRight.x - borderImages.width), topLeft.y }; - Gfx::drawImage(unZoomedRt, topRight, ImageId(borderImages.right).withTranslucency(ExtColour::unk34)); - Gfx::drawImage(unZoomedRt, topRight, ImageId(borderImages.right).withTranslucency(colour)); + drawingCtx.drawImage(unZoomedRt, topRight, ImageId(borderImages.right).withTranslucency(ExtColour::unk34)); + drawingCtx.drawImage(unZoomedRt, topRight, ImageId(borderImages.right).withTranslucency(colour)); - Gfx::drawRect(unZoomedRt, topLeft.x + borderImages.width + 1, topLeft.y, bottomRight.x - topLeft.x - 2 * borderImages.width, bottomRight.y - topLeft.y + 1, (1 << 25) | enumValue(ExtColour::unk34)); - Gfx::drawRect(unZoomedRt, topLeft.x + borderImages.width + 1, topLeft.y, bottomRight.x - topLeft.x - 2 * borderImages.width, bottomRight.y - topLeft.y + 1, (1 << 25) | enumValue(colour)); + drawingCtx.drawRect(unZoomedRt, topLeft.x + borderImages.width + 1, topLeft.y, bottomRight.x - topLeft.x - 2 * borderImages.width, bottomRight.y - topLeft.y + 1, (1 << 25) | enumValue(ExtColour::unk34)); + drawingCtx.drawRect(unZoomedRt, topLeft.x + borderImages.width + 1, topLeft.y, bottomRight.x - topLeft.x - 2 * borderImages.width, bottomRight.y - topLeft.y + 1, (1 << 25) | enumValue(colour)); char buffer[512]{}; @@ -129,8 +131,8 @@ namespace OpenLoco::Ui *str++ = ' '; StringManager::formatString(str, getTransportIconsFromStationFlags(station.flags)); - Gfx::setCurrentFontSpriteBase(kZoomToStationFonts[zoom]); - Gfx::drawString(unZoomedRt, topLeft.x + borderImages.width, topLeft.y, Colour::black, buffer); + drawingCtx.setCurrentFontSpriteBase(kZoomToStationFonts[zoom]); + drawingCtx.drawString(unZoomedRt, topLeft.x + borderImages.width, topLeft.y, Colour::black, buffer); } // 0x0048DE97 @@ -173,6 +175,8 @@ namespace OpenLoco::Ui unZoomedRt.width >>= rt.zoomLevel; unZoomedRt.height >>= rt.zoomLevel; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + char buffer[512]{}; for (const auto& town : TownManager::towns()) { @@ -182,8 +186,8 @@ namespace OpenLoco::Ui } StringManager::formatString(buffer, town.name); - Gfx::setCurrentFontSpriteBase(kZoomToTownFonts[rt.zoomLevel]); - Gfx::drawString(unZoomedRt, town.labelFrame.left[rt.zoomLevel] + 1, town.labelFrame.top[rt.zoomLevel] + 1, AdvancedColour(Colour::white).outline(), buffer); + drawingCtx.setCurrentFontSpriteBase(kZoomToTownFonts[rt.zoomLevel]); + drawingCtx.drawString(unZoomedRt, town.labelFrame.left[rt.zoomLevel] + 1, town.labelFrame.top[rt.zoomLevel] + 1, AdvancedColour(Colour::white).outline(), buffer); } } @@ -202,6 +206,8 @@ namespace OpenLoco::Ui unZoomedRt.width >>= rt.zoomLevel; unZoomedRt.height >>= rt.zoomLevel; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto orderNum = 0; for (auto& orderFrame : Vehicles::OrderManager::displayFrames()) { @@ -223,8 +229,8 @@ namespace OpenLoco::Ui continue; } - Gfx::setCurrentFontSpriteBase(Font::medium_normal); - Gfx::drawString(unZoomedRt, orderFrame.frame.left[rt.zoomLevel] + 1, orderFrame.frame.top[rt.zoomLevel], AdvancedColour(Colour::white).outline(), const_cast(orderString.c_str())); + drawingCtx.setCurrentFontSpriteBase(Font::medium_normal); + drawingCtx.drawString(unZoomedRt, orderFrame.frame.left[rt.zoomLevel] + 1, orderFrame.frame.top[rt.zoomLevel], AdvancedColour(Colour::white).outline(), const_cast(orderString.c_str())); } } @@ -266,6 +272,8 @@ namespace OpenLoco::Ui zoomViewRt.bits = rt->bits + (unkX - rt->x) + ((unkY - rt->y) * (rt->width + rt->pitch)); zoomViewRt.zoomLevel = zoom; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // make sure, the compare operation is done in int32_t to avoid the loop becoming an infinite loop. // this as well as the [x += 32] in the loop causes signed integer overflow -> undefined behaviour. auto rightBorder = zoomViewRt.x + zoomViewRt.width; @@ -297,7 +305,7 @@ namespace OpenLoco::Ui columnRt.width = paintRight - columnRt.x; - Gfx::clearSingle(columnRt, fillColour); + drawingCtx.clearSingle(columnRt, fillColour); auto* sess = Paint::allocateSession(columnRt, options); sess->generate(); sess->arrangeStructs(); diff --git a/src/OpenLoco/src/Widget.cpp b/src/OpenLoco/src/Widget.cpp index b4bf1def8b..75f44f3c51 100644 --- a/src/OpenLoco/src/Widget.cpp +++ b/src/OpenLoco/src/Widget.cpp @@ -1,4 +1,5 @@ #include "Widget.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "Input.h" @@ -41,9 +42,10 @@ namespace OpenLoco::Ui // 0x004CF3EB static void drawStationNameBackground(Gfx::RenderTarget* rt, const Window* window, const Widget* widget, int16_t x, int16_t y, AdvancedColour colour, int16_t width) { - Gfx::drawImage(rt, x - 4, y, Gfx::recolour(ImageIds::curved_border_left_medium, colour.c())); - Gfx::drawImage(rt, x + width, y, Gfx::recolour(ImageIds::curved_border_right_medium, colour.c())); - Gfx::fillRect(*rt, x, y, x + width - 1, y + 11, Colours::getShade(colour.c(), 5)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(rt, x - 4, y, Gfx::recolour(ImageIds::curved_border_left_medium, colour.c())); + drawingCtx.drawImage(rt, x + width, y, Gfx::recolour(ImageIds::curved_border_right_medium, colour.c())); + drawingCtx.fillRect(*rt, x, y, x + width - 1, y + 11, Colours::getShade(colour.c(), 5)); } void Widget::draw(Gfx::RenderTarget* rt, Window* window, const uint64_t pressedWidgets, const uint64_t toolWidgets, const uint64_t hoveredWidgets, uint8_t& scrollviewIndex) @@ -188,20 +190,21 @@ namespace OpenLoco::Ui // 0x004CF487 void Widget::drawViewportCentreButton(Gfx::RenderTarget* rt, const Window* window, const WidgetIndex_t widgetIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); auto& widget = window->widgets[widgetIndex]; if (Input::isHovering(window->type, window->number, widgetIndex)) { - Gfx::drawRect(*rt, widget.left + window->x, widget.top + window->y, widget.width(), widget.height(), 0x2000000 | 54); - Gfx::drawRect(*rt, widget.left + window->x, widget.top + window->y, widget.width(), widget.height(), 0x2000000 | 52); + drawingCtx.drawRect(*rt, widget.left + window->x, widget.top + window->y, widget.width(), widget.height(), 0x2000000 | 54); + drawingCtx.drawRect(*rt, widget.left + window->x, widget.top + window->y, widget.width(), widget.height(), 0x2000000 | 52); uint8_t flags = 0; if (Input::isPressed(window->type, window->number, widgetIndex)) flags = 0x20; - Gfx::drawRectInset(*rt, widget.left + window->x, widget.top + window->y, widget.width(), widget.height(), window->getColour(WindowColour::secondary).translucent().u8(), flags); + drawingCtx.drawRectInset(*rt, widget.left + window->x, widget.top + window->y, widget.width(), widget.height(), window->getColour(WindowColour::secondary).translucent().u8(), flags); } - Gfx::drawImage(rt, widget.left + window->x, widget.top + window->y, Gfx::recolour(ImageIds::centre_viewport, window->getColour(WindowColour::secondary).c())); + drawingCtx.drawImage(rt, widget.left + window->x, widget.top + window->y, Gfx::recolour(ImageIds::centre_viewport, window->getColour(WindowColour::secondary).c())); } // 0x004CAB8E @@ -220,7 +223,8 @@ namespace OpenLoco::Ui int16_t x = widget->right + window->x - 18; int16_t y = widget->bottom + window->y - 18; uint32_t image = Gfx::recolour(ImageIds::window_resize_handle, colour.c()); - Gfx::drawImage(rt, x, y, image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(rt, x, y, image); } void Widget::sub_4CADE8(Gfx::RenderTarget* rt, const Window* window, AdvancedColour colour, bool enabled, bool disabled, bool activated) @@ -237,6 +241,8 @@ namespace OpenLoco::Ui } } + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + if (disabled) { // TODO: this is odd most likely this is another flag like Widget::kImageIdColourSet @@ -251,16 +257,16 @@ namespace OpenLoco::Ui if (colour.isTranslucent()) { c = Colours::getShade(colour.c(), 4); - Gfx::drawImageSolid(*rt, placeForImage + Ui::Point{ 1, 1 }, pureImage, c); + drawingCtx.drawImageSolid(*rt, placeForImage + Ui::Point{ 1, 1 }, pureImage, c); c = Colours::getShade(colour.c(), 2); - Gfx::drawImageSolid(*rt, placeForImage, pureImage, c); + drawingCtx.drawImageSolid(*rt, placeForImage, pureImage, c); } else { c = Colours::getShade(colour.c(), 6); - Gfx::drawImageSolid(*rt, placeForImage + Ui::Point{ 1, 1 }, pureImage, c); + drawingCtx.drawImageSolid(*rt, placeForImage + Ui::Point{ 1, 1 }, pureImage, c); c = Colours::getShade(colour.c(), 4); - Gfx::drawImageSolid(*rt, placeForImage, pureImage, c); + drawingCtx.drawImageSolid(*rt, placeForImage, pureImage, c); } return; @@ -278,13 +284,14 @@ namespace OpenLoco::Ui imageId = imageId.withPrimary(colour.c()); } - Gfx::drawImage(*rt, placeForImage, imageId); + drawingCtx.drawImage(*rt, placeForImage, imageId); } // 0x004CAB58 void Widget::drawPanel(Gfx::RenderTarget* rt, const Window* window, uint16_t flags, AdvancedColour colour) { - Gfx::fillRectInset(*rt, window->x + left, window->y + top, window->x + right, window->y + bottom, colour.u8(), flags); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(*rt, window->x + left, window->y + top, window->x + right, window->y + bottom, colour.u8(), flags); draw_resize_handle(rt, window, this, colour); } @@ -292,6 +299,7 @@ namespace OpenLoco::Ui // 0x004CAAB9 void Widget::drawFrame(Gfx::RenderTarget* rt, const Window* window, uint16_t flags, AdvancedColour colour) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); auto clipped = Gfx::clipRenderTarget(*rt, Ui::Rect(left + window->x, top + window->y, right - left, 41)); if (clipped) { @@ -304,7 +312,7 @@ namespace OpenLoco::Ui { imageId = Gfx::recolour(ImageIds::frame_background_image_alt, colour.c()); } - Gfx::drawImage(&*clipped, 0, 0, imageId); + drawingCtx.drawImage(&*clipped, 0, 0, imageId); } uint8_t shade; @@ -317,7 +325,7 @@ namespace OpenLoco::Ui shade = Colours::getShade(colour.c(), 1); } - Gfx::fillRect( + drawingCtx.fillRect( *rt, window->x + right, window->y + top, @@ -341,19 +349,20 @@ namespace OpenLoco::Ui flags |= 0x20; } + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); if (content == kContentUnk) { flags |= 0x10; - Gfx::fillRectInset(*rt, l, t, r, b, colour.u8(), flags); + drawingCtx.fillRectInset(*rt, l, t, r, b, colour.u8(), flags); return; } if (window->flags & WindowFlags::flag_6) { - Gfx::fillRect(*rt, l, t, r, b, 0x2000000 | 52); + drawingCtx.fillRect(*rt, l, t, r, b, 0x2000000 | 52); } - Gfx::fillRectInset(*rt, l, t, r, b, colour.u8(), flags); + drawingCtx.fillRectInset(*rt, l, t, r, b, colour.u8(), flags); if (content == kContentNull) { @@ -397,7 +406,8 @@ namespace OpenLoco::Ui imageId = imageId.withPrimary(colour.c()); } - Gfx::drawImage(*rt, Ui::Point(window->x + left, window->y + top), imageId); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(*rt, Ui::Point(window->x + left, window->y + top), imageId); } // 0x004CACD4 @@ -417,18 +427,19 @@ namespace OpenLoco::Ui if (activated) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); flags |= 0x20; if (content == kContentUnk) { // 0x004CABE8 flags |= 0x10; - Gfx::fillRectInset(*rt, l, t, r, b, colour.u8(), flags); + drawingCtx.fillRectInset(*rt, l, t, r, b, colour.u8(), flags); return; } - Gfx::fillRectInset(*rt, l, t, r, b, colour.u8(), flags); + drawingCtx.fillRectInset(*rt, l, t, r, b, colour.u8(), flags); } if (content == kContentNull) @@ -467,7 +478,8 @@ namespace OpenLoco::Ui imageId = imageId.withPrimary(colour.c()); } - Gfx::drawImage(*rt, Ui::Point(window->x + left, window->y + top), imageId); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(*rt, Ui::Point(window->x + left, window->y + top), imageId); } // 0x004CB164 @@ -483,7 +495,8 @@ namespace OpenLoco::Ui flags |= 0x20; } - Gfx::fillRectInset(*rt, l, t, r, b, colour.u8(), flags); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(*rt, l, t, r, b, colour.u8(), flags); } // 0x004CB1BE @@ -529,7 +542,8 @@ namespace OpenLoco::Ui int16_t centreX = window->x + (widget->left + widget->right + 1) / 2 - 1; int16_t width = widget->right - widget->left - 2; - Gfx::drawStringCentredClipped(*rt, centreX, y, width, colour, string, _commonFormatArgs); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringCentredClipped(*rt, centreX, y, width, colour, string, _commonFormatArgs); } // 0x004CB263 @@ -544,7 +558,8 @@ namespace OpenLoco::Ui } int width = widget->right - widget->left - 2; - Gfx::drawStringLeftClipped(*rt, x, y, width, colour, string, _commonFormatArgs); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringLeftClipped(*rt, x, y, width, colour, string, _commonFormatArgs); } // 0x4CB2D6 @@ -563,14 +578,15 @@ namespace OpenLoco::Ui { colour = colour.FD(); } - - drawStringLeft(*rt, window->x + left + 1, window->y + top, colour, text, _commonFormatArgs); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringLeft(*rt, window->x + left + 1, window->y + top, colour, text, _commonFormatArgs); } // 0x4CB29C void Widget::drawTextBox(Gfx::RenderTarget* rt, const Window* window, uint16_t flags, AdvancedColour colour) { - Gfx::fillRectInset(*rt, window->x + left, window->y + top, window->x + right, window->y + bottom, colour.u8(), flags | 0x60); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(*rt, window->x + left, window->y + top, window->x + right, window->y + bottom, colour.u8(), flags | 0x60); } // 0x004CA6AE @@ -580,14 +596,16 @@ namespace OpenLoco::Ui int r = window->x + right; int t = window->y + top; int b = window->y + bottom; - Gfx::fillRectInset(*rt, l, t, r, b, colour.u8(), flags | 0x60); - Gfx::fillRect(*rt, l + 1, t + 1, r - 1, b - 1, 0x2000000 | 46); + + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(*rt, l, t, r, b, colour.u8(), flags | 0x60); + drawingCtx.fillRect(*rt, l + 1, t + 1, r - 1, b - 1, 0x2000000 | 46); int16_t width = r - l - 4 - 10; int16_t y = t + 1; int16_t x = l + 2 + (width / 2); - Gfx::drawStringCentredClipped(*rt, x, y, width, AdvancedColour(Colour::white).outline(), text, _commonFormatArgs); + drawingCtx.drawStringCentredClipped(*rt, x, y, width, AdvancedColour(Colour::white).outline(), text, _commonFormatArgs); } // 0x004CA750 @@ -600,15 +618,16 @@ namespace OpenLoco::Ui int16_t width = right - left - 4 - 14; int16_t x = left + window->x + 2 + (width / 2); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - width = Gfx::clipString(width - 8, stringBuffer); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + width = drawingCtx.clipString(width - 8, stringBuffer); x -= width / 2; int16_t y = window->y + top + 1; drawStationNameBackground(rt, window, this, x, y, colour, width); - Gfx::drawString(*rt, x, y, Colour::black, stringBuffer); + drawingCtx.drawString(*rt, x, y, Colour::black, stringBuffer); } // 0x004CA7F6 @@ -622,11 +641,12 @@ namespace OpenLoco::Ui int16_t width = right - left - 4 - 14; x = x + (width / 2); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - int16_t stringWidth = Gfx::clipString(width - 8, stringBuffer); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + int16_t stringWidth = drawingCtx.clipString(width - 8, stringBuffer); x -= (stringWidth - 1) / 2; - Gfx::drawString(*rt, x, window->y + top + 1, AdvancedColour(Colour::black).outline(), stringBuffer); + drawingCtx.drawString(*rt, x, window->y + top + 1, AdvancedColour(Colour::black).outline(), stringBuffer); } // 0x004CA88B @@ -640,11 +660,12 @@ namespace OpenLoco::Ui int16_t width = right - left - 4 - 14; x = x + (width / 2); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - int16_t stringWidth = Gfx::clipString(width - 8, stringBuffer); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + int16_t stringWidth = drawingCtx.clipString(width - 8, stringBuffer); x -= (stringWidth - 1) / 2; - Gfx::drawString(*rt, x, window->y + top + 1, AdvancedColour(Colour::black).outline(), stringBuffer); + drawingCtx.drawString(*rt, x, window->y + top + 1, AdvancedColour(Colour::black).outline(), stringBuffer); } static void draw_hscroll(Gfx::RenderTarget* rt, const Window* window, Widget* widget, uint16_t flags, AdvancedColour colour, bool enabled, bool disabled, bool activated, bool hovered, int16_t scrollview_index) @@ -663,6 +684,7 @@ namespace OpenLoco::Ui } uint16_t f; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); // pusha f = 0; @@ -670,11 +692,11 @@ namespace OpenLoco::Ui { f = flags | 0x20; } - Gfx::fillRectInset(*rt, ax, cx, ax + 9, dx, colour.u8(), f); + drawingCtx.fillRectInset(*rt, ax, cx, ax + 9, dx, colour.u8(), f); // popa // pusha - Gfx::drawString(*rt, ax + 2, cx, Colour::black, (char*)0x005045F2); + drawingCtx.drawString(*rt, ax + 2, cx, Colour::black, (char*)0x005045F2); // popa // pusha @@ -683,23 +705,23 @@ namespace OpenLoco::Ui { f = flags | 0x20; } - Gfx::fillRectInset(*rt, bx - 9, cx, bx, dx, colour.u8(), f); + drawingCtx.fillRectInset(*rt, bx - 9, cx, bx, dx, colour.u8(), f); // popa // pusha - Gfx::drawString(*rt, bx - 6 - 1, cx, Colour::black, (char*)0x005045F5); + drawingCtx.drawString(*rt, bx - 6 - 1, cx, Colour::black, (char*)0x005045F5); // popa // pusha - Gfx::fillRect(*rt, ax + 10, cx, bx - 10, dx, Colours::getShade(colour.c(), 7)); - Gfx::fillRect(*rt, ax + 10, cx, bx - 10, dx, 0x1000000 | Colours::getShade(colour.c(), 3)); + drawingCtx.fillRect(*rt, ax + 10, cx, bx - 10, dx, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, ax + 10, cx, bx - 10, dx, 0x1000000 | Colours::getShade(colour.c(), 3)); // popa // pusha - Gfx::fillRect(*rt, ax + 10, cx + 2, bx - 10, cx + 2, Colours::getShade(colour.c(), 3)); - Gfx::fillRect(*rt, ax + 10, cx + 3, bx - 10, cx + 3, Colours::getShade(colour.c(), 7)); - Gfx::fillRect(*rt, ax + 10, cx + 7, bx - 10, cx + 7, Colours::getShade(colour.c(), 3)); - Gfx::fillRect(*rt, ax + 10, cx + 8, bx - 10, cx + 8, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, ax + 10, cx + 2, bx - 10, cx + 2, Colours::getShade(colour.c(), 3)); + drawingCtx.fillRect(*rt, ax + 10, cx + 3, bx - 10, cx + 3, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, ax + 10, cx + 7, bx - 10, cx + 7, Colours::getShade(colour.c(), 3)); + drawingCtx.fillRect(*rt, ax + 10, cx + 8, bx - 10, cx + 8, Colours::getShade(colour.c(), 7)); // popa // pusha @@ -708,7 +730,7 @@ namespace OpenLoco::Ui { f = 0x20; } - Gfx::fillRectInset(*rt, ax - 1 + scroll_area->hThumbLeft, cx, ax - 1 + scroll_area->hThumbRight, dx, colour.u8(), f); + drawingCtx.fillRectInset(*rt, ax - 1 + scroll_area->hThumbLeft, cx, ax - 1 + scroll_area->hThumbRight, dx, colour.u8(), f); // popa } @@ -728,6 +750,7 @@ namespace OpenLoco::Ui } uint16_t f; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); // pusha f = 0; @@ -735,11 +758,11 @@ namespace OpenLoco::Ui { f = flags | 0x20; } - Gfx::fillRectInset(*rt, ax, cx, bx, cx + 9, colour.u8(), f); + drawingCtx.fillRectInset(*rt, ax, cx, bx, cx + 9, colour.u8(), f); // popa // pusha - Gfx::drawString(*rt, ax + 1, cx - 1, Colour::black, (char*)0x005045EC); + drawingCtx.drawString(*rt, ax + 1, cx - 1, Colour::black, (char*)0x005045EC); // popa // pusha @@ -748,23 +771,23 @@ namespace OpenLoco::Ui { f = flags | 0x20; } - Gfx::fillRectInset(*rt, ax, dx - 9, bx, dx, colour.u8(), f); + drawingCtx.fillRectInset(*rt, ax, dx - 9, bx, dx, colour.u8(), f); // popa // pusha - Gfx::drawString(*rt, ax + 1, dx - 8 - 1, Colour::black, (char*)0x005045EF); + drawingCtx.drawString(*rt, ax + 1, dx - 8 - 1, Colour::black, (char*)0x005045EF); // popa // pusha - Gfx::fillRect(*rt, ax, cx + 10, bx, dx - 10, Colours::getShade(colour.c(), 7)); - Gfx::fillRect(*rt, ax, cx + 10, bx, dx - 10, 0x1000000 | Colours::getShade(colour.c(), 3)); + drawingCtx.fillRect(*rt, ax, cx + 10, bx, dx - 10, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, ax, cx + 10, bx, dx - 10, 0x1000000 | Colours::getShade(colour.c(), 3)); // popa // pusha - Gfx::fillRect(*rt, ax + 2, cx + 10, ax + 2, dx - 10, Colours::getShade(colour.c(), 3)); - Gfx::fillRect(*rt, ax + 3, cx + 10, ax + 3, dx - 10, Colours::getShade(colour.c(), 7)); - Gfx::fillRect(*rt, ax + 7, cx + 10, ax + 7, dx - 10, Colours::getShade(colour.c(), 3)); - Gfx::fillRect(*rt, ax + 8, cx + 10, ax + 8, dx - 10, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, ax + 2, cx + 10, ax + 2, dx - 10, Colours::getShade(colour.c(), 3)); + drawingCtx.fillRect(*rt, ax + 3, cx + 10, ax + 3, dx - 10, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, ax + 7, cx + 10, ax + 7, dx - 10, Colours::getShade(colour.c(), 3)); + drawingCtx.fillRect(*rt, ax + 8, cx + 10, ax + 8, dx - 10, Colours::getShade(colour.c(), 7)); // popa // pusha @@ -773,7 +796,7 @@ namespace OpenLoco::Ui { f = flags | 0x20; } - Gfx::fillRectInset(*rt, ax, cx - 1 + scroll_area->vThumbTop, bx, cx - 1 + scroll_area->vThumbBottom, colour.u8(), f); + drawingCtx.fillRectInset(*rt, ax, cx - 1 + scroll_area->vThumbTop, bx, cx - 1 + scroll_area->vThumbBottom, colour.u8(), f); // popa } @@ -785,7 +808,8 @@ namespace OpenLoco::Ui int16_t r = window->x + right; int16_t b = window->y + bottom; - Gfx::fillRectInset(*rt, l, t, r, b, colour.u8(), flags | 0x60); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(*rt, l, t, r, b, colour.u8(), flags | 0x60); l++; t++; @@ -794,7 +818,7 @@ namespace OpenLoco::Ui const auto* scroll_area = &window->scrollAreas[scrollview_index]; - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); if (scroll_area->flags & Ui::ScrollView::ScrollFlags::hscrollbarVisible) { draw_hscroll(rt, window, this, flags, colour, enabled, disabled, activated, hovered, scrollview_index); @@ -856,9 +880,10 @@ namespace OpenLoco::Ui // 0x004CB00B void Widget::draw_27_checkbox(Gfx::RenderTarget* rt, const Window* window, uint16_t flags, AdvancedColour colour, bool enabled, bool disabled, bool activated) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); if (enabled) { - Gfx::fillRectInset( + drawingCtx.fillRectInset( *rt, window->x + left, window->y + top, @@ -870,8 +895,8 @@ namespace OpenLoco::Ui if (activated) { - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - Gfx::drawString(*rt, window->x + left, window->y + top, colour.opaque(), _strCheckmark); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + drawingCtx.drawString(*rt, window->x + left, window->y + top, colour.opaque(), _strCheckmark); } } @@ -890,7 +915,8 @@ namespace OpenLoco::Ui colour = colour.inset(); } - Gfx::drawStringLeft(*rt, window->x + left + 14, window->y + top, colour, text, _commonFormatArgs); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringLeft(*rt, window->x + left + 14, window->y + top, colour, text, _commonFormatArgs); } // 0x004CA679 @@ -900,7 +926,8 @@ namespace OpenLoco::Ui int r = window->x + right; int t = window->y + top; int b = window->y + bottom; - Gfx::fillRect(*rt, l, t, r, b, Colours::getShade(Colour::black, 5)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRect(*rt, l, t, r, b, Colours::getShade(Colour::black, 5)); } void Widget::drawGroupbox(Gfx::RenderTarget* const rt, const Window* window) @@ -912,14 +939,15 @@ namespace OpenLoco::Ui int32_t b = window->y + bottom; int32_t textEndPos = l; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); // First, draw the label text, if any. if (text != StringIds::null) { char buffer[512] = { 0 }; StringManager::formatString(buffer, sizeof(buffer), text); - Gfx::drawString(*rt, l, t, colour, buffer); - textEndPos = l + Gfx::getStringWidth(buffer) + 1; + drawingCtx.drawString(*rt, l, t, colour, buffer); + textEndPos = l + drawingCtx.getStringWidth(buffer) + 1; } // Prepare border dimensions @@ -929,24 +957,24 @@ namespace OpenLoco::Ui b = window->y + bottom; // Border left of text - Gfx::fillRect(*rt, l, t, l + 4, t, Colours::getShade(colour.c(), 4)); - Gfx::fillRect(*rt, l + 1, t + 1, l + 4, t + 1, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, l, t, l + 4, t, Colours::getShade(colour.c(), 4)); + drawingCtx.fillRect(*rt, l + 1, t + 1, l + 4, t + 1, Colours::getShade(colour.c(), 7)); // Border right of text - Gfx::fillRect(*rt, textEndPos, t, r - 1, t, Colours::getShade(colour.c(), 4)); - Gfx::fillRect(*rt, textEndPos, t + 1, r - 2, t + 1, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, textEndPos, t, r - 1, t, Colours::getShade(colour.c(), 4)); + drawingCtx.fillRect(*rt, textEndPos, t + 1, r - 2, t + 1, Colours::getShade(colour.c(), 7)); // Border right - Gfx::fillRect(*rt, r - 1, t + 1, r - 1, b - 1, Colours::getShade(colour.c(), 4)); - Gfx::fillRect(*rt, r, t, r, b, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, r - 1, t + 1, r - 1, b - 1, Colours::getShade(colour.c(), 4)); + drawingCtx.fillRect(*rt, r, t, r, b, Colours::getShade(colour.c(), 7)); // Border bottom - Gfx::fillRect(*rt, l, b - 1, r - 2, b - 1, Colours::getShade(colour.c(), 4)); - Gfx::fillRect(*rt, l, b, r - 1, b, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, l, b - 1, r - 2, b - 1, Colours::getShade(colour.c(), 4)); + drawingCtx.fillRect(*rt, l, b, r - 1, b, Colours::getShade(colour.c(), 7)); // Border left - Gfx::fillRect(*rt, l, t + 1, l, b - 2, Colours::getShade(colour.c(), 4)); - Gfx::fillRect(*rt, l + 1, t + 2, l + 1, b - 2, Colours::getShade(colour.c(), 7)); + drawingCtx.fillRect(*rt, l, t + 1, l, b - 2, Colours::getShade(colour.c(), 4)); + drawingCtx.fillRect(*rt, l + 1, t + 2, l + 1, b - 2, Colours::getShade(colour.c(), 7)); } // 0x004CF194 @@ -978,22 +1006,23 @@ namespace OpenLoco::Ui return; } + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); if (isActivated) { if (imageId != kContentUnk) { - Gfx::drawImage(rt, pos.x, pos.y, imageId); + drawingCtx.drawImage(rt, pos.x, pos.y, imageId); } } else { if (imageId != kContentUnk) { - Gfx::drawImage(rt, pos.x, pos.y + 1, imageId); + drawingCtx.drawImage(rt, pos.x, pos.y + 1, imageId); } - Gfx::drawImage(rt, pos.x, pos.y, Gfx::recolourTranslucent(ImageIds::tab, ExtColour::unk33)); - Gfx::drawRect(*rt, pos.x, pos.y + 26, 31, 1, Colours::getShade(w->getColour(WindowColour::secondary).c(), 7)); + drawingCtx.drawImage(rt, pos.x, pos.y, Gfx::recolourTranslucent(ImageIds::tab, ExtColour::unk33)); + drawingCtx.drawRect(*rt, pos.x, pos.y + 26, 31, 1, Colours::getShade(w->getColour(WindowColour::secondary).c(), 7)); } } diff --git a/src/OpenLoco/src/Widget.h b/src/OpenLoco/src/Widget.h index 9d3f7f710b..a90465c301 100644 --- a/src/OpenLoco/src/Widget.h +++ b/src/OpenLoco/src/Widget.h @@ -13,7 +13,7 @@ namespace OpenLoco::Ui { // Indicates that the imageId has a colour set and not to replace it with the window colour // This reuses the ImageIdFlags::translucent flag for use in widget draw - // Flag *MUST* be removed before passing to Gfx::drawImage functions + // Flag *MUST* be removed before passing to drawingCtx.drawImage functions static constexpr uint32_t kImageIdColourSet = (1 << 30); static constexpr int32_t kContentNull = 0xFFFFFFFF; static constexpr int32_t kContentUnk = 0xFFFFFFFE; diff --git a/src/OpenLoco/src/Window.cpp b/src/OpenLoco/src/Window.cpp index 47d7e28b3f..9c98299fd8 100644 --- a/src/OpenLoco/src/Window.cpp +++ b/src/OpenLoco/src/Window.cpp @@ -1,6 +1,7 @@ #include "Window.h" #include "Config.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "Graphics/Colour.h" #include "Input.h" @@ -1461,9 +1462,11 @@ namespace OpenLoco::Ui // 0x004CA4DF void Window::draw(Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + if ((this->flags & WindowFlags::transparent) && !(this->flags & WindowFlags::noBackground)) { - Gfx::fillRect(*rt, this->x, this->y, this->x + this->width - 1, this->y + this->height - 1, 0x2000000 | 52); + drawingCtx.fillRect(*rt, this->x, this->y, this->x + this->width - 1, this->y + this->height - 1, 0x2000000 | 52); } uint64_t pressedWidget = 0; @@ -1503,7 +1506,7 @@ namespace OpenLoco::Ui if (this->flags & WindowFlags::whiteBorderMask) { - Gfx::fillRectInset( + drawingCtx.fillRectInset( *rt, this->x, this->y, diff --git a/src/OpenLoco/src/Windows/About.cpp b/src/OpenLoco/src/Windows/About.cpp index a2c6ec2bbe..6927b1c0cf 100644 --- a/src/OpenLoco/src/Windows/About.cpp +++ b/src/OpenLoco/src/Windows/About.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" @@ -83,38 +84,39 @@ namespace OpenLoco::Ui::Windows::About const int16_t x = window.x + kWindowSize.width / 2; int16_t y = window.y + 25; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_69, nullptr); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_69, nullptr); y += 10; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_70, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_70, nullptr); // Chris Sawyer logo - drawImage(rt, window.x + 92, window.y + 52, ImageIds::chris_sawyer_logo_small); + drawingCtx.drawImage(rt, window.x + 92, window.y + 52, ImageIds::chris_sawyer_logo_small); y += 79; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_71, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_71, nullptr); y += 10; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_72, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_72, nullptr); y += 10; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_73, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_73, nullptr); y += 10; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_74, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_74, nullptr); y += 13; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_75, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_75, nullptr); y += 25; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_76, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_76, nullptr); y += 10; - drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_77, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::about_locomotion_77, nullptr); // Licenced to Atari y += 25; - drawStringCentred(*rt, x, y, Colour::black, StringIds::licenced_to_atari_inc, nullptr); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::licenced_to_atari_inc, nullptr); } static void initEvents() diff --git a/src/OpenLoco/src/Windows/AboutMusic.cpp b/src/OpenLoco/src/Windows/AboutMusic.cpp index 3d562968c8..838dd76616 100644 --- a/src/OpenLoco/src/Windows/AboutMusic.cpp +++ b/src/OpenLoco/src/Windows/AboutMusic.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" @@ -137,20 +138,21 @@ namespace OpenLoco::Ui::Windows::AboutMusic const int16_t x = 240; int16_t y = 2; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); for (const auto& songStrings : stringsToDraw) { // TODO: optimisation: don't draw past fold. // Song name - drawStringCentred(rt, x, y, Colour::black, songStrings.first, nullptr); + drawingCtx.drawStringCentred(rt, x, y, Colour::black, songStrings.first, nullptr); y += 10; // Credit line - drawStringCentred(rt, x, y, Colour::black, songStrings.second, nullptr); + drawingCtx.drawStringCentred(rt, x, y, Colour::black, songStrings.second, nullptr); y += 10; // Show CS' copyright after every two lines. - drawStringCentred(rt, x, y, Colour::black, StringIds::music_copyright, nullptr); + drawingCtx.drawStringCentred(rt, x, y, Colour::black, StringIds::music_copyright, nullptr); y += 14; } } diff --git a/src/OpenLoco/src/Windows/BuildVehicle.cpp b/src/OpenLoco/src/Windows/BuildVehicle.cpp index 601b02a776..827004cd51 100644 --- a/src/OpenLoco/src/Windows/BuildVehicle.cpp +++ b/src/OpenLoco/src/Windows/BuildVehicle.cpp @@ -1,5 +1,6 @@ #include "CompanyManager.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Economy/Economy.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" @@ -918,6 +919,8 @@ namespace OpenLoco::Ui::Windows::BuildVehicle // 0x4C2F23 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + window.draw(rt); drawTransportTypeTabs(&window, rt); drawTrackTypeTabs(&window, rt); @@ -938,7 +941,7 @@ namespace OpenLoco::Ui::Windows::BuildVehicle } } - Gfx::drawStringLeftClipped(*rt, x, y, window.width - 186, Colour::black, bottomLeftMessage, &args); + drawingCtx.drawStringLeftClipped(*rt, x, y, window.width - 186, Colour::black, bottomLeftMessage, &args); } if (window.rowHover == -1) @@ -1064,18 +1067,20 @@ namespace OpenLoco::Ui::Windows::BuildVehicle auto x = window.widgets[widx::scrollview_vehicle_selection].right + window.x + 2; auto y = window.widgets[widx::scrollview_vehicle_preview].bottom + window.y + 2; - Gfx::drawStringLeftWrapped(*rt, x, y, 180, Colour::black, StringIds::buffer_1250); + drawingCtx.drawStringLeftWrapped(*rt, x, y, 180, Colour::black, StringIds::buffer_1250); } // 0x4C3307 static void drawScroll(Ui::Window& window, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + switch (scrollIndex) { case scrollIdx::vehicle_selection: { auto colour = Colours::getShade(window.getColour(WindowColour::secondary).c(), 4); - Gfx::clear(rt, colour * 0x01010101); + drawingCtx.clear(rt, colour * 0x01010101); if (window.var_83C == 0) { auto defaultMessage = StringIds::no_vehicles_available; @@ -1094,7 +1099,7 @@ namespace OpenLoco::Ui::Windows::BuildVehicle auto widget = window.widgets[widx::scrollview_vehicle_selection]; auto width = widget.right - widget.left - 17; auto y = (window.rowHeight - 10) / 2; - Gfx::drawStringLeftWrapped(rt, 3, y, width, Colour::black, defaultMessage, &args); + drawingCtx.drawStringLeftWrapped(rt, 3, y, width, Colour::black, defaultMessage, &args); } else { @@ -1132,11 +1137,11 @@ namespace OpenLoco::Ui::Windows::BuildVehicle { if (rowIsALockedVehicle) { - Gfx::fillRect(rt, 0, y, window.width, y + window.rowHeight - 1, lockedHoverRowColour); + drawingCtx.fillRect(rt, 0, y, window.width, y + window.rowHeight - 1, lockedHoverRowColour); } else { - Gfx::fillRect(rt, 0, y, window.width, y + window.rowHeight - 1, normalHoverRowColour); + drawingCtx.fillRect(rt, 0, y, window.width, y + window.rowHeight - 1, normalHoverRowColour); } colouredString = StringIds::wcolour2_stringid; } @@ -1144,7 +1149,7 @@ namespace OpenLoco::Ui::Windows::BuildVehicle { if (rowIsALockedVehicle) { - Gfx::fillRect(rt, 0, y, window.width, y + window.rowHeight - 1, lockedRowColour); + drawingCtx.fillRect(rt, 0, y, window.width, y + window.rowHeight - 1, lockedRowColour); } } @@ -1155,7 +1160,7 @@ namespace OpenLoco::Ui::Windows::BuildVehicle FormatArguments args{}; args.push(vehicleObj->name); half = (window.rowHeight - 10) / 2; - Gfx::drawStringLeft(rt, x + 3, y + half, Colour::black, colouredString, &args); + drawingCtx.drawStringLeft(rt, x + 3, y + half, Colour::black, colouredString, &args); } } break; @@ -1164,7 +1169,7 @@ namespace OpenLoco::Ui::Windows::BuildVehicle { auto colour = Colours::getShade(window.getColour(WindowColour::secondary).c(), 0); // Gfx::clear needs the colour copied to each byte of eax - Gfx::clear(rt, colour * 0x01010101); + drawingCtx.clear(rt, colour * 0x01010101); if (window.rowHover == -1) { @@ -1194,7 +1199,7 @@ namespace OpenLoco::Ui::Windows::BuildVehicle *buffer++ = '\0'; FormatArguments args{}; args.push(StringIds::buffer_1250); - Gfx::drawStringCentredClipped(rt, 89, 52, 177, Colour::darkOrange, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringCentredClipped(rt, 89, 52, 177, Colour::darkOrange, StringIds::wcolour2_stringid, &args); break; } } @@ -1367,6 +1372,8 @@ namespace OpenLoco::Ui::Windows::BuildVehicle // 0x4C28F1 static void drawTrackTypeTabs(Ui::Window* window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto skin = ObjectManager::get(); auto companyColour = CompanyManager::getCompanyColour(CompanyId(window->number)); @@ -1374,13 +1381,13 @@ namespace OpenLoco::Ui::Windows::BuildVehicle auto top = window->y + 69; auto right = left + window->width - 187; auto bottom = top; - Gfx::fillRect(*rt, left, top, right, bottom, Colours::getShade(window->getColour(WindowColour::secondary).c(), 7)); + drawingCtx.fillRect(*rt, left, top, right, bottom, Colours::getShade(window->getColour(WindowColour::secondary).c(), 7)); left = window->x + window->width - 187; top = window->y + 41; right = left; bottom = top + 27; - Gfx::fillRect(*rt, left, top, right, bottom, Colours::getShade(window->getColour(WindowColour::secondary).c(), 7)); + drawingCtx.fillRect(*rt, left, top, right, bottom, Colours::getShade(window->getColour(WindowColour::secondary).c(), 7)); for (uint32_t tab = 0; tab < _numTrackTypeTabs; ++tab) { @@ -1391,7 +1398,7 @@ namespace OpenLoco::Ui::Windows::BuildVehicle top = widget.top + window->y + 26; right = left + 29; bottom = top; - Gfx::fillRect(*rt, left, top, right, bottom, Colours::getShade(window->getColour(WindowColour::secondary).c(), 5)); + drawingCtx.fillRect(*rt, left, top, right, bottom, Colours::getShade(window->getColour(WindowColour::secondary).c(), 5)); } auto img = 0; diff --git a/src/OpenLoco/src/Windows/Cheats.cpp b/src/OpenLoco/src/Windows/Cheats.cpp index 22afbc2146..72cdf20b66 100644 --- a/src/OpenLoco/src/Windows/Cheats.cpp +++ b/src/OpenLoco/src/Windows/Cheats.cpp @@ -1,6 +1,7 @@ #include "CompanyManager.h" #include "Config.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/Cheat.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -215,6 +216,8 @@ namespace OpenLoco::Ui::Windows::Cheats static void draw(Ui::Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets and tabs. self.draw(rt); Common::drawTabs(&self, rt); @@ -222,7 +225,7 @@ namespace OpenLoco::Ui::Windows::Cheats // Add cash step label and value { auto& widget = self.widgets[Widx::cash_step_value]; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 10, self.y + widget.top, @@ -231,7 +234,7 @@ namespace OpenLoco::Ui::Windows::Cheats auto args = FormatArguments::common(); args.push(_cashIncreaseStep); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + widget.left + 1, self.y + widget.top, @@ -243,7 +246,7 @@ namespace OpenLoco::Ui::Windows::Cheats // Loan label and value { auto& widget = self.widgets[Widx::loan_value]; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 10, self.y + widget.top, @@ -254,7 +257,7 @@ namespace OpenLoco::Ui::Windows::Cheats auto args = FormatArguments::common(); args.push(company->currentLoan); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + widget.left + 1, self.y + widget.top, @@ -266,7 +269,7 @@ namespace OpenLoco::Ui::Windows::Cheats // Add year label and value { auto& widget = self.widgets[Widx::year_step_value]; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 10, self.y + widget.top, @@ -275,7 +278,7 @@ namespace OpenLoco::Ui::Windows::Cheats auto args = FormatArguments::common(); args.push(_date.year); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + widget.left + 1, self.y + widget.top, @@ -287,7 +290,7 @@ namespace OpenLoco::Ui::Windows::Cheats // Add month label and value { auto& widget = self.widgets[Widx::month_step_value]; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 10, self.y + widget.top, @@ -296,7 +299,7 @@ namespace OpenLoco::Ui::Windows::Cheats auto args = FormatArguments::common(); args.push((string_id)OpenLoco::StringManager::monthToString(_date.month).second); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + widget.left + 1, self.y + widget.top, @@ -308,7 +311,7 @@ namespace OpenLoco::Ui::Windows::Cheats // Add day label and value { auto& widget = self.widgets[Widx::day_step_value]; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 10, self.y + widget.top, @@ -317,7 +320,7 @@ namespace OpenLoco::Ui::Windows::Cheats auto args = FormatArguments::common(); args.push(_date.day + 1); // +1 since days in game are 0-based, but IRL they are 1-based - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + widget.left + 1, self.y + widget.top, @@ -516,6 +519,8 @@ namespace OpenLoco::Ui::Windows::Cheats static void draw(Ui::Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets and tabs. self.draw(rt); Common::drawTabs(&self, rt); @@ -523,7 +528,7 @@ namespace OpenLoco::Ui::Windows::Cheats // Draw current company name auto company = CompanyManager::get(_targetCompanyId); auto& widget = self.widgets[Widx::target_company_dropdown]; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + widget.left, self.y + widget.top, diff --git a/src/OpenLoco/src/Windows/CompanyFaceSelection.cpp b/src/OpenLoco/src/Windows/CompanyFaceSelection.cpp index cb8cb456ab..e6364a3310 100644 --- a/src/OpenLoco/src/Windows/CompanyFaceSelection.cpp +++ b/src/OpenLoco/src/Windows/CompanyFaceSelection.cpp @@ -1,5 +1,6 @@ #include "Audio/Audio.h" #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -227,17 +228,19 @@ namespace OpenLoco::Ui::Windows::CompanyFaceSelection return; } + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + { const auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 0); const auto l = self.x + 1 + self.widgets[widx::face_frame].left; const auto t = self.y + 1 + self.widgets[widx::face_frame].top; const auto r = self.x - 1 + self.widgets[widx::face_frame].right; const auto b = self.y - 1 + self.widgets[widx::face_frame].bottom; - Gfx::fillRect(*rt, l, t, r, b, colour); + drawingCtx.fillRect(*rt, l, t, r, b, colour); const CompetitorObject* competitor = reinterpret_cast(ObjectManager::getTemporaryObject()); uint32_t img = competitor->images[0] + 1 + (1 << 29); - Gfx::drawImage(rt, l, t, img); + drawingCtx.drawImage(rt, l, t, img); } { @@ -248,7 +251,7 @@ namespace OpenLoco::Ui::Windows::CompanyFaceSelection *str++ = ControlCodes::windowColour2; auto objectPtr = self.object; strcpy(str, ObjectManager::ObjectIndexEntry::read(&objectPtr)._name); - Gfx::drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::buffer_2039); + drawingCtx.drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::buffer_2039); } // There was code for displaying competitor stats if window opened with none @@ -258,7 +261,8 @@ namespace OpenLoco::Ui::Windows::CompanyFaceSelection // 0x00435152 static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { - Gfx::clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); auto index = 0; for (const auto& object : ObjectManager::getAvailableObjects(ObjectType::competitor)) @@ -269,20 +273,20 @@ namespace OpenLoco::Ui::Windows::CompanyFaceSelection if (index == self.rowHover) { inlineColour = ControlCodes::windowColour2; - Gfx::fillRect(rt, 0, y, self.width, y + 9, 0x2000000 | 48); + drawingCtx.fillRect(rt, 0, y, self.width, y + 9, 0x2000000 | 48); } std::string name(object.second._name); name.insert(0, 1, inlineColour); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); AdvancedColour stringColour = Colour::black; if (isInUseCompetitor(object.first)) { - Gfx::setCurrentFontSpriteBase(Font::m1); + drawingCtx.setCurrentFontSpriteBase(Font::m1); stringColour = self.getColour(WindowColour::secondary).opaque().inset(); } - Gfx::drawString(rt, 0, y - 1, stringColour, const_cast(name.c_str())); + drawingCtx.drawString(rt, 0, y - 1, stringColour, const_cast(name.c_str())); index++; } diff --git a/src/OpenLoco/src/Windows/CompanyList.cpp b/src/OpenLoco/src/Windows/CompanyList.cpp index 5f02c808de..3560c7be74 100644 --- a/src/OpenLoco/src/Windows/CompanyList.cpp +++ b/src/OpenLoco/src/Windows/CompanyList.cpp @@ -2,6 +2,7 @@ #include "CompanyManager.h" #include "CompanyRecords.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Economy/Economy.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -432,6 +433,8 @@ namespace OpenLoco::Ui::Windows::CompanyList // 0x00435E56 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -445,14 +448,16 @@ namespace OpenLoco::Ui::Windows::CompanyList auto xPos = self.x + 3; auto yPos = self.y + self.height - 13; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); } // 0x00435EA7 static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 3); - Gfx::clearSingle(rt, colour); + drawingCtx.clearSingle(rt, colour); auto yBottom = 0; for (auto i = 0; i < self.var_83C; i++, yBottom += 25) @@ -476,7 +481,7 @@ namespace OpenLoco::Ui::Windows::CompanyList if (rowItem == self.rowHover) { - Gfx::drawRect(rt, 0, yBottom, self.width, 24, (1 << 25) | PaletteIndex::index_30); + drawingCtx.drawRect(rt, 0, yBottom, self.width, 24, (1 << 25) | PaletteIndex::index_30); stringId = StringIds::wcolour2_stringid; } @@ -491,7 +496,7 @@ namespace OpenLoco::Ui::Windows::CompanyList args.push(imageId); args.push(company->name); - Gfx::drawStringLeftClipped(rt, 0, yBottom - 1, 173, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(rt, 0, yBottom - 1, 173, Colour::black, stringId, &args); } { @@ -501,7 +506,7 @@ namespace OpenLoco::Ui::Windows::CompanyList args.rewind(); args.push(ownerStatus); - Gfx::drawStringLeftClipped(rt, 175, yBottom + 7, 208, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(rt, 175, yBottom + 7, 208, Colour::black, stringId, &args); } auto performanceStringId = StringIds::performance_index; @@ -522,7 +527,7 @@ namespace OpenLoco::Ui::Windows::CompanyList args.push(performanceStringId); formatPerformanceIndex(company->performanceIndex, args); - Gfx::drawStringLeftClipped(rt, 385, yBottom - 1, 143, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(rt, 385, yBottom - 1, 143, Colour::black, stringId, &args); } { @@ -531,7 +536,7 @@ namespace OpenLoco::Ui::Windows::CompanyList args.push(StringIds::company_value_currency); args.push(company->companyValueHistory[0]); - Gfx::drawStringLeftClipped(rt, 530, yBottom - 1, 98, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(rt, 530, yBottom - 1, 98, Colour::black, stringId, &args); } } } @@ -1017,6 +1022,8 @@ namespace OpenLoco::Ui::Windows::CompanyList // 0x00437949 static void drawGraphLegend(Window* self, Gfx::RenderTarget* rt, int16_t x, int16_t y) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto cargoCount = 0; for (uint8_t i = 0; i < ObjectManager::getMaxObjects(ObjectType::cargo); i++) { @@ -1035,13 +1042,13 @@ namespace OpenLoco::Ui::Windows::CompanyList if (!(self->var_854 & (1 << cargoCount)) || !(_word_9C68C7 & (1 << 2))) { - Gfx::fillRect(*rt, x, y + 3, x + 4, y + 7, palette); + drawingCtx.fillRect(*rt, x, y + 3, x + 4, y + 7, palette); } auto args = FormatArguments(); args.push(cargo->name); - Gfx::drawStringLeftClipped(*rt, x + 6, y, 94, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(*rt, x + 6, y, 94, Colour::black, stringId, &args); y += 10; cargoCount++; @@ -1051,6 +1058,8 @@ namespace OpenLoco::Ui::Windows::CompanyList // 0x00437120 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -1126,12 +1135,12 @@ namespace OpenLoco::Ui::Windows::CompanyList args.push(100); args.push(10); - Gfx::drawStringLeft(*rt, x, y, Colour::black, StringIds::cargo_deliver_graph_title, &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::cargo_deliver_graph_title, &args); x = self.x + 160; y = self.height + self.y - 13; - Gfx::drawStringLeft(*rt, x, y, Colour::black, StringIds::cargo_transit_time); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::cargo_transit_time); } // 0x004379F2 @@ -1220,6 +1229,8 @@ namespace OpenLoco::Ui::Windows::CompanyList // 0x0043745A static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -1241,7 +1252,7 @@ namespace OpenLoco::Ui::Windows::CompanyList }; auto x = self.x + 4; - Gfx::drawStringLeft(*rt, x, y, Colour::black, string[i], &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, string[i], &args); } y += 11; @@ -1256,7 +1267,7 @@ namespace OpenLoco::Ui::Windows::CompanyList imageId = Gfx::recolour(imageId, company->mainColours.primary); auto x = self.x + 4; - Gfx::drawImage(rt, x, y, imageId); + drawingCtx.drawImage(rt, x, y, imageId); x = self.x + 33; y += 7; @@ -1266,7 +1277,7 @@ namespace OpenLoco::Ui::Windows::CompanyList args.push(0); args.push(CompanyManager::getRecords().date[i]); - Gfx::drawStringLeft(*rt, x, y, Colour::black, StringIds::record_date_achieved, &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::record_date_achieved, &args); y += 17; } @@ -1473,6 +1484,8 @@ namespace OpenLoco::Ui::Windows::CompanyList // 0x00437637 static void drawTabs(Window* self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto skin = ObjectManager::get(); // Company List Tab @@ -1582,7 +1595,7 @@ namespace OpenLoco::Ui::Windows::CompanyList { auto x = self->widgets[widx::tab_values].left + self->x + 28; auto y = self->widgets[widx::tab_values].top + self->y + 14 + 1; - Gfx::drawStringRight(*rt, x, y, Colour::black, StringIds::currency_symbol); + drawingCtx.drawStringRight(*rt, x, y, Colour::black, StringIds::currency_symbol); } } @@ -1598,7 +1611,7 @@ namespace OpenLoco::Ui::Windows::CompanyList { auto x = self->widgets[widx::tab_payment_rates].left + self->x + 28; auto y = self->widgets[widx::tab_payment_rates].top + self->y + 14 + 1; - Gfx::drawStringRight(*rt, x, y, Colour::black, StringIds::currency_symbol); + drawingCtx.drawStringRight(*rt, x, y, Colour::black, StringIds::currency_symbol); } } @@ -1636,6 +1649,8 @@ namespace OpenLoco::Ui::Windows::CompanyList // 0x00437810 static void drawGraphLegend(Window* self, Gfx::RenderTarget* rt, int16_t x, int16_t y) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto companyCount = 0; for (auto& company : CompanyManager::companies()) { @@ -1650,13 +1665,13 @@ namespace OpenLoco::Ui::Windows::CompanyList if (!(self->var_854 & (1 << companyCount)) || !(_word_9C68C7 & (1 << 2))) { - Gfx::fillRect(*rt, x, y + 3, x + 4, y + 7, colour); + drawingCtx.fillRect(*rt, x, y + 3, x + 4, y + 7, colour); } auto args = FormatArguments(); args.push(company.name); - Gfx::drawStringLeftClipped(*rt, x + 6, y, 94, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(*rt, x + 6, y, 94, Colour::black, stringId, &args); y += 10; companyCount++; diff --git a/src/OpenLoco/src/Windows/CompanyWindow.cpp b/src/OpenLoco/src/Windows/CompanyWindow.cpp index bee13cfe43..300a92c19a 100644 --- a/src/OpenLoco/src/Windows/CompanyWindow.cpp +++ b/src/OpenLoco/src/Windows/CompanyWindow.cpp @@ -2,6 +2,7 @@ #include "CompanyManager.h" #include "Config.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Economy/Expenditures.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" @@ -187,6 +188,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 0x00432055 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); Common::drawCompanySelect(&self, rt); @@ -196,7 +199,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // Draw 'owner' label { auto& widget = self.widgets[widx::face]; - Gfx::drawStringCentred( + drawingCtx.drawStringCentred( *rt, self.x + (widget.left + widget.right) / 2, self.y + widget.top - 12, @@ -210,7 +213,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow const uint32_t image = Gfx::recolour(competitor->images[company->ownerEmotion] + 1, company->mainColours.primary); const uint16_t x = self.x + self.widgets[widx::face].left + 1; const uint16_t y = self.y + self.widgets[widx::face].top + 1; - Gfx::drawImage(rt, x, y, image); + drawingCtx.drawImage(rt, x, y, image); } // If the owner's been naughty, draw some jail bars over them. @@ -219,7 +222,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow const uint32_t image = ImageIds::owner_jailed; const uint16_t x = self.x + self.widgets[widx::face].left + 1; const uint16_t y = self.y + self.widgets[widx::face].top + 1; - Gfx::drawImage(rt, x, y, image); + drawingCtx.drawImage(rt, x, y, image); } // Draw owner name @@ -227,7 +230,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow auto args = FormatArguments::common(company->ownerName); auto& widget = self.widgets[widx::change_owner_name]; auto origin = Ui::Point(self.x + (widget.left + widget.right) / 2, self.y + widget.top + 5); - Gfx::drawStringCentredWrapped( + drawingCtx.drawStringCentredWrapped( *rt, origin, widget.right - widget.left, @@ -248,7 +251,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow CompanyManager::getOwnerStatus(CompanyId(self.number), args); auto& widget = self.widgets[widx::unk_11]; - Gfx::drawStringLeftClipped( + drawingCtx.drawStringLeftClipped( *rt, self.x + widget.left - 1, self.y + widget.top - 1, @@ -717,26 +720,28 @@ namespace OpenLoco::Ui::Windows::CompanyWindow static void drawAIdetails(Gfx::RenderTarget& rt, const int32_t x, int32_t& y, const OpenLoco::Company& company) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + const auto competitor = ObjectManager::get(company.competitorId); { FormatArguments args{}; args.push(competitor->intelligence); args.push(aiRatingToLevel(competitor->intelligence)); - Gfx::drawStringLeft(rt, x, y, Colour::black, StringIds::company_details_intelligence, &args); + drawingCtx.drawStringLeft(rt, x, y, Colour::black, StringIds::company_details_intelligence, &args); y += 10; } { FormatArguments args{}; args.push(competitor->aggressiveness); args.push(aiRatingToLevel(competitor->aggressiveness)); - Gfx::drawStringLeft(rt, x, y, Colour::black, StringIds::company_details_aggressiveness, &args); + drawingCtx.drawStringLeft(rt, x, y, Colour::black, StringIds::company_details_aggressiveness, &args); y += 10; } { FormatArguments args{}; args.push(competitor->competitiveness); args.push(aiRatingToLevel(competitor->competitiveness)); - Gfx::drawStringLeft(rt, x, y, Colour::black, StringIds::company_details_competitiveness, &args); + drawingCtx.drawStringLeft(rt, x, y, Colour::black, StringIds::company_details_competitiveness, &args); y += 10; } } @@ -755,6 +760,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 0x00432919 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); Common::drawCompanySelect(&self, rt); @@ -764,7 +771,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow auto y = self.y + 48; { auto args = FormatArguments::common(company->startedDate); - Gfx::drawStringLeft(*rt, x, y, Colour::black, StringIds::company_details_started, &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::company_details_started, &args); y += 10; } @@ -781,13 +788,13 @@ namespace OpenLoco::Ui::Windows::CompanyWindow { formatId = StringIds::company_details_performance_increasing; } - Gfx::drawStringLeft(*rt, x, y, Colour::black, formatId, &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, formatId, &args); y += 25; } { auto args = FormatArguments::common(company->ownerName); - Gfx::drawStringLeftClipped(*rt, x, y, 213, Colour::black, StringIds::owner_label, &args); + drawingCtx.drawStringLeftClipped(*rt, x, y, 213, Colour::black, StringIds::owner_label, &args); y += 10; } @@ -804,7 +811,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow if (count != 0) { auto args = FormatArguments::common(count); - Gfx::drawStringLeft(*rt, x, y, Colour::black, transportTypeCountString[i], &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, transportTypeCountString[i], &args); y += 10; } } @@ -813,7 +820,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow { x = self.x + (self.widgets[widx::viewport].left + self.widgets[widx::viewport].right) / 2; y = self.y + self.widgets[widx::viewport].top - 12; - Gfx::drawStringCentred(*rt, x, y, Colour::black, StringIds::wcolour2_headquarters); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::wcolour2_headquarters); } if (company->headquartersX == -1) @@ -824,7 +831,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow static_cast(self.y + self.widgets[widx::viewport].top + self.widgets[widx::viewport].height() / 2 - 5) }; width -= 2; - Gfx::drawStringCentredWrapped(*rt, loc, width, Colour::black, StringIds::not_yet_constructed); + drawingCtx.drawStringCentredWrapped(*rt, loc, width, Colour::black, StringIds::not_yet_constructed); } if (self.viewports[0] != nullptr) @@ -1343,6 +1350,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 0x00432F9A static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); Common::drawCompanySelect(&self, rt); @@ -1352,7 +1361,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow uint16_t y = self.y + widget.top + 3; // 'Main colour scheme' - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, x, y, @@ -1361,7 +1370,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 'Special colour schemes used for' y += 17; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, x, y, @@ -1662,6 +1671,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 0x004333D0 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); Common::drawCompanySelect(&self, rt); @@ -1670,7 +1681,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // Draw 'expenditure/income' label { - Gfx::drawStringLeftUnderline( + drawingCtx.drawStringLeftUnderline( *rt, self.x + 5, self.y + 47, @@ -1706,11 +1717,11 @@ namespace OpenLoco::Ui::Windows::CompanyWindow if (i % 2 == 0) { auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 6) | 0x1000000; - Gfx::fillRect(*rt, self.x + 4, y, self.x + 129, y + 9, colour); + drawingCtx.fillRect(*rt, self.x + 4, y, self.x + 129, y + 9, colour); } auto args = FormatArguments::common(ExpenditureLabels[i]); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 5, y - 1, @@ -1723,7 +1734,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 'Current loan' label { - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 7, self.y + self.widgets[widx::currentLoan].top, @@ -1736,7 +1747,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow loco_global _loanInterestRate; FormatArguments args{}; args.push(_loanInterestRate); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + self.widgets[widx::currentLoan].right + 3, self.y + self.widgets[widx::currentLoan].top + 1, @@ -1756,7 +1767,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow if (company->cash.var_04 < 0) cashFormat = StringIds::cash_negative; - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 7, self.y + self.widgets[widx::currentLoan].top + 13, @@ -1770,7 +1781,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // Set company value in format args. auto args = FormatArguments::common(company->companyValueHistory[0]); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 7, self.y + self.widgets[widx::currentLoan].top + 26, @@ -1784,7 +1795,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // Set company value in format args. auto args = FormatArguments::common(company->vehicleProfit); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 7, self.y + self.widgets[widx::currentLoan].top + 39, @@ -1804,7 +1815,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow format = StringIds::black_stringid; } - Gfx::drawStringRightUnderline( + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringRightUnderline( *rt, x, y, @@ -1816,6 +1828,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow static currency48_t drawFinanceExpenditureColumn(Gfx::RenderTarget* rt, const int16_t x, int16_t& y, uint8_t columnIndex, Company& company) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + currency48_t sum = 0; for (auto j = 0; j < ExpenditureType::Count; j++) { @@ -1826,7 +1840,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow { auto args = FormatArguments::common(StringIds::currency48, expenditures); - Gfx::drawStringRight( + drawingCtx.drawStringRight( *rt, x, y, @@ -1841,6 +1855,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow static void drawFinanceSum(Gfx::RenderTarget* rt, int16_t x, int16_t& y, currency48_t sum) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto mainFormat = StringIds::black_stringid; auto sumFormat = StringIds::plus_currency48; if (sum < 0) @@ -1852,14 +1868,16 @@ namespace OpenLoco::Ui::Windows::CompanyWindow y += 4; - Gfx::drawStringRight(*rt, x, y, Colour::black, mainFormat, &args); + drawingCtx.drawStringRight(*rt, x, y, Colour::black, mainFormat, &args); - Gfx::fillRect(*rt, x - expenditureColumnWidth + 10, y - 2, x, y - 2, enumValue(Colour::darkGreen)); + drawingCtx.fillRect(*rt, x - expenditureColumnWidth + 10, y - 2, x, y - 2, enumValue(Colour::darkGreen)); } // 0x0043361E static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + int16_t y = 47 - self.widgets[widx::scrollview].top + 14; for (uint8_t i = 0; i < static_cast(ExpenditureType::Count); i++) @@ -1868,7 +1886,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow if (i % 2 == 0) { auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 6) | 0x1000000; - Gfx::fillRect(rt, 0, y, expenditureColumnWidth * 17, y + 9, colour); + drawingCtx.fillRect(rt, 0, y, expenditureColumnWidth * 17, y + 9, colour); } y += 10; @@ -2137,13 +2155,15 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 0x00433ACD static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); uint16_t y = self.y + 47; // 'Cargo delivered' - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 5, y, @@ -2168,7 +2188,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow args.push(company->cargoDelivered[i]); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 10, y, @@ -2183,7 +2203,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // No cargo delivered yet? if (numPrinted == 0) { - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, self.x + 10, y, @@ -2325,6 +2345,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow // 0x00433DEB static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -2335,15 +2357,15 @@ namespace OpenLoco::Ui::Windows::CompanyWindow int16_t y = self.y + 47; // for example: "Provide the transport services on this little island" for "Boulder Breakers" scenario - y = Gfx::drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::buffer_2039); + y = drawingCtx.drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::buffer_2039); y += 5; - Gfx::drawStringLeft(*rt, self.x + 5, y, Colour::black, StringIds::challenge_label); + drawingCtx.drawStringLeft(*rt, self.x + 5, y, Colour::black, StringIds::challenge_label); y += 10; { FormatArguments args = {}; Scenario::formatChallengeArguments(Scenario::getObjective(), Scenario::getObjectiveProgress(), args); - y = Gfx::drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::challenge_value, &args); + y = drawingCtx.drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::challenge_value, &args); y += 5; } @@ -2355,13 +2377,13 @@ namespace OpenLoco::Ui::Windows::CompanyWindow uint16_t months = Scenario::getObjectiveProgress().completedChallengeInMonths % 12; auto args = FormatArguments::common(years, months); - Gfx::drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::success_you_completed_the_challenge_in_years_months, &args); + drawingCtx.drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::success_you_completed_the_challenge_in_years_months, &args); return; } if ((playerCompany->challengeFlags & CompanyFlags::challengeFailed) != CompanyFlags::none) { - Gfx::drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::failed_you_failed_to_complete_the_challenge); + drawingCtx.drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::failed_you_failed_to_complete_the_challenge); return; } @@ -2375,14 +2397,14 @@ namespace OpenLoco::Ui::Windows::CompanyWindow args.skip(2); args.push(years); args.push(months); - Gfx::drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::beaten_by_other_player_completed_in_years_months, &args); + drawingCtx.drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::beaten_by_other_player_completed_in_years_months, &args); return; } { FormatArguments args{}; args.push(playerCompany->challengeProgress); - y = Gfx::drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::progress_towards_completing_challenge_percent, &args); + y = drawingCtx.drawStringLeftWrapped(*rt, self.x + 5, y, self.width - 10, Colour::black, StringIds::progress_towards_completing_challenge_percent, &args); } if ((Scenario::getObjective().flags & Scenario::ObjectiveFlags::withinTimeLimit) != 0) @@ -2393,7 +2415,7 @@ namespace OpenLoco::Ui::Windows::CompanyWindow uint16_t months = monthsLeft % 12; auto args = FormatArguments::common(years, months); - Gfx::drawStringLeftWrapped(*rt, self.x + 5, y, self.width + 10, Colour::black, StringIds::time_remaining_years_months, &args); + drawingCtx.drawStringLeftWrapped(*rt, self.x + 5, y, self.width + 10, Colour::black, StringIds::time_remaining_years_months, &args); return; } } @@ -2651,7 +2673,8 @@ namespace OpenLoco::Ui::Windows::CompanyWindow const uint32_t image = Gfx::recolour(competitor->images[company->ownerEmotion], company->mainColours.primary); const uint16_t x = self->x + self->widgets[Common::widx::company_select].left + 1; const uint16_t y = self->y + self->widgets[Common::widx::company_select].top + 1; - Gfx::drawImage(rt, x, y, image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(rt, x, y, image); } // 0x00434413 diff --git a/src/OpenLoco/src/Windows/Construction/Common.cpp b/src/OpenLoco/src/Windows/Construction/Common.cpp index 912a0b69f3..13263334f5 100644 --- a/src/OpenLoco/src/Windows/Construction/Common.cpp +++ b/src/OpenLoco/src/Windows/Construction/Common.cpp @@ -1,6 +1,7 @@ #include "CompanyManager.h" #include "Construction.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -747,6 +748,8 @@ namespace OpenLoco::Ui::Windows::Construction // 0x0049EFEF static void drawRoadTabs(Window* self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto company = CompanyManager::getPlayerCompany(); auto companyColour = company->mainColours.primary; auto roadObj = ObjectManager::get(_trackType & ~(1 << 7)); @@ -780,14 +783,14 @@ namespace OpenLoco::Ui::Windows::Construction clipped->y <<= 1; auto roadStationObj = ObjectManager::get(_lastSelectedStationType); auto imageId = Gfx::recolour(roadStationObj->image, companyColour); - Gfx::drawImage(&*clipped, -4, -10, imageId); + drawingCtx.drawImage(&*clipped, -4, -10, imageId); auto colour = Colours::getTranslucent(companyColour); if (!(roadStationObj->flags & RoadStationFlags::recolourable)) { colour = ExtColour::unk2E; } imageId = Gfx::recolourTranslucent(roadStationObj->image, colour) + 1; - Gfx::drawImage(&*clipped, -4, -10, imageId); + drawingCtx.drawImage(&*clipped, -4, -10, imageId); } Widget::drawTab(self, rt, -2, widx::tab_station); @@ -809,7 +812,7 @@ namespace OpenLoco::Ui::Windows::Construction auto imageId = roadExtraObj->var_0E; if (self->currentTab == widx::tab_overhead - widx::tab_construction) imageId += (self->frameNo / 2) % 8; - Gfx::drawImage(rt, x, y, imageId); + drawingCtx.drawImage(rt, x, y, imageId); } } @@ -821,6 +824,8 @@ namespace OpenLoco::Ui::Windows::Construction // 0x0049ED40 static void drawTrackTabs(Window* self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto company = CompanyManager::getPlayerCompany(); auto companyColour = company->mainColours.primary; auto trackObj = ObjectManager::get(_trackType); @@ -871,7 +876,7 @@ namespace OpenLoco::Ui::Windows::Construction auto trainStationObj = ObjectManager::get(_lastSelectedStationType); auto imageId = Gfx::recolour(trainStationObj->image + TrainStation::ImageIds::preview_image, companyColour); - Gfx::drawImage(&*clipped, -4, -9, imageId); + drawingCtx.drawImage(&*clipped, -4, -9, imageId); auto colour = Colours::getTranslucent(companyColour); if (!(trainStationObj->flags & TrainStationFlags::recolourable)) @@ -879,7 +884,7 @@ namespace OpenLoco::Ui::Windows::Construction colour = ExtColour::unk2E; } imageId = Gfx::recolourTranslucent(trainStationObj->image + TrainStation::ImageIds::preview_image_windows, colour); - Gfx::drawImage(&*clipped, -4, -9, imageId); + drawingCtx.drawImage(&*clipped, -4, -9, imageId); } Widget::drawTab(self, rt, -2, widx::tab_station); @@ -913,7 +918,7 @@ namespace OpenLoco::Ui::Windows::Construction frameIndex <<= 3; imageId += frameIndex; } - Gfx::drawImage(&*clipped, 15, 31, imageId); + drawingCtx.drawImage(&*clipped, 15, 31, imageId); } Widget::drawTab(self, rt, -2, widx::tab_signal); @@ -935,7 +940,7 @@ namespace OpenLoco::Ui::Windows::Construction auto imageId = trackExtraObj->var_0E; if (self->currentTab == widx::tab_overhead - widx::tab_construction) imageId += (self->frameNo / 2) % 8; - Gfx::drawImage(rt, x, y, imageId); + drawingCtx.drawImage(rt, x, y, imageId); } } diff --git a/src/OpenLoco/src/Windows/Construction/ConstructionTab.cpp b/src/OpenLoco/src/Windows/Construction/ConstructionTab.cpp index 87692e7aec..195907c241 100644 --- a/src/OpenLoco/src/Windows/Construction/ConstructionTab.cpp +++ b/src/OpenLoco/src/Windows/Construction/ConstructionTab.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "CompanyManager.h" #include "Construction.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/ImageIds.h" #include "Input.h" @@ -2651,8 +2652,10 @@ namespace OpenLoco::Ui::Windows::Construction::Construction x += self->x; auto y = self->widgets[widx::construct].bottom + self->y - 23; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + if (_constructionHover != 1) - Gfx::drawStringCentred(*rt, x, y, Colour::black, StringIds::build_this); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::build_this); y += 11; @@ -2662,7 +2665,7 @@ namespace OpenLoco::Ui::Windows::Construction::Construction { auto args = FormatArguments(); args.push(_trackCost); - Gfx::drawStringCentred(*rt, x, y, Colour::black, StringIds::build_cost, &args); + drawingCtx.drawStringCentred(*rt, x, y, Colour::black, StringIds::build_cost, &args); } } } @@ -2710,6 +2713,8 @@ namespace OpenLoco::Ui::Windows::Construction::Construction // 0x0049CF36 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -2725,7 +2730,7 @@ namespace OpenLoco::Ui::Windows::Construction::Construction auto x = self.x + self.widgets[widx::bridge].left + 2; auto y = self.y + self.widgets[widx::bridge].top + 1; - Gfx::drawImage(rt, x, y, imageId); + drawingCtx.drawImage(rt, x, y, imageId); } } } diff --git a/src/OpenLoco/src/Windows/Construction/OverheadTab.cpp b/src/OpenLoco/src/Windows/Construction/OverheadTab.cpp index 128d18f0a4..f00ce146dc 100644 --- a/src/OpenLoco/src/Windows/Construction/OverheadTab.cpp +++ b/src/OpenLoco/src/Windows/Construction/OverheadTab.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "CompanyManager.h" #include "Construction.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/ImageIds.h" #include "Input.h" @@ -518,7 +519,8 @@ namespace OpenLoco::Ui::Windows::Construction::Overhead auto args = FormatArguments(); args.push(_modCost); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); } } diff --git a/src/OpenLoco/src/Windows/Construction/SignalTab.cpp b/src/OpenLoco/src/Windows/Construction/SignalTab.cpp index c019550b75..2ac7fc775c 100644 --- a/src/OpenLoco/src/Windows/Construction/SignalTab.cpp +++ b/src/OpenLoco/src/Windows/Construction/SignalTab.cpp @@ -1,5 +1,6 @@ #include "Audio/Audio.h" #include "Construction.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/ImageIds.h" #include "Input.h" @@ -300,6 +301,8 @@ namespace OpenLoco::Ui::Windows::Construction::Signal // 0x0049E501 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -313,7 +316,7 @@ namespace OpenLoco::Ui::Windows::Construction::Signal auto args = FormatArguments(); args.push(trainSignalObject->var_0C); - Gfx::drawStringLeftWrapped(*rt, xPos, yPos, width, Colour::black, StringIds::signal_black, &args); + drawingCtx.drawStringLeftWrapped(*rt, xPos, yPos, width, Colour::black, StringIds::signal_black, &args); } auto imageId = trainSignalObject->image; @@ -321,14 +324,14 @@ namespace OpenLoco::Ui::Windows::Construction::Signal xPos = self.widgets[widx::both_directions].midX() + self.x; yPos = self.widgets[widx::both_directions].bottom + self.y - 4; - Gfx::drawImage(rt, xPos - 8, yPos, imageId); + drawingCtx.drawImage(rt, xPos - 8, yPos, imageId); - Gfx::drawImage(rt, xPos + 8, yPos, imageId + 4); + drawingCtx.drawImage(rt, xPos + 8, yPos, imageId + 4); xPos = self.widgets[widx::single_direction].midX() + self.x; yPos = self.widgets[widx::single_direction].bottom + self.y - 4; - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); if (_signalCost != 0x80000000 && _signalCost != 0) { @@ -338,7 +341,7 @@ namespace OpenLoco::Ui::Windows::Construction::Signal xPos = self.x + 69; yPos = self.widgets[widx::single_direction].bottom + self.y + 5; - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); } } diff --git a/src/OpenLoco/src/Windows/Construction/StationTab.cpp b/src/OpenLoco/src/Windows/Construction/StationTab.cpp index f707e309b6..4496986bf0 100644 --- a/src/OpenLoco/src/Windows/Construction/StationTab.cpp +++ b/src/OpenLoco/src/Windows/Construction/StationTab.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "CompanyManager.h" #include "Construction.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/ImageIds.h" #include "Industry.h" @@ -621,6 +622,8 @@ namespace OpenLoco::Ui::Windows::Construction::Station // 0x0049DE40 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -633,20 +636,20 @@ namespace OpenLoco::Ui::Windows::Construction::Station { auto airportObj = ObjectManager::get(_lastSelectedStationType); auto imageId = Gfx::recolour(airportObj->image, companyColour); - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); } else if (_byte_1136063 & (1 << 6)) { auto dockObj = ObjectManager::get(_lastSelectedStationType); auto imageId = Gfx::recolour(dockObj->image, companyColour); - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); } else if (_trackType & (1 << 7)) { auto roadStationObj = ObjectManager::get(_lastSelectedStationType); auto imageId = Gfx::recolour(roadStationObj->image + RoadStation::ImageIds::preview_image, companyColour); - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); auto colour = Colours::getTranslucent(companyColour); if (!(roadStationObj->flags & RoadStationFlags::recolourable)) @@ -655,14 +658,14 @@ namespace OpenLoco::Ui::Windows::Construction::Station } imageId = Gfx::recolourTranslucent(roadStationObj->image + RoadStation::ImageIds::preview_image_windows, colour); - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); } else { auto trainStationObj = ObjectManager::get(_lastSelectedStationType); auto imageId = Gfx::recolour(trainStationObj->image + TrainStation::ImageIds::preview_image, companyColour); - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); auto colour = Colours::getTranslucent(companyColour); if (!(trainStationObj->flags & TrainStationFlags::recolourable)) @@ -671,7 +674,7 @@ namespace OpenLoco::Ui::Windows::Construction::Station } imageId = Gfx::recolourTranslucent(trainStationObj->image + TrainStation::ImageIds::preview_image_windows, colour); - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); } if (_stationCost != 0x80000000 && _stationCost != 0) @@ -682,13 +685,13 @@ namespace OpenLoco::Ui::Windows::Construction::Station auto args = FormatArguments(); args.push(_stationCost); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); } xPos = self.x + 3; yPos = self.widgets[widx::image].bottom + self.y + 16; auto width = self.width - 4; - Gfx::drawRectInset(*rt, xPos, yPos, width, 1, self.getColour(WindowColour::secondary).u8(), (1 << 5)); + drawingCtx.drawRectInset(*rt, xPos, yPos, width, 1, self.getColour(WindowColour::secondary).u8(), (1 << 5)); if (!(_byte_522096 & (1 << 3))) return; @@ -710,17 +713,17 @@ namespace OpenLoco::Ui::Windows::Construction::Station xPos = self.x + 69; yPos = self.widgets[widx::image].bottom + self.y + 18; width = self.width - 4; - Gfx::drawStringCentredClipped(*rt, xPos, yPos, width, Colour::black, StringIds::new_station_buffer, &args); + drawingCtx.drawStringCentredClipped(*rt, xPos, yPos, width, Colour::black, StringIds::new_station_buffer, &args); xPos = self.x + 2; yPos = self.widgets[widx::image].bottom + self.y + 29; Ui::Point origin = { xPos, yPos }; - Gfx::drawStringLeft(*rt, &origin, Colour::black, StringIds::catchment_area_accepts); + drawingCtx.drawStringLeft(*rt, &origin, Colour::black, StringIds::catchment_area_accepts); if (_constructingStationAcceptedCargoTypes == 0) { - Gfx::drawStringLeft(*rt, origin.x, origin.y, Colour::black, StringIds::catchment_area_nothing); + drawingCtx.drawStringLeft(*rt, origin.x, origin.y, Colour::black, StringIds::catchment_area_nothing); } else { @@ -734,7 +737,7 @@ namespace OpenLoco::Ui::Windows::Construction::Station { auto cargoObj = ObjectManager::get(i); - Gfx::drawImage(rt, origin.x, origin.y, cargoObj->unitInlineSprite); + drawingCtx.drawImage(rt, origin.x, origin.y, cargoObj->unitInlineSprite); origin.x += 10; } } @@ -745,11 +748,11 @@ namespace OpenLoco::Ui::Windows::Construction::Station yPos = self.widgets[widx::image].bottom + self.y + 49; origin = { xPos, yPos }; - Gfx::drawStringLeft(*rt, &origin, Colour::black, StringIds::catchment_area_produces); + drawingCtx.drawStringLeft(*rt, &origin, Colour::black, StringIds::catchment_area_produces); if (_constructingStationProducedCargoTypes == 0) { - Gfx::drawStringLeft(*rt, origin.x, origin.y, Colour::black, StringIds::catchment_area_nothing); + drawingCtx.drawStringLeft(*rt, origin.x, origin.y, Colour::black, StringIds::catchment_area_nothing); } else { @@ -763,7 +766,7 @@ namespace OpenLoco::Ui::Windows::Construction::Station { auto cargoObj = ObjectManager::get(i); - Gfx::drawImage(rt, origin.x, origin.y, cargoObj->unitInlineSprite); + drawingCtx.drawImage(rt, origin.x, origin.y, cargoObj->unitInlineSprite); origin.x += 10; } } diff --git a/src/OpenLoco/src/Windows/EditKeyboardShortcut.cpp b/src/OpenLoco/src/Windows/EditKeyboardShortcut.cpp index 77d8f26776..9a9849b780 100644 --- a/src/OpenLoco/src/Windows/EditKeyboardShortcut.cpp +++ b/src/OpenLoco/src/Windows/EditKeyboardShortcut.cpp @@ -1,4 +1,5 @@ #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "Input/Shortcut.h" @@ -67,12 +68,14 @@ namespace OpenLoco::Ui::Windows::EditKeyboardShortcut // 0x004BE8DF static void draw(Ui::Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); FormatArguments args{}; args.push(ShortcutManager::getName(static_cast(*_editingShortcutIndex))); auto point = Ui::Point(self.x + 140, self.y + 32); - Gfx::drawStringCentredWrapped(*rt, point, 272, Colour::black, StringIds::change_keyboard_shortcut_desc, &args); + drawingCtx.drawStringCentredWrapped(*rt, point, 272, Colour::black, StringIds::change_keyboard_shortcut_desc, &args); } // 0x004BE821 diff --git a/src/OpenLoco/src/Windows/Error.cpp b/src/OpenLoco/src/Windows/Error.cpp index 5b606734d2..598981ba96 100644 --- a/src/OpenLoco/src/Windows/Error.cpp +++ b/src/OpenLoco/src/Windows/Error.cpp @@ -1,5 +1,6 @@ #include "Audio/Audio.h" #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "Interop/Interop.hpp" @@ -96,18 +97,20 @@ namespace OpenLoco::Ui::Windows::Error if (buffer != &_byte_9C64B3[0]) { - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); int16_t strWidth; { - strWidth = Gfx::getStringWidthNewLined(&_byte_9C64B3[0]); + strWidth = drawingCtx.getStringWidthNewLined(&_byte_9C64B3[0]); } strWidth = std::min(strWidth, 196); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); { uint16_t breakLineCount = 0; - std::tie(strWidth, breakLineCount) = Gfx::wrapString(&_byte_9C64B3[0], strWidth); + std::tie(strWidth, breakLineCount) = drawingCtx.wrapString(&_byte_9C64B3[0], strWidth); _word_9C66B3 = breakLineCount; } @@ -211,23 +214,24 @@ namespace OpenLoco::Ui::Windows::Error uint16_t width = self.width; uint16_t height = self.height; auto skin = ObjectManager::get()->colour_09; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); - Gfx::drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | 45); - Gfx::drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | (116 + enumValue(skin))); + drawingCtx.drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | 45); + drawingCtx.drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | (116 + enumValue(skin))); - Gfx::drawRect(*rt, x, y + 2, 1, height - 4, 0x2000000 | 46); - Gfx::drawRect(*rt, x + width - 1, y + 2, 1, height - 4, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 2, y + height - 1, width - 4, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 2, y, width - 4, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x, y + 2, 1, height - 4, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + width - 1, y + 2, 1, height - 4, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 2, y + height - 1, width - 4, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 2, y, width - 4, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 1, y + 1, 1, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + width - 1 - 1, y + 1, 1, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + width - 1 - 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 1, y + 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + width - 1 - 1, y + 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + width - 1 - 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); if (_errorCompetitorId == CompanyId::null) { - Gfx::drawStringCentredRaw(*rt, ((width + 1) / 2) + x - 1, y + 1, _word_9C66B3, Colour::black, &_byte_9C64B3[0]); + drawingCtx.drawStringCentredRaw(*rt, ((width + 1) / 2) + x - 1, y + 1, _word_9C66B3, Colour::black, &_byte_9C64B3[0]); } else { @@ -241,14 +245,14 @@ namespace OpenLoco::Ui::Windows::Error imageId = Gfx::recolour(imageId, company->mainColours.primary); imageId++; - Gfx::drawImage(rt, xPos, yPos, imageId); + drawingCtx.drawImage(rt, xPos, yPos, imageId); if (company->jailStatus != 0) { - Gfx::drawImage(rt, xPos, yPos, ImageIds::owner_jailed); + drawingCtx.drawImage(rt, xPos, yPos, ImageIds::owner_jailed); } - Gfx::drawStringCentredRaw(*rt, self.x + 156, self.y + 20, _word_9C66B3, Colour::black, &_byte_9C64B3[0]); + drawingCtx.drawStringCentredRaw(*rt, self.x + 156, self.y + 20, _word_9C66B3, Colour::black, &_byte_9C64B3[0]); } } diff --git a/src/OpenLoco/src/Windows/IndustryList.cpp b/src/OpenLoco/src/Windows/IndustryList.cpp index 2aa1c18321..d4a28a6a7c 100644 --- a/src/OpenLoco/src/Windows/IndustryList.cpp +++ b/src/OpenLoco/src/Windows/IndustryList.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "Config.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Economy/Economy.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -134,6 +135,8 @@ namespace OpenLoco::Ui::Windows::IndustryList // 0x00457CD9 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); auto args = FormatArguments(); @@ -146,7 +149,7 @@ namespace OpenLoco::Ui::Windows::IndustryList args.push(StringIds::status_num_industries_plural); args.push(self.var_83C); - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); } // 0x00457EC4 @@ -380,8 +383,10 @@ namespace OpenLoco::Ui::Windows::IndustryList // 0x00457D2A static void drawScroll(Ui::Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(self.getColour(WindowColour::secondary).c(), 4); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); uint16_t yPos = 0; for (uint16_t i = 0; i < self.var_83C; i++) @@ -400,7 +405,7 @@ namespace OpenLoco::Ui::Windows::IndustryList // Highlight selection. if (industryId == IndustryId(self.rowHover)) { - Gfx::drawRect(rt, 0, yPos, self.width, kRowHeight, 0x2000030); + drawingCtx.drawRect(rt, 0, yPos, self.width, kRowHeight, 0x2000030); text_colour_id = StringIds::wcolour2_stringid; } @@ -414,7 +419,7 @@ namespace OpenLoco::Ui::Windows::IndustryList args.push(industry->name); args.push(industry->town); - Gfx::drawStringLeftClipped(rt, 0, yPos, 198, Colour::black, text_colour_id, &args); + drawingCtx.drawStringLeftClipped(rt, 0, yPos, 198, Colour::black, text_colour_id, &args); } // Industry Status { @@ -424,7 +429,7 @@ namespace OpenLoco::Ui::Windows::IndustryList auto args = FormatArguments(); args.push(StringIds::buffer_1250); - Gfx::drawStringLeftClipped(rt, 200, yPos, 238, Colour::black, text_colour_id, &args); + drawingCtx.drawStringLeftClipped(rt, 200, yPos, 238, Colour::black, text_colour_id, &args); } // Industry Production Delivered { @@ -439,7 +444,7 @@ namespace OpenLoco::Ui::Windows::IndustryList auto args = FormatArguments(); args.push(productionTransported); - Gfx::drawStringLeftClipped(rt, 440, yPos, 138, Colour::black, StringIds::production_transported_percent, &args); + drawingCtx.drawStringLeftClipped(rt, 440, yPos, 138, Colour::black, StringIds::production_transported_percent, &args); } yPos += kRowHeight; } @@ -642,6 +647,8 @@ namespace OpenLoco::Ui::Windows::IndustryList // 0x0045826C static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -650,7 +657,7 @@ namespace OpenLoco::Ui::Windows::IndustryList auto xPos = self.x + 3; auto yPos = self.y + self.height - 13; auto width = self.width - 19; - Gfx::drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::no_industry_available); + drawingCtx.drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::no_industry_available); return; } @@ -685,14 +692,14 @@ namespace OpenLoco::Ui::Windows::IndustryList auto yPos = self.y + self.height - 13; widthOffset = 138; - Gfx::drawStringRight(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); + drawingCtx.drawStringRight(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); } auto xPos = self.x + 3; auto yPos = self.y + self.height - 13; auto width = self.width - 19 - widthOffset; - Gfx::drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::black_stringid, &industryObj->name); + drawingCtx.drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::black_stringid, &industryObj->name); } // 0x0045843A @@ -897,8 +904,10 @@ namespace OpenLoco::Ui::Windows::IndustryList // 0x00458352 static void drawScroll(Ui::Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(self.getColour(WindowColour::secondary).c(), 4); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); loco_global _word_E0C3C6; uint16_t xPos = 0; @@ -911,13 +920,13 @@ namespace OpenLoco::Ui::Windows::IndustryList if (self.rowInfo[i] == self.var_846) { _word_E0C3C6 = AdvancedColour::translucentFlag; - Gfx::drawRectInset(rt, xPos, yPos, kRowHeight, kRowHeight, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); + drawingCtx.drawRectInset(rt, xPos, yPos, kRowHeight, kRowHeight, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); } } else { _word_E0C3C6 = AdvancedColour::translucentFlag | AdvancedColour::outlineFlag; - Gfx::drawRectInset(rt, xPos, yPos, kRowHeight, kRowHeight, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); + drawingCtx.drawRectInset(rt, xPos, yPos, kRowHeight, kRowHeight, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); } auto industryObj = ObjectManager::get(self.rowInfo[i]); diff --git a/src/OpenLoco/src/Windows/IndustryWindow.cpp b/src/OpenLoco/src/Windows/IndustryWindow.cpp index e21784c489..00818857fe 100644 --- a/src/OpenLoco/src/Windows/IndustryWindow.cpp +++ b/src/OpenLoco/src/Windows/IndustryWindow.cpp @@ -2,6 +2,7 @@ #include "CompanyManager.h" #include "Config.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -131,6 +132,8 @@ namespace OpenLoco::Ui::Windows::Industry // 0x00455C22 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); self.drawViewports(rt); @@ -147,7 +150,7 @@ namespace OpenLoco::Ui::Windows::Industry auto x = self.x + widget->left - 1; auto y = self.y + widget->top - 1; auto width = widget->width(); - Gfx::drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::black_stringid, &args); } // 0x00455C86 @@ -442,6 +445,8 @@ namespace OpenLoco::Ui::Windows::Industry // 0x00456705 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -456,7 +461,7 @@ namespace OpenLoco::Ui::Windows::Industry { origin.x += 4; origin.y += 10; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::received_cargo); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::received_cargo); auto cargoNumber = 0; for (const auto& receivedCargoType : industryObj->requiredCargoType) @@ -476,7 +481,7 @@ namespace OpenLoco::Ui::Windows::Industry } args.push(industry->receivedCargoQuantityPreviousMonth[cargoNumber]); - origin.y = Gfx::drawStringLeftWrapped(*rt, origin.x, origin.y, 290, Colour::black, StringIds::black_stringid, &args); + origin.y = drawingCtx.drawStringLeftWrapped(*rt, origin.x, origin.y, 290, Colour::black, StringIds::black_stringid, &args); } cargoNumber++; } @@ -487,7 +492,7 @@ namespace OpenLoco::Ui::Windows::Industry // Draw Last Months produced cargo stats if (industry->canProduceCargo()) { - Gfx::drawStringLeft(*rt, origin.x, origin.y, Colour::black, StringIds::produced_cargo); + drawingCtx.drawStringLeft(*rt, origin.x, origin.y, Colour::black, StringIds::produced_cargo); origin.y += 10; origin.x += 4; @@ -510,7 +515,7 @@ namespace OpenLoco::Ui::Windows::Industry args.push(industry->producedCargoQuantityPreviousMonth[cargoNumber]); args.push(industry->producedCargoPercentTransportedPreviousMonth[cargoNumber]); - origin.y = Gfx::drawStringLeftWrapped(*rt, origin.x, origin.y, 290, Colour::black, StringIds::transported_cargo, &args); + origin.y = drawingCtx.drawStringLeftWrapped(*rt, origin.x, origin.y, 290, Colour::black, StringIds::transported_cargo, &args); } cargoNumber++; } @@ -570,6 +575,8 @@ namespace OpenLoco::Ui::Windows::Industry // 0x00456079 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -585,7 +592,7 @@ namespace OpenLoco::Ui::Windows::Industry int16_t x = self.x + 2; int16_t y = self.y - 24 + 68; - Gfx::drawStringLeft(*rt, x, y, Colour::black, StringIds::production_graph_label, &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::production_graph_label, &args); } // Draw Y label and grid lines. @@ -596,9 +603,9 @@ namespace OpenLoco::Ui::Windows::Industry auto args = FormatArguments(); args.push(yTick); - Gfx::drawRect(*rt, self.x + 41, yPos, 239, 1, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + drawingCtx.drawRect(*rt, self.x + 41, yPos, 239, 1, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); - Gfx::drawStringRight(*rt, self.x + 39, yPos - 6, Colour::black, StringIds::population_graph_people, &args); + drawingCtx.drawStringRight(*rt, self.x + 39, yPos - 6, Colour::black, StringIds::population_graph_people, &args); yTick += 1000; } @@ -623,10 +630,10 @@ namespace OpenLoco::Ui::Windows::Industry auto args = FormatArguments(); args.push(year); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::population_graph_year, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::population_graph_year, &args); } - Gfx::drawRect(*rt, xPos, yPos + 11, 1, self.height - 74, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + drawingCtx.drawRect(*rt, xPos, yPos + 11, 1, self.height - 74, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); } const auto history = productionTabWidx == widx::tab_production ? industry->producedCargoMonthlyHistory1 : industry->producedCargoMonthlyHistory2; @@ -641,7 +648,7 @@ namespace OpenLoco::Ui::Windows::Industry { if (yPos2 <= graphBottom) { - Gfx::drawLine(*rt, xPos, yPos1, xPos + 1, yPos2, Colours::getShade(self.getColour(WindowColour::secondary).c(), 7)); + drawingCtx.drawLine(*rt, xPos, yPos1, xPos + 1, yPos2, Colours::getShade(self.getColour(WindowColour::secondary).c(), 7)); } } } @@ -835,10 +842,11 @@ namespace OpenLoco::Ui::Windows::Industry auto xPos = widget.left + self->x; auto yPos = widget.top + self->y; - Gfx::drawImage(rt, xPos, yPos, imageId); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(rt, xPos, yPos, imageId); auto caroObj = ObjectManager::get(industryObj->producedCargoType[productionTabNumber]); - Gfx::drawImage(rt, xPos + 18, yPos + 14, caroObj->unitInlineSprite); + drawingCtx.drawImage(rt, xPos + 18, yPos + 14, caroObj->unitInlineSprite); Widget::drawTab(self, rt, -2, tab); } diff --git a/src/OpenLoco/src/Windows/KeyboardShortcuts.cpp b/src/OpenLoco/src/Windows/KeyboardShortcuts.cpp index 02dc35a3bf..f6dc37779a 100644 --- a/src/OpenLoco/src/Windows/KeyboardShortcuts.cpp +++ b/src/OpenLoco/src/Windows/KeyboardShortcuts.cpp @@ -1,4 +1,5 @@ #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "Input/ShortcutManager.h" @@ -154,9 +155,11 @@ namespace OpenLoco::Ui::Windows::KeyboardShortcuts // 0x004BE72C static void drawScroll(Ui::Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto colour = self.getColour(WindowColour::secondary).c(); auto shade = Colours::getShade(colour, 4); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); const auto& shortcuts = Config::get().shortcuts; auto yPos = 0; @@ -165,7 +168,7 @@ namespace OpenLoco::Ui::Windows::KeyboardShortcuts string_id format = StringIds::black_stringid; if (i == self.rowHover) { - Gfx::drawRect(rt, 0, yPos, 800, kRowHeight, 0x2000030); + drawingCtx.drawRect(rt, 0, yPos, 800, kRowHeight, 0x2000030); format = StringIds::wcolour2_stringid; } @@ -191,7 +194,7 @@ namespace OpenLoco::Ui::Windows::KeyboardShortcuts formatter.push(baseStringId); formatter.push(buffer); - Gfx::drawStringLeft(rt, 0, yPos - 1, Colour::black, format, &formatter); + drawingCtx.drawStringLeft(rt, 0, yPos - 1, Colour::black, format, &formatter); yPos += kRowHeight; } } diff --git a/src/OpenLoco/src/Windows/LandscapeGeneration.cpp b/src/OpenLoco/src/Windows/LandscapeGeneration.cpp index 6993ec35cb..cf54374874 100644 --- a/src/OpenLoco/src/Windows/LandscapeGeneration.cpp +++ b/src/OpenLoco/src/Windows/LandscapeGeneration.cpp @@ -1,4 +1,5 @@ #include "Audio/Audio.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "IndustryManager.h" @@ -171,9 +172,11 @@ namespace OpenLoco::Ui::Windows::LandscapeGeneration // 0x0043DC30 static void draw(Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::start_year].top, @@ -372,37 +375,39 @@ namespace OpenLoco::Ui::Windows::LandscapeGeneration // 0x0043DF89 static void draw(Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::generator].top, Colour::black, StringIds::generator); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::sea_level].top, Colour::black, StringIds::sea_level); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::min_land_height].top, Colour::black, StringIds::min_land_height); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::topography_style].top, Colour::black, StringIds::topography_style); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::hill_density].top, @@ -425,6 +430,8 @@ namespace OpenLoco::Ui::Windows::LandscapeGeneration // 0x0043E01C static void drawScroll(Ui::Window& window, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + uint16_t yPos = 0; for (uint16_t i = 0; i < kMaxLandObjects; i++) { @@ -434,26 +441,26 @@ namespace OpenLoco::Ui::Windows::LandscapeGeneration // Draw tile icon. const uint32_t imageId = landObject->var_16 + OpenLoco::Land::ImageIds::landscape_generator_tile_icon; - Gfx::drawImage(&rt, 2, yPos + 1, imageId); + drawingCtx.drawImage(&rt, 2, yPos + 1, imageId); // Draw land description. _commonFormatArgs[0] = landObject->name; - Gfx::drawStringLeftClipped(rt, 24, yPos + 5, 121, Colour::black, StringIds::wcolour2_stringid, &*_commonFormatArgs); + drawingCtx.drawStringLeftClipped(rt, 24, yPos + 5, 121, Colour::black, StringIds::wcolour2_stringid, &*_commonFormatArgs); // Draw rectangle. - Gfx::fillRectInset(rt, 150, yPos + 5, 340, yPos + 16, window.getColour(WindowColour::secondary).u8(), 0b110000); + drawingCtx.fillRectInset(rt, 150, yPos + 5, 340, yPos + 16, window.getColour(WindowColour::secondary).u8(), 0b110000); // Draw current distribution setting. const string_id distributionId = landDistributionLabelIds[enumValue(S5::getOptions().landDistributionPatterns[i])]; _commonFormatArgs[0] = distributionId; - Gfx::drawStringLeftClipped(rt, 151, yPos + 5, 177, Colour::black, StringIds::black_stringid, &*_commonFormatArgs); + drawingCtx.drawStringLeftClipped(rt, 151, yPos + 5, 177, Colour::black, StringIds::black_stringid, &*_commonFormatArgs); // Draw rectangle (knob). const uint8_t flags = window.rowHover == i ? 0b110000 : 0; - Gfx::fillRectInset(rt, 329, yPos + 6, 339, yPos + 15, window.getColour(WindowColour::secondary).u8(), flags); + drawingCtx.fillRectInset(rt, 329, yPos + 6, 339, yPos + 15, window.getColour(WindowColour::secondary).u8(), flags); // Draw triangle (knob). - Gfx::drawStringLeft(rt, 330, yPos + 6, Colour::black, StringIds::dropdown, nullptr); + drawingCtx.drawStringLeft(rt, 330, yPos + 6, Colour::black, StringIds::dropdown, nullptr); yPos += kRowHeight; } @@ -754,58 +761,60 @@ namespace OpenLoco::Ui::Windows::LandscapeGeneration // 0x0043E53A static void draw(Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::number_of_forests].top, Colour::black, StringIds::number_of_forests); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::minForestRadius].top, Colour::black, StringIds::min_forest_radius); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::maxForestRadius].top, Colour::black, StringIds::max_forest_radius); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::minForestDensity].top, Colour::black, StringIds::min_forest_density); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::maxForestDensity].top, Colour::black, StringIds::max_forest_density); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::number_random_trees].top, Colour::black, StringIds::number_random_trees); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::min_altitude_for_trees].top, Colour::black, StringIds::min_altitude_for_trees); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::max_altitude_for_trees].top, @@ -992,16 +1001,18 @@ namespace OpenLoco::Ui::Windows::LandscapeGeneration // 0x0043E9A3 static void draw(Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::number_of_towns].top, Colour::black, StringIds::number_of_towns); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::max_town_size].top, @@ -1133,9 +1144,11 @@ namespace OpenLoco::Ui::Windows::LandscapeGeneration // 0x0043EB9D static void draw(Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); - Gfx::drawStringLeft( + drawingCtx.drawStringLeft( *rt, window.x + 10, window.y + window.widgets[widx::num_industries].top, diff --git a/src/OpenLoco/src/Windows/LandscapeGenerationConfirm.cpp b/src/OpenLoco/src/Windows/LandscapeGenerationConfirm.cpp index a041dbf076..c3444844f4 100644 --- a/src/OpenLoco/src/Windows/LandscapeGenerationConfirm.cpp +++ b/src/OpenLoco/src/Windows/LandscapeGenerationConfirm.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Input.h" @@ -38,6 +39,8 @@ namespace OpenLoco::Ui::Windows::LandscapeGenerationConfirm // 0x004C18A5 static void draw(Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + window.draw(rt); static loco_global _commonFormatArgs; @@ -45,7 +48,7 @@ namespace OpenLoco::Ui::Windows::LandscapeGenerationConfirm *_commonFormatArgs = prompt; auto origin = Ui::Point(window.x + (window.width / 2), window.y + 41); - Gfx::drawStringCentredWrapped(*rt, origin, window.width, Colour::black, StringIds::wcolour2_stringid, (const char*)&*_commonFormatArgs); + drawingCtx.drawStringCentredWrapped(*rt, origin, window.width, Colour::black, StringIds::wcolour2_stringid, (const char*)&*_commonFormatArgs); } // 0x004C18E4 diff --git a/src/OpenLoco/src/Windows/MapToolTip.cpp b/src/OpenLoco/src/Windows/MapToolTip.cpp index 3b165d57fc..93b4ae50e9 100644 --- a/src/OpenLoco/src/Windows/MapToolTip.cpp +++ b/src/OpenLoco/src/Windows/MapToolTip.cpp @@ -1,4 +1,5 @@ #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Input.h" #include "Interop/Interop.hpp" @@ -115,6 +116,8 @@ namespace OpenLoco::Ui::Windows::MapToolTip // 0x004CF010 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto args = FormatArguments::mapToolTip(); StringManager::ArgsWrapper argsWrap(&args); auto firstArg = argsWrap.pop(); @@ -126,25 +129,25 @@ namespace OpenLoco::Ui::Windows::MapToolTip if (_mapTooltipOwner == CompanyId::null || _mapTooltipOwner == CompanyManager::getControllingId()) { Ui::Point origin(self.x + self.width / 2, self.y + self.height / 2 - 5); - Gfx::drawStringCentredWrapped(*rt, origin, self.width, Colour::black, StringIds::outlined_wcolour2_stringid, &args); + drawingCtx.drawStringCentredWrapped(*rt, origin, self.width, Colour::black, StringIds::outlined_wcolour2_stringid, &args); } else { Ui::Point origin(self.x + self.width / 2 + 13, self.y + self.height / 2 - 5); - auto width = Gfx::drawStringCentredWrapped(*rt, origin, self.width - 28, Colour::black, StringIds::outlined_wcolour2_stringid, &args); + auto width = drawingCtx.drawStringCentredWrapped(*rt, origin, self.width - 28, Colour::black, StringIds::outlined_wcolour2_stringid, &args); auto left = self.width / 2 + self.x + 13 - width / 2 - 28; auto top = self.height / 2 - 13 + self.y; auto right = left + 25; auto bottom = top + 25; - Gfx::fillRect(*rt, left, top, right, bottom, enumValue(Colour::darkGreen)); + drawingCtx.fillRect(*rt, left, top, right, bottom, enumValue(Colour::darkGreen)); auto* company = CompanyManager::get(_mapTooltipOwner); auto* competitor = ObjectManager::get(company->competitorId); auto imageId = Gfx::recolour(competitor->images[company->ownerEmotion], company->mainColours.primary); - Gfx::drawImage(rt, left + 1, top + 1, imageId); + drawingCtx.drawImage(rt, left + 1, top + 1, imageId); } } diff --git a/src/OpenLoco/src/Windows/MapWindow.cpp b/src/OpenLoco/src/Windows/MapWindow.cpp index 62cd46d918..3cf2e66b28 100644 --- a/src/OpenLoco/src/Windows/MapWindow.cpp +++ b/src/OpenLoco/src/Windows/MapWindow.cpp @@ -1,4 +1,5 @@ #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Engine/Limits.h" #include "Entities/Entity.h" #include "Entities/EntityManager.h" @@ -563,12 +564,14 @@ namespace OpenLoco::Ui::Windows::MapWindow StringIds::map_key_vegetation, }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + for (auto i = 0; i < kOverallGraphKeySize; i++) { auto colour = overallColours[i]; if (!(self->var_854 & (1 << i)) || !(mapFrameNumber & (1 << 2))) { - Gfx::drawRect(*rt, x, *y + 3, 5, 5, colour); + drawingCtx.drawRect(*rt, x, *y + 3, 5, 5, colour); } auto args = FormatArguments(); args.push(lineNames[i]); @@ -580,7 +583,7 @@ namespace OpenLoco::Ui::Windows::MapWindow stringId = StringIds::small_white_string; } - Gfx::drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); *y += 10; } @@ -608,13 +611,15 @@ namespace OpenLoco::Ui::Windows::MapWindow StringIds::forbid_ships, }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + for (uint8_t i = 0; i < std::size(_vehicleTypeCounts); i++) { if (!(self->var_854 & (1 << i)) || !(mapFrameNumber & (1 << 2))) { auto colour = vehicleTypeColours[i]; - Gfx::drawRect(*rt, x, *y + 3, 5, 5, colour); + drawingCtx.drawRect(*rt, x, *y + 3, 5, 5, colour); } auto args = FormatArguments(); args.push(lineNames[i]); @@ -626,7 +631,7 @@ namespace OpenLoco::Ui::Windows::MapWindow stringId = StringIds::small_white_string; } - Gfx::drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); *y += 10; } @@ -669,6 +674,8 @@ namespace OpenLoco::Ui::Windows::MapWindow PaletteIndex::index_12, }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + for (uint8_t i = 0; i < ObjectManager::getMaxObjects(ObjectType::industry); i++) { auto industry = ObjectManager::get(i); @@ -680,7 +687,7 @@ namespace OpenLoco::Ui::Windows::MapWindow { auto colour = industryColours[_byte_F253CE[i]]; - Gfx::drawRect(*rt, x, *y + 3, 5, 5, colour); + drawingCtx.drawRect(*rt, x, *y + 3, 5, 5, colour); } auto args = FormatArguments(); @@ -693,7 +700,7 @@ namespace OpenLoco::Ui::Windows::MapWindow stringId = StringIds::small_white_string; } - Gfx::drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); *y += 10; } @@ -702,6 +709,8 @@ namespace OpenLoco::Ui::Windows::MapWindow // 0x0046D5A4 static void drawGraphKeyRoutes(Window* self, Gfx::RenderTarget* rt, uint16_t x, uint16_t* y) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + for (auto i = 0; _byte_F253DF[i] != 0xFF; i++) { auto index = _byte_F253DF[i]; @@ -709,7 +718,7 @@ namespace OpenLoco::Ui::Windows::MapWindow if (!(self->var_854 & (1 << i)) || !(mapFrameNumber & (1 << 2))) { - Gfx::drawRect(*rt, x, *y + 3, 5, 5, colour); + drawingCtx.drawRect(*rt, x, *y + 3, 5, 5, colour); } auto routeType = StringIds::map_routes_aircraft; @@ -743,7 +752,7 @@ namespace OpenLoco::Ui::Windows::MapWindow stringId = StringIds::small_white_string; } - Gfx::drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); *y += 10; } @@ -752,6 +761,8 @@ namespace OpenLoco::Ui::Windows::MapWindow // 0x0046D6E1 static void drawGraphKeyCompanies(Window* self, Gfx::RenderTarget* rt, uint16_t x, uint16_t* y) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + for (const auto& company : CompanyManager::companies()) { auto index = company.id(); @@ -759,7 +770,7 @@ namespace OpenLoco::Ui::Windows::MapWindow if (!(self->var_854 & (1 << enumValue(index))) || !(mapFrameNumber & (1 << 2))) { - Gfx::drawRect(*rt, x, *y + 3, 5, 5, colour); + drawingCtx.drawRect(*rt, x, *y + 3, 5, 5, colour); } auto args = FormatArguments(); @@ -772,7 +783,7 @@ namespace OpenLoco::Ui::Windows::MapWindow stringId = StringIds::small_white_string; } - Gfx::drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); + drawingCtx.drawStringLeftClipped(*rt, x + 6, *y, 94, Colour::black, stringId, &args); *y += 10; } @@ -908,6 +919,8 @@ namespace OpenLoco::Ui::Windows::MapWindow // 0x0046B779 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); drawTabs(&self, rt); @@ -968,7 +981,7 @@ namespace OpenLoco::Ui::Windows::MapWindow auto y = self.y + self.widgets[widx::statusBar].top - 1; auto width = self.widgets[widx::statusBar].width(); - Gfx::drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::black_stringid, &args); } // 0x0046BF0F based on @@ -979,7 +992,8 @@ namespace OpenLoco::Ui::Windows::MapWindow auto trainPos = locationToMapWindowPos(vehicle->position); - Gfx::fillRect(*rt, trainPos.x, trainPos.y, trainPos.x, trainPos.y, colour); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRect(*rt, trainPos.x, trainPos.y, trainPos.x, trainPos.y, colour); } // 0x0046C294 @@ -987,9 +1001,11 @@ namespace OpenLoco::Ui::Windows::MapWindow { auto newStartPos = locationToMapWindowPos({ stationPos.x, stationPos.y }); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + if (endPos.x != Location::null) { - Gfx::drawLine(*rt, endPos.x, endPos.y, newStartPos.x, newStartPos.y, colour); + drawingCtx.drawLine(*rt, endPos.x, endPos.y, newStartPos.x, newStartPos.y, colour); } endPos = newStartPos; @@ -1051,6 +1067,8 @@ namespace OpenLoco::Ui::Windows::MapWindow if (!colour) return; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Point startPos = { Location::null, 0 }; Point endPos = { Location::null, 0 }; for (auto& order : Vehicles::OrderRingView(train.head->orderTableOffset)) @@ -1070,7 +1088,7 @@ namespace OpenLoco::Ui::Windows::MapWindow if (startPos.x == Location::null || endPos.x == Location::null) return; - Gfx::drawLine(*rt, startPos.x, startPos.y, endPos.x, endPos.y, *colour); + drawingCtx.drawLine(*rt, startPos.x, startPos.y, endPos.x, endPos.y, *colour); } // 0x0046C426 @@ -1163,7 +1181,8 @@ namespace OpenLoco::Ui::Windows::MapWindow std::swap(top, bottom); } - Gfx::fillRect(*rt, left, top, right, bottom, colour); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRect(*rt, left, top, right, bottom, colour); } // 0x0046BE51 @@ -1335,22 +1354,24 @@ namespace OpenLoco::Ui::Windows::MapWindow // 0x0046C481 static void drawTownNames(Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + for (const auto& town : TownManager::towns()) { auto townPos = locationToMapWindowPos({ town.x, town.y }); StringManager::formatString(_stringFormatBuffer, town.name); - Gfx::setCurrentFontSpriteBase(Font::small); + drawingCtx.setCurrentFontSpriteBase(Font::small); - auto strWidth = Gfx::getStringWidth(_stringFormatBuffer); + auto strWidth = drawingCtx.getStringWidth(_stringFormatBuffer); strWidth /= 2; townPos.x -= strWidth; townPos.y -= 3; - Gfx::setCurrentFontSpriteBase(Font::small); - Gfx::drawString(*rt, townPos.x, townPos.y, AdvancedColour(Colour::purple).outline(), _stringFormatBuffer); + drawingCtx.setCurrentFontSpriteBase(Font::small); + drawingCtx.drawString(*rt, townPos.x, townPos.y, AdvancedColour(Colour::purple).outline(), _stringFormatBuffer); } } @@ -1360,7 +1381,8 @@ namespace OpenLoco::Ui::Windows::MapWindow if (!Game::hasFlags(1u << 0)) return; - Gfx::clearSingle(rt, PaletteIndex::index_0A); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clearSingle(rt, PaletteIndex::index_0A); auto element = Gfx::getG1Element(0); auto backupElement = *element; @@ -1376,7 +1398,7 @@ namespace OpenLoco::Ui::Windows::MapWindow Gfx::getG1Element(0)->yOffset = -8; Gfx::getG1Element(0)->flags = 0; - Gfx::drawImage(&rt, 0, 0, 0); + drawingCtx.drawImage(&rt, 0, 0, 0); *element = backupElement; diff --git a/src/OpenLoco/src/Windows/MessageWindow.cpp b/src/OpenLoco/src/Windows/MessageWindow.cpp index 289c21f10d..8ec1290646 100644 --- a/src/OpenLoco/src/Windows/MessageWindow.cpp +++ b/src/OpenLoco/src/Windows/MessageWindow.cpp @@ -2,6 +2,7 @@ #include "CompanyManager.h" #include "Config.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -219,7 +220,8 @@ namespace OpenLoco::Ui::Windows::MessageWindow { auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 4); - Gfx::clearSingle(rt, colour); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clearSingle(rt, colour); auto height = 0; for (auto i = 0; i < _messageCount; i++) @@ -246,7 +248,7 @@ namespace OpenLoco::Ui::Windows::MessageWindow if (self.rowHover == i) { - Gfx::drawRect(rt, 0, height, self.width, 38, (1 << 25) | PaletteIndex::index_30); + drawingCtx.drawRect(rt, 0, height, self.width, 38, (1 << 25) | PaletteIndex::index_30); stringId = StringIds::wcolour2_stringid; } @@ -255,14 +257,14 @@ namespace OpenLoco::Ui::Windows::MessageWindow args.push(StringIds::tiny_font_date); args.push(message->date); - Gfx::drawStringLeft(rt, 0, height, Colour::black, stringId, &args); + drawingCtx.drawStringLeft(rt, 0, height, Colour::black, stringId, &args); } { auto args = FormatArguments(); args.push(StringIds::buffer_2039); auto width = self.widgets[widx::scrollview].width() - 14; - Gfx::drawStringLeftWrapped(rt, 0, height + 6, width, Colour::black, stringId, &args); + drawingCtx.drawStringLeftWrapped(rt, 0, height + 6, width, Colour::black, stringId, &args); height += messageHeight; } } @@ -502,6 +504,8 @@ namespace OpenLoco::Ui::Windows::MessageWindow // 0x0042AA02 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); auto yPos = self.widgets[widx::company_major_news].top + self.y; @@ -527,7 +531,7 @@ namespace OpenLoco::Ui::Windows::MessageWindow auto args = FormatArguments(); args.push(newsStringIds[i]); - Gfx::drawStringLeft(*rt, self.x + 4, yPos, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringLeft(*rt, self.x + 4, yPos, Colour::black, StringIds::wcolour2_stringid, &args); } { @@ -535,7 +539,7 @@ namespace OpenLoco::Ui::Windows::MessageWindow auto args = FormatArguments(); args.push(newsDropdownStringIds[static_cast(Config::get().old.newsSettings[i])]); - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); } yPos += 15; } diff --git a/src/OpenLoco/src/Windows/MusicSelection.cpp b/src/OpenLoco/src/Windows/MusicSelection.cpp index e7972463ca..39bc0429f3 100644 --- a/src/OpenLoco/src/Windows/MusicSelection.cpp +++ b/src/OpenLoco/src/Windows/MusicSelection.cpp @@ -1,5 +1,6 @@ #include "Audio/Audio.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "Interop/Interop.hpp" @@ -100,8 +101,10 @@ namespace OpenLoco::Ui::Windows::MusicSelection // 0x004C1663 static void drawScroll(Ui::Window& window, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(window.getColour(WindowColour::secondary).c(), 4); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); const auto& config = Config::get().old; @@ -113,20 +116,20 @@ namespace OpenLoco::Ui::Windows::MusicSelection // Draw hovered track if (i == window.rowHover) { - Gfx::drawRect(rt, 0, y, 800, kRowHeight, 0x2000030); + drawingCtx.drawRect(rt, 0, y, 800, kRowHeight, 0x2000030); text_colour_id = StringIds::wcolour2_stringid; } // Draw checkbox. - Gfx::fillRectInset(rt, 2, y, 11, y + 10, window.getColour(WindowColour::secondary).u8(), 0xE0); + drawingCtx.fillRectInset(rt, 2, y, 11, y + 10, window.getColour(WindowColour::secondary).u8(), 0xE0); // Draw checkmark if track is enabled. if (config.enabledMusic[i]) - Gfx::drawStringLeft(rt, 2, y, window.getColour(WindowColour::secondary), StringIds::wcolour2_stringid, (void*)&StringIds::checkmark); + drawingCtx.drawStringLeft(rt, 2, y, window.getColour(WindowColour::secondary), StringIds::wcolour2_stringid, (void*)&StringIds::checkmark); // Draw track name. string_id music_title_id = Audio::getMusicInfo(i)->titleId; - Gfx::drawStringLeft(rt, 15, y, window.getColour(WindowColour::secondary), text_colour_id, (void*)&music_title_id); + drawingCtx.drawStringLeft(rt, 15, y, window.getColour(WindowColour::secondary), text_colour_id, (void*)&music_title_id); y += kRowHeight; } diff --git a/src/OpenLoco/src/Windows/NetworkStatus.cpp b/src/OpenLoco/src/Windows/NetworkStatus.cpp index 45ea062ac9..6fad7e4043 100644 --- a/src/OpenLoco/src/Windows/NetworkStatus.cpp +++ b/src/OpenLoco/src/Windows/NetworkStatus.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" @@ -104,12 +105,14 @@ namespace OpenLoco::Ui::Windows::NetworkStatus static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); uint16_t x = self.x + (self.width / 2); uint16_t y = self.y + (self.height / 2); uint16_t width = self.width; - Gfx::drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::buffer_1250, nullptr); + drawingCtx.drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::buffer_1250, nullptr); } static void initEvents() diff --git a/src/OpenLoco/src/Windows/News/News.cpp b/src/OpenLoco/src/Windows/News/News.cpp index 0e3c76d060..555a9abdb1 100644 --- a/src/OpenLoco/src/Windows/News/News.cpp +++ b/src/OpenLoco/src/Windows/News/News.cpp @@ -1,6 +1,7 @@ #include "News.h" #include "CompanyManager.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -547,7 +548,8 @@ namespace OpenLoco::Ui::Windows::NewsWindow case MessageItemArgumentType::company: case MessageItemArgumentType::vehicleTab: { - Gfx::drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::black_tiny_font, &args); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::black_tiny_font, &args); break; } @@ -561,9 +563,11 @@ namespace OpenLoco::Ui::Windows::NewsWindow // 0x00429872 static void drawLateNews(Window* self, Gfx::RenderTarget* rt, Message* news) { - Gfx::drawImage(rt, self->x, self->y, ImageIds::news_background_new_left); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); - Gfx::drawImage(rt, self->x + (kWindowSize.width / 2), self->y, ImageIds::news_background_new_right); + drawingCtx.drawImage(rt, self->x, self->y, ImageIds::news_background_new_left); + + drawingCtx.drawImage(rt, self->x + (kWindowSize.width / 2), self->y, ImageIds::news_background_new_right); self->draw(rt); @@ -586,13 +590,13 @@ namespace OpenLoco::Ui::Windows::NewsWindow int16_t y = self->y + 38; Ui::Point origin = { x, y }; - Gfx::drawStringCentredWrapped(*rt, origin, 352, Colour::black, StringIds::buffer_2039); + drawingCtx.drawStringCentredWrapped(*rt, origin, 352, Colour::black, StringIds::buffer_2039); x = self->x + 1; y = self->y + 1; origin = { x, y }; - Gfx::drawStringLeft(*rt, &origin, Colour::black, StringIds::news_date, &news->date); + drawingCtx.drawStringLeft(*rt, &origin, Colour::black, StringIds::news_date, &news->date); self->drawViewports(rt); @@ -602,6 +606,8 @@ namespace OpenLoco::Ui::Windows::NewsWindow // 0x00429934 static void drawMiddleNews(Window* self, Gfx::RenderTarget* rt, Message* news) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + const auto& mtd = getMessageTypeDescriptor(news->type); if (mtd.hasFlag(MessageTypeFlags::hasFirstItem)) { @@ -614,7 +620,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow auto width = self->widgets[Common::widx::viewport1].width() + 1; auto height = self->widgets[Common::widx::viewport1].height() + 1; auto colour = (1 << 25) | PaletteIndex::index_35; - Gfx::drawRect(*rt, x, y, width, height, colour); + drawingCtx.drawRect(*rt, x, y, width, height, colour); } } } @@ -630,7 +636,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow auto width = self->widgets[Common::widx::viewport2].width() + 1; auto height = self->widgets[Common::widx::viewport2].height() + 1; auto colour = (1 << 25) | PaletteIndex::index_35; - Gfx::drawRect(*rt, x, y, width, height, colour); + drawingCtx.drawRect(*rt, x, y, width, height, colour); } } } @@ -639,13 +645,14 @@ namespace OpenLoco::Ui::Windows::NewsWindow // 0x004299E7 static void drawEarlyNews(Window* self, Gfx::RenderTarget* rt, Message* news) { - auto imageId = Gfx::recolour(ImageIds::news_background_old_left, ExtColour::translucentBrown1); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); - Gfx::drawImage(rt, self->x, self->y, imageId); + auto imageId = Gfx::recolour(ImageIds::news_background_old_left, ExtColour::translucentBrown1); + drawingCtx.drawImage(rt, self->x, self->y, imageId); imageId = Gfx::recolour(ImageIds::news_background_old_right, ExtColour::translucentBrown1); - Gfx::drawImage(rt, self->x + (kWindowSize.width / 2), self->y, imageId); + drawingCtx.drawImage(rt, self->x + (kWindowSize.width / 2), self->y, imageId); self->draw(rt); @@ -668,12 +675,12 @@ namespace OpenLoco::Ui::Windows::NewsWindow int16_t y = self->y + 38; Ui::Point origin = { x, y }; - Gfx::drawStringCentredWrapped(*rt, origin, 352, Colour::black, StringIds::buffer_2039); + drawingCtx.drawStringCentredWrapped(*rt, origin, 352, Colour::black, StringIds::buffer_2039); origin.x = self->x + 4; origin.y = self->y + 5; - Gfx::drawStringLeft(*rt, &origin, Colour::black, StringIds::news_date, &news->date); + drawingCtx.drawStringLeft(*rt, &origin, Colour::black, StringIds::news_date, &news->date); self->drawViewports(rt); @@ -684,19 +691,21 @@ namespace OpenLoco::Ui::Windows::NewsWindow auto width = self->width - 6; auto height = self->height; auto colour = (1 << 25) | PaletteIndex::index_68; - Gfx::drawRect(*rt, x, y, width, height, colour); + drawingCtx.drawRect(*rt, x, y, width, height, colour); x = self->widgets[Common::widx::viewport1].left + self->x; y = self->widgets[Common::widx::viewport1].top + self->y; width = self->widgets[Common::widx::viewport1].width(); height = self->widgets[Common::widx::viewport1].height(); colour = (1 << 25) | PaletteIndex::index_68; - Gfx::drawRect(*rt, x, y, width, height, colour); + drawingCtx.drawRect(*rt, x, y, width, height, colour); } // 0x00429761 static void drawStationNews(Window* self, Gfx::RenderTarget* rt, Message* news) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self->draw(rt); char* newsString = news->messageString; @@ -711,7 +720,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow int16_t y = self->y + 17; Ui::Point origin = { x, y }; - Gfx::drawStringCentredWrapped(*rt, origin, 338, Colour::black, StringIds::buffer_2039); + drawingCtx.drawStringCentredWrapped(*rt, origin, 338, Colour::black, StringIds::buffer_2039); self->drawViewports(rt); const auto& mtd = getMessageTypeDescriptor(news->type); @@ -726,7 +735,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow auto width = self->widgets[Common::widx::viewport1].width(); auto height = self->widgets[Common::widx::viewport1].height(); auto colour = (1 << 25) | PaletteIndex::index_35; - Gfx::drawRect(*rt, x, y, width, height, colour); + drawingCtx.drawRect(*rt, x, y, width, height, colour); } } } @@ -742,7 +751,7 @@ namespace OpenLoco::Ui::Windows::NewsWindow auto width = self->widgets[Common::widx::viewport2].width(); auto height = self->widgets[Common::widx::viewport2].height(); auto colour = (1 << 25) | PaletteIndex::index_35; - Gfx::drawRect(*rt, x, y, width, height, colour); + drawingCtx.drawRect(*rt, x, y, width, height, colour); } } } diff --git a/src/OpenLoco/src/Windows/News/Ticker.cpp b/src/OpenLoco/src/Windows/News/Ticker.cpp index c0e91acfd2..b73a629676 100644 --- a/src/OpenLoco/src/Windows/News/Ticker.cpp +++ b/src/OpenLoco/src/Windows/News/Ticker.cpp @@ -1,4 +1,5 @@ #include "Audio/Audio.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Interop/Interop.hpp" #include "Localisation/StringIds.h" @@ -180,7 +181,8 @@ namespace OpenLoco::Ui::Windows::NewsWindow::Ticker colour = Colours::getShade(Colour::mutedDarkRed, 5); } - Gfx::clearSingle(*clipped, colour); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clearSingle(*clipped, colour); char* newsString = news->messageString; auto buffer = const_cast(StringManager::getString(StringIds::buffer_2039)); diff --git a/src/OpenLoco/src/Windows/ObjectSelectionWindow.cpp b/src/OpenLoco/src/Windows/ObjectSelectionWindow.cpp index 8f196463ae..e21094af69 100644 --- a/src/OpenLoco/src/Windows/ObjectSelectionWindow.cpp +++ b/src/OpenLoco/src/Windows/ObjectSelectionWindow.cpp @@ -1,5 +1,6 @@ #include "Audio/Audio.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -259,6 +260,8 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow // 0x0047328D static void drawTabs(Window* self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto y = self->widgets[widx::panel].top + self->y - 26; auto x = self->x + 3; @@ -275,25 +278,25 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow if (_tabInformation[index].index == self->currentTab) { image = Gfx::recolour(ImageIds::selected_tab, self->getColour(WindowColour::secondary).c()); - Gfx::drawImage(rt, xPos, yPos, image); + drawingCtx.drawImage(rt, xPos, yPos, image); image = Gfx::recolour(_tabDisplayInfo[_tabInformation[index].index].image, Colour::mutedSeaGreen); - Gfx::drawImage(rt, xPos, yPos, image); + drawingCtx.drawImage(rt, xPos, yPos, image); } else { - Gfx::drawImage(rt, xPos, yPos, image); + drawingCtx.drawImage(rt, xPos, yPos, image); image = Gfx::recolour(_tabDisplayInfo[_tabInformation[index].index].image, Colour::mutedSeaGreen); - Gfx::drawImage(rt, xPos, yPos, image); + drawingCtx.drawImage(rt, xPos, yPos, image); image = Gfx::recolourTranslucent(ImageIds::tab, ExtColour::unk33); - Gfx::drawImage(rt, xPos, yPos, image); + drawingCtx.drawImage(rt, xPos, yPos, image); if (row < 1) { auto colour = Colours::getShade(self->getColour(WindowColour::secondary).c(), 7); - Gfx::drawRect(*rt, xPos, yPos + 26, 31, 1, colour); + drawingCtx.drawRect(*rt, xPos, yPos + 26, 31, 1, colour); } } xPos += 31; @@ -508,19 +511,23 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow if (!clipped) return; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + { auto buffer = const_cast(StringManager::getString(StringIds::buffer_1250)); strncpy(buffer, indexEntry._filename, strlen(indexEntry._filename) + 1); FormatArguments args{}; args.push(StringIds::buffer_1250); - Gfx::drawStringLeft(*clipped, 18, height - kDescriptionRowHeight * 3 - 4, Colour::black, StringIds::object_selection_filename, &args); + drawingCtx.drawStringLeft(*clipped, 18, height - kDescriptionRowHeight * 3 - 4, Colour::black, StringIds::object_selection_filename, &args); } } // 0x004733F5 static void draw(Window& self, Gfx::RenderTarget* rt) { - Gfx::fillRectInset(*rt, self.x, self.y + 20, self.x + self.width - 1, self.y + 20 + 60, self.getColour(WindowColour::primary).u8(), 0); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.fillRectInset(*rt, self.x, self.y + 20, self.x + self.width - 1, self.y + 20 + 60, self.getColour(WindowColour::primary).u8(), 0); self.draw(rt); drawTabs(&self, rt); @@ -540,13 +547,13 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow { auto widget = widgets[widx::objectImage]; auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 5); - Gfx::drawRect(*rt, self.x + widget.left, self.y + widget.top, widget.width(), widget.height(), colour); + drawingCtx.drawRect(*rt, self.x + widget.left, self.y + widget.top, widget.width(), widget.height(), colour); } else { auto widget = widgets[widx::objectImage]; auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 0); - Gfx::drawRect(*rt, self.x + widget.left + 1, self.y + widget.top + 1, widget.width() - 2, widget.height() - 2, colour); + drawingCtx.drawRect(*rt, self.x + widget.left + 1, self.y + widget.top + 1, widget.width() - 2, widget.height() - 2, colour); } auto type = self.currentTab; @@ -555,7 +562,7 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow args.push(_112C1C5[type]); args.push(ObjectManager::getMaxObjects(static_cast(type))); - Gfx::drawStringLeft(*rt, self.x + 3, self.y + self.height - 12, Colour::black, 2038, &args); + drawingCtx.drawStringLeft(*rt, self.x + 3, self.y + self.height - 12, Colour::black, 2038, &args); if (self.rowHover == -1) return; @@ -588,7 +595,7 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow strncpy(buffer, ObjectManager::ObjectIndexEntry::read(&objectPtr)._name, 510); - Gfx::drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::buffer_2039); + drawingCtx.drawStringCentredClipped(*rt, x, y, width, Colour::black, StringIds::buffer_2039); } { @@ -618,7 +625,9 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow // 0x0047361D static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t) { - Gfx::clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); if (ObjectManager::getNumInstalledObjects() == 0) return; @@ -628,7 +637,7 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow for (auto [i, object] : objects) { uint8_t flags = (1 << 7) | (1 << 6) | (1 << 5); - Gfx::fillRectInset(rt, 2, y, 11, y + 10, self.getColour(WindowColour::secondary).u8(), flags); + drawingCtx.fillRectInset(rt, 2, y, 11, y + 10, self.getColour(WindowColour::secondary).u8(), flags); uint8_t textColour = ControlCodes::Colour::black; @@ -638,7 +647,7 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow auto windowObjectName = ObjectManager::ObjectIndexEntry::read(&objectPtr)._name; if (object._name == windowObjectName) { - Gfx::fillRect(rt, 0, y, self.width, y + kRowHeight - 1, (1 << 25) | PaletteIndex::index_30); + drawingCtx.fillRect(rt, 0, y, self.width, y + kRowHeight - 1, (1 << 25) | PaletteIndex::index_30); textColour = ControlCodes::windowColour2; } } @@ -646,11 +655,11 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow if (_50D144[i] & (1 << 0)) { auto x = 2; - Gfx::setCurrentFontSpriteBase(Font::m2); + drawingCtx.setCurrentFontSpriteBase(Font::m2); if (textColour != ControlCodes::windowColour2) { - Gfx::setCurrentFontSpriteBase(Font::m1); + drawingCtx.setCurrentFontSpriteBase(Font::m1); } auto checkColour = self.getColour(WindowColour::secondary).opaque(); @@ -660,15 +669,15 @@ namespace OpenLoco::Ui::Windows::ObjectSelectionWindow checkColour = checkColour.inset(); } - Gfx::drawString(rt, x, y, checkColour, _strCheckmark); + drawingCtx.drawString(rt, x, y, checkColour, _strCheckmark); } char buffer[512]{}; buffer[0] = textColour; strncpy(&buffer[1], object._name, 510); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); - Gfx::drawString(rt, 15, y, Colour::black, buffer); + drawingCtx.drawString(rt, 15, y, Colour::black, buffer); y += kRowHeight; } } diff --git a/src/OpenLoco/src/Windows/Options.cpp b/src/OpenLoco/src/Windows/Options.cpp index 0463144662..f44c73f916 100644 --- a/src/OpenLoco/src/Windows/Options.cpp +++ b/src/OpenLoco/src/Windows/Options.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "Config.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Environment.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -642,6 +643,8 @@ namespace OpenLoco::Ui::Windows::Options // 0x004BFAF9 static void draw(Window& w, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. w.draw(rt); @@ -649,26 +652,26 @@ namespace OpenLoco::Ui::Windows::Options int16_t x = w.x + 10; int16_t y = w.y + Display::_widgets[Display::Widx::screen_mode].top + 1; - drawStringLeft(*rt, x, y, Colour::black, StringIds::options_screen_mode, nullptr); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::options_screen_mode, nullptr); y = w.y + Display::_widgets[Display::Widx::display_resolution].top + 1; - drawStringLeft(*rt, x, y, Colour::black, StringIds::display_resolution, nullptr); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::display_resolution, nullptr); y = w.y + Display::_widgets[Display::Widx::construction_marker].top + 1; - drawStringLeft(*rt, x, y, Colour::black, StringIds::construction_marker, nullptr); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::construction_marker, nullptr); y = w.y + Display::_widgets[Display::Widx::vehicles_min_scale].top + 1; - drawStringLeft(*rt, x, y, Colour::black, StringIds::vehicles_min_scale, nullptr); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::vehicles_min_scale, nullptr); y = w.y + Display::_widgets[Display::Widx::station_names_min_scale].top + 1; - drawStringLeft(*rt, x, y, Colour::black, StringIds::station_names_min_scale, nullptr); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::station_names_min_scale, nullptr); y = w.y + Display::_widgets[Display::Widx::display_scale].top + 1; - drawStringLeft(*rt, x, y, Colour::black, StringIds::window_scale_factor, nullptr); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::window_scale_factor, nullptr); int scale = (int)(Config::get().scaleFactor * 100); auto& scaleWidget = w.widgets[Widx::display_scale]; - drawStringLeft(*rt, w.x + scaleWidget.left + 1, w.y + scaleWidget.top + 1, Colour::black, StringIds::scale_formatted, &scale); + drawingCtx.drawStringLeft(*rt, w.x + scaleWidget.left + 1, w.y + scaleWidget.top + 1, Colour::black, StringIds::scale_formatted, &scale); } static void applyScreenModeRestrictions(Window* w) @@ -986,19 +989,21 @@ namespace OpenLoco::Ui::Windows::Options // 0x004C05F9 static void draw(Window& w, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. w.draw(rt); Common::drawTabs(&w, rt); - Gfx::drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::currently_playing_btn].top, Colour::black, StringIds::currently_playing, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::currently_playing_btn].top, Colour::black, StringIds::currently_playing, nullptr); - Gfx::drawStringLeft(*rt, w.x + 183, w.y + w.widgets[Widx::volume].top + 7, Colour::black, StringIds::volume, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 183, w.y + w.widgets[Widx::volume].top + 7, Colour::black, StringIds::volume, nullptr); - Gfx::drawImage(rt, w.x + w.widgets[Widx::volume].left, w.y + w.widgets[Widx::volume].top, Gfx::recolour(ImageIds::volume_slider_track, w.getColour(WindowColour::secondary).c())); + drawingCtx.drawImage(rt, w.x + w.widgets[Widx::volume].left, w.y + w.widgets[Widx::volume].top, Gfx::recolour(ImageIds::volume_slider_track, w.getColour(WindowColour::secondary).c())); int16_t x = 90 + (Config::get().old.volume / 32); - Gfx::drawImage(rt, w.x + w.widgets[Widx::volume].left + x, w.y + w.widgets[Widx::volume].top, Gfx::recolour(ImageIds::volume_slider_thumb, w.getColour(WindowColour::secondary).c())); + drawingCtx.drawImage(rt, w.x + w.widgets[Widx::volume].left + x, w.y + w.widgets[Widx::volume].top, Gfx::recolour(ImageIds::volume_slider_thumb, w.getColour(WindowColour::secondary).c())); } static void onMouseUp(Window& w, WidgetIndex_t wi) @@ -1383,15 +1388,17 @@ namespace OpenLoco::Ui::Windows::Options // 0x004C0B5B static void draw(Window& w, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. w.draw(rt); Common::drawTabs(&w, rt); - Gfx::drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::language].top + 1, Colour::black, StringIds::options_language, nullptr); - Gfx::drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::distance_speed].top + 1, Colour::black, StringIds::distance_and_speed, nullptr); - Gfx::drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::heights].top + 1, Colour::black, StringIds::heights, nullptr); - Gfx::drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::currency].top + 1, Colour::black, StringIds::current_game_currency, nullptr); - Gfx::drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::preferred_currency].top + 1, Colour::black, StringIds::new_game_currency, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::language].top + 1, Colour::black, StringIds::options_language, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::distance_speed].top + 1, Colour::black, StringIds::distance_and_speed, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::heights].top + 1, Colour::black, StringIds::heights, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::currency].top + 1, Colour::black, StringIds::current_game_currency, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, w.y + w.widgets[Widx::preferred_currency].top + 1, Colour::black, StringIds::new_game_currency, nullptr); } static void onMouseUp(Window& w, WidgetIndex_t wi) @@ -2042,16 +2049,20 @@ namespace OpenLoco::Ui::Windows::Options static void drawDropdownContent(Window* w, Gfx::RenderTarget* rt, WidgetIndex_t widgetIndex, string_id stringId, int32_t value) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto& widget = w->widgets[widgetIndex]; FormatArguments args = {}; args.push(stringId); args.push(value); - drawStringLeft(*rt, w->x + widget.left + 1, w->y + widget.top + 1, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(*rt, w->x + widget.left + 1, w->y + widget.top + 1, Colour::black, StringIds::black_stringid, &args); } // 0x004C1282 static void draw(Window& w, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + w.draw(rt); Common::drawTabs(&w, rt); @@ -2062,10 +2073,10 @@ namespace OpenLoco::Ui::Windows::Options FormatArguments args = {}; args.push(StringIds::buffer_2039); - Gfx::drawStringLeft(*rt, w.x + 24, w.y + w.widgets[Widx::change_btn].top + 1, Colour::black, StringIds::wcolour2_preferred_owner_name, &args); + drawingCtx.drawStringLeft(*rt, w.x + 24, w.y + w.widgets[Widx::change_btn].top + 1, Colour::black, StringIds::wcolour2_preferred_owner_name, &args); auto y = w.y + w.widgets[Widx::autosave_frequency].top; - drawStringLeft(*rt, w.x + 10, y, Colour::black, StringIds::autosave_frequency, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, y, Colour::black, StringIds::autosave_frequency, nullptr); auto freq = Config::get().autosaveFrequency; string_id stringId; @@ -2084,7 +2095,7 @@ namespace OpenLoco::Ui::Windows::Options drawDropdownContent(&w, rt, Widx::autosave_frequency, stringId, freq); y = w.y + w.widgets[Widx::autosave_amount].top; - drawStringLeft(*rt, w.x + 10, y, Colour::black, StringIds::autosave_amount, nullptr); + drawingCtx.drawStringLeft(*rt, w.x + 10, y, Colour::black, StringIds::autosave_amount, nullptr); auto scale = Config::get().autosaveAmount; drawDropdownContent(&w, rt, Widx::autosave_amount, StringIds::int_32, scale); diff --git a/src/OpenLoco/src/Windows/PlayerInfoPanel.cpp b/src/OpenLoco/src/Windows/PlayerInfoPanel.cpp index 5dd583fad0..5ca29957f3 100644 --- a/src/OpenLoco/src/Windows/PlayerInfoPanel.cpp +++ b/src/OpenLoco/src/Windows/PlayerInfoPanel.cpp @@ -1,6 +1,7 @@ #include "Company.h" #include "CompanyManager.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -206,18 +207,20 @@ namespace OpenLoco::Ui::Windows::PlayerInfoPanel // 0x43944B static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Widget& frame = _widgets[Widx::outer_frame]; - Gfx::drawRect(*rt, window.x + frame.left, window.y + frame.top, frame.width(), frame.height(), 0x2000000 | 52); + drawingCtx.drawRect(*rt, window.x + frame.left, window.y + frame.top, frame.width(), frame.height(), 0x2000000 | 52); // Draw widgets. window.draw(rt); - drawRectInset(*rt, window.x + frame.left + 1, window.y + frame.top + 1, frame.width() - 2, frame.height() - 2, window.getColour(WindowColour::secondary).u8(), 0x30); + drawingCtx.drawRectInset(*rt, window.x + frame.left + 1, window.y + frame.top + 1, frame.width() - 2, frame.height() - 2, window.getColour(WindowColour::secondary).u8(), 0x30); auto playerCompany = CompanyManager::get(CompanyManager::getControllingId()); auto competitor = ObjectManager::get(playerCompany->competitorId); auto image = Gfx::recolour(competitor->images[playerCompany->ownerEmotion], playerCompany->mainColours.primary); - Gfx::drawImage(rt, window.x + frame.left + 2, window.y + frame.top + 2, image); + drawingCtx.drawImage(rt, window.x + frame.left + 2, window.y + frame.top + 2, image); auto x = window.x + frame.width() / 2 + 12; { @@ -242,7 +245,7 @@ namespace OpenLoco::Ui::Windows::PlayerInfoPanel auto args = FormatArguments(); args.push(playerCompany->cash.var_00); args.push(playerCompany->cash.var_04); - Gfx::drawStringCentred(*rt, x, window.y + frame.top + 2, colour, companyValueString, &args); + drawingCtx.drawStringCentred(*rt, x, window.y + frame.top + 2, colour, companyValueString, &args); } { @@ -265,7 +268,7 @@ namespace OpenLoco::Ui::Windows::PlayerInfoPanel auto args = FormatArguments(); args.push(playerCompany->performanceIndex); - Gfx::drawStringCentred(*rt, x, window.y + frame.top + 14, colour, performanceString, &args); + drawingCtx.drawStringCentred(*rt, x, window.y + frame.top + 14, colour, performanceString, &args); } } diff --git a/src/OpenLoco/src/Windows/ProgressBar.cpp b/src/OpenLoco/src/Windows/ProgressBar.cpp index fdd0c245e1..a6f3d575a2 100644 --- a/src/OpenLoco/src/Windows/ProgressBar.cpp +++ b/src/OpenLoco/src/Windows/ProgressBar.cpp @@ -1,4 +1,5 @@ #include "Ui/ProgressBar.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" @@ -96,6 +97,8 @@ namespace OpenLoco::Ui::Windows::ProgressBar // 004CF7A0 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); auto clipped = Gfx::clipRenderTarget(*rt, Ui::Rect(self.x + 2, self.y + 17, self.width - 5, self.height - 19)); @@ -103,7 +106,7 @@ namespace OpenLoco::Ui::Windows::ProgressBar return; // First, draw the train track. - Gfx::drawImage(&*clipped, 0, 0, ImageIds::progressbar_track); + drawingCtx.drawImage(&*clipped, 0, 0, ImageIds::progressbar_track); // What train image to use depends on the progress bar style. uint32_t trainImage; @@ -134,7 +137,7 @@ namespace OpenLoco::Ui::Windows::ProgressBar // Draw the train image from the right of the window, int16_t xPos = _progressBarValue - 255; - Gfx::drawImage(&*clipped, xPos, 0, trainImage); + drawingCtx.drawImage(&*clipped, xPos, 0, trainImage); } static void initEvents() diff --git a/src/OpenLoco/src/Windows/PromptBrowseWindow.cpp b/src/OpenLoco/src/Windows/PromptBrowseWindow.cpp index fc335b7d9d..89bb432e58 100644 --- a/src/OpenLoco/src/Windows/PromptBrowseWindow.cpp +++ b/src/OpenLoco/src/Windows/PromptBrowseWindow.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "Config.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Environment.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -332,14 +333,15 @@ namespace OpenLoco::Ui::Windows::PromptBrowse auto args = FormatArguments::common(StringIds::empty); char folderBuffer[256]{}; StringManager::formatString(folderBuffer, StringIds::window_browse_folder, &args); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - const auto folderLabelWidth = Gfx::getStringWidth(folderBuffer); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + const auto folderLabelWidth = drawingCtx.getStringWidth(folderBuffer); // We'll ensure the folder width does not reach the parent button. const uint16_t maxWidth = self.widgets[widx::parent_button].left - folderLabelWidth - 10; const std::string nameBuffer = _currentDirectory.u8string(); strncpy(&_displayFolderBuffer[0], nameBuffer.c_str(), 512); - uint16_t folderWidth = Gfx::getStringWidth(_displayFolderBuffer); + uint16_t folderWidth = drawingCtx.getStringWidth(_displayFolderBuffer); // If the folder already fits, we're done. if (folderWidth <= maxWidth) @@ -361,7 +363,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse // Prepare for the next pass, if needed. relativeDirectory++; - } while (Gfx::getStringWidth(_displayFolderBuffer) > maxWidth); + } while (drawingCtx.getStringWidth(_displayFolderBuffer) > maxWidth); } static FormatArguments getStringPtrFormatArgs(const char* buffer) @@ -375,12 +377,14 @@ namespace OpenLoco::Ui::Windows::PromptBrowse // 0x00445E38 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + window.draw(rt); { auto folder = &_displayFolderBuffer[0]; auto args = getStringPtrFormatArgs(folder); - Gfx::drawStringLeft(*rt, window.x + 3, window.y + window.widgets[widx::parent_button].top + 6, Colour::black, StringIds::window_browse_folder, &args); + drawingCtx.drawStringLeft(*rt, window.x + 3, window.y + window.widgets[widx::parent_button].top + 6, Colour::black, StringIds::window_browse_folder, &args); } auto selectedIndex = window.var_85A; @@ -397,7 +401,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse const std::string nameBuffer = selectedFile.stem().u8string(); auto args = getStringPtrFormatArgs(nameBuffer.c_str()); - Gfx::drawStringCentredClipped( + drawingCtx.drawStringCentredClipped( *rt, x + (width / 2), y, @@ -429,7 +433,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse if (filenameBox.type != WidgetType::none) { // Draw filename label - Gfx::drawStringLeft(*rt, window.x + 3, window.y + filenameBox.top + 2, Colour::black, StringIds::window_browse_filename, nullptr); + drawingCtx.drawStringLeft(*rt, window.x + 3, window.y + filenameBox.top + 2, Colour::black, StringIds::window_browse_filename, nullptr); // Clip to text box auto context2 = Gfx::clipRenderTarget(*rt, Ui::Rect(window.x + filenameBox.left + 1, window.y + filenameBox.top + 1, filenameBox.right - filenameBox.left - 1, filenameBox.bottom - filenameBox.top - 1)); @@ -442,7 +446,8 @@ namespace OpenLoco::Ui::Windows::PromptBrowse static void drawSavePreview(Ui::Window& window, Gfx::RenderTarget& rt, int32_t x, int32_t y, int32_t width, int32_t height, const S5::SaveDetails& saveInfo) { - Gfx::fillRectInset(rt, x, y, x + width, y + height, window.getColour(WindowColour::secondary).u8(), 0x30); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(rt, x, y, x + width, y + height, window.getColour(WindowColour::secondary).u8(), 0x30); auto imageId = 0; auto g1 = Gfx::getG1Element(imageId); @@ -454,7 +459,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse g1->offset = (uint8_t*)saveInfo.image; g1->width = 250; g1->height = 200; - Gfx::drawImage(&rt, x + 1, y + 1, imageId); + drawingCtx.drawImage(&rt, x + 1, y + 1, imageId); *g1 = backupg1; } y += 207; @@ -464,17 +469,17 @@ namespace OpenLoco::Ui::Windows::PromptBrowse // Company { auto args = getStringPtrFormatArgs(saveInfo.company); - y = Gfx::drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, StringIds::window_browse_company, &args); + y = drawingCtx.drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, StringIds::window_browse_company, &args); } // Owner { auto args = getStringPtrFormatArgs(saveInfo.owner); - y = Gfx::drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, StringIds::owner_label, &args); + y = drawingCtx.drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, StringIds::owner_label, &args); } // Date - y = Gfx::drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, StringIds::window_browse_date, &saveInfo.date); + y = drawingCtx.drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, StringIds::window_browse_date, &saveInfo.date); // Challenge progress auto flags = saveInfo.challengeFlags; @@ -491,13 +496,14 @@ namespace OpenLoco::Ui::Windows::PromptBrowse progress = saveInfo.challengeProgress; } } - Gfx::drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, stringId, &progress); + drawingCtx.drawStringLeftWrapped(rt, x, y, maxWidth, Colour::black, stringId, &progress); } } static void drawLandscapePreview(Ui::Window& window, Gfx::RenderTarget& rt, int32_t x, int32_t y, int32_t width, int32_t height) { - Gfx::fillRectInset(rt, x, y, x + width, y + height, window.getColour(WindowColour::secondary).u8(), 0x30); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(rt, x, y, x + width, y + height, window.getColour(WindowColour::secondary).u8(), 0x30); if (_previewScenarioOptions->scenarioFlags & Scenario::Flags::landscapeGenerationDone) { @@ -512,29 +518,31 @@ namespace OpenLoco::Ui::Windows::PromptBrowse g1->offset = &_previewScenarioOptions->preview[0][0]; g1->width = 128; g1->height = 128; - Gfx::drawImage(&rt, x + 1, y + 1, imageId); + drawingCtx.drawImage(&rt, x + 1, y + 1, imageId); *g1 = backupg1; - Gfx::drawImage(&rt, x, y + 1, ImageIds::height_map_compass); + drawingCtx.drawImage(&rt, x, y + 1, ImageIds::height_map_compass); } } else { // Randomly generated landscape auto imageId = Gfx::recolour(ImageIds::random_map_watermark, window.getColour(WindowColour::secondary).c()); - Gfx::drawImage(&rt, x, y, imageId); + drawingCtx.drawImage(&rt, x, y, imageId); auto origin = Ui::Point(x + 64, y + 60); - Gfx::drawStringCentredWrapped(rt, origin, 128, Colour::black, StringIds::randomly_generated_landscape); + drawingCtx.drawStringCentredWrapped(rt, origin, 128, Colour::black, StringIds::randomly_generated_landscape); } } static void drawTextInput(Ui::Window* window, Gfx::RenderTarget& rt, const char* text, int32_t caret, bool showCaret) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw text box text Ui::Point origin = { 0, 1 }; { auto args = getStringPtrFormatArgs(text); - Gfx::drawStringLeft(rt, &origin, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(rt, &origin, Colour::black, StringIds::black_stringid, &args); } if (showCaret) @@ -542,7 +550,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse if (caret == -1) { // Draw horizontal caret - Gfx::drawStringLeft(rt, &origin, Colour::black, StringIds::window_browse_input_caret, nullptr); + drawingCtx.drawStringLeft(rt, &origin, Colour::black, StringIds::window_browse_input_caret, nullptr); } else { @@ -551,10 +559,10 @@ namespace OpenLoco::Ui::Windows::PromptBrowse const std::string gbuffer = std::string(text, caret); auto args = getStringPtrFormatArgs(gbuffer.c_str()); origin = { 0, 1 }; - Gfx::drawStringLeft(rt, &origin, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(rt, &origin, Colour::black, StringIds::black_stringid, &args); // Draw vertical caret - Gfx::drawRect(rt, origin.x, origin.y, 1, 9, Colours::getShade(window->getColour(WindowColour::secondary).c(), 9)); + drawingCtx.drawRect(rt, origin.x, origin.y, 1, 9, Colours::getShade(window->getColour(WindowColour::secondary).c(), 9)); } } } @@ -567,8 +575,10 @@ namespace OpenLoco::Ui::Windows::PromptBrowse // 0x00446314 static void drawScroll(Ui::Window& window, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Background - Gfx::clearSingle(rt, Colours::getShade(window.getColour(WindowColour::secondary).c(), 4)); + drawingCtx.clearSingle(rt, Colours::getShade(window.getColour(WindowColour::secondary).c(), 4)); // Directories / files auto i = 0; @@ -582,7 +592,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse auto stringId = StringIds::black_stringid; if (i == window.var_85A) { - Gfx::drawRect(rt, 0, y, window.width, lineHeight, 0x2000000 | 48); + drawingCtx.drawRect(rt, 0, y, window.width, lineHeight, 0x2000000 | 48); stringId = StringIds::wcolour2_stringid; } @@ -590,7 +600,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse auto x = 1; if (isRootPath(entry) || fs::is_directory(entry)) { - Gfx::drawImage(&rt, x, y, ImageIds::icon_folder); + drawingCtx.drawImage(&rt, x, y, ImageIds::icon_folder); x += 14; } @@ -599,7 +609,7 @@ namespace OpenLoco::Ui::Windows::PromptBrowse // Draw the name auto args = getStringPtrFormatArgs(nameBuffer.c_str()); - Gfx::drawStringLeft(rt, x, y, Colour::black, stringId, &args); + drawingCtx.drawStringLeft(rt, x, y, Colour::black, stringId, &args); } y += lineHeight; i++; diff --git a/src/OpenLoco/src/Windows/PromptOkCancelWindow.cpp b/src/OpenLoco/src/Windows/PromptOkCancelWindow.cpp index f8a6f5af24..f3ee1a7114 100644 --- a/src/OpenLoco/src/Windows/PromptOkCancelWindow.cpp +++ b/src/OpenLoco/src/Windows/PromptOkCancelWindow.cpp @@ -1,4 +1,5 @@ #include "Audio/Audio.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Input.h" #include "Interop/Interop.hpp" @@ -128,13 +129,15 @@ namespace OpenLoco::Ui::Windows::PromptOkCancel // 0x004470AA static void draw(Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); FormatArguments args{}; args.push(StringIds::buffer_2039); auto origin = Ui::Point(self.x + self.width / 2, self.y + 41); - Gfx::drawStringCentredWrapped(*rt, origin, self.width, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringCentredWrapped(*rt, origin, self.width, Colour::black, StringIds::wcolour2_stringid, &args); } static void initEvents() diff --git a/src/OpenLoco/src/Windows/ScenarioOptions.cpp b/src/OpenLoco/src/Windows/ScenarioOptions.cpp index 287c647372..d5b9a221e9 100644 --- a/src/OpenLoco/src/Windows/ScenarioOptions.cpp +++ b/src/OpenLoco/src/Windows/ScenarioOptions.cpp @@ -1,4 +1,5 @@ #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Economy/Economy.h" #include "GameState.h" #include "Graphics/Colour.h" @@ -193,16 +194,18 @@ namespace OpenLoco::Ui::Windows::ScenarioOptions // 0x0043FC91 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); const int16_t xPos = window.x + 5; int16_t yPos = window.y + widgets[widx::check_time_limit].bottom + 10; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::challenge_label); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::challenge_label); FormatArguments args = {}; OpenLoco::Scenario::formatChallengeArguments(Scenario::getObjective(), Scenario::getObjectiveProgress(), args); yPos += 10; - Gfx::drawStringLeftWrapped(*rt, xPos, yPos, window.width - 10, Colour::black, StringIds::challenge_value, &args); + drawingCtx.drawStringLeftWrapped(*rt, xPos, yPos, window.width - 10, Colour::black, StringIds::challenge_value, &args); } static const string_id objectiveTypeLabelIds[] = { @@ -600,54 +603,56 @@ namespace OpenLoco::Ui::Windows::ScenarioOptions // 0x0043F4EB static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::max_competing_companies].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::max_competing_companies); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::max_competing_companies); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::delay_before_competing_companies_start].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::delay_before_competing_companies_start); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::delay_before_competing_companies_start); } { const int16_t xPos = window.x + 15; int16_t yPos = window.y + widgets[widx::preferred_intelligence].top - 14; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::selection_of_competing_companies); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::selection_of_competing_companies); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::preferred_intelligence].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::preferred_intelligence); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::preferred_intelligence); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::preferred_aggressiveness].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::preferred_aggressiveness); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::preferred_aggressiveness); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::preferred_competitiveness].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::preferred_competitiveness); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::preferred_competitiveness); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::competitor_forbid_trains].top - 12; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::forbid_competing_companies_from_using); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::forbid_competing_companies_from_using); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::player_forbid_trains].top - 12; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::forbid_player_companies_from_using); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::forbid_player_companies_from_using); } } @@ -880,24 +885,26 @@ namespace OpenLoco::Ui::Windows::ScenarioOptions // 0x0043F97D static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::starting_loan].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::starting_loan); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::starting_loan); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::max_loan_size].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::max_loan_size); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::max_loan_size); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::loan_interest_rate].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::loan_interest_rate); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::loan_interest_rate); } } @@ -1016,6 +1023,8 @@ namespace OpenLoco::Ui::Windows::ScenarioOptions // 0x0043F004 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); { @@ -1036,19 +1045,19 @@ namespace OpenLoco::Ui::Windows::ScenarioOptions const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::change_name_btn].top + 1; int16_t width = widgets[widx::change_name_btn].left - 20; - Gfx::drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::scenario_name_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::scenario_name_stringid, &args); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::scenario_group].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::scenario_group); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::scenario_group); } { const int16_t xPos = window.x + 10; int16_t yPos = window.y + widgets[widx::change_details_btn].top + 1; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::scenario_details); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::scenario_details); } { @@ -1067,7 +1076,7 @@ namespace OpenLoco::Ui::Windows::ScenarioOptions } auto& target = window.widgets[widx::change_details_btn]; - Gfx::drawStringLeftWrapped(*rt, window.x + 16, window.y + 12 + target.top, target.left - 26, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeftWrapped(*rt, window.x + 16, window.y + 12 + target.top, target.left - 26, Colour::black, StringIds::black_stringid, &args); } } diff --git a/src/OpenLoco/src/Windows/ScenarioSelect.cpp b/src/OpenLoco/src/Windows/ScenarioSelect.cpp index 0a9e46c9a6..c0df4ab7b4 100644 --- a/src/OpenLoco/src/Windows/ScenarioSelect.cpp +++ b/src/OpenLoco/src/Windows/ScenarioSelect.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "Config.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -156,7 +157,8 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect // 0x004439AF static void draw(Window& self, Gfx::RenderTarget* rt) { - Gfx::drawRectInset(*rt, self.x, self.y + 20, self.width, 41, self.getColour(WindowColour::primary).u8(), 0); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawRectInset(*rt, self.x, self.y + 20, self.width, 41, self.getColour(WindowColour::primary).u8(), 0); // Draw widgets. self.draw(rt); @@ -180,7 +182,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect auto origin = Ui::Point(widget.midX() + self.x, widget.midY() + self.y - 3 - offset); const string_id caption = scenarioGroupIds[i]; - Gfx::drawStringCentredWrapped(*rt, origin, widget.width() - 4, Colour::black, StringIds::wcolour2_stringid, &caption); + drawingCtx.drawStringCentredWrapped(*rt, origin, widget.width() - 4, Colour::black, StringIds::wcolour2_stringid, &caption); } // Scenario selected? @@ -230,7 +232,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect args.push(StringIds::buffer_2039); x += colWidth / 2; - Gfx::drawStringCentredClipped(*rt, x, y, 170, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringCentredClipped(*rt, x, y, 170, Colour::black, StringIds::wcolour2_stringid, &args); y += 14; } @@ -238,7 +240,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect // Outline for preview image { x = baseX + 20; - Gfx::drawRectInset(*rt, x, y, 130, 130, self.getColour(WindowColour::secondary).u8(), 0x30); + drawingCtx.drawRectInset(*rt, x, y, 130, 130, self.getColour(WindowColour::secondary).u8(), 0x30); x += 1; y += 1; @@ -259,11 +261,11 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect g1->height = 128; // Draw preview image and restore original G1 image. - Gfx::drawImage(rt, x, y, imageId); + drawingCtx.drawImage(rt, x, y, imageId); *g1 = backupG1; // Draw compass - Gfx::drawImage(rt, x, y, ImageIds::height_map_compass); + drawingCtx.drawImage(rt, x, y, ImageIds::height_map_compass); } } else @@ -273,7 +275,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect // No preview image -- a placeholder will have to do. auto image = Gfx::recolour(ImageIds::random_map_watermark, self.getColour(WindowColour::secondary).c()); - Gfx::drawImage(rt, x, y, image); + drawingCtx.drawImage(rt, x, y, image); x += 64; y += 59; @@ -283,7 +285,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect // Overlay random map note. auto origin = Ui::Point(x, y); - Gfx::drawStringCentredWrapped(*rt, origin, 128, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringCentredWrapped(*rt, origin, 128, Colour::black, StringIds::wcolour2_stringid, &args); } { @@ -296,12 +298,12 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect auto args = FormatArguments(); args.push(StringIds::buffer_2039); - y = Gfx::drawStringLeftWrapped(*rt, x, y, 170, Colour::black, StringIds::black_stringid, &args); + y = drawingCtx.drawStringLeftWrapped(*rt, x, y, 170, Colour::black, StringIds::black_stringid, &args); // Challenge header y += 5; auto origin = Ui::Point(x, y); - Gfx::drawStringLeft(*rt, &origin, Colour::black, StringIds::challenge_label, nullptr); + drawingCtx.drawStringLeft(*rt, &origin, Colour::black, StringIds::challenge_label, nullptr); // Challenge text str = const_cast(StringManager::getString(StringIds::buffer_1250)); @@ -310,20 +312,20 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect y += 10; args = FormatArguments(); args.push(StringIds::buffer_1250); - y = Gfx::drawStringLeftWrapped(*rt, x, y, 170, Colour::black, StringIds::challenge_value, &args); + y = drawingCtx.drawStringLeftWrapped(*rt, x, y, 170, Colour::black, StringIds::challenge_value, &args); // Start year y += 5; args = FormatArguments(); args.push(scenarioInfo->startYear); - Gfx::drawStringLeft(*rt, x, y, Colour::black, StringIds::challenge_start_date, &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, StringIds::challenge_start_date, &args); // Competing companies y += 10; args = FormatArguments(); args.push(scenarioInfo->numCompetingCompanies); string_id competitionStringId = scenarioInfo->numCompetingCompanies == 0 ? StringIds::challenge_competing_companies_none : StringIds::challenge_competing_companies_up_to; - y = Gfx::drawStringLeftWrapped(*rt, x, y, 170, Colour::black, competitionStringId, &args); + y = drawingCtx.drawStringLeftWrapped(*rt, x, y, 170, Colour::black, competitionStringId, &args); if (scenarioInfo->numCompetingCompanies == 0 || scenarioInfo->competingCompanyDelay == 0) return; @@ -332,15 +334,17 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect args = FormatArguments(); args.push(scenarioInfo->competingCompanyDelay); competitionStringId = scenarioInfo->numCompetingCompanies == 1 ? StringIds::competition_not_starting_for_month : StringIds::competition_not_starting_for_months; - Gfx::drawStringLeft(*rt, x, y, Colour::black, competitionStringId, &args); + drawingCtx.drawStringLeft(*rt, x, y, Colour::black, competitionStringId, &args); } } // 0x00443D02 static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto colour = Colours::getShade(self.getColour(WindowColour::secondary).c(), 4); - Gfx::clearSingle(rt, colour); + drawingCtx.clearSingle(rt, colour); using namespace ScenarioManager; auto scenarioCount = getScenarioCountByCategory(self.currentTab); @@ -362,7 +366,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect auto formatStringId = StringIds::black_stringid; if (scenarioInfo == reinterpret_cast(self.info)) { - Gfx::drawRect(rt, 0, y, self.width, kRowHeight - 1, 0x2000000 | 48); + drawingCtx.drawRect(rt, 0, y, self.width, kRowHeight - 1, 0x2000000 | 48); formatStringId = StringIds::wcolour2_stringid; } @@ -375,7 +379,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect args.push(StringIds::buffer_2039); const int16_t x = 210; - Gfx::drawStringCentred(rt, x, y + 1, Colour::black, formatStringId, &args); + drawingCtx.drawStringCentred(rt, x, y + 1, Colour::black, formatStringId, &args); } // Completed? @@ -386,7 +390,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect } // Draw checkmark to indicate completion - Gfx::drawImage(&rt, self.widgets[widx::list].width() - ScrollView::barWidth - 25, y + 1, ImageIds::scenario_completed_tick); + drawingCtx.drawImage(&rt, self.widgets[widx::list].width() - ScrollView::barWidth - 25, y + 1, ImageIds::scenario_completed_tick); // 'Completed by' info { @@ -400,7 +404,7 @@ namespace OpenLoco::Ui::Windows::ScenarioSelect args.push(scenarioInfo->completedMonths % 12); const int16_t x = (self.widgets[widx::list].width() - ScrollView::barWidth) / 2; - Gfx::drawStringCentred(rt, x, y + 10, Colour::black, formatStringId, &args); + drawingCtx.drawStringCentred(rt, x, y + 10, Colour::black, formatStringId, &args); } y += kRowHeight; diff --git a/src/OpenLoco/src/Windows/StationList.cpp b/src/OpenLoco/src/Windows/StationList.cpp index 2b254e882f..28dd7e38e6 100644 --- a/src/OpenLoco/src/Windows/StationList.cpp +++ b/src/OpenLoco/src/Windows/StationList.cpp @@ -1,4 +1,5 @@ #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" @@ -449,8 +450,10 @@ namespace OpenLoco::Ui::Windows::StationList // 0x0049157F static void drawScroll(Ui::Window& window, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(window.getColour(WindowColour::secondary).c(), 4); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); uint16_t yPos = 0; for (uint16_t i = 0; i < window.var_83C; i++) @@ -469,7 +472,7 @@ namespace OpenLoco::Ui::Windows::StationList // Highlight selection. if (stationId == StationId(window.rowHover)) { - Gfx::drawRect(rt, 0, yPos, window.width, kRowHeight, 0x2000030); + drawingCtx.drawRect(rt, 0, yPos, window.width, kRowHeight, 0x2000030); text_colour_id = StringIds::wcolour2_stringid; } @@ -481,14 +484,14 @@ namespace OpenLoco::Ui::Windows::StationList _commonFormatArgs[2] = enumValue(station->town); _commonFormatArgs[3] = getTransportIconsFromStationFlags(station->flags); - Gfx::drawStringLeftClipped(rt, 0, yPos, 198, Colour::black, text_colour_id, &*_commonFormatArgs); + drawingCtx.drawStringLeftClipped(rt, 0, yPos, 198, Colour::black, text_colour_id, &*_commonFormatArgs); // Then the station's current status. char* buffer = const_cast(StringManager::getString(StringIds::buffer_1250)); station->getStatusString(buffer); _commonFormatArgs[0] = StringIds::buffer_1250; - Gfx::drawStringLeftClipped(rt, 200, yPos, 198, Colour::black, text_colour_id, &*_commonFormatArgs); + drawingCtx.drawStringLeftClipped(rt, 200, yPos, 198, Colour::black, text_colour_id, &*_commonFormatArgs); // Total units waiting. uint16_t totalUnits = 0; @@ -497,7 +500,7 @@ namespace OpenLoco::Ui::Windows::StationList _commonFormatArgs[0] = StringIds::num_units; *(uint32_t*)&_commonFormatArgs[1] = totalUnits; - Gfx::drawStringLeftClipped(rt, 400, yPos, 88, Colour::black, text_colour_id, &*_commonFormatArgs); + drawingCtx.drawStringLeftClipped(rt, 400, yPos, 88, Colour::black, text_colour_id, &*_commonFormatArgs); // And, finally, what goods the station accepts. char* ptr = buffer; @@ -517,7 +520,7 @@ namespace OpenLoco::Ui::Windows::StationList } _commonFormatArgs[0] = StringIds::buffer_1250; - Gfx::drawStringLeftClipped(rt, 490, yPos, 118, Colour::black, text_colour_id, &*_commonFormatArgs); + drawingCtx.drawStringLeftClipped(rt, 490, yPos, 118, Colour::black, text_colour_id, &*_commonFormatArgs); yPos += kRowHeight; } @@ -539,6 +542,8 @@ namespace OpenLoco::Ui::Windows::StationList // 0x004914D8 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets and tabs. window.draw(rt); drawTabs(&window, rt); @@ -549,7 +554,7 @@ namespace OpenLoco::Ui::Windows::StationList uint32_t image = Gfx::recolour(competitor->images[company->ownerEmotion], company->mainColours.primary); uint16_t x = window.x + window.widgets[widx::company_select].left + 1; uint16_t y = window.y + window.widgets[widx::company_select].top + 1; - Gfx::drawImage(rt, x, y, image); + drawingCtx.drawImage(rt, x, y, image); // TODO: locale-based pluralisation. _commonFormatArgs[0] = window.var_83C == 1 ? StringIds::status_num_stations_singular : StringIds::status_num_stations_plural; @@ -557,7 +562,7 @@ namespace OpenLoco::Ui::Windows::StationList // Draw number of stations. auto origin = Ui::Point(window.x + 4, window.y + window.height - 12); - Gfx::drawStringLeft(*rt, &origin, Colour::black, StringIds::black_stringid, &*_commonFormatArgs); + drawingCtx.drawStringLeft(*rt, &origin, Colour::black, StringIds::black_stringid, &*_commonFormatArgs); } // 0x004917BB diff --git a/src/OpenLoco/src/Windows/StationWindow.cpp b/src/OpenLoco/src/Windows/StationWindow.cpp index a2616358b2..c63276aab1 100644 --- a/src/OpenLoco/src/Windows/StationWindow.cpp +++ b/src/OpenLoco/src/Windows/StationWindow.cpp @@ -1,5 +1,6 @@ #include "CompanyManager.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -113,6 +114,8 @@ namespace OpenLoco::Ui::Windows::Station // 0x0048E470 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); self.drawViewports(rt); @@ -129,7 +132,7 @@ namespace OpenLoco::Ui::Windows::Station const auto x = self.x + widget.left - 1; const auto y = self.y + widget.top - 1; const auto width = widget.width() - 1; - Gfx::drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::black_stringid, &args); } // 0x0048E4D4 @@ -360,6 +363,8 @@ namespace OpenLoco::Ui::Windows::Station // 0x0048E8DE static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -396,7 +401,7 @@ namespace OpenLoco::Ui::Windows::Station const auto y = self.y + widget.top - 1; const auto width = widget.width(); - Gfx::drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::buffer_1250); + drawingCtx.drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::buffer_1250); } // 0x0048EB0B @@ -465,7 +470,8 @@ namespace OpenLoco::Ui::Windows::Station // 0x0048E986 static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { - Gfx::clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); const auto station = StationManager::get(StationId(self.number)); int16_t y = 1; @@ -492,7 +498,7 @@ namespace OpenLoco::Ui::Windows::Station for (; units > 0; units--) { { - Gfx::drawImage(&rt, xPos, y, cargoObj->unitInlineSprite); + drawingCtx.drawImage(&rt, xPos, y, cargoObj->unitInlineSprite); xPos += 10; } } @@ -512,7 +518,7 @@ namespace OpenLoco::Ui::Windows::Station const auto& widget = self.widgets[widx::scrollview]; auto xPos = widget.width() - 14; - Gfx::drawStringRight(rt, xPos, y, AdvancedColour(Colour::black).outline(), cargoStr, &args); + drawingCtx.drawStringRight(rt, xPos, y, AdvancedColour(Colour::black).outline(), cargoStr, &args); y += 10; if (cargo.origin != StationId(self.number)) { @@ -521,7 +527,7 @@ namespace OpenLoco::Ui::Windows::Station args2.push(originStation->name); args2.push(originStation->town); - Gfx::drawStringRight(rt, xPos, y, AdvancedColour(Colour::black).outline(), StringIds::station_cargo_en_route_end, &args2); + drawingCtx.drawStringRight(rt, xPos, y, AdvancedColour(Colour::black).outline(), StringIds::station_cargo_en_route_end, &args2); y += 10; } y += 2; @@ -536,7 +542,7 @@ namespace OpenLoco::Ui::Windows::Station { auto args = FormatArguments(); args.push(StringIds::nothing_waiting); - Gfx::drawStringLeft(rt, 1, 0, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(rt, 1, 0, Colour::black, StringIds::black_stringid, &args); } } @@ -659,19 +665,21 @@ namespace OpenLoco::Ui::Windows::Station // 0x0048EF02 static void drawRatingBar(Window* self, Gfx::RenderTarget* rt, int16_t x, int16_t y, uint8_t amount, Colour colour) { - Gfx::fillRectInset(*rt, x, y, x + 99, y + 9, self->getColour(WindowColour::secondary).u8(), 48); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.fillRectInset(*rt, x, y, x + 99, y + 9, self->getColour(WindowColour::secondary).u8(), 48); uint16_t rating = (amount * 96) / 256; if (rating > 2) { - Gfx::fillRectInset(*rt, x + 2, y + 2, x + 1 + rating, y + 8, enumValue(colour), 0); + drawingCtx.fillRectInset(*rt, x + 2, y + 2, x + 1 + rating, y + 8, enumValue(colour), 0); } } // 0x0048ED2F static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { - Gfx::clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); const auto station = StationManager::get(StationId(self.number)); int16_t y = 0; @@ -686,7 +694,7 @@ namespace OpenLoco::Ui::Windows::Station } auto cargoObj = ObjectManager::get(cargoId); - Gfx::drawStringLeftClipped(rt, 1, y, 98, Colour::black, StringIds::wcolour2_stringid, &cargoObj->name); + drawingCtx.drawStringLeftClipped(rt, 1, y, 98, Colour::black, StringIds::wcolour2_stringid, &cargoObj->name); auto rating = cargo.rating; auto colour = Colour::green; @@ -703,7 +711,7 @@ namespace OpenLoco::Ui::Windows::Station drawRatingBar(&self, &rt, 100, y, amount, colour); uint16_t percent = rating / 2; - Gfx::drawStringLeft(rt, 201, y, Colour::black, StringIds::station_cargo_rating_percent, &percent); + drawingCtx.drawStringLeft(rt, 201, y, Colour::black, StringIds::station_cargo_rating_percent, &percent); y += 10; cargoId++; } @@ -923,6 +931,8 @@ namespace OpenLoco::Ui::Windows::Station // 0x0048EFBC static void drawTabs(Window* self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto skin = ObjectManager::get(); auto station = StationManager::get(StationId(self->number)); auto companyColour = CompanyManager::getCompanyColour(station->owner); @@ -967,7 +977,7 @@ namespace OpenLoco::Ui::Windows::Station auto& cargo = cargoStats; if (!cargo.empty()) { - Gfx::fillRect(*rt, xOffset, yOffset, xOffset + 22, yOffset + 1, (1 << 25) | PaletteIndex::index_30); + drawingCtx.fillRect(*rt, xOffset, yOffset, xOffset + 22, yOffset + 1, (1 << 25) | PaletteIndex::index_30); auto ratingColour = Colour::green; if (cargo.rating < 100) @@ -978,7 +988,7 @@ namespace OpenLoco::Ui::Windows::Station } auto ratingBarLength = (cargo.rating * 30) / 256; - Gfx::fillRect(*rt, xOffset, yOffset, xOffset - 1 + ratingBarLength, yOffset + 1, Colours::getShade(ratingColour, 6)); + drawingCtx.fillRect(*rt, xOffset, yOffset, xOffset - 1 + ratingBarLength, yOffset + 1, Colours::getShade(ratingColour, 6)); yOffset += 3; totalRatingBars++; diff --git a/src/OpenLoco/src/Windows/TerraForm.cpp b/src/OpenLoco/src/Windows/TerraForm.cpp index 99056166f3..66a981dab1 100644 --- a/src/OpenLoco/src/Windows/TerraForm.cpp +++ b/src/OpenLoco/src/Windows/TerraForm.cpp @@ -1,5 +1,6 @@ #include "Audio/Audio.h" #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Economy/Economy.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -695,6 +696,8 @@ namespace OpenLoco::Ui::Windows::Terraform // 0x004BB8C9 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -728,12 +731,12 @@ namespace OpenLoco::Ui::Windows::Terraform { auto xPos = self.x + 3 + self.width - 17; auto yPos = self.y + self.height - 13; - Gfx::drawStringRight(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); + drawingCtx.drawStringRight(*rt, xPos, yPos, Colour::black, StringIds::build_cost, &args); } auto xPos = self.x + 3; auto yPos = self.y + self.height - 13; auto width = self.width - 19 - xPos; - Gfx::drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::black_stringid, &treeObj->name); + drawingCtx.drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::black_stringid, &treeObj->name); } static void drawTreeThumb(TreeObject* treeObj, Gfx::RenderTarget* clipped) @@ -754,14 +757,17 @@ namespace OpenLoco::Ui::Windows::Terraform } image = Gfx::recolour(image, colour); } - Gfx::drawImage(clipped, 32, 96, image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(clipped, 32, 96, image); } // 0x004BB982 static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(self.getColour(WindowColour::secondary).c(), 3); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); uint16_t xPos = 0; uint16_t yPos = 0; @@ -773,13 +779,13 @@ namespace OpenLoco::Ui::Windows::Terraform if (self.rowInfo[i] == self.var_846) { _lastTreeColourFlag = AdvancedColour::translucentFlag; - Gfx::drawRectInset(rt, xPos, yPos, 65, kRowHeight - 1, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); + drawingCtx.drawRectInset(rt, xPos, yPos, 65, kRowHeight - 1, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); } } else { _lastTreeColourFlag = AdvancedColour::translucentFlag | AdvancedColour::outlineFlag; - Gfx::drawRectInset(rt, xPos, yPos, 65, kRowHeight - 1, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); + drawingCtx.drawRectInset(rt, xPos, yPos, 65, kRowHeight - 1, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); } auto treeObj = ObjectManager::get(self.rowInfo[i]); @@ -1046,6 +1052,8 @@ namespace OpenLoco::Ui::Windows::Terraform // 0x004BC5E7 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -1063,7 +1071,7 @@ namespace OpenLoco::Ui::Windows::Terraform auto args = FormatArguments(); args.push(_raiseLandCost); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::clear_land_cost, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::clear_land_cost, &args); } static void initEvents() @@ -1548,6 +1556,8 @@ namespace OpenLoco::Ui::Windows::Terraform // 0x004BC909 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto skin = ObjectManager::get(); auto imgId = skin->img; self.widgets[widx::paint_mode].image = imgId + InterfaceSkin::ImageIds::tab_colour_scheme_frame0; @@ -1567,7 +1577,7 @@ namespace OpenLoco::Ui::Windows::Terraform { auto args = FormatArguments(); args.push(_raiseLandCost); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::increase_height_cost, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::increase_height_cost, &args); } } @@ -1579,7 +1589,7 @@ namespace OpenLoco::Ui::Windows::Terraform { auto args = FormatArguments(); args.push(_lowerLandCost); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::decrease_height_cost, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::decrease_height_cost, &args); } } } @@ -1833,6 +1843,8 @@ namespace OpenLoco::Ui::Windows::Terraform // 0x004BCCFF static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -1848,7 +1860,7 @@ namespace OpenLoco::Ui::Windows::Terraform auto args = FormatArguments(); args.push(_raiseWaterCost); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::increase_height_cost, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::increase_height_cost, &args); } } @@ -1861,7 +1873,7 @@ namespace OpenLoco::Ui::Windows::Terraform auto args = FormatArguments(); args.push(_lowerWaterCost); - Gfx::drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::decrease_height_cost, &args); + drawingCtx.drawStringCentred(*rt, xPos, yPos, Colour::black, StringIds::decrease_height_cost, &args); } } } @@ -2274,6 +2286,8 @@ namespace OpenLoco::Ui::Windows::Terraform // 0x004BC0C2 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -2290,14 +2304,16 @@ namespace OpenLoco::Ui::Windows::Terraform auto yPos = self.y + self.height - 13; auto width = self.width - 19; - Gfx::drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::black_stringid, &wallObj->name); + drawingCtx.drawStringLeftClipped(*rt, xPos, yPos, width, Colour::black, StringIds::black_stringid, &wallObj->name); } // 0x004BC11C static void drawScroll(Window& self, Gfx::RenderTarget& rt, uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(self.getColour(WindowColour::secondary).c(), 3); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); uint16_t xPos = 0; uint16_t yPos = 0; @@ -2307,19 +2323,19 @@ namespace OpenLoco::Ui::Windows::Terraform { if (self.rowInfo[i] == self.var_846) { - Gfx::drawRectInset(rt, xPos, yPos, 40, kRowHeight, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); + drawingCtx.drawRectInset(rt, xPos, yPos, 40, kRowHeight, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); } } else { - Gfx::drawRectInset(rt, xPos, yPos, 40, kRowHeight, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); + drawingCtx.drawRectInset(rt, xPos, yPos, 40, kRowHeight, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); } auto wallObj = ObjectManager::get(self.rowInfo[i]); auto clipped = Gfx::clipRenderTarget(rt, Ui::Rect(xPos + 1, yPos + 1, 39, 47)); if (clipped) - Gfx::drawImage(&*clipped, 34, 28, wallObj->sprite); + drawingCtx.drawImage(&*clipped, 34, 28, wallObj->sprite); xPos += 40; diff --git a/src/OpenLoco/src/Windows/TextInputWindow.cpp b/src/OpenLoco/src/Windows/TextInputWindow.cpp index d936cb5146..b91541627f 100644 --- a/src/OpenLoco/src/Windows/TextInputWindow.cpp +++ b/src/OpenLoco/src/Windows/TextInputWindow.cpp @@ -1,4 +1,5 @@ #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "Interop/Interop.hpp" @@ -221,13 +222,15 @@ namespace OpenLoco::Ui::Windows::TextInput */ static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + window.draw(rt); *((string_id*)(&_commonFormatArgs[0])) = _message; memcpy(&_commonFormatArgs[2], _formatArgs + 8, 8); Ui::Point position = { (int16_t)(window.x + window.width / 2), (int16_t)(window.y + 30) }; - Gfx::drawStringCentredWrapped(*rt, position, window.width - 8, Colour::black, StringIds::wcolour2_stringid, &_commonFormatArgs[0]); + drawingCtx.drawStringCentredWrapped(*rt, position, window.width - 8, Colour::black, StringIds::wcolour2_stringid, &_commonFormatArgs[0]); auto widget = &_widgets[Widx::input]; auto clipped = Gfx::clipRenderTarget(*rt, Ui::Rect(widget->left + 1 + window.x, widget->top + 1 + window.y, widget->width() - 2, widget->height() - 2)); @@ -242,7 +245,7 @@ namespace OpenLoco::Ui::Windows::TextInput *((string_id*)(&_commonFormatArgs[0])) = StringIds::buffer_2039; position = { inputSession.xOffset, 1 }; - Gfx::drawStringLeft(*clipped, &position, Colour::black, StringIds::black_stringid, _commonFormatArgs); + drawingCtx.drawStringLeft(*clipped, &position, Colour::black, StringIds::black_stringid, _commonFormatArgs); const uint16_t numCharacters = static_cast(inputSession.cursorPosition); const uint16_t maxNumCharacters = inputSession.inputLenLimit; @@ -252,7 +255,7 @@ namespace OpenLoco::Ui::Windows::TextInput args.push(maxNumCharacters); widget = &_widgets[Widx::ok]; - Gfx::drawStringRight(*rt, window.x + widget->left - 5, window.y + widget->top + 1, Colour::black, StringIds::num_characters_left_int_int, &args); + drawingCtx.drawStringRight(*rt, window.x + widget->left - 5, window.y + widget->top + 1, Colour::black, StringIds::num_characters_left_int_int, &args); if ((inputSession.cursorFrame % 32) >= 16) { @@ -264,8 +267,8 @@ namespace OpenLoco::Ui::Windows::TextInput *((string_id*)(&_commonFormatArgs[0])) = StringIds::buffer_2039; position = { inputSession.xOffset, 1 }; - Gfx::drawStringLeft(*clipped, &position, Colour::black, StringIds::black_stringid, _commonFormatArgs); - Gfx::fillRect(*clipped, position.x, position.y, position.x, position.y + 9, Colours::getShade(window.getColour(WindowColour::secondary).c(), 9)); + drawingCtx.drawStringLeft(*clipped, &position, Colour::black, StringIds::black_stringid, _commonFormatArgs); + drawingCtx.fillRect(*clipped, position.x, position.y, position.x, position.y + 9, Colours::getShade(window.getColour(WindowColour::secondary).c(), 9)); } // 0x004CE8B6 diff --git a/src/OpenLoco/src/Windows/TileInspector.cpp b/src/OpenLoco/src/Windows/TileInspector.cpp index 1d4776f99e..3398575ab6 100644 --- a/src/OpenLoco/src/Windows/TileInspector.cpp +++ b/src/OpenLoco/src/Windows/TileInspector.cpp @@ -1,4 +1,5 @@ #include "CompanyManager.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Graphics/ImageIds.h" @@ -128,6 +129,8 @@ namespace OpenLoco::Ui::Windows::TileInspector static void draw(Ui::Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. self.draw(rt); @@ -135,12 +138,12 @@ namespace OpenLoco::Ui::Windows::TileInspector { auto args = FormatArguments::common(StringIds::tile_inspector_x_coord); auto& widget = self.widgets[widx::xPos]; - Gfx::drawStringLeft(*rt, self.x + widget.left - 15, self.y + widget.top + 1, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringLeft(*rt, self.x + widget.left - 15, self.y + widget.top + 1, Colour::black, StringIds::wcolour2_stringid, &args); } { auto args = FormatArguments::common(StringIds::tile_inspector_y_coord); auto& widget = self.widgets[widx::yPos]; - Gfx::drawStringLeft(*rt, self.x + widget.left - 15, self.y + widget.top + 1, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringLeft(*rt, self.x + widget.left - 15, self.y + widget.top + 1, Colour::black, StringIds::wcolour2_stringid, &args); } // Coord X/Y values @@ -148,13 +151,13 @@ namespace OpenLoco::Ui::Windows::TileInspector FormatArguments args = {}; args.push(_currentPosition.x); auto& widget = self.widgets[widx::xPos]; - Gfx::drawStringLeft(*rt, self.x + widget.left + 2, self.y + widget.top + 1, Colour::black, StringIds::tile_inspector_coord, &args); + drawingCtx.drawStringLeft(*rt, self.x + widget.left + 2, self.y + widget.top + 1, Colour::black, StringIds::tile_inspector_coord, &args); } { FormatArguments args = {}; args.push(_currentPosition.y); auto& widget = self.widgets[widx::yPos]; - Gfx::drawStringLeft(*rt, self.x + widget.left + 2, self.y + widget.top + 1, Colour::black, StringIds::tile_inspector_coord, &args); + drawingCtx.drawStringLeft(*rt, self.x + widget.left + 2, self.y + widget.top + 1, Colour::black, StringIds::tile_inspector_coord, &args); } // Selected element details @@ -168,7 +171,7 @@ namespace OpenLoco::Ui::Windows::TileInspector snprintf(&buffer[1], std::size(buffer) - 1, "Data: %02x %02x %02x %02x %02x %02x %02x %02x", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); auto widget = self.widgets[widx::detailsGroup]; - Gfx::drawString(*rt, self.x + widget.left + 7, self.y + widget.top + 14, Colour::black, buffer); + drawingCtx.drawString(*rt, self.x + widget.left + 7, self.y + widget.top + 14, Colour::black, buffer); } } @@ -308,6 +311,8 @@ namespace OpenLoco::Ui::Windows::TileInspector if (_currentPosition == TilePos2(0, 0)) return; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto tile = TileManager::get(_currentPosition); auto yPos = 0; auto rowNum = 0; @@ -316,12 +321,12 @@ namespace OpenLoco::Ui::Windows::TileInspector string_id formatString; if (self.var_842 == rowNum) { - Gfx::fillRect(rt, 0, yPos, self.width, yPos + self.rowHeight, enumValue(Colour::darkGreen)); + drawingCtx.fillRect(rt, 0, yPos, self.width, yPos + self.rowHeight, enumValue(Colour::darkGreen)); formatString = StringIds::white_stringid; } else if (self.rowHover == rowNum) { - Gfx::fillRect(rt, 0, yPos, self.width, yPos + self.rowHeight, 0x2000030); + drawingCtx.fillRect(rt, 0, yPos, self.width, yPos + self.rowHeight, 0x2000030); formatString = StringIds::wcolour2_stringid; } else @@ -350,7 +355,7 @@ namespace OpenLoco::Ui::Windows::TileInspector args.push(elementName); } - Gfx::drawStringLeft(rt, 0, yPos, Colour::black, formatString, &args); + drawingCtx.drawStringLeft(rt, 0, yPos, Colour::black, formatString, &args); rowNum++; yPos += self.rowHeight; } diff --git a/src/OpenLoco/src/Windows/TimePanel.cpp b/src/OpenLoco/src/Windows/TimePanel.cpp index a6a8564e17..152654491b 100644 --- a/src/OpenLoco/src/Windows/TimePanel.cpp +++ b/src/OpenLoco/src/Windows/TimePanel.cpp @@ -1,5 +1,6 @@ #include "CompanyManager.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -169,13 +170,15 @@ namespace OpenLoco::Ui::Windows::TimePanel // 0x004397BE static void draw(Ui::Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Widget& frame = _widgets[Widx::outer_frame]; - Gfx::drawRect(*rt, self.x + frame.left, self.y + frame.top, frame.width(), frame.height(), 0x2000000 | 52); + drawingCtx.drawRect(*rt, self.x + frame.left, self.y + frame.top, frame.width(), frame.height(), 0x2000000 | 52); // Draw widgets. self.draw(rt); - Gfx::drawRectInset(*rt, self.x + frame.left + 1, self.y + frame.top + 1, frame.width() - 2, frame.height() - 2, self.getColour(WindowColour::secondary).u8(), 0x30); + drawingCtx.drawRectInset(*rt, self.x + frame.left + 1, self.y + frame.top + 1, frame.width() - 2, frame.height() - 2, self.getColour(WindowColour::secondary).u8(), 0x30); *(uint32_t*)&_commonFormatArgs[0] = getCurrentDay(); string_id format = StringIds::date_daymonthyear; @@ -193,10 +196,10 @@ namespace OpenLoco::Ui::Windows::TimePanel { c = Colour::white; } - Gfx::drawStringCentred(*rt, self.x + _widgets[Widx::date_btn].midX(), self.y + _widgets[Widx::date_btn].top + 1, c, format, &*_commonFormatArgs); + drawingCtx.drawStringCentred(*rt, self.x + _widgets[Widx::date_btn].midX(), self.y + _widgets[Widx::date_btn].top + 1, c, format, &*_commonFormatArgs); auto skin = ObjectManager::get(); - Gfx::drawImage(rt, self.x + _widgets[Widx::map_chat_menu].left - 2, self.y + _widgets[Widx::map_chat_menu].top - 1, skin->img + map_sprites_by_rotation[WindowManager::getCurrentRotation()]); + drawingCtx.drawImage(rt, self.x + _widgets[Widx::map_chat_menu].left - 2, self.y + _widgets[Widx::map_chat_menu].top - 1, skin->img + map_sprites_by_rotation[WindowManager::getCurrentRotation()]); } // 0x004398FB diff --git a/src/OpenLoco/src/Windows/TitleExit.cpp b/src/OpenLoco/src/Windows/TitleExit.cpp index e6dd499476..2307ee0f9f 100644 --- a/src/OpenLoco/src/Windows/TitleExit.cpp +++ b/src/OpenLoco/src/Windows/TitleExit.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -60,8 +61,9 @@ namespace OpenLoco::Ui::Windows::TitleExit static void prepareDraw(Ui::Window& self) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); auto exitString = StringManager::getString(StringIds::title_exit_game); - self.width = Gfx::getStringWidthNewLined(exitString) + 10; + self.width = drawingCtx.getStringWidthNewLined(exitString) + 10; self.x = Ui::width() - self.width; self.widgets[Widx::exit_button].right = self.width; } @@ -69,13 +71,15 @@ namespace OpenLoco::Ui::Windows::TitleExit // 0x00439236 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. window.draw(rt); int16_t x = window.x + window.width / 2; int16_t y = window.y + window.widgets[Widx::exit_button].top + 8; Ui::Point origin = { x, y }; - Gfx::drawStringCentredWrapped(*rt, origin, window.width, Colour::black, StringIds::title_exit_game); + drawingCtx.drawStringCentredWrapped(*rt, origin, window.width, Colour::black, StringIds::title_exit_game); } // 0x00439268 diff --git a/src/OpenLoco/src/Windows/TitleLogo.cpp b/src/OpenLoco/src/Windows/TitleLogo.cpp index c176313664..7d1570729e 100644 --- a/src/OpenLoco/src/Windows/TitleLogo.cpp +++ b/src/OpenLoco/src/Windows/TitleLogo.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" #include "Interop/Interop.hpp" @@ -55,7 +56,8 @@ namespace OpenLoco::Ui::Windows::TitleLogo // 0x00439298 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { - Gfx::drawImage(rt, window.x, window.y, ImageIds::locomotion_logo); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(rt, window.x, window.y, ImageIds::locomotion_logo); } // 0x004392AD diff --git a/src/OpenLoco/src/Windows/TitleMenu.cpp b/src/OpenLoco/src/Windows/TitleMenu.cpp index ab5524378b..d5a6e1ed3b 100644 --- a/src/OpenLoco/src/Windows/TitleMenu.cpp +++ b/src/OpenLoco/src/Windows/TitleMenu.cpp @@ -1,5 +1,6 @@ #include "Config.h" #include "Console.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "EditorController.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -222,6 +223,8 @@ namespace OpenLoco::Ui::Windows::TitleMenu // 0x00438EC7 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. window.draw(rt); @@ -236,8 +239,8 @@ namespace OpenLoco::Ui::Windows::TitleMenu image_id = kGlobeSpin[((window.var_846 / 2) % kGlobeSpin.size())]; } - OpenLoco::Gfx::drawImage(rt, x, y, image_id); - OpenLoco::Gfx::drawImage(rt, x, y, ImageIds::title_menu_sparkle); + drawingCtx.drawImage(rt, x, y, image_id); + drawingCtx.drawImage(rt, x, y, ImageIds::title_menu_sparkle); } if (window.widgets[Widx::load_game_btn].type != Ui::WidgetType::none) @@ -251,8 +254,8 @@ namespace OpenLoco::Ui::Windows::TitleMenu image_id = kGlobeSpin[((window.var_846 / 2) % kGlobeSpin.size())]; } - OpenLoco::Gfx::drawImage(rt, x, y, image_id); - OpenLoco::Gfx::drawImage(rt, x, y, ImageIds::title_menu_save); + drawingCtx.drawImage(rt, x, y, image_id); + drawingCtx.drawImage(rt, x, y, ImageIds::title_menu_save); } if (window.widgets[Widx::tutorial_btn].type != Ui::WidgetType::none) @@ -266,10 +269,10 @@ namespace OpenLoco::Ui::Windows::TitleMenu image_id = kGlobeSpin[((window.var_846 / 2) % kGlobeSpin.size())]; } - OpenLoco::Gfx::drawImage(rt, x, y, image_id); + drawingCtx.drawImage(rt, x, y, image_id); // TODO: base lesson overlay on language - OpenLoco::Gfx::drawImage(rt, x, y, ImageIds::title_menu_lesson_l); + drawingCtx.drawImage(rt, x, y, ImageIds::title_menu_lesson_l); } if (window.widgets[Widx::scenario_editor_btn].type != Ui::WidgetType::none) @@ -283,7 +286,7 @@ namespace OpenLoco::Ui::Windows::TitleMenu image_id = kGlobeConstruct[((window.var_846 / 2) % kGlobeConstruct.size())]; } - OpenLoco::Gfx::drawImage(rt, x, y, image_id); + drawingCtx.drawImage(rt, x, y, image_id); } if (window.widgets[Widx::multiplayer_toggle_btn].type != Ui::WidgetType::none) @@ -306,7 +309,7 @@ namespace OpenLoco::Ui::Windows::TitleMenu string = StringIds::two_player_mode_connected; } - drawStringCentredClipped(*rt, x, y, kWW - 4, Colour::black, string, (char*)0x112c826); + drawingCtx.drawStringCentredClipped(*rt, x, y, kWW - 4, Colour::black, string, (char*)0x112c826); } } diff --git a/src/OpenLoco/src/Windows/TitleOptions.cpp b/src/OpenLoco/src/Windows/TitleOptions.cpp index 7ffbda4eb0..387e708d0f 100644 --- a/src/OpenLoco/src/Windows/TitleOptions.cpp +++ b/src/OpenLoco/src/Windows/TitleOptions.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" @@ -58,6 +59,8 @@ namespace OpenLoco::Ui::Windows::TitleOptions static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. window.draw(rt); @@ -65,7 +68,7 @@ namespace OpenLoco::Ui::Windows::TitleOptions int16_t y = window.y + window.widgets[Widx::options_button].top + 2; Ui::Point origin = { x, y }; - Gfx::drawStringCentredWrapped(*rt, origin, window.width, Colour::white, StringIds::outlined_wcolour2_stringid, (const char*)&StringIds::options); + drawingCtx.drawStringCentredWrapped(*rt, origin, window.width, Colour::white, StringIds::outlined_wcolour2_stringid, (const char*)&StringIds::options); } static void onMouseUp(Window& window, WidgetIndex_t widgetIndex) diff --git a/src/OpenLoco/src/Windows/TitleVersion.cpp b/src/OpenLoco/src/Windows/TitleVersion.cpp index 0389fd017b..dff1593dfe 100644 --- a/src/OpenLoco/src/Windows/TitleVersion.cpp +++ b/src/OpenLoco/src/Windows/TitleVersion.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Interop/Interop.hpp" #include "OpenLoco.h" @@ -38,7 +39,9 @@ namespace OpenLoco::Ui::Windows::TitleVersion // 0x00439236 static void draw(Ui::Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto versionInfo = getVersionInfo(); - Gfx::drawString(*rt, window.x, window.y, AdvancedColour(Colour::white).outline(), (void*)versionInfo.c_str()); + drawingCtx.drawString(*rt, window.x, window.y, AdvancedColour(Colour::white).outline(), (void*)versionInfo.c_str()); } } diff --git a/src/OpenLoco/src/Windows/ToolTip.cpp b/src/OpenLoco/src/Windows/ToolTip.cpp index fbb73b95eb..175adf1d8d 100644 --- a/src/OpenLoco/src/Windows/ToolTip.cpp +++ b/src/OpenLoco/src/Windows/ToolTip.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Input.h" @@ -62,15 +63,17 @@ namespace OpenLoco::Ui::Windows::ToolTip static void common(const Window* window, int32_t widgetIndex, string_id stringId, int16_t cursorX, int16_t cursorY, FormatArguments& args) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + StringManager::formatString(_text, stringId, &args); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); - int16_t strWidth = Gfx::getStringWidthNewLined(_text); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); + int16_t strWidth = drawingCtx.getStringWidthNewLined(_text); strWidth = std::max(strWidth, 196); - Gfx::setCurrentFontSpriteBase(Font::medium_bold); + drawingCtx.setCurrentFontSpriteBase(Font::medium_bold); - auto [wrappedWidth, breakCount] = Gfx::wrapString(_text, strWidth + 1); + auto [wrappedWidth, breakCount] = drawingCtx.wrapString(_text, strWidth + 1); _lineBreakCount = breakCount; int width = wrappedWidth + 3; @@ -172,20 +175,22 @@ namespace OpenLoco::Ui::Windows::ToolTip uint16_t width = window.width; uint16_t height = window.height; - Gfx::drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | 45); - Gfx::drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | (116 + enumValue(ObjectManager::get()->colour_08))); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | 45); + drawingCtx.drawRect(*rt, x + 1, y + 1, width - 2, height - 2, 0x2000000 | (116 + enumValue(ObjectManager::get()->colour_08))); - Gfx::drawRect(*rt, x, y + 2, 1, height - 4, 0x2000000 | 46); - Gfx::drawRect(*rt, x + width - 1, y + 2, 1, height - 4, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 2, y + height - 1, width - 4, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 2, y, width - 4, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x, y + 2, 1, height - 4, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + width - 1, y + 2, 1, height - 4, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 2, y + height - 1, width - 4, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 2, y, width - 4, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 1, y + 1, 1, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + width - 1 - 1, y + 1, 1, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); - Gfx::drawRect(*rt, x + width - 1 - 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 1, y + 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + width - 1 - 1, y + 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); + drawingCtx.drawRect(*rt, x + width - 1 - 1, y + height - 1 - 1, 1, 1, 0x2000000 | 46); - Gfx::drawStringCentredRaw(*rt, ((width + 1) / 2) + x - 1, y + 1, _lineBreakCount, Colour::black, _text); + drawingCtx.drawStringCentredRaw(*rt, ((width + 1) / 2) + x - 1, y + 1, _lineBreakCount, Colour::black, _text); } // 0x004C94F7 diff --git a/src/OpenLoco/src/Windows/ToolbarBottomEditor.cpp b/src/OpenLoco/src/Windows/ToolbarBottomEditor.cpp index 5fb4b1e0f6..cd5d001581 100644 --- a/src/OpenLoco/src/Windows/ToolbarBottomEditor.cpp +++ b/src/OpenLoco/src/Windows/ToolbarBottomEditor.cpp @@ -1,3 +1,4 @@ +#include "Drawing/SoftwareDrawingEngine.h" #include "EditorController.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -64,28 +65,30 @@ namespace OpenLoco::Ui::Windows::ToolbarBottom::Editor // 0x0043CE65 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Widget& previous = self.widgets[widx::previous_frame]; Widget& next = self.widgets[widx::next_frame]; if (EditorController::canGoBack()) { - Gfx::drawRect(*rt, previous.left + self.x, previous.top + self.y, previous.width(), previous.height(), 0x2000000 | 52); + drawingCtx.drawRect(*rt, previous.left + self.x, previous.top + self.y, previous.width(), previous.height(), 0x2000000 | 52); } - Gfx::drawRect(*rt, next.left + self.x, next.top + self.y, next.width(), next.height(), 0x2000000 | 52); + drawingCtx.drawRect(*rt, next.left + self.x, next.top + self.y, next.width(), next.height(), 0x2000000 | 52); self.draw(rt); if (EditorController::canGoBack()) { - Gfx::drawRectInset(*rt, previous.left + self.x + 1, previous.top + self.y + 1, previous.width() - 2, previous.height() - 2, self.getColour(WindowColour::secondary).u8(), 0x30); + drawingCtx.drawRectInset(*rt, previous.left + self.x + 1, previous.top + self.y + 1, previous.width() - 2, previous.height() - 2, self.getColour(WindowColour::secondary).u8(), 0x30); } - Gfx::drawRectInset(*rt, next.left + self.x + 1, next.top + self.y + 1, next.width() - 2, next.height() - 2, self.getColour(WindowColour::secondary).u8(), 0x30); + drawingCtx.drawRectInset(*rt, next.left + self.x + 1, next.top + self.y + 1, next.width() - 2, next.height() - 2, self.getColour(WindowColour::secondary).u8(), 0x30); - Gfx::drawStringCentred(*rt, (previous.right + next.left) / 2 + self.x, self.y + self.height - 12, self.getColour(WindowColour::tertiary).opaque().outline(), _stepNames[EditorController::getCurrentStep()]); + drawingCtx.drawStringCentred(*rt, (previous.right + next.left) / 2 + self.x, self.y + self.height - 12, self.getColour(WindowColour::tertiary).opaque().outline(), _stepNames[EditorController::getCurrentStep()]); if (EditorController::canGoBack()) { - Gfx::drawImage(rt, self.x + previous.left + 6, self.y + previous.top + 6, ImageIds::step_back); + drawingCtx.drawImage(rt, self.x + previous.left + 6, self.y + previous.top + 6, ImageIds::step_back); int x = (previous.left + 30 + previous.right) / 2; int y = previous.top + 6; auto textColour = self.getColour(WindowColour::secondary).opaque(); @@ -93,10 +96,10 @@ namespace OpenLoco::Ui::Windows::ToolbarBottom::Editor { textColour = Colour::white; } - Gfx::drawStringCentred(*rt, self.x + x, self.y + y, textColour, StringIds::editor_previous_step); - Gfx::drawStringCentred(*rt, self.x + x, self.y + y + 10, textColour, _stepNames[EditorController::getPreviousStep()]); + drawingCtx.drawStringCentred(*rt, self.x + x, self.y + y, textColour, StringIds::editor_previous_step); + drawingCtx.drawStringCentred(*rt, self.x + x, self.y + y + 10, textColour, _stepNames[EditorController::getPreviousStep()]); } - Gfx::drawImage(rt, self.x + next.right - 29, self.y + next.top + 4, ImageIds::step_forward); + drawingCtx.drawImage(rt, self.x + next.right - 29, self.y + next.top + 4, ImageIds::step_forward); int x = next.left + (next.width() - 31) / 2; int y = next.top + 6; auto textColour = self.getColour(WindowColour::secondary).opaque(); @@ -104,8 +107,8 @@ namespace OpenLoco::Ui::Windows::ToolbarBottom::Editor { textColour = Colour::white; } - Gfx::drawStringCentred(*rt, self.x + x, self.y + y, textColour, StringIds::editor_next_step); - Gfx::drawStringCentred(*rt, self.x + x, self.y + y + 10, textColour, _stepNames[EditorController::getNextStep()]); + drawingCtx.drawStringCentred(*rt, self.x + x, self.y + y, textColour, StringIds::editor_next_step); + drawingCtx.drawStringCentred(*rt, self.x + x, self.y + y + 10, textColour, _stepNames[EditorController::getNextStep()]); } // 0x0043D0ED diff --git a/src/OpenLoco/src/Windows/ToolbarTop.cpp b/src/OpenLoco/src/Windows/ToolbarTop.cpp index da50433e02..69d6a1f4af 100644 --- a/src/OpenLoco/src/Windows/ToolbarTop.cpp +++ b/src/OpenLoco/src/Windows/ToolbarTop.cpp @@ -1,6 +1,7 @@ #include "Audio/Audio.h" #include "CompanyManager.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "Game.h" #include "GameCommands/GameCommands.h" @@ -744,6 +745,8 @@ namespace OpenLoco::Ui::Windows::ToolbarTop::Game // 0x00439DE4 static void draw(Window& window, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Common::draw(window, rt); const auto companyColour = CompanyManager::getPlayerCompanyColour(); @@ -778,10 +781,10 @@ namespace OpenLoco::Ui::Windows::ToolbarTop::Game bg_image++; } - Gfx::drawImage(rt, x, y, fg_image); + drawingCtx.drawImage(rt, x, y, fg_image); y = window.widgets[Common::Widx::railroad_menu].top + window.y; - Gfx::drawImage(rt, x, y, bg_image); + drawingCtx.drawImage(rt, x, y, bg_image); } { @@ -808,10 +811,10 @@ namespace OpenLoco::Ui::Windows::ToolbarTop::Game bg_image++; } - Gfx::drawImage(rt, x, y, fg_image); + drawingCtx.drawImage(rt, x, y, fg_image); y = window.widgets[Common::Widx::vehicles_menu].top + window.y; - Gfx::drawImage(rt, x, y, bg_image); + drawingCtx.drawImage(rt, x, y, bg_image); } { @@ -834,7 +837,7 @@ namespace OpenLoco::Ui::Windows::ToolbarTop::Game if (Input::isDropdownActive(Ui::WindowType::topToolbar, Common::Widx::build_vehicles_menu)) fg_image++; - Gfx::drawImage(rt, x, y, fg_image); + drawingCtx.drawImage(rt, x, y, fg_image); } } diff --git a/src/OpenLoco/src/Windows/ToolbarTopCommon.cpp b/src/OpenLoco/src/Windows/ToolbarTopCommon.cpp index 65756d0c4f..e2dbb8d746 100644 --- a/src/OpenLoco/src/Windows/ToolbarTopCommon.cpp +++ b/src/OpenLoco/src/Windows/ToolbarTopCommon.cpp @@ -2,6 +2,7 @@ #include "Audio/Audio.h" #include "CompanyManager.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -37,6 +38,8 @@ namespace OpenLoco::Ui::Windows::ToolbarTop::Common // 0x00439DE4 void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + // Draw widgets. self.draw(rt); @@ -73,10 +76,10 @@ namespace OpenLoco::Ui::Windows::ToolbarTop::Common bgImage++; } - Gfx::drawImage(rt, x, y, fgImage); + drawingCtx.drawImage(rt, x, y, fgImage); y = self.widgets[Widx::road_menu].top + self.y; - Gfx::drawImage(rt, x, y, bgImage); + drawingCtx.drawImage(rt, x, y, bgImage); } } diff --git a/src/OpenLoco/src/Windows/TownList.cpp b/src/OpenLoco/src/Windows/TownList.cpp index 58a60c3e36..8bb67a3d0c 100644 --- a/src/OpenLoco/src/Windows/TownList.cpp +++ b/src/OpenLoco/src/Windows/TownList.cpp @@ -1,5 +1,6 @@ #include "Audio/Audio.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -143,8 +144,10 @@ namespace OpenLoco::Ui::Windows::TownList // 0x0049A0F8 static void drawScroll(Ui::Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(self.getColour(WindowColour::secondary).c(), 3); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); uint16_t yPos = 0; for (uint16_t i = 0; i < self.var_83C; i++) @@ -163,7 +166,7 @@ namespace OpenLoco::Ui::Windows::TownList // Highlight selection. if (townId == TownId(self.rowHover)) { - Gfx::drawRect(rt, 0, yPos, self.width, kRowHeight, 0x2000030); + drawingCtx.drawRect(rt, 0, yPos, self.width, kRowHeight, 0x2000030); text_colour_id = StringIds::wcolour2_stringid; } @@ -176,14 +179,14 @@ namespace OpenLoco::Ui::Windows::TownList auto args = FormatArguments(); args.push(town->name); - Gfx::drawStringLeftClipped(rt, 0, yPos, 198, Colour::black, text_colour_id, &args); + drawingCtx.drawStringLeftClipped(rt, 0, yPos, 198, Colour::black, text_colour_id, &args); } // Town Type { auto args = FormatArguments(); args.push(town->getTownSizeString()); - Gfx::drawStringLeftClipped(rt, 200, yPos, 278, Colour::black, text_colour_id, &args); + drawingCtx.drawStringLeftClipped(rt, 200, yPos, 278, Colour::black, text_colour_id, &args); } // Town Population { @@ -191,7 +194,7 @@ namespace OpenLoco::Ui::Windows::TownList args.push(StringIds::int_32); args.push(town->population); - Gfx::drawStringLeftClipped(rt, 280, yPos, 68, Colour::black, text_colour_id, &args); + drawingCtx.drawStringLeftClipped(rt, 280, yPos, 68, Colour::black, text_colour_id, &args); } // Town Stations { @@ -199,7 +202,7 @@ namespace OpenLoco::Ui::Windows::TownList args.push(StringIds::int_32); args.push(town->numStations); - Gfx::drawStringLeftClipped(rt, 350, yPos, 68, Colour::black, text_colour_id, &args); + drawingCtx.drawStringLeftClipped(rt, 350, yPos, 68, Colour::black, text_colour_id, &args); } yPos += kRowHeight; } @@ -208,6 +211,8 @@ namespace OpenLoco::Ui::Windows::TownList // 0x0049A0A7 static void draw(Ui::Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); auto args = FormatArguments(); @@ -220,7 +225,7 @@ namespace OpenLoco::Ui::Windows::TownList args.push(StringIds::status_towns_plural); args.push(self.var_83C); - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::black_stringid, &args); } // 0x0049A27F @@ -632,12 +637,14 @@ namespace OpenLoco::Ui::Windows::TownList // 0x0049A627 static void draw(Ui::Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); - Gfx::drawStringLeft(*rt, self.x + 3, self.y + self.widgets[widx::current_size].top + 1, Colour::black, StringIds::town_size_label); + drawingCtx.drawStringLeft(*rt, self.x + 3, self.y + self.widgets[widx::current_size].top + 1, Colour::black, StringIds::town_size_label); - Gfx::drawStringLeft(*rt, self.x + 3, self.y + self.height - 13, Colour::black, StringIds::select_town_size); + drawingCtx.drawStringLeft(*rt, self.x + 3, self.y + self.height - 13, Colour::black, StringIds::select_town_size); } // 0x0049A675 @@ -847,6 +854,8 @@ namespace OpenLoco::Ui::Windows::TownList // 0x0049A9C2 static void draw(Ui::Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -862,7 +871,7 @@ namespace OpenLoco::Ui::Windows::TownList auto buildingObj = ObjectManager::get(buildingId); - Gfx::drawStringLeftClipped(*rt, self.x + 3, self.y + self.height - 13, self.width - 19, Colour::black, StringIds::black_stringid, &buildingObj->name); + drawingCtx.drawStringLeftClipped(*rt, self.x + 3, self.y + self.height - 13, self.width - 19, Colour::black, StringIds::black_stringid, &buildingObj->name); } // 0x0049AB31 @@ -1180,8 +1189,10 @@ namespace OpenLoco::Ui::Windows::TownList // 0x0049AA1C static void drawScroll(Ui::Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto shade = Colours::getShade(self.getColour(WindowColour::secondary).c(), 3); - Gfx::clearSingle(rt, shade); + drawingCtx.clearSingle(rt, shade); uint16_t xPos = 0; uint16_t yPos = 0; @@ -1191,12 +1202,12 @@ namespace OpenLoco::Ui::Windows::TownList { if (self.rowInfo[i] == self.var_846) { - Gfx::drawRectInset(rt, xPos, yPos, 112, 112, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); + drawingCtx.drawRectInset(rt, xPos, yPos, 112, 112, self.getColour(WindowColour::secondary).u8(), AdvancedColour::translucentFlag); } } else { - Gfx::drawRectInset(rt, xPos, yPos, 112, 112, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); + drawingCtx.drawRectInset(rt, xPos, yPos, 112, 112, self.getColour(WindowColour::secondary).u8(), (AdvancedColour::translucentFlag | AdvancedColour::outlineFlag)); } auto buildingObj = ObjectManager::get(self.rowInfo[i]); diff --git a/src/OpenLoco/src/Windows/TownWindow.cpp b/src/OpenLoco/src/Windows/TownWindow.cpp index ec750f63f0..523ef3a825 100644 --- a/src/OpenLoco/src/Windows/TownWindow.cpp +++ b/src/OpenLoco/src/Windows/TownWindow.cpp @@ -2,6 +2,7 @@ #include "CompanyManager.h" #include "Config.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -130,6 +131,8 @@ namespace OpenLoco::Ui::Windows::Town // 0x00498FFE static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); self.drawViewports(rt); @@ -145,7 +148,7 @@ namespace OpenLoco::Ui::Windows::Town const auto x = self.x + widget.left - 1; const auto y = self.y + widget.top - 1; const auto width = widget.width() - 1; - Gfx::drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::status_town_population, &args); + drawingCtx.drawStringLeftClipped(*rt, x, y, width, Colour::black, StringIds::status_town_population, &args); } // 0x00499079 @@ -392,6 +395,8 @@ namespace OpenLoco::Ui::Windows::Town // 0x004994F9 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -409,9 +414,9 @@ namespace OpenLoco::Ui::Windows::Town args.push(yTick); const uint16_t xPos = 39; - Gfx::drawRect(*clipped, xPos, yPos, 241, 1, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + drawingCtx.drawRect(*clipped, xPos, yPos, 241, 1, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); - Gfx::drawStringRight(*clipped, xPos, yPos - 6, Colour::black, StringIds::population_graph_people, &args); + drawingCtx.drawStringRight(*clipped, xPos, yPos - 6, Colour::black, StringIds::population_graph_people, &args); yTick += 1000; } @@ -433,10 +438,10 @@ namespace OpenLoco::Ui::Windows::Town auto args = FormatArguments(); args.push(year); - Gfx::drawStringCentred(*clipped, xPos, yPos, Colour::black, StringIds::population_graph_year, &args); + drawingCtx.drawStringCentred(*clipped, xPos, yPos, Colour::black, StringIds::population_graph_year, &args); } - Gfx::drawRect(*clipped, xPos, 11, 1, self.height - 66, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + drawingCtx.drawRect(*clipped, xPos, 11, 1, self.height - 66, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); } // Draw population graph @@ -445,7 +450,7 @@ namespace OpenLoco::Ui::Windows::Town // Do not draw current segment yet; it may be zeroed. if (i < town->historySize - 1) - Gfx::drawLine(*clipped, xPos, yPos1, xPos + 1, yPos2, Colours::getShade(self.getColour(WindowColour::secondary).c(), 7)); + drawingCtx.drawLine(*clipped, xPos, yPos1, xPos + 1, yPos2, Colours::getShade(self.getColour(WindowColour::secondary).c(), 7)); month--; if (month < 0) @@ -518,12 +523,14 @@ namespace OpenLoco::Ui::Windows::Town // 0x004997F1 static void draw(Window& self, Gfx::RenderTarget* rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); uint16_t xPos = self.x + 4; uint16_t yPos = self.y + 46; - Gfx::drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::local_authority_ratings_transport_companies); + drawingCtx.drawStringLeft(*rt, xPos, yPos, Colour::black, StringIds::local_authority_ratings_transport_companies); xPos += 4; yPos += 14; @@ -552,7 +559,7 @@ namespace OpenLoco::Ui::Windows::Town args.push(rating); args.push(rank); - Gfx::drawStringLeftClipped(*rt, xPos, yPos, self.width - 12, Colour::black, StringIds::town_rating_company_percentage_rank, &args); + drawingCtx.drawStringLeftClipped(*rt, xPos, yPos, self.width - 12, Colour::black, StringIds::town_rating_company_percentage_rank, &args); yPos += 10; } diff --git a/src/OpenLoco/src/Windows/Tutorial.cpp b/src/OpenLoco/src/Windows/Tutorial.cpp index 533bae8099..a7cf8ac611 100644 --- a/src/OpenLoco/src/Windows/Tutorial.cpp +++ b/src/OpenLoco/src/Windows/Tutorial.cpp @@ -1,4 +1,5 @@ #include "Tutorial.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Graphics/Colour.h" #include "Graphics/Gfx.h" #include "Localisation/FormatArguments.hpp" @@ -68,15 +69,17 @@ namespace OpenLoco::Ui::Windows::Tutorial StringIds::tutorial_3_title, }; + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto tutorialNumber = OpenLoco::Tutorial::getTutorialNumber(); auto args = FormatArguments::common(titleStringIds[tutorialNumber]); auto& widget = self.widgets[Widx::frame]; auto yPos = self.y + widget.top + 4; - Gfx::drawStringCentred(*rt, self.x + widget.midX(), yPos, Colour::black, StringIds::tutorial_text, &args); + drawingCtx.drawStringCentred(*rt, self.x + widget.midX(), yPos, Colour::black, StringIds::tutorial_text, &args); yPos += 10; - Gfx::drawStringCentred(*rt, self.x + widget.midX(), yPos, Colour::black, StringIds::tutorial_control, nullptr); + drawingCtx.drawStringCentred(*rt, self.x + widget.midX(), yPos, Colour::black, StringIds::tutorial_control, nullptr); } static void initEvents() diff --git a/src/OpenLoco/src/Windows/Vehicle.cpp b/src/OpenLoco/src/Windows/Vehicle.cpp index 269f351c49..1a2c261325 100644 --- a/src/OpenLoco/src/Windows/Vehicle.cpp +++ b/src/OpenLoco/src/Windows/Vehicle.cpp @@ -1,6 +1,7 @@ #include "Vehicles/Vehicle.h" #include "CompanyManager.h" #include "Config.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "GameCommands/GameCommands.h" #include "Graphics/Colour.h" @@ -913,6 +914,8 @@ namespace OpenLoco::Ui::Windows::Vehicle // 0x004B226D static void draw(Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -921,7 +924,7 @@ namespace OpenLoco::Ui::Windows::Vehicle { if ((pickupButton.image & 0x20000000) != 0 && !self.isDisabled(widx::pickup)) { - Gfx::drawImage( + drawingCtx.drawImage( rt, self.x + pickupButton.left, self.y + pickupButton.top, @@ -948,7 +951,7 @@ namespace OpenLoco::Ui::Windows::Vehicle strFormat = StringIds::black_stringid; } - Gfx::drawStringLeftClipped( + drawingCtx.drawStringLeftClipped( *rt, self.x + self.widgets[widx::status].left - 1, self.y + self.widgets[widx::status].top - 1, @@ -961,27 +964,27 @@ namespace OpenLoco::Ui::Windows::Vehicle Widget& speedWidget = self.widgets[widx::speedControl]; if (speedWidget.type != WidgetType::none) { - Gfx::drawImage( + drawingCtx.drawImage( rt, self.x + speedWidget.left, self.y + speedWidget.top + 10, Gfx::recolour(ImageIds::speed_control_track, self.getColour(WindowColour::secondary).c())); - Gfx::drawStringCentred( + drawingCtx.drawStringCentred( *rt, self.x + speedWidget.midX(), self.y + speedWidget.top + 4, Colour::black, StringIds::tiny_power); - Gfx::drawStringCentred( + drawingCtx.drawStringCentred( *rt, self.x + speedWidget.midX(), self.y + speedWidget.bottom - 10, Colour::black, StringIds::tiny_brake); - Gfx::drawImage( + drawingCtx.drawImage( rt, self.x + speedWidget.left + 1, self.y + speedWidget.top + 57 - veh->var_6E, @@ -1001,7 +1004,7 @@ namespace OpenLoco::Ui::Windows::Vehicle Widget& button = self.widgets[widx::viewport]; origin.x = self.x + button.midX(); origin.y = self.y + button.midY(); - Gfx::drawStringCentredWrapped( + drawingCtx.drawStringCentredWrapped( *rt, origin, button.width() - 6, @@ -1501,6 +1504,8 @@ namespace OpenLoco::Ui::Windows::Vehicle // 0x004B3542 static void draw(Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -1510,7 +1515,7 @@ namespace OpenLoco::Ui::Windows::Vehicle if ((self.widgets[widx::pickup].image & (1 << 29)) && !self.isDisabled(widx::pickup)) { auto image = Gfx::recolour(self.widgets[widx::pickup].image, CompanyManager::getCompanyColour(self.owner)); - Gfx::drawImage(rt, self.widgets[widx::pickup].left + self.x, self.widgets[widx::pickup].top + self.y, image); + drawingCtx.drawImage(rt, self.widgets[widx::pickup].left + self.x, self.widgets[widx::pickup].top + self.y, image); } } @@ -1531,7 +1536,7 @@ namespace OpenLoco::Ui::Windows::Vehicle { str = StringIds::vehicle_details_total_power_and_weight; } - Gfx::drawStringLeftClipped(*rt, pos.x, pos.y, self.width - 6, Colour::black, str, &args); + drawingCtx.drawStringLeftClipped(*rt, pos.x, pos.y, self.width - 6, Colour::black, str, &args); } { @@ -1545,7 +1550,7 @@ namespace OpenLoco::Ui::Windows::Vehicle { str = StringIds::vehicle_details_max_speed_and_rack_rail_and_reliability; } - Gfx::drawStringLeftClipped(*rt, pos.x, pos.y, self.width - 16, Colour::black, str, &args); + drawingCtx.drawStringLeftClipped(*rt, pos.x, pos.y, self.width - 16, Colour::black, str, &args); } { @@ -1559,14 +1564,16 @@ namespace OpenLoco::Ui::Windows::Vehicle str = StringIds::vehicle_car_count_and_length; args.push(head->getCarCount()); } - Gfx::drawStringLeftClipped(*rt, pos.x, pos.y, self.width - 16, Colour::black, str, &args); + drawingCtx.drawStringLeftClipped(*rt, pos.x, pos.y, self.width - 16, Colour::black, str, &args); } } // 0x004B36A3 static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t i) { - Gfx::clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); auto head = Common::getVehicle(&self); if (head == nullptr) { @@ -1589,7 +1596,7 @@ namespace OpenLoco::Ui::Windows::Vehicle top = pos.y - 1; carStr = StringIds::black_stringid; } - Gfx::fillRect(rt, 0, top, self.width, bottom, 0x2000030); + drawingCtx.fillRect(rt, 0, top, self.width, bottom, 0x2000030); } int16_t y = pos.y + (self.rowHeight - 22) / 2; @@ -1607,14 +1614,14 @@ namespace OpenLoco::Ui::Windows::Vehicle args.push(vehicleObj->name); x += 2; y = pos.y + (self.rowHeight / 2) - 6; - Gfx::drawStringLeft(rt, x, y, Colour::black, carStr, &args); + drawingCtx.drawStringLeft(rt, x, y, Colour::black, carStr, &args); pos.y += self.rowHeight; } if (EntityId(self.rowHover) == train.tail->id && _dragCarComponent != nullptr) { - Gfx::fillRect(rt, 0, pos.y - 1, self.width, pos.y, 0x2000030); + drawingCtx.fillRect(rt, 0, pos.y - 1, self.width, pos.y, 0x2000030); } } @@ -1825,6 +1832,8 @@ namespace OpenLoco::Ui::Windows::Vehicle // 004B3F0D static void draw(Ui::Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -1838,14 +1847,14 @@ namespace OpenLoco::Ui::Windows::Vehicle head->generateCargoTotalString(buffer); FormatArguments args = {}; args.push(StringIds::buffer_1250); - Gfx::drawStringLeftClipped(*rt, self.x + 3, self.y + self.height - 25, self.width - 15, Colour::black, StringIds::total_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, self.x + 3, self.y + self.height - 25, self.width - 15, Colour::black, StringIds::total_stringid, &args); // draw cargo capacity buffer = const_cast(StringManager::getString(StringIds::buffer_1250)); head->generateCargoCapacityString(buffer); args = {}; args.push(StringIds::buffer_1250); - Gfx::drawStringLeftClipped(*rt, self.x + 3, self.y + self.height - 13, self.width - 15, Colour::black, StringIds::vehicle_capacity_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, self.x + 3, self.y + self.height - 13, self.width - 15, Colour::black, StringIds::vehicle_capacity_stringid, &args); } // based on 0x004B40C7 @@ -1856,6 +1865,8 @@ namespace OpenLoco::Ui::Windows::Vehicle return; } + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + auto cargoObj = ObjectManager::get(cargoType); auto unitNameFormat = cargoQty == 1 ? cargoObj->unitNameSingular : cargoObj->unitNamePlural; auto station = StationManager::get(stationId); @@ -1865,14 +1876,16 @@ namespace OpenLoco::Ui::Windows::Vehicle args.push(cargoQty); args.push(station->name); args.push(station->town); - Gfx::drawStringLeft(rt, x, y, Colour::black, strFormat, &args); + drawingCtx.drawStringLeft(rt, x, y, Colour::black, strFormat, &args); y += 10; } // 004B3F62 static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t i) { - Gfx::clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); auto* head = Common::getVehicle(&self); if (head == nullptr) { @@ -1887,7 +1900,7 @@ namespace OpenLoco::Ui::Windows::Vehicle auto body = car.body; if (front->id == EntityId(self.rowHover)) { - Gfx::fillRect(rt, 0, y, self.width, y + self.rowHeight - 1, 0x2000030); + drawingCtx.fillRect(rt, 0, y, self.width, y + self.rowHeight - 1, 0x2000030); strFormat = StringIds::wcolour2_stringid; } // Get width of the drawing @@ -1912,7 +1925,7 @@ namespace OpenLoco::Ui::Windows::Vehicle { FormatArguments args{}; args.push(StringIds::cargo_empty); - Gfx::drawStringLeft(rt, width, cargoTextHeight + 5, Colour::black, strFormat, &args); + drawingCtx.drawStringLeft(rt, width, cargoTextHeight + 5, Colour::black, strFormat, &args); } } @@ -2209,6 +2222,8 @@ namespace OpenLoco::Ui::Windows::Vehicle // 0x004B576C static void draw(Ui::Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -2226,7 +2241,7 @@ namespace OpenLoco::Ui::Windows::Vehicle auto args = FormatArguments(); args.push(veh1->lastIncome.day); // Last income on: {DATE DMY} - Gfx::drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::last_income_on_date, &args); + drawingCtx.drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::last_income_on_date, &args); pos.y += 10; for (int i = 0; i < 4; i++) { @@ -2245,7 +2260,7 @@ namespace OpenLoco::Ui::Windows::Vehicle args.push(veh1->lastIncome.cargoAges[i]); args.push(veh1->lastIncome.cargoProfits[i]); // {STRINGID} transported {INT16} blocks in {INT16} days = {CURRENCY32} - Gfx::drawStringLeftWrapped(*rt, pos.x + 4, pos.y, self.width - 12, Colour::black, StringIds::transported_blocks_in_days, &args); + drawingCtx.drawStringLeftWrapped(*rt, pos.x + 4, pos.y, self.width - 12, Colour::black, StringIds::transported_blocks_in_days, &args); // TODO: fix function to take pointer to offset pos.y += 12; @@ -2254,7 +2269,7 @@ namespace OpenLoco::Ui::Windows::Vehicle else { // Last income: N/A" - Gfx::drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::last_income_na); + drawingCtx.drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::last_income_na); pos.y += 10; } @@ -2265,7 +2280,7 @@ namespace OpenLoco::Ui::Windows::Vehicle // Last journey average speed: {VELOCITY} auto args = FormatArguments(); args.push(head->lastAverageSpeed); - Gfx::drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::last_journey_average_speed, &args); + drawingCtx.drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::last_journey_average_speed, &args); pos.y += 10 + 5; } @@ -2273,7 +2288,7 @@ namespace OpenLoco::Ui::Windows::Vehicle // Monthly Running Cost: {CURRENCY32} auto args = FormatArguments(); args.push(head->calculateRunningCost()); - Gfx::drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::vehicle_monthly_running_cost, &args); + drawingCtx.drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::vehicle_monthly_running_cost, &args); pos.y += 10; } @@ -2282,7 +2297,7 @@ namespace OpenLoco::Ui::Windows::Vehicle auto args = FormatArguments(); auto monthlyProfit = (train.veh2->totalRecentProfit()) / 4; args.push(monthlyProfit); - Gfx::drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::vehicle_monthly_profit, &args); + drawingCtx.drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::vehicle_monthly_profit, &args); pos.y += 10 + 5; } @@ -2291,7 +2306,7 @@ namespace OpenLoco::Ui::Windows::Vehicle auto args = FormatArguments(); args.push(train.head->totalRefundCost); pos.y = self.y + self.height - 14; - Gfx::drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::sale_value_of_vehicle, &args); + drawingCtx.drawStringLeft(*rt, pos.x, pos.y, Colour::black, StringIds::sale_value_of_vehicle, &args); } } @@ -3066,6 +3081,8 @@ namespace OpenLoco::Ui::Windows::Vehicle // 0x004B4866 static void draw(Window& self, Gfx::RenderTarget* const rt) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + self.draw(rt); Common::drawTabs(&self, rt); @@ -3074,7 +3091,7 @@ namespace OpenLoco::Ui::Windows::Vehicle // Location at bottom left edge of window Ui::Point loc{ static_cast(self.x + 3), static_cast(self.y + self.height - 13) }; - Gfx::drawStringLeftClipped(*rt, loc.x, loc.y, self.width - 14, Colour::black, StringIds::route_click_on_waypoint); + drawingCtx.drawStringLeftClipped(*rt, loc.x, loc.y, self.width - 14, Colour::black, StringIds::route_click_on_waypoint); } } @@ -3160,14 +3177,16 @@ namespace OpenLoco::Ui::Windows::Vehicle // 0x004B4A58 based on static void sub_4B4A58(Window& self, Gfx::RenderTarget& rt, const string_id strFormat, FormatArguments& args, Vehicles::Order& order, int16_t& y) { + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + Ui::Point loc = { 8, static_cast(y - 1) }; - Gfx::drawStringLeft(rt, &loc, Colour::black, strFormat, &args); + drawingCtx.drawStringLeft(rt, &loc, Colour::black, strFormat, &args); if (order.hasFlag(Vehicles::OrderFlags::HasNumber)) { if (Input::isToolActive(self.type, self.number)) { auto imageId = kNumberCircle[_113646A - 1]; - Gfx::drawImage(&rt, loc.x + 3, loc.y + 1, Gfx::recolour(imageId, Colour::white)); + drawingCtx.drawImage(&rt, loc.x + 3, loc.y + 1, Gfx::recolour(imageId, Colour::white)); } _113646A++; } @@ -3176,7 +3195,9 @@ namespace OpenLoco::Ui::Windows::Vehicle // 0x004B48BA static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t i) { - Gfx::clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + + drawingCtx.clearSingle(rt, Colours::getShade(self.getColour(WindowColour::secondary).c(), 4)); auto head = Common::getVehicle(&self); if (head == nullptr) @@ -3188,7 +3209,7 @@ namespace OpenLoco::Ui::Windows::Vehicle auto rowNum = 0; if (head->sizeOfOrderTable == 1) { - Gfx::drawStringLeft(rt, 8, 0, Colour::black, StringIds::no_route_defined); + drawingCtx.drawStringLeft(rt, 8, 0, Colour::black, StringIds::no_route_defined); rowNum++; // Used to move down the text } @@ -3199,13 +3220,13 @@ namespace OpenLoco::Ui::Windows::Vehicle auto strFormat = StringIds::black_stringid; if (self.var_842 == rowNum) { - Gfx::fillRect(rt, 0, y, self.width, y + 9, enumValue(Colour::darkGreen)); + drawingCtx.fillRect(rt, 0, y, self.width, y + 9, enumValue(Colour::darkGreen)); strFormat = StringIds::white_stringid; } if (self.rowHover == rowNum) { strFormat = StringIds::wcolour2_stringid; - Gfx::fillRect(rt, 0, y, self.width, y + 9, 0x2000030); + drawingCtx.fillRect(rt, 0, y, self.width, y + 9, 0x2000030); } FormatArguments args{}; @@ -3236,7 +3257,7 @@ namespace OpenLoco::Ui::Windows::Vehicle sub_4B4A58(self, rt, strFormat, args, order, y); if (head->currentOrder + head->orderTableOffset == order.getOffset()) { - Gfx::drawStringLeft(rt, 1, y - 1, Colour::black, StringIds::orders_current_order); + drawingCtx.drawStringLeft(rt, 1, y - 1, Colour::black, StringIds::orders_current_order); } rowNum++; @@ -3247,18 +3268,18 @@ namespace OpenLoco::Ui::Windows::Vehicle auto strFormat = StringIds::black_stringid; if (self.var_842 == rowNum) { - Gfx::fillRect(rt, 0, loc.y, self.width, loc.y + lineHeight, enumValue(Colour::darkGreen)); + drawingCtx.fillRect(rt, 0, loc.y, self.width, loc.y + lineHeight, enumValue(Colour::darkGreen)); strFormat = StringIds::white_stringid; } if (self.rowHover == rowNum) { strFormat = StringIds::wcolour2_stringid; - Gfx::fillRect(rt, 0, loc.y, self.width, loc.y + lineHeight, 0x2000030); + drawingCtx.fillRect(rt, 0, loc.y, self.width, loc.y + lineHeight, 0x2000030); } loc.y -= 1; auto args = FormatArguments::common(orderString[0]); - Gfx::drawStringLeft(rt, &loc, Colour::black, strFormat, &args); + drawingCtx.drawStringLeft(rt, &loc, Colour::black, strFormat, &args); } static void initEvents() diff --git a/src/OpenLoco/src/Windows/VehicleList.cpp b/src/OpenLoco/src/Windows/VehicleList.cpp index d37a0ff4e7..d41a1d8789 100644 --- a/src/OpenLoco/src/Windows/VehicleList.cpp +++ b/src/OpenLoco/src/Windows/VehicleList.cpp @@ -1,5 +1,6 @@ #include "CompanyManager.h" #include "Date.h" +#include "Drawing/SoftwareDrawingEngine.h" #include "Entities/EntityManager.h" #include "Graphics/Colour.h" #include "Graphics/ImageIds.h" @@ -613,7 +614,8 @@ namespace OpenLoco::Ui::Windows::VehicleList uint32_t image = Gfx::recolour(competitorObj->images[company->ownerEmotion], company->mainColours.primary); uint16_t x = self.x + self.widgets[Widx::company_select].left + 1; uint16_t y = self.y + self.widgets[Widx::company_select].top + 1; - Gfx::drawImage(rt, x, y, image); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.drawImage(rt, x, y, image); static constexpr std::pair typeToFooterStringIds[]{ { StringIds::num_trains_singular, StringIds::num_trains_plural }, @@ -631,7 +633,7 @@ namespace OpenLoco::Ui::Windows::VehicleList string_id footerStringId = self.var_83C == 1 ? footerStringPair.first : footerStringPair.second; args = FormatArguments::common(footerStringId, self.var_83C); - Gfx::drawStringLeft(*rt, self.x + 3, self.y + self.height - 13, Colour::black, StringIds::black_stringid, &args); + drawingCtx.drawStringLeft(*rt, self.x + 3, self.y + self.height - 13, Colour::black, StringIds::black_stringid, &args); } static constexpr std::array typeToFilterStringIds{ @@ -645,7 +647,7 @@ namespace OpenLoco::Ui::Windows::VehicleList string_id filter = typeToFilterStringIds[self.var_88A]; args = FormatArguments::common(filter); auto* widget = &self.widgets[Widx::filter_type]; - Gfx::drawStringLeftClipped(*rt, self.x + widget->left + 1, self.y + widget->top, widget->width() - 15, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, self.x + widget->left + 1, self.y + widget->top, widget->width() - 15, Colour::black, StringIds::wcolour2_stringid, &args); } auto* widget = &self.widgets[Widx::cargo_type]; @@ -687,7 +689,7 @@ namespace OpenLoco::Ui::Windows::VehicleList if (filterActive) { // Draw filter text as prepared - Gfx::drawStringLeftClipped(*rt, xPos, self.y + widget->top, widget->width() - 15, Colour::black, StringIds::wcolour2_stringid, &args); + drawingCtx.drawStringLeftClipped(*rt, xPos, self.y + widget->top, widget->width() - 15, Colour::black, StringIds::wcolour2_stringid, &args); } } @@ -707,7 +709,8 @@ namespace OpenLoco::Ui::Windows::VehicleList static void drawScroll(Window& self, Gfx::RenderTarget& rt, const uint32_t scrollIndex) { auto shade = Colours::getShade(self.getColour(WindowColour::secondary).c(), 1); - Gfx::clearSingle(rt, shade); + auto drawingCtx = Gfx::getDrawingEngine().getDrawingContext(); + drawingCtx.clearSingle(rt, shade); auto yPos = 0; for (auto i = 0; i < self.var_83C; i++) @@ -728,7 +731,7 @@ namespace OpenLoco::Ui::Windows::VehicleList } // Highlight selection. if (head->id == EntityId(self.rowHover)) - Gfx::drawRect(rt, 0, yPos, self.width, self.rowHeight, Colours::getShade(self.getColour(WindowColour::secondary).c(), 0)); + drawingCtx.drawRect(rt, 0, yPos, self.width, self.rowHeight, Colours::getShade(self.getColour(WindowColour::secondary).c(), 0)); // Draw vehicle at the bottom of the row. drawVehicle(head, &rt, yPos + (self.rowHeight - 28) / 2 + 6); @@ -751,7 +754,7 @@ namespace OpenLoco::Ui::Windows::VehicleList // Draw status yPos += 2; - Gfx::drawStringLeftClipped(rt, 1, yPos, 308, AdvancedColour(Colour::black).outline(), format, &args); + drawingCtx.drawStringLeftClipped(rt, 1, yPos, 308, AdvancedColour(Colour::black).outline(), format, &args); } auto vehicle = Vehicles::Vehicle(*head); @@ -767,7 +770,7 @@ namespace OpenLoco::Ui::Windows::VehicleList } auto args = FormatArguments::common(profit); - Gfx::drawStringLeftClipped(rt, 310, yPos, 98, AdvancedColour(Colour::black).outline(), format, &args); + drawingCtx.drawStringLeftClipped(rt, 310, yPos, 98, AdvancedColour(Colour::black).outline(), format, &args); } // Vehicle age @@ -778,14 +781,14 @@ namespace OpenLoco::Ui::Windows::VehicleList format = StringIds::vehicle_list_age_year; auto args = FormatArguments::common(age); - Gfx::drawStringLeftClipped(rt, 410, yPos, 63, AdvancedColour(Colour::black).outline(), format, &args); + drawingCtx.drawStringLeftClipped(rt, 410, yPos, 63, AdvancedColour(Colour::black).outline(), format, &args); } // Vehicle reliability { int16_t reliability = vehicle.veh2->reliability; auto args = FormatArguments::common(reliability); - Gfx::drawStringLeftClipped(rt, 475, yPos, 65, AdvancedColour(Colour::black).outline(), StringIds::vehicle_list_reliability, &args); + drawingCtx.drawStringLeftClipped(rt, 475, yPos, 65, AdvancedColour(Colour::black).outline(), StringIds::vehicle_list_reliability, &args); } yPos += self.rowHeight - 2;