Example #1
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();
}