示例#1
0
void BrushTool::mouseMoveEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(mouse.isButtonDown(Qt::LeftButton)){
        hud->fill(Qt::transparent);

        QImage temp(layer->size(), layer->format());
        temp.fill(Qt::transparent);

        QPainter *painter = this->getPainter(&temp);

        if(m_brushSize->value() == 1)
            Tool::drawPerfectLine(painter, mouse.getPos(), m_last);
        else
            painter->drawLine(mouse.getPos(), m_last);

        delete painter;

        if(QVector2D(mouse.getPos() - m_last).lengthSquared() >= (m_brushSize->value() + 2) * m_brushSize->value()){
            m_last = mouse.getPos();

            this->drawInSelection(layer, &temp, selection, useSelection);
        }
        else{
            this->drawInSelection(hud, &temp, selection, useSelection);
        }
    }
}
示例#2
0
void Ellipse::process(Canvas &canvasMain, Canvas &canvasTemp,
    const MouseState &mouse, const PaintParameters &param)
{
    canvasTemp.clear();
    if (!m_leftClicked && mouse.isLeftPressed())
    {
        if (mouse.isOnCanvas())
        {
            m_ellipseStart = mouse.getPos();
            m_ellipseStart -= canvasMain.getPos();
            m_startOnCanvas = true;
        }
        else
        {
            m_startOnCanvas = false;
        }
    }
    else if (m_leftClicked && mouse.isLeftPressed() && m_startOnCanvas)
    {
        m_ellipseEnd = mouse.getPos();
        m_ellipseEnd -= canvasMain.getPos();
        drawEllipse(*canvasTemp.ptr(), m_ellipseStart, m_ellipseEnd, param);
    }
    else if (m_leftClicked && !mouse.isLeftPressed() && m_startOnCanvas)
    {
        drawEllipse(*canvasMain.ptr(), m_ellipseStart, m_ellipseEnd, param);
    }
    m_leftClicked = mouse.isLeftPressed();
}
void GradientTool::drawGradient(MouseState mouse, QImage *image, QColor from, QColor to)
{
    QPainter painter(image);

    QPoint gradVec = mouse.getPos() -  mouse.getClickedAt();
    float length = std::sqrt(gradVec.x() * gradVec.x() + gradVec.y() * gradVec.y());
    float vecX = gradVec.x() / length;
    float vecY = gradVec.y() / length;
    qsrand(0);

    for(int i(0); i < image->width(); ++i){
        for(int j(0); j < image->height(); ++j){
            QPoint point = QPoint(i, j) - mouse.getClickedAt();
            float val = (float)(point.x() * vecX + point.y() * vecY) / length;

            val = std::min(1.f, std::max(0.f, val));

            if(m_dithering->isChecked()){
                painter.setPen(QPen(m_brushes[(int) round(val * std::pow(2, m_ditheringLevel->value() -1)) * std::pow(2, 5-m_ditheringLevel->value())], 1));
            }
            else{
                if(qrand() %128 < val *128)
                    painter.setPen(QPen(to));
                else
                    painter.setPen(QPen(from));
            }

            painter.drawPoint(i, j);
        }
    }
}
void SelectionTool::mouseMoveEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(m_moving){
        hud->fill(Qt::transparent);

        QPainter painter(hud);
        painter.setOpacity(.6);
        painter.drawImage(mouse.delta(), m_movingSelection);
    }
    else if(m_drawing){
        hud->fill(Qt::transparent);

        QPixmap temp(hud->size());
        temp.fill(Qt::transparent);

        QPainter painter(&temp);
        painter.setPen(Qt::NoPen);
        painter.setBrush(QBrush(GREEN_SELECTION));

        this->paintSelection(mouse, &painter);

        painter.end();
        painter.begin(hud);
        painter.setOpacity(.6);
        painter.drawPixmap(0, 0, temp);
    }
    else{
        if(*useSelection && m_selectionMode == "only" && QColor(selection->pixel(mouse.getPos())) == Qt::white)
            this->setCursor(Selection);
        else
            this->setCorrectCursor();
    }
}
示例#5
0
void BrushTool::mouseReleaseEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(mouse.button() == Qt::LeftButton){
        hud->fill(Qt::transparent);

        QImage temp(layer->size(), layer->format());
        temp.fill(Qt::transparent);

        QPainter *painter = this->getPainter(&temp);

        if(m_brushSize->value() == 1)
            Tool::drawPerfectLine(painter, mouse.getPos(), m_last);
        else
            painter->drawLine(mouse.getPos(), m_last);

        delete painter;

        this->drawInSelection(layer, &temp, selection, useSelection);
    }
}
void SelectionTool::mousePressEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(*useSelection && m_selectionMode == "only" && QColor(selection->pixel(mouse.getPos())) == Qt::white){
        m_moving = true;

        m_movingSelection = QImage(layer->size(), layer->format());
        m_movingSelection.fill(GREEN_SELECTION);
        QPainter painter(&m_movingSelection);
        painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        painter.drawImage(0, 0, *selection);
    }
    else if(mouse.button() == Qt::LeftButton){
        m_drawing = true;
        m_noKeyReleased = true;
        m_keysDown.remove(Qt::Key_Shift);
        m_keysDown.remove(Qt::Key_Alt);
    }
}
示例#7
0
void BrushTool::mousePressEvent(MouseState mouse, QImage *layer, QImage *hud, QImage *selection, bool *useSelection)
{
    if(mouse.button() == Qt::LeftButton){
        m_last = mouse.getPos();
    }
}