-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcurvenode.cpp
More file actions
51 lines (43 loc) · 1.32 KB
/
curvenode.cpp
File metadata and controls
51 lines (43 loc) · 1.32 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "curvenode.hpp"
#include "curve.hpp"
#include "scalemap.hpp"
CurveNode::CurveNode()
: m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0)
{
m_geometry.setDrawingMode(GL_LINE_STRIP);
m_material.setColor(Qt::red);
setMaterial(&m_material);
setGeometry(&m_geometry);
}
QColor CurveNode::color() const
{
return m_material.color();
}
void CurveNode::setColor(const QColor &color)
{
if (color != m_material.color()) {
m_material.setColor(color);
markDirty(QSGNode::DirtyMaterial);
}
}
void CurveNode::updateFromCurve(Curve* curve, const QPainterPath& path)
{
ScaleMap* xScaleMap = curve->xScaleMap();
ScaleMap* yScaleMap = curve->yScaleMap();
if (!xScaleMap || !yScaleMap)
{
m_geometry.allocate(0);
markDirty(QSGNode::DirtyGeometry);
return;
}
double height = curve->height();
m_geometry.allocate(path.elementCount());
QSGGeometry::Point2D* vertex = m_geometry.vertexDataAsPoint2D();
for (int i = 0; i < m_geometry.vertexCount(); ++i)
{
const QPainterPath::Element& element = path.elementAt(i);
vertex[i].x = xScaleMap->mapToPixel(element.x);
vertex[i].y = height - yScaleMap->mapToPixel(element.y); // y = 0 is at the top, so we subtract from the height
}
markDirty(QSGNode::DirtyGeometry);
}