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

Function drawSimple

src/OpenLoco/src/Ui/Widgets/CaptionWidget.cpp:53–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 }
52
53 static void drawSimple(Gfx::DrawingContext& drawingCtx, const Widget& widget, const WidgetState& widgetState, const Caption::Style captionStyle)
54 {
55 auto formatArgs = FormatArguments(widget.textArgs);
56
57 char stringBuffer[512];
58 if (captionStyle == Caption::Style::blackText)
59 {
60 stringBuffer[0] = ControlCodes::Colour::black;
61 }
62 else if (captionStyle == Caption::Style::colourText)
63 {
64 stringBuffer[0] = ControlCodes::windowColour1;
65 }
66 else if (captionStyle == Caption::Style::whiteText)
67 {
68 stringBuffer[0] = ControlCodes::Colour::white;
69 }
70 else
71 {
72 assert(false);
73 }
74
75 StringManager::formatString(&stringBuffer[1], widget.text, formatArgs);
76
77 auto* window = widgetState.window;
78
79 const auto pos = window->position() + widget.position();
80 const auto size = widget.size();
81
82 const auto width = size.width - 4 - 14;
83
84 auto stationNamePos = pos + Ui::Point(2 + (width / 2), 1);
85
86 auto tr = Gfx::TextRenderer(drawingCtx);
87 tr.setCurrentFont(Gfx::Font::medium_bold);
88
89 int16_t stringWidth = tr.clipString(width - 8, stringBuffer);
90 stationNamePos.x -= (stringWidth - 1) / 2;
91
92 if (captionStyle == Caption::Style::blackText)
93 {
94 drawStationNameBackground(drawingCtx, stationNamePos, widgetState.colour, stringWidth);
95 }
96
97 auto textPos = stationNamePos;
98 tr.drawString(textPos, AdvancedColour(Colour::black).outline(), stringBuffer);
99 }
100
101 void Caption::draw(Gfx::DrawingContext& drawingCtx, const Widget& widget, const WidgetState& widgetState)
102 {

Callers 1

drawMethod · 0.85

Calls 11

formatStringFunction · 0.85
TextRendererClass · 0.85
setCurrentFontMethod · 0.80
clipStringMethod · 0.80
drawStringMethod · 0.80
outlineMethod · 0.80
FormatArgumentsClass · 0.50
AdvancedColourClass · 0.50
positionMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected