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

Function drawImage

src/OpenLoco/src/Ui/Widgets/ImageButtonWidget.cpp:11–66  ·  view source on GitHub ↗

0x004CADE8

Source from the content-addressed store, hash-verified

9{
10 // 0x004CADE8
11 static void drawImage(Gfx::DrawingContext& drawingCtx, const Widget& widget, const WidgetState& widgetState)
12 {
13 auto* window = widgetState.window;
14
15 const auto pos = window->position() + widget.position();
16
17 const bool isColourSet = widget.image & Widget::kImageIdColourSet;
18 ImageId imageId = ImageId::fromUInt32(widget.image & ~Widget::kImageIdColourSet);
19
20 auto colour = widgetState.colour;
21 if (widgetState.disabled)
22 {
23 // TODO: this is odd most likely this is another flag like Widget::kImageIdColourSet
24 if (imageId.hasSecondary())
25 {
26 return;
27 }
28
29 // No colour applied image
30 const auto pureImage = ImageId{ imageId.getIndex() };
31 uint8_t c;
32 if (colour.isTranslucent())
33 {
34 c = Colours::getShade(colour.c(), 4);
35 drawingCtx.drawImageSolid(pos + Ui::Point{ 1, 1 }, pureImage, c);
36 c = Colours::getShade(colour.c(), 2);
37 drawingCtx.drawImageSolid(pos, pureImage, c);
38 }
39 else
40 {
41 c = Colours::getShade(colour.c(), 6);
42 drawingCtx.drawImageSolid(pos + Ui::Point{ 1, 1 }, pureImage, c);
43 c = Colours::getShade(colour.c(), 4);
44 drawingCtx.drawImageSolid(pos, pureImage, c);
45 }
46
47 return;
48 }
49
50 if (!isColourSet && imageId.hasSecondary())
51 {
52 imageId = imageId.withSecondary(colour.c());
53 }
54
55 if (!isColourSet && imageId.hasPrimary())
56 {
57 imageId = imageId.withPrimary(colour.c());
58 }
59
60 if (!isColourSet)
61 {
62 imageId = ImageId::fromUInt32(Gfx::recolour(imageId.getIndex(), colour.c()));
63 }
64
65 drawingCtx.drawImage(pos, imageId);
66 }
67
68 static void draw_3(Gfx::DrawingContext& drawingCtx, const Widget& widget, const WidgetState& widgetState)

Callers 3

draw_3Function · 0.70
drawMethod · 0.70
drawImageMethod · 0.50

Calls 12

getShadeFunction · 0.85
recolourFunction · 0.85
hasSecondaryMethod · 0.80
cMethod · 0.80
drawImageSolidMethod · 0.80
withSecondaryMethod · 0.80
hasPrimaryMethod · 0.80
withPrimaryMethod · 0.80
positionMethod · 0.45
getIndexMethod · 0.45
isTranslucentMethod · 0.45
drawImageMethod · 0.45

Tested by

no test coverage detected