1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
30
31
32
33
34
35
40
41
46
63
64
65
66
67
68
69
70
71
72
77
78
79
80
81
/* ... */
#include <gui/graph_screen/GraphLine.hpp>
using namespace touchgfx;
bool GraphLine::drawCanvasWidget(const Rect& invalidatedArea) const
{
if (numPoints < 2)
{
return true;
}if (numPoints < 2) { ... }
int firstIndex = 0;
int lastIndex = numPoints - 1;
while (firstIndex < lastIndex &&
invalidatedArea.x > (widgetXindex(firstIndex + 1) + lineWidth / 2).to<int>())
{
firstIndex++;
}while (firstIndex < lastIndex && invalidatedArea.x > (widgetXindex(firstIndex + 1) + lineWidth / 2).to()) { ... }
while (lastIndex > firstIndex &&
invalidatedArea.right() < (widgetXindex(lastIndex - 1) - lineWidth / 2).to<int>())
{
lastIndex--;
}while (lastIndex > firstIndex && invalidatedArea.right() < (widgetXindex(lastIndex - 1) - lineWidth / 2).to()) { ... }
if (firstIndex < lastIndex)
{
Canvas canvas(this, invalidatedArea);
canvas.moveTo(xAboveOutgoing(firstIndex), yAboveOutgoing(firstIndex));
canvas.lineTo(xAboveIncoming(firstIndex + 1), yAboveIncoming(firstIndex + 1));
for (int index = firstIndex + 1; index < lastIndex; index++)
{
canvas.lineTo(xAboveOutgoing(index), yAboveOutgoing(index));
canvas.lineTo(xAboveIncoming(index + 1), yAboveIncoming(index + 1));
}for (int index = firstIndex + 1; index < lastIndex; index++) { ... }
for (int index = lastIndex - 1; index >= firstIndex; index--)
{
canvas.lineTo(xBelowIncoming(index + 1), yBelowIncoming(index + 1));
canvas.lineTo(xBelowOutgoing(index), yBelowOutgoing(index));
}for (int index = lastIndex - 1; index >= firstIndex; index--) { ... }
return canvas.render();
}if (firstIndex < lastIndex) { ... }
return true;
...}
Rect GraphLine::getMinimalRectContainingIndices(int firstIndex, int lastIndex) const
{
int minX = (widgetXindex(firstIndex) - lineWidth / 2).to<int>();
int maxX = (widgetXindex(lastIndex) + lineWidth / 2).to<int>();
int minY = (widgetYindex(firstIndex) - lineWidth / 2).to<int>();
int maxY = (widgetYindex(firstIndex) + lineWidth / 2).to<int>();
for (int index = firstIndex + 1; index <= lastIndex; index++)
{
minY = MIN(minY, (widgetYindex(index) - lineWidth / 2).to<int>());
maxY = MAX(maxY, (widgetYindex(index) + lineWidth / 2).to<int>());
}for (int index = firstIndex + 1; index <= lastIndex; index++) { ... }
Rect minimalRect = Rect(minX, minY, maxX - minX + 1, maxY - minY + 1);
return minimalRect;
...}