Esempio n. 1
0
void SCgContour::updateShape()
{
    prepareGeometryChange();

    mShape = QPainterPath();

    // Generate control points to be used for path drawing
    PointFVector points;
    quint32 pointsSize = mPoints.size();
    for (quint32 i = 0; i < pointsSize; i++)
    {
        QPointF p2 = mPoints[(i + 1) % pointsSize];
        QPointF p1 = mPoints[i];

        QVector2D dir(p2 - p1);

        // In case two points are placed close to each other
        // we need to adjust corner radius.
        qreal cornerRadiusAdjusted = cornerRadius;
        qreal dirLength = dir.length();
        if(dirLength < cornerRadius * 2)
            cornerRadiusAdjusted = dirLength / 2;

        dir.normalize();
        QPointF dv = dir.toPointF() * cornerRadiusAdjusted;

        points.push_back(p1);
        points.push_back(p1 + dv);
        points.push_back(p2 - dv);
    }

    // Draw path using generated points
    quint32 psz3 = pointsSize * 3;
    for (quint32 i = 0; i < psz3; i += 3)
    {
        if (i == 0)
            mShape.moveTo(points[i + 1]);
        mShape.lineTo(points[i + 2]);
        mShape.quadTo(points[(i + 3) % psz3], points[(i + 4) % psz3]);
    }
    mShape.closeSubpath();

    mShapeNormal = mShape;

    QPainterPathStroker path_stroker;
    path_stroker.setWidth(SCgAlphabet::lineWidthForShape() + 2);
    mShape = path_stroker.createStroke(mShape);

    mLineShape = mShape;

    mShape = mShapeNormal.united(mShape);

    updateConnected();

    update();
}
Esempio n. 2
0
void SCgContour::updateShape()
{
    prepareGeometryChange();

    mShape = QPainterPath();

    PointFVector points;
    quint32 pointsSize = mPoints.size();
    for (quint32 i = 0; i < pointsSize; i++)
    {
        QPointF p2 = mPoints[(i + 1) % pointsSize];
        QPointF p1 = mPoints[i];
        QVector2D dir(p2 - p1);
        dir.normalize();

        QPointF dv = dir.toPointF() * CONTOUR_CORNER_RADIUS;
        points.push_back(p1);
        points.push_back(p1 + dv);
        points.push_back(p2 - dv);
    }

    // draw path
    quint32 psz3 = pointsSize * 3;
    for (quint32 i = 0; i < pointsSize; i++)
    {
        quint32 idx = i * 3;

        if (i == 0)
            mShape.moveTo(points[idx + 1]);
        mShape.lineTo(points[idx + 2]);
        mShape.quadTo(points[(idx + 3) % psz3], points[(idx + 4) % psz3]);
    }
    mShape.closeSubpath();

    mShapeNormal = mShape;
    QPainterPathStroker path_stroker;
    //path_stroker.setJoinStyle(Qt::MiterJoin);
    path_stroker.setWidth(SCgAlphabet::lineWidthForShape() + 2);
    mShape = path_stroker.createStroke(mShape);

    mLineShape = mShape;

    mShape = mShapeNormal.united(mShape);

    updateConnected();

    update();
}
Esempio n. 3
0
void CAggMemoryDC::Lines(
    const PointFVector& pts,
    const Color& clr,
    const REAL width/*=1.0*/)
{
    if (m_buf==0)
        return;

    unsigned count=pts.size()/2;
    ATLASSERT(count>0);
    ATLASSERT((float)count/2.0f>0);

    pixel_format pixf(m_rbuf);
    ren_base renb(pixf);
    solid_renderer ren_solid(renb);

    m_path.remove_all();

    for(unsigned i=0; i<count; ++i)
    {
        m_path.move_to(pts[i*2].x, pts[i*2].y);
        m_path.line_to(pts[i*2+1].x, pts[i*2+1].y);
    }

    typedef agg::conv_stroke<conv_path_trans_type> conv_stroke_outline;
    conv_stroke_outline stroke(m_transpath);
    stroke.width(width);

    m_ras_aa.add_path(stroke);

    ren_solid.color(agg::rgba8(clr.GetR(), clr.GetG(), clr.GetB(), clr.GetA()));
    agg::render_scanlines(m_ras_aa, m_sl, ren_solid);
}
Esempio n. 4
0
void SCgContour::setPoints(const PointFVector &points)
{
    if (points.size() < 3)
        return;

    SCgPointObject::setPoints(points);
}