我要在TouchGFX中创建一个波形窗口小部件,但不确定如何最好地在最后将波形循环回零,因为有三个帧缓冲区,因此您必须使区域无效3次,否则会闪烁。您将如何处理将数组循环回开始(x = 0)。
主要问题是我的代码最初假定只有一个帧缓冲区。我认为我的代码需要针对三个帧缓冲区进行重构,或者添加直接写入帧缓冲区的功能。任何提示将不胜感激。
bool Graph::drawCanvasWidget(const Rect& invalidatedArea) const
{
if (numPoints < 3)
{
// A graph line with a single (or not even a single) point is invisible
return true;
}
else{
Canvas canvas(this, invalidatedArea);
for (int index = 0; index < (numPoints-1); index++)
{
canvas.moveTo(points[index].x,points[index].y);
canvas.lineTo(points[index].x,points[index+1].y);
canvas.lineTo(points[index+1].x,points[index+1].y);
canvas.lineTo(points[index+1].x,points[index].y);
}
return canvas.render(); // Shape above automatically closed
}
return true;
}
void Graph::newPoint(int y)
{
if(numPoints==501){
numPoints=0;
}else if ((maxPoints-numPoints)<=20){
points[numPoints].x = numPoints;
points[numPoints].y = y;
Rect minimalRect(480,0,20,100);
invalidateRect(minimalRect);
numPoints++;
}else{
points[numPoints].x = numPoints;
points[numPoints].y = y;
Rect minimalRect(numPoints-3,0,20,100);
invalidateRect(minimalRect);
numPoints++;
}
}
答案 0 :(得分:0)
有了TouchGFX 4.15.0(刚刚推出),TouchGFX Designer现在支持一个Graph小部件(以前只能在演示的源代码中找到),可用于生成波形。它有一些更优雅的插入点的方式,可能会满足您的需求。