MCPcopy Create free account
hub / github.com/GlobedGD/globed2 / refreshGraph

Method refreshGraph

src/modules/scripting-ui/ui/ScriptLogPanelPopup.cpp:118–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118void ScriptLogPanelPopup::refreshGraph(const std::deque<std::pair<asp::time::SystemTime, float>>& queue) {
119 m_drawNode->clear();
120
121 CCSize chartSize { GRAPH_SIZE.width - 20.f, GRAPH_SIZE.height - 20.f };
122 CCPoint chartBase = { 10.f, 10.f };
123
124 // draw grid
125
126 bool addLabels = m_graphLabelsNode->getChildrenCount() == 0;
127
128 // horizontal lines
129 for (size_t i = 0; i <= 10; i++) {
130 float ygap = chartSize.height / 10;
131 float y = chartBase.y + ygap * i;
132
133 m_drawNode->drawSegment(
134 { chartBase.x, y },
135 { chartBase.x + chartSize.width, y },
136 0.5f,
137 ccColor4F {0.5f, 0.5f, 0.5f, 0.35f}
138 );
139
140 if (addLabels && i > 0) {
141 // add labels
142 Build<CCLabelBMFont>::create(fmt::format("{}%", i * 10).c_str(), "bigFont.fnt")
143 .scale(0.3f)
144 .anchorPoint(1.f, 0.5f)
145 .pos(chartBase.x - 4.f, y)
146 .parent(m_graphLabelsNode);
147 }
148 }
149
150 // outline
151 m_drawNode->drawRect(
152 chartBase - CCSize{2.f, 0.f},
153 chartBase + chartSize + CCSize{2.f, 0.f}, { 0.f, 0.f, 0.f, 0.f }, 1.0f, { 0.9f, 0.9f, 0.9f, 1.0f }
154 );
155
156 // draw the chart itself
157
158 if (queue.size() < 2) return;
159
160 std::vector<CCPoint> segments;
161
162 size_t i = 0;
163 for (auto [time, perc] : queue) {
164 perc = std::round(std::clamp(perc * 100.f, 0.f, 100.f)) / 100.f;
165
166 float y = chartBase.y + chartSize.height * perc;
167
168 float xgap = chartSize.width / (float)(queue.size() - 1);
169 float x = chartBase.x + xgap * i;
170
171 segments.push_back(CCPoint { x, y });
172
173 i++;
174 }
175

Callers 1

refreshMethod · 0.95

Calls 2

clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected