Skip to content

Commit

Permalink
Merge pull request #767 from CandyFace/Fill/vector-stuff
Browse files Browse the repository at this point in the history
Vector fill and more
  • Loading branch information
chchwy committed Oct 17, 2017
2 parents 8fd5081 + d17d4a2 commit c826529
Show file tree
Hide file tree
Showing 19 changed files with 1,172 additions and 503 deletions.
22 changes: 20 additions & 2 deletions app/tooloptionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ void ToolOptionWidget::createUI()
pLayout->addWidget( mMakeInvisibleBox, 8, 0, 1, 2 );
pLayout->addWidget( mVectorMergeBox, 9, 0, 1, 2 );
pLayout->addWidget( mInpolLevelsBox, 10, 0, 1, 4);
pLayout->addWidget( mToleranceSlider, 1, 0, 1, 2);
pLayout->addWidget( mToleranceSpinBox, 1, 2, 1, 2);
pLayout->addWidget( mToleranceSlider, 2, 0, 1, 2);
pLayout->addWidget( mToleranceSpinBox, 2, 2, 1, 2);
pLayout->addWidget( mFillContour, 1, 0, 1, 2);

pLayout->setRowStretch( 17, 1 );
Expand Down Expand Up @@ -311,12 +311,26 @@ void ToolOptionWidget::visibilityOnLayer()
{
switch (propertyType)
{
case SMUDGE:
mSizeSlider->setVisible(false);
mBrushSpinBox->setVisible(false);
mUsePressureBox->setVisible(false);
mFeatherSlider->setVisible(false);
mFeatherSpinBox->setVisible(false);
mUseFeatherBox->setVisible(false);
break;
case PENCIL:
mSizeSlider->setVisible(false);
mBrushSpinBox->setVisible(false);
mUsePressureBox->setVisible(false);
break;
case BUCKET:
mSizeSlider->setLabel(tr("Stroke Thickness"));
mToleranceSlider->setVisible(false);
mToleranceSpinBox->setVisible(false);
break;
default:
mSizeSlider->setLabel(tr("Width"));
mToleranceSlider->setVisible(false);
mToleranceSpinBox->setVisible(false);
mUseAABox->setVisible(false);
Expand All @@ -330,6 +344,10 @@ void ToolOptionWidget::visibilityOnLayer()
case PENCIL:
mFillContour->setVisible(false);
break;
case BUCKET:
mBrushSpinBox->setVisible(false);
mSizeSlider->setVisible(false);
break;
default:
mMakeInvisibleBox->setVisible(false);
break;
Expand Down
1 change: 1 addition & 0 deletions core_lib/graphics/vector/bezierarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Status BezierArea::createDomElement( QXmlStreamWriter& xmlStream )
{
xmlStream.writeStartElement( "area" );
xmlStream.writeAttribute( "colourNumber", QString::number( mColourNumber ) );
xmlStream.writeAttribute("filled", QString::number( mIsFilled ) );

int errorLocation = -1;
for ( int i = 0; i < mVertex.size(); i++ )
Expand Down
1 change: 1 addition & 0 deletions core_lib/graphics/vector/bezierarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class BezierArea

private:
bool mSelected = false;
bool mIsFilled = false;
};

#endif
36 changes: 26 additions & 10 deletions core_lib/graphics/vector/beziercurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Status BezierCurve::createDomElement( QXmlStreamWriter& xmlStream )
xmlStream.writeAttribute( "variableWidth", variableWidth ? "true" : "false" );
if (feather>0) xmlStream.writeAttribute( "feather", QString::number( feather ) );
xmlStream.writeAttribute( "invisible", invisible ? "true" : "false" );
xmlStream.writeAttribute( "filled", mFilled ? "true" : "false" );
xmlStream.writeAttribute( "colourNumber", QString::number( colourNumber ) );
xmlStream.writeAttribute( "originX", QString::number( origin.x() ) );
xmlStream.writeAttribute( "originY", QString::number( origin.y() ) );
Expand Down Expand Up @@ -113,6 +114,7 @@ Status BezierCurve::createDomElement( QXmlStreamWriter& xmlStream )
<< QString( "variableWidth = %1" ).arg( "variableWidth" )
<< QString( "feather = %1" ).arg( feather )
<< QString( "invisible = %1" ).arg( invisible )
<< QString( "filled = %1" ).arg( mFilled )
<< QString( "colourNumber = %1" ).arg( colourNumber )
<< QString( "originX = %1" ).arg( origin.x() )
<< QString( "originY = %1" ).arg( origin.y() )
Expand All @@ -138,6 +140,7 @@ void BezierCurve::loadDomElement(QDomElement element)
variableWidth = (element.attribute("variableWidth") == "1");
feather = element.attribute("feather").toDouble();
invisible = (element.attribute("invisible") == "1");
mFilled = (element.attribute("filled") == "1");
if (width == 0) invisible = true;
colourNumber = element.attribute("colourNumber").toInt();
origin = QPointF( element.attribute("originX").toFloat(), element.attribute("originY").toFloat() );
Expand Down Expand Up @@ -254,6 +257,17 @@ void BezierCurve::setSelected(int i, bool YesOrNo)
selected[i+1] = YesOrNo;
}

/**
* @brief BezierCurve::setFilled
* @param YesOrNo: bool
* setFilled doesn't do anything on its own, but we use it
* to see if a curve has been filled with an BezierArea.
*/
void BezierCurve::setFilled(bool YesOrNo)
{
mFilled = YesOrNo;
}

BezierCurve BezierCurve::transformed(QTransform transformation)
{
BezierCurve transformedCurve = *this; // copy the curve
Expand Down Expand Up @@ -337,7 +351,7 @@ void BezierCurve::addPoint(int position, const QPointF point)
}
}

void BezierCurve::addPoint(int position, const qreal t) // t is the fraction where to split the bezier curve (ex: t=0.5)
void BezierCurve::addPoint(int position, const qreal fraction) // fraction is where to split the bezier curve (ex: fraction=0.5)
{
// de Casteljau's method is used
// http://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm
Expand All @@ -348,12 +362,12 @@ void BezierCurve::addPoint(int position, const qreal t) // t is the fraction
QPointF vB = getVertex(position);
QPointF c1o = getC1(position);
QPointF c2o = getC2(position);
QPointF c12 = (1-t)*c1o + t*c2o;
QPointF cA1 = (1-t)*vA + t*c1o;
QPointF cB2 = (1-t)*c2o + t*vB;
QPointF cA2 = (1-t)*cA1 + t*c12;
QPointF cB1 = (1-t)*c12 + t*cB2;
QPointF vM = (1-t)*cA2 + t*cB1;
QPointF c12 = (1-fraction)*c1o + fraction*c2o;
QPointF cA1 = (1-fraction)*vA + fraction*c1o;
QPointF cB2 = (1-fraction)*c2o + fraction*vB;
QPointF cA2 = (1-fraction)*cA1 + fraction*c12;
QPointF cB1 = (1-fraction)*c12 + fraction*cB2;
QPointF vM = (1-fraction)*cA2 + fraction*cB1;

setC1(position, cB1);
setC2(position, cB2);
Expand Down Expand Up @@ -457,7 +471,7 @@ void BezierCurve::drawPath(QPainter& painter, Object* object, QTransform transfo
if (!simplified)
{
// highlight the selected elements
colour = QColor(100,100,255); // highlight colour
colour = QColor(100,150,255); // highlight colour
painter.setBrush(Qt::NoBrush);
qreal lineWidth = 1.5/painter.matrix().m11();
painter.setPen(QPen(QBrush(colour), lineWidth, Qt::SolidLine, Qt::RoundCap,Qt::RoundJoin));
Expand All @@ -468,7 +482,7 @@ void BezierCurve::drawPath(QPainter& painter, Object* object, QTransform transfo
{
if (isSelected(i))
{
//painter.fillRect(myCurve.getVertex(i).x()-0.5*squareWidth, myCurve.getVertex(i).y()-0.5*squareWidth, squareWidth, squareWidth, colour);
// painter.fillRect(myCurve.getVertex(i).x()-0.5*squareWidth, myCurve.getVertex(i).y()-0.5*squareWidth, squareWidth, squareWidth, colour);

//painter.fillRect(QRectF(myCurve.getVertex(i).x()-0.5*squareWidth, myCurve.getVertex(i).y()-0.5*squareWidth, squareWidth, squareWidth), colour);

Expand Down Expand Up @@ -519,13 +533,15 @@ QPainterPath BezierCurve::getStrokedPath(qreal width)
return getStrokedPath(width, true);
}

// this function is a mess and outputs buggy results randomly...
QPainterPath BezierCurve::getStrokedPath(qreal width, bool usePressure)
{
QPainterPath path;
QPointF tangentVec, normalVec, normalVec2, normalVec2_1, normalVec2_2;
qreal width2 = width;
path.setFillRule(Qt::WindingFill);
int n = vertex.size();
path.setFillRule(Qt::WindingFill);

normalVec = QPointF(-(c1.at(0) - origin).y(), (c1.at(0) - origin).x());
normalise(normalVec);
if (usePressure) width2 = width * 0.5 * pressure.at(0);
Expand Down
7 changes: 5 additions & 2 deletions core_lib/graphics/vector/beziercurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class BezierCurve
QPointF getC1(int i) const { return c1.at(i); }
QPointF getC2(int i) const { return c2.at(i); }
qreal getPressure(int i) const { return pressure.at(i); }
bool isSelected(int i) const { return selected.at(i+1); }
bool isSelected(int vertex) const { return selected.at(vertex+1); }
bool isSelected() const { bool result=true; for(int i=0; i<selected.size(); i++) result = result && selected[i]; return result; }
bool isPartlySelected() const { bool result=false; for(int i=0; i<selected.size(); i++) result = result || selected[i]; return result; }
bool isInvisible() const { return invisible; }
bool intersects(QPointF point, qreal distance);
bool intersects(QRectF rectangle);
bool isFilled() const { return mFilled; }

void setOrigin(const QPointF& point);
void setOrigin(const QPointF& point, const qreal& pressureValue, const bool& trueOrFalse);
Expand All @@ -70,13 +71,14 @@ class BezierCurve
void setColourNumber(int colourNumber) { this->colourNumber = colourNumber; }
void setSelected(bool YesOrNo) { for(int i=0; i<selected.size(); i++) { selected[i] = YesOrNo; } }
void setSelected(int i, bool YesOrNo);
void setFilled(bool yesOrNo);

BezierCurve transformed(QTransform transformation);
void transform(QTransform transformation);

void appendCubic(const QPointF& c1Point, const QPointF& c2Point, const QPointF& vertexPoint, qreal pressureValue);
void addPoint(int position, const QPointF point);
void addPoint(int position, const qreal t);
void addPoint(int position, const qreal fraction);
QPointF getPointOnCubic(int i, qreal t);
void removeVertex(int i);
QPainterPath getStraightPath();
Expand Down Expand Up @@ -110,6 +112,7 @@ class BezierCurve
float feather = 0.f;
bool variableWidth = 0.f;
bool invisible = false;
bool mFilled = false;
QList<bool> selected; // this list has one more element than the other list (the first element is for the origin)
};

Expand Down
Loading

0 comments on commit c826529

Please sign in to comment.