MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / drawBackground

Method drawBackground

src/OpenLoco/src/Ui/Widgets/FrameWidget.cpp:73–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71 }
72
73 void Frame::drawBackground(Gfx::DrawingContext& drawingCtx, const Widget& widget, const WidgetState& widgetState)
74 {
75 const auto* window = widgetState.window;
76 const auto pos = window->position() + widget.position();
77 const auto size = widget.size();
78
79 const auto& rt = drawingCtx.currentRenderTarget();
80 const auto clipped = Gfx::clipRenderTarget(rt, Ui::Rect(pos.x, pos.y, size.width, 41));
81 if (clipped)
82 {
83 uint32_t imageId = widget.image;
84 if (window->hasFlags(WindowFlags::lighterFrame))
85 {
86 imageId = Gfx::recolour(ImageIds::frame_background_image, widgetState.colour.c());
87 }
88 else
89 {
90 imageId = Gfx::recolour(ImageIds::frame_background_image_alt, widgetState.colour.c());
91 }
92
93 drawingCtx.pushRenderTarget(*clipped);
94
95 // Derive the number of background images to paint
96 const auto backgroundImageWidth = Gfx::getG1Element(imageId)->width;
97 const auto numPassesNeeded = (widget.width() + backgroundImageWidth - 1) / backgroundImageWidth;
98
99 // Draw background image repeatedly to account for large windows
100 // NB: starting on the right side to counter the border on the left side of the sprite
101 for (auto i = numPassesNeeded; i >= 0; i--)
102 {
103 drawingCtx.drawImage(i * (backgroundImageWidth - 1), 0, imageId);
104 }
105
106 drawingCtx.popRenderTarget();
107 }
108 }
109
110 void Frame::drawSolid(Gfx::DrawingContext& drawingCtx, const Widget& widget, const WidgetState& widgetState)
111 {

Callers

nothing calls this directly

Calls 12

clipRenderTargetFunction · 0.85
RectClass · 0.85
recolourFunction · 0.85
getG1ElementFunction · 0.85
cMethod · 0.80
pushRenderTargetMethod · 0.80
popRenderTargetMethod · 0.80
positionMethod · 0.45
sizeMethod · 0.45
hasFlagsMethod · 0.45
widthMethod · 0.45
drawImageMethod · 0.45

Tested by

no test coverage detected