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

Function graphDrawAxesAndLabels

src/OpenLoco/src/Ui/Chart.cpp:67–183  ·  view source on GitHub ↗

0x004CFA49

Source from the content-addressed store, hash-verified

65
66 // 0x004CFA49
67 static void graphDrawAxesAndLabels(const GraphSettings& gs, Window& self, Gfx::DrawingContext& drawingCtx)
68 {
69 auto xAxisLabelValue = gs.xAxisRange;
70 if ((gs.flags & GraphFlags::dataFrontToBack) != GraphFlags::none)
71 {
72 xAxisLabelValue -= (gs.dataEnd - 1) * gs.xAxisStepSize;
73 }
74
75 // 0x004CFA74
76 for (auto xTickPos = 0U; xTickPos < gs.dataEnd; xTickPos++)
77 {
78 auto remainder = xAxisLabelValue % gs.xAxisLabelIncrement;
79
80 // Draw vertical lines for each of the data points
81 {
82 auto xPos = xTickPos * gs.xAxisTickIncrement + gs.left + gs.xOffset;
83 auto height = gs.canvasHeight + (remainder == 0 ? 3 : 0);
84
85 auto colour = self.getColour(WindowColour::secondary).c();
86 auto paletteIndex = Colours::getShade(colour, remainder == 0 ? 6 : 4);
87
88 drawingCtx.drawRect(xPos, gs.top, 1, height, paletteIndex, Gfx::RectFlags::none);
89 }
90
91 // No remainder means we get to draw a label on the horizontal axis, too
92 if (remainder == 0)
93 {
94 int16_t xPos = xTickPos * gs.xAxisTickIncrement + gs.left + gs.xOffset;
95 int16_t yPos = gs.canvasBottom + 5;
96
97 auto tr = Gfx::TextRenderer(drawingCtx);
98 auto formatArgs = FormatArguments{};
99 formatArgs.push(gs.xLabel);
100 formatArgs.push(xAxisLabelValue);
101
102 tr.drawStringCentred({ xPos, yPos }, Colour::black, StringIds::graph_label_format, formatArgs);
103 }
104
105 xAxisLabelValue += gs.xAxisStepSize;
106 }
107
108 // 0x004CFB5C
109 auto yAxisPos = 0;
110 while (true)
111 {
112 // Draw horizontal lines for each of the vertical axis labels
113 {
114 auto colour = self.getColour(WindowColour::secondary).c();
115 auto paletteIndex = Colours::getShade(colour, 6);
116
117 auto xPos = gs.left + gs.xOffset - 2;
118 auto width = gs.width - gs.xOffset + 3;
119 auto yPos = -yAxisPos + gs.canvasHeight + gs.top;
120 if ((gs.flags & GraphFlags::showNegativeValues) != GraphFlags::none)
121 {
122 yPos -= gs.canvasHeight / 2;
123 }
124

Callers 1

drawGraphFunction · 0.85

Calls 8

getShadeFunction · 0.85
TextRendererClass · 0.85
cMethod · 0.80
getColourMethod · 0.80
drawStringCentredMethod · 0.80
drawStringRightMethod · 0.80
drawRectMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected