void ScatteredLineBrush::BrushBegin(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	int size = pDoc->getSize();
	int width = pDoc->getWidth();

	glPointSize((float)size);
	glLineWidth((float)width);

	BrushMove(source, target);
}
void ScatteredLineBrush::BrushMove(const Point source, const Point target)
{
	ImpressionistDoc* pDoc = GetDocument();
	ImpressionistUI* dlg = pDoc->m_pUI;

	if (pDoc == NULL) {
		printf("LineBrush::BrushMove  document is NULL\n");
		return;
	}

	const int size = pDoc->getSize();
	const float half_size = size / 2.0f;
	const int width = pDoc->getWidth();
	const int angle = pDoc->getAngle();
	const float half_line_width = width / 2.0f;
	float alpha = pDoc->getAlpha();
	float x, y;

	//glBegin(GL_POINTS);
	for (int i = 0; i < 3; i++)
	{

		x = target.x - size / 2 + irand(size);
		y = target.y - size / 2 + irand(size);

		Point random = Point(x, y);
		glPushMatrix();
		glTranslatef(random.x, random.y, 0.0f);
		glRotatef(angle, 0, 0, 1.0f);

		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glBegin(GL_LINES);
		SetColor(random, alpha);
		glVertex2f(-half_size, 0);
		glVertex2f(half_size, 0);
		glEnd();

		glPopMatrix();
		
	}
}
Ejemplo n.º 3
0
void LineBrush::BrushMove( const Point source, const Point target , int brushsize)
{
    ImpressionistDoc* pDoc = GetDocument();
    ImpressionistUI* dlg=pDoc->m_pUI;

    if ( pDoc == NULL ) {
        printf( "PointBrush::BrushMove  document is NULL\n" );
        return;
    }

    int half_size;
    glGetIntegerv(GL_POINT_SIZE, &half_size);
    half_size /= 2;

    // dirty patch
    if (brushsize > 0) {
        glPointSize(brushsize);
        half_size = brushsize / 2;
        if (half_size == 0) half_size = 1;
    } else {
        // then it's normal paint
        // should set color according to original
        SetColor( source );
    }

    int width = ceil(pDoc->getWidth() / 2.0); //make sure it works when width is 1
    int angle = pDoc->getAngle();

    float m_sin = sin(2.0f * M_PI * angle / 360);
    float m_cos = cos(2.0f * M_PI * angle / 360);

    float depth = dlg->m_paintView->current_depth;

    glBegin( GL_POLYGON );

    if (pDoc->m_pUI->m_EdgeClipButton->value())
    {
        int nLength;
        int pLength;
        for (nLength = 0; nLength <= half_size; nLength++)
        {
            if (pDoc->isEdge(target.x - (int)(nLength * m_cos), target.y - (int)(nLength * m_sin)))
            {
                break;
            }
        }

        for (pLength = 0; pLength <= half_size; pLength++)
        {
            if (pDoc->isEdge(target.x + (int)(pLength * m_cos), target.y + (int)(pLength * m_sin)))
            {
                break;
            }
        }

        glVertex2d( target.x - nLength * m_cos - width * m_sin, target.y - nLength * m_sin + width * m_cos);
        glVertex2d( target.x + pLength * m_cos - width * m_sin, target.y + pLength * m_sin + width * m_cos);
        glVertex2d( target.x + pLength * m_cos + width * m_sin, target.y + pLength * m_sin - width * m_cos);
        glVertex2d( target.x - nLength * m_cos + width * m_sin, target.y - nLength * m_sin - width * m_cos);
    }
    else
    {
        glVertex2d( target.x - half_size * m_cos - width * m_sin, target.y - half_size * m_sin + width * m_cos);
        glVertex2d( target.x + half_size * m_cos - width * m_sin, target.y + half_size * m_sin + width * m_cos);
        glVertex2d( target.x + half_size * m_cos + width * m_sin, target.y + half_size * m_sin - width * m_cos);
        glVertex2d( target.x - half_size * m_cos + width * m_sin, target.y - half_size * m_sin - width * m_cos);
    }

    glEnd();
}