Beispiel #1
0
/**
 * This function is optimized for drawing with subpixel precision.
 * @param brush brush to draw the line with
 * @param from starting point
 * @param to ending point
 * @param distance distance from previous dab.
 */
void Layer::drawSoftLine(const Brush& brush, const BrushMaskGenerator &mask, const Point& from, const Point& to, qreal &distance)
{
	qreal dx = to.x() - from.x();
	qreal dy = to.y() - from.y();
	const qreal dist = hypot(dx, dy);
	dx = dx / dist;
	dy = dy / dist;
	const qreal dp = (to.pressure() - from.pressure()) / dist;

	const qreal spacing0 = qMax(1.0, brush.spacingDist(from.pressure()));
	qreal i;
	if(distance>=spacing0)
		i = 0;
	else if(distance==0)
		i = spacing0;
	else
		i = distance;

	Point p(from.x() + dx*i, from.y() + dy*i, qBound(0.0, from.pressure() + dp*i, 1.0));

	while(i<=dist) {
		const qreal spacing = qMax(1.0, brush.spacingDist(p.pressure()));
		directDab(brush, mask, p);
		p.rx() += dx * spacing;
		p.ry() += dy * spacing;
		p.setPressure(qBound(0.0, p.pressure() + dp * spacing, 1.0));
		i += spacing;
	}
	distance = i-dist;
}
Beispiel #2
0
/**
 * This line drawing function is optimized for drawing with no subpixel
 * precision.
 * The last point is not drawn, so successive lines can be drawn blotches.
 */
void Layer::drawHardLine(const Brush &brush, const Point& from, const Point& to, StrokeState &state) {
    const qreal dp = (to.pressure()-from.pressure()) / hypot(to.x()-from.x(), to.y()-from.y());

    int x0 = qFloor(from.x());
    int y0 = qFloor(from.y());
    qreal p = from.pressure();
    int x1 = qFloor(to.x());
    int y1 = qFloor(to.y());
    int dy = y1 - y0;
    int dx = x1 - x0;
    int stepx, stepy;

    if (dy < 0) {
        dy = -dy;
        stepy = -1;
    } else {
        stepy = 1;
    }
    if (dx < 0) {
        dx = -dx;
        stepx = -1;
    } else {
        stepx = 1;
    }

    dy *= 2;
    dx *= 2;

    qreal distance = state.distance;

    if (dx > dy) {
        int fraction = dy - (dx >> 1);
        while (x0 != x1) {
            const qreal spacing = brush.spacingDist(p);
            if (fraction >= 0) {
                y0 += stepy;
                fraction -= dx;
            }
            x0 += stepx;
            fraction += dy;
            if(++distance >= spacing) {
                directDab(brush, Point(x0, y0, p), state);
                distance = 0;
            }
            p += dp;
        }
    } else {